0dd1d5c3bb1a88f746835343150b37867b4a4d76
[u/mrichter/AliRoot.git] / PWGLF / SPECTRA / PiKaPr / TOF / pp7 / AliAnalysisCombinedHadronSpectra2MC.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 ///////////////////////////////////////////////////////////////////////////
17 //                                                                       //
18 //                                                                       //
19 // Analysis for identified charged hadron spectra. TPC/TOF               //
20 //                                                                       //
21 //                                                                       //
22 ///////////////////////////////////////////////////////////////////////////
23
24
25
26
27 #include "Riostream.h"
28 #include "TChain.h"
29 #include "TTree.h"
30 #include "TH1F.h"
31 #include "TH2F.h"
32 #include "TH3F.h"
33 #include "TList.h"
34 #include "TMath.h"
35 #include "TCanvas.h"
36 #include "TObjArray.h"
37 #include "TF1.h"
38 #include "TFile.h"
39
40 #include "AliAnalysisTaskSE.h"
41 #include "AliAnalysisManager.h"
42
43 #include "AliHeader.h"
44 #include "AliGenPythiaEventHeader.h"
45 #include "AliGenCocktailEventHeader.h"
46
47 #include "AliPID.h"
48 #include "AliESDtrackCuts.h"
49 #include "AliESDVertex.h"
50 #include "AliESDEvent.h"
51 #include "AliESDInputHandler.h"
52 #include "AliESDtrack.h"
53 #include "AliESDpid.h"
54
55 #include "AliMCEventHandler.h"
56 #include "AliMCEvent.h"
57 #include "AliStack.h"
58
59 #include "AliAnalysisFilter.h"
60 #include "AliCFContainer.h"
61 #include "AliCFFrame.h"
62 #include "AliCFGridSparse.h"
63 #include "TDatabasePDG.h"
64 #include "TROOT.h"
65 #include "TSystem.h"
66
67 #include "AliAnalysisTaskSE.h"
68 #include "AliAnalysisManager.h"
69
70 #include "AliHeader.h"
71 #include "AliGenPythiaEventHeader.h"
72 #include "AliGenCocktailEventHeader.h"
73
74 #include "AliPID.h"
75 #include "AliESDtrackCuts.h"
76 #include "AliESDVertex.h"
77 #include "AliESDEvent.h"
78 #include "AliESDInputHandler.h"
79 #include "AliESDtrack.h"
80 #include "AliESDpid.h"
81
82 #include "AliMCEventHandler.h"
83 #include "AliMCEvent.h"
84 #include "AliStack.h"
85
86 #include "AliAnalysisFilter.h"
87 #include "AliCFContainer.h"
88 #include "AliCFFrame.h"
89 #include "AliCFGridSparse.h"
90 #include "TDatabasePDG.h"
91 #include "TROOT.h"
92 #include "TSystem.h"
93 #include "AliMultiplicity.h"
94
95
96 #include "AliLog.h"
97 #include "AliESDUtils.h"
98
99 #include "AliAnalysisCombinedHadronSpectra2MC.h"
100
101
102 ClassImp(AliAnalysisCombinedHadronSpectra2MC)
103
104 //________________________________________________________________________
105 AliAnalysisCombinedHadronSpectra2MC::AliAnalysisCombinedHadronSpectra2MC() 
106 : AliAnalysisTaskSE("TaskChargedHadron"), multiplicity(0),vert(0), fESD(0), fListHist(0), fESDtrackCuts(0),fESDpid(0),
107   fMCtrue(0),
108   fAlephParameters(),
109   TOFCheck(0),  
110   calibrateESD(kTRUE), correctTExp(kTRUE), useT0TOF(kTRUE), timeResolution(96.), tuneTOFMC(kFALSE),
111   fTreeTrack(0),
112   fTreeEv(0),
113   fLoadOCDB(kTRUE),
114   frunOld(0),
115   frun(0),
116   tofCalib(0),
117   t0maker(0),
118   fT0TOF0(-999), fT0TOF1(-999), fT0TOF2(-999), fT0TOF3(-999), fT0TOF4(-999), fT0TOF5(-999), fT0TOF6(-999), fT0TOF7(-999), XPrimVertex(-999), YPrimVertex(-999), ZPrimVertex(-999), NContrPrimVertex(-999), rapidityMC(0), fDCAXY(-999), fDCAZ(-999), fcut(-999), fTOFout(-999), ftrdout(-999), ftime(-999), ftpcclust(-999), flength(-999), fsign(-999), ftimetof(-999), ftofchan(-999), feta(-999), fphi(-999), fmomtrasv(-999),sigmapi(-999), sigmaka(-999), sigmapr(-999), fTot(-999), fmom(-999), fexptimepi(-999), fexptimeka(-999), fexptimepr(-999), ftofz(-999),ftofx(-999), t0track(-999), TPCSignal(-999), TPCSigmaPI(-999), TPCSigmaKA(-999), TPCSigmaPR(-999), fmatch(-999), fPhiout(-999), fXout(-999), fYout(-999), fZout(-999), fTimeZeroType(AliESDpid::kTOF_T0), fMCtracks(-999), fMCPrimaries(-999), spdCorr(-999), treeMCP(-999), treeMCPt(-999), treeMCEta(-999), treeMCPhi(-999), treeMCPdg(-999), treeMCPBis(-999), treeMCPtBis(-999), treeMCEtaBis(-999), treeMCPhiBis(-999), treeMCPdgBis(-999), t0trackSigma(-999), fptMC(-999), fphiMC(-999), fetaMC(-999), fPdgcode(-999),
119 pad (0x0), resx(0x0), resz(0x0), tofres(0x0), tofresTOF(0x0), tofresgood (0x0), hNumMatch(0x0), hNumMatchPos(0x0),  hNumMatchNeg(0x0),  hDenMatch(0x0),  
120   hNumMatchPip(0x0), hNumMatchPim(0x0),hNumMatchKap(0x0),  hNumMatchKam(0x0),hNumMatchPrp(0x0),  hNumMatchPrm(0x0), hDenMatchPip(0x0),  hDenMatchPim(0x0), hDenMatchKap(0x0),  hDenMatchKam(0x0), hDenMatchPrp(0x0), hDenMatchPrm(0x0),
121
122 hDenMatchPos(0x0),  hDenMatchNeg(0x0),  hNumMatchEta(0x0),  hNumMatchPosEta(0x0),  hNumMatchNegEta(0x0),  hDenMatchEta(0x0),  hDenMatchPosEta(0x0),   hDenMatchNegEta(0x0),  hNumMatchphiOut(0x0),  hNumMatchPosphiOut(0x0),  hNumMatchNegphiOut(0x0),  hDenMatchphiOut(0x0),  hDenMatchPosphiOut(0x0),  hDenMatchNegphiOut(0x0),  hNumMatchEtaPtMa(0x0),  hNumMatchPosEtaPtMa(0x0),  hNumMatchNegEtaPtMa(0x0),  hDenMatchEtaPtMa(0x0),  hDenMatchPosEtaPtMa(0x0),  hDenMatchNegEtaPtMa(0x0),  hNumMatchphiOutPtMa(0x0),  hNumMatchPosphiOutPtMa(0x0),  hNumMatchNegphiOutPtMa(0x0),  hDenMatchphiOutPtMa(0x0),  hDenMatchPosphiOutPtMa(0x0),  hDenMatchNegphiOutPtMa(0x0), hNumMatchTRDOut(0x0), hNumMatchPosTRDOut(0x0), hNumMatchNegTRDOut(0x0), hDenMatchTRDOut(0x0), hDenMatchPosTRDOut(0x0), hDenMatchNegTRDOut(0x0), hNumMatchNoTRDOut(0x0), hNumMatchPosNoTRDOut(0x0), hNumMatchNegNoTRDOut(0x0), hDenMatchNoTRDOut(0x0), hDenMatchPosNoTRDOut(0x0), hDenMatchNegNoTRDOut(0x0), hNumMatchTPCpip(0x0), hNumMatchTPCkap(0x0), hNumMatchTPCprp(0x0), hDenMatchTPCpip(0x0), hDenMatchTPCkap(0x0), hDenMatchTPCprp(0x0), hNumMatchTPCpim(0x0), hNumMatchTPCkam(0x0), hNumMatchTPCprm(0x0), hDenMatchTPCpim(0x0), hDenMatchTPCkam(0x0), hDenMatchTPCprm(0x0), hNumEv(0x0) 
123 {
124   // default Constructor
125   for(Int_t i=0; i<5;i++){r1[i]=-999;}
126   
127   for(Int_t mult=0; mult<7;mult++){
128     for(Int_t part=0; part<6;part++){
129       hNumMatchMultTrk[mult][part]=(0);
130       hDenMatchMultTrk[mult][part]=(0);
131       hDenTrkMultTrk[mult][part]=(0);
132     }
133   }
134   
135   for(Int_t mult=0; mult<7;mult++){
136     for(Int_t part=0; part<6;part++){
137       hNumMatchMultTrkTRDOut[mult][part]=(0);
138       hDenMatchMultTrkTRDOut[mult][part]=(0);
139       hDenTrkMultTrkTRDOut[mult][part]=(0);
140     }
141   }
142
143   for(Int_t mult=0; mult<7;mult++){
144     for(Int_t part=0; part<6;part++){
145       hNumMatchMultTrkNoTRDOut[mult][part]=(0);
146       hDenMatchMultTrkNoTRDOut[mult][part]=(0);
147       hDenTrkMultTrkNoTRDOut[mult][part]=(0);
148     }
149   }
150
151   for(Int_t mult=0; mult<7;mult++){
152     for(Int_t part=0; part<6;part++){
153       hNumMatchMultSPD[mult][part]=(0);
154       hDenMatchMultSPD[mult][part]=(0);
155       hDenTrkMultSPD[mult][part]=(0);
156     }
157   }
158   
159   for(Int_t mult=0; mult<7;mult++){
160     for(Int_t part=0; part<2;part++){
161       hNumMatchMultTrkInc[mult][part]=(0);
162       hDenMatchMultTrkInc[mult][part]=(0);
163       hNumMatchMultSPDInc[mult][part]=(0);
164       hDenMatchMultSPDInc[mult][part]=(0);
165     }
166   }
167   
168   for(Int_t part=0; part<6;part++){
169     hDenTrkVertMultTrk[part]=(0);
170   }
171   for(Int_t part=0; part<6;part++){
172     hDenTrkTriggerMultTrk[part]=(0);
173   }
174   
175 }
176
177
178 //________________________________________________________________________
179 AliAnalysisCombinedHadronSpectra2MC::AliAnalysisCombinedHadronSpectra2MC(const char *name)  : AliAnalysisTaskSE(name), multiplicity(0),vert(0), fESD(0), fListHist(0), fESDtrackCuts(0),fESDpid(0),
180   fMCtrue(0),
181   fAlephParameters(),
182   TOFCheck(0),  
183   calibrateESD(kTRUE), correctTExp(kTRUE), useT0TOF(kTRUE), timeResolution(96.), tuneTOFMC(kFALSE),
184   fTreeTrack(0),
185   fTreeEv(0),
186   fLoadOCDB(kTRUE),
187   frunOld(0),
188   frun(0),
189   tofCalib(0),
190   t0maker(0),
191                                                                                               fT0TOF0(-999), fT0TOF1(-999), fT0TOF2(-999), fT0TOF3(-999), fT0TOF4(-999), fT0TOF5(-999), fT0TOF6(-999), fT0TOF7(-999), XPrimVertex(-999), YPrimVertex(-999), ZPrimVertex(-999), NContrPrimVertex(-999), rapidityMC(0), fDCAXY(-999), fDCAZ(-999), fcut(-999), fTOFout(-999), ftrdout(-999), ftime(-999), ftpcclust(-999), flength(-999), fsign(-999), ftimetof(-999), ftofchan(-999), feta(-999), fphi(-999), fmomtrasv(-999),sigmapi(-999), sigmaka(-999), sigmapr(-999), fTot(-999), fmom(-999), fexptimepi(-999), fexptimeka(-999), fexptimepr(-999), ftofz(-999),ftofx(-999), t0track(-999), TPCSignal(-999), TPCSigmaPI(-999), TPCSigmaKA(-999), TPCSigmaPR(-999), fmatch(-999), fPhiout(-999), fXout(-999), fYout(-999), fZout(-999), fTimeZeroType(AliESDpid::kTOF_T0), fMCtracks(-999), fMCPrimaries(-999), spdCorr(-999), treeMCP(-999), treeMCPt(-999), treeMCEta(-999), treeMCPhi(-999), treeMCPdg(-999), treeMCPBis(-999), treeMCPtBis(-999), treeMCEtaBis(-999), treeMCPhiBis(-999), treeMCPdgBis(-999), t0trackSigma(-999), fptMC(-999), fphiMC(-999), fetaMC(-999), fPdgcode(-999),
192 pad (0x0), resx(0x0), resz(0x0), tofres(0x0), tofresTOF(0x0), tofresgood (0x0), hNumMatch(0x0), hNumMatchPos(0x0),  hNumMatchNeg(0x0),  hDenMatch(0x0), 
193  hNumMatchPip(0x0), hNumMatchPim(0x0),hNumMatchKap(0x0),  hNumMatchKam(0x0),hNumMatchPrp(0x0),  hNumMatchPrm(0x0), hDenMatchPip(0x0),  hDenMatchPim(0x0), hDenMatchKap(0x0),  hDenMatchKam(0x0), hDenMatchPrp(0x0), hDenMatchPrm(0x0),
194  hDenMatchPos(0x0),  hDenMatchNeg(0x0),  hNumMatchEta(0x0),  hNumMatchPosEta(0x0),  hNumMatchNegEta(0x0),  hDenMatchEta(0x0),  hDenMatchPosEta(0x0),   hDenMatchNegEta(0x0),  hNumMatchphiOut(0x0),  hNumMatchPosphiOut(0x0),  hNumMatchNegphiOut(0x0),  hDenMatchphiOut(0x0),  hDenMatchPosphiOut(0x0),  hDenMatchNegphiOut(0x0),  hNumMatchEtaPtMa(0x0),  hNumMatchPosEtaPtMa(0x0),  hNumMatchNegEtaPtMa(0x0),  hDenMatchEtaPtMa(0x0),  hDenMatchPosEtaPtMa(0x0),  hDenMatchNegEtaPtMa(0x0),  hNumMatchphiOutPtMa(0x0),  hNumMatchPosphiOutPtMa(0x0),  hNumMatchNegphiOutPtMa(0x0),  hDenMatchphiOutPtMa(0x0),  hDenMatchPosphiOutPtMa(0x0),  hDenMatchNegphiOutPtMa(0x0), hNumMatchTRDOut(0x0), hNumMatchPosTRDOut(0x0), hNumMatchNegTRDOut(0x0), hDenMatchTRDOut(0x0), hDenMatchPosTRDOut(0x0), hDenMatchNegTRDOut(0x0), hNumMatchNoTRDOut(0x0), hNumMatchPosNoTRDOut(0x0), hNumMatchNegNoTRDOut(0x0), hDenMatchNoTRDOut(0x0), hDenMatchPosNoTRDOut(0x0), hDenMatchNegNoTRDOut(0x0), hNumMatchTPCpip(0x0), hNumMatchTPCkap(0x0), hNumMatchTPCprp(0x0), hDenMatchTPCpip(0x0), hDenMatchTPCkap(0x0), hDenMatchTPCprp(0x0), hNumMatchTPCpim(0x0), hNumMatchTPCkam(0x0), hNumMatchTPCprm(0x0), hDenMatchTPCpim(0x0), hDenMatchTPCkam(0x0), hDenMatchTPCprm(0x0),  hNumEv(0x0)
195 {
196   
197   //
198   // standard constructur which should be used
199   //
200   Printf("*** CONSTRUCTOR CALLED ****");
201
202
203   for(Int_t mult=0; mult<7;mult++){
204     for(Int_t part=0; part<6;part++){
205       hNumMatchMultTrk[mult][part]=(0);
206       hDenMatchMultTrk[mult][part]=(0);
207       hDenTrkMultTrk[mult][part]=(0);
208     }
209   }
210
211   for(Int_t mult=0; mult<7;mult++){
212     for(Int_t part=0; part<6;part++){
213       hNumMatchMultTrkTRDOut[mult][part]=(0);
214       hDenMatchMultTrkTRDOut[mult][part]=(0);
215       hDenTrkMultTrkTRDOut[mult][part]=(0);
216     }
217   }
218
219   for(Int_t mult=0; mult<7;mult++){
220     for(Int_t part=0; part<6;part++){
221       hNumMatchMultTrkNoTRDOut[mult][part]=(0);
222       hDenMatchMultTrkNoTRDOut[mult][part]=(0);
223       hDenTrkMultTrkNoTRDOut[mult][part]=(0);
224     }
225   }
226
227   for(Int_t mult=0; mult<7;mult++){
228     for(Int_t part=0; part<6;part++){
229       hNumMatchMultSPD[mult][part]=(0);
230       hDenMatchMultSPD[mult][part]=(0);
231       hDenTrkMultSPD[mult][part]=(0);
232     }
233   }
234   
235   for(Int_t mult=0; mult<7;mult++){
236     for(Int_t part=0; part<2;part++){
237       hNumMatchMultTrkInc[mult][part]=(0);
238       hDenMatchMultTrkInc[mult][part]=(0);
239       hNumMatchMultSPDInc[mult][part]=(0);
240       hDenMatchMultSPDInc[mult][part]=(0);
241       }
242   }
243
244   for(Int_t part=0; part<6;part++){
245     hDenTrkVertMultTrk[part]=(0);
246   }
247   for(Int_t part=0; part<6;part++){
248     hDenTrkTriggerMultTrk[part]=(0);
249   }
250   
251
252   // 
253   /* real */
254   //   for(Int_t i=0; i<5;i++){r1[i]=-999;}
255   //   fAlephParameters[0] = 0.0283086;
256   //   fAlephParameters[1] = 2.63394e+01;
257   //   fAlephParameters[2] = 5.04114e-11;
258   //   fAlephParameters[3] = 2.12543e+00;
259   //   fAlephParameters[4] = 4.88663e+00;
260   //
261   // initialize PID object
262   //
263   
264   //   tofCalib = new AliTOFcalib();
265   
266   //   fESDpid = new AliESDpid();
267   
268   //   t0maker = new AliTOFT0maker(fESDpid, tofCalib); 
269   
270   //   if(AliPID::ParticleMass(0) == 0) new AliPID(); 
271   
272   //
273   // create track cuts
274   //
275   AliESDtrackCuts* ESDtrackCuts = new AliESDtrackCuts("AliESDtrackCuts","AliESDtrackCuts");
276   fESDtrackCuts = (AliESDtrackCuts*) ESDtrackCuts->GetStandardITSTPCTrackCuts2010(kTRUE);
277   
278   
279   DefineOutput(1, TList::Class());
280
281 }
282
283
284 //________________________________________________________________________
285 Int_t AliAnalysisCombinedHadronSpectra2MC::Mult()
286 {
287   AliESDtrackCuts* esdTrackCutsMult = new AliESDtrackCuts;
288   
289   // TPC
290   esdTrackCutsMult->SetMinNClustersTPC(70);
291   esdTrackCutsMult->SetMaxChi2PerClusterTPC(4);
292   esdTrackCutsMult->SetAcceptKinkDaughters(kFALSE);
293   esdTrackCutsMult->SetRequireTPCRefit(kTRUE);
294   // ITS
295   esdTrackCutsMult->SetRequireITSRefit(kTRUE);
296   esdTrackCutsMult->SetClusterRequirementITS(AliESDtrackCuts::kSPD,
297                                              AliESDtrackCuts::kAny);
298   
299   esdTrackCutsMult->SetMaxDCAToVertexXYPtDep("0.0182+0.0350/pt^1.01");
300   
301   esdTrackCutsMult->SetMaxDCAToVertexZ(2);
302   
303   esdTrackCutsMult->SetDCAToVertex2D(kFALSE);
304   esdTrackCutsMult->SetRequireSigmaToVertex(kFALSE);
305   
306   esdTrackCutsMult->SetEtaRange(-0.8,+0.8);
307   esdTrackCutsMult->SetPtRange(0.15, 1e10);
308   
309   // Here is what we finally want:
310   Int_t multipli = esdTrackCutsMult->CountAcceptedTracks(fESD);
311   delete esdTrackCutsMult;
312   return multipli;
313   
314  }
315
316
317 //________________________________________________________________________
318 void AliAnalysisCombinedHadronSpectra2MC::UserCreateOutputObjects() 
319 {
320   // Create histograms
321   // Called once
322   
323   //OpenFile(2);
324
325   fTreeTrack = new TTree("TreeTrack","Track Properties");
326
327   fTreeTrack->Branch("XPrimVertex",&XPrimVertex,"XPrimVertex/D");  
328   fTreeTrack->Branch("YPrimVertex",&YPrimVertex,"YPrimVertex/D");  
329   fTreeTrack->Branch("ZPrimVertex",&ZPrimVertex,"ZPrimVertex/D"); 
330   
331   fTreeTrack->Branch("NContrPrimVertex",&NContrPrimVertex,"NContrPrimVertex/I");  
332   fTreeTrack->Branch("multiplicity",&multiplicity,"multiplicity/I");  
333   fTreeTrack->Branch("T0TOF0",&fT0TOF0,"T0TOF0/D");
334   fTreeTrack->Branch("T0TOF1",&fT0TOF1,"T0TOF1/D");
335   fTreeTrack->Branch("T0TOF7",&fT0TOF7,"T0TOF7/D");
336   fTreeTrack->Branch("DCAXY",&fDCAXY,"fDCAXY/F");  
337   fTreeTrack->Branch("DCAZ",&fDCAZ,"fDCAZ/F");  
338   fTreeTrack->Branch("cut",&fcut,"cut/I");
339   fTreeTrack->Branch("TOFout",&fTOFout,"TOFout/I");
340   fTreeTrack->Branch("ftrdout",&ftrdout,"ftrdout/I");
341   fTreeTrack->Branch("ftime",&ftime,"ftime/I");
342   fTreeTrack->Branch("fmatch",&fmatch,"fmatch/I");
343   fTreeTrack->Branch("fmom",&fmom,"fmom/D");
344   fTreeTrack->Branch("tpcclust",&ftpcclust,"tpcclust/I");
345   fTreeTrack->Branch("length",&flength,"length/D");
346   fTreeTrack->Branch("sign",&fsign,"sign/I");
347   fTreeTrack->Branch("timetof",&ftimetof,"timetof/D");
348   fTreeTrack->Branch("exptimepi",&fexptimepi,"exptimepi/D");
349   fTreeTrack->Branch("exptimeka",&fexptimeka,"exptimeka/D");
350   fTreeTrack->Branch("exptimepr",&fexptimepr,"exptimepr/D");
351   fTreeTrack->Branch("tofz",&ftofz,"tofz/D"); 
352   fTreeTrack->Branch("tofx",&ftofx,"tofx/D");
353   fTreeTrack->Branch("t0track",&t0track,"t0track/F");
354   fTreeTrack->Branch("tofchan",&ftofchan,"tofchan/I");
355   fTreeTrack->Branch("eta",&feta,"eta/D");
356   fTreeTrack->Branch("phi",&fphi,"phi/D");
357   fTreeTrack->Branch("TOFtot",&fTot,"TOFtot/F");
358   fTreeTrack->Branch("momtrasv",&fmomtrasv,"momtrasv/D");
359   fTreeTrack->Branch("sigmapi",&sigmapi,"sigmapi/D");
360   fTreeTrack->Branch("sigmaka",&sigmaka,"sigmaka/D");
361   fTreeTrack->Branch("sigmapr",&sigmapr,"sigmapr/D");
362   fTreeTrack->Branch("TPCsignal",&TPCSignal,"TPCsignal/D");
363   fTreeTrack->Branch("TPCSigmaPI",&TPCSigmaPI,"TPCSigmaPI/F");
364   fTreeTrack->Branch("TPCSigmaKA",&TPCSigmaKA,"TPCSigmaKA/F");
365   fTreeTrack->Branch("TPCSigmaPR",&TPCSigmaPR,"TPCSigmaPR/F");
366   fTreeTrack->Branch("r10",&r1[0],"r10/D");
367   fTreeTrack->Branch("r11",&r1[1],"r11/D");
368   fTreeTrack->Branch("r12",&r1[2],"r12/D");
369   fTreeTrack->Branch("r13",&r1[3],"r13/D");
370   fTreeTrack->Branch("r14",&r1[4],"r14/D");
371   
372   fTreeTrack->Branch("fPhiout",&fPhiout,"fPhiout/D");
373   fTreeTrack->Branch("fXout",&fXout,"fXout/D");
374   fTreeTrack->Branch("fYout",&fYout,"fYout/D");
375   fTreeTrack->Branch("fZout",&fZout,"fZout/D");
376
377   //PostData(2, fTreeTrack);
378
379   //OpenFile(1);
380
381   fTreeEv = new TTree("TreeEv","Event Properties");
382   fTreeEv->Branch("multiplicity",&multiplicity,"multiplicity/I");  
383   fTreeEv->Branch("vert",&vert,"vert/I");  
384
385   //PostData(1, fTreeEv);
386
387   OpenFile(1);
388
389   if (!TOFCheck) TOFCheck = new TList();
390   TOFCheck->SetOwner();
391
392   Double_t fBinLim0[47];
393   for(Int_t i=0;i<=46;i++){
394     // pt [0.20,5] GeV/c - not uniform
395     if(i<=16) fBinLim0[i] = 0.2 + i*0.05;
396     if((i>16)&&(i<=36))fBinLim0[i] = 1.0 + (i-16)*0.1;
397     if(i>36) fBinLim0[i] = 3.0 + (i-36)*0.2;
398   }
399
400
401   pad=new TH2D("pad", "pad", 400, -10, 10, 400, -10, 10);
402   pad->GetXaxis()->SetTitle("#DeltaX_{pad} (cm)");
403   pad->GetYaxis()->SetTitle("#DeltaZ_{pad} (cm)");
404   TOFCheck->AddLast(pad);
405   resx=new TH1D("resx", "resx", 150, -10, 10);
406   resx->GetXaxis()->SetTitle("#DeltaX_{pad} (cm)");
407   TOFCheck->AddLast(resx);
408   resz=new TH1D("resz", "resz", 150, -10, 10);
409   resz->GetXaxis()->SetTitle("#DeltaZ_{pad} (cm)");
410   TOFCheck->AddLast(resz);
411   tofres=new TH1D("tofres", "tofres", 100, -500, 500);
412   tofres->GetXaxis()->SetTitle("t_{TOF}-t_{0}-t_{exp #pi} (ps)");
413   TOFCheck->AddLast(tofres);
414   tofresTOF=new TH1D("tofresTOF", "tofresTOF", 100, -500, 500);
415   tofresTOF->GetXaxis()->SetTitle("t_{TOF}-t_{0}-t_{exp #pi} (ps)");
416   TOFCheck->AddLast(tofresTOF);
417   tofresgood=new TH1D("tofresgood", "tofresgood", 100, -500, 500);
418   tofresgood->Sumw2();
419   tofresgood->GetXaxis()->SetTitle("t_{TOF}-t_{0}-t_{exp #pi} (ps)");
420   TOFCheck->AddLast(tofresgood);
421
422   //PT
423
424   hNumMatch=new TH1F("hNumMatch","",46,fBinLim0);
425   hNumMatch->Sumw2();
426   TOFCheck->AddLast(hNumMatch);
427   hNumMatchPos=new TH1F("hNumMatchPos","",46,fBinLim0);
428   hNumMatchPos->Sumw2();
429   TOFCheck->AddLast(hNumMatchPos);
430   hNumMatchNeg=new TH1F("hNumMatchNeg","",46,fBinLim0);
431   hNumMatchNeg->Sumw2();
432   TOFCheck->AddLast(hNumMatchNeg);
433   hDenMatch=new TH1F("hDenMatch","",46,fBinLim0);
434   hDenMatch->Sumw2();
435   TOFCheck->AddLast(hDenMatch);
436   hDenMatchPos=new TH1F("hDenMatchPos","",46,fBinLim0);
437   hDenMatchPos->Sumw2();
438   TOFCheck->AddLast(hDenMatchPos);
439   hDenMatchNeg=new TH1F("hDenMatchNeg","",46,fBinLim0);
440   hDenMatchNeg->Sumw2();
441   TOFCheck->AddLast(hDenMatchNeg);
442
443   //PT per SPECIE
444   
445   hNumMatchPip=new TH1F("hNumMatchPip","",46,fBinLim0);
446   hNumMatchPip->Sumw2();
447   TOFCheck->AddLast(hNumMatchPip);
448   hNumMatchPim=new TH1F("hNumMatchPim","",46,fBinLim0);
449   hNumMatchPim->Sumw2();
450   TOFCheck->AddLast(hNumMatchPim);
451   hNumMatchKap=new TH1F("hNumMatchKap","",46,fBinLim0);
452   hNumMatchKap->Sumw2();
453   TOFCheck->AddLast(hNumMatchKap);
454   hNumMatchKam=new TH1F("hNumMatchKam","",46,fBinLim0);
455   hNumMatchKam->Sumw2();
456   TOFCheck->AddLast(hNumMatchKam);
457   hNumMatchPrp=new TH1F("hNumMatchPrp","",46,fBinLim0);
458   hNumMatchPrp->Sumw2();
459   TOFCheck->AddLast(hNumMatchPrp);
460   hNumMatchPrm=new TH1F("hNumMatchPrm","",46,fBinLim0);
461   hNumMatchPrm->Sumw2();
462   TOFCheck->AddLast(hNumMatchPrm);
463
464   hDenMatchPip=new TH1F("hDenMatchPip","",46,fBinLim0);
465   hDenMatchPip->Sumw2();
466   TOFCheck->AddLast(hDenMatchPip);
467   hDenMatchPim=new TH1F("hDenMatchPim","",46,fBinLim0);
468   hDenMatchPim->Sumw2();
469   TOFCheck->AddLast(hDenMatchPim);
470   hDenMatchKap=new TH1F("hDenMatchKap","",46,fBinLim0);
471   hDenMatchKap->Sumw2();
472   TOFCheck->AddLast(hDenMatchKap);
473   hDenMatchKam=new TH1F("hDenMatchKam","",46,fBinLim0);
474   hDenMatchKam->Sumw2();
475   TOFCheck->AddLast(hDenMatchKam);
476   hDenMatchPrp=new TH1F("hDenMatchPrp","",46,fBinLim0);
477   hDenMatchPrp->Sumw2();
478   TOFCheck->AddLast(hDenMatchPrp);
479   hDenMatchPrm=new TH1F("hDenMatchPrm","",46,fBinLim0);
480   hDenMatchPrm->Sumw2();
481   TOFCheck->AddLast(hDenMatchPrm);
482
483
484   //ETA
485
486   
487   hNumMatchEta=new TH1F("hNumMatchEta","",36,-0.9,0.9);
488   hNumMatchEta->Sumw2();
489   TOFCheck->AddLast(hNumMatchEta);
490   hNumMatchPosEta=new TH1F("hNumMatchPosEta","",36,-0.9,0.9);
491   hNumMatchPosEta->Sumw2();
492   TOFCheck->AddLast(hNumMatchPosEta);
493   hNumMatchNegEta=new TH1F("hNumMatchNegEta","",36,-0.9,0.9);
494   hNumMatchNegEta->Sumw2();
495   TOFCheck->AddLast(hNumMatchNegEta);
496   hDenMatchEta=new TH1F("hDenMatchEta","",36,-0.9,0.9);
497   hDenMatchEta->Sumw2();
498   TOFCheck->AddLast(hDenMatchEta);
499   hDenMatchPosEta=new TH1F("hDenMatchPosEta","",36,-0.9,0.9);
500   hDenMatchPosEta->Sumw2();
501   TOFCheck->AddLast(hDenMatchPosEta);
502   hDenMatchNegEta=new TH1F("hDenMatchNegEta","",36,-0.9,0.9);
503   hDenMatchNegEta->Sumw2();
504   TOFCheck->AddLast(hDenMatchNegEta);
505
506   //PHI OUT
507
508   hNumMatchphiOut=new TH1F("hNumMatchphiOut","",18,0,360);
509   hNumMatchphiOut->Sumw2();
510   TOFCheck->AddLast(hNumMatchphiOut);
511   hNumMatchPosphiOut=new TH1F("hNumMatchPosphiOut","",18,0,360);
512   hNumMatchPosphiOut->Sumw2();
513   TOFCheck->AddLast(hNumMatchPosphiOut);
514   hNumMatchNegphiOut=new TH1F("hNumMatchNegphiOut","",18,0,360);
515   hNumMatchNegphiOut->Sumw2();
516   TOFCheck->AddLast(hNumMatchNegphiOut);
517   hDenMatchphiOut=new TH1F("hDenMatchphiOut","",18,0,360);
518   hDenMatchphiOut->Sumw2();
519   TOFCheck->AddLast(hDenMatchphiOut);
520   hDenMatchPosphiOut=new TH1F("hDenMatchPosphiOut","",18,0,360);
521   hDenMatchPosphiOut->Sumw2();
522   TOFCheck->AddLast(hDenMatchPosphiOut);
523   hDenMatchNegphiOut=new TH1F("hDenMatchNegphiOut","",18,0,360);
524   hDenMatchNegphiOut->Sumw2();
525   TOFCheck->AddLast(hDenMatchNegphiOut);
526
527   //ETA pt>0.5
528
529   hNumMatchEtaPtMa=new TH1F("hNumMatchEtaPtMa","",36,-0.9,0.9);
530   hNumMatchEtaPtMa->Sumw2();
531   TOFCheck->AddLast(hNumMatchEtaPtMa);
532   hNumMatchPosEtaPtMa=new TH1F("hNumMatchPosEtaPtMa","",36,-0.9,0.9);
533   hNumMatchPosEtaPtMa->Sumw2();
534   TOFCheck->AddLast(hNumMatchPosEtaPtMa);
535   hNumMatchNegEtaPtMa=new TH1F("hNumMatchNegEtaPtMa","",36,-0.9,0.9);
536   hNumMatchNegEtaPtMa->Sumw2();
537   TOFCheck->AddLast(hNumMatchNegEtaPtMa);
538   hDenMatchEtaPtMa=new TH1F("hDenMatchEtaPtMa","",36,-0.9,0.9);
539   hDenMatchEtaPtMa->Sumw2();
540   TOFCheck->AddLast(hDenMatchEtaPtMa);
541   hDenMatchPosEtaPtMa=new TH1F("hDenMatchPosEtaPtMa","",36,-0.9,0.9);
542   hDenMatchPosEtaPtMa->Sumw2();
543   TOFCheck->AddLast(hDenMatchPosEtaPtMa);
544   hDenMatchNegEtaPtMa=new TH1F("hDenMatchNegEtaPtMa","",36,-0.9,0.9);
545   hDenMatchNegEtaPtMa->Sumw2();
546   TOFCheck->AddLast(hDenMatchNegEtaPtMa);
547
548   //PHI OUT pt>0.5
549
550   hNumMatchphiOutPtMa=new TH1F("hNumMatchphiOutPtMa","",18,0,360);
551   hNumMatchphiOutPtMa->Sumw2();
552   TOFCheck->AddLast(hNumMatchphiOutPtMa);
553   hNumMatchPosphiOutPtMa=new TH1F("hNumMatchPosphiOutPtMa","",18,0,360);
554   hNumMatchPosphiOutPtMa->Sumw2();
555   TOFCheck->AddLast(hNumMatchPosphiOutPtMa);
556   hNumMatchNegphiOutPtMa=new TH1F("hNumMatchNegphiOutPtMa","",18,0,360);
557   hNumMatchNegphiOutPtMa->Sumw2();
558   TOFCheck->AddLast(hNumMatchNegphiOutPtMa);
559   hDenMatchphiOutPtMa=new TH1F("hDenMatchphiOutPtMa","",18,0,360);
560   hDenMatchphiOutPtMa->Sumw2();
561   TOFCheck->AddLast(hDenMatchphiOutPtMa);
562   hDenMatchPosphiOutPtMa=new TH1F("hDenMatchPosphiOutPtMa","",18,0,360);
563   hDenMatchPosphiOutPtMa->Sumw2();
564   TOFCheck->AddLast(hDenMatchPosphiOutPtMa);
565   hDenMatchNegphiOutPtMa=new TH1F("hDenMatchNegphiOutPtMa","",18,0,360);
566   hDenMatchNegphiOutPtMa->Sumw2();
567   TOFCheck->AddLast(hDenMatchNegphiOutPtMa);
568  
569   //TRD OUT
570
571   hNumMatchTRDOut=new TH1F("hNumMatchTRDOut","",46,fBinLim0);
572   hNumMatchTRDOut->Sumw2();
573   TOFCheck->AddLast(hNumMatchTRDOut);
574   hNumMatchPosTRDOut=new TH1F("hNumMatchPosTRDOut","",46,fBinLim0);
575   hNumMatchPosTRDOut->Sumw2();
576   TOFCheck->AddLast(hNumMatchPosTRDOut);
577   hNumMatchNegTRDOut=new TH1F("hNumMatchNegTRDOut","",46,fBinLim0);
578   hNumMatchNegTRDOut->Sumw2();
579   TOFCheck->AddLast(hNumMatchNegTRDOut);
580   hDenMatchTRDOut=new TH1F("hDenMatchTRDOut","",46,fBinLim0);
581   hDenMatchTRDOut->Sumw2();
582   TOFCheck->AddLast(hDenMatchTRDOut);
583   hDenMatchPosTRDOut=new TH1F("hDenMatchPosTRDOut","",46,fBinLim0);
584   hDenMatchPosTRDOut->Sumw2();
585   TOFCheck->AddLast(hDenMatchPosTRDOut);
586   hDenMatchNegTRDOut=new TH1F("hDenMatchNegTRDOut","",46,fBinLim0);
587   hDenMatchNegTRDOut->Sumw2();
588   TOFCheck->AddLast(hDenMatchNegTRDOut);
589
590   hNumMatchNoTRDOut=new TH1F("hNumMatchNoTRDOut","",46,fBinLim0);
591   hNumMatchNoTRDOut->Sumw2();
592   TOFCheck->AddLast(hNumMatchNoTRDOut);
593   hNumMatchPosNoTRDOut=new TH1F("hNumMatchPosNoTRDOut","",46,fBinLim0);
594   hNumMatchPosNoTRDOut->Sumw2();
595   TOFCheck->AddLast(hNumMatchPosNoTRDOut);
596   hNumMatchNegNoTRDOut=new TH1F("hNumMatchNegNoTRDOut","",46,fBinLim0);
597   hNumMatchNegNoTRDOut->Sumw2();
598   TOFCheck->AddLast(hNumMatchNegNoTRDOut);
599   hDenMatchNoTRDOut=new TH1F("hDenMatchNoTRDOut","",46,fBinLim0);
600   hDenMatchNoTRDOut->Sumw2();
601   TOFCheck->AddLast(hDenMatchNoTRDOut);
602   hDenMatchPosNoTRDOut=new TH1F("hDenMatchPosNoTRDOut","",46,fBinLim0);
603   hDenMatchPosNoTRDOut->Sumw2();
604   TOFCheck->AddLast(hDenMatchPosNoTRDOut);
605   hDenMatchNegNoTRDOut=new TH1F("hDenMatchNegNoTRDOut","",46,fBinLim0);
606   hDenMatchNegNoTRDOut->Sumw2();
607   TOFCheck->AddLast(hDenMatchNegNoTRDOut);
608
609   //confronto con TPC
610
611   hNumMatchTPCpip=new TH1F("hNumMatchTPCpip","",46,fBinLim0);
612   hNumMatchTPCpip->Sumw2();
613   TOFCheck->AddLast(hNumMatchTPCpip);
614   hNumMatchTPCkap=new TH1F("hNumMatchTPCkap","",46,fBinLim0);
615   hNumMatchTPCkap->Sumw2();
616   TOFCheck->AddLast(hNumMatchTPCkap);
617   hNumMatchTPCprp=new TH1F("hNumMatchTPCprp","",46,fBinLim0);
618   hNumMatchTPCprp->Sumw2();
619   TOFCheck->AddLast(hNumMatchTPCprp);
620   
621   hDenMatchTPCpip=new TH1F("hDenMatchTPCpip","",46,fBinLim0);
622   hDenMatchTPCpip->Sumw2();
623   TOFCheck->AddLast(hDenMatchTPCpip);
624   hDenMatchTPCkap=new TH1F("hDenMatchTPCkap","",46,fBinLim0);
625   hDenMatchTPCkap->Sumw2();
626   TOFCheck->AddLast(hDenMatchTPCkap);
627   hDenMatchTPCprp=new TH1F("hDenMatchTPCprp","",46,fBinLim0);
628   hDenMatchTPCprp->Sumw2();
629   TOFCheck->AddLast(hDenMatchTPCprp);
630
631   hNumMatchTPCpim=new TH1F("hNumMatchTPCpim","",46,fBinLim0);
632   hNumMatchTPCpim->Sumw2();
633   TOFCheck->AddLast(hNumMatchTPCpim);
634   hNumMatchTPCkam=new TH1F("hNumMatchTPCkam","",46,fBinLim0);
635   hNumMatchTPCkam->Sumw2();
636   TOFCheck->AddLast(hNumMatchTPCkam);
637   hNumMatchTPCprm=new TH1F("hNumMatchTPCprm","",46,fBinLim0);
638   hNumMatchTPCprm->Sumw2();
639   TOFCheck->AddLast(hNumMatchTPCprm);
640   
641   hDenMatchTPCpim=new TH1F("hDenMatchTPCpim","",46,fBinLim0);
642   hDenMatchTPCpim->Sumw2();
643   TOFCheck->AddLast(hDenMatchTPCpim);
644   hDenMatchTPCkam=new TH1F("hDenMatchTPCkam","",46,fBinLim0);
645   hDenMatchTPCkam->Sumw2();
646   TOFCheck->AddLast(hDenMatchTPCkam);
647   hDenMatchTPCprm=new TH1F("hDenMatchTPCprm","",46,fBinLim0);
648   hDenMatchTPCprm->Sumw2();
649   TOFCheck->AddLast(hDenMatchTPCprm);
650
651
652   //selected events
653   hNumEv=new TH1F("NumEv","NumEv",4,1,5);
654   TOFCheck->AddLast(hNumEv);
655
656
657   
658   //efficiency
659   for(Int_t mult=0; mult<7;mult++){
660     for(Int_t part=0; part<2;part++){
661       hNumMatchMultTrkInc[mult][part]=new TH1F(Form("hNumMatch_Inc_MultTrk%i_Charge%i",mult,part),"",46,fBinLim0);
662       hNumMatchMultTrkInc[mult][part]->Sumw2();
663       TOFCheck->AddLast(hNumMatchMultTrkInc[mult][part]);
664       hDenMatchMultTrkInc[mult][part]=new TH1F(Form("hDenMatch_Inc_MultTrk%i_Charge%i",mult,part),"",46,fBinLim0);
665       hDenMatchMultTrkInc[mult][part]->Sumw2();
666       TOFCheck->AddLast(hDenMatchMultTrkInc[mult][part]);
667     }
668   }
669   
670
671   for(Int_t mult=0; mult<7;mult++){
672     for(Int_t part=0; part<6;part++){
673       hNumMatchMultTrk[mult][part]=new TH1F(Form("hNumMatch_MultTrk%i_Part%i",mult,part),"",46,fBinLim0);
674       hNumMatchMultTrk[mult][part]->Sumw2();
675       TOFCheck->AddLast(hNumMatchMultTrk[mult][part]);
676       hDenMatchMultTrk[mult][part]=new TH1F(Form("hDenMatch_MultTrk%i_Part%i",mult,part),"",46,fBinLim0);
677       hDenMatchMultTrk[mult][part]->Sumw2();
678       TOFCheck->AddLast(hDenMatchMultTrk[mult][part]);
679       hDenTrkMultTrk[mult][part]=new TH1F(Form("hDenTrk_MultTrk%i_Part%i",mult,part),"",46,fBinLim0);
680       hDenTrkMultTrk[mult][part]->Sumw2();
681       TOFCheck->AddLast(hDenTrkMultTrk[mult][part]);
682     }
683   }
684   
685
686    for(Int_t mult=0; mult<7;mult++){
687     for(Int_t part=0; part<6;part++){
688       hNumMatchMultTrkTRDOut[mult][part]=new TH1F(Form("hNumMatch_MultTrk%i_Part%iTRDOut",mult,part),"",46,fBinLim0);
689       hNumMatchMultTrkTRDOut[mult][part]->Sumw2();
690       TOFCheck->AddLast(hNumMatchMultTrkTRDOut[mult][part]);
691       hDenMatchMultTrkTRDOut[mult][part]=new TH1F(Form("hDenMatch_MultTrk%i_Part%iTRDOut",mult,part),"",46,fBinLim0);
692       hDenMatchMultTrkTRDOut[mult][part]->Sumw2();
693       TOFCheck->AddLast(hDenMatchMultTrkTRDOut[mult][part]);
694       hDenTrkMultTrkTRDOut[mult][part]=new TH1F(Form("hDenTrk_MultTrk%i_Part%iTRDOut",mult,part),"",46,fBinLim0);
695       hDenTrkMultTrkTRDOut[mult][part]->Sumw2();
696       TOFCheck->AddLast(hDenTrkMultTrkTRDOut[mult][part]);
697     }
698   }
699
700      for(Int_t mult=0; mult<7;mult++){
701     for(Int_t part=0; part<6;part++){
702       hNumMatchMultTrkNoTRDOut[mult][part]=new TH1F(Form("hNumMatch_MultTrk%i_Part%iNoTRDOut",mult,part),"",46,fBinLim0);
703       hNumMatchMultTrkNoTRDOut[mult][part]->Sumw2();
704       TOFCheck->AddLast(hNumMatchMultTrkNoTRDOut[mult][part]);
705       hDenMatchMultTrkNoTRDOut[mult][part]=new TH1F(Form("hDenMatch_MultTrk%i_Part%iNoTRDOut",mult,part),"",46,fBinLim0);
706       hDenMatchMultTrkNoTRDOut[mult][part]->Sumw2();
707       TOFCheck->AddLast(hDenMatchMultTrkNoTRDOut[mult][part]);
708       hDenTrkMultTrkNoTRDOut[mult][part]=new TH1F(Form("hDenTrk_MultTrk%i_Part%iNoTRDOut",mult,part),"",46,fBinLim0);
709       hDenTrkMultTrkNoTRDOut[mult][part]->Sumw2();
710       TOFCheck->AddLast(hDenTrkMultTrkNoTRDOut[mult][part]);
711     }
712   }
713
714   for(Int_t mult=0; mult<7;mult++){
715     for(Int_t part=0; part<2;part++){
716       hNumMatchMultSPDInc[mult][part]=new TH1F(Form("hNumMatch_Inc_MultSPD%i_Charge%i",mult,part),"",46,fBinLim0);
717       hNumMatchMultSPDInc[mult][part]->Sumw2();
718       TOFCheck->AddLast(hNumMatchMultSPDInc[mult][part]);
719       hDenMatchMultSPDInc[mult][part]=new TH1F(Form("hDenMatch_Inc_MultSPD%i_Charge%i",mult,part),"",46,fBinLim0);
720       hDenMatchMultSPDInc[mult][part]->Sumw2();
721       TOFCheck->AddLast(hDenMatchMultSPDInc[mult][part]);
722     }
723   }
724
725   for(Int_t mult=0; mult<7;mult++){
726     for(Int_t part=0; part<6;part++){
727       hNumMatchMultSPD[mult][part]=new TH1F(Form("hNumMatch_MultSPD%i_Part%i",mult,part),"",46,fBinLim0);
728       hNumMatchMultSPD[mult][part]->Sumw2();
729       TOFCheck->AddLast(hNumMatchMultSPD[mult][part]);
730       hDenMatchMultSPD[mult][part]=new TH1F(Form("hDenMatch_MultSPD%i_Part%i",mult,part),"",46,fBinLim0);
731       hDenMatchMultSPD[mult][part]->Sumw2();
732       TOFCheck->AddLast(hDenMatchMultSPD[mult][part]);
733       hDenTrkMultSPD[mult][part]=new TH1F(Form("hDenTrk_MultSPD%i_Part%i",mult,part),"",46,fBinLim0);
734       hDenTrkMultSPD[mult][part]->Sumw2();
735       TOFCheck->AddLast(hDenTrkMultSPD[mult][part]);
736     }
737   }
738
739   for(Int_t part=0; part<6;part++){
740     hDenTrkVertMultTrk[part]=new TH1F(Form("hDenTrkVert_Part%i",part),"",46,fBinLim0);
741     hDenTrkVertMultTrk[part]->Sumw2();
742     TOFCheck->AddLast(hDenTrkVertMultTrk[part]);
743
744   }
745   
746   for(Int_t part=0; part<6;part++){
747     hDenTrkTriggerMultTrk[part]=new TH1F(Form("hDenTrkTrigger_Part%i",part),"",46,fBinLim0);
748     hDenTrkTriggerMultTrk[part]->Sumw2();
749     TOFCheck->AddLast(hDenTrkTriggerMultTrk[part]);
750   }
751   
752   PostData(1, TOFCheck);
753
754 }
755
756 //________________________________________________________________________
757 void AliAnalysisCombinedHadronSpectra2MC::UserExec(Option_t *) 
758 {
759   //
760   // main event loop
761   //
762  
763   
764   multiplicity=-999, vert=-999, XPrimVertex=-999, YPrimVertex=-999, ZPrimVertex=-999, NContrPrimVertex=-999, fMCtracks=-999, fMCPrimaries=-999, spdCorr=-1.0;
765   fT0TOF0=-999, fT0TOF1=-999, fT0TOF2=-999, fT0TOF3=-999, fT0TOF4=-999, fT0TOF5=-999, fT0TOF6=-999, fT0TOF7=-999, frun=-999;
766   
767   fESD = dynamic_cast<AliESDEvent*>( InputEvent() );
768   if (!fESD) {
769     Printf("ERROR: fESD not available");
770     return;
771   }
772   
773   if (!fESDtrackCuts) {
774     Printf("ERROR: fESDtrackCuts not available");
775     return;
776   }
777   
778   hNumEv->Fill(1);
779   
780   AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
781   if (!eventHandler) {
782     Printf("ERROR: Could not retrieve MC event handler");
783     return;
784   }
785   
786   AliESDInputHandler* esdH = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
787   if (esdH)
788     fESDpid = esdH->GetESDpid();
789   
790   AliMCEvent* mcEvent = 0x0;
791   AliStack* stack = 0x0;
792   if (eventHandler) mcEvent = eventHandler->MCEvent();
793   if (!mcEvent) {
794     Printf("ERROR: Could not retrieve MC event");
795     return;
796   }
797   
798   stack = mcEvent->Stack();
799   if (!stack) return;
800
801   //
802   // check if event is selected by physics selection class
803   //
804
805   //trigger efficiency correction
806   //loop on primary MC tracks
807   for(Int_t i = 0; i < stack->GetNtrack(); i++) {
808     treeMCPBis=-999; treeMCPtBis=-999; treeMCEtaBis=-999; treeMCPhiBis=-999; treeMCPdgBis=-999;    
809     if (!stack->IsPhysicalPrimary(i)) continue;
810     TParticle * trackMC = stack->Particle(i);
811     //Double_t rapidityMC=-999;
812     
813     treeMCPBis=trackMC->P();
814     treeMCPtBis=trackMC->Pt();
815     treeMCEtaBis=trackMC->Eta();
816     //if(TMath::Abs(treeMCEtaBis)>=0.9){continue;}
817     treeMCPhiBis=trackMC->Phi()* 180 / TMath::Pi();
818     treeMCPdgBis = trackMC->GetPdgCode();
819     if(TMath::Abs(trackMC->Y())>=0.5) {continue;}
820     if((TMath::Abs(treeMCPdgBis)!=211)&&(TMath::Abs(treeMCPdgBis)!=321)&&(TMath::Abs(treeMCPdgBis)!=2212)){continue;}
821   
822     Int_t PartTypeMC=-5;
823     if((TMath::Abs(treeMCPdgBis)==211)&&(treeMCPdgBis>0)){PartTypeMC=0;}
824     if((TMath::Abs(treeMCPdgBis)==211)&&(treeMCPdgBis<0)){PartTypeMC=1;}
825     if((TMath::Abs(treeMCPdgBis)==321)&&(treeMCPdgBis>0)){PartTypeMC=2;}
826     if((TMath::Abs(treeMCPdgBis)==321)&&(treeMCPdgBis<0)){PartTypeMC=3;}
827     if((TMath::Abs(treeMCPdgBis)==2212)&&(treeMCPdgBis>0)){PartTypeMC=4;}
828     if((TMath::Abs(treeMCPdgBis)==2212)&&(treeMCPdgBis<0)){PartTypeMC=5;}
829   
830
831     //fill Histo
832     hDenTrkTriggerMultTrk[PartTypeMC]->Fill(treeMCPtBis);    
833
834   }  
835
836
837
838   Bool_t isSelected = kFALSE;
839   isSelected = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected()& AliVEvent::kMB);
840
841   if (!isSelected) {
842     return;
843   }
844   
845   hNumEv->Fill(2);
846   
847   
848   
849   //vertex efficiency correction+senza taglio in eta
850   //loop on primary MC tracks
851   for(Int_t i = 0; i < stack->GetNtrack(); i++) {
852     treeMCPBis=-999; treeMCPtBis=-999; treeMCEtaBis=-999; treeMCPhiBis=-999; treeMCPdgBis=-999;    
853     if (!stack->IsPhysicalPrimary(i)) continue;
854     TParticle * trackMC = stack->Particle(i);
855     //Double_t rapidityMC=-999;
856     
857     treeMCPBis=trackMC->P();
858     treeMCPtBis=trackMC->Pt();
859     treeMCEtaBis=trackMC->Eta();
860     //if(TMath::Abs(treeMCEtaBis)>=0.9){continue;}
861     treeMCPhiBis=trackMC->Phi()* 180 / TMath::Pi();
862     treeMCPdgBis = trackMC->GetPdgCode();
863     if(TMath::Abs(trackMC->Y())>=0.5) {continue;}
864     if((TMath::Abs(treeMCPdgBis)!=211)&&(TMath::Abs(treeMCPdgBis)!=321)&&(TMath::Abs(treeMCPdgBis)!=2212)){continue;}
865   
866     Int_t PartTypeMC=-5;
867     if((TMath::Abs(treeMCPdgBis)==211)&&(treeMCPdgBis>0)){PartTypeMC=0;}
868     if((TMath::Abs(treeMCPdgBis)==211)&&(treeMCPdgBis<0)){PartTypeMC=1;}
869     if((TMath::Abs(treeMCPdgBis)==321)&&(treeMCPdgBis>0)){PartTypeMC=2;}
870     if((TMath::Abs(treeMCPdgBis)==321)&&(treeMCPdgBis<0)){PartTypeMC=3;}
871     if((TMath::Abs(treeMCPdgBis)==2212)&&(treeMCPdgBis>0)){PartTypeMC=4;}
872     if((TMath::Abs(treeMCPdgBis)==2212)&&(treeMCPdgBis<0)){PartTypeMC=5;}
873   
874
875     //fill Histo
876     hDenTrkVertMultTrk[PartTypeMC]->Fill(treeMCPtBis);    
877
878   }     
879        
880  
881
882
883   //
884   // monitor vertex position
885   //
886   const AliESDVertex *vertex = fESD->GetPrimaryVertexTracks(); //! Primary vertex estimated using ESD tracks
887   if(vertex->GetNContributors()<1) { // # of tracklets/tracks used for the estimate
888     // SPD vertex
889     vertex = fESD->GetPrimaryVertexSPD(); //! Primary vertex estimated by the SPD
890     if(vertex->GetNContributors()<1) vertex = 0x0;
891   }  
892
893   if (!vertex) {
894     vert=0;
895   } else {vert=1;}
896
897   if (!vertex) {
898     return;
899   }
900
901   hNumEv->Fill(3);
902
903   
904   if (vertex) {ZPrimVertex=vertex->GetZv();}
905   if(TMath::Abs(ZPrimVertex)>10){return;}
906
907   hNumEv->Fill(4);
908   multiplicity=Mult();
909
910   fTreeEv->Fill();
911
912
913   if (vertex) {XPrimVertex=vertex->GetXv(); YPrimVertex=vertex->GetYv(); ZPrimVertex=vertex->GetZv(); NContrPrimVertex=vertex->GetNContributors(); 
914     vert=1;}  
915
916   //multiplicity as defined by Marek
917   const AliMultiplicity *mult = fESD->GetMultiplicity();
918   Float_t nClusters[6]={0.0,0.0,0.0,0.0,0.0,0.0};
919   for(Int_t ilay=0; ilay<6; ilay++)
920     {
921       nClusters[ilay] = (Float_t)mult->GetNumberOfITSClusters(ilay);
922     }
923   //cambio
924   spdCorr = AliESDUtils::GetCorrSPD2(nClusters[1],vertex->GetZ());
925   //spdCorr=50;
926   // end cambio
927   
928   Int_t imult=-5;
929   if((multiplicity>=0)&&(multiplicity<=5)){imult=1;}
930   if((multiplicity>=6)&&(multiplicity<=9)){imult=2;}
931   if((multiplicity>=10)&&(multiplicity<=14)){imult=3;}
932   if((multiplicity>=15)&&(multiplicity<=22)){imult=4;}
933   if((multiplicity>=23)&&(multiplicity<=32)){imult=5;}
934   if(multiplicity>=33){imult=6;}
935   
936   Int_t imultSPD=-5;
937   if((spdCorr>=0)&&(spdCorr<=16)){imultSPD=1;}
938   if((spdCorr>=17)&&(spdCorr<=30)){imultSPD=2;}
939   if((spdCorr>=31)&&(spdCorr<=45)){imultSPD=3;}
940   if((spdCorr>=46)&&(spdCorr<=68)){imultSPD=4;}
941   if((spdCorr>=69)&&(spdCorr<=97)){imultSPD=5;}
942   if(spdCorr>=98){imult=6;}
943
944   fMCtracks=mcEvent->GetNumberOfTracks();
945   fMCPrimaries=mcEvent->GetNumberOfPrimaries();
946   
947   
948   //cout<<"trk  "<<fMCtracks<<endl;
949   //cout<<"trk primaries  "<<fMCPrimaries<<endl;
950   
951   //  //TOF settings done in the TOF tender
952   
953   //   frun = fESD->GetRunNumber();
954   //   if(frun==frunOld){fLoadOCDB=kFALSE;}else {fLoadOCDB=kTRUE;}
955   //   //if (tuneTOFMC) calibrateESD = kFALSE;
956   //   Double_t *T0TOF;
957   //   if(fLoadOCDB){
958   //     AliCDBManager *cdb = AliCDBManager::Instance();
959   //     cdb->SetDefaultStorage("alien://folder=/alice/data/2010/OCDB");
960   //     //cdb->SetDefaultStorage("raw://");
961   //     cdb->SetRun(frun);}
962   
963   //   /* init TOF calibration */
964   //   if (correctTExp)
965   //     tofCalib->SetCorrectTExp(kTRUE);
966   
967   //   tofCalib->Init(frun);
968   
969   //   /* init TOF T0-maker */
970   //   t0maker->SetTimeResolution(timeResolution);
971   
972   //   /* calibrate ESD */
973   //   if (calibrateESD)
974   //     tofCalib->CalibrateESD(fESD);
975   
976   //   T0TOF=t0maker->ComputeT0TOF(fESD);// calcola il t0 solo col tof in 10 bin di pt e lo setta in AliTOFPidResponse 
977   
978   //   //scrive i valori precedenti nel TOFHeader
979   //   t0maker->WriteInESD(fESD); 
980   
981   //   //setta T0_TOF in AliTOFPidResponse ovvero i valori settati in AliTOFHeader. Se non ci sono setta T0spread
982   //   fTimeZeroType=AliESDpid::kTOF_T0;
983   
984   //   fESDpid->SetTOFResponse(fESD,(AliESDpid::EStartTimeType_t)fTimeZeroType);
985   
986   
987   //   fESDpid->MakePID(fESD,kFALSE); //calcola la sigma e le gi in piĆ¹ definisce la flag kTOFmismatch
988   
989
990   
991   
992
993 //   fT0TOF0=T0TOF[0];
994 //   fT0TOF1=T0TOF[1];
995 //   fT0TOF2=T0TOF[2];
996 //   fT0TOF3=T0TOF[3];
997 //   fT0TOF4=T0TOF[4];
998 //   fT0TOF5=T0TOF[5];
999 //   fT0TOF6=T0TOF[6];
1000 //   fT0TOF7=T0TOF[7];
1001  
1002   //
1003   // track loop
1004   //
1005   
1006   
1007   for (Int_t i=0;i<fESD->GetNumberOfTracks();++i) {
1008     
1009     AliESDtrack *track =fESD->GetTrack(i); 
1010     if (!track){continue;}
1011     // start TOF analysis
1012     
1013     rapidityMC=-999, fDCAXY=-999, fDCAZ=-999, fcut=-999, fTOFout=-999, ftrdout=-999, ftime=-999, ftpcclust=-999, flength=-999, fsign=-999, ftimetof=-999, ftofchan=-999, feta=-999, fphi=-999, fmomtrasv=-999,sigmapi=-999, sigmaka=-999, sigmapr=-999, fTot=-999, fmom=-999, fexptimepi=-999, fexptimeka=-999, fexptimepr=-999, ftofz=-999,ftofx=-999, TPCSignal=-999, TPCSigmaPI=-999, TPCSigmaKA=-999, TPCSigmaPR=-999, r1[0]=-999,r1[1]=-999,r1[2]=-999,r1[3]=-999,r1[4]=-999, fmatch=-999, fXout=-999, fYout=-999, fZout=-999, fPhiout=-999;
1014     
1015
1016     if (!fESDtrackCuts->AcceptTrack(track)) {continue;}
1017     if (!(track->GetStatus()&AliESDtrack::kTOFout)==0) {fTOFout=1;}else {fTOFout=0;}
1018     if (!(track->GetStatus()&AliESDtrack::kTIME)==0) {ftime=1;}else {ftime=0;}  
1019     if (!(track->GetStatus()&AliESDtrack::kTRDout)==0) {ftrdout=1;}else {ftrdout=0;}  
1020     if (!(track->GetStatus()&AliESDtrack::kTOFmismatch)==0) {fmatch=0;}else {fmatch=1;}  
1021     track->GetImpactParameters(fDCAXY, fDCAZ);
1022
1023     track->GetTOFpid(r1);
1024     fmomtrasv=track->Pt(); 
1025     feta=track->Eta();// return pseudorapidity return -TMath::Log(TMath::Tan(0.5 * Theta())); 
1026     if(!(TMath::Abs(feta)<0.9))continue;
1027     
1028     fmom=track->GetP();  // This function returns the track momentum
1029     Double_t *trackT0;
1030     // trackT0 = t0maker->GetT0p(fmom);// [0]=to -- [1] = sigma T0
1031 //     fT0meas=trackT0[0]; 
1032 //     fT0sigma=trackT0[1];
1033     ftpcclust=track->GetNcls(1);
1034     flength=track->GetIntegratedLength();
1035     fsign=track->GetSign();
1036     ftimetof=track->GetTOFsignal();
1037     Double_t inttime[5]; 
1038     track->GetIntegratedTimes(inttime);// Returns the array with integrated times for each particle hypothesis
1039     fexptimepi=inttime[2];
1040     fexptimeka=inttime[3];
1041     fexptimepr=inttime[4];
1042
1043     fTot = track->GetTOFsignalToT();
1044     ftofz=track->GetTOFsignalDz(); // local z  of track's impact on the TOF pad 
1045     ftofx=track->GetTOFsignalDx(); // local x  of track's impact on the TOF pad 
1046     ftofchan=track->GetTOFCalChannel(); // Channel Index of the TOF Signal
1047     
1048     fphi=track->Phi()* 180 / TMath::Pi();// Returns the azimuthal angle of momentum  0 <= phi < 2*pi
1049     Double_t sigma[5];
1050     t0track = fESDpid->GetTOFResponse().GetStartTime(fmom); // T0best time
1051     t0trackSigma = fESDpid->GetTOFResponse().GetStartTimeRes(fmom); // T0best time
1052
1053     for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++){
1054       sigma[ipart] = fESDpid->GetTOFResponse().GetExpectedSigma(fmom, inttime[ipart], AliPID::ParticleMass(ipart));}
1055     sigmapi=sigma[2];
1056     sigmaka=sigma[3];
1057     sigmapr=sigma[4];
1058     TPCSignal = track->GetTPCsignal();
1059     TPCSigmaPI=fESDpid->NumberOfSigmasTPC(track,AliPID::kPion);
1060     TPCSigmaKA=fESDpid->NumberOfSigmasTPC(track,AliPID::kKaon);
1061     TPCSigmaPR=fESDpid->NumberOfSigmasTPC(track,AliPID::kProton);
1062
1063     AliExternalTrackParam *exttrack=(AliExternalTrackParam *)track->GetOuterParam();
1064     if(exttrack){
1065     fPhiout=exttrack->Phi();
1066     fXout=exttrack->GetX();
1067     fYout=exttrack->GetY();
1068     fZout=exttrack->GetZ();}
1069
1070     //start to take MC data
1071     Int_t flab=0;
1072     flab=track->GetLabel(); /*The Get*Label() getters return the label of the associated MC particle. The absolute value of this label is the index of the particle within the MC stack. If the label is negative, this track was assigned a certain number of clusters that did not in fact belong to this track. */
1073     Int_t abslab=TMath::Abs(flab);
1074     AliMCParticle *MCpart =(AliMCParticle* ) mcEvent->GetTrack(abslab);
1075     if(MCpart){
1076       TParticle *part = MCpart->Particle();
1077       if(part){
1078         fptMC=part->Pt();
1079         fphiMC=part->Phi()* 180 / TMath::Pi(); //angolo tra 0 e 2pi
1080         fetaMC=part->Eta();
1081         fPdgcode = part->GetPdgCode();
1082       }
1083     }
1084
1085     //inizio plot match eff
1086     //numeratore
1087     
1088     if((TMath::Abs(TPCSigmaPI)<3)&&(TMath::Abs(TPCSigmaKA)>3)&&(TMath::Abs(TPCSigmaPR)>3)&&(fsign>0)){hDenMatchTPCpip->Fill(fmomtrasv);}
1089     if((TMath::Abs(TPCSigmaPI)>3)&&(TMath::Abs(TPCSigmaKA)<3)&&(TMath::Abs(TPCSigmaPR)>3)&&(fsign>0)){hDenMatchTPCkap->Fill(fmomtrasv);}
1090     if((TMath::Abs(TPCSigmaPI)>3)&&(TMath::Abs(TPCSigmaKA)>3)&&(TMath::Abs(TPCSigmaPR)<3)&&(fsign>0)){hDenMatchTPCprp->Fill(fmomtrasv);}
1091     if((TMath::Abs(TPCSigmaPI)<3)&&(TMath::Abs(TPCSigmaKA)>3)&&(TMath::Abs(TPCSigmaPR)>3)&&(fsign<0)){hDenMatchTPCpim->Fill(fmomtrasv);}
1092     if((TMath::Abs(TPCSigmaPI)>3)&&(TMath::Abs(TPCSigmaKA)<3)&&(TMath::Abs(TPCSigmaPR)>3)&&(fsign<0)){hDenMatchTPCkam->Fill(fmomtrasv);}
1093     if((TMath::Abs(TPCSigmaPI)>3)&&(TMath::Abs(TPCSigmaKA)>3)&&(TMath::Abs(TPCSigmaPR)<3)&&(fsign<0)){hDenMatchTPCprm->Fill(fmomtrasv);}
1094
1095     hDenMatch->Fill(fmomtrasv);
1096     if(fsign>0) hDenMatchPos->Fill(fmomtrasv);
1097     if(fsign<0) hDenMatchNeg->Fill(fmomtrasv);
1098     hDenMatchEta->Fill(feta);
1099     if(fsign>0) hDenMatchPosEta->Fill(feta);
1100     if(fsign<0) hDenMatchNegEta->Fill(feta);
1101
1102     if((TMath::Abs(fPdgcode)==211)&&(fsign>0)){hDenMatchPip->Fill(fmomtrasv);}
1103     if((TMath::Abs(fPdgcode)==211)&&(fsign<0)){hDenMatchPim->Fill(fmomtrasv);}
1104     if((TMath::Abs(fPdgcode)==321)&&(fsign>0)){hDenMatchKap->Fill(fmomtrasv);}
1105     if((TMath::Abs(fPdgcode)==321)&&(fsign<0)){hDenMatchKam->Fill(fmomtrasv);}
1106     if((TMath::Abs(fPdgcode)==2212)&&(fsign>0)){hDenMatchPrp->Fill(fmomtrasv);}
1107     if((TMath::Abs(fPdgcode)==2212)&&(fsign<0)){hDenMatchPrm->Fill(fmomtrasv);}
1108
1109     if(fmomtrasv>0.5){
1110       hDenMatchEtaPtMa->Fill(feta);
1111       if(fsign>0) hDenMatchPosEtaPtMa->Fill(feta);
1112       if(fsign<0) hDenMatchNegEtaPtMa->Fill(feta);
1113       hDenMatchphiOutPtMa->Fill(fPhiout*180/TMath::Pi());
1114       if(fsign>0) hDenMatchPosphiOutPtMa->Fill(fPhiout*180/TMath::Pi());
1115       if(fsign<0) hDenMatchNegphiOutPtMa->Fill(fPhiout*180/TMath::Pi());
1116     }
1117     //Int_t NSM=tofchan/8736;
1118     hDenMatchphiOut->Fill(fPhiout*180/TMath::Pi());
1119     if(fsign>0) hDenMatchPosphiOut->Fill(fPhiout*180/TMath::Pi());
1120     if(fsign<0) hDenMatchNegphiOut->Fill(fPhiout*180/TMath::Pi());
1121     
1122     if(ftrdout==1){
1123       hDenMatchTRDOut->Fill(fmomtrasv);
1124       if(fsign>0) hDenMatchPosTRDOut->Fill(fmomtrasv);
1125       if(fsign<0) hDenMatchNegTRDOut->Fill(fmomtrasv);
1126     }
1127
1128     if(ftrdout==0){
1129       hDenMatchNoTRDOut->Fill(fmomtrasv);
1130       if(fsign>0) hDenMatchPosNoTRDOut->Fill(fmomtrasv);
1131       if(fsign<0) hDenMatchNegNoTRDOut->Fill(fmomtrasv);
1132     }
1133
1134     //denominatore
1135     if((fTOFout==1)&&(ftime==1)&&(flength>350)&&(ftimetof>10000)&&(fexptimepi>10000)&&(fexptimeka>10000)&&(fexptimepr>10000)&&(ftimetof<80000)){
1136       
1137       if((TMath::Abs(TPCSigmaPI)<3)&&(TMath::Abs(TPCSigmaKA)>3)&&(TMath::Abs(TPCSigmaPR)>3)&&(fsign>0)){hNumMatchTPCpip->Fill(fmomtrasv);}
1138       if((TMath::Abs(TPCSigmaPI)>3)&&(TMath::Abs(TPCSigmaKA)<3)&&(TMath::Abs(TPCSigmaPR)>3)&&(fsign>0)){hNumMatchTPCkap->Fill(fmomtrasv);}
1139       if((TMath::Abs(TPCSigmaPI)>3)&&(TMath::Abs(TPCSigmaKA)>3)&&(TMath::Abs(TPCSigmaPR)<3)&&(fsign>0)){hNumMatchTPCprp->Fill(fmomtrasv);}
1140       if((TMath::Abs(TPCSigmaPI)<3)&&(TMath::Abs(TPCSigmaKA)>3)&&(TMath::Abs(TPCSigmaPR)>3)&&(fsign<0)){hNumMatchTPCpim->Fill(fmomtrasv);}
1141       if((TMath::Abs(TPCSigmaPI)>3)&&(TMath::Abs(TPCSigmaKA)<3)&&(TMath::Abs(TPCSigmaPR)>3)&&(fsign<0)){hNumMatchTPCkam->Fill(fmomtrasv);}
1142       if((TMath::Abs(TPCSigmaPI)>3)&&(TMath::Abs(TPCSigmaKA)>3)&&(TMath::Abs(TPCSigmaPR)<3)&&(fsign<0)){hNumMatchTPCprm->Fill(fmomtrasv);}
1143       
1144       hNumMatch->Fill(fmomtrasv);
1145       if(fsign>0) hNumMatchPos->Fill(fmomtrasv);
1146       if(fsign<0) hNumMatchNeg->Fill(fmomtrasv);
1147       hNumMatchEta->Fill(feta);
1148       if(fsign>0) hNumMatchPosEta->Fill(feta);
1149       if(fsign<0) hNumMatchNegEta->Fill(feta);
1150       
1151       if((TMath::Abs(fPdgcode)==211)&&(fsign>0)){hNumMatchPip->Fill(fmomtrasv);}
1152       if((TMath::Abs(fPdgcode)==211)&&(fsign<0)){hNumMatchPim->Fill(fmomtrasv);}
1153       if((TMath::Abs(fPdgcode)==321)&&(fsign>0)){hNumMatchKap->Fill(fmomtrasv);}
1154       if((TMath::Abs(fPdgcode)==321)&&(fsign<0)){hNumMatchKam->Fill(fmomtrasv);}
1155       if((TMath::Abs(fPdgcode)==2212)&&(fsign>0)){hNumMatchPrp->Fill(fmomtrasv);}
1156       if((TMath::Abs(fPdgcode)==2212)&&(fsign<0)){hNumMatchPrm->Fill(fmomtrasv);}
1157       
1158       if(fmomtrasv>0.5){
1159         hNumMatchEtaPtMa->Fill(feta);
1160         if(fsign>0) hNumMatchPosEtaPtMa->Fill(feta);
1161         if(fsign<0) hNumMatchNegEtaPtMa->Fill(feta);
1162         hNumMatchphiOutPtMa->Fill(fPhiout*180/TMath::Pi());
1163         if(fsign>0) hNumMatchPosphiOutPtMa->Fill(fPhiout*180/TMath::Pi());
1164         if(fsign<0) hNumMatchNegphiOutPtMa->Fill(fPhiout*180/TMath::Pi());
1165       }
1166       hNumMatchphiOut->Fill(fPhiout*180/TMath::Pi());
1167       if(fsign>0) hNumMatchPosphiOut->Fill(fPhiout*180/TMath::Pi());
1168       if(fsign<0) hNumMatchNegphiOut->Fill(fPhiout*180/TMath::Pi());
1169       
1170       if(ftrdout==1){
1171         hNumMatchTRDOut->Fill(fmomtrasv);
1172         if(fsign>0) hNumMatchPosTRDOut->Fill(fmomtrasv);
1173         if(fsign<0) hNumMatchNegTRDOut->Fill(fmomtrasv);
1174       }
1175       
1176       if(ftrdout==0){
1177         hNumMatchNoTRDOut->Fill(fmomtrasv);
1178         if(fsign>0) hNumMatchPosNoTRDOut->Fill(fmomtrasv);
1179         if(fsign<0) hNumMatchNegNoTRDOut->Fill(fmomtrasv);
1180       }
1181     }
1182     
1183     //fine plot test matching efficiency
1184
1185     pad->Fill(ftofx,ftofz);
1186     resx->Fill(ftofx);
1187     resz->Fill(ftofz);
1188     Float_t deltat;
1189     if((fmom>0.9)&&(fmom<1.1)){
1190       deltat=ftimetof-t0track-fexptimepi;
1191       tofres->Fill(deltat);
1192       if(t0track!=0){tofresTOF->Fill(deltat);}
1193       if((TMath::Abs(ftofx)<1.25)&&(TMath::Abs(ftofz)<1.75)){
1194         tofresgood->Fill(deltat);
1195       }
1196     }
1197     
1198     
1199     //inizio plot efficienze matching + tracking spettri
1200     Int_t ip=0;
1201     if(TMath::Abs(fPdgcode)==211){ip=2;}
1202     if(TMath::Abs(fPdgcode)==321){ip=3;}
1203     if(TMath::Abs(fPdgcode)==2212){ip=4;}
1204     if((ip!=2)&&(ip!=3)&&(ip!=4)){continue;}
1205
1206     Float_t mass;
1207     mass=AliPID::ParticleMass(ip);//GeV
1208     Double_t momlung;
1209     momlung=TMath::Sqrt(fmom*fmom-fmomtrasv*fmomtrasv);
1210     Double_t transvmass;
1211     transvmass=TMath::Sqrt(mass*mass+fmomtrasv*fmomtrasv);
1212     rapidityMC=TMath::ASinH(momlung/transvmass);
1213     if(rapidityMC>=0.5){continue;}
1214
1215
1216     Int_t PartType=-5;
1217     if((TMath::Abs(fPdgcode)==211)&&(fsign>0)){PartType=0;}
1218     if((TMath::Abs(fPdgcode)==211)&&(fsign<0)){PartType=1;}
1219     if((TMath::Abs(fPdgcode)==321)&&(fsign>0)){PartType=2;}
1220     if((TMath::Abs(fPdgcode)==321)&&(fsign<0)){PartType=3;}
1221     if((TMath::Abs(fPdgcode)==2212)&&(fsign>0)){PartType=4;}
1222     if((TMath::Abs(fPdgcode)==2212)&&(fsign<0)){PartType=5;}
1223
1224     Int_t Pos=-5;
1225     if((PartType==0)||(PartType==2)||(PartType==4)){Pos=0;}
1226     if((PartType==1)||(PartType==3)||(PartType==5)){Pos=1;}
1227      
1228     if((fTOFout==1)&&(ftime==1))
1229       {
1230         
1231         
1232         hNumMatchMultTrk[imult][PartType]->Fill(fmomtrasv);
1233         hNumMatchMultSPD[imultSPD][PartType]->Fill(fmomtrasv); 
1234         hNumMatchMultTrk[0][PartType]->Fill(fmomtrasv);
1235         hNumMatchMultSPD[0][PartType]->Fill(fmomtrasv); 
1236         
1237         hNumMatchMultTrkInc[imult][Pos]->Fill(fmomtrasv);
1238         hNumMatchMultSPDInc[imultSPD][Pos]->Fill(fmomtrasv); 
1239         hNumMatchMultTrkInc[0][Pos]->Fill(fmomtrasv);
1240         hNumMatchMultSPDInc[0][Pos]->Fill(fmomtrasv);
1241         
1242         if(ftrdout==1) {hNumMatchMultTrkTRDOut[0][PartType]->Fill(fmomtrasv);}
1243         if(ftrdout==0) {hNumMatchMultTrkNoTRDOut[0][PartType]->Fill(fmomtrasv);}
1244                 
1245       }
1246     
1247     hDenMatchMultTrk[imult][PartType]->Fill(fmomtrasv);
1248     hDenMatchMultSPD[imultSPD][PartType]->Fill(fmomtrasv); 
1249     hDenMatchMultTrk[0][PartType]->Fill(fmomtrasv);
1250     hDenMatchMultSPD[0][PartType]->Fill(fmomtrasv); 
1251     
1252     hDenMatchMultTrkInc[imult][Pos]->Fill(fmomtrasv);
1253     hDenMatchMultSPDInc[imultSPD][Pos]->Fill(fmomtrasv); 
1254     hDenMatchMultTrkInc[0][Pos]->Fill(fmomtrasv);
1255     hDenMatchMultSPDInc[0][Pos]->Fill(fmomtrasv);
1256
1257   
1258    
1259     
1260
1261     fTreeTrack->Fill(); 
1262     
1263     /*
1264       kTOFout = TOF matching
1265       kTIME = good integrated time
1266       100000 > track->GetTOFsignal() > 12000 = TOF time reasanble range
1267       tracklength > 365 = should be greater than the TOF radius (370 cm)
1268     */
1269     
1270    
1271     
1272   } // end of track loop
1273   
1274
1275    //secondo modo per trovare le primarie
1276   //loop on primary MC tracks
1277   for(Int_t i = 0; i < stack->GetNtrack(); i++) {
1278     treeMCPBis=-999; treeMCPtBis=-999; treeMCEtaBis=-999; treeMCPhiBis=-999; treeMCPdgBis=-999;    
1279     if (!stack->IsPhysicalPrimary(i)) continue;
1280     TParticle * trackMC = stack->Particle(i);
1281     //Double_t rapidityMC=-999;
1282     
1283     treeMCPBis=trackMC->P();
1284     treeMCPtBis=trackMC->Pt();
1285     treeMCEtaBis=trackMC->Eta();
1286     if(TMath::Abs(treeMCEtaBis)>=0.9){continue;}
1287     treeMCPhiBis=trackMC->Phi()* 180 / TMath::Pi();
1288     treeMCPdgBis = trackMC->GetPdgCode();
1289     if(TMath::Abs(trackMC->Y())>=0.5) {continue;}
1290     if((TMath::Abs(treeMCPdgBis)!=211)&&(TMath::Abs(treeMCPdgBis)!=321)&&(TMath::Abs(treeMCPdgBis)!=2212)){continue;}
1291   
1292     Int_t PartTypeMC=-5;
1293     if((TMath::Abs(treeMCPdgBis)==211)&&(treeMCPdgBis>0)){PartTypeMC=0;}
1294     if((TMath::Abs(treeMCPdgBis)==211)&&(treeMCPdgBis<0)){PartTypeMC=1;}
1295     if((TMath::Abs(treeMCPdgBis)==321)&&(treeMCPdgBis>0)){PartTypeMC=2;}
1296     if((TMath::Abs(treeMCPdgBis)==321)&&(treeMCPdgBis<0)){PartTypeMC=3;}
1297     if((TMath::Abs(treeMCPdgBis)==2212)&&(treeMCPdgBis>0)){PartTypeMC=4;}
1298     if((TMath::Abs(treeMCPdgBis)==2212)&&(treeMCPdgBis<0)){PartTypeMC=5;}
1299   
1300
1301     //fill Histo
1302     hDenTrkMultTrk[imult][PartTypeMC]->Fill(treeMCPtBis);
1303     hDenTrkMultSPD[imultSPD][PartTypeMC]->Fill(treeMCPtBis);
1304     hDenTrkMultTrk[0][PartTypeMC]->Fill(treeMCPtBis);
1305     hDenTrkMultSPD[0][PartTypeMC]->Fill(treeMCPtBis); 
1306     
1307
1308   }     
1309        
1310  
1311
1312
1313   frunOld=frun;
1314   
1315
1316 }      
1317
1318
1319 //________________________________________________________________________
1320 void AliAnalysisCombinedHadronSpectra2MC::Terminate(Option_t *) 
1321 {
1322   // Draw result to the screen
1323   // Called once at the end of the query
1324   Printf("*** CONSTRUCTOR CALLED ****");
1325    TOFCheck = dynamic_cast<TList*> (GetOutputData(1));
1326   if (!TOFCheck) {
1327     Printf("ERROR: TOFCheck not available");
1328     return;   
1329   } 
1330   
1331   system("touch ok.job");
1332 }
1333