StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StUEMaker2009.cxx
1 //
2 // Grant Webb
3 // Brookhaven National Laboratory
4 // 30 July 2015
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 "StEmcUtil/geometry/StEmcGeom.h"
26 #include "StEEmcUtil/EEmcGeom/EEmcGeomSimple.h"
27 #include "StEEmcUtil/database/StEEmcDb.h"
28 #include "StJetMaker2012.h"
29 #include "StJetSkimEventMaker.h"
30 #include "StUEMaker2009.h"
31 
32 ClassImp(StUEMaker2009);
33 
34 void StUEMaker2009::Clear(Option_t* option)
35 {
36  for (size_t iBranch = 0; iBranch < mUeBranches.size(); ++iBranch) {
37  StUeBranch* uebranch = mUeBranches[iBranch];
38  uebranch->event->Clear(option);
39  }
40 
41  StMaker::Clear(option);
42 }
43 
44 int StUEMaker2009::Init()
45 {
46  assert(!mFileName.IsNull());
47 
48  mFile = TFile::Open(mFileName,"recreate");
49  assert(mFile);
50 
51  mTree = new TTree("ue","ueTree");
52 
53  for (size_t iBranch = 0; iBranch < mUeBranches.size(); ++iBranch) {
54  StUeBranch* uebranch = mUeBranches[iBranch];
55  // jetbranch->jetfinder->Init();
56  mTree->Branch(uebranch->name + "_" + uebranch->jetname,"StUeEvent",&uebranch->event);
57  }
58 
59  mTree->BranchRef();
60  mJetMaker = dynamic_cast<StJetMaker2012*>( GetMakerInheritsFrom("StJetMaker2012") );
61  mSkimMaker = dynamic_cast<StJetSkimEventMaker*>( GetMakerInheritsFrom("StJetSkimEventMaker") );
62  // StEEmcDb* eemcDb = (StEEmcDb*)GetDataSet("StEEmcDb");
63  // eemcDb->setThreshold(3);
64  return StMaker::Init();
65 }
66 
68 {
69  for ( size_t iBranch = 0; iBranch < mUeBranches.size(); ++iBranch){
70  StUeBranch* uebranch = mUeBranches[iBranch];
71  StJetEvent * jetEvent = mJetMaker->event(uebranch->jetname);
72  StJetVertex * jetvertex = jetEvent->vertex();
73  StJetCandidate *leadingjet = findLeadingJet(jetvertex);
74 
75  uebranch->event->mRunId = GetRunNumber();
76  uebranch->event->mEventId = GetEventNumber();
77  uebranch->event->mDatime = GetDateTime();
78  uebranch->event->mLeadingJetpt = leadingjet->pt();
79 
80  if(uebranch->anapars->useTpc){
81 
82  StjTPCMuDst tpc;
83  // Save vertex index
84  // int savedVertexIndex = tpc.currentVertexIndex();
85 
86  // Keep track of number of good vertices
87  int nvertices = 0;
88 
89  // Vertex loop
90  for (int iVertex = 0; iVertex < tpc.numberOfVertices(); ++iVertex) {
91  tpc.setVertexIndex(iVertex);
92 
93  // Get TPC vertex and tracks
94  StjPrimaryVertex vertex = tpc.getVertex();
95 
96  // Skip pile-up vertex
97  if (vertex.ranking() <= 0) continue;
98  if(leadingjet->pt() == 0) continue; // no jet in the event
99  if(leadingjet->vertex()->position().Z() != vertex.position().Z()) continue; // Check that the vertex in the jet and the event are the same
100 
101  // Found good vertex
102  ++nvertices;
103 
104  StjTrackList trackList = tpc.getTrackList();
105  if (uebranch->anapars->changeTracks) trackList = (*uebranch->anapars->changeTracks)(trackList);
106  trackList = uebranch->anapars->tpcCuts()(trackList);
107  trackList = uebranch->anapars->trackRegion()(trackList,leadingjet,uebranch->name);
108  addTracks(trackList,uebranch->event);
109 
110  StjTowerEnergyList bemcEnergyList;
111  if (uebranch->anapars->useBemc) {
112  StjBEMCMuDst bemc;
113  if (uebranch->anapars->changeTowers) (*uebranch->anapars->changeTowers)(bemcEnergyList);
114  bemcEnergyList = uebranch->anapars->bemcCuts()(bemc.getEnergyList());
115  }
116  StjTowerEnergyList energyList;
117  //Apply hadronic correction to towers
118  energyList = uebranch->anapars->correctTowerEnergyForTracks()(bemcEnergyList,trackList);
119  energyList = uebranch->anapars->towerRegion()(energyList,leadingjet,uebranch->name);
120  addTowers(energyList,uebranch->event);
121 
122  StJetVertex* uevertex = uebranch->event->newVertex();
123  copyVertex(vertex, uevertex);
124 
125  } // End of vertex Loop
126  } // End of useTpc
127  if (uebranch->anapars->useMonteCarlo) {
128  StjMCMuDst mc(this);
129  StjPrimaryVertex mcvertex = mc.getMCVertex();
130  StjMCParticleList mcparticles = uebranch->anapars->mcCuts()(mc.getMCParticleList());
131  mcparticles = uebranch->anapars->particleRegion()(mcparticles,leadingjet,uebranch->name);
132  addParticles(mcparticles,uebranch->event);
133  StJetVertex* uevertex = uebranch->event->newVertex();
134  copyVertex(mcvertex, uevertex);
135  }
136  } // End of Loop over UE Branches
137 
138  mTree->Fill();
139  return kStOk;
140 }
141 
143 {
144  mFile->Write();
145  mFile->Close();
146 
147  return kStOk;
148 }
149 
150 void StUEMaker2009::addBranch(const char* name, StAnaPars* anapars, const char* jetname)// StJetPars* jetpars)
151 {
152  mUeBranches.push_back(new StUeBranch(name,anapars,jetname));
153 }
154 
155 
156 void StUEMaker2009::setUeFile(const char* filename)
157 {
158  mFileName = filename;
159 }
160 
161 StUeEvent* StUEMaker2009::event(const char* branchname)
162 {
163  TBranch* branch = mTree->GetBranch(branchname);
164  if (branch) return *(StUeEvent**)branch->GetAddress();
165  return 0;
166 }
167 
168 StJetCandidate* StUEMaker2009::findLeadingJet(StJetVertex *vertex)
169 {
170  // Find highest pt jet
171  StJetCandidate * leadingjet = new StJetCandidate();
172  StJetCandidate * jets = new StJetCandidate();
173  for (int iJet = 0; iJet < vertex->numberOfJets(); ++iJet){
174  jets = (StJetCandidate*) vertex->jet(iJet);
175  if(leadingjet->pt() < jets->pt()){
176  leadingjet = jets;
177  }
178  } // End of loop over jets
179 
180  return leadingjet;
181 }
182 
183 
184 void StUEMaker2009::copyVertex(const StjPrimaryVertex& vertex, StJetVertex* jetvertex)
185 {
186  jetvertex->mPosition = vertex.position();
187  jetvertex->mPosError = vertex.posError();
188  jetvertex->mVertexFinderId = vertex.vertexFinderId();
189  jetvertex->mRanking = vertex.ranking();
190  jetvertex->mNTracksUsed = vertex.nTracksUsed();
191  jetvertex->mNBTOFMatch = vertex.nBTOFMatch();
192  jetvertex->mNCTBMatch = vertex.nCTBMatch();
193  jetvertex->mNBEMCMatch = vertex.nBEMCMatch();
194  jetvertex->mNEEMCMatch = vertex.nEEMCMatch();
195  jetvertex->mNCrossCentralMembrane = vertex.nCrossCentralMembrane();
196  jetvertex->mSumTrackPt = vertex.sumTrackPt();
197  jetvertex->mMeanDip = vertex.meanDip();
198  jetvertex->mChiSquared = vertex.chiSquared();
199  jetvertex->mRefMultPos = vertex.refMultPos();
200  jetvertex->mRefMultNeg = vertex.refMultNeg();
201  jetvertex->mRefMultFtpcWest = vertex.refMultFtpcWest();
202  jetvertex->mRefMultFtpcEast = vertex.refMultFtpcEast();
203 }
204 
205 void StUEMaker2009::copyTrack(const StjTrack& t, StJetTrack* track)
206 {
207  track->mId = t.id;
208  track->mDetectorId = t.detectorId;
209  track->mFlag = t.flag;
210  track->mCharge = t.charge;
211  track->mNHits = t.nHits;
212  track->mNHitsFit = t.nHitsFit;
213  track->mNHitsPoss = t.nHitsPoss;
214  track->mNHitsDedx = t.nHitsDedx;
215  track->mDedx = t.dEdx;
216  track->mBeta = t.beta;
217  track->mFirstPoint = t.firstPoint;
218  track->mLastPoint = t.lastPoint;
219  track->mExitTowerId = t.exitTowerId;
220  track->mExitDetectorId = t.exitDetectorId;
221  track->mDca.SetXYZ(t.dcaX,t.dcaY,t.dcaZ);
222  track->mDcaD = t.dcaD;
223  track->mChi2 = t.chi2;
224  track->mChi2Prob = t.chi2prob;
225  track->mPt = t.pt;
226  track->mEta = t.eta;
227  track->mPhi = t.phi;
228  track->mNSigmaPion = t.nSigmaPion;
229  track->mNSigmaKaon = t.nSigmaKaon;
230  track->mNSigmaProton = t.nSigmaProton;
231  track->mNSigmaElectron = t.nSigmaElectron;
232 
233  track->mBTofTrayId = t.btofTrayId;
234  track->mNSigmaTofPion = t.nSigmaTofPion;
235  track->mNSigmaTofKaon = t.nSigmaTofKaon;
236  track->mNSigmaTofProton = t.nSigmaTofProton;
237  track->mNSigmaTofElectron = t.nSigmaTofElectron;
238 
239  track->mIdTruth = t.idTruth;
240  track->mQaTruth = t.qaTruth;
241 }
242 
243 void StUEMaker2009::copyTower(const StjTowerEnergy& t, StJetTower* tower)
244 {
245  tower->mId = t.towerId;
246  tower->mDetectorId = t.detectorId;
247  tower->mAdc = t.adc;
248  tower->mPedestal = t.pedestal;
249  tower->mRms = t.rms;
250  tower->mStatus = t.status;
251  tower->mEta = t.towerEta;
252  tower->mPhi = t.towerPhi;
253 
254  Float_t energy = t.energy;
255  tower->mPt = energy/TMath::CosH(t.towerEta);
256 }
257 
258 void StUEMaker2009::copyParticle(const StjMCParticle& t, StJetParticle* particle)
259 {
260  particle->mId = t.mcparticleId;
261  particle->mPt = t.pt;
262  particle->mEta = t.eta;
263  particle->mPhi = t.phi;
264  particle->mM = t.m;
265  particle->mE = t.e;
266  particle->mPdg = t.pdg;
267  particle->mStatus = t.status;
268  particle->mFirstMother = t.firstMotherId;
269  particle->mLastMother = t.lastMotherId;
270  particle->mFirstDaughter = t.firstDaughterId;
271  particle->mLastDaughter = t.lastDaughterId;
272 }
273 
274 void StUEMaker2009::addTracks(const StjTrackList& trackList, StUeEvent* event){
275 
276  for (StjTrackList::const_iterator iTrack = trackList.begin(); iTrack != trackList.end(); ++iTrack) {
277  StJetTrack* ueTrack = event->newTrack();
278  StjTrack track = *iTrack;
279  copyTrack(track, ueTrack);
280  }// End of track Loop
281 
282 }
283 
284 void StUEMaker2009::addTowers(const StjTowerEnergyList& towerList, StUeEvent* event){
285 
286  for (StjTowerEnergyList::const_iterator iTower = towerList.begin(); iTower != towerList.end(); ++iTower) {
287 
288  StJetTower* ueTower = event->newTower();
289  StjTowerEnergy tower = *iTower;
290  copyTower(tower, ueTower);
291  }// End of tower Loop
292 }
293 
294 void StUEMaker2009::addParticles(const StjMCParticleList& mcParticleList, StUeEvent* event){
295 
296  for (StjMCParticleList::const_iterator iParticle = mcParticleList.begin(); iParticle != mcParticleList.end(); ++iParticle) {
297 
298  StJetParticle* ueParticle = event->newParticle();
299  StjMCParticle mcparticle = *iParticle;
300  copyParticle(mcparticle, ueParticle);
301  }// End of particle Loop
302 }
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StMaker.cxx:634
void Clear(Option_t *option="")
User defined functions.
virtual Int_t GetRunNumber() const
Returns the current RunNumber.
Definition: StMaker.cxx:1054
Definition: Stypes.h:41