13 #include "StFgtSlowSimuMaker.h"
15 #include "tables/St_g2t_fgt_hit_Table.h"
16 #include "StFgtDbMaker/StFgtDbMaker.h"
17 #include "StFgtDbMaker/StFgtDb.h"
19 #include "StRoot/StEvent/StFgtCollection.h"
20 #include "StRoot/StEvent/StEvent.h"
27 memset(hA,0,
sizeof(hA));
30 mRnd =
new TRandom3();
36 const Float_t StFgtSlowSimuMaker::pulseShape[20]={0.0,0.1,0.3,0.4,0.2,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
42 for(i=0;i<kFgtNumDiscs;i++){
43 for(j=0;j<kFgtNumQuads;j++) {
54 StFgtSlowSimuMaker::~StFgtSlowSimuMaker(){
61 StFgtSlowSimuMaker::saveHisto(TString fname){
63 #ifdef __FGT_QA_HISTO__
66 TString outName=fname+
".hist.root";
67 TFile f( outName,
"recreate");
69 printf(
"%d histos are written to '%s' ...\n",HList->GetEntries(),outName.Data());
83 LOG_INFO<<
"::Finish() \n"<< endm;
85 #ifdef __FGT_QA_HISTO__
86 TString a(
"fgtSlowSimQA");
97 StFgtSlowSimuMaker::InitRun(Int_t runNumber){
98 LOG_INFO<<
"::InitRun() "<< runNumber<< endm;
103 LOG_ERROR<<
"StFgtSlowSimuMaker::InitRun could not find FgtDb Maker"<<endm;
106 fgtDb=dbmkr->getDbTables();
108 LOG_ERROR<<
"StFgtSlowSimuMaker::InitRun could not find FgtDb table from FgtDbMaker"<<endm;
113 LOG_INFO<< Form(
"fgt-simu-params from DB, ver=%.0f:\n",fgtDb->getSimuParam(0))<<endl;
117 par_cutoffOfBichel=fgtDb->getSimuParam(1);
118 par_pairsPerCm =fgtDb->getSimuParam(2);
119 par_trackTOFcutoff=fgtDb->getSimuParam(3);
120 par_XYamplSigma =fgtDb->getSimuParam(4) ;
121 par_trackPcutoff =fgtDb->getSimuParam(5);
122 par_transDiffusionPerPath=fgtDb->getSimuParam(6);
123 par_binStep=fgtDb->getSimuParam(7);
126 par_stripThreshAdc=fgtDb->getSimuParam(10);
127 par_2DampCutoffScale=fgtDb->getSimuParam(11);
128 par_overalGain=fgtDb->getSimuParam(12);
129 LOG_INFO<<
"par_overalGain from DB = " << par_overalGain <<
", but overwriting to 20 for now. Need fix in DB later"<<endm;
131 par_PplaneChargeFraction=fgtDb->getSimuParam(13);
133 LOG_INFO<<Form(
"::InitRun() runNo=%d badSetup=0x%x; params: track cutoff: TOF<%.1fns and P>%.1f MeV/c ; prim ions/cm=%.1f, X,YamplSigma=%.4f cm, stripThres=%.2f (ADC), transDiffusion=%.1f um/1cm, cutoffOfBichel=%d, binStep=%d Digi: 2DampCutoffScale=%.1f a.u., overalGain=%.2f a.u. P-planeChargFract=%.2f switch_addPeds=%d", runNumber, par_badSetup,
134 par_trackTOFcutoff*1e9,par_trackPcutoff*1e3,
135 par_pairsPerCm, par_XYamplSigma,par_stripThreshAdc,
136 par_transDiffusionPerPath*1e4,
137 par_cutoffOfBichel, par_binStep,
138 par_2DampCutoffScale,par_overalGain,par_PplaneChargeFraction,
139 switch_addPeds)<< endm;
142 if(par_XYamplSigma<=0) par_badSetup+=0x2;
143 if(par_pairsPerCm <=0) par_badSetup+=0x4;
154 StFgtSlowSimuMaker::Init(){
156 LOG_INFO<<
"::Init()"<< endm;
160 #ifdef __FGT_QA_HISTO__
166 #ifdef __FGT_QA_HISTO__
174 return StMaker::Init();
186 LOG_ERROR<< Form(
" Make skips FGT content for this event %d because of incorrect initialization from DB, val=0x%0x",mInpEve,par_badSetup);
196 LOG_WARN <<
"StEvent is missing. FGT slow simulator skipping event" << endl;
200 mEventId=mEvent->id();
201 LOG_INFO <<Form(
"%s::Make() inpEve=%d, eveId=%d",
GetName(),mInpEve,mEventId)<<endm;
209 mEvent->setFgtCollection(fgtX);
211 fgtColl= mEvent-> fgtCollection();
221 St_g2t_fgt_hit *fgt_hitT = (St_g2t_fgt_hit *) GetDataSet(
"g2t_fgt_hit");
223 LOG_FATAL<<Form(
"g2t_Fgt table empty")<<endm;
228 unpack_g2t_hits( fgt_hitT );
234 Int_t iDisc=0,iQuad=0;
235 for(iDisc=0;iDisc<kFgtNumDiscs ;iDisc++) {
236 for(iQuad=0;iQuad<kFgtNumQuads;iQuad++) {
238 quadDigitizationXY->Reset();
239 quadDigitizationRad->Reset(); quadDigitizationPhi->Reset();
241 vector<fgt_g2t_auxil> &L=
mG2tHitList[iDisc][iQuad];
242 if(L.size()<=0)
continue;
243 Int_t stripIdOffset= kFgtNumStrips * ( iDisc*kFgtNumQuads + iQuad)*2;
244 if(debug) LOG_INFO<<Form(
"Process g2t hits in disk=%d quad=%d nHit=%d idOff=%d",iDisc,iQuad,L.size(),stripIdOffset)<<endm;
245 for(UInt_t i=0;i<L.size();i++) {
246 responseMipModel(L[i].Rloc,L[i].Dloc);
247 #ifdef __FGT_QA_HISTO__
248 hA[11+iDisc] ->Fill(L[i].Rlab.x(),L[i].Rlab.y());
251 printf(
"DIGIXY Lab: Disc=%1d Quad=%1d itr=%d x=%8.4f y=%8.4f z=%8.4f R=%8.4f phi=%10.6f\n",
252 iDisc,iQuad,i,L[i].Rlab.X(),L[i].Rlab.Y(),L[i].Rlab.Z(),L[i].Rlab.Perp(), L[i].Rlab.Phi());
253 printf(
"DIGIXY Loc: Disc=%1d Quad=%1d itr=%d x=%8.4f y=%8.4f z=%8.4f R=%8.4f phi=%10.6f\n",
254 iDisc,iQuad,i,L[i].Rloc.X(),L[i].Rloc.Y(),L[i].Rloc.Z(),L[i].Rloc.Perp(), L[i].Rloc.Phi());
258 if(quadDigitizationXY->Integral()<0.1)
continue;
259 projectQuad2strips( iDisc, iQuad);
261 exportStripPlane2StEvent(quadDigitizationRad,stripIdOffset,fgtColl->getStripCollection(iDisc));
262 exportStripPlane2StEvent(quadDigitizationPhi,stripIdOffset+kFgtNumStrips,fgtColl->getStripCollection(iDisc));
266 LOG_INFO<<Form(
"End of fgt-slow-simu FgtColl: numDisc=%d, total strips=%d",fgtColl->getNumDiscs(),fgtColl -> getNumStrips() )<<endm;
269 for(iDisc=0; iDisc <(int)fgtColl->getNumDiscs(); iDisc++) {
274 StSPtrVecFgtStrip &stripVec = stripPtr->getStripVec();
276 for( StSPtrVecFgtStripIterator it=stripVec.begin();it!=stripVec.end();++it, ih++) {
278 Short_t discX, quadrantX, stripX; Char_t layerX;
279 StFgtGeom::decodeGeoId(((*it))->getGeoId(),discX,quadrantX, layerX, stripX);
282 LOG_DEBUG<<Form(
"iDisc=%d ih=%d strip: geoId=%d ADC=%d charge=%.1f deco0: strip=%d quad=%d oct=%d plane=%c disc=%d \n",iDisc,ih,((*it))->getGeoId(),((*it))->getAdc(0),((*it))->getCharge(),stripX,quadrantX,stripX>=300,layerX,discX)<<endm;
295 StFgtSlowSimuMaker::unpack_g2t_hits( St_g2t_fgt_hit *fgt_hitT){
296 g2t_fgt_hit_st *hitPtr = fgt_hitT->GetTable();
301 Int_t nhits = fgt_hitT->GetNRows();
302 for(Int_t ih=0; ih<nhits; ih++,hitPtr++) {
303 Int_t ivid = hitPtr->volume_id;
304 Double_t de_keV= hitPtr->de*1e6;
305 Double_t tof_ns=hitPtr->tof*1.e9;
308 Int_t numbv1 = ivid/100;
309 Int_t numbv2 = ivid%100;
316 TVector3 Rlab( hitPtr->x);
317 Float_t Rxy=sqrt(Rlab.X()*Rlab.X()+Rlab.Y()*Rlab.Y());
322 #if 0 // use only disc #1, for testing
323 if(iDisc!=0 || iQuad!=1) {
324 printf(
"TT tmp skip disc ? or quad ?\n");
341 Rloc.RotateZ(-StFgtGeom::phiQuadXaxis(iQuad));
345 #ifdef __FGT_QA_HISTO__
348 if(!StFgtGeom::inDisc(Rlab))
continue;
349 #ifdef __FGT_QA_HISTO__
352 if(fabs(Rloc.x()) < StFgtGeom::deadQuadEdge())
continue;
353 #ifdef __FGT_QA_HISTO__
356 if(fabs(Rloc.y()) < StFgtGeom::deadQuadEdge())
continue;
357 #ifdef __FGT_QA_HISTO__
360 if(!StFgtGeom::belowFlat(Rloc))
continue;
361 #ifdef __FGT_QA_HISTO__
365 if(hitPtr->tof> par_trackTOFcutoff )
continue;
366 #ifdef __FGT_QA_HISTO__
370 TVector3 Plab(hitPtr->p);
372 #ifdef __FGT_QA_HISTO__
373 if(Plab.Mag()>0) hA[7]->Fill(log10(Plab.Mag()*1000.));
375 if(Plab.Mag()< par_trackPcutoff )
continue;
376 #ifdef __FGT_QA_HISTO__
384 Double_t ds=hitPtr->ds;
386 TVector3 verLab=Plab.Unit();
388 TVector3 Rloc2=Rlab+ds*verLab; Rloc2.RotateZ(-StFgtGeom::phiQuadXaxis(iQuad));
389 TVector3 Dloc=Rloc2-Rloc;
402 aux.Rlab=aux.
Rloc=aux.Dloc=TVector3(0,0,0); aux.
hitPtr=0; aux.iQuad=-1;
407 aux.Rlab=Rlab+ds/2.*verLab;
415 #ifdef __FGT_QA_HISTO__
417 hA[3]->Fill(10+5*iDisc);
418 hA[3]->Fill(10+5*iDisc+iQuad+1);
419 Double_t de_kev=hitPtr->de*1.e6;
421 hA[1]->Fill(hitPtr->ds);
422 hA[2]->Fill(Rlab.z());
423 hA[4]->Fill(Rlab.x(),Rlab.y());
424 hA[6]->Fill(Rlab.Perp());
435 StFgtSlowSimuMaker::projectQuad2strips( Int_t iDisc, Int_t iQuad ){
437 Double_t totAmp=quadDigitizationXY->Integral();
438 Double_t maxAmp=quadDigitizationXY->GetMaximum();
439 Double_t cut_2DampCutoff= maxAmp/par_2DampCutoffScale;
443 Int_t nPix0=0, nPix1=0;
444 Double_t sumAmp=0.,sumAmpAtten=0., sumAdcP=0., sumAdcR=0.;
446 Int_t nx=quadDigitizationXY->GetNbinsX();
447 Int_t ny=quadDigitizationXY->GetNbinsY();
449 for(bx=1;bx<=nx;bx++)
450 for(by=1;by<=ny;by++) {
451 Float_t amp=quadDigitizationXY->GetBinContent(bx,by);
452 if (amp < cut_2DampCutoff)
continue;
454 Double_t x=quadDigitizationXY->GetXaxis()->GetBinCenter(bx);
455 Double_t y=quadDigitizationXY->GetYaxis()->GetBinCenter(by);
456 Double_t ampAtten=amp*par_overalGain;
457 if (ampAtten < cut_2DampCutoff)
continue;
460 Double_t r=sqrt(x*x+y*y);
461 Double_t phi=atan2(y,x);
464 Int_t iRadID=StFgtGeom::rad2LocalStripId(r,phi,&binFrac);
471 Int_t iPhiID=StFgtGeom::phi2LocalStripId(r,phi,&binFrac);
481 Double_t adcP= par_PplaneChargeFraction *ampAtten;
482 Double_t adcR=(1.-par_PplaneChargeFraction)*ampAtten;
486 sumAmp+=amp; sumAmpAtten+=ampAtten;
487 sumAdcP+=adcP; sumAdcR+=adcR;
490 quadDigitizationRad->Fill(iRadID,adcR);
491 quadDigitizationPhi->Fill(iPhiID,adcP);
496 #ifdef __FGT_QA_HISTO__
498 digRAll->Fill(iRadID,adcR);
499 digPAll->Fill(iPhiID,adcP);
500 digRadcAll->Fill(x,y,adcR);
501 digPadcAll->Fill(x,y,adcP);
506 #ifdef __FGT_QA_HISTO__
507 hA[29]->Fill(sumAdcR);
508 hA[30]->Fill(sumAdcP);
509 hA[31]->Fill(sumAdcP,sumAdcR);
518 StFgtSlowSimuMaker::exportStripPlane2StEvent(TH1F *h, Int_t stripIdOffset,
StFgtStripCollection *stripCollectionPtr){
523 Float_t *adcPtr=h->GetArray();
525 Int_t nx=h->GetNbinsX();
527 for(Int_t iId=0;iId<nx;iId++) {
528 Double_t adc=adcPtr[iId+1];
530 if(adc >par_stripThreshAdc ) nSeq=3;
531 if( nSeq<=0)
continue;
532 Int_t geoId=stripIdOffset+iId;
535 Int_t rdo, arm, apv, chan;
536 fgtDb->getElecCoordFromGeoId( geoId, rdo, arm, apv, chan );
539 Int_t elecId = StFgtGeom::getElectIdFromElecCoord( rdo, arm, apv, chan );
540 StFgtStrip* stripPtr = stripCollectionPtr->getStrip( elecId );
545 if( switch_addPeds ) {
546 stat=fgtDb->getStatusFromElecCoord(rdo,arm,apv,chan);
548 ped=fgtDb ->getPedestalFromGeoId( geoId);
549 sigPed=fgtDb->getPedestalSigmaFromGeoId( geoId);
556 for(
int iTbOff=0;iTbOff<7;iTbOff++)
558 if( switch_addPeds ) {
559 adc2=adc*pulseShape[iTbOff];
560 adc2+=mRnd->Gaus(ped,sigPed);
561 if(adc2<ped-3*sigPed) adc2=ped-3*sigPed;
563 if(adc2 >4095 ) adc=4095;
566 stripPtr->setAdc( (Short_t)(adc2), timebin+iTbOff );
569 stripPtr->setGeoId( geoId );
570 stripPtr->setElecCoords(rdo,arm,apv,chan);
virtual void Clear(Option_t *option="")
User defined functions.
vector< fgt_g2t_auxil > mG2tHitList[kFgtMxDisk+1][kFgtMxQuad]
accepted track segements
virtual void Clear(Option_t *option="")
User defined functions.
virtual const char * GetName() const
special overload
.... utility c-struct for g2t hits
TVector3 Rloc
hit entrance in LAB
g2t_fgt_hit_st * hitPtr
entrance & path in local ref frame