--- /dev/null
+#include "AliAnalysisTaskTransverseEnergy.h"
+#include "AliAnalysisEtSelectionHandler.h"
+#include "AliAnalysisManager.h"
+#include "AliInputEventHandler.h"
+#include "AliPhysicsSelectionTask.h"
+#include "AliPhysicsSelection.h"
+#include "AliESDCentrality.h"
+#include "AliESDEvent.h"
+#include "AliLog.h"
+#include <iostream>
+
+ClassImp(AliAnalysisTaskTransverseEnergy)
+
+AliAnalysisTaskTransverseEnergy::AliAnalysisTaskTransverseEnergy(const char* name, Bool_t isMc) :
+ AliAnalysisTaskSE(name)
+ ,fESDEvent(0)
+ ,fMCConfigFile("ConfigEtMonteCarlo.C")
+ ,fRecoConfigFile("ConfigEtReconstructed.C")
+ ,fHistEtRecvsEtMC(0)
+ ,fEsdtrackCutsITSTPC(0)
+ ,fEsdtrackCutsTPC(0)
+ ,fEsdtrackCutsITS(0)
+ ,fOutputList(0)
+ ,fPhysSelTaskName("selctionTask")
+ ,fCentSelTaskName("centralityTask")
+ ,fIsMc(isMc)
+ ,fUsingDefaultSelection(true)
+ ,fCurrentRunNumber(-1)
+ ,fSelectionHandler(0)
+{
+ // Constructor
+ LoadPhysicsSelection("physicsSelections.root");
+}
+
+AliAnalysisTaskTransverseEnergy::~AliAnalysisTaskTransverseEnergy()
+{
+ // destructor
+}
+
+Int_t AliAnalysisTaskTransverseEnergy::CheckPhysicsSelection(Int_t runNumber)
+{
+ // Check if the physics selection is valid, if not load a new one
+ if (runNumber == fCurrentRunNumber || fIsMc)
+ {
+ return 0;
+ }
+ else
+ {
+ AliPhysicsSelection *selection = 0;
+ AliPhysicsSelectionTask *physSelTask = dynamic_cast<AliPhysicsSelectionTask*>(AliAnalysisManager::GetAnalysisManager()->GetTasks()->At(0));
+ if (physSelTask)
+ {
+
+ if ((selection = fSelectionHandler->GetPhysicsSelection(runNumber)))
+ {
+ }
+ else if ((selection = fSelectionHandler->GetDefaultPhysicsSelection()))
+ {
+ fUsingDefaultSelection = true;
+ }
+ else if ((selection = new AliPhysicsSelection()))
+ {
+ fUsingDefaultSelection = true;
+ }
+ else
+ {
+ AliError("Something went very wrong, not able to load/create new physics selection");
+ return -1;
+ }
+ }
+ else
+ {
+ AliError("Could not get physics selection task from manager, undefined or no selection will be used");
+ return -1;
+ }
+ AliInfo("Changing the physics selection");
+ // The physics selection task has a bit weird implementation, setting the the physics selection will not update the handler, so we do it manually
+ AliInputEventHandler* handler = dynamic_cast<AliInputEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
+ physSelTask->SetPhysicsSelection(selection);
+ handler->SetEventSelection(selection);
+ fCurrentRunNumber = runNumber;
+
+ }
+
+ return 1;
+}
+
+Bool_t AliAnalysisTaskTransverseEnergy::IsPhysicsSelected() const
+{
+ // See header file for class documentation
+ if(fIsMc) return true;
+ if(!fUsingDefaultSelection) return (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & AliVEvent::kUserDefined);
+ return (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & AliVEvent::kMB);
+}
+
+Int_t AliAnalysisTaskTransverseEnergy::LoadPhysicsSelection(TString name)
+{
+ // See header file for class documentation
+ if(fIsMc) return 0;
+ fSelectionHandler = new AliAnalysisEtSelectionHandler(name);
+ if (!fSelectionHandler) return -1;
+ return 0;
+}
+
+AliESDCentrality* AliAnalysisTaskTransverseEnergy::GetCentralityObject()
+{
+ // See header file for class documentation
+ if (fESDEvent)return fESDEvent->GetCentrality();
+ else return 0;
+}
+
+
--- /dev/null
+#ifndef ALIANALYSISTASKTRANSVERSEENERGY_H
+#define ALIANALYSISTASKTRANSVERSEENERGY_H
+
+#include "AliAnalysisTaskSE.h"
+#include "AliESDtrackCuts.h"
+
+class AliESDCentrality;
+class AliAnalysisEtSelectionHandler;
+
+class AliAnalysisTaskTransverseEnergy : public AliAnalysisTaskSE
+{
+
+public:
+
+ /** Constructor */
+ AliAnalysisTaskTransverseEnergy(const char* name, Bool_t isMc);
+
+ /** Destructro */
+ virtual ~AliAnalysisTaskTransverseEnergy();
+
+ AliESDtrackCuts* GetTPCITSTrackCuts(){return (AliESDtrackCuts*) fOutputList->FindObject("fEsdTrackCuts");}
+ AliESDtrackCuts* GetTPCOnlyTrackCuts(){return (AliESDtrackCuts*) fOutputList->FindObject("fEsdTrackCutsTPCOnly");}
+ AliESDtrackCuts* GetITSTrackCuts(){return (AliESDtrackCuts*) fOutputList->FindObject("fEsdTrackCutsITS");}
+
+ Int_t LoadPhysicsSelection(TString name);
+
+ void SetMcData(Bool_t isMc = true) { fIsMc = isMc; }
+
+protected:
+
+ /** Check if the physics selection is still valid, if not load new */
+ Int_t CheckPhysicsSelection(Int_t runNumber); // check if the current physics selection is valid, if not load new
+
+ /** Check if the event is a physics event */
+ Bool_t IsPhysicsSelected() const;
+
+ /** Get the centrality object */
+ AliESDCentrality* GetCentralityObject();
+
+ /** The ESD event */
+ AliESDEvent *fESDEvent; //The ESD event
+
+ TString fMCConfigFile; // the name of the ConfigFile
+ TString fRecoConfigFile; // the name of the ConfigFile
+
+ TH2F *fHistEtRecvsEtMC; // Rec vs MC histo
+
+ AliESDtrackCuts* fEsdtrackCutsITSTPC; // track cuts ITS&TPC
+ AliESDtrackCuts* fEsdtrackCutsTPC; // track cuts TPC
+ AliESDtrackCuts* fEsdtrackCutsITS; // track cuts ITS
+
+ TList *fOutputList; //output list
+
+ TString fPhysSelTaskName; // If we need to access the physics selection task
+ TString fCentSelTaskName; // If we need to access the centrality selection task
+
+ Bool_t fIsMc; // Are we analysing MC data
+
+ Bool_t fUsingDefaultSelection; // Are we using the default physics selection
+
+private:
+
+ Int_t fCurrentRunNumber; // The current run number
+
+ AliAnalysisEtSelectionHandler* fSelectionHandler; //! Taking care of loading the correct selections
+ AliAnalysisTaskTransverseEnergy();
+ //Declare it private to avoid compilation warning
+ AliAnalysisTaskTransverseEnergy & operator = (const AliAnalysisTaskTransverseEnergy &);//assignment
+ AliAnalysisTaskTransverseEnergy(const AliAnalysisTaskTransverseEnergy &) ; //copy constructor
+
+ ClassDef(AliAnalysisTaskTransverseEnergy, 1)
+};
+
+#endif // ALIANALYSISTASKTRANSVERSEENERGY_H