15 #include "StMcEEmcTreeMaker.h"
17 #include "StMuDSTMaker/COMMON/StMuDst.h"
18 #include "StMuDSTMaker/COMMON/StMuEvent.h"
19 #include "StEvent/StTriggerIdCollection.h"
20 #include "StEvent/StTriggerId.h"
22 #include "StarClassLibrary/StThreeVectorF.hh"
23 #include "StEEmcUtil/EEmcGeom/EEmcGeomDefs.h"
25 #include "StMcEvent/StMcTrack.hh"
26 #include "StMcEvent/StMcCalorimeterHit.hh"
27 #include "StMcEvent/StMcEmcModuleHitCollection.hh"
28 #include "StMcEvent/StMcEmcHitCollection.hh"
29 #include "StMcEvent/StMcContainers.hh"
30 #include "StMcEvent/StMcEvent.hh"
31 #include "StMcEvent/StMcVertex.hh"
33 #include "St_DataSet.h"
34 #include "St_DataSetIter.h"
35 #include "tables/St_g2t_event_Table.h"
36 #include "tables/St_particle_Table.h"
37 #include "tables/St_g2t_pythia_Table.h"
39 #include "StRoot/StEEmcPool/./EEmcTreeContainers/EEmcEnergy.h"
40 #include "StRoot/StEEmcPool/./EEmcTreeContainers/McParticle.h"
41 #include "StRoot/StEEmcPool/StEEmcPointMap/StEEmcPointMap.h"
44 mNumEvents(0), mMaxNumEvents(-1), mTowEnergyThres( 0.01 ), mBjX1(0), mBjX2(0) {
46 mAncestorParticleArr =
new TClonesArray(
"McParticle_t", 10);
47 mIncidentParticleArr =
new TClonesArray(
"McParticle_t", 5);
48 mVertexArr =
new TClonesArray(
"TVector3", 5);
54 delete mAncestorParticleArr;
55 delete mIncidentParticleArr;
71 if(
mIOStat == UNSET || mFilename.empty() ){
72 LOG_ERROR <<
"Must set IO status to READ or WRITE and provide a filename" << endm;
77 if( mTriggerSet.empty() &&
mIOStat == WRITE ){
78 LOG_FATAL <<
"ERROR: trigger set is empty." << endm;
79 LOG_FATAL <<
"If you really want to process all triggers, enter a single trigger ID of -999." << endm;
81 }
else if (mTriggerSet.size() == 1 && mTriggerSet.count( -999 ) ) {
87 LOG_INFO <<
GetName() <<
": Set to "
88 << (
mIOStat == READ ?
"READ" :
"WRITE" )
89 <<
" the file '" << mFilename
92 if( mIOStat == READ ){
93 mChain =
new TChain(
"tree");
94 Int_t nFiles =
mChain->Add( mFilename.data(), 1 );
97 LOG_INFO <<
"Opened " << nFiles <<
" based on '" << mFilename << endm;
99 LOG_ERROR <<
"Opened " << nFiles <<
" based on '" << mFilename << endm;
107 mTree->SetBranchAddress(
"incidentParticleArr", &mIncidentParticleArr );
108 mTree->SetBranchAddress(
"ancestorParticleArr", &mAncestorParticleArr );
109 mTree->SetBranchAddress(
"vertexArr", &mVertexArr );
110 mTree->SetBranchAddress(
"xBj1", &mBjX1 );
111 mTree->SetBranchAddress(
"xBj2", &mBjX2 );
114 }
else if( mIOStat == WRITE ){
115 mFile =
new TFile( mFilename.data(),
"RECREATE" );
116 if(
mFile->IsOpen() ){
117 LOG_INFO <<
"Opened file '" << mFilename <<
"' for writing" << endm;
119 LOG_FATAL <<
"Error opening file '" << mFilename <<
"'" << endm;
124 mTree =
new TTree(
"tree",
"McEEmcTree" );
126 mTree->Branch(
"incidentParticleArr", &mIncidentParticleArr );
127 mTree->Branch(
"ancestorParticleArr", &mAncestorParticleArr );
128 mTree->Branch(
"vertexArr", &mVertexArr );
129 mTree->Branch(
"xBj1", &mBjX1 );
130 mTree->Branch(
"xBj2", &mBjX2 );
135 Int_t treeMax = -1111;
137 treeMax =
mChain->GetEntries();
139 if( mMaxNumEvents < 0 || mMaxNumEvents > treeMax )
159 if( !mTriggerSet.empty() ){
167 const StTriggerId& l1trig =
event->triggerIdCollection().l1();
169 std::set< Int_t >::iterator iter = mTriggerSet.begin();
170 for( ; iter != mTriggerSet.end() && !accept; ++iter )
171 accept = l1trig.isTrigger( (*iter) );
186 Int_t StMcEEmcTreeMaker_t::fill(){
191 mcEventPtr =
static_cast< StMcEvent*
>( StMaker::GetChain()->GetDataSet(
"StMcEvent") );
193 LOG_FATAL <<
"ERROR finding StMcEvent" << endm;
206 if( geantDstI(
"particle") ){
207 St_g2t_pythia *Pg2t_pythia = (St_g2t_pythia*)geantDstI(
"g2t_pythia");
208 g2t_pythia_st *g2t_pythia1 = Pg2t_pythia->GetTable();
210 mBjX1 = g2t_pythia1->bjor_1;
211 mBjX2 = g2t_pythia1->bjor_2;
216 Int_t incPartIdx = -1;
221 const StSPtrVecMcTrack& tracks = mcEventPtr->tracks();
222 StSPtrVecMcTrack::const_iterator trackIter;
227 StSPtrVecMcCalorimeterHit::const_iterator hitIter;
229 for( trackIter = tracks.begin(); trackIter != tracks.end(); ++trackIter ){
230 const StPtrVecMcCalorimeterHit& etowHits = (*trackIter)->eemcHits();
232 Bool_t pass = !etowHits.empty();
235 const StMcVertex *stop = (*trackIter)->stopVertex();
236 pass = ( !stop || stop->position().z() > kEEmcZPRE1 );
241 Float_t eTowEnergy = 0;
245 for( hitIter = etowHits.begin(); hitIter != etowHits.end(); ++hitIter )
246 eTowEnergy += (*hitIter)->dE();
248 pass &= ( eTowEnergy > mTowEnergyThres );
259 Float_t ePre1 = 0, ePre2 = 0, ePost = 0, eTow = 0;
260 for( hitIter = etowHits.begin(); hitIter != etowHits.end(); ++hitIter ){
261 Int_t sec = (*hitIter)->module() - 1;
262 Int_t sub = (*hitIter)->sub() - 1;
263 Int_t eta = (*hitIter)->eta() - 1;
265 eemcEnergy->eTow.getByBin( sec, sub, eta ).energy = (*hitIter)->dE();
266 ++(eemcEnergy->nTowers);
267 eTow += (*hitIter)->dE();
272 const StPtrVecMcCalorimeterHit& eprsHits = (*trackIter)->eprsHits();
273 for( hitIter = eprsHits.begin(); hitIter != eprsHits.end(); ++hitIter ){
274 Int_t sec = (*hitIter)->module() - 1;
275 Int_t sub = ((*hitIter)->sub() - 1)%5;
276 Int_t eta = (*hitIter)->eta() - 1;
277 Int_t offset = ((*hitIter)->sub() - 1)/5;
279 ( offset ? ( offset == 2 ? eemcEnergy->ePost : eemcEnergy->ePre2 ) : eemcEnergy->ePre1 ).getByBin( sec, sub, eta ).energy = (*hitIter)->dE();
280 ( offset ? ( offset == 2 ? ePost : ePre2 ) : ePre1 ) += (*hitIter)->dE();
285 std::vector< Double_t > meanU(kEEmcNumSectors,0), eU(kEEmcNumSectors,0), meanV(kEEmcNumSectors,0), eV(kEEmcNumSectors,0);
288 const StPtrVecMcCalorimeterHit& esmduHits = (*trackIter)->esmduHits();
289 for( hitIter = esmduHits.begin(); hitIter != esmduHits.end(); ++hitIter ){
290 Int_t sec = (*hitIter)->module() - 1;
291 Int_t strip = (*hitIter)->eta() - 1;
292 eemcEnergy->eSmd.sec[sec].layer[0].strip[strip].energy = (*hitIter)->dE();
293 meanU[sec] += strip*(*hitIter)->dE();
294 eU[sec] += (*hitIter)->dE();
295 ++(eemcEnergy->nStrips);
299 const StPtrVecMcCalorimeterHit& esmdvHits = (*trackIter)->esmdvHits();
300 for( hitIter = esmdvHits.begin(); hitIter != esmdvHits.end(); ++hitIter ){
301 Int_t sec = (*hitIter)->module() - 1;
302 Int_t strip = (*hitIter)->eta() - 1;
303 eemcEnergy->eSmd.sec[sec].layer[1].strip[strip].energy = (*hitIter)->dE();
304 meanV[sec] += strip*(*hitIter)->dE();
305 eV[sec] += (*hitIter)->dE();
306 ++(eemcEnergy->nStrips);
310 Float_t uPos = -1, vPos = -1;
311 Float_t maxE = 0, maxEu = 0, maxEv = 0;
313 for( Int_t i=0; i<kEEmcNumSectors; ++i ){
314 Float_t smdSum = eU[i]+eV[i];
315 if( maxE < smdSum && eU[i] && eV[i] ){
319 uPos =
static_cast< Float_t
>( meanU[i] / eU[i] );
320 vPos =
static_cast< Float_t
>( meanV[i] / eV[i] );
330 Float_t xPos = 0, yPos = 0;
331 if( uPos > 0 && vPos > 0 )
332 StEEmcPointMap_t::convertStripUVtoXY( sector, uPos, vPos, xPos, yPos );
335 new( (*mIncidentParticleArr)[ incPartIdx ] )
McParticle_t( getAncestorIdx( (*trackIter)->parent() ),
336 getVertexIdx( (*trackIter)->startVertex() ),
337 getVertexIdx( (*trackIter)->stopVertex() ),
338 (*trackIter)->geantId(),
339 (*trackIter)->pdgId(),
340 (*trackIter)->energy(),
341 TVector3( (*trackIter)->momentum().xyz() ),
344 TVector3( xPos, yPos, kEEmcZSMD ),
345 eTow, ePre1, ePre2, ePost );
352 TVector3 mom( (*trackIter)->momentum().xyz() );
353 Double_t eta = mom.Eta();
356 if( eta > 0.5 && eta < 2.5 )
357 getAncestorIdx( *trackIter );
362 if( !ierr && incPartIdx > -1 ){
364 std::map< const StMcTrack*, Int_t > ancestorMapCopy( mAncestorMap );
367 std::map< const StMcTrack*, Int_t >::iterator ancestorMapIter;
370 for( ancestorMapIter = ancestorMapCopy.begin(); ancestorMapIter != ancestorMapCopy.end(); ++ancestorMapIter ){
371 UInt_t mapSize = mAncestorMap.size();
372 const StMcTrack *parent = ancestorMapIter->first->parent();
378 mapSize = mAncestorMap.size();
379 getAncestorIdx( parent );
380 parent = parent->parent();
381 }
while( parent && mapSize != mAncestorMap.size() );
386 for( ancestorMapIter = mAncestorMap.begin(); ancestorMapIter != mAncestorMap.end(); ++ancestorMapIter ){
387 Int_t idx = ancestorMapIter->second;
390 if( idx > -1 && track )
391 new( (*mAncestorParticleArr)[ idx ] )
McParticle_t( getAncestorIdx( track->parent() ),
392 getVertexIdx( track->startVertex() ),
393 getVertexIdx( track->stopVertex() ),
397 TVector3( track->momentum().xyz() ),
398 0, 0, 0, 0, 0, TVector3(),
403 for( mVertexMapIter = mVertexMap.begin(); mVertexMapIter != mVertexMap.end(); ++mVertexMapIter ){
404 Int_t idx = mVertexMapIter->second;
407 if( idx > -1 && vertex )
408 new( (*mVertexArr)[ idx ] ) TVector3( vertex->position().xyz() );
428 mAncestorParticleArr->Clear(
"C");
429 mIncidentParticleArr->Clear(
"C");
430 mVertexArr->Clear(
"C");
432 mAncestorMap.clear();
449 mFilename = fileName;
452 void StMcEEmcTreeMaker_t::setMaxNumEvents( Int_t maxNum ){
457 void StMcEEmcTreeMaker_t::setEnergyThreshold( Float_t val ){
458 mTowEnergyThres = val;
462 Int_t StMcEEmcTreeMaker_t::getVertexIdx(
const StMcVertex* vertex ){
465 if( vertex && vertex->position().z() > -900 ){
466 mVertexMapIter = mVertexMap.find( vertex );
467 if( mVertexMapIter != mVertexMap.end() ) {
468 idx = mVertexMapIter->second;
470 idx = mVertexMap.size();
471 mVertexMap[ vertex ] = idx;
478 Int_t StMcEEmcTreeMaker_t::getAncestorIdx(
const StMcTrack* track ){
482 mAncestorMapIter = mAncestorMap.find( track );
483 if( mAncestorMapIter != mAncestorMap.end() ) {
484 idx = mAncestorMapIter->second;
486 idx = mAncestorMap.size();
487 mAncestorMap[ track ] = idx;
virtual ~StMcEEmcTreeMaker_t()
deconstructor
iostatus_t mIOStat
filenames
Monte Carlo Track class All information on a simulated track is stored in this class: kinematics...
void setTreeStatus(iostatus_t iostatus, const Char_t *fileName)
modifiers
StMcEEmcTreeMaker_t(const Char_t *myName)
constructor
Int_t Make()
Build an event.
TChain * mChain
TChains for reading.
Int_t Finish()
Write everything to file.
void Clear(Option_t *opts="")
Clear for next event.
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Int_t mMaxNumEvents
max number of events
virtual const char * GetName() const
special overload
TClonesArray * mEEmcEnergyArr
The data.
Int_t mNumEvents
number of events processed / written outt
Event data structure to hold all information from a Monte Carlo simulation. This class is the interfa...
TFile * mFile
TFiles/TTrees for writing.