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>
7 #include "StMcEvent/StMcEvent.hh"
8 #include "StEventTypes.h"
9 #include "StDbUtilities/StGlobalCoordinate.hh"
10 #include "Sti/StiHit.h"
11 #include "Sti/StiHitContainer.h"
12 #include "Sti/StiDetector.h"
13 #include "Sti/StiDetectorBuilder.h"
14 #include "Sti/StiTrackContainer.h"
15 #include "StiIst/StiIstDetectorBuilder.h"
16 #include "StiIstHitLoader.h"
17 #include "StMcEvent/StMcTrack.hh"
18 #include "StMcEvent/StMcIstHit.hh"
19 #include "StMcEvent/StMcIstHitCollection.hh"
20 #include "StMcEvent/StMcIstLayerHitCollection.hh"
21 #include "StIstHitCollection.h"
22 #include "StIstHit.h"
23 
24 
25 StiIstHitLoader::StiIstHitLoader() :
26  StiHitLoader<StEvent, StiDetectorBuilder>("IstHitLoader")
27 {}
28 
29 StiIstHitLoader::StiIstHitLoader(StiHitContainer *hitContainer, Factory<StiHit> *hitFactory,
30  StiDetectorBuilder *detector) :
31  StiHitLoader<StEvent, StiDetectorBuilder>("IstHitLoader", hitContainer, hitFactory, detector)
32 {}
33 
34 StiIstHitLoader::~StiIstHitLoader()
35 {}
36 
37 void StiIstHitLoader::loadHits(StEvent *source, Filter<StiTrack> *trackFilter, Filter<StiHit> *hitFilter)
38 {
39  if (!_detector)
40  throw runtime_error("StiIstHitLoader::loadHits(StEvent*) - FATAL - _detector==0");
41 
42  if (!_hitContainer)
43  throw runtime_error("StiIstHitLoader::loadHits(StEvent*) - FATAL - _hitContainer==0");
44 
45 
46  StIstHitCollection *col = source->istHitCollection();
47 
48  if (!col) {
49  LOG_WARN << "StiIstHitLoader::loadHits() - StIstHitCollection not found. "
50  "Check for istFastSim option in input chain. "
51  "IST hits will not be used in tracking" << endm;
52  return;
53  }
54 
55  int nIsthits = col->numberOfHits();
56  LOG_DEBUG << "StiIstHitLoader: IST Hits: " << nIsthits << endm;
57 
58  if (nIsthits) {
59  for (int ladderIdx = 0; ladderIdx < kIstNumLadders; ++ladderIdx ) {
60  StIstLadderHitCollection *ladderHitCollection = col->ladder(ladderIdx);
61 
62  if (! ladderHitCollection) {
63  LOG_WARN << "No IST ladder hit collection" << endl;
64  return;
65  }
66 
67  for (int sensorIdx = 0; sensorIdx < kIstNumSensorsPerLadder; sensorIdx++) {
68  StIstSensorHitCollection *sensorHitCollection = ladderHitCollection->sensor(sensorIdx);
69 
70  if (! sensorHitCollection) {
71  cout << "No IST sensor hit collection" << endl;
72  return;
73  }
74 
75  StSPtrVecIstHit &vec = sensorHitCollection->hits();
76  LOG_DEBUG << "StiIstHitLoader - collection size: " << vec.size() << " on Ladder " << ladderIdx + 1 << " Sensor " << sensorIdx + 1 << endm;
77 
78  for (unsigned int j = 0; j < vec.size(); j++) {
79  StIstHit *hit = vec[j];
80 
81  if (!hit)
82  throw runtime_error("StiIstHitLoader::loadHits(StEvent*) -E- NULL hit in container");
83 
84  if (hit->detector() != kIstId) continue;
85 
86  LOG_DEBUG << *hit << "\n"
87  << *static_cast<StMeasuredPoint*>(hit) << endm;
88 
89  // The IST sensitive layers are split into two halves so, access the corresponding
90  // sensor half to be later associated with this istHit
91  int sensorHalf = hit->localPosition(0) < 0 ? 1 : 2;
92  const StiDetector *detector = static_cast<StiIstDetectorBuilder*>(_detector)->getActiveDetector(hit->getLadder(), sensorHalf);
93 
94  if (!detector)
95  throw runtime_error("StiIstHitLoader::loadHits(StEvent*) -E- NULL detector pointer");
96 
97  StiHit *stiHit = _hitFactory->getInstance();
98 
99  if (!stiHit) throw runtime_error("StiIstHitLoader::loadHits(StEvent*) -E- stiHit==0");
100 
101  stiHit->reset();
102 
103  stiHit->setGlobal(detector, hit, hit->position().x(), hit->position().y(), hit->position().z(), hit->charge());
104  // Allow the hit to be shared by up to 5 tracks
105  stiHit->setMaxTimes(5);
106 
107  _hitContainer->add( stiHit );
108  } // end hits loop
109  } //end sensors loop
110  } // end ladders loop
111  }// end nIsthits cut
112 
113 }
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 int kIstNumLadders
24 IST Ladders
virtual Abstract * getInstance()=0
Get a pointer to instance of objects served by this factory.
void setMaxTimes(int set)
Set the number of times used.
Definition: StiHit.h:142
const int kIstNumSensorsPerLadder
6 sensor per one IST Ladder