]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGCF/Correlations/DPhi/FourierDecomposition/AliPool.h
lightweight event mixing classes (AliEvtPool and AliEvtPoolManager)
[u/mrichter/AliRoot.git] / PWGCF / Correlations / DPhi / FourierDecomposition / AliPool.h
1 #ifndef AliPool_h
2 #define AliPool_h
3
4 #include <vector>
5 #include <deque>
6 #include <Rtypes.h>
7 #include <Riostream.h>
8 #include <TObject.h>
9 #include <TFile.h>
10 #include <TMath.h>
11 #include <TSystem.h>
12
13 class AliMiniTrack;
14
15 // Low-memory event mixing classes:
16 // - AliEvtPoolManager: Maintain 2D vector (z,cent) of AliEvtPools.
17 // - AliEvtPool: collections of sub-events in z and mult/cent bins.
18 // - AliMiniTrack: super-lightweight track "struct" class.
19 //
20 // Stores a buffer of tracks that updates continuously. The track type
21 // contained by the pools can be anything (no inheritance from
22 // AliVParticle, or even TObject, required). To use a track type other
23 // than AliMiniTrack, just redefine the MiniEvent typedef (for example,
24 // using AliESDTracks, or TLorenzVectors).
25 // Pools are updated based on maintaining a minimum fixed
26 // number of tracks. Multiplicity/centrality and z-vertex bins must be
27 // passed in at initialization. For example of implementation, see
28 // $ALICE_ROOT/PWGCF/Correlations/DPhi/FourierDecomposition/AliDhcTask.cxx
29 //
30 // Authors: A. Adare and C. Loizides
31
32 typedef std::vector< AliMiniTrack > MiniEvent;
33
34 class AliMiniTrack
35 {
36  public:
37   AliMiniTrack() : fPt(0), fEta(0), fPhi(0), fSign(0) {};
38   AliMiniTrack(Double_t pt, Double_t eta, Double_t phi, Int_t sign) :
39    fPt(pt), fEta(eta), fPhi(phi), fSign(sign>=0?1:0) {};
40  
41   Float_t Eta()  const { return fEta; }
42   Float_t Phi()  const { return fPhi; }
43   Float_t Pt()   const { return fPt;  }
44   Int_t   Sign() const { if (fSign) return 1; return -1; }
45
46  protected: 
47   Float_t fPt;
48   Float_t fEta;
49   Float_t fPhi;
50   Bool_t  fSign;
51 };
52
53 class AliEvtPool : public TObject
54 {
55  public:
56  AliEvtPool(Int_t d) : 
57    fEvents(0),
58    fNTracksInEvent(0),
59    fEventIndex(0),
60    fMixDepth(d), 
61    fMultMin(-999), 
62    fMultMax(+999), 
63    fZvtxMin(-999), 
64    fZvtxMax(+999), 
65    fWasUpdated(0), 
66    fMultBinIndex(0), 
67     fZvtxBinIndex(0), 
68    fDebug(0), 
69    fTargetTrackDepth(0),
70    fFirstFilled(0),
71    fNTimes(0) {;}
72   
73  AliEvtPool(Int_t d, Double_t multMin, Double_t multMax, 
74             Double_t zvtxMin, Double_t zvtxMax) : 
75    fEvents(0),
76    fNTracksInEvent(0),
77    fEventIndex(0),
78    fMixDepth(d), 
79    fMultMin(multMin), 
80    fMultMax(multMax), 
81    fZvtxMin(zvtxMin),
82    fZvtxMax(zvtxMax),
83    fWasUpdated(0),
84     fMultBinIndex(0), 
85    fZvtxBinIndex(0),
86    fDebug(0),
87    fTargetTrackDepth(0),
88    fFirstFilled(0),
89    fNTimes(0) {;}
90   ~AliEvtPool();
91   
92   Bool_t      EventMatchesBin(Int_t mult,    Double_t zvtx) const;
93   Bool_t      EventMatchesBin(Double_t mult, Double_t zvtx) const;
94   Bool_t      IsReady()                    const { return NTracksInPool() >= fTargetTrackDepth; }
95   Bool_t      IsFirstReady()               const { return fFirstFilled;   }
96   Int_t       GetNTimes()                  const { return fNTimes;        }
97   Int_t       GetCurrentNEvents()          const { return fEvents.size(); }
98   Int_t       GlobalEventIndex(Int_t j)    const;
99   MiniEvent*  GetEvent(Int_t i)            const;
100   Int_t       MultBinIndex()               const { return fMultBinIndex; }
101   Int_t       NTracksInEvent(Int_t iEvent) const;
102   Int_t       NTracksInCurrentEvent()      const { if (fNTracksInEvent.empty()) return 0;  
103                                                    return fNTracksInEvent.back(); }
104   void        PrintInfo()                  const;
105   Int_t       NTracksInPool()              const;
106   Bool_t      WasUpdated()                 const { return fWasUpdated; }
107   Int_t       ZvtxBinIndex()               const { return fZvtxBinIndex; }
108   void        SetDebug(Bool_t b)                 { fDebug = b; }
109   void        SetTargetTrackDepth(Int_t d)       { fTargetTrackDepth = d; }
110   Int_t       SetEventMultRange(Int_t    multMin, Int_t multMax);
111   Int_t       SetEventMultRange(Double_t multMin, Double_t multMax);
112   Int_t       SetEventZvtxRange(Double_t zvtxMin, Double_t zvtxMax);
113   void        SetMultBinIndex(Int_t iM)          { fMultBinIndex = iM; }
114   void        SetZvtxBinIndex(Int_t iZ)          { fZvtxBinIndex = iZ; }
115   Int_t       UpdatePool(MiniEvent* miniEvt);
116   
117 protected:
118   deque< MiniEvent* >   fEvents;              //Pool of events storing Minitracks
119   deque<int>            fNTracksInEvent;      //Tracks in event
120   deque<int>            fEventIndex;          //Original event index
121   Int_t                 fMixDepth;            //Number of evts. to mix with
122   Double_t              fMultMin, fMultMax;   //Track multiplicity bin range
123   Double_t              fZvtxMin, fZvtxMax;   //Event z-vertex bin range
124   Bool_t                fWasUpdated;          //Evt. succesfully passed selection?
125   Int_t                 fMultBinIndex;        //Multiplicity bin
126   Int_t                 fZvtxBinIndex;        //Zvertex bin
127   Int_t                 fDebug;               //If 1 then debug on
128   Int_t                 fTargetTrackDepth;    //Number of tracks, once full
129   Bool_t                fFirstFilled;         //Init to false
130   Int_t                 fNTimes;              //Number of times init. condition reached
131
132   ClassDef(AliEvtPool,1) // Event pool class
133 };
134
135 class AliEvtPoolManager : public TObject
136 {
137 public:
138   AliEvtPoolManager() : 
139     fDebug(0),
140     fNMultBins(0), 
141     fNZvtxBins(0),
142     fEvPool(0),
143     fTargetTrackDepth(0) {;}
144   AliEvtPoolManager(Int_t maxEvts, Int_t minNTracks,
145                     Int_t nMultBins, Double_t *multbins,
146                     Int_t nZvtxBins, Double_t *zvtxbins);
147
148   ~AliEvtPoolManager();
149   
150   // First uses bin indices, second uses the variables themselves.
151   AliEvtPool *GetEventPool(Int_t iMult, Int_t iZvtx) const;
152   AliEvtPool *GetEventPool(Int_t    centVal, Double_t zvtxVal) const;
153   AliEvtPool *GetEventPool(Double_t centVal, Double_t zvtxVal) const;
154
155   Int_t       InitEventPools(Int_t depth, 
156                              Int_t nmultbins, Double_t *multbins, 
157                              Int_t nzvtxbins, Double_t *zvtxbins);
158   void        SetTargetTrackDepth(Int_t d) { fTargetTrackDepth = d;}
159   Int_t       UpdatePools(MiniEvent*);
160   void        SetDebug(Bool_t b) { fDebug = b; }
161
162 protected:
163   Int_t      fDebug;                         // If 1 then debug on
164   Int_t      fNMultBins;                     // number mult bins
165   Int_t      fNZvtxBins;                     // number vertex bins
166   vector< vector<AliEvtPool*> > fEvPool;     // pool in bins of [fMultBin][fZvtxBin]
167   Int_t      fTargetTrackDepth;              // Required track size, same for all pools.
168
169   ClassDef(AliEvtPoolManager,1)
170 };
171 #endif