25 #include <StMcEvent.hh>
26 #include <StMcEvent/StMcHit.hh>
27 #include <StMcIstHit.hh>
29 #include <StMcEvent/StMcIstHitCollection.hh>
37 #include "tables/St_g2t_ist_hit_Table.h"
38 #include "tables/St_HitError_Table.h"
39 #include "TGeoManager.h"
44 #include "StIstDbMaker/StIstDb.h"
45 #include "StIstUtil/StIstCollection.h"
46 #include "StIstUtil/StIstRawHitCollection.h"
47 #include "StIstUtil/StIstRawHit.h"
48 #include "StIstUtil/StIstConsts.h"
49 #include "StIstSlowSimMaker.h"
51 #include "tables/St_istSimPar_Table.h"
53 #include "tables/St_istMapping_Table.h"
54 #include "tables/St_istControl_Table.h"
56 #include <SystemOfUnits.h>
62 mMappingGeomVec.resize( kIstNumElecIds );
64 mCurrentTimeBinNum = 9;
65 fAdc =
new TF1(
"fAdc",
"landau",0,9);
66 fAdc->SetParameters(1.14288,3.8,1.168);
69 Int_t StIstSlowSimMaker::Init()
71 LOG_DEBUG<<
"StIstSlowSimMaker::Init()"<<endm;
75 ToWhiteConst(
"istRawAdcSimu",mIstCollectionPtr);
77 if(!mIstCollectionPtr ) {
78 LOG_WARN <<
"Error constructing istCollection" << endm;
88 LOG_DEBUG<<
"StIstSlowSimMaker::InitRun "<<runnumber<<endm;
98 LOG_ERROR <<
"InitRun : no istDb" << endm;
103 const istControl_st *istControlTable = mIstDb->getControl() ;
104 if (!istControlTable) {
105 LOG_ERROR <<
"Pointer to IST control table is null" << endm;
109 mDefaultTimeBin = istControlTable[0].kIstDefaultTimeBin;
110 mCurrentTimeBinNum = istControlTable[0].kIstCurrentTimeBinNum;
114 const istMapping_st *gM = mIstDb->getMapping();
116 LOG_ERROR <<
"Pointer to IST mapping table is null" << endm;
120 for(Int_t i=0; i<kIstNumElecIds; i++) {
121 LOG_DEBUG<<Form(
" PrInt_t entry %d : geoId=%d ",i,gM[0].mapping[i])<<endm;
122 Int_t geomIdTemp = gM[0].mapping[i];
123 mMappingGeomVec[geomIdTemp-1] = i;
128 mRndGen = (TRandom3 *)gRandom;
130 istSimPar_st
const*
const istSimParTable = mIstDb->istSimPar();
131 mHitEffMode = istSimParTable[0].mode;
132 mMomCut = istSimParTable[0].pCut;
133 mHitEff = istSimParTable[0].effIst;
135 LOG_INFO <<
" IST MC hit efficiency mode used for IST slow simulator: " << mHitEffMode << endm;
136 LOG_INFO <<
" +++ Hit Efficiency at p > " << mMomCut <<
" GeV/c = " << mHitEff << endm;
146 if (! mcEvent) {LOG_INFO <<
"No StMcEvent on input" << endl;
return kStWarn;}
149 if ( mBuildIdealGeom && !gGeoManager ) {
150 GetDataBase(
"VmcGeometry");
158 mIstCollectionPtr->setNumTimeBins(mCurrentTimeBinNum);
162 LOG_DEBUG<<
"ist MC hit collection found"<<endm;
163 Int_t nIsthits=istMcHitCol->numberOfHits();
165 if(istMcHitCol->layer(0)){
166 StSPtrVecMcIstHit mcHitVec = istMcHitCol->layer(0)->hits();
167 for(std::vector<StMcIstHit*>::iterator mcHitIt = mcHitVec.begin();mcHitIt!=mcHitVec.end(); ++mcHitIt){
168 LOG_DEBUG <<
"IST MC hit found ...... " << endm;
170 if(!mcIstHit)
continue;
172 switch (mHitEffMode) {
176 if(mcIstHit->parentTrack()) {
177 float const ptot = mcIstHit->parentTrack()->momentum().mag();
178 hitEff = 1.0 - (1. - mHitEff)*ptot/mMomCut;
179 if(hitEff<mHitEff) hitEff = mHitEff;
189 if( mRndGen->Rndm()>hitEff )
continue;
192 Double_t localIstHitPos[3]={mcIstHit->position().x(),mcIstHit->position().y(),mcIstHit->position().z()};
193 LOG_DEBUG <<
"StMcIstHit local position (before discretization) = " << localIstHitPos[0] <<
" " << localIstHitPos[1] <<
" " << localIstHitPos[2] << endm;
194 Int_t ladder = mcIstHit->ladder();
195 Int_t sensor = mcIstHit->wafer();
196 UShort_t meanColumn, meanRow;
199 getMCHitRowAndColumn(mcIstHit, meanColumn, meanRow);
202 Float_t rPhiPos_mean = (meanRow-1) * kIstPadPitchRow + 0.5 * kIstPadPitchRow;
203 Float_t zPos_mean = (meanColumn-1) * kIstPadPitchColumn + 0.5 * kIstPadPitchColumn;
204 localIstHitPos[0] = kIstSensorActiveSizeRPhi/2.0 - rPhiPos_mean;
205 localIstHitPos[2] = zPos_mean - kIstSensorActiveSizeZ/2.0;
207 LOG_DEBUG <<
"geometry position ladder = " << ladder <<
"\tsensor = " << sensor <<
"\tcolumn = " << meanColumn <<
"\trow = " << meanRow << endm;
208 LOG_DEBUG <<
"StMcIstHit local position (after discretization) = " << localIstHitPos[0] <<
" " << localIstHitPos[1] <<
" " << localIstHitPos[2] << endm;
210 StMcTrack *trackMC = mcIstHit->parentTrack();
211 Long_t pdgId = trackMC->pdgId();
212 Long_t idTruth = trackMC->key();
213 LOG_DEBUG <<
"trackMC pdgId = " << pdgId <<
"\tidTruth = " << idTruth << endm;
216 generateRawHits(mcIstHit);
220 LOG_DEBUG <<
"StIstSlowSimMaker::Make() -I- Loaded " << nIsthits <<
" IST MC raw hits. \n";
223 LOG_DEBUG <<
"No Ist MC hits found."<<endm;
226 LOG_DEBUG <<
"Number of IST MC raw hits produced by slow simulator: " << mIstCollectionPtr->getNumRawHits() << endm;
233 if(mIstCollectionPtr ) {
235 mIstCollectionPtr->getRawHitCollection(i)->Clear(opts);
248 Double_t localIstHitPos[3]={istMChit->position().x(),istMChit->position().y(),istMChit->position().z()};
249 Float_t rPhiPos = kIstSensorActiveSizeRPhi/2.0 - localIstHitPos[0];
250 Float_t zPos = localIstHitPos[2] + kIstSensorActiveSizeZ/2.0;
251 if(rPhiPos<0||zPos<0){
252 LOG_WARN<<
"StIstSlowSimMaker::getMCHitRowAndColumn Wrong local position rPhiPos = "<<rPhiPos<<
" zPos = "<<zPos<<endm;
254 meanColumn = (UShort_t)floor( zPos/kIstPadPitchColumn ) + 1;
255 meanRow = (UShort_t)floor( rPhiPos/kIstPadPitchRow ) + 1;
259 void StIstSlowSimMaker::generateRawHits(
const StMcIstHit *istMChit)
const
261 LOG_DEBUG <<
"StIstSlowSimMaker::generateRawHits - Calculating pad row and column ... " << endm;
262 Int_t ladderId = istMChit->ladder();
263 Int_t sensorId = istMChit->wafer();
264 UShort_t meanColumn, meanRow;
265 getMCHitRowAndColumn(istMChit, meanColumn, meanRow);
267 Double_t dS = istMChit->dS();
268 StThreeVectorD midPos(istMChit->position().x(),istMChit->position().y(),istMChit->position().z());
269 Double_t mcLocPx = istMChit->localMomentum().x();
270 Double_t mcLocPy = istMChit->localMomentum().y();
271 Double_t mcLocPz = istMChit->localMomentum().z();
274 Double_t mcLocTot = mcLocP.mag();
280 LOG_DEBUG<<
"istMcHit geometry position ladder = " << ladderId <<
"\tsensor = " << sensorId <<
"\tcolumn = " << meanColumn <<
"\trow = " << meanRow << endm;
281 LOG_DEBUG<<
"istMcHit local position x = "<<midPos.x()<<
"\ty = "<<midPos.y()<<
"\tz = "<<midPos.z()<<endm;
282 LOG_DEBUG<<
"istMcHit local position enter x = "<<inPos.x()<<
"\ty = "<<inPos.y()<<
"\tz = "<<inPos.z()<<endm;
283 LOG_DEBUG<<
"istMcHit local position exit x = "<<outPos.x()<<
"\ty = "<<outPos.y()<<
"\tz = "<<outPos.z()<<endm;
284 LOG_DEBUG<<
"istMcHit local momentum x = "<<mcLocP.x()<<
"\ty = "<<mcLocP.y()<<
"\tz = "<<mcLocP.z()<<endm;
285 LOG_DEBUG<<
"istMcHit local direction x = "<<mcLocalDir.x()<<
"\ty = "<<mcLocalDir.y()<<
"\tz = "<<mcLocalDir.z()<<endm;
286 LOG_DEBUG<<
"istMcHit dS = "<<dS<<
"\ttotMom = "<<mcLocTot<<endl;
288 vector<StThreeVectorD> crossVec;
289 LOG_DEBUG<<
"transforming to sensor coordinates"<<endm;
290 transformToSensor(inPos);
291 transformToSensor(outPos);
292 LOG_DEBUG<<
"inPos x = "<<inPos.x()<<
"\ty = "<<inPos.y()<<
"\tz = "<<inPos.z()<<endm;
293 LOG_DEBUG<<
"outPos x = "<<outPos.x()<<
"\ty = "<<outPos.y()<<
"\tz = "<<outPos.z()<<endm;
295 checkPadCrossing(inPos, outPos, mcLocalDir, dS, crossVec);
296 LOG_DEBUG<<
"StIstSlowSimMaker::generateRawHits crossVec.size() = "<<crossVec.size()<<endm;
297 if(crossVec.size()==1) {
298 LOG_WARN<<
"StIstSlowSimMaker: McHit is outside of active area -> skip!"<<endm;
302 StThreeVectorD totalPath = crossVec[crossVec.size()-1]-crossVec[0];
303 Double_t pathLengthTotal = totalPath.mag();
304 LOG_DEBUG<<
"inPos x = "<<crossVec[0].x()<<
"\ty = "<<crossVec[0].y()<<
"\tz = "<<crossVec[0].z()<<endm;
308 const Double_t sidEdx = 3.87;
309 const Double_t sensorThickness = 0.03;
310 const Double_t mip = 441.0;
311 const Double_t kIstMPV = mip / (sidEdx * 1e-3 * sensorThickness);
312 Double_t kIstTimeBinFrac[mCurrentTimeBinNum];
314 Int_t maxTB = mCurrentTimeBinNum/2;
315 Double_t mean = fAdc->GetParameter(1);
316 Double_t sum = fAdc->Integral(mean-0.5-maxTB,mean-0.5+(mCurrentTimeBinNum-maxTB));
317 for(Int_t iTB=0; iTB<mCurrentTimeBinNum; iTB++){
319 kIstTimeBinFrac[iTB] = fAdc->Integral(mean-0.5-maxTB+iTB,mean-0.5-maxTB+iTB+1)/sum;
321 LOG_WARN<<
"StIstSlowSimMaker: integral of adc spectrum = 0"<<endm;
326 if(istRawHitCollection) {
327 for (UInt_t i = 0; i < crossVec.size()-1; ++i) {
328 LOG_DEBUG<<
"i = "<<i+1<<
"\tpos x = "<<crossVec[i+1].x()<<
"\ty = "<<crossVec[i+1].y()<<
"\tz = "<<crossVec[i+1].z()<<endm;
332 Double_t pathLength = path.mag();
333 Double_t rPhiPos_mean, zPos_mean;
334 findPad(meanPos, meanColumn, meanRow, rPhiPos_mean, zPos_mean);
338 Int_t geoId = (ladderId-1)*kIstNumApvChannels*kIstApvsPerLadder+ (sensorId-1)*(kIstNumApvsPerArm/2)*(kIstNumApvChannels/2) + (meanColumn-1)*kIstNumApvChannels/2 + meanRow;
339 Int_t elecId = mMappingGeomVec[geoId-1];
340 LOG_DEBUG <<
"elecID = " << elecId <<
"\tgeoId = " << geoId << endm;
342 Int_t idTruth = istMChit->parentTrack()->key();
345 Float_t angleCorr = fabs(mcLocalDir.dot(normal));
346 LOG_DEBUG<<
"incident angle w.r.t. sensor surface normal direction: "<<angleCorr<<endm;
348 StIstRawHit *rawHit = istRawHitCollection->getRawHit(elecId);
351 for (UChar_t t = 0; t < mCurrentTimeBinNum; t++) {
352 Float_t adcSum = 0.0;
354 adcSum += rawHit->getCharge(t);
357 LOG_DEBUG<<
"dE = "<<1e6*istMChit->dE()<<
" keV \tpathLength = "<<pathLength<<
"\tpathLengthTotal = "<<pathLengthTotal<<endm;
359 if(pathLengthTotal>1e-6) charge = istMChit->dE() * pathLength / pathLengthTotal;
360 if(kIstTimeBinFrac[maxTB]>0) charge *= kIstTimeBinFrac[t]*kIstMPV/kIstTimeBinFrac[maxTB];
361 if ( charge > adcSum ) {
362 rawHit->setIdTruth(idTruth);
366 rawHit->setCharge(adcSum, t);
367 LOG_DEBUG<<
"charge = "<<adcSum<<
"\tat TB"<<(Int_t)t<<endm;
369 rawHit->setChannelId( elecId );
370 rawHit->setGeoId( geoId );
371 rawHit->setDefaultTimeBin( mDefaultTimeBin );
373 LOG_DEBUG <<
"rawHitPosition ladder = " <<(Int_t)rawHit->
getLadder()<<
"\tsensor = " <<(Int_t)rawHit->
getSensor()<<
"\tcolumn = "<<(Int_t)rawHit->
getColumn()<<
"\trow = "<<(Int_t)rawHit->
getRow()<< endm;
377 LOG_WARN <<
"StIstSlowSimMaker: No rawHitCollection found for ladder " << ladderId << endm;
391 Double_t rPhiPosMean;
393 Double_t rPhiPosMean_out;
394 Double_t zPosMean_out;
397 cross_vec.push_back(inPos);
400 findPad(outPos, column_out, row_out, rPhiPosMean_out, zPosMean_out);
401 findPad(inPos, column, row, rPhiPosMean, zPosMean);
403 LOG_DEBUG<<
"StIstSlowSimMaker::checkPadCrossing"<<endm;
404 LOG_DEBUG<<
"\tcolumn_out = "<<column_out<<
"\trow_out = "<<row_out<<endm;
405 LOG_DEBUG<<
"\tcolumn_in = "<<column<<
"\trow_in = "<<row<<endm;
407 if(column==65535||column_out==65535)
return;
409 mcLocalDir.setX(-mcLocalDir.x());
411 Short_t row_dist = abs(row-row_out);
412 Short_t column_dist = abs(column-column_out);
414 LOG_DEBUG<<
"StIstSlowSimMaker::checkPadCrossing column_dist = "<<column_dist<<
"\trow_dist = "<<row_dist<<endm;
418 unsigned short row_next = row;
419 unsigned short column_next = column;
421 while(row_dist>=1 || column_dist>=1)
425 StThreeVectorD halfPad(direction(mcLocalDir.x())*kIstPadPitchRow/2.0,
426 direction(mcLocalDir.y())*scaleFromYvsX(mcLocalDir, kIstPadPitchRow/2.0),
427 direction(mcLocalDir.z())*kIstPadPitchColumn/2.0);
429 LOG_DEBUG<<
"current x = "<<current.x()<<
"\ty = "<<current.y()<<
"\tz = "<<current.z()<<endm;
431 distanceToBorder(current, mcLocalDir, mean, distance);
432 LOG_DEBUG<<
"current x = "<<current.x()<<
"\ty = "<<current.y()<<
"\tz = "<<current.z()<<endm;
436 LOG_DEBUG<<
"current_next x = "<<current_next.x()<<
"\ty = "<<current_next.y()<<
"\tz = "<<current_next.z()<<endm;
439 findPad(current_next, column_next, row_next, rPhiPosMean, zPosMean);
441 if(row_next==row && column_next==column) {
442 LOG_WARN <<
" distance calculating not yielding to the next row/column! Break! " << endm;
447 column = column_next;
449 cross_vec.push_back(current);
451 row_dist = abs(row-row_out);
452 column_dist = abs(column-column_out);
455 cross_vec.push_back(outPos);
464 Double_t rPhiPos = hitPos.x();
465 Double_t zPos = hitPos.z();
467 if(rPhiPos<-kIstPadPitchRow/2.||rPhiPos>kIstSensorActiveSizeRPhi+kIstPadPitchRow/2.||zPos<-kIstPadPitchColumn/2.||zPos>kIstSensorActiveSizeZ+kIstPadPitchColumn/2.){
468 LOG_ERROR<<
"StIstSlowSimMaker::findPad Wrong local position rPhiPos = "<<rPhiPos<<
" zPos = "<<zPos<<endm;
469 column = row = rPhiPos_mean = zPos_mean = 65535;
472 row = (UShort_t)floor( rPhiPos/kIstPadPitchRow ) + 1;
475 column = (UShort_t)floor( zPos/kIstPadPitchColumn ) + 1;
476 if(column<1) column = 1;
478 rPhiPos_mean = (row-1) * kIstPadPitchRow + 0.5 * kIstPadPitchRow;
479 zPos_mean = (column-1) * kIstPadPitchColumn + 0.5 * kIstPadPitchColumn;
482 void StIstSlowSimMaker::transformToSensor(
StThreeVectorD &hitPos)
const
484 hitPos.setX(kIstSensorActiveSizeRPhi/2.0 - hitPos.x());
485 hitPos.setZ(hitPos.z() + kIstSensorActiveSizeZ/2.0);
490 StThreeVectorD halfPad(kIstPadPitchRow/2.0, 0.0150, kIstPadPitchColumn/2.0);
491 LOG_DEBUG<<
"distanceToBorder() mean x = "<<mean.x()<<
"\ty = "<<mean.y()<<
"\tz = "<<mean.z()<<endm;
494 Double_t plane_x = mean.x()+direction(dir.x())*halfPad.x();
495 Double_t diff_x = plane_x-hitPos.x();
498 Double_t plane_z = mean.z()+direction(dir.z())*halfPad.z();
499 Double_t diff_z = plane_z-hitPos.z();
501 LOG_DEBUG<<
"yz plane x = "<<plane_x<<
"\txy plane z = "<<plane_z<<endm;
502 LOG_DEBUG<<
"diff_x = "<<diff_x<<
"\tdiff_z = "<<diff_z<<endm;
503 LOG_DEBUG<<
"dir x = "<<dir.x()<<
"\ty = "<<dir.y()<<
"\tz = "<<dir.z()<<endm;
505 if(fabs(dir.x())<1e-6)
508 dist.setY(scaleFromYvsZ(dir, diff_z));
511 if(fabs(dir.z())<1e-6)
514 dist.setY(scaleFromYvsX(dir, diff_x));
517 if(diff_x/dir.x()<=diff_z/dir.z())
520 dist.setZ(diff_x*dir.z()/dir.x());
524 dist.setX(diff_z*dir.x()/dir.z());
528 dist.setY(scaleFromYvsX(dir, dist.x()));
529 LOG_DEBUG<<
"dist x = "<<dist.x()<<
"\ty = "<<dist.y()<<
"\tz = "<<dist.z()<<endm;
534 Double_t StIstSlowSimMaker::direction(
const Double_t x)
const
536 return (x>0) - (x<0);
539 Double_t StIstSlowSimMaker::scaleFromYvsX(
const StThreeVectorD vec,
const Double_t a)
const
541 if(fabs(vec.x())>1e-6)
return a*vec.y()/vec.x();
543 LOG_WARN<<
"StIstSlowSimMaker::scaleFromYvsX x component is 0"<<endm;
548 Double_t StIstSlowSimMaker::scaleFromYvsZ(
const StThreeVectorD vec,
const Double_t a)
const
550 if(fabs(vec.z())>1e-6)
return a*vec.y()/vec.z();
552 LOG_WARN<<
"StIstSlowSimMaker::scaleFromYvsZ z component is 0"<<endm;
unsigned char getLadder() const
1-24
unsigned char getColumn() const
1-12
virtual void Clear(Option_t *option="")
User defined functions.
const int kIstNumLadders
24 IST Ladders
Monte Carlo Track class All information on a simulated track is stored in this class: kinematics...
unsigned char getRow() const
1-64
void getMCHitRowAndColumn(const StMcIstHit *istMChit, UShort_t &meanColumn, UShort_t &meanRow) const
void findPad(const StThreeVectorD hitPos, UShort_t &column, UShort_t &row, Double_t &rPhiPos_mean, Double_t &zPos_mean) const
int getChannelId() const
0-110591
const int kIstNumColumnsPerSensor
12 columns in beam direction per each sensor
void checkPadCrossing(const StThreeVectorD inPos, const StThreeVectorD outPos, StThreeVectorD mcLocalDir, Double_t dS, vector< StThreeVectorD > &cross_vec) const
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Event data structure to hold all information from a Monte Carlo simulation. This class is the interfa...
unsigned char getSensor() const
1-6
const int kIstNumRowsPerSensor
64 rows in r-phi direction per each sensor
void Clear(Option_t *opts="")
User defined functions.
Int_t InitRun(Int_t runNumber)