StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StiPixelHitLoader.cxx
1  /*
2  * $Id: StiPixelHitLoader.cxx,v 1.28 2014/01/30 16:50:59 didenko Exp $
3  *
4  * $Log: StiPixelHitLoader.cxx,v $
5  * Revision 1.28 2014/01/30 16:50:59 didenko
6  * get back to previous revision
7  *
8  * Revision 1.26 2013/03/12 15:04:00 bouchet
9  * StPxlHit navigation to retrieve hits
10  *
11  * Revision 1.24 2012/12/18 20:52:32 bouchet
12  * update for DEV13 geometry
13  *
14  * Revision 1.23 2011/04/22 22:00:18 fisyak
15  * warn off
16  *
17  * Revision 1.22 2009/02/09 02:47:19 andrewar
18  * UPGR15 update. Will break backward compatibility with older geometries.
19  *
20  * Revision 1.21 2008/03/25 20:02:28 andrewar
21  * Removed hit smearing.
22  *
23  * Revision 1.20 2007/10/16 19:50:25 fisyak
24  * rename Hft => Pxl, remove Hpd, Igt and Fst
25  *
26  * Revision 1.19 2007/05/16 15:03:22 andrewar
27  * Removed cout's in favor of LOG_INFO.
28  *
29  * Revision 1.18 2007/03/28 13:33:23 mmiller
30  * Removed cout/printf's.
31  *
32  * Revision 1.17 2006/11/30 20:42:46 andrewar
33  * Fixed sign error in pixel smearing.
34  *
35  * Revision 1.16 2006/11/29 04:19:23 andrewar
36  * Added smearing to hit loader.
37  *
38  * Revision 1.15 2006/11/17 15:39:03 wleight
39  * Changes to make PXL hits work with UPGR05 geometry
40  *
41  * Revision 1.14 2006/02/17 21:37:53 andrewar
42  * Removed streaming of all read pixel hits, added version comments log
43  *
44  */
45 
46 
47 #include <iostream>
48 #include <stdexcept>
49 #include <cmath>
50 #include <stdio.h>
51 #include <stdlib.h>
52 #include "StEvent.h"
53 #include "StEventTypes.h"
54 #include "StDbUtilities/StGlobalCoordinate.hh"
55 #include "Sti/Base/Factory.h"
56 #include "Sti/StiHit.h"
57 //#include "StRnDHit.h"
58 #include "StPxlHitCollection.h"
59 #include "StPxlHit.h"
60 //#include "StRnDHitCollection.h"
61 #include "Sti/StiHitContainer.h"
62 #include "Sti/StiDetector.h"
63 #include "Sti/StiDetectorBuilder.h"
64 #include "Sti/StiTrackContainer.h"
65 #include "StiPixelHitLoader.h"
66 
67 StiPixelHitLoader::StiPixelHitLoader()
68 : StiHitLoader<StEvent,StiDetectorBuilder>("PixelHitLoader")
69 {}
70 
71 StiPixelHitLoader::StiPixelHitLoader(StiHitContainer* hitContainer,
72  Factory<StiHit>*hitFactory,
73  StiDetectorBuilder * detector)
74 : StiHitLoader<StEvent,StiDetectorBuilder>("PixelHitLoader",hitContainer,hitFactory,detector)
75 {}
76 
77 StiPixelHitLoader::~StiPixelHitLoader()
78 {}
79 
80 void StiPixelHitLoader::loadHits(StEvent* source,
81  Filter<StiTrack> * trackFilter,
82  Filter<StiHit> * hitFilter)
83 {
84 
85  LOG_INFO << " -I- Started" << endl;
86  if (!_detector)
87  throw runtime_error("StiPixelHitLoader::loadHits(StEvent*) - FATAL - _detector==0");
88  if(!_hitContainer)
89  throw runtime_error("StiPixelHitLoader::loadHits(StEvent*) - FATAL - _hitContainer==0");
90 
91  StPxlHitCollection *col = source->pxlHitCollection();
92  if (!col) {
93  LOG_ERROR <<"StiPixelHitLoader::loadHits\tERROR:\tcol==0"
94  <<"You must not have pixelFastSim in your chain"
95  <<"will return with no action taken"<<endm;
96  return;
97  }
98  //Added by Michael Lomnitz (KSU): Loops over Sector/Ladder/Sensor to obtain the whole hit collection
99  StiDetector *detector=0;
100  int nHit=0;
101 
102  StPxlHitCollection* PxlHitCollection=source->pxlHitCollection();
103  if(! PxlHitCollection){cout<<"No PXL hit collection"<<endl; return;}
104  UInt_t numberOfSectors=PxlHitCollection->numberOfSectors();
105  for(UInt_t i=0;i<numberOfSectors;i++){
106  StPxlSectorHitCollection* PxlSectorHitCollection=PxlHitCollection->sector(i);
107  if(! PxlSectorHitCollection){cout<<"No PXLSector hit collection"<<endl; return;}
108  UInt_t numberOfLadders=PxlSectorHitCollection->numberOfLadders();
109  for(UInt_t j=0;j<numberOfLadders;j++){
110  StPxlLadderHitCollection* PxlLadderHitCollection=PxlSectorHitCollection->ladder(j);
111  if(! PxlLadderHitCollection){cout<<"No PXLLadder hit collection"<<endl; return;}
112  UInt_t numberOfSensors=PxlLadderHitCollection->numberOfSensors();
113  for(UInt_t l=0;l<numberOfSensors;l++){
114  StPxlSensorHitCollection* PxlSensorHitCollection=PxlLadderHitCollection->sensor(l);
115  StSPtrVecPxlHit& vec = PxlSensorHitCollection->hits();
116 
117  LOG_DEBUG<<"StiPixelHitLoader - collection size: "<<vec.size()<<endm;
118 
119  for(unsigned int j=0; j<vec.size(); j++) {
120  StPxlHit *pxlH = vec[j];
121  if(!pxlH)
122  throw runtime_error("StiPixelHitLoader::loadHits(StEvent*) -E- NULL hit in container");
123 
124  if (pxlH->detector()!=kPxlId) continue;
125 
126  int LAY=0, LAD=0;
127 
128  if(pxlH->layer()==1)
129  {
130  LAY=0;//(int)pxlH->layer()-1;
131  LAD=(int)pxlH->sector()-1;
132  }
133  else
134  {
135  LAY=1;//(int)pxlH->layer()-1;
136  LAD=(((int)pxlH->sector()-1)*3 + (int)pxlH->ladder()-1);
137  }
138  LOG_DEBUG << " layer : "<< LAY <<" ladder : "<< LAD << endm;
139  LOG_DEBUG << "X/Y/Z : " << pxlH->position().x()<<"/"<< pxlH->position().y()<<"/"<<pxlH->position().z()<<endm;
140  LOG_DEBUG << "Xl/Yl/Zl : " << pxlH->localPosition(0)<<"/"<< pxlH->localPosition(1)<<"/"<<pxlH->localPosition(2)<<endm;
141  detector= _detector->getDetector(LAY,LAD);
142 
143  if(!detector)
144  throw runtime_error("StiPixelHitLoader::loadHits(StEvent*) -E- NULL detector pointer");
145  LOG_DEBUG <<"add hit to detector:\t"<<detector->getName()<<endm;
146  double angle = detector->getPlacement()->getNormalRefAngle();
147  double radius = detector->getPlacement()->getNormalRadius();
148  double zcenter = detector->getPlacement()->getZcenter();
149  double halfDepth = detector->getShape()->getHalfDepth();
150  double halfWidth = detector->getShape()->getHalfWidth();
151  double thick = detector->getShape()->getThickness();
152  LOG_DEBUG << " detector info " << *detector << endm;
153  LOG_DEBUG << " radius = "<< radius << " angle = " << angle << " zCenter = " << zcenter << endm;
154  LOG_DEBUG << " depth = " << halfDepth << " Width = " << halfWidth << " thickness= " << thick << endm;
155  LOG_DEBUG << " key 1 : " << detector->getKey(1) <<" key 2 : " << detector->getKey(2) << endm;
156 
157  StiHit *stiHit=_hitFactory->getInstance();
158  if(!stiHit) throw runtime_error("StiPixelHitLoader::loadHits(StEvent*) -E- stiHit==0");
159  stiHit->reset();
160 
161  stiHit->setGlobal(detector, pxlH,
162  pxlH->position().x(), pxlH->position().y(),
163  pxlH->position().z(), pxlH->charge());
164 
165  _hitContainer->add(stiHit);
166  LOG_DEBUG <<" nHit = "<<nHit<<" Sector = "<<pxlH->sector()<<" Ladder = "<<pxlH->ladder()<<" x = "<<pxlH->position().x()<<" y = "<<pxlH->position().y()<<" z = "<<pxlH->position().z()<<endm;
167 
168  //done loop over hits
169  nHit++;
170  }
171  }
172  }
173  }
174  LOG_INFO <<"StiPixelHitLoader:loadHits -I- Loaded "<<nHit<<" pixel hits."<<endm;
175 }
176 
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