FairRoot/PandaRoot
dayone-2017/fastsim/prod_ana.C
Go to the documentation of this file.
1 // --------------------------------------------------------------------------------------
2 //
3 // Example analysis macro using PndSimpleCombiner(Task). !! MODIFY for your purpose !!
4 //
5 // USAGE:
6 // prod_ana.C( <pref>, <from>, <to>, [nevt] )
7 //
8 // <pref> : input/output file names prefix or full input file name
9 // <from> : first run number
10 // <to> : last run number
11 // [mode] : arbitrary mode number; default: 0
12 // [nevt] : number of events; default: 0 = all
13 //
14 // --------------------------------------------------------------------------------------
15 
17 {
18  bool fileok=true;
19  TFile fff(fn);
20  if (fff.IsZombie()) fileok=false;
21  TTree *t=(TTree*)fff.Get("pndsim");
22  if (t==0x0) fileok=false;
23 
24  if (!fileok) cout <<"Skipping broken file '"<<fn<<"'"<<endl;
25  return fileok;
26 }
27 
28 int prod_ana(TString prefix="", int from=1, int to=1, int mode=0, int nevts=0)
29 {
30 
31  // ****************************************
32  // configuration for PndSimpleCombinerTask
33  //
34  // APPLY CHANGES HERE!
35  // ****************************************
36 
37  double Mom = 10.;
38  TString anadecay = "";
39  TString anaparms = "qapart";
40 
41  // for 2 phi @ 2.3 GeV
42  if (prefix.Contains("phi"))
43  {
44  Mom = -2.3;
45  anadecay = "phi -> K+ K-; pbp -> phi phi";
46  anaparms = "mwin=0.4:mwin(phi)=0.3:qarec:fit4c:pidk=Loose";
47  }
48  // for J/psi (e+ e-) pi+ pi- @ 3.872 GeV
49  else if (prefix.Contains("Jee"))
50  {
51  Mom = -3.872;
52  anadecay = "J/psi -> e+ e-; pbp -> J/psi pi+ pi-";
53  anaparms = "mwin(J/psi)=2.6|3.3:qaevs:qarec:fit4c:pide=Loose";
54  }
55  // for J/psi (mu+ mu-) pi+ pi- @ 3.872 GeV
56  else if (prefix.Contains("Jmm"))
57  {
58  Mom = -3.872;
59  anadecay = "J/psi -> mu+ mu-; pbp -> J/psi pi+ pi-";
60  anaparms = "mwin(J/psi)=2.6|3.3:qaevs:qarec:fit4c:pidmu=Loose";
61  }
62  // for pbar p -> e+ e- @ 1.5 GeV/c
63  else if (prefix.Contains("ppee"))
64  {
65  Mom = 1.5;
66  anadecay = "pbp -> e+ e-";
67  anaparms = "mwin(pbp)=1.5|2.5:qaevs:qarec:fit4c:pide=Loose";
68  }
69  // for pbar p -> e+ e- @ 5.5 GeV
70  else if (prefix.Contains("etac1"))
71  {
72  Mom = -5.5;
73  anadecay = "pi0->gamma gamma; eta->gamma gamma; J/psi->e+ e-; chi_1c -> J/psi gamma; eta_c1 -> chi_1c pi0 pi0; pbp -> eta_c1 eta";
74  anaparms = "mwin=0.8:mwin(pi0)=0.024:mwin(eta)=0.048:qaevs:qarec:fit4cbest<200:pide=Loose:!ntp0:!ntp1";
75  }
76  // default (for tests)
77  else
78  {
79  Mom = -5.5;
80  anadecay = "pi0->gamma gamma";
81  anaparms = "mwin(pi0)=0.06";
82 
83  }
84 
85  // this sets fast/full sim mode automatically by checking for input file name suffix
86  //bool fastsim = (prefix.EndsWith(".root") && prefix.Contains("_fsim")) || gSystem->AccessPathName(Form("%s_%d_pid.root",prefix.Data(),from));
87 
88  // --> if not wanted, set to either true or false
89  bool fastsim = true;
90 
91  // the run number for PndSimpleAnalysis task;
92  // running over multiple files sets run number to first input file number
93  int run = from;
94 
95  // run software trigger (trigger definition might be outdated)
96  bool runST = false;
97 
98 
99 
100  // ****************************************
101  // APPLY CHANGES HERE!
102  //
103  // configuration for PndSimpleCombinerTask
104  // ****************************************
105 
106 
107  // Print some help text
108  if (prefix=="")
109  {
110  cout << "Example analysis macro using PndSimpleCombiner(Task). !! MODIFY for your purpose !!\n\n";
111  cout << "USAGE:\n";
112  cout << "prod_ana.C( <pref>, <from>, <to>, [mode], [nevt] )\n\n";
113  cout << " <pref> : input/output file names prefix or full input file name\n";
114  cout << " <from> : first run number\n";
115  cout << " <to> : last run number\n";
116  cout << " [mode] : arbitrary mode number; default: 0\n";
117  cout << " [nevt] : number of events; default: 0 = all\n\n";
118  }
119 
120  // if Mom<0, interprete as -E_cm
121  double mp = 0.938272;
122  double Ecm = 0;
123 
124  // if mom<0, it's -E_cm -> compute mom
125  if (Mom<0)
126  {
127  Ecm = -Mom;
128  double X = (Mom*Mom-2*mp*mp)/(2*mp);
129  Mom = sqrt(X*X-mp*mp);
130  }
131  else
132  {
133  Ecm = sqrt(pow(sqrt(Mom*Mom + mp*mp) + mp,2) - Mom*Mom);
134  }
135 
136  // Print current analysis configuration
137  cout << "------------------------------------------------\n";
138  cout << " Current analysis configuration\n";
139  cout << "------------------------------------------------\n";
140  printf( " p_beam : %.3f GeV/c\n",Mom);
141  printf( " E_cm : %.3f GeV\n",Ecm);
142  cout << " reco : "<<anadecay<<endl;
143  cout << " params : "<<anaparms<<endl;
144  cout << " softtrig : "<<(runST?"yes":"no")<<endl;
145  cout << "------------------------------------------------\n\n";
146 
147  // if started without parameters -> stop here
148  if (prefix=="") return 0;
149 
150 
151  TString suffix = fastsim ? "fsim" : "pid";
152 
153  TString outFile = TString::Format("%s_ana_%d_%d.root",prefix.Data(), from, to);
154  //TString inParFile = TString::Format("%s_%d_par.root",prefix.Data(),from);
155  TString firstFile = TString::Format("%s_%d_%s.root",prefix.Data(),from,suffix.Data());
156 
157  // if prefix is a full file name, we skip the run number in the name
158  if (prefix.EndsWith(".root"))
159  {
160  firstFile = prefix;
161  outFile = prefix;
162  outFile.ReplaceAll(".root","_ana.root");
163  //inParFile = prefix; inParFile.ReplaceAll("_pid.root","_par.root");
164  to = from;
165  }
166  // if only one file, we name outfile to 'prefix_<run>_ana.root'
167  else if (from>=to) outFile = TString::Format("%s_%d_ana.root", prefix.Data(), from);
168 
169  int ffidx = from;
170  while (!checkfile(firstFile) && ffidx<=to) {ffidx++; firstFile = TString::Format("%s_%d_%s.root",prefix.Data(),ffidx,suffix.Data());}
171 
172 
173  // Start a stop watch
174  TStopwatch fTimer;
175  fTimer.Start();
176 
177  // --------------------------------
178  // Create the Analysis run manager
179  // --------------------------------
180  FairRunAna *fRun = new FairRunAna();
181  FairFileSource *fSrc = new FairFileSource(firstFile);
182 
183  // *** Add pid files
184  for (int i=ffidx+1;i<=to;++i)
185  {
186  TString fname = TString::Format("%s_%d_%s.root",prefix.Data(),i,suffix.Data());
187  if ( checkfile(fname) ) fSrc->AddFile(fname);
188  }
189 
190  fRun->SetSource(fSrc);
191 
192  // *** PID table with selection thresholds; can be modified by the user
193  TString pidParFile = TString(gSystem->Getenv("VMCWORKDIR"))+"/macro/params/all.par";
194 
195  // *** initialization
196  FairLogger::GetLogger()->SetLogToFile(kFALSE);
197 
198  /*
199  FairRuntimeDb* rtdb = fRun->GetRuntimeDb();
200 
201  // *** setup parameter database
202  FairParRootFileIo* parIO = new FairParRootFileIo();
203  parIO->open(inParFile);
204  FairParRootFileIo* parIOdummy = new FairParRootFileIo();
205  parIO->open("dummypar.root");
206  FairParAsciiFileIo* parIOPid = new FairParAsciiFileIo();
207  parIOPid->open(pidParFile.Data(),"in");
208  rtdb->setFirstInput(parIO);
209 
210  rtdb->setFirstInput(parIO);
211  rtdb->setSecondInput(parIOPid);
212  rtdb->setOutput(parIOdummy);
213  rtdb->setContainersStatic();
214  */
215 
216  fRun->SetOutputFile(outFile);
217 
218  //---------------------Create and Set the Field(s)----------
219  //PndMultiField *fField= new PndMultiField("AUTO");
220  //fRun->SetField(fField);
221 
223 
224  // ***
225  // *** HERE YOUR ANALYSIS CODE GOES!
226  // ***
227 
228 
229  // *****************************
230  // *** PndSimpleCombinerTask ***
231  // *****************************
232 
233  // PID algorithm for the PndSimpleCombinerTask (for Eventshape variables)
234  TString pidalgo = "PidAlgoEmcBayes;PidAlgoDrc;PidAlgoDisc;PidAlgoStt;PidAlgoMdtHardCuts;PidAlgoSciT";
235  if (fastsim) pidalgo = "PidChargedProbability";
236 
237  // allow shortcuts
238  anadecay.ReplaceAll("pbp","pbarpSystem");
239  anadecay.ReplaceAll("pbp0","pbarpSystem0");
240  anaparms.ReplaceAll("pbp","pbarpSystem");
241  anaparms.ReplaceAll("pbp0","pbarpSystem0");
242 
243  // Prevent generator from throwing a lot of warnings
244  //TLorentzVector fIni(0,0,Mom,0.938272+sqrt(Mom*Mom+0.938272*0.938272));
245  TDatabasePDG::Instance()->AddParticle("pbarpSystem","pbarpSystem",3,kFALSE,0.1,0, "",88888);
246  TDatabasePDG::Instance()->AddParticle("pbarpSystem0","pbarpSystem0",3,kFALSE,0.1,0, "",88880);
247  TDatabasePDG::Instance()->AddParticle("eta_c1","eta_c1",4.3,kFALSE,0.02,0,"",999441);
248 
249  if (anadecay!="")
250  {
251  //if (fastsim)
252  anaparms+=":algo="+pidalgo;
253  PndSimpleCombinerTask *scTask = new PndSimpleCombinerTask(anadecay, anaparms, Mom, run, mode);
254  scTask->SetPidAlgo(pidalgo);
255 
256  fRun->AddTask(scTask);
257  }
258 
259  // *****************************
260  // *** PndSimpleCombinerTask ***
261  // *****************************
262 
263 
264 
265  // *****************************
266  // *** PndParticleQATask ***
267  // *****************************
268 
269  // do particle QA?
270  bool partQA = (anaparms.Contains("qapart"));
271  bool mc = !(anaparms.Contains("!mc"));
272  bool neut = !(anaparms.Contains("!neut"));
273  bool chrg = !(anaparms.Contains("!chrg"));
274 
275  if (partQA)
276  {
277  PndParticleQATask *partQaTask = new PndParticleQATask(fastsim, chrg, neut, mc, mode); // particle QA task
278 
279  TString fPidArrayNames = "IdealPidProbability : DrcBarrelProbability : MvdPidProbability : SttPidProbability : ";
280  fPidArrayNames += "ScEmcPidBarrel1Probability;ScEmcPidBarrel2Probability;ScEmcPidFwCapProbability;ScEmcPidBwCapProbability";
281  partQaTask->SetPidArrayNames(fPidArrayNames);
282 
283  fRun->AddTask(partQaTask);
284  }
285 
286  // *****************************
287  // *** PndParticleQATask ***
288  // *****************************
289 
290 
291 
292  // ***********************
293  // *** SoftTriggerTask ***
294  // ***********************
295 
296  if (runST)
297  {
298  // this file contains the trigger line definitions
299  TString triggercfg = TString(gSystem->Getenv("VMCWORKDIR"))+"/softrig/triggerlines.cfg"; // fullsim trigger definitions
300  if (fastsim) triggercfg = TString(gSystem->Getenv("VMCWORKDIR"))+"/softrig/triggerlines_fsim.cfg"; // fastsim trigger definitions
301 
302  PndSoftTriggerTask *stTask = new PndSoftTriggerTask(Mom, 0, run, triggercfg);
303 
304  if (fastsim) stTask->SetFastSimDefaults();
305  else stTask->SetFullSimDefaults();
306 
307  fRun->AddTask(stTask);
308  }
309 
310  // ***********************
311  // *** SoftTriggerTask ***
312  // ***********************
313 
314 
315  // *** and run analysis
316  fRun->Init();
317  fRun->Run(0,nevts);
318 
319  //------------------------Print some info and exit----------------
320  fTimer.Stop();
321  FairSystemInfo sysInfo;
322  Float_t maxMemory=sysInfo.GetMaxMemory();
323  Double_t rtime = fTimer.RealTime();
324  Double_t ctime = fTimer.CpuTime();
325 
326  Float_t cpuUsage=ctime/rtime;
327 
328  cout << endl;
329  cout << "[INFO ] Macro call : prod_ana.C(\""<<prefix<<"\", "<<from<<", "<<to<<", "<<mode<<", "<<nevts<<")" <<endl;
330  cout << "[INFO ] Output file : " << outFile << endl;
331  cout << "[INFO ] Real time : " << rtime << " s, CPU time " << ctime << "s" << endl;
332  cout << "[INFO ] CPU usage : " << cpuUsage*100. << "%" << endl;
333  cout << "[INFO ] Max Memory : " << maxMemory << " MB" << endl;
334  cout << "[INFO ] Macro finished successfully." << endl<<endl;
335  return 0;
336 }
Double_t x0
Definition: checkhelixhit.C:70
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)
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
Double_t
int prod_ana(TString prefix="", int from=1, int to=1, int mode=0, int nevts=0)
Double_t ctime
Definition: hit_dirc.C:114
bool checkfile(TString fn)
double X
Definition: anaLmdDigi.C:68
void SetPidArrayNames(TString names)
TTree * t
Definition: bump_analys.C:13
Double_t rtime
Definition: hit_dirc.C:113