StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
scan_embed_mc.C
1 //Original Version done by Cristina May 2007
2 //Modification extra histograms by Xianglei
3 //Extra 3D Histograms Dca : ETA: pt and Nfit: Eta: pt are being added
4 
5 #ifndef __CINT__
6 #include "TROOT.h"
7 #include "TSystem.h"
8 #include <iostream.h>
9 #include "TH1.h"
10 #include "TH2.h"
11 #include "TH3.h"
12 #include "TFile.h"
13 #include "TTree.h"
14 #include "TChain.h"
15 #include "TTreeHelper.h"
16 #endif
17 
18 void scan_embed_mc(
19  const Int_t id = 8,
20 
21  const TString inputMiniMc ="/eliza3/starprod/embedding/P08id/dAu/*/*/*.minimc.root", //test
22 
23  const Char_t* particle= "Phi",
24  const Char_t* production = "P08id",
25  const Int_t eid = 90117,
26  const Char_t* date = "040709",
27 
28  )
29 {
30  gSystem->Load("StarRoot");
31 
32  // -------------------- A n a l y s i s C u t s ---------------------------------
33 
34  const float VZCut = 30.; // Cut for Z Vertex
35  const float yCut = 1; // Cut for pseudoRapidity. we do not need this cuts for MC tracks and matched tracks
36  const float NFitCut = 25.; //Cut for Number of Fit Points
37  const int NCommCut = 10; // Cut for Number of common hits
38 
39  //------------------Ranges of the histograms ---------------------------------------
40 
41  const int nchNch = 200; const float maxNch = 1000;
42  const int nchPt = 80; const float maxPt = 8.0;
43  const int nchNhits = 50; const float minNhits = 0.; const float maxNhits = 50.;
44  const int nchDca = 100; const float maxDca = 3.;
45  const float maxDedx = 20.;
46  const float NSigmaCut = 2.0;
47  float mass2 = -1.0;
48 
49  if (id == 2) { TString tag = "Eplus"; mass2 = 0.511; Char_t *Daugther = "Eplus";}
50  if (id == 8) { TString tag = "PiPlus"; mass2 = 0.019; Char_t *Daugther = "PiPlus";}
51  if (id == 9) { TString tag = "PiMinus"; mass2 = 0.019; Char_t *Daugther = "PiMius";}
52  if (id == 11) { TString tag = "KPlus"; mass2 = 0.245; Char_t *Daugther = "KPlus";}
53  if (id == 12) { TString tag = "KMinus"; mass2 = 0.245; Char_t *Daugther = "KMinus";}
54  if (id == 14) { TString tag = "Proton"; mass2 = 0.880; Char_t *Daugther = "Proton";}
55  if (id == 15) { TString tag = "Pbar"; mass2 = 0.880; Char_t *Daugther = "Pbar";}
56  if (id == 50) { TString tag = "Phi"; mass2 = 1.020; }
57 
58 
59  if( mass2 < 0 ) {
60  cout << "Negative mass2 for pid = " << id << endl;
61  return;
62  }
63 
64  //-------------------------MC---------------------------------
65 
66  TString filePathMc(inputMiniMc);
67 
68  cout << endl;
69  cout << endl;
70  cout << "Input MiniMc file : " << filePathMc.Data() <<endl;
71  cout << "#---------------------------------------------------------------------------" << endl;
72  cout << " Event selection" << endl;
73  cout << " |VZ| < " << VZCut << endl;
74  cout << "#---------------------------------------------------------------------------" << endl;
75  cout << " Track selection (mMatchedPairs)" << endl;
76  cout << " For DCA : mMatchedPairs.mFitPts >= " << NFitCut << " && mMatchedPairs.mNCommonHit > " << NCommCut << endl;
77  cout << " For NFit : mMatchedPairs.mDcaGl < " << maxDca << " && mMatchedPairs.mFitPts/mMatchedPairs.mNCommonHit < 2.5 && mMatchedPairs.mFitPts >= 10" << endl;
78  cout << " For dE/dx : mMatchedPairs.mDcaGl < " << maxDca << " && mMatchedPairs.mFitPts >= " << NFitCut << " && |mMatchedPairs.mEtaPr| < " << yCut << endl;
79  cout << " For pt, eta, phi : |mMatchedPairs.mDcaGl| < " << maxDca << endl;
80  cout << "#---------------------------------------------------------------------------" << endl;
81  cout << " Track selection (mGhostPairs)" << endl;
82  cout << " For dE/dx : mGhostPairs.mDcaGl < " << maxDca << " && mGhostPairs.mFitPts >= " << NFitCut << " && |mGhostPairs.mEtaPr| < " << yCut << endl;
83  cout << "#---------------------------------------------------------------------------" << endl;
84  cout << " Track selection (mMcTracks)" << endl;
85  cout << " For pt, eta, phi : |mMatchedPairs.mEtaPr| > " << yCut << endl;
86  cout << endl;
87 
88  const Char_t* outputFileName = Form("./%s_%s_%s_mc_%s.root", production, particle, Daugther, date);
89  TString oFile(outputFileName);
90 
91  TTreeHelper TH("StMiniMcTree");
92  TH.AddFile(filePathMc);
93 
94  //All reconstructed Histograms
95 
96  TH1D* hMult=new TH1D("hMult","Multiplicity",1000,0,maxNch);
97 
98  TH1D* nChTotal = new TH1D("nChTotal", "nCharged Distribution", 1200, 0, maxNch);
99  TH2F* dedx = new TH2F("dedx", "de/dx vs P", 400, 0.0, 2., 400, 0., maxDedx);
100  TH3D* hDca = new TH3D("hDca","Nch:Pt:Dca",nchNch,0,maxNch,nchPt,0,maxPt,nchDca,0, maxDca);
101  TH3D* hNfit = new TH3D("hNfit","Nch:Pt:Nhits",nchNch,0,maxNch,nchPt,0,maxPt,nchNhits,0,maxNhits);
102 
103  // Checking some Global Variables
104 
105  TH1D* vz = new TH1D("vz","Vertex Z",200,0.-50.,50.0);
106  TH2D* v_xy = new TH2D("vxy", "Vertez_X_Y", 200, -3.0, 3., 400, -3.0, 3.);
107 
108  TH1D* dvz = new TH1D("dvz","Delta Vertex Z MC - Reco",50,0.-5.,5.0);
109  TH1D* dvx = new TH1D("dvx","Delta Vertex X MC - Reco",50,0.-5.,5.0);
110  TH1D* dvy = new TH1D("dvy","Delta Vertex Y MC - Reco",50,0.-5.,5.0);
111 
112  TH1D* hPtM = new TH1D("PtM","Pt_Pr",400,0,20);
113  TH1D* hEtaM = new TH1D("EtaM","EtaPr",200,-1.8,1.8);
114  TH1D* hPhiM = new TH1D("PhiM","PhiPr",200,-5.0,5.0);
115  TH1D* hYM = new TH1D("YM","YPr",100,-1.5,1.5);
116  TH3D* hPtYPhiM = new TH3D("PtYPhiM","Pt:Y:Phi",nchPt,0,maxPt,100,-1.5,1.5,200,-5.0,5.0);
117  TH1D* hFSectM = new TH1D("FSectM","First Sector",30,0,30.);
118  TH1D* hLSectM = new TH1D("LSectM","Last Sector",30,0,30.);
119 
120  TH1D* hPtMc =new TH1D("PtMc","Pt_Mc",400,0,20);
121  TH1D* hEtaMc=new TH1D("EtaMc","Eta_Mc",200,-1.8,1.8);
122  TH1D* hYMc=new TH1D("YMc","Y_Mc",100,-1.5,1.5);
123  TH1D* hPhiMc=new TH1D("PhiMc","Phi_Mc",200,-5.0,5.0);
124  TH3D* hPtYPhiMc = new TH3D("PtYPhiMc","Pt:Y:Phi",nchPt,0,maxPt,100,-1.5,1.5,200,-5.0,5.0);
125 
126  hPtMc->Sumw2();
127  hPtM->Sumw2();
128 
129  //Energy loss
130  TString title = Form("ptM-ptMc :ptM ( |vtx|<30, %.1f< |yMc|<%.1f, nFitM>=25, nComm>=10)", 1., 1.);
131  TH2D* hPtM_E = new TH2D ("hPtM_E", title.Data(), 50, 0, 10, 50, -0.05, 0.05);
132  TString title = Form("YM-YMc :YM ( |vtx|<30, %.1f< |yMc|<%.1f, nFitM>=25, nComm>=10)", 1., 1.);
133  TH2D* hYM_E = new TH2D ("hYM_E", title.Data(), 50, -1.2, 1.2, 50, -0.05, 0.05);
134  TString title = Form("PhiM-PhiMc :PhiM ( |vtx|<30, %.1f< |yMc|<%.1f, nFitM>=25, nComm>=10)", 1., 1.);
135  TH2D* hPhiM_E = new TH2D ("hPhiM_E", title.Data(), 50, -3.2, 3.2, 50, -0.05, 0.05);
136 
137  //Ghost ==Real
138  TH2F* dedxG = new TH2F("dedxG","dE/dx vs p", 400,0., 2., 400, 0.,maxDedx);//for MIPS
139  TH3D* hDcaG = new TH3D("hDcaG","Nch:Pt:Dca",nchNch,0,maxNch,nchPt,0,maxPt,nchDca,0, maxDca);
140  TH3D* hNfitG = new TH3D("hNfitG","Nch:Pt:Nhits",nchNch,0,maxNch,nchPt,0,maxPt,nchNhits,0,maxNhits);
141  TH1D* hPhiG = new TH1D("PhiG","PhiG",200,-5.0,5.0);
142  TH1D* hFSectG = new TH1D("FSectG","First Sector",30,0,30.);
143  TH1D* hLSectG = new TH1D("LSectG","Last Sector",30,0,30.);
144 
145  //3 D histograms for DCa ETA and Pt, also NFit Eta and Pt
146 
147  TH3D* hPtEtaDcaM = new TH3D("hPtEtaDcaM","Pt:Eta:DcaM", nchPt,0, maxPt,200,-1.8,1.8, nchDca,0, maxDca);// for MonteCarlo
148  TH3D* hPtEtaDcaG = new TH3D("hPtEtaDcaG","Pt:Eta:DcaG", nchPt,0, maxPt,200,-1.8,1.8, nchDca,0, maxDca);// for Global
149  hPtEtaDcaM->Sumw2();
150  hPtEtaDcaG->Sumw2();
151 
152  TH3D* hPtEtaNfitM = new TH3D("hPtEtaNfitM","Pt:Eta:NfitM",nchPt,0,maxPt,200,-1.8,1.8,nchNhits,0,maxNhits);// for MonteCarlo
153  TH3D* hPtEtaNfitG = new TH3D("hPtEtaNfitG","Pt:Eta:NfitG",nchPt,0,maxPt,200,-1.8,1.8,nchNhits,0,maxNhits);// for Global
154  hPtEtaNfitM->Sumw2();
155  hPtEtaNfitG->Sumw2();
156 
157  //Variables
158 
159  const Int_t &nch = TH("mNUncorrectedPrimaries");
160  const Float_t &VX = TH("mVertexX");
161  const Float_t &VY = TH("mVertexY");
162  const Float_t &VZ = TH("mVertexZ");
163 
164  const Float_t &VXmc = TH("mMcVertexX");
165  const Float_t &VYmc = TH("mMcVertexY");
166  const Float_t &VZmc = TH("mMcVertexZ");
167 
168  //Mc Tracks
169 
170  const Int_t &ntrk1 = TH ("mMcTracks");
171 
172  const Float_t *&PtMc = TH("mMcTracks.mPtMc");
173  const Float_t *&PzMc = TH("mMcTracks.mPzMc");
174  const Float_t *&NHits = TH("mMcTracks.mNHitMc");
175  const Float_t *&EtaMc = TH("mMcTracks.mEtaMc");
176  const Float_t *&PhiMc = TH("mMcTracks.mPhiMc");
177 
178  // Matched Pairs
179  /*
180  const Int_t &ntrk = TH("mMatchedPairs"); //Extension Pr - all possible reconstructed tracks
181 
182  const Float_t *&PtM = TH("mMatchedPairs.mPtPr");
183  const Float_t *&PzM = TH("mMatchedPairs.mPzPr");
184  const Float_t *&EtaM = TH("mMatchedPairs.mEtaPr");
185  const Float_t *&PhiM = TH("mMatchedPairs.mPhiPr");
186  const Short_t *&FSectM = TH("mMatchedPairs.mFirstSector");
187  const Short_t *&LSectM = TH("mMatchedPairs.mLastSector");
188 
189 
190  //Ext Mc - reconstructed and matched with embedded tracks
191 
192  const Float_t *&PtMmc= TH("mMatchedPairs.mPtMc");
193  const Float_t *&PzMmc= TH("mMatchedPairs.mPzMc");
194  const Float_t *&EtaMmc = TH("mMatchedPairs.mEtaMc");
195  const Float_t *&PhiMmc = TH("mMatchedPairs.mPhiMc");
196 
197  const Float_t *&dEdx = TH("mMatchedPairs.mDedx");
198  const Float_t *&Dca = TH("mMatchedPairs.mDcaGl");
199  const Short_t *&NFit = TH("mMatchedPairs.mFitPts");
200  const Short_t *&NComm = TH("mMatchedPairs.mNCommonHit");
201 
202  const Short_t *&Gid = TH("mMatchedPairs.mGeantId");
203 
204  */
205  //========================================================
206  //to scan meson Phi, use MatGlobalPairs instead of Matchd pairs
207 
208  const Int_t &ntrk = TH("mMatGlobPairs");
209 
210  const Float_t *&PtM = TH("mMatGlobPairs.mPtGl");
211  const Float_t *&PzM = TH("mMatGlobPairs.mPzGl");
212  const Float_t *&EtaM = TH("mMatGlobPairs.mEtaGl");
213  const Float_t *&PhiM = TH("mMatGlobPairs.mPhiGl");
214 
215  const Short_t *&FSectM = TH("mMatGlobPairs.mFirstSector");
216  const Short_t *&LSectM = TH("mMatGlobPairs.mLastSector");
217 
218 
219  const Float_t *&PtMmc= TH("mMatGlobPairs.mPtMc");
220  const Float_t *&PzMmc= TH("mMatGlobPairs.mPzMc");
221  const Float_t *&EtaMmc = TH("mMatGlobPairs.mEtaMc");
222  const Float_t *&PhiMmc = TH("mMatGlobPairs.mPhiMc");
223 
224  const Float_t *&dEdx = TH("mMatGlobPairs.mDedx");
225  const Float_t *&Dca = TH("mMatGlobPairs.mDcaGl");
226  const Short_t *&NFit = TH("mMatGlobPairs.mFitPts");
227  const Short_t *&NComm = TH("mMatGlobPairs.mNCommonHit");
228 
229  const Short_t *&Gid = TH("mMatGlobPairs.mGeantId");
230 
231  //=======================================================
232 
233 
234  //Ghost Tracks
235 
236  const Int_t &ntrkG = TH("mGhostPairs");
237 
238  const Float_t *&PtG = TH("mGhostPairs.mPtPr");
239  const Float_t *&PzG = TH("mGhostPairs.mPzPr");
240  const Float_t *&dEdxG= TH("mGhostPairs.mDedx");
241  const Float_t *&DcaG = TH("mGhostPairs.mDcaGl");
242  const Float_t *&EtaG = TH("mGhostPairs.mEtaPr");
243  const Float_t *&PhiG = TH("mGhostPairs.mPhiPr");
244  const Short_t *&NFitG = TH("mGhostPairs.mFitPts");
245  const Short_t *&FSectG = TH("mGhostPairs.mFirstSector");
246  const Short_t *&LSectG = TH("mGhostPairs.mLastSector");
247 
248  int ev = 0;
249  int evGood = 0;
250  while(TH.Next())// && ev ==0)
251  {
252  //checking vertex position
253 
254  vz->Fill(VZ);// 1 vertex per event, first fill vz and then apply the cuts
255 
256  vxy->Fill(VX,VY);//this is the 2d ok
257 
258  dvx->Fill(VX-VXmc);//delta VX
259  dvy->Fill(VY-VYmc);
260  dvz->Fill(VZ-VZmc);//delta VZ
261 
262  ev++;
263 
264  if(fabs(VZ)> VZCut) continue;
265  evGood++;
266 
267  // cout << Form("MiniMcTree: (Good Event)/(Event number) = %5d/%5d, VZ = %1.4f, Number of embedded tracks = %10d, Matched tracks = %10d", evGood, ev, VZ, ntrk1, ntrk) << endl;
268 
269  for (Int_t itr=0; itr<ntrk; itr++)
270  {
271 
272  if ( Gid[itr]!=14 && Gid[itr]!=15) continue; //use this line for Phi meson decaying in KK (14, 15)
273  if (fabs(EtaM[itr]) > yCut) continue;
274 
275  //Defining Momentum
276 
277  float p = sqrt(PtM[itr]*PtM[itr]+PzM[itr]*PzM[itr]);
278 
279  if (NFit[itr] >= NFitCut && NComm[itr] > NCommCut)
280  {
281 
282  hDca->Fill(nch, PtM[itr],Dca[itr]);
283  hPtEtaDcaM ->Fill( PtM[itr], EtaM[itr], Dca[itr]);
284  //of course x ->Pt, y->Eta, z->DCA
285  }
286 
287 
288  //if (Dca[itr] < maxDca && (1.*(NFit[itr])/NComm[itr])< 2.5 && NFit[itr]>=10)
289  if (Dca[itr] < maxDca && NFit[itr]>=10)
290  {
291  hNfit ->Fill(nch, PtM[itr], NFit[itr]);
292  hPtEtaNfitM ->Fill( PtM[itr], EtaM[itr], NFit[itr]);
293  //of course x ->Pt, y->Eta, z->NFIT
294 
295  }
296 
297  if( Dca[itr] < maxDca && NFit[itr] >= NFitCut && NComm[itr] > NCommCut)
298  dedx->Fill(p,dEdx[itr]*1e6);
299 
300  // filling histograms for global variables and energy loss
301 
302  if (Dca[itr]<0. || Dca[itr]>maxDca) continue;
303  if(NFit[itr] >= NFitCut && NComm[itr] > NCommCut )
304  {
305  hPtM->Fill(PtM[itr]);
306  hEtaM->Fill(EtaM[itr]);
307  hFSectM->Fill(FSectM[itr]);
308  hLSectM->Fill(LSectM[itr]);
309  Double_t mass0 = 0.13957;
310  Double_t P0 = sqrt(PtM[itr]*PtM[itr]+PzM[itr]*PzM[itr]+mass0*mass0);
311  Double_t P0mc = sqrt(PtMmc[itr]*PtMmc[itr]+PzMmc[itr]*PzMmc[itr]+mass0*mass0);
312  Double_t rap = 0.5*log((P0+PzM[itr])/(P0-PzM[itr]));
313  Double_t rapmc = 0.5*log((P0mc+PzMmc[itr])/(P0mc-PzMmc[itr]));
314  hYM->Fill(rap);
315  hPhiM->Fill(PhiM[itr]);
316  hPtM_E->Fill(PtM[itr], PtM[itr]-PtMmc[itr]);
317  hYM_E->Fill(rap, rap-rapmc);
318  hPhiM_E->Fill(PhiM[itr], PhiM[itr]-PhiMmc[itr]);
319  hPtYPhiM->Fill(PtM[itr],rap,PhiM[itr]);
320  }
321 
322  }//closing for loop
323 
324  //filling Ghosts tracks
325 
326  for (Int_t itrG=0; itrG<ntrkG; itrG++)
327  {
328  if (fabs(EtaG[itrG]) > yCut) continue;
329  float pg = sqrt(PtG[itrG]*PtG[itrG]+PzG[itrG]*PzG[itrG]);
330 
331  if (NFitG[itrG] >= NFitCut)
332  {
333  hDcaG ->Fill(nch, PtG[itrG],DcaG[itrG]);
334  hPtEtaDcaG ->Fill(PtG[itr], EtaG[itr], DcaG[itr]);
335  //of course x-> Pt, y->Eta, z->DCA
336  }
337 
338  if (DcaG[itrG] < maxDca && NFitG[itrG] >= 10)
339  {
340  hNfitG ->Fill(nch, PtG[itrG], NFitG[itrG]);
341  hPtEtaNfitG->Fill( PtG[itr], EtaG[itr], NFitG[itr]);
342  //of course x-> Pt, y->Eta, z->Nfit
343  }
344 
345  if( DcaG[itrG] < maxDca && NFitG[itrG] >= NFitCut){
346  dedxG->Fill(pg,dEdxG[itrG]*1e6);
347  hPhiG->Fill(PhiG[itrG]);
348  hFSectG->Fill(FSectG[itrG]);
349  hLSectG->Fill(LSectG[itrG]);
350  }
351  }
352 
353  //filling Mc tracks(embedded)
354 
355  for (int itr1=0; itr1 < ntrk1; itr1++)
356  {
357  //if (fabs(EtaMc[itr1]) > yCut) continue;
358 
359  hPtMc->Fill(PtMc[itr1]);
360  hEtaMc->Fill(EtaMc[itr1]);
361  Double_t mass0 = 0.13957;
362  Double_t P0 = sqrt(PtMc[itr1]*PtMc[itr1]+PzMc[itr1]*PzMc[itr1]+mass0*mass0);
363  hYMc->Fill(0.5*log((P0+PzMc[itr1])/(P0-PzMc[itr1])));
364  hPhiMc->Fill(PhiMc[itr1]);
365  hPtYPhiMc->Fill(PtMc[itr1],0.5*log((P0+PzMc[itr1])/(P0-PzMc[itr1])),PhiMc[itr1]);
366  }
367 
368  }//closing while loop
369 
370 
371  //-------Writing-----------
372 
373  cout<< "Creating output file .... "<<oFile; flush(cout);
374 
375  TFile *fout=new TFile(oFile,"recreate");
376  fout->cd();
377 
378  // -- MC
379  hMult->Write();
380  nChTotal->Write();
381  dedx->Write();
382  dedxG->Write();
383  hNfit->Write();
384  hNfitG->Write();
385  hDca-> Write();
386 
387  //Ghost
388  hDcaG-> Write();
389  hPhiG->Write();
390  hFSectG->Write();
391  hLSectG->Write();
392 
393  hPtEtaNfitG->Write();
394  hPtEtaDcaG ->Write();
395 
396  //Global Variables
397  v_xy->Write();
398  vz->Write();
399 
400  dvx->Write();
401  dvy->Write();
402  dvz->Write();
403 
404  //---Matched
405  hPtM->Write();
406  hEtaM->Write();
407  hFSectM->Write();
408  hLSectM->Write();
409  hYM->Write();
410  hPhiM->Write();
411  hPtM_E->Write();
412  hYM_E->Write();
413  hPhiM_E->Write();
414  hPtYPhiM->Write();
415 
416  hPtEtaDcaM->Write();
417  hPtEtaNfitM-> Write();
418 
419  //---Embedded
420  hEtaMc->Write();
421  hYMc->Write();
422  hPtMc->Write();
423  hPhiMc->Write();
424  hPtYPhiMc->Write();
425 
426  fout->GetList()->Sort();
427 
428  fout->Close();
429  cout<<" done"<<endl; flush(cout);
430 }
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Definition: TDataSet.cxx:893