FairRoot/PandaRoot
tut_ana_ntp_qa.C
Go to the documentation of this file.
1 class RhoCandList;
2 class RhoCandidate;
5 class PndAnalysis;
6 class RhoTuple;
7 
8 // **** some auxilliary functions in auxtut.C ****
9 // - FairRunAna* initrun(TString prefix, TString outfile, int min=-1, int max=-1) --> Init FairRunAna
10 // - plotmyhistos() --> Plots all histograms in current TDirectory on a autosized canvas
11 // - writemyhistos() --> Writes all histos in current TFile
12 // - fillM(RhoCandList l, TH1* h) --> Fill mass histogram h with masses of candidates in l
13 // - RemoveGeoManager() --> Temporary fix for error on macro exit
14 // **** some auxilliary functions in auxtut.C ****
15 #include "auxtut.C"
16 
17 void tut_ana_ntp_qa(int nevts = 0, TString prefix = "signal")
18 {
19  // *** some variables
20  int i=0,j=0, k=0, l=0;
21  gStyle->SetOptFit(1011);
22 
23  // *** Initialize FairRunAna with defaults
24  TString OutFile="out_dummy.root";
25  FairRunAna* fRun = initrun(prefix, OutFile);
26  fRun->Init();
27 
28  // *** create an output file for all histograms
29  TFile *out = TFile::Open(prefix+"_ana_ntp.root","RECREATE");
30 
31  // *** create ntuples for J/psi and psi(2S)
32  RhoTuple *njpsi = new RhoTuple("njpsi","J/psi Analysis");
33  RhoTuple *npsip = new RhoTuple("npsip","psi' Analysis");
34 
35  // *** create some columns which might not be filled sometimes
36  njpsi->Column("tjpsim", 0.0f, -999.9f);
37  njpsi->Column("tjpsip", 0.0f, -999.9f);
38  njpsi->Column("tjpsitht", 0.0f, -999.9f);
39 
40  npsip->Column("tpsim", 0.0f, -999.9f);
41  npsip->Column("tpsip", 0.0f, -999.9f);
42  npsip->Column("tpsitht", 0.0f, -999.9f);
43 
44  //
45  // Now the analysis stuff comes...
46  //
47 
48  // *** the data reader object
49  PndAnalysis* theAnalysis = new PndAnalysis();
50  if (nevts==0) nevts= theAnalysis->GetEntries();
51 
52  // *** RhoCandLists for the analysis
53  RhoCandList muplus, muminus, piplus, piminus, jpsi, psi2s;
54 
55  // *** Mass selector for the jpsi cands
56  double m0_jpsi = TDatabasePDG::Instance()->GetParticle("J/psi")->Mass(); // Get nominal PDG mass of the J/psi
57  RhoMassParticleSelector *jpsiMassSel=new RhoMassParticleSelector("jpsi",m0_jpsi,1.0);
58 
59  // *** Pid Selection Algorithms
60  TString pidSelection = "PidAlgoEmcBayes;PidAlgoDrc;PidAlgoDisc;PidAlgoStt;PidAlgoMdtHardCuts";
61 
62  // *** the lorentz vector of the initial psi(2S)
63  TLorentzVector ini(0, 0, 6.231552, 7.240065);
64 
65  // *** the QA tool for easy ntuple output
66  PndRhoTupleQA qa(theAnalysis,ini.P());
67 
68 
69  // ***
70  // the event loop
71  // ***
72  while (theAnalysis->GetEvent() && i++<nevts)
73  {
74  if ((i%100)==0) cout<<"evt " << i << endl;
75 
76  // *** Select with no PID info ('All'); type and mass are set
77  theAnalysis->FillList(muplus, "MuonAllPlus", pidSelection);
78  theAnalysis->FillList(muminus, "MuonAllMinus", pidSelection);
79  theAnalysis->FillList(piplus, "PionAllPlus", pidSelection);
80  theAnalysis->FillList(piminus, "PionAllMinus", pidSelection);
81 
82  // *** combinatorics for J/psi -> mu+ mu-
83  jpsi.Combine(muplus, muminus);
84  jpsi.SetType(443);
85 
86  // *** some mass pre selection
87  //jpsi.Select(jpsiMassSel);
88 
89  // ***
90  // *** do all kind of analysis and store in N-tuple
91  // ***
92  for (j=0;j<jpsi.GetLength();++j)
93  {
94  // get daughters
95  RhoCandidate *mup = jpsi[j]->Daughter(0);
96  RhoCandidate *mum = jpsi[j]->Daughter(1);
99 
100  // get truth information
101  bool mct = theAnalysis->McTruthMatch(jpsi[j]);
102  RhoCandidate *true_jpsi = jpsi[j]->GetMcTruth();
103 
104  // perform vertex fitter
105  RhoKinVtxFitter vtxfitter(jpsi[j]); // instantiate a vertex fitter
106  vtxfitter.Fit();
107 
108  RhoCandidate *fitvtx_jpsi = jpsi[j]->GetFit();
109  double chi2_vtx = vtxfitter.GetChi2(); // access chi2 of fit
110  double prob_vtx = vtxfitter.GetProb(); // access probability of fit
111  TVector3 vtxpos(-999.,-999.,-999.);
112  if (fitvtx_jpsi) vtxpos = fitvtx_jpsi->Daughter(0)->Pos();
113 
114  // perform mass fit
115  RhoKinFitter mfitter(jpsi[j]); // instantiate the RhoKinFitter in psi(2S)
116  mfitter.AddMassConstraint(m0_jpsi); // add the mass constraint
117  mfitter.Fit(); // do fit
118 
119  RhoCandidate *fitmass_jpsi = jpsi[j]->GetFit();
120  double chi2_mass = mfitter.GetChi2(); // get chi2 of fit
121  double prob_mass = mfitter.GetProb(); // access probability of fit
122 
123  // *** now write ntuple information
124 
125  // *** general event info
126  njpsi->Column("ev", (Float_t) i, -999.9f);
127  njpsi->Column("cand", (Float_t) j, -999.9f);
128 
129  // *** basic J/psi info
130  njpsi->Column("jpsim", (Float_t) jpsi[j]->M(), -999.9f);
131  njpsi->Column("jpsip", (Float_t) jpsi[j]->P(), -999.9f);
132  njpsi->Column("jpsipt", (Float_t) jpsi[j]->P3().Pt(), -999.9f);
133  njpsi->Column("jpsitht", (Float_t) jpsi[j]->P3().Theta(), -999.9f);
134  njpsi->Column("jpsimissm", (Float_t) (ini-(jpsi[j]->P4())).M(), -999.9f);
135 
136  // *** MC truth info
137  njpsi->Column("mct", (Float_t) mct, -999.9f);
138  if (true_jpsi)
139  {
140  njpsi->Column("tjpsim", (Float_t) true_jpsi->M(), -999.9f);
141  njpsi->Column("tjpsip", (Float_t) true_jpsi->M(), -999.9f);
142  njpsi->Column("tjpsitht",(Float_t) true_jpsi->P3().Theta(), -999.9f);
143  }
144 
145  // *** fitting info
146  njpsi->Column("jpsimvtx", (Float_t) fitvtx_jpsi->M(), -999.9f);
147  njpsi->Column("chi2vtx", (Float_t) chi2_vtx, -999.9f);
148  njpsi->Column("probvtx", (Float_t) prob_vtx, -999.9f);
149  njpsi->Column("vtxx", (Float_t) vtxpos.X(), -999.9f);
150  njpsi->Column("vtxy", (Float_t) vtxpos.Y(), -999.9f);
151  njpsi->Column("vtxz", (Float_t) vtxpos.Z(), -999.9f);
152 
153  njpsi->Column("jpsimmass", (Float_t) fitmass_jpsi->M(), -999.9f);
154  njpsi->Column("chi2mass", (Float_t) chi2_mass, -999.9f);
155  njpsi->Column("probmass", (Float_t) prob_mass, -999.9f);
156 
157  // *** kinematic info of daughters
158  njpsi->Column("mupp", (Float_t) mup->P(), -999.9f);
159  njpsi->Column("muppt", (Float_t) mup->P3().Pt(), -999.9f);
160  njpsi->Column("muptht", (Float_t) mup->P3().Theta(), -999.9f);
161 
162  njpsi->Column("mump", (Float_t) mum->P(), -999.9f);
163  njpsi->Column("mumpt", (Float_t) mum->P3().Pt(), -999.9f);
164  njpsi->Column("mumtht", (Float_t) mum->P3().Theta(), -999.9f);
165 
166  // *** PID info of daughters
167  njpsi->Column("muppid", (Float_t) mup->GetPidInfo(1), -999.9f);
168  njpsi->Column("mumpid", (Float_t) mum->GetPidInfo(1), -999.9f);
169 
170  // *** and finally FILL Ntuple
171  njpsi->DumpData();
172 
173  }
174 
175  // *** combinatorics for psi(2S) -> J/psi pi+ pi-
176  psi2s.Combine(jpsi, piplus, piminus);
177  psi2s.SetType(88888);
178 
179  for (j=0;j<psi2s.GetLength();++j)
180  {
181  // get daughters
182  RhoCandidate *jp = psi2s[j]->Daughter(0);
183  RhoCandidate *pip = psi2s[j]->Daughter(1);
184  RhoCandidate *pim = psi2s[j]->Daughter(2);
185 
188 
189  // get truth information
190  bool mct = theAnalysis->McTruthMatch(psi2s[j]);
191  RhoCandidate *true_psi = psi2s[j]->GetMcTruth();
192 
193  // do 4C fit
194  RhoKinFitter fitter(psi2s[j]); // instantiate the kin fitter in psi(2S)
195  fitter.Add4MomConstraint(ini); // set 4 constraint
196  fitter.Fit(); // do fit
197  RhoCandidate *fit4c_jpsi = psi2s[j]->Daughter(0)->GetFit(); // get fitted J/psi
198 
199  double chi2_4c = fitter.GetChi2(); // get chi2 of fit
200  double prob_4c = fitter.GetProb(); // access probability of fit
201 
202  // *** general event info
203  npsip->Column("ev", (Float_t) i, -999.9f);
204  npsip->Column("cand", (Float_t) j, -999.9f);
205 
206  // *** basic psi(2s) info
207  qa.qaCand("psi", psi2s[j], npsip);
208 
209  // *** basic J/psi info
210  qa.qaCand("jpsi" , jp , npsip);
211  qa.qaCand("jpsi4cfit", fit4c_jpsi, npsip);
212 
213  // *** MC truth info
214  npsip->Column("mct", (Float_t) mct, -999.9f);
215  if (true_psi)
216  {
217  npsip->Column("tpsim", (Float_t) true_psi->M(), -999.9f);
218  npsip->Column("tpsip", (Float_t) true_psi->M(), -999.9f);
219  npsip->Column("tpsitht",(Float_t) true_psi->P3().Theta(), -999.9f);
220  }
221 
222  // *** kinematic info of daughters
223  qa.qaCand("pip", pip, npsip);
224  qa.qaCand("pim", pip, npsip);
225 
226  // *** PID info of daughters
227  qa.qaPid("pip", pip, npsip);
228  qa.qaPid("pim", pip, npsip);
229 
230  // *** and finally FILL Ntuple
231  npsip->DumpData();
232  }
233 
234  }
235 
236  // *** write out all the histos
237  out->cd();
238 
239  njpsi->GetInternalTree()->Write();
240  npsip->GetInternalTree()->Write();
241 
242  out->Save();
243 
244  // *** temporaty fix to avoid error on macro exit
246 }
Int_t GetEntries()
FairRunAna * initrun(TString prefix, TString outfile, int min=-1, int max=-1)
Definition: QA/auxi.C:32
void AddMassConstraint(double mass)
Int_t i
Definition: run_full.C:25
void RemoveGeoManager()
Definition: auxtut.C:11
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)
PndPidCandidate * GetRecoCandidate() const
Definition: RhoCandidate.h:376
RhoTuple()
Definition: RhoTuple.cxx:27
RhoCandidate * Daughter(Int_t n)
CandList piplus
void Add4MomConstraint(TLorentzVector lv)
FairRunAna * fRun
Definition: hit_dirc.C:58
CandList muplus
void Combine(RhoCandList &l1, RhoCandList &l2)
TFile * f
Definition: bump_analys.C:12
void Column(const char *label, Bool_t value, Bool_t defval=0, const char *block=0)
Definition: RhoTuple.cxx:56
double GetProb() const
Definition: RhoFitterBase.h:50
void SetType(const TParticlePDG *pdt, int start=0)
TFile * out
Definition: reco_muo.C:20
Double_t M() const
Double_t P() const
void tut_ana_ntp_qa(int nevts=0, TString prefix="signal")
void DumpData()
Definition: RhoTuple.cxx:391
GeV c P
CandList piminus
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
static const double mup
Definition: mzparameters.h:21
double GetPidInfo(int hypo)
TVector3 P3() const
Definition: RhoCandidate.h:199