]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG/EMCAL/AliAnalysisTaskEmcal.cxx
AliAODEvent::GetHeader() returns AliVHeader
[u/mrichter/AliRoot.git] / PWG / EMCAL / AliAnalysisTaskEmcal.cxx
index 06d84cd11aed31b680ccd0f0a70618f43b06820d..46a9cbc0813ba9ae93d6d69f02cb4c7ed49a952c 100644 (file)
@@ -1,8 +1,7 @@
-// $Id: AliAnalysisTaskEmcal.cxx 56756 2012-05-30 05:03:02Z loizides $
 //
 // Emcal base analysis task.
 //
-// Author: S.Aiola
+// Author: S.Aiola, M. Verweij
 
 #include "AliAnalysisTaskEmcal.h"
 
 #include "AliGenPythiaEventHeader.h"
 #include "AliAODMCHeader.h"
 #include "AliMCEvent.h"
+#include "AliAnalysisUtils.h"
+#include "AliEmcalTriggerPatchInfo.h"
+
+#include "AliParticleContainer.h"
+#include "AliClusterContainer.h"
 
 ClassImp(AliAnalysisTaskEmcal)
 
 //________________________________________________________________________
 AliAnalysisTaskEmcal::AliAnalysisTaskEmcal() : 
   AliAnalysisTaskSE("AliAnalysisTaskEmcal"),
-  fAnaType(kTPC),
   fForceBeamType(kNA),
   fGeneralHistograms(kFALSE),
   fInitialized(kFALSE),
   fCreateHisto(kTRUE),
-  fTracksName(),
-  fCaloName(),
   fCaloCellsName(),
   fCaloTriggersName(),
+  fCaloTriggerPatchInfoName(),
   fMinCent(-999),
   fMaxCent(-999),
   fMinVz(-999),
   fMaxVz(-999),
+  fTrackPtCut(0),
+  fMinNTrack(0),
+  fUseAliAnaUtils(kFALSE),
+  fAliAnalysisUtils(0x0),
   fOffTrigger(AliVEvent::kAny),
   fTrigClass(),
+  fTriggerTypeSel(kND),
   fNbins(500),
   fMinBinPt(0),
   fMaxBinPt(250),
-  fClusPtCut(0.15),
-  fTrackPtCut(0.15),
-  fTrackMinEta(-0.9),
-  fTrackMaxEta(0.9),
-  fTrackMinPhi(-10),
-  fTrackMaxPhi(10),
-  fClusTimeCutLow(-10),
-  fClusTimeCutUp(10),
   fMinPtTrackInEmcal(0),
   fEventPlaneVsEmcal(-1),
-  fMinEventPlane(-10),
-  fMaxEventPlane(10),
+  fMinEventPlane(-1e6),
+  fMaxEventPlane(1e6),
   fCentEst("V0M"),
-  fTrackBitMap(0),
-  fClusterBitMap(0),
-  fMCTrackBitMap(0),
-  fMCClusterBitMap(0),
   fIsEmbedded(kFALSE),
   fIsPythia(kFALSE),
   fSelectPtHardBin(-999),
   fMinMCLabel(0),
   fMCLabelShift(0),
   fNcentBins(4),
+  fNeedEmcalGeom(kTRUE),
+  fIsEsd(kFALSE),
   fGeom(0),
   fTracks(0),
   fCaloClusters(0),
   fCaloCells(0),
   fCaloTriggers(0),
+  fTriggerPatchInfo(0),
   fCent(0),
   fCentBin(-1),
   fEPV0(-1.0),
@@ -96,73 +94,78 @@ AliAnalysisTaskEmcal::AliAnalysisTaskEmcal() :
   fPtHard(0),
   fPtHardBin(0),
   fNTrials(0),
+  fXsection(0),
+  fParticleCollArray(),
+  fClusterCollArray(),
+  fMainTriggerPatch(0x0),
+  fTriggers(0),
   fOutput(0),
+  fHistEventCount(0),
   fHistTrialsAfterSel(0),
   fHistEventsAfterSel(0),
+  fHistXsectionAfterSel(0),
   fHistTrials(0),
-  fHistXsection(0),
   fHistEvents(0),
+  fHistXsection(0),
   fHistPtHard(0),
   fHistCentrality(0),
   fHistZVertex(0),
-  fHistEventPlane(0)
+  fHistEventPlane(0),
+  fHistEventRejection(0)
 {
   // Default constructor.
 
   fVertex[0] = 0;
   fVertex[1] = 0;
   fVertex[2] = 0;
+
+  fParticleCollArray.SetOwner(kTRUE);
+  fClusterCollArray.SetOwner(kTRUE);
 }
 
 //________________________________________________________________________
 AliAnalysisTaskEmcal::AliAnalysisTaskEmcal(const char *name, Bool_t histo) : 
   AliAnalysisTaskSE(name),
-  fAnaType(kTPC),
   fForceBeamType(kNA),
   fGeneralHistograms(kFALSE),
   fInitialized(kFALSE),
   fCreateHisto(histo),
-  fTracksName(),
-  fCaloName(),
   fCaloCellsName(),
   fCaloTriggersName(),
+  fCaloTriggerPatchInfoName(),
   fMinCent(-999),
   fMaxCent(-999),
   fMinVz(-999),
   fMaxVz(-999),
+  fTrackPtCut(0),
+  fMinNTrack(0),
+  fUseAliAnaUtils(kFALSE),
+  fAliAnalysisUtils(0x0),
   fOffTrigger(AliVEvent::kAny),
   fTrigClass(),
+  fTriggerTypeSel(kND),
   fNbins(500),
   fMinBinPt(0),
   fMaxBinPt(250),
-  fClusPtCut(0.15),
-  fTrackPtCut(0.15),
-  fTrackMinEta(-0.9),
-  fTrackMaxEta(0.9),
-  fTrackMinPhi(-10),
-  fTrackMaxPhi(10),
-  fClusTimeCutLow(-10),
-  fClusTimeCutUp(10),
   fMinPtTrackInEmcal(0),
   fEventPlaneVsEmcal(-1),
-  fMinEventPlane(-10),
-  fMaxEventPlane(10),
+  fMinEventPlane(-1e6),
+  fMaxEventPlane(1e6),
   fCentEst("V0M"),
-  fTrackBitMap(0),
-  fClusterBitMap(0),
-  fMCTrackBitMap(0),
-  fMCClusterBitMap(0),
   fIsEmbedded(kFALSE),
   fIsPythia(kFALSE),
   fSelectPtHardBin(-999),
   fMinMCLabel(0),
   fMCLabelShift(0),
   fNcentBins(4),
+  fNeedEmcalGeom(kTRUE),
+  fIsEsd(kFALSE),
   fGeom(0),
   fTracks(0),
   fCaloClusters(0),
   fCaloCells(0),
   fCaloTriggers(0),
+  fTriggerPatchInfo(0),
   fCent(0),
   fCentBin(-1),
   fEPV0(-1.0),
@@ -174,16 +177,24 @@ AliAnalysisTaskEmcal::AliAnalysisTaskEmcal(const char *name, Bool_t histo) :
   fPtHard(0),
   fPtHardBin(0),
   fNTrials(0),
+  fXsection(0),
+  fParticleCollArray(),
+  fClusterCollArray(),
+  fMainTriggerPatch(0x0),
+  fTriggers(0),
   fOutput(0),
+  fHistEventCount(0),
   fHistTrialsAfterSel(0),
   fHistEventsAfterSel(0),
+  fHistXsectionAfterSel(0),
   fHistTrials(0),
-  fHistXsection(0),
   fHistEvents(0),
+  fHistXsection(0),
   fHistPtHard(0),
   fHistCentrality(0),
   fHistZVertex(0),
-  fHistEventPlane(0)
+  fHistEventPlane(0),
+  fHistEventRejection(0)
 {
   // Standard constructor.
 
@@ -191,6 +202,9 @@ AliAnalysisTaskEmcal::AliAnalysisTaskEmcal(const char *name, Bool_t histo) :
   fVertex[1] = 0;
   fVertex[2] = 0;
 
+  fParticleCollArray.SetOwner(kTRUE);
+  fClusterCollArray.SetOwner(kTRUE);
+
   if (fCreateHisto) {
     DefineOutput(1, TList::Class()); 
   }
@@ -202,10 +216,72 @@ AliAnalysisTaskEmcal::~AliAnalysisTaskEmcal()
   // Destructor
 }
 
+//________________________________________________________________________
+void AliAnalysisTaskEmcal::SetClusPtCut(Double_t cut, Int_t c)
+{
+  AliClusterContainer *cont = GetClusterContainer(c);
+  if (cont) cont->SetClusPtCut(cut);
+  else AliError(Form("%s in SetClusPtCut(...): container %d not found",GetName(),c));
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskEmcal::SetClusTimeCut(Double_t min, Double_t max, Int_t c)
+{
+  AliClusterContainer *cont = GetClusterContainer(c);
+  if (cont) cont->SetClusTimeCut(min,max);
+  else AliError(Form("%s in SetClusTimeCut(...): container %d not found",GetName(),c));
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskEmcal::SetTrackPtCut(Double_t cut, Int_t c)
+{
+  AliParticleContainer *cont = GetParticleContainer(c);
+  if (cont) cont->SetParticlePtCut(cut);
+  else AliError(Form("%s in SetTrackPtCut(...): container %d not found",GetName(),c));
+
+  fTrackPtCut = cut;
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskEmcal::SetTrackEtaLimits(Double_t min, Double_t max, Int_t c)
+{
+  AliParticleContainer *cont = GetParticleContainer(c);
+  if (cont) cont->SetParticleEtaLimits(min,max);
+  else AliError(Form("%s in SetTrackPtCut(...): container %d not found",GetName(),c));
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskEmcal::SetTrackPhiLimits(Double_t min, Double_t max, Int_t c)
+{
+  AliParticleContainer *cont = GetParticleContainer(c);
+  if (cont) cont->SetParticlePhiLimits(min,max);
+  else AliError(Form("%s in SetTrackPhiLimits(...): container %d not found",GetName(),c));
+}
+
 //________________________________________________________________________
 void AliAnalysisTaskEmcal::UserCreateOutputObjects()
 {
   // Create user output.
+
+  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+  if (mgr) {
+    AliVEventHandler *evhand = mgr->GetInputEventHandler();
+    if (evhand) {
+      if (evhand->InheritsFrom("AliESDInputHandler")) {
+        fIsEsd = kTRUE;
+      }
+      else {
+        fIsEsd = kFALSE;        
+      }
+    }
+    else {
+      AliError("Event handler not found!");
+    }
+  }
+  else {
+    AliError("Analysis manager not found!");
+  }  
+
   if (!fCreateHisto)
     return;
 
@@ -229,22 +305,27 @@ void AliAnalysisTaskEmcal::UserCreateOutputObjects()
     fHistEventsAfterSel->GetXaxis()->SetTitle("p_{T} hard bin");
     fHistEventsAfterSel->GetYaxis()->SetTitle("total events");
     fOutput->Add(fHistEventsAfterSel);
+
+    fHistXsectionAfterSel = new TProfile("fHistXsectionAfterSel", "fHistXsectionAfterSel", 11, 0, 11);
+    fHistXsectionAfterSel->GetXaxis()->SetTitle("p_{T} hard bin");
+    fHistXsectionAfterSel->GetYaxis()->SetTitle("xsection");
+    fOutput->Add(fHistXsectionAfterSel);
     
     fHistTrials = new TH1F("fHistTrials", "fHistTrials", 11, 0, 11);
     fHistTrials->GetXaxis()->SetTitle("p_{T} hard bin");
     fHistTrials->GetYaxis()->SetTitle("trials");
     fOutput->Add(fHistTrials);
 
-    fHistXsection = new TProfile("fHistXsection", "fHistXsection", 11, 0, 11);
-    fHistXsection->GetXaxis()->SetTitle("p_{T} hard bin");
-    fHistXsection->GetYaxis()->SetTitle("xsection");
-    fOutput->Add(fHistXsection);
-
     fHistEvents = new TH1F("fHistEvents", "fHistEvents", 11, 0, 11);
     fHistEvents->GetXaxis()->SetTitle("p_{T} hard bin");
     fHistEvents->GetYaxis()->SetTitle("total events");
     fOutput->Add(fHistEvents);
 
+    fHistXsection = new TProfile("fHistXsection", "fHistXsection", 11, 0, 11);
+    fHistXsection->GetXaxis()->SetTitle("p_{T} hard bin");
+    fHistXsection->GetYaxis()->SetTitle("xsection");
+    fOutput->Add(fHistXsection);
+
     const Int_t ptHardLo[11] = { 0, 5,11,21,36,57, 84,117,152,191,234};
     const Int_t ptHardHi[11] = { 5,11,21,36,57,84,117,152,191,234,1000000};
     
@@ -278,6 +359,28 @@ void AliAnalysisTaskEmcal::UserCreateOutputObjects()
   fHistEventPlane->GetYaxis()->SetTitle("counts");
   fOutput->Add(fHistEventPlane);
 
+  fHistEventRejection = new TH1F("fHistEventRejection","Reasons to reject event",20,0,20);
+  fHistEventRejection->GetXaxis()->SetBinLabel(1,"PhysSel");
+  fHistEventRejection->GetXaxis()->SetBinLabel(2,"trigger");
+  fHistEventRejection->GetXaxis()->SetBinLabel(3,"trigTypeSel");
+  fHistEventRejection->GetXaxis()->SetBinLabel(4,"Cent");
+  fHistEventRejection->GetXaxis()->SetBinLabel(5,"vertex contr.");
+  fHistEventRejection->GetXaxis()->SetBinLabel(6,"Vz");
+  fHistEventRejection->GetXaxis()->SetBinLabel(7,"trackInEmcal");
+  fHistEventRejection->GetXaxis()->SetBinLabel(8,"minNTrack");
+  fHistEventRejection->GetXaxis()->SetBinLabel(9,"VtxSel2013pA");
+  fHistEventRejection->GetXaxis()->SetBinLabel(10,"PileUp");
+  fHistEventRejection->GetXaxis()->SetBinLabel(11,"EvtPlane");
+  fHistEventRejection->GetXaxis()->SetBinLabel(12,"SelPtHardBin");
+  fHistEventRejection->GetYaxis()->SetTitle("counts");
+  fOutput->Add(fHistEventRejection);
+
+  fHistEventCount = new TH1F("fHistEventCount","fHistEventCount",2,0,2);
+  fHistEventCount->GetXaxis()->SetBinLabel(1,"Accepted");
+  fHistEventCount->GetXaxis()->SetBinLabel(2,"Rejected");
+  fHistEventCount->GetYaxis()->SetTitle("counts");
+  fOutput->Add(fHistEventCount);
+
   PostData(1, fOutput);
 }
 
@@ -285,8 +388,9 @@ void AliAnalysisTaskEmcal::UserCreateOutputObjects()
 Bool_t AliAnalysisTaskEmcal::FillGeneralHistograms()
 {
   if (fIsPythia) {
-    fHistEventsAfterSel->SetBinContent(fPtHardBin + 1, fHistEventsAfterSel->GetBinContent(fPtHardBin + 1) + 1);
-    fHistTrialsAfterSel->SetBinContent(fPtHardBin + 1, fHistTrialsAfterSel->GetBinContent(fPtHardBin + 1) + fNTrials);
+    fHistEventsAfterSel->Fill(fPtHardBin, 1);
+    fHistTrialsAfterSel->Fill(fPtHardBin, fNTrials);
+    fHistXsectionAfterSel->Fill(fPtHardBin, fXsection);
     fHistPtHard->Fill(fPtHard);
   }
 
@@ -302,6 +406,8 @@ void AliAnalysisTaskEmcal::UserExec(Option_t *)
 {
   // Main loop, called for each event.
 
+  fMainTriggerPatch = NULL;
+
   if (!fInitialized)
     ExecOnce();
 
@@ -311,8 +417,13 @@ void AliAnalysisTaskEmcal::UserExec(Option_t *)
   if (!RetrieveEventObjects())
     return;
 
-  if (!IsEventSelected()) 
+  if (IsEventSelected()) {
+    if (fGeneralHistograms) fHistEventCount->Fill("Accepted",1);
+  }
+  else {
+    if (fGeneralHistograms) fHistEventCount->Fill("Rejected",1);
     return;
+  }
 
   if (fGeneralHistograms && fCreateHisto) {
     if (!FillGeneralHistograms())
@@ -334,116 +445,37 @@ void AliAnalysisTaskEmcal::UserExec(Option_t *)
 }
 
 //________________________________________________________________________
-Bool_t AliAnalysisTaskEmcal::AcceptCluster(AliVCluster *clus) const
+Bool_t AliAnalysisTaskEmcal::AcceptCluster(AliVCluster *clus, Int_t c) const
 {
   // Return true if cluster is accepted.
 
   if (!clus)
     return kFALSE;
-      
-  if (!clus->IsEMCAL())
-    return kFALSE;
 
-  if (clus->GetLabel() > fMinMCLabel) {
-    if (clus->TestBits(fMCClusterBitMap) != (Int_t)fMCClusterBitMap) {
-      AliDebug(2,"MC Cluster not accepted because of bit map.");
-      return kFALSE;
-    }
-  }
-  else {
-    if (clus->TestBits(fClusterBitMap) != (Int_t)fClusterBitMap) {
-      AliDebug(2,"Cluster not accepted because of bit map.");
-      return kFALSE;
-    }
+  AliClusterContainer *cont = GetClusterContainer(c);
+  if (!cont) {
+    AliError(Form("%s:Container %d not found",GetName(),c));
+    return 0;
   }
 
-  if (clus->GetTOF() > fClusTimeCutUp || clus->GetTOF() < fClusTimeCutLow)
-    return kFALSE;
-
-  TLorentzVector nPart;
-  clus->GetMomentum(nPart, const_cast<Double_t*>(fVertex));
-
-  if (nPart.Et() < fClusPtCut)
-    return kFALSE;
-
-  return kTRUE;
+  return cont->AcceptCluster(clus);
 }
 
 //________________________________________________________________________
-Bool_t AliAnalysisTaskEmcal::AcceptTrack(AliVParticle *track) const
+Bool_t AliAnalysisTaskEmcal::AcceptTrack(AliVParticle *track, Int_t c) const
 {
   // Return true if track is accepted.
 
   if (!track)
     return kFALSE;
 
-  if (TMath::Abs(track->GetLabel()) > fMinMCLabel) {
-    if(track->TestBits(fMCTrackBitMap) != (Int_t)fMCTrackBitMap) {
-      AliDebug(2,"MC Track not accepted because of bit map.");
-      return kFALSE;
-    }
-  }
-  else {
-    if(track->TestBits(fTrackBitMap) != (Int_t)fTrackBitMap) {
-      AliDebug(2,"Track not accepted because of bit map.");
-      return kFALSE;
-    }
-  }
-
-  if (track->Pt() < fTrackPtCut)
-    return kFALSE;
-
-  if (track->Eta() < fTrackMinEta || track->Eta() > fTrackMaxEta || 
-      track->Phi() < fTrackMinPhi || track->Phi() > fTrackMaxPhi)
-    return kFALSE;
-  
-  return kTRUE;
-}
-
-//________________________________________________________________________
-Bool_t AliAnalysisTaskEmcal::AcceptEmcalPart(AliEmcalParticle *part) const
-{
-  // Return true if EMCal particle is accepted.
-
-  if (!part)
-    return kFALSE;
-
-  if (part->IsTrack()) {
-    if (part->IsMC()) { 
-      if (part->TestBits(fMCTrackBitMap) != (Int_t)fMCTrackBitMap)
-       return kFALSE;
-    }
-    else {
-      if (part->TestBits(fTrackBitMap) != (Int_t)fTrackBitMap)
-       return kFALSE;
-    }
-
-    if (part->Pt() < fTrackPtCut)
-      return kFALSE;
-
-    if (part->Eta() < fTrackMinEta || part->Eta() > fTrackMaxEta || 
-       part->Phi() < fTrackMinPhi || part->Phi() > fTrackMaxPhi)
-      return kFALSE;
-  }
-
-  if (part->IsCluster()) {
-    if (part->IsMC(fMinMCLabel)) { 
-      if (part->TestBits(fMCClusterBitMap) != (Int_t)fMCClusterBitMap)
-       return kFALSE;
-    }
-    else {
-      if (part->TestBits(fClusterBitMap) != (Int_t)fClusterBitMap)
-       return kFALSE;
-    }
-
-    if (!part->IsEMCAL())
-      return kFALSE;
-
-    if (part->Pt() < fClusPtCut)
-      return kFALSE;
+  AliParticleContainer *cont = GetParticleContainer(c);
+  if (!cont) {
+    AliError(Form("%s:Container %d not found",GetName(),c));
+    return 0;
   }
 
-  return kTRUE;
+  return cont->AcceptParticle(track);
 }
 
 //________________________________________________________________________
@@ -459,17 +491,16 @@ Bool_t AliAnalysisTaskEmcal::PythiaInfoFromFile(const char* currFile, Float_t &f
   fXsec = 0;
   fTrials = 1;
 
-  if(file.Contains(".zip#")){
+  if (file.Contains(".zip#")) {
     Ssiz_t pos1 = file.Index("root_archive",12,0,TString::kExact);
     Ssiz_t pos = file.Index("#",1,pos1,TString::kExact);
     Ssiz_t pos2 = file.Index(".root",5,TString::kExact);
     file.Replace(pos+1,pos2-pos1,"");
-  }
-  else {
+  } else {
     // not an archive take the basename....
     file.ReplaceAll(gSystem->BaseName(file.Data()),"");
   }
-  Printf("%s",file.Data());
+  AliDebug(1,Form("File name: %s",file.Data()));
 
   // Get the pt hard bin
   TString strPthard(file);
@@ -483,23 +514,24 @@ Bool_t AliAnalysisTaskEmcal::PythiaInfoFromFile(const char* currFile, Float_t &f
   else 
     AliWarning(Form("Could not extract file number from path %s", strPthard.Data()));
 
-  TFile *fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec.root")); // problem that we cannot really test the existance of a file in a archive so we have to lvie with open error message from root
-  if(!fxsec){
+  // problem that we cannot really test the existance of a file in a archive so we have to live with open error message from root
+  TFile *fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec.root")); 
+  
+  if (!fxsec) {
     // next trial fetch the histgram file
     fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec_hists.root"));
-    if(!fxsec){
+    if (!fxsec) {
        // not a severe condition but inciate that we have no information
       return kFALSE;
-    }
-    else{
+    } else {
       // find the tlist we want to be independtent of the name so use the Tkey
       TKey* key = (TKey*)fxsec->GetListOfKeys()->At(0); 
-      if(!key){
+      if (!key) {
        fxsec->Close();
        return kFALSE;
       }
       TList *list = dynamic_cast<TList*>(key->ReadObj());
-      if(!list){
+      if (!list) {
        fxsec->Close();
        return kFALSE;
       }
@@ -507,10 +539,9 @@ Bool_t AliAnalysisTaskEmcal::PythiaInfoFromFile(const char* currFile, Float_t &f
       fTrials  = ((TH1F*)list->FindObject("h1Trials"))->GetBinContent(1);
       fxsec->Close();
     }
-  } // no tree pyxsec.root
-  else {
+  } else { // no tree pyxsec.root
     TTree *xtree = (TTree*)fxsec->Get("Xsection");
-    if(!xtree){
+    if (!xtree) {
       fxsec->Close();
       return kFALSE;
     }
@@ -529,6 +560,8 @@ Bool_t AliAnalysisTaskEmcal::PythiaInfoFromFile(const char* currFile, Float_t &f
 //________________________________________________________________________
 Bool_t AliAnalysisTaskEmcal::UserNotify()
 {
+  // Called when file changes.
+
   if (!fIsPythia || !fGeneralHistograms || !fCreateHisto)
     return kTRUE;
 
@@ -538,9 +571,9 @@ Bool_t AliAnalysisTaskEmcal::UserNotify()
     return kFALSE;
   }
 
-  Float_t xsection = 0;
-  Float_t trials   = 0;
-  Int_t   pthard   = 0;
+  Float_t xsection    = 0;
+  Float_t trials      = 0;
+  Int_t   pthardbin   = 0;
 
   TFile *curfile = tree->GetCurrentFile();
   if (!curfile) {
@@ -549,16 +582,18 @@ Bool_t AliAnalysisTaskEmcal::UserNotify()
   }
 
   TChain *chain = dynamic_cast<TChain*>(tree);
-  if (chain)
-    tree = chain->GetTree();
+  if (chain) tree = chain->GetTree();
 
   Int_t nevents = tree->GetEntriesFast();
 
-  PythiaInfoFromFile(curfile->GetName(), xsection, trials, pthard);
+  PythiaInfoFromFile(curfile->GetName(), xsection, trials, pthardbin);
+
+  // TODO: Workaround
+  if ((pthardbin < 0) || (pthardbin > 10)) pthardbin = 0;
 
-  fHistTrials->Fill(pthard, trials);
-  fHistXsection->Fill(pthard, xsection);
-  fHistEvents->Fill(pthard, nevents);
+  fHistTrials->Fill(pthardbin, trials);
+  fHistXsection->Fill(pthardbin, xsection);
+  fHistEvents->Fill(pthardbin, nevents);
 
   return kTRUE;
 }
@@ -573,45 +608,51 @@ void AliAnalysisTaskEmcal::ExecOnce()
     return;
   }
 
-  fGeom = AliEMCALGeometry::GetInstance();
-  if (!fGeom) {
-    AliError(Form("%s: Can not create geometry", GetName()));
-    return;
+  if (fNeedEmcalGeom) {
+    fGeom = AliEMCALGeometry::GetInstance();
+    if (!fGeom) {
+      AliError(Form("%s: Can not create geometry", GetName()));
+      return;
+    }
   }
 
+  
   if (fEventPlaneVsEmcal >= 0) {
-    Double_t ep = (fGeom->GetArm1PhiMax() + fGeom->GetArm1PhiMin()) / 2 * TMath::DegToRad() + fEventPlaneVsEmcal - TMath::Pi();
-    fMinEventPlane = ep - TMath::Pi() / 4;
-    fMaxEventPlane = ep + TMath::Pi() / 4;
+    if (fGeom) {
+      Double_t ep = (fGeom->GetArm1PhiMax() + fGeom->GetArm1PhiMin()) / 2 * TMath::DegToRad() + fEventPlaneVsEmcal - TMath::Pi();
+      fMinEventPlane = ep - TMath::Pi() / 4;
+      fMaxEventPlane = ep + TMath::Pi() / 4;
+    }
+    else {
+      AliWarning("Could not set event plane limits because EMCal geometry was not loaded!");
+    }
   }
 
-  if (!fCaloName.IsNull() && !fCaloClusters) {
-    fCaloClusters =  dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fCaloName));
-    if (!fCaloClusters) {
-      AliError(Form("%s: Could not retrieve clusters %s!", GetName(), fCaloName.Data())); 
+  //Load all requested track branches - each container knows name already
+  for (Int_t i =0; i<fParticleCollArray.GetEntriesFast(); i++) {
+    AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
+    cont->SetArray(InputEvent());
+  }
+
+  if (fParticleCollArray.GetEntriesFast()>0) {
+    fTracks = GetParticleArray(0);
+    if (!fTracks) {
+      AliError(Form("%s: Could not retrieve first track branch!", GetName()));
       return;
-    } else {
-      TClass *cl = fCaloClusters->GetClass();
-      if (!cl->GetBaseClass("AliVCluster") && !cl->GetBaseClass("AliEmcalParticle")) {
-       AliError(Form("%s: Collection %s does not contain AliVCluster nor AliEmcalParticle objects!", GetName(), fCaloName.Data())); 
-       fCaloClusters = 0;
-       return;
-      }
     }
   }
 
-  if (!fTracksName.IsNull() && !fTracks) {
-    fTracks = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTracksName));
-    if (!fTracks) {
-      AliError(Form("%s: Could not retrieve tracks %s!", GetName(), fTracksName.Data())); 
+  //Load all requested cluster branches - each container knows name already
+  for (Int_t i =0; i<fClusterCollArray.GetEntriesFast(); i++) {
+    AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
+    cont->SetArray(InputEvent());
+  }
+
+  if (fClusterCollArray.GetEntriesFast()>0) {
+    fCaloClusters = GetClusterArray(0);
+    if (!fCaloClusters) {
+      AliError(Form("%s: Could not retrieve first cluster branch!", GetName()));
       return;
-    } else {
-      TClass *cl = fTracks->GetClass();
-      if (!cl->GetBaseClass("AliVParticle") && !cl->GetBaseClass("AliEmcalParticle")) {
-       AliError(Form("%s: Collection %s does not contain AliVParticle nor AliEmcalParticle objects!", GetName(), fTracksName.Data())); 
-       fTracks = 0;
-       return;
-      }
     }
   }
 
@@ -631,6 +672,15 @@ void AliAnalysisTaskEmcal::ExecOnce()
     }
   }
 
+  if (!fCaloTriggerPatchInfoName.IsNull() && !fTriggerPatchInfo) {
+    fTriggerPatchInfo = GetArrayFromEvent(fCaloTriggerPatchInfoName.Data(),"AliEmcalTriggerPatchInfo");
+    if (!fTriggerPatchInfo) {
+      AliError(Form("%s: Could not retrieve calo trigger patch info %s!", GetName(), fCaloTriggerPatchInfoName.Data())); 
+      return;
+    }
+
+  }
+
   fInitialized = kTRUE;
 }
 
@@ -658,13 +708,10 @@ AliAnalysisTaskEmcal::BeamType AliAnalysisTaskEmcal::GetBeamType()
   } else {
     Int_t runNumber = InputEvent()->GetRunNumber();
     if ((runNumber >= 136851 && runNumber <= 139517) ||  // LHC10h
-       (runNumber >= 166529 && runNumber <= 170593))    // LHC11h
-    { 
+       (runNumber >= 166529 && runNumber <= 170593)) {  // LHC11h
       return kAA;
-    } 
-    else if ((runNumber>=188365 && runNumber <= 188366) || // LHC12g
-            (runNumber >= 195344 && runNumber <= 196608))  // LHC13b-f
-    {
+    } else if ((runNumber>=188365 && runNumber <= 188366) ||   // LHC12g
+              (runNumber >= 195344 && runNumber <= 196608)) { // LHC13b-f
       return kpA;
     } else {
       return kpp;
@@ -672,6 +719,56 @@ AliAnalysisTaskEmcal::BeamType AliAnalysisTaskEmcal::GetBeamType()
   }  
 }
 
+//________________________________________________________________________
+ULong_t AliAnalysisTaskEmcal::GetTriggerList()
+{
+  if (!fTriggerPatchInfo)
+    return 0;
+
+  //number of patches in event
+  Int_t nPatch = fTriggerPatchInfo->GetEntries();
+
+  //loop over patches to define trigger type of event
+  Int_t nG1 = 0;
+  Int_t nG2 = 0;
+  Int_t nJ1 = 0;
+  Int_t nJ2 = 0;
+  AliEmcalTriggerPatchInfo *patch;
+  for (Int_t iPatch = 0; iPatch < nPatch; iPatch++) {
+    patch = (AliEmcalTriggerPatchInfo*)fTriggerPatchInfo->At( iPatch );
+    if (patch->IsGammaHigh()) nG1++;
+    if (patch->IsGammaLow())  nG2++;
+    if (patch->IsJetHigh()) nJ1++;
+    if (patch->IsJetLow())  nJ2++;
+  }
+
+  AliDebug(2, "Patch summary: ");
+  AliDebug(2, Form("Number of patches: %d", nPatch));
+  AliDebug(2, Form("Jet:   low[%d], high[%d]" ,nJ2, nJ1));
+  AliDebug(2, Form("Gamma: low[%d], high[%d]" ,nG2, nG1));
+
+  ULong_t triggers(0);
+  if (nG1>0)
+    SETBIT(triggers, kG1);
+  if (nG2>0)
+    SETBIT(triggers, kG2);
+  if (nJ1>0)
+    SETBIT(triggers, kJ1);
+  if (nJ2>0)
+    SETBIT(triggers, kJ2);
+  return triggers;
+}
+
+//________________________________________________________________________
+Bool_t AliAnalysisTaskEmcal::HasTriggerType(TriggerType t)
+{
+  // Check if event has a given trigger type
+  if(t == kND){
+    return fTriggers == 0;
+  }
+  return TESTBIT(fTriggers, int(t));
+}
+
 //________________________________________________________________________
 Bool_t AliAnalysisTaskEmcal::IsEventSelected()
 {
@@ -685,11 +782,13 @@ Bool_t AliAnalysisTaskEmcal::IsEventSelected()
     } else {
       const AliAODEvent *aev = dynamic_cast<const AliAODEvent*>(InputEvent());
       if (aev) {
-        res = aev->GetHeader()->GetOfflineTrigger();
+        res = ((AliVAODHeader*)aev->GetHeader())->GetOfflineTrigger();
       }
     }
-    if ((res & fOffTrigger) == 0)
+    if ((res & fOffTrigger) == 0) {
+      if (fGeneralHistograms) fHistEventRejection->Fill("PhysSel",1);
       return kFALSE;
+    }
   }
 
   if (!fTrigClass.IsNull()) {
@@ -703,11 +802,15 @@ Bool_t AliAnalysisTaskEmcal::IsEventSelected()
         fired = aev->GetFiredTriggerClasses();
       }
     }
-    if (!fired.Contains("-B-"))
+    if (!fired.Contains("-B-")) {
+      if (fGeneralHistograms) fHistEventRejection->Fill("trigger",1);
       return kFALSE;
+    }
     TObjArray *arr = fTrigClass.Tokenize("|");
-    if (!arr)
+    if (!arr) {
+      if (fGeneralHistograms) fHistEventRejection->Fill("trigger",1);
       return kFALSE;
+    }
     Bool_t match = 0;
     for (Int_t i=0;i<arr->GetEntriesFast();++i) {
       TObject *obj = arr->At(i);
@@ -719,55 +822,118 @@ Bool_t AliAnalysisTaskEmcal::IsEventSelected()
       }
     }
     delete arr;
-    if (!match)
+    if (!match) {
+      if (fGeneralHistograms) fHistEventRejection->Fill("trigger",1);
       return kFALSE;
+    }
+  }
+
+  if (fTriggerTypeSel != kND) {
+    if (!HasTriggerType(fTriggerTypeSel)) {
+      if (fGeneralHistograms) fHistEventRejection->Fill("trigTypeSel",1);
+      return kFALSE;
+    }
   }
 
   if ((fMinCent != -999) && (fMaxCent != -999)) {
-    if (fCent<fMinCent)
+    if (fCent<fMinCent || fCent>fMaxCent) {
+      if (fGeneralHistograms) fHistEventRejection->Fill("Cent",1);
       return kFALSE;
-    if (fCent>fMaxCent)
+    }
+  }
+
+  if (fUseAliAnaUtils) {
+    if (!fAliAnalysisUtils)
+      fAliAnalysisUtils = new AliAnalysisUtils();
+    fAliAnalysisUtils->SetMinVtxContr(2);
+    fAliAnalysisUtils->SetMaxVtxZ(999);
+    if(fMinVz<-10.) fMinVz = -10.; 
+    if(fMinVz>10.)  fMaxVz = 10.;
+
+    if (!fAliAnalysisUtils->IsVertexSelected2013pA(InputEvent())) {
+      if (fGeneralHistograms) fHistEventRejection->Fill("VtxSel2013pA",1);
       return kFALSE;
+    }
+
+    if (fAliAnalysisUtils->IsPileUpEvent(InputEvent())) {
+      if (fGeneralHistograms) fHistEventRejection->Fill("PileUp",1);
+      return kFALSE;
+    }
   }
 
   if ((fMinVz != -999) && (fMaxVz != -999)) {
-    if (fNVertCont == 0 )
+    if (fNVertCont == 0 ) {
+      if (fGeneralHistograms) fHistEventRejection->Fill("vertex contr.",1);
       return kFALSE;
+    }
     Double_t vz = fVertex[2];
-    if (vz<fMinVz)
-      return kFALSE;
-    if (vz>fMaxVz)
+    if (vz<fMinVz || vz>fMaxVz) {
+      if (fGeneralHistograms) fHistEventRejection->Fill("Vz",1);
       return kFALSE;
+    }
   }
 
-  if (fMinPtTrackInEmcal > 0 && fTracks && fGeom) {
+  if (fMinPtTrackInEmcal > 0 && fGeom) {
     Bool_t trackInEmcalOk = kFALSE;
-    Int_t ntracks = fTracks->GetEntries();
+    Int_t ntracks = GetNParticles(0);
     for (Int_t i = 0; i < ntracks; i++) {
-      AliVTrack *track = static_cast<AliVTrack*>(fTracks->At(i));
-      if (!AcceptTrack(track))
+      AliVParticle *track = GetAcceptParticleFromArray(i,0);
+      if (!track)
        continue;
-      if (track->Eta() < fGeom->GetArm1EtaMin() || track->Eta() > fGeom->GetArm1EtaMax() ||
-         track->Phi() < fGeom->GetArm1PhiMin() * TMath::DegToRad() || track->Phi() > fGeom->GetArm1PhiMax() * TMath::DegToRad())
+
+      Double_t phiMin = fGeom->GetArm1PhiMin() * TMath::DegToRad();
+      Double_t phiMax = fGeom->GetArm1PhiMax() * TMath::DegToRad();
+      Int_t runNumber = InputEvent()->GetRunNumber();
+      if (runNumber>=177295 && runNumber<=197470) { //small SM masked in 2012 and 2013
+       phiMin = 1.4;   
+       phiMax = TMath::Pi();
+      }
+
+      if (track->Eta() < fGeom->GetArm1EtaMin() || track->Eta() > fGeom->GetArm1EtaMax() || track->Phi() < phiMin || track->Phi() > phiMax)
        continue;
       if (track->Pt() > fMinPtTrackInEmcal) {
        trackInEmcalOk = kTRUE;
        break;
       }
     }
-    if (!trackInEmcalOk)
+    if (!trackInEmcalOk) {
+      if (fGeneralHistograms) fHistEventRejection->Fill("trackInEmcal",1);
       return kFALSE;
+    }
   }
 
+  if (fMinNTrack > 0) {
+    Int_t nTracksAcc = 0;
+    Int_t ntracks = GetNParticles(0);
+    for (Int_t i = 0; i < ntracks; i++) {
+      AliVParticle *track = GetAcceptParticleFromArray(i,0);
+      if (!track)
+       continue;
+      if (track->Pt() > fTrackPtCut) {
+       nTracksAcc++;
+       if (nTracksAcc>=fMinNTrack)
+         break;
+      }
+    }
+    if (nTracksAcc<fMinNTrack) {
+      if (fGeneralHistograms) fHistEventRejection->Fill("minNTrack",1);
+      return kFALSE;
+    }
+  }
 
   if (!(fEPV0 > fMinEventPlane && fEPV0 <= fMaxEventPlane) &&
       !(fEPV0 + TMath::Pi() > fMinEventPlane && fEPV0 + TMath::Pi() <= fMaxEventPlane) &&
       !(fEPV0 - TMath::Pi() > fMinEventPlane && fEPV0 - TMath::Pi() <= fMaxEventPlane)) 
-    return kFALSE;
-
-  if (fSelectPtHardBin != -999 && fSelectPtHardBin != fPtHardBin) 
-    return kFALSE;
+    {
+      if (fGeneralHistograms) fHistEventRejection->Fill("EvtPlane",1);
+      return kFALSE;
+    }
 
+  if (fSelectPtHardBin != -999 && fSelectPtHardBin != fPtHardBin)  {
+      if (fGeneralHistograms) fHistEventRejection->Fill("SelPtHardBin",1);
+      return kFALSE;
+    }
+  
   return kTRUE;
 }
 
@@ -822,8 +988,8 @@ Bool_t AliAnalysisTaskEmcal::RetrieveEventObjects()
   if (fBeamType == kAA || fBeamType == kpA ) {
     AliCentrality *aliCent = InputEvent()->GetCentrality();
     if (aliCent) {
-      fCent = aliCent->GetCentralityPercentile(fCentEst.Data()); 
-      if(fNcentBins==4) {
+      fCent = aliCent->GetCentralityPercentile(fCentEst.Data());
+      if (fNcentBins==4) {
        if      (fCent >=  0 && fCent <   10) fCentBin = 0;
        else if (fCent >= 10 && fCent <   30) fCentBin = 1;
        else if (fCent >= 30 && fCent <   50) fCentBin = 2;
@@ -832,18 +998,20 @@ Bool_t AliAnalysisTaskEmcal::RetrieveEventObjects()
          AliWarning(Form("%s: Negative centrality: %f. Assuming 99", GetName(), fCent));
          fCentBin = fNcentBins-1;
        }
-      }
-      else {
+      } else {
        Double_t centWidth = (fMaxCent-fMinCent)/(Double_t)fNcentBins;
-       fCentBin = TMath::FloorNint(fCent/centWidth);
-       if(fCentBin>=fNcentBins) {
+       if(centWidth>0.)
+         fCentBin = TMath::FloorNint(fCent/centWidth);
+       else 
+         fCentBin = 0;
+       if (fCentBin>=fNcentBins) {
          AliWarning(Form("%s: fCentBin too large: cent = %f fCentBin = %d. Assuming 99", GetName(),fCent,fCentBin));
          fCentBin = fNcentBins-1;
        }
       }
     } else {
       AliWarning(Form("%s: Could not retrieve centrality information! Assuming 99", GetName()));
-      fCentBin = 3;
+      fCentBin = fNcentBins-1;
     }
     AliEventplane *aliEP = InputEvent()->GetEventplane();
     if (aliEP) {
@@ -867,7 +1035,7 @@ Bool_t AliAnalysisTaskEmcal::RetrieveEventObjects()
        AliAODMCHeader* aodMCH = dynamic_cast<AliAODMCHeader*>(InputEvent()->FindListObject(AliAODMCHeader::StdBranchName()));
 
        if (aodMCH) {
-         for(UInt_t i = 0;i<aodMCH->GetNCocktailHeaders();i++) {
+         for (UInt_t i = 0;i<aodMCH->GetNCocktailHeaders();i++) {
            fPythiaHeader = dynamic_cast<AliGenPythiaEventHeader*>(aodMCH->GetCocktailHeader(i));
            if (fPythiaHeader) break;
          }
@@ -877,17 +1045,279 @@ Bool_t AliAnalysisTaskEmcal::RetrieveEventObjects()
 
     if (fPythiaHeader) {
       fPtHard = fPythiaHeader->GetPtHard();
-    
+
       const Int_t ptHardLo[11] = { 0, 5,11,21,36,57, 84,117,152,191,234};
       const Int_t ptHardHi[11] = { 5,11,21,36,57,84,117,152,191,234,1000000};
       for (fPtHardBin = 0; fPtHardBin < 11; fPtHardBin++) {
        if (fPtHard >= ptHardLo[fPtHardBin] && fPtHard < ptHardHi[fPtHardBin])
          break;
       }
-    
+
+      fXsection = fPythiaHeader->GetXsection();
       fNTrials = fPythiaHeader->Trials();
     }
   }
 
+  fTriggers = GetTriggerList();
+
   return kTRUE;
 }
+
+//________________________________________________________________________
+AliParticleContainer* AliAnalysisTaskEmcal::AddParticleContainer(const char *n) 
+{
+  // Add particle container
+  // will be called in AddTask macro
+
+  TString tmp = TString(n);
+  if (tmp.IsNull()) return 0;
+
+  AliParticleContainer *cont = 0x0;
+  cont = new AliParticleContainer();
+  cont->SetArrayName(n);
+  TString contName = cont->GetArrayName();
+  fParticleCollArray.Add(cont);
+
+  return cont;
+}
+
+//________________________________________________________________________
+AliClusterContainer* AliAnalysisTaskEmcal::AddClusterContainer(const char *n) 
+{
+  // Add cluster container
+  // will be called in AddTask macro
+
+  TString tmp = TString(n);
+  if (tmp.IsNull()) return 0;
+
+  AliClusterContainer *cont = 0x0;
+  cont = new AliClusterContainer();
+  cont->SetArrayName(n);
+
+  fClusterCollArray.Add(cont);
+
+  return cont;
+}
+
+//________________________________________________________________________
+AliParticleContainer* AliAnalysisTaskEmcal::GetParticleContainer(Int_t i) const 
+{
+  // Get i^th particle container
+
+  if (i<0 || i>fParticleCollArray.GetEntriesFast()) return 0;
+  AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
+  return cont;
+}
+
+//________________________________________________________________________
+AliClusterContainer* AliAnalysisTaskEmcal::GetClusterContainer(Int_t i) const 
+{
+  // Get i^th cluster container
+
+  if (i<0 || i>fClusterCollArray.GetEntriesFast()) return 0;
+  AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.At(i));
+  return cont;
+}
+
+//________________________________________________________________________
+AliParticleContainer* AliAnalysisTaskEmcal::GetParticleContainer(const char *name) const 
+{
+  // Get particle container with name
+
+  AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.FindObject(name));
+  return cont;
+}
+
+//________________________________________________________________________
+AliClusterContainer* AliAnalysisTaskEmcal::GetClusterContainer(const char *name) const 
+{
+  // Get cluster container with name
+
+  AliClusterContainer *cont = static_cast<AliClusterContainer*>(fClusterCollArray.FindObject(name));
+  return cont;
+}
+
+//________________________________________________________________________
+TClonesArray* AliAnalysisTaskEmcal::GetParticleArray(Int_t i) const 
+{
+  // Get i^th TClonesArray with AliVParticle
+
+  AliParticleContainer *cont = GetParticleContainer(i);
+  if (!cont) {
+    AliError(Form("%s: Particle container %d not found",GetName(),i));
+    return 0;
+  }
+  TString contName = cont->GetArrayName();
+  return cont->GetArray();
+}
+
+//________________________________________________________________________
+TClonesArray* AliAnalysisTaskEmcal::GetClusterArray(Int_t i) const 
+{
+  // Get i^th TClonesArray with AliVCluster
+
+  AliClusterContainer *cont = GetClusterContainer(i);
+  if (!cont) {
+    AliError(Form("%s:Cluster container %d not found",GetName(),i));
+    return 0;
+  }
+  return cont->GetArray();
+}
+
+//________________________________________________________________________
+AliVParticle* AliAnalysisTaskEmcal::GetAcceptParticleFromArray(Int_t p, Int_t c) const 
+{
+  // Get particle p if accepted from  container c
+  // If particle not accepted return 0
+
+  AliParticleContainer *cont = GetParticleContainer(c);
+  if (!cont) {
+    AliError(Form("%s: Particle container %d not found",GetName(),c));
+    return 0;
+  }
+  AliVParticle *vp = cont->GetAcceptParticle(p);
+
+  return vp;
+}
+
+//________________________________________________________________________
+AliVCluster* AliAnalysisTaskEmcal::GetAcceptClusterFromArray(Int_t cl, Int_t c) const 
+{
+  // Get particle p if accepted from  container c
+  // If particle not accepted return 0
+
+  AliClusterContainer *cont = GetClusterContainer(c);
+  if (!cont) {
+    AliError(Form("%s: Cluster container %d not found",GetName(),c));
+    return 0;
+  }
+  AliVCluster *vc = cont->GetAcceptCluster(cl);
+
+  return vc;
+}
+
+//________________________________________________________________________
+Int_t AliAnalysisTaskEmcal::GetNParticles(Int_t i) const 
+{
+  // Get number of entries in particle array i
+
+  AliParticleContainer *cont = GetParticleContainer(i);
+  if (!cont) {
+    AliError(Form("%s: Particle container %d not found",GetName(),i));
+    return 0;
+  }
+  return cont->GetNEntries();
+}
+
+//________________________________________________________________________
+Int_t AliAnalysisTaskEmcal::GetNClusters(Int_t i) const 
+{
+  // Get number of entries in cluster array i
+
+  AliClusterContainer *cont = GetClusterContainer(i);
+  if (!cont) {
+    AliError(Form("%s: Cluster container %d not found",GetName(),i));
+    return 0;
+  }
+  return cont->GetNEntries();
+}
+
+//________________________________________________________________________
+AliEmcalTriggerPatchInfo* AliAnalysisTaskEmcal::GetMainTriggerPatch() 
+{
+  //get main trigger match; if not known yet, look for it and cache
+
+  if (fMainTriggerPatch) 
+    return fMainTriggerPatch;
+
+  if (!fTriggerPatchInfo) {
+    AliError(Form("%s: fTriggerPatchInfo not available",GetName()));
+    return 0;
+  }
+
+  //number of patches in event
+  Int_t nPatch = fTriggerPatchInfo->GetEntries();
+
+  //extract main trigger patch
+  AliEmcalTriggerPatchInfo *patch;
+  for (Int_t iPatch = 0; iPatch < nPatch; iPatch++) {
+    
+    patch = (AliEmcalTriggerPatchInfo*)fTriggerPatchInfo->At( iPatch );
+    if (patch->IsMainTrigger()) {
+      fMainTriggerPatch = patch;
+      break;
+    }
+  }
+
+  return fMainTriggerPatch;
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskEmcal::AddObjectToEvent(TObject *obj)
+{
+  // Add object to event
+
+  if (!(InputEvent()->FindListObject(obj->GetName()))) {
+    InputEvent()->AddObject(obj);
+  } else {
+    AliFatal(Form("%s: Container with name %s already present. Aborting", GetName(), obj->GetName()));
+  }
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskEmcal::GenerateFixedBinArray(Int_t n, Double_t min, Double_t max, Double_t* array) const
+{
+  Double_t binWidth = (max-min)/n;
+  array[0] = min;
+  for (Int_t i = 1; i <= n; i++) {
+    array[i] = array[i-1]+binWidth;
+  }
+}
+
+//________________________________________________________________________
+Double_t* AliAnalysisTaskEmcal::GenerateFixedBinArray(Int_t n, Double_t min, Double_t max) const
+{
+  Double_t *array = new Double_t[n+1];
+
+  GenerateFixedBinArray(n, min, max, array);
+
+  return array;
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskEmcal::SetRejectionReasonLabels(TAxis* axis)
+{
+  axis->SetBinLabel(1,  "NullObject");
+  axis->SetBinLabel(2,  "Pt");
+  axis->SetBinLabel(3,  "Acceptance");
+  axis->SetBinLabel(4,  "BitMap");
+  axis->SetBinLabel(5,  "Bit4");
+  axis->SetBinLabel(6,  "Bit5");
+  axis->SetBinLabel(7,  "Bit6");
+  axis->SetBinLabel(8,  "Bit7");
+  axis->SetBinLabel(9,  "MCFlag");
+  axis->SetBinLabel(10, "MCGenerator");
+  axis->SetBinLabel(11, "ChargeCut");
+  axis->SetBinLabel(12, "Bit11");
+  axis->SetBinLabel(13, "Bit12");
+  axis->SetBinLabel(14, "IsEMCal");
+  axis->SetBinLabel(15, "Time");
+  axis->SetBinLabel(16, "Energy");
+  axis->SetBinLabel(17, "Bit16");
+  axis->SetBinLabel(18, "Bit17");
+  axis->SetBinLabel(19, "Area");
+  axis->SetBinLabel(20, "AreaEmc");
+  axis->SetBinLabel(21, "ZLeadingCh");
+  axis->SetBinLabel(22, "ZLeadingEmc");
+  axis->SetBinLabel(23, "NEF");
+  axis->SetBinLabel(24, "MinLeadPt");
+  axis->SetBinLabel(25, "MaxTrackPt");
+  axis->SetBinLabel(26, "MaxClusterPt");
+  axis->SetBinLabel(27, "Flavour");
+  axis->SetBinLabel(28, "TagStatus");
+  axis->SetBinLabel(29, "Bit28");
+  axis->SetBinLabel(30, "Bit29");
+  axis->SetBinLabel(31, "Bit30");
+  axis->SetBinLabel(32, "Bit31");
+}