139#pragma warning ( disable : 4355 )
160 fMultiGraph =
nullptr;
174 std::cerr << kERROR <<
"IPythonInteractive::Init: already initialized..." << std::endl;
178 for(
auto& title : graphTitles){
179 fGraphs.push_back(
new TGraph() );
180 fGraphs.back()->SetTitle(title);
181 fGraphs.back()->SetName(title);
182 fGraphs.back()->SetFillColor(color);
183 fGraphs.back()->SetLineColor(color);
184 fGraphs.back()->SetMarkerColor(color);
185 fMultiGraph->Add(fGraphs.back());
197 for(
Int_t i=0; i<fNumGraphs; i++){
211 fGraphs[0]->Set(fIndex+1);
212 fGraphs[1]->Set(fIndex+1);
213 fGraphs[0]->SetPoint(fIndex,
x, y1);
214 fGraphs[1]->SetPoint(fIndex,
x, y2);
227 for(
Int_t i=0; i<fNumGraphs;i++){
228 fGraphs[i]->Set(fIndex+1);
229 fGraphs[i]->SetPoint(fIndex, dat[0], dat[i+1]);
249 fAnalysisType (
Types::kNoAnalysisType ),
250 fRegressionReturnVal ( 0 ),
251 fMulticlassReturnVal ( 0 ),
252 fDataSetInfo ( dsi ),
253 fSignalReferenceCut ( 0.5 ),
254 fSignalReferenceCutOrientation( 1. ),
255 fVariableTransformType (
Types::kSignal ),
256 fJobName ( jobName ),
257 fMethodName ( methodTitle ),
258 fMethodType ( methodType ),
262 fConstructedFromWeightFile (
kFALSE ),
264 fMethodBaseDir ( 0 ),
267 fModelPersistence (
kTRUE),
278 fSplTrainEffBvsS ( 0 ),
279 fVarTransformString (
"None" ),
280 fTransformationPointer ( 0 ),
281 fTransformation ( dsi, methodTitle ),
283 fVerbosityLevelString (
"Default" ),
286 fIgnoreNegWeightsInTraining(
kFALSE ),
288 fBackgroundClass ( 0 ),
313 fAnalysisType (
Types::kNoAnalysisType ),
314 fRegressionReturnVal ( 0 ),
315 fMulticlassReturnVal ( 0 ),
316 fDataSetInfo ( dsi ),
317 fSignalReferenceCut ( 0.5 ),
318 fVariableTransformType (
Types::kSignal ),
320 fMethodName (
"MethodBase" ),
321 fMethodType ( methodType ),
323 fTMVATrainingVersion ( 0 ),
324 fROOTTrainingVersion ( 0 ),
325 fConstructedFromWeightFile (
kTRUE ),
327 fMethodBaseDir ( 0 ),
330 fModelPersistence (
kTRUE),
331 fWeightFile ( weightFile ),
341 fSplTrainEffBvsS ( 0 ),
342 fVarTransformString (
"None" ),
343 fTransformationPointer ( 0 ),
344 fTransformation ( dsi,
"" ),
346 fVerbosityLevelString (
"Default" ),
349 fIgnoreNegWeightsInTraining(
kFALSE ),
351 fBackgroundClass ( 0 ),
369 if (!fSetupCompleted)
Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"Calling destructor of method which got never setup" <<
Endl;
372 if (fInputVars != 0) { fInputVars->clear();
delete fInputVars; }
373 if (fRanking != 0)
delete fRanking;
376 if (fDefaultPDF!= 0) {
delete fDefaultPDF; fDefaultPDF = 0; }
377 if (fMVAPdfS != 0) {
delete fMVAPdfS; fMVAPdfS = 0; }
378 if (fMVAPdfB != 0) {
delete fMVAPdfB; fMVAPdfB = 0; }
381 if (fSplS) {
delete fSplS; fSplS = 0; }
382 if (fSplB) {
delete fSplB; fSplB = 0; }
383 if (fSpleffBvsS) {
delete fSpleffBvsS; fSpleffBvsS = 0; }
384 if (fSplRefS) {
delete fSplRefS; fSplRefS = 0; }
385 if (fSplRefB) {
delete fSplRefB; fSplRefB = 0; }
386 if (fSplTrainRefS) {
delete fSplTrainRefS; fSplTrainRefS = 0; }
387 if (fSplTrainRefB) {
delete fSplTrainRefB; fSplTrainRefB = 0; }
388 if (fSplTrainEffBvsS) {
delete fSplTrainEffBvsS; fSplTrainEffBvsS = 0; }
390 for (
Int_t i = 0; i < 2; i++ ) {
391 if (fEventCollections.at(i)) {
392 for (std::vector<Event*>::const_iterator it = fEventCollections.at(i)->begin();
393 it != fEventCollections.at(i)->end(); ++it) {
396 delete fEventCollections.at(i);
397 fEventCollections.at(i) = 0;
401 if (fRegressionReturnVal)
delete fRegressionReturnVal;
402 if (fMulticlassReturnVal)
delete fMulticlassReturnVal;
412 if (fSetupCompleted)
Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"Calling SetupMethod for the second time" <<
Endl;
414 DeclareBaseOptions();
417 fSetupCompleted =
kTRUE;
427 ProcessBaseOptions();
437 CheckForUnusedOptions();
445 SetConfigDescription(
"Configuration options for classifier architecture and tuning" );
453 fSplTrainEffBvsS = 0;
460 fTxtWeightsOnly =
kTRUE;
470 fInputVars =
new std::vector<TString>;
471 for (
UInt_t ivar=0; ivar<GetNvar(); ivar++) {
472 fInputVars->push_back(DataInfo().GetVariableInfo(ivar).GetLabel());
474 fRegressionReturnVal = 0;
475 fMulticlassReturnVal = 0;
477 fEventCollections.resize( 2 );
478 fEventCollections.at(0) = 0;
479 fEventCollections.at(1) = 0;
482 if (DataInfo().GetClassInfo(
"Signal") != 0) {
483 fSignalClass = DataInfo().GetClassInfo(
"Signal")->GetNumber();
485 if (DataInfo().GetClassInfo(
"Background") != 0) {
486 fBackgroundClass = DataInfo().GetClassInfo(
"Background")->GetNumber();
489 SetConfigDescription(
"Configuration options for MVA method" );
490 SetConfigName(
TString(
"Method") + GetMethodTypeName() );
513 DeclareOptionRef( fVerbose,
"V",
"Verbose output (short form of \"VerbosityLevel\" below - overrides the latter one)" );
515 DeclareOptionRef( fVerbosityLevelString=
"Default",
"VerbosityLevel",
"Verbosity level" );
516 AddPreDefVal(
TString(
"Default") );
517 AddPreDefVal(
TString(
"Debug") );
518 AddPreDefVal(
TString(
"Verbose") );
519 AddPreDefVal(
TString(
"Info") );
520 AddPreDefVal(
TString(
"Warning") );
521 AddPreDefVal(
TString(
"Error") );
522 AddPreDefVal(
TString(
"Fatal") );
526 fTxtWeightsOnly =
kTRUE;
529 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)\"" );
531 DeclareOptionRef( fHelp,
"H",
"Print method-specific help message" );
533 DeclareOptionRef( fHasMVAPdfs,
"CreateMVAPdfs",
"Create PDFs for classifier outputs (signal and background)" );
535 DeclareOptionRef( fIgnoreNegWeightsInTraining,
"IgnoreNegWeightsInTraining",
536 "Events with negative weights are ignored in the training (but are included for testing and performance evaluation)" );
548 fDefaultPDF =
new PDF(
TString(GetName())+
"_PDF", GetOptions(),
"MVAPdf" );
549 fDefaultPDF->DeclareOptions();
550 fDefaultPDF->ParseOptions();
551 fDefaultPDF->ProcessOptions();
552 fMVAPdfB =
new PDF(
TString(GetName())+
"_PDFBkg", fDefaultPDF->GetOptions(),
"MVAPdfBkg", fDefaultPDF );
553 fMVAPdfB->DeclareOptions();
554 fMVAPdfB->ParseOptions();
555 fMVAPdfB->ProcessOptions();
556 fMVAPdfS =
new PDF(
TString(GetName())+
"_PDFSig", fMVAPdfB->GetOptions(),
"MVAPdfSig", fDefaultPDF );
557 fMVAPdfS->DeclareOptions();
558 fMVAPdfS->ParseOptions();
559 fMVAPdfS->ProcessOptions();
562 SetOptions( fMVAPdfS->GetOptions() );
567 GetTransformationHandler(),
571 if (fDefaultPDF!= 0) {
delete fDefaultPDF; fDefaultPDF = 0; }
572 if (fMVAPdfS != 0) {
delete fMVAPdfS; fMVAPdfS = 0; }
573 if (fMVAPdfB != 0) {
delete fMVAPdfB; fMVAPdfB = 0; }
577 fVerbosityLevelString =
TString(
"Verbose");
578 Log().SetMinType( kVERBOSE );
580 else if (fVerbosityLevelString ==
"Debug" )
Log().SetMinType( kDEBUG );
581 else if (fVerbosityLevelString ==
"Verbose" )
Log().SetMinType( kVERBOSE );
582 else if (fVerbosityLevelString ==
"Info" )
Log().SetMinType( kINFO );
583 else if (fVerbosityLevelString ==
"Warning" )
Log().SetMinType( kWARNING );
584 else if (fVerbosityLevelString ==
"Error" )
Log().SetMinType( kERROR );
585 else if (fVerbosityLevelString ==
"Fatal" )
Log().SetMinType( kFATAL );
586 else if (fVerbosityLevelString !=
"Default" ) {
587 Log() << kFATAL <<
"<ProcessOptions> Verbosity level type '"
588 << fVerbosityLevelString <<
"' unknown." <<
Endl;
600 DeclareOptionRef( fNormalise=
kFALSE,
"Normalise",
"Normalise input variables" );
601 DeclareOptionRef( fUseDecorr=
kFALSE,
"D",
"Use-decorrelated-variables flag" );
602 DeclareOptionRef( fVariableTransformTypeString=
"Signal",
"VarTransformType",
603 "Use signal or background events to derive for variable transformation (the transformation is applied on both types of, course)" );
604 AddPreDefVal(
TString(
"Signal") );
605 AddPreDefVal(
TString(
"Background") );
606 DeclareOptionRef( fTxtWeightsOnly=
kTRUE,
"TxtWeightFilesOnly",
"If True: write all training results (weights) as text files (False: some are written in ROOT format)" );
616 DeclareOptionRef( fNbinsMVAPdf = 60,
"NbinsMVAPdf",
"Number of bins used for the PDFs of classifier outputs" );
617 DeclareOptionRef( fNsmoothMVAPdf = 2,
"NsmoothMVAPdf",
"Number of smoothing iterations for classifier PDFs" );
631 Log() << kWARNING <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"Parameter optimization is not yet implemented for method "
632 << GetName() <<
Endl;
633 Log() << kWARNING <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"Currently we need to set hardcoded which parameter is tuned in which ranges"<<
Endl;
635 std::map<TString,Double_t> tunedParameters;
636 tunedParameters.size();
637 return tunedParameters;
658 if (Help()) PrintHelpMessage();
661 if(!IsSilentFile()) BaseDir()->cd();
665 GetTransformationHandler().CalcTransformations(Data()->GetEventCollection());
669 <<
"Begin training" <<
Endl;
670 Long64_t nEvents = Data()->GetNEvents();
671 Timer traintimer( nEvents, GetName(),
kTRUE );
674 <<
"\tEnd of training " <<
Endl;
677 <<
"Elapsed time for training with " << nEvents <<
" events: "
681 <<
"\tCreate MVA output for ";
684 if (DoMulticlass()) {
685 Log() <<
Form(
"[%s] : ",DataInfo().GetName())<<
"Multiclass classification on training sample" <<
Endl;
688 else if (!DoRegression()) {
690 Log() <<
Form(
"[%s] : ",DataInfo().GetName())<<
"classification on training sample" <<
Endl;
699 Log() <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"regression on training sample" <<
Endl;
703 Log() <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"Create PDFs" <<
Endl;
710 if (fModelPersistence ) WriteStateToFile();
713 if ((!DoRegression()) && (fModelPersistence)) MakeClass();
720 WriteMonitoringHistosToFile();
728 if (!DoRegression())
Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"Trying to use GetRegressionDeviation() with a classification job" <<
Endl;
731 bool truncate =
false;
732 TH1F*
h1 = regRes->QuadraticDeviation( tgtNum , truncate, 1.);
737 TH1F* h2 = regRes->QuadraticDeviation( tgtNum , truncate, yq[0]);
748 Data()->SetCurrentType(
type);
754 Long64_t nEvents = Data()->GetNEvents();
758 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().GetName()) <<
"Evaluation of " <<
GetMethodName() <<
" on "
761 regRes->Resize( nEvents );
766 Int_t totalProgressDraws = 100;
767 Int_t drawProgressEvery = 1;
768 if(nEvents >= totalProgressDraws) drawProgressEvery = nEvents/totalProgressDraws;
770 for (
Int_t ievt=0; ievt<nEvents; ievt++) {
772 Data()->SetCurrentEvent(ievt);
773 std::vector< Float_t > vals = GetRegressionValues();
774 regRes->SetValue( vals, ievt );
777 if(ievt % drawProgressEvery == 0 || ievt==nEvents-1) timer.
DrawProgressBar( ievt );
780 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().GetName())
781 <<
"Elapsed time for evaluation of " << nEvents <<
" events: "
788 TString histNamePrefix(GetTestvarName());
790 regRes->CreateDeviationHistograms( histNamePrefix );
798 Data()->SetCurrentType(
type);
803 if (!resMulticlass)
Log() << kFATAL<<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"unable to create pointer in AddMulticlassOutput, exiting."<<
Endl;
805 Long64_t nEvents = Data()->GetNEvents();
810 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"Multiclass evaluation of " <<
GetMethodName() <<
" on "
813 resMulticlass->Resize( nEvents );
814 for (
Int_t ievt=0; ievt<nEvents; ievt++) {
815 Data()->SetCurrentEvent(ievt);
816 std::vector< Float_t > vals = GetMulticlassValues();
817 resMulticlass->SetValue( vals, ievt );
821 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().GetName())
822 <<
"Elapsed time for evaluation of " << nEvents <<
" events: "
829 TString histNamePrefix(GetTestvarName());
832 resMulticlass->CreateMulticlassHistos( histNamePrefix, fNbinsMVAoutput, fNbinsH );
833 resMulticlass->CreateMulticlassPerformanceHistos(histNamePrefix);
840 if (errUpper) *errUpper=-1;
847 Double_t val = GetMvaValue(err, errUpper);
857 return GetMvaValue()*GetSignalReferenceCutOrientation() > GetSignalReferenceCut()*GetSignalReferenceCutOrientation() ?
kTRUE :
kFALSE;
864 return mvaVal*GetSignalReferenceCutOrientation() > GetSignalReferenceCut()*GetSignalReferenceCutOrientation() ?
kTRUE :
kFALSE;
872 Data()->SetCurrentType(
type);
877 Long64_t nEvents = Data()->GetNEvents();
882 std::vector<Double_t> mvaValues = GetMvaValues(0, nEvents,
true);
889 for (
Int_t ievt=0; ievt<nEvents; ievt++) {
890 clRes->
SetValue( mvaValues[ievt], ievt );
899 Long64_t nEvents = Data()->GetNEvents();
900 if (firstEvt > lastEvt || lastEvt > nEvents) lastEvt = nEvents;
901 if (firstEvt < 0) firstEvt = 0;
902 std::vector<Double_t> values(lastEvt-firstEvt);
904 nEvents = values.size();
910 Log() << kHEADER <<
Form(
"[%s] : ",DataInfo().GetName())
913 <<
" sample (" << nEvents <<
" events)" <<
Endl;
915 for (
Int_t ievt=firstEvt; ievt<lastEvt; ievt++) {
916 Data()->SetCurrentEvent(ievt);
917 values[ievt] = GetMvaValue();
922 if (modulo <= 0 ) modulo = 1;
928 <<
"Elapsed time for evaluation of " << nEvents <<
" events: "
940 Data()->SetCurrentType(
type);
945 Long64_t nEvents = Data()->GetNEvents();
950 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().GetName()) <<
"Evaluation of " <<
GetMethodName() <<
" on "
953 mvaProb->
Resize( nEvents );
954 for (
Int_t ievt=0; ievt<nEvents; ievt++) {
956 Data()->SetCurrentEvent(ievt);
958 if (proba < 0)
break;
963 if (modulo <= 0 ) modulo = 1;
967 Log() << kDEBUG <<
Form(
"Dataset[%s] : ",DataInfo().GetName())
968 <<
"Elapsed time for evaluation of " << nEvents <<
" events: "
987 Data()->SetCurrentType(
type);
989 bias = 0; biasT = 0; dev = 0; devT = 0; rms = 0; rmsT = 0;
992 const Int_t nevt = GetNEvents();
997 Log() << kINFO <<
"Calculate regression for all events" <<
Endl;
999 for (
Long64_t ievt=0; ievt<nevt; ievt++) {
1001 const Event* ev = Data()->GetEvent(ievt);
1004 Float_t r = GetRegressionValues()[0];
1023 m1 += t*w;
s1 += t*t*w;
1024 m2 +=
r*w; s2 +=
r*
r*w;
1029 Log() << kINFO <<
"Elapsed time for evaluation of " << nevt <<
" events: "
1041 corr = s12/sumw - m1*
m2;
1053 for (
Long64_t ievt=0; ievt<nevt; ievt++) {
1055 hist->
Fill( rV[ievt], tV[ievt], wV[ievt] );
1056 if (
d >= devMin &&
d <= devMax) {
1058 biasT += wV[ievt] *
d;
1060 rmsT += wV[ievt] *
d *
d;
1061 histT->
Fill( rV[ievt], tV[ievt], wV[ievt] );
1079 Data()->SetCurrentType(savedType);
1089 if (!resMulticlass)
Log() << kFATAL<<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"unable to create pointer in TestMulticlass, exiting."<<
Endl;
1098 TString histNamePrefix(GetTestvarName());
1099 TString histNamePrefixTest{histNamePrefix +
"_Test"};
1100 TString histNamePrefixTrain{histNamePrefix +
"_Train"};
1121 if (0==mvaRes && !(GetMethodTypeName().Contains(
"Cuts"))) {
1122 Log()<<
Form(
"Dataset[%s] : ",DataInfo().GetName()) <<
"mvaRes " << mvaRes <<
" GetMethodTypeName " << GetMethodTypeName()
1123 <<
" contains " << !(GetMethodTypeName().Contains(
"Cuts")) <<
Endl;
1124 Log() << kFATAL<<
Form(
"Dataset[%s] : ",DataInfo().GetName()) <<
"<TestInit> Test variable " << GetTestvarName()
1125 <<
" not found in tree" <<
Endl;
1130 fMeanS, fMeanB, fRmsS, fRmsB, fXmin, fXmax, fSignalClass );
1138 fCutOrientation = (fMeanS > fMeanB) ? kPositive : kNegative;
1150 TestvarName=
Form(
"[%s]%s",DataInfo().GetName(),GetTestvarName().Data());
1153 TestvarName=GetTestvarName();
1155 TH1* mva_s =
new TH1D( TestvarName +
"_S",TestvarName +
"_S", fNbinsMVAoutput, fXmin, sxmax );
1156 TH1* mva_b =
new TH1D( TestvarName +
"_B",TestvarName +
"_B", fNbinsMVAoutput, fXmin, sxmax );
1157 mvaRes->
Store(mva_s,
"MVA_S");
1158 mvaRes->
Store(mva_b,
"MVA_B");
1168 proba_s =
new TH1D( TestvarName +
"_Proba_S", TestvarName +
"_Proba_S", fNbinsMVAoutput, 0.0, 1.0 );
1169 proba_b =
new TH1D( TestvarName +
"_Proba_B", TestvarName +
"_Proba_B", fNbinsMVAoutput, 0.0, 1.0 );
1170 mvaRes->
Store(proba_s,
"Prob_S");
1171 mvaRes->
Store(proba_b,
"Prob_B");
1176 rarity_s =
new TH1D( TestvarName +
"_Rarity_S", TestvarName +
"_Rarity_S", fNbinsMVAoutput, 0.0, 1.0 );
1177 rarity_b =
new TH1D( TestvarName +
"_Rarity_B", TestvarName +
"_Rarity_B", fNbinsMVAoutput, 0.0, 1.0 );
1178 mvaRes->
Store(rarity_s,
"Rar_S");
1179 mvaRes->
Store(rarity_b,
"Rar_B");
1185 TH1* mva_eff_s =
new TH1D( TestvarName +
"_S_high", TestvarName +
"_S_high", fNbinsH, fXmin, sxmax );
1186 TH1* mva_eff_b =
new TH1D( TestvarName +
"_B_high", TestvarName +
"_B_high", fNbinsH, fXmin, sxmax );
1187 mvaRes->
Store(mva_eff_s,
"MVA_HIGHBIN_S");
1188 mvaRes->
Store(mva_eff_b,
"MVA_HIGHBIN_B");
1197 Log() << kHEADER <<
Form(
"[%s] : ",DataInfo().GetName())<<
"Loop over test events and fill histograms with classifier response..." <<
Endl <<
Endl;
1198 if (mvaProb)
Log() << kINFO <<
"Also filling probability and rarity histograms (on request)..." <<
Endl;
1202 if ( mvaRes->
GetSize() != GetNEvents() ) {
1204 assert(mvaRes->
GetSize() == GetNEvents());
1207 for (
Long64_t ievt=0; ievt<GetNEvents(); ievt++) {
1209 const Event* ev = GetEvent(ievt);
1213 if (DataInfo().IsSignal(ev)) {
1214 mvaResTypes->push_back(
kTRUE);
1215 mva_s ->
Fill(
v, w );
1217 proba_s->
Fill( (*mvaProb)[ievt][0], w );
1218 rarity_s->
Fill( GetRarity(
v ), w );
1221 mva_eff_s ->
Fill(
v, w );
1224 mvaResTypes->push_back(
kFALSE);
1225 mva_b ->
Fill(
v, w );
1227 proba_b->
Fill( (*mvaProb)[ievt][0], w );
1228 rarity_b->
Fill( GetRarity(
v ), w );
1230 mva_eff_b ->
Fill(
v, w );
1245 if (fSplS) {
delete fSplS; fSplS = 0; }
1246 if (fSplB) {
delete fSplB; fSplB = 0; }
1260 tf << prefix <<
"#GEN -*-*-*-*-*-*-*-*-*-*-*- general info -*-*-*-*-*-*-*-*-*-*-*-" << std::endl << prefix << std::endl;
1261 tf << prefix <<
"Method : " << GetMethodTypeName() <<
"::" <<
GetMethodName() << std::endl;
1262 tf.setf(std::ios::left);
1263 tf << prefix <<
"TMVA Release : " << std::setw(10) << GetTrainingTMVAVersionString() <<
" ["
1264 << GetTrainingTMVAVersionCode() <<
"]" << std::endl;
1265 tf << prefix <<
"ROOT Release : " << std::setw(10) << GetTrainingROOTVersionString() <<
" ["
1266 << GetTrainingROOTVersionCode() <<
"]" << std::endl;
1267 tf << prefix <<
"Creator : " << userInfo->
fUser << std::endl;
1268 tf << prefix <<
"Date : ";
TDatime *
d =
new TDatime; tf <<
d->AsString() << std::endl;
delete d;
1271 tf << prefix <<
"Training events: " << Data()->GetNTrainingEvents() << std::endl;
1275 tf << prefix <<
"Analysis type : " <<
"[" << ((GetAnalysisType()==
Types::kRegression) ?
"Regression" :
"Classification") <<
"]" << std::endl;
1276 tf << prefix << std::endl;
1281 tf << prefix << std::endl << prefix <<
"#OPT -*-*-*-*-*-*-*-*-*-*-*-*- options -*-*-*-*-*-*-*-*-*-*-*-*-" << std::endl << prefix << std::endl;
1282 WriteOptionsToStream( tf, prefix );
1283 tf << prefix << std::endl;
1286 tf << prefix << std::endl << prefix <<
"#VAR -*-*-*-*-*-*-*-*-*-*-*-* variables *-*-*-*-*-*-*-*-*-*-*-*-" << std::endl << prefix << std::endl;
1287 WriteVarsToStream( tf, prefix );
1288 tf << prefix << std::endl;
1305 AddRegressionOutput(
type );
1307 AddMulticlassOutput(
type );
1309 AddClassifierOutput(
type );
1311 AddClassifierOutputProb(
type );
1321 if (!parent)
return;
1326 AddInfoItem( gi,
"TMVA Release", GetTrainingTMVAVersionString() +
" [" +
gTools().StringFromInt(GetTrainingTMVAVersionCode()) +
"]" );
1327 AddInfoItem( gi,
"ROOT Release", GetTrainingROOTVersionString() +
" [" +
gTools().StringFromInt(GetTrainingROOTVersionCode()) +
"]");
1328 AddInfoItem( gi,
"Creator", userInfo->
fUser);
1332 AddInfoItem( gi,
"Training events",
gTools().StringFromInt(Data()->GetNTrainingEvents()));
1333 AddInfoItem( gi,
"TrainingTime",
gTools().StringFromDouble(
const_cast<TMVA::MethodBase*
>(
this)->GetTrainTime()));
1338 AddInfoItem( gi,
"AnalysisType", analysisType );
1342 AddOptionsXMLTo( parent );
1345 AddVarsXMLTo( parent );
1348 if (fModelPersistence)
1349 AddSpectatorsXMLTo( parent );
1352 AddClassesXMLTo(parent);
1355 if (DoRegression()) AddTargetsXMLTo(parent);
1358 GetTransformationHandler(
false).AddXMLTo( parent );
1362 if (fMVAPdfS) fMVAPdfS->AddXMLTo(pdfs);
1363 if (fMVAPdfB) fMVAPdfB->AddXMLTo(pdfs);
1366 AddWeightsXMLTo( parent );
1382 ReadWeightsFromStream( rf );
1395 TString tfname( GetWeightFileName() );
1400 <<
"Creating xml weight file: "
1406 WriteStateToXML(rootnode);
1418 TString tfname(GetWeightFileName());
1421 <<
"Reading weight file: "
1427 Log() << kFATAL <<
"Error parsing XML file " << tfname <<
Endl;
1430 ReadStateFromXML(rootnode);
1435 fb.open(tfname.
Data(),std::ios::in);
1436 if (!fb.is_open()) {
1437 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"<ReadStateFromFile> "
1438 <<
"Unable to open input weight file: " << tfname <<
Endl;
1440 std::istream fin(&fb);
1441 ReadStateFromStream(fin);
1444 if (!fTxtWeightsOnly) {
1447 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"Reading root weight file: "
1450 ReadStateFromStream( *rfile );
1460 ReadStateFromXML(rootnode);
1474 fMethodName = fullMethodName(fullMethodName.
Index(
"::")+2,fullMethodName.
Length());
1477 Log().SetSource( GetName() );
1479 <<
"Read method \"" <<
GetMethodName() <<
"\" of type \"" << GetMethodTypeName() <<
"\"" <<
Endl;
1489 if (nodeName==
"GeneralInfo") {
1494 while (antypeNode) {
1497 if (
name ==
"TrainingTime")
1500 if (
name ==
"AnalysisType") {
1506 else Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"Analysis type " << val <<
" is not known." <<
Endl;
1509 if (
name ==
"TMVA Release" ||
name ==
"TMVA") {
1512 fTMVATrainingVersion =
TString(
s(
s.Index(
"[")+1,
s.Index(
"]")-
s.Index(
"[")-1)).
Atoi();
1513 Log() << kDEBUG <<
Form(
"[%s] : ",DataInfo().GetName()) <<
"MVA method was trained with TMVA Version: " << GetTrainingTMVAVersionString() <<
Endl;
1516 if (
name ==
"ROOT Release" ||
name ==
"ROOT") {
1519 fROOTTrainingVersion =
TString(
s(
s.Index(
"[")+1,
s.Index(
"]")-
s.Index(
"[")-1)).
Atoi();
1521 <<
"MVA method was trained with ROOT Version: " << GetTrainingROOTVersionString() <<
Endl;
1526 else if (nodeName==
"Options") {
1527 ReadOptionsFromXML(ch);
1531 else if (nodeName==
"Variables") {
1532 ReadVariablesFromXML(ch);
1534 else if (nodeName==
"Spectators") {
1535 ReadSpectatorsFromXML(ch);
1537 else if (nodeName==
"Classes") {
1538 if (DataInfo().GetNClasses()==0) ReadClassesFromXML(ch);
1540 else if (nodeName==
"Targets") {
1541 if (DataInfo().GetNTargets()==0 && DoRegression()) ReadTargetsFromXML(ch);
1543 else if (nodeName==
"Transformations") {
1544 GetTransformationHandler().ReadFromXML(ch);
1546 else if (nodeName==
"MVAPdfs") {
1548 if (fMVAPdfS) {
delete fMVAPdfS; fMVAPdfS=0; }
1549 if (fMVAPdfB) {
delete fMVAPdfB; fMVAPdfB=0; }
1553 fMVAPdfS =
new PDF(pdfname);
1554 fMVAPdfS->ReadXML(pdfnode);
1557 fMVAPdfB =
new PDF(pdfname);
1558 fMVAPdfB->ReadXML(pdfnode);
1561 else if (nodeName==
"Weights") {
1562 ReadWeightsFromXML(ch);
1565 Log() << kWARNING <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"Unparsed XML node: '" << nodeName <<
"'" <<
Endl;
1572 if (GetTransformationHandler().GetCallerName() ==
"") GetTransformationHandler().SetCallerName( GetName() );
1592 methodType = methodType(methodType.
Last(
' '),methodType.
Length());
1597 if (methodName ==
"") methodName = methodType;
1598 fMethodName = methodName;
1600 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"Read method \"" <<
GetMethodName() <<
"\" of type \"" << GetMethodTypeName() <<
"\"" <<
Endl;
1603 Log().SetSource( GetName() );
1618 ReadOptionsFromStream(fin);
1622 fin.getline(buf,512);
1624 ReadVarsFromStream(fin);
1629 if (IsNormalised()) {
1635 if ( fVarTransformString ==
"None") {
1638 }
else if ( fVarTransformString ==
"Decorrelate" ) {
1640 }
else if ( fVarTransformString ==
"PCA" ) {
1641 varTrafo = GetTransformationHandler().AddTransformation(
new VariablePCATransform(DataInfo()), -1 );
1642 }
else if ( fVarTransformString ==
"Uniform" ) {
1643 varTrafo = GetTransformationHandler().AddTransformation(
new VariableGaussTransform(DataInfo(),
"Uniform"), -1 );
1644 }
else if ( fVarTransformString ==
"Gauss" ) {
1646 }
else if ( fVarTransformString ==
"GaussDecorr" ) {
1650 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"<ProcessOptions> Variable transform '"
1651 << fVarTransformString <<
"' unknown." <<
Endl;
1654 if (GetTransformationHandler().GetTransformationList().GetSize() > 0) {
1655 fin.getline(buf,512);
1659 varTrafo->ReadTransformationFromStream(fin, trafo );
1670 fin.getline(buf,512);
1672 if (fMVAPdfS != 0) {
delete fMVAPdfS; fMVAPdfS = 0; }
1673 if (fMVAPdfB != 0) {
delete fMVAPdfB; fMVAPdfB = 0; }
1674 fMVAPdfS =
new PDF(
TString(GetName()) +
" MVA PDF Sig");
1675 fMVAPdfB =
new PDF(
TString(GetName()) +
" MVA PDF Bkg");
1676 fMVAPdfS->SetReadingVersion( GetTrainingTMVAVersionCode() );
1677 fMVAPdfB->SetReadingVersion( GetTrainingTMVAVersionCode() );
1684 fin.getline(buf,512);
1686 fin.getline(buf,512);
1687 ReadWeightsFromStream( fin );;
1690 if (GetTransformationHandler().GetCallerName() ==
"") GetTransformationHandler().SetCallerName( GetName() );
1700 o << prefix <<
"NVar " << DataInfo().GetNVariables() << std::endl;
1701 std::vector<VariableInfo>::const_iterator varIt = DataInfo().GetVariableInfos().begin();
1702 for (; varIt!=DataInfo().GetVariableInfos().end(); ++varIt) { o << prefix; varIt->WriteToStream(o); }
1703 o << prefix <<
"NSpec " << DataInfo().GetNSpectators() << std::endl;
1704 varIt = DataInfo().GetSpectatorInfos().begin();
1705 for (; varIt!=DataInfo().GetSpectatorInfos().end(); ++varIt) { o << prefix; varIt->WriteToStream(o); }
1717 istr >>
dummy >> readNVar;
1719 if (readNVar!=DataInfo().GetNVariables()) {
1720 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"You declared "<< DataInfo().GetNVariables() <<
" variables in the Reader"
1721 <<
" while there are " << readNVar <<
" variables declared in the file"
1727 std::vector<VariableInfo>::iterator varIt = DataInfo().GetVariableInfos().begin();
1729 for (; varIt!=DataInfo().GetVariableInfos().end(); ++varIt, ++varIdx) {
1736 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"ERROR in <ReadVarsFromStream>" <<
Endl;
1737 Log() << kINFO <<
"The definition (or the order) of the variables found in the input file is" <<
Endl;
1738 Log() << kINFO <<
"is not the same as the one declared in the Reader (which is necessary for" <<
Endl;
1739 Log() << kINFO <<
"the correct working of the method):" <<
Endl;
1740 Log() << kINFO <<
" var #" << varIdx <<
" declared in Reader: " << varIt->GetExpression() <<
Endl;
1741 Log() << kINFO <<
" var #" << varIdx <<
" declared in file : " << varInfo.
GetExpression() <<
Endl;
1742 Log() << kFATAL <<
"The expression declared to the Reader needs to be checked (name or order are wrong)" <<
Endl;
1755 for (
UInt_t idx=0; idx<DataInfo().GetVariableInfos().size(); idx++) {
1771 for (
UInt_t idx=0; idx<DataInfo().GetSpectatorInfos().size(); idx++) {
1773 VariableInfo& vi = DataInfo().GetSpectatorInfos()[idx];
1791 UInt_t nClasses=DataInfo().GetNClasses();
1796 for (
UInt_t iCls=0; iCls<nClasses; ++iCls) {
1797 ClassInfo *classInfo=DataInfo().GetClassInfo (iCls);
1814 for (
UInt_t idx=0; idx<DataInfo().GetTargetInfos().size(); idx++) {
1830 if (readNVar!=DataInfo().GetNVariables()) {
1831 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"You declared "<< DataInfo().GetNVariables() <<
" variables in the Reader"
1832 <<
" while there are " << readNVar <<
" variables declared in the file"
1842 existingVarInfo = DataInfo().GetVariableInfos()[varIdx];
1847 existingVarInfo = readVarInfo;
1850 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"ERROR in <ReadVariablesFromXML>" <<
Endl;
1851 Log() << kINFO <<
"The definition (or the order) of the variables found in the input file is" <<
Endl;
1852 Log() << kINFO <<
"not the same as the one declared in the Reader (which is necessary for the" <<
Endl;
1853 Log() << kINFO <<
"correct working of the method):" <<
Endl;
1854 Log() << kINFO <<
" var #" << varIdx <<
" declared in Reader: " << existingVarInfo.
GetExpression() <<
Endl;
1855 Log() << kINFO <<
" var #" << varIdx <<
" declared in file : " << readVarInfo.
GetExpression() <<
Endl;
1856 Log() << kFATAL <<
"The expression declared to the Reader needs to be checked (name or order are wrong)" <<
Endl;
1870 if (readNSpec!=DataInfo().GetNSpectators(
kFALSE)) {
1871 Log() << kFATAL<<
Form(
"Dataset[%s] : ",DataInfo().GetName()) <<
"You declared "<< DataInfo().GetNSpectators(
kFALSE) <<
" spectators in the Reader"
1872 <<
" while there are " << readNSpec <<
" spectators declared in the file"
1882 existingSpecInfo = DataInfo().GetSpectatorInfos()[specIdx];
1887 existingSpecInfo = readSpecInfo;
1890 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"ERROR in <ReadSpectatorsFromXML>" <<
Endl;
1891 Log() << kINFO <<
"The definition (or the order) of the spectators found in the input file is" <<
Endl;
1892 Log() << kINFO <<
"not the same as the one declared in the Reader (which is necessary for the" <<
Endl;
1893 Log() << kINFO <<
"correct working of the method):" <<
Endl;
1894 Log() << kINFO <<
" spec #" << specIdx <<
" declared in Reader: " << existingSpecInfo.
GetExpression() <<
Endl;
1895 Log() << kINFO <<
" spec #" << specIdx <<
" declared in file : " << readSpecInfo.
GetExpression() <<
Endl;
1896 Log() << kFATAL <<
"The expression declared to the Reader needs to be checked (name or order are wrong)" <<
Endl;
1915 for (
UInt_t icls = 0; icls<readNCls;++icls) {
1917 DataInfo().AddClass(classname);
1925 DataInfo().AddClass(className);
1932 if (DataInfo().GetClassInfo(
"Signal") != 0) {
1933 fSignalClass = DataInfo().GetClassInfo(
"Signal")->GetNumber();
1937 if (DataInfo().GetClassInfo(
"Background") != 0) {
1938 fBackgroundClass = DataInfo().GetClassInfo(
"Background")->GetNumber();
1958 DataInfo().AddTarget(expression,
"",
"",0,0);
1970 if (fBaseDir != 0)
return fBaseDir;
1971 Log()<<kDEBUG<<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
" Base Directory for " <<
GetMethodName() <<
" not set yet --> check if already there.." <<
Endl;
1973 if (IsSilentFile()) {
1974 Log() << kFATAL <<
Form(
"Dataset[%s] : ", DataInfo().GetName())
1975 <<
"MethodBase::BaseDir() - No directory exists when running a Method without output file. Enable the "
1976 "output when creating the factory"
1982 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"MethodBase::BaseDir() - MethodBaseDir() return a NULL pointer!" <<
Endl;
1988 Log()<<kDEBUG<<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
" Base Directory for " << GetMethodTypeName() <<
" does not exist yet--> created it" <<
Endl;
1989 sdir = methodDir->
mkdir(defaultDir);
1992 if (fModelPersistence) {
1995 wfilePath.
Write(
"TrainingPath" );
1996 wfileName.
Write(
"WeightFileName" );
2000 Log()<<kDEBUG<<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
" Base Directory for " << GetMethodTypeName() <<
" existed, return it.." <<
Endl;
2010 if (fMethodBaseDir != 0) {
2011 return fMethodBaseDir;
2014 const char *datasetName = DataInfo().
GetName();
2016 Log() << kDEBUG <<
Form(
"Dataset[%s] : ", datasetName) <<
" Base Directory for " << GetMethodTypeName()
2017 <<
" not set yet --> check if already there.." <<
Endl;
2020 if (!factoryBaseDir)
return nullptr;
2021 fMethodBaseDir = factoryBaseDir->
GetDirectory(datasetName);
2022 if (!fMethodBaseDir) {
2023 fMethodBaseDir = factoryBaseDir->
mkdir(datasetName,
Form(
"Base directory for dataset %s", datasetName));
2024 if (!fMethodBaseDir) {
2025 Log() << kFATAL <<
"Can not create dir " << datasetName;
2028 TString methodTypeDir =
Form(
"Method_%s", GetMethodTypeName().Data());
2029 fMethodBaseDir = fMethodBaseDir->GetDirectory(methodTypeDir.
Data());
2031 if (!fMethodBaseDir) {
2033 TString methodTypeDirHelpStr =
Form(
"Directory for all %s methods", GetMethodTypeName().Data());
2034 fMethodBaseDir = datasetDir->
mkdir(methodTypeDir.
Data(), methodTypeDirHelpStr);
2035 Log() << kDEBUG <<
Form(
"Dataset[%s] : ", datasetName) <<
" Base Directory for " <<
GetMethodName()
2036 <<
" does not exist yet--> created it" <<
Endl;
2039 Log() << kDEBUG <<
Form(
"Dataset[%s] : ", datasetName)
2040 <<
"Return from MethodBaseDir() after creating base directory " <<
Endl;
2041 return fMethodBaseDir;
2058 fWeightFile = theWeightFile;
2066 if (fWeightFile!=
"")
return fWeightFile;
2071 TString wFileDir(GetWeightFileDir());
2074 if (wFileDir.
IsNull() )
return wFileName;
2076 return ( wFileDir + (wFileDir[wFileDir.
Length()-1]==
'/' ?
"" :
"/")
2088 if (0 != fMVAPdfS) {
2089 fMVAPdfS->GetOriginalHist()->Write();
2090 fMVAPdfS->GetSmoothedHist()->Write();
2091 fMVAPdfS->GetPDFHist()->Write();
2093 if (0 != fMVAPdfB) {
2094 fMVAPdfB->GetOriginalHist()->Write();
2095 fMVAPdfB->GetSmoothedHist()->Write();
2096 fMVAPdfB->GetPDFHist()->Write();
2102 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"<WriteEvaluationHistosToFile> Unknown result: "
2104 <<
"/kMaxAnalysisType" <<
Endl;
2109 GetTransformationHandler().PlotVariables (GetEventCollection(
Types::kTesting ), BaseDir() );
2112 <<
" variable plots are not produces ! The number of variables is " << DataInfo().GetNVariables()
2132 fin.getline(buf,512);
2134 if (
line.BeginsWith(
"TMVA Release")) {
2138 std::stringstream
s(code.
Data());
2139 s >> fTMVATrainingVersion;
2140 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"MVA method was trained with TMVA Version: " << GetTrainingTMVAVersionString() <<
Endl;
2142 if (
line.BeginsWith(
"ROOT Release")) {
2146 std::stringstream
s(code.
Data());
2147 s >> fROOTTrainingVersion;
2148 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"MVA method was trained with ROOT Version: " << GetTrainingROOTVersionString() <<
Endl;
2150 if (
line.BeginsWith(
"Analysis type")) {
2154 std::stringstream
s(code.
Data());
2155 std::string analysisType;
2157 if (analysisType ==
"regression" || analysisType ==
"Regression") SetAnalysisType(
Types::kRegression );
2158 else if (analysisType ==
"classification" || analysisType ==
"Classification") SetAnalysisType(
Types::kClassification );
2159 else if (analysisType ==
"multiclass" || analysisType ==
"Multiclass") SetAnalysisType(
Types::kMulticlass );
2160 else Log() << kFATAL <<
"Analysis type " << analysisType <<
" from weight-file not known!" << std::endl;
2162 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"Method was trained for "
2182 if (mvaRes==0 || mvaRes->
GetSize()==0) {
2183 Log() << kERROR<<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"<CreateMVAPdfs> No result of classifier testing available" <<
Endl;
2190 TH1* histMVAPdfS =
new TH1D( GetMethodTypeName() +
"_tr_S", GetMethodTypeName() +
"_tr_S",
2191 fMVAPdfS->GetHistNBins( mvaRes->
GetSize() ), minVal, maxVal );
2192 TH1* histMVAPdfB =
new TH1D( GetMethodTypeName() +
"_tr_B", GetMethodTypeName() +
"_tr_B",
2193 fMVAPdfB->GetHistNBins( mvaRes->
GetSize() ), minVal, maxVal );
2197 histMVAPdfS->
Sumw2();
2198 histMVAPdfB->
Sumw2();
2203 Double_t theWeight = Data()->GetEvent(ievt)->GetWeight();
2205 if (DataInfo().IsSignal(Data()->GetEvent(ievt))) histMVAPdfS->
Fill( theVal, theWeight );
2206 else histMVAPdfB->
Fill( theVal, theWeight );
2215 histMVAPdfS->
Write();
2216 histMVAPdfB->
Write();
2219 fMVAPdfS->BuildPDF ( histMVAPdfS );
2220 fMVAPdfB->BuildPDF ( histMVAPdfB );
2221 fMVAPdfS->ValidatePDF( histMVAPdfS );
2222 fMVAPdfB->ValidatePDF( histMVAPdfB );
2224 if (DataInfo().GetNClasses() == 2) {
2225 Log() << kINFO<<
Form(
"Dataset[%s] : ",DataInfo().GetName())
2226 <<
Form(
"<CreateMVAPdfs> Separation from histogram (PDF): %1.3f (%1.3f)",
2227 GetSeparation( histMVAPdfS, histMVAPdfB ), GetSeparation( fMVAPdfS, fMVAPdfB ) )
2239 if (!fMVAPdfS || !fMVAPdfB) {
2240 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;
2243 Double_t sigFraction = DataInfo().GetTrainingSumSignalWeights() / (DataInfo().GetTrainingSumSignalWeights() + DataInfo().GetTrainingSumBackgrWeights() );
2246 return GetProba(mvaVal,sigFraction);
2254 if (!fMVAPdfS || !fMVAPdfB) {
2255 Log() << kWARNING <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"<GetProba> MVA PDFs for Signal and Background don't exist" <<
Endl;
2258 Double_t p_s = fMVAPdfS->GetVal( mvaVal );
2259 Double_t p_b = fMVAPdfB->GetVal( mvaVal );
2261 Double_t denom = p_s*ap_sig + p_b*(1 - ap_sig);
2263 return (denom > 0) ? (p_s*ap_sig) / denom : -1;
2276 Log() << kWARNING <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"<GetRarity> Required MVA PDF for Signal or Background does not exist: "
2277 <<
"select option \"CreateMVAPdfs\"" <<
Endl;
2292 Data()->SetCurrentType(
type);
2302 else if (list->
GetSize() > 2) {
2303 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"<GetEfficiency> Wrong number of arguments"
2304 <<
" in string: " << theString
2305 <<
" | required format, e.g., Efficiency:0.05, or empty string" <<
Endl;
2313 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"<GetEfficiency> Binning mismatch between signal and background histos" <<
Endl;
2321 TH1 * effhist = results->
GetHist(
"MVA_HIGHBIN_S");
2328 if (results->
DoesExist(
"MVA_EFF_S")==0) {
2331 TH1* eff_s =
new TH1D( GetTestvarName() +
"_effS", GetTestvarName() +
" (signal)", fNbinsH,
xmin,
xmax );
2332 TH1* eff_b =
new TH1D( GetTestvarName() +
"_effB", GetTestvarName() +
" (background)", fNbinsH,
xmin,
xmax );
2333 results->
Store(eff_s,
"MVA_EFF_S");
2334 results->
Store(eff_b,
"MVA_EFF_B");
2337 Int_t sign = (fCutOrientation == kPositive) ? +1 : -1;
2341 for (
UInt_t ievt=0; ievt<Data()->GetNEvents(); ievt++) {
2344 Bool_t isSignal = DataInfo().IsSignal(GetEvent(ievt));
2345 Float_t theWeight = GetEvent(ievt)->GetWeight();
2346 Float_t theVal = (*mvaRes)[ievt];
2349 TH1* theHist = isSignal ? eff_s : eff_b;
2352 if (isSignal) nevtS+=theWeight;
2356 if (sign > 0 && maxbin > fNbinsH)
continue;
2357 if (sign < 0 && maxbin < 1 )
continue;
2358 if (sign > 0 && maxbin < 1 ) maxbin = 1;
2359 if (sign < 0 && maxbin > fNbinsH) maxbin = fNbinsH;
2364 for (
Int_t ibin=maxbin+1; ibin<=fNbinsH; ibin++) theHist->
AddBinContent( ibin , theWeight );
2366 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"<GetEfficiency> Mismatch in sign" <<
Endl;
2377 TH1* eff_BvsS =
new TH1D( GetTestvarName() +
"_effBvsS", GetTestvarName() +
"", fNbins, 0, 1 );
2378 results->
Store(eff_BvsS,
"MVA_EFF_BvsS");
2383 TH1* rej_BvsS =
new TH1D( GetTestvarName() +
"_rejBvsS", GetTestvarName() +
"", fNbins, 0, 1 );
2384 results->
Store(rej_BvsS);
2386 rej_BvsS->
SetYTitle(
"Backgr rejection (1-eff)" );
2389 TH1* inveff_BvsS =
new TH1D( GetTestvarName() +
"_invBeffvsSeff",
2390 GetTestvarName(), fNbins, 0, 1 );
2391 results->
Store(inveff_BvsS);
2393 inveff_BvsS->
SetYTitle(
"Inverse backgr. eff (1/eff)" );
2399 fSplRefS =
new TSpline1(
"spline2_signal",
new TGraph( eff_s ) );
2400 fSplRefB =
new TSpline1(
"spline2_background",
new TGraph( eff_b ) );
2414 for (
Int_t bini=1; bini<=fNbins; bini++) {
2436 Double_t effS = 0., rejB, effS_ = 0., rejB_ = 0.;
2437 Int_t nbins_ = 5000;
2438 for (
Int_t bini=1; bini<=nbins_; bini++) {
2441 effS = (bini - 0.5)/
Float_t(nbins_);
2442 rejB = 1.0 - fSpleffBvsS->Eval( effS );
2445 if ((effS - rejB)*(effS_ - rejB_) < 0)
break;
2452 SetSignalReferenceCut( cut );
2457 if (0 == fSpleffBvsS) {
2463 Double_t effS = 0, effB = 0, effS_ = 0, effB_ = 0;
2464 Int_t nbins_ = 1000;
2470 for (
Int_t bini=1; bini<=nbins_; bini++) {
2473 effS = (bini - 0.5)/
Float_t(nbins_);
2474 effB = fSpleffBvsS->Eval( effS );
2475 integral += (1.0 - effB);
2489 for (
Int_t bini=1; bini<=nbins_; bini++) {
2492 effS = (bini - 0.5)/
Float_t(nbins_);
2493 effB = fSpleffBvsS->Eval( effS );
2496 if ((effB - effBref)*(effB_ - effBref) <= 0)
break;
2502 effS = 0.5*(effS + effS_);
2505 if (nevtS > 0) effSerr =
TMath::Sqrt( effS*(1.0 - effS)/nevtS );
2530 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"<GetTrainingEfficiency> Wrong number of arguments"
2531 <<
" in string: " << theString
2532 <<
" | required format, e.g., Efficiency:0.05" <<
Endl;
2545 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"<GetTrainingEfficiency> Binning mismatch between signal and background histos"
2553 TH1 * effhist = results->
GetHist(
"MVA_HIGHBIN_S");
2558 if (results->
DoesExist(
"MVA_TRAIN_S")==0) {
2564 TH1* mva_s_tr =
new TH1D( GetTestvarName() +
"_Train_S",GetTestvarName() +
"_Train_S", fNbinsMVAoutput, fXmin, sxmax );
2565 TH1* mva_b_tr =
new TH1D( GetTestvarName() +
"_Train_B",GetTestvarName() +
"_Train_B", fNbinsMVAoutput, fXmin, sxmax );
2566 results->
Store(mva_s_tr,
"MVA_TRAIN_S");
2567 results->
Store(mva_b_tr,
"MVA_TRAIN_B");
2572 TH1* mva_eff_tr_s =
new TH1D( GetTestvarName() +
"_trainingEffS", GetTestvarName() +
" (signal)",
2574 TH1* mva_eff_tr_b =
new TH1D( GetTestvarName() +
"_trainingEffB", GetTestvarName() +
" (background)",
2576 results->
Store(mva_eff_tr_s,
"MVA_TRAINEFF_S");
2577 results->
Store(mva_eff_tr_b,
"MVA_TRAINEFF_B");
2580 Int_t sign = (fCutOrientation == kPositive) ? +1 : -1;
2582 std::vector<Double_t> mvaValues = GetMvaValues(0,Data()->GetNEvents());
2583 assert( (
Long64_t) mvaValues.size() == Data()->GetNEvents());
2586 for (
Int_t ievt=0; ievt<Data()->GetNEvents(); ievt++) {
2588 Data()->SetCurrentEvent(ievt);
2589 const Event* ev = GetEvent();
2594 TH1* theEffHist = DataInfo().IsSignal(ev) ? mva_eff_tr_s : mva_eff_tr_b;
2595 TH1* theClsHist = DataInfo().IsSignal(ev) ? mva_s_tr : mva_b_tr;
2597 theClsHist->
Fill( theVal, theWeight );
2601 if (sign > 0 && maxbin > fNbinsH)
continue;
2602 if (sign < 0 && maxbin < 1 )
continue;
2603 if (sign > 0 && maxbin < 1 ) maxbin = 1;
2604 if (sign < 0 && maxbin > fNbinsH) maxbin = fNbinsH;
2606 if (sign > 0)
for (
Int_t ibin=1; ibin<=maxbin; ibin++) theEffHist->
AddBinContent( ibin , theWeight );
2607 else for (
Int_t ibin=maxbin+1; ibin<=fNbinsH; ibin++) theEffHist->
AddBinContent( ibin , theWeight );
2620 TH1* eff_bvss =
new TH1D( GetTestvarName() +
"_trainingEffBvsS", GetTestvarName() +
"", fNbins, 0, 1 );
2622 TH1* rej_bvss =
new TH1D( GetTestvarName() +
"_trainingRejBvsS", GetTestvarName() +
"", fNbins, 0, 1 );
2623 results->
Store(eff_bvss,
"EFF_BVSS_TR");
2624 results->
Store(rej_bvss,
"REJ_BVSS_TR");
2630 if (fSplTrainRefS)
delete fSplTrainRefS;
2631 if (fSplTrainRefB)
delete fSplTrainRefB;
2632 fSplTrainRefS =
new TSpline1(
"spline2_signal",
new TGraph( mva_eff_tr_s ) );
2633 fSplTrainRefB =
new TSpline1(
"spline2_background",
new TGraph( mva_eff_tr_b ) );
2646 fEffS = results->
GetHist(
"MVA_TRAINEFF_S");
2647 for (
Int_t bini=1; bini<=fNbins; bini++) {
2665 fSplTrainEffBvsS =
new TSpline1(
"effBvsS",
new TGraph( eff_bvss ) );
2669 if (0 == fSplTrainEffBvsS)
return 0.0;
2672 Double_t effS = 0., effB, effS_ = 0., effB_ = 0.;
2673 Int_t nbins_ = 1000;
2674 for (
Int_t bini=1; bini<=nbins_; bini++) {
2677 effS = (bini - 0.5)/
Float_t(nbins_);
2678 effB = fSplTrainEffBvsS->Eval( effS );
2681 if ((effB - effBref)*(effB_ - effBref) <= 0)
break;
2686 return 0.5*(effS + effS_);
2695 if (!resMulticlass)
Log() << kFATAL<<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"unable to create pointer in GetMulticlassEfficiency, exiting."<<
Endl;
2707 if (!resMulticlass)
Log() << kFATAL<<
"unable to create pointer in GetMulticlassTrainingEfficiency, exiting."<<
Endl;
2709 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"Determine optimal multiclass cuts for training data..." <<
Endl;
2710 for (
UInt_t icls = 0; icls<DataInfo().GetNClasses(); ++icls) {
2741 Log() << kFATAL <<
"Cannot get confusion matrix for non-multiclass analysis." << std::endl;
2745 Data()->SetCurrentType(
type);
2749 if (resMulticlass ==
nullptr) {
2750 Log() << kFATAL <<
Form(
"Dataset[%s] : ", DataInfo().GetName())
2751 <<
"unable to create pointer in GetMulticlassEfficiency, exiting." <<
Endl;
2768 return (rms > 0) ?
TMath::Abs(fMeanS - fMeanB)/rms : 0;
2792 if ((!pdfS && pdfB) || (pdfS && !pdfB))
2793 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"<GetSeparation> Mismatch in pdfs" <<
Endl;
2794 if (!pdfS) pdfS = fSplS;
2795 if (!pdfB) pdfB = fSplB;
2797 if (!fSplS || !fSplB) {
2798 Log()<<kDEBUG<<
Form(
"[%s] : ",DataInfo().GetName())<<
"could not calculate the separation, distributions"
2799 <<
" fSplS or fSplB are not yet filled" <<
Endl;
2814 if ((!histS && histB) || (histS && !histB))
2815 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"<GetROCIntegral(TH1D*, TH1D*)> Mismatch in hists" <<
Endl;
2817 if (histS==0 || histB==0)
return 0.;
2830 for (
UInt_t i=0; i<nsteps; i++) {
2836 return integral*step;
2848 if ((!pdfS && pdfB) || (pdfS && !pdfB))
2849 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"<GetSeparation> Mismatch in pdfs" <<
Endl;
2850 if (!pdfS) pdfS = fSplS;
2851 if (!pdfB) pdfB = fSplB;
2853 if (pdfS==0 || pdfB==0)
return 0.;
2862 for (
UInt_t i=0; i<nsteps; i++) {
2866 return integral*step;
2876 Double_t& max_significance_value )
const
2881 Double_t effS(0),effB(0),significance(0);
2882 TH1D *temp_histogram =
new TH1D(
"temp",
"temp", fNbinsH, fXmin, fXmax );
2884 if (SignalEvents <= 0 || BackgroundEvents <= 0) {
2885 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"<GetMaximumSignificance> "
2886 <<
"Number of signal or background events is <= 0 ==> abort"
2890 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"Using ratio SignalEvents/BackgroundEvents = "
2891 << SignalEvents/BackgroundEvents <<
Endl;
2896 if ( (eff_s==0) || (eff_b==0) ) {
2897 Log() << kWARNING <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"Efficiency histograms empty !" <<
Endl;
2898 Log() << kWARNING <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"no maximum cut found, return 0" <<
Endl;
2902 for (
Int_t bin=1; bin<=fNbinsH; bin++) {
2907 significance =
sqrt(SignalEvents)*( effS )/
sqrt( effS + ( BackgroundEvents / SignalEvents) * effB );
2917 delete temp_histogram;
2919 Log() << kINFO <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"Optimal cut at : " << max_significance <<
Endl;
2920 Log() << kINFO<<
Form(
"Dataset[%s] : ",DataInfo().GetName()) <<
"Maximum significance: " << max_significance_value <<
Endl;
2922 return max_significance;
2936 Data()->SetCurrentType(treeType);
2938 Long64_t entries = Data()->GetNEvents();
2942 Log() << kFATAL <<
Form(
"Dataset[%s] : ",DataInfo().GetName())<<
"<CalculateEstimator> Wrong tree type: " << treeType <<
Endl;
2945 UInt_t varIndex = DataInfo().FindVarIndex( theVarName );
2961 for (
Int_t ievt = 0; ievt < entries; ievt++) {
2963 const Event* ev = GetEvent(ievt);
2968 if (DataInfo().IsSignal(ev)) {
2970 meanS += weight*theVar;
2971 rmsS += weight*theVar*theVar;
2975 meanB += weight*theVar;
2976 rmsB += weight*theVar*theVar;
2984 meanS = meanS/sumwS;
2985 meanB = meanB/sumwB;
2989 Data()->SetCurrentType(previousTreeType);
2999 if (theClassFileName ==
"")
3000 classFileName = GetWeightFileDir() +
"/" + GetJobName() +
"_" +
GetMethodName() +
".class.C";
3002 classFileName = theClassFileName;
3006 TString tfname( classFileName );
3008 <<
"Creating standalone class: "
3011 std::ofstream fout( classFileName );
3013 Log() << kFATAL <<
"<MakeClass> Unable to open file: " << classFileName <<
Endl;
3018 fout <<
"// Class: " << className << std::endl;
3019 fout <<
"// Automatically generated by MethodBase::MakeClass" << std::endl <<
"//" << std::endl;
3023 fout <<
"/* configuration options =====================================================" << std::endl << std::endl;
3024 WriteStateToStream( fout );
3026 fout <<
"============================================================================ */" << std::endl;
3029 fout <<
"" << std::endl;
3030 fout <<
"#include <array>" << std::endl;
3031 fout <<
"#include <vector>" << std::endl;
3032 fout <<
"#include <cmath>" << std::endl;
3033 fout <<
"#include <string>" << std::endl;
3034 fout <<
"#include <iostream>" << std::endl;
3035 fout <<
"" << std::endl;
3038 this->MakeClassSpecificHeader( fout, className );
3040 fout <<
"#ifndef IClassifierReader__def" << std::endl;
3041 fout <<
"#define IClassifierReader__def" << std::endl;
3043 fout <<
"class IClassifierReader {" << std::endl;
3045 fout <<
" public:" << std::endl;
3047 fout <<
" // constructor" << std::endl;
3048 fout <<
" IClassifierReader() : fStatusIsClean( true ) {}" << std::endl;
3049 fout <<
" virtual ~IClassifierReader() {}" << std::endl;
3051 fout <<
" // return classifier response" << std::endl;
3053 fout <<
" virtual std::vector<double> GetMulticlassValues( const std::vector<double>& inputValues ) const = 0;" << std::endl;
3055 fout <<
" virtual double GetMvaValue( const std::vector<double>& inputValues ) const = 0;" << std::endl;
3058 fout <<
" // returns classifier status" << std::endl;
3059 fout <<
" bool IsStatusClean() const { return fStatusIsClean; }" << std::endl;
3061 fout <<
" protected:" << std::endl;
3063 fout <<
" bool fStatusIsClean;" << std::endl;
3064 fout <<
"};" << std::endl;
3066 fout <<
"#endif" << std::endl;
3068 fout <<
"class " << className <<
" : public IClassifierReader {" << std::endl;
3070 fout <<
" public:" << std::endl;
3072 fout <<
" // constructor" << std::endl;
3073 fout <<
" " << className <<
"( std::vector<std::string>& theInputVars )" << std::endl;
3074 fout <<
" : IClassifierReader()," << std::endl;
3075 fout <<
" fClassName( \"" << className <<
"\" )," << std::endl;
3076 fout <<
" fNvars( " << GetNvar() <<
" )" << std::endl;
3077 fout <<
" {" << std::endl;
3078 fout <<
" // the training input variables" << std::endl;
3079 fout <<
" const char* inputVars[] = { ";
3080 for (
UInt_t ivar=0; ivar<GetNvar(); ivar++) {
3081 fout <<
"\"" << GetOriginalVarName(ivar) <<
"\"";
3082 if (ivar<GetNvar()-1) fout <<
", ";
3084 fout <<
" };" << std::endl;
3086 fout <<
" // sanity checks" << std::endl;
3087 fout <<
" if (theInputVars.size() <= 0) {" << std::endl;
3088 fout <<
" std::cout << \"Problem in class \\\"\" << fClassName << \"\\\": empty input vector\" << std::endl;" << std::endl;
3089 fout <<
" fStatusIsClean = false;" << std::endl;
3090 fout <<
" }" << std::endl;
3092 fout <<
" if (theInputVars.size() != fNvars) {" << std::endl;
3093 fout <<
" std::cout << \"Problem in class \\\"\" << fClassName << \"\\\": mismatch in number of input values: \"" << std::endl;
3094 fout <<
" << theInputVars.size() << \" != \" << fNvars << std::endl;" << std::endl;
3095 fout <<
" fStatusIsClean = false;" << std::endl;
3096 fout <<
" }" << std::endl;
3098 fout <<
" // validate input variables" << std::endl;
3099 fout <<
" for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) {" << std::endl;
3100 fout <<
" if (theInputVars[ivar] != inputVars[ivar]) {" << std::endl;
3101 fout <<
" std::cout << \"Problem in class \\\"\" << fClassName << \"\\\": mismatch in input variable names\" << std::endl" << std::endl;
3102 fout <<
" << \" for variable [\" << ivar << \"]: \" << theInputVars[ivar].c_str() << \" != \" << inputVars[ivar] << std::endl;" << std::endl;
3103 fout <<
" fStatusIsClean = false;" << std::endl;
3104 fout <<
" }" << std::endl;
3105 fout <<
" }" << std::endl;
3107 fout <<
" // initialize min and max vectors (for normalisation)" << std::endl;
3108 for (
UInt_t ivar = 0; ivar < GetNvar(); ivar++) {
3109 fout <<
" fVmin[" << ivar <<
"] = " << std::setprecision(15) << GetXmin( ivar ) <<
";" << std::endl;
3110 fout <<
" fVmax[" << ivar <<
"] = " << std::setprecision(15) << GetXmax( ivar ) <<
";" << std::endl;
3113 fout <<
" // initialize input variable types" << std::endl;
3114 for (
UInt_t ivar=0; ivar<GetNvar(); ivar++) {
3115 fout <<
" fType[" << ivar <<
"] = \'" << DataInfo().GetVariableInfo(ivar).GetVarType() <<
"\';" << std::endl;
3118 fout <<
" // initialize constants" << std::endl;
3119 fout <<
" Initialize();" << std::endl;
3121 if (GetTransformationHandler().GetTransformationList().GetSize() != 0) {
3122 fout <<
" // initialize transformation" << std::endl;
3123 fout <<
" InitTransform();" << std::endl;
3125 fout <<
" }" << std::endl;
3127 fout <<
" // destructor" << std::endl;
3128 fout <<
" virtual ~" << className <<
"() {" << std::endl;
3129 fout <<
" Clear(); // method-specific" << std::endl;
3130 fout <<
" }" << std::endl;
3132 fout <<
" // the classifier response" << std::endl;
3133 fout <<
" // \"inputValues\" is a vector of input values in the same order as the" << std::endl;
3134 fout <<
" // variables given to the constructor" << std::endl;
3136 fout <<
" std::vector<double> GetMulticlassValues( const std::vector<double>& inputValues ) const override;" << std::endl;
3138 fout <<
" double GetMvaValue( const std::vector<double>& inputValues ) const override;" << std::endl;
3141 fout <<
" private:" << std::endl;
3143 fout <<
" // method-specific destructor" << std::endl;
3144 fout <<
" void Clear();" << std::endl;
3146 if (GetTransformationHandler().GetTransformationList().GetSize()!=0) {
3147 fout <<
" // input variable transformation" << std::endl;
3148 GetTransformationHandler().MakeFunction(fout, className,1);
3149 fout <<
" void InitTransform();" << std::endl;
3150 fout <<
" void Transform( std::vector<double> & iv, int sigOrBgd ) const;" << std::endl;
3153 fout <<
" // common member variables" << std::endl;
3154 fout <<
" const char* fClassName;" << std::endl;
3156 fout <<
" const size_t fNvars;" << std::endl;
3157 fout <<
" size_t GetNvar() const { return fNvars; }" << std::endl;
3158 fout <<
" char GetType( int ivar ) const { return fType[ivar]; }" << std::endl;
3160 fout <<
" // normalisation of input variables" << std::endl;
3161 fout <<
" double fVmin[" << GetNvar() <<
"];" << std::endl;
3162 fout <<
" double fVmax[" << GetNvar() <<
"];" << std::endl;
3163 fout <<
" double NormVariable( double x, double xmin, double xmax ) const {" << std::endl;
3164 fout <<
" // normalise to output range: [-1, 1]" << std::endl;
3165 fout <<
" return 2*(x - xmin)/(xmax - xmin) - 1.0;" << std::endl;
3166 fout <<
" }" << std::endl;
3168 fout <<
" // type of input variable: 'F' or 'I'" << std::endl;
3169 fout <<
" char fType[" << GetNvar() <<
"];" << std::endl;
3171 fout <<
" // initialize internal variables" << std::endl;
3172 fout <<
" void Initialize();" << std::endl;
3174 fout <<
" std::vector<double> GetMulticlassValues__( const std::vector<double>& inputValues ) const;" << std::endl;
3176 fout <<
" double GetMvaValue__( const std::vector<double>& inputValues ) const;" << std::endl;
3178 fout <<
"" << std::endl;
3179 fout <<
" // private members (method specific)" << std::endl;
3182 MakeClassSpecific( fout, className );
3185 fout <<
"inline std::vector<double> " << className <<
"::GetMulticlassValues( const std::vector<double>& inputValues ) const" << std::endl;
3187 fout <<
"inline double " << className <<
"::GetMvaValue( const std::vector<double>& inputValues ) const" << std::endl;
3189 fout <<
"{" << std::endl;
3190 fout <<
" // classifier response value" << std::endl;
3192 fout <<
" std::vector<double> retval;" << std::endl;
3194 fout <<
" double retval = 0;" << std::endl;
3197 fout <<
" // classifier response, sanity check first" << std::endl;
3198 fout <<
" if (!IsStatusClean()) {" << std::endl;
3199 fout <<
" std::cout << \"Problem in class \\\"\" << fClassName << \"\\\": cannot return classifier response\"" << std::endl;
3200 fout <<
" << \" because status is dirty\" << std::endl;" << std::endl;
3201 fout <<
" }" << std::endl;
3202 fout <<
" else {" << std::endl;
3203 if (IsNormalised()) {
3204 fout <<
" // normalise variables" << std::endl;
3205 fout <<
" std::vector<double> iV;" << std::endl;
3206 fout <<
" iV.reserve(inputValues.size());" << std::endl;
3207 fout <<
" int ivar = 0;" << std::endl;
3208 fout <<
" for (std::vector<double>::const_iterator varIt = inputValues.begin();" << std::endl;
3209 fout <<
" varIt != inputValues.end(); varIt++, ivar++) {" << std::endl;
3210 fout <<
" iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));" << std::endl;
3211 fout <<
" }" << std::endl;
3212 if (GetTransformationHandler().GetTransformationList().GetSize() != 0 && GetMethodType() !=
Types::kLikelihood &&
3214 fout <<
" Transform( iV, -1 );" << std::endl;
3218 fout <<
" retval = GetMulticlassValues__( iV );" << std::endl;
3220 fout <<
" retval = GetMvaValue__( iV );" << std::endl;
3223 if (GetTransformationHandler().GetTransformationList().GetSize() != 0 && GetMethodType() !=
Types::kLikelihood &&
3225 fout <<
" std::vector<double> iV(inputValues);" << std::endl;
3226 fout <<
" Transform( iV, -1 );" << std::endl;
3228 fout <<
" retval = GetMulticlassValues__( iV );" << std::endl;
3230 fout <<
" retval = GetMvaValue__( iV );" << std::endl;
3234 fout <<
" retval = GetMulticlassValues__( inputValues );" << std::endl;
3236 fout <<
" retval = GetMvaValue__( inputValues );" << std::endl;
3240 fout <<
" }" << std::endl;
3242 fout <<
" return retval;" << std::endl;
3243 fout <<
"}" << std::endl;
3246 if (GetTransformationHandler().GetTransformationList().GetSize()!=0)
3247 GetTransformationHandler().MakeFunction(fout, className,2);
3259 std::streambuf* cout_sbuf = std::cout.rdbuf();
3260 std::ofstream* o = 0;
3261 if (
gConfig().WriteOptionsReference()) {
3262 Log() << kINFO <<
"Print Help message for class " << GetName() <<
" into file: " << GetReferenceFile() <<
Endl;
3263 o =
new std::ofstream( GetReferenceFile(), std::ios::app );
3265 Log() << kFATAL <<
"<PrintHelpMessage> Unable to append to output file: " << GetReferenceFile() <<
Endl;
3267 std::cout.rdbuf( o->rdbuf() );
3274 <<
"================================================================"
3278 <<
"H e l p f o r M V A m e t h o d [ " << GetName() <<
" ] :"
3283 Log() <<
"Help for MVA method [ " << GetName() <<
" ] :" <<
Endl;
3291 Log() <<
"<Suppress this message by specifying \"!H\" in the booking option>" <<
Endl;
3293 <<
"================================================================"
3300 Log() <<
"# End of Message___" <<
Endl;
3303 std::cout.rdbuf( cout_sbuf );
3318 retval = fSplRefS->Eval( theCut );
3320 else retval = fEffS->GetBinContent( fEffS->FindBin( theCut ) );
3329 if (theCut-fXmin < eps) retval = (GetCutOrientation() == kPositive) ? 1.0 : 0.0;
3330 else if (fXmax-theCut < eps) retval = (GetCutOrientation() == kPositive) ? 0.0 : 1.0;
3343 if (GetTransformationHandler().GetTransformationList().GetEntries() <= 0) {
3344 return (Data()->GetEventCollection(
type));
3351 if (fEventCollections.at(idx) == 0) {
3352 fEventCollections.at(idx) = &(Data()->GetEventCollection(
type));
3353 fEventCollections.at(idx) = GetTransformationHandler().CalcTransformations(*(fEventCollections.at(idx)),
kTRUE);
3355 return *(fEventCollections.at(idx));
3363 UInt_t a = GetTrainingTMVAVersionCode() & 0xff0000;
a>>=16;
3364 UInt_t b = GetTrainingTMVAVersionCode() & 0x00ff00;
b>>=8;
3365 UInt_t c = GetTrainingTMVAVersionCode() & 0x0000ff;
3375 UInt_t a = GetTrainingROOTVersionCode() & 0xff0000;
a>>=16;
3376 UInt_t b = GetTrainingROOTVersionCode() & 0x00ff00;
b>>=8;
3377 UInt_t c = GetTrainingROOTVersionCode() & 0x0000ff;
3388 if (mvaRes != NULL) {
3391 TH1D *mva_s_tr =
dynamic_cast<TH1D*
> (mvaRes->
GetHist(
"MVA_TRAIN_S"));
3392 TH1D *mva_b_tr =
dynamic_cast<TH1D*
> (mvaRes->
GetHist(
"MVA_TRAIN_B"));
3394 if ( !mva_s || !mva_b || !mva_s_tr || !mva_b_tr)
return -1;
3396 if (SorB ==
's' || SorB ==
'S')
const Bool_t Use_Splines_for_Eff_
const Int_t NBIN_HIST_HIGH
#define ROOT_VERSION_CODE
static RooMathCoreReg dummy
TMatrixT< Double_t > TMatrixD
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
#define TMVA_VERSION_CODE
Class to manage histogram axis.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write all objects in this collection.
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
const char * AsString() const
Return the date & time as a string (ctime() format).
TObject * Get(const char *namecycle) override
Return pointer to object identified by namecycle.
Describe directory structure in memory.
virtual TDirectory * GetDirectory(const char *namecycle, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory using apath.
virtual TDirectory * mkdir(const char *name, const char *title="", Bool_t returnExistingDirectory=kFALSE)
Create a sub-directory "a" or a hierarchy of sub-directories "a/b/c/...".
virtual Bool_t cd(const char *path=nullptr)
Change current directory to "this" directory.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
void Close(Option_t *option="") override
Close a file.
A TGraph is an object made of two arrays X and Y with npoints each.
1-D histogram with a double per channel (see TH1 documentation)}
1-D histogram with a float per channel (see TH1 documentation)}
virtual Double_t GetBinCenter(Int_t bin) const
Return bin center for 1D histogram.
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 void AddBinContent(Int_t bin)
Increment bin content by 1.
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.
virtual void SetXTitle(const char *title)
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
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...
virtual Int_t GetNbinsX() const
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
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...
virtual Int_t GetMaximumBin() const
Return location of bin with maximum value in the range.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
virtual void SetYTitle(const char *title)
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
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 Double_t KolmogorovTest(const TH1 *h2, Option_t *option="") const
Statistical test of compatibility in shape between this histogram and h2, using Kolmogorov test.
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
static Bool_t AddDirectoryStatus()
Static function: cannot be inlined on Windows/NT.
2-D histogram with a float per channel (see TH1 documentation)}
Int_t Fill(Double_t)
Invalid Fill method.
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Class that contains all the information of a class.
TString fWeightFileExtension
Int_t fMaxNumOfAllowedVariables
VariablePlotting & GetVariablePlotting()
class TMVA::Config::VariablePlotting fVariablePlotting
Class that contains all the data information.
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not.
static void SetIsTraining(Bool_t)
when this static function is called, it sets the flag whether events with negative event weight shoul...
Float_t GetTarget(UInt_t itgt) const
static void SetIgnoreNegWeightsInTraining(Bool_t)
when this static function is called, it sets the flag whether events with negative event weight shoul...
Interface for all concrete MVA method implementations.
void Init(std::vector< TString > &graphTitles)
This function gets some title and it creates a TGraph for every title.
IPythonInteractive()
standard constructor
~IPythonInteractive()
standard destructor
void ClearGraphs()
This function sets the point number to 0 for all graphs.
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 base Class for all MVA method.
TDirectory * MethodBaseDir() const
returns the ROOT directory where all instances of the corresponding MVA method are stored
virtual Double_t GetKSTrainingVsTest(Char_t SorB, TString opt="X")
MethodBase(const TString &jobName, Types::EMVA methodType, const TString &methodTitle, DataSetInfo &dsi, const TString &theOption="")
standard constructor
virtual Double_t GetSeparation(TH1 *, TH1 *) const
compute "separation" defined as
void ReadClassesFromXML(void *clsnode)
read number of classes from XML
void SetWeightFileDir(TString fileDir)
set directory of weight file
void WriteStateToXML(void *parent) const
general method used in writing the header of the weight files where the used variables,...
void DeclareBaseOptions()
define the options (their key words) that can be set in the option string here the options valid for ...
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 void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility they are hence without any...
virtual Double_t GetSignificance() const
compute significance of mean difference
virtual Double_t GetProba(const Event *ev)
const char * GetName() const
virtual TMatrixD GetMulticlassConfusionMatrix(Double_t effB, Types::ETreeType type)
Construct a confusion matrix for a multiclass classifier.
void PrintHelpMessage() const
prints out method-specific help method
virtual void WriteEvaluationHistosToFile(Types::ETreeType treetype)
writes all MVA evaluation histograms to file
virtual void TestMulticlass()
test multiclass classification
const std::vector< TMVA::Event * > & GetEventCollection(Types::ETreeType type)
returns the event collection (i.e.
void SetupMethod()
setup of methods
TDirectory * BaseDir() const
returns the ROOT directory where info/histograms etc of the corresponding MVA method instance are sto...
virtual std::vector< Float_t > GetMulticlassEfficiency(std::vector< std::vector< Float_t > > &purity)
void AddInfoItem(void *gi, const TString &name, const TString &value) const
xml writing
virtual void AddClassifierOutputProb(Types::ETreeType type)
prepare tree branch with the method's discriminating variable
virtual Double_t GetEfficiency(const TString &, Types::ETreeType, Double_t &err)
fill background efficiency (resp.
TString GetTrainingTMVAVersionString() const
calculates the TMVA version string from the training version code on the fly
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...
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 ...
void ProcessSetup()
process all options the "CheckForUnusedOptions" is done in an independent call, since it may be overr...
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
virtual Bool_t IsSignalLike()
uses a pre-set cut on the MVA output (SetSignalReferenceCut and SetSignalReferenceCutOrientation) for...
virtual ~MethodBase()
destructor
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 ...
virtual Double_t GetTrainingEfficiency(const TString &)
void SetWeightFileName(TString)
set the weight file name (depreciated)
virtual void MakeClass(const TString &classFileName=TString("")) const
create reader class for method (classification only at present)
TString GetWeightFileName() const
retrieve weight file name
virtual void TestClassification()
initialization
void AddOutput(Types::ETreeType type, Types::EAnalysisType analysisType)
virtual void WriteMonitoringHistosToFile() const
write special monitoring histograms to file dummy implementation here --------------—
virtual void AddRegressionOutput(Types::ETreeType type)
prepare tree branch with the method's discriminating variable
void InitBase()
default initialization called by all constructors
virtual void GetRegressionDeviation(UInt_t tgtNum, Types::ETreeType type, Double_t &stddev, Double_t &stddev90Percent) const
void ReadStateFromXMLString(const char *xmlstr)
for reading from memory
void CreateMVAPdfs()
Create PDFs of the MVA output variables.
TString GetTrainingROOTVersionString() const
calculates the ROOT version string from the training version code on the fly
virtual Double_t GetValueForRoot(Double_t)
returns efficiency as function of cut
void ReadStateFromFile()
Function to write options and weights to file.
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 ReadVarsFromStream(std::istream &istr)
Read the variables (name, min, max) for a given data transformation method from the stream.
void ReadSpectatorsFromXML(void *specnode)
read spectator info from XML
virtual Double_t GetMvaValue(Double_t *errLower=0, Double_t *errUpper=0)=0
void SetTestvarName(const TString &v="")
void ReadVariablesFromXML(void *varnode)
read variable info from XML
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.
virtual std::vector< Float_t > GetMulticlassTrainingEfficiency(std::vector< std::vector< Float_t > > &purity)
void WriteStateToStream(std::ostream &tf) const
general method used in writing the header of the weight files where the used variables,...
virtual Double_t GetRarity(Double_t mvaVal, Types::ESBType reftype=Types::kBackground) const
compute rarity:
virtual void SetTuneParameters(std::map< TString, Double_t > tuneParameters)
set the tuning parameters according to the argument This is just a dummy .
void ReadStateFromStream(std::istream &tf)
read the header from the weight files of the different MVA methods
void AddVarsXMLTo(void *parent) const
write variable info to XML
void AddTargetsXMLTo(void *parent) const
write target info to XML
void ReadTargetsFromXML(void *tarnode)
read target info from XML
void ProcessBaseOptions()
the option string is decoded, for available options see "DeclareOptions"
void ReadStateFromXML(void *parent)
void NoErrorCalc(Double_t *const err, Double_t *const errUpper)
void WriteStateToFile() const
write options and weights to file note that each one text file for the main configuration information...
void AddClassesXMLTo(void *parent) const
write class info to XML
virtual void AddClassifierOutput(Types::ETreeType type)
prepare tree branch with the method's discriminating variable
void AddSpectatorsXMLTo(void *parent) const
write spectator info to XML
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
virtual void AddMulticlassOutput(Types::ETreeType type)
prepare tree branch with the method's discriminating variable
virtual void CheckSetup()
check may be overridden by derived class (sometimes, eg, fitters are used which can only be implement...
void SetSource(const std::string &source)
PDF wrapper for histograms; uses user-defined spline interpolation.
Double_t GetVal(Double_t x) const
returns value PDF(x)
Double_t GetIntegral(Double_t xmin, Double_t xmax)
computes PDF integral within given ranges
Class that is the base-class for a vector of result.
void Resize(Int_t entries)
std::vector< Bool_t > * GetValueVectorTypes()
void SetValue(Float_t value, Int_t ievt)
set MVA response
std::vector< Float_t > * GetValueVector()
Class which takes the results of a multiclass classification.
TMatrixD GetConfusionMatrix(Double_t effB)
Returns a confusion matrix where each class is pitted against each other.
Float_t GetAchievablePur(UInt_t cls)
std::vector< Double_t > GetBestMultiClassCuts(UInt_t targetClass)
calculate the best working point (optimal cut values) for the multiclass classifier
void CreateMulticlassHistos(TString prefix, Int_t nbins, Int_t nbins_high)
this function fills the mva response histos for multiclass classification
Float_t GetAchievableEff(UInt_t cls)
void CreateMulticlassPerformanceHistos(TString prefix)
Create performance graphs for this classifier a multiclass setting.
Class that is the base-class for a vector of result.
Class that is the base-class for a vector of result.
Bool_t DoesExist(const TString &alias) const
Returns true if there is an object stored in the result for a given alias, false otherwise.
TH1 * GetHist(const TString &alias) const
TList * GetStorage() const
void Store(TObject *obj, const char *alias=0)
Root finding using Brents algorithm (translated from CERNLIB function RZERO)
Double_t Root(Double_t refValue)
Root finding using Brents algorithm; taken from CERNLIB function RZERO.
Linear interpolation of TGraph.
Timing information for training and evaluation of MVA methods.
Double_t ElapsedSeconds(void)
computes elapsed tim in seconds
TString GetElapsedTime(Bool_t Scientific=kTRUE)
returns pretty string with elapsed time
void DrawProgressBar(Int_t, const TString &comment="")
draws progress bar in color or B&W caution:
Singleton class for Global types used by TMVA.
Class for type info of MVA input variable.
void ReadFromXML(void *varnode)
read VariableInfo from stream
const TString & GetExpression() const
void ReadFromStream(std::istream &istr)
read VariableInfo from stream
void AddToXML(void *varnode)
write class to XML
void SetExternalLink(void *p)
void * GetExternalLink() const
A TMultiGraph is a collection of TGraph (or derived) objects.
virtual const char * GetName() const
Returns name of object.
Collectable string class.
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
void ToLower()
Change string to lower-case.
Int_t Atoi() const
Return integer value of string.
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
const char * Data() const
TString & ReplaceAll(const TString &s1, const TString &s2)
Ssiz_t Last(char c) const
Find last occurrence of a character c.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
virtual const char * GetBuildNode() const
Return the build node name.
virtual int mkdir(const char *name, Bool_t recursive=kFALSE)
Make a file system directory.
virtual const char * WorkingDirectory()
Return working directory.
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
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...
void FreeDoc(XMLDocPointer_t xmldoc)
frees allocated document data and deletes document itself
XMLNodePointer_t DocGetRootElement(XMLDocPointer_t xmldoc)
returns root node of document
XMLDocPointer_t NewDoc(const char *version="1.0")
creates new xml document with provided version
XMLDocPointer_t ParseFile(const char *filename, Int_t maxbuf=100000)
Parses content of file and tries to produce xml structures.
XMLDocPointer_t ParseString(const char *xmlstring)
parses content of string and tries to produce xml structures
void DocSetRootElement(XMLDocPointer_t xmldoc, XMLNodePointer_t xmlnode)
set main (root) node for document
void Init(TClassEdit::TInterpreterLookupHelper *helper)
static constexpr double s
static constexpr double m2
void GetMethodName(TString &name, TKey *mkey)
void CreateVariableTransforms(const TString &trafoDefinition, TMVA::DataSetInfo &dataInfo, TMVA::TransformationHandler &transformationHandler, TMVA::MsgLogger &log)
MsgLogger & Endl(MsgLogger &ml)
Short_t Max(Short_t a, Short_t b)
Double_t Sqrt(Double_t x)
Short_t Min(Short_t a, Short_t b)