FairRoot/PandaRoot
QAmacro_mvd_ana.C
Go to the documentation of this file.
1 // root macro to analyze the clusterization output
2 //#include "../../run/Tools.C"
3 
4 #include "../auxi.C"
6 {
7  cout << "QA Analysis module for the MVD - Hit resolution check." << endl;
8 
9  TString inFile = "mvdqasim.root";
10  TString recoFile = "mvdqarec.root";
11  TString parFile = "mvdqapar.root";
12 
13  Int_t nEvents = 100;
14  Bool_t verbose = kTRUE;
15  Bool_t isSuccessful = kFALSE;
16  Bool_t test1=kTRUE, test2=kTRUE, test3=kTRUE;
17 
18 // cout << "$VMCWORKDIR" << endl;
19 // gROOT->LoadMacro("$VMCWORKDIR/macro/run/Tools.C");
20 // LoadPandaStyle();
21 
22  // ----- Timer --------------------------------------------------------
23  TStopwatch timer;
24  timer.Start();
25  // ------------------------------------------------------------------------
26 
27  // ----- Get Data from framework --------------------------------------
28  // load first the file with the GeoManager
30  picture.ReplaceAll(".root",".png");
31 
32  TFile* f = new TFile(inFile.Data()); // the sim file you want to analyse
33  TTree* t=(TTree*)f->Get("pndsim");
34  t->AddFriend("pndsim",recoFile.Data()); // the reco file you want to analyse
35  TFile* dbfile = new TFile(parFile.Data());
36 
37  PndGeoHandling* fGeoH = new PndGeoHandling(inFile,parFile);
38 
39  if (!gGeoManager) {
40  dbfile->Get("FairBaseParSet");
42  if(!gGeoManager) {
43  dbfile->Get("FairGeoParSet");
44  if(!gGeoManager) {
45  std::cout<<"Could not find valid GeoManager. Abort now!"<<std::endl;
46  return 1;
47  }
48  }
49  }
50 
51  TClonesArray* mc_array=new TClonesArray("PndSdsMCPoint");
52  t->SetBranchAddress("MVDPoint",&mc_array);//Branch names
53 
54  TClonesArray* digiPixel_array=new TClonesArray("PndSdsDigiPixel");
55  t->SetBranchAddress("MVDPixelDigis",&digiPixel_array);//Branch names
56 
57  TClonesArray* digiStrip_array=new TClonesArray("PndSdsDigiStrip");
58  t->SetBranchAddress("MVDStripDigis",&digiStrip_array);//Branch names
59 
60  TClonesArray* strhit_array=new TClonesArray("PndSdsHit");
61  t->SetBranchAddress("MVDHitsStrip",&strhit_array);//Branch names
62 
63  TClonesArray* pixhit_array=new TClonesArray("PndSdsHit");
64  t->SetBranchAddress("MVDHitsPixel",&pixhit_array);//Branch names
65 
66  if(!fGeoH){
67  std::cout<<"No MvdGeoHandling existant. Abort now!"<<std::endl;
68  return 1;
69  }
70  fGeoH->FillSensorMap();
71 // fGeoH->PrintSensorNames();
72 
73 // FairEventHeader* header = new FairEventHeader();
74 // t->SetBranchAddress("EventHeader.", &header);
75 // t->GetEntry(0);
76 //
77 // Int_t runId = header->GetRunId();
78 
79 
80 
81  TH1D* hisDiff = new TH1D("diff","",100,-0.008,0.008);
82  hisDiff->SetTitle("MVD Hit Resolution (double gaussian fit);#Deltax / cm;");
83 
84  double angmax = 0.02;
85  TH1D* hisDiffTheta = new TH1D("DiffTheta","",100,-angmax,angmax);
86  hisDiffTheta->SetTitle("#Theta resolution;#Delta#Theta/mrad;");
87 
88  TH1D* hisDiffPhi = new TH1D("DiffPhi","",100,-angmax,angmax);
89  hisDiffPhi->SetTitle("#Phi resolution;#Delta#Phi/mrad;");
90 
91  TVector3 vecs, vecmc, vecdiff, mommc, sensorDim;
93  TVector2 locals, localmc, localdiff;
94  TGeoHMatrix* currentTransMat;
96  Double_t difftheta, diffphi;
97 
98  cout<<" -I- Start Loop"<<endl;
99  for (Int_t j=0; j<nEvents && j<t->GetEntriesFast(); j++)
100  {
101  if(10==j) verbose=kFALSE;
102  t->GetEntry(j);
103  if(verbose) cout<<"Event No "<<j<<endl;
104  else if (!(j%100)) cout <<"Event No "<<j<<endl;
105  if(verbose) std::cout<<"Check sanity of the arrays:"<<std::endl;
106  if(mc_array){
107  if(verbose) std::cout<<"mc_array ok with "<<mc_array->GetEntriesFast()<<" entries"<<std::endl;
108  }
109  else {
110  std::cout<<"*** mc_array broken - check your file! ."<<std::endl;
111  test3=kFALSE;
112  }
113  if(digiPixel_array){
114  if(verbose) std::cout<<"digiPixel_array ok with "<<digiStrip_array->GetEntriesFast()<<" entries"<<std::endl;
115  }
116  else {
117  std::cout<<"*** digiPixel_array broken - check your file! ."<<std::endl;
118  test3=kFALSE;
119  }
120  if(digiStrip_array){
121  if(verbose) std::cout<<"digiStrip_array ok with "<<digiStrip_array->GetEntriesFast()<<" entries"<<std::endl;
122  }
123  else {
124  std::cout<<"*** digiStrip_array broken - check your file! ."<<std::endl;
125  test3=kFALSE;
126  }
127  if(strhit_array){
128  if(verbose) std::cout<<"strhit_array ok with "<<strhit_array->GetEntriesFast()<<" entries"<<std::endl;
129  }
130  else {
131  std::cout<<"*** strhit_array broken - check your file! ."<<std::endl;
132  test3=kFALSE;
133  }
134  if(pixhit_array){
135  if(verbose) std::cout<<"pixhit_array ok with "<<pixhit_array->GetEntriesFast()<<" entries"<<std::endl;
136  }
137  else {
138  std::cout<<"*** pixhit_array broken - check your file! ."<<std::endl;
139  test3=kFALSE;
140  }
141 
142 
143  // ----- PIXEL HITS -----
144  for (Int_t ii=0; ii<pixhit_array->GetEntriesFast(); ii++)
145  {
146 
147  PndSdsHit *hit=(PndSdsHit*)pixhit_array->At(ii);
148  if(verbose) cout <<ii<< ".";
149  detname = fGeoH->GetPath( hit->GetSensorID());
150  gGeoManager->cd( detname.Data() );
151  currentTransMat = gGeoManager->GetCurrentMatrix();
152  vecs.SetXYZ(hit->GetX(), hit->GetY(), hit->GetZ());
153  Int_t mcid = hit->GetRefIndex();
154  if(verbose)cout<<mcid<<" ";
155  if(mcid<0 || mcid >= mc_array->GetEntriesFast()) continue;
156  PndSdsMCPoint *point=(PndSdsMCPoint*)mc_array->At(mcid);
157  Int_t mcpdg = -1;
158 
159  vecmc.SetXYZ( 0.5 * (point->GetX() + point->GetXOut()),
160  0.5 * (point->GetY() + point->GetYOut()),
161  0.5 * (point->GetZ() + point->GetZOut()));
162  vecdiff = vecmc - vecs;
163  difftheta = vecmc.Theta() - vecs.Theta();
164  diffphi = vecmc.Phi() - vecs.Phi();
165  //convert deg to mrad
166  difftheta = difftheta*1000.*TMath::Pi()/180.;
167  diffphi= diffphi*1000.*TMath::Pi()/180.;
168 
169  hisDiffTheta->Fill(difftheta);
170  hisDiffPhi->Fill(diffphi);
171 
172  //--- Now move vectors to the local sensor system
173  tmpMaster[0]=vecs.x();tmpMaster[1]=vecs.y();tmpMaster[2]=vecs.z();
174  currentTransMat->MasterToLocal(tmpMaster,tmpLocal);
175  vecs.SetXYZ(tmpLocal[0],tmpLocal[1],tmpLocal[2]);
176  tmpMaster[0]=vecmc.x();tmpMaster[1]=vecmc.y();tmpMaster[2]=vecmc.z();
177  currentTransMat->MasterToLocal(tmpMaster,tmpLocal);
178  vecmc.SetXYZ(tmpLocal[0],tmpLocal[1],tmpLocal[2]);
179  vecdiff = vecmc - vecs;
180 
181  hisDiff->Fill(vecdiff.X());
182  }//end for ii (pixel hits in event)
183  if(verbose) cout <<endl;
184 
185 
186 
187  // ----- STRIP HITS -----
188  for (Int_t iii=0; iii<strhit_array->GetEntriesFast(); iii++)
189  {
190  PndSdsHit *hit=(PndSdsHit*)strhit_array->At(iii);
191  detname = fGeoH->GetPath( hit->GetSensorID());
192  gGeoManager->cd( detname.Data() );
193  currentTransMat = gGeoManager->GetCurrentMatrix();
194 
195  vecs.SetXYZ(hit->GetX(), hit->GetY(), hit->GetZ());
196 
197  Int_t mcid = hit->GetRefIndex();
198  if(mcid<0 || mcid >= mc_array->GetEntriesFast()) continue;
199  PndSdsMCPoint *point=(PndSdsMCPoint*)mc_array->At(mcid);
200  Int_t mcpdg = -1;
201 
202  vecmc.SetXYZ( 0.5 * (point->GetX() + point->GetXOut()),
203  0.5 * (point->GetY() + point->GetYOut()),
204  0.5 * (point->GetZ() + point->GetZOut()));
205  vecdiff = vecmc - vecs;
206  difftheta = vecmc.Theta() - vecs.Theta();
207  diffphi = vecmc.Phi() - vecs.Phi();
208  //convert deg to mrad
209  difftheta = difftheta*1000.*TMath::Pi()/180.;
210  diffphi= diffphi*1000.*TMath::Pi()/180.;
211 
212  hisDiffTheta->Fill(difftheta);
213  hisDiffPhi->Fill(diffphi);
214 
215  //--- Now move vectors to the local sensor system
216  tmpMaster[0]=vecs.x();tmpMaster[1]=vecs.y();tmpMaster[2]=vecs.z();
217  currentTransMat->MasterToLocal(tmpMaster,tmpLocal);
218  vecs.SetXYZ(tmpLocal[0],tmpLocal[1],tmpLocal[2]);
219  tmpMaster[0]=vecmc.x();tmpMaster[1]=vecmc.y();tmpMaster[2]=vecmc.z();
220  currentTransMat->MasterToLocal(tmpMaster,tmpLocal);
221  vecmc.SetXYZ(tmpLocal[0],tmpLocal[1],tmpLocal[2]);
222  vecdiff = vecmc - vecs;
223 
224  hisDiff->Fill(vecdiff.X());
225  }//end for iii (strip hits in event)
226 
227  }// end for j (events)
228 
229 
231  Int_t pix = 400;
232  Int_t a = 2, b = 2;
233 
234  TCanvas* can1 = new TCanvas("MvdTestPlot","MCHit view in MVD",0,0,a*pix,b*pix);
235  can1->Divide(a,b);
236 
237  TCanvas* can2 = new TCanvas("MvdResPlot","MVD point resolution");
238 
239  can2->cd();
240 
241  Double_t par[6]={0., 0., 0.0005, 0., 0., 0.002};
242  //prefit peak
243  TF1* g2 = new TF1("g2","gaus",-0.002,0.002);
244  hisDiff->Fit(g2,"R");
245  g2->GetParameters(&par[0]);
246  //fit total
247  TF1* total = new TF1("total","gaus(0)+gaus(3)",-0.008,0.008);
248  total->SetParameters(par);
249  total->SetLineColor(4);
250  total->SetLineWidth(2);
251  total->SetLineStyle(7);
252  hisDiff->Fit(total,"R");
253  total->GetParameters(&par[0]);
254 
255  hisDiff->SetMarkerStyle(3);
256  hisDiff->SetMarkerSize(0.4);
257  hisDiff->DrawCopy("pe");
258 
259  // change styling for text
260  gStyle->SetOptTitle(kFALSE);
261  gStyle->SetOptStat(kFALSE);
262 
263  TString str="";
264  std::cout<<" --- Test resolution ---"<<std::endl;
265 
266  Float_t mean1=10000*par[1];
267  Float_t sigma1=10000*par[2];
268  Float_t mean2=10000*par[4];
269  Float_t sigma2=10000*par[5];
270 
271  cout << "<DartMeasurement name=\"mean1\" type=\"numeric/double\">";
272  cout << mean1;
273  cout << "</DartMeasurement>" << endl;
274 
275  str = "Mean_{1} = ";
276  str += (mean1); for (int i=0;i<6;i++) str.Chop();
277  str += " #mum";
278  std::cout<<str.Data()<<" is ";
279  if( fabs(mean1) < 2*sigma1 ){
280  std::cout<<"less";
281  test1=test1 && kTRUE;
282  } else {
283  std::cout<<"MORE";
284  test1=kFALSE;
285  } std::cout<<" than 2 #sigma away from 0"<<std::endl;
286 
287  cout << "<DartMeasurement name=\"mean2\" type=\"numeric/double\">";
288  cout << mean2;
289  cout << "</DartMeasurement>" << endl;
290 
291  str = "Mean_{2} = ";
292  str += (mean2); for (int i=0;i<6;i++) str.Chop();
293  str += " #mum";
294  std::cout<<str.Data()<<" is ";
295  if( fabs(mean2) < 2*sigma2 ){
296  std::cout<<"less";
297  test1=test1 && kTRUE;
298  } else {
299  std::cout<<"MORE";
300  test1=kFALSE;
301  } std::cout<<" than 2 #sigma away from 0"<<std::endl;
302 
303  cout << "<DartMeasurement name=\"sigma1\" type=\"numeric/double\">";
304  cout << sigma1;
305  cout << "</DartMeasurement>" << endl;
306 
307  str = "#sigma_{1} = ";
308  str += (sigma1); for (int i=0;i<6;i++) str.Chop();
309  str += " #mum";
310 // DrawText( 0.2, 0.8, str.Data(),0.05,1);
311  std::cout<< str.Data();
312  if( fabs(sigma1) < 10 ){
313  std::cout<< " Passed a 10um window.";
314  test2=test2 && kTRUE;
315  } else {
316  std::cout<<" Didn't pass a 10um window.";
317  test2=kFALSE;
318  } std::cout<<std::endl;
319 
320  cout << "<DartMeasurement name=\"sigma2\" type=\"numeric/double\">";
321  cout << sigma2;
322  cout << "</DartMeasurement>" << endl;
323 
324  str = "#sigma_{2} = ";
325  str += (sigma2); for (int i=0;i<6;i++) str.Chop();
326  str += " #mum";
327 // DrawText( 0.2, 0.7, str.Data(),0.05,1);
328  std::cout<< str.Data();
329 
330  if( fabs(sigma2) < 100 ){
331  std::cout<< " Passed a 100um window.";
332  test2=test2 && kTRUE;
333  } else {
334  std::cout<<" Didn't pass a 100um window.";
335  test2=kFALSE;
336  } std::cout<<std::endl;
337 
338  // reset styling for pictures
339 // LoadPandaStyle();
340 
341  can2->Print(picture);
342 
343 // can2->Print(picture + "(");
344 // can1->cd(1);
345 // hisDiff->GetXaxis()->SetNdivisions(-05);
346 // hisDiff->DrawCopy("");
347 // can1->Update();mypad=(TPad*)gPad;BetterStatBox(mypad);
348 // can1->cd(3);
349 // hisDiffTheta->GetXaxis()->SetNdivisions(-05);
350 // hisDiffTheta->DrawCopy("");
351 // can1->Update();mypad=(TPad*)gPad;BetterStatBox(mypad);
352 // can1->cd(4);
353 // hisDiffPhi->GetXaxis()->SetNdivisions(-05);
354 // hisDiffPhi->DrawCopy("");
355 // can1->Update();mypad=(TPad*)gPad;BetterStatBox(mypad);
356 // can1->Print(picture + ")");
357 
358 
359  // ----- Finish -------------------------------------------------------
360  timer.Stop();
361  Double_t rtime = timer.RealTime();
362  Double_t ctime = timer.CpuTime();
363  printf("RealTime=%f seconds, CpuTime=%f seconds\n",rtime,ctime);
364  isSuccessful = test1 && test2 && test3;
365  if(isSuccessful){
366  std::cout << " Test passed" << std::endl;
367  std::cout << " All ok " << std::endl;
368  } else {
369  std::cout<<"Something is worong:"<<endl;
370  std::cout<<"Test of Data Arrays: "<< ((test3) ? "ok" : "bad") <<std::endl;
371  std::cout<<"Test of resolution mean: "<< ((test1) ? "ok" : "bad") <<std::endl;
372  std::cout<<"Test of resolution sigma: "<< ((test2) ? "ok" : "bad") <<std::endl;
373  }
374  std::cout<<std::endl;
375  CloseGeoManager();
376  return 0;
377 
378 }
Double_t GetXOut() const
Definition: PndSdsMCPoint.h:81
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
Int_t i
Definition: run_full.C:25
TTree * b
PndGeoHandling * fGeoH
Definition: anasim.C:34
Double_t GetZOut() const
Definition: PndSdsMCPoint.h:83
#define verbose
int QAmacro_mvd_ana()
Double_t par[3]
TString detname
Definition: anasim.C:61
TVector2 localdiff
Definition: anaLmdDigi.C:66
TVector3 mommc
Definition: anaLmdDigi.C:64
TClonesArray * mc_array
Definition: anaLmdCluster.C:25
TF1 * g2
TGeoManager * gGeoManager
void CloseGeoManager()
Definition: QA/auxi.C:11
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
Int_t a
Definition: anaLmdDigi.C:126
TGeoHMatrix * currentTransMat
Definition: anasim.C:60
double mean1
Definition: plot_eta_c.C:104
TVector2 localmc
Definition: anaLmdDigi.C:66
Double_t
TString parFile
Definition: hit_dirc.C:14
double sigma2
Definition: plot_eta_c.C:109
TVector2 locals
Definition: anaLmdDigi.C:66
Int_t nEvents
Definition: hit_dirc.C:11
TStopwatch timer
Definition: hit_dirc.C:51
TFile * f
Definition: bump_analys.C:12
TString picture
Definition: anaMvdDigi.C:21
TF1 * total
TVector3 vecmc
Definition: anaLmdCluster.C:52
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
int mcpdg
Double_t ctime
Definition: hit_dirc.C:114
TClonesArray * digiPixel_array
Definition: anaMvdDigi.C:31
TCanvas * can2
double sigma1
Definition: reco_analys2.C:57
Double_t GetYOut() const
Definition: PndSdsMCPoint.h:82
std::string recoFile
Double_t tmpLocal[3]
Definition: anasim.C:59
TTree * t
Definition: bump_analys.C:13
TClonesArray * digiStrip_array
Definition: anaLmdDigi.C:32
PndSdsMCPoint * hit
Definition: anasim.C:70
TCanvas * can1
Int_t GetSensorID() const
Definition: PndSdsHit.h:90
Double_t rtime
Definition: hit_dirc.C:113
TVector3 vecdiff
Definition: anaLmdReco.C:77
Double_t Pi
PndSdsMCPoint * point
Definition: anaLmdCluster.C:72