]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGHF/hfe/AliHFEvarManager.cxx
Updates for TRD HFE analysis
[u/mrichter/AliRoot.git] / PWGHF / hfe / AliHFEvarManager.cxx
CommitLineData
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**************************************************************************/
15//
16// Class AliHFEvarManager:
17// Contains definition of the variables which are filled into the
18// Correction framework container. The class handles both AliCFContainer and
19// AliHFEcontainer.
20// Defining a new variable which has to be monitored can be done via the
21// function AddVariable. This function also defines a new dimension for the
22// particle container and appends it to the list of variables. For a new
23// track the function NewTrack caches the values to be filled into the
24// correction framework container. With FillContainer the specified
25// correction framework container is filled. The VarManager also handles
26// the filling of the correlation matrices
27//
28// Author:
29// Markus Fasel <M.Fasel@gsi.de>
30//
31#include <TClass.h>
32#include <TH3.h>
33#include <TF3.h>
34#include <TMath.h>
35#include <THnSparse.h>
36#include <TString.h>
37
38#include "AliCFContainer.h"
39#include "AliLog.h"
40#include "AliVParticle.h"
41
42#include "AliHFEcontainer.h"
43#include "AliHFEsignalCuts.h"
11ff28c5 44#include "AliHFEtools.h"
3a72645a 45#include "AliHFEvarManager.h"
46
47ClassImp(AliHFEvarManager)
48ClassImp(AliHFEvarManager::AliHFEvariable);
49
50//____________________________________________________________
51AliHFEvarManager::AliHFEvarManager():
52 TNamed(),
53 fVariables(NULL),
54 fContent(NULL),
55 fContentMC(NULL),
56 fWeightFactor(1.),
57 fSignalTrack(kTRUE),
9f3d831b 58 fWeighting(kFALSE),
3a72645a 59 fSignal(NULL),
9f3d831b 60 fWeightFactors(NULL),
61 fWeightFactorsFunction(NULL)
3a72645a 62{
63 //
64 // Dummy constructor
65 //
66 SetOwner();
67}
68
69//____________________________________________________________
70AliHFEvarManager::AliHFEvarManager(const Char_t *name):
71 TNamed(name, ""),
72 fVariables(NULL),
73 fContent(NULL),
74 fContentMC(NULL),
75 fWeightFactor(1.),
76 fSignalTrack(kTRUE),
9f3d831b 77 fWeighting(kFALSE),
3a72645a 78 fSignal(NULL),
9f3d831b 79 fWeightFactors(NULL),
80 fWeightFactorsFunction(NULL)
3a72645a 81{
82 //
83 // Default constructor
84 //
85 fVariables = new TObjArray;
86 SetOwner();
87}
88
89//____________________________________________________________
90AliHFEvarManager::AliHFEvarManager(const AliHFEvarManager &ref):
91 TNamed(ref),
92 fVariables(NULL),
93 fContent(NULL),
94 fContentMC(NULL),
95 fWeightFactor(ref.fWeightFactor),
96 fSignalTrack(ref.fSignalTrack),
9f3d831b 97 fWeighting(ref.fWeighting),
3a72645a 98 fSignal(NULL),
9f3d831b 99 fWeightFactors(NULL),
100 fWeightFactorsFunction(NULL)
3a72645a 101{
102 //
103 // Copy Constructor
104 //
105 ref.Copy(*this);
106}
107
108//____________________________________________________________
109AliHFEvarManager &AliHFEvarManager::operator=(const AliHFEvarManager &ref){
110 //
111 // Assignment operator
112 //
113 if(&ref != this){
114 this->~AliHFEvarManager();
115 ref.Copy(*this);
116 }
117 return *this;
118}
119
120//____________________________________________________________
121AliHFEvarManager::~AliHFEvarManager(){
122 //
123 // Destructor
124 //
125 if(IsOwner()){
126 if(fVariables) delete fVariables;
127 }
128 if(fContent) delete[] fContent;
129 if(fContentMC) delete[] fContentMC;
130}
131
132//____________________________________________________________
133void AliHFEvarManager::Copy(TObject &o) const{
134 //
135 // Make Copy
136 //
137 AliHFEvarManager &target = dynamic_cast<AliHFEvarManager &>(o);
138 target.fVariables = fVariables;
139 target.fContent = new Double_t[sizeof(fContent)/sizeof(Double_t)];
140 target.fContentMC = new Double_t[sizeof(fContentMC)/sizeof(Double_t)];
141 target.fWeightFactor = fWeightFactor;
142 target.fSignalTrack = fSignalTrack;
143 target.fWeighting = fWeighting;
144 target.fSignal = fSignal;
145 target.fWeightFactors = fWeightFactors;
146 target.fWeightFactorsFunction = fWeightFactorsFunction;
147 target.SetOwner(kFALSE);
148}
149
150//____________________________________________________________
151void AliHFEvarManager::AddVariable(TString name){
152 //
153 // Add new variable to the var manager
8c1c76e9 154 // Use default binning
3a72645a 155 // Value derived via GetValue()
156 //
157 AliDebug(1, Form("Var Name: %s", name.Data()));
158
159 if(!name.CompareTo("pt"))
160 fVariables->AddLast(new AliHFEvariable("pt", "pt", kPt, 44, 0.1, 20, kTRUE));
161 else if(!name.CompareTo("eta"))
8c1c76e9 162 fVariables->AddLast(new AliHFEvariable("eta", "eta", kEta, 8, -0.8, 0.8));
3a72645a 163 else if(!name.CompareTo("phi"))
8c1c76e9 164 fVariables->AddLast(new AliHFEvariable("phi", "phi", kPhi, 18, -0, 2*TMath::Pi()));
3a72645a 165 else if(!name.CompareTo("charge"))
166 fVariables->AddLast(new AliHFEvariable("charge", "charge", kCharge, 2, -1.1, 1.1));
167 else if(!name.CompareTo("source"))
11ff28c5 168 fVariables->AddLast(new AliHFEvariable("source", "source", kSource, 8, 0, 8));
3a72645a 169 else if(!name.CompareTo("centrality"))
6555e2ad 170 fVariables->AddLast(new AliHFEvariable("centrality", "centrality", kCentrality, 11, 0.0, 11.0));
3a72645a 171 else if(!name.CompareTo("species"))
172 fVariables->AddLast(new AliHFEvariable("species", "species", kSpecies, 6, -1, 5));
173
174 // More to come ...
175}
176
8c1c76e9 177//____________________________________________________________
178void AliHFEvarManager::AddVariable(TString name, Int_t nBins, Double_t min, Double_t max, Bool_t isLogarithmic){
179 //
180 // Add new variable to the var manager
181 // User can define minimum and maximum
182 // Function can be used to copy variables to a new var manager
183 // Value derived via GetValue()
184 //
185 AliDebug(1, Form("Var Name: %s", name.Data()));
186
187 UInt_t varcode = 1000;
188 if(!name.CompareTo("pt")){
189 varcode = kPt;
190 } else if(!name.CompareTo("eta")){
191 varcode = kEta;
192 } else if(!name.CompareTo("phi")){
193 varcode = kPhi;
194 } else if(!name.CompareTo("charge")){
195 varcode = kCharge;
196 } else if(!name.CompareTo("source")){
197 varcode = kSource;
198 } else if(!name.CompareTo("species")){
199 varcode = kSpecies;
200 } else if(!name.CompareTo("centrality")) {
201 varcode = kCentrality;
202 } else {
203 AliError("Variable not defined or not supposed to have a user-defined binning.");
204 }
205
206 if(varcode < 1000) fVariables->AddLast(new AliHFEvariable(name.Data(), name.Data(), varcode, nBins, min, max, isLogarithmic));
207 // More to come ...
208}
209
210//____________________________________________________________
211void AliHFEvarManager::AddVariable(TString name, Int_t nBins, const Double_t *binning){
212 //
213 // Add new variable to the var manager
214 // Not to be applied for Variables which have a limited amount of possible values like charge, species, source
215 // Value derived via GetValue()
216 //
217 AliDebug(1, Form("Var Name: %s", name.Data()));
218
219 UInt_t varcode = 1000;
220 if(!name.CompareTo("pt")){
221 varcode = kPt;
222 } else if(!name.CompareTo("eta")){
223 varcode = kEta;
224 } else if(!name.CompareTo("phi")){
225 varcode = kPhi;
226 } else if(!name.CompareTo("centrality")) {
227 varcode = kCentrality;
228 } else {
229 AliError("Variable not defined or not supposed to have a user-defined binning.");
230 }
231
232 if(varcode < 1000) fVariables->AddLast(new AliHFEvariable(name.Data(), name.Data(), varcode, nBins, binning));
233 // More to come ...
234}
235
6555e2ad 236//____________________________________________________________
237Bool_t AliHFEvarManager::IsVariableDefined(TString name){
238 //
239 // Add new variable to the var manager
240 // Value derived via GetValue()
241 //
242 AliDebug(1, Form("Var Name: %s", name.Data()));
243
244 AliHFEvariable *u = (AliHFEvariable *) fVariables->FindObject((const char*)name);
245 if(u) return kTRUE;
246 else return kFALSE;
247
248 // More to come ...
249}
250
3a72645a 251//____________________________________________________________
252void AliHFEvarManager::DefineVariables(AliHFEcontainer *cont){
253 //
254 // Define Variables
255 //
256 Int_t nVars = fVariables->GetEntriesFast();
257 cont->SetNumberOfVariables(nVars);
258 TIter vars(fVariables);
259 AliHFEvariable *var;
260 Int_t counter = 0;
261 while((var = dynamic_cast<AliHFEvariable *>(vars()))){
262 cont->SetVariableName(counter, var->GetName());
263 if(var->IsLogarithmic())
264 cont->MakeLogarithmicBinning(counter, var->GetNumberOfBins(), var->GetMinimum(), var->GetMaximum());
8c1c76e9 265 else if(var->HasUserDefinedBinning())
266 cont->MakeUserDefinedBinning(counter, var->GetNumberOfBins(), var->GetBinning());
3a72645a 267 else
268 cont->MakeLinearBinning(counter, var->GetNumberOfBins(), var->GetMinimum(), var->GetMaximum());
269 counter++;
270 }
271 fContent = new Double_t[nVars];
272 memset(fContent, 0, sizeof(Double_t) * nVars);
273 fContentMC = new Double_t[nVars];
274 memset(fContentMC, 0, sizeof(Double_t) * nVars);
275}
276
277//____________________________________________________________
278void AliHFEvarManager::NewTrack(AliVParticle *recTrack, AliVParticle *mcTrack, Float_t centrality, Int_t aprioriPID, Bool_t signal){
279 //
280 // Cache information for new track pair
281 //
282 AliDebug(1, "Filling new Track");
283 fSignalTrack = signal;
284 FillArray(recTrack, fContent, centrality, aprioriPID);
285 if(mcTrack) FillArray(mcTrack, fContentMC, centrality, aprioriPID);
286 if(fWeighting){
287 Int_t indexpt = -1, indexeta = -1, indexphi = -1, counter = 0;
288 AliHFEvariable *var = NULL;
289 TIter vars(fVariables);
290 while((var = dynamic_cast<AliHFEvariable *>(vars()))){
291 switch(var->GetVarCode()){
292 case kPt: indexpt = counter; break;
293 case kEta: indexeta = counter; break;
294 case kPhi: indexphi = counter; break;
295 };
296 if(indexpt >= 0 && indexeta >= 0 && indexphi >= 0) // all dimensions found
297 break;
298 counter++;
299 }
300 if(indexpt >= 0 && indexeta >= 0 && indexphi >= 0)
301 fWeightFactor = FindWeight(fContent[indexpt], fContent[indexeta], fContent[indexphi]);
302 }
303}
304
305//____________________________________________________________
306Double_t AliHFEvarManager::GetValue(AliVParticle *track, UInt_t code, Float_t centrality, Int_t aprioriPID) const {
307 //
308 // Definition of the variables
309 //
310 if(!track) return 0.;
311 Double_t value = 0.;
312 switch(code){
313 case kPt: value = track->Pt(); break;
314 case kEta: value = track->Eta(); break;
315 case kPhi: value = track->Phi(); break;
316 case kCharge:{
317 value = track->Charge();
318 if(TString(track->IsA()->GetName()).Contains("MC")) value /= 3;
319 break;
320 }
321 case kSource:{
322 if(fSignal){
11ff28c5 323 if(fSignal->IsCharmElectron(track)) value = 0;
324 else if(fSignal->IsBeautyElectron(track)) value = 1;
325 else if(fSignal->IsGammaElectron(track)) value = 2;
c2690925 326 else if(fSignal->IsNonHFElectron(track)) value = 3;
11ff28c5 327 else if(fSignal->IsJpsiElectron(track)) value = 4;
328 else if(fSignal->IsB2JpsiElectron(track)) value = 5;
329 else if(fSignal->IsKe3Electron(track)) value = 6;
330 else value = 7;
3a72645a 331 }
e17c1f86 332 AliDebug(2, Form("source: %f", value));
3a72645a 333 break;
334 }
335 case kSpecies: value = aprioriPID; break;
336 case kCentrality: value = centrality; break;
337 };
338 return value;
339}
340
341//____________________________________________________________
342void AliHFEvarManager::FillArray(AliVParticle *track, Double_t* container, Float_t centrality, Int_t aprioriPID) const{
343 //
344 // Fill array with variables
345 //
346 TIter vars(fVariables);
347 AliHFEvariable *var = NULL;
348 Int_t counter = 0;
349 while((var = dynamic_cast<AliHFEvariable *>(vars())))
350 container[counter++] = GetValue(track , var->GetVarCode(), centrality, aprioriPID);
351}
352
353//____________________________________________________________
354void AliHFEvarManager::FillContainer(AliCFContainer *cont, Int_t step, Bool_t useMC) const{
355 //
356 // Fill CF container with defined content
357 //
358
359 // Do reweighting if necessary
360 Double_t *content = fContent;
361 if(useMC) content = fContentMC;
362 cont->Fill(content, step, fWeightFactor);
363}
364
365//____________________________________________________________
c2690925 366void AliHFEvarManager::FillContainer(const AliHFEcontainer *const cont, const Char_t *contname, UInt_t step, Bool_t useMC, Double_t externalWeight) const {
3a72645a 367 //
368 // Fill CF container with defined content
369 //
370
371 // Do reweighting if necessary
372 Double_t *content = fContent;
373 if(useMC) content = fContentMC;
374 cont->FillCFContainer(contname, step, content, fWeightFactor * externalWeight);
375}
376
377//____________________________________________________________
c2690925 378void AliHFEvarManager::FillContainerStepname(const AliHFEcontainer *const cont, const Char_t *contname, const Char_t *step, Bool_t useMC, Double_t externalWeight) const {
3a72645a 379 //
380 // Fill CF container with defined content
381 //
382
383 // Do reweighting if necessary
384 Double_t *content = fContent;
385 if(useMC) content = fContentMC;
386 cont->FillCFContainerStepname(contname, step, content, fWeightFactor * externalWeight);
387}
388
389//____________________________________________________________
390void AliHFEvarManager::FillCorrelationMatrix(THnSparseF *matrix) const {
391 //
392 // Fill Correlation Matrix
393 //
394
395 // Do reweighting if necessary
c2690925 396 Int_t nVars = fVariables->GetEntriesFast();
397 Double_t *content = new Double_t[2*nVars];
398 memcpy(&content[0], fContent, sizeof(Double_t) * nVars);
399 memcpy(&content[nVars], fContentMC, sizeof(Double_t) * nVars);
400 matrix->Fill(content, fWeightFactor);
6c70d827 401 delete[] content;
c2690925 402
3a72645a 403}
404
405//_______________________________________________
406void AliHFEvarManager::SetWeightFactors(TH3F *weightFactors){
407 //
408 // Set the histos with the weights for the efficiency maps
409 //
410 fWeighting = kTRUE;
411 fWeightFactors = weightFactors;
412}
413
414//_______________________________________________
415void AliHFEvarManager::SetWeightFactorsFunction(TF3 *weightFactorsFunction){
416 //
417 // Set the histos with the weights for the efficiency maps
418 //
419 fWeighting = kTRUE;
420 fWeightFactorsFunction = weightFactorsFunction;
421}
422
423//_______________________________________________
424Double_t AliHFEvarManager::FindWeight(Double_t pt, Double_t eta, Double_t phi) const {
425 //
426 // Find the weight corresponding to pt eta and phi in the TH3D
427 //
428 Double_t weight = 1.0;
429 if(fWeightFactors) {
430
431 TAxis *ptaxis = fWeightFactors->GetXaxis();
432 TAxis *etaaxis = fWeightFactors->GetYaxis();
433 TAxis *phiaxis = fWeightFactors->GetZaxis();
434
435 Int_t ptbin = ptaxis->FindBin(pt);
436 Int_t etabin = etaaxis->FindBin(eta);
437 Int_t phibin = phiaxis->FindBin(phi);
438
439
440 weight = fWeightFactors->GetBinContent(ptbin,etabin,phibin);
441 }
442 else if(fWeightFactorsFunction) {
443
444 weight = fWeightFactorsFunction->Eval(pt,eta,phi);
445
446 }
447
448 AliDebug(2, Form("pt %f, eta %f, phi %f, weight %f",pt,eta,phi,weight));
449
450 return weight;
451}
452
453//_______________________________________________
454AliHFEvarManager::AliHFEvariable::AliHFEvariable():
455 TNamed()
456 , fCode(0)
457 , fNBins(0)
458 , fMin(0)
459 , fMax(0)
9f3d831b 460 , fBinning()
3a72645a 461 , fIsLogarithmic(kFALSE)
11ff28c5 462 , fUserDefinedBinning(kFALSE)
3a72645a 463{
464 //
465 // Dummy constructor
466 //
467}
468
8c1c76e9 469//_______________________________________________
470AliHFEvarManager::AliHFEvariable::AliHFEvariable(const Char_t *name, const Char_t *title, UInt_t code, UInt_t nBins, const Double_t *binning):
471 TNamed(name, title)
472 , fCode(code)
473 , fNBins(nBins)
474 , fMin(0.)
475 , fMax(0.)
9f3d831b 476 , fBinning()
8c1c76e9 477 , fIsLogarithmic(kFALSE)
11ff28c5 478 , fUserDefinedBinning(kTRUE)
8c1c76e9 479{
480 //
481 // Default constructor
482 //
9f3d831b 483 fBinning.Set(nBins+1);
484 memcpy(fBinning.GetArray(), binning, sizeof(Double_t) * (nBins+1));
8c1c76e9 485}
486
3a72645a 487//_______________________________________________
488AliHFEvarManager::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):
489 TNamed(name, title)
490 , fCode(code)
491 , fNBins(nBins)
492 , fMin(min)
493 , fMax(max)
9f3d831b 494 , fBinning()
3a72645a 495 , fIsLogarithmic(isLogarithmic)
11ff28c5 496 , fUserDefinedBinning(kFALSE)
3a72645a 497{
498 //
499 // Default constructor
500 //
501}
502
503//_______________________________________________
504AliHFEvarManager::AliHFEvariable::AliHFEvariable(const AliHFEvarManager::AliHFEvariable &ref):
505 TNamed(ref)
506 , fCode(ref.fCode)
507 , fNBins(ref.fNBins)
508 , fMin(ref.fMin)
509 , fMax(ref.fMax)
9f3d831b 510 , fBinning(ref.fBinning)
3a72645a 511 , fIsLogarithmic(ref.fIsLogarithmic)
11ff28c5 512 , fUserDefinedBinning(ref.fUserDefinedBinning)
3a72645a 513{
514 //
515 // Copy constructor
516 //
517}
518
519//_______________________________________________
520AliHFEvarManager::AliHFEvariable& AliHFEvarManager::AliHFEvariable::operator=(const AliHFEvarManager::AliHFEvariable &ref){
521 //
522 // Assignment operator
523 //
524
525 if(&ref != this){
526 TNamed::operator=(ref);
9f3d831b 527 fBinning = ref.fBinning;
3a72645a 528 fCode = ref.fCode;
529 fNBins = ref.fNBins;
530 fMax = ref.fMax;
531 fMin = ref.fMin;
532 fIsLogarithmic = ref.fIsLogarithmic;
11ff28c5 533 fUserDefinedBinning = ref.fUserDefinedBinning;
3a72645a 534 }
535 return *this;
536}
537
8c1c76e9 538//_______________________________________________
539AliHFEvarManager::AliHFEvariable::~AliHFEvariable(){
540 //
541 // Destruktor
542 //
8c1c76e9 543}
544
11ff28c5 545//_______________________________________________
546Double_t* AliHFEvarManager::AliHFEvariable::GetBinning() {
b593c849 547 //
548 // Get the binning
549 //
550
11ff28c5 551 if(fUserDefinedBinning) return fBinning.GetArray();
552
553 // No User defined Binning - create one and store in fBinning
554 if(fBinning.GetSize() != 0) return fBinning.GetArray();
555 else{
556 Double_t *binning;
557 if(fIsLogarithmic) binning = AliHFEtools::MakeLogarithmicBinning(fNBins, fMin, fMax);
558 else binning = AliHFEtools::MakeLogarithmicBinning(fNBins, fMin, fMax);
559 fBinning.Set(fNBins+1, binning);
71925dea 560 delete []binning;
11ff28c5 561 return fBinning.GetArray();
562 }
563}
564