FairRoot/PandaRoot
dec13/tut_ana.C
Go to the documentation of this file.
1 class FairRunAna;
2 
3 // Check if file exists and readable
4 bool checkfile(TString fn)
5 {
6  bool fileok=true;
7  TFile fff(fn, "READ");
8  if (fff.IsZombie()) fileok=false;
9  TTree *t=(TTree*)fff.Get("pndsim");
10  if (t==0x0) fileok=false;
11 
12  if (!fileok) cout <<"Skipping broken file '"<<fn<<"'"<<endl;
13  fff.Close();
14 
15  return fileok;
16 }
17 
18 // Add many input files to FairRunAna
19 void attachFiles(FairRunAna* fRun, TString pref, int min, int max)
20 {
21  bool firstfile=true;
22  for (int i=min;i<=max;++i) {
23  TString fname = TString::Format("%s_%d_pid.root",pref.Data(),i);
24 
25  if (checkfile(fname) ) {
26  if (firstfile) fRun->SetInputFile(fname);
27  else fRun->AddFile(fname);
28  firstfile=false;
29  }
30  }
31 }
32 
33 void tut_ana(TString pref="pid_complete.root", int min=-1, int max=1, int nevts=0)
34 {
35  TString OutFile, inParFile;
36 
37  // *** add input files
38  FairRunAna *fRun= new FairRunAna();
39 
40  // *** just open one file
41  if (min<0)
42  {
43  // *** set input file, output file and par file
44  OutFile = "ana.root";
45  inParFile = "simparams.root";
46 
47  fRun->SetInputFile(pref);
48  }
49  // *** attach many input files
50  else {
51  // *** set output file and par file
52  OutFile = TString::Format("%s_ana_%d_%d.root",pref.Data(), min, max);
53  inParFile = TString::Format("%s_%d_par.root",pref.Data(), min);
54 
55  attachFiles(fRun, pref, min, max);
56  }
57 
58  // *** PID table with selection thresholds; can be modified by the user
59  TString pidParFile = TString(gSystem->Getenv("VMCWORKDIR"))+"/macro/params/all.par";
60 
61  // *** initialization
62  FairLogger::GetLogger()->SetLogToFile(kFALSE);
63  FairRuntimeDb* rtdb = fRun->GetRuntimeDb();
64 
65  // *** setup parameter database
66  FairParRootFileIo* parIO = new FairParRootFileIo();
67  parIO->open(inParFile);
68  FairParAsciiFileIo* parIOPid = new FairParAsciiFileIo();
69  parIOPid->open(pidParFile.Data(),"in");
70 
71  rtdb->setFirstInput(parIO);
72  rtdb->setSecondInput(parIOPid);
73  rtdb->setOutput(parIO);
74 
75  fRun->SetOutputFile("dummyout.root");
76  fRun->Init();
77 
78  // *** create an output file for all histograms
79  TFile *out = TFile::Open(OutFile,"RECREATE");
80 
81  // *** the data reader object
82  PndAnalysis* theAnalysis = new PndAnalysis();
83  if (nevts==0) nevts= theAnalysis->GetEntries();
84 
85  int i=0;
86 
87  // *** the event loop
88  while (theAnalysis->GetEvent() && i++<nevts)
89  {
90  if ((i%100)==0) cout<<"evt " << i << endl;
91 
92  // ***
93  // *** HERE YOUR ANALYSIS CODE GOES!
94  // ***
95 
96  }
97 
98  // *** write out all the histos
99  out->cd();
100  out->Save();
101  out->Close();
102 
103 }
Int_t GetEntries()
Double_t x0
Definition: checkhelixhit.C:70
void attachFiles(FairRunAna *fRun, TString pref, int min, int max)
Definition: dec13/tut_ana.C:19
Int_t i
Definition: run_full.C:25
bool checkfile(TString fn)
Definition: dec13/tut_ana.C:4
void tut_ana(TString pref="pid_complete.root", int min=-1, int max=1, int nevts=0)
Definition: dec13/tut_ana.C:33
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:26
FairRunAna * fRun
Definition: hit_dirc.C:58
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:25
TFile * out
Definition: reco_muo.C:20
TTree * t
Definition: bump_analys.C:13
Int_t GetEvent(Int_t n=-1)