EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AnalyzeTree.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file AnalyzeTree.cxx
1 // This macro reads the starlight.root file produced by convertStarlightAsciiToTree.C,
2 // which contains TLorentzVectors for the parents and a TClonesArray of TLorentzVectors
3 // for the daughters.
4 //
5 // It creates histograms of the p_T and rapidity of the daughters, as well as the p_T,
6 // rapidity and mass of the parent. While the parents may have been created as the
7 // vector sum of any number of daughter particles, this macro currently produces
8 // histograms for only the first two daughter particles. The daughter histograms are
9 // called D1Pt, D2Pt, D1Rapidity, and D1Rapidity. Parent histograms are
10 // named ParentPt, ParentRapidity, and ParentMass. The histograms are stored in
11 // starlight_histos.root.
12 //
13 // To use this macro, you must first run convertStarlightAsciiToTree.C to produce the
14 // starlight.root file. If needed, modify the file AnalyzeTree.h to call your input file
15 // (as downloaded, it calls starlight.root). Then open root and type .x anaTree.C .
16 
17 #define AnalyzeTree_cxx
18 #include "AnalyzeTree.h"
19 #include <TH2.h>
20 #include <TStyle.h>
21 #include <TCanvas.h>
22 #include <TLorentzVector.h>
23 #include <iostream>
24 
26 {
27 // In a ROOT session, you can do:
28 // Root > .L MyClass.C
29 // Root > MyClass t
30 // Root > t.GetEntry(12); // Fill t data members with entry number 12
31 // Root > t.Show(); // Show values of entry 12
32 // Root > t.Show(16); // Read and show values of entry 16
33 // Root > t.Loop(); // Loop on all entries
34 //
35 
36 // This is the loop skeleton where:
37 // jentry is the global entry number in the chain
38 // ientry is the entry number in the current Tree
39 // Note that the argument to GetEntry must be:
40 // jentry for TChain::GetEntry
41 // ientry for TTree::GetEntry and TBranch::GetEntry
42 //
43 // To read only selected branches, Insert statements like:
44 // METHOD1:
45 // fChain->SetBranchStatus("*",0); // disable all branches
46 // fChain->SetBranchStatus("branchname",1); // activate branchname
47 // METHOD2: replace line
48 // fChain->GetEntry(jentry); //read all branches
49 //by b_branchname->GetEntry(ientry); //read only this branch
50  if (fChain == 0) return;
51 
52 // define histos
53  TH1D* D1Prapidity = new TH1D("D1Prapidity","Prapidity of Daughter 1",200, -10, 10);
54  TH1D* D1Pt = new TH1D("D1Pt","Transverse Momentum of Daughter 1",100, 0, 2.);
55  TH1D* D2Prapidity = new TH1D("D2Prapidity","Prapidity of Daughter 2",200, -10, 10);
56  TH1D* D2Pt = new TH1D("D2Pt","Transverse Momentum of Daughter 2",100, 0, 2.);
57  TH1D* ParentRapidity = new TH1D("ParentRapidity","Rapidity of Parent",200, -10, 10);
58  TH1D* ParentPt = new TH1D("ParentPt","Transverse Momentum of Parent",100, 0, 2.);
59  TH1D* ParentMass = new TH1D("ParentMass","Invariant Mass of Parent",100, 0, 5.);
60 
61 // Fill histograms
62  Long64_t nentries = fChain->GetEntriesFast();
63 
64  Long64_t nbytes = 0, nb = 0;
65  for (Long64_t jentry=0; jentry<nentries;jentry++) {
66  Long64_t ientry = LoadTree(jentry);
67  if (ientry < 0) break;
68  nb = fChain->GetEntry(jentry); nbytes += nb;
69  // if desired, acceptance or analysis cuts can be applied here, before filling histograms
70  // if (Cut(ientry) < 0) continue;
71  D1Prapidity->Fill( p1prap_ );
72  D2Prapidity->Fill( p2prap_ );
73  D1Pt->Fill( p1pt_ );
74  D2Pt->Fill( p2pt_ );
75  ParentRapidity->Fill( fsrap_ );
76  ParentPt->Fill( fspt_ );
77  ParentMass->Fill( fsmass_ );
78  }// jentry
79 
80 
81 // write out the histos
82  TFile *histofile = new TFile("starlight_histos.root","recreate");
83 // f->cd;
84 
85  D1Prapidity->Write();
86  D2Prapidity->Write();
87  D1Pt->Write();
88  D2Pt->Write();
89  ParentRapidity->Write();
90  ParentPt->Write();
91  ParentMass->Write();
92 
93  histofile->Save();
94  histofile->Close();
95 
96 }