FairRoot/PandaRoot
thailand2017/solution/tut_ana_fit.C
Go to the documentation of this file.
1 class RhoCandList;
2 class RhoCandidate;
5 class PndAnalysis;
6 
7 // **** some auxilliary functions in auxtut.C ****
8 // - FairRunAna* initrun(TString prefix, TString outfile, int min=-1, int max=-1) --> Init FairRunAna
9 // - plotmyhistos() --> Plots all histograms in current TDirectory on a autosized canvas
10 // - writemyhistos() --> Writes all histos in current TFile
11 // - fillM(RhoCandList l, TH1* h) --> Fill mass histogram h with masses of candidates in l
12 // - RemoveGeoManager() --> Temporary fix for error on macro exit
13 // **** some auxilliary functions in auxtut.C ****
14 #include "auxtut.C"
15 
16 void tut_ana_fit(int nevts = 0, TString prefix = "signal")
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  // *** create some histograms
31  TH1F *hjpsim_all = new TH1F("hjpsim_all","J/#psi mass",200,0,4.5);
32  TH1F *hpsim_all = new TH1F("hpsim_all","#psi(2S) mass",200,0,5);
33 
34  TH1F *hjpsim_vf = new TH1F("hjpsim_vf", "J/#psi mass (vertex fit)",200,0,4.5);
35  TH1F *hjpsim_4cf = new TH1F("hjpsim_4cf","J/#psi mass (4C fit)",200,0,4.5);
36  TH1F *hjpsim_mcf = new TH1F("hjpsim_mcf","J/#psi mass (mass constraint fit)",200,0,4.5);
37 
38  TH1F *hjpsi_chi2_vf = new TH1F("hjpsi_chi2_vf", "J/#psi: #chi^{2} vertex fit",100,0,10);
39  TH1F *hpsi_chi2_4c = new TH1F("hpsi_chi2_4c", "#psi(2S): #chi^{2} 4C fit",100,0,250);
40  TH1F *hjpsi_chi2_mf = new TH1F("hjpsi_chi2_mf", "J/#psi: #chi^{2} mass fit",100,0,10);
41 
42  TH1F *hjpsi_prob_vf = new TH1F("hjpsi_prob_vf", "J/#psi: Prob vertex fit",100,0,1);
43  TH1F *hpsi_prob_4c = new TH1F("hpsi_prob_4c", "#psi(2S): Prob 4C fit",100,0,1);
44  TH1F *hjpsi_prob_mf = new TH1F("hjpsi_prob_mf", "J/#psi: Prob mass fit",100,0,1);
45 
46  TH2F *hvpos = new TH2F("hvpos","(x,y) projection of fitted decay vertex",100,-2,2,100,-2,2);
47 
48  //
49  // Now the analysis stuff comes...
50  //
51 
52 
53  // *** the data reader object
54  PndAnalysis* theAnalysis = new PndAnalysis();
55  if (nevts==0) nevts= theAnalysis->GetEntries();
56 
57  // *** RhoCandLists for the analysis
58  RhoCandList muplus, muminus, piplus, piminus, jpsi, psi2s;
59 
60  // *** Mass selector for the jpsi cands
61  double m0_jpsi = TDatabasePDG::Instance()->GetParticle("J/psi")->Mass(); // Get nominal PDG mass of the J/psi
62  RhoMassParticleSelector *jpsiMassSel=new RhoMassParticleSelector("jpsi",m0_jpsi,1.0);
63 
64  // *** the lorentz vector of the initial psi(2S), needed by 4C fitter
65  TLorentzVector ini(0, 0, 6.231552, 7.240065);
66 
67  // ***
68  // the event loop
69  // ***
70  while (theAnalysis->GetEvent() && i++<nevts)
71  {
72  if ((i%100)==0) cout<<"evt " << i << endl;
73 
74  // *** Select with no PID info ('All'); type and mass are set
75  theAnalysis->FillList(muplus, "MuonAllPlus");
76  theAnalysis->FillList(muminus, "MuonAllMinus");
77  theAnalysis->FillList(piplus, "PionAllPlus");
78  theAnalysis->FillList(piminus, "PionAllMinus");
79 
80  // *** combinatorics for J/psi -> mu+ mu-
81  jpsi.Combine(muplus, muminus);
82 
83  // ***
84  // *** do VERTEX FIT (J/psi)
85  // ***
86  for (j=0;j<jpsi.GetLength();++j)
87  {
88  hjpsim_all->Fill(jpsi[j]->M()); // fill histo for all J/psi candidates
89 
90  RhoKinVtxFitter vtxfitter(jpsi[j]); // instantiate a vertex fitter
91  vtxfitter.Fit();
92 
93  double chi2_vtx = vtxfitter.GetChi2(); // access chi2 of fit
94  double prob_vtx = vtxfitter.GetProb(); // access probability of fit
95  hjpsi_chi2_vf->Fill(chi2_vtx);
96  hjpsi_prob_vf->Fill(prob_vtx);
97 
98  if ( prob_vtx > 0.01 ) // when good enough, fill some histos
99  {
100  RhoCandidate *jfit = jpsi[j]->GetFit(); // access the fitted cand
101  TVector3 jVtx=jfit->Pos(); // and the decay vertex position
102 
103  hjpsim_vf->Fill(jfit->M());
104  hvpos->Fill(jVtx.X(),jVtx.Y());
105  }
106  }
107 
108  // *** some rough mass selection
109  jpsi.Select(jpsiMassSel);
110 
111  // *** combinatorics for psi(2S) -> J/psi pi+ pi-
112  psi2s.Combine(jpsi, piplus, piminus);
113 
114  // ***
115  // *** do 4C FIT (initial psi(2S) system)
116  // ***
117  for (j=0;j<psi2s.GetLength();++j)
118  {
119  hpsim_all->Fill(psi2s[j]->M()); // fill histo for all psi(2S) candidates
120 
121  RhoKinFitter fitter(psi2s[j]); // instantiate the kin fitter in psi(2S)
122  fitter.Add4MomConstraint(ini); // set 4 constraint
123  fitter.Fit(); // do fit
124 
125  double chi2_4c = fitter.GetChi2(); // get chi2 of fit
126  double prob_4c = fitter.GetProb(); // access probability of fit
127  hpsi_chi2_4c->Fill(chi2_4c);
128  hpsi_prob_4c->Fill(prob_4c);
129 
130  if ( prob_4c > 0.01 ) // when good enough, fill some histo
131  {
132  RhoCandidate *jfit = psi2s[j]->Daughter(0)->GetFit(); // get fitted J/psi
133 
134  hjpsim_4cf->Fill(jfit->M());
135  }
136  }
137 
138  // ***
139  // *** do MASS CONSTRAINT FIT (J/psi)
140  // ***
141  for (j=0;j<jpsi.GetLength();++j)
142  {
143  RhoKinFitter mfitter(jpsi[j]); // instantiate the RhoKinFitter in psi(2S)
144  mfitter.AddMassConstraint(m0_jpsi); // add the mass constraint
145  mfitter.Fit(); // do fit
146 
147  double chi2_m = mfitter.GetChi2(); // get chi2 of fit
148  double prob_m = mfitter.GetProb(); // access probability of fit
149  hjpsi_chi2_mf->Fill(chi2_m);
150  hjpsi_prob_mf->Fill(prob_m);
151 
152  if ( prob_m > 0.01 ) // when good enough, fill some histo
153  {
154  RhoCandidate *jfit = jpsi[j]->GetFit(); // access the fitted cand
155  hjpsim_mcf->Fill(jfit->M());
156  }
157  }
158 
159  }
160 
161  // *** change to directory where histograms are created
162  out->cd();
163 
164  // *** plot all histos
165  plotmyhistos();
166 
167  // *** write out all the histos to file
168  int nhist = writemyhistos();
169  cout<<"Writing "<<nhist<<" histograms to file"<<endl;
170  out->Save();
171 
172  // *** temporaty fix to avoid error on macro exit
174 }
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
TH2F * hvpos
Definition: plot_eta_c.C:47
Bool_t FillList(RhoCandList &l, TString listkey="All", TString pidTcaNames="", int trackHypothesis=-1)
CandList piplus
void Add4MomConstraint(TLorentzVector lv)
FairRunAna * fRun
Definition: hit_dirc.C:58
CandList muplus
void Combine(RhoCandList &l1, RhoCandList &l2)
PndAnalysis(TString tname1="", TString tname2="", TString algnamec="PidAlgoIdealCharged", TString algnamen="PidAlgoIdealNeutral")
Definition: PndAnalysis.cxx:48
void Select(RhoParticleSelectorBase *pidmgr)
double GetProb() const
Definition: RhoFitterBase.h:50
TFile * out
Definition: reco_muo.C:20
void tut_ana_fit(int nevts=0, TString prefix="signal")
Double_t M() const
CandList piminus
double GetChi2() const
Definition: RhoFitterBase.h:48
Int_t GetEvent(Int_t n=-1)
Bool_t Fit()
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