1 #include "StEmcMixerMaker.h"
4 #include "SystemOfUnits.h"
10 #include "math_constants.h"
11 #include "StEmcSimulatorMaker/StEmcSimulatorMaker.h"
12 #include "StEventTypes.h"
14 #include "StEmcUtil/geometry/StEmcGeom.h"
15 #include "tables/St_emcStatus_Table.h"
16 #include "tables/St_smdStatus_Table.h"
27 mFakeTrackEmbed = kFALSE;
28 for(Int_t i=0;i<NDETECTORS;i++) mGeom[i]=StEmcGeom::instance(i+1);
31 StEmcMixerMaker::~StEmcMixerMaker()
35 Int_t StEmcMixerMaker::Init()
37 m_hit_1 =
new TH1F(
"old_hit",
"old_hit",100,0.,30.);
38 m_hit_2 =
new TH1F(
"new_hit",
"new_hit",100,0.,30.);
39 m_edep_1 =
new TH1F(
"EDEP1",
"edep1",100,0.,30.);
40 m_edep_2 =
new TH1F(
"EDEP2",
"edep2",100,0.,30.);
41 return StMaker::Init();
46 if(!getEvents())
return kStWarn;
50 for(Int_t i=0;i<NDETECTORS;i++)
51 for(Int_t j=0;j<(EMCCHANNELS+(MAXCHANNELS-EMCCHANNELS)*(i>1));j++)
57 if(mAddHits){
if(addHits()!=
kStOk) { LOG_WARN <<
" error in addhits***"<<endm;
return kStWarn; } }
72 Int_t StEmcMixerMaker::addHits()
76 Int_t stat_h2_all[MAXCHANNELS];
77 Int_t stat_h2[MAXCHANNELS];
80 Float_t old_edep_tot=0.0;
81 Float_t new_edep_tot=0.0;
82 for(Int_t i=0; i<NDETECTORS; i++)
84 StDetectorId
id =
static_cast<StDetectorId
>(i+kBarrelEmcTowerId);
87 if(!detector1){ LOG_WARN <<
"detector1 not loaded"<<endm; }
88 if(!detector2){ LOG_WARN <<
"detector2 not loaded"<<endm; }
93 if(detector1 && detector2)
for(UInt_t j=1;j<=NMODULES;j++)
97 StSPtrVecEmcRawHit& rawHit1=module1->hits();
98 StSPtrVecEmcRawHit& rawHit2=module2->hits();
100 for(UInt_t k1=0;k1<rawHit1.size();k1++) {edep1_tot+=rawHit1[k1]->energy();}
101 for(UInt_t k1=0;k1<rawHit2.size();k1++) {edep2_tot+=rawHit2[k1]->energy();}
103 for(UInt_t is=0;is<rawHit2.size();is++) {stat_h2_all[is]=0;stat_h2[is]=0;}
105 for(UInt_t k1=0;k1<rawHit1.size();k1++)
108 m1=(Int_t)rawHit1[k1]->module();
109 e1=(Int_t)rawHit1[k1]->eta();
110 s1=abs(rawHit1[k1]->sub());
111 for(UInt_t is=0;is<rawHit2.size();is++) {stat_h2[is]=0;}
113 Float_t edep_add=0.0;
115 for(UInt_t k2=0;k2<rawHit2.size();k2++)
if(checkHit(i,rawHit2[k2]))
117 if(stat_h2[k2]==1)
continue;
119 m2=(Int_t)rawHit2[k2]->module();
120 e2=(Int_t)rawHit2[k2]->eta();
121 s2=abs(rawHit2[k2]->sub());
122 if(m1==m2 && e1==e2 && s1==s2)
126 edep_add=rawHit2[k2]->energy();
127 adc_add=rawHit2[k2]->adc();
129 if(stat_h2[k2]==1)
break;
131 Float_t new_edep=rawHit1[k1]->energy()+edep_add;
132 UInt_t new_adc=rawHit1[k1]->adc()+adc_add;
133 Float_t oldE=rawHit1[k1]->energy();
134 old_edep_tot+=rawHit1[k1]->energy();
135 rawHit1[k1]->setAdc(new_adc);
136 rawHit1[k1]->setEnergy(new_edep);
137 new_edep_tot+=new_edep;
138 UInt_t calib = rawHit1[k1]->calibrationType();
139 while(calib>127) calib-=128;
141 LOG_DEBUG <<
"EMBEDDED HIT -> det = "<<i+1<<
" m = "<<m1<<
" e = "<<e1<<
" s = "<<s1
142 <<
" calib = "<<rawHit1[k1]->calibrationType()
143 <<
" new calib = "<<calib
144 <<
" oldE = "<<oldE<<
" EADD = "<<edep_add
145 <<
" newE = "<<rawHit1[k1]->energy()<<endm;
147 rawHit1[k1]->setCalibrationType(calib);
151 if(mEmbedAll)
for(UInt_t k2=0;k2<rawHit2.size();k2++)
if(checkHit(i,rawHit2[k2]))
153 if(stat_h2_all[k2]==0)
156 rawHit2[k2]->eta(), rawHit2[k2]->sub(),
157 rawHit2[k2]->adc(), rawHit2[k2]->energy());
158 detector1->addHit(hit);
159 new_edep_tot+=rawHit2[k2]->energy();
163 m_hit_1->Fill(old_edep_tot);
164 m_hit_2->Fill(new_edep_tot);
165 m_edep_1->Fill(edep1_tot);
166 m_edep_2->Fill(edep2_tot);
174 void StEmcMixerMaker::clearPoints()
179 StSPtrVecEmcPoint& pvec = emccol->barrelPoints();
180 if(mClear)pvec.clear();
187 void StEmcMixerMaker::clearClusters()
190 if(emccol)
for(Int_t i=0; i<NDETECTORS; i++)
192 StDetectorId
id =
static_cast<StDetectorId
>(i+kBarrelEmcTowerId);
196 if(detector->cluster())
198 StSPtrVecEmcCluster& cluster=detector->cluster()->clusters();
199 if(mClear)cluster.clear();
212 Bool_t StEmcMixerMaker::getEvents()
218 mEvent1 = (
StEvent*)GetInputDS(
"StEvent");
219 if(!mEvent1)
return kFALSE;
220 if(!mEvent1->emcCollection())
return kFALSE;
235 mEvent2->setEmcCollection(ecol);
237 }
else { LOG_WARN <<
"No second event to embed"<<endm;
return kFALSE; }
241 StMaker *m = GetMaker(
"embedIO");
242 if(!m) { LOG_WARN <<
"No embedIO maker"<<endm;
return kFALSE; }
243 mEvent2 = (
StEvent*)m->GetInputDS(
"StEvent");
244 if(!mEvent2) { LOG_WARN <<
"No second event to embed"<<endm;
return kFALSE; }
245 if(!mEvent2->emcCollection()) { LOG_WARN <<
"No second event to embed"<<endm;
return kFALSE; }
248 LOG_DEBUG <<
"Event 1 = "<<mEvent1<<
" Event 2 ="<<mEvent2<<endm;
251 if(mEvent1==mEvent2) { LOG_DEBUG <<
"Identical events"<<endm;
return kFALSE; }
257 const TString detname[] = {
"bemc",
"bprs",
"bsmde",
"bsmdp",
"eemc",
"eprs",
"esmde",
"esmdp"};
260 for(Int_t i=0; i<NDETECTORS; i++)
262 StDetectorId
id =
static_cast<StDetectorId
>(i+kBarrelEmcTowerId);
264 LOG_INFO <<
"****************** hits in detector "<< detname[i].Data()<<endm;
265 if(detector)
for(UInt_t j=1;j<=NMODULES;j++)
268 StSPtrVecEmcRawHit& rawHit=module->hits();
269 if(rawHit.size()>0) { LOG_INFO <<
"Number of hits for module "<<j<<
" = "<<rawHit.size()<<endm; }
270 for(UInt_t k=0;k<rawHit.size();k++) {
271 LOG_INFO <<
"Hit number = "<<k<<
" module = " << rawHit[k]->module()<<
" eta = "<<rawHit[k]->eta() <<
" sub = "<< rawHit[k]->sub()<<
" adc = "<< rawHit[k]->adc() <<
" energy = "<<rawHit[k]->energy()<<endm;
282 void StEmcMixerMaker::getDB()
284 TDataSet *Db=GetDataBase(
"Calibrations/emc/y3bemc");
285 Int_t valid[NDETECTORS];
for(Int_t i=0;i<NDETECTORS;i++) valid[i]=0;
286 St_emcStatus* s0 = (St_emcStatus*)Db->
Find(
"bemcStatus");
289 emcStatus_st* st=s0->GetTable();
290 for(Int_t i=0;i<EMCCHANNELS;i++) mStatus[0][i] = st[0].Status[i];
291 }
else for(Int_t i=0;i<EMCCHANNELS;i++) mStatus[0][i] = 0;
293 Db=GetDataBase(
"Calibrations/emc/y3bprs");
294 St_emcStatus* s1 = (St_emcStatus*)Db->
Find(
"bprsStatus");
297 emcStatus_st* st=s1->GetTable();
298 for(Int_t i=0;i<EMCCHANNELS;i++) mStatus[1][i] = st[0].Status[i];
299 }
else for(Int_t i=0;i<EMCCHANNELS;i++) mStatus[1][i] = 0;
301 Db=GetDataBase(
"Calibrations/emc/y3bsmde");
302 St_smdStatus* s2 = (St_smdStatus*)Db->
Find(
"bsmdeStatus");
305 smdStatus_st* st=s2->GetTable();
306 for(Int_t i=0;i<SMDCHANNELS;i++) mStatus[2][i] = st[0].Status[i];
307 }
else for(Int_t i=0;i<SMDCHANNELS;i++) mStatus[2][i] = 0;
309 Db=GetDataBase(
"Calibrations/emc/y3bsmdp");
310 St_smdStatus* s3 = (St_smdStatus*)Db->
Find(
"bsmdpStatus");
313 smdStatus_st* st=s3->GetTable();
314 for(Int_t i=0;i<SMDCHANNELS;i++) mStatus[3][i] = st[0].Status[i];
315 }
else for(Int_t i=0;i<SMDCHANNELS;i++) mStatus[3][i] = 0;
317 for(Int_t i=0;i<NDETECTORS;i++)
318 for(Int_t j=0;j<(EMCCHANNELS*(i<2)+SMDCHANNELS*(i>1));j++)
319 if(mStatus[i][j]==1) valid[i]++;
321 LOG_DEBUG <<
"Date = "<<GetDate()<<
" time = "<<GetTime()<<endm;
322 for(Int_t i=0;i<NDETECTORS;i++) { LOG_DEBUG <<
"Number of valid channels for detector "<<i<<
" = "<<valid[i]<<endm; }
331 Bool_t StEmcMixerMaker::checkHit(Int_t d,
StEmcRawHit* h)
333 if(!h)
return kFALSE;
334 Int_t m = (Int_t)h->module();
335 Int_t e = (Int_t)h->eta();
336 Int_t s = abs(h->sub());
338 mGeom[d]->getId(m,e,s,
id);
339 if(
id>0)
if(mStatus[d][
id-1]==1)
return kTRUE;
348 Int_t StEmcMixerMaker::addTracks()
351 StSPtrVecTrackNode& Node1 = mEvent1->trackNodes();
352 StSPtrVecTrackNode& Node2 = mEvent2->trackNodes();
353 for (
unsigned int j=0; j < Node2.size(); j++)
360 Node1.push_back(node);
void printHits(StEvent *)
Prints all EMC hits in the StEvent object.
virtual void AddData(TDataSet *data, const char *dir=".data")
User methods.
StEmcCollection * getEmcCollection()
void addTracks(bool cuts=false)
Add tracks to the list of the rendered objects from current MuDst event.
virtual TDataSet * Find(const char *path) const