CbmRoot
Loading...
Searching...
No Matches
PairAnalysisMixingHandler.cxx
Go to the documentation of this file.
1
2// //
3// //
4// Authors:
5// * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
6// Julian Book <Julian.Book@cern.ch>
7/*
8
9 Event mixing handler, that creates event pools of size fDepth. Events
10 are ring-buffered and mixing is done for events that are similar according
11 to the binnnings and variables specific via:
12
13 AddVariable(PairAnalysisVarManager::ValueTypes type, TVectorD* const bins)
14
15 You can specify which type of event mixing should be done (+-/-+,++,--) using:
16
17 SetMixType(EMixType type)
18
19*/
20// //
22
24
25#include <TAxis.h>
26#include <TH1.h>
27#include <TVectorD.h>
28
29#include "PairAnalysis.h"
31#include "PairAnalysisTrack.h"
32
34
36 : PairAnalysisMixingHandler("ME", "ME")
37{
38 //
39 // Default Constructor
40 //
41}
42
43//______________________________________________
44PairAnalysisMixingHandler::PairAnalysisMixingHandler(const char* name, const char* title)
45 : TNamed(name, title)
46 , fArrPools("TClonesArray")
47 , fAxes(fMaxCuts)
48{
49 //
50 // Named Constructor
51 //
52 for (Int_t i = 0; i < fMaxCuts; ++i) {
53 fEventCuts[i] = 0;
54 }
55 fAxes.SetOwner(kTRUE);
56}
57
58//______________________________________________
60{
61 //
62 // Default Destructor
63 //
64 fAxes.Delete();
65 if (fPID) delete fPID;
66}
67
68//________________________________________________________________
70{
71 //
72 // Add a variable to the mixing handler with arbitrary binning 'bins'
73 //
74
75 // limit number of variables to fMaxCuts
76 if (fAxes.GetEntriesFast() >= fMaxCuts) return;
77
78 Int_t size = fAxes.GetEntriesFast();
79 fEventCuts[size] = (UShort_t) type;
80 fAxes.Add(bins);
81}
82
83//______________________________________________
85{
86 //
87 // fill event buffers and perform mixing if the pool depth is reached
88 //
89
90 //check if there are tracks available
91 if (papa->GetTrackArray(0)->GetEntriesFast() == 0 && papa->GetTrackArray(1)->GetEntriesFast() == 0) return;
92
93 TString dim;
94 Int_t bin = FindBin(PairAnalysisVarManager::GetData(), &dim);
95
96 //add mixing bin to event data
98
99 if (bin < 0) {
100 Error("Fill", "Bin outside range: %s", dim.Data());
101 return;
102 }
103
104 // get mixing pool, create it if it does not yet exist.
105 TClonesArray* poolp = static_cast<TClonesArray*>(fArrPools.At(bin));
106 // do mixing
107 if (poolp) {
108 TClonesArray& pool = *poolp;
109 DoMixing(pool, papa);
110 }
111
112 Int_t index1 = 0;
113
114 if (!poolp) {
115 Info("Fill", "New pool at %d (%s)", bin, dim.Data());
116 poolp = new (fArrPools[bin]) TClonesArray("PairAnalysisMixedEvent", fDepth);
117 poolp->SetUniqueID(0);
118 }
119 else {
120 // one count further in the ring buffer
121 index1 = (poolp->GetUniqueID() + 1) % fDepth;
122 }
123
124 TClonesArray& pool = *poolp;
125
126 PairAnalysisMixedEvent* event = static_cast<PairAnalysisMixedEvent*>(pool.At(index1));
127 if (!event) {
128 // Info("Fill",Form("new event at %d: %d",bin,index1));
129 event = new (pool[index1]) PairAnalysisMixedEvent();
130 // Int_t size = TMath::Max(papa->GetTrackArray(0)->GetEntriesFast(),papa->GetTrackArray(1)->GetEntriesFast()));
131 event->Set();
132 event->SetProcessID(fPID);
133 }
134 else {
135 // Info("Fill",Form("use event at %d: %d",bin,index1));
136 }
137
138 // event->SetProcessID(fPID);
139 event->SetTracks(*papa->GetTrackArray(0), *papa->GetTrackArray(1));
140 event->SetEventData(PairAnalysisVarManager::GetData());
141
142 //set current event position in ring buffer
143 pool.SetUniqueID(index1);
144}
145
146//______________________________________________
148{
149 //
150 // perform the mixing
151 //
152
153 // we need at least one event for mixing
154 if (pool.GetEntriesFast() < 1) return;
155 // printf("entries: %d\n",pool.GetEntriesFast()); //buffer track arrays and copy them back afterwards
156
157 TObjArray arrTrDummy[4];
158 for (Int_t i = 0; i < 4; ++i)
159 arrTrDummy[i] = papa->fTracks[i];
160
161 //buffer also global event data
162 Double_t* values = PairAnalysisVarManager::GetData();
163
164 // The event data should alread be filled, since
165 // all events are in the same mixing bin anyhow...
166 TObject* o = 0x0;
167 TIter ev1P(&arrTrDummy[0]);
168 TIter ev1N(&arrTrDummy[1]);
169
170 // for (Int_t i2=i1+1; i2<pool.GetEntriesFast(); ++i2){
171 for (Int_t i1 = 0; i1 < pool.GetEntriesFast(); ++i1) {
172 const PairAnalysisMixedEvent* ev2 = static_cast<PairAnalysisMixedEvent*>(pool.At(i1));
173 // don't mix with itself
174 if (!ev2) continue;
175
176 //clear arryas
177 papa->fTracks[0].Clear();
178 papa->fTracks[1].Clear();
179 papa->fTracks[2].Clear();
180 papa->fTracks[3].Clear();
181
182 //setup track arrays
183 ev1P.Reset();
184 ev1N.Reset();
185 TIter ev2P(ev2->GetTrackArrayP());
186 TIter ev2N(ev2->GetTrackArrayN());
187
188 //mixing of ev1- ev2 (pair type4). This is common for all mixing types
189 while ((o = ev1N()))
190 papa->fTracks[1].Add(o);
191 while ((o = ev2P()))
192 papa->fTracks[2].Add(o);
193 papa->FillPairArrays(1, 2);
194
196 // all 4 pair arrays will be filled
197 while ((o = ev1P()))
198 papa->fTracks[0].Add(o);
199 while ((o = ev2N()))
200 papa->fTracks[3].Add(o);
201 papa->FillPairArrays(0, 2);
202 papa->FillPairArrays(1, 3);
203 if (fMixType == EMixType::kAll) papa->FillPairArrays(0, 3);
204 }
205
207 //use the pair type of ev1- ev1 also for ev1 ev1-
208 papa->fTracks[1].Clear();
209 papa->fTracks[2].Clear();
210 while ((o = ev1P()))
211 papa->fTracks[1].Add(o);
212 while ((o = ev2N()))
213 papa->fTracks[2].Add(o);
214 papa->FillPairArrays(1, 2);
215 }
216 }
217
218 //copy back the tracks
219 for (Int_t i = 0; i < 4; ++i) {
220 papa->fTracks[i].Clear();
221 papa->fTracks[i] = arrTrDummy[i];
222 }
223
224 //set back global event values
226}
227
228//______________________________________________
230{
231 //
232 // initialise event buffers
233 //
234 Int_t size = GetNumberOfBins();
235
236 Info("Init", "Creating a pool array with size %d", size);
237 if (papa && papa->DoEventProcess()) fArrPools.Expand(size);
238
239 TString values;
240 for (Int_t i = 0; i < fAxes.GetEntriesFast(); ++i) {
241 TVectorD* bins = static_cast<TVectorD*>(fAxes.At(i));
242 Int_t nRows = bins->GetNrows();
243 values += Form("%s: ", PairAnalysisVarManager::GetValueName(fEventCuts[i]));
244 for (Int_t irow = 0; irow < nRows; ++irow) {
245 values += Form("%.2f, ", (*bins)[irow]);
246 }
247 }
248
249 if (!fPID) { fPID = TProcessID::AddProcessID(); }
250
251 Info("Init", "%s", values.Data());
252}
253
254//______________________________________________
256{
257 //
258 // return the number of bins this mixing handler has
259 //
260 Int_t size = 1;
261 for (Int_t i = 0; i < fAxes.GetEntriesFast(); ++i)
262 size *= ((static_cast<TVectorD*>(fAxes.At(i)))->GetNrows() - 1);
263 return size;
264}
265
266//______________________________________________
267Int_t PairAnalysisMixingHandler::FindBin(const Double_t values[], TString* dim)
268{
269 //
270 // bin bin in mixing stack described by 'values'
271 // if the values are outside the binning range -1 is returned
272 // if dim is non NULL debug info will be stored in the variable
273 //
274
275 if (fAxes.GetEntriesFast() == 0) {
276 if (dim) (*dim) = "single bin";
277 return 0;
278 }
279 if (dim) (*dim) = "";
280 Int_t sizeAdd = 1;
281 Int_t bin = 0;
282 for (Int_t i = 0; i < fAxes.GetEntriesFast(); ++i) {
283 Double_t val = values[fEventCuts[i]];
284 TVectorD* bins = static_cast<TVectorD*>(fAxes.At(i));
285 Int_t nRows = bins->GetNrows();
286 if ((val < (*bins)[0]) || (val > (*bins)[nRows - 1])) { return -1; }
287
288 Int_t pos = TMath::BinarySearch(nRows, bins->GetMatrixArray(), val);
289 bin += sizeAdd * pos;
290 if (dim) (*dim) += Form("%s: %f (%d); ", PairAnalysisVarManager::GetValueName(fEventCuts[i]), val, pos);
291 sizeAdd *= (nRows - 1);
292 }
293
294 return bin;
295}
static constexpr size_t size()
Definition KfSimdPseudo.h:2
ClassImp(PairAnalysisMixingHandler) PairAnalysisMixingHandler
const TClonesArray * GetTrackArrayN() const
const TClonesArray * GetTrackArrayP() const
void SetTracks(const TObjArray &arrP, const TObjArray &arrN)
void AddVariable(PairAnalysisVarManager::ValueTypes type, TVectorD *const bins)
void Init(const PairAnalysis *papa=0x0)
void DoMixing(TClonesArray &pool, PairAnalysis *papa)
internal PID for references to buffered objects
Int_t FindBin(const Double_t values[], TString *dim=0x0)
void Fill(const PairAnalysisEvent *ev, PairAnalysis *papa)
static void SetEventData(const Double_t data[PairAnalysisVarManager::kNMaxValuesMC])
static const char * GetValueName(Int_t i)
static void SetValue(ValueTypes var, Double_t val)
Bool_t DoEventProcess() const
const TObjArray * GetTrackArray(Int_t i) const
TObjArray fTracks[4]
void FillPairArrays(Int_t arr1, Int_t arr2)