20 #include "StTofSimMaker.h"
23 #include "StThreeVectorD.hh"
25 #include "RanluxEngine.h"
26 #include "RandGauss.h"
30 #include "StTofUtil/StTofCalibration.h"
31 #include "StTofUtil/StTofSimParam.h"
32 #include "StTofUtil/StTofGeometry.h"
33 #include "StEventTypes.h"
36 #include "tables/St_g2t_ctf_hit_Table.h"
37 #include "tables/St_g2t_vpd_hit_Table.h"
40 #include "StTofUtil/StTofDataCollection.h"
41 #include "StTofUtil/StTofSlatCollection.h"
42 #include "StTofMCSlat.h"
44 typedef vector<StTofMCSlat> tofMCSlatVector;
45 typedef tofMCSlatVector::iterator tofMCSlatVecIter;
73 mdE =
new TH1F(
"energy deposition",
"dE",100,0.,0.011);
74 mdS =
new TH1F(
"distance",
"ds",100,0.,10);
75 mNumberOfPhotoelectrons =
new TH1F(
"number of photoelectrons",
"nphe",1000,0,5000);
76 mT =
new TH1F(
"delay corrected tof",
"time",100,0.,12e-7);
77 mTime =
new TH1F(
"only hit-pos resolution added",
"tt",100,0.,12e-7);
78 mTime1 =
new TH1F(
"fully corrected tof",
"tt1",100,0.,120e-7);
79 mPMlength =
new TH1F(
"distance in slat",
"length",100,0,22);
80 mAdc =
new TH1F(
"adc",
"adc",1025,-0.5,1024.5);
81 mTdc =
new TH1F(
"tdc",
"tdc",2049,-0.5,2048.5);
84 return StMaker::Init();
91 LOG_INFO <<
"StTofSimMaker::InitRun -- initializing TofGeometry --" << endm;
101 LOG_INFO <<
"StTofSimMaker::FinishRun -- cleaning up TofGeometry --" << endm;
102 if (mGeomDb)
delete mGeomDb;
111 LOG_INFO <<
"StTofSimMaker Make() starts" << endm;
114 tofMCSlatVector tofMC;
122 St_g2t_ctf_hit *g2t_tof_hit = (St_g2t_ctf_hit*) geantIter(
"g2t_tof_hit");
124 g2t_ctf_hit_st* tof_hit = g2t_tof_hit->GetTable();
125 int numberOfTofHits = g2t_tof_hit->GetNRows();
126 LOG_INFO <<
"TOF #hits: " << numberOfTofHits << endm;
128 tofMCSlatVector MCSlatVec;
130 for (
int i=0;i<numberOfTofHits;i++,tof_hit++){
135 tofMCSlatVector slatTempVec = MCSlatVec;
136 tofMCSlatVector slatErasedVec = slatTempVec;
137 tofMCSlatVecIter slatTempIter, slatErasedIter;
139 while (slatTempVec.size()!=0){
140 unsigned short fastTdc;
141 int nFired=0, accumNPhe=0;
142 float accumDe=0., accumDs=0., fastTof=0.;
143 slatTempIter=slatTempVec.begin();
144 slatErasedIter=slatErasedVec.begin();
145 fastTof = slatTempIter->mcInfo().mTof;
146 fastTdc = slatTempIter->tdc();
148 while(slatErasedIter!=slatErasedVec.end()){
149 if(slatTempIter->slatIndex() == slatErasedIter->slatIndex()){
151 accumDe += slatErasedIter->mcInfo().mDe;
152 accumDs += slatErasedIter->mcInfo().mDs;
153 accumNPhe += slatErasedIter->mcInfo().mNPhe;
154 fastTof = min(fastTof, slatErasedIter->mcInfo().mTof);
155 fastTdc = min(fastTdc, slatErasedIter->tdc());
157 slatErasedVec.erase(slatErasedIter);
163 MCSlat.setNHits(nFired);
164 MCSlat.setNPhe(accumNPhe);
165 MCSlat.setDe(accumDe);
166 MCSlat.setDs(accumDs);
167 MCSlat.setTof(fastTof);
168 MCSlat.setTdc(fastTdc);
169 tofMC.push_back(MCSlat);
171 slatTempVec = slatErasedVec;
173 LOG_INFO <<
"StTofSimMaker::make() vector size from " << MCSlatVec.size()
174 <<
" to " << tofMC.size() << endm;
181 for (
unsigned int i=0;i<tofMC.size(); i++){
183 *MCSlatPtr = tofMC[i];
185 mSlatCollection->push_back(MCSlatPtr);
189 LOG_INFO <<
"StTofSimMaker Make() no TOF hits found" << endm;
192 St_g2t_vpd_hit *g2t_vpd_hit = (St_g2t_vpd_hit*) geantIter(
"g2t_vpd_hit");
195 int numberOfVpdHits = g2t_vpd_hit->GetNRows();
196 LOG_INFO <<
"VPD #hits: " << numberOfVpdHits << endm;
199 LOG_INFO <<
"StTofSimMaker Make() no VPD hits found" << endm;
205 for (
size_t j=0;j<mSlatCollection->size();j++){
206 mTheTofCollection->addSlat(dynamic_cast<StTofMCSlat*>(mSlatCollection->getSlat(j)));
212 for (
int i=0;i<48;i++){
213 bool slatFound =
false;
215 for (j=0;j<(int)mSlatCollection->size();j++){
216 StTofSlat *tempSlat = mSlatCollection->getSlat(j);
217 unsigned short indexSlat = tempSlat->slatIndex();
218 if (indexSlat == mGeomDb->daqToSlatId(i)){
222 StTofData *rawTofData =
new StTofData(indexSlat,tempSlat->adc(),tempSlat->tdc(),0,0,0,0);
223 if (Debug()) LOG_INFO << indexSlat <<
": A" << tempSlat->adc() <<
" T" << tempSlat->tdc() << endm;
224 mDataCollection->push_back(rawTofData);
231 mDataCollection->push_back(rawTofData);
234 for(
size_t jj = 0; jj < mDataCollection->size(); jj++)
235 mTheTofCollection->addData(mDataCollection->getData(jj));
237 mEvent = (
StEvent*) GetInputDS(
"StEvent");
238 if (mEvent) mEvent->setTofCollection(mTheTofCollection);
240 LOG_INFO <<
"StTofSimMaker: Where is StEvent !?! Unable to store data" << endm;
246 LOG_INFO <<
"StTofSimMaker: verifying TOF StEvent data ..." << endm;
248 if(mmTheTofCollection) {
249 LOG_INFO <<
" + StEvent tofCollection Exists" << endm;
250 if(mmTheTofCollection->slatsPresent())
251 LOG_INFO <<
" + StEvent TofSlatCollection Exists" << endm;
253 LOG_INFO <<
" - StEvent TofSlatCollection DOES NOT Exist" << endm;
254 if(mmTheTofCollection->hitsPresent())
255 LOG_INFO <<
" + StEvent TofHitCollection Exists" << endm;
257 LOG_INFO <<
" - StEvent TofHitCollection DOES NOT Exist" << endm;
260 LOG_INFO <<
" - StEvent tofCollection DOES NOT Exist" << endm;
261 LOG_INFO <<
" - StEvent TofSlatCollection DOES NOT Exist" << endm;
262 LOG_INFO <<
" - StEvent TofHitCollection DOES NOT Exist" << endm;
265 LOG_INFO <<
"StTofSimMaker Make() finished" << endm;
275 LOG_INFO <<
" " <<setw( 3) << tof_hit->id <<
" " <<setw( 4) << tof_hit->next_tr_hit_p
276 <<
" " <<setw( 4) << tof_hit->track_p <<
" " <<setw( 8) << tof_hit->volume_id
277 <<
" " <<setw(13) << tof_hit->de <<
" " <<setw(11) << tof_hit->ds
278 <<
" " <<setw(12) << tof_hit->p[0] <<
" " <<setw(12) << tof_hit->p[1]
279 <<
" " <<setw(12) << tof_hit->p[2] <<
" " <<setw( 7) << tof_hit->s_track
280 <<
" " <<setw(13) << tof_hit->tof <<
" " <<setw(10) << tof_hit->x[0]
281 <<
" " <<setw(10) << tof_hit->x[1] <<
" " <<setw(10) << tof_hit->x[2]
294 if (slatId != volId){
295 LOG_INFO <<
"StTofSimMaker::Make Warning: volume_id ("<< volId
296 <<
") and hit ("<<slatId<<
") inconsistent. Switching to volumeid."<< endm;
301 float zmin = mGeomDb->
tofSlat(slatId).z_min;
302 float zmax = mGeomDb->
tofSlat(slatId).z_max;
303 float cosang = mGeomDb->
tofSlat(slatId).cosang;
305 float length = (zmax-tof_hit->x[2])/cosang ;
306 float max_distance = (zmax-zmin)/cosang ;
308 if (length>max_distance || length<0){
309 LOG_INFO <<
"StTofSimMaker: length="<<length<<
" max="<<max_distance
310 <<
" zmin="<<zmin<<
" zmax="<<zmax<<
" coasng="<<cosang<<endm;
316 long numberOfPhotoelectrons;
317 if (mSimDb->slat_para()){
318 LOG_INFO <<
"StTofSimMaker Slat Response Table not implemented yet. "
319 <<
" Switching to exponential model instead" <<endm;
322 numberOfPhotoelectrons = long (tof_hit->de * mSimDb->GeV_2_n_photons()
323 * mSimDb->cath_eff() * mSimDb->cath_surf() * mSimDb->surf_loss());
329 float time= tof_hit->tof + length*mSimDb->delay();
330 float resl= mSimDb->time_res() * ::sqrt(length);
331 if (resl<50e-12) resl=50e-12;
332 float tt = tof_hit->tof + (float) random.shoot()* resl;
333 float tt1 = time + (float) random.shoot()* mSimDb->start_res();
337 mPMlength->Fill(length);
338 mdE->Fill(tof_hit->de);
339 mdS->Fill(tof_hit->ds);
340 mNumberOfPhotoelectrons->Fill(numberOfPhotoelectrons);
348 slat.setSlatIndex(slatId);
351 slatData.mNPhe = numberOfPhotoelectrons;
352 slatData.mDe = tof_hit->de;
353 slatData.mDs = tof_hit->ds;
354 slatData.mTof = tof_hit->tof;
355 slatData.mTime = time;
356 slatData.mMTime = tt;
357 slatData.mMTimeL = tt1;
358 slatData.mPmLength = length;
359 slatData.mSLength = tof_hit->s_track;
363 slatData.mPTot = hitMomentum.mag();
364 slatData.mGId = tof_hit->id;
365 slatData.mTrkId = tof_hit->track_p;
367 slat.setMCInfo(slatData);
370 float tdcOffset = mCalibDb->slat(slatId).offset_tdc
371 + random.shoot() * mCalibDb->slat(slatId).ods_tdc;
372 float cctdc = mCalibDb->slat(slatId).cc_tdc;
373 if(cctdc==0) cctdc=0.0001;
374 unsigned short tdc = (
unsigned short)((
float)tt/cctdc+ tdcOffset);
375 float adcOffset = mCalibDb->slat(slatId).offset_adc
376 + random.shoot() * mCalibDb->slat(slatId).ods_adc;
377 unsigned short adc = (
unsigned short)((
float)numberOfPhotoelectrons
378 * mSimDb->nphe_to_adc() + adcOffset);
379 if (tdc>2048) tdc=2048;
380 if (adc>1024) adc=1024;
390 LOG_INFO <<
"StTofmcInfo slatId " << slatId <<
" " << slatData;
391 LOG_INFO <<
" a:" << adc <<
" t:" << tdc <<
" dE:"<< slatData.mDe <<
" dS:"<< slatData.mDs
392 <<
" mTof:" << slatData.mTof <<
" mTime:"<< slatData.mTime <<
" mMTime:"<<slatData.mMTime
393 <<
" mMTimeL:"<< slatData.mMTimeL <<
" mSLength:" << slatData.mSLength
394 <<
" mPTot:" << slatData.mPTot << endm;
409 return mSimDb->GeV_2_n_photons() * mSimDb->cath_eff()
410 * mSimDb->cath_surf() * mSimDb->surf_loss()
411 * exp(-dz/mSimDb->attlen());
419 LOG_INFO <<
"StTofSimMaker::Finish writing tofsim.root ...";
420 TFile theFile(
"tofsim.root",
"RECREATE",
"tofsim");
424 mNumberOfPhotoelectrons->Write();
431 LOG_INFO <<
"done"<<endm;
tofSlatGeom_st tofSlat(const Int_t slatId) const
return slat geometry structure for slatId
void fillRaw(void)
digitize to ADC and TDC entries (empty)
virtual Int_t Finish()
write histograms to file
void fillEvent()
fill event (empty)
virtual Int_t Make()
read in GSTAR table and create TOF SlatCollection
Int_t FinishRun(int)
FinishRun method, clean up TOFp dBase entries.
Time-of-Flight Calibration Utilities.
virtual ~StTofSimMaker()
default empty destructor
void init()
initializes calibration from XDF or dBase (not functioning yet)
StTofMCSlat detectorResponse(g2t_ctf_hit_st *)
calculate detector response for a single hit
Time-of-Flight Geometry Utilities.
virtual Int_t Init()
Initialize dBase interfaces and book histograms.
Int_t InitRun(int)
InitRun method, (re)initialize TOFp data from STAR dBase.
StTofSimMaker(const char *name="TofSim")
default constructor
void electronicNoise(void)
simulate electronic noise (empty)
float slatResponseExp(float &)
exponential slat response model
void printSlat(const Int_t slatId, ostream &os=cout) const
print slat-specific geometry parameters
int tofSlatCrossId(const StThreeVectorD &point) const
return the index of a slat if the point is in the slat
Time-of-Flight Simulation Utilities.
void init()
initializes calibration from XDF or dBase (not functioning yet)
void init()
initialize geometry class from XDF file and set-up DAQ/Slat mappings