ROOT  6.06/09
Reference Guide
QuickMVAProbEstimator.cxx
Go to the documentation of this file.
2 
3 #include <iostream>
4 
5 #include "TMath.h"
6 
7 #ifndef ROOT_TMVA_MsgLogger
8 #include "TMVA/MsgLogger.h"
9 #endif
10 
11 
13  EventInfo ev;
14  ev.eventValue=val; ev.eventWeight=weight; ev.eventType=type;
15 
16  fEvtVector.push_back(ev);
17  if (fIsSorted) fIsSorted=false;
18 
19 }
20 
21 
23  // Well.. if it's fast is actually another question all together, merely
24  // it's a quick and dirty simple kNN approach to the 1-Dim signal/backgr. MVA
25  // distributions.
26 
27 
28  if (!fIsSorted) {
29  std::sort(fEvtVector.begin(),fEvtVector.end(),TMVA::QuickMVAProbEstimator::compare), fIsSorted=true;
30  }
31 
32  Double_t percentage = 0.1;
33  UInt_t nRange = TMath::Max(fNMin,(UInt_t) (fEvtVector.size() * percentage));
34  nRange = TMath::Min(fNMax,nRange);
35  // just make sure that nRange > you total number of events
36  if (nRange > fEvtVector.size()) {
37  nRange = fEvtVector.size()/3.;
38  Log() << kWARNING << " !! you have only " << fEvtVector.size() << " of events.. . I choose "
39  << nRange << " for the quick and dirty kNN MVAProb estimate" << Endl;
40  }
41 
42  EventInfo tmp; tmp.eventValue=value;
43  std::vector<EventInfo>::iterator it = std::upper_bound(fEvtVector.begin(),fEvtVector.end(),tmp,TMVA::QuickMVAProbEstimator::compare);
44 
45  UInt_t iLeft=0, iRight=0;
46  Double_t nSignal=0;
47  Double_t nBackgr=0;
48 
49  while ( (iLeft+iRight) < nRange){
50  if ( fEvtVector.end() > it+iRight+1){
51  iRight++;
52  if ( ((it+iRight))->eventType == 0) nSignal+=((it+iRight))->eventWeight;
53  else nBackgr+=((it+iRight))->eventWeight;
54  }
55  if ( fEvtVector.begin() <= it-iLeft-1){
56  iLeft++;
57  if ( ((it-iLeft))->eventType == 0) nSignal+=((it-iLeft))->eventWeight;
58  else nBackgr+=((it-iLeft))->eventWeight;
59  }
60  }
61 
62  Double_t mvaProb = (nSignal+nBackgr) ? nSignal/(nSignal+nBackgr) : -1 ;
63  return mvaProb;
64 
65 }
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:162
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:170
int Int_t
Definition: RtypesCore.h:41
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
double Double_t
Definition: RtypesCore.h:55
int type
Definition: TGX11.cxx:120
Double_t GetMVAProbAt(Double_t value)
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:202
std::vector< EventInfo > fEvtVector
float value
Definition: math.cpp:443
Definition: math.cpp:60