FairRoot/PandaRoot
newana_check_eta.C
Go to the documentation of this file.
1 class TCandList;
2 class TCandidate;
3 class TFitParams;
4 
5 int newana_check_eta(int nevts=0)
6 {
7  TString OutFile="output.root";
8  TString inPidFile = "evt_pid_stt.root";
9  TString inRecoFile = "evt_reco_stt.root";
10  TString inSimFile = "evt_points_stt.root";
11  TString inParFile = "evt_params_stt.root";
12 
13  gStyle->SetOptFit(1011);
14  gROOT->Macro("$VMCWORKDIR/gconfig/rootlogon.C");
15 
16  FairLogger::GetLogger()->SetLogToFile(kFALSE);
17  //FairLogger::GetLogger()->SetLogScreenLevel("DEBUG4");
18  //FairLogger::GetLogger()->SetLogVerbosityLevel("MEDIUM");
19 
20  FairRunAna* fRun = new FairRunAna();
21  FairRuntimeDb* rtdb = fRun->GetRuntimeDb();
22  fRun->SetInputFile(inSimFile);
23  fRun->AddFriend(inPidFile);
24  fRun->AddFriend(inRecoFile);
25 
26  FairParRootFileIo* parIO = new FairParRootFileIo();
27  parIO->open(inParFile);
28  rtdb->setFirstInput(parIO);
29  rtdb->setOutput(parIO);
30 
31  fRun->SetOutputFile(OutFile);
32  fRun->Init();
33 
34  TFile *out = TFile::Open("output_newmc.root","RECREATE");
35 
36 
37  TH1F *h_etac_nocut=new TH1F("h_etac_nocut","m(eta_c), (no cuts);E, GeV",100,2.5,3.5);
38  TH1F *h_mphi_nocuts=new TH1F("h_mphi_nocuts","#phi: m(K+ K-) (no cuts)",100,0.95,1.1);
39 
40  TH1F *h_etac_pid=new TH1F("h_etac_pid","m(eta_c), (MC PID);E, GeV",100,2.5,3.5);
41  TH1F *h_mphi_pid=new TH1F("h_mphi_pid","#phi: m(K+ K-) (MC PID)",100,0.95,1.1);
42 
43  TH1F *h_etac_4c=new TH1F("h_etac_4c","m(eta_c), 4C-fit",100,2.5,3.5);
44  TH1F *h_mphi_4c=new TH1F("h_mphi_4c","#phi: m(K+ K-) (4C-fit)",100,0.95,1.1);
45 
46  TH1F *h_etac_vtx=new TH1F("h_etac_vtx","m(eta_c), Vertex fit",100,2.5,3.5);
47  TH1F *h_mphi_vtx=new TH1F("h_mphi_vtx","#phi: m(K+ K-) (Vertex fit)",100,0.95,1.1);
48 
49  TH1F *h_etac_phimass=new TH1F("h_etac_phimass","m(eta_c), (cut on #phi mass);E, GeV",100,2.5,3.5);
50  TH1F *h_mphi_final=new TH1F("h_mphi_final","#phi: m(K+ K-)",100,0.95,1.1);
51 
52  TH1F *nc=new TH1F("nc","n charged",20,0,20);
53 
54  TH1F *h_chi2_4c=new TH1F("h_chi2_4c","#chi^{2} 4C-fit;#chi^{2}/N_{df}",100,0,100);
55  TH1F *h_chi2b_4c=new TH1F("h_chi2b_4c","#chi^{2} 4C-fit;#chi^{2}/N_{df}",100,0,100);
56  TH1F *h_chi2_vtx=new TH1F("h_chi2_vtx","#chi^{2} vertex;#chi^{2}/N_{df}",100,0,100);
57  TH2F *hvpos = new TH2F("hvpos","(x,y) projection of fitted decay vertex",100,-5,5,100,-5,5);
58  TH1F *hvzpos = new TH1F("hvzpos","z position of fitted decay vertex",100,-10,10);
59  TH1F *hvtxresX = new TH1F("hvtxresX","X resolution of fitted decay vertex",100,-0.1,0.1);
60  TH1F *hvtxresY = new TH1F("hvtxresY","Y resolution of fitted decay vertex",100,-0.1,0.1);
61  TH1F *hvtxresZ = new TH1F("hvtxresZ","Z resolution of fitted decay vertex",100,-0.1,0.1);
62 
63  TPidMassSelector *phiMassSel=new TPidMassSelector("phi",1.02,0.02);
64 
65  // the candidates lists we need
66  TCandList p1, p2, phi1, phi1_pid, etac, etac_pid, etac_nocut, mctracks;
67 
68  int n_reco=0;
69  // Number of events in file and number of reconstructed eta_c to store in root file
70  TH1F *n_events=new TH1F("n_events","total number of events",1,0,1);
71  TH1F *n_etac=new TH1F("n_etac","number of reconstructed eta_c",1,0,1);
72 
73  TLorentzVector ini(0,0,3.6772,4.7333);
74 
75  PndAnalysis* theAnalysis = new PndAnalysis();
76  if (nevts==0) nevts= theAnalysis->GetEntries();
77  n_events->SetBinContent(1,nevts);
78  // cout << "nevts " << nevts << "\n";
79  int i=0,j=0, k=0, l=0;
80 
81  // *************
82  // this is the loop through the events ... as simple as this...
83  // ****************
84  while (theAnalysis->GetEvent() && i++<nevts)
85  {
86  // cout << "evt: " << i << endl;
87 
88  if ((i%100)==0) cout<<"evt " << i << endl;
89  //if (!((i+1)%100)) cout<<"evt " << i << "\n";
90 
91  theAnalysis->FillList(mctracks,"McTruth");
92  theAnalysis->FillList(p1,"KaonVeryLoosePlus");
93  theAnalysis->FillList(p2,"KaonVeryLooseMinus");
94 
95  int nchrg=p1.GetLength()+p2.GetLength();
96  nc->Fill(nchrg);
97 
98  phi1.Combine(p1,p2);
99  for (j=0;j<phi1.GetLength();++j) h_mphi_nocuts->Fill(phi1[j].M());
100 
101  phi1.Select(phiMassSel);
102  etac_nocut.Combine(phi1,phi1);
103 
104  for (l=0;l<etac_nocut.GetLength();++l) {
105  h_etac_nocut->Fill(etac_nocut[l].M());
106  }
107 
108  FairMCEventHeader* evthead = theAnalysis->GetEventHeader();
109  TVector3 mcVertex, mcD1Vertex, mcD2vertex;
110  evthead->GetVertex(mcVertex);
111 
112  //MC PID
113  // Leave only kaons in particle lists
114  int n_removed=0;
115  int ii=0;
116  for (l=0;l<p1.GetLength();++l) {
117  ii=l-n_removed;
118  Int_t mcIndex = p1[ii].GetMicroCandidate().GetMcIndex();
119  if (mcIndex>-1){
120  if ((mctracks[mcIndex].PdgCode()!=321))// || (mctracks[mcIndex].GetMotherID()!=-1))
121  {
122  p1.Remove(p1[ii]);
123  n_removed++;
124  }
125  if (mcIndex==0) mcD1Vertex = mctracks[mcIndex].Pos();
126  if (mcIndex==2) mcD1Vertex = mctracks[mcIndex].Pos();
127  }
128  else
129  {
130  std::cout<<"stt h: " << p1[ii].GetMicroCandidate().GetSttHits() << std::endl;
131  std::cout<<"Kaon list 1, element "<<l<<" has no assosiated mcTRack"<<std::endl;
132  }
133  }
134 
135  n_removed = 0;
136  ii = 0;
137  for (l=0;l<p2.GetLength();++l) {
138  ii=l-n_removed;
139  Int_t mcIndex = p2[ii].GetMicroCandidate().GetMcIndex();
140  if (mcIndex>-1){
141  if ((mctracks[mcIndex].PdgCode()!=-321))// || (mctracks[mcIndex].GetMotherID()!=-1))
142  {
143  p2.Remove(p2[ii]);
144  n_removed++;
145  }
146  if (mcIndex==1) mcD1Vertex = mctracks[mcIndex].Pos();
147  if (mcIndex==3) mcD1Vertex = mctracks[mcIndex].Pos();
148  }
149  else
150  {
151  std::cout<<"stt h: " << p2[ii].GetMicroCandidate().GetSttHits() << std::endl;
152  std::cout<<"Kaon list 2, element "<<l<<" has no assosiated mcTRack"<<std::endl;
153  }
154  }
155 
156  phi1_pid.Combine(p1,p2);
157 
158  for (j=0;j<phi1_pid.GetLength();++j) h_mphi_pid->Fill(phi1_pid[j].M());
159  phi1_pid.Select(phiMassSel);
160  etac.Combine(phi1_pid,phi1_pid);
161 
162  for (l=0;l<etac.GetLength();++l) {
163  h_etac_pid->Fill(etac[l].M());
164  }
165  //cout << " ";// << endl;
166  //if (use4cfit)
167  {
169  int best_i=0;
170  double best_chi2=1000;
171  TCandidate *ccfit;// = new TCandidate();
172  double m_phi1, m_phi2;
173  for (l=0;l<etac.GetLength();++l) {
174  Rho4CFitter fitter(etac[l],ini);
175  fitter.FitConserveMasses();
176  double chi2=fitter.GetChi2();
177  if (chi2<best_chi2)
178  {
179  best_chi2=chi2;
180  best_i = l;
181  ccfit = (TCandidate*)fitter.FittedCand(etac[l]);
182  TCandidate *phi1best = fitter.FittedCand(*(etac[l].Daughter(0)));
183  TCandidate *phi2best = fitter.FittedCand(*(etac[l].Daughter(1)));
184  TCandidate *k1best = fitter.FittedCand(*(etac[l].Daughter(0)->Daughter(0)));
185  TCandidate *k2best = fitter.FittedCand(*(etac[l].Daughter(0)->Daughter(1)));
186  TCandidate *k3best = fitter.FittedCand(*(etac[l].Daughter(1)->Daughter(0)));
187  TCandidate *k4best = fitter.FittedCand(*(etac[l].Daughter(1)->Daughter(1)));
188  TLorentzVector tlvk1 = k1best->P4();
189  TLorentzVector tlvk2 = k2best->P4();
190  TLorentzVector tlvk3 = k3best->P4();
191  TLorentzVector tlvk4 = k4best->P4();
192  m_phi1= (tlvk1+tlvk2).M();
193  m_phi2= (tlvk3+tlvk4).M();
194  }
195  h_chi2_4c->Fill(chi2/9); // Ndf=3N-3=9
196  }
197 
198  if (etac.GetLength()!=0) cout << "evt: " << i << "\tbest: " << best_chi2 << "\tlen " << etac.GetLength() << endl;
199 
200  if(/*(best_chi2<270)&&*/(etac.GetLength()!=0))
201  {
202  h_chi2b_4c->Fill(best_chi2/9); // Ndf=3N-3=9
203  h_etac_4c->Fill(ccfit->M());
204  h_mphi_4c->Fill(m_phi1);
205  h_mphi_4c->Fill(m_phi2);
206  h_mphi_final->Fill(m_phi1);
207  h_mphi_final->Fill(m_phi2);
208  if (((m_phi1>1.02-0.02)&&(m_phi1<1.02+0.02))&&((m_phi2>1.02-0.02)&&(m_phi2<1.02+0.02)))
209  {
210  h_etac_phimass->Fill(etac[best_i].M());
211  if ((etac[best_i].M()>2.9)&&(etac[best_i].M()<3.06))
212  n_reco++;
213  }
214  }
215  }
216  // else // use vertex fit
217  {
218  TCandList etac_vtx;
219  TCandidate *k1, *k2, *k3, *k4, *phi1tmp, *phi2tmp, *etac_tmp;
220 
221  //Combine 4 kaons directly to candidates
222  for (j=0;j<etac.GetLength();++j)
223  {
224  phi1tmp=etac[j].Daughter(0);
225  phi2tmp=etac[j].Daughter(1);
226 
227  k1=phi1tmp->Daughter(0);
228  k2=phi1tmp->Daughter(1);
229  k3=phi2tmp->Daughter(0);
230  k4=phi2tmp->Daughter(1);
231 
232  etac_tmp=k1->Combine(*k2,*k3,*k4);
233  etac_vtx.Add(*etac_tmp);
234  }
235 
236  for (l=0;l<etac.GetLength();++l) {
237  h_etac_pid->Fill(etac_vtx[l].M());
238  }
239 
241  int best_i=0;
242  double best_chi2=1000;
243  TCandidate *etacfit_best=0;
244  TCandidate *k1fit_best, *k2fit_best, *k3fit_best, *k4fit_best;
245  TCandidate *phi1fit_best, *phi2fit_best;
246  TVector3 bestPos;
247  Float_t etacvtx_mass;
248  for (j=0;j<etac_vtx.GetLength();++j)
249  {
250  RhoKinVtxFitter vtxfitter(etac_vtx[j]); // instantiate a vertex fitter
251  vtxfitter.AddMassConstraint(ini.M());
252  vtxfitter.Fit(); // do the vertex fit
253 
254  TCandidate *etacfit=vtxfitter.FittedCand(etac_vtx[j]); // request the fitted EtaC candidate
255  TVector3 etacVtx=etacfit->Pos(); // and the decay vertex position
256  double chi2_vtx=vtxfitter.GlobalChi2();
257  h_chi2_vtx->Fill(chi2_vtx/5); // Number degree of freedom 2N-3=5
258  // plot mass and vtx x,y projection after fit
259  hvpos->Fill(etacVtx.X(),etacVtx.Y());
260  hvzpos->Fill(etacVtx.Z());
261  if(chi2_vtx<best_chi2)
262  {
263  best_chi2=chi2;
264  best_i=l;
265  etacfit_best=etacfit;
266  k1fit_best=vtxfitter.FittedCand(*(etacfit_best->Daughter(0)));
267  k2fit_best=vtxfitter.FittedCand(*(etacfit_best->Daughter(1)));
268  k3fit_best=vtxfitter.FittedCand(*(etacfit_best->Daughter(2)));
269  k4fit_best=vtxfitter.FittedCand(*(etacfit_best->Daughter(3)));
270  etacvtx_mass = etacfit_best->M();
271  bestPos = etacfit->Pos();
272  }
273 
274  }
275  if(/*(best_chi2<150)&&*/(etac.GetLength()!=0))
276  {
277  //h_etac_vtx->Fill(etacfit_best->M());
278  h_etac_vtx->Fill(etacvtx_mass);
279  phi1fit_best=k1fit_best->Combine(*k2fit_best);
280  phi2fit_best=k3fit_best->Combine(*k4fit_best);
281  double m_phi1=phi1fit_best->M();
282  double m_phi2=phi2fit_best->M();
283  h_mphi_vtx->Fill(m_phi1);
284  h_mphi_vtx->Fill(m_phi2);
285  h_mphi_final->Fill(m_phi1);
286  h_mphi_final->Fill(m_phi2);
287  hvtxresX->Fill(mcVertex.X()-bestPos.X());
288  hvtxresY->Fill(mcVertex.Y()-bestPos.Y());
289  hvtxresZ->Fill(mcVertex.Z()-bestPos.Z());
290 
291  if (((m_phi1>1.02-0.03)&&(m_phi1<1.02+0.03))&&((m_phi2>1.02-0.03)&&(m_phi2<1.02+0.03)))
292  {
293  h_etac_phimass->Fill(etacvtx_mass);
294  if ((etacvtx_mass>2.9)&&(etacvtx_mass<3.06))
295  n_reco++;
296  }
297  }
298 
299  }
300  }
301  std::cout<<"Number of reconstructed eta_c = "<<n_reco<<std::endl;
302  n_etac->SetBinContent(1,n_reco);
303 
304 
305  out->cd();
306  n_etac->Write();
307  n_events->Write();
308  h_etac_nocut->Write();
309  h_etac_pid->Write();
310  h_etac_phimass->Write();
311  h_etac_vtx->Write();
312  h_etac_4c->Write();
313 
314  h_mphi_nocuts->Write();
315  h_mphi_pid->Write();
316  h_mphi_vtx->Write();
317  h_mphi_4c->Write();
318  h_mphi_final->Write();
319 
320  nc->Write();
321 
322  h_chi2_4c->Write();
323  h_chi2_vtx->Write();
324  hvzpos->Write();
325  hvpos->Write();
326  hvtxresX->Write();
327  hvtxresY->Write();
328  hvtxresZ->Write();
329  out->Save();
330 
331  return 0;
332 }
Int_t GetEntries()
TH1F * h_chi2_vtx
TH1F * h_etac_nocut
Definition: plot_eta_c_stt.C:7
TH1F * hvtxresX
Int_t i
Definition: run_full.C:25
FairMCEventHeader * GetEventHeader()
TH1F * h_etac_4c
TString inRecoFile
Bool_t FitConserveMasses()
Definition: Rho4CFitter.cxx:64
TH1F * hvzpos
Bool_t FillList(RhoCandList &l, TString listkey="All", TString pidTcaNames="", int trackHypothesis=-1)
TH1F * h_mphi_nocuts
TH1F * h_mphi_4c
FairRunAna * fRun
Definition: hit_dirc.C:58
TH1F * h_etac_vtx
Definition: plot_eta_c_stt.C:9
TString inSimFile
TH1F * h_chi2b_4c
TH1F * h_chi2_4c
TH1F * h_mphi_vtx
int newana_check_eta(int nevts=0)
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
void AddMassConstraint(double mass)
TFile * out
Definition: reco_muo.C:20
TH1F * n_events
TH1F * h_etac_pid
Definition: plot_eta_c_stt.C:8
TPad * p2
Definition: hist-t7.C:117
TH1F * hvtxresZ
TPad * p1
Definition: hist-t7.C:116
double GetChi2() const
Definition: RhoFitterBase.h:48
Int_t GetEvent(Int_t n=-1)
TH1F * h_mphi_pid
TH1F * hvtxresY
TH2F * hvpos
TH1F * nc