Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
readJetTree.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file readJetTree.C
1 
13 #include <TFile.h>
14 #include <TH1.h>
15 #include <TH2.h>
16 #include <TCanvas.h>
17 #include <TTreeReader.h>
18 #include <TTreeReaderValue.h>
19 #include <TTreeReaderArray.h>
20 #include <vector>
21 #include <iostream>
22 #include <TDatabasePDG.h>
23 #include <TString.h>
24 #include <set>
25 #include <TChain.h>
26 #include <TGraph.h>
27 #include <string>
28 #include <vector>
29 
30 #pragma GCC diagnostic push
31 #pragma GCC diagnostic ignored "-Wundefined-internal"
32 #include <FullJetFinder.h>
33 #pragma GCC diagnostic pop
34 
35 R__LOAD_LIBRARY(libFullJetFinder.so)
36 
37 bool CheckValue(ROOT::Internal::TTreeReaderValueBase& value) {
38  if (value.GetSetupStatus() < 0) {
39  std::cerr << "Error " << value.GetSetupStatus()
40  << "setting up reader for " << value.GetBranchName() << '\n';
41  return false;
42  }
43  return true;
44 }
45 
46 void printProgress(int cur, int total){
47  if((cur % (total/100))==0){
48  float frac = float(cur)/float(total) + 0.01;
49  int barWidth = 70;
50  std::cout << "[";
51  int pos = barWidth * frac;
52  for (int i = 0; i < barWidth; ++i) {
53  if (i < pos) std::cout << "=";
54  else if (i == pos) std::cout << ">";
55  else std::cout << " ";
56  }
57  std::cout << "] " << int(frac * 100.0) << " %\r";
58  std::cout.flush();
59  if(cur >= total*0.99) std::cout<<std::endl;
60  }
61 }
62 
63 // Analyze TTree "AntiKt_r04/Data" in the file passed into the function.
64 // Returns false in case of errors.
65 //takes list of datafiles as entry
66 bool readJetTree(const std::string &dataFiles = "/sphenix/tg/tg01/hf/jkvapil/JET30_r11_30GeV/condorJob/myTestJets/outputData_000*.root"){
67  TChain *tc = new TChain("AntiKt_r04/Data"); //TTRee name
68  tc->Add(dataFiles.data());
69  int n_events = tc->GetEntries(); //gen total number of events
70  tc->LoadTree(-1); //previous commands detached the Tree head, reset back to supress warning
71  TTreeReader reader(tc);
72  TTreeReaderValue<FullJetFinder::Container> jet_container(reader,"JetContainer");
73 
74  TH1I *h_jet_n = new TH1I("h_jet_n","h_jet_n",2,-0.5,1.5);
75  TH1F *h_reco_jet_pt = new TH1F("h_reco_jet_pt","h_reco_jet_pt",100,0,100);
76  TH1F *h_reco_track_pt = new TH1F("h_reco_track_pt","h_reco_track_pt",100,0,100);
77 
78  std::cout<<"Total number of events: "<<n_events<<std::endl;
79 
80  //main event loop
81  while (reader.Next()){
82  if (!CheckValue(jet_container)) return false; //NULL guards
83  printProgress(reader.GetCurrentEntry(),n_events);
84 
85  h_jet_n->Fill(0.0,jet_container->reco_jet_n);
86  h_jet_n->Fill(1.0,jet_container->truth_jet_n);
87 
88  //reco jet loop
89  for (auto reco_jet : jet_container->recojets){
90  h_reco_jet_pt->Fill(reco_jet.pt);
91  //track inside jet loop
92  for (auto chConstituent : reco_jet.chConstituents){
93  h_reco_track_pt->Fill(chConstituent.pt);
94  } // for (auto chConstituent : reco_jet.chConstituents)
95  }//f or (auto reco_jet : jet_container->recojets)
96  } //while (reader.Next())
97 
98  //plotting
99  TCanvas *c = new TCanvas("c","c",2400,800);
100  c->Divide(3,1);
101  c->cd(1);
102  h_jet_n->Draw();
103  c->cd(2);
104  h_reco_jet_pt->Draw();
105  c->cd(3);
106  h_reco_track_pt->Draw();
107  return true;
108 }