StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StjeDefaultJetTreeWriter.cxx
1 // $Id: StjeDefaultJetTreeWriter.cxx,v 1.12 2010/11/29 02:40:26 pibero Exp $
2 // Copyright (C) 2008 Tai Sakuma <sakuma@bnl.gov>
3 #include "StjeDefaultJetTreeWriter.h"
4 
5 #include <StMuDSTMaker/COMMON/StMuDst.h>
6 #include <StMuDSTMaker/COMMON/StMuEvent.h>
7 #include <StMuDSTMaker/COMMON/StMuDstMaker.h>
8 
9 #include "StSpinPool/StJets/StJets.h"
10 #include "StSpinPool/StJets/StJet.h"
11 #include "StMuTrackFourVec.h"
12 
13 #include "StMuTrackEmu.h"
14 #include "StMuTowerEmu.h"
15 #include "StMcTrackEmu.h"
16 
17 #include <StJetFinder/StProtoJet.h>
18 
19 
20 #include <StFourPMaker.h>
21 #include <StBET4pMaker.h>
22 
23 #include <TTree.h>
24 
25 using namespace std;
26 
27 StjeDefaultJetTreeWriter::StjeDefaultJetTreeWriter(StMuDstMaker& uDstMaker, std::string outFileName)
28  : _uDstMaker(uDstMaker)
29  , _OutFileName(outFileName)
30  , _jetTree(0)
31  , _outFile(0)
32 {
33 
34 }
35 
36 StjeDefaultJetTreeWriter::~StjeDefaultJetTreeWriter()
37 {
38 
39 }
40 
41 void StjeDefaultJetTreeWriter::addJetFinder(StFourPMaker* fourPMaker, const vector<const AbstractFourVec*>* particleList, list<StProtoJet>* protoJetList, const char* name, StJets* stjets)
42 {
43  AnalyzerCtl anaCtl;
44  anaCtl._branchName = name;
45  anaCtl._fourPMaker = fourPMaker;
46  anaCtl._protoJetList = protoJetList;
47  anaCtl._jets = stjets;
48 
49  _analyzerCtlList.push_back(anaCtl);
50 }
51 
52 void StjeDefaultJetTreeWriter::Init()
53 {
54  _outFile = new TFile(_OutFileName.c_str(), "recreate");
55  _jetTree = new TTree("jet", "jetTree");
56 
57  for(vector<AnalyzerCtl>::iterator it = _analyzerCtlList.begin(); it != _analyzerCtlList.end(); ++it) {
58  _jetTree->Branch((*it)._branchName.c_str(), "StJets", &((*it)._jets));
59  }
60 
61  _jetTree->BranchRef();
62 }
63 
64 void StjeDefaultJetTreeWriter::Finish()
65 {
66  _outFile->Write();
67  _outFile->Close();
68  delete _outFile;
69  _outFile = 0;
70 }
71 
72 void StjeDefaultJetTreeWriter::fillJetTreeHeader(int iAnalyzer)
73 {
74  StFourPMaker* fourPMaker = _analyzerCtlList[iAnalyzer]._fourPMaker;
75  StJets& jets = *_analyzerCtlList[iAnalyzer]._jets;
76 
77  jets.Clear();
78  jets.setBemcCorrupt(fourPMaker->bemcCorrupt());
79 
80  StMuEvent* event = _uDstMaker.muDst()->event();
81  jets.seteventId(event->eventId());
82  jets.seteventNumber(event->eventNumber());
83  jets.setrunId(event->runId());
84  jets.setrunNumber(event->runNumber());
85 
86  StBET4pMaker* bet4p = dynamic_cast<StBET4pMaker*>(fourPMaker);
87  if (bet4p) {
88  jets.setDylanPoints( bet4p->nDylanPoints() );
89  jets.setSumEmcE( bet4p->sumEmcEt() );
90  }
91 }
92 
93 void StjeDefaultJetTreeWriter::fillJetTree(int iAnalyzer, int iVertex)
94 {
95  if (iVertex) return; // Only use first vertex
96  StFourPMaker* fourPMaker = _analyzerCtlList[iAnalyzer]._fourPMaker;
97  std::list<StProtoJet>* protoJetList = _analyzerCtlList[iAnalyzer]._protoJetList;
98  fillJetTreeForOneJetFindingAlgorithm(*_analyzerCtlList[iAnalyzer]._jets, protoJetList, fourPMaker);
99 }
100 
101 void StjeDefaultJetTreeWriter::fillJetTreeForOneJetFindingAlgorithm(StJets& jets, std::list<StProtoJet>* protoJetList, StFourPMaker* fourPMaker)
102 {
103  for(list<StProtoJet>::iterator it = protoJetList->begin(); it != protoJetList->end(); ++it) {
104  fillJet(jets, *it);
105  }
106 }
107 
108 void StjeDefaultJetTreeWriter::fillJet(StJets &stjets, StProtoJet& pj)
109 {
110  StJet aJet(StJet(pj.e(), pj.px(), pj.py(), pj.pz(), 0, 0));
111  stjets.addJet(aJet);
112  TClonesArray* jets = stjets.jets();
113  StJet* jet = (StJet*)jets->Last();
114  jet->zVertex = _uDstMaker.muDst()->event()->primaryVertexPosition().z();
115 
116  const StProtoJet::FourVecList &particleList = pj.list();
117  for(StProtoJet::FourVecList::const_iterator it2 = particleList.begin(); it2 != particleList.end(); ++it2) {
118  const StMuTrackFourVec *particle = dynamic_cast<const StMuTrackFourVec*>(*it2);
119  if (!particle) {
120  cout <<"StJets::addProtoJet(). ERROR:\tcast to StMuTrackFourVecFailed. no action"<<endl;
121  return;
122  }
123  int muTrackIndex = particle->getIndex();
124  if (muTrackIndex <0) {
125  cout <<"Error, muTrackIndex<0. abort()"<<endl;
126  abort();
127  }
128 
129  StDetectorId detectorId;
130  int mDetId = particle->detectorId();
131  if (mDetId==kTpcIdentifier)
132  detectorId = kTpcId;
133  else if (mDetId==kBarrelEmcTowerIdentifier)
134  detectorId = kBarrelEmcTowerId;
135  else if (mDetId==kEndcapEmcTowerIdentifier)
136  detectorId = kEndcapEmcTowerId;
137  else
138  detectorId = kUnknownId;
139 
140  // Add tracks
141  if (StMuTrackEmu* track = particle->track()) {
142  TrackToJetIndex t2j( jets->GetLast(), muTrackIndex, detectorId, jet );
143 
144  t2j.SetPxPyPzE(particle->px(), particle->py(), particle->pz(), particle->e() );
145  t2j.setTrackId( track->id() );
146  t2j.setFlag( track->flag() );
147  t2j.setCharge( track->charge() );
148  t2j.setNhits( track->nHits() );
149  t2j.setNhitsPoss( track->nHitsPoss() );
150  t2j.setNhitsDedx( track->nHitsDedx() );
151  t2j.setNhitsFit( track->nHitsFit() );
152  t2j.setNsigmaPion( track->nSigmaPion() );
153  t2j.setNsigmaElectron( track->nSigmaElectron() );
154  t2j.setNsigmaKaon( track->nSigmaKaon() );
155  t2j.setNsigmaProton( track->nSigmaProton() );
156  t2j.setTdca ( track->Tdca() );
157  t2j.setTdcaz ( track->dcaZ() );
158  t2j.setTdcaxy ( track->dcaD() );
159  t2j.setetaext ( track->etaext() );
160  t2j.setphiext ( track->phiext() );
161  t2j.setdEdx ( track->dEdx() );
162 
163  stjets.addTrackToIndex(t2j); // for backward compatibility
164  jet->addTrack((TrackToJetIndex*)stjets.tracks()->Last());
165  }
166 
167  // Add towers
168  if (StMuTowerEmu* tower = particle->tower()) {
169  TowerToJetIndex t2j(jets->GetLast());
170 
171  t2j.SetPxPyPzE(particle->px(), particle->py(), particle->pz(), particle->e());
172  t2j.setTowerId(tower->id());
173  t2j.setDetectorId(tower->detectorId());
174  t2j.setAdc(tower->adc());
175  t2j.setPedestal(tower->pedestal());
176  t2j.setRms(tower->rms());
177  t2j.setStatus(tower->status());
178 
179  stjets.addTowerToIndex(t2j); // for backward compatibility
180  jet->addTower((TowerToJetIndex*)stjets.towers()->Last());
181  }
182 
183  // Add Pythia particles
184  if (StMcTrackEmu* mctrack = particle->mctrack()) {
185  TrackToJetIndex t2j( jets->GetLast(), muTrackIndex, detectorId, jet );
186 
187  t2j.SetPtEtaPhiE(mctrack->pt(),mctrack->eta(),mctrack->phi(),mctrack->e());
188  t2j.setId(mctrack->id());
189  t2j.setPdg(mctrack->pdg());
190  t2j.setStatus(mctrack->status());
191 
192  stjets.addTrackToIndex(t2j); // for backward compatibility
193  jet->addTrack((TrackToJetIndex*)stjets.tracks()->Last());
194  }
195 
196  if (mDetId==kTpcIdentifier) {
197  jet->nTracks++;
198  jet->tpcEtSum += particle->eT();
199  }
200  else if (mDetId==kBarrelEmcTowerIdentifier) {
201  jet->nBtowers++;
202  jet->btowEtSum += particle->eT();
203  }
204  else if (mDetId==kEndcapEmcTowerIdentifier) {
205  jet->nEtowers++;
206  jet->etowEtSum += particle->eT();
207  }
208  }
209 }
StThreeVectorF primaryVertexPosition(int vtx_id=-1) const
The StMuDst is supposed to be structured in &#39;physical events&#39;. Therefore there is only 1 primary vert...
Definition: StMuEvent.cxx:221
StMuDst * muDst()
Definition: StMuDstMaker.h:425
int nTracks
The number of tracks in this jet.
Definition: StJet.h:104
void setBemcCorrupt(bool v)
Set the BEMC corrupt flag. true –&gt; event is corrupt, no jet finding was performed.
Definition: StJets.h:35
TClonesArray * jets()
Access to the jets in this event.
Definition: StJets.h:42
Definition: StJets.h:24
float zVertex
position of vertex used to reconstruct jet
Definition: StJet.h:134
int nBtowers
The number of Barrel towers in this jet.
Definition: StJet.h:107
float etowEtSum
The summed Et from Endcap towers.
Definition: StJet.h:119
TClonesArray * tracks()
The track/tower to jet indices TClonesArray: this contains all the 4momenta contained in jets for jet...
Definition: StJets.h:47
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:320
int nEtowers
The number of Endcap towers in this jet.
Definition: StJet.h:110
float tpcEtSum
The summed Et from tracks.
Definition: StJet.h:113
float btowEtSum
The summed Et from Barrel towers.
Definition: StJet.h:116
Definition: StJet.h:91