FairRoot/PandaRoot
ana_MCOpt.C
Go to the documentation of this file.
1 // root macro to analyze the simulation output
2 int ana_MCOpt()
3 {
4 
5  // ----- Load libraries ------------------------------------------------
6 //``gSystem->Load("fstream.h");
7  gROOT->Macro("$VMCWORKDIR/gconfig/rootlogon.C");
8 
9  gSystem->Load("libSciT");
10  // ----- Timer --------------------------------------------------------
11  TStopwatch timer;
12  timer.Start();
13  // ------------------------------------------------------------------------
14 
15  gStyle->SetPalette(1);
16 
17  TFile* f = new TFile("test.root"); // the sim file you want to analyse
18  TTree *t=(TTree *) f->Get("pndsim") ;
19  TClonesArray* hit_array=new TClonesArray("PndSciTPoint");
20  t->SetBranchAddress("SciTPoint",&hit_array);//Branch names
21 
22 
23  TClonesArray* mc_array=new TClonesArray("PndMCTrack");
24  t->SetBranchAddress("MCTrack",&mc_array);//Branch names
25 
26  TFile *out = TFile::Open("pid_MCOpt.root","RECREATE");
27 
28 
29  // histos
30  TH2D* hisxy = new TH2D("hisxy","MC Points, xy view",200,-70.,70.,200,-70.,70.);
31  TH2D* hisrz = new TH2D("hisrz"," MC Points, rz view",200,-70.,70.,200,0,70.);
32  TH1D* hisde = new TH1D("hisde","MC Points, Energyloss",200,0.,0.005);
33 
34 
35  TH2D* hisdedx =new TH2D("hisdedx","",200,0.,0.04,200,0.,1.0);
36  hisdedx->SetTitle("HYP MC Points, dE/dx(P);p/GeV / cm;dE/dx / (GeV/cm)");
37 
38 
39 
40 
41  TH1D* hismom = new TH1D("hisximom"," MC Points, momentum",100,0.,1.5);
42 
43 
44  int nEvents = 100;
45  bool verbose = false;
46 
47  TVector3 vecs,veco;
48  TVector3 vecFront,vecS,vecP;
49  Double_t dx,dE,p,dEdX,pxi;
50 
52 
53  for (Int_t j=0; j<t->GetEntriesFast(); j++)
54  {
55  t->GetEntry(j);
56 
57  for (Int_t i=0; i<hit_array->GetEntriesFast(); i++)
58  {
59  if(verbose) cout<<"Point No "<<i<<endl;
60  PndSciTPoint *hit=(PndSciTPoint*)hit_array->At(i);
61  //int mcpdg = -1;
62 
63 
64 
65  vecs.SetXYZ(hit->GetX(), hit->GetY(), hit->GetZ());
66  veco.SetXYZ(hit->GetXout(),hit->GetYout(),hit->GetZout());
67  vecP.SetXYZ(hit->GetPxin(),hit->GetPyin(),hit->GetPzin());
68 
69  dx=(veco-vecs).Mag();
70  dE=hit->GetEnergyLoss();
71  pxi=vecP.Mag();
72 
73 
74  hisxy->Fill(vecs.x(),vecs.y());
75  hisrz->Fill(vecs.z(),vecs.Perp());
76  hisde->Fill(dE);
77  hismom->Fill(pxi);
78 
79  if(dx!=0)
80  {
81  dEdX=(dE/dx);
82  hisdedx->Fill(p,dEdX);
83  hisde->Fill(dEdX);
84  }
85 
86 
87  }//end for i (points in event)
88  }// end for j (events)
89 
90 
91 
92 out->cd();
93 
94 hisxy->Write();
95 hisrz->Write();
96 hisdedx->Write();
97 hisde->Write();
98 hismom->Write();
99 out->Save();
100 
101 
102  // ----- Finish -------------------------------------------------------
103  timer.Stop();
104  Double_t rtime = timer.RealTime();
105  Double_t ctime = timer.CpuTime();
106  cout << endl << endl;
107  cout << "Macro finished succesfully." << endl;
108  //cout << "Output file is " << outFile << endl;
109  //cout << "Parameter file is " << parFile << endl;
110  cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
111  cout << endl;
112  // ------------------------------------------------------------------------
113 
114  return 0;
115 }
TH2D * hisdedx
Definition: anasim.C:42
TH1D * hisde
Definition: anaLmdDigi.C:44
Double_t GetYout() const
Definition: PndSciTPoint.h:56
Int_t i
Definition: run_full.C:25
#define verbose
TClonesArray * mc_array
Definition: anaLmdCluster.C:25
Double_t p
Definition: anasim.C:58
TClonesArray * hit_array
Double_t dEdX
Definition: anasim.C:58
TVector3 vecs
TVector3 vecFront
Definition: anasim.C:57
Double_t
Double_t dE
Definition: anasim.C:58
Int_t nEvents
Definition: hit_dirc.C:11
TStopwatch timer
Definition: hit_dirc.C:51
TH1D * hismom
Definition: anaMvdDigi.C:49
TFile * f
Definition: bump_analys.C:12
TString detname
Definition: anasim.C:61
int ana_MCOpt()
Definition: ana_MCOpt.C:2
TFile * out
Definition: reco_muo.C:20
TVector3 veco
Definition: anaMvdSim.C:33
TH2D * hisxy
Definition: anaLmdDigi.C:38
TVector3 vecP
Definition: anasim.C:57
Double_t ctime
Definition: hit_dirc.C:114
TH2D * hisrz
Definition: anaLmdDigi.C:41
double dx
int hit(Int_t nEvents=0, TString inFile="sim.root", TString parFile="par.root", TString inDigi="digi.root", TString outFile="hit.root", Int_t timeBased=0)
Definition: hit.C:1
Double_t GetXout() const
Definition: PndSciTPoint.h:55
Double_t GetZout() const
Definition: PndSciTPoint.h:57
TTree * t
Definition: bump_analys.C:13
Double_t rtime
Definition: hit_dirc.C:113