FairRoot/PandaRoot
ana_dsdsj_full.C
Go to the documentation of this file.
1 
2 #include "TFile.h"
3 #include "TH1F.h"
4 #include "TH2F.h"
5 #include "TCanvas.h"
6 #include "TStopwatch.h"
7 #include "TROOT.h"
8 #include "TSystem.h"
9 #include "TTree.h"
10 #include "TString.h"
11 /*
12 #include "RhoSelector/TPidSelector.h"
13 #include "RhoBase/TCandList.h"
14 #include "RhoBase/TCandListIterator.h"
15 #include "RhoBase/TCandidate.h"
16 #include "RhoBase/TFactory.h"
17 */
18 
19 void config_histo(TH1 *h, TString tx, TString ty)
20 {
21  h->SetLineWidth(2);
22  //h->SetLineColor(1);
23  //h->SetFillColor(1);
24 
25  h->GetXaxis()->SetTitleOffset(1.2);
26  h->GetXaxis()->SetTitleColor(1);
27  h->GetXaxis()->SetLabelSize(0.05);
28  h->GetXaxis()->SetTitleSize(0.05);
29  h->GetXaxis()->SetNdivisions(505);
30 
31  h->GetYaxis()->SetTitleOffset(1.6);
32  h->GetYaxis()->SetTitleFont(42);
33  h->GetYaxis()->SetLabelSize(0.05);
34  h->GetYaxis()->SetTitleSize(0.05);
35  h->SetMinimum(0);
36 
37  h->SetFillStyle(1000);
38  h->SetFillColor(3);
39  h->SetLineWidth(1);
40 
41  h->SetXTitle(tx);
42  h->SetYTitle(ty);
43 
44 }
45 
46 void printCand(TLorentzVector l, TVector3 p)
47 {
48  cout <<"vtx("<<p.X()<<"/"<<p.Y()<<"/"<<p.Z()<<") p4("<<l.Px()<<"/"<<l.Py()<<"/"<<l.Pz()<<")="<<l.Vect().Mag()<<endl;
49 }
50 
51 void propagate(TLorentzVector &l, TVector3 &p, float charge, TH2F* hpro=0)
52 {
53  double x0=p.X()/100;
54  double y0=p.Y()/100;
55  double z0=p.Z()/100;
56 
57  double px0=l.Px();
58  double py0=l.Py();
59  double pz0=l.Pz();
60 
61  double B=2;
62 
63  double pt=sqrt(px0*px0+py0*py0);
64  double lambda=pz0/pt;
65  double s_t=z0/lambda;
66  double a=-0.2998*B*charge/3;
67  double rho=a/pt;
68 
69  //cout <<hpro<<endl;
70 
71  if (hpro)
72  {
73  int steps=100;
74  double dz=z0/steps;
75  for (int i=0;i<steps;i++)
76  {
77  if (i==90) i=99;
78  double s_tt=(i+1)*dz/lambda;
79  double cosrst=cos(rho*s_tt);
80  double sinrst=sin(rho*s_tt);
81 
82  double px = px0*cosrst + py0*sinrst;
83  double py = py0*cosrst - px0*sinrst;
84  //double pz = pz0;
85 
86  double xt=x0 - px/a*sinrst + py/a*(1-cosrst);
87  double yt=y0 - py/a*sinrst - px/a*(1-cosrst);
88  //double z=z0 - lambda*s_tt;
89 
90  hpro->Fill(xt,yt);
91  }
92  }
93 
94  //cout <<"lam="<<atan(1/lambda)/3.1416*180<<" "<<rho<<" "<<s_t<<endl;
95 
96  double cosrs=cos(rho*s_t);
97  double sinrs=sin(rho*s_t);
98 
99  double px = px0*cosrs + py0*sinrs;
100  double py = py0*cosrs - px0*sinrs;
101  double pz = pz0;
102 
103  double x=x0 - px/a*sinrs + py/a*(1-cosrs);
104  double y=y0 - py/a*sinrs - px/a*(1-cosrs);
105  double z=z0 - lambda*s_t;
106 
107  l.SetX(px);
108  l.SetY(py);
109  l.SetZ(pz);
110 
111  p.SetX(x*100);
112  p.SetY(y*100);
113  p.SetZ(z*100);
114 }
115 
116 int ana_dsdsj_full(TString fname="dsdsj.full.root",int num=10, int pr=1)
117 {
118  TStopwatch timer;
119  timer.Start();
120 
121  gROOT->LoadMacro("$VMCWORKDIR/gconfig/basiclibs.C");
122  basiclibs();
123 
124  // **** the library is needed in order to use the TCandidate and TCandList etc
125  gSystem->Load("libRho");
126 
127  TCanvas *c1=new TCanvas("c1","c1",1000,700);
128  c1->Divide(3,2);
129 
130  // **** access the datastructure holding the particle lists
131  //
132  TFile* f = new TFile(fname.Data());
133  TTree *t=(TTree*)f->Get("pndsim") ;
134 
135  // **** for every event, a TCLonesArray with the candidates is stored in pndsim
136  //
137  TClonesArray *fChrgCands=new TClonesArray("TCandidate");
138  TClonesArray *fNeutCands=new TClonesArray("TCandidate");
139  TClonesArray *fMcCands=new TClonesArray("TCandidate");
140 
141  t->SetBranchAddress("PndChargedCandidates",&fChrgCands);
142  t->SetBranchAddress("PndNeutralCandidates",&fNeutCands);
143  t->SetBranchAddress("PndMcTracks",&fMcCands);
144 
145  TCandidate *tc;
146 
147  // **** create and setup some histos for QA plots
148  //
149  TH1F *phimass = new TH1F("phimass","phi cands",100,0.98,1.1);
150  TH1F *pi0mass = new TH1F("pi0mass","pi0 cands",100,0.130-0.05,0.130+0.05);
151  TH1F *dsmass = new TH1F("dsmass","Ds cands",100,1.968-0.06,1.968+0.06);
152  TH1F *ds0mass = new TH1F("ds0mass","Ds0 cands",100,2.317-0.1,2.317+0.1);
153  TH1F *ppmass = new TH1F("ppmass","pbarp cands",100,4.291-0.1,4.291+0.1);
154  TH1F *pp2mass = new TH1F("pp2mass","sum m_{miss}+m_{Ds}",100,4.2855-0.02,4.2855+0.02);
155 
156  TH1F *nmult=new TH1F("nmult","# neutrals",15,0,15);
157 
158  TH1F *pdiff=new TH1F("pdiff","momentum difference",100,0,2);
159  TH2F *pdiff2=new TH2F("pdiff2","gamma corr",50,0,2.5,50,0,2.5);
160 
161  config_histo(phimass,"m(K^{+} K^{-}) [GeV/c^{2}]","entries");
162  config_histo(pi0mass,"m(#gamma#gamma) [GeV/c^{2}]","entries");
163  config_histo(dsmass,"m(#phi#pi^{#pm}) [GeV/c^{2}]","entries");
164  config_histo(ds0mass,"m(D_{s}#pi^{0}) [GeV/c^{2}]","entries");
165  config_histo(ppmass,"m(D_{s} D_{s0}*) [GeV/c^{2}]","entries");
166  config_histo(pp2mass,"m_{miss}+m_{D_{s}} [GeV/c^{2}]","entries");
167 
168  /*phimass->SetMinimum(0);
169  pi0mass->SetMinimum(0);
170  dsmass->SetMinimum(0);
171  ds0mass->SetMinimum(0);
172  ppmass->SetMinimum(0);
173  */
174  if (num==0) num= t->GetEntriesFast();
175  cout <<"\n####### Processing "<<num <<" events...\n"<<endl;
176 
177  // **** create all the particle lists we'll need for rebuilding the decay tree
178  //
179  TCandList mcCands;
180 
181  TCandList allCands,neutralCands,chargedCands,chargedCands2, plusCands,minusCands;
182 
183  TCandList kpCands,kmCands,piCands;
184 
185  TCandList phiCands,pi0Cands,dsCands,ds0Cands,ppCands;
186 
187  // **** create and configure the selectors/filters we'd like to use later
188  //
189  TPidChargedSelector *chargedSel = new TPidChargedSelector;
190  TPidNeutralSelector *neutralSel = new TPidNeutralSelector;
191  TPidPlusSelector *plusSel = new TPidPlusSelector;
192  TPidMinusSelector *minusSel = new TPidMinusSelector;
193 
194  // **** mass selectors for the resonances/composites
195  //
196  TPidMassSelector *phiMSel = new TPidMassSelector("phiSelector" , 1.0195 , 0.04);
197  TPidMassSelector *pi0MSel = new TPidMassSelector("pi0Selector" , 0.130 , 0.02);
198  TPidMassSelector *dsMSel = new TPidMassSelector("dsSelector" , 1.9685 , 0.02);
199 
200  TPidSimpleKaonSelector *kSel = new TPidSimpleKaonSelector();
201  kSel->SetCriterion("veryLoose");
202  TPidSimplePionSelector *piSel = new TPidSimplePionSelector();
203  piSel->SetCriterion("veryLoose");
204 
205  TH2F *hpro=new TH2F("hpro","",300,-1,1,300,-1,1);
206 
207 
208  int i1,i2;
209 
210  // **** loop over all _events_
211  //
212  for (Int_t j=0; j< num;j++)
213  {
214  if ((j%100)==0) cout <<"evt "<<j<<endl;
215 
216  if (pr) cout <<endl<<"************** evt "<<j<<endl;
217 
218  t->GetEntry(j);
219  TFactory::Instance()->Reset();
220 
221  mcCands.Cleanup();
222  chargedCands.Cleanup();
223  chargedCands2.Cleanup();
224  neutralCands.Cleanup();
225 
226  // **** loop over all Candidates and add them to the list allCands
227  //
228 
229  for (i1=0; i1<fChrgCands->GetEntriesFast(); i1++){
230  tc = (TCandidate *)fChrgCands->At(i1);
231 
232  TLorentzVector l=tc->P4();
233  TVector3 p=tc->Pos();
234 
235  if (pr!=0)
236  {
237  cout <<"1 --> ";
238  cout <<"c("<<tc->Charge()<<") vtx("<<p.X()<<"/"<<p.Y()<<"/"<<p.Z()<<") p4("<<l.Px()<<"/"<<l.Py()<<"/"<<l.Pz()<<")="<<l.Vect().Mag()<<endl;
239  //printCand(l,pos);
240  }
241 
242  chargedCands.Add(*tc);
243  //pdiff->Fill(p.Mag());
244  propagate(l,p,tc->GetCharge());
245 
246  //if (j=1 && i1==1)
247  //{
248  // propagate(l,p,tc->GetCharge(), hpro);
249  //}
250  //else
251  // propagate(l,p,tc->GetCharge());
252 
253 
254 
255  if (pr!=0)
256  {
257  cout <<"2 --> ";
258  cout <<"c("<<tc->Charge()<<") vtx("<<p.X()<<"/"<<p.Y()<<"/"<<p.Z()<<") p4("<<l.Px()<<"/"<<l.Py()<<"/"<<l.Pz()<<")="<<l.Vect().Mag()<<endl;
259  //printCand(l,pos);
260  cout <<endl;
261  }
262  tc->SetP4(l);
263  tc->SetPos(p);
264  //cout <<"2 -->"<<*tc<<endl;
265 
266  //pdiff->Fill(p.Mag());
267 
268  chargedCands2.Add(*tc);
269  }
270 
271  for (i1=0; i1<fNeutCands->GetEntriesFast(); i1++){
272  tc = (TCandidate *)fNeutCands->At(i1);
273 
274  double minang=10;
275 
276  for (i2=0;i2<chargedCands.GetLength();i2++)
277  {
278  TVector3 gam=tc->P3();
279  TVector3 chrg=chargedCands[i2].Pos();
280 
281  double ang=gam.Angle(chrg);
282 
283  //pdiff2->Fill(gam.Angle(chrg), tc->P4().E());
284  if (minang>ang) minang=ang;
285 
286  }
287  pdiff2->Fill(minang, tc->P4().E());
288  pdiff->Fill(tc->P4().E());
289  //tc->SetEnergy(tc->P4().E()*1.07);
290  if (minang>0.3)
291  neutralCands.Add(*tc);
292  }
293 
294  for (i1=0; i1<fMcCands->GetEntriesFast(); i1++){
295  tc = (TCandidate *)fMcCands->At(i1);
296  mcCands.Add(*tc);
297  }
298 
299 
300  // **** select all the basic list
301  //
302 
303  cout <<"c:"<<chargedCands.GetLength()<<" n:"<<neutralCands.GetLength()<<endl;
304 
305  nmult->Fill(neutralCands.GetLength());
306 
307  plusCands.Select(chargedCands2 ,plusSel);
308  minusCands.Select(chargedCands2 ,minusSel);
309 
310  // **** pid selection
311  //
312  kpCands.Select(plusCands ,kSel);
313  kmCands.Select(minusCands ,kSel);
314  piCands.Select(chargedCands2 ,piSel);
315 
316  cout <<"chrg:"<<chargedCands.GetLength()<<" ";
317  cout <<"plus:"<<plusCands.GetLength()<<" ";
318  cout <<"minus:"<<minusCands.GetLength()<<" ";
319  cout <<"K+:"<<kpCands.GetLength()<<" ";
320  cout <<"K-:"<<kmCands.GetLength()<<" ";
321  cout <<"pi+-:"<<piCands.GetLength()<<" ";
322  //cout <<"pi-:"<<piminusCands.GetLength()<<endl;
323 
324  // **** now start combining all composits; inbetween plot masses
325  // before using the mass selectors
326  //
327  phiCands.Combine(kpCands,kmCands);
328 
329  //phiCands.Select(phiMSel);
330  TCandListIterator iterPhi(phiCands);
331  while (tc=iterPhi.Next()) phimass->Fill(tc->M());
332  phiCands.Select(phiMSel);
333  cout <<"phi:"<<phiCands.GetLength()<<" "<<endl;
334  dsCands.Combine(phiCands,piCands);
335 
336  TCandListIterator iterDs(dsCands);
337  while (tc=iterDs.Next())
338  {
339  dsmass->Fill(tc->M());
340 
341  TLorentzVector lds=tc->P4();
342  TLorentzVector ini(0,0,8.824,9.812);
343 
344  TLorentzVector miss=ini-lds;
345  //ds0mass->Fill(miss.M());
346 
347  pp2mass->Fill(miss.M()+lds.M());
348 
349  }
350  dsCands.Select(dsMSel);
351 
352  pi0Cands.Combine(neutralCands,neutralCands);
353 
354  TCandListIterator iterPi0(pi0Cands);
355  while (tc=iterPi0.Next()) pi0mass->Fill(tc->M());
356  pi0Cands.Select(pi0MSel);
357 
358  ds0Cands.Combine(dsCands,pi0Cands);
359 
360  TCandListIterator iterDs0(ds0Cands);
361  while (tc=iterDs0.Next()) ds0mass->Fill(tc->M());
362 
363  ppCands.Combine(ds0Cands,dsCands);
364  //cout << ds0Cands.GetLength()<<" "<<dsCands.GetLength()<<" "<<ppCands.GetLength()<<endl;
365  //ppCands.Select(neutralSel);
366 
367  // **** since we didn't care about the D_s charge, combinations might appear in two
368  // different ways; RemoveClones removes double candidates based on the same final states
369  //ppCands.RemoveClones();
370 
371  TCandListIterator iterPp(ppCands);
372 
373  while (tc=iterPp.Next())
374  {
375  ppmass->Fill(tc->M());
376  //printTree(tc);
377  }
378 
379  TCandListIterator iterChrg(chargedCands);
380  while(tc=iterChrg.Next())
381  {
382  int idx=tc->GetMcIdx();
383  //if (idx!=-1) pdiff->Fill(tc->P()-mcCands[idx]->P());
384  }
385 
386 
387  }
388 
389  // **** plot all that stuff
390  //
391 
392  c1->cd(1);
393  phimass->Draw();
394  c1->cd(2);
395  pi0mass->Draw();
396  c1->cd(3);
397  dsmass->Draw();
398  c1->cd(4);
399  ds0mass->Draw();
400  c1->cd(5);
401  ppmass->Draw();
402  //pdiff->Draw();
403  c1->cd(6);
404  pp2mass->Draw();
405  //pdiff2->Draw("colz");
406  //hpro->Draw();
407 
408  c1->cd();
409 
410  //timer.Stop();
411  //Double_t rtime = timer.RealTime();
412  //Double_t ctime = timer.CpuTime();
413 
414  //printf("RealTime=%f seconds, CpuTime=%f seconds\n",rtime,ctime);
415  return 0;
416 
417 }
418 
419 /*void printTree(TCandidate *tc, int level=0)
420 {
421  int i=0;
422  int nd=tc->NDaughters();
423  if (nd==0) return;
424  cout <<tc->Uid()<<"("<<level<<") -> ";
425  for (i=0;i<nd;i++) cout<<tc->Daughter(i)->Uid()<<" ";
426  cout <<endl;
427  for (i=0;i<nd;i++) printTree(tc->Daughter(i),level+1);
428  if (level==0) cout <<endl;
429 }
430 */
Double_t z0
Definition: checkhelixhit.C:62
Double_t x0
Definition: checkhelixhit.C:70
friend F32vec4 cos(const F32vec4 &a)
Definition: P4_F32vec4.h:112
void propagate(TLorentzVector &l, TVector3 &p, float charge, TH2F *hpro=0)
basiclibs()
int num[96]
Definition: ranlxd.cxx:381
Int_t i
Definition: run_full.C:25
Double_t lambda(Double_t x, Double_t y, Double_t z)
Definition: drawdal.C:48
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
int ana_dsdsj_full(TString fname="dsdsj.full.root", int num=10, int pr=1)
friend F32vec4 sin(const F32vec4 &a)
Definition: P4_F32vec4.h:111
TClonesArray * fMcCands
Definition: poormantracks.C:26
Double_t p
Definition: anasim.C:58
TString pt(TString pts, TString exts="px py pz")
Definition: invexp.C:133
int idx[MAX]
Definition: autocutx.C:38
Int_t a
Definition: anaLmdDigi.C:126
void config_histo(TH1 *h, TString tx, TString ty)
Double_t y0
Definition: checkhelixhit.C:71
TStopwatch timer
Definition: hit_dirc.C:51
TFile * f
Definition: bump_analys.C:12
Double_t z
c1
Definition: plot_dirc.C:35
CandList gam
Double_t x
void printCand(TLorentzVector l, TVector3 p)
TTree * t
Definition: bump_analys.C:13
Double_t y
static int pr
Definition: ranlxd.cxx:374
double pz[39]
Definition: pipisigmas.h:14