Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
QuickMVAProbEstimator.cxx
Go to the documentation of this file.
1/*! \class TMVA::QuickMVAProbEstimator
2\ingroup TMVA
3
4*/
5
7
8#include "TMVA/MsgLogger.h"
9#include "TMVA/Types.h"
10
11#include "TMath.h"
12
13
15 EventInfo ev;
16 ev.eventValue=val; ev.eventWeight=weight; ev.eventType=type;
17
18 fEvtVector.push_back(ev);
19 if (fIsSorted) fIsSorted=false;
20
21}
22
23
25 // Well.. if it's fast is actually another question all together, merely
26 // it's a quick and dirty simple kNN approach to the 1-Dim signal/backgr. MVA
27 // distributions.
28
29
30 if (!fIsSorted) {
31 std::sort(fEvtVector.begin(),fEvtVector.end(),TMVA::QuickMVAProbEstimator::compare), fIsSorted=true;
32 }
33
34 Double_t percentage = 0.1;
35 UInt_t nRange = TMath::Max(fNMin,(UInt_t) (fEvtVector.size() * percentage));
36 nRange = TMath::Min(fNMax,nRange);
37 // just make sure that nRange > you total number of events
38 if (nRange > fEvtVector.size()) {
39 nRange = fEvtVector.size()/3.;
40 Log() << kWARNING << " !! you have only " << fEvtVector.size() << " of events.. . I choose "
41 << nRange << " for the quick and dirty kNN MVAProb estimate" << Endl;
42 }
43
44 EventInfo tmp; tmp.eventValue=value;
45 std::vector<EventInfo>::iterator it = std::upper_bound(fEvtVector.begin(),fEvtVector.end(),tmp,TMVA::QuickMVAProbEstimator::compare);
46
47 UInt_t iLeft=0, iRight=0;
48 Double_t nSignal=0;
49 Double_t nBackgr=0;
50
51 while ( (iLeft+iRight) < nRange){
52 if ( fEvtVector.end() > it+iRight+1){
53 iRight++;
54 if ( ((it+iRight))->eventType == 0) nSignal+=((it+iRight))->eventWeight;
55 else nBackgr+=((it+iRight))->eventWeight;
56 }
57 if ( fEvtVector.begin() <= it-iLeft-1){
58 iLeft++;
59 if ( ((it-iLeft))->eventType == 0) nSignal+=((it-iLeft))->eventWeight;
60 else nBackgr+=((it-iLeft))->eventWeight;
61 }
62 }
63
64 Double_t mvaProb = (nSignal+nBackgr) ? nSignal/(nSignal+nBackgr) : -1 ;
65 return mvaProb;
66
67}
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
static bool compare(EventInfo e1, EventInfo e2)
Double_t GetMVAProbAt(Double_t value)
void AddEvent(Double_t val, Double_t weight, Int_t type)
std::vector< EventInfo > fEvtVector
MsgLogger & Endl(MsgLogger &ml)
Definition MsgLogger.h:148
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:250
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:198