FairRoot/PandaRoot
Functions
run_ana_invariantmass_2pi_stt.C File Reference

Go to the source code of this file.

Functions

int run_ana_invariantmass_2pi_stt (int nEntries=0)
 

Function Documentation

int run_ana_invariantmass_2pi_stt ( int  nEntries = 0)

Definition at line 5 of file run_ana_invariantmass_2pi_stt.C.

References RhoFitterBase::Fit(), PndMCTrack::GetMotherID(), PndMCTrack::GetPdgCode(), hvpos, hvtxresX, hvtxresY, hvtxresZ, hvzpos, i, inFile, inSimFile, Mass, mc_array, nc, out, timer, tree, TString, and y.

6 {
7 
8  gStyle->SetOptFit(1011);
9 
10  TStopwatch timer;
11  timer.Start();
12 
13  gROOT->Macro("$VMCWORKDIR/gconfig/rootlogon.C");
14 
15 
16  TString inPidFile = "evt_pid_stt.root";
17  TString inSimFile = "evt_points_stt.root";
18  TFile *inFile = TFile::Open(inSimFile,"READ");
19  TTree *tree=(TTree *) inFile->Get("pndsim") ;
20  tree->AddFriend("pndsim",inPidFile);
21  TClonesArray* mc_array=new TClonesArray("PndMCTrack");
22  tree->SetBranchAddress("MCTrack",&mc_array);
23 
24  TClonesArray* cand_array=new TClonesArray("PndPidCandidate");
25  tree->SetBranchAddress("PidChargedCand",&cand_array);
26 
27  FairMCEventHeader* evthead;
28  tree->SetBranchAddress("MCEventHeader.", &evthead);
29 
30  TFile *out=TFile::Open("invariantmass_2pi_stt.root","RECREATE");
31 
32  PndEventReader evr(inPidFile);
33 
34  //Define all histograms
35 int n_reco=0;
36 
37  TH1F *nc=new TH1F("nc","Number of Charged Tracks; Charged Tracks",20,-0.5,19.5);
38  TH1F *invmassnosel=new TH1F("invmassnosel","#pi^{+}#pi^{-} Invariant mass;Invariant Mass (GeV)",100,0,10);
39  TH1F *invmassnocut=new TH1F("invmassnocut","#pi^{+}#pi^{-} Invariant mass;Invariant Mass (GeV)",100,2,4);
40  TH1F *invmasswithpid=new TH1F("invmasswithpid","#pi^{+}#pi^{-} Invariant mass;Invariant Mass (GeV)",100,0,10);
41  TH1F *invmasswithpid_sel=new TH1F("invmasswithpid_sel","#pi^{+}#pi^{-} Invariant mass;Invariant Mass (GeV)",100,2,4);
42  // TH1F *invmassvtx=new TH1F("invmassvtx","#pi^{+}#pi^{-} Invariant mass;Invariant Mass (GeV)",100,2,4);
43  TH1F *invmass_trackhighmom= new TH1F("invmass_trackhighmom","#pi^{+}#pi^{-} Invariant mass;Invariant Mass (GeV)",100,2,4);
44 
45  TH1F *invmasschicut_best=new TH1F("invmasschicut_best","#pi^{+}#pi^{-} Invariant mass;Invariant Mass (GeV)",100,2,4);
46 
47  TH2F *hvpos = new TH2F("hvpos","(x,y) projection of fitted decay vertex",100,-5,5,100,-5,5);
48  TH1F *hvzpos = new TH1F("hvzpos","z position of fitted decay vertex",100,-4,4);
49 
50  TH1F *chivtx=new TH1F("chivtx","Chi Square RhoKinVtxFitter; Chi Square/N_{df}",100,0,8);
51 
52  TH1F *hvtxresX = new TH1F("hvtxresX","X resolution of fitted decay vertex",100,-0.3,0.3);
53  TH1F *hvtxresY = new TH1F("hvtxresY","Y resolution of fitted decay vertex",100,-0.3,0.3);
54  TH1F *hvtxresZ = new TH1F("hvtxresZ","Z resolution of fitted decay vertex",100,-0.3,0.3);
55 
56  TPidPlusSelector *piplusSel=new TPidPlusSelector("piplus");
57  TPidMinusSelector *piminusSel=new TPidMinusSelector("piminus");
58 
59  TCandList pp, pm, pipi,pipinosel, pipiwithpid;
60 
61 
62  TLorentzVector ini(0,0,4.0,5.04684);
63  int i=0,j=0,k=0,l=0,y=0;
64 
65  TLorentzVector beam;
66  beam.SetXYZM (0.0,0.0,4.0,0.938272);
67  TLorentzVector target;
68  target.SetXYZM (0.0,0.0,0.0,0.938272);
69  TLorentzVector pbarp=beam+target;
70 
71 
72  float energypip, energypim, momxpip, momypip, momzpip;
73  TPidMassSelector *pipisel=new TPidMassSelector("pipisel",3.07,1.0); //energy in the center of mass 3.07 GeV
74 
75  TPidPlusSelector *piplusSel=new TPidPlusSelector("piplus");
76  TPidMinusSelector *piminusSel=new TPidMinusSelector("piminus");
77 
78  if (nEntries==0) nEntries=evr.GetEntries();
79  while (evr.GetEvent() && i++<nEntries){
80 
81  if (!((i+1)%100)) cout<<"evt " << i << "\n";
82 
83  evr.FillList(pp,"Charged");
84  evr.FillList(pm,"Charged");
85  pp.Select(piplusSel);
86  pm.Select(piminusSel);
87 
88  int nchrg=pp.GetLength();
89  nc->Fill(nchrg);
90  float momentumpplus, momentumpminus, theta1, theta2, phi1, phi2;
91 
92  int n_removed=0;
93  int ii=0;
94  for (Int_t l=0;l<pp.GetLength();l++){
95  ii=l-n_removed;
96  if((pp[ii].GetMicroCandidate()->GetSttHits())==0){
97  pp.Remove(pp[ii]);
98  n_removed++;
99  }
100  }
101 
102  int n_removed=0;
103  int ii=0;
104  for (Int_t l=0;l<pm.GetLength();l++){
105  ii=l-n_removed;
106  if((pm[ii].GetMicroCandidate()->GetSttHits())==0){
107  pm.Remove(pm[ii]);
108  n_removed++;
109  }
110  }
111 
112  for (Int_t l=0;l<pp.GetLength();l++){
113  pp[l].SetMass(TRho::Instance()->GetPDG()->GetParticle(211)->Mass());
114  momentumpplus=pp[l].GetMicroCandidate().GetMomentum().Mag();
115  theta1=pp[l].GetMicroCandidate().GetMomentum().Theta()*TMath::RadToDeg();
116  phi1=pp[l].GetMicroCandidate().GetMomentum().Phi()*TMath::RadToDeg();
117  }
118 
119 
120 
121 
122 
123  for (Int_t l=0;l<pm.GetLength();l++){
124  if((pm[l].GetMicroCandidate()->GetSttHits())>0){
125  pm[l].SetMass(TRho::Instance()->GetPDG()->GetParticle(211)->Mass());
126  momentumpminus=pm[l].GetMicroCandidate().GetMomentum().Mag();
127  theta2=pm[l].GetMicroCandidate().GetMomentum().Theta()*TMath::RadToDeg();
128  phi2=pm[l].GetMicroCandidate().GetMomentum().Phi()*TMath::RadToDeg();
129  }
130 
131  }
132 
133 
134  pipinosel.Combine(pp,pm);
135 
136  for (y=0;y<pipinosel.GetLength();++y){
137  invmassnosel->Fill(pipinosel[y].M());
138  }
139 
140  pipi.Combine(pp,pm);
141  pipi.Select(pipisel); //Mass selector
142 
143  for (y=0;y<pipi.GetLength();++y){
144  invmassnocut->Fill(pipi[y].M());
145  if (momentumpplus>0.3 && momentumpminus >0.3){ //All the combination with momentum >0.3 GeV
146  invmass_trackhighmom->Fill(pipi[y].M());
147  }
148 
149  }
150 
151  //MonteCarlo PID
152  tree->GetEntry(i-1);
153 
154  TVector3 mcVertex;
155  evthead->GetVertex(mcVertex);
156 
157 // MC PID
158  // Leave only pions in particle lists
159  int n_removed=0;
160  int ii=0;
161  for (l=0;l<pp.GetLength();++l) {
162  ii=l-n_removed;
163  if (pp[ii].GetMicroCandidate().GetMcIndex()>-1){
164  PndMCTrack *mcTrack = (PndMCTrack*)mc_array->At(pp[ii].GetMicroCandidate().GetMcIndex());
165  if (mcTrack!=0)
166  {
167  if ((mcTrack->GetPdgCode()!=211) || (mcTrack->GetMotherID()!=-1))
168  {
169  pp.Remove(pp[ii]);
170  n_removed++;
171  }
172  }
173  else
174  {
175  std::cout<<"Pi plus, element "<<l<<" has no assosiated mcTRack"<<std::endl;
176  }
177  }
178  }
179 
180 
181  n_removed=0;
182  ii=0;
183  for (l=0;l<pm.GetLength();++l) {
184  ii=l-n_removed;
185  if (pm[ii].GetMicroCandidate().GetMcIndex()>-1){
186  PndMCTrack *mcTrack = (PndMCTrack*)mc_array->At(pm[ii].GetMicroCandidate().GetMcIndex());
187  if (mcTrack!=0)
188  {
189  if ((mcTrack->GetPdgCode()!=-211) || (mcTrack->GetMotherID()!=-1))
190  {
191  pm.Remove(pm[ii]);
192  n_removed++;
193  }
194  }
195  else
196  {
197  std::cout<<"Pi Minus, element "<<l<<" has no assosiated mcTRack"<<std::endl;
198  }
199  }
200  }
201 
202 
203 
204  pipiwithpid.Combine(pp,pm);
205  for (y=0;y<pipiwithpid.GetLength();++y){
206  invmasswithpid->Fill(pipiwithpid[y].M());
207  }
208 
209 
210  pipiwithpid.Combine(pp,pm);
211  pipiwithpid.Select(pipisel); //Mass selector
212  for (y=0;y<pipiwithpid.GetLength();++y){
213  invmasswithpid_sel->Fill(pipiwithpid[y].M());
214  }
215 
216  int best_i=0;
217  double best_chi2=1000;
218  TCandidate *pipifit_best=0;
219  Float_t pipivtx_mass;
220  TVector3 bestPos;
221  for (y=0;y<pipiwithpid.GetLength();++y){
222 
223  RhoKinVtxFitter vtxfitter(pipiwithpid[y]);
224  vtxfitter.Fit();
225  TCandidate *pipifit=vtxfitter.FittedCand(pipiwithpid[y]);
226 
227  TVector3 pipiVtx=pipifit->Pos();
228  double chi2_vtx=vtxfitter.GlobalChi2();
229 
230  hvpos->Fill(pipiVtx.X(),pipiVtx.Y());
231  hvzpos->Fill(pipiVtx.Z());
232 
233  if(chi2_vtx<best_chi2)
234  {
235  best_chi2=chi2_vtx;
236  best_i=y;
237  pipifit_best=pipifit;
238  pipivtx_mass=pipifit_best->M();
239  bestPos = pipifit->Pos();
240  }
241 
242  chivtx->Fill(chi2_vtx/1); // Number degree of freedom 2N-3=5; N=number of charged tracks
243 
244  }
245 
246  if((pipiwithpid.GetLength())!=0)
247  {
248  invmasschicut_best->Fill(pipivtx_mass);
249  n_reco++;
250  hvtxresX->Fill(mcVertex.X()-bestPos.X());
251  hvtxresY->Fill(mcVertex.Y()-bestPos.Y());
252  hvtxresZ->Fill(mcVertex.Z()-bestPos.Z());
253  }
254 
255  }
256 
257 
258 
259  out->cd();
260  out->Write();
261  out->Save();
262 
263  timer.Stop();
264 
265 
266  return 0;
267 }
TH1F * hvtxresX
Int_t i
Definition: run_full.C:25
TTree * tree
Definition: plot_dirc.C:12
Int_t GetPdgCode() const
Definition: PndMCTrack.h:73
TH1F * hvzpos
TClonesArray * mc_array
Definition: anaLmdCluster.C:25
TString inFile
Definition: hit_dirc.C:8
TString inSimFile
TStopwatch timer
Definition: hit_dirc.C:51
TFile * out
Definition: reco_muo.C:20
TH1F * hvtxresZ
Double_t y
Int_t GetMotherID() const
Definition: PndMCTrack.h:74
TH1F * hvtxresY
TH2F * hvpos
TH1F * nc