ROOT logo
#ifndef AliPool_h
#define AliPool_h

#include <vector>
#include <deque>
#include <Rtypes.h>
#include <Riostream.h>
#include <TObject.h>
#include <TFile.h>
#include <TMath.h>
#include <TSystem.h>

using std::vector;
using std::deque;


class AliMiniTrack;

// Low-memory event mixing classes:
// - AliEvtPoolManager: Maintain 2D vector (z,cent) of AliEvtPools.
// - AliEvtPool: collections of sub-events in z and mult/cent bins.
// - AliMiniTrack: super-lightweight track "struct" class.
//
// Stores a buffer of tracks that updates continuously. The track type
// contained by the pools can be anything (no inheritance from
// AliVParticle, or even TObject, required). To use a track type other
// than AliMiniTrack, just redefine the MiniEvent typedef (for example,
// using AliESDTracks, or TLorenzVectors).
// Pools are updated based on maintaining a minimum fixed
// number of tracks. Multiplicity/centrality and z-vertex bins must be
// passed in at initialization. For example of implementation, see
// $ALICE_ROOT/PWGCF/Correlations/DPhi/FourierDecomposition/AliDhcTask.cxx
//
// Authors: A. Adare and C. Loizides

typedef std::vector< AliMiniTrack > MiniEvent;

class AliMiniTrack
{
 public:
  AliMiniTrack() : fPt(0), fEta(0), fPhi(0), fSign(0) {};
  AliMiniTrack(Double_t pt, Double_t eta, Double_t phi, Int_t sign) :
   fPt(pt), fEta(eta), fPhi(phi), fSign(sign>=0?1:0) {};
 
  Float_t Eta()  const { return fEta; }
  Float_t Phi()  const { return fPhi; }
  Float_t Pt()   const { return fPt;  }
  Int_t   Sign() const { if (fSign) return 1; return -1; }

 protected: 
  Float_t fPt;
  Float_t fEta;
  Float_t fPhi;
  Bool_t  fSign;
};

class AliEvtPool : public TObject
{
 public:
 AliEvtPool(Int_t d) : 
   fEvents(0),
   fNTracksInEvent(0),
   fEventIndex(0),
   fMixDepth(d), 
   fMultMin(-999), 
   fMultMax(+999), 
   fZvtxMin(-999), 
   fZvtxMax(+999), 
   fWasUpdated(0), 
   fMultBinIndex(0), 
    fZvtxBinIndex(0), 
   fDebug(0), 
   fTargetTrackDepth(0),
   fFirstFilled(0),
   fNTimes(0) {;}
  
 AliEvtPool(Int_t d, Double_t multMin, Double_t multMax, 
	    Double_t zvtxMin, Double_t zvtxMax) : 
   fEvents(0),
   fNTracksInEvent(0),
   fEventIndex(0),
   fMixDepth(d), 
   fMultMin(multMin), 
   fMultMax(multMax), 
   fZvtxMin(zvtxMin),
   fZvtxMax(zvtxMax),
   fWasUpdated(0),
    fMultBinIndex(0), 
   fZvtxBinIndex(0),
   fDebug(0),
   fTargetTrackDepth(0),
   fFirstFilled(0),
   fNTimes(0) {;}
  ~AliEvtPool();
  
  Bool_t      EventMatchesBin(Int_t mult,    Double_t zvtx) const;
  Bool_t      EventMatchesBin(Double_t mult, Double_t zvtx) const;
  Bool_t      IsReady()                    const { return NTracksInPool() >= fTargetTrackDepth; }
  Bool_t      IsFirstReady()               const { return fFirstFilled;   }
  Int_t       GetNTimes()                  const { return fNTimes;        }
  Int_t       GetCurrentNEvents()          const { return fEvents.size(); }
  Int_t       GlobalEventIndex(Int_t j)    const;
  MiniEvent*  GetEvent(Int_t i)            const;
  Int_t       MultBinIndex()               const { return fMultBinIndex; }
  Int_t       NTracksInEvent(Int_t iEvent) const;
  Int_t       NTracksInCurrentEvent()      const { if (fNTracksInEvent.empty()) return 0;  
                                                   return fNTracksInEvent.back(); }
  void        PrintInfo()                  const;
  Int_t       NTracksInPool()              const;
  Bool_t      WasUpdated()                 const { return fWasUpdated; }
  Int_t       ZvtxBinIndex()               const { return fZvtxBinIndex; }
  void        SetDebug(Bool_t b)                 { fDebug = b; }
  void        SetTargetTrackDepth(Int_t d)       { fTargetTrackDepth = d; }
  Int_t       SetEventMultRange(Int_t    multMin, Int_t multMax);
  Int_t       SetEventMultRange(Double_t multMin, Double_t multMax);
  Int_t       SetEventZvtxRange(Double_t zvtxMin, Double_t zvtxMax);
  void        SetMultBinIndex(Int_t iM)          { fMultBinIndex = iM; }
  void        SetZvtxBinIndex(Int_t iZ)          { fZvtxBinIndex = iZ; }
  Int_t       UpdatePool(MiniEvent* miniEvt);
  
protected:
  deque< MiniEvent* >   fEvents;              //Pool of events storing Minitracks
  deque<int>            fNTracksInEvent;      //Tracks in event
  deque<int>            fEventIndex;          //Original event index
  Int_t                 fMixDepth;            //Number of evts. to mix with
  Double_t              fMultMin, fMultMax;   //Track multiplicity bin range
  Double_t              fZvtxMin, fZvtxMax;   //Event z-vertex bin range
  Bool_t                fWasUpdated;          //Evt. succesfully passed selection?
  Int_t                 fMultBinIndex;        //Multiplicity bin
  Int_t                 fZvtxBinIndex;        //Zvertex bin
  Int_t                 fDebug;               //If 1 then debug on
  Int_t                 fTargetTrackDepth;    //Number of tracks, once full
  Bool_t                fFirstFilled;         //Init to false
  Int_t                 fNTimes;              //Number of times init. condition reached

  ClassDef(AliEvtPool,1) // Event pool class
};

class AliEvtPoolManager : public TObject
{
public:
  AliEvtPoolManager() : 
    fDebug(0),
    fNMultBins(0), 
    fNZvtxBins(0),
    fEvPool(0),
    fTargetTrackDepth(0) {;}
  AliEvtPoolManager(Int_t maxEvts, Int_t minNTracks,
		    Int_t nMultBins, Double_t *multbins,
		    Int_t nZvtxBins, Double_t *zvtxbins);

  ~AliEvtPoolManager();
  
  // First uses bin indices, second uses the variables themselves.
  AliEvtPool *GetEventPool(Int_t iMult, Int_t iZvtx) const;
  AliEvtPool *GetEventPool(Int_t    centVal, Double_t zvtxVal) const;
  AliEvtPool *GetEventPool(Double_t centVal, Double_t zvtxVal) const;

  Int_t       InitEventPools(Int_t depth, 
			     Int_t nmultbins, Double_t *multbins, 
			     Int_t nzvtxbins, Double_t *zvtxbins);
  void        SetTargetTrackDepth(Int_t d) { fTargetTrackDepth = d;}
  Int_t       UpdatePools(MiniEvent*);
  void        SetDebug(Bool_t b) { fDebug = b; }

protected:
  Int_t      fDebug;                         // If 1 then debug on
  Int_t      fNMultBins;                     // number mult bins
  Int_t      fNZvtxBins;                     // number vertex bins
  vector< vector<AliEvtPool*> > fEvPool;     // pool in bins of [fMultBin][fZvtxBin]
  Int_t      fTargetTrackDepth;              // Required track size, same for all pools.

  ClassDef(AliEvtPoolManager,1)
};
#endif
 AliPool.h:1
 AliPool.h:2
 AliPool.h:3
 AliPool.h:4
 AliPool.h:5
 AliPool.h:6
 AliPool.h:7
 AliPool.h:8
 AliPool.h:9
 AliPool.h:10
 AliPool.h:11
 AliPool.h:12
 AliPool.h:13
 AliPool.h:14
 AliPool.h:15
 AliPool.h:16
 AliPool.h:17
 AliPool.h:18
 AliPool.h:19
 AliPool.h:20
 AliPool.h:21
 AliPool.h:22
 AliPool.h:23
 AliPool.h:24
 AliPool.h:25
 AliPool.h:26
 AliPool.h:27
 AliPool.h:28
 AliPool.h:29
 AliPool.h:30
 AliPool.h:31
 AliPool.h:32
 AliPool.h:33
 AliPool.h:34
 AliPool.h:35
 AliPool.h:36
 AliPool.h:37
 AliPool.h:38
 AliPool.h:39
 AliPool.h:40
 AliPool.h:41
 AliPool.h:42
 AliPool.h:43
 AliPool.h:44
 AliPool.h:45
 AliPool.h:46
 AliPool.h:47
 AliPool.h:48
 AliPool.h:49
 AliPool.h:50
 AliPool.h:51
 AliPool.h:52
 AliPool.h:53
 AliPool.h:54
 AliPool.h:55
 AliPool.h:56
 AliPool.h:57
 AliPool.h:58
 AliPool.h:59
 AliPool.h:60
 AliPool.h:61
 AliPool.h:62
 AliPool.h:63
 AliPool.h:64
 AliPool.h:65
 AliPool.h:66
 AliPool.h:67
 AliPool.h:68
 AliPool.h:69
 AliPool.h:70
 AliPool.h:71
 AliPool.h:72
 AliPool.h:73
 AliPool.h:74
 AliPool.h:75
 AliPool.h:76
 AliPool.h:77
 AliPool.h:78
 AliPool.h:79
 AliPool.h:80
 AliPool.h:81
 AliPool.h:82
 AliPool.h:83
 AliPool.h:84
 AliPool.h:85
 AliPool.h:86
 AliPool.h:87
 AliPool.h:88
 AliPool.h:89
 AliPool.h:90
 AliPool.h:91
 AliPool.h:92
 AliPool.h:93
 AliPool.h:94
 AliPool.h:95
 AliPool.h:96
 AliPool.h:97
 AliPool.h:98
 AliPool.h:99
 AliPool.h:100
 AliPool.h:101
 AliPool.h:102
 AliPool.h:103
 AliPool.h:104
 AliPool.h:105
 AliPool.h:106
 AliPool.h:107
 AliPool.h:108
 AliPool.h:109
 AliPool.h:110
 AliPool.h:111
 AliPool.h:112
 AliPool.h:113
 AliPool.h:114
 AliPool.h:115
 AliPool.h:116
 AliPool.h:117
 AliPool.h:118
 AliPool.h:119
 AliPool.h:120
 AliPool.h:121
 AliPool.h:122
 AliPool.h:123
 AliPool.h:124
 AliPool.h:125
 AliPool.h:126
 AliPool.h:127
 AliPool.h:128
 AliPool.h:129
 AliPool.h:130
 AliPool.h:131
 AliPool.h:132
 AliPool.h:133
 AliPool.h:134
 AliPool.h:135
 AliPool.h:136
 AliPool.h:137
 AliPool.h:138
 AliPool.h:139
 AliPool.h:140
 AliPool.h:141
 AliPool.h:142
 AliPool.h:143
 AliPool.h:144
 AliPool.h:145
 AliPool.h:146
 AliPool.h:147
 AliPool.h:148
 AliPool.h:149
 AliPool.h:150
 AliPool.h:151
 AliPool.h:152
 AliPool.h:153
 AliPool.h:154
 AliPool.h:155
 AliPool.h:156
 AliPool.h:157
 AliPool.h:158
 AliPool.h:159
 AliPool.h:160
 AliPool.h:161
 AliPool.h:162
 AliPool.h:163
 AliPool.h:164
 AliPool.h:165
 AliPool.h:166
 AliPool.h:167
 AliPool.h:168
 AliPool.h:169
 AliPool.h:170
 AliPool.h:171
 AliPool.h:172
 AliPool.h:173
 AliPool.h:174
 AliPool.h:175