FairRoot/PandaRoot
tutorials/anatask/PndSoftTriggerTask.cxx
Go to the documentation of this file.
1 // ******************************************************
2 // Psi' -> J/psi (-> e+ e-) pi+ pi- Analysis Example Task
3 //
4 // K.Goetzen 7/2012
5 // *******************************************************
6 
7 #include "TClonesArray.h"
8 
9 #include "FairRootManager.h"
10 #include "FairRunAna.h"
11 #include "FairRuntimeDb.h"
12 //#include "PndTpcLheGFTrack.h"
13 
14 #include "TVector3.h"
15 #include "TH1F.h"
16 #include "TH2F.h"
17 #include "TStopwatch.h"
18 
19 #include "FairRun.h"
20 #include "FairRuntimeDb.h"
21 #include <string>
22 #include <iostream>
23 
24 // RHO stuff
25 #include "RhoCandidate.h"
26 #include "RhoHistogram/RhoTuple.h"
27 #include "RhoFactory.h"
28 
29 // Analysis Tools
30 #include "PndSoftTriggerTask.h"
31 #include "PndAnalysis.h"
32 
33 // Fitters
34 #include "Rho4CFitter.h"
35 #include "RhoKinVtxFitter.h"
36 #include "RhoKinFitter.h"
37 #include "RhoVtxPoca.h"
38 
39 
40 using std::cout;
41 using std::endl;
42 
43 // *** constants for particles
44 
45 const double fDMass = 1.8693; // *** center of mass cut window
46 const double fDMassCut = 0.25; // *** center of mass cut window
47 
48 const double fD0Mass = 1.8645; // *** center of mass cut window
49 const double fD0MassCut = 0.25; // *** center of mass cut window
50 
51 const double fJMass = 3.09687; // *** center of mass cut window
52 const double fJMassCut = 0.7; // *** center of mass cut window
53 
54 const double fDsMass = 1.9686; // *** center of mass cut window
55 const double fDsMassCut = 0.2; // *** center of mass cut window
56 
57 const double fPhiMass = 1.0195; // *** center of mass cut window
58 const double fPhiMassCut = 0.2; // *** center of mass cut window
59 
60 const double fLamcMass = 2.2849; // *** center of mass cut window
61 const double fLamcMassCut = 0.2; // *** center of mass cut window
62 
63 
64 
65 // ----- Default constructor -------------------------------------------
67  FairTask("Panda Analysis Task") {
68 }
69 // -------------------------------------------------------------------------
70 
71 // ----- Destructor ----------------------------------------------------
73 // -------------------------------------------------------------------------
74 
75 
76 
77 // ----- Public method Init --------------------------------------------
78 InitStatus PndSoftTriggerTask::Init()
79 {
80  //cout << " Inside the Init function****" << endl;
81 
82 
83  // initialize analysis object
85 
86  // Create and register output array
87 /* hjpsimass = new TH1F("hjpsimass","jpsi cands",100,0.0,4.5);
88  hpsimass = new TH1F("hpsimass","psi cands",100,0.,4.5);*/
89 
90  double max = 5.5;
91 
92  h_mom= new TH1F("h_mom","Momenta",200,0,5);
93  h_momc= new TH1F("h_momc","Momenta charged",200,0,5);
94  h_momn= new TH1F("h_momn","Momenta neutral",200,0,5);
95  h_mult= new TH1F("h_mult","Multiplicity",50,-0.5,49.5);
96  h_multc= new TH1F("h_multc","Multiplicity charged",30,-0.5,29.5);
97  h_multn= new TH1F("h_multn","Multiplicity neutral",50,-0.5,49.5);
98  h_multrem= new TH1F("h_multrem","Removed",50,-0.5,49.5);
99 
100  // J/psi histos
101  h_jpsi=new TH1F("h_jpsi","J/psi",200,0,max);
102  h_jpsit=new TH1F("h_jpsit","J/psi true",200,0,max);
103  h_jpsisel=new TH1F("h_jpsisel","J/psi selected",200,0,max);
105 
106  // D0 histos
107  h_d0=new TH1F("h_d0","D0",200,0,max);
108  h_d0t=new TH1F("h_d0t","D0 true",200,0,max);
109  h_d0sel=new TH1F("h_d0sel","D0 selected",200,0,max);
111 
112  h_d0_pocx=new TH1F("h_d0_pocx","D0 poca X",100,-1,1);
113  h_d0_pocy=new TH1F("h_d0_pocy","D0 poca Y",100,-1,1);
114  h_d0_pocz=new TH1F("h_d0_pocz","D0 poca Z",100,-1,1);
115 
116  h_d0_pocxm=new TH1F("h_d0_pocxm","D0 poca X match",100,-1,1);
117  h_d0_pocym=new TH1F("h_d0_pocym","D0 poca Y match",100,-1,1);
118  h_d0_poczm=new TH1F("h_d0_poczm","D0 poca Z match",100,-1,1);
119 
120  h_d0_l = new TH1F("h_d0_l","flight length",100,0,1);
121  h_d0_lm = new TH1F("h_d0_lm","flight length match",100,0,1);
122 
123  h_d0_pocxm->SetLineColor(2);
124  h_d0_pocym->SetLineColor(2);
125  h_d0_poczm->SetLineColor(2);
126  h_d0_lm->SetLineColor(2);
127 
128  // D+ histos
129  h_dpm=new TH1F("h_dpm","D#pm",200,0,max);
130  h_dpmt=new TH1F("h_dpmt","D#pm true",200,0,max);
131  h_dpmsel=new TH1F("h_dpmsel","D#pm selected",200,0,max);
133 
134  // Ds histos
135  h_ds=new TH1F("h_ds","Ds",200,0,max);
136  h_dst=new TH1F("h_dst","Ds true",200,0,max);
137  h_dssel=new TH1F("h_dssel","Ds selected",200,0,max);
139 
140  // Phi histos
141  h_phi=new TH1F("h_phi","Phi",200,0,max);
142  h_phit=new TH1F("h_phit","Phi true",200,0,max);
143  h_phisel=new TH1F("h_phisel","Phi selected",200,0,max);
145 
146  // Lam_c histos
147  h_lamc=new TH1F("h_lamc","Lam_c",200,0,max);
148  h_lamct=new TH1F("h_lamct","Lam_c true",200,0,max);
149  h_lamcsel=new TH1F("h_lamcsel","Lam_c selected",200,0,max);
151 
152 
153 
154  ntp=new RhoTuple("ntp","the J/psi ntuple");
155  ntp2=new RhoTuple("ntp2","the psi(2S) ntuple");
156 
157  // **** mass selector and McTruthMatcher
158  //
159 
160  evcount=0;
161 
162  chmax=0;
163  neutmax=0;
164  allmax=0;
165 
166  cntsel=0;
167 
168  cntjpsi=0;
169  cntd0=0;
170  cntdpm=0;
171  cntds=0;
172  cntphi=0;
173  cntlamc=0;
174 
175  cout << "-I- PndSoftTriggerTask: Intialization successfull" << endl;
176 
177  timer=new TStopwatch();
178  timer->Start();
179 
180  return kSUCCESS;
181 }
182 
184 
185  // Get run and runtime database
186  FairRun* run = FairRun::Instance();
187  if ( ! run ) Fatal("SetParContainers", "No analysis run");
188 
189  //FairRuntimeDb* db = run->GetRuntimeDb();
190  //if ( ! db ) Fatal("SetParContainers", "No runtime database");
191 
192 
193 }
194 
195 // -------------------------------------------------------------------------
196 
197 // ----- Public method Exec --------------------------------------------
198 void PndSoftTriggerTask::Exec(Option_t*)
199 {
200  Int_t j=0;
201 
203 
204  if (!(++evcount%100))
205  {
206  cout <<"evt "<<evcount;
207  timer->Stop();
208  cout <<" t="<< timer->CpuTime();
209  timer->Start();
210  cout <<" Cand Watermark = "<<RhoFactory::Instance()->GetCandidateWatermark();
211  cout <<" allmax:"<<chmax;
212  cout <<" chmax:"<<chmax;
213  cout <<" neutmax:"<<neutmax;
214  cout <<" mcmax:"<<mcmax;
215  cout <<endl;
216  }
217 
218 
219  // **** create all the particle lists we'll need for rebuilding the decay tree
220  //
221  //RhoCandList eplus, eminus, piplus, piminus, jpsi, psi, mctrk;
222 
223  RhoCandList all, chrg, neut;
224  RhoCandList ep, em, mup, mum, pip, pim, kp, km, pp, pm;
225  RhoCandList Jpsi, D0, D0b, Dpm, Dm, Ds, Dsb, Lamc, Lamcb, Phi;
226 
227  // *** Select with no PID info ('All'); type and mass are set
228  theAnalysis->FillList(all , "All");
229  theAnalysis->FillList(chrg, "Charged");
230  theAnalysis->FillList(neut, "Neutral");
231 
232  int nch = chrg.GetLength();
233  int nneut = neut.GetLength();
234  int nall = all.GetLength();
235 
236  if (nch>chmax) chmax=nch;
237  if (nneut>neutmax) neutmax=nneut;
238  if (nall>allmax) allmax=nall;
239 
240 
241  // ************ preliminary FIX to remove double tracks ...
242  RemoveDoubles(chrg);
243  // ************ preliminary FIX to remove double tracks ...
244 
245  double pidcut=0.1;
246 
247  SelectPid(0, -11,1,chrg,ep,pidcut);
248  SelectPid(0, 11,-1,chrg,em,pidcut);
249 
250  SelectPid(1, -13,1,chrg,mup,pidcut);
251  SelectPid(1, 13,-1,chrg,mum,pidcut);
252 
253  SelectPid(2, 211,1,chrg,pip,pidcut);
254  SelectPid(2, -211,-1,chrg,pim,pidcut);
255 
256  SelectPid(3, 321,1,chrg,kp,pidcut);
257  SelectPid(3, -321,-1,chrg,km,pidcut);
258 
259  SelectPid(4, 2212,1,chrg,pp,pidcut);
260  SelectPid(4,-2212,-1,chrg,pm,pidcut);
261 
262  // fill multiplicities
263  h_mult->Fill(all.GetLength());
264  h_multc->Fill(chrg.GetLength());
265  h_multn->Fill(neut.GetLength());
266 
267  // fill momentum histos
268  for (j=0;j<all.GetLength();++j) h_mom->Fill(all[j]->P());
269  for (j=0;j<chrg.GetLength();++j) h_momc->Fill(chrg[j]->P());
270  for (j=0;j<neut.GetLength();++j) h_momn->Fill(neut[j]->P());
271 
272  // *** J/psi->l+ l- cominatorics
273  Jpsi.Combine(ep, em);
274  Jpsi.CombineAndAppend(mup, mum);
275  Jpsi.SetType("J/psi");
276 
277  // *** D0 -> K- pi+ cominatorics
278  D0.Combine(km, pip); D0.SetType("D0");
279  D0b.Combine(kp,pim); D0b.SetType("anti-D0");
280  D0.Append(D0b);
281 
282  // *** D+ -> K- pi+ pi+ cominatorics
283  Dpm.Combine(km, pip, pip); Dpm.SetType("D+");
284  Dm.Combine(kp,pim,pim); Dm.SetType("D-");
285  Dpm.Append(Dm);
286 
287  // *** Ds+ -> K+ K- pi+ cominatorics
288  Ds.Combine(kp, km, pip); Ds.SetType("D_s+");
289  Dsb.Combine(kp, km, pim); Dsb.SetType("D_s-");
290  Ds.Append(Dsb);
291 
292  // *** phi -> K+ K- cominatorics
293  Phi.Combine(km, kp);
294 
295  // *** Lambda_c -> p K- pi+ cominatorics
296  Lamc.Combine(pp, km, pip); Lamc.SetType("Lambda_c+");
297  Lamcb.Combine(pm, kp, pim); Lamcb.SetType("anti-Lambda_c-");
298  Lamc.Append(Lamcb);
299 
300  // how many combinations are selected?
301  int comb =0;
302  int foundjpsi =0;
303  int foundd0 =0;
304  int founddpm =0;
305  int foundds =0;
306  int foundphi =0;
307  int foundlamc =0;
308 
309 
310  // ----------------------------------------------------------------------
311  // ********* J/psi
312  for (j=0;j<Jpsi.GetLength();++j)
313  {
314  double m=Jpsi[j]->M();
315 
316  h_jpsi->Fill(m);
317 
318  if (theAnalysis->McTruthMatch(Jpsi.Get(j))) h_jpsit->Fill(m);
319 
320  if (fabs(m-fJMass)<fJMassCut)
321  {
322  h_jpsisel->Fill(m);
323  foundjpsi++;
324  comb++;
325  }
326  }
327 
328 
329  // ----------------------------------------------------------------------
330  // ********* D0
331  for (j=0;j<D0.GetLength();++j)
332  {
333  double m=D0[j]->M();
334 
335  h_d0->Fill(m);
336 
337  if (theAnalysis->McTruthMatch(D0.Get(j))) h_d0t->Fill(m);
338 
339  if (fabs(m-fD0Mass)<fD0MassCut )
340  {
341  h_d0sel->Fill(m);
342  foundd0++;
343  comb++;
344  }
345  }
346 
347  // ----------------------------------------------------------------------
348  // ********* D+
349  for (j=0;j<Dpm.GetLength();++j)
350  {
351  double m=Dpm[j]->M();
352 
353  h_dpm->Fill(m);
354 
355  double beta = Dpm[j]->P4().Beta();
356  double gamma = Dpm[j]->P4().Gamma();
357 
358  // determine pseudo vertex
359  RhoVtxPoca poca;
360  TVector3 vtx;
361  double pocaquality = poca.GetPocaVtx(vtx,Dpm.Get(j));
362 
363  // decay length
364  h_d0_l->Fill(vtx.Mag()/(beta*gamma));
365 
366  // vertex
367  h_d0_pocx->Fill(vtx.X());
368  h_d0_pocy->Fill(vtx.Y());
369  h_d0_pocz->Fill(vtx.Z());
370 
371  // store mc truth matched cands
372  if (theAnalysis->McTruthMatch(Dpm.Get(j)))
373  {
374  h_dpmt->Fill(m);
375  h_d0_pocxm->Fill(vtx.X());
376  h_d0_pocym->Fill(vtx.Y());
377  h_d0_poczm->Fill(vtx.Z());
378  h_d0_lm->Fill(vtx.Mag()/(beta*gamma));
379  }
380 
381  // store selected cands
382  if (fabs(m-fDMass)<fDMassCut )
383  {
384  h_dpmsel->Fill(m);
385  founddpm++;
386  comb++;
387  }
388  }
389 
390  // ----------------------------------------------------------------------
391  // ********* Ds
392  for (j=0;j<Ds.GetLength();++j)
393  {
394  double m=Ds[j]->M();
395 
396  h_ds->Fill(m);
397 
398  if (theAnalysis->McTruthMatch(Ds.Get(j))) h_dst->Fill(m);
399 
400  if ( fabs(m-fDsMass)<fDsMassCut )
401  {
402  h_dssel->Fill(m);
403  foundds++;
404  comb++;
405  }
406  }
407 
408  // ----------------------------------------------------------------------
409  // ********* Phi
410  for (j=0;j<Phi.GetLength();++j)
411  {
412  double m=Phi[j]->M();
413 
414  h_phi->Fill(m);
415 
416  if (theAnalysis->McTruthMatch(Phi.Get(j))) h_phit->Fill(m);
417 
418  if (fabs(m-fPhiMass)<fPhiMassCut )
419  {
420  h_phisel->Fill(m);
421  foundphi++;
422  comb++;
423  }
424  }
425 
426  // ----------------------------------------------------------------------
427  // ********* Lam c
428  for (j=0;j<Lamc.GetLength();++j)
429  {
430  double m=Lamc[j]->M();
431 
432  h_lamc->Fill(m);
433 
434  if (theAnalysis->McTruthMatch(Lamc.Get(j))) h_lamct->Fill(m);
435 
436  if ( fabs(m-fLamcMass)<fLamcMassCut )
437  {
438  h_lamcsel->Fill(m);
439  foundlamc++;
440  comb++;
441  }
442  }
443 
444  if (comb>0) cntsel++;
445 
446  if (foundjpsi>0) cntjpsi++;
447  if (foundd0>0) cntd0++;
448  if (founddpm>0) cntdpm++;
449  if (foundds>0) cntds++;
450  if (foundphi>0) cntphi++;
451  if (foundlamc>0) cntlamc++;
452 
453 
454 }
455 // -------------------------------------------------------------------------
456 
457 void PndSoftTriggerTask::ConfigureHistos(TH1F *hall, TH1F *htrue, TH1F *hsel)
458 {
459  htrue->SetLineColor(2);
460  hsel->SetFillStyle(3001);
461  hsel->SetFillColor(602);
462  hsel->SetLineStyle(3);
463  hsel->SetLineColor(602);
464 
465 }
466 
467 // -------------------------------------------------------------------------
468 
470 {
471  Int_t i=0;
472  for (i=0;i<l.GetLength();++i)
473  {
474  h->Fill(l[i]->M());
475  }
476 }
477 // -------------------------------------------------------------------------
478 
480 {
481  int i,j;
482  int rem=0;
483 
484  //cout <<"********* before*****"<<endl<<l<<endl;
485 
486  for (i=0;i<l.GetLength();++i)
487  {
488  bool sim=false;
489  for (j=i+1;j<l.GetLength();++j)
490  {
491  if(!sim &&
492  fabs(l[i]->Px()-l[j]->Px())<limit &&
493  fabs(l[i]->Py()-l[j]->Py())<limit &&
494  fabs(l[i]->Pz()-l[j]->Pz())<limit &&
495  fabs(l[i]->E()-l[j]->E())<limit)
496  {
497  sim=true;
498  }
499  //if (similarity(l[i].P4(), l[j]->P4())<limit){ sim=true; j=10000;}
500  }
501  if (sim) {l.Remove(l[i--]); rem++;}
502  }
503  //cout<<"1:" <<rem<<endl;
504  //cout <<"********* after *****"<<endl<<l<<endl;
505 
506  return rem;
507 }
508 
509 
510 // -------------------------------------------------------------------------
512 {
513  int N=l.GetLength();
514  if (N>max) N=max;
515  for (int j=0;j<N;++j)
516  {
517  cout <<*(l[j])<<" PDG:"<<l[j]->PdgCode()<<" MC pointer:"<<l[j]->GetMcTruth()<<endl;
518  }
519  cout <<endl;
520 }
521 
522 // -------------------------------------------------------------------------
523 
524 void PndSoftTriggerTask::SelectPid(int type, int pdg, int chrg, RhoCandList &l, RhoCandList &lpid, double cut)
525 {
526  lpid.Cleanup();
527 
528  for (int j=0;j<l.GetLength();++j)
529  {
530  if (fabs(l[j]->Charge()-double(chrg))<0.001 && l[j]->GetPidInfo(type)>=cut)
531  {
532  //RhoCandidate c(l[j]);
533  //c.SetMass(pdgmass[type]);
534  lpid.Put(l[j]);
535  }
536  }
537  for (int j=0;j<lpid.GetLength();++j) lpid[j]->SetType(pdg);
538 }
539 
540 // -------------------------------------------------------------------------
541 
543 {
544  int removed = 0;
545  int pdgcode=0;
546  int nmct = mct.GetLength();
547 
548  //PndMcTruthMatch mcm;
549 
550  if (l.GetLength()>0) pdgcode = l[0]->PdgCode();
551 
552  for (int ii=l.GetLength();ii>=0;--ii)
553  {
554  RhoCandidate* mccand = l[ii]->GetMcTruth();
555 
556  if (mccand)
557  if(mccand->PdgCode()==pdgcode)
558 // if (mcm.MctMatch(l[ii],mct))
559  continue; //don't remove if good mctruth
560  l.Remove(l[ii]);
561  removed++;
562  }
563  return removed;
564 }
565 
566 // -------------------------------------------------------------------------
567 
569 {
570  cout <<"Efficiency (ev):" << (double)cntsel / (double)evcount <<endl;
571  cout <<"Efficiency J/psi (ev):"<< (double)cntjpsi/ (double)evcount <<endl;
572  cout <<"Efficiency D0 (ev):"<< (double)cntd0 / (double)evcount <<endl;
573  cout <<"Efficiency D+- (ev):"<< (double)cntdpm / (double)evcount <<endl;
574  cout <<"Efficiency Ds (ev):"<< (double)cntds / (double)evcount <<endl;
575  cout <<"Efficiency Phi (ev):"<< (double)cntphi / (double)evcount <<endl;
576  cout <<"Efficiency Lamc (ev):"<< (double)cntlamc/ (double)evcount <<endl;
577 
578  h_mom->Write();
579  h_momc->Write();
580  h_momn->Write();
581  h_mult->Write();
582  h_multc->Write();
583  h_multn->Write();
584  h_multrem->Write();
585 
586  h_jpsi->Write();
587  h_jpsit->Write();
588  h_jpsisel->Write();
589 
590  h_d0->Write();
591  h_d0t->Write();
592  h_d0sel->Write();
593 
594  h_d0_pocx->Write();
595  h_d0_pocy->Write();
596  h_d0_pocz->Write();
597 
598  h_d0_pocxm->Write();
599  h_d0_pocym->Write();
600  h_d0_poczm->Write();
601 
602  h_d0_l->Write();
603  h_d0_lm->Write();
604 
605  h_dpm->Write();
606  h_dpmt->Write();
607  h_dpmsel->Write();
608 
609  h_ds->Write();
610  h_dst->Write();
611  h_dssel->Write();
612 
613  h_phi->Write();
614  h_phit->Write();
615  h_phisel->Write();
616 
617  h_lamc->Write();
618  h_lamct->Write();
619  h_lamcsel->Write();
620 
621  ntp->GetInternalTree()->Write();
622  ntp2->GetInternalTree()->Write();
623 
624 }
625 
sim(Int_t nEvents=1, TString SimEngine="TGeant4", Float_t mom=6.231552)
void Append(const RhoCandidate *c)
Definition: RhoCandList.h:52
Int_t run
Definition: autocutx.C:47
void Cleanup()
Definition: RhoCandList.cxx:62
const double fPhiMassCut
Int_t i
Definition: run_full.C:25
__m128 m
Definition: P4_F32vec4.h:28
const double fLamcMassCut
Int_t GetLength() const
Definition: RhoCandList.h:46
int ev
Bool_t FillList(RhoCandList &l, TString listkey="All", TString pidTcaNames="", int trackHypothesis=-1)
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:26
virtual void Exec(Option_t *opt)
double cut[MAX]
Definition: autocutx.C:36
vTop Write()
void CombineAndAppend(RhoCandList &l1, RhoCandList &l2)
void Combine(RhoCandList &l1, RhoCandList &l2)
void ConfigureHistos(TH1F *hall, TH1F *htrue, TH1F *hsel)
void PrintList(RhoCandList &l, int max=10)
Double_t GetPocaVtx(TVector3 &vertex, RhoCandidate *composite)
Definition: RhoVtxPoca.cxx:27
void FillMassHisto(TH1F *h, RhoCandList &l)
int RemoveDoubles(RhoCandList &l, double limit=0.0001)
void SetType(const TParticlePDG *pdt, int start=0)
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
static RhoFactory * Instance()
Definition: RhoFactory.cxx:34
Int_t Remove(RhoCandidate *)
void SelectPid(int type, int pdg, int chrg, RhoCandList &l, RhoCandList &lpid, double cut=0.2)
static Int_t GetCandidateWatermark()
Definition: RhoFactory.cxx:110
ClassImp(PndAnaContFact)
void Put(const RhoCandidate *, Int_t i=-1)
Definition: RhoCandList.cxx:77
Bool_t McTruthMatch(RhoCandidate *cand, Int_t level=2, bool verbose=false)
Int_t GetEvent(Int_t n=-1)
int SelectPdgCode(RhoCandList &mct, RhoCandList &l)
double limit
Definition: dedx_bands.C:18
static const double mup
Definition: mzparameters.h:21
RhoCandidate * Get(Int_t)
Definition: RhoCandList.cxx:94