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

Go to the source code of this file.

Functions

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

Function Documentation

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

Definition at line 17 of file thailand2017/solution/tut_ana_mcmatch.C.

References RhoCandList::Combine(), PndAnalysis::FillList(), fRun, PndAnalysis::GetEntries(), PndAnalysis::GetEvent(), RhoCandList::GetLength(), i, initrun(), PndAnalysis::McTruthMatch(), muminus, muplus, out, piminus, piplus, plotmyhistos(), PndAnalysis::PndAnalysis(), RemoveGeoManager(), RhoCandList::Select(), RhoCandList::SetType(), TString, and writemyhistos().

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_mcmatch.root","RECREATE");
30 
31  // *** create some histograms
32  TH1F *hjpsim_all = new TH1F("hjpsim_all","J/#psi mass",200,0,4.5);
33  TH1F *hpsim_all = new TH1F("hpsim_all","#psi(2S) mass",200,0,5);
34 
35  TH1F *hjpsim_nm = new TH1F("hjpsim_nm","J/#psi mass (no truth match)",200,0,4.5);
36  TH1F *hpsim_nm = new TH1F("hpsim_nm","#psi(2S) mass (no truth match)",200,0,5);
37 
38  TH1F *hjpsim_ftm = new TH1F("hjpsim_ftm","J/#psi mass (full truth match)",200,0,4.5);
39  TH1F *hpsim_ftm = new TH1F("hpsim_ftm","#psi(2S) mass (full truth match)",200,0,5);
40 
41  TH1F *hjpsim_diff = new TH1F("hjpsim_diff","J/#psi mass diff to truth",100,-2,2);
42  TH1F *hpsim_diff = new TH1F("hpsim_diff","#psi(2S) mass diff to truth",100,-2,2);
43 
44  //
45  // Now the analysis stuff comes...
46  //
47 
48 
49  // *** the data reader object
50  PndAnalysis* theAnalysis = new PndAnalysis();
51  if (nevts==0) nevts= theAnalysis->GetEntries();
52 
53  // *** RhoCandLists for the analysis
54  RhoCandList muplus, muminus, piplus, piminus, jpsi, psi2s;
55 
56  // *** Mass selector for the jpsi cands
57  RhoMassParticleSelector *jpsiMassSel=new RhoMassParticleSelector("jpsi",3.096,1.0);
58 
59  // ***
60  // the event loop
61  // ***
62  while (theAnalysis->GetEvent() && i++<nevts)
63  {
64  if ((i%100)==0) cout<<"evt " << i << endl;
65 
66  // *** Select with no PID info ('All'); type and mass are set
67  theAnalysis->FillList(muplus, "MuonAllPlus");
68  theAnalysis->FillList(muminus, "MuonAllMinus");
69  theAnalysis->FillList(piplus, "PionAllPlus");
70  theAnalysis->FillList(piminus, "PionAllMinus");
71 
72  // *** combinatorics for J/psi -> mu+ mu-
73  jpsi.Combine(muplus, muminus);
74 
75  // ***
76  // *** do the TRUTH MATCH for jpsi
77  // ***
78  jpsi.SetType(443);
79 
80  for (j=0;j<jpsi.GetLength();++j)
81  {
82  hjpsim_all->Fill( jpsi[j]->M() );
83 
84  if (theAnalysis->McTruthMatch(jpsi[j]))
85  {
86  hjpsim_ftm->Fill( jpsi[j]->M() );
87  hjpsim_diff->Fill( jpsi[j]->GetMcTruth()->M() - jpsi[j]->M() );
88  }
89  else
90  hjpsim_nm->Fill( jpsi[j]->M() );
91  }
92 
93  // *** some rough mass selection
94  jpsi.Select(jpsiMassSel);
95 
96  // *** combinatorics for psi(2S) -> J/psi pi+ pi-
97  psi2s.Combine(jpsi, piplus, piminus);
98 
99  // ***
100  // *** do the TRUTH MATCH for psi(2S)
101  // ***
102  psi2s.SetType(88888);
103 
104  for (j=0;j<psi2s.GetLength();++j)
105  {
106  hpsim_all->Fill( psi2s[j]->M() );
107 
108  if (theAnalysis->McTruthMatch(psi2s[j]))
109  {
110  hpsim_ftm->Fill( psi2s[j]->M() );
111  hpsim_diff->Fill( psi2s[j]->GetMcTruth()->M() - psi2s[j]->M() );
112  }
113  else
114  hpsim_nm->Fill( psi2s[j]->M() );
115  }
116  }
117 
118  // *** change to directory where histograms are created
119  out->cd();
120 
121  // *** plot all histos
122  plotmyhistos();
123 
124  // *** write out all the histos to file
125  int nhist = writemyhistos();
126  cout<<"Writing "<<nhist<<" histograms to file"<<endl;
127  out->Save();
128 
129  // *** temporaty fix to avoid error on macro exit
131 }
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
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)
void SetType(const TParticlePDG *pdt, int start=0)
TFile * out
Definition: reco_muo.C:20
CandList piminus
Bool_t McTruthMatch(RhoCandidate *cand, Int_t level=2, bool verbose=false)
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