StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StiSvtHitLoader.cxx
1 #include "Stiostream.h"
2 #include <cmath>
3 #include <stdio.h>
4 #include "StEventTypes.h"
5 #include "StEvent.h"
6 #include "Sti/Base/Factory.h"
7 #include "StiSvt/StiSvtHitLoader.h"
8 #include "Sti/StiHit.h"
9 #include "Sti/StiTrack.h"
10 #include "Sti/StiHitContainer.h"
11 #include "Sti/StiDetectorBuilder.h"
12 #include "Sti/StiDetector.h"
13 #include "Sti/StiHitTest.h"
14 
15 StiSvtHitLoader::StiSvtHitLoader()
16 : StiHitLoader<StEvent,StiDetectorBuilder>("SvtHitLoader")
17 {}
18 
19 StiSvtHitLoader::StiSvtHitLoader(StiHitContainer* hitContainer,
20  Factory<StiHit>*hitFactory,
21  StiDetectorBuilder*detector)
22 : StiHitLoader<StEvent,StiDetectorBuilder>("SvtHitLoader",hitContainer,hitFactory,detector)
23 {}
24 
25 StiSvtHitLoader::~StiSvtHitLoader()
26 {}
27 
28 void StiSvtHitLoader::loadHits(StEvent* source,
29  Filter<StiTrack> * trackFilter,
30  Filter<StiHit> * hitFilter)
31 {
32  cout <<"StiSvtHitLoader::loadHits() - Started"<<endl;
33  if (!source) throw runtime_error("StiSvtHitLoader::loadHits() -F- source==0 ");
34  StSvtHitCollection* svthits = source->svtHitCollection();
35  if (!svthits)
36  {
37  cout << "StiSvtHitLoader::loadHits(StEvent* source) -W- NO SVT hits"<<endl;
38  return;
39  }
40  StSvtHit* hit=0;
41  StiHit* stiHit=0;
42  StiDetector* detector=0;
43  if (!_hitContainer) throw runtime_error("StiSvtHitLoader::loadHits() -F- _hitContainer==0 ");
44  int hitCounter = 0;
45  for (unsigned int barrel=0; barrel<svthits->numberOfBarrels(); ++barrel)
46  {
47  StSvtBarrelHitCollection* barrelhits = svthits->barrel(barrel);
48  if (!barrelhits) continue;
49  for (unsigned int ladder=0; ladder<barrelhits->numberOfLadders(); ++ladder)
50  {
51  StSvtLadderHitCollection* ladderhits = barrelhits->ladder(ladder);
52  if (!ladderhits) continue;
53  for (unsigned int wafer=0; wafer<ladderhits->numberOfWafers(); ++wafer)
54  {
55  StSvtWaferHitCollection* waferhits = ladderhits->wafer(wafer);
56  if (!waferhits) continue;
57  const StSPtrVecSvtHit& hits = waferhits->hits();
58  StiHitTest hitTest;
59  for (const_StSvtHitIterator it=hits.begin(); it!=hits.end(); ++it)
60  {
61  if (!*it) throw runtime_error("StiSvtHitLoader::loadHits() -W- *it==0!");
62  hit = static_cast<StSvtHit*>(*it);
63  if (!hit) throw runtime_error("StiSvtHitLoader::loadHits() -W- hit==0!");
64  int svtLayer = hit->layer();
65  int svtLadder = hit->ladder();
66  int stilayer = getLayer(svtLayer);
67  int stiladder = getLadder(svtLayer,svtLadder);
68  detector = _detector->getDetector(stilayer,stiladder);
69  if (!detector) throw runtime_error("StiSvtHitLoader::loadHits() -W- detector==0!");
70  if (hit->flag()>=4) continue;
71  if (hit->flag()< 0) continue;
72  stiHit = _hitFactory->getInstance();
73  stiHit->setGlobal(detector,hit,hit->position().x(),hit->position().y(),hit->position().z(),hit->charge() );
74  hitTest.add(stiHit->x(),stiHit->y(),stiHit->z());
75  _hitContainer->add( stiHit );
76  hitCounter++;
77  }
78  if (hitTest.getN()< 10) continue;
79  double w=hitTest.width();
80  double dx = detector->getPlacement()->getNormalRadius()-hitTest.center()[0];;
81  double ay = hitTest.yAngle()*180/3.1415;
82  double az = hitTest.zAngle()*180/3.1415;
83 
84  if (w< 0.1 && fabs(dx)<1 && fabs(ay)<1 && fabs(az)<1) continue;
85  printf("**** SVT geom problem: barrel=%d ladder%d wafer%d\n",barrel,ladder,wafer);
86  printf("**** SVT dX=%g aY=%g aZ=%g\n\n",dx,ay,az);
87  }
88  }
89  }
90  cout <<"StiSvtHitLoader::loadHits() -I- SVT Hits added:"<<hitCounter<<endl;
91  cout <<"StiSvtHitLoader::loadHits() -I- Hit Container size:"<<_hitContainer->size()<<endl;
92  cout <<"StiSvtHitLoader::loadHits() -I- Done"<<endl;
93 }
94 
95 #if 0
96 int StiSvtHitLoader::getLayer(int svtLayer) const
97 {
98  int layer;
99  switch (svtLayer)
100  {
101  case 1: layer = 0; break;
102  case 2: layer = 1; break;
103  case 3: layer = 2; break;
104  case 4: layer = 3; break;
105  case 5: layer = 4; break;
106  case 6: layer = 5; break;
107  default: throw runtime_error("StiSvtHitLoader:getLayer() -E- invalid argument");
108  }
109  return layer;
110 }
111 
112 int StiSvtHitLoader::getLadder(int svtLayer,int svtLadder) const
113 {
114  int layer;
115  int ladder;
116  switch (svtLayer)
117  {
118  case 1:
119  switch (svtLadder)
120  {
121  case 2: layer = 0; ladder = 0;break;
122  case 4: layer = 0; ladder = 1;break;
123  case 6: layer = 0; ladder = 2;break;
124  case 8: layer = 0; ladder = 3;break;
125  default: throw runtime_error("StiSvtHitLoader:loadHits() -E- 1");
126  }
127  break;
128  case 2:
129  switch (svtLadder)
130  {
131  case 1: layer = 1; ladder = 0;break;
132  case 3: layer = 1; ladder = 1;break;
133  case 5: layer = 1; ladder = 2;break;
134  case 7: layer = 1; ladder = 3;break;
135  default: throw runtime_error("StiSvtHitLoader:loadHits() -E- 2");
136  }
137  break;
138  case 3:
139  switch (svtLadder)
140  {
141  case 2: layer = 2; ladder = 0;break;
142  case 4: layer = 2; ladder = 1;break;
143  case 6: layer = 2; ladder = 2;break;
144  case 8: layer = 2; ladder = 3;break;
145  case 10: layer = 2; ladder = 4;break;
146  case 12: layer = 2; ladder = 5;break;
147  default: throw runtime_error("StiSvtHitLoader:loadHits() -E- 3");
148  }
149  break;
150  case 4:
151  switch (svtLadder)
152  {
153  case 1: layer = 3; ladder = 0;break;
154  case 3: layer = 3; ladder = 1;break;
155  case 5: layer = 3; ladder = 2;break;
156  case 7: layer = 3; ladder = 3;break;
157  case 9: layer = 3; ladder = 4;break;
158  case 11: layer = 3; ladder = 5;break;
159  default: throw runtime_error("StiSvtHitLoader:loadHits() -E- 4");
160  }
161  break;
162  case 5:
163  switch (svtLadder)
164  {
165  case 2: layer = 4; ladder = 0;break;
166  case 4: layer = 4; ladder = 1;break;
167  case 6: layer = 4; ladder = 2;break;
168  case 8: layer = 4; ladder = 3;break;
169  case 10: layer = 4; ladder = 4;break;
170  case 12: layer = 4; ladder = 5;break;
171  case 14: layer = 4; ladder = 6;break;
172  case 16: layer = 4; ladder = 7;break;
173  default: throw runtime_error("StiSvtHitLoader:loadHits() -E- 5");
174  }
175  break;
176  case 6:
177  switch (svtLadder)
178  {
179  case 1: layer = 5; ladder = 0;break;
180  case 3: layer = 5; ladder = 1;break;
181  case 5: layer = 5; ladder = 2;break;
182  case 7: layer = 5; ladder = 3;break;
183  case 9: layer = 5; ladder = 4;break;
184  case 11: layer = 5; ladder = 5;break;
185  case 13: layer = 5; ladder = 6;break;
186  case 15: layer = 5; ladder = 7;break;
187  default: throw runtime_error("StiSvtHitLoader:loadHits() -E- 6");
188  }
189  break;
190  }
191  return ladder;
192 }
193 #endif
virtual void add(StiHit *)
void setGlobal(const StiDetector *detector, const StMeasuredPoint *stHit, Float_t x, Float_t y, Float_t z, Float_t energy)
Definition: StiHit.cxx:133
Definition: StiHit.h:51
const Float_t & x() const
Return the local x, y, z values.
Definition: StiHit.h:67
virtual Abstract * getInstance()=0
Get a pointer to instance of objects served by this factory.
virtual unsigned int size() const