40 #include "filval/filval.hpp" 41 #include "filval_root/filval_root.hpp" 47 #define W_MASS 80.385 // GeV/c^2 48 #define Z_MASS 91.188 // GeV/c^2 49 #define T_MASS 172.44 // GeV/c^2 55 void enable_branches(MiniTreeDataSet& mt){
56 mt.track_branch<
int>(
"nLepGood");
57 mt.track_branch<
int>(
"nJet");
58 mt.track_branch<
int>(
"nGenPart");
60 mt.track_branch<
int>(
"nBJetLoose40");
61 mt.track_branch<
int>(
"nBJetMedium40");
62 mt.track_branch<
int>(
"nBJetTight40");
64 #define MVA_DTYPES int, int, int, int, int 65 void declare_values(MiniTreeDataSet& mt){
67 auto event_number = mt.get_current_event_number();
68 auto is_training = fv::apply(fv::GenFunction::register_function<
bool(
int)>(
"is_odd",
71 }))), fv::tuple(event_number));
73 auto is_signal = fv::bound(fv::GenFunction::register_function<
bool()>(
"is_signal",
75 const std::string& label = mt->get_current_event_label();
76 return label ==
"signal";
79 auto weight = fv::constant<double>(
"1", 1);
81 auto mva_data = fv::root::mva_data<MVA_DTYPES>(is_training, is_signal, weight,
82 {
"nJet", lookup<int>(
"nJet")},
83 {
"nBJetLoose40", lookup<int>(
"nBJetLoose40")},
84 {
"nBJetMedium40", lookup<int>(
"nBJetMedium40")},
85 {
"nBJetTight40", lookup<int>(
"nBJetTight40")},
86 {
"nLepGood", lookup<int>(
"nLepGood")}
88 GenValue::alias(
"mva_data", mva_data);
92 void declare_containers(MiniTreeDataSet& mt){
94 auto mva_data = (MVAData<MVA_DTYPES>*)lookup<MVAData<MVA_DTYPES>::type>(
"mva_data");
95 auto mva = mt.register_container<MVA<MVA_DTYPES>>(
"my_mva", mva_data);
96 mva->add_method(
"KNN",
"H:nkNN=20:ScaleFrac=0.8:SigmaFact=1.0:Kernel=Gaus:UseKernel=F:UseWeight=T:!Trim");
100 void create_mva(
const std::string& output_filename,
const std::vector<std::string>& sig_files,
const std::vector<std::string>& bg_files,
bool silent){
101 gSystem->Load(
"libfilval.so");
102 auto replace_suffix = [](
const std::string& input,
const std::string& new_suffix){
103 return input.substr(0, input.find_last_of(
".")) + new_suffix;
105 string log_filename = replace_suffix(output_filename,
".log");
106 fv::util::Log::init_logger(log_filename, fv::util::LogPriority::kLogDebug);
108 std::map<std::string, std::string> filenames_with_labels;
109 for (
const std::string& fname : sig_files){
110 filenames_with_labels[fname] =
"signal";
112 for (
const std::string& fname : bg_files){
113 filenames_with_labels[fname] =
"background";
116 MiniTreeDataSet mt(output_filename, filenames_with_labels);
120 declare_containers(mt);
126 int main(
int argc,
char * argv[])
128 fv::util::ArgParser args(argc, argv);
129 if(args.cmdOptionExists(
"-h")) {
130 cout <<
"Usage: ./mva (-s) -out outfile.root -sig [signal_minitree.root]+ -bg [background_minitree.root]+" << endl;
133 bool silent = args.cmdOptionExists(
"-s");
134 string output_filename = args.getCmdOption(
"-out");
135 std::vector<std::string> sig_files;
136 std::vector<std::string> bg_files;
137 std::vector<std::string>* cur_flist =
nullptr;
139 for(
int i=1; i<argc; i++){
140 if (!strncmp(argv[i],
"-sig", 4)){
141 cur_flist = &sig_files;
143 else if (!strncmp(argv[i],
"-bg", 3)){
144 cur_flist = &bg_files;
147 else if (!strncmp(argv[i],
"-out", 4)){
150 else if (cur_flist !=
nullptr){
151 cur_flist->push_back(argv[i]);
154 create_mva(output_filename, sig_files, bg_files, silent);
The namespace containing all filval classes and functions.