]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Helper class for event mixing based on VEvent
authormorsch <morsch@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 18 Mar 2009 17:17:16 +0000 (17:17 +0000)
committermorsch <morsch@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 18 Mar 2009 17:17:16 +0000 (17:17 +0000)
ANALYSIS/ANALYSISaliceLinkDef.h
ANALYSIS/AliMultiEventInputHandler.cxx [new file with mode: 0644]
ANALYSIS/AliMultiEventInputHandler.h [new file with mode: 0644]
ANALYSIS/libANALYSISalice.pkg

index ce258d67487afc678d84cf445096d3aa797e5f7c..f4af578c1ee34dbe6a7c3b3193c1f0515904ac6c 100644 (file)
@@ -19,6 +19,7 @@
 
 #pragma link C++ class AliEventPoolSparse+;
 
+#pragma link C++ class AliMultiEventInputHandler+;
 
 #ifdef WITHXML
 #pragma link C++ class AliTagAnalysis+;
diff --git a/ANALYSIS/AliMultiEventInputHandler.cxx b/ANALYSIS/AliMultiEventInputHandler.cxx
new file mode 100644 (file)
index 0000000..d3ba80a
--- /dev/null
@@ -0,0 +1,158 @@
+/**************************************************************************
+ * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/* $Id$ */
+
+//-------------------------------------------------------------------------
+//     Event handler for multiple VEvent input.
+//     This class handles multiple inputs for event mixing. 
+//     Author: Andreas Morsch, CERN
+//-------------------------------------------------------------------------
+
+#include "AliMultiEventInputHandler.h"
+#include "AliVEvent.h"
+#include "AliAODEvent.h"
+#include "AliESDEvent.h"
+#include "AliVEventPool.h"
+#include "AliLog.h"
+#include <TObjArray.h>
+#include <TTree.h>
+
+
+ClassImp(AliMultiEventInputHandler)
+
+AliMultiEventInputHandler::AliMultiEventInputHandler() :
+    AliInputEventHandler(),
+    fBufferSize(0),
+    fFormat(1),
+    fNBuffered(0),
+    fIndex(0),
+    fCurrentBin(0),
+    fTree(0),
+    fEventPool(0),
+    fEventBuffer(0)
+{
+  // Default constructor
+}
+
+//______________________________________________________________________________
+AliMultiEventInputHandler::AliMultiEventInputHandler(Int_t size, Int_t format) :
+    AliInputEventHandler(),
+    fBufferSize(size),
+    fFormat(format),
+    fNBuffered(0),
+    fIndex(0),
+    fCurrentBin(0),
+    fTree(0),
+    fEventPool(0),
+    fEventBuffer(new AliVEvent*[size])
+{
+  // Default constructor
+    for (Int_t i = 0; i < size; i++) 
+       if (fFormat == 1) {
+           fEventBuffer[i] = new AliAODEvent();
+       } else if (fFormat == 0) {
+           fEventBuffer[i] = new AliESDEvent();
+       } else{
+           AliWarning(Form("Unknown Format %5d", fFormat));
+       }
+}
+
+//______________________________________________________________________________
+AliMultiEventInputHandler::AliMultiEventInputHandler(const char* name, const char* title, Int_t size, Int_t format):
+    AliInputEventHandler(name, title),
+    fBufferSize(size),
+    fFormat(format),
+    fNBuffered(0),
+    fIndex(0),
+    fCurrentBin(0),
+    fTree(0),
+    fEventPool(0),
+    fEventBuffer(new AliVEvent*[size])
+{
+    // Constructor
+    for (Int_t i = 0; i < size; i++) 
+       if (fFormat == 1) {
+           fEventBuffer[i] = new AliAODEvent();
+       } else if (fFormat == 0) {
+           fEventBuffer[i] = new AliESDEvent();
+       } else{
+           AliWarning(Form("Unknown Format %5d", fFormat));
+       }
+}
+
+//______________________________________________________________________________
+AliMultiEventInputHandler::~AliMultiEventInputHandler() 
+{
+// Destructor
+}
+
+Bool_t AliMultiEventInputHandler::Init(TTree* tree, Option_t* /*opt*/)
+{
+    // Initialisation necessary for each new tree
+    fTree = tree;
+    if (!fTree) return kFALSE;
+    // Get pointer to AOD event
+    fEventBuffer[0]->ReadFromTree(fTree, "");
+    fIndex     = 0;
+    fNBuffered = 1;
+    return kTRUE;
+}
+
+Bool_t AliMultiEventInputHandler::BeginEvent(Long64_t /*entry*/)
+{
+    // Actions before analysis of each event 
+    //
+    // Reset the number of events buffered for this bin to 0
+    if (fCurrentBin != (fEventPool->BinNumber())) {
+       fCurrentBin = fEventPool->BinNumber();
+       fNBuffered = 0;
+    }
+    return kTRUE;
+}
+
+Bool_t AliMultiEventInputHandler::FinishEvent()
+{
+    // 
+    // Connect the next event in the buffer to the tree
+    fIndex++;
+    
+    fIndex %= fBufferSize;
+    AliInfo(Form("Connecting buffer entry %5d", fIndex));
+
+    fEventBuffer[fIndex]->ReadFromTree(fTree, "reconnect");
+
+    fNBuffered++;
+    if (fNBuffered > fBufferSize) fNBuffered = fBufferSize;
+
+    return (kTRUE);
+}
+
+
+AliVEvent* AliMultiEventInputHandler::GetEvent(Int_t iev) const
+{
+    // Get event number iev from buffer
+    if ((iev < 0) || (iev >= fBufferSize))
+    {
+       AliWarning(Form("Event number out of range: %10d", iev));
+       return 0;
+    }
+       
+    iev = fIndex - (fBufferSize - 1 - iev);
+    if (iev < 0) iev += fBufferSize;
+    AliInfo(Form("Event index in buffer is %5d", iev));
+    return (fEventBuffer[iev]);
+}
+
diff --git a/ANALYSIS/AliMultiEventInputHandler.h b/ANALYSIS/AliMultiEventInputHandler.h
new file mode 100644 (file)
index 0000000..39fe2e5
--- /dev/null
@@ -0,0 +1,56 @@
+#ifndef ALIMULTIEVENTINPUTHANDLER_H
+#define ALIMULTIEVENTINPUTHANDLER_H
+/* Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+//----------------------------------------------------------------------------
+//     Multi VEvent Input Handler realisation of the AliVEventHandler interface.
+//     This class handles multiple events for mixing.
+//     Author: Andreas Morsch, CERN
+//----------------------------------------------------------------------------
+
+#include "AliInputEventHandler.h"
+class AliVEventPool;
+class AliVEvent;
+
+class AliMultiEventInputHandler : public AliInputEventHandler {
+
+ public:
+    AliMultiEventInputHandler();
+    AliMultiEventInputHandler(Int_t size, Int_t format = 1);
+    AliMultiEventInputHandler(const char* name, const char* title, Int_t size, Int_t format = 1);
+    virtual ~AliMultiEventInputHandler();
+    void   SetBufferSize(Int_t size) {fBufferSize = size;}
+    void   SetEventPool(AliVEventPool* pool) {fEventPool = pool;}
+    Int_t  GetBufferSize()           const {return fBufferSize;}
+    Int_t  GetNBuffered()            const {return fNBuffered;}
+    Bool_t IsBufferReady()           const {return (fNBuffered >= (fBufferSize -1));}
+    Bool_t IsFreshBuffer()           const {return (fIndex == (fBufferSize - 1));}
+    AliVEventPool           *GetEventPool()      const {return fEventPool;}
+    virtual AliVEvent       *GetEvent()          const {return 0;}
+    virtual AliVEvent       *GetEvent(Int_t iev) const;
+    AliVEvent               *GetLatestEvent()    const {return fEventBuffer[fIndex];}
+    // From the interface
+    virtual Bool_t Init(Option_t* /*opt*/)    {return kTRUE;}
+    virtual Bool_t Init(TTree* tree, Option_t* /*opt*/);
+    virtual Bool_t FinishEvent();
+    virtual Bool_t BeginEvent(Long64_t /*entry*/);
+    
+ private:
+    AliMultiEventInputHandler(const AliMultiEventInputHandler& handler);             
+    AliMultiEventInputHandler& operator=(const AliMultiEventInputHandler& handler);  
+ private:
+    Int_t          fBufferSize;   // Size of the buffer
+    Int_t          fFormat;       // 0: ESD 1: AOD
+    Int_t          fNBuffered;    // Number of events actually buffered
+    Int_t          fIndex;        // Pointer to most recent event
+    Int_t          fCurrentBin;   // Current bin from the pool
+    TTree*         fTree;         // Pointer to the tree
+    AliVEventPool* fEventPool;    // Pointer to the pool
+    AliVEvent**    fEventBuffer;  // The event buffer
+    ClassDef(AliMultiEventInputHandler, 1);
+};
+
+#endif
index fced27210be7148cff49fed6a87ea7f704008ccd..58ae2717c2833289c4896fb02e77924988c0e4dd 100644 (file)
@@ -4,7 +4,8 @@ SRCS =  AliAnalysisTaskSE.cxx AliAnalysisTaskME.cxx \
        AliAnalysisTaskESDfilter.cxx AliAnalysisTaskKineFilter.cxx AliAnalysisTaskMCParticleFilter.cxx \
        AliKineTrackCuts.cxx AliESDtrackCuts.cxx AliESDv0Cuts.cxx \
        AliEventPoolOTF.cxx AliEventPoolLoop.cxx AliEventPoolSparse.cxx \
-       AliAnalysisTaskTagCreator.cxx
+       AliAnalysisTaskTagCreator.cxx \
+        AliMultiEventInputHandler.cxx
 
 CHECKALIEN = $(shell root-config --has-alien)
 ifeq (yes,$(CHECKALIEN))