FairRoot/PandaRoot
tut_ana_task_d0.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_d0(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";
64 
65  // *** initialization
66  FairLogger::GetLogger()->SetLogToFile(kFALSE);
67  FairRuntimeDb* rtdb = fRun->GetRuntimeDb();
68 
69  // *** setup parameter database
70  FairParRootFileIo* parIO = new FairParRootFileIo();
71  parIO->open(inParFile);
72  FairParAsciiFileIo* parIOPid = new FairParAsciiFileIo();
73  parIOPid->open(pidParFile.Data(),"in");
74 
75  rtdb->setFirstInput(parIO);
76  rtdb->setSecondInput(parIOPid);
77  rtdb->setOutput(parIO);
78 
79  fRun->SetOutputFile(OutFile);
80 
81  // *** HERE OUR TASK GOES!
82  PndTutAnaTaskD0 *anaTask = new PndTutAnaTaskD0(pbarmom);
83  fRun->AddTask(anaTask);
84 
85  // *** and run analysis
86  fRun->Init();
87  fRun->Run(0,nevts);
88 }
Double_t x0
Definition: checkhelixhit.C:70
Int_t i
Definition: run_full.C:25
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:26
bool checkfile(TString fn)
static void ForceConstantBz(Double_t bz=0.)
Force a constant B field value for all positions.
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
void tut_ana_task_d0(TString pref="pid_complete.root", int min=-1, int max=1, int nevts=0)
TTree * t
Definition: bump_analys.C:13
void attachFiles(FairRunAna *fRun, TString pref, int min, int max)