FairRoot/PandaRoot
PndProdAnaTask.cxx
Go to the documentation of this file.
1 // ************************************************************************
2 //
3 // Analysis Example Task
4 //
5 // for the Simulation Production (macro/production/scripts) and Analysis, see
6 //
7 // https://panda-wiki.gsi.de/foswiki/bin/view/Computing/PandaRootSimulationKronos
8 // https://panda-wiki.gsi.de/foswiki/bin/view/Computing/PandaRootRhoTutorial
9 //
10 // K.Goetzen 6/2016
11 // ************************************************************************
12 
13 
14 // The header file
15 #include "PndProdAnaTask.h"
16 
17 // C++ headers
18 #include <string>
19 #include <iostream>
20 
21 // FAIR headers
22 #include "FairRootManager.h"
23 #include "FairRunAna.h"
24 #include "FairRuntimeDb.h"
25 #include "FairRun.h"
26 #include "FairRuntimeDb.h"
27 
28 // ROOT headers
29 #include "TClonesArray.h"
30 #include "TVector3.h"
31 #include "TH1F.h"
32 #include "TH2F.h"
33 
34 // RHO headers
35 #include "RhoCandidate.h"
36 #include "RhoHistogram/RhoTuple.h"
37 #include "RhoFactory.h"
39 
40 // Analysis headers
41 #include "PndAnalysis.h"
42 #include "Rho4CFitter.h"
43 #include "RhoKinVtxFitter.h"
44 #include "RhoKinFitter.h"
45 #include "RhoVtxPoca.h"
46 #include "PndRhoTupleQA.h"
47 
48 
49 using std::cout;
50 using std::endl;
51 
52 
53 // ----- Default constructor -------------------------------------------
55  FairTask("Panda Tutorial Analysis Task")
56 {
57  fMode = mode;
58  fPidAlgo = pidAlgo;
59  if (fPidAlgo=="") fPidAlgo = "PidAlgoEmcBayes;PidAlgoDrc;PidAlgoDisc;PidAlgoStt;PidAlgoMdtHardCuts;PidAlgoSciT;PidAlgoRich";
60 }
61 // -------------------------------------------------------------------------
62 
63 
64 // ----- Destructor ----------------------------------------------------
66 // -------------------------------------------------------------------------
67 
68 
69 // ----- Method to select true PID candidates
71 {
72  int removed = 0;
73 
74  for (int ii=l.GetLength()-1;ii>=0;--ii)
75  {
76  if ( !(ana->McTruthMatch(l[ii])) )
77  {
78  l.Remove(l[ii]);
79  removed++;
80  }
81  }
82 
83  return removed;
84 }
85 // -------------------------------------------------------------------------
86 
87 
88 // ----- Public method Init --------------------------------------------
90 {
91  // initialize analysis object
92  fAnalysis = new PndAnalysis();
93 
94  // reset the event counter
95  fEvtCount = 0;
96 
97  // *** Save current gDirectory
98  TDirectory *dir = gDirectory;
99  FairRootManager::Instance()->GetOutFile()->cd();
100 
101  ntp = new RhoTuple("ntp", "Prod Example Analysis: D0->K pi");
102  ntp->GetInternalTree()->SetDirectory(gDirectory);
103 
104  // *** restore original gDirectory
105  dir->cd();
106 
107  // *** the lorentz vector of the initial psi(2S)
108  fIni.SetXYZT(0, 0, 6.231552, 7.240065);
109 
110  return kSUCCESS;
111 }
112 
113 // -------------------------------------------------------------------------
114 
115 
116 // ----- Public method Exec --------------------------------------------
117 void PndProdAnaTask::Exec(Option_t*)
118 {
119  // *** some variables
120  int i=0,j=0, k=0, l=0;
121 
122  // necessary to read the next event
124 
125  if (!(++fEvtCount%100)) cout << "[PndProdAnaTask] evt "<<fEvtCount<<endl;
126 
127  // *** QA tool for simple dumping of analysis results in RhoRuple
128  // *** WIKI: https://panda-wiki.gsi.de/foswiki/bin/view/Computing/PandaRootAnalysisJuly13#PndRhoTupleQA
129  PndRhoTupleQA qa(fAnalysis,fIni.P());
130 
131  // *** RhoCandLists for the analysis
132  RhoCandList kp, km, pip, pim, D0, D0bar;
133 
134  // *** Select with no PID info ('All'); type and mass are set
135  fAnalysis->FillList(kp, "KaonAllPlus", fPidAlgo);
136  fAnalysis->FillList(km, "MuonAllMinus", fPidAlgo);
137  fAnalysis->FillList(pip, "PionAllPlus", fPidAlgo);
138  fAnalysis->FillList(pim, "PionAllMinus", fPidAlgo);
139 
140  D0.Combine(km, pip, 421);
141  D0bar.Combine(kp, pim, -421);
142 
143  D0.Append(D0bar);
144 
145  for (j=0; j<D0.GetLength(); ++j)
146  {
147  Float_t mmiss = (fIni-(D0[j]->P4())).M();
148  Float_t msum = D0[j]->M() + mmiss;
149 
150  // dump out information
151  ntp->Column("ev", (Int_t) fEvtCount);
152  ntp->Column("cand", (Int_t) j);
153  ntp->Column("ncand", (Int_t) D0.GetLength());
154  ntp->Column("mode", (Int_t) fMode);
155  ntp->Column("mmiss", (Float_t) mmiss);
156  ntp->Column("msum", (Float_t) msum);
157 
158  // store beam info
159  qa.qaP4("beam", fIni, ntp);
160 
161  // store information about composite candidate tree recursively (see analysis/AnalysisTools/PndRhoTupleQA)
162  qa.qaComp("x", D0[j], ntp);
163 
164  // store the 4-vector of the truth matched candidate (or a dummy, if not matched to keep ntuple consistent)
165  RhoCandidate *truth = D0[j]->GetMcTruth();
166  TLorentzVector lv(0,0,0,0);
167  if (truth) lv = truth->P4();
168  qa.qaP4("trx", lv, ntp);
169 
170  // do a vertex fit
171  RhoKinVtxFitter vtxfitter(D0[j]); // *** instantiate the vertex fitter; input is the object to be fitted
172  vtxfitter.Fit(); // *** perform fit
173 
174  RhoCandidate *cfit = D0[j]->GetFit(); // *** get the fitted candidate
175  qa.qaVtx("fvxx",cfit,ntp);
176  qa.qaP4("fvxx", cfit->P4(), ntp);
177  double chi2_vtx = vtxfitter.GetChi2(); // *** and the chi^2 of the fit
178  ntp->Column("chi2vx", (Float_t) chi2_vtx);
179 
180  // really write information to tree
181  ntp->DumpData();
182  }
183 }
184 
185 
187 {
188  ntp->GetInternalTree()->Write();
189 }
190 
TLorentzVector fIni
Int_t i
Definition: run_full.C:25
virtual void Exec(Option_t *opt)
Int_t GetLength() const
Definition: RhoCandList.h:46
Bool_t FillList(RhoCandList &l, TString listkey="All", TString pidTcaNames="", int trackHypothesis=-1)
virtual InitStatus Init()
virtual void Finish()
Int_t mode
Definition: autocutx.C:47
void GetEventInTask()
int SelectTruePid(PndAnalysis *ana, RhoCandList &l)
TLorentzVector P4() const
Definition: RhoCandidate.h:195
void Column(const char *label, Bool_t value, Bool_t defval=0, const char *block=0)
Definition: RhoTuple.cxx:56
Int_t Remove(RhoCandidate *)
RhoCandidate * GetMcTruth() const
Definition: RhoCandidate.h:437
PndAnalysis * fAnalysis
void DumpData()
Definition: RhoTuple.cxx:391
PndProdAnaTask(int mode=0, TString pidAlgo="")
ClassImp(PndAnaContFact)
RhoCandidate * GetFit() const
Definition: RhoCandidate.h:293
double GetChi2() const
Definition: RhoFitterBase.h:48
TTree * GetInternalTree()
Definition: RhoTuple.h:207
Bool_t McTruthMatch(RhoCandidate *cand, Int_t level=2, bool verbose=false)
RhoTuple * ntp