TENDER becomes Tender, removing .so
[u/mrichter/AliRoot.git] / PWGGA / GammaConv / AliCaloPhotonCuts.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                                                                *
4  * Authors: Friederike Bock, Baldo Sahlmueller                                *
5  * Version 1.0                                                                                    *
6  *                                                                                                                *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                          *
14  **************************************************************************/
15
16 ////////////////////////////////////////////////
17 //---------------------------------------------
18 // Class handling all kinds of selection cuts for
19 // Photon from EMCAL clusters
20 //---------------------------------------------
21 ////////////////////////////////////////////////
22
23 #include "AliCaloPhotonCuts.h"
24 #include "AliAnalysisManager.h"
25 #include "AliInputEventHandler.h"
26 #include "AliMCEventHandler.h"
27 #include "AliAODHandler.h"
28 #include "TH1.h"
29 #include "TH2.h"
30 #include "TF1.h"
31 #include "AliStack.h"
32 #include "AliAODConversionMother.h"
33 #include "AliAODConversionPhoton.h"
34 #include "TObjString.h"
35 #include "AliAODEvent.h"
36 #include "AliESDEvent.h"
37 #include "AliCentrality.h"
38 #include "TList.h"
39 #include "TFile.h"
40 #include "AliLog.h"
41 #include "AliV0ReaderV1.h"
42 #include "AliAODMCParticle.h"
43 #include "AliAODMCHeader.h"
44 #include "AliPicoTrack.h"
45 #include "AliEMCALRecoUtils.h"
46 #include "AliTrackerBase.h"
47
48 class iostream;
49
50 using namespace std;
51
52 ClassImp(AliCaloPhotonCuts)
53
54
55 const char* AliCaloPhotonCuts::fgkCutNames[AliCaloPhotonCuts::kNCuts] = {
56         "ClusterType",          //0   0: all,    1: EMCAL,   2: PHOS
57         "EtaMin",               //1   0: -10,    1: -0.6687, 2: -0,5, 3: -2
58         "EtaMax",               //2   0: 10,     1: 0.66465, 2: 0.5,  3: 2
59         "PhiMin",               //3   0: -10000, 1: 1.39626
60         "PhiMax",               //4   0: 10000, 1: 3.125
61         "DistanceToBadChannel", //5   0: 0,      1: 5
62         "Timing",               //6   0: no cut
63         "TrackMatching",        //7   0: 0,      1: 5
64         "ExoticCell",           //8   0: no cut
65         "MinEnergy",            //9   0: no cut, 1: 0.05,    2: 0.1,  3: 0.15, 4: 0.2, 5: 0.3, 6: 0.5, 7: 0.75, 8: 1, 9: 1.25 (all GeV)
66         "MinNCells",            //10  0: no cut, 1: 1,       2: 2,    3: 3,    4: 4,   5: 5,   6: 6
67         "MinM02",                               //11
68         "MaxM02",                               //12
69         "MinM20",                               //13
70         "MaxM20",                               //14
71         "MaximumDispersion",    //15
72         "NLM"                                   //16
73 };
74
75
76 //________________________________________________________________________
77 AliCaloPhotonCuts::AliCaloPhotonCuts(const char *name,const char *title) :
78         AliAnalysisCuts(name,title),
79         fHistograms(NULL),      
80         fClusterType(0),
81         fMinEtaCut(-10),
82         fMaxEtaCut(10),
83         fUseEtaCut(0),
84         fMinPhiCut(-10000),
85         fMaxPhiCut(-10000),
86         fUsePhiCut(0),
87         fMinDistanceToBadChannel(0),
88         fUseDistanceToBadChannel(0),
89         fMaxTimeDiff(10e10),
90         fUseTimeDiff(0),
91     fMaxDistTrackToClusterEta(0),
92     fMinDistTrackToClusterPhi(0),
93     fMaxDistTrackToClusterPhi(0),
94         fUseDistTrackToCluster(0),
95     fExtendedMatching(kFALSE),
96         fExoticCell(0),
97         fUseExoticCell(0),
98         fMinEnergy(0),
99         fUseMinEnergy(0),
100         fMinNCells(0),
101         fUseNCells(0),
102         fMaxM02(1000),
103         fMinM02(0),
104         fUseM02(0),
105         fMaxM20(1000),
106         fMinM20(0),
107         fUseM20(0),
108         fMaxDispersion(1000),
109         fUseDispersion(0),
110         fMinNLM(0),
111         fMaxNLM(1000),
112         fUseNLM(0),
113         fCutString(NULL),
114         fHistCutIndex(NULL),
115         fHistAcceptanceCuts(NULL),
116         fHistClusterIdentificationCuts(NULL),
117         fHistClusterEtavsPhiBeforeAcc(NULL),
118         fHistClusterEtavsPhiAfterAcc(NULL),
119         fHistClusterEtavsPhiAfterQA(NULL),
120     //fHistDistanceToBadChannelBeforeAcc(NULL),
121     //fHistDistanceToBadChannelAfterAcc(NULL),
122         fHistClusterTimevsEBeforeQA(NULL),
123         fHistClusterTimevsEAfterQA(NULL),
124     //fHistExoticCellBeforeQA(NULL),
125     //fHistExoticCellAfterQA(NULL),
126     //fHistNMatchedTracks(NULL),
127         fHistEnergyOfClusterBeforeQA(NULL),
128         fHistEnergyOfClusterAfterQA(NULL),
129         fHistNCellsBeforeQA(NULL),
130         fHistNCellsAfterQA(NULL),
131         fHistM02BeforeQA(NULL),
132         fHistM02AfterQA(NULL),
133         fHistM20BeforeQA(NULL),
134         fHistM20AfterQA(NULL),
135         fHistDispersionBeforeQA(NULL),
136     fHistDispersionAfterQA(NULL),
137     //fHistNLMBeforeQA(NULL),
138     //fHistNLMAfterQA(NULL),
139     fHistClusterRBeforeQA(NULL),
140     fHistClusterRAfterQA(NULL),
141     fHistClusterdEtadPhiBeforeQA(NULL),
142     fHistClusterdEtadPhiAfterQA(NULL),
143     fHistDistanceTrackToClusterBeforeQA(NULL),
144     fHistDistanceTrackToClusterAfterQA(NULL),
145     fHistClusterdEtadPhiPosTracksBeforeQA(NULL),
146     fHistClusterdEtadPhiNegTracksBeforeQA(NULL),
147     fHistClusterdEtadPhiPosTracksAfterQA(NULL),
148     fHistClusterdEtadPhiNegTracksAfterQA(NULL),
149     fHistClusterdEtadPhiPosTracks_P1_BeforeQA(NULL),
150     fHistClusterdEtadPhiPosTracks_P14_BeforeQA(NULL),
151     fHistClusterdEtadPhiPosTracks_P4_BeforeQA(NULL),
152     fHistClusterdEtadPhiNegTracks_P1_BeforeQA(NULL),
153     fHistClusterdEtadPhiNegTracks_P14_BeforeQA(NULL),
154     fHistClusterdEtadPhiNegTracks_P4_BeforeQA(NULL),
155     fHistClusterdEtadPtBeforeQA(NULL),
156     fHistClusterdPhidPtBeforeQA(NULL),
157     fHistClusterM20Pt_dPhiBeforeQA(NULL),
158     fHistClusterM02Pt_dPhiBeforeQA(NULL),
159     fHistClusterM20M02BeforeQA(NULL),
160     fHistClusterM20M02AfterQA(NULL)
161 {
162    for(Int_t jj=0;jj<kNCuts;jj++){fCuts[jj]=0;}
163    fCutString=new TObjString((GetCutNumber()).Data());
164 }
165
166 //________________________________________________________________________
167 AliCaloPhotonCuts::AliCaloPhotonCuts(const AliCaloPhotonCuts &ref) :
168    AliAnalysisCuts(ref),
169         fHistograms(NULL),      
170         fClusterType(ref.fClusterType),
171         fMinEtaCut(ref.fMinEtaCut),
172         fMaxEtaCut(ref.fMaxEtaCut),
173         fUseEtaCut(ref.fUseEtaCut),
174         fMinPhiCut(ref.fMinPhiCut),
175         fMaxPhiCut(ref.fMaxPhiCut),
176         fUsePhiCut(ref.fUsePhiCut),
177         fMinDistanceToBadChannel(ref.fMinDistanceToBadChannel),
178         fUseDistanceToBadChannel(ref.fUseDistanceToBadChannel),
179         fMaxTimeDiff(ref.fMaxTimeDiff),
180         fUseTimeDiff(ref.fUseTimeDiff),
181     fMaxDistTrackToClusterEta(ref.fMaxDistTrackToClusterEta),
182     fMinDistTrackToClusterPhi(ref.fMinDistTrackToClusterPhi),
183     fMaxDistTrackToClusterPhi(ref.fMaxDistTrackToClusterPhi),
184         fUseDistTrackToCluster(ref.fUseDistTrackToCluster),
185     fExtendedMatching(ref.fExtendedMatching),
186         fExoticCell(ref.fExoticCell),
187         fUseExoticCell(ref.fUseExoticCell),
188         fMinEnergy(ref.fMinEnergy),
189         fUseMinEnergy(ref.fUseMinEnergy),
190         fMinNCells(ref.fMinNCells),
191         fUseNCells(ref.fUseNCells),
192         fMaxM02(ref.fMaxM02),
193         fMinM02(ref.fMinM02),
194         fUseM02(ref.fUseM02),
195         fMaxM20(ref.fMaxM20),
196         fMinM20(ref.fMinM20),
197         fUseM20(ref.fUseDispersion),
198         fMaxDispersion(ref.fMaxDispersion),
199         fUseDispersion(ref.fUseDispersion),
200         fMinNLM(ref.fMinNLM),
201         fMaxNLM(ref.fMaxNLM),
202         fUseNLM(ref.fUseNLM),
203         fCutString(NULL),
204         fHistCutIndex(NULL),
205         fHistAcceptanceCuts(NULL),
206         fHistClusterIdentificationCuts(NULL),
207         fHistClusterEtavsPhiBeforeAcc(NULL),
208         fHistClusterEtavsPhiAfterAcc(NULL),
209         fHistClusterEtavsPhiAfterQA(NULL),
210     //fHistDistanceToBadChannelBeforeAcc(NULL),
211     //fHistDistanceToBadChannelAfterAcc(NULL),
212         fHistClusterTimevsEBeforeQA(NULL),
213         fHistClusterTimevsEAfterQA(NULL),
214     //fHistExoticCellBeforeQA(NULL),
215     //fHistExoticCellAfterQA(NULL),
216     //fHistNMatchedTracks(NULL),
217         fHistEnergyOfClusterBeforeQA(NULL),
218         fHistEnergyOfClusterAfterQA(NULL),
219         fHistNCellsBeforeQA(NULL),
220         fHistNCellsAfterQA(NULL),
221         fHistM02BeforeQA(NULL),
222         fHistM02AfterQA(NULL),
223         fHistM20BeforeQA(NULL),
224         fHistM20AfterQA(NULL),
225         fHistDispersionBeforeQA(NULL),
226     fHistDispersionAfterQA(NULL),
227     //fHistNLMBeforeQA(NULL),
228     //fHistNLMAfterQA(NULL),
229     fHistClusterRBeforeQA(NULL),
230     fHistClusterRAfterQA(NULL),
231     fHistClusterdEtadPhiBeforeQA(NULL),
232     fHistClusterdEtadPhiAfterQA(NULL),
233     fHistDistanceTrackToClusterBeforeQA(NULL),
234     fHistDistanceTrackToClusterAfterQA(NULL),
235     fHistClusterdEtadPhiPosTracksBeforeQA(NULL),
236     fHistClusterdEtadPhiNegTracksBeforeQA(NULL),
237     fHistClusterdEtadPhiPosTracksAfterQA(NULL),
238     fHistClusterdEtadPhiNegTracksAfterQA(NULL),
239     fHistClusterdEtadPhiPosTracks_P1_BeforeQA(NULL),
240     fHistClusterdEtadPhiPosTracks_P14_BeforeQA(NULL),
241     fHistClusterdEtadPhiPosTracks_P4_BeforeQA(NULL),
242     fHistClusterdEtadPhiNegTracks_P1_BeforeQA(NULL),
243     fHistClusterdEtadPhiNegTracks_P14_BeforeQA(NULL),
244     fHistClusterdEtadPhiNegTracks_P4_BeforeQA(NULL),
245     fHistClusterdEtadPtBeforeQA(NULL),
246     fHistClusterdPhidPtBeforeQA(NULL),
247     fHistClusterM20Pt_dPhiBeforeQA(NULL),
248     fHistClusterM02Pt_dPhiBeforeQA(NULL),
249     fHistClusterM20M02BeforeQA(NULL),
250     fHistClusterM20M02AfterQA(NULL)
251 {
252    // Copy Constructor
253    for(Int_t jj=0;jj<kNCuts;jj++){fCuts[jj]=ref.fCuts[jj];}
254    fCutString=new TObjString((GetCutNumber()).Data());
255
256 }
257
258
259 //________________________________________________________________________
260 AliCaloPhotonCuts::~AliCaloPhotonCuts() {
261    // Destructor
262    //Deleting fHistograms leads to seg fault it it's added to output collection of a task
263    // if(fHistograms)
264    //    delete fHistograms;
265    // fHistograms = NULL;
266    if(fCutString != NULL){
267       delete fCutString;
268       fCutString = NULL;
269    }
270 }
271
272 //________________________________________________________________________
273 void AliCaloPhotonCuts::InitCutHistograms(TString name){
274
275         // Initialize Cut Histograms for QA (only initialized and filled if function is called)
276         TH1::AddDirectory(kFALSE);
277
278         if(fHistograms != NULL){
279                 delete fHistograms;
280                 fHistograms=NULL;
281         }
282         if(fHistograms==NULL){
283                 fHistograms=new TList();
284                 fHistograms->SetOwner(kTRUE);
285                 if(name=="")fHistograms->SetName(Form("CaloCuts_%s",GetCutNumber().Data()));
286                 else fHistograms->SetName(Form("%s_%s",name.Data(),GetCutNumber().Data()));
287         }
288
289         // IsPhotonSelected
290         fHistCutIndex=new TH1F(Form("IsPhotonSelected %s",GetCutNumber().Data()),"IsPhotonSelected",5,-0.5,4.5);
291         fHistCutIndex->GetXaxis()->SetBinLabel(kPhotonIn+1,"in");
292         fHistCutIndex->GetXaxis()->SetBinLabel(kDetector+1,"detector");
293         fHistCutIndex->GetXaxis()->SetBinLabel(kAcceptance+1,"acceptance");
294         fHistCutIndex->GetXaxis()->SetBinLabel(kClusterQuality+1,"cluster QA");
295         fHistCutIndex->GetXaxis()->SetBinLabel(kPhotonOut+1,"out");
296         fHistograms->Add(fHistCutIndex);
297
298         // Acceptance Cuts
299         fHistAcceptanceCuts=new TH1F(Form("AcceptanceCuts %s",GetCutNumber().Data()),"AcceptanceCuts",5,-0.5,4.5);
300         fHistAcceptanceCuts->GetXaxis()->SetBinLabel(1,"in");
301         fHistAcceptanceCuts->GetXaxis()->SetBinLabel(2,"eta");
302         fHistAcceptanceCuts->GetXaxis()->SetBinLabel(3,"phi");
303         fHistAcceptanceCuts->GetXaxis()->SetBinLabel(4,"distance to bad channel");
304         fHistAcceptanceCuts->GetXaxis()->SetBinLabel(5,"out");
305         fHistograms->Add(fHistAcceptanceCuts);
306
307         // Cluster Cuts
308         fHistClusterIdentificationCuts =new TH1F(Form("ClusterQualityCuts %s",GetCutNumber().Data()),"ClusterQualityCuts",11,-0.5,10.5);
309         fHistClusterIdentificationCuts->GetXaxis()->SetBinLabel(1,"in");
310         fHistClusterIdentificationCuts->GetXaxis()->SetBinLabel(2,"timing");
311         fHistClusterIdentificationCuts->GetXaxis()->SetBinLabel(3,"track matching");
312         fHistClusterIdentificationCuts->GetXaxis()->SetBinLabel(4,"Exotics");
313         fHistClusterIdentificationCuts->GetXaxis()->SetBinLabel(5,"minimum energy");
314         fHistClusterIdentificationCuts->GetXaxis()->SetBinLabel(6,"minimum NCells");
315         fHistClusterIdentificationCuts->GetXaxis()->SetBinLabel(7,"M02");
316         fHistClusterIdentificationCuts->GetXaxis()->SetBinLabel(8,"M20");
317         fHistClusterIdentificationCuts->GetXaxis()->SetBinLabel(9,"dispersion");
318         fHistClusterIdentificationCuts->GetXaxis()->SetBinLabel(10,"NLM");
319         fHistClusterIdentificationCuts->GetXaxis()->SetBinLabel(11,"out");
320         fHistograms->Add(fHistClusterIdentificationCuts);
321
322         // Acceptance related histogramms
323     fHistClusterEtavsPhiBeforeAcc=new TH2F(Form("EtaPhi_beforeAcceptance %s",GetCutNumber().Data()),"EtaPhi_beforeAcceptance",430,0,2*TMath::Pi(),96,-0.7,0.7); // 462->430, 110->96
324         fHistograms->Add(fHistClusterEtavsPhiBeforeAcc);
325     fHistClusterEtavsPhiAfterAcc=new TH2F(Form("EtaPhi_afterAcceptance %s",GetCutNumber().Data()),"EtaPhi_afterAcceptance",430,0,2*TMath::Pi(),96,-0.7,0.7); // 462->430, 110->96
326         fHistograms->Add(fHistClusterEtavsPhiAfterAcc);
327     fHistClusterEtavsPhiAfterQA=new TH2F(Form("EtaPhi_afterClusterQA %s",GetCutNumber().Data()),"EtaPhi_afterClusterQA",430,0,2*TMath::Pi(),96,-0.7,0.7); // 462->430, 110->96
328         fHistograms->Add(fHistClusterEtavsPhiAfterQA);
329     //fHistDistanceToBadChannelBeforeAcc = new TH1F(Form("DistanceToBadChannel_beforeAcceptance %s",GetCutNumber().Data()),"DistanceToBadChannel_beforeAcceptance",200,0,40);
330     //fHistograms->Add(fHistDistanceToBadChannelBeforeAcc);
331     //fHistDistanceToBadChannelAfterAcc = new TH1F(Form("DistanceToBadChannel_afterAcceptance %s",GetCutNumber().Data()),"DistanceToBadChannel_afterAcceptance",200,0,40);
332     //fHistograms->Add(fHistDistanceToBadChannelAfterAcc);
333         
334         // Cluster quality related histograms
335     Double_t timeMin = -2e-6;
336     Double_t timeMax = 8e-6;
337         if (GetClusterType() == 1){
338                 timeMin = -2e-7;
339                 timeMax = 12e-7;
340         }       
341     fHistClusterTimevsEBeforeQA=new TH2F(Form("ClusterTimeVsE_beforeClusterQA %s",GetCutNumber().Data()),"ClusterTimeVsE_beforeClusterQA",800,timeMin,timeMax,100,0,40);
342         fHistograms->Add(fHistClusterTimevsEBeforeQA);
343     fHistClusterTimevsEAfterQA=new TH2F(Form("ClusterTimeVsE_afterClusterQA %s",GetCutNumber().Data()),"ClusterTimeVsE_afterClusterQA",800,timeMin,timeMax,100,0,40);
344         fHistograms->Add(fHistClusterTimevsEAfterQA);
345     //fHistExoticCellBeforeQA=new TH2F(Form("ExoticCell_beforeClusterQA %s",GetCutNumber().Data()),"ExoticCell_beforeClusterQA",400,0,40,50,0.75,1);
346     //fHistograms->Add(fHistExoticCellBeforeQA);
347     //fHistExoticCellAfterQA=new TH2F(Form("ExoticCell_afterClusterQA %s",GetCutNumber().Data()),"ExoticCell_afterClusterQA",400,0,40,50,0.75,1);
348     //fHistograms->Add(fHistExoticCellAfterQA);
349     //fHistNMatchedTracks = new TH1F(Form("NMatchedTracks_%s",GetCutNumber().Data()),"NMatchedTracks",22,-1.5,20.5);
350     //fHistograms->Add(fHistNMatchedTracks);
351         fHistEnergyOfClusterBeforeQA = new TH1F(Form("EnergyOfCluster_beforeClusterQA %s",GetCutNumber().Data()),"EnergyOfCluster_beforeClusterQA",300,0,30);
352         fHistograms->Add(fHistEnergyOfClusterBeforeQA);
353         fHistEnergyOfClusterAfterQA = new TH1F(Form("EnergyOfCluster_afterClusterQA %s",GetCutNumber().Data()),"EnergyOfCluster_afterClusterQA",300,0,30);
354         fHistograms->Add(fHistEnergyOfClusterAfterQA);
355         fHistNCellsBeforeQA = new TH1F(Form("NCellPerCluster_beforeClusterQA %s",GetCutNumber().Data()),"NCellPerCluster_beforeClusterQA",50,0,50);
356         fHistograms->Add(fHistNCellsBeforeQA);
357         fHistNCellsAfterQA = new TH1F(Form("NCellPerCluster_afterClusterQA %s",GetCutNumber().Data()),"NCellPerCluster_afterClusterQA",50,0,50);
358         fHistograms->Add(fHistNCellsAfterQA);
359         fHistM02BeforeQA = new TH1F(Form("M02_beforeClusterQA %s",GetCutNumber().Data()),"M02_beforeClusterQA",400,0,5);
360         fHistograms->Add(fHistM02BeforeQA);
361         fHistM02AfterQA = new TH1F(Form("M02_afterClusterQA %s",GetCutNumber().Data()),"M02_afterClusterQA",400,0,5);
362         fHistograms->Add(fHistM02AfterQA);
363         fHistM20BeforeQA = new TH1F(Form("M20_beforeClusterQA %s",GetCutNumber().Data()),"M20_beforeClusterQA",400,0,2.5);
364         fHistograms->Add(fHistM20BeforeQA);
365         fHistM20AfterQA = new TH1F(Form("M20_afterClusterQA %s",GetCutNumber().Data()),"M20_afterClusterQA",400,0,2.5);
366         fHistograms->Add(fHistM20AfterQA);
367         fHistDispersionBeforeQA = new TH1F(Form("Dispersion_beforeClusterQA %s",GetCutNumber().Data()),"Dispersion_beforeClusterQA",100,0,4);
368         fHistograms->Add(fHistDispersionBeforeQA);
369         fHistDispersionAfterQA = new TH1F(Form("Dispersion_afterClusterQA %s",GetCutNumber().Data()),"Dispersion_afterClusterQA",100,0,4);
370         fHistograms->Add(fHistDispersionAfterQA);
371     //fHistNLMBeforeQA = new TH1F(Form("NLM_beforeClusterQA %s",GetCutNumber().Data()),"NLM_beforeClusterQA",10,0,10);
372     //fHistograms->Add(fHistNLMBeforeQA);
373     //fHistNLMAfterQA = new TH1F(Form("NLM_afterClusterQA %s",GetCutNumber().Data()),"NLM_afterClusterQA",10,0,10);
374     //fHistograms->Add(fHistNLMAfterQA);
375
376     //TrackMatching histograms
377     if(fUseDistTrackToCluster) {
378         fHistClusterRBeforeQA = new TH1F(Form("R_Cluster_beforeClusterQA %s",GetCutNumber().Data()),"R of cluster",200,400,500);
379         fHistograms->Add(fHistClusterRBeforeQA);
380         fHistClusterRAfterQA = new TH1F(Form("R_Cluster_afterClusterQA %s",GetCutNumber().Data()),"R of cluster_matched",200,400,500);
381         fHistograms->Add(fHistClusterRAfterQA);
382         fHistClusterdEtadPhiBeforeQA=new TH2F(Form("dEtaVsdPhi_beforeClusterQA %s",GetCutNumber().Data()),"dEtaVsdPhi_beforeClusterQA",240,-0.3,0.3,240,-0.3,0.3);
383         fHistograms->Add(fHistClusterdEtadPhiBeforeQA);
384         fHistClusterdEtadPhiAfterQA=new TH2F(Form("dEtaVsdPhi_afterClusterQA %s",GetCutNumber().Data()),"dEtaVsdPhi_afterClusterQA",240,-0.3,0.3,240,-0.3,0.3);
385         fHistograms->Add(fHistClusterdEtadPhiAfterQA);
386         fHistDistanceTrackToClusterBeforeQA = new TH1F(Form("DistanceToTrack_beforeClusterQA %s",GetCutNumber().Data()),"DistanceToTrack_beforeClusterQA",200,0,2);
387         fHistograms->Add(fHistDistanceTrackToClusterBeforeQA);
388         fHistDistanceTrackToClusterAfterQA = new TH1F(Form("DistanceToTrack_afterClusterQA %s",GetCutNumber().Data()),"DistanceToTrack_afterClusterQA",200,0,2);
389         fHistograms->Add(fHistDistanceTrackToClusterAfterQA);
390         
391         if(fExtendedMatching){
392             fHistClusterdEtadPhiPosTracksBeforeQA = new TH2F(Form("dEtaVsdPhi_posTracks_beforeClusterQA %s",GetCutNumber().Data()),"dEtaVsdPhi_posTracks_beforeClusterQA",240,-0.3,0.3,240,-0.3,0.3);
393             fHistograms->Add(fHistClusterdEtadPhiPosTracksBeforeQA);
394             fHistClusterdEtadPhiNegTracksBeforeQA = new TH2F(Form("dEtaVsdPhi_negTracks_beforeClusterQA %s",GetCutNumber().Data()),"dEtaVsdPhi_negTracks_beforeClusterQA",240,-0.3,0.3,240,-0.3,0.3);
395             fHistograms->Add(fHistClusterdEtadPhiNegTracksBeforeQA);
396             fHistClusterdEtadPhiPosTracksAfterQA = new TH2F(Form("dEtaVsdPhi_posTracks_afterClusterQA %s",GetCutNumber().Data()),"dEtaVsdPhi_posTracks_afterClusterQA",240,-0.3,0.3,240,-0.3,0.3);
397             fHistograms->Add(fHistClusterdEtadPhiPosTracksAfterQA);
398             fHistClusterdEtadPhiNegTracksAfterQA = new TH2F(Form("dEtaVsdPhi_negTracks_afterClusterQA %s",GetCutNumber().Data()),"dEtaVsdPhi_negTracks_afterClusterQA",240,-0.3,0.3,240,-0.3,0.3);
399             fHistograms->Add(fHistClusterdEtadPhiNegTracksAfterQA);
400             fHistClusterdEtadPhiPosTracks_P1_BeforeQA = new TH2F(Form("dEtaVsdPhi_posTracks_P<1_beforeClusterQA %s",GetCutNumber().Data()),"dEtaVsdPhi_posTracks_P<1_beforeClusterQA",240,-0.3,0.3,240,-0.3,0.3);
401             fHistograms->Add(fHistClusterdEtadPhiPosTracks_P1_BeforeQA);
402             fHistClusterdEtadPhiPosTracks_P14_BeforeQA = new TH2F(Form("dEtaVsdPhi_posTracks_1<P<4_beforeClusterQA %s",GetCutNumber().Data()),"dEtaVsdPhi_posTracks_1<P<4_beforeClusterQA",240,-0.3,0.3,240,-0.3,0.3);
403             fHistograms->Add(fHistClusterdEtadPhiPosTracks_P14_BeforeQA);
404             fHistClusterdEtadPhiPosTracks_P4_BeforeQA = new TH2F(Form("dEtaVsdPhi_posTracks_P>4_beforeClusterQA %s",GetCutNumber().Data()),"dEtaVsdPhi_posTracks_P>4_beforeClusterQA",240,-0.3,0.3,240,-0.3,0.3);
405             fHistograms->Add(fHistClusterdEtadPhiPosTracks_P4_BeforeQA);
406             fHistClusterdEtadPhiNegTracks_P1_BeforeQA= new TH2F(Form("dEtaVsdPhi_negTrack_P<1s_beforeClusterQA %s",GetCutNumber().Data()),"dEtaVsdPhi_negTrack_P<1s_beforeClusterQA",240,-0.3,0.3,240,-0.3,0.3);
407             fHistograms->Add(fHistClusterdEtadPhiNegTracks_P1_BeforeQA);
408             fHistClusterdEtadPhiNegTracks_P14_BeforeQA = new TH2F(Form("dEtaVsdPhi_negTracks_1<P<4_beforeClusterQA %s",GetCutNumber().Data()),"dEtaVsdPhi_negTracks_1<P<4_beforeClusterQA",240,-0.3,0.3,240,-0.3,0.3);
409             fHistograms->Add(fHistClusterdEtadPhiNegTracks_P14_BeforeQA);
410             fHistClusterdEtadPhiNegTracks_P4_BeforeQA = new TH2F(Form("dEtaVsdPhi_negTracks_P>4_beforeClusterQA %s",GetCutNumber().Data()),"dEtaVsdPhi_negTracks_P>4_beforeClusterQA",240,-0.3,0.3,240,-0.3,0.3);
411             fHistograms->Add(fHistClusterdEtadPhiNegTracks_P4_BeforeQA);
412             fHistClusterdEtadPtBeforeQA = new TH2F(Form("dEtaVsPt_beforeClusterQA %s",GetCutNumber().Data()),"dEtaVsPt_beforeClusterQA",240,-0.3,0.3,250,0,25);
413             fHistograms->Add(fHistClusterdEtadPtBeforeQA);
414             fHistClusterdPhidPtBeforeQA = new TH2F(Form("dPhiVsPt_beforeClusterQA %s",GetCutNumber().Data()),"dPhiVsPt_beforeClusterQA",480,-0.6,0.6,250,0,25);
415             fHistograms->Add(fHistClusterdPhidPtBeforeQA);
416             fHistClusterM20Pt_dPhiBeforeQA = new TH2F(Form("M20VsPt_dPhi_beforeClusterQA %s",GetCutNumber().Data()),"M20VsPt_dPhi_beforeClusterQA",200,0,2.5,250,0,25);
417             fHistograms->Add(fHistClusterM20Pt_dPhiBeforeQA);
418             fHistClusterM02Pt_dPhiBeforeQA = new TH2F(Form("M02VsPt_dPhi_beforeClusterQA %s",GetCutNumber().Data()),"M20VsPt_dPhi_beforeClusterQA",400,0,5,250,0,25);
419             fHistograms->Add(fHistClusterM02Pt_dPhiBeforeQA);
420             fHistClusterM20M02BeforeQA = new TH2F(Form("M20VsM02_beforeClusterQA %s",GetCutNumber().Data()),"M20VsM02_beforeClusterQA",200,0,2.5,400,0,5);
421             fHistograms->Add(fHistClusterM20M02BeforeQA);
422             fHistClusterM20M02AfterQA = new TH2F(Form("M20VsM02_afterClusterQA %s",GetCutNumber().Data()),"M20VsM02_afterClusterQA",200,0,2.5,400,0,5);
423             fHistograms->Add(fHistClusterM20M02AfterQA);
424         }
425     }
426         TH1::AddDirectory(kTRUE);
427 }
428
429
430 ///________________________________________________________________________
431 Bool_t AliCaloPhotonCuts::ClusterIsSelectedMC(TParticle *particle,AliStack *fMCStack){
432    // MonteCarlo Photon Selection
433
434         if(!fMCStack)return kFALSE;
435
436         if (particle->GetPdgCode() == 22){
437
438                 if ( particle->Eta() < fMinEtaCut || particle->Eta() > fMaxEtaCut ) return kFALSE;
439                 if ( particle->Phi() < fMinPhiCut || particle->Phi() > fMaxPhiCut ) return kFALSE;
440                 
441                 if(particle->GetMother(0) >-1 && fMCStack->Particle(particle->GetMother(0))->GetPdgCode() == 22){
442                         return kFALSE; // no photon as mothers!
443                 }
444                 if(particle->GetMother(0) >= fMCStack->GetNprimary()){
445                         return kFALSE; // the gamma has a mother, and it is not a primary particle
446                 }
447                 return kTRUE;
448         }
449         return kFALSE;
450 }
451 ///________________________________________________________________________
452 Bool_t AliCaloPhotonCuts::ClusterIsSelectedAODMC(AliAODMCParticle *particle,TClonesArray *aodmcArray){
453         // MonteCarlo Photon Selection
454
455         if(!aodmcArray)return kFALSE;
456         if (particle->GetPdgCode() == 22){
457                 if ( particle->Eta() < fMinEtaCut || particle->Eta() > fMaxEtaCut ) return kFALSE;
458                 if ( particle->Phi() < fMinPhiCut || particle->Phi() > fMaxPhiCut ) return kFALSE;
459                 if(particle->GetMother() > -1){
460                         if((static_cast<AliAODMCParticle*>(aodmcArray->At(particle->GetMother())))->GetPdgCode() == 22){
461                                 return kFALSE; // no photon as mothers!
462                         }
463                         if(!(static_cast<AliAODMCParticle*>(aodmcArray->At(particle->GetMother()))->IsPrimary())){
464                                 return kFALSE; // the gamma has a mother, and it is not a primary particle
465                         }
466                 }
467                 return kTRUE; // return in case of accepted gamma
468         }
469         return kFALSE;
470 }
471
472
473
474 ///________________________________________________________________________
475 // This function selects the clusters based on their quality criteria
476 ///________________________________________________________________________
477 Bool_t AliCaloPhotonCuts::ClusterQualityCuts(AliVCluster* cluster, AliVEvent *event, Bool_t isMC)
478 {   // Specific Photon Cuts
479     if(event){} // suppress warning
480
481         Int_t cutIndex = 0;
482         if(fHistClusterIdentificationCuts)fHistClusterIdentificationCuts->Fill(cutIndex);
483         cutIndex++;
484
485 //      Double_t minR = 999.0;
486         // get the minimum radius of tracks to cluster
487 //      if(fHistDistanceTrackToClusterBeforeQA || fHistDistanceTrackToClusterAfterQA){
488 //              Float_t pos[3];
489 //              cluster->GetPosition(pos);  // Get cluster position
490 //              
491 //              TVector3 cp(pos);
492 //              int NtrMatched = 0;
493 //              NtrMatched = cluster->GetNTracksMatched();
494 //              fHistNMatchedTracks->Fill(NtrMatched);
495 //              //loop over tracks for Jet QA
496 //              TList *l = event->GetList();
497 //              TClonesArray *tracks = dynamic_cast<TClonesArray*>(l->FindObject("Tracks"));
498 //              for(int itrack = 0; itrack < NtrMatched; itrack++){
499 //                      AliVTrack *trackcluster = static_cast<AliVTrack*>(tracks->At(itrack));
500 //                      if (! trackcluster) {
501 //                              AliError(Form("Couldn't get ESD track %d\n", itrack));
502 //                              continue;
503 //                      }
504 //                      Double_t dphi = -999.0;
505 //                      Double_t deta = -999.0;
506 //                      AliPicoTrack::GetEtaPhiDiff(trackcluster, cluster, dphi, deta);
507 //                      cout << "here" << endl;
508 //                      Double_t dr = sqrt(dphi*dphi + deta+deta);
509 //                      if(dr < minR)
510 //                              minR = dr;
511 //              }//loop over tracks
512 //      }
513         
514         // Fill Histos before Cuts
515         if(fHistClusterTimevsEBeforeQA) fHistClusterTimevsEBeforeQA->Fill(cluster->GetTOF(), cluster->E());
516 //      if(fHistExoticCellBeforeQA) fHistExoticCellBeforeQA->Fill(cluster->E(), );
517 //      if(fHistDistanceTrackToClusterBeforeQA) fHistDistanceTrackToClusterBeforeQA->Fill(minR);
518         if(fHistEnergyOfClusterBeforeQA) fHistEnergyOfClusterBeforeQA->Fill(cluster->E());
519         if(fHistNCellsBeforeQA) fHistNCellsBeforeQA->Fill(cluster->GetNCells());
520         if(fHistM02BeforeQA) fHistM02BeforeQA->Fill(cluster->GetM02());
521         if(fHistM20BeforeQA) fHistM20BeforeQA->Fill(cluster->GetM20());
522         if(fHistDispersionBeforeQA) fHistDispersionBeforeQA->Fill(cluster->GetDispersion());
523 //      if(fHistNLMBeforeQA) fHistNLMBeforeQA->Fill(cluster->GetNExMax());
524         
525         // Check wether timing is ok
526         if (fUseTimeDiff){
527                 if(abs(cluster->GetTOF()) > fMaxTimeDiff && !isMC){
528                         if(fHistClusterIdentificationCuts)fHistClusterIdentificationCuts->Fill(cutIndex); //1
529                         return kFALSE;
530                 }
531         }       
532         cutIndex++; //2, next cut
533
534         // Minimum distance to track
535 //      if (fUseDistTrackToCluster){
536 //              Float_t pos[3];
537 //              cluster->GetPosition(pos);  // Get cluster position
538 //              TVector3 cp(pos);
539 //              int NtrMatched = 0;
540 //              NtrMatched = cluster->GetNTracksMatched();
541 //              fHistNMatchedTracks->Fill(NtrMatched);
542 //              if(NtrMatched > 0){
543 //                      //loop over tracks for QA
544 //                      TList *l = event->GetList();
545 //                      TClonesArray *tracks = dynamic_cast<TClonesArray*>(l->FindObject("Tracks"));
546 //                      
547 //                      Double_t dphi = 999.0;
548 //                      Double_t deta = 999.0;
549 //                      Double_t dr2 = 999.0;
550 // 
551 //                      for(int itrack = 0; itrack < NtrMatched; itrack++){
552 //                              AliVTrack *trackcluster = NULL;
553 //                              trackcluster = static_cast<AliVTrack*>(tracks->At(itrack));
554 //                              if (! trackcluster) {
555 //                              AliError(Form("Couldn't get ESD track %d\n", itrack));
556 //                              continue;
557 //                              }
558 //                              AliPicoTrack::GetEtaPhiDiff(trackcluster, cluster, dphi, deta);
559 //                              dr2 = dphi*dphi + deta+deta;
560 //                              //cout << dr << endl;
561 //                              if(dr2 < fMinDistTrackToCluster*fMinDistTrackToCluster){
562 //              //        if(dphi < fMinDistTrackToCluster || deta < fMinDistTrackToCluster){
563 //                              if(fHistClusterIdentificationCuts)fHistClusterIdentificationCuts->Fill(cutIndex); //2
564 //                              return kFALSE;
565 //                              }
566 //                              
567 //                      }//loop over tracks
568 //              }
569 // //           if(cluster->GetEmcCpvDistance() < fMinDistTrackToCluster){
570 // //                   if(fHistClusterIdentificationCuts)fHistClusterIdentificationCuts->Fill(cutIndex); //2
571 // //                   return kFALSE;
572 // //           }
573 //      }
574         cutIndex++;//3, next cut
575
576         // exotic cell cut --IMPLEMENT LATER---
577 //      if(!AcceptanceCuts(photon)){
578 //              if(fHistClusterIdentificationCuts)fHistClusterIdentificationCuts->Fill(cutIndex); //3
579 //              return kFALSE;
580 //      }
581         cutIndex++; //4, next cut
582         
583         // minimum cell energy cut
584         if (fUseMinEnergy){
585                 if(cluster->E() < fMinEnergy){
586                         if(fHistClusterIdentificationCuts)fHistClusterIdentificationCuts->Fill(cutIndex); //4
587                         return kFALSE;
588                 }
589         }       
590         cutIndex++; //5, next cut
591         
592         // minimum number of cells
593         if (fUseNCells){
594                 if(cluster->GetNCells() < fMinNCells) {
595                         if(fHistClusterIdentificationCuts)fHistClusterIdentificationCuts->Fill(cutIndex); //5
596                         return kFALSE;
597                 }
598         }       
599         cutIndex++; //6, next cut
600         
601         // M02 cut
602         if (fUseM02){
603                 if( cluster->GetM02()< fMinM02 || cluster->GetM02() > fMaxM02 ) {
604                         if(fHistClusterIdentificationCuts)fHistClusterIdentificationCuts->Fill(cutIndex); //6
605                         return kFALSE;
606                 }
607         }       
608         cutIndex++; //7, next cut
609         
610         // M20 cut
611         if (fUseM20){
612                 if( cluster->GetM20()< fMinM20 || cluster->GetM20() > fMaxM20 ) {
613                         if(fHistClusterIdentificationCuts)fHistClusterIdentificationCuts->Fill(cutIndex); //7
614                         return kFALSE;
615                 }
616         }       
617         cutIndex++; //8, next cut
618         
619         // dispersion cut
620         if (fUseDispersion){
621                 if( cluster->GetDispersion()> fMaxDispersion) {
622                         if(fHistClusterIdentificationCuts)fHistClusterIdentificationCuts->Fill(cutIndex); //8
623                         return kFALSE;
624                 }
625         }       
626         cutIndex++; //9, next cut
627         
628         // NLM cut --IMPLEMENT LATER---
629 //      if (fUseNLM){
630 //              if( cluster->GetDispersion()> fMaxDispersion) {
631 //                      if(fHistClusterIdentificationCuts)fHistClusterIdentificationCuts->Fill(cutIndex); //9
632 //                      return kFALSE;
633 //              }
634 //      }       
635         cutIndex++; //9, next cut
636         
637         // DONE with selecting photons
638         if(fHistClusterIdentificationCuts)fHistClusterIdentificationCuts->Fill(cutIndex); //10
639
640         // Histos after Cuts
641 //  Double_t vertex[3] = {0,0,0};
642 //      event->GetPrimaryVertex()->GetXYZ(vertex);
643         // TLorentzvector with cluster
644 //      TLorentzVector clusterVector;
645 //      cluster->GetMomentum(clusterVector,vertex);
646
647     Float_t clusPos[3]={0,0,0};
648     cluster->GetPosition(clusPos);
649     TVector3 clusterVector(clusPos[0],clusPos[1],clusPos[2]);
650         Double_t etaCluster = clusterVector.Eta();
651         Double_t phiCluster = clusterVector.Phi();
652         if (phiCluster < 0) phiCluster= phiCluster+ 2*TMath::Pi();
653
654         if(fHistClusterEtavsPhiAfterQA) fHistClusterEtavsPhiAfterQA->Fill(phiCluster,etaCluster);
655         if(fHistClusterTimevsEAfterQA) fHistClusterTimevsEAfterQA->Fill(cluster->GetTOF(), cluster->E());
656 //      if(fHistExoticCellAfterQA) fHistExoticCellAfterQA->Fill(cluster->E(), );
657 //      if(fHistDistanceTrackToClusterAfterQA) fHistDistanceTrackToClusterAfterQA->Fill(minR);
658         if(fHistEnergyOfClusterAfterQA) fHistEnergyOfClusterAfterQA->Fill(cluster->E());
659         if(fHistNCellsAfterQA) fHistNCellsAfterQA->Fill(cluster->GetNCells());
660         if(fHistM02AfterQA) fHistM02AfterQA->Fill(cluster->GetM02());
661         if(fHistM20AfterQA) fHistM20AfterQA->Fill(cluster->GetM20());
662         if(fHistDispersionAfterQA) fHistDispersionAfterQA->Fill(cluster->GetDispersion());
663 //      if(fHistNLMBeforeQA) fHistNLMAfterQA->Fill(cluster->GetNExMax());
664
665         return kTRUE;
666
667 }
668
669
670 ///________________________________________________________________________
671 Bool_t AliCaloPhotonCuts::ClusterIsSelected(AliVCluster *cluster, AliVEvent * event, Bool_t isMC)
672 {
673         //Selection of Reconstructed photon clusters with Calorimeters
674
675         FillClusterCutIndex(kPhotonIn);
676
677 //  Double_t vertex[3] = {0,0,0};
678 //      event->GetPrimaryVertex()->GetXYZ(vertex);
679     // TLorentzvector with cluster
680 //  TLorentzVector clusterVector;
681 //      cluster->GetMomentum(clusterVector,vertex);
682
683     Float_t clusPos[3]={0,0,0};
684     cluster->GetPosition(clusPos);
685     TVector3 clusterVector(clusPos[0],clusPos[1],clusPos[2]);
686         Double_t etaCluster = clusterVector.Eta();
687         Double_t phiCluster = clusterVector.Phi();
688         if (phiCluster < 0) phiCluster= phiCluster+ 2*TMath::Pi();
689
690         // Histos before cuts
691         if(fHistClusterEtavsPhiBeforeAcc) fHistClusterEtavsPhiBeforeAcc->Fill(phiCluster,etaCluster);
692         
693         // Cluster Selection - 0= accept any calo cluster
694         if (fClusterType > 0){
695                 //Select EMCAL cluster
696                 if (fClusterType == 1 && !cluster->IsEMCAL()){
697                         FillClusterCutIndex(kDetector);
698                         return kFALSE;
699                 }
700                 //Select PHOS cluster
701                 if (fClusterType == 2 && !cluster->IsPHOS()){
702                         FillClusterCutIndex(kDetector);
703                         return kFALSE;
704                 }
705         }
706         
707         // Acceptance Cuts
708         if(!AcceptanceCuts(cluster,event)){
709                 FillClusterCutIndex(kAcceptance);
710                 return kFALSE;
711         }
712         // Cluster Quality Cuts
713         if(!ClusterQualityCuts(cluster,event,isMC)){
714                 FillClusterCutIndex(kClusterQuality);
715                 return kFALSE;
716         }
717
718         // Photon passed cuts
719         FillClusterCutIndex(kPhotonOut);
720         return kTRUE;
721 }
722
723
724 ///________________________________________________________________________
725 Bool_t AliCaloPhotonCuts::AcceptanceCuts(AliVCluster *cluster, AliVEvent* event) 
726 {
727    // Exclude certain areas for photon reconstruction
728     if(event){} // suppress warning
729
730         Int_t cutIndex=0;
731         if(fHistAcceptanceCuts)fHistAcceptanceCuts->Fill(cutIndex);
732         cutIndex++;
733
734         
735 //      Double_t vertex[3] = {0,0,0};
736 //      event->GetPrimaryVertex()->GetXYZ(vertex);
737         // TLorentzvector with cluster
738 //      TLorentzVector clusterVector;
739 //      cluster->GetMomentum(clusterVector,vertex);
740
741     Float_t clusPos[3]={0,0,0};
742     cluster->GetPosition(clusPos);
743     TVector3 clusterVector(clusPos[0],clusPos[1],clusPos[2]);
744         Double_t etaCluster = clusterVector.Eta();
745         Double_t phiCluster = clusterVector.Phi();
746         if (phiCluster < 0) phiCluster= phiCluster+ 2*TMath::Pi();
747         
748         // check eta range
749         if (fUseEtaCut){
750                 if (etaCluster < fMinEtaCut || etaCluster > fMaxEtaCut){
751                         if(fHistAcceptanceCuts)fHistAcceptanceCuts->Fill(cutIndex);
752                         return kFALSE;
753                 }
754         }
755         cutIndex++;
756         
757         // check phi range
758         if (fUsePhiCut ){
759         if (phiCluster < fMinPhiCut || phiCluster > fMaxPhiCut){
760                         if(fHistAcceptanceCuts)fHistAcceptanceCuts->Fill(cutIndex);
761                         return kFALSE;
762                 }
763         }
764         cutIndex++;
765         
766         // check distance to bad channel
767         if (fUseDistanceToBadChannel){
768                 if (cluster->GetDistanceToBadChannel() < fMinDistanceToBadChannel){
769                         if(fHistAcceptanceCuts)fHistAcceptanceCuts->Fill(cutIndex);
770                         return kFALSE;
771                 }       
772         }
773         cutIndex++;
774         if(fHistAcceptanceCuts)fHistAcceptanceCuts->Fill(cutIndex);
775
776         // Histos after cuts
777         if(fHistClusterEtavsPhiAfterAcc) fHistClusterEtavsPhiAfterAcc->Fill(phiCluster,etaCluster);
778         
779         return kTRUE;
780 }
781
782 Bool_t AliCaloPhotonCuts::MatchConvPhotonToCluster(AliAODConversionPhoton* convPhoton, AliVCluster* cluster, AliVEvent* event ){
783
784         if (!fUseDistTrackToCluster) return kFALSE;
785         
786         AliESDEvent *esdev = dynamic_cast<AliESDEvent*>(event);
787         AliAODEvent *aodev = 0;
788         if (!esdev) {
789                 aodev = dynamic_cast<AliAODEvent*>(event);
790                 if (!aodev) {
791                         AliError("Task needs AOD or ESD event, returning");
792                         return kFALSE;
793                 }
794         }
795
796 //    Double_t vertex[3] = {0,0,0};
797 //        event->GetPrimaryVertex()->GetXYZ(vertex);
798
799     if(!cluster->IsEMCAL() && !cluster->IsPHOS()){AliError("Cluster is neither EMCAL nor PHOS, returning"); return kFALSE;}
800
801     Float_t clusterPosition[3] = {0,0,0};
802     cluster->GetPosition(clusterPosition);
803     Double_t clusterR = TMath::Sqrt( clusterPosition[0]*clusterPosition[0] + clusterPosition[1]*clusterPosition[1] );
804     if(fHistClusterRBeforeQA) fHistClusterRBeforeQA->Fill(clusterR);
805
806 //cout << "+++++++++ Cluster: x, y, z, R" << clusterPosition[0] << ", " << clusterPosition[1] << ", " << clusterPosition[2] << ", " << clusterR << "+++++++++" << endl;
807
808         Bool_t matched = kFALSE;
809         for (Int_t i = 0; i < 2; i++){
810                 Int_t tracklabel = convPhoton->GetLabel(i);
811                 AliVTrack *inTrack = 0x0;       
812                 if(esdev) {
813                         if(tracklabel > event->GetNumberOfTracks() ) continue;
814                         inTrack = esdev->GetTrack(tracklabel);
815                 } else {
816                         if(((AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask("V0ReaderV1"))->AreAODsRelabeled()){
817                                 inTrack = dynamic_cast<AliVTrack*>(event->GetTrack(tracklabel));        
818                         } else {
819                                 for(Int_t ii=0; ii<event->GetNumberOfTracks(); ii++) {
820                                         inTrack = dynamic_cast<AliVTrack*>(event->GetTrack(ii));
821                                         if(inTrack){
822                                                 if(inTrack->GetID() == tracklabel) {
823                                                         continue;
824                                                 }
825                                         }
826                                 }
827                         }
828                 }
829
830                 AliESDtrack *esdt = dynamic_cast<AliESDtrack*>(inTrack);
831                 AliAODTrack *aodt = 0;
832                 if (!esdt) {
833                         aodt = dynamic_cast<AliAODTrack*>(inTrack);
834                         if (!aodt){AliError("Track is neither ESD nor AOD, continue"); continue;}
835                 }
836
837                 AliExternalTrackParam *trackParam = 0;
838                 if (esdt) {
839                         const AliExternalTrackParam *in = esdt->GetInnerParam();
840                         if (!in){AliError("Could not get InnerParam of Track, continue"); continue;}
841                         trackParam = new AliExternalTrackParam(*in);
842                 } else {
843                         Double_t xyz[3] = {0}, pxpypz[3] = {0}, cv[21] = {0};
844                         aodt->PxPyPz(pxpypz);
845                         aodt->XvYvZv(xyz);
846                         aodt->GetCovarianceXYZPxPyPz(cv);
847                         trackParam = new AliExternalTrackParam(xyz,pxpypz,cv,aodt->Charge());
848                 }
849                 if (!trackParam){AliError("Could not get TrackParameters, continue"); continue;}
850                 
851                 Bool_t propagated = kFALSE;
852                 AliExternalTrackParam emcParam(*trackParam);
853                 Float_t dPhi = 0;
854                 Float_t dEta = 0;
855
856                 if(cluster->IsEMCAL()){
857                         Float_t eta = 0; Float_t phi = 0; Float_t pt = 0;
858                         propagated = AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(&emcParam, 430, 0.000510999, 20, eta, phi, pt);
859                         if(propagated){
860                                 propagated = AliEMCALRecoUtils::ExtrapolateTrackToCluster(&emcParam, cluster, 0.000510999, 5, dEta, dPhi);
861                         }
862                 }
863                 if(cluster->IsPHOS()){
864                         propagated = AliTrackerBase::PropagateTrackToBxByBz(&emcParam, clusterR, 0.000510999, 20, kTRUE, 0.8, -1);
865                         if (propagated){
866                                 Double_t trkPos[3] = {0,0,0};
867                                 emcParam.GetXYZ(trkPos);
868                                 TVector3 trkPosVec(trkPos[0],trkPos[1],trkPos[2]);
869                                 TVector3 clsPosVec(clusterPosition);
870                                 dPhi = clsPosVec.DeltaPhi(trkPosVec);
871                                 dEta = clsPosVec.Eta()-trkPosVec.Eta();
872                         }
873                 }
874
875                 if (propagated){
876                         Float_t dR2 = dPhi*dPhi + dEta*dEta;
877             if(fHistDistanceTrackToClusterBeforeQA)fHistDistanceTrackToClusterBeforeQA->Fill(TMath::Sqrt(dR2));
878             if(fHistClusterdEtadPhiBeforeQA) fHistClusterdEtadPhiBeforeQA->Fill(dEta, dPhi);
879
880             Float_t clusM02 = (Float_t) cluster->GetM02();
881             Float_t clusM20 = (Float_t) cluster->GetM20();
882             if(fExtendedMatching){
883                 if(inTrack->Charge() > 0) {
884                     fHistClusterdEtadPhiPosTracksBeforeQA->Fill(dEta, dPhi);
885                     if(inTrack->P() < 1) fHistClusterdEtadPhiPosTracks_P1_BeforeQA->Fill(dEta, dPhi);
886                     else if(inTrack->P() < 4) fHistClusterdEtadPhiPosTracks_P14_BeforeQA->Fill(dEta, dPhi);
887                     else fHistClusterdEtadPhiPosTracks_P4_BeforeQA->Fill(dEta, dPhi);
888                 }
889                 else{
890                     fHistClusterdEtadPhiNegTracksBeforeQA->Fill(dEta, dPhi);
891                     if(inTrack->P() < 1) fHistClusterdEtadPhiNegTracks_P1_BeforeQA->Fill(dEta, dPhi);
892                     else if(inTrack->P() < 4) fHistClusterdEtadPhiNegTracks_P14_BeforeQA->Fill(dEta, dPhi);
893                     else fHistClusterdEtadPhiNegTracks_P4_BeforeQA->Fill(dEta, dPhi);
894                 }
895                 fHistClusterdEtadPtBeforeQA->Fill(dEta, inTrack->Pt());
896                 fHistClusterdPhidPtBeforeQA->Fill(dPhi, inTrack->Pt());
897                 if(abs(dPhi) > 0.05){
898                     fHistClusterM20Pt_dPhiBeforeQA->Fill(clusM20, inTrack->Pt());
899                     fHistClusterM02Pt_dPhiBeforeQA->Fill(clusM02, inTrack->Pt());
900                 }
901                 fHistClusterM20M02BeforeQA->Fill(clusM20, clusM02);
902             }
903
904             Bool_t match_dEta = (abs(dEta) < fMaxDistTrackToClusterEta) ? kTRUE : kFALSE;
905             Bool_t match_dPhi = kFALSE;
906             if( (inTrack->Charge() > 0) && (dPhi > fMinDistTrackToClusterPhi) && (dPhi < fMaxDistTrackToClusterPhi) ) match_dPhi = kTRUE;
907             else if( (inTrack->Charge() < 0) && (dPhi < -fMinDistTrackToClusterPhi) && (dPhi > -fMaxDistTrackToClusterPhi) ) match_dPhi = kTRUE;
908
909             if(match_dEta && match_dPhi){
910             //if(dR2 < fMinDistTrackToCluster*fMinDistTrackToCluster){
911                                 matched = kTRUE;
912                         } else {
913                 if(fHistDistanceTrackToClusterAfterQA)fHistDistanceTrackToClusterAfterQA->Fill(TMath::Sqrt(dR2));
914                 if(fHistClusterdEtadPhiAfterQA) fHistClusterdEtadPhiAfterQA->Fill(dEta, dPhi);
915                 if(fHistClusterRAfterQA) fHistClusterRAfterQA->Fill(clusterR);
916                 if(fExtendedMatching){
917                     if(inTrack->Charge() > 0) fHistClusterdEtadPhiPosTracksAfterQA->Fill(dEta, dPhi);
918                     else fHistClusterdEtadPhiNegTracksAfterQA->Fill(dEta, dPhi);
919                     fHistClusterM20M02AfterQA->Fill(clusM20, clusM02);
920                 }
921                         }       
922                 }
923                 delete trackParam;
924         }
925
926         return matched;
927
928 }
929
930 //____________________________________________________________________________________________
931
932
933 ///________________________________________________________________________
934 Bool_t AliCaloPhotonCuts::UpdateCutString() {
935    ///Update the cut string (if it has been created yet)
936
937    if(fCutString && fCutString->GetString().Length() == kNCuts) {
938       fCutString->SetString(GetCutNumber());
939    } else {
940       return kFALSE;
941    }
942    return kTRUE;
943 }
944
945 ///________________________________________________________________________
946 Bool_t AliCaloPhotonCuts::InitializeCutsFromCutString(const TString analysisCutSelection ) {
947         // Initialize Cuts from a given Cut string
948         AliInfo(Form("Set CaloCut Number: %s",analysisCutSelection.Data()));
949         if(analysisCutSelection.Length()!=kNCuts) {
950                 AliError(Form("Cut selection has the wrong length! size is %d, number of cuts is %d", analysisCutSelection.Length(), kNCuts));
951                 return kFALSE;
952         }
953         if(!analysisCutSelection.IsDigit()){
954                 AliError("Cut selection contains characters");
955                 return kFALSE;
956         }
957
958         const char *cutSelection = analysisCutSelection.Data();
959         #define ASSIGNARRAY(i)  fCuts[i] = cutSelection[i] - '0'
960         for(Int_t ii=0;ii<kNCuts;ii++){
961                 ASSIGNARRAY(ii);
962         }
963
964         // Set Individual Cuts
965         for(Int_t ii=0;ii<kNCuts;ii++){
966                 if(!SetCut(cutIds(ii),fCuts[ii]))return kFALSE;
967         }
968         PrintCutsWithValues();
969         return kTRUE;
970 }
971
972 ///________________________________________________________________________
973 Bool_t AliCaloPhotonCuts::SetCut(cutIds cutID, const Int_t value) {
974         ///Set individual cut ID
975
976         switch (cutID) {                
977                 
978                 case kClusterType:
979                         if( SetClusterTypeCut(value)) {
980                                 fCuts[kClusterType] = value;
981                                 UpdateCutString();
982                                 return kTRUE;
983                         } else return kFALSE;
984                 
985                 case kEtaMin:
986                         if( SetMinEtaCut(value)) {
987                                 fCuts[kEtaMin] = value;
988                                 UpdateCutString();
989                                 return kTRUE;
990                         } else return kFALSE;
991
992                 case kEtaMax:
993                         if( SetMaxEtaCut(value)) {
994                                 fCuts[kEtaMax] = value;
995                                 UpdateCutString();
996                                 return kTRUE;
997                         } else return kFALSE;
998
999                 case kPhiMin:
1000                         if( SetMinPhiCut(value)) {
1001                                 fCuts[kPhiMin] = value;
1002                                 UpdateCutString();
1003                                 return kTRUE;
1004                         } else return kFALSE;
1005
1006                 case kPhiMax:
1007                         if( SetMaxPhiCut(value)) {
1008                                 fCuts[kPhiMax] = value;
1009                                 UpdateCutString();
1010                                 return kTRUE;
1011                         } else return kFALSE;
1012
1013                 case kDistanceToBadChannel:
1014                         if( SetDistanceToBadChannelCut(value)) {
1015                                 fCuts[kDistanceToBadChannel] = value;
1016                                 UpdateCutString();
1017                                 return kTRUE;
1018                         } else return kFALSE;
1019
1020                 case kTiming:
1021                         if( SetTimingCut(value)) {
1022                                 fCuts[kTiming] = value;
1023                                 UpdateCutString();
1024                                 return kTRUE;
1025                         } else return kFALSE;
1026
1027                 case kTrackMatching:
1028                         if( SetTrackMatchingCut(value)) {
1029                                 fCuts[kTrackMatching] = value;
1030                                 UpdateCutString();
1031                                 return kTRUE;
1032                         } else return kFALSE;
1033
1034                 case kExoticCell:
1035                         if( SetExoticCellCut(value)) {
1036                                 fCuts[kExoticCell] = value;
1037                                 UpdateCutString();
1038                                 return kTRUE;
1039                         } else return kFALSE;
1040
1041                 case kMinEnery:
1042                         if( SetMinEnergyCut(value)) {
1043                                 fCuts[kMinEnery] = value;
1044                                 UpdateCutString();
1045                                 return kTRUE;
1046                         } else return kFALSE;
1047
1048                 case kNMinCells:
1049                         if( SetMinNCellsCut(value)) {
1050                                 fCuts[kNMinCells] = value;
1051                                 UpdateCutString();
1052                                 return kTRUE;
1053                         } else return kFALSE;
1054                         
1055                 case kMinM02:
1056                         if( SetMinM02(value)) {
1057                                 fCuts[kMinM02] = value;
1058                                 UpdateCutString();
1059                                 return kTRUE;
1060                         } else return kFALSE;
1061
1062                 case kMaxM02:
1063                         if( SetMaxM02(value)) {
1064                                 fCuts[kMaxM02] = value;
1065                                 UpdateCutString();
1066                                 return kTRUE;
1067                         } else return kFALSE;
1068                 
1069                 case kMinM20:
1070                         if( SetMinM20(value)) {
1071                                 fCuts[kMinM20] = value;
1072                                 UpdateCutString();
1073                                 return kTRUE;
1074                         } else return kFALSE;
1075
1076                 case kMaxM20:
1077                         if( SetMaxM20(value)) {
1078                                 fCuts[kMaxM20] = value;
1079                                 UpdateCutString();
1080                                 return kTRUE;
1081                         } else return kFALSE;
1082
1083                 case kDispersion:
1084                         if( SetDispersion(value)) {
1085                                 fCuts[kDispersion] = value;
1086                                 UpdateCutString();
1087                                 return kTRUE;
1088                         } else return kFALSE;
1089
1090                 case kNLM:
1091                         if( SetNLM(value)) {
1092                                 fCuts[kNLM] = value;
1093                                 UpdateCutString();
1094                                 return kTRUE;
1095                         } else return kFALSE;
1096
1097                 case kNCuts:
1098                         AliError("Cut id out of range");
1099                         return kFALSE;
1100         }
1101
1102         AliError("Cut id %d not recognized");
1103         return kFALSE;
1104
1105
1106 }
1107 ///________________________________________________________________________
1108 void AliCaloPhotonCuts::PrintCuts() {
1109    // Print out current Cut Selection
1110    for(Int_t ic = 0; ic < kNCuts; ic++) {
1111       printf("%-30s : %d \n", fgkCutNames[ic], fCuts[ic]);
1112    }
1113 }
1114
1115 void AliCaloPhotonCuts::PrintCutsWithValues() {
1116         // Print out current Cut Selection with value
1117         printf("\nCluster cutnumber \n");
1118         for(Int_t ic = 0; ic < kNCuts; ic++) {
1119                 printf("%d",fCuts[ic]);
1120         }
1121         printf("\n\n");
1122
1123         printf("Acceptance cuts: \n");
1124         if (fClusterType == 0) printf("\tall calorimeter clusters are used\n");
1125         if (fClusterType == 1) printf("\tEMCAL calorimeter clusters are used\n");
1126         if (fClusterType == 2) printf("\tPHOS calorimeter clusters are used\n");
1127         if (fUseEtaCut) printf("\t%3.2f < eta_{cluster} < %3.2f\n", fMinEtaCut, fMaxEtaCut );
1128         if (fUsePhiCut) printf("\t%3.2f < phi_{cluster} < %3.2f\n", fMinPhiCut, fMaxPhiCut );
1129         if (fUseDistanceToBadChannel) printf("\tcut on exotics applied \n");
1130         
1131         printf("Cluster Quality cuts: \n");
1132         if (fUseTimeDiff) printf("\t time difference < %3.2f\n", fMaxTimeDiff );
1133     if (fUseDistTrackToCluster) printf("\tmin distance to track in eta > %3.2f, min phi < %3.2f and max phi > %3.2f\n", fMaxDistTrackToClusterEta, fMinDistTrackToClusterPhi, fMaxDistTrackToClusterPhi );
1134     if (fUseExoticCell)printf("\t exotic cell: %3.2f\n", fExoticCell );
1135     if (fUseMinEnergy)printf("\t E_{cluster} > %3.2f\n", fMinEnergy );
1136         if (fUseNCells) printf("\t number of cells per cluster >= %d\n", fMinNCells );
1137         if (fUseM02) printf("\t %3.2f < M02 < %3.2f\n", fMinM02, fMaxM02 );
1138         if (fUseM20) printf("\t %3.2f < M20 < %3.2f\n", fMinM20, fMaxM20 );
1139         if (fUseDispersion) printf("\t dispersion < %3.2f\n", fMaxDispersion );
1140         if (fUseNLM) printf("\t %d < NLM < %d\n", fMinNLM, fMaxNLM );
1141         
1142 }
1143
1144 // EMCAL acceptance 2011
1145 // 1.39626, 3.125 (phi)
1146 // -0.66687,,0.66465
1147
1148
1149 ///________________________________________________________________________
1150 Bool_t AliCaloPhotonCuts::SetClusterTypeCut(Int_t clusterType)
1151 {   // Set Cut
1152         switch(clusterType){
1153         case 0: // all clusters
1154                 fClusterType=0;
1155                 break;
1156         case 1: // EMCAL clusters
1157                 fClusterType=1;
1158                 break;
1159         case 2: // PHOS clusters
1160                 fClusterType=2;
1161                 break;
1162         default:
1163                 AliError(Form("ClusterTypeCut not defined %d",clusterType));
1164                 return kFALSE;
1165         }
1166         return kTRUE;
1167 }
1168
1169 //___________________________________________________________________
1170 Bool_t AliCaloPhotonCuts::SetMinEtaCut(Int_t minEta)
1171 {
1172         switch(minEta){
1173         case 0:
1174                 if (!fUseEtaCut) fUseEtaCut=0;
1175                 fMinEtaCut=-10.;
1176                 break;
1177         case 1:
1178                 if (!fUseEtaCut) fUseEtaCut=1;
1179                 fMinEtaCut=-0.6687;
1180                 break;
1181         case 2: 
1182                 if (!fUseEtaCut) fUseEtaCut=1;
1183                 fMinEtaCut=-0.5;
1184                 break;
1185         case 3: 
1186                 if (!fUseEtaCut) fUseEtaCut=1;
1187                 fMinEtaCut=-2;
1188                 break;
1189         default:
1190                 AliError(Form("MinEta Cut not defined %d",minEta));
1191                 return kFALSE;
1192         }
1193         return kTRUE;
1194 }
1195
1196
1197 //___________________________________________________________________
1198 Bool_t AliCaloPhotonCuts::SetMaxEtaCut(Int_t maxEta)
1199 {
1200         switch(maxEta){
1201         case 0: 
1202                 if (!fUseEtaCut) fUseEtaCut=0;
1203                 fMaxEtaCut=10;
1204                 break;          
1205         case 1:
1206                 if (!fUseEtaCut) fUseEtaCut=1;
1207                 fMaxEtaCut=0.66465;
1208                 break;
1209         case 2: 
1210                 if (!fUseEtaCut) fUseEtaCut=1;
1211                 fMaxEtaCut=0.5;
1212                 break;
1213         case 3: 
1214                 if (!fUseEtaCut) fUseEtaCut=1;
1215                 fMaxEtaCut=2;
1216                 break;
1217         default:
1218                 AliError(Form("MaxEta Cut not defined %d",maxEta));
1219                 return kFALSE;
1220         }
1221         return kTRUE;
1222 }
1223
1224 //___________________________________________________________________
1225 Bool_t AliCaloPhotonCuts::SetMinPhiCut(Int_t minPhi)
1226 {
1227         switch(minPhi){
1228         case 0: 
1229                 if (!fUsePhiCut) fUsePhiCut=0;
1230                 fMinPhiCut=-10000;
1231                 break;
1232         case 1: // min EMCAL
1233                 if (!fUsePhiCut) fUsePhiCut=1;
1234                 fMinPhiCut=1.39626;
1235                 break;
1236         case 2: // min EMCAL with TRD 2012 
1237                 if (!fUsePhiCut) fUsePhiCut=1;
1238                 fMinPhiCut=2.10;
1239                 break;
1240         case 3: // min EMCAL with TRD 2011 
1241                 if (!fUsePhiCut) fUsePhiCut=1;
1242                 fMinPhiCut=2.45;
1243                 break;
1244                 
1245                 
1246         default:
1247                 AliError(Form("MinPhi Cut not defined %d",minPhi));
1248                 return kFALSE;
1249         }
1250         return kTRUE;
1251 }
1252
1253 //___________________________________________________________________
1254 Bool_t AliCaloPhotonCuts::SetMaxPhiCut(Int_t maxPhi)
1255 {
1256         switch(maxPhi){
1257         case 0: 
1258                 if (!fUsePhiCut) fUsePhiCut=0;
1259                 fMaxPhiCut=10000;
1260                 break;
1261         case 1: // max EMCAL
1262                 if (!fUsePhiCut) fUsePhiCut=1;
1263                 fMaxPhiCut=3.15;
1264                 break;
1265         case 2: // max EMCAL with TRD 2011
1266                 if (!fUsePhiCut) fUsePhiCut=1;
1267                 fMaxPhiCut=2.45;
1268                 break;
1269         case 3: // max EMCAL with TRD 2012
1270                 if (!fUsePhiCut) fUsePhiCut=1;
1271                 fMaxPhiCut=2.10;
1272                 break;
1273                 
1274                 
1275         default:
1276                 AliError(Form("Max Phi Cut not defined %d",maxPhi));
1277                 return kFALSE;
1278         }
1279         return kTRUE;
1280 }
1281
1282 //___________________________________________________________________
1283 Bool_t AliCaloPhotonCuts::SetDistanceToBadChannelCut(Int_t distanceToBadChannel)
1284 {
1285         switch(distanceToBadChannel){
1286         case 0: 
1287                 fUseDistanceToBadChannel=0;
1288                 fMinDistanceToBadChannel=0;
1289                 break;
1290         case 1: 
1291                 if (!fUseDistanceToBadChannel) fUseDistanceToBadChannel=1;
1292                 fMinDistanceToBadChannel=5;
1293                 break;
1294         default:
1295                 AliError(Form("minimum distance to bad channel Cut not defined %d",distanceToBadChannel));
1296                 return kFALSE;
1297         }
1298         return kTRUE;
1299 }
1300
1301 //___________________________________________________________________
1302 Bool_t AliCaloPhotonCuts::SetTimingCut(Int_t timing)
1303 {
1304         switch(timing){
1305         case 0: 
1306                 fUseTimeDiff=0;
1307                 fMaxTimeDiff=500;
1308                 break;
1309         case 1: 
1310                 if (!fUseTimeDiff) fUseTimeDiff=1;
1311                 fMaxTimeDiff=10e-7; //1000ns
1312                 break;
1313         case 2: 
1314                 if (!fUseTimeDiff) fUseTimeDiff=1;
1315                 fMaxTimeDiff=50e-8; //500ns
1316                 break;
1317         case 3: 
1318                 if (!fUseTimeDiff) fUseTimeDiff=1;
1319                 fMaxTimeDiff=20e-8; //200ns
1320                 break;
1321         case 4: 
1322                 if (!fUseTimeDiff) fUseTimeDiff=1;
1323                 fMaxTimeDiff=10e-8; //100ns
1324                 break;
1325         case 5: 
1326                 if (!fUseTimeDiff) fUseTimeDiff=1;
1327                 fMaxTimeDiff=50e-9; //50ns
1328                 break;
1329
1330         default:
1331                 AliError(Form("Timing Cut not defined %d",timing));
1332                 return kFALSE;
1333         }
1334         return kTRUE;
1335 }
1336
1337 //___________________________________________________________________
1338 Bool_t AliCaloPhotonCuts::SetTrackMatchingCut(Int_t trackMatching)
1339 {
1340         switch(trackMatching){
1341         case 0: 
1342         fUseDistTrackToCluster = 0;
1343         fMaxDistTrackToClusterEta = 0;
1344         fMinDistTrackToClusterPhi = 0;
1345         fMaxDistTrackToClusterPhi = 0;
1346                 break;
1347         case 1: 
1348                 if (!fUseDistTrackToCluster) fUseDistTrackToCluster=1;
1349         fMaxDistTrackToClusterEta = 0.015;
1350         fMinDistTrackToClusterPhi = -0.01;
1351         fMaxDistTrackToClusterPhi = 0.03;       //0.04;
1352                 break;
1353         case 2: 
1354                 if (!fUseDistTrackToCluster) fUseDistTrackToCluster=1;
1355         fMaxDistTrackToClusterEta = 0.015;
1356         fMinDistTrackToClusterPhi = -0.01;
1357         fMaxDistTrackToClusterPhi = 0.035;      //0.05;
1358                 break;
1359         case 3: 
1360                 if (!fUseDistTrackToCluster) fUseDistTrackToCluster=1;
1361         fMaxDistTrackToClusterEta = 0.015;
1362         fMinDistTrackToClusterPhi = -0.015;
1363         fMaxDistTrackToClusterPhi = 0.04;       //0.1;
1364                 break;
1365         case 4: 
1366                 if (!fUseDistTrackToCluster) fUseDistTrackToCluster=1;
1367         fMaxDistTrackToClusterEta = 0.015;
1368         fMinDistTrackToClusterPhi = -0.015;
1369         fMaxDistTrackToClusterPhi = 0.045;      //0.13;
1370                 break;
1371         case 5: 
1372                 if (!fUseDistTrackToCluster) fUseDistTrackToCluster=1;
1373         fMaxDistTrackToClusterEta = 0.015;
1374         fMinDistTrackToClusterPhi = -0.02;
1375         fMaxDistTrackToClusterPhi = 0.05;       //0.15
1376                 break;
1377         case 6: 
1378                 if (!fUseDistTrackToCluster) fUseDistTrackToCluster=1;
1379         fMaxDistTrackToClusterEta = 0.015;
1380         fMinDistTrackToClusterPhi = -0.02;
1381         fMaxDistTrackToClusterPhi = 0.055;      //0.2;
1382                 break;
1383         case 7: 
1384                 if (!fUseDistTrackToCluster) fUseDistTrackToCluster=1;
1385         fMaxDistTrackToClusterEta = 0.015;
1386         fMinDistTrackToClusterPhi = -0.025;
1387         fMaxDistTrackToClusterPhi = 0.06;       //0.3;
1388                 break;
1389         case 8: 
1390                 if (!fUseDistTrackToCluster) fUseDistTrackToCluster=1;
1391         fMaxDistTrackToClusterEta = 0.015;
1392         fMinDistTrackToClusterPhi = -0.025;
1393         fMaxDistTrackToClusterPhi = 0.07;       //0.4;
1394                 break;
1395         case 9: 
1396                 if (!fUseDistTrackToCluster) fUseDistTrackToCluster=1;
1397         fMaxDistTrackToClusterEta = 0.02;
1398         fMinDistTrackToClusterPhi = -0.03;
1399         fMaxDistTrackToClusterPhi = 0.1;        //0.5;
1400                 break;
1401
1402         default:
1403                 AliError(Form("Track Matching Cut not defined %d",trackMatching));
1404                 return kFALSE;
1405         }
1406         return kTRUE;
1407 }
1408
1409 //___________________________________________________________________
1410 Bool_t AliCaloPhotonCuts::SetExoticCellCut(Int_t exoticCell)
1411 {
1412         switch(exoticCell){
1413         case 0: 
1414                 fUseExoticCell=0;
1415                 fExoticCell=0;
1416                 break;
1417         case 1: 
1418                 if (!fUseExoticCell) fUseExoticCell=1;
1419                 fExoticCell=5; 
1420                 break;
1421         default:
1422                 AliError(Form("Exotic cell Cut not defined %d",exoticCell));
1423                 return kFALSE;
1424         }
1425         return kTRUE;
1426 }
1427                 
1428 //___________________________________________________________________
1429 Bool_t AliCaloPhotonCuts::SetMinEnergyCut(Int_t minEnergy)
1430 {
1431         switch(minEnergy){
1432         case 0: 
1433                 if (!fUseMinEnergy) fUseMinEnergy=0;
1434                 fMinEnergy=0.1;
1435                 break;
1436         case 1: 
1437                 if (!fUseMinEnergy) fUseMinEnergy=1;
1438                 fMinEnergy=0.2; 
1439                 break;
1440         case 2: 
1441                 if (!fUseMinEnergy) fUseMinEnergy=1;
1442                 fMinEnergy=0.3; 
1443                 break;
1444         case 3: 
1445                 if (!fUseMinEnergy) fUseMinEnergy=1;
1446                 fMinEnergy=0.4; 
1447                 break;
1448         case 4: 
1449                 if (!fUseMinEnergy) fUseMinEnergy=1;
1450                 fMinEnergy=0.5; 
1451                 break;
1452         case 5: 
1453                 if (!fUseMinEnergy) fUseMinEnergy=1;
1454                 fMinEnergy=0.6; 
1455                 break;
1456         case 6: 
1457                 if (!fUseMinEnergy) fUseMinEnergy=1;
1458                 fMinEnergy=4.5; 
1459                 break;
1460         case 7: 
1461                 if (!fUseMinEnergy) fUseMinEnergy=1;
1462                 fMinEnergy=5.0; 
1463                 break;
1464         case 8: 
1465                 if (!fUseMinEnergy) fUseMinEnergy=1;
1466                 fMinEnergy=5.5; 
1467                 break;
1468         case 9: 
1469                 if (!fUseMinEnergy) fUseMinEnergy=1;
1470                 fMinEnergy=6.0; 
1471                 break;
1472         default:
1473                 AliError(Form("Minimum Energy Cut not defined %d",minEnergy));
1474                 return kFALSE;
1475         }
1476         return kTRUE;
1477 }
1478                 
1479 //___________________________________________________________________
1480 Bool_t AliCaloPhotonCuts::SetMinNCellsCut(Int_t minNCells)
1481 {
1482         switch(minNCells){
1483         case 0:
1484                 if (!fUseNCells) fUseNCells=0;
1485                 fMinNCells=0;
1486                 break;
1487         case 1: 
1488                 if (!fUseNCells) fUseNCells=1;
1489                 fMinNCells=1; 
1490                 break;
1491         case 2: 
1492                 if (!fUseNCells) fUseNCells=1;
1493                 fMinNCells=2; 
1494                 break;
1495         case 3: 
1496                 if (!fUseNCells) fUseNCells=1;
1497                 fMinNCells=3; 
1498                 break;
1499         case 4: 
1500                 if (!fUseNCells) fUseNCells=1;
1501                 fMinNCells=4; 
1502                 break;
1503         case 5: 
1504                 if (!fUseNCells) fUseNCells=1;
1505                 fMinNCells=5; 
1506                 break;
1507         case 6: 
1508                 if (!fUseNCells) fUseNCells=1;
1509                 fMinNCells=6; 
1510                 break;
1511
1512         default:
1513                 AliError(Form("Min N cells Cut not defined %d",minNCells));
1514                 return kFALSE;
1515         }
1516         return kTRUE;
1517 }
1518
1519 //___________________________________________________________________
1520 Bool_t AliCaloPhotonCuts::SetMaxM02(Int_t maxM02)
1521 {
1522         switch(maxM02){
1523         case 0: 
1524                 if (!fUseM02) fUseM02=0;
1525                 fMaxM02=100;
1526                 break;
1527         case 1: 
1528                 if (!fUseM02) fUseM02=1;
1529                 fMaxM02=1.; 
1530                 break;
1531         case 2: 
1532                 if (!fUseM02) fUseM02=1;
1533                 fMaxM02=0.7; 
1534                 break;
1535         case 3: 
1536                 if (!fUseM02) fUseM02=1;
1537                 fMaxM02=0.5; 
1538                 break;
1539         case 4: 
1540                 if (!fUseM02) fUseM02=1;
1541                 fMaxM02=0.4; 
1542                 break;
1543         default:
1544                 AliError(Form("Max M02 Cut not defined %d",maxM02));
1545                 return kFALSE;
1546         }
1547         return kTRUE;
1548 }
1549
1550 //___________________________________________________________________
1551 Bool_t AliCaloPhotonCuts::SetMinM02(Int_t minM02)
1552 {
1553         switch(minM02){
1554         case 0: 
1555                 if (!fUseM02) fUseM02=0;
1556                 fMinM02=0;
1557                 break;
1558         case 1: 
1559                 if (!fUseM02) fUseM02=1;
1560                 fMinM02=0.002; 
1561                 break;
1562         case 2: 
1563                 if (!fUseM02) fUseM02=1;
1564                 fMinM02=0.2; 
1565                 break;
1566
1567         default:
1568                 AliError(Form("Min M02 not defined %d",minM02));
1569                 return kFALSE;
1570         }
1571         return kTRUE;
1572 }
1573
1574 //___________________________________________________________________
1575 Bool_t AliCaloPhotonCuts::SetMaxM20(Int_t maxM20)
1576 {
1577         switch(maxM20){
1578         case 0: 
1579                 if (!fUseM20) fUseM20=0;
1580                 fMaxM20=100;
1581                 break;
1582         case 1: 
1583                 if (!fUseM20) fUseM20=1;
1584                 fMaxM20=0.5; 
1585                 break;
1586         default:
1587                 AliError(Form("Max M20 Cut not defined %d",maxM20));
1588                 return kFALSE;
1589         }
1590         return kTRUE;
1591 }
1592
1593 //___________________________________________________________________
1594 Bool_t AliCaloPhotonCuts::SetMinM20(Int_t minM20)
1595 {
1596         switch(minM20){
1597         case 0: 
1598                 if (!fUseM20) fUseM20=0;
1599                 fMinM20=0;
1600                 break;
1601         case 1: 
1602                 if (!fUseM20) fUseM20=1;
1603                 fMinM20=0.002; 
1604                 break;
1605         default:
1606                 AliError(Form("Min M20 Cut not defined %d",minM20));
1607                 return kFALSE;
1608         }
1609         return kTRUE;
1610 }
1611
1612 //___________________________________________________________________
1613 Bool_t AliCaloPhotonCuts::SetDispersion(Int_t dispersion)
1614 {
1615         switch(dispersion){
1616         case 0: 
1617                 if (!fUseDispersion) fUseDispersion=0;
1618                 fMaxDispersion =100;
1619                 break;
1620         case 1: 
1621                 if (!fUseDispersion) fUseDispersion=1;
1622                 fMaxDispersion=2.; 
1623                 break;
1624         default:
1625                 AliError(Form("Maximum Dispersion Cut not defined %d",dispersion));
1626                 return kFALSE;
1627         }
1628         return kTRUE;
1629 }
1630
1631 //___________________________________________________________________
1632 Bool_t AliCaloPhotonCuts::SetNLM(Int_t nlm)
1633 {
1634         switch(nlm){
1635         case 0: 
1636                 if (!fUseNLM) fUseNLM=0;
1637                 fMinNLM =0;
1638                 fMaxNLM =100;
1639                 break;
1640         case 1: 
1641                 if (!fUseNLM) fUseNLM=1;
1642                 fMinNLM =0;
1643                 fMaxNLM =1;
1644                 break;
1645         default:
1646                 AliError(Form("NLM Cut not defined %d",nlm));
1647                 return kFALSE;
1648         }
1649         return kTRUE;
1650 }
1651         
1652 ///________________________________________________________________________
1653 TString AliCaloPhotonCuts::GetCutNumber(){
1654    // returns TString with current cut number
1655    TString a(kNCuts);
1656    for(Int_t ii=0;ii<kNCuts;ii++){
1657       a.Append(Form("%d",fCuts[ii]));
1658    }
1659    return a;
1660 }
1661         
1662