AliPhysics  608b256 (608b256)
AliAnalysisTaskHeavyNeutralMesonToGG.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-2020, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: Friederike Bock, Sandro Wenzel *
5  * Version 1.0 *
6  * *
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 
18 //----------------------------------------------------------------
19 // Class used to do analysis on conversion photons + calo photons
20 //----------------------------------------------------------------
22 #include "TChain.h"
23 #include "TTree.h"
24 #include "TBranch.h"
25 #include "TFile.h"
26 #include "TH1F.h"
27 #include "TH2F.h"
28 #include "TH3F.h"
29 #include "THnSparse.h"
30 #include "TCanvas.h"
31 #include "TNtuple.h"
32 #include "AliAnalysisTask.h"
33 #include "AliAnalysisManager.h"
34 #include "AliESDEvent.h"
35 #include "AliESDInputHandler.h"
36 #include "AliMCEventHandler.h"
37 #include "AliMCEvent.h"
38 #include "AliMCParticle.h"
39 #include "AliCentrality.h"
40 #include "AliESDVZERO.h"
41 #include "AliESDpid.h"
43 #include "AliVParticle.h"
44 #include "AliESDtrack.h"
45 #include "AliESDtrackCuts.h"
46 #include "AliKFVertex.h"
47 #include "AliGenCocktailEventHeader.h"
49 #include "AliAODMCParticle.h"
50 #include "AliAODMCHeader.h"
51 #include "AliEventplane.h"
53 #include "AliAODEvent.h"
54 #include "AliAODInputHandler.h"
55 #include "AliESDEvent.h"
56 #include "AliESDInputHandler.h"
57 #include "AliInputEventHandler.h"
58 #include "AliCaloTrackMatcher.h"
59 #include <vector>
60 #include <map>
61 
63 
64 //________________________________________________________________________
66  fRandom(0),
67  fV0Reader(NULL),
68  fBGHandler(NULL),
69  fBGHandlerRP(NULL),
70  fBGClusHandler(NULL),
71  fBGClusHandlerRP(NULL),
72  fInputEvent(NULL),
73  fMCEvent(NULL),
74  fEventCuts(NULL),
75  fConversionCuts(NULL),
76  fCaloPhotonCuts(NULL),
77  fMesonCuts(NULL),
78  fCutFolder(NULL),
79  fESDList(NULL),
80  fBackList(NULL),
81  fMotherList(NULL),
82  fTrueList(NULL),
83  fMCList(NULL),
84  fOutputContainer(NULL),
85  fGammaCandidates(NULL),
86  fClusterCandidates(NULL),
87  fEventCutArray(NULL),
88  fCutArray(NULL),
89  fClusterCutArray(NULL),
90  fMesonCutArray(NULL),
91  fReaderGammas(NULL),
92  fV0ReaderName("V0ReaderV1"),
93  fCorrTaskSetting(""),
94  fFileNameBroken(NULL),
95  fSparseMotherInvMassPtZM(NULL),
96  fSparseMotherBackInvMassPtZM(NULL),
97  fTreeBrokenFiles(NULL),
98  fProfileTruePrimaryMesonWeightsInvMassPt(NULL),
99  fHistoMotherInvMassPt(NULL),
100  fHistoMotherMatchedInvMassPt(NULL),
101  fHistoMotherBackInvMassPt(NULL),
102  fHistoMotherMesonPtY(NULL),
103  fHistoMotherMesonPtAlpha(NULL),
104  fHistoMotherMesonPtOpenAngle(NULL),
105  fHistoMotherMesonConvPhotonEtaPhi(NULL),
106  fHistoTrueMesonInvMassPt(NULL),
107  fHistoTrueMesonMatchedInvMassPt(NULL),
108  fHistoTrueMesonCaloPhotonInvMassPt(NULL),
109  fHistoTrueMesonCaloConvertedPhotonInvMassPt(NULL),
110  fHistoTrueMesonCaloMixedPhotonConvPhotonInvMassPt(NULL),
111  fHistoTrueMesonCaloConvertedPhotonMatchedInvMassPt(NULL),
112  fHistoTrueMesonCaloElectronInvMassPt(NULL),
113  fHistoTrueMesonCaloMergedClusterInvMassPt(NULL),
114  fHistoTrueMesonCaloMergedClusterPartConvInvMassPt(NULL),
115  fHistoTruePrimaryMesonInvMassPt(NULL),
116  fHistoTruePrimaryMesonW0WeightingInvMassPt(NULL),
117  fHistoTruePrimaryMesonMCPtResolPt(NULL),
118  fHistoTrueMotherMesonConvPhotonEtaPhi(NULL),
119  fHistoTrueBckGGInvMassPt(NULL),
120  fHistoTrueBckFullMesonContainedInOneClusterInvMassPt(NULL),
121  fHistoTrueBckAsymEClustersInvMassPt(NULL),
122  fHistoTrueBckContInvMassPt(NULL),
123  fHistoTrueMesonPtY(NULL),
124  fHistoTrueMesonPtAlpha(NULL),
125  fHistoTrueMesonPtOpenAngle(NULL),
126  fHistoMCMesonPtY(NULL),
127  fHistoMCMesonPtAlpha(NULL),
128  fHistoMCMesonPtJetPt(NULL),
129  fHistoTrueNLabelsInClusPt(NULL),
130  fHistoDoubleCountTrueMesonInvMassPt(NULL),
131  fHistoDoubleCountTrueConvGammaRPt(NULL),
132  fHistoDoubleCountTrueClusterGammaPt(NULL),
133  fHistoSPDClusterTrackletBackground(NULL),
134  fProfileEtaShift(NULL),
135  fProfileJetJetXSection(NULL),
136  fHistoMCHeaders(NULL),
137  fHistoConvGammaPt(NULL),
138  fHistoClusGammaPt(NULL),
139  fHistoClusGammaE(NULL),
140  fHistoClusOverlapHeadersGammaPt(NULL),
141  fHistoClusAllHeadersGammaPt(NULL),
142  fHistoClusRejectedHeadersGammaPt(NULL),
143  fHistoMotherInvMassRejected(NULL),
144  fHistoMCMesonPt(NULL),
145  fHistoMCMesonWOWeightPt(NULL),
146  fHistoMCMesonWOEvtWeightPt(NULL),
147  fHistoMCMesonInAccPt(NULL),
148  fHistoMCMesonWOWeightInAccPt(NULL),
149  fHistoMCMesonWOEvtWeightInAccPt(NULL),
150  fHistoTrueConvGammaPt(NULL),
151  fHistoTruePrimaryConvGammaPt(NULL),
152  fHistoTrueClusGammaPt(NULL),
153  fHistoTrueClusConvGammaPt(NULL),
154  fHistoTrueClusConvGammaFullyPt(NULL),
155  fHistoTruePrimaryClusGammaPt(NULL),
156  fHistoTruePrimaryClusConvGammaPt(NULL),
157  fHistoMultipleCountTrueMeson(NULL),
158  fHistoMultipleCountTrueConvGamma(NULL),
159  fHistoMultipleCountTrueClusterGamma(NULL),
160  fHistoNEvents(NULL),
161  fHistoNEventsWOWeight(NULL),
162  fHistoNGoodESDTracks(NULL),
163  fHistoVertexZ(NULL),
164  fHistoVertexX(NULL),
165  fHistoVertexY(NULL),
166  fHistoNGammaConvCandidates(NULL),
167  fHistoNGammaCaloCandidates(NULL),
168  fHistoNV0Tracks(NULL),
169  fHistoJetJetNTrials(NULL),
170  fMapMultipleCountTrueMesons(),
171  fMapMultipleCountTrueConvGammas(),
172  fMapMultipleCountTrueClusterGammas(),
173  fVectorRecTrueMesons(0),
174  fVectorDoubleCountTrueMesons(0),
175  fVectorDoubleCountTrueConvGammas(0),
176  fVectorDoubleCountTrueClusterGammas(0),
177  fUnsmearedPx(NULL),
178  fUnsmearedPy(NULL),
179  fUnsmearedPz(NULL),
180  fUnsmearedE(NULL),
181  fMesonInvMassWindow(NULL),
182  fMCEventPos(NULL),
183  fMCEventNeg(NULL),
184  fESDArrayPos(NULL),
185  fESDArrayNeg(NULL),
186  fEventPlaneAngle(-100),
187  fMesonInvMassMin(0),
188  fMesonInvMassMax(0),
189  fMesonInvMassNBins(0),
190  fWeightJetJetMC(1),
191  fNGammaCandidates(0),
192  fnCuts(0),
193  fiCut(0),
194  fIsHeavyIon(0),
195  fMesonRecoMode(-1),
196  fMesonType(-1),
197  fMesonPDG(0),
198  fDoMesonQA(0),
199  fDoPhotonQA(0),
200  fDoClusterQA(0),
201  fIsMC(0),
202  fMoveParticleAccordingToVertex(kTRUE),
203  fDoLightOutput(kFALSE),
204  fIsFromDesiredHeader(kTRUE),
205  fIsOverlappingWithOtherHeader(kFALSE),
206  fDoTHnSparse(kTRUE),
207  fSetPlotHistsExtQA(kFALSE),
208  fDoConvGammaShowerShapeTree(kFALSE),
209  fEnableSortForClusMC(kFALSE),
210  fDoPrimaryTrackMatching(kFALSE),
211  fDoInvMassShowerShapeTree(kFALSE),
212  fAllowOverlapHeaders(kTRUE),
213  fEnableClusterCutsForTrigger(kFALSE)
214 {
215 
216 }
217 
218 //________________________________________________________________________
220  AliAnalysisTaskSE(name),
221  fRandom(0),
222  fV0Reader(NULL),
223  fBGHandler(NULL),
224  fBGHandlerRP(NULL),
225  fBGClusHandler(NULL),
226  fBGClusHandlerRP(NULL),
227  fInputEvent(NULL),
228  fMCEvent(NULL),
229  fEventCuts(NULL),
230  fConversionCuts(NULL),
231  fCaloPhotonCuts(NULL),
232  fMesonCuts(NULL),
233  fCutFolder(NULL),
234  fESDList(NULL),
235  fBackList(NULL),
236  fMotherList(NULL),
237  fTrueList(NULL),
238  fMCList(NULL),
239  fOutputContainer(NULL),
240  fGammaCandidates(NULL),
241  fClusterCandidates(NULL),
242  fEventCutArray(NULL),
243  fCutArray(NULL),
244  fClusterCutArray(NULL),
245  fMesonCutArray(NULL),
246  fReaderGammas(NULL),
247  fV0ReaderName("V0ReaderV1"),
248  fCorrTaskSetting(""),
249  fFileNameBroken(NULL),
250  fSparseMotherInvMassPtZM(NULL),
251  fSparseMotherBackInvMassPtZM(NULL),
252  fTreeBrokenFiles(NULL),
253  fProfileTruePrimaryMesonWeightsInvMassPt(NULL),
254  fHistoMotherInvMassPt(NULL),
255  fHistoMotherMatchedInvMassPt(NULL),
256  fHistoMotherBackInvMassPt(NULL),
257  fHistoMotherMesonPtY(NULL),
258  fHistoMotherMesonPtAlpha(NULL),
259  fHistoMotherMesonPtOpenAngle(NULL),
260  fHistoMotherMesonConvPhotonEtaPhi(NULL),
261  fHistoTrueMesonInvMassPt(NULL),
262  fHistoTrueMesonMatchedInvMassPt(NULL),
263  fHistoTrueMesonCaloPhotonInvMassPt(NULL),
264  fHistoTrueMesonCaloConvertedPhotonInvMassPt(NULL),
265  fHistoTrueMesonCaloMixedPhotonConvPhotonInvMassPt(NULL),
266  fHistoTrueMesonCaloConvertedPhotonMatchedInvMassPt(NULL),
267  fHistoTrueMesonCaloElectronInvMassPt(NULL),
268  fHistoTrueMesonCaloMergedClusterInvMassPt(NULL),
269  fHistoTrueMesonCaloMergedClusterPartConvInvMassPt(NULL),
270  fHistoTruePrimaryMesonInvMassPt(NULL),
271  fHistoTruePrimaryMesonW0WeightingInvMassPt(NULL),
272  fHistoTruePrimaryMesonMCPtResolPt(NULL),
273  fHistoTrueMotherMesonConvPhotonEtaPhi(NULL),
274  fHistoTrueBckGGInvMassPt(NULL),
275  fHistoTrueBckFullMesonContainedInOneClusterInvMassPt(NULL),
276  fHistoTrueBckAsymEClustersInvMassPt(NULL),
277  fHistoTrueBckContInvMassPt(NULL),
278  fHistoTrueMesonPtY(NULL),
279  fHistoTrueMesonPtAlpha(NULL),
280  fHistoTrueMesonPtOpenAngle(NULL),
281  fHistoMCMesonPtY(NULL),
282  fHistoMCMesonPtAlpha(NULL),
283  fHistoMCMesonPtJetPt(NULL),
284  fHistoTrueNLabelsInClusPt(NULL),
285  fHistoDoubleCountTrueMesonInvMassPt(NULL),
286  fHistoDoubleCountTrueConvGammaRPt(NULL),
287  fHistoDoubleCountTrueClusterGammaPt(NULL),
288  fHistoSPDClusterTrackletBackground(NULL),
289  fProfileEtaShift(NULL),
290  fProfileJetJetXSection(NULL),
291  fHistoMCHeaders(NULL),
292  fHistoConvGammaPt(NULL),
293  fHistoClusGammaPt(NULL),
294  fHistoClusGammaE(NULL),
295  fHistoClusOverlapHeadersGammaPt(NULL),
296  fHistoClusAllHeadersGammaPt(NULL),
297  fHistoClusRejectedHeadersGammaPt(NULL),
298  fHistoMotherInvMassRejected(NULL),
299  fHistoMCMesonPt(NULL),
300  fHistoMCMesonWOWeightPt(NULL),
301  fHistoMCMesonWOEvtWeightPt(NULL),
302  fHistoMCMesonInAccPt(NULL),
303  fHistoMCMesonWOWeightInAccPt(NULL),
304  fHistoMCMesonWOEvtWeightInAccPt(NULL),
305  fHistoTrueConvGammaPt(NULL),
306  fHistoTruePrimaryConvGammaPt(NULL),
307  fHistoTrueClusGammaPt(NULL),
308  fHistoTrueClusConvGammaPt(NULL),
309  fHistoTrueClusConvGammaFullyPt(NULL),
310  fHistoTruePrimaryClusGammaPt(NULL),
311  fHistoTruePrimaryClusConvGammaPt(NULL),
312  fHistoMultipleCountTrueMeson(NULL),
313  fHistoMultipleCountTrueConvGamma(NULL),
314  fHistoMultipleCountTrueClusterGamma(NULL),
315  fHistoNEvents(NULL),
316  fHistoNEventsWOWeight(NULL),
317  fHistoNGoodESDTracks(NULL),
318  fHistoVertexZ(NULL),
319  fHistoVertexX(NULL),
320  fHistoVertexY(NULL),
321  fHistoNGammaConvCandidates(NULL),
322  fHistoNGammaCaloCandidates(NULL),
323  fHistoNV0Tracks(NULL),
324  fHistoJetJetNTrials(NULL),
325  fMapMultipleCountTrueMesons(),
326  fMapMultipleCountTrueConvGammas(),
327  fMapMultipleCountTrueClusterGammas(),
328  fVectorRecTrueMesons(0),
329  fVectorDoubleCountTrueMesons(0),
330  fVectorDoubleCountTrueConvGammas(0),
331  fVectorDoubleCountTrueClusterGammas(0),
332  fUnsmearedPx(NULL),
333  fUnsmearedPy(NULL),
334  fUnsmearedPz(NULL),
335  fUnsmearedE(NULL),
336  fMesonInvMassWindow(NULL),
337  fMCEventPos(NULL),
338  fMCEventNeg(NULL),
339  fESDArrayPos(NULL),
340  fESDArrayNeg(NULL),
341  fEventPlaneAngle(-100),
342  fMesonInvMassMin(0),
343  fMesonInvMassMax(0),
344  fMesonInvMassNBins(0),
345  fWeightJetJetMC(1),
346  fNGammaCandidates(0),
347  fnCuts(0),
348  fiCut(0),
349  fIsHeavyIon(0),
350  fMesonRecoMode(-1),
351  fMesonType(-1),
352  fMesonPDG(0),
353  fDoMesonQA(0),
354  fDoPhotonQA(0),
355  fDoClusterQA(0),
356  fIsMC(0),
357  fMoveParticleAccordingToVertex(kTRUE),
358  fDoLightOutput(kFALSE),
359  fIsFromDesiredHeader(kTRUE),
360  fIsOverlappingWithOtherHeader(kFALSE),
361  fDoTHnSparse(kTRUE),
362  fSetPlotHistsExtQA(kFALSE),
363  fDoConvGammaShowerShapeTree(kFALSE),
364  fEnableSortForClusMC(kFALSE),
365  fDoPrimaryTrackMatching(kFALSE),
366  fDoInvMassShowerShapeTree(kFALSE),
367  fAllowOverlapHeaders(kTRUE),
368  fEnableClusterCutsForTrigger(kFALSE)
369 {
370  // Define output slots here
371  DefineOutput(1, TList::Class());
372 }
373 
375 {
376  if(fGammaCandidates){
377  delete fGammaCandidates;
378  fGammaCandidates = 0x0;
379  }
380  if(fClusterCandidates){
381  delete fClusterCandidates;
382  fClusterCandidates = 0x0;
383  }
384  if(fBGHandler){
385  delete[] fBGHandler;
386  fBGHandler = 0x0;
387  }
388  if(fBGHandlerRP){
389  delete[] fBGHandlerRP;
390  fBGHandlerRP = 0x0;
391  }
392  if(fBGClusHandler){
393  delete[] fBGClusHandler;
394  fBGClusHandler = 0x0;
395  }
396  if(fBGClusHandlerRP){
397  delete[] fBGClusHandlerRP;
398  fBGClusHandlerRP = 0x0;
399  }
400 }
401 //___________________________________________________________
403 
404  const Int_t nDim = 4;
405  Int_t nBins[nDim] = {800,300,7,4};
406  Double_t xMin[nDim] = {0,0, 0,0};
407  Double_t xMax[nDim] = {0.8,30,7,4};
408 
409  if(fDoTHnSparse){
410  fSparseMotherInvMassPtZM = new THnSparseF*[fnCuts];
411  fSparseMotherBackInvMassPtZM = new THnSparseF*[fnCuts];
412  }
413 
416 
419 
420  for(Int_t iCut = 0; iCut<fnCuts;iCut++){
421  if (((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->DoBGCalculation()){
422  TString cutstringEvent = ((AliConvEventCuts*)fEventCutArray->At(iCut))->GetCutNumber();
423  TString cutstringConvGamma = "";
424  TString cutstringCaloGamma = "";
425  if (fMesonRecoMode < 2) cutstringConvGamma = ((AliConversionPhotonCuts*)fCutArray->At(iCut))->GetCutNumber();
426  if (fMesonRecoMode > 0 || fEnableClusterCutsForTrigger ) cutstringCaloGamma = ((AliCaloPhotonCuts*)fClusterCutArray->At(iCut))->GetCutNumber();
427  TString cutstringMeson = ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetCutNumber();
428 
429  TString fullCutString = "";
430  if (fMesonRecoMode == 0) fullCutString = Form("%i_%s_%s_%s",fMesonRecoMode, cutstringEvent.Data(), cutstringConvGamma.Data(), cutstringMeson.Data());
431  else if (fMesonRecoMode == 1) fullCutString = Form("%i_%s_%s_%s_%s",fMesonRecoMode, cutstringEvent.Data(),cutstringConvGamma.Data(),cutstringCaloGamma.Data(), cutstringMeson.Data());
432  else if (fMesonRecoMode == 2) fullCutString = Form("%i_%s_%s_%s",fMesonRecoMode, cutstringEvent.Data(), cutstringCaloGamma.Data(), cutstringMeson.Data());
433 
434  Int_t collisionSystem = atoi((TString)(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetCutNumber())(0,1));
435  Int_t centMin = atoi((TString)(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetCutNumber())(1,1));
436  Int_t centMax = atoi((TString)(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetCutNumber())(2,1));
437 
438  if( collisionSystem == 1 || collisionSystem == 2 ||
439  collisionSystem == 5 || collisionSystem == 8 ||
440  collisionSystem == 9){
441  centMin = centMin*10;
442  centMax = centMax*10;
443  if(centMax ==0 && centMax!=centMin) centMax=100;
444  }else if(collisionSystem == 3 || collisionSystem == 6){
445  centMin = centMin*5;
446  centMax = centMax*5;
447  }else if(collisionSystem == 4 || collisionSystem == 7){
448  centMin = ((centMin*5)+45);
449  centMax = ((centMax*5)+45);
450  }
451 
452  if(fDoTHnSparse){
453  fBackList[iCut] = new TList();
454  fBackList[iCut]->SetName(Form("%s Back histograms",fullCutString.Data()));
455  fBackList[iCut]->SetOwner(kTRUE);
456  fCutFolder[iCut]->Add(fBackList[iCut]);
457 
458  fSparseMotherBackInvMassPtZM[iCut] = new THnSparseF("Back_Back_InvMass_Pt_z_m", "Back_Back_InvMass_Pt_z_m",nDim,nBins,xMin,xMax);
459  fBackList[iCut]->Add(fSparseMotherBackInvMassPtZM[iCut]);
460 
461  fMotherList[iCut] = new TList();
462  fMotherList[iCut]->SetName(Form("%s Mother histograms",fullCutString.Data()));
463  fMotherList[iCut]->SetOwner(kTRUE);
464  fCutFolder[iCut]->Add(fMotherList[iCut]);
465 
466  fSparseMotherInvMassPtZM[iCut] = new THnSparseF("Back_Mother_InvMass_Pt_z_m", "Back_Mother_InvMass_Pt_z_m",nDim,nBins,xMin,xMax);
467  fMotherList[iCut]->Add(fSparseMotherInvMassPtZM[iCut]);
468  }
469 
470  if(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->BackgroundHandlerType() == 0){
471  fBGHandler[iCut] = new AliGammaConversionAODBGHandler( collisionSystem,centMin,centMax,
472  ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetNumberOfBGEvents(),
473  ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->UseTrackMultiplicity(),
474  2,8,5);
475  fBGClusHandler[iCut] = new AliGammaConversionAODBGHandler( collisionSystem,centMin,centMax,
476  ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetNumberOfBGEvents(),
477  ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->UseTrackMultiplicity(),
478  2,8,5);
479  fBGHandlerRP[iCut] = NULL;
480  }else{
482  ((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity(),
483  ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetNumberOfBGEvents());
485  ((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity(),
486  ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetNumberOfBGEvents());
487  fBGHandler[iCut] = NULL;
488  }
489  }
490  }
491 }
492 
493 //________________________________________________________________________
495 
496  fV0Reader = (AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask(fV0ReaderName.Data());
497  if(!fV0Reader){printf("Error: No V0 Reader");return;}// GetV0Reader
498  if (fIsMC == 2){
499  fDoClusterQA = 0;
500  fDoTHnSparse = kFALSE;
501  } else if (fIsMC == 3){
502  fDoTHnSparse = kFALSE;
503  }
504 
505  if (fMesonRecoMode == 2)
507 
508  // Create histograms
509  if(fOutputContainer != NULL){
510  delete fOutputContainer;
511  fOutputContainer = NULL;
512  }
513  if(fOutputContainer == NULL){
514  fOutputContainer = new TList();
515  fOutputContainer->SetOwner(kTRUE);
516  }
517 
518  // Array of current cut's gammas
519  fGammaCandidates = new TList();
520  fClusterCandidates = new TList();
521  fClusterCandidates->SetOwner(kTRUE);
522 
523  fCutFolder = new TList*[fnCuts];
524  fESDList = new TList*[fnCuts];
525 
526  if(fDoTHnSparse){
527  fBackList = new TList*[fnCuts];
528  fMotherList = new TList*[fnCuts];
529  }
530 
531  fHistoNEvents = new TH1F*[fnCuts];
532  if (fIsMC > 1){
533  fHistoNEventsWOWeight = new TH1F*[fnCuts];
534  }
535  if (fIsMC == 2){
536  fProfileJetJetXSection = new TProfile*[fnCuts];
537  fHistoJetJetNTrials = new TH1F*[fnCuts];
538  }
539  fHistoNGoodESDTracks = new TH1F*[fnCuts];
540  fHistoVertexZ = new TH1F*[fnCuts];
541  if(!fDoLightOutput){
542  fHistoVertexX = new TH1F*[fnCuts];
543  fHistoVertexY = new TH1F*[fnCuts];
544  }
545  if (fMesonRecoMode < 2) fHistoNGammaConvCandidates = new TH1F*[fnCuts];
546  if(fIsHeavyIon==2) fProfileEtaShift = new TProfile*[fnCuts];
547  if(!fDoLightOutput){
549  fHistoNV0Tracks = new TH1F*[fnCuts];
550  if (fMesonRecoMode < 2)
551  fHistoConvGammaPt = new TH1F*[fnCuts];
552  }
553 
555  fHistoNGammaCaloCandidates = new TH1F*[fnCuts];
556  if (!fDoLightOutput ){
557  fHistoClusGammaPt = new TH1F*[fnCuts];
558  fHistoClusGammaE = new TH1F*[fnCuts];
559  if (fIsMC > 0){
561  fHistoClusAllHeadersGammaPt = new TH1F*[fnCuts];
563  }
564  }
565  }
566 
568  fHistoMotherInvMassRejected = new TH1F*[fnCuts];
570  if(!fDoLightOutput && fMesonRecoMode == 1){
572  }
573  if (fDoMesonQA > 0){
578  }
579 
580  fMesonInvMassWindow = new Double_t[2];
581  if (fMesonType < 0 || fMesonType > 2){
582  if(!fV0Reader){printf("Error: No V0 Reader");return;}// GetV0Reader
583  } else if (fMesonType == 0){ // pi0 case 134.9770 ± 0.0005 MeV
584  fMesonPDG = 111;
585  fMesonInvMassMin = 0.;
586  fMesonInvMassMax = 0.400;
587  fMesonInvMassNBins = 400;
588  fMesonInvMassWindow[0] = 0.05;
589  fMesonInvMassWindow[1] = 0.17;
590  } else if (fMesonType == 1){ // eta case 547.862 ± 0.017 MeV
591  fMesonPDG = 221;
592  fMesonInvMassMin = 0.300;
593  fMesonInvMassMax = 0.800;
594  fMesonInvMassNBins = 500;
595  fMesonInvMassWindow[0] = 0.45;
596  fMesonInvMassWindow[1] = 0.65;
597  } else if (fMesonType == 2){ // eta' case 957.78 ± 0.06 MeV
598  fMesonPDG = 331;
599  fMesonInvMassMin = 0.700;
600  fMesonInvMassMax = 1.200;
601  fMesonInvMassNBins = 500;
602  fMesonInvMassWindow[0] = 0.85;
603  fMesonInvMassWindow[1] = 1.05;
604  }
605  // set common binning in pT for mesons and photons
606  Int_t nBinsPt = 200;
607  Float_t binWidthPt = 0.1;
608  Float_t minPt = 0;
609  Float_t maxPt = 20;
610  Int_t nBinsQAPt = 170;
611  Float_t maxQAPt = 20;
612  Int_t nBinsClusterPt = 500;
613  Float_t minClusterPt = 0;
614  Float_t maxClusterPt = 50;
615  Double_t *arrPtBinning = new Double_t[1200];
616  Double_t *arrQAPtBinning = new Double_t[1200];
617  Double_t *arrClusPtBinning = new Double_t[1200];
618  // Set special pt binning for pp 8TeV
619  if (((AliConvEventCuts*)fV0Reader->GetEventCuts())->GetEnergyEnum() == AliConvEventCuts::k8TeV ){
620  nBinsQAPt = 190;
621  maxQAPt = 40;
622  for(Int_t i=0; i<nBinsQAPt+1;i++){
623  if(i<60) arrQAPtBinning[i] = 0.05*i;
624  else if(i<130) arrQAPtBinning[i] = 3.+0.1*(i-60);
625  else if(i<170) arrQAPtBinning[i] = 10.+0.25*(i-130);
626  else if(i<190) arrQAPtBinning[i] = 20.+1.0*(i-170);
627  else arrQAPtBinning[i] = maxQAPt;
628  }
629  nBinsPt = 400;
630  minPt = 0;
631  maxPt = 40;
632  for(Int_t i=0; i<nBinsPt+1;i++){
633  arrPtBinning[i] = ((maxPt-minPt)/nBinsPt)*i;
634  }
635  nBinsClusterPt = 800;
636  minClusterPt = 0;
637  maxClusterPt = 80;
638  for(Int_t i=0; i<nBinsPt+1;i++){
639  arrClusPtBinning[i] = ((maxClusterPt-minClusterPt)/nBinsClusterPt)*i;
640  }
641  // Set special pt binning for pPb 5TeV
642  } else if ( ((AliConvEventCuts*)fV0Reader->GetEventCuts())->GetEnergyEnum() == AliConvEventCuts::kpPb5TeV ||
644  ((AliConvEventCuts*)fV0Reader->GetEventCuts())->GetEnergyEnum() == AliConvEventCuts::k5TeV ){
645  binWidthPt = 0.05;
646  nBinsPt = 205;
647  minPt = 0;
648  maxPt = 60;
649  for(Int_t i=0; i<nBinsPt+1;i++){
650  if (i < 1) arrPtBinning[i] = 0.3*i;
651  else if(i<55) arrPtBinning[i] = 0.3+0.05*(i-1);
652  else if(i<125) arrPtBinning[i] = 3.+0.1*(i-55);
653  else if(i<165) arrPtBinning[i] = 10.+0.25*(i-125);
654  else if(i<205) arrPtBinning[i] = 20.+1.0*(i-165);
655  else arrPtBinning[i] = maxPt;
656  }
657  nBinsQAPt = 210;
658  maxQAPt = 60;
659  for(Int_t i=0; i<nBinsQAPt+1;i++){
660  if(i<60) arrQAPtBinning[i] = 0.05*i;
661  else if(i<130) arrQAPtBinning[i] = 3.+0.1*(i-60);
662  else if(i<170) arrQAPtBinning[i] = 10.+0.25*(i-130);
663  else if(i<210) arrQAPtBinning[i] = 20.+1.0*(i-170);
664  else arrQAPtBinning[i] = maxQAPt;
665  }
666  nBinsClusterPt = 301;
667  minClusterPt = 0;
668  maxClusterPt = 100;
669  for(Int_t i=0; i<nBinsClusterPt+1;i++){
670  if (i < 1) arrClusPtBinning[i] = 0.3*i;
671  else if(i<55) arrClusPtBinning[i] = 0.3+0.05*(i-1);
672  else if(i<125) arrClusPtBinning[i] = 3.+0.1*(i-55);
673  else if(i<155) arrClusPtBinning[i] = 10.+0.2*(i-125);
674  else if(i<211) arrClusPtBinning[i] = 16.+0.25*(i-155);
675  else if(i<251) arrClusPtBinning[i] = 30.+0.5*(i-211);
676  else if(i<301) arrClusPtBinning[i] = 50.+1.0*(i-251);
677  else arrClusPtBinning[i] = maxClusterPt;
678  }
679  // Set special pt binning for pp 13TeV, pPb 8TeV
680  } else if ( ((AliConvEventCuts*)fV0Reader->GetEventCuts())->GetEnergyEnum() == AliConvEventCuts::k13TeV ||
683  nBinsPt = 285;
684  minPt = 0;
685  maxPt = 100;
686  binWidthPt = 0.05;
687  for(Int_t i=0; i<nBinsPt+1;i++){
688  if (i < 1) arrPtBinning[i] = 0.3*i;
689  else if(i<55) arrPtBinning[i] = 0.3+0.05*(i-1);
690  else if(i<125) arrPtBinning[i] = 3.+0.1*(i-55);
691  else if(i<185) arrPtBinning[i] = 10.+0.25*(i-125);
692  else if(i<235) arrPtBinning[i] = 25.+0.5*(i-185);
693  else if(i<285) arrPtBinning[i] = 50.+1.0*(i-235);
694  else arrPtBinning[i] = maxPt;
695  }
696  nBinsQAPt = 270;
697  maxQAPt = 100;
698  for(Int_t i=0; i<nBinsQAPt+1;i++){
699  if(i<60) arrQAPtBinning[i] = 0.05*i;
700  else if(i<130) arrQAPtBinning[i] = 3.+0.1*(i-60);
701  else if(i<170) arrQAPtBinning[i] = 10.+0.25*(i-130);
702  else if(i<210) arrQAPtBinning[i] = 20.+0.5*(i-170);
703  else if(i<270) arrQAPtBinning[i] = 40.+1.0*(i-210);
704  else arrQAPtBinning[i] = maxQAPt;
705  }
706  nBinsClusterPt = 301;
707  minClusterPt = 0;
708  maxClusterPt = 100;
709  for(Int_t i=0; i<nBinsClusterPt+1;i++){
710  if (i < 1) arrClusPtBinning[i] = 0.3*i;
711  else if(i<55) arrClusPtBinning[i] = 0.3+0.05*(i-1);
712  else if(i<125) arrClusPtBinning[i] = 3.+0.1*(i-55);
713  else if(i<155) arrClusPtBinning[i] = 10.+0.2*(i-125);
714  else if(i<211) arrClusPtBinning[i] = 16.+0.25*(i-155);
715  else if(i<251) arrClusPtBinning[i] = 30.+0.5*(i-211);
716  else if(i<301) arrClusPtBinning[i] = 50.+1.0*(i-251);
717  else arrClusPtBinning[i] = maxClusterPt;
718  }
719  } else if (((AliConvEventCuts*)fV0Reader->GetEventCuts())->GetEnergyEnum() == AliConvEventCuts::kXeXe5440GeV ){
720  nBinsPt = 90;
721  minPt = 0;
722  maxPt = 20;
723  for(Int_t i=0; i<nBinsPt+1;i++){
724  if (i < 1) arrPtBinning[i] = 0.3*i;
725  else if(i<58) arrPtBinning[i] = 0.3+0.1*(i-1);
726  else if(i<82) arrPtBinning[i] = 6.+0.25*(i-58);
727  else if(i<90) arrPtBinning[i] = 12.+1.0*(i-82);
728  else arrPtBinning[i] = maxPt;
729  }
730  nBinsQAPt = 92;
731  maxQAPt = 20;
732  for(Int_t i=0; i<nBinsQAPt+1;i++){
733  if(i<60) arrQAPtBinning[i] = 0.1*i;
734  else if(i<84) arrQAPtBinning[i] = 6.+0.25*(i-60);
735  else if(i<92) arrQAPtBinning[i] = 12.+1.0*(i-84);
736  else arrQAPtBinning[i] = maxQAPt;
737  }
738  nBinsClusterPt = 148;
739  minClusterPt = 0;
740  maxClusterPt = 40;
741  for(Int_t i=0; i<nBinsClusterPt+1;i++){
742  if (i < 1) arrClusPtBinning[i] = 0.3*i;
743  else if(i<98) arrClusPtBinning[i] = 0.3+0.1*(i-1);
744  else if(i<123) arrClusPtBinning[i] = 10.+0.2*(i-98);
745  else if(i<148) arrClusPtBinning[i] = 15.+1.0*(i-123);
746  else arrClusPtBinning[i] = maxClusterPt;
747  }
748  } else if (((AliConvEventCuts*)fV0Reader->GetEventCuts())->GetEnergyEnum() == AliConvEventCuts::kPbPb5TeV ){
749  nBinsPt = 90;
750  minPt = 0;
751  maxPt = 20;
752  for(Int_t i=0; i<nBinsPt+1;i++){
753  if (i < 1) arrPtBinning[i] = 0.3*i;
754  else if(i<58) arrPtBinning[i] = 0.3+0.1*(i-1);
755  else if(i<82) arrPtBinning[i] = 6.+0.25*(i-58);
756  else if(i<90) arrPtBinning[i] = 12.+1.0*(i-82);
757  else arrPtBinning[i] = maxPt;
758  }
759  nBinsQAPt = 92;
760  maxQAPt = 20;
761  for(Int_t i=0; i<nBinsQAPt+1;i++){
762  if(i<60) arrQAPtBinning[i] = 0.1*i;
763  else if(i<84) arrQAPtBinning[i] = 6.+0.25*(i-60);
764  else if(i<92) arrQAPtBinning[i] = 12.+1.0*(i-84);
765  else arrQAPtBinning[i] = maxQAPt;
766  }
767  nBinsClusterPt = 148;
768  minClusterPt = 0;
769  maxClusterPt = 40;
770  for(Int_t i=0; i<nBinsClusterPt+1;i++){
771  if (i < 1) arrClusPtBinning[i] = 0.3*i;
772  else if(i<98) arrClusPtBinning[i] = 0.3+0.1*(i-1);
773  else if(i<123) arrClusPtBinning[i] = 10.+0.2*(i-98);
774  else if(i<148) arrClusPtBinning[i] = 15.+1.0*(i-123);
775  else arrClusPtBinning[i] = maxClusterPt;
776  }
777  // default binning
778  } else {
779  for(Int_t i=0; i<nBinsPt+1;i++){
780  arrPtBinning[i] = ((maxPt-minPt)/nBinsPt)*i;
781  }
782  for(Int_t i=0; i<nBinsClusterPt+1;i++){
783  arrClusPtBinning[i] = ((maxClusterPt-minClusterPt)/nBinsClusterPt)*i;
784  }
785  for(Int_t i=0; i<nBinsQAPt+1;i++){
786  if(i<60) arrQAPtBinning[i] = 0.05*i;
787  else if(i<130) arrQAPtBinning[i] = 3.+0.1*(i-60);
788  else if(i<170) arrQAPtBinning[i] = 10.+0.25*(i-130);
789  else arrQAPtBinning[i] = maxQAPt;
790  }
791  }
792 
793  for(Int_t iCut = 0; iCut<fnCuts;iCut++){
794  TString cutstringEvent = ((AliConvEventCuts*)fEventCutArray->At(iCut))->GetCutNumber();
795  TString cutstringConvGamma = "";
796  TString cutstringCaloGamma = "";
797  if (fMesonRecoMode < 2) cutstringConvGamma = ((AliConversionPhotonCuts*)fCutArray->At(iCut))->GetCutNumber();
798  if (fMesonRecoMode > 0 || fEnableClusterCutsForTrigger) cutstringCaloGamma = ((AliCaloPhotonCuts*)fClusterCutArray->At(iCut))->GetCutNumber();
799  TString cutstringMeson = ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetCutNumber();
800 
801  TString fullCutString = "";
802  if (fMesonRecoMode == 0) fullCutString = Form("%i_%s_%s_%s",fMesonRecoMode, cutstringEvent.Data(), cutstringConvGamma.Data(), cutstringMeson.Data());
803  else if (fMesonRecoMode == 1) fullCutString = Form("%i_%s_%s_%s_%s",fMesonRecoMode, cutstringEvent.Data(),cutstringConvGamma.Data(),cutstringCaloGamma.Data(), cutstringMeson.Data());
804  else if (fMesonRecoMode == 2) fullCutString = Form("%i_%s_%s_%s",fMesonRecoMode, cutstringEvent.Data(), cutstringCaloGamma.Data(), cutstringMeson.Data());
805 
806  fCutFolder[iCut] = new TList();
807  fCutFolder[iCut]->SetName(Form("Cut Number %s",fullCutString.Data()));
808  fCutFolder[iCut]->SetOwner(kTRUE);
809  fOutputContainer->Add(fCutFolder[iCut]);
810  fESDList[iCut] = new TList();
811  fESDList[iCut]->SetName(Form("%s ESD histograms",fullCutString.Data()));
812  fESDList[iCut]->SetOwner(kTRUE);
813  fCutFolder[iCut]->Add(fESDList[iCut]);
814 
815  fHistoNEvents[iCut] = new TH1F("NEvents", "NEvents", 14, -0.5, 13.5);
816  fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(1,"Accepted");
817  fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(2,"Centrality");
818  fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(3,"Miss. MC or inc. ev.");
819  if (((AliConvEventCuts*)fEventCutArray->At(iCut))->IsSpecialTrigger() > 1 ){
820  TString TriggerNames = "Not Trigger: ";
821  TriggerNames = TriggerNames+ ( (AliConvEventCuts*)fEventCutArray->At(iCut))->GetSpecialTriggerName();
822  fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(4,TriggerNames.Data());
823  }else {
824  fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(4,"Trigger");
825  }
826  fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(5,"Vertex Z");
827  fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(6,"Cont. Vertex");
828  fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(7,"Pile-Up");
829  fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(8,"no SDD");
830  fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(9,"no V0AND");
831  fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(10,"EMCAL problem");
832  fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(11,"rejectedForJetJetMC");
833  fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(12,"SPD hits vs tracklet");
834  fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(13,"Out-of-Bunch pileup Past-Future");
835  fHistoNEvents[iCut]->GetXaxis()->SetBinLabel(14,"Pileup V0M-TPCout Tracks");
836  fESDList[iCut]->Add(fHistoNEvents[iCut]);
837 
838  if (fIsMC > 1){
839  fHistoNEventsWOWeight[iCut] = new TH1F("NEventsWOWeight", "NEventsWOWeight", 14, -0.5, 13.5);
840  fHistoNEventsWOWeight[iCut]->GetXaxis()->SetBinLabel(1,"Accepted");
841  fHistoNEventsWOWeight[iCut]->GetXaxis()->SetBinLabel(2,"Centrality");
842  fHistoNEventsWOWeight[iCut]->GetXaxis()->SetBinLabel(3,"Miss. MC or inc. ev.");
843  if (((AliConvEventCuts*)fEventCutArray->At(iCut))->IsSpecialTrigger() > 1 ){
844  TString TriggerNames = "Not Trigger: ";
845  TriggerNames = TriggerNames+ ( (AliConvEventCuts*)fEventCutArray->At(iCut))->GetSpecialTriggerName();
846  fHistoNEventsWOWeight[iCut]->GetXaxis()->SetBinLabel(4,TriggerNames.Data());
847  }else {
848  fHistoNEventsWOWeight[iCut]->GetXaxis()->SetBinLabel(4,"Trigger");
849  }
850  fHistoNEventsWOWeight[iCut]->GetXaxis()->SetBinLabel(5,"Vertex Z");
851  fHistoNEventsWOWeight[iCut]->GetXaxis()->SetBinLabel(6,"Cont. Vertex");
852  fHistoNEventsWOWeight[iCut]->GetXaxis()->SetBinLabel(7,"Pile-Up");
853  fHistoNEventsWOWeight[iCut]->GetXaxis()->SetBinLabel(8,"no SDD");
854  fHistoNEventsWOWeight[iCut]->GetXaxis()->SetBinLabel(9,"no V0AND");
855  fHistoNEventsWOWeight[iCut]->GetXaxis()->SetBinLabel(10,"EMCAL problem");
856  fHistoNEventsWOWeight[iCut]->GetXaxis()->SetBinLabel(11,"rejectedForJetJetMC");
857  fHistoNEventsWOWeight[iCut]->GetXaxis()->SetBinLabel(12,"SPD hits vs tracklet");
858  fHistoNEventsWOWeight[iCut]->GetXaxis()->SetBinLabel(13,"Out-of-Bunch pileup Past-Future");
859  fHistoNEventsWOWeight[iCut]->GetXaxis()->SetBinLabel(14,"Pileup V0M-TPCout Tracks");
860  fESDList[iCut]->Add(fHistoNEventsWOWeight[iCut]);
861  }
862 
863  if (fIsMC == 2){
864  fProfileJetJetXSection[iCut] = new TProfile("XSection", "XSection", 1, -0.5, 0.5);
865  fESDList[iCut]->Add(fProfileJetJetXSection[iCut]);
866  fHistoJetJetNTrials[iCut] = new TH1F("NTrials", "#sum{NTrials}", 1, 0, 1);
867  fHistoJetJetNTrials[iCut]->GetXaxis()->SetBinLabel(1,"#sum{NTrials}");
868  fESDList[iCut]->Add(fHistoJetJetNTrials[iCut]);
869  }
870 
871  if(fIsHeavyIon == 1)
872  fHistoNGoodESDTracks[iCut] = new TH1F("GoodESDTracks", "GoodESDTracks; # TPC tracks", 4000, 0, 4000);
873  else if(fIsHeavyIon == 2)
874  fHistoNGoodESDTracks[iCut] = new TH1F("GoodESDTracks", "GoodESDTracks; # TPC tracks", 400, 0, 400);
875  else
876  fHistoNGoodESDTracks[iCut] = new TH1F("GoodESDTracks", "GoodESDTracks; # TPC tracks", 200, 0, 200);
877  fESDList[iCut]->Add(fHistoNGoodESDTracks[iCut]);
878 
879  fHistoVertexZ[iCut] = new TH1F("VertexZ", "VertexZ", 200, -10, 10);
880  fESDList[iCut]->Add(fHistoVertexZ[iCut]);
881  if(!fDoLightOutput){
882  fHistoVertexX[iCut] = new TH1F("VertexX", "VertexX", 100, -5, 5);
883  fESDList[iCut]->Add(fHistoVertexX[iCut]);
884  fHistoVertexY[iCut] = new TH1F("VertexY", "VertexY", 100, -5, 5);
885  fESDList[iCut]->Add(fHistoVertexY[iCut]);
886  }
887 
888  if (fMesonRecoMode < 2){
889  if(fIsHeavyIon == 1)
890  fHistoNGammaConvCandidates[iCut] = new TH1F("GammaConvCandidates", "GammaConvCandidates; # accepted #gamma_{conv}", 100, 0, 100);
891  else if(fIsHeavyIon == 2)
892  fHistoNGammaConvCandidates[iCut] = new TH1F("GammaConvCandidates", "GammaConvCandidates; # accepted #gamma_{conv}", 50, 0, 50);
893  else
894  fHistoNGammaConvCandidates[iCut] = new TH1F("GammaConvCandidates", "GammaConvCandidates; # accepted #gamma_{conv}", 50, 0, 50);
895  fESDList[iCut]->Add(fHistoNGammaConvCandidates[iCut]);
896  }
898  if(fIsHeavyIon == 1)
899  fHistoNGammaCaloCandidates[iCut] = new TH1F("GammaCaloCandidates", "GammaCaloCandidates; # accepted #gamma_{conv}", 100, 0, 100);
900  else if(fIsHeavyIon == 2)
901  fHistoNGammaCaloCandidates[iCut] = new TH1F("GammaCaloCandidates", "GammaCaloCandidates; # accepted #gamma_{conv}", 50, 0, 50);
902  else
903  fHistoNGammaCaloCandidates[iCut] = new TH1F("GammaCaloCandidates", "GammaCaloCandidates; # accepted #gamma_{conv}", 50, 0, 50);
904  fESDList[iCut]->Add(fHistoNGammaCaloCandidates[iCut]);
905  }
906 
907  if(!fDoLightOutput){
908  fHistoSPDClusterTrackletBackground[iCut] = new TH2F("SPD tracklets vs SPD clusters", "SPD tracklets vs SPD clusters", 100, 0, 200, 250, 0, 1000);
910 
911  if(fIsHeavyIon == 1)
912  fHistoNV0Tracks[iCut] = new TH1F("V0 Multiplicity", "V0 Multiplicity; VZERO amp [arb. units]", 30000, 0, 30000);
913  else if(fIsHeavyIon == 2)
914  fHistoNV0Tracks[iCut] = new TH1F("V0 Multiplicity", "V0 Multiplicity; VZERO amp [arb. units]", 2500, 0, 2500);
915  else
916  fHistoNV0Tracks[iCut] = new TH1F("V0 Multiplicity", "V0 Multiplicity; VZERO amp [arb. units]", 1500, 0, 1500);
917  fESDList[iCut]->Add(fHistoNV0Tracks[iCut]);
918 
919  if (fMesonRecoMode < 2){
920  fHistoConvGammaPt[iCut] = new TH1F("ESD_ConvGamma_Pt", "ESD_ConvGamma_Pt; p_{T,conv}(GeV/c)", (Int_t)((maxPt-minPt)/binWidthPt), minPt, maxPt);
921  fESDList[iCut]->Add(fHistoConvGammaPt[iCut]);
922  }
924  fHistoClusGammaPt[iCut] = new TH1F("ClusGamma_Pt", "ClusGamma_Pt; p_{T,clus} (GeV/c)", nBinsClusterPt, arrClusPtBinning);
925  fESDList[iCut]->Add(fHistoClusGammaPt[iCut]);
926  fHistoClusGammaE[iCut] = new TH1F("ClusGamma_E", "ClusGamma_E; E_{clus} (GeV)", nBinsClusterPt, arrClusPtBinning);
927  fESDList[iCut]->Add(fHistoClusGammaE[iCut]);
928  if (fIsMC > 0){
929  fHistoClusOverlapHeadersGammaPt[iCut] = new TH1F("ClusGammaOverlapHeaders_Pt", "ClusGammaOverlapHeaders_Pt; p_{T,clus} (GeV/c), selected header w/ overlap",
930  nBinsClusterPt, arrClusPtBinning);
931  fESDList[iCut]->Add(fHistoClusOverlapHeadersGammaPt[iCut]);
932  fHistoClusAllHeadersGammaPt[iCut] = new TH1F("ClusGammaAllHeaders_Pt", "ClusGammaAllHeaders_Pt; p_{T,clus} (GeV/c), all headers",
933  nBinsClusterPt, arrClusPtBinning);
934  fESDList[iCut]->Add(fHistoClusAllHeadersGammaPt[iCut]);
935  fHistoClusRejectedHeadersGammaPt[iCut] = new TH1F("ClusGammaRejectedHeaders_Pt", "ClusGammaRejectedHeaders_Pt; p_{T,clus} (GeV/c), rejected headers",
936  nBinsClusterPt, arrClusPtBinning);
937  fESDList[iCut]->Add(fHistoClusRejectedHeadersGammaPt[iCut]);
938  }
939  }
940  }
941 
942  if(fIsHeavyIon == 2){
943  fProfileEtaShift[iCut] = new TProfile("Eta Shift", "Eta Shift", 1, -0.5, 0.5);
944  fESDList[iCut]->Add(fProfileEtaShift[iCut]);
945  }
946 
947  if (fIsMC > 1){
948  fHistoNEvents[iCut]->Sumw2();
949  fHistoNGoodESDTracks[iCut]->Sumw2();
950  fHistoVertexZ[iCut]->Sumw2();
951  if (fMesonRecoMode < 2) fHistoNGammaConvCandidates[iCut]->Sumw2();
953  if(!fDoLightOutput){
954  fHistoVertexX[iCut]->Sumw2();
955  fHistoVertexY[iCut]->Sumw2();
956  fHistoSPDClusterTrackletBackground[iCut]->Sumw2();
957  fHistoNV0Tracks[iCut]->Sumw2();
958  if (fMesonRecoMode < 2)
959  fHistoConvGammaPt[iCut]->Sumw2();
961  if (fHistoClusGammaPt[iCut]) fHistoClusGammaPt[iCut]->Sumw2();
962  if (fHistoClusGammaE[iCut]) fHistoClusGammaE[iCut]->Sumw2();
966  }
967  }
968  }
969 
970 
971  fHistoMotherInvMassPt[iCut] = new TH2F("ESD_Mother_InvMass_Pt", "ESD_Mother_InvMass_Pt; M_{inv} (GeV/c^{2}); p_{T,pair} (GeV/c)",
972  fMesonInvMassNBins, fMesonInvMassMin, fMesonInvMassMax, nBinsPt, arrPtBinning);
973  fESDList[iCut]->Add(fHistoMotherInvMassPt[iCut]);
974  fHistoMotherInvMassRejected[iCut] = new TH1F("ESD_Mother_InvMassRejected", "ESD_Mother_InvMassRejected; M_{inv} (GeV/c^{2})",
975  1200, 0, 1.2);
976  fESDList[iCut]->Add(fHistoMotherInvMassRejected[iCut]);
977 
978  if(!fDoLightOutput){
979  if (fMesonRecoMode == 1){
980  fHistoMotherMatchedInvMassPt[iCut] = new TH2F("ESD_MotherMatched_InvMass_Pt", "ESD_MotherMatched_InvMass_Pt; M_{inv} (GeV/c^{2}) matched conv e^{+/-}to cluster; p_{T,pair} (GeV/c)",
981  fMesonInvMassNBins, fMesonInvMassMin, fMesonInvMassMax, nBinsPt, arrPtBinning);
982  fESDList[iCut]->Add(fHistoMotherMatchedInvMassPt[iCut]);
983  }
984  }
985 
986  fHistoMotherBackInvMassPt[iCut] = new TH2F("ESD_Background_InvMass_Pt", "ESD_Background_InvMass_Pt; M_{inv, mxed}(GeV/c^{2}); p_{T,BG pair} (GeV/c)",
987  fMesonInvMassNBins, fMesonInvMassMin, fMesonInvMassMax, nBinsPt, arrPtBinning);
988  fESDList[iCut]->Add(fHistoMotherBackInvMassPt[iCut]);
989 
990  if (fIsMC > 1){
991  fHistoMotherInvMassPt[iCut]->Sumw2();
992  fHistoMotherBackInvMassPt[iCut]->Sumw2();
993  if(!fDoLightOutput && fMesonRecoMode == 1){
995  }
996  }
997 
998  if (fDoMesonQA > 0 ){
999  fHistoMotherMesonPtY[iCut] = new TH2F("ESD_MotherMeson_Pt_Y", "ESD_MotherMeson_Pt_Y; p_{T, meson cand} (GeV/c); y_{meson cand}",
1000  nBinsQAPt, arrQAPtBinning, 150, -1.5, 1.5);
1001  fESDList[iCut]->Add(fHistoMotherMesonPtY[iCut]);
1002  fHistoMotherMesonPtAlpha[iCut] = new TH2F("ESD_MotherMeson_Pt_Alpha", "ESD_MotherMeson_Pt_Alpha; p_{T, meson cand} (GeV/c); #alpha_{meson cand}",
1003  nBinsQAPt, arrQAPtBinning, 200, -1, 1);
1004  fESDList[iCut]->Add(fHistoMotherMesonPtAlpha[iCut]);
1005  fHistoMotherMesonPtOpenAngle[iCut] = new TH2F("ESD_MotherMeson_Pt_OpenAngle", "ESD_MotherMeson_Pt_OpenAngle; p_{T, meson cand} (GeV/c); #theta_{meson cand}",
1006  nBinsQAPt, arrQAPtBinning, 100, 0, 1);
1007  fESDList[iCut]->Add(fHistoMotherMesonPtOpenAngle[iCut]);
1008  fHistoMotherMesonConvPhotonEtaPhi[iCut] = new TH2F("ESD_MotherMesonConvPhoton_Eta_Phi", "ConvPhoton under meson peak; #phi_{#gamma_{conv}}(rad); #eta_{#gamma_{conv}}",
1009  600, 0, 2*TMath::Pi(), 200, -1, 1);
1010  fESDList[iCut]->Add(fHistoMotherMesonConvPhotonEtaPhi[iCut]);
1011  if (fIsMC > 1){
1012  fHistoMotherMesonPtY[iCut]->Sumw2();
1013  fHistoMotherMesonPtAlpha[iCut]->Sumw2();
1014  fHistoMotherMesonPtOpenAngle[iCut]->Sumw2();
1015  fHistoMotherMesonConvPhotonEtaPhi[iCut]->Sumw2();
1016  }
1017  }
1018  }
1019 
1020  InitBack(); // Init Background Handler
1021 
1022  if(fIsMC>0){
1023  // MC Histogramms
1024  fMCList = new TList*[fnCuts];
1025  // True Histogramms
1026  fTrueList = new TList*[fnCuts];
1027 
1028  if(!fDoLightOutput){
1029  fHistoMCHeaders = new TH1I*[fnCuts];
1030  if (fMesonRecoMode < 2){
1031  fHistoTrueConvGammaPt = new TH1F*[fnCuts];
1034  fHistoTruePrimaryConvGammaPt = new TH1F*[fnCuts];
1035  }
1036 
1038  fHistoTrueClusGammaPt = new TH1F*[fnCuts];
1039  fHistoTrueClusConvGammaPt = new TH1F*[fnCuts];
1040  fHistoTruePrimaryClusGammaPt = new TH1F*[fnCuts];
1046  }
1047  }
1048 
1049  fHistoMCMesonPt = new TH1F*[fnCuts];
1050  fHistoMCMesonWOWeightPt = new TH1F*[fnCuts];
1051  fHistoMCMesonInAccPt = new TH1F*[fnCuts];
1052  fHistoMCMesonWOWeightInAccPt = new TH1F*[fnCuts];
1053  if (fIsMC > 1){
1054  fHistoMCMesonWOEvtWeightPt = new TH1F*[fnCuts];
1056  }
1057 
1060  fHistoMultipleCountTrueMeson = new TH1F*[fnCuts];
1064  if (fMesonRecoMode == 1){
1066  }
1067 
1068  if (fDoMesonQA > 0){
1069  fHistoMCMesonPtY = new TH2F*[fnCuts];
1071  if (fIsMC == 2){
1073  }
1074 
1075  if (fIsMC < 2){
1076  if (fMesonRecoMode > 0){
1082  }
1083  if (fMesonRecoMode == 1){
1086  }
1087  if (fMesonRecoMode == 2){
1089  }
1091  }
1092  if(fDoMesonQA > 1){
1097  }
1098  fHistoTrueMesonPtY = new TH2F*[fnCuts];
1101  }
1102 
1103  for(Int_t iCut = 0; iCut<fnCuts;iCut++){
1104  TString cutstringEvent = ((AliConvEventCuts*)fEventCutArray->At(iCut))->GetCutNumber();
1105  TString cutstringConvGamma = "";
1106  TString cutstringCaloGamma = "";
1107  if (fMesonRecoMode < 2) cutstringConvGamma = ((AliConversionPhotonCuts*)fCutArray->At(iCut))->GetCutNumber();
1108  if (fMesonRecoMode > 0 || fEnableClusterCutsForTrigger) cutstringCaloGamma = ((AliCaloPhotonCuts*)fClusterCutArray->At(iCut))->GetCutNumber();
1109  TString cutstringMeson = ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetCutNumber();
1110 
1111  TString fullCutString = "";
1112  if (fMesonRecoMode == 0) fullCutString = Form("%i_%s_%s_%s",fMesonRecoMode, cutstringEvent.Data(), cutstringConvGamma.Data(), cutstringMeson.Data());
1113  else if (fMesonRecoMode == 1) fullCutString = Form("%i_%s_%s_%s_%s",fMesonRecoMode, cutstringEvent.Data(),cutstringConvGamma.Data(),cutstringCaloGamma.Data(), cutstringMeson.Data());
1114  else if (fMesonRecoMode == 2) fullCutString = Form("%i_%s_%s_%s",fMesonRecoMode, cutstringEvent.Data(), cutstringCaloGamma.Data(), cutstringMeson.Data());
1115 
1116  fMCList[iCut] = new TList();
1117  fMCList[iCut]->SetName(Form("%s MC histograms",fullCutString.Data()));
1118  fMCList[iCut]->SetOwner(kTRUE);
1119  fCutFolder[iCut]->Add(fMCList[iCut]);
1120  if(!fDoLightOutput){
1121  fHistoMCHeaders[iCut] = new TH1I("MC_Headers", "MC_Headers", 20, 0, 20);
1122  fMCList[iCut]->Add(fHistoMCHeaders[iCut]);
1123  }
1124 
1125  fHistoMCMesonPt[iCut] = new TH1F("MC_Meson_Pt", "MC_Meson_Pt; p_{T} (GeV/c)",
1126  (Int_t)((maxPt-minPt)/binWidthPt), minPt, maxPt);
1127  fHistoMCMesonPt[iCut]->Sumw2();
1128  fMCList[iCut]->Add(fHistoMCMesonPt[iCut]);
1129  fHistoMCMesonWOWeightPt[iCut] = new TH1F("MC_Meson_WOWeights_Pt", "MC_Meson_WOWeights_Pt; p_{T} (GeV/c)",
1130  (Int_t)((maxPt-minPt)/binWidthPt), minPt, maxPt);
1131  fMCList[iCut]->Add(fHistoMCMesonWOWeightPt[iCut]);
1132 
1133  fHistoMCMesonInAccPt[iCut] = new TH1F("MC_MesonInAcc_Pt", "MC_MesonInAcc_Pt; p_{T} (GeV/c)",
1134  (Int_t)((maxPt-minPt)/binWidthPt), minPt, maxPt);
1135  fHistoMCMesonInAccPt[iCut]->Sumw2();
1136  fMCList[iCut]->Add(fHistoMCMesonInAccPt[iCut]);
1137  fHistoMCMesonWOWeightInAccPt[iCut] = new TH1F("MC_MesonWOWeightInAcc_Pt", "MC_MesonWOWeightInAcc_Pt; p_{T} (GeV/c)",
1138  (Int_t)((maxPt-minPt)/binWidthPt), minPt, maxPt);
1139  fMCList[iCut]->Add(fHistoMCMesonWOWeightInAccPt[iCut]);
1140 
1141  if (fIsMC > 1){
1142  fHistoMCMesonWOWeightPt[iCut]->Sumw2();
1143  fHistoMCMesonWOWeightInAccPt[iCut]->Sumw2();
1144  fHistoMCMesonWOEvtWeightPt[iCut] = new TH1F("MC_Meson_WOEventWeights_Pt", "MC_Meson_WOEventWeights_Pt; p_{T} (GeV/c)",
1145  (Int_t)((maxPt-minPt)/binWidthPt), minPt, maxPt);
1146  fMCList[iCut]->Add(fHistoMCMesonWOEvtWeightPt[iCut]);
1147  fHistoMCMesonWOEvtWeightInAccPt[iCut] = new TH1F("MC_Meson_WOEventWeightsInAcc_Pt", "MC_Meson_WOEventWeightsInAcc_Pt; p_{T} (GeV/c)",
1148  (Int_t)((maxPt-minPt)/binWidthPt), minPt, maxPt);
1149  fMCList[iCut]->Add(fHistoMCMesonWOEvtWeightInAccPt[iCut]);
1150 
1151  if (fDoMesonQA > 0 && fIsMC == 2){
1152  fHistoMCMesonPtJetPt[iCut] = new TH2F("MC_Meson_Pt_JetPt", "MC_Meson_Pt_JetPt; p_{T} (GeV/c); p_{T,jet} (GeV/c)",
1153  nBinsQAPt, arrQAPtBinning, 200, 0, 200);
1154  fHistoMCMesonPtJetPt[iCut]->Sumw2();
1155  fMCList[iCut]->Add(fHistoMCMesonPtJetPt[iCut]);
1156  }
1157  }
1158 
1159  // book additional MC QA histograms
1160  if (fDoMesonQA > 0){
1161  fHistoMCMesonPtY[iCut] = new TH2F("MC_Meson_Pt_Y", "MC_Meson_Pt_Y; p_{T} (GeV/c); Y ",
1162  nBinsQAPt, arrQAPtBinning, 150, -1.5, 1.5);
1163  fHistoMCMesonPtY[iCut]->Sumw2();
1164  fMCList[iCut]->Add(fHistoMCMesonPtY[iCut]);
1165  fHistoMCMesonPtAlpha[iCut] = new TH2F("MC_Meson_Pt_Alpha", "MC_Meson_Pt_Alpha; p_{T} (GeV/c); #alpha",
1166  nBinsQAPt, arrQAPtBinning, 200, -1, 1);
1167  fMCList[iCut]->Add(fHistoMCMesonPtAlpha[iCut]);
1168 
1169  if (fIsMC == 2){
1170  fHistoMCMesonPtAlpha[iCut]->Sumw2();
1171  }
1172  }
1173 
1174  fTrueList[iCut] = new TList();
1175  fTrueList[iCut]->SetName(Form("%s True histograms",fullCutString.Data()));
1176  fTrueList[iCut]->SetOwner(kTRUE);
1177  fCutFolder[iCut]->Add(fTrueList[iCut]);
1178 
1179  if(!fDoLightOutput){
1180  if (fMesonRecoMode < 2){
1181  fHistoTrueConvGammaPt[iCut] = new TH1F("ESD_TrueConvGamma_Pt", "ESD_TrueConvGamma_Pt; p_{T,conv} (GeV/c); counts",
1182  (Int_t)((maxPt-minPt)/binWidthPt), minPt, maxPt);
1183  fTrueList[iCut]->Add(fHistoTrueConvGammaPt[iCut]);
1184  fHistoDoubleCountTrueConvGammaRPt[iCut] = new TH2F("ESD_TrueDoubleCountConvGamma_R_Pt", "ESD_TrueDoubleCountConvGamma_R_Pt; R (cm); p_{T,conv} (GeV/c)",
1185  800, 0, 200, (Int_t)((maxPt-minPt)/binWidthPt), minPt, maxPt);
1186  fTrueList[iCut]->Add(fHistoDoubleCountTrueConvGammaRPt[iCut]);
1187  fHistoMultipleCountTrueConvGamma[iCut] = new TH1F("ESD_TrueMultipleCountConvGamma", "ESD_TrueMultipleCountConvGamma", 10, 1, 11);
1188  fTrueList[iCut]->Add(fHistoMultipleCountTrueConvGamma[iCut]);
1189  fHistoTruePrimaryConvGammaPt[iCut] = new TH1F("ESD_TruePrimaryConvGamma_Pt", "ESD_TruePrimaryConvGamma_Pt;p_{T,conv} (GeV/c); counts", (Int_t)((maxPt-minPt)/binWidthPt), minPt, maxPt);
1190  fTrueList[iCut]->Add(fHistoTruePrimaryConvGammaPt[iCut]);
1191  }
1193  fHistoTrueClusGammaPt[iCut] = new TH1F("TrueClusGamma_Pt", "ESD_TrueClusGamma_Pt; p_{T,clus} (GeV/c); counts", nBinsClusterPt, arrClusPtBinning);
1194  fTrueList[iCut]->Add(fHistoTrueClusGammaPt[iCut]);
1195  fHistoTruePrimaryClusGammaPt[iCut] = new TH1F("TruePrimaryClusGamma_Pt", "ESD_TruePrimaryClusGamma_Pt; p_{T,clus} (GeV/c); counts", nBinsClusterPt, arrClusPtBinning);
1196  fTrueList[iCut]->Add(fHistoTruePrimaryClusGammaPt[iCut]);
1197  fHistoTrueClusConvGammaPt[iCut] = new TH1F("TrueClusConvGamma_Pt", "TrueClusConvGamma_Pt; p_{T,clus} (GeV/c); counts", nBinsClusterPt, arrClusPtBinning);
1198  fTrueList[iCut]->Add(fHistoTrueClusConvGammaPt[iCut]);
1199  fHistoTruePrimaryClusConvGammaPt[iCut] = new TH1F("TruePrimaryClusConvGamma_Pt", "ESD_TruePrimaryClusConvGamma_Pt; p_{T,clus} (GeV/c); counts", nBinsClusterPt, arrClusPtBinning);
1200  fTrueList[iCut]->Add(fHistoTruePrimaryClusConvGammaPt[iCut]);
1201  fHistoDoubleCountTrueClusterGammaPt[iCut] = new TH2F("TrueDoubleCountClusterGamma_Pt", "TrueDoubleCountClusterGamma_Pt; p_{T,clus} (GeV/c); counts",
1202  nBinsClusterPt, arrClusPtBinning, 2, 0, 2);
1204  fHistoMultipleCountTrueClusterGamma[iCut] = new TH1F("TrueMultipleCountClusterGamma", "TrueMultipleCountClusterGamma", 10, 1, 11);
1206  fHistoTrueClusConvGammaFullyPt[iCut] = new TH1F("TrueClusConvGammaFullyContained_Pt", "TrueClusConvGammaFullyContained_Pt; p_{T,clus} (GeV/c); counts",
1207  nBinsClusterPt, arrClusPtBinning);
1208  fTrueList[iCut]->Add(fHistoTrueClusConvGammaFullyPt[iCut]);
1209  fHistoTrueNLabelsInClusPt[iCut] = new TH2F("TrueNLabelsInClus_Pt", "TrueNLabelsInClus_Pt; p_{T,clus} (GeV/c); counts",
1210  100, -0.5, 99.5, nBinsClusterPt, arrClusPtBinning);
1211  fTrueList[iCut]->Add(fHistoTrueNLabelsInClusPt[iCut]);
1212  }
1213  }
1214 
1215  if (fIsMC > 1){
1216  if(!fDoLightOutput){
1217  if (fMesonRecoMode < 2){
1218  fHistoTrueConvGammaPt[iCut]->Sumw2();
1219  fHistoDoubleCountTrueConvGammaRPt[iCut]->Sumw2();
1220  fHistoMultipleCountTrueConvGamma[iCut]->Sumw2();
1221  }
1223  fHistoTruePrimaryConvGammaPt[iCut]->Sumw2();
1224  }
1226  fHistoTruePrimaryClusGammaPt[iCut]->Sumw2();
1227  fHistoTrueNLabelsInClusPt[iCut]->Sumw2();
1228  fHistoTrueClusConvGammaPt[iCut]->Sumw2();
1229  fHistoTruePrimaryClusConvGammaPt[iCut]->Sumw2();
1230  fHistoTrueClusGammaPt[iCut]->Sumw2();
1231  fHistoDoubleCountTrueClusterGammaPt[iCut]->Sumw2();
1232  fHistoMultipleCountTrueClusterGamma[iCut]->Sumw2();
1233  fHistoTrueClusConvGammaFullyPt[iCut]->Sumw2();
1234  }
1235  }
1236 
1237  }
1238 
1239  fHistoTrueMesonInvMassPt[iCut] = new TH2F("ESD_TrueMeson_InvMass_Pt", "ESD_TrueMeson_InvMass_Pt;M_{inv}(GeV/c^{2});p_{T}(GeV/c)",
1240  fMesonInvMassNBins, fMesonInvMassMin, fMesonInvMassMax, nBinsPt, arrPtBinning);
1241  fHistoTrueMesonInvMassPt[iCut]->Sumw2();
1242  fTrueList[iCut]->Add(fHistoTrueMesonInvMassPt[iCut]);
1243 
1244  fHistoDoubleCountTrueMesonInvMassPt[iCut] = new TH2F("ESD_TrueDoubleCountMeson_InvMass_Pt", "ESD_TrueDoubleCountMeson_InvMass_Pt;M_{inv}(GeV/c^{2});p_{T}(GeV/c)",
1245  fMesonInvMassNBins, fMesonInvMassMin, fMesonInvMassMax, nBinsPt, arrPtBinning);
1247  fHistoMultipleCountTrueMeson[iCut] = new TH1F("ESD_TrueMultipleCountMeson", "ESD_TrueMultipleCountMeson;# number of multiple counts;#", 10, 1, 11);
1248  fHistoMultipleCountTrueMeson[iCut]->Sumw2();
1249  fTrueList[iCut]->Add(fHistoMultipleCountTrueMeson[iCut]);
1250 
1251  fHistoTruePrimaryMesonInvMassPt[iCut] = new TH2F("ESD_TruePrimaryMeson_InvMass_Pt", "ESD_TruePrimaryMeson_InvMass_Pt;M_{inv}(GeV/c^{2});p_{T}(GeV/c)",
1252  fMesonInvMassNBins, fMesonInvMassMin, fMesonInvMassMax, nBinsPt, arrPtBinning);
1253  fHistoTruePrimaryMesonInvMassPt[iCut]->Sumw2();
1254  fTrueList[iCut]->Add(fHistoTruePrimaryMesonInvMassPt[iCut]);
1255 
1256  fHistoTruePrimaryMesonW0WeightingInvMassPt[iCut] = new TH2F("ESD_TruePrimaryMesonW0Weights_InvMass_Pt",
1257  "ESD_TruePrimaryMesonW0Weights_InvMass_Pt;M_{inv}(GeV/c^{2});p_{T}(GeV/c)",
1258  fMesonInvMassNBins, fMesonInvMassMin, fMesonInvMassMax, nBinsPt, arrPtBinning);
1260 
1261  fProfileTruePrimaryMesonWeightsInvMassPt[iCut] = new TProfile2D("ESD_TruePrimaryMesonWeights_InvMass_Pt",
1262  "ESD_TruePrimaryMesonWeights_InvMass_Pt;M_{inv}(GeV/c^{2});p_{T}(GeV/c)",
1263  fMesonInvMassNBins, fMesonInvMassMin, fMesonInvMassMax, nBinsPt, arrPtBinning);
1266 
1267  if (fMesonRecoMode == 1){
1268  fHistoTrueMesonMatchedInvMassPt[iCut] = new TH2F("ESD_TrueMeson_Matched_InvMass_Pt", "ESD_TrueMeson_Matched_InvMass_Pt;M_{inv}(GeV/c^{2});p_{T}(GeV/c)",
1269  fMesonInvMassNBins, fMesonInvMassMin, fMesonInvMassMax, nBinsPt, arrPtBinning);
1270  fHistoTrueMesonMatchedInvMassPt[iCut]->Sumw2();
1271  fTrueList[iCut]->Add(fHistoTrueMesonMatchedInvMassPt[iCut]);
1272  }
1273 
1274  if (fIsMC > 1){
1276  }
1277 
1278  if (fDoMesonQA > 0){
1279  if (fIsMC < 2){
1280  if (fMesonRecoMode > 0){
1281  fHistoTrueMesonCaloPhotonInvMassPt[iCut] = new TH2F( "ESD_TrueMesonCaloPhoton_InvMass_Pt",
1282  "ESD_TrueMesonCaloPhoton_InvMass_Pt; M_{inv}(GeV/c^{2}) #gamma #gamma;p_{T}(GeV/c) ",
1283  fMesonInvMassNBins, fMesonInvMassMin, fMesonInvMassMax, nBinsPt, arrPtBinning);
1285  fHistoTrueMesonCaloConvertedPhotonInvMassPt[iCut] = new TH2F( "ESD_TrueMesonCaloConvertedPhoton_InvMass_Pt",
1286  "ESD_TrueMesonCaloConvertedPhoton_InvMass_Pt;M_{inv}(GeV/c^{2}) #gamma #gamma_{conv};p_{T}(GeV/c)",
1287  fMesonInvMassNBins, fMesonInvMassMin, fMesonInvMassMax, nBinsPt, arrPtBinning);
1289  fHistoTrueMesonCaloElectronInvMassPt[iCut] = new TH2F("ESD_TrueMesonCaloElectron_InvMass_Pt",
1290  "ESD_TrueMesonCaloElectron_InvMass_Pt; M_{inv}(GeV/c^{2}) #gamma e^{#pm}; ; p_{T}(GeV/c)",
1291  fMesonInvMassNBins, fMesonInvMassMin, fMesonInvMassMax, nBinsPt, arrPtBinning);
1293  fHistoTrueMesonCaloMergedClusterInvMassPt[iCut] = new TH2F("ESD_TrueMesonCaloMergedCluster_InvMass_Pt",
1294  "ESD_TrueMesonCaloMergedCluster_InvMass_Pt; M_{inv}(GeV/c^{2}) #gamma merged cluster; p_{T}(GeV/c)",
1295  fMesonInvMassNBins, fMesonInvMassMin, fMesonInvMassMax, nBinsPt, arrPtBinning);
1297  fHistoTrueMesonCaloMergedClusterPartConvInvMassPt[iCut] = new TH2F( "ESD_TrueMesonCaloMergedClusterPartConv_InvMass_Pt",
1298  "ESD_TrueMesonCaloMergedClusterPartConv_InvMass_Pt; M_{inv}(GeV/c^{2}) #gamma merged cluster, part conv; p_{T}(GeV/c)",
1299  fMesonInvMassNBins, fMesonInvMassMin, fMesonInvMassMax, nBinsPt, arrPtBinning);
1301  }
1302  if (fMesonRecoMode == 1){
1303  fHistoTrueMesonCaloConvertedPhotonMatchedInvMassPt[iCut] = new TH2F("ESD_TrueMesonCaloConvertedPhotonMatched_InvMass_Pt",
1304  "ESD_TrueMesonCaloConvertedPhotonMatched_InvMass_Pt;M_{inv}(GeV/c^{2}) #gamma #gamma_{conv,matched};p_{T}(GeV/c)",
1305  fMesonInvMassNBins, fMesonInvMassMin, fMesonInvMassMax, nBinsPt, arrPtBinning);
1307  fHistoTrueMotherMesonConvPhotonEtaPhi[iCut] = new TH2F("ESD_TrueMotherMesonConvPhoton_Eta_Phi", "conv photons for true ; #phi_{#gamma_{conv}}(rad);#eta_{#gamma_{conv}}",
1308  600, 0, 2*TMath::Pi(), 200, -1, 1);
1310  }
1311  if (fMesonRecoMode == 2){
1312  fHistoTrueMesonCaloMixedPhotonConvPhotonInvMassPt[iCut] = new TH2F("ESD_TrueMesonCaloMixedPhotonConvertedPhoton_InvMass_Pt",
1313  "ESD_TrueMesonCaloMixedPhotonConvertedPhoton_InvMass_Pt;M_{inv}(GeV/c^{2}) #gamma #gamma_{conv,matched};p_{T}(GeV/c)",
1314  fMesonInvMassNBins, fMesonInvMassMin, fMesonInvMassMax, nBinsPt, arrPtBinning);
1316  }
1317  fHistoTruePrimaryMesonMCPtResolPt[iCut] = new TH2F("ESD_TruePrimaryMeson_MCPt_ResolPt",
1318  "ESD_TruePrimaryMeson_ResolPt_MCPt; p_{T,MC}(GeV/c); (p_{T,rec}-p_{T,MC})/p_{T,MC}()",
1319  500, 0.03, 25, 1000, -1., 1.);
1320  fHistoTruePrimaryMesonMCPtResolPt[iCut]->Sumw2();
1322  fTrueList[iCut]->Add(fHistoTruePrimaryMesonMCPtResolPt[iCut]);
1323  }
1324  if(fDoMesonQA>1){
1325  fHistoTrueBckGGInvMassPt[iCut] = new TH2F("ESD_TrueBckGG_InvMass_Pt",
1326  "ESD_TrueBckGG_InvMass_Pt; M_{inv} (GeV/c^{2}) #gamma #gamma no signal; #pair p_{T}(GeV/c)",
1327  fMesonInvMassNBins, fMesonInvMassMin, fMesonInvMassMax, nBinsPt, arrPtBinning);
1328  fTrueList[iCut]->Add(fHistoTrueBckGGInvMassPt[iCut]);
1329  fHistoTrueBckFullMesonContainedInOneClusterInvMassPt[iCut] = new TH2F( "ESD_TrueBckFullMesonContained_InvMass_Pt",
1330  "ESD_TrueBckFullMesonContained_InvMass_Pt; M_{inv} (GeV/c^{2}) #gamma #gamma, calo gamma with full pi0; #pair p_{T}(GeV/c)",
1331  fMesonInvMassNBins, fMesonInvMassMin, fMesonInvMassMax, nBinsPt, arrPtBinning);
1333  fHistoTrueBckAsymEClustersInvMassPt[iCut] = new TH2F("ESD_TrueBckAsymEClus_InvMass_Pt",
1334  "ESD_TrueBckAsymEClus_InvMass_Pt; M_{inv} (GeV/c^{2}) #gamma #gamma, calo gamma >70% of pi0 energy; #pair p_{T}(GeV/c)",
1335  fMesonInvMassNBins, fMesonInvMassMin, fMesonInvMassMax, nBinsPt, arrPtBinning);
1337  fHistoTrueBckContInvMassPt[iCut] = new TH2F("ESD_TrueBckCont_InvMass_Pt",
1338  "ESD_TrueBckCont_InvMass_Pt; M_{inv} (GeV/c^{2}) contamination; #pair p_{T}(GeV/c)",
1339  fMesonInvMassNBins, fMesonInvMassMin, fMesonInvMassMax, nBinsPt, arrPtBinning);
1340  fTrueList[iCut]->Add(fHistoTrueBckContInvMassPt[iCut]);
1341  }
1342  fHistoTrueMesonPtY[iCut] = new TH2F("ESD_TrueMeson_Pt_Y", "ESD_TrueMeson_Pt_Y; p_{T}(GeV/c); Y",
1343  nBinsQAPt, arrQAPtBinning, 150, -1.5, 1.5);
1344  fTrueList[iCut]->Add(fHistoTrueMesonPtY[iCut]);
1345  fHistoTrueMesonPtAlpha[iCut] = new TH2F("ESD_TrueMeson_Pt_Alpha", "ESD_TrueMeson_Pt_Alpha; p_{T}(GeV/c); #alpha",
1346  nBinsQAPt, arrQAPtBinning, 200, -1, 1);
1347  fTrueList[iCut]->Add(fHistoTrueMesonPtAlpha[iCut]);
1348  fHistoTrueMesonPtOpenAngle[iCut] = new TH2F("ESD_TrueMeson_Pt_OpenAngle", "ESD_TrueMeson_Pt_OpenAngle; p_{T}(GeV/c); #theta",
1349  nBinsQAPt, arrQAPtBinning, 100, 0, 1);
1350  fTrueList[iCut]->Add(fHistoTrueMesonPtOpenAngle[iCut]);
1351 
1352  if (fIsMC > 1){
1353  if(fDoMesonQA>1){
1354  fHistoTrueBckGGInvMassPt[iCut]->Sumw2();
1356  fHistoTrueBckAsymEClustersInvMassPt[iCut]->Sumw2();
1357  fHistoTrueBckContInvMassPt[iCut]->Sumw2();
1358  }
1359  fHistoTrueMesonPtY[iCut]->Sumw2();
1360  fHistoTrueMesonPtAlpha[iCut]->Sumw2();
1361  fHistoTrueMesonPtOpenAngle[iCut]->Sumw2();
1363  }
1364  }
1365  }
1366  }
1367 
1371 
1375 
1376  fVectorRecTrueMesons.clear();
1377 
1378  if(fV0Reader)
1380  if(((AliConversionPhotonCuts*)fV0Reader->GetConversionCuts())->GetCutHistograms())
1381  fOutputContainer->Add(((AliConversionPhotonCuts*)fV0Reader->GetConversionCuts())->GetCutHistograms());
1382  if(fV0Reader)
1384  if(((AliConvEventCuts*)fV0Reader->GetEventCuts())->GetCutHistograms())
1385  fOutputContainer->Add(((AliConvEventCuts*)fV0Reader->GetEventCuts())->GetCutHistograms());
1386 
1390 
1391  for(Int_t iMatcherTask = 0; iMatcherTask < 3; iMatcherTask++){
1392  AliCaloTrackMatcher* temp = (AliCaloTrackMatcher*) (AliAnalysisManager::GetAnalysisManager()->GetTask(Form("CaloTrackMatcher_%i",iMatcherTask)));
1393  if(temp) fOutputContainer->Add(temp->GetCaloTrackMatcherHistograms());
1394  }
1395 
1396  for(Int_t iCut = 0; iCut<fnCuts;iCut++){
1397  if(!((AliConvEventCuts*)fEventCutArray->At(iCut))) continue;
1398  if(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetCutHistograms()){
1399  fCutFolder[iCut]->Add(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetCutHistograms());
1400  }
1401  if (fMesonRecoMode < 2){
1402  if(!((AliConversionPhotonCuts*)fCutArray->At(iCut))) continue;
1403  if(((AliConversionPhotonCuts*)fCutArray->At(iCut))->GetCutHistograms()){
1404  fCutFolder[iCut]->Add(((AliConversionPhotonCuts*)fCutArray->At(iCut))->GetCutHistograms());
1405  }
1406  }
1408  if(!((AliCaloPhotonCuts*)fClusterCutArray->At(iCut))) continue;
1409  if(((AliCaloPhotonCuts*)fClusterCutArray->At(iCut))->GetCutHistograms()){
1410  fCutFolder[iCut]->Add(((AliCaloPhotonCuts*)fClusterCutArray->At(iCut))->GetCutHistograms());
1411  }
1412  if(fSetPlotHistsExtQA){
1413  if(!((AliCaloPhotonCuts*)fClusterCutArray->At(iCut))) continue;
1414  if(((AliCaloPhotonCuts*)fClusterCutArray->At(iCut))->GetExtQAHistograms()){
1415  fCutFolder[iCut]->Add(((AliCaloPhotonCuts*)fClusterCutArray->At(iCut))->GetExtQAHistograms());
1416  }
1417  }
1418  }
1419  if(!((AliConversionMesonCuts*)fMesonCutArray->At(iCut))) continue;
1420  if(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetCutHistograms()){
1421  fCutFolder[iCut]->Add(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetCutHistograms());
1422  }
1423  }
1424 
1425  if (fIsMC > 0){
1426  fTreeBrokenFiles = new TTree("BrokenFiles", "BrokenFiles");
1427  fTreeBrokenFiles->Branch("fileName",&fFileNameBroken);
1429  }
1430 
1431  PostData(1, fOutputContainer);
1432 }
1433 //_____________________________________________________________________________
1435 
1436  for(Int_t iCut = 0; iCut<fnCuts;iCut++){
1437  if (((AliConvEventCuts*)fEventCutArray->At(iCut))->GetPeriodEnum() == AliConvEventCuts::kNoPeriod && ((AliConvEventCuts*)fV0Reader->GetEventCuts())->GetPeriodEnum() != AliConvEventCuts::kNoPeriod){
1438  ((AliConvEventCuts*)fEventCutArray->At(iCut))->SetPeriodEnumExplicit(((AliConvEventCuts*)fV0Reader->GetEventCuts())->GetPeriodEnum());
1439  } else if (((AliConvEventCuts*)fEventCutArray->At(iCut))->GetPeriodEnum() == AliConvEventCuts::kNoPeriod ){
1440  ((AliConvEventCuts*)fEventCutArray->At(iCut))->SetPeriodEnum(fV0Reader->GetPeriodName());
1441  }
1442 
1443  if(fIsHeavyIon == 2){
1444  if(!((AliConvEventCuts*)fEventCutArray->At(iCut))->GetDoEtaShift()){
1445  fProfileEtaShift[iCut]->Fill(0.,(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetEtaShift()));
1446  continue; // No Eta Shift requested, continue
1447  }
1448  if(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetEtaShift() == 0.0){ // Eta Shift requested but not set, get shift automatically
1449  ((AliConvEventCuts*)fEventCutArray->At(iCut))->GetCorrectEtaShiftFromPeriod();
1450  fProfileEtaShift[iCut]->Fill(0.,(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetEtaShift()));
1451  ((AliConvEventCuts*)fEventCutArray->At(iCut))->DoEtaShift(kFALSE); // Eta Shift Set, make sure that it is called only once
1452  continue;
1453  } else{
1454  printf(" Gamma Conversion Task %s :: Eta Shift Manually Set to %f \n\n",
1455  (((AliConvEventCuts*)fEventCutArray->At(iCut))->GetCutNumber()).Data(),((AliConvEventCuts*)fEventCutArray->At(iCut))->GetEtaShift());
1456  fProfileEtaShift[iCut]->Fill(0.,(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetEtaShift()));
1457  ((AliConvEventCuts*)fEventCutArray->At(iCut))->DoEtaShift(kFALSE); // Eta Shift Set, make sure that it is called only once
1458  }
1459  }
1460  }
1461 
1462  return kTRUE;
1463 }
1464 //_____________________________________________________________________________
1466  //
1467  // Called for each event
1468  //
1469  fInputEvent = InputEvent();
1470 
1471  if(fIsMC > 0) fMCEvent = MCEvent();
1472 
1473  Int_t eventQuality = ((AliConvEventCuts*)fV0Reader->GetEventCuts())->GetEventQuality();
1474  if(fInputEvent->IsIncompleteDAQ()==kTRUE) eventQuality = 2;// incomplete event
1475  // Event Not Accepted due to MC event missing or wrong trigger for V0ReaderV1 or because it is incomplete => abort processing of this event/file
1476  if(eventQuality == 2 || eventQuality == 3){
1477  // write out name of broken file for first event
1478  if (fIsMC > 0){
1479  if (fInputEvent->IsA()==AliESDEvent::Class()){
1480  if (((AliESDEvent*)fInputEvent)->GetEventNumberInFile() == 0){
1481  fFileNameBroken = new TObjString(Form("%s",((TString)fV0Reader->GetCurrentFileName()).Data()));
1482  if (fTreeBrokenFiles) fTreeBrokenFiles->Fill();
1483  delete fFileNameBroken;
1484  }
1485  }
1486  }
1487 
1488  for(Int_t iCut = 0; iCut<fnCuts; iCut++){
1489  fHistoNEvents[iCut]->Fill(eventQuality);
1490  if (fIsMC > 1) fHistoNEventsWOWeight[iCut]->Fill(eventQuality);
1491  }
1492  return;
1493  }
1494 
1495 // if(fInputEvent->IsA()==AliAODEvent::Class()){
1496 // fInputEvent->InitMagneticField();
1497 // }
1498 
1499  fReaderGammas = fV0Reader->GetReconstructedGammas(); // Gammas from default Cut
1500 
1501  // ------------------- BeginEvent ----------------------------
1502  AliEventplane *EventPlane = fInputEvent->GetEventplane();
1503  if(fIsHeavyIon ==1)fEventPlaneAngle = EventPlane->GetEventplane("V0",fInputEvent,2);
1504  else fEventPlaneAngle=0.0;
1505 
1506  if(fIsMC>0 && fInputEvent->IsA()==AliAODEvent::Class() && !(fV0Reader->AreAODsRelabeled()) && fMesonRecoMode < 2){
1507  RelabelAODPhotonCandidates(kTRUE);// In case of AODMC relabeling MC
1508  fV0Reader->RelabelAODs(kTRUE);
1509  }
1510 
1511  for(Int_t iCut = 0; iCut<fnCuts; iCut++){
1512 
1513  fiCut = iCut;
1514  Bool_t isRunningEMCALrelAna = kFALSE;
1516  if (((AliCaloPhotonCuts*)fClusterCutArray->At(fiCut))->GetClusterType() == 1) isRunningEMCALrelAna = kTRUE;
1517  }
1518 
1519  Int_t eventNotAccepted = ((AliConvEventCuts*)fEventCutArray->At(iCut))->IsEventAcceptedByCut(fV0Reader->GetEventCuts(),fInputEvent,fMCEvent,fIsHeavyIon,isRunningEMCALrelAna);
1520 
1521  if(fIsMC==2){
1522  Float_t xsection = -1.;
1523  Float_t ntrials = -1.;
1524  ((AliConvEventCuts*)fEventCutArray->At(iCut))->GetXSectionAndNTrials(fMCEvent,xsection,ntrials,fInputEvent);
1525  if((xsection==-1.) || (ntrials==-1.)) AliFatal(Form("ERROR: GetXSectionAndNTrials returned invalid xsection/ntrials, periodName from V0Reader: '%s'",fV0Reader->GetPeriodName().Data()));
1526  fProfileJetJetXSection[iCut]->Fill(0.,xsection);
1527  fHistoJetJetNTrials[iCut]->Fill("#sum{NTrials}",ntrials);
1528  }
1529 
1530  if(fIsMC>0){
1531  fWeightJetJetMC = 1;
1532  // cout << fMCEvent << endl;
1533  Bool_t isMCJet = ((AliConvEventCuts*)fEventCutArray->At(iCut))->IsJetJetMCEventAccepted( fMCEvent, fWeightJetJetMC, fInputEvent );
1534  if (fIsMC == 3){
1535  Double_t weightMult = ((AliConvEventCuts*)fEventCutArray->At(iCut))->GetWeightForMultiplicity(fV0Reader->GetNumberOfPrimaryTracks());
1536  fWeightJetJetMC = fWeightJetJetMC*weightMult;
1537  }
1538  if(fIsMC==1) fWeightJetJetMC = 1;
1539  if (!isMCJet){
1540  fHistoNEvents[iCut]->Fill(10,fWeightJetJetMC);
1541  if (fIsMC>1) fHistoNEventsWOWeight[iCut]->Fill(10);
1542  continue;
1543  }
1544  }
1545 
1546  Bool_t triggered = kTRUE;
1547 
1548  if(eventNotAccepted!= 0){
1549  // cout << "event rejected due to wrong trigger: " <<eventNotAccepted << endl;
1550  fHistoNEvents[iCut]->Fill(eventNotAccepted, fWeightJetJetMC); // Check Centrality, PileUp, SDD and V0AND --> Not Accepted => eventQuality = 1
1551  if (fIsMC>1) fHistoNEventsWOWeight[iCut]->Fill(eventNotAccepted);
1552  if (eventNotAccepted==3 && fIsMC > 0){
1553  triggered = kFALSE;
1554  }else {
1555  continue;
1556  }
1557  }
1558 
1559  if(eventQuality != 0){// Event Not Accepted
1560  //cout << "event rejected due to: " <<eventQuality << endl;
1561  fHistoNEvents[iCut]->Fill(eventQuality, fWeightJetJetMC);
1562  if (fIsMC>1) fHistoNEventsWOWeight[iCut]->Fill(eventQuality);
1563  continue;
1564  }
1565 
1566  if (triggered==kTRUE){
1567  fHistoNEvents[iCut]->Fill(eventQuality, fWeightJetJetMC); // Should be 0 here
1568  if (fIsMC>1) fHistoNEventsWOWeight[iCut]->Fill(eventQuality); // Should be 0 here
1569 
1571  fHistoVertexZ[iCut]->Fill(fInputEvent->GetPrimaryVertex()->GetZ(), fWeightJetJetMC);
1572  if(!fDoLightOutput){
1573  fHistoVertexX[iCut]->Fill(fInputEvent->GetPrimaryVertex()->GetX(), fWeightJetJetMC);
1574  fHistoVertexY[iCut]->Fill(fInputEvent->GetPrimaryVertex()->GetY(), fWeightJetJetMC);
1575  fHistoSPDClusterTrackletBackground[iCut]->Fill(fInputEvent->GetMultiplicity()->GetNumberOfTracklets(),(fInputEvent->GetNumberOfITSClusters(0)+fInputEvent->GetNumberOfITSClusters(1)),fWeightJetJetMC);
1576  if(((AliConvEventCuts*)fEventCutArray->At(iCut))->IsHeavyIon() == 2) fHistoNV0Tracks[iCut]->Fill(fInputEvent->GetVZEROData()->GetMTotV0A(), fWeightJetJetMC);
1577  else fHistoNV0Tracks[iCut]->Fill(fInputEvent->GetVZEROData()->GetMTotV0A()+fInputEvent->GetVZEROData()->GetMTotV0C(), fWeightJetJetMC);
1578  }
1579  }
1580 
1581  if(fIsMC>0){
1582  // Process MC Particle
1583  if(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetSignalRejection() != 0){
1584  if(fInputEvent->IsA()==AliESDEvent::Class()){
1585  ((AliConvEventCuts*)fEventCutArray->At(iCut))->GetNotRejectedParticles(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetSignalRejection(),
1586  ((AliConvEventCuts*)fEventCutArray->At(iCut))->GetAcceptedHeader(),
1587  fMCEvent);
1588  }
1589  else if(fInputEvent->IsA()==AliAODEvent::Class()){
1590  ((AliConvEventCuts*)fEventCutArray->At(iCut))->GetNotRejectedParticles(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetSignalRejection(),
1591  ((AliConvEventCuts*)fEventCutArray->At(iCut))->GetAcceptedHeader(),
1592  fInputEvent);
1593  }
1594 
1595  if(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetAcceptedHeader()){
1596  for(Int_t i = 0;i<(((AliConvEventCuts*)fEventCutArray->At(iCut))->GetAcceptedHeader())->GetEntries();i++){
1597  TString nameBin= fHistoMCHeaders[iCut]->GetXaxis()->GetBinLabel(i+1);
1598  if (nameBin.CompareTo("")== 0){
1599  TString nameHeader = ((TObjString*)((TList*)((AliConvEventCuts*)fEventCutArray->At(iCut))
1600  ->GetAcceptedHeader())->At(i))->GetString();
1601  fHistoMCHeaders[iCut]->GetXaxis()->SetBinLabel(i+1,nameHeader.Data());
1602  }
1603  }
1604  }
1605  }
1606  }
1607  if(fIsMC>0){
1608  if(fInputEvent->IsA()==AliESDEvent::Class())
1610  if(fInputEvent->IsA()==AliAODEvent::Class())
1612  }
1613 
1614  if (triggered==kFALSE) continue;
1615 
1616  // it is in the loop to have the same conversion cut string (used also for MC stuff that should be same for V0 and Cluster)
1617  if (fMesonRecoMode > 0 || fEnableClusterCutsForTrigger) // process calo clusters
1618  ProcessClusters();
1619  if (fMesonRecoMode < 2) // Process this cuts gammas
1621 
1622  if (fMesonRecoMode < 2) fHistoNGammaConvCandidates[iCut]->Fill(fGammaCandidates->GetEntries(),fWeightJetJetMC);
1624 
1625  if (fMesonRecoMode < 2){
1626  if(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->UseMCPSmearing() && fIsMC>0){
1627  fUnsmearedPx = new Double_t[fGammaCandidates->GetEntries()]; // Store unsmeared Momenta
1628  fUnsmearedPy = new Double_t[fGammaCandidates->GetEntries()];
1629  fUnsmearedPz = new Double_t[fGammaCandidates->GetEntries()];
1630  fUnsmearedE = new Double_t[fGammaCandidates->GetEntries()];
1631 
1632  for(Int_t gamma=0;gamma<fGammaCandidates->GetEntries();gamma++){ // Smear the AODPhotons in MC
1633  fUnsmearedPx[gamma] = ((AliAODConversionPhoton*)fGammaCandidates->At(gamma))->Px();
1634  fUnsmearedPy[gamma] = ((AliAODConversionPhoton*)fGammaCandidates->At(gamma))->Py();
1635  fUnsmearedPz[gamma] = ((AliAODConversionPhoton*)fGammaCandidates->At(gamma))->Pz();
1636  fUnsmearedE[gamma] = ((AliAODConversionPhoton*)fGammaCandidates->At(gamma))->E();
1637  ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->SmearParticle(dynamic_cast<AliAODConversionPhoton*>(fGammaCandidates->At(gamma)));
1638  }
1639  }
1640  }
1641 
1642  // check gamma gamma pairs and veto if necessary
1643  if (!((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetAcceptMassFlag())
1644  SetPhotonVeto();
1645 
1646  CalculateMesonCandidates(); // Combine Gammas from conversion and from calo
1647 
1648  if(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->DoBGCalculation()){
1649  if(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->BackgroundHandlerType() == 0){
1650  CalculateBackground(); // Combinatorial Background
1651  UpdateEventByEventData(); // Store Event for mixed Events
1652  } else{
1653  CalculateBackgroundRP(); // Combinatorial Background
1654  fBGHandlerRP[iCut]->AddEvent(fGammaCandidates,fInputEvent); // Store Event for mixed Events
1655  fBGClusHandlerRP[iCut]->AddEvent(fClusterCandidates,fInputEvent); // Store Event for mixed Events
1656  }
1657  }
1658 
1659  if (fMesonRecoMode < 2){
1660  if(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->UseMCPSmearing() && fIsMC>0){
1661  for(Int_t gamma=0;gamma<fGammaCandidates->GetEntries();gamma++){ // Smear the AODPhotons in MC
1662  ((AliAODConversionPhoton*)fGammaCandidates->At(gamma))->SetPx(fUnsmearedPx[gamma]); // Reset Unsmeared Momenta
1663  ((AliAODConversionPhoton*)fGammaCandidates->At(gamma))->SetPy(fUnsmearedPy[gamma]);
1664  ((AliAODConversionPhoton*)fGammaCandidates->At(gamma))->SetPz(fUnsmearedPz[gamma]);
1665  ((AliAODConversionPhoton*)fGammaCandidates->At(gamma))->SetE(fUnsmearedE[gamma]);
1666  }
1667  delete[] fUnsmearedPx; fUnsmearedPx = 0x0;
1668  delete[] fUnsmearedPy; fUnsmearedPy = 0x0;
1669  delete[] fUnsmearedPz; fUnsmearedPz = 0x0;
1670  delete[] fUnsmearedE;fUnsmearedE = 0x0;
1671  }
1672  }
1673 
1674  if(fIsMC>0){
1675  fVectorRecTrueMesons.clear();
1682  }
1683 
1684  fGammaCandidates->Clear(); // delete this cuts good gammas
1685  fClusterCandidates->Clear(); // delete cluster candidates
1686  }
1687 
1688  if(fIsMC>0 && fInputEvent->IsA()==AliAODEvent::Class() && !(fV0Reader->AreAODsRelabeled()) && fMesonRecoMode < 2){
1689  RelabelAODPhotonCandidates(kFALSE); // Back to ESDMC Label
1690  fV0Reader->RelabelAODs(kFALSE);
1691  }
1692 
1693  PostData(1, fOutputContainer);
1694 }
1695 
1696 //________________________________________________________________________
1698  Int_t nclus = 0;
1699  TClonesArray * arrClustersProcess = NULL;
1700  if(!fCorrTaskSetting.CompareTo("")){
1701  nclus = fInputEvent->GetNumberOfCaloClusters();
1702  } else {
1703  arrClustersProcess = dynamic_cast<TClonesArray*>(fInputEvent->FindListObject(Form("%sClustersBranch",fCorrTaskSetting.Data())));
1704  if(!arrClustersProcess)
1705  AliFatal(Form("%sClustersBranch was not found in AliAnalysisTaskHeavyNeutralMesonToGG! Check the correction framework settings!",fCorrTaskSetting.Data()));
1706  nclus = arrClustersProcess->GetEntries();
1707  }
1708 
1709  // cout << nclus << endl;
1710 
1711  if(nclus == 0) return;
1712 
1713  // plotting histograms on cell/tower level, only if extendedMatchAndQA > 1
1714  ((AliCaloPhotonCuts*)fClusterCutArray->At(fiCut))->FillHistogramsExtendedQA(fInputEvent,fIsMC);
1715 
1716  // match tracks to clusters
1717  if(fDoPrimaryTrackMatching) ((AliCaloPhotonCuts*)fClusterCutArray->At(fiCut))->MatchTracksToClusters(fInputEvent,fWeightJetJetMC,kFALSE);
1718 
1719  // vertex
1720  Double_t vertex[3] = {0,0,0};
1721  InputEvent()->GetPrimaryVertex()->GetXYZ(vertex);
1722 
1723  // Loop over EMCal clusters
1724  for(Int_t i = 0; i < nclus; i++){
1725  AliVCluster* clus = NULL;
1726  if(fInputEvent->IsA()==AliESDEvent::Class()){
1727  if(arrClustersProcess)
1728  clus = new AliESDCaloCluster(*(AliESDCaloCluster*)arrClustersProcess->At(i));
1729  else
1730  clus = new AliESDCaloCluster(*(AliESDCaloCluster*)fInputEvent->GetCaloCluster(i));
1731  } else if(fInputEvent->IsA()==AliAODEvent::Class()){
1732  if(arrClustersProcess)
1733  clus = new AliAODCaloCluster(*(AliAODCaloCluster*)arrClustersProcess->At(i));
1734  else
1735  clus = new AliAODCaloCluster(*(AliAODCaloCluster*)fInputEvent->GetCaloCluster(i));
1736  }
1737 
1738  if (!clus) continue;
1739  if(!((AliCaloPhotonCuts*)fClusterCutArray->At(fiCut))->ClusterIsSelected(clus,fInputEvent,fMCEvent,fIsMC,fWeightJetJetMC,i)){
1740  delete clus;
1741  continue;
1742  }
1743 
1744  // TLorentzvector with cluster
1745  TLorentzVector clusterVector;
1746  clus->GetMomentum(clusterVector,vertex);
1747 
1748  TLorentzVector* tmpvec = new TLorentzVector();
1749  tmpvec->SetPxPyPzE(clusterVector.Px(),clusterVector.Py(),clusterVector.Pz(),clusterVector.E());
1750 
1751  // convert to AODConversionPhoton
1752  AliAODConversionPhoton *PhotonCandidate = new AliAODConversionPhoton(tmpvec);
1753  if(!PhotonCandidate){ delete clus; delete tmpvec; continue;}
1754 
1755  // Flag Photon as CaloPhoton
1756  PhotonCandidate->SetIsCaloPhoton();
1757  PhotonCandidate->SetCaloClusterRef((Long_t)i);
1758  PhotonCandidate->SetLeadingCellID(((AliCaloPhotonCuts*)fClusterCutArray->At(fiCut))->FindLargestCellInCluster(clus,fInputEvent));
1759 
1760  // get MC label
1761  if(fIsMC>0){
1762  PhotonCandidate->SetNCaloPhotonMCLabels(clus->GetNLabels());
1763  Int_t* mclabelsCluster = clus->GetLabels();
1764  PhotonCandidate->SetNCaloPhotonMCLabels(clus->GetNLabels());
1765  // cout << clus->GetNLabels() << endl;
1766  if (clus->GetNLabels()>0){
1767  for (Int_t k =0; k<(Int_t)clus->GetNLabels(); k++){
1768  if (k<50)PhotonCandidate->SetCaloPhotonMCLabel(k,mclabelsCluster[k]);
1769  // Int_t pdgCode = fMCEvent->Particle(mclabelsCluster[k])->GetPdgCode();
1770  // cout << "label " << k << "\t" << mclabelsCluster[k] << " pdg code: " << pdgCode << endl;
1771  }
1772  }
1773  }
1774 
1775  fIsFromDesiredHeader = kTRUE;
1777  //TString periodName = fV0Reader->GetPeriodName();
1778  // test whether largest contribution to cluster orginates in added signals
1779  if (fIsMC>0 && ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetSignalRejection() > 0){
1780  if (((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetCaloPhotonMCLabel(0), fMCEvent, fInputEvent) == 0){
1781  fIsFromDesiredHeader = kFALSE;
1782  }
1783  if (clus->GetNLabels()>1){
1784  Int_t* mclabelsCluster = clus->GetLabels();
1785  for (Int_t l = 1; l < (Int_t)clus->GetNLabels(); l++ ){
1786  if (((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(mclabelsCluster[l], fMCEvent, fInputEvent) == 0){
1788  }
1789  }
1790  }
1791  }
1793  fHistoClusAllHeadersGammaPt[fiCut]->Fill(PhotonCandidate->Pt(),fWeightJetJetMC);
1795  fHistoClusRejectedHeadersGammaPt[fiCut]->Fill(PhotonCandidate->Pt(),fWeightJetJetMC);
1797  fHistoClusOverlapHeadersGammaPt[fiCut]->Fill(PhotonCandidate->Pt(),fWeightJetJetMC);
1798 
1800  fHistoClusGammaPt[fiCut]->Fill(PhotonCandidate->Pt(),fWeightJetJetMC);
1801  fHistoClusGammaE[fiCut]->Fill(PhotonCandidate->E(),fWeightJetJetMC);
1802  if(fIsMC>0){
1803  if(fInputEvent->IsA()==AliESDEvent::Class()){
1804  ProcessTrueClusterCandidates(PhotonCandidate,clus->GetM02());
1805  }else {
1806  ProcessTrueClusterCandidatesAOD(PhotonCandidate,clus->GetM02());
1807  }
1808  }
1809  fClusterCandidates->Add(PhotonCandidate); // if no second loop is required add to events good gammas
1810  }else{
1811  delete PhotonCandidate;
1812  }
1813 
1814  delete clus;
1815  delete tmpvec;
1816  }
1817 }
1818 
1819 //________________________________________________________________________
1821 
1822  TParticle *Photon = NULL;
1823  if (!TruePhotonCandidate->GetIsCaloPhoton()) AliFatal("CaloPhotonFlag has not been set task will abort");
1824  if (TruePhotonCandidate->GetCaloPhotonMCLabel(0) < 0) return;
1825  if(!fDoLightOutput) fHistoTrueNLabelsInClusPt[fiCut]->Fill(TruePhotonCandidate->GetNCaloPhotonMCLabels(),TruePhotonCandidate->Pt(),fWeightJetJetMC);
1826 
1827  if (TruePhotonCandidate->GetNCaloPhotonMCLabels()>0)Photon = fMCEvent->Particle(TruePhotonCandidate->GetCaloPhotonMCLabel(0));
1828  else return;
1829 
1830  if(Photon == NULL){
1831  // cout << "no photon" << endl;
1832  return;
1833  }
1834 
1835  TruePhotonCandidate->SetCaloPhotonMCFlags(fMCEvent, fEnableSortForClusMC);
1836 
1837  const AliVVertex* primVtxMC = fMCEvent->GetPrimaryVertex();
1838  Double_t mcProdVtxX = primVtxMC->GetX();
1839  Double_t mcProdVtxY = primVtxMC->GetY();
1840  Double_t mcProdVtxZ = primVtxMC->GetZ();
1841  Bool_t isPrimary = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsConversionPrimaryESD( fMCEvent, TruePhotonCandidate->GetCaloPhotonMCLabel(0), mcProdVtxX, mcProdVtxY, mcProdVtxZ);
1842 
1843  // to get primary distrinction right put mother of conversion electron as particle to check
1844  if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion())
1845  isPrimary = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsConversionPrimaryESD( fMCEvent, Photon->GetMother(0), mcProdVtxX, mcProdVtxY, mcProdVtxZ);
1846 
1847 
1848  // Fill histograms for inclusive gamma corrections
1849  // --> a) all clusters with leading real or converted photons
1850  if (TruePhotonCandidate->IsLargestComponentPhoton() || (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion()) ){
1851  fHistoTrueClusGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt(),fWeightJetJetMC);
1852  if(!fDoLightOutput){
1853  // how many of those clusters are from converted photons
1854  if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion()){
1855  fHistoTrueClusConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt(), fWeightJetJetMC);
1856  }
1857  // --> b) which of these are primary
1858  if(isPrimary){
1859  fHistoTruePrimaryClusGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt(),fWeightJetJetMC);
1860  // --> c) which are from conversions? Just additonal information
1861  if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion() && (Photon->GetMother(0)>-1)){
1862  fHistoTruePrimaryClusConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt(), fWeightJetJetMC);
1863  }
1864  // --> d) how do the secondaries look like
1865  }
1866  }
1867  }
1868 
1869  // Some additional QA
1870  if (fDoClusterQA > 0){
1871  // how many of the converted photons are fully contained in the cluster
1872  if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion() && TruePhotonCandidate->IsConversionFullyContained())
1873  fHistoTrueClusConvGammaFullyPt[fiCut]->Fill(TruePhotonCandidate->Pt(), fWeightJetJetMC);
1874  }
1875 
1876  // Check if we are double counting photons
1877  Int_t motherLab = Photon->GetMother(0);
1878  if (motherLab > -1){
1879  if (TruePhotonCandidate->IsLargestComponentPhoton()){
1881  fHistoDoubleCountTrueClusterGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt(),(Double_t)0,fWeightJetJetMC);
1883  }
1884  }
1885  Int_t grandMotherLab = fMCEvent->Particle(motherLab)->GetMother(0);
1886  if (grandMotherLab > -1){
1887  if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion()){
1889  fHistoDoubleCountTrueClusterGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt(),(Double_t)1,fWeightJetJetMC);
1891  }
1892  }
1893  }
1894  }
1895  return;
1896 }
1897 
1898 
1899 //________________________________________________________________________
1901 
1902  AliAODMCParticle *Photon = NULL;
1903  TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(fInputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
1904  if (AODMCTrackArray){
1905  if (!TruePhotonCandidate->GetIsCaloPhoton()) AliFatal("CaloPhotonFlag has not been set task will abort");
1906  if (TruePhotonCandidate->GetNCaloPhotonMCLabels()>0) Photon = (AliAODMCParticle*) AODMCTrackArray->At(TruePhotonCandidate->GetCaloPhotonMCLabel(0));
1907  else return;
1908  }else {
1909  AliInfo("AODMCTrackArray could not be loaded");
1910  return;
1911  }
1912 
1913  if(Photon == NULL){
1914  // cout << "no photon" << endl;
1915  return;
1916  }
1917 
1919  if(!fDoLightOutput) fHistoTrueNLabelsInClusPt[fiCut]->Fill(TruePhotonCandidate->GetNCaloPhotonMCLabels(),TruePhotonCandidate->Pt(),fWeightJetJetMC);
1920 
1921  const AliVVertex* primVtxMC = fMCEvent->GetPrimaryVertex();
1922  Double_t mcProdVtxX = primVtxMC->GetX();
1923  Double_t mcProdVtxY = primVtxMC->GetY();
1924  Double_t mcProdVtxZ = primVtxMC->GetZ();
1925  Bool_t isPrimary = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsConversionPrimaryAOD(fInputEvent, Photon, mcProdVtxX, mcProdVtxY, mcProdVtxZ);
1926 
1927  // to get primary distrinction right put mother of conversion electron as particle to check
1928  if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion()){
1929  if (Photon->GetMother()> -1){
1930  AliAODMCParticle *Mother = (AliAODMCParticle*) AODMCTrackArray->At(Photon->GetMother());
1931  isPrimary = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsConversionPrimaryAOD( fInputEvent, Mother, mcProdVtxX, mcProdVtxY, mcProdVtxZ);
1932  }
1933  }
1934 
1935  // True Photon
1936  if (TruePhotonCandidate->IsLargestComponentPhoton() || (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion()) ){
1937  fHistoTrueClusGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt(),fWeightJetJetMC);
1938  if(!fDoLightOutput){
1939  if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion()){
1940  fHistoTrueClusConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt(), fWeightJetJetMC);
1941  }
1942  if(isPrimary){
1943  fHistoTruePrimaryClusGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt(),fWeightJetJetMC);
1944  if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion()){
1945  fHistoTruePrimaryClusConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt(), fWeightJetJetMC);
1946  }
1947  }
1948  }
1949  }
1950  if (fDoClusterQA > 0){
1951  if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion() && TruePhotonCandidate->IsConversionFullyContained())
1952  fHistoTrueClusConvGammaFullyPt[fiCut]->Fill(TruePhotonCandidate->Pt(), fWeightJetJetMC);
1953  }
1954  Int_t motherLab = Photon->GetMother();
1955  if (motherLab > -1){
1956  if (TruePhotonCandidate->IsLargestComponentPhoton()){
1958  fHistoDoubleCountTrueClusterGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt(),(Double_t)0,fWeightJetJetMC);
1960  }
1961  }
1962  Int_t grandMotherLab = ((AliAODMCParticle*) AODMCTrackArray->At(motherLab))->GetMother();
1963  if (grandMotherLab > -1){
1964  if (TruePhotonCandidate->IsLargestComponentElectron() && TruePhotonCandidate->IsConversion()){
1966  fHistoDoubleCountTrueClusterGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt(),(Double_t)1,fWeightJetJetMC);
1968  }
1969  }
1970  }
1971  }
1972 
1973  return;
1974 }
1975 
1976 //________________________________________________________________________
1978 
1979  Int_t nV0 = 0;
1980  TList *GammaCandidatesStepOne = new TList();
1981  TList *GammaCandidatesStepTwo = new TList();
1982  // Loop over Photon Candidates allocated by ReaderV1
1983  for(Int_t i = 0; i < fReaderGammas->GetEntriesFast(); i++){
1984  AliAODConversionPhoton* PhotonCandidate = (AliAODConversionPhoton*) fReaderGammas->At(i);
1985  if(!PhotonCandidate) continue;
1986  fIsFromDesiredHeader = kTRUE;
1987  if(fIsMC>0 && ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetSignalRejection() != 0){
1988  Int_t isPosFromMBHeader = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCEvent, fInputEvent);
1989  if(isPosFromMBHeader == 0 && ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetSignalRejection() != 3) continue;
1990  Int_t isNegFromMBHeader = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCEvent, fInputEvent);
1991  if(isNegFromMBHeader == 0 && ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetSignalRejection() != 3) continue;
1992  if( (isNegFromMBHeader+isPosFromMBHeader) != 4) fIsFromDesiredHeader = kFALSE;
1993  }
1994 
1995  if(!((AliConversionPhotonCuts*)fCutArray->At(fiCut))->PhotonIsSelected(PhotonCandidate,fInputEvent)) continue;
1996  if(!((AliConversionPhotonCuts*)fCutArray->At(fiCut))->InPlaneOutOfPlaneCut(PhotonCandidate->GetPhotonPhi(),fEventPlaneAngle)) continue;
1997  if(!((AliConversionPhotonCuts*)fCutArray->At(fiCut))->UseElecSharingCut() &&
1998  !((AliConversionPhotonCuts*)fCutArray->At(fiCut))->UseToCloseV0sCut()){
1999  fGammaCandidates->Add(PhotonCandidate); // if no second loop is required add to events good gammas
2000 
2002  if(!fDoLightOutput) fHistoConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt(),fWeightJetJetMC);
2003  }
2004  if(fIsMC>0){
2005  if(fInputEvent->IsA()==AliESDEvent::Class())
2006  ProcessTruePhotonCandidates(PhotonCandidate);
2007  if(fInputEvent->IsA()==AliAODEvent::Class())
2008  ProcessTruePhotonCandidatesAOD(PhotonCandidate);
2009  }
2010  }else if(((AliConversionPhotonCuts*)fCutArray->At(fiCut))->UseElecSharingCut()){ // if Shared Electron cut is enabled, Fill array, add to step one
2011  ((AliConversionPhotonCuts*)fCutArray->At(fiCut))->FillElectonLabelArray(PhotonCandidate,nV0);
2012  nV0++;
2013  GammaCandidatesStepOne->Add(PhotonCandidate);
2014  }else if(!((AliConversionPhotonCuts*)fCutArray->At(fiCut))->UseElecSharingCut() &&
2015  ((AliConversionPhotonCuts*)fCutArray->At(fiCut))->UseToCloseV0sCut()){ // shared electron is disabled, step one not needed -> step two
2016  GammaCandidatesStepTwo->Add(PhotonCandidate);
2017  }
2018  }
2019 
2020  if(((AliConversionPhotonCuts*)fCutArray->At(fiCut))->UseElecSharingCut()){
2021  for(Int_t i = 0;i<GammaCandidatesStepOne->GetEntries();i++){
2022  AliAODConversionPhoton *PhotonCandidate= (AliAODConversionPhoton*) GammaCandidatesStepOne->At(i);
2023  if(!PhotonCandidate) continue;
2024  fIsFromDesiredHeader = kTRUE;
2025  if(fMCEvent && ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetSignalRejection() != 0){
2026  Int_t isPosFromMBHeader = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCEvent, fInputEvent);
2027  Int_t isNegFromMBHeader = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCEvent, fInputEvent);
2028  if( (isNegFromMBHeader+isPosFromMBHeader) != 4) fIsFromDesiredHeader = kFALSE;
2029  }
2030  if(!((AliConversionPhotonCuts*)fCutArray->At(fiCut))->RejectSharedElectronV0s(PhotonCandidate,i,GammaCandidatesStepOne->GetEntries())) continue;
2031  if(!((AliConversionPhotonCuts*)fCutArray->At(fiCut))->UseToCloseV0sCut()){ // To Colse v0s cut diabled, step two not needed
2032  fGammaCandidates->Add(PhotonCandidate);
2034  if(!fDoLightOutput) fHistoConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt(),fWeightJetJetMC);
2035  }
2036  if(fIsMC>0){
2037  if(fInputEvent->IsA()==AliESDEvent::Class())
2038  ProcessTruePhotonCandidates(PhotonCandidate);
2039  if(fInputEvent->IsA()==AliAODEvent::Class())
2040  ProcessTruePhotonCandidatesAOD(PhotonCandidate);
2041  }
2042  } else GammaCandidatesStepTwo->Add(PhotonCandidate); // Close v0s cut enabled -> add to list two
2043  }
2044  }
2045 
2046  if(((AliConversionPhotonCuts*)fCutArray->At(fiCut))->UseToCloseV0sCut()){
2047  for(Int_t i = 0;i<GammaCandidatesStepTwo->GetEntries();i++){
2048  AliAODConversionPhoton* PhotonCandidate = (AliAODConversionPhoton*) GammaCandidatesStepTwo->At(i);
2049  if(!PhotonCandidate) continue;
2050  fIsFromDesiredHeader = kTRUE;
2051  if(fMCEvent && ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetSignalRejection() != 0){
2052  Int_t isPosFromMBHeader = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCEvent, fInputEvent);
2053  Int_t isNegFromMBHeader = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCEvent, fInputEvent);
2054  if( (isNegFromMBHeader+isPosFromMBHeader) != 4) fIsFromDesiredHeader = kFALSE;
2055  }
2056  if(!((AliConversionPhotonCuts*)fCutArray->At(fiCut))->RejectToCloseV0s(PhotonCandidate,GammaCandidatesStepTwo,i)) continue;
2057  fGammaCandidates->Add(PhotonCandidate); // Add gamma to current cut TList
2059  if(!fDoLightOutput) fHistoConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt(),fWeightJetJetMC);
2060  }
2061  if(fIsMC>0){
2062  if(fInputEvent->IsA()==AliESDEvent::Class())
2063  ProcessTruePhotonCandidates(PhotonCandidate);
2064  if(fInputEvent->IsA()==AliAODEvent::Class())
2065  ProcessTruePhotonCandidatesAOD(PhotonCandidate);
2066  }
2067  }
2068  }
2069 
2070  delete GammaCandidatesStepOne;
2071  GammaCandidatesStepOne = 0x0;
2072  delete GammaCandidatesStepTwo;
2073  GammaCandidatesStepTwo = 0x0;
2074 
2075 }
2076 
2077 //________________________________________________________________________
2079 
2080  const AliVVertex* primVtxMC = fMCEvent->GetPrimaryVertex();
2081  Double_t mcProdVtxX = primVtxMC->GetX();
2082  Double_t mcProdVtxY = primVtxMC->GetY();
2083  Double_t mcProdVtxZ = primVtxMC->GetZ();
2084 
2085  TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(fInputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
2086  if (AODMCTrackArray == NULL) return;
2087  AliAODMCParticle *posDaughter = (AliAODMCParticle*) AODMCTrackArray->At(TruePhotonCandidate->GetMCLabelPositive());
2088  AliAODMCParticle *negDaughter = (AliAODMCParticle*) AODMCTrackArray->At(TruePhotonCandidate->GetMCLabelNegative());
2089 
2090  if(posDaughter == NULL || negDaughter == NULL) return; // One particle does not exist
2091  Int_t pdgCode[2] = {TMath::Abs(posDaughter->GetPdgCode()),TMath::Abs(negDaughter->GetPdgCode())};
2092 
2093  if(posDaughter->GetMother() != negDaughter->GetMother()){
2094  return;
2095  } else if(posDaughter->GetMother() == -1){
2096  return;
2097  }
2098 
2099  if(pdgCode[0]!=11 || pdgCode[1]!=11){
2100  return; //One Particle is not a electron
2101  }
2102 
2103  if(posDaughter->GetPdgCode()==negDaughter->GetPdgCode()){
2104  return; // Same Charge
2105  }
2106 
2107  AliAODMCParticle *Photon = (AliAODMCParticle*) AODMCTrackArray->At(posDaughter->GetMother());
2108  if(Photon->GetPdgCode() != 22){
2109  return; // Mother is no Photon
2110  }
2111 
2112  if(((posDaughter->GetMCProcessCode())) != 5 || ((negDaughter->GetMCProcessCode())) != 5){
2113  return;// check if the daughters come from a conversion
2114  }
2115  // STILL A BUG IN ALIROOT >>8 HAS TPO BE REMOVED AFTER FIX
2116 
2117  // True Photon
2119  if(!fDoLightOutput) fHistoTrueConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt(),fWeightJetJetMC);
2120  if (CheckVectorForDoubleCount(fVectorDoubleCountTrueConvGammas,posDaughter->GetMother())){
2121  if(!fDoLightOutput) fHistoDoubleCountTrueConvGammaRPt[fiCut]->Fill(TruePhotonCandidate->GetConversionRadius(),TruePhotonCandidate->Pt(),fWeightJetJetMC);
2122  FillMultipleCountMap(fMapMultipleCountTrueConvGammas,posDaughter->GetMother());
2123  }
2124  }
2125 
2126  Bool_t isPrimary = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsConversionPrimaryAOD(fInputEvent, Photon, mcProdVtxX, mcProdVtxY, mcProdVtxZ);
2127  if(isPrimary){
2128  // Count just primary MC Gammas as true --> For Ratio esdtruegamma / mcconvgamma
2130  if(!fDoLightOutput){
2131  fHistoTruePrimaryConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt(),fWeightJetJetMC);
2132  }
2133  }
2134  // (Not Filled for i6, Extra Signal Gamma (parambox) are secondary)
2135  }
2136  TruePhotonCandidate->SetIsTrueConvertedPhoton();
2137  return;
2138 }
2139 
2140 //________________________________________________________________________
2142 
2143  const AliVVertex* primVtxMC = fMCEvent->GetPrimaryVertex();
2144  Double_t mcProdVtxX = primVtxMC->GetX();
2145  Double_t mcProdVtxY = primVtxMC->GetY();
2146  Double_t mcProdVtxZ = primVtxMC->GetZ();
2147 
2148  // Process True Photons
2149  TParticle *posDaughter = TruePhotonCandidate->GetPositiveMCDaughter(fMCEvent);
2150  TParticle *negDaughter = TruePhotonCandidate->GetNegativeMCDaughter(fMCEvent);
2151 
2152  if(posDaughter == NULL || negDaughter == NULL) return; // One particle does not exist
2153  Int_t pdgCode[2] = {TMath::Abs(posDaughter->GetPdgCode()),TMath::Abs(negDaughter->GetPdgCode())};
2154  if(posDaughter->GetMother(0) != negDaughter->GetMother(0)){
2155  return;
2156  }
2157  else if(posDaughter->GetMother(0) == -1){
2158  return;
2159  }
2160 
2161  if(pdgCode[0]!=11 || pdgCode[1]!=11) return; //One Particle is not a electron
2162 
2163  if(posDaughter->GetPdgCode()==negDaughter->GetPdgCode()) return; // Same Charge
2164 
2165  TParticle *Photon = TruePhotonCandidate->GetMCParticle(fMCEvent);
2166 
2167  if(Photon->GetPdgCode() != 22){
2168  return; // Mother is no Photon
2169  }
2170 
2171  if(posDaughter->GetUniqueID() != 5 || negDaughter->GetUniqueID() !=5) return;// check if the daughters come from a conversion
2172 
2173  // True Photon
2175  if(!fDoLightOutput) fHistoTrueConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt(),fWeightJetJetMC);
2176  if (CheckVectorForDoubleCount(fVectorDoubleCountTrueConvGammas,posDaughter->GetMother(0))){
2177  if(!fDoLightOutput) fHistoDoubleCountTrueConvGammaRPt[fiCut]->Fill(TruePhotonCandidate->GetConversionRadius(),TruePhotonCandidate->Pt(),fWeightJetJetMC);
2178  FillMultipleCountMap(fMapMultipleCountTrueConvGammas,posDaughter->GetMother(0));
2179  }
2180  }
2181  Bool_t isPrimary = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsConversionPrimaryESD( fMCEvent, posDaughter->GetMother(0), mcProdVtxX, mcProdVtxY, mcProdVtxZ);
2182  if(isPrimary){
2183  // Count just primary MC Gammas as true --> For Ratio esdtruegamma / mcconvgamma
2185  if(!fDoLightOutput){
2186  fHistoTruePrimaryConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt(),fWeightJetJetMC);
2187  }
2188  }
2189  // (Not Filled for i6, Extra Signal Gamma (parambox) are secondary)
2190  }
2191  TruePhotonCandidate->SetIsTrueConvertedPhoton();
2192  return;
2193 }
2194 //________________________________________________________________________
2196 
2197  const AliVVertex* primVtxMC = fMCEvent->GetPrimaryVertex();
2198  Double_t mcProdVtxX = primVtxMC->GetX();
2199  Double_t mcProdVtxY = primVtxMC->GetY();
2200  Double_t mcProdVtxZ = primVtxMC->GetZ();
2201 
2202  TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(fInputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
2203  if (AODMCTrackArray == NULL) return;
2204 
2205  // Loop over all primary MC particle
2206  for(Long_t i = 0; i < AODMCTrackArray->GetEntriesFast(); i++) {
2207 
2208  AliAODMCParticle* particle = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(i));
2209  if (!particle) continue;
2210 
2211  Bool_t isPrimary = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsConversionPrimaryAOD(fInputEvent, particle, mcProdVtxX, mcProdVtxY, mcProdVtxZ);
2212  if (isPrimary) {
2213 
2214  Int_t isMCFromMBHeader = -1;
2215  if(((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetSignalRejection() != 0){
2216  isMCFromMBHeader = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCEvent, fInputEvent);
2217  if(isMCFromMBHeader == 0 && ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetSignalRejection() != 3) continue;
2218  }
2219 
2220  if (fMesonRecoMode < 2){
2221  if(!((AliConversionPhotonCuts*)fCutArray->At(fiCut))->InPlaneOutOfPlaneCut(particle->Phi(),fEventPlaneAngle,kFALSE)) continue;
2222  }
2223 
2224  Double_t mesonY = 1.e30;
2225  Double_t ratio = 0;
2226  if (particle->E() != TMath::Abs(particle->Pz())){
2227  ratio = (particle->E()+particle->Pz()) / (particle->E()-particle->Pz());
2228  }
2229  if( !(ratio <= 0) ){
2230  mesonY = particle->Y()-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift();
2231  }
2232 
2233  // check neutral mesons
2234  if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelectedAODMC(particle,AODMCTrackArray,((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift())){
2235  AliAODMCParticle* daughter0 = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(particle->GetDaughterLabel(0)));
2236  AliAODMCParticle* daughter1 = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(particle->GetDaughterLabel(1)));
2237  Float_t weighted= 1;
2238  if(((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCEvent, fInputEvent)){
2239  if (particle->Pt()>0.005){
2240  weighted= ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetWeightForMeson(i, 0x0, fInputEvent);
2241  }
2242  }
2243  Double_t alpha = -10;
2244 
2245  if(particle->GetPdgCode() == fMesonPDG){
2246  alpha = (daughter0->E() - daughter1->E())/(daughter0->E() + daughter1->E());
2247  if (fHistoMCMesonPt[fiCut])fHistoMCMesonPt[fiCut]->Fill(particle->Pt(),weighted*fWeightJetJetMC); // All MC Meson
2248  if (fHistoMCMesonWOWeightPt[fiCut]) fHistoMCMesonWOWeightPt[fiCut]->Fill(particle->Pt(),fWeightJetJetMC);
2249  if (fIsMC > 1 && fHistoMCMesonWOEvtWeightPt[fiCut])fHistoMCMesonWOEvtWeightPt[fiCut]->Fill(particle->Pt());
2250  if (fDoMesonQA > 0){
2251  if (fHistoMCMesonPtY[fiCut])fHistoMCMesonPtY[fiCut]->Fill(particle->Pt(),mesonY,weighted*fWeightJetJetMC);
2252  if (fHistoMCMesonPtAlpha[fiCut])fHistoMCMesonPtAlpha[fiCut]->Fill(particle->Pt(),alpha,fWeightJetJetMC);
2253  if (fIsMC == 2 && fHistoMCMesonPtJetPt[fiCut])fHistoMCMesonPtJetPt[fiCut]->Fill(particle->Pt(),((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetMaxPtJet(),fWeightJetJetMC);
2254  }
2255 
2256  // Check the acceptance for both gammas
2257  if (fMesonRecoMode == 0){
2258  if( ((AliConversionPhotonCuts*)fCutArray->At(fiCut))->PhotonIsSelectedAODMC(daughter0,AODMCTrackArray,kFALSE) &&
2259  ((AliConversionPhotonCuts*)fCutArray->At(fiCut))->PhotonIsSelectedAODMC(daughter1,AODMCTrackArray,kFALSE) &&
2260  ((AliConversionPhotonCuts*)fCutArray->At(fiCut))->InPlaneOutOfPlaneCut(daughter0->Phi(),fEventPlaneAngle,kFALSE) &&
2261  ((AliConversionPhotonCuts*)fCutArray->At(fiCut))->InPlaneOutOfPlaneCut(daughter1->Phi(),fEventPlaneAngle,kFALSE)){
2262  // check acceptance of clusters as well, true if one of them points into the Calo acceptance
2263  if (fHistoMCMesonInAccPt[fiCut])fHistoMCMesonInAccPt[fiCut]->Fill(particle->Pt(),weighted*fWeightJetJetMC); // MC Meson with gamma in acc
2264  if (fHistoMCMesonWOWeightInAccPt[fiCut])fHistoMCMesonWOWeightInAccPt[fiCut]->Fill(particle->Pt(),fWeightJetJetMC); // MC Meson with gamma in acc wo weight
2265  if(fIsMC > 1 && fHistoMCMesonWOEvtWeightInAccPt[fiCut])fHistoMCMesonWOEvtWeightInAccPt[fiCut]->Fill(particle->Pt()); // MC Meson with gamma in acc wo any weight
2266  }
2267  } else if (fMesonRecoMode == 1){
2268  if( ((AliConversionPhotonCuts*)fCutArray->At(fiCut))->PhotonIsSelectedAODMC(daughter0,AODMCTrackArray,kFALSE) &&
2269  ((AliConversionPhotonCuts*)fCutArray->At(fiCut))->PhotonIsSelectedAODMC(daughter1,AODMCTrackArray,kFALSE) &&
2270  ((AliConversionPhotonCuts*)fCutArray->At(fiCut))->InPlaneOutOfPlaneCut(daughter0->Phi(),fEventPlaneAngle,kFALSE) &&
2271  ((AliConversionPhotonCuts*)fCutArray->At(fiCut))->InPlaneOutOfPlaneCut(daughter1->Phi(),fEventPlaneAngle,kFALSE)){
2272  // check acceptance of clusters as well, true if one of them points into the Calo acceptance
2273  if( ((AliCaloPhotonCuts*)fClusterCutArray->At(fiCut))->ClusterIsSelectedAODMC(daughter0,AODMCTrackArray) ||
2274  ((AliCaloPhotonCuts*)fClusterCutArray->At(fiCut))->ClusterIsSelectedAODMC(daughter1,AODMCTrackArray) ){
2275  if (fHistoMCMesonInAccPt[fiCut])fHistoMCMesonInAccPt[fiCut]->Fill(particle->Pt(),weighted*fWeightJetJetMC); // MC Meson with gamma in acc
2276  if (fHistoMCMesonWOWeightInAccPt[fiCut])fHistoMCMesonWOWeightInAccPt[fiCut]->Fill(particle->Pt(),fWeightJetJetMC); // MC Meson with gamma in acc wo weight
2277  if(fIsMC > 1 && fHistoMCMesonWOEvtWeightInAccPt[fiCut])fHistoMCMesonWOEvtWeightInAccPt[fiCut]->Fill(particle->Pt()); // MC Meson with gamma in acc wo any weight
2278  }
2279  }
2280  } else if (fMesonRecoMode == 2){
2281  if (((AliCaloPhotonCuts*)fClusterCutArray->At(fiCut))->ClusterIsSelectedAODMC(daughter0,AODMCTrackArray) &&
2282  ((AliCaloPhotonCuts*)fClusterCutArray->At(fiCut))->ClusterIsSelectedAODMC(daughter1,AODMCTrackArray) ){
2283  if (fHistoMCMesonInAccPt[fiCut])fHistoMCMesonInAccPt[fiCut]->Fill(particle->Pt(),weighted*fWeightJetJetMC); // MC Meson with gamma in acc
2284  if (fHistoMCMesonWOWeightInAccPt[fiCut])fHistoMCMesonWOWeightInAccPt[fiCut]->Fill(particle->Pt(),fWeightJetJetMC); // MC Meson with gamma in acc wo weight
2285  if(fIsMC > 1 && fHistoMCMesonWOEvtWeightInAccPt[fiCut])fHistoMCMesonWOEvtWeightInAccPt[fiCut]->Fill(particle->Pt()); // MC Meson with gamma in acc wo any weight
2286  }
2287  }
2288  }
2289  }
2290  }
2291  }
2292 }
2293 
2294 //________________________________________________________________________
2296 
2297  const AliVVertex* primVtxMC = fMCEvent->GetPrimaryVertex();
2298  Double_t mcProdVtxX = primVtxMC->GetX();
2299  Double_t mcProdVtxY = primVtxMC->GetY();
2300  Double_t mcProdVtxZ = primVtxMC->GetZ();
2301  // cout << mcProdVtxX <<"\t" << mcProdVtxY << "\t" << mcProdVtxZ << endl;
2302 
2303  // Loop over all primary MC particle
2304  for(Long_t i = 0; i < fMCEvent->GetNumberOfTracks(); i++) {
2305  if (((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsConversionPrimaryESD( fMCEvent, i, mcProdVtxX, mcProdVtxY, mcProdVtxZ)){
2306  // fill primary histograms
2307  TParticle* particle = (TParticle *)fMCEvent->Particle(i);
2308  if (!particle) continue;
2309 
2310  Int_t isMCFromMBHeader = -1;
2311  if(((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetSignalRejection() != 0){
2312  isMCFromMBHeader = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCEvent, fInputEvent);
2313  if(isMCFromMBHeader == 0 && ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetSignalRejection() != 3) continue;
2314  }
2315 
2316  if (fMesonRecoMode < 2){
2317  if(!((AliConversionPhotonCuts*)fCutArray->At(fiCut))->InPlaneOutOfPlaneCut(particle->Phi(),fEventPlaneAngle,kFALSE)) continue;
2318  }
2319 
2320  // Fill histograms for other particles
2321  Double_t mesonY = 1.e30;
2322  Double_t ratio = 0;
2323  if (particle->Energy() != TMath::Abs(particle->Pz())){
2324  ratio = (particle->Energy()+particle->Pz()) / (particle->Energy()-particle->Pz());
2325  }
2326  if( !(ratio <= 0) ){
2327  mesonY = particle->Y()-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift();
2328  }
2329 
2330  // check neutral mesons
2331  if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelectedMC(particle,fMCEvent,((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift())){
2332  TParticle* daughter0 = (TParticle*)fMCEvent->Particle(particle->GetFirstDaughter());
2333  TParticle* daughter1 = (TParticle*)fMCEvent->Particle(particle->GetLastDaughter());
2334 
2335  Float_t weighted= 1;
2336  if(((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCEvent, fInputEvent)){
2337  if (particle->Pt()>0.005){
2338  weighted= ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetWeightForMeson(i, fMCEvent, fInputEvent);
2339  }
2340  }
2341 
2342  Double_t alpha = -10;
2343  if(particle->GetPdgCode() == fMesonPDG){
2344  alpha = (daughter0->Energy() - daughter1->Energy())/(daughter0->Energy() + daughter1->Energy());
2345  if (fHistoMCMesonPt[fiCut])fHistoMCMesonPt[fiCut]->Fill(particle->Pt(),weighted*fWeightJetJetMC); // All MC Meson
2346  if (fHistoMCMesonWOWeightPt[fiCut]) fHistoMCMesonWOWeightPt[fiCut]->Fill(particle->Pt(),fWeightJetJetMC);
2347  if (fIsMC > 1 && fHistoMCMesonWOEvtWeightPt[fiCut])fHistoMCMesonWOEvtWeightPt[fiCut]->Fill(particle->Pt());
2348  if (fDoMesonQA > 0){
2349  if (fHistoMCMesonPtY[fiCut])fHistoMCMesonPtY[fiCut]->Fill(particle->Pt(),mesonY,weighted*fWeightJetJetMC); // All MC Meson
2350  if (fHistoMCMesonPtAlpha[fiCut])fHistoMCMesonPtAlpha[fiCut]->Fill(particle->Pt(),alpha,fWeightJetJetMC); // All MC Meson
2351  if (fIsMC == 2 && fHistoMCMesonPtJetPt[fiCut])fHistoMCMesonPtJetPt[fiCut]->Fill(particle->Pt(),((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetMaxPtJet(),fWeightJetJetMC);
2352  }
2353 
2354  // Check the acceptance for both gammas & whether they are counted as primaries as well
2355  Bool_t kDaughter0IsPrim = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsConversionPrimaryESD( fMCEvent, particle->GetFirstDaughter(), mcProdVtxX, mcProdVtxY, mcProdVtxZ);
2356  Bool_t kDaughter1IsPrim = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsConversionPrimaryESD( fMCEvent, particle->GetLastDaughter(), mcProdVtxX, mcProdVtxY, mcProdVtxZ);
2357  if( kDaughter0IsPrim && kDaughter1IsPrim ){
2358  if (fMesonRecoMode == 0){
2359  if( ((AliConversionPhotonCuts*)fCutArray->At(fiCut))->PhotonIsSelectedMC(daughter0,fMCEvent,kFALSE) &&
2360  ((AliConversionPhotonCuts*)fCutArray->At(fiCut))->PhotonIsSelectedMC(daughter1,fMCEvent,kFALSE) &&
2361  ((AliConversionPhotonCuts*)fCutArray->At(fiCut))->InPlaneOutOfPlaneCut(daughter0->Phi(),fEventPlaneAngle,kFALSE) &&
2362  ((AliConversionPhotonCuts*)fCutArray->At(fiCut))->InPlaneOutOfPlaneCut(daughter1->Phi(),fEventPlaneAngle,kFALSE)){
2363  // check acceptance of clusters as well, true if one of them points into the Calo acceptance
2364  if (fHistoMCMesonInAccPt[fiCut])fHistoMCMesonInAccPt[fiCut]->Fill(particle->Pt(),weighted*fWeightJetJetMC); // MC Meson with gamma in acc
2365  if (fHistoMCMesonWOWeightInAccPt[fiCut])fHistoMCMesonWOWeightInAccPt[fiCut]->Fill(particle->Pt(),fWeightJetJetMC); // MC Meson with gamma in acc wo weighting
2366  if(fIsMC > 1 && fHistoMCMesonWOEvtWeightInAccPt[fiCut])fHistoMCMesonWOEvtWeightInAccPt[fiCut]->Fill(particle->Pt()); // MC Meson with gamma in acc wo any weight
2367  }
2368  } else if (fMesonRecoMode == 1){
2369  if (((AliConversionPhotonCuts*)fCutArray->At(fiCut))->PhotonIsSelectedMC(daughter0,fMCEvent,kFALSE) &&
2370  ((AliConversionPhotonCuts*)fCutArray->At(fiCut))->PhotonIsSelectedMC(daughter1,fMCEvent,kFALSE) &&
2371  ((AliConversionPhotonCuts*)fCutArray->At(fiCut))->InPlaneOutOfPlaneCut(daughter0->Phi(),fEventPlaneAngle,kFALSE) &&
2372  ((AliConversionPhotonCuts*)fCutArray->At(fiCut))->InPlaneOutOfPlaneCut(daughter1->Phi(),fEventPlaneAngle,kFALSE)){
2373  // check acceptance of clusters as well, true if one of them points into the Calo acceptance
2374  if (((AliCaloPhotonCuts*)fClusterCutArray->At(fiCut))->ClusterIsSelectedMC(daughter0,fMCEvent) ||
2375  ((AliCaloPhotonCuts*)fClusterCutArray->At(fiCut))->ClusterIsSelectedMC(daughter1,fMCEvent) ){
2376  if (fHistoMCMesonInAccPt[fiCut])fHistoMCMesonInAccPt[fiCut]->Fill(particle->Pt(),weighted*fWeightJetJetMC); // MC Meson with gamma in acc
2377  if (fHistoMCMesonWOWeightInAccPt[fiCut])fHistoMCMesonWOWeightInAccPt[fiCut]->Fill(particle->Pt(),fWeightJetJetMC); // MC Meson with gamma in acc wo weighting
2378  if(fIsMC > 1 && fHistoMCMesonWOEvtWeightInAccPt[fiCut])fHistoMCMesonWOEvtWeightInAccPt[fiCut]->Fill(particle->Pt()); // MC Meson with gamma in acc wo any weight
2379  }
2380  }
2381  } else if (fMesonRecoMode == 2){
2382  if (((AliCaloPhotonCuts*)fClusterCutArray->At(fiCut))->ClusterIsSelectedMC(daughter0,fMCEvent) &&
2383  ((AliCaloPhotonCuts*)fClusterCutArray->At(fiCut))->ClusterIsSelectedMC(daughter1,fMCEvent) ){
2384  if (fHistoMCMesonInAccPt[fiCut])fHistoMCMesonInAccPt[fiCut]->Fill(particle->Pt(),weighted*fWeightJetJetMC); // MC Meson with gamma in acc
2385  if (fHistoMCMesonWOWeightInAccPt[fiCut])fHistoMCMesonWOWeightInAccPt[fiCut]->Fill(particle->Pt(),fWeightJetJetMC); // MC Meson with gamma in acc wo weighting
2386  if(fIsMC > 1 && fHistoMCMesonWOEvtWeightInAccPt[fiCut])fHistoMCMesonWOEvtWeightInAccPt[fiCut]->Fill(particle->Pt()); // MC Meson with gamma in acc wo any weight
2387  }
2388  }
2389  }
2390  }
2391  }
2392  }
2393  }
2394 }
2395 
2396 
2397 //________________________________________________________________________
2398 // function to reject photons in specific invariant mass window
2399 //________________________________________________________________________
2401  TClonesArray * arrClustersMesonCand = NULL;
2402  if(fCorrTaskSetting.CompareTo("") && fMesonRecoMode > 0)
2403  arrClustersMesonCand = dynamic_cast<TClonesArray*>(fInputEvent->FindListObject(Form("%sClustersBranch",fCorrTaskSetting.Data())));
2404 
2405  if (fMesonRecoMode == 0){
2406  if(fGammaCandidates->GetEntries()>1){
2407  for(Int_t firstGammaIndex=0;firstGammaIndex<fGammaCandidates->GetEntries()-1;firstGammaIndex++){
2408  AliAODConversionPhoton *gamma0=dynamic_cast<AliAODConversionPhoton*>(fGammaCandidates->At(firstGammaIndex));
2409  if (gamma0==NULL) continue;
2410  for(Int_t secondGammaIndex=firstGammaIndex+1;secondGammaIndex<fGammaCandidates->GetEntries();secondGammaIndex++){
2411  AliAODConversionPhoton *gamma1=dynamic_cast<AliAODConversionPhoton*>(fGammaCandidates->At(secondGammaIndex));
2412  //Check for same Electron ID
2413  if (gamma1==NULL) continue;
2414  if(gamma0->GetTrackLabelPositive() == gamma1->GetTrackLabelPositive() ||
2415  gamma0->GetTrackLabelNegative() == gamma1->GetTrackLabelNegative() ||
2416  gamma0->GetTrackLabelNegative() == gamma1->GetTrackLabelPositive() ||
2417  gamma0->GetTrackLabelPositive() == gamma1->GetTrackLabelNegative() ) continue;
2418 
2419  AliAODConversionMother *mesonCand = new AliAODConversionMother(gamma0,gamma1);
2420  mesonCand->SetLabels(firstGammaIndex,secondGammaIndex);
2421  mesonCand->CalculateDistanceOfClossetApproachToPrimVtx(fInputEvent->GetPrimaryVertex());
2422 
2423  if((((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(mesonCand,kTRUE,((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift()))){
2424  if (!(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelectedByMassCut(mesonCand, 0))){
2425  gamma0->SetUseForMesonPair(kFALSE);
2426  gamma1->SetUseForMesonPair(kFALSE);
2427  fHistoMotherInvMassRejected[fiCut]->Fill(mesonCand->M());
2428  }
2429  }
2430  delete mesonCand;
2431  mesonCand=0x0;
2432  }
2433  }
2434  }
2435  } else if (fMesonRecoMode == 1){
2436  if(fGammaCandidates->GetEntries()>0){
2437  for(Int_t firstGammaIndex=0;firstGammaIndex<fGammaCandidates->GetEntries();firstGammaIndex++){
2438  AliAODConversionPhoton *gamma0=dynamic_cast<AliAODConversionPhoton*>(fGammaCandidates->At(firstGammaIndex));
2439  if (gamma0==NULL) continue;
2440 
2441  for(Int_t secondGammaIndex=0;secondGammaIndex<fClusterCandidates->GetEntries();secondGammaIndex++){
2442  Bool_t matched = kFALSE;
2443  AliAODConversionPhoton *gamma1=dynamic_cast<AliAODConversionPhoton*>(fClusterCandidates->At(secondGammaIndex));
2444  if (gamma1==NULL) continue;
2445 
2446  if (gamma1->GetIsCaloPhoton()){
2447  AliVCluster* cluster = NULL;
2448  if(fInputEvent->IsA()==AliESDEvent::Class()){
2449  if(arrClustersMesonCand)
2450  cluster = new AliESDCaloCluster(*(AliESDCaloCluster*)arrClustersMesonCand->At(gamma1->GetCaloClusterRef()));
2451  else
2452  cluster = fInputEvent->GetCaloCluster(gamma1->GetCaloClusterRef());
2453  } else if(fInputEvent->IsA()==AliAODEvent::Class()){
2454  if(arrClustersMesonCand)
2455  cluster = new AliAODCaloCluster(*(AliAODCaloCluster*)arrClustersMesonCand->At(gamma1->GetCaloClusterRef()));
2456  else
2457  cluster = fInputEvent->GetCaloCluster(gamma1->GetCaloClusterRef());
2458  }
2459 
2460  matched = ((AliCaloPhotonCuts*)fClusterCutArray->At(fiCut))->MatchConvPhotonToCluster(gamma0,cluster, fInputEvent, fWeightJetJetMC);
2461  if(arrClustersMesonCand) delete cluster;
2462  }
2463 
2464  AliAODConversionMother *mesonCand = new AliAODConversionMother(gamma0,gamma1);
2465  mesonCand->SetLabels(firstGammaIndex,secondGammaIndex);
2466 
2467  if((((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(mesonCand,kTRUE,((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift()))){
2468  if (!matched){
2469  if (!(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelectedByMassCut(mesonCand, 0))){
2470  gamma0->SetUseForMesonPair(kFALSE);
2471  gamma1->SetUseForMesonPair(kFALSE);
2472  fHistoMotherInvMassRejected[fiCut]->Fill(mesonCand->M());
2473  }
2474  }
2475  }
2476  delete mesonCand;
2477  mesonCand=0x0;
2478  }
2479  }
2480  }
2481  } else if (fMesonRecoMode == 2){
2482  if(fClusterCandidates->GetEntries()>0){
2483  for(Int_t firstGammaIndex=0;firstGammaIndex<fClusterCandidates->GetEntries();firstGammaIndex++){
2484  AliAODConversionPhoton *gamma0=dynamic_cast<AliAODConversionPhoton*>(fClusterCandidates->At(firstGammaIndex));
2485  if (gamma0==NULL) continue;
2486  for(Int_t secondGammaIndex=firstGammaIndex+1;secondGammaIndex<fClusterCandidates->GetEntries();secondGammaIndex++){
2487  AliAODConversionPhoton *gamma1=dynamic_cast<AliAODConversionPhoton*>(fClusterCandidates->At(secondGammaIndex));
2488  if (gamma1==NULL) continue;
2489 
2490  AliAODConversionMother *mesonCand = new AliAODConversionMother(gamma0,gamma1);
2491  mesonCand->SetLabels(firstGammaIndex,secondGammaIndex);
2492 
2493  if((((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(mesonCand, kTRUE, ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift(), gamma0->GetLeadingCellID(), gamma1->GetLeadingCellID()))){
2494  if (!(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelectedByMassCut(mesonCand, 0))){
2495  gamma0->SetUseForMesonPair(kFALSE);
2496  gamma1->SetUseForMesonPair(kFALSE);
2497  fHistoMotherInvMassRejected[fiCut]->Fill(mesonCand->M());
2498  }
2499  }
2500  delete mesonCand;
2501  mesonCand=0x0;
2502  }
2503  }
2504  }
2505  }
2506 }
2507 
2508 
2509 //________________________________________________________________________
2511  TClonesArray * arrClustersMesonCand = NULL;
2512  if(fCorrTaskSetting.CompareTo("") && fMesonRecoMode > 0)
2513  arrClustersMesonCand = dynamic_cast<TClonesArray*>(fInputEvent->FindListObject(Form("%sClustersBranch",fCorrTaskSetting.Data())));
2514 
2515  if (fMesonRecoMode == 0){
2516  if(fGammaCandidates->GetEntries()>1){
2517  for(Int_t firstGammaIndex=0;firstGammaIndex<fGammaCandidates->GetEntries()-1;firstGammaIndex++){
2518  AliAODConversionPhoton *gamma0=dynamic_cast<AliAODConversionPhoton*>(fGammaCandidates->At(firstGammaIndex));
2519  if (gamma0==NULL) continue;
2520  for(Int_t secondGammaIndex=firstGammaIndex+1;secondGammaIndex<fGammaCandidates->GetEntries();secondGammaIndex++){
2521  AliAODConversionPhoton *gamma1=dynamic_cast<AliAODConversionPhoton*>(fGammaCandidates->At(secondGammaIndex));
2522  //Check for same Electron ID
2523  if (gamma1==NULL) continue;
2524  if(gamma0->GetTrackLabelPositive() == gamma1->GetTrackLabelPositive() ||
2525  gamma0->GetTrackLabelNegative() == gamma1->GetTrackLabelNegative() ||
2526  gamma0->GetTrackLabelNegative() == gamma1->GetTrackLabelPositive() ||
2527  gamma0->GetTrackLabelPositive() == gamma1->GetTrackLabelNegative() ) continue;
2528 
2529 
2530  AliAODConversionMother *mesonCand = new AliAODConversionMother(gamma0,gamma1);
2531  mesonCand->SetLabels(firstGammaIndex,secondGammaIndex);
2532  mesonCand->CalculateDistanceOfClossetApproachToPrimVtx(fInputEvent->GetPrimaryVertex());
2533 
2534  if((((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(mesonCand,kTRUE,((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift()))){
2535  if (!gamma0->GetUseForMesonPair() || !gamma1->GetUseForMesonPair()){
2536  fHistoMotherInvMassRejected[fiCut]->Fill(mesonCand->M());
2537  delete mesonCand;
2538  mesonCand=0x0;
2539  continue;
2540  }
2541  if (fHistoMotherInvMassPt[fiCut]) fHistoMotherInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(), fWeightJetJetMC);
2542 
2543  if (fDoMesonQA > 0){
2544  if (mesonCand->M() > fMesonInvMassWindow[0] && mesonCand->M() < fMesonInvMassWindow[1]){
2545  if (fHistoMotherMesonPtY[fiCut]) fHistoMotherMesonPtY[fiCut]->Fill(mesonCand->Pt(),mesonCand->Rapidity()-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift(),fWeightJetJetMC);
2546  if (fHistoMotherMesonPtAlpha[fiCut]) fHistoMotherMesonPtAlpha[fiCut]->Fill(mesonCand->Pt(),mesonCand->GetAlpha(),fWeightJetJetMC);
2547  if (fHistoMotherMesonPtOpenAngle[fiCut]) fHistoMotherMesonPtOpenAngle[fiCut]->Fill(mesonCand->Pt(),mesonCand->GetOpeningAngle(),fWeightJetJetMC);
2548  }
2549  }
2550  if(fDoTHnSparse && ((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->DoBGCalculation()){
2551  Int_t zbin = 0;
2552  Int_t mbin = 0;
2553  if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->BackgroundHandlerType() == 0){
2554  zbin = fBGHandler[fiCut]->GetZBinIndex(fInputEvent->GetPrimaryVertex()->GetZ());
2555  if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
2557  }else {
2558  mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fGammaCandidates->GetEntries());
2559  }
2560  }else{
2561  zbin = fBGHandlerRP[fiCut]->GetZBinIndex(fInputEvent->GetPrimaryVertex()->GetZ());
2562  if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
2564  }else {
2566  }
2567  }
2568 
2569  Double_t sparesFill[4] = {mesonCand->M(),mesonCand->Pt(),(Double_t)zbin,(Double_t)mbin};
2570  if (fSparseMotherInvMassPtZM[fiCut]) fSparseMotherInvMassPtZM[fiCut]->Fill(sparesFill,1);
2571  }
2572 
2573 
2574  if( fIsMC > 0 ){
2575  if(fInputEvent->IsA()==AliESDEvent::Class())
2576  ProcessTrueMesonCandidatesConv(mesonCand, gamma0, gamma1);
2577  if(fInputEvent->IsA()==AliAODEvent::Class())
2578  ProcessTrueMesonCandidatesConvAOD(mesonCand, gamma0, gamma1);
2579  }
2580  }
2581  delete mesonCand;
2582  mesonCand=0x0;
2583  }
2584  }
2585  }
2586  } else if (fMesonRecoMode == 1){
2587  if(fGammaCandidates->GetEntries()>0){
2588  for(Int_t firstGammaIndex=0;firstGammaIndex<fGammaCandidates->GetEntries();firstGammaIndex++){
2589  AliAODConversionPhoton *gamma0=dynamic_cast<AliAODConversionPhoton*>(fGammaCandidates->At(firstGammaIndex));
2590  if (gamma0==NULL) continue;
2591 
2592  for(Int_t secondGammaIndex=0;secondGammaIndex<fClusterCandidates->GetEntries();secondGammaIndex++){
2593  Bool_t matched = kFALSE;
2594  AliAODConversionPhoton *gamma1=dynamic_cast<AliAODConversionPhoton*>(fClusterCandidates->At(secondGammaIndex));
2595  if (gamma1==NULL) continue;
2596 
2597  if (gamma1->GetIsCaloPhoton()){
2598  AliVCluster* cluster = NULL;
2599  if(fInputEvent->IsA()==AliESDEvent::Class()){
2600  if(arrClustersMesonCand)
2601  cluster = new AliESDCaloCluster(*(AliESDCaloCluster*)arrClustersMesonCand->At(gamma1->GetCaloClusterRef()));
2602  else
2603  cluster = fInputEvent->GetCaloCluster(gamma1->GetCaloClusterRef());
2604  } else if(fInputEvent->IsA()==AliAODEvent::Class()){
2605  if(arrClustersMesonCand)
2606  cluster = new AliAODCaloCluster(*(AliAODCaloCluster*)arrClustersMesonCand->At(gamma1->GetCaloClusterRef()));
2607  else
2608  cluster = fInputEvent->GetCaloCluster(gamma1->GetCaloClusterRef());
2609  }
2610 
2611  matched = ((AliCaloPhotonCuts*)fClusterCutArray->At(fiCut))->MatchConvPhotonToCluster(gamma0,cluster, fInputEvent, fWeightJetJetMC);
2612  if(arrClustersMesonCand) delete cluster;
2613  }
2614 
2615  AliAODConversionMother *mesonCand = new AliAODConversionMother(gamma0,gamma1);
2616  mesonCand->SetLabels(firstGammaIndex,secondGammaIndex);
2617 
2618  if((((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(mesonCand,kTRUE,((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift()))){
2619  if (matched){
2620  if(!fDoLightOutput && fMesonRecoMode == 1){
2621  if(fHistoMotherMatchedInvMassPt[fiCut]) fHistoMotherMatchedInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(),fWeightJetJetMC);
2622  }
2623  }else {
2624  if (!gamma0->GetUseForMesonPair() || !gamma1->GetUseForMesonPair()){
2625  fHistoMotherInvMassRejected[fiCut]->Fill(mesonCand->M());
2626  delete mesonCand;
2627  mesonCand=0x0;
2628  continue;
2629  }
2630  if (fHistoMotherInvMassPt[fiCut]) fHistoMotherInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(),fWeightJetJetMC);
2631  }
2632 
2633  // fill new histograms
2634  if (!matched){
2635  if (fDoMesonQA > 0){
2636  if (mesonCand->M() > fMesonInvMassWindow[0] && mesonCand->M() < fMesonInvMassWindow[1]){
2637  if (fHistoMotherMesonPtY[fiCut]) fHistoMotherMesonPtY[fiCut]->Fill(mesonCand->Pt(),mesonCand->Rapidity()-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift(),fWeightJetJetMC);
2638  if (fHistoMotherMesonPtAlpha[fiCut]) fHistoMotherMesonPtAlpha[fiCut]->Fill(mesonCand->Pt(),mesonCand->GetAlpha(),fWeightJetJetMC);
2639  if (fHistoMotherMesonPtOpenAngle[fiCut]) fHistoMotherMesonPtOpenAngle[fiCut]->Fill(mesonCand->Pt(),mesonCand->GetOpeningAngle(),fWeightJetJetMC);
2641  }
2642  }
2643  if(fDoTHnSparse && ((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->DoBGCalculation()){
2644  Int_t zbin = 0;
2645  Int_t mbin = 0;
2646 
2647  if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->BackgroundHandlerType() == 0){
2648  zbin = fBGHandler[fiCut]->GetZBinIndex(fInputEvent->GetPrimaryVertex()->GetZ());
2649  if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
2651  }else {
2652  mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fGammaCandidates->GetEntries());
2653  }
2654  }else{
2655  zbin = fBGHandlerRP[fiCut]->GetZBinIndex(fInputEvent->GetPrimaryVertex()->GetZ());
2656  if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
2658  }else {
2660  }
2661  }
2662  Double_t sparesFill[4] = {mesonCand->M(),mesonCand->Pt(),(Double_t)zbin,(Double_t)mbin};
2663  if (fSparseMotherInvMassPtZM[fiCut]) fSparseMotherInvMassPtZM[fiCut]->Fill(sparesFill,1);
2664  }
2665  }
2666 
2667  if(fIsMC>0){
2668  if(fInputEvent->IsA()==AliESDEvent::Class())
2669  ProcessTrueMesonCandidatesConvCalo(mesonCand, gamma0, gamma1, matched);
2670  if(fInputEvent->IsA()==AliAODEvent::Class())
2671  ProcessTrueMesonCandidatesConvCaloAOD(mesonCand, gamma0, gamma1, matched);
2672  }
2673  }
2674  delete mesonCand;
2675  mesonCand=0x0;
2676  }
2677  }
2678  }
2679  } else if (fMesonRecoMode == 2){
2680  if(fClusterCandidates->GetEntries()>0){
2681  for(Int_t firstGammaIndex=0;firstGammaIndex<fClusterCandidates->GetEntries();firstGammaIndex++){
2682  AliAODConversionPhoton *gamma0=dynamic_cast<AliAODConversionPhoton*>(fClusterCandidates->At(firstGammaIndex));
2683  if (gamma0==NULL) continue;
2684  for(Int_t secondGammaIndex=firstGammaIndex+1;secondGammaIndex<fClusterCandidates->GetEntries();secondGammaIndex++){
2685  AliAODConversionPhoton *gamma1=dynamic_cast<AliAODConversionPhoton*>(fClusterCandidates->At(secondGammaIndex));
2686  if (gamma1==NULL) continue;
2687 
2688  AliAODConversionMother *mesonCand = new AliAODConversionMother(gamma0,gamma1);
2689  mesonCand->SetLabels(firstGammaIndex,secondGammaIndex);
2690 
2691  if((((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(mesonCand, kTRUE, ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift(), gamma0->GetLeadingCellID(), gamma1->GetLeadingCellID()))){
2692  if (!gamma0->GetUseForMesonPair() || !gamma1->GetUseForMesonPair()){
2693  fHistoMotherInvMassRejected[fiCut]->Fill(mesonCand->M());
2694  delete mesonCand;
2695  mesonCand=0x0;
2696  continue;
2697  }
2698  if (fHistoMotherInvMassPt[fiCut]) fHistoMotherInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(), fWeightJetJetMC);
2699  // fill new histograms
2700  if (fDoMesonQA > 0 && fDoMesonQA < 3){
2701  if ( mesonCand->M() > fMesonInvMassWindow[0] && mesonCand->M() < fMesonInvMassWindow[1]){
2702  fHistoMotherMesonPtY[fiCut]->Fill(mesonCand->Pt(),mesonCand->Rapidity()-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift(), fWeightJetJetMC);
2703  fHistoMotherMesonPtAlpha[fiCut]->Fill(mesonCand->Pt(),mesonCand->GetAlpha(), fWeightJetJetMC);
2704  fHistoMotherMesonPtOpenAngle[fiCut]->Fill(mesonCand->Pt(),mesonCand->GetOpeningAngle(), fWeightJetJetMC);
2705  }
2706  }
2707  if(fDoTHnSparse && ((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->DoBGCalculation()){
2708  Int_t zbin = 0;
2709  Int_t mbin = 0;
2710 
2711  if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->BackgroundHandlerType() == 0){
2712  zbin = fBGHandler[fiCut]->GetZBinIndex(fInputEvent->GetPrimaryVertex()->GetZ());
2713  if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
2715  } else {
2717  }
2718  }
2719  Double_t sparesFill[4] = {mesonCand->M(),mesonCand->Pt(),(Double_t)zbin,(Double_t)mbin};
2720  if (fSparseMotherInvMassPtZM[fiCut]) fSparseMotherInvMassPtZM[fiCut]->Fill(sparesFill,1);
2721  }
2722 
2723  if(fIsMC> 0){
2724  if(fInputEvent->IsA()==AliESDEvent::Class())
2725  ProcessTrueMesonCandidatesCalo(mesonCand,gamma0,gamma1);
2726  if(fInputEvent->IsA()==AliAODEvent::Class())
2727  ProcessTrueMesonCandidatesCaloAOD(mesonCand,gamma0,gamma1);
2728  }
2729  }
2730  delete mesonCand;
2731  mesonCand=0x0;
2732  }
2733  }
2734  }
2735  }
2736 }
2737 
2738 //______________________________________________________________________
2740  AliAODConversionPhoton *TrueGammaCandidate0,
2741  AliAODConversionPhoton *TrueGammaCandidate1,
2742  Bool_t matched )
2743 {
2744  // obtain MC vertex
2745  const AliVVertex* primVtxMC = fMCEvent->GetPrimaryVertex();
2746  Double_t mcProdVtxX = primVtxMC->GetX();
2747  Double_t mcProdVtxY = primVtxMC->GetY();
2748  Double_t mcProdVtxZ = primVtxMC->GetZ();
2749 
2750  // Process True Mesons
2751  if(TrueGammaCandidate0->GetV0Index()<fInputEvent->GetNumberOfV0s()){
2752  Bool_t isTrueMeson = kFALSE;
2753  Int_t gamma0MCLabel = -1;
2754  Int_t gamma0MotherLabel = -1;
2755  if (TrueGammaCandidate0->IsTrueConvertedPhoton()){
2756  gamma0MCLabel = TrueGammaCandidate0->GetMCParticleLabel(fMCEvent);
2757  if(gamma0MCLabel>-1){
2758  TParticle * gammaMC0 = (TParticle*)fMCEvent->Particle(gamma0MCLabel);
2759  gamma0MotherLabel=gammaMC0->GetFirstMother();
2760  }
2761  }
2762  if (!TrueGammaCandidate1->GetIsCaloPhoton()) AliFatal("CaloPhotonFlag has not been set. Aborting");
2763 
2764  Int_t gamma1MCLabel = TrueGammaCandidate1->GetCaloPhotonMCLabel(0); // get most probable MC label
2765  Int_t gamma1MotherLabel = -1;
2766  // check if
2767 
2768  TParticle * gammaMC1 = 0x0;
2769  if(gamma1MCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
2770  // Daughters Gamma 1
2771  gammaMC1 = (TParticle*)fMCEvent->Particle(gamma1MCLabel);
2772  if (TrueGammaCandidate1->IsLargestComponentPhoton() || TrueGammaCandidate1->IsLargestComponentElectron()){ // largest component is electro magnetic
2773  // get mother of interest (pi0 or eta)
2774  if (TrueGammaCandidate1->IsLargestComponentPhoton()){ // for photons its the direct mother
2775  gamma1MotherLabel=gammaMC1->GetMother(0);
2776  }else if (TrueGammaCandidate1->IsLargestComponentElectron()){ // for electrons its either the direct mother or for conversions the grandmother
2777  if (TrueGammaCandidate1->IsConversion() && gammaMC1->GetMother(0)>-1) gamma1MotherLabel=fMCEvent->Particle(gammaMC1->GetMother(0))->GetMother(0);
2778  else gamma1MotherLabel=gammaMC1->GetMother(0);
2779  }
2780  }
2781  }
2782 
2783  if(gamma0MotherLabel>=0 && gamma0MotherLabel==gamma1MotherLabel){
2784  if(((TParticle*)fMCEvent->Particle(gamma1MotherLabel))->GetPdgCode() == fMesonPDG){
2785  isTrueMeson=kTRUE;
2786  }
2787  }
2788 
2789  if(isTrueMeson ){// True Pion or Eta
2790  if (!matched){
2791  if (fHistoTrueMesonInvMassPt[fiCut]) fHistoTrueMesonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(),fWeightJetJetMC);
2792  }else{
2793  if (fHistoTrueMesonMatchedInvMassPt[fiCut]) fHistoTrueMesonMatchedInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(),fWeightJetJetMC);
2794  }
2795  if (fDoMesonQA > 0 && fIsMC < 2){
2796  if (TrueGammaCandidate1->IsLargestComponentPhoton() && !matched){
2797  if (fHistoTrueMesonCaloPhotonInvMassPt[fiCut]) fHistoTrueMesonCaloPhotonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
2798  }
2799  if (TrueGammaCandidate1->IsLargestComponentElectron() && !matched){
2800  if (fHistoTrueMesonCaloElectronInvMassPt[fiCut]) fHistoTrueMesonCaloElectronInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
2801  }
2802  if (TrueGammaCandidate1->IsLargestComponentElectron() && TrueGammaCandidate1->IsConversion() ){
2803  if ( !matched){
2804  fHistoTrueMesonCaloConvertedPhotonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
2805  }
2806 
2807  if ((TrueGammaCandidate0->GetMCLabelPositive() == gamma1MCLabel || TrueGammaCandidate0->GetMCLabelNegative() == gamma1MCLabel) && isTrueMeson){
2809  }
2810  }
2811  if ((TrueGammaCandidate1->IsMerged() || TrueGammaCandidate1->IsMergedPartConv() || TrueGammaCandidate1->IsDalitzMerged()) && !matched ){
2813  }
2814  if (TrueGammaCandidate1->IsMergedPartConv() && !matched){
2816  }
2817  }
2818  if (!matched){
2819  if (fDoMesonQA > 0){
2820  if (isTrueMeson){
2821  if (mesonCand->M() > fMesonInvMassWindow[0] && mesonCand->M() < fMesonInvMassWindow[1] ){
2822  if (fHistoTrueMesonPtY[fiCut]) fHistoTrueMesonPtY[fiCut]->Fill(mesonCand->Pt(),mesonCand->Rapidity()-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift(),fWeightJetJetMC);
2823  if (fHistoTrueMesonPtAlpha[fiCut]) fHistoTrueMesonPtAlpha[fiCut]->Fill(mesonCand->Pt(),mesonCand->GetAlpha(),fWeightJetJetMC);
2824  if (fHistoTrueMesonPtOpenAngle[fiCut]) fHistoTrueMesonPtOpenAngle[fiCut]->Fill(mesonCand->Pt(),mesonCand->GetOpeningAngle(),fWeightJetJetMC);
2825  if (fHistoTrueMotherMesonConvPhotonEtaPhi[fiCut])fHistoTrueMotherMesonConvPhotonEtaPhi[fiCut]->Fill(TrueGammaCandidate0->GetPhotonPhi(), TrueGammaCandidate0->GetPhotonEta(),fWeightJetJetMC);
2826  }
2827  }
2828  }
2829  Bool_t isPrimary = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsConversionPrimaryESD( fMCEvent, gamma0MotherLabel, mcProdVtxX, mcProdVtxY, mcProdVtxZ);
2830  if (isPrimary) {
2831  Float_t weighted= 1;
2832  if(((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(gamma1MotherLabel, fMCEvent, fInputEvent)){
2833  if (((TParticle*)fMCEvent->Particle(gamma1MotherLabel))->Pt()>0.005){
2834  weighted= ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetWeightForMeson(gamma1MotherLabel, fMCEvent, fInputEvent);
2835  // cout << "rec \t " <<gamma1MotherLabel << "\t" << weighted << endl;
2836  }
2837  }
2838  if (isTrueMeson){
2839  if (fHistoTruePrimaryMesonInvMassPt[fiCut]) fHistoTruePrimaryMesonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(),weighted*fWeightJetJetMC);
2841  if (fProfileTruePrimaryMesonWeightsInvMassPt[fiCut]) fProfileTruePrimaryMesonWeightsInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(),weighted*fWeightJetJetMC);
2843  if (fHistoDoubleCountTrueMesonInvMassPt[fiCut]) fHistoDoubleCountTrueMesonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(),weighted*fWeightJetJetMC);
2845  }
2846  }
2847 
2848  if (fDoMesonQA > 0 && fIsMC < 2){
2849  if(isTrueMeson){ // Only primary pi0 for resolution
2850  if (fHistoTruePrimaryMesonMCPtResolPt[fiCut]) fHistoTruePrimaryMesonMCPtResolPt[fiCut]->Fill(((TParticle*)fMCEvent->Particle(gamma1MotherLabel))->Pt(),(mesonCand->Pt()-((TParticle*)fMCEvent->Particle(gamma1MotherLabel))->Pt())/((TParticle*)fMCEvent->Particle(gamma1MotherLabel))->Pt(),weighted*fWeightJetJetMC);
2851  }
2852  }
2853  }
2854  }
2855  }else if(!isTrueMeson ){ // Background
2856  if (fDoMesonQA > 1){
2857  if(gamma0MotherLabel>-1 && gamma1MotherLabel>-1){ // Both Tracks are Photons and have a mother but not Meson or Eta
2858  if (fHistoTrueBckGGInvMassPt[fiCut])fHistoTrueBckGGInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(), fWeightJetJetMC);
2859  if(
2860  ( ((TParticle*)fMCEvent->Particle(gamma1MotherLabel))->GetPdgCode() == fMesonPDG
2861  && (TrueGammaCandidate1->IsMerged() || TrueGammaCandidate1->IsMergedPartConv()))
2862  ){
2864  }else if( TrueGammaCandidate1->E()/mesonCand->E() > 0.7 ){
2865  if (fHistoTrueBckAsymEClustersInvMassPt[fiCut]) fHistoTrueBckAsymEClustersInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(), fWeightJetJetMC);
2866  }
2867  }else { // No photon or without mother
2868  if (fHistoTrueBckContInvMassPt[fiCut]) fHistoTrueBckContInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(), fWeightJetJetMC);
2869  }
2870  }
2871  }
2872  if (isTrueMeson && !matched){
2873  fVectorRecTrueMesons.push_back(gamma0MotherLabel);
2874  }
2875  }
2876 }
2877 
2878 //______________________________________________________________________
2880  AliAODConversionPhoton *TrueGammaCandidate0,
2881  AliAODConversionPhoton *TrueGammaCandidate1,
2882  Bool_t matched )
2883 {
2884  const AliVVertex* primVtxMC = fMCEvent->GetPrimaryVertex();
2885  Double_t mcProdVtxX = primVtxMC->GetX();
2886  Double_t mcProdVtxY = primVtxMC->GetY();
2887  Double_t mcProdVtxZ = primVtxMC->GetZ();
2888 
2889  // Process True Mesons
2890  TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(fInputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
2891  if (AODMCTrackArray == NULL) return;
2892  Bool_t isTrueMeson = kFALSE;
2893 
2894  AliAODMCParticle *positiveMC = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(TrueGammaCandidate0->GetMCLabelPositive()));
2895  AliAODMCParticle *negativeMC = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(TrueGammaCandidate0->GetMCLabelNegative()));
2896 
2897  Int_t gamma0MCLabel = -1;
2898  Int_t gamma0MotherLabel = -1;
2899  if(!positiveMC||!negativeMC)
2900  return;
2901 
2902  if (TrueGammaCandidate0->IsTrueConvertedPhoton()){
2903  gamma0MCLabel = positiveMC->GetMother();
2904  AliAODMCParticle * gammaMC0 = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma0MCLabel));
2905  gamma0MotherLabel=gammaMC0->GetMother();
2906  }
2907 
2908  if (!TrueGammaCandidate1->GetIsCaloPhoton()) AliFatal("CaloPhotonFlag has not been set. Aborting");
2909  Int_t gamma1MCLabel = TrueGammaCandidate1->GetCaloPhotonMCLabel(0); // get most probable MC label
2910  Int_t gamma1MotherLabel = -1;
2911  // check if
2912 
2913  AliAODMCParticle * gammaMC1 = 0x0;
2914  if(gamma1MCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
2915  // Daughters Gamma 1
2916  gammaMC1 = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MCLabel));
2917  if (TrueGammaCandidate1->IsLargestComponentPhoton() || TrueGammaCandidate1->IsLargestComponentElectron()){ // largest component is electro magnetic
2918  // get mother of interest (pi0 or eta)
2919  if (TrueGammaCandidate1->IsLargestComponentPhoton()){ // for photons its the direct mother
2920  gamma1MotherLabel=gammaMC1->GetMother();
2921  }else if (TrueGammaCandidate1->IsLargestComponentElectron()){ // for electrons its either the direct mother or for conversions the grandmother
2922  if (TrueGammaCandidate1->IsConversion()){
2923  AliAODMCParticle * gammaGrandMotherMC1 = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gammaMC1->GetMother()));
2924  gamma1MotherLabel=gammaGrandMotherMC1->GetMother();
2925  }else gamma1MotherLabel=gammaMC1->GetMother();
2926  }
2927  }
2928  }
2929 
2930  if(gamma0MotherLabel>=0 && gamma0MotherLabel==gamma1MotherLabel){
2931  if(((AliAODMCParticle*)AODMCTrackArray->At(gamma1MotherLabel))->GetPdgCode() == fMesonPDG){
2932  isTrueMeson=kTRUE;
2933  }
2934  }
2935 
2936  if(isTrueMeson ){// True Pion or Eta
2937  if (!matched){
2938  if (fHistoTrueMesonInvMassPt[fiCut]) fHistoTrueMesonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(),fWeightJetJetMC);
2939 
2940  }else{
2941  if (fHistoTrueMesonMatchedInvMassPt[fiCut]) fHistoTrueMesonMatchedInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(),fWeightJetJetMC);
2942  }
2943  if (fDoMesonQA > 0 && fIsMC < 2){
2944  if (TrueGammaCandidate1->IsLargestComponentPhoton() && !matched){
2945  if (fHistoTrueMesonCaloPhotonInvMassPt[fiCut]) fHistoTrueMesonCaloPhotonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
2946  }
2947  if (TrueGammaCandidate1->IsLargestComponentElectron() && !matched) {
2948  if (fHistoTrueMesonCaloElectronInvMassPt[fiCut]) fHistoTrueMesonCaloElectronInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
2949  }
2950  if (TrueGammaCandidate1->IsLargestComponentElectron() && TrueGammaCandidate1->IsConversion()){
2951  if (!matched)fHistoTrueMesonCaloConvertedPhotonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
2952  if ((TrueGammaCandidate0->GetMCLabelPositive() == gamma1MCLabel || TrueGammaCandidate0->GetMCLabelNegative() == gamma1MCLabel) && isTrueMeson)
2954  }
2955  if ((TrueGammaCandidate1->IsMerged() || TrueGammaCandidate1->IsMergedPartConv() || TrueGammaCandidate1->IsDalitzMerged()) && !matched ){
2957  }
2958  if (TrueGammaCandidate1->IsMergedPartConv() && !matched) {
2960  }
2961  }
2962 
2963  if ( !matched){
2964  if (fDoMesonQA > 0){
2965  if (mesonCand->M() > fMesonInvMassWindow[0] && mesonCand->M() < fMesonInvMassWindow[1] ){
2966  if (fHistoTrueMesonPtY[fiCut]) fHistoTrueMesonPtY[fiCut]->Fill(mesonCand->Pt(),mesonCand->Rapidity()-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift(),fWeightJetJetMC);
2967  if (fHistoTrueMesonPtAlpha[fiCut]) fHistoTrueMesonPtAlpha[fiCut]->Fill(mesonCand->Pt(),mesonCand->GetAlpha(),fWeightJetJetMC);
2968  if (fHistoTrueMesonPtOpenAngle[fiCut]) fHistoTrueMesonPtOpenAngle[fiCut]->Fill(mesonCand->Pt(),mesonCand->GetOpeningAngle(),fWeightJetJetMC);
2969  if (fHistoTrueMotherMesonConvPhotonEtaPhi[fiCut]) fHistoTrueMotherMesonConvPhotonEtaPhi[fiCut]->Fill(TrueGammaCandidate0->GetPhotonPhi(), TrueGammaCandidate0->GetPhotonEta(),fWeightJetJetMC);
2970  }
2971  }
2972 
2973  Bool_t isPrimary = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsConversionPrimaryAOD(fInputEvent, static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma0MotherLabel)), mcProdVtxX, mcProdVtxY, mcProdVtxZ);
2974  if(isPrimary){
2975  // Only primary pi0 for efficiency calculation
2976  Float_t weighted= 1;
2977  if(((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(gamma1MotherLabel, 0x0, fInputEvent)){
2978  if (static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt()>0.005){
2979  weighted= ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetWeightForMeson(gamma1MotherLabel, 0x0, fInputEvent);
2980  // cout << "rec \t " <<gamma1MotherLabel << "\t" << weighted << endl;
2981  }
2982  }
2983  if (isTrueMeson){
2984  if (fHistoTruePrimaryMesonInvMassPt[fiCut]) fHistoTruePrimaryMesonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(),weighted*fWeightJetJetMC);
2986  if (fProfileTruePrimaryMesonWeightsInvMassPt[fiCut]) fProfileTruePrimaryMesonWeightsInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(),weighted*fWeightJetJetMC);
2988  if (fHistoDoubleCountTrueMesonInvMassPt[fiCut]) fHistoDoubleCountTrueMesonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(),weighted*fWeightJetJetMC);
2990  }
2991  }
2992  if (fDoMesonQA > 0 && fIsMC < 2){
2993  if(isTrueMeson){ // Only primary pi0 for resolution
2994  if (fHistoTruePrimaryMesonMCPtResolPt[fiCut]) fHistoTruePrimaryMesonMCPtResolPt[fiCut]->Fill(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt(),
2995  (mesonCand->Pt()-static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt())/static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt(),weighted*fWeightJetJetMC);
2996 
2997  }
2998  }
2999  }
3000  }
3001  }else if(!isTrueMeson ) { // Background
3002  if (fDoMesonQA > 1){
3003  if(gamma0MotherLabel>-1 && gamma1MotherLabel>-1){ // Both Tracks are Photons and have a mother but not Meson or Eta
3004  if (fHistoTrueBckGGInvMassPt[fiCut]) fHistoTrueBckGGInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
3005 
3006  if( (((AliAODMCParticle*)AODMCTrackArray->At(gamma1MotherLabel))->GetPdgCode() == fMesonPDG
3007  && ((TrueGammaCandidate1->IsMerged() || TrueGammaCandidate1->IsMergedPartConv())))
3008  ){
3010  }else if( TrueGammaCandidate1->E()/mesonCand->E() > 0.7 ){
3011  if (fHistoTrueBckAsymEClustersInvMassPt[fiCut]) fHistoTrueBckAsymEClustersInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(), fWeightJetJetMC);
3012  }
3013  }else { // No photon or without mother
3014  if (fHistoTrueBckContInvMassPt[fiCut]) fHistoTrueBckContInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
3015  }
3016  }
3017  }
3018  if (isTrueMeson && !matched){
3019  fVectorRecTrueMesons.push_back(gamma0MotherLabel);
3020  }
3021 }
3022 
3023 
3024 //______________________________________________________________________
3026  AliAODConversionPhoton *TrueGammaCandidate0,
3027  AliAODConversionPhoton *TrueGammaCandidate1)
3028 {
3029  // Process True Mesons
3030  const AliVVertex* primVtxMC = fMCEvent->GetPrimaryVertex();
3031  Double_t mcProdVtxX = primVtxMC->GetX();
3032  Double_t mcProdVtxY = primVtxMC->GetY();
3033  Double_t mcProdVtxZ = primVtxMC->GetZ();
3034 
3035  Bool_t isTrueMeson = kFALSE;
3036  Int_t gamma0MCLabel = TrueGammaCandidate0->GetCaloPhotonMCLabel(0); // get most probable MC label
3037  Int_t gamma0MotherLabel = -1;
3038 
3039  TParticle * gammaMC0 = 0x0;
3040  if(gamma0MCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
3041  gammaMC0 = (TParticle*)fMCEvent->Particle(gamma0MCLabel);
3042  if (TrueGammaCandidate0->IsLargestComponentPhoton() || TrueGammaCandidate0->IsLargestComponentElectron()){ // largest component is electro magnetic
3043  // get mother of interest (pi0 or eta)
3044  if (TrueGammaCandidate0->IsLargestComponentPhoton()){ // for photons its the direct mother
3045  gamma0MotherLabel=gammaMC0->GetMother(0);
3046  } else if (TrueGammaCandidate0->IsLargestComponentElectron()){ // for electrons its either the direct mother or for conversions the grandmother
3047  if (TrueGammaCandidate0->IsConversion() && (gammaMC0->GetMother(0) > -1)){
3048  gamma0MotherLabel=fMCEvent->Particle(gammaMC0->GetMother(0))->GetMother(0);
3049  } else {
3050  gamma0MotherLabel=gammaMC0->GetMother(0);
3051  }
3052  }
3053  }
3054  }
3055  if (!TrueGammaCandidate1->GetIsCaloPhoton()) AliFatal("CaloPhotonFlag has not been set. Aborting");
3056 
3057  Int_t gamma1MCLabel = TrueGammaCandidate1->GetCaloPhotonMCLabel(0); // get most probable MC label
3058  Int_t gamma1MotherLabel = -1;
3059  // check if
3060 
3061  TParticle * gammaMC1 = 0x0;
3062  if(gamma1MCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
3063  // Daughters Gamma 1
3064  gammaMC1 = (TParticle*)fMCEvent->Particle(gamma1MCLabel);
3065  if (TrueGammaCandidate1->IsLargestComponentPhoton() || TrueGammaCandidate1->IsLargestComponentElectron()){ // largest component is electro magnetic
3066  // get mother of interest (pi0 or eta)
3067  if (TrueGammaCandidate1->IsLargestComponentPhoton()){ // for photons its the direct mother
3068  gamma1MotherLabel = gammaMC1->GetMother(0);
3069  } else if (TrueGammaCandidate1->IsLargestComponentElectron()){ // for electrons its either the direct mother or for conversions the grandmother
3070  if (TrueGammaCandidate1->IsConversion()){
3071  if(gammaMC1->GetMother(0) > -1) gamma1MotherLabel = fMCEvent->Particle(gammaMC1->GetMother(0))->GetMother(0);
3072  } else {
3073  gamma1MotherLabel=gammaMC1->GetMother(0);
3074  }
3075  }
3076  }
3077  }
3078 
3079  if(gamma0MotherLabel>=0 && gamma0MotherLabel==gamma1MotherLabel){
3080  if(((TParticle*)fMCEvent->Particle(gamma1MotherLabel))->GetPdgCode() == fMesonPDG){
3081  isTrueMeson=kTRUE;
3082  }
3083  }
3084 
3085  if(isTrueMeson ){// True Meson
3086  if (fHistoTrueMesonInvMassPt[fiCut]) fHistoTrueMesonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(), fWeightJetJetMC);
3087  if (fDoMesonQA > 0 && fDoMesonQA < 3 && fIsMC < 2){
3088  // both gammas are real gammas
3089  if (TrueGammaCandidate0->IsLargestComponentPhoton() && TrueGammaCandidate1->IsLargestComponentPhoton()) {
3090  if (fHistoTrueMesonCaloPhotonInvMassPt[fiCut]) fHistoTrueMesonCaloPhotonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
3091  }
3092  // both particles are electrons
3093  if (TrueGammaCandidate0->IsLargestComponentElectron() && TrueGammaCandidate1->IsLargestComponentElectron() ) {
3094  if (fHistoTrueMesonCaloElectronInvMassPt[fiCut]) fHistoTrueMesonCaloElectronInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
3095  }
3096  // both particles are converted electrons
3097  if ((TrueGammaCandidate0->IsLargestComponentElectron() && TrueGammaCandidate0->IsConversion()) && (TrueGammaCandidate1->IsLargestComponentElectron() && TrueGammaCandidate1->IsConversion()) ){
3098  fHistoTrueMesonCaloConvertedPhotonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
3099  }
3100  // 1 gamma is converted the other one is normals
3101  if ( (TrueGammaCandidate0->IsLargestComponentPhoton() && TrueGammaCandidate1->IsLargestComponentElectron() && TrueGammaCandidate1->IsConversion()) ||
3102  (TrueGammaCandidate1->IsLargestComponentPhoton() && TrueGammaCandidate0->IsLargestComponentElectron() && TrueGammaCandidate0->IsConversion())
3103  ) {
3104  fHistoTrueMesonCaloMixedPhotonConvPhotonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
3105  }
3106 
3107  // at least one of the photon is merged
3108  if (TrueGammaCandidate0->IsMerged() || TrueGammaCandidate0->IsMergedPartConv() || TrueGammaCandidate0->IsDalitzMerged() || TrueGammaCandidate1->IsMerged() || TrueGammaCandidate1->IsMergedPartConv() || TrueGammaCandidate1->IsDalitzMerged() ){
3109  if (fHistoTrueMesonCaloMergedClusterInvMassPt[fiCut]) fHistoTrueMesonCaloMergedClusterInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
3110  }
3111  // at least one of the photon is merged and part conv
3112  if (TrueGammaCandidate1->IsMergedPartConv() || TrueGammaCandidate0->IsMergedPartConv()) {
3114  }
3115  }
3116 
3117  if (fDoMesonQA > 0 && fDoMesonQA < 3){
3118  if ( mesonCand->M() > fMesonInvMassWindow[0] && mesonCand->M() < fMesonInvMassWindow[1] ){
3119  if (fHistoTrueMesonPtY[fiCut]) fHistoTrueMesonPtY[fiCut]->Fill(mesonCand->Pt(),mesonCand->Rapidity()-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift(), fWeightJetJetMC);
3120  if (fHistoTrueMesonPtAlpha[fiCut]) fHistoTrueMesonPtAlpha[fiCut]->Fill(mesonCand->Pt(),mesonCand->GetAlpha(), fWeightJetJetMC);
3121  if (fHistoTrueMesonPtOpenAngle[fiCut]) fHistoTrueMesonPtOpenAngle[fiCut]->Fill(mesonCand->Pt(),mesonCand->GetOpeningAngle(), fWeightJetJetMC);
3122  }
3123 
3124  }
3125  Bool_t isPrimary = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsConversionPrimaryESD( fMCEvent, gamma0MotherLabel, mcProdVtxX, mcProdVtxY, mcProdVtxZ);
3126  if(isPrimary){ // Only primary pi0 for efficiency calculation
3127  // filling primary histograms
3128  Float_t weighted= 1;
3129  if(((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(gamma1MotherLabel, fMCEvent, fInputEvent)){
3130  if (((TParticle*)fMCEvent->Particle(gamma1MotherLabel))->Pt()>0.005){
3131  weighted= ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetWeightForMeson(gamma1MotherLabel, fMCEvent, fInputEvent);
3132  // cout << "rec \t " <<gamma1MotherLabel << "\t" << weighted << endl;
3133  }
3134  }
3135  if (isTrueMeson){
3136  if (fHistoTruePrimaryMesonInvMassPt[fiCut]) fHistoTruePrimaryMesonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(),weighted* fWeightJetJetMC);
3138  if (fProfileTruePrimaryMesonWeightsInvMassPt[fiCut]) fProfileTruePrimaryMesonWeightsInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(),weighted* fWeightJetJetMC);
3139  if (CheckVectorForDoubleCount(fVectorDoubleCountTrueMesons,gamma0MotherLabel) && fHistoDoubleCountTrueMesonInvMassPt[fiCut]) fHistoDoubleCountTrueMesonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(), weighted*fWeightJetJetMC);
3140  }
3141  if (fDoMesonQA > 0 && fDoMesonQA < 3 && fIsMC<2){
3142  if(isTrueMeson){ // Only primary pi0 for resolution
3143  if (fHistoTruePrimaryMesonMCPtResolPt[fiCut]) fHistoTruePrimaryMesonMCPtResolPt[fiCut]->Fill(((TParticle*)fMCEvent->Particle(gamma1MotherLabel))->Pt(),(mesonCand->Pt()-((TParticle*)fMCEvent->Particle(gamma1MotherLabel))->Pt())/((TParticle*)fMCEvent->Particle(gamma1MotherLabel))->Pt(),weighted* fWeightJetJetMC);
3144  }
3145  }
3146  }
3147  } else if(!isTrueMeson ){ // Background
3148  if (fDoMesonQA > 1 && fDoMesonQA < 3){
3149  if(gamma0MotherLabel>-1 && gamma1MotherLabel>-1){ // Both Tracks are Photons and have a mother but not Pi0 or Eta
3150  if (fHistoTrueBckGGInvMassPt[fiCut]) fHistoTrueBckGGInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(), fWeightJetJetMC);
3151 
3152  if( (((TParticle*)fMCEvent->Particle(gamma0MotherLabel))->GetPdgCode() == fMesonPDG
3153  && (TrueGammaCandidate0->IsMerged() || TrueGammaCandidate0->IsMergedPartConv()))
3154  ||
3155  (((TParticle*)fMCEvent->Particle(gamma1MotherLabel))->GetPdgCode() == fMesonPDG
3156  && (TrueGammaCandidate1->IsMerged() || TrueGammaCandidate1->IsMergedPartConv()))
3157  ){
3159  }else if( (TrueGammaCandidate0->E()/mesonCand->E() > 0.7) || (TrueGammaCandidate1->E()/mesonCand->E() > 0.7) ){
3160  if (fHistoTrueBckAsymEClustersInvMassPt[fiCut]) fHistoTrueBckAsymEClustersInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(), fWeightJetJetMC);
3161  }
3162  } else { // No photon or without mother
3163  if (fHistoTrueBckContInvMassPt[fiCut]) fHistoTrueBckContInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(), fWeightJetJetMC);
3164  }
3165  }
3166  }
3167 }
3168 
3169 //______________________________________________________________________
3171  AliAODConversionPhoton *TrueGammaCandidate0,
3172  AliAODConversionPhoton *TrueGammaCandidate1)
3173 {
3174  const AliVVertex* primVtxMC = fMCEvent->GetPrimaryVertex();
3175  Double_t mcProdVtxX = primVtxMC->GetX();
3176  Double_t mcProdVtxY = primVtxMC->GetY();
3177  Double_t mcProdVtxZ = primVtxMC->GetZ();
3178 
3179  // Process True Mesons
3180  TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(fInputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
3181  if (AODMCTrackArray == NULL) return;
3182 
3183  Bool_t isTrueMeson = kFALSE;
3184  Int_t gamma0MCLabel = TrueGammaCandidate0->GetCaloPhotonMCLabel(0); // get most probable MC label
3185  Int_t gamma0MotherLabel = -1;
3186 
3187  // check if
3188  AliAODMCParticle * gammaMC0 = 0x0;
3189  if(gamma0MCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
3190  // Daughters Gamma 0
3191  gammaMC0 = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma0MCLabel));
3192  if (TrueGammaCandidate0->IsLargestComponentPhoton() || TrueGammaCandidate0->IsLargestComponentElectron()){ // largest component is electro magnetic
3193  // get mother of interest (pi0 or eta)
3194  if (TrueGammaCandidate0->IsLargestComponentPhoton()){ // for photons its the direct mother
3195  gamma0MotherLabel=gammaMC0->GetMother();
3196  } else if (TrueGammaCandidate0->IsLargestComponentElectron()){ // for electrons its either the direct mother or for conversions the grandmother
3197  if (TrueGammaCandidate0->IsConversion()){
3198  AliAODMCParticle * gammaGrandMotherMC0 = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gammaMC0->GetMother()));
3199  gamma0MotherLabel=gammaGrandMotherMC0->GetMother();
3200  } else gamma0MotherLabel=gammaMC0->GetMother();
3201  }
3202  }
3203  }
3204 
3205  Int_t gamma1MCLabel = TrueGammaCandidate1->GetCaloPhotonMCLabel(0); // get most probable MC label
3206  Int_t gamma1MotherLabel = -1;
3207 
3208  // check if
3209  AliAODMCParticle *gammaMC1 = 0x0;
3210  if(gamma1MCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
3211  // Daughters Gamma 1
3212  gammaMC1 = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MCLabel));
3213  if (TrueGammaCandidate1->IsLargestComponentPhoton() || TrueGammaCandidate1->IsLargestComponentElectron()){ // largest component is electro magnetic
3214  // get mother of interest (pi0 or eta)
3215  if (TrueGammaCandidate1->IsLargestComponentPhoton()){ // for photons its the direct mother
3216  gamma1MotherLabel=gammaMC1->GetMother();
3217  } else if (TrueGammaCandidate1->IsLargestComponentElectron()){ // for electrons its either the direct mother or for conversions the grandmother
3218  if (TrueGammaCandidate1->IsConversion()){
3219  AliAODMCParticle * gammaGrandMotherMC1 = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gammaMC1->GetMother()));
3220  gamma1MotherLabel=gammaGrandMotherMC1->GetMother();
3221  } else gamma1MotherLabel=gammaMC1->GetMother();
3222  }
3223  }
3224  }
3225 
3226  if(gamma0MotherLabel>=0 && gamma0MotherLabel==gamma1MotherLabel){
3227  if(((AliAODMCParticle*)AODMCTrackArray->At(gamma1MotherLabel))->GetPdgCode() == fMesonPDG){
3228  isTrueMeson=kTRUE;
3229  }
3230  }
3231 
3232  if(isTrueMeson ){// True Meson
3233  if (fHistoTrueMesonInvMassPt[fiCut]) fHistoTrueMesonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(), fWeightJetJetMC);
3234  if (fDoMesonQA > 0 && fDoMesonQA < 3 && fIsMC < 2){
3235  // both gammas are real gammas
3236  if (TrueGammaCandidate0->IsLargestComponentPhoton() && TrueGammaCandidate1->IsLargestComponentPhoton()) {
3237  if (fHistoTrueMesonCaloPhotonInvMassPt[fiCut]) fHistoTrueMesonCaloPhotonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
3238  }
3239  // both particles are electrons
3240  if (TrueGammaCandidate0->IsLargestComponentElectron() && TrueGammaCandidate1->IsLargestComponentElectron() ) {
3241  if (fHistoTrueMesonCaloElectronInvMassPt[fiCut]) fHistoTrueMesonCaloElectronInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
3242  }
3243  // both particles are converted electrons
3244  if ((TrueGammaCandidate0->IsLargestComponentElectron() && TrueGammaCandidate0->IsConversion()) && (TrueGammaCandidate1->IsLargestComponentElectron() && TrueGammaCandidate1->IsConversion()) ){
3245  fHistoTrueMesonCaloConvertedPhotonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
3246  }
3247  // 1 gamma is converted the other one is normals
3248  if ( (TrueGammaCandidate0->IsLargestComponentPhoton() && TrueGammaCandidate1->IsLargestComponentElectron() && TrueGammaCandidate1->IsConversion()) ||
3249  (TrueGammaCandidate1->IsLargestComponentPhoton() && TrueGammaCandidate0->IsLargestComponentElectron() && TrueGammaCandidate0->IsConversion())
3250  ) {
3251  fHistoTrueMesonCaloMixedPhotonConvPhotonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
3252  }
3253 
3254  // at least one of the photon is merged
3255  if (TrueGammaCandidate0->IsMerged() || TrueGammaCandidate0->IsMergedPartConv() || TrueGammaCandidate0->IsDalitzMerged() || TrueGammaCandidate1->IsMerged() || TrueGammaCandidate1->IsMergedPartConv() || TrueGammaCandidate1->IsDalitzMerged() ){
3256  if (fHistoTrueMesonCaloMergedClusterInvMassPt[fiCut]) fHistoTrueMesonCaloMergedClusterInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
3257  }
3258  // at least one of the photon is merged and part conv
3259  if (TrueGammaCandidate1->IsMergedPartConv() || TrueGammaCandidate0->IsMergedPartConv()) {
3261  }
3262  }
3263 
3264  if (fDoMesonQA > 0 && fDoMesonQA < 3){
3265  if ( mesonCand->M() > fMesonInvMassWindow[0] && mesonCand->M() < fMesonInvMassWindow[1] ){
3266  if (fHistoTrueMesonPtY[fiCut]) fHistoTrueMesonPtY[fiCut]->Fill(mesonCand->Pt(),mesonCand->Rapidity()-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift(), fWeightJetJetMC);
3267  if (fHistoTrueMesonPtAlpha[fiCut]) fHistoTrueMesonPtAlpha[fiCut]->Fill(mesonCand->Pt(),mesonCand->GetAlpha(), fWeightJetJetMC);
3268  if (fHistoTrueMesonPtOpenAngle[fiCut]) fHistoTrueMesonPtOpenAngle[fiCut]->Fill(mesonCand->Pt(),mesonCand->GetOpeningAngle(), fWeightJetJetMC);
3269  }
3270  }
3271 
3272  Bool_t isPrimary = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsConversionPrimaryAOD(fInputEvent, static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma0MotherLabel)), mcProdVtxX, mcProdVtxY, mcProdVtxZ);
3273  if(isPrimary){ // Only primary pi0 for efficiency calculation
3274  Float_t weighted= 1;
3275  if(((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(gamma1MotherLabel, 0x0, fInputEvent)){
3276  if (static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt()>0.005){
3277  weighted= ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetWeightForMeson(gamma1MotherLabel, 0x0, fInputEvent);
3278  }
3279  }
3280 
3281  if (fHistoTruePrimaryMesonInvMassPt[fiCut]) fHistoTruePrimaryMesonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(),weighted* fWeightJetJetMC);
3283  if (fProfileTruePrimaryMesonWeightsInvMassPt[fiCut]) fProfileTruePrimaryMesonWeightsInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(),weighted* fWeightJetJetMC);
3284  if (CheckVectorForDoubleCount(fVectorDoubleCountTrueMesons,gamma0MotherLabel) && fHistoDoubleCountTrueMesonInvMassPt[fiCut]) fHistoDoubleCountTrueMesonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(), weighted*fWeightJetJetMC);
3285  if (fDoMesonQA > 0 && fDoMesonQA < 3 && fIsMC<2){
3286  if (fHistoTruePrimaryMesonMCPtResolPt[fiCut]) fHistoTruePrimaryMesonMCPtResolPt[fiCut]->Fill(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt(),
3287  (mesonCand->Pt()-static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt())/static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt(),weighted* fWeightJetJetMC);
3288  }
3289  }
3290  } else if(!isTrueMeson ) { // Background
3291  if (fDoMesonQA > 1 && fDoMesonQA < 3){
3292  if(gamma0MotherLabel>-1 && gamma1MotherLabel>-1){ // Both Tracks are Photons and have a mother but not Pi0 or Eta
3293  if (fHistoTrueBckGGInvMassPt[fiCut]) fHistoTrueBckGGInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(), fWeightJetJetMC);
3294 
3295  if( (((AliAODMCParticle*)AODMCTrackArray->At(gamma0MotherLabel))->GetPdgCode() == fMesonPDG
3296  && (TrueGammaCandidate0->IsMerged() || TrueGammaCandidate0->IsMergedPartConv()))
3297  ||
3298  (((AliAODMCParticle*)AODMCTrackArray->At(gamma1MotherLabel))->GetPdgCode() == fMesonPDG
3299  && (TrueGammaCandidate1->IsMerged() || TrueGammaCandidate1->IsMergedPartConv()))
3300  ){
3302  }else if( (TrueGammaCandidate0->E()/mesonCand->E() > 0.7) || (TrueGammaCandidate1->E()/mesonCand->E() > 0.7) ){
3303  if (fHistoTrueBckAsymEClustersInvMassPt[fiCut]) fHistoTrueBckAsymEClustersInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(), fWeightJetJetMC);
3304  }
3305  } else { // No photon or without mother
3306  if (fHistoTrueBckContInvMassPt[fiCut]) fHistoTrueBckContInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(), fWeightJetJetMC);
3307  }
3308  }
3309  }
3310 }
3311 
3312 
3313 //______________________________________________________________________
3315  AliAODConversionPhoton *TrueGammaCandidate0,
3316  AliAODConversionPhoton *TrueGammaCandidate1)
3317 {
3318  // Process True Mesons
3319  const AliVVertex* primVtxMC = fMCEvent->GetPrimaryVertex();
3320  Double_t mcProdVtxX = primVtxMC->GetX();
3321  Double_t mcProdVtxY = primVtxMC->GetY();
3322  Double_t mcProdVtxZ = primVtxMC->GetZ();
3323 
3324  if(TrueGammaCandidate0->GetV0Index()<fInputEvent->GetNumberOfV0s()){
3325  Bool_t isTrueMeson = kFALSE;
3326  Bool_t isTrueMesonDalitz = kFALSE;
3327  Bool_t gamma0DalitzCand = kFALSE;
3328  Bool_t gamma1DalitzCand = kFALSE;
3329  Int_t gamma0MCLabel = TrueGammaCandidate0->GetMCParticleLabel(fMCEvent);
3330  Int_t gamma0MotherLabel = -1;
3331  if(gamma0MCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
3332  // Daughters Gamma 0
3333  TParticle * negativeMC = (TParticle*)TrueGammaCandidate0->GetNegativeMCDaughter(fMCEvent);
3334  TParticle * positiveMC = (TParticle*)TrueGammaCandidate0->GetPositiveMCDaughter(fMCEvent);
3335  TParticle * gammaMC0 = (TParticle*)fMCEvent->Particle(gamma0MCLabel);
3336  if(TMath::Abs(negativeMC->GetPdgCode())==11 && TMath::Abs(positiveMC->GetPdgCode())==11){ // Electrons ...
3337  if(negativeMC->GetUniqueID() == 5 && positiveMC->GetUniqueID() ==5){ // ... From Conversion ...
3338  if(gammaMC0->GetPdgCode() == 22){ // ... with Gamma Mother
3339  gamma0MotherLabel=gammaMC0->GetFirstMother();
3340  }
3341  }
3342  if(gammaMC0->GetPdgCode() ==fMesonPDG){ // Dalitz candidate
3343  gamma0DalitzCand = kTRUE;
3344  gamma0MotherLabel=-fMesonPDG;
3345  }
3346  }
3347  }
3348  if(TrueGammaCandidate1->GetV0Index()<fInputEvent->GetNumberOfV0s()){
3349  Int_t gamma1MCLabel = TrueGammaCandidate1->GetMCParticleLabel(fMCEvent);
3350  Int_t gamma1MotherLabel = -1;
3351  if(gamma1MCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
3352  // Daughters Gamma 1
3353  TParticle * negativeMC = (TParticle*)TrueGammaCandidate1->GetNegativeMCDaughter(fMCEvent);
3354  TParticle * positiveMC = (TParticle*)TrueGammaCandidate1->GetPositiveMCDaughter(fMCEvent);
3355  TParticle * gammaMC1 = (TParticle*)fMCEvent->Particle(gamma1MCLabel);
3356  if(TMath::Abs(negativeMC->GetPdgCode())==11 && TMath::Abs(positiveMC->GetPdgCode())==11){ // Electrons ...
3357  if(negativeMC->GetUniqueID() == 5 && positiveMC->GetUniqueID() ==5){ // ... From Conversion ...
3358  if(gammaMC1->GetPdgCode() == 22){ // ... with Gamma Mother
3359  gamma1MotherLabel=gammaMC1->GetFirstMother();
3360  }
3361  }
3362  if(gammaMC1->GetPdgCode() ==fMesonPDG ){ // Dalitz candidate
3363  gamma1DalitzCand = kTRUE;
3364  gamma1MotherLabel=-fMesonPDG;
3365  }
3366  }
3367  }
3368  if(gamma0MotherLabel>=0 && gamma0MotherLabel==gamma1MotherLabel){
3369  if(((TParticle*)fMCEvent->Particle(gamma1MotherLabel))->GetPdgCode() == fMesonPDG){
3370  isTrueMeson=kTRUE;
3374  }
3375  }
3376  }
3377 
3378  //Identify Dalitz candidate
3379  if (gamma1DalitzCand || gamma0DalitzCand){
3380  if (gamma0DalitzCand && gamma0MCLabel >=0 && gamma0MCLabel==gamma1MotherLabel){
3381  if (gamma0MotherLabel == -fMesonPDG) isTrueMesonDalitz = kTRUE;
3382  }
3383  if (gamma1DalitzCand && gamma1MCLabel >=0 && gamma1MCLabel==gamma0MotherLabel){
3384  if (gamma1MotherLabel == -fMesonPDG) isTrueMesonDalitz = kTRUE;
3385  }
3386  }
3387 
3388 
3389  if(isTrueMeson ){// True Meosn
3390  if (fHistoTrueMesonInvMassPt[fiCut])fHistoTrueMesonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(),fWeightJetJetMC);
3391  if (fDoMesonQA > 0){
3392  if ( mesonCand->M() > fMesonInvMassWindow[0] && mesonCand->M() < fMesonInvMassWindow[1]){
3393  if(fIsMC < 2){
3394  if (fHistoTrueMesonPtY[fiCut]) fHistoTrueMesonPtY[fiCut]->Fill(mesonCand->Pt(),mesonCand->Rapidity()-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift());
3395  if (fHistoTrueMesonPtOpenAngle[fiCut]) fHistoTrueMesonPtOpenAngle[fiCut]->Fill(mesonCand->Pt(),mesonCand->GetOpeningAngle());
3396  if (fHistoTrueMesonPtAlpha[fiCut]) fHistoTrueMesonPtAlpha[fiCut]->Fill(mesonCand->Pt(),mesonCand->GetAlpha(),fWeightJetJetMC);
3397  }
3398  }
3399  }
3400  Bool_t isPrimary = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsConversionPrimaryESD( fMCEvent, gamma0MotherLabel, mcProdVtxX, mcProdVtxY, mcProdVtxZ);
3401  if(isPrimary){ // Only primary pi0 for efficiency calculation
3402  Float_t weighted= 1;
3403  if(((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(gamma1MotherLabel, fMCEvent, fInputEvent)){
3404  if (((TParticle*)fMCEvent->Particle(gamma1MotherLabel))->Pt()>0.005){
3405  weighted= ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetWeightForMeson(gamma1MotherLabel, fMCEvent, fInputEvent);
3406  // cout << "rec \t " <<gamma1MotherLabel << "\t" << weighted << endl;
3407  }
3408  }
3409  if (fHistoTruePrimaryMesonInvMassPt[fiCut]) fHistoTruePrimaryMesonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(),weighted*fWeightJetJetMC);
3411  if (fProfileTruePrimaryMesonWeightsInvMassPt[fiCut]) fProfileTruePrimaryMesonWeightsInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(),weighted*fWeightJetJetMC);
3412 
3413  if (fDoMesonQA > 0 && fIsMC < 2){
3414  if (fHistoTruePrimaryMesonMCPtResolPt[fiCut]) fHistoTruePrimaryMesonMCPtResolPt[fiCut]->Fill(((TParticle*)fMCEvent->Particle(gamma1MotherLabel))->Pt(),(mesonCand->Pt()-((TParticle*)fMCEvent->Particle(gamma1MotherLabel))->Pt())/((TParticle*)fMCEvent->Particle(gamma1MotherLabel))->Pt(),weighted);
3415  }
3416  }
3417  } else if(!isTrueMeson ){ // Background
3418  if (fDoMesonQA > 1 && fIsMC < 2){
3419  if(gamma0MotherLabel>-1 && gamma1MotherLabel>-1){ // Both Tracks are Photons and have a mother but not Pi0 or Eta
3420  if (fHistoTrueBckGGInvMassPt[fiCut])fHistoTrueBckGGInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
3421  } else { // No photon or without mother
3422  if (fHistoTrueBckContInvMassPt[fiCut]) fHistoTrueBckContInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
3423  }
3424  }
3425  if (!isTrueMesonDalitz && (gamma0DalitzCand || gamma1DalitzCand)){
3426  if (fDoMesonQA > 1 && fIsMC < 2 && fHistoTrueBckContInvMassPt[fiCut]) fHistoTrueBckContInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
3427  }
3428  }
3429  }
3430  }
3431 }
3432 
3433 //______________________________________________________________________
3435  AliAODConversionPhoton *TrueGammaCandidate0,
3436  AliAODConversionPhoton *TrueGammaCandidate1)
3437 {
3438  const AliVVertex* primVtxMC = fMCEvent->GetPrimaryVertex();
3439  Double_t mcProdVtxX = primVtxMC->GetX();
3440  Double_t mcProdVtxY = primVtxMC->GetY();
3441  Double_t mcProdVtxZ = primVtxMC->GetZ();
3442 
3443  // Process True Mesons
3444  TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(fInputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
3445  Bool_t isTrueMeson = kFALSE;
3446  Bool_t isTrueMesonDalitz = kFALSE;
3447  Bool_t gamma0DalitzCand = kFALSE;
3448  Bool_t gamma1DalitzCand = kFALSE;
3449 
3450  if (AODMCTrackArray!=NULL && TrueGammaCandidate0 != NULL){
3451  AliAODMCParticle *positiveMC = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(TrueGammaCandidate0->GetMCLabelPositive()));
3452  AliAODMCParticle *negativeMC = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(TrueGammaCandidate0->GetMCLabelNegative()));
3453 
3454  Int_t gamma0MCLabel = -1;
3455  Int_t gamma0MotherLabel = -1;
3456  if(!positiveMC||!negativeMC)
3457  return;
3458 
3459  if(positiveMC->GetMother()>-1&&(negativeMC->GetMother() == positiveMC->GetMother())){
3460  gamma0MCLabel = positiveMC->GetMother();
3461  }
3462 
3463  if(gamma0MCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
3464  // Daughters Gamma 0
3465  AliAODMCParticle * gammaMC0 = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma0MCLabel));
3466  if(TMath::Abs(negativeMC->GetPdgCode())==11 && TMath::Abs(positiveMC->GetPdgCode())==11){ // Electrons ...
3467  if(((positiveMC->GetMCProcessCode())) == 5 && ((negativeMC->GetMCProcessCode())) == 5){ // ... From Conversion ...
3468  if(gammaMC0->GetPdgCode() == 22){ // ... with Gamma Mother
3469  gamma0MotherLabel=gammaMC0->GetMother();
3470  }
3471  }
3472  if(gammaMC0->GetPdgCode() ==fMesonPDG){ // Dalitz candidate
3473  gamma0DalitzCand = kTRUE;
3474  gamma0MotherLabel=-fMesonPDG;
3475  }
3476  }
3477  }
3478  positiveMC = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(TrueGammaCandidate1->GetMCLabelPositive()));
3479  negativeMC = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(TrueGammaCandidate1->GetMCLabelNegative()));
3480 
3481  Int_t gamma1MCLabel = -1;
3482  Int_t gamma1MotherLabel = -1;
3483  if(!positiveMC||!negativeMC)
3484  return;
3485 
3486  if(positiveMC->GetMother()>-1&&(negativeMC->GetMother() == positiveMC->GetMother())){
3487  gamma1MCLabel = positiveMC->GetMother();
3488  }
3489  if(gamma1MCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
3490  // Daughters Gamma 1
3491  AliAODMCParticle * gammaMC1 = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MCLabel));
3492  if(TMath::Abs(negativeMC->GetPdgCode())==11 && TMath::Abs(positiveMC->GetPdgCode())==11){ // Electrons ...
3493  if(((positiveMC->GetMCProcessCode())) == 5 && ((negativeMC->GetMCProcessCode())) == 5){ // ... From Conversion ...
3494  if(gammaMC1->GetPdgCode() == 22){ // ... with Gamma Mother
3495  gamma1MotherLabel=gammaMC1->GetMother();
3496  }
3497  }
3498  if(gammaMC1->GetPdgCode() ==fMesonPDG ){ // Dalitz candidate
3499  gamma1DalitzCand = kTRUE;
3500  gamma1MotherLabel=-fMesonPDG;
3501  }
3502  }
3503  }
3504  if(gamma0MotherLabel>=0 && gamma0MotherLabel==gamma1MotherLabel){
3505  if(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->GetPdgCode() == fMesonPDG){
3506  isTrueMeson=kTRUE;
3510  }
3511  }
3512  }
3513 
3514  //Identify Dalitz candidate
3515  if (gamma1DalitzCand || gamma0DalitzCand){
3516  if (gamma0DalitzCand && gamma0MCLabel >=0 && gamma0MCLabel==gamma1MotherLabel){
3517  if (gamma0MotherLabel == -fMesonPDG) isTrueMesonDalitz = kTRUE;
3518  }
3519  if (gamma1DalitzCand && gamma1MCLabel >=0 && gamma1MCLabel==gamma0MotherLabel){
3520  if (gamma1MotherLabel == -fMesonPDG) isTrueMesonDalitz = kTRUE;
3521  }
3522  }
3523 
3524  if(isTrueMeson ){// True Meson
3525  if (fHistoTrueMesonInvMassPt[fiCut])fHistoTrueMesonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(),fWeightJetJetMC);
3526  if (fDoMesonQA > 0){
3527  if ( mesonCand->M() > fMesonInvMassWindow[0] && mesonCand->M() < fMesonInvMassWindow[1]){
3528  if(fIsMC < 2){
3529  if (fHistoTrueMesonPtY[fiCut]) fHistoTrueMesonPtY[fiCut]->Fill(mesonCand->Pt(),mesonCand->Rapidity()-((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift());
3530  if (fHistoTrueMesonPtOpenAngle[fiCut]) fHistoTrueMesonPtOpenAngle[fiCut]->Fill(mesonCand->Pt(),mesonCand->GetOpeningAngle());
3531  }
3532  if (fHistoTrueMesonPtAlpha[fiCut]) fHistoTrueMesonPtAlpha[fiCut]->Fill(mesonCand->Pt(),mesonCand->GetAlpha(),fWeightJetJetMC);
3533  }
3534 
3535  }
3536  Bool_t isPrimary = ((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsConversionPrimaryAOD(fInputEvent, static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma0MotherLabel)), mcProdVtxX, mcProdVtxY, mcProdVtxZ);
3537 
3538  if(isPrimary){ // Only primary pi0 for efficiency calculation
3539  Float_t weighted= 1;
3540  if(((AliConvEventCuts*)fEventCutArray->At(fiCut))->IsParticleFromBGEvent(gamma1MotherLabel, 0x0, fInputEvent)){
3541  if (static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt()>0.005){
3542  weighted= ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetWeightForMeson(gamma1MotherLabel, 0x0, fInputEvent);
3543  // cout << "rec \t " <<gamma1MotherLabel << "\t" << weighted << endl;
3544  }
3545  }
3546  if (fHistoTruePrimaryMesonInvMassPt[fiCut]) fHistoTruePrimaryMesonInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(),weighted*fWeightJetJetMC);
3548  if (fProfileTruePrimaryMesonWeightsInvMassPt[fiCut]) fProfileTruePrimaryMesonWeightsInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt(),weighted*fWeightJetJetMC);
3549 
3550  if (fDoMesonQA > 0 && fIsMC < 2){
3551  if (fHistoTruePrimaryMesonMCPtResolPt[fiCut])fHistoTruePrimaryMesonMCPtResolPt[fiCut]->Fill(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt(),
3552  (mesonCand->Pt()-static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt())/static_cast<AliAODMCParticle*>(AODMCTrackArray->At(gamma1MotherLabel))->Pt(),weighted);
3553  }
3554  }
3555  } else if(!isTrueMeson ) { // Background
3556  if (fDoMesonQA > 1 && fIsMC < 2){
3557  if(!(gamma0MotherLabel>-1 && gamma1MotherLabel>-1)){ // Both Tracks are Photons and have a mother but not Pi0 or Eta
3558  if (fHistoTrueBckGGInvMassPt[fiCut])fHistoTrueBckGGInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
3559  } else { // No photon or without mother
3560  if (fHistoTrueBckContInvMassPt[fiCut]) fHistoTrueBckContInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
3561  }
3562  }
3563  if (!isTrueMesonDalitz && (gamma0DalitzCand || gamma1DalitzCand)){
3564  if (fDoMesonQA > 1 && fIsMC < 2)if (fHistoTrueBckContInvMassPt[fiCut]) fHistoTrueBckContInvMassPt[fiCut]->Fill(mesonCand->M(),mesonCand->Pt());
3565  }
3566  }
3567  }
3568  return;
3569 }
3570 
3571 
3572 //________________________________________________________________________
3574 
3575  // set current BG handler
3576  AliGammaConversionAODBGHandler* currBGHandler = NULL;
3577  TList* currPhotonList = NULL;
3578  if (fMesonRecoMode == 0){
3579  currBGHandler = fBGHandler[fiCut];
3580  currPhotonList = fGammaCandidates;
3581  } else if (fMesonRecoMode == 1){
3582  currBGHandler = fBGClusHandler[fiCut];
3583  currPhotonList = fGammaCandidates;
3584  } else if (fMesonRecoMode == 2){
3585  currBGHandler = fBGClusHandler[fiCut];
3586  currPhotonList = fClusterCandidates;
3587  }
3588 
3589  Int_t zbin = currBGHandler->GetZBinIndex(fInputEvent->GetPrimaryVertex()->GetZ());
3590  Int_t mbin = 0;
3591  if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
3593  } else {
3594  mbin = currBGHandler->GetMultiplicityBinIndex(currPhotonList->GetEntries());
3595  }
3596 
3598  if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
3599  for(Int_t nEventsInBG=0;nEventsInBG<currBGHandler->GetNBGEvents();nEventsInBG++){
3600  AliGammaConversionAODVector *previousEventV0s = currBGHandler->GetBGGoodV0s(zbin,mbin,nEventsInBG);
3601  if (fMesonRecoMode < 2){
3602  if(fMoveParticleAccordingToVertex == kTRUE || ((AliConversionPhotonCuts*)fCutArray->At(fiCut))->GetInPlaneOutOfPlaneCut() != 0 ){
3603  bgEventVertex = currBGHandler->GetBGEventVertex(zbin,mbin,nEventsInBG);
3604  }
3605  }
3606  for(Int_t iCurrent=0;iCurrent<currPhotonList->GetEntries();iCurrent++){
3607  AliAODConversionPhoton currentEventGoodV0 = *(AliAODConversionPhoton*)(currPhotonList->At(iCurrent));
3608  if (!currentEventGoodV0.GetUseForMesonPair() )continue;
3609  for(UInt_t iPrevious=0;iPrevious<previousEventV0s->size();iPrevious++){
3610  AliAODConversionPhoton previousGoodV0 = (AliAODConversionPhoton)(*(previousEventV0s->at(iPrevious)));
3611  if(fMoveParticleAccordingToVertex == kTRUE){
3612  if (bgEventVertex){
3613  MoveParticleAccordingToVertex(&previousGoodV0,bgEventVertex);
3614  }
3615  }
3616  if (fMesonRecoMode < 2){
3617  if(((AliConversionPhotonCuts*)fCutArray->At(fiCut))->GetInPlaneOutOfPlaneCut() != 0){
3618  if (bgEventVertex){
3619  RotateParticleAccordingToEP(&previousGoodV0,bgEventVertex->fEP,fEventPlaneAngle);
3620  }
3621  }
3622  }
3623  AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&previousGoodV0);
3624  backgroundCandidate->CalculateDistanceOfClossetApproachToPrimVtx(fInputEvent->GetPrimaryVertex());
3625  if((((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(backgroundCandidate, kFALSE,
3626  ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift()), currentEventGoodV0.GetLeadingCellID(), previousGoodV0.GetLeadingCellID())){
3627  if (fHistoMotherBackInvMassPt[fiCut]) fHistoMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt(),fWeightJetJetMC);
3628  if(fDoTHnSparse){
3629  Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
3630  if (fSparseMotherBackInvMassPtZM[fiCut]) fSparseMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
3631  }
3632  }
3633  }
3634  }
3635  }
3636  }else {
3637  for(Int_t nEventsInBG=0;nEventsInBG <currBGHandler->GetNBGEvents();nEventsInBG++){
3638  AliGammaConversionAODVector *previousEventV0s = currBGHandler->GetBGGoodV0s(zbin,mbin,nEventsInBG);
3639  if(previousEventV0s){
3640  if (fMesonRecoMode < 2){
3641  if(fMoveParticleAccordingToVertex == kTRUE || ((AliConversionPhotonCuts*)fCutArray->At(fiCut))->GetInPlaneOutOfPlaneCut() != 0 ){
3642  bgEventVertex = currBGHandler->GetBGEventVertex(zbin,mbin,nEventsInBG);
3643  }
3644  }
3645  for(Int_t iCurrent=0;iCurrent<currPhotonList->GetEntries();iCurrent++){
3646  AliAODConversionPhoton currentEventGoodV0 = *(AliAODConversionPhoton*)(currPhotonList->At(iCurrent));
3647  if (!currentEventGoodV0.GetUseForMesonPair() )continue;
3648  for(UInt_t iPrevious=0;iPrevious<previousEventV0s->size();iPrevious++){
3649  AliAODConversionPhoton previousGoodV0 = (AliAODConversionPhoton)(*(previousEventV0s->at(iPrevious)));
3650  if(fMoveParticleAccordingToVertex == kTRUE){
3651  if (bgEventVertex){
3652  MoveParticleAccordingToVertex(&previousGoodV0,bgEventVertex);
3653  }
3654  }
3655  if (fMesonRecoMode < 2){
3656  if(((AliConversionPhotonCuts*)fCutArray->At(fiCut))->GetInPlaneOutOfPlaneCut() != 0){
3657  if (bgEventVertex){
3658  RotateParticleAccordingToEP(&previousGoodV0,bgEventVertex->fEP,fEventPlaneAngle);
3659  }
3660  }
3661  }
3662  AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&previousGoodV0);
3663  backgroundCandidate->CalculateDistanceOfClossetApproachToPrimVtx(fInputEvent->GetPrimaryVertex());
3664  if((((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(backgroundCandidate,kFALSE,
3665  ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift()), currentEventGoodV0.GetLeadingCellID(), previousGoodV0.GetLeadingCellID())){
3666  if (fHistoMotherBackInvMassPt[fiCut]) fHistoMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt(),fWeightJetJetMC);
3667  if(fDoTHnSparse){
3668  Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
3669  if (fSparseMotherBackInvMassPtZM[fiCut]) fSparseMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
3670  }
3671  }
3672  delete backgroundCandidate;
3673  backgroundCandidate = 0x0;
3674  }
3675  }
3676  }
3677  }
3678  }
3679 }
3680 
3681 //________________________________________________________________________
3683 
3684  // set current BG handler
3685  AliConversionAODBGHandlerRP* currBGHandler = NULL;
3686  TList* currPhotonList = NULL;
3687  if (fMesonRecoMode == 0){
3688  currBGHandler = fBGHandlerRP[fiCut];
3689  currPhotonList = fGammaCandidates;
3690  } else if (fMesonRecoMode == 1){
3691  currBGHandler = fBGClusHandlerRP[fiCut];
3692  currPhotonList = fGammaCandidates;
3693  } else if (fMesonRecoMode == 2){
3694  currBGHandler = fBGClusHandlerRP[fiCut];
3695  currPhotonList = fClusterCandidates;
3696  }
3697 
3698  Int_t zbin = currBGHandler->GetZBinIndex(fInputEvent->GetPrimaryVertex()->GetZ());
3699  Int_t mbin = 0;
3700  if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
3702  } else {
3703  mbin = currBGHandler->GetMultiplicityBinIndex(currPhotonList->GetEntries());
3704  }
3705 
3706  //Rotation Method
3707  if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseRotationMethod()){
3708  // Correct for the number of rotations
3709  // BG is for rotation the same, except for factor NRotations
3710  Double_t weight=1./Double_t(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->GetNumberOfBGEvents());
3711  for(Int_t firstGammaIndex=0;firstGammaIndex<currPhotonList->GetEntries();firstGammaIndex++){
3712  AliAODConversionPhoton *gamma0=dynamic_cast<AliAODConversionPhoton*>(currPhotonList->At(firstGammaIndex));
3713  if (gamma0==NULL) continue;
3714  if (!gamma0->GetUseForMesonPair() ) continue;
3715  for(Int_t secondGammaIndex=firstGammaIndex+1;secondGammaIndex<currPhotonList->GetEntries();secondGammaIndex++){
3716  AliAODConversionPhoton *gamma1=dynamic_cast<AliAODConversionPhoton*>(currPhotonList->At(secondGammaIndex));
3717  if (gamma1 == NULL) continue;
3718  if (!gamma1->GetUseForMesonPair() ) continue;
3719  if(!((AliConversionPhotonCuts*)fCutArray->At(fiCut))->PhotonIsSelected(gamma1,fInputEvent))continue;
3720  for(Int_t nRandom=0;nRandom<((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->GetNumberOfBGEvents();nRandom++){
3721  RotateParticle(gamma1);
3722  AliAODConversionMother backgroundCandidate(gamma0,gamma1);
3723  backgroundCandidate.CalculateDistanceOfClossetApproachToPrimVtx(fInputEvent->GetPrimaryVertex());
3724  if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(&backgroundCandidate, kFALSE, ((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift())){
3725 
3726  if (fHistoMotherBackInvMassPt[fiCut]) fHistoMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate.M(),backgroundCandidate.Pt(),fWeightJetJetMC);
3727  if(fDoTHnSparse){
3728  Double_t sparesFill[4] = {backgroundCandidate.M(),backgroundCandidate.Pt(),(Double_t)zbin,(Double_t)mbin};
3729  if (fSparseMotherBackInvMassPtZM[fiCut]) fSparseMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,weight);
3730  }
3731  }
3732  }
3733  }
3734  }
3735 
3736  }else {
3737  // Do Event Mixing
3738  for(Int_t nEventsInBG=0;nEventsInBG <currBGHandler->GetNBGEvents(currPhotonList,fInputEvent);nEventsInBG++){
3739  AliGammaConversionPhotonVector *previousEventGammas = currBGHandler->GetBGGoodGammas(currPhotonList,fInputEvent,nEventsInBG);
3740  if(previousEventGammas){
3741  // test weighted background
3742  Double_t weight=1.0;
3743  // Correct for the number of eventmixing:
3744  // N gammas -> (N-1) + (N-2) +(N-3) ...+ (N-(N-1)) using sum formula sum(i)=N*(N-1)/2 -> N*(N-1)/2
3745  // real combinations (since you cannot combine a photon with its own)
3746  // but BG leads to N_{a}*N_{b}combinations
3747  weight*=0.5*(Double_t(currPhotonList->GetEntries()-1))/Double_t(previousEventGammas->size());
3748 
3749  for(Int_t iCurrent=0;iCurrent<currPhotonList->GetEntries();iCurrent++){
3750  AliAODConversionPhoton *gamma0 = (AliAODConversionPhoton*)(currPhotonList->At(iCurrent));
3751  if (!gamma0->GetUseForMesonPair() ) continue;
3752  for(UInt_t iPrevious=0;iPrevious<previousEventGammas->size();iPrevious++){
3753  AliAODConversionPhoton *gamma1 = (AliAODConversionPhoton*)(previousEventGammas->at(iPrevious));
3754  AliAODConversionMother backgroundCandidate(gamma0,gamma1);
3755  backgroundCandidate.CalculateDistanceOfClossetApproachToPrimVtx(fInputEvent->GetPrimaryVertex());
3757  ->MesonIsSelected(&backgroundCandidate,kFALSE,((AliConvEventCuts*)fEventCutArray->At(fiCut))->GetEtaShift())){
3758  if (fHistoMotherBackInvMassPt[fiCut]) fHistoMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate.M(),backgroundCandidate.Pt(),fWeightJetJetMC);
3759  if(fDoTHnSparse){
3760  Double_t sparesFill[4] = {backgroundCandidate.M(),backgroundCandidate.Pt(),(Double_t)zbin,(Double_t)mbin};
3761  if (fSparseMotherBackInvMassPtZM[fiCut]) fSparseMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,weight);
3762  }
3763  }
3764  }
3765  }
3766  }
3767  }
3768  }
3769 }
3770 
3771 //________________________________________________________________________
3773  Int_t fNDegreesPMBackground= ((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->NDegreesRotation();
3774  Double_t nRadiansPM = fNDegreesPMBackground*TMath::Pi()/180;
3775  Double_t rotationValue = fRandom.Rndm()*2*nRadiansPM + TMath::Pi()-nRadiansPM;
3776  gamma->RotateZ(rotationValue);
3777 }
3778 
3779 //________________________________________________________________________
3781  previousEventEP=previousEventEP+TMath::Pi();
3782  thisEventEP=thisEventEP+TMath::Pi();
3783  Double_t rotationValue= thisEventEP-previousEventEP;
3784  gamma->RotateZ(rotationValue);
3785 }
3786 
3787 //________________________________________________________________________
3789  //see header file for documentation
3790 
3791  Double_t dx = vertex->fX - fInputEvent->GetPrimaryVertex()->GetX();
3792  Double_t dy = vertex->fY - fInputEvent->GetPrimaryVertex()->GetY();
3793  Double_t dz = vertex->fZ - fInputEvent->GetPrimaryVertex()->GetZ();
3794 
3795  Double_t movedPlace[3] = {particle->GetConversionX() - dx,particle->GetConversionY() - dy,particle->GetConversionZ() - dz};
3796  particle->SetConversionPoint(movedPlace);
3797 }
3798 //________________________________________________________________________
3800  //see header file for documentation
3801  if(fGammaCandidates->GetEntries() >0 && fMesonRecoMode == 0 ){
3802  if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
3803  fBGHandler[fiCut]->AddEvent(fGammaCandidates,fInputEvent->GetPrimaryVertex()->GetX(), fInputEvent->GetPrimaryVertex()->GetY(), fInputEvent->GetPrimaryVertex()->GetZ(),
3805  }else { // means we use #V0s for multiplicity
3806  fBGHandler[fiCut]->AddEvent(fGammaCandidates, fInputEvent->GetPrimaryVertex()->GetX(), fInputEvent->GetPrimaryVertex()->GetY(), fInputEvent->GetPrimaryVertex()->GetZ(),
3807  fGammaCandidates->GetEntries(), fEventPlaneAngle);
3808  }
3809  } else if((fGammaCandidates->GetEntries() >0 || fClusterCandidates->GetEntries() > 0 ) && fMesonRecoMode == 1 ){
3810  if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
3811  fBGHandler[fiCut]->AddEvent(fGammaCandidates,fInputEvent->GetPrimaryVertex()->GetX(), fInputEvent->GetPrimaryVertex()->GetY(), fInputEvent->GetPrimaryVertex()->GetZ(),
3813  fBGClusHandler[fiCut]->AddEvent(fClusterCandidates,fInputEvent->GetPrimaryVertex()->GetX(), fInputEvent->GetPrimaryVertex()->GetY(), fInputEvent->GetPrimaryVertex()->GetZ(),
3815  }else { // means we use #V0s for multiplicity
3816  fBGHandler[fiCut]->AddEvent(fGammaCandidates, fInputEvent->GetPrimaryVertex()->GetX(), fInputEvent->GetPrimaryVertex()->GetY(), fInputEvent->GetPrimaryVertex()->GetZ(),
3817  fGammaCandidates->GetEntries(), fEventPlaneAngle);
3818  fBGClusHandler[fiCut]->AddEvent(fClusterCandidates, fInputEvent->GetPrimaryVertex()->GetX(), fInputEvent->GetPrimaryVertex()->GetY(), fInputEvent->GetPrimaryVertex()->GetZ(),
3819  fGammaCandidates->GetEntries(), fEventPlaneAngle);
3820  }
3821  } else if(fClusterCandidates->GetEntries() >0 && fMesonRecoMode == 2 ){
3822  if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
3823  fBGClusHandler[fiCut]->AddEvent(fClusterCandidates,fInputEvent->GetPrimaryVertex()->GetX(), fInputEvent->GetPrimaryVertex()->GetY(),