FairRoot/PandaRoot
tut_ana_d0.C
Go to the documentation of this file.
1 class FairRunAna;
2 
3 // Check if file exists and readable
4 bool checkfile(TString fn)
5 {
6  bool fileok=true;
7  TFile fff(fn, "READ");
8  if (fff.IsZombie()) fileok=false;
9  TTree *t=(TTree*)fff.Get("pndsim");
10  if (t==0x0) fileok=false;
11 
12  if (!fileok) cout <<"Skipping broken file '"<<fn<<"'"<<endl;
13  fff.Close();
14 
15  return fileok;
16 }
17 
18 // Add many input files to FairRunAna
19 void attachFiles(FairRunAna* fRun, TString pref, int min, int max)
20 {
21  bool firstfile=true;
22  for (int i=min;i<=max;++i) {
23  TString fname = TString::Format("%s_%d_pid.root",pref.Data(),i);
24 
25  if (checkfile(fname) ) {
26  if (firstfile) fRun->SetInputFile(fname);
27  else fRun->AddFile(fname);
28  firstfile=false;
29  }
30  }
31 }
32 
33 void tut_ana_d0(TString pref="pid_complete.root", int min=-1, int max=1, int nevts=0)
34 {
35  TString OutFile, inParFile;
36 
37  double pbarmom = 9.808065;
38  double mp=0.938272;
39  TLorentzVector ini(0,0,pbarmom, sqrt(pbarmom*pbarmom+mp*mp)+mp);
40 
41  // *** add input files
42  FairRunAna *fRun= new FairRunAna();
43 
44  // *** just open one file
45  if (min<0)
46  {
47  // *** set input file, output file and par file
48  OutFile = "ana.root";
49  inParFile = "simparams.root";
50 
51  fRun->SetInputFile(pref);
52  }
53  // *** attach many input files
54  else {
55  // *** set output file and par file
56  OutFile = TString::Format("%s_ana_%d_%d.root",pref.Data(), min, max);
57  inParFile = TString::Format("%s_%d_par.root",pref.Data(), min);
58 
59  attachFiles(fRun, pref, min, max);
60  }
61 
62  // *** PID table with selection thresholds; can be modified by the user
63  TString pidParFile = TString(gSystem->Getenv("VMCWORKDIR"))+"/macro/params/all.par";
64 
65  // *** initialization
66  FairLogger::GetLogger()->SetLogToFile(kFALSE);
67  FairRuntimeDb* rtdb = fRun->GetRuntimeDb();
68 
69  // *** setup parameter database
70  FairParRootFileIo* parIO = new FairParRootFileIo();
71  parIO->open(inParFile);
72  FairParAsciiFileIo* parIOPid = new FairParAsciiFileIo();
73  parIOPid->open(pidParFile.Data(),"in");
74 
75  rtdb->setFirstInput(parIO);
76  rtdb->setSecondInput(parIOPid);
77  rtdb->setOutput(parIO);
78 
79  fRun->SetOutputFile("dummyout.root");
80  fRun->Init();
81 
82  // *** create an output file for all histograms
83  TFile *out = TFile::Open(OutFile,"RECREATE");
84 
85  // *** the data reader object
86  PndAnalysis* theAnalysis = new PndAnalysis();
87  if (nevts==0) nevts= theAnalysis->GetEntries();
88 
89  int i=0;
90 
91  RhoCandList kp, km, pip, pim, d0, d0b;
92  TString pidsel = "PidAlgoEmcBayes;PidAlgoDrc;PidAlgoDisc;PidAlgoStt;PidAlgoMdtHardCuts";
93 
94  RhoMassParticleSelector *fD0Sel = new RhoMassParticleSelector("D0Sel", 1.864, 1.0);
95  RhoVtxPoca fVtxPoca;
96 
97  RhoTuple *nd0 = new RhoTuple("nd0","my D0 tuple");
98 
99  // *** the event loop
100  while (theAnalysis->GetEvent() && i++<nevts)
101  {
102  if ((i%100)==0) cout<<"evt " << i << endl;
103 
104  // ***
105  // *** HERE YOUR ANALYSIS CODE GOES!
106  // ***
107  theAnalysis->FillList( kp, "KaonAllPlus", pidsel);
108  theAnalysis->FillList( km, "KaonAllMinus", pidsel);
109  theAnalysis->FillList( pip, "PionAllPlus", pidsel);
110  theAnalysis->FillList( pim, "PionAllMinus", pidsel);
111 
112  d0.Combine(km, pip);
113  d0.SetType(421);
114  d0b.Combine(kp, pim);
115  d0b.SetType(-421);
116  d0.Append(d0b);
117 
118  d0.Select(fD0Sel);
119 
120  for (int j=0;j<d0.GetLength();++j)
121  {
122  RhoCandidate *dka = d0[j]->Daughter(0);
123  RhoCandidate *dpi = d0[j]->Daughter(1);
124 
127 
128  TLorentzVector d0cm = d0[j]->P4();
129  TLorentzVector kacm = dka->P4();
130  TLorentzVector picm = dpi->P4();
131  d0cm.Boost(-ini.BoostVector());
132  kacm.Boost(-ini.BoostVector());
133  picm.Boost(-ini.BoostVector());
134 
135  bool mct = theAnalysis->McTruthMatch(d0[j]);
136 
137  TVector3 vtx;
138  double qavtx = fVtxPoca.GetPocaVtx(vtx, d0[j]);
139 
140  nd0->Column("ev", (Float_t) i);
141  nd0->Column("cand", (Float_t) j);
142  nd0->Column("pdg", (Float_t) d0[j]->PdgCode());
143  nd0->Column("mct", (Float_t) mct);
144 
145  nd0->Column("d0m", (Float_t) d0[j]->M());
146  nd0->Column("d0p", (Float_t) d0[j]->P());
147  nd0->Column("d0tht", (Float_t) d0[j]->P3().Theta());
148  nd0->Column("d0phi", (Float_t) d0[j]->P3().Phi());
149  nd0->Column("d0pt", (Float_t) d0[j]->P3().Pt());
150  nd0->Column("d0pcm", (Float_t) d0cm.P());
151  nd0->Column("d0thtcm", (Float_t) d0cm.Theta());
152  nd0->Column("d0miss", (Float_t) (ini-(d0[j]->P4())).M());
153 
154  nd0->Column("d0vx", (Float_t) vtx.X());
155  nd0->Column("d0vy", (Float_t) vtx.Y());
156  nd0->Column("d0vz", (Float_t) vtx.Z());
157  nd0->Column("d0vqa", (Float_t) qavtx);
158 
159  nd0->Column("kch", (Float_t) dka->Charge());
160  nd0->Column("kp", (Float_t) dka->P());
161  nd0->Column("ktht", (Float_t) dka->P3().Theta());
162  nd0->Column("kphi", (Float_t) dka->P3().Phi());
163  nd0->Column("kpt", (Float_t) dka->P3().Pt());
164  nd0->Column("kpid", (Float_t) dka->GetPidInfo(3));
165  nd0->Column("kapcm", (Float_t) kacm.P());
166  nd0->Column("kathtcm", (Float_t) kacm.Theta());
167 
168  nd0->Column("pich", (Float_t) dpi->Charge());
169  nd0->Column("pip", (Float_t) dpi->P());
170  nd0->Column("pitht", (Float_t) dpi->P3().Theta());
171  nd0->Column("piphi", (Float_t) dpi->P3().Phi());
172  nd0->Column("pit", (Float_t) dpi->P3().Pt());
173  nd0->Column("pipid", (Float_t) dpi->GetPidInfo(2));
174  nd0->Column("pipcm", (Float_t) picm.P());
175  nd0->Column("pithtcm", (Float_t) picm.Theta());
176 
177  nd0->DumpData();
178  }
179 
180 
181  }
182 
183  // *** write out all the histos
184  out->cd();
185  nd0->GetInternalTree()->Write();
186  out->Save();
187  out->Close();
188 
189 }
190 
191 
192 
193 
194 
195 
196 
197 
198 
199 
200 
201 
202 
203 
Int_t GetEntries()
Double_t x0
Definition: checkhelixhit.C:70
void Append(const RhoCandidate *c)
Definition: RhoCandList.h:52
void tut_ana_d0(TString pref="pid_complete.root", int min=-1, int max=1, int nevts=0)
Definition: tut_ana_d0.C:33
Int_t i
Definition: run_full.C:25
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
Int_t GetLength() const
Definition: RhoCandList.h:46
Bool_t FillList(RhoCandList &l, TString listkey="All", TString pidTcaNames="", int trackHypothesis=-1)
PndPidCandidate * GetRecoCandidate() const
Definition: RhoCandidate.h:376
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:26
static const double mp
Definition: mzparameters.h:11
FairRunAna * fRun
Definition: hit_dirc.C:58
Double_t d0
Definition: checkhelixhit.C:59
void Combine(RhoCandList &l1, RhoCandList &l2)
void attachFiles(FairRunAna *fRun, TString pref, int min, int max)
Double_t GetPocaVtx(TVector3 &vertex, RhoCandidate *composite)
Definition: RhoVtxPoca.cxx:27
void Select(RhoParticleSelectorBase *pidmgr)
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
TLorentzVector P4() const
Definition: RhoCandidate.h:195
void Column(const char *label, Bool_t value, Bool_t defval=0, const char *block=0)
Definition: RhoTuple.cxx:56
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:25
void SetType(const TParticlePDG *pdt, int start=0)
TFile * out
Definition: reco_muo.C:20
Double_t P() const
void DumpData()
Definition: RhoTuple.cxx:391
bool checkfile(TString fn)
GeV c P
Double_t Charge() const
Definition: RhoCandidate.h:184
TTree * GetInternalTree()
Definition: RhoTuple.h:207
TTree * t
Definition: bump_analys.C:13
Bool_t McTruthMatch(RhoCandidate *cand, Int_t level=2, bool verbose=false)
Int_t GetEvent(Int_t n=-1)
PndMCTrack * mct
Definition: hist-t7.C:147
double GetPidInfo(int hypo)
TVector3 P3() const
Definition: RhoCandidate.h:199