FairRoot/PandaRoot
dec13/tut_ana_task.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_task(TString pref="pid_complete.root", int min=-1, int max=1, int nevts=0)
34 {
35  TString OutFile, inParFile;
36 
37  // pbarmom for analysis task
38  double pbarmom = 9.808065;
39 
40  // *** add input files
41  FairRunAna *fRun= new FairRunAna();
42 
43  // *** just open one file
44  if (min<0)
45  {
46  // *** set input file, output file and par file
47  OutFile = "ana.root";
48  inParFile = "simparams.root";
49 
50  fRun->SetInputFile(pref);
51  }
52  // *** attach many input files
53  else {
54  // *** set output file and par file
55  OutFile = TString::Format("%s_ana_%d_%d.root",pref.Data(), min, max);
56  inParFile = TString::Format("%s_%d_par.root",pref.Data(), min);
57 
58  attachFiles(fRun, pref, min, max);
59  }
60 
61  // *** PID table with selection thresholds; can be modified by the user
62  TString pidParFile = TString(gSystem->Getenv("VMCWORKDIR"))+"/macro/params/all.par";
63 
64  // *** initialization
65  FairLogger::GetLogger()->SetLogToFile(kFALSE);
66  FairRuntimeDb* rtdb = fRun->GetRuntimeDb();
67 
68  // *** setup parameter database
69  FairParRootFileIo* parIO = new FairParRootFileIo();
70  parIO->open(inParFile);
71  FairParAsciiFileIo* parIOPid = new FairParAsciiFileIo();
72  parIOPid->open(pidParFile.Data(),"in");
73 
74  rtdb->setFirstInput(parIO);
75  rtdb->setSecondInput(parIOPid);
76  rtdb->setOutput(parIO);
77 
78  fRun->SetOutputFile(OutFile);
79 
80  // *** HERE OUR TASK GOES!
81  PndTutAnaTask *anaTask = new PndTutAnaTask(pbarmom);
82  fRun->AddTask(anaTask);
83 
84  // *** and run analysis
85  fRun->Init();
86  fRun->Run(0,nevts);
87 }
Double_t x0
Definition: checkhelixhit.C:70
Int_t i
Definition: run_full.C:25
void tut_ana_task(TString pref="pid_complete.root", int min=-1, int max=1, int nevts=0)
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
bool checkfile(TString fn)
void attachFiles(FairRunAna *fRun, TString pref, int min, int max)
TTree * t
Definition: bump_analys.C:13