66 #include "StMessMgr.h"
69 #include "StPxlFastSim.h"
70 #include "StEvent/StPxlHit.h"
71 #include "StEvent/StPxlHitCollection.h"
72 #include "StMcEvent/StMcPxlHitCollection.hh"
73 #include "StMcEvent/StMcPxlHit.hh"
74 #include "tables/St_HitError_Table.h"
75 #include "StarClassLibrary/StRandom.hh"
76 #include "StThreeVectorF.hh"
77 #include "StPxlDbMaker/StPxlDb.h"
78 #include "StPxlUtil/StPxlConstants.h"
79 #include "StPxlUtil/StPxlDigiHit.h"
81 #include "TGeoManager.h"
82 #include "TGeoMatrix.h"
85 #include "TObjectSet.h"
89 if (mRandom)
delete mRandom;
90 if (mPxlDb)
delete mPxlDb;
96 LOG_INFO <<
"StPxlFastSim::init()" << endm;
103 LOG_ERROR <<
"StPxlFastSim - E - mPxlDb is not available" << endm;
108 LOG_INFO <<
"StPxlFastSim - Using geometry from pxlDB" <<endm;
113 LOG_INFO <<
"StPxlFastSim - Using ideal geometry" <<endm;
116 if (!mRandom) mRandom =
new StRandom();
119 Int_t seed = time(NULL);
120 mRandom->setSeed(seed);
121 LOG_INFO <<
"StPxlFastSim - smearing random generator is using random seed = " << seed <<endm;
125 LOG_INFO <<
"StPxlFastSim - smearing random generator is using default seed" <<endm;
128 St_HitError *pxlTableSet = (St_HitError*)calib_db.
Find(
"PixelHitError");
132 LOG_ERROR <<
"StPxlFastSim - E - PixelHitError is not available" << endm;
136 HitError_st* pxlHitError = pxlTableSet->GetTable();
140 LOG_ERROR <<
"StPxlFastSim - E - pxl hit table is not available in PixelHitError" << endm;
146 if (pxlHitError->coeff[0] <= 0 || pxlHitError->coeff[3] <= 0)
148 LOG_ERROR <<
"StPxlFastSim - E - negative or corrupted PXL hits errors in DB" << endm;
152 mResXPix = std::sqrt(pxlHitError->coeff[0]);
153 mResZPix = std::sqrt(pxlHitError->coeff[3]);
162 Float_t smearedX = 0, smearedY = 0, smearedZ = 0;
166 for (UInt_t iSec = 0; iSec < mcPxlHitCol.numberOfSectors(); iSec++)
169 if (!mcPxlSectorHitCol)
continue;
171 for (UInt_t iLad = 0; iLad < mcPxlSectorHitCol->numberOfLadders(); iLad++)
174 if (!mcPxlLadderHitCol)
continue;
176 for (UInt_t iSen = 0; iSen < mcPxlLadderHitCol->numberOfSensors(); iSen++)
179 if (!mcPxlSensorHitCol)
continue;
181 UInt_t nSenHits = mcPxlSensorHitCol->hits().size();
182 LOG_DEBUG <<
"Sector/Ladder/Sensor = " << iSec + 1 <<
"/" << iLad + 1 <<
"/" << iSen + 1 <<
". Number of sensor hits = " << nSenHits << endm;
185 for (UInt_t iHit = 0; iHit < nSenHits; iHit++)
187 StMcPxlHit* mcPix = mcPxlSensorHitCol->hits()[iHit];
190 Int_t sector = mcPix->
sector();
191 Int_t ladder = mcPix->
ladder();
194 Double_t localPixHitPos[3] = {mcPix->position().x(), mcPix->position().y(), mcPix->position().z()};
196 LOG_DEBUG <<
"localPixHitPos = " << localPixHitPos[0] <<
" " << localPixHitPos[1] <<
" " << localPixHitPos[2] << endm;
199 smearedX = distortHit(localPixHitPos[0], mResXPix, StPxlConsts::kPxlActiveLengthX / 2.0);
200 smearedZ = distortHit(localPixHitPos[2], mResZPix, StPxlConsts::kPxlActiveLengthY / 2.0);
201 if (mResYPix) smearedY = distortHit(localPixHitPos[1], mResYPix, 0.0020);
202 else smearedY = localPixHitPos[1];
203 localPixHitPos[0] = smearedX;
204 localPixHitPos[2] = smearedZ;
205 localPixHitPos[1] = smearedY;
206 LOG_DEBUG <<
"smearedlocal = " << localPixHitPos[0] <<
" " << localPixHitPos[1] <<
" " << localPixHitPos[2] << endm;
207 Double_t smearedGlobalPixHitPos[3] = {0, 0, 0};
208 localToMatser(localPixHitPos,smearedGlobalPixHitPos,iSec+1,iLad+1,iSen+1);
213 UInt_t hw = sector * 10 + ladder;
215 unsigned short idTruth = mcPix->parentTrack() ? mcPix->parentTrack()->key() : -999;
216 unsigned short quality = mcPix->parentTrack() ? 100 : 0;
219 gpixpos, mRndHitError, hw, mcPix->dE(), 0, idTruth, quality, mcPix->key());
221 LOG_DEBUG <<
"key() : " << mcPix->key() - 1 <<
" idTruth: " << mcPix->parentTrack()->key() << endm;
222 LOG_DEBUG <<
"from StMcPxlHit : x= " << mcPix->position().x() <<
"; y= " << mcPix->position().y() <<
"; z= " << mcPix->position().z() << endm;
223 LOG_DEBUG <<
"pxlHit location x= " << tempHit->position().x() <<
"; y= " << tempHit->position().y() <<
"; z= " << tempHit->position().z() << endm;
225 pxlHitCol.addHit(tempHit);
241 double StPxlFastSim::distortHit(
const double x,
const double res,
const double detLength)
const
244 if (std::fabs(x) > detLength) {
245 LOG_WARN <<
"distortHit() - Generated hit is outside detector sensor plane" << endm;
252 smeared_x = mRandom->gauss(x, res);
253 }
while ( std::fabs(smeared_x) > detLength);
260 void StPxlFastSim::localToMatser(Double_t* local,Double_t* master,Int_t sector,Int_t ladder,Int_t sensor)
264 TGeoHMatrix *combP = (TGeoHMatrix *)mPxlDb->geoHMatrixSensorOnGlobal(sector, ladder,sensor);
265 combP->LocalToMaster(local, master);
271 Path = Form(
"/HALL_1/CAVE_1/TpcRefSys_1/IDSM_1/PXMO_1/PXLA_%i/LADR_%i/PXSI_%i/PLAC_1", sector, ladder, sensor);
273 gGeoManager->RestoreMasterVolume();
274 gGeoManager->CdTop();
275 gGeoManager->cd(Path);
277 gGeoManager->GetCurrentMatrix()->LocalToMaster(local, master);
Int_t addPxlHits(const StMcPxlHitCollection &, StPxlHitCollection &)
creates an StPxlHit object for every StMcPxlHit, and fills the hit StPxlHitCollection container...
Int_t initRun(const TDataSet &calib_db, const TObjectSet *pxlDbDataSet, const Int_t run)
A random seed is passed to mRandom PXL smearing resolutions (PixelHitError) are fetched from calib_db...
~StPxlFastSim()
This class does not own any hit containers. mRandom is deleted here.
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
virtual TDataSet * Find(const char *path) const