]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Added a temptative task for monitors
authorpulvir <pulvir@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 20 Jul 2011 17:16:40 +0000 (17:16 +0000)
committerpulvir <pulvir@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 20 Jul 2011 17:16:40 +0000 (17:16 +0000)
Tried to correct the cut for nsigma (generic one)
Small restyling of mini-task

PWG2/CMakelibPWG2resonances.pkg
PWG2/PWG2resonancesLinkDef.h
PWG2/RESONANCES/AliRsnCutPIDNSigma.cxx
PWG2/RESONANCES/AliRsnCutPIDNSigma.h
PWG2/RESONANCES/AliRsnMiniAnalysisTask.cxx
PWG2/RESONANCES/AliRsnMiniMonitor.cxx
PWG2/RESONANCES/AliRsnMiniMonitorTask.cxx [new file with mode: 0644]
PWG2/RESONANCES/AliRsnMiniMonitorTask.h [new file with mode: 0644]

index f2dfe1e20dab711290cb37eb7057f5ebb0c188a2..ad555ba48bb111329f78424ba01c88456ccdc9f6 100644 (file)
@@ -75,7 +75,8 @@ set ( SRCS RESONANCES/AliRsnDaughter.cxx
            RESONANCES/AliRsnMiniOutput.cxx
            RESONANCES/AliRsnMiniValue.cxx
            RESONANCES/AliRsnMiniMonitor.cxx
-           RESONANCES/AliRsnMiniAnalysisTask.cxx )
+           RESONANCES/AliRsnMiniAnalysisTask.cxx
+           RESONANCES/AliRsnMiniMonitorTask.cxx )
 
 string ( REPLACE ".cxx" ".h" HDRS "${SRCS}" )
 
index 15e45e165eb9b0a72b40a27d375e18dc8606b16b..cb4486c78ee4389ae1aa6794a2c04396cc1a6371 100644 (file)
@@ -58,6 +58,6 @@
 #pragma link C++ class AliRsnMiniValue+;
 #pragma link C++ class AliRsnMiniMonitor+;
 #pragma link C++ class AliRsnMiniAnalysisTask+;
-
+#pragma link C++ class AliRsnMiniMonitorTask+;
 
 #endif
index b2f76851d0e9b9f8d0c8808f2a0f6ba39880c6cd..09241cba69a9264f1aa662252915a622faf9dd3b 100644 (file)
 
 ClassImp(AliRsnCutPIDNSigma)
 
+//_________________________________________________________________________________________________
+AliRsnCutPIDNSigma::AliRsnCutPIDNSigma() : 
+   AliRsnCut("cut", AliRsnTarget::kDaughter),
+   fSpecies(AliPID::kUnknown),
+   fDetector(kDetectors),
+   fRejectUnmatched(kFALSE),
+   fMomMin(0.0),
+   fMomMax(1E20),
+   fNSigma(1E20)
+{
+//
+// Main constructor.
+//
+}
+
 //_________________________________________________________________________________________________
 AliRsnCutPIDNSigma::AliRsnCutPIDNSigma
 (const char *name, AliPID::EParticleType species, EDetector det, Double_t nsigma) :
-   AliRsnCut(name, AliRsnCut::kDaughter, -nsigma, nsigma),
+   AliRsnCut(name, AliRsnTarget::kDaughter),
    fSpecies(species),
    fDetector(det),
+   fRejectUnmatched(kFALSE),
    fMomMin(0.0),
    fMomMax(1E20),
-   fRejectUnmatched(kFALSE)
+   fNSigma(nsigma)
 {
 //
 // Main constructor.
@@ -46,9 +62,10 @@ AliRsnCutPIDNSigma::AliRsnCutPIDNSigma
    AliRsnCut(copy),
    fSpecies(copy.fSpecies),
    fDetector(copy.fDetector),
+   fRejectUnmatched(copy.fRejectUnmatched),
    fMomMin(copy.fMomMin),
    fMomMax(copy.fMomMax),
-   fRejectUnmatched(copy.fRejectUnmatched)
+   fNSigma(copy.fNSigma)
 {
 //
 // Copy constructor.
@@ -66,9 +83,10 @@ AliRsnCutPIDNSigma& AliRsnCutPIDNSigma::operator=(const AliRsnCutPIDNSigma& copy
 
    fSpecies = copy.fSpecies;
    fDetector = copy.fDetector;
+   fRejectUnmatched = copy.fRejectUnmatched;
    fMomMin = copy.fMomMin;
    fMomMax = copy.fMomMax;
-   fRejectUnmatched = copy.fRejectUnmatched;
+   fNSigma = copy.fNSigma;
 
    return (*this);
 }
@@ -92,66 +110,57 @@ Bool_t AliRsnCutPIDNSigma::IsSelected(TObject *object)
 
    // get reference momentum, for range cut
    Double_t momentum = -1.0;
-   if (!fDaughter->Ref2Vtrack()) {
+   AliVTrack *vtrack = fDaughter->Ref2Vtrack();
+   if (!vtrack) {
       AliDebugClass(2, "Referenced daughter is not a track");
       return kFALSE;
    }
    if (fDetector == kTPC)
-      momentum = fDaughter->Ref2Vtrack()->GetTPCmomentum();
+      momentum = vtrack->GetTPCmomentum();
    else
-      momentum = fDaughter->GetRef()->P();
+      momentum = vtrack->P();
       
-   // check momentum range, if required
+   // check momentum range
    if (momentum < fMomMin || momentum > fMomMax) {
       AliDebugClass(2, Form("Track momentum = %.5f, outside allowed range [%.2f - %.2f]", momentum, fMomMin, fMomMax));
       return kFALSE;
    }
    
-   // matching check, if required
-   if (fRejectUnmatched) {
-      switch (fDetector) {
-         case kITS:
-            if (!IsITS(fDaughter->Ref2Vtrack())) {
-               AliDebug(3, "Rejecting track not matched in ITS");
-               return kFALSE;
-            }
-            break;
-         case kTPC:
-            if (!IsTPC(fDaughter->Ref2Vtrack())) {
-               AliDebug(3, "Rejecting track not matched in TPC");
-               return kFALSE;
-            }
-            break;
-         case kTOF:
-            if (!IsTOF(fDaughter->Ref2Vtrack())) {
-               AliDebug(3, "Rejecting track not matched in TOF");
-               return kFALSE;
-            }
-            break;
-         default:
-            AliWarning("Required to reject unmatched tracks, but no detector defined. Track rejected");
-            return kFALSE;
-      }
-   }
-   
    // check PID
-   // the number of sigmas is set as cut value, which is then checked
-   // using the basic functions available in AliRsnCut
+   Bool_t matched;
+   Double_t nsigma;
    switch (fDetector) {
       case kITS:
-         fCutValueD = pid->NumberOfSigmasITS(fDaughter->GetRef(), fSpecies);
+         matched = IsITS(vtrack);
+         nsigma  = pid->NumberOfSigmasITS(vtrack, fSpecies);
          break;
       case kTPC:
-         fCutValueD = pid->NumberOfSigmasTPC(fDaughter->GetRef(), fSpecies);
+         matched = IsTPC(vtrack);
+         nsigma  = pid->NumberOfSigmasTPC(vtrack, fSpecies);
          break;
       case kTOF:
-         fCutValueD = pid->NumberOfSigmasTOF(fDaughter->GetRef(), fSpecies);
+         matched = IsTOF(vtrack);
+         nsigma  = pid->NumberOfSigmasTOF(vtrack, fSpecies);
          break;
       default:
+         AliError("Bad detector chosen. Rejecting track");
          return kFALSE;
    }
    
-   return OkRangeD();
+   // determine cut result
+   if (fRejectUnmatched && (matched == kFALSE)) {
+      AliDebugClass(2, "Required to reject unmatched traks, and this track is not matched in the detector");
+      return kFALSE;
+   } else {
+      AliDebugClass(2, Form("Nsigma = %.5f, maximum allowed = %.2f", nsigma, fNSigma));
+      if (TMath::Abs(nsigma) <= fNSigma) {
+         AliDebugClass(2, "Track accepted");
+         return kTRUE;
+      } else {
+         AliDebugClass(2, "Track rejected");
+         return kFALSE;
+      }
+   }
 }
 
 //_________________________________________________________________________________________________
index f6852f1a3db8a518735c63e80c9cf527ed402833..cf978150a0ecd4457ea0ea6afb022a6682720d02 100644 (file)
@@ -2,10 +2,16 @@
 #define ALIRSNCUTPIDNSIGMA_H
 
 //
-// Class for generalized n-sigma PID cuts with detectors.
-// Allows to choose the detector to check and define a momentum range
-// in order to permit different cuts in different ranges.
+// Class for n-sigma PID cuts.
+// ---
+// Requires:
 //
+// 1) the used detector, chosen from an enumeration
+// 2) the reference charged particle species, chosen from AliPID enumeration
+// 3) a momentum range: outside it, the cut is never passed
+//
+
+#include <TMath.h>
 
 #include "AliPID.h"
 
@@ -24,15 +30,17 @@ public:
       kDetectors
    };
 
-   AliRsnCutPIDNSigma(const char *name = "cutPIDNsigma", AliPID::EParticleType species = AliPID::kUnknown, EDetector det = kDetectors, Double_t nsigma = 3.0);
+   AliRsnCutPIDNSigma();
+   AliRsnCutPIDNSigma(const char *name, AliPID::EParticleType species, EDetector det, Double_t nsigma);
    AliRsnCutPIDNSigma(const AliRsnCutPIDNSigma& copy);
    AliRsnCutPIDNSigma& operator=(const AliRsnCutPIDNSigma& copy);
    virtual ~AliRsnCutPIDNSigma() { }
 
-   void             SetRejectUnmatched(Bool_t yn = kTRUE)         {fRejectUnmatched = yn;}
-   void             SetMomentumRange(Double_t min, Double_t max)  {fMomMin = min; fMomMax = max;}
-   void             SetNSigmaRange(Double_t min, Double_t max)    {AliRsnCut::SetRangeD(min, max);}
    void             SetSpecies(AliPID::EParticleType type)        {fSpecies = type;}
+   void             SetDetector(EDetector det)                    {fDetector = det;}
+   void             SetRejectUnmatched(Bool_t yn = kTRUE)         {fRejectUnmatched = yn;}
+   void             SetNSigma(Double_t nsigma)                    {fNSigma = nsigma;}
+   void             SetMomentumRange(Double_t min, Double_t max);
    
    Bool_t           IsITS(const AliVTrack *vtrack) const;
    Bool_t           IsTPC(const AliVTrack *vtrack) const;
@@ -45,13 +53,26 @@ private:
 
    AliPID::EParticleType   fSpecies;         //  particle species
    EDetector               fDetector;        //  detector used for PID
-   Double_t                fMomMin;          //  momentum range (for ITS and TOF it is vertex momentum, for TPC it is inner wall)
-   Double_t                fMomMax;          //  momentum range (for ITS and TOF it is vertex momentum, for TPC it is inner wall)
    Bool_t                  fRejectUnmatched; //  tracks not matched to this detector do pass the cut?
+   Double_t                fMomMin;          //  momentum range (ITS/TOF: vertex momentum, TPC: mom at inner wall)
+   Double_t                fMomMax;          //  momentum range (ITS/TOF: vertex momentum, TPC: mom at inner wall)
+   Double_t                fNSigma;          //  nsigma range
 
    ClassDef(AliRsnCutPIDNSigma, 1)
 };
 
+inline void AliRsnCutPIDNSigma::SetMomentumRange(Double_t min, Double_t max)
+{
+//
+// Assigns the range in total momentum used for check
+// For ITS and TOF, it is used to check momentum at vertex,
+// for TPC it is used to check momentum at TPC inner barrel
+//
+
+   fMomMin = TMath::Min(min, max);
+   fMomMax = TMath::Max(min, max);
+}
+
 inline Bool_t AliRsnCutPIDNSigma::IsITS(const AliVTrack *vtrack) const
 {
 //
index 275360eca922d8b0b15ef44efdc3c94752054b9e..ba5c0ca5e5133d7969c0ff62e1fc83d1721b2efc 100644 (file)
@@ -758,7 +758,7 @@ void AliRsnMiniAnalysisTask::FillTrueMotherESD(AliRsnMiniEvent *miniEvent)
       if (!def->IsMother()) continue;
       for (ip = 0; ip < npart; ip++) {
          AliMCParticle *part = (AliMCParticle*)fMCEvent->GetTrack(ip);
-         if (TMath::Abs(part->Particle()->GetPdgCode()) != def->GetMotherPDG()) continue;
+         if (part->Particle()->GetPdgCode() != def->GetMotherPDG()) continue;
          // check that daughters match expected species
          if (part->Particle()->GetNDaughters() < 2) continue;
          label1 = part->Particle()->GetDaughter(0);
@@ -807,7 +807,7 @@ void AliRsnMiniAnalysisTask::FillTrueMotherAOD(AliRsnMiniEvent *miniEvent)
       if (!def->IsMother()) continue;
       for (ip = 0; ip < npart; ip++) {
          AliAODMCParticle *part = (AliAODMCParticle*)list->At(ip);
-         if (TMath::Abs(part->GetPdgCode()) != def->GetMotherPDG()) continue;
+         if (part->GetPdgCode() != def->GetMotherPDG()) continue;
          // check that daughters match expected species
          if (part->GetNDaughters() < 2) continue;
          label1 = part->GetDaughter(0);
index 4dd2b9c43bafca878c86381df9b140c6f3a2f413..117f94f19d42cf96a5337d4d781558a685e9a4ce 100644 (file)
@@ -44,6 +44,8 @@
 #include "TH3.h"
 
 #include "AliLog.h"
+#include "AliPID.h"
+#include "AliPIDResponse.h"
 
 #include "AliRsnDaughter.h"
 #include "AliRsnEvent.h"
@@ -136,7 +138,7 @@ Bool_t AliRsnMiniMonitor::Init(const char *name, TList *list)
          break;
       case ktimeTOFvsP:
          sname += "_TOFsignal";
-         histogram = new TH2F(sname.Data(), "", 500, 0.0, 5.0, 1000, -5.0, 5.0);
+         histogram = new TH2F(sname.Data(), "", 500, 0.0, 5.0, 1000, 0.0, 200000.0);
          break;
       default:
          AliError("Wrong enum type");
@@ -156,7 +158,7 @@ Bool_t AliRsnMiniMonitor::Init(const char *name, TList *list)
 }
 
 //_____________________________________________________________________________
-Bool_t AliRsnMiniMonitor::Fill(AliRsnDaughter *track, AliRsnEvent *)
+Bool_t AliRsnMiniMonitor::Fill(AliRsnDaughter *track, AliRsnEvent *event)
 {
 //
 // Fill the histogram
@@ -175,6 +177,8 @@ Bool_t AliRsnMiniMonitor::Fill(AliRsnDaughter *track, AliRsnEvent *)
 
    Double_t valueX, valueY;
    AliVTrack *vtrack = track->Ref2Vtrack();
+   
+   AliPIDResponse *pid = event->GetPIDResponse();
 
    switch (fType) {
       case kdEdxTPCvsP: 
@@ -192,7 +196,9 @@ Bool_t AliRsnMiniMonitor::Fill(AliRsnDaughter *track, AliRsnEvent *)
             return kFALSE;
          }
          valueX = vtrack->P();
-         valueY = vtrack->GetTOFsignal();
+         //valueY = vtrack->GetTOFsignal();
+         valueY = 1E20;
+         if (pid) valueY = pid->NumberOfSigmasTOF(vtrack, AliPID::kKaon);
          ((TH2F*)obj)->Fill(valueX, valueY);
          return kTRUE;
       default:
diff --git a/PWG2/RESONANCES/AliRsnMiniMonitorTask.cxx b/PWG2/RESONANCES/AliRsnMiniMonitorTask.cxx
new file mode 100644 (file)
index 0000000..444864f
--- /dev/null
@@ -0,0 +1,411 @@
+//
+// Analysis task for 'mini' sub-package
+// Contains all definitions needed for running an analysis:
+// -- global event cut
+// -- a list of track cuts (any number)
+// -- definitions of output histograms
+// -- values to be computed.
+// Each one must be defined using the "CREATE" methods, which
+// add directly a new element in the task collections, and don't
+// need an external object to be passed to the task itself.
+//
+
+#include <Riostream.h>
+
+#include <TH1.h>
+#include <TList.h>
+#include <TTree.h>
+
+#include "AliLog.h"
+#include "AliEventplane.h"
+#include "AliMultiplicity.h"
+#include "AliTriggerAnalysis.h"
+#include "AliAnalysisManager.h"
+#include "AliInputEventHandler.h"
+
+#include "AliESDtrackCuts.h"
+#include "AliESDUtils.h"
+
+#include "AliAODEvent.h"
+#include "AliAODMCParticle.h"
+
+#include "AliRsnCutSet.h"
+#include "AliRsnMiniPair.h"
+#include "AliRsnMiniEvent.h"
+#include "AliRsnMiniParticle.h"
+
+#include "AliRsnMiniMonitorTask.h"
+
+ClassImp(AliRsnMiniMonitorTask)
+
+//__________________________________________________________________________________________________
+AliRsnMiniMonitorTask::AliRsnMiniMonitorTask() :
+   AliAnalysisTaskSE(),
+   fUseMC(kFALSE),
+   fEvNum(0),
+   fUseCentrality(kFALSE),
+   fCentralityType("QUALITY"),
+   fOutput(0x0),
+   fHistograms("AliRsnMiniMonitor", 0),
+   fEventCuts(0x0),
+   fTrackCuts(0),
+   fRsnEvent(),
+   fBigOutput(kFALSE)
+{
+//
+// Dummy constructor ALWAYS needed for I/O.
+//
+}
+
+//__________________________________________________________________________________________________
+AliRsnMiniMonitorTask::AliRsnMiniMonitorTask(const char *name, Bool_t useMC) :
+   AliAnalysisTaskSE(name),
+   fUseMC(useMC),
+   fEvNum(0),
+   fUseCentrality(kFALSE),
+   fCentralityType("QUALITY"),
+   fOutput(0x0),
+   fHistograms("AliRsnMiniMonitor", 0),
+   fEventCuts(0x0),
+   fTrackCuts(0),
+   fRsnEvent(),
+   fBigOutput(kFALSE)
+{
+//
+// Default constructor.
+// Define input and output slots here (never in the dummy constructor)
+// Input slot #0 works with a TChain - it is connected to the default input container
+// Output slot #1 writes into a TH1 container
+//
+
+   DefineOutput(1, TList::Class());
+}
+
+//__________________________________________________________________________________________________
+AliRsnMiniMonitorTask::AliRsnMiniMonitorTask(const AliRsnMiniMonitorTask& copy) :
+   AliAnalysisTaskSE(copy),
+   fUseMC(copy.fUseMC),
+   fEvNum(0),
+   fUseCentrality(copy.fUseCentrality),
+   fCentralityType(copy.fCentralityType),
+   fOutput(0x0),
+   fHistograms(copy.fHistograms),
+   fEventCuts(copy.fEventCuts),
+   fTrackCuts(copy.fTrackCuts),
+   fRsnEvent(),
+   fBigOutput(copy.fBigOutput)
+{
+//
+// Copy constructor.
+// Implemented as requested by C++ standards.
+// Can be used in PROOF and by plugins.
+//
+}
+
+//__________________________________________________________________________________________________
+AliRsnMiniMonitorTask& AliRsnMiniMonitorTask::operator=(const AliRsnMiniMonitorTask& copy)
+{
+//
+// Assignment operator.
+// Implemented as requested by C++ standards.
+// Can be used in PROOF and by plugins.
+//
+
+   AliAnalysisTaskSE::operator=(copy);
+   
+   fUseMC = copy.fUseMC;
+   fUseCentrality = copy.fUseCentrality;
+   fCentralityType = copy.fCentralityType;
+   fHistograms = copy.fHistograms;
+   fEventCuts = copy.fEventCuts;
+   fTrackCuts = copy.fTrackCuts;
+   fBigOutput = copy.fBigOutput;
+   
+   return (*this);
+}
+
+//__________________________________________________________________________________________________
+AliRsnMiniMonitorTask::~AliRsnMiniMonitorTask()
+{
+//
+// Destructor. 
+// Clean-up the output list, but not the histograms that are put inside
+// (the list is owner and will clean-up these histograms). Protect in PROOF case.
+//
+
+
+   if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
+      delete fOutput;
+   }
+}
+
+//__________________________________________________________________________________________________
+Int_t AliRsnMiniMonitorTask::AddTrackCuts(AliRsnCutSet *cuts)
+{
+//
+// Add a new cut set for a new criterion for track selection.
+// A user can add as many as he wants, and each one corresponds
+// to one of the available bits in the AliRsnMiniParticle mask.
+// The only check is the following: if a cut set with the same name
+// as the argument is there, this is not added.
+// Return value is the array position of this set.
+//
+
+   TObject *obj = fTrackCuts.FindObject(cuts->GetName());
+   
+   if (obj) {
+      AliInfo(Form("A cut set named '%s' already exists", cuts->GetName()));
+      return fTrackCuts.IndexOf(obj);
+   } else {
+      fTrackCuts.AddLast(cuts);
+      return fTrackCuts.IndexOf(cuts);
+   }
+}
+
+//__________________________________________________________________________________________________
+void AliRsnMiniMonitorTask::UserCreateOutputObjects()
+{
+//
+// Initialization of outputs.
+// This is called once per worker node.
+//
+
+   // reset counter
+   fEvNum = 0;
+   
+   // message
+   AliInfo(Form("Selected event characterization: %s (%s)", (fUseCentrality ? "centrality" : "multiplicity"), fCentralityType.Data()));
+   
+   // create list and set it as owner of its content (MANDATORY)
+   if (fBigOutput) OpenFile(1);
+   fOutput = new TList();
+   fOutput->SetOwner();
+   
+   // create one histogram per each stored definition (event histograms)
+   Int_t i, ndef = fHistograms.GetEntries();
+   AliRsnMiniMonitor *def = 0x0;
+   for (i = 0; i < ndef; i++) {
+      def = (AliRsnMiniMonitor*)fHistograms[i];
+      if (!def) continue;
+      if (!def->Init(GetName(), fOutput)) {
+         AliError(Form("Def '%s': failed initialization", def->GetName()));
+         continue;
+      }
+   }
+   
+   // post data for ALL output slots >0 here, to get at least an empty histogram
+   PostData(1, fOutput);
+}
+
+//__________________________________________________________________________________________________
+void AliRsnMiniMonitorTask::UserExec(Option_t *)
+{
+//
+// Computation loop.
+// In this case, it checks if the event is acceptable, and eventually
+// creates the corresponding mini-event and stores it in the buffer.
+// The real histogram filling is done at the end, in "FinishTaskOutput".
+//
+
+   // event counter
+   fEvNum++;
+   
+   // check current event
+   Char_t check = CheckCurrentEvent();
+   if (!check) return;
+   
+   // setup PID response
+   AliAnalysisManager *man = AliAnalysisManager::GetAnalysisManager(); 
+       AliInputEventHandler *inputHandler = (AliInputEventHandler*)man->GetInputEventHandler(); 
+       fRsnEvent.SetPIDResponse(inputHandler->GetPIDResponse());
+   
+   // loop on monitors and fill them
+   Int_t it, icut, nTracks = fRsnEvent.GetAbsoluteSum(), nCuts = fTrackCuts.GetEntriesFast();
+   AliRsnDaughter cursor;
+   AliRsnCutSet *cut = 0x0;
+   AliRsnMiniMonitor *mon = 0x0;
+   TObjArrayIter next(&fHistograms);
+   for (it = 0; it < nTracks; it++) {
+      fRsnEvent.SetDaughter(cursor, it, fUseMC);
+      next.Reset();
+      while ( (mon = (AliRsnMiniMonitor*)next()) ) {
+         icut = mon->GetCutID();
+         if (icut >= 0 && icut < nCuts) {
+            cut = (AliRsnCutSet*)fTrackCuts[icut];
+            if (!cut) {
+               AliError("Cut not found");
+               continue;
+            }
+            if (!cut->IsSelected(&cursor)) continue;
+         }
+         mon->Fill(&cursor, &fRsnEvent);
+      }
+   }
+      
+   // post data for computed stuff
+   PostData(1, fOutput);
+}
+
+//__________________________________________________________________________________________________
+void AliRsnMiniMonitorTask::Terminate(Option_t *)
+{
+//
+// Draw result to screen, or perform fitting, normalizations
+// Called once at the end of the query
+//
+
+   fOutput = dynamic_cast<TList*>(GetOutputData(1));
+   if (!fOutput) { 
+      AliError("Could not retrieve TList fOutput"); 
+      return; 
+   }
+}
+
+//__________________________________________________________________________________________________
+Char_t AliRsnMiniMonitorTask::CheckCurrentEvent()
+{
+//
+// This method checks if current event is OK for analysis.
+// In case it is, the pointers of the local AliRsnEvent data member
+// will point to it, in order to allow cut checking, otherwise the
+// function exits with a failure message.
+// ---
+// ESD events must pass the physics selection, AOD are supposed to do.
+// ---
+// While checking the event, a histogram is filled to count the number
+// of CINT1B, V0AND and CANDLE events, which are needed for normalization
+// ---
+// Return values can be:
+//    -- 'E' if the event is accepted and is ESD
+//    -- 'A' if the event is accepted and is AOD
+//    --  0  if the event is not accepted
+//
+
+   // string to sum messages
+   TString msg("");
+   
+   // check input type
+   // exit points are provided in all cases an event is bad
+   // if this block is passed, an event can be rejected only
+   // if it does not pass the set of event cuts defined in the task
+   Char_t output = 0;
+   Bool_t isSelected;
+   if (fInputEvent->InheritsFrom(AliESDEvent::Class())) {
+      // type ESD
+      output = 'E';
+      // ESD specific check: Physics Selection
+      // --> if this is failed, the event is rejected
+      isSelected = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & AliVEvent::kMB);
+      if (!isSelected) {
+         AliDebugClass(2, "Event does not pass physics selections");
+         fRsnEvent.SetRef(0x0);
+         fRsnEvent.SetRefMC(0x0);
+         return 0;
+      }
+      // set reference to input
+      fRsnEvent.SetRef(fInputEvent);
+      // add MC if requested and available
+      if (fUseMC) {
+         if (fMCEvent) 
+            fRsnEvent.SetRefMC(fMCEvent);
+         else {
+            AliWarning("MC event requested but not available");
+            fRsnEvent.SetRefMC(0x0);
+         }
+      }
+   } else if (fInputEvent->InheritsFrom(AliAODEvent::Class())) {
+      // type AOD
+      output = 'A';
+      // set reference to input
+      fRsnEvent.SetRef(fInputEvent);
+      // add MC if requested and available (it is in the same object)
+      if (fUseMC) {
+         fRsnEvent.SetRefMC(fInputEvent);
+         if (!fRsnEvent.GetAODList()) {
+            AliWarning("MC event requested but not available");
+            fRsnEvent.SetRefMC(0x0);
+         }
+      }
+   } else {
+      AliError(Form("Bad input event class: %s", fInputEvent->ClassName()));
+      // reset pointers in local AliRsnEvent object
+      fRsnEvent.SetRef(0x0);
+      fRsnEvent.SetRefMC(0x0);
+      return 0;
+   }
+   
+   // if event cuts are defined, they are checked here
+   // final decision on the event depends on this
+   isSelected = kTRUE;
+   if (fEventCuts) {
+      if (!fEventCuts->IsSelected(&fRsnEvent)) {
+         msg += " -- Local cuts = REJECTED";
+         isSelected = kFALSE;
+      } else {
+         msg += " -- Local cuts = ACCEPTED";
+         isSelected = kTRUE;
+      }
+   } else {
+      msg += " -- Local cuts = NONE";
+      isSelected = kTRUE;
+   }
+   
+   // if the above exit point is not taken, the event is accepted
+   AliDebugClass(2, Form("Stats for event %d: %s", fEvNum, msg.Data()));
+   if (isSelected) {
+      return output;
+   } else {
+      return 0;
+   }
+}
+
+//__________________________________________________________________________________________________
+Double_t AliRsnMiniMonitorTask::ComputeCentrality(Bool_t isESD)
+{
+//
+// Computes event centrality/multiplicity according to the criterion defined
+// by two elements: (1) choice between multiplicity and centrality and
+// (2) the string defining what criterion must be used for specific computation.
+//
+
+   if (fUseCentrality) {
+      AliCentrality *centrality = fInputEvent->GetCentrality();
+      if (!centrality) {
+         AliError("Cannot compute centrality!");
+         return -1.0;
+      }
+      return centrality->GetCentralityPercentile(fCentralityType.Data());
+   } else {
+      if (!fCentralityType.CompareTo("TRACKS"))
+         return fInputEvent->GetNumberOfTracks();
+      else if (!fCentralityType.CompareTo("QUALITY"))
+         if (isESD)
+            return AliESDtrackCuts::GetReferenceMultiplicity((AliESDEvent*)fInputEvent, kTRUE);
+         else {
+            Double_t count = 0.;
+            Int_t iTrack, ntracksLoop = fInputEvent->GetNumberOfTracks();
+            for (iTrack = 0; iTrack < ntracksLoop; iTrack++) {    
+               AliVTrack   *track = (AliVTrack*)fInputEvent->GetTrack(iTrack);
+               AliAODTrack *aodt  = dynamic_cast<AliAODTrack*>(track);
+               if (!aodt) continue;
+               if (!aodt->TestFilterBit(5)) continue;
+               count++;
+            }
+            return count;
+         }
+      else if (!fCentralityType.CompareTo("TRACKLETS")) {
+         if (isESD) {
+            const AliMultiplicity *mult = ((AliESDEvent*)fInputEvent)->GetMultiplicity();
+            Float_t nClusters[6] = {0.0,0.0,0.0,0.0,0.0,0.0};
+            for(Int_t ilay = 0; ilay < 6; ilay++) nClusters[ilay] = (Float_t)mult->GetNumberOfITSClusters(ilay);
+            return AliESDUtils::GetCorrSPD2(nClusters[1], fInputEvent->GetPrimaryVertex()->GetZ());
+         } else {
+            AliWarning("Cannot compute multiplicity with SPD tracklets from AOD");
+            return 1E20;
+         }
+      } else {
+         AliError(Form("String '%s' does not define a possible multiplicity/centrality computation", fCentralityType.Data()));
+         return -1.0;
+      }
+   }
+}
diff --git a/PWG2/RESONANCES/AliRsnMiniMonitorTask.h b/PWG2/RESONANCES/AliRsnMiniMonitorTask.h
new file mode 100644 (file)
index 0000000..549386f
--- /dev/null
@@ -0,0 +1,85 @@
+#ifndef ALIRSNMINIMonitorTask_H
+#define ALIRSNMINIMonitorTask_H
+
+//
+// Analysis task for 'mini' sub-package
+// Contains all definitions needed for running an analysis:
+// -- global event cut
+// -- a list of track cuts (any number)
+// -- definitions of output histograms
+// -- values to be computed.
+//
+
+#include <TString.h>
+#include <TClonesArray.h>
+
+#include "AliAnalysisTaskSE.h"
+
+#include "AliRsnEvent.h"
+#include "AliRsnMiniMonitor.h"
+
+class TList;
+
+class AliTriggerAnalysis;
+class AliRsnMiniEvent;
+class AliRsnCutSet;
+
+class AliRsnMiniMonitorTask : public AliAnalysisTaskSE {
+
+public:
+
+   AliRsnMiniMonitorTask();
+   AliRsnMiniMonitorTask(const char *name, Bool_t isMC = kFALSE);
+   AliRsnMiniMonitorTask(const AliRsnMiniMonitorTask &copy);
+   AliRsnMiniMonitorTask& operator=(const AliRsnMiniMonitorTask &copy);
+   virtual ~AliRsnMiniMonitorTask();
+
+   void                UseMC(Bool_t yn = kTRUE)           {fUseMC = yn;}                     
+   void                UseCentrality(const char *type)    {fUseCentrality = kTRUE; fCentralityType = type; fCentralityType.ToUpper();}
+   void                UseMultiplicity(const char *type)  {fUseCentrality = kFALSE; fCentralityType = type; fCentralityType.ToUpper();}
+   void                SetEventCuts(AliRsnCutSet *cuts)   {fEventCuts    = cuts;}
+   Int_t               AddTrackCuts(AliRsnCutSet *cuts);
+   TClonesArray       *Outputs()                          {return &fHistograms;}
+   
+   virtual void        UserCreateOutputObjects();
+   virtual void        UserExec(Option_t*);
+   virtual void        Terminate(Option_t*);
+   
+   AliRsnMiniMonitor  *CreateMonitor(const char *name, AliRsnMiniMonitor::EType type, Int_t cutID);
+  
+private:
+
+   Char_t   CheckCurrentEvent();
+   Double_t ComputeCentrality(Bool_t isESD);
+
+   Bool_t               fUseMC;           //  use or not MC info
+   Int_t                fEvNum;           //! absolute event counter
+   Bool_t               fUseCentrality;   //  if true, use centrality for event, otherwise use multiplicity
+   TString              fCentralityType;  //  definition used to choose what centrality or multiplicity to use
+                       
+   TList               *fOutput;          //  output list
+   TClonesArray         fHistograms;      //  list of histogram definitions
+                       
+   AliRsnCutSet        *fEventCuts;       //  cuts on events
+   TObjArray            fTrackCuts;       //  list of single track cuts
+   AliRsnEvent          fRsnEvent;        //! interface object to the event
+   Bool_t               fBigOutput;       //  flag if open file for output list
+
+   ClassDef(AliRsnMiniMonitorTask, 1);   // AliRsnMiniMonitorTask
+};
+
+inline AliRsnMiniMonitor* AliRsnMiniMonitorTask::CreateMonitor
+(const char *name, AliRsnMiniMonitor::EType type, Int_t cutID)
+{
+//
+// Create a new histogram definition in the task,
+// which is then returned to the user for its configuration
+//
+
+   Int_t n = fHistograms.GetEntries(); 
+   AliRsnMiniMonitor *newDef = new (fHistograms[n]) AliRsnMiniMonitor(name, type, cutID);
+   
+   return newDef;
+}
+
+#endif