StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StjJetListWriter.cxx
1 // $Id: StjJetListWriter.cxx,v 1.8 2009/12/03 09:57:36 pibero Exp $
2 #include "StjJetListWriter.h"
3 
4 #include <TFile.h>
5 #include <TTree.h>
6 
7 #include <iostream>
8 
9 ClassImp(StjJetListWriter)
10 
11 using namespace std;
12 
13 StjJetListWriter::StjJetListWriter(const char* jetTreeName, const char* jetFourVecTreeName, TDirectory* file)
14  : _file(file)
15 {
16  _file->cd();
17 
18  _jetTree = new TTree(jetTreeName, jetTreeName);
19  _jetTree->SetAutoSave(kMaxLong64);
20  _jetTree->SetMaxTreeSize(kMaxLong64);
21 
22  _jetTree->Branch("eventId" , &_jet_eventId , "eventId/I" );
23  _jetTree->Branch("nJets" , &_jet_nJets , "nJets/I" );
24  _jetTree->Branch("jetId" , _jet_jetId , "jetId[nJets]/I" );
25  _jetTree->Branch("pt" , _jet_pt , "pt[nJets]/D" );
26  _jetTree->Branch("eta" , _jet_eta , "eta[nJets]/D" );
27  _jetTree->Branch("detectorEta", _jet_detectorEta , "detectorEta[nJets]/D");
28  _jetTree->Branch("phi" , _jet_phi , "phi[nJets]/D" );
29  _jetTree->Branch("m" , _jet_m , "m[nJets]/D" );
30  _jetTree->Branch("neuRt" , _jet_neuRt , "neuRt[nJets]/D" );
31  _jetTree->Branch("vertexZ" , &_jet_vertexZ , "vertexZ/D");
32  _jetTree->Branch("runNumber" , &_jet_runNumber , "runNumber/I" );
33 
34  _jetFourVecTree = new TTree(jetFourVecTreeName, jetFourVecTreeName);
35  _jetFourVecTree->SetAutoSave(kMaxLong64);
36  _jetFourVecTree->SetMaxTreeSize(kMaxLong64);
37 
38  _jetFourVecTree->Branch("eventId" , &_four_eventId , "eventId/I" );
39  _jetFourVecTree->Branch("nFourVecs" , &_four_nFourVecs , "nFourVecs/I" );
40  _jetFourVecTree->Branch("jetId" , _four_jetId , "jetId[nFourVecs]/I" );
41  _jetFourVecTree->Branch("pt" , _four_pt , "pt[nFourVecs]/D" );
42  _jetFourVecTree->Branch("eta" , _four_eta , "eta[nFourVecs]/D" );
43  _jetFourVecTree->Branch("phi" , _four_phi , "phi[nFourVecs]/D" );
44  _jetFourVecTree->Branch("towerId" , _four_towerId , "towerId[nFourVecs]/I" );
45  _jetFourVecTree->Branch("trackId" , _four_trackId , "trackId[nFourVecs]/S" );
46  _jetFourVecTree->Branch("mcparticleId", _four_mcparticleId , "mcparticleId[nFourVecs]/I");
47  _jetFourVecTree->Branch("m" , _four_m , "m[nFourVecs]/D" );
48  _jetFourVecTree->Branch("type" , _four_type , "type[nFourVecs]/I" );
49  _jetFourVecTree->Branch("detectorId" , _four_detectorId , "detectorId[nFourVecs]/I" );
50  _jetFourVecTree->Branch("fourvecId" , _four_fourvecId , "fourvecId[nFourVecs]/I" );
51  _jetFourVecTree->Branch("runNumber" , &_four_runNumber , "runNumber/I" );
52  _jetFourVecTree->Branch("vertexZ" , &_four_vertexZ , "vertexZ/D" );
53 }
54 
55 void StjJetListWriter::Fill(const StjJetList& jetList)
56 {
57  if(jetList.empty()) return;
58 
59  _jet_runNumber = jetList[0].runNumber;
60  _jet_eventId = jetList[0].eventId;
61  _jet_vertexZ = jetList[0].vertexZ;
62 
63  _four_nFourVecs = 0;
64 
65  _jet_nJets = jetList.size();
66  for(int i = 0; i < _jet_nJets; ++i) {
67  const StjJet& jet = jetList[i];
68  _jet_jetId[i] = jet.jetId;
69  _jet_pt[i] = jet.pt;
70  _jet_eta[i] = jet.eta;
71  _jet_phi[i] = jet.phi;
72  _jet_m[i] = jet.m;
73  _jet_neuRt[i] = jet.neuRt;
74  _jet_detectorEta[i] = jet.detectorEta;
75  fillFourVecTree(jet.jetId, jet.fourVecList);
76  }
77 
78  _jetTree->Fill();
79  _jetFourVecTree->Fill();
80 }
81 
82 void StjJetListWriter::fillFourVecTree(int jetId, const StjFourVecList& fourVecList)
83 {
84  if(fourVecList.empty()) return;
85 
86  _four_runNumber = fourVecList[0].runNumber;
87  _four_eventId = fourVecList[0].eventId;
88  _four_vertexZ = fourVecList[0].vertexZ;
89 
90  for(size_t i = 0; i < fourVecList.size(); ++i) {
91  const StjFourVec& four = fourVecList[i];
92  _four_fourvecId[_four_nFourVecs] = four.fourvecId;
93  _four_jetId[_four_nFourVecs] = jetId;
94  _four_type[_four_nFourVecs] = four.type;
95  _four_detectorId[_four_nFourVecs] = four.detectorId;
96  _four_trackId[_four_nFourVecs] = four.trackId;
97  _four_towerId[_four_nFourVecs] = four.towerId;
98  _four_mcparticleId[_four_nFourVecs] = four.mcparticleId;
99  _four_pt[_four_nFourVecs] = four.pt;
100  _four_eta[_four_nFourVecs] = four.eta;
101  _four_phi[_four_nFourVecs] = four.phi;
102  _four_m[_four_nFourVecs] = four.m;
103  _four_nFourVecs++;
104  }
105 }
106 
107 void StjJetListWriter::Finish()
108 {
109  _jetTree->BuildIndex("runNumber", "eventId");
110  _jetFourVecTree->BuildIndex("runNumber", "eventId");
111 }