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 "AliHFEvarManager.h"
46 ClassImp(AliHFEvarManager)
47 ClassImp(AliHFEvarManager::AliHFEvariable);
49 //____________________________________________________________
50 AliHFEvarManager::AliHFEvarManager():
60 fWeightFactorsFunction(NULL)
68 //____________________________________________________________
69 AliHFEvarManager::AliHFEvarManager(const Char_t *name):
79 fWeightFactorsFunction(NULL)
82 // Default constructor
84 fVariables = new TObjArray;
88 //____________________________________________________________
89 AliHFEvarManager::AliHFEvarManager(const AliHFEvarManager &ref):
94 fWeightFactor(ref.fWeightFactor),
95 fSignalTrack(ref.fSignalTrack),
96 fWeighting(ref.fWeighting),
99 fWeightFactorsFunction(NULL)
107 //____________________________________________________________
108 AliHFEvarManager &AliHFEvarManager::operator=(const AliHFEvarManager &ref){
110 // Assignment operator
113 this->~AliHFEvarManager();
119 //____________________________________________________________
120 AliHFEvarManager::~AliHFEvarManager(){
125 if(fVariables) delete fVariables;
127 if(fContent) delete[] fContent;
128 if(fContentMC) delete[] fContentMC;
131 //____________________________________________________________
132 void AliHFEvarManager::Copy(TObject &o) const{
136 AliHFEvarManager &target = dynamic_cast<AliHFEvarManager &>(o);
137 target.fVariables = fVariables;
138 target.fContent = new Double_t[sizeof(fContent)/sizeof(Double_t)];
139 target.fContentMC = new Double_t[sizeof(fContentMC)/sizeof(Double_t)];
140 target.fWeightFactor = fWeightFactor;
141 target.fSignalTrack = fSignalTrack;
142 target.fWeighting = fWeighting;
143 target.fSignal = fSignal;
144 target.fWeightFactors = fWeightFactors;
145 target.fWeightFactorsFunction = fWeightFactorsFunction;
146 target.SetOwner(kFALSE);
149 //____________________________________________________________
150 void AliHFEvarManager::AddVariable(TString name){
152 // Add new variable to the var manager
153 // Value derived via GetValue()
155 AliDebug(1, Form("Var Name: %s", name.Data()));
157 if(!name.CompareTo("pt"))
158 fVariables->AddLast(new AliHFEvariable("pt", "pt", kPt, 44, 0.1, 20, kTRUE));
159 else if(!name.CompareTo("eta"))
160 fVariables->AddLast(new AliHFEvariable("eta", "eta", kEta, 8, -0.8, 0.8));
161 else if(!name.CompareTo("phi"))
162 fVariables->AddLast(new AliHFEvariable("phi", "phi", kPhi, 18, -0, 2*TMath::Pi()));
163 else if(!name.CompareTo("charge"))
164 fVariables->AddLast(new AliHFEvariable("charge", "charge", kCharge, 2, -1.1, 1.1));
165 else if(!name.CompareTo("source"))
166 fVariables->AddLast(new AliHFEvariable("source", "source", kSource, 4, 0, 4));
167 else if(!name.CompareTo("centrality"))
168 fVariables->AddLast(new AliHFEvariable("centrality", "centrality", kCentrality, 11, 0.0, 11.0));
169 else if(!name.CompareTo("species"))
170 fVariables->AddLast(new AliHFEvariable("species", "species", kSpecies, 6, -1, 5));
175 //____________________________________________________________
176 Bool_t AliHFEvarManager::IsVariableDefined(TString name){
178 // Add new variable to the var manager
179 // Value derived via GetValue()
181 AliDebug(1, Form("Var Name: %s", name.Data()));
183 AliHFEvariable *u = (AliHFEvariable *) fVariables->FindObject((const char*)name);
190 //____________________________________________________________
191 void AliHFEvarManager::DefineVariables(AliHFEcontainer *cont){
195 Int_t nVars = fVariables->GetEntriesFast();
196 cont->SetNumberOfVariables(nVars);
197 TIter vars(fVariables);
200 while((var = dynamic_cast<AliHFEvariable *>(vars()))){
201 cont->SetVariableName(counter, var->GetName());
202 if(var->IsLogarithmic())
203 cont->MakeLogarithmicBinning(counter, var->GetNumberOfBins(), var->GetMinimum(), var->GetMaximum());
205 cont->MakeLinearBinning(counter, var->GetNumberOfBins(), var->GetMinimum(), var->GetMaximum());
208 fContent = new Double_t[nVars];
209 memset(fContent, 0, sizeof(Double_t) * nVars);
210 fContentMC = new Double_t[nVars];
211 memset(fContentMC, 0, sizeof(Double_t) * nVars);
214 //____________________________________________________________
215 void AliHFEvarManager::NewTrack(AliVParticle *recTrack, AliVParticle *mcTrack, Float_t centrality, Int_t aprioriPID, Bool_t signal){
217 // Cache information for new track pair
219 AliDebug(1, "Filling new Track");
220 fSignalTrack = signal;
221 FillArray(recTrack, fContent, centrality, aprioriPID);
222 if(mcTrack) FillArray(mcTrack, fContentMC, centrality, aprioriPID);
224 Int_t indexpt = -1, indexeta = -1, indexphi = -1, counter = 0;
225 AliHFEvariable *var = NULL;
226 TIter vars(fVariables);
227 while((var = dynamic_cast<AliHFEvariable *>(vars()))){
228 switch(var->GetVarCode()){
229 case kPt: indexpt = counter; break;
230 case kEta: indexeta = counter; break;
231 case kPhi: indexphi = counter; break;
233 if(indexpt >= 0 && indexeta >= 0 && indexphi >= 0) // all dimensions found
237 if(indexpt >= 0 && indexeta >= 0 && indexphi >= 0)
238 fWeightFactor = FindWeight(fContent[indexpt], fContent[indexeta], fContent[indexphi]);
242 //____________________________________________________________
243 Double_t AliHFEvarManager::GetValue(AliVParticle *track, UInt_t code, Float_t centrality, Int_t aprioriPID) const {
245 // Definition of the variables
247 if(!track) return 0.;
250 case kPt: value = track->Pt(); break;
251 case kEta: value = track->Eta(); break;
252 case kPhi: value = track->Phi(); break;
254 value = track->Charge();
255 if(TString(track->IsA()->GetName()).Contains("MC")) value /= 3;
260 if(fSignal->IsCharmElectron(track)) value = 0;
261 else if(fSignal->IsBeautyElectron(track)) value = 1;
262 else if(fSignal->IsGammaElectron(track)) value = 2;
267 case kSpecies: value = aprioriPID; break;
268 case kCentrality: value = centrality; break;
273 //____________________________________________________________
274 void AliHFEvarManager::FillArray(AliVParticle *track, Double_t* container, Float_t centrality, Int_t aprioriPID) const{
276 // Fill array with variables
278 TIter vars(fVariables);
279 AliHFEvariable *var = NULL;
281 while((var = dynamic_cast<AliHFEvariable *>(vars())))
282 container[counter++] = GetValue(track , var->GetVarCode(), centrality, aprioriPID);
285 //____________________________________________________________
286 void AliHFEvarManager::FillContainer(AliCFContainer *cont, Int_t step, Bool_t useMC) const{
288 // Fill CF container with defined content
291 // Do reweighting if necessary
292 Double_t *content = fContent;
293 if(useMC) content = fContentMC;
294 cont->Fill(content, step, fWeightFactor);
297 //____________________________________________________________
298 void AliHFEvarManager::FillContainer(AliHFEcontainer *cont, const Char_t *contname, UInt_t step, Bool_t useMC, Double_t externalWeight) const {
300 // Fill CF container with defined content
303 // Do reweighting if necessary
304 Double_t *content = fContent;
305 if(useMC) content = fContentMC;
306 cont->FillCFContainer(contname, step, content, fWeightFactor * externalWeight);
309 //____________________________________________________________
310 void AliHFEvarManager::FillContainerStepname(AliHFEcontainer *cont, const Char_t *contname, const Char_t *step, Bool_t useMC, Double_t externalWeight) const {
312 // Fill CF container with defined content
315 // Do reweighting if necessary
316 Double_t *content = fContent;
317 if(useMC) content = fContentMC;
318 cont->FillCFContainerStepname(contname, step, content, fWeightFactor * externalWeight);
321 //____________________________________________________________
322 void AliHFEvarManager::FillCorrelationMatrix(THnSparseF *matrix) const {
324 // Fill Correlation Matrix
327 // Do reweighting if necessary
328 Double_t content[10];
329 memcpy(content, fContent, sizeof(Double_t) * 5);
330 memcpy(&content[5], fContentMC, sizeof(Double_t) * 5);
331 matrix->Fill(content, fWeightFactor);
334 //_______________________________________________
335 void AliHFEvarManager::SetWeightFactors(TH3F *weightFactors){
337 // Set the histos with the weights for the efficiency maps
340 fWeightFactors = weightFactors;
343 //_______________________________________________
344 void AliHFEvarManager::SetWeightFactorsFunction(TF3 *weightFactorsFunction){
346 // Set the histos with the weights for the efficiency maps
349 fWeightFactorsFunction = weightFactorsFunction;
352 //_______________________________________________
353 Double_t AliHFEvarManager::FindWeight(Double_t pt, Double_t eta, Double_t phi) const {
355 // Find the weight corresponding to pt eta and phi in the TH3D
357 Double_t weight = 1.0;
360 TAxis *ptaxis = fWeightFactors->GetXaxis();
361 TAxis *etaaxis = fWeightFactors->GetYaxis();
362 TAxis *phiaxis = fWeightFactors->GetZaxis();
364 Int_t ptbin = ptaxis->FindBin(pt);
365 Int_t etabin = etaaxis->FindBin(eta);
366 Int_t phibin = phiaxis->FindBin(phi);
369 weight = fWeightFactors->GetBinContent(ptbin,etabin,phibin);
371 else if(fWeightFactorsFunction) {
373 weight = fWeightFactorsFunction->Eval(pt,eta,phi);
377 AliDebug(2, Form("pt %f, eta %f, phi %f, weight %f",pt,eta,phi,weight));
382 //_______________________________________________
383 AliHFEvarManager::AliHFEvariable::AliHFEvariable():
389 , fIsLogarithmic(kFALSE)
396 //_______________________________________________
397 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):
403 , fIsLogarithmic(isLogarithmic)
406 // Default constructor
410 //_______________________________________________
411 AliHFEvarManager::AliHFEvariable::AliHFEvariable(const AliHFEvarManager::AliHFEvariable &ref):
417 , fIsLogarithmic(ref.fIsLogarithmic)
424 //_______________________________________________
425 AliHFEvarManager::AliHFEvariable& AliHFEvarManager::AliHFEvariable::operator=(const AliHFEvarManager::AliHFEvariable &ref){
427 // Assignment operator
431 TNamed::operator=(ref);
436 fIsLogarithmic = ref.fIsLogarithmic;