Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ana.C
Go to the documentation of this file.
1 #include <TFile.h>
2 #include <TTree.h>
3 #include <TH2D.h>
4 #include <TSystem.h>
5 
6 void ana(
7  const char* in = "DSTReader.root",
8  const char* out = "hist.root"
9  ){
10 
11  gSystem->Load("libg4testbench");
12 
13  TFile *outf = TFile::Open(out, "recreate");
14 
15  TFile *inf = TFile::Open(in, "read");
16  TTree *T = (TTree*) inf->Get("T");
17 
18  //T->SetAlias("avg_x", "0.5*(G4HIT_Coil.x[][0]+G4HIT_Coil.x[][1])");
19  //T->SetAlias("avg_y", "0.5*(G4HIT_Coil.y[][0]+G4HIT_Coil.y[][1])");
20  //T->SetAlias("avg_z", "0.5*(G4HIT_Coil.z[][0]+G4HIT_Coil.z[][1])");
21  //T->SetAlias("edep", "G4HIT_Coil.edep");
22 
23  T->SetAlias("avg_x", "G4HIT_Coil.get_avg_x()");
24  T->SetAlias("avg_y", "G4HIT_Coil.get_avg_y()");
25  T->SetAlias("avg_z", "G4HIT_Coil.get_avg_z()");
26  T->SetAlias("avg_r", "sqrt(avg_x*avg_x+avg_z*avg_z)");
27  T->SetAlias("avg_phi", "TMath::ATan2(-avg_x,avg_z)/TMath::Pi()*180");
28  T->SetAlias("edep", "G4HIT_Coil.get_edep()");
29 
30  TH2D *h2d_ezy = new TH2D("h2d_ezy","edep [GeV]; avg_z [cm]; avg_y [cm]", 50, -25, 25, 50, -25, 25);
31  T->Project("h2d_ezy", "avg_y:avg_z", "edep");
32  outf->cd();
33  h2d_ezy->Write();
34 
35  TH2D *h2d_ezy_0 = new TH2D("h2d_ezy_0","edep [GeV], |x|<0.5cm; Z [cm]; Y [cm]", 50, -25, 25, 50, -25, 25);
36  T->Project("h2d_ezy_0", "avg_y:avg_z", "edep*(abs(avg_x)<0.5)");
37  outf->cd();
38  h2d_ezy->Write();
39 
40  double ybin[51];
41  for(int i=0;i<51;++i) ybin[i] = i - 25.;
42 
43  //for(int i=27;i<28;++i) {
44  for(int i=0;i<50;++i) {
45  const char* hname = Form("h2d_ezx_%02d",i);
46  TH2D *h2d_ezx = new TH2D(hname,
47  Form("edep [GeV], %02.0f<avg_y<%02.0f cm; avg_z [cm]; avg_x [cm]", ybin[i], ybin[i+1]),
48  50, -25, 25, 50, -25, 25);
49  T->Project(hname, "avg_x:avg_z" , Form("edep*(avg_y>%f&&avg_y<%f)",ybin[i],ybin[i+1]));
50  outf->cd();
51  h2d_ezx->Write();
52  }
53 
54  TH2D *h2d_ephiy = new TH2D("h2d_ephiy","edep [GeV]; #phi [deg.]; avg_y [cm]", 38, -180, 180, 50, -25, 25);
55  T->Project("h2d_ephiy", "avg_y:avg_phi", "edep*(avg_r<7)");
56  outf->cd();
57  h2d_ephiy->Write();
58 
59  outf->Close();
60 }
void ana()
Definition: ana.C:291