Fix from Salvatore for new framework
[u/mrichter/AliRoot.git] / ANALYSIS / AliEventPoolManager.h
CommitLineData
2a910c25 1#ifndef AliEventPoolManager_h
2#define AliEventPoolManager_h
3
4#include <vector>
5#include <deque>
6#include <Rtypes.h>
7#include <Riostream.h>
8#include <TObjArray.h>
9#include <TFile.h>
10#include <TMath.h>
11#include <TRandom.h>
12#include <TSystem.h>
13
14// Generic event mixing classes
15//
16// Stores a buffer of tracks that updates continuously. The track type
17// contained by the pools can be anything inheriting from
18// TObject. Pools are updated based on maintaining a minimum fixed
19// number of tracks. Multiplicity/centrality and z-vertex bins must be
20// passed in at initialization. For example of implementation, see
15695e03 21// $ALICE_ROOT/PWGCF/Correlations/DPhi/AliAnalysisTaskPhiCorrelations.cxx
2a910c25 22//
23// Authors: A. Adare and C. Loizides
24
c82bb898 25using std::deque;
26
2a910c25 27class AliEventPool : public TObject
28{
29 public:
30 AliEventPool(Int_t d)
31 : fEvents(0),
32 fNTracksInEvent(0),
33 fEventIndex(0),
34 fMixDepth(d),
35 fMultMin(-999),
36 fMultMax(+999),
37 fZvtxMin(-999),
38 fZvtxMax(+999),
6df75196 39 fPsiMin(-999),
40 fPsiMax(+999),
2a910c25 41 fWasUpdated(0),
42 fMultBinIndex(0),
43 fZvtxBinIndex(0),
6df75196 44 fPsiBinIndex(0),
2a910c25 45 fDebug(0),
46 fTargetTrackDepth(0),
47 fFirstFilled(0),
f0df9076 48 fNTimes(0),
49 fTargetFraction(1),
50 fTargetEvents(0) {;}
2a910c25 51
6df75196 52
2a910c25 53 AliEventPool(Int_t d, Double_t multMin, Double_t multMax,
6df75196 54 Double_t zvtxMin, Double_t zvtxMax,
55 Double_t psiMin=-999., Double_t psiMax=999.)
2a910c25 56 : fEvents(0),
57 fNTracksInEvent(0),
58 fEventIndex(0),
59 fMixDepth(d),
60 fMultMin(multMin),
61 fMultMax(multMax),
62 fZvtxMin(zvtxMin),
63 fZvtxMax(zvtxMax),
6df75196 64 fPsiMin(psiMin),
65 fPsiMax(psiMax),
2a910c25 66 fWasUpdated(0),
67 fMultBinIndex(0),
68 fZvtxBinIndex(0),
6df75196 69 fPsiBinIndex(0),
2a910c25 70 fDebug(0),
71 fTargetTrackDepth(0),
72 fFirstFilled(0),
f0df9076 73 fNTimes(0),
74 fTargetFraction(1),
75 fTargetEvents(0) {;}
6df75196 76
2a910c25 77 ~AliEventPool() {;}
78
6df75196 79 Bool_t EventMatchesBin(Int_t mult, Double_t zvtx, Double_t psi=0.) const;
80 Bool_t EventMatchesBin(Double_t mult, Double_t zvtx, Double_t psi=0.) const;
f0df9076 81 Bool_t IsReady() const { return IsReady(NTracksInPool(), GetCurrentNEvents()); }
fa67180e 82 Bool_t IsFirstReady() const { return fFirstFilled; }
83 Int_t GetNTimes() const { return fNTimes; }
2a910c25 84 Int_t GetCurrentNEvents() const { return fEvents.size(); }
85 Int_t GlobalEventIndex(Int_t j) const;
86 TObject *GetRandomTrack() const;
87 TObjArray *GetRandomEvent() const;
88 TObjArray *GetEvent(Int_t i) const;
89 Int_t MultBinIndex() const { return fMultBinIndex; }
90 Int_t NTracksInEvent(Int_t iEvent) const;
91 Int_t NTracksInCurrentEvent() const { return fNTracksInEvent.back(); }
92 void PrintInfo() const;
6df75196 93 Int_t PsiBinIndex() const { return fPsiBinIndex; }
2a910c25 94 Int_t NTracksInPool() const;
95 Bool_t WasUpdated() const { return fWasUpdated; }
96 Int_t ZvtxBinIndex() const { return fZvtxBinIndex; }
97 void SetDebug(Bool_t b) { fDebug = b; }
f0df9076 98 void SetTargetTrackDepth(Int_t d, Float_t fraction = 1.0) { fTargetTrackDepth = d; fTargetFraction = fraction; }
99 void SetTargetEvents(Int_t ev) { fTargetEvents = ev; }
2a910c25 100 Int_t SetEventMultRange(Int_t multMin, Int_t multMax);
101 Int_t SetEventMultRange(Double_t multMin, Double_t multMax);
102 Int_t SetEventZvtxRange(Double_t zvtxMin, Double_t zvtxMax);
6df75196 103 Int_t SetEventPsiRange(Double_t psiMin, Double_t psiMax);
2a910c25 104 void SetMultBinIndex(Int_t iM) { fMultBinIndex = iM; }
105 void SetZvtxBinIndex(Int_t iZ) { fZvtxBinIndex = iZ; }
6df75196 106 void SetPsiBinIndex(Int_t iP) { fPsiBinIndex = iP; }
2a910c25 107 Int_t UpdatePool(TObjArray *trk);
108
109protected:
f0df9076 110 Bool_t IsReady(Int_t tracks, Int_t events) const { return (tracks >= fTargetFraction * fTargetTrackDepth) || ((fTargetEvents > 0) && (events >= fTargetEvents)); }
111
2a910c25 112 deque<TObjArray*> fEvents; //Holds TObjArrays of MyTracklets
113 deque<int> fNTracksInEvent; //Tracks in event
114 deque<int> fEventIndex; //Original event index
115 Int_t fMixDepth; //Number of evts. to mix with
116 Double_t fMultMin, fMultMax; //Track multiplicity bin range
117 Double_t fZvtxMin, fZvtxMax; //Event z-vertex bin range
6df75196 118 Double_t fPsiMin, fPsiMax; //Event plane angle (Psi) bin range
2a910c25 119 Bool_t fWasUpdated; //Evt. succesfully passed selection?
120 Int_t fMultBinIndex; //Multiplicity bin
121 Int_t fZvtxBinIndex; //Zvertex bin
6df75196 122 Int_t fPsiBinIndex; //Event plane angle (Psi) bin
2a910c25 123 Int_t fDebug; //If 1 then debug on
124 Int_t fTargetTrackDepth; //Number of tracks, once full
125 Bool_t fFirstFilled; //Init to false
126 Int_t fNTimes; //Number of times init. condition reached
f0df9076 127 Float_t fTargetFraction; //fraction of fTargetTrackDepth at which pool is ready (default: 1.0)
128 Int_t fTargetEvents; //if non-zero: number of filled events after which pool is ready regardless of fTargetTrackDepth (default: 0)
2a910c25 129
f0df9076 130 ClassDef(AliEventPool,3) // Event pool class
2a910c25 131};
132
133class AliEventPoolManager : public TObject
134{
135public:
136 AliEventPoolManager()
137 : fDebug(0),
138 fNMultBins(0),
139 fNZvtxBins(0),
6df75196 140 fNPsiBins(0),
2a910c25 141 fEvPool(0),
142 fTargetTrackDepth(0) {;}
143 AliEventPoolManager(Int_t maxEvts, Int_t minNTracks,
6df75196 144 Int_t nMultBins, Double_t *multbins,
145 Int_t nZvtxBins, Double_t *zvtxbins);
146
147 AliEventPoolManager(Int_t maxEvts, Int_t minNTracks,
148 Int_t nMultBins, Double_t *multbins,
149 Int_t nZvtxBins, Double_t *zvtxbins,
150 Int_t nPsiBins, Double_t *psibins);
151
2a910c25 152 ~AliEventPoolManager() {;}
153
154 // First uses bin indices, second uses the variables themselves.
6df75196 155 AliEventPool *GetEventPool(Int_t iMult, Int_t iZvtx, Int_t iPsi=0) const;
156 AliEventPool *GetEventPool(Int_t centVal, Double_t zvtxVal, Double_t psiVal=0.) const;
157 AliEventPool *GetEventPool(Double_t centVal, Double_t zvtxVal, Double_t psiVal=0.) const;
2a910c25 158
159 Int_t InitEventPools(Int_t depth,
160 Int_t nmultbins, Double_t *multbins,
6df75196 161 Int_t nzvtxbins, Double_t *zvtxbins,
162 Int_t npsibins, Double_t *psibins);
163
2a910c25 164 void SetTargetTrackDepth(Int_t d) { fTargetTrackDepth = d;} // Same as for G.E.P. class
165 Int_t UpdatePools(TObjArray *trk);
166 void SetDebug(Bool_t b) { fDebug = b; }
f0df9076 167 void SetTargetValues(Int_t trackDepth, Float_t fraction, Int_t events);
6df75196 168
169 protected:
2a910c25 170 Int_t fDebug; // If 1 then debug on
171 Int_t fNMultBins; // number mult bins
172 Int_t fNZvtxBins; // number vertex bins
6df75196 173 Int_t fNPsiBins; // number Event plane angle (Psi) bins
174 std::vector<AliEventPool*> fEvPool; // pool in bins of [fNMultBin][fNZvtxBin][fNPsiBin]
2a910c25 175 Int_t fTargetTrackDepth; // Required track size, same for all pools.
6df75196 176
177 ClassDef(AliEventPoolManager,2)
2a910c25 178};
179#endif