]>
Commit | Line | Data |
---|---|---|
3a72645a | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
27de2dfb | 15 | |
16 | /* $Id$ */ | |
17 | ||
3a72645a | 18 | // |
19 | // Class AliHFEvarManager: | |
20 | // Contains definition of the variables which are filled into the | |
21 | // Correction framework container. The class handles both AliCFContainer and | |
22 | // AliHFEcontainer. | |
23 | // Defining a new variable which has to be monitored can be done via the | |
24 | // function AddVariable. This function also defines a new dimension for the | |
25 | // particle container and appends it to the list of variables. For a new | |
26 | // track the function NewTrack caches the values to be filled into the | |
27 | // correction framework container. With FillContainer the specified | |
28 | // correction framework container is filled. The VarManager also handles | |
29 | // the filling of the correlation matrices | |
30 | // | |
31 | // Author: | |
32 | // Markus Fasel <M.Fasel@gsi.de> | |
33 | // | |
34 | #include <TClass.h> | |
35 | #include <TH3.h> | |
36 | #include <TF3.h> | |
37 | #include <TMath.h> | |
38 | #include <THnSparse.h> | |
39 | #include <TString.h> | |
40 | ||
41 | #include "AliCFContainer.h" | |
42 | #include "AliLog.h" | |
43 | #include "AliVParticle.h" | |
44 | ||
45 | #include "AliHFEcontainer.h" | |
46 | #include "AliHFEsignalCuts.h" | |
47 | #include "AliHFEvarManager.h" | |
48 | ||
49 | ClassImp(AliHFEvarManager) | |
50 | ClassImp(AliHFEvarManager::AliHFEvariable); | |
51 | ||
52 | //____________________________________________________________ | |
53 | AliHFEvarManager::AliHFEvarManager(): | |
54 | TNamed(), | |
55 | fVariables(NULL), | |
56 | fContent(NULL), | |
57 | fContentMC(NULL), | |
58 | fWeightFactor(1.), | |
59 | fSignalTrack(kTRUE), | |
60 | fWeighting(kFALSE), | |
61 | fSignal(NULL), | |
62 | fWeightFactors(NULL), | |
63 | fWeightFactorsFunction(NULL) | |
64 | { | |
65 | // | |
66 | // Dummy constructor | |
67 | // | |
68 | SetOwner(); | |
69 | } | |
70 | ||
71 | //____________________________________________________________ | |
72 | AliHFEvarManager::AliHFEvarManager(const Char_t *name): | |
73 | TNamed(name, ""), | |
74 | fVariables(NULL), | |
75 | fContent(NULL), | |
76 | fContentMC(NULL), | |
77 | fWeightFactor(1.), | |
78 | fSignalTrack(kTRUE), | |
79 | fWeighting(kFALSE), | |
80 | fSignal(NULL), | |
81 | fWeightFactors(NULL), | |
82 | fWeightFactorsFunction(NULL) | |
83 | { | |
84 | // | |
85 | // Default constructor | |
86 | // | |
87 | fVariables = new TObjArray; | |
88 | SetOwner(); | |
89 | } | |
90 | ||
91 | //____________________________________________________________ | |
92 | AliHFEvarManager::AliHFEvarManager(const AliHFEvarManager &ref): | |
93 | TNamed(ref), | |
94 | fVariables(NULL), | |
95 | fContent(NULL), | |
96 | fContentMC(NULL), | |
97 | fWeightFactor(ref.fWeightFactor), | |
98 | fSignalTrack(ref.fSignalTrack), | |
99 | fWeighting(ref.fWeighting), | |
100 | fSignal(NULL), | |
101 | fWeightFactors(NULL), | |
102 | fWeightFactorsFunction(NULL) | |
103 | { | |
104 | // | |
105 | // Copy Constructor | |
106 | // | |
107 | ref.Copy(*this); | |
108 | } | |
109 | ||
110 | //____________________________________________________________ | |
111 | AliHFEvarManager &AliHFEvarManager::operator=(const AliHFEvarManager &ref){ | |
112 | // | |
113 | // Assignment operator | |
114 | // | |
115 | if(&ref != this){ | |
116 | this->~AliHFEvarManager(); | |
117 | ref.Copy(*this); | |
118 | } | |
119 | return *this; | |
120 | } | |
121 | ||
122 | //____________________________________________________________ | |
123 | AliHFEvarManager::~AliHFEvarManager(){ | |
124 | // | |
125 | // Destructor | |
126 | // | |
127 | if(IsOwner()){ | |
128 | if(fVariables) delete fVariables; | |
129 | } | |
130 | if(fContent) delete[] fContent; | |
131 | if(fContentMC) delete[] fContentMC; | |
132 | } | |
133 | ||
134 | //____________________________________________________________ | |
135 | void AliHFEvarManager::Copy(TObject &o) const{ | |
136 | // | |
137 | // Make Copy | |
138 | // | |
139 | AliHFEvarManager &target = dynamic_cast<AliHFEvarManager &>(o); | |
140 | target.fVariables = fVariables; | |
141 | target.fContent = new Double_t[sizeof(fContent)/sizeof(Double_t)]; | |
142 | target.fContentMC = new Double_t[sizeof(fContentMC)/sizeof(Double_t)]; | |
143 | target.fWeightFactor = fWeightFactor; | |
144 | target.fSignalTrack = fSignalTrack; | |
145 | target.fWeighting = fWeighting; | |
146 | target.fSignal = fSignal; | |
147 | target.fWeightFactors = fWeightFactors; | |
148 | target.fWeightFactorsFunction = fWeightFactorsFunction; | |
149 | target.SetOwner(kFALSE); | |
150 | } | |
151 | ||
152 | //____________________________________________________________ | |
153 | void AliHFEvarManager::AddVariable(TString name){ | |
154 | // | |
155 | // Add new variable to the var manager | |
156 | // Value derived via GetValue() | |
157 | // | |
158 | AliDebug(1, Form("Var Name: %s", name.Data())); | |
159 | ||
160 | if(!name.CompareTo("pt")) | |
161 | fVariables->AddLast(new AliHFEvariable("pt", "pt", kPt, 44, 0.1, 20, kTRUE)); | |
162 | else if(!name.CompareTo("eta")) | |
163 | fVariables->AddLast(new AliHFEvariable("eta", "eta", kEta, 8, -0.8, 0.8)); | |
164 | else if(!name.CompareTo("phi")) | |
165 | fVariables->AddLast(new AliHFEvariable("phi", "phi", kPhi, 18, -0, 2*TMath::Pi())); | |
166 | else if(!name.CompareTo("charge")) | |
167 | fVariables->AddLast(new AliHFEvariable("charge", "charge", kCharge, 2, -1.1, 1.1)); | |
168 | else if(!name.CompareTo("source")) | |
169 | fVariables->AddLast(new AliHFEvariable("source", "source", kSource, 4, 0, 4)); | |
170 | else if(!name.CompareTo("centrality")) | |
6555e2ad | 171 | fVariables->AddLast(new AliHFEvariable("centrality", "centrality", kCentrality, 11, 0.0, 11.0)); |
3a72645a | 172 | else if(!name.CompareTo("species")) |
173 | fVariables->AddLast(new AliHFEvariable("species", "species", kSpecies, 6, -1, 5)); | |
174 | ||
175 | // More to come ... | |
176 | } | |
177 | ||
6555e2ad | 178 | //____________________________________________________________ |
179 | Bool_t AliHFEvarManager::IsVariableDefined(TString name){ | |
180 | // | |
181 | // Add new variable to the var manager | |
182 | // Value derived via GetValue() | |
183 | // | |
184 | AliDebug(1, Form("Var Name: %s", name.Data())); | |
185 | ||
186 | AliHFEvariable *u = (AliHFEvariable *) fVariables->FindObject((const char*)name); | |
187 | if(u) return kTRUE; | |
188 | else return kFALSE; | |
189 | ||
190 | // More to come ... | |
191 | } | |
192 | ||
3a72645a | 193 | //____________________________________________________________ |
194 | void AliHFEvarManager::DefineVariables(AliHFEcontainer *cont){ | |
195 | // | |
196 | // Define Variables | |
197 | // | |
198 | Int_t nVars = fVariables->GetEntriesFast(); | |
199 | cont->SetNumberOfVariables(nVars); | |
200 | TIter vars(fVariables); | |
201 | AliHFEvariable *var; | |
202 | Int_t counter = 0; | |
203 | while((var = dynamic_cast<AliHFEvariable *>(vars()))){ | |
204 | cont->SetVariableName(counter, var->GetName()); | |
205 | if(var->IsLogarithmic()) | |
206 | cont->MakeLogarithmicBinning(counter, var->GetNumberOfBins(), var->GetMinimum(), var->GetMaximum()); | |
207 | else | |
208 | cont->MakeLinearBinning(counter, var->GetNumberOfBins(), var->GetMinimum(), var->GetMaximum()); | |
209 | counter++; | |
210 | } | |
211 | fContent = new Double_t[nVars]; | |
212 | memset(fContent, 0, sizeof(Double_t) * nVars); | |
213 | fContentMC = new Double_t[nVars]; | |
214 | memset(fContentMC, 0, sizeof(Double_t) * nVars); | |
215 | } | |
216 | ||
217 | //____________________________________________________________ | |
218 | void AliHFEvarManager::NewTrack(AliVParticle *recTrack, AliVParticle *mcTrack, Float_t centrality, Int_t aprioriPID, Bool_t signal){ | |
219 | // | |
220 | // Cache information for new track pair | |
221 | // | |
222 | AliDebug(1, "Filling new Track"); | |
223 | fSignalTrack = signal; | |
224 | FillArray(recTrack, fContent, centrality, aprioriPID); | |
225 | if(mcTrack) FillArray(mcTrack, fContentMC, centrality, aprioriPID); | |
226 | if(fWeighting){ | |
227 | Int_t indexpt = -1, indexeta = -1, indexphi = -1, counter = 0; | |
228 | AliHFEvariable *var = NULL; | |
229 | TIter vars(fVariables); | |
230 | while((var = dynamic_cast<AliHFEvariable *>(vars()))){ | |
231 | switch(var->GetVarCode()){ | |
232 | case kPt: indexpt = counter; break; | |
233 | case kEta: indexeta = counter; break; | |
234 | case kPhi: indexphi = counter; break; | |
235 | }; | |
236 | if(indexpt >= 0 && indexeta >= 0 && indexphi >= 0) // all dimensions found | |
237 | break; | |
238 | counter++; | |
239 | } | |
240 | if(indexpt >= 0 && indexeta >= 0 && indexphi >= 0) | |
241 | fWeightFactor = FindWeight(fContent[indexpt], fContent[indexeta], fContent[indexphi]); | |
242 | } | |
243 | } | |
244 | ||
245 | //____________________________________________________________ | |
246 | Double_t AliHFEvarManager::GetValue(AliVParticle *track, UInt_t code, Float_t centrality, Int_t aprioriPID) const { | |
247 | // | |
248 | // Definition of the variables | |
249 | // | |
250 | if(!track) return 0.; | |
251 | Double_t value = 0.; | |
252 | switch(code){ | |
253 | case kPt: value = track->Pt(); break; | |
254 | case kEta: value = track->Eta(); break; | |
255 | case kPhi: value = track->Phi(); break; | |
256 | case kCharge:{ | |
257 | value = track->Charge(); | |
258 | if(TString(track->IsA()->GetName()).Contains("MC")) value /= 3; | |
259 | break; | |
260 | } | |
261 | case kSource:{ | |
262 | if(fSignal){ | |
263 | if(fSignal->IsCharmElectron(track)) value = 0; | |
264 | else if(fSignal->IsBeautyElectron(track)) value = 1; | |
265 | else if(fSignal->IsGammaElectron(track)) value = 2; | |
266 | else value = 3; | |
267 | } | |
268 | break; | |
269 | } | |
270 | case kSpecies: value = aprioriPID; break; | |
271 | case kCentrality: value = centrality; break; | |
272 | }; | |
273 | return value; | |
274 | } | |
275 | ||
276 | //____________________________________________________________ | |
277 | void AliHFEvarManager::FillArray(AliVParticle *track, Double_t* container, Float_t centrality, Int_t aprioriPID) const{ | |
278 | // | |
279 | // Fill array with variables | |
280 | // | |
281 | TIter vars(fVariables); | |
282 | AliHFEvariable *var = NULL; | |
283 | Int_t counter = 0; | |
284 | while((var = dynamic_cast<AliHFEvariable *>(vars()))) | |
285 | container[counter++] = GetValue(track , var->GetVarCode(), centrality, aprioriPID); | |
286 | } | |
287 | ||
288 | //____________________________________________________________ | |
289 | void AliHFEvarManager::FillContainer(AliCFContainer *cont, Int_t step, Bool_t useMC) const{ | |
290 | // | |
291 | // Fill CF container with defined content | |
292 | // | |
293 | ||
294 | // Do reweighting if necessary | |
295 | Double_t *content = fContent; | |
296 | if(useMC) content = fContentMC; | |
297 | cont->Fill(content, step, fWeightFactor); | |
298 | } | |
299 | ||
300 | //____________________________________________________________ | |
301 | void AliHFEvarManager::FillContainer(AliHFEcontainer *cont, const Char_t *contname, UInt_t step, Bool_t useMC, Double_t externalWeight) const { | |
302 | // | |
303 | // Fill CF container with defined content | |
304 | // | |
305 | ||
306 | // Do reweighting if necessary | |
307 | Double_t *content = fContent; | |
308 | if(useMC) content = fContentMC; | |
309 | cont->FillCFContainer(contname, step, content, fWeightFactor * externalWeight); | |
310 | } | |
311 | ||
312 | //____________________________________________________________ | |
313 | void AliHFEvarManager::FillContainerStepname(AliHFEcontainer *cont, const Char_t *contname, const Char_t *step, Bool_t useMC, Double_t externalWeight) const { | |
314 | // | |
315 | // Fill CF container with defined content | |
316 | // | |
317 | ||
318 | // Do reweighting if necessary | |
319 | Double_t *content = fContent; | |
320 | if(useMC) content = fContentMC; | |
321 | cont->FillCFContainerStepname(contname, step, content, fWeightFactor * externalWeight); | |
322 | } | |
323 | ||
324 | //____________________________________________________________ | |
325 | void AliHFEvarManager::FillCorrelationMatrix(THnSparseF *matrix) const { | |
326 | // | |
327 | // Fill Correlation Matrix | |
328 | // | |
329 | ||
330 | // Do reweighting if necessary | |
331 | Double_t content[10]; | |
332 | memcpy(content, fContent, sizeof(Double_t) * 5); | |
333 | memcpy(&content[5], fContentMC, sizeof(Double_t) * 5); | |
334 | matrix->Fill(content, fWeightFactor); | |
335 | } | |
336 | ||
337 | //_______________________________________________ | |
338 | void AliHFEvarManager::SetWeightFactors(TH3F *weightFactors){ | |
339 | // | |
340 | // Set the histos with the weights for the efficiency maps | |
341 | // | |
342 | fWeighting = kTRUE; | |
343 | fWeightFactors = weightFactors; | |
344 | } | |
345 | ||
346 | //_______________________________________________ | |
347 | void AliHFEvarManager::SetWeightFactorsFunction(TF3 *weightFactorsFunction){ | |
348 | // | |
349 | // Set the histos with the weights for the efficiency maps | |
350 | // | |
351 | fWeighting = kTRUE; | |
352 | fWeightFactorsFunction = weightFactorsFunction; | |
353 | } | |
354 | ||
355 | //_______________________________________________ | |
356 | Double_t AliHFEvarManager::FindWeight(Double_t pt, Double_t eta, Double_t phi) const { | |
357 | // | |
358 | // Find the weight corresponding to pt eta and phi in the TH3D | |
359 | // | |
360 | Double_t weight = 1.0; | |
361 | if(fWeightFactors) { | |
362 | ||
363 | TAxis *ptaxis = fWeightFactors->GetXaxis(); | |
364 | TAxis *etaaxis = fWeightFactors->GetYaxis(); | |
365 | TAxis *phiaxis = fWeightFactors->GetZaxis(); | |
366 | ||
367 | Int_t ptbin = ptaxis->FindBin(pt); | |
368 | Int_t etabin = etaaxis->FindBin(eta); | |
369 | Int_t phibin = phiaxis->FindBin(phi); | |
370 | ||
371 | ||
372 | weight = fWeightFactors->GetBinContent(ptbin,etabin,phibin); | |
373 | } | |
374 | else if(fWeightFactorsFunction) { | |
375 | ||
376 | weight = fWeightFactorsFunction->Eval(pt,eta,phi); | |
377 | ||
378 | } | |
379 | ||
380 | AliDebug(2, Form("pt %f, eta %f, phi %f, weight %f",pt,eta,phi,weight)); | |
381 | ||
382 | return weight; | |
383 | } | |
384 | ||
385 | //_______________________________________________ | |
386 | AliHFEvarManager::AliHFEvariable::AliHFEvariable(): | |
387 | TNamed() | |
388 | , fCode(0) | |
389 | , fNBins(0) | |
390 | , fMin(0) | |
391 | , fMax(0) | |
392 | , fIsLogarithmic(kFALSE) | |
393 | { | |
394 | // | |
395 | // Dummy constructor | |
396 | // | |
397 | } | |
398 | ||
399 | //_______________________________________________ | |
400 | AliHFEvarManager::AliHFEvariable::AliHFEvariable(const Char_t *name, const Char_t *title, UInt_t code, UInt_t nBins, Double_t min, Double_t max, Bool_t isLogarithmic): | |
401 | TNamed(name, title) | |
402 | , fCode(code) | |
403 | , fNBins(nBins) | |
404 | , fMin(min) | |
405 | , fMax(max) | |
406 | , fIsLogarithmic(isLogarithmic) | |
407 | { | |
408 | // | |
409 | // Default constructor | |
410 | // | |
411 | } | |
412 | ||
413 | //_______________________________________________ | |
414 | AliHFEvarManager::AliHFEvariable::AliHFEvariable(const AliHFEvarManager::AliHFEvariable &ref): | |
415 | TNamed(ref) | |
416 | , fCode(ref.fCode) | |
417 | , fNBins(ref.fNBins) | |
418 | , fMin(ref.fMin) | |
419 | , fMax(ref.fMax) | |
420 | , fIsLogarithmic(ref.fIsLogarithmic) | |
421 | { | |
422 | // | |
423 | // Copy constructor | |
424 | // | |
425 | } | |
426 | ||
427 | //_______________________________________________ | |
428 | AliHFEvarManager::AliHFEvariable& AliHFEvarManager::AliHFEvariable::operator=(const AliHFEvarManager::AliHFEvariable &ref){ | |
429 | // | |
430 | // Assignment operator | |
431 | // | |
432 | ||
433 | if(&ref != this){ | |
434 | TNamed::operator=(ref); | |
435 | fCode = ref.fCode; | |
436 | fNBins = ref.fNBins; | |
437 | fMax = ref.fMax; | |
438 | fMin = ref.fMin; | |
439 | fIsLogarithmic = ref.fIsLogarithmic; | |
440 | } | |
441 | return *this; | |
442 | } | |
443 |