FairRoot/PandaRoot
anaMvdSim.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  gROOT->Macro("$VMCWORKDIR/gconfig/rootlogon.C");
7  gROOT->LoadMacro("../Tools.C");
9  // ----- Timer --------------------------------------------------------
10  TStopwatch timer;
11  timer.Start();
12  // ------------------------------------------------------------------------
13 
14  PndFileNameCreator namecreator("../data/Lars/MvdDtsSim.root");
15  std::string inFile = namecreator.GetSimFileName(false);
16 
17  TFile* f = new TFile(inFile.c_str()); // the sim file you want to analyse
18  TTree *t=(TTree *) f->Get("pndsim") ;
19  TClonesArray* hit_array=new TClonesArray("PndSdsMCPoint");
20  t->SetBranchAddress("MVDPoint",&hit_array);//Branch names
21 
22  TClonesArray* mc_array=new TClonesArray("PndMCTrack");
23  t->SetBranchAddress("MCTrack",&mc_array);//Branch names
24 
25  TH2D* hisxy = new TH2D("hisxy","MVD MC Points, xy view",100,-5.,5.,100,-5.,5.);
26  TH2D* hisrz = new TH2D("hisrz","MVD MC Points, rz view",100,-5.,5.,100,-5.,5.);
27  TH1D* hisde = new TH1D("hisde","MVD MC Points, Energyloss",100,0.,0.002);
28 
29 
30  int nEvents = 1000;
31  bool verbose = false;
32 
33  TVector3 vecs,veco;
34 
35  for (Int_t j=0; j<nEvents && j<t->GetEntriesFast(); j++)
36  {
37  t->GetEntry(j);
38  if(verbose) cout<<"Event No "<<j<<endl;
39  for (Int_t i=0; i<hit_array->GetEntriesFast(); i++)
40  {
41  if(verbose) cout<<"Point No "<<i<<endl;
42  PndSdsMCPoint *hit=(PndSdsMCPoint*)hit_array->At(i);
43  int mcpdg = -1;
44 
45  //PndMCTrack *mctruth = (PndMCTrack*)mc_array->At(hit->GetTrackID());
46  //mcpdg = mctruth->GetPdgCode();
47  //cout<<"mcpdg="<<mcpdg<<endl;
48 
49  vecs.SetXYZ(hit->GetX(), hit->GetY(), hit->GetZ());
50  Int_t layer = Int_t(10.*vecs->Mag());
51  if(verbose) cout<<vecs.x()<<"\t"<<vecs.y()<<"\t"<<vecs.z()<<endl;
52 
53  hisxy->Fill(vecs.x(),vecs.y());
54  hisrz->Fill(vecs.z(),((vecs.y()>0.)?1.:-1.)*vecs.Perp());
55  hisde->Fill(hit->GetEnergyLoss());
56  }//end for i (points in event)
57  }// end for j (events)
58 
59 TCanvas* can1 = new TCanvas("can1","MCHit view in MVD",0,0,800,800);
60 can1->Divide(2,2);
61 can1->cd(1);
62 DrawNice2DHisto(hisxy);
63 can1->cd(2);
64 DrawNice2DHisto(hisrz);
65 can1->cd(3);
66 gPad->SetLogy();
67 hisde->DrawCopy("");
68 can1->cd(4);
69 can1->Print("outAnaMvdSim.ps");
70 
71 
72 
73 
74  // ----- Finish -------------------------------------------------------
75  timer.Stop();
76  Double_t rtime = timer.RealTime();
77  Double_t ctime = timer.CpuTime();
78  cout << endl << endl;
79  cout << "Macro finished succesfully." << endl;
80  //cout << "Output file is " << outFile << endl;
81  //cout << "Parameter file is " << parFile << endl;
82  cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
83  cout << endl;
84  // ------------------------------------------------------------------------
85 
86 }
TClonesArray * mc_array
Definition: anaMvdSim.C:22
Double_t ctime
Definition: anaMvdSim.C:77
Int_t i
Definition: run_full.C:25
bool verbose
Definition: anaMvdSim.C:31
TH1D * hisde
Definition: anaMvdSim.C:27
PndFileNameCreator namecreator("../data/Lars/MvdDtsSim.root")
TStopwatch timer
Definition: anaMvdSim.C:10
TTree * t
Definition: anaMvdSim.C:18
TFile * f
Definition: anaMvdSim.C:17
std::string inFile
Definition: anaMvdSim.C:15
Double_t rtime
Definition: anaMvdSim.C:76
std::string GetSimFileName(std::string addon="", bool cut=false)
DrawNice2DHisto(hisxy)
TH2D * hisrz
Definition: anaMvdSim.C:26
A simple class which adds the corresponding file extensions to a given base class.
Double_t
TVector3 vecs
Definition: anaMvdSim.C:33
TVector3 veco
Definition: anaMvdSim.C:33
int mcpdg
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
TClonesArray * hit_array
Definition: anaMvdSim.C:19
LoadPandaStyle()
TH2D * hisxy
Definition: anaMvdSim.C:25
int nEvents
Definition: anaMvdSim.C:30
TCanvas * can1
Definition: anaMvdSim.C:59