00001
00002
00003
00004
00005
00007
00008
00009
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00039 #include "float.h"
00040 #include "TpcMapUtilities.h"
00041 #include "TpcHitUtilities.h"
00042 #include "StEventTypes.h"
00043 #include "StThreeVectorD.hh"
00044 #include <algorithm>
00045
00046 #include "StDbUtilities/StTpcCoordinateTransform.hh"
00047 #include "StDbUtilities/StTpcLocalSectorCoordinate.hh"
00048 #include "StDbUtilities/StTpcPadCoordinate.hh"
00049 #include "StDbUtilities/StGlobalCoordinate.hh"
00050 #include "StTpcDb/StTpcDb.h"
00051
00052 #ifndef ST_NO_NAMESPACES
00053 using std::sort;
00054 using std::pair;
00055 #endif
00056
00057 TpcHitUtilities::TpcHitUtilities()
00058 {
00059 buildMaps();
00060 clear();
00061 }
00062
00063 TpcHitUtilities::TpcHitUtilities(StTrack* tck, double magneticField)
00064 {
00065 buildMaps();
00066 clear();
00067 m_StTrack = tck;
00068 m_BField = magneticField;
00069 }
00070
00071 TpcHitUtilities::~TpcHitUtilities() {}
00072
00073
00074 void TpcHitUtilities::clear()
00075 {
00076 m_StTrack = 0;
00077 m_BField = 0.;
00078 m_tpcHitVec.clear();
00079 return;
00080 }
00081
00082 void TpcHitUtilities::setTrack(StTrack* tck)
00083 {
00084 m_StTrack = tck;
00085 return;
00086 }
00087
00088 void TpcHitUtilities::setBField(double b)
00089 {
00090 m_BField = b;
00091 return;
00092 }
00093
00094 const vector<StTpcHit*>& TpcHitUtilities::tpcHitVec() const { return m_tpcHitVec;}
00095
00096
00097 void TpcHitUtilities::findHits()
00098 {
00099 StPtrVecHit vec = m_StTrack->detectorInfo()->hits(kTpcId);
00100 StPtrVecHitIterator iter;
00101 StTpcHit* hit;
00102
00103 for (iter = vec.begin(); iter != vec.end(); iter++) {
00104 if (*iter){
00105 hit = dynamic_cast<StTpcHit*>(*iter);
00106 if (hit) { m_tpcHitVec.push_back(hit); }
00107 }
00108 }
00109 return;
00110 }
00111
00112
00113
00114 bool TpcHitUtilities::keepHit(StTpcHit* tpcHit)
00115 {
00116 if (tpcHit->flag()==0) {return true;}
00117 else {return false;}
00118
00119 }
00120
00121
00122 const StThreeVectorD TpcHitUtilities::sectorNormal(int sector)
00123 {
00124 int numSectors = gStTpcDb->Dimensions()->numberOfSectors();
00125 double beta = (sector > 12) ?(numSectors-sector)*2.*M_PI/(static_cast<double>(numSectors)/2.): sector*2.*M_PI/(static_cast<double>(numSectors)/2.);
00126 const StThreeVectorD vec(sin(beta), cos(beta), 0.);
00127 return vec;
00128 }
00129
00130
00131 double TpcHitUtilities::dx(StTpcHit* tpcHit)
00132 {
00133 double ds=0.;
00134 HitMapQAKey mykey;
00135 mykey.sector = tpcHit->sector();
00136 mykey.padrow = tpcHit->padrow();
00137 PadrowLocation padLoc = m_PadrowMap[mykey];
00138 const StThreeVectorD normal = m_SectorNormalMap[tpcHit->sector()];
00139 double s_out = m_StTrack->geometry()->helix().pathLength(padLoc.outsidePoint(), normal);
00140 double s_in = m_StTrack->geometry()->helix().pathLength(padLoc.insidePoint(), normal);
00141 ds = s_out-s_in;
00142 if (ds < 0.) {ds = -1.*ds;}
00143 if (s_out==DBL_MAX || s_in==DBL_MAX) {ds = 0.;}
00144 return ds;
00145 }
00146
00147 void TpcHitUtilities::buildMaps()
00148 {
00149 StTpcCoordinateTransform transformer(gStTpcDb);
00150
00151 {for (int sector=1; sector<=24; sector++) {
00152 m_SectorNormalMap[sector] = sectorNormal(sector);
00153 }}
00154
00155
00156
00157 {for (int sector=1; sector<=24; sector++) {
00158
00159 for (int padrow=1; padrow<=45; padrow++) {
00160 double padlength;
00161 if (padrow<14) {
00162 padlength = gStTpcDb->PadPlaneGeometry()->innerSectorPadLength();}
00163 else {
00164 padlength = gStTpcDb->PadPlaneGeometry()->outerSectorPadLength();}
00165
00166
00167 StTpcPadCoordinate padCoord(sector, padrow, 1, 1);
00168 StTpcLocalSectorCoordinate lsMidCoord;
00169 transformer(padCoord, lsMidCoord);
00170
00171
00172 const StThreeVector<double>& lsPos = lsMidCoord.position();
00173 StTpcLocalSectorCoordinate lsTopCoord(lsPos.x(),
00174 lsPos.y()+padlength/2.,
00175 lsPos.z(),
00176 sector);
00177 StTpcLocalSectorCoordinate lsBotCoord(lsPos.x(),
00178 lsPos.y()-padlength/2.,
00179 lsPos.z(),
00180 sector);
00181
00182 StGlobalCoordinate gBotCoord, gMidCoord, gTopCoord;
00183 transformer(lsTopCoord, gTopCoord);
00184 transformer(lsBotCoord, gBotCoord);
00185 transformer(lsMidCoord, gMidCoord);
00186 const StThreeVector<double>& gTopPos = gTopCoord.position();
00187 const StThreeVector<double>& gMidPos = gMidCoord.position();
00188 const StThreeVector<double>& gBotPos = gBotCoord.position();
00189 const StThreeVectorD gTopPosD(gTopPos.x(),gTopPos.y(),gTopPos.z());
00190 const StThreeVectorD gMidPosD(gMidPos.x(),gMidPos.y(),gMidPos.z());
00191 const StThreeVectorD gBotPosD(gBotPos.x(),gBotPos.y(),gBotPos.z());
00192
00193
00194 PadrowLocation padLocation(gTopPosD, gMidPosD, gBotPosD);
00195 HitMapQAKey myKey;
00196 myKey.sector = sector;
00197 myKey.padrow = padrow;
00198 m_PadrowMap.insert(padrowMapValType(myKey,padLocation));
00199
00200
00201 }
00202 }}
00203
00204 cout<<"Done Building Maps"<<endl;
00205 return;
00206 }