FairRoot/PandaRoot
Functions
benchmark.C File Reference
#include <vector>
#include <iostream>
#include <fstream>
#include <set>
#include "../auxi.C"

Go to the source code of this file.

Functions

int benchmark ()
 

Function Documentation

int benchmark ( )

Definition at line 13 of file benchmark.C.

References allDigiFile, c, CloseGeoManager(), ctime, digiFile, Double_t, fRun, GetEntries(), out, outFile, parFile, parInput1, parIo1, recoFile, rtdb, rtime, simFile, timer, and TString.

13  {
14 
15  TString simFile = "sim.root";
16  TString parFile = "sim_params.root";
17  TString digiFile = "digi.root";
18  TString recoFile = "reco.root";
19 
20  TString outFile = "out.root"; //of the FairRunAna
21  TFile *out = TFile::Open("benchmark.root", "RECREATE"); //output for the histograms
22 
23  int Ev_start = 0;
24  int Ev_end = 0; // take 0 for all events
25  TStopwatch timer;
26  timer.Start();
27 
28  // algorithm parameters:
29 
30  double t0Dist_plus = 10;
31  double t0Dist_minus = 4;
32 
33  // ----- Initialize Run manager -------------------------------------------
34  FairRunAna *fRun = new FairRunAna();
35  fRun->SetInputFile(recoFile);
36  fRun->AddFriend(digiFile);
37  fRun->AddFriend(simFile);
38  fRun->SetOutputFile(outFile);
39  fRun->SetUseFairLinks(kTRUE);
40 
41  // ----- Parameter database --------------------------------------------
42  TString allDigiFile = gSystem->Getenv("VMCWORKDIR");
43  allDigiFile += "/macro/params/all.par";
44 
45  FairRuntimeDb* rtdb = fRun->GetRuntimeDb();
46  FairParRootFileIo* parInput1 = new FairParRootFileIo();
47  parInput1->open(parFile.Data());
48 
49  FairParAsciiFileIo* parIo1 = new FairParAsciiFileIo();
50  parIo1->open(allDigiFile.Data(), "in");
51  rtdb->setFirstInput(parInput1);
52  rtdb->setSecondInput(parIo1);
53 
54  fRun->Init();
55 
56  // used variables
57 
58  double timeStamp;
59  double t0_MC;
60  double dist1,dist2;
61  int t0_candidates = 0, t0_ghosts = 0, t0_good = 0, t0_missed = 0, t0_double = 0, t0_MCs = 0;
62 
63  std::multiset<double> set_t0MC, set_t0Candidates;
64  std::multiset<double>::iterator it_t0Can, it_t0Can2, it_t0CanOld, it_t0MC;
65 
66  // output objects for .root file:
67 
68  // histogram parameters
69  int binN = 1000, binStart = 0, binEnd = 5000;
70 
71  TH1D *h_t0_MC = new TH1D("h_t0_MC", "t0 ;time [ns]", binN, binStart,binEnd);
72  TH1D *h_t0Candidates = new TH1D("h_t0Candidates", "t0 ;time [ns]", binN,binStart, binEnd);
73  THStack *hs_timeline = new THStack("hs_timeline","event time and T0 candidates ;time [ns]");
74 
75  TH1D *h_t0Resolution = new TH1D("h_t0Resolution","t0 Resolution ;time [ns]", 10*(t0Dist_plus+t0Dist_minus), -t0Dist_minus, t0Dist_plus);
76  TH1D *h_results = new TH1D("h_results", "results",6,0,5);
77 
78  // ----------------- Initialize Used Variables and Branches ------------------------------
79  FairRootManager* ioman = FairRootManager::Instance();
80 
81  TClonesArray* t0CandidateArray = (TClonesArray*) ioman->GetObject("T0Candidates"); // if not "initialized" here it may produces error at the first access
82 
83  FairTimeStamp *t0Candidate;
84 
85  //---------------------------------FairEventHeader ----------------------------
86  FairEventHeader* evtHeader = NULL;
87  TFile* digFile = TFile::Open(digiFile);
88  TTree* digTree = (TTree*) digFile->Get("pndsim");
89  digTree->SetBranchAddress("EventHeader.", &evtHeader);
90  //-------------------------------------------------------------------
91 
92  if (Ev_end == 0)
93  Ev_end = Int_t((ioman->GetInChain())->GetEntries());
94  cout << " EndEvent = " << Ev_end << endl;
95 
96  //****************************************************************************************
97 // Data are collected in sets for the benchmark and in addition are stored in histograms
98 
99  for (int i_Event = Ev_start; i_Event < Ev_end; i_Event++) { // ------- Loop over events
100 
101  digTree->GetEntry(i_Event);
102  ioman->ReadEvent(i_Event);
103  cout << "event: " << i_Event << " time: " << evtHeader->GetEventTime()
104  << endl;
105 
106  if (i_Event < Ev_end - 2) { // -2 because the digi and the reco stage add an additional "event" to write out the remaining data in the buffers
107  t0_MC = evtHeader->GetEventTime();
108  if (t0_MC < binEnd)
109  h_t0_MC->Fill(t0_MC, -0.5);
110 
111  set_t0MC.insert(t0_MC);
112  }
113 
114  for (Int_t i_Array = 0; i_Array < t0CandidateArray->GetEntries();
115  i_Array++) { //scitHit array loop
116 
117  t0Candidate = (FairTimeStamp*) t0CandidateArray->At(i_Array);
118  timeStamp = t0Candidate->GetTimeStamp();
119  if (timeStamp < binEnd)
120  h_t0Candidates->Fill(timeStamp);
121 
122  set_t0Candidates.insert(timeStamp);
123 
124  } // end of scit array loop
125 
126  } // end of Event loop
127 
128  // ********************* Analyse Results of the T0 algorithm *************************
129 
130 
131  t0_candidates = set_t0Candidates.size();
132  t0_MCs = set_t0MC.size();
133 
134  for (it_t0MC = set_t0MC.begin(); it_t0MC != set_t0MC.end();it_t0MC++){
135 
136  it_t0Can = set_t0Candidates.lower_bound(*it_t0MC-t0Dist_minus); // get first possible T0 Candidate
137 
138  if(it_t0Can == set_t0Candidates.end()){ // if no possible T0 candidte is found (end of set)
139  t0_missed++;
140  continue;
141  }
142 
143  dist1 = *it_t0Can - *it_t0MC; // check distance between t0 cndidate and t0MC
144  if (dist1 > t0Dist_plus){ // if distance is to large => t0_MC was missed
145  t0_missed++;
146  continue;
147  }
148  it_t0Can2 = it_t0Can;// check if the next t0_candidate may fits better!
149  it_t0Can2++;
150  if(it_t0Can2 != set_t0Candidates.end()){
151  dist2 = *it_t0Can2 - *it_t0MC;
152  if(abs(dist2) < abs(dist1)){
153  it_t0Can = it_t0Can2;// if its better it replace the t0Candidate
154  dist1 = dist2;
155  }
156  } // now it_t0Can is the best fitting t0Candidate and dist1 is its distance
157 
158  t0_good++;
159  h_t0Resolution->Fill(dist1);
160  if(it_t0CanOld == it_t0Can) t0_double++; // now check a potential double pick of this t0_Candidate
161  it_t0CanOld = it_t0Can; // save the picked t0 candidate for the next double pick check
162  }
163 
164  t0_ghosts = t0_candidates - t0_good;
165 
166  h_results->Fill("t0_MCs",t0_MCs);
167  h_results->Fill("t0_candidates",t0_candidates);
168  h_results->Fill("t0_good",t0_good);
169  h_results->Fill("t0_double",t0_double);
170  h_results->Fill("t0_missed",t0_missed);
171  h_results->Fill("t0_ghosts",t0_ghosts);
172  // write out all stuff
173 
174  h_t0_MC->SetLineColor(6);
175  h_t0_MC->SetFillColor(6);
176 
177  h_t0Candidates->SetLineColor(1);
178  h_t0Candidates->SetFillColor(1);
179 
180  hs_timeline->Add(h_t0Candidates);
181  hs_timeline->Add(h_t0_MC);
182 
183  TCanvas *c = new TCanvas;
184  h_results->Draw();
185  c->SaveAs("results.pdf");
186 
187  out->cd();
188 
189  h_t0_MC->Write("", TObject::kOverwrite);
190  h_t0Candidates->Write("", TObject::kOverwrite);
191 
192  hs_timeline->Write("", TObject::kOverwrite);
193 
194  h_results->Write("", TObject::kOverwrite);
195 
196  timer.Stop();
197  Double_t rtime = timer.RealTime();
198  Double_t ctime = timer.CpuTime();
199  cout << endl << endl;
200  cout << "Macro finished succesfully." << endl;
201  cout << "Output file is " << outFile << endl;
202  cout << "Parameter file is " << parFile << endl;
203  cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
204  cout << endl;
205  // -----------
206  cout << " Test passed" << endl;
207  cout << " All ok " << endl;
208 
209  CloseGeoManager();
210  return 0;
211 }
TString outFile
Definition: hit_dirc.C:17
TString digiFile
Definition: bump_emc.C:20
TString allDigiFile
Definition: hit_muo.C:36
void CloseGeoManager()
Definition: QA/auxi.C:11
FairRunAna * fRun
Definition: hit_dirc.C:58
TString simFile
Definition: bump_emc.C:11
Double_t
TString parFile
Definition: hit_dirc.C:14
TStopwatch timer
Definition: hit_dirc.C:51
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
TFile * out
Definition: reco_muo.C:20
FairParRootFileIo * parInput1
Definition: hit_dirc.C:67
Double_t ctime
Definition: hit_dirc.C:114
FairParAsciiFileIo * parIo1
Definition: bump_emc.C:53
std::string recoFile
cout<<"will loop over "<< t-> GetEntries()
Definition: root2ascii.C:17
Double_t rtime
Definition: hit_dirc.C:113