StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ReadStJets.C
1 //
2 // Pibero Djawotho <pibero@tamu.edu>
3 // Texas A&M University
4 // 20 July 2010
5 //
6 // Simple macro to read jet trees in old format (StJets) and skim trees
7 //
8 
9 void ReadStJets(int nevents = 10, const char* jetfile = "Jets_pt15_25_01.root", const char* skimfile = "Skim_pt15_25_01.root")
10 {
11  // Load shared libraries
12  gSystem->Load("StJets");
13  gSystem->Load("StJetSkimEvent");
14 
15  // Create chains
16  TChain* jetchain = new TChain("jet");
17  TChain* skimchain = new TChain("jetSkimTree");
18 
19  // Add file lists
20  jetchain->Add(jetfile);
21  skimchain->Add(skimfile);
22 
23  // Setup skim event buffer
24  StJetSkimEvent* skimevent = 0;
25  skimchain->SetBranchAddress("skimEventBranch",&skimevent);
26 
27  // Event loop
28  for (int iEvent = 0; iEvent < nevents; ++iEvent) {
29  // Exit loop on end-of-file or error
30  if (jetchain->GetEvent(iEvent) <= 0 || skimchain->GetEvent(iEvent) <= 0) break;
31 
32  // Loop over jet branches
33  for (int iBranch = 0; iBranch < jetchain->GetNbranches(); ++iBranch) {
34  TBranch* branch = (TBranch*)jetchain->GetListOfBranches()->At(iBranch);
35  cout << "Branch #" << iBranch << ": " << branch->GetName() << endl;
36 
37  // Get jets
38  StJets* stjets = *(StJets**)branch->GetAddress();
39 
40  // Jet branch and skim branch must be synchronized
41  assert(stjets->runId() == skimevent->runId() && stjets->eventId() == skimevent->eventId());
42 
43  // Print
44  cout << "iEvent = " << iEvent << endl;
45  cout << "runId = " << stjets->runId() << endl;
46  cout << "eventId = " << stjets->eventId() << endl;
47 
48  TVector3 vertex(skimevent->bestVert()->position());
49  cout << "vx = " << vertex.x() << ", vy = " << vertex.y() << ", vz = " << vertex.z() << endl;
50 
51  // Loop over jets
52  cout << "nJets = " << stjets->nJets() << endl;
53  for (int iJet = 0; iJet < stjets->nJets(); ++iJet) {
54  StJet* jet = (StJet*)stjets->jets()->At(iJet);
55  cout << "Jet #" << iJet << ": jetPt = " << jet->jetPt << ", jetEta = " << jet->jetEta << ", jetPhi = " << jet->jetPhi
56  << ", nTracks = " << jet->nTracks << ", nBtowers = " << jet->nBtowers << ", nEtowers = " << jet->nEtowers
57  << endl;
58 
59  // Loop over tracks
60  TObjArray tracks = stjets->tracks(iJet);
61  if (strcmp(branch->GetName(),"PythiaConeJets") == 0) {
62  for (int iTrack = 0; iTrack < tracks.GetEntriesFast(); ++iTrack) {
63  TrackToJetIndex* track = (TrackToJetIndex*)tracks.At(iTrack);
64  cout << "Particle #" << iTrack << ": id = " << track->id() << ", pdg = " << track->pdg()
65  << ", status = " << track->status()
66  << ", pt = " << track->Pt() << ", eta = " << track->Eta() << ", phi = " << track->Phi()
67  << ", e = " << track->E() << ", m = " << track->M()
68  << endl;
69  } // End loop over tracks
70  }
71  else {
72  for (int iTrack = 0; iTrack < tracks.GetEntriesFast(); ++iTrack) {
73  TrackToJetIndex* track = (TrackToJetIndex*)tracks.At(iTrack);
74  cout << "Track #" << iTrack << ": id = " << track->trackId() << ", detId = " << track->detectorId()
75  << ", pt = " << track->Pt() << ", eta = " << track->Eta() << ", phi = " << track->Phi()
76  << endl;
77  } // End loop over tracks
78  }
79 
80  // Loop over towers
81  TObjArray towers = stjets->towers(iJet);
82  for (int iTower = 0; iTower < towers.GetEntriesFast(); ++iTower) {
83  TowerToJetIndex* tower = (TowerToJetIndex*)towers.At(iTower);
84  cout << "Tower #" << iTower << ": id = " << tower->towerId() << ", detId = " << tower->detectorId()
85  << ", pt = " << tower->Pt() << ", eta = " << tower->Eta() << ", phi = " << tower->Phi()
86  << endl;
87  } // End loop over towers
88  } // End loop over jets
89  } // End loop over branches
90 
91  cout << endl;
92  } // End event loop
93 }
int nTracks
The number of tracks in this jet.
Definition: StJet.h:104
TClonesArray * jets()
Access to the jets in this event.
Definition: StJets.h:42
Definition: StJets.h:24
float jetPt
Pt (stored for convenience when drawing TTree)
Definition: StJet.h:125
int nJets() const
The number of jets found in this event.
Definition: StJets.h:39
int nBtowers
The number of Barrel towers in this jet.
Definition: StJet.h:107
int eventId() const
access to event numbers, used to synchronize with StMuDstMaker for simultaneous reading ...
Definition: StJets.h:59
float jetEta
Eta (stored for convenience when drawing TTree)
Definition: StJet.h:128
TClonesArray * tracks()
The track/tower to jet indices TClonesArray: this contains all the 4momenta contained in jets for jet...
Definition: StJets.h:47
float jetPhi
Phi (stored for convenience when drawing TTree)
Definition: StJet.h:131
int nEtowers
The number of Endcap towers in this jet.
Definition: StJet.h:110
Definition: StJet.h:91