- changes by Lucia in order to include PbPb centrality trigger according to trigger...
[u/mrichter/AliRoot.git] / PWGGA / GammaConv / AliConvEventCuts.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Authors: Svein Lindal, Daniel Lohner                                   *
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 // Gamma Conversion analysis
20 //---------------------------------------------
21 ////////////////////////////////////////////////
22
23 #include "AliConvEventCuts.h"
24
25 #include "AliAODTrack.h"
26 #include "AliESDtrack.h"
27 #include "AliAnalysisManager.h"
28 #include "AliInputEventHandler.h"
29 #include "AliMCEventHandler.h"
30 #include "AliAODHandler.h"
31 #include "TH1.h"
32 #include "TH2.h"
33 #include "TF1.h"
34 #include "AliStack.h"
35 #include "TObjString.h"
36 #include "AliAODEvent.h"
37 #include "AliESDEvent.h"
38 #include "AliCentrality.h"
39 #include "TList.h"
40 #include "TFile.h"
41 #include "AliLog.h"
42 #include "AliGenCocktailEventHeader.h"
43 #include "AliGenDPMjetEventHeader.h"
44 #include "AliGenPythiaEventHeader.h"
45 #include "AliGenHijingEventHeader.h"
46 #include "AliTriggerAnalysis.h"
47 #include "AliV0ReaderV1.h"
48 #include "AliAODMCParticle.h"
49 #include "AliAODMCHeader.h"
50
51 class iostream;
52
53 using namespace std;
54
55 ClassImp(AliConvEventCuts)
56
57
58 const char* AliConvEventCuts::fgkCutNames[AliConvEventCuts::kNCuts] = {
59    "HeavyIon",                                          //0
60    "CentralityMin",                                     //1
61    "CentralityMax",                                     //2
62    "SelectSpecialTrigger",                      //3
63    "SelectSpecialSubTriggerClass",      //4
64    "RemovePileUp",                                      //5
65    "RejectExtraSignals",                        //6
66 };
67
68
69 //________________________________________________________________________
70 AliConvEventCuts::AliConvEventCuts(const char *name,const char *title) :
71         AliAnalysisCuts(name,title),
72         fHistograms(NULL),
73         fHeaderList(NULL),
74         fEventQuality(-1),
75         fIsHeavyIon(0),
76         fDetectorCentrality(0),
77         fModCentralityClass(0),
78         fMaxVertexZ(10),
79         fCentralityMin(0),
80         fCentralityMax(0),
81         fMultiplicityMethod(0),
82         fSpecialTrigger(0),
83         fSpecialSubTrigger(0),
84         fRemovePileUp(kFALSE),
85         fRejectExtraSignals(0),
86         fOfflineTriggerMask(0),
87         fHasV0AND(kTRUE),
88         fIsSDDFired(kTRUE),
89         fRandom(0),
90         fnHeaders(0),
91         fNotRejectedStart(NULL),
92         fNotRejectedEnd(NULL),
93         fGeneratorNames(NULL),
94         fCutString(NULL),
95         fUtils(NULL),
96         fEtaShift(0.0),
97         fDoEtaShift(kFALSE),
98         fDoReweightHistoMCPi0(kFALSE),
99         fDoReweightHistoMCEta(kFALSE),
100         fDoReweightHistoMCK0s(kFALSE),
101         fPathTrFReweighting(""),
102         fNameHistoReweightingPi0(""),
103         fNameHistoReweightingEta(""),
104         fNameHistoReweightingK0s(""),
105         fNameFitDataPi0(""),
106         fNameFitDataEta(""),
107         fNameFitDataK0s(""),
108         fHistoEventCuts(NULL),
109         hCentrality(NULL),
110         hCentralityVsNumberOfPrimaryTracks(NULL),
111         hVertexZ(NULL),
112         hTriggerClass(NULL),
113         hTriggerClassSelected(NULL),
114         hReweightMCHistPi0(NULL),
115         hReweightMCHistEta(NULL),
116         hReweightMCHistK0s(NULL),
117         fFitDataPi0(NULL),
118         fFitDataEta(NULL),
119         fFitDataK0s(NULL),
120         fAddedSignalPDGCode(0),
121         fPreSelCut(kFALSE),
122         fTriggerSelectedManually(kFALSE),
123         fSpecialTriggerName(""),
124         fSpecialSubTriggerName(""),
125         fNSpecialSubTriggerOptions(0),
126         fV0ReaderName(""),
127         fCaloTriggers(NULL),
128         fTriggerPatchInfo(NULL),
129         fMainTriggerPatchEMCAL(NULL),
130         fCaloTriggersName(""),
131         fCaloTriggerPatchInfoName(""),
132         fTriggersEMCAL(0),
133         fTriggersEMCALSelected(-1),
134         fEMCALTrigInitialized(kFALSE)
135         
136 {
137    for(Int_t jj=0;jj<kNCuts;jj++){fCuts[jj]=0;}
138    fCutString=new TObjString((GetCutNumber()).Data());
139
140    fUtils = new AliAnalysisUtils();
141    //if you do not want to apply the cut on the distance between the SPD and TRK vertex:
142    //fUtils->SetCutOnZVertexSPD(kFALSE);
143
144
145 }
146
147 //________________________________________________________________________
148 AliConvEventCuts::AliConvEventCuts(const AliConvEventCuts &ref) :
149         AliAnalysisCuts(ref),
150         fHistograms(NULL),
151         fHeaderList(ref.fHeaderList),
152         fEventQuality(ref.fEventQuality),
153         fIsHeavyIon(ref.fIsHeavyIon),
154         fDetectorCentrality(ref.fDetectorCentrality),
155         fModCentralityClass(ref.fModCentralityClass),
156         fMaxVertexZ(ref.fMaxVertexZ),
157         fCentralityMin(ref.fCentralityMin),
158         fCentralityMax(ref.fCentralityMax),
159         fMultiplicityMethod(ref.fMultiplicityMethod),
160         fSpecialTrigger(ref.fSpecialTrigger),
161         fSpecialSubTrigger(ref.fSpecialSubTrigger),
162         fRemovePileUp(ref.fRemovePileUp),
163         fRejectExtraSignals(ref.fRejectExtraSignals),
164         fOfflineTriggerMask(ref.fOfflineTriggerMask),
165         fHasV0AND(ref.fHasV0AND),
166         fIsSDDFired(ref.fIsSDDFired),
167         fRandom(ref.fRandom),
168         fnHeaders(ref.fnHeaders),
169         fNotRejectedStart(NULL),
170         fNotRejectedEnd(NULL),
171         fGeneratorNames(ref.fGeneratorNames),
172         fCutString(NULL),
173         fUtils(NULL),
174         fEtaShift(ref.fEtaShift),
175         fDoEtaShift(ref.fDoEtaShift),
176         fDoReweightHistoMCPi0(ref.fDoReweightHistoMCPi0),
177         fDoReweightHistoMCEta(ref.fDoReweightHistoMCEta),
178         fDoReweightHistoMCK0s(ref.fDoReweightHistoMCK0s),
179         fPathTrFReweighting(ref.fPathTrFReweighting),
180         fNameHistoReweightingPi0(ref.fNameHistoReweightingPi0),
181         fNameHistoReweightingEta(ref.fNameHistoReweightingEta),
182         fNameHistoReweightingK0s(ref.fNameHistoReweightingK0s),
183         fNameFitDataPi0(ref.fNameFitDataPi0),
184         fNameFitDataEta(ref.fNameFitDataEta),
185         fNameFitDataK0s(ref.fNameFitDataK0s),
186         fHistoEventCuts(NULL),
187         hCentrality(NULL),
188         hCentralityVsNumberOfPrimaryTracks(NULL),
189         hVertexZ(NULL),
190         hTriggerClass(NULL),
191         hTriggerClassSelected(NULL),
192         hReweightMCHistPi0(ref.hReweightMCHistPi0),
193         hReweightMCHistEta(ref.hReweightMCHistEta),
194         hReweightMCHistK0s(ref.hReweightMCHistK0s),
195         fFitDataPi0(ref.fFitDataPi0),
196         fFitDataEta(ref.fFitDataEta),
197         fFitDataK0s(ref.fFitDataK0s),
198         fAddedSignalPDGCode(ref.fAddedSignalPDGCode),
199         fPreSelCut(ref.fPreSelCut),
200         fTriggerSelectedManually(ref.fTriggerSelectedManually),
201         fSpecialTriggerName(ref.fSpecialTriggerName),
202         fSpecialSubTriggerName(ref.fSpecialSubTriggerName),
203         fNSpecialSubTriggerOptions(ref.fNSpecialSubTriggerOptions),
204         fV0ReaderName(ref.fV0ReaderName),
205         fCaloTriggers(NULL),
206         fTriggerPatchInfo(NULL),
207         fMainTriggerPatchEMCAL(NULL),
208         fCaloTriggersName(ref.fCaloTriggersName),
209         fCaloTriggerPatchInfoName(ref.fCaloTriggerPatchInfoName),
210         fTriggersEMCAL(ref.fTriggersEMCAL),
211         fTriggersEMCALSelected(ref.fTriggersEMCALSelected),
212         fEMCALTrigInitialized(kFALSE)
213 {
214    // Copy Constructor
215    for(Int_t jj=0;jj<kNCuts;jj++){fCuts[jj]=ref.fCuts[jj];}
216    fCutString=new TObjString((GetCutNumber()).Data());
217    fUtils = new AliAnalysisUtils();
218    // dont copy histograms (if you like histograms, call InitCutHistograms())
219
220 }
221
222
223 //________________________________________________________________________
224 AliConvEventCuts::~AliConvEventCuts() {
225    // Destructor
226    //Deleting fHistograms leads to seg fault it it's added to output collection of a task
227    // if(fHistograms)
228    //    delete fHistograms;
229    // fHistograms = NULL;
230    if(fCutString != NULL){
231       delete fCutString;
232       fCutString = NULL;
233    }
234    if(fNotRejectedStart){
235       delete[] fNotRejectedStart;
236       fNotRejectedStart = NULL;
237    }
238    if(fNotRejectedEnd){
239       delete[] fNotRejectedEnd;
240       fNotRejectedEnd = NULL;
241    }
242    if(fGeneratorNames){
243       delete[] fGeneratorNames;
244       fGeneratorNames = NULL;
245    }
246    if(fUtils){
247      delete fUtils;
248      fUtils = NULL;
249    }
250
251 }
252
253 //________________________________________________________________________
254 void AliConvEventCuts::InitCutHistograms(TString name, Bool_t preCut){
255
256    // Initialize Cut Histograms for QA (only initialized and filled if function is called)
257    TH1::AddDirectory(kFALSE);
258
259    if(fHistograms != NULL){
260       delete fHistograms;
261       fHistograms=NULL;
262    }
263    if(fHistograms==NULL){
264       fHistograms=new TList();
265       fHistograms->SetOwner(kTRUE);
266       if(name=="")fHistograms->SetName(Form("ConvEventCuts_%s",GetCutNumber().Data()));
267       else fHistograms->SetName(Form("%s_%s",name.Data(),GetCutNumber().Data()));
268    }
269
270    if (hReweightMCHistPi0){
271       hReweightMCHistPi0->SetName("MCInputForWeightingPi0");
272       fHistograms->Add(hReweightMCHistPi0);
273    }
274    if (hReweightMCHistEta){
275       hReweightMCHistEta->SetName("MCInputForWeightingEta");
276       fHistograms->Add(hReweightMCHistEta);
277    }
278    if (hReweightMCHistK0s){
279       hReweightMCHistK0s->SetName("MCInputForWeightingK0s");
280       fHistograms->Add(hReweightMCHistK0s);
281    }
282
283    hCentrality=new TH1F(Form("Centrality %s",GetCutNumber().Data()),"Centrality",100,0,100);
284    fHistograms->Add(hCentrality);
285    hCentralityVsNumberOfPrimaryTracks=new TH2F(Form("Centrality vs Primary Tracks %s",GetCutNumber().Data()),"Centrality vs Primary Tracks ",100,0,100,4000,0,4000);
286    fHistograms->Add(hCentralityVsNumberOfPrimaryTracks);
287
288    // Event Cuts and Info
289    if(preCut){
290       fHistoEventCuts=new TH1F(Form("ESD_EventCuts %s",GetCutNumber().Data()),"Event Cuts",7,-0.5,6.5);
291       fHistoEventCuts->GetXaxis()->SetBinLabel(1,"in");
292       fHistoEventCuts->GetXaxis()->SetBinLabel(2,"OfflineTrigger");
293       fHistoEventCuts->GetXaxis()->SetBinLabel(3,"nvtxcontr");
294       fHistoEventCuts->GetXaxis()->SetBinLabel(4,"VertexZ");
295       fHistoEventCuts->GetXaxis()->SetBinLabel(5,"pileup");
296       fHistoEventCuts->GetXaxis()->SetBinLabel(6,"centrsel");
297       fHistoEventCuts->GetXaxis()->SetBinLabel(7,"out");
298       fHistograms->Add(fHistoEventCuts);
299
300       hVertexZ=new TH1F(Form("VertexZ %s",GetCutNumber().Data()),"VertexZ",1000,-50,50);
301       fHistograms->Add(hVertexZ);
302
303       hTriggerClass= new TH1F(Form("OfflineTrigger %s",GetCutNumber().Data()),"OfflineTrigger",35,-0.5,34.5);
304       hTriggerClass->GetXaxis()->SetBinLabel( 1,"kMB");
305       hTriggerClass->GetXaxis()->SetBinLabel( 2,"kINT7");
306       hTriggerClass->GetXaxis()->SetBinLabel( 3,"kMUON");
307       hTriggerClass->GetXaxis()->SetBinLabel( 4,"kHighMult");
308       hTriggerClass->GetXaxis()->SetBinLabel( 5,"kKEMC1");
309       hTriggerClass->GetXaxis()->SetBinLabel( 6,"kCINT5");
310       hTriggerClass->GetXaxis()->SetBinLabel( 7,"kCMUS5/kMUSPB");
311       hTriggerClass->GetXaxis()->SetBinLabel( 8,"kMUSH7/kMUSHPB");
312       hTriggerClass->GetXaxis()->SetBinLabel( 9,"kMUL7/kMuonLikePB");
313       hTriggerClass->GetXaxis()->SetBinLabel(10,"kMUU7/kMuonUnlikePB");
314       hTriggerClass->GetXaxis()->SetBinLabel(11,"kEMC7/kEMC8");
315       hTriggerClass->GetXaxis()->SetBinLabel(12,"kMUS7");
316       hTriggerClass->GetXaxis()->SetBinLabel(13,"kPHI1");
317       hTriggerClass->GetXaxis()->SetBinLabel(14,"kPHI7/kPHI8/kPHOSPb");
318       hTriggerClass->GetXaxis()->SetBinLabel(15,"kEMCEJE");
319       hTriggerClass->GetXaxis()->SetBinLabel(16,"kEMCEGA");
320       hTriggerClass->GetXaxis()->SetBinLabel(17,"kCentral");
321       hTriggerClass->GetXaxis()->SetBinLabel(18,"kSemiCentral");
322       hTriggerClass->GetXaxis()->SetBinLabel(19,"kDG5");
323       hTriggerClass->GetXaxis()->SetBinLabel(20,"kZED");
324       hTriggerClass->GetXaxis()->SetBinLabel(21,"kSPI7/kSPI");
325       hTriggerClass->GetXaxis()->SetBinLabel(22,"kINT8");
326       hTriggerClass->GetXaxis()->SetBinLabel(23,"kMuonSingleLowPt8");
327       hTriggerClass->GetXaxis()->SetBinLabel(24,"kMuonSingleHighPt8");
328       hTriggerClass->GetXaxis()->SetBinLabel(25,"kMuonLikeLowPt8");
329       hTriggerClass->GetXaxis()->SetBinLabel(26,"kMuonUnlikeLowPt8");
330       hTriggerClass->GetXaxis()->SetBinLabel(27,"kMuonUnlikeLowPt0");
331       hTriggerClass->GetXaxis()->SetBinLabel(28,"kUserDefined");
332       hTriggerClass->GetXaxis()->SetBinLabel(29,"kTRD");
333       hTriggerClass->GetXaxis()->SetBinLabel(30,"kFastOnly");
334       hTriggerClass->GetXaxis()->SetBinLabel(31,"kAnyINT");
335       hTriggerClass->GetXaxis()->SetBinLabel(32,"kAny");
336       hTriggerClass->GetXaxis()->SetBinLabel(33,"V0AND");
337       hTriggerClass->GetXaxis()->SetBinLabel(34,"NOT kFastOnly");
338       hTriggerClass->GetXaxis()->SetBinLabel(35,"failed Physics Selection");
339       fHistograms->Add(hTriggerClass);
340    }
341    if(!preCut){
342       hTriggerClassSelected= new TH1F(Form("OfflineTriggerSelected %s",GetCutNumber().Data()),"OfflineTriggerSelected",34,-0.5,33.5);
343       hTriggerClassSelected->GetXaxis()->SetBinLabel( 1,"kMB");
344       hTriggerClassSelected->GetXaxis()->SetBinLabel( 2,"kINT7");
345       hTriggerClassSelected->GetXaxis()->SetBinLabel( 3,"kMUON");
346       hTriggerClassSelected->GetXaxis()->SetBinLabel( 4,"kHighMult");
347       hTriggerClassSelected->GetXaxis()->SetBinLabel( 5,"kKEMC1");
348       hTriggerClassSelected->GetXaxis()->SetBinLabel( 6,"kCINT5");
349       hTriggerClassSelected->GetXaxis()->SetBinLabel( 7,"kCMUS5/kMUSPB");
350       hTriggerClassSelected->GetXaxis()->SetBinLabel( 8,"kMUSH7/kMUSHPB");
351       hTriggerClassSelected->GetXaxis()->SetBinLabel( 9,"kMUL7/kMuonLikePB");
352       hTriggerClassSelected->GetXaxis()->SetBinLabel(10,"kMUU7/kMuonUnlikePB");
353       hTriggerClassSelected->GetXaxis()->SetBinLabel(11,"kEMC7/kEMC8");
354       hTriggerClassSelected->GetXaxis()->SetBinLabel(12,"kMUS7");
355       hTriggerClassSelected->GetXaxis()->SetBinLabel(13,"kPHI1");
356       hTriggerClassSelected->GetXaxis()->SetBinLabel(14,"kPHI7/kPHI8/kPHOSPb");
357       hTriggerClassSelected->GetXaxis()->SetBinLabel(15,"kEMCEJE");
358       hTriggerClassSelected->GetXaxis()->SetBinLabel(16,"kEMCEGA");
359       hTriggerClassSelected->GetXaxis()->SetBinLabel(17,"kCentral");
360       hTriggerClassSelected->GetXaxis()->SetBinLabel(18,"kSemiCentral");
361       hTriggerClassSelected->GetXaxis()->SetBinLabel(19,"kDG5");
362       hTriggerClassSelected->GetXaxis()->SetBinLabel(20,"kZED");
363       hTriggerClassSelected->GetXaxis()->SetBinLabel(21,"kSPI7/kSPI");
364       hTriggerClassSelected->GetXaxis()->SetBinLabel(22,"kINT8");
365       hTriggerClassSelected->GetXaxis()->SetBinLabel(23,"kMuonSingleLowPt8");
366       hTriggerClassSelected->GetXaxis()->SetBinLabel(24,"kMuonSingleHighPt8");
367       hTriggerClassSelected->GetXaxis()->SetBinLabel(25,"kMuonLikeLowPt8");
368       hTriggerClassSelected->GetXaxis()->SetBinLabel(26,"kMuonUnlikeLowPt8");
369       hTriggerClassSelected->GetXaxis()->SetBinLabel(27,"kMuonUnlikeLowPt0");
370       hTriggerClassSelected->GetXaxis()->SetBinLabel(28,"kUserDefined");
371       hTriggerClassSelected->GetXaxis()->SetBinLabel(29,"kTRD");
372       hTriggerClassSelected->GetXaxis()->SetBinLabel(30,"kFastOnly");
373       hTriggerClassSelected->GetXaxis()->SetBinLabel(31,"kAnyINT");
374       hTriggerClassSelected->GetXaxis()->SetBinLabel(32,"kAny");
375       hTriggerClassSelected->GetXaxis()->SetBinLabel(33,"V0AND");
376       hTriggerClassSelected->GetXaxis()->SetBinLabel(34,"NOT kFastOnly");
377       fHistograms->Add(hTriggerClassSelected);
378       
379    }
380    TH1::AddDirectory(kTRUE);
381 }
382
383 ///________________________________________________________________________
384 Bool_t AliConvEventCuts::EventIsSelected(AliVEvent *fInputEvent, AliVEvent *fMCEvent){
385    // Process Event Selection
386
387    Int_t cutindex=0;
388    if(fHistoEventCuts)fHistoEventCuts->Fill(cutindex);
389    cutindex++;
390
391    // Check for MC event
392    Bool_t isMC = kFALSE;
393    if(fMCEvent && fInputEvent->IsA()==AliESDEvent::Class()){
394       // Check if MC event is correctly loaded
395       AliMCEventHandler* mcHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
396       if (!mcHandler){
397          fEventQuality = 2;
398          return kFALSE;
399       }
400       if (!mcHandler->InitOk() ){
401          fEventQuality = 2;
402          return kFALSE;
403       }
404       if (!mcHandler->TreeK() ){
405          fEventQuality = 2;
406          return kFALSE;
407       }
408       if (!mcHandler->TreeTR() ) {
409          fEventQuality = 2;
410          return kFALSE;
411       }
412       isMC = kTRUE;
413    }
414
415    
416    
417    // Event Trigger
418 //    cout << "before event trigger" << endl;
419    if(!IsTriggerSelected(fInputEvent, isMC )){
420       if(fHistoEventCuts)fHistoEventCuts->Fill(cutindex);
421       fEventQuality = 3;
422       return kFALSE;
423    }
424    cutindex++;
425
426    if(fInputEvent->IsA()==AliESDEvent::Class()){
427       AliTriggerAnalysis fTriggerAnalysis;// = new AliTriggerAnalysis;
428       fHasV0AND = fTriggerAnalysis.IsOfflineTriggerFired((AliESDEvent*)fInputEvent, AliTriggerAnalysis::kV0AND);
429       if(fHasV0AND&&hTriggerClass)hTriggerClass->Fill(32);
430    }
431 //   cout << "event number " << ((AliESDEvent*)fInputEvent)->GetEventNumberInFile() << " entered"<< endl;
432
433
434    // Number of Contributors Cut
435    if(GetNumberOfContributorsVtx(fInputEvent)<=0) {
436       if(fHistoEventCuts)fHistoEventCuts->Fill(cutindex);
437       fEventQuality = 5;
438       return kFALSE;
439    }
440    cutindex++;
441
442    // Z Vertex Position Cut
443    if(!VertexZCut(fInputEvent)){
444       if(fHistoEventCuts)fHistoEventCuts->Fill(cutindex);
445       fEventQuality = 4;
446       return kFALSE;
447    }
448    cutindex++;
449
450    // Pile Up Rejection
451
452    if(fRemovePileUp){
453       if(fInputEvent->IsPileupFromSPD(3,0.8,3.,2.,5.)){
454          if(fHistoEventCuts)fHistoEventCuts->Fill(cutindex);
455          fEventQuality = 6;
456          return kFALSE;
457       }
458    }
459    cutindex++;
460
461    // Centrality Selection
462    if(!IsCentralitySelected(fInputEvent,fMCEvent)){
463       if(fHistoEventCuts)fHistoEventCuts->Fill(cutindex);
464       fEventQuality = 1;
465       return kFALSE;
466    }
467    cutindex++;
468
469    // Fill Event Histograms
470    if(fHistoEventCuts)fHistoEventCuts->Fill(cutindex);
471    if(hVertexZ)hVertexZ->Fill(fInputEvent->GetPrimaryVertex()->GetZ());
472    if(hCentrality)hCentrality->Fill(GetCentrality(fInputEvent));
473    if(hCentralityVsNumberOfPrimaryTracks)
474       hCentralityVsNumberOfPrimaryTracks->Fill(GetCentrality(fInputEvent),
475                                                ((AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()
476                                                 ->GetTask(fV0ReaderName.Data()))->GetNumberOfPrimaryTracks());
477    fEventQuality = 0;
478    return kTRUE;
479 }
480
481 ///________________________________________________________________________
482 Bool_t AliConvEventCuts::UpdateCutString() {
483         ///Update the cut string (if it has been created yet)
484
485         if(fCutString && fCutString->GetString().Length() == kNCuts) {
486                 fCutString->SetString(GetCutNumber());
487         } else {
488                 return kFALSE;
489         }
490         return kTRUE;
491 }
492
493 ///________________________________________________________________________
494 void AliConvEventCuts::LoadReweightingHistosMCFromFile() {
495
496         AliInfo("Entering loading of histograms for weighting");
497         TFile *f = TFile::Open(fPathTrFReweighting.Data());
498         if(!f){
499                 AliError(Form("file for weighting %s not found",fPathTrFReweighting.Data()));
500                 return;
501         }
502         if (fNameHistoReweightingPi0.CompareTo("") != 0 && fDoReweightHistoMCPi0 ){
503                 cout << "I have to find: " <<  fNameHistoReweightingPi0.Data() << endl;
504                 TH1D *hReweightMCHistPi0temp = (TH1D*)f->Get(fNameHistoReweightingPi0.Data());
505                 hReweightMCHistPi0 = new TH1D(*hReweightMCHistPi0temp);
506                 if (hReweightMCHistPi0) AliInfo(Form("%s has been loaded from %s", fNameHistoReweightingPi0.Data(),fPathTrFReweighting.Data() ));
507                 else AliWarning(Form("%s not found in %s", fNameHistoReweightingPi0.Data() ,fPathTrFReweighting.Data()));
508                 hReweightMCHistPi0->SetDirectory(0);
509         }
510         if (fNameFitDataPi0.CompareTo("") != 0 && fDoReweightHistoMCPi0 ){
511                 cout << "I have to find: " <<  fNameFitDataPi0.Data() << endl;
512                 TF1 *fFitDataPi0temp = (TF1*)f->Get(fNameFitDataPi0.Data());
513                 fFitDataPi0 = new TF1(*fFitDataPi0temp);
514                 if (fFitDataPi0) AliInfo(Form("%s has been loaded from %s", fNameFitDataPi0.Data(),fPathTrFReweighting.Data() ));
515                 else AliWarning(Form("%s not found in %s",fPathTrFReweighting.Data(), fNameFitDataPi0.Data() ));
516         }
517
518         if (fNameHistoReweightingEta.CompareTo("") != 0 && fDoReweightHistoMCEta){
519                 cout << "I have to find: " <<  fNameHistoReweightingEta.Data() << endl;
520                 TH1D *hReweightMCHistEtatemp = (TH1D*)f->Get(fNameHistoReweightingEta.Data());
521                 hReweightMCHistEta = new TH1D(*hReweightMCHistEtatemp);
522                 if (hReweightMCHistEta) AliInfo(Form("%s has been loaded from %s", fNameHistoReweightingEta.Data(),fPathTrFReweighting.Data() ));
523                 else AliWarning(Form("%s not found in %s", fNameHistoReweightingEta.Data(),fPathTrFReweighting.Data() ));
524                 hReweightMCHistEta->SetDirectory(0);
525         }
526
527         if (fNameFitDataEta.CompareTo("") != 0 && fDoReweightHistoMCEta){
528                 cout << "I have to find: " <<  fNameFitDataEta.Data() << endl;
529                 TF1 *fFitDataEtatemp = (TF1*)f->Get(fNameFitDataEta.Data());
530                 fFitDataEta = new TF1(*fFitDataEtatemp);
531                 if (fFitDataEta) AliInfo(Form("%s has been loaded from %s", fNameFitDataEta.Data(),fPathTrFReweighting.Data() ));
532                 else AliWarning(Form("%s not found in %s", fNameFitDataEta.Data(),fPathTrFReweighting.Data() ));
533
534         }
535         if (fNameHistoReweightingK0s.CompareTo("") != 0 && fDoReweightHistoMCK0s){
536                 cout << "I have to find: " <<  fNameHistoReweightingK0s.Data() << endl;
537                 TH1D *hReweightMCHistK0stemp = (TH1D*)f->Get(fNameHistoReweightingK0s.Data());
538                 hReweightMCHistK0s = new TH1D(*hReweightMCHistK0stemp);
539                 if (hReweightMCHistK0s) AliInfo(Form("%s has been loaded from %s", fNameHistoReweightingK0s.Data(),fPathTrFReweighting.Data() ));
540                 else AliWarning(Form("%s not found in %s", fNameHistoReweightingK0s.Data(),fPathTrFReweighting.Data() ));
541                 hReweightMCHistK0s->SetDirectory(0);
542         }
543
544         if (fNameFitDataK0s.CompareTo("") != 0 && fDoReweightHistoMCK0s){
545                 cout << "I have to find: " <<  fNameFitDataK0s.Data() << endl; 
546                 TF1 *fFitDataK0stemp = (TF1*)f->Get(fNameFitDataK0s.Data());
547                 fFitDataK0s = new TF1(*fFitDataK0stemp);
548                 if (fFitDataK0s) AliInfo(Form("%s has been loaded from %s", fNameFitDataK0s.Data(),fPathTrFReweighting.Data() ));
549                 else AliWarning(Form("%s not found in %s", fNameFitDataK0s.Data(),fPathTrFReweighting.Data() ));
550         }
551         f->Close();
552         delete f;
553 }
554
555
556 ///________________________________________________________________________
557 Bool_t AliConvEventCuts::InitializeCutsFromCutString(const TString analysisCutSelection ) {
558         // Initialize Cuts from a given Cut string
559         if(fDoReweightHistoMCPi0 || fDoReweightHistoMCEta || fDoReweightHistoMCK0s) {
560                 AliInfo("Weighting was enabled");
561                 LoadReweightingHistosMCFromFile();
562         }
563
564         AliInfo(Form("Set Event Cut Number: %s",analysisCutSelection.Data()));
565         if(analysisCutSelection.Length()!=kNCuts) {
566                 AliError(Form("Cut selection has the wrong length! size is %d, number of cuts is %d", analysisCutSelection.Length(), kNCuts));
567                 return kFALSE;
568         }
569         if(!analysisCutSelection.IsDigit()){
570                 AliError("Cut selection contains characters");
571                 return kFALSE;
572         }
573
574         if (fV0ReaderName.CompareTo("") == 0){
575                 fV0ReaderName = "V0ReaderV1";
576         }       
577         const char *cutSelection = analysisCutSelection.Data();
578         #define ASSIGNARRAY(i)  fCuts[i] = cutSelection[i] - '0'
579         for(Int_t ii=0;ii<kNCuts;ii++){
580                 ASSIGNARRAY(ii);
581         }
582
583         // Set Individual Cuts
584         for(Int_t ii=0;ii<kNCuts;ii++){
585                 if(!SetCut(cutIds(ii),fCuts[ii]))return kFALSE;
586         }
587
588         PrintCutsWithValues();
589
590         return kTRUE;
591 }
592
593 ///________________________________________________________________________
594 Bool_t AliConvEventCuts::SetCut(cutIds cutID, const Int_t value) {
595         ///Set individual cut ID
596
597         switch (cutID) {
598         case kremovePileUp:
599                 if( SetRemovePileUp(value)) {
600                         fCuts[kremovePileUp] = value;
601                         UpdateCutString();
602                         return kTRUE;
603                 } else return kFALSE;
604         case kSelectSpecialTriggerAlias:
605                 if( SetSelectSpecialTrigger(value)) {
606                         fCuts[kSelectSpecialTriggerAlias] = value;
607                         UpdateCutString();
608                         return kTRUE;
609                 } else return kFALSE;
610         case kSelectSubTriggerClass:
611                 if( SetSelectSubTriggerClass(value)) {
612                         fCuts[kSelectSubTriggerClass] = value;
613                         UpdateCutString();
614                         return kTRUE;
615                 } else return kFALSE;
616         case kisHeavyIon:
617                 if( SetIsHeavyIon(value)) {
618                         fCuts[kisHeavyIon] = value;
619                         UpdateCutString();
620                         return kTRUE;
621                 } else return kFALSE;
622         case kCentralityMin:
623                 if( SetCentralityMin(value)) {
624                         fCuts[kCentralityMin] = value;
625                         UpdateCutString();
626                         return kTRUE;
627                 } else return kFALSE;
628         case kCentralityMax:
629                 if( SetCentralityMax(value)) {
630                         fCuts[kCentralityMax] = value;
631                         UpdateCutString();
632                         return kTRUE;
633                 } else return kFALSE;
634         case kExtraSignals:
635                 if( SetRejectExtraSignalsCut(value)) {
636                         fCuts[kExtraSignals] = value;
637                         UpdateCutString();
638                         return kTRUE;
639                 } else return kFALSE;           
640         case kNCuts:
641                 AliError("Cut id out of range");
642                 return kFALSE;
643         }
644
645         AliError("Cut id %d not recognized");
646         return kFALSE;
647 }
648
649 ///________________________________________________________________________
650 void AliConvEventCuts::PrintCuts() {
651         // Print out current Cut Selection
652         for(Int_t ic = 0; ic < kNCuts; ic++) {
653                 printf("%-30s : %d \n", fgkCutNames[ic], fCuts[ic]);
654         }
655 }
656
657 void AliConvEventCuts::PrintCutsWithValues() {
658    // Print out current Cut Selection with value
659         printf("\nEvent cutnumber \n");
660         for(Int_t ic = 0; ic < kNCuts; ic++) {
661                 printf("%d",fCuts[ic]);
662         }
663         printf("\n\n");
664
665         if (fIsHeavyIon == 0) {
666                 printf("Running in pp mode \n");
667                 if (fSpecialTrigger == 0){
668                         if (fSpecialSubTrigger == 0){
669                                 printf("\t only events triggered by V0OR will be analysed \n");
670                         } else if (fSpecialSubTrigger == 1){
671                                 printf("\t only events where SDD was present will be analysed \n");
672                         }
673                 } else if (fSpecialTrigger == 1){
674                         if (fSpecialSubTrigger == 0){
675                                 printf("\t only events triggered by V0AND will be analysed \n");
676                         } else if(fSpecialSubTrigger == 1){
677                                 printf("\t only events where SDD was present will be analysed and triggered by VOAND\n");
678                         }    
679                 } else if (fSpecialTrigger > 1){ 
680                         printf("\t only events triggered by %s %s\n", fSpecialTriggerName.Data(), fSpecialSubTriggerName.Data());
681                 }
682         } else if (fIsHeavyIon == 1){ 
683                 printf("Running in PbPb mode \n");
684                 if (fDetectorCentrality == 0){
685                         printf("\t centrality selection based on V0M \n");
686                 } else if (fDetectorCentrality == 1){
687                         printf("\t centrality selection based on Cl1 \n");
688                 }   
689                 if (fModCentralityClass == 0){
690                         printf("\t %d - %d \n", fCentralityMin*10, fCentralityMax*10);
691                 } else if ( fModCentralityClass == 1){ 
692                         printf("\t %d - %d \n", fCentralityMin*5, fCentralityMax*5);
693                 } else if ( fModCentralityClass == 2){ 
694                         printf("\t %d - %d \n", fCentralityMin*5+45, fCentralityMax*5+45);
695                 } else if (fModCentralityClass == 3){
696                         printf("\t %d - %d, with Track mult in MC as data \n", fCentralityMin*10, fCentralityMax*10);
697                 } else if ( fModCentralityClass == 4){ 
698                         printf("\t %d - %d, with Track mult in MC as data \n", fCentralityMin*5, fCentralityMax*5);
699                 } else if ( fModCentralityClass == 5){ 
700                         printf("\t %d - %d, with Track mult in MC as data \n", fCentralityMin*5+45, fCentralityMax*5+45);
701                 }
702                 if (fSpecialTrigger == 0){
703                         printf("\t only events triggered by kMB, kCentral, kSemiCentral will be analysed \n");
704                 } else if (fSpecialTrigger > 1){
705                         printf("\t only events triggered by %s %s\n", fSpecialTriggerName.Data(), fSpecialSubTriggerName.Data());
706                         printf("\n\t        SpecialTrigger is:  %s\n", fSpecialTriggerName.Data());
707                         printf("\t        SpecialSubTrigger is: %s\n\n", fSpecialSubTriggerName.Data());
708                 }
709         } else if (fIsHeavyIon == 2){
710                 printf("Running in pPb mode \n");
711                 if (fDetectorCentrality == 0){
712                         printf("\t centrality selection based on V0A \n");
713                 } else if (fDetectorCentrality == 1){
714                         printf("\t centrality selection based on Cl1 \n");
715                 }   
716                 if (fModCentralityClass == 0){
717                         printf("\t %d - %d \n", fCentralityMin*10, fCentralityMax*10);
718                 }
719                 if (fSpecialTrigger == 0){
720                         printf("\t only events triggered by kINT7 will be analysed \n");
721                 } else if (fSpecialTrigger > 1){ 
722                         printf("\t only events triggered by %s %s\n", fSpecialTriggerName.Data(), fSpecialSubTriggerName.Data());
723                 }
724         }
725         printf("MC event cuts: \n");
726         if (fRejectExtraSignals == 0) printf("\t no rejection was applied \n");
727                 else if (fRejectExtraSignals == 1) printf("\t only MB header will be inspected \n");
728                 else if (fRejectExtraSignals > 1) printf("\t special header have been selected \n");
729 }
730
731 ///________________________________________________________________________
732 Bool_t AliConvEventCuts::SetIsHeavyIon(Int_t isHeavyIon)
733 {   // Set Cut
734         switch(isHeavyIon){
735         case 0:
736                 fIsHeavyIon=0;
737                 break;
738         case 1:
739                 fIsHeavyIon=1;
740                 fDetectorCentrality=0;
741                 break;
742         case 2:
743                 fIsHeavyIon=1;
744                 fDetectorCentrality=1;
745                 break;
746         case 3: //allows to select centrality 0-45% in steps of 5% for V0 Multiplicity
747                 fIsHeavyIon=1;
748                 fDetectorCentrality=0;
749                 fModCentralityClass=1;
750                 break;
751         case 4: //allows to select centrality 45-90% in steps of 5% for V0 Multiplicity
752                 fIsHeavyIon=1;
753                 fDetectorCentrality=0;
754                 fModCentralityClass=2;
755                 break;
756         case 5: //strict cut on v0 tracks for MC
757                 fIsHeavyIon=1;
758                 fDetectorCentrality=0;
759                 fModCentralityClass=3;
760                 break;
761         case 6: //allows to select centrality 0-45% in steps of 5% for track mult
762                 //strict cut on v0 tracks for MC
763                 fIsHeavyIon=1;
764                 fDetectorCentrality=0;
765                 fModCentralityClass=4;
766                 break;
767         case 7: //allows to select centrality 45-90% in steps of 5% for V0 Multiplicity
768                 //strict cut on v0 tracks for MC
769                 fIsHeavyIon=1;
770                 fDetectorCentrality=0;
771                 fModCentralityClass=5;
772                 break;
773         case 8:
774                 fIsHeavyIon=2;
775                 fDetectorCentrality=0;
776                 break;
777         case 9:
778                 fIsHeavyIon=2;
779                 fDetectorCentrality=1;
780                 break;
781         default:
782                 AliError(Form("SetHeavyIon not defined %d",isHeavyIon));
783                 return kFALSE;
784         }
785         return kTRUE;
786 }
787
788 //___________________________________________________________________
789 Bool_t AliConvEventCuts::SetCentralityMin(Int_t minCentrality)
790 {
791         // Set Cut
792         if(minCentrality<0||minCentrality>9){
793                 AliError(Form("minCentrality not defined %d",minCentrality));
794                 return kFALSE;
795         }
796
797         fCentralityMin=minCentrality;
798         return kTRUE;
799 }
800
801 //___________________________________________________________________
802 Bool_t AliConvEventCuts::SetCentralityMax(Int_t maxCentrality)
803 {
804         // Set Cut
805         if(maxCentrality<0||maxCentrality>9){
806                 AliError(Form("maxCentrality not defined %d",maxCentrality));
807                 return kFALSE;
808         }
809         fCentralityMax=maxCentrality;
810         return kTRUE;
811 }
812
813 ///________________________________________________________________________
814 Bool_t AliConvEventCuts::SetSelectSpecialTrigger(Int_t selectSpecialTrigger)
815 {// Set Cut
816
817         switch(selectSpecialTrigger){
818         case 0:
819                 fSpecialTrigger=0; // V0OR
820                 break;
821         case 1:
822                 fSpecialTrigger=1; // V0AND
823                 break;
824 //      case 2:
825 //              fSpecialTrigger=2; // 
826 //              break;
827         case 3:       
828                 fSpecialTrigger=3; //specific centrality trigger selection
829                 fSpecialTriggerName="AliVEvent::kCentral/kSemiCentral/kMB";
830                 break;
831         case 4:
832                 fSpecialTrigger=4; // trigger alias kTRD 
833                 fOfflineTriggerMask=AliVEvent::kTRD;
834                 fTriggerSelectedManually = kTRUE;
835                 fSpecialTriggerName="AliVEvent::kTRD";
836                 break;
837         case 5:
838                 fSpecialTrigger=5; // trigger alias kEMC
839                 fOfflineTriggerMask=AliVEvent::kEMC7 | AliVEvent::kEMC8 | AliVEvent::kEMC1 ;
840                 fTriggerSelectedManually = kTRUE;
841                 fTriggersEMCALSelected= 0;
842                 SETBIT(fTriggersEMCALSelected, kL0);
843                 fSpecialTriggerName="AliVEvent::kEMC7/kEMC8/kEMC1";
844                 break;
845         case 6:
846                 fSpecialTrigger=6; // trigger alias kPHI
847                 fOfflineTriggerMask=AliVEvent::kPHI7 | AliVEvent::kPHI1 | AliVEvent::kPHI8 | AliVEvent::kPHOSPb;
848                 fTriggerSelectedManually = kTRUE;
849                 fSpecialTriggerName="AliVEvent::kPHI7/kPHI1/kPHI8/kPHOSPb";
850                 break;
851         case 7:
852                 fSpecialTrigger=7; // trigger alias kHighMult
853                 fOfflineTriggerMask=AliVEvent::kHighMult;
854                 fTriggerSelectedManually = kTRUE;
855                 fSpecialTriggerName="AliVEvent::kHighMult";
856                 break;
857                 case 8:
858                 fSpecialTrigger=8; // trigger alias kEMCEGA
859                 fOfflineTriggerMask=AliVEvent::kEMCEGA;
860                 fTriggerSelectedManually = kTRUE;
861                 fTriggersEMCALSelected= 0;
862                 SETBIT(fTriggersEMCALSelected, kG2);
863                 fSpecialTriggerName="AliVEvent::kEMCEGA";
864                 break;
865                 case 9:
866                 fSpecialTrigger=9; // trigger alias kEMCEJE
867                 fOfflineTriggerMask=AliVEvent::kEMCEJE;
868                 fTriggerSelectedManually = kTRUE;
869                 fTriggersEMCALSelected= 0;
870                 SETBIT(fTriggersEMCALSelected, kJ2);
871                 fSpecialTriggerName="AliVEvent::kEMCEJE";
872                 break;
873         default:
874                 AliError("Warning: Special Trigger Not known");
875                 return 0;
876         }
877         return 1;
878 }
879
880 ///________________________________________________________________________
881 Bool_t AliConvEventCuts::SetSelectSubTriggerClass(Int_t selectSpecialSubTriggerClass)
882 {// Set Cut
883
884         if (fSpecialTrigger == 0){ //OR 
885                 switch(selectSpecialSubTriggerClass){
886                 case 0://with VZERO
887                         fSpecialTrigger=0;
888                         fSpecialSubTrigger=0; 
889 //                      AliInfo("Info: Nothing to be done");
890                         break;  
891                 case 3: //V0OR with SDD requested (will only work with LHC11a dataset)
892                         fSpecialSubTrigger=1; 
893                         cout << "V0OR with SDD requested" << endl;          
894                         break;
895                 default:
896                         AliError("Warning: Special Subtrigger Class Not known");
897                         return 0;
898                 }       
899         } else if (fSpecialTrigger == 1){ //AND with different detectors
900                 switch(selectSpecialSubTriggerClass){
901                 case 0: //with VZERO general implementation of V0AND (periods LHC11c onwards)
902                         fSpecialTrigger=0;
903                         fSpecialSubTrigger=0; 
904                         fOfflineTriggerMask=AliVEvent::kINT7;
905                         fTriggerSelectedManually = kTRUE;
906                         fSpecialTriggerName="AliVEvent::kINT7";
907                 break;
908                 case 1: //with TZERO
909                         fSpecialTrigger=0;
910                         fSpecialSubTrigger=0; 
911                         fOfflineTriggerMask=AliVEvent::kINT8;
912                         fTriggerSelectedManually = kTRUE;
913                         fSpecialTriggerName="AliVEvent::kINT8";
914                         break;
915                 case 2: //with VZERO (will only work with LHC11a dataset)
916                         fSpecialTrigger=1;
917                         fSpecialSubTrigger=0; 
918 //                      AliInfo("Info: Nothing to be done");
919                         break;  
920                 case 3: //V0AND with SDD requested (will only work with LHC11a dataset)
921                         fSpecialTrigger=1;
922                         fSpecialSubTrigger=1; 
923                         break;
924                 default:
925                         AliError("Warning: Special Subtrigger Class Not known");
926                         return 0;
927                 }               
928         } else if (fSpecialTrigger == 3){ // Selecting kCentral and kSemiCentral from trigger classes, not aliases
929                 switch(selectSpecialSubTriggerClass){
930                 case 0: // all together
931                         fSpecialSubTrigger=0; 
932                         fSpecialSubTriggerName="";
933 //                      AliInfo("Info: Nothing to be done");
934                         break;
935                 case 1: // kCentral - no vertex restriction
936                         fSpecialSubTrigger=1; 
937                         fNSpecialSubTriggerOptions=1;
938                         fSpecialSubTriggerName="CVHN";
939                         cout << "kCentralOpen" << endl;
940                         break;
941                 case 2: // kCentral - T00 +- 10 cm
942                         fSpecialSubTrigger=1; 
943                         fNSpecialSubTriggerOptions=1;
944                         fSpecialSubTriggerName="CCENT";
945                         cout << "kCentralVertex" << endl;
946                         break;
947                 case 3: // kCentral - both
948                         fSpecialSubTrigger=1; 
949                         fNSpecialSubTriggerOptions=1;
950                         fSpecialSubTriggerName="CVHN|CCENT";
951                         cout << "kCentral both" << endl;
952                         break;
953                 case 4: // kSemiCentral - no vertex restriction
954                         fSpecialSubTrigger=1; 
955                         fNSpecialSubTriggerOptions=1;
956                         fSpecialSubTriggerName="CVLN";
957                         cout << "kSemiCentralOpen" << endl;
958                         break;
959                 case 5: // kSemiCentral - T00 +- 10 cm
960                         fSpecialSubTrigger=1; 
961                         fNSpecialSubTriggerOptions=1;
962                         fSpecialSubTriggerName="CSEMI";
963                         cout << "kSemiCentralVertex" << endl;
964                         break;
965                 case 6: // kSemiCentral - both
966                         fSpecialSubTrigger=1; 
967                         fNSpecialSubTriggerOptions=1;
968                         fSpecialSubTriggerName="CSEMI%CVLN";
969                         cout << "kSemiCentral both" << endl;
970                         break;
971                 case 7: // kMB
972                         fSpecialSubTrigger=1; 
973                         fNSpecialSubTriggerOptions=1;
974                         fSpecialSubTriggerName="CPBI1_|CPBI1-";
975                         cout << "kMB 1" << endl;
976                         break;                  
977                 case 8: // kMB
978                         fSpecialSubTrigger=1; 
979                         fNSpecialSubTriggerOptions=1;
980                         fSpecialSubTriggerName="CPBI2_|CPBI2-";
981                         cout << "kMB 2" << endl;
982                         break;                  
983                 default:
984                         AliError("Warning: Special Subtrigger Class Not known");
985                         return 0;
986                 }               
987         } else if (fSpecialTrigger == 4){ // Subdivision of TRD trigger classes
988                 switch(selectSpecialSubTriggerClass){
989                 case 0: // all together
990                         fSpecialSubTrigger=0; 
991                         fSpecialSubTriggerName="";
992 //                      AliInfo("Info: Nothing to be done");
993                         break;
994                 case 1: // 7WUHSH - V0AND with single electron in TRD & EMCAL
995                         fSpecialSubTrigger=1; 
996                         fNSpecialSubTriggerOptions=1;
997                         fSpecialSubTriggerName="7WUHEE";
998                         break;
999                 case 2: // 8WUHSH - T0AND with single electron in TRD & EMCAL
1000                         fSpecialSubTrigger=1; 
1001                         fNSpecialSubTriggerOptions=1;
1002                         fSpecialSubTriggerName="8WUHEE";
1003                         break;
1004                 case 3: // 7WUHSE - V0AND with single high pt electron in TRD
1005                         fSpecialSubTrigger=1; 
1006                         fNSpecialSubTriggerOptions=1;
1007                         fSpecialSubTriggerName="7WUHSE";
1008                         break;
1009                 case 4: // 8WUHSE - T0AND with single high pt electron in TRD
1010                         fSpecialSubTrigger=1; 
1011                         fNSpecialSubTriggerOptions=1;
1012                         fSpecialSubTriggerName="8WUHSE";
1013                         break;
1014                 case 5: // 7WUHJE - V0AND with jet in TRD
1015                         fSpecialSubTrigger=1; 
1016                         fNSpecialSubTriggerOptions=1;
1017                         fSpecialSubTriggerName="7WUHJT";
1018                         break;
1019                 case 6: // 8WUHJE - T0AND with jet in TRD
1020                         fSpecialSubTrigger=1; 
1021                         fNSpecialSubTriggerOptions=1;
1022                         fSpecialSubTriggerName="8WUHJT";
1023                         break;
1024                 case 7: // 7WUHQU - V0AND with dielectron pair in TRD
1025                         fSpecialSubTrigger=1; 
1026                         fNSpecialSubTriggerOptions=1;
1027                         fSpecialSubTriggerName="7WUHQU";
1028                         break;
1029                 case 8: // 8WUHQU - T0AND with dielectron pair in TRD
1030                         fSpecialSubTrigger=1; 
1031                         fNSpecialSubTriggerOptions=1;
1032                         fSpecialSubTriggerName="8WUHQU";
1033                         break;
1034                 default:
1035                         AliError("Warning: Special Subtrigger Class Not known");
1036                         return 0;
1037                 }                  
1038         } else if (fSpecialTrigger == 5){ // Subdivision of kEMC trigger classes
1039                 switch(selectSpecialSubTriggerClass){
1040                 case 0: // all together
1041                         fSpecialSubTrigger=0; 
1042                         fSpecialSubTriggerName="";
1043 //                      AliInfo("Info: Nothing to be done");
1044                         break;
1045                 case 1: // CEMC1 - V0OR and EMCAL fired
1046                         fOfflineTriggerMask=AliVEvent::kEMC1;
1047                         fSpecialTriggerName="AliVEvent::kEMC1";
1048                         fSpecialSubTrigger=1; 
1049                         fNSpecialSubTriggerOptions=1;
1050                         fSpecialSubTriggerName="CEMC1";
1051                         break;
1052                 case 2: // CEMC7 - V0AND and EMCAL fired 
1053                         fSpecialSubTrigger=1; 
1054                         fOfflineTriggerMask=AliVEvent::kEMC7;
1055                         fSpecialTriggerName="AliVEvent::kEMC7";
1056                         fNSpecialSubTriggerOptions=1;
1057                         fSpecialSubTriggerName="CEMC7";
1058                         break;
1059                 case 3: // CEMC8  - T0OR and EMCAL fired
1060                         fOfflineTriggerMask=AliVEvent::kEMC8;
1061                         fSpecialTriggerName="AliVEvent::kEMC8";
1062                         fSpecialSubTrigger=1; 
1063                         fNSpecialSubTriggerOptions=1;
1064                         fSpecialSubTriggerName="CEMC8";
1065                         break;
1066                 default:
1067                         AliError("Warning: Special Subtrigger Class Not known");
1068                         return 0;
1069                 }                  
1070         }  else if (fSpecialTrigger == 6){ // Subdivision of kPHI trigger classes
1071                 switch(selectSpecialSubTriggerClass){
1072                 case 0: // all together
1073                         fSpecialSubTrigger=0; 
1074                         fSpecialSubTriggerName="";
1075 //                      AliInfo("Info: Nothing to be done");
1076                         break;
1077                 case 1: // CEMC1 - V0OR and EMCAL fired
1078                         fOfflineTriggerMask=AliVEvent::kPHI1;
1079                         fSpecialTriggerName="AliVEvent::kPHI1";
1080                         fSpecialSubTrigger=1; 
1081                         fNSpecialSubTriggerOptions=1;
1082                         fSpecialSubTriggerName="CPHI1";
1083                         break;
1084                 case 2: // CEMC7 - V0AND and EMCAL fired 
1085                         fSpecialSubTrigger=1; 
1086                         fOfflineTriggerMask=AliVEvent::kPHI7;
1087                         fSpecialTriggerName="AliVEvent::kPHI7";
1088                         fNSpecialSubTriggerOptions=1;
1089                         fSpecialSubTriggerName="CPHI7";
1090                         break;
1091                 case 3: // CEMC8  - T0OR and EMCAL fired
1092                         fOfflineTriggerMask=AliVEvent::kPHI8;
1093                         fSpecialTriggerName="AliVEvent::kPHI8";
1094                         fSpecialSubTrigger=1; 
1095                         fNSpecialSubTriggerOptions=1;
1096                         fSpecialSubTriggerName="CPHI8";
1097                         break;
1098                 default:
1099                         AliError("Warning: Special Subtrigger Class Not known");
1100                         return 0;
1101                 }                  
1102         } else if (fSpecialTrigger == 7){ // Subdivision of kHighMult trigger classes
1103                 switch(selectSpecialSubTriggerClass){
1104                 case 0: // all together
1105                         fSpecialSubTrigger=0; 
1106                         fSpecialSubTriggerName="";
1107 //                      AliInfo("Info: Nothing to be done");
1108                         break;
1109                 case 1: // CSHM1 - V0OR and high mult fired
1110                         fSpecialSubTrigger=1; 
1111                         fNSpecialSubTriggerOptions=1;
1112                         fSpecialSubTriggerName="CSHM1";
1113                         break;
1114                 case 2: // CSHM7 - V0AND and high mult fired 
1115                         fSpecialSubTrigger=1; 
1116                         fNSpecialSubTriggerOptions=1;
1117                         fSpecialSubTriggerName="CSHM7";
1118                         break;
1119                 case 3: // CSHM8  - T0OR and high mult fired
1120                         fSpecialSubTrigger=1; 
1121                         fNSpecialSubTriggerOptions=1;
1122                         fSpecialSubTriggerName="CSHM8";
1123                         break;
1124                 default:
1125                         AliError("Warning: Special Subtrigger Class Not known");
1126                         return 0;
1127                 }                  
1128         }  else if (fSpecialTrigger == 8){ // Subdivision of kEMCEGA trigger classes
1129                 switch(selectSpecialSubTriggerClass){
1130                 case 0: // all together
1131                         fSpecialSubTrigger=0; 
1132                         fSpecialSubTriggerName="";
1133 //                      AliInfo("Info: Nothing to be done");
1134                         break;
1135                 case 1: // 7EGA - CINT7 EGA
1136                         fSpecialSubTrigger=1; 
1137                         fNSpecialSubTriggerOptions=1;
1138                         fSpecialSubTriggerName="7EGA";
1139                         fTriggersEMCALSelected= 0;
1140                         SETBIT(fTriggersEMCALSelected, kG2);
1141                         break;
1142                 case 2: // 8EGA - CINT8 EGA
1143                         fSpecialSubTrigger=1; 
1144                         fNSpecialSubTriggerOptions=1;
1145                         fSpecialSubTriggerName="8EGA";
1146                         fTriggersEMCALSelected= 0;
1147                         SETBIT(fTriggersEMCALSelected, kG2);
1148                         break;
1149                 case 3: // 7EG1 - CINT7 EG1
1150                         fSpecialSubTrigger=1; 
1151                         fNSpecialSubTriggerOptions=1;
1152                         fSpecialSubTriggerName="7EG1";
1153                         fTriggersEMCALSelected= 0;
1154                         SETBIT(fTriggersEMCALSelected, kG1);
1155                         break;
1156                 case 4: // 8EG1 - CINT8 EG1
1157                         fSpecialSubTrigger=1; 
1158                         fNSpecialSubTriggerOptions=1;
1159                         fSpecialSubTriggerName="8EG1";
1160                         fTriggersEMCALSelected= 0;
1161                         SETBIT(fTriggersEMCALSelected, kG1);
1162                         break;
1163                 case 5: // 7EG2 - CINT7 EG2
1164                         fSpecialSubTrigger=1; 
1165                         fNSpecialSubTriggerOptions=1;
1166                         fSpecialSubTriggerName="7EG2";
1167                         fTriggersEMCALSelected= 0;
1168                         SETBIT(fTriggersEMCALSelected, kG2);
1169                         break;
1170                 case 6: // 8EG2 - CINT8 EG2
1171                         fSpecialSubTrigger=1; 
1172                         fNSpecialSubTriggerOptions=1;
1173                         fSpecialSubTriggerName="8EG2";
1174                         fTriggersEMCALSelected= 0;
1175                         SETBIT(fTriggersEMCALSelected, kG2);
1176                         break;
1177                 default:
1178                         AliError("Warning: Special Subtrigger Class Not known");
1179                         return 0;
1180                 }                  
1181         } else if (fSpecialTrigger == 9){ // Subdivision of kEMCEGA trigger classes
1182                 switch(selectSpecialSubTriggerClass){
1183                 case 0: // all together
1184                         fSpecialSubTrigger=0; 
1185                         fSpecialSubTriggerName="";
1186 //                      AliInfo("Info: Nothing to be done");
1187                         break;
1188                 case 1: // 7EJE - CINT7 EJE
1189                         fSpecialSubTrigger=1; 
1190                         fNSpecialSubTriggerOptions=1;
1191                         fSpecialSubTriggerName="7EJE";
1192                         fTriggersEMCALSelected= 0;
1193                         SETBIT(fTriggersEMCALSelected, kJ2);
1194                         break;
1195                 case 2: // 8EJE - CINT8 EJE
1196                         fSpecialSubTrigger=1; 
1197                         fNSpecialSubTriggerOptions=1;
1198                         fSpecialSubTriggerName="8EJE";
1199                         fTriggersEMCALSelected= 0;
1200                         SETBIT(fTriggersEMCALSelected, kJ2);
1201                         break;
1202                 case 3: // 7EJ1 - CINT7 EJ1
1203                         fSpecialSubTrigger=1; 
1204                         fNSpecialSubTriggerOptions=1;
1205                         fSpecialSubTriggerName="7EJ1";
1206                         fTriggersEMCALSelected= 0;
1207                         SETBIT(fTriggersEMCALSelected, kJ1);
1208                         break;
1209                 case 4: // 8EJ1 - CINT8 EJ1
1210                         fSpecialSubTrigger=1; 
1211                         fNSpecialSubTriggerOptions=1;
1212                         fSpecialSubTriggerName="8EJ1";
1213                         fTriggersEMCALSelected= 0;
1214                         SETBIT(fTriggersEMCALSelected, kJ1);
1215                         break;
1216                 case 5: // 7EJ2 - CINT7 EJ2
1217                         fSpecialSubTrigger=1; 
1218                         fNSpecialSubTriggerOptions=1;
1219                         fSpecialSubTriggerName="7EJ2";
1220                         fTriggersEMCALSelected= 0;
1221                         SETBIT(fTriggersEMCALSelected, kJ2);
1222                         break;
1223                 case 6: // 8EJ2 - CINT8 EJ2
1224                         fSpecialSubTrigger=1; 
1225                         fNSpecialSubTriggerOptions=1;
1226                         fSpecialSubTriggerName="8EJ2";
1227                         fTriggersEMCALSelected= 0;
1228                         SETBIT(fTriggersEMCALSelected, kJ2);
1229                         break;
1230                 default:
1231                         AliError("Warning: Special Subtrigger Class Not known");
1232                         return 0;
1233                 }                  
1234         }
1235         return 1;
1236 }
1237
1238 ///________________________________________________________________________
1239 Bool_t AliConvEventCuts::SetMultiplicityMethod(Int_t multiplicityMethod)
1240 {
1241         // Set Cut
1242         fMultiplicityMethod=multiplicityMethod;
1243
1244         // 0 Photon Multiplicity
1245         // 1 TPC Track multiplicity
1246         // 2 V0 Mult
1247         // 3 SPD Mult
1248
1249         return kTRUE;
1250 }
1251
1252 ///________________________________________________________________________
1253 Bool_t AliConvEventCuts::SetRemovePileUp(Int_t removePileUp)
1254 {// Set Cut
1255         switch(removePileUp){
1256         case 0:
1257                 fRemovePileUp=kFALSE;
1258                 break;
1259         case 1:
1260                 fRemovePileUp=kTRUE;
1261                 break;
1262         default:
1263                 AliError("RemovePileUpCut not defined");
1264                 return kFALSE;
1265         }
1266         return kTRUE;
1267 }
1268
1269 ///________________________________________________________________________
1270 Bool_t AliConvEventCuts::SetRejectExtraSignalsCut(Int_t extraSignal) {
1271
1272         switch(extraSignal){
1273         case 0:
1274                 fRejectExtraSignals = 0;
1275                 break; // No Rejection
1276         case 1:
1277                 fRejectExtraSignals = 1;
1278                 break; // MinBias Header
1279         case 2:
1280                 fRejectExtraSignals = 2;
1281                 break; // User String Array
1282         case 3:
1283                 fRejectExtraSignals = 3;
1284                 break; // Rejection for Gamma Correction only
1285         default:
1286                 AliError(Form("Extra Signal Rejection not defined %d",extraSignal));
1287                 return kFALSE;
1288         }
1289         return kTRUE;
1290 }
1291
1292 //-------------------------------------------------------------
1293 Double_t AliConvEventCuts::GetCentrality(AliVEvent *event)
1294 {   // Get Event Centrality
1295
1296         AliESDEvent *esdEvent=dynamic_cast<AliESDEvent*>(event);
1297         if(esdEvent){
1298                 AliCentrality *fESDCentrality=(AliCentrality*)esdEvent->GetCentrality();
1299                 if(fDetectorCentrality==0){
1300                         if (fIsHeavyIon==2){
1301                                 return fESDCentrality->GetCentralityPercentile("V0A"); // default for pPb
1302                         } else{
1303                                 return fESDCentrality->GetCentralityPercentile("V0M"); // default
1304                         }
1305                 }
1306                 if(fDetectorCentrality==1){
1307                         return fESDCentrality->GetCentralityPercentile("CL1");
1308                 }
1309         }
1310
1311         AliAODEvent *aodEvent=dynamic_cast<AliAODEvent*>(event);
1312         if(aodEvent){
1313                 if(aodEvent->GetHeader()){return aodEvent->GetHeader()->GetCentrality();}
1314         }
1315
1316         return -1;
1317 }
1318
1319 //_____________________________________________________________________________________
1320 Bool_t AliConvEventCuts::IsCentralitySelected(AliVEvent *event, AliVEvent *fMCEvent)
1321 {   // Centrality Selection
1322         if(!fIsHeavyIon)return kTRUE;
1323
1324         if(fCentralityMin == fCentralityMax ) return kTRUE;//0-100%
1325         else if(fCentralityMax==0) fCentralityMax=10; //CentralityRange = fCentralityMin-100%
1326
1327         Double_t centrality=GetCentrality(event);
1328         if(centrality<0)return kFALSE;
1329
1330         Int_t centralityC=0;
1331         if (fModCentralityClass == 0){
1332                 centralityC= Int_t(centrality/10);
1333                 if(centralityC >= fCentralityMin && centralityC < fCentralityMax)
1334                         return kTRUE;
1335                 else return kFALSE;
1336         }
1337         else if (fModCentralityClass ==1){
1338                 centralityC= Int_t(centrality);
1339                 if(centralityC >= fCentralityMin*5 && centralityC < fCentralityMax*5){
1340                         return kTRUE;
1341                 } else return kFALSE;
1342         }
1343         else if (fModCentralityClass ==2){
1344                 centralityC= Int_t(centrality);
1345                 if(centralityC >= ((fCentralityMin*5)+45) && centralityC < ((fCentralityMax*5)+45))
1346                         return kTRUE;
1347                 else return kFALSE;
1348         }
1349
1350         Int_t nprimaryTracks = ((AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask(fV0ReaderName.Data()))->GetNumberOfPrimaryTracks();
1351         Int_t PrimaryTracks10[10][2] =
1352                 {
1353                         {9999,9999}, //  0
1354                         {1210, 928}, // 10
1355                         { 817, 658}, // 20
1356                         { 536, 435}, // 30
1357                         { 337, 276}, // 40
1358                         { 197, 162}, // 50
1359                         { 106, 100}, // 60
1360                         {  51,  44}, // 70
1361                         {  21,  18}, // 80
1362                         {   0,   0}  // 90
1363                 };
1364         Int_t PrimaryTracks5a[10][2] =
1365                 {
1366                         {9999,9999}, // 0
1367                         {1485,1168}, // 5
1368                         {1210, 928}, // 10
1369                         { 995, 795}, // 15
1370                         { 817, 658}, // 20
1371                         { 666, 538}, // 25
1372                         { 536, 435}, // 30
1373                         { 428, 350}, // 35
1374                         { 337, 276}, // 40
1375                         { 260, 214}  // 45
1376                 };
1377         Int_t PrimaryTracks5b[10][2] =
1378                 {
1379                         { 260, 214}, // 45
1380                         { 197, 162}, // 50
1381                         { 147, 125}, // 55
1382                         { 106, 100}, // 60
1383                         {  75,  63}, // 65
1384                         {  51,  44}, // 70
1385                         {  34,  29}, // 75
1386                         {  21,  18}, // 80
1387                         {  13,  11}, // 85
1388                         {   0,   0}  // 90
1389                 };
1390         Int_t column = 0;
1391         if(event->IsA()==AliESDEvent::Class()) column = 0;
1392         if(event->IsA()==AliAODEvent::Class()) column = 1;
1393
1394         if (fModCentralityClass == 3){
1395                 if(fMCEvent){
1396                         if(nprimaryTracks > PrimaryTracks10[fCentralityMax][column] && nprimaryTracks <= PrimaryTracks10[fCentralityMin][column])
1397                                 return kTRUE;
1398                         else return kFALSE;
1399                 }
1400                 else{
1401                         centralityC= Int_t(centrality/10);
1402                         if(centralityC >= fCentralityMin && centralityC < fCentralityMax)
1403                                 return kTRUE;
1404                         else return kFALSE;
1405                 }
1406         }
1407         else if (fModCentralityClass ==4){
1408                 if(fMCEvent){
1409                         if(nprimaryTracks > PrimaryTracks5a[fCentralityMax][column] && nprimaryTracks <= PrimaryTracks5a[fCentralityMin][column])
1410                                 return kTRUE;
1411                         else return kFALSE;
1412                 }
1413                 else{
1414                         centralityC= Int_t(centrality);
1415                         if(centralityC >= fCentralityMin*5 && centralityC < fCentralityMax*5){
1416                                 return kTRUE;
1417                         } else return kFALSE;
1418                 }
1419         }
1420         else if (fModCentralityClass ==5){
1421                 if(fMCEvent){
1422                         if(nprimaryTracks > PrimaryTracks5b[fCentralityMax][column] && nprimaryTracks <= PrimaryTracks5b[fCentralityMin][column])
1423                                 return kTRUE;
1424                         else return kFALSE;
1425                 }
1426                 else{
1427                         centralityC= Int_t(centrality);
1428                         if(centralityC >= ((fCentralityMin*5)+45) && centralityC < ((fCentralityMax*5)+45))
1429                                 return kTRUE;
1430                         else return kFALSE;
1431                 }
1432         }
1433
1434         return kFALSE;
1435 }
1436
1437 ///________________________________________________________________________
1438 Bool_t AliConvEventCuts::VertexZCut(AliVEvent *event){
1439         // Cut on z position of primary vertex
1440         Double_t fVertexZ=event->GetPrimaryVertex()->GetZ();
1441         Double_t fVertexZSPD = 0;
1442         AliESDEvent *fESDEvent=dynamic_cast<AliESDEvent*>(event);
1443         if(fESDEvent){
1444                 fVertexZSPD = fESDEvent->GetPrimaryVertexSPD()->GetZ();
1445         } 
1446         AliAODEvent *fAODEvent=dynamic_cast<AliAODEvent*>(event);
1447         if(fAODEvent){
1448                 fVertexZSPD = fAODEvent->GetPrimaryVertexSPD()->GetZ();
1449         }
1450         
1451         if(abs(fVertexZ)>fMaxVertexZ)return kFALSE;
1452
1453         TString periodName = ((AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()
1454                                                                                                         ->GetTask(fV0ReaderName.Data()))->GetPeriodName();
1455         if (periodName.CompareTo("LHC11h")==0){
1456                 if (abs(fVertexZ-fVertexZSPD) > 0.1) return kFALSE;
1457         }                                               
1458         if (fIsHeavyIon == 2){
1459                 if(fUtils->IsFirstEventInChunk(event)) return kFALSE;
1460                 if(!fUtils->IsVertexSelected2013pA(event)) return kFALSE;
1461                 if(fUtils->IsPileUpEvent(event)) return kFALSE;
1462         }
1463
1464         return kTRUE;
1465 }
1466
1467 ///________________________________________________________________________
1468 Int_t AliConvEventCuts::GetNumberOfContributorsVtx(AliVEvent *event){
1469         // returns number of contributors to the vertex
1470
1471         AliESDEvent *fESDEvent=dynamic_cast<AliESDEvent*>(event);
1472         if(fESDEvent){
1473                 if (fESDEvent->GetPrimaryVertex() != NULL){
1474                         if(fESDEvent->GetPrimaryVertex()->GetNContributors()>0) {
1475         //     cout << "accepted global" << fESDEvent->GetEventNumberInFile() << " with NCont: " << fESDEvent->GetPrimaryVertex()->GetNContributors() << endl;
1476                                 return fESDEvent->GetPrimaryVertex()->GetNContributors();
1477                         }
1478                 }
1479
1480                 if(fESDEvent->GetPrimaryVertexSPD() !=NULL){
1481                         if(fESDEvent->GetPrimaryVertexSPD()->GetNContributors()>0) {
1482         //     cout << "accepted SPD" << fESDEvent->GetEventNumberInFile() << " with NCont: " << fESDEvent->GetPrimaryVertexSPD()->GetNContributors() << endl;
1483                                 return fESDEvent->GetPrimaryVertexSPD()->GetNContributors();
1484                         }  else {
1485                                 AliWarning(Form("Number of contributors from bad vertex type:: %s",fESDEvent->GetPrimaryVertex()->GetName()));
1486         //            cout << "rejected " << fESDEvent->GetEventNumberInFile() << endl;
1487                                 return 0;
1488                         }
1489                 }
1490         }
1491
1492         AliAODEvent *fAODEvent=dynamic_cast<AliAODEvent*>(event);
1493         if(fAODEvent){
1494                 if (fAODEvent->GetPrimaryVertex() != NULL){
1495                         if(fAODEvent->GetPrimaryVertex()->GetNContributors()>0) {
1496                                 return fAODEvent->GetPrimaryVertex()->GetNContributors();
1497                         }
1498                 }
1499                 if(fAODEvent->GetPrimaryVertexSPD() !=NULL){
1500                         if(fAODEvent->GetPrimaryVertexSPD()->GetNContributors()>0) {
1501                                 return fAODEvent->GetPrimaryVertexSPD()->GetNContributors();
1502                         } else {
1503                                 AliWarning(Form("Number of contributors from bad vertex type:: %s",fAODEvent->GetPrimaryVertex()->GetName()));
1504                                 return 0;
1505                         }
1506                 }
1507         }
1508         // cout << "rejected " << fESDEvent->GetEventNumberInFile() << endl;
1509         return 0;
1510 }
1511
1512
1513 ///________________________________________________________________________
1514 Bool_t AliConvEventCuts::IsTriggerSelected(AliVEvent *fInputEvent, Bool_t isMC)
1515 {
1516
1517         AliInputEventHandler *fInputHandler=(AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
1518
1519         
1520         UInt_t isSelected = AliVEvent::kAny;
1521         TString periodName = ((AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask(fV0ReaderName.Data()))->GetPeriodName();
1522         //    cout <<   periodName.Data() << endl;
1523         
1524         if (fInputHandler==NULL) return kFALSE;
1525         if( fInputHandler->GetEventSelection() || fInputEvent->IsA()==AliAODEvent::Class()) {
1526         
1527                 TString firedTrigClass = fInputEvent->GetFiredTriggerClasses();  
1528                 if (!fTriggerSelectedManually){
1529                         if (fPreSelCut) fOfflineTriggerMask = AliVEvent::kAny;
1530                         else {
1531                                 if (fIsHeavyIon == 1) fOfflineTriggerMask = AliVEvent::kMB | AliVEvent::kCentral | AliVEvent::kSemiCentral;
1532                                 else if (fIsHeavyIon == 2) fOfflineTriggerMask = AliVEvent::kINT7;
1533                                 else if (periodName.CompareTo("LHC11c") == 0 || periodName.CompareTo("LHC11d") == 0 || periodName.CompareTo("LHC11e") == 0 || periodName.CompareTo("LHC11f") == 0 || periodName.CompareTo("LHC11g") == 0  || periodName.CompareTo("LHC12a") == 0 || periodName.CompareTo("LHC12b") == 0 || periodName.CompareTo("LHC12c") == 0 || periodName.CompareTo("LHC12d") == 0 || periodName.CompareTo("LHC12f") == 0  || periodName.CompareTo("LHC12g") == 0  || periodName.CompareTo("LHC12h") == 0  || periodName.CompareTo("LHC12i") == 0  ||periodName.CompareTo("LHC13g") == 0 ) {
1534                                         fOfflineTriggerMask = AliVEvent::kINT7;      
1535         //                              cout << "will take kINT7 as trigger mask" << endl; 
1536                                 }       
1537                                 else fOfflineTriggerMask = AliVEvent::kMB;
1538                         }
1539                 }
1540                 // Get the actual offline trigger mask for the event and AND it with the
1541                 // requested mask. If no mask requested select by default the event.
1542         //       if (fPreSelCut) cout << "Trigger selected from outside: "<< fTriggerSelectedManually <<"\t Offline Trigger mask for Precut: " << fOfflineTriggerMask << endl;
1543         //       else cout << "Trigger selected from outside: "<< fTriggerSelectedManually <<"\t Offline Trigger mask: " << fOfflineTriggerMask << endl;
1544
1545                 if (isMC) fOfflineTriggerMask = AliVEvent::kAny;
1546         
1547                 if (fOfflineTriggerMask){
1548                         isSelected = fOfflineTriggerMask & fInputHandler->IsEventSelected();             
1549                         
1550                         if (isSelected && !fPreSelCut){
1551 //                              cout << "Special trigger: "<< fSpecialTrigger << " initialized " << fEMCALTrigInitialized << endl;
1552                                 if (fSpecialTrigger == 5 || fSpecialTrigger == 8 || fSpecialTrigger == 9){ // EMCAL triggers
1553                                         if (!fEMCALTrigInitialized ) InitializeEMCALTrigger(fInputEvent);
1554                                         fTriggersEMCAL= GetTriggerList();       
1555                                 }
1556                                 if (fSpecialSubTrigger>0 && !isMC){
1557                                         if (!firedTrigClass.Contains(fSpecialSubTriggerName.Data())) isSelected = 0;
1558                                 } else if (isMC){
1559                                         if (fSpecialTrigger == 5 || fSpecialTrigger == 8 || fSpecialTrigger == 9){ // EMCAL triggers
1560                                                 isSelected = 0;
1561 //                                              if (fTriggersEMCAL > 0)cout << "Special Trigger " << fSpecialTrigger << " triggers: " << fTriggersEMCAL << "    selected triggers: " << fTriggersEMCALSelected << " run number: " <<fInputEvent->GetRunNumber()<<endl;
1562                                                 if (fTriggersEMCAL&fTriggersEMCALSelected){
1563 //                                                      cout << "accepted ++++++++++++++++++++" << endl;
1564                                                         isSelected = 1;
1565                                                 }       
1566                                         }       
1567                                 }
1568                                 //if for specif centrality trigger selection 
1569                                 if(fSpecialSubTrigger == 1){
1570                                         if(fSpecialSubTriggerName.Contains("|")){
1571                                                 TObjArray *ClassesList = fSpecialSubTriggerName.Tokenize("|");
1572                                                 for (Int_t i=0; i<ClassesList->GetEntriesFast();++i){
1573                                                         TObjString *NameClass = (TObjString*)ClassesList->At(i);
1574                                                         if (firedTrigClass.Contains(NameClass->GetString())) isSelected = 1;
1575 //                                                      cout << "|||||||| \t" << NameClass->GetString() << "\t ||||||||" << endl;
1576                                                 }
1577                                         } else if(fSpecialSubTriggerName.Contains("%")){
1578                                                 TObjArray *ClassesList = fSpecialSubTriggerName.Tokenize("%");
1579                                                 for (Int_t i=0; i<ClassesList->GetEntriesFast();++i){
1580                                                         TObjString *NameClass = (TObjString*)ClassesList->At(i);
1581                                                         if (firedTrigClass.Contains(NameClass->GetString())) isSelected = 1;
1582 //                                                      cout << "|||||||| \t" << NameClass->GetString() << "\t ||||||||" << endl;
1583                                                 }       
1584                                         } else if(fSpecialSubTriggerName.Contains("&")){
1585                                                 TObjArray *ClassesList = fSpecialSubTriggerName.Tokenize("&");
1586                                                 TString CheckClass = "";
1587                                                 for (Int_t i=0; i<ClassesList->GetEntriesFast(); i++){
1588                                                         TObjString *NameClass = (TObjString*)ClassesList->At(i);
1589                                                         if (firedTrigClass.Contains(NameClass->GetString())) CheckClass+="1";
1590                                                         else CheckClass+="0";
1591                                                 }
1592                                                 if(CheckClass.Contains("0")) isSelected = 0;
1593 //                                              cout << "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&" << endl;
1594                                         }       
1595                                         else if(firedTrigClass.Contains(fSpecialSubTriggerName.Data())) isSelected = 1;
1596                                 }
1597                         }                               
1598                 }        
1599         }
1600         fIsSDDFired = !(fInputHandler->IsEventSelected() & AliVEvent::kFastOnly);
1601
1602         // Fill Histogram
1603         if(hTriggerClass){
1604                 if (fIsSDDFired) hTriggerClass->Fill(33);
1605                 if (fInputHandler->IsEventSelected() & AliVEvent::kMB)hTriggerClass->Fill(0);
1606                 if (fInputHandler->IsEventSelected() & AliVEvent::kINT7)hTriggerClass->Fill(1);
1607                 if (fInputHandler->IsEventSelected() & AliVEvent::kMUON)hTriggerClass->Fill(2);
1608                 if (fInputHandler->IsEventSelected() & AliVEvent::kHighMult)hTriggerClass->Fill(3);
1609                 if (fInputHandler->IsEventSelected() & AliVEvent::kEMC1)hTriggerClass->Fill(4);
1610                 if (fInputHandler->IsEventSelected() & AliVEvent::kCINT5)hTriggerClass->Fill(5);
1611                 if (fInputHandler->IsEventSelected() & AliVEvent::kCMUS5)hTriggerClass->Fill(6);
1612         //       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSPB)hTriggerClass->Fill(6);
1613                 if (fInputHandler->IsEventSelected() & AliVEvent::kMUSH7)hTriggerClass->Fill(7);
1614         //       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSHPB)hTriggerClass->Fill(7);
1615                 if (fInputHandler->IsEventSelected() & AliVEvent::kMUL7)hTriggerClass->Fill(8);
1616         //       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonLikePB)hTriggerClass->Fill(8);
1617                 if (fInputHandler->IsEventSelected() & AliVEvent::kMUU7)hTriggerClass->Fill(9);
1618         //       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikePB)hTriggerClass->Fill(9);
1619                 if (fInputHandler->IsEventSelected() & AliVEvent::kEMC7)hTriggerClass->Fill(10);
1620         //       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC8)hTriggerClass->Fill(10);
1621                 if (fInputHandler->IsEventSelected() & AliVEvent::kMUS7)hTriggerClass->Fill(11);
1622                 if (fInputHandler->IsEventSelected() & AliVEvent::kPHI1)hTriggerClass->Fill(12);
1623                 if (fInputHandler->IsEventSelected() & AliVEvent::kPHI7)hTriggerClass->Fill(13);
1624         //       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI8)hTriggerClass->Fill(13);
1625         //       if (fInputHandler->IsEventSelected() & AliVEvent::kPHOSPb)hTriggerClass->Fill(13);
1626                 if (fInputHandler->IsEventSelected() & AliVEvent::kEMCEJE)hTriggerClass->Fill(14);
1627                 if (fInputHandler->IsEventSelected() & AliVEvent::kEMCEGA)hTriggerClass->Fill(15);
1628                 if (fInputHandler->IsEventSelected() & AliVEvent::kCentral)hTriggerClass->Fill(16);
1629                 if (fInputHandler->IsEventSelected() & AliVEvent::kSemiCentral)hTriggerClass->Fill(17);
1630                 if (fInputHandler->IsEventSelected() & AliVEvent::kDG5)hTriggerClass->Fill(18);
1631                 if (fInputHandler->IsEventSelected() & AliVEvent::kZED)hTriggerClass->Fill(19);
1632                 if (fInputHandler->IsEventSelected() & AliVEvent::kSPI7)hTriggerClass->Fill(20);
1633         //       if (fInputHandler->IsEventSelected() & AliVEvent::kSPI)hTriggerClass->Fill(20);
1634                 if (fInputHandler->IsEventSelected() & AliVEvent::kINT8)hTriggerClass->Fill(21);
1635                 if (fInputHandler->IsEventSelected() & AliVEvent::kMuonSingleLowPt8)hTriggerClass->Fill(22);
1636                 if (fInputHandler->IsEventSelected() & AliVEvent::kMuonSingleHighPt8)hTriggerClass->Fill(23);
1637                 if (fInputHandler->IsEventSelected() & AliVEvent::kMuonLikeLowPt8)hTriggerClass->Fill(24);
1638                 if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikeLowPt8)hTriggerClass->Fill(25);
1639                 if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikeLowPt0)hTriggerClass->Fill(26);
1640                 if (fInputHandler->IsEventSelected() & AliVEvent::kUserDefined)hTriggerClass->Fill(27);
1641                 if (fInputHandler->IsEventSelected() & AliVEvent::kTRD)hTriggerClass->Fill(28);
1642                 if (fInputHandler->IsEventSelected() & AliVEvent::kFastOnly)hTriggerClass->Fill(29);
1643                 if (fInputHandler->IsEventSelected() & AliVEvent::kAnyINT)hTriggerClass->Fill(30);
1644                 if (fInputHandler->IsEventSelected() & AliVEvent::kAny)hTriggerClass->Fill(31);
1645                 if (!fInputHandler->IsEventSelected()) hTriggerClass->Fill(34);
1646         }
1647
1648         if(hTriggerClassSelected && isSelected){
1649                 if (!fIsSDDFired) hTriggerClassSelected->Fill(33);
1650                 if (fInputHandler->IsEventSelected() & AliVEvent::kMB)hTriggerClassSelected->Fill(0);
1651                 if (fInputHandler->IsEventSelected() & AliVEvent::kINT7)hTriggerClassSelected->Fill(1);
1652                 if (fInputHandler->IsEventSelected() & AliVEvent::kMUON)hTriggerClassSelected->Fill(2);
1653                 if (fInputHandler->IsEventSelected() & AliVEvent::kHighMult)hTriggerClassSelected->Fill(3);
1654                 if (fInputHandler->IsEventSelected() & AliVEvent::kEMC1)hTriggerClassSelected->Fill(4);
1655                 if (fInputHandler->IsEventSelected() & AliVEvent::kCINT5)hTriggerClassSelected->Fill(5);
1656                 if (fInputHandler->IsEventSelected() & AliVEvent::kCMUS5)hTriggerClassSelected->Fill(6);
1657         //       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSPB)hTriggerClassSelected->Fill(6);
1658                 if (fInputHandler->IsEventSelected() & AliVEvent::kMUSH7)hTriggerClassSelected->Fill(7);
1659         //       if (fInputHandler->IsEventSelected() & AliVEvent::kMUSHPB)hTriggerClassSelected->Fill(7);
1660                 if (fInputHandler->IsEventSelected() & AliVEvent::kMUL7)hTriggerClassSelected->Fill(8);
1661         //       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonLikePB)hTriggerClassSelected->Fill(8);
1662                 if (fInputHandler->IsEventSelected() & AliVEvent::kMUU7)hTriggerClassSelected->Fill(9);
1663         //       if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikePB)hTriggerClassSelected->Fill(9);
1664                 if (fInputHandler->IsEventSelected() & AliVEvent::kEMC7)hTriggerClassSelected->Fill(10);
1665         //       if (fInputHandler->IsEventSelected() & AliVEvent::kEMC8)hTriggerClassSelected->Fill(10);
1666                 if (fInputHandler->IsEventSelected() & AliVEvent::kMUS7)hTriggerClassSelected->Fill(11);
1667                 if (fInputHandler->IsEventSelected() & AliVEvent::kPHI1)hTriggerClassSelected->Fill(12);
1668                 if (fInputHandler->IsEventSelected() & AliVEvent::kPHI7)hTriggerClassSelected->Fill(13);
1669         //       if (fInputHandler->IsEventSelected() & AliVEvent::kPHI8)hTriggerClassSelected->Fill(13);
1670         //       if (fInputHandler->IsEventSelected() & AliVEvent::kPHOSPb)hTriggerClassSelected->Fill(13);
1671                 if (fInputHandler->IsEventSelected() & AliVEvent::kEMCEJE)hTriggerClassSelected->Fill(14);
1672                 if (fInputHandler->IsEventSelected() & AliVEvent::kEMCEGA)hTriggerClassSelected->Fill(15);
1673                 if (fInputHandler->IsEventSelected() & AliVEvent::kCentral)hTriggerClassSelected->Fill(16);
1674                 if (fInputHandler->IsEventSelected() & AliVEvent::kSemiCentral)hTriggerClassSelected->Fill(17);
1675                 if (fInputHandler->IsEventSelected() & AliVEvent::kDG5)hTriggerClassSelected->Fill(18);
1676                 if (fInputHandler->IsEventSelected() & AliVEvent::kZED)hTriggerClassSelected->Fill(19);
1677                 if (fInputHandler->IsEventSelected() & AliVEvent::kSPI7)hTriggerClassSelected->Fill(20);
1678         //       if (fInputHandler->IsEventSelected() & AliVEvent::kSPI)hTriggerClassSelected->Fill(20);
1679                 if (fInputHandler->IsEventSelected() & AliVEvent::kINT8)hTriggerClassSelected->Fill(21);
1680                 if (fInputHandler->IsEventSelected() & AliVEvent::kMuonSingleLowPt8)hTriggerClassSelected->Fill(22);
1681                 if (fInputHandler->IsEventSelected() & AliVEvent::kMuonSingleHighPt8)hTriggerClassSelected->Fill(23);
1682                 if (fInputHandler->IsEventSelected() & AliVEvent::kMuonLikeLowPt8)hTriggerClassSelected->Fill(24);
1683                 if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikeLowPt8)hTriggerClassSelected->Fill(25);
1684                 if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikeLowPt0)hTriggerClassSelected->Fill(26);
1685                 if (fInputHandler->IsEventSelected() & AliVEvent::kUserDefined)hTriggerClassSelected->Fill(27);
1686                 if (fInputHandler->IsEventSelected() & AliVEvent::kTRD)hTriggerClassSelected->Fill(28);
1687                 if (fInputHandler->IsEventSelected() & AliVEvent::kFastOnly)hTriggerClassSelected->Fill(29);
1688                 if (fInputHandler->IsEventSelected() & AliVEvent::kAnyINT)hTriggerClassSelected->Fill(30);
1689                 if (fInputHandler->IsEventSelected() & AliVEvent::kAny)hTriggerClassSelected->Fill(31);
1690         }
1691
1692         if(!isSelected)return kFALSE;
1693         return kTRUE;
1694
1695 }
1696
1697 ///________________________________________________________________________
1698 TString AliConvEventCuts::GetCutNumber(){
1699    // returns TString with current cut number
1700    TString a(kNCuts);
1701    for(Int_t ii=0;ii<kNCuts;ii++){
1702       a.Append(Form("%d",fCuts[ii]));
1703    }
1704    return a;
1705 }
1706
1707 ///________________________________________________________________________
1708 void AliConvEventCuts::GetNotRejectedParticles(Int_t rejection, TList *HeaderList, AliVEvent *MCEvent){
1709
1710         TString periodName = ((AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask(fV0ReaderName.Data()))->GetPeriodName();
1711
1712
1713         if(fNotRejectedStart){
1714                 delete[] fNotRejectedStart;
1715                 fNotRejectedStart = NULL;
1716         }
1717         if(fNotRejectedEnd){
1718                 delete[] fNotRejectedEnd;
1719                 fNotRejectedEnd = NULL;
1720         }
1721         if(fGeneratorNames){
1722                 delete[] fGeneratorNames;
1723                 fGeneratorNames = NULL;
1724         }
1725
1726         if(rejection == 0) return; // No Rejection
1727
1728         AliGenCocktailEventHeader *cHeader = 0x0;
1729         AliAODMCHeader *cHeaderAOD = 0x0;
1730         Bool_t headerFound = kFALSE;
1731         AliStack *fMCStack = 0x0;
1732         TClonesArray *fMCStackAOD = 0x0;
1733         if(MCEvent->IsA()==AliMCEvent::Class()){
1734                 cHeader = dynamic_cast<AliGenCocktailEventHeader*>(dynamic_cast<AliMCEvent*>(MCEvent)->GenEventHeader());
1735                 if(cHeader) headerFound = kTRUE;
1736                 if(dynamic_cast<AliMCEvent*>(MCEvent))fMCStack = dynamic_cast<AliStack*>(dynamic_cast<AliMCEvent*>(MCEvent)->Stack());
1737         }
1738         if(MCEvent->IsA()==AliAODEvent::Class()){ // MCEvent is a AODEvent in case of AOD
1739                 cHeaderAOD = dynamic_cast<AliAODMCHeader*>(MCEvent->FindListObject(AliAODMCHeader::StdBranchName()));
1740                 fMCStackAOD = dynamic_cast<TClonesArray*>(MCEvent->FindListObject(AliAODMCParticle::StdBranchName()));
1741                 
1742                 
1743                 if(cHeaderAOD) headerFound = kTRUE;
1744         }
1745
1746         if(headerFound){
1747                 TList *genHeaders = 0x0;
1748                 if(cHeader) genHeaders = cHeader->GetHeaders();
1749                 if(cHeaderAOD){
1750                         genHeaders = cHeaderAOD->GetCocktailHeaders();
1751                         if(genHeaders->GetEntries()==1){
1752                                 SetRejectExtraSignalsCut(0);
1753                                 return;
1754                         }
1755                 }
1756                 AliGenEventHeader* gh = 0;
1757                 fnHeaders = 0;
1758                 Int_t firstindexA = 0;
1759                 Int_t lastindexA =  -1;
1760                 if(rejection == 1 || rejection == 3) fnHeaders = 1; // MinBiasHeader
1761                 if(rejection == 2){ // TList of Headers Names
1762                         for(Int_t i = 0; i<genHeaders->GetEntries();i++){
1763                                 gh = (AliGenEventHeader*)genHeaders->At(i);
1764                                 TString GeneratorName = gh->GetName();
1765                                 lastindexA = lastindexA + gh->NProduced();
1766 //                              cout << i << "\t" << GeneratorName.Data() << endl;
1767                                 for(Int_t j = 0; j<HeaderList->GetEntries();j++){
1768                                         TString GeneratorInList = ((TObjString*)HeaderList->At(j))->GetString();
1769 //                                      cout << GeneratorInList.Data() << endl;
1770                                         if(GeneratorName.CompareTo(GeneratorInList) == 0){
1771 //                                              cout << "accepted" << endl;
1772                                                 if (GeneratorInList.CompareTo("PARAM") == 0 || GeneratorInList.CompareTo("BOX") == 0 ){
1773                                                         if(fMCStack){
1774                                                                 if (fMCStack->Particle(firstindexA)->GetPdgCode() == fAddedSignalPDGCode ) {
1775                                                                         if (periodName.CompareTo("LHC14a1b")==0 || periodName.CompareTo("LHC14a1c")==0 ){
1776                                                                                 if (gh->NProduced() > 10 && fMCStack->Particle(firstindexA+10)->GetPdgCode() == fAddedSignalPDGCode ){
1777 //                                                                                      cout << "cond 1: "<< fnHeaders << endl;
1778                                                                                         fnHeaders++;
1779                                                                                         continue;
1780                                                                                 }       
1781                                                                                 continue;
1782                                                                         } else {
1783 //                                                                              cout << "cond 2: " << fnHeaders << endl;
1784                                                                                 fnHeaders++;
1785                                                                                 continue;
1786                                                                         }       
1787                                                                 }
1788                                                         }   
1789                                                         if ( fMCStackAOD){
1790                                                                 AliAODMCParticle *aodMCParticle = static_cast<AliAODMCParticle*>(fMCStackAOD->At(firstindexA));
1791                                                                 if (  aodMCParticle->GetPdgCode() == fAddedSignalPDGCode ){
1792                                                                         if (periodName.CompareTo("LHC14a1b")==0 || periodName.CompareTo("LHC14a1c")==0 ){
1793                                                                                 if (gh->NProduced() > 10){
1794                                                                                         AliAODMCParticle *aodMCParticle2 = static_cast<AliAODMCParticle*>(fMCStackAOD->At(firstindexA+10));
1795                                                                                         if (  aodMCParticle2->GetPdgCode() == fAddedSignalPDGCode ){
1796 //                                                                                              cout << "cond 1: " << fnHeaders << endl;
1797                                                                                                 fnHeaders++;
1798                                                                                                 continue;
1799                                                                                         } 
1800                                                                                 }       
1801                                                                                 continue;
1802                                                                         } else {
1803 //                                                                              cout << "cond 2: " << fnHeaders << endl;
1804                                                                                 fnHeaders++;
1805                                                                                 continue;
1806                                                                         }       
1807                                                                 }   
1808                                                         }
1809                                                         continue;
1810                                                 }
1811 //                                              cout << "cond 3: "<< fnHeaders << endl;
1812                                                 fnHeaders++;
1813                                                 continue;
1814                                         }
1815                                 }
1816                                 firstindexA = firstindexA + gh->NProduced();
1817                         }
1818                 }
1819 //              cout << "number of headers: " <<fnHeaders << endl;
1820                 
1821                 fNotRejectedStart = new Int_t[fnHeaders];
1822                 fNotRejectedEnd = new Int_t[fnHeaders];
1823                 fGeneratorNames = new TString[fnHeaders];
1824
1825                 if(rejection == 1 || rejection == 3){
1826                         fNotRejectedStart[0] = 0;
1827                         fNotRejectedEnd[0] = ((AliGenEventHeader*)genHeaders->At(0))->NProduced()-1;
1828                         fGeneratorNames[0] = ((AliGenEventHeader*)genHeaders->At(0))->GetName();
1829                         return;
1830                 }
1831
1832                 Int_t firstindex = 0;
1833                 Int_t lastindex =  -1;
1834                 Int_t number = 0;
1835                 
1836                 for(Int_t i = 0; i<genHeaders->GetEntries();i++){
1837                         gh = (AliGenEventHeader*)genHeaders->At(i);
1838                         TString GeneratorName = gh->GetName();
1839                         lastindex = lastindex + gh->NProduced();
1840                         for(Int_t j = 0; j<HeaderList->GetEntries();j++){
1841                                 TString GeneratorInList = ((TObjString*)HeaderList->At(j))->GetString();
1842 //                              cout << i << "\t" << GeneratorName.Data() << endl;
1843                                 if(GeneratorName.CompareTo(GeneratorInList) == 0){
1844                                         if (GeneratorInList.CompareTo("PARAM") == 0 || GeneratorInList.CompareTo("BOX") == 0 ){
1845                                                 if(fMCStack){
1846                                                         if (fMCStack->Particle(firstindex)->GetPdgCode() == fAddedSignalPDGCode ) {
1847                                                                 if (periodName.CompareTo("LHC14a1b")==0 || periodName.CompareTo("LHC14a1c")==0 ){
1848 //                                                                      cout << "produced " << gh->NProduced() << " with box generator" << endl;
1849                                                                         if (gh->NProduced() > 10 && fMCStack->Particle(firstindex+10)->GetPdgCode() == fAddedSignalPDGCode){
1850 //                                                                              cout << "one of them was a pi0 or eta" <<  endl;
1851                                                                                 fNotRejectedStart[number] = firstindex;
1852                                                                                 fNotRejectedEnd[number] = lastindex;
1853                                                                                 fGeneratorNames[number] = GeneratorName;
1854                                                                                 number++;
1855 //                                                                              cout << "Number of particles produced for: " << i << "\t" << GeneratorName.Data() << "\t" << lastindex-firstindex+1 << endl;
1856                                                                                 continue;
1857                                                                         }       
1858                                                                 } else {
1859                                                                         fNotRejectedStart[number] = firstindex;
1860                                                                         fNotRejectedEnd[number] = lastindex;
1861                                                                         fGeneratorNames[number] = GeneratorName;
1862                                                                         number++;
1863                                                                         continue;
1864                                                                 }       
1865                                                         }
1866                                                 }   
1867                                                 if ( fMCStackAOD){
1868                                                         AliAODMCParticle *aodMCParticle = static_cast<AliAODMCParticle*>(fMCStackAOD->At(firstindex));
1869                                                         if (  aodMCParticle->GetPdgCode() == fAddedSignalPDGCode ){
1870                                                                 if (periodName.CompareTo("LHC14a1b")==0 || periodName.CompareTo("LHC14a1c")==0 ){
1871                                                                         if (gh->NProduced() > 10) {
1872                                                                                 AliAODMCParticle *aodMCParticle2 = static_cast<AliAODMCParticle*>(fMCStackAOD->At(firstindex+10));
1873                                                                                 if ( aodMCParticle2->GetPdgCode() == fAddedSignalPDGCode ){
1874                                                                                         fNotRejectedEnd[number] = lastindex;
1875                                                                                         fNotRejectedStart[number] = firstindex;
1876                                                                                         fGeneratorNames[number] = GeneratorName;
1877                                                                                         number++;
1878                                                                         } 
1879                                                                                         continue;
1880                                                                                 }
1881                                                                 } else {
1882                                                                         fNotRejectedStart[number] = firstindex;
1883                                                                         fNotRejectedEnd[number] = lastindex;
1884                                                                         fGeneratorNames[number] = GeneratorName;
1885                                                                         number++;
1886                                                                         continue;       
1887                                                                 }       
1888                                                         }   
1889                                                 }
1890                                                 continue;
1891                                         } else {
1892                                                 fNotRejectedStart[number] = firstindex;
1893                                                 fNotRejectedEnd[number] = lastindex;
1894                                                 fGeneratorNames[number] = GeneratorName;
1895 //                                              cout << "Number of particles produced for: " << i << "\t" << GeneratorName.Data() << "\t" << lastindex-firstindex+1 << endl;
1896                                                 number++;
1897                                                 continue;
1898                                         }
1899                                         
1900                                 }
1901                         }
1902                         firstindex = firstindex + gh->NProduced();
1903                 }
1904 //              for (Int_t i = 0; i < number; i++){
1905 //                      cout << i << "\t" <<fGeneratorNames[i] << "\t" << fNotRejectedStart[i] << "\t" <<fNotRejectedEnd[i] << endl;
1906 //              }       
1907         
1908         } else { // No Cocktail Header Found
1909                 fNotRejectedStart = new Int_t[1];
1910                 fNotRejectedEnd = new Int_t[1];
1911
1912                 fnHeaders = 1;
1913                 fNotRejectedStart[0] = 0;
1914                 fNotRejectedEnd[0] = static_cast<AliMCEvent*>(MCEvent)->Stack()->GetNprimary()-1;
1915                 fGeneratorNames = new TString[1];
1916                 fGeneratorNames[0] = "NoCocktailGeneratorFound";
1917
1918                 AliGenPythiaEventHeader *mcHeaderPythia = dynamic_cast<AliGenPythiaEventHeader*>(static_cast<AliMCEvent*>(MCEvent)->GenEventHeader());
1919                 if (mcHeaderPythia) fGeneratorNames[0] = "NoCocktailGeneratorFound_Pythia";
1920                 AliGenDPMjetEventHeader *mcHeaderPhojet = dynamic_cast<AliGenDPMjetEventHeader*>(static_cast<AliMCEvent*>(MCEvent)->GenEventHeader());
1921                 if (mcHeaderPhojet) fGeneratorNames[0] = "NoCocktailGeneratorFound_Phojet";
1922                 AliGenHijingEventHeader *mcHeaderHijing = dynamic_cast<AliGenHijingEventHeader*>(static_cast<AliMCEvent*>(MCEvent)->GenEventHeader());
1923                 if (mcHeaderHijing) fGeneratorNames[0] = "NoCocktailGeneratorFound_Hijing";
1924
1925                 SetRejectExtraSignalsCut(0);
1926         }
1927         
1928 }
1929
1930 //_________________________________________________________________________
1931 Int_t AliConvEventCuts::IsParticleFromBGEvent(Int_t index, AliStack *MCStack, AliVEvent *InputEvent){
1932
1933         // Not Accepted == kFALSE == 0
1934         //     Accepted ==  kTRUE == 1
1935         //  FirstHeader ==  kTRUE == 3
1936         if(index < 0) return 0; // No Particle
1937
1938 //      if (index == 100){
1939 //              cout << "possible headers" << endl;
1940 //              for(Int_t i = 0;i<fnHeaders;i++){
1941 //                      cout << i << "\t" <<fGeneratorNames[i] << "\t" << fNotRejectedStart[i] << "\t" <<fNotRejectedEnd[i] << endl;
1942 //              }
1943 //      }       
1944         Int_t accepted = 0;
1945         if(!InputEvent || InputEvent->IsA()==AliESDEvent::Class()){
1946                 if( index >= MCStack->GetNprimary()){ // Secondary Particle
1947                         if( ((TParticle*)MCStack->Particle(index))->GetMother(0) < 0) return 1; // Secondary Particle without Mother??
1948                         return IsParticleFromBGEvent(((TParticle*)MCStack->Particle(index))->GetMother(0),MCStack,InputEvent);
1949                 }
1950                 for(Int_t i = 0;i<fnHeaders;i++){
1951                         if(index >= fNotRejectedStart[i] && index <= fNotRejectedEnd[i]){
1952                                 accepted = 1;
1953                                 if(i == 0) accepted = 2; // MB Header
1954                         }
1955                 }
1956         }
1957         else if(InputEvent->IsA()==AliAODEvent::Class()){
1958                 TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(InputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
1959                 if (AODMCTrackArray){
1960                         AliAODMCParticle *aodMCParticle = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(index));
1961                         if(!aodMCParticle) return 1; // Photon Without a Mother ? --> Accepted
1962                         if(!aodMCParticle->IsPrimary()){
1963                                 if( aodMCParticle->GetMother() < 0) return 1;// Secondary Particle without Mother??
1964                                 return IsParticleFromBGEvent(aodMCParticle->GetMother(),MCStack,InputEvent);
1965                         }
1966                         index = abs(static_cast<AliAODMCParticle*>(AODMCTrackArray->At(index))->GetLabel());
1967                         for(Int_t i = 0;i<fnHeaders;i++){
1968                                 if(index >= fNotRejectedStart[i] && index <= fNotRejectedEnd[i]){
1969                                         accepted = 1;
1970                                         if(i == 0) accepted = 2; // MB Header
1971                                 }
1972                         }
1973                 }       
1974         }
1975
1976         return accepted;
1977 }
1978
1979 //_________________________________________________________________________
1980 Int_t AliConvEventCuts::IsEventAcceptedByCut(AliConvEventCuts *ReaderCuts, AliVEvent *InputEvent, AliMCEvent *MCEvent, Int_t isHeavyIon){
1981
1982         Bool_t isMC = kFALSE;
1983         if (MCEvent){isMC = kTRUE;}
1984         
1985         if ( !IsTriggerSelected(InputEvent, isMC) )
1986                 return 3;
1987
1988         if(isHeavyIon != 0 && !(IsCentralitySelected(InputEvent,MCEvent)))
1989                 return 1; // Check Centrality --> Not Accepted => eventQuality = 1
1990                 
1991         if(isHeavyIon == 0 && GetIsFromPileup()){
1992                 if(InputEvent->IsPileupFromSPD(3,0.8,3.,2.,5.)){
1993                         return 6; // Check Pileup --> Not Accepted => eventQuality = 6
1994                 }
1995         }
1996
1997         Bool_t hasV0And = ReaderCuts->HasV0AND();
1998         Bool_t isSDDFired = ReaderCuts->IsSDDFired();
1999         
2000         if( ( (IsSpecialTrigger() == 0 && IsSpecialSubTrigger() == 1) || (IsSpecialTrigger() == 1 && IsSpecialSubTrigger() == 1) ) && !isSDDFired && !MCEvent) 
2001         //if V0OR with SDD requested or V0AND with SDD request but the SDD has not fired
2002         return 7; // V0 with SDD requested but no fired
2003
2004         if( ( (IsSpecialTrigger() == 1 && IsSpecialSubTrigger() == 0) || (IsSpecialTrigger() == 1 && IsSpecialSubTrigger() == 1) ) && !hasV0And) 
2005         //if V0AND (only) or V0AND with SDD requested but V0AND requested but no fired
2006         return 8; // V0AND requested but no fired
2007
2008
2009         
2010         if( (IsSpecialTrigger() == 2 || IsSpecialTrigger() == 3) && !isSDDFired && !MCEvent)
2011                 return 7; // With SDD requested but no fired
2012
2013         if( (IsSpecialTrigger() == 1 || IsSpecialTrigger() == 3) && !hasV0And)
2014                 return 8; // V0AND requested but no fired
2015
2016         if(hCentrality)hCentrality->Fill(GetCentrality(InputEvent));
2017         if(hCentralityVsNumberOfPrimaryTracks)
2018                 hCentralityVsNumberOfPrimaryTracks->Fill(GetCentrality(InputEvent),
2019                                                                                                 ((AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()
2020                                                                                                 ->GetTask(fV0ReaderName.Data()))->GetNumberOfPrimaryTracks());     
2021
2022         return 0;
2023 }
2024
2025 //_________________________________________________________________________
2026 Float_t AliConvEventCuts::GetWeightForMeson(TString period, Int_t index, AliStack *MCStack, AliVEvent *InputEvent){
2027         if (!(period.CompareTo("LHC12f1a") == 0 || period.CompareTo("LHC12f1b") == 0  || period.CompareTo("LHC12i3") == 0 || period.CompareTo("LHC11a10a") == 0 || period.CompareTo("LHC11a10b") == 0 || period.CompareTo("LHC11a10b_bis") == 0 || period.CompareTo("LHC11a10a_bis") == 0 || period.CompareTo("LHC11a10b_plus") == 0 || period.Contains("LHC13d2")|| period.Contains("LHC14a1") || 
2028         period.CompareTo("LHC13e7") == 0 || period.Contains("LHC13b2_efix") || period.CompareTo("LHC14b2") == 0 )) return 1.;
2029
2030         Int_t kCaseGen = 0;
2031         for (Int_t i = 0; i < fnHeaders; i++){
2032                 if (index >= fNotRejectedStart[i] && index < fNotRejectedEnd[i]+1){
2033                         if (fGeneratorNames[i].CompareTo("Pythia") == 0){
2034                                 kCaseGen = 1;
2035                         } else if (fGeneratorNames[i].CompareTo("DPMJET") == 0){
2036                                 kCaseGen = 2;
2037                         } else if (fGeneratorNames[i].CompareTo("HIJING") == 0 ||
2038                                                 fGeneratorNames[i].CompareTo("Hijing") == 0 ||
2039                                                 fGeneratorNames[i].Contains("hijing")){
2040                                 kCaseGen = 3;
2041                         } else if (fGeneratorNames[i].CompareTo("BOX") == 0){
2042                                 kCaseGen = 4;
2043                         } else if (fGeneratorNames[i].CompareTo("PARAM") == 0){
2044                                 kCaseGen = 5;
2045                         } else if (fGeneratorNames[i].CompareTo("NoCocktailGeneratorFound") == 0){
2046                                 kCaseGen = 6;
2047                         } else if (fGeneratorNames[i].CompareTo("NoCocktailGeneratorFound_Pythia") == 0){
2048                                 kCaseGen = 1;
2049                         } else if (fGeneratorNames[i].CompareTo("NoCocktailGeneratorFound_Phojet") == 0){
2050                                 kCaseGen = 2;
2051                         } else if (fGeneratorNames[i].CompareTo("NoCocktailGeneratorFound_Hijing") == 0){
2052                                 kCaseGen = 3;
2053                         }
2054                         if (period.Contains("LHC13d2") || period.CompareTo("LHC13e7") == 0 || period.Contains("LHC13b2_efix")  || period.Contains("LHC14a1") || period.CompareTo("LHC14b2") == 0 ){
2055                                 kCaseGen = 3;
2056                         }
2057                 }
2058         }
2059         if (kCaseGen == 0) return 1;
2060
2061
2062         Double_t mesonPt = 0;
2063         Double_t mesonMass = 0;
2064         Int_t PDGCode = 0;
2065         if(!InputEvent || InputEvent->IsA()==AliESDEvent::Class()){
2066                 mesonPt = ((TParticle*)MCStack->Particle(index))->Pt();
2067                 mesonMass = ((TParticle*)MCStack->Particle(index))->GetCalcMass();
2068                 PDGCode = ((TParticle*)MCStack->Particle(index))->GetPdgCode();
2069         }
2070         else if(InputEvent->IsA()==AliAODEvent::Class()){
2071                 TClonesArray *AODMCTrackArray = dynamic_cast<TClonesArray*>(InputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
2072                 if (AODMCTrackArray){
2073                         AliAODMCParticle *aodMCParticle = static_cast<AliAODMCParticle*>(AODMCTrackArray->At(index));
2074                         mesonPt = aodMCParticle->Pt();
2075                         mesonMass = aodMCParticle->GetCalcMass();
2076                         PDGCode = aodMCParticle->GetPdgCode();
2077                 } else {
2078                         return 1;
2079                 }       
2080         }
2081
2082         Float_t functionResultMC = 1.;
2083         if (kCaseGen == 1){ // Pythia 6
2084                 Float_t dNdyMC = 2.1462;
2085                 Float_t nMC = 7.06055;
2086                 Float_t tMC = 0.12533;
2087                 if ( PDGCode ==  111){
2088                         dNdyMC = 2.1462;
2089                         nMC = 7.06055;
2090                         tMC = 0.12533;
2091                 } else if ( PDGCode ==  221){
2092                         dNdyMC = 0.2357;
2093                         nMC = 5.9105;
2094                         tMC = 0.1525;
2095                 }
2096                 functionResultMC = dNdyMC / ( 2 * TMath::Pi())*(nMC-1.)*(nMC-2.) / (nMC*tMC*(nMC*tMC+mesonMass*(nMC-2.)))  * TMath::Power(1.+(TMath::Sqrt(mesonPt*mesonPt+mesonMass*mesonMass)-mesonMass)/(nMC*tMC), -nMC);
2097         } else if (kCaseGen == 2){ // Phojet
2098                 Float_t dNdyMC = 2.35978;
2099                 Float_t nMC = 6.81795;
2100                 Float_t tMC = 0.11492;
2101                 if ( PDGCode ==  111){
2102                         dNdyMC = 2.35978;
2103                         nMC = 6.81795;
2104                         tMC = 0.11492;
2105                 } else if ( PDGCode ==  221){
2106                         dNdyMC = 0.3690;
2107                         nMC = 5.55809;
2108                         tMC = 0.13387;
2109                 }
2110                 functionResultMC = dNdyMC / ( 2 * TMath::Pi())*(nMC-1.)*(nMC-2.) / (nMC*tMC*(nMC*tMC+mesonMass*(nMC-2.)))  * TMath::Power(1.+(TMath::Sqrt(mesonPt*mesonPt+mesonMass*mesonMass)-mesonMass)/(nMC*tMC), -nMC);
2111         } else if (kCaseGen == 4){ // BOX generators pp
2112         //       functionResultMC = 1./sqrt(1.-mesonMass*mesonMass/((mesonMass*mesonMass+mesonPt*mesonPt)*cosh(mesonY)*cosh(mesonY)));
2113                 Float_t a = 0.23437;
2114                 Float_t b = 5.6661;
2115                 Float_t c = -1430.5863;
2116                 Float_t d = -0.6966624;
2117                 Float_t e = 252.3742;
2118                 if ( PDGCode ==  111){
2119                         a = 0.23437;
2120                         b = 5.6661;
2121                         c = -1430.5863;
2122                         d = -0.6966624;
2123                         e = 252.3742;
2124                 } else if ( PDGCode ==  221){
2125                         a = 0.10399;
2126                         b = 4.35311;
2127                         c = -12.17723;
2128                         d = -0.01172;
2129                         e =1.85140;
2130                 }
2131                 functionResultMC = a*TMath::Power(mesonPt,-1.*(b+c/(TMath::Power(mesonPt,d)+e)))*1./mesonPt *1./1.6 *1./(2.* TMath::Pi());
2132         //       cout << functionResultMC << endl;
2133         } else if (kCaseGen == 3 ){ // HIJING
2134                 if ( PDGCode ==  111 && fDoReweightHistoMCPi0 && hReweightMCHistPi0!= 0x0){
2135                         functionResultMC = hReweightMCHistPi0->Interpolate(mesonPt);
2136                 }
2137                 if ( PDGCode ==  221 && fDoReweightHistoMCEta && hReweightMCHistEta!= 0x0){
2138                         functionResultMC = hReweightMCHistEta->Interpolate(mesonPt);
2139                 }
2140                 if ( PDGCode ==  310 && fDoReweightHistoMCK0s && hReweightMCHistK0s!= 0x0){
2141                         functionResultMC = hReweightMCHistK0s->Interpolate(mesonPt);
2142                 }
2143         }
2144
2145         Float_t functionResultData = 1;
2146         if (kCaseGen == 1 || kCaseGen == 2 || kCaseGen == 4 ){
2147                 Float_t dNdyData = 2.2328;
2148                 Float_t nData = 7.1473;
2149                 Float_t tData = 0.1346;
2150                 if ( PDGCode ==  111){
2151                         dNdyData = 2.2328;
2152                         nData = 7.1473;
2153                         tData = 0.1346;
2154                 } else if ( PDGCode ==  221){
2155                         dNdyData = 0.38992; //be careful this fit is not optimal, eta in data still has problems
2156                         nData = 5.72778;
2157                         tData = 0.13835;
2158                 }
2159                 functionResultData = dNdyData / ( 2 * TMath::Pi())*(nData-1.)*(nData-2.) / (nData*tData*(nData*tData+mesonMass*(nData-2.)))  * TMath::Power(1.+(TMath::Sqrt(mesonPt*mesonPt+mesonMass*mesonMass)-mesonMass)/(nData*tData), -nData);
2160         //       cout << functionResultData << endl;
2161         } else {
2162                 if ( PDGCode ==  111 && fDoReweightHistoMCPi0 && fFitDataPi0!= 0x0){
2163                         functionResultData = fFitDataPi0->Eval(mesonPt);
2164                 }
2165                 if ( PDGCode ==  221 && fDoReweightHistoMCEta && fFitDataEta!= 0x0){
2166                         functionResultData = fFitDataEta->Eval(mesonPt);
2167                 }
2168                 if ( PDGCode ==  310 && fDoReweightHistoMCK0s && fFitDataK0s!= 0x0){
2169                         functionResultData = fFitDataK0s->Eval(mesonPt);
2170                 }
2171
2172         }
2173
2174         Double_t weight = 1;
2175         if (PDGCode ==  111 || PDGCode ==  221){
2176                 if (functionResultData != 0. && functionResultMC != 0. && isfinite(functionResultData) && isfinite(functionResultMC)){
2177                         weight = functionResultData/functionResultMC;
2178                         if ( kCaseGen == 3){
2179                                 if (PDGCode ==  111){ 
2180                                 if (!(fDoReweightHistoMCPi0 && hReweightMCHistPi0!= 0x0 && PDGCode ==  111)){
2181                                         weight = 1.;
2182                                 }
2183                                 } 
2184                                 if (PDGCode ==  221){ 
2185                                 if (!(fDoReweightHistoMCEta && hReweightMCHistEta!= 0x0 && PDGCode ==  221)){
2186                                         weight = 1.;
2187                                 }
2188                                 }
2189                         }
2190                         if (!isfinite(functionResultData)) weight = 1.;
2191                         if (!isfinite(weight)) weight = 1.;
2192                 }
2193         } else if (PDGCode ==  310 && functionResultMC != 0 && isfinite(functionResultMC)){
2194                         weight = functionResultMC;
2195         }
2196
2197         //    if (fModCentralityClass == 0 && fCentralityMin == 4 && fCentralityMax == 6 && PDGCode ==  111){
2198         //        cout << period.Data() << "\t" << kCaseGen << "\t" <<fModCentralityClass<< "\t" <<fCentralityMin<< "\t" <<fCentralityMax << "\t" << mesonPt << "\t" <<mesonMass<< "\t"<<functionResultData << "\t"<< functionResultMC << "\t" << weight <<endl;
2199         //    }
2200         return weight;
2201 }
2202
2203
2204 ///________________________________________________________________________
2205 void AliConvEventCuts::GetCorrectEtaShiftFromPeriod(TString periodName){
2206
2207    if(periodName.CompareTo("LHC12g") == 0 || //pilot run 2012
2208       periodName.CompareTo("LHC13b") == 0 || //mainly minimum bias
2209       periodName.CompareTo("LHC13c") == 0 || //mainly minimum bias
2210       periodName.CompareTo("LHC13d") == 0 || //mainly triggered
2211       periodName.CompareTo("LHC13e") == 0 || //mainly triggered
2212       periodName.CompareTo("LHC13c3") == 0 || //MC Starlight, anchor LHC13d+e
2213       periodName.CompareTo("LHC13c2") == 0 || //MC Starlight, coherent J/Psi, UPC muon anchor LHC13d+e
2214       periodName.CompareTo("LHC13b4") == 0 || //MC Pythia 6 (Jet-Jet), anchor LHC13b
2215       periodName.CompareTo("LHC13b2_fix_1") == 0 || //MC DPMJET, anchr LHC13b+c
2216       periodName.CompareTo("LHC13b2_efix_p1") == 0 || //MC DPMJET, anchr LHC13b+c
2217       periodName.CompareTo("LHC13b2_efix_p2") == 0 || //MC DPMJET, anchr LHC13b+c
2218       periodName.CompareTo("LHC13b2_efix_p3") == 0 || //MC DPMJET, anchr LHC13b+c
2219       periodName.CompareTo("LHC13b2_efix_p4") == 0 || //MC DPMJET, anchr LHC13b+c
2220       periodName.CompareTo("LHC13e7") == 0 || //MC DPMJET, anchr LHC13b+c
2221       periodName.CompareTo("LHC13b3") == 0 || //MC HIJING, weighted to number of events per run, anchor LHC13b
2222       periodName.CompareTo("LHC13b2") == 0 ||  // MC DPMJET, wrong energy, anchor LHC13b
2223       periodName.CompareTo("LHC13b2_plus") == 0 || // MC DPMJET, weighted to number event per run, anchor LHC13b
2224       periodName.CompareTo("LHC13c1_bis") == 0 || // MC AMPT fast generation, pT hardbin, anchor ?
2225       periodName.CompareTo("LHC13c1") == 0 || // MC AMPT fast generation, anchor ?
2226       periodName.CompareTo("LHC13b1") == 0 || // MC DPMJET, fragments, with fixed label 0, anchor LHC12g
2227       periodName.CompareTo("LHC12g4b_fix") == 0 || // MC DPMJET, with fixed label 0, anchor LHC12g
2228       periodName.CompareTo("LHC12g1_fix") == 0 || // MC ?, with fixed label 0, anchor LHC12g
2229       periodName.CompareTo("LHC12g4c") == 0 || // MC DPMJET, shifted vertex runs, anchor LHC12g
2230       periodName.CompareTo("LHC12h6") == 0 || // MC muon cocktail, anchor LHC12g
2231       periodName.CompareTo("LHC12g4b") == 0 || // MC DPMJET 3rd iteration, anchor LHC12g
2232       periodName.CompareTo("LHC12g4a") == 0 || // MC DPMJET improved, anchor LHC12g
2233       periodName.CompareTo("LHC12g4") == 0 || // MC DPMJET, anchor LHC12g
2234       periodName.CompareTo("LHC12g5") == 0 || // MC PHOJET, anchor LHC12g
2235       periodName.CompareTo("LHC12g2") == 0 || // MC Starlight background, anchor LHC12g
2236       periodName.CompareTo("LHC12g1") == 0 ) // MC ?, anchor LHC12g
2237       {
2238          printf(" Gamma Conversion Cuts %s :: pPb Run doing Eta Shift of %f \n\n",(GetCutNumber()).Data(),-0.465);
2239          SetEtaShift(-0.465);
2240       }
2241    else if(periodName.CompareTo("LHC13f") == 0 ||
2242            periodName.CompareTo("LHC13c6b") == 0 ||// MC Jpsi -> mumu, anchor LHC13f
2243            periodName.CompareTo("LHC13c5") == 0 || //MC Starlight, gamma gamma UPC muon, anchor LHC13f
2244            periodName.CompareTo("LHC13c4") == 0 )//MC Starlight, coherent JPsi, UPC muon, anchor LHC13f
2245       {
2246          printf(" Gamma Conversion Cuts %s :: Pbp Run doing Eta Shift of %f \n\n",(GetCutNumber()).Data(),0.465);
2247          SetEtaShift(+0.465);
2248       }
2249    else printf(" Gamma Conversion Cuts %s :: Automatic Eta Shift requested but Period is not known -> No Shift \n\n",(GetCutNumber()).Data());
2250 }
2251
2252 //________________________________________________________________________
2253 AliEmcalTriggerPatchInfo* AliConvEventCuts::GetMainTriggerPatch() 
2254 {
2255   //get main trigger match; if not known yet, look for it and cache
2256
2257   if (fMainTriggerPatchEMCAL) 
2258     return fMainTriggerPatchEMCAL;
2259
2260   if (!fTriggerPatchInfo) {
2261     AliError(Form("%s: fTriggerPatchInfo not available",GetName()));
2262     return 0;
2263   }
2264
2265   //number of patches in event
2266   Int_t nPatch = fTriggerPatchInfo->GetEntries();
2267
2268   //extract main trigger patch
2269   AliEmcalTriggerPatchInfo *patch;
2270   for (Int_t iPatch = 0; iPatch < nPatch; iPatch++) {
2271     patch = (AliEmcalTriggerPatchInfo*)fTriggerPatchInfo->At( iPatch );
2272     if (patch->IsMainTrigger()) {
2273       fMainTriggerPatchEMCAL = patch;
2274       break;
2275     }
2276   }
2277
2278   return fMainTriggerPatchEMCAL;
2279 }
2280
2281
2282 //________________________________________________________________________
2283 void AliConvEventCuts::InitializeEMCALTrigger(AliVEvent *fInputEvent)
2284 {
2285 //      cout << "entered EMCAL trigger initialization" << endl;
2286         
2287         // Init the analysis.
2288         if (fCaloTriggersName.IsNull()){
2289                 if (fInputEvent->IsA()==AliESDEvent::Class()){
2290                         fCaloTriggersName = "EMCALTrigger";
2291                 } else {
2292                         fCaloTriggersName = "emcalTrigger";
2293                 }       
2294         }
2295         
2296         if (!fCaloTriggersName.IsNull() && !fCaloTriggers) {
2297                 fCaloTriggers =  dynamic_cast<AliVCaloTrigger*>(fInputEvent->FindListObject(fCaloTriggersName));
2298                 if (!fCaloTriggers) {
2299                         AliError(Form("%s: Could not retrieve calo triggers %s!", GetName(), fCaloTriggersName.Data())); 
2300                 return;
2301                 }
2302         }
2303
2304         if (fCaloTriggerPatchInfoName.IsNull()){
2305                 if (fInputEvent->IsA()==AliESDEvent::Class()){
2306                         fCaloTriggerPatchInfoName = "EmcalTriggers";
2307                 } else {
2308                         fCaloTriggerPatchInfoName = "EmcalTriggers";
2309                 }
2310         }       
2311         
2312         if (!fCaloTriggerPatchInfoName.IsNull() && !fTriggerPatchInfo) {
2313                 fTriggerPatchInfo = GetArrayFromEvent(fInputEvent, fCaloTriggerPatchInfoName.Data(), "AliEmcalTriggerPatchInfo");
2314                 if (!fTriggerPatchInfo) {
2315                         AliError(Form("%s: Could not retrieve calo trigger patch info %s!", GetName(), fCaloTriggerPatchInfoName.Data())); 
2316                 return;
2317                 }
2318
2319         }
2320
2321         fEMCALTrigInitialized = kTRUE;
2322 }
2323
2324 //________________________________________________________________________
2325 ULong_t AliConvEventCuts::GetTriggerList(){
2326         if (!fTriggerPatchInfo)
2327         return 0;
2328         //number of patches in event
2329         Int_t nPatch = fTriggerPatchInfo->GetEntries();
2330
2331         //loop over patches to define trigger type of event
2332         Int_t nG1 = 0;
2333         Int_t nG2 = 0;
2334         Int_t nJ1 = 0;
2335         Int_t nJ2 = 0;
2336         Int_t nL0 = 0;
2337         AliEmcalTriggerPatchInfo *patch;
2338 //      if (nPatch> 0) {cout << "NEW Triggers in this event*********************************" << endl;}
2339         for (Int_t iPatch = 0; iPatch < nPatch; iPatch++) {
2340                 patch = (AliEmcalTriggerPatchInfo*)fTriggerPatchInfo->At( iPatch );
2341 //              cout << "Patch energy: "<<patch->GetPatchE() << "\t ADC counts: " << patch->GetADCAmp() << endl;
2342 //              cout << "Phi: " << patch->GetPhiMin() << " - " << patch->GetPhiMax() << " delta phi: " <<abs(patch->GetPhiMin()-patch->GetPhiMax())<< endl;
2343 //              cout << "Eta: " << patch->GetEtaMin() << " - " << patch->GetEtaMax() << " delta eta: " <<abs(patch->GetEtaMin()-patch->GetEtaMax())<< endl;
2344                 if (patch->IsGammaHigh()){
2345 //                      cout << "fired L1GA high" << endl;
2346                         nG1++;
2347                 }       
2348                 if (patch->IsGammaLow()){
2349 //                      cout << "fired L1GA low" << endl;
2350                         nG2++;
2351                 }       
2352                 if (patch->IsJetHigh()){
2353 //                      cout << "fired L1JE high" << endl;
2354                         nJ1++;
2355                 }
2356                 if (patch->IsJetLow()){
2357 //                      cout << "fired L1JE low" << endl;
2358                         nJ2++;
2359                 }       
2360                 if (patch->IsLevel0()){
2361 //                      cout << "fired L0" << endl;
2362                         nL0++;
2363                 }       
2364 //              cout << patch->GetPatchE()      << "\t" << patch->GetADCAmp()   << "\t" << patch->IsGammaHigh() << "\t" << patch->IsGammaLow()  
2365 //                   << "\t" << patch->IsJetHigh()      << "\t" << patch->IsJetLow()    << "\t" << patch->IsLevel0() 
2366 //                       << "\t" << patch->GetPhiMin()  << "\t" << patch->GetPhiMax()   << "\t" << abs(patch->GetPhiMin()-patch->GetPhiMax())
2367 //                       << "\t" << patch->GetEtaMin()  << "\t" << patch->GetEtaMax()   << "\t" << abs(patch->GetEtaMin()-patch->GetEtaMax()) << endl;
2368         }
2369
2370         if (nPatch > 0){
2371                 AliDebug(2, "Patch summary: ");
2372                 AliDebug(2, Form("Number of patches: %d", nPatch));
2373                 AliDebug(2, Form("Level0: [%d]" ,nL0));
2374                 AliDebug(2, Form("Jet:    low[%d], high[%d]" ,nJ2, nJ1));
2375                 AliDebug(2, Form("Gamma:  low[%d], high[%d]" ,nG2, nG1));
2376         }
2377                 
2378 //      if (nPatch > 0){
2379 //              cout <<           Form("Number of patches: %d", nPatch) << endl;
2380 //              cout <<           Form("Level0: [%d]" ,nL0) << endl;
2381 //              cout <<           Form("Jet:    low[%d], high[%d]" ,nJ2, nJ1) << endl;
2382 //              cout <<           Form("Gamma:  low[%d], high[%d]" ,nG2, nG1) << endl;
2383 //      }
2384           
2385         ULong_t triggers(0);
2386         if (nG1>0)
2387                 SETBIT(triggers, kG1);
2388         if (nG2>0)
2389                 SETBIT(triggers, kG2);
2390         if (nJ1>0)
2391                 SETBIT(triggers, kJ1);
2392         if (nJ2>0)
2393                 SETBIT(triggers, kJ2);
2394         if (nL0>0)
2395                 SETBIT(triggers, kL0);
2396         return triggers;
2397 }
2398
2399 //________________________________________________________________________
2400 Bool_t AliConvEventCuts::HasTriggerType(TriggerTypeEMCAL t){
2401         // Check if event has a given trigger type
2402         if(t == kND){
2403                 return fTriggersEMCAL == 0;
2404         }
2405         return TESTBIT(fTriggersEMCAL, int(t));
2406 }
2407
2408
2409 //________________________________________________________________________
2410 TClonesArray *AliConvEventCuts::GetArrayFromEvent(AliVEvent* fInputEvent, const char *name, const char *clname)
2411 {
2412         // Get array from event.
2413
2414         TClonesArray *arr = 0;
2415         TString sname(name);
2416         if (!sname.IsNull()) {
2417                 arr = dynamic_cast<TClonesArray*>(fInputEvent->FindListObject(sname));
2418                 if (!arr) {
2419                 AliWarning(Form("%s: Could not retrieve array with name %s!", GetName(), name)); 
2420                 return 0;
2421                 }
2422         } else {
2423                 return 0;
2424         }
2425
2426         if (!clname)
2427                 return arr;
2428
2429         TString objname(arr->GetClass()->GetName());
2430         TClass cls(objname);
2431         if (!cls.InheritsFrom(clname)) {
2432                 AliWarning(Form("%s: Objects of type %s in %s are not inherited from %s!", 
2433                                                 GetName(), cls.GetName(), name, clname)); 
2434                 return 0;
2435         }
2436         return arr;
2437 }