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