--- /dev/null
+//
+// Class AliMixEventCutObj
+//
+// AliMixEventCutObj object contains information about one cut on for event mixing
+// used by AliMixEventPool class
+//
+// authors:
+// Martin Vala (martin.vala@cern.ch)
+//
+
+#include "AliLog.h"
+#include "AliESDEvent.h"
+#include "AliAODEvent.h"
+#include "AliMultiplicity.h"
+
+#include "AliMixEventCutObj.h"
+
+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, "->");
+}
+//_________________________________________________________________________________________________
+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.
+ //
+}
+
+//_________________________________________________________________________________________________
+void AliMixEventCutObj::Reset() {
+ //
+ // Reset cut.
+ //
+
+ AliDebug(AliLog::kDebug + 2, "<-");
+ fCurrentVal = fCutMin - fCutStep;
+ fNoMore = kFALSE;
+ AliDebug(AliLog::kDebug + 2, "->");
+}
+//_________________________________________________________________________________________________
+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::Print(const Option_t *) const {
+ //
+ // Prints cut information
+ //
+
+ AliInfo(Form("%d %f %f %f", fCutType, fCutMin, fCutMax, fCutStep));
+}
+//_________________________________________________________________________________________________
+void AliMixEventCutObj::PrintCurrentInterval() {
+ //
+ // Prints current cut interval information
+ //
+
+ AliInfo(Form("%s <%f,%f>", GetNameOfCut(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::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(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;
+}
+//_________________________________________________________________________________________________
+const char* AliMixEventCutObj::GetNameOfCut(Short_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 "";
+}
+
--- /dev/null
+//
+// Class AliMixEventCutObj
+//
+// AliMixEventCutObj object contains information about one cut on for event mixing
+// used by AliMixEventPool class
+//
+// authors:
+// Martin Vala (martin.vala@cern.ch)
+//
+
+#ifndef ALIMIXEVENTCUTOBJ_H
+#define ALIMIXEVENTCUTOBJ_H
+
+#include <TObject.h>
+class AliVEvent;
+class AliAODEvent;
+class AliESDEvent;
+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
+
+ Float_t fCurrentVal; // current value
+ Bool_t fNoMore; // flag for no more bins
+
+ AliMixEventCutObj& operator=(const AliMixEventCutObj& ) { return *this;}
+
+ ClassDef(AliMixEventCutObj, 1)
+};
+
+#endif
--- /dev/null
+//
+// 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 "AliLog.h"
+#include "AliMixEventPool.h"
+#include "AliMixEventInputHandler.h"
+#include "AliAnalysisManager.h"
+
+#include "AliMixInputHandlerInfo.h"
+#include <TChainElement.h>
+
+ClassImp(AliMixEventInputHandler)
+
+//_____________________________________________________________________________
+AliMixEventInputHandler::AliMixEventInputHandler(const Int_t size) :
+ AliInputEventHandler(),
+ fBufferSize(size),
+ fInputHandlers(),
+ fMixTrees(),
+ fTreeMap(size),
+ fMixIntupHandlerInfoTmp(0),
+ fEntryCounter(0),
+ fEventPool(0),
+ fMixEventNumber(0) {
+//
+// Default constructor.
+//
+ AliDebug(AliLog::kDebug + 10, "<-");
+ AliDebug(AliLog::kDebug + 10, "->");
+}
+
+//_____________________________________________________________________________
+AliInputEventHandler* AliMixEventInputHandler::InputEventHandler(const Int_t index) {
+ //
+ // Returns input handler
+ //
+ AliDebug(AliLog::kDebug, Form("<-"));
+ if ((index >= 0) && (index < fBufferSize)) {
+ AliDebug(AliLog::kDebug, Form("->"));
+ return (AliInputEventHandler*) fInputHandlers.At(index);
+ }
+ AliDebug(AliLog::kDebug, Form("->"));
+ return 0;
+}
+//_____________________________________________________________________________
+void AliMixEventInputHandler::SetInputHandlerForMixing(const AliInputEventHandler*const inHandler) {
+ //
+ // Create N (fBufferSize) copies of input handler
+ //
+ AliDebug(AliLog::kDebug, Form("<-"));
+ AliDebug(AliLog::kDebug, 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, Form("->"));
+}
+//_____________________________________________________________________________
+Bool_t AliMixEventInputHandler::Init(Option_t*opt) {
+ //
+ // Init() is called for all mix input handlers.
+ //
+ AliDebug(AliLog::kDebug, Form("<- \"%s\"", opt));
+ AliInputEventHandler *eh = 0;
+ TObjArrayIter next(&fInputHandlers);
+ while ((eh = (AliInputEventHandler *) next())) {
+ eh->Init(opt);
+ }
+ AliDebug(AliLog::kDebug, Form("->"));
+ return kTRUE;
+}
+//_____________________________________________________________________________
+Bool_t AliMixEventInputHandler::Init(TTree* tree, Option_t*) {
+ //
+ // Init(const char*path) is called for all mix input handlers.
+ // Create event pool if needed
+ //
+ AliDebug(AliLog::kDebug, Form("<- %p", tree));
+ if (!tree) {
+ AliDebug(AliLog::kDebug, Form("->"));
+ return kFALSE;
+ }
+ AliDebug(AliLog::kDebug, Form("%s", tree->GetCurrentFile()->GetName()));
+
+ // clears array of input handlers
+ fMixTrees.SetOwner(kTRUE);
+ fMixTrees.Clear();
+
+ // create AliMixInputHandlerInfo
+ if (!fMixIntupHandlerInfoTmp) fMixIntupHandlerInfoTmp = new AliMixInputHandlerInfo(tree->GetName());
+
+ // adds current file
+ fMixIntupHandlerInfoTmp->AddTreeToChain(tree);
+ 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, Form("fInputHandlers[%d]", i));
+ mixIHI = new AliMixInputHandlerInfo(fMixIntupHandlerInfoTmp->GetName(), fMixIntupHandlerInfoTmp->GetTitle());
+ mixIHI->PrepareEntry(che, -1, InputEventHandler(i));
+ AliDebug(AliLog::kDebug, Form("chain[%d]->GetEntries() = %lld", i, mixIHI->GetChain()->GetEntries()));
+ fMixTrees.Add(mixIHI);
+ }
+ AliDebug(AliLog::kDebug, Form("fEntryCounter=%lld", fEntryCounter));
+
+ if (fEventPool->NeedInit())
+ fEventPool->Init();
+
+ AliDebug(AliLog::kDebug, Form("->"));
+ return kTRUE;
+}
+//_____________________________________________________________________________
+Bool_t AliMixEventInputHandler::Notify() {
+ //
+ // Notify() is called for all mix input handlers
+ //
+ AliDebug(AliLog::kDebug, Form("<-"));
+ AliInputEventHandler *eh = 0;
+ TObjArrayIter next(&fInputHandlers);
+ while ((eh = (AliInputEventHandler *) next())) {
+ eh->Notify();
+ }
+ AliDebug(AliLog::kDebug, Form("->"));
+ return kTRUE;
+}
+
+//_____________________________________________________________________________
+Bool_t AliMixEventInputHandler::Notify(const char*path) {
+ //
+ // Notify(const char*path) is called for all mix input handlers
+ //
+ AliDebug(AliLog::kDebug, Form("<- %s", path));
+ AliInputEventHandler *eh = 0;
+ TObjArrayIter next(&fInputHandlers);
+ while ((eh = (AliInputEventHandler *) next())) {
+ eh->Notify(path);
+ }
+ AliDebug(AliLog::kDebug, Form("->"));
+ return kTRUE;
+}
+//_____________________________________________________________________________
+Bool_t AliMixEventInputHandler::BeginEvent(Long64_t entry) {
+ //
+ // BeginEvent(Long64_t entry) is called for all mix input handlers
+ //
+
+ AliDebug(AliLog::kDebug, Form("-> %lld", entry));
+ AliInputEventHandler *eh = 0;
+ TObjArrayIter next(&fInputHandlers);
+ while ((eh = (AliInputEventHandler *) next())) {
+ eh->BeginEvent(entry);
+ }
+ AliDebug(AliLog::kDebug, Form("->"));
+ return kTRUE;
+}
+
+
+//_____________________________________________________________________________
+Bool_t AliMixEventInputHandler::GetEntry() {
+ //
+ // Sets correct events to every mix events
+ //
+ AliDebug(AliLog::kDebug, Form("<-"));
+
+ AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+ AliInputEventHandler *inEvHMain = dynamic_cast<AliInputEventHandler *>(mgr->GetInputEventHandler());
+
+ Long64_t zeroChainEntries = fMixIntupHandlerInfoTmp->GetChain()->GetEntries() - inEvHMain->GetTree()->GetEntries();
+
+ // if fEntryCounter is 0 just add entry
+ if (!fEntryCounter) {
+ if (inEvHMain) {
+
+ fEventPool->AddEntry(inEvHMain->GetTree()->GetReadEntry() + zeroChainEntries, inEvHMain->GetEvent());
+ }
+ return kTRUE;
+ }
+
+ AliDebug(AliLog::kDebug, Form("++++++++++++++ BEGIN SETUP EVENT %lld +++++++++++++++++++", fEntryCounter));
+
+ fMixEventNumber = 0;
+ TEntryList *el = fEventPool->FindEntryList(inEvHMain->GetEvent());
+ Long64_t elNum = 0;
+ if (el)
+ elNum = el->GetN();
+ else
+ AliDebug(AliLog::kDebug, "el is null");
+
+ AliInputEventHandler *eh = 0;
+ AliMixInputHandlerInfo *mihi = 0;
+ TObjArrayIter next(&fInputHandlers);
+ Int_t counter = 0;
+ Long64_t entryMix = 0;
+ while ((eh = (AliInputEventHandler *) next())) {
+ if (fEventPool->GetListOfEventCuts()->GetEntries() > 0) {
+ entryMix = -1;
+ if (el && el->GetN() >= fBufferSize) {
+ Long64_t entryInEntryList = elNum - 1 - counter;
+ if (entryInEntryList < 0) break;
+ entryMix = el->GetEntry(entryInEntryList);
+ }
+ } else {
+ entryMix = fEntryCounter - 1 - counter ;
+ }
+
+ AliDebug(AliLog::kDebug, Form("Handler[%d] entryMix %lld ", counter, entryMix));
+ if (entryMix < 0) break;
+
+ mihi = (AliMixInputHandlerInfo*) fMixTrees.At(counter);
+ TChainElement *te = fMixIntupHandlerInfoTmp->GetEntryInTree(entryMix);
+ mihi->PrepareEntry(te, entryMix, InputEventHandler(counter));
+ fMixEventNumber++;
+ counter++;
+ }
+
+ if (inEvHMain) {
+ fEventPool->AddEntry(inEvHMain->GetTree()->GetReadEntry() + zeroChainEntries, inEvHMain->GetEvent());
+ }
+
+ AliDebug(AliLog::kDebug, Form("fEntryCounter=%lld fMixEventNumber=%d", fEntryCounter, fMixEventNumber));
+ AliDebug(AliLog::kDebug, Form("++++++++++++++ END SETUP EVENT %lld +++++++++++++++++++", fEntryCounter));
+ AliDebug(AliLog::kDebug, Form("->"));
+ return kTRUE;
+}
+//_____________________________________________________________________________
+Bool_t AliMixEventInputHandler::FinishEvent() {
+ //
+ // FinishEvent() is called for all mix input handlers
+ //
+ AliDebug(AliLog::kDebug, Form("<-"));
+ AliInputEventHandler *eh = 0;
+ TObjArrayIter next(&fInputHandlers);
+ while ((eh = (AliInputEventHandler *) next())) {
+ eh->FinishEvent();
+ }
+ fEntryCounter++;
+ AliDebug(AliLog::kDebug, Form("->"));
+ return kTRUE;
+}
--- /dev/null
+//
+// Class AliMixEventInputHandler
+//
+// Mixing input handler prepare N events before UserExec
+// TODO example
+// author:
+// Martin Vala (martin.vala@cern.ch)
+//
+
+#ifndef ALIMIXEVENTINPUTHANDLER_H
+#define ALIMIXEVENTINPUTHANDLER_H
+
+#include <TObjArray.h>
+
+#include "AliInputEventHandler.h"
+#include <TArrayI.h>
+
+class TChain;
+class AliMixEventPool;
+class AliMixInputHandlerInfo;
+class AliMixEventInputHandler : public AliInputEventHandler {
+
+public:
+ AliMixEventInputHandler(const Int_t size=1);
+ virtual ~AliMixEventInputHandler() {;};
+
+ // From the interface
+ virtual Bool_t Init(Option_t* opt /*opt*/);
+ virtual Bool_t Init(TTree* tree, Option_t* /*opt*/);
+ virtual Bool_t BeginEvent(Long64_t entry /*entry*/);
+ virtual Bool_t GetEntry();
+ virtual Bool_t FinishEvent();
+ virtual Bool_t Notify();
+ virtual Bool_t Notify(const char *path);
+
+
+ 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 MixedEventNumber() const {return fMixEventNumber;}
+ Long64_t EntryAll() const { return fEntryCounter;}
+protected:
+
+ Int_t fBufferSize; // Size of the buffer
+ TObjArray fInputHandlers; // buffer of input handlers
+ 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 fMixEventNumber; // number mix
+
+private:
+
+ AliMixEventInputHandler(const AliMixEventInputHandler& handler);
+ AliMixEventInputHandler& operator=(const AliMixEventInputHandler& handler);
+
+ ClassDef(AliMixEventInputHandler, 1)
+};
+
+#endif
--- /dev/null
+//
+// Class AliMixEventPool
+//
+// AliMixEventPool is used to find
+// similar events
+//
+// author:
+// Martin Vala (martin.vala@cern.ch)
+//
+
+#include <TEntryList.h>
+
+#include "AliLog.h"
+#include "AliMixEventCutObj.h"
+
+#include "AliMixEventPool.h"
+
+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 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() {
+ //
+ // Destructor
+ //
+ AliDebug(AliLog::kDebug + 5, "<-");
+ AliDebug(AliLog::kDebug + 5, "->");
+}
+//_________________________________________________________________________________________________
+void AliMixEventPool::AddCut(AliMixEventCutObj* cut) {
+ //
+ // Adds cut
+ //
+
+ if (cut) fListOfEventCuts.Add(cut);
+}
+//_________________________________________________________________________________________________
+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()));
+ }
+}
+//_________________________________________________________________________________________________
+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();
+ }
+ }
+
+ }
+ 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;
+}
+
+//_________________________________________________________________________________________________
+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) {
+ //
+ // 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,"->");
+}
--- /dev/null
+//
+// Class AliMixEventPool
+//
+// AliMixEventPool is used to find
+// similar events
+//
+// author:
+// Martin Vala (martin.vala@cern.ch)
+//
+
+#ifndef ALIMIXEVENTPOOL_H
+#define ALIMIXEVENTPOOL_H
+
+#include <TObjArray.h>
+#include <TNamed.h>
+
+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)
+};
+
+#endif
--- /dev/null
+//
+// Class AliMixInputHandlerInfo
+//
+// AliMixInputHandlerInfo is interface with mixed
+// input handlers
+//
+// author:
+// Martin Vala (martin.vala@cern.ch)
+//
+#include <TTree.h>
+#include <TChain.h>
+#include <TFile.h>
+#include <TChainElement.h>
+
+#include "AliLog.h"
+#include "AliInputEventHandler.h"
+
+#include "AliMixInputHandlerInfo.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() {
+ //
+ // 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;
+}
+
+//_____________________________________________________________________________
+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::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);
+
+}
+
+//_____________________________________________________________________________
+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;
+}
+
+//_____________________________________________________________________________
+void AliMixInputHandlerInfo::PrepareEntry(TChainElement *te, Long64_t entry, AliInputEventHandler *eh) {
+ //
+ // Prepare Entry
+ //
+ if (!te) return;
+
+ if (te) {
+ 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");
+// eh->Notify(te->GetTitle());
+ }
+ fNeedNotify = kTRUE;
+ 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));
+
+}
--- /dev/null
+//
+// Class AliMixInputHandlerInfo
+//
+// AliMixInputHandlerInfo is interface with mixed
+// input handlers
+//
+// author:
+// Martin Vala (martin.vala@cern.ch)
+//
+#ifndef ALIMIXINPUTHANDLERINFO_H
+#define ALIMIXINPUTHANDLERINFO_H
+#include <TArrayI.h>
+#include <TNamed.h>
+
+class TTree;
+class TChain;
+class TChainElement;
+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);
+
+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
+};
+
+#endif // ALIMIXINPUTHANDLERINFO_H
--- /dev/null
+#ifdef __CINT__
+
+#pragma link off all globals;
+#pragma link off all classes;
+#pragma link off all functions;
+
+#pragma link C++ class AliMixEventInputHandler+;
+#pragma link C++ class AliMixInputHandlerInfo+;
+#pragma link C++ class AliMixEventPool+;
+#pragma link C++ class AliMixEventCutObj+;
+
+#endif
--- /dev/null
+#-*- Mode: Makefile -*-
+
+SRCS = \
+EventMixing/AliMixEventInputHandler.cxx \
+EventMixing/AliMixInputHandlerInfo.cxx \
+EventMixing/AliMixEventPool.cxx \
+EventMixing/AliMixEventCutObj.cxx
+
+
+HDRS:= $(SRCS:.cxx=.h)
+
+DHDR= EventMixingLinkDef.h
+
+EXPORT:=$(SRCS:.cxx=.h)
+
+#EINCLUDE:= ANALYSIS ANALYSIS/Tender
+
+#ifeq (win32gcc,$(ALICE_TARGET))
+#PACKSOFLAGS:= $(SOFLAGS) -L$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET) -lSTEERBase \
+# -lANALYSIS -lCDB
+#endif