FairRoot/PandaRoot
macro/outdated/SimulationGG/SimulationMacros/plot_radmap.C
Go to the documentation of this file.
1 // macro reads from the RadMap Branch
2 // and fills histograms
3 int plot_radmap(Long64_t nevreq, TString outputfile="RadMap_Out.root")
4 {
5  gROOT->LoadMacro("$VMCWORKDIR/gconfig/rootlogon.C");
6  rootlogon();
7 
8  // open an output file
9  TFile *fout = new TFile(outputfile,"RECREATE");
10 
11  // chain for the pndsim tree in the simulation files
12  TChain mych("pndsim");
13 
14  /*
15  mych.Add("/data/panda/pbarH150_1.root");
16  mych.Add("/data/panda/pbarH150_2.root");
17  mych.Add("/data/panda/pbarH150_3.root");
18  mych.Add("/data/panda/pbarH150_4.root");
19  mych.Add("/data/panda/pbarH150_5.root");
20  */
21 
22  /*
23  mych.Add("/data/panda/pbarp150_dpm_1.root");
24  mych.Add("/data/panda/pbarp150_dpm_2.root");
25  mych.Add("/data/panda/pbarp150_dpm_3.root");
26  mych.Add("/data/panda/pbarp150_dpm_4.root");
27  */
28 
29  mych.Add("/s/olaf/test.root");
30 
31  // mych.SetBranchStatus("*",0);
32  // mych.SetBranchStatus("Rad*",1);
33 
34  Long64_t nentries = (Long64_t)mych.GetEntries();
35 
36  /*
37  this lines can be used for a single tree file instead of a chain
38  TFile *file = new TFile(treefile);
39  TTree *tree = (TTree*)file->Get("pndsim");
40 
41  tree->SetBranchStatus("*",0);
42  tree->SetBranchStatus("Rad*",1);
43 
44  Long64_t nentries = (Long64_t)tree->GetEntriesFast();
45  */
46 
47  cout << "we have " << nentries << " events" << endl;
48 
49  TClonesArray *fRadMapPoint = new TClonesArray("FairRadMapPoint");
50 
51  mych.SetBranchAddress("RadMap",&fRadMapPoint);
52 
53  // if a single tree file is used
54  // tree->SetBranchAddress("RadMap",&fRadMapPoint);
55 
56  // define some histograms
57 
58  TH2D *histo = new TH2D("histo","histo",400,-100.,300.,150,0.,150.);
59 
60  TH2D *his2 = new TH2D("his2","his2",1000,-300.,700.,300,0.,300.);
61 
62  TH2D *his3 = new TH2D("his3","his3",400,-100.,300.,150,0.,150.);
63 
64  TH2D *his4 = new TH2D("his4","his4",2300,-100.,130.,1000,0.,50.);
65 
66  TH2D *spezial = new TH2D("spezial","spezial",100,125.,135.,100,45.,55.);
67 
68  TH2D *his5 = new TH2D("his5","his5",120,-60.,60.,120,-60.,60.);
69 
70  // TProfile2D * histop =
71  // new TProfile2D("histop","histop",400,-100.,300.,150,0.,150.,1e-22,1e-11);
72 
73  // define some variables
74  Double_t x,y,z,r,dose,dSL,mass;
75  Int_t pid,VolID;
76 
77  // loop over events
78  Long64_t nevents;
79 
80  cout << "you requested " << nevreq << " events" << endl;
81 
82  if(nevreq==0){
83  nevents=nentries;
84  }else{
85  nevents=nevreq;
86  }
87 
88  if(nevents>nentries) nevents=nentries;
89 
90  Int_t npoints,sumofpoints;
91 
92  sumofpoints=0;
93 
94  for (Long64_t i=0; i<nevents; i++) {
95 
96  cout << "event " << i << endl;
97 
98  x=0.;
99  y=0.;
100  z=0.;
101  r=0.;
102  dose=0.;
103  dSL=0.;
104  pid=0;
105  npoints=0;
106 
107 
108  mych.GetEntry(i);
109  npoints = fRadMapPoint->GetEntries();
110 
111  // tree->GetEntry(i);
112  // npoints = fRadMapPoint->GetEntriesFast();
113 
114 
115  // loop over points
116  for (Int_t ii=0; ii < npoints; ii++) {
117 
118  sumofpoints++;
119 
120  FairRadMapPoint *p= (FairRadMapPoint *) fRadMapPoint->At(ii);
121 
122  // cout << "Point Number " << ii << " Zout = "<< p->GetZOut() << endl;
123 
124  dose= p->GetDose();
125  dSL = p->GetDoseSL();
126  if(dose<=0) continue;
127 
128  pid=p->GetPdg();
129  VolID=p->GetDetectorID(); // volume ID (replaces detector ID here!!)
130  mass=p->GetMass();
131 
132  z= p->GetZOut();
133  y= p->GetYOut();
134  x= p->GetXOut();
135  r= sqrt(pow(p->GetXOut(),2)+pow(p->GetYOut(),2));
136 
137  // cout << "Dose: " << z << endl;
138 
139  histo->Fill(z,r,dose);
140  his2->Fill(z,r,dose);
141  his4->Fill(z,r,dose);
142 
143  // special conditions
144  // if(z>129.5||z<130.5) his5->Fill(x,y,dose);
145 
146  // if(VolID==5509) his5->Fill(x,y,dose);
147 
148  spezial->Fill(z,r,dose);
149 
150  if(pid==2112)
151  his3->Fill(z,r,dose); // neutrons
152 
153  }
154 
155  }
156 
157 
158  // scale by the number of events
159  Double_t scale=1./nevents;
160 
161  histo->Scale(scale);
162  his2->Scale(scale);
163  his3->Scale(scale);
164  his4->Scale(scale);
165  // his5->Scale(scale);
166  spezial->Scale(scale);
167 
168 
169  // write to output file
170  fout->Write("histo");
171  fout->Write("his2");
172  fout->Write("his3");
173  fout->Write("his4");
174  fout->Write("his5");
175  fout->Write("spezial");
176 
177  cout << "total no. of points: " << sumofpoints << endl;
178 
179  return 0;
180 }
Double_t p
Definition: anasim.C:58
double r
Definition: RiemannTest.C:14
Int_t i
Definition: run_full.C:25
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
int pid()
Double_t
Double_t z
int plot_radmap(Long64_t nevreq, TString outputfile="RadMap_Out.root")
Double_t x
Double_t y