FairRoot/PandaRoot
Typedefs | Functions
scripts/prod_ana.C File Reference

Go to the source code of this file.

Typedefs

typedef std::vector< TStringStrVec
 

Functions

bool checkfile (TString fn)
 
StrVec SplitString (TString s, TString delim=",")
 
StrVec ReadModeTab (TString filename)
 
int prod_ana (TString prefix="", int from=1, int to=1, int mode=0, int nevts=0)
 

Typedef Documentation

typedef std::vector<TString> StrVec

Definition at line 16 of file scripts/prod_ana.C.

Function Documentation

bool checkfile ( TString  fn)

Definition at line 18 of file scripts/prod_ana.C.

References t, and x0.

Referenced by prod_ana().

19 {
20  bool fileok=true;
21  TFile fff(fn);
22  if (fff.IsZombie()) fileok=false;
23  TTree *t=(TTree*)fff.Get("pndsim");
24  if (t==0x0) fileok=false;
25 
26  if (!fileok) cout <<"Skipping broken file '"<<fn<<"'"<<endl;
27  return fileok;
28 }
Double_t x0
Definition: checkhelixhit.C:70
TTree * t
Definition: bump_analys.C:13
int prod_ana ( TString  prefix = "",
int  from = 1,
int  to = 1,
int  mode = 0,
int  nevts = 0 
)

Definition at line 67 of file scripts/prod_ana.C.

References checkfile(), ctime, Double_t, RhoCalculationTools::ForceConstantBz(), fRun, i, mode, mp, outFile, printf(), ReadModeTab(), rtime, run, PndSimpleCombinerTask::SetPidAlgo(), SplitString(), sqrt(), TString, v, and X.

68 {
69  // Read table with modes
70  TString path = TString(gSystem->Getenv("VMCWORKDIR"))+"/macro/production/scripts/";
71  TString modefile = path+"table_modes_prod_ana.txt";
72  std::vector<TString> modetab = ReadModeTab(modefile);
73  int modefromtab = -1;
74 
75  // ****************************************
76  // configuration for PndSimpleCombinerTask
77  //
78  // APPLY CHANGES HERE!
79  // ****************************************
80 
81 
82  double Mom = 6.569;
83 
84  TString anadecay = "D0 -> K- pi+; pbp->D0 D0_bar";
85  TString anaparms = "fit4cbest:mwin=0.8";
86 
87  // we look in the analysis table for analysis mode #mode
88  for (int i=0; i<(int)modetab.size(); ++i)
89  {
90  StrVec v = SplitString(modetab[i],"//");
91 
92  if (v[0].Atoi() == mode)
93  {
94  Mom = v[1].Atof();
95  anadecay = v[2];
96  anaparms = v[3];
97  modefromtab = i;
98  anaparms += ":algo=PidAlgoMvd;PidAlgoMdtHardCuts;PidAlgoDrc;PidAlgoStt;PidAlgoEmcBayes;PidAlgoSciT;PidAlgoFtof";
99  }
100  }
101 
102  // this sets fast/full sim mode automatically by checking for input file name suffix
103  //bool fastsim = (prefix.EndsWith(".root") && prefix.Contains("_fsim")) || gSystem->AccessPathName(Form("%s_%d_pid.root",prefix.Data(),from));
104 
105  // --> if not wanted, set to either true or false
106  bool fastsim = false;
107 
108  // the run number for PndSimpleAnalysis task;
109  // running over multiple files sets run number to first input file number
110  int run = from;
111 
112  // run software trigger (trigger definition might be outdated)
113  bool runST = false;
114 
115 
116  // ****************************************
117  // APPLY CHANGES HERE!
118  //
119  // configuration for PndSimpleCombinerTask
120  // ****************************************
121 
122 
123  // Print some help text
124  if (prefix=="" || prefix=="!")
125  {
126  cout << "Example analysis macro using PndSimpleCombiner(Task). !! MODIFY for your purpose !!\n\n";
127  cout << "USAGE:\n";
128  cout << "prod_ana.C( <pref>, <from>, <to>, [mode], [nevt] )\n\n";
129  cout << " <pref> : input/output file names prefix or full input file name\n";
130  cout << " <from> : first run number\n";
131  cout << " <to> : last run number\n";
132  cout << " [mode] : arbitrary mode number; default: 0\n";
133  cout << " [nevt] : number of events; default: 0 = all\n\n";
134  cout << "Example : root -l -b -q 'prod_ana.C(\"mysim\",1,20,10)'\n\n";
135 
136  if (modetab.size()>0) cout <<"\nFound "<<modetab.size()<<" analysis modes in "<<modefile<<".\n"<<endl;
137 
138  if (modetab.size()>0 && prefix=="!")
139  {
140  for (int i=0;i <(int)modetab.size(); ++i)
141  {
142  StrVec v = SplitString(modetab[i],"//");
143  printf("(%02d) Mode %4s @ %s = %7s GeV : %s [PARM: %s]\n", i, v[0].Data(), v[1].Atof()<0 ? "E" : "p", v[1].Data(), v[2].Data(), v[3].Data());
144  }
145  cout <<endl;
146  }
147  }
148 
149  // if Mom<0, interprete as -E_cm
150  double mp = 0.938272;
151  double Ecm = 0;
152 
153  // if mom<0, it's -E_cm -> compute mom
154  if (Mom<0)
155  {
156  Ecm = -Mom;
157  double X = (Mom*Mom-2*mp*mp)/(2*mp);
158  Mom = sqrt(X*X-mp*mp);
159  }
160  else
161  {
162  Ecm = sqrt(pow(sqrt(Mom*Mom + mp*mp) + mp,2) - Mom*Mom);
163  }
164 
165  // Print current analysis configuration
166  cout << "------------------------------------------------\n";
167  cout << " Current analysis configuration\n";
168  cout << "------------------------------------------------\n";
169  printf( " Mode : %d (%d)\n", mode, modefromtab);
170  printf( " p_beam : %.3f GeV/c\n", Mom);
171  printf( " E_cm : %.3f GeV\n", Ecm);
172  cout << " reco : "<<anadecay<<endl;
173  cout << " params : "<<anaparms<<endl;
174  cout << " softtrig : "<<(runST?"yes":"no")<<endl;
175  cout << "------------------------------------------------\n\n";
176 
177  // if started without parameters -> stop here
178  prefix.ReplaceAll("!","");
179  if (prefix=="") return 0;
180 
181 
182  TString suffix = fastsim ? "fsim" : "pid";
183 
184  TString outFile = TString::Format("%s_ana_%d_%d.root",prefix.Data(), from, to);
185  //TString inParFile = TString::Format("%s_%d_par.root",prefix.Data(),from);
186  TString firstFile = TString::Format("%s_%d_%s.root",prefix.Data(),from,suffix.Data());
187 
188  // if prefix is a full file name, we skip the run number in the name
189  if (prefix.EndsWith(".root"))
190  {
191  firstFile = prefix;
192  outFile = prefix;
193  outFile.ReplaceAll(".root","_ana.root");
194  //inParFile = prefix; inParFile.ReplaceAll("_pid.root","_par.root");
195  to = from;
196  }
197  // if only one file, we name outfile to 'prefix_<run>_ana.root'
198  else if (from>=to) outFile = TString::Format("%s_%d_ana.root", prefix.Data(), from);
199 
200 
201  // Start a stop watch
202  TStopwatch fTimer;
203  fTimer.Start();
204 
205  // --------------------------------
206  // Create the Analysis run manager
207  // --------------------------------
208  FairRunAna *fRun = new FairRunAna();
209  FairFileSource *fSrc = new FairFileSource(firstFile);
210 
211  // *** Add pid files
212  for (int i=from+1;i<=to;++i)
213  {
214  TString fname = TString::Format("%s_%d_%s.root",prefix.Data(),i,suffix.Data());
215  if ( checkfile(fname) ) fSrc->AddFile(fname);
216  }
217 
218  fRun->SetSource(fSrc);
219 
220  // *** PID table with selection thresholds; can be modified by the user
221  TString pidParFile = TString(gSystem->Getenv("VMCWORKDIR"))+"/macro/params/all.par";
222 
223  // *** initialization
224  FairLogger::GetLogger()->SetLogToFile(kFALSE);
225 
226  /*
227  FairRuntimeDb* rtdb = fRun->GetRuntimeDb();
228 
229  // *** setup parameter database
230  FairParRootFileIo* parIO = new FairParRootFileIo();
231  parIO->open(inParFile);
232  FairParRootFileIo* parIOdummy = new FairParRootFileIo();
233  parIO->open("dummypar.root");
234  FairParAsciiFileIo* parIOPid = new FairParAsciiFileIo();
235  parIOPid->open(pidParFile.Data(),"in");
236  rtdb->setFirstInput(parIO);
237 
238  rtdb->setFirstInput(parIO);
239  rtdb->setSecondInput(parIOPid);
240  rtdb->setOutput(parIOdummy);
241  rtdb->setContainersStatic();
242  */
243 
244  fRun->SetOutputFile(outFile);
245 
246  //---------------------Create and Set the Field(s)----------
247  //PndMultiField *fField= new PndMultiField("AUTO");
248  //fRun->SetField(fField);
249 
251 
252  // ***
253  // *** HERE YOUR ANALYSIS CODE GOES!
254  // ***
255 
256 
257  // *****************************
258  // *** PndSimpleCombinerTask ***
259  // *****************************
260 
261  // PID algorithm for the PndSimpleCombinerTask (for Eventshape variables)
262  TString pidalgo = "PidAlgoEmcBayes;PidAlgoDrc;PidAlgoDisc;PidAlgoStt;PidAlgoMdtHardCuts;PidAlgoSciT";
263  if (fastsim) pidalgo = "PidChargedProbability";
264 
265  // allow shortcuts
266  anadecay.ReplaceAll("pbp","pbarpSystem");
267  anadecay.ReplaceAll("pbp0","pbarpSystem0");
268  anaparms.ReplaceAll("pbp","pbarpSystem");
269  anaparms.ReplaceAll("pbp0","pbarpSystem0");
270 
271  // Prevent generator from throwing a lot of warnings
272  //TLorentzVector fIni(0,0,Mom,0.938272+sqrt(Mom*Mom+0.938272*0.938272));
273  TDatabasePDG::Instance()->AddParticle("ppSystem","ppSystem",3,kFALSE,0.1,6, "",98888);
274  TDatabasePDG::Instance()->AddParticle("pbarpSystem","pbarpSystem",3,kFALSE,0.1,0, "",88888);
275  TDatabasePDG::Instance()->AddParticle("pbarpSystem0","pbarpSystem0",3,kFALSE,0.1,0, "",88880);
276 
277  if (anadecay!="")
278  {
279  if (fastsim) anaparms+=":algo="+pidalgo;
280  PndSimpleCombinerTask *scTask = new PndSimpleCombinerTask(anadecay, anaparms, Mom, run, mode);
281  scTask->SetPidAlgo(pidalgo);
282 
283  fRun->AddTask(scTask);
284  }
285 
286  // *****************************
287  // *** PndSimpleCombinerTask ***
288  // *****************************
289 
290 
291 
292  // *****************************
293  // *** PndParticleQATask ***
294  // *****************************
295 
296  // do particle QA?
297  bool partQA = (anaparms.Contains("qapart"));
298  bool mc = !(anaparms.Contains("!mc"));
299  bool neut = !(anaparms.Contains("!neut"));
300  bool chrg = !(anaparms.Contains("!chrg"));
301 
302  if (partQA)
303  {
304  PndParticleQATask *partQaTask = new PndParticleQATask(fastsim, chrg, neut, mc, mode); // particle QA task
305  fRun->AddTask(partQaTask);
306  }
307 
308  // *****************************
309  // *** PndParticleQATask ***
310  // *****************************
311 
312 
313 
314  // ***********************
315  // *** SoftTriggerTask ***
316  // ***********************
317 
318  if (runST)
319  {
320  // this file contains the trigger line definitions
321  TString triggercfg = TString(gSystem->Getenv("VMCWORKDIR"))+"/softrig/triggerlines.cfg"; // fullsim trigger definitions
322  if (fastsim) triggercfg = TString(gSystem->Getenv("VMCWORKDIR"))+"/softrig/triggerlines_fsim.cfg"; // fastsim trigger definitions
323 
324  PndSoftTriggerTask *stTask = new PndSoftTriggerTask(Mom, 0, run, triggercfg);
325 
326  if (fastsim) stTask->SetFastSimDefaults();
327  else stTask->SetFullSimDefaults();
328 
329  fRun->AddTask(stTask);
330  }
331 
332  // ***********************
333  // *** SoftTriggerTask ***
334  // ***********************
335 
336 
337  // *** and run analysis
338  fRun->Init();
339  fRun->Run(0,nevts);
340 
341  //------------------------Print some info and exit----------------
342  fTimer.Stop();
343  FairSystemInfo sysInfo;
344  Float_t maxMemory=sysInfo.GetMaxMemory();
345  Double_t rtime = fTimer.RealTime();
346  Double_t ctime = fTimer.CpuTime();
347 
348  Float_t cpuUsage=ctime/rtime;
349 
350  cout << endl;
351  cout << "[INFO ] Macro call : prod_fsim.C(\""<<prefix<<"\", "<<from<<", "<<to<<", "<<mode<<", "<<nevts<<")" <<endl;
352  cout << "[INFO ] Output file : " << outFile << endl;
353  cout << "[INFO ] Real time : " << rtime << " s, CPU time " << ctime << "s" << endl;
354  cout << "[INFO ] CPU usage : " << cpuUsage*100. << "%" << endl;
355  cout << "[INFO ] Max Memory : " << maxMemory << " MB" << endl;
356  cout << "[INFO ] Macro finished successfully." << endl<<endl;
357  return 0;
358 }
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
Int_t run
Definition: autocutx.C:47
Int_t i
Definition: run_full.C:25
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
TString outFile
Definition: hit_dirc.C:17
void SetPidAlgo(TString algo)
__m128 v
Definition: P4_F32vec4.h:4
static const double mp
Definition: mzparameters.h:11
static void ForceConstantBz(Double_t bz=0.)
Force a constant B field value for all positions.
FairRunAna * fRun
Definition: hit_dirc.C:58
Int_t mode
Definition: autocutx.C:47
StrVec ReadModeTab(TString filename)
Double_t
StrVec SplitString(TString s, TString delim=",")
std::vector< TString > StrVec
Double_t ctime
Definition: hit_dirc.C:114
double X
Definition: anaLmdDigi.C:68
Double_t rtime
Definition: hit_dirc.C:113
bool checkfile(TString fn)
StrVec ReadModeTab ( TString  filename)

Definition at line 47 of file scripts/prod_ana.C.

References res, and TString.

Referenced by prod_ana().

48 {
49  ifstream input(filename.Data(), std::ifstream::in);
50 
51  StrVec res;
52 
53  for( std::string line; getline( input, line ); )
54  {
55  TString modeline(line);
56  if (modeline.Contains("#")) modeline = modeline(0, modeline.Index("#"));
57  modeline = modeline.Strip(TString::kBoth);
58  if (modeline!="") res.push_back(TString(modeline));
59  }
60 
61  input.close();
62 
63  return res;
64 }
Int_t res
Definition: anadigi.C:166
std::vector< TString > StrVec
const string filename
StrVec SplitString ( TString  s,
TString  delim = "," 
)

Definition at line 30 of file scripts/prod_ana.C.

References s, TString, and v.

Referenced by prod_ana().

31 {
32  StrVec v;
33  s.ReplaceAll("\t"," ");
34  s += delim;
35 
36  while (s.Contains(delim))
37  {
38  TString tok = s(0,s.Index(delim));
39  s.Remove(0,tok.Length()+delim.Length());
40  tok = (TString)tok.Strip(TString::kBoth);
41  v.push_back(tok);
42  }
43 
44  return v;
45 }
TLorentzVector s
Definition: Pnd2DStar.C:50
__m128 v
Definition: P4_F32vec4.h:4
std::vector< TString > StrVec