FairRoot/PandaRoot
anasim.C
Go to the documentation of this file.
1 // root macro to analyze the simulation output
2 //void convertMCPoints()
3 {
4 
5  // ----- Load libraries ------------------------------------------------
6 //``gSystem->Load("fstream.h");
7  gROOT->Macro("../Libs.C");
8  gROOT->LoadMacro("../Tools.C");
10  // ----- Timer --------------------------------------------------------
11  TStopwatch timer;
12  timer.Start();
13  // ------------------------------------------------------------------------
14 /*
15 Convert PndMvdWaferMCPoints to the STAR Format (text, "x y z layer")
16 for the conformal mapping stuff
17 */
18 
19 // PndFileNameCreator namecreator("../data/mvddpm6GeV.root");
20  PndFileNameCreator namecreator("../data/mvdStrip.root");
21  std::string inFile = namecreator.GetSimFileName(false);
23  picture.ReplaceAll(".root",".ps");
24 
25  TFile* f = new TFile(inFile.c_str()); // the sim file you want to analyse
26  TTree *t=(TTree *) f->Get("pndsim") ;
27  TClonesArray* hit_array=new TClonesArray("PndSdsMCPoint");
28  t->SetBranchAddress("MVDPoint",&hit_array);//Branch names
29 
30  TClonesArray* mc_array=new TClonesArray("PndMCTrack");
31  t->SetBranchAddress("MCTrack",&mc_array);//Branch names
32 
33  TGeoManager *geoMan = (TGeoManager*) gDirectory->Get("FAIRGeom");
35 
36  // histos
37  TH2D* hisxy = new TH2D("hisxy","MVD MC Points, xy view",200,-15.,15.,200,-15.,15.);
38  TH2D* hisrz = new TH2D("hisrz","MVD MC Points, rz view",200,-20.,20.,200,-15.,25.);
39  TH1D* hisde = new TH1D("hisde","MVD MC Points, Energyloss",200,0.,0.002);
40 
41 // TH2D* hisdedx = new TH2D("hisdedx","MVD MC Points, dE/dx",200,0.,1.,200,0.,0.002);
42  TH2D* hisdedx =new TH2D("hisdedx","",200,0.,0.4,200,0.,1.0);
43  hisdedx->SetTitle("MVD MC Points, dE/dx(P);p/GeV / cm;dE/dx / (GeV/cm)");
44 
45 
46 
47  TH1D* hismom = new TH1D("hismom","MVD MC Points, momentum",100,0.,1.5);
48  TH2D* hisLocalXY = new TH2D("hisLocalxy","",100,-5.,5.,100,-5.,5.);
49  hisLocalXY->SetTitle("Local Hit XY;x_{L} / cm;y_{L} / cm");
50  TH1D* hisLocalZ = new TH1D("localz","",100,-0.005, 0.005);
51  hisLocalZ->SetTitle("Locel MC Hit Z;z / cm");
52 
53  int nEvents = 1000;
54  bool verbose = false;
55 
56  TVector3 vecs,veco;
57  TVector3 vecFront,vecBack,vecP;
60  TGeoHMatrix* currentTransMat;
62 
63  for (Int_t j=0; j<nEvents && j<t->GetEntriesFast(); j++)
64  {
65  t->GetEntry(j);
66  if( verbose || 0 == j%1000 ) cout<<"Event No "<<j<<endl;
67  for (Int_t i=0; i<hit_array->GetEntriesFast(); i++)
68  {
69  if(verbose) cout<<"Point No "<<i<<endl;
70  PndSdsMCPoint *hit=(PndSdsMCPoint*)hit_array->At(i);
71  int mcpdg = -1;
72 
73  //PndMCTrack *mctruth = (PndMCTrack*)mc_array->At(hit->GetTrackID());
74  //mcpdg = mctruth->GetPdgCode();
75  //cout<<"mcpdg="<<mcpdg<<endl;
76 
77  vecs.SetXYZ(hit->GetX(), hit->GetY(), hit->GetZ());
78  veco.SetXYZ(hit->GetXOut(),hit->GetYOut(),hit->GetZOut());
79  vecP.SetXYZ(hit->GetPx(),hit->GetPy(),hit->GetPz());
80  dx=(veco-vecs).Mag();
81  dE=hit->GetEnergyLoss();
82  p=vecP.Mag();
83  Int_t layer = Int_t(10.*vecs->Mag());
84  if(verbose) cout<<vecs.x()<<"\t"<<vecs.y()<<"\t"<<vecs.z()<<endl;
85 
86  hisxy->Fill(vecs.x(),vecs.y());
87  hisrz->Fill(vecs.z(),((vecs.y()>0.)?1.:-1.)*vecs.Perp());
88  hisde->Fill(dE);
89  hismom->Fill(p);
90 
91  if(dx!=0)
92  {
93  dEdX=(dE/dx);
94  hisdedx->Fill(p,dEdX);
95  }
96 
97  detname = fGeoH->GetPath( hit->GetDetName());
98  geoMan->cd( detname.Data() );
99  currentTransMat = geoMan->GetCurrentMatrix();
100  tmpMaster[0]=0.5*(veco.x()+vecs.x());
101  tmpMaster[1]=0.5*(veco.y()+vecs.y());
102  tmpMaster[2]=0.5*(veco.z()+vecs.z());
103  currentTransMat->MasterToLocal(tmpMaster,tmpLocal);
104  vecs.SetXYZ(tmpLocal[0],tmpLocal[1],tmpLocal[2]);
105  hisLocalXY->Fill(vecs.x(),vecs.y());
106  hisLocalZ->Fill(vecs.z());
107 
108  }//end for i (points in event)
109  }// end for j (events)
110 
111 TCanvas* can1 = new TCanvas("can1","MCHit view in MVD",0,0,800,800);
112 can1->Divide(3,3);
113 can1->cd(1);
114 DrawNice2DHisto(hisxy);
115 can1->cd(2);
116 DrawNice2DHisto(hisrz);
117 can1->cd(3);
118 gPad->SetLogy();
119 hisde->DrawCopy("");
120 can1->cd(4);
121 DrawNice2DHisto(hisdedx);
122 can1->cd(5);
123 DrawNice2DHisto(hisLocalXY);
124 can1->cd(6);
125 hisLocalZ->DrawCopy("");
126 can1->cd(7);
127 hismom->DrawCopy("");
128 
129 
130 can1->Print(picture.Data());
131 
132 
133 
134 
135  // ----- Finish -------------------------------------------------------
136  timer.Stop();
137  Double_t rtime = timer.RealTime();
138  Double_t ctime = timer.CpuTime();
139  cout << endl << endl;
140  cout << "Macro finished succesfully." << endl;
141  //cout << "Output file is " << outFile << endl;
142  //cout << "Parameter file is " << parFile << endl;
143  cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
144  cout << endl;
145  // ------------------------------------------------------------------------
146 
147 }
Double_t p
Definition: anasim.C:58
Double_t GetXOut() const
Definition: PndSdsMCPoint.h:81
TH2D * hisdedx
Definition: anasim.C:42
TH1D * hisde
Definition: anaLmdDigi.C:44
Int_t i
Definition: run_full.C:25
PndGeoHandling * fGeoH
Definition: anasim.C:34
Double_t GetZOut() const
Definition: PndSdsMCPoint.h:83
#define verbose
TGeoManager * geoMan
DrawNice2DHisto(hisxy)
TString detname
Definition: anasim.C:61
TClonesArray * mc_array
Definition: anaLmdCluster.C:25
std::string GetSimFileName(std::string addon="", bool cut=false)
TString GetPath(Int_t shortID)
for a given shortID the path is returned
TClonesArray * hit_array
Double_t dE
Definition: anasim.C:58
Double_t dEdX
Definition: anasim.C:58
TVector3 vecs
TString inFile
Definition: hit_dirc.C:8
Class to access the naming information of the MVD.
Double_t tmpMaster[3]
Definition: anasim.C:59
TGeoHMatrix * currentTransMat
Definition: anasim.C:60
TVector3 vecFront
Definition: anasim.C:57
A simple class which adds the corresponding file extensions to a given base class.
Double_t
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 picture
Definition: anaMvdDigi.C:21
TVector3 veco
Definition: anaMvdSim.C:33
TH2D * hisxy
Definition: anaLmdDigi.C:38
TVector3 vecP
Definition: anasim.C:57
PndFileNameCreator namecreator("../data/Lars/MvdDtsSim.root")
int mcpdg
Double_t ctime
Definition: hit_dirc.C:114
TH2D * hisrz
Definition: anaLmdDigi.C:41
double dx
Double_t GetYOut() const
Definition: PndSdsMCPoint.h:82
Double_t tmpLocal[3]
Definition: anasim.C:59
Int_t layer
Definition: reco_muo.C:36
TTree * t
Definition: bump_analys.C:13
PndSdsMCPoint * hit
Definition: anasim.C:70
TH1D * hisLocalZ
Definition: anasim.C:50
TCanvas * can1
Double_t rtime
Definition: hit_dirc.C:113
LoadPandaStyle()
TH2D * hisLocalXY
Definition: anaplaneclust.C:76
TVector3 vecBack
Definition: anasim.C:57