improvements in the base class (S.Aiola)
authorloizides <loizides@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 3 Sep 2012 07:15:54 +0000 (07:15 +0000)
committerloizides <loizides@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 3 Sep 2012 07:15:54 +0000 (07:15 +0000)
PWG/EMCAL/AliAnalysisTaskEmcal.cxx
PWG/EMCAL/AliAnalysisTaskEmcal.h

index da5addb..7de45bf 100644 (file)
@@ -10,6 +10,7 @@
 #include <TClonesArray.h>
 #include <TList.h>
 #include <TObject.h>
+#include <TH1F.h>
 
 #include "AliAODEvent.h"
 #include "AliAnalysisManager.h"
@@ -31,6 +32,8 @@ ClassImp(AliAnalysisTaskEmcal)
 AliAnalysisTaskEmcal::AliAnalysisTaskEmcal() : 
   AliAnalysisTaskSE("AliAnalysisTaskEmcal"),
   fAnaType(kTPC),
+  fForceBeamType(kNA),
+  fGeneralHistograms(kFALSE),
   fInitialized(kFALSE),
   fCreateHisto(kTRUE),
   fTracksName(),
@@ -46,12 +49,13 @@ AliAnalysisTaskEmcal::AliAnalysisTaskEmcal() :
   fMaxBinPt(250),
   fClusPtCut(0.15),
   fTrackPtCut(0.15),
-  fMinTrackEta(-0.9),
-  fMaxTrackEta(0.9),
-  fMinTrackPhi(-10),
-  fMaxTrackPhi(10),
+  fTrackMinEta(-0.9),
+  fTrackMaxEta(0.9),
+  fTrackMinPhi(-10),
+  fTrackMaxPhi(10),
   fClusTimeCutLow(-10),
   fClusTimeCutUp(10),
+  fGeom(0),
   fTracks(0),
   fCaloClusters(0),
   fCent(0),
@@ -74,6 +78,8 @@ AliAnalysisTaskEmcal::AliAnalysisTaskEmcal() :
 AliAnalysisTaskEmcal::AliAnalysisTaskEmcal(const char *name, Bool_t histo) : 
   AliAnalysisTaskSE(name),
   fAnaType(kTPC),
+  fForceBeamType(kNA),
+  fGeneralHistograms(kFALSE),
   fInitialized(kFALSE),
   fCreateHisto(histo),
   fTracksName(),
@@ -89,12 +95,13 @@ AliAnalysisTaskEmcal::AliAnalysisTaskEmcal(const char *name, Bool_t histo) :
   fMaxBinPt(250),
   fClusPtCut(0.15),
   fTrackPtCut(0.15),
-  fMinTrackEta(-0.9),
-  fMaxTrackEta(0.9),
-  fMinTrackPhi(-10),
-  fMaxTrackPhi(10),
+  fTrackMinEta(-0.9),
+  fTrackMaxEta(0.9),
+  fTrackMinPhi(-10),
+  fTrackMaxPhi(10),
   fClusTimeCutLow(-10),
   fClusTimeCutUp(10),
+  fGeom(0),
   fTracks(0),
   fCaloClusters(0),
   fCent(0),
@@ -124,6 +131,42 @@ AliAnalysisTaskEmcal::~AliAnalysisTaskEmcal()
 }
 
 //________________________________________________________________________
+void AliAnalysisTaskEmcal::UserCreateOutputObjects()
+{
+  // Create user output.
+  if (!fCreateHisto)
+    return;
+
+  OpenFile(1);
+  fOutput = new TList();
+  fOutput->SetOwner();
+
+  if (!fGeneralHistograms)
+    return;
+
+  fHistCentrality = new TH1F("fHistCentrality","Event centrality distribution", 200, 0, 100);
+  fHistCentrality->GetXaxis()->SetTitle("Centrality (%)");
+  fHistCentrality->GetYaxis()->SetTitle("counts");
+  fOutput->Add(fHistCentrality);
+
+  fHistZVertex = new TH1F("fHistZVertex","Z vertex position", 60, -30, 30);
+  fHistZVertex->GetXaxis()->SetTitle("z");
+  fHistZVertex->GetYaxis()->SetTitle("counts");
+  fOutput->Add(fHistZVertex);
+
+  PostData(1, fOutput);
+}
+
+//________________________________________________________________________
+Bool_t AliAnalysisTaskEmcal::FillGeneralHistograms()
+{
+  fHistCentrality->Fill(fCent);
+  fHistZVertex->Fill(fVertex[2]);
+
+  return kTRUE;
+}
+
+//________________________________________________________________________
 void AliAnalysisTaskEmcal::UserExec(Option_t *) 
 {
   // Main loop, called for each event.
@@ -140,11 +183,18 @@ void AliAnalysisTaskEmcal::UserExec(Option_t *)
   if (!IsEventSelected()) 
     return;
 
+  if (fGeneralHistograms && fCreateHisto) {
+    if (!FillGeneralHistograms())
+      return;
+  }
+
   if (!Run())
     return;
 
-  if (!FillHistograms())
-    return;
+  if (fCreateHisto) {
+    if (!FillHistograms())
+      return;
+  }
     
   if (fCreateHisto && fOutput) {
     // information for this iteration of the UserExec in the container
@@ -179,43 +229,54 @@ Bool_t AliAnalysisTaskEmcal::AcceptCluster(AliVCluster *clus, Bool_t acceptMC) c
 }
 
 //________________________________________________________________________
-Bool_t AliAnalysisTaskEmcal::AcceptEmcalPart(AliEmcalParticle *part, Bool_t acceptMC) const
+Bool_t AliAnalysisTaskEmcal::AcceptTrack(AliVTrack *track, Bool_t acceptMC) const
 {
-  // Return true if EMCal particle is accepted.
+  // Return true if track is accepted.
 
-  if (!part)
+  if (!track)
     return kFALSE;
 
-  if (fAnaType == kEMCAL && !part->IsEMCAL())
+  if (!acceptMC && track->GetLabel() == 100)
     return kFALSE;
 
-  if ((part->IsTrack() && part->Pt() < fTrackPtCut) || (part->IsCluster() && part->Pt() < fClusPtCut))
+  if (track->Pt() < fTrackPtCut)
     return kFALSE;
 
-  if (!acceptMC && part->IsMC())
+  if (track->Eta() < fTrackMinEta || track->Eta() > fTrackMaxEta || 
+      track->Phi() < fTrackMinPhi || track->Phi() > fTrackMaxPhi)
     return kFALSE;
-
+  
   return kTRUE;
 }
 
 //________________________________________________________________________
-Bool_t AliAnalysisTaskEmcal::AcceptTrack(AliVTrack *track, Bool_t acceptMC) const
+Bool_t AliAnalysisTaskEmcal::AcceptEmcalPart(AliEmcalParticle *part, Bool_t acceptMC) const
 {
-  // Return true if track is accepted.
+  // Return true if EMCal particle is accepted.
 
-  if (!track)
+  if (!part)
     return kFALSE;
 
-  if (!acceptMC && track->GetLabel() == 100)
-    return kFALSE;
+  if (part->IsTrack()) { 
+    if (part->Pt() < fTrackPtCut)
+      return kFALSE;
 
-  if (track->Pt() < fTrackPtCut)
-    return kFALSE;
+    if (part->Eta() < fTrackMinEta || part->Eta() > fTrackMaxEta || 
+       part->Phi() < fTrackMinPhi || part->Phi() > fTrackMaxPhi)
+      return kFALSE;
+  }
+
+  if (part->IsCluster()) {
+    if (!part->IsEMCAL())
+      return kFALSE;
 
-  if (track->Eta() < fMinTrackEta || track->Eta() > fMaxTrackEta || 
-      track->Phi() < fMinTrackPhi || track->Phi() > fMaxTrackPhi)
+    if (part->Pt() < fClusPtCut)
+      return kFALSE;
+  }
+
+  if (!acceptMC && part->IsMC())
     return kFALSE;
-  
+
   return kTRUE;
 }
 
@@ -229,7 +290,11 @@ void AliAnalysisTaskEmcal::ExecOnce()
     return;
   }
 
-  if (!fCaloName.IsNull() && (fAnaType == kEMCAL || fAnaType == kEMCALOnly) && !fCaloClusters) {
+  fGeom = AliEMCALGeometry::GetInstance();
+  if (!fGeom) 
+    AliWarning(Form("%s: Can not create geometry", GetName()));
+
+  if (!fCaloName.IsNull() && !fCaloClusters) {
     fCaloClusters =  dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fCaloName));
     if (!fCaloClusters) {
       AliError(Form("%s: Could not retrieve clusters %s!", GetName(), fCaloName.Data())); 
@@ -244,7 +309,7 @@ void AliAnalysisTaskEmcal::ExecOnce()
     }
   }
 
-  if (!fTracksName.IsNull() && fAnaType != kEMCALOnly && !fTracks) {
+  if (!fTracksName.IsNull() && !fTracks) {
     fTracks = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTracksName));
     if (!fTracks) {
       AliError(Form("%s: Could not retrieve tracks %s!", GetName(), fTracksName.Data())); 
@@ -258,7 +323,17 @@ void AliAnalysisTaskEmcal::ExecOnce()
       }
     }
   }
-  SetInitialized();
+
+  if (fAnaType == kTPC) {
+    SetTrackEtaLimits(-0.9, 0.9);
+    SetTrackPhiLimits(-10, 10);
+  } 
+  else if (fAnaType == kEMCAL && fGeom) {
+    SetTrackEtaLimits(fGeom->GetArm1EtaMin(), fGeom->GetArm1EtaMax());
+    SetTrackPhiLimits(fGeom->GetArm1PhiMin() * TMath::DegToRad(), fGeom->GetArm1PhiMax() * TMath::DegToRad());
+  }
+
+  fInitialized = kTRUE;
 }
 
 //_____________________________________________________
@@ -267,6 +342,9 @@ AliAnalysisTaskEmcal::BeamType AliAnalysisTaskEmcal::GetBeamType()
   // Get beam type : pp-AA-pA
   // ESDs have it directly, AODs get it from hardcoded run number ranges
 
+  if (fForceBeamType != kNA)
+    return fForceBeamType;
+
   AliESDEvent *esd = dynamic_cast<AliESDEvent*>(InputEvent());
   if (esd) {
     const AliESDRun *run = esd->GetESDRun();
index 2d388bd..d07fc8f 100644 (file)
@@ -10,6 +10,8 @@ class AliEmcalParticle;
 class AliMCParticle;
 class AliVCluster;
 class AliVTrack;
+class TH1F;
+class AliEMCALGeometry;
 
 #include "AliAnalysisTaskSE.h"
 
@@ -17,10 +19,9 @@ class AliAnalysisTaskEmcal : public AliAnalysisTaskSE {
  public:
   
   enum EmcalAnaType {
-    kTPC       = 0,     // TPC only analysis
-    kEMCAL     = 1,     // EMCal + TPC analysis
-    kTPCSmall  = 2,     // TPC only in EMCal acceptance
-    kEMCALOnly = 3,     // EMCal only analysis
+    kTPC       = 0,     // TPC acceptance
+    kEMCAL     = 1,     // EMCal acceptance
+    kUser      = 2,     // User defined acceptance
   };
 
   enum BeamType {
@@ -35,36 +36,41 @@ class AliAnalysisTaskEmcal : public AliAnalysisTaskSE {
   virtual ~AliAnalysisTaskEmcal();
 
   void                        UserExec(Option_t *option);
+  void                        UserCreateOutputObjects();
 
-  void                        SetAnaType(EmcalAnaType type)                         { fAnaType        = type;         }
-  void                        SetCentRange(Double_t min, Double_t max)              { fMinCent = min; fMaxCent = max; }
-  void                        SetClusName(const char *n)                            { fCaloName       = n;            }
-  void                        SetClusPtCut(Double_t cut)                            { fClusPtCut      = cut;          }
-  void                        SetClusTimeCut(Double_t min, Double_t max)            { fClusTimeCutLow = min; fClusTimeCutUp = max;      }
-  void                        SetHistoBins(Int_t nbins, Double_t min, Double_t max) { fNbins = nbins; fMinBinPt = min; fMaxBinPt = max; }
-  void                        SetOffTrigger(UInt_t t)                               { fOffTrigger    = t;                               }
-  void                        SetPtCut(Double_t cut)                                { SetClusPtCut(cut); SetTrackPtCut(cut);            }
-  void                        SetTrackPtCut(Double_t cut)                           { fTrackPtCut     = cut;          }
-  void                        SetTrackEtaLimits(Double_t min, Double_t max)         { fMaxTrackEta      = max ; fMinTrackEta      = min ; }
-  void                        SetTrackPhiLimits(Double_t min, Double_t max)         { fMaxTrackPhi      = max ; fMinTrackPhi      = min ; }
-  void                        SetTracksName(const char *n)                          { fTracksName     = n;            }
-  void                        SetTrigClass(const char *n)                           { fTrigClass = n;                 } 
-  void                        SetVzRange(Double_t min, Double_t max)                { fMinVz = min; fMaxVz   = max;   }
+  void                        SetAnaType(EmcalAnaType type)                         { fAnaType           = type ;                         ; }
+  void                        SetCentRange(Double_t min, Double_t max)              { fMinCent           = min  ; fMaxCent = max          ; }
+  void                        SetClusName(const char *n)                            { fCaloName          = n                              ; }
+  void                        SetClusPtCut(Double_t cut)                            { fClusPtCut         = cut                            ; }
+  void                        SetClusTimeCut(Double_t min, Double_t max)            { fClusTimeCutLow    = min  ; fClusTimeCutUp = max    ; }
+  void                        SetHistoBins(Int_t nbins, Double_t min, Double_t max) { fNbins = nbins; fMinBinPt = min; fMaxBinPt = max    ; }
+  void                        SetOffTrigger(UInt_t t)                               { fOffTrigger        = t                              ; }
+  void                        SetPtCut(Double_t cut)                                { SetClusPtCut(cut)         ; SetTrackPtCut(cut)      ; }
+  void                        SetTrackPtCut(Double_t cut)                           { fTrackPtCut        = cut                            ; }
+  void                        SetTrackEtaLimits(Double_t min, Double_t max)         { fTrackMaxEta       = max  ; fTrackMinEta      = min ; }
+  void                        SetTrackPhiLimits(Double_t min, Double_t max)         { fTrackMaxPhi       = max  ; fTrackMinPhi      = min ; }
+  void                        SetTracksName(const char *n)                          { fTracksName        = n                              ; }
+  void                        SetTrigClass(const char *n)                           { fTrigClass         = n                              ; }  
+  void                        SetVzRange(Double_t min, Double_t max)                { fMinVz             = min  ; fMaxVz   = max          ; }
+  void                        SetForceBeamType(BeamType f)                          { fForceBeamType     = f                              ; }
+  void                        SetMakeGeneralHistograms(Bool_t g)                    { fGeneralHistograms = g                              ; }
 
  protected:
   Bool_t                      AcceptCluster(AliVCluster        *clus,  Bool_t acceptMC = kFALSE) const;
   Bool_t                      AcceptEmcalPart(AliEmcalParticle *part,  Bool_t acceptMC = kFALSE) const;
   Bool_t                      AcceptTrack(AliVTrack            *track, Bool_t acceptMC = kFALSE) const;
   virtual void                ExecOnce();
-  virtual Bool_t              FillHistograms()                                     { return fCreateHisto; }
+  virtual Bool_t              FillGeneralHistograms();
+  virtual Bool_t              FillHistograms()                                     { return kTRUE                 ; }
   BeamType                    GetBeamType();
   TClonesArray               *GetArrayFromEvent(const char *name, const char *clname=0);
   virtual Bool_t              IsEventSelected();
   virtual Bool_t              RetrieveEventObjects();
   virtual Bool_t              Run()                                                { return kTRUE                 ; }
-  void                        SetInitialized(Bool_t ini = kTRUE)                   { fInitialized    = ini        ; }
 
   EmcalAnaType                fAnaType;                    // analysis type
+  BeamType                    fForceBeamType;              // forced beam type
+  Bool_t                      fGeneralHistograms;          // whether or not it should fill some general histograms
   Bool_t                      fInitialized;                // whether or not the task has been already initialized
   Bool_t                      fCreateHisto;                // whether or not create histograms
   TString                     fTracksName;                 // name of track collection
@@ -80,12 +86,13 @@ class AliAnalysisTaskEmcal : public AliAnalysisTaskSE {
   Double_t                    fMaxBinPt;                   // max pt in histograms
   Double_t                    fClusPtCut;                  // cut on cluster pt
   Double_t                    fTrackPtCut;                 // cut on track pt
-  Double_t                    fMinTrackEta;                // cut on track eta
-  Double_t                    fMaxTrackEta;                // cut on track eta
-  Double_t                    fMinTrackPhi;                // cut on track phi
-  Double_t                    fMaxTrackPhi;                // cut on track phi
+  Double_t                    fTrackMinEta;                // cut on track eta
+  Double_t                    fTrackMaxEta;                // cut on track eta
+  Double_t                    fTrackMinPhi;                // cut on track phi
+  Double_t                    fTrackMaxPhi;                // cut on track phi
   Double_t                    fClusTimeCutLow;             // low time cut for clusters
   Double_t                    fClusTimeCutUp;              // up time cut for clusters
+  AliEMCALGeometry           *fGeom;                       //!emcal geometry
   TClonesArray               *fTracks;                     //!tracks
   TClonesArray               *fCaloClusters;               //!clusters
   Double_t                    fCent;                       //!event centrality
@@ -98,10 +105,13 @@ class AliAnalysisTaskEmcal : public AliAnalysisTaskSE {
   BeamType                    fBeamType;                   //!event beam type
   TList                      *fOutput;                     //!output list
 
+  TH1F                       *fHistCentrality;             //!Event centrality distribution
+  TH1F                       *fHistZVertex;                //!Z vertex position
+
  private:
   AliAnalysisTaskEmcal(const AliAnalysisTaskEmcal&);            // not implemented
   AliAnalysisTaskEmcal &operator=(const AliAnalysisTaskEmcal&); // not implemented
 
-  ClassDef(AliAnalysisTaskEmcal, 6) // EMCAL base analysis task
+  ClassDef(AliAnalysisTaskEmcal, 7) // EMCAL base analysis task
 };
 #endif