]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/EventMixing/AliMixInputEventHandler.cxx
Fix for event mixing when running in local mode. Mix event inputhandler was calling...
[u/mrichter/AliRoot.git] / ANALYSIS / EventMixing / AliMixInputEventHandler.cxx
index fd9bab82f30476227be7354ee1beac821102afb6..0552fa6ecf2f123f937fc3326a2feb0c962e7bd5 100644 (file)
@@ -34,7 +34,8 @@ AliMixInputEventHandler::AliMixInputEventHandler(const Int_t size, const Int_t m
    fNumberMixed(0),
    fMixNumber(mixNum),
    fUseDefautProcess(kFALSE),
-   fUsePreMixEvents(kTRUE),
+   fDoMixExtra(kTRUE),
+   fDoMixIfNotEnoughEvents(kTRUE),
    fCurrentEntry(0),
    fCurrentEntryMain(0),
    fCurrentEntryMix(0),
@@ -50,24 +51,6 @@ AliMixInputEventHandler::AliMixInputEventHandler(const Int_t size, const Int_t m
    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)
 {
@@ -81,6 +64,7 @@ void AliMixInputEventHandler::SetInputHandlerForMixing(const AliInputEventHandle
       AliDebug(AliLog::kDebug + 5, Form("Adding %d ...", i));
       fInputHandlers.Add((AliInputEventHandler *) inHandler->Clone());
    }
+
    AliDebug(AliLog::kDebug + 5, Form("->"));
 }
 
@@ -97,6 +81,12 @@ Bool_t AliMixInputEventHandler::Init(TTree *tree, Option_t *opt)
       AliDebug(AliLog::kDebug + 5, Form("->"));
       return kFALSE;
    }
+
+   if (!fDoMixIfNotEnoughEvents) {
+      fDoMixExtra = kFALSE;
+      AliWarning("fDoMixIfNotEnoughEvents=kTRUE -> setting fDoMixExtra=kFALSE");
+   }
+
    // clears array of input handlers
    fMixTrees.Clear();
    // create AliMixInputHandlerInfo
@@ -105,6 +95,14 @@ Bool_t AliMixInputEventHandler::Init(TTree *tree, Option_t *opt)
       tree->LoadTree(0);
       fMixIntupHandlerInfoTmp = new AliMixInputHandlerInfo(tree->GetName());
    }
+
+   AliInputEventHandler *ih = 0;
+   for (Int_t i = 0; i < fInputHandlers.GetEntries(); i++) {
+      ih = (AliInputEventHandler *) fInputHandlers.At(i);
+      ih->SetParentHandler(this);
+//       ih->Init(tree,opt);
+   }
+
    AliDebug(AliLog::kDebug + 5, Form("->"));
    return kTRUE;
 }
@@ -130,6 +128,8 @@ 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));
+   
+   Bool_t firstRun=(fMixIntupHandlerInfoTmp->GetChain()->GetEntries()<=0);
    // adds current file
    fMixIntupHandlerInfoTmp->AddTreeToChain(path);
    Int_t lastIndex = fMixIntupHandlerInfoTmp->GetChain()->GetListOfFiles()->GetEntries();
@@ -138,7 +138,7 @@ Bool_t AliMixInputEventHandler::Notify(const char *path)
    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);
+      if (firstRun) mixIHI->PrepareEntry(che, -1, (AliInputEventHandler*)InputEventHandler(i), fAnalysisType);
       AliDebug(AliLog::kDebug + 5, Form("chain[%d]->GetEntries() = %lld", i, mixIHI->GetChain()->GetEntries()));
       fMixTrees.Add(mixIHI);
    }
@@ -188,6 +188,7 @@ Bool_t AliMixInputEventHandler::GetEntry()
    } else {
       AliWarning("Not supported Mixing !!!");
    }
+
    AliDebug(AliLog::kDebug + 5, Form("->"));
    return kTRUE;
 }
@@ -220,7 +221,7 @@ Bool_t AliMixInputEventHandler::MixStd()
    }
    // pre mix evetns
    Int_t mixNum = fMixNumber;
-   if (fUsePreMixEvents) {
+   if (fDoMixExtra) {
       if (fEntryCounter <= 2 * fMixNumber) mixNum = 2 * fMixNumber + 2;
    }
    // start of
@@ -238,9 +239,9 @@ Bool_t AliMixInputEventHandler::MixStd()
       mihi = (AliMixInputHandlerInfo *) fMixTrees.At(0);
       TChainElement *te = fMixIntupHandlerInfoTmp->GetEntryInTree(entryMix);
       if (!te) {
-         AliError("te is null. this is error. tell to developer (#1)")
+       AliError("te is null. this is error. tell to developer (#1)");
       } else {
-         mihi->PrepareEntry(te, entryMix, InputEventHandler(0), fAnalysisType);
+         mihi->PrepareEntry(te, entryMix, (AliInputEventHandler*)InputEventHandler(0), fAnalysisType);
          // runs UserExecMix for all tasks
          fNumberMixed++;
          UserExecMixAllTasks(fEntryCounter, 1, fEntryCounter, entryMixReal, fNumberMixed);
@@ -303,7 +304,7 @@ Bool_t AliMixInputEventHandler::MixBuffer()
       elNum = el->GetN();
       if (elNum < fBufferSize + 1) {
          UserExecMixAllTasks(fEntryCounter, idEntryList, currentMainEntry, -1, 0);
-         AliDebug(AliLog::kDebug + 3, Form("++++++++++++++ END SETUP EVENT %lld SKIPPED (%lld) +++++++++++++++++++", fEntryCounter, elNum));
+         AliDebug(AliLog::kDebug + 3, Form("++++++++++++++ END SETUP EVENT %lld SKIPPED (%lld) LESS THEN BUFFER +++++++++++++++++++", fEntryCounter, elNum));
          return kTRUE;
       }
    }
@@ -330,10 +331,10 @@ Bool_t AliMixInputEventHandler::MixBuffer()
       mihi = (AliMixInputHandlerInfo *) fMixTrees.At(counter);
       TChainElement *te = fMixIntupHandlerInfoTmp->GetEntryInTree(entryMix);
       if (!te) {
-         AliError("te is null. this is error. tell to developer (#1)")
+       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);
+         mihi->PrepareEntry(te, entryMix, (AliInputEventHandler*)InputEventHandler(counter), fAnalysisType);
          // runs UserExecMix for all tasks
          UserExecMixAllTasks(fEntryCounter, idEntryList, fEntryCounter, entryMixReal, counter);
          fNumberMixed++;
@@ -382,8 +383,12 @@ Bool_t AliMixInputEventHandler::MixEventsMoreTimesWithOneEvent()
    // return in case of 0 entry in full chain
    if (!fEntryCounter) {
       // runs UserExecMix for all tasks, if needed
-      if (el) UserExecMixAllTasks(fEntryCounter, idEntryList, currentMainEntry, -1, 0);
-      else UserExecMixAllTasks(fEntryCounter, -1, currentMainEntry, -1, 0);
+      if (el && fDoMixIfNotEnoughEvents) {
+         UserExecMixAllTasks(fEntryCounter, idEntryList, currentMainEntry, -1, 0);
+      } else {
+         idEntryList = -1;
+         UserExecMixAllTasks(fEntryCounter, idEntryList, currentMainEntry, -1, 0);
+      }
       AliDebug(AliLog::kDebug + 3, Form("++++++++++++++ END SETUP EVENT %lld SKIPPED (fEntryCounter=0, idEntryList=%d) +++++++++++++++++++", fEntryCounter, idEntryList));
       return kTRUE;
    }
@@ -396,14 +401,28 @@ Bool_t AliMixInputEventHandler::MixEventsMoreTimesWithOneEvent()
    } else {
       elNum = el->GetN();
       if (elNum < fBufferSize + 1) {
-         UserExecMixAllTasks(fEntryCounter, idEntryList, currentMainEntry, -1, 0);
+         if (fDoMixIfNotEnoughEvents) {
+            // include main event in to counter in this case (so idEntryList>0)
+            UserExecMixAllTasks(fEntryCounter, idEntryList, currentMainEntry, -1, 0);
+         }  else {
+            // dont include it in main event counter (idEntryList = -1)
+            idEntryList = -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;
       }
+      if (!fDoMixIfNotEnoughEvents) {
+         if (elNum <= fMixNumber + 1) {
+            UserExecMixAllTasks(fEntryCounter, idEntryList, currentMainEntry, -1, 0);
+            AliDebug(AliLog::kDebug + 3, Form("++++++++++++++ END SETUP EVENT %lld SKIPPED (%lld) NOT ENOUGH EVENTS TO MIX => NEED=%d +++++++++++++++++++", fEntryCounter, elNum, fMixNumber + 1));
+            return kTRUE;
+         }
+      }
    }
    // pre mix evetns
    Int_t mixNum = fMixNumber;
-   if (fUsePreMixEvents) {
+   if (fDoMixExtra) {
       if (elNum <= 2 * fMixNumber + 1) mixNum = elNum + 1;
    }
    AliMixInputHandlerInfo *mihi = 0;
@@ -421,9 +440,9 @@ Bool_t AliMixInputEventHandler::MixEventsMoreTimesWithOneEvent()
       entryMixReal = entryMix;
       TChainElement *te = fMixIntupHandlerInfoTmp->GetEntryInTree(entryMix);
       if (!te) {
-         AliError("te is null. this is error. tell to developer (#2)")
+       AliError("te is null. this is error. tell to developer (#2)");
       } else {
-         mihi->PrepareEntry(te, entryMix, InputEventHandler(0), fAnalysisType);
+         mihi->PrepareEntry(te, entryMix, (AliInputEventHandler*)InputEventHandler(0), fAnalysisType);
          // runs UserExecMix for all tasks
          fNumberMixed++;
          UserExecMixAllTasks(fEntryCounter, idEntryList, currentMainEntry, entryMixReal, fNumberMixed);
@@ -498,8 +517,8 @@ 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("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");