FairRoot/PandaRoot
rho/tut_ana_pid.C
Go to the documentation of this file.
1 class RhoCandList;
2 class RhoCandidate;
5 class PndAnalysis;
6 
7 // *** routine to only keep PID matched candidates in list
9 {
10  int removed = 0;
11 
12  for (int ii=l.GetLength()-1;ii>=0;--ii)
13  {
14  if ( !(ana->McTruthMatch(l[ii])) )
15  {
16  l.Remove(l[ii]);
17  removed++;
18  }
19  }
20 
21  return removed;
22 }
23 
24 
25 void tut_ana_pid(int nevts = 0, TString prefix = "signal")
26 {
27  // *** some variables
28  int i=0,j=0, k=0, l=0;
29  gStyle->SetOptFit(1011);
30 
31  // *** the output file for FairRunAna
32  TString OutFile="out_dummy.root";
33 
34  // *** the files coming from the simulation
35  TString inPidFile = prefix+"_pid.root"; // this file contains the PndPidCandidates and McTruth
36  TString inParFile = prefix+"_par.root";
37 
38  // *** PID table with selection thresholds; can be modified by the user
39  TString pidParFile = TString(gSystem->Getenv("VMCWORKDIR"))+"/macro/params/all.par";
40 
41  // *** initialization
42  FairLogger::GetLogger()->SetLogToFile(kFALSE);
43  FairRunAna* fRun = new FairRunAna();
44  FairRuntimeDb* rtdb = fRun->GetRuntimeDb();
45  fRun->SetInputFile(inPidFile);
46 
47  // *** setup parameter database
48  FairParRootFileIo* parIO = new FairParRootFileIo();
49  parIO->open(inParFile);
50  FairParAsciiFileIo* parIOPid = new FairParAsciiFileIo();
51  parIOPid->open(pidParFile.Data(),"in");
52 
53  rtdb->setFirstInput(parIO);
54  rtdb->setSecondInput(parIOPid);
55  rtdb->setOutput(parIO);
56 
57  fRun->SetOutputFile(OutFile);
58  fRun->Init();
59 
60  // *** create an output file for all histograms
61  TFile *out = TFile::Open(prefix+"_ana_pid.root","RECREATE");
62 
63  // *** create some histograms
64  TH1F *hjpsim_all = new TH1F("hjpsim_all","J/#psi mass (all)",200,0,4.5);
65  TH1F *hpsim_all = new TH1F("hpsim_all","#psi(2S) mass (all)",200,0,5);
66 
67  TH1F *hjpsim_lpid = new TH1F("hjpsim_lpid","J/#psi mass (loose pid)",200,0,4.5);
68  TH1F *hpsim_lpid = new TH1F("hpsim_lpid","#psi(2S) mass (loose pid)",200,0,5);
69 
70  TH1F *hjpsim_tpid = new TH1F("hjpsim_tpid","J/#psi mass (tight pid)",200,0,4.5);
71  TH1F *hpsim_tpid = new TH1F("hpsim_tpid","#psi(2S) mass (tight pid)",200,0,5);
72 
73  TH1F *hjpsim_trpid = new TH1F("hjpsim_trpid","J/#psi mass (true pid)",200,0,4.5);
74  TH1F *hpsim_trpid = new TH1F("hpsim_trpid","#psi(2S) mass (true pid)",200,0,5);
75 
76 
77  //
78  // Now the analysis stuff comes...
79  //
80 
81 
82  // *** the data reader object
83  PndAnalysis* theAnalysis = new PndAnalysis();
84  if (nevts==0) nevts= theAnalysis->GetEntries();
85 
86  // *** RhoCandLists for the analysis
87  RhoCandList muplus, muminus, piplus, piminus, jpsi, psi2s;
88 
89  // *** Mass selector for the jpsi cands
90  RhoMassParticleSelector *jpsiMassSel=new RhoMassParticleSelector("jpsi",3.096,1.0);
91 
92  // ***
93  // the event loop
94  // ***
95  while (theAnalysis->GetEvent() && i++<nevts)
96  {
97  if ((i%100)==0) cout<<"evt " << i << endl;
98 
99  // ***
100  // *** NO PID combinatorics
101  // ***
102 
103  // *** Select with no PID info ('All'); type and mass are set
104  theAnalysis->FillList(muplus, "MuonAllPlus");
105  theAnalysis->FillList(muminus, "MuonAllMinus");
106  theAnalysis->FillList(piplus, "PionAllPlus");
107  theAnalysis->FillList(piminus, "PionAllMinus");
108 
109  // *** combinatorics for J/psi -> mu+ mu-
110  jpsi.Combine(muplus, muminus);
111 
112  for (j=0;j<jpsi.GetLength();++j) hjpsim_all->Fill( jpsi[j]->M() );
113 
114  // *** some rough mass selection
115  jpsi.Select(jpsiMassSel);
116 
117  // *** combinatorics for psi(2S) -> J/psi pi+ pi-
118  psi2s.Combine(jpsi, piplus, piminus);
119  for (j=0;j<psi2s.GetLength();++j) hpsim_all->Fill( psi2s[j]->M() );
120 
121 
122  // ***
123  // *** TRUE PID combinatorics
124  // ***
125 
126  // *** do MC truth match for PID type
127  SelectTruePid(theAnalysis, muplus);
128  SelectTruePid(theAnalysis, muminus);
129  SelectTruePid(theAnalysis, piplus);
130  SelectTruePid(theAnalysis, piminus);
131 
132  // *** all combinatorics again with true PID
133  jpsi.Combine(muplus, muminus);
134  for (j=0;j<jpsi.GetLength();++j) hjpsim_trpid->Fill( jpsi[j]->M() );
135  jpsi.Select(jpsiMassSel);
136 
137  psi2s.Combine(jpsi, piplus, piminus);
138  for (j=0;j<psi2s.GetLength();++j) hpsim_trpid->Fill( psi2s[j]->M() );
139 
140 
141  // ***
142  // *** LOOSE PID combinatorics
143  // ***
144 
145  // *** and again with PidAlgoMvd;PidAlgoStt;PidAlgoDrc and loose selection
146  theAnalysis->FillList(muplus, "MuonLoosePlus", "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
147  theAnalysis->FillList(muminus, "MuonLooseMinus", "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
148  theAnalysis->FillList(piplus, "PionLoosePlus", "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
149  theAnalysis->FillList(piminus, "PionLooseMinus", "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
150 
151  jpsi.Combine(muplus, muminus);
152  for (j=0;j<jpsi.GetLength();++j) hjpsim_lpid->Fill( jpsi[j]->M() );
153  jpsi.Select(jpsiMassSel);
154 
155  psi2s.Combine(jpsi, piplus, piminus);
156  for (j=0;j<psi2s.GetLength();++j) hpsim_lpid->Fill( psi2s[j]->M() );
157 
158 
159  // ***
160  // *** TIGHT PID combinatorics
161  // ***
162 
163  // *** and again with PidAlgoMvd;PidAlgoStt and tight selection
164  theAnalysis->FillList(muplus, "MuonTightPlus", "PidAlgoMdtHardCuts");
165  theAnalysis->FillList(muminus, "MuonTightMinus", "PidAlgoMdtHardCuts");
166  theAnalysis->FillList(piplus, "PionLoosePlus", "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
167  theAnalysis->FillList(piminus, "PionLooseMinus", "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
168 
169  jpsi.Combine(muplus, muminus);
170  for (j=0;j<jpsi.GetLength();++j) hjpsim_tpid->Fill( jpsi[j]->M() );
171  jpsi.Select(jpsiMassSel);
172 
173  psi2s.Combine(jpsi, piplus, piminus);
174  for (j=0;j<psi2s.GetLength();++j) hpsim_tpid->Fill( psi2s[j]->M() );
175 
176  }
177 
178  // *** write out all the histos
179  out->cd();
180 
181  hjpsim_all->Write();
182  hpsim_all->Write();
183  hjpsim_lpid->Write();
184  hpsim_lpid->Write();
185  hjpsim_tpid->Write();
186  hpsim_tpid->Write();
187  hjpsim_trpid->Write();
188  hpsim_trpid->Write();
189 
190  out->Save();
191 
192 }
Int_t GetEntries()
int SelectTruePid(PndAnalysis *ana, RhoCandList &l)
Int_t i
Definition: run_full.C:25
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 tut_ana_pid(int nevts=0, TString prefix="signal")
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)
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
TFile * out
Definition: reco_muo.C:20
Int_t Remove(RhoCandidate *)
CandList piminus
Bool_t McTruthMatch(RhoCandidate *cand, Int_t level=2, bool verbose=false)
Int_t GetEvent(Int_t n=-1)
CandList muminus