16 #include "TClonesArray.h"
22 #include "StEventTypes.h"
23 #include "StMuDSTMaker/COMMON/StMuTypes.hh"
24 #include "StMcEvent/StMcEventTypes.hh"
25 #include "StEEmcUtil/database/EEmcDbItem.h"
26 #include "StEEmcUtil/database/StEEmcDb.h"
27 #include "StEEmcUtil/EEmcGeom/EEmcGeomSimple.h"
28 #include "StEEmcUtil/StEEmcSmd/EEmcSmdGeom.h"
29 #include "StEEmcSimulatorMaker/StEEmcFastMaker.h"
30 #include "StEEmcPool/StEEmcA2EMaker/StEEmcA2EMaker.h"
33 #include "StEEmcPool/StEEmcDataDrivenMcEventInfo/StEEmcDataDrivenMcEventInfo.h"
34 #include "StEEmcShowerShape.h"
35 #include "StEEmcDataDrivenMcMaker.h"
39 StEEmcDataDrivenMcMaker::StEEmcDataDrivenMcMaker(
const char* name) :
StMaker(name)
47 memset(mStrips, 0,
sizeof(mStrips));
48 mDataDrivenMcEventInfo->Clear(option);
52 int StEEmcDataDrivenMcMaker::Init()
60 TFile* file =
new TFile(mLibraryFile);
61 LOG_INFO <<
"Shower Shape Library = " << mLibraryFile << endm;
62 assert(file && !file->IsZombie());
63 TTree* tree = (TTree*)file->Get(
"etas");
66 tree->SetBranchAddress(
"StEEmcSmdResponse", &showerShape);
68 for (
int i = 0; i < NUMBER_OF_ENERGY_BINS; ++i) {
69 for (
int j = 0; j < NUMBER_OF_PRESHOWER_BINS; ++j) {
70 mShowerShapes[i][j] =
new TClonesArray(
"StEEmcShowerShape");
74 for (
int iEntry = 0; tree->GetEntry(iEntry) > 0; ++iEntry) {
75 int uid = showerShape->highUstripId();
76 int vid = showerShape->highVstripId();
79 if (uid < mNumberOfStripsReplaced || uid > 288 - mNumberOfStripsReplaced-1 || vid < mNumberOfStripsReplaced || vid > 288-mNumberOfStripsReplaced-1)
continue;
80 assert(0 <= showerShape->sector() && showerShape->sector() < 12);
81 int i = getEnergyBin(showerShape);
82 int j = getPreshowerBin(showerShape);
83 assert(i >= 0 && i < NUMBER_OF_ENERGY_BINS);
84 assert(j >= 0 && j < NUMBER_OF_PRESHOWER_BINS);
85 TClonesArray& tca = *mShowerShapes[i][j];
86 mLibraryMap[
new (tca[tca.GetEntriesFast()])
StEEmcShowerShape(*showerShape)] = iEntry;
89 LOG_INFO <<
"Number of shower shapes in library = " << tree->GetEntriesFast() << endm;
91 for (
int i = 0; i < NUMBER_OF_ENERGY_BINS; ++i) {
92 for (
int j = 0; j < NUMBER_OF_PRESHOWER_BINS; ++j) {
93 LOG_INFO <<
"Energy bin =" << i
94 <<
", preshower bin=" << j
95 <<
", number of shower shapes=" << mShowerShapes[i][j]->GetEntriesFast()
108 if (mLogFileName !=
"") {
109 mLogFile = TFile::Open(mLogFileName,
"recreate");
117 mTree =
new TTree(
"DataDrivenMcEventInfo",
"Data-driven Monte Carlo event info");
118 mTree->Branch(
"DataDrivenMcEventInfo", &mDataDrivenMcEventInfo);
125 mEEmcDb = (
StEEmcDb*)this->GetDataSet(
"StEEmcDb");
129 memset(mPed, 0,
sizeof(mPed));
130 memset(mGain, 0,
sizeof(mGain));
132 return StMaker::Init();
135 int StEEmcDataDrivenMcMaker::InitRun(
int runNumber)
137 for (
int sector = 0; sector < 12; ++sector) {
138 for (
int plane = 0; plane < 2; ++plane) {
140 for (
int strip = 0; strip < 288; ++strip) {
142 const EEmcDbItem* x = mEEmcDb->getByStrip(sector+1, uv, strip+1);
144 mPed[sector][plane][strip] = mUsePed ? x->ped : 0;
150 return StMaker::InitRun(runNumber);
156 if (!GetDataSet(
"MuDst")) {
157 LOG_WARN <<
"No MuDst" << endm;
164 LOG_WARN <<
"No MuDst EMC collection" << endm;
169 for (
int plane = 1; plane <= 2; ++plane) {
170 char uv =
'U' + plane - 1;
171 for (
int i = 0; i < emc->getNEndcapSmdHits(uv); ++i) {
173 StMuEmcHit*
hit = emc->getEndcapSmdHit(uv, i, sector, strip);
174 hit->setAdc(
int(hit->
getAdc() + mPed[sector-1][plane-1][strip-1]));
175 mStrips[sector-1][plane-1][strip-1] = hit;
180 mMcEvent = (
StMcEvent*)GetDataSet(
"StMcEvent");
183 LOG_WARN <<
"No StMcEvent" << endm;
188 mDataDrivenMcEventInfo->SetRunId(mMcEvent->runNumber());
189 mDataDrivenMcEventInfo->SetEventId(mMcEvent->eventNumber());
192 if (
StMuDstMaker* mudst = dynamic_cast<StMuDstMaker*>(GetMakerInheritsFrom(
"StMuDstMaker"))) {
193 mDataDrivenMcEventInfo->SetFileName(mudst->chain()->GetFile()->GetName());
198 processVertex(mMcEvent->primaryVertex());
201 if (mDataDrivenMcEventInfo->NumberOfReplacements()) mTree->Fill();
206 void StEEmcDataDrivenMcMaker::processVertex(
StMcVertex* mcVertex)
208 for (
unsigned int i = 0; i < mcVertex->numberOfDaughters(); ++i)
209 processTrack(mcVertex->daughter(i));
212 void StEEmcDataDrivenMcMaker::processTrack(
StMcTrack* mcTrack)
214 if (mcTrack->stopVertex()) {
216 processVertex(mcTrack->stopVertex());
221 if (mcTrack->geantId() < 1 || mcTrack->geantId() > 3)
return;
224 if (mcTrack->esmduHits().empty() && mcTrack->esmdvHits().empty())
return;
227 if (multiSector(mcTrack->esmduHits()) || multiSector(mcTrack->esmdvHits()))
return;
230 TVector3 momentum(mcTrack->momentum().xyz());
231 float cosTheta = momentum.CosTheta();
232 if (!cosTheta)
return;
238 TVector3
vertex(mcTrack->startVertex()->position().xyz());
245 TVector3 position = momentum;
246 float magnitude = (zSMD -
vertex.z()) / cosTheta;
247 position.SetMag(magnitude);
262 for (
int plane = 0; plane < 2; ++plane) {
267 sectors[plane] = eemcStrip->stripStructId.sectorId - 1;
268 strips [plane] = eemcStrip->stripStructId. stripId - 1;
271 StPtrVecMcCalorimeterHit& hits = (plane == 0) ? mcTrack->esmduHits() : mcTrack->esmdvHits();
276 for (
size_t k = 0; k < hits.size(); ++k) {
279 replaceInfo->addMcHitEsmdU(hit);
281 replaceInfo->addMcHitEsmdV(hit);
282 if (!maxHit || hit->dE() > maxHit->dE()) maxHit = hit;
286 int maxId = maxHit->eta() - 1;
288 replaceInfo->highStripShiftU = maxId - strips[plane];
291 replaceInfo->highStripShiftV = maxId - strips[plane];
296 getEnergies(mcTrack, replaceInfo);
300 int iEnergyBin = !(mcTrack->energy() < 8);
303 assert(iEnergyBin >= 0 && iEnergyBin < NUMBER_OF_ENERGY_BINS);
317 if (sector+1 == sec && subsector+1 == sub && etabin+1 == eta) {
327 int iPreshowerBin = -1;
329 if (pre1 == 0 && pre2 == 0)
331 else if (pre1 == 0 && pre2 > 0)
333 else if (pre1 > 0 && pre1 < 4e-3)
335 else if (pre1 >= 4e-3)
338 LOG_ERROR <<
"Could not determine preshower bin" << endm;
343 assert(iPreshowerBin >= 0 && iPreshowerBin < NUMBER_OF_PRESHOWER_BINS);
345 int iEntry = gRandom->Integer(mShowerShapes[iEnergyBin][iPreshowerBin]->GetEntriesFast());
350 replaceInfo->pid = mcTrack->geantId();
351 replaceInfo->parentPid = mcTrack->parent()->geantId();
352 replaceInfo->libraryShapeId = mLibraryMap[showerShape];
353 replaceInfo->libraryBinId = iEnergyBin * NUMBER_OF_PRESHOWER_BINS + iPreshowerBin;
354 replaceInfo->energy = mcTrack->energy();
355 replaceInfo->momentum = mcTrack->momentum().xyz();
359 if (mcTrack->parent()->parent())
360 replaceInfo->firstHadronPid = mcTrack->parent()->parent()->pdgId();
365 assert(showerShape->energy());
371 for (
int plane = 0; plane < 2; ++plane) {
372 int& sector = sectors[plane];
373 int& strip = strips [plane];
375 float scale = GetShowerShapeScale(mcTrack, showerShape, sector, plane, strip);
376 if (plane == 0){ replaceInfo->energyScaleU = scale; }
else{ replaceInfo->energyScaleV = scale; }
378 for (
int dx = -mNumberOfStripsReplaced; dx <= mNumberOfStripsReplaced; ++dx) {
380 if (id < 0 || id >= 288)
continue;
381 int highStrip = (plane == 0) ? showerShape->highUstripId() : showerShape->highVstripId();
382 int id2 = highStrip + dx;
383 assert(0 <= id2 && id2 < 288);
384 StMuEmcHit* hit2 = (plane == 0) ? showerShape->uStrip(id2) : showerShape->vStrip(id2);
390 int det = (plane == 0) ? esmdu : esmdv;
408 assert(mMuEmcUtil->getEndcapId(det, sector+1,
id+1, 1, id3) == 0);
410 hit->setAdc((
int)mPed[sector][plane][
id]);
415 mStrips[sector][plane][id] = hit;
423 StPtrVecMcCalorimeterHit& mcHits = (plane == 0) ? mcTrack->esmduHits() : mcTrack->esmdvHits();
424 for (
size_t i = 0; i < mcHits.size(); ++i) {
426 if (mcHit->module() == sector+1 && mcHit->eta() ==
id+1) {
445 int adc = int(hit->
getEnergy() * mGain[sector][plane][id] + mPed[sector][plane][id]);
447 if (adc < 0) adc = 0;
448 if (adc > StEEmcFastMaker::getMaxAdc()) adc = StEEmcFastMaker::getMaxAdc();
465 bool StEEmcDataDrivenMcMaker::multiSector(
const vector<StMcCalorimeterHit*>& hits)
const
467 for (
size_t i = 0; i < hits.size(); ++i)
468 if (hits[i]->module() != hits[0]->module())
475 return !(showerShape->energy() < 8);
478 int StEEmcDataDrivenMcMaker::getPreshowerBin(
StEEmcShowerShape* showerShape)
const
480 float pre1 = showerShape->preshower1();
481 float pre2 = showerShape->preshower2();
483 if (pre1 == 0 && pre2 == 0)
return 0;
484 if (pre1 == 0 && pre2 > 0)
return 1;
485 if (pre1 > 0 && pre1 < 4e-3)
return 2;
486 if (pre1 >= 4e-3)
return 3;
494 const int NUMBER_OF_EEMC_LAYERS = 6;
496 StPtrVecMcCalorimeterHit* hits[NUMBER_OF_EEMC_LAYERS];
499 hits[0] = &mcTrack->eemcHits();
500 hits[1] = &mcTrack->eprsHits();
501 hits[4] = &mcTrack->esmduHits();
502 hits[5] = &mcTrack->esmdvHits();
504 emc[0] = mMcEvent->eemcHitCollection();
505 emc[1] = mMcEvent->eprsHitCollection();
506 emc[4] = mMcEvent->esmduHitCollection();
507 emc[5] = mMcEvent->esmdvHitCollection();
509 for (
int layer = 0; layer < NUMBER_OF_EEMC_LAYERS; ++layer) {
510 if (layer == 2 || layer == 3)
continue;
511 replaceInfo->nTowerFired[layer] = hits[layer]->size();
515 replaceInfo->dEnergy[layer] = 0;
516 replaceInfo->totalEnergyScaled[layer] = 0;
518 for (
size_t i = 0; i < hits[layer]->size(); ++i) {
520 replaceInfo->dEnergy[layer] += hit->dE();
521 int id = hit->sub() + 100 * hit->module() + 100000 * hit->eta();
525 StEEmcTower tower = mA2E->
tower(hit->module()-1, hit->sub()-1, hit->eta()-1);
526 replaceInfo->totalEnergyScaled[layer] += tower.
energy();
529 StEEmcStrip strip = mA2E->
strip(hit->module()-1, hit->sub()-1, hit->eta()-1);
530 replaceInfo->totalEnergyScaled[layer] += strip.
energy();
534 replaceInfo->totalEnergy[layer] = 0;
536 for (
size_t m = 1; m <= emc[layer]->numberOfModules(); ++m) {
537 for (
size_t k = 0; k < emc[layer]->module(m)->numberOfHits(); ++k) {
539 int id = hit->sub() + 100 * hit->module() + 100000 * hit->eta();
540 if (find(ids.begin(), ids.end(), id) != ids.end()) {
541 replaceInfo->totalEnergy[layer] += hit->dE();
548 float StEEmcDataDrivenMcMaker::GetShowerShapeScale
554 int geantPhotonCentralStrip
558 switch (mShowerShapeScalingMethod)
562 float smdEnergyGeant = 0;
563 float smdEnergyLibrary = 0;
564 for (
int dx = -mNumberOfStripsReplaced; dx <= mNumberOfStripsReplaced; ++dx)
566 int id = geantPhotonCentralStrip + dx;
567 if (id < 0 || id >= 288)
continue;
568 int highStrip = (plane == 0) ? showerShape->highUstripId() : showerShape->highVstripId();
569 int id2 = highStrip + dx;
570 assert(0 <= id2 && id2 < 288);
571 StMuEmcHit* hit2 = (plane == 0) ? showerShape->uStrip(id2) : showerShape->vStrip(id2);
573 StPtrVecMcCalorimeterHit& mcHits = (plane == 0) ? mcTrack->esmduHits() : mcTrack->esmdvHits();
574 for (
size_t i = 0; i < mcHits.size(); ++i)
577 if (mcHit->module() == sector+1 && mcHit->eta() ==
id+1)
579 smdEnergyGeant += mcHit->dE();
585 scale = smdEnergyGeant/smdEnergyLibrary;
590 scale = mcTrack->energy() / showerShape->energy();
EEmc ADC –> energy maker.
static EEmcGeomSimple & Instance()
returns a reference to a static instance of EEmcGeomSimple
float getEnergy() const
Return Hit energy.
StEEmcStrip & strip(Int_t sector, Int_t plane, Int_t strip)
virtual void Clear(Option_t *option="")
User defined functions.
Monte Carlo Track class All information on a simulated track is stored in this class: kinematics...
int getAdc() const
Return ADC value.
static Float_t getSmdGain()
(adc=g*de ) fixed gain for SMD
Base class for representing tower, preshower and postshower elements.
Float_t getZSMD() const
gets z-depth of the SMD layer in EEMC
static StMuEmcCollection * muEmcCollection()
returns pointer to current StMuEmcCollection
StEEmcTower & tower(Int_t index, Int_t layer=0)
void Clear(Option_t *option="")
User defined functions.
void energy(Float_t e)
Set the energy (adc-ped+0.5)/gain for this element.
Event data structure to hold all information from a Monte Carlo simulation. This class is the interfa...
Base class for describing an endcap SMD strip.
const StructEEmcStrip * getDca2Strip(const Int_t iUV, const TVector3 &point, Float_t *dca) const