FairRoot/PandaRoot
QA/day1/ana_day1.C
Go to the documentation of this file.
1 class RhoCandList;
2 class RhoCandidate;
5 class PndAnalysis;
6 #include "../auxi.C"
7 
8 // *** routine to only keep PID matched candidates in list
10 {
11  int removed = 0;
12 
13  for (int ii=l.GetLength()-1;ii>=0;--ii)
14  {
15  if ( !(ana->McTruthMatch(l[ii])) )
16  {
17  l.Remove(l[ii]);
18  removed++;
19  }
20  }
21 
22  return removed;
23 }
24 
26 {
27  TLorentzVector lv=c->P4();
28 
29  cout <<c->PdgCode()<<" ("<<lv.X()<<"/"<<lv.Y()<<"/"<<lv.Z()<<"/"<<lv.E()<<")"<<endl;
30 }
31 
32 void countDoubles(RhoCandList &l, int &n1, int &n2, int &n3)
33 {
34  int n_smc = 0;
35  int n_strk = 0;
36  int n_both = 0;
37  double d = 0.00001;
38 
39  for (int i=0;i<l.GetLength()-1;++i)
40  {
41  for (int j=i+1;j<l.GetLength();++j)
42  {
43  TLorentzVector dl = l[i]->P4() - l[j]->P4();
44 
45  bool chkmc = (l[i]->GetMcTruth()==l[j]->GetMcTruth());
46  bool chktrk = (fabs(dl.X())<d) && (fabs(dl.Y())<d) && (fabs(dl.Z())<d) && (fabs(dl.E())<d);
47  if (chkmc) n_smc++;
48  if (chktrk) n_strk++;
49  if (chktrk && chkmc) n_both++;
50  }
51  }
52  n1 = n_strk;
53  n2 = n_smc;
54  n3 = n_both;
55 }
56 
57 int ana_day1(int nevts=0, TString prefix="fakeonline")
58 {
59  TDatabasePDG::Instance()->AddParticle("pbarpSystem","pbarpSystem",1.9,kFALSE,0.1,0,"",88888);
60  TStopwatch fTimer;
61  // *** some variables
62  int i=0,j=0, k=0, l=0;
63  gStyle->SetOptFit(1011);
64 
65  // *** the output file for FairRunAna
66  TString OutFile="output.root";
67 
68  // *** the files coming from the simulation
69  TString inPidFile = prefix+"_pid.root"; // this file contains the PndPidCandidates and McTruth
70  TString inParFile = prefix+"_par.root";
71 
72  // *** PID table with selection thresholds; can be modified by the user
73  TString pidParFile = TString(gSystem->Getenv("VMCWORKDIR"))+"/macro/params/all.par";
74 
75  // *** initialization
76  FairLogger::GetLogger()->SetLogToFile(kFALSE);
77  FairRunAna* fRun = new FairRunAna();
78  FairRuntimeDb* rtdb = fRun->GetRuntimeDb();
79  fRun->SetInputFile(inPidFile);
80 
81  // *** setup parameter database
82  FairParRootFileIo* parIO = new FairParRootFileIo();
83  parIO->open(inParFile);
84  FairParAsciiFileIo* parIOPid = new FairParAsciiFileIo();
85  parIOPid->open(pidParFile.Data(),"in");
86 
87  rtdb->setFirstInput(parIO);
88  rtdb->setSecondInput(parIOPid);
89  rtdb->setOutput(parIO);
90 
91  fRun->SetOutputFile(OutFile);
92  fRun->Init();
93 
94  // *** create an output file for all histograms
95  TString histofile=prefix+"_histo.root";
96  TFile *out = TFile::Open(histofile,"RECREATE");
97 
98  // *** create some histograms
99  TH1F *hmomtrk = new TH1F("hmomtrk","track momentum (all)",200,0,5);
100  TH1F *hthttrk = new TH1F("hthttrk","track theta (all)",200,0,3.1415);
101 
102  TH1F *hjpsim_all = new TH1F("hjpsim_all","J/#psi mass (all)",200,0,4.5);
103  TH1F *hpsim_all = new TH1F("hpsim_all","#psi(2S) mass (all)",200,0,5);
104 
105  TH1F *hjpsim_lpid = new TH1F("hjpsim_lpid","J/#psi mass (loose pid)",200,0,4.5);
106  TH1F *hpsim_lpid = new TH1F("hpsim_lpid","#psi(2S) mass (loose pid)",200,0,5);
107 
108  TH1F *hjpsim_tpid = new TH1F("hjpsim_tpid","J/#psi mass (tight pid)",200,0,4.5);
109  TH1F *hpsim_tpid = new TH1F("hpsim_tpid","#psi(2S) mass (tight pid)",200,0,5);
110 
111  TH1F *hjpsim_trpid = new TH1F("hjpsim_trpid","J/#psi mass (true pid)",200,0,4.5);
112  TH1F *hpsim_trpid = new TH1F("hpsim_trpid","#psi(2S) mass (true pid)",200,0,5);
113 
114 
115  TH1F *hjpsim_ftm = new TH1F("hjpsim_ftm","J/#psi mass (full truth match)",200,0,4.5);
116  TH1F *hpsim_ftm = new TH1F("hpsim_ftm","#psi(2S) mass (full truth match)",200,0,5);
117 
118  TH1F *hjpsim_nm = new TH1F("hjpsim_nm","J/#psi mass (no truth match)",200,0,4.5);
119  TH1F *hpsim_nm = new TH1F("hpsim_nm","#psi(2S) mass (no truth match)",200,0,5);
120 
121  TH1F *hjpsim_diff = new TH1F("hjpsim_diff","J/#psi mass diff to truth",100,-2,2);
122  TH1F *hpsim_diff = new TH1F("hpsim_diff","#psi(2S) mass diff to truth",100,-2,2);
123 
124 
125  TH1F *hjpsim_vf = new TH1F("hjpsim_vf","J/#psi mass (vertex fit)",200,0,4.5);
126  TH1F *hjpsim_4cf = new TH1F("hjpsim_4cf","J/#psi mass (4C fit)",200,0,4.5);
127  TH1F *hjpsim_mcf = new TH1F("hjpsim_mcf","J/#psi mass (mass constraint fit)",200,0,4.5);
128 
129  TH1F *hjpsi_chi2_vf = new TH1F("hjpsi_chi2_vf", "J/#psi: #chi^{2} vertex fit",100,0,10);
130  TH1F *hpsi_chi2_4c = new TH1F("hpsi_chi2_4c", "#psi(2S): #chi^{2} 4C fit",100,0,250);
131  TH1F *hjpsi_chi2_mf = new TH1F("hjpsi_chi2_mf", "J/#psi: #chi^{2} mass fit",100,0,10);
132 
133  TH1F *hjpsi_prob_vf = new TH1F("hjpsi_prob_vf", "J/#psi: Prob vertex fit",100,0,1);
134  TH1F *hpsi_prob_4c = new TH1F("hpsi_prob_4c", "#psi(2S): Prob 4C fit",100,0,1);
135  TH1F *hjpsi_prob_mf = new TH1F("hjpsi_prob_mf", "J/#psi: Prob mass fit",100,0,1);
136 
137  TH2F *hvpos = new TH2F("hvpos","(x,y) projection of fitted decay vertex",100,-2,2,100,-2,2);
138 
139  //
140  // Now the analysis stuff comes...
141  //
142 
143 
144  // *** the data reader object
145  PndAnalysis* theAnalysis = new PndAnalysis();
146  if (nevts==0) nevts= theAnalysis->GetEntries();
147 
148  // *** RhoCandLists for the analysis
149  RhoCandList chrg, muplus, muminus, piplus, piminus, jpsi, psi2s;
150 
151  // *** Mass selector for the jpsi cands
152  double m0_jpsi = TDatabasePDG::Instance()->GetParticle("J/psi")->Mass(); // Get nominal PDG mass of the J/psi
153  RhoMassParticleSelector *jpsiMassSel=new RhoMassParticleSelector("jpsi",m0_jpsi,1.0);
154 
155  // *** the lorentz vector of the initial psi(2S)
156  TLorentzVector ini(0, 0, 6.231552, 7.240065);
157 
158  // ***
159  // the event loop
160  // ***
161 
162  int cntdbltrk=0, cntdblmc=0, cntdblboth=0, cnttrk=0, cnt_dbl_jpsi=0, cnt_dbl_psip=0;
163 
164  while (theAnalysis->GetEvent() && i++<nevts)
165  {
166  if ((i%100)==0) cout<<"evt " << i << endl;
167 
168  // *** Select with no PID info ('All'); type and mass are set
169  theAnalysis->FillList(chrg, "Charged");
170  theAnalysis->FillList(muplus, "MuonAllPlus");
171  theAnalysis->FillList(muminus, "MuonAllMinus");
172  theAnalysis->FillList(piplus, "PionAllPlus");
173  theAnalysis->FillList(piminus, "PionAllMinus");
174 
175  // *** momentum and theta histograms
176  for (j=0;j<muplus.GetLength();++j)
177  {
178  hmomtrk->Fill(muplus[j]->P());
179  hthttrk->Fill(muplus[j]->P4().Theta());
180  }
181  for (j=0;j<muminus.GetLength();++j)
182  {
183  hmomtrk->Fill(muminus[j]->P());
184  hthttrk->Fill(muminus[j]->P4().Theta());
185  }
186 
187  cnttrk += chrg.GetLength();
188 
189  int n1, n2, n3;
190 
191  countDoubles(chrg,n1,n2,n3);
192  cntdbltrk += n1;
193  cntdblmc += n2;
194  cntdblboth += n3;
195 
196  // *** combinatorics for J/psi -> mu+ mu-
197  jpsi.Combine(muplus, muminus);
198 
199 
200  // ***
201  // *** do the TRUTH MATCH for jpsi
202  // ***
203  jpsi.SetType(443);
204 
205  int nm = 0;
206  for (j=0;j<jpsi.GetLength();++j)
207  {
208  hjpsim_all->Fill( jpsi[j]->M() );
209 
210  if (theAnalysis->McTruthMatch(jpsi[j]))
211  {
212  nm++;
213  hjpsim_ftm->Fill( jpsi[j]->M() );
214  hjpsim_diff->Fill( jpsi[j]->GetMcTruth()->M() - jpsi[j]->M() );
215  }
216  else
217  hjpsim_nm->Fill( jpsi[j]->M() );
218  }
219 
220  if (nm>1) cnt_dbl_jpsi++;
221  // ***
222  // *** do VERTEX FIT (J/psi)
223  // ***
224  for (j=0;j<jpsi.GetLength();++j)
225  {
226  RhoKinVtxFitter vtxfitter(jpsi[j]); // instantiate a vertex fitter
227  vtxfitter.Fit();
228 
229  double chi2_vtx = vtxfitter.GetChi2(); // access chi2 of fit
230  double prob_vtx = vtxfitter.GetProb(); // access probability of fit
231  hjpsi_chi2_vf->Fill(chi2_vtx);
232  hjpsi_prob_vf->Fill(prob_vtx);
233 
234  if ( prob_vtx > 0.01 ) // when good enough, fill some histos
235  {
236  RhoCandidate *jfit = jpsi[j]->GetFit(); // access the fitted cand
237  TVector3 jVtx=jfit->Pos(); // and the decay vertex position
238 
239  hjpsim_vf->Fill(jfit->M());
240  hvpos->Fill(jVtx.X(),jVtx.Y());
241  }
242  }
243 
244  // *** some rough mass selection
245  jpsi.Select(jpsiMassSel);
246 
247  // *** combinatorics for psi(2S) -> J/psi pi+ pi-
248  psi2s.Combine(jpsi, piplus, piminus);
249 
250 
251  // ***
252  // *** do the TRUTH MATCH for psi(2S)
253  // ***
254  psi2s.SetType(88888);
255 
256  nm = 0;
257  for (j=0;j<psi2s.GetLength();++j)
258  {
259  hpsim_all->Fill( psi2s[j]->M() );
260 
261  if (theAnalysis->McTruthMatch(psi2s[j]))
262  {
263  nm++;
264  hpsim_ftm->Fill( psi2s[j]->M() );
265  hpsim_diff->Fill( psi2s[j]->GetMcTruth()->M() - psi2s[j]->M() );
266  }
267  else
268  hpsim_nm->Fill( psi2s[j]->M() );
269  }
270  if (nm>1) cnt_dbl_psip++;
271 
272 
273  // ***
274  // *** do 4C FIT (initial psi(2S) system)
275  // ***
276  for (j=0;j<psi2s.GetLength();++j)
277  {
278  RhoKinFitter fitter(psi2s[j]); // instantiate the kin fitter in psi(2S)
279  fitter.Add4MomConstraint(ini); // set 4 constraint
280  fitter.Fit(); // do fit
281 
282  double chi2_4c = fitter.GetChi2(); // get chi2 of fit
283  double prob_4c = fitter.GetProb(); // access probability of fit
284  hpsi_chi2_4c->Fill(chi2_4c);
285  hpsi_prob_4c->Fill(prob_4c);
286 
287  if ( prob_4c > 0.01 ) // when good enough, fill some histo
288  {
289  RhoCandidate *jfit = psi2s[j]->Daughter(0)->GetFit(); // get fitted J/psi
290 
291  hjpsim_4cf->Fill(jfit->M());
292  }
293  }
294 
295 
296  // ***
297  // *** do MASS CONSTRAINT FIT (J/psi)
298  // ***
299  for (j=0;j<jpsi.GetLength();++j)
300  {
301  RhoKinFitter mfitter(jpsi[j]); // instantiate the RhoKinFitter in psi(2S)
302  mfitter.AddMassConstraint(m0_jpsi); // add the mass constraint
303  mfitter.Fit(); // do fit
304 
305  double chi2_m = mfitter.GetChi2(); // get chi2 of fit
306  double prob_m = mfitter.GetProb(); // access probability of fit
307  hjpsi_chi2_mf->Fill(chi2_m);
308  hjpsi_prob_mf->Fill(prob_m);
309 
310  if ( prob_m > 0.01 ) // when good enough, fill some histo
311  {
312  RhoCandidate *jfit = jpsi[j]->GetFit(); // access the fitted cand
313  hjpsim_mcf->Fill(jfit->M());
314  }
315  }
316 
317 
318  // ***
319  // *** TRUE PID combinatorics
320  // ***
321 
322  // *** do MC truth match for PID type
323  SelectTruePid(theAnalysis, muplus);
324  SelectTruePid(theAnalysis, muminus);
325  SelectTruePid(theAnalysis, piplus);
326  SelectTruePid(theAnalysis, piminus);
327 
328  // *** all combinatorics again with true PID
329  jpsi.Combine(muplus, muminus);
330  for (j=0;j<jpsi.GetLength();++j) hjpsim_trpid->Fill( jpsi[j]->M() );
331  jpsi.Select(jpsiMassSel);
332 
333  psi2s.Combine(jpsi, piplus, piminus);
334  for (j=0;j<psi2s.GetLength();++j) hpsim_trpid->Fill( psi2s[j]->M() );
335 
336 
337  // ***
338  // *** LOOSE PID combinatorics
339  // ***
340 
341  // *** and again with PidAlgoMvd;PidAlgoStt;PidAlgoDrc and loose selection
342  theAnalysis->FillList(muplus, "MuonLoosePlus", "PidAlgoMvd;PidAlgoStt;PidAlgoDrc;PidAlgoMdtHardCuts");
343  theAnalysis->FillList(muminus, "MuonLooseMinus", "PidAlgoMvd;PidAlgoStt;PidAlgoDrc;PidAlgoMdtHardCuts");
344  theAnalysis->FillList(piplus, "PionLoosePlus", "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
345  theAnalysis->FillList(piminus, "PionLooseMinus", "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
346 
347  jpsi.Combine(muplus, muminus);
348  for (j=0;j<jpsi.GetLength();++j) hjpsim_lpid->Fill( jpsi[j]->M() );
349  jpsi.Select(jpsiMassSel);
350 
351  psi2s.Combine(jpsi, piplus, piminus);
352  for (j=0;j<psi2s.GetLength();++j) hpsim_lpid->Fill( psi2s[j]->M() );
353 
354 
355  // ***
356  // *** TIGHT PID combinatorics
357  // ***
358 
359  // *** and again with PidAlgoMvd;PidAlgoStt and tight selection
360  theAnalysis->FillList(muplus, "MuonTightPlus", "PidAlgoMdtHardCuts");
361  theAnalysis->FillList(muminus, "MuonTightMinus", "PidAlgoMdtHardCuts");
362  theAnalysis->FillList(piplus, "PionLoosePlus", "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
363  theAnalysis->FillList(piminus, "PionLooseMinus", "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
364 
365  jpsi.Combine(muplus, muminus);
366  for (j=0;j<jpsi.GetLength();++j) hjpsim_tpid->Fill( jpsi[j]->M() );
367  jpsi.Select(jpsiMassSel);
368 
369  psi2s.Combine(jpsi, piplus, piminus);
370  for (j=0;j<psi2s.GetLength();++j) hpsim_tpid->Fill( psi2s[j]->M() );
371 
372  }
373 
374  // *** write out all the histos
375  out->cd();
376 
377  hmomtrk->Write();
378  hthttrk->Write();
379 
380  hjpsim_all->Write();
381  hpsim_all->Write();
382  hjpsim_lpid->Write();
383  hpsim_lpid->Write();
384  hjpsim_tpid->Write();
385  hpsim_tpid->Write();
386  hjpsim_trpid->Write();
387  hpsim_trpid->Write();
388 
389  hjpsim_ftm->Write();
390  hpsim_ftm->Write();
391  hjpsim_nm->Write();
392  hpsim_nm->Write();
393 
394  hpsim_diff->Write();
395  hjpsim_diff->Write();
396 
397  hjpsim_vf->Write();
398  hjpsim_4cf->Write();
399  hjpsim_mcf->Write();
400 
401  hjpsi_chi2_vf->Write();
402  hpsi_chi2_4c->Write();
403  hjpsi_chi2_mf->Write();
404 
405  hjpsi_prob_vf->Write();
406  hpsi_prob_4c->Write();
407  hjpsi_prob_mf->Write();
408 
409  hvpos->Write();
410 
411  out->Save();
412 
413  // Extract the maximal used memory an add is as Dart measurement
414  // This line is filtered by CTest and the value send to CDash
415  FairSystemInfo sysInfo;
416  Float_t maxMemory=sysInfo.GetMaxMemory();
417  cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
418  cout << maxMemory;
419  cout << "</DartMeasurement>" << endl;
420 
421  fTimer.Stop();
422  Double_t rtime = fTimer.RealTime();
423  Double_t ctime = fTimer.CpuTime();
424 
425  Float_t cpuUsage=ctime/rtime;
426  cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
427  cout << cpuUsage;
428  cout << "</DartMeasurement>" << endl;
429 
430  cout << endl;
431  cout << "Real time " << rtime << " s, CPU time " << ctime
432  << "s" << endl;
433  cout << "CPU usage " << cpuUsage*100. << "%" << endl;
434  cout << "Max Memory " << maxMemory << " MB" << endl;
435 
436  cout << "Macro finished successfully." << endl;
437 
438  CloseGeoManager();
439  return 0;
440 }
Int_t GetEntries()
void printCand(RhoCandidate *c)
void AddMassConstraint(double mass)
TObjArray * d
Int_t i
Definition: run_full.C:25
TVector3 Pos() const
Definition: RhoCandidate.h:186
Int_t GetLength() const
Definition: RhoCandList.h:46
Bool_t FillList(RhoCandList &l, TString listkey="All", TString pidTcaNames="", int trackHypothesis=-1)
CandList piplus
void Add4MomConstraint(TLorentzVector lv)
void CloseGeoManager()
Definition: QA/auxi.C:11
FairRunAna * fRun
Definition: hit_dirc.C:58
CandList muplus
void Combine(RhoCandList &l1, RhoCandList &l2)
Double_t
PndAnalysis(TString tname1="", TString tname2="", TString algnamec="PidAlgoIdealCharged", TString algnamen="PidAlgoIdealNeutral")
Definition: PndAnalysis.cxx:48
void Select(RhoParticleSelectorBase *pidmgr)
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
TLorentzVector P4() const
Definition: RhoCandidate.h:195
double GetProb() const
Definition: RhoFitterBase.h:50
void SetType(const TParticlePDG *pdt, int start=0)
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
TFile * out
Definition: reco_muo.C:20
Double_t M() const
Int_t Remove(RhoCandidate *)
Double_t ctime
Definition: hit_dirc.C:114
int SelectTruePid(PndAnalysis *ana, RhoCandList &l)
GeV c P
int ana_day1(int nevts=0, TString prefix="fakeonline")
void countDoubles(RhoCandList &l, int &n1, int &n2, int &n3)
CandList piminus
double GetChi2() const
Definition: RhoFitterBase.h:48
Bool_t McTruthMatch(RhoCandidate *cand, Int_t level=2, bool verbose=false)
Int_t GetEvent(Int_t n=-1)
Bool_t Fit()
CandList muminus
Double_t rtime
Definition: hit_dirc.C:113
TH2F * hvpos