FairRoot/PandaRoot
Functions
thailand2017/tut_ana_fit.C File Reference
#include "auxtut.C"

Go to the source code of this file.

Functions

void tut_ana_fit (int nevts=0, TString prefix="signal")
 

Function Documentation

void tut_ana_fit ( int  nevts = 0,
TString  prefix = "signal" 
)

Definition at line 16 of file thailand2017/tut_ana_fit.C.

References RhoKinFitter::Add4MomConstraint(), RhoKinFitter::AddMassConstraint(), RhoCandList::Combine(), PndAnalysis::FillList(), RhoKinFitter::Fit(), RhoFitterBase::Fit(), fRun, RhoFitterBase::GetChi2(), PndAnalysis::GetEntries(), PndAnalysis::GetEvent(), RhoCandList::GetLength(), RhoFitterBase::GetProb(), i, initrun(), muminus, muplus, out, piminus, piplus, plotmyhistos(), PndAnalysis::PndAnalysis(), RhoCandidate::Pos(), RemoveGeoManager(), RhoCandList::Select(), TString, and writemyhistos().

17 {
18  // *** some variables
19  int i=0,j=0, k=0, l=0;
20  gStyle->SetOptFit(1011);
21 
22  // *** Initialize FairRunAna with defaults
23  TString OutFile="out_dummy.root";
24  FairRunAna* fRun = initrun(prefix, OutFile);
25  fRun->Init();
26 
27  // *** create an output file for all histograms
28  TFile *out = TFile::Open(prefix+"_ana_fit.root","RECREATE");
29 
30  // #### EXERCISE: create some histograms
31  TH1F *hjpsim_all = new TH1F("hjpsim_all","J/#psi mass",200,0,4.5);
32  TH1F *hjpsim_vf = new TH1F("hjpsim_vf", "J/#psi mass (vertex fit)",200,0,4.5);
33  TH1F *hjpsi_chi2_vf = new TH1F("hjpsi_chi2_vf", "J/#psi: #chi^{2} vertex fit",100,0,10);
34  TH1F *hjpsi_prob_vf = new TH1F("hjpsi_prob_vf", "J/#psi: Prob vertex fit",100,0,1);
35  // ....
36 
37  // ------------------------------
38  // Now the analysis stuff comes...
39  // ------------------------------
40 
41 
42  // *** the data reader object
43  PndAnalysis* theAnalysis = new PndAnalysis();
44  if (nevts==0) nevts= theAnalysis->GetEntries();
45 
46  // *** RhoCandLists for the analysis
47  RhoCandList muplus, muminus, piplus, piminus, jpsi, pbarp;
48 
49  // *** Mass selector for the jpsi cands
50  double m0_jpsi = TDatabasePDG::Instance()->GetParticle("J/psi")->Mass(); // Get nominal PDG mass of the J/psi
51  RhoMassParticleSelector *jpsiMassSel=new RhoMassParticleSelector("jpsi",m0_jpsi,1.0);
52 
53  // *** the lorentz vector of the initial pbarp, needed by 4C fitter
54  TLorentzVector ini(0, 0, 6.231552, 7.240065);
55 
56  // ***
57  // the event loop
58  // ***
59  while (theAnalysis->GetEvent() && i++<nevts)
60  {
61  if ((i%100)==0) cout<<"evt " << i << endl;
62 
63  // *** Select with no PID info ('All'); type and mass are set
64  theAnalysis->FillList(muplus, "MuonAllPlus");
65  theAnalysis->FillList(muminus, "MuonAllMinus");
66  theAnalysis->FillList(piplus, "PionAllPlus");
67  theAnalysis->FillList(piminus, "PionAllMinus");
68 
69  // *** combinatorics for J/psi -> mu+ mu-
70  jpsi.Combine(muplus, muminus);
71 
72  // ***
73  // *** do VERTEX FIT (J/psi)
74  // ***
75  for (j=0;j<jpsi.GetLength();++j)
76  {
77  // #### EXERCISE: fill unfitted mass in histogram
78  // ... ->Fill(...
79 
80  RhoKinVtxFitter vtxfitter(jpsi[j]); // instantiate a vertex fitter
81  vtxfitter.Fit();
82 
83  double chi2_vtx = vtxfitter.GetChi2(); // access chi2 of fit
84  double prob_vtx = vtxfitter.GetProb(); // access probability of fit
85 
86  // #### EXERCISE: fill chi2 and prob in histogram
87  // hjpsi_chi2_vf->Fill(...
88  // ...
89 
90  if ( prob_vtx > 0.01 ) // when good enough, fill some histos
91  {
92  RhoCandidate *jfit = jpsi[j]->GetFit(); // access the fitted cand
93  TVector3 jVtx=jfit->Pos(); // and the decay vertex position
94 
95  // #### EXERCISE: fill fitted mass and vertex position in histograms
96  // ...
97  }
98  }
99 
100  // *** some rough mass selection
101  jpsi.Select(jpsiMassSel);
102 
103  // *** combinatorics for pbarp -> J/psi pi+ pi-
104  pbarp.Combine(jpsi, piplus, piminus);
105 
106  // ***
107  // *** do 4C FIT (initial psi(2S) system)
108  // ***
109  for (j=0;j<pbarp.GetLength();++j)
110  {
111  // #### EXERCISE: fill unfitted mass in histogram
112  // ... ->Fill(...
113 
114  RhoKinFitter fitter(pbarp[j]); // instantiate the kin fitter in psi(2S)
115  fitter.Add4MomConstraint(ini); // set 4 constraint
116  fitter.Fit(); // do fit
117 
118  double chi2_4c = fitter.GetChi2(); // get chi2 of fit
119  double prob_4c = fitter.GetProb(); // access probability of fit
120 
121  // #### EXERCISE: fill chi2 and prob in histogram
122  // hpbarp_chi2_vf->Fill(...
123  // ...
124 
125  if ( prob_4c > 0.01 ) // when good enough, fill some histo
126  {
127  RhoCandidate *jfit = pbarp[j]->Daughter(0)->GetFit(); // get fitted J/psi
128 
129  // #### EXERCISE: fill fitted mass and vertex position in histograms
130  // ...
131  }
132  }
133 
134  // ***
135  // *** do MASS CONSTRAINT FIT (J/psi)
136  // ***
137  for (j=0;j<jpsi.GetLength();++j)
138  {
139  RhoKinFitter mfitter(jpsi[j]); // instantiate the RhoKinFitter in psi(2S)
140  mfitter.AddMassConstraint(m0_jpsi); // add the mass constraint
141  mfitter.Fit(); // do fit
142 
143  // #### EXERCISE: fill chi2 and prob in histogram
144  // double chi2_m = ...
145  // hpbarp_chi2_vf->Fill(...
146 
147  // #### EXERCISE: cut on prob and fill surviving candidates mass in histogram
148  // if (....
149  }
150 
151  }
152 
153  // *** change to directory where histograms are created
154  out->cd();
155 
156  // *** plot all histos
157  plotmyhistos();
158 
159  // *** write out all the histos to file
160  int nhist = writemyhistos();
161  cout<<"Writing "<<nhist<<" histograms to file"<<endl;
162  out->Save();
163 
164  // *** temporaty fix to avoid error on macro exit
166 }
Int_t GetEntries()
FairRunAna * initrun(TString prefix, TString outfile, int min=-1, int max=-1)
Definition: QA/auxi.C:32
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)
CandList piplus
FairRunAna * fRun
Definition: hit_dirc.C:58
CandList muplus
void Combine(RhoCandList &l1, RhoCandList &l2)
void Select(RhoParticleSelectorBase *pidmgr)
TFile * out
Definition: reco_muo.C:20
CandList piminus
Int_t GetEvent(Int_t n=-1)
CandList muminus
int writemyhistos(int maxy=800, double asp=1.1)
Definition: QA/auxi.C:121
void plotmyhistos(std::vector< TH1 * > h, int maxy=700, double asp=1.1)
Definition: QA/auxi.C:62