Improved Mixing Info task
authormvala <mvala@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sat, 26 Feb 2011 18:09:10 +0000 (18:09 +0000)
committermvala <mvala@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sat, 26 Feb 2011 18:09:10 +0000 (18:09 +0000)
ANALYSIS/EventMixing/AliAnalysisTaskMixInfo.cxx
ANALYSIS/EventMixing/AliAnalysisTaskMixInfo.h
ANALYSIS/EventMixing/AliMixEventCutObj.cxx
ANALYSIS/EventMixing/AliMixEventCutObj.h
ANALYSIS/EventMixing/AliMixInfo.cxx

index 1d1d56d..7269ea6 100644 (file)
@@ -4,6 +4,12 @@
 // AliAnalysisTaskMixInfo is task
 // for mixing info
 //
+// Mixing info can be enabled by setting one of following lines in UserCreateOutput() in your task
+//       // prints mixing info
+//       AliLog::SetClassDebugLevel("AliAnalysisTaskMixInfo", AliLog::kDebug);
+//       // prints mixing info + event info for both (main and mixed) events
+//       AliLog::SetClassDebugLevel("AliAnalysisTaskMixInfo", AliLog::kDebug+1);
+//
 // authors:
 //          Martin Vala (martin.vala@cern.ch)
 //
@@ -17,6 +23,7 @@
 #include "AliAnalysisTaskMixInfo.h"
 #include "AliMixInfo.h"
 #include "AliMixEventPool.h"
+#include "AliMixEventCutObj.h"
 
 
 ClassImp(AliAnalysisTaskMixInfo)
@@ -24,6 +31,8 @@ ClassImp(AliAnalysisTaskMixInfo)
 //________________________________________________________________________
 AliAnalysisTaskMixInfo::AliAnalysisTaskMixInfo(const char *name)
    : AliAnalysisTaskSE(name),
+     fInputEHMain(0),
+     fInputEHMix(0),
      fOutputList(0),
      fMixInfo(0),
      fCurrentEntryTmp(-1),
@@ -54,22 +63,21 @@ void AliAnalysisTaskMixInfo::UserCreateOutputObjects()
    SetDebugForAllClasses();
    fOutputList = new TList();
    fOutputList->SetOwner(kTRUE);
-   if (!fMixInfo) InitMixInfo();
 
-   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
-   AliMultiInputEventHandler *inEvHMain = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
-   if (inEvHMain) {
-      AliMixInputEventHandler *mixEH = dynamic_cast<AliMixInputEventHandler *>(inEvHMain->GetFirstMultiInputHandler());
-      if (mixEH) {
-         AliMixEventPool *evPool = mixEH->GetEventPool();
-         if (evPool) {
-            evPool->SetBufferSize(mixEH->BufferSize());
-            evPool->SetMixNumber(mixEH->MixNumber());
-            fMixInfo->SetEventPool(evPool);
-         }
+   // sets all Inuput Handler pointers
+   InitInputHandlers();
+
+   // inits mix info
+   InitMixInfo();
+
+   if (fInputEHMix) {
+      AliMixEventPool *evPool = fInputEHMix->GetEventPool();
+      if (evPool) {
+         evPool->SetBufferSize(fInputEHMix->BufferSize());
+         evPool->SetMixNumber(fInputEHMix->MixNumber());
+         fMixInfo->SetEventPool(evPool);
       }
    }
-
    if (fMixInfo) fOutputList->Add(fMixInfo);
 
    // Post output data.
@@ -81,23 +89,14 @@ void AliAnalysisTaskMixInfo::UserExec(Option_t *)
 {
    // Main loop
    // Called for each event
-//     if (fCurrentEntry != fCurrentEntryTmp) {
-//       fCurrentEntryTmp = fCurrentEntry;
-   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
-   AliMultiInputEventHandler *inEvHMain = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
-   if (inEvHMain) {
-      AliMixInputEventHandler *mixEH = dynamic_cast<AliMixInputEventHandler *>(inEvHMain->GetFirstMultiInputHandler());
-      if (fMixInfo && mixEH) {
-         if (mixEH->BufferSize() > 1) {
-            if (mixEH->NumberMixedTimes() >= mixEH->BufferSize())
-               fMixInfo->FillHistogram(AliMixInfo::kMainEvents, mixEH->CurrentBinIndex());
-         } else {
-            fMixInfo->FillHistogram(AliMixInfo::kMainEvents, mixEH->CurrentBinIndex());
-         }
-
-//          if (mixEH->CurrentEntryMix() >= 0)
-         AliDebug(AliLog::kDebug + 1, Form("Main %lld %d [%lld,%lld] %d", mixEH->CurrentEntry(), mixEH->CurrentBinIndex(), mixEH->CurrentEntryMain(), mixEH->CurrentEntryMix(), mixEH->NumberMixed()));
+   if (fMixInfo && fInputEHMix) {
+      if (fInputEHMix->BufferSize() > 1) {
+         if (fInputEHMix->NumberMixedTimes() >= fInputEHMix->BufferSize())
+            fMixInfo->FillHistogram(AliMixInfo::kMainEvents, fInputEHMix->CurrentBinIndex());
+      } else {
+         fMixInfo->FillHistogram(AliMixInfo::kMainEvents, fInputEHMix->CurrentBinIndex());
       }
+      AliDebug(AliLog::kDebug, Form("Main %lld %d [%lld,%lld] %d", fInputEHMix->CurrentEntry(), fInputEHMix->CurrentBinIndex(), fInputEHMix->CurrentEntryMain(), fInputEHMix->CurrentEntryMix(), fInputEHMix->NumberMixed()));
    }
    // Post output data.
    PostData(1, fOutputList);
@@ -107,18 +106,19 @@ void AliAnalysisTaskMixInfo::UserExec(Option_t *)
 void AliAnalysisTaskMixInfo::UserExecMix(Option_t *)
 {
    // UserExecMix
-   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
-   AliMultiInputEventHandler *inEvHMain = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
-   if (inEvHMain) {
-      AliMixInputEventHandler *mixEH = dynamic_cast<AliMixInputEventHandler *>(inEvHMain->GetFirstMultiInputHandler());
-      if (!mixEH) return;
-      if (fMixInfo) fMixInfo->FillHistogram(AliMixInfo::kMixedEvents, mixEH->CurrentBinIndex());
-      if (mixEH->CurrentEntryMix() < 0) {
-         AliError("Mix entry is -1 and it should not happen !!!!!");
-         return ;
-      }
-      AliDebug(AliLog::kDebug, Form("Mixing %lld %d [%lld,%lld] %d", mixEH->CurrentEntry(), mixEH->CurrentBinIndex(), mixEH->CurrentEntryMain(), mixEH->CurrentEntryMix(), mixEH->NumberMixed()));
+
+   if (!fInputEHMix) return;
+
+   // fills bin index (even when it is -1, so we know out of range combinations)
+   if (fMixInfo) fMixInfo->FillHistogram(AliMixInfo::kMixedEvents, fInputEHMix->CurrentBinIndex());
+
+   // just test
+   if (fInputEHMix->CurrentEntryMix() < 0) {
+      AliError("Mix entry is -1 and it should not happen !!!!!");
+      return ;
    }
+   AliDebug(AliLog::kDebug, Form("Mixing %lld %d [%lld,%lld] %d", fInputEHMix->CurrentEntry(), fInputEHMix->CurrentBinIndex(), fInputEHMix->CurrentEntryMain(), fInputEHMix->CurrentEntryMix(), fInputEHMix->NumberMixed()));
+   if (AliLog::GetDebugLevel("", IsA()->GetName()) > AliLog::kDebug) PrintEventInfo();
    // Post output data.
    PostData(1, fOutputList);
 }
@@ -182,33 +182,57 @@ void AliAnalysisTaskMixInfo::SetDebugForAllClasses()
    AliDebug(AliLog::kDebug + 10, "->");
 }
 
-
+//_____________________________________________________________________________
 void AliAnalysisTaskMixInfo::InitMixInfo()
 {
    //
    // Init mixing info
    //
-   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
-   AliMultiInputEventHandler *inEvHMain = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
-   if (inEvHMain) {
-      AliMixInputEventHandler *mixEH = dynamic_cast<AliMixInputEventHandler *>(inEvHMain->GetFirstMultiInputHandler());
-      if (mixEH) {
-         fMixInfo = new AliMixInfo("mixInfo", "Mix title");
-         AliMixEventPool *evPool = mixEH->GetEventPool();
-         if (!evPool) {
-            //             TList *list = new TList;
-            if (fMixInfo) fMixInfo->CreateHistogram(AliMixInfo::kMainEvents, 1, 1, 2);
-            if (fMixInfo) fMixInfo->CreateHistogram(AliMixInfo::kMixedEvents, 1, 1, 2);
-         } else {
-            if (evPool->NeedInit()) evPool->Init();
-            Int_t num = evPool->GetListOfEntryLists()->GetEntriesFast();
-            if (fMixInfo) fMixInfo->CreateHistogram(AliMixInfo::kMainEvents, num, 1, num + 1);
-            if (fMixInfo) fMixInfo->CreateHistogram(AliMixInfo::kMixedEvents, num, 1, num + 1);
-         }
+   if (fInputEHMix) {
+      fMixInfo = new AliMixInfo("mixInfo", "Mix title");
+      AliMixEventPool *evPool = fInputEHMix->GetEventPool();
+      if (!evPool) {
+         //             TList *list = new TList;
+         if (fMixInfo) fMixInfo->CreateHistogram(AliMixInfo::kMainEvents, 1, 1, 2);
+         if (fMixInfo) fMixInfo->CreateHistogram(AliMixInfo::kMixedEvents, 1, 1, 2);
       } else {
-         AliError("No mixEH");
+         if (evPool->NeedInit()) evPool->Init();
+         Int_t num = evPool->GetListOfEntryLists()->GetEntriesFast();
+         if (fMixInfo) fMixInfo->CreateHistogram(AliMixInfo::kMainEvents, num, 1, num + 1);
+         if (fMixInfo) fMixInfo->CreateHistogram(AliMixInfo::kMixedEvents, num, 1, num + 1);
       }
-   } else {
-      AliError("No inEvHMain");
+   }
+}
+
+//_____________________________________________________________________________
+void AliAnalysisTaskMixInfo::PrintEventInfo()
+{
+   //
+   // Prints event info for all event mxing cuts
+   //
+   if (fInputEHMix) {
+      TObjArrayIter next(fInputEHMix->GetEventPool()->GetListOfEventCuts());
+      AliMixEventCutObj *cut;
+      AliInputEventHandler *ihMain = fInputEHMain->GetFirstInputEventHandler();
+      AliMultiInputEventHandler *ihMultiMix = fInputEHMix->GetFirstMultiInputHandler();
+      AliInputEventHandler *ihMix = 0;
+      if (ihMultiMix) ihMix = ihMultiMix->GetFirstInputEventHandler();
+      if (!ihMix) return;
+      while ((cut = (AliMixEventCutObj *) next())) {
+         cut->PrintValues(ihMain->GetEvent(), ihMix->GetEvent());
+      }
+   }
+}
+
+//_____________________________________________________________________________
+void AliAnalysisTaskMixInfo::InitInputHandlers()
+{
+   //
+   // Sets needed input handlers
+   //
+   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+   fInputEHMain = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
+   if (fInputEHMain) {
+      fInputEHMix = dynamic_cast<AliMixInputEventHandler *>(fInputEHMain->GetFirstMultiInputHandler());
    }
 }
index b57c5d2..6eed0e8 100644 (file)
@@ -15,6 +15,7 @@
 \r
 #include "AliAnalysisTaskSE.h"\r
 \r
+class AliMixInputEventHandler;\r
 class TList;\r
 class AliMixInfo;\r
 class AliAnalysisTaskMixInfo : public AliAnalysisTaskSE {\r
@@ -28,21 +29,27 @@ public:
    virtual void    UserExecMix(Option_t *option = "");\r
    virtual void    FinishTaskOutput();\r
 \r
+   void            InitInputHandlers();\r
    void            InitMixInfo();\r
    // sets log type to list of classes\r
    void            SetLogType(AliLog::EType_t type, TString allClasses = "");\r
    // sets correctly debug level to AliLog for all classes listed in fLogClassesString\r
    void            SetDebugForAllClasses();\r
 \r
+   void            PrintEventInfo();\r
+\r
 private:\r
 \r
-   TList       *fOutputList;     //! output list\r
-   AliMixInfo  *fMixInfo;        //!\r
+   AliMultiInputEventHandler  *fInputEHMain;       //! input multi handler\r
+   AliMixInputEventHandler    *fInputEHMix;        //! mix input handler\r
+\r
+   TList                      *fOutputList;        //! output list\r
+   AliMixInfo                 *fMixInfo;           //! mix info\r
 \r
-   Long64_t    fCurrentEntryTmp; //! temporary current entry number\r
+   Long64_t                    fCurrentEntryTmp;   //! temporary current entry number\r
 \r
-   AliLog::EType_t     fLogType;           // log type\r
-   TString             fLogClassesString;  // all classes string divided with ":"\r
+   AliLog::EType_t             fLogType;           // log type\r
+   TString                     fLogClassesString;  // all classes string divided with ":"\r
 \r
    AliAnalysisTaskMixInfo(const AliAnalysisTaskMixInfo &); // not implemented\r
    AliAnalysisTaskMixInfo &operator=(const AliAnalysisTaskMixInfo &); // not implemented\r
index 649a14d..aa76dad 100644 (file)
@@ -135,7 +135,7 @@ Int_t AliMixEventCutObj::GetBinNumber(Float_t num) const
    Int_t binNum = 0;
    for (Float_t iCurrent = fCutMin; iCurrent < fCutMax; iCurrent += fCutStep) {
       binNum++;
-      if ((num >= iCurrent) && (num <= iCurrent + fCutStep - fCutSmallVal)) {
+      if ((num >= iCurrent) && (num < iCurrent + fCutStep - fCutSmallVal)) {
          return binNum;
       }
    }
@@ -148,49 +148,68 @@ Int_t AliMixEventCutObj::GetIndex(AliVEvent *ev)
    //
    // Finds bin (index) in current cut from event information.
    //
+   return GetBinNumber(GetValue(ev));
+}
+
+//_________________________________________________________________________________________________
+Double_t AliMixEventCutObj::GetValue(AliVEvent* ev)
+{
+   //
+   // Returns value from event
+   //
+
    AliESDEvent *esd = dynamic_cast<AliESDEvent *>(ev);
-   if (esd) return GetIndex(esd);
+   if (esd) return GetValue(esd);
    AliAODEvent *aod = dynamic_cast<AliAODEvent *>(ev);
-   if (aod) return GetIndex(aod);
-   return -1;
+   if (aod) return GetValue(aod);
+
+   AliFatal("Event is not supported in Event Mixing cuts!!!!");
+   return -99999;
 }
 
 //_________________________________________________________________________________________________
-Int_t AliMixEventCutObj::GetIndex(AliESDEvent *ev)
+Double_t AliMixEventCutObj::GetValue(AliESDEvent* ev)
 {
    //
-   // Finds bin (index) in current cut from ESD event information.
+   // Returns value from esd event
    //
+
    switch (fCutType) {
       case kMultiplicity:
-         return GetBinNumber((Float_t)ev->GetNumberOfTracks());
+         return (Double_t)ev->GetNumberOfTracks();
       case kZVertex:
-         return GetBinNumber(ev->GetVertex()->GetZ());
+         return ev->GetVertex()->GetZ();
       case kNumberV0s:
-         return GetBinNumber(ev->GetNumberOfV0s());
+         return ev->GetNumberOfV0s();
       case kNumberTracklets:
          const AliMultiplicity *multESD = ev->GetMultiplicity();
-         return GetBinNumber(multESD->GetNumberOfTracklets());
+         return multESD->GetNumberOfTracklets();
    }
-   return -1;
+
+   AliFatal("Mixing Cut TYPE is not supported");
+   return -99999;
+
 }
 
 //_________________________________________________________________________________________________
-Int_t AliMixEventCutObj::GetIndex(AliAODEvent *ev)
+Double_t AliMixEventCutObj::GetValue(AliAODEvent* ev)
 {
    //
-   // Finds bin (index) in current cut from AOD event information.
+   // Returns value from aod event
    //
    switch (fCutType) {
       case kMultiplicity:
-         return GetBinNumber((Float_t)ev->GetNumberOfTracks());
+         return (Double_t) ev->GetNumberOfTracks();
       case kZVertex:
-         return GetBinNumber(ev->GetVertex(0)->GetZ());
+         return ev->GetVertex(0)->GetZ();
       case kNumberV0s:
-         return GetBinNumber(ev->GetNumberOfV0s());
+         return ev->GetNumberOfV0s();
    }
-   return -1;
+
+   AliFatal("Mixing Cut TYPE is not supported");
+   return -99999;
 }
+
 //_________________________________________________________________________________________________
 const char *AliMixEventCutObj::GetCutName(Int_t index) const
 {
@@ -220,3 +239,13 @@ void AliMixEventCutObj::SetCurrentValueToIndex(Int_t index)
    //
    for (Int_t i = 0; i < index; i++) AddStep();
 }
+
+//_________________________________________________________________________________________________
+void AliMixEventCutObj::PrintValues(AliVEvent* main, AliVEvent* mix)
+{
+   //
+   // Prints values of both events for current type
+   //
+   AliInfo(Form("name=%s main=%f mix=%f", GetCutName(), GetValue(main), GetValue(mix)));
+}
+
index 88fc1ca..0c04b85 100644 (file)
@@ -25,6 +25,7 @@ public:
 
    virtual void Print(const Option_t *) const;
    void PrintCurrentInterval();
+   void PrintValues(AliVEvent *main, AliVEvent* mix);
    void Reset();
    void AddStep();
 
@@ -37,8 +38,10 @@ public:
    Short_t     GetType() const { return fCutType; }
    Int_t       GetBinNumber(Float_t num) const;
    Int_t       GetIndex(AliVEvent *ev);
-   Int_t       GetIndex(AliESDEvent *ev);
-   Int_t       GetIndex(AliAODEvent *ev);
+   Double_t    GetValue(AliVEvent *ev);
+   Double_t    GetValue(AliESDEvent *ev);
+   Double_t    GetValue(AliAODEvent *ev);
+
    const char *GetCutName(Int_t index = -1) const;
 
    void        SetCurrentValueToIndex(Int_t index);
index 6d6930a..3874c67 100644 (file)
@@ -319,16 +319,12 @@ void AliMixInfo::DynamicExec(AliMixInfo *const mixInfo)
 
    Int_t mixNum = 1;
    if (text) {
-
-
       if (mixInfo) {
-
          AliMixEventPool *evPool = (AliMixEventPool *) mixInfo->GetEventPool("mixEventPool");
          if (evPool) {
             mixNum = evPool->GetMixNumber();
             if (binX - 1 >= 0) {
                if (!evPool->SetCutValuesFromBinIndex(binX - 1)) return;
-
             }
             text->SetName("mixInfoText");
             text->SetTextAlign(12);
@@ -340,7 +336,6 @@ void AliMixInfo::DynamicExec(AliMixInfo *const mixInfo)
             text->AddText(Form("BINCONTENT=%d", hist2DValue));
             TObjArray *eventCuts = evPool->GetListOfEventCuts();
             if (eventCuts) {
-
                TObjArrayIter next(eventCuts);
                AliMixEventCutObj *cut;
                while ((cut = (AliMixEventCutObj *) next())) {
@@ -348,9 +343,7 @@ void AliMixInfo::DynamicExec(AliMixInfo *const mixInfo)
                   else text->AddText(Form("%s <Out of Range>", cut->GetCutName()));
                }
             }
-
          }
-
       }
       switch (hist2DValue) {
          case 1 :