64 DT::Flow flow_TPS(steering, inputs_TPS);
65 DT::Flow flow_DPS1(steering, inputs_DPS1);
66 DT::Flow flow_DPS2(steering, inputs_DPS2);
67 DT::Flow flow_SPS(steering, inputs_SPS);
68 auto tIn_TPS = flow_TPS.GetInputTree();
69 auto tIn_DPS1 = flow_DPS1.GetInputTree();
70 auto tIn_DPS2 = flow_DPS2.GetInputTree();
71 auto tIn_SPS = flow_SPS.GetInputTree();
72 auto [fOut, tOut] = flow_TPS.GetOutput(output);
78 int nEntries_TPS = tIn_TPS->GetEntries();
79 int nEntries_DPS1 = tIn_DPS1->GetEntries();
80 int nEntries_DPS2 = tIn_DPS2->GetEntries();
81 int nEntries_SPS = tIn_SPS->GetEntries();
86 case TrainingMode::ThreeClasses:
88 int nEntries_DPS = nEntries_DPS1 + nEntries_DPS2;
89 nTrain = ranges::min({nEntries_TPS, nEntries_DPS, nEntries_SPS}) * 0.8;
90 cout <<
"Three-classes training mode selected" << endl;
93 case TrainingMode::TwoClasses:
94 nTrain = ranges::min({nEntries_TPS, nEntries_DPS1, nEntries_DPS2, nEntries_SPS}) * 0.8;
95 cout <<
"Two-classes training mode selected" << endl;
100 TMVA::Tools::Instance();
101 unique_ptr<TMVA::Factory> factory;
103 case TrainingMode::ThreeClasses:
104 factory = make_unique<TMVA::Factory>(
105 "TMVAMulticlass", fOut,
106 "!V:!Silent:Color:DrawProgressBar:Transformations=I,D,P,G,N:AnalysisType=Multiclass");
108 case TrainingMode::TwoClasses:
109 factory = make_unique<TMVA::Factory>(
110 "TMVAClassification", fOut,
111 "!V:!Silent:Color:DrawProgressBar:Transformations=I,D,P,G,N:AnalysisType=Classification");
115 auto dataloader = make_unique<TMVA::DataLoader>(
"dataset");
118 tpsVars.printVariables();
121 case TrainingMode::ThreeClasses:
122 dataloader->AddTree(tIn_TPS,
"TPS", 1.0);
123 dataloader->AddTree(tIn_DPS1,
"DPS", 1.0);
124 dataloader->AddTree(tIn_DPS2,
"DPS", 1.0);
125 dataloader->AddTree(tIn_SPS,
"SPS", 1.0);
126 dataloader->SetWeightExpression(
"EventWeight",
"TPS");
127 dataloader->SetWeightExpression(
"EventWeight",
"DPS");
128 dataloader->SetWeightExpression(
"EventWeight",
"SPS");
130 case TrainingMode::TwoClasses:
131 dataloader->AddSignalTree(tIn_TPS, 1.0);
132 dataloader->AddBackgroundTree(tIn_DPS1, 1.0);
133 dataloader->AddBackgroundTree(tIn_DPS2, 1.0);
134 dataloader->AddBackgroundTree(tIn_SPS, 1.0);
135 dataloader->SetWeightExpression(
"EventWeight",
"Signal");
136 dataloader->SetWeightExpression(
"EventWeight",
"Background");
140 cout <<
green <<
"Trees added successfully. About to prepare training and test trees..." <<
def << endl;
144 case TrainingMode::ThreeClasses:
146 dataloader->PrepareTrainingAndTestTree(
148 Form(
"SplitMode=Random:NormMode=NumEvents:"
149 "SplitSeed=100:nTrain_TPS=%d:nTrain_DPS=%d:"
151 nTrain, nTrain, nTrain));
154 "!H:V:NTrees=800:MaxDepth=2:MinNodeSize=5%:"
155 "nCuts=100:BoostType=Grad:Shrinkage=0.03:"
156 "UseBaggedBoost:BaggedSampleFraction=0.7:"
157 "UseRandomisedTrees";
158 factory->BookMethod(dataloader.get(), TMVA::Types::kBDT,
"BDT", BDToptions);
161 "!H:V:ErrorStrategy=CROSSENTROPY"
162 ":WeightInitialization=XAVIER"
163 ":Layout=RELU|256,RELU|128,RELU|64,LINEAR"
164 ":TrainingStrategy=LearningRate=1e-4,Momentum=0.9,"
165 "Repetitions=1,ConvergenceSteps=20,BatchSize=1024,"
166 "TestRepetitions=1,MaxEpochs=100,WeightDecay=1e-3,"
167 "Regularization=L2,Optimizer=ADAM,"
168 "DropConfig=0.0+0.1+0.1+0.0";
169 factory->BookMethod(dataloader.get(), TMVA::Types::kDL,
"DNN", DNNoptions);
172 case TrainingMode::TwoClasses:
175 dataloader->PrepareTrainingAndTestTree(
177 Form(
"SplitMode=Random:NormMode=EqualNumEvents:"
178 "VerboseLevel=Debug:nTrain_Signal=%d:"
179 "nTrain_Background=%d:nTest_Signal=%d:"
180 "nTest_Background=%d",
181 nTrain, nTrain * 3, nTrain / 4, nTrain * 3 / 4));
184 "H:V:NTrees=800:MaxDepth=3:MinNodeSize=2%:"
185 "nCuts=100:BoostType=Grad:Shrinkage=0.05:"
186 "UseBaggedBoost:BaggedSampleFraction=0.8:"
187 "UseRandomisedTrees";
188 factory->BookMethod(dataloader.get(), TMVA::Types::kBDT,
"BDT", BDToptions);
191 "H:V:ErrorStrategy=CROSSENTROPY:"
192 "WeightInitialization=XAVIER"
193 ":Layout=RELU|512,RELU|256,RELU|128,RELU|64,LINEAR"
194 ":TrainingStrategy=LearningRate=5e-4,Momentum=0.9,"
195 "Repetitions=1,ConvergenceSteps=20,BatchSize=512,"
196 "TestRepetitions=1,MaxEpochs=100,WeightDecay=1e-5,"
197 "Regularization=L2,Optimizer=ADAM,"
198 "DropConfig=0.0+0.3+0.3+0.0";
199 factory->BookMethod(dataloader.get(), TMVA::Types::kDL,
"DNN", DNNoptions);
202 "!H:!V:NTrees=200:MinNodeSize=1%:MaxDepth=4:"
203 "UseRandomisedTrees:UsePoissonNvars";
204 factory->BookMethod(dataloader.get(), TMVA::Types::kBDT,
"RF", RFoptions);
206 TString XGBoostOptions =
"!H:!V:NTrees=1000:MaxDepth=4";
207 factory->BookMethod(dataloader.get(), TMVA::Types::kBDT,
"XGBoost", XGBoostOptions);
209 cout <<
"BDT options: " << BDToptions << endl;
210 cout <<
"DNN options: " << DNNoptions << endl;
211 cout <<
"RF options: " << RFoptions << endl;
216 factory->TrainAllMethods();
217 factory->TestAllMethods();
218 factory->EvaluateAllMethods();
220 metainfo.Set<
bool>(
"git",
"complete",
true);