]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/EventMixing/AliMixInputEventHandler.cxx
Added Centrality cut to event mixing.
[u/mrichter/AliRoot.git] / ANALYSIS / EventMixing / AliMixInputEventHandler.cxx
index 596c3e8561a498c221ed2c7275ba9f7e85cdf7e4..e8c39d1840acb28152df46af146869c3fcf2de93 100644 (file)
@@ -34,11 +34,13 @@ 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),
-   fCurrentBinIndex(-1)
+   fCurrentBinIndex(-1),
+   fOfflineTriggerMask(0)
 {
    //
    // Default constructor.
@@ -49,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)
 {
@@ -80,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("->"));
 }
 
@@ -96,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
@@ -104,22 +95,14 @@ Bool_t AliMixInputEventHandler::Init(TTree *tree, Option_t *opt)
       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();
+
+   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;
 }
@@ -153,7 +136,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);
+      mixIHI->PrepareEntry(che, -1, (AliInputEventHandler*)InputEventHandler(i), fAnalysisType);
       AliDebug(AliLog::kDebug + 5, Form("chain[%d]->GetEntries() = %lld", i, mixIHI->GetChain()->GetEntries()));
       fMixTrees.Add(mixIHI);
    }
@@ -189,8 +172,7 @@ 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();
    }
@@ -204,6 +186,7 @@ Bool_t AliMixInputEventHandler::GetEntry()
    } else {
       AliWarning("Not supported Mixing !!!");
    }
+
    AliDebug(AliLog::kDebug + 5, Form("->"));
    return kTRUE;
 }
@@ -223,6 +206,10 @@ Bool_t AliMixInputEventHandler::MixStd()
    if (mh) inEvHMain = dynamic_cast<AliInputEventHandler *>(mh->GetFirstInputEventHandler());
    else inEvHMain = dynamic_cast<AliInputEventHandler *>(mgr->GetInputEventHandler());
    if (!inEvHMain) return kFALSE;
+
+   // check for PhysSelection
+   if (!IsEventCurrentSelected()) return kFALSE;
+
    // return in case of 0 entry in full chain
    if (!fEntryCounter) {
       AliDebug(AliLog::kDebug + 3, Form("-> fEntryCounter == 0"));
@@ -232,7 +219,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
@@ -252,7 +239,7 @@ Bool_t AliMixInputEventHandler::MixStd()
       if (!te) {
          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);
@@ -281,6 +268,10 @@ Bool_t AliMixInputEventHandler::MixBuffer()
    if (mh) inEvHMain = dynamic_cast<AliInputEventHandler *>(mh->GetFirstInputEventHandler());
    else inEvHMain = dynamic_cast<AliInputEventHandler *>(mgr->GetInputEventHandler());
    if (!inEvHMain) return kFALSE;
+
+   // check for PhysSelection
+   if (!IsEventCurrentSelected()) return kFALSE;
+
    // find out zero chain entries
    Long64_t zeroChainEntries = fMixIntupHandlerInfoTmp->GetChain()->GetEntries() - inEvHMain->GetTree()->GetTree()->GetEntries();
    // fill entry
@@ -299,8 +290,8 @@ Bool_t AliMixInputEventHandler::MixBuffer()
    if (!fEntryCounter) {
       AliDebug(AliLog::kDebug + 3, Form("-> fEntryCounter == 0"));
       // runs UserExecMix for all tasks, if needed
-                       if (el) UserExecMixAllTasks(fEntryCounter, idEntryList, currentMainEntry, -1, 0);
-                       else UserExecMixAllTasks(fEntryCounter, -1, currentMainEntry, -1, 0);
+      if (el) UserExecMixAllTasks(fEntryCounter, idEntryList, currentMainEntry, -1, 0);
+      else UserExecMixAllTasks(fEntryCounter, -1, currentMainEntry, -1, 0);
       return kTRUE;
    }
    if (!el) {
@@ -310,8 +301,8 @@ Bool_t AliMixInputEventHandler::MixBuffer()
    } else {
       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));
+         UserExecMixAllTasks(fEntryCounter, idEntryList, currentMainEntry, -1, 0);
+         AliDebug(AliLog::kDebug + 3, Form("++++++++++++++ END SETUP EVENT %lld SKIPPED (%lld) LESS THEN BUFFER +++++++++++++++++++", fEntryCounter, elNum));
          return kTRUE;
       }
    }
@@ -320,7 +311,7 @@ Bool_t AliMixInputEventHandler::MixBuffer()
    Int_t counter = 0;
    AliInputEventHandler *eh = 0;
    TObjArrayIter next(&fInputHandlers);
-   while ((eh = dynamic_cast<AliInputEventHandler *> (next()))) {
+   while ((eh = dynamic_cast<AliInputEventHandler *>(next()))) {
       if (fEventPool && fEventPool->GetListOfEventCuts()->GetEntries() > 0) {
          entryMix = -1;
          if (elNum >= fBufferSize) {
@@ -341,7 +332,7 @@ Bool_t AliMixInputEventHandler::MixBuffer()
          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++;
@@ -370,6 +361,10 @@ Bool_t AliMixInputEventHandler::MixEventsMoreTimesWithOneEvent()
    if (mh) inEvHMain = dynamic_cast<AliInputEventHandler *>(mh->GetFirstInputEventHandler());
    else inEvHMain = dynamic_cast<AliInputEventHandler *>(mgr->GetInputEventHandler());
    if (!inEvHMain) return kFALSE;
+
+   // check for PhysSelection
+   if (!IsEventCurrentSelected()) return kFALSE;
+
    // find out zero chain entries
    Long64_t zeroChainEntries = fMixIntupHandlerInfoTmp->GetChain()->GetEntries() - inEvHMain->GetTree()->GetTree()->GetEntries();
    // fill entry
@@ -386,8 +381,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;
    }
@@ -400,14 +399,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;
@@ -427,7 +440,7 @@ Bool_t AliMixInputEventHandler::MixEventsMoreTimesWithOneEvent()
       if (!te) {
          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);
@@ -486,12 +499,11 @@ void AliMixInputEventHandler::UserExecMixAllTasks(Long64_t entryCounter, Int_t i
    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));
-         fCurrentEntry = idEntryList;
-         fCurrentEntryMain = entryCounter;
-         fCurrentEntryMix = entryMainReal;
-         fCurrentBinIndex = entryMixReal;
-
-         if (entryMixReal > -1) mixTask->UserExecMix("");
+         fCurrentEntry = entryCounter;
+         fCurrentEntryMain = entryMainReal;
+         fCurrentEntryMix = entryMixReal;
+         fCurrentBinIndex = idEntryList;
+         if (entryMixReal >= 0) mixTask->UserExecMix("");
       }
    }
 }
@@ -523,3 +535,19 @@ void AliMixInputEventHandler::SetMixNumber(const Int_t mixNum)
    }
    fMixNumber = mixNum;
 }
+
+Bool_t AliMixInputEventHandler::IsEventCurrentSelected()
+{
+   AliDebug(AliLog::kDebug + 5, Form("<-"));
+   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+   AliMultiInputEventHandler *mh = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
+   Bool_t isSelected = kTRUE;
+   if (mh) {
+      if (fOfflineTriggerMask && mh->GetEventSelection()) {
+         isSelected = fOfflineTriggerMask & mh->IsEventSelected();
+      }
+   }
+   AliDebug(AliLog::kDebug + 1, Form("isSelected=%d", isSelected));
+   AliDebug(AliLog::kDebug + 5, Form("-> %d", isSelected));
+   return isSelected;
+}