Line data Source code
1 : #ifndef AliEventPoolManager_h
2 : #define AliEventPoolManager_h
3 :
4 : #include <vector>
5 : #include <deque>
6 : #include <Rtypes.h>
7 : #include <TObjArray.h>
8 : #include "AliLog.h"
9 : #include <AliVParticle.h>
10 :
11 : // Generic event mixing classes
12 : //
13 : // Stores a buffer of tracks that updates continuously. The track type
14 : // contained by the pools can be anything inheriting from
15 : // TObject. Pools are updated based on maintaining a minimum fixed
16 : // number of tracks. Multiplicity/centrality and z-vertex bins must be
17 : // passed in at initialization. For example of implementation, see
18 : // $ALICE_ROOT/PWGCF/Correlations/DPhi/AliAnalysisTaskPhiCorrelations.cxx
19 : //
20 : // Authors: A. Adare and C. Loizides
21 :
22 : using std::deque;
23 :
24 0 : class AliEventPool : public TObject
25 : {
26 : public:
27 0 : AliEventPool()
28 0 : : fEvents(0),
29 0 : fNTracksInEvent(0),
30 0 : fEventIndex(0),
31 0 : fMixDepth(1000),
32 0 : fMultMin(-999),
33 0 : fMultMax(+999),
34 0 : fZvtxMin(-999),
35 0 : fZvtxMax(+999),
36 0 : fPsiMin(-999),
37 0 : fPsiMax(+999),
38 0 : fPtMin(-9999),
39 0 : fPtMax(+9999),
40 0 : fWasUpdated(0),
41 0 : fMultBinIndex(0),
42 0 : fZvtxBinIndex(0),
43 0 : fPsiBinIndex(0),
44 0 : fPtBinIndex(0),
45 0 : fDebug(0),
46 0 : fTargetTrackDepth(0),
47 0 : fFirstFilled(0),
48 0 : fLockFlag(0),
49 0 : fSaveFlag(0),
50 0 : fNTimes(0),
51 0 : fTargetFraction(1),
52 0 : fTargetEvents(0) {;} // default constructor needed for correct saving
53 :
54 0 : AliEventPool(Int_t d)
55 0 : : fEvents(0),
56 0 : fNTracksInEvent(0),
57 0 : fEventIndex(0),
58 0 : fMixDepth(d),
59 0 : fMultMin(-999),
60 0 : fMultMax(+999),
61 0 : fZvtxMin(-999),
62 0 : fZvtxMax(+999),
63 0 : fPsiMin(-999),
64 0 : fPsiMax(+999),
65 0 : fPtMin(-9999),
66 0 : fPtMax(+9999),
67 0 : fWasUpdated(0),
68 0 : fMultBinIndex(0),
69 0 : fZvtxBinIndex(0),
70 0 : fPsiBinIndex(0),
71 0 : fPtBinIndex(0),
72 0 : fDebug(0),
73 0 : fTargetTrackDepth(0),
74 0 : fFirstFilled(0),
75 0 : fLockFlag(0),
76 0 : fSaveFlag(0),
77 0 : fNTimes(0),
78 0 : fTargetFraction(1),
79 0 : fTargetEvents(0) {;}
80 :
81 :
82 0 : AliEventPool(Int_t d, Double_t multMin, Double_t multMax,
83 : Double_t zvtxMin, Double_t zvtxMax,
84 : Double_t psiMin=-999., Double_t psiMax=999.,
85 : Double_t ptMin=-9999., Double_t ptMax=9999.)
86 0 : : fEvents(0),
87 0 : fNTracksInEvent(0),
88 0 : fEventIndex(0),
89 0 : fMixDepth(d),
90 0 : fMultMin(multMin),
91 0 : fMultMax(multMax),
92 0 : fZvtxMin(zvtxMin),
93 0 : fZvtxMax(zvtxMax),
94 0 : fPsiMin(psiMin),
95 0 : fPsiMax(psiMax),
96 0 : fPtMin(ptMin),
97 0 : fPtMax(ptMax),
98 0 : fWasUpdated(0),
99 0 : fMultBinIndex(0),
100 0 : fZvtxBinIndex(0),
101 0 : fPsiBinIndex(0),
102 0 : fPtBinIndex(0),
103 0 : fDebug(0),
104 0 : fTargetTrackDepth(0),
105 0 : fFirstFilled(0),
106 0 : fLockFlag(0),
107 0 : fSaveFlag(0),
108 0 : fNTimes(0),
109 0 : fTargetFraction(1),
110 0 : fTargetEvents(0) {;}
111 :
112 0 : ~AliEventPool() {;}
113 :
114 : Bool_t EventMatchesBin(Int_t mult, Double_t zvtx, Double_t psi=0., Double_t pt=0.) const;
115 : Bool_t EventMatchesBin(Double_t mult, Double_t zvtx, Double_t psi=0., Double_t pt=0.) const;
116 0 : Bool_t IsReady() const { return IsReady(NTracksInPool(), GetCurrentNEvents()); }
117 0 : Bool_t IsFirstReady() const { return fFirstFilled; }
118 0 : Int_t GetNTimes() const { return fNTimes; }
119 0 : Int_t GetCurrentNEvents() const { return fEvents.size(); }
120 : Int_t GlobalEventIndex(Int_t j) const;
121 : TObject *GetRandomTrack() const;
122 : TObjArray *GetRandomEvent() const;
123 : TObjArray *GetEvent(Int_t i) const;
124 0 : Int_t MultBinIndex() const { return fMultBinIndex; }
125 : Int_t NTracksInEvent(Int_t iEvent) const;
126 0 : Int_t NTracksInCurrentEvent() const { return fNTracksInEvent.back(); }
127 : void PrintInfo() const;
128 0 : Int_t PsiBinIndex() const { return fPsiBinIndex; }
129 0 : Int_t PtBinIndex() const { return fPtBinIndex; }
130 : Int_t NTracksInPool() const;
131 0 : Bool_t WasUpdated() const { return fWasUpdated; }
132 0 : Int_t ZvtxBinIndex() const { return fZvtxBinIndex; }
133 0 : void SetDebug(Bool_t b) { fDebug = b; }
134 0 : void SetTargetTrackDepth(Int_t d, Float_t fraction = 1.0) { fTargetTrackDepth = d; fTargetFraction = fraction; }
135 0 : void SetTargetEvents(Int_t ev) { fTargetEvents = ev; }
136 : Int_t SetEventMultRange(Int_t multMin, Int_t multMax);
137 : Int_t SetEventMultRange(Double_t multMin, Double_t multMax);
138 : Int_t SetEventZvtxRange(Double_t zvtxMin, Double_t zvtxMax);
139 : Int_t SetEventPsiRange(Double_t psiMin, Double_t psiMax);
140 : Int_t SetEventPtRange(Double_t ptMin, Double_t ptMax);
141 0 : void SetMultBinIndex(Int_t iM) { fMultBinIndex = iM; }
142 0 : void SetZvtxBinIndex(Int_t iZ) { fZvtxBinIndex = iZ; }
143 0 : void SetPsiBinIndex(Int_t iP) { fPsiBinIndex = iP; }
144 0 : void SetPtBinIndex(Int_t iPt) { fPtBinIndex = iPt; }
145 0 : void SetLockFlag(Bool_t val) { fLockFlag = val; }
146 0 : Bool_t GetLockFlag() { return fLockFlag; }
147 0 : void SetSaveFlag(Bool_t val) { fSaveFlag = val; }
148 0 : Bool_t GetSaveFlag() { return fSaveFlag; }
149 0 : Double_t GetPtMin() { return fPtMin; }
150 0 : Double_t GetPtMax() { return fPtMax; }
151 0 : Double_t GetPsiMin() { return fPsiMin; }
152 0 : Double_t GetPsiMax() { return fPsiMax; }
153 0 : Double_t GetMultMin() { return fMultMin; }
154 0 : Double_t GetMultMax() { return fMultMax; }
155 0 : Double_t GetZvtxMin() { return fZvtxMin; }
156 0 : Double_t GetZvtxMax() { return fZvtxMax; }
157 :
158 : Int_t UpdatePool(TObjArray *trk);
159 : Long64_t Merge(TCollection* hlist);
160 : // deque<TObjArray*> GetEvents() { return fEvents; }
161 : void Clear();
162 :
163 : protected:
164 0 : Bool_t IsReady(Int_t tracks, Int_t events) const { return (tracks >= fTargetFraction * fTargetTrackDepth) || ((fTargetEvents > 0) && (events >= fTargetEvents)); }
165 :
166 : deque<TObjArray*> fEvents; //Holds TObjArrays of MyTracklets
167 : deque<int> fNTracksInEvent; //Tracks in event
168 : deque<int> fEventIndex; //Original event index
169 : Int_t fMixDepth; //Number of evts. to mix with
170 : Double_t fMultMin, fMultMax; //Track multiplicity bin range
171 : Double_t fZvtxMin, fZvtxMax; //Event z-vertex bin range
172 : Double_t fPsiMin, fPsiMax; //Event plane angle (Psi) bin range
173 : Double_t fPtMin, fPtMax; //Particle pt bin range
174 : Bool_t fWasUpdated; //Evt. succesfully passed selection?
175 : Int_t fMultBinIndex; //Multiplicity bin
176 : Int_t fZvtxBinIndex; //Zvertex bin
177 : Int_t fPsiBinIndex; //Event plane angle (Psi) bin
178 : Int_t fPtBinIndex; //Particle pt bin
179 : Int_t fDebug; //If 1 then debug on
180 : Int_t fTargetTrackDepth; //Number of tracks, once full
181 : Bool_t fFirstFilled; //Init to false
182 : Bool_t fLockFlag; //if locked, no update is allowed. Useful for external pools
183 : Bool_t fSaveFlag; //flag whether to save the pool to the output file or not
184 : Int_t fNTimes; //Number of times init. condition reached
185 : Float_t fTargetFraction; //fraction of fTargetTrackDepth at which pool is ready (default: 1.0)
186 : Int_t fTargetEvents; //if non-zero: number of filled events after which pool is ready regardless of fTargetTrackDepth (default: 0)
187 :
188 170 : ClassDef(AliEventPool,4) // Event pool class
189 : };
190 :
191 0 : class AliEventPoolManager : public TObject
192 : {
193 : public:
194 0 : AliEventPoolManager()
195 0 : : fDebug(0),
196 0 : fNMultBins(0),
197 0 : fNZvtxBins(0),
198 0 : fNPsiBins(0),
199 0 : fNPtBins(0),
200 0 : fMultBins(),
201 0 : fZvtxBins(),
202 0 : fPsiBins(),
203 0 : fPtBins(),
204 0 : fEvPool(0),
205 0 : fTargetTrackDepth(0) {}
206 : AliEventPoolManager(Int_t maxEvts, Int_t minNTracks,
207 : Int_t nMultBins, Double_t *multbins,
208 : Int_t nZvtxBins, Double_t *zvtxbins);
209 :
210 : AliEventPoolManager(Int_t maxEvts, Int_t minNTracks,
211 : Int_t nMultBins, Double_t *multbins,
212 : Int_t nZvtxBins, Double_t *zvtxbins,
213 : Int_t nPsiBins, Double_t *psibins);
214 :
215 : AliEventPoolManager(Int_t maxEvts, Int_t minNTracks,
216 : Int_t nMultBins, Double_t *multbins,
217 : Int_t nZvtxBins, Double_t *zvtxbins,
218 : Int_t nPsiBins, Double_t *psibins,
219 : Int_t nPtBins, Double_t *ptbins);
220 :
221 : AliEventPoolManager(Int_t maxEvts, Int_t minNTracks, const char* binning);
222 :
223 :
224 0 : ~AliEventPoolManager() {;}
225 : Long64_t Merge(TCollection* hlist);
226 :
227 : // First uses bin indices, second uses the variables themselves.
228 : AliEventPool *GetEventPool(Int_t iMult, Int_t iZvtx, Int_t iPsi=0, Int_t iPt=0) const;
229 : AliEventPool *GetEventPool(Int_t centVal, Double_t zvtxVal, Double_t psiVal=0., Int_t iPt=0) const;
230 : AliEventPool *GetEventPool(Double_t centVal, Double_t zvtxVal, Double_t psiVal=0., Int_t iPt=0) const;
231 :
232 : Int_t InitEventPools(Int_t depth,
233 : Int_t nMultBins, Double_t *multbin,
234 : Int_t nZvtxBins, Double_t *zvtxbin,
235 : Int_t nPsiBins, Double_t *psibin,
236 : Int_t nPtBins, Double_t *ptbin);
237 :
238 0 : void SetTargetTrackDepth(Int_t d) { fTargetTrackDepth = d;} // Same as for G.E.P. class
239 : Int_t UpdatePools(TObjArray *trk);
240 0 : void SetDebug(Bool_t b) { fDebug = b; }
241 : void SetTargetValues(Int_t trackDepth, Float_t fraction, Int_t events);
242 0 : Int_t GetNumberOfAllBins() {return fNPtBins*fNMultBins*fNZvtxBins*fNPsiBins;}
243 0 : Int_t GetNumberOfPtBins() {return fNPtBins;}
244 0 : Int_t GetNumberOfMultBins() {return fNMultBins;}
245 0 : Int_t GetNumberOfZVtxBins() {return fNZvtxBins;}
246 0 : Int_t GetNumberOfPsiBins() {return fNPsiBins;}
247 :
248 : void Validate();
249 : void ClearPools();
250 : void ClearPools(Double_t minCent, Double_t maxCent, Double_t minZvtx, Double_t maxZvtx, Double_t minPsi, Double_t maxPsi, Double_t minPt, Double_t maxPt);
251 : void SetSaveFlag(Double_t minCent, Double_t maxCent, Double_t minZvtx, Double_t maxZvtx, Double_t minPsi, Double_t maxPsi, Double_t minPt, Double_t maxPt);
252 :
253 : protected:
254 : Int_t fDebug; // If 1 then debug on
255 : Int_t fNMultBins; // number mult bins
256 : Int_t fNZvtxBins; // number vertex bins
257 : Int_t fNPsiBins; // number Event plane angle (Psi) bins
258 : Int_t fNPtBins; // number pt bins
259 :
260 : std::vector<Double_t> fMultBins; // mult bins
261 : std::vector<Double_t> fZvtxBins; // vertex bins
262 : std::vector<Double_t> fPsiBins; // Event plane angle (Psi) bins
263 : std::vector<Double_t> fPtBins; // pt bins
264 :
265 : std::vector<AliEventPool*> fEvPool; // pool in bins of [fNMultBin][fNZvtxBin][fNPsiBin][fNPtBins]
266 : Int_t fTargetTrackDepth; // Required track size, same for all pools.
267 :
268 0 : Int_t GetBinIndex(Int_t iMult, Int_t iZvtx, Int_t iPsi, Int_t iPt) const {return fNZvtxBins*fNPsiBins*fNPtBins*iMult + fNPsiBins*fNPtBins*iZvtx + fNPtBins*iPsi + iPt;}
269 : Double_t* GetBinning(const char* configuration, const char* tag, Int_t& nBins) const;
270 :
271 170 : ClassDef(AliEventPoolManager,3)
272 : };
273 :
274 :
275 : #endif
|