82 Log() << kERROR <<
"Cannot cal ROC curve etc, as in put mvaS and mvaB have differen #nbins or range "<<
Endl;
98 Log() << kERROR <<
"Cannot Rebin Histograms mvaS and mvaB, ROC values will be calculated without Rebin histograms."<<
Endl;
129 Int_t FillColor__S = c_SignalFill;
130 Int_t FillStyle__S = 1001;
131 Int_t LineColor__S = c_SignalLine;
132 Int_t LineWidth__S = 2;
136 Int_t FillColor__B = c_BackgroundFill;
137 Int_t FillStyle__B = 3554;
138 Int_t LineColor__B = c_BackgroundLine;
139 Int_t LineWidth__B = 2;
168 if (fSplS) {
delete fSplS; fSplS = 0; }
169 if (fSplB) {
delete fSplB; fSplB = 0; }
170 if (fSpleffBvsS) {
delete fSpleffBvsS; fSpleffBvsS = 0; }
171 if (fSplmvaCumS) {
delete fSplmvaCumS; fSplmvaCumS = 0; }
172 if (fSplmvaCumB) {
delete fSplmvaCumB; fSplmvaCumB = 0; }
173 if (fmvaScumul) {
delete fmvaScumul; }
174 if (fmvaBcumul) {
delete fmvaBcumul; }
175 if (effBvsS) {
delete effBvsS; }
176 if (rejBvsS) {
delete rejBvsS; }
177 if (inveffBvsS) {
delete inveffBvsS; }
189 Log() << kERROR <<
"I guess the mva distributions fed into ROCCalc were already normalized, therefore the calculated error on the efficiency will be incorrect !! " <<
Endl;
197 fmvaScumul->SetMinimum(0);
198 fmvaBcumul->SetMinimum(0);
203 if(effBvsS==0) effBvsS =
new TH1D(
"effBvsS",
"ROC-Curve", fNbins, 0, 1 );
204 effBvsS->SetXTitle(
"Signal eff" );
205 effBvsS->SetYTitle(
"Backgr eff" );
208 if(rejBvsS==0) rejBvsS =
new TH1D(
"rejBvsS",
"ROC-Curve", fNbins, 0, 1 );
209 rejBvsS->SetXTitle(
"Signal eff" );
210 rejBvsS->SetYTitle(
"Backgr rejection (1-eff)" );
213 if(inveffBvsS ==0) inveffBvsS =
new TH1D(
"invBeffvsSeff",
"ROC-Curve" , fNbins, 0, 1 );
214 inveffBvsS->SetXTitle(
"Signal eff" );
215 inveffBvsS->SetYTitle(
"Inverse backgr. eff (1/eff)" );
221 fSplmvaCumS =
new TSpline1(
"spline2_signal",
new TGraph( fmvaScumul ) );
222 fSplmvaCumB =
new TSpline1(
"spline2_background",
new TGraph( fmvaBcumul ) );
229 for (
UInt_t bini=1; bini<=fNbins; bini++) {
232 Double_t effS = effBvsS->GetBinCenter( bini );
236 if (fUseSplines) effB = fSplmvaCumB->Eval( cut );
237 else effB = fmvaBcumul->GetBinContent( fmvaBcumul->FindBin( cut ) );
240 effBvsS->SetBinContent( bini, effB );
241 rejBvsS->SetBinContent( bini, 1.0-effB );
243 inveffBvsS->SetBinContent( bini, 1.0/effB );
252 Double_t effS = 0., rejB = 0., effS_ = 0., rejB_ = 0.;
254 for (
Int_t bini=1; bini<=nbins; bini++) {
257 effS = (bini - 0.5)/
Float_t(nbins);
258 rejB = 1.0 - fSpleffBvsS->Eval( effS );
261 if ((effS - rejB)*(effS_ - rejB_) < 0)
break;
266 fSignalCut =
Root( 0.5*(effS + effS_) );
277 if (fSpleffBvsS == 0) this->GetROC();
281 for (
Int_t bini=1; bini<=nbins; bini++) {
284 effS = (bini - 0.5)/
Float_t(nbins);
285 effB = fSpleffBvsS->Eval( effS );
286 integral += (1.0 - effB);
300 Double_t effS=0., effB, effSOld=1., effBOld=0.;
302 if (fSpleffBvsS == 0) this->GetROC();
305 for (
Int_t bini=1; bini<=nbins; bini++) {
307 effS = (bini - 0.5)*step;
308 effB = fSpleffBvsS->Eval( effS );
311 if ((effB - effBref)*(effBOld - effBref) <= 0)
break;
317 effS = 0.5*(effS + effSOld);
320 if (fNevtS > 0) effSerr =
TMath::Sqrt( effS*(1.0 - effS)/fNevtS );
334 if (fUseSplines) retVal = fSplmvaCumS->Eval( theCut );
335 else retVal = fmvaScumul->GetBinContent( fmvaScumul->FindBin( theCut ) );
344 if (theCut-fXmin < eps) retVal = (fCutOrientation > 0) ? 1.0 : 0.0;
345 else if (fXmax-theCut < eps) retVal = (fCutOrientation > 0) ? 0.0 : 1.0;
357 Double_t fa = GetEffForRoot(
a ) - refValue;
358 Double_t fb = GetEffForRoot(
b ) - refValue;
360 Log() << kWARNING <<
"<ROCCalc::Root> initial interval w/o root: "
361 <<
"(a=" <<
a <<
", b=" <<
b <<
"),"
362 <<
" (Eff_a=" << GetEffForRoot(
a )
363 <<
", Eff_b=" << GetEffForRoot(
b ) <<
"), "
364 <<
"(fa=" << fa <<
", fb=" << fb <<
"), "
365 <<
"refValue = " << refValue <<
Endl;
372 for (
Int_t iter= 0; iter <= fMaxIter; iter++) {
373 if ((fb < 0 &&
fc < 0) || (fb > 0 &&
fc > 0)) {
384 fa = fb; fb =
fc;
fc = fa;
398 if (ac_equal) { p = 2 *
m *
s;
q = 1 -
s; }
401 p =
s * (2 *
m *
q * (
q -
r) - (
b -
a) * (
r - 1));
402 q = (
q - 1) * (
r - 1) * (
s - 1);
410 if (2 * p < (min1 < min2 ? min1 : min2)) {
414 else {
d =
m;
e =
m; }
420 else b += (
m > 0 ? +tol : -tol);
422 fb = GetEffForRoot(
b ) - refValue;
427 Log() << kWARNING <<
"<ROCCalc::Root> maximum iterations (" << fMaxIter
428 <<
") reached before convergence" <<
Endl;
437 if (fnStot!=nStot || fnBtot!=nBtot || !fSignificance) {
438 GetSignificance(nStot, nBtot);
448 if (fnStot==nStot && fnBtot==nBtot && !fSignificance)
return fSignificance;
449 fnStot=nStot; fnBtot=nBtot;
451 fSignificance = (
TH1*) fmvaScumul->
Clone(
"Significance"); fSignificance->SetTitle(
"Significance");
452 fSignificance->Reset(); fSignificance->SetFillStyle(0);
453 fSignificance->SetXTitle(
"mva cut value");
454 fSignificance->SetYTitle(
"Stat. significance S/Sqrt(S+B)");
455 fSignificance->SetLineColor(2);
456 fSignificance->SetLineWidth(5);
458 fPurity = (
TH1*) fmvaScumul->
Clone(
"Purity"); fPurity->SetTitle(
"Purity");
459 fPurity->Reset(); fPurity->SetFillStyle(0);
460 fPurity->SetXTitle(
"mva cut value");
461 fPurity->SetYTitle(
"Purity: S/(S+B)");
462 fPurity->SetLineColor(3);
463 fPurity->SetLineWidth(5);
466 for (
Int_t i=1; i<=fSignificance->GetNbinsX(); i++) {
467 Double_t S = fmvaScumul->GetBinContent( i ) * nStot;
468 Double_t B = fmvaBcumul->GetBinContent( i ) * nBtot;
481 cout <<
"S="<<
S<<
" B="<<
B<<
" purity="<<purity<< endl;
482 fPurity->SetBinContent( i, purity );
483 fSignificance->SetBinContent( i, sig );
500 return fSignificance;
static struct mg_connection * fc(struct mg_context *ctx)
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
const char * GetTitle() const
Returns title of object.
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
A Graph is a graphics object made of two arrays X and Y with npoints each.
1-D histogram with a double per channel (see TH1 documentation)}
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
virtual Double_t GetMean(Int_t axis=1) const
For axis = 1,2 or 3 returns the mean value of the histogram along X,Y or Z axis.
virtual void SetXTitle(const char *title)
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
virtual Double_t GetMaximum(Double_t maxval=FLT_MAX) const
Return maximum value smaller than maxval of bins in the range, unless the value has been overridden b...
virtual Int_t GetNbinsX() const
virtual void SetMaximum(Double_t maximum=-1111)
virtual TH1 * RebinX(Int_t ngroup=2, const char *newname="")
virtual void SetYTitle(const char *title)
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
virtual Double_t GetSumOfWeights() const
Return the sum of weights excluding under/overflows.
ostringstream derivative to redirect and format output
Double_t Root(Double_t)
Root finding using Brents algorithm; taken from CERNLIB function RZERO.
Double_t GetROCIntegral()
code to compute the area under the ROC ( rej-vs-eff ) curve
TH1 * GetPurity(Int_t nStot, Int_t nBtot)
Double_t GetEffSForEffBof(Double_t effBref, Double_t &effSerr)
get the signal efficiency for a particular background efficiency that will be the value of the effici...
ROCCalc(TH1 *mvaS, TH1 *mvaB)
TH1 * GetSignificance(Int_t nStot, Int_t nBtot)
MsgLogger & Log() const
message logger
TH1D * GetROC()
get the ROC curve
void ApplySignalAndBackgroundStyle(TH1 *sig, TH1 *bkg, TH1 *any=0)
Double_t GetEffForRoot(Double_t theCut)
returns efficiency as function of cut
Linear interpolation of TGraph.
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
RooArgSet S(const RooAbsArg &v1)
static constexpr double s
Abstract ClassifierFactory template that handles arbitrary types.
MsgLogger & Endl(MsgLogger &ml)
Short_t Max(Short_t a, Short_t b)
Double_t Sqrt(Double_t x)