FairRoot/PandaRoot
QAmacro_emc_4.C
Go to the documentation of this file.
1 //
2 // Macro that checks the energy stored in hits with the energy sum of points TClonesArray for the EMC.
3 // The total energy per event are checked as well as the energy deposited per crystal.
4 // Run QAmacro_emc_1.C and QAmacro_emc_2.C prior to this macro.
5 //
6 // If a shashlyk module if fired in event, this event is skipped
7 //
8 // JGM, April 2010
9 //
10 #include "../auxi.C"
12 {
13 
15  // The following part of macro access RunTimeDataBase and initialize PndEmcMapper from it
17  FairRunAna *fRun= new FairRunAna();
18  fRun->SetInputFile("sim_emc.root");
19  fRun->SetOutputFile("dummy_out.root");
20 
21  FairRuntimeDb* rtdb = fRun->GetRuntimeDb();
22  FairParRootFileIo* parInput1 = new FairParRootFileIo();
23  parInput1->open("simparams.root");
24 
25  TString emcAsciiPar = gSystem->Getenv("VMCWORKDIR");
26  emcAsciiPar += "/macro/params/";
27  emcAsciiPar += "emc.par";
28 
29  FairParAsciiFileIo* parInput2 = new FairParAsciiFileIo();
30  parInput2->open(emcAsciiPar.Data(),"in");
31 
32  rtdb->setFirstInput(parInput1);
33  rtdb->setSecondInput(parInput2);
34 
35  PndEmcGeoPar *geoPar = (PndEmcGeoPar*) rtdb->getContainer("PndEmcGeoPar");
36  fRun->Init();
37 
38  geoPar->InitEmcMapper();
40 
41  TFile* f = new TFile("full_emc.root"); //file you want to analyse
42  TTree *t=(TTree *) f->Get("pndsim") ;
43 
44  TClonesArray* hit_array=new TClonesArray("PndEmcHit");
45  t->SetBranchAddress("EmcHit",&hit_array);
46 
47  TFile* fsim = new TFile("sim_emc.root"); //file you want to analyse
48  TTree *tsim=(TTree *) fsim->Get("pndsim") ;
49 
50  TClonesArray* point_array=new TClonesArray("PndEmcPoint");
51  tsim->SetBranchAddress("EmcPoint",&point_array);
52 
53  TH1F *h1= new TH1F("h1","Energy deposit, sum points",500,0,2);
54  TH1F *h2= new TH1F("h2","Energy deposit, hits",500,0,2);
55 
56  Bool_t fTest=kTRUE;
57  Double_t tolerance=1e-5; // tolerance in GeV
58 
59  Short_t module=0;
60 
61  for (Int_t j=0; j< t->GetEntriesFast(); j++)
62  {
63  t->GetEntry(j);
64  tsim->GetEntry(j);
65 
66  // Sum over hits
67 
68  Double_t total_energy_from_hits=0;
69 
70  for (Int_t i=0; i<hit_array->GetEntriesFast(); i++)
71  {
72  PndEmcHit *hit=(PndEmcHit*)hit_array->At(i);
73 
74  // Skip shashlyk elements
75  module = hit->GetModule();
76  if (module==5) break;
77 
78  total_energy_from_hits += hit->GetEnergy();
79 
80  Int_t detID = hit->GetDetectorID();
81  Double_t energy_from_points=0;
82  for (Int_t k=0; k<point_array->GetEntriesFast(); k++)
83  {
84  PndEmcPoint *point=(PndEmcPoint*)point_array->At(k);
85  if (point->GetDetectorID()==detID) energy_from_points+=point->GetEnergyLoss();
86  }
87  if (fabs(hit->GetEnergy()-energy_from_points)>tolerance)
88  {
89  cout << "<E> Energy of det=" << detID<< " does not match between points and digis: " << hit->GetEnergy() << "/" << energy_from_points << endl;
90  fTest=kFALSE;
91  }
92 
93  }
94  if (module==5) continue;
95 
96  h2->Fill(total_energy_from_hits);
97 
98  // Sum over the points
99 
100  Double_t total_energy_from_points=0;
101 
102  for (Int_t i=0; i<point_array->GetEntriesFast(); i++)
103  {
104  PndEmcPoint *point=(PndEmcPoint*)point_array->At(i);
105  total_energy_from_points += point->GetEnergyLoss();
106  }
107 
108  h1->Fill(total_energy_from_points);
109 
110  if (fabs(total_energy_from_points-total_energy_from_hits)>tolerance)
111  {
112  cout << "<E> Total energy values do not match: " << total_energy_from_points << "/" << total_energy_from_hits << endl;
113  fTest=kFALSE;
114  }
115  }
116 
117 if (fTest){
118  cout << " Test passed" << endl;
119  cout << " All ok " << endl;
120 }else{
121  cout << " Test Failed" << endl;
122  cout << " Not Ok " << endl;
123 }
124  CloseGeoManager();
125  return 0;
126 }
127 
represents a mc hit in an emc crystal
Definition: PndEmcPoint.h:19
TClonesArray * point_array
Int_t i
Definition: run_full.C:25
PndMvdGeoPar * geoPar
TClonesArray * hit_array
void InitEmcMapper()
void CloseGeoManager()
Definition: QA/auxi.C:11
FairRunAna * fRun
Definition: hit_dirc.C:58
Double_t
virtual Double_t GetEnergy() const
Definition: PndEmcHit.h:54
TFile * f
Definition: bump_analys.C:12
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
FairParAsciiFileIo * parInput2
Definition: conMvdDigi.C:26
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
FairParRootFileIo * parInput1
Definition: hit_dirc.C:67
represents the deposited energy of one emc crystal from simulation
Definition: PndEmcHit.h:26
TTree * t
Definition: bump_analys.C:13
int QAmacro_emc_4()
Definition: QAmacro_emc_4.C:11
PndSdsMCPoint * hit
Definition: anasim.C:70
Short_t GetModule() const
Definition: PndEmcHit.h:58
PndSdsMCPoint * point
Definition: anaLmdCluster.C:72