FairRoot/PandaRoot
outreadMvdDigi.C
Go to the documentation of this file.
1 // root macro to analyze the clusterization output
2 {
3  int nEvents = 20000;
4  bool verbose = false;
5 
6  // ----- Load libraries ------------------------------------------------
7  gROOT->Macro("$VMCWORKDIR/gconfig/rootlogon.C");
8  gROOT->LoadMacro("../Tools.C");
10 
11  // ----- Timer --------------------------------------------------------
12  TStopwatch timer;
13  timer.Start();
14  // ------------------------------------------------------------------------
15 
16 
17  PndFileNameCreator namecreator("../data/Lars/MvdDtsSim.root");
18  std::string inFile = namecreator.GetSimFileName(false);
19  std::string digiFile = namecreator.GetDigiFileName(false);
20  std::string parfile = "../data/Lars/MvdDtsParams.root";
22  picture.ReplaceAll(".root",".ps");
23 
24  TFile* f = new TFile(inFile.c_str()); // the sim file you want to analyse
25  TTree *t=(TTree *) f->Get("pndsim") ;
26  t->AddFriend("pndsim",digiFile.c_str()); // the digi file
27 
28  TClonesArray* mc_array=new TClonesArray("PndSdsMCPoint");
29  t->SetBranchAddress("MVDPoint",&mc_array);//Branch names
30 
31  TClonesArray* digiStrip_array=new TClonesArray("PndSdsDigiStrip");
32  t->SetBranchAddress("MVDStripDigis",&digiStrip_array);//Branch names
33 
34  TGeoManager *geoMan = (TGeoManager*) gDirectory->Get("FAIRGeom");
35 
36  std::ofstream Outfile("../data/Lars/0999_1001_85.hit",ios_base::app);
37  std::ofstream Outrealfile("../data/Lars/0999_1001_85.real",ios_base::app);
38 
39 
40  // --------- HISTOS ---------
41  TH2D* hisxy = new TH2D("hisxy","",100,-1.1,1.1,100,-1.1,1.1);
42  hisxy->SetTitle("MVD MC Point, xy view;x / cm;y / cm");
43 
44  TH2D* hisrz = new TH2D("hisrz","",100,0.,10.,100,-5.,5.);
45  hisrz->SetTitle("MVD MC Point, rz view;z / cm;r/ cm");
46 
47  TH1D* hisde = new TH1D("hisde","MVD MC Points, Energyloss",100,0.,0.002);
48 
49  TH1D* hismom = new TH1D("hismom","MVD MC Points, momentum",100,0.,1.5);
50 
51  int n = 100; int low = 0;
52 
53  TH2I* hisStripTop = new TH2I("hisstriptop","Strip Top channel&fe numbers",5,0,4,130,0,130);
54 
55  TH2I* hisStripBot = new TH2I("hisstripbot","Strip Bot channel&fe numbers",5,0,4,130,0,130);
56 
57  TH1I* hisStripStrip = new TH1I("hisstripstrip","Strip numbers",3*128,0,3*128);
58 
59  TH1D* hisStripCharge = new TH1D("hisstripcharge","Strip Charge content",100,0.,1e5);
60 
61  TH1D* hisStripChargeTop = new TH1D("hisstripchargetop","Strip Charge content",100,0.,1e5);
62  hisStripChargeTop->SetLineColor(kBlue);
63 
64  TH1D* hisStripChargeBot = new TH1D("hisstripchargebot","Strip Charge content",100,0.,1e5);
65  hisStripChargeBot->SetLineColor(kRed);
66  // --------- HISTOS ---------
67 
68 
69  TVector3 vecmc, mommc;
71  TVector2 locals, localmc, localdiff;
72  int col, row, fe;
73  double x,y;
74 
75  TFile* parDB = new TFile(parfile.c_str());
76  PndMvdStripDigiPar* par = (PndMvdStripDigiPar*)gROOT->FindObject("MVDStripDigiParRect");
77 
78  int nrFeChannels=par->GetNrFECh();
79  int nrStrips=par->GetNrTopFE()*nrFeChannels;
80 
81  int evID=0;
82  for (Int_t j=0; j<nEvents && j<t->GetEntriesFast(); j++)
83  {
84  evID++;
85  t->GetEntry(j);
86  if(verbose) cout<<"Event No "<<j<<endl;
87 
88  double x,y,z,Eloss;
89 
90  // ----- MC Points -----
91  for (Int_t i=0; i<mc_array->GetEntriesFast(); i++)
92  {
93  if(verbose) cout<<"Point No "<<i<<endl;
94  PndSdsMCPoint *point=(PndSdsMCPoint*)mc_array->At(i);
95  vecmc = 0.5*(point->GetPosition() + point->GetPositionOut());
96 // vecmc.SetXYZ(point->GetX(),point->GetY(),point->GetZ());
97  mommc.SetXYZ(point->GetPx(),point->GetPy(),point->GetPz());
98  hisxy->Fill(vecmc.x(),vecmc.y());
99  if(vecmc.y() > 0.) hisrz->Fill(vecmc.z(),vecmc.Perp());
100  else hisrz->Fill(vecmc.z(),-1.*vecmc.Perp());
101  hisde->Fill(point->GetEnergyLoss());
102  hismom->Fill(mommc.Mag());
103  x=point->GetX();
104  y=point->GetY();
105  z=point->GetZ();
106  Eloss=point->GetEnergyLoss();
107  Outrealfile<<evID<<" "<<x<<" "<<y<<" "<<z<<" "<<Eloss<<" "<<point->GetPx()<<" "<<point->GetPy()<<" "<<point->GetPz()<<endl;
108  }
109 
110  // ----- STRIP DIGIS -----
111  if(0==digiStrip_array->GetEntriesFast()) Outfile<<evID<<" "<<0<<" "<<0<<" "<<0.<<endl;
112  for (Int_t i=0; i<digiStrip_array->GetEntriesFast(); i++)
113  {
114  PndSdsDigiStrip *stripdigi = digiStrip_array->At(i);
115  fe = stripdigi->GetFE();
116  col = stripdigi->GetChannel();
117  int strip = fe * nrFeChannels + col;
118  hisStripStrip->Fill(strip);
119  hisStripCharge->Fill(stripdigi->GetCharge());
120  if (strip <= nrStrips)
121  {
122  hisStripTop->Fill(fe,col);
123  hisStripChargeTop->Fill(stripdigi->GetCharge());
124  } else {
125  hisStripBot->Fill(fe,col);
126  hisStripChargeBot->Fill(stripdigi->GetCharge());
127  }
128  Outfile<<evID<<" "<<fe<<" "<<col<<" "<<stripdigi->GetCharge()<<endl;
129  }
130  }// end for j (events)
131 
132 Int_t a = 2, b = 2;
133 Outrealfile.close();
134 Outfile.close();
135 TCanvas* can1 = new TCanvas("MvdTestPlot","MCHit view in MVD",0,0,a*400,b*400);
136 can1->Divide(a,b);
137 TPad* mypad=0;
138 
139 can1->cd(1);
140 mypad=gPad;
141 mypad.Divide(2,2);
142 mypad->cd(1);DrawNice2DHisto(hisxy);
143 mypad->cd(2);DrawNice2DHisto(hisrz);
144 mypad->cd(3);gPad->SetLogy();hisde->DrawCopy();
145 mypad->cd(4);hismom->DrawCopy();
146 
147 can1->cd(3);
148 mypad=gPad;
149 mypad.Divide(2,2);
150 mypad->cd(1);DrawNice2DHisto(hisStripTop);
151 mypad->cd(2);DrawNice2DHisto(hisStripBot);
152 mypad->cd(3);hisStripStrip->DrawCopy();
153 mypad->cd(4);hisStripCharge->DrawCopy();
154 hisStripChargeTop->DrawCopy("sames");
155 hisStripChargeBot->DrawCopy("sames");
156 can1->Update();mypad=(TPad*)gPad; BetterStatBox(mypad);
157 
158 can1->cd(4);
159 mypad=gPad;
160 mypad.Divide(2,2);
161 mypad->cd(1);
162 mypad->cd(2);
163 mypad->cd(3);
164 mypad->cd(4);
165 
166 // can1->Update();
167 //can1->Print(picture.Data());
168 
169 
170  // ----- Finish -------------------------------------------------------
171  timer.Stop();
172  Double_t rtime = timer.RealTime();
173  Double_t ctime = timer.CpuTime();
174  cout << endl << endl;
175  cout << "Macro finished succesfully." << endl;
176  cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
177  cout << endl;
178  // ------------------------------------------------------------------------
179 
180 }
double y
TClonesArray * digiStrip_array
std::string parfile
TString picture
TVector3 mommc
int low
Int_t i
Definition: run_full.C:25
Int_t a
TH1D * hismom
TH1D * hisStripChargeBot
Class for digitised strip hits.
std::string GetDigiFileName(std::string addon="", bool cut=false)
TPad * mypad
Double_t ctime
TGeoManager * geoMan
Double_t GetCharge() const
Definition: PndSdsDigi.h:60
LoadPandaStyle()
std::ofstream Outrealfile("../data/Lars/0999_1001_85.real", ios_base::app)
TVector3 GetPositionOut() const
Definition: PndSdsMCPoint.h:91
Double_t tmpz
std::string inFile
Int_t GetFE() const
Definition: PndSdsDigi.h:57
bool verbose
Definition: outreadMvdDigi.C:4
std::string GetSimFileName(std::string addon="", bool cut=false)
double x
PndFileNameCreator namecreator("../data/Lars/MvdDtsSim.root")
TH1D * hisde
TH1I * hisStripStrip
int nrFeChannels
std::ofstream Outfile("../data/Lars/0999_1001_85.hit", ios_base::app)
Double_t rtime
TH2D * hisxy
TVector2 localmc
A simple class which adds the corresponding file extensions to a given base class.
TStopwatch timer
Double_t
int col
Int_t nEvents
Definition: hit_dirc.C:11
Double_t tmpy
TClonesArray * point
Definition: anaLmdDigi.C:29
TVector2 localdiff
int evID
std::string digiFile
Double_t tmpx
TClonesArray * mc_array
int nrStrips
Double_t z
TVector3 vecmc
int fe
TFile * parDB
TH1D * hisStripChargeTop
TVector3 GetPosition() const
Definition: PndSdsMCPoint.h:90
TH2D * hisrz
TVector2 locals
PndMvdStripDigiPar * par
Int_t b
DrawNice2DHisto(hisxy)
TH2I * hisStripBot
Int_t GetChannel() const
int n
int row
TCanvas * can1
BetterStatBox(mypad)
TH1D * hisStripCharge
TFile * f
TTree * t
TH2I * hisStripTop