]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGHF/hfe/AliAnalysisTaskEMCalHFEpA.cxx
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / PWGHF / hfe / AliAnalysisTaskEMCalHFEpA.cxx
1
2 /**************************************************************************
3  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *               
4  *                                                                        *               
5  * Author: The ALICE Off-line Project.                                    *               
6  * Contributors are mentioned in the code where appropriate.              *               
7  *                                                                        *               
8  * Permission to use, copy, modify and distribute this software and its   *               
9  * documentation strictly for non-commercial purposes is hereby granted   *               
10  * without fee, provided that the above copyright notice appears in all   *               
11  * copies and that both the copyright notice and this permission notice   *               
12  * appear in the supporting documentation. The authors make no claims     *               
13  * about the suitability of this software for any purpose. It is          *               
14  * provided "as is" without express or implied warranty.                  *               
15  **************************************************************************/
16
17         ////////////////////////////////////////////////////////////////////////
18         //                                                                    //
19         //      Task for Heavy-flavour electron analysis in pPb collisions    //
20         //      (+ Electron-Hadron Jetlike Azimuthal Correlation)             //
21         //                                                                                                                                        //
22         //              version: March 23, 2014.                                                                      //
23         //                                                                    //
24         //          Authors                                                                               //
25         //              Elienos Pereira de Oliveira Filho (epereira@cern.ch)          //
26         //              Cristiane Jahnke                (cristiane.jahnke@cern.ch)                    //
27         //                                                                    //
28         ////////////////////////////////////////////////////////////////////////
29
30 #include "TChain.h"
31 #include "TTree.h"
32 #include "TNtuple.h"
33 #include "TH1F.h"
34 #include "TH2F.h"
35 #include "TCanvas.h"
36 #include "AliAnalysisTask.h"
37 #include "AliAnalysisManager.h"
38 #include "AliESDEvent.h"
39 #include "AliAODEvent.h"
40 #include "AliVEvent.h"
41 #include "AliESDInputHandler.h"
42 #include "AliESDtrackCuts.h"
43 #include "AliESDCaloCluster.h"
44 #include "AliESDCaloCells.h"
45 #include "AliEMCALTrack.h"
46 #include "AliExternalTrackParam.h"
47 #include "AliPhysicsSelection.h"
48 #include "TGeoGlobalMagField.h"
49 #include "AliMagF.h"
50 #include "AliLog.h"
51 #include "AliStack.h"
52 #include "AliCentrality.h"
53 #include "AliAODMCParticle.h"
54 #include "AliAODMCHeader.h"
55 #include "AliPID.h"
56 #include "AliPIDResponse.h"
57 #include "AliHFEcontainer.h"
58 #include "AliHFEcuts.h"
59 #include "AliHFEpid.h"
60 #include "AliHFEpidBase.h"
61 #include "AliHFEpidQAmanager.h"
62 #include "AliHFEtools.h"
63 #include "AliCFContainer.h"
64 #include "AliCFManager.h"
65 #include "AliSelectNonHFE.h"
66 #include "AliHFEpidTPC.h"
67 #include "AliAnalysisTaskEMCalHFEpA.h"
68 #include "TMath.h"
69 #include "THnSparse.h"
70 #include "TLorentzVector.h"
71 #include "TString.h"
72 #include "TFile.h"
73 #include "AliESDHandler.h"
74 #include "AliMCEventHandler.h"
75 #include "AliMCEvent.h"
76 #include "AliStack.h"
77 #include "TParticle.h"
78 #include "AliLog.h"
79 #include "AliAnalysisTaskSE.h"
80 #include "TRefArray.h"
81 #include "TVector.h"
82 #include "stdio.h"
83 #include "TGeoManager.h"
84 #include "iostream"
85 #include "fstream"
86 #include "AliKFParticle.h"
87 #include "AliKFVertex.h"
88 #include "AliVParticle.h"
89 #include "AliVTrack.h"
90 #include "AliEventPoolManager.h"
91 #include "TObjArray.h"
92         //include to use reader as Lucile does
93 #include "AliCaloTrackAODReader.h"
94 #include "AliCaloTrackReader.h"
95
96         //______________________________________________________________________
97
98         //______________________________________________________________________
99 ClassImp(AliAnalysisTaskEMCalHFEpA)
100
101         //______________________________________________________________________
102 AliAnalysisTaskEMCalHFEpA::AliAnalysisTaskEMCalHFEpA(const char *name) 
103 : AliAnalysisTaskSE(name)
104 ,fCorrelationFlag(0)
105 ,fIsMC(0)
106 ,fUseEMCal(kFALSE)
107 ,fUseTrigger(kFALSE)
108 ,fUseShowerShapeCut(kFALSE)
109 ,fFillBackground(kFALSE)
110 ,fAssocWithSPD(kFALSE)
111
112 ,fEMCEG1(kFALSE)
113 ,fEMCEG2(kFALSE)
114 ,fIsHFE1(kFALSE)
115 ,fIsHFE2(kFALSE)
116 ,fIsNonHFE(kFALSE)
117 ,fIsFromD(kFALSE)
118 ,fIsFromB(kFALSE)
119 ,fIsFromPi0(kFALSE)
120 ,fIsFromEta(kFALSE)
121 ,fIsFromGamma(kFALSE)
122 ,fESD(0)
123 ,fAOD(0)
124 ,fVevent(0)
125 ,fPartnerCuts(new AliESDtrackCuts())
126 ,fOutputList(0)
127 ,fPidResponse(0)
128 ,fNonHFE(new AliSelectNonHFE())
129 ,fIsAOD(kFALSE)
130 ,fCentrality(0)
131 ,fCentralityMin(0)
132 ,fCentralityMax(100)
133 ,fHasCentralitySelection(kFALSE)
134 ,fCentralityHist(0)
135 ,fCentralityHistPass(0)
136 ,fZvtx(0)
137 ,fEstimator(0)
138 ,fClus(0)
139         //,fClusESD(0)
140 ,fNevent(0)
141 ,fPtElec_Inc(0)
142 ,fPtPrim(0)
143 ,fPtSec(0)
144 ,fPtPrim2(0)
145 ,fPtSec2(0)
146 ,fCharge_n(0)
147 ,fCharge_p(0)
148 ,fTime(0)
149 ,fTime2(0)
150 ,ftimingEle(0)
151 ,ftimingEle2(0)
152 ,fPtElec_ULS(0)
153 ,fPtElec_LS(0)
154 ,fPtElec_ULS_NoPid(0)
155 ,fPtElec_LS_NoPid(0)
156 ,fPtElec_ULS_MC(0)
157 ,fPtElec_ULS_MC_weight(0)
158 ,fPtElec_ULS2(0)
159 ,fPtElec_LS2(0)
160 ,fPtElec_ULS_weight(0)
161 ,fPtElec_LS_weight(0)
162 ,fPtElec_ULS2_weight(0)
163 ,fPtElec_LS2_weight(0)
164 ,fTOF01(0)
165 ,fTOF02(0)
166 ,fTOF03(0)
167 ,fpid(0)
168 ,fEoverP_pt(0)
169 ,fEoverP_tpc(0)
170 ,fTPC_pt(0)
171 ,fTPC_p(0)
172 ,fTPCnsigma_pt(0)
173 ,fTPCnsigma_p(0)
174 ,fTPCnsigma_pt_2D(0)
175 ,fShowerShapeCut(0)
176 ,fShowerShapeM02_EoverP(0)
177 ,fShowerShapeM20_EoverP(0)
178 ,fShowerShape_ha(0)
179 ,fShowerShape_ele(0)
180 ,fTPCnsigma_eta(0)
181 ,fTPCnsigma_phi(0)
182 ,fECluster(0)
183 ,fECluster_pure(0)
184 ,fEtaPhi(0)
185 ,fEtaPhi_num(0)
186 ,fEtaPhi_den(0)
187 ,fpt_reco_pt_MC_num(0)
188 ,fpt_reco_pt_MC_den(0)
189 ,fVtxZ(0)
190
191 ,fVtxZ_new1(0)
192 ,fVtxZ_new2(0)
193 ,fVtxZ_new3(0)
194 ,fVtxZ_new4(0)
195
196 ,fEtad(0)
197 ,fNTracks(0)
198 ,fNTracks_pt(0)
199 ,fNTracks_eta(0)
200 ,fNTracks_phi(0)
201 ,fNClusters(0)
202 ,fTPCNcls_EoverP(0)
203 ,fTPCNcls_pid(0)
204 ,fEta(0)
205 ,fPhi(0)
206 ,fR(0)
207 ,fR_EoverP(0)
208 ,fNcells(0)
209 ,fNcells_EoverP(0)
210 ,fNcells_electrons(0)
211 ,fNcells_hadrons(0)
212 ,fECluster_ptbins(0)
213 ,fEoverP_ptbins(0)
214 ,fEoverP_wSSCut(0)
215 ,fM02_EoverP(0)
216 ,fM20_EoverP(0)
217 ,fTPCnsigma_eta_electrons(0)
218 ,fTPCnsigma_eta_hadrons(0)
219 ,fEoverP_pt_pions(0)
220 ,ftpc_p_EoverPcut(0)
221 ,fnsigma_p_EoverPcut(0)
222 ,fEoverP_pt_pions2(0)
223 ,fNcells_pt(0)
224 ,fEoverP_pt_hadrons(0)
225 ,fCEtaPhi_Inc(0)
226 ,fCEtaPhi_ULS(0)
227 ,fCEtaPhi_LS(0)
228 ,fCEtaPhi_ULS_NoP(0)
229 ,fCEtaPhi_LS_NoP(0)
230 ,fCEtaPhi_ULS_Weight(0)
231 ,fCEtaPhi_LS_Weight(0)
232 ,fCEtaPhi_ULS_NoP_Weight(0)
233 ,fCEtaPhi_LS_NoP_Weight(0)
234 ,fInvMass(0)
235 ,fInvMassBack(0)
236 ,fDCA(0)
237 ,fDCABack(0)
238 ,fOpAngle(0)
239 ,fOpAngleBack(0)
240 ,fInvMass2(0)
241 ,fInvMassBack2(0)
242 ,fDCA2(0)
243 ,fDCABack2(0)
244 ,fOpAngle2(0)
245 ,fOpAngleBack2(0)
246 ,fMassCut(0.1)
247 ,fEtaCutMin(-0.9)
248 ,fEtaCutMax(0.9)
249 ,fdPhiCut(0.05)
250 ,fdEtaCut(0.05)
251 ,fEoverPCutMin(0.8)
252 ,fEoverPCutMax(1.2)
253 ,fM20CutMin(0.0)
254 ,fM20CutMax(10)
255 ,fM02CutMin(0.0)
256 ,fM02CutMax(10)
257 ,fAngleCut(999)
258 ,fChi2Cut(3.5)
259 ,fDCAcut(999)
260 ,fMassCutFlag(kTRUE)
261 ,fAngleCutFlag(kFALSE)
262 ,fChi2CutFlag(kFALSE)
263 ,fDCAcutFlag(kFALSE)
264 ,fAssHadronPtMin(0.5)
265 ,fAssHadronPtMax(2.0)
266 ,fPtBackgroundBeforeReco(0)
267 ,fPtBackgroundBeforeReco2(0)
268 ,fPtBackgroundBeforeReco_weight(0)
269 ,fPtBackgroundBeforeReco2_weight(0)
270 ,fpT_m_electron(0)
271 ,fpT_gm_electron(0)
272 ,fPtBackgroundAfterReco(0)
273 ,fPtMinAsso(0.3)
274 ,fTpcNclsAsso(80)
275 ,fPtMCparticleAll(0)
276 ,fPtMCparticleAll_nonPrimary(0)
277 ,fPtMCparticleAlle_nonPrimary(0)
278 ,fPtMCparticleAlle_Primary(0)
279 ,fPtMCparticleReco(0)
280 ,fPtMCparticleReco_nonPrimary(0)
281 ,fPtMCparticleAllHfe1(0)
282 ,fPtMCparticleRecoHfe1(0)
283 ,fPtMCparticleAllHfe2(0)
284 ,fPtMCparticleRecoHfe2(0)
285 ,fPtMCelectronAfterAll(0)
286 ,fPtMCelectronAfterAll_unfolding(0)
287 ,fPtMCelectronAfterAll_nonPrimary(0)
288 ,fPtMCelectronAfterAll_Primary(0)
289 ,fPtMCpi0(0)
290 ,fPtMCeta(0)
291 ,fPtMCpi02(0)
292 ,fPtMCeta2(0)
293 ,fPtMC_EMCal_All(0)
294 ,fPtMC_EMCal_Selected(0)
295 ,fPtMC_TPC_All(0)
296 ,fPtMC_TPC_Selected(0)
297 ,fPt_track_match_den(0)
298 ,fPt_track_match_num(0)
299 ,fPtMCWithLabel(0)
300 ,fPtMCWithoutLabel(0)
301 ,fPtIsPhysicaPrimary(0)
302 ,fCuts(0)
303         //,reader(0)    
304 ,fCFM(0)
305 ,fPID(new AliHFEpid("hfePid"))
306         //Lucile
307 ,fPIDqa(0)
308 ,fMCstack(0)
309 ,fRejectKinkMother(kFALSE)
310 ,fMCtrack(0)
311 ,fMCtrackMother(0)
312 ,fMCtrackGMother(0)
313 ,fMCtrackGGMother(0)
314 ,fMCtrackGGGMother(0)
315 ,fMCarray(0)
316 ,fMCheader(0)
317 ,fMCparticle(0)
318 ,fMCparticle2(0)
319 ,fMCparticleMother(0)
320 ,fMCparticleGMother(0)
321 ,fMCparticleGGMother(0)
322 ,fMCparticleGGGMother(0)
323 ,fEventHandler(0)
324 ,fMCevent(0)
325 ,fPoolMgr(0)
326 ,fPool(0)
327 ,fTracksClone(0)
328 ,fTracks(0)     
329 ,fCEtaPhi_Inc_EM(0)     
330 ,fCEtaPhi_ULS_EM(0)
331 ,fCEtaPhi_LS_EM(0)
332 ,fCEtaPhi_ULS_Weight_EM(0)
333 ,fCEtaPhi_LS_Weight_EM(0)
334 ,fPoolNevents(0)
335 ,fEventMixingFlag(0)
336 ,fCEtaPhi_Inc_DiHadron(0)
337 ,fPtTrigger_Inc(0)
338 {
339                 //Named constructor 
340                 // Define input and output slots here
341                 // Input slot #0 works with a TChain
342         DefineInput(0, TChain::Class());
343                 // Output slot #0 id reserved by the base class for AOD
344                 // Output slot #1 writes into a TH1 container
345                 // DefineOutput(1, TH1I::Class());
346         DefineOutput(1, TList::Class());
347                 //  DefineOutput(3, TTree::Class());
348 }
349
350         //________________________________________________________________________
351 AliAnalysisTaskEMCalHFEpA::AliAnalysisTaskEMCalHFEpA() 
352 : AliAnalysisTaskSE("DefaultAnalysis_AliAnalysisTaskEMCalHFEpA")
353 ,fCorrelationFlag(0)
354 ,fIsMC(0)
355 ,fUseEMCal(kFALSE)
356 ,fUseTrigger(kFALSE)
357 ,fUseShowerShapeCut(kFALSE)
358 ,fFillBackground(kFALSE)
359 ,fAssocWithSPD(kFALSE)
360 ,fEMCEG1(kFALSE)
361 ,fEMCEG2(kFALSE)
362 ,fIsHFE1(kFALSE)
363 ,fIsHFE2(kFALSE)
364 ,fIsNonHFE(kFALSE)
365 ,fIsFromD(kFALSE)
366 ,fIsFromB(kFALSE)
367 ,fIsFromPi0(kFALSE)
368 ,fIsFromEta(kFALSE)
369 ,fIsFromGamma(kFALSE)
370 ,fESD(0)
371 ,fAOD(0)
372 ,fVevent(0)
373 ,fPartnerCuts(new AliESDtrackCuts())
374 ,fOutputList(0)
375 ,fPidResponse(0)
376 ,fNonHFE(new AliSelectNonHFE())
377 ,fIsAOD(kFALSE)
378 ,fCentrality(0)
379 ,fCentralityMin(0)
380 ,fCentralityMax(100)
381 ,fHasCentralitySelection(kFALSE)
382 ,fCentralityHist(0)
383 ,fCentralityHistPass(0)
384 ,fZvtx(0)
385 ,fEstimator(0)
386 ,fClus(0)
387         //,fClusESD(0)
388 ,fNevent(0)
389 ,fPtElec_Inc(0)
390 ,fPtPrim(0)
391 ,fPtSec(0)
392 ,fPtPrim2(0)
393 ,fPtSec2(0)
394 ,fCharge_n(0)
395 ,fCharge_p(0)
396 ,fTime(0)
397 ,fTime2(0)
398 ,ftimingEle(0)
399 ,ftimingEle2(0)
400 ,fPtElec_ULS(0)
401 ,fPtElec_LS(0)
402 ,fPtElec_ULS_NoPid(0)
403 ,fPtElec_LS_NoPid(0)
404 ,fPtElec_ULS_MC(0)
405 ,fPtElec_ULS_MC_weight(0)
406 ,fPtElec_ULS2(0)
407 ,fPtElec_LS2(0)
408 ,fPtElec_ULS_weight(0)
409 ,fPtElec_LS_weight(0)
410 ,fPtElec_ULS2_weight(0)
411 ,fPtElec_LS2_weight(0)
412 ,fTOF01(0)
413 ,fTOF02(0)
414 ,fTOF03(0)
415 ,fpid(0)
416 ,fEoverP_pt(0)
417 ,fEoverP_tpc(0)
418 ,fTPC_pt(0)
419 ,fTPC_p(0)
420 ,fTPCnsigma_pt(0)
421 ,fTPCnsigma_p(0)
422 ,fTPCnsigma_pt_2D(0)
423 ,fShowerShapeCut(0)
424 ,fShowerShapeM02_EoverP(0)
425 ,fShowerShapeM20_EoverP(0)
426 ,fShowerShape_ha(0)
427 ,fShowerShape_ele(0)
428 ,fTPCnsigma_eta(0)
429 ,fTPCnsigma_phi(0)
430 ,fECluster(0)
431 ,fECluster_pure(0)
432 ,fEtaPhi(0)
433 ,fEtaPhi_num(0)
434 ,fEtaPhi_den(0)
435 ,fpt_reco_pt_MC_num(0)
436 ,fpt_reco_pt_MC_den(0)
437 ,fVtxZ(0)
438
439 ,fVtxZ_new1(0)
440 ,fVtxZ_new2(0)
441 ,fVtxZ_new3(0)
442 ,fVtxZ_new4(0)
443
444 ,fEtad(0)
445 ,fNTracks(0)
446 ,fNTracks_pt(0)
447 ,fNTracks_eta(0)
448 ,fNTracks_phi(0)
449 ,fNClusters(0)
450 ,fTPCNcls_EoverP(0)
451 ,fTPCNcls_pid(0)
452 ,fEta(0)
453 ,fPhi(0)
454 ,fR(0)
455 ,fR_EoverP(0)
456 ,fNcells(0)
457 ,fNcells_EoverP(0)
458 ,fNcells_electrons(0)
459 ,fNcells_hadrons(0)
460 ,fECluster_ptbins(0)
461 ,fEoverP_ptbins(0)
462 ,fEoverP_wSSCut(0)
463 ,fM02_EoverP(0)
464 ,fM20_EoverP(0)
465 ,fTPCnsigma_eta_electrons(0)
466 ,fTPCnsigma_eta_hadrons(0)
467 ,fEoverP_pt_pions(0)
468 ,ftpc_p_EoverPcut(0)
469 ,fnsigma_p_EoverPcut(0)
470 ,fEoverP_pt_pions2(0)
471 ,fNcells_pt(0)
472 ,fEoverP_pt_hadrons(0)
473 ,fCEtaPhi_Inc(0)
474 ,fCEtaPhi_ULS(0)
475 ,fCEtaPhi_LS(0)
476 ,fCEtaPhi_ULS_NoP(0)
477 ,fCEtaPhi_LS_NoP(0)
478 ,fCEtaPhi_ULS_Weight(0)
479 ,fCEtaPhi_LS_Weight(0)
480 ,fCEtaPhi_ULS_NoP_Weight(0)
481 ,fCEtaPhi_LS_NoP_Weight(0)
482 ,fInvMass(0)
483 ,fInvMassBack(0)
484 ,fDCA(0)
485 ,fDCABack(0)
486 ,fOpAngle(0)
487 ,fOpAngleBack(0)
488 ,fInvMass2(0)
489 ,fInvMassBack2(0)
490 ,fDCA2(0)
491 ,fDCABack2(0)
492 ,fOpAngle2(0)
493 ,fOpAngleBack2(0)
494 ,fMassCut(0.1)
495 ,fEtaCutMin(-0.9)
496 ,fEtaCutMax(0.9)
497 ,fdPhiCut(0.05)
498 ,fdEtaCut(0.05)
499 ,fEoverPCutMin(0.8)
500 ,fEoverPCutMax(1.2)
501 ,fM20CutMin(0)
502 ,fM20CutMax(10)
503 ,fM02CutMin(0)
504 ,fM02CutMax(10)
505 ,fAngleCut(999)
506 ,fChi2Cut(3.5)
507 ,fDCAcut(999)
508 ,fMassCutFlag(kTRUE)
509 ,fAngleCutFlag(kFALSE)
510 ,fChi2CutFlag(kFALSE)
511 ,fDCAcutFlag(kFALSE)
512 ,fAssHadronPtMin(0.5)
513 ,fAssHadronPtMax(2.0)
514 ,fPtBackgroundBeforeReco(0)
515 ,fPtBackgroundBeforeReco2(0)
516 ,fPtBackgroundBeforeReco_weight(0)
517 ,fPtBackgroundBeforeReco2_weight(0)
518 ,fpT_m_electron(0)
519 ,fpT_gm_electron(0)
520 ,fPtBackgroundAfterReco(0)
521 ,fPtMinAsso(0.3)
522 ,fTpcNclsAsso(80)
523 ,fPtMCparticleAll(0)
524 ,fPtMCparticleAll_nonPrimary(0)
525 ,fPtMCparticleAlle_nonPrimary(0)
526 ,fPtMCparticleAlle_Primary(0)
527 ,fPtMCparticleReco(0)
528 ,fPtMCparticleReco_nonPrimary(0)
529 ,fPtMCparticleAllHfe1(0)
530 ,fPtMCparticleRecoHfe1(0)
531 ,fPtMCparticleAllHfe2(0)
532 ,fPtMCparticleRecoHfe2(0)
533 ,fPtMCelectronAfterAll(0)
534 ,fPtMCelectronAfterAll_unfolding(0)
535 ,fPtMCelectronAfterAll_nonPrimary(0)
536 ,fPtMCelectronAfterAll_Primary(0)
537 ,fPtMCpi0(0)
538 ,fPtMCeta(0)
539 ,fPtMCpi02(0)
540 ,fPtMCeta2(0)
541 ,fPtMC_EMCal_All(0)
542 ,fPtMC_EMCal_Selected(0)
543 ,fPtMC_TPC_All(0)
544 ,fPtMC_TPC_Selected(0)
545 ,fPt_track_match_den(0)
546 ,fPt_track_match_num(0)
547 ,fPtMCWithLabel(0)
548 ,fPtMCWithoutLabel(0)
549 ,fPtIsPhysicaPrimary(0)
550 ,fCuts(0)
551         //Lucile
552         //,reader(0)
553 ,fCFM(0)
554 ,fPID(new AliHFEpid("hfePid"))
555 ,fPIDqa(0)
556 ,fMCstack(0)
557 ,fRejectKinkMother(kFALSE)
558 ,fMCtrack(0)
559 ,fMCtrackMother(0)
560 ,fMCtrackGMother(0)
561 ,fMCtrackGGMother(0)
562 ,fMCtrackGGGMother(0)
563 ,fMCarray(0)
564 ,fMCheader(0)
565 ,fMCparticle(0)
566 ,fMCparticle2(0)
567 ,fMCparticleMother(0)
568 ,fMCparticleGMother(0)
569 ,fMCparticleGGMother(0)
570 ,fMCparticleGGGMother(0)
571 ,fEventHandler(0)
572 ,fMCevent(0)
573 ,fPoolMgr(0)
574 ,fPool(0)
575 ,fTracksClone(0)
576 ,fTracks(0)     
577 ,fCEtaPhi_Inc_EM(0)     
578 ,fCEtaPhi_ULS_EM(0)
579 ,fCEtaPhi_LS_EM(0)
580 ,fCEtaPhi_ULS_Weight_EM(0)
581 ,fCEtaPhi_LS_Weight_EM(0)
582 ,fPoolNevents(0)
583 ,fEventMixingFlag(0)
584 ,fCEtaPhi_Inc_DiHadron(0)
585 ,fPtTrigger_Inc(0)
586 {
587                 // Constructor
588                 // Define input and output slots here
589                 // Input slot #0 works with a TChain
590         DefineInput(0, TChain::Class());
591                 // Output slot #0 id reserved by the base class for AOD
592                 // Output slot #1 writes into a TH1 container
593                 // DefineOutput(1, TH1I::Class());
594         DefineOutput(1, TList::Class());
595                 //DefineOutput(3, TTree::Class());
596 }
597
598         //______________________________________________________________________
599 AliAnalysisTaskEMCalHFEpA::~AliAnalysisTaskEMCalHFEpA()
600 {
601         //Destructor 
602         delete fOutputList;
603         delete fPID;
604         delete fCFM;
605         delete fPIDqa;
606         //Lucile
607         //delete reader; 
608 }
609
610         //______________________________________________________________________
611         //Create Output Objects
612         //Here we can define the histograms and others output files
613         //Called once
614 void AliAnalysisTaskEMCalHFEpA::UserCreateOutputObjects()
615 {
616                 //______________________________________________________________________
617                 //Initialize PID
618         if(!fPID->GetNumberOfPIDdetectors()) 
619     {
620                 fPID->AddDetector("TPC", 0);
621     }
622         
623         fPID->SortDetectors(); 
624         
625         fPIDqa = new AliHFEpidQAmanager();
626         fPIDqa->Initialize(fPID);
627                 //______________________________________________________________________
628         
629                 //______________________________________________________________________  
630                 //Initialize correction Framework and Cuts
631         fCFM = new AliCFManager;
632         const Int_t kNcutSteps = AliHFEcuts::kNcutStepsMCTrack + AliHFEcuts::kNcutStepsRecTrack + AliHFEcuts::kNcutStepsDETrack;
633         fCFM->SetNStepParticle(kNcutSteps);
634         for(Int_t istep = 0; istep < kNcutSteps; istep++) fCFM->SetParticleCutsList(istep, NULL);
635         
636         if(!fCuts)
637         {
638                 AliWarning("Cuts not available. Default cuts will be used");
639                 fCuts = new AliHFEcuts;
640                 fCuts->CreateStandardCuts();
641         }
642         
643         fCuts->Initialize(fCFM);
644                 //______________________________________________________________________
645         
646                 ///___________________//Lucile
647         
648                 //if(fIsAOD) {
649                 //      reader = new AliCaloTrackAODReader();
650                 //}
651                         //___________________________________________________
652                 ///Output Tlist
653                 //Create TList
654         fOutputList = new TList();
655         fOutputList->SetOwner();        
656         
657                 //PIDqa
658         fOutputList->Add(fPIDqa->MakeList("PIDQA"));
659         
660                 //Store the number of events
661                 //Define the histo
662         fNevent = new TH1F("fNevent","Number of Events",15,0,15);
663                 //And then, add to the output list
664         fOutputList->Add(fNevent);
665         
666         fpid = new TH1F("fpid","PID flag",5,0,5);
667         fOutputList->Add(fpid);
668         
669         //pt Distribution
670         fPtElec_Inc = new TH1F("fPtElec_Inc","Inclusive Electrons; p_{T} (GeV/c); Count",300,0,30);     
671         
672         fPtPrim = new TH1F("fPtPrim","Primary Electrons aod track; p_{T} (GeV/c); Count",300,0,30);
673         fPtSec = new TH1F("fPtSec","Secundary Electrons aod track; p_{T} (GeV/c); Count",300,0,30);
674         fPtPrim2 = new TH1F("fPtPrim2","Primary Electrons vtrack; p_{T} (GeV/c); Count",300,0,30);
675         fPtSec2 = new TH1F("fPtSec2","Secundary Electrons vtrack; p_{T} (GeV/c); Count",300,0,30);
676
677         
678         fPtElec_ULS = new TH1F("fPtElec_ULS","ULS; p_{T} (GeV/c); Count",300,0,30);
679         fPtElec_LS = new TH1F("fPtElec_LS","LS; p_{T} (GeV/c); Count",300,0,30);
680         
681         fPtElec_ULS_NoPid = new TH1F("fPtElec_ULS_NoPid","ULS; p_{T} (GeV/c); Count",300,0,30);
682         fPtElec_LS_NoPid = new TH1F("fPtElec_LS_NoPid","LS; p_{T} (GeV/c); Count",300,0,30);
683         
684         fPtElec_ULS_MC = new TH1F("fPtElec_ULS_MC","ULS; p_{T} (GeV/c); Count",300,0,30);
685         fPtElec_ULS_MC_weight = new TH1F("fPtElec_ULS_MC_weight","ULS; p_{T} (GeV/c); Count",300,0,30);
686         
687         fPtElec_ULS_weight = new TH1F("fPtElec_ULS_weight","ULS; p_{T} (GeV/c); Count",300,0,30);
688         fPtElec_LS_weight = new TH1F("fPtElec_LS_weight","LS; p_{T} (GeV/c); Count",300,0,30);
689         
690         fTOF01 = new TH2F("fTOF01","",200,-20,20,200,-20,20);
691         fTOF02 = new TH2F("fTOF02","",200,-20,20,200,-20,20);
692         fTOF03 = new TH2F("fTOF03","",200,-20,20,200,-20,20);
693         
694         if(fFillBackground){
695                 fPtElec_ULS2 = new TH1F("fPtElec_ULS2","ULS; p_{T} (GeV/c); Count",300,0,30);
696                 fPtElec_LS2 = new TH1F("fPtElec_LS2","LS; p_{T} (GeV/c); Count",300,0,30);
697                 
698                 fPtElec_ULS2_weight = new TH1F("fPtElec_ULS2_weight","ULS; p_{T} (GeV/c); Count",300,0,30);
699                 fPtElec_LS2_weight = new TH1F("fPtElec_LS2_weight","LS; p_{T} (GeV/c); Count",300,0,30);
700
701         }
702         
703         fPtTrigger_Inc = new TH1F("fPtTrigger_Inc","pT dist for Hadron Contamination; p_{t} (GeV/c); Count",300,0,30);
704         fTPCnsigma_pt_2D = new TH2F("fTPCnsigma_pt_2D",";pt (GeV/c);TPC Electron N#sigma",1000,0.3,30,1000,-15,10);
705         fShowerShapeCut = new TH2F("fShowerShapeCut","Shower Shape;M02;M20",500,0,1.8,500,0,1.8);
706         fEtaPhi_num=new TH2F("fEtaPhi_num","#eta x #phi track;#phi;#eta",200,0.,5,50,-1.,1.);
707         fEtaPhi_den=new TH2F("fEtaPhi_den","#eta x #phi track;#phi;#eta",200,0.,5,50,-1.,1.);
708                 
709         fpt_reco_pt_MC_num=new TH2F("fpt_reco_pt_MC_num","pt reco x pt MC;pt reco; pt MC",300,0.,30,300,0.,30);
710         fpt_reco_pt_MC_den=new TH2F("fpt_reco_pt_MC_den","pt reco x pt MC;pt reco; pt MC",300,0.,30,300,0.,30);
711         
712         
713         fCharge_n = new TH1F("fCharge_n","Inclusive Electrons (Negative Charge); p_{t} (GeV/c); Count",200,0,30);
714         fCharge_p = new TH1F("fCharge_p","Inclusive Positrons (Positive Charge); p_{t} (GeV/c); Count",200,0,30);
715         
716         fECluster_pure= new TH1F("fECluster_pure", ";ECluster pure",2000,0,100);
717         
718         if(fUseEMCal){
719                 
720                 if(!fIsAOD){
721                         fTime = new TH2D("fTime","Cells Cluster Time; p_{T} (GeV/c); Time (s)",300,0,30,1000,1e-8,1e-5);
722                         fTime2 = new TH2D("fTime2","Cells Cluster Time;  p_{T} (GeV/c); Time (s)",300,0,30,1000,1e-8,1e-5);
723                 }
724                 
725                 ftimingEle = new TH2D("ftimingEle","Cluster Time;  p_{T} (GeV/c); Time (s)",300,0,30,1000,1e-8,1e-5);
726                 ftimingEle2 = new TH2D("ftimingEle2","Cluster Time;  p_{T} (GeV/c); Time (s)",300,0,30,1000,1e-8,1e-5);
727                 
728                 fShowerShape_ha = new TH2F("fShowerShape_ha","Shower Shape hadrons;M02;M20",500,0,1.8,500,0,1.8);
729                 fShowerShape_ele = new TH2F("fShowerShape_ele","Shower Shape electrons;M02;M20",500,0,1.8,500,0,1.8);
730                 
731                 fShowerShapeM02_EoverP = new TH2F("fShowerShapeM02_EoverP","Shower Shape;M02;E/p",500,0,1.8,500,0,1.8);
732                 fShowerShapeM20_EoverP = new TH2F("fShowerShapeM20_EoverP","Shower Shape;M20;E/p",500,0,1.8,500,0,1.8);
733                 
734         }
735         
736         fOutputList->Add(fTOF01);
737         fOutputList->Add(fTOF02);
738         fOutputList->Add(fTOF03);
739         
740         fOutputList->Add(fEtaPhi_num);
741         fOutputList->Add(fEtaPhi_den);
742         
743         fOutputList->Add(fpt_reco_pt_MC_num);
744         fOutputList->Add(fpt_reco_pt_MC_den);
745         
746         
747         fOutputList->Add(fPtElec_Inc);
748         fOutputList->Add(fPtElec_ULS);
749         fOutputList->Add(fPtElec_LS);
750         fOutputList->Add(fPtElec_ULS_NoPid);
751         fOutputList->Add(fPtElec_LS_NoPid);
752         fOutputList->Add(fPtElec_ULS_MC);
753         fOutputList->Add(fPtElec_ULS_MC_weight);
754         
755         fOutputList->Add(fPtPrim);
756         fOutputList->Add(fPtSec);
757         fOutputList->Add(fPtPrim2);
758         fOutputList->Add(fPtSec2);
759
760
761         
762         fOutputList->Add(fPtElec_ULS_weight);
763         fOutputList->Add(fPtElec_LS_weight);
764         
765         if(fFillBackground){
766                 fOutputList->Add(fPtElec_ULS2);
767                 fOutputList->Add(fPtElec_LS2);
768                 fOutputList->Add(fPtElec_ULS2_weight);
769                 fOutputList->Add(fPtElec_LS2_weight);
770         }
771         
772         
773         fOutputList->Add(fPtTrigger_Inc);
774         fOutputList->Add(fTPCnsigma_pt_2D);
775         fOutputList->Add(fShowerShapeCut);
776         
777         fOutputList->Add(fCharge_n);
778         fOutputList->Add(fCharge_p);
779         
780         fOutputList->Add(fECluster_pure);
781         
782         if(fUseEMCal){
783                 
784                 if(!fIsAOD){
785                         fOutputList->Add(fTime);
786                         fOutputList->Add(fTime2);
787                         
788                 }
789                 
790                 fOutputList->Add(ftimingEle);
791                 fOutputList->Add(ftimingEle2);
792                 
793                 fOutputList->Add(fShowerShape_ha);
794                 fOutputList->Add(fShowerShape_ele);
795                 
796                 fOutputList->Add(fShowerShapeM02_EoverP);
797                 fOutputList->Add(fShowerShapeM20_EoverP);
798                 
799                 
800                 
801         }
802         
803         fVtxZ_new1= new  TH1F("fVtxZ_new1","fVtxZ_new1",1000, -50,50);
804         fVtxZ_new2= new  TH1F("fVtxZ_new2","fVtxZ_new2",1000, -50,50);
805         fVtxZ_new3= new  TH1F("fVtxZ_new3","fVtxZ_new3",1000, -50,50);
806         fVtxZ_new4= new  TH1F("fVtxZ_new4","fVtxZ_new4",1000, -50,50);
807         
808                 //General Histograms
809         
810                 //Steps
811                 //Step 1: Before Track cuts
812                 //Step 2: Before PID
813                 //Step 3: After PID
814         
815         fEoverP_pt = new TH2F *[3];
816         fTPC_p = new TH2F *[3];
817         fTPCnsigma_p = new TH2F *[3];
818         
819         fECluster= new TH1F *[3];
820         fEtaPhi= new TH2F *[3];
821         fVtxZ= new  TH1F *[3];
822         fEtad= new  TH1F *[3];
823         fNTracks= new  TH1F *[3];
824         
825         fNTracks_pt= new  TH2F *[3];
826         fNTracks_eta= new  TH2F *[3];
827         fNTracks_phi= new  TH2F *[3];
828         
829         fNClusters= new TH1F *[3];
830         fTPCNcls_EoverP= new TH2F *[3]; 
831         fTPCNcls_pid=new TH2F *[4];
832         
833         
834         
835         for(Int_t i = 0; i < 3; i++)
836         {
837                 fEoverP_pt[i] = new TH2F(Form("fEoverP_pt%d",i),";p_{t} (GeV/c);E / p ",1000,0,30,500,0,2);
838                 fTPC_p[i] = new TH2F(Form("fTPC_p%d",i),";pt (GeV/c);TPC dE/dx (a. u.)",1000,0.3,15,1000,-20,200);
839                 fTPCnsigma_p[i] = new TH2F(Form("fTPCnsigma_p%d",i),";p (GeV/c);TPC Electron N#sigma",1000,0.3,15,1000,-15,10);
840                 
841                 
842                 fECluster[i]= new TH1F(Form("fECluster%d",i), ";ECluster",2000, 0,100);
843                 fEtaPhi[i]= new TH2F(Form("fEtaPhi%d",i),"#eta x #phi Clusters;#phi;#eta",200,0.,5,50,-1.,1.);
844                 fVtxZ[i]= new  TH1F(Form("fVtxZ%d",i),"VtxZ",1000, -50,50);
845                 fEtad[i]= new  TH1F(Form("fEtad%d",i),"Eta distribution",200, -1.2,1.2);
846                 fNTracks[i]= new  TH1F(Form("fNTracks%d",i),"NTracks",1000, 0,5000);
847                 
848                 fNTracks_pt[i]= new  TH2F(Form("fNTracks_pt%d",i),"NTracks vs. pt",1000, 0,5000, 1000, 0, 100);
849                 fNTracks_eta[i]= new  TH2F(Form("fNTracks_eta%d",i),"NTracks vs. pt",1000, 0,5000, 500, -1.0, 1.0);
850                 fNTracks_phi[i]= new  TH2F(Form("fNTracks_phi%d",i),"NTracks vs. pt",1000, 0,5000, 500, 0, 5.0);
851
852                 
853                 
854                 fNClusters[i]= new TH1F(Form("fNClusters%d",i),"fNClusters0",200, 0,100);
855                 fTPCNcls_EoverP[i]= new TH2F(Form("fTPCNcls_EoverP%d",i),"TPCNcls_EoverP",1000,0,200,200,0,2);  
856                         
857                 
858                 
859                 fOutputList->Add(fEoverP_pt[i]);
860                 fOutputList->Add(fTPC_p[i]);
861                 fOutputList->Add(fTPCnsigma_p[i]);
862                 
863                 
864                 fOutputList->Add(fECluster[i]);
865                 fOutputList->Add(fEtaPhi[i]);
866                 fOutputList->Add(fVtxZ[i]);
867                 fOutputList->Add(fEtad[i]);
868                 fOutputList->Add(fNTracks[i]);
869                 
870                 fOutputList->Add(fNTracks_pt[i]);
871                 fOutputList->Add(fNTracks_eta[i]);
872                 fOutputList->Add(fNTracks_phi[i]);
873                 
874                 fOutputList->Add(fNClusters[i]);
875                 fOutputList->Add(fTPCNcls_EoverP[i]);
876         }
877         
878         for(Int_t i = 0; i < 4; i++)
879         {
880                 fTPCNcls_pid[i]= new TH2F(Form("fTPCNcls_pid%d",i),"fTPCNcls_pid;NCls;NCls for PID",200,0,200,200,0,200);
881                 fOutputList->Add(fTPCNcls_pid[i]);
882         }
883         
884                 //pt bin
885         Int_t fPtBin[7] = {1,2,4,6,8,10,15};
886         
887         fEoverP_tpc = new TH2F *[6];
888         fTPC_pt = new TH1F *[6];
889         fTPCnsigma_pt = new TH1F *[6];
890         
891         fEta=new TH1F *[6];
892         fPhi=new TH1F *[6];
893         fR=new TH1F *[6];
894         fR_EoverP=new TH2F *[6];
895         fNcells=new TH1F *[6];
896         fNcells_EoverP=new TH2F *[6];
897         fM02_EoverP= new TH2F *[6];
898         fM20_EoverP= new TH2F *[6];
899         fEoverP_ptbins=new TH1F *[6];
900         fECluster_ptbins=new TH1F *[6];
901         fEoverP_wSSCut=new TH1F *[6];
902         fNcells_electrons=new TH1F *[6];
903         fNcells_hadrons=new TH1F *[6];
904         fTPCnsigma_eta_electrons=new TH2F *[6];
905         fTPCnsigma_eta_hadrons=new TH2F *[6];
906         
907         if(fCorrelationFlag)
908         {
909                 fCEtaPhi_Inc = new TH2F *[6];
910                 fCEtaPhi_Inc_DiHadron = new TH2F *[6];
911                 
912                 fCEtaPhi_ULS = new TH2F *[6];
913                 fCEtaPhi_LS = new TH2F *[6];
914                 fCEtaPhi_ULS_NoP = new TH2F *[6];
915                 fCEtaPhi_LS_NoP = new TH2F *[6];
916                 
917                 fCEtaPhi_ULS_Weight = new TH2F *[6];
918                 fCEtaPhi_LS_Weight = new TH2F *[6];
919                 fCEtaPhi_ULS_NoP_Weight = new TH2F *[6];
920                 fCEtaPhi_LS_NoP_Weight = new TH2F *[6];
921                 
922                 fCEtaPhi_Inc_EM = new TH2F *[6];
923                 
924                 fCEtaPhi_ULS_EM = new TH2F *[6];
925                 fCEtaPhi_LS_EM = new TH2F *[6];
926                 
927                 fCEtaPhi_ULS_Weight_EM = new TH2F *[6];
928                 fCEtaPhi_LS_Weight_EM = new TH2F *[6];
929                 
930                 fInvMass = new TH1F("fInvMass","",200,0,0.3);
931                 fInvMassBack = new TH1F("fInvMassBack","",200,0,0.3);
932                 fDCA = new TH1F("fDCA","",200,0,1);
933                 fDCABack = new TH1F("fDCABack","",200,0,1);
934                 fOpAngle = new TH1F("fOpAngle","",200,0,0.5);
935                 fOpAngleBack = new TH1F("fOpAngleBack","",200,0,0.5);
936                 
937                 fOutputList->Add(fInvMass);
938                 fOutputList->Add(fInvMassBack);
939                 fOutputList->Add(fDCA);
940                 fOutputList->Add(fDCABack);
941                 fOutputList->Add(fOpAngle);
942                 fOutputList->Add(fOpAngleBack);
943         }
944         
945         if(fFillBackground){
946                 
947                 fInvMass = new TH1F("fInvMass","",200,0,0.3);
948                 fInvMassBack = new TH1F("fInvMassBack","",200,0,0.3);
949                 fDCA = new TH1F("fDCA","",200,0,1);
950                 fDCABack = new TH1F("fDCABack","",200,0,1);
951                 fOpAngle = new TH1F("fOpAngle","",200,0,0.5);
952                 fOpAngleBack = new TH1F("fOpAngleBack","",200,0,0.5);
953                 
954                 fOutputList->Add(fInvMass);
955                 fOutputList->Add(fInvMassBack);
956                 fOutputList->Add(fDCA);
957                 fOutputList->Add(fDCABack);
958                 fOutputList->Add(fOpAngle);
959                 fOutputList->Add(fOpAngleBack);
960                 
961                         //histos for TPC-only
962                 fInvMass2 = new TH1F("fInvMass2","",200,0,0.3);
963                 fInvMassBack2 = new TH1F("fInvMassBack2","",200,0,0.3);
964                 fDCA2 = new TH1F("fDCA2","",200,0,1);
965                 fDCABack2 = new TH1F("fDCABack2","",200,0,1);
966                 fOpAngle2 = new TH1F("fOpAngle2","",200,0,0.5);
967                 fOpAngleBack2 = new TH1F("fOpAngleBack2","",200,0,0.5);
968                 
969                 fOutputList->Add(fInvMass2);
970                 fOutputList->Add(fInvMassBack2);
971                 fOutputList->Add(fDCA2);
972                 fOutputList->Add(fDCABack2);
973                 fOutputList->Add(fOpAngle2);
974                 fOutputList->Add(fOpAngleBack2);
975                 
976         }
977         
978         for(Int_t i = 0; i < 6; i++)
979         {
980                 fEoverP_tpc[i] = new TH2F(Form("fEoverP_tpc%d",i),Form("%d < p_{t} < %d GeV/c;TPC Electron N#sigma;E / p ",fPtBin[i],fPtBin[i+1]),1000,-15,15,100,0,2);
981                 fTPC_pt[i] = new TH1F(Form("fTPC_pt%d",i),Form("%d < p_{t} < %d GeV/c;TPC Electron N#sigma;Count",fPtBin[i],fPtBin[i+1]),200,20,200);
982                 fTPCnsigma_pt[i] = new TH1F(Form("fTPCnsigma_pt%d",i),Form("%d < p_{t} < %d GeV/c;TPC Electron N#sigma;Count",fPtBin[i],fPtBin[i+1]),200,-15,10);
983                 
984                 fEta[i]=new TH1F(Form("fEta%d",i), Form("%d < p_{t} < %d GeV/c;#eta; counts",fPtBin[i],fPtBin[i+1]),100, -0.1,0.1);
985                 fPhi[i]=new TH1F(Form("fPhi%d",i),Form("%d < p_{t} < %d GeV/c;#phi; counts )",fPtBin[i],fPtBin[i+1]), 100, -0.1,0.1);
986                 fR[i]=new TH1F(Form("fR%d",i),Form("%d < p_{t} < %d GeV/c;R;counts )",fPtBin[i],fPtBin[i+1]), 100, -0.1,0.1);
987                 fR_EoverP[i]=new TH2F(Form("fR_EoverP%d",i),Form("%d < p_{t} < %d GeV/c;R;E / p ",fPtBin[i],fPtBin[i+1]),100, 0,0.1,1000,0,10);
988                 fNcells[i]=new TH1F(Form("fNcells%d",i), Form("%d < p_{t} < %d GeV/c;ncells;counts ",fPtBin[i],fPtBin[i+1]),100, 0, 30);
989                 fNcells_electrons[i]=new TH1F(Form("fNcells_electrons%d",i), Form("%d < p_{t} < %d GeV/c;ncells;counts ",fPtBin[i],fPtBin[i+1]),100, 0, 30);
990                 fNcells_hadrons[i]=new TH1F(Form("fNcells_hadrons%d",i), Form("%d < p_{t} < %d GeV/c;ncells;counts ",fPtBin[i],fPtBin[i+1]),100, 0, 30);
991                 fNcells_EoverP[i]=new TH2F(Form("fNcells_EoverP%d",i),Form("%d < p_{t} < %d GeV/c; Ncells; E / p ",fPtBin[i],fPtBin[i+1]),1000, 0,20,100,0,30);
992                 fM02_EoverP[i]= new TH2F(Form("fM02_EoverP%d",i),Form("%d < p_{t} < %d GeV/c; M02; E / p ",fPtBin[i],fPtBin[i+1]),1000,0,100,100,0,2);
993                 fM20_EoverP[i]= new TH2F(Form("fM20_EoverP%d",i),Form("%d < p_{t} < %d GeV/c; M20; E / p ",fPtBin[i],fPtBin[i+1]),1000,0,100,100,0,2);
994                 fEoverP_ptbins[i] = new TH1F(Form("fEoverP_ptbins%d",i),Form("%d < p_{t} < %d GeV/c;E / p ",fPtBin[i],fPtBin[i+1]),500,0,2);
995                 fECluster_ptbins[i]= new TH1F(Form("fECluster_ptbins%d",i), Form("%d < p_{t} < %d GeV/c;ECluster; Counts ",fPtBin[i],fPtBin[i+1]),2000, 0,100);
996                 fEoverP_wSSCut[i]=new TH1F(Form("fEoverP_wSSCut%d",i),Form("%d < p_{t} < %d GeV/c;E / p ; Counts",fPtBin[i],fPtBin[i+1]),500,0,2);
997                 fTPCnsigma_eta_electrons[i]=new TH2F(Form("fTPCnsigma_eta_electrons%d",i),Form("%d < p_{t} < %d GeV/c;TPC Electron N#sigma;Eta ",fPtBin[i],fPtBin[i+1]),1000,-15,15,100,-1,1);
998                 fTPCnsigma_eta_hadrons[i]=new TH2F(Form("fTPCnsigma_eta_hadrons%d",i),Form("%d < p_{t} < %d GeV/c;TPC Electron N#sigma;Eta ",fPtBin[i],fPtBin[i+1]),1000,-15,15,100,-1,1);
999                 
1000                 fOutputList->Add(fEoverP_tpc[i]);
1001                 fOutputList->Add(fTPC_pt[i]);
1002                 fOutputList->Add(fTPCnsigma_pt[i]);
1003                 
1004                 fOutputList->Add(fEta[i]);
1005                 fOutputList->Add(fPhi[i]);
1006                 fOutputList->Add(fR[i]);
1007                 fOutputList->Add(fR_EoverP[i]);
1008                 fOutputList->Add(fNcells[i]);
1009                 fOutputList->Add(fNcells_electrons[i]);
1010                 fOutputList->Add(fNcells_hadrons[i]);
1011                 fOutputList->Add(fNcells_EoverP[i]);
1012                 fOutputList->Add(fECluster_ptbins[i]);
1013                 fOutputList->Add(fEoverP_ptbins[i]);
1014                 fOutputList->Add(fEoverP_wSSCut[i]);
1015                 fOutputList->Add(fM02_EoverP[i]);
1016                 fOutputList->Add(fM20_EoverP[i]);
1017                 fOutputList->Add(fTPCnsigma_eta_electrons[i]);
1018                 fOutputList->Add(fTPCnsigma_eta_hadrons[i]);
1019                 
1020                 
1021                 if(fCorrelationFlag)
1022                 {
1023                         fCEtaPhi_Inc[i] = new TH2F(Form("fCEtaPhi_Inc%d",i),Form("%d < p_{t} < %d GeV/c;#DeltaPhi (rad);#Delta#eta",fPtBin[i],fPtBin[i+1]),200,-0.5*TMath::Pi(),1.5*TMath::Pi(),200,-2,2);
1024                         fCEtaPhi_Inc_DiHadron[i] = new TH2F(Form("fCEtaPhi_Inc_DiHadron%d",i),Form("%d < p_{t} < %d GeV/c;#DeltaPhi (rad);#Delta#eta",fPtBin[i],fPtBin[i+1]),200,-0.5*TMath::Pi(),1.5*TMath::Pi(),200,-2,2);
1025                         
1026                         fCEtaPhi_ULS[i] = new TH2F(Form("fCEtaPhi_ULS%d",i),Form("%d < p_{t} < %d GeV/c;#DeltaPhi (rad);#Delta#eta",fPtBin[i],fPtBin[i+1]),200,-0.5*TMath::Pi(),1.5*TMath::Pi(),200,-2,2);
1027                         fCEtaPhi_LS[i] = new TH2F(Form("fCEtaPhi_LS%d",i),Form("%d < p_{t} < %d GeV/c;#DeltaPhi (rad);#Delta#eta",fPtBin[i],fPtBin[i+1]),200,-0.5*TMath::Pi(),1.5*TMath::Pi(),200,-2,2);
1028                         fCEtaPhi_ULS_NoP[i] = new TH2F(Form("fCEtaPhi_ULS_NoP%d",i),Form("%d < p_{t} < %d GeV/c;#DeltaPhi (rad);#Delta#eta",fPtBin[i],fPtBin[i+1]),200,-0.5*TMath::Pi(),1.5*TMath::Pi(),200,-2,2);
1029                         fCEtaPhi_LS_NoP[i] = new TH2F(Form("fCEtaPhi_LS_NoP%d",i),Form("%d < p_{t} < %d GeV/c;#DeltaPhi (rad);#Delta#eta",fPtBin[i],fPtBin[i+1]),200,-0.5*TMath::Pi(),1.5*TMath::Pi(),200,-2,2);
1030                         
1031                         fCEtaPhi_ULS_Weight[i] = new TH2F(Form("fCEtaPhi_ULS_Weight%d",i),Form("%d < p_{t} < %d GeV/c;#DeltaPhi (rad);#Delta#eta",fPtBin[i],fPtBin[i+1]),200,-0.5*TMath::Pi(),1.5*TMath::Pi(),200,-2,2);
1032                         fCEtaPhi_LS_Weight[i] = new TH2F(Form("fCEtaPhi_LS_Weight%d",i),Form("%d < p_{t} < %d GeV/c;#DeltaPhi (rad);#Delta#eta",fPtBin[i],fPtBin[i+1]),200,-0.5*TMath::Pi(),1.5*TMath::Pi(),200,-2,2);
1033                         fCEtaPhi_ULS_NoP_Weight[i] = new TH2F(Form("fCEtaPhi_ULS_NoP_Weight%d",i),Form("%d < p_{t} < %d GeV/c;#DeltaPhi (rad);#Delta#eta",fPtBin[i],fPtBin[i+1]),200,-0.5*TMath::Pi(),1.5*TMath::Pi(),200,-2,2);
1034                         fCEtaPhi_LS_NoP_Weight[i] = new TH2F(Form("fCEtaPhi_LS_NoP_Weight%d",i),Form("%d < p_{t} < %d GeV/c;#DeltaPhi (rad);#Delta#eta",fPtBin[i],fPtBin[i+1]),200,-0.5*TMath::Pi(),1.5*TMath::Pi(),200,-2,2);
1035                         
1036                         fOutputList->Add(fCEtaPhi_Inc[i]);
1037                         fOutputList->Add(fCEtaPhi_Inc_DiHadron[i]);
1038                         
1039                         fOutputList->Add(fCEtaPhi_ULS[i]);
1040                         fOutputList->Add(fCEtaPhi_LS[i]);
1041                         fOutputList->Add(fCEtaPhi_ULS_NoP[i]);
1042                         fOutputList->Add(fCEtaPhi_LS_NoP[i]);
1043                         
1044                         fOutputList->Add(fCEtaPhi_ULS_Weight[i]);
1045                         fOutputList->Add(fCEtaPhi_LS_Weight[i]);
1046                         fOutputList->Add(fCEtaPhi_ULS_NoP_Weight[i]);
1047                         fOutputList->Add(fCEtaPhi_LS_NoP_Weight[i]);
1048                         
1049                         if(fEventMixingFlag)
1050                         {
1051                                 fCEtaPhi_Inc_EM[i] = new TH2F(Form("fCEtaPhi_Inc_EM%d",i),Form("%d < p_{t} < %d GeV/c;#DeltaPhi (rad);#Delta#eta",fPtBin[i],fPtBin[i+1]),200,-0.5*TMath::Pi(),1.5*TMath::Pi(),200,-2,2);
1052                                 
1053                                 fCEtaPhi_ULS_EM[i] = new TH2F(Form("fCEtaPhi_ULS_EM%d",i),Form("%d < p_{t} < %d GeV/c;#DeltaPhi (rad);#Delta#eta",fPtBin[i],fPtBin[i+1]),200,-0.5*TMath::Pi(),1.5*TMath::Pi(),200,-2,2);
1054                                 fCEtaPhi_LS_EM[i] = new TH2F(Form("fCEtaPhi_LS_EM%d",i),Form("%d < p_{t} < %d GeV/c;#DeltaPhi (rad);#Delta#eta",fPtBin[i],fPtBin[i+1]),200,-0.5*TMath::Pi(),1.5*TMath::Pi(),200,-2,2);
1055                                 
1056                                 fCEtaPhi_ULS_Weight_EM[i] = new TH2F(Form("fCEtaPhi_ULS_Weight_EM%d",i),Form("%d < p_{t} < %d GeV/c;#DeltaPhi (rad);#Delta#eta",fPtBin[i],fPtBin[i+1]),200,-0.5*TMath::Pi(),1.5*TMath::Pi(),200,-2,2);
1057                                 fCEtaPhi_LS_Weight_EM[i] = new TH2F(Form("fCEtaPhi_LS_Weight_EM%d",i),Form("%d < p_{t} < %d GeV/c;#DeltaPhi (rad);#Delta#eta",fPtBin[i],fPtBin[i+1]),200,-0.5*TMath::Pi(),1.5*TMath::Pi(),200,-2,2);
1058                                 
1059                                 fOutputList->Add(fCEtaPhi_Inc_EM[i]);
1060                                 
1061                                 fOutputList->Add(fCEtaPhi_ULS_EM[i]);
1062                                 fOutputList->Add(fCEtaPhi_LS_EM[i]);
1063                                 
1064                                 fOutputList->Add(fCEtaPhi_ULS_Weight_EM[i]);
1065                                 fOutputList->Add(fCEtaPhi_LS_Weight_EM[i]);
1066                         }
1067                 }
1068         }
1069         
1070                 //pt integrated
1071         fTPCnsigma_eta = new TH2F("fTPCnsigma_eta",";Pseudorapidity #eta; TPC signal - <TPC signal>_{elec} (#sigma)",200,-0.9,0.9,200,-15,15);
1072         fTPCnsigma_phi = new TH2F("fTPCnsigma_phi",";Azimuthal Angle #phi; TPC signal - <TPC signal>_{elec} (#sigma)",200,0,2*TMath::Pi(),200,-15,15);
1073         
1074         
1075         
1076         fNcells_pt=new TH2F("fNcells_pt","fNcells_pt",1000, 0,20,100,0,30);
1077         fEoverP_pt_pions= new TH2F("fEoverP_pt_pions","fEoverP_pt_pions",1000,0,30,500,0,2);
1078         
1079         ftpc_p_EoverPcut= new TH2F("ftpc_p_EoverPcut","ftpc_p_EoverPcut",1000,0,30,200,20,200);
1080         fnsigma_p_EoverPcut= new TH2F("fnsigma_p_EoverPcut","fnsigma_p_EoverPcut",1000,0,30,500,-15,15);
1081         
1082         fEoverP_pt_pions2= new TH2F("fEoverP_pt_pions2","fEoverP_pt_pions2",1000,0,30,500,0,2);
1083         fEoverP_pt_hadrons= new TH2F("fEoverP_pt_hadrons","fEoverP_pt_hadrons",1000,0,30,500,0,2);
1084         
1085         
1086         fOutputList->Add(fTPCnsigma_eta);
1087         fOutputList->Add(fTPCnsigma_phi);
1088         
1089         fOutputList->Add(fNcells_pt);
1090         fOutputList->Add(fEoverP_pt_pions);
1091         
1092         fOutputList->Add(ftpc_p_EoverPcut);
1093         fOutputList->Add(fnsigma_p_EoverPcut);
1094         
1095         fOutputList->Add(fEoverP_pt_pions2);
1096         fOutputList->Add(fEoverP_pt_hadrons);
1097         
1098         fOutputList->Add(fVtxZ_new1);
1099         fOutputList->Add(fVtxZ_new2);
1100         fOutputList->Add(fVtxZ_new3);
1101         fOutputList->Add(fVtxZ_new4);
1102         
1103         
1104
1105         
1106                 //__________________________________________________________________
1107                 //Efficiency studies
1108         if(fIsMC)
1109         {
1110                 fPtBackgroundBeforeReco = new TH1F("fPtBackgroundBeforeReco",";p_{T} (GeV/c);Count",300,0,30);
1111                 fPtBackgroundBeforeReco_weight = new TH1F("fPtBackgroundBeforeReco_weight",";p_{T} (GeV/c);Count",300,0,30);
1112                 if(fFillBackground)fPtBackgroundBeforeReco2 = new TH1F("fPtBackgroundBeforeReco2",";p_{T} (GeV/c);Count",300,0,30);
1113                 if(fFillBackground)fPtBackgroundBeforeReco2_weight = new TH1F("fPtBackgroundBeforeReco2_weight",";p_{T} (GeV/c);Count",300,0,30);
1114                 fpT_m_electron= new TH2F("fpT_m_electron","fpT_m_electron",300,0,30,300,0,30);
1115                 fpT_gm_electron= new TH2F("fpT_gm_electron","fpT_gm_electron",300,0,30,300,0,30);
1116                 
1117                 fPtBackgroundAfterReco = new TH1F("fPtBackgroundAfterReco",";p_{T} (GeV/c);Count",300,0,30);    
1118                 fPtMCparticleAll = new TH1F("fPtMCparticleAll",";p_{T} (GeV/c);Count",200,0,40);        
1119                 fPtMCparticleReco = new TH1F("fPtMCparticleReco",";p_{T} (GeV/c);Count",200,0,40);
1120                 
1121                 fPtMCparticleAll_nonPrimary = new TH1F("fPtMCparticleAll_nonPrimary",";p_{T} (GeV/c);Count",200,0,40);  
1122                 fPtMCparticleAlle_nonPrimary = new TH1F("fPtMCparticleAlle_nonPrimary",";p_{T} (GeV/c);Count",200,0,40);
1123                 fPtMCparticleAlle_Primary = new TH1F("fPtMCparticleAlle_Primary",";p_{T} (GeV/c);Count",200,0,40);
1124                 
1125                 fPtMCparticleReco_nonPrimary = new TH1F("fPtMCparticleReco_nonPrimary",";p_{T} (GeV/c);Count",200,0,40);
1126                 
1127                 fPtMCparticleAllHfe1 = new TH1F("fPtMCparticleAllHfe1",";p_{t} (GeV/c);Count",200,0,40);
1128                 fPtMCparticleRecoHfe1 = new TH1F("fPtMCparticleRecoHfe1",";p_{t} (GeV/c);Count",200,0,40);
1129                 fPtMCparticleAllHfe2 = new TH1F("fPtMCparticleAllHfe2",";p_{t} (GeV/c);Count",200,0,40);
1130                 fPtMCparticleRecoHfe2 = new TH1F("fPtMCparticleRecoHfe2",";p_{t} (GeV/c);Count",200,0,40);
1131                 
1132                 fPtMCelectronAfterAll = new TH1F("fPtMCelectronAfterAll",";p_{T} (GeV/c);Count",200,0,40);
1133                 fPtMCelectronAfterAll_unfolding = new TH1F("fPtMCelectronAfterAll_unfolding",";p_{T} (GeV/c);Count",200,0,40);
1134                 fPtMCelectronAfterAll_nonPrimary = new TH1F("fPtMCelectronAfterAll_nonPrimary",";p_{T} (GeV/c);Count",200,0,40);
1135                 fPtMCelectronAfterAll_Primary = new TH1F("fPtMCelectronAfterAll_Primary",";p_{T} (GeV/c);Count",200,0,40);
1136                 
1137
1138                 
1139                 fPtMCpi0 = new TH1F("fPtMCpi0",";p_{t} (GeV/c);Count",200,0,30);
1140                 fPtMCeta = new TH1F("fPtMCeta",";p_{T} (GeV/c);Count",200,0,30);
1141                 fPtMCpi02 = new TH1F("fPtMCpi02",";p_{t} (GeV/c);Count",200,0,30);
1142                 fPtMCeta2 = new TH1F("fPtMCeta2",";p_{T} (GeV/c);Count",200,0,30);
1143                 fPtMC_EMCal_All= new TH1F("fPtMC_EMCal_All",";p_{t} (GeV/c);Count",200,0,40);
1144                 fPtMC_EMCal_Selected= new TH1F("fPtMC_EMCal_Selected",";p_{t} (GeV/c);Count",200,0,40);
1145                 fPtMC_TPC_All= new TH1F("fPtMC_TPC_All",";p_{T} (GeV/c);Count",200,0,40);
1146                 fPtMC_TPC_Selected = new TH1F("fPtMC_TPC_Selected",";p_{T} (GeV/c);Count",200,0,40);
1147                 
1148                 fPt_track_match_den = new TH1F("fPt_track_match_den",";p_{T} (GeV/c);Count",200,0,40);
1149                 fPt_track_match_num = new TH1F("fPt_track_match_num",";p_{T} (GeV/c);Count",200,0,40);
1150                 
1151                 fPtMCWithLabel = new TH1F("fPtMCWithLabel",";p_{t} (GeV/c);Count",200,0,40);
1152                 fPtMCWithoutLabel = new TH1F("fPtMCWithoutLabel",";p_{t} (GeV/c);Count",200,0,40);
1153                 fPtIsPhysicaPrimary = new TH1F("fPtIsPhysicaPrimary",";p_{t} (GeV/c);Count",200,0,40);
1154                 
1155                 fOutputList->Add(fPtBackgroundBeforeReco);
1156                 fOutputList->Add(fPtBackgroundBeforeReco_weight);
1157                 
1158                 if(fFillBackground) fOutputList->Add(fPtBackgroundBeforeReco2);
1159                 if(fFillBackground) fOutputList->Add(fPtBackgroundBeforeReco2_weight);
1160                 
1161                 fOutputList->Add(fpT_m_electron);
1162                 fOutputList->Add(fpT_gm_electron);
1163                 
1164                 fOutputList->Add(fPtBackgroundAfterReco);
1165                 fOutputList->Add(fPtMCparticleAll);
1166                 fOutputList->Add(fPtMCparticleReco);
1167                 
1168                 fOutputList->Add(fPtMCparticleAll_nonPrimary);
1169                 fOutputList->Add(fPtMCparticleAlle_nonPrimary);
1170                 
1171                 fOutputList->Add(fPtMCparticleAlle_Primary);
1172                 fOutputList->Add(fPtMCparticleReco_nonPrimary);
1173                 
1174                 fOutputList->Add(fPtMCparticleAllHfe1);
1175                 fOutputList->Add(fPtMCparticleRecoHfe1);
1176                 fOutputList->Add(fPtMCparticleAllHfe2);
1177                 fOutputList->Add(fPtMCparticleRecoHfe2);
1178                 fOutputList->Add(fPtMCelectronAfterAll);
1179                 fOutputList->Add(fPtMCelectronAfterAll_unfolding);
1180                 
1181                 fOutputList->Add(fPtMCelectronAfterAll_nonPrimary);
1182                 fOutputList->Add(fPtMCelectronAfterAll_Primary);
1183                 
1184                 
1185                 
1186                 fOutputList->Add(fPtMCpi0);
1187                 fOutputList->Add(fPtMCeta);
1188                 fOutputList->Add(fPtMCpi02);
1189                 fOutputList->Add(fPtMCeta2);
1190                 fOutputList->Add(fPtMC_EMCal_All);
1191                 fOutputList->Add(fPtMC_EMCal_Selected);
1192                 fOutputList->Add(fPtMC_TPC_All);
1193                 fOutputList->Add(fPtMC_TPC_Selected);
1194                 
1195                 fOutputList->Add(fPt_track_match_den);
1196                 fOutputList->Add(fPt_track_match_num);
1197                 
1198                 fOutputList->Add(fPtMCWithLabel);
1199                 fOutputList->Add(fPtMCWithoutLabel);
1200                 fOutputList->Add(fPtIsPhysicaPrimary);
1201         }
1202         
1203         fCentralityHist = new TH1F("fCentralityHist",";Centrality (%); Count",1000000,0,100);
1204         fCentralityHistPass = new TH1F("fCentralityHistPass",";Centrality (%); Count",1000000,0,100);
1205         fOutputList->Add(fCentralityHist);
1206         fOutputList->Add(fCentralityHistPass);
1207         
1208                 //______________________________________________________________________
1209                 //Mixed event analysis
1210         if(fEventMixingFlag)
1211         {
1212                 fPoolNevents = new TH1F("fPoolNevents","Event Mixing Statistics; Number of events; Count",1000,0,1000);
1213                 fOutputList->Add(fPoolNevents);
1214                 
1215                 Int_t trackDepth = 2000; // number of objects (tracks) kept per event buffer bin. Once the number of stored objects (tracks) is above that limit, the oldest ones are removed.
1216                 Int_t poolsize   = 1000;  // Maximum number of events, ignored in the present implemented of AliEventPoolManager
1217                 
1218                 Int_t nCentralityBins  = 15;
1219                 Double_t centralityBins[] = { 0, 1, 2, 3, 4, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100.1 };
1220                 
1221                 Int_t nZvtxBins  = 9;
1222                 Double_t vertexBins[] = {-10, -7, -5, -3, -1, 1, 3, 5, 7, 10};
1223                 
1224                 fPoolMgr = new AliEventPoolManager(poolsize, trackDepth, nCentralityBins, (Double_t*) centralityBins, nZvtxBins, (Double_t*) vertexBins);
1225         }
1226                 //______________________________________________________________________
1227         
1228         PostData(1, fOutputList);
1229         
1230                 ///______________________________________________________________________
1231 }
1232
1233 //______________________________________________________________________
1234 //Main loop
1235 //Called for each event
1236 void AliAnalysisTaskEMCalHFEpA::UserExec(Option_t *) 
1237 {
1238                 //Check Event
1239         fESD = dynamic_cast<AliESDEvent*>(InputEvent());
1240         fAOD = dynamic_cast<AliAODEvent*>(InputEvent());
1241         
1242         if(!(fESD || fAOD))
1243         {
1244                 printf("ERROR: fESD & fAOD not available\n");
1245                 return;
1246         }
1247         
1248         fVevent = dynamic_cast<AliVEvent*>(InputEvent());
1249         
1250         if(!fVevent) 
1251         {
1252                 printf("ERROR: fVEvent not available\n");
1253                 return;
1254         }
1255         
1256                 //Check Cuts    
1257         if(!fCuts)
1258         {
1259                 AliError("HFE cuts not available");
1260                 return;
1261         }
1262                 //Check PID
1263         if(!fPID->IsInitialized())
1264         { 
1265                         // Initialize PID with the given run number
1266                 AliWarning("PID not initialised, get from Run no");
1267                 
1268                 if(fIsAOD)      
1269                 {
1270                         fPID->InitializePID(fAOD->GetRunNumber());
1271                 }
1272                 else 
1273                 {
1274                         fPID->InitializePID(fESD->GetRunNumber());
1275                 }
1276         }
1277         
1278                 //PID response
1279         fPidResponse = fInputHandler->GetPIDResponse();
1280         
1281         
1282                 //Check PID response
1283         if(!fPidResponse)
1284         {
1285                 AliDebug(1, "Using default PID Response");
1286                 fPidResponse = AliHFEtools::GetDefaultPID(kFALSE, fInputEvent->IsA() == AliAODEvent::Class()); 
1287         }
1288         
1289         fPID->SetPIDResponse(fPidResponse);
1290         
1291         fCFM->SetRecEventInfo(fVevent); 
1292         
1293         Double_t *fListOfmotherkink = 0;
1294         Int_t fNumberOfVertices = 0; 
1295         Int_t fNumberOfMotherkink = 0;
1296         
1297                 //______________________________________________________________________
1298                 //Vertex Selection
1299         if(fIsAOD)
1300         {
1301                         
1302                 const AliAODVertex* trkVtx = fAOD->GetPrimaryVertex();
1303                 if(!trkVtx || trkVtx->GetNContributors()<=0) return;
1304                 TString vtxTtl = trkVtx->GetTitle();
1305                 if(!vtxTtl.Contains("VertexerTracks")) return;
1306                 Float_t zvtx = trkVtx->GetZ();
1307                 fZvtx = zvtx;
1308                 
1309                 fVtxZ_new1->Fill(fZvtx);
1310                 
1311                 const AliAODVertex* spdVtx = fAOD->GetPrimaryVertexSPD();
1312                 if(spdVtx->GetNContributors()<=0) return;
1313                 TString vtxTyp = spdVtx->GetTitle();
1314                 Double_t cov[6]={0};
1315                 spdVtx->GetCovarianceMatrix(cov);
1316                 Double_t zRes = TMath::Sqrt(cov[5]);
1317                 if(vtxTyp.Contains("vertexer:Z") && (zRes>0.25)) return;
1318                 if(TMath::Abs(spdVtx->GetZ() - trkVtx->GetZ())>0.5) return;
1319                 if(TMath::Abs(zvtx) > 10) return;
1320                 
1321                 fVtxZ_new2->Fill(fZvtx);
1322                 
1323                         //Look for kink mother for AOD
1324                 
1325                 fNumberOfVertices = 0; 
1326                 fNumberOfMotherkink = 0;
1327                 
1328                 if(fIsAOD)
1329                 {
1330                         fNumberOfVertices = fAOD->GetNumberOfVertices();
1331                         
1332                         fListOfmotherkink = new Double_t[fNumberOfVertices];
1333                         
1334                         for(Int_t ivertex=0; ivertex < fNumberOfVertices; ivertex++) 
1335                         {
1336                                 AliAODVertex *aodvertex = fAOD->GetVertex(ivertex);
1337                                 if(!aodvertex) continue;
1338                                 if(aodvertex->GetType()==AliAODVertex::kKink) 
1339                                 {
1340                                         AliAODTrack *mother1 = (AliAODTrack *) aodvertex->GetParent();
1341                                         if(!mother1) continue;
1342                                         Int_t idmother = mother1->GetID();
1343                                         fListOfmotherkink[fNumberOfMotherkink] = idmother;
1344                                         fNumberOfMotherkink++;
1345                                 }
1346                         }
1347                 }
1348         }
1349         else
1350         {
1351                 
1352                 
1353                 
1354                 /// ESD
1355                 const AliESDVertex* trkVtx = fESD->GetPrimaryVertex();
1356                 if(!trkVtx || trkVtx->GetNContributors()<=0) return;
1357                 TString vtxTtl = trkVtx->GetTitle();
1358                 if(!vtxTtl.Contains("VertexerTracks")) return;
1359                 Float_t zvtx = trkVtx->GetZ();
1360                 
1361                 const AliESDVertex* spdVtx = fESD->GetPrimaryVertexSPD();
1362                 if(spdVtx->GetNContributors()<=0) return;
1363                 TString vtxTyp = spdVtx->GetTitle();
1364                 Double_t cov[6]={0};
1365                 spdVtx->GetCovarianceMatrix(cov);
1366                 Double_t zRes = TMath::Sqrt(cov[5]);
1367                 if(vtxTyp.Contains("vertexer:Z") && (zRes>0.25)) return;
1368                 if(TMath::Abs(spdVtx->GetZ() - trkVtx->GetZ())>0.5) return;
1369                 if(TMath::Abs(zvtx) > 10) return;
1370         }
1371         
1372                 //______________________________________________________________________
1373         
1374         
1375                 
1376                 //Only events with at least 2 tracks are accepted
1377         Int_t fNOtrks =  fVevent->GetNumberOfTracks();
1378         
1379         //if(fIsAOD) Int_t fNOtrks =  fAOD->GetNumberOfTracks();
1380         //if(!fIsAOD) Int_t fNOtrks =  fESD->GetNumberOfTracks();
1381         
1382                 //commented to test
1383         if(fNOtrks<2) return;
1384
1385         
1386         //new track loop to select events
1387         
1388         fNevent->Fill(13);
1389         /*
1390         if(fUseTrigger){
1391                 if(fIsAOD){
1392                         double fTrackMulti=0;
1393                         for(Int_t iTracks = 0; iTracks < fVevent->GetNumberOfTracks(); iTracks++) 
1394                         {
1395                                 AliVParticle* Vtrack = fVevent->GetTrack(iTracks);
1396                                 if (!Vtrack) 
1397                                 {
1398                                         printf("ERROR: Could not receive track %d\n", iTracks);
1399                                         continue;
1400                                 }
1401                 
1402                                 AliVTrack *track = dynamic_cast<AliVTrack*>(Vtrack);
1403                                         //AliESDtrack *etrack = dynamic_cast<AliESDtrack*>(Vtrack);
1404                                 AliAODTrack *atrack = dynamic_cast<AliAODTrack*>(Vtrack);
1405                 
1406                                 if((track->Pt())<0.2 || (track->Pt())>1000.0) continue;
1407                                 //if it is not a hybrid track, continue
1408                                 if(!atrack->TestFilterBit(768)) continue;
1409                                 else fTrackMulti=fTrackMulti+1;
1410                 
1411                         }
1412                                 //Only take event if track multiplicity is bigger than 2.
1413                         if(fTrackMulti<2) return;
1414                 }
1415         }
1416          */
1417         
1418         fVtxZ_new3->Fill(fZvtx);
1419         
1420         fNevent->Fill(14);
1421         
1422                 
1423         //trying to use same as Lucile
1424         /*if(fIsAOD) {
1425                         //reader = new AliCaloTrackAODReader();
1426                 reader->SwitchOnCTS();
1427                 reader->SetCTSPtMin(0.2);
1428                 reader->SetCTSPtMax(1000);      
1429                 reader->SwitchOffRecalculateVertexBC();
1430                 reader->SwitchOffVertexBCEventSelection();
1431                 reader->SwitchOffUseTrackTimeCut();     
1432                 reader->SwitchOffUseTrackDCACut();      
1433                 reader->SwitchOnAODHybridTrackSelection();
1434                 reader->SwitchOnRejectNoTrackEvents();
1435         }*/
1436         
1437         
1438                 //______________________________________________________________________
1439                 //Centrality Selection
1440         if(fHasCentralitySelection)
1441         {
1442                 Float_t centrality = -1;
1443                 
1444                 if(fIsAOD) 
1445                 {
1446                         fCentrality = fAOD->GetHeader()->GetCentralityP();
1447                 }
1448                 else
1449                 {
1450                         fCentrality = fESD->GetCentrality();
1451                 }
1452                 
1453                 if(fEstimator==1) centrality = fCentrality->GetCentralityPercentile("ZDC");
1454                 else centrality = fCentrality->GetCentralityPercentile("V0A");
1455                 
1456                         //cout << "Centrality = " << centrality << " %" << endl;
1457                 
1458                 fCentralityHist->Fill(centrality);
1459                 
1460                 if(centrality<fCentralityMin || centrality>fCentralityMax) return;
1461                 
1462                 fCentralityHistPass->Fill(centrality);
1463         }
1464                 //______________________________________________________________________
1465         
1466                 //______________________________________________________________________
1467         
1468         if(fIsMC)
1469         {
1470                 if(fIsAOD)
1471                 {       
1472                         fMCarray = dynamic_cast<TClonesArray*>(fAOD->FindListObject(AliAODMCParticle::StdBranchName()));
1473                         
1474                         if(!fMCarray)
1475                         {
1476                                 AliError("Array of MC particles not found");
1477                                 return;
1478                         }
1479                         
1480                         fMCheader = dynamic_cast<AliAODMCHeader*>(fAOD->GetList()->FindObject(AliAODMCHeader::StdBranchName()));
1481                         
1482                         if(!fMCheader) 
1483                         {
1484                                 AliError("Could not find MC Header in AOD");
1485                                 return;
1486                         }
1487                         
1488                         for(Int_t iMC = 0; iMC < fMCarray->GetEntries(); iMC++)
1489                         {
1490                                 fMCparticle = (AliAODMCParticle*) fMCarray->At(iMC);
1491                                 if(fMCparticle->GetMother()>0) fMCparticleMother = (AliAODMCParticle*) fMCarray->At(fMCparticle->GetMother());
1492                                                                 
1493                                 Int_t pdg = fMCparticle->GetPdgCode();
1494                                 
1495                                                         
1496                                 double proX = fMCparticle->Xv();
1497                                 double proY = fMCparticle->Yv();
1498                                 double proR = sqrt(pow(proX,2)+pow(proY,2));
1499                                 
1500                                 
1501                                 if(fMCparticle->Eta()>=fEtaCutMin && fMCparticle->Eta()<=fEtaCutMax && fMCparticle->Charge()!=0)
1502                                 {
1503                                                 //to correct background
1504                                         if (TMath::Abs(pdg) == 11 && fMCparticle->GetMother()>0){
1505                                                 Int_t mpdg = fMCparticleMother->GetPdgCode();
1506
1507                                                 if(TMath::Abs(mpdg) == 221 || TMath::Abs(mpdg) == 22 || TMath::Abs(mpdg) == 111){
1508                                                 
1509                                                         if(proR<7){
1510                                                                 fPtMCparticleAlle_nonPrimary->Fill(fMCparticle->Pt()); //denominator for total efficiency for all electrons, and not primary
1511                                                 
1512                                                         }
1513                                                 }
1514                                         }
1515                                         
1516                                         if (TMath::Abs(pdg) == 11 && fMCparticle->IsPhysicalPrimary()) fPtMCparticleAlle_Primary->Fill(fMCparticle->Pt()); //denominator for total efficiency for all electrons primary
1517                                         
1518                                         if( TMath::Abs(pdg) == 211 || TMath::Abs(pdg) == 2212 || TMath::Abs(pdg) == 321 || TMath::Abs(pdg) == 11 || TMath::Abs(pdg) == 13 ) 
1519                                         {
1520                                                 
1521                                                 fPtMCparticleAll_nonPrimary->Fill(fMCparticle->Pt()); //denominator for total efficiency for all particles, and not primary
1522                                                 if(fMCparticle->IsPhysicalPrimary()) 
1523                                                 {
1524                                                         fPtMCparticleAll->Fill(fMCparticle->Pt());
1525                                                         
1526                                                         Bool_t MotherFound = FindMother(iMC);
1527                                                         //Bool_t MotherFound = FindMother(track->GetLabel());
1528                                                         if(MotherFound)
1529                                                         {
1530                                                                 if(fIsHFE1){
1531                                                                         //denominator for total efficiency and tracking
1532                                                                         //unfolding: denominator is pt_MC and numerator is pt_reco
1533                                                                         fPtMCparticleAllHfe1->Fill(fMCparticle->Pt());
1534                                                                         fEtaPhi_den->Fill(fMCparticle->Phi(),fMCparticle->Eta());
1535                                                                         
1536                                                                 
1537                                                                 } //denominator for total efficiency and tracking
1538                                                                 if(fIsHFE2) fPtMCparticleAllHfe2->Fill(fMCparticle->Pt());
1539                                                         }
1540                                                 }
1541                                         }
1542                                 }//eta cut
1543                                 
1544                                 //only primary pions 
1545                                 if(fMCparticle->IsPhysicalPrimary()){
1546                                         if(TMath::Abs(pdg)==111) fPtMCpi0->Fill(fMCparticle->Pt());
1547                                         if(TMath::Abs(pdg)==221) fPtMCeta->Fill(fMCparticle->Pt());
1548                                         
1549                                         if(fMCparticle->Eta()>=fEtaCutMin && fMCparticle->Eta()<=fEtaCutMax)
1550                                         {
1551                                                 
1552                                                 if(TMath::Abs(pdg)==111) fPtMCpi02->Fill(fMCparticle->Pt());
1553                                                 if(TMath::Abs(pdg)==221) fPtMCeta2->Fill(fMCparticle->Pt());
1554                                                 
1555                                         }
1556                                         
1557                                 }
1558                                 
1559                         }//loop tracks
1560                 }//AOD
1561                 else
1562                 {
1563                         fEventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
1564                         if (!fEventHandler) {
1565                                 Printf("ERROR: Could not retrieve MC event handler");
1566                                 return;
1567                         }
1568                         
1569                         fMCevent = fEventHandler->MCEvent();
1570                         if (!fMCevent) {
1571                                 Printf("ERROR: Could not retrieve MC event");
1572                                 return;
1573                         }
1574                         
1575                         fMCstack = fMCevent->Stack();
1576                         
1577                 for(Int_t iMC = 0; iMC < fMCstack->GetNtrack(); iMC++)
1578                 {
1579                                 
1580                                 fMCtrack = fMCstack->Particle(iMC);
1581                                 if(fMCtrack->GetFirstMother()>0) fMCtrackMother = fMCstack->Particle(fMCtrack->GetFirstMother());
1582                                 TParticle *particle=fMCstack->Particle(iMC);
1583                                 
1584                                 Int_t pdg = fMCtrack->GetPdgCode();
1585                                  
1586                                 
1587                                 if(TMath::Abs(pdg)==111) fPtMCpi0->Fill(fMCtrack->Pt());
1588                                 if(TMath::Abs(pdg)==221) fPtMCeta->Fill(fMCtrack->Pt());
1589                                                 
1590                                 
1591                                 if(fMCtrack->Eta()>=fEtaCutMin && fMCtrack->Eta()<=fEtaCutMax)
1592                                 {
1593                                         
1594                                                 //to correct background
1595                                         if (TMath::Abs(pdg) == 11 && fMCtrack->GetFirstMother()>0){
1596                                                 Int_t mpdg = fMCtrackMother->GetPdgCode();
1597                                                 if(TMath::Abs(mpdg) == 221 || TMath::Abs(mpdg) == 22 || TMath::Abs(mpdg) == 111){
1598                                                                 Double_t proR=particle->R();
1599                                                                 if(proR<7){
1600                                                                         fPtMCparticleAlle_nonPrimary->Fill(fMCtrack->Pt()); //denominator for total efficiency for all electrons, and not primary
1601                                                                 }
1602                                                 }
1603                                         }
1604                                         
1605                                         if(TMath::Abs(pdg) == 11 && fMCstack->IsPhysicalPrimary(iMC)){
1606                                                 
1607                                                 fPtMCparticleAlle_Primary->Fill(fMCtrack->Pt());
1608                                         }
1609                                         
1610                                         if( TMath::Abs(pdg) == 211 || TMath::Abs(pdg) == 2212 || TMath::Abs(pdg) == 321 || TMath::Abs(pdg) == 11 || TMath::Abs(pdg) == 13 )
1611                                         {
1612                                                 fPtMCparticleAll_nonPrimary->Fill(fMCtrack->Pt());//denominator for total efficiency for all particle, non Primary track
1613                                                 
1614                                                 if(fMCstack->IsPhysicalPrimary(iMC))
1615                                                 {
1616                                                         fPtMCparticleAll->Fill(fMCtrack->Pt());
1617                                                 
1618                                                         Bool_t MotherFound = FindMother(iMC);
1619                                                         //Bool_t MotherFound = FindMother(track->GetLabel());
1620                                                         if(MotherFound)
1621                                                         {
1622                                                                 if(fIsHFE1){
1623                                                                         fPtMCparticleAllHfe1->Fill(fMCtrack->Pt());//denominator for total efficiency and tracking
1624                                                                         fEtaPhi_den->Fill(fMCtrack->Phi(),fMCtrack->Eta());
1625                                                                 }
1626                                                                 if(fIsHFE2) fPtMCparticleAllHfe2->Fill(fMCtrack->Pt());
1627                                                         }
1628                                                 }//Is Physical primary
1629                                         }       
1630                                 }//eta cut
1631                 }//loop tracks
1632                 }//ESD
1633         }//Is MC
1634         
1635         //______________________________________________________________________
1636         //EMCal Trigger Selection (Threshold selection)
1637         TString firedTrigger;
1638         TString TriggerEG1("CEMC7EG1"); //takes trigger with name with EG1, ex: CEMC7EG1-B-NOPF-CENTNOTRD  
1639         TString TriggerEG2("CEMC7EG2");
1640         //Jan 17, 2014
1641         TString TriggerEJE("EJE");
1642                 
1643         if(fAOD) firedTrigger = fAOD->GetFiredTriggerClasses();
1644         else if(fESD) firedTrigger = fESD->GetFiredTriggerClasses();
1645         
1646         fNevent->Fill(0);
1647         if(firedTrigger.Contains(TriggerEG1)) fNevent->Fill(1);
1648         if(firedTrigger.Contains(TriggerEG2)) fNevent->Fill(2);
1649         
1650         // Jan 06, 2014: I changed the counters: Only fill with 3 or 4 if we want the trigger threshold selected.
1651         //EG1
1652         if(firedTrigger.Contains(TriggerEG1))
1653         { 
1654                 if(fEMCEG1) fNevent->Fill(3);
1655         }
1656         else 
1657         {
1658                 if(fEMCEG1) return;
1659         }
1660         
1661         //EG2
1662         if(firedTrigger.Contains(TriggerEG2))
1663         { 
1664                 if(fEMCEG2) fNevent->Fill(4);
1665         }
1666         else
1667         { 
1668                 if(fEMCEG2) return;
1669         }
1670         
1671         //______________________________________________________________________
1672         //Testing if there is an overlap EGA and EJE
1673         //none
1674         if(!(firedTrigger.Contains(TriggerEG1) && firedTrigger.Contains(TriggerEG2) ) && !firedTrigger.Contains(TriggerEJE))
1675         { 
1676                 fNevent->Fill(6);
1677         }
1678         //only GA
1679         if((firedTrigger.Contains(TriggerEG1) || firedTrigger.Contains(TriggerEG2)) && !firedTrigger.Contains(TriggerEJE))
1680         { 
1681                 fNevent->Fill(7);
1682         }
1683         //only JE
1684         if(!(firedTrigger.Contains(TriggerEG1) && firedTrigger.Contains(TriggerEG2)) && firedTrigger.Contains(TriggerEJE))
1685         { 
1686                 fNevent->Fill(8);
1687         }
1688         //both
1689         if((firedTrigger.Contains(TriggerEG1) || firedTrigger.Contains(TriggerEG2)) && firedTrigger.Contains(TriggerEJE))
1690         { 
1691                 fNevent->Fill(9);
1692         }
1693         
1694                 
1695         //New cluster information 
1696         //after trigger threshold selection
1697         Int_t ClsNo2 = fVevent->GetNumberOfCaloClusters(); 
1698         
1699         if(ClsNo2<=0){
1700                 fNevent->Fill(11); //events with no cluster
1701                 return;
1702         } 
1703         for (Int_t i=0; i< ClsNo2; i++ ){
1704                 
1705                 fClus = fVevent->GetCaloCluster(i);
1706                 if(fClus->IsEMCAL())
1707                 {
1708                         //pure cluster information
1709                         fECluster_pure->Fill(fClus->E());
1710                 }
1711         }
1712         
1713         fNevent->Fill(12); //events with cluster
1714         
1715         
1716         fVtxZ_new4->Fill(fZvtx);
1717         
1718         //__________________________________________________________________
1719         
1720         Int_t ClsNo = -999;
1721         if(!fIsAOD) ClsNo = fESD->GetNumberOfCaloClusters(); 
1722         else ClsNo = fAOD->GetNumberOfCaloClusters(); 
1723         
1724         //______________________________________________________________________
1725         
1726         ///_____________________________________________________________________
1727         ///Track loop
1728         for(Int_t iTracks = 0; iTracks < fVevent->GetNumberOfTracks(); iTracks++) 
1729         {
1730                 AliVParticle* Vtrack = fVevent->GetTrack(iTracks);
1731                 if (!Vtrack) 
1732                 {
1733                         printf("ERROR: Could not receive track %d\n", iTracks);
1734                         continue;
1735                 }
1736                 
1737                 AliVTrack *track = dynamic_cast<AliVTrack*>(Vtrack);
1738                 AliESDtrack *etrack = dynamic_cast<AliESDtrack*>(Vtrack);
1739                 AliAODTrack *atrack = dynamic_cast<AliAODTrack*>(Vtrack);
1740                 
1741                 //aod test -- Francesco suggestion
1742                 AliAODTrack *aod_track=fAOD->GetTrack(iTracks);
1743                 
1744                 Double_t fTPCnSigma = -999;
1745                 Double_t fTOFnSigma = -999;
1746                 Double_t fTPCnSigma_pion = -999;
1747                 Double_t fTPCnSigma_proton = -999;
1748                 Double_t fTPCnSigma_kaon = -999;
1749                 Double_t fTPCsignal = -999;
1750                 Double_t fPt = -999;
1751                 Double_t fP = -999;
1752                 
1753                 //December 9th 2013
1754                 //Etacut test on the begging
1755                 fEtad[0]->Fill(track->Eta());
1756                         //if(track->Eta()<fEtaCutMin || track->Eta()>fEtaCutMax) continue;
1757                 fEtad[1]->Fill(track->Eta());
1758                 
1759                         
1760                 
1761                 
1762                 ///_____________________________________________________________________________
1763                 ///Fill QA plots without track selection
1764                 fPt = track->Pt();
1765                 fP = TMath::Sqrt((track->Pt())*(track->Pt()) + (track->Pz())*(track->Pz()));
1766                 
1767                 fTPCsignal = track->GetTPCsignal();
1768                 fTPCnSigma = fPidResponse->NumberOfSigmasTPC(track, AliPID::kElectron);
1769                 fTOFnSigma = fPidResponse->NumberOfSigmasTOF(track, AliPID::kElectron);
1770                 fTPCnSigma_pion = fPidResponse->NumberOfSigmasTPC(track, AliPID::kPion);
1771                 fTPCnSigma_proton = fPidResponse->NumberOfSigmasTPC(track, AliPID::kProton);
1772                 fTPCnSigma_kaon = fPidResponse->NumberOfSigmasTPC(track, AliPID::kKaon);
1773                 
1774                 fTPC_p[0]->Fill(fPt,fTPCsignal);
1775                 fTPCnsigma_p[0]->Fill(fP,fTPCnSigma);
1776                 
1777                 
1778                 Float_t TPCNcls = track->GetTPCNcls();
1779                 //TPC Ncls for pid
1780                 Float_t TPCNcls_pid = track->GetTPCsignalN();
1781                 
1782                 
1783                 
1784                 Float_t pos[3]={0,0,0};
1785                 
1786                 Double_t fEMCflag = kFALSE;
1787                 if(track->GetEMCALcluster()>0)
1788                 {
1789                         fClus = fVevent->GetCaloCluster(track->GetEMCALcluster());
1790                         if(fClus->IsEMCAL())
1791                         {
1792                                 
1793                                 //only for charged tracks
1794                                 fECluster[0]->Fill(fClus->E());
1795
1796                                 
1797                                 if(TMath::Abs(fClus->GetTrackDx())<=fdPhiCut && TMath::Abs(fClus->GetTrackDz())<=fdEtaCut)
1798                                 {
1799                                         fEMCflag = kTRUE;
1800                                         fEoverP_pt[0]->Fill(fPt,(fClus->E() / fP));
1801                                         
1802                                         
1803                                         Float_t Energy  = fClus->E();
1804                                         Float_t EoverP  = Energy/track->P();
1805                                                 //Float_t M02   = fClus->GetM02();
1806                                                 //Float_t M20   = fClus->GetM20();
1807                                         
1808                                                 /////////////// for Eta Phi distribution
1809                                         fClus->GetPosition(pos);
1810                                         TVector3 vpos(pos[0],pos[1],pos[2]);
1811                                         Double_t cphi = vpos.Phi();
1812                                         Double_t ceta = vpos.Eta();
1813                                         fEtaPhi[0]->Fill(cphi,ceta);
1814                                         
1815                                         
1816                                         fTPCNcls_EoverP[0]->Fill(TPCNcls, EoverP);
1817                                 }
1818                         }
1819                 }
1820                 
1821                         //______________________________________________________________
1822                         // Vertex
1823                 
1824                 fVtxZ[0]->Fill(fZvtx);
1825                 if(iTracks == 0)fNTracks[0]->Fill(fNOtrks);
1826                 fNTracks_pt[0]->Fill(fNOtrks, fPt);
1827                 fNTracks_eta[0]->Fill(fNOtrks, track->Eta());
1828                 fNTracks_phi[0]->Fill(fNOtrks, track->Phi());
1829
1830                 
1831                 fNClusters[0]->Fill(ClsNo);
1832                 fTPCNcls_pid[0]->Fill(TPCNcls, TPCNcls_pid);
1833                         //______________________________________________________________
1834                 
1835 ///Fill QA plots without track selection
1836 ///_____________________________________________________________________________
1837 //______________________________________________________________________________________
1838 //Track Selection Cuts  
1839                 
1840 //AOD (Test Filter Bit)
1841                 if(fIsAOD)
1842                 {
1843                                 // standard cuts with very loose DCA - BIT(4)
1844                                 // Description:
1845                         /*
1846                          GetStandardITSTPCTrackCuts2011(kFALSE)
1847                          SetMaxChi2PerClusterTPC(4);
1848                          SetAcceptKinkDaughters(kFALSE);
1849                          SetRequireTPCRefit(kTRUE);
1850                          SetRequireITSRefit(kTRUE);
1851                          SetClusterRequirementITS(AliESDtrackCuts::kSPD, AliESDtrackCuts::kAny);
1852                          SetMaxDCAToVertexZ(2);
1853                          SetMaxDCAToVertex2D(kFALSE);
1854                          SetRequireSigmaToVertex(kFALSE);
1855                          SetMaxChi2PerClusterITS(36); 
1856                          SetMaxDCAToVertexXY(2.4)
1857                          SetMaxDCAToVertexZ(3.2)
1858                          SetDCaToVertex2D(kTRUE)
1859                          */     
1860                         
1861                         if(!atrack->TestFilterMask(AliAODTrack::kTrkGlobalNoDCA)) continue; 
1862                 }
1863                 
1864 //RecKine: ITSTPC cuts  
1865                 if(!ProcessCutStep(AliHFEcuts::kStepRecKineITSTPC, track)) continue;
1866 //RecKink
1867                 if(fRejectKinkMother) 
1868                 { 
1869                         if(fIsAOD)
1870                         {
1871                                 Bool_t kinkmotherpass = kTRUE;
1872                                 for(Int_t kinkmother = 0; kinkmother < fNumberOfMotherkink; kinkmother++) 
1873                                 {
1874                                         if(track->GetID() == fListOfmotherkink[kinkmother]) 
1875                                         {
1876                                                 kinkmotherpass = kFALSE;
1877                                                 continue;
1878                                         }
1879                                 }
1880                                 if(!kinkmotherpass) continue;
1881                         }
1882                         else
1883                         {
1884                                 if(etrack->GetKinkIndex(0) != 0) continue;
1885                         }
1886                 } 
1887                 
1888 //RecPrim
1889                 if(!fIsAOD)
1890                 {
1891                         if(!ProcessCutStep(AliHFEcuts::kStepRecPrim, track)) continue;
1892                 }
1893                 
1894 //HFEcuts: ITS layers cuts
1895                 if(!ProcessCutStep(AliHFEcuts::kStepHFEcutsITS, track)) continue;
1896                 
1897 //HFE cuts: TPC PID cleanup
1898                 if(!ProcessCutStep(AliHFEcuts::kStepHFEcutsTPC, track)) continue;
1899 //______________________________________________________________________________________
1900                 
1901                 if(fIsAOD){     
1902                                 //AOD test -- Fancesco suggestion
1903                         Int_t type=aod_track->GetType();
1904                         if(type==AliAODTrack::kPrimary) fPtPrim->Fill(aod_track->Pt());
1905                         if(type==AliAODTrack::kSecondary) fPtSec->Fill(aod_track->Pt());
1906                 
1907                                 //Int_t type2=track->GetType();
1908                         if(type==AliAODTrack::kPrimary) fPtPrim2->Fill(track->Pt());
1909                         if(type==AliAODTrack::kSecondary) fPtSec2->Fill(track->Pt());
1910                 }
1911                         
1912                 
1913 ///_____________________________________________________________
1914 ///QA plots after track selection
1915                 if(fIsMC)
1916                 {
1917                         if(track->GetLabel()>=0) fPtMCWithLabel->Fill(fPt);
1918                         else fPtMCWithoutLabel->Fill(fPt);
1919                 }
1920                 
1921                 if(fIsMC  && track->GetLabel()>=0)
1922                 {
1923                         if(fIsAOD){
1924                                 fMCparticle = (AliAODMCParticle*) fMCarray->At(track->GetLabel());
1925                         
1926                                                                                         
1927                                 if(fMCparticle->IsPhysicalPrimary()) fPtIsPhysicaPrimary->Fill(fPt);
1928                         
1929                                 Int_t pdg = fMCparticle->GetPdgCode();
1930                                 if(fMCparticle->Eta()>=fEtaCutMin && fMCparticle->Eta()<=fEtaCutMax && fMCparticle->Charge()!=0)
1931                                 {
1932                                 
1933                                                                 
1934                                         if( TMath::Abs(pdg) == 211 || TMath::Abs(pdg) == 2212 || TMath::Abs(pdg) == 321 || TMath::Abs(pdg) == 11 || TMath::Abs(pdg) == 13 ) 
1935                                         {       
1936                                                 fPtMCparticleReco_nonPrimary->Fill(fMCparticle->Pt()); //not Primary track
1937                                         
1938                                                 if(fMCparticle->IsPhysicalPrimary()) 
1939                                                 {
1940                                                         fPtMCparticleReco->Fill(fMCparticle->Pt());
1941                                                 
1942                                                         Bool_t MotherFound = FindMother(track->GetLabel());
1943                                                         if(MotherFound)
1944                                                         {
1945                                                                 if(fIsHFE1){
1946                                                                         fPtMCparticleRecoHfe1->Fill(fMCparticle->Pt());//numerator tracking
1947                                                                         //unfolding
1948                                                                         fpt_reco_pt_MC_den->Fill(track->Pt(),fMCparticle->Pt());
1949
1950                                                                 }
1951                                                                 if(fIsHFE2) fPtMCparticleRecoHfe2->Fill(fMCparticle->Pt());
1952                                                         }
1953                                                 }
1954                                         }
1955                                 }
1956                                 
1957                                                                 
1958                                 
1959                         }//close AOD
1960                          //ESD
1961                         else 
1962                         {       
1963                         
1964                                                         
1965                                 if(fMCtrack->Eta()>=fEtaCutMin && fMCtrack->Eta()<=fEtaCutMax)
1966                                 {
1967                                 
1968                                         fMCtrack = fMCstack->Particle(track->GetLabel());
1969                                         Int_t pdg = fMCtrack->GetPdgCode();
1970                                 
1971                                         if( TMath::Abs(pdg) == 211 || TMath::Abs(pdg) == 2212 || TMath::Abs(pdg) == 321 || TMath::Abs(pdg) == 11 || TMath::Abs(pdg) == 13 )
1972                                         {
1973                                                 fPtMCparticleReco_nonPrimary->Fill(fMCtrack->Pt());//not Primary track
1974                                         }
1975                                 
1976                                 
1977                                         if(fMCstack->IsPhysicalPrimary(track->GetLabel()))
1978                                         {
1979                                                 fPtIsPhysicaPrimary->Fill(fPt);
1980                                 
1981                                 
1982                                                 if( TMath::Abs(pdg) == 211 || TMath::Abs(pdg) == 2212 || TMath::Abs(pdg) == 321 || TMath::Abs(pdg) == 11 || TMath::Abs(pdg) == 13 )
1983                                                 {
1984                                                         fPtMCparticleReco->Fill(fMCtrack->Pt());
1985                                                 
1986                                                         Bool_t MotherFound = FindMother(track->GetLabel());
1987                                                         if(MotherFound)
1988                                                         {
1989                                                                 if(fIsHFE1) fPtMCparticleRecoHfe1->Fill(fMCtrack->Pt());//numerator tracking
1990                                                                 if(fIsHFE2) fPtMCparticleRecoHfe2->Fill(fMCtrack->Pt());
1991                                                         }
1992                                                 }
1993                                         }
1994                                 }
1995                         }//close ESD
1996                 }//close IsMC
1997                 
1998                 fTPC_p[1]->Fill(fPt,fTPCsignal);
1999                 fTPCnsigma_p[1]->Fill(fP,fTPCnSigma);
2000                 Double_t fPtBin[7] = {1,2,4,6,8,10,15};
2001                 
2002                 TPCNcls = track->GetTPCNcls();
2003                 Float_t pos2[3]={0,0,0};
2004                 
2005                 if(track->GetEMCALcluster()>0)
2006                 {
2007                         fClus = fVevent->GetCaloCluster(track->GetEMCALcluster());
2008                         if(fClus->IsEMCAL())
2009                         {
2010                                 if(TMath::Abs(fClus->GetTrackDx())<=fdPhiCut && TMath::Abs(fClus->GetTrackDz())<=fdEtaCut)
2011                                 {
2012                                         fEoverP_pt[1]->Fill(fPt,(fClus->E() / fP));
2013                                         
2014                                         Float_t Energy  = fClus->E();
2015                                         Float_t EoverP  = Energy/track->P();
2016                                         Float_t M02     = fClus->GetM02();
2017                                         Float_t M20     = fClus->GetM20();
2018                                         Float_t ncells  = fClus->GetNCells();
2019                                         
2020                                                 /////////////// for Eta Phi distribution
2021                                         fClus->GetPosition(pos2);
2022                                         TVector3 vpos(pos2[0],pos2[1],pos2[2]);
2023                                         Double_t cphi = vpos.Phi();
2024                                         Double_t ceta = vpos.Eta();
2025                                         fEtaPhi[1]->Fill(cphi,ceta);
2026                                         
2027                                         fECluster[1]->Fill(Energy);
2028                                         fTPCNcls_EoverP[1]->Fill(TPCNcls, EoverP);
2029                                         
2030                                         
2031                                         //for EMCal trigger performance
2032                                         if(EoverP > 0.9){
2033                                                 ftpc_p_EoverPcut->Fill(track->P(), fTPCsignal);
2034                                                 fnsigma_p_EoverPcut->Fill(track->P(), fTPCnSigma);
2035                                                 
2036                                         }
2037                                         
2038                                         
2039                                         //for hadron contamination calculations
2040                                         
2041                                         
2042                                         // EtaCut -> dados
2043                                         if(track->Eta()>=fEtaCutMin && track->Eta()<=fEtaCutMax ){
2044                                                         //main
2045                                                 if(TMath::Abs(fTPCnSigma_pion)<3 || TMath::Abs(fTPCnSigma_proton)<3 || TMath::Abs(fTPCnSigma_kaon)<3 ){
2046                                                         
2047                                                         if(fTPCnSigma<-3.5){
2048                                                                 fEoverP_pt_hadrons->Fill(fPt,EoverP);
2049                                                                 if(fUseEMCal) fShowerShape_ha->Fill(M02,M20);
2050                                                         }
2051                                                 }
2052                                                         //for systematic studies of hadron contamination
2053                                                 if(fTPCnSigma < -4){
2054                                                         fEoverP_pt_pions->Fill(fPt, EoverP);
2055                                                         
2056                                                 }
2057                                                 
2058                                                 if(fTPCnSigma < -5){
2059                                                         fEoverP_pt_pions2->Fill(fPt, EoverP);
2060                                                         
2061                                                 }
2062                                                 
2063                                                 
2064                                         }
2065                                         
2066                                         
2067                                         
2068                                         
2069                                         for(Int_t i = 0; i < 6; i++)
2070                                         {
2071                                                 if(fPt>=fPtBin[i] && fPt<fPtBin[i+1])
2072                                                 {
2073                                                         
2074                                                         if(fTPCnSigma < -5 && fTPCnSigma > -10){
2075                                                                 fNcells_hadrons[i]->Fill(ncells);
2076                                                         }
2077                                                                 //hadrons selection using E/p
2078                                                         if((fClus->E() / fP) >= 0.2 && (fClus->E() / fP) <= 0.7){
2079                                                                 fTPCnsigma_eta_hadrons[i]->Fill(fTPCnSigma, ceta);
2080                                                         }
2081                                                                 //electrons selection using E/p
2082                                                         if((fClus->E() / fP) >= fEoverPCutMin && (fClus->E() / fP) <= fEoverPCutMax) {
2083                                                                 fTPCnsigma_eta_electrons[i]->Fill(fTPCnSigma, ceta);
2084                                                         }
2085                                                 }
2086                                         }
2087                                         
2088                                         if((fClus->E() / fP) >= fEoverPCutMin && (fClus->E() / fP) <= fEoverPCutMax)
2089                                         {
2090                                                 fTPCnsigma_eta->Fill(track->Eta(),fTPCnSigma);
2091                                                 fTPCnsigma_phi->Fill(track->Phi(),fTPCnSigma);
2092                                                 
2093                                                 if(fUseEMCal)
2094                                                 {
2095                                                         if(fTPCnSigma < 3.5 && fCorrelationFlag)
2096                                                         {
2097                                                                 fPtTrigger_Inc->Fill(fPt);
2098                                                                 DiHadronCorrelation(track, iTracks);
2099                                                         }
2100                                                 }
2101                                         }
2102                                         
2103                                 }
2104                         }
2105                 }
2106                 
2107                 //______________________________________________________________
2108                 // Vertex
2109                 
2110                 fVtxZ[1]->Fill(fZvtx);
2111                 if(iTracks == 0)fNTracks[1]->Fill(fNOtrks);
2112                 fNTracks_pt[1]->Fill(fNOtrks, fPt);
2113                 fNTracks_eta[1]->Fill(fNOtrks, track->Eta());
2114                 fNTracks_phi[1]->Fill(fNOtrks, track->Phi());
2115                 fNClusters[1]->Fill(ClsNo);
2116                 fTPCNcls_pid[1]->Fill(TPCNcls, TPCNcls_pid);
2117                 
2118                 //______________________________________________________________
2119                 
2120                 ///______________________________________________________________________
2121                 ///Histograms for PID Studies
2122                 //Double_t fPtBin[6] = {2,4,6,8,10,15};
2123                 
2124                 for(Int_t i = 0; i < 6; i++)
2125                 {
2126                         if(fPt>=fPtBin[i] && fPt<fPtBin[i+1])
2127                         {
2128                                 if(fEMCflag) fEoverP_tpc[i]->Fill(fTPCnSigma,(fClus->E() / fP));
2129                                 
2130                                 
2131                                 fTPC_pt[i]->Fill(fTPCsignal);
2132                                 fTPCnsigma_pt[i]->Fill(fTPCnSigma);
2133                                 
2134                         }
2135                 }
2136                 
2137                         ///QA plots after track selection
2138                         ///_____________________________________________________________
2139                 
2140                         //_______________________________________________________
2141                         //Correlation Analysis - DiHadron
2142                 if(!fUseEMCal)
2143                 {
2144                         if(fTPCnSigma < 3.5 && fCorrelationFlag)
2145                         {
2146                                 fPtTrigger_Inc->Fill(fPt);
2147                                 DiHadronCorrelation(track, iTracks);
2148                         }
2149                 }
2150                         //_______________________________________________________
2151                 
2152                 
2153                         ///////////////////////////////////////////////////////////////////
2154                         ///TPC - efficiency calculation // 
2155                 
2156                         /// changing start here
2157                 if(fIsMC && fIsAOD && track->GetLabel()>=0)
2158                 {
2159                         fMCparticle = (AliAODMCParticle*) fMCarray->At(track->GetLabel());
2160                         Int_t pdg = fMCparticle->GetPdgCode();
2161                         
2162                                 //
2163                         if(fMCparticle->IsPhysicalPrimary()){
2164                                 
2165                                 
2166                                 if(fMCparticle->Eta()>=fEtaCutMin && fMCparticle->Eta()<=fEtaCutMax ){
2167                                         
2168                                         Bool_t MotherFound = FindMother(track->GetLabel());
2169                                         if(MotherFound){
2170                                                 fMCparticleMother = (AliAODMCParticle*) fMCarray->At(fMCparticle->GetMother());
2171                                         if( TMath::Abs(pdg) == 11 && fMCparticleMother->GetPdgCode()!=22 ){
2172                                                         if(fIsHFE1) fPtMC_TPC_All->Fill(fMCparticle->Pt());     
2173                                         }
2174                                         }
2175                                 }
2176                         }
2177                 }///until here
2178                 
2179                 else if(fIsMC && track->GetLabel()>=0)//ESD
2180                 {
2181                         
2182                         if(fMCstack->IsPhysicalPrimary(track->GetLabel())){
2183                                 fMCtrack = fMCstack->Particle(track->GetLabel());
2184                                 
2185                                 Int_t pdg = fMCtrack->GetPdgCode();
2186                                 if(fMCtrack->Eta()>=fEtaCutMin && fMCtrack->Eta()<=fEtaCutMax ){
2187                                         
2188                                         if(fMCtrack->GetFirstMother()>0){
2189                                             fMCtrackMother = fMCstack->Particle(fMCtrack->GetFirstMother());
2190                                                 Bool_t MotherFound = FindMother(track->GetLabel());
2191                                                 if(MotherFound){
2192                                                         if( TMath::Abs(pdg) == 11 && fMCtrackMother->GetPdgCode()!=22 ){
2193                                                                 if(fIsHFE1) fPtMC_TPC_All->Fill(fMCtrack->Pt());        
2194                                                         }
2195                                                 }
2196                                         }
2197                                 }
2198                         }
2199                 }
2200                 
2201                 
2202                         if(fPt>1 && fPt<2) fTOF01->Fill(fTOFnSigma,fTPCnSigma);
2203                         if(fPt>2 && fPt<4) fTOF02->Fill(fTOFnSigma,fTPCnSigma);
2204                         if(fPt>4 && fPt<6) fTOF03->Fill(fTOFnSigma,fTPCnSigma);
2205                 
2206 ///________________________________________________________________________
2207 ///PID
2208 ///Here the PID cuts defined in the file "ConfigEMCalHFEpA.C" is applied
2209             Int_t pidpassed = 1;
2210             AliHFEpidObject hfetrack;
2211             hfetrack.SetAnalysisType(AliHFEpidObject::kESDanalysis);
2212             hfetrack.SetRecTrack(track);
2213             hfetrack.SetPP();   //proton-proton analysis
2214             if(!fPID->IsSelected(&hfetrack, NULL, "", fPIDqa)) pidpassed = 0;
2215             fpid->Fill(pidpassed);
2216                 
2217             if(pidpassed==0) continue;
2218 ///________________________________________________________________________             
2219                 
2220                 
2221 ////////////////////////////////////////////////////////////////////
2222 ///TPC efficiency calculations 
2223                 
2224                         
2225                 if(fIsMC && fIsAOD && track->GetLabel()>=0)
2226                 {
2227                         fMCparticle = (AliAODMCParticle*) fMCarray->At(track->GetLabel());
2228                         Int_t pdg = fMCparticle->GetPdgCode();
2229                         
2230                                 //
2231                         if(fMCparticle->IsPhysicalPrimary()){
2232                                 
2233                                 
2234                                 if(fMCparticle->Eta()>=fEtaCutMin && fMCparticle->Eta()<=fEtaCutMax ){
2235                                         
2236                                         Bool_t MotherFound = FindMother(track->GetLabel());
2237                                         if(MotherFound){
2238                                                 fMCparticleMother = (AliAODMCParticle*) fMCarray->At(fMCparticle->GetMother());
2239                                         if( TMath::Abs(pdg) == 11 && fMCparticleMother->GetPdgCode()!=22 ){
2240                                                         if(fIsHFE1) fPtMC_TPC_Selected->Fill(fMCparticle->Pt());        
2241                                         }
2242                                         }
2243                                 }
2244                         }
2245                 }///until here
2246                 
2247                 else if(fIsMC && track->GetLabel()>=0)//ESD
2248                 {
2249                         
2250                         if(fMCstack->IsPhysicalPrimary(track->GetLabel())){
2251                                 fMCtrack = fMCstack->Particle(track->GetLabel());
2252                                 
2253                                 Int_t pdg = fMCtrack->GetPdgCode();
2254                                 if(fMCtrack->Eta()>=fEtaCutMin && fMCtrack->Eta()<=fEtaCutMax ){
2255                                         
2256                                         if(fMCtrack->GetFirstMother()>0){
2257                                             fMCtrackMother = fMCstack->Particle(fMCtrack->GetFirstMother());
2258                                                 Bool_t MotherFound = FindMother(track->GetLabel());
2259                                                 if(MotherFound){
2260                                                         if( TMath::Abs(pdg) == 11 && fMCtrackMother->GetPdgCode()!=22 ){
2261                                                                 if(fIsHFE1) fPtMC_TPC_Selected->Fill(fMCtrack->Pt());   
2262                                                         }
2263                                                 }
2264                                         }
2265                                 }
2266                         }
2267                 }
2268                 
2269                 //Eta Cut for TPC only
2270                 if(track->Eta()>=fEtaCutMin && track->Eta()<=fEtaCutMax ){
2271                         fTPCnsigma_pt_2D->Fill(fPt,fTPCnSigma);
2272                 }
2273                 
2274                 //Background for TPC only
2275                 if(fFillBackground){
2276                         
2277                         //efficiency without SS cut for TPC only
2278                         if(track->Eta()>=fEtaCutMin && track->Eta()<=fEtaCutMax){
2279                                 Background(track, iTracks, Vtrack, kTRUE); //IsTPConly=kTRUE
2280                         } //Eta cut to be consistent with other efficiency
2281                 }
2282                 
2283                 
2284                 fTPCnsigma_p[2]->Fill(fP,fTPCnSigma);
2285                 fTPC_p[2]->Fill(fP,fTPCsignal);
2286                 TPCNcls = track->GetTPCNcls();
2287                 Float_t pos3[3]={0,0,0};
2288                 
2289                 
2290                 //here denominator for track-matching efficiency
2291                 if(fIsMC && fIsAOD && track->GetLabel()>=0)
2292                 {
2293                         fMCparticle = (AliAODMCParticle*) fMCarray->At(track->GetLabel());
2294                         Int_t pdg = fMCparticle->GetPdgCode();
2295                         
2296                                 //
2297                         if(fMCparticle->IsPhysicalPrimary()){
2298                                 
2299                                 
2300                                 if(fMCparticle->Eta()>=fEtaCutMin && fMCparticle->Eta()<=fEtaCutMax ){
2301                                         
2302                                         Bool_t MotherFound = FindMother(track->GetLabel());
2303                                         if(MotherFound){
2304                                                 fMCparticleMother = (AliAODMCParticle*) fMCarray->At(fMCparticle->GetMother());
2305                                         if( TMath::Abs(pdg) == 11 && fMCparticleMother->GetPdgCode()!=22 ){
2306                                                         if(fIsHFE1) fPt_track_match_den->Fill(fMCparticle->Pt());       
2307                                         }
2308                                         }
2309                                 }
2310                         }
2311                 }///until here          
2312                 
2313                 
2314                 if(track->GetEMCALcluster()>0)
2315                 {
2316                         fClus = fVevent->GetCaloCluster(track->GetEMCALcluster());
2317                         if(fClus->IsEMCAL())
2318                         {
2319                                 
2320                 //________________________________________________________________________              
2321                                 
2322                                 
2323                                 //Cluster timing distribution -- for ESD 
2324                                 if(fUseEMCal && !fIsAOD){
2325                                                 
2326                                         AliESDCaloCells &cells_esd=*(fESD->GetEMCALCells());
2327                                         TRefArray* caloClusters_esd = new TRefArray();
2328                                     fESD->GetEMCALClusters(caloClusters_esd);
2329                                         Int_t nclus_esd = caloClusters_esd->GetEntries();
2330                                         
2331                                 
2332                                         for (Int_t icl = 0; icl < nclus_esd; icl++) {
2333                                                                                                 
2334                                                 AliESDCaloCluster* clus_esd = (AliESDCaloCluster*)caloClusters_esd->At(icl);
2335                                                 
2336                                                 if(clus_esd->IsEMCAL()){
2337                                                         Float_t ncells_esd      = fClus->GetNCells();
2338                                                         UShort_t * index_esd = clus_esd->GetCellsAbsId() ;
2339                                                         UShort_t * index2_esd = fClus->GetCellsAbsId() ;
2340                                                         
2341                                                         
2342                                                         for(Int_t i = 0; i < ncells_esd ; i++){
2343                                                                 
2344                                                                 Int_t absId_esd =   index_esd[i];
2345                                                                 fTime->Fill(fPt,cells_esd.GetCellTime(absId_esd));
2346                                                                 
2347                                                                 Int_t absId2_esd =   index2_esd[i];
2348                                                                 fTime2->Fill(fPt,cells_esd.GetCellTime(absId2_esd));
2349                                                         }
2350                                                         
2351                                                 }
2352                                         }
2353                                         
2354                                 }
2355                                 /* not working!
2356                                 //Cluster timing distribution -- for AOD 
2357                                 if(fUseEMCal && fIsAOD){
2358                                         
2359                                         AliAODCaloCells &cells_aod=*(fAOD->GetEMCALCells());
2360                                         
2361                                         TRefArray* caloClusters_aod = new TRefArray();
2362                                         fAOD->GetEMCALClusters(caloClusters_aod);
2363                                         
2364                                         Int_t nclus_aod = caloClusters_aod->GetEntries();
2365                                         
2366                                         for (Int_t icl = 0; icl < nclus_aod; icl++) {
2367                                                                                                 
2368                                                 AliAODCaloCluster* clus_aod = (AliAODCaloCluster*)caloClusters_aod->At(icl);
2369                                                 
2370                                                 
2371                                                 if(clus_aod->IsEMCAL()){
2372                                                         Float_t ncells_aod      = fClus->GetNCells();
2373                                                         UShort_t * index_aod = clus_aod->GetCellsAbsId() ;
2374                                                         UShort_t * index2_aod = fClus->GetCellsAbsId() ;
2375                                                         
2376                                                         
2377                                                         for(Int_t i = 0; i < ncells_aod ; i++){
2378                                                                 
2379                                                                 Int_t absId_aod =   index_aod[i];
2380                                                                 fTime->Fill(fPt,cells_aod.GetCellTime(absId_aod));
2381                                                                 
2382                                                                 Int_t absId2_aod =   index2_aod[i];
2383                                                                 fTime2->Fill(fPt,cells_aod.GetCellTime(absId2_aod));
2384                                                         }
2385                                                         
2386                                                 }
2387                                         }
2388                                         
2389                                 }
2390                                  */
2391                                         
2392                                                                         
2393                                 if(fUseEMCal){
2394                                         double emctof = fClus->GetTOF();
2395                                         ftimingEle->Fill(fPt,emctof);
2396                                 }
2397                                         //________________________________________________________________________              
2398                                 
2399                                 
2400                                 
2401                                 
2402                                 // Residuals
2403                                 Double_t Dx = fClus->GetTrackDx();
2404                                 Double_t Dz = fClus->GetTrackDz();
2405                                 Double_t R=TMath::Sqrt(Dx*Dx+Dz*Dz);
2406                                 
2407                                 for(Int_t i = 0; i < 6; i++)
2408                                 {
2409                                         if(fPt>=fPtBin[i] && fPt<fPtBin[i+1])
2410                                         {
2411                                                 
2412                                                 fEta[i]->Fill(Dz);
2413                                                 fPhi[i]->Fill(Dx);
2414                                                 fR[i]->Fill(R);
2415                                         }
2416                                 }       
2417                                 
2418                                 if(TMath::Abs(fClus->GetTrackDx())<=fdPhiCut && TMath::Abs(fClus->GetTrackDz())<=fdEtaCut)
2419                                 {
2420                                         Float_t Energy  = fClus->E();
2421                                         Float_t EoverP  = Energy/track->P();
2422                                         Float_t M02     = fClus->GetM02();
2423                                         Float_t M20     = fClus->GetM20();
2424                                         Float_t ncells  = fClus->GetNCells();
2425                                         
2426                                         //here numerator for track-matching efficiency
2427                                         if(fIsMC && fIsAOD && track->GetLabel()>=0)
2428                                         {
2429                                                 fMCparticle = (AliAODMCParticle*) fMCarray->At(track->GetLabel());
2430                                                 Int_t pdg = fMCparticle->GetPdgCode();
2431                                                 
2432                                                         //
2433                                                 if(fMCparticle->IsPhysicalPrimary()){
2434                                                         
2435                                                         
2436                                                         if(fMCparticle->Eta()>=fEtaCutMin && fMCparticle->Eta()<=fEtaCutMax ){
2437                                                                 
2438                                                                 Bool_t MotherFound = FindMother(track->GetLabel());
2439                                                                 if(MotherFound){
2440                                                                         fMCparticleMother = (AliAODMCParticle*) fMCarray->At(fMCparticle->GetMother());
2441                                                                         if( TMath::Abs(pdg) == 11 && fMCparticleMother->GetPdgCode()!=22 ){
2442                                                                                 if(fIsHFE1) fPt_track_match_num->Fill(fMCparticle->Pt());       
2443                                                                         }
2444                                                                 }
2445                                                         }
2446                                                 }
2447                                         }///until here          
2448                                         
2449                                         
2450                                         
2451                                         //----------------------------------------------------------------------------------------
2452                                         
2453                                         // EtaCut electrons histogram
2454                                         //Shower Shape Cut
2455                                         if(track->Eta()>=fEtaCutMin && track->Eta()<=fEtaCutMax ){
2456                                                 
2457                                                 if(fUseShowerShapeCut){
2458                                                         if(M02 >= fM02CutMin && M02<=fM02CutMax && M20>=fM20CutMin && M20<=fM20CutMax){
2459                                                                 fEoverP_pt[2]->Fill(fPt,(fClus->E() / fP));
2460                                                                 fShowerShapeCut->Fill(M02,M20);
2461                                                                 
2462                                                         }
2463                                                         
2464                                                 }
2465                                                 if(!fUseShowerShapeCut){
2466                                                         fEoverP_pt[2]->Fill(fPt,(fClus->E() / fP));
2467                                                         fShowerShapeCut->Fill(M02,M20);
2468                                                         
2469                                                 }
2470                                                 if(fUseEMCal) fShowerShape_ele->Fill(M02,M20);
2471                                                 
2472                                                 //for shower shape cut studies - now with TPC PID Cut
2473                                                 if(fUseEMCal){
2474                                                         fShowerShapeM02_EoverP->Fill(M02,EoverP);
2475                                                         fShowerShapeM20_EoverP->Fill(M20,EoverP);
2476                                                 }
2477                                                 
2478                                         }
2479                                         
2480                                         //----------------------------------------------------------------------------------------
2481                                         
2482                                         
2483                                         
2484                                         // for Eta Phi distribution
2485                                         fClus->GetPosition(pos3);
2486                                         TVector3 vpos(pos3[0],pos3[1],pos3[2]);
2487                                         Double_t cphi = vpos.Phi();
2488                                         Double_t ceta = vpos.Eta();
2489                                         fEtaPhi[2]->Fill(cphi,ceta);
2490                                         
2491                                         
2492                                         
2493                                         fTPCNcls_EoverP[2]->Fill(TPCNcls, EoverP);
2494                                         
2495                                         for(Int_t i = 0; i < 6; i++)
2496                                         {
2497                                                 if(fPt>=fPtBin[i] && fPt<fPtBin[i+1])
2498                                                 {
2499                                                         
2500                                                         fR_EoverP[i]->Fill(R, EoverP);
2501                                                         fNcells[i]->Fill(ncells);
2502                                                         fNcells_EoverP[i]->Fill(EoverP, ncells);
2503                                                         fM02_EoverP[i]->Fill(M02,EoverP);
2504                                                         fM20_EoverP[i]->Fill(M20,EoverP);
2505                                                         fECluster_ptbins[i]->Fill(Energy);
2506                                                         fEoverP_ptbins[i]->Fill(EoverP);
2507                                                         
2508                                                         if((fClus->E() / fP) >= fEoverPCutMin && (fClus->E() / fP) <= fEoverPCutMax) {
2509                                                                 fNcells_electrons[i]->Fill(ncells);
2510                                                         }
2511                                                         
2512                                                         if(M02<0.5 && M20<0.3) {
2513                                                                 fEoverP_wSSCut[i]->Fill(EoverP);
2514                                                         }
2515                                                 }
2516                                         }
2517                                         
2518                                         fNcells_pt->Fill(fPt, ncells);
2519                                         
2520                                         
2521                                         ////////////////////////////////////////////////////////////////////
2522                                         ///EMCal - Efficiency calculations 
2523                                         
2524                                                 
2525                                         if(fIsMC && fIsAOD && track->GetLabel()>=0)
2526                                         {
2527                                                 fMCparticle = (AliAODMCParticle*) fMCarray->At(track->GetLabel());
2528                                                 Int_t pdg = fMCparticle->GetPdgCode();
2529                                                 
2530                                                 //
2531                                                 if(fMCparticle->IsPhysicalPrimary()){
2532                                                         
2533                                                         //Phi cut && fMCparticle->Phi()>=(TMath::Pi()*80/180) && fMCparticle->Phi()<=TMath::Pi()
2534                                                         if(fMCparticle->Eta()>=fEtaCutMin && fMCparticle->Eta()<=fEtaCutMax  ){
2535                                                                 
2536                                                                 Bool_t MotherFound = FindMother(track->GetLabel());
2537                                                                 if(MotherFound){
2538                                                                         fMCparticleMother = (AliAODMCParticle*) fMCarray->At(fMCparticle->GetMother());
2539                                                                         if( TMath::Abs(pdg) == 11 && fMCparticleMother->GetPdgCode()!=22 ){
2540                                                                                 if(fIsHFE1)fPtMC_EMCal_All->Fill(fMCparticle->Pt());    
2541                                                                         }
2542                                                                 }
2543                                                         }
2544                                                 }
2545                                         }
2546                                         
2547                                         else if(fIsMC && track->GetLabel()>=0)//ESD
2548                                         {
2549                                                 
2550                                                 if(fMCstack->IsPhysicalPrimary(track->GetLabel()))
2551                                                 {
2552                                                         
2553                                                         fMCtrack = fMCstack->Particle(track->GetLabel());
2554                                                         
2555                                                         Int_t pdg = fMCtrack->GetPdgCode();
2556                                                         //Phi cut && fMCtrack->Phi()>=(TMath::Pi()*80/180) && fMCtrack->Phi()<=TMath::Pi()
2557                                                         if(fMCtrack->Eta()>=fEtaCutMin && fMCtrack->Eta()<=fEtaCutMax )
2558                                                         {
2559                                                                 Bool_t MotherFound = FindMother(track->GetLabel());
2560                                                                         //MotherFound included
2561                                                                 if(MotherFound){
2562                                                                         if(fMCtrack->GetFirstMother()>0){
2563                                                                                 fMCtrackMother = fMCstack->Particle(fMCtrack->GetFirstMother());
2564                                                                                 if( TMath::Abs(pdg) == 11 && fMCtrackMother->GetPdgCode()!=22 ){
2565                                                                                         if(fIsHFE1)fPtMC_EMCal_All->Fill(fMCtrack->Pt());       
2566                                                                                 }
2567                                                                         }
2568                                                                 }
2569                                                         }
2570                                                 }
2571                                         }
2572                                         
2573                                         //_______________________________________________________
2574                                         //PID using EMCal
2575                                         if((fClus->E() / fP) >= fEoverPCutMin && (fClus->E() / fP) <= fEoverPCutMax)
2576                                         {       
2577                                                 
2578                                             fECluster[2]->Fill(Energy);
2579                                                 fTPCNcls_pid[3]->Fill(TPCNcls, TPCNcls_pid);
2580                                                 
2581                                                 if(fUseEMCal)
2582                                                 {
2583                                                         fPtElec_Inc->Fill(fPt);
2584                                                         //Eta cut for background
2585                                                         if(fFillBackground){
2586                                                                 fEtad[2]->Fill(track->Eta());
2587                                                                 
2588                                                                 //background for triggered data: trigger electron must have same cuts on shower shape  06/Jan/2014
2589                                                                 if(fUseShowerShapeCut){
2590                                                                         if(M02 >= fM02CutMin && M02<=fM02CutMax && M20>=fM20CutMin && M20<=fM20CutMax){
2591                                                                                 if(track->Eta()>=fEtaCutMin && track->Eta()<=fEtaCutMax){
2592                                                                                         Background(track, iTracks, Vtrack, kFALSE);
2593                                                                                 }
2594                                                                         }
2595                                                                 }
2596                                                                 else{
2597                                                                         if(track->Eta()>=fEtaCutMin && track->Eta()<=fEtaCutMax){
2598                                                                                 Background(track, iTracks, Vtrack, kFALSE);
2599                                                                         }
2600                                                                 }
2601                                                                 
2602                                                         }
2603                                                         
2604                                                         double emctof2 = fClus->GetTOF();
2605                                                         ftimingEle2->Fill(fPt,emctof2);
2606                                                         //Correlation Analysis
2607                                                         if(fCorrelationFlag) 
2608                                                         {
2609                                                                 ElectronHadronCorrelation(track, iTracks, Vtrack);
2610                                                         }
2611                                                 }
2612                                                 //_______________________________________________________
2613                                                 
2614                                                 ////////////////////////////////////////////////////////////////////
2615                                                 ///EMCal - efficiency calculations 
2616                                                 
2617                                                 if(track->Charge()<0)  fCharge_n->Fill(fPt);
2618                                                 if(track->Charge()>0)  fCharge_p->Fill(fPt);
2619                                                 
2620                                                 
2621                                                         
2622                                                 if(fIsMC && fIsAOD && track->GetLabel()>=0)//AOD
2623                                                 {
2624                                                         if(track->Charge()<0)  fCharge_n->Fill(fPt);
2625                                                         if(track->Charge()>0)  fCharge_p->Fill(fPt);
2626                                                         
2627                                                         fMCparticle = (AliAODMCParticle*) fMCarray->At(track->GetLabel());
2628                                                         if(fMCparticle->GetMother()>0) fMCparticleMother = (AliAODMCParticle*) fMCarray->At(fMCparticle->GetMother());
2629                                                         Int_t pdg = fMCparticle->GetPdgCode();
2630                                         
2631                                                         double proX = fMCparticle->Xv();
2632                                                         double proY = fMCparticle->Yv();
2633                                                         double proR = sqrt(pow(proX,2)+pow(proY,2));
2634                                                         
2635                                                         
2636                                                         if(fMCparticle->Eta()>=fEtaCutMin && fMCparticle->Eta()<=fEtaCutMax && fMCparticle->Phi()>=(TMath::Pi()*80/180) && fMCparticle->Phi()<=TMath::Pi()  ){
2637                                                                         
2638                                                                 if( TMath::Abs(pdg) == 11 && fMCparticle->GetMother()>0 ){
2639                                                                         Int_t mpdg = fMCparticleMother->GetPdgCode();
2640                                                                         if(TMath::Abs(mpdg) == 221 || TMath::Abs(mpdg) == 22 || TMath::Abs(mpdg) == 111){
2641                                                                                 if(proR<7)fPtMCelectronAfterAll_nonPrimary->Fill(fMCparticle->Pt()); //numerator for the total efficiency, non Primary track
2642                                                                         }
2643                                                                 }
2644                                                                 if( TMath::Abs(pdg) == 11 && fMCparticle->IsPhysicalPrimary()) fPtMCelectronAfterAll_Primary->Fill(fMCparticle->Pt()); 
2645                                                         }       
2646                                                                 
2647                                                         
2648                                                         //
2649                                                         if(fMCparticle->IsPhysicalPrimary()){
2650                                                                 
2651                                                                 
2652                                                                 if(fMCparticle->Eta()>=fEtaCutMin && fMCparticle->Eta()<=fEtaCutMax ){
2653                                                                                 
2654                                                                         Bool_t MotherFound = FindMother(track->GetLabel());
2655                                                                         if(MotherFound){
2656                                                                                 
2657                                                                                 if(!fUseShowerShapeCut){
2658                                                                                         if(fIsHFE1){ 
2659                                                                                                 //Unfolding   pt_reco/pt_MC  in the efficiency
2660                                                                                                 fPtMCelectronAfterAll->Fill(fMCparticle->Pt());
2661                                                                                                 fPtMCelectronAfterAll_unfolding->Fill(track->Pt());
2662                                                                                                 fEtaPhi_num->Fill(fMCparticle->Phi(),fMCparticle->Eta());
2663                                                                                                 
2664                                                                                                 //new histo to estimate how different is pt reco from pt MC 
2665                                                                                                 fpt_reco_pt_MC_num->Fill(track->Pt(),fMCparticle->Pt());
2666                                                                                         }//numerator for the total efficiency AOD
2667                                                                                 }
2668                                                                                         //November 11 for efficiency of triggered data
2669                                                                                 if(fUseShowerShapeCut){
2670                                                                                         if(M02 >= fM02CutMin && M02<=fM02CutMax && M20>=fM20CutMin && M20<=fM20CutMax){
2671                                                                                                 if(fIsHFE1){ 
2672                                                                                                         //Unfolding   pt_reco/pt_MC  in the efficiency
2673                                                                                                         fPtMCelectronAfterAll->Fill(fMCparticle->Pt());
2674                                                                                                         fPtMCelectronAfterAll_unfolding->Fill(track->Pt());
2675                                                                                                         fEtaPhi_num->Fill(fMCparticle->Phi(),fMCparticle->Eta());
2676                                                                                                         
2677                                                                                                         //new histo to estimate how different is pt reco from pt MC 
2678                                                                                                         fpt_reco_pt_MC_num->Fill(track->Pt(),fMCparticle->Pt());
2679                                                                                                 }//numerator for the total efficiency AOD
2680                                                                                         }
2681                                                                                 }
2682                                                                         
2683                                                                         
2684                                                                         
2685                                                                                         fMCparticleMother = (AliAODMCParticle*) fMCarray->At(fMCparticle->GetMother());
2686                                                                                         if( TMath::Abs(pdg) == 11 && fMCparticleMother->GetPdgCode()!=22 ){
2687                                                                                                 if(fIsHFE1)fPtMC_EMCal_Selected->Fill(fMCparticle->Pt());       
2688                                                                                         }
2689                                                                         }//if MotherFound
2690                                                                 }//eta cut
2691                                                         }
2692                                                 }///close AOD
2693                                                 
2694                                                 else if(fIsMC && track->GetLabel()>=0)//ESD
2695                                                 {
2696                                                         if(track->Charge()<0)  fCharge_n->Fill(fPt);
2697                                                         if(track->Charge()>0)  fCharge_p->Fill(fPt);
2698                                                         
2699                                                         fMCtrack = fMCstack->Particle(track->GetLabel());
2700                                                         if(fMCtrack->GetFirstMother()>0) fMCtrackMother = fMCstack->Particle(fMCtrack->GetFirstMother());
2701                                                         TParticle *particle=fMCstack->Particle(track->GetLabel());
2702
2703                                                         Int_t pdg = fMCtrack->GetPdgCode();
2704                                                         
2705                                                         
2706                                                         if(fMCtrack->Eta()>=fEtaCutMin && fMCtrack->Eta()<=fEtaCutMax){
2707                                                                 if( TMath::Abs(pdg) == 11 && fMCtrack->GetFirstMother()>0 ){
2708                                                                         Int_t mpdg = fMCtrackMother->GetPdgCode();
2709                                                                         if(TMath::Abs(mpdg) == 221 || TMath::Abs(mpdg) == 22 || TMath::Abs(mpdg) == 111){
2710                                                                                 Double_t proR=particle->R();
2711                                                                                 if(proR<7){
2712                                                                                   fPtMCelectronAfterAll_nonPrimary->Fill(fMCtrack->Pt()); //numerator for the total efficiency, non Primary track
2713                                                                                 }
2714                                                                         }
2715                                                                 }
2716                                                                 if( TMath::Abs(pdg) == 11 && fMCstack->IsPhysicalPrimary(track->GetLabel())) fPtMCelectronAfterAll_Primary->Fill(fMCtrack->Pt());
2717                                                         }
2718                                                         
2719                                                         if(fMCstack->IsPhysicalPrimary(track->GetLabel()))
2720                                                         {
2721                                                                 Bool_t MotherFound = FindMother(track->GetLabel());
2722                                                             
2723                                                                 if(MotherFound)
2724                                                                 {
2725                                                                         if(fMCtrack->Eta()>=fEtaCutMin && fMCtrack->Eta()<=fEtaCutMax){
2726                                                                                 
2727                                                                                 
2728                                                                                 if(!fUseShowerShapeCut){
2729                                                                                         if(fIsHFE1){
2730                                                                                                 fPtMCelectronAfterAll->Fill(fMCtrack->Pt()); //numerator for the total efficiency ESD
2731                                                                                                 fEtaPhi_num->Fill(fMCtrack->Phi(),fMCtrack->Eta());
2732                                                                                         }
2733                                                                                 }
2734                                                                                 //November 11 for efficiency of triggered data
2735                                                                                 if(fUseShowerShapeCut){
2736                                                                                         if(M02 >= fM02CutMin && M02<=fM02CutMax && M20>=fM20CutMin && M20<=fM20CutMax){
2737                                                                                                 if(fIsHFE1){
2738                                                                                                         fPtMCelectronAfterAll->Fill(fMCtrack->Pt()); //numerator for the total efficiency ESD
2739                                                                                                         fEtaPhi_num->Fill(fMCtrack->Phi(),fMCtrack->Eta());
2740                                                                                                 }
2741                                                                                         }
2742                                                                                 }
2743                                                                                 
2744                                                                                 
2745                                                                                 
2746                                                                         }
2747                                                                 }
2748                                                                 
2749                                                                 
2750                                                                 
2751                                                                 // Phi cut && fMCtrack->Phi()>=(TMath::Pi()*80/180) && fMCtrack->Phi()<=TMath::Pi()
2752                                                                 if(fMCtrack->Eta()>=fEtaCutMin && fMCtrack->Eta()<=fEtaCutMax)
2753                                                                 {
2754                                                                         //included MotherFound
2755                                                                         
2756                                                                         if(MotherFound)
2757                                                                         {
2758                                                                                 if(fMCtrack->GetFirstMother()>0){
2759                                                                                         fMCtrackMother = fMCstack->Particle(fMCtrack->GetFirstMother());
2760                                                                                         if( TMath::Abs(pdg) == 11 && fMCtrackMother->GetPdgCode()!=22 ){
2761                                                                                         
2762                                                                                                 if(fIsHFE1)fPtMC_EMCal_Selected->Fill(fMCtrack->Pt());  
2763                                                                                         }
2764                                                                                 }
2765                                                                         }
2766                                                                 }
2767                                                         }
2768                                                 }//close ESD
2769                                                 ///////////////////////////////////////////////////////////////////
2770                                                 
2771                                                 
2772                                         }
2773                                 }
2774                         }
2775                 }
2776                 
2777                         //______________________________________________________________
2778                         // Vertex
2779                 
2780                 fVtxZ[2]->Fill(fZvtx);
2781                 if(iTracks == 0)fNTracks[2]->Fill(fNOtrks);
2782                 fNTracks_pt[2]->Fill(fNOtrks, fPt);
2783                 fNTracks_eta[2]->Fill(fNOtrks, track->Eta());
2784                 fNTracks_phi[2]->Fill(fNOtrks, track->Phi());
2785                 fNClusters[2]->Fill(ClsNo);
2786                 fTPCNcls_pid[2]->Fill(TPCNcls, TPCNcls_pid);
2787                 
2788                         //______________________________________________________________
2789                 
2790                         //_______________________________________________________
2791                         //Correlation Analysis
2792                 if(!fUseEMCal)
2793                 {
2794                         fPtElec_Inc->Fill(fPt);
2795                         
2796                         if(fCorrelationFlag) 
2797                         {
2798                                 ElectronHadronCorrelation(track, iTracks, Vtrack);
2799                         }
2800                 }
2801                         //_______________________________________________________
2802                 
2803                         ///________________________________________________________________________
2804         }
2805         
2806                 //__________________________________________________________________
2807                 //Event Mixing Analysis
2808                 //Filling pool
2809         if(fEventMixingFlag)
2810         {
2811                 fPool = fPoolMgr->GetEventPool(fCentrality->GetCentralityPercentile("V0A"), fZvtx); // Get the buffer associated with the current centrality and z-vtx
2812                 
2813                 if(!fPool) AliFatal(Form("No pool found for centrality = %f, zVtx = %f", fCentrality->GetCentralityPercentile("V0A"), fZvtx));
2814                 
2815                 fPool->UpdatePool(SelectedHadrons()); // fill the tracks in the event buffer. The ownership is handed over to the event mixing class. We are not allowed to delete tracksClone anymore!
2816                 
2817                 
2818         }
2819         
2820                 //__________________________________________________________________
2821         
2822         delete fListOfmotherkink;
2823         PostData(1, fOutputList);
2824 }      
2825
2826         //______________________________________________________________________
2827 void AliAnalysisTaskEMCalHFEpA::Terminate(Option_t *) 
2828 {
2829                 //Draw result to the screen
2830                 //Called once at the end of the query
2831         
2832         fOutputList = dynamic_cast<TList*> (GetOutputData(1));
2833         
2834         if(!fOutputList) 
2835         {
2836                 printf("ERROR: Output list not available\n");
2837                 return;
2838         }
2839 }
2840
2841         //______________________________________________________________________
2842 Bool_t AliAnalysisTaskEMCalHFEpA::ProcessCutStep(Int_t cutStep, AliVParticle *track)
2843 {
2844                 //Check single track cuts for a given cut step
2845                 //Note this function is called inside the UserExec function
2846         const Int_t kMCOffset = AliHFEcuts::kNcutStepsMCTrack;
2847         if(!fCFM->CheckParticleCuts(cutStep + kMCOffset, track)) return kFALSE;
2848         return kTRUE;
2849 }
2850
2851
2852         //______________________________________________________________________
2853
2854
2855 void AliAnalysisTaskEMCalHFEpA::Background(AliVTrack *track, Int_t trackIndex, AliVParticle *vtrack, Bool_t IsTPConly)
2856 {
2857         ///_________________________________________________________________
2858         ///MC analysis
2859         Bool_t IsMCefix=kFALSE; //to make correction on efix, use kTRUE (do not change the efficiency, so I will keep the correction only for d3)
2860                 
2861                 if(fIsMC)
2862                 {
2863                         if(track->GetLabel() < 0)
2864                         {
2865                                 AliWarning(Form("The track %d does not have a valid MC label",trackIndex));
2866                                 return;
2867                         }
2868                         
2869                         if(fIsAOD)
2870                         {
2871                                 fMCparticle = (AliAODMCParticle*) fMCarray->At(track->GetLabel());
2872                                 
2873                                 if(fMCparticle->GetMother()<0) return;
2874                                 
2875                                 fMCparticleMother = (AliAODMCParticle*) fMCarray->At(fMCparticle->GetMother());
2876                                 if(fMCparticleMother->GetMother()>0)fMCparticleGMother = (AliAODMCParticle*) fMCarray->At(fMCparticleMother->GetMother());
2877                                 
2878                                 if(TMath::Abs(fMCparticle->GetPdgCode())==11 && (TMath::Abs(fMCparticleMother->GetPdgCode())==22 || TMath::Abs(fMCparticleMother->GetPdgCode())==111 || TMath::Abs(fMCparticleMother->GetPdgCode())==221))
2879                                 {
2880                                                 //Is Background
2881                                         if(!IsTPConly)fPtBackgroundBeforeReco->Fill(track->Pt());
2882                                         if(IsTPConly)fPtBackgroundBeforeReco2->Fill(track->Pt());
2883                                         
2884                                         
2885                                                 //October 08th weighted histos
2886                                         if(TMath::Abs(fMCparticleMother->GetPdgCode())==111 || TMath::Abs(fMCparticleMother->GetPdgCode())==221 ){
2887                                                 
2888                                                 Double_t mPt=fMCparticleMother->Pt();
2889                                                 Double_t mweight=1;
2890                                                 
2891                                                         //________________________________________________________________
2892                                                         //correction for efix based on data - parametrization from MinJung
2893                                                 if(IsMCefix){
2894                                                         if(TMath::Abs(fMCparticleMother->GetPdgCode())==111){
2895                                                                 Double_t x=mPt;
2896                                                                 if(0.100000 <= x < 0.112797 ) mweight=1.030419;
2897                                                                 if(0.112797 <= x < 0.127231 ) mweight=1.044554;
2898                                                                 if(0.127231 <= x < 0.143512 ) mweight=1.062733;
2899                                                                 if(0.143512 <= x < 0.161877 ) mweight=1.085332;
2900                                                                 if(0.161877 <= x < 0.182592 ) mweight=1.115248;
2901                                                                 if(0.182592 <= x < 0.205957 ) mweight=1.153990;
2902                                                                 if(0.205957 <= x < 0.232313 ) mweight=1.201346;
2903                                                                 if(0.232313 <= x < 0.262041 ) mweight=1.257332;
2904                                                                 if(0.262041 <= x < 0.295573 ) mweight=1.315488;
2905                                                                 if(0.295573 <= x < 0.333397 ) mweight=1.369138;
2906                                                                 if(0.333397 <= x < 0.376060 ) mweight=1.407632;
2907                                                                 if(0.376060 <= x < 0.424183 ) mweight=1.422232;
2908                                                                 if(0.424183 <= x < 0.478465 ) mweight=1.406922;
2909                                                                 if(0.478465 <= x < 0.539692 ) mweight=1.360082;
2910                                                                 if(0.539692 <= x < 0.608754 ) mweight=1.284405;
2911                                                                 if(0.608754 <= x < 0.686654 ) mweight=1.182017;
2912                                                                 if(0.686654 <= x < 0.774523 ) mweight=1.062002;
2913                                                                 if(0.774523 <= x < 0.873636 ) mweight=0.935533;
2914                                                                 if(0.873636 <= x < 0.985432 ) mweight=0.816081;
2915                                                                 if(0.985432 <= x < 1.111534 ) mweight=0.717527;
2916                                                                 if(1.111534 <= x < 1.253773 ) mweight=0.647465;
2917                                                                 if(1.253773 <= x < 1.414214 ) mweight=0.607212;
2918                                                                 if(1.414214 <= x < 1.595185 ) mweight=0.589750;
2919                                                                 if(1.595185 <= x < 1.799315 ) mweight=0.587406;
2920                                                                 if(1.799315 <= x < 2.029567 ) mweight=0.592858;
2921                                                                 if(2.029567 <= x < 2.289283 ) mweight=0.601059;
2922                                                                 if(2.289283 <= x < 2.582235 ) mweight=0.608003;
2923                                                                 if(2.582235 <= x < 2.912674 ) mweight=0.611705;
2924                                                                 if(2.912674 <= x < 3.285398 ) mweight=0.610086;
2925                                                                 if(3.285398 <= x < 3.705818 ) mweight=0.605015;
2926                                                                 if(3.705818 <= x < 4.180038 ) mweight=0.596299;
2927                                                                 if(4.180038 <= x < 4.714942 ) mweight=0.590727;
2928                                                                 if(4.714942 <= x < 5.318296 ) mweight=0.585358;
2929                                                                 if(5.318296 <= x < 5.998859 ) mweight=0.585257;
2930                                                                 if(5.998859 <= x < 6.766511 ) mweight=0.580812;
2931                                                                 if(6.766511 <= x < 7.632396 ) mweight=0.576207;
2932                                                                 if(7.632396 <= x < 8.609086 ) mweight=0.575912;
2933                                                                 if(8.609086 <= x < 9.710759 ) mweight=0.558718;
2934                                                                 if(9.710759 <= x < 10.953409 ) mweight=0.555625;
2935                                                                 if(10.953409 <= x < 12.355077 ) mweight=0.558886;
2936                                                                 if(12.355077 <= x < 13.936111 ) mweight=0.545318;
2937                                                                 if(13.936111 <= x < 15.719464 ) mweight=0.517607;
2938                                                                 if(15.719464 <= x < 17.731026 ) mweight=0.512366;
2939                                                                 if(17.731026 <= x < 20.000000 ) mweight=0.497034;
2940                                                                 
2941                                                                 
2942                                                         }
2943                                                         
2944                                                         
2945                                                 }//end of IsMCefix
2946                                                 
2947                                                         //________________________________________________________________
2948                                                         //correction for d3 based on data //from Jan
2949                                                 if(!IsMCefix){
2950                                                         if(TMath::Abs(fMCparticleMother->GetPdgCode())==111){
2951                                                                 Double_t x=mPt;
2952                                                                 if(0.100000 <= x < 0.112797 ) mweight=1.262120;
2953                                                                 if(0.112797 <= x < 0.127231 ) mweight=1.277765;
2954                                                                 if(0.127231 <= x < 0.143512 ) mweight=1.295605;
2955                                                                 if(0.143512 <= x < 0.161877 ) mweight=1.318155;
2956                                                                 if(0.161877 <= x < 0.182592 ) mweight=1.348693;
2957                                                                 if(0.182592 <= x < 0.205957 ) mweight=1.388636;
2958                                                                 if(0.205957 <= x < 0.232313 ) mweight=1.439122;
2959                                                                 if(0.232313 <= x < 0.262041 ) mweight=1.497452;
2960                                                                 if(0.262041 <= x < 0.295573 ) mweight=1.559409;
2961                                                                 if(0.295573 <= x < 0.333397 ) mweight=1.615169;
2962                                                                 if(0.333397 <= x < 0.376060 ) mweight=1.654954;
2963                                                                 if(0.376060 <= x < 0.424183 ) mweight=1.668753;
2964                                                                 if(0.424183 <= x < 0.478465 ) mweight=1.652225;
2965                                                                 if(0.478465 <= x < 0.539692 ) mweight=1.603119;
2966                                                                 if(0.539692 <= x < 0.608754 ) mweight=1.526049;
2967                                                                 if(0.608754 <= x < 0.686654 ) mweight=1.426724;
2968                                                                 if(0.686654 <= x < 0.774523 ) mweight=1.312684;
2969                                                                 if(0.774523 <= x < 0.873636 ) mweight=1.195395;
2970                                                                 if(0.873636 <= x < 0.985432 ) mweight=1.086264;
2971                                                                 if(0.985432 <= x < 1.111534 ) mweight=0.993666;
2972                                                                 if(1.111534 <= x < 1.253773 ) mweight=0.922587;
2973                                                                 if(1.253773 <= x < 1.414214 ) mweight=0.875739;
2974                                                                 if(1.414214 <= x < 1.595185 ) mweight=0.852181;
2975                                                                 if(1.595185 <= x < 1.799315 ) mweight=0.847828;
2976                                                                 if(1.799315 <= x < 2.029567 ) mweight=0.863875;
2977                                                                 if(2.029567 <= x < 2.289283 ) mweight=0.899112;
2978                                                                 if(2.289283 <= x < 2.582235 ) mweight=0.955194;
2979                                                                 if(2.582235 <= x < 2.912674 ) mweight=1.033824;
2980                                                                 if(2.912674 <= x < 3.285398 ) mweight=1.133714;
2981                                                                 if(3.285398 <= x < 3.705818 ) mweight=1.259471;
2982                                                                 if(3.705818 <= x < 4.180038 ) mweight=1.406883;
2983                                                                 if(4.180038 <= x < 4.714942 ) mweight=1.578923;
2984                                                                 if(4.714942 <= x < 5.318296 ) mweight=1.778513;
2985                                                                 if(5.318296 <= x < 5.998859 ) mweight=2.001171;
2986                                                                 if(5.998859 <= x < 6.766511 ) mweight=2.223161;
2987                                                                 if(6.766511 <= x < 7.632396 ) mweight=2.449445;
2988                                                                 if(7.632396 <= x < 8.609086 ) mweight=2.661734;
2989                                                                 if(8.609086 <= x < 9.710759 ) mweight=2.851935;
2990                                                                 if(9.710759 <= x < 10.953409 ) mweight=2.974319;
2991                                                                 if(10.953409 <= x < 12.355077 ) mweight=3.106314;
2992                                                                 if(12.355077 <= x < 13.936111 ) mweight=3.126815;
2993                                                                 if(13.936111 <= x < 15.719464 ) mweight=3.150053;
2994                                                                 if(15.719464 <= x < 17.731026 ) mweight=3.218509;
2995                                                                 if(17.731026 <= x < 20.000000 ) mweight=3.252141;
2996                                                                 
2997                                                                 
2998                                                         }
2999                                                 }
3000                                                         //________________________________________________________________
3001                                                 
3002                                                         //Histo pT mother versus pT electron
3003                                                 fpT_m_electron->Fill(mPt, track->Pt());
3004                                                 
3005                                                 if(!IsTPConly)fPtBackgroundBeforeReco_weight->Fill(track->Pt(), 1./mweight);
3006                                                 if(IsTPConly)fPtBackgroundBeforeReco2_weight->Fill(track->Pt(), 1./mweight);
3007                                         }
3008                                         else if(fMCparticleMother->GetMother()>0 && (TMath::Abs(fMCparticleGMother->GetPdgCode())==111 || TMath::Abs(fMCparticleGMother->GetPdgCode())==221 )){
3009                                                 
3010                                                 Double_t gmPt=fMCparticleGMother->Pt();
3011                                                 Double_t gmweight=1;
3012                                                 
3013                                                         //________________________________________________________________
3014                                                         //correction for efix based on data - parametrization from MinJung
3015                                                 if(IsMCefix){
3016                                                         if(TMath::Abs(fMCparticleGMother->GetPdgCode())==111){
3017                                                                 Double_t x=gmPt;
3018                                                                 if(0.100000 <= x < 0.112797 ) gmweight=1.030419;
3019                                                                 if(0.112797 <= x < 0.127231 ) gmweight=1.044554;
3020                                                                 if(0.127231 <= x < 0.143512 ) gmweight=1.062733;
3021                                                                 if(0.143512 <= x < 0.161877 ) gmweight=1.085332;
3022                                                                 if(0.161877 <= x < 0.182592 ) gmweight=1.115248;
3023                                                                 if(0.182592 <= x < 0.205957 ) gmweight=1.153990;
3024                                                                 if(0.205957 <= x < 0.232313 ) gmweight=1.201346;
3025                                                                 if(0.232313 <= x < 0.262041 ) gmweight=1.257332;
3026                                                                 if(0.262041 <= x < 0.295573 ) gmweight=1.315488;
3027                                                                 if(0.295573 <= x < 0.333397 ) gmweight=1.369138;
3028                                                                 if(0.333397 <= x < 0.376060 ) gmweight=1.407632;
3029                                                                 if(0.376060 <= x < 0.424183 ) gmweight=1.422232;
3030                                                                 if(0.424183 <= x < 0.478465 ) gmweight=1.406922;
3031                                                                 if(0.478465 <= x < 0.539692 ) gmweight=1.360082;
3032                                                                 if(0.539692 <= x < 0.608754 ) gmweight=1.284405;
3033                                                                 if(0.608754 <= x < 0.686654 ) gmweight=1.182017;
3034                                                                 if(0.686654 <= x < 0.774523 ) gmweight=1.062002;
3035                                                                 if(0.774523 <= x < 0.873636 ) gmweight=0.935533;
3036                                                                 if(0.873636 <= x < 0.985432 ) gmweight=0.816081;
3037                                                                 if(0.985432 <= x < 1.111534 ) gmweight=0.717527;
3038                                                                 if(1.111534 <= x < 1.253773 ) gmweight=0.647465;
3039                                                                 if(1.253773 <= x < 1.414214 ) gmweight=0.607212;
3040                                                                 if(1.414214 <= x < 1.595185 ) gmweight=0.589750;
3041                                                                 if(1.595185 <= x < 1.799315 ) gmweight=0.587406;
3042                                                                 if(1.799315 <= x < 2.029567 ) gmweight=0.592858;
3043                                                                 if(2.029567 <= x < 2.289283 ) gmweight=0.601059;
3044                                                                 if(2.289283 <= x < 2.582235 ) gmweight=0.608003;
3045                                                                 if(2.582235 <= x < 2.912674 ) gmweight=0.611705;
3046                                                                 if(2.912674 <= x < 3.285398 ) gmweight=0.610086;
3047                                                                 if(3.285398 <= x < 3.705818 ) gmweight=0.605015;
3048                                                                 if(3.705818 <= x < 4.180038 ) gmweight=0.596299;
3049                                                                 if(4.180038 <= x < 4.714942 ) gmweight=0.590727;
3050                                                                 if(4.714942 <= x < 5.318296 ) gmweight=0.585358;
3051                                                                 if(5.318296 <= x < 5.998859 ) gmweight=0.585257;
3052                                                                 if(5.998859 <= x < 6.766511 ) gmweight=0.580812;
3053                                                                 if(6.766511 <= x < 7.632396 ) gmweight=0.576207;
3054                                                                 if(7.632396 <= x < 8.609086 ) gmweight=0.575912;
3055                                                                 if(8.609086 <= x < 9.710759 ) gmweight=0.558718;
3056                                                                 if(9.710759 <= x < 10.953409 ) gmweight=0.555625;
3057                                                                 if(10.953409 <= x < 12.355077 ) gmweight=0.558886;
3058                                                                 if(12.355077 <= x < 13.936111 ) gmweight=0.545318;
3059                                                                 if(13.936111 <= x < 15.719464 ) gmweight=0.517607;
3060                                                                 if(15.719464 <= x < 17.731026 ) gmweight=0.512366;
3061                                                                 if(17.731026 <= x < 20.000000 ) gmweight=0.497034;
3062                                                                 
3063                                                                 
3064                                                                 
3065                                                         }
3066                                                         
3067                                                         
3068                                                 }//end of IsMCefix
3069                                                 
3070                                                         //________________________________________________________________
3071                                                         //correction for d3 based on data
3072                                                 if(!IsMCefix){
3073                                                         if(TMath::Abs(fMCparticleGMother->GetPdgCode())==111){
3074                                                                 Double_t x=gmPt;
3075                                                                 if(0.100000 <= x < 0.112797 ) gmweight=1.262120;
3076                                                                 if(0.112797 <= x < 0.127231 ) gmweight=1.277765;
3077                                                                 if(0.127231 <= x < 0.143512 ) gmweight=1.295605;
3078                                                                 if(0.143512 <= x < 0.161877 ) gmweight=1.318155;
3079                                                                 if(0.161877 <= x < 0.182592 ) gmweight=1.348693;
3080                                                                 if(0.182592 <= x < 0.205957 ) gmweight=1.388636;
3081                                                                 if(0.205957 <= x < 0.232313 ) gmweight=1.439122;
3082                                                                 if(0.232313 <= x < 0.262041 ) gmweight=1.497452;
3083                                                                 if(0.262041 <= x < 0.295573 ) gmweight=1.559409;
3084                                                                 if(0.295573 <= x < 0.333397 ) gmweight=1.615169;
3085                                                                 if(0.333397 <= x < 0.376060 ) gmweight=1.654954;
3086                                                                 if(0.376060 <= x < 0.424183 ) gmweight=1.668753;
3087                                                                 if(0.424183 <= x < 0.478465 ) gmweight=1.652225;
3088                                                                 if(0.478465 <= x < 0.539692 ) gmweight=1.603119;
3089                                                                 if(0.539692 <= x < 0.608754 ) gmweight=1.526049;
3090                                                                 if(0.608754 <= x < 0.686654 ) gmweight=1.426724;
3091                                                                 if(0.686654 <= x < 0.774523 ) gmweight=1.312684;
3092                                                                 if(0.774523 <= x < 0.873636 ) gmweight=1.195395;
3093                                                                 if(0.873636 <= x < 0.985432 ) gmweight=1.086264;
3094                                                                 if(0.985432 <= x < 1.111534 ) gmweight=0.993666;
3095                                                                 if(1.111534 <= x < 1.253773 ) gmweight=0.922587;
3096                                                                 if(1.253773 <= x < 1.414214 ) gmweight=0.875739;
3097                                                                 if(1.414214 <= x < 1.595185 ) gmweight=0.852181;
3098                                                                 if(1.595185 <= x < 1.799315 ) gmweight=0.847828;
3099                                                                 if(1.799315 <= x < 2.029567 ) gmweight=0.863875;
3100                                                                 if(2.029567 <= x < 2.289283 ) gmweight=0.899112;
3101                                                                 if(2.289283 <= x < 2.582235 ) gmweight=0.955194;
3102                                                                 if(2.582235 <= x < 2.912674 ) gmweight=1.033824;
3103                                                                 if(2.912674 <= x < 3.285398 ) gmweight=1.133714;
3104                                                                 if(3.285398 <= x < 3.705818 ) gmweight=1.259471;
3105                                                                 if(3.705818 <= x < 4.180038 ) gmweight=1.406883;
3106                                                                 if(4.180038 <= x < 4.714942 ) gmweight=1.578923;
3107                                                                 if(4.714942 <= x < 5.318296 ) gmweight=1.778513;
3108                                                                 if(5.318296 <= x < 5.998859 ) gmweight=2.001171;
3109                                                                 if(5.998859 <= x < 6.766511 ) gmweight=2.223161;
3110                                                                 if(6.766511 <= x < 7.632396 ) gmweight=2.449445;
3111                                                                 if(7.632396 <= x < 8.609086 ) gmweight=2.661734;
3112                                                                 if(8.609086 <= x < 9.710759 ) gmweight=2.851935;
3113                                                                 if(9.710759 <= x < 10.953409 ) gmweight=2.974319;
3114                                                                 if(10.953409 <= x < 12.355077 ) gmweight=3.106314;
3115                                                                 if(12.355077 <= x < 13.936111 ) gmweight=3.126815;
3116                                                                 if(13.936111 <= x < 15.719464 ) gmweight=3.150053;
3117                                                                 if(15.719464 <= x < 17.731026 ) gmweight=3.218509;
3118                                                                 if(17.731026 <= x < 20.000000 ) gmweight=3.252141;
3119                                                                 
3120                                                         }
3121                                                 }
3122                                                 
3123                                                         //________________________________________________________________
3124                                                 
3125                                                 
3126                                                         //Histo pT gmother versus pT electron 
3127                                                 fpT_gm_electron->Fill(gmPt, track->Pt());
3128                                                 
3129                                                 if(!IsTPConly)fPtBackgroundBeforeReco_weight->Fill(track->Pt(), 1./gmweight);
3130                                                 if(IsTPConly)fPtBackgroundBeforeReco2_weight->Fill(track->Pt(), 1./gmweight);
3131                                         }
3132                                         else{
3133                                                 if(!IsTPConly)fPtBackgroundBeforeReco_weight->Fill(track->Pt());
3134                                                 if(IsTPConly)fPtBackgroundBeforeReco2_weight->Fill(track->Pt());                                
3135                                         }
3136                                 }//particle kind
3137                         }//IsAOD
3138                          //ESD
3139                         else
3140                         {
3141                                 fMCtrack = fMCstack->Particle(track->GetLabel());
3142                                 
3143                                 if(fMCtrack->GetFirstMother()<0) return;
3144                                 
3145                                 fMCtrackMother = fMCstack->Particle(fMCtrack->GetFirstMother());
3146                                 
3147                                 if(TMath::Abs(fMCtrack->GetPdgCode())==11 && (TMath::Abs(fMCtrackMother->GetPdgCode())==22 || TMath::Abs(fMCtrackMother->GetPdgCode())==111 || TMath::Abs(fMCtrackMother->GetPdgCode())==221))
3148                                 {
3149                                                 //Is Background
3150                                         if(!IsTPConly)fPtBackgroundBeforeReco->Fill(track->Pt());
3151                                         if(IsTPConly)fPtBackgroundBeforeReco2->Fill(track->Pt());
3152                                 }
3153                         }
3154                 }//IsMC
3155                 
3156                         ///_________________________________________________________________
3157                 
3158                         //________________________________________________
3159                         //Associated particle cut
3160                 fPartnerCuts->SetAcceptKinkDaughters(kFALSE);
3161                 fPartnerCuts->SetRequireITSRefit(kTRUE);
3162                 fPartnerCuts->SetRequireTPCRefit(kTRUE);
3163                 fPartnerCuts->SetEtaRange(-0.9,0.9);
3164                 fPartnerCuts->SetMaxChi2PerClusterTPC(4.0);
3165                 fPartnerCuts->SetMinNClustersTPC(80);
3166                 fPartnerCuts->SetPtRange(0.3,1e10);
3167                         //fPartnerCuts->SetRequireSigmaToVertex(kTRUE);
3168                         //fPartnerCuts->SetMaxDCAToVertexXY(1);
3169                         //fPartnerCuts->SetMaxDCAToVertexZ(3);
3170                         //_________________________________________________
3171                 
3172                         ///#################################################################
3173                         //Non-HFE reconstruction
3174                 fNonHFE = new AliSelectNonHFE();
3175                 fNonHFE->SetAODanalysis(fIsAOD);
3176                 if(fMassCutFlag) fNonHFE->SetInvariantMassCut(fMassCut);
3177                 if(fAngleCutFlag) fNonHFE->SetOpeningAngleCut(fAngleCut);
3178                 if(fChi2CutFlag) fNonHFE->SetChi2OverNDFCut(fChi2Cut);
3179                 if(fDCAcutFlag) fNonHFE->SetDCACut(fDCAcut);
3180                 fNonHFE->SetAlgorithm("DCA"); //KF
3181                 fNonHFE->SetPIDresponse(fPidResponse);
3182                 fNonHFE->SetTrackCuts(-3.5,3.5,fPartnerCuts);
3183                 fNonHFE->SetAdditionalCuts(fPtMinAsso,fTpcNclsAsso);
3184                 
3185                 if(!IsTPConly){
3186                         fNonHFE->SetHistAngleBack(fOpAngleBack);
3187                         fNonHFE->SetHistAngle(fOpAngle);
3188                         fNonHFE->SetHistDCABack(fDCABack);
3189                         fNonHFE->SetHistDCA(fDCA);
3190                         fNonHFE->SetHistMassBack(fInvMassBack);
3191                         fNonHFE->SetHistMass(fInvMass);
3192                 }
3193                 if(IsTPConly){
3194                         fNonHFE->SetHistAngleBack(fOpAngleBack2);
3195                         fNonHFE->SetHistAngle(fOpAngle2);
3196                         fNonHFE->SetHistDCABack(fDCABack2);
3197                         fNonHFE->SetHistDCA(fDCA2);
3198                         fNonHFE->SetHistMassBack(fInvMassBack2);
3199                         fNonHFE->SetHistMass(fInvMass2);
3200                 }
3201                 
3202                 fNonHFE->FindNonHFE(trackIndex,vtrack,fVevent);
3203                 
3204                         //index of track selected as partner
3205                 Int_t *fUlsPartner = fNonHFE->GetPartnersULS();
3206                 
3207                         //Electron Information
3208                 Double_t fPhiE = -999;
3209                 Double_t fEtaE = -999;
3210                 Double_t fPtE = -999;
3211                 fPhiE = track->Phi();
3212                 fEtaE = track->Eta();
3213                 fPtE = track->Pt();
3214                 
3215                         ///_________________________________________________________________
3216                         ///MC analysis
3217                 if(fIsMC)
3218                 {
3219                         if(fIsAOD)
3220                         {
3221                                 if(TMath::Abs(fMCparticle->GetPdgCode())==11 && (TMath::Abs(fMCparticleMother->GetPdgCode())==22 || TMath::Abs(fMCparticleMother->GetPdgCode())==111 || TMath::Abs(fMCparticleMother->GetPdgCode())==221))
3222                                 {
3223                                         
3224                                         Double_t weight=1;
3225                                         
3226                                         if(!IsTPConly){
3227                                                 if(fNonHFE->IsULS()) fPtElec_ULS->Fill(fPtE,fNonHFE->GetNULS());
3228                                                 if(fNonHFE->IsLS()) fPtElec_LS->Fill(fPtE,fNonHFE->GetNLS());
3229                                                 
3230                                                 
3231                                                 
3232                                                 
3233                                                 if(TMath::Abs(fMCparticleMother->GetPdgCode())==111 || TMath::Abs(fMCparticleMother->GetPdgCode())==221){
3234                                                         Double_t mPt=fMCparticleMother->Pt();
3235                                                         Double_t mweight1=1;
3236                                                         Double_t mweight2=1;
3237                                                                 //Double_t weight=1;
3238                                                         
3239                                                                 //----------------------------------------------------------------------------
3240                                                         if(IsMCefix){
3241                                                                 if(TMath::Abs(fMCparticleMother->GetPdgCode())==111){
3242                                                                         Double_t x=mPt;
3243                                                                         if(0.100000 <= x < 0.112797 ) weight=1.030419;
3244                                                                         if(0.112797 <= x < 0.127231 ) weight=1.044554;
3245                                                                         if(0.127231 <= x < 0.143512 ) weight=1.062733;
3246                                                                         if(0.143512 <= x < 0.161877 ) weight=1.085332;
3247                                                                         if(0.161877 <= x < 0.182592 ) weight=1.115248;
3248                                                                         if(0.182592 <= x < 0.205957 ) weight=1.153990;
3249                                                                         if(0.205957 <= x < 0.232313 ) weight=1.201346;
3250                                                                         if(0.232313 <= x < 0.262041 ) weight=1.257332;
3251                                                                         if(0.262041 <= x < 0.295573 ) weight=1.315488;
3252                                                                         if(0.295573 <= x < 0.333397 ) weight=1.369138;
3253                                                                         if(0.333397 <= x < 0.376060 ) weight=1.407632;
3254                                                                         if(0.376060 <= x < 0.424183 ) weight=1.422232;
3255                                                                         if(0.424183 <= x < 0.478465 ) weight=1.406922;
3256                                                                         if(0.478465 <= x < 0.539692 ) weight=1.360082;
3257                                                                         if(0.539692 <= x < 0.608754 ) weight=1.284405;
3258                                                                         if(0.608754 <= x < 0.686654 ) weight=1.182017;
3259                                                                         if(0.686654 <= x < 0.774523 ) weight=1.062002;
3260                                                                         if(0.774523 <= x < 0.873636 ) weight=0.935533;
3261                                                                         if(0.873636 <= x < 0.985432 ) weight=0.816081;
3262                                                                         if(0.985432 <= x < 1.111534 ) weight=0.717527;
3263                                                                         if(1.111534 <= x < 1.253773 ) weight=0.647465;
3264                                                                         if(1.253773 <= x < 1.414214 ) weight=0.607212;
3265                                                                         if(1.414214 <= x < 1.595185 ) weight=0.589750;
3266                                                                         if(1.595185 <= x < 1.799315 ) weight=0.587406;
3267                                                                         if(1.799315 <= x < 2.029567 ) weight=0.592858;
3268                                                                         if(2.029567 <= x < 2.289283 ) weight=0.601059;
3269                                                                         if(2.289283 <= x < 2.582235 ) weight=0.608003;
3270                                                                         if(2.582235 <= x < 2.912674 ) weight=0.611705;
3271                                                                         if(2.912674 <= x < 3.285398 ) weight=0.610086;
3272                                                                         if(3.285398 <= x < 3.705818 ) weight=0.605015;
3273                                                                         if(3.705818 <= x < 4.180038 ) weight=0.596299;
3274                                                                         if(4.180038 <= x < 4.714942 ) weight=0.590727;
3275                                                                         if(4.714942 <= x < 5.318296 ) weight=0.585358;
3276                                                                         if(5.318296 <= x < 5.998859 ) weight=0.585257;
3277                                                                         if(5.998859 <= x < 6.766511 ) weight=0.580812;
3278                                                                         if(6.766511 <= x < 7.632396 ) weight=0.576207;
3279                                                                         if(7.632396 <= x < 8.609086 ) weight=0.575912;
3280                                                                         if(8.609086 <= x < 9.710759 ) weight=0.558718;
3281                                                                         if(9.710759 <= x < 10.953409 ) weight=0.555625;
3282                                                                         if(10.953409 <= x < 12.355077 ) weight=0.558886;
3283                                                                         if(12.355077 <= x < 13.936111 ) weight=0.545318;
3284                                                                         if(13.936111 <= x < 15.719464 ) weight=0.517607;
3285                                                                         if(15.719464 <= x < 17.731026 ) weight=0.512366;
3286                                                                         if(17.731026 <= x < 20.000000 ) weight=0.497034;
3287                                                                         
3288                                                                         
3289                                                                 }
3290                                                                 
3291                                                                 
3292                                                         }//end of IsMCefix
3293                                                          //----------------------------------------------------------------------------
3294                                                          //correction based on data only for pi0
3295                                                         if(!IsMCefix){
3296                                                                 if(TMath::Abs(fMCparticleMother->GetPdgCode())==111){
3297                                                                         Double_t x=mPt;
3298                                                                         if(0.100000 <= x < 0.112797 ) weight=1.262120;
3299                                                                         if(0.112797 <= x < 0.127231 ) weight=1.277765;
3300                                                                         if(0.127231 <= x < 0.143512 ) weight=1.295605;
3301                                                                         if(0.143512 <= x < 0.161877 ) weight=1.318155;
3302                                                                         if(0.161877 <= x < 0.182592 ) weight=1.348693;
3303                                                                         if(0.182592 <= x < 0.205957 ) weight=1.388636;
3304                                                                         if(0.205957 <= x < 0.232313 ) weight=1.439122;
3305                                                                         if(0.232313 <= x < 0.262041 ) weight=1.497452;
3306                                                                         if(0.262041 <= x < 0.295573 ) weight=1.559409;
3307                                                                         if(0.295573 <= x < 0.333397 ) weight=1.615169;
3308                                                                         if(0.333397 <= x < 0.376060 ) weight=1.654954;
3309                                                                         if(0.376060 <= x < 0.424183 ) weight=1.668753;
3310                                                                         if(0.424183 <= x < 0.478465 ) weight=1.652225;
3311                                                                         if(0.478465 <= x < 0.539692 ) weight=1.603119;
3312                                                                         if(0.539692 <= x < 0.608754 ) weight=1.526049;
3313                                                                         if(0.608754 <= x < 0.686654 ) weight=1.426724;
3314                                                                         if(0.686654 <= x < 0.774523 ) weight=1.312684;
3315                                                                         if(0.774523 <= x < 0.873636 ) weight=1.195395;
3316                                                                         if(0.873636 <= x < 0.985432 ) weight=1.086264;
3317                                                                         if(0.985432 <= x < 1.111534 ) weight=0.993666;
3318                                                                         if(1.111534 <= x < 1.253773 ) weight=0.922587;
3319                                                                         if(1.253773 <= x < 1.414214 ) weight=0.875739;
3320                                                                         if(1.414214 <= x < 1.595185 ) weight=0.852181;
3321                                                                         if(1.595185 <= x < 1.799315 ) weight=0.847828;
3322                                                                         if(1.799315 <= x < 2.029567 ) weight=0.863875;
3323                                                                         if(2.029567 <= x < 2.289283 ) weight=0.899112;
3324                                                                         if(2.289283 <= x < 2.582235 ) weight=0.955194;
3325                                                                         if(2.582235 <= x < 2.912674 ) weight=1.033824;
3326                                                                         if(2.912674 <= x < 3.285398 ) weight=1.133714;
3327                                                                         if(3.285398 <= x < 3.705818 ) weight=1.259471;
3328                                                                         if(3.705818 <= x < 4.180038 ) weight=1.406883;
3329                                                                         if(4.180038 <= x < 4.714942 ) weight=1.578923;
3330                                                                         if(4.714942 <= x < 5.318296 ) weight=1.778513;
3331                                                                         if(5.318296 <= x < 5.998859 ) weight=2.001171;
3332                                                                         if(5.998859 <= x < 6.766511 ) weight=2.223161;
3333                                                                         if(6.766511 <= x < 7.632396 ) weight=2.449445;
3334                                                                         if(7.632396 <= x < 8.609086 ) weight=2.661734;
3335                                                                         if(8.609086 <= x < 9.710759 ) weight=2.851935;
3336                                                                         if(9.710759 <= x < 10.953409 ) weight=2.974319;
3337                                                                         if(10.953409 <= x < 12.355077 ) weight=3.106314;
3338                                                                         if(12.355077 <= x < 13.936111 ) weight=3.126815;
3339                                                                         if(13.936111 <= x < 15.719464 ) weight=3.150053;
3340                                                                         if(15.719464 <= x < 17.731026 ) weight=3.218509;
3341                                                                         if(17.731026 <= x < 20.000000 ) weight=3.252141;
3342                                                                         
3343                                                                         
3344                                                                 }
3345                                                                 
3346                                                         }
3347                                                                 //----------------------------------------------------------------------------
3348                                                         
3349                                                                 //check this
3350                                                         if(fNonHFE->IsULS()) mweight1=(fNonHFE->GetNULS())/weight;
3351                                                         if(fNonHFE->IsLS())  mweight2=(fNonHFE->GetNLS())/weight;
3352                                                         
3353                                                                 //fill histos
3354                                                         if(fNonHFE->IsULS())fPtElec_ULS_weight->Fill(fPtE, mweight1);
3355                                                         if(fNonHFE->IsLS())fPtElec_LS_weight->Fill(fPtE, mweight2);
3356                                                 }
3357                                                 else if(fMCparticleMother->GetMother()>0 && (TMath::Abs(fMCparticleGMother->GetPdgCode())==111 || TMath::Abs(fMCparticleGMother->GetPdgCode())==221 )){
3358                                                         Double_t gmPt=fMCparticleGMother->Pt();
3359                                                         Double_t gmweight1=1;
3360                                                         Double_t gmweight2=1;
3361                                                                 //Double_t weight=1;
3362                                                         
3363                                                                 //----------------------------------------------------------------------------
3364                                                         if(IsMCefix){
3365                                                                 if(TMath::Abs(fMCparticleGMother->GetPdgCode())==111){
3366                                                                         Double_t x=gmPt;
3367                                                                         if(0.100000 <= x < 0.112797 ) weight=1.030419;
3368                                                                         if(0.112797 <= x < 0.127231 ) weight=1.044554;
3369                                                                         if(0.127231 <= x < 0.143512 ) weight=1.062733;
3370                                                                         if(0.143512 <= x < 0.161877 ) weight=1.085332;
3371                                                                         if(0.161877 <= x < 0.182592 ) weight=1.115248;
3372                                                                         if(0.182592 <= x < 0.205957 ) weight=1.153990;
3373                                                                         if(0.205957 <= x < 0.232313 ) weight=1.201346;
3374                                                                         if(0.232313 <= x < 0.262041 ) weight=1.257332;
3375                                                                         if(0.262041 <= x < 0.295573 ) weight=1.315488;
3376                                                                         if(0.295573 <= x < 0.333397 ) weight=1.369138;
3377                                                                         if(0.333397 <= x < 0.376060 ) weight=1.407632;
3378                                                                         if(0.376060 <= x < 0.424183 ) weight=1.422232;
3379                                                                         if(0.424183 <= x < 0.478465 ) weight=1.406922;
3380                                                                         if(0.478465 <= x < 0.539692 ) weight=1.360082;
3381                                                                         if(0.539692 <= x < 0.608754 ) weight=1.284405;
3382                                                                         if(0.608754 <= x < 0.686654 ) weight=1.182017;
3383                                                                         if(0.686654 <= x < 0.774523 ) weight=1.062002;
3384                                                                         if(0.774523 <= x < 0.873636 ) weight=0.935533;
3385                                                                         if(0.873636 <= x < 0.985432 ) weight=0.816081;
3386                                                                         if(0.985432 <= x < 1.111534 ) weight=0.717527;
3387                                                                         if(1.111534 <= x < 1.253773 ) weight=0.647465;
3388                                                                         if(1.253773 <= x < 1.414214 ) weight=0.607212;
3389                                                                         if(1.414214 <= x < 1.595185 ) weight=0.589750;
3390                                                                         if(1.595185 <= x < 1.799315 ) weight=0.587406;
3391                                                                         if(1.799315 <= x < 2.029567 ) weight=0.592858;
3392                                                                         if(2.029567 <= x < 2.289283 ) weight=0.601059;
3393                                                                         if(2.289283 <= x < 2.582235 ) weight=0.608003;
3394                                                                         if(2.582235 <= x < 2.912674 ) weight=0.611705;
3395                                                                         if(2.912674 <= x < 3.285398 ) weight=0.610086;
3396                                                                         if(3.285398 <= x < 3.705818 ) weight=0.605015;
3397                                                                         if(3.705818 <= x < 4.180038 ) weight=0.596299;
3398                                                                         if(4.180038 <= x < 4.714942 ) weight=0.590727;
3399                                                                         if(4.714942 <= x < 5.318296 ) weight=0.585358;
3400                                                                         if(5.318296 <= x < 5.998859 ) weight=0.585257;
3401                                                                         if(5.998859 <= x < 6.766511 ) weight=0.580812;
3402                                                                         if(6.766511 <= x < 7.632396 ) weight=0.576207;
3403                                                                         if(7.632396 <= x < 8.609086 ) weight=0.575912;
3404                                                                         if(8.609086 <= x < 9.710759 ) weight=0.558718;
3405                                                                         if(9.710759 <= x < 10.953409 ) weight=0.555625;
3406                                                                         if(10.953409 <= x < 12.355077 ) weight=0.558886;
3407                                                                         if(12.355077 <= x < 13.936111 ) weight=0.545318;
3408                                                                         if(13.936111 <= x < 15.719464 ) weight=0.517607;
3409                                                                         if(15.719464 <= x < 17.731026 ) weight=0.512366;
3410                                                                         if(17.731026 <= x < 20.000000 ) weight=0.497034;
3411                                                                         
3412                                                                         
3413                                                                 }
3414                                                                 
3415                                                                 
3416                                                         }//end of IsMCefix
3417                                                          //----------------------------------------------------------------------------
3418                                                         
3419                                                                 //correction based on data only for pi0
3420                                                         if(!IsMCefix){
3421                                                                 if(TMath::Abs(fMCparticleGMother->GetPdgCode())==111){
3422                                                                         Double_t x=gmPt;
3423                                                                         if(0.100000 <= x < 0.112797 ) weight=1.262120;
3424                                                                         if(0.112797 <= x < 0.127231 ) weight=1.277765;
3425                                                                         if(0.127231 <= x < 0.143512 ) weight=1.295605;
3426                                                                         if(0.143512 <= x < 0.161877 ) weight=1.318155;
3427                                                                         if(0.161877 <= x < 0.182592 ) weight=1.348693;
3428                                                                         if(0.182592 <= x < 0.205957 ) weight=1.388636;
3429                                                                         if(0.205957 <= x < 0.232313 ) weight=1.439122;
3430                                                                         if(0.232313 <= x < 0.262041 ) weight=1.497452;
3431                                                                         if(0.262041 <= x < 0.295573 ) weight=1.559409;
3432                                                                         if(0.295573 <= x < 0.333397 ) weight=1.615169;
3433                                                                         if(0.333397 <= x < 0.376060 ) weight=1.654954;
3434                                                                         if(0.376060 <= x < 0.424183 ) weight=1.668753;
3435                                                                         if(0.424183 <= x < 0.478465 ) weight=1.652225;
3436                                                                         if(0.478465 <= x < 0.539692 ) weight=1.603119;
3437                                                                         if(0.539692 <= x < 0.608754 ) weight=1.526049;
3438                                                                         if(0.608754 <= x < 0.686654 ) weight=1.426724;
3439                                                                         if(0.686654 <= x < 0.774523 ) weight=1.312684;
3440                                                                         if(0.774523 <= x < 0.873636 ) weight=1.195395;
3441                                                                         if(0.873636 <= x < 0.985432 ) weight=1.086264;
3442                                                                         if(0.985432 <= x < 1.111534 ) weight=0.993666;
3443                                                                         if(1.111534 <= x < 1.253773 ) weight=0.922587;
3444                                                                         if(1.253773 <= x < 1.414214 ) weight=0.875739;
3445                                                                         if(1.414214 <= x < 1.595185 ) weight=0.852181;
3446                                                                         if(1.595185 <= x < 1.799315 ) weight=0.847828;
3447                                                                         if(1.799315 <= x < 2.029567 ) weight=0.863875;
3448                                                                         if(2.029567 <= x < 2.289283 ) weight=0.899112;
3449                                                                         if(2.289283 <= x < 2.582235 ) weight=0.955194;
3450                                                                         if(2.582235 <= x < 2.912674 ) weight=1.033824;
3451                                                                         if(2.912674 <= x < 3.285398 ) weight=1.133714;
3452                                                                         if(3.285398 <= x < 3.705818 ) weight=1.259471;
3453                                                                         if(3.705818 <= x < 4.180038 ) weight=1.406883;
3454                                                                         if(4.180038 <= x < 4.714942 ) weight=1.578923;
3455                                                                         if(4.714942 <= x < 5.318296 ) weight=1.778513;
3456                                                                         if(5.318296 <= x < 5.998859 ) weight=2.001171;
3457                                                                         if(5.998859 <= x < 6.766511 ) weight=2.223161;
3458                                                                         if(6.766511 <= x < 7.632396 ) weight=2.449445;
3459                                                                         if(7.632396 <= x < 8.609086 ) weight=2.661734;
3460                                                                         if(8.609086 <= x < 9.710759 ) weight=2.851935;
3461                                                                         if(9.710759 <= x < 10.953409 ) weight=2.974319;
3462                                                                         if(10.953409 <= x < 12.355077 ) weight=3.106314;
3463                                                                         if(12.355077 <= x < 13.936111 ) weight=3.126815;
3464                                                                         if(13.936111 <= x < 15.719464 ) weight=3.150053;
3465                                                                         if(15.719464 <= x < 17.731026 ) weight=3.218509;
3466                                                                         if(17.731026 <= x < 20.000000 ) weight=3.252141;
3467                                                                         
3468                                                                         
3469                                                                 }
3470                                                         }
3471                                                         
3472                                                         
3473                                                         
3474                                                         
3475                                                                 //check this
3476                                                         if(fNonHFE->IsULS()) gmweight1=(fNonHFE->GetNULS())/weight;
3477                                                         if(fNonHFE->IsLS())  gmweight2=(fNonHFE->GetNLS())/weight;
3478                                                         
3479                                                                 //fill histos
3480                                                         if(fNonHFE->IsULS())fPtElec_ULS_weight->Fill(fPtE, gmweight1);
3481                                                         if(fNonHFE->IsLS())fPtElec_LS_weight->Fill(fPtE, gmweight2);
3482                                                 }
3483                                                 else{
3484                                                         if(fNonHFE->IsULS()) fPtElec_ULS_weight->Fill(fPtE,fNonHFE->GetNULS());
3485                                                         if(fNonHFE->IsLS()) fPtElec_LS_weight->Fill(fPtE,fNonHFE->GetNLS());                            
3486                                                 }
3487                                                 
3488                                                 
3489                                         }//!IsTPConly
3490                                         
3491                                         if(IsTPConly){
3492                                                 if(fNonHFE->IsULS()) fPtElec_ULS2->Fill(fPtE,fNonHFE->GetNULS());
3493                                                 if(fNonHFE->IsLS()) fPtElec_LS2->Fill(fPtE,fNonHFE->GetNLS());
3494                                                 
3495                                                 
3496                                                 
3497                                                 
3498                                                         //new 08 October        //weighted histograms 
3499                                                 if(TMath::Abs(fMCparticleMother->GetPdgCode())==111 || TMath::Abs(fMCparticleMother->GetPdgCode())==221){
3500                                                         Double_t mPt=fMCparticleMother->Pt();
3501                                                         
3502                                                         Double_t mweight1=1;
3503                                                         Double_t mweight2=1;
3504                                                                 //Double_t weight=1;
3505                                                         
3506                                                                 //----------------------------------------------------------------------------
3507                                                         if(IsMCefix){
3508                                                                 if(TMath::Abs(fMCparticleMother->GetPdgCode())==111){
3509                                                                         Double_t x=mPt;
3510                                                                         if(0.100000 <= x < 0.112797 ) weight=1.030419;
3511                                                                         if(0.112797 <= x < 0.127231 ) weight=1.044554;
3512                                                                         if(0.127231 <= x < 0.143512 ) weight=1.062733;
3513                                                                         if(0.143512 <= x < 0.161877 ) weight=1.085332;
3514                                                                         if(0.161877 <= x < 0.182592 ) weight=1.115248;
3515                                                                         if(0.182592 <= x < 0.205957 ) weight=1.153990;
3516                                                                         if(0.205957 <= x < 0.232313 ) weight=1.201346;
3517                                                                         if(0.232313 <= x < 0.262041 ) weight=1.257332;
3518                                                                         if(0.262041 <= x < 0.295573 ) weight=1.315488;
3519                                                                         if(0.295573 <= x < 0.333397 ) weight=1.369138;
3520                                                                         if(0.333397 <= x < 0.376060 ) weight=1.407632;
3521                                                                         if(0.376060 <= x < 0.424183 ) weight=1.422232;
3522                                                                         if(0.424183 <= x < 0.478465 ) weight=1.406922;
3523                                                                         if(0.478465 <= x < 0.539692 ) weight=1.360082;
3524                                                                         if(0.539692 <= x < 0.608754 ) weight=1.284405;
3525                                                                         if(0.608754 <= x < 0.686654 ) weight=1.182017;
3526                                                                         if(0.686654 <= x < 0.774523 ) weight=1.062002;
3527                                                                         if(0.774523 <= x < 0.873636 ) weight=0.935533;
3528                                                                         if(0.873636 <= x < 0.985432 ) weight=0.816081;
3529                                                                         if(0.985432 <= x < 1.111534 ) weight=0.717527;
3530                                                                         if(1.111534 <= x < 1.253773 ) weight=0.647465;
3531                                                                         if(1.253773 <= x < 1.414214 ) weight=0.607212;
3532                                                                         if(1.414214 <= x < 1.595185 ) weight=0.589750;
3533                                                                         if(1.595185 <= x < 1.799315 ) weight=0.587406;
3534                                                                         if(1.799315 <= x < 2.029567 ) weight=0.592858;
3535                                                                         if(2.029567 <= x < 2.289283 ) weight=0.601059;
3536                                                                         if(2.289283 <= x < 2.582235 ) weight=0.608003;
3537                                                                         if(2.582235 <= x < 2.912674 ) weight=0.611705;
3538                                                                         if(2.912674 <= x < 3.285398 ) weight=0.610086;
3539                                                                         if(3.285398 <= x < 3.705818 ) weight=0.605015;
3540                                                                         if(3.705818 <= x < 4.180038 ) weight=0.596299;
3541                                                                         if(4.180038 <= x < 4.714942 ) weight=0.590727;
3542                                                                         if(4.714942 <= x < 5.318296 ) weight=0.585358;
3543                                                                         if(5.318296 <= x < 5.998859 ) weight=0.585257;
3544                                                                         if(5.998859 <= x < 6.766511 ) weight=0.580812;
3545                                                                         if(6.766511 <= x < 7.632396 ) weight=0.576207;
3546                                                                         if(7.632396 <= x < 8.609086 ) weight=0.575912;
3547                                                                         if(8.609086 <= x < 9.710759 ) weight=0.558718;
3548                                                                         if(9.710759 <= x < 10.953409 ) weight=0.555625;
3549                                                                         if(10.953409 <= x < 12.355077 ) weight=0.558886;
3550                                                                         if(12.355077 <= x < 13.936111 ) weight=0.545318;
3551                                                                         if(13.936111 <= x < 15.719464 ) weight=0.517607;
3552                                                                         if(15.719464 <= x < 17.731026 ) weight=0.512366;
3553                                                                         if(17.731026 <= x < 20.000000 ) weight=0.497034;
3554                                                                         
3555                                                                         
3556                                                                 }
3557                                                                 
3558                                                                 
3559                                                         }//end of IsMCefix
3560                                                          //----------------------------------------------------------------------------
3561                                                         
3562                                                                 //correction based on data only for pi0 for d3
3563                                                         if(!IsMCefix){
3564                                                                 if(TMath::Abs(fMCparticleMother->GetPdgCode())==111){
3565                                                                         Double_t x=mPt;
3566                                                                         if(0.100000 <= x < 0.112797 ) weight=1.262120;
3567                                                                         if(0.112797 <= x < 0.127231 ) weight=1.277765;
3568                                                                         if(0.127231 <= x < 0.143512 ) weight=1.295605;
3569                                                                         if(0.143512 <= x < 0.161877 ) weight=1.318155;
3570                                                                         if(0.161877 <= x < 0.182592 ) weight=1.348693;
3571                                                                         if(0.182592 <= x < 0.205957 ) weight=1.388636;
3572                                                                         if(0.205957 <= x < 0.232313 ) weight=1.439122;
3573                                                                         if(0.232313 <= x < 0.262041 ) weight=1.497452;
3574                                                                         if(0.262041 <= x < 0.295573 ) weight=1.559409;
3575                                                                         if(0.295573 <= x < 0.333397 ) weight=1.615169;
3576                                                                         if(0.333397 <= x < 0.376060 ) weight=1.654954;
3577                                                                         if(0.376060 <= x < 0.424183 ) weight=1.668753;
3578                                                                         if(0.424183 <= x < 0.478465 ) weight=1.652225;
3579                                                                         if(0.478465 <= x < 0.539692 ) weight=1.603119;
3580                                                                         if(0.539692 <= x < 0.608754 ) weight=1.526049;
3581                                                                         if(0.608754 <= x < 0.686654 ) weight=1.426724;
3582                                                                         if(0.686654 <= x < 0.774523 ) weight=1.312684;
3583                                                                         if(0.774523 <= x < 0.873636 ) weight=1.195395;
3584                                                                         if(0.873636 <= x < 0.985432 ) weight=1.086264;
3585                                                                         if(0.985432 <= x < 1.111534 ) weight=0.993666;
3586                                                                         if(1.111534 <= x < 1.253773 ) weight=0.922587;
3587                                                                         if(1.253773 <= x < 1.414214 ) weight=0.875739;
3588                                                                         if(1.414214 <= x < 1.595185 ) weight=0.852181;
3589                                                                         if(1.595185 <= x < 1.799315 ) weight=0.847828;
3590                                                                         if(1.799315 <= x < 2.029567 ) weight=0.863875;
3591                                                                         if(2.029567 <= x < 2.289283 ) weight=0.899112;
3592                                                                         if(2.289283 <= x < 2.582235 ) weight=0.955194;
3593                                                                         if(2.582235 <= x < 2.912674 ) weight=1.033824;
3594                                                                         if(2.912674 <= x < 3.285398 ) weight=1.133714;
3595                                                                         if(3.285398 <= x < 3.705818 ) weight=1.259471;
3596                                                                         if(3.705818 <= x < 4.180038 ) weight=1.406883;
3597                                                                         if(4.180038 <= x < 4.714942 ) weight=1.578923;
3598                                                                         if(4.714942 <= x < 5.318296 ) weight=1.778513;
3599                                                                         if(5.318296 <= x < 5.998859 ) weight=2.001171;
3600                                                                         if(5.998859 <= x < 6.766511 ) weight=2.223161;
3601                                                                         if(6.766511 <= x < 7.632396 ) weight=2.449445;
3602                                                                         if(7.632396 <= x < 8.609086 ) weight=2.661734;
3603                                                                         if(8.609086 <= x < 9.710759 ) weight=2.851935;
3604                                                                         if(9.710759 <= x < 10.953409 ) weight=2.974319;
3605                                                                         if(10.953409 <= x < 12.355077 ) weight=3.106314;
3606                                                                         if(12.355077 <= x < 13.936111 ) weight=3.126815;
3607                                                                         if(13.936111 <= x < 15.719464 ) weight=3.150053;
3608                                                                         if(15.719464 <= x < 17.731026 ) weight=3.218509;
3609                                                                         if(17.731026 <= x < 20.000000 ) weight=3.252141;
3610                                                                         
3611                                                                         
3612                                                                 }
3613                                                         }
3614                                                         
3615                                                                 //check this
3616                                                         if(fNonHFE->IsULS()) mweight1=(fNonHFE->GetNULS())/weight;
3617                                                         if(fNonHFE->IsLS())  mweight2=(fNonHFE->GetNLS())/weight;
3618                                                         
3619                                                                 //fill histos
3620                                                         if(fNonHFE->IsULS())fPtElec_ULS2_weight->Fill(fPtE, mweight1);
3621                                                         if(fNonHFE->IsLS())fPtElec_LS2_weight->Fill(fPtE, mweight2);
3622                                                 }
3623                                                 else if(fMCparticleMother->GetMother()>0 && (TMath::Abs(fMCparticleGMother->GetPdgCode())==111 || TMath::Abs(fMCparticleGMother->GetPdgCode())==221 )){
3624                                                         Double_t gmPt=fMCparticleGMother->Pt();
3625                                                         Double_t gmweight1=1;
3626                                                         Double_t gmweight2=1;
3627                                                                 //Double_t weight=1;
3628                                                         
3629                                                         
3630                                                                 //----------------------------------------------------------------------------
3631                                                         if(IsMCefix){
3632                                                                 if(TMath::Abs(fMCparticleGMother->GetPdgCode())==111){
3633                                                                         Double_t x=gmPt;
3634                                                                         if(0.100000 <= x < 0.112797 ) weight=1.030419;
3635                                                                         if(0.112797 <= x < 0.127231 ) weight=1.044554;
3636                                                                         if(0.127231 <= x < 0.143512 ) weight=1.062733;
3637                                                                         if(0.143512 <= x < 0.161877 ) weight=1.085332;
3638                                                                         if(0.161877 <= x < 0.182592 ) weight=1.115248;
3639                                                                         if(0.182592 <= x < 0.205957 ) weight=1.153990;
3640                                                                         if(0.205957 <= x < 0.232313 ) weight=1.201346;
3641                                                                         if(0.232313 <= x < 0.262041 ) weight=1.257332;
3642                                                                         if(0.262041 <= x < 0.295573 ) weight=1.315488;
3643                                                                         if(0.295573 <= x < 0.333397 ) weight=1.369138;
3644                                                                         if(0.333397 <= x < 0.376060 ) weight=1.407632;
3645                                                                         if(0.376060 <= x < 0.424183 ) weight=1.422232;
3646                                                                         if(0.424183 <= x < 0.478465 ) weight=1.406922;
3647                                                                         if(0.478465 <= x < 0.539692 ) weight=1.360082;
3648                                                                         if(0.539692 <= x < 0.608754 ) weight=1.284405;
3649                                                                         if(0.608754 <= x < 0.686654 ) weight=1.182017;
3650                                                                         if(0.686654 <= x < 0.774523 ) weight=1.062002;
3651                                                                         if(0.774523 <= x < 0.873636 ) weight=0.935533;
3652                                                                         if(0.873636 <= x < 0.985432 ) weight=0.816081;
3653                                                                         if(0.985432 <= x < 1.111534 ) weight=0.717527;
3654                                                                         if(1.111534 <= x < 1.253773 ) weight=0.647465;
3655                                                                         if(1.253773 <= x < 1.414214 ) weight=0.607212;
3656                                                                         if(1.414214 <= x < 1.595185 ) weight=0.589750;
3657                                                                         if(1.595185 <= x < 1.799315 ) weight=0.587406;
3658                                                                         if(1.799315 <= x < 2.029567 ) weight=0.592858;
3659                                                                         if(2.029567 <= x < 2.289283 ) weight=0.601059;
3660                                                                         if(2.289283 <= x < 2.582235 ) weight=0.608003;
3661                                                                         if(2.582235 <= x < 2.912674 ) weight=0.611705;
3662                                                                         if(2.912674 <= x < 3.285398 ) weight=0.610086;
3663                                                                         if(3.285398 <= x < 3.705818 ) weight=0.605015;
3664                                                                         if(3.705818 <= x < 4.180038 ) weight=0.596299;
3665                                                                         if(4.180038 <= x < 4.714942 ) weight=0.590727;
3666                                                                         if(4.714942 <= x < 5.318296 ) weight=0.585358;
3667                                                                         if(5.318296 <= x < 5.998859 ) weight=0.585257;
3668                                                                         if(5.998859 <= x < 6.766511 ) weight=0.580812;
3669                                                                         if(6.766511 <= x < 7.632396 ) weight=0.576207;
3670                                                                         if(7.632396 <= x < 8.609086 ) weight=0.575912;
3671                                                                         if(8.609086 <= x < 9.710759 ) weight=0.558718;
3672                                                                         if(9.710759 <= x < 10.953409 ) weight=0.555625;
3673                                                                         if(10.953409 <= x < 12.355077 ) weight=0.558886;
3674                                                                         if(12.355077 <= x < 13.936111 ) weight=0.545318;
3675                                                                         if(13.936111 <= x < 15.719464 ) weight=0.517607;
3676                                                                         if(15.719464 <= x < 17.731026 ) weight=0.512366;
3677                                                                         if(17.731026 <= x < 20.000000 ) weight=0.497034;
3678                                                                         
3679                                                                         
3680                                                                 }
3681                                                                 
3682                                                                 
3683                                                         }//end of IsMCefix
3684                                                          //----------------------------------------------------------------------------
3685                                                          //correction based on data only for pi0
3686                                                         if(!IsMCefix){
3687                                                                 if(TMath::Abs(fMCparticleGMother->GetPdgCode())==111){
3688                                                                         Double_t x=gmPt;
3689                                                                         if(0.100000 <= x < 0.112797 ) weight=1.262120;
3690                                                                         if(0.112797 <= x < 0.127231 ) weight=1.277765;
3691                                                                         if(0.127231 <= x < 0.143512 ) weight=1.295605;
3692                                                                         if(0.143512 <= x < 0.161877 ) weight=1.318155;
3693                                                                         if(0.161877 <= x < 0.182592 ) weight=1.348693;
3694                                                                         if(0.182592 <= x < 0.205957 ) weight=1.388636;
3695                                                                         if(0.205957 <= x < 0.232313 ) weight=1.439122;
3696                                                                         if(0.232313 <= x < 0.262041 ) weight=1.497452;
3697                                                                         if(0.262041 <= x < 0.295573 ) weight=1.559409;
3698                                                                         if(0.295573 <= x < 0.333397 ) weight=1.615169;
3699                                                                         if(0.333397 <= x < 0.376060 ) weight=1.654954;
3700                                                                         if(0.376060 <= x < 0.424183 ) weight=1.668753;
3701                                                                         if(0.424183 <= x < 0.478465 ) weight=1.652225;
3702                                                                         if(0.478465 <= x < 0.539692 ) weight=1.603119;
3703                                                                         if(0.539692 <= x < 0.608754 ) weight=1.526049;
3704                                                                         if(0.608754 <= x < 0.686654 ) weight=1.426724;
3705                                                                         if(0.686654 <= x < 0.774523 ) weight=1.312684;
3706                                                                         if(0.774523 <= x < 0.873636 ) weight=1.195395;
3707                                                                         if(0.873636 <= x < 0.985432 ) weight=1.086264;
3708                                                                         if(0.985432 <= x < 1.111534 ) weight=0.993666;
3709                                                                         if(1.111534 <= x < 1.253773 ) weight=0.922587;
3710                                                                         if(1.253773 <= x < 1.414214 ) weight=0.875739;
3711                                                                         if(1.414214 <= x < 1.595185 ) weight=0.852181;
3712                                                                         if(1.595185 <= x < 1.799315 ) weight=0.847828;
3713                                                                         if(1.799315 <= x < 2.029567 ) weight=0.863875;
3714                                                                         if(2.029567 <= x < 2.289283 ) weight=0.899112;
3715                                                                         if(2.289283 <= x < 2.582235 ) weight=0.955194;
3716                                                                         if(2.582235 <= x < 2.912674 ) weight=1.033824;
3717                                                                         if(2.912674 <= x < 3.285398 ) weight=1.133714;
3718                                                                         if(3.285398 <= x < 3.705818 ) weight=1.259471;
3719                                                                         if(3.705818 <= x < 4.180038 ) weight=1.406883;
3720                                                                         if(4.180038 <= x < 4.714942 ) weight=1.578923;
3721                                                                         if(4.714942 <= x < 5.318296 ) weight=1.778513;
3722                                                                         if(5.318296 <= x < 5.998859 ) weight=2.001171;
3723                                                                         if(5.998859 <= x < 6.766511 ) weight=2.223161;
3724                                                                         if(6.766511 <= x < 7.632396 ) weight=2.449445;
3725                                                                         if(7.632396 <= x < 8.609086 ) weight=2.661734;
3726                                                                         if(8.609086 <= x < 9.710759 ) weight=2.851935;
3727                                                                         if(9.710759 <= x < 10.953409 ) weight=2.974319;
3728                                                                         if(10.953409 <= x < 12.355077 ) weight=3.106314;
3729                                                                         if(12.355077 <= x < 13.936111 ) weight=3.126815;
3730                                                                         if(13.936111 <= x < 15.719464 ) weight=3.150053;
3731                                                                         if(15.719464 <= x < 17.731026 ) weight=3.218509;
3732                                                                         if(17.731026 <= x < 20.000000 ) weight=3.252141;
3733                                                                         
3734                                                                         
3735                                                                 }
3736                                                         }
3737                                                         //----------------------------------------------------------------------------
3738                                                         
3739                                                         
3740                                                         
3741                                                                 //check this
3742                                                         if(fNonHFE->IsULS()) gmweight1=(fNonHFE->GetNULS())/weight;
3743                                                         if(fNonHFE->IsLS())  gmweight2=(fNonHFE->GetNLS())/weight;
3744                                                         
3745                                                                 //fill histos
3746                                                         if(fNonHFE->IsULS())fPtElec_ULS2_weight->Fill(fPtE, gmweight1);
3747                                                         if(fNonHFE->IsLS())fPtElec_LS2_weight->Fill(fPtE, gmweight2);
3748                                                 }
3749                                                 else{
3750                                                         if(fNonHFE->IsULS()) fPtElec_ULS2_weight->Fill(fPtE,fNonHFE->GetNULS());
3751                                                         if(fNonHFE->IsLS()) fPtElec_LS2_weight->Fill(fPtE,fNonHFE->GetNLS());                           
3752                                                 }
3753                                                 
3754                                                         //ULS with no weight from ULS-LS original
3755                                                         // we have to know if track2 comes from same mother!!!
3756                                                 if(fNonHFE->IsULS()){
3757                                                         
3758                                                         for(Int_t iTracks = 0; iTracks < fVevent->GetNumberOfTracks(); iTracks++) 
3759                                                         {
3760                                                                 
3761                                                                 AliVParticle* Vtrack2 = fVevent->GetTrack(iTracks);
3762                                                                 if (!Vtrack2) 
3763                                                                 {
3764                                                                         printf("ERROR: Could not receive track %d\n", iTracks);
3765                                                                         continue;
3766                                                                 }
3767                                                                 AliVTrack *track2 = dynamic_cast<AliVTrack*>(Vtrack2);
3768                                                                 if(track2->GetLabel()<0) continue;
3769                                                                 fMCparticle2 = (AliAODMCParticle*) fMCarray->At(track2->GetLabel());
3770                                                                 if(fMCparticle2->GetMother()<0) continue;
3771                                                                 
3772                                                                 for(Int_t i = 0; i < fNonHFE->GetNULS(); i++)
3773                                                                 {
3774                                                                         if(fUlsPartner[i]==iTracks){
3775                                                                                         //only fill if it has same mother
3776                                                                                 
3777                                                                                 if(fMCparticle2->GetMother()==fMCparticle->GetMother()) fPtElec_ULS_MC->Fill(fPtE);
3778                                                                                 
3779                                                                                 //-----------------------------------------------------------------------------------------------------------
3780                                                                                 //weight for mother
3781                                                                                 Double_t weight2=1;
3782                                                                                 Double_t mPt=fMCparticleMother->Pt();
3783                                                                                 
3784                                                                                                                                                                 
3785                                                                                 if(TMath::Abs(fMCparticleMother->GetPdgCode())==111){
3786                                                                                         Double_t x=mPt;
3787                                                                                         
3788                                                                                         if(!IsMCefix){
3789                                                                                                 if(0.100000 <= x < 0.112797 ) weight=1.262120;
3790                                                                                                 if(0.112797 <= x < 0.127231 ) weight=1.277765;
3791                                                                                                 if(0.127231 <= x < 0.143512 ) weight=1.295605;
3792                                                                                                 if(0.143512 <= x < 0.161877 ) weight=1.318155;
3793                                                                                                 if(0.161877 <= x < 0.182592 ) weight=1.348693;
3794                                                                                                 if(0.182592 <= x < 0.205957 ) weight=1.388636;
3795                                                                                                 if(0.205957 <= x < 0.232313 ) weight=1.439122;
3796                                                                                                 if(0.232313 <= x < 0.262041 ) weight=1.497452;
3797                                                                                                 if(0.262041 <= x < 0.295573 ) weight=1.559409;
3798                                                                                                 if(0.295573 <= x < 0.333397 ) weight=1.615169;
3799                                                                                                 if(0.333397 <= x < 0.376060 ) weight=1.654954;
3800                                                                                                 if(0.376060 <= x < 0.424183 ) weight=1.668753;
3801                                                                                                 if(0.424183 <= x < 0.478465 ) weight=1.652225;
3802                                                                                                 if(0.478465 <= x < 0.539692 ) weight=1.603119;
3803                                                                                                 if(0.539692 <= x < 0.608754 ) weight=1.526049;
3804                                                                                                 if(0.608754 <= x < 0.686654 ) weight=1.426724;
3805                                                                                                 if(0.686654 <= x < 0.774523 ) weight=1.312684;
3806                                                                                                 if(0.774523 <= x < 0.873636 ) weight=1.195395;
3807                                                                                                 if(0.873636 <= x < 0.985432 ) weight=1.086264;
3808                                                                                                 if(0.985432 <= x < 1.111534 ) weight=0.993666;
3809                                                                                                 if(1.111534 <= x < 1.253773 ) weight=0.922587;
3810                                                                                                 if(1.253773 <= x < 1.414214 ) weight=0.875739;
3811                                                                                                 if(1.414214 <= x < 1.595185 ) weight=0.852181;
3812                                                                                                 if(1.595185 <= x < 1.799315 ) weight=0.847828;
3813                                                                                                 if(1.799315 <= x < 2.029567 ) weight=0.863875;
3814                                                                                                 if(2.029567 <= x < 2.289283 ) weight=0.899112;
3815                                                                                                 if(2.289283 <= x < 2.582235 ) weight=0.955194;
3816                                                                                                 if(2.582235 <= x < 2.912674 ) weight=1.033824;
3817                                                                                                 if(2.912674 <= x < 3.285398 ) weight=1.133714;
3818                                                                                                 if(3.285398 <= x < 3.705818 ) weight=1.259471;
3819                                                                                                 if(3.705818 <= x < 4.180038 ) weight=1.406883;
3820                                                                                                 if(4.180038 <= x < 4.714942 ) weight=1.578923;
3821                                                                                                 if(4.714942 <= x < 5.318296 ) weight=1.778513;
3822                                                                                                 if(5.318296 <= x < 5.998859 ) weight=2.001171;
3823                                                                                                 if(5.998859 <= x < 6.766511 ) weight=2.223161;
3824                                                                                                 if(6.766511 <= x < 7.632396 ) weight=2.449445;
3825                                                                                                 if(7.632396 <= x < 8.609086 ) weight=2.661734;
3826                                                                                                 if(8.609086 <= x < 9.710759 ) weight=2.851935;
3827                                                                                                 if(9.710759 <= x < 10.953409 ) weight=2.974319;
3828                                                                                                 if(10.953409 <= x < 12.355077 ) weight=3.106314;
3829                                                                                                 if(12.355077 <= x < 13.936111 ) weight=3.126815;
3830                                                                                                 if(13.936111 <= x < 15.719464 ) weight=3.150053;
3831                                                                                                 if(15.719464 <= x < 17.731026 ) weight=3.218509;
3832                                                                                                 if(17.731026 <= x < 20.000000 ) weight=3.252141;
3833                                                                                                 
3834                                                                                         }
3835                                                                                         if(IsMCefix){
3836                                                                                                 
3837                                                                                                 if(0.100000 <= x < 0.112797 ) weight2=1.030419;
3838                                                                                                 if(0.112797 <= x < 0.127231 ) weight2=1.044554;
3839                                                                                                 if(0.127231 <= x < 0.143512 ) weight2=1.062733;
3840                                                                                                 if(0.143512 <= x < 0.161877 ) weight2=1.085332;
3841                                                                                                 if(0.161877 <= x < 0.182592 ) weight2=1.115248;
3842                                                                                                 if(0.182592 <= x < 0.205957 ) weight2=1.153990;
3843                                                                                                 if(0.205957 <= x < 0.232313 ) weight2=1.201346;
3844                                                                                                 if(0.232313 <= x < 0.262041 ) weight2=1.257332;
3845                                                                                                 if(0.262041 <= x < 0.295573 ) weight2=1.315488;
3846                                                                                                 if(0.295573 <= x < 0.333397 ) weight2=1.369138;
3847                                                                                                 if(0.333397 <= x < 0.376060 ) weight2=1.407632;
3848                                                                                                 if(0.376060 <= x < 0.424183 ) weight2=1.422232;
3849                                                                                                 if(0.424183 <= x < 0.478465 ) weight2=1.406922;
3850                                                                                                 if(0.478465 <= x < 0.539692 ) weight2=1.360082;
3851                                                                                                 if(0.539692 <= x < 0.608754 ) weight2=1.284405;
3852                                                                                                 if(0.608754 <= x < 0.686654 ) weight2=1.182017;
3853                                                                                                 if(0.686654 <= x < 0.774523 ) weight2=1.062002;
3854                                                                                                 if(0.774523 <= x < 0.873636 ) weight2=0.935533;
3855                                                                                                 if(0.873636 <= x < 0.985432 ) weight2=0.816081;
3856                                                                                                 if(0.985432 <= x < 1.111534 ) weight2=0.717527;
3857                                                                                                 if(1.111534 <= x < 1.253773 ) weight2=0.647465;
3858                                                                                                 if(1.253773 <= x < 1.414214 ) weight2=0.607212;
3859                                                                                                 if(1.414214 <= x < 1.595185 ) weight2=0.589750;
3860                                                                                                 if(1.595185 <= x < 1.799315 ) weight2=0.587406;
3861                                                                                                 if(1.799315 <= x < 2.029567 ) weight2=0.592858;
3862                                                                                                 if(2.029567 <= x < 2.289283 ) weight2=0.601059;
3863                                                                                                 if(2.289283 <= x < 2.582235 ) weight2=0.608003;
3864                                                                                                 if(2.582235 <= x < 2.912674 ) weight2=0.611705;
3865                                                                                                 if(2.912674 <= x < 3.285398 ) weight2=0.610086;
3866                                                                                                 if(3.285398 <= x < 3.705818 ) weight2=0.605015;
3867                                                                                                 if(3.705818 <= x < 4.180038 ) weight2=0.596299;
3868                                                                                                 if(4.180038 <= x < 4.714942 ) weight2=0.590727;
3869                                                                                                 if(4.714942 <= x < 5.318296 ) weight2=0.585358;
3870                                                                                                 if(5.318296 <= x < 5.998859 ) weight2=0.585257;
3871                                                                                                 if(5.998859 <= x < 6.766511 ) weight2=0.580812;
3872                                                                                                 if(6.766511 <= x < 7.632396 ) weight2=0.576207;
3873                                                                                                 if(7.632396 <= x < 8.609086 ) weight2=0.575912;
3874                                                                                                 if(8.609086 <= x < 9.710759 ) weight2=0.558718;
3875                                                                                                 if(9.710759 <= x < 10.953409 ) weight2=0.555625;
3876                                                                                                 if(10.953409 <= x < 12.355077 ) weight2=0.558886;
3877                                                                                                 if(12.355077 <= x < 13.936111 ) weight2=0.545318;
3878                                                                                                 if(13.936111 <= x < 15.719464 ) weight2=0.517607;
3879                                                                                                 if(15.719464 <= x < 17.731026 ) weight2=0.512366;
3880                                                                                                 if(17.731026 <= x < 20.000000 ) weight2=0.497034;
3881                                                                                                 
3882                                                                                                 
3883                                                                                         }
3884                                                                                         
3885                                                                                 }
3886                                                                                         //weight for grandmother
3887                                                                                 Double_t gmPt=fMCparticleGMother->Pt();
3888                                                                                 if(TMath::Abs((fMCparticleMother->GetMother()>0) && ((fMCparticleGMother->GetPdgCode())==111))){
3889                                                                                         Double_t x=gmPt;
3890                                                                                         
3891                                                                                         if(!IsMCefix){
3892                                                                                                 if(0.100000 <= x < 0.112797 ) weight=1.262120;
3893                                                                                                 if(0.112797 <= x < 0.127231 ) weight=1.277765;
3894                                                                                                 if(0.127231 <= x < 0.143512 ) weight=1.295605;
3895                                                                                                 if(0.143512 <= x < 0.161877 ) weight=1.318155;
3896                                                                                                 if(0.161877 <= x < 0.182592 ) weight=1.348693;
3897                                                                                                 if(0.182592 <= x < 0.205957 ) weight=1.388636;
3898                                                                                                 if(0.205957 <= x < 0.232313 ) weight=1.439122;
3899                                                                                                 if(0.232313 <= x < 0.262041 ) weight=1.497452;
3900                                                                                                 if(0.262041 <= x < 0.295573 ) weight=1.559409;
3901                                                                                                 if(0.295573 <= x < 0.333397 ) weight=1.615169;
3902                                                                                                 if(0.333397 <= x < 0.376060 ) weight=1.654954;
3903                                                                                                 if(0.376060 <= x < 0.424183 ) weight=1.668753;
3904                                                                                                 if(0.424183 <= x < 0.478465 ) weight=1.652225;
3905                                                                                                 if(0.478465 <= x < 0.539692 ) weight=1.603119;
3906                                                                                                 if(0.539692 <= x < 0.608754 ) weight=1.526049;
3907                                                                                                 if(0.608754 <= x < 0.686654 ) weight=1.426724;
3908                                                                                                 if(0.686654 <= x < 0.774523 ) weight=1.312684;
3909                                                                                                 if(0.774523 <= x < 0.873636 ) weight=1.195395;
3910                                                                                                 if(0.873636 <= x < 0.985432 ) weight=1.086264;
3911                                                                                                 if(0.985432 <= x < 1.111534 ) weight=0.993666;
3912                                                                                                 if(1.111534 <= x < 1.253773 ) weight=0.922587;
3913                                                                                                 if(1.253773 <= x < 1.414214 ) weight=0.875739;
3914                                                                                                 if(1.414214 <= x < 1.595185 ) weight=0.852181;
3915                                                                                                 if(1.595185 <= x < 1.799315 ) weight=0.847828;
3916                                                                                                 if(1.799315 <= x < 2.029567 ) weight=0.863875;
3917                                                                                                 if(2.029567 <= x < 2.289283 ) weight=0.899112;
3918                                                                                                 if(2.289283 <= x < 2.582235 ) weight=0.955194;
3919                                                                                                 if(2.582235 <= x < 2.912674 ) weight=1.033824;
3920                                                                                                 if(2.912674 <= x < 3.285398 ) weight=1.133714;
3921                                                                                                 if(3.285398 <= x < 3.705818 ) weight=1.259471;
3922                                                                                                 if(3.705818 <= x < 4.180038 ) weight=1.406883;
3923                                                                                                 if(4.180038 <= x < 4.714942 ) weight=1.578923;
3924                                                                                                 if(4.714942 <= x < 5.318296 ) weight=1.778513;
3925                                                                                                 if(5.318296 <= x < 5.998859 ) weight=2.001171;
3926                                                                                                 if(5.998859 <= x < 6.766511 ) weight=2.223161;
3927                                                                                                 if(6.766511 <= x < 7.632396 ) weight=2.449445;
3928                                                                                                 if(7.632396 <= x < 8.609086 ) weight=2.661734;
3929                                                                                                 if(8.609086 <= x < 9.710759 ) weight=2.851935;
3930                                                                                                 if(9.710759 <= x < 10.953409 ) weight=2.974319;
3931                                                                                                 if(10.953409 <= x < 12.355077 ) weight=3.106314;
3932                                                                                                 if(12.355077 <= x < 13.936111 ) weight=3.126815;
3933                                                                                                 if(13.936111 <= x < 15.719464 ) weight=3.150053;
3934                                                                                                 if(15.719464 <= x < 17.731026 ) weight=3.218509;
3935                                                                                                 if(17.731026 <= x < 20.000000 ) weight=3.252141;
3936                                                                                                 
3937                                                                                         }
3938                                                                                         if(IsMCefix){
3939                                                                                                 
3940                                                                                                 if(0.100000 <= x < 0.112797 ) weight2=1.030419;
3941                                                                                                 if(0.112797 <= x < 0.127231 ) weight2=1.044554;
3942                                                                                                 if(0.127231 <= x < 0.143512 ) weight2=1.062733;
3943                                                                                                 if(0.143512 <= x < 0.161877 ) weight2=1.085332;
3944                                                                                                 if(0.161877 <= x < 0.182592 ) weight2=1.115248;
3945                                                                                                 if(0.182592 <= x < 0.205957 ) weight2=1.153990;
3946                                                                                                 if(0.205957 <= x < 0.232313 ) weight2=1.201346;
3947                                                                                                 if(0.232313 <= x < 0.262041 ) weight2=1.257332;
3948                                                                                                 if(0.262041 <= x < 0.295573 ) weight2=1.315488;
3949                                                                                                 if(0.295573 <= x < 0.333397 ) weight2=1.369138;
3950                                                                                                 if(0.333397 <= x < 0.376060 ) weight2=1.407632;
3951                                                                                                 if(0.376060 <= x < 0.424183 ) weight2=1.422232;
3952                                                                                                 if(0.424183 <= x < 0.478465 ) weight2=1.406922;
3953                                                                                                 if(0.478465 <= x < 0.539692 ) weight2=1.360082;
3954                                                                                                 if(0.539692 <= x < 0.608754 ) weight2=1.284405;
3955                                                                                                 if(0.608754 <= x < 0.686654 ) weight2=1.182017;
3956                                                                                                 if(0.686654 <= x < 0.774523 ) weight2=1.062002;
3957                                                                                                 if(0.774523 <= x < 0.873636 ) weight2=0.935533;
3958                                                                                                 if(0.873636 <= x < 0.985432 ) weight2=0.816081;
3959                                                                                                 if(0.985432 <= x < 1.111534 ) weight2=0.717527;
3960                                                                                                 if(1.111534 <= x < 1.253773 ) weight2=0.647465;
3961                                                                                                 if(1.253773 <= x < 1.414214 ) weight2=0.607212;
3962                                                                                                 if(1.414214 <= x < 1.595185 ) weight2=0.589750;
3963                                                                                                 if(1.595185 <= x < 1.799315 ) weight2=0.587406;
3964                                                                                                 if(1.799315 <= x < 2.029567 ) weight2=0.592858;
3965                                                                                                 if(2.029567 <= x < 2.289283 ) weight2=0.601059;
3966                                                                                                 if(2.289283 <= x < 2.582235 ) weight2=0.608003;
3967                                                                                                 if(2.582235 <= x < 2.912674 ) weight2=0.611705;
3968                                                                                                 if(2.912674 <= x < 3.285398 ) weight2=0.610086;
3969                                                                                                 if(3.285398 <= x < 3.705818 ) weight2=0.605015;
3970                                                                                                 if(3.705818 <= x < 4.180038 ) weight2=0.596299;
3971                                                                                                 if(4.180038 <= x < 4.714942 ) weight2=0.590727;
3972                                                                                                 if(4.714942 <= x < 5.318296 ) weight2=0.585358;
3973                                                                                                 if(5.318296 <= x < 5.998859 ) weight2=0.585257;
3974                                                                                                 if(5.998859 <= x < 6.766511 ) weight2=0.580812;
3975                                                                                                 if(6.766511 <= x < 7.632396 ) weight2=0.576207;
3976                                                                                                 if(7.632396 <= x < 8.609086 ) weight2=0.575912;
3977                                                                                                 if(8.609086 <= x < 9.710759 ) weight2=0.558718;
3978                                                                                                 if(9.710759 <= x < 10.953409 ) weight2=0.555625;
3979                                                                                                 if(10.953409 <= x < 12.355077 ) weight2=0.558886;
3980                                                                                                 if(12.355077 <= x < 13.936111 ) weight2=0.545318;
3981                                                                                                 if(13.936111 <= x < 15.719464 ) weight2=0.517607;
3982                                                                                                 if(15.719464 <= x < 17.731026 ) weight2=0.512366;
3983                                                                                                 if(17.731026 <= x < 20.000000 ) weight2=0.497034;
3984                                                                                                 
3985                                                                                         }
3986                                                                                 }
3987                                                                                 
3988                                                                                 if(fMCparticle2->GetMother()==fMCparticle->GetMother()) fPtElec_ULS_MC_weight->Fill(fPtE, 1./weight2);
3989                                                                                 
3990                                                                                         //-----------------------------------------------------------------------------------------------------------
3991                                                                                         //end of weight
3992                                                                                 
3993                                                                         }//partner found same as track
3994                                                                 }//loop in all partner
3995                                                                 
3996                                                         }//track
3997                                                 }//is ULS
3998                                                 
3999                                         }//IsTPConly
4000                                         
4001                                 }//particle kind
4002                                 
4003                                 if(IsTPConly){
4004                                                 //ULS-LS with no pid AOD
4005                                         if(fNonHFE->IsULS()) fPtElec_ULS_NoPid->Fill(fPtE,fNonHFE->GetNULS());
4006                                         if(fNonHFE->IsLS()) fPtElec_LS_NoPid->Fill(fPtE,fNonHFE->GetNLS());
4007                                 }
4008                                 
4009                         }//close IsAOD
4010                          //It is ESD
4011                         else 
4012                         {
4013                                 if(TMath::Abs(fMCtrack->GetPdgCode())==11 && (TMath::Abs(fMCtrackMother->GetPdgCode())==22 || TMath::Abs(fMCtrackMother->GetPdgCode())==111 || TMath::Abs(fMCtrackMother->GetPdgCode())==221))
4014                                 {
4015                                         if(!IsTPConly){
4016                                                 if(fNonHFE->IsULS()) fPtElec_ULS->Fill(fPtE,fNonHFE->GetNULS());
4017                                                 if(fNonHFE->IsLS()) fPtElec_LS->Fill(fPtE,fNonHFE->GetNLS());
4018                                         }
4019                                         
4020                                         if(IsTPConly){
4021                                                 if(fNonHFE->IsULS()) fPtElec_ULS2->Fill(fPtE,fNonHFE->GetNULS());
4022                                                 if(fNonHFE->IsLS()) fPtElec_LS2->Fill(fPtE,fNonHFE->GetNLS());
4023                                         }
4024                                 }
4025                                 
4026                                 
4027                         }
4028                 }//close IsMC
4029                  ///_________________________________________________________________
4030                  //not MC
4031                 else
4032                 {
4033                         if(!IsTPConly){
4034                                 if(fNonHFE->IsULS()) fPtElec_ULS->Fill(fPtE,fNonHFE->GetNULS());
4035                                 if(fNonHFE->IsLS()) fPtElec_LS->Fill(fPtE,fNonHFE->GetNLS());
4036                         }
4037                         
4038                         if(IsTPConly){
4039                                 if(fNonHFE->IsULS()) fPtElec_ULS2->Fill(fPtE,fNonHFE->GetNULS());
4040                                 if(fNonHFE->IsLS()) fPtElec_LS2->Fill(fPtE,fNonHFE->GetNLS());
4041                         }
4042                 }
4043                 
4044                 
4045                 
4046 }//end of Background function
4047
4048         //______________________________________________________________________
4049 void AliAnalysisTaskEMCalHFEpA::ElectronHadronCorrelation(AliVTrack *track, Int_t trackIndex, AliVParticle *vtrack)
4050 {
4051         
4052         ///_________________________________________________________________
4053         ///MC analysis
4054         if(fIsMC)
4055         {
4056                 if(track->GetLabel() < 0)
4057         {
4058                         AliWarning(Form("The track %d does not have a valid MC label",trackIndex));
4059                         return;
4060         }
4061                 
4062                 if(fIsAOD)
4063                 {
4064                         fMCparticle = (AliAODMCParticle*) fMCarray->At(track->GetLabel());
4065                         
4066                         if(fMCparticle->GetMother()<0) return;
4067                 
4068                 fMCparticleMother = (AliAODMCParticle*) fMCarray->At(fMCparticle->GetMother());
4069                 
4070                 if(TMath::Abs(fMCparticle->GetPdgCode())==11 && (TMath::Abs(fMCparticleMother->GetPdgCode())==22 || TMath::Abs(fMCparticleMother->GetPdgCode())==111 || TMath::Abs(fMCparticleMother->GetPdgCode())==221))
4071                 {
4072                                         //Is Background
4073                                 fPtBackgroundBeforeReco->Fill(track->Pt());
4074                         }
4075                 }
4076                 else
4077                 {
4078                 fMCtrack = fMCstack->Particle(track->GetLabel());
4079                 
4080                 if(fMCtrack->GetFirstMother()<0) return;
4081                 
4082                 fMCtrackMother = fMCstack->Particle(fMCtrack->GetFirstMother());
4083                 
4084                 if(TMath::Abs(fMCtrack->GetPdgCode())==11 && (TMath::Abs(fMCtrackMother->GetPdgCode())==22 || TMath::Abs(fMCtrackMother->GetPdgCode())==111 || TMath::Abs(fMCtrackMother->GetPdgCode())==221))
4085                 {
4086                                         //Is Background
4087                                 fPtBackgroundBeforeReco->Fill(track->Pt());
4088                         }
4089                 }
4090         }
4091                 ///_________________________________________________________________
4092         
4093                 //________________________________________________
4094                 //Associated particle cut
4095         fPartnerCuts->SetAcceptKinkDaughters(kFALSE);
4096     fPartnerCuts->SetRequireITSRefit(kTRUE);
4097     fPartnerCuts->SetRequireTPCRefit(kTRUE);
4098     fPartnerCuts->SetEtaRange(-0.9,0.9);
4099     fPartnerCuts->SetMaxChi2PerClusterTPC(4.0);
4100     fPartnerCuts->SetMinNClustersTPC(80);
4101     fPartnerCuts->SetPtRange(0.3,1e10);
4102                 //fPartnerCuts->SetRequireSigmaToVertex(kTRUE);
4103                 //fPartnerCuts->SetMaxDCAToVertexXY(1);
4104                 //fPartnerCuts->SetMaxDCAToVertexZ(3);
4105                 //_________________________________________________
4106         
4107                 ///#################################################################
4108                 //Non-HFE reconstruction
4109         fNonHFE = new AliSelectNonHFE();
4110         fNonHFE->SetAODanalysis(fIsAOD);
4111         if(fMassCutFlag) fNonHFE->SetInvariantMassCut(fMassCut);
4112         if(fAngleCutFlag) fNonHFE->SetOpeningAngleCut(fAngleCut);
4113         if(fChi2CutFlag) fNonHFE->SetChi2OverNDFCut(fChi2Cut);
4114         if(fDCAcutFlag) fNonHFE->SetDCACut(fDCAcut);
4115         fNonHFE->SetAlgorithm("DCA"); //KF
4116         fNonHFE->SetPIDresponse(fPidResponse);
4117         fNonHFE->SetTrackCuts(-3.5,3.5,fPartnerCuts);
4118         fNonHFE->SetAdditionalCuts(fPtMinAsso,fTpcNclsAsso);
4119         
4120         
4121         fNonHFE->SetHistAngleBack(fOpAngleBack);
4122         fNonHFE->SetHistAngle(fOpAngle);
4123         fNonHFE->SetHistDCABack(fDCABack);
4124         fNonHFE->SetHistDCA(fDCA);
4125         fNonHFE->SetHistMassBack(fInvMassBack);
4126         fNonHFE->SetHistMass(fInvMass);
4127         
4128         fNonHFE->FindNonHFE(trackIndex,vtrack,fVevent);
4129         
4130         Int_t *fUlsPartner = fNonHFE->GetPartnersULS();
4131         Int_t *fLsPartner = fNonHFE->GetPartnersLS();
4132         Bool_t fUlsIsPartner = kFALSE;
4133         Bool_t fLsIsPartner = kFALSE;
4134                 ///#################################################################
4135         
4136         
4137                 //Electron Information
4138         Double_t fPhiE = -999;
4139         Double_t fEtaE = -999;
4140         Double_t fPhiH = -999;
4141         Double_t fEtaH = -999;  
4142         Double_t fDphi = -999;
4143         Double_t fDeta = -999;
4144         Double_t fPtE = -999;
4145         Double_t fPtH = -999;
4146         
4147         Double_t pi = TMath::Pi();
4148         
4149         fPhiE = track->Phi();
4150         fEtaE = track->Eta();
4151         fPtE = track->Pt();
4152         
4153         
4154                 ///_________________________________________________________________
4155                 ///MC analysis
4156         if(fIsMC)
4157         {
4158                 if(fIsAOD)
4159                 {
4160                         if(TMath::Abs(fMCparticle->GetPdgCode())==11 && (TMath::Abs(fMCparticleMother->GetPdgCode())==22 || TMath::Abs(fMCparticleMother->GetPdgCode())==111 || TMath::Abs(fMCparticleMother->GetPdgCode())==221))
4161                 {
4162                                 if(fNonHFE->IsULS()) fPtElec_ULS->Fill(fPtE,fNonHFE->GetNULS());
4163                                 if(fNonHFE->IsLS()) fPtElec_LS->Fill(fPtE,fNonHFE->GetNLS());
4164                                 
4165                                 
4166                         }
4167                         
4168                         if(fNonHFE->IsULS()) fPtElec_ULS_NoPid->Fill(fPtE,fNonHFE->GetNULS());
4169                         if(fNonHFE->IsLS()) fPtElec_LS_NoPid->Fill(fPtE,fNonHFE->GetNLS());
4170                 }
4171                 else 
4172                 {
4173                         if(TMath::Abs(fMCtrack->GetPdgCode())==11 && (TMath::Abs(fMCtrackMother->GetPdgCode())==22 || TMath::Abs(fMCtrackMother->GetPdgCode())==111 || TMath::Abs(fMCtrackMother->GetPdgCode())==221))
4174                         {
4175                                 if(fNonHFE->IsULS()) fPtElec_ULS->Fill(fPtE,fNonHFE->GetNULS());
4176                                 if(fNonHFE->IsLS()) fPtElec_LS->Fill(fPtE,fNonHFE->GetNLS());
4177                                 
4178                         }
4179                         
4180                         
4181                 }
4182         }
4183                 ///_________________________________________________________________
4184         else
4185         {
4186                 if(fNonHFE->IsULS()) fPtElec_ULS->Fill(fPtE,fNonHFE->GetNULS());
4187                 if(fNonHFE->IsLS()) fPtElec_LS->Fill(fPtE,fNonHFE->GetNLS());
4188         }
4189         
4190         
4191         
4192         
4193                 //__________________________________________________________________
4194                 //Event Mixing Analysis - Hadron Loop
4195                 //Retrieve
4196         if(fEventMixingFlag)
4197         {
4198                 fPool = fPoolMgr->GetEventPool(fCentrality->GetCentralityPercentile("V0A"), fZvtx); // Get the buffer associated with the current centrality and z-vtx
4199                 
4200                 if(!fPool) AliFatal(Form("No pool found for centrality = %f, zVtx = %f",fCentrality->GetCentralityPercentile("V0A"), fZvtx));
4201                 
4202                 if(fPool->GetCurrentNEvents() >= 5) // start mixing when 5 events are in the buffer
4203                 {
4204                         fPoolNevents->Fill(fPool->GetCurrentNEvents());
4205                         
4206                         for (Int_t jMix = 0; jMix < fPool->GetCurrentNEvents(); jMix++)  // mix with each event in the buffer
4207                         {
4208                                 TObjArray* bgTracks = fPool->GetEvent(jMix);
4209                                 
4210                                 for (Int_t kMix = 0; kMix < bgTracks->GetEntriesFast(); kMix++)  // mix with each track in the event
4211                                 {
4212                                         const AliEHCParticle* MixedTrack(dynamic_cast<AliEHCParticle*>(bgTracks->At(kMix)));
4213                                         if (NULL == MixedTrack) continue;
4214                                         
4215                                         fPhiH = MixedTrack->Phi();
4216                                         fEtaH = MixedTrack->Eta();
4217                                         fPtH = MixedTrack->Pt();
4218                                         
4219                                         if(fPtH<fAssHadronPtMin || fPtH>fAssHadronPtMax) continue;
4220                                         
4221                                         fDphi = fPhiE - fPhiH;
4222                                         
4223                                         if (fDphi > 3*pi/2) fDphi = fDphi - 2*pi;
4224                                         if (fDphi < -pi/2)  fDphi = fDphi + 2*pi;
4225                                         
4226                                         fDeta = fEtaE - fEtaH;
4227                                         
4228                                         Double_t fPtBin[7] = {1,2,4,6,8,10,15};
4229                                         
4230                                         for(Int_t i = 0; i < 6; i++)
4231                                         {
4232                                             if(fPtE>=fPtBin[i] && fPtE<fPtBin[i+1])
4233                                             {
4234                                                         fCEtaPhi_Inc_EM[i]->Fill(fDphi,fDeta);
4235                                                         
4236                                                         if(fNonHFE->IsULS()) fCEtaPhi_ULS_EM[i]->Fill(fDphi,fDeta);
4237                                                         if(fNonHFE->IsLS()) fCEtaPhi_LS_EM[i]->Fill(fDphi,fDeta);
4238                                                         
4239                                                         if(fNonHFE->IsULS()) fCEtaPhi_ULS_Weight_EM[i]->Fill(fDphi,fDeta,fNonHFE->GetNULS());
4240                                                         if(fNonHFE->IsLS()) fCEtaPhi_LS_Weight_EM[i]->Fill(fDphi,fDeta,fNonHFE->GetNLS());
4241                                             }
4242                                         }
4243                                         
4244                                                 // TODO your code: do event mixing with current event and bgTracks
4245                                                 // note that usually the content filled now is weighted by 1 / pool->GetCurrentNEvents()
4246                                 }
4247                         }
4248                 }
4249         }
4250                 //__________________________________________________________________
4251         
4252                 //__________________________________________________________________
4253                 //Same Event Analysis - Hadron Loop
4254         for(Int_t iTracks = 0; iTracks < fVevent->GetNumberOfTracks(); iTracks++) 
4255         {
4256                 if(trackIndex==iTracks) continue;
4257                 
4258                 AliVParticle* Vtrack2 = fVevent->GetTrack(iTracks);
4259                 if (!Vtrack2) 
4260                 {
4261                         printf("ERROR: Could not receive track %d\n", iTracks);
4262                         continue;
4263                 }
4264                 
4265                 AliVTrack *track2 = dynamic_cast<AliVTrack*>(Vtrack2);
4266                 
4267                 if(track2->Eta()<fEtaCutMin || track2->Eta()>fEtaCutMax ) continue;
4268                 
4269                 if(fIsAOD) 
4270                 {
4271                         AliAODTrack *atrack2 = dynamic_cast<AliAODTrack*>(Vtrack2);
4272                         if(!atrack2->TestFilterMask(AliAODTrack::kTrkTPCOnly)) continue;
4273                         if((!(atrack2->GetStatus()&AliESDtrack::kITSrefit)|| (!(atrack2->GetStatus()&AliESDtrack::kTPCrefit)))) continue;
4274                         if(atrack2->GetTPCNcls() < 80) continue; 
4275                         if(fAssocWithSPD && ((!(atrack2->HasPointOnITSLayer(0))) && (!(atrack2->HasPointOnITSLayer(1))))) continue;
4276                 }
4277                 else
4278                 {   
4279                         AliESDtrack *etrack2 = dynamic_cast<AliESDtrack*>(Vtrack2); 
4280                         if(!fPartnerCuts->AcceptTrack(etrack2)) continue; 
4281                 }
4282                 
4283                 fPhiH = track2->Phi();
4284                 fEtaH = track2->Eta();
4285                 fPtH = track2->Pt();
4286                 
4287                 if(fPtH<fAssHadronPtMin || fPtH>fAssHadronPtMax) continue;
4288                 
4289                 fDphi = fPhiE - fPhiH;
4290                 
4291                 if (fDphi > 3*pi/2) fDphi = fDphi - 2*pi;
4292                 if (fDphi < -pi/2)  fDphi = fDphi + 2*pi;
4293                 
4294                 fDeta = fEtaE - fEtaH;
4295                 
4296                 Double_t fPtBin[7] = {1,2,4,6,8,10,15};
4297                 
4298                 //______________________________________________________________
4299                 //Check if this track is a Non-HFE partner
4300                 for(Int_t i = 0; i < fNonHFE->GetNULS(); i++)
4301                 {
4302                         if(fUlsPartner[i]==iTracks) fUlsIsPartner=kTRUE;
4303                 }
4304                 for(Int_t i = 0; i < fNonHFE->GetNLS(); i++)
4305                 {
4306                         if(fLsPartner[i]==iTracks) fLsIsPartner=kTRUE;
4307                 }
4308                 //______________________________________________________________
4309                 
4310                 for(Int_t i = 0; i < 6; i++)
4311                 {
4312                     if(fPtE>=fPtBin[i] && fPtE<fPtBin[i+1])
4313                     {
4314                                 fCEtaPhi_Inc[i]->Fill(fDphi,fDeta);
4315                                 
4316                                 if(fNonHFE->IsULS()) fCEtaPhi_ULS[i]->Fill(fDphi,fDeta);
4317                                 if(fNonHFE->IsLS()) fCEtaPhi_LS[i]->Fill(fDphi,fDeta);
4318                                 if(fNonHFE->IsULS() && !fUlsIsPartner) fCEtaPhi_ULS_NoP[i]->Fill(fDphi,fDeta);
4319                                 if(fNonHFE->IsLS() && !fLsIsPartner) fCEtaPhi_LS_NoP[i]->Fill(fDphi,fDeta);
4320                                 
4321                                 if(fNonHFE->IsULS()) fCEtaPhi_ULS_Weight[i]->Fill(fDphi,fDeta,fNonHFE->GetNULS());
4322                                 if(fNonHFE->IsLS()) fCEtaPhi_LS_Weight[i]->Fill(fDphi,fDeta,fNonHFE->GetNLS());
4323                                 if(fNonHFE->IsULS() && !fUlsIsPartner) fCEtaPhi_ULS_NoP_Weight[i]->Fill(fDphi,fDeta,fNonHFE->GetNULS());
4324                                 if(fNonHFE->IsLS() && !fLsIsPartner) fCEtaPhi_LS_NoP_Weight[i]->Fill(fDphi,fDeta,fNonHFE->GetNLS());
4325                     }
4326                 }
4327         }
4328 }
4329
4330         //____________________________________________________________________________________________________________
4331         //Create a TObjArray with selected hadrons, for the mixed event analysis
4332 TObjArray* AliAnalysisTaskEMCalHFEpA::SelectedHadrons()
4333 {
4334         fTracksClone = new TObjArray;
4335         fTracksClone->SetOwner(kTRUE);
4336         
4337         for(Int_t iTracks = 0; iTracks < fVevent->GetNumberOfTracks(); iTracks++) 
4338         {       
4339                 AliVParticle* Vtrack2 = fVevent->GetTrack(iTracks);
4340                 if (!Vtrack2) 
4341                 {
4342                         printf("ERROR: Could not receive track %d\n", iTracks);
4343                         continue;
4344                 }
4345                 
4346                 AliVTrack *track2 = dynamic_cast<AliVTrack*>(Vtrack2);
4347                 
4348                 if(track2->Eta()<fEtaCutMin || track2->Eta()>fEtaCutMax ) continue;
4349                 
4350                 if(fIsAOD) 
4351                 {
4352                         AliAODTrack *atrack2 = dynamic_cast<AliAODTrack*>(Vtrack2);
4353                         if(!atrack2->TestFilterMask(AliAODTrack::kTrkTPCOnly)) continue;
4354                         if((!(atrack2->GetStatus()&AliESDtrack::kITSrefit)|| (!(atrack2->GetStatus()&AliESDtrack::kTPCrefit)))) continue;
4355                         if(atrack2->GetTPCNcls() < 80) continue; 
4356                         if(fAssocWithSPD && ((!(atrack2->HasPointOnITSLayer(0))) && (!(atrack2->HasPointOnITSLayer(1))))) continue;
4357                 }
4358                 else
4359                 {   
4360                         AliESDtrack *etrack2 = dynamic_cast<AliESDtrack*>(Vtrack2); 
4361                         if(!fPartnerCuts->AcceptTrack(etrack2)) continue; 
4362                 }
4363                 
4364                 fTracksClone->Add(new AliEHCParticle(track2->Eta(), track2->Phi(), track2->Pt()));
4365         }
4366         return fTracksClone;
4367 }
4368         //____________________________________________________________________________________________________________
4369
4370         //______________________________________________________________________
4371 void AliAnalysisTaskEMCalHFEpA::DiHadronCorrelation(AliVTrack *track, Int_t trackIndex)
4372 {       
4373                 //________________________________________________
4374                 //Associated particle cut
4375         fPartnerCuts->SetAcceptKinkDaughters(kFALSE);
4376     fPartnerCuts->SetRequireITSRefit(kTRUE);
4377     fPartnerCuts->SetRequireTPCRefit(kTRUE);
4378     fPartnerCuts->SetEtaRange(-0.9,0.9);
4379     fPartnerCuts->SetMaxChi2PerClusterTPC(4.0);
4380     fPartnerCuts->SetMinNClustersTPC(80);
4381     fPartnerCuts->SetPtRange(0.3,1e10);
4382                 //fPartnerCuts->SetRequireSigmaToVertex(kTRUE);
4383                 //fPartnerCuts->SetMaxDCAToVertexXY(1);
4384                 //fPartnerCuts->SetMaxDCAToVertexZ(3);
4385                 //_________________________________________________
4386         
4387                 //Electron Information
4388         Double_t fPhiE = -999;
4389         Double_t fEtaE = -999;
4390         Double_t fPhiH = -999;
4391         Double_t fEtaH = -999;  
4392         Double_t fDphi = -999;
4393         Double_t fDeta = -999;
4394         Double_t fPtE = -999;
4395         Double_t fPtH = -999;
4396         
4397         Double_t pi = TMath::Pi();
4398         
4399         fPhiE = track->Phi();
4400         fEtaE = track->Eta();
4401         fPtE = track->Pt();
4402         
4403                 //__________________________________________________________________
4404                 //Same Event Analysis - Hadron Loop
4405         for(Int_t iTracks = 0; iTracks < fVevent->GetNumberOfTracks(); iTracks++) 
4406         {
4407                 if(trackIndex==iTracks) continue;
4408                 
4409                 AliVParticle* Vtrack2 = fVevent->GetTrack(iTracks);
4410                 if (!Vtrack2) 
4411                 {
4412                         printf("ERROR: Could not receive track %d\n", iTracks);
4413                         continue;
4414                 }
4415                 
4416                 AliVTrack *track2 = dynamic_cast<AliVTrack*>(Vtrack2);
4417                 if(track2->Eta()<fEtaCutMin || track2->Eta()>fEtaCutMax ) continue;
4418                 
4419                 if(fIsAOD) 
4420                 {
4421                         AliAODTrack *atrack2 = dynamic_cast<AliAODTrack*>(Vtrack2);
4422                         if(!atrack2->TestFilterMask(AliAODTrack::kTrkTPCOnly)) continue;
4423                         if((!(atrack2->GetStatus()&AliESDtrack::kITSrefit)|| (!(atrack2->GetStatus()&AliESDtrack::kTPCrefit)))) continue;
4424                         if(atrack2->GetTPCNcls() < 80) continue; 
4425                         if(fAssocWithSPD && ((!(atrack2->HasPointOnITSLayer(0))) && (!(atrack2->HasPointOnITSLayer(1))))) continue;
4426                 }
4427                 else
4428                 {   
4429                         AliESDtrack *etrack2 = dynamic_cast<AliESDtrack*>(Vtrack2); 
4430                         if(!fPartnerCuts->AcceptTrack(etrack2)) continue; 
4431                 }
4432                 
4433                 fPhiH = track2->Phi();
4434                 fEtaH = track2->Eta();
4435                 fPtH = track2->Pt();
4436                 
4437                 if(fPtH<fAssHadronPtMin || fPtH>fAssHadronPtMax) continue;
4438                 
4439                 fDphi = fPhiE - fPhiH;
4440                 
4441                 if (fDphi > 3*pi/2) fDphi = fDphi - 2*pi;
4442                 if (fDphi < -pi/2)  fDphi = fDphi + 2*pi;
4443                 
4444                 fDeta = fEtaE - fEtaH;
4445                 
4446                 Double_t fPtBin[7] = {1,2,4,6,8,10,15};
4447                 
4448                 for(Int_t i = 0; i < 6; i++)
4449                 {
4450                     if(fPtE>=fPtBin[i] && fPtE<fPtBin[i+1])
4451                     {
4452                                 fCEtaPhi_Inc_DiHadron[i]->Fill(fDphi,fDeta);
4453                     }
4454                 }
4455         }
4456 }
4457         //____________________________________________________________________________________________________________
4458
4459         //______________________________________________________________________
4460 Bool_t AliAnalysisTaskEMCalHFEpA::FindMother(Int_t mcIndex)
4461 {
4462         fIsHFE1 = kFALSE;
4463         fIsHFE2 = kFALSE;
4464         fIsNonHFE = kFALSE;
4465         fIsFromD = kFALSE;
4466         fIsFromB = kFALSE;
4467         fIsFromPi0 = kFALSE;
4468         fIsFromEta = kFALSE;
4469         fIsFromGamma = kFALSE;
4470         
4471         if(mcIndex < 0 || !fIsMC)
4472         {
4473                 return kFALSE;
4474         }
4475         
4476         Int_t pdg = -99999;
4477         Int_t mpdg = -99999;
4478         Int_t gmpdg = -99999;
4479         Int_t ggmpdg = -99999;
4480         Int_t gggmpdg = -99999;
4481         
4482         if(fIsAOD)
4483         {       
4484                 fMCparticle = (AliAODMCParticle*) fMCarray->At(mcIndex);
4485                 
4486                 pdg = TMath::Abs(fMCparticle->GetPdgCode());
4487                 
4488                 
4489                 if(pdg!=11)
4490                 {
4491                         fIsHFE1 = kFALSE;
4492                         fIsHFE2 = kFALSE;
4493                         fIsNonHFE = kFALSE;
4494                         fIsFromD = kFALSE;
4495                         fIsFromB = kFALSE;
4496                         fIsFromPi0 = kFALSE;
4497                         fIsFromEta = kFALSE;
4498                         fIsFromGamma = kFALSE;
4499                         return kFALSE;
4500                 }
4501                 
4502                 if(fMCparticle->GetMother()<0)
4503                 {
4504                         fIsHFE1 = kFALSE;
4505                         fIsHFE2 = kFALSE;
4506                         fIsNonHFE = kFALSE;
4507                         fIsFromD = kFALSE;
4508                         fIsFromB = kFALSE;
4509                         fIsFromPi0 = kFALSE;
4510                         fIsFromEta = kFALSE;
4511                         fIsFromGamma = kFALSE;
4512                         return kFALSE;
4513                 }
4514                 
4515                 fMCparticleMother = (AliAODMCParticle*) fMCarray->At(fMCparticle->GetMother());
4516                 mpdg = TMath::Abs(fMCparticleMother->GetPdgCode());
4517                 
4518                 if(fMCparticleMother->GetMother()<0)
4519                 {
4520                         gmpdg = 0;
4521                         ggmpdg = 0;
4522                         gggmpdg = 0;
4523                 }
4524                 else
4525                 {
4526                         fMCparticleGMother = (AliAODMCParticle*) fMCarray->At(fMCparticleMother->GetMother());
4527                         gmpdg = TMath::Abs(fMCparticleGMother->GetPdgCode());
4528                         if(fMCparticleGMother->GetMother()<0)
4529                         {
4530                                 ggmpdg = 0;
4531                                 gggmpdg = 0;
4532                         }
4533                         else
4534                         {
4535                                 fMCparticleGGMother = (AliAODMCParticle*) fMCarray->At(fMCparticleGMother->GetMother());
4536                                 ggmpdg = TMath::Abs(fMCparticleGGMother->GetPdgCode());
4537                                 if(fMCparticleGGMother->GetMother()<0)
4538                                 {
4539                                         gggmpdg = 0;
4540                                 }
4541                                 else
4542                                 {
4543                                         fMCparticleGGGMother = (AliAODMCParticle*) fMCarray->At(fMCparticleGGMother->GetMother());
4544                                         gggmpdg = TMath::Abs(fMCparticleGGGMother->GetPdgCode());
4545                                 }
4546                         }
4547                 }
4548         }
4549         else
4550         {
4551                 fMCtrack = fMCstack->Particle(mcIndex);
4552                 
4553                 pdg = TMath::Abs(fMCtrack->GetPdgCode());
4554                 
4555                 if(pdg!=11)
4556                 {
4557                         fIsHFE1 = kFALSE;
4558                         fIsHFE2 = kFALSE;
4559                         fIsNonHFE = kFALSE;
4560                         fIsFromD = kFALSE;
4561                         fIsFromB = kFALSE;
4562                         fIsFromPi0 = kFALSE;
4563                         fIsFromEta = kFALSE;
4564                         fIsFromGamma = kFALSE;
4565                         return kFALSE;
4566                 }
4567                 
4568                 if(fMCtrack->GetFirstMother()<0)
4569                 {
4570                         fIsHFE1 = kFALSE;
4571                         fIsHFE2 = kFALSE;
4572                         fIsNonHFE = kFALSE;
4573                         fIsFromD = kFALSE;
4574                         fIsFromB = kFALSE;
4575                         fIsFromPi0 = kFALSE;
4576                         fIsFromEta = kFALSE;
4577                         fIsFromGamma = kFALSE;
4578                         return kFALSE;
4579                 }
4580                 
4581                 fMCtrackMother = fMCstack->Particle(fMCtrack->GetFirstMother());
4582                 mpdg = TMath::Abs(fMCtrackMother->GetPdgCode());
4583                 
4584                 if(fMCtrackMother->GetFirstMother()<0)
4585                 {
4586                         gmpdg = 0;
4587                         ggmpdg = 0;
4588                         gggmpdg = 0;
4589                 }
4590                 else
4591                 {
4592                         fMCtrackGMother = fMCstack->Particle(fMCtrackMother->GetFirstMother());
4593                         gmpdg = TMath::Abs(fMCtrackGMother->GetPdgCode());
4594                         
4595                         if(fMCtrackGMother->GetFirstMother()<0)
4596                         {
4597                                 ggmpdg = 0;
4598                                 gggmpdg = 0;
4599                         }
4600                         else
4601                         {
4602                                 fMCtrackGGMother = fMCstack->Particle(fMCtrackGMother->GetFirstMother());
4603                                 ggmpdg = TMath::Abs(fMCtrackGGMother->GetPdgCode());
4604                                 
4605                                 if(fMCtrackGGMother->GetFirstMother()<0)
4606                                 {
4607                                         gggmpdg = 0;
4608                                 }
4609                                 else
4610                                 {
4611                                         fMCtrackGGGMother = fMCstack->Particle(fMCtrackGGMother->GetFirstMother());
4612                                         gggmpdg = TMath::Abs(fMCtrackGGGMother->GetPdgCode());
4613                                 }
4614                         }
4615                 }
4616         }
4617         
4618         //Tag Electron Source
4619         if(mpdg==111 || mpdg==221 || mpdg==22)
4620         {
4621                 fIsHFE1 = kFALSE;
4622                 fIsHFE2 = kFALSE;
4623                 fIsNonHFE = kTRUE;
4624                 fIsFromD = kFALSE;
4625                 fIsFromB = kFALSE;
4626                 
4627                 fIsFromPi0 = kFALSE;
4628                 fIsFromEta = kFALSE;
4629                 fIsFromGamma = kFALSE;
4630                 
4631                 if(mpdg==111) fIsFromPi0 = kFALSE;
4632                 if(mpdg==221)fIsFromEta = kFALSE;
4633                 if(mpdg==22) fIsFromGamma = kFALSE;
4634                 
4635                 return kTRUE;
4636         }
4637         else
4638         {
4639                 fIsHFE1 = kFALSE;
4640                 fIsHFE2 = kTRUE;
4641                 
4642                 fIsFromPi0 = kFALSE;
4643                 fIsFromEta = kFALSE;
4644                 fIsFromGamma = kFALSE;
4645                 
4646                 fIsNonHFE = kFALSE;
4647                 
4648                 fIsFromD = kFALSE;
4649                 fIsFromB = kFALSE;
4650                 
4651                 if(mpdg>400 && mpdg<500)
4652                 {
4653                         if((gmpdg>500 && gmpdg<600) || (ggmpdg>500 && ggmpdg<600) || (gggmpdg>500 && gggmpdg<600))
4654                         {
4655                                 fIsHFE1 = kTRUE;
4656                                 fIsFromD = kFALSE;
4657                                 fIsFromB = kTRUE;
4658                                 return kTRUE;
4659                         }
4660                         else
4661                         {
4662                                 fIsHFE1 = kTRUE;
4663                                 fIsFromD = kTRUE;
4664                                 fIsFromB = kFALSE;
4665                                 return kTRUE;
4666                         }
4667                 }
4668                 else if(mpdg>500 && mpdg<600)
4669                 {
4670                         fIsHFE1 = kTRUE;
4671                         fIsFromD = kFALSE;
4672                         fIsFromB = kTRUE;
4673                         return kTRUE;
4674                 }
4675                 else
4676                 {
4677                         fIsHFE1 = kFALSE;
4678                         fIsFromD = kFALSE;
4679                         fIsFromB = kFALSE;
4680                         return kFALSE;
4681                 }
4682         }
4683 }