FairRoot/PandaRoot
AllNeutronAnalysis_job_edit.C
Go to the documentation of this file.
2 {
3  bool verbose = false;
4  // ----- Load libraries ------------------------------------------------
5  gROOT->Macro("$VMCWORKDIR/gconfig/rootlogon.C");
6  gSystem->Load("libHypGe");
7  // ----- Timer --------------------------------------------------------
8  TStopwatch timer;
9  timer.Start();
10  // ------------------------------------------------------------------------
11 
12 
13  //Files
14  //TString Path = getenv("SIMDATADIR");
15  TString Filename = "$SIMDATADIR/Neutron/"+Filename_ext;
16  //TString Filename = "$SIMDATADIR/TripleBall40Offset10_urqmd_pbarC_1_5000Evts.root";
17  TString outfile= "$SIMDATADIR/Neutron/Ana/Ana" + Filename_ext;
18  TFile* InputFile = new TFile(Filename);
19  TFile* OutputFile = new TFile(outfile,"RECREATE");
20 
21  //getting simulation branches from input file
22  TTree *b=(TTree *) InputFile->Get("pndsim") ;
23  TClonesArray* hit_bar=new TClonesArray("PndHypGePoint");
24  b->SetBranchAddress("HypGePoint",&hit_bar);//Branch names
25  TClonesArray* mc_bar=new TClonesArray("PndMCTrack");
26  b->SetBranchAddress("MCTrack",&mc_bar);//Branch names
27 
28  //declaring histograms
29  //histogram with polar angle of detector interactions of primary neutrons
30  TH1D* hNHits = new TH1D("hNHits","Polar angle of primary neutrons interacting with the crystals",180, 90,180);
31  hNHits->SetXTitle("#Theta [#circ]");
32  hNHits->SetYTitle("Counts / 0.5 #circ");
33  //histogram with the polar momentum of primary neutrons interacting with the crystals
34  TH1D* hNHits_p = new TH1D("hNHits_p","Direction of polar momentum of primary neutrons interacting with the crystals",180, 90,180);
35  hNHits_p->SetXTitle("#Theta [#circ]");
36  hNHits_p->SetYTitle("Counts / 0.5 #circ");
37  //histogram with the polar momentum of primary neutrons in the solid angle of the crystal (not necessarily interacting with the crystal)
38  TH1D* hNAll = new TH1D("hNAll","All Neutrons",180, 90,180);
39  hNAll->SetXTitle("#Theta [#circ]");
40  hNAll->SetYTitle("Counts / 0.5 #circ");
41  //histogram with E_kin of primary neutrons
42  TH1D* hNMom = new TH1D("hNMom","E_{kin} of neutrons",1000, 0,0.5);
43  hNMom->SetXTitle("E_{kin} of neutrons [GeV]");
44  hNMom->SetYTitle("Counts / 0.5 MeV");
45  //histogram to see which detector is hit
46  TH1D* hCrystalHit = new TH1D("hCrystalHit","Hits per Crystal",1700,1,1700);
47  hCrystalHit->SetXTitle("Crystal number");
48  hCrystalHit->SetYTitle("Counts per crystal");
49  //histogram to see the energy deposited by the neutron
50  TH1D* hNeutronEnergyDeposit = new TH1D("hNeutronEnergyDeposit","Energy deposited by Neutrons per Hit",500,0,0.005);
51  hNeutronEnergyDeposit->SetXTitle("Energy [GeV]");
52  hNeutronEnergyDeposit->SetYTitle("Counts / 10 keV");
53 
54  Int_t *ActualTrackID ;
55  Int_t nEvents = b->GetEntriesFast();
56  cout<< "Number of Simulated Events: "<<nEvents<<endl;
57 
58  Int_t Hits=0;
59  Int_t DetID=-10;
60  Int_t TrackID=-10;
61  int iNeutrons = 0;
62  //event loop
63  for (Int_t k=0; k<nEvents; k++)
64  {
65  b->GetEntry(k);
66  if (!((k*100)% nEvents)) // mark every % of proceeded events
67  {
68  cout << "Event number :\t" << k << endl;
69  }
70  //if(verbose) cout<<"Event No "<<j<<endl;
71 
72  DetID=-10;
73  TrackID=-10;
74  // loop over the hits of an event
75  for (Int_t i=0; i<hit_bar->GetEntriesFast(); i++)
76  {
77  //if (i==0)
78  //Hits++;
79  //cout <<"Hit "<< i << endl;
80 
81  PndHypGePoint *hitgam=(PndHypGePoint*)hit_bar->At(i);
82  PndMCTrack *mcgam = (PndMCTrack*)mc_bar->At(hitgam->GetTrackID());
83 
84  TVector3 NMom = mcgam->GetMomentum();
85 
86  if ( hitgam->GetpdgCode()==2112 && mcgam->GetMotherID() == -1 && !(DetID == hitgam->GetDetectorID() && TrackID==hitgam->GetTrackID())) // primary neutron, last part: not(same paricle and crystal) -> against multi counting of a single neutron
87  {
88  DetID = hitgam->GetDetectorID();
89  TrackID = hitgam->GetTrackID();
90  cout << "Event :\t" << k <<"\tHit : \t" << i << "\tDetector :\t" << DetID << "\tTrackID :\t"<< TrackID<<"\tMother :\t"<< mcgam->GetMotherID()<<endl;
91  iNeutrons++;
92  hCrystalHit->Fill(hitgam->GetDetectorID()); //fill histogram to see which detector is hit
93 
94  TVector3 NHit;
95  // fill vector with hit coordinates to get theta of the hit
96  NHit.SetX(hitgam->GetX());
97  NHit.SetY(hitgam->GetY());
98  NHit.SetZ(hitgam->GetZ()+55);
99  hNHits->Fill(180/TMath::Pi()*NHit.Theta()); //fill histogram with polar angle of detector interactions of primary neutrons
100 
101  TVector3 NHit_p;
102  // fill vector with hit momentum to get theta of the hit momentum
103  NHit_p.SetX(hitgam->GetPx());
104  NHit_p.SetY(hitgam->GetPy());
105  NHit_p.SetZ(hitgam->GetPz());
106  hNHits_p->Fill(180/TMath::Pi()*NHit_p.Theta()); //fill histogram with the polar momentum of primary neutrons interacting with the crystals
107 
108 
109  hNMom->Fill(1./2.* NMom.Mag2()/0.939); //fill histogram with E_kin of primary neutrons
110 
111  }
112 
113  if (hitgam->GetpdgCode()==2112) // neutron
114  {
115  hNeutronEnergyDeposit->Fill(hitgam->GetEnergyLoss());
116  }
117  }
118 
119  // loop over all entries in mctrack
120  cout << "mcbar length :\t" <<mc_bar->GetEntriesFast() << endl;
121  for (Int_t m = 0; m<mc_bar->GetEntriesFast();m++)
122  {
123  //cout << "mcbar length :\t" <<mc_bar->GetEntriesFast() << endl;
124  PndMCTrack *mcgam = (PndMCTrack*)mc_bar->At(m);
125  TVector3 NAllMom = mcgam->GetMomentum();
126  if (mcgam->GetPdgCode() == 2112 && mcgam->GetMotherID() == -1)
127  {
128  cout << "event :\t"<<k<<"\tmcpdg :\t" << mcgam->GetPdgCode() << "\tmcmotherid :\t"<< mcgam->GetMotherID() <<endl;
129 
130  hNAll->Fill(180/TMath::Pi()*NAllMom.Theta()); //fill histogram with the polar momentum of primary neutrons in the solid angle of the crystal (not necessarily interacting with the crystal)
131  }
132  }
133  }// end for k (events)
134 
135 
136 
137  //hNAll->DrawCopy();
138  //hNHits->SetLineColor(kRed);
139  //hNHits->DrawCopy("same");
140 
141  //Analysis of spectrum
142  hNHits->Write();
143  hNHits_p->Write();
144  hNAll->Write();
145  hNMom->Write();
146  hCrystalHit->Write();
147  hNeutronEnergyDeposit->Write();
148 
149 
150 
151  //hNeutronEnergyDeposit->DrawCopy();
152 
153  OutputFile->Close();
154 
155  //hNeutronEnergyDeposit->Draw();
156  //hNHits->Draw();
157 
158 
159  // ----- Finish -------------------------------------------------------
160  timer.Stop();
161  Double_t rtime = timer.RealTime();
162  Double_t ctime = timer.CpuTime();
163  cout << endl << endl;
164  cout << "Macro finished succesfully." << endl;
165 
166  cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
167  cout << endl;
168 
169  cout << "Hits\t" << Hits << endl;
170  // ------------------------------------------------------------------------
171  return iNeutrons;
172 }
Int_t i
Definition: run_full.C:25
__m128 m
Definition: P4_F32vec4.h:28
TTree * b
Int_t GetPdgCode() const
Definition: PndMCTrack.h:73
#define verbose
Double_t GetPz() const
Definition: PndHypGePoint.h:59
Int_t GetTrackID() const
Definition: PndHypGePoint.h:51
TVector3 GetMomentum() const
Definition: PndMCTrack.h:78
TClonesArray * hit_bar
Double_t
Double_t GetPy() const
Definition: PndHypGePoint.h:58
Int_t nEvents
Definition: hit_dirc.C:11
TStopwatch timer
Definition: hit_dirc.C:51
Double_t GetPx() const
Definition: PndHypGePoint.h:57
Double_t ctime
Definition: hit_dirc.C:114
Double_t GetZ() const
Definition: PndHypGePoint.h:56
Double_t GetX() const
Definition: PndHypGePoint.h:54
Double_t GetY() const
Definition: PndHypGePoint.h:55
int AllNeutronAnalysis_job_edit(TString Filename_ext)
TClonesArray * mc_bar
Int_t GetMotherID() const
Definition: PndMCTrack.h:74
Double_t rtime
Definition: hit_dirc.C:113
Double_t Pi
Int_t GetDetectorID() const
Definition: PndHypGePoint.h:53
Double_t GetEnergyLoss() const
Definition: PndHypGePoint.h:62
TString outfile
Double_t GetpdgCode() const
Definition: PndHypGePoint.h:63