FairRoot/PandaRoot
ana_MCpid.C
Go to the documentation of this file.
1 // root macro to analyze the simulation output
2 //void convertMCPoints()
3 int ana_MCpid()
4 {
5 
6  // ----- Load libraries ------------------------------------------------
7 //``gSystem->Load("fstream.h");
8  gROOT->Macro("$VMCWORKDIR/gconfig/rootlogon.C");
9 
10  gSystem->Load("libHypGe");
11  // ----- Timer --------------------------------------------------------
12  TStopwatch timer;
13  timer.Start();
14  // ------------------------------------------------------------------------
15 
16  gStyle->SetPalette(1);
17 
18  TFile* f = new TFile("sim_pidC.root"); // the sim file you want to analyse
19  TTree *t=(TTree *) f->Get("pndsim") ;
20  TClonesArray* hit_array=new TClonesArray("PndHypPoint");
21  t->SetBranchAddress("HypPoint",&hit_array);//Branch names
22 
23  TClonesArray* mc_array=new TClonesArray("PndMCTrack");
24  t->SetBranchAddress("MCTrack",&mc_array);//Branch names
25 
26 
27 
28  // histos
29  TH2D* hisxy = new TH2D("hisxy","HYP MC Points, xy view",200,-5.,5.,200,-5.,5.);
30  TH2D* hisrz = new TH2D("hisrz","HYP MC Points, rz view",200,-80.,-70.,200,0,5.);
31  TH1D* hisde = new TH1D("hisde","HYP MC Points, Energyloss",200,0.,0.002);
32 
33 
34  TH2D* hisdedx =new TH2D("hisdedx","",200,0.,0.4,200,0.,1.0);
35  hisdedx->SetTitle("HYP MC Points, dE/dx(P);p/GeV / cm;dE/dx / (GeV/cm)");
36 
37 
38 
39  TH1D* hismom = new TH1D("hismom","HYP MC Points, momentum",100,0.,1.5);
40 
41 
42  int nEvents = 100;
43  bool verbose = false;
44 
45  TVector3 vecs,veco;
46  TVector3 vecFront,vecBack,vecP;
48 
50 
51  for (Int_t j=0; j<t->GetEntriesFast(); j++)
52  {
53  t->GetEntry(j);
54 
55  for (Int_t i=0; i<hit_array->GetEntriesFast(); i++)
56  {
57  if(verbose) cout<<"Point No "<<i<<endl;
58  PndHypPoint *hit=(PndHypPoint*)hit_array->At(i);
59  int mcpdg = -1;
60 
61  //PndMCTrack *mctruth = (PndMCTrack*)mc_array->At(hit->GetTrackID());
62  //mcpdg = mctruth->GetPdgCode();
63  //cout<<"mcpdg="<<mcpdg<<endl;
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  dx=(veco-vecs).Mag();
69  dE=hit->GetEnergyLoss();
70  p=vecP.Mag();
71  Int_t layer = Int_t(10.*vecs->Mag());
72  if(verbose) cout<<vecs.x()<<"\t"<<vecs.y()<<"\t"<<vecs.z()<<endl;
73 
74  hisxy->Fill(vecs.x(),vecs.y());
75  hisrz->Fill(vecs.z(),vecs.Perp());
76  hisde->Fill(dE);
77  hismom->Fill(p);
78 
79  if(dx!=0)
80  {
81  dEdX=(dE/dx);
82  hisdedx->Fill(p,dEdX);
83  }
84 
85 
86  }//end for i (points in event)
87  }// end for j (events)
88 
89 TCanvas* can1 = new TCanvas("can1","MCHit view in HYP",0,0,800,800);
90 can1->Divide(3,2);
91 can1->cd(1);
92 hisxy->Draw("colz");
93 can1->cd(2);
94 hisrz->Draw("colz");
95 can1->cd(3);
96 gPad->SetLogy();
97 hisde->Draw("");
98 can1->cd(4);
99 hisdedx->Draw();
100 can1->cd(5);
101 hismom->Draw("");
102 
103 
104 can1->Print("output.jpg");
105 
106 
107 
108 
109  // ----- Finish -------------------------------------------------------
110  timer.Stop();
111  Double_t rtime = timer.RealTime();
112  Double_t ctime = timer.CpuTime();
113  cout << endl << endl;
114  cout << "Macro finished succesfully." << endl;
115  //cout << "Output file is " << outFile << endl;
116  //cout << "Parameter file is " << parFile << endl;
117  cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
118  cout << endl;
119  // ------------------------------------------------------------------------
120 
121  return 0;
122 }
int ana_MCpid()
Definition: ana_MCpid.C:3
Double_t GetPxin() const
Definition: PndHypPoint.h:95
Double_t GetPyin() const
Definition: PndHypPoint.h:96
TH2D * hisdedx
Definition: anasim.C:42
Double_t GetYout() const
Definition: PndHypPoint.h:111
TH1D * hisde
Definition: anaLmdDigi.C:44
Int_t i
Definition: run_full.C:25
Double_t GetPzin() const
Definition: PndHypPoint.h:97
#define verbose
Double_t GetZout() const
Definition: PndHypPoint.h:112
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
TVector3 veco
Definition: anaMvdSim.C:33
TH2D * hisxy
Definition: anaLmdDigi.C:38
TVector3 vecP
Definition: anasim.C:57
int mcpdg
Double_t ctime
Definition: hit_dirc.C:114
TH2D * hisrz
Definition: anaLmdDigi.C:41
double dx
Double_t GetXout() const
Definition: PndHypPoint.h:110
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
TTree * t
Definition: bump_analys.C:13
TCanvas * can1
Double_t rtime
Definition: hit_dirc.C:113
TVector3 vecBack
Definition: anasim.C:57