Update (Andrea)
[u/mrichter/AliRoot.git] / PWG3 / vertexingHF / AliMultiDimVector.h
CommitLineData
ac7636a0 1#ifndef ALIMULTIDIMVECTOR_H
2#define ALIMULTIDIMVECTOR_H
3
4/* Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. *
5 * See cxx source for full Copyright notice */
6
7b45817b 7/* $Id$ */
ac7636a0 8
9///////////////////////////////////////////////////////////////////
10// //
11// Class to store number of signal and background candidates //
12// in bins of cut variables //
13// Origin: Elena Bruna (bruna@to.infn.it) //
14// Updated: Sergey Senyukov (senyukov@to.infn.it) //
3aa6ce53 15// Francesco Prino (prino@to.infn.it) //
16// Last Updated: Giacomo Ortona (ortona@to.infn.it) //
ac7636a0 17// //
18///////////////////////////////////////////////////////////////////
19
20#include "TArrayF.h"
21#include "TArrayI.h"
22#include "TNamed.h"
23#include "TH2.h"
bac542b0 24#include "TMath.h"
ac7636a0 25#include "TString.h"
26
27class AliMultiDimVector : public TNamed{
28
29 public:
30 AliMultiDimVector();
31 AliMultiDimVector(const AliMultiDimVector &mv);
2350a1d9 32 AliMultiDimVector(const char *name, const char *title, const Int_t nptbins,
33 const Float_t* ptlimits, const Int_t npars, const Int_t *nofcells, const Float_t *loosecuts, const Float_t *tightcuts, const TString *axisTitles);
ac7636a0 34 virtual ~AliMultiDimVector(){};
35
36 ULong64_t GetNTotCells() const {return fNTotCells;}
37 Int_t GetNVariables() const {return fNVariables;}
38 Int_t GetNPtBins() const {return fNPtBins;}
39 Int_t GetNCutSteps(Int_t iVar) const {return fNCutSteps[iVar];}
40 Float_t GetMinLimit(Int_t iVar) const {return fMinLimits[iVar];}
41 Float_t GetMaxLimit(Int_t iVar) const {return fMaxLimits[iVar];}
42 Float_t GetCutStep(Int_t iVar) const {return (fMaxLimits[iVar]-fMinLimits[iVar])/(Float_t)fNCutSteps[iVar];}
43 TString GetAxisTitle(Int_t iVar) const {return fAxisTitles[iVar];}
44 Bool_t IsIntegrated() const {return fIsIntegrated;}
45
46 void CopyStructure(const AliMultiDimVector* mv);
47
48 Float_t GetCutValue(Int_t iVar, Int_t iCell) const{
49 if(fGreaterThan[iVar]) return fMinLimits[iVar]+(Float_t)iCell*GetCutStep(iVar);
50 else return fMaxLimits[iVar]-(Float_t)iCell*GetCutStep(iVar);
51 }
52 Float_t GetElement(ULong64_t globadd) const {return fVett[globadd];}
2350a1d9 53 Float_t GetElement(const Int_t *ind, Int_t ptbin) const {
ac7636a0 54 ULong64_t elem=GetGlobalAddressFromIndices(ind,ptbin);
55 return fVett[elem];
56 }
bac542b0 57 Float_t GetPtLimit(Int_t i) const{return fPtLimits[i];}
58 Int_t GetPtBin(const Float_t pt) const{
59 Int_t theBin=TMath::BinarySearch(fNPtBins+1,fPtLimits,pt);
60 if(theBin>=fNPtBins) theBin=-1;
61 return theBin;
62 }
ac7636a0 63 void GetEntireMultiDimVector(Float_t *vett) const {
64 for(ULong64_t i=0; i<fNTotCells; i++) vett[i]=fVett[i];
65 }
66
67 Bool_t GetIndicesFromGlobalAddress(ULong64_t globadd, Int_t *ind, Int_t &ptbin) const;
2350a1d9 68 ULong64_t GetGlobalAddressFromIndices(const Int_t *ind, Int_t ptbin) const;
69 Bool_t GetIndicesFromValues(const Float_t *values, Int_t *ind) const;
70 ULong64_t GetGlobalAddressFromValues(const Float_t *values, Int_t ptbin) const;
ac7636a0 71 Bool_t GetCutValuesFromGlobalAddress(ULong64_t globadd, Float_t *cuts, Int_t &ptbin) const;
bac542b0 72
2350a1d9 73 ULong64_t* GetGlobalAddressesAboveCuts(const Float_t *values, Float_t pt, Int_t& nVals) const{
bac542b0 74 Int_t theBin=GetPtBin(pt);
75 if(theBin>=0) return GetGlobalAddressesAboveCuts(values,theBin,nVals);
76 else return 0x0;
77 }
2350a1d9 78 ULong64_t* GetGlobalAddressesAboveCuts(const Float_t *values, Int_t ptbin, Int_t& nVals) const;
3aa6ce53 79 Bool_t GetGreaterThan(Int_t iVar) const {return fGreaterThan[iVar];}
ac7636a0 80
81 void SetElement(ULong64_t globadd,Float_t val) {fVett[globadd]=val;}
82 void SetElement(Int_t *ind, Int_t ptbin, Float_t val){
83 ULong64_t elem=GetGlobalAddressFromIndices(ind,ptbin);
3aa6ce53 84 if(elem>fNTotCells){
85 printf("SetElement: indices %d %d %d ptbin %d elem %d\n",ind[0],ind[1],ind[2],ptbin,(Int_t)elem);
86 }
ac7636a0 87 fVett[elem]=val;
88 }
89 void IncrementElement(Int_t *ind, Int_t ptbin){
90 SetElement(ind,ptbin,GetElement(ind,ptbin)+1);
91 }
92 void IncrementElement(ULong64_t globadd){
93 SetElement(globadd,GetElement(globadd)+1.);
94 }
95
96 void Fill(Float_t* values, Int_t ptbin);
97 void FillAndIntegrate(Float_t* values, Int_t ptbin);
98 void Integrate();
99
100 void Reset(){
101 for(ULong64_t i=0; i<fNTotCells; i++) fVett[i]=0.;
102 }
103 void MultiplyBy(Float_t factor);
2350a1d9 104 void Multiply(const AliMultiDimVector* mv,Float_t factor);
105 void Multiply(const AliMultiDimVector* mv1, const AliMultiDimVector* mv2);
106 void Add(const AliMultiDimVector* mv);
107 void Sum(const AliMultiDimVector* mv1, const AliMultiDimVector* mv2);
108 void LinearComb(const AliMultiDimVector* mv1, Float_t norm1, const AliMultiDimVector* mv2, Float_t norm2);
109 void DivideBy(const AliMultiDimVector* mv);
110 void Divide(const AliMultiDimVector* mv1, const AliMultiDimVector* mv2);
ac7636a0 111 void Sqrt();
2350a1d9 112 void Sqrt(const AliMultiDimVector* mv);
ac7636a0 113
114 void FindMaximum(Float_t& max_value, Int_t *ind, Int_t ptbin);
0adeb69c 115 Int_t* FindLocalMaximum(Float_t& maxValue, Int_t *numFixed,Int_t* indFixed, Int_t nfixed,Int_t ptbin);
ac7636a0 116
2350a1d9 117 TH2F* Project(Int_t firstVar, Int_t secondVar, const Int_t* fixedVars, Int_t ptbin, Float_t norm=1.);
ac7636a0 118
2350a1d9 119 void SuppressZeroBKGEffect(const AliMultiDimVector* BKG);
bac542b0 120 AliMultiDimVector* ShrinkPtBins(Int_t firstBin, Int_t lastBin);
3aa6ce53 121
122 void SetNewLimits(Float_t* loose,Float_t* tight);
123 void SwapLimits(Int_t ilim);
124
125
bac542b0 126 void PrintStatus();
ac7636a0 127
128 protected:
129 void GetIntegrationLimits(Int_t iVar, Int_t iCell, Int_t& minbin, Int_t& maxbin) const;
130 void GetFillRange(Int_t iVar, Int_t iCell, Int_t& minbin, Int_t& maxbin) const;
ac7636a0 131 Float_t CountsAboveCell(ULong64_t globadd) const;
132
3aa6ce53 133 //void SetMinLimits(Int_t nvar, Float_t* minlim);
134 //void SetMaxLimits(Int_t nvar, Float_t* maxlim);
ac7636a0 135 private:
136 static const Int_t fgkMaxNVariables=10; // max. n. of selection variables
bac542b0 137 static const Int_t fgkMaxNPtBins=10; // max. n. of Pt bins
ac7636a0 138
139 Int_t fNVariables; // n. of selection variables
140 Int_t fNPtBins; // n. of pt bins
bac542b0 141 Float_t fPtLimits[fgkMaxNPtBins+1]; // limits of pt bins
ac7636a0 142 Int_t fNCutSteps[fgkMaxNVariables]; // n. of cut step for each variable
143 Float_t fMinLimits[fgkMaxNVariables]; // lower cut value for each variable
144 Float_t fMaxLimits[fgkMaxNVariables]; // higher cut value for each variable
145 Bool_t fGreaterThan[fgkMaxNVariables];// sign of the cut (> or <)
146 TString fAxisTitles[fgkMaxNVariables]; // titles for variables
147 TArrayF fVett; // array with n. of candidates vs. cuts
148 ULong64_t fNTotCells; // total number of matrix elements
149 Bool_t fIsIntegrated; // flag for integrated matrix
150
bac542b0 151 ClassDef(AliMultiDimVector,2); // a multi-dimensional vector class
ac7636a0 152
153};
154
155#endif