StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TpcHitUtilities.cxx
1 // $Id: TpcHitUtilities.cxx,v 1.10 2018/04/11 02:43:22 smirnovd Exp $
3 //
4 // Author: M.L. Miller, Yale
5 //
7 //
8 // Description: TPC sector gains hit utilities class
9 //
11 //
12 // $Log: TpcHitUtilities.cxx,v $
13 // Revision 1.10 2018/04/11 02:43:22 smirnovd
14 // Enable TPC/iTPC switch via St_tpcPadConfig
15 //
16 // This is accomplished by substituting St_tpcPadPlanes with St_tpcPadConfig.
17 // A sector ID is passed to St_tpcPadConfig in order to extract parameters for
18 // either TPC or iTPC
19 //
20 // Revision 1.9 2011/01/18 14:40:32 fisyak
21 // Clean up TpcDb interfaces and Tpc coordinate transformation
22 //
23 // Revision 1.8 2006/05/22 18:27:34 genevb
24 // Remove patch to observe fast offline issues
25 //
26 // Revision 1.7 2006/05/20 03:17:21 genevb
27 // Changed MapKey to MapQAKey to make it unique for QA
28 //
29 // Revision 1.6 2006/05/18 03:27:41 genevb
30 // Patch to observe fast offline issues
31 //
32 // Revision 1.5 2003/09/19 21:23:37 genevb
33 // Extraneous semicolon
34 //
35 // Revision 1.4 2002/02/01 23:15:27 genevb
36 // Include float.h
37 //
38 // Revision 1.3 2001/04/25 18:14:12 perev
39 // HPcorrs
40 //
41 // Revision 1.2 2000/08/09 18:57:44 lansdell
42 // improvements in TPC gains code reduces CPU time per event by factor of 2
43 //
44 //
46 #include "float.h"
47 #include "TpcMapUtilities.h"
48 #include "TpcHitUtilities.h"
49 #include "StEventTypes.h" // StEvent
50 #include "StThreeVectorD.hh"
51 #include <algorithm> // STL
52 // StDb
53 #include "StDbUtilities/StTpcCoordinateTransform.hh"
54 #include "StDbUtilities/StTpcLocalSectorCoordinate.hh"
55 #include "StDbUtilities/StTpcPadCoordinate.hh"
56 #include "StDbUtilities/StGlobalCoordinate.hh"
57 #include "StTpcDb/StTpcDb.h"
58 
59 #ifndef ST_NO_NAMESPACES
60 using std::sort;
61 using std::pair;
62 #endif
63 
64 TpcHitUtilities::TpcHitUtilities()
65 {
66  buildMaps();
67  clear();
68 }
69 
70 TpcHitUtilities::TpcHitUtilities(StTrack* tck, double magneticField)
71 {
72  buildMaps();
73  clear();
74  m_StTrack = tck;
75  m_BField = magneticField;
76 }
77 
78 TpcHitUtilities::~TpcHitUtilities() {}
79 
80 //Access--------------------------------------
81 void TpcHitUtilities::clear()
82 {
83  m_StTrack = 0;
84  m_BField = 0.;
85  m_tpcHitVec.clear();
86  return;
87 }
88 
89 void TpcHitUtilities::setTrack(StTrack* tck)
90 {
91  m_StTrack = tck;
92  return;
93 }
94 
95 void TpcHitUtilities::setBField(double b)
96 {
97  m_BField = b;
98  return;
99 }
100 
101 const vector<StTpcHit*>& TpcHitUtilities::tpcHitVec() const { return m_tpcHitVec;}
102 
103 //Methods---------------------------------------
104 void TpcHitUtilities::findHits()
105 {
106  StPtrVecHit vec = m_StTrack->detectorInfo()->hits(kTpcId);
107  StPtrVecHitIterator iter;
108  StTpcHit* hit;
109 
110  for (iter = vec.begin(); iter != vec.end(); iter++) {
111  if (*iter){
112  hit = dynamic_cast<StTpcHit*>(*iter);
113  if (hit) { m_tpcHitVec.push_back(hit); }
114  }
115  }
116  return;
117 }
118 
119 
120 //Hit Filter, currently keep only flag==0 hits
121 bool TpcHitUtilities::keepHit(StTpcHit* tpcHit)
122 {
123  if (tpcHit->flag()==0) {return true;}
124  else {return false;}
125 
126 }
127 
128 //Outward pointing normal of the sector
129 const StThreeVectorD TpcHitUtilities::sectorNormal(int sector)
130 {
131  int numSectors = gStTpcDb->Dimensions()->numberOfSectors();
132  double beta = (sector > 12) ?(numSectors-sector)*2.*M_PI/(static_cast<double>(numSectors)/2.): sector*2.*M_PI/(static_cast<double>(numSectors)/2.);
133  const StThreeVectorD vec(sin(beta), cos(beta), 0.);
134  return vec;
135 }
136 
137 //Caluclate Pathlength using StHelixD
138 double TpcHitUtilities::dx(StTpcHit* tpcHit)
139 {
140  double ds=0.;
141  HitMapQAKey mykey; //Build a key to the map (sector, padrow)
142  mykey.sector = tpcHit->sector();
143  mykey.padrow = tpcHit->padrow();
144  PadrowLocation padLoc = m_PadrowMap[mykey];
145  const StThreeVectorD normal = m_SectorNormalMap[tpcHit->sector()];
146  double s_out = m_StTrack->geometry()->helix().pathLength(padLoc.outsidePoint(), normal);
147  double s_in = m_StTrack->geometry()->helix().pathLength(padLoc.insidePoint(), normal);
148  ds = s_out-s_in;
149  if (ds < 0.) {ds = -1.*ds;}
150  if (s_out==DBL_MAX || s_in==DBL_MAX) {ds = 0.;}
151  return ds;
152 }
153 
154 void TpcHitUtilities::buildMaps()
155 {
156  StTpcCoordinateTransform transformer(gStTpcDb);
157  //Build map with an outward pointing normal keyed by sector number
158  {for (int sector=1; sector<=24; sector++) {
159  m_SectorNormalMap[sector] = sectorNormal(sector);
160  }}
161 
162  //Build map with a point on outside, center, and inside of padrow (this plus normal define a plane)
163  //StTpcCoordinateTransform transformer(gStTpcDb);
164  {for (int sector=1; sector<=24; sector++) {
165 
166  for (int padrow=1; padrow<=45; padrow++) {
167  double padlength;
168  if (padrow<14) {
169  padlength = St_tpcPadConfigC::instance()->innerSectorPadLength(sector);}
170  else {
171  padlength = St_tpcPadConfigC::instance()->outerSectorPadLength(sector);}
172 
173  //Get the position of the padrow center, transform to local sector coordinates
174  StTpcPadCoordinate padCoord(sector, padrow, 1, 1);
175  StTpcLocalSectorCoordinate lsMidCoord;
176  transformer(padCoord, lsMidCoord);
177 
178  //Boost the local y value by +- padlength / 2.
179  const StThreeVector<double>& lsPos = lsMidCoord.position();
180  StTpcLocalSectorCoordinate lsTopCoord(lsPos.x(),
181  lsPos.y()+padlength/2.,
182  lsPos.z(),
183  sector);
184  StTpcLocalSectorCoordinate lsBotCoord(lsPos.x(),
185  lsPos.y()-padlength/2.,
186  lsPos.z(),
187  sector);
188  //Transform back to global coordinates
189  StGlobalCoordinate gBotCoord, gMidCoord, gTopCoord;
190  transformer(lsTopCoord, gTopCoord);
191  transformer(lsBotCoord, gBotCoord);
192  transformer(lsMidCoord, gMidCoord);
193  const StThreeVector<double>& gTopPos = gTopCoord.position();
194  const StThreeVector<double>& gMidPos = gMidCoord.position();
195  const StThreeVector<double>& gBotPos = gBotCoord.position();
196  const StThreeVectorD gTopPosD(gTopPos.x(),gTopPos.y(),gTopPos.z());
197  const StThreeVectorD gMidPosD(gMidPos.x(),gMidPos.y(),gMidPos.z());
198  const StThreeVectorD gBotPosD(gBotPos.x(),gBotPos.y(),gBotPos.z());
199 
200  //Store in this form
201  PadrowLocation padLocation(gTopPosD, gMidPosD, gBotPosD);
202  HitMapQAKey myKey;
203  myKey.sector = sector;
204  myKey.padrow = padrow;
205  m_PadrowMap.insert(padrowMapValType(myKey,padLocation));
206  //cout <<sector<<"\t"<<padrow<<"\t"<<endl;
207  //padLocation.print();
208  }
209  }}
210 
211  cout<<"Done Building Maps"<<endl;
212  return;
213 }
map< HitMapQAKey, PadrowLocation, MapQAKeyLessThan > m_PadrowMap
Map of normal vectors to a sector.
pair< double, double > pathLength(double r) const
path length at given r (cylindrical r)
Definition: StHelix.cc:351
vector< StTpcHit * > m_tpcHitVec
Map of 3 points in each padrow.