]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Added posibility to Call GetEntry for Mixed events. This is tmp fix for mixing events...
authormvala <mvala@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 2 Aug 2012 16:12:35 +0000 (16:12 +0000)
committermvala <mvala@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 2 Aug 2012 16:12:35 +0000 (16:12 +0000)
Example:

   // don't call GetEntry for mixed events automatically
   // user will have to do it by hand in UserExecMix()
   mixHandler->DoMixEventGetEntryAuto(kFALSE);

and in your task you do

UserExecMix() {

...

// AliMixInputEventHandler *fMixingInputHandler = ... ;
...
// Calling GetEntry for main event
if (!fMixingInputHandler->GetEntryMainEvent()) return;
// now TRef is correctly set for Main Event ONLY

Int_t nContributorsMain = aodEvent->GetVertex(0)->GetNContributors();
AliAODEvent *aodEventMixTmp=0;
Int_t nContributorsMix=0;
for(Int_t iBuffer=0; iBuffer<bufferSize; iBuffer++) {
   // calling GetEntry for mixed event with id=iBuffer
   if (!fMixingInputHandler->GetEntryMixedEvent(iBuffer)) return;
   // now TRef is correctly set for Mixed Event with id 'iBuffer' ONLY
   // other Mixed Events and Main Event has WRONG TRef

   aodEventMixTmp = dynamic_cast<AliAODEvent *>(GetMixedEvent(iBuffer));
   nContributorsMix = aodEventMixTmp->GetVertex(0)->GetNContributors();
   AliInfo(Form("[mixed=%d] main=%d [%d] -> mix=%d [%d]",fMixingInputHandler->NumberMixedTimes(),aodEvent->GetNumberOfTracks(),nContributorsMain,aodEventMixTmp->GetNumberOfTracks(),nContributorsMix));
}
...

}

ANALYSIS/EventMixing/AliMixInputEventHandler.cxx
ANALYSIS/EventMixing/AliMixInputEventHandler.h

index 0edcb44127998036f3b110f98eb9796d6a8f7519..d28b6784943ccc7aa914228e5586d6e7120da274 100644 (file)
@@ -9,7 +9,6 @@
 
 #include <TFile.h>
 #include <TChain.h>
-#include <TEntryList.h>
 #include <TChainElement.h>
 #include <TSystem.h>
 
@@ -37,11 +36,14 @@ AliMixInputEventHandler::AliMixInputEventHandler(const Int_t size, const Int_t m
    fUseDefautProcess(kFALSE),
    fDoMixExtra(kTRUE),
    fDoMixIfNotEnoughEvents(kTRUE),
+   fDoMixEventGetEntryAuto(kTRUE),
    fCurrentEntry(0),
    fCurrentEntryMain(0),
    fCurrentEntryMix(0),
    fCurrentBinIndex(-1),
-   fOfflineTriggerMask(0)
+   fOfflineTriggerMask(0),
+   fCurrentMixEntry(),
+   fCurrentEntryMainTree(0)
 {
    //
    // Default constructor.
@@ -90,9 +92,9 @@ Bool_t AliMixInputEventHandler::Init(TTree *tree, Option_t *opt)
       return kFALSE;
    }
 
-   if (!fDoMixIfNotEnoughEvents) {
+   if (!fDoMixIfNotEnoughEvents&&fDoMixExtra) {
       fDoMixExtra = kFALSE;
-      AliWarning("fDoMixIfNotEnoughEvents=kTRUE -> setting fDoMixExtra=kFALSE");
+      AliWarning("fDoMixIfNotEnoughEvents=kFALSE -> setting fDoMixExtra=kFALSE");
    }
 
    // clears array of input handlers
@@ -108,7 +110,6 @@ Bool_t AliMixInputEventHandler::Init(TTree *tree, Option_t *opt)
    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("->"));
@@ -152,7 +153,6 @@ 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, (AliInputEventHandler *)InputEventHandler(i), fAnalysisType);
       if (doPrepareEntry) mixIHI->PrepareEntry(che, -1, (AliInputEventHandler *)InputEventHandler(i), fAnalysisType);
       AliDebug(AliLog::kDebug + 5, Form("chain[%d]->GetEntries() = %lld", i, mixIHI->GetChain()->GetEntries()));
       fMixTrees.Add(mixIHI);
@@ -174,6 +174,8 @@ Bool_t AliMixInputEventHandler::BeginEvent(Long64_t entry)
    //
    // BeginEvent(Long64_t entry) is called for all mix input handlers
    //
+   fCurrentEntryMainTree = entry;
+
    AliDebug(AliLog::kDebug + 5, Form("-> %lld", entry));
    if (fUseDefautProcess) {
       AliDebug(AliLog::kDebug, Form("-> SKIPPED"));
@@ -256,7 +258,7 @@ Bool_t AliMixInputEventHandler::MixStd()
       if (!te) {
          AliError("te is null. this is error. tell to developer (#1)");
       } else {
-         mihi->PrepareEntry(te, entryMix, (AliInputEventHandler *)InputEventHandler(0), fAnalysisType);
+         if (fDoMixEventGetEntryAuto) mihi->PrepareEntry(te, entryMix, (AliInputEventHandler *)InputEventHandler(0), fAnalysisType);
          // runs UserExecMix for all tasks
          fNumberMixed++;
          UserExecMixAllTasks(fEntryCounter, 1, fEntryCounter, entryMixReal, fNumberMixed);
@@ -289,6 +291,8 @@ Bool_t AliMixInputEventHandler::MixBuffer()
    // check for PhysSelection
    if (!IsEventCurrentSelected()) return kFALSE;
 
+   fCurrentMixEntry.Reset();
+
    // find out zero chain entries
    Long64_t zeroChainEntries = fMixIntupHandlerInfoTmp->GetChain()->GetEntries() - inEvHMain->GetTree()->GetTree()->GetEntries();
    // fill entry
@@ -323,6 +327,7 @@ Bool_t AliMixInputEventHandler::MixBuffer()
          return kTRUE;
       }
    }
+
    AliMixInputHandlerInfo *mihi = 0;
    Long64_t entryMix = 0, entryMixReal = 0;
    Int_t counter = 0;
@@ -348,8 +353,9 @@ Bool_t AliMixInputEventHandler::MixBuffer()
       if (!te) {
          AliError("te is null. this is error. tell to developer (#1)");
       } else {
+         fCurrentMixEntry.Enter(entryMixReal);
          AliDebug(AliLog::kDebug + 3, Form("Preparing InputEventHandler(%d)", counter));
-         mihi->PrepareEntry(te, entryMix, (AliInputEventHandler *)InputEventHandler(counter), fAnalysisType);
+         if (fDoMixEventGetEntryAuto) mihi->PrepareEntry(te, entryMix, (AliInputEventHandler *)InputEventHandler(counter), fAnalysisType);
          fNumberMixed++;
       }
       counter++;
@@ -359,7 +365,7 @@ Bool_t AliMixInputEventHandler::MixBuffer()
       // runs UserExecMix for all tasks
       UserExecMixAllTasks(fEntryCounter, idEntryList, fEntryCounter, entryMixReal, 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("->"));
@@ -386,6 +392,8 @@ Bool_t AliMixInputEventHandler::MixEventsMoreTimesWithOneEvent()
    // check for PhysSelection
    if (!IsEventCurrentSelected()) return kFALSE;
 
+   fCurrentMixEntry.Reset();
+
    // find out zero chain entries
    Long64_t zeroChainEntries = fMixIntupHandlerInfoTmp->GetChain()->GetEntries() - inEvHMain->GetTree()->GetTree()->GetEntries();
    // fill entry
@@ -450,6 +458,7 @@ Bool_t AliMixInputEventHandler::MixEventsMoreTimesWithOneEvent()
    mihi = (AliMixInputHandlerInfo *) fMixTrees.At(0);
    // fills num for main events
    for (counter = 0; counter < mixNum; counter++) {
+      fCurrentMixEntry.Reset();
       Long64_t entryInEntryList =  elNum - 2 - counter;
       AliDebug(AliLog::kDebug + 3, Form("entryInEntryList=%lld", entryInEntryList));
       if (entryInEntryList < 0) break;
@@ -461,7 +470,8 @@ Bool_t AliMixInputEventHandler::MixEventsMoreTimesWithOneEvent()
       if (!te) {
          AliError("te is null. this is error. tell to developer (#2)");
       } else {
-         mihi->PrepareEntry(te, entryMix, (AliInputEventHandler *)InputEventHandler(0), fAnalysisType);
+         fCurrentMixEntry.Enter(entryMixReal);
+         if (fDoMixEventGetEntryAuto) mihi->PrepareEntry(te, entryMix, (AliInputEventHandler *)InputEventHandler(0), fAnalysisType);
          // runs UserExecMix for all tasks
          fNumberMixed++;
          UserExecMixAllTasks(fEntryCounter, idEntryList, currentMainEntry, entryMixReal, fNumberMixed);
@@ -561,7 +571,7 @@ Bool_t AliMixInputEventHandler::IsEventCurrentSelected()
    //
    // Check if event is selected by Physics selection
    //
-   
+
    AliDebug(AliLog::kDebug + 5, Form("<-"));
    Bool_t isSelected = kTRUE;
    if (fOfflineTriggerMask && fOfflineTriggerMask != AliVEvent::kAny) {
@@ -576,3 +586,42 @@ Bool_t AliMixInputEventHandler::IsEventCurrentSelected()
    AliDebug(AliLog::kDebug + 5, Form("-> %d", isSelected));
    return isSelected;
 }
+
+//_____________________________________________________________________________
+Bool_t AliMixInputEventHandler::GetEntryMainEvent() {
+   //
+   // Calling GetEntry for main event in input handler (Should be used in UserExecMix() only)
+   //
+
+   AliInputEventHandler *ih = ((AliMultiInputEventHandler *)ParentHandler())->GetFirstInputEventHandler();
+   ih->GetTree()->GetEntry(fCurrentEntryMainTree);
+   return kTRUE;
+}
+
+//_____________________________________________________________________________
+Bool_t AliMixInputEventHandler::GetEntryMixedEvent(Int_t id) {
+   //
+   // Calling GetEntry for mixed event in input handler with id
+   // (Should be used in UserExecMix() only)
+   //
+
+   AliMixInputHandlerInfo *mihi = (AliMixInputHandlerInfo *) fMixTrees.At(id);
+
+   Long64_t entryMix = fCurrentMixEntry.GetEntry(fCurrentMixEntry.GetN()-id-1);
+   if(entryMix<0) {
+      AliError(Form("GetEntryMixedEvent(%d) => entryMix<0 [1]",id));
+      return kFALSE;
+   }
+   TChainElement *te = fMixIntupHandlerInfoTmp->GetEntryInTree(entryMix);
+   if (!te) {
+      AliError("te is null. this is error. tell to developer (#3)");
+      return kFALSE;
+   }
+   if(entryMix<0) {
+      AliError(Form("GetEntryMixedEvent(%d) => entryMix<0 [2]",id));
+      return kFALSE;
+   }
+   mihi->PrepareEntry(te, entryMix, (AliInputEventHandler *)InputEventHandler(id), fAnalysisType);
+
+   return kTRUE;
+}
index 10c0b0c914bb441a3bab13d5cc03e88c0b8a0ff2..6eabd177ea1fe20aff32cb4a8508e9d6828827db 100644 (file)
@@ -11,6 +11,7 @@
 #define ALIMIXINPUTEVENTHANDLER_H
 
 #include <TObjArray.h>
+#include <TEntryList.h>
 #include <TArrayI.h>
 
 #include <AliVEvent.h>
@@ -18,6 +19,7 @@
 #include "AliMultiInputEventHandler.h"
 
 class TChain;
+class TChainElement;
 class AliMixEventPool;
 class AliMixInputHandlerInfo;
 class AliInputEventHandler;
@@ -67,6 +69,10 @@ public:
    Bool_t                  IsEventCurrentSelected();
    Bool_t                  IsMixingIfNotEnoughEvents() { return fDoMixIfNotEnoughEvents;}
 
+   void                    DoMixEventGetEntryAuto(Bool_t doAuto=kTRUE) { fDoMixEventGetEntryAuto = doAuto; }
+
+   Bool_t                  GetEntryMainEvent();
+   Bool_t                  GetEntryMixedEvent(Int_t idHandler=0);
 protected:
 
    TObjArray               fMixTrees;              // buffer of input handlers
@@ -81,16 +87,19 @@ private:
 
    Bool_t                  fUseDefautProcess;      // use default process
    Bool_t                  fDoMixExtra;            // mix extra events to get enough combinations
-   Bool_t                  fDoMixIfNotEnoughEvents;// mix events if they dont have enough events to mix
+   Bool_t                  fDoMixIfNotEnoughEvents;// mix events if they don't have enough events to mix
+   Bool_t                  fDoMixEventGetEntryAuto;// flag for preparing mixed events automatically (default on)
 
    // 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
-
    ULong64_t fOfflineTriggerMask;   //  Task processes collision candidates only
 
+   TEntryList fCurrentMixEntry;    //! array of mix entries currently used (user should touch)
+   Long64_t fCurrentEntryMainTree; //! current entry in current tree (main event)
+
    virtual Bool_t          MixStd();
    virtual Bool_t          MixBuffer();
    virtual Bool_t          MixEventsMoreTimesWithOneEvent();
@@ -101,7 +110,7 @@ private:
    AliMixInputEventHandler(const AliMixInputEventHandler &handler);
    AliMixInputEventHandler &operator=(const AliMixInputEventHandler &handler);
 
-   ClassDef(AliMixInputEventHandler, 4)
+   ClassDef(AliMixInputEventHandler, 5)
 };
 
 #endif