StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ReadJetTree2009.C
1 //
2 // Pibero Djawotho <pibero@tamu.edu>
3 // Texas A&M
4 // 16 July 2012
5 //
6 // Sample jet tree reader
7 //
8 
9 void ReadJetTree2009(int nentries = 1e6,
10  const char* jetfile = "jets.root",
11  const char* skimfile = "skim.root",
12  const char* outfile = "out.root")
13 {
14  cout << "nentries = " << nentries << endl;
15  cout << "jetfile = " << jetfile << endl;
16  cout << "skimfile = " << skimfile << endl;
17  cout << "outfile = " << outfile << endl;
18 
19  // Load libraries
20  gSystem->Load("StJetEvent");
21  gSystem->Load("StJetSkimEvent");
22 
23  // Open jet & skim files
24  TChain* jetChain = new TChain("jet");
25  TChain* skimChain = new TChain("jetSkimTree");
26 
27  jetChain->Add(jetfile);
28  skimChain->Add(skimfile);
29 
30  // Set jet buffer
31  StJetEvent* jets = 0;
32  jetChain->SetBranchAddress("ConeJets12",&jets);
33 
34  // Set skim buffer
35  StJetSkimEvent* skim = 0;
36  skimChain->SetBranchAddress("skimEventBranch",&skim);
37 
38  // Open output file and book histograms
39  TFile* ofile = TFile::Open(outfile,"recreate");
40  assert(ofile);
41 
42  TH1F* hTriggers = new TH1F("hTriggers",";trigger ID",5,0,5);
43  TH1F* hVertexZ = new TH1F("hVertexZ",";z-vertex [cm]",100,-200,200);
44 
45  TH1F* hJetPt = new TH1F("hJetPt",";jet pt [GeV]",100,0,100);
46  TH1F* hJetEta = new TH1F("hJetEta",";jet #eta",100,-1.5,1.5);
47  TH1F* hJetPhi = new TH1F("hJetPhi",";jet #phi [radians]",100,-TMath::Pi(),TMath::Pi());
48  TH1F* hJetRt = new TH1F("hJetRt",";R_{T}",101,0,1.01);
49  TH1F* hNtracks = new TH1F("hNtracks",";track multiplicity",50,0,50);
50  TH1F* hNtowers = new TH1F("hNtowers",";tower multiplicity",50,0,50);
51 
52  TH1F* hTrackPt = new TH1F("hTrackPt",";track pt [GeV]",100,0,100);
53  TH1F* hTrackEta = new TH1F("hTrackEta",";track #eta",100,-1.5,1.5);
54  TH1F* hTrackPhi = new TH1F("hTrackPhi",";track #phi [radians]",100,-TMath::Pi(),TMath::Pi());
55 
56  TH1F* hTowerPt = new TH1F("hTowerPt",";tower pt [GeV]",100,0,100);
57  TH1F* hTowerEta = new TH1F("hTowerEta",";tower #eta",100,-1.5,1.5);
58  TH1F* hTowerPhi = new TH1F("hTowerPhi",";tower #phi [radians]",100,-TMath::Pi(),TMath::Pi());
59 
60  // Event loop
61  for (int iEntry = 0; iEntry < nentries; ++iEntry) {
62  if (jetChain->GetEvent(iEntry) <= 0 || skimChain->GetEvent(iEntry) <= 0) break;
63 
64  // Should not be null
65  assert(jets && skim);
66 
67  // Enforce event synchronization
68  assert(jets->runId() == skim->runId() && jets->eventId() == skim->eventId());
69 
70  // Progress indicator
71  if (iEntry % 1000 == 0) cout << iEntry << endl;
72 
73  // Trigger loop
74  for (int i = 0; i < skim->triggers()->GetEntriesFast(); ++i) {
75  StJetSkimTrig* trig = (StJetSkimTrig*)skim->triggers()->At(i);
76  // Data only
77  if (trig && trig->didFire()) {
78  hTriggers->Fill(Form("%d",trig->trigId()),1);
79  }
80  } // End trigger loop
81 
82  // Vertex
83  hVertexZ->Fill(jets->vertex()->position().z());
84 
85  // Jet loop
86  for (int iJet = 0; iJet < jets->vertex()->numberOfJets(); ++iJet) {
87  StJetCandidate* jet = jets->vertex()->jet(iJet);
88  hJetPt->Fill(jet->pt());
89  hJetEta->Fill(jet->eta());
90  hJetPhi->Fill(jet->phi());
91  hJetRt->Fill(jet->neutralFraction());
92  hNtracks->Fill(jet->numberOfTracks());
93  hNtowers->Fill(jet->numberOfTowers());
94  // Track loop
95  for (int iTrack = 0; iTrack < jet->numberOfTracks(); ++iTrack) {
96  StJetTrack* track = jet->track(iTrack);
97  hTrackPt->Fill(track->pt());
98  hTrackEta->Fill(track->eta());
99  hTrackPhi->Fill(track->phi());
100  } // End track loop
101  // Tower loop
102  for (int iTower = 0; iTower < jet->numberOfTowers(); ++iTower) {
103  StJetTower* tower = jet->tower(iTower);
104  hTowerPt->Fill(tower->pt());
105  hTowerEta->Fill(tower->eta());
106  hTowerPhi->Fill(tower->phi());
107  } // End tower loop
108  } // End jet loop
109  } // End event loop
110 
111  // Remove bins with no label
112  hTriggers->LabelsDeflate();
113 
114  // Write and close output file
115  ofile->Write();
116  ofile->Close();
117 }