FairRoot/PandaRoot
thailand2017/tut_ana_pid.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 
17 // *** routine to only keep PID matched candidates in list
19 {
20  int removed = 0;
21 
22  for (int ii=l.GetLength()-1;ii>=0;--ii)
23  {
24  if ( !(ana->McTruthMatch(l[ii])) )
25  {
26  l.Remove(l[ii]);
27  removed++;
28  }
29  }
30 
31  return removed;
32 }
33 
34 
35 void tut_ana_pid(int nevts = 0, TString prefix = "signal")
36 {
37  // *** some variables
38  int i=0,j=0, k=0, l=0;
39  gStyle->SetOptFit(1011);
40 
41  // *** Initialize FairRunAna with defaults
42  TString OutFile="out_dummy.root";
43  FairRunAna* fRun = initrun(prefix, OutFile);
44  fRun->Init();
45 
46  // *** create an output file for all histograms
47  TFile *out = TFile::Open(prefix+"_ana_pid.root","RECREATE");
48 
49  // #### EXERCISE: create some histograms
50  TH1F *hjpsim_all = new TH1F("hjpsim_all","J/#psi mass (all)",200,0,4.5); // -> no PID
51  TH1F *hjpsim_lpid = new TH1F("hjpsim_lpid","J/#psi mass (loose pid)",200,0,4.5); // -> loose PID
52  // ...
53 
54  // ------------------------------
55  // Now the analysis stuff comes...
56  // ------------------------------
57 
58 
59  // *** the data reader object
60  PndAnalysis* theAnalysis = new PndAnalysis();
61  if (nevts==0) nevts= theAnalysis->GetEntries();
62 
63  // *** RhoCandLists for the analysis
64  RhoCandList muplus, muminus, piplus, piminus, jpsi, pbarp;
65 
66  // *** Mass selector for the jpsi cands
67  RhoMassParticleSelector *jpsiMassSel=new RhoMassParticleSelector("jpsi",3.096,1.0);
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  // *** combinatorics NO PID
77 
78  // #### EXERCISE: ---> Fill mu+, mu-, pi+ and pi- lists
79  theAnalysis->FillList(muplus, "MuonAllPlus");
80  //...
81 
82  // *** combinatorics for J/psi -> mu+ mu-
83  jpsi.Combine(muplus, muminus);
84  fillM(jpsi, hjpsim_all);
85  jpsi.Select(jpsiMassSel);
86 
87  // *** combinatorics for pbarp -> J/psi pi+ pi-
88  pbarp.Combine(jpsi, piplus, piminus);
89 
90 
91  // *** TRUE PID combinatorics
92 
93  // #### EXERCISE: do MC truth match for PID type
94  SelectTruePid(theAnalysis, muplus);
95  //....
96 
97 
98  // #### EXERCISE: all combinatorics again with true PID
99  //jpsi.Combine(...
100  //jpsi.Select(....
101  //pbarp.Combine(...
102 
103 
104  // #### EXERCISE: LOOSE PID combinatorics
105 
106  // *** and again with PidAlgoMvd;PidAlgoStt;PidAlgoDrc and loose selection
107  // theAnalysis->FillList(muplus, "MuonLoosePlus", "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
108  // ...
109 
110  //jpsi.Combine(..
111  //jpsi.Select(....
112  //pbarp.Combine(...
113 
114 
115  // #### EXERCISE: TIGHT PID combinatorics
116 
117  // *** and again with tight selection
118  // ...
119 
120  }
121 
122  // *** change to directory where histograms are created
123  out->cd();
124 
125  // *** plot all histos
126  plotmyhistos();
127 
128  // *** write out all the histos to file
129  int nhist = writemyhistos();
130  cout<<"Writing "<<nhist<<" histograms to file"<<endl;
131  out->Save();
132 
133  // *** temporaty fix to avoid error on macro exit
135 }
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
void tut_ana_pid(int nevts=0, TString prefix="signal")
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)
TFile * out
Definition: reco_muo.C:20
Int_t Remove(RhoCandidate *)
int SelectTruePid(PndAnalysis *ana, RhoCandList &l)
CandList piminus
Bool_t McTruthMatch(RhoCandidate *cand, Int_t level=2, bool verbose=false)
Int_t GetEvent(Int_t n=-1)
CandList muminus
int fillM(RhoCandList &l, TH1 *h)
Definition: QA/auxi.C:139
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