FairRoot/PandaRoot
anaLmdReco.C
Go to the documentation of this file.
1 /*
2  * anaLmdReco.C * * Created on: Jun 30, 2010 * Author: huagen
3  */
4 
5 //*********************************************
6 // definition of Luminosity Monitor Detector
7 // the dimension of the LMD is 2cm*5.33cm*5cm*150um
8 // totally 16 wafers distrited on 4 planes
9 // 4 wafers located at up, down, left , right on each plane
10 //*************************************************************
11 
12 {
13 // int nEvents = 2e4;
14  bool verbose = false;
15 
16  // ----- Load libraries ------------------------------------------------
17  gROOT->Macro("$VMCWORKDIR/gconfig/rootlogon.C");
18 // gROOT->Macro("Libs.C");
19 
20  // ----- Timer --------------------------------------------------------
21  TStopwatch timer;
22  timer.Start();
23 
24  TFile* f = new TFile("/private/huagen/simdata/Lmd_Reco_DPM_elastic_6.2_1.9mrad_5M_2.root"); // the sim file
25 // TFile* f = new TFile("/private/huagen/simdata/Lmd_Test_Reco.root");
26  TTree *t=(TTree *) f->Get("pndsim") ;
27  TClonesArray* hit_array=new TClonesArray("PndSdsHit");
28  t->SetBranchAddress("LMDHitsStrip",&hit_array);//Branch names
29 
30 // TFile* F = new TFile("/private/huagen/simdata/Lmd_Test.root"); // the sim file
31  TFile* F = new TFile("/private/huagen/simdata/Lmd_DPM_elastic_6.2_1.9mrad_5M_2.root");
32  TTree *T=(TTree *) F->Get("pndsim") ;
33  TClonesArray* mc_array=new TClonesArray("PndSdsMCPoint");
34  T->SetBranchAddress("LMDPoint",&mc_array);//Branch names
35 /*
36  TFile* digi = new TFile("/private/huagen/simdata/Lmd_Digi_DPM_elastic_6.2_2.72mrad_1M.root"); // the sim file
37  TTree *Tdigi=(TTree *) digi->Get("pndsim") ;
38  TClonesArray* digi_array=new TClonesArray("PndSdsDigiStrip");
39  Tdigi->SetBranchAddress("LMDStripDigis",&digi_array);//Branch names
40 */
41  TH3F *h2 = new TH3F("c2","Reconstructed Points", 200, -10, 10, 100, -10, 10, 100, 1070,1150);
42  h2->SetFillColor(kRed);
43  TH3F *h3 = new TH3F("c3","MC Points", 200, -10, 10, 100, -10, 10, 100, 1070,1150);
44  h3->SetFillColor(kRed);
45 
46  TH2D* hisxy = new TH2D("hisxy","",200,-10.,10.,200,-10.,10.);
47  hisxy->SetTitle("LMD Reconstructed points, xy view;x / cm;y / cm");
48  TH2D* hisrz = new TH2D("hisrz","",800,1070.,1150.,100,-10.,10.);
49  hisrz->SetTitle("LMD Reconstructed points, rz view;z / cm;r/ cm");
50 
51  //MC point: xy view and rz view
52  TH2D* mchisxy = new TH2D("mchisxy","",200,-10.,10.,200,-10.,10.);
53  mchisxy->SetTitle("LMD MC points, xy view;x / cm;y / cm");
54  TH2D* mchisrz = new TH2D("mchisrz","",800,1070.,1150.,100,-10.,10.);
55  mchisrz->SetTitle("LMD MC points, rz view;z / cm;r/ cm");
56 
57  TH2D* hisDiffXY = new TH2D("hisdiffxy","",100,-0.05,0.05,100,-0.05,0.05);
58  hisDiffXY->SetTitle("MC - RECO Hit coordinates xy view;#Deltax / cm;#Deltay / cm");
59  TH2D* hisDiffRZ = new TH2D("hisdiffrz","",100,-0.1.,0.1.,100,-0.05,0.05);
60  hisDiffRZ->SetTitle("MC - RECO Hit coordinates rz view;#Deltaz / cm;#Deltar / cm");
61 
62  TH1F* hisDiffX = new TH1F("hisdiffx","",400,-0.02.,0.02.);
63  hisDiffX->SetTitle("MC - RECO Hit coordinate x;x / cm;");
64  TH1F* hisDiffY = new TH1F("hisdiffy","",400,-0.02.,0.02);
65  hisDiffY->SetTitle("MC - RECO Hit coordinate y;y / cm;");
66  TH1F* hisDiffZ = new TH1F("hisdiffz","",400,-0.02,0.02);
67  hisDiffZ->SetTitle("MC - RECO Hit coordinate z;z / cm;");
68 
69  TH1D* RecoCharge = new TH1D("RecoCharge","",200,0.,1000);
70  TH1D* DigiCharge = new TH1D("DigiCharge","",200,0.,1000);
71  TH1D* MCCharge = new TH1D("MCCharge","",200,0.,1000);
72 
73  TVector3 vecs, vecmc, vecdiif;
74  double mcX=0,mcY=0,mcZ=0;
75  double reX=0,reY=0,reZ=0;
76  double diffX=0,diffY=0,diffZ=0;
78 
79  for (Int_t j=0; j<t->GetEntriesFast(); j++)
80  {
81  t->GetEntry(j);
82  T->GetEntry(j);
83  // Tdigi->GetEntry(j);
84  // if(verbose)
85  if(j%1000==0)
86  cout<<"**************Event No************ "<<j<<endl;
87  // cout<<"The Digis of this event is "<<digi_array->GetEntriesFast()<<endl;
88  for (Int_t i=0; i<hit_array->GetEntriesFast(); i++)
89  {
90  // cout<<"Point No "<<i<<endl;
91 
92  if(hit_array->GetEntriesFast()!= mc_array->GetEntriesFast())continue;
93  PndSdsHit *hit=(PndSdsHit*)hit_array->At(i);
94  PndSdsMCPoint *point=(PndSdsMCPoint*)mc_array->At(i);
95  Int_t ID_hit = hit.GetSensorID();
96  Int_t ID_mc = point.GetSensorID();
97  if(hit_array->GetEntriesFast()!= mc_array->GetEntriesFast())continue;
98 /*
99  for(Int_t k=0;k<mc_array->GetEntriesFast();k++){
100  PndSdsMCPoint *mcpoint=(PndSdsMCPoint*)mc_array->At(k);
101  if (ID_hit == ID_mc)
102  { point=mcpoint;
103  cout<<"*********correspongding det name in MC is "<<ID_mc<<endl;
104  }
105  }
106 */
107  int mcpdg = -1;
108  mcX = (point->GetPosition().X()+point->GetPositionOut().X())/2;
109  mcY = (point->GetPosition().Y()+point->GetPositionOut().Y())/2;
110  mcZ = (point->GetPosition().Z()+point->GetPositionOut().Z())/2;
111 
112 // mcX = point->GetPosition().X();//+point->GetPositionOut().X())/2;
113 // mcY = point->GetPosition().Y();//+point->GetPositionOut().Y())/2;
114 // mcZ = point->GetPosition().Z();//+point->GetPositionOut().Z())/2;
115  RecoPosition = hit->GetPosition();
116  MCposition.SetXYZ(mcX,mcY,mcZ);
117 // MCposition = point->GetPosition();
118  vecdiff = MCposition - RecoPosition;
119 
120  // Int_t layer = Int_t(10.*RecoPosition->Mag());
121  RecoCharge->Fill(hit->GetEloss()*1000000);
122  MCCharge->Fill(point->GetEnergyLoss()*1000000);
123 
124  // Int_t count=0;
125  // for(Int_t i=0;i<digi_array->GetEntriesFast();i++){
126  // PndSdsDigiStrip *digis = (PndSdsDigiStrip*)digi_array->At(i);
127  // Int_t FE=digis->GetFE();
128  // cout<<"the FE is:"<<FE<<endl;
129  // if(FE>10)count++;
130  // cout<<"the number of digis on backside is: "<<count<<endl;}
131  // if(count==2){
132 
133  h2->Fill(RecoPosition.x(),RecoPosition.y(),RecoPosition.z());
134  h3->Fill(MCposition.x(),MCposition.y(),MCposition.z());
135 
136  hisxy->Fill(RecoPosition.x(),RecoPosition.y());
137  mchisxy->Fill(mcX,mcY);
138  int vz=1; if(RecoPosition.y()<0) vz=-1;
139  hisrz->Fill(RecoPosition.z(),vz*RecoPosition.Perp());
140  mchisrz->Fill(MCposition.z(),vz*MCposition.Perp());
141  // cout<<RecoPosition.Perp()<<endl;
142  hisDiffXY->Fill(vecdiff.x(),vecdiff.y());
143  hisDiffRZ->Fill(vecdiff.z(),vecdiff.Perp());
144  hisDiffX->Fill(vecdiff.x());
145  hisDiffY->Fill(vecdiff.y());
146  hisDiffZ->Fill(vecdiff.z());
147 
148  // }//end for i (points in event)
149  // } loop with digi
150  } //loop digis == 3
151  }// end for j (events)
152 
153 TCanvas* can1 = new TCanvas("LmdTestPlot","MCHit view in LMD",0,0,800,800);
154  can1->Divide(3,3);
155  gStyle->SetOptFit();
157 
158  TF1 *g1 = new TF1("g1","gaus",-0.004,0.003);
159  TF1 *g2 = new TF1("g2","gaus",-0.006,0.006);
160  TF1 *total = new TF1("total","gaus(0)+gaus(3)",-0.03,0.03);
161 
162  total->SetLineColor(kRed);
163  total->SetLineWidth(1);
164  g1->SetLineWidth(1);
165  g2->SetLineWidth(1);
166 
167 can1->cd(1);
168 hisxy->DrawCopy();
169 can1->cd(2);
170 hisrz->DrawCopy();
171 
172 can1->cd(4);
173 mchisxy->DrawCopy();
174 //hisDiffXY->DrawCopy("col");
175 can1->cd(5);
176 //hisDiffRZ->DrawCopy("col");
177 mchisrz->DrawCopy();
178 
179 can1->cd(7);
180 hisDiffX->DrawCopy("");
181 //hisDiffX->Fit("gaus");
183 can1->cd(8);
184 hisDiffY->DrawCopy("");
185 can1->cd(9);
186 hisDiffZ->DrawCopy("");
187 
188 can2 = new TCanvas("can2","xy-difference",0,0,600,900);
189 can2->Divide(1,2);
190 can2->cd(1);
191 hisDiffX->DrawCopy();
192 can2->cd(2);
193 hisDiffY->Fit(g1,"R");
194 hisDiffY->Fit(g2,"R+");
195 g1->GetParameters(&par[0]);
196 g2->GetParameters(&par[3]);
197 total->SetParameters(par);
198 //hisDiffY->Fit(total,"R");//"R+"
199 hisDiffY->Fit("gaus");
200 hisDiffY->DrawCopy();
201 //hisDiffY->Fit("gaus");
202 
203 TCanvas* can4 = new TCanvas("MC_Digi_Reco_Charge","Charge",0,0,600,900);
204  can4->Divide(1,2);
205 gStyle->SetOptFit();
206 can4->cd(1);
207 RecoCharge->DrawCopy();
208 can4->cd(2);
209 MCCharge->DrawCopy();
210 
211 TCanvas* can5 = new TCanvas("MC_Reco_hits","Hits",0,0,600,900);
212  can5->Divide(1,2);
213 gStyle->SetOptFit();
214 can5->cd(1);
215 h2->DrawCopy();
216 can5->cd(2);
217 h3->DrawCopy();
218 
219  // ----- Finish -------------------------------------------------------
220  timer.Stop();
221  Double_t rtime = timer.RealTime();
222  Double_t ctime = timer.CpuTime();
223  cout << endl << endl;
224  cout << "Macro finished succesfully." << endl;
225  cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
226  cout << endl;
227  // ------------------------------------------------------------------------
228 
229 }
230 
231 
TH1D * DigiCharge
Definition: anaLmdReco.C:70
TVector3 vecmc
Definition: anaLmdReco.C:73
TVector3 MCposition
Definition: anaLmdReco.C:77
double mcY
Definition: anaLmdReco.C:74
TH2D * hisDiffXY
Definition: anaLmdReco.C:57
Int_t i
Definition: run_full.C:25
TVector3 GetPosition() const
Definition: PndSdsHit.h:93
TH1F * hisDiffX
Definition: anaLmdReco.C:62
TF1 * total
Definition: anaLmdReco.C:160
#define verbose
TH3F * h2
Definition: anaLmdReco.C:41
double diffX
Definition: anaLmdReco.C:76
TVector3 vecs
Definition: anaLmdReco.C:73
TCanvas * can1
Definition: anaLmdReco.C:153
TH2D * mchisrz
Definition: anaLmdReco.C:54
TFile * f
Definition: anaLmdReco.C:24
double mcZ
Definition: anaLmdReco.C:74
TVector3 GetPositionOut() const
Definition: PndSdsMCPoint.h:91
TCanvas * can4
Definition: anaLmdReco.C:203
Double_t GetEloss() const
Definition: PndSdsHit.h:97
TH1F * hisDiffZ
Definition: anaLmdReco.C:66
can2
Definition: anaLmdReco.C:188
Int_t GetSensorID() const
Definition: PndSdsMCPoint.h:89
double reZ
Definition: anaLmdReco.C:75
TStopwatch timer
Definition: anaLmdReco.C:21
double mcX
Definition: anaLmdReco.C:74
TH3F * h3
Definition: anaLmdReco.C:43
TH2D * hisDiffRZ
Definition: anaLmdReco.C:59
TTree * T
Definition: anaLmdReco.C:32
double diffZ
Definition: anaLmdReco.C:76
TCanvas * can5
Definition: anaLmdReco.C:211
Double_t ctime
Definition: anaLmdReco.C:222
Double_t
TFile * F
Definition: anaLmdReco.C:31
TClonesArray * point
Definition: anaLmdDigi.C:29
TVector3 RecoPosition
Definition: anaLmdReco.C:77
double reY
Definition: anaLmdReco.C:75
TF1 * g2
Definition: anaLmdReco.C:159
TH2D * hisrz
Definition: anaLmdReco.C:48
double diffY
Definition: anaLmdReco.C:76
TClonesArray * mc_array
Definition: anaLmdReco.C:33
int mcpdg
TTree * t
Definition: anaLmdReco.C:26
TVector3 GetPosition() const
Definition: PndSdsMCPoint.h:90
TH2D * hisxy
Definition: anaLmdReco.C:46
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
TH1D * RecoCharge
Definition: anaLmdReco.C:69
TClonesArray * hit_array
Definition: anaLmdReco.C:27
TF1 * g1
Definition: anaLmdReco.C:158
Double_t par[6]
Definition: anaLmdReco.C:156
TVector3 vecdiif
Definition: anaLmdReco.C:73
TH1F * hisDiffY
Definition: anaLmdReco.C:64
Int_t GetSensorID() const
Definition: PndSdsHit.h:90
TH1D * MCCharge
Definition: anaLmdReco.C:71
TH2D * mchisxy
Definition: anaLmdReco.C:52
TVector3 vecdiff
Definition: anaLmdReco.C:77
double reX
Definition: anaLmdReco.C:75
Double_t rtime
Definition: anaLmdReco.C:221