36void TMVAClassificationCategoryApplication()
40 std::map<std::string,int> Use;
42 Use[
"LikelihoodCat"] = 1;
46 std::cout << std::endl
47 <<
"==> Start TMVAClassificationCategoryApplication" << std::endl;
55 Float_t var1, var2, var3, var4, eta;
65 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) {
67 TString methodName = it->first +
" method";
68 TString weightfile =
"dataset/weights/TMVAClassificationCategory_" +
TString(it->first) +
".weights.xml";
69 reader->
BookMVA( methodName, weightfile );
75 std::map<std::string,TH1*> hist;
76 hist[
"LikelihoodCat"] =
new TH1F(
"MVA_LikelihoodCat",
"MVA_LikelihoodCat", nbin, -1, 0.9999 );
77 hist[
"FisherCat"] =
new TH1F(
"MVA_FisherCat",
"MVA_FisherCat", nbin, -4, 4 );
85 if (
gSystem->AccessPathName( fname +
"toy_sigbkg_categ_offset.root" )) {
86 fname =
gROOT->GetTutorialDir() +
"/machine_learning/data/";
88 if (UseOffsetMethod) fname +=
"toy_sigbkg_categ_offset.root";
89 else fname +=
"toy_sigbkg_categ_varoff.root";
90 std::cout <<
"--- TMVAClassificationApp : Accessing " << fname <<
"!" << std::endl;
93 std::cout <<
"ERROR: could not open data file: " << fname << std::endl;
105 std::cout <<
"--- Use signal sample for evaluation" << std::endl;
113 std::cout <<
"--- Processing: " << theTree->
GetEntries() <<
" events" << std::endl;
118 if (ievt%1000 == 0) std::cout <<
"--- ... Processing event: " << ievt << std::endl;
124 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) {
125 if (!it->second)
continue;
126 TString methodName = it->first +
" method";
127 hist[it->first]->Fill( reader->
EvaluateMVA( methodName ) );
132 std::cout <<
"--- End of event loop: "; sw.
Print();
136 TFile *target =
new TFile(
"TMVApp.root",
"RECREATE" );
137 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++)
138 if (it->second) hist[it->first]->Write();
141 std::cout <<
"--- Created root file: \"TMVApp.root\" containing the MVA output histograms" << std::endl;
144 std::cout <<
"==> TMVAClassificationApplication is done!" << std::endl << std::endl;
147int main(
int argc,
char** argv )
149 TMVAClassificationCategoryApplication();
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
long long Long64_t
Portable signed long integer 8 bytes.
float Float_t
Float 4 bytes (float).
TObject * Get(const char *namecycle) override
Return pointer to object identified by namecycle.
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
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.
1-D histogram with a float per channel (see TH1 documentation)
The Reader class serves to use the MVAs in a specific analysis context.
Double_t EvaluateMVA(const std::vector< Float_t > &, const TString &methodTag, Double_t aux=0)
Evaluate a std::vector<float> of input data for a given method The parameter aux is obligatory for th...
IMethod * BookMVA(const TString &methodTag, const TString &weightfile)
read method name from weight file
void AddSpectator(const TString &expression, Float_t *)
Add a float spectator or expression to the reader.
void AddVariable(const TString &expression, Float_t *)
Add a float variable or expression to the reader.
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
void Stop()
Stop the stopwatch.
void Print(Option_t *option="") const override
Print the real and cpu time passed between the start and stop events.
A TTree represents a columnar dataset.
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr, TClass *realClass, EDataType datatype, bool isptr, bool suppressMissingBranchError)
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
Read all branches of entry and return total number of bytes read.
virtual Long64_t GetEntries() const