126 #pragma warning ( disable : 4355 )
143 fAnalysisType (
Types::kNoAnalysisType ),
144 fRegressionReturnVal ( 0 ),
145 fMulticlassReturnVal ( 0 ),
146 fDisableWriting (
kFALSE ),
147 fDataSetInfo ( dsi ),
148 fSignalReferenceCut ( 0.5 ),
149 fSignalReferenceCutOrientation( 1. ),
150 fVariableTransformType (
Types::kSignal ),
151 fJobName ( jobName ),
152 fMethodName ( methodTitle ),
153 fMethodType ( methodType ),
157 fConstructedFromWeightFile (
kFALSE ),
159 fMethodBaseDir ( theBaseDir ),
170 fSplTrainEffBvsS ( 0 ),
171 fVarTransformString (
"None" ),
172 fTransformationPointer ( 0 ),
173 fTransformation ( dsi, methodTitle ),
175 fVerbosityLevelString (
"Default" ),
178 fIgnoreNegWeightsInTraining(
kFALSE ),
180 fBackgroundClass ( 0 ),
207 fAnalysisType (
Types::kNoAnalysisType ),
208 fRegressionReturnVal ( 0 ),
209 fMulticlassReturnVal ( 0 ),
210 fDataSetInfo ( dsi ),
211 fSignalReferenceCut ( 0.5 ),
212 fVariableTransformType (
Types::kSignal ),
214 fMethodName (
"MethodBase" ),
215 fMethodType ( methodType ),
217 fTMVATrainingVersion ( 0 ),
218 fROOTTrainingVersion ( 0 ),
219 fConstructedFromWeightFile ( kTRUE ),
220 fBaseDir ( theBaseDir ),
221 fMethodBaseDir ( 0 ),
222 fWeightFile ( weightFile ),
232 fSplTrainEffBvsS ( 0 ),
233 fVarTransformString (
"None" ),
234 fTransformationPointer ( 0 ),
235 fTransformation ( dsi,
"" ),
237 fVerbosityLevelString (
"Default" ),
240 fIgnoreNegWeightsInTraining(
kFALSE ),
242 fBackgroundClass ( 0 ),
256 if (!fSetupCompleted)
Log() <<
kFATAL <<
"Calling destructor of method which got never setup" <<
Endl;
259 if (fInputVars != 0) { fInputVars->clear();
delete fInputVars; }
260 if (fRanking != 0)
delete fRanking;
263 if (fDefaultPDF!= 0) {
delete fDefaultPDF; fDefaultPDF = 0; }
264 if (fMVAPdfS != 0) {
delete fMVAPdfS; fMVAPdfS = 0; }
265 if (fMVAPdfB != 0) {
delete fMVAPdfB; fMVAPdfB = 0; }
268 if (fSplS) {
delete fSplS; fSplS = 0; }
269 if (fSplB) {
delete fSplB; fSplB = 0; }
270 if (fSpleffBvsS) {
delete fSpleffBvsS; fSpleffBvsS = 0; }
271 if (fSplRefS) {
delete fSplRefS; fSplRefS = 0; }
272 if (fSplRefB) {
delete fSplRefB; fSplRefB = 0; }
273 if (fSplTrainRefS) {
delete fSplTrainRefS; fSplTrainRefS = 0; }
274 if (fSplTrainRefB) {
delete fSplTrainRefB; fSplTrainRefB = 0; }
275 if (fSplTrainEffBvsS) {
delete fSplTrainEffBvsS; fSplTrainEffBvsS = 0; }
277 for (
Int_t i = 0; i < 2; i++ ) {
278 if (fEventCollections.at(i)) {
279 for (std::vector<Event*>::const_iterator it = fEventCollections.at(i)->begin();
280 it != fEventCollections.at(i)->end(); it++) {
283 delete fEventCollections.at(i);
284 fEventCollections.at(i) = 0;
288 if (fRegressionReturnVal)
delete fRegressionReturnVal;
289 if (fMulticlassReturnVal)
delete fMulticlassReturnVal;
297 if (fSetupCompleted)
Log() <<
kFATAL <<
"Calling SetupMethod for the second time" <<
Endl;
299 DeclareBaseOptions();
302 fSetupCompleted =
kTRUE;
312 ProcessBaseOptions();
322 CheckForUnusedOptions();
330 SetConfigDescription(
"Configuration options for classifier architecture and tuning" );
338 fSplTrainEffBvsS = 0;
345 fTxtWeightsOnly =
kTRUE;
355 fInputVars =
new std::vector<TString>;
356 for (
UInt_t ivar=0; ivar<GetNvar(); ivar++) {
357 fInputVars->push_back(DataInfo().GetVariableInfo(ivar).GetLabel());
359 fRegressionReturnVal = 0;
360 fMulticlassReturnVal = 0;
362 fEventCollections.resize( 2 );
363 fEventCollections.at(0) = 0;
364 fEventCollections.at(1) = 0;
370 if (DataInfo().GetClassInfo(
"Signal") != 0) {
371 fSignalClass = DataInfo().GetClassInfo(
"Signal")->GetNumber();
373 if (DataInfo().GetClassInfo(
"Background") != 0) {
374 fBackgroundClass = DataInfo().GetClassInfo(
"Background")->GetNumber();
377 SetConfigDescription(
"Configuration options for MVA method" );
378 SetConfigName(
TString(
"Method") + GetMethodTypeName() );
398 DeclareOptionRef( fVerbose,
"V",
"Verbose output (short form of \"VerbosityLevel\" below - overrides the latter one)" );
400 DeclareOptionRef( fVerbosityLevelString=
"Default",
"VerbosityLevel",
"Verbosity level" );
401 AddPreDefVal(
TString(
"Default") );
402 AddPreDefVal(
TString(
"Debug") );
403 AddPreDefVal(
TString(
"Verbose") );
404 AddPreDefVal(
TString(
"Info") );
405 AddPreDefVal(
TString(
"Warning") );
406 AddPreDefVal(
TString(
"Error") );
407 AddPreDefVal(
TString(
"Fatal") );
411 fTxtWeightsOnly =
kTRUE;
414 DeclareOptionRef( fVarTransformString,
"VarTransform",
"List of variable transformations performed before training, e.g., \"D_Background,P_Signal,G,N_AllClasses\" for: \"Decorrelation, PCA-transformation, Gaussianisation, Normalisation, each for the given class of events ('AllClasses' denotes all events of all classes, if no class indication is given, 'All' is assumed)\"" );
416 DeclareOptionRef( fHelp,
"H",
"Print method-specific help message" );
418 DeclareOptionRef( fHasMVAPdfs,
"CreateMVAPdfs",
"Create PDFs for classifier outputs (signal and background)" );
420 DeclareOptionRef( fIgnoreNegWeightsInTraining,
"IgnoreNegWeightsInTraining",
421 "Events with negative weights are ignored in the training (but are included for testing and performance evaluation)" );
433 fDefaultPDF =
new PDF(
TString(GetName())+
"_PDF", GetOptions(),
"MVAPdf" );
434 fDefaultPDF->DeclareOptions();
435 fDefaultPDF->ParseOptions();
436 fDefaultPDF->ProcessOptions();
437 fMVAPdfB =
new PDF(
TString(GetName())+
"_PDFBkg", fDefaultPDF->GetOptions(),
"MVAPdfBkg", fDefaultPDF );
439 fMVAPdfB->ParseOptions();
440 fMVAPdfB->ProcessOptions();
441 fMVAPdfS =
new PDF(
TString(GetName())+
"_PDFSig", fMVAPdfB->GetOptions(),
"MVAPdfSig", fDefaultPDF );
443 fMVAPdfS->ParseOptions();
444 fMVAPdfS->ProcessOptions();
447 SetOptions( fMVAPdfS->GetOptions() );
452 GetTransformationHandler(),
456 if (fDefaultPDF!= 0) {
delete fDefaultPDF; fDefaultPDF = 0; }
457 if (fMVAPdfS != 0) {
delete fMVAPdfS; fMVAPdfS = 0; }
458 if (fMVAPdfB != 0) {
delete fMVAPdfB; fMVAPdfB = 0; }
462 fVerbosityLevelString =
TString(
"Verbose");
465 else if (fVerbosityLevelString ==
"Debug" )
Log().SetMinType(
kDEBUG );
466 else if (fVerbosityLevelString ==
"Verbose" )
Log().SetMinType(
kVERBOSE );
467 else if (fVerbosityLevelString ==
"Info" )
Log().SetMinType(
kINFO );
468 else if (fVerbosityLevelString ==
"Warning" )
Log().SetMinType(
kWARNING );
469 else if (fVerbosityLevelString ==
"Error" )
Log().SetMinType(
kERROR );
470 else if (fVerbosityLevelString ==
"Fatal" )
Log().SetMinType(
kFATAL );
471 else if (fVerbosityLevelString !=
"Default" ) {
472 Log() <<
kFATAL <<
"<ProcessOptions> Verbosity level type '"
473 << fVerbosityLevelString <<
"' unknown." <<
Endl;
486 TString trafoDefinition(trafoDefinitionIn);
487 if (trafoDefinition ==
"None")
return;
491 TString trafoDefinitionCheck(trafoDefinitionIn);
492 int npartial = 0, ntrafo=0;
493 for (
Int_t pos = 0, siz = trafoDefinition.
Sizeof(); pos < siz; ++pos) {
494 TString ch = trafoDefinition(pos,1);
495 if ( ch ==
"(" ) npartial++;
496 if ( ch ==
"+" || ch ==
",") ntrafo++;
499 log <<
kWARNING <<
"The use of multiple partial variable transformations during the application phase can be properly invoked via the \"Reader\", but it is not yet implemented in \"MakeClass\", the creation mechanism for standalone C++ application classes. The standalone C++ class produced by this training job is thus INCOMPLETE AND MUST NOT BE USED! The transformation in question is: " << trafoDefinitionIn <<
Endl;
507 Int_t parenthesisCount = 0;
508 for (
Int_t position = 0, size = trafoDefinition.
Sizeof(); position < size; ++position) {
509 TString ch = trafoDefinition(position,1);
510 if (ch ==
"(") ++parenthesisCount;
511 else if (ch ==
")") --parenthesisCount;
512 else if (ch ==
"," && parenthesisCount == 0) trafoDefinition.
Replace(position,1,
'+');
518 TString tdef = os->GetString();
524 Ssiz_t parLen = tdef.
Index(
")", parStart )-parStart+1;
526 variables = tdef(parStart,parLen);
527 tdef.
Remove(parStart,parLen);
528 variables.
Remove(parLen-1,1);
534 if (trClsList->
GetSize() < 1) log <<
kFATAL <<
"Incorrect transformation string provided." <<
Endl;
541 if (trCls !=
"AllClasses") {
544 log <<
kFATAL <<
"Class " << trCls <<
" not known for variable transformation "
545 << trName <<
", please check." <<
Endl;
552 if (trName ==
"I" || trName ==
"Ident" || trName ==
"Identity") {
553 if (variables.
Length() == 0) variables =
"_V_";
556 else if (trName ==
"D" || trName ==
"Deco" || trName ==
"Decorrelate") {
557 if (variables.
Length() == 0) variables =
"_V_";
560 else if (trName ==
"P" || trName ==
"PCA") {
561 if (variables.
Length() == 0) variables =
"_V_";
564 else if (trName ==
"U" || trName ==
"Uniform") {
565 if (variables.
Length() == 0) variables =
"_V_,_T_";
568 else if (trName ==
"G" || trName ==
"Gauss") {
569 if (variables.
Length() == 0) variables =
"_V_";
572 else if (trName ==
"N" || trName ==
"Norm" || trName ==
"Normalise" || trName ==
"Normalize") {
573 if (variables.
Length() == 0) variables =
"_V_,_T_";
576 else log <<
kFATAL <<
"<ProcessOptions> Variable transform '"
577 << trName <<
"' unknown." <<
Endl;
579 if (transformation) {
582 log <<
kINFO <<
"Create Transformation \"" << trName <<
"\" with reference class "
583 << clsInfo->
GetName() <<
"=("<< idxCls <<
")"<<
Endl;
585 log <<
kINFO <<
"Create Transformation \"" << trName <<
"\" with events from all classes." <<
Endl;
601 DeclareOptionRef( fNormalise=
kFALSE,
"Normalise",
"Normalise input variables" );
602 DeclareOptionRef( fUseDecorr=
kFALSE,
"D",
"Use-decorrelated-variables flag" );
603 DeclareOptionRef( fVariableTransformTypeString=
"Signal",
"VarTransformType",
604 "Use signal or background events to derive for variable transformation (the transformation is applied on both types of, course)" );
605 AddPreDefVal(
TString(
"Signal") );
606 AddPreDefVal(
TString(
"Background") );
607 DeclareOptionRef( fTxtWeightsOnly=kTRUE,
"TxtWeightFilesOnly",
"If True: write all training results (weights) as text files (False: some are written in ROOT format)" );
617 DeclareOptionRef( fNbinsMVAPdf = 60,
"NbinsMVAPdf",
"Number of bins used for the PDFs of classifier outputs" );
618 DeclareOptionRef( fNsmoothMVAPdf = 2,
"NsmoothMVAPdf",
"Number of smoothing iterations for classifier PDFs" );
632 Log() <<
kWARNING <<
"Parameter optimization is not yet implemented for method "
633 << GetName() <<
Endl;
634 Log() <<
kWARNING <<
"Currently we need to set hardcoded which parameter is tuned in which ranges"<<
Endl;
636 std::map<TString,Double_t> tunedParameters;
637 tunedParameters.size();
638 return tunedParameters;
659 if (Help()) PrintHelpMessage();
666 GetTransformationHandler().CalcTransformations(
Data()->GetEventCollection());
671 Timer traintimer( nEvents, GetName(), kTRUE );
675 Log() <<
kINFO <<
"Elapsed time for training with " << nEvents <<
" events: "
678 Log() <<
kINFO <<
"Create MVA output for ";
681 if (DoMulticlass()) {
682 Log() <<
"Multiclass classification on training sample" <<
Endl;
685 else if (!DoRegression()) {
687 Log() <<
"classification on training sample" <<
Endl;
696 Log() <<
"regression on training sample" <<
Endl;
700 Log() <<
"Create PDFs" <<
Endl;
707 if (!fDisableWriting ) WriteStateToFile();
710 if ((!DoRegression()) && (!fDisableWriting)) MakeClass();
715 WriteMonitoringHistosToFile();
722 if (!DoRegression())
Log() <<
kFATAL <<
"Trying to use GetRegressionDeviation() with a classification job" <<
Endl;
725 bool truncate =
false;
726 TH1F*
h1 = regRes->QuadraticDeviation( tgtNum , truncate, 1.);
731 TH1F* h2 = regRes->QuadraticDeviation( tgtNum , truncate, yq[0]);
742 Data()->SetCurrentType(type);
756 regRes->Resize( nEvents );
758 Data()->SetCurrentEvent(ievt);
759 std::vector< Float_t > vals = GetRegressionValues();
760 regRes->SetValue( vals, ievt );
764 Log() <<
kINFO <<
"Elapsed time for evaluation of " << nEvents <<
" events: "
771 TString histNamePrefix(GetTestvarName());
773 regRes->CreateDeviationHistograms( histNamePrefix );
781 Data()->SetCurrentType(type);
786 if (!resMulticlass)
Log() <<
kFATAL<<
"unable to create pointer in AddMulticlassOutput, exiting."<<
Endl;
796 resMulticlass->Resize( nEvents );
798 Data()->SetCurrentEvent(ievt);
799 std::vector< Float_t > vals = GetMulticlassValues();
800 resMulticlass->SetValue( vals, ievt );
804 Log() <<
kINFO <<
"Elapsed time for evaluation of " << nEvents <<
" events: "
811 TString histNamePrefix(GetTestvarName());
813 resMulticlass->CreateMulticlassHistos( histNamePrefix, fNbinsMVAoutput, fNbinsH );
822 if (errUpper) *errUpper=-1;
829 Double_t val = GetMvaValue(err, errUpper);
839 return GetMvaValue()*GetSignalReferenceCutOrientation() > GetSignalReferenceCut()*GetSignalReferenceCutOrientation() ? kTRUE :
kFALSE;
846 return mvaVal*GetSignalReferenceCutOrientation() > GetSignalReferenceCut()*GetSignalReferenceCutOrientation() ? kTRUE :
kFALSE;
854 Data()->SetCurrentType(type);
865 << (type==
Types::kTraining?
"training":
"testing") <<
" sample (" << nEvents <<
" events)" <<
Endl;
869 Data()->SetCurrentEvent(ievt);
870 clRes->
SetValue( GetMvaValue(), ievt );
874 if (modulo <= 0 ) modulo = 1;
878 Log() <<
kINFO <<
"Elapsed time for evaluation of " << nEvents <<
" events: "
892 Data()->SetCurrentType(type);
905 mvaProb->
Resize( nEvents );
908 Data()->SetCurrentEvent(ievt);
910 if (proba < 0)
break;
915 if (modulo <= 0 ) modulo = 1;
919 Log() <<
kINFO <<
"Elapsed time for evaluation of " << nEvents <<
" events: "
939 Data()->SetCurrentType(type);
941 bias = 0; biasT = 0; dev = 0; devT = 0; rms = 0; rmsT = 0;
943 Double_t m1 = 0, m2 = 0, s1 = 0, s2 = 0, s12 = 0;
944 const Int_t nevt = GetNEvents();
949 for (
Long64_t ievt=0; ievt<nevt; ievt++) {
951 const Event* ev =
Data()->GetEvent(ievt);
954 Float_t r = GetRegressionValues()[0];
973 m1 += t*w; s1 += t*t*w;
974 m2 += r*w; s2 += r*r*w;
987 corr = s12/sumw - m1*m2;
988 corr /=
TMath::Sqrt( (s1/sumw - m1*m1) * (s2/sumw - m2*m2) );
991 TH2F* hist =
new TH2F(
"hist",
"hist", 150, xmin, xmax, 100, xmin, xmax );
992 TH2F* histT =
new TH2F(
"histT",
"histT", 150, xmin, xmax, 100, xmin, xmax );
999 for (
Long64_t ievt=0; ievt<nevt; ievt++) {
1000 Float_t d = (rV[ievt] - tV[ievt]);
1001 hist->
Fill( rV[ievt], tV[ievt], wV[ievt] );
1002 if (d >= devMin && d <= devMax) {
1004 biasT += wV[ievt] * d;
1006 rmsT += wV[ievt] * d * d;
1007 histT->
Fill( rV[ievt], tV[ievt], wV[ievt] );
1025 Data()->SetCurrentType(savedType);
1035 if (!resMulticlass)
Log() <<
kFATAL<<
"unable to create pointer in TestMulticlass, exiting."<<
Endl;
1036 Log() <<
kINFO <<
"Determine optimal multiclass cuts for test data..." <<
Endl;
1037 for (
UInt_t icls = 0; icls<DataInfo().GetNClasses(); ++icls) {
1054 if (0==mvaRes && !(GetMethodTypeName().Contains(
"Cuts"))) {
1055 Log() <<
"mvaRes " << mvaRes <<
" GetMethodTypeName " << GetMethodTypeName()
1056 <<
" contains " << !(GetMethodTypeName().Contains(
"Cuts")) <<
Endl;
1057 Log() <<
kFATAL <<
"<TestInit> Test variable " << GetTestvarName()
1058 <<
" not found in tree" <<
Endl;
1063 fMeanS, fMeanB, fRmsS, fRmsB, fXmin, fXmax, fSignalClass );
1071 fCutOrientation = (fMeanS > fMeanB) ? kPositive : kNegative;
1080 TH1* mva_s =
new TH1D( GetTestvarName() +
"_S",GetTestvarName() +
"_S", fNbinsMVAoutput, fXmin, sxmax );
1081 TH1* mva_b =
new TH1D( GetTestvarName() +
"_B",GetTestvarName() +
"_B", fNbinsMVAoutput, fXmin, sxmax );
1082 mvaRes->
Store(mva_s,
"MVA_S");
1083 mvaRes->
Store(mva_b,
"MVA_B");
1093 proba_s =
new TH1D( GetTestvarName() +
"_Proba_S", GetTestvarName() +
"_Proba_S", fNbinsMVAoutput, 0.0, 1.0 );
1094 proba_b =
new TH1D( GetTestvarName() +
"_Proba_B", GetTestvarName() +
"_Proba_B", fNbinsMVAoutput, 0.0, 1.0 );
1095 mvaRes->
Store(proba_s,
"Prob_S");
1096 mvaRes->
Store(proba_b,
"Prob_B");
1101 rarity_s =
new TH1D( GetTestvarName() +
"_Rarity_S", GetTestvarName() +
"_Rarity_S", fNbinsMVAoutput, 0.0, 1.0 );
1102 rarity_b =
new TH1D( GetTestvarName() +
"_Rarity_B", GetTestvarName() +
"_Rarity_B", fNbinsMVAoutput, 0.0, 1.0 );
1103 mvaRes->
Store(rarity_s,
"Rar_S");
1104 mvaRes->
Store(rarity_b,
"Rar_B");
1110 TH1* mva_eff_s =
new TH1D( GetTestvarName() +
"_S_high", GetTestvarName() +
"_S_high", fNbinsH, fXmin, sxmax );
1111 TH1* mva_eff_b =
new TH1D( GetTestvarName() +
"_B_high", GetTestvarName() +
"_B_high", fNbinsH, fXmin, sxmax );
1112 mvaRes->
Store(mva_eff_s,
"MVA_HIGHBIN_S");
1113 mvaRes->
Store(mva_eff_b,
"MVA_HIGHBIN_B");
1121 Log() <<
kINFO <<
"Loop over test events and fill histograms with classifier response..." <<
Endl;
1122 if (mvaProb)
Log() <<
kINFO <<
"Also filling probability and rarity histograms (on request)..." <<
Endl;
1123 for (
Long64_t ievt=0; ievt<GetNEvents(); ievt++) {
1125 const Event* ev = GetEvent(ievt);
1129 if (DataInfo().IsSignal(ev)) {
1130 mva_s ->
Fill( v, w );
1132 proba_s->
Fill( (*mvaProb)[ievt][0], w );
1133 rarity_s->
Fill( GetRarity( v ), w );
1136 mva_eff_s ->
Fill( v, w );
1139 mva_b ->
Fill( v, w );
1141 proba_b->
Fill( (*mvaProb)[ievt][0], w );
1142 rarity_b->
Fill( GetRarity( v ), w );
1144 mva_eff_b ->
Fill( v, w );
1159 if (fSplS) {
delete fSplS; fSplS = 0; }
1160 if (fSplB) {
delete fSplB; fSplB = 0; }
1174 tf << prefix <<
"#GEN -*-*-*-*-*-*-*-*-*-*-*- general info -*-*-*-*-*-*-*-*-*-*-*-" << std::endl << prefix << std::endl;
1175 tf << prefix <<
"Method : " << GetMethodTypeName() <<
"::" <<
GetMethodName() << std::endl;
1176 tf.setf(std::ios::left);
1177 tf << prefix <<
"TMVA Release : " << std::setw(10) << GetTrainingTMVAVersionString() <<
" ["
1178 << GetTrainingTMVAVersionCode() <<
"]" << std::endl;
1179 tf << prefix <<
"ROOT Release : " << std::setw(10) << GetTrainingROOTVersionString() <<
" ["
1180 << GetTrainingROOTVersionCode() <<
"]" << std::endl;
1181 tf << prefix <<
"Creator : " << userInfo->
fUser << std::endl;
1185 tf << prefix <<
"Training events: " <<
Data()->GetNTrainingEvents() << std::endl;
1187 TString analysisType(((const_cast<TMVA::MethodBase*>(
this)->GetAnalysisType()==
Types::kRegression) ?
"Regression" :
"Classification"));
1189 tf << prefix <<
"Analysis type : " <<
"[" << ((GetAnalysisType()==
Types::kRegression) ?
"Regression" :
"Classification") <<
"]" << std::endl;
1190 tf << prefix << std::endl;
1195 tf << prefix << std::endl << prefix <<
"#OPT -*-*-*-*-*-*-*-*-*-*-*-*- options -*-*-*-*-*-*-*-*-*-*-*-*-" << std::endl << prefix << std::endl;
1196 WriteOptionsToStream( tf, prefix );
1197 tf << prefix << std::endl;
1200 tf << prefix << std::endl << prefix <<
"#VAR -*-*-*-*-*-*-*-*-*-*-*-* variables *-*-*-*-*-*-*-*-*-*-*-*-" << std::endl << prefix << std::endl;
1201 WriteVarsToStream( tf, prefix );
1202 tf << prefix << std::endl;
1219 AddRegressionOutput( type );
1221 AddMulticlassOutput( type );
1223 AddClassifierOutput( type );
1225 AddClassifierOutputProb( type );
1235 if (!parent)
return;
1240 AddInfoItem( gi,
"TMVA Release", GetTrainingTMVAVersionString() +
" [" +
gTools().StringFromInt(GetTrainingTMVAVersionCode()) +
"]" );
1241 AddInfoItem( gi,
"ROOT Release", GetTrainingROOTVersionString() +
" [" +
gTools().StringFromInt(GetTrainingROOTVersionCode()) +
"]");
1242 AddInfoItem( gi,
"Creator", userInfo->
fUser);
1246 AddInfoItem( gi,
"Training events",
gTools().StringFromInt(
Data()->GetNTrainingEvents()));
1247 AddInfoItem( gi,
"TrainingTime",
gTools().StringFromDouble(const_cast<TMVA::MethodBase*>(
this)->GetTrainTime()));
1252 AddInfoItem( gi,
"AnalysisType", analysisType );
1256 AddOptionsXMLTo( parent );
1259 AddVarsXMLTo( parent );
1262 if (!fDisableWriting)
1263 AddSpectatorsXMLTo( parent );
1266 AddClassesXMLTo(parent);
1269 if (DoRegression()) AddTargetsXMLTo(parent);
1272 GetTransformationHandler(
false).AddXMLTo( parent );
1276 if (fMVAPdfS) fMVAPdfS->AddXMLTo(pdfs);
1277 if (fMVAPdfB) fMVAPdfB->AddXMLTo(pdfs);
1280 AddWeightsXMLTo( parent );
1296 ReadWeightsFromStream( rf );
1309 TString tfname( GetWeightFileName() );
1313 Log() <<
kINFO <<
"Creating weight file in xml format: "
1319 WriteStateToXML(rootnode);
1331 TString tfname(GetWeightFileName());
1333 Log() <<
kINFO <<
"Reading weight file: "
1337 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,29,0)
1343 ReadStateFromXML(rootnode);
1348 fb.open(tfname.
Data(),std::ios::in);
1349 if (!fb.is_open()) {
1350 Log() <<
kFATAL <<
"<ReadStateFromFile> "
1351 <<
"Unable to open input weight file: " << tfname <<
Endl;
1353 std::istream fin(&fb);
1354 ReadStateFromStream(fin);
1357 if (!fTxtWeightsOnly) {
1360 Log() <<
kINFO <<
"Reading root weight file: "
1363 ReadStateFromStream( *rfile );
1371 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,26,00)
1374 ReadStateFromXML(rootnode);
1377 Log() <<
kFATAL <<
"Method MethodBase::ReadStateFromXMLString( const char* xmlstr = "
1378 << xmlstr <<
" ) is not available for ROOT versions prior to 5.26/00." <<
Endl;
1390 fMethodName = fullMethodName(fullMethodName.
Index(
"::")+2,fullMethodName.
Length());
1393 Log().SetSource( GetName() );
1404 if (nodeName==
"GeneralInfo") {
1409 while (antypeNode) {
1412 if (
name ==
"TrainingTime")
1415 if (
name ==
"AnalysisType") {
1421 else Log() <<
kFATAL <<
"Analysis type " << val <<
" is not known." <<
Endl;
1424 if (
name ==
"TMVA Release" ||
name ==
"TMVA") {
1428 Log() <<
kINFO <<
"MVA method was trained with TMVA Version: " << GetTrainingTMVAVersionString() <<
Endl;
1431 if (
name ==
"ROOT Release" ||
name ==
"ROOT") {
1435 Log() <<
kINFO <<
"MVA method was trained with ROOT Version: " << GetTrainingROOTVersionString() <<
Endl;
1440 else if (nodeName==
"Options") {
1441 ReadOptionsFromXML(ch);
1445 else if (nodeName==
"Variables") {
1446 ReadVariablesFromXML(ch);
1448 else if (nodeName==
"Spectators") {
1449 ReadSpectatorsFromXML(ch);
1451 else if (nodeName==
"Classes") {
1452 if (DataInfo().GetNClasses()==0) ReadClassesFromXML(ch);
1454 else if (nodeName==
"Targets") {
1455 if (DataInfo().GetNTargets()==0 && DoRegression()) ReadTargetsFromXML(ch);
1457 else if (nodeName==
"Transformations") {
1458 GetTransformationHandler().ReadFromXML(ch);
1460 else if (nodeName==
"MVAPdfs") {
1462 if (fMVAPdfS) {
delete fMVAPdfS; fMVAPdfS=0; }
1463 if (fMVAPdfB) {
delete fMVAPdfB; fMVAPdfB=0; }
1467 fMVAPdfS =
new PDF(pdfname);
1468 fMVAPdfS->ReadXML(pdfnode);
1471 fMVAPdfB =
new PDF(pdfname);
1472 fMVAPdfB->ReadXML(pdfnode);
1475 else if (nodeName==
"Weights") {
1476 ReadWeightsFromXML(ch);
1479 Log() <<
kWARNING <<
"Unparsed XML node: '" << nodeName <<
"'" <<
Endl;
1486 if (GetTransformationHandler().GetCallerName() ==
"") GetTransformationHandler().SetCallerName( GetName() );
1506 methodType = methodType(methodType.Last(
' '),methodType.Length());
1511 if (methodName ==
"") methodName = methodType;
1512 fMethodName = methodName;
1517 Log().SetSource( GetName() );
1532 ReadOptionsFromStream(fin);
1536 fin.getline(buf,512);
1538 ReadVarsFromStream(fin);
1543 if (IsNormalised()) {
1549 if ( fVarTransformString ==
"None") {
1552 }
else if ( fVarTransformString ==
"Decorrelate" ) {
1554 }
else if ( fVarTransformString ==
"PCA" ) {
1555 varTrafo = GetTransformationHandler().AddTransformation(
new VariablePCATransform(DataInfo()), -1 );
1556 }
else if ( fVarTransformString ==
"Uniform" ) {
1557 varTrafo = GetTransformationHandler().AddTransformation(
new VariableGaussTransform(DataInfo(),
"Uniform"), -1 );
1558 }
else if ( fVarTransformString ==
"Gauss" ) {
1560 }
else if ( fVarTransformString ==
"GaussDecorr" ) {
1564 Log() <<
kFATAL <<
"<ProcessOptions> Variable transform '"
1565 << fVarTransformString <<
"' unknown." <<
Endl;
1568 if (GetTransformationHandler().GetTransformationList().GetSize() > 0) {
1569 fin.getline(buf,512);
1573 varTrafo->ReadTransformationFromStream(fin, trafo );
1584 fin.getline(buf,512);
1586 if (fMVAPdfS != 0) {
delete fMVAPdfS; fMVAPdfS = 0; }
1587 if (fMVAPdfB != 0) {
delete fMVAPdfB; fMVAPdfB = 0; }
1588 fMVAPdfS =
new PDF(
TString(GetName()) +
" MVA PDF Sig");
1589 fMVAPdfB =
new PDF(
TString(GetName()) +
" MVA PDF Bkg");
1590 fMVAPdfS->SetReadingVersion( GetTrainingTMVAVersionCode() );
1591 fMVAPdfB->SetReadingVersion( GetTrainingTMVAVersionCode() );
1598 fin.getline(buf,512);
1600 fin.getline(buf,512);
1601 ReadWeightsFromStream( fin );;
1604 if (GetTransformationHandler().GetCallerName() ==
"") GetTransformationHandler().SetCallerName( GetName() );
1614 o << prefix <<
"NVar " << DataInfo().GetNVariables() << std::endl;
1615 std::vector<VariableInfo>::const_iterator varIt = DataInfo().GetVariableInfos().begin();
1616 for (; varIt!=DataInfo().GetVariableInfos().end(); varIt++) { o << prefix; varIt->WriteToStream(o); }
1617 o << prefix <<
"NSpec " << DataInfo().GetNSpectators() << std::endl;
1618 varIt = DataInfo().GetSpectatorInfos().begin();
1619 for (; varIt!=DataInfo().GetSpectatorInfos().end(); varIt++) { o << prefix; varIt->WriteToStream(o); }
1631 istr >> dummy >> readNVar;
1633 if (readNVar!=DataInfo().GetNVariables()) {
1634 Log() <<
kFATAL <<
"You declared "<< DataInfo().GetNVariables() <<
" variables in the Reader"
1635 <<
" while there are " << readNVar <<
" variables declared in the file"
1641 std::vector<VariableInfo>::iterator varIt = DataInfo().GetVariableInfos().begin();
1643 for (; varIt!=DataInfo().GetVariableInfos().end(); varIt++, varIdx++) {
1650 Log() <<
kINFO <<
"ERROR in <ReadVarsFromStream>" <<
Endl;
1651 Log() <<
kINFO <<
"The definition (or the order) of the variables found in the input file is" <<
Endl;
1652 Log() <<
kINFO <<
"is not the same as the one declared in the Reader (which is necessary for" <<
Endl;
1653 Log() <<
kINFO <<
"the correct working of the method):" <<
Endl;
1654 Log() <<
kINFO <<
" var #" << varIdx <<
" declared in Reader: " << varIt->GetExpression() <<
Endl;
1656 Log() <<
kFATAL <<
"The expression declared to the Reader needs to be checked (name or order are wrong)" <<
Endl;
1669 for (
UInt_t idx=0; idx<DataInfo().GetVariableInfos().size(); idx++) {
1685 for (
UInt_t idx=0; idx<DataInfo().GetSpectatorInfos().size(); idx++) {
1687 VariableInfo& vi = DataInfo().GetSpectatorInfos()[idx];
1705 UInt_t nClasses=DataInfo().GetNClasses();
1710 for (
UInt_t iCls=0; iCls<nClasses; ++iCls) {
1711 ClassInfo *classInfo=DataInfo().GetClassInfo (iCls);
1728 for (
UInt_t idx=0; idx<DataInfo().GetTargetInfos().size(); idx++) {
1744 if (readNVar!=DataInfo().GetNVariables()) {
1745 Log() <<
kFATAL <<
"You declared "<< DataInfo().GetNVariables() <<
" variables in the Reader"
1746 <<
" while there are " << readNVar <<
" variables declared in the file"
1756 existingVarInfo = DataInfo().GetVariableInfos()[varIdx];
1761 existingVarInfo = readVarInfo;
1764 Log() <<
kINFO <<
"ERROR in <ReadVariablesFromXML>" <<
Endl;
1765 Log() <<
kINFO <<
"The definition (or the order) of the variables found in the input file is" <<
Endl;
1766 Log() <<
kINFO <<
"not the same as the one declared in the Reader (which is necessary for the" <<
Endl;
1767 Log() <<
kINFO <<
"correct working of the method):" <<
Endl;
1770 Log() <<
kFATAL <<
"The expression declared to the Reader needs to be checked (name or order are wrong)" <<
Endl;
1784 if (readNSpec!=DataInfo().GetNSpectators(
kFALSE)) {
1785 Log() <<
kFATAL <<
"You declared "<< DataInfo().GetNSpectators(
kFALSE) <<
" spectators in the Reader"
1786 <<
" while there are " << readNSpec <<
" spectators declared in the file"
1796 existingSpecInfo = DataInfo().GetSpectatorInfos()[specIdx];
1801 existingSpecInfo = readSpecInfo;
1804 Log() <<
kINFO <<
"ERROR in <ReadSpectatorsFromXML>" <<
Endl;
1805 Log() <<
kINFO <<
"The definition (or the order) of the spectators found in the input file is" <<
Endl;
1806 Log() <<
kINFO <<
"not the same as the one declared in the Reader (which is necessary for the" <<
Endl;
1807 Log() <<
kINFO <<
"correct working of the method):" <<
Endl;
1810 Log() <<
kFATAL <<
"The expression declared to the Reader needs to be checked (name or order are wrong)" <<
Endl;
1829 for (
UInt_t icls = 0; icls<readNCls;++icls) {
1831 DataInfo().AddClass(classname);
1839 DataInfo().AddClass(className);
1846 if (DataInfo().GetClassInfo(
"Signal") != 0) {
1847 fSignalClass = DataInfo().GetClassInfo(
"Signal")->GetNumber();
1851 if (DataInfo().GetClassInfo(
"Background") != 0) {
1852 fBackgroundClass = DataInfo().GetClassInfo(
"Background")->GetNumber();
1872 DataInfo().AddTarget(expression,
"",
"",0,0);
1884 if (fBaseDir != 0)
return fBaseDir;
1885 Log()<<
kDEBUG<<
" Base Directory for " << GetMethodTypeName() <<
" not set yet --> check if already there.." <<
Endl;
1889 Log() <<
kFATAL <<
"MethodBase::BaseDir() - MethodBaseDir() return a NULL pointer!" <<
Endl;
1910 wfilePath.Write(
"TrainingPath" );
1911 wfileName.Write(
"WeightFileName" );
1922 if (fMethodBaseDir != 0)
return fMethodBaseDir;
1924 Log()<<
kDEBUG<<
" Base Directory for " << GetMethodTypeName() <<
" not set yet --> check if already there.." <<
Endl;
1930 Log()<<
kDEBUG<<
" Base Directory for " << GetMethodTypeName() <<
" existed, return it.." <<
Endl;
1934 Log()<<
kDEBUG<<
" Base Directory for " << GetMethodTypeName() <<
" does not exist yet--> created it" <<
Endl;
1937 Log()<<
kDEBUG<<
"Return from MethodBaseDir() after creating base directory "<<
Endl;
1938 return fMethodBaseDir;
1955 fWeightFile = theWeightFile;
1963 if (fWeightFile!=
"")
return fWeightFile;
1968 TString wFileDir(GetWeightFileDir());
1969 return ( wFileDir + (wFileDir[wFileDir.
Length()-1]==
'/' ?
"" :
"/")
1982 if (0 != fMVAPdfS) {
1983 fMVAPdfS->GetOriginalHist()->Write();
1984 fMVAPdfS->GetSmoothedHist()->Write();
1985 fMVAPdfS->GetPDFHist()->Write();
1987 if (0 != fMVAPdfB) {
1988 fMVAPdfB->GetOriginalHist()->Write();
1989 fMVAPdfB->GetSmoothedHist()->Write();
1990 fMVAPdfB->GetPDFHist()->Write();
1996 Log() <<
kFATAL <<
"<WriteEvaluationHistosToFile> Unknown result: "
1998 <<
"/kMaxAnalysisType" <<
Endl;
2001 GetTransformationHandler().PlotVariables (GetEventCollection(
Types::kTesting ), BaseDir() );
2020 fin.getline(buf,512);
2026 std::stringstream s(code.
Data());
2027 s >> fTMVATrainingVersion;
2028 Log() <<
kINFO <<
"MVA method was trained with TMVA Version: " << GetTrainingTMVAVersionString() <<
Endl;
2034 std::stringstream s(code.
Data());
2035 s >> fROOTTrainingVersion;
2036 Log() <<
kINFO <<
"MVA method was trained with ROOT Version: " << GetTrainingROOTVersionString() <<
Endl;
2042 std::stringstream s(code.
Data());
2043 std::string analysisType;
2045 if (analysisType ==
"regression" || analysisType ==
"Regression") SetAnalysisType(
Types::kRegression );
2046 else if (analysisType ==
"classification" || analysisType ==
"Classification") SetAnalysisType(
Types::kClassification );
2047 else if (analysisType ==
"multiclass" || analysisType ==
"Multiclass") SetAnalysisType(
Types::kMulticlass );
2048 else Log() <<
kFATAL <<
"Analysis type " << analysisType <<
" from weight-file not known!" << std::endl;
2050 Log() <<
kINFO <<
"Method was trained for "
2070 if (mvaRes==0 || mvaRes->
GetSize()==0) {
2071 Log() <<
kERROR<<
"<CreateMVAPdfs> No result of classifier testing available" <<
Endl;
2078 TH1* histMVAPdfS =
new TH1D( GetMethodTypeName() +
"_tr_S", GetMethodTypeName() +
"_tr_S",
2079 fMVAPdfS->GetHistNBins( mvaRes->
GetSize() ), minVal, maxVal );
2080 TH1* histMVAPdfB =
new TH1D( GetMethodTypeName() +
"_tr_B", GetMethodTypeName() +
"_tr_B",
2081 fMVAPdfB->GetHistNBins( mvaRes->
GetSize() ), minVal, maxVal );
2085 histMVAPdfS->Sumw2();
2086 histMVAPdfB->
Sumw2();
2091 Double_t theWeight =
Data()->GetEvent(ievt)->GetWeight();
2093 if (DataInfo().IsSignal(
Data()->GetEvent(ievt))) histMVAPdfS->Fill( theVal, theWeight );
2094 else histMVAPdfB->
Fill( theVal, theWeight );
2101 histMVAPdfS->Write();
2102 histMVAPdfB->
Write();
2105 fMVAPdfS->BuildPDF ( histMVAPdfS );
2106 fMVAPdfB->BuildPDF ( histMVAPdfB );
2107 fMVAPdfS->ValidatePDF( histMVAPdfS );
2108 fMVAPdfB->ValidatePDF( histMVAPdfB );
2110 if (DataInfo().GetNClasses() == 2) {
2112 <<
Form(
"<CreateMVAPdfs> Separation from histogram (PDF): %1.3f (%1.3f)",
2113 GetSeparation( histMVAPdfS, histMVAPdfB ), GetSeparation( fMVAPdfS, fMVAPdfB ) )
2125 if (!fMVAPdfS || !fMVAPdfB) {
2126 Log() <<
kINFO <<
"<GetProba> MVA PDFs for Signal and Background don't exist yet, we'll create them on demand" <<
Endl;
2129 Double_t sigFraction = DataInfo().GetTrainingSumSignalWeights() / (DataInfo().GetTrainingSumSignalWeights() + DataInfo().GetTrainingSumBackgrWeights() );
2132 return GetProba(mvaVal,sigFraction);
2140 if (!fMVAPdfS || !fMVAPdfB) {
2141 Log() <<
kWARNING <<
"<GetProba> MVA PDFs for Signal and Background don't exist" <<
Endl;
2144 Double_t p_s = fMVAPdfS->GetVal( mvaVal );
2145 Double_t p_b = fMVAPdfB->GetVal( mvaVal );
2147 Double_t denom = p_s*ap_sig + p_b*(1 - ap_sig);
2149 return (denom > 0) ? (p_s*ap_sig) / denom : -1;
2160 Log() <<
kWARNING <<
"<GetRarity> Required MVA PDF for Signal or Backgroud does not exist: "
2161 <<
"select option \"CreateMVAPdfs\"" <<
Endl;
2176 Data()->SetCurrentType(type);
2185 if (!list || list->
GetSize() < 2) computeArea = kTRUE;
2186 else if (list->
GetSize() > 2) {
2187 Log() <<
kFATAL <<
"<GetEfficiency> Wrong number of arguments"
2188 <<
" in string: " << theString
2189 <<
" | required format, e.g., Efficiency:0.05, or empty string" <<
Endl;
2197 Log() <<
kFATAL <<
"<GetEfficiency> Binning mismatch between signal and background histos" <<
Endl;
2205 TH1 * effhist = results->
GetHist(
"MVA_HIGHBIN_S");
2212 if (results->
DoesExist(
"MVA_EFF_S")==0) {
2215 TH1* eff_s =
new TH1D( GetTestvarName() +
"_effS", GetTestvarName() +
" (signal)", fNbinsH, xmin, xmax );
2216 TH1* eff_b =
new TH1D( GetTestvarName() +
"_effB", GetTestvarName() +
" (background)", fNbinsH, xmin, xmax );
2217 results->
Store(eff_s,
"MVA_EFF_S");
2218 results->
Store(eff_b,
"MVA_EFF_B");
2221 Int_t sign = (fCutOrientation == kPositive) ? +1 : -1;
2225 for (
UInt_t ievt=0; ievt<
Data()->GetNEvents(); ievt++) {
2228 Bool_t isSignal = DataInfo().IsSignal(GetEvent(ievt));
2229 Float_t theWeight = GetEvent(ievt)->GetWeight();
2230 Float_t theVal = (*mvaRes)[ievt];
2233 TH1* theHist = isSignal ? eff_s : eff_b;
2236 if (isSignal) nevtS+=theWeight;
2240 if (sign > 0 && maxbin > fNbinsH)
continue;
2241 if (sign < 0 && maxbin < 1 )
continue;
2242 if (sign > 0 && maxbin < 1 ) maxbin = 1;
2243 if (sign < 0 && maxbin > fNbinsH) maxbin = fNbinsH;
2248 for (
Int_t ibin=maxbin+1; ibin<=fNbinsH; ibin++) theHist->
AddBinContent( ibin , theWeight );
2250 Log() <<
kFATAL <<
"<GetEfficiency> Mismatch in sign" <<
Endl;
2261 TH1* eff_BvsS =
new TH1D( GetTestvarName() +
"_effBvsS", GetTestvarName() +
"", fNbins, 0, 1 );
2262 results->
Store(eff_BvsS,
"MVA_EFF_BvsS");
2267 TH1* rej_BvsS =
new TH1D( GetTestvarName() +
"_rejBvsS", GetTestvarName() +
"", fNbins, 0, 1 );
2268 results->
Store(rej_BvsS);
2270 rej_BvsS->
SetYTitle(
"Backgr rejection (1-eff)" );
2273 TH1* inveff_BvsS =
new TH1D( GetTestvarName() +
"_invBeffvsSeff",
2274 GetTestvarName(), fNbins, 0, 1 );
2275 results->
Store(inveff_BvsS);
2277 inveff_BvsS->
SetYTitle(
"Inverse backgr. eff (1/eff)" );
2283 fSplRefS =
new TSpline1(
"spline2_signal",
new TGraph( eff_s ) );
2284 fSplRefB =
new TSpline1(
"spline2_background",
new TGraph( eff_b ) );
2296 RootFinder rootFinder( &IGetEffForRoot, fXmin, fXmax );
2300 for (
Int_t bini=1; bini<=fNbins; bini++) {
2322 Double_t effS = 0., rejB, effS_ = 0., rejB_ = 0.;
2323 Int_t nbins_ = 5000;
2324 for (
Int_t bini=1; bini<=nbins_; bini++) {
2327 effS = (bini - 0.5)/
Float_t(nbins_);
2328 rejB = 1.0 - fSpleffBvsS->Eval( effS );
2331 if ((effS - rejB)*(effS_ - rejB_) < 0)
break;
2338 SetSignalReferenceCut( cut );
2343 if (0 == fSpleffBvsS) {
2349 Double_t effS = 0, effB = 0, effS_ = 0, effB_ = 0;
2350 Int_t nbins_ = 1000;
2356 for (
Int_t bini=1; bini<=nbins_; bini++) {
2359 effS = (bini - 0.5)/
Float_t(nbins_);
2360 effB = fSpleffBvsS->Eval( effS );
2361 integral += (1.0 - effB);
2375 for (
Int_t bini=1; bini<=nbins_; bini++) {
2378 effS = (bini - 0.5)/
Float_t(nbins_);
2379 effB = fSpleffBvsS->Eval( effS );
2382 if ((effB - effBref)*(effB_ - effBref) <= 0)
break;
2388 effS = 0.5*(effS + effS_);
2391 if (nevtS > 0) effSerr =
TMath::Sqrt( effS*(1.0 - effS)/nevtS );
2416 Log() <<
kFATAL <<
"<GetTrainingEfficiency> Wrong number of arguments"
2417 <<
" in string: " << theString
2418 <<
" | required format, e.g., Efficiency:0.05" <<
Endl;
2431 Log() <<
kFATAL <<
"<GetTrainingEfficiency> Binning mismatch between signal and background histos"
2439 TH1 * effhist = results->
GetHist(
"MVA_HIGHBIN_S");
2444 if (results->
DoesExist(
"MVA_TRAIN_S")==0) {
2450 TH1* mva_s_tr =
new TH1D( GetTestvarName() +
"_Train_S",GetTestvarName() +
"_Train_S", fNbinsMVAoutput, fXmin, sxmax );
2451 TH1* mva_b_tr =
new TH1D( GetTestvarName() +
"_Train_B",GetTestvarName() +
"_Train_B", fNbinsMVAoutput, fXmin, sxmax );
2452 results->
Store(mva_s_tr,
"MVA_TRAIN_S");
2453 results->
Store(mva_b_tr,
"MVA_TRAIN_B");
2458 TH1* mva_eff_tr_s =
new TH1D( GetTestvarName() +
"_trainingEffS", GetTestvarName() +
" (signal)",
2459 fNbinsH, xmin, xmax );
2460 TH1* mva_eff_tr_b =
new TH1D( GetTestvarName() +
"_trainingEffB", GetTestvarName() +
" (background)",
2461 fNbinsH, xmin, xmax );
2462 results->
Store(mva_eff_tr_s,
"MVA_TRAINEFF_S");
2463 results->
Store(mva_eff_tr_b,
"MVA_TRAINEFF_B");
2466 Int_t sign = (fCutOrientation == kPositive) ? +1 : -1;
2469 for (
Int_t ievt=0; ievt<
Data()->GetNEvents(); ievt++) {
2471 Data()->SetCurrentEvent(ievt);
2472 const Event* ev = GetEvent();
2477 TH1* theEffHist = DataInfo().IsSignal(ev) ? mva_eff_tr_s : mva_eff_tr_b;
2478 TH1* theClsHist = DataInfo().IsSignal(ev) ? mva_s_tr : mva_b_tr;
2480 theClsHist->
Fill( theVal, theWeight );
2484 if (sign > 0 && maxbin > fNbinsH)
continue;
2485 if (sign < 0 && maxbin < 1 )
continue;
2486 if (sign > 0 && maxbin < 1 ) maxbin = 1;
2487 if (sign < 0 && maxbin > fNbinsH) maxbin = fNbinsH;
2489 if (sign > 0)
for (
Int_t ibin=1; ibin<=maxbin; ibin++) theEffHist->
AddBinContent( ibin , theWeight );
2490 else for (
Int_t ibin=maxbin+1; ibin<=fNbinsH; ibin++) theEffHist->
AddBinContent( ibin , theWeight );
2503 TH1* eff_bvss =
new TH1D( GetTestvarName() +
"_trainingEffBvsS", GetTestvarName() +
"", fNbins, 0, 1 );
2505 TH1* rej_bvss =
new TH1D( GetTestvarName() +
"_trainingRejBvsS", GetTestvarName() +
"", fNbins, 0, 1 );
2506 results->
Store(eff_bvss,
"EFF_BVSS_TR");
2507 results->
Store(rej_bvss,
"REJ_BVSS_TR");
2513 if (fSplTrainRefS)
delete fSplTrainRefS;
2514 if (fSplTrainRefB)
delete fSplTrainRefB;
2515 fSplTrainRefS =
new TSpline1(
"spline2_signal",
new TGraph( mva_eff_tr_s ) );
2516 fSplTrainRefB =
new TSpline1(
"spline2_background",
new TGraph( mva_eff_tr_b ) );
2528 RootFinder rootFinder(&IGetEffForRoot, fXmin, fXmax );
2531 fEffS = results->
GetHist(
"MVA_TRAINEFF_S");
2532 for (
Int_t bini=1; bini<=fNbins; bini++) {
2550 fSplTrainEffBvsS =
new TSpline1(
"effBvsS",
new TGraph( eff_bvss ) );
2554 if (0 == fSplTrainEffBvsS)
return 0.0;
2557 Double_t effS = 0., effB, effS_ = 0., effB_ = 0.;
2558 Int_t nbins_ = 1000;
2559 for (
Int_t bini=1; bini<=nbins_; bini++) {
2562 effS = (bini - 0.5)/
Float_t(nbins_);
2563 effB = fSplTrainEffBvsS->Eval( effS );
2566 if ((effB - effBref)*(effB_ - effBref) <= 0)
break;
2571 return 0.5*(effS + effS_);
2581 if (!resMulticlass)
Log() <<
kFATAL<<
"unable to create pointer in GetMulticlassEfficiency, exiting."<<
Endl;
2593 if (!resMulticlass)
Log() <<
kFATAL<<
"unable to create pointer in GetMulticlassTrainingEfficiency, exiting."<<
Endl;
2595 Log() <<
kINFO <<
"Determine optimal multiclass cuts for training data..." <<
Endl;
2596 for (
UInt_t icls = 0; icls<DataInfo().GetNClasses(); ++icls) {
2613 return (rms > 0) ?
TMath::Abs(fMeanS - fMeanB)/rms : 0;
2633 if ((!pdfS && pdfB) || (pdfS && !pdfB))
2634 Log() <<
kFATAL <<
"<GetSeparation> Mismatch in pdfs" <<
Endl;
2635 if (!pdfS) pdfS = fSplS;
2636 if (!pdfB) pdfB = fSplB;
2638 if (!fSplS || !fSplB) {
2639 Log()<<
kWARNING<<
"could not calculate the separation, distributions"
2640 <<
" fSplS or fSplB are not yet filled" <<
Endl;
2655 if ((!histS && histB) || (histS && !histB))
2656 Log() <<
kFATAL <<
"<GetROCIntegral(TH1D*, TH1D*)> Mismatch in hists" <<
Endl;
2658 if (histS==0 || histB==0)
return 0.;
2671 for (
UInt_t i=0; i<nsteps; i++) {
2675 return integral*step;
2687 if ((!pdfS && pdfB) || (pdfS && !pdfB))
2688 Log() <<
kFATAL <<
"<GetSeparation> Mismatch in pdfs" <<
Endl;
2689 if (!pdfS) pdfS = fSplS;
2690 if (!pdfB) pdfB = fSplB;
2692 if (pdfS==0 || pdfB==0)
return 0.;
2701 for (
UInt_t i=0; i<nsteps; i++) {
2705 return integral*step;
2715 Double_t& max_significance_value )
const
2720 Double_t effS(0),effB(0),significance(0);
2721 TH1D *temp_histogram =
new TH1D(
"temp",
"temp", fNbinsH, fXmin, fXmax );
2723 if (SignalEvents <= 0 || BackgroundEvents <= 0) {
2724 Log() <<
kFATAL <<
"<GetMaximumSignificance> "
2725 <<
"Number of signal or background events is <= 0 ==> abort"
2729 Log() <<
kINFO <<
"Using ratio SignalEvents/BackgroundEvents = "
2730 << SignalEvents/BackgroundEvents <<
Endl;
2735 if ( (eff_s==0) || (eff_b==0) ) {
2741 for (
Int_t bin=1; bin<=fNbinsH; bin++) {
2746 significance =
sqrt(SignalEvents)*( effS )/
sqrt( effS + ( BackgroundEvents / SignalEvents) * effB );
2756 delete temp_histogram;
2758 Log() <<
kINFO <<
"Optimal cut at : " << max_significance <<
Endl;
2759 Log() <<
kINFO <<
"Maximum significance: " << max_significance_value <<
Endl;
2761 return max_significance;
2775 Data()->SetCurrentType(treeType);
2781 Log() <<
kFATAL <<
"<CalculateEstimator> Wrong tree type: " << treeType <<
Endl;
2784 UInt_t varIndex = DataInfo().FindVarIndex( theVarName );
2800 for (
Int_t ievt = 0; ievt < entries; ievt++) {
2802 const Event* ev = GetEvent(ievt);
2807 if (DataInfo().IsSignal(ev)) {
2809 meanS += weight*theVar;
2810 rmsS += weight*theVar*theVar;
2814 meanB += weight*theVar;
2815 rmsB += weight*theVar*theVar;
2823 meanS = meanS/sumwS;
2824 meanB = meanB/sumwB;
2828 Data()->SetCurrentType(previousTreeType);
2838 if (theClassFileName ==
"")
2839 classFileName = GetWeightFileDir() +
"/" + GetJobName() +
"_" +
GetMethodName() +
".class.C";
2841 classFileName = theClassFileName;
2845 TString tfname( classFileName );
2846 Log() <<
kINFO <<
"Creating standalone response class: "
2849 std::ofstream fout( classFileName );
2851 Log() <<
kFATAL <<
"<MakeClass> Unable to open file: " << classFileName <<
Endl;
2856 fout <<
"// Class: " << className << std::endl;
2857 fout <<
"// Automatically generated by MethodBase::MakeClass" << std::endl <<
"//" << std::endl;
2861 fout <<
"/* configuration options =====================================================" << std::endl << std::endl;
2862 WriteStateToStream( fout );
2864 fout <<
"============================================================================ */" << std::endl;
2867 fout <<
"" << std::endl;
2868 fout <<
"#include <vector>" << std::endl;
2869 fout <<
"#include <cmath>" << std::endl;
2870 fout <<
"#include <string>" << std::endl;
2871 fout <<
"#include <iostream>" << std::endl;
2872 fout <<
"" << std::endl;
2875 this->MakeClassSpecificHeader( fout, className );
2877 fout <<
"#ifndef IClassifierReader__def" << std::endl;
2878 fout <<
"#define IClassifierReader__def" << std::endl;
2880 fout <<
"class IClassifierReader {" << std::endl;
2882 fout <<
" public:" << std::endl;
2884 fout <<
" // constructor" << std::endl;
2885 fout <<
" IClassifierReader() : fStatusIsClean( true ) {}" << std::endl;
2886 fout <<
" virtual ~IClassifierReader() {}" << std::endl;
2888 fout <<
" // return classifier response" << std::endl;
2889 fout <<
" virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;" << std::endl;
2891 fout <<
" // returns classifier status" << std::endl;
2892 fout <<
" bool IsStatusClean() const { return fStatusIsClean; }" << std::endl;
2894 fout <<
" protected:" << std::endl;
2896 fout <<
" bool fStatusIsClean;" << std::endl;
2897 fout <<
"};" << std::endl;
2899 fout <<
"#endif" << std::endl;
2901 fout <<
"class " << className <<
" : public IClassifierReader {" << std::endl;
2903 fout <<
" public:" << std::endl;
2905 fout <<
" // constructor" << std::endl;
2906 fout <<
" " << className <<
"( std::vector<std::string>& theInputVars ) " << std::endl;
2907 fout <<
" : IClassifierReader()," << std::endl;
2908 fout <<
" fClassName( \"" << className <<
"\" )," << std::endl;
2909 fout <<
" fNvars( " << GetNvar() <<
" )," << std::endl;
2910 fout <<
" fIsNormalised( " << (IsNormalised() ?
"true" :
"false") <<
" )" << std::endl;
2911 fout <<
" { " << std::endl;
2912 fout <<
" // the training input variables" << std::endl;
2913 fout <<
" const char* inputVars[] = { ";
2914 for (
UInt_t ivar=0; ivar<GetNvar(); ivar++) {
2915 fout <<
"\"" << GetOriginalVarName(ivar) <<
"\"";
2916 if (ivar<GetNvar()-1) fout <<
", ";
2918 fout <<
" };" << std::endl;
2920 fout <<
" // sanity checks" << std::endl;
2921 fout <<
" if (theInputVars.size() <= 0) {" << std::endl;
2922 fout <<
" std::cout << \"Problem in class \\\"\" << fClassName << \"\\\": empty input vector\" << std::endl;" << std::endl;
2923 fout <<
" fStatusIsClean = false;" << std::endl;
2924 fout <<
" }" << std::endl;
2926 fout <<
" if (theInputVars.size() != fNvars) {" << std::endl;
2927 fout <<
" std::cout << \"Problem in class \\\"\" << fClassName << \"\\\": mismatch in number of input values: \"" << std::endl;
2928 fout <<
" << theInputVars.size() << \" != \" << fNvars << std::endl;" << std::endl;
2929 fout <<
" fStatusIsClean = false;" << std::endl;
2930 fout <<
" }" << std::endl;
2932 fout <<
" // validate input variables" << std::endl;
2933 fout <<
" for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {" << std::endl;
2934 fout <<
" if (theInputVars[ivar] != inputVars[ivar]) {" << std::endl;
2935 fout <<
" std::cout << \"Problem in class \\\"\" << fClassName << \"\\\": mismatch in input variable names\" << std::endl" << std::endl;
2936 fout <<
" << \" for variable [\" << ivar << \"]: \" << theInputVars[ivar].c_str() << \" != \" << inputVars[ivar] << std::endl;" << std::endl;
2937 fout <<
" fStatusIsClean = false;" << std::endl;
2938 fout <<
" }" << std::endl;
2939 fout <<
" }" << std::endl;
2941 fout <<
" // initialize min and max vectors (for normalisation)" << std::endl;
2942 for (
UInt_t ivar = 0; ivar < GetNvar(); ivar++) {
2943 fout <<
" fVmin[" << ivar <<
"] = " << std::setprecision(15) << GetXmin( ivar ) <<
";" << std::endl;
2944 fout <<
" fVmax[" << ivar <<
"] = " << std::setprecision(15) << GetXmax( ivar ) <<
";" << std::endl;
2947 fout <<
" // initialize input variable types" << std::endl;
2948 for (
UInt_t ivar=0; ivar<GetNvar(); ivar++) {
2949 fout <<
" fType[" << ivar <<
"] = \'" << DataInfo().GetVariableInfo(ivar).GetVarType() <<
"\';" << std::endl;
2952 fout <<
" // initialize constants" << std::endl;
2953 fout <<
" Initialize();" << std::endl;
2955 if (GetTransformationHandler().GetTransformationList().GetSize() != 0) {
2956 fout <<
" // initialize transformation" << std::endl;
2957 fout <<
" InitTransform();" << std::endl;
2959 fout <<
" }" << std::endl;
2961 fout <<
" // destructor" << std::endl;
2962 fout <<
" virtual ~" << className <<
"() {" << std::endl;
2963 fout <<
" Clear(); // method-specific" << std::endl;
2964 fout <<
" }" << std::endl;
2966 fout <<
" // the classifier response" << std::endl;
2967 fout <<
" // \"inputValues\" is a vector of input values in the same order as the " << std::endl;
2968 fout <<
" // variables given to the constructor" << std::endl;
2969 fout <<
" double GetMvaValue( const std::vector<double>& inputValues ) const;" << std::endl;
2971 fout <<
" private:" << std::endl;
2973 fout <<
" // method-specific destructor" << std::endl;
2974 fout <<
" void Clear();" << std::endl;
2976 if (GetTransformationHandler().GetTransformationList().GetSize()!=0) {
2977 fout <<
" // input variable transformation" << std::endl;
2978 GetTransformationHandler().MakeFunction(fout, className,1);
2979 fout <<
" void InitTransform();" << std::endl;
2980 fout <<
" void Transform( std::vector<double> & iv, int sigOrBgd ) const;" << std::endl;
2983 fout <<
" // common member variables" << std::endl;
2984 fout <<
" const char* fClassName;" << std::endl;
2986 fout <<
" const size_t fNvars;" << std::endl;
2987 fout <<
" size_t GetNvar() const { return fNvars; }" << std::endl;
2988 fout <<
" char GetType( int ivar ) const { return fType[ivar]; }" << std::endl;
2990 fout <<
" // normalisation of input variables" << std::endl;
2991 fout <<
" const bool fIsNormalised;" << std::endl;
2992 fout <<
" bool IsNormalised() const { return fIsNormalised; }" << std::endl;
2993 fout <<
" double fVmin[" << GetNvar() <<
"];" << std::endl;
2994 fout <<
" double fVmax[" << GetNvar() <<
"];" << std::endl;
2995 fout <<
" double NormVariable( double x, double xmin, double xmax ) const {" << std::endl;
2996 fout <<
" // normalise to output range: [-1, 1]" << std::endl;
2997 fout <<
" return 2*(x - xmin)/(xmax - xmin) - 1.0;" << std::endl;
2998 fout <<
" }" << std::endl;
3000 fout <<
" // type of input variable: 'F' or 'I'" << std::endl;
3001 fout <<
" char fType[" << GetNvar() <<
"];" << std::endl;
3003 fout <<
" // initialize internal variables" << std::endl;
3004 fout <<
" void Initialize();" << std::endl;
3005 fout <<
" double GetMvaValue__( const std::vector<double>& inputValues ) const;" << std::endl;
3006 fout <<
"" << std::endl;
3007 fout <<
" // private members (method specific)" << std::endl;
3010 MakeClassSpecific( fout, className );
3012 fout <<
" inline double " << className <<
"::GetMvaValue( const std::vector<double>& inputValues ) const" << std::endl;
3013 fout <<
" {" << std::endl;
3014 fout <<
" // classifier response value" << std::endl;
3015 fout <<
" double retval = 0;" << std::endl;
3017 fout <<
" // classifier response, sanity check first" << std::endl;
3018 fout <<
" if (!IsStatusClean()) {" << std::endl;
3019 fout <<
" std::cout << \"Problem in class \\\"\" << fClassName << \"\\\": cannot return classifier response\"" << std::endl;
3020 fout <<
" << \" because status is dirty\" << std::endl;" << std::endl;
3021 fout <<
" retval = 0;" << std::endl;
3022 fout <<
" }" << std::endl;
3023 fout <<
" else {" << std::endl;
3024 fout <<
" if (IsNormalised()) {" << std::endl;
3025 fout <<
" // normalise variables" << std::endl;
3026 fout <<
" std::vector<double> iV;" << std::endl;
3027 fout <<
" iV.reserve(inputValues.size());" << std::endl;
3028 fout <<
" int ivar = 0;" << std::endl;
3029 fout <<
" for (std::vector<double>::const_iterator varIt = inputValues.begin();" << std::endl;
3030 fout <<
" varIt != inputValues.end(); varIt++, ivar++) {" << std::endl;
3031 fout <<
" iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));" << std::endl;
3032 fout <<
" }" << std::endl;
3033 if (GetTransformationHandler().GetTransformationList().GetSize()!=0 &&
3036 fout <<
" Transform( iV, -1 );" << std::endl;
3038 fout <<
" retval = GetMvaValue__( iV );" << std::endl;
3039 fout <<
" }" << std::endl;
3040 fout <<
" else {" << std::endl;
3041 if (GetTransformationHandler().GetTransformationList().GetSize()!=0 &&
3044 fout <<
" std::vector<double> iV;" << std::endl;
3045 fout <<
" int ivar = 0;" << std::endl;
3046 fout <<
" for (std::vector<double>::const_iterator varIt = inputValues.begin();" << std::endl;
3047 fout <<
" varIt != inputValues.end(); varIt++, ivar++) {" << std::endl;
3048 fout <<
" iV.push_back(*varIt);" << std::endl;
3049 fout <<
" }" << std::endl;
3050 fout <<
" Transform( iV, -1 );" << std::endl;
3051 fout <<
" retval = GetMvaValue__( iV );" << std::endl;
3054 fout <<
" retval = GetMvaValue__( inputValues );" << std::endl;
3056 fout <<
" }" << std::endl;
3057 fout <<
" }" << std::endl;
3059 fout <<
" return retval;" << std::endl;
3060 fout <<
" }" << std::endl;
3063 if (GetTransformationHandler().GetTransformationList().GetSize()!=0)
3064 GetTransformationHandler().MakeFunction(fout, className,2);
3076 std::streambuf* cout_sbuf = std::cout.rdbuf();
3077 std::ofstream* o = 0;
3078 if (
gConfig().WriteOptionsReference()) {
3079 Log() <<
kINFO <<
"Print Help message for class " << GetName() <<
" into file: " << GetReferenceFile() <<
Endl;
3080 o =
new std::ofstream( GetReferenceFile(), std::ios::app );
3082 Log() <<
kFATAL <<
"<PrintHelpMessage> Unable to append to output file: " << GetReferenceFile() <<
Endl;
3084 std::cout.rdbuf( o->rdbuf() );
3091 <<
"================================================================"
3095 <<
"H e l p f o r M V A m e t h o d [ " << GetName() <<
" ] :"
3100 Log() <<
"Help for MVA method [ " << GetName() <<
" ] :" <<
Endl;
3108 Log() <<
"<Suppress this message by specifying \"!H\" in the booking option>" <<
Endl;
3110 <<
"================================================================"
3117 Log() <<
"# End of Message___" <<
Endl;
3120 std::cout.rdbuf( cout_sbuf );
3143 retval = fSplRefS->Eval( theCut );
3145 else retval = fEffS->GetBinContent( fEffS->FindBin( theCut ) );
3154 if (theCut-fXmin < eps) retval = (GetCutOrientation() == kPositive) ? 1.0 : 0.0;
3155 else if (fXmax-theCut < eps) retval = (GetCutOrientation() == kPositive) ? 0.0 : 1.0;
3168 if (GetTransformationHandler().GetTransformationList().GetEntries() <= 0) {
3169 return (
Data()->GetEventCollection(type));
3176 if (fEventCollections.at(idx) == 0) {
3177 fEventCollections.at(idx) = &(
Data()->GetEventCollection(type));
3178 fEventCollections.at(idx) = GetTransformationHandler().CalcTransformations(*(fEventCollections.at(idx)),kTRUE);
3180 return *(fEventCollections.at(idx));
3188 UInt_t a = GetTrainingTMVAVersionCode() & 0xff0000; a>>=16;
3189 UInt_t b = GetTrainingTMVAVersionCode() & 0x00ff00; b>>=8;
3190 UInt_t c = GetTrainingTMVAVersionCode() & 0x0000ff;
3200 UInt_t a = GetTrainingROOTVersionCode() & 0xff0000; a>>=16;
3201 UInt_t b = GetTrainingROOTVersionCode() & 0x00ff00; b>>=8;
3202 UInt_t c = GetTrainingROOTVersionCode() & 0x0000ff;
3212 return GetThisBaseThreadLocal();
3220 GetThisBaseThreadLocal() =
this;
3228 if (mvaRes !=
NULL) {
3231 TH1D *mva_s_tr =
dynamic_cast<TH1D*
> (mvaRes->
GetHist(
"MVA_TRAIN_S"));
3232 TH1D *mva_b_tr =
dynamic_cast<TH1D*
> (mvaRes->
GetHist(
"MVA_TRAIN_B"));
3234 if ( !mva_s || !mva_b || !mva_s_tr || !mva_b_tr)
return -1;
3236 if (SorB ==
's' || SorB ==
'S')
virtual Int_t GetEntries() const
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
virtual void AddClassifierOutputProb(Types::ETreeType type)
prepare tree branch with the method's discriminating variable
virtual Int_t FindBin(Double_t x, Double_t y=0, Double_t z=0)
Return Global bin number corresponding to x,y,z.
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
virtual void SetTuneParameters(std::map< TString, Double_t > tuneParameters)
set the tuning parameters accoding to the argument This is just a dummy .
const TString & GetWeightFileDir() const
static TDirectory * RootBaseDir()
void AddInfoItem(void *gi, const TString &name, const TString &value) const
xml writing
#define TMVA_VERSION_CODE
MsgLogger & Endl(MsgLogger &ml)
TH1 * GetHist(const TString &alias) const
Bool_t GetLine(std::istream &fin, char *buf)
reads one line from the input stream checks for certain keywords and interprets the line if keywords ...
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
TString GetTrainingROOTVersionString() const
calculates the ROOT version string from the training version code on the fly
void AddOutput(Types::ETreeType type, Types::EAnalysisType analysisType)
static void CreateVariableTransforms(const TString &trafoDefinition, TMVA::DataSetInfo &dataInfo, TMVA::TransformationHandler &transformationHandler, TMVA::MsgLogger &log)
create variable transformations
virtual const char * WorkingDirectory()
Return working directory.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
void ReadStateFromXML(void *parent)
virtual Double_t GetMvaValue(Double_t *errLower=0, Double_t *errUpper=0)=0
void variables(TString fin="TMVA.root", TString dirName="InputVariables_Id", TString title="TMVA Input Variables", Bool_t isRegression=kFALSE, Bool_t useTMVAStyle=kTRUE)
Collectable string class.
virtual Int_t GetMaximumBin() const
Return location of bin with maximum value in the range.
const TString & GetExpression() const
TString & ReplaceAll(const TString &s1, const TString &s2)
virtual void WriteEvaluationHistosToFile(Types::ETreeType treetype)
writes all MVA evaluation histograms to file
TString GetTrainingTMVAVersionString() const
calculates the TMVA version string from the training version code on the fly
virtual std::map< TString, Double_t > OptimizeTuningParameters(TString fomType="ROCIntegral", TString fitType="FitGA")
call the Optimzier with the set of paremeters and ranges that are meant to be tuned.
XMLDocPointer_t NewDoc(const char *version="1.0")
creates new xml document with provided version
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
virtual Int_t GetQuantiles(Int_t nprobSum, Double_t *q, const Double_t *probSum=0)
Compute Quantiles for this histogram Quantile x_q of a probability distribution Function F is defined...
virtual int MakeDirectory(const char *name)
Make a directory.
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
virtual Double_t GetMaximumSignificance(Double_t SignalEvents, Double_t BackgroundEvents, Double_t &optimal_significance_value) const
plot significance, S/Sqrt(S^2 + B^2), curve for given number of signal and background events; returns...
static Bool_t AddDirectoryStatus()
static function: cannot be inlined on Windows/NT
1-D histogram with a float per channel (see TH1 documentation)}
Short_t Min(Short_t a, Short_t b)
void ToLower()
Change string to lower-case.
virtual Double_t GetKSTrainingVsTest(Char_t SorB, TString opt="X")
virtual void SetYTitle(const char *title)
virtual TDirectory * mkdir(const char *name, const char *title="")
Create a sub-directory and return a pointer to the created directory.
MethodBase(const TString &jobName, Types::EMVA methodType, const TString &methodTitle, DataSetInfo &dsi, const TString &theOption="", TDirectory *theBaseDir=0)
standard constructur
virtual void TestMulticlass()
test multiclass classification
virtual Int_t GetNbinsX() const
#define ROOT_VERSION_CODE
void ReadTargetsFromXML(void *tarnode)
read target info from XML
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not...
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
void FreeDoc(XMLDocPointer_t xmldoc)
frees allocated document data and deletes document itself
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
virtual Bool_t IsSignalLike()
uses a pre-set cut on the MVA output (SetSignalReferenceCut and SetSignalReferenceCutOrientation) for...
void CreateMVAPdfs()
Create PDFs of the MVA output variables.
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
TString GetWeightFileName() const
retrieve weight file name
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
void ReadVariablesFromXML(void *varnode)
read variable info from XML
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
const char * Data() const
static void SetIsTraining(Bool_t)
when this static function is called, it sets the flag whether events with negative event weight shoul...
void WriteStateToStream(std::ostream &tf) const
general method used in writing the header of the weight files where the used variables, variable transformation type etc.
virtual ~MethodBase()
destructor
void DocSetRootElement(XMLDocPointer_t xmldoc, XMLNodePointer_t xmlnode)
set main (root) node for document
void WriteVarsToStream(std::ostream &tf, const TString &prefix="") const
write the list of variables (name, min, max) for a given data transformation method to the stream ...
void Init(TClassEdit::TInterpreterLookupHelper *helper)
void ReadStateFromFile()
Function to write options and weights to file.
virtual void MakeClass(const TString &classFileName=TString("")) const
create reader class for method (classification only at present)
std::vector< Float_t > * GetValueVector()
virtual void AddClassifierOutput(Types::ETreeType type)
prepare tree branch with the method's discriminating variable
void ReadClassesFromXML(void *clsnode)
read number of classes from XML
void ResetThisBase()
reset required for RootFinder
std::vector< std::vector< double > > Data
void SetupMethod()
setup of methods
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
XMLDocPointer_t ParseString(const char *xmlstring)
parses content of string and tries to produce xml structures
Int_t Atoi() const
Return integer value of string.
virtual Double_t GetProba(const Event *ev)
virtual void AddBinContent(Int_t bin)
Increment bin content by 1.
virtual Double_t GetEfficiency(const TString &, Types::ETreeType, Double_t &err)
fill background efficiency (resp.
virtual std::vector< Float_t > GetMulticlassEfficiency(std::vector< std::vector< Float_t > > &purity)
Double_t GetEffForRoot(Double_t)
returns efficiency as function of cut
Double_t Root(Double_t refValue)
Root finding using Brents algorithm; taken from CERNLIB function RZERO.
TString GetElapsedTime(Bool_t Scientific=kTRUE)
void ReadStateFromXMLString(const char *xmlstr)
for reading from memory
void AddClassesXMLTo(void *parent) const
write class info to XML
void SaveDoc(XMLDocPointer_t xmldoc, const char *filename, Int_t layout=1)
store document content to file if layout<=0, no any spaces or newlines will be placed between xmlnode...
TString fWeightFileExtension
virtual Double_t GetBinCenter(Int_t bin) const
return bin center for 1D historam Better to use h1.GetXaxis().GetBinCenter(bin)
virtual Double_t GetMean(Int_t axis=1) const
For axis = 1,2 or 3 returns the mean value of the histogram along X,Y or Z axis.
std::string GetMethodName(TCppMethod_t)
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Double_t length(const TVector2 &v)
Class to manage histogram axis.
R__EXTERN TSystem * gSystem
virtual const char * GetBuildNode() const
Return the build node name.
Bool_t DoesExist(const TString &alias) const
void ReadVarsFromStream(std::istream &istr)
Read the variables (name, min, max) for a given data transformation method from the stream...
virtual void WriteMonitoringHistosToFile() const
write special monitoring histograms to file dummy implementation here --------------— ...
const Int_t NBIN_HIST_HIGH
2-D histogram with a float per channel (see TH1 documentation)}
class TMVA::Config::VariablePlotting fVariablePlotting
ClassInfo * GetClassInfo(Int_t clNum) const
void Statistics(Types::ETreeType treeType, const TString &theVarName, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &, Double_t &)
calculates rms,mean, xmin, xmax of the event variable this can be either done for the variables as th...
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
Float_t GetAchievablePur(UInt_t cls)
void SetValue(Float_t value, Int_t ievt)
set MVA response
virtual Double_t KolmogorovTest(const TH1 *h2, Option_t *option="") const
Statistical test of compatibility in shape between this histogram and h2, using Kolmogorov test...
Double_t ElapsedSeconds(void)
computes elapsed tim in seconds
char * Form(const char *fmt,...)
void ReadFromXML(void *varnode)
read VariableInfo from stream
const TString & GetName() const
TSubString Strip(EStripType s=kTrailing, char c= ' ') const
Return a substring of self stripped at beginning and/or end.
virtual Double_t GetSignificance() const
compute significance of mean difference significance = | - |/Sqrt(RMS_S2 + RMS_B2) ...
void DeclareBaseOptions()
define the options (their key words) that can be set in the option string here the options valid for ...
1-D histogram with a double per channel (see TH1 documentation)}
void ProcessBaseOptions()
the option string is decoded, for availabel options see "DeclareOptions"
void WriteStateToFile() const
write options and weights to file note that each one text file for the main configuration information...
void AddTargetsXMLTo(void *parent) const
write target info to XML
virtual TObject * FindObject(const char *name) const
Find object by name in the list of memory objects.
void DeclareOptions()
define the options (their key words) that can be set in the option string know options: PDFInterpol[i...
TString & Remove(Ssiz_t pos)
void AddVarsXMLTo(void *parent) const
write variable info to XML
TList * GetStorage() const
static void SetIgnoreNegWeightsInTraining(Bool_t)
when this static function is called, it sets the flag whether events with negative event weight shoul...
XMLDocPointer_t ParseFile(const char *filename, Int_t maxbuf=100000)
Parses content of file and tries to produce xml structures.
const std::vector< TMVA::Event * > & GetEventCollection(Types::ETreeType type)
returns the event collection (i.e.
virtual Int_t GetSize() const
virtual void CheckSetup()
check may be overridden by derived class (sometimes, eg, fitters are used which can only be implement...
virtual void AddRegressionOutput(Types::ETreeType type)
prepare tree branch with the method's discriminating variable
Double_t GetVal(Double_t x) const
returns value PDF(x)
std::vector< Double_t > GetBestMultiClassCuts(UInt_t targetClass)
void SetWeightFileName(TString)
set the weight file name (depreciated)
Describe directory structure in memory.
virtual Double_t GetROCIntegral(TH1D *histS, TH1D *histB) const
calculate the area (integral) under the ROC curve as a overall quality measure of the classification ...
TDirectory * BaseDir() const
returns the ROOT directory where info/histograms etc of the corresponding MVA method instance are sto...
static RooMathCoreReg dummy
const Bool_t Use_Splines_for_Eff_
virtual void GetRegressionDeviation(UInt_t tgtNum, Types::ETreeType type, Double_t &stddev, Double_t &stddev90Percent) const
void ProcessSetup()
process all options the "CheckForUnusedOptions" is done in an independent call, since it may be overr...
virtual void AddMulticlassOutput(Types::ETreeType type)
prepare tree branch with the method's discriminating variable
Mother of all ROOT objects.
Float_t GetTarget(UInt_t itgt) const
void * GetExternalLink() const
Float_t GetAchievableEff(UInt_t cls)
virtual Double_t GetSeparation(TH1 *, TH1 *) const
compute "separation" defined as = (1/2) Int_-oo..+oo { (S(x) - B(x))^2/(S(x) + B(x)) dx } ...
virtual std::vector< Float_t > GetMulticlassTrainingEfficiency(std::vector< std::vector< Float_t > > &purity)
virtual void SetXTitle(const char *title)
virtual void TestRegression(Double_t &bias, Double_t &biasT, Double_t &dev, Double_t &devT, Double_t &rms, Double_t &rmsT, Double_t &mInf, Double_t &mInfT, Double_t &corr, Types::ETreeType type)
calculate of regression output versus "true" value from test sample ...
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
void ReadFromStream(std::istream &istr)
void PrintHelpMessage() const
prints out method-specific help method
static MethodBase * GetThisBase()
return a pointer the base class of this method
virtual void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility they are hence without any...
Short_t Max(Short_t a, Short_t b)
void AddToXML(void *varnode)
write class to XML
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TDirectory * MethodBaseDir() const
returns the ROOT directory where all instances of the corresponding MVA method are stored ...
void SetWeightFileDir(TString fileDir)
set directory of weight file
XMLNodePointer_t DocGetRootElement(XMLDocPointer_t xmldoc)
returns root node of document
void AddSpectatorsXMLTo(void *parent) const
write spectator info to XML
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
A Graph is a graphics object made of two arrays X and Y with npoints each.
virtual TDirectory * GetDirectory(const char *namecycle, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory using apath.
virtual Int_t Sizeof() const
Returns size string will occupy on I/O buffer.
virtual Double_t GetTrainingEfficiency(const TString &)
Double_t GetIntegral(Double_t xmin, Double_t xmax)
computes PDF integral within given ranges
void ReadSpectatorsFromXML(void *specnode)
read spectator info from XML
void DrawProgressBar(Int_t, const TString &comment="")
draws progress bar in color or B&W caution:
void InitBase()
default initialization called by all constructors
void Store(TObject *obj, const char *alias=0)
virtual Double_t GetRarity(Double_t mvaVal, Types::ESBType reftype=Types::kBackground) const
compute rarity: R(x) = Integrate_[-oo..x] { PDF(x') dx' } where PDF(x) is the PDF of the classifier's...
static Double_t IGetEffForRoot(Double_t)
interface for RootFinder
Double_t Sqrt(Double_t x)
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
const char * AsString() const
Return the date & time as a string (ctime() format).
virtual Double_t GetMaximum(Double_t maxval=FLT_MAX) const
Return maximum value smaller than maxval of bins in the range, unless the value has been overridden b...
Int_t Fill(Double_t)
Invalid Fill method.
void SetTestvarName(const TString &v="")
double norm(double *x, double *p)
void WriteStateToXML(void *parent) const
general method used in writing the header of the weight files where the used variables, variable transformation type etc.
virtual void TestClassification()
initialization
void ReadStateFromStream(std::istream &tf)
read the header from the weight files of the different MVA methods
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write all objects in this collection.
void SetExternalLink(void *p)
void Resize(Int_t entries)
Ssiz_t First(char c) const
Find first occurrence of a character c.
void NoErrorCalc(Double_t *const err, Double_t *const errUpper)
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
virtual void Close(Option_t *option="")
Close a file.