FairRoot/PandaRoot
anaGemPointrate.C
Go to the documentation of this file.
1 // root macro to analyze the simulation output
2 #include <vector>
3 #include <map>
4 int anaGemPointrate(int nEvents = 10, bool verbose = false)
5 {
6 // int nEvents = 1000;
7 // bool verbose = false;
8  // ----- Timer --------------------------------------------------------
9  TStopwatch timer;
10  timer.Start();
11  // ------------------------------------------------------------------------
12 
13  TFile* f = new TFile("Gem_Test.root"); // the sim file you want to analyse
14  TTree *t=(TTree *) f->Get("pndsim") ;
15 
16  TClonesArray* hit_array=new TClonesArray("PndGemMCPoint");
17  t->SetBranchAddress("GEMPoint",&hit_array);//Branch names
18 
19  TClonesArray* mc_array=new TClonesArray("PndMCTrack");
20  t->SetBranchAddress("MCTrack",&mc_array);//Branch names
21 
22  TH2D* hisxy = new TH2D("hisxy","GEM MC Points, xy view",100,-150.,150.,100,-150.,150.);
23  TH2D* hisrz = new TH2D("hisrz","GEM MC Points, rz view",100,0.,300.,100,-150.,150.);
24  TH1D* hisde = new TH1D("hisde","GEM MC Points, Energyloss",100,0.,0.00002);
25 
26 
27  TH1D *hisDisk1Theta = new TH1D("disk1theta","Gem Disk 1 pointrate per 6GeV DPM event;#theta;dN/d#theta ",45,0.,45.);
28  TH1D *hisDisk2Theta = new TH1D("disk2theta","Gem Disk 2 pointrate per 6GeV DPM event;#theta;dN/d#theta ",45,0.,45.);
29  TH1D *hisDisk3Theta = new TH1D("disk3theta","Gem Disk 3 pointrate per 6GeV DPM event;#theta;dN/d#theta ",45,0.,45.);
30 
31  TH2D *histrackrate = new TH2D("trackrate","Gem trackrate per 6GeV DPM event;#theta;nPoints ",45,0.,45.,3,1.,4.);
32 
33 
34  TVector3 vecs;
35  std::map<int,int> hitsontrack;
37  int trackno=0,hitcount=0;
38  double scale=1., weight=1.,thetadeg=0.;
39  if(nEvents!=0) scale=1./(double)nEvents;
40  cout << "scale = "<<scale<<endl;
41 
42  for (Int_t j=0; j<nEvents && j<t->GetEntriesFast(); j++)
43  {
44  t->GetEntry(j);
45  if(verbose) cout<<"Event No "<<j<<endl;
46  for(int l=0;l<mc_array->GetEntriesFast();l++){
47  hitsontrack[l]=0;
48  } // end for Tracknumbers
49  for (Int_t i=0; i<hit_array->GetEntriesFast(); i++)
50  {
51  if(verbose) cout<<"Point No "<<i<<endl;
52  PndGemMCPoint *hit=(PndGemMCPoint*)hit_array->At(i);
53  int mcpdg = -1;
54 
55 // PndMCTrack *mctruth = (PndMCTrack*)mc_array->At(hit->GetTrackID());
56 // mcpdg = mctruth->GetPdgCode();
57 // cout<<"mcpdg="<<mcpdg<<endl;
58 
59  vecs.SetXYZ(hit->GetX(), hit->GetY(), hit->GetZ());
60 
61  hisxy->Fill(vecs.x(),vecs.y());
62  hisrz->Fill(vecs.z(),((vecs.y()>0.)?1.:-1.)*vecs.Perp());
63  hisde->Fill(hit->GetEnergyLoss());
64 
65  detname = hit->GetDetName();
66  thetadeg = vecs.Theta()*TMath::RadToDeg();
67  if(detname .Contains("Disk1")){
68  hisDisk1Theta->Fill(thetadeg);
69  }else if(detname .Contains("Disk2")){
70  hisDisk2Theta->Fill(thetadeg);
71  }else if(detname .Contains("Disk3")){
72  hisDisk3Theta->Fill(thetadeg);
73  }
74  trackno = hit->GetTrackID();
75  hitsontrack[trackno]++;
76  }//end for i (points in event)
77 
78  for(int k=0;k<mc_array->GetEntriesFast();k++){
79  PndMCTrack *mctruth = (PndMCTrack*)mc_array->At(k);
80  vecs=mctruth->GetMomentum();
81  thetadeg = vecs.Theta()*TMath::RadToDeg();
82  histrackrate->Fill(thetadeg,hitsontrack[k],scale);
83  } // end for Tracknumbers
84  }// end for j (events)
85 
86 TCanvas* can1 = new TCanvas("can1","MCHit view in GEM",0,0,800,800);
87 can1->Divide(3,3);
88 
89 can1->cd(1);
90 DrawNice2DHisto(hisxy);
91 
92 can1->cd(2);
93 DrawNice2DHisto(hisrz);
94 
95 can1->cd(3);
96 gPad->SetLogy();
97 hisde->DrawCopy("");
98 
99 can1->cd(4);
100 hisDisk1Theta->Scale(scale,"width");
101 hisDisk1Theta->DrawCopy();
102 
103 can1->cd(5);
104 hisDisk2Theta->Scale(scale,"width");
105 hisDisk2Theta->DrawCopy();
106 
107 can1->cd(6);
108 hisDisk3Theta->Scale(scale,"width");
109 hisDisk3Theta->DrawCopy();
110 
111 can1->cd(7);
112 //histrackrate->Scale(scale,"width");
113 //histrackrate->Draw("colz");
114 DrawNice2DHisto(histrackrate,"",histrackrate->GetMaximum());
115 
116 can1->Print("outAnaGemSim.png");
117 
118 
119 
120 
121  // ----- Finish -------------------------------------------------------
122  timer.Stop();
123  Double_t rtime = timer.RealTime();
124  Double_t ctime = timer.CpuTime();
125  cout << endl << endl;
126  cout << "Macro finished succesfully." << endl;
127  //cout << "Output file is " << outFile << endl;
128  //cout << "Parameter file is " << parFile << endl;
129  cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
130  cout << endl;
131  // ------------------------------------------------------------------------
132 
133  return 0;
134 }
TH1D * hisde
Definition: anaLmdDigi.C:44
Int_t i
Definition: run_full.C:25
#define verbose
int anaGemPointrate(int nEvents=10, bool verbose=false)
DrawNice2DHisto(hisxy)
TString detname
Definition: anasim.C:61
TVector3 GetMomentum() const
Definition: PndMCTrack.h:78
TClonesArray * mc_array
Definition: anaLmdCluster.C:25
TClonesArray * hit_array
TVector3 vecs
Double_t
Int_t nEvents
Definition: hit_dirc.C:11
TStopwatch timer
Definition: hit_dirc.C:51
TFile * f
Definition: bump_analys.C:12
TH2D * hisxy
Definition: anaLmdDigi.C:38
int mcpdg
Double_t ctime
Definition: hit_dirc.C:114
TH2D * hisrz
Definition: anaLmdDigi.C:41
TTree * t
Definition: bump_analys.C:13
PndSdsMCPoint * hit
Definition: anasim.C:70
TCanvas * can1
Double_t rtime
Definition: hit_dirc.C:113