Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Example.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Example.C
1 // $Id: $
2 
11 #include <TFile.h>
12 #include <TPad.h>
13 #include <TString.h>
14 #include <TSystem.h>
15 #include <TTree.h>
16 #include <cassert>
17 #include <cmath>
18 
19 // it is good to load the libg4dst lib and the header files,
20 // which allow us to use the compiled function in the output class
21 #include <calobase/RawTower.h>
22 #include <calobase/RawTowerv1.h>
23 #include <g4main/PHG4HitEval.h>
24 #include <g4main/PHG4Particlev1.h>
25 #include <g4main/PHG4Particlev2.h>
26 #include <g4main/PHG4VtxPointv1.h>
27 using namespace std;
28 
29 // allow you to access them in command line after running this macro
30 TFile *_file0 = NULL;
31 TTree *T = NULL;
32 
34 void CheckItOut()
35 {
36  // This print out the content of the first event to screen.
37  // It contain a bunch of nodes here:
38  // G4Hit_*.* - PHG4Hit for various subsystems, https://www.phenix.bnl.gov/WWW/sPHENIX/doxygen/html/d3/d9e/classPHG4Hit.html
39  // TOWER_*.* - RawTower for calorimeters, https://www.phenix.bnl.gov/WWW/sPHENIX/doxygen/html/d9/dd8/classRawTower.html
40  // PHG4Particle.* - Geant4 particles, https://www.phenix.bnl.gov/WWW/sPHENIX/doxygen/html/de/dc9/classPHG4Particle.html
41  // PHG4VtxPoint.* - Vertex point Geant4 particles were produced, https://www.phenix.bnl.gov/WWW/sPHENIX/doxygen/html/d6/d81/classPHG4VtxPoint.html
42  T->Show(0);
43 
44  // Anything you see from the last print can be directly plotted using T->Draw();
45  new TCanvas("CheckItOut", "CheckItOut");
46  T->Draw(
47  "Sum$(G4HIT_HCALOUT.edep) + Sum$(G4HIT_ABSORBER_HCALOUT.edep)>>hSum_CEMC(30,0,30)");
48  TH1 *hSum_CEMC = static_cast<TH1 *>(gDirectory->GetObjectChecked("hSum_CEMC", "TH1"));
49  hSum_CEMC->SetTitle(
50  "Total energy deposition in Outer HCal;Energy deposition (GeV)");
51 }
52 
55 {
56  // I am interested in first particle in the array, which is the generated pion.
57  // Here our life would be easier with some new definition of variables
58  T->SetAlias("PHG4Particle_p",
59  "1*sqrt(PHG4Particle[].fpx**2+PHG4Particle[].fpy**2+PHG4Particle[].fpz**2)");
60  T->SetAlias("PHG4Particle_eta",
61  "0.5*log((PHG4Particle_p+PHG4Particle[].fpz)/(PHG4Particle_p-PHG4Particle[].fpz))");
62  T->SetAlias("PHG4Particle_pT",
63  "1*sqrt(PHG4Particle[].fpx**2+PHG4Particle[].fpy**2)");
64 
65  new TCanvas("AcessGeant4Particles", "AcessGeant4Particles");
66  T->Draw("PHG4Particle_pT>>hPHG4Particle_pT(30,0,50)",
67  "PHG4Particle[].trkid>0" // select only the primary particle to draw (positive track ID)
68  );
69  TH1 *hPHG4Particle_pT = static_cast<TH1 *>(gDirectory->GetObjectChecked("hPHG4Particle_pT", "TH1"));
70  hPHG4Particle_pT->SetTitle("pT for the first Geant4 particle;pT (GeV/c)");
71 }
72 
77 {
78  new TCanvas("WhereIsTheHits", "WhereIsTheHits");
79  gPad->DrawFrame(-250, -250, 250, 250,
80  "Geant4 Hit distribution;X (cm);Y (cm)");
81 
82  T->Draw("G4HIT_SVTX.get_avg_y():G4HIT_SVTX.get_avg_x()", "", "* same");
83  T->Draw(
84  "G4HIT_ABSORBER_CEMC.get_avg_y():G4HIT_ABSORBER_CEMC.get_avg_x()>>hG4HIT_ABSORBER_CEMC(500,-250,250,500,-250,250)",
85  "", "scat same");
86  T->Draw(
87  "G4HIT_ABSORBER_HCALIN.get_avg_y():G4HIT_ABSORBER_HCALIN.get_avg_x()>>hG4HIT_ABSORBER_HCALIN(500,-250,250,500,-250,250)",
88  "", "scat same");
89  T->Draw(
90  "G4HIT_ABSORBER_HCALOUT.get_avg_y():G4HIT_ABSORBER_HCALOUT.get_avg_x()>>hG4HIT_ABSORBER_HCALOUT(500,-250,250,500,-250,250)",
91  "", "scat same");
92 }
93 
95 {
96  // Here our life would be easier with some new definition of variables
97  T->SetAlias("CEMC_Sample",
98  "Sum$(G4HIT_CEMC.edep)/(Sum$(G4HIT_CEMC.edep) + Sum$(G4HIT_ABSORBER_CEMC.edep))");
99  T->SetAlias("HCALIN_Sample",
100  "Sum$(G4HIT_HCALIN.edep)/(Sum$(G4HIT_HCALIN.edep) + Sum$(G4HIT_ABSORBER_HCALIN.edep))");
101  T->SetAlias("HCALOUT_Sample",
102  "Sum$(G4HIT_HCALOUT.edep)/(Sum$(G4HIT_HCALOUT.edep) + Sum$(G4HIT_ABSORBER_HCALOUT.edep))");
103 
104  new TCanvas("PlotCalorimeterSamplingFraction", "PlotCalorimeterSamplingFraction");
105 
106  T->Draw("CEMC_Sample>>CEMC_Sample(30,0,.15)");
107  TH1 *CEMC_Sample = static_cast<TH1 *>(gDirectory->GetObjectChecked("CEMC_Sample", "TH1"));
108  CEMC_Sample->SetLineColor(kRed);
109  T->Draw("HCALIN_Sample>>HCALIN_Sample(30,0,.15)", "", "same");
110  TH1 *HCALIN_Sample = static_cast<TH1 *>(gDirectory->GetObjectChecked("HCALIN_Sample", "TH1"));
111  HCALIN_Sample->SetLineColor(kMagenta);
112  T->Draw("HCALOUT_Sample>>HCALOUT_Sample(30,0,.15)", "", "same");
113  TH1 *HCALOUT_Sample = static_cast<TH1 *>(gDirectory->GetObjectChecked("HCALOUT_Sample", "TH1"));
114  HCALOUT_Sample->SetLineColor(kBlue);
115  CEMC_Sample->SetTitle("Sampling fraction for three calorimeters; E_{Scint}/(E_{Scint} + E_{Absorber})");
116 }
117 
119 {
120  new TCanvas("AccessCalorimeterTowers", "AccessCalorimeterTowers");
121 
122  T->Draw("TOWER_CALIB_HCALOUT.get_bineta()>>hTowerBin(22,-0.5,21.5)", "TOWER_CALIB_HCALOUT.get_energy()");
123  TH1 *hTowerBin = static_cast<TH1 *>(gDirectory->GetObjectChecked("hTowerBin", "TH1"));
124  hTowerBin->SetTitle("HCal tower eta bin distribution; Eta Bin # ; Sum energy in scintillator (GeV)");
125 }
126 
127 /*
128  * \brief Example macro to use output for PHG4DSTReader
129  *
130  * (s)PHENIX DST files are designed for high speed IO for batch computing,
131  * the content is not necessarily easily readable through ROOT commandline.
132  * This maybe some headache during testing/development stage.
133  *
134  * PHG4DSTReader is designed to solve this problem, by exporting a copy of
135  * DST tree into a ROOT readable TTree file. User can directly inspect the content
136  * using ROOT commandlines or simple macros.
137  * https://www.phenix.bnl.gov/WWW/sPHENIX/doxygen/html/d4/dc9/classPHG4DSTReader.html
138  *
139  * PHG4DSTReader is by-default disabled in sPHENIX simulation, but can be enabled
140  * for small-scale test simulation runs by following switch in Fun4All_G4_sPHENIX.C
141  * bool do_DSTReader = true;
142  *
143  * This example macro work on its output, usually named *_DSTReader.root.
144  * A test file is prepared at https://www.phenix.bnl.gov/phenix/WWW/sPHENIX/tutorial/G4sPHENIX.root_DSTReader.root
145  * which is output of the default Fun4All_G4_sPHENIX.C macro with 100 events and do_DSTReader = true;
146  *
147  * */
148 void Example( //
149  const TString infile =
150  "https://www.phenix.bnl.gov/phenix/WWW/sPHENIX/tutorial/G4sPHENIX.root_DSTReader.root" // this is output of the default Fun4All_G4_sPHENIX.C macro with 100 events and do_DSTReader = true;
151  )
152 {
153  gSystem->Load("libg4dst.so");
154 
155  // open file, get the tree
156  _file0 = TFile::Open(infile);
157  assert(_file0);
158  T = (TTree *) _file0->GetObjectChecked("T", "TTree");
159  assert(T);
160 
161  // Now I have bunch of example to show how to use this file.
162  // They are self-explanatory
163  // and all the lines can be copy-paste in ROOT command lines too
164  CheckItOut();
166  WhereIsTheHits();
169 }