FairRoot/PandaRoot
Functions
NeutronAnalysis_COSY_CrossSec.C File Reference
#include "TH1D.h"
#include "TH2D.h"
#include "TString.h"
#include "TFile.h"
#include "TTree.h"
#include "TStopwatch.h"
#include "TVector3.h"
#include "TROOT.h"
#include "TMath.h"
#include "TClonesArray.h"
#include "TSystem.h"
#include "TStyle.h"
#include <stdio.h>
#include <iostream>

Go to the source code of this file.

Functions

int NeutronAnalysis_COSY_CrossSec (TString Filename_ext, Int_t StartEvent=0, Int_t NoOfEvents=0)
 

Function Documentation

int NeutronAnalysis_COSY_CrossSec ( TString  Filename_ext,
Int_t  StartEvent = 0,
Int_t  NoOfEvents = 0 
)

Definition at line 20 of file NeutronAnalysis_COSY_CrossSec.C.

References b, ctime, Double_t, PndMCTrack::GetPdgCode(), hit_bar, m, mc_bar, outfile, rtime, timer, TString, and verbose.

21 {
22  bool verbose = false;
23  // ----- Load libraries ------------------------------------------------
24  gROOT->Macro("$VMCWORKDIR/gconfig/rootlogon.C");
25  gSystem->Load("libHypGe");
26  // ----- Timer --------------------------------------------------------
27  TStopwatch timer;
28  timer.Start();
29  // ------------------------------------------------------------------------
30 
31 
32  //Files
33  //TString Path = getenv("SIMDATADIR");
34  TString Filename = "$SIMDATADIR/COSY/"+Filename_ext;
35  //TString Filename = "$SIMDATADIR/TripleBall40Offset10_urqmd_pbarC_1_5000Evts.root";
36  TString outfile= "$SIMDATADIR/COSY/Ana/ToCombine/" + Filename_ext;
37  outfile += "/Ana";
38  outfile += Filename_ext;
39  outfile.ReplaceAll(".root","");
40  outfile += "_Start_";
41  outfile += StartEvent;
42  outfile += "_nEventssssssssssss_";
43  outfile += NoOfEvents;
44  outfile += ".root";
45  cout << outfile << endl;
46  TFile* InputFile = new TFile(Filename);
47  //TFile* OutputFile = new TFile(outfile,"RECREATE");
48 
49  //getting simulation branches from input file
50  TTree *b=(TTree *) InputFile->Get("pndsim") ;
51  TClonesArray* hit_bar=new TClonesArray("PndHypGePoint");
52  b->SetBranchAddress("HypGePoint",&hit_bar);//Branch names
53  TClonesArray* mc_bar=new TClonesArray("PndMCTrack");
54  b->SetBranchAddress("MCTrack",&mc_bar);//Branch names
55 
56  //declaring histograms
57  //histogram with polar angle of detector interactions of primary neutrons
58  TH1D* hNHits = new TH1D("hNHits","Polar angle of primary neutrons interacting with the crystals",180, 90,180);
59  hNHits->SetXTitle("#Theta [#circ]");
60  hNHits->SetYTitle("Counts / 0.5 #circ");
61  //histogram with the polar momentum of primary neutrons interacting with the crystals
62  TH1D* hNHits_p = new TH1D("hNHits_p","Direction of polar momentum of primary neutrons interacting with the crystals",180, 90,180);
63  hNHits_p->SetXTitle("#Theta [#circ]");
64  hNHits_p->SetYTitle("Counts / 0.5 #circ");
65  //histogram with the polar momentum of primary neutrons in the solid angle of the crystal (not necessarily interacting with the crystal)
66  TH1D* hNAll = new TH1D("hNAll","All Neutrons",360, 0,180);
67  hNAll->SetXTitle("#Theta [#circ]");
68  hNAll->SetYTitle("Counts / 0.5 #circ");
69 
70  //histogram with the polar momentum of primary neutrons in the solid angle of the crystal (not necessarily interacting with the crystal)
71  TH1D* hPAll = new TH1D("hPAll","All Protons",360, 0,180);
72  hPAll->SetXTitle("#Theta [#circ]");
73  hPAll->SetYTitle("Counts / 0.5 #circ");
74 
75  //histogram with E_kin of primary neutrons
76  TH1D* hNMom = new TH1D("hNMom","E_{kin} of neutrons",1000, 0,0.5);
77  hNMom->SetXTitle("E_{kin} of neutrons [GeV]");
78  hNMom->SetYTitle("Counts / 0.5 MeV");
79  //histogram to see which detector is hit
80  TH1D* hCrystalHit = new TH1D("hCrystalHit","Hits per Crystal",1700,1,1700);
81  hCrystalHit->SetXTitle("Crystal number");
82  hCrystalHit->SetYTitle("Counts per crystal");
83  //histogram to see the energy deposited by the neutron
84  TH1D* hNeutronEnergyDeposit = new TH1D("hNeutronEnergyDeposit","Energy deposited by Neutrons per Hit",500,0,0.005);
85  hNeutronEnergyDeposit->SetXTitle("Energy [GeV]");
86  hNeutronEnergyDeposit->SetYTitle("Counts / 10 keV");
87 
88  //histogram to visualize the x-y-distribution of neutrons
89  TH2D* hNeutronXYDistribution = new TH2D("hNeutronXYDistribution","Distribution of Neutrons",40, -40,40,40,-40,40);
90  hNeutronXYDistribution->SetXTitle("X-postion [cm]");
91  hNeutronXYDistribution->SetYTitle("Y-postion [cm]");
92  gStyle->SetPalette(1);
93 
94 
95 
96  Int_t *ActualTrackID ;
97  //Int_t nEvents = b->GetEntriesFast();
98  //cout<< "Number of Simulated Events: "<<nEvents<<endl;
99 
100  Int_t Hits=0;
101  Int_t DetID=-10;
102  Int_t TrackID=-10;
103  Int_t iNeutrons = 0;
104  Int_t NuclearInteractionCounter=0;
105 
106 
107 
108  TVector3 NHit;
109  TVector3 NMom;
110  TVector3 NAllMom;
111  TVector3 StartVertex;
112 
113 
114  Int_t EndEvent;
115  if (NoOfEvents ==0)
116  {
117  EndEvent = b->GetEntriesFast();
118  NoOfEvents = EndEvent - StartEvent;
119  }
120  else
121  EndEvent = StartEvent + NoOfEvents;
122 
123  //event loop
124  for (Int_t k=StartEvent; k< EndEvent; k++)
125  //for (Int_t k=569494; k<569498; k++)
126  {
127  b->GetEntry(k);
128  if (!((k*100)% NoOfEvents)) // mark every % of proceeded events
129  {
130  cout << "Event number :\t" << k << endl;
131  }
132  //if(verbose) cout<<"Event No "<<j<<endl;
133 
134  DetID=-10;
135  TrackID=-10;
136 
137  // loop over the hits of an event
138  //for (Int_t i=0; i<hit_bar->GetEntriesFast(); i++)
139  //{
143 
144  //PndHypGePoint *hitgam=(PndHypGePoint*)hit_bar->At(i);
145  //PndMCTrack *mcgam = (PndMCTrack*)mc_bar->At(hitgam->GetTrackID());
146 
148  //if (hitgam->GetpdgCode() == 2112)
149  //{
150  //StartVertex = mcgam->GetStartVertex();
151  //cout <<"Event " <<k<< " \t\tStartVertex Radius: " <<StartVertex.Mag()<< endl;
152 
153  //if (StartVertex.Mag() <20) // prevent counting of neutrons created by nuclear reactions inside the detector 20 (cm) is random value, must be smaller than the distance from (0,0,0) to detector (here 30 cm)
154  //{
155  //if (!(DetID == hitgam->GetDetectorID() && TrackID==hitgam->GetTrackID())) // used to prevent counting of neutrons that reenter a crystal (neutrons left crystal through the central hole skewly and reentered the same crystal afterwards) and of neutrons that enter multiple crystals by scattering
156  //{
157  //DetID = hitgam->GetDetectorID();
158  //TrackID = hitgam->GetTrackID();
160  //iNeutrons++;
161  //hCrystalHit->Fill(hitgam->GetDetectorID()); //fill histogram to see which detector is hit
162 
163 
165  //NHit.SetX(hitgam->GetX());
166  //NHit.SetY(hitgam->GetY());
167  //NHit.SetZ(hitgam->GetZ()); // no shift like in PANDA!!!!
168  //hNHits->Fill(180/TMath::Pi()*NHit.Theta()); //fill histogram with polar angle of detector interactions of primary neutrons
169  //cout << "Event " << k <<" Theta " <<180/TMath::Pi()*NHit.Theta()<<endl;
170 
171  //TVector3 NHit_p;
173  //NHit_p.SetX(hitgam->GetPx());
174  //NHit_p.SetY(hitgam->GetPy());
175  //NHit_p.SetZ(hitgam->GetPz());
176  //hNHits_p->Fill(180/TMath::Pi()*NHit_p.Theta()); //fill histogram with the polar momentum of primary neutrons interacting with the crystals
177 
178  //hNeutronXYDistribution->Fill(hitgam->GetX(),hitgam->GetY());
180  //hNeutronEnergyDeposit->Fill(hitgam->GetEnergyLoss());
181 
182  //}
183  //}
184  //}
185  //}
186 
187  // loop over all entries in mctrack
188  //cout << "mcbar length :\t" <<mc_bar->GetEntriesFast() << endl;
189  int verboseMC = 0;
190  if (verboseMC) cout << "Event " << k << "\tNumber of particles: " <<mc_bar->GetEntriesFast() ;
191  if(mc_bar->GetEntriesFast()>2)
192  {
193  //NuclearInteractionCounter++;
194  for (Int_t m = 0; m<mc_bar->GetEntriesFast();m++)
195  {
196  //cout << "mcbar length :\t" <<mc_bar->GetEntriesFast() << endl;
197  PndMCTrack *mcgam = (PndMCTrack*)mc_bar->At(m);
198 
199  if (mcgam->GetPdgCode() != 2212 && mcgam->GetPdgCode() != 11 && mcgam->GetPdgCode() !=-2212)
200  {
201  if (verboseMC)cout << "\t Found Particle with PDG code: " << mcgam->GetPdgCode() << endl;
202  NuclearInteractionCounter++;
203  break;
204  }
205  else
206  if ( m == mc_bar->GetEntriesFast()-1)
207  if (verboseMC)cout << endl;
208  }
209  }
210  else
211  if (verboseMC)cout << endl;
212 
213 
214  }// end for k (events)
215 
216 
217  //hNeutronXYDistribution->DrawCopy("colz");
221 
223  //hNHits->Write();
224  //hNHits_p->Write();
225  //hNAll->Write();
226  //hPAll->Write();
227  //hNMom->Write();
228  //hCrystalHit->Write();
229  //hNeutronEnergyDeposit->Write();
230  //hNeutronXYDistribution->Write();
231 
232 
233 
234  //hNeutronEnergyDeposit->DrawCopy();
235 
236  //OutputFile->Close();
237 
238  //hNeutronEnergyDeposit->Draw();
239  //hNHits->Draw();
240 
241  cout << "Number of nuclear interactions: " <<NuclearInteractionCounter << endl;
242  // ----- Finish -------------------------------------------------------
243  timer.Stop();
244  Double_t rtime = timer.RealTime();
245  Double_t ctime = timer.CpuTime();
246  cout << endl << endl;
247  cout << "Macro finished succesfully." << endl;
248 
249  cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
250  cout << endl;
251 
252  cout << "Hits\t" << Hits << endl;
253  // ------------------------------------------------------------------------
254  return iNeutrons;
255 }
__m128 m
Definition: P4_F32vec4.h:28
TTree * b
Int_t GetPdgCode() const
Definition: PndMCTrack.h:73
#define verbose
TClonesArray * hit_bar
Double_t
TStopwatch timer
Definition: hit_dirc.C:51
Double_t ctime
Definition: hit_dirc.C:114
TClonesArray * mc_bar
Double_t rtime
Definition: hit_dirc.C:113
TString outfile