StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StiIstHitLoader.cxx
1 #include <iostream>
2 #include <stdexcept>
3 #include <cmath>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include "StEvent.h"
7 #include "StMcEvent/StMcEvent.hh"
8 #include "StEventTypes.h"
9 #include "StDbUtilities/StGlobalCoordinate.hh"
10 #include "Sti/Base/Factory.h"
11 #include "Sti/StiHit.h"
12 #include "Sti/StiHitContainer.h"
13 #include "Sti/StiDetector.h"
14 #include "Sti/StiDetectorBuilder.h"
15 //#include "Sti/StiMcTrack.h"
16 #include "Sti/StiTrackContainer.h"
17 #include "StiIstHitLoader.h"
18 #include "StMcEvent/StMcTrack.hh"
19 #include "StMcEvent/StMcIstHit.hh"
20 #include "StMcEvent/StMcIstHitCollection.hh"
21 #include "StMcEvent/StMcIstLayerHitCollection.hh"
22 #include "StBFChain.h"
23 #include "StChain.h"
24 #include "StMaker.h"
25 //#include "StPixelFastSimMaker/StPixelFastSimMaker.h"
26 
27 StiIstHitLoader::StiIstHitLoader()
28  : StiHitLoader<StEvent,StiDetectorBuilder>("IstHitLoader")
29 {}
30 
31 StiIstHitLoader::StiIstHitLoader(StiHitContainer* hitContainer,
32  Factory<StiHit>*hitFactory,
33  StiDetectorBuilder * detector)
34  : StiHitLoader<StEvent,StiDetectorBuilder>("IstHitLoader",hitContainer,hitFactory,detector)
35 {evNum=0;}
36 
37 StiIstHitLoader::~StiIstHitLoader()
38 {}
39 
40 void StiIstHitLoader::loadHits(StEvent* source,
41  Filter<StiTrack> * trackFilter,
42  Filter<StiHit> * hitFilter)
43 {
44  n=0;
45  //cout << " n = " << n << endl;
46  LOG_INFO << "StiIstHitLoader::loadHits(StEvent*) -I- Started" << endm;
47  if (!_detector)
48  throw runtime_error("StiIstHitLoader::loadHits(StEvent*) - FATAL - _detector==0");
49  if(!_hitContainer)
50  throw runtime_error("StiIstHitLoader::loadHits(StEvent*) - FATAL - _hitContainer==0");
51 
52  //StSPtrVecHit* istHits = source->hitCollection("Ist");
53  StRnDHitCollection *col = source->rndHitCollection();
54  if (!col) {
55  LOG_INFO <<"StiIstHitLoader::loadHits\tERROR:\tcol==0"<<endm;
56  LOG_INFO <<"You must not have pixelFastSim in your chain"<<endm;
57  LOG_INFO <<"will return with no action taken"<<endm;
58  return;
59  }
60  StSPtrVecRnDHit& vec = col->hits();
61 
62  LOG_DEBUG <<"StiIstHitLoader: RnD Hits: "<<vec.size()<<endm;
63 
64  for(unsigned int j=0; j<vec.size(); j++) {
65 
66  //StRnDHit* hit = dynamic_cast<StRndHit*>((*istHits)[j]);
67  StRnDHit* hit = vec[j];
68  assert(hit);
69 
70  if (hit->detector()!=kIstId) continue;
71  //if(hit->extraByte0()==1){
72  // ladder module side
73  // volume_id = numbv(1)*1000000 + numbv(2)*10000 + numbv(3)*100 + numbv(4)
74  //MLM cout <<"retrieve detector"<<endl;
75  int layer = hit->layer();
76  int ladder = hit->ladder();
77  int wafer = hit->wafer();
78  LOG_DEBUG<<"StiIstHitLoader: hit has ladder: "<<ladder<<"; wafer: "<<wafer<<endm;
79  LOG_DEBUG<<"StiIstHitLoader: hit volume id: "<<hit->volumeId()<<endm;
80  StiDetector* detector=0;
81  //detector=_detector->getDetector(2*(layer-1)+side-1,ladder);
82  //detector=_detector->getDetector(ladder,wafer);
83  detector=_detector->getDetector(layer,ladder);
84  if (!detector) cout <<"no detector found for hit:\t"<<*hit<<endl;
85  assert(detector);
86  cout <<"StiIstHitLoader: add hit to detector:\t"<<detector->getName()<<endl;
87 
88  StiHit * stiHit = _hitFactory->getInstance();
89  if(!stiHit) throw runtime_error("StiIstHitLoader::loadHits(StEvent*) -E- stiHit==0");
90  stiHit->reset();
91  LOG_DEBUG<<"StiIstHitLoader: hit has position ("<<hit->position().x()<<","<<hit->position().y()<<","<<hit->position().z()<<")"<<endm;
92  stiHit->setGlobal(detector, hit, hit->position().x(),hit->position().y(),hit->position().z(),hit->charge());
93  _hitContainer->add( stiHit );
94  //}
95  }
96 
97  LOG_INFO << "StiIstHitLoader::loadHits(StEvent*) -I- Done" << endm;
98 }
99 
103 /*
104 void StiIstHitLoader::loadMcHits(StMcEvent* source,
105  bool useMcAsRec,
106  Filter<StiTrack> * trackFilter,
107  Filter<StiHit> * hitFilter,
108  StMcTrack & stMcTrack,
109  StiMcTrack & stiMcTrack)
110 {
111  if (evNum==source->eventNumber()) return;
112  else evNum=source->eventNumber();
113 
114  cout << "StiIstHitLoader::loadMcHits(StMcEvent*) -I- Started" << endl;
115  if (!_detector) throw runtime_error("StiIstHitLoader::loadMcHits(StMcEvent*) -F- _detector==0");
116  if(!_mcHitContainer) throw runtime_error("StiIstHitLoader::loadMcHits(StMcEvent*) -F- _mcHitContainer==0");
117  if(!_mcTrackFactory) throw runtime_error("StiIstHitLoader::loadMcHits() -F- _mcTrackFactory==0");
118  if (!_mcTrackContainer) throw runtime_error("StiIstHitLoader::loadMcHitss() -F- _mcTrackContainer==0");
119  if(!_hitFactory) throw runtime_error("StiIstHitLoader::loadMcHits(StMcEvent*) -F- _hitFactory==0");
120  cout << "StiIstHitLoader::loadMcHits() -I- Loading"<<endl;
121 
122  if (n>0) return;
123  n++;
124  StMcIstHitCollection* allIstHitCol = source->istHitCollection();
125  //cout << "ist: Number of Layers" << allIstHitCol->numberOfLayers() << endl;
126  for(int tiLayer=0; tiLayer<allIstHitCol->numberOfLayers(); tiLayer++)
127  {
128  cout << "StiIstHitLoader::loadMcHits(StMcEvent*) -I- layer " << tiLayer << endl;
129  StMcIstLayerHitCollection* istHitCol = allIstHitCol->layer(tiLayer);
130  StSPtrVecMcIstHit& hits = istHitCol->hits();
131 
132  int nHitCount = 0;
133  StiDetector* detector;
134 
135  for (vector<StMcIstHit*>::const_iterator iterHit = hits.begin();iterHit != hits.end();iterHit++)
136  {
137  StMcIstHit *hit = *iterHit;
138  if(!hit){//something's wrong
139  cout<<"null hit"<<endl;
140  continue;
141  }
142  nHitCount++;
143  //cout << "guck: " << tiLayer << " " << hit->layer()-1 << endl;
144  detector = _detector->getDetector(hit->layer()-1, hit->ladder()-1);
145  StiHit * stiHit = _hitFactory->getInstance();
146  if(!stiHit) throw runtime_error("StiIstHitLoader::loadHits(StEvent*) -E- stiHit==0");
147  stiHit->reset();
148  stiHit->setGlobal(detector, 0, hit->position().x(),hit->position().y(),hit->position().z(),hit->dE());
149  _hitContainer->add( stiHit );
150  //stiMcTrack.addHit( stiHit );
151  }
152  cout << "StiIstHitLoader::loadMcHits(StEvent*) -I- number of hits uploaded, after: " << _hitContainer->size() << endl;
153  cout << "StiIstHitLoader::loadMcHits(StEvent*) -I- Done" << endl;
154  cout<<"nHitCount\t"<<nHitCount<<endl;
155  }
156 }
157 */
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
virtual Abstract * getInstance()=0
Get a pointer to instance of objects served by this factory.
const string & getName() const
Get the name of the object.
Definition: Named.cxx:22