Functions
gar.cxx File Reference
#include "garana/Accessors/TreeManager.h"
#include "garana/Utility/Backtracker.h"
#include <TH2F.h>
#include <TCanvas.h>
#include <TEfficiency.h>
#include <TGraphAsymmErrors.h>
#include <iostream>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

g4Tree

Definition at line 19 of file gar.cxx.

19  {
20 
21 
22  std::cout << "welcome to garana!" << std::endl;
23  if(argc==1) {
24  std::cout << "you must specify a root file to analyze" << std::endl;
25  return 1;
26  }
27 
28  if(argc>2) {
29  std::cout << "too many arguments! ignoring all file names except"
30  << argv[1] << std::endl;
31  }
32 
33  TreeManager* tm = new TreeManager(argv[1]);
34 
35  ///////// histograms /////////////////
36  // headerTree
37  HeaderTree* header = tm->GetHeaderTree();
38  std::cout << "input tree type: " << *header->TreeType() << std::endl;
39 
40  // genTree
41  std::string htitle = "my garana histogram ("+*header->TreeType()+");E_{#nu} [GeV];";
42  TH1F* hnue = new TH1F("hnue",htitle.c_str(),10,0,10);
43 
44  /// g4Tree
45  std::string htitleg4 = "my garana histogram ("+*header->TreeType()+");E_{tot} [GeV];";
46  TH1F* hg4 = new TH1F("hg4",htitle.c_str(),10,0,3);
47  TH1F* hg4_efrac = new TH1F("hg4_efrac","Fraction of Incident #nu Energy; E_{G4particle}/E_{#nu};",50,0,1);
48  TH1F* hg4_eprot = new TH1F("hg4_eprot","primary protons;KE [MeV];",20,0,10);
49  TH1F* hg4_nprot = new TH1F("hg4_nprot",";proton multiplicity;",20,0,20); //Ar has 18 protons
50 
51  // recoTree
52  TH2F* h_recotrk_vtx_xy = new TH2F("h_recotrk_vtx_xy",";reco vertex x [cm]; reco vertex y [cm]", 20, -250, 250, 20, -400, 100);
53  TH2F* h_recotrk_vtx_zy = new TH2F("h_recotrk_vtx_zy",";reco vertex z [cm]; reco vertex y [cm]", 20, 1200, 1800, 20, -400, 100);
54  TH2F* h_recotrk_vtx_xz = new TH2F("h_recotrk_vtx_xz",";reco vertex x [cm]; reco vertex z [cm]", 20, -250, 250, 20, 1200, 1800);
55 
56  TH2F* h_recovtx_vtx_xy = new TH2F("h_recovtx_vtx_xy",";reco vertex x [cm]; reco vertex y [cm]", 20, -250, 250, 20, -400, 100);
57  TH2F* h_recovtx_vtx_zy = new TH2F("h_recovtx_vtx_zy",";reco vertex z [cm]; reco vertex y [cm]", 20, 1200, 1800, 20, -400, 100);
58  TH2F* h_recovtx_vtx_xz = new TH2F("h_recovtx_vtx_xz",";reco vertex x [cm]; reco vertex z [cm]", 20, -250, 250, 20, 1200, 1800);
59 
60  TEfficiency* eff_reco_prot_integ = new TEfficiency("eff_reco_prot_integ","",1,0,1); //integrated proton reco eff
61  TEfficiency* eff_reco_prot_tprot = new TEfficiency("eff_reco_prot_tprot","proton reconstruction efficiency; proton KE [MeV]; "
62  "#epsilon_{reco}",40,0,2); //proton reco eff vs. proton KE [MeV]
63 
64  //////// tree accessors //////////
65  GenTree* gen = tm->GetGenTree();
66  G4Tree* g4 = tm->GetG4Tree();
67  RecoTree* reco = tm->GetRecoTree();
68 
69  // truth matching utility
70  Backtracker bt(tm);
71 
72  /////// main event loop ////////// (e.g. over single genie interactions)
73  for(size_t ientry=0; ientry<tm->NEntries(); ientry++){
74 
75  tm->GetEntry(ientry); //gets entry for all trees
76  bt.FillMaps(); //load associations for this entry
77 
78  cout << "gen stuff" << endl;
79  // genTree
80  for(size_t i=0; i<gen->NGen(); i++){
81  if(!gen->IsGenie(i)) continue;
82  hnue->Fill(gen->NuP(i)->E());
83 
84  /*for(size_t ifsp=0; ifsp<gen->NFSParticles(i); ifsp++){
85  std::cout << "FSParticle " << ifsp << " with trackID " << gen->FSTrackId(i,ifsp) << std::endl;
86  }*/
87  }
88 
89  cout << "g4 stuff" << endl;
90  // g4Tree
91  size_t nprot = 0;
92  for(size_t i=0; i<g4->NSim(); i++){
93 
94  hg4->Fill(g4->SimMomEnter(i)->at(0)->E());
95  hg4_efrac->Fill(g4->SimMomEnter(i)->at(0)->E()/gen->NuP(bt.G4ParticleToGTruth(i))->E());
96 
97  if(g4->PDG(i) == 2212 && g4->IsPrimary(i)) { //is it a primary proton?
98  nprot++;
99  hg4_eprot->Fill(1.e3*(g4->SimMomEnter(i)->at(0)->E()-0.938272)); //KE in [MeV]
100 
101  const vector<UInt_t>* matchedtracks = bt.G4ParticleToTracks(i);
102  eff_reco_prot_integ->Fill(matchedtracks->size()>0, 0.5);
103  eff_reco_prot_tprot->Fill(matchedtracks->size()>0, 1e3*(g4->SimMomEnter(i)->at(0)->E()-0.938272));
104 
105  }
106  }
107 
108  hg4_nprot->Fill(nprot);
109 
110  cout << "reco stuff" << endl;
111  // recoTree
112  // tracks
113  for(size_t itrk=0; itrk<reco->NTrack(); itrk++) {
114  auto trkvtx = reco->TrackVertex(itrk);
115  h_recotrk_vtx_xy->Fill(trkvtx->X(), trkvtx->Y());
116  h_recotrk_vtx_zy->Fill(trkvtx->Z(), trkvtx->Y());
117  h_recotrk_vtx_xz->Fill(trkvtx->X(), trkvtx->Z());
118 
119  }// end for tracks
120 
121  // vertices
122  for(size_t ivtx=0; ivtx<reco->NVertex(); ivtx++) {
123  auto vtx = reco->GetVertex(ivtx);
124  h_recovtx_vtx_xy->Fill(vtx->X(), vtx->Y());
125  h_recovtx_vtx_zy->Fill(vtx->Z(), vtx->Y());
126  h_recovtx_vtx_xz->Fill(vtx->X(), vtx->Z());
127 
128  }// end for vertices
129 
130  }//end main event loop
131 
132  //hg4_nprot->SetBinContent(hg4_nprot->GetXaxis()->GetNbins(),hg4_nprot->GetBinContent(hg4_nprot->GetXaxis()->GetNbins()+1));
133  cout << "proton reconstruction efficiency: " << eff_reco_prot_integ->GetEfficiency(1) << endl;
134 
135  auto c = new TCanvas();
136  hnue->Draw();
137  std::string outname = "testhist_"+*header->TreeType()+".png";
138  c->SaveAs(outname.c_str());
139 
140  auto cg4 = new TCanvas();
141  hg4->Draw();
142  outname = "testg4hist_"+*header->TreeType()+".png";
143  cg4->SaveAs(outname.c_str());
144 
145  outname = "g4_efrac_of_nu_"+*header->TreeType()+".png";
146  auto cg4_efrac = new TCanvas();
147  hg4_efrac->Draw();
148  cg4_efrac->SaveAs(outname.c_str());
149 
150  outname = "g4_nproton_"+*header->TreeType()+".png";
151  auto cg4_nprot = new TCanvas();
152  hg4_nprot->Draw();
153  cg4_nprot->SaveAs(outname.c_str());
154 
155  outname = "g4_eproton_"+*header->TreeType()+".png";
156  auto cg4_eprot = new TCanvas();
157  hg4_eprot->Draw("e0hist");
158  cg4_eprot->SaveAs(outname.c_str());
159 
160  TCanvas* c_recotrk_vtx_xy = new TCanvas("c_recotrk_vtx_xy","reco track vertex: X-Y");
161  h_recotrk_vtx_xy->Draw("colz");
162  h_recovtx_vtx_xy->Draw("same");
163  c_recotrk_vtx_xy->SaveAs("reco_trk_vtx_xy.png");
164 
165  TCanvas* c_recotrk_vtx_zy = new TCanvas("c_recotrk_vtx_zy","reco track vertex: Z-Y");
166  h_recotrk_vtx_zy->Draw("colz");
167  h_recovtx_vtx_zy->Draw("same*");
168  c_recotrk_vtx_zy->SaveAs("reco_trk_vtx_zy.png");
169 
170  TCanvas* c_recotrk_vtx_xz = new TCanvas("c_recotrk_vtx_xz","reco track vertex: X-Y");
171  h_recotrk_vtx_xz->Draw("colz");
172  h_recovtx_vtx_xz->Draw("same*");
173  c_recotrk_vtx_xz->SaveAs("reco_trk_vtx_xz.png");
174 
175  TCanvas* c_recovtx_vtx_xy = new TCanvas("c_recovtx_vtx_xy","reco vertex: X-Y");
176  h_recovtx_vtx_xy->Draw("colz");
177  c_recovtx_vtx_xy->SaveAs("reco_vtx_vtx_xy.png");
178 
179  TCanvas* c_recovtx_vtx_zy = new TCanvas("c_recovtx_vtx_zy","reco vertex: Z-Y");
180  h_recovtx_vtx_zy->Draw("colz");
181  c_recovtx_vtx_zy->SaveAs("reco_vtx_vtx_zy.png");
182 
183  TCanvas* c_recovtx_vtx_xz = new TCanvas("c_recovtx_vtx_xz","reco vertex: X-Y");
184  h_recovtx_vtx_xz->Draw("colz");
185  c_recovtx_vtx_xz->SaveAs("reco_vtx_vtx_xz.png");
186 
187  TCanvas* c_reco_peff_tp = new TCanvas();
188  eff_reco_prot_tprot->Draw();
189  c_reco_peff_tp->Update();
190  auto g = eff_reco_prot_tprot->GetPaintedGraph();
191  g->GetYaxis()->SetRangeUser(0,1);
192  g->SetMarkerStyle(8);
193  g->SetMarkerColor(kBlue);
194  g->SetLineWidth(2);
195  g->Draw("pl");
196 
197  c_reco_peff_tp->SaveAs("reco_proton_eff_tproton.png");
198 
199  // clean up bare pointers
200  delete tm;
201  delete gen;
202  delete g4;
203  delete reco;
204 
205  delete hnue;
206  delete hg4;
207  delete c;
208  delete cg4;
209 
210  delete h_recotrk_vtx_xy;
211  delete h_recotrk_vtx_zy;
212  delete h_recotrk_vtx_xz;
213  delete h_recovtx_vtx_xy;
214  delete h_recovtx_vtx_zy;
215  delete h_recovtx_vtx_xz;
216  delete c_recotrk_vtx_xy;
217  delete c_recotrk_vtx_zy;
218  delete c_recotrk_vtx_xz;
219  delete c_recovtx_vtx_xy;
220  delete c_recovtx_vtx_zy;
221  delete c_recovtx_vtx_xz;
222 
223  return 0;
224 }
virtual const UInt_t NSim() const =0
number of particles
static constexpr double g
Definition: Units.h:144
virtual const Int_t PDG(const UInt_t &iparticle) const =0
particle PDG code
std::string string
Definition: nybbler.cc:12
virtual const UInt_t NGen() const =0
virtual const TLorentzVector * GetVertex(const size_t &ivertex) const =0
vertex 4-position for vertex with index ivertex
virtual const vector< const TLorentzVector * > * SimMomEnter(const UInt_t &iparticle) const =0
particle 4-momentum at entry point, all regions
virtual const size_t NVertex() const =0
number of vertices in this event
tm
Definition: demo.py:21
const std::string *const TreeType() const
Definition: HeaderTree.cxx:32
bt
Definition: tracks.py:83
virtual const TLorentzVector * NuP(const UInt_t &igen)=0
initial neutrino 4-momentum
gen
Definition: demo.py:24
virtual const size_t NTrack() const =0
number of tracks in this event
virtual const bool IsPrimary(const UInt_t &iparticle) const =0
did particle come from generator?
virtual const TLorentzVector * TrackVertex(const size_t &itrack) const =0
4-position of track&#39;s assumed start point
HeaderTree * GetHeaderTree() const
G4Tree * GetG4Tree() const
E
Definition: 018_def.c:13
RecoTree * GetRecoTree() const
trkvtx
Definition: tracks.py:173
UInt_t const & NEntries() const
Definition: TreeManager.h:53
GenTree * GetGenTree() const
void GetEntry(const UInt_t &ientry)
QTextStream & endl(QTextStream &s)
virtual const Bool_t IsGenie(const UInt_t &igen) const =0
g4
Definition: tracks.py:87