FairRoot/PandaRoot
radiation.cxx
Go to the documentation of this file.
1 /*
2  * test_main.cxx
3  *
4  * Created on: Feb 8, 2012
5  * Author: promme
6  */
7 
8 #include<iostream>
9 #include<sstream>
10 #include<string>
11 
12 #include<TString.h>
13 #include<TChain.h>
14 #include<TClonesArray.h>
15 #include<TROOT.h>
16 #include<TVector3.h>
17 #include<TH1.h>
18 #include<TH2.h>
19 #include<TApplication.h>
20 #include<TCanvas.h>
21 
22 #include<FairRadMapPoint.h>
23 
24 #include<PndLmdDim.h>
25 
26 /*
27 #include<TCanvas.h>
28 
29 #include<TFile.h>
30 #include<TSystem.h>
31 
32 #include<TRotation.h>
33 
34 #include<TMath.h>
35 #include<TGaxis.h>
36 
37 #include<TStopwatch.h>
38 
39 #include<PndMCTrack.h>
40 #include<PndSdsMCPoint.h>
41 
42 // needed for geane backtracking
43 #include<FairRunAna.h>
44 #include<FairRootManager.h>
45 #include<FairGeane.h>
46 #include<FairRtdbRun.h>
47 #include<FairRuntimeDb.h>
48 #include<FairParRootFileIo.h>
49 #include<PndLmdPerformanceTask.h>
50 #include<FairLogger.h>
51 
52 */
53 
54 using namespace std;
55 
56 double last_percent(0);
57 
58 void DrawProgressBar(int len, double percent) {
59  if ((int)(last_percent*100) == (int)(percent*100)) return;
60  //cout << " drawing " << endl;
61  cout << "\x1B[2K"; // Erase the entire current line.
62  cout << "\x1B[0E"; // Move to the beginning of the current line.
63  string progress;
64  for (int i = 0; i < len; ++i) {
65  if (i < static_cast<int>(len * percent)) {
66  progress += "=";
67  } else {
68  progress += " ";
69  }
70  }
71  cout << "[" << progress << "] " << (static_cast<int>(100 * percent)) << "%";
72  flush(cout); // Required.
73  last_percent = percent;
74 }
75 
76 int main(int nargs, char** args) {
77  // load first all dictionaries for ROOT in order
78  // to read the files correctly
79  gROOT->Macro("$VMCWORKDIR/gconfig/rootlogon.C");
80  TApplication myapp("myapp",0,0);
81  TString storePath = ".";
82  // set the storepath to somewhere else, if provided
83  if (nargs == 2) {
84  storePath = args[1];
85  } else {
86  if (nargs == 1)
87  cout << " Hint: you may change the standard path from "
88  << storePath.Data()
89  << " to any other folder by providing the path as an argument! "
90  << endl;
91  if (nargs > 2)
92  cout << " Error: too many arguments! " << endl;
93  }
94  TString startEvent = "";
95  // Input file (MC events)
96  TString MCFile = storePath + "/Lumi_MC";
97  MCFile += startEvent;
98  MCFile += ".root";
99  TChain tMC("pndsim");
100  tMC.Add(MCFile);
101 
102  std::cout << "MCFile : " << MCFile.Data() << std::endl;
103 
104  //--- MC info -----------------------------------------------------------------
105  TClonesArray* true_tracks = new TClonesArray("PndMCTrack");
106  tMC.SetBranchAddress("MCTrack", &true_tracks); //True Tracks to compare
107 
108  TClonesArray* true_points = new TClonesArray("PndSdsMCPoint");
109  tMC.SetBranchAddress("LMDPoint", &true_points); //True Points to compare
110 
111  TClonesArray* radmap_points = new TClonesArray("FairRadMapPoint");
112  tMC.SetBranchAddress("RadMap", & radmap_points); // Radiation map points
113 
114  TClonesArray* radlen_points = new TClonesArray("FairRadLenPoint");
115  tMC.SetBranchAddress("RadLen", & radlen_points); // Radiation length points
116  //----------------------------------------------------------------------------------
117 
118  TCanvas canvas_rad_map_x_y("canvas_rad_map_x_y", "radiation map x y", 600, 600);
119  TH2D radiation_map_x_y("radiation_map_x_y", "radiation map x y", 500, 15, 45, 500, -15, 15);
120  radiation_map_x_y.Draw("COLZ");
121  radiation_map_x_y.SetXTitle("X [cm]");
122  radiation_map_x_y.SetYTitle("Y [cm]");
123  radiation_map_x_y.SetZTitle("dose");
124  canvas_rad_map_x_y.SetLogz();
125 
126  TCanvas canvas_rad_map_x_z("canvas_rad_map_x_z", "radiation map x z", 1000, 600);
127  TH2D radiation_map_x_z("radiation_map_x_z", "radiation map x z", 1000, 1100, 1200, 400, 10, 50);
128  radiation_map_x_z.Draw("COLZ");
129  radiation_map_x_z.SetXTitle("Z [cm]");
130  radiation_map_x_z.SetYTitle("X [cm]");
131  radiation_map_x_z.SetZTitle("dose");
132  canvas_rad_map_x_z.SetLogz();
133 
134  TCanvas canvas_rad_map_x_y_plane_0("canvas_rad_map_x_y_plane_0", "radiation map x y of plane 0", 600, 600);
135  TH2D radiation_map_x_y_plane_0("radiation_map_x_y_plane_0", "radiation map x y of plane 0", 150, 10, 40, 150, -15, 15);
136  radiation_map_x_y_plane_0.Draw("COLZ");
137  radiation_map_x_y_plane_0.SetXTitle("X [cm]");
138  radiation_map_x_y_plane_0.SetYTitle("Y [cm]");
139  radiation_map_x_y_plane_0.SetZTitle("dose");
140  canvas_rad_map_x_y_plane_0.SetLogz();
141 
142  // initialize the lmd dimension class
144  lmddim.Read_transformation_matrices("matrices_perfect.txt", false);
145  lmddim.Read_transformation_matrices("matrices.txt", true);
146 
147  int nEvents = tMC.GetEntries();
148  cout << " reading " << nEvents << " Events " << endl;
149  for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
150  DrawProgressBar(50, (iEvent+1)/((double)nEvents));
151  tMC.GetEntry(iEvent);
152 
153  //PndSdsMCPoint* mcpoint = (PndSdsMCPoint*) true_points->At(iHit);
154  int nradmappoints = radmap_points->GetEntriesFast();
155  for (int iradmappoint = 0; iradmappoint < nradmappoints; iradmappoint++){
156  FairRadMapPoint* radmap_point = (FairRadMapPoint*) radmap_points->At(iradmappoint);
157  const TVector3& position = radmap_point->GetPosition();
158  double dose = radmap_point->GetDose();
159 
160  int detID = radmap_point->GetDetectorID();
161 
162  //int ihalf, iplane, imodule, iside, idie, isensor;
163  //lmddim.Get_sensor_by_id(detID, ihalf, iplane, imodule, iside, idie, isensor);
164 
165  //if (iplane == 0) does not work
166  if (dose > 0){
167  if (position.Z() > 1105 && position.Z() < 1130)
168  radiation_map_x_y_plane_0.Fill(position.X(), position.Y(), dose);
169  radiation_map_x_y.Fill(position.X(), position.Y(), dose);
170  radiation_map_x_z.Fill(position.Z(), position.X(), dose);
171  }
172  }
173 
174  if ((iEvent%1000)==0){
175  canvas_rad_map_x_y.cd();
176  radiation_map_x_y.Draw("COLZ");
177  canvas_rad_map_x_y.Update();
178  canvas_rad_map_x_y_plane_0.cd();
179  radiation_map_x_y_plane_0.Draw("COLZ");
180  canvas_rad_map_x_y_plane_0.Update();
181  canvas_rad_map_x_z.cd();
182  radiation_map_x_z.Draw("COLZ");
183  canvas_rad_map_x_z.Update();
184  }
185  }
186 
187  canvas_rad_map_x_y.Print("dose_x_y.pdf");
188  canvas_rad_map_x_y_plane_0.Print("dose_x_y_plane_0.pdf");
189  canvas_rad_map_x_z.Print("dose_x_z.pdf");
190 
191 
192 
193 /*
194  TString DigiFile = storePath + "/Lumi_digi";
195  DigiFile += startEvent;
196  DigiFile += ".root";
197  // Digi file
198  TString RecoFile = storePath + "/Lumi_reco";
199  RecoFile += startEvent;
200  RecoFile += ".root";
201  // TCand file
202  TString CandFile = storePath + "/Lumi_TCand";
203  CandFile += startEvent;
204  CandFile += ".root";
205  // Parameter file << this one
206  TString parFile = storePath + "/Lumi_Params";
207  parFile += startEvent;
208  parFile += ".root";
209  // Track file
210  TString TrkFile = storePath + "/Lumi_Track";
211  TrkFile += startEvent;
212  TrkFile += ".root";
213 
214  // ---- Load libraries -------------------------------------------------
215  gROOT->Macro("$VMCWORKDIR/gconfig/rootlogon.C");
216  gSystem->Load("libSds");
217  gSystem->Load("libSdsReco");
218  gSystem->Load("libLmd");
219  gSystem->Load("libLmdReco");
220  gSystem->Load("libLmdTrk");
221  // ------------------------------------------------------------------------
222  // Output file
223  TString outFile = storePath + "/Lumi_Testing_";
224  outFile += startEvent;
225  outFile += ".root";
226 
227  // Output histogram file
228  TString outFilehist = storePath + "/Lumi_performance_histograms_";
229  outFilehist += startEvent;
230  outFilehist += ".root";
231 
232  std::cout << "DigiFile: " << DigiFile.Data() << std::endl;
233  std::cout << "RecoFile: " << RecoFile.Data() << std::endl;
234  std::cout << "TCandFile: " << CandFile.Data() << std::endl;
235  std::cout << "TrackFile: " << TrkFile.Data() << std::endl;
236  std::cout << "TestingFile: " << outFile.Data() << std::endl;
237  // --- Now choose concrete engines for the different tasks -------------
238  // ------------------------------------------------------------------------
239 
240 
241  // In general, the following parts need not be touched
242  // ========================================================================
243 
244 
245  // ----- Timer --------------------------------------------------------
246  TStopwatch timer;
247  timer.Start();
248  // ------------------------------------------------------------------------
249 
250 
251  // ----- Reconstruction run -------------------------------------------
252  FairRunAna *fRun = new FairRunAna();
253  fRun->SetInputFile(MCFile);
254  //fRun->AddFriend(DigiFile);
255  //fRun->AddFriend(RecoFile);
256  //fRun->AddFriend(CandFile);
257  //fRun->AddFriend(TrkFile);
258  fRun->SetOutputFile(outFile);
259  // ------------------------------------------------------------------------
260 
261  FairGeane *Geane = new FairGeane();
262  fRun->AddTask(Geane);
263 
264  // ----- Parameter database --------------------------------------------
265  FairRuntimeDb* rtdb = fRun->GetRuntimeDb();
266  FairParRootFileIo* parInput1 = new FairParRootFileIo(kTRUE);
267  parInput1->open(parFile.Data());
268  rtdb->setFirstInput(parInput1);
269 
270  // =========================================================================
271  // ====== Geane Back-Propagating ======
272  // =========================================================================
273 
274  // ----- SDS hit producer --------------------------------------------
275 
276  // PndEmcMapper *emcMap = PndEmcMapper::Instance(6);
277  Double_t fpBeam = 1.5;
278  TVector3 IP(0, 0, 0);
279  PndLmdPerformanceTask* lmdperformance = new PndLmdPerformanceTask();
280  lmdperformance->SetVerbose(0);
281  fRun->AddTask(lmdperformance);
282  rtdb->setOutput(parInput1);
283  //lmdperformance->SetHistFilename(outFilehist);
284  rtdb->print();
285  // ===== End of Geane =====
286  // =========================================================================
287 
288  // ----- Intialise and run --------------------------------------------
289  fRun->Init();
290  // // PndEmcMapper *emcMap = PndEmcMapper::Instance(6);
291  // PndEmcMapper *emcMap = PndEmcMapper::Instance();
292  // //Geane->SetField(fRun->GetField());
293  FairRootManager* ioman = FairRootManager::Instance();
294  if (!ioman) {
295  std::cout << "Error: "
296  << "RootManager not instantiated!" << std::endl;
297  return 1;
298  }
299  fRun->Run(0, ioman->CheckMaxEventNo()); // hmm does not work yet, seems to return 0 but then is runs over all what was intended.
300  // ------------------------------------------------------------------------
301  rtdb->saveOutput();
302  rtdb->print();
303  // ----- Finish -------------------------------------------------------
304  timer.Stop();
305  Double_t rtime = timer.RealTime();
306  Double_t ctime = timer.CpuTime();
307  cout << endl << endl;
308  cout << "Macro finished succesfully." << endl;
309  cout << "Output file is " << outFile << endl;
310  cout << "Parameter file is " << parFile << endl;
311  cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
312  cout << endl;
313  // ------------------------------------------------------------------------
314 
315  //myapp.Run();
316 */
317  return 0;
318 }
319 
320 /*
321  // some design constants of the LUMI detector
322  const int nplanes(4);
323  const int nsensors_per_plane(8);
324 
325  double last_percent(-1.);
326  // draw a progress bar only when the length changes significantly
327  void DrawProgressBar(int len, double percent);
328 
329  void Resolution_and_acceptance(){
330  cout << " analysis tool vers. 1.1 " << endl;
331 
332 
333  gSystem->Load("libSds");
334  gSystem->Load("libSdsReco");
335  gSystem->Load("libLmd");
336  gSystem->Load("libLmdReco");
337  gSystem->Load("libLmdTrk");
338 
339  TStopwatch timer;
340  timer.Start();
341  // ------------------------------------------------------------------------
342 
343  TString storePath = "./tmpOutput";
344  TString startEvent = "0";
345  // ---- Input files --------------------------------------------------------
346  TString simMC = storePath + "/Lumi_MC_";
347  simMC += startEvent;
348  simMC += ".root";
349  TChain tMC("pndsim");
350  tMC.Add(simMC);
351 
352  TString DigiFile = storePath + "/Lumi_digi_";
353  DigiFile += startEvent;
354  DigiFile += ".root";
355  TChain tdigiHits("pndsim");
356  tdigiHits.Add(DigiFile);
357 
358  TString recHit = storePath + "/Lumi_reco_";
359  recHit += startEvent;
360  recHit += ".root";
361  TChain tHits("pndsim");
362  tHits.Add(recHit);
363 
364  TString trkCand = storePath + "/Lumi_TCand_";
365  trkCand += startEvent;
366  trkCand += ".root";
367  TChain tTrkCand("pndsim");
368  tTrkCand.Add(trkCand);
369 
370  TString recTrack = storePath + "/Lumi_Track_";
371  recTrack += startEvent;
372  recTrack += ".root";
373  TChain tTrkRec("pndsim");
374  tTrkRec.Add(recTrack);
375 
376  TString geaneFile = storePath + "/Lumi_Geane_";
377  geaneFile += startEvent;
378  geaneFile += ".root";
379  TChain tgeane("pndsim");
380  tgeane.Add(geaneFile);
381 
382  // Parameter file << needed for geane back tracking
383  TString parFile = storePath+"/Lumi_Params_";
384  parFile += startEvent;
385  parFile += ".root";
386 
387  // ---- Output file ----------------------------------------------------------------
388  TString fakefile = storePath + "/fake";
389  fakefile += startEvent;
390  fakefile += ".root";tmpOutput
391  // ---------------------------------------------------------------------------------
392 
393  // ---------------------------------------------------------------------------------
394 
395  // ---- needed to use the back propagation ----------------------------------------
396 
397  FairRunAna *fRun= new FairRunAna();
398  fRun->SetInputFile(simMC);
399  //fRun->AddFriend(DigiFile);
400  //fRun->AddFriend(recHit);
401  //fRun->AddFriend(trkCand);
402  //fRun->AddFriend(recTrack);
403  fRun->SetOutputFile(fakefile);
404  // ------------------------------------------------------------------------
405 
406  FairGeane *Geane = new FairGeane();
407  //fRun->AddTask(Geane);
408  FairGeanePro* fPro = Geane->Exec();
409  // new FairGeanePro();
410 
411  cout << " ok " << endl;
412 
413  // ----- Parameter database --------------------------------------------
414  FairRuntimeDb* rtdb = fRun->GetRuntimeDb();
415  FairParRootFileIo* parInput1 = new FairParRootFileIo(kTRUE);
416  parInput1->open(parFile.Data());
417  rtdb->setFirstInput(parInput1);
418  fRun->Init();
419 
420  // ---- Output file ----------------------------------------------------------------
421  TString out = storePath + "/Resolution_and_acceptance";
422  out += startEvent;
423  out += ".root";
424  TFile *output_histfile = new TFile(out, "RECREATE");
425  // ---------------------------------------------------------------------------------
426 
427  //--- MC info -----------------------------------------------------------------
428  TClonesArray* true_tracks = new TClonesArray("PndMCTrack");
429  tMC.SetBranchAddress("MCTrack", &true_tracks); //True Track to compare
430 
431  TClonesArray* true_points = new TClonesArray("PndSdsMCPoint");
432  tMC.SetBranchAddress("LMDPoint", &true_points); //True Points to compare
433  //----------------------------------------------------------------------------------
434 
435 
436  //--- Digitization info ------------------------------------------------------------
437  TClonesArray* fStripClusterArray = new TClonesArray("PndSdsClusterStrip");
438  tHits.SetBranchAddress("LMDStripClusterCand", &fStripClusterArray);
439 
440  TClonesArray* fStripDigiArray = new TClonesArray("PndSdsDigiStrip");
441  tdigiHits.SetBranchAddress("LMDStripDigis", &fStripDigiArray);
442  //----------------------------------------------------------------------------------
443 
444  //--- Real Hits --------------------------------------------------------------------
445  TClonesArray* rechit_array = new TClonesArray("PndSdsHit");
446  tHits.SetBranchAddress("LMDHitsStrip", &rechit_array); //Points for Tracks
447  //----------------------------------------------------------------------------------
448 
449 
450  //--- Track Candidate ---------------------------------------------------------------
451  TClonesArray* trkcand_array = new TClonesArray("PndTrackCand");
452  tTrkCand.SetBranchAddress("LMDTrackCand", &trkcand_array); //Points for Track Canidates
453  //-----------------------------------------------------------------------------------
454 
455  //--- Real tracks -------------------------------------------------------------------
456  TClonesArray* rec_trk = new TClonesArray("PndLinTrack");
457  tTrkRec.SetBranchAddress("LMDTrack", &rec_trk); //Tracks
458  //----------------------------------------------------------------------------------
459 
460  //--- Geane info ------------------------------------------------------------------
461  // TClonesArray* geaneArray =new TClonesArray("FairTrackParP");
462  //TClonesArray* geaneArray = new TClonesArray("FairTrackParH");
463  //tgeane.SetBranchAddress("GeaneTrackFinal", &geaneArray); //Tracks with parabolic parameterization
464  // angular acceptance in theta and phi
465 
466  TH2* hist_angular_distr_gen = new TH2F("hist_angular_distr_gen", "hist_angular_distr_gen", 100, 0., 20.e-3, 100, 0., 3.141);
467  TH2* hist_angular_distr_acc = new TH2F("hist_angular_distr_acc", "hist_angular_distr_acc", 100, 0., 20.e-3, 100, 0., 3.141);
468 
469  // spatial acceptance in x and y at the first lumi plane
470  TH2* hist_spatial_distr_gen = new TH2F("hist_spatial_distr_gen", "hist_spatial_distr_gen", 1000, -100., 100., 1000, -100., 100.);
471  TH2* hist_spatial_distr_acc = new TH2F("hist_spatial_distr_acc", "hist_spatial_distr_acc", 1000, -100., 100., 1000, -100., 100.);
472 
473  TTree* tree_results = new TTree("tree_results", "tree_results");
474  // initial momenta of the antiprotons
475  double px_init;
476  double py_init;
477  double pz_init;
478  double ptheta_init;
479  double pphi_init;
480  tree_results->Branch("px_init", &px_init);
481  tree_results->Branch("py_init", &py_init);
482  tree_results->Branch("pz_init", &pz_init);
483  tree_results->Branch("ptheta_init", &ptheta_init);
484  tree_results->Branch("pphi_init", &pphi_init);
485  // momenta at the entry of a detector plane
486  // in the reference system of the LUMI
487  double px_in;
488  double py_in;
489  double pz_in;
490  double ptheta_in;
491  double pphi_in;
492  tree_results->Branch("px_in", &px_in);
493  tree_results->Branch("py_in", &py_in);
494  tree_results->Branch("pz_in", &pz_in);
495  tree_results->Branch("ptheta_in", &ptheta_in);
496  tree_results->Branch("pphi_in", &pphi_in);
497  // position at the entry of a detector plane
498  // in the reference system of the LUMI
499  double x_in;
500  double y_in;
501  double z_in;
502  tree_results->Branch("x_in", &x_in);
503  tree_results->Branch("y_in", &y_in);
504  tree_results->Branch("z_in", &z_in);
505  // detector and sensor id of the mc hits
506  int det_id;
507  int sens_id;
508  tree_results->Branch("det_id", &det_id);
509  tree_results->Branch("sens_id", &sens_id);
510  // calculated plane and sensor in plane id
511  int plane;
512  int sensor;
513  tree_results->Branch("plane", &plane);
514  tree_results->Branch("sensor", &sensor);
515 
516  // Drawing directly from a tree is elegant but slow as every Draw call
517  // loops over the whole tree of events
518  // Better it is to create the desired histograms in advance
519  // and to fill those on event by event basis simultaneously
520 
521  // histograms per plane
522  TH2* hist_xy [nplanes];
523  TH1* hist_theta_init [nplanes];
524  TH1* hist_theta_in [nplanes];
525  TH1* hist_theta_diff [nplanes];
526  TH1* hist_theta_diff_rel [nplanes];
527 
528  // histograms per sensor
529  TH2* hists_xy [nplanes][nsensors_per_plane];
530  TH1* hists_theta_init [nplanes][nsensors_per_plane];
531  TH1* hists_theta_in [nplanes][nsensors_per_plane];
532  TH1* hists_theta_diff [nplanes][nsensors_per_plane];
533  TH1* hists_theta_diff_rel [nplanes][nsensors_per_plane];
534 
535  TCanvas temp_canvas("temp_canvas", "canvas for initialization", 100, 100);
536  temp_canvas.cd();
537  // loop over planes
538  cout << " constructing histograms for " << nplanes << " planes with " << nsensors_per_plane << " sensors per plane " << endl;
539 
540  for (int iplane = 0; iplane < nplanes; iplane++){
541  stringstream hist_name;
542  stringstream hist_title;
543 
544  hist_name << "hist_xy_plane_" << iplane;
545  hist_title << "xy hit distribution plane " << iplane;
546  hist_xy[iplane] = new TH2F(hist_name.str().c_str(), hist_title.str().c_str(),
547  100, -10, 10, 100, -10, 10);
548  hist_xy[iplane]->Draw();
549  hist_xy[iplane]->GetXaxis()->SetTitle("X [cm]");
550  hist_xy[iplane]->GetYaxis()->SetTitle("Y [cm]");
551 
552  hist_name .str("");
553  hist_title.str("");
554 
555  hist_name << "hist_theta_init_plane_" << iplane;
556  hist_title << "initial #Theta distribution plane " << iplane;
557  hist_theta_init[iplane] = new TH1F(hist_name.str().c_str(), hist_title.str().c_str(),
558  150, 0, 15e-3);
559  hist_theta_init[iplane]->Draw();
560  hist_theta_init[iplane]->GetXaxis()->SetTitle("#Theta [rad]");
561  hist_theta_init[iplane]->GetYaxis()->SetTitle("entries");
562 
563  hist_name .str("");
564  hist_title.str("");
565 
566  hist_name << "hist_theta_in_plane_" << iplane;
567  hist_title << "#Theta distribution at plane " << iplane;
568  hist_theta_in[iplane] = new TH1F(hist_name.str().c_str(), hist_title.str().c_str(),
569  200, 0, 20e-3);
570  hist_theta_in[iplane]->Draw();
571  hist_theta_in[iplane]->GetXaxis()->SetTitle("#Theta [rad]");
572  hist_theta_in[iplane]->GetYaxis()->SetTitle("entries");
573 
574  hist_name .str("");
575  hist_title.str("");
576 
577  hist_name << "hist_theta_diff_in_plane_" << iplane;
578  hist_title << "#Delta#Theta distribution at plane " << iplane;
579  hist_theta_diff[iplane] = new TH1F(hist_name.str().c_str(), hist_title.str().c_str(),
580  100, -20e-5, 20e-5);
581  hist_theta_diff[iplane]->Draw();
582  hist_theta_diff[iplane]->GetXaxis()->SetTitle("#Delta#Theta [rad]");
583  hist_theta_diff[iplane]->GetYaxis()->SetTitle("entries");
584 
585  hist_name .str("");
586  hist_title.str("");
587 
588  hist_name << "hist_theta_diff_rel_in_plane_" << iplane;
589  hist_title << "#Delta#Theta/#Theta distribution at plane " << iplane;
590  hist_theta_diff_rel[iplane] = new TH1F(hist_name.str().c_str(), hist_title.str().c_str(),
591  100, -1, 1);
592  hist_theta_diff_rel[iplane]->Draw();
593  hist_theta_diff_rel[iplane]->GetXaxis()->SetTitle("#Delta#Theta/#Theta");
594  hist_theta_diff_rel[iplane]->GetYaxis()->SetTitle("entries");
595 
596  // loop over sensors per plane which are enumerated linearly
597  for (int isensor = 0; isensor < nsensors_per_plane; isensor++){
598  hist_name .str("");
599  hist_title.str("");
600 
601  hist_name << "hist_xy_plane_" << iplane << "_sensor_" << isensor;
602  hist_title << "xy hit distribution plane " << iplane << " sensor " << isensor;
603  hists_xy[iplane][isensor] = new TH2F(hist_name.str().c_str(), hist_title.str().c_str(),
604  100, -10, 10, 100, -10, 10);
605  hists_xy[iplane][isensor]->Draw();
606  hists_xy[iplane][isensor]->GetXaxis()->SetTitle("X [cm]");
607  hists_xy[iplane][isensor]->GetYaxis()->SetTitle("Y [cm]");
608 
609  hist_name .str("");
610  hist_title.str("");
611 
612  hist_name << "hist_theta_init_plane_" << iplane << "_sensor_" << isensor;
613  hist_title << "initial #Theta distribution plane " << iplane << " sensor " << isensor;
614  hists_theta_init[iplane][isensor] = new TH1F(hist_name.str().c_str(), hist_title.str().c_str(),
615  150, 0, 15e-3);
616  hists_theta_init[iplane][isensor]->Draw();
617  hists_theta_init[iplane][isensor]->GetXaxis()->SetTitle("#Theta [rad]");
618  hists_theta_init[iplane][isensor]->GetYaxis()->SetTitle("entries");
619 
620  hist_name .str("");
621  hist_title.str("");
622 
623  hist_name << "hist_theta_in_plane_" << iplane << "_sensor_" << isensor;
624  hist_title << "#Theta distribution at plane " << iplane << " sensor " << isensor;
625  hists_theta_in[iplane][isensor] = new TH1F(hist_name.str().c_str(), hist_title.str().c_str(),
626  200, 0, 20e-3);
627  hists_theta_in[iplane][isensor]->Draw();
628  hists_theta_in[iplane][isensor]->GetXaxis()->SetTitle("#Theta [rad]");
629  hists_theta_in[iplane][isensor]->GetYaxis()->SetTitle("entries");
630 
631  hist_name .str("");
632  hist_title.str("");
633 
634  hist_name << "hist_theta_diff_in_plane_" << iplane << "_sensor_" << isensor;
635  hist_title << "#Delta#Theta distribution at plane " << iplane << " sensor " << isensor;
636  hists_theta_diff[iplane][isensor] = new TH1F(hist_name.str().c_str(), hist_title.str().c_str(),
637  100, -20e-5, 20e-5);
638  hists_theta_diff[iplane][isensor]->Draw();
639  hists_theta_diff[iplane][isensor]->GetXaxis()->SetTitle("#Delta#Theta [rad]");
640  hists_theta_diff[iplane][isensor]->GetYaxis()->SetTitle("entries");
641 
642  hist_name .str("");
643  hist_title.str("");
644 
645  hist_name << "hist_theta_diff_rel_in_plane_" << iplane << "_sensor_" << isensor;
646  hist_title << "#Delta#Theta/#Theta distribution at plane " << iplane << " sensor " << isensor;
647  hists_theta_diff_rel[iplane][isensor] = new TH1F(hist_name.str().c_str(), hist_title.str().c_str(),
648  100, -1, 1);
649  hists_theta_diff_rel[iplane][isensor]->Draw();
650  hists_theta_diff_rel[iplane][isensor]->GetXaxis()->SetTitle("#Delta#Theta/#Theta");
651  hists_theta_diff_rel[iplane][isensor]->GetYaxis()->SetTitle("entries");
652  }
653  }
654 
655 
656  // rotation into the lumi position according to the beamline file
657  // matrix tri6 - tr=1 rot=1 refl=0 scl=0
658  // 0.999192 0.000000 0.040200 Tx = 22.893063
659  // 0.000000 1.000000 -0.000000 Ty = 0.000000
660  // -0.040200 0.000000 0.999192 Tz = 1049.770390
661  // The matrix is a rotation around y of around 0.04025 radian
662  TRotation inv_lmdrotation;
663  //inv_lmdrotation.RotateY(-0.04025);
664  inv_lmdrotation.RotateY(-2.326/180.*TMath::Pi()); // as derived by mathias michel
665  TVector3 inv_lmdtranslation(
666  -22.893063, 0.000000, -1049.770390);
667 
668  int nEvents = tMC.GetEntries();
669  if (tTrkCand.GetEntries() != nEvents) {cout << "nMC <> nTrkCand! Exiting." << endl; return;}
670  if (tTrkRec.GetEntries() != nEvents) {cout << "nMC <> nTrkRec! Exiting." << endl; return;}
671  if (tHits.GetEntries() != nEvents) {cout << "nMC <> nHits! Exiting." << endl; return;}
672  if (tdigiHits.GetEntries() != nEvents) {cout << "nMC <> nTrkdigiHits! Exiting." << endl; return;}
673  //if (tgeane.GetEntries() != nEvents) {cout << "nMC <> TrkCand! Exiting." << endl; return;}
674  //TVector3 ip(0,0,0);
675  //PndLmdGeaneTask* lmdgeane = new PndLmdGeaneTask();
676  cout << " reading " << nEvents << " Events " << endl;
677  for (Int_t j = 0; j < nEvents; j++) {
678  DrawProgressBar(50, (j+1)/((double)nEvents));
679  tMC.GetEntry(j);
680  tTrkCand.GetEntry(j);
681  tTrkRec.GetEntry(j);
682  tHits.GetEntry(j);
683  tdigiHits.GetEntry(j);
684  const int nParticles = true_tracks->GetEntriesFast();
685 
686  int npbar = 0;
687  for (Int_t iParticle = 0; iParticle < nParticles; iParticle++) {
688  // if(nParticles!=4) continue;
689  PndMCTrack *mctrk = (PndMCTrack*) true_tracks->At(iParticle);
690  Int_t mcID = mctrk->GetPdgCode();
691  if (mctrk->IsGeneratorCreated()){//mcID == -2212) {
692  npbar++;
693  // if(nParticles!=4) cout<<"For event #"<<j<<" mcID="<<mcID<<endl;
694  TVector3 MomMC = mctrk->GetMomentum();
695  hist_angular_distr_gen->Fill(MomMC.Theta(), MomMC.Phi());
696  //hallTheta->Fill(MomMC.Theta());
697  //hallPhi->Fill(MomMC.Phi());
698  }
699  }
700  if (0&&npbar != 1)
701  cout << "found " << npbar << " anti-protons" << endl;
702 
703  int nHits = true_points->GetEntriesFast();
704  int nSdsHits = 0;
705  for (Int_t iHit = 0; iHit < nHits; iHit++) {
706  PndSdsMCPoint* mcpoint = (PndSdsMCPoint*) true_points->At(iHit);
707  PndMCTrack *mctrk = (PndMCTrack*) true_tracks->At(mcpoint->GetTrackID());
708  if (mctrk->IsGeneratorCreated()){ // take only anti-protons from the generator
709  if (mcpoint){
710  TVector3 _mcpoint((mcpoint->GetPosition())); // position at the sensor entrance
711  TVector3 _mctrack(mcpoint->GetPx(), mcpoint->GetPy(), mcpoint->GetPz()); // momentum of the track at the entrance
712  if (1) { // translate it into the reference system of the lumi monitor
713  _mcpoint = inv_lmdtranslation+_mcpoint;
714  _mcpoint = inv_lmdrotation*_mcpoint;
715  }
716  TVector3 momMC = mctrk->GetMomentum(); // momentum in the primary vertex
717  TVector3 posMC = mctrk->GetStartVertex(); // position of the primary vertex
718  if (1) { // use back propagation for the track
719  TVector3 initpos, initmom(0,0,momMC.Mag()),
720  StartPosErr, StartMomErr, \
721  ResPosErr, ResMomErr;
722  int charge = mctrk->GetPdgCode() > 0 ? 1 : mctrk->GetPdgCode() < 0 ? -1 : 0;
723  FairTrackParH *fStart =
724  new FairTrackParH(posMC, momMC, StartPosErr, StartMomErr, charge); // exchange fCharge by charge of PDGCode
725  FairTrackParH *fRes =
726  new FairTrackParH(initpos, initmom, ResPosErr, ResMomErr, charge);
727  Bool_t isProp = fPro->Propagate(fStart, fRes, mctrk->GetPdgCode());
728  if (!isProp) cout << "Propagate(): back propagation not possible! " << endl;
729  _mctrack = initmom;// inv_lmdrotation*_mctrack;
730 
731  }
732  det_id = mcpoint->GetDetectorID(); // store the detector id
733  sens_id = mcpoint->GetSensorID(); // store the sensor id
734  // calculate the plane and sensor on this plane
735  plane = sens_id/nsensors_per_plane;
736  sensor = sens_id-plane*nsensors_per_plane;
737 
738  // write those values out
739  px_init = momMC.X();
740  py_init = momMC.Y();
741  pz_init = momMC.Z();
742  ptheta_init = momMC.Theta();
743  pphi_init = momMC.Phi();
744  x_in = _mcpoint.X();
745  y_in = _mcpoint.Y();
746  z_in = _mcpoint.Z();
747  px_in = _mctrack.X();
748  py_in = _mctrack.Y();
749  pz_in = _mctrack.Z();
750  ptheta_in = _mctrack.Theta();
751  pphi_in = _mctrack.Phi();
752 
753  if (plane < 0 || plane >= nplanes || sensor < 0 || sensor >= nsensors_per_plane){
754  cout << " warning: calculated plane or sensor is wrong: plane " << plane << " sensor " << sensor << endl;
755  } else {
756  hist_xy [plane] ->Fill(x_in,y_in);
757  hists_xy[plane][sensor]->Fill(x_in,y_in);
758 
759  hist_theta_init [plane] ->Fill(ptheta_init);
760  hists_theta_init [plane][sensor]->Fill(ptheta_init);
761 
762  hist_theta_in [plane] ->Fill(ptheta_in);
763  hists_theta_in[plane][sensor]->Fill(ptheta_in);
764 
765  hist_theta_diff[plane] ->Fill(ptheta_in-ptheta_init);
766  hists_theta_diff[plane][sensor]->Fill(ptheta_in-ptheta_init);
767 
768  if (ptheta_init > 0){
769  hist_theta_diff_rel[plane] ->Fill((ptheta_in-ptheta_init)/ptheta_init);
770  hists_theta_diff_rel[plane][sensor]->Fill((ptheta_in-ptheta_init)/ptheta_init);
771  }
772 
773  tree_results->Fill();
774  }
775 
776  //cout << _mcpoint.X() << " " << _mcpoint.Y() << " "<< _mcpoint.Z() << endl;
777  hist_spatial_distr_acc->Fill(_mcpoint.X(), _mcpoint.Y());
778  hist_angular_distr_acc->Fill(momMC.Theta(), momMC.Phi());
779  nSdsHits++;
780  }
781  }
782  }
783  if (0 && nHits > 0)
784  cout << "found " << nHits << " hit(s) with " << nSdsHits << " sds hit(s)" << endl;
785  }
786 
787  hist_angular_distr_acc->Divide(hist_angular_distr_gen);
788 
789  TGaxis::SetMaxDigits(3);
790  TCanvas* canvas1 = new TCanvas("canvas1", "canvas1", 800, 800);
791  canvas1->Divide(2,2);
792  canvas1->cd(1);
793  hist_angular_distr_gen->Draw("COLZ");
794  hist_angular_distr_gen->SetXTitle("#Theta [rad]");
795  hist_angular_distr_gen->SetYTitle("#Phi [rad]");
796  gPad->Update();
797  canvas1->cd(2);
798  hist_angular_distr_acc->Draw("COLZ");
799  hist_angular_distr_acc->SetXTitle("#Theta [rad]");
800  hist_angular_distr_acc->SetYTitle("#Phi [rad]");
801  gPad->Update();
802  canvas1->cd(3);
803  hist_spatial_distr_gen->Draw("COLZ");
804  hist_spatial_distr_gen->SetXTitle("X [cm]");
805  hist_spatial_distr_gen->SetYTitle("Y [cm]");
806  hist_spatial_distr_gen->GetXaxis()->SetRangeUser(-10,10);
807  hist_spatial_distr_gen->GetYaxis()->SetRangeUser(-10,10);
808  gPad->Update();
809  canvas1->cd(4);
810  hist_spatial_distr_acc->Draw("COLZ");
811  hist_spatial_distr_acc->SetXTitle("X [cm]");
812  hist_spatial_distr_acc->SetYTitle("Y [cm]");
813  hist_spatial_distr_acc->GetXaxis()->SetRangeUser(-10,10);
814  hist_spatial_distr_acc->GetYaxis()->SetRangeUser(-10,10);
815  gPad->Update();
816 
817  // draw individual plane and sensor properties
818  //gStyle->SetPaperSize(25,25);
819  TCanvas canvas_properties_per_plane("canvas_properties_per_plane", "properties per plane", 800, 800);
820  canvas_properties_per_plane.cd();
821  // assuming to have 4 planes
822  if (nplanes != 4) cout << " warning: attempting to draw histograms for a number of planes not 4! " << endl;
823  canvas_properties_per_plane.Divide(2,2);
824 
825  TCanvas canvas_properties_per_sensor("canvas_properties_per_sensor", "properties per sensor", 800, 800);
826  canvas_properties_per_sensor.cd();
827  // assuming to have 8 sensors per plane
828  if (nsensors_per_plane != 8) cout << " warning: attempting to draw histograms for a number of sensors per plane not 8! " << endl;
829  canvas_properties_per_sensor.Divide(3,3);
830 
831  for (int iplane = 0; iplane < nplanes; iplane++){
832  canvas_properties_per_plane.cd(iplane+1);
833  hist_xy[iplane]->Draw("COLZ");
834  }
835  canvas_properties_per_plane.Print("Resolution_acceptance_results.ps(");
836  for (int iplane = 0; iplane < nplanes; iplane++){
837  for (int isensor = 0; isensor < nsensors_per_plane; isensor++){
838  canvas_properties_per_sensor.cd(isensor+1);
839  hists_xy[iplane][isensor]->Draw("COLZ");
840  }
841  canvas_properties_per_sensor.Print("Resolution_acceptance_results.ps(");
842  }
843 
844  for (int iplane = 0; iplane < nplanes; iplane++){
845  canvas_properties_per_plane.cd(iplane+1);
846  hist_theta_init[iplane]->Draw();
847  }
848  canvas_properties_per_plane.Print("Resolution_acceptance_results.ps(");
849  for (int iplane = 0; iplane < nplanes; iplane++){
850  for (int isensor = 0; isensor < nsensors_per_plane; isensor++){
851  canvas_properties_per_sensor.cd(isensor+1);
852  hists_theta_init[iplane][isensor]->Draw();
853  canvas_properties_per_sensor.cd(9);
854  if (isensor > 0)
855  hists_theta_init[iplane][isensor]->Draw("same E");
856  else
857  hists_theta_init[iplane][isensor]->Draw("E");
858  hists_theta_init[iplane][isensor]->SetLineColor(kAzure-9+isensor);
859  }
860  canvas_properties_per_sensor.Print("Resolution_acceptance_results.ps(");
861  }
862  for (int isensor = 0; isensor < nsensors_per_plane; isensor++){
863  canvas_properties_per_sensor.cd(isensor+1);
864  for (int iplane = 0; iplane < nplanes; iplane++){
865  if (iplane > 0)
866  hists_theta_init[iplane][isensor]->Draw("same");
867  else
868  hists_theta_init[iplane][isensor]->Draw();
869  hists_theta_init[iplane][isensor]->SetLineColor(kGray+iplane);
870  }
871  }
872  canvas_properties_per_sensor.cd(9);
873  gPad->Clear();
874  canvas_properties_per_sensor.Print("Resolution_acceptance_results.ps(");
875 
876  for (int iplane = 0; iplane < nplanes; iplane++){
877  canvas_properties_per_plane.cd(iplane+1);
878  hist_theta_in[iplane]->Draw();
879  }
880  canvas_properties_per_plane.Print("Resolution_acceptance_results.ps(");
881  for (int iplane = 0; iplane < nplanes; iplane++){
882  for (int isensor = 0; isensor < nsensors_per_plane; isensor++){
883  canvas_properties_per_sensor.cd(isensor+1);
884  hists_theta_in[iplane][isensor]->Draw();
885  canvas_properties_per_sensor.cd(9);
886  if (isensor > 0)
887  hists_theta_in[iplane][isensor]->Draw("same E");
888  else
889  hists_theta_in[iplane][isensor]->Draw("E");
890  hists_theta_in[iplane][isensor]->SetLineColor(kAzure-9+isensor);
891  }
892  canvas_properties_per_sensor.Print("Resolution_acceptance_results.ps(");
893  }
894  for (int isensor = 0; isensor < nsensors_per_plane; isensor++){
895  canvas_properties_per_sensor.cd(isensor+1);
896  for (int iplane = 0; iplane < nplanes; iplane++){
897  if (iplane > 0)
898  hists_theta_in[iplane][isensor]->Draw("same");
899  else
900  hists_theta_in[iplane][isensor]->Draw();
901  hists_theta_in[iplane][isensor]->SetLineColor(kGray+iplane);
902  }
903  }
904  canvas_properties_per_sensor.cd(9);
905  gPad->Clear();
906  canvas_properties_per_sensor.Print("Resolution_acceptance_results.ps(");
907 
908  for (int iplane = 0; iplane < nplanes; iplane++){
909  canvas_properties_per_plane.cd(iplane+1);
910  hist_theta_diff[iplane]->Draw();
911  }
912  canvas_properties_per_plane.Print("Resolution_acceptance_results.ps(");
913  for (int iplane = 0; iplane < nplanes; iplane++){
914  for (int isensor = 0; isensor < nsensors_per_plane; isensor++){
915  canvas_properties_per_sensor.cd(isensor+1);
916  hists_theta_diff[iplane][isensor]->Draw();
917  canvas_properties_per_sensor.cd(9);
918  if (isensor > 0)
919  hists_theta_diff[iplane][isensor]->Draw("same E");
920  else
921  hists_theta_diff[iplane][isensor]->Draw("E");
922  hists_theta_diff[iplane][isensor]->SetLineColor(kAzure-9+isensor);
923  }
924  canvas_properties_per_sensor.Print("Resolution_acceptance_results.ps(");
925  }
926  for (int isensor = 0; isensor < nsensors_per_plane; isensor++){
927  canvas_properties_per_sensor.cd(isensor+1);
928  for (int iplane = 0; iplane < nplanes; iplane++){
929  if (iplane > 0)
930  hists_theta_diff[iplane][isensor]->Draw("same");
931  else
932  hists_theta_diff[iplane][isensor]->Draw();
933  hists_theta_diff[iplane][isensor]->SetLineColor(kGray+iplane);
934  }
935  }
936  canvas_properties_per_sensor.cd(9);
937  gPad->Clear();
938  canvas_properties_per_sensor.Print("Resolution_acceptance_results.ps(");
939 
940  for (int iplane = 0; iplane < nplanes; iplane++){
941  canvas_properties_per_plane.cd(iplane+1);
942  hist_theta_diff_rel[iplane]->Draw();
943  }
944  canvas_properties_per_plane.Print("Resolution_acceptance_results.ps(");
945  for (int iplane = 0; iplane < nplanes; iplane++){
946  for (int isensor = 0; isensor < nsensors_per_plane; isensor++){
947  canvas_properties_per_sensor.cd(isensor+1);
948  hists_theta_diff_rel[iplane][isensor]->Draw();
949  canvas_properties_per_sensor.cd(9);
950  if (isensor > 0)
951  hists_theta_diff_rel[iplane][isensor]->Draw("same E");
952  else
953  hists_theta_diff_rel[iplane][isensor]->Draw("E");
954  hists_theta_diff_rel[iplane][isensor]->SetLineColor(kAzure-9+isensor);
955  }
956  canvas_properties_per_sensor.Print("Resolution_acceptance_results.ps(");
957  }
958  for (int isensor = 0; isensor < nsensors_per_plane; isensor++){
959  canvas_properties_per_sensor.cd(isensor+1);
960  for (int iplane = 0; iplane < nplanes; iplane++){
961  if (iplane > 0)
962  hists_theta_diff_rel[iplane][isensor]->Draw("same");
963  else
964  hists_theta_diff_rel[iplane][isensor]->Draw();
965  hists_theta_diff_rel[iplane][isensor]->SetLineColor(kGray+iplane);
966  }
967  }
968  canvas_properties_per_sensor.cd(9);
969  gPad->Clear();
970  canvas_properties_per_sensor.Print("Resolution_acceptance_results.ps(");
971 
972  canvas_properties_per_plane.Clear();
973  canvas_properties_per_plane.Print("Resolution_acceptance_results.ps)");
974  // convert to pdf
975  cout << "converting to pdf " << system("ps2pdf Resolution_acceptance_results.ps")<< endl;
976  cout << "deleting ps file " << system("rm Resolution_acceptance_results.ps")<< endl;
977 
978  output_histfile->Write();
979 
980  hist_angular_distr_gen->SetDirectory(0);
981  hist_angular_distr_acc->SetDirectory(0);
982  hist_spatial_distr_gen->SetDirectory(0);
983  hist_spatial_distr_acc->SetDirectory(0);
984  output_histfile->Close();
985  }
986 
987  void DrawProgressBar(int len, double percent) {
988  if ((int)(last_percent*100) == (int)(percent*100)) return;
989  //cout << " drawing " << endl;
990  cout << "\x1B[2K"; // Erase the entire current line.
991  cout << "\x1B[0E"; // Move to the beginning of the current line.
992  string progress;
993  for (int i = 0; i < len; ++i) {
994  if (i < static_cast<int>(len * percent)) {
995  progress += "=";
996  } else {
997  progress += " ";
998  }
999  }
1000  cout << "[" << progress << "] " << (static_cast<int>(100 * percent)) << "%";
1001  flush(cout); // Required.
1002  last_percent = percent;
1003  }*/
1004 
double last_percent(-1.)
int main(int argc, char **argv)
Int_t i
Definition: run_full.C:25
void DrawProgressBar(int len, double percent)
Int_t startEvent
TString storePath
Int_t nEvents
Definition: hit_dirc.C:11
void Read_transformation_matrices(string filename="", bool aligned=true, int version_number=geometry_version)
Definition: PndLmdDim.cxx:1515
static PndLmdDim & Get_instance()
Definition: PndLmdDim.cxx:242
TString MCFile