FairRoot/PandaRoot
PndScrutAnaTask.cxx
Go to the documentation of this file.
1 // ************************************************************************
2 //
3 // Template for an Analysis Task,
4 //
5 // for the December 2013 CM Tutorial
6 //
7 // For further info see also
8 //
9 // http://panda-wiki.gsi.de/cgi-bin/viewauth/Computing/PandaRootRhoTutorial
10 // http://panda-wiki.gsi.de/cgi-bin/view/Computing/PandaRootAnalysisJuly13
11 //
12 // K.Goetzen 11/2013
13 //
14 // ************************************************************************
15 
16 
17 // The header file
18 #include "PndScrutAnaTask.h"
19 
20 // C++ headers
21 #include <string>
22 #include <iostream>
23 
24 // FAIR headers
25 #include "FairRootManager.h"
26 #include "FairRunAna.h"
27 #include "FairRuntimeDb.h"
28 #include "FairRun.h"
29 #include "FairRuntimeDb.h"
30 
31 // ROOT headers
32 #include "TClonesArray.h"
33 #include "TVector3.h"
34 #include "TH1F.h"
35 #include "TH2F.h"
36 #include "TDatabasePDG.h"
37 
38 // RHO headers
39 #include "RhoCandidate.h"
40 #include "RhoHistogram/RhoTuple.h"
41 #include "RhoFactory.h"
43 #include "RhoTuple.h"
44 
45 // Analysis headers
46 #include "PndAnalysis.h"
47 #include "Rho4CFitter.h"
48 #include "RhoKinVtxFitter.h"
49 #include "RhoKinFitter.h"
50 #include "RhoVtxPoca.h"
51 #include "PndRhoTupleQA.h"
52 #include "PndEventShape.h"
53 
54 
55 using std::cout;
56 using std::endl;
57 
58 
59 // ----- Default constructor -------------------------------------------
60 PndScrutAnaTask::PndScrutAnaTask(double pbarmom, TString outname) :
61  FairTask("Panda Scrutiny Analysis Task")
62 {
63  double mp=0.938272;
64  fIni.SetXYZT(0,0,pbarmom, sqrt(pbarmom*pbarmom+mp*mp)+mp);
65 
66  fOutName = outname;
67 }
68 // -------------------------------------------------------------------------
69 
70 
71 // ----- Destructor ----------------------------------------------------
73 {
74  delete fFile;
75 }
76 // -------------------------------------------------------------------------
77 
78 
79 // ----- Public method Init --------------------------------------------
80 InitStatus PndScrutAnaTask::Init()
81 {
82  // *** initialize PndAnalysis object
83  fAnalysis = new PndAnalysis();
84 
85  // *** reset the event counter
86  fEvtCount = 0;
87 
88  // *******
89  // ******* PREPARE/CREATE THE STUFF YOU NEED
90  // *******
91 
92  fPdg = TDatabasePDG::Instance();
93 
94  // *** Mass selector for the jpsi cands
95  double m0_jpsi = fPdg->GetParticle("J/psi")->Mass(); // Get nominal PDG mass of the J/psi
96  jpsiMassSel = new RhoMassParticleSelector("jpsi" ,m0_jpsi,0.5);
97  jpsiPreMassSel = new RhoMassParticleSelector("jpsipre",m0_jpsi,2.0);
98 
99  // ***
100  // *** Prepare RhoTuple output
101  // ***
102  TDirectory *dir = gDirectory;
103  fFile=new TFile(fOutName,"RECREATE");
104  fFile->cd();
105 
106  // *** create some ntuples
107  ntp1 = new RhoTuple("ntp1", "jpsi analysis");
108  ntp2 = new RhoTuple("ntp2", "psi(2S) analysis");
109  nmc = new RhoTuple("nmc", "mctruth info");
110 
111  // assign RhoTuples to outfile
112  if (ntp1) ntp1->GetInternalTree()->SetDirectory(gDirectory);
113  if (ntp2) ntp2->GetInternalTree()->SetDirectory(gDirectory);
114  if (nmc) nmc->GetInternalTree()->SetDirectory(gDirectory);
115 
116  // *** restore original gDirectory
117  dir->cd();
118 
119  return kSUCCESS;
120 }
121 
122 // -------------------------------------------------------------------------
123 
125 {
126  // *** Get run and runtime database
127  FairRun* run = FairRun::Instance();
128  if ( ! run ) Fatal("SetParContainers", "No analysis run");
129 }
130 
131 // -------------------------------------------------------------------------
132 
133 // ----- Public method Exec --------------------------------------------
134 void PndScrutAnaTask::Exec(Option_t*)
135 {
136  // *** some variables
137  int i=0,j=0;
138 
139  // *** necessary to read the next event
140  fAnalysis->GetEvent();
141 
142  // *** print event counter
143  if (!(++fEvtCount%100)) cout << "evt "<<fEvtCount<<endl;
144 
145  // *******
146  // ******* PUT ANALYSIS CODE HERE
147  // *******
148 
149  TString pidalg = "PidChargedProbability";
150 
151  // *** QA tool for simple dumping of analysis results in RhoRuple
152  // *** WIKI: https://panda-wiki.gsi.de/foswiki/bin/view/Computing/PandaRootAnalysisJuly13#PndRhoTupleQA
153  PndRhoTupleQA qa(fAnalysis,fIni.P());
154 
155  // *** RhoCandLists for the analysis
156  RhoCandList muplus, muminus, piplus, piminus, jpsi, psi2s, all, mclist;
157 
158 
159  // *** Select with PID info pidalg and ('All'); type and mass are set
160  fAnalysis->FillList(muplus, "MuonAllPlus", pidalg);
161  fAnalysis->FillList(muminus, "MuonAllMinus", pidalg);
162  fAnalysis->FillList(piplus, "PionAllPlus", pidalg);
163  fAnalysis->FillList(piminus, "PionAllMinus", pidalg);
164 
165 
166  // *** Setup event shape object
167  fAnalysis->FillList(all, "All", pidalg);
168  PndEventShape evsh(all, fIni, 0.05, 0.1);
169 
170 
171  // *** store MC info in ntuple
172  fAnalysis->FillList(mclist, "McTruth");
173 
174  nmc->Column("ev", (Int_t) fEvtCount);
175  qa.qaMcList("", mclist, nmc);
176  nmc->DumpData();
177 
178 
179  // *** combinatorics for J/psi -> mu+ mu-
180  jpsi.Combine(muplus, muminus);
181  jpsi.Select(jpsiPreMassSel);
182  jpsi.SetType(443);
183  int njmct = fAnalysis->McTruthMatch(jpsi); // match the whole list to count #matches (should be only 1)
184 
185  // *** write ntuple for the jpsi reconstruction
186  for (j=0;j<jpsi.GetLength();++j)
187  {
188  // some general info about event (actually written for each candidate!)
189  ntp1->Column("ev", (Float_t) i);
190  ntp1->Column("cand", (Float_t) j);
191  ntp1->Column("ncand", (Float_t) jpsi.GetLength());
192  ntp1->Column("nmct", (Float_t) njmct);
193 
194  // store info about initial 4-vector
195  qa.qaP4("beam", fIni, ntp1);
196 
197  // dump information about composite candidate tree recursively (see analysis/AnalysisTools/PndRhoTupleQA)
198  qa.qaComp("j", jpsi[j], ntp1);
199 
200  // dump info about event shapes
201  qa.qaEventShapeShort("es",&evsh, ntp1);
202 
203  // *** store the 4-vector of the truth matched candidate (or a dummy, if not matched to keep ntuple consistent)
204  RhoCandidate *truth = jpsi[j]->GetMcTruth();
205  TLorentzVector lv;
206  if (truth) lv = truth->P4();
207  qa.qaP4("trj", lv, ntp1);
208 
209  ntp1->DumpData();
210  }
211 
212 
213  // *** some rough mass selection on J/psi
214  jpsi.Select(jpsiMassSel);
215 
216  // *** combinatorics for psi(2S) -> J/psi pi+ pi-
217  psi2s.Combine(jpsi, piplus, piminus);
218  psi2s.SetType(100443);
219  int npsimct = fAnalysis->McTruthMatch(psi2s); // match the whole list to count #matches (should be only 1)
220 
221  // *** write ntuple for the psi(2S) reconstruction
222  for (j=0;j<psi2s.GetLength();++j)
223  {
224  // some general info about event (actually written for each candidate!)
225  ntp2->Column("ev", (Float_t) i);
226  ntp2->Column("cand", (Float_t) j);
227  ntp2->Column("ncand", (Float_t) psi2s.GetLength());
228  ntp2->Column("nmct", (Float_t) npsimct);
229 
230  RhoKinFitter kinfit(psi2s[j]);
231  kinfit.Add4MomConstraint(fIni);
232  kinfit.Fit();
233 
234  RhoCandidate *psifit=psi2s[j]->GetFit();
235  // store info about initial 4-vector
236  qa.qaP4("beam", fIni, ntp2);
237 
238  // dump information about composite candidate tree recursively (see analysis/AnalysisTools/PndRhoTupleQA)
239  qa.qaComp("psi", psi2s[j], ntp2);
240  qa.qaComp("fpsi",psifit, ntp2);
241  ntp2->Column("fchi2", (Float_t) kinfit.GetChi2());
242 
243  // dump info about event shapes
244  qa.qaEventShapeShort("es",&evsh, ntp2);
245 
246  // *** store the 4-vector of the truth matched candidate (or a dummy, if not matched to keep ntuple consistent)
247  RhoCandidate *truth = psi2s[j]->GetMcTruth();
248  TLorentzVector lv;
249  if (truth) lv = truth->P4();
250  qa.qaP4("trpsi", lv, ntp2);
251 
252  ntp2->DumpData();
253  }
254 
255 }
256 
257 
259 {
260 
261  // *******
262  // ******* STORE YOUR HISTOS AND TUPLES
263  // *******
264 
265  fFile->Write();
266  fFile->Close();
267 
268 }
269 
CandList mclist
Int_t run
Definition: autocutx.C:47
Int_t i
Definition: run_full.C:25
PndAnalysis * fAnalysis
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
TLorentzVector fIni
RhoMassParticleSelector * jpsiMassSel
virtual void SetParContainers()
virtual void Finish()
Bool_t FillList(RhoCandList &l, TString listkey="All", TString pidTcaNames="", int trackHypothesis=-1)
CandList piplus
void Add4MomConstraint(TLorentzVector lv)
static const double mp
Definition: mzparameters.h:11
CandList muplus
RhoMassParticleSelector * jpsiPreMassSel
virtual void Exec(Option_t *opt)
TDatabasePDG * fPdg
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
RhoCandidate * GetMcTruth() const
Definition: RhoCandidate.h:437
void DumpData()
Definition: RhoTuple.cxx:391
virtual InitStatus Init()
CandList piminus
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)
Int_t GetEvent(Int_t n=-1)
Bool_t Fit()
CandList muminus
PndScrutAnaTask(double pbarmom, TString outname)