Logo ROOT  
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 
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 }
TMath::Max
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
TMath::Log
Double_t Log(Double_t x)
Definition: TMath.h:760
TMVA::QuickMVAProbEstimator::fIsSorted
Bool_t fIsSorted
Definition: QuickMVAProbEstimator.h:33
TMVA::QuickMVAProbEstimator::EventInfo
Definition: QuickMVAProbEstimator.h:14
QuickMVAProbEstimator.h
TMVA::QuickMVAProbEstimator::AddEvent
void AddEvent(Double_t val, Double_t weight, Int_t type)
Definition: QuickMVAProbEstimator.cxx:14
MsgLogger.h
TMVA::QuickMVAProbEstimator::compare
static bool compare(EventInfo e1, EventInfo e2)
Definition: QuickMVAProbEstimator.h:19
TMVA::QuickMVAProbEstimator::EventInfo::eventType
Int_t eventType
Definition: QuickMVAProbEstimator.h:17
Types.h
TMath::Min
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:180
TMVA::Endl
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:158
unsigned int
TMVA::QuickMVAProbEstimator::EventInfo::eventValue
Double_t eventValue
Definition: QuickMVAProbEstimator.h:15
Double_t
double Double_t
Definition: RtypesCore.h:59
TMVA::QuickMVAProbEstimator::EventInfo::eventWeight
Double_t eventWeight
Definition: QuickMVAProbEstimator.h:16
type
int type
Definition: TGX11.cxx:121
TMVA::QuickMVAProbEstimator::GetMVAProbAt
Double_t GetMVAProbAt(Double_t value)
Definition: QuickMVAProbEstimator.cxx:24
TMVA::QuickMVAProbEstimator::fEvtVector
std::vector< EventInfo > fEvtVector
Definition: QuickMVAProbEstimator.h:32
TMath.h
int