1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 // Class AliHFEvarManager:
17 // Contains definition of the variables which are filled into the
18 // Correction framework container. The class handles both AliCFContainer and
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
29 // Markus Fasel <M.Fasel@gsi.de>
35 #include <THnSparse.h>
38 #include "AliCFContainer.h"
40 #include "AliVParticle.h"
42 #include "AliHFEcontainer.h"
43 #include "AliHFEsignalCuts.h"
44 #include "AliHFEtools.h"
45 #include "AliHFEvarManager.h"
47 ClassImp(AliHFEvarManager)
48 ClassImp(AliHFEvarManager::AliHFEvariable);
50 //____________________________________________________________
51 AliHFEvarManager::AliHFEvarManager():
61 fWeightFactorsFunction(NULL)
69 //____________________________________________________________
70 AliHFEvarManager::AliHFEvarManager(const Char_t *name):
80 fWeightFactorsFunction(NULL)
83 // Default constructor
85 fVariables = new TObjArray;
89 //____________________________________________________________
90 AliHFEvarManager::AliHFEvarManager(const AliHFEvarManager &ref):
95 fWeightFactor(ref.fWeightFactor),
96 fSignalTrack(ref.fSignalTrack),
97 fWeighting(ref.fWeighting),
100 fWeightFactorsFunction(NULL)
108 //____________________________________________________________
109 AliHFEvarManager &AliHFEvarManager::operator=(const AliHFEvarManager &ref){
111 // Assignment operator
114 this->~AliHFEvarManager();
120 //____________________________________________________________
121 AliHFEvarManager::~AliHFEvarManager(){
126 if(fVariables) delete fVariables;
128 if(fContent) delete[] fContent;
129 if(fContentMC) delete[] fContentMC;
132 //____________________________________________________________
133 void AliHFEvarManager::Copy(TObject &o) const{
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);
150 //____________________________________________________________
151 void AliHFEvarManager::AddVariable(TString name){
153 // Add new variable to the var manager
154 // Use default binning
155 // Value derived via GetValue()
157 AliDebug(1, Form("Var Name: %s", name.Data()));
159 if(!name.CompareTo("pt"))
160 fVariables->AddLast(new AliHFEvariable("pt", "pt", kPt, 44, 0.1, 20, kTRUE));
161 else if(!name.CompareTo("eta"))
162 fVariables->AddLast(new AliHFEvariable("eta", "eta", kEta, 8, -0.8, 0.8));
163 else if(!name.CompareTo("phi"))
164 fVariables->AddLast(new AliHFEvariable("phi", "phi", kPhi, 18, -0, 2*TMath::Pi()));
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"))
168 fVariables->AddLast(new AliHFEvariable("source", "source", kSource, 8, 0, 8));
169 else if(!name.CompareTo("centrality"))
170 fVariables->AddLast(new AliHFEvariable("centrality", "centrality", kCentrality, 11, 0.0, 11.0));
171 else if(!name.CompareTo("species"))
172 fVariables->AddLast(new AliHFEvariable("species", "species", kSpecies, 6, -1, 5));
177 //____________________________________________________________
178 void AliHFEvarManager::AddVariable(TString name, Int_t nBins, Double_t min, Double_t max, Bool_t isLogarithmic){
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()
185 AliDebug(1, Form("Var Name: %s", name.Data()));
187 UInt_t varcode = 1000;
188 if(!name.CompareTo("pt")){
190 } else if(!name.CompareTo("eta")){
192 } else if(!name.CompareTo("phi")){
194 } else if(!name.CompareTo("charge")){
196 } else if(!name.CompareTo("source")){
198 } else if(!name.CompareTo("species")){
200 } else if(!name.CompareTo("centrality")) {
201 varcode = kCentrality;
203 AliError("Variable not defined or not supposed to have a user-defined binning.");
206 if(varcode < 1000) fVariables->AddLast(new AliHFEvariable(name.Data(), name.Data(), varcode, nBins, min, max, isLogarithmic));
210 //____________________________________________________________
211 void AliHFEvarManager::AddVariable(TString name, Int_t nBins, const Double_t *binning){
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()
217 AliDebug(1, Form("Var Name: %s", name.Data()));
219 UInt_t varcode = 1000;
220 if(!name.CompareTo("pt")){
222 } else if(!name.CompareTo("eta")){
224 } else if(!name.CompareTo("phi")){
226 } else if(!name.CompareTo("centrality")) {
227 varcode = kCentrality;
229 AliError("Variable not defined or not supposed to have a user-defined binning.");
232 if(varcode < 1000) fVariables->AddLast(new AliHFEvariable(name.Data(), name.Data(), varcode, nBins, binning));
236 //____________________________________________________________
237 Bool_t AliHFEvarManager::IsVariableDefined(TString name){
239 // Add new variable to the var manager
240 // Value derived via GetValue()
242 AliDebug(1, Form("Var Name: %s", name.Data()));
244 AliHFEvariable *u = (AliHFEvariable *) fVariables->FindObject((const char*)name);
251 //____________________________________________________________
252 void AliHFEvarManager::DefineVariables(AliHFEcontainer *cont){
256 Int_t nVars = fVariables->GetEntriesFast();
257 cont->SetNumberOfVariables(nVars);
258 TIter vars(fVariables);
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());
265 else if(var->HasUserDefinedBinning())
266 cont->MakeUserDefinedBinning(counter, var->GetNumberOfBins(), var->GetBinning());
268 cont->MakeLinearBinning(counter, var->GetNumberOfBins(), var->GetMinimum(), var->GetMaximum());
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);
277 //____________________________________________________________
278 void AliHFEvarManager::NewTrack(AliVParticle *recTrack, AliVParticle *mcTrack, Float_t centrality, Int_t aprioriPID, Bool_t signal){
280 // Cache information for new track pair
282 AliDebug(1, "Filling new Track");
283 fSignalTrack = signal;
284 FillArray(recTrack, fContent, centrality, aprioriPID);
285 if(mcTrack) FillArray(mcTrack, fContentMC, centrality, aprioriPID);
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;
296 if(indexpt >= 0 && indexeta >= 0 && indexphi >= 0) // all dimensions found
300 if(indexpt >= 0 && indexeta >= 0 && indexphi >= 0)
301 fWeightFactor = FindWeight(fContent[indexpt], fContent[indexeta], fContent[indexphi]);
305 //____________________________________________________________
306 Double_t AliHFEvarManager::GetValue(AliVParticle *track, UInt_t code, Float_t centrality, Int_t aprioriPID) const {
308 // Definition of the variables
310 if(!track) return 0.;
313 case kPt: value = track->Pt(); break;
314 case kEta: value = track->Eta(); break;
315 case kPhi: value = track->Phi(); break;
317 value = track->Charge();
318 if(TString(track->IsA()->GetName()).Contains("MC")) value /= 3;
323 if(fSignal->IsCharmElectron(track)) value = 0;
324 else if(fSignal->IsBeautyElectron(track)) value = 1;
325 else if(fSignal->IsGammaElectron(track)) value = 2;
326 else if(fSignal->IsNonHFElectron(track)) value = 3;
327 else if(fSignal->IsJpsiElectron(track)) value = 4;
328 else if(fSignal->IsB2JpsiElectron(track)) value = 5;
329 else if(fSignal->IsKe3Electron(track)) value = 6;
332 AliDebug(2, Form("source: %f", value));
335 case kSpecies: value = aprioriPID; break;
336 case kCentrality: value = centrality; break;
341 //____________________________________________________________
342 void AliHFEvarManager::FillArray(AliVParticle *track, Double_t* container, Float_t centrality, Int_t aprioriPID) const{
344 // Fill array with variables
346 TIter vars(fVariables);
347 AliHFEvariable *var = NULL;
349 while((var = dynamic_cast<AliHFEvariable *>(vars())))
350 container[counter++] = GetValue(track , var->GetVarCode(), centrality, aprioriPID);
353 //____________________________________________________________
354 void AliHFEvarManager::FillContainer(AliCFContainer *cont, Int_t step, Bool_t useMC) const{
356 // Fill CF container with defined content
359 // Do reweighting if necessary
360 Double_t *content = fContent;
361 if(useMC) content = fContentMC;
362 cont->Fill(content, step, fWeightFactor);
365 //____________________________________________________________
366 void AliHFEvarManager::FillContainer(const AliHFEcontainer *const cont, const Char_t *contname, UInt_t step, Bool_t useMC, Double_t externalWeight) const {
368 // Fill CF container with defined content
371 // Do reweighting if necessary
372 Double_t *content = fContent;
373 if(useMC) content = fContentMC;
374 cont->FillCFContainer(contname, step, content, fWeightFactor * externalWeight);
377 //____________________________________________________________
378 void AliHFEvarManager::FillContainerStepname(const AliHFEcontainer *const cont, const Char_t *contname, const Char_t *step, Bool_t useMC, Double_t externalWeight) const {
380 // Fill CF container with defined content
383 // Do reweighting if necessary
384 Double_t *content = fContent;
385 if(useMC) content = fContentMC;
386 cont->FillCFContainerStepname(contname, step, content, fWeightFactor * externalWeight);
389 //____________________________________________________________
390 void AliHFEvarManager::FillCorrelationMatrix(THnSparseF *matrix) const {
392 // Fill Correlation Matrix
395 // Do reweighting if necessary
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);
405 //_______________________________________________
406 void AliHFEvarManager::SetWeightFactors(TH3F *weightFactors){
408 // Set the histos with the weights for the efficiency maps
411 fWeightFactors = weightFactors;
414 //_______________________________________________
415 void AliHFEvarManager::SetWeightFactorsFunction(TF3 *weightFactorsFunction){
417 // Set the histos with the weights for the efficiency maps
420 fWeightFactorsFunction = weightFactorsFunction;
423 //_______________________________________________
424 Double_t AliHFEvarManager::FindWeight(Double_t pt, Double_t eta, Double_t phi) const {
426 // Find the weight corresponding to pt eta and phi in the TH3D
428 Double_t weight = 1.0;
431 TAxis *ptaxis = fWeightFactors->GetXaxis();
432 TAxis *etaaxis = fWeightFactors->GetYaxis();
433 TAxis *phiaxis = fWeightFactors->GetZaxis();
435 Int_t ptbin = ptaxis->FindBin(pt);
436 Int_t etabin = etaaxis->FindBin(eta);
437 Int_t phibin = phiaxis->FindBin(phi);
440 weight = fWeightFactors->GetBinContent(ptbin,etabin,phibin);
442 else if(fWeightFactorsFunction) {
444 weight = fWeightFactorsFunction->Eval(pt,eta,phi);
448 AliDebug(2, Form("pt %f, eta %f, phi %f, weight %f",pt,eta,phi,weight));
453 //_______________________________________________
454 AliHFEvarManager::AliHFEvariable::AliHFEvariable():
461 , fIsLogarithmic(kFALSE)
462 , fUserDefinedBinning(kFALSE)
469 //_______________________________________________
470 AliHFEvarManager::AliHFEvariable::AliHFEvariable(const Char_t *name, const Char_t *title, UInt_t code, UInt_t nBins, const Double_t *binning):
477 , fIsLogarithmic(kFALSE)
478 , fUserDefinedBinning(kTRUE)
481 // Default constructor
483 fBinning.Set(nBins+1);
484 memcpy(fBinning.GetArray(), binning, sizeof(Double_t) * (nBins+1));
487 //_______________________________________________
488 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):
495 , fIsLogarithmic(isLogarithmic)
496 , fUserDefinedBinning(kFALSE)
499 // Default constructor
503 //_______________________________________________
504 AliHFEvarManager::AliHFEvariable::AliHFEvariable(const AliHFEvarManager::AliHFEvariable &ref):
510 , fBinning(ref.fBinning)
511 , fIsLogarithmic(ref.fIsLogarithmic)
512 , fUserDefinedBinning(ref.fUserDefinedBinning)
519 //_______________________________________________
520 AliHFEvarManager::AliHFEvariable& AliHFEvarManager::AliHFEvariable::operator=(const AliHFEvarManager::AliHFEvariable &ref){
522 // Assignment operator
526 TNamed::operator=(ref);
527 fBinning = ref.fBinning;
532 fIsLogarithmic = ref.fIsLogarithmic;
533 fUserDefinedBinning = ref.fUserDefinedBinning;
538 //_______________________________________________
539 AliHFEvarManager::AliHFEvariable::~AliHFEvariable(){
545 //_______________________________________________
546 Double_t* AliHFEvarManager::AliHFEvariable::GetBinning() {
551 if(fUserDefinedBinning) return fBinning.GetArray();
553 // No User defined Binning - create one and store in fBinning
554 if(fBinning.GetSize() != 0) return fBinning.GetArray();
557 if(fIsLogarithmic) binning = AliHFEtools::MakeLogarithmicBinning(fNBins, fMin, fMax);
558 else binning = AliHFEtools::MakeLogarithmicBinning(fNBins, fMin, fMax);
559 fBinning.Set(fNBins+1, binning);
561 return fBinning.GetArray();