26 #ifndef ROOT_TMVA_Tools
29 #ifndef ROOT_TMVA_ROCCalc
32 #ifndef ROOT_TMVA_Config
35 #ifndef ROOT_TMVA_Event
38 #ifndef ROOT_TMVA_Version
44 #ifndef ROOT_TMVA_MsgLogger
86 Log() <<
kFATAL <<
" Cannot cal ROC curve etc, as in put mvaS and mvaB have differen #nbins or range "<<
Endl;
127 Int_t FillStyle__S = 1001;
129 Int_t LineWidth__S = 2;
134 Int_t FillStyle__B = 3554;
136 Int_t LineWidth__B = 2;
166 if (fSplS) {
delete fSplS; fSplS = 0; }
167 if (fSplB) {
delete fSplB; fSplB = 0; }
168 if (fSpleffBvsS) {
delete fSpleffBvsS; fSpleffBvsS = 0; }
169 if (fSplmvaCumS) {
delete fSplmvaCumS; fSplmvaCumS = 0; }
170 if (fSplmvaCumB) {
delete fSplmvaCumB; fSplmvaCumB = 0; }
171 if (fmvaScumul) {
delete fmvaScumul; }
172 if (fmvaBcumul) {
delete fmvaBcumul; }
185 Log() <<
kWARNING <<
"I guess the mva distributions fed into ROCCalc were already normalized, therefore the calculated error on the efficiency will be incorrect !! " <<
Endl;
192 fmvaScumul->SetMinimum(0);
193 fmvaBcumul->SetMinimum(0);
198 TH1D* effBvsS =
new TH1D(
"effBvsS",
"ROC-Curve", fNbins, 0, 1 );
203 TH1D* rejBvsS =
new TH1D(
"rejBvsS",
"ROC-Curve", fNbins, 0, 1 );
205 rejBvsS->
SetYTitle(
"Backgr rejection (1-eff)" );
208 TH1D* inveffBvsS =
new TH1D(
"invBeffvsSeff",
"ROC-Curve" , fNbins, 0, 1 );
210 inveffBvsS->
SetYTitle(
"Inverse backgr. eff (1/eff)" );
216 fSplmvaCumS =
new TSpline1(
"spline2_signal",
new TGraph( fmvaScumul ) );
217 fSplmvaCumB =
new TSpline1(
"spline2_background",
new TGraph( fmvaBcumul ) );
224 for (
UInt_t bini=1; bini<=fNbins; bini++) {
231 if (fUseSplines) effB = fSplmvaCumB->Eval( cut );
232 else effB = fmvaBcumul->GetBinContent( fmvaBcumul->FindBin( cut ) );
247 Double_t effS = 0., rejB = 0., effS_ = 0., rejB_ = 0.;
252 effS = (bini - 0.5)/
Float_t(nbins);
253 rejB = 1.0 - fSpleffBvsS->Eval( effS );
256 if ((effS - rejB)*(effS_ - rejB_) < 0)
break;
261 fSignalCut =
Root( 0.5*(effS + effS_) );
272 if (fSpleffBvsS == 0) this->GetROC();
279 effS = (bini - 0.5)/
Float_t(nbins);
280 effB = fSpleffBvsS->Eval( effS );
281 integral += (1.0 - effB);
295 Double_t effS=0., effB, effSOld=1., effBOld=0.;
297 if (fSpleffBvsS == 0) this->GetROC();
302 effS = (bini - 0.5)*step;
303 effB = fSpleffBvsS->Eval( effS );
306 if ((effB - effBref)*(effBOld - effBref) <= 0)
break;
312 effS = 0.5*(effS + effSOld);
315 if (fNevtS > 0) effSerr =
TMath::Sqrt( effS*(1.0 - effS)/fNevtS );
329 if (fUseSplines) retVal = fSplmvaCumS->Eval( theCut );
330 else retVal = fmvaScumul->GetBinContent( fmvaScumul->FindBin( theCut ) );
339 if (theCut-fXmin < eps) retVal = (fCutOrientation > 0) ? 1.0 : 0.0;
340 else if (fXmax-theCut < eps) retVal = (fCutOrientation > 0) ? 0.0 : 1.0;
352 Double_t fa = GetEffForRoot( a ) - refValue;
353 Double_t fb = GetEffForRoot( b ) - refValue;
355 Log() <<
kWARNING <<
"<ROCCalc::Root> initial interval w/o root: "
356 <<
"(a=" << a <<
", b=" << b <<
"),"
357 <<
" (Eff_a=" << GetEffForRoot( a )
358 <<
", Eff_b=" << GetEffForRoot( b ) <<
"), "
359 <<
"(fa=" << fa <<
", fb=" << fb <<
"), "
360 <<
"refValue = " << refValue <<
Endl;
368 if ((fb < 0 && fc < 0) || (fb > 0 && fc > 0)) {
373 d = b -
a; e = b -
a;
379 fa = fb; fb =
fc; fc = fa;
393 if (ac_equal) { p = 2 * m * s; q = 1 - s; }
395 q = fa /
fc; r = fb /
fc;
396 p = s * (2 * m * q * (q -
r) - (b - a) * (r - 1));
397 q = (q - 1) * (r - 1) * (s - 1);
405 if (2 * p < (min1 < min2 ? min1 : min2)) {
409 else { d =
m; e =
m; }
415 else b += (m > 0 ? +tol : -
tol);
417 fb = GetEffForRoot( b ) - refValue;
422 Log() <<
kWARNING <<
"<ROCCalc::Root> maximum iterations (" << fMaxIter
423 <<
") reached before convergence" <<
Endl;
432 if (fnStot!=nStot || fnBtot!=nBtot || !fSignificance) {
433 GetSignificance(nStot, nBtot);
443 if (fnStot==nStot && fnBtot==nBtot && !fSignificance)
return fSignificance;
444 fnStot=nStot; fnBtot=nBtot;
446 fSignificance = (
TH1*) fmvaScumul->
Clone(
"Significance"); fSignificance->SetTitle(
"Significance");
447 fSignificance->Reset(); fSignificance->SetFillStyle(0);
448 fSignificance->SetXTitle(
"mva cut value");
449 fSignificance->SetYTitle(
"Stat. significance S/Sqrt(S+B)");
450 fSignificance->SetLineColor(2);
451 fSignificance->SetLineWidth(5);
453 fPurity = (
TH1*) fmvaScumul->
Clone(
"Purity"); fPurity->SetTitle(
"Purity");
454 fPurity->Reset(); fPurity->SetFillStyle(0);
455 fPurity->SetXTitle(
"mva cut value");
456 fPurity->SetYTitle(
"Purity: S/(S+B)");
457 fPurity->SetLineColor(3);
458 fPurity->SetLineWidth(5);
461 for (
Int_t i=1; i<=fSignificance->GetNbinsX(); i++) {
462 Double_t S = fmvaScumul->GetBinContent( i ) * nStot;
463 Double_t B = fmvaBcumul->GetBinContent( i ) * nBtot;
476 cout <<
"S="<<S<<
" B="<<B<<
" purity="<<purity<< endl;
477 fPurity->SetBinContent( i, purity );
478 fSignificance->SetBinContent( i, sig );
495 return fSignificance;
virtual void SetLineWidth(Width_t lwidth)
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
MsgLogger & Log() const
message logger
MsgLogger & Endl(MsgLogger &ml)
virtual void SetMaximum(Double_t maximum=-1111)
ROCCalc(TH1 *mvaS, TH1 *mvaB)
static Int_t c_SignalFill
virtual void SetYTitle(const char *title)
virtual void SetFillStyle(Style_t fstyle)
virtual Int_t GetNbinsX() const
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
TH1D * GetROC()
get the ROC curve
static struct mg_connection * fc(struct mg_context *ctx)
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Double_t GetEffSForEffBof(Double_t effBref, Double_t &effSerr)
get the signal efficiency for a particular backgroud efficiency that will be the value of the efficie...
Double_t Root(Double_t)
Root finding using Brents algorithm; taken from CERNLIB function RZERO.
Double_t GetEffForRoot(Double_t theCut)
returns efficiency as function of cut
std::map< std::string, std::string >::const_iterator iter
TH1 * GetPurity(Int_t nStot, Int_t nBtot)
virtual void SetLineColor(Color_t lcolor)
virtual Double_t GetBinCenter(Int_t bin) const
return bin center for 1D historam Better to use h1.GetXaxis().GetBinCenter(bin)
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 SetFillColor(Color_t fcolor)
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
TH1 * GetSignificance(Int_t nStot, Int_t nBtot)
virtual Double_t GetSumOfWeights() const
Return the sum of weights excluding under/overflows.
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb"...
const char * GetTitle() const
Returns title of object.
1-D histogram with a double per channel (see TH1 documentation)}
static Int_t c_SignalLine
virtual TH1 * RebinX(Int_t ngroup=2, const char *newname="")
static Int_t c_BackgroundFill
void ApplySignalAndBackgroundStyle(TH1 *sig, TH1 *bkg, TH1 *any=0)
Int_t c_Canvas = TColor::GetColor( "#f0f0f0" ); Int_t c_FrameFill = TColor::GetColor( "#fffffd" ); In...
Abstract ClassifierFactory template that handles arbitrary types.
virtual void SetXTitle(const char *title)
Short_t Max(Short_t a, Short_t b)
A Graph is a graphics object made of two arrays X and Y with npoints each.
virtual void SetTitle(const char *title)
Change (i.e.
Double_t GetROCIntegral()
code to compute the area under the ROC ( rej-vs-eff ) curve
static Int_t c_BackgroundLine
Double_t Sqrt(Double_t x)
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...