Port of new Event Mixing implementation
authormvala <mvala@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 25 Jan 2011 11:22:22 +0000 (11:22 +0000)
committermvala <mvala@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 25 Jan 2011 11:22:22 +0000 (11:22 +0000)
15 files changed:
ANALYSIS/AliAnalysisTaskSE.h
ANALYSIS/CMakelibEventMixing.pkg [new file with mode: 0644]
ANALYSIS/EventMixing/AliAnalysisTaskMixInfo.cxx [new file with mode: 0644]
ANALYSIS/EventMixing/AliAnalysisTaskMixInfo.h [new file with mode: 0644]
ANALYSIS/EventMixing/AliMixEventCutObj.cxx
ANALYSIS/EventMixing/AliMixEventCutObj.h
ANALYSIS/EventMixing/AliMixEventPool.cxx
ANALYSIS/EventMixing/AliMixEventPool.h
ANALYSIS/EventMixing/AliMixInfo.cxx [new file with mode: 0644]
ANALYSIS/EventMixing/AliMixInfo.h [new file with mode: 0644]
ANALYSIS/EventMixing/AliMixInputEventHandler.cxx [new file with mode: 0644]
ANALYSIS/EventMixing/AliMixInputEventHandler.h [new file with mode: 0644]
ANALYSIS/EventMixing/AliMixInputHandlerInfo.cxx
ANALYSIS/EventMixing/AliMixInputHandlerInfo.h
ANALYSIS/EventMixingLinkDef.h

index c732202..89b7434 100644 (file)
@@ -43,7 +43,7 @@ class AliAnalysisTaskSE : public AliAnalysisTask
     // To be implemented by user
     virtual void   UserCreateOutputObjects()  {;}
     virtual void   UserExec(Option_t* /*option*/) {;}
-    virtual void   UserExecMix(Option_t *option = "") {;}
+    virtual void   UserExecMix(Option_t */*option*/) {;}
     virtual Bool_t UserNotify() {return kTRUE;}
     virtual void   NotifyRun()  {;}
     
diff --git a/ANALYSIS/CMakelibEventMixing.pkg b/ANALYSIS/CMakelibEventMixing.pkg
new file mode 100644 (file)
index 0000000..453c5be
--- /dev/null
@@ -0,0 +1,47 @@
+#--------------------------------------------------------------------------------#
+# Package File for TENDER                                                        #
+# Author : Johny Jose (johny.jose@cern.ch)                                       #
+# Variables Defined :                                                            #
+#                                                                                #
+# SRCS - C++ source files                                                        #
+# HDRS - C++ header files                                                        #
+# DHDR - ROOT Dictionary Linkdef header file                                     #
+# CSRCS - C source files                                                         #
+# CHDRS - C header files                                                         #
+# EINCLUDE - Include directories                                                 #
+# EDEFINE - Compiler definitions                                                 #
+# ELIBS - Extra libraries to link                                                #
+# ELIBSDIR - Extra library directories                                           #
+# PACKFFLAGS - Fortran compiler flags for package                                #
+# PACKCXXFLAGS - C++ compiler flags for package                                  #
+# PACKCFLAGS - C compiler flags for package                                      #
+# PACKSOFLAGS - Shared library linking flags                                     #
+# PACKLDFLAGS - Module linker flags                                              #
+# PACKBLIBS - Libraries to link (Executables only)                               #
+# EXPORT - Header files to be exported                                           #
+# CINTHDRS - Dictionary header files                                             #
+# CINTAUTOLINK - Set automatic dictionary generation                             #
+# ARLIBS - Archive Libraries and objects for linking (Executables only)          #
+# SHLIBS - Shared Libraries and objects for linking (Executables only)           #
+#--------------------------------------------------------------------------------#
+
+set ( SRCS EventMixing/AliMixEventCutObj.cxx
+  EventMixing/AliMixEventPool.cxx
+  EventMixing/AliMixInfo.cxx
+  EventMixing/AliMixInputHandlerInfo.cxx
+  EventMixing/AliMixInputEventHandler.cxx
+  EventMixing/AliAnalysisTaskMixInfo.cxx)
+
+string ( REPLACE ".cxx" ".h" HDRS "${SRCS}" )
+
+set ( DHDR  EventMixingLinkDef.h)
+
+string ( REPLACE ".cxx" ".h" EXPORT "${SRCS}" )
+
+set ( EINCLUDE  ANALYSIS ANALYSIS/EventMixing)
+
+if( ALICE_TARGET STREQUAL "win32gcc")
+       
+               set ( PACKSOFLAGS  ${SOFLAGS} -L${ALICE_ROOT}/lib/tgt_${ALICE_TARGET} -lSTEERBase -lANALYSIS -lANALYSISalice )
+
+endif( ALICE_TARGET STREQUAL "win32gcc")
diff --git a/ANALYSIS/EventMixing/AliAnalysisTaskMixInfo.cxx b/ANALYSIS/EventMixing/AliAnalysisTaskMixInfo.cxx
new file mode 100644 (file)
index 0000000..c6bfcd6
--- /dev/null
@@ -0,0 +1,215 @@
+//
+// Class AliAnalysisTaskMixInfo
+//
+// AliAnalysisTaskMixInfo is task
+// for mixing info
+//
+// authors:
+//          Martin Vala (martin.vala@cern.ch)
+//
+
+#include <TList.h>
+
+#include "AliAnalysisManager.h"
+
+#include "AliMixInputEventHandler.h"
+#include "AliAnalysisTaskMixInfo.h"
+#include "AliMixInfo.h"
+#include "AliMixEventPool.h"
+
+ClassImp(AliAnalysisTaskMixInfo)
+
+//________________________________________________________________________
+AliAnalysisTaskMixInfo::AliAnalysisTaskMixInfo(const char *name)
+   : AliAnalysisTaskSE(name),
+     fOutputList(0),
+     fMixInfo(0),
+     fCurrentEntryTmp(-1),
+     fLogType(AliLog::kInfo),
+     fLogClassesString()
+{
+   //
+   // Constructor
+   //
+   DefineOutput(1, TList::Class());
+}
+
+//________________________________________________________________________
+AliAnalysisTaskMixInfo::~AliAnalysisTaskMixInfo()
+{
+   //
+   // Destructor
+   //
+   if (fOutputList && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) delete fOutputList;
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskMixInfo::UserCreateOutputObjects()
+{
+   // Create histograms
+   // Called once
+
+   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);
+         }
+      }
+   }
+
+   if (fMixInfo) fOutputList->Add(fMixInfo);
+
+   // Post output data.
+   PostData(1, fOutputList);
+}
+
+//________________________________________________________________________
+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->NumberMixed(), mixEH->CurrentEntryMain(), mixEH->CurrentEntryMix(), mixEH->NumberMixed()));
+
+   }
+   // Post output data.
+   PostData(1, fOutputList);
+}
+
+//________________________________________________________________________
+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 (fMixInfo) fMixInfo->FillHistogram(AliMixInfo::kMixedEvents, mixEH->CurrentBinIndex());
+      if (!mixEH || mixEH->CurrentEntryMix() < 0) {
+         AliError("Mix entry is -1 and it should not happen !!!!!");
+         return ;
+      }
+      if (mixEH)
+         AliDebug(AliLog::kDebug, Form("Mixing %lld %d [%lld,%lld] %d", mixEH->CurrentEntry(), mixEH->NumberMixed(), mixEH->CurrentEntryMain(), mixEH->CurrentEntryMix(), mixEH->CurrentBinIndex()));
+   }
+   // Post output data.
+   PostData(1, fOutputList);
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskMixInfo::FinishTaskOutput()
+{
+   // FinishTaskOutput
+   if (fMixInfo) fMixInfo->Print();
+}
+
+
+//________________________________________________________________________
+void AliAnalysisTaskMixInfo::Terminate(Option_t *)
+{
+   // Draw result to the screen
+   // Called once at the end of the query
+   fOutputList = dynamic_cast<TList *>(GetOutputData(1));
+   if (!fOutputList) {
+      AliError("fOutputList not available");
+      return;
+   }
+   fOutputList->Print();
+   fMixInfo = (AliMixInfo *) fOutputList->FindObject("mixInfo");
+   if (fMixInfo) {
+      fMixInfo->Draw("HIST");
+      AliMixEventPool *evPool = (AliMixEventPool *) fMixInfo->GetEventPool("mixEventPool");
+      if (evPool) evPool->Print();
+   }
+}
+
+//_____________________________________________________________________________
+void AliAnalysisTaskMixInfo::SetLogType(AliLog::EType_t type, TString allClasses)
+{
+   //
+   // Set Log level for this and other classes (list of their names)
+   //
+   AliDebug(AliLog::kDebug + 10, "<-");
+   fLogType = type;
+   fLogClassesString = allClasses;
+   SetDebugForAllClasses();
+   AliDebug(AliLog::kDebug + 10, "->");
+}
+
+//_____________________________________________________________________________
+void AliAnalysisTaskMixInfo::SetDebugForAllClasses()
+{
+   //
+   // Set debug level for all classes for which it is required
+   //
+   AliDebug(AliLog::kDebug + 10, "<-");
+   TObjArray *array = fLogClassesString.Tokenize(":");
+   TObjString *str;
+   TString strr;
+   for (Int_t i = 0; i < array->GetEntriesFast(); i++) {
+      str = (TObjString *) array->At(i);
+      strr = str->GetString();
+      AliLog::SetClassDebugLevel(strr.Data(), fLogType);
+      AliDebug(AliLog::kDebug + 5, Form("Setting Debug level %d to %s ...", (Int_t)fLogType - AliLog::kDebug, strr.Data()));
+   }
+   AliDebug(AliLog::kDebug + 10, "->");
+}
+
+
+void AliAnalysisTaskMixInfo::InitMixInfo()
+{
+   //
+   // Init mixing info
+   //
+   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+   AliMultiInputEventHandler *inEvHMain = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
+   if (inEvHMain) {
+      //         AliMixEventInputHandler *mixEH = dynamic_cast<AliMixEventInputHandler *>(inEvHMain->MixingHandler());
+      AliMixInputEventHandler *mixEH = dynamic_cast<AliMixInputEventHandler *>(inEvHMain->GetFirstMultiInputHandler());
+      if (mixEH) {
+         fMixInfo = new AliMixInfo("mixInfo", "Mix title");
+//             if(fMixInfo) fMixInfo->SetOutputList(fOutputList);
+         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);
+         }
+      } else {
+         AliError("No mixEH");
+      }
+   } else {
+      AliError("No inEvHMain");
+   }
+}
diff --git a/ANALYSIS/EventMixing/AliAnalysisTaskMixInfo.h b/ANALYSIS/EventMixing/AliAnalysisTaskMixInfo.h
new file mode 100644 (file)
index 0000000..b57c5d2
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef ALIANALYSISTASKMIXINFO_H\r
+#define ALIANALYSISTASKMIXINFO_H\r
+\r
+//\r
+// Class AliAnalysisTaskMixInfo\r
+//\r
+// AliAnalysisTaskMixInfo is task\r
+// for mixing info\r
+//\r
+// authors:\r
+//          Martin Vala (martin.vala@cern.ch)\r
+//\r
+\r
+#include "AliLog.h"\r
+\r
+#include "AliAnalysisTaskSE.h"\r
+\r
+class TList;\r
+class AliMixInfo;\r
+class AliAnalysisTaskMixInfo : public AliAnalysisTaskSE {\r
+public:\r
+   AliAnalysisTaskMixInfo(const char *name = "<default name>");\r
+   virtual ~AliAnalysisTaskMixInfo();\r
+\r
+   virtual void    UserCreateOutputObjects();\r
+   virtual void    UserExec(Option_t *option);\r
+   virtual void    Terminate(Option_t *);\r
+   virtual void    UserExecMix(Option_t *option = "");\r
+   virtual void    FinishTaskOutput();\r
+\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
+private:\r
+\r
+   TList       *fOutputList;     //! output list\r
+   AliMixInfo  *fMixInfo;        //!\r
+\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
+\r
+   AliAnalysisTaskMixInfo(const AliAnalysisTaskMixInfo &); // not implemented\r
+   AliAnalysisTaskMixInfo &operator=(const AliAnalysisTaskMixInfo &); // not implemented\r
+\r
+   ClassDef(AliAnalysisTaskMixInfo, 1); // example of analysis\r
+};\r
+\r
+#endif\r
index 55bc5cb..618467a 100644 (file)
@@ -4,7 +4,7 @@
 // AliMixEventCutObj object contains information about one cut on for event mixing
 // used by AliMixEventPool class
 //
-// authors: 
+// authors:
 //          Martin Vala (martin.vala@cern.ch)
 //
 
@@ -19,170 +19,202 @@ ClassImp(AliMixEventCutObj)
 
 //_________________________________________________________________________________________________
 AliMixEventCutObj::AliMixEventCutObj(EEPAxis_t type, Float_t min, Float_t max, Float_t step) : TObject(),
-    fCutType((Short_t)type),
-    fCutMin(min),
-    fCutMax(max),
-    fCutStep(step),
-    fCutSmallVal((max - min) / (step*1e6)),
-    fCurrentVal(min),
-    fNoMore(kFALSE) {
-  //
-  // Default constructor.
-  //
-
-  AliDebug(AliLog::kDebug + 2, "<-");
-
-  AliDebug(AliLog::kDebug + 2, "->");
+   fCutType((Int_t)type),
+   fCutMin(min),
+   fCutMax(max),
+   fCutStep(step),
+   fCutSmallVal(0),
+   fCurrentVal(min)
+{
+   //
+   // Default constructor
+   //
+   AliDebug(AliLog::kDebug + 5, "<-");
+   if (fCutStep < 1e-5) AliError("fCutStep is too small !!! This cut will not work !!!");
+   AliDebug(AliLog::kDebug + 5, "->");
 }
+
 //_________________________________________________________________________________________________
-AliMixEventCutObj::AliMixEventCutObj(const AliMixEventCutObj& obj) : TObject(obj),
-    fCutType(obj.fCutType),
-    fCutMin(obj.fCutMin),
-    fCutMax(obj.fCutMax),
-    fCutStep(obj.fCutStep),
-    fCutSmallVal(obj.fCutSmallVal),
-    fCurrentVal(obj.fCurrentVal),
-    fNoMore(obj.fNoMore) {
-  //
-  // Copy constructor.
-  //
+AliMixEventCutObj::AliMixEventCutObj(const AliMixEventCutObj &obj) : TObject(obj),
+   fCutType(obj.fCutType),
+   fCutMin(obj.fCutMin),
+   fCutMax(obj.fCutMax),
+   fCutStep(obj.fCutStep),
+   fCutSmallVal(obj.fCutSmallVal),
+   fCurrentVal(obj.fCurrentVal)
+{
+   //
+   // Copy constructor
+   //
+   AliDebug(AliLog::kDebug + 5, "<-");
+   AliDebug(AliLog::kDebug + 5, "->");
 }
 
 //_________________________________________________________________________________________________
-void AliMixEventCutObj::Reset() {
-  //
-  // Reset cut.
-  //
-
-  AliDebug(AliLog::kDebug + 2, "<-");
-  fCurrentVal = fCutMin - fCutStep;
-  fNoMore = kFALSE;
-  AliDebug(AliLog::kDebug + 2, "->");
+AliMixEventCutObj& AliMixEventCutObj::operator=(const AliMixEventCutObj& obj)
+{
+   //
+   // Assigned operator
+   //
+   if (&obj != this) {
+      TObject::operator=(obj);
+      fCutType = obj.fCutType;
+      fCutMin = obj.fCutMin;
+      fCutMax = obj.fCutMax;
+      fCutStep = obj.fCutStep;
+      fCutSmallVal = obj.fCutSmallVal;
+      fCurrentVal = obj.fCurrentVal;
+//       fNoMore = obj.fNoMore;
+   }
+   return *this;
 }
+
+
 //_________________________________________________________________________________________________
-Bool_t AliMixEventCutObj::HasMore() const {
-  //
-  // Return kTRUE when fCurrentVal is in interval of cut range
-  //
-  
-  return ((fCurrentVal + fCutStep) < fCutMax);
+void AliMixEventCutObj::Reset()
+{
+   //
+   // Reset cut
+   //
+   AliDebug(AliLog::kDebug + 5, "<-");
+   fCurrentVal = fCutMin - fCutStep;
+   AliDebug(AliLog::kDebug + 5, "->");
+}
+//_________________________________________________________________________________________________
+Bool_t AliMixEventCutObj::HasMore() const
+{
+   //
+   // Return kTRUE when fCurrentVal is in interval of cut range
+   //
+   return ((fCurrentVal + fCutStep) < fCutMax);
 }
 
 //_________________________________________________________________________________________________
-void AliMixEventCutObj::AddStep() {
-  //
-  // Adds step
-  //
-  
-  fCurrentVal += fCutStep;
+void AliMixEventCutObj::AddStep()
+{
+   //
+   // Adds step
+   //
+   fCurrentVal += fCutStep;
 }
 
 //_________________________________________________________________________________________________
-void AliMixEventCutObj::Print(const Option_t *) const {
-  //
-  // Prints cut information
-  //
-  
-  AliInfo(Form("%d %f %f %f", fCutType, fCutMin, fCutMax, fCutStep));
+void AliMixEventCutObj::Print(const Option_t *) const
+{
+   //
+   // Prints cut information
+   //
+   AliInfo(Form("%s %f %f %f", GetCutName(fCutType), fCutMin, fCutMax, fCutStep));
 }
 //_________________________________________________________________________________________________
-void AliMixEventCutObj::PrintCurrentInterval() {
-  //
-  // Prints current cut interval information
-  //
-  
-  AliInfo(Form("%s <%f,%f>", GetNameOfCut(fCutType), GetMin(), GetMax()));
+void AliMixEventCutObj::PrintCurrentInterval()
+{
+   //
+   // Prints current cut interval information
+   //
+   AliDebug(AliLog::kDebug, Form("%s <%f,%f>", GetCutName(fCutType), GetMin(), GetMax()));
 }
 
 //_________________________________________________________________________________________________
-Int_t AliMixEventCutObj::GetNumberOfBins() const {
-  //
-  // Returns number of bins
-  //
-  
-  if (!fCutStep) return -1;
-  return (Int_t)((fCutMax -fCutMin) / fCutStep);
+Int_t AliMixEventCutObj::GetNumberOfBins() const
+{
+   //
+   // Returns number of bins
+   //
+   if (fCutStep < 1e-5) return -1;
+   return (Int_t)((fCutMax - fCutMin) / fCutStep);
 }
 
 //_________________________________________________________________________________________________
-Int_t AliMixEventCutObj::GetBinNumber(Float_t num) const {
-  //
-  // Returns bin (index) number in current cut.
-  // Returns -1 in case of out of range
-  //
-  
-  Int_t binNum = 0;
-  for (Float_t i = fCutMin;i <= fCutMax - fCutSmallVal;i += fCutStep) {
-    binNum++;
-    if ((num >= i) && (num <= i + fCutStep - fCutSmallVal)) return binNum;
-
-  }
-  return -1;
+Int_t AliMixEventCutObj::GetBinNumber(Float_t num) const
+{
+   //
+   // Returns bin (index) number in current cut.
+   // Returns -1 in case of out of range
+   //
+   Int_t binNum = 0;
+   for (Float_t i = fCutMin; i <= fCutMax - fCutSmallVal; i += fCutStep) {
+      binNum++;
+      if ((num >= i) && (num <= i + fCutStep - fCutSmallVal)) return binNum;
+   }
+   return -1;
 }
 
 //_________________________________________________________________________________________________
-Int_t AliMixEventCutObj::GetIndex(AliVEvent* ev) {
-  //
-  // Finds bin (index) in current cut from event information.
-  //
-  
-  AliESDEvent *esd = dynamic_cast<AliESDEvent*>(ev);
-  if (esd) return GetIndex(esd);
-  AliAODEvent *aod = dynamic_cast<AliAODEvent*>(ev);
-  if (aod) return GetIndex(aod);
-  return -1;
+Int_t AliMixEventCutObj::GetIndex(AliVEvent *ev)
+{
+   //
+   // Finds bin (index) in current cut from event information.
+   //
+   AliESDEvent *esd = dynamic_cast<AliESDEvent *>(ev);
+   if (esd) return GetIndex(esd);
+   AliAODEvent *aod = dynamic_cast<AliAODEvent *>(ev);
+   if (aod) return GetIndex(aod);
+   return -1;
 }
 
 //_________________________________________________________________________________________________
-Int_t AliMixEventCutObj::GetIndex(AliESDEvent* ev) {
-  //
-  // Finds bin (index) in current cut from ESD event information.
-  //
-  switch (fCutType) {
-  case kMultiplicity:
-    return GetBinNumber((Float_t)ev->GetNumberOfTracks());
-  case kZVertex:
-    return GetBinNumber(ev->GetVertex()->GetZ());
-  case kNumberV0s:
-    return GetBinNumber(ev->GetNumberOfV0s());
-  case kNumberTracklets:
-    const AliMultiplicity* multESD = ev->GetMultiplicity();
-    return GetBinNumber(multESD->GetNumberOfTracklets());
-  }
-  return -1;
+Int_t AliMixEventCutObj::GetIndex(AliESDEvent *ev)
+{
+   //
+   // Finds bin (index) in current cut from ESD event information.
+   //
+   switch (fCutType) {
+      case kMultiplicity:
+         return GetBinNumber((Float_t)ev->GetNumberOfTracks());
+      case kZVertex:
+         return GetBinNumber(ev->GetVertex()->GetZ());
+      case kNumberV0s:
+         return GetBinNumber(ev->GetNumberOfV0s());
+      case kNumberTracklets:
+         const AliMultiplicity *multESD = ev->GetMultiplicity();
+         return GetBinNumber(multESD->GetNumberOfTracklets());
+   }
+   return -1;
 }
 
 //_________________________________________________________________________________________________
-Int_t AliMixEventCutObj::GetIndex(AliAODEvent* ev) {
-  //
-  // Finds bin (index) in current cut from AOD event information.
-  //
-  switch (fCutType) {
-  case kMultiplicity:
-    return GetBinNumber((Float_t)ev->GetNumberOfTracks());
-  case kZVertex:
-    return GetBinNumber(ev->GetVertex(0)->GetZ());
-  case kNumberV0s:
-    return GetBinNumber(ev->GetNumberOfV0s());
-  }
-  return -1;
+Int_t AliMixEventCutObj::GetIndex(AliAODEvent *ev)
+{
+   //
+   // Finds bin (index) in current cut from AOD event information.
+   //
+   switch (fCutType) {
+      case kMultiplicity:
+         return GetBinNumber((Float_t)ev->GetNumberOfTracks());
+      case kZVertex:
+         return GetBinNumber(ev->GetVertex(0)->GetZ());
+      case kNumberV0s:
+         return GetBinNumber(ev->GetNumberOfV0s());
+   }
+   return -1;
 }
 //_________________________________________________________________________________________________
-const char* AliMixEventCutObj::GetNameOfCut(Short_t index) const
+const char *AliMixEventCutObj::GetCutName(Int_t index) const
 {
-  //
-  // Retruns name of cut
-  //
-  switch ((Int_t)index) {
-    case kMultiplicity:
-      return "Multiplicity";
-    case kZVertex:
-      return "ZVertex";
-    case kNumberV0s:
-      return "NumberV0s";
-    case kNumberTracklets:
-      return "NumberTracklets";
-  }
-  return "";
+   //
+   // Retruns name of cut
+   //
+
+   if (index < 0) index = fCutType;
+   switch (index) {
+      case kMultiplicity:
+         return "Multiplicity";
+      case kZVertex:
+         return "ZVertex";
+      case kNumberV0s:
+         return "NumberV0s";
+      case kNumberTracklets:
+         return "NumberTracklets";
+   }
+   return "";
 }
 
+//_________________________________________________________________________________________________
+void AliMixEventCutObj::SetCurrentValueToIndex(Int_t index)
+{
+   //
+   // Sets current value to index
+   //
+   for (Int_t i = 0; i < index; i++) AddStep();
+}
index 2a304fa..88fc1ca 100644 (file)
@@ -4,7 +4,7 @@
 // AliMixEventCutObj object contains information about one cut on for event mixing
 // used by AliMixEventPool class
 //
-// authors: 
+// authors:
 //          Martin Vala (martin.vala@cern.ch)
 //
 
 class AliVEvent;
 class AliAODEvent;
 class AliESDEvent;
-class AliMixEventCutObj : public TObject
-{
+class AliMixEventCutObj : public TObject {
 public:
-  enum EEPAxis_t {kMultiplicity=0, kZVertex=1, kNumberV0s=2, kNumberTracklets=3, kAllEventAxis=4};
-    
-    AliMixEventCutObj(EEPAxis_t type=kMultiplicity,Float_t min=0,Float_t max=0, Float_t step=0);
-    AliMixEventCutObj(const AliMixEventCutObj& obj);
-    virtual ~AliMixEventCutObj() {;}
-
-    virtual void Print(const Option_t *) const;
-    void PrintCurrentInterval();
-    void Reset();
-    void AddStep();
-
-    Bool_t      HasMore() const;
-
-    Int_t       GetNumberOfBins() const;
-    Float_t     GetMin() const { return fCurrentVal;}
-    Float_t     GetMax() const { return fCurrentVal+fCutStep-fCutSmallVal;}
-    Float_t     GetStep() const { return fCutStep;}
-    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);
-    const char *GetNameOfCut(Short_t index) const;
-    
-private:
-    Short_t     fCutType;       // cut type
-    Float_t     fCutMin;        // cut min
-    Float_t     fCutMax;        // cut max
-    Float_t     fCutStep;       // cut step
-    Float_t     fCutSmallVal;   // small value
+   enum EEPAxis_t {kMultiplicity = 0, kZVertex = 1, kNumberV0s = 2, kNumberTracklets = 3, kAllEventAxis = 4};
+
+   AliMixEventCutObj(EEPAxis_t type = kMultiplicity, Float_t min = 0.0, Float_t max = 0.0, Float_t step = 1.0);
+   AliMixEventCutObj(const AliMixEventCutObj &obj);
+   AliMixEventCutObj &operator=(const AliMixEventCutObj &obj);
+
+   virtual void Print(const Option_t *) const;
+   void PrintCurrentInterval();
+   void Reset();
+   void AddStep();
+
+   Bool_t      HasMore() const;
 
-    Float_t     fCurrentVal;    // current value
-    Bool_t      fNoMore;        // flag for no more bins
+   Int_t       GetNumberOfBins() const;
+   Float_t     GetMin() const { return fCurrentVal; }
+   Float_t     GetMax() const { return fCurrentVal + fCutStep - fCutSmallVal; }
+   Float_t     GetStep() const { return fCutStep; }
+   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);
+   const char *GetCutName(Int_t index = -1) const;
+
+   void        SetCurrentValueToIndex(Int_t index);
+
+private:
+   Int_t       fCutType;       // cut type
+   Float_t     fCutMin;        // cut min
+   Float_t     fCutMax;        // cut max
+   Float_t     fCutStep;       // cut step
+   Float_t     fCutSmallVal;   // small value
 
-    AliMixEventCutObj& operator=(const AliMixEventCutObj& ) { return *this;}
+   Float_t     fCurrentVal;    // current value
 
-    ClassDef(AliMixEventCutObj, 1)
+   ClassDef(AliMixEventCutObj, 1)
 };
 
 #endif
index 8b03fef..79e4884 100644 (file)
@@ -1,7 +1,7 @@
 //
 // Class AliMixEventPool
 //
-// AliMixEventPool is used to find 
+// AliMixEventPool is used to find
 // similar events
 //
 // author:
 ClassImp(AliMixEventPool)
 
 //_________________________________________________________________________________________________
-AliMixEventPool::AliMixEventPool(const char* name, const char* title) : TNamed(name, title),
-    fListOfEntryList(),
-    fListOfEventCuts(),
-    fBinNumber(0) {
-  //
-  // Default constructor.
-  //
-
-  AliDebug(AliLog::kDebug + 5, "<-");
-  AliDebug(AliLog::kDebug + 5, "->");
+AliMixEventPool::AliMixEventPool(const char *name, const char *title) : TNamed(name, title),
+   fListOfEntryList(),
+   fListOfEventCuts(),
+   fBinNumber(0),
+   fBufferSize(0),
+   fMixNumber(0)
+{
+   //
+   // Default constructor.
+   //
+   AliDebug(AliLog::kDebug + 5, "<-");
+   AliDebug(AliLog::kDebug + 5, "->");
 }
 //_________________________________________________________________________________________________
-AliMixEventPool::AliMixEventPool(const AliMixEventPool& obj) : TNamed(obj),
-    fListOfEntryList(obj.fListOfEntryList),
-    fListOfEventCuts(obj.fListOfEventCuts),
-    fBinNumber(obj.fBinNumber) {
-  //
-  // Copy constructor
-  //
-  AliDebug(AliLog::kDebug + 5, "<-");
-  AliDebug(AliLog::kDebug + 5, "->");
+AliMixEventPool::AliMixEventPool(const AliMixEventPool &obj) : TNamed(obj),
+   fListOfEntryList(obj.fListOfEntryList),
+   fListOfEventCuts(obj.fListOfEventCuts),
+   fBinNumber(obj.fBinNumber),
+   fBufferSize(obj.fBufferSize),
+   fMixNumber(obj.fMixNumber)
+{
+   //
+   // Copy constructor
+   //
+   AliDebug(AliLog::kDebug + 5, "<-");
+   AliDebug(AliLog::kDebug + 5, "->");
 }
+
 //_________________________________________________________________________________________________
-AliMixEventPool::~AliMixEventPool() {
-  //
-  // Destructor
-  //
-  AliDebug(AliLog::kDebug + 5, "<-");
-  AliDebug(AliLog::kDebug + 5, "->");
+AliMixEventPool& AliMixEventPool::operator=(const AliMixEventPool& obj)
+{
+   //
+   // Assigned operator
+   //
+   if (&obj != this) {
+      TNamed::operator=(obj);
+      fListOfEntryList = obj.fListOfEntryList;
+      fListOfEventCuts = obj.fListOfEventCuts;
+      fBinNumber = obj.fBinNumber;
+      fBufferSize = obj.fBufferSize;
+      fMixNumber = obj.fMixNumber;
+   }
+   return *this;
 }
-//_________________________________________________________________________________________________
-void AliMixEventPool::AddCut(AliMixEventCutObj* cut) {
-  //
-  // Adds cut
-  //
 
-  if (cut) fListOfEventCuts.Add(cut);
+
+//_________________________________________________________________________________________________
+AliMixEventPool::~AliMixEventPool()
+{
+   //
+   // Destructor
+   //
+   AliDebug(AliLog::kDebug + 5, "<-");
+   AliDebug(AliLog::kDebug + 5, "->");
 }
 //_________________________________________________________________________________________________
-void AliMixEventPool::Print(const Option_t* option) const {
-  //
-  // Prints usefull information
-  //
-
-  TObjArrayIter next(&fListOfEventCuts);
-  //   Int_t c=0;
-  AliMixEventCutObj *cut;
-  while ((cut = (AliMixEventCutObj *) next())) {
-    cut->Print(option);
-  }
-
-  AliInfo(Form("NumOfEntryList %d", fListOfEntryList.GetEntries()));
-
-  TEntryList *el;
-  for (Int_t i = 0;i < fListOfEntryList.GetEntries();i++) {
-    el = (TEntryList*) fListOfEntryList.At(i);
-
-    AliInfo(Form("EntryList[%d] %lld", i, el->GetN()));
-  }
+void AliMixEventPool::AddCut(AliMixEventCutObj *cut)
+{
+   //
+   // Adds cut
+   //
+   if (cut) fListOfEventCuts.Add(new AliMixEventCutObj(*cut));
 }
 //_________________________________________________________________________________________________
-Int_t AliMixEventPool::Init() {
-  //
-  // Init event pool
-  //
-  AliDebug(AliLog::kDebug+5,"<-");
-  CreateEntryListsRecursivly(fListOfEventCuts.GetEntries() - 1);
-
-  fBinNumber++;
-  AliDebug(AliLog::kDebug, Form("fBinnumber = %d", fBinNumber));
-
-  AddEntryList();
-  AliDebug(AliLog::kDebug+5,"->");
-  return 0;
+void AliMixEventPool::Print(const Option_t *option) const
+{
+   //
+   // Prints usefull information
+   //
+   TObjArrayIter next(&fListOfEventCuts);
+   //   Int_t c=0;
+   AliMixEventCutObj *cut;
+   while ((cut = (AliMixEventCutObj *) next())) {
+      cut->Print(option);
+   }
+   AliDebug(AliLog::kDebug, Form("NumOfEntryList %d", fListOfEntryList.GetEntries()));
+   TEntryList *el;
+   for (Int_t i = 0; i < fListOfEntryList.GetEntries(); i++) {
+      el = (TEntryList *) fListOfEntryList.At(i);
+      AliDebug(AliLog::kDebug, Form("EntryList[%d] %lld", i, el->GetN()));
+   }
+}
+//_________________________________________________________________________________________________
+Int_t AliMixEventPool::Init()
+{
+   //
+   // Init event pool
+   //
+   AliDebug(AliLog::kDebug + 5, "<-");
+   CreateEntryListsRecursivly(fListOfEventCuts.GetEntries() - 1);
+   fBinNumber++;
+   AliDebug(AliLog::kDebug, Form("fBinnumber = %d", fBinNumber));
+   AddEntryList();
+   AliDebug(AliLog::kDebug + 5, "->");
+   return 0;
 }
 
 //_________________________________________________________________________________________________
-void AliMixEventPool::CreateEntryListsRecursivly(Int_t index) {
-  //
-  // Helper function which create entrylist recursivly
-  //
-  AliDebug(AliLog::kDebug+5,"<-");
-  AliMixEventCutObj *cut;
-  if (index >= 0) {
-    AliDebug(AliLog::kDebug, Form("index = %d", index));
-    cut = dynamic_cast<AliMixEventCutObj*>(fListOfEventCuts.At(index));
-    cut->Reset();
-
-    while (cut->HasMore()) {
-      cut->AddStep();
-      CreateEntryListsRecursivly(index - 1);
-      if (cut->HasMore()) {
-        fBinNumber++;
-        AliDebug(AliLog::kDebug, Form("fBinnumber = %d", fBinNumber));
-        AddEntryList();
-        //                 PrintCurrentCutIntervals();
+void AliMixEventPool::CreateEntryListsRecursivly(Int_t index)
+{
+   //
+   // Helper function which create entrylist recursivly
+   //
+   AliDebug(AliLog::kDebug + 5, "<-");
+   AliMixEventCutObj *cut;
+   if (index >= 0) {
+      AliDebug(AliLog::kDebug, Form("index = %d", index));
+      cut = dynamic_cast<AliMixEventCutObj *>(fListOfEventCuts.At(index));
+      cut->Reset();
+      while (cut->HasMore()) {
+         cut->AddStep();
+         CreateEntryListsRecursivly(index - 1);
+         if (cut->HasMore()) {
+            fBinNumber++;
+            AliDebug(AliLog::kDebug, Form("fBinnumber = %d", fBinNumber));
+            AddEntryList();
+            //                 PrintCurrentCutIntervals();
+         }
       }
-    }
+   }
+   AliDebug(AliLog::kDebug + 5, "->");
+}
 
-  }
-  AliDebug(AliLog::kDebug+5,"->");
+//_________________________________________________________________________________________________
+TEntryList *AliMixEventPool::AddEntryList()
+{
+   //
+   // Adds endtry list
+   //
+   AliDebug(AliLog::kDebug + 5, "<-");
+   TObjArrayIter next(&fListOfEventCuts);
+   AliMixEventCutObj *cut;
+   while ((cut = (AliMixEventCutObj *) next())) {
+      if (cut) cut->PrintCurrentInterval();
+   }
+   TEntryList *el = new TEntryList;
+   fListOfEntryList.Add(el);
+   AliDebug(AliLog::kDebug, Form("Number in Entry list -> %lld", el->GetN()));
+   AliDebug(AliLog::kDebug + 5, "->");
+   return el;
 }
 
 //_________________________________________________________________________________________________
-TEntryList* AliMixEventPool::AddEntryList() {
-  //
-  // Adds endtry list
-  //
-  
-  AliDebug(AliLog::kDebug+5,"<-");
-  
-  TObjArrayIter next(&fListOfEventCuts);
-  AliMixEventCutObj *cut;
-  while ((cut = (AliMixEventCutObj*) next())) {
-    if (cut) cut->PrintCurrentInterval();
-  }
-
-  TEntryList *el = new TEntryList;
-  fListOfEntryList.Add(el);
-
-  AliDebug(AliLog::kDebug, Form("Number in Entry list -> %lld", el->GetN()));
-  AliDebug(AliLog::kDebug+5,"->");
-  return el;
+Bool_t AliMixEventPool::AddEntry(Long64_t entry, AliVEvent *ev)
+{
+   //
+   // Adds entry to correct entry list
+   //
+   AliDebug(AliLog::kDebug + 5, "<-");
+   AliDebug(AliLog::kDebug + 5, Form("AddEntry(%lld,%p)", entry, (void *)ev));
+   if (entry < 0) {
+      AliDebug(AliLog::kDebug, Form("Entry %lld was NOT added !!!", entry));
+      return kFALSE;
+   }
+   Int_t idEntryList = -1;
+   TEntryList *el =  FindEntryList(ev, idEntryList);
+   if (el) {
+      el->Enter(entry);
+      AliDebug(AliLog::kDebug, Form("Entry %lld was added with idEntryList %d !!!", entry, idEntryList));
+      return kTRUE;
+   }
+   AliDebug(AliLog::kDebug, Form("Entry %lld was NOT added !!!", entry));
+   AliDebug(AliLog::kDebug + 5, "->");
+   return kFALSE;
 }
 
 //_________________________________________________________________________________________________
-Bool_t AliMixEventPool::AddEntry(Long64_t entry, AliVEvent* ev) {
-  //
-  // Adds entry to correct entry list
-  //
-  
-  AliDebug(AliLog::kDebug+5,"<-");
-  AliDebug(AliLog::kDebug + 5, Form("AddEntry(%lld,%p)", entry, ev));
-  if (entry < 0) {
-    AliDebug(AliLog::kDebug, Form("Entry %lld was NOT added !!!", entry));
-    return kFALSE;
-
-  }
-
-  TEntryList *el =  FindEntryList(ev);
-  if (el) {
-    el->Enter(entry);
-    AliDebug(AliLog::kDebug, Form("Entry %lld was added !!!", entry));
-    return kTRUE;
-  }
-
-  AliDebug(AliLog::kDebug, Form("Entry %lld was NOT added !!!", entry));
-  AliDebug(AliLog::kDebug+5,"->");
-  return kFALSE;
+TEntryList *AliMixEventPool::FindEntryList(AliVEvent *ev, Int_t &idEntryList)
+{
+   //
+   // Find entrlist in list of entrlist
+   //
+   AliDebug(AliLog::kDebug + 5, "<-");
+   Int_t num = fListOfEventCuts.GetEntriesFast();
+   if (num < 1) return 0;
+   Int_t *indexes = new Int_t[num] ;
+   Int_t *lenght = new Int_t[num];
+   Int_t i = 0;
+   TObjArrayIter next(&fListOfEventCuts);
+   AliMixEventCutObj *cut;
+   while ((cut = (AliMixEventCutObj *) next())) {
+      indexes[i] = cut->GetIndex(ev);
+      if (indexes[i] < 0) {
+         AliDebug(AliLog::kDebug, Form("idEntryList %d", -1));
+         delete [] indexes;
+         delete [] lenght;
+         return 0;
+      }
+      lenght[i] = cut->GetNumberOfBins();
+      AliDebug(AliLog::kDebug + 1, Form("indexes[%d] %d", i, indexes[i]));
+      i++;
+   }
+   idEntryList = 0;
+   SearchIndexRecursive(fListOfEventCuts.GetEntries() - 1, &indexes[0], &lenght[0], idEntryList);
+   AliDebug(AliLog::kDebug, Form("idEntryList %d", idEntryList - 1));
+   // index which start with 0 (idEntryList-1)
+   delete [] indexes;
+   delete [] lenght;
+   AliDebug(AliLog::kDebug + 5, "->");
+   return (TEntryList *) fListOfEntryList.At(idEntryList - 1);
 }
 
 //_________________________________________________________________________________________________
-TEntryList* AliMixEventPool::FindEntryList(AliVEvent* ev) {
-  //
-  // Find entrlist in list of entrlist
-  //
-  
-  AliDebug(AliLog::kDebug+5,"<-");
-  const Int_t num = fListOfEventCuts.GetEntries();
-  if (num <= 0) return 0;
-
-  Int_t indexes[num];
-  Int_t lenght[num];
-  Int_t i = 0;
-  TObjArrayIter next(&fListOfEventCuts);
-  AliMixEventCutObj *cut;
-  while ((cut = (AliMixEventCutObj*) next())) {
-    indexes[i] = cut->GetIndex(ev);
-    if (indexes[i] < 0) {
-      AliDebug(AliLog::kDebug, Form("retIndex %d", -1));
-      return 0;
-    }
-    lenght[i] = cut->GetNumberOfBins();
-    AliDebug(AliLog::kDebug + 1, Form("indexes[%d] %d", i, indexes[i]));
-    i++;
-  }
-
-  Int_t retIndex = 0;
-  SearchIndexRecursive(fListOfEventCuts.GetEntries() - 1, &indexes[0], &lenght[0], retIndex);
-  AliDebug(AliLog::kDebug, Form("retIndex %d", retIndex - 1));
-  // index which start with 0 (retIndex-1)
-  AliDebug(AliLog::kDebug+5,"->");
-  return (TEntryList*) fListOfEntryList.At(retIndex - 1);
+void AliMixEventPool::SearchIndexRecursive(Int_t num, Int_t *i, Int_t *d, Int_t &index)
+{
+   //
+   // Search for index of entrylist
+   //
+   AliDebug(AliLog::kDebug + 5, "<-");
+   if (num > 0) {
+      index += (i[num] - 1) * d[num-1];
+      SearchIndexRecursive(num - 1, i, d, index);
+   } else {
+      index += i[num];
+   }
+   AliDebug(AliLog::kDebug + 5, "->");
 }
 
 //_________________________________________________________________________________________________
-void AliMixEventPool::SearchIndexRecursive(Int_t num, Int_t* i, Int_t* d, Int_t& index) {
-  //
-  // Search for index of entrylist
-  //
-  
-  AliDebug(AliLog::kDebug+5,"<-");
-  if (num > 0) {
-    index += (i[num] - 1) * d[num-1];
-    SearchIndexRecursive(num - 1, i, d, index);
-  } else {
-    index += i[num];
-  }
-  AliDebug(AliLog::kDebug+5,"->");
+void AliMixEventPool::SetCutValuesFromBinIndex(Int_t index)
+{
+   //
+   // Sets cut value from bin index
+   //
+   Int_t numCuts = fListOfEventCuts.GetEntriesFast();
+   Int_t *lenght = new Int_t[numCuts];
+   Int_t *indexes = new Int_t[numCuts];
+   Long64_t timesNum = 1;
+   AliMixEventCutObj *cut;
+   Int_t i = 0, j = 0;
+   for (i = 0; i < numCuts; i++) {
+      cut = (AliMixEventCutObj *) fListOfEventCuts.At(i);
+      cut->Reset();
+      lenght[i] = cut->GetNumberOfBins();
+      indexes[i] = 1;
+      timesNum *= lenght[i];
+   }
+
+   if (index < 0 || index >= timesNum) {
+      AliError(Form("index=%d is out of range !!!", index));
+      return;
+   }
+
+   Long64_t indexNum = index;
+   for (i = 0; i < numCuts; i++) {
+      timesNum = 1;
+      for (j = 0; j < numCuts - i - 1; j++) timesNum *= lenght[j];
+      indexNum /= timesNum;
+      indexes[numCuts-i-1] = indexNum + 1;
+      index -= indexNum * timesNum;
+      indexNum = index;
+   }
+
+   for (i = 0; i < numCuts; i++) {
+      cut = (AliMixEventCutObj *) fListOfEventCuts.At(i);
+      for (j = 0; j < indexes[i]; j++) cut->AddStep();
+      cut->PrintCurrentInterval();
+
+   }
+
+   for (i = 0; i < numCuts; i++) AliDebug(AliLog::kDebug, Form("indexes[%d]=%d", i, indexes[i]));
+
+   delete [] lenght;
+   delete [] indexes;
 }
index f1adbc9..4caec6c 100644 (file)
@@ -1,7 +1,7 @@
 //
 // Class AliMixEventPool
 //
-// AliMixEventPool is used to find 
+// AliMixEventPool is used to find
 // similar events
 //
 // author:
 class TEntryList;
 class AliMixEventCutObj;
 class AliVEvent;
-class AliMixEventPool : public TNamed
-{
-  public:
-    AliMixEventPool(const char* name="mixEventPool", const char* title="Mix event pool");
-    AliMixEventPool(const AliMixEventPool& obj);
-    virtual ~AliMixEventPool();
-
-    // prints object info
-    virtual void      Print(const Option_t* option="") const;
-
-    // inits correctly object
-    Int_t       Init();
-    
-    void        CreateEntryListsRecursivly(Int_t index);
-    void        SearchIndexRecursive(Int_t num, Int_t *i, Int_t *d, Int_t &index);
-    TEntryList* AddEntryList();
-    
-    Bool_t      AddEntry(Long64_t entry, AliVEvent* ev);
-    TEntryList *FindEntryList(AliVEvent *ev);
-    
-    void        AddCut(AliMixEventCutObj*cut);
-    
-    Bool_t      NeedInit() { return (fListOfEntryList.GetEntries() == 0); }
-    TObjArray  *GetListOfEntryLists() { return &fListOfEntryList; }   
-    TObjArray  *GetListOfEventCuts() { return &fListOfEventCuts; }
-    
-  private:
-
-    TObjArray   fListOfEntryList;       // list of entry lists
-    TObjArray   fListOfEventCuts;       // list of entry lists
-    
-    Int_t       fBinNumber;             // bin number
-    
-    AliMixEventPool& operator= (const AliMixEventPool&) { return *this; }
-
-    ClassDef(AliMixEventPool, 1)
+class AliMixEventPool : public TNamed {
+public:
+   AliMixEventPool(const char *name = "mixEventPool", const char *title = "Mix event pool");
+   AliMixEventPool(const AliMixEventPool &obj);
+   AliMixEventPool &operator= (const AliMixEventPool& obj);
+   virtual ~AliMixEventPool();
+
+   // prints object info
+   virtual void      Print(const Option_t *option = "") const;
+
+   // inits correctly object
+   Int_t       Init();
+
+   void        CreateEntryListsRecursivly(Int_t index);
+   void        SearchIndexRecursive(Int_t num, Int_t *i, Int_t *d, Int_t &index);
+   TEntryList *AddEntryList();
+
+   Bool_t      AddEntry(Long64_t entry, AliVEvent *ev);
+   TEntryList *FindEntryList(AliVEvent *ev, Int_t &idEntryList);
+
+   void        AddCut(AliMixEventCutObj *cut);
+
+   Bool_t      NeedInit() { return (fListOfEntryList.GetEntries() == 0); }
+   TObjArray  *GetListOfEntryLists() { return &fListOfEntryList; }
+   TObjArray  *GetListOfEventCuts() { return &fListOfEventCuts; }
+
+   void        SetCutValuesFromBinIndex(Int_t index);
+   void        SetBufferSize(Int_t buffer) { fBufferSize = buffer; }
+   void        SetMixNumber(Int_t numMix) { fMixNumber = numMix; }
+   Int_t       GetBufferSize() const { return fBufferSize; }
+   Int_t       GetMixNumber() const { return fMixNumber; }
+
+private:
+
+   TObjArray   fListOfEntryList;       // list of entry lists
+   TObjArray   fListOfEventCuts;       // list of entry lists
+
+   Int_t       fBinNumber;             // bin number
+   Int_t       fBufferSize;            // buffer size
+   Int_t       fMixNumber;             // mixing number
+
+   ClassDef(AliMixEventPool, 1)
 };
 
 #endif
diff --git a/ANALYSIS/EventMixing/AliMixInfo.cxx b/ANALYSIS/EventMixing/AliMixInfo.cxx
new file mode 100644 (file)
index 0000000..6a1b3e7
--- /dev/null
@@ -0,0 +1,467 @@
+//
+// Class AliMixInfo
+//
+// AliMixInfo object contains information about one cut on for event mixing
+// available for users containing mixing information
+//
+// authors:
+//          Martin Vala (martin.vala@cern.ch)
+//
+
+#include <TList.h>
+#include <TPad.h>
+#include <TROOT.h>
+#include <TFile.h>
+#include <TH1.h>
+#include <TH2.h>
+#include <TProfile.h>
+#include <TStyle.h>
+#include <TLegend.h>
+#include <TPavesText.h>
+#include <TCanvas.h>
+
+#include "AliLog.h"
+
+#include "AliMixInfo.h"
+#include "AliMixEventPool.h"
+#include "AliMixEventCutObj.h"
+
+ClassImp(AliMixInfo)
+
+//_________________________________________________________________________________________________
+AliMixInfo::AliMixInfo(const char *name, const char *title) :
+   TNamed(name, title),
+   fHistogramList(0)
+{
+   //
+   // Default constructor.
+   //
+   AliDebug(AliLog::kDebug + 5, "<-");
+   AliDebug(AliLog::kDebug + 5, "->");
+}
+//_________________________________________________________________________________________________
+AliMixInfo::AliMixInfo(const AliMixInfo &obj) :
+   TNamed(obj),
+   fHistogramList(obj.fHistogramList)
+{
+   //
+   // Copy constructor.
+   //
+   AliDebug(AliLog::kDebug + 5, "<-");
+   AliDebug(AliLog::kDebug + 5, "->");
+}
+//_________________________________________________________________________________________________
+AliMixInfo::~AliMixInfo()
+{
+   //
+   // Destructor
+   //
+}
+
+//_________________________________________________________________________________________________
+void AliMixInfo::CreateHistogram(AliMixInfo::EInfoHistorgramType type, Int_t nbins, Int_t min, Int_t max)
+{
+   //
+   // Create mix info histograms
+   //
+   if (!fHistogramList) {
+      fHistogramList = new TList;
+      fHistogramList->SetOwner(kTRUE);
+   }
+   TH1I *hist = (TH1I *) fHistogramList->FindObject(GetNameHistogramByType(type));
+   if (hist) return;
+   hist = new TH1I(GetNameHistogramByType(type), GetTitleHistogramByType(type), nbins, min, max);
+   fHistogramList->Add(hist);
+}
+
+//_________________________________________________________________________________________________
+void AliMixInfo::FillHistogram(AliMixInfo::EInfoHistorgramType type, Int_t value)
+{
+   //
+   // Create mix info histograms
+   //
+   if (type == kMixedEvents && value < 0) return;
+   if (!fHistogramList) {
+      AliError("fHistogramList is null");
+      return;
+   }
+   TH1I *hist = (TH1I *) fHistogramList->FindObject(GetNameHistogramByType(type));
+   if (hist) {
+      hist->Fill(value);
+      AliDebug(AliLog::kDebug, Form("%s was filled with %d sum is %.0f", GetNameHistogramByType(type), value, hist->GetBinContent(value)));
+   } else {
+      AliError(Form("Problem filling histogram %s", GetNameHistogramByType(type)));
+   }
+}
+
+//_________________________________________________________________________________________________
+const char *AliMixInfo::GetNameHistogramByType(Int_t index) const
+{
+   //
+   // Retruns name of cut
+   //
+   switch (index) {
+      case kMainEvents:
+         return "hMainEvents";
+      case kMixedEvents:
+         return "hMixedEvents";
+   }
+   return "";
+}
+
+//_________________________________________________________________________________________________
+const char *AliMixInfo::GetTitleHistogramByType(Int_t index) const
+{
+   //
+   // Retruns name of cut
+   //
+   switch (index) {
+      case kMainEvents:
+         return "Main Events";
+      case kMixedEvents:
+         return "Mixed Events";
+   }
+   return "";
+}
+
+//_________________________________________________________________________________________________
+void AliMixInfo::Print(Option_t *option) const
+{
+   //
+   // Print Mix info
+   //
+   if (!fHistogramList) return;
+   if (option)
+      AliInfo(Form("Name %s with option is %s", GetName(), option));
+   TIter next(fHistogramList);
+   TH1I *h = 0;
+   for (Int_t i = 0; i < fHistogramList->GetEntries(); i++) {
+      h = dynamic_cast<TH1I *>(fHistogramList->At(i));
+      if (h) {
+         h->Print();
+         continue;
+      }
+   }
+}
+//_________________________________________________________________________________________________
+void AliMixInfo::Draw(Option_t* option)
+{
+   //
+   // Drwas mixi info canvas
+   //
+   if (!fHistogramList) return;
+
+   // creating main canvas
+   TCanvas *cMain = new TCanvas("cMain", "Mixing Info", 500, 500);
+   if (!cMain) return;
+   cMain->Divide(1, 2, 0.001, 0.001);
+   cMain->cd(1);
+//     TVirtualPad *upperPad = cMain->cd(1);
+//     upperPad->Divide(2,1);
+//     TVirtualPad *upperPad1 = gPad->cd(2);
+//     upperPad1->Divide(1,2);
+//     upperPad1->cd(1);
+   TPavesText*text = new TPavesText(0.05, 0.05, 0.95, 0.95, 1);
+   text->SetName("mixInfoText");
+   text->AddText("Help:");
+   text->AddText("Move over histogram to see mix info for different bins");
+   text->Draw();
+
+   // gets corresponding histograms
+   TH1I *hMain = GetHistogramByType(kMainEvents);
+   if (!hMain) {
+      AliError("hMain is null");
+      return;
+   }
+   TH1I *hMix =  GetHistogramByType(kMixedEvents);
+   if (!hMix) {
+      AliError("hMix is null");
+      return;
+   }
+
+
+   TH2I *hMixInfo2D = 0;
+//     TH1I *hOK=0,*hBad=0;
+   AliMixEventPool *evPool = (AliMixEventPool *) GetEventPool("mixEventPool");
+   if (evPool) {
+      Int_t mixNum = evPool->GetMixNumber();
+//         hOK = (TH1I *) hMain->Clone();
+//         hBad = (TH1I *) hMain->Clone();
+      if (!hMixInfo2D) hMixInfo2D = new TH2I("hMixInfo2D", "hMixInfo2D", hMain->GetXaxis()->GetNbins() + 1, hMain->GetXaxis()->GetXmin() - 1, hMain->GetXaxis()->GetXmax(), 1, 0, 1);
+      for (Int_t iBin = 0; iBin < hMain->GetNbinsX() + 1; iBin++) {
+         if (!iBin) {
+            hMixInfo2D->SetBinContent(iBin + 1, 1, 1);
+         } else if (!hMain->GetBinContent(iBin) && !hMix->GetBinContent(iBin)) {
+            hMixInfo2D->SetBinContent(iBin + 1, 1, 2);
+         } else if (hMix->GetBinContent(iBin) == mixNum * hMain->GetBinContent(iBin)) {
+            hMixInfo2D->SetBinContent(iBin + 1, 1, 4);
+         } else {
+            hMixInfo2D->SetBinContent(iBin + 1, 1, 3);
+         }
+      }
+   }
+
+   TStyle *style = gStyle;
+   Int_t cols[4] = { kYellow, kViolet, kRed, kGreen  };
+   style->SetPalette(4, cols);
+   cMain->cd(2);
+   hMixInfo2D->SetMaximum(4);
+   hMixInfo2D->SetStats(0);
+   hMixInfo2D->SetTitle("");
+   hMixInfo2D->GetXaxis()->SetNdivisions(510);
+   hMixInfo2D->GetYaxis()->SetNdivisions(0);
+
+   cMain->SetGrid();
+//     hMixInfo2D->SetBarWidth(1);
+//     hMixInfo2D->SetLineColor(kBlack);
+//     hMixInfo2D->SetLineWidth(11);
+   hMixInfo2D->Draw(Form("COL %s", option));
+//
+//     TLegend *legend = new TLegend(0.55,0.65,0.76,0.82);
+//     legend->AddEntry(hOK,"OK","f");
+//     legend->AddEntry(hBad,"NOT OK","f");
+//     legend->Draw();
+
+   cMain->cd(2)->AddExec("dynamic", Form("AliMixInfo::DynamicExec((AliMixInfo*)0x%lx)", (ULong_t)this));
+}
+
+//_________________________________________________________________________________________________
+void AliMixInfo::DynamicExec(AliMixInfo *const mixInfo)
+{
+   //
+   // Function which is run when user move mouse over mix info
+   //
+
+   TObject *select = gPad->GetSelected();
+   if (!select) return;
+   if (!select->InheritsFrom(TH2I::Class())) {
+      gPad->SetUniqueID(0);
+      return;
+   }
+
+   TH2I *hSelected = (TH2I *) select;
+   gPad->GetCanvas()->FeedbackMode(kTRUE);
+
+   //erase old position and draw a line at current position
+   Int_t uid = gPad->GetUniqueID();
+//     int pxold = gPad->GetUniqueID();
+   Int_t px = gPad->GetEventX();
+//     Int_t py = gPad->GetEventY();
+//     float uxmin = gPad->GetUxmin();
+//     float uxmax = gPad->GetUxmax();
+//     float uymin = gPad->GetUymin();
+//     float uymax = gPad->GetUymax();
+   //     Int_t pxmin = gPad->XtoAbsPixel ( uxmin );
+   //     Int_t pxmax = gPad->XtoAbsPixel ( uxmax );
+   //     Int_t pymin = gPad->YtoAbsPixel ( uymin );
+   //     Int_t pymax = gPad->YtoAbsPixel ( uymax );
+// //     if(pxold) gVirtualX->DrawLine(pxold,pymin,pxold,pymax);
+// //     else gVirtualX->DrawLine(px,pymin,px,pymax);
+//     gPad->SetUniqueID ( px );
+
+   Float_t upx = gPad->AbsPixeltoX(px);
+//     Float_t upy = gPad->AbsPixeltoY(py);
+
+   Float_t x = gPad->PadtoX(upx);
+//     Float_t y = gPad->PadtoY ( upy );
+
+   Int_t binX = hSelected->GetXaxis()->FindBin(x) - 1;
+//     Int_t binY = hSelected->GetYaxis()->FindBin(y)-1;
+
+
+
+   // return in case of same bin
+   if (uid == binX) return;
+//     Printf("%d %d",uid,binX);
+
+   //create or set the new canvas cInfo
+   TPaveText *text = 0;
+   TVirtualPad *padsav = gPad;
+   TCanvas *cInfo = (TCanvas *) gROOT->GetListOfCanvases()->FindObject("cMain");
+   if (cInfo) {
+      text = (TPaveText *)cInfo->GetPrimitive("mixInfoText");
+      if (!text) {
+         text = new TPavesText(0.05, 0.05, 0.95, 0.95, 1);
+      } else {
+         text->DeleteText();
+      }
+
+   } else   cInfo = new TCanvas("cInfo", "MixInfo Canvas", 510, 0, 350, 150);
+
+   TVirtualPad *upperPad = cInfo->cd(1);
+//     TVirtualPad *upperPadL = upperPad->cd(1);
+//     TVirtualPad *upperPadR = upperPad->cd(2);
+//     TVirtualPad *upperPadR1 = upperPadR->cd(1);
+//     TVirtualPad *upperPadR2 = upperPadR->cd(2);
+//     TH1I *hMain = 0;
+//     TH1I *hMix = 0;
+
+
+//     mixInfo->Print();
+//     return;
+
+   // gets corresponding histograms
+   TH1I *hMain = mixInfo->GetHistogramByType(kMainEvents);
+   if (!hMain) {
+      Printf("hMain is null");
+      return;
+   }
+   TH1I *hMix =  mixInfo->GetHistogramByType(kMixedEvents);
+   if (!hMix) {
+      Printf("hMix is null");
+      return;
+   }
+
+   Double_t numMain = hMain->GetBinContent(binX);
+   Double_t numMix = hMix->GetBinContent(binX);
+   Int_t hist2DValue = (Int_t) hSelected->GetBinContent(binX + 1, 1);
+
+   Int_t mixNum = 1;
+   if (text) {
+      text->SetName("mixInfoText");
+      text->SetTextAlign(12);
+      text->SetToolTipText("Mixing Info about current binX");
+//         text->SetTextSize(0.1);
+//         text->SetTextColor(3);
+      text->SetBorderSize(2);
+      text->AddText(Form("binX=%d", binX));
+      text->AddText(Form("numMain=%.0f", numMain));
+      text->AddText(Form("numMix=%.0f", numMix));
+      text->AddText(Form("BINCONTENT=%d", hist2DValue));
+
+      if (mixInfo) {
+
+         AliMixEventPool *evPool = (AliMixEventPool *) mixInfo->GetEventPool("mixEventPool");
+         if (evPool) {
+            mixNum = evPool->GetMixNumber();
+            if (binX - 1 > 0)
+               evPool->SetCutValuesFromBinIndex(binX - 1);
+            TObjArray *eventCuts = evPool->GetListOfEventCuts();
+            if (eventCuts) {
+
+               TObjArrayIter next(eventCuts);
+               AliMixEventCutObj *cut;
+               while ((cut = (AliMixEventCutObj *) next())) {
+                  if (hist2DValue > 1) text->AddText(Form("%s <%.2f,%.2f)", cut->GetCutName(), cut->GetMin(), cut->GetMax()));
+                  else text->AddText(Form("%s <Out of Range>", cut->GetCutName()));
+               }
+            }
+
+         }
+
+      }
+      switch (hist2DValue) {
+         case 1 :
+            text->SetFillColor(kYellow);
+            break;
+         case 2 :
+            text->SetFillColor(kViolet);
+            break;
+         case 3 :
+            text->SetFillColor(kRed);
+            break;
+         case 4 :
+            text->SetFillColor(kGreen);
+            break;
+         default:
+            text->SetFillColor(kWhite);
+            break;
+      }
+      upperPad->cd();
+      text->Draw();
+//         upperPadR1->cd();
+//         TH1D *proj1 = hSelected->ProjectionY("_xxx",binX);
+//         proj1->Draw();
+//         upperPadR2->cd();
+//         TH1D *proj2 = hSelected->ProjectionY("_xxx",binX);
+//         proj1->Draw();
+
+   }
+   cInfo->Update();
+   padsav->cd();
+
+   gPad->SetUniqueID(binX);
+}
+
+//_________________________________________________________________________________________________
+Long64_t AliMixInfo::Merge(TCollection *list)
+{
+   //
+   // Merge function
+   //
+   if (!list) return 0;
+   TIter nxfc(list);
+   AliMixInfo *mi = 0;
+   Long64_t counter = 0;
+   while ((mi = (AliMixInfo *) nxfc())) {
+      // Do not merge with ourself
+      if (mi == this) continue;
+      // Make sure that it is a AliMixInfo
+      if (!mi->InheritsFrom(AliMixInfo::Class())) {
+         Error("Merge", "attempt to add object of class: %s to a %s", mi->ClassName(), ClassName());
+         return -1;
+      }
+      // Merge now
+      Add(mi);
+      counter++;
+   }
+   // Done
+   return counter;
+}
+
+TH1I *AliMixInfo::GetHistogramByType(Int_t index) const
+{
+   //
+   // GetHistogramByType
+   //
+   return (TH1I *) fHistogramList->FindObject(GetNameHistogramByType(index));
+}
+
+//_________________________________________________________________________________________________
+void AliMixInfo::Add(AliMixInfo *mi)
+{
+   //
+   // adds AliMixInfo
+   //
+
+   AliInfo(Form("Adding %p", mi));
+   if (!mi) return;
+   if (!fHistogramList) return;
+   TH1I *hMain = GetHistogramByType(kMainEvents);
+   if (!hMain) {
+      AliError("hMain is null");
+      return;
+   }
+   TH1I *hMix =  GetHistogramByType(kMixedEvents);
+   if (!hMix) {
+      AliError("hMain is null");
+      return;
+   }
+   hMain->Add(mi->GetHistogramByType(kMainEvents));
+   hMix->Add(mi->GetHistogramByType(kMixedEvents));
+}
+
+//_________________________________________________________________________________________________
+void AliMixInfo::SetEventPool(AliMixEventPool *evPool)
+{
+   //
+   // Sets event pool
+   //
+   if (!evPool) return;
+
+   if (!fHistogramList) return;
+
+   fHistogramList->Add(evPool);
+}
+
+//_________________________________________________________________________________________________
+AliMixEventPool *AliMixInfo::GetEventPool(const char *name)
+{
+   //
+   // Gets event pool
+   //
+   if (!fHistogramList) return 0;
+
+   return (AliMixEventPool *) fHistogramList->FindObject(name);
+}
+
diff --git a/ANALYSIS/EventMixing/AliMixInfo.h b/ANALYSIS/EventMixing/AliMixInfo.h
new file mode 100644 (file)
index 0000000..78e56fc
--- /dev/null
@@ -0,0 +1,58 @@
+//
+// Class AliMixInfo
+//
+// AliMixInfo object contains information about one cut on for event mixing
+// available for users containing mixing information
+//
+// authors:
+//          Martin Vala (martin.vala@cern.ch)
+//
+
+#ifndef ALIMIXINFO_H
+#define ALIMIXINFO_H
+
+#include <TNamed.h>
+#include <Rtypes.h>
+
+class AliMixEventPool;
+class TH1I;
+class TList;
+class TCollection;
+class AliMixInfo : public TNamed {
+public:
+   enum EInfoHistorgramType { kMainEvents = 0, kMixedEvents = 1, kNumTypes };
+
+   AliMixInfo(const char *name = "mix", const char *title = "MixInfo");
+   AliMixInfo(const AliMixInfo &obj);
+   virtual ~AliMixInfo();
+
+   void Reset();
+   virtual void Print(Option_t *option = "") const;
+   virtual void Draw(Option_t *option = "");
+   virtual Long64_t Merge(TCollection *list);
+
+   void Add(AliMixInfo *mi);
+
+   void SetOutputList(TList * const list) { fHistogramList = list; }
+   void CreateHistogram(EInfoHistorgramType type, Int_t nbins, Int_t min, Int_t max);
+   void FillHistogram(AliMixInfo::EInfoHistorgramType type, Int_t value);
+   const char *GetNameHistogramByType(Int_t index) const;
+   const char *GetTitleHistogramByType(Int_t index) const;
+   TH1I  *GetHistogramByType(Int_t index) const;
+
+   void    SetEventPool(AliMixEventPool *evPool);
+   AliMixEventPool *GetEventPool(const char *name);
+
+
+   static void DynamicExec(AliMixInfo*const mixInfo);
+private:
+
+   TList     *fHistogramList;  // histogram list
+
+   AliMixInfo &operator=(const AliMixInfo &) { return *this; }
+
+   ClassDef(AliMixInfo, 1)
+
+};
+
+#endif
diff --git a/ANALYSIS/EventMixing/AliMixInputEventHandler.cxx b/ANALYSIS/EventMixing/AliMixInputEventHandler.cxx
new file mode 100644 (file)
index 0000000..c3d2abf
--- /dev/null
@@ -0,0 +1,527 @@
+//
+// Class AliMixEventInputHandler
+//
+// Mixing input handler prepare N events before UserExec
+// TODO example
+// author:
+//        Martin Vala (martin.vala@cern.ch)
+//
+
+#include <TFile.h>
+#include <TChain.h>
+#include <TEntryList.h>
+#include <TChainElement.h>
+#include <TSystem.h>
+
+#include "AliLog.h"
+#include "AliAnalysisManager.h"
+#include "AliInputEventHandler.h"
+
+#include "AliMixEventPool.h"
+#include "AliMixInputEventHandler.h"
+#include "AliMixInputHandlerInfo.h"
+
+#include "AliAnalysisTaskSE.h"
+
+ClassImp(AliMixInputEventHandler)
+
+AliMixInputEventHandler::AliMixInputEventHandler(const Int_t size, const Int_t mixNum): AliMultiInputEventHandler(size),
+   fMixTrees(),
+   fTreeMap(size > 0 ? size : 1),
+   fMixIntupHandlerInfoTmp(0),
+   fEntryCounter(0),
+   fEventPool(0),
+   fNumberMixed(0),
+   fMixNumber(mixNum),
+   fUseDefautProcess(kFALSE),
+   fUsePreMixEvents(kTRUE),
+   fCurrentEntry(0),
+   fCurrentEntryMain(0),
+   fCurrentEntryMix(0),
+   fCurrentBinIndex(-1)
+{
+   //
+   // Default constructor.
+   //
+   AliDebug(AliLog::kDebug + 10, "<-");
+   fMixTrees.SetOwner(kTRUE);
+   SetMixNumber(mixNum);
+   AliDebug(AliLog::kDebug + 10, "->");
+}
+
+//_____________________________________________________________________________
+AliInputEventHandler *AliMixInputEventHandler::InputEventHandler(const Int_t index)
+{
+   //
+   // Returns input handler
+   //
+   AliDebug(AliLog::kDebug + 5, Form("<-"));
+   if ((index >= 0) && (index < fBufferSize)) {
+      AliMultiInputEventHandler *eh = dynamic_cast<AliMultiInputEventHandler *>(fInputHandlers.At(index));
+      if (eh)
+         return (AliInputEventHandler *) eh;
+//             return (AliInputEventHandler *) eh->InputEventHandler(0);
+      else
+         return (AliInputEventHandler *) fInputHandlers.At(index);
+   }
+   AliDebug(AliLog::kDebug + 5, Form("->"));
+   return 0;
+}
+//_____________________________________________________________________________
+void AliMixInputEventHandler::SetInputHandlerForMixing(const AliInputEventHandler *const inHandler)
+{
+   //
+   // Create N (fBufferSize) copies of input handler
+   //
+   AliDebug(AliLog::kDebug + 5, Form("<-"));
+   fInputHandlers.Clear();
+   AliDebug(AliLog::kDebug + 5, Form("Creating %d input event handlers ...", fBufferSize));
+   for (Int_t i = 0; i < fBufferSize; i++) {
+      AliDebug(AliLog::kDebug + 5, Form("Adding %d ...", i));
+      fInputHandlers.Add((AliInputEventHandler *) inHandler->Clone());
+   }
+   AliDebug(AliLog::kDebug + 5, Form("->"));
+}
+
+//_____________________________________________________________________________
+Bool_t AliMixInputEventHandler::Init(TTree *tree, Option_t *opt)
+{
+   //
+   // Init(const char*path) is called for all mix input handlers.
+   // Create event pool if needed
+   //
+   AliDebug(AliLog::kDebug + 5, Form("<- %p %s", (void *)tree, opt));
+   fAnalysisType = opt;
+   if (!tree) {
+      AliDebug(AliLog::kDebug + 5, Form("->"));
+      return kFALSE;
+   }
+   // clears array of input handlers
+   fMixTrees.Clear();
+   // create AliMixInputHandlerInfo
+   if (!fMixIntupHandlerInfoTmp) {
+      // loads first file TChain (tree)
+      tree->LoadTree(0);
+      fMixIntupHandlerInfoTmp = new AliMixInputHandlerInfo(tree->GetName());
+   }
+   // moved to Notify
+//     // adds current file
+//     fMixIntupHandlerInfoTmp->AddTreeToChain(tree->GetTree());
+//     Int_t lastIndex = fMixIntupHandlerInfoTmp->GetChain()->GetListOfFiles()->GetEntries();
+//     TChainElement *che = (TChainElement *)fMixIntupHandlerInfoTmp->GetChain()->GetListOfFiles()->At(lastIndex - 1);
+//     AliMixInputHandlerInfo *mixIHI = 0;
+//     for(Int_t i = 0; i < fInputHandlers.GetEntries(); i++) {
+//       AliDebug(AliLog::kDebug+5, Form("fInputHandlers[%d]", i));
+//       mixIHI = new AliMixInputHandlerInfo(fMixIntupHandlerInfoTmp->GetName(), fMixIntupHandlerInfoTmp->GetTitle());
+//       mixIHI->PrepareEntry(che, -1, InputEventHandler(i),fAnalysisType);
+//       AliDebug(AliLog::kDebug+5, Form("chain[%d]->GetEntries() = %lld", i, mixIHI->GetChain()->GetEntries()));
+//       fMixTrees.Add(mixIHI);
+//     }
+//     AliDebug(AliLog::kDebug+5, Form("fEntryCounter=%lld", fEntryCounter));
+//     if(fEventPool && fEventPool->NeedInit())
+//       fEventPool->Init();
+   AliDebug(AliLog::kDebug + 5, Form("->"));
+   return kTRUE;
+}
+//_____________________________________________________________________________
+Bool_t AliMixInputEventHandler::Notify()
+{
+   //
+   // Notify() is called for all mix input handlers
+   //
+   AliDebug(AliLog::kDebug + 5, Form("<-"));
+   if (fUseDefautProcess) {
+      AliDebug(AliLog::kDebug, Form("-> SKIPPED"));
+      return AliMultiInputEventHandler::Notify();
+   }
+   AliDebug(AliLog::kDebug + 5, Form("->"));
+   return kTRUE;
+}
+
+//_____________________________________________________________________________
+Bool_t AliMixInputEventHandler::Notify(const char *path)
+{
+   //
+   // Notify(const char*path) is called for all mix input handlers
+   //
+   AliDebug(AliLog::kDebug + 5, Form("<- %s", path));
+   // adds current file
+   fMixIntupHandlerInfoTmp->AddTreeToChain(path);
+   Int_t lastIndex = fMixIntupHandlerInfoTmp->GetChain()->GetListOfFiles()->GetEntries();
+   TChainElement *che = (TChainElement *)fMixIntupHandlerInfoTmp->GetChain()->GetListOfFiles()->At(lastIndex - 1);
+   AliMixInputHandlerInfo *mixIHI = 0;
+   for (Int_t i = 0; i < fInputHandlers.GetEntries(); i++) {
+      AliDebug(AliLog::kDebug + 5, Form("fInputHandlers[%d]", i));
+      mixIHI = new AliMixInputHandlerInfo(fMixIntupHandlerInfoTmp->GetName(), fMixIntupHandlerInfoTmp->GetTitle());
+      mixIHI->PrepareEntry(che, -1, InputEventHandler(i), fAnalysisType);
+      AliDebug(AliLog::kDebug + 5, Form("chain[%d]->GetEntries() = %lld", i, mixIHI->GetChain()->GetEntries()));
+      fMixTrees.Add(mixIHI);
+   }
+   AliDebug(AliLog::kDebug + 5, Form("fEntryCounter=%lld", fEntryCounter));
+   if (fEventPool && fEventPool->NeedInit())
+      fEventPool->Init();
+   if (fUseDefautProcess) {
+      AliDebug(AliLog::kDebug, Form("-> SKIPPED"));
+      return AliMultiInputEventHandler::Notify(path);
+   }
+   AliDebug(AliLog::kDebug + 5, Form("->"));
+   return kTRUE;
+}
+
+//_____________________________________________________________________________
+Bool_t AliMixInputEventHandler::BeginEvent(Long64_t entry)
+{
+   //
+   // BeginEvent(Long64_t entry) is called for all mix input handlers
+   //
+   AliDebug(AliLog::kDebug + 5, Form("-> %lld", entry));
+   if (fUseDefautProcess) {
+      AliDebug(AliLog::kDebug, Form("-> SKIPPED"));
+      AliMultiInputEventHandler::BeginEvent(entry);/* return GetEntry();*/
+   }
+   AliDebug(AliLog::kDebug + 5, Form("->"));
+   return kTRUE;
+}
+//_____________________________________________________________________________
+Bool_t AliMixInputEventHandler::GetEntry()
+{
+   //
+   // All mixed events are set
+   //
+   AliDebug(AliLog::kDebug + 5, Form("<-"));
+   // if no event pool MixStd
+//     if (fEventPool && fEventPool->NeedInit()) fEventPool->Init();
+   if (!fEventPool) {
+      MixStd();
+   }
+   // if buffer size is higher then 1
+   else if (fBufferSize > 1) {
+      MixBuffer();
+   }
+   // if mix number is higher then 0 and buffer size is 1
+   else if (fMixNumber > 0) {
+      MixEventsMoreTimesWithOneEvent();
+   } else {
+      AliWarning("Not supported Mixing !!!");
+   }
+   AliDebug(AliLog::kDebug + 5, Form("->"));
+   return kTRUE;
+}
+
+//_____________________________________________________________________________
+Bool_t AliMixInputEventHandler::MixStd()
+{
+   //
+   // Mix std - No event pool
+   //
+   AliDebug(AliLog::kDebug + 5, Form("<-"));
+   AliDebug(AliLog::kDebug + 1, "Mix method");
+   // get correct handler
+   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+   AliMultiInputEventHandler *mh = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
+   AliInputEventHandler *inEvHMain = 0;
+   if (mh) inEvHMain = dynamic_cast<AliInputEventHandler *>(mh->GetFirstInputEventHandler());
+   else inEvHMain = dynamic_cast<AliInputEventHandler *>(mgr->GetInputEventHandler());
+   if (!inEvHMain) return kFALSE;
+   // return in case of 0 entry in full chain
+   if (!fEntryCounter) {
+      AliDebug(AliLog::kDebug + 3, Form("-> fEntryCounter == 0"));
+      // runs UserExecMix for all tasks (kFALSE means that UserExecMix is not called)
+      UserExecMixAllTasks(fEntryCounter, 1, fEntryCounter, -1, 0);
+      return kTRUE;
+   }
+   // pre mix evetns
+   Int_t mixNum = fMixNumber;
+   if (fUsePreMixEvents) {
+      if (fEntryCounter <= 2 * fMixNumber) mixNum = 2 * fMixNumber + 2;
+   }
+   // start of
+   AliDebug(AliLog::kDebug + 3, Form("++++++++++++++ BEGIN SETUP EVENT %lld +++++++++++++++++++", fEntryCounter));
+   // reset mix number
+   fNumberMixed = 0;
+   AliMixInputHandlerInfo *mihi = 0;
+   Long64_t entryMix = 0, entryMixReal = 0;
+   Int_t counter = 0;
+   for (counter = 0; counter < mixNum; counter++) {
+      entryMix = fEntryCounter - 1 - counter ;
+      AliDebug(AliLog::kDebug + 5, Form("Handler[%d] entryMix %lld ", counter, entryMix));
+      if (entryMix < 0) break;
+      entryMixReal = entryMix;
+      mihi = (AliMixInputHandlerInfo *) fMixTrees.At(0);
+      TChainElement *te = fMixIntupHandlerInfoTmp->GetEntryInTree(entryMix);
+      if (!te) {
+         AliError("te is null. this is error. tell to developer (#1)")
+      } else {
+         mihi->PrepareEntry(te, entryMix, InputEventHandler(0), fAnalysisType);
+         // runs UserExecMix for all tasks
+         fNumberMixed++;
+         UserExecMixAllTasks(fEntryCounter, 1, fEntryCounter, entryMixReal, fNumberMixed);
+         InputEventHandler(0)->FinishEvent();
+      }
+   }
+   AliDebug(AliLog::kDebug + 3, Form("fEntryCounter=%lld fMixEventNumber=%d", fEntryCounter, fNumberMixed));
+   AliDebug(AliLog::kDebug + 3, Form("++++++++++++++ END SETUP EVENT %lld +++++++++++++++++++", fEntryCounter));
+   AliDebug(AliLog::kDebug + 5, Form("->"));
+   AliDebug(AliLog::kDebug + 5, Form("->"));
+   return kTRUE;
+}
+
+//_____________________________________________________________________________
+Bool_t AliMixInputEventHandler::MixBuffer()
+{
+   //
+   // Mix in event buffer
+   //
+   AliDebug(AliLog::kDebug + 5, Form("<-"));
+   AliDebug(AliLog::kDebug + 1, "Mix method");
+   // get correct handler
+   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+   AliMultiInputEventHandler *mh = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
+   AliInputEventHandler *inEvHMain = 0;
+   if (mh) inEvHMain = dynamic_cast<AliInputEventHandler *>(mh->GetFirstInputEventHandler());
+   else inEvHMain = dynamic_cast<AliInputEventHandler *>(mgr->GetInputEventHandler());
+   if (!inEvHMain) return kFALSE;
+   // find out zero chain entries
+   Long64_t zeroChainEntries = fMixIntupHandlerInfoTmp->GetChain()->GetEntries() - inEvHMain->GetTree()->GetTree()->GetEntries();
+   // fill entry
+   Long64_t currentMainEntry = inEvHMain->GetTree()->GetTree()->GetReadEntry() + zeroChainEntries;
+   // fills entry
+   if (fEventPool && inEvHMain) fEventPool->AddEntry(currentMainEntry, inEvHMain->GetEvent());
+   // start of
+   AliDebug(AliLog::kDebug + 3, Form("++++++++++++++ BEGIN SETUP EVENT %lld +++++++++++++++++++", fEntryCounter));
+   // reset mix number
+   fNumberMixed = 0;
+   Long64_t elNum = 0;
+   TEntryList *el = 0;
+   Int_t idEntryList = -1;
+   if (fEventPool) el = fEventPool->FindEntryList(inEvHMain->GetEvent(), idEntryList);
+   // return in case of 0 entry in full chain
+   if (!fEntryCounter) {
+      AliDebug(AliLog::kDebug + 3, Form("-> fEntryCounter == 0"));
+      // runs UserExecMix for all tasks (kFALSE means that UserExecMix is not called)
+      UserExecMixAllTasks(fEntryCounter, idEntryList, fEntryCounter, -1, 0);
+      return kTRUE;
+   }
+   if (!el) {
+      AliDebug(AliLog::kDebug + 3, Form("++++++++++++++ END SETUP EVENT %lld SKIPPED (el null) +++++++++++++++++++", fEntryCounter));
+      UserExecMixAllTasks(fEntryCounter, -1, fEntryCounter, -1, 0);
+      return kTRUE;
+   } else {
+      elNum = el->GetN();
+      if (elNum < fBufferSize + 1) {
+         AliDebug(AliLog::kDebug + 3, Form("++++++++++++++ END SETUP EVENT %lld SKIPPED (%lld) +++++++++++++++++++", fEntryCounter, elNum));
+         return kTRUE;
+      }
+   }
+   AliMixInputHandlerInfo *mihi = 0;
+   Long64_t entryMix = 0, entryMixReal = 0;
+   Int_t counter = 0;
+   AliInputEventHandler *eh = 0;
+   TObjArrayIter next(&fInputHandlers);
+   while ((eh = (AliInputEventHandler *) next())) {
+      if (fEventPool && fEventPool->GetListOfEventCuts()->GetEntries() > 0) {
+         entryMix = -1;
+         if (elNum >= fBufferSize) {
+            Long64_t entryInEntryList =  elNum - 2 - counter;
+            if (entryInEntryList < 0) break;
+            entryMix = el->GetEntry(entryInEntryList);
+         }
+      }
+      AliDebug(AliLog::kDebug + 5, Form("Handler[%d] entryMix %lld ", counter, entryMix));
+      if (entryMix < 0) {
+         UserExecMixAllTasks(fEntryCounter, -1, currentMainEntry, -1, 0);
+         break;
+      }
+      entryMixReal = entryMix;
+      mihi = (AliMixInputHandlerInfo *) fMixTrees.At(counter);
+      TChainElement *te = fMixIntupHandlerInfoTmp->GetEntryInTree(entryMix);
+      if (!te) {
+         AliError("te is null. this is error. tell to developer (#1)")
+      } else {
+         AliDebug(AliLog::kDebug + 3, Form("Preparing InputEventHandler(%d)", counter));
+         mihi->PrepareEntry(te, entryMix, InputEventHandler(counter), fAnalysisType);
+         // runs UserExecMix for all tasks
+         UserExecMixAllTasks(fEntryCounter, idEntryList, fEntryCounter, entryMixReal, counter);
+         fNumberMixed++;
+      }
+      counter++;
+   }
+   AliDebug(AliLog::kDebug + 3, Form("fEntryCounter=%lld fMixEventNumber=%d", fEntryCounter, fNumberMixed));
+   AliDebug(AliLog::kDebug + 3, Form("++++++++++++++ END SETUP EVENT %lld +++++++++++++++++++", fEntryCounter));
+   AliDebug(AliLog::kDebug + 5, Form("->"));
+   AliDebug(AliLog::kDebug + 5, Form("->"));
+   return kTRUE;
+}
+
+//_____________________________________________________________________________
+Bool_t AliMixInputEventHandler::MixEventsMoreTimesWithOneEvent()
+{
+   //
+   // Mix in history with one event in buffer
+   //
+   AliDebug(AliLog::kDebug + 5, "<-");
+   AliDebug(AliLog::kDebug + 1, "Mix method");
+   // get correct handler
+   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+   AliMultiInputEventHandler *mh = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
+   AliInputEventHandler *inEvHMain = 0;
+   if (mh) inEvHMain = dynamic_cast<AliInputEventHandler *>(mh->GetFirstInputEventHandler());
+   else inEvHMain = dynamic_cast<AliInputEventHandler *>(mgr->GetInputEventHandler());
+   if (!inEvHMain) return kFALSE;
+   // find out zero chain entries
+   Long64_t zeroChainEntries = fMixIntupHandlerInfoTmp->GetChain()->GetEntries() - inEvHMain->GetTree()->GetTree()->GetEntries();
+   // fill entry
+   Long64_t currentMainEntry = inEvHMain->GetTree()->GetTree()->GetReadEntry() + zeroChainEntries;
+   if (fEventPool && inEvHMain) fEventPool->AddEntry(currentMainEntry, inEvHMain->GetEvent());
+   // start of
+   AliDebug(AliLog::kDebug + 3, Form("++++++++++++++ BEGIN SETUP EVENT %lld +++++++++++++++++++", fEntryCounter));
+   // reset mix number
+   fNumberMixed = 0;
+   Long64_t elNum = 0;
+   Int_t idEntryList = -1;
+   TEntryList *el = 0;
+   if (fEventPool) el = fEventPool->FindEntryList(inEvHMain->GetEvent(), idEntryList);
+   // return in case of 0 entry in full chain
+   if (!fEntryCounter) {
+      // runs UserExecMix for all tasks (kFALSE means that UserExecMix is not called)
+      UserExecMixAllTasks(fEntryCounter, idEntryList, currentMainEntry, -1, 0);
+      AliDebug(AliLog::kDebug + 3, Form("++++++++++++++ END SETUP EVENT %lld SKIPPED (fEntryCounter=0, idEntryList=%d) +++++++++++++++++++", fEntryCounter, idEntryList));
+      return kTRUE;
+   }
+   if (!el) {
+      if (fEventPool) {
+         AliDebug(AliLog::kDebug + 3, Form("++++++++++++++ END SETUP EVENT %lld SKIPPED (el null, idEntryList=%d) +++++++++++++++++++", fEntryCounter, idEntryList));
+         UserExecMixAllTasks(fEntryCounter, -1, currentMainEntry, -1, 0);
+         return kTRUE;
+      }
+   } else {
+      elNum = el->GetN();
+      if (elNum < fBufferSize + 1) {
+         UserExecMixAllTasks(fEntryCounter, idEntryList, currentMainEntry, -1, 0);
+         AliDebug(AliLog::kDebug + 3, Form("++++++++++++++ END SETUP EVENT %lld SKIPPED [FIRST ENTRY in el] (elnum=%lld, idEntryList=%d) +++++++++++++++++++", fEntryCounter, elNum, idEntryList));
+         return kTRUE;
+      }
+   }
+   // pre mix evetns
+   Int_t mixNum = fMixNumber;
+   if (fUsePreMixEvents) {
+      if (elNum <= 2 * fMixNumber + 1) mixNum = elNum + 1;
+   }
+   AliMixInputHandlerInfo *mihi = 0;
+   Long64_t entryMix = 0, entryMixReal = 0;
+   Int_t counter = 0;
+   mihi = (AliMixInputHandlerInfo *) fMixTrees.At(0);
+   // fills num for main events
+   for (counter = 0; counter < mixNum; counter++) {
+      Long64_t entryInEntryList =  elNum - 2 - counter;
+      AliDebug(AliLog::kDebug + 3, Form("entryInEntryList=%lld", entryInEntryList));
+      if (entryInEntryList < 0) break;
+      entryMix = el->GetEntry(entryInEntryList);
+      AliDebug(AliLog::kDebug + 3, Form("entryMix=%lld", entryMix));
+      if (entryMix < 0) break;
+      entryMixReal = entryMix;
+      TChainElement *te = fMixIntupHandlerInfoTmp->GetEntryInTree(entryMix);
+      if (!te) {
+         AliError("te is null. this is error. tell to developer (#2)")
+      } else {
+         mihi->PrepareEntry(te, entryMix, InputEventHandler(0), fAnalysisType);
+         // runs UserExecMix for all tasks
+         fNumberMixed++;
+         UserExecMixAllTasks(fEntryCounter, idEntryList, currentMainEntry, entryMixReal, fNumberMixed);
+         InputEventHandler(0)->FinishEvent();
+      }
+   }
+   AliDebug(AliLog::kDebug + 3, Form("fEntryCounter=%lld fMixEventNumber=%d", fEntryCounter, fNumberMixed));
+   AliDebug(AliLog::kDebug + 3, Form("++++++++++++++ END SETUP EVENT %lld +++++++++++++++++++", fEntryCounter));
+   AliDebug(AliLog::kDebug + 5, Form("->"));
+   AliDebug(AliLog::kDebug + 5, Form("->"));
+   return kTRUE;
+}
+
+//_____________________________________________________________________________
+Bool_t AliMixInputEventHandler::MixEventsMoreTimesWithBuffer()
+{
+   //
+   // Mix more events in buffer with mixing with history
+   //
+   AliWarning("Not implemented");
+   return kFALSE;
+}
+
+//_____________________________________________________________________________
+Bool_t AliMixInputEventHandler::FinishEvent()
+{
+   //
+   // FinishEvent() is called for all mix input handlers
+   //
+   AliDebug(AliLog::kDebug + 5, Form("<-"));
+   AliMultiInputEventHandler::FinishEvent();
+   fEntryCounter++;
+   AliDebug(AliLog::kDebug + 5, Form("->"));
+   return kTRUE;
+}
+
+//_____________________________________________________________________________
+void AliMixInputEventHandler::AddInputEventHandler(AliVEventHandler*)
+{
+   //
+   // AddInputEventHandler will not be used
+   //
+   AliWarning("Function AddInputEventHandler is disabled for AliMixEventInputHandler !!!");
+   AliWarning("Use AliMixEventInputHandler::SetInputHandlerForMixing instead. Exiting ...");
+}
+
+//_____________________________________________________________________________
+void AliMixInputEventHandler::UserExecMixAllTasks(Long64_t entryCounter, Int_t idEntryList, Long64_t entryMainReal, Long64_t entryMixReal, Int_t numMixed)
+{
+   //
+   // Execute all task and sets mixing parameters
+   //
+   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+   AliAnalysisTaskSE *mixTask = 0;
+   TObjArrayIter next(mgr->GetTasks());
+   while ((mixTask = (AliAnalysisTaskSE *) next())) {
+      if (dynamic_cast<AliAnalysisTaskSE *>(mixTask)) {
+         AliDebug(AliLog::kDebug, Form("%s %lld %d [%lld,%lld] %d", mixTask->GetName(), entryCounter, numMixed, entryMainReal, entryMixReal, idEntryList));
+//          mixTask->SetCurrentBinIndex(idEntryList);
+//          mixTask->SetCurrentEntry(entryCounter);
+//          mixTask->SetCurrentEntryMain(entryMainReal);
+//          mixTask->SetCurrentEntryMix(entryMixReal);
+//          mixTask->SetNumberMixed(numMixed);
+         fCurrentEntry = idEntryList;
+         fCurrentEntryMain = entryCounter;
+         fCurrentEntryMix = entryMainReal;
+         fCurrentBinIndex = entryMixReal;
+
+         if (entryMixReal > -1) mixTask->UserExecMix("");
+      }
+   }
+}
+
+//_____________________________________________________________________________
+void AliMixInputEventHandler::SetMixNumber(const Int_t mixNum)
+{
+   //
+   // Sets mix number
+   //
+   if (fMixNumber > 1 && fBufferSize > 1) {
+      AliWarning("Sleeping 10 sec to show Warning Message ...")
+      AliWarning("=========================================================================================");
+      AliWarning(Form("BufferSize(%d) higher > 1 and fMixNumber(%d) > 1, which is not supported", fBufferSize, mixNum));
+      AliWarning("");
+      AliWarning("\tBufferSize will be set to 1");
+      AliWarning("");
+      AliWarning("Hints:");
+      AliWarning("");
+      AliWarning("\t1.If you want to use buffer do:");
+      AliWarning(Form("\t\tAliMixInputEventHandler *mixH = new AliMixInputEventHandler(%d,1)", fBufferSize));
+      AliWarning("");
+      AliWarning("\t2.If you want to use mix more time with buffer size 1, then do:");
+      AliWarning(Form("\t\tAliMixInputEventHandler *mixH = new AliMixInputEventHandler(1,%d)", mixNum));
+      AliWarning("");
+      AliWarning("=========================================================================================");
+      gSystem->Sleep(10000);
+      fBufferSize = 1;
+   }
+   fMixNumber = mixNum;
+}
diff --git a/ANALYSIS/EventMixing/AliMixInputEventHandler.h b/ANALYSIS/EventMixing/AliMixInputEventHandler.h
new file mode 100644 (file)
index 0000000..21bf37f
--- /dev/null
@@ -0,0 +1,100 @@
+//
+// Class AliMixEventInputHandler
+//
+// Mixing input handler prepare N events before UserExec
+// TODO example
+// author:
+//        Martin Vala (martin.vala@cern.ch)
+//
+
+#ifndef ALIMIXINPUTEVENTHANDLER_H
+#define ALIMIXINPUTEVENTHANDLER_H
+
+#include <TObjArray.h>
+#include <TArrayI.h>
+
+#include "AliMultiInputEventHandler.h"
+
+class TChain;
+class AliMixEventPool;
+class AliMixInputHandlerInfo;
+class AliInputEventHandler;
+class AliMixInputEventHandler : public AliMultiInputEventHandler {
+
+public:
+   AliMixInputEventHandler(const Int_t size = 1, const Int_t mixNum = 1);
+
+   // From the interface
+   virtual Bool_t  Init(Option_t *opt) { return AliMultiInputEventHandler::Init(opt); }
+   virtual Bool_t  Init(TTree *tree, Option_t *opt);
+   virtual Bool_t  Notify();
+   virtual Bool_t  Notify(const char *path);
+   virtual Bool_t  BeginEvent(Long64_t entry);
+   virtual Bool_t  GetEntry();
+   virtual Bool_t  FinishEvent();
+
+   // removing default impementation
+   virtual void            AddInputEventHandler(AliVEventHandler */*inHandler*/);
+
+   void                    SetInputHandlerForMixing(const AliInputEventHandler *const inHandler);
+   void                    SetEventPool(AliMixEventPool *const evPool) { fEventPool = evPool; }
+
+   AliInputEventHandler   *InputEventHandler(const Int_t index);
+   AliMixEventPool        *GetEventPool() const { return fEventPool; }
+   Int_t                   BufferSize() const { return fBufferSize; }
+   Int_t                   NumberMixedTimes() const { return fNumberMixed; }
+   Int_t                   MixNumber() const { return fMixNumber; }
+   Long64_t                EntryAll() const { return fEntryCounter; }
+   void                    UseDefaultProcess(Bool_t b = kTRUE) { fUseDefautProcess = b; }
+   void                    UsePreMixEvents(Bool_t b = kTRUE) { fUsePreMixEvents = b; }
+   void                    SetMixNumber(const Int_t mixNum);
+
+   void                    SetCurrentBinIndex(Int_t const index) { fCurrentBinIndex = index; }
+   void                    SetCurrentEntry(Long64_t const entry) { fCurrentEntry = entry ; }
+   void                    SetCurrentEntryMain(Long64_t const entry) { fCurrentEntryMain = entry ; }
+   void                    SetCurrentEntryMix(Long64_t const entry) { fCurrentEntryMix = entry ; }
+   void                    SetNumberMixed(Int_t const index) { fNumberMixed = index; }
+
+   Int_t                   CurrentBinIndex() const { return fCurrentBinIndex; }
+   Long64_t                CurrentEntry() const { return fCurrentEntry; }
+   Long64_t                CurrentEntryMain() const { return fCurrentEntryMain; }
+   Long64_t                CurrentEntryMix() const { return fCurrentEntryMix; }
+   Int_t                   NumberMixed() const { return fNumberMixed; }
+
+
+
+protected:
+
+   TObjArray               fMixTrees;              // buffer of input handlers
+   TArrayI                 fTreeMap;               // tree map
+   AliMixInputHandlerInfo *fMixIntupHandlerInfoTmp;//! mix input handler info full chain
+   Long64_t                fEntryCounter;          // entry counter
+   AliMixEventPool        *fEventPool;             // event pool
+   Int_t                   fNumberMixed;           // number of mixed events with current event
+   Int_t                   fMixNumber;             // user's mix number request
+
+private:
+
+   Bool_t                  fUseDefautProcess;      // use default process
+   Bool_t                  fUsePreMixEvents;       // use pre mixing events
+
+   // mixing info
+   Long64_t fCurrentEntry;       //! current entry number (adds 1 for every event processed on each worker)
+   Long64_t fCurrentEntryMain;   //! current entry in chain of processed files
+   Long64_t fCurrentEntryMix;    //! current mixed entry in chain of processed files
+   Int_t    fCurrentBinIndex;    //! current bin index
+
+   virtual Bool_t          MixStd();
+   virtual Bool_t          MixBuffer();
+   virtual Bool_t          MixEventsMoreTimesWithOneEvent();
+   virtual Bool_t          MixEventsMoreTimesWithBuffer();
+
+   void                    UserExecMixAllTasks(Long64_t entryCounter, Int_t idEntryList, Long64_t entryMainReal, Long64_t entryMixReal, Int_t numMixed);
+
+   AliMixInputEventHandler(const AliMixInputEventHandler& handler);
+   AliMixInputEventHandler &operator=(const AliMixInputEventHandler &handler);
+
+   ClassDef(AliMixInputEventHandler, 1)
+};
+
+#endif
index f847dc1..40aa7d9 100644 (file)
@@ -1,10 +1,10 @@
 //
 // Class AliMixInputHandlerInfo
 //
-// AliMixInputHandlerInfo is interface with mixed 
+// AliMixInputHandlerInfo is interface with mixed
 // input handlers
 //
-// author: 
+// author:
 //        Martin Vala (martin.vala@cern.ch)
 //
 #include <TTree.h>
 ClassImp(AliMixInputHandlerInfo)
 
 //_____________________________________________________________________________
-AliMixInputHandlerInfo::AliMixInputHandlerInfo(const char* name, const char* title): TNamed(name, title),
-    fChain(0),
-    fChainEntriesArray(),
-    fZeroEntryNumber(0),
-    fNeedNotify(kFALSE) {
-  //
-  // Default constructor.
-  //
+AliMixInputHandlerInfo::AliMixInputHandlerInfo(const char *name, const char *title): TNamed(name, title),
+   fChain(0),
+   fChainEntriesArray(),
+   fZeroEntryNumber(0),
+   fNeedNotify(kFALSE)
+{
+   //
+   // Default constructor.
+   //
 }
 //_____________________________________________________________________________
-AliMixInputHandlerInfo::~AliMixInputHandlerInfo() {
-  //
-  // Destructor
-  //
-  if (fChain) delete fChain;
+AliMixInputHandlerInfo::~AliMixInputHandlerInfo()
+{
+   //
+   // Destructor
+   //
+   if (fChain) delete fChain;
 }
 
 //_____________________________________________________________________________
-TChain* AliMixInputHandlerInfo::GetChain() {
-  //
-  // Returns curren chain. When chain is null it will create it
-  //
-  if (!fChain) fChain = new TChain(GetName());
-  return fChain;
+TChain *AliMixInputHandlerInfo::GetChain()
+{
+   //
+   // Returns curren chain. When chain is null it will create it
+   //
+   if (!fChain) fChain = new TChain(GetName());
+   return fChain;
 }
 
 //_____________________________________________________________________________
-void AliMixInputHandlerInfo::AddChain(TChain* chain) {
-  //
-  // Add chain
-  //
-  AliDebug(AliLog::kDebug, "<-");
-
-  if (!chain) return;
-
-  if (fChain) delete fChain;
-  fChain = new TChain(GetName());
-  fChain->Add(chain);
-
-  AliDebug(AliLog::kDebug, "->");
+void AliMixInputHandlerInfo::AddChain(TChain *chain)
+{
+   //
+   // Add chain
+   //
+   AliDebug(AliLog::kDebug + 5, "<-");
+   if (!chain) return;
+   if (fChain) delete fChain;
+   fChain = new TChain(GetName());
+   fChain->Add(chain);
+   AliDebug(AliLog::kDebug + 5, "->");
 }
 
 //_____________________________________________________________________________
-void AliMixInputHandlerInfo::AddTreeToChain(TTree *tree) {
-  //
-  // Adds tree to chain
-  //
-  AliDebug(AliLog::kDebug, Form("%s %lld", tree->GetCurrentFile()->GetName(), tree->GetEntries()));
-
-  GetChain();
-  fChain->AddFile(tree->GetCurrentFile()->GetName());
-
-
-  fChainEntriesArray.Set(fChain->GetListOfFiles()->GetEntries());
-
-  AliDebug(AliLog::kDebug, Form("Adding %lld to id %d", tree->GetEntries(), fChain->GetListOfFiles()->GetEntries() - 1));
-  fChainEntriesArray.AddAt(tree->GetEntries(), fChain->GetListOfFiles()->GetEntries() - 1);
-
+void AliMixInputHandlerInfo::AddTreeToChain(const char *path)
+{
+   //
+   // Adds tree in to chain
+   //
+   AliDebug(AliLog::kDebug + 5, Form("<- %s", path));
+   GetChain();
+   fChain->AddFile(path);
+   AliDebug(AliLog::kDebug + 3, Form("Num files in fChain %d", fChain->GetListOfFiles()->GetEntries()));
+   Long64_t sumTree = fZeroEntryNumber;
+   for (Int_t i = 0; i < fChainEntriesArray.GetSize() ; i++) sumTree += fChainEntriesArray.At(i);
+   fChain->LoadTree(sumTree);
+   Int_t lastIndex = fChain->GetListOfFiles()->GetEntries();
+   AliDebug(AliLog::kDebug + 3, Form("Num files in fChain %d", lastIndex));
+   fChainEntriesArray.Set(lastIndex);
+   AliDebug(AliLog::kDebug + 3, Form("Adding %lld to id %d", fChain->GetTree()->GetEntries(), lastIndex - 1));
+   fChainEntriesArray.AddAt((Int_t)fChain->GetTree()->GetEntries(), (Int_t)lastIndex - 1);
+   AliDebug(AliLog::kDebug + 5, Form("-> %s", path));
 }
 
 //_____________________________________________________________________________
-TChainElement* AliMixInputHandlerInfo::GetEntryInTree(Long64_t& entry) {
-  //
-  // Get entry in current tree
-  //
-  fZeroEntryNumber = 0;
-  if (entry < fZeroEntryNumber) {
-    AliError(Form("Num %lld is less then ZeroEntryNumber(%lld)", entry, fZeroEntryNumber));
-    entry = -1;
-    return 0;
-  }
-
-  Long64_t sumTree = fZeroEntryNumber;
-  for (Int_t i = 0;i < fChainEntriesArray.GetSize() ;i++) {
-    sumTree += fChainEntriesArray.At(i);
-    if (sumTree > entry) {
-      sumTree = entry - sumTree + fChainEntriesArray.At(i);
-      AliDebug(AliLog::kDebug, Form("Entry in current tree num is %lld with i=%d", sumTree, i));
-
-      entry = sumTree;
-      TChainElement *chEl = (TChainElement*) fChain->GetListOfFiles()->At(i);
-      AliDebug(AliLog::kDebug, Form("Real filename is %s %s", chEl->GetName(), chEl->GetTitle()));
-
-      AliDebug(AliLog::kDebug, Form("And filename is %s %lld", fChain->GetTree()->GetCurrentFile()->GetName(), fChain->GetEntries()));
-      return chEl;
-    }
-  }
-
-  entry = -1;
-  return 0;
+TChainElement *AliMixInputHandlerInfo::GetEntryInTree(Long64_t &entry)
+{
+   //
+   // Get entry in current tree
+   //
+   AliDebug(AliLog::kDebug + 5, Form("<- %lld", entry));
+   fZeroEntryNumber = 0;
+   if (entry < fZeroEntryNumber) {
+      AliError(Form("Num %lld is less then ZeroEntryNumber(%lld)", entry, fZeroEntryNumber));
+      entry = -1;
+      AliDebug(AliLog::kDebug + 5, "->");
+      return 0;
+   }
+   Long64_t sumTree = fZeroEntryNumber;
+   for (Int_t i = 0; i < fChainEntriesArray.GetSize() ; i++) {
+      sumTree += fChainEntriesArray.At(i);
+      if (sumTree > entry) {
+         sumTree = entry - sumTree + fChainEntriesArray.At(i);
+         AliDebug(AliLog::kDebug + 1, Form("Entry in current tree num is %lld with i=%d", sumTree, i));
+         entry = sumTree;
+         AliDebug(AliLog::kDebug + 5, "->");
+         return (TChainElement *) fChain->GetListOfFiles()->At(i);
+      }
+   }
+   entry = -1;
+   AliDebug(AliLog::kDebug + 5, "->");
+   return 0;
 }
 
 //_____________________________________________________________________________
-void AliMixInputHandlerInfo::PrepareEntry(TChainElement *te, Long64_t entry, AliInputEventHandler *eh) {
-  //
-  // Prepare Entry 
-  //
-  if (!te) return;
-
-  if (te) {
-    if (entry < 0) {
+void AliMixInputHandlerInfo::PrepareEntry(TChainElement *te, Long64_t entry, AliInputEventHandler *eh, Option_t *opt)
+{
+   //
+   // Prepare Entry
+   //
+   AliDebug(AliLog::kDebug + 5, Form("<- %lld", entry));
+   if (!te) {
+      AliDebug(AliLog::kDebug + 5, "-> te is null");
+      return;
+   }
+   if (entry < 0) {
       AliDebug(AliLog::kDebug, Form("We are creating new chain from file %s ...", te->GetTitle()));
       if (!fChain) {
-        fChain = new TChain(te->GetName());
-        fChain->AddFile(te->GetTitle());
-        fChain->GetEntry(0);
-        eh->Init(fChain->GetTree(), "proof");
+         fChain = new TChain(te->GetName());
+         fChain->AddFile(te->GetTitle());
+         fChain->GetEntry(0);
+         eh->Init(fChain->GetTree(), opt);
 //       eh->Notify(te->GetTitle());
       }
       fNeedNotify = kTRUE;
+      AliDebug(AliLog::kDebug + 5, "->");
       return;
-    }
-
-  }
-
-  if (fChain) {
-    AliDebug(AliLog::kDebug, Form("Filename is %s", fChain->GetCurrentFile()->GetName()));
-    TString fn = fChain->GetCurrentFile()->GetName();
-    if (fn.CompareTo(te->GetTitle())) {
-      AliDebug(AliLog::kDebug, Form("Filename %s is NOT same ...", te->GetTitle()));
-      AliDebug(AliLog::kDebug, Form("We are changing to file %s ...", te->GetTitle()));
-      // change file
-      delete fChain;
-      fChain = new TChain(te->GetName());
-      fChain->AddFile(te->GetTitle());
-      fChain->GetEntry(0);
-      eh->Init(fChain->GetTree(), "proof");
-
-      eh->Notify(te->GetTitle());
-      eh->BeginEvent(entry);
-      fChain->GetEntry(entry);
-      fNeedNotify = kFALSE;
-    } else {
-      AliDebug(AliLog::kDebug, Form("We are reusing file %s ...", te->GetTitle()));
-      if (fNeedNotify) eh->Notify(te->GetTitle());
-      fNeedNotify = kFALSE;
-      AliDebug(AliLog::kDebug, Form("Entry is %lld + GetEntries %lld ...", entry, fChain->GetEntries()));
-      eh->BeginEvent(entry);
-      fChain->GetEntry(entry);
-      // file is in tree fChain already
-    }
-  }
-
-  AliDebug(AliLog::kDebug, Form("We are USING file %s ...", te->GetTitle()));
-  AliDebug(AliLog::kDebug, Form("We are USING file from fChain->GetTree() %s ...", fChain->GetTree()->GetCurrentFile()->GetName()));
-
-  // here we have correct chain with 1 tree only
-  AliDebug(AliLog::kDebug, Form("Entry is %lld ...", entry));
+   }
+   if (fChain) {
+      AliDebug(AliLog::kDebug, Form("Filename is %s", fChain->GetTree()->GetCurrentFile()->GetName()));
+      TString fn = fChain->GetTree()->GetCurrentFile()->GetName();
+      if (fn.CompareTo(te->GetTitle())) {
+         AliDebug(AliLog::kDebug, Form("Filename %s is NOT same ...", te->GetTitle()));
+         AliDebug(AliLog::kDebug, Form("We are changing to file %s ...", te->GetTitle()));
+         // change file
+         delete fChain;
+         fChain = new TChain(te->GetName());
+         fChain->AddFile(te->GetTitle());
+         fChain->GetEntry(0);
+         eh->Init(fChain->GetTree(), opt);
+         eh->Notify(te->GetTitle());
+         eh->BeginEvent(entry);
+         fChain->GetEntry(entry);
+         fNeedNotify = kFALSE;
+      } else {
+         AliDebug(AliLog::kDebug, Form("We are reusing file %s ...", te->GetTitle()));
+         if (fNeedNotify) eh->Notify(te->GetTitle());
+         fNeedNotify = kFALSE;
+         AliDebug(AliLog::kDebug, Form("Entry is %lld  fChain->GetEntries %lld ...", entry, fChain->GetEntries()));
+         eh->BeginEvent(entry);
+         fChain->GetEntry(entry);
+         // file is in tree fChain already
+      }
+   }
+   AliDebug(AliLog::kDebug, Form("We are USING file %s ...", te->GetTitle()));
+   AliDebug(AliLog::kDebug, Form("We are USING file from fChain->GetTree() %s ...", fChain->GetTree()->GetCurrentFile()->GetName()));
+   // here we have correct chain with 1 tree only
+   AliDebug(AliLog::kDebug + 5, "->");
+}
 
+//_____________________________________________________________________________
+Long64_t AliMixInputHandlerInfo::GetEntries()
+{
+   //
+   // Returns number of entries
+   //
+   if (fChain) return fChain->GetEntries();
+   return -1;
 }
index adb49c8..13e2d66 100644 (file)
@@ -1,10 +1,10 @@
 //
 // Class AliMixInputHandlerInfo
 //
-// AliMixInputHandlerInfo is interface with mixed 
+// AliMixInputHandlerInfo is interface with mixed
 // input handlers
 //
-// author: 
+// author:
 //        Martin Vala (martin.vala@cern.ch)
 //
 #ifndef ALIMIXINPUTHANDLERINFO_H
@@ -19,28 +19,30 @@ class AliInputEventHandler;
 class AliMixInputHandlerInfo : public TNamed {
 
 public:
-  AliMixInputHandlerInfo(const char* name = "defautlTree", const char* title = "Defautl tree");
-  virtual ~AliMixInputHandlerInfo();
-  TChain *GetChain();
-  
-  void AddChain(TChain *chain);
-  void AddTreeToChain(TTree *tree);
-  
-  void PrepareEntry(TChainElement* te, Long64_t entry, AliInputEventHandler* eh);
-  
-  void SetZeroEntryNumber(Long64_t num) { fZeroEntryNumber = num;}
-  TChainElement* GetEntryInTree(Long64_t& entry);
+   AliMixInputHandlerInfo(const char *name = "defautlTree", const char *title = "Defautl tree");
+   virtual ~AliMixInputHandlerInfo();
+   TChain *GetChain();
+
+   void AddChain(TChain *chain);
+//     void AddTreeToChain(TTree *tree);
+   void AddTreeToChain(const char *path);
+
+   void PrepareEntry(TChainElement *te, Long64_t entry, AliInputEventHandler *eh, Option_t *opt);
+
+   void SetZeroEntryNumber(Long64_t num) { fZeroEntryNumber = num; }
+   TChainElement *GetEntryInTree(Long64_t &entry);
+   Long64_t      GetEntries();
 
 private:
-  TChain    *fChain;              // current chain
-  TArrayI   fChainEntriesArray;   // array of entries of every chaing
-  Long64_t  fZeroEntryNumber;     // zero entry number (will be used when we will delete not needed chains)
-  Bool_t    fNeedNotify;          // flag if Notify is needed for current input handler
-  
-  AliMixInputHandlerInfo(const AliMixInputHandlerInfo& handler);             
-  AliMixInputHandlerInfo& operator=(const AliMixInputHandlerInfo& handler);  
-
-  ClassDef(AliMixInputHandlerInfo, 1); // Mix Input Handler info
+   TChain    *fChain;              // current chain
+   TArrayI   fChainEntriesArray;   // array of entries of every chaing
+   Long64_t  fZeroEntryNumber;     // zero entry number (will be used when we will delete not needed chains)
+   Bool_t    fNeedNotify;          // flag if Notify is needed for current input handler
+
+   AliMixInputHandlerInfo(const AliMixInputHandlerInfo &handler);
+   AliMixInputHandlerInfo &operator=(const AliMixInputHandlerInfo &handler);
+
+   ClassDef(AliMixInputHandlerInfo, 1); // Mix Input Handler info
 };
 
 #endif // ALIMIXINPUTHANDLERINFO_H
index f78558c..757bff1 100644 (file)
@@ -1,12 +1,11 @@
 #ifdef __CINT__
 
-#pragma link off all globals;
-#pragma link off all classes;
-#pragma link off all functions;
+#pragma link C++ class AliMixEventCutObj+;
+#pragma link C++ class AliMixEventPool+;
 
-#pragma link C++ class AliMixEventInputHandler+;
+#pragma link C++ class AliMixInfo+;
 #pragma link C++ class AliMixInputHandlerInfo+;
-#pragma link C++ class AliMixEventPool+;
-#pragma link C++ class AliMixEventCutObj+;
+#pragma link C++ class AliMixInputEventHandler+;
+#pragma link C++ class AliAnalysisTaskMixInfo+;
 
 #endif