141 #pragma warning ( disable : 4355 )
163 fMultiGraph =
nullptr;
177 std::cerr << kERROR <<
"IPythonInteractive::Init: already initialized..." << std::endl;
181 for(
auto& title : graphTitles){
182 fGraphs.push_back(
new TGraph() );
183 fGraphs.back()->SetTitle(title);
184 fGraphs.back()->SetName(title);
185 fGraphs.back()->SetFillColor(color);
186 fGraphs.back()->SetLineColor(color);
187 fGraphs.back()->SetMarkerColor(color);
188 fMultiGraph->Add(fGraphs.back());
200 for(
Int_t i=0; i<fNumGraphs; i++){
214 fGraphs[0]->Set(fIndex+1);
215 fGraphs[1]->Set(fIndex+1);
216 fGraphs[0]->SetPoint(fIndex, x, y1);
217 fGraphs[1]->SetPoint(fIndex, x, y2);
230 for(
Int_t i=0; i<fNumGraphs;i++){
231 fGraphs[i]->Set(fIndex+1);
232 fGraphs[i]->SetPoint(fIndex, dat[0], dat[i+1]);
252 fAnalysisType (
Types::kNoAnalysisType ),
253 fRegressionReturnVal ( 0 ),
254 fMulticlassReturnVal ( 0 ),
255 fDataSetInfo ( dsi ),
256 fSignalReferenceCut ( 0.5 ),
257 fSignalReferenceCutOrientation( 1. ),
258 fVariableTransformType (
Types::kSignal ),
259 fJobName ( jobName ),
260 fMethodName ( methodTitle ),
261 fMethodType ( methodType ),
265 fConstructedFromWeightFile (
kFALSE ),
267 fMethodBaseDir ( 0 ),
270 fModelPersistence (kTRUE),
281 fSplTrainEffBvsS ( 0 ),
282 fVarTransformString (
"None" ),
283 fTransformationPointer ( 0 ),
284 fTransformation ( dsi, methodTitle ),
286 fVerbosityLevelString (
"Default" ),
289 fIgnoreNegWeightsInTraining(
kFALSE ),
291 fBackgroundClass ( 0 ),
316 fAnalysisType (
Types::kNoAnalysisType ),
317 fRegressionReturnVal ( 0 ),
318 fMulticlassReturnVal ( 0 ),
319 fDataSetInfo ( dsi ),
320 fSignalReferenceCut ( 0.5 ),
321 fVariableTransformType (
Types::kSignal ),
323 fMethodName (
"MethodBase" ),
324 fMethodType ( methodType ),
326 fTMVATrainingVersion ( 0 ),
327 fROOTTrainingVersion ( 0 ),
328 fConstructedFromWeightFile ( kTRUE ),
330 fMethodBaseDir ( 0 ),
333 fModelPersistence (kTRUE),
334 fWeightFile ( weightFile ),
344 fSplTrainEffBvsS ( 0 ),
345 fVarTransformString (
"None" ),
346 fTransformationPointer ( 0 ),
347 fTransformation ( dsi,
"" ),
349 fVerbosityLevelString (
"Default" ),
352 fIgnoreNegWeightsInTraining(
kFALSE ),
354 fBackgroundClass ( 0 ),
372 if (!fSetupCompleted)
Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"Calling destructor of method which got never setup" <<
Endl;
375 if (fInputVars != 0) { fInputVars->clear();
delete fInputVars; }
376 if (fRanking != 0)
delete fRanking;
379 if (fDefaultPDF!= 0) {
delete fDefaultPDF; fDefaultPDF = 0; }
380 if (fMVAPdfS != 0) {
delete fMVAPdfS; fMVAPdfS = 0; }
381 if (fMVAPdfB != 0) {
delete fMVAPdfB; fMVAPdfB = 0; }
384 if (fSplS) {
delete fSplS; fSplS = 0; }
385 if (fSplB) {
delete fSplB; fSplB = 0; }
386 if (fSpleffBvsS) {
delete fSpleffBvsS; fSpleffBvsS = 0; }
387 if (fSplRefS) {
delete fSplRefS; fSplRefS = 0; }
388 if (fSplRefB) {
delete fSplRefB; fSplRefB = 0; }
389 if (fSplTrainRefS) {
delete fSplTrainRefS; fSplTrainRefS = 0; }
390 if (fSplTrainRefB) {
delete fSplTrainRefB; fSplTrainRefB = 0; }
391 if (fSplTrainEffBvsS) {
delete fSplTrainEffBvsS; fSplTrainEffBvsS = 0; }
393 for (
Int_t i = 0; i < 2; i++ ) {
394 if (fEventCollections.at(i)) {
395 for (std::vector<Event*>::const_iterator it = fEventCollections.at(i)->begin();
396 it != fEventCollections.at(i)->end(); it++) {
399 delete fEventCollections.at(i);
400 fEventCollections.at(i) = 0;
404 if (fRegressionReturnVal)
delete fRegressionReturnVal;
405 if (fMulticlassReturnVal)
delete fMulticlassReturnVal;
415 if (fSetupCompleted)
Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"Calling SetupMethod for the second time" <<
Endl;
417 DeclareBaseOptions();
420 fSetupCompleted =
kTRUE;
430 ProcessBaseOptions();
440 CheckForUnusedOptions();
448 SetConfigDescription(
"Configuration options for classifier architecture and tuning" );
456 fSplTrainEffBvsS = 0;
463 fTxtWeightsOnly =
kTRUE;
473 fInputVars =
new std::vector<TString>;
474 for (
UInt_t ivar=0; ivar<GetNvar(); ivar++) {
475 fInputVars->push_back(DataInfo().GetVariableInfo(ivar).GetLabel());
477 fRegressionReturnVal = 0;
478 fMulticlassReturnVal = 0;
480 fEventCollections.resize( 2 );
481 fEventCollections.at(0) = 0;
482 fEventCollections.at(1) = 0;
485 if (DataInfo().GetClassInfo(
"Signal") != 0) {
486 fSignalClass = DataInfo().GetClassInfo(
"Signal")->GetNumber();
488 if (DataInfo().GetClassInfo(
"Background") != 0) {
489 fBackgroundClass = DataInfo().GetClassInfo(
"Background")->GetNumber();
492 SetConfigDescription(
"Configuration options for MVA method" );
493 SetConfigName(
TString(
"Method") + GetMethodTypeName() );
516 DeclareOptionRef( fVerbose,
"V",
"Verbose output (short form of \"VerbosityLevel\" below - overrides the latter one)" );
518 DeclareOptionRef( fVerbosityLevelString=
"Default",
"VerbosityLevel",
"Verbosity level" );
519 AddPreDefVal(
TString(
"Default") );
520 AddPreDefVal(
TString(
"Debug") );
521 AddPreDefVal(
TString(
"Verbose") );
522 AddPreDefVal(
TString(
"Info") );
523 AddPreDefVal(
TString(
"Warning") );
524 AddPreDefVal(
TString(
"Error") );
525 AddPreDefVal(
TString(
"Fatal") );
529 fTxtWeightsOnly =
kTRUE;
532 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)\"" );
534 DeclareOptionRef( fHelp,
"H",
"Print method-specific help message" );
536 DeclareOptionRef( fHasMVAPdfs,
"CreateMVAPdfs",
"Create PDFs for classifier outputs (signal and background)" );
538 DeclareOptionRef( fIgnoreNegWeightsInTraining,
"IgnoreNegWeightsInTraining",
539 "Events with negative weights are ignored in the training (but are included for testing and performance evaluation)" );
552 fDefaultPDF->DeclareOptions();
553 fDefaultPDF->ParseOptions();
554 fDefaultPDF->ProcessOptions();
555 fMVAPdfB =
new PDF(
TString(
GetName())+
"_PDFBkg", fDefaultPDF->GetOptions(),
"MVAPdfBkg", fDefaultPDF );
557 fMVAPdfB->ParseOptions();
558 fMVAPdfB->ProcessOptions();
559 fMVAPdfS =
new PDF(
TString(
GetName())+
"_PDFSig", fMVAPdfB->GetOptions(),
"MVAPdfSig", fDefaultPDF );
561 fMVAPdfS->ParseOptions();
562 fMVAPdfS->ProcessOptions();
565 SetOptions( fMVAPdfS->GetOptions() );
570 GetTransformationHandler(),
574 if (fDefaultPDF!= 0) {
delete fDefaultPDF; fDefaultPDF = 0; }
575 if (fMVAPdfS != 0) {
delete fMVAPdfS; fMVAPdfS = 0; }
576 if (fMVAPdfB != 0) {
delete fMVAPdfB; fMVAPdfB = 0; }
580 fVerbosityLevelString =
TString(
"Verbose");
581 Log().SetMinType( kVERBOSE );
583 else if (fVerbosityLevelString ==
"Debug" )
Log().SetMinType( kDEBUG );
584 else if (fVerbosityLevelString ==
"Verbose" )
Log().SetMinType( kVERBOSE );
585 else if (fVerbosityLevelString ==
"Info" )
Log().SetMinType( kINFO );
586 else if (fVerbosityLevelString ==
"Warning" )
Log().SetMinType( kWARNING );
587 else if (fVerbosityLevelString ==
"Error" )
Log().SetMinType( kERROR );
588 else if (fVerbosityLevelString ==
"Fatal" )
Log().SetMinType( kFATAL );
589 else if (fVerbosityLevelString !=
"Default" ) {
590 Log() << kFATAL <<
"<ProcessOptions> Verbosity level type '"
591 << fVerbosityLevelString <<
"' unknown." <<
Endl;
603 DeclareOptionRef( fNormalise=
kFALSE,
"Normalise",
"Normalise input variables" );
604 DeclareOptionRef( fUseDecorr=
kFALSE,
"D",
"Use-decorrelated-variables flag" );
605 DeclareOptionRef( fVariableTransformTypeString=
"Signal",
"VarTransformType",
606 "Use signal or background events to derive for variable transformation (the transformation is applied on both types of, course)" );
607 AddPreDefVal(
TString(
"Signal") );
608 AddPreDefVal(
TString(
"Background") );
609 DeclareOptionRef( fTxtWeightsOnly=kTRUE,
"TxtWeightFilesOnly",
"If True: write all training results (weights) as text files (False: some are written in ROOT format)" );
619 DeclareOptionRef( fNbinsMVAPdf = 60,
"NbinsMVAPdf",
"Number of bins used for the PDFs of classifier outputs" );
620 DeclareOptionRef( fNsmoothMVAPdf = 2,
"NsmoothMVAPdf",
"Number of smoothing iterations for classifier PDFs" );
634 Log() << kWARNING <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"Parameter optimization is not yet implemented for method "
636 Log() << kWARNING <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"Currently we need to set hardcoded which parameter is tuned in which ranges"<<
Endl;
638 std::map<TString,Double_t> tunedParameters;
639 tunedParameters.size();
640 return tunedParameters;
661 if (Help()) PrintHelpMessage();
664 if(!IsSilentFile()) BaseDir()->cd();
668 GetTransformationHandler().CalcTransformations(
Data()->GetEventCollection());
672 <<
"Begin training" <<
Endl;
677 <<
"\tEnd of training " <<
Endl;
680 <<
"Elapsed time for training with " << nEvents <<
" events: "
684 <<
"\tCreate MVA output for ";
687 if (DoMulticlass()) {
688 Log() <<
Form(
"[%s] : ",DataInfo().
GetName())<<
"Multiclass classification on training sample" <<
Endl;
691 else if (!DoRegression()) {
693 Log() <<
Form(
"[%s] : ",DataInfo().
GetName())<<
"classification on training sample" <<
Endl;
702 Log() <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"regression on training sample" <<
Endl;
713 if (fModelPersistence ) WriteStateToFile();
716 if ((!DoRegression()) && (fModelPersistence)) MakeClass();
723 WriteMonitoringHistosToFile();
731 if (!DoRegression())
Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"Trying to use GetRegressionDeviation() with a classification job" <<
Endl;
734 bool truncate =
false;
735 TH1F*
h1 = regRes->QuadraticDeviation( tgtNum , truncate, 1.);
740 TH1F* h2 = regRes->QuadraticDeviation( tgtNum , truncate, yq[0]);
751 Data()->SetCurrentType(type);
764 regRes->Resize( nEvents );
766 Data()->SetCurrentEvent(ievt);
767 std::vector< Float_t > vals = GetRegressionValues();
768 regRes->SetValue( vals, ievt );
773 <<
"Elapsed time for evaluation of " << nEvents <<
" events: "
780 TString histNamePrefix(GetTestvarName());
782 regRes->CreateDeviationHistograms( histNamePrefix );
790 Data()->SetCurrentType(type);
795 if (!resMulticlass)
Log() << kFATAL<<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"unable to create pointer in AddMulticlassOutput, exiting."<<
Endl;
805 resMulticlass->Resize( nEvents );
807 Data()->SetCurrentEvent(ievt);
808 std::vector< Float_t > vals = GetMulticlassValues();
809 resMulticlass->SetValue( vals, ievt );
814 <<
"Elapsed time for evaluation of " << nEvents <<
" events: "
821 TString histNamePrefix(GetTestvarName());
823 resMulticlass->CreateMulticlassHistos( histNamePrefix, fNbinsMVAoutput, fNbinsH );
824 resMulticlass->CreateMulticlassPerformanceHistos(histNamePrefix);
831 if (errUpper) *errUpper=-1;
838 Double_t val = GetMvaValue(err, errUpper);
848 return GetMvaValue()*GetSignalReferenceCutOrientation() > GetSignalReferenceCut()*GetSignalReferenceCutOrientation() ? kTRUE :
kFALSE;
855 return mvaVal*GetSignalReferenceCutOrientation() > GetSignalReferenceCut()*GetSignalReferenceCutOrientation() ? kTRUE :
kFALSE;
863 Data()->SetCurrentType(type);
873 std::vector<Double_t> mvaValues = GetMvaValues(0, nEvents,
true);
881 clRes->
SetValue( mvaValues[ievt], ievt );
891 if (firstEvt > lastEvt || lastEvt > nEvents) lastEvt =
nEvents;
892 if (firstEvt < 0) firstEvt = 0;
893 std::vector<Double_t> values(lastEvt-firstEvt);
895 nEvents = values.size();
902 << (
Data()->GetCurrentType()==
Types::kTraining?
"training":
"testing") <<
" sample (" << nEvents <<
" events)" <<
Endl;
905 for (
Int_t ievt=firstEvt; ievt<lastEvt; ievt++) {
906 Data()->SetCurrentEvent(ievt);
907 values[ievt] = GetMvaValue();
912 if (modulo <= 0 ) modulo = 1;
918 <<
"Elapsed time for evaluation of " << nEvents <<
" events: "
930 Data()->SetCurrentType(type);
943 mvaProb->
Resize( nEvents );
946 Data()->SetCurrentEvent(ievt);
948 if (proba < 0)
break;
953 if (modulo <= 0 ) modulo = 1;
958 <<
"Elapsed time for evaluation of " << nEvents <<
" events: "
977 Data()->SetCurrentType(type);
979 bias = 0; biasT = 0; dev = 0; devT = 0; rms = 0; rmsT = 0;
981 Double_t m1 = 0, m2 = 0, s1 = 0, s2 = 0, s12 = 0;
982 const Int_t nevt = GetNEvents();
987 for (
Long64_t ievt=0; ievt<nevt; ievt++) {
989 const Event* ev =
Data()->GetEvent(ievt);
992 Float_t r = GetRegressionValues()[0];
1011 m1 += t*w; s1 += t*t*w;
1012 m2 += r*w; s2 += r*r*w;
1025 corr = s12/sumw - m1*m2;
1026 corr /=
TMath::Sqrt( (s1/sumw - m1*m1) * (s2/sumw - m2*m2) );
1029 TH2F* hist =
new TH2F(
"hist",
"hist", 150, xmin, xmax, 100, xmin, xmax );
1030 TH2F* histT =
new TH2F(
"histT",
"histT", 150, xmin, xmax, 100, xmin, xmax );
1037 for (
Long64_t ievt=0; ievt<nevt; ievt++) {
1038 Float_t d = (rV[ievt] - tV[ievt]);
1039 hist->
Fill( rV[ievt], tV[ievt], wV[ievt] );
1040 if (d >= devMin && d <= devMax) {
1042 biasT += wV[ievt] * d;
1044 rmsT += wV[ievt] * d * d;
1045 histT->
Fill( rV[ievt], tV[ievt], wV[ievt] );
1063 Data()->SetCurrentType(savedType);
1073 if (!resMulticlass)
Log() << kFATAL<<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"unable to create pointer in TestMulticlass, exiting."<<
Endl;
1074 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"Determine optimal multiclass cuts for test data..." <<
Endl;
1075 for (
UInt_t icls = 0; icls<DataInfo().GetNClasses(); ++icls) {
1092 if (0==mvaRes && !(GetMethodTypeName().Contains(
"Cuts"))) {
1093 Log()<<
Form(
"Dataset[%s] : ",DataInfo().
GetName()) <<
"mvaRes " << mvaRes <<
" GetMethodTypeName " << GetMethodTypeName()
1094 <<
" contains " << !(GetMethodTypeName().Contains(
"Cuts")) <<
Endl;
1095 Log() << kFATAL<<
Form(
"Dataset[%s] : ",DataInfo().
GetName()) <<
"<TestInit> Test variable " << GetTestvarName()
1096 <<
" not found in tree" <<
Endl;
1101 fMeanS, fMeanB, fRmsS, fRmsB, fXmin, fXmax, fSignalClass );
1109 fCutOrientation = (fMeanS > fMeanB) ? kPositive : kNegative;
1121 TestvarName=
Form(
"[%s]%s",DataInfo().
GetName(),GetTestvarName().
Data());
1124 TestvarName=GetTestvarName();
1126 TH1* mva_s =
new TH1D( TestvarName +
"_S",TestvarName +
"_S", fNbinsMVAoutput, fXmin, sxmax );
1127 TH1* mva_b =
new TH1D( TestvarName +
"_B",TestvarName +
"_B", fNbinsMVAoutput, fXmin, sxmax );
1128 mvaRes->
Store(mva_s,
"MVA_S");
1129 mvaRes->
Store(mva_b,
"MVA_B");
1139 proba_s =
new TH1D( TestvarName +
"_Proba_S", TestvarName +
"_Proba_S", fNbinsMVAoutput, 0.0, 1.0 );
1140 proba_b =
new TH1D( TestvarName +
"_Proba_B", TestvarName +
"_Proba_B", fNbinsMVAoutput, 0.0, 1.0 );
1141 mvaRes->
Store(proba_s,
"Prob_S");
1142 mvaRes->
Store(proba_b,
"Prob_B");
1147 rarity_s =
new TH1D( TestvarName +
"_Rarity_S", TestvarName +
"_Rarity_S", fNbinsMVAoutput, 0.0, 1.0 );
1148 rarity_b =
new TH1D( TestvarName +
"_Rarity_B", TestvarName +
"_Rarity_B", fNbinsMVAoutput, 0.0, 1.0 );
1149 mvaRes->
Store(rarity_s,
"Rar_S");
1150 mvaRes->
Store(rarity_b,
"Rar_B");
1156 TH1* mva_eff_s =
new TH1D( TestvarName +
"_S_high", TestvarName +
"_S_high", fNbinsH, fXmin, sxmax );
1157 TH1* mva_eff_b =
new TH1D( TestvarName +
"_B_high", TestvarName +
"_B_high", fNbinsH, fXmin, sxmax );
1158 mvaRes->
Store(mva_eff_s,
"MVA_HIGHBIN_S");
1159 mvaRes->
Store(mva_eff_b,
"MVA_HIGHBIN_B");
1168 Log() << kHEADER <<
Form(
"[%s] : ",DataInfo().
GetName())<<
"Loop over test events and fill histograms with classifier response..." <<
Endl <<
Endl;
1169 if (mvaProb)
Log() << kINFO <<
"Also filling probability and rarity histograms (on request)..." <<
Endl;
1173 if ( mvaRes->
GetSize() != GetNEvents() ) {
1174 Log() << kFATAL <<
TString::Format(
"Inconsistent result size %lld with number of events %u ", mvaRes->
GetSize() , GetNEvents() ) << Endl;
1175 assert(mvaRes->
GetSize() == GetNEvents());
1178 for (
Long64_t ievt=0; ievt<GetNEvents(); ievt++) {
1180 const Event* ev = GetEvent(ievt);
1184 if (DataInfo().IsSignal(ev)) {
1185 mvaResTypes->push_back(kTRUE);
1186 mva_s ->
Fill( v, w );
1188 proba_s->
Fill( (*mvaProb)[ievt][0], w );
1189 rarity_s->
Fill( GetRarity( v ), w );
1192 mva_eff_s ->
Fill( v, w );
1195 mvaResTypes->push_back(
kFALSE);
1196 mva_b ->
Fill( v, w );
1198 proba_b->
Fill( (*mvaProb)[ievt][0], w );
1199 rarity_b->
Fill( GetRarity( v ), w );
1201 mva_eff_b ->
Fill( v, w );
1216 if (fSplS) {
delete fSplS; fSplS = 0; }
1217 if (fSplB) {
delete fSplB; fSplB = 0; }
1231 tf << prefix <<
"#GEN -*-*-*-*-*-*-*-*-*-*-*- general info -*-*-*-*-*-*-*-*-*-*-*-" << std::endl << prefix << std::endl;
1232 tf << prefix <<
"Method : " << GetMethodTypeName() <<
"::" <<
GetMethodName() << std::endl;
1233 tf.setf(std::ios::left);
1234 tf << prefix <<
"TMVA Release : " << std::setw(10) << GetTrainingTMVAVersionString() <<
" ["
1235 << GetTrainingTMVAVersionCode() <<
"]" << std::endl;
1236 tf << prefix <<
"ROOT Release : " << std::setw(10) << GetTrainingROOTVersionString() <<
" ["
1237 << GetTrainingROOTVersionCode() <<
"]" << std::endl;
1238 tf << prefix <<
"Creator : " << userInfo->
fUser << std::endl;
1242 tf << prefix <<
"Training events: " <<
Data()->GetNTrainingEvents() << std::endl;
1244 TString analysisType(((const_cast<TMVA::MethodBase*>(
this)->GetAnalysisType()==
Types::kRegression) ?
"Regression" :
"Classification"));
1246 tf << prefix <<
"Analysis type : " <<
"[" << ((GetAnalysisType()==
Types::kRegression) ?
"Regression" :
"Classification") <<
"]" << std::endl;
1247 tf << prefix << std::endl;
1252 tf << prefix << std::endl << prefix <<
"#OPT -*-*-*-*-*-*-*-*-*-*-*-*- options -*-*-*-*-*-*-*-*-*-*-*-*-" << std::endl << prefix << std::endl;
1253 WriteOptionsToStream( tf, prefix );
1254 tf << prefix << std::endl;
1257 tf << prefix << std::endl << prefix <<
"#VAR -*-*-*-*-*-*-*-*-*-*-*-* variables *-*-*-*-*-*-*-*-*-*-*-*-" << std::endl << prefix << std::endl;
1258 WriteVarsToStream( tf, prefix );
1259 tf << prefix << std::endl;
1276 AddRegressionOutput( type );
1278 AddMulticlassOutput( type );
1280 AddClassifierOutput( type );
1282 AddClassifierOutputProb( type );
1292 if (!parent)
return;
1297 AddInfoItem( gi,
"TMVA Release", GetTrainingTMVAVersionString() +
" [" +
gTools().StringFromInt(GetTrainingTMVAVersionCode()) +
"]" );
1298 AddInfoItem( gi,
"ROOT Release", GetTrainingROOTVersionString() +
" [" +
gTools().StringFromInt(GetTrainingROOTVersionCode()) +
"]");
1299 AddInfoItem( gi,
"Creator", userInfo->
fUser);
1303 AddInfoItem( gi,
"Training events",
gTools().StringFromInt(
Data()->GetNTrainingEvents()));
1304 AddInfoItem( gi,
"TrainingTime",
gTools().StringFromDouble(const_cast<TMVA::MethodBase*>(
this)->GetTrainTime()));
1309 AddInfoItem( gi,
"AnalysisType", analysisType );
1313 AddOptionsXMLTo( parent );
1316 AddVarsXMLTo( parent );
1319 if (fModelPersistence)
1320 AddSpectatorsXMLTo( parent );
1323 AddClassesXMLTo(parent);
1326 if (DoRegression()) AddTargetsXMLTo(parent);
1329 GetTransformationHandler(
false).AddXMLTo( parent );
1333 if (fMVAPdfS) fMVAPdfS->AddXMLTo(pdfs);
1334 if (fMVAPdfB) fMVAPdfB->AddXMLTo(pdfs);
1337 AddWeightsXMLTo( parent );
1353 ReadWeightsFromStream( rf );
1366 TString tfname( GetWeightFileName() );
1371 <<
"Creating xml weight file: "
1377 WriteStateToXML(rootnode);
1389 TString tfname(GetWeightFileName());
1392 <<
"Reading weight file: "
1396 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,29,0)
1402 ReadStateFromXML(rootnode);
1407 fb.open(tfname.
Data(),std::ios::in);
1408 if (!fb.is_open()) {
1409 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"<ReadStateFromFile> "
1410 <<
"Unable to open input weight file: " << tfname <<
Endl;
1412 std::istream fin(&fb);
1413 ReadStateFromStream(fin);
1416 if (!fTxtWeightsOnly) {
1419 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"Reading root weight file: "
1422 ReadStateFromStream( *rfile );
1430 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,26,00)
1433 ReadStateFromXML(rootnode);
1436 Log() << kFATAL<<
Form(
"Dataset[%s] : ",DataInfo().
GetName()) <<
"Method MethodBase::ReadStateFromXMLString( const char* xmlstr = "
1437 << xmlstr <<
" ) is not available for ROOT versions prior to 5.26/00." <<
Endl;
1449 fMethodName = fullMethodName(fullMethodName.
Index(
"::")+2,fullMethodName.
Length());
1454 <<
"Read method \"" <<
GetMethodName() <<
"\" of type \"" << GetMethodTypeName() <<
"\"" <<
Endl;
1464 if (nodeName==
"GeneralInfo") {
1469 while (antypeNode) {
1472 if (
name ==
"TrainingTime")
1475 if (
name ==
"AnalysisType") {
1481 else Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"Analysis type " << val <<
" is not known." <<
Endl;
1484 if (
name ==
"TMVA Release" ||
name ==
"TMVA") {
1488 Log() << kDEBUG <<
Form(
"[%s] : ",DataInfo().
GetName()) <<
"MVA method was trained with TMVA Version: " << GetTrainingTMVAVersionString() <<
Endl;
1491 if (
name ==
"ROOT Release" ||
name ==
"ROOT") {
1496 <<
"MVA method was trained with ROOT Version: " << GetTrainingROOTVersionString() <<
Endl;
1501 else if (nodeName==
"Options") {
1502 ReadOptionsFromXML(ch);
1506 else if (nodeName==
"Variables") {
1507 ReadVariablesFromXML(ch);
1509 else if (nodeName==
"Spectators") {
1510 ReadSpectatorsFromXML(ch);
1512 else if (nodeName==
"Classes") {
1513 if (DataInfo().GetNClasses()==0) ReadClassesFromXML(ch);
1515 else if (nodeName==
"Targets") {
1516 if (DataInfo().GetNTargets()==0 && DoRegression()) ReadTargetsFromXML(ch);
1518 else if (nodeName==
"Transformations") {
1519 GetTransformationHandler().ReadFromXML(ch);
1521 else if (nodeName==
"MVAPdfs") {
1523 if (fMVAPdfS) {
delete fMVAPdfS; fMVAPdfS=0; }
1524 if (fMVAPdfB) {
delete fMVAPdfB; fMVAPdfB=0; }
1528 fMVAPdfS =
new PDF(pdfname);
1529 fMVAPdfS->ReadXML(pdfnode);
1532 fMVAPdfB =
new PDF(pdfname);
1533 fMVAPdfB->ReadXML(pdfnode);
1536 else if (nodeName==
"Weights") {
1537 ReadWeightsFromXML(ch);
1540 Log() << kWARNING <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"Unparsed XML node: '" << nodeName <<
"'" <<
Endl;
1547 if (GetTransformationHandler().GetCallerName() ==
"") GetTransformationHandler().SetCallerName(
GetName() );
1563 while (!
TString(buf).BeginsWith(
"Method")) GetLine(fin,buf);
1567 methodType = methodType(methodType.Last(
' '),methodType.Length());
1572 if (methodName ==
"") methodName = methodType;
1573 fMethodName = methodName;
1575 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"Read method \"" <<
GetMethodName() <<
"\" of type \"" << GetMethodTypeName() <<
"\"" <<
Endl;
1592 while (!
TString(buf).BeginsWith(
"#OPT")) GetLine(fin,buf);
1593 ReadOptionsFromStream(fin);
1597 fin.getline(buf,512);
1598 while (!
TString(buf).BeginsWith(
"#VAR")) fin.getline(buf,512);
1599 ReadVarsFromStream(fin);
1604 if (IsNormalised()) {
1610 if ( fVarTransformString ==
"None") {
1613 }
else if ( fVarTransformString ==
"Decorrelate" ) {
1615 }
else if ( fVarTransformString ==
"PCA" ) {
1616 varTrafo = GetTransformationHandler().AddTransformation(
new VariablePCATransform(DataInfo()), -1 );
1617 }
else if ( fVarTransformString ==
"Uniform" ) {
1618 varTrafo = GetTransformationHandler().AddTransformation(
new VariableGaussTransform(DataInfo(),
"Uniform"), -1 );
1619 }
else if ( fVarTransformString ==
"Gauss" ) {
1621 }
else if ( fVarTransformString ==
"GaussDecorr" ) {
1625 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"<ProcessOptions> Variable transform '"
1626 << fVarTransformString <<
"' unknown." <<
Endl;
1629 if (GetTransformationHandler().GetTransformationList().GetSize() > 0) {
1630 fin.getline(buf,512);
1631 while (!
TString(buf).BeginsWith(
"#MAT")) fin.getline(buf,512);
1634 varTrafo->ReadTransformationFromStream(fin, trafo );
1645 fin.getline(buf,512);
1646 while (!
TString(buf).BeginsWith(
"#MVAPDFS")) fin.getline(buf,512);
1647 if (fMVAPdfS != 0) {
delete fMVAPdfS; fMVAPdfS = 0; }
1648 if (fMVAPdfB != 0) {
delete fMVAPdfB; fMVAPdfB = 0; }
1651 fMVAPdfS->SetReadingVersion( GetTrainingTMVAVersionCode() );
1652 fMVAPdfB->SetReadingVersion( GetTrainingTMVAVersionCode() );
1659 fin.getline(buf,512);
1660 while (!
TString(buf).BeginsWith(
"#WGT")) fin.getline(buf,512);
1661 fin.getline(buf,512);
1662 ReadWeightsFromStream( fin );;
1665 if (GetTransformationHandler().GetCallerName() ==
"") GetTransformationHandler().SetCallerName(
GetName() );
1675 o << prefix <<
"NVar " << DataInfo().GetNVariables() << std::endl;
1676 std::vector<VariableInfo>::const_iterator varIt = DataInfo().GetVariableInfos().begin();
1677 for (; varIt!=DataInfo().GetVariableInfos().end(); varIt++) { o << prefix; varIt->WriteToStream(o); }
1678 o << prefix <<
"NSpec " << DataInfo().GetNSpectators() << std::endl;
1679 varIt = DataInfo().GetSpectatorInfos().begin();
1680 for (; varIt!=DataInfo().GetSpectatorInfos().end(); varIt++) { o << prefix; varIt->WriteToStream(o); }
1692 istr >> dummy >> readNVar;
1694 if (readNVar!=DataInfo().GetNVariables()) {
1695 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"You declared "<< DataInfo().GetNVariables() <<
" variables in the Reader"
1696 <<
" while there are " << readNVar <<
" variables declared in the file"
1702 std::vector<VariableInfo>::iterator varIt = DataInfo().GetVariableInfos().begin();
1704 for (; varIt!=DataInfo().GetVariableInfos().end(); varIt++, varIdx++) {
1711 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"ERROR in <ReadVarsFromStream>" <<
Endl;
1712 Log() << kINFO <<
"The definition (or the order) of the variables found in the input file is" <<
Endl;
1713 Log() << kINFO <<
"is not the same as the one declared in the Reader (which is necessary for" <<
Endl;
1714 Log() << kINFO <<
"the correct working of the method):" <<
Endl;
1715 Log() << kINFO <<
" var #" << varIdx <<
" declared in Reader: " << varIt->GetExpression() <<
Endl;
1716 Log() << kINFO <<
" var #" << varIdx <<
" declared in file : " << varInfo.
GetExpression() <<
Endl;
1717 Log() << kFATAL <<
"The expression declared to the Reader needs to be checked (name or order are wrong)" <<
Endl;
1730 for (
UInt_t idx=0; idx<DataInfo().GetVariableInfos().size(); idx++) {
1746 for (
UInt_t idx=0; idx<DataInfo().GetSpectatorInfos().size(); idx++) {
1748 VariableInfo& vi = DataInfo().GetSpectatorInfos()[idx];
1766 UInt_t nClasses=DataInfo().GetNClasses();
1771 for (
UInt_t iCls=0; iCls<nClasses; ++iCls) {
1772 ClassInfo *classInfo=DataInfo().GetClassInfo (iCls);
1789 for (
UInt_t idx=0; idx<DataInfo().GetTargetInfos().size(); idx++) {
1805 if (readNVar!=DataInfo().GetNVariables()) {
1806 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"You declared "<< DataInfo().GetNVariables() <<
" variables in the Reader"
1807 <<
" while there are " << readNVar <<
" variables declared in the file"
1817 existingVarInfo = DataInfo().GetVariableInfos()[varIdx];
1822 existingVarInfo = readVarInfo;
1825 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"ERROR in <ReadVariablesFromXML>" <<
Endl;
1826 Log() << kINFO <<
"The definition (or the order) of the variables found in the input file is" <<
Endl;
1827 Log() << kINFO <<
"not the same as the one declared in the Reader (which is necessary for the" <<
Endl;
1828 Log() << kINFO <<
"correct working of the method):" <<
Endl;
1829 Log() << kINFO <<
" var #" << varIdx <<
" declared in Reader: " << existingVarInfo.
GetExpression() <<
Endl;
1830 Log() << kINFO <<
" var #" << varIdx <<
" declared in file : " << readVarInfo.
GetExpression() <<
Endl;
1831 Log() << kFATAL <<
"The expression declared to the Reader needs to be checked (name or order are wrong)" <<
Endl;
1845 if (readNSpec!=DataInfo().GetNSpectators(
kFALSE)) {
1846 Log() << kFATAL<<
Form(
"Dataset[%s] : ",DataInfo().
GetName()) <<
"You declared "<< DataInfo().GetNSpectators(
kFALSE) <<
" spectators in the Reader"
1847 <<
" while there are " << readNSpec <<
" spectators declared in the file"
1857 existingSpecInfo = DataInfo().GetSpectatorInfos()[specIdx];
1862 existingSpecInfo = readSpecInfo;
1865 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"ERROR in <ReadSpectatorsFromXML>" <<
Endl;
1866 Log() << kINFO <<
"The definition (or the order) of the spectators found in the input file is" <<
Endl;
1867 Log() << kINFO <<
"not the same as the one declared in the Reader (which is necessary for the" <<
Endl;
1868 Log() << kINFO <<
"correct working of the method):" <<
Endl;
1869 Log() << kINFO <<
" spec #" << specIdx <<
" declared in Reader: " << existingSpecInfo.
GetExpression() <<
Endl;
1870 Log() << kINFO <<
" spec #" << specIdx <<
" declared in file : " << readSpecInfo.
GetExpression() <<
Endl;
1871 Log() << kFATAL <<
"The expression declared to the Reader needs to be checked (name or order are wrong)" <<
Endl;
1890 for (
UInt_t icls = 0; icls<readNCls;++icls) {
1892 DataInfo().AddClass(classname);
1900 DataInfo().AddClass(className);
1907 if (DataInfo().GetClassInfo(
"Signal") != 0) {
1908 fSignalClass = DataInfo().GetClassInfo(
"Signal")->GetNumber();
1912 if (DataInfo().GetClassInfo(
"Background") != 0) {
1913 fBackgroundClass = DataInfo().GetClassInfo(
"Background")->GetNumber();
1933 DataInfo().AddTarget(expression,
"",
"",0,0);
1945 if (fBaseDir != 0)
return fBaseDir;
1946 Log()<<kDEBUG<<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
" Base Directory for " <<
GetMethodName() <<
" not set yet --> check if already there.." <<
Endl;
1950 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"MethodBase::BaseDir() - MethodBaseDir() return a NULL pointer!" <<
Endl;
1956 Log()<<kDEBUG<<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
" Base Directory for " << GetMethodTypeName() <<
" does not exist yet--> created it" <<
Endl;
1957 sdir = methodDir->
mkdir(defaultDir);
1962 wfilePath.Write(
"TrainingPath" );
1963 wfileName.Write(
"WeightFileName" );
1966 Log()<<kDEBUG<<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
" Base Directory for " << GetMethodTypeName() <<
" existed, return it.." <<
Endl;
1976 if (fMethodBaseDir != 0)
return fMethodBaseDir;
1978 Log()<<kDEBUG<<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
" Base Directory for " << GetMethodTypeName() <<
" not set yet --> check if already there.." <<
Endl;
1986 fMethodBaseDir = fFactoryBaseDir->
mkdir(DataInfo().
GetName(),
Form(
"Base directory for dataset %s",DataInfo().
GetName()));
1987 if(!fMethodBaseDir)
Log()<<kFATAL<<
"Can not create dir "<<DataInfo().GetName();
1990 fMethodBaseDir = fMethodBaseDir->GetDirectory(_methodDir.
Data());
1992 if(!fMethodBaseDir){
1997 Log()<<kDEBUG<<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"Return from MethodBaseDir() after creating base directory "<<
Endl;
1998 return fMethodBaseDir;
2015 fWeightFile = theWeightFile;
2023 if (fWeightFile!=
"")
return fWeightFile;
2028 TString wFileDir(GetWeightFileDir());
2029 return ( wFileDir + (wFileDir[wFileDir.
Length()-1]==
'/' ?
"" :
"/")
2043 if (0 != fMVAPdfS) {
2044 fMVAPdfS->GetOriginalHist()->Write();
2045 fMVAPdfS->GetSmoothedHist()->Write();
2046 fMVAPdfS->GetPDFHist()->Write();
2048 if (0 != fMVAPdfB) {
2049 fMVAPdfB->GetOriginalHist()->Write();
2050 fMVAPdfB->GetSmoothedHist()->Write();
2051 fMVAPdfB->GetPDFHist()->Write();
2057 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"<WriteEvaluationHistosToFile> Unknown result: "
2059 <<
"/kMaxAnalysisType" <<
Endl;
2062 GetTransformationHandler().PlotVariables (GetEventCollection(
Types::kTesting ), BaseDir() );
2081 fin.getline(buf,512);
2087 std::stringstream s(code.
Data());
2088 s >> fTMVATrainingVersion;
2089 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"MVA method was trained with TMVA Version: " << GetTrainingTMVAVersionString() <<
Endl;
2095 std::stringstream s(code.
Data());
2096 s >> fROOTTrainingVersion;
2097 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"MVA method was trained with ROOT Version: " << GetTrainingROOTVersionString() <<
Endl;
2103 std::stringstream s(code.
Data());
2104 std::string analysisType;
2106 if (analysisType ==
"regression" || analysisType ==
"Regression") SetAnalysisType(
Types::kRegression );
2107 else if (analysisType ==
"classification" || analysisType ==
"Classification") SetAnalysisType(
Types::kClassification );
2108 else if (analysisType ==
"multiclass" || analysisType ==
"Multiclass") SetAnalysisType(
Types::kMulticlass );
2109 else Log() << kFATAL <<
"Analysis type " << analysisType <<
" from weight-file not known!" << std::endl;
2111 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"Method was trained for "
2131 if (mvaRes==0 || mvaRes->
GetSize()==0) {
2132 Log() << kERROR<<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"<CreateMVAPdfs> No result of classifier testing available" <<
Endl;
2139 TH1* histMVAPdfS =
new TH1D( GetMethodTypeName() +
"_tr_S", GetMethodTypeName() +
"_tr_S",
2140 fMVAPdfS->GetHistNBins( mvaRes->
GetSize() ), minVal, maxVal );
2141 TH1* histMVAPdfB =
new TH1D( GetMethodTypeName() +
"_tr_B", GetMethodTypeName() +
"_tr_B",
2142 fMVAPdfB->GetHistNBins( mvaRes->
GetSize() ), minVal, maxVal );
2146 histMVAPdfS->Sumw2();
2147 histMVAPdfB->
Sumw2();
2152 Double_t theWeight =
Data()->GetEvent(ievt)->GetWeight();
2154 if (DataInfo().IsSignal(
Data()->GetEvent(ievt))) histMVAPdfS->Fill( theVal, theWeight );
2155 else histMVAPdfB->
Fill( theVal, theWeight );
2164 histMVAPdfS->Write();
2165 histMVAPdfB->
Write();
2168 fMVAPdfS->BuildPDF ( histMVAPdfS );
2169 fMVAPdfB->BuildPDF ( histMVAPdfB );
2170 fMVAPdfS->ValidatePDF( histMVAPdfS );
2171 fMVAPdfB->ValidatePDF( histMVAPdfB );
2173 if (DataInfo().GetNClasses() == 2) {
2175 <<
Form(
"<CreateMVAPdfs> Separation from histogram (PDF): %1.3f (%1.3f)",
2176 GetSeparation( histMVAPdfS, histMVAPdfB ), GetSeparation( fMVAPdfS, fMVAPdfB ) )
2188 if (!fMVAPdfS || !fMVAPdfB) {
2189 Log() << kINFO<<
Form(
"Dataset[%s] : ",DataInfo().
GetName()) <<
"<GetProba> MVA PDFs for Signal and Background don't exist yet, we'll create them on demand" <<
Endl;
2192 Double_t sigFraction = DataInfo().GetTrainingSumSignalWeights() / (DataInfo().GetTrainingSumSignalWeights() + DataInfo().GetTrainingSumBackgrWeights() );
2195 return GetProba(mvaVal,sigFraction);
2203 if (!fMVAPdfS || !fMVAPdfB) {
2204 Log() << kWARNING <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"<GetProba> MVA PDFs for Signal and Background don't exist" <<
Endl;
2207 Double_t p_s = fMVAPdfS->GetVal( mvaVal );
2208 Double_t p_b = fMVAPdfB->GetVal( mvaVal );
2210 Double_t denom = p_s*ap_sig + p_b*(1 - ap_sig);
2212 return (denom > 0) ? (p_s*ap_sig) / denom : -1;
2225 Log() << kWARNING <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"<GetRarity> Required MVA PDF for Signal or Background does not exist: "
2226 <<
"select option \"CreateMVAPdfs\"" <<
Endl;
2241 Data()->SetCurrentType(type);
2250 if (!list || list->
GetSize() < 2) computeArea = kTRUE;
2251 else if (list->
GetSize() > 2) {
2252 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"<GetEfficiency> Wrong number of arguments"
2253 <<
" in string: " << theString
2254 <<
" | required format, e.g., Efficiency:0.05, or empty string" <<
Endl;
2262 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"<GetEfficiency> Binning mismatch between signal and background histos" <<
Endl;
2270 TH1 * effhist = results->
GetHist(
"MVA_HIGHBIN_S");
2277 if (results->
DoesExist(
"MVA_EFF_S")==0) {
2280 TH1* eff_s =
new TH1D( GetTestvarName() +
"_effS", GetTestvarName() +
" (signal)", fNbinsH, xmin, xmax );
2281 TH1* eff_b =
new TH1D( GetTestvarName() +
"_effB", GetTestvarName() +
" (background)", fNbinsH, xmin, xmax );
2282 results->
Store(eff_s,
"MVA_EFF_S");
2283 results->
Store(eff_b,
"MVA_EFF_B");
2286 Int_t sign = (fCutOrientation == kPositive) ? +1 : -1;
2290 for (
UInt_t ievt=0; ievt<
Data()->GetNEvents(); ievt++) {
2293 Bool_t isSignal = DataInfo().IsSignal(GetEvent(ievt));
2294 Float_t theWeight = GetEvent(ievt)->GetWeight();
2295 Float_t theVal = (*mvaRes)[ievt];
2298 TH1* theHist = isSignal ? eff_s : eff_b;
2301 if (isSignal) nevtS+=theWeight;
2305 if (sign > 0 && maxbin > fNbinsH)
continue;
2306 if (sign < 0 && maxbin < 1 )
continue;
2307 if (sign > 0 && maxbin < 1 ) maxbin = 1;
2308 if (sign < 0 && maxbin > fNbinsH) maxbin = fNbinsH;
2313 for (
Int_t ibin=maxbin+1; ibin<=fNbinsH; ibin++) theHist->
AddBinContent( ibin , theWeight );
2315 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"<GetEfficiency> Mismatch in sign" <<
Endl;
2326 TH1* eff_BvsS =
new TH1D( GetTestvarName() +
"_effBvsS", GetTestvarName() +
"", fNbins, 0, 1 );
2327 results->
Store(eff_BvsS,
"MVA_EFF_BvsS");
2332 TH1* rej_BvsS =
new TH1D( GetTestvarName() +
"_rejBvsS", GetTestvarName() +
"", fNbins, 0, 1 );
2333 results->
Store(rej_BvsS);
2335 rej_BvsS->
SetYTitle(
"Backgr rejection (1-eff)" );
2338 TH1* inveff_BvsS =
new TH1D( GetTestvarName() +
"_invBeffvsSeff",
2339 GetTestvarName(), fNbins, 0, 1 );
2340 results->
Store(inveff_BvsS);
2342 inveff_BvsS->
SetYTitle(
"Inverse backgr. eff (1/eff)" );
2348 fSplRefS =
new TSpline1(
"spline2_signal",
new TGraph( eff_s ) );
2349 fSplRefB =
new TSpline1(
"spline2_background",
new TGraph( eff_b ) );
2363 for (
Int_t bini=1; bini<=fNbins; bini++) {
2385 Double_t effS = 0., rejB, effS_ = 0., rejB_ = 0.;
2386 Int_t nbins_ = 5000;
2387 for (
Int_t bini=1; bini<=nbins_; bini++) {
2390 effS = (bini - 0.5)/
Float_t(nbins_);
2391 rejB = 1.0 - fSpleffBvsS->Eval( effS );
2394 if ((effS - rejB)*(effS_ - rejB_) < 0)
break;
2401 SetSignalReferenceCut( cut );
2406 if (0 == fSpleffBvsS) {
2412 Double_t effS = 0, effB = 0, effS_ = 0, effB_ = 0;
2413 Int_t nbins_ = 1000;
2419 for (
Int_t bini=1; bini<=nbins_; bini++) {
2422 effS = (bini - 0.5)/
Float_t(nbins_);
2423 effB = fSpleffBvsS->Eval( effS );
2424 integral += (1.0 - effB);
2438 for (
Int_t bini=1; bini<=nbins_; bini++) {
2441 effS = (bini - 0.5)/
Float_t(nbins_);
2442 effB = fSpleffBvsS->Eval( effS );
2445 if ((effB - effBref)*(effB_ - effBref) <= 0)
break;
2451 effS = 0.5*(effS + effS_);
2454 if (nevtS > 0) effSerr =
TMath::Sqrt( effS*(1.0 - effS)/nevtS );
2479 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"<GetTrainingEfficiency> Wrong number of arguments"
2480 <<
" in string: " << theString
2481 <<
" | required format, e.g., Efficiency:0.05" <<
Endl;
2494 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"<GetTrainingEfficiency> Binning mismatch between signal and background histos"
2502 TH1 * effhist = results->
GetHist(
"MVA_HIGHBIN_S");
2507 if (results->
DoesExist(
"MVA_TRAIN_S")==0) {
2513 TH1* mva_s_tr =
new TH1D( GetTestvarName() +
"_Train_S",GetTestvarName() +
"_Train_S", fNbinsMVAoutput, fXmin, sxmax );
2514 TH1* mva_b_tr =
new TH1D( GetTestvarName() +
"_Train_B",GetTestvarName() +
"_Train_B", fNbinsMVAoutput, fXmin, sxmax );
2515 results->
Store(mva_s_tr,
"MVA_TRAIN_S");
2516 results->
Store(mva_b_tr,
"MVA_TRAIN_B");
2521 TH1* mva_eff_tr_s =
new TH1D( GetTestvarName() +
"_trainingEffS", GetTestvarName() +
" (signal)",
2522 fNbinsH, xmin, xmax );
2523 TH1* mva_eff_tr_b =
new TH1D( GetTestvarName() +
"_trainingEffB", GetTestvarName() +
" (background)",
2524 fNbinsH, xmin, xmax );
2525 results->
Store(mva_eff_tr_s,
"MVA_TRAINEFF_S");
2526 results->
Store(mva_eff_tr_b,
"MVA_TRAINEFF_B");
2529 Int_t sign = (fCutOrientation == kPositive) ? +1 : -1;
2531 std::vector<Double_t> mvaValues = GetMvaValues(0,
Data()->GetNEvents());
2532 assert( (
Long64_t) mvaValues.size() ==
Data()->GetNEvents());
2535 for (
Int_t ievt=0; ievt<
Data()->GetNEvents(); ievt++) {
2537 Data()->SetCurrentEvent(ievt);
2538 const Event* ev = GetEvent();
2543 TH1* theEffHist = DataInfo().IsSignal(ev) ? mva_eff_tr_s : mva_eff_tr_b;
2544 TH1* theClsHist = DataInfo().IsSignal(ev) ? mva_s_tr : mva_b_tr;
2546 theClsHist->
Fill( theVal, theWeight );
2550 if (sign > 0 && maxbin > fNbinsH)
continue;
2551 if (sign < 0 && maxbin < 1 )
continue;
2552 if (sign > 0 && maxbin < 1 ) maxbin = 1;
2553 if (sign < 0 && maxbin > fNbinsH) maxbin = fNbinsH;
2555 if (sign > 0)
for (
Int_t ibin=1; ibin<=maxbin; ibin++) theEffHist->
AddBinContent( ibin , theWeight );
2556 else for (
Int_t ibin=maxbin+1; ibin<=fNbinsH; ibin++) theEffHist->
AddBinContent( ibin , theWeight );
2569 TH1* eff_bvss =
new TH1D( GetTestvarName() +
"_trainingEffBvsS", GetTestvarName() +
"", fNbins, 0, 1 );
2571 TH1* rej_bvss =
new TH1D( GetTestvarName() +
"_trainingRejBvsS", GetTestvarName() +
"", fNbins, 0, 1 );
2572 results->
Store(eff_bvss,
"EFF_BVSS_TR");
2573 results->
Store(rej_bvss,
"REJ_BVSS_TR");
2579 if (fSplTrainRefS)
delete fSplTrainRefS;
2580 if (fSplTrainRefB)
delete fSplTrainRefB;
2581 fSplTrainRefS =
new TSpline1(
"spline2_signal",
new TGraph( mva_eff_tr_s ) );
2582 fSplTrainRefB =
new TSpline1(
"spline2_background",
new TGraph( mva_eff_tr_b ) );
2595 fEffS = results->
GetHist(
"MVA_TRAINEFF_S");
2596 for (
Int_t bini=1; bini<=fNbins; bini++) {
2614 fSplTrainEffBvsS =
new TSpline1(
"effBvsS",
new TGraph( eff_bvss ) );
2618 if (0 == fSplTrainEffBvsS)
return 0.0;
2621 Double_t effS = 0., effB, effS_ = 0., effB_ = 0.;
2622 Int_t nbins_ = 1000;
2623 for (
Int_t bini=1; bini<=nbins_; bini++) {
2626 effS = (bini - 0.5)/
Float_t(nbins_);
2627 effB = fSplTrainEffBvsS->Eval( effS );
2630 if ((effB - effBref)*(effB_ - effBref) <= 0)
break;
2635 return 0.5*(effS + effS_);
2644 if (!resMulticlass)
Log() << kFATAL<<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"unable to create pointer in GetMulticlassEfficiency, exiting."<<
Endl;
2656 if (!resMulticlass)
Log() << kFATAL<<
"unable to create pointer in GetMulticlassTrainingEfficiency, exiting."<<
Endl;
2658 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"Determine optimal multiclass cuts for training data..." <<
Endl;
2659 for (
UInt_t icls = 0; icls<DataInfo().GetNClasses(); ++icls) {
2690 Log() << kFATAL <<
"Cannot get confusion matrix for non-multiclass analysis." << std::endl;
2694 Data()->SetCurrentType(type);
2698 if (resMulticlass ==
nullptr) {
2700 <<
"unable to create pointer in GetMulticlassEfficiency, exiting." <<
Endl;
2717 return (rms > 0) ?
TMath::Abs(fMeanS - fMeanB)/rms : 0;
2741 if ((!pdfS && pdfB) || (pdfS && !pdfB))
2742 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"<GetSeparation> Mismatch in pdfs" <<
Endl;
2743 if (!pdfS) pdfS = fSplS;
2744 if (!pdfB) pdfB = fSplB;
2746 if (!fSplS || !fSplB) {
2747 Log()<<kDEBUG<<
Form(
"[%s] : ",DataInfo().
GetName())<<
"could not calculate the separation, distributions"
2748 <<
" fSplS or fSplB are not yet filled" <<
Endl;
2763 if ((!histS && histB) || (histS && !histB))
2764 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"<GetROCIntegral(TH1D*, TH1D*)> Mismatch in hists" <<
Endl;
2766 if (histS==0 || histB==0)
return 0.;
2779 for (
UInt_t i=0; i<nsteps; i++) {
2783 return integral*step;
2795 if ((!pdfS && pdfB) || (pdfS && !pdfB))
2796 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"<GetSeparation> Mismatch in pdfs" <<
Endl;
2797 if (!pdfS) pdfS = fSplS;
2798 if (!pdfB) pdfB = fSplB;
2800 if (pdfS==0 || pdfB==0)
return 0.;
2809 for (
UInt_t i=0; i<nsteps; i++) {
2813 return integral*step;
2823 Double_t& max_significance_value )
const
2828 Double_t effS(0),effB(0),significance(0);
2829 TH1D *temp_histogram =
new TH1D(
"temp",
"temp", fNbinsH, fXmin, fXmax );
2831 if (SignalEvents <= 0 || BackgroundEvents <= 0) {
2832 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"<GetMaximumSignificance> "
2833 <<
"Number of signal or background events is <= 0 ==> abort"
2837 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"Using ratio SignalEvents/BackgroundEvents = "
2838 << SignalEvents/BackgroundEvents <<
Endl;
2843 if ( (eff_s==0) || (eff_b==0) ) {
2844 Log() << kWARNING <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"Efficiency histograms empty !" <<
Endl;
2845 Log() << kWARNING <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"no maximum cut found, return 0" <<
Endl;
2849 for (
Int_t bin=1; bin<=fNbinsH; bin++) {
2854 significance =
sqrt(SignalEvents)*( effS )/
sqrt( effS + ( BackgroundEvents / SignalEvents) * effB );
2864 delete temp_histogram;
2866 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"Optimal cut at : " << max_significance <<
Endl;
2867 Log() << kINFO<<
Form(
"Dataset[%s] : ",DataInfo().
GetName()) <<
"Maximum significance: " << max_significance_value <<
Endl;
2869 return max_significance;
2883 Data()->SetCurrentType(treeType);
2889 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().
GetName())<<
"<CalculateEstimator> Wrong tree type: " << treeType <<
Endl;
2892 UInt_t varIndex = DataInfo().FindVarIndex( theVarName );
2908 for (
Int_t ievt = 0; ievt < entries; ievt++) {
2910 const Event* ev = GetEvent(ievt);
2915 if (DataInfo().IsSignal(ev)) {
2917 meanS += weight*theVar;
2918 rmsS += weight*theVar*theVar;
2922 meanB += weight*theVar;
2923 rmsB += weight*theVar*theVar;
2931 meanS = meanS/sumwS;
2932 meanB = meanB/sumwB;
2936 Data()->SetCurrentType(previousTreeType);
2946 if (theClassFileName ==
"")
2947 classFileName = GetWeightFileDir() +
"/" + GetJobName() +
"_" +
GetMethodName() +
".class.C";
2949 classFileName = theClassFileName;
2953 TString tfname( classFileName );
2955 <<
"Creating standalone class: "
2958 std::ofstream fout( classFileName );
2960 Log() << kFATAL <<
"<MakeClass> Unable to open file: " << classFileName <<
Endl;
2965 fout <<
"// Class: " << className << std::endl;
2966 fout <<
"// Automatically generated by MethodBase::MakeClass" << std::endl <<
"//" << std::endl;
2970 fout <<
"/* configuration options =====================================================" << std::endl << std::endl;
2971 WriteStateToStream( fout );
2973 fout <<
"============================================================================ */" << std::endl;
2976 fout <<
"" << std::endl;
2977 fout <<
"#include <vector>" << std::endl;
2978 fout <<
"#include <cmath>" << std::endl;
2979 fout <<
"#include <string>" << std::endl;
2980 fout <<
"#include <iostream>" << std::endl;
2981 fout <<
"" << std::endl;
2984 this->MakeClassSpecificHeader( fout, className );
2986 fout <<
"#ifndef IClassifierReader__def" << std::endl;
2987 fout <<
"#define IClassifierReader__def" << std::endl;
2989 fout <<
"class IClassifierReader {" << std::endl;
2991 fout <<
" public:" << std::endl;
2993 fout <<
" // constructor" << std::endl;
2994 fout <<
" IClassifierReader() : fStatusIsClean( true ) {}" << std::endl;
2995 fout <<
" virtual ~IClassifierReader() {}" << std::endl;
2997 fout <<
" // return classifier response" << std::endl;
2998 fout <<
" virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;" << std::endl;
3000 fout <<
" // returns classifier status" << std::endl;
3001 fout <<
" bool IsStatusClean() const { return fStatusIsClean; }" << std::endl;
3003 fout <<
" protected:" << std::endl;
3005 fout <<
" bool fStatusIsClean;" << std::endl;
3006 fout <<
"};" << std::endl;
3008 fout <<
"#endif" << std::endl;
3010 fout <<
"class " << className <<
" : public IClassifierReader {" << std::endl;
3012 fout <<
" public:" << std::endl;
3014 fout <<
" // constructor" << std::endl;
3015 fout <<
" " << className <<
"( std::vector<std::string>& theInputVars ) " << std::endl;
3016 fout <<
" : IClassifierReader()," << std::endl;
3017 fout <<
" fClassName( \"" << className <<
"\" )," << std::endl;
3018 fout <<
" fNvars( " << GetNvar() <<
" )," << std::endl;
3019 fout <<
" fIsNormalised( " << (IsNormalised() ?
"true" :
"false") <<
" )" << std::endl;
3020 fout <<
" { " << std::endl;
3021 fout <<
" // the training input variables" << std::endl;
3022 fout <<
" const char* inputVars[] = { ";
3023 for (
UInt_t ivar=0; ivar<GetNvar(); ivar++) {
3024 fout <<
"\"" << GetOriginalVarName(ivar) <<
"\"";
3025 if (ivar<GetNvar()-1) fout <<
", ";
3027 fout <<
" };" << std::endl;
3029 fout <<
" // sanity checks" << std::endl;
3030 fout <<
" if (theInputVars.size() <= 0) {" << std::endl;
3031 fout <<
" std::cout << \"Problem in class \\\"\" << fClassName << \"\\\": empty input vector\" << std::endl;" << std::endl;
3032 fout <<
" fStatusIsClean = false;" << std::endl;
3033 fout <<
" }" << std::endl;
3035 fout <<
" if (theInputVars.size() != fNvars) {" << std::endl;
3036 fout <<
" std::cout << \"Problem in class \\\"\" << fClassName << \"\\\": mismatch in number of input values: \"" << std::endl;
3037 fout <<
" << theInputVars.size() << \" != \" << fNvars << std::endl;" << std::endl;
3038 fout <<
" fStatusIsClean = false;" << std::endl;
3039 fout <<
" }" << std::endl;
3041 fout <<
" // validate input variables" << std::endl;
3042 fout <<
" for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {" << std::endl;
3043 fout <<
" if (theInputVars[ivar] != inputVars[ivar]) {" << std::endl;
3044 fout <<
" std::cout << \"Problem in class \\\"\" << fClassName << \"\\\": mismatch in input variable names\" << std::endl" << std::endl;
3045 fout <<
" << \" for variable [\" << ivar << \"]: \" << theInputVars[ivar].c_str() << \" != \" << inputVars[ivar] << std::endl;" << std::endl;
3046 fout <<
" fStatusIsClean = false;" << std::endl;
3047 fout <<
" }" << std::endl;
3048 fout <<
" }" << std::endl;
3050 fout <<
" // initialize min and max vectors (for normalisation)" << std::endl;
3051 for (
UInt_t ivar = 0; ivar < GetNvar(); ivar++) {
3052 fout <<
" fVmin[" << ivar <<
"] = " << std::setprecision(15) << GetXmin( ivar ) <<
";" << std::endl;
3053 fout <<
" fVmax[" << ivar <<
"] = " << std::setprecision(15) << GetXmax( ivar ) <<
";" << std::endl;
3056 fout <<
" // initialize input variable types" << std::endl;
3057 for (
UInt_t ivar=0; ivar<GetNvar(); ivar++) {
3058 fout <<
" fType[" << ivar <<
"] = \'" << DataInfo().GetVariableInfo(ivar).GetVarType() <<
"\';" << std::endl;
3061 fout <<
" // initialize constants" << std::endl;
3062 fout <<
" Initialize();" << std::endl;
3064 if (GetTransformationHandler().GetTransformationList().GetSize() != 0) {
3065 fout <<
" // initialize transformation" << std::endl;
3066 fout <<
" InitTransform();" << std::endl;
3068 fout <<
" }" << std::endl;
3070 fout <<
" // destructor" << std::endl;
3071 fout <<
" virtual ~" << className <<
"() {" << std::endl;
3072 fout <<
" Clear(); // method-specific" << std::endl;
3073 fout <<
" }" << std::endl;
3075 fout <<
" // the classifier response" << std::endl;
3076 fout <<
" // \"inputValues\" is a vector of input values in the same order as the " << std::endl;
3077 fout <<
" // variables given to the constructor" << std::endl;
3078 fout <<
" double GetMvaValue( const std::vector<double>& inputValues ) const;" << std::endl;
3080 fout <<
" private:" << std::endl;
3082 fout <<
" // method-specific destructor" << std::endl;
3083 fout <<
" void Clear();" << std::endl;
3085 if (GetTransformationHandler().GetTransformationList().GetSize()!=0) {
3086 fout <<
" // input variable transformation" << std::endl;
3087 GetTransformationHandler().MakeFunction(fout, className,1);
3088 fout <<
" void InitTransform();" << std::endl;
3089 fout <<
" void Transform( std::vector<double> & iv, int sigOrBgd ) const;" << std::endl;
3092 fout <<
" // common member variables" << std::endl;
3093 fout <<
" const char* fClassName;" << std::endl;
3095 fout <<
" const size_t fNvars;" << std::endl;
3096 fout <<
" size_t GetNvar() const { return fNvars; }" << std::endl;
3097 fout <<
" char GetType( int ivar ) const { return fType[ivar]; }" << std::endl;
3099 fout <<
" // normalisation of input variables" << std::endl;
3100 fout <<
" const bool fIsNormalised;" << std::endl;
3101 fout <<
" bool IsNormalised() const { return fIsNormalised; }" << std::endl;
3102 fout <<
" double fVmin[" << GetNvar() <<
"];" << std::endl;
3103 fout <<
" double fVmax[" << GetNvar() <<
"];" << std::endl;
3104 fout <<
" double NormVariable( double x, double xmin, double xmax ) const {" << std::endl;
3105 fout <<
" // normalise to output range: [-1, 1]" << std::endl;
3106 fout <<
" return 2*(x - xmin)/(xmax - xmin) - 1.0;" << std::endl;
3107 fout <<
" }" << std::endl;
3109 fout <<
" // type of input variable: 'F' or 'I'" << std::endl;
3110 fout <<
" char fType[" << GetNvar() <<
"];" << std::endl;
3112 fout <<
" // initialize internal variables" << std::endl;
3113 fout <<
" void Initialize();" << std::endl;
3114 fout <<
" double GetMvaValue__( const std::vector<double>& inputValues ) const;" << std::endl;
3115 fout <<
"" << std::endl;
3116 fout <<
" // private members (method specific)" << std::endl;
3119 MakeClassSpecific( fout, className );
3121 fout <<
" inline double " << className <<
"::GetMvaValue( const std::vector<double>& inputValues ) const" << std::endl;
3122 fout <<
" {" << std::endl;
3123 fout <<
" // classifier response value" << std::endl;
3124 fout <<
" double retval = 0;" << std::endl;
3126 fout <<
" // classifier response, sanity check first" << std::endl;
3127 fout <<
" if (!IsStatusClean()) {" << std::endl;
3128 fout <<
" std::cout << \"Problem in class \\\"\" << fClassName << \"\\\": cannot return classifier response\"" << std::endl;
3129 fout <<
" << \" because status is dirty\" << std::endl;" << std::endl;
3130 fout <<
" retval = 0;" << std::endl;
3131 fout <<
" }" << std::endl;
3132 fout <<
" else {" << std::endl;
3133 fout <<
" if (IsNormalised()) {" << std::endl;
3134 fout <<
" // normalise variables" << std::endl;
3135 fout <<
" std::vector<double> iV;" << std::endl;
3136 fout <<
" iV.reserve(inputValues.size());" << std::endl;
3137 fout <<
" int ivar = 0;" << std::endl;
3138 fout <<
" for (std::vector<double>::const_iterator varIt = inputValues.begin();" << std::endl;
3139 fout <<
" varIt != inputValues.end(); varIt++, ivar++) {" << std::endl;
3140 fout <<
" iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));" << std::endl;
3141 fout <<
" }" << std::endl;
3142 if (GetTransformationHandler().GetTransformationList().GetSize()!=0 &&
3145 fout <<
" Transform( iV, -1 );" << std::endl;
3147 fout <<
" retval = GetMvaValue__( iV );" << std::endl;
3148 fout <<
" }" << std::endl;
3149 fout <<
" else {" << std::endl;
3150 if (GetTransformationHandler().GetTransformationList().GetSize()!=0 &&
3153 fout <<
" std::vector<double> iV;" << std::endl;
3154 fout <<
" int ivar = 0;" << std::endl;
3155 fout <<
" for (std::vector<double>::const_iterator varIt = inputValues.begin();" << std::endl;
3156 fout <<
" varIt != inputValues.end(); varIt++, ivar++) {" << std::endl;
3157 fout <<
" iV.push_back(*varIt);" << std::endl;
3158 fout <<
" }" << std::endl;
3159 fout <<
" Transform( iV, -1 );" << std::endl;
3160 fout <<
" retval = GetMvaValue__( iV );" << std::endl;
3163 fout <<
" retval = GetMvaValue__( inputValues );" << std::endl;
3165 fout <<
" }" << std::endl;
3166 fout <<
" }" << std::endl;
3168 fout <<
" return retval;" << std::endl;
3169 fout <<
" }" << std::endl;
3172 if (GetTransformationHandler().GetTransformationList().GetSize()!=0)
3173 GetTransformationHandler().MakeFunction(fout, className,2);
3185 std::streambuf* cout_sbuf = std::cout.rdbuf();
3186 std::ofstream* o = 0;
3187 if (
gConfig().WriteOptionsReference()) {
3188 Log() << kINFO <<
"Print Help message for class " <<
GetName() <<
" into file: " << GetReferenceFile() <<
Endl;
3189 o =
new std::ofstream( GetReferenceFile(), std::ios::app );
3191 Log() << kFATAL <<
"<PrintHelpMessage> Unable to append to output file: " << GetReferenceFile() <<
Endl;
3193 std::cout.rdbuf( o->rdbuf() );
3200 <<
"================================================================"
3204 <<
"H e l p f o r M V A m e t h o d [ " <<
GetName() <<
" ] :"
3209 Log() <<
"Help for MVA method [ " <<
GetName() <<
" ] :" <<
Endl;
3217 Log() <<
"<Suppress this message by specifying \"!H\" in the booking option>" <<
Endl;
3219 <<
"================================================================"
3226 Log() <<
"# End of Message___" <<
Endl;
3229 std::cout.rdbuf( cout_sbuf );
3244 retval = fSplRefS->Eval( theCut );
3246 else retval = fEffS->GetBinContent( fEffS->FindBin( theCut ) );
3255 if (theCut-fXmin < eps) retval = (GetCutOrientation() == kPositive) ? 1.0 : 0.0;
3256 else if (fXmax-theCut < eps) retval = (GetCutOrientation() == kPositive) ? 0.0 : 1.0;
3269 if (GetTransformationHandler().GetTransformationList().GetEntries() <= 0) {
3270 return (
Data()->GetEventCollection(type));
3277 if (fEventCollections.at(idx) == 0) {
3278 fEventCollections.at(idx) = &(
Data()->GetEventCollection(type));
3279 fEventCollections.at(idx) = GetTransformationHandler().CalcTransformations(*(fEventCollections.at(idx)),kTRUE);
3281 return *(fEventCollections.at(idx));
3289 UInt_t a = GetTrainingTMVAVersionCode() & 0xff0000; a>>=16;
3290 UInt_t b = GetTrainingTMVAVersionCode() & 0x00ff00; b>>=8;
3291 UInt_t c = GetTrainingTMVAVersionCode() & 0x0000ff;
3301 UInt_t a = GetTrainingROOTVersionCode() & 0xff0000; a>>=16;
3302 UInt_t b = GetTrainingROOTVersionCode() & 0x00ff00; b>>=8;
3303 UInt_t c = GetTrainingROOTVersionCode() & 0x0000ff;
3314 if (mvaRes !=
NULL) {
3317 TH1D *mva_s_tr =
dynamic_cast<TH1D*
> (mvaRes->
GetHist(
"MVA_TRAIN_S"));
3318 TH1D *mva_b_tr =
dynamic_cast<TH1D*
> (mvaRes->
GetHist(
"MVA_TRAIN_B"));
3320 if ( !mva_s || !mva_b || !mva_s_tr || !mva_b_tr)
return -1;
3322 if (SorB ==
's' || SorB ==
'S')
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
std::string GetName(const std::string &scope_name)
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 according to the argument This is just a dummy .
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 ...
Singleton class for Global types used by TMVA.
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)
Class that is the base-class for a vector of result.
void AddPoint(Double_t x, Double_t y1, Double_t y2)
This function is used only in 2 TGraph case, and it will add new data points to graphs.
virtual const char * WorkingDirectory()
Return working directory.
void ReadStateFromXML(void *parent)
virtual Double_t GetMvaValue(Double_t *errLower=0, Double_t *errUpper=0)=0
Collectable string class.
virtual Int_t GetMaximumBin() const
Return location of bin with maximum value in the range.
virtual Double_t GetValueForRoot(Double_t)
returns efficiency as function of cut
const TString & GetExpression() const
TString & ReplaceAll(const TString &s1, const TString &s2)
const char * GetName() const
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 Optimizer with the set of parameters 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...
A TMultiGraph is a collection of TGraph (or derived) objects.
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 base Class for all MVA method.
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, , curve for given number of signal and background events; returns cut for maximum ...
static Bool_t AddDirectoryStatus()
Static function: cannot be inlined on Windows/NT.
tomato 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 "a" or a hierarchy of sub-directories "a/b/c/...".
virtual void TestMulticlass()
test multiclass classification
TMatrixD GetConfusionMatrix(Double_t effB)
Returns a confusion matrix where each class is pitted against each other.
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
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...
Class that contains all the information of a class.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
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
virtual std::vector< Double_t > GetMvaValues(Long64_t firstEvt=0, Long64_t lastEvt=-1, Bool_t logProgress=false)
get all the MVA values for the events of the current Data type
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 ...
MethodBase(const TString &jobName, Types::EMVA methodType, const TString &methodTitle, DataSetInfo &dsi, const TString &theOption="")
standard constructor
void ClearGraphs()
This function sets the point number to 0 for all graphs.
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()
~IPythonInteractive()
standard destructor
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
std::vector< std::vector< double > > Data
void SetupMethod()
setup of methods
void Init(std::vector< TString > &graphTitles)
This function gets some title and it creates a TGraph for every title.
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.
Class that contains all the data information.
virtual Double_t GetProba(const Event *ev)
PDF wrapper for histograms; uses user-defined spline interpolation.
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.
void CreateVariableTransforms(const TString &trafoDefinition, TMVA::DataSetInfo &dataInfo, TMVA::TransformationHandler &transformationHandler, TMVA::MsgLogger &log)
virtual std::vector< Float_t > GetMulticlassEfficiency(std::vector< std::vector< Float_t > > &purity)
Double_t Root(Double_t refValue)
Root finding using Brents algorithm; taken from CERNLIB function RZERO.
TString GetElapsedTime(Bool_t Scientific=kTRUE)
returns pretty string with elapsed time
TMatrixT< Double_t > TMatrixD
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 histogram.
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.
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
tomato 2-D histogram with a float per channel (see TH1 documentation)}
class TMVA::Config::VariablePlotting fVariablePlotting
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
virtual const char * GetName() const
Returns name of object.
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
void DeclareBaseOptions()
define the options (their key words) that can be set in the option string here the options valid for ...
tomato 1-D histogram with a double per channel (see TH1 documentation)}
Linear interpolation of TGraph.
void ProcessBaseOptions()
the option string is decoded, for available 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
void DeclareOptions()
define the options (their key words) that can be set in the option string
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)
calculate the best working point (optimal cut values) for the multiclass classifier ...
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...
Class which takes the results of a multiclass classification.
static RooMathCoreReg dummy
const Bool_t Use_Splines_for_Eff_
IPythonInteractive()
standard constructor
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
Float_t GetTarget(UInt_t itgt) const
Interface for all concrete MVA method implementations.
void * GetExternalLink() const
Float_t GetAchievableEff(UInt_t cls)
void SetSource(const std::string &source)
virtual Double_t GetSeparation(TH1 *, TH1 *) const
compute "separation" defined as
Root finding using Brents algorithm (translated from CERNLIB function RZERO)
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 <sum-of-deviation-squared> 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)
read VariableInfo from stream
void PrintHelpMessage() const
prints out method-specific help method
virtual void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility they are hence without any...
Class that is the base-class for a vector of result.
Short_t Max(Short_t a, Short_t b)
void AddToXML(void *varnode)
write class to XML
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.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
THist< 1, double, THistStatContent, THistStatUncertainty > TH1D
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:
std::vector< Bool_t > * GetValueVectorTypes()
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: where PDF(x) is the PDF of the classifier's signal or background distribution ...
Double_t Sqrt(Double_t x)
Class for type info of MVA input variable.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
virtual TMatrixD GetMulticlassConfusionMatrix(Double_t effB, Types::ETreeType type)
Construct a confusion matrix for a multiclass classifier.
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.
THist< 2, float, THistStatContent, THistStatUncertainty > TH2F
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.
Timing information for training and evaluation of MVA methods.
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.
Class that is the base-class for a vector of result.
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.