FairRoot/PandaRoot
ReadHCal.C
Go to the documentation of this file.
1 /*
2  * ReadHCal.C
3  *
4  * Created on: Mar 21, 2010
5  * Author: Simone Bianco
6  */
7 
8 int ReadHCal(){
9 
10  // Customize
11 
12  const Int_t numStages = 15;
13 
14  Double_t MomInit = 0.7; // initial momentum
15 
16  TString ScintName[numStages];
17  TString AbsName[numStages];
18 
19  bool ScintBool[numStages];
20  bool AbsBool[numStages];
21 
22  cout << "Initialize names" << endl;
23 
24  for (Int_t w = 0 ; w < numStages ; w++)
25  {
26  ScintName[w] = Form("TestHCalScintillator%d_",w+1);
27  AbsName[w] = Form("TestHCalAbsorber%d_",w+1);
28  cout << ScintName[w] << "\t" << AbsName[w] << endl;
29 
30  }
31 
32 
33  // load libs
34 
35  gROOT->Macro("$VMCWORKDIR/gconfig/rootlogon.C");
36 
37  //
38 
39  TString directory = gSystem->Getenv("VMCWORKDIR");
40  TString HitsFile = "HCalMC.root";
41  TString ParFile = "HCalMC_Params.root";
42 
43  TFile *f = new TFile(HitsFile);
44 
45  TFile *par = new TFile(ParFile);
46  par->Get("FairBaseParSet");
47 
48  TH1F *steps = new TH1F("Stages","Stages",numStages*2,0.5,2*numStages+0.5);
49 
50  TH1F *elossTot = new TH1F("eloss","eloss",1000,0.,1.1*MomInit);
51 
52  TCanvas *c1 = new TCanvas();
53  TCanvas *c2 = new TCanvas();
54 
55  fGeoH = new PndGeoHandling();
56 
57  TTree *t=(TTree *) f->Get("pndsim") ;
58 
59  TClonesArray* mc_array=new TClonesArray("PndSdsMCPoint");
60  t->SetBranchAddress("MVDPoint",&mc_array);//Branch names
61 
62  TClonesArray* tr_array=new TClonesArray("PndMCTrack");
63  t->SetBranchAddress("MCTrack",&tr_array);//Branch names
64 
65  cout << "Events: " << t->GetEntries() << endl;
66 
67  TString name;
68 
69  Double_t eLoss = 0.; // eloss in one event
70  Double_t Zv = 99.;
71 
72  for (Int_t j = 0 ; j < t->GetEntries() ; j++) // loop on events
73 
74  {
75 
76  for (Int_t o = 0 ; o < numStages ; o++)
77  {
78  ScintBool[o] = false;
79  AbsBool[o] = false;
80  }
81 
82  t->GetEvent(j);
83  eLoss = 0;
84 
85  if (j%10000 == 0) cout << "Ev. " << j << endl;
86 
87  for (Int_t y = 0 ; y < mc_array->GetEntries() ; y++) // loop on hits
88  {
89 
90  PndSdsMCPoint *point = (PndSdsMCPoint*)mc_array->At(y);
91 
92  PndMCTrack *track = (PndMCTrack*)tr_array->At(point->GetTrackID());
93 
94  eLoss += point->GetEnergyLoss();
95 
96  Zv = (track->GetStartVertex()).Z();
97 
98  if (track->GetMotherID()<0.5 && track->GetPdgCode()==2212 && Zv<-1.) // check if primary
99  {
100  name = fGeoH->GetPath(point->GetDetName());
101 
102  for (Int_t r = 0; r < numStages ; r++)
103  {
104 
105  if (name.Contains(ScintName[r]))
106  {
107  ScintBool[r] = true;
108  steps->Fill(2*(r+1)-1);
109  }
110  if (name.Contains(AbsName[r]))
111  {
112  AbsBool[o] = true;
113  steps->Fill(2*(r+1));
114  }
115 
116  } // end loop on names
117  }
118 
119  } // end loop on entries
120 
121  elossTot->Fill(eLoss);
122 
123  } // end loop on events
124 
125  c1->cd();
126  steps->Draw();
127  steps->GetXaxis()->SetTitle("# of stages");
128  steps->GetYaxis()->SetTitle("# of protons");
129 
130 
131  c2->cd();
132  elossTot->Draw();
133  elossTot->GetXaxis()->SetTitle("Energy loss / event [GeV]");
134  return 0;
135 
136 }
137 
double r
Definition: RiemannTest.C:14
PndGeoHandling * fGeoH
Definition: anasim.C:34
Int_t GetPdgCode() const
Definition: PndMCTrack.h:73
Double_t par[3]
c2
Definition: plot_dirc.C:39
TClonesArray * mc_array
Definition: anaLmdCluster.C:25
TString GetPath(Int_t shortID)
for a given shortID the path is returned
Class to access the naming information of the MVD.
Double_t
PndMCTrack * track
Definition: anaLmdCluster.C:89
TFile * f
Definition: bump_analys.C:12
c1
Definition: plot_dirc.C:35
TString name
double Z
Definition: anaLmdDigi.C:68
TTree * t
Definition: bump_analys.C:13
Double_t y
TVector3 GetStartVertex() const
Definition: PndMCTrack.h:76
Int_t GetMotherID() const
Definition: PndMCTrack.h:74
TString directory
int ReadHCal()
Definition: ReadHCal.C:8
PndSdsMCPoint * point
Definition: anaLmdCluster.C:72