FairRoot/PandaRoot
thailand2017/solution/tut_ana_comb.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 void tut_ana_comb(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_comb.root","RECREATE");
30 
31  // *** create some histograms
32  TH1F *hjpsim_all = new TH1F("hjpsim_all","J/#psi mass (all)",200,0,4.5);
33  TH1F *hpsim_all = new TH1F("hpsim_all","#psi(2S) mass (all)",200,0,5);
34 
35  TH1F *hjpsim_pcut = new TH1F("hjpsim_pcut","J/#psi mass (comb. by hand with p cut)",200,0,4.5);
36  TH1F *hpsim_pcut = new TH1F("hpsim_pcut","#psi(2S) mass (comb. by hand with p cut))",200,0,5);
37 
38  //
39  // Now the analysis stuff comes...
40  //
41 
42 
43  // *** the data reader object
44  PndAnalysis* theAnalysis = new PndAnalysis();
45  if (nevts==0) nevts= theAnalysis->GetEntries();
46 
47  // *** RhoCandLists for the analysis
48  RhoCandList muplus, muminus, piplus, piminus, jpsi, psi2s;
49 
50  // *** Mass selector for the jpsi cands
51  RhoMassParticleSelector *jpsiMassSel=new RhoMassParticleSelector("jpsi",3.096,1.0);
52 
53  // ***
54  // the event loop
55  // ***
56  while (theAnalysis->GetEvent() && i++<nevts)
57  {
58  if ((i%100)==0) cout<<"evt " << i << endl;
59 
60  // *** Select with no PID info ('All'); type and mass are set
61  theAnalysis->FillList(muplus, "MuonAllPlus");
62  theAnalysis->FillList(muminus, "MuonAllMinus");
63  theAnalysis->FillList(piplus, "PionAllPlus");
64  theAnalysis->FillList(piminus, "PionAllMinus");
65 
66  // ***
67  // *** SIMPLE COMBINATORICS for J/psi -> mu+ mu-
68  // ***
69  jpsi.Combine(muplus, muminus);
70  fillM(jpsi, hjpsim_all);
71 
72  // *** some rough mass selection
73  jpsi.Select(jpsiMassSel);
74 
75  // ***
76  // *** SIMPLE COMBINATORICS for psi(2S) -> J/psi pi+ pi-
77  // ***
78  psi2s.Combine(jpsi, piplus, piminus);
79  fillM(psi2s,hpsim_all);
80 
81  // ***
82  // *** COMBINATORICS BY HAND for J/psi -> mu+ mu- with extra p cut
83  // ***
84 
85  // clean jpsi list and fill it with mu+ mu- combinations
86  jpsi.Cleanup();
87 
88  for (j=0;j<muplus.GetLength();++j)
89  {
90  if (muplus[j]->P()<0.3) continue; // apply momentum selection (can be done easier
91  // with a momentum selector, just for demonstration here)
92  for (k=0;k<muminus.GetLength();++k)
93  {
94  if (muminus[k]->P()<0.3) continue;
95 
96  RhoCandidate *combCand = muplus[j]->Combine(muminus[k]);
97  jpsi.Append(combCand);
98  }
99  }
100 
101  fillM(jpsi,hjpsim_pcut);
102 
103  // *** some rough mass selection
104  jpsi.Select(jpsiMassSel);
105 
106  // ***
107  // *** COMBINATORICS BY HAND for psi(2S) -> J/psi pi+ pi- with extra p cut
108  // ***
109 
110  // clean psi(2S) list and fill it with J/psi pi+ mpi- combinations
111  psi2s.Cleanup();
112 
113  for (j=0;j<jpsi.GetLength();++j)
114  {
115  for (k=0;k<piplus.GetLength();++k)
116  {
117  // momentum selection and check clash with J/psi
118  if ( piplus[k]->P()<0.2 || piplus[k]->Overlaps(jpsi[j]) ) continue;
119 
120  for (l=0;l<piminus.GetLength();++l)
121  {
122  // momentum selection and check clash with J/psi
123  if ( piminus[l]->P()<0.2 || piminus[l]->Overlaps(jpsi[j]) ) continue;
124 
125  RhoCandidate *combCand = jpsi[j]->Combine(piplus[k], piminus[l]);
126  psi2s.Append(combCand);
127  }
128  }
129  }
130 
131  fillM(psi2s,hpsim_pcut);
132  }
133 
134  // *** change to directory where histograms are created
135  out->cd();
136 
137  // *** plot all histos
138  plotmyhistos();
139 
140  // *** write out all the histos to file
141  int nhist = writemyhistos();
142  cout<<"Writing "<<nhist<<" histograms to file"<<endl;
143  out->Save();
144 
145  // *** temporaty fix to avoid error on macro exit
147 }
Int_t GetEntries()
FairRunAna * initrun(TString prefix, TString outfile, int min=-1, int max=-1)
Definition: QA/auxi.C:32
void Append(const RhoCandidate *c)
Definition: RhoCandList.h:52
void Cleanup()
Definition: RhoCandList.cxx:62
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)
PndAnalysis(TString tname1="", TString tname2="", TString algnamec="PidAlgoIdealCharged", TString algnamen="PidAlgoIdealNeutral")
Definition: PndAnalysis.cxx:48
void tut_ana_comb(int nevts=0, TString prefix="signal")
void Select(RhoParticleSelectorBase *pidmgr)
TFile * out
Definition: reco_muo.C:20
GeV c P
CandList piminus
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