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