Coverity
[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);
57291f02 32 AliMultiDimVector& operator=(const AliMultiDimVector &mv);
2350a1d9 33 AliMultiDimVector(const char *name, const char *title, const Int_t nptbins,
34 const Float_t* ptlimits, const Int_t npars, const Int_t *nofcells, const Float_t *loosecuts, const Float_t *tightcuts, const TString *axisTitles);
ac7636a0 35 virtual ~AliMultiDimVector(){};
36
37 ULong64_t GetNTotCells() const {return fNTotCells;}
38 Int_t GetNVariables() const {return fNVariables;}
39 Int_t GetNPtBins() const {return fNPtBins;}
40 Int_t GetNCutSteps(Int_t iVar) const {return fNCutSteps[iVar];}
41 Float_t GetMinLimit(Int_t iVar) const {return fMinLimits[iVar];}
42 Float_t GetMaxLimit(Int_t iVar) const {return fMaxLimits[iVar];}
43 Float_t GetCutStep(Int_t iVar) const {return (fMaxLimits[iVar]-fMinLimits[iVar])/(Float_t)fNCutSteps[iVar];}
44 TString GetAxisTitle(Int_t iVar) const {return fAxisTitles[iVar];}
45 Bool_t IsIntegrated() const {return fIsIntegrated;}
46
47 void CopyStructure(const AliMultiDimVector* mv);
48
49 Float_t GetCutValue(Int_t iVar, Int_t iCell) const{
50 if(fGreaterThan[iVar]) return fMinLimits[iVar]+(Float_t)iCell*GetCutStep(iVar);
51 else return fMaxLimits[iVar]-(Float_t)iCell*GetCutStep(iVar);
52 }
53 Float_t GetElement(ULong64_t globadd) const {return fVett[globadd];}
2350a1d9 54 Float_t GetElement(const Int_t *ind, Int_t ptbin) const {
ac7636a0 55 ULong64_t elem=GetGlobalAddressFromIndices(ind,ptbin);
56 return fVett[elem];
57 }
bac542b0 58 Float_t GetPtLimit(Int_t i) const{return fPtLimits[i];}
59 Int_t GetPtBin(const Float_t pt) const{
60 Int_t theBin=TMath::BinarySearch(fNPtBins+1,fPtLimits,pt);
61 if(theBin>=fNPtBins) theBin=-1;
62 return theBin;
63 }
ac7636a0 64 void GetEntireMultiDimVector(Float_t *vett) const {
65 for(ULong64_t i=0; i<fNTotCells; i++) vett[i]=fVett[i];
66 }
67
68 Bool_t GetIndicesFromGlobalAddress(ULong64_t globadd, Int_t *ind, Int_t &ptbin) const;
2350a1d9 69 ULong64_t GetGlobalAddressFromIndices(const Int_t *ind, Int_t ptbin) const;
70 Bool_t GetIndicesFromValues(const Float_t *values, Int_t *ind) const;
71 ULong64_t GetGlobalAddressFromValues(const Float_t *values, Int_t ptbin) const;
ac7636a0 72 Bool_t GetCutValuesFromGlobalAddress(ULong64_t globadd, Float_t *cuts, Int_t &ptbin) const;
bac542b0 73
2350a1d9 74 ULong64_t* GetGlobalAddressesAboveCuts(const Float_t *values, Float_t pt, Int_t& nVals) const{
bac542b0 75 Int_t theBin=GetPtBin(pt);
76 if(theBin>=0) return GetGlobalAddressesAboveCuts(values,theBin,nVals);
77 else return 0x0;
78 }
2350a1d9 79 ULong64_t* GetGlobalAddressesAboveCuts(const Float_t *values, Int_t ptbin, Int_t& nVals) const;
3aa6ce53 80 Bool_t GetGreaterThan(Int_t iVar) const {return fGreaterThan[iVar];}
ac7636a0 81
82 void SetElement(ULong64_t globadd,Float_t val) {fVett[globadd]=val;}
83 void SetElement(Int_t *ind, Int_t ptbin, Float_t val){
84 ULong64_t elem=GetGlobalAddressFromIndices(ind,ptbin);
3aa6ce53 85 if(elem>fNTotCells){
86 printf("SetElement: indices %d %d %d ptbin %d elem %d\n",ind[0],ind[1],ind[2],ptbin,(Int_t)elem);
87 }
ac7636a0 88 fVett[elem]=val;
89 }
90 void IncrementElement(Int_t *ind, Int_t ptbin){
91 SetElement(ind,ptbin,GetElement(ind,ptbin)+1);
92 }
93 void IncrementElement(ULong64_t globadd){
94 SetElement(globadd,GetElement(globadd)+1.);
95 }
96
97 void Fill(Float_t* values, Int_t ptbin);
98 void FillAndIntegrate(Float_t* values, Int_t ptbin);
99 void Integrate();
100
101 void Reset(){
102 for(ULong64_t i=0; i<fNTotCells; i++) fVett[i]=0.;
103 }
104 void MultiplyBy(Float_t factor);
2350a1d9 105 void Multiply(const AliMultiDimVector* mv,Float_t factor);
106 void Multiply(const AliMultiDimVector* mv1, const AliMultiDimVector* mv2);
107 void Add(const AliMultiDimVector* mv);
108 void Sum(const AliMultiDimVector* mv1, const AliMultiDimVector* mv2);
109 void LinearComb(const AliMultiDimVector* mv1, Float_t norm1, const AliMultiDimVector* mv2, Float_t norm2);
110 void DivideBy(const AliMultiDimVector* mv);
111 void Divide(const AliMultiDimVector* mv1, const AliMultiDimVector* mv2);
ac7636a0 112 void Sqrt();
2350a1d9 113 void Sqrt(const AliMultiDimVector* mv);
ac7636a0 114
115 void FindMaximum(Float_t& max_value, Int_t *ind, Int_t ptbin);
0adeb69c 116 Int_t* FindLocalMaximum(Float_t& maxValue, Int_t *numFixed,Int_t* indFixed, Int_t nfixed,Int_t ptbin);
ac7636a0 117
2350a1d9 118 TH2F* Project(Int_t firstVar, Int_t secondVar, const Int_t* fixedVars, Int_t ptbin, Float_t norm=1.);
ac7636a0 119
2350a1d9 120 void SuppressZeroBKGEffect(const AliMultiDimVector* BKG);
bac542b0 121 AliMultiDimVector* ShrinkPtBins(Int_t firstBin, Int_t lastBin);
3aa6ce53 122
123 void SetNewLimits(Float_t* loose,Float_t* tight);
124 void SwapLimits(Int_t ilim);
125
126
bac542b0 127 void PrintStatus();
ac7636a0 128
129 protected:
130 void GetIntegrationLimits(Int_t iVar, Int_t iCell, Int_t& minbin, Int_t& maxbin) const;
131 void GetFillRange(Int_t iVar, Int_t iCell, Int_t& minbin, Int_t& maxbin) const;
ac7636a0 132 Float_t CountsAboveCell(ULong64_t globadd) const;
133
3aa6ce53 134 //void SetMinLimits(Int_t nvar, Float_t* minlim);
135 //void SetMaxLimits(Int_t nvar, Float_t* maxlim);
ac7636a0 136 private:
137 static const Int_t fgkMaxNVariables=10; // max. n. of selection variables
bac542b0 138 static const Int_t fgkMaxNPtBins=10; // max. n. of Pt bins
ac7636a0 139
140 Int_t fNVariables; // n. of selection variables
141 Int_t fNPtBins; // n. of pt bins
bac542b0 142 Float_t fPtLimits[fgkMaxNPtBins+1]; // limits of pt bins
ac7636a0 143 Int_t fNCutSteps[fgkMaxNVariables]; // n. of cut step for each variable
144 Float_t fMinLimits[fgkMaxNVariables]; // lower cut value for each variable
145 Float_t fMaxLimits[fgkMaxNVariables]; // higher cut value for each variable
146 Bool_t fGreaterThan[fgkMaxNVariables];// sign of the cut (> or <)
147 TString fAxisTitles[fgkMaxNVariables]; // titles for variables
148 TArrayF fVett; // array with n. of candidates vs. cuts
149 ULong64_t fNTotCells; // total number of matrix elements
150 Bool_t fIsIntegrated; // flag for integrated matrix
151
bac542b0 152 ClassDef(AliMultiDimVector,2); // a multi-dimensional vector class
ac7636a0 153
154};
155
156#endif