StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StjeJetEventTreeWriter.cxx
1 //
2 // Pibero Djawotho <pibero@tamu.edu>
3 // Texas A&M University
4 // 1 September 2009
5 //
6 
7 class StJets;
8 
9 #include "StEmcUtil/geometry/StEmcGeom.h"
10 #include "StEEmcUtil/EEmcGeom/EEmcGeomSimple.h"
11 #include "StEventTypes.h"
12 #include "StMuDSTMaker/COMMON/StMuTypes.hh"
13 #include "StMuTrackFourVec.h"
14 
15 #include "StMuTrackEmu.h"
16 #include "StMuTowerEmu.h"
17 #include "StMcTrackEmu.h"
18 #include "StSpinPool/StJetEvent/StJetEventTypes.h"
19 
20 #include "StJetFinder/StProtoJet.h"
21 
22 #include "StFourPMaker.h"
23 #include "StBET4pMaker.h"
24 
25 #include "TFile.h"
26 #include "TTree.h"
27 
28 #include "StjeJetEventTreeWriter.h"
29 
30 ClassImp(StjeJetEventTreeWriter);
31 
32 StjeJetEventTreeWriter::StjeJetEventTreeWriter(const char* outFileName)
33  : _OutFileName(outFileName)
34  , _jetTree(0)
35  , _outFile(0)
36 {
37 }
38 
39 void StjeJetEventTreeWriter::addJetFinder(StFourPMaker* fourPMaker, const vector<const AbstractFourVec*>* particleList, list<StProtoJet>* protoJetList, const char* name, StJets*)
40 {
41  AnalyzerCtl anaCtl;
42 
43  anaCtl._branchName = name;
44  anaCtl._fourPMaker = fourPMaker;
45  anaCtl._protoJetList = protoJetList;
46  anaCtl._jetEvent = new StJetEvent;
47 
48  _analyzerCtlList.push_back(anaCtl);
49 }
50 
51 void StjeJetEventTreeWriter::Init()
52 {
53  _outFile = new TFile(_OutFileName, "recreate");
54  _jetTree = new TTree("jet", "jetTree");
55 
56  for (vector<AnalyzerCtl>::iterator iAnalyzer = _analyzerCtlList.begin(); iAnalyzer != _analyzerCtlList.end(); ++iAnalyzer)
57  _jetTree->Branch(iAnalyzer->_branchName.c_str(), "StJetEvent", &iAnalyzer->_jetEvent);
58 
59  _jetTree->BranchRef();
60 }
61 
62 void StjeJetEventTreeWriter::Finish()
63 {
64  _outFile->Write();
65  _outFile->Close();
66  delete _outFile;
67  _outFile = 0;
68 }
69 
70 void StjeJetEventTreeWriter::fillJetTreeHeader(int iAnalyzer)
71 {
72  StJetEvent* jetEvent = _analyzerCtlList[iAnalyzer]._jetEvent;
73  StFourPMaker* fourPMaker = _analyzerCtlList[iAnalyzer]._fourPMaker;
74  jetEvent->Clear();
75  jetEvent->mRunId = fourPMaker->GetRunNumber();
76  jetEvent->mEventId = fourPMaker->GetEventNumber();
77  jetEvent->mDatime = fourPMaker->GetDateTime();
78 }
79 
80 void StjeJetEventTreeWriter::fillJetTree(int iAnalyzer, int iVertex)
81 {
82  AnalyzerCtl& analyzerCtl = _analyzerCtlList[iAnalyzer];
83  fillJetTreeForOneVertex(analyzerCtl._jetEvent,analyzerCtl._protoJetList,analyzerCtl._fourPMaker,iVertex);
84 }
85 
86 void StjeJetEventTreeWriter::fillJetTreeForOneVertex(StJetEvent* jetEvent, list<StProtoJet>* protoJetList, StFourPMaker* fourPMaker, int iVertex)
87 {
88  StJetVertex* jetVertex = jetEvent->newVertex();
89  copyVertex(fourPMaker->getVertexNodes()[iVertex].vertex,jetVertex);
90  for (list<StProtoJet>::iterator protojet = protoJetList->begin(); protojet != protoJetList->end(); ++protojet)
91  jetVertex->addJet(fillJet(jetEvent,jetVertex,*protojet));
92 }
93 
94 StJetCandidate* StjeJetEventTreeWriter::fillJet(StJetEvent* jetEvent, StJetVertex* jetVertex, StProtoJet& protojet)
95 {
96  StJetCandidate* jet = jetEvent->newJet(jetVertex->position(),TLorentzVector(protojet.px(),protojet.py(),protojet.pz(),protojet.e()));
97 
98  // Loop over jet particles
99  const StProtoJet::FourVecList& particleList = protojet.list();
100  for (StProtoJet::FourVecList::const_iterator iParticle = particleList.begin(); iParticle != particleList.end(); ++iParticle) {
101  const StMuTrackFourVec* particle = dynamic_cast<const StMuTrackFourVec*>(*iParticle);
102 
103  if (StMuTrackEmu* t = particle->track()) {
104  StJetTrack* track = jetEvent->newTrack();
105  track->mId = t->id();
106  track->mDetectorId = t->detectorId();
107  track->mFlag = t->flag();
108  track->mCharge = t->charge();
109  track->mNHits = t->nHits();
110  track->mNHitsFit = t->nHitsFit();
111  track->mNHitsPoss = t->nHitsPoss();
112  track->mNHitsDedx = t->nHitsDedx();
113  track->mDedx = t->dEdx();
114  track->mBeta = t->beta();
115  track->mFirstPoint = t->firstPoint();
116  track->mLastPoint = t->lastPoint();
117  track->mExitTowerId = t->exitTowerId();
118  track->mExitDetectorId = t->exitDetectorId();
119  track->mExitPoint.SetPtEtaPhi(t->bemcRadius(),t->etaext(),t->phiext());
120  track->mDca.SetXYZ(t->dcaX(),t->dcaY(),t->dcaZ());
121  track->mDcaD = t->dcaD();
122  track->mChi2 = t->chi2();
123  track->mChi2Prob = t->chi2prob();
124  TVector3 mom(t->px(),t->py(),t->pz());
125  track->mPt = mom.Pt();
126  track->mEta = mom.Eta();
127  track->mPhi = mom.Phi();
128  track->mNSigmaPion = t->nSigmaPion();
129  track->mNSigmaKaon = t->nSigmaKaon();
130  track->mNSigmaProton = t->nSigmaProton();
131  track->mNSigmaElectron = t->nSigmaElectron();
132  jet->addTrack(track)->setJet(jet);
133  }
134 
135  if (StMuTowerEmu* t = particle->tower()) {
136  StJetTower* tower = jetEvent->newTower();
137  tower->mId = t->id();
138  tower->mDetectorId = t->detectorId();
139  tower->mAdc = t->adc();
140  tower->mPedestal = t->pedestal();
141  tower->mRms = t->rms();
142  tower->mStatus = t->status();
143 
144  // StMuTowerEmu has the tower momentum from
145  // the origin. Here we correct for vertex.
146 
147  TVector3 mom(t->px(),t->py(),t->pz());
148  float energy = mom.Mag();
149 
150  switch (t->detectorId()) {
151  case kBarrelEmcTowerId:
152  mom.SetPtEtaPhi(StEmcGeom::instance("bemc")->Radius(),mom.Eta(),mom.Phi());
153  break;
154  case kEndcapEmcTowerId:
155  mom.SetMag(EEmcGeomSimple::Instance().getZMean()/mom.Unit().z());
156  break;
157  }
158 
159  mom -= jetVertex->position();
160  mom.SetMag(energy);
161 
162  tower->mPt = mom.Pt();
163  tower->mEta = mom.Eta();
164  tower->mPhi = mom.Phi();
165  jet->addTower(tower)->setJet(jet);
166  }
167 
168  if (StMcTrackEmu* t = particle->mctrack()) {
169  StJetParticle* part = jetEvent->newParticle();
170  part->mId = t->id();
171  part->mPt = t->pt();
172  part->mEta = t->eta();
173  part->mPhi = t->phi();
174  part->mM = t->m();
175  part->mE = t->e();
176  part->mPdg = t->pdg();
177  part->mStatus = t->status();
178  jet->addParticle(part)->setJet(jet);
179  }
180  } // End loop over jet particles
181 
182  float sumTowerPt = jet->sumTowerPt();
183  float sumTrackPt = jet->sumTrackPt();
184 
185  jet->mRt = sumTowerPt/(sumTowerPt+sumTrackPt);
186 
187  jet->setVertex(jetVertex);
188 
189  return jet;
190 }
191 
192 void StjeJetEventTreeWriter::copyVertex(const StMuPrimaryVertex* muVertex, StJetVertex* jetVertex)
193 {
194  jetVertex->mPosition = muVertex->position().xyz();
195  jetVertex->mPosError = muVertex->posError().xyz();
196  jetVertex->mVertexFinderId = muVertex->vertexFinderId();
197  jetVertex->mRanking = muVertex->ranking();
198  jetVertex->mNTracksUsed = muVertex->nTracksUsed();
199  jetVertex->mNBTOFMatch = muVertex->nBTOFMatch();
200  jetVertex->mNCTBMatch = muVertex->nCTBMatch();
201  jetVertex->mNBEMCMatch = muVertex->nBEMCMatch();
202  jetVertex->mNEEMCMatch = muVertex->nEEMCMatch();
203  jetVertex->mNCrossCentralMembrane = muVertex->nCrossCentralMembrane();
204  jetVertex->mSumTrackPt = muVertex->sumTrackPt();
205  jetVertex->mMeanDip = muVertex->meanDip();
206  jetVertex->mChiSquared = muVertex->chiSquared();
207  jetVertex->mRefMultPos = muVertex->refMultPos();
208  jetVertex->mRefMultNeg = muVertex->refMultNeg();
209  jetVertex->mRefMultFtpcWest = muVertex->refMultFtpcWest();
210  jetVertex->mRefMultFtpcEast = muVertex->refMultFtpcEast();
211 }
static EEmcGeomSimple & Instance()
returns a reference to a static instance of EEmcGeomSimple
Definition: StJets.h:24
virtual Int_t GetRunNumber() const
Returns the current RunNumber.
Definition: StMaker.cxx:1054