AliPhysics  vAN-20150822 (d56cf94)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
AliSignificanceCalculator.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 calculate statistical //
21 // significance from AliMultiVeector objects with signal and //
22 // background counts vs. cut values //
23 // Origin: Francesco Prino (prino@to.infn.it) //
24 // //
26 
27 #include "AliMultiDimVector.h"
29 #include "TMath.h"
30 #include "AliLog.h"
31 
35 
36 //___________________________________________________________________________
38 fSignal(0),
39 fErrSquareSignal(0),
40 fBackground(0),
41 fErrSquareBackground(0),
42 fSignificance(0),
43 fErrSignificance(0),
44 fNormSig(1.),
45 fNormBkg(1.)
46 {
47  // default constructor
50 }
51 //___________________________________________________________________________
53 fSignal(sig),
54 fErrSquareSignal(0),
55 fBackground(bkg),
56 fErrSquareBackground(0),
57 fSignificance(0),
58 fErrSignificance(0),
59 fNormSig(normsig),
60 fNormBkg(normbkg)
61 {
62  // standard constructor
64 }
65 //___________________________________________________________________________
67 fSignal(sig),
68 fErrSquareSignal(err2sig),
69 fBackground(bkg),
70 fErrSquareBackground(err2bkg),
71 fSignificance(0),
72 fErrSignificance(0),
73 fNormSig(normsig),
74 fNormBkg(normbkg)
75 {
76  // standard constructor
78 }
79 //___________________________________________________________________________
81  // destructor
82  if(fSignal) delete fSignal;
83  if(fBackground) delete fBackground;
84  if(fSignificance) delete fSignificance;
86 }
87 //___________________________________________________________________________
89  // checks AliMultiDimVector dimension and normalization
90  if(fSignal==0 || fBackground==0) return kFALSE;
91  if(fNormSig==0. || fNormBkg==0.) return kFALSE;
92  if(fSignal->GetNTotCells() != fBackground->GetNTotCells()) return kFALSE;
93  return kTRUE;
94 }
95 //___________________________________________________________________________
97  // calculates significance and its error
98  if(!Check()) AliFatal("Signal and Background AliMultiDimVector dimensions do not match!");
99 
100  if(fSignificance) delete fSignificance;
106 
107  for(ULong64_t i=0;i<fSignal->GetNTotCells();i++) {
108  if(fSignal->GetElement(i)!=-1 && fBackground->GetElement(i)!=-1){
109  Float_t s=fSignal->GetElement(i)*fNormSig;
110  Float_t b=fBackground->GetElement(i)*fNormBkg;
111  Float_t signif=0.;
112  Float_t errsig=0.;
113  if((s+b)>0){
114  signif=s/TMath::Sqrt(s+b);
115  Float_t errs,errb;
116  if(fErrSquareSignal) errs=TMath::Sqrt(fErrSquareSignal->GetElement(i))*fNormSig;
117  else errs=TMath::Sqrt(fSignal->GetElement(i))*fNormSig; // Poisson statistics
119  else errb=TMath::Sqrt(fBackground->GetElement(i))*fNormBkg; // Poisson
120  Float_t dsigds=(s+2*b)/2./(s+b)/TMath::Sqrt(s+b);
121  Float_t dsigdb=-s/2./(s+b)/TMath::Sqrt(s+b);
122  errsig=TMath::Sqrt(dsigds*dsigds*errs*errs+dsigdb*dsigdb*errb*errb);
123  }
124  fSignificance->SetElement(i,signif);
125  fErrSignificance->SetElement(i,errsig);
126  }
127  }
128  fSignificance->SetNameTitle("Significance","Significance");
129  fErrSignificance->SetNameTitle("ErrorOnSignificance","ErrorOnSignificance");
130 }
131 //___________________________________________________________________________
133  // calculates purity
134  if(!Check()) AliFatal("Signal and Background AliMultiDimVector dimensions do not match!");
135 
136  AliMultiDimVector* purity=new AliMultiDimVector();
137  purity->CopyStructure(fSignal);
138  for(ULong64_t i=0;i<fSignal->GetNTotCells();i++) {
139  if(fSignal->GetElement(i)!=-1 && fBackground->GetElement(i)!=-1){
140  Float_t s=fSignal->GetElement(i)*fNormSig;
141  Float_t b=fBackground->GetElement(i)*fNormBkg;
142  Float_t pur=0.;
143  if((s+b)>0) pur=s/(s+b);
144  purity->SetElement(i,pur);
145  }
146  }
147  purity->SetNameTitle("Purity","Purity");
148  return purity;
149 }
150 //___________________________________________________________________________
152  // calculates error on purity
153  if(!Check()) AliFatal("Signal and Background AliMultiDimVector dimensions do not match!");
154 
155  AliMultiDimVector* epurity=new AliMultiDimVector();
156  epurity->CopyStructure(fSignal);
157  for(ULong64_t i=0;i<fSignal->GetNTotCells();i++) {
158  if(fSignal->GetElement(i)!=-1 && fBackground->GetElement(i)!=-1){
159  Float_t s=fSignal->GetElement(i)*fNormSig;
160  Float_t b=fBackground->GetElement(i)*fNormBkg;
161  Float_t epur=0.;
162  if((s+b)>0){
163  Float_t errs,errb;
164  if(fErrSquareSignal) errs=TMath::Sqrt(fErrSquareSignal->GetElement(i))*fNormSig;
165  else errs=TMath::Sqrt(fSignal->GetElement(i))*fNormSig; // Poisson statistics
167  else errb=TMath::Sqrt(fBackground->GetElement(i))*fNormBkg; // Poisson
168  Float_t dpurds=b/(s+b)/(s+b);
169  Float_t dpurdb=-s/(s+b)/(s+b);
170  epur=TMath::Sqrt(dpurds*dpurds*errs*errs+dpurdb*dpurdb*errb*errb);
171  }
172  epurity->SetElement(i,epur);
173  }
174  }
175  epurity->SetNameTitle("ErrorOnPurity","ErrorOnPurity");
176  return epurity;
177 }
178 //___________________________________________________________________________
180  // Signal over Background
181  if(!Check()) AliFatal("Signal and Background AliMultiDimVector dimensions do not match!");
182 
184  sob->CopyStructure(fSignal);
185  for(ULong64_t i=0;i<fSignal->GetNTotCells();i++) {
186  if(fSignal->GetElement(i)!=-1 && fBackground->GetElement(i)!=-1){
187  Float_t s=fSignal->GetElement(i)*fNormSig;
188  Float_t b=fBackground->GetElement(i)*fNormBkg;
189  Float_t soverb=0.;
190  if(b>0) soverb=s/b;
191  sob->SetElement(i,soverb);
192  }
193  }
194  sob->SetNameTitle("SoverB","SoverB");
195  return sob;
196 }
197 //___________________________________________________________________________
199  // Error on Signal over Background
200  if(!Check()) AliFatal("Signal and Background AliMultiDimVector dimensions do not match!");
201 
203  esob->CopyStructure(fSignal);
204  for(ULong64_t i=0;i<fSignal->GetNTotCells();i++) {
205  if(fSignal->GetElement(i)!=-1 && fBackground->GetElement(i)!=-1){
206  Float_t s=fSignal->GetElement(i)*fNormSig;
207  Float_t b=fBackground->GetElement(i)*fNormBkg;
208  Float_t esoverb=0.;
209  if(b>0){
210  Float_t soverb=s/b;
211  Float_t errs,errb;
212  if(fErrSquareSignal) errs=TMath::Sqrt(fErrSquareSignal->GetElement(i))*fNormSig;
213  else errs=TMath::Sqrt(fSignal->GetElement(i))*fNormSig; // Poisson statistics
215  else errb=TMath::Sqrt(fBackground->GetElement(i))*fNormBkg; // Poisson
216  esoverb=soverb*TMath::Sqrt(errs*errs/s/s+errb*errb/b/b);
217  }
218  esob->SetElement(i,esoverb);
219  }
220  }
221  esob->SetNameTitle("ErrorOnSoverB","ErrorOnSoverB");
222  return esob;
223 }
ClassImp(AliAnalysisTaskTriggerRates) AliAnalysisTaskTriggerRates
AliMultiDimVector * fBackground
matrix with err^2 for signal
AliMultiDimVector * fSignificance
matrix with err^2 for background
AliMultiDimVector * CalculatePurity() const
AliMultiDimVector * fErrSquareBackground
background matrix
AliMultiDimVector * CalculatePurityError() const
void SetElement(ULong64_t globadd, Float_t val)
void CopyStructure(const AliMultiDimVector *mv)
AliMultiDimVector * CalculateSOverBError() const
AliMultiDimVector * fErrSquareSignal
signal matrix
Float_t fNormBkg
signal normalization
AliMultiDimVector * CalculateSOverB() const
ULong64_t GetNTotCells() const
AliMultiDimVector * fErrSignificance
significance matrix
Float_t fNormSig
matrix with error on significance
Float_t GetElement(ULong64_t globadd) const