AliPhysics  5dd2c10 (5dd2c10)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
AliMultiDimVector.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 2007-2009, 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 /* $Id$ */
17 
19 // //
20 // Implementation of the class to store the number of signal //
21 // and background events in bins of the cut values //
22 // Origin: Elena Bruna (bruna@to.infn.it) //
23 // Updated: Sergey Senyukov (senyukov@to.infn.it) //
24 // Francesco Prino (prino@to.infn.it) //
25 // Last Updated: Giacomo Ortona (ortona@to.infn.it) //
26 // //
28 
29 #include <fstream>
30 #include <Riostream.h>
31 #include "TH2.h"
32 #include "AliMultiDimVector.h"
33 #include "AliLog.h"
34 #include "TString.h"
35 
36 using std::cout;
37 using std::endl;
38 
42 
43 //___________________________________________________________________________
44 AliMultiDimVector::AliMultiDimVector():TNamed("AliMultiDimVector","default"),
45 fNVariables(0),
46 fNPtBins(0),
47 fVett(0),
48 fNTotCells(0),
49 fIsIntegrated(0)
50 {
51  // default constructor
52 
53  for(Int_t i=0; i<fgkMaxNVariables; i++) {
54  fNCutSteps[i]=0;
55  fMinLimits[i]=0;
56  fMaxLimits[i]=0;
57  fGreaterThan[i]=kTRUE;
58  fAxisTitles[i]="";
59  }
60  for(Int_t i=0; i<fgkMaxNPtBins+1; i++) {
61  fPtLimits[i]=0;
62  }
63 }
64 //___________________________________________________________________________
65 AliMultiDimVector::AliMultiDimVector(const char *name,const char *title, const Int_t nptbins, const Float_t* ptlimits, const Int_t npars, const Int_t *nofcells,const Float_t *loosecuts, const Float_t *tightcuts, const TString *axisTitles):TNamed(name,title),
66 fNVariables(npars),
67 fNPtBins(nptbins),
68 fVett(0),
69 fNTotCells(0),
70 fIsIntegrated(0){
71 // standard constructor
72 
73  for(Int_t i=0; i<fgkMaxNVariables; i++) {
74  fNCutSteps[i]=0;
75  fMinLimits[i]=0;
76  fMaxLimits[i]=0;
77  fGreaterThan[i]=kTRUE;
78  fAxisTitles[i]="";
79  }
80  for(Int_t i=0; i<fgkMaxNPtBins+1; i++) {
81  fPtLimits[i]=0;
82  }
83 
84  ULong64_t ntot=1;
85  for(Int_t i=0;i<fNVariables;i++){
86  ntot*=nofcells[i];
87  fNCutSteps[i]=nofcells[i];
88  if(loosecuts[i] == tightcuts[i]){
89  if(loosecuts[i]!=0){
90  printf("AliMultiDimVector::AliMultiDimVector: WARNING! same tight/loose variable for variable number %d. AliMultiDimVector with run with the following values: loose: %f; tight: %f\n",i,tightcuts[i]-0.1*tightcuts[i],tightcuts[i]);
91  fMinLimits[i]=tightcuts[i]-0.1*tightcuts[i];
92  fMaxLimits[i]=tightcuts[i];
93  }else{
94  fMinLimits[i]=0;
95  fMaxLimits[i]=0.0001;
96  }
97  fGreaterThan[i]=kTRUE;
98  }
99  if(loosecuts[i] < tightcuts[i]){
100  fMinLimits[i]=loosecuts[i];
101  fMaxLimits[i]=tightcuts[i];
102  fGreaterThan[i]=kTRUE;
103  }else{
104  fMinLimits[i]=tightcuts[i];
105  fMaxLimits[i]=loosecuts[i];
106  fGreaterThan[i]=kFALSE;
107  }
108  fAxisTitles[i]=axisTitles[i].Data();
109  }
110  fNTotCells=ntot*fNPtBins;
111  fVett.Set(fNTotCells);
112  for(Int_t ipt=0;ipt<fNPtBins+1;ipt++) fPtLimits[ipt]=ptlimits[ipt];
113  for(Int_t ipt=fNPtBins+1;ipt<fgkMaxNPtBins+1;ipt++) fPtLimits[ipt]=999.;
114  for (ULong64_t j=0;j<fNTotCells;j++) fVett.AddAt(0,j);
115 }
116 //___________________________________________________________________________
117 AliMultiDimVector::AliMultiDimVector(const AliMultiDimVector &mv):TNamed(mv.GetName(),mv.GetTitle()),
118 fNVariables(mv.fNVariables),
119 fNPtBins(mv.fNPtBins),
120 fVett(0),
121 fNTotCells(mv.fNTotCells),
122 fIsIntegrated(mv.fIsIntegrated)
123 {
124  // copy constructor
125 
126  for(Int_t i=0; i<fgkMaxNVariables; i++) {
127  fNCutSteps[i]=0;
128  fMinLimits[i]=0;
129  fMaxLimits[i]=0;
130  fGreaterThan[i]=kTRUE;
131  fAxisTitles[i]="";
132  }
133  for(Int_t i=0; i<fgkMaxNPtBins+1; i++) {
134  fPtLimits[i]=0;
135  }
136 
137 
138  for(Int_t i=0;i<fNVariables;i++){
139  fNCutSteps[i]=mv.GetNCutSteps(i);
140  fMinLimits[i]=mv.GetMinLimit(i);
141  fMaxLimits[i]=mv.GetMaxLimit(i);
142  fGreaterThan[i]=mv.GetGreaterThan(i);
143  fAxisTitles[i]=mv.GetAxisTitle(i);
144  }
145  fVett.Set(fNTotCells);
146 
147  for(Int_t ipt=0;ipt<fNPtBins+1;ipt++) fPtLimits[ipt]=mv.GetPtLimit(ipt);
148  for(ULong64_t i=0;i<fNTotCells;i++) fVett[i]=mv.GetElement(i);
149 }
150 //___________________________________________________________________________
152 {
153  // assignment operator
154 
155  if(&mv == this) return *this;
156 
157  TNamed::operator=(mv);
158 
160  fNPtBins=mv.fNPtBins;
163 
164 
165  for(Int_t i=0; i<fgkMaxNVariables; i++) {
166  fNCutSteps[i]=0;
167  fMinLimits[i]=0;
168  fMaxLimits[i]=0;
169  fGreaterThan[i]=kTRUE;
170  fAxisTitles[i]="";
171  }
172  for(Int_t i=0; i<fgkMaxNPtBins+1; i++) {
173  fPtLimits[i]=0;
174  }
175 
176 
177  for(Int_t i=0;i<fNVariables;i++){
178  fNCutSteps[i]=mv.GetNCutSteps(i);
179  fMinLimits[i]=mv.GetMinLimit(i);
180  fMaxLimits[i]=mv.GetMaxLimit(i);
181  fGreaterThan[i]=mv.GetGreaterThan(i);
182  fAxisTitles[i]=mv.GetAxisTitle(i);
183  }
184  fVett.Set(fNTotCells);
185 
186  for(Int_t ipt=0;ipt<fNPtBins+1;ipt++) fPtLimits[ipt]=mv.GetPtLimit(ipt);
187  for(ULong64_t i=0;i<fNTotCells;i++) fVett[i]=mv.GetElement(i);
188 
189  return *this;
190 }
191 //___________________________________________________________________________
193 // Sets dimensions and limit from mv
195  fNPtBins=mv->GetNPtBins();
196  fNTotCells=mv->GetNTotCells();
198  for(Int_t i=0;i<fNVariables;i++){
199  fNCutSteps[i]=mv->GetNCutSteps(i);
200  fMinLimits[i]=mv->GetMinLimit(i);
201  fMaxLimits[i]=mv->GetMaxLimit(i);
202  fGreaterThan[i]=mv->GetGreaterThan(i);
203  fAxisTitles[i]=mv->GetAxisTitle(i);
204  }
205  for(Int_t ipt=0;ipt<fNPtBins+1;ipt++) fPtLimits[ipt]=mv->GetPtLimit(ipt);
206  fVett.Set(fNTotCells);
207 }
208 //______________________________________________________________________
209 Bool_t AliMultiDimVector::GetIndicesFromGlobalAddress(ULong64_t globadd, Int_t *ind, Int_t &ptbin) const {
210 // returns matrix element indices and Pt bin from global index
211  if(globadd>=fNTotCells) return kFALSE;
212  ULong64_t r=globadd;
213  Int_t prod=1;
214  Int_t nOfCellsPlusLevel[fgkMaxNVariables+1];
215  for(Int_t k=0;k<fNVariables;k++) nOfCellsPlusLevel[k]=fNCutSteps[k];
216  nOfCellsPlusLevel[fNVariables]=fNPtBins;
217 
218  for(Int_t i=0;i<fNVariables+1;i++) prod*=nOfCellsPlusLevel[i];
219  for(Int_t i=0;i<fNVariables+1;i++){
220  prod/=nOfCellsPlusLevel[i];
221  if(i<fNVariables) ind[i]=r/prod;
222  else ptbin=r/prod;
223  r=globadd%prod;
224  }
225  return kTRUE;
226 }
227 //______________________________________________________________________
228 Bool_t AliMultiDimVector::GetCutValuesFromGlobalAddress(ULong64_t globadd, Float_t *cuts, Int_t &ptbin) const {
229  Int_t ind[fgkMaxNVariables];
230  Bool_t retcode=GetIndicesFromGlobalAddress(globadd,ind,ptbin);
231  if(!retcode) return kFALSE;
232  for(Int_t i=0;i<fNVariables;i++) cuts[i]=GetCutValue(i,ind[i]);
233  return kTRUE;
234 }
235 //______________________________________________________________________
236 ULong64_t AliMultiDimVector::GetGlobalAddressFromIndices(const Int_t *ind, Int_t ptbin) const {
237  // Returns the global index of the cell in the matrix
238  Int_t prod=1;
239  ULong64_t elem=0;
240  Int_t indexPlusLevel[fgkMaxNVariables+1];
241  Int_t nOfCellsPlusLevel[fgkMaxNVariables+1];
242  for(Int_t i=0;i<fNVariables;i++){
243  indexPlusLevel[i]=ind[i];
244  nOfCellsPlusLevel[i]=fNCutSteps[i];
245  }
246  indexPlusLevel[fNVariables]=ptbin;
247  nOfCellsPlusLevel[fNVariables]=fNPtBins;
248 
249  for(Int_t i=0;i<fNVariables+1;i++){
250  prod=indexPlusLevel[i];
251  if(i<fNVariables){
252  for(Int_t j=i+1;j<fNVariables+1;j++){
253  prod*=nOfCellsPlusLevel[j];
254  }
255  }
256  elem+=prod;
257  }
258  return elem;
259 }
260 //______________________________________________________________________
261 Bool_t AliMultiDimVector::GetIndicesFromValues(const Float_t *values, Int_t *ind) const {
262  // Fills the array of matrix indices strating from variable values
263  for(Int_t i=0;i<fNVariables;i++){
264  if(fGreaterThan[i]){
265  if(values[i]<GetMinLimit(i)) return kFALSE;
266  ind[i]=(Int_t)((values[i]-fMinLimits[i])/GetCutStep(i));
267  if(ind[i]>=GetNCutSteps(i)) ind[i]=GetNCutSteps(i)-1;
268  }else{
269  if(values[i]>GetMaxLimit(i)) return kFALSE;
270  ind[i]=(Int_t)((fMaxLimits[i]-values[i])/GetCutStep(i));
271  if(ind[i]>=GetNCutSteps(i)) ind[i]=GetNCutSteps(i)-1;
272  }
273  }
274  return kTRUE;
275 }
276 //______________________________________________________________________
277 ULong64_t AliMultiDimVector::GetGlobalAddressFromValues(const Float_t *values, Int_t ptbin) const {
278  // Returns the global index of the cell in the matrix
279  Int_t ind[fgkMaxNVariables];
280  Bool_t retcode=GetIndicesFromValues(values,ind);
281  if(retcode) return GetGlobalAddressFromIndices(ind,ptbin);
282  else{
283  AliError("Values out of range");
284  return fNTotCells+999;
285  }
286 }
287 //_____________________________________________________________________________
288 void AliMultiDimVector::MultiplyBy(Float_t factor){
289  // multiply the AliMultiDimVector by a constant factor
290  for(ULong64_t i=0;i<fNTotCells;i++){
291  if(fVett.At(i)>0.)
292  fVett.AddAt(fVett.At(i)*factor,i);
293  else fVett.AddAt(-1,i);
294  }
295 
296 }
297 //_____________________________________________________________________________
298 void AliMultiDimVector::Multiply(const AliMultiDimVector* mv,Float_t factor){
299  // Sets AliMultiDimVector=mv*constant factor
300  for(ULong64_t i=0;i<fNTotCells;i++){
301  if(mv->GetElement(i)>0.)
302  fVett.AddAt(mv->GetElement(i)*factor,i);
303  else fVett.AddAt(-1,i);
304  }
305 }
306 //_____________________________________________________________________________
308  // Sets AliMultiDimVector=mv1*mv2
309  for(ULong64_t i=0;i<fNTotCells;i++){
310  if(mv1->GetElement(i)>0. && mv2->GetElement(i)>0.)
311  fVett.AddAt(mv1->GetElement(i)*mv2->GetElement(i),i);
312  else fVett.AddAt(-1,i);
313  }
314 }
315 //_____________________________________________________________________________
317  // Sums contents of mv to AliMultiDimVector
318  if (mv->GetNTotCells()!=fNTotCells){
319  AliError("Different dimension of the vectors!!");
320  }else{
321  for(ULong64_t i=0;i<fNTotCells;i++)
322  if(mv->GetElement(i)>0. && fVett.At(i)>0.)
323  fVett.AddAt(fVett.At(i)+mv->GetElement(i),i);
324  else fVett.AddAt(-1,i);
325  }
326 }
327 //_____________________________________________________________________________
329  // Sets AliMultiDimVector=mv1+mv2
330  if (fNTotCells!=mv1->GetNTotCells()&&mv1->GetNTotCells()!=mv2->GetNTotCells()) {
331  AliError("Different dimension of the vectors!!");
332  }
333  else{
334  for(ULong64_t i=0;i<mv1->GetNTotCells();i++) {
335  if(mv1->GetElement(i)>0. && mv2->GetElement(i)>0.)
336  fVett.AddAt(mv1->GetElement(i)+mv2->GetElement(i),i);
337  else fVett.AddAt(-1,i);
338  }
339  }
340 }
341 //_____________________________________________________________________________
342 void AliMultiDimVector::LinearComb(const AliMultiDimVector* mv1, Float_t norm1, const AliMultiDimVector* mv2, Float_t norm2){
343  // Sets AliMultiDimVector=n1*mv1+n2*mv2
344  if (fNTotCells!=mv1->GetNTotCells()&&mv1->GetNTotCells()!=mv2->GetNTotCells()) {
345  AliError("Different dimension of the vectors!!");
346  }
347  else{
348  for(ULong64_t i=0;i<mv1->GetNTotCells();i++) {
349  if(mv1->GetElement(i)>0. && mv2->GetElement(i)>0.)
350  fVett.AddAt(norm1*mv1->GetElement(i)+norm2*mv2->GetElement(i),i);
351  else fVett.AddAt(-1,i);
352  }
353  }
354 }
355 //_____________________________________________________________________________
357  // Divide AliMulivector by mv
358  if (mv->GetNTotCells()!=fNTotCells) {
359  AliError("Different dimension of the vectors!!");
360  }
361  else{
362  for(ULong64_t i=0;i<fNTotCells;i++)
363  if(mv->GetElement(i)!=0 &&mv->GetElement(i)>0. && fVett.At(i)>0.)
364  fVett.AddAt(fVett.At(i)/mv->GetElement(i),i);
365  else fVett.AddAt(-1,i);
366  }
367 
368 }
369 //_____________________________________________________________________________
371  // Sets AliMultiDimVector=mv1/mv2
372  if (fNTotCells!=mv1->GetNTotCells()&&mv1->GetNTotCells()!=mv2->GetNTotCells()) {
373  AliError("Different dimension of the vectors!!");
374  }
375  else{
376  for(ULong64_t i=0;i<mv1->GetNTotCells();i++)
377  if(mv2->GetElement(i)!=0&& mv2->GetElement(i)>0.&& mv1->GetElement(i)>0.)
378  {
379  fVett.AddAt(mv1->GetElement(i)/mv2->GetElement(i),i);
380  }
381  else fVett.AddAt(-1,i);
382  }
383 }
384 //_____________________________________________________________________________
386  // Sqrt of elements of AliMultiDimVector
387  for(ULong64_t i=0;i<fNTotCells;i++) {
388  if(fVett.At(i)>=0) fVett.AddAt(TMath::Sqrt(fVett.At(i)),i);
389  else {
390  fVett.AddAt(-1,i);
391  }
392  }
393 }
394 //_____________________________________________________________________________
396  // Sets AliMultiDimVector=sqrt(mv)
397  for(ULong64_t i=0;i<fNTotCells;i++)
398  if(mv->GetElement(i)>=0) fVett.AddAt(TMath::Sqrt(mv->GetElement(i)),i);
399  else fVett.AddAt(-1,i);
400 }
401 //_____________________________________________________________________________
402 void AliMultiDimVector::FindMaximum(Float_t& maxValue, Int_t *ind , Int_t ptbin){
403  // finds the element with maximum contents
404  const ULong64_t nelem=fNTotCells/fNPtBins;
405  TArrayF vett;
406  vett.Set(nelem);
407  ULong64_t runningAddress;
408  for(ULong64_t i=0;i<nelem;i++){
409  runningAddress=ptbin+i*fNPtBins;
410  vett.AddAt(fVett[runningAddress],i);
411  }
412  maxValue=TMath::MaxElement(nelem,vett.GetArray());
413  ULong64_t maxAddress=TMath::LocMax(nelem,vett.GetArray());
414  ULong64_t maxGlobalAddress=ptbin+maxAddress*fNPtBins;
415  Int_t checkedptbin;
416  GetIndicesFromGlobalAddress(maxGlobalAddress,ind,checkedptbin);
417 }
418 
419 //_____________________________________________________________________________
420 //Int_t* AliMultiDimVector::FindLocalMaximum(Float_t& maxValue, Bool_t *isFree,Int_t* indFixed, Int_t ptbin){
421 Int_t* AliMultiDimVector::FindLocalMaximum(Float_t& maxValue, Int_t *numFixed,Int_t* indFixed, Int_t nfixed,Int_t ptbin){
422  //return the elements with maximum content (maxValue) given fixed step for not free variables
423  //numFixed[nfixed] is the indices of the fixed variables in the cuts array [fNVariables]={kTRUE,kTRUE,...,kFALSE,...,kFALSE,...,kTRUE}
424  //indFixed[nfixed]={1,2} //nfixed is the number of false in isFree; indFixed contains the step for the i-th variable
426 
427  // Int_t nfixed=0,nfree=0;
428  //Int_t indtmp[fNVariables];
429  if(nfixed>fNVariables)cout<<"AliMultiDimVector::FindLocalMaximum:ERROR! too many variables"<<endl;
430  ULong64_t nelem=1;
431  Int_t* indMax=new Int_t[fNVariables];
432  //Get the number of fixed vars
433  /*
434  for (Int_t iv=0;iv<fNVariables;iv++){
435  if(isFree[iv]){
436  nfree++;
437  nelem*=fNCutSteps[iv];
438  indMax[iv]=0;
439  }
440  else {
441  indMax[iv]=indFixed[nfixed];
442  if(indFixed[nfixed]>=GetNCutSteps(iv)){
443  indMax[iv]=0;
444  cout<<"AliMultiDimVector::FindLocalMaximum:ERROR! called fixed ind "<< indFixed[nfixed]<<" but "<<iv<<" var has only "<<GetNCutSteps(iv)<<" steps"<<endl;
445  }
446  nfixed++;
447  }
448  }
449  */
450  for (Int_t iv=0;iv<fNVariables;iv++)indMax[iv]=0;
451  for(Int_t i=0;i<nfixed;i++){
452  indMax[numFixed[i]]=indFixed[i];
453  }
454  //Get position of fixed vars
455  /*
456  Int_t fixedIndexes[nfixed];
457  Int_t iforfixed=0;
458  for (Int_t iv=0;iv<fNVariables;iv++){
459  if(!isFree[iv]){
460  fixedIndexes[iforfixed]=iv;
461  iforfixed++;
462  }
463  }
464  */
465  TArrayF vett;
466  vett.Set(nelem);
467 
468  ULong64_t first=fNTotCells/fNPtBins*ptbin;
469  ULong64_t last=first+fNTotCells/fNPtBins;
470  Int_t dummyptbin;
471 
472  maxValue=fVett[GetGlobalAddressFromIndices(indMax,ptbin)];
473  Int_t tmpInd[fNVariables];
474 
475  //loop on multidimvector global addresses
476  for(ULong64_t iga=first;iga<last;iga++){
477  GetIndicesFromGlobalAddress(iga,tmpInd,dummyptbin);
478  Bool_t goodCell=kTRUE;
479  for(Int_t ifix=0;ifix<nfixed&&goodCell;ifix++){
480  // if(indFixed[ifix]!=indMax[fixedIndexes[ifix]])goodCell=kFALSE;
481  if(indFixed[ifix]!=tmpInd[numFixed[ifix]])goodCell=kFALSE;
482  }
483  if(goodCell){
484  if(fVett[iga]>maxValue){
485  maxValue=fVett[iga];
486  // GetIndicesFromGlobalAddress(iga,indMax,dummyptbin);
487  for(Int_t inv=0;inv<fNVariables;inv++)indMax[inv]=tmpInd[inv];
488  }
489  }
490  }
491 
492  return indMax;
493 }
494 
495 //_____________________________________________________________________________
496 TH2F* AliMultiDimVector::Project(Int_t firstVar, Int_t secondVar, const Int_t* fixedVars, Int_t ptbin, Float_t norm){
497  // Project the AliMultiDimVector on a 2D histogram
498 
499  TString hisName=Form("hproj%s%dv%d",GetName(),secondVar,firstVar);
500  TString hisTit=Form("%s vs. %s",fAxisTitles[secondVar].Data(),fAxisTitles[firstVar].Data());
501  TH2F* h2=new TH2F(hisName.Data(),hisTit.Data(),fNCutSteps[firstVar],fMinLimits[firstVar],fMaxLimits[firstVar],fNCutSteps[secondVar],fMinLimits[secondVar],fMaxLimits[secondVar]);
502 
503  Int_t index[fgkMaxNVariables];
504  for(Int_t i=0;i<fNVariables;i++){
505  index[i]=fixedVars[i];
506  }
507 
508  for(Int_t i=0;i<fNCutSteps[firstVar];i++){
509  for(Int_t j=0;j<fNCutSteps[secondVar];j++){
510  index[firstVar]=i;
511  index[secondVar]=j;
512  Float_t cont=GetElement(index,ptbin)/norm;
513  Int_t bin1=i+1;
514  if(!fGreaterThan[firstVar]) bin1=fNCutSteps[firstVar]-i;
515  Int_t bin2=j+1;
516  if(!fGreaterThan[secondVar]) bin2=fNCutSteps[secondVar]-j;
517  h2->SetBinContent(bin1,bin2,cont);
518  }
519  }
520  return h2;
521 }
522 //_____________________________________________________________________________
523 void AliMultiDimVector::GetIntegrationLimits(Int_t iVar, Int_t iCell, Int_t& minbin, Int_t& maxbin) const {
524  // computes bin limits for integrating the AliMultiDimVector
525  minbin=0;
526  maxbin=0;
527  if(iVar<fNVariables){
528  minbin=iCell;
529  maxbin=fNCutSteps[iVar]-1;
530  }
531 }
532 //_____________________________________________________________________________
533 void AliMultiDimVector::GetFillRange(Int_t iVar, Int_t iCell, Int_t& minbin, Int_t& maxbin) const {
534  // computes range of cells passing the cuts for FillAndIntegrate
535  minbin=0;
536  maxbin=0;
537  if(iVar<fNVariables){
538  minbin=0; // bin 0 corresponds to loose cuts
539  maxbin=iCell;
540  }
541 }
542 //_____________________________________________________________________________
544  // integrates the matrix
545  if(fIsIntegrated){
546  AliError("MultiDimVector already integrated");
547  return;
548  }
549  TArrayF integral(fNTotCells);
550  for(ULong64_t i=0;i<fNTotCells;i++) integral[i]=CountsAboveCell(i);
551  for(ULong64_t i=0;i<fNTotCells;i++) fVett[i]= integral[i];
552  fIsIntegrated=kTRUE;
553 }//_____________________________________________________________________________
554 ULong64_t* AliMultiDimVector::GetGlobalAddressesAboveCuts(const Float_t *values, Int_t ptbin, Int_t& nVals) const{
555  // fills an array with global addresses of cells passing the cuts
556 
557  Int_t ind[fgkMaxNVariables];
558  Bool_t retcode=GetIndicesFromValues(values,ind);
559  if(!retcode){
560  nVals=0;
561  return 0x0;
562  }
563  for(Int_t i=fNVariables; i<fgkMaxNVariables; i++) ind[i]=0;
564  Int_t mink[fgkMaxNVariables];
565  Int_t maxk[fgkMaxNVariables];
566  Int_t size=1;
567  for(Int_t i=0;i<fgkMaxNVariables;i++){
568  GetFillRange(i,ind[i],mink[i],maxk[i]);
569  size*=(maxk[i]-mink[i]+1);
570  }
571  ULong64_t* indexes=new ULong64_t[size];
572  nVals=0;
573  for(Int_t k0=mink[0]; k0<=maxk[0]; k0++){
574  for(Int_t k1=mink[1]; k1<=maxk[1]; k1++){
575  for(Int_t k2=mink[2]; k2<=maxk[2]; k2++){
576  for(Int_t k3=mink[3]; k3<=maxk[3]; k3++){
577  for(Int_t k4=mink[4]; k4<=maxk[4]; k4++){
578  for(Int_t k5=mink[5]; k5<=maxk[5]; k5++){
579  for(Int_t k6=mink[6]; k6<=maxk[6]; k6++){
580  for(Int_t k7=mink[7]; k7<=maxk[7]; k7++){
581  for(Int_t k8=mink[8]; k8<=maxk[8]; k8++){
582  for(Int_t k9=mink[9]; k9<=maxk[9]; k9++){
583  Int_t currentBin[fgkMaxNVariables]={k0,k1,k2,k3,k4,k5,k6,k7,k8,k9};
584  indexes[nVals++]=GetGlobalAddressFromIndices(currentBin,ptbin);
585  }
586  }
587  }
588  }
589  }
590  }
591  }
592  }
593  }
594  }
595  return indexes;
596 }
597 //_____________________________________________________________________________
598 Float_t AliMultiDimVector::CountsAboveCell(ULong64_t globadd) const{
599  // integrates the counts of cells above cell with address globadd
600  Int_t ind[fgkMaxNVariables];
601  Int_t ptbin;
602  GetIndicesFromGlobalAddress(globadd,ind,ptbin);
603  for(Int_t i=fNVariables; i<fgkMaxNVariables; i++) ind[i]=0;
604  Int_t mink[fgkMaxNVariables];
605  Int_t maxk[fgkMaxNVariables];
606  for(Int_t i=0;i<fgkMaxNVariables;i++){
607  GetIntegrationLimits(i,ind[i],mink[i],maxk[i]);
608  }
609  Float_t sumcont=0.;
610  for(Int_t k0=mink[0]; k0<=maxk[0]; k0++){
611  for(Int_t k1=mink[1]; k1<=maxk[1]; k1++){
612  for(Int_t k2=mink[2]; k2<=maxk[2]; k2++){
613  for(Int_t k3=mink[3]; k3<=maxk[3]; k3++){
614  for(Int_t k4=mink[4]; k4<=maxk[4]; k4++){
615  for(Int_t k5=mink[5]; k5<=maxk[5]; k5++){
616  for(Int_t k6=mink[6]; k6<=maxk[6]; k6++){
617  for(Int_t k7=mink[7]; k7<=maxk[7]; k7++){
618  for(Int_t k8=mink[8]; k8<=maxk[8]; k8++){
619  for(Int_t k9=mink[9]; k9<=maxk[9]; k9++){
620  Int_t currentBin[fgkMaxNVariables]={k0,k1,k2,k3,k4,k5,k6,k7,k8,k9};
621  sumcont+=GetElement(currentBin,ptbin);
622  }
623  }
624  }
625  }
626  }
627  }
628  }
629  }
630  }
631  }
632  return sumcont;
633 }
634 //_____________________________________________________________________________
635 void AliMultiDimVector::Fill(Float_t* values, Int_t ptbin){
636  // fills the cells of AliMultiDimVector corresponding to values
637  if(fIsIntegrated){
638  AliError("MultiDimVector already integrated -- Use FillAndIntegrate");
639  return;
640  }
641  Int_t ind[fgkMaxNVariables];
642  Bool_t retcode=GetIndicesFromValues(values,ind);
643  for(Int_t i=fNVariables; i<fgkMaxNVariables; i++) ind[i]=0;
644  if(retcode) IncrementElement(ind,ptbin);
645 }
646 //_____________________________________________________________________________
647 void AliMultiDimVector::FillAndIntegrate(Float_t* values, Int_t ptbin){
648  // fills the cells of AliMultiDimVector passing the cuts
649  // The number of nested loops must match fgkMaxNVariables!!!!
650  fIsIntegrated=kTRUE;
651  Int_t ind[fgkMaxNVariables];
652  Bool_t retcode=GetIndicesFromValues(values,ind);
653  if(!retcode) return;
654  for(Int_t i=fNVariables; i<fgkMaxNVariables; i++) ind[i]=0;
655  Int_t mink[fgkMaxNVariables];
656  Int_t maxk[fgkMaxNVariables];
657  for(Int_t i=0;i<fgkMaxNVariables;i++){
658  GetFillRange(i,ind[i],mink[i],maxk[i]);
659  }
660  for(Int_t k0=mink[0]; k0<=maxk[0]; k0++){
661  for(Int_t k1=mink[1]; k1<=maxk[1]; k1++){
662  for(Int_t k2=mink[2]; k2<=maxk[2]; k2++){
663  for(Int_t k3=mink[3]; k3<=maxk[3]; k3++){
664  for(Int_t k4=mink[4]; k4<=maxk[4]; k4++){
665  for(Int_t k5=mink[5]; k5<=maxk[5]; k5++){
666  for(Int_t k6=mink[6]; k6<=maxk[6]; k6++){
667  for(Int_t k7=mink[7]; k7<=maxk[7]; k7++){
668  for(Int_t k8=mink[8]; k8<=maxk[8]; k8++){
669  for(Int_t k9=mink[9]; k9<=maxk[9]; k9++){
670  Int_t currentBin[fgkMaxNVariables]={k0,k1,k2,k3,k4,k5,k6,k7,k8,k9};
671  IncrementElement(currentBin,ptbin);
672  }
673  }
674  }
675  }
676  }
677  }
678  }
679  }
680  }
681  }
682 
683 }
684 //_____________________________________________________________________________
686  // Sets to zero elements for which mvBKG=0
687  for(ULong64_t i=0;i<fNTotCells;i++)
688  if(mvBKG->GetElement(i)<0.00000001) fVett.AddAt(0,i);
689 }
690 //_____________________________________________________________________________
691 AliMultiDimVector* AliMultiDimVector:: ShrinkPtBins(Int_t firstBin, Int_t lastBin){
692  // sums the elements of pt bins between firstBin and lastBin
693  if(firstBin<0 || lastBin>=fNPtBins || firstBin>=lastBin){
694  AliError("Bad numbers of Pt bins to be shrinked");
695  return 0;
696  }
697  Int_t nofcells[fgkMaxNVariables];
698  Float_t loosecuts[fgkMaxNVariables];
699  Float_t tightcuts[fgkMaxNVariables];
700  TString axisTitles[fgkMaxNVariables];
701  for(Int_t j=0;j<fgkMaxNVariables;j++) {
702  nofcells[j]=0;
703  loosecuts[j]=0.;
704  tightcuts[j]=0.;
705  axisTitles[j]="";
706  }
707  for(Int_t i=0;i<fNVariables;i++){
708  nofcells[i]=fNCutSteps[i];
709  if(fGreaterThan[i]){
710  loosecuts[i]=fMinLimits[i];
711  tightcuts[i]=fMaxLimits[i];
712  }else{
713  loosecuts[i]=fMaxLimits[i];
714  tightcuts[i]=fMinLimits[i];
715  }
716  axisTitles[i]=fAxisTitles[i];
717  }
718  Int_t newNptbins=fNPtBins-(lastBin-firstBin);
719  Float_t ptlimits[fgkMaxNPtBins+1];
720  for(Int_t ipt=0; ipt<=firstBin;ipt++) ptlimits[ipt]=fPtLimits[ipt];
721  for(Int_t ipt=firstBin+1; ipt<newNptbins+1;ipt++) ptlimits[ipt]=fPtLimits[ipt+(lastBin-firstBin)];
722  AliMultiDimVector* shrinkedMV=new AliMultiDimVector(GetName(),GetTitle(),newNptbins,ptlimits,fNVariables,nofcells,loosecuts,tightcuts,axisTitles);
723 
724  ULong64_t nOfPointsPerPtbin=fNTotCells/fNPtBins;
725  ULong64_t addressOld,addressNew;
726  Int_t npb,opb;
727  for(npb=0;npb<firstBin;npb++){
728  opb=npb;
729  for(ULong64_t k=0;k<nOfPointsPerPtbin;k++){
730  addressOld=opb+k*fNPtBins;
731  addressNew=npb+k*newNptbins;
732  shrinkedMV->SetElement(addressNew,fVett[addressOld]);
733  }
734  }
735  npb=firstBin;
736  for(ULong64_t k=0;k<nOfPointsPerPtbin;k++){
737  Float_t summedValue=0.;
738  for(opb=firstBin;opb<=lastBin;opb++){
739  addressOld=opb+k*fNPtBins;
740  summedValue+=fVett[addressOld];
741  }
742  addressNew=npb+k*newNptbins;
743  shrinkedMV->SetElement(addressNew,summedValue);
744  }
745  for(npb=firstBin+1;npb<newNptbins;npb++){
746  opb=npb+(lastBin-firstBin);
747  for(ULong64_t k=0;k<nOfPointsPerPtbin;k++){
748  addressOld=opb+k*fNPtBins;
749  addressNew=npb+k*newNptbins;
750  shrinkedMV->SetElement(addressNew,fVett[addressOld]);
751  }
752  }
753  return shrinkedMV;
754 }
755 //_____________________________________________________________________________
756 void AliMultiDimVector::SetNewLimits(Float_t* loose,Float_t* tight){
757  for(Int_t i=0;i<fNVariables;i++){
758  if(loose[i] < tight[i]){
759  fMinLimits[i]=loose[i];
760  fMaxLimits[i]=tight[i];
761  fGreaterThan[i]=kTRUE;
762  }else{
763  fMinLimits[i]=tight[i];
764  fMaxLimits[i]=loose[i];
765  fGreaterThan[i]=kFALSE;
766  }
767  }
768 }
769 //_____________________________________________________________________________
771  Float_t oldmin = fMinLimits[ivar];
772  fMinLimits[ivar] = fMaxLimits[ivar];
773  fMaxLimits[ivar] = oldmin;
774  if(fGreaterThan[ivar])fGreaterThan[ivar]=kFALSE;
775  else fGreaterThan[ivar]=kTRUE;
776 }
777 //_____________________________________________________________________________
779  //
780  printf("Number of Pt bins = %d\n",fNPtBins);
781  printf("Limits of Pt bins = ");
782  for(Int_t ib=0;ib<fNPtBins+1;ib++) printf("%6.2f ",fPtLimits[ib]);
783  printf("\n");
784  printf("Number of cut variables = %d\n",fNVariables);
785  for(Int_t iv=0;iv<fNVariables;iv++){
786  printf("- Variable %d: %s\n",iv,fAxisTitles[iv].Data());
787  printf(" Nsteps= %d Rage = %6.2f %6.2f\n",
788  fNCutSteps[iv],fMinLimits[iv],fMaxLimits[iv]);
789  }
790 }
ClassImp(AliAnalysisTaskTriggerRates) AliAnalysisTaskTriggerRates
static const Int_t fgkMaxNVariables
ULong64_t fNTotCells
array with n. of candidates vs. cuts
void FillAndIntegrate(Float_t *values, Int_t ptbin)
const char * title
Definition: MakeQAPdf.C:26
Bool_t fGreaterThan[fgkMaxNVariables]
higher cut value for each variable
void SuppressZeroBKGEffect(const AliMultiDimVector *BKG)
void LinearComb(const AliMultiDimVector *mv1, Float_t norm1, const AliMultiDimVector *mv2, Float_t norm2)
Float_t fMinLimits[fgkMaxNVariables]
n. of cut step for each variable
Int_t fNPtBins
n. of selection variables
void DivideBy(const AliMultiDimVector *mv)
Float_t fPtLimits[fgkMaxNPtBins+1]
n. of pt bins
Bool_t IsIntegrated() const
Bool_t fIsIntegrated
total number of matrix elements
Int_t GetNVariables() const
void SetElement(ULong64_t globadd, Float_t val)
Int_t fNVariables
max. n. of Pt bins
void CopyStructure(const AliMultiDimVector *mv)
Float_t GetCutStep(Int_t iVar) const
static const Int_t fgkMaxNPtBins
max. n. of selection variables
ULong64_t GetGlobalAddressFromValues(const Float_t *values, Int_t ptbin) const
Float_t GetPtLimit(Int_t i) const
void FindMaximum(Float_t &max_value, Int_t *ind, Int_t ptbin)
Bool_t GetCutValuesFromGlobalAddress(ULong64_t globadd, Float_t *cuts, Int_t &ptbin) const
Int_t GetNPtBins() const
void SetNewLimits(Float_t *loose, Float_t *tight)
void MultiplyBy(Float_t factor)
void IncrementElement(Int_t *ind, Int_t ptbin)
Bool_t GetGreaterThan(Int_t iVar) const
TH2F * Project(Int_t firstVar, Int_t secondVar, const Int_t *fixedVars, Int_t ptbin, Float_t norm=1.)
Float_t GetCutValue(Int_t iVar, Int_t iCell) const
void SwapLimits(Int_t ilim)
void Add(const AliMultiDimVector *mv)
ULong64_t * GetGlobalAddressesAboveCuts(const Float_t *values, Float_t pt, Int_t &nVals) const
Float_t fMaxLimits[fgkMaxNVariables]
void Sum(const AliMultiDimVector *mv1, const AliMultiDimVector *mv2)
ULong64_t GetGlobalAddressFromIndices(const Int_t *ind, Int_t ptbin) const
void Multiply(const AliMultiDimVector *mv, Float_t factor)
void Divide(const AliMultiDimVector *mv1, const AliMultiDimVector *mv2)
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
Float_t GetMaxLimit(Int_t iVar) const
ULong64_t GetNTotCells() const
Int_t GetNCutSteps(Int_t iVar) const
void Fill(Float_t *values, Int_t ptbin)
Int_t * FindLocalMaximum(Float_t &maxValue, Int_t *numFixed, Int_t *indFixed, Int_t nfixed, Int_t ptbin)
AliMultiDimVector & operator=(const AliMultiDimVector &mv)
Bool_t GetIndicesFromValues(const Float_t *values, Int_t *ind) const
AliMultiDimVector * ShrinkPtBins(Int_t firstBin, Int_t lastBin)
TString fAxisTitles[fgkMaxNVariables]
sign of the cut (> or <)
TString GetAxisTitle(Int_t iVar) const
Float_t CountsAboveCell(ULong64_t globadd) const
Int_t fNCutSteps[fgkMaxNVariables]
limits of pt bins
void GetFillRange(Int_t iVar, Int_t iCell, Int_t &minbin, Int_t &maxbin) const
Float_t GetMinLimit(Int_t iVar) const
void GetIntegrationLimits(Int_t iVar, Int_t iCell, Int_t &minbin, Int_t &maxbin) const
Bool_t GetIndicesFromGlobalAddress(ULong64_t globadd, Int_t *ind, Int_t &ptbin) const
Int_t nptbins
Float_t GetElement(ULong64_t globadd) const
TString prod[]
total number of productions
TArrayF fVett
titles for variables