FairRoot/PandaRoot
ana_invariantmass_2pi_tpc.C
Go to the documentation of this file.
1 class TCandList;
2 class TCandidate;
3 class TFitParams;
4 
5 int ana_invariantmass_2pi_tpc(int nEntries=0)
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.root";
17  TString inSimFile = "evt_points.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("ana_invariantmass_2pi_tpc.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  for (Int_t l=0;l<pp.GetLength();l++){
93  pp[l].SetMass(TRho::Instance()->GetPDG()->GetParticle(211)->Mass());
94  momentumpplus=pp[l].GetMicroCandidate().GetMomentum().Mag();
95  theta1=pp[l].GetMicroCandidate().GetMomentum().Theta()*TMath::RadToDeg();
96  phi1=pp[l].GetMicroCandidate().GetMomentum().Phi()*TMath::RadToDeg();
97 
98  }
99  for (Int_t l=0;l<pm.GetLength();l++){
100  pm[l].SetMass(TRho::Instance()->GetPDG()->GetParticle(211)->Mass());
101  momentumpminus=pm[l].GetMicroCandidate().GetMomentum().Mag();
102  theta2=pm[l].GetMicroCandidate().GetMomentum().Theta()*TMath::RadToDeg();
103  phi2=pm[l].GetMicroCandidate().GetMomentum().Phi()*TMath::RadToDeg();
104 
105 
106  }
107 
108 
109  pipinosel.Combine(pp,pm);
110 
111  for (y=0;y<pipinosel.GetLength();++y){
112  invmassnosel->Fill(pipinosel[y].M());
113  }
114 
115  pipi.Combine(pp,pm);
116  pipi.Select(pipisel); //Mass selector
117 
118  for (y=0;y<pipi.GetLength();++y){
119  invmassnocut->Fill(pipi[y].M());
120  if (momentumpplus>0.3 && momentumpminus >0.3){ //All the combination with momentum >0.3 GeV
121  invmass_trackhighmom->Fill(pipi[y].M());
122  }
123 
124  }
125 
126  //MonteCarlo PID
127  tree->GetEntry(i-1);
128 
129  TVector3 mcVertex;
130  evthead->GetVertex(mcVertex);
131 
132 // MC PID
133  // Leave only pions in particle lists
134  int n_removed=0;
135  int ii=0;
136  for (l=0;l<pp.GetLength();++l) {
137  ii=l-n_removed;
138  if (pp[ii].GetMicroCandidate().GetMcIndex()>-1){
139  PndMCTrack *mcTrack = (PndMCTrack*)mc_array->At(pp[ii].GetMicroCandidate().GetMcIndex());
140  if (mcTrack!=0)
141  {
142  if ((mcTrack->GetPdgCode()!=211) || (mcTrack->GetMotherID()!=-1))
143  {
144  pp.Remove(pp[ii]);
145  n_removed++;
146  }
147  }
148  else
149  {
150  std::cout<<"Pi plus, element "<<l<<" has no assosiated mcTRack"<<std::endl;
151  }
152  }
153  }
154 
155 
156  n_removed=0;
157  ii=0;
158  for (l=0;l<pm.GetLength();++l) {
159  ii=l-n_removed;
160  if (pm[ii].GetMicroCandidate().GetMcIndex()>-1){
161  PndMCTrack *mcTrack = (PndMCTrack*)mc_array->At(pm[ii].GetMicroCandidate().GetMcIndex());
162  if (mcTrack!=0)
163  {
164  if ((mcTrack->GetPdgCode()!=-211) || (mcTrack->GetMotherID()!=-1))
165  {
166  pm.Remove(pm[ii]);
167  n_removed++;
168  }
169  }
170  else
171  {
172  std::cout<<"Pi Minus, element "<<l<<" has no assosiated mcTRack"<<std::endl;
173  }
174  }
175  }
176 
177 
178 
179  pipiwithpid.Combine(pp,pm);
180  for (y=0;y<pipiwithpid.GetLength();++y){
181  invmasswithpid->Fill(pipiwithpid[y].M());
182  }
183 
184 
185  pipiwithpid.Combine(pp,pm);
186  pipiwithpid.Select(pipisel); //Mass selector
187  for (y=0;y<pipiwithpid.GetLength();++y){
188  invmasswithpid_sel->Fill(pipiwithpid[y].M());
189  }
190 
191  int best_i=0;
192  double best_chi2=1000;
193  TCandidate *pipifit_best=0;
194  Float_t pipivtx_mass;
195  TVector3 bestPos;
196  for (y=0;y<pipiwithpid.GetLength();++y){
197 
198  RhoKinVtxFitter vtxfitter(pipiwithpid[y]);
199  vtxfitter.Fit();
200  TCandidate *pipifit=vtxfitter.FittedCand(pipiwithpid[y]);
201 
202  TVector3 pipiVtx=pipifit->Pos();
203  double chi2_vtx=vtxfitter.GlobalChi2();
204 
205  hvpos->Fill(pipiVtx.X(),pipiVtx.Y());
206  hvzpos->Fill(pipiVtx.Z());
207 
208  if(chi2_vtx<best_chi2)
209  {
210  best_chi2=chi2_vtx;
211  best_i=y;
212  pipifit_best=pipifit;
213  pipivtx_mass=pipifit_best->M();
214  bestPos = pipifit->Pos();
215  }
216 
217  chivtx->Fill(chi2_vtx/1); // Number degree of freedom 2N-3=5; N=number of charged tracks
218 
219  }
220 
221  if((pipiwithpid.GetLength()!=0))
222  {
223  invmasschicut_best->Fill(pipivtx_mass);
224  n_reco++;
225  hvtxresX->Fill(mcVertex.X()-bestPos.X());
226  hvtxresY->Fill(mcVertex.Y()-bestPos.Y());
227  hvtxresZ->Fill(mcVertex.Z()-bestPos.Z());
228  }
229 
230  }
231 
232 
233 
234  out->cd();
235  out->Write();
236  out->Save();
237 
238  timer.Stop();
239 
240 
241  return 0;
242 }
243 
244 
TH1F * hvtxresX
Int_t i
Definition: run_full.C:25
TTree * tree
Definition: plot_dirc.C:12
TH1F * nc
Definition: plot_eta_c.C:38
Int_t GetPdgCode() const
Definition: PndMCTrack.h:73
TH2F * hvpos
Definition: plot_eta_c.C:47
TClonesArray * mc_array
Definition: anaLmdCluster.C:25
TString inFile
Definition: hit_dirc.C:8
int ana_invariantmass_2pi_tpc(int nEntries=0)
TString inSimFile
TStopwatch timer
Definition: hit_dirc.C:51
TH1F * hvzpos
Definition: plot_eta_c.C:45
TFile * out
Definition: reco_muo.C:20
TH1F * hvtxresZ
Double_t y
Int_t GetMotherID() const
Definition: PndMCTrack.h:74
TH1F * hvtxresY