Logo ROOT   master
Reference Guide
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 #include <iostream>
14 
15 
17  EventInfo ev;
18  ev.eventValue=val; ev.eventWeight=weight; ev.eventType=type;
19 
20  fEvtVector.push_back(ev);
21  if (fIsSorted) fIsSorted=false;
22 
23 }
24 
25 
27  // Well.. if it's fast is actually another question all together, merely
28  // it's a quick and dirty simple kNN approach to the 1-Dim signal/backgr. MVA
29  // distributions.
30 
31 
32  if (!fIsSorted) {
33  std::sort(fEvtVector.begin(),fEvtVector.end(),TMVA::QuickMVAProbEstimator::compare), fIsSorted=true;
34  }
35 
36  Double_t percentage = 0.1;
37  UInt_t nRange = TMath::Max(fNMin,(UInt_t) (fEvtVector.size() * percentage));
38  nRange = TMath::Min(fNMax,nRange);
39  // just make sure that nRange > you total number of events
40  if (nRange > fEvtVector.size()) {
41  nRange = fEvtVector.size()/3.;
42  Log() << kWARNING << " !! you have only " << fEvtVector.size() << " of events.. . I choose "
43  << nRange << " for the quick and dirty kNN MVAProb estimate" << Endl;
44  }
45 
46  EventInfo tmp; tmp.eventValue=value;
47  std::vector<EventInfo>::iterator it = std::upper_bound(fEvtVector.begin(),fEvtVector.end(),tmp,TMVA::QuickMVAProbEstimator::compare);
48 
49  UInt_t iLeft=0, iRight=0;
50  Double_t nSignal=0;
51  Double_t nBackgr=0;
52 
53  while ( (iLeft+iRight) < nRange){
54  if ( fEvtVector.end() > it+iRight+1){
55  iRight++;
56  if ( ((it+iRight))->eventType == 0) nSignal+=((it+iRight))->eventWeight;
57  else nBackgr+=((it+iRight))->eventWeight;
58  }
59  if ( fEvtVector.begin() <= it-iLeft-1){
60  iLeft++;
61  if ( ((it-iLeft))->eventType == 0) nSignal+=((it-iLeft))->eventWeight;
62  else nBackgr+=((it-iLeft))->eventWeight;
63  }
64  }
65 
66  Double_t mvaProb = (nSignal+nBackgr) ? nSignal/(nSignal+nBackgr) : -1 ;
67  return mvaProb;
68 
69 }
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:158
Double_t Log(Double_t x)
Definition: TMath.h:750
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:180
void AddEvent(Double_t val, Double_t weight, Int_t type)
static bool compare(EventInfo e1, EventInfo e2)
unsigned int UInt_t
Definition: RtypesCore.h:42
int type
Definition: TGX11.cxx:120
Double_t GetMVAProbAt(Double_t value)
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
std::vector< EventInfo > fEvtVector