StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StJetMaker2009.cxx
1 //
2 // Pibero Djawotho <pibero@tamu.edu>
3 // Texas A&M University
4 // 27 May 2010
5 //
6 
7 #include <list>
8 #include "TFile.h"
9 #include "TTree.h"
10 #include "StAnaPars.h"
11 #include "StjTPCMuDst.h"
12 //#include "StjTPCRandomMuDst.h"
13 #include "StjBEMCMuDst.h"
14 #include "StjEEMCMuDst.h"
15 #include "StjMCMuDst.h"
16 #include "StjTPCNull.h"
17 #include "StjBEMCNull.h"
18 #include "StjEEMCNull.h"
19 #include "StjAbstractTowerEnergyCorrectionForTracks.h"
20 #include "StjeTrackListToStMuTrackFourVecList.h"
21 #include "StjeTowerEnergyListToStMuTrackFourVecList.h"
22 #include "StjMCParticleToStMuTrackFourVec.h"
23 #include "StJetFinder/StJetFinder.h"
24 #include "StSpinPool/StJetEvent/StJetEventTypes.h"
25 #include "StMuTrackFourVec.h"
26 #include "StMuTrackEmu.h"
27 #include "StMuTowerEmu.h"
28 #include "StMcTrackEmu.h"
29 #include "StEmcUtil/geometry/StEmcGeom.h"
30 #include "StEEmcUtil/EEmcGeom/EEmcGeomSimple.h"
31 #include "StEEmcUtil/database/StEEmcDb.h"
32 
33 #include "StJetMaker2009.h"
34 
35 ClassImp(StJetMaker2009);
36 
37 void StJetMaker2009::Clear(Option_t* option)
38 {
39  for (size_t iBranch = 0; iBranch < mJetBranches.size(); ++iBranch) {
40  StJetBranch* jetbranch = mJetBranches[iBranch];
41  jetbranch->event->Clear(option);
42  }
43 
44  StMaker::Clear(option);
45 }
46 
47 int StJetMaker2009::Init()
48 {
49  assert(!mFileName.IsNull());
50 
51  mFile = TFile::Open(mFileName,"recreate");
52  assert(mFile);
53 
54  mTree = new TTree("jet","jetTree");
55 
56  for (size_t iBranch = 0; iBranch < mJetBranches.size(); ++iBranch) {
57  StJetBranch* jetbranch = mJetBranches[iBranch];
58  jetbranch->jetfinder->Init();
59  mTree->Branch(jetbranch->name,"StJetEvent",&jetbranch->event);
60  }
61 
62  mTree->BranchRef();
63 
64  StEEmcDb* eemcDb = (StEEmcDb*)GetDataSet("StEEmcDb");
65  eemcDb->setThreshold(3);
66 
67  return StMaker::Init();
68 }
69 
71 {
72  // Loop over jet branches
73  for (size_t iBranch = 0; iBranch < mJetBranches.size(); ++iBranch) {
74  StJetBranch* jetbranch = mJetBranches[iBranch];
75 
76  // Fill header
77  jetbranch->event->mRunId = GetRunNumber();
78  jetbranch->event->mEventId = GetEventNumber();
79  jetbranch->event->mDatime = GetDateTime();
80 
81  if (jetbranch->anapars->useTpc) {
82 // StjTPCRandomMuDst tpc((StMuDstMaker*)0,
83 // jetbranch->anapars->randomSelectorProb,
84 // jetbranch->anapars->randomSelectorAt,
85 // jetbranch->anapars->randomSelectorSeed);
86  StjTPCMuDst tpc;
87 
88  // Save vertex index
89  int savedVertexIndex = tpc.currentVertexIndex();
90 
91  // Keep track of number of good vertices
92  int nvertices = 0;
93 
94  int totNumVertices = tpc.numberOfVertices();
95  // store the total number of available vertices if set by anapars
96  if(jetbranch->anapars->storeOnlyDefaultVertex && totNumVertices > 1) {
97  totNumVertices = 1;
98  }
99 
100  // Vertex loop
101  for (int iVertex = 0; iVertex < totNumVertices; ++iVertex) {
102  tpc.setVertexIndex(iVertex);
103 
104  // Get TPC vertex and tracks
105  StjPrimaryVertex vertex = tpc.getVertex();
106 
107  // Skip pile-up vertex
108  if (vertex.ranking() <= 0) continue;
109 
110  // Found good vertex
111  ++nvertices;
112  StjTrackList trackList = tpc.getTrackList();
113  if (jetbranch->anapars->changeTracks) trackList = (*jetbranch->anapars->changeTracks)(trackList);
114  trackList = jetbranch->anapars->tpcCuts()(trackList);
115 
116  // Get BEMC towers
117  StjTowerEnergyList bemcEnergyList;
118 
119  if (jetbranch->anapars->useBemc) {
120  StjBEMCMuDst bemc;
121  bemcEnergyList = bemc.getEnergyList();
122  if (jetbranch->anapars->changeTowers) (*jetbranch->anapars->changeTowers)(bemcEnergyList);
123  bemcEnergyList = jetbranch->anapars->bemcCuts()(bemcEnergyList);
124  }
125 
126  // Get EEMC towers
127  StjTowerEnergyList eemcEnergyList;
128 
129  if (jetbranch->anapars->useEemc) {
130  StjEEMCMuDst eemc;
131  eemcEnergyList = eemc.getEnergyList();
132  if (jetbranch->anapars->changeTowers) (*jetbranch->anapars->changeTowers)(eemcEnergyList);
133  eemcEnergyList = jetbranch->anapars->eemcCuts()(eemcEnergyList);
134  }
135 
136  // Merge BEMC and EEMC towers
137  StjTowerEnergyList energyList;
138 
139  copy(bemcEnergyList.begin(),bemcEnergyList.end(),back_inserter(energyList));
140  copy(eemcEnergyList.begin(),eemcEnergyList.end(),back_inserter(energyList));
141 
142  // Apply hadronic correction to towers
143  energyList = jetbranch->anapars->correctTowerEnergyForTracks()(energyList,trackList);
144 
145  // Convert tracks and towers to Lorentz vectors
146  FourList tpc4pList = StjeTrackListToStMuTrackFourVecList()(trackList);
147  FourList energy4pList = StjeTowerEnergyListToStMuTrackFourVecList()(energyList);
148 
149  // Merge tracks and towers
150  StProtoJet::FourVecList particles; // vector<const AbstractFourVec*>
151 
152  copy(tpc4pList.begin(),tpc4pList.end(),back_inserter(particles));
153  copy(energy4pList.begin(),energy4pList.end(),back_inserter(particles));
154 
155  // Run jet finder
156  StJetFinder::JetList protojets; // list<StProtoJet>
157  jetbranch->jetfinder->findJets(protojets,particles);
158 
159  // Filter jets
160  protojets = jetbranch->anapars->jetCuts()(protojets);
161 
162  // Add vertex
163  StJetVertex* jetvertex = jetbranch->event->newVertex();
164  copyVertex(vertex,jetvertex);
165 
166  // Add jets
167  for (StJetFinder::JetList::const_iterator iProtoJet = protojets.begin(); iProtoJet != protojets.end(); ++iProtoJet)
168  addJet(*iProtoJet,jetbranch->event,jetvertex);
169 
170  // Clean up particles
171  for (StProtoJet::FourVecList::const_iterator i = particles.begin(); i != particles.end(); ++i)
172  delete *i;
173  } // End vertex loop
174 
175  // No good vertex was found. Use (0,0,0) for vertex and EMC-only jets.
176  // Useful for beam-gas background studies.
177  if (!nvertices) {
178  // Get BEMC towers
179  StjTowerEnergyList bemcEnergyList;
180 
181  if (jetbranch->anapars->useBemc) {
182  StjBEMCMuDst bemc;
183  bemc.setVertex(0,0,0);
184  bemcEnergyList = bemc.getEnergyList();
185  if (jetbranch->anapars->changeTowers) (*jetbranch->anapars->changeTowers)(bemcEnergyList);
186  bemcEnergyList = jetbranch->anapars->bemcCuts()(bemcEnergyList);
187  }
188 
189  // Get EEMC towers
190  StjTowerEnergyList eemcEnergyList_temp, eemcEnergyList;
191 
192  if (jetbranch->anapars->useEemc) {
193  StjEEMCMuDst eemc;
194  eemcEnergyList = eemc.getEnergyList();
195  if (jetbranch->anapars->changeTowers) (*jetbranch->anapars->changeTowers)(eemcEnergyList);
196  eemcEnergyList = jetbranch->anapars->eemcCuts()(eemcEnergyList);
197 
198  }
199 
200  // Merge BEMC and EEMC towers
201  StjTowerEnergyList energyList;
202 
203  copy(bemcEnergyList.begin(),bemcEnergyList.end(),back_inserter(energyList));
204  copy(eemcEnergyList.begin(),eemcEnergyList.end(),back_inserter(energyList));
205 
206  // Convert towers to Lorentz vectors
207  FourList energy4pList = StjeTowerEnergyListToStMuTrackFourVecList()(energyList);
208 
209  // Merge tracks and towers
210  StProtoJet::FourVecList particles; // vector<const AbstractFourVec*>
211 
212  copy(energy4pList.begin(),energy4pList.end(),back_inserter(particles));
213 
214  // Run jet finder
215  StJetFinder::JetList protojets; // list<StProtoJet>
216  jetbranch->jetfinder->findJets(protojets,particles);
217 
218  // Filter jets
219  protojets = jetbranch->anapars->jetCuts()(protojets);
220 
221  // Add dummy vertex (0,0,0)
222  StJetVertex* jetvertex = jetbranch->event->newVertex();
223  jetvertex->mPosition.SetXYZ(0,0,0);
224 
225  // Add jets
226  for (StJetFinder::JetList::const_iterator iProtoJet = protojets.begin(); iProtoJet != protojets.end(); ++iProtoJet)
227  addJet(*iProtoJet,jetbranch->event,jetvertex);
228 
229  // Clean up particles
230  for (StProtoJet::FourVecList::const_iterator i = particles.begin(); i != particles.end(); ++i)
231  delete *i;
232  }
233 
234  // Restore vertex index
235  tpc.setVertexIndex(savedVertexIndex);
236 
237  } // End useTpc
238 
239  if (jetbranch->anapars->useMonteCarlo) {
240  StjMCMuDst mc(this);
241  StjPrimaryVertex mcvertex = mc.getMCVertex();
242  StjMCParticleList mcparticles = jetbranch->anapars->mcCuts()(mc.getMCParticleList());
243  StProtoJet::FourVecList particles; // vector<const AbstractFourVec*>
244  transform(mcparticles.begin(),mcparticles.end(),back_inserter(particles),StjMCParticleToStMuTrackFourVec());
245 
246  // Run jet finder
247  StJetFinder::JetList protojets; // list<StProtoJet>
248  jetbranch->jetfinder->findJets(protojets,particles);
249 
250  // Filter jets
251  protojets = jetbranch->anapars->jetCuts()(protojets);
252 
253  // Add vertex
254  StJetVertex* jetvertex = jetbranch->event->newVertex();
255  copyVertex(mcvertex,jetvertex);
256 
257  // Add jets
258  for (StJetFinder::JetList::const_iterator iProtoJet = protojets.begin(); iProtoJet != protojets.end(); ++iProtoJet)
259  addJet(*iProtoJet,jetbranch->event,jetvertex);
260 
261  // Clean up particles
262  for (StProtoJet::FourVecList::const_iterator i = particles.begin(); i != particles.end(); ++i)
263  delete *i;
264  } // End useMonteCarlo
265 
266  } // End loop over jet branches
267 
268  mTree->Fill();
269 
270  return kStOk;
271 }
272 
274 {
275  mFile->Write();
276  mFile->Close();
277 
278  return kStOk;
279 }
280 
281 // Setters
282 
283 void StJetMaker2009::addBranch(const char* name, StAnaPars* anapars, StJetPars* jetpars)
284 {
285  mJetBranches.push_back(new StJetBranch(name,anapars,jetpars));
286 }
287 
288 void StJetMaker2009::setJetFile(const char* filename)
289 {
290  mFileName = filename;
291 }
292 
293 // Getters
294 
295 TTree* StJetMaker2009::tree()
296 {
297  return mTree;
298 }
299 
300 StJetEvent* StJetMaker2009::event(const char* branchname)
301 {
302  TBranch* branch = mTree->GetBranch(branchname);
303  if (branch) return *(StJetEvent**)branch->GetAddress();
304  return 0;
305 }
306 
307 void StJetMaker2009::addJet(const StProtoJet& protojet, StJetEvent* event, StJetVertex* vertex)
308 {
309  StJetCandidate* jet = event->newJet(vertex->position(),TLorentzVector(protojet.px(),protojet.py(),protojet.pz(),protojet.e()), static_cast<float>(protojet.area()), static_cast<float>(protojet.areaError()));
310  vertex->addJet(jet);
311  jet->setVertex(vertex);
312 
313  // Add jet particles
314  const StProtoJet::FourVecList& particles = protojet.list();
315  for (StProtoJet::FourVecList::const_iterator iParticle = particles.begin(); iParticle != particles.end(); ++iParticle) {
316  const StMuTrackFourVec* particle = dynamic_cast<const StMuTrackFourVec*>(*iParticle);
317 
318  if (const StMuTrackEmu* t = particle->track()) {
319  StJetTrack* track = event->newTrack();
320  copyTrack(t,track);
321  jet->addTrack(track)->setJet(jet);
322  }
323 
324  if (const StMuTowerEmu* t = particle->tower()) {
325  StJetTower* tower = event->newTower();
326  copyTower(t,tower);
327  jet->addTower(tower)->setJet(jet);
328  }
329 
330  if (const StMcTrackEmu* t = particle->mctrack()) {
331  StJetParticle* part = event->newParticle();
332  copyParticle(t,part);
333  jet->addParticle(part)->setJet(jet);
334  }
335  } // End add jet particles
336 
337  // Calculate neutral fraction
338  float sumTowerPt = jet->sumTowerPt();
339  float sumTrackPt = jet->sumTrackPt();
340  jet->mRt = sumTowerPt/(sumTowerPt+sumTrackPt);
341 }
342 
343 void StJetMaker2009::copyVertex(const StjPrimaryVertex& vertex, StJetVertex* jetvertex)
344 {
345  jetvertex->mPosition = vertex.position();
346  jetvertex->mPosError = vertex.posError();
347  jetvertex->mVertexFinderId = vertex.vertexFinderId();
348  jetvertex->mRanking = vertex.ranking();
349  jetvertex->mNTracksUsed = vertex.nTracksUsed();
350  jetvertex->mNBTOFMatch = vertex.nBTOFMatch();
351  jetvertex->mNCTBMatch = vertex.nCTBMatch();
352  jetvertex->mNBEMCMatch = vertex.nBEMCMatch();
353  jetvertex->mNEEMCMatch = vertex.nEEMCMatch();
354  jetvertex->mNCrossCentralMembrane = vertex.nCrossCentralMembrane();
355  jetvertex->mSumTrackPt = vertex.sumTrackPt();
356  jetvertex->mMeanDip = vertex.meanDip();
357  jetvertex->mChiSquared = vertex.chiSquared();
358  jetvertex->mRefMultPos = vertex.refMultPos();
359  jetvertex->mRefMultNeg = vertex.refMultNeg();
360  jetvertex->mRefMultFtpcWest = vertex.refMultFtpcWest();
361  jetvertex->mRefMultFtpcEast = vertex.refMultFtpcEast();
362 }
363 
364 void StJetMaker2009::copyTrack(const StMuTrackEmu* t, StJetTrack* track)
365 {
366  track->mId = t->id();
367  track->mDetectorId = t->detectorId();
368  track->mFlag = t->flag();
369  track->mCharge = t->charge();
370  track->mNHits = t->nHits();
371  track->mNHitsFit = t->nHitsFit();
372  track->mNHitsPoss = t->nHitsPoss();
373  track->mNHitsDedx = t->nHitsDedx();
374  track->mDedx = t->dEdx();
375  track->mBeta = t->beta();
376  track->mFirstPoint = t->firstPoint();
377  track->mLastPoint = t->lastPoint();
378  track->mExitTowerId = t->exitTowerId();
379  track->mExitDetectorId = t->exitDetectorId();
380  track->mExitPoint.SetPtEtaPhi(t->bemcRadius(),t->etaext(),t->phiext());
381  track->mDca.SetXYZ(t->dcaX(),t->dcaY(),t->dcaZ());
382  track->mDcaD = t->dcaD();
383  track->mChi2 = t->chi2();
384  track->mChi2Prob = t->chi2prob();
385  TVector3 mom(t->px(),t->py(),t->pz());
386  track->mPt = mom.Pt();
387  track->mEta = mom.Eta();
388  track->mPhi = mom.Phi();
389  track->mNSigmaPion = t->nSigmaPion();
390  track->mNSigmaKaon = t->nSigmaKaon();
391  track->mNSigmaProton = t->nSigmaProton();
392  track->mNSigmaElectron = t->nSigmaElectron();
393 
394  track->mBTofTrayId = t->btofTrayId();
395  track->mNSigmaTofPion = t->nSigmaTofPion();
396  track->mNSigmaTofKaon = t->nSigmaTofKaon();
397  track->mNSigmaTofProton = t->nSigmaTofProton();
398  track->mNSigmaTofElectron = t->nSigmaTofElectron();
399 
400  track->mIdTruth = t->idTruth();
401  track->mQaTruth = t->qaTruth();
402 }
403 
404 void StJetMaker2009::copyTower(const StMuTowerEmu* t, StJetTower* tower)
405 {
406  tower->mId = t->id();
407  tower->mDetectorId = t->detectorId();
408  tower->mAdc = t->adc();
409  tower->mPedestal = t->pedestal();
410  tower->mRms = t->rms();
411  tower->mStatus = t->status();
412  TVector3 mom(t->px(),t->py(),t->pz());
413  tower->mPt = mom.Pt();
414  tower->mEta = mom.Eta();
415  tower->mPhi = mom.Phi();
416 }
417 
418 void StJetMaker2009::copyParticle(const StMcTrackEmu* t, StJetParticle* particle)
419 {
420  particle->mId = t->id();
421  particle->mPt = t->pt();
422  particle->mEta = t->eta();
423  particle->mPhi = t->phi();
424  particle->mM = t->m();
425  particle->mE = t->e();
426  particle->mPdg = t->pdg();
427  particle->mStatus = t->status();
428  particle->mFirstMother = t->firstMother();
429  particle->mLastMother = t->lastMother();
430  particle->mFirstDaughter = t->firstDaughter();
431  particle->mLastDaughter = t->lastDaughter();
432 }
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StMaker.cxx:634
virtual Int_t GetRunNumber() const
Returns the current RunNumber.
Definition: StMaker.cxx:1054
void Clear(Option_t *option="")
User defined functions.
Definition: Stypes.h:41