]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/EventMixing/AliMixInputEventHandler.cxx
AliMixInputHandlerInfo : BeginEvent function for each input handler after fChain...
[u/mrichter/AliRoot.git] / ANALYSIS / EventMixing / AliMixInputEventHandler.cxx
index c3d2abf33dce046fb141e31eb80d5e05a0f13101..34b4d9d709ace74492dd0099f58dfaa752a0508c 100644 (file)
@@ -38,7 +38,8 @@ AliMixInputEventHandler::AliMixInputEventHandler(const Int_t size, const Int_t m
    fCurrentEntry(0),
    fCurrentEntryMain(0),
    fCurrentEntryMix(0),
-   fCurrentBinIndex(-1)
+   fCurrentBinIndex(-1),
+   fOfflineTriggerMask(0)
 {
    //
    // Default constructor.
@@ -49,24 +50,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)
 {
@@ -104,22 +87,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 +128,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 +164,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 +178,7 @@ Bool_t AliMixInputEventHandler::GetEntry()
    } else {
       AliWarning("Not supported Mixing !!!");
    }
+
    AliDebug(AliLog::kDebug + 5, Form("->"));
    return kTRUE;
 }
@@ -223,10 +198,14 @@ 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"));
-      // runs UserExecMix for all tasks (kFALSE means that UserExecMix is not called)
+      // runs UserExecMix for all tasks, if needed
       UserExecMixAllTasks(fEntryCounter, 1, fEntryCounter, -1, 0);
       return kTRUE;
    }
@@ -252,7 +231,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 +260,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
@@ -298,8 +281,9 @@ Bool_t AliMixInputEventHandler::MixBuffer()
    // 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);
+      // runs UserExecMix for all tasks, if needed
+      if (el) UserExecMixAllTasks(fEntryCounter, idEntryList, currentMainEntry, -1, 0);
+      else UserExecMixAllTasks(fEntryCounter, -1, currentMainEntry, -1, 0);
       return kTRUE;
    }
    if (!el) {
@@ -309,6 +293,7 @@ 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));
          return kTRUE;
       }
@@ -318,7 +303,7 @@ Bool_t AliMixInputEventHandler::MixBuffer()
    Int_t counter = 0;
    AliInputEventHandler *eh = 0;
    TObjArrayIter next(&fInputHandlers);
-   while ((eh = (AliInputEventHandler *) next())) {
+   while ((eh = dynamic_cast<AliInputEventHandler *>(next()))) {
       if (fEventPool && fEventPool->GetListOfEventCuts()->GetEntries() > 0) {
          entryMix = -1;
          if (elNum >= fBufferSize) {
@@ -339,7 +324,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++;
@@ -368,6 +353,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
@@ -383,8 +372,9 @@ Bool_t AliMixInputEventHandler::MixEventsMoreTimesWithOneEvent()
    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);
+      // runs UserExecMix for all tasks, if needed
+      if (el) UserExecMixAllTasks(fEntryCounter, idEntryList, currentMainEntry, -1, 0);
+      else UserExecMixAllTasks(fEntryCounter, -1, currentMainEntry, -1, 0);
       AliDebug(AliLog::kDebug + 3, Form("++++++++++++++ END SETUP EVENT %lld SKIPPED (fEntryCounter=0, idEntryList=%d) +++++++++++++++++++", fEntryCounter, idEntryList));
       return kTRUE;
    }
@@ -424,7 +414,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);
@@ -483,17 +473,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));
-//          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("");
+         fCurrentEntry = entryCounter;
+         fCurrentEntryMain = entryMainReal;
+         fCurrentEntryMix = entryMixReal;
+         fCurrentBinIndex = idEntryList;
+         if (entryMixReal >= 0) mixTask->UserExecMix("");
       }
    }
 }
@@ -525,3 +509,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;
+}