4 #include "TEfficiency.h"
6 #include "TGraphErrors.h"
14 #include "TRatioPlot.h"
16 #include "TMVA/Factory.h"
17 #include "TMVA/DataLoader.h"
18 #include "TMVA/Tools.h"
31 gStyle->SetOptStat(0);
34 TCanvas *pad =
new TCanvas(
"pad",
38 TLegend *legend =
nullptr;
39 TH1F *htemplate =
nullptr;
41 auto default_data =
new TChain(
"tree");
42 default_data->SetTitle(input.Data());
43 auto files =
fileVector(Form(
"%s/%s/%s", dir.Data(), input.Data(), filePattern.Data()));
47 default_data->Add(
file.c_str());
52 auto signal_train = default_data->CopyTree(
"jet_flavor==4 && jet_n>0",
"", TMath::Floor(default_data->GetEntries() / 1.0));
53 std::cout <<
"Signal Tree (Training): " << signal_train->GetEntries() << std::endl;
55 auto background_train = default_data->CopyTree(
"(jet_flavor<4||jet_flavor==21) && jet_n>0",
"", TMath::Floor(default_data->GetEntries() / 1.0));
56 std::cout <<
"Background Tree (Training): " << background_train->GetEntries() << std::endl;
74 TMVA::Tools::Instance();
76 auto outputFile = TFile::Open(
"CharmJetClassification_Results.root",
"RECREATE");
78 TMVA::Factory factory(
"TMVAClassification",
80 "!V:ROC:!Correlations:!Silent:Color:DrawProgressBar:AnalysisType=Classification");
86 TMVA::DataLoader loader_ktagger(
"dataset_ktagger");
87 TMVA::DataLoader loader_etagger(
"dataset_etagger");
88 TMVA::DataLoader loader_mutagger(
"dataset_mutagger");
89 TMVA::DataLoader loader_ip3dtagger(
"dataset_ip3dtagger");
97 loader_ktagger.AddSpectator(
"jet_pt");
98 loader_ktagger.AddSpectator(
"jet_eta");
99 loader_ktagger.AddVariable(
"jet_k1_pt");
100 loader_ktagger.AddVariable(
"jet_k1_sIP3D");
101 loader_ktagger.AddVariable(
"jet_k2_pt");
102 loader_ktagger.AddVariable(
"jet_k2_sIP3D");
103 loader_ktagger.AddSpectator(
"jet_flavor");
104 loader_ktagger.AddSpectator(
"met_et");
105 loader_ktagger.AddSignalTree(signal_train, 1.0);
106 loader_ktagger.AddBackgroundTree(background_train, 1.0);
110 loader_etagger.AddSpectator(
"jet_pt");
111 loader_etagger.AddSpectator(
"jet_eta");
112 loader_etagger.AddVariable(
"jet_e1_pt");
113 loader_etagger.AddVariable(
"jet_e1_sIP3D");
114 loader_etagger.AddVariable(
"jet_e2_pt");
115 loader_etagger.AddVariable(
"jet_e2_sIP3D");
116 loader_etagger.AddSpectator(
"jet_flavor");
117 loader_etagger.AddSpectator(
"met_et");
118 loader_etagger.AddSignalTree(signal_train, 1.0);
119 loader_etagger.AddBackgroundTree(background_train, 1.0);
121 loader_mutagger.AddSpectator(
"jet_pt");
122 loader_mutagger.AddSpectator(
"jet_eta");
123 loader_mutagger.AddVariable(
"jet_mu1_pt");
124 loader_mutagger.AddVariable(
"jet_mu1_sIP3D");
125 loader_mutagger.AddVariable(
"jet_mu2_pt");
126 loader_mutagger.AddVariable(
"jet_mu2_sIP3D");
127 loader_mutagger.AddSpectator(
"jet_flavor");
128 loader_mutagger.AddSpectator(
"met_et");
129 loader_mutagger.AddSignalTree(signal_train, 1.0);
130 loader_mutagger.AddBackgroundTree(background_train, 1.0);
133 loader_ip3dtagger.AddSpectator(
"jet_pt");
134 loader_ip3dtagger.AddSpectator(
"jet_eta");
135 loader_ip3dtagger.AddVariable(
"jet_t1_pt");
136 loader_ip3dtagger.AddVariable(
"jet_t1_sIP3D");
137 loader_ip3dtagger.AddVariable(
"jet_t2_pt");
138 loader_ip3dtagger.AddVariable(
"jet_t2_sIP3D");
139 loader_ip3dtagger.AddVariable(
"jet_t3_pt");
140 loader_ip3dtagger.AddVariable(
"jet_t3_sIP3D");
141 loader_ip3dtagger.AddVariable(
"jet_t4_pt");
142 loader_ip3dtagger.AddVariable(
"jet_t4_sIP3D");
143 loader_ip3dtagger.AddSpectator(
"jet_flavor");
144 loader_ip3dtagger.AddSpectator(
"met_et");
145 loader_ip3dtagger.AddSignalTree(signal_train, 1.0);
146 loader_ip3dtagger.AddBackgroundTree(background_train, 1.0);
160 loader_ktagger.PrepareTrainingAndTestTree(TCut(
"jet_pt>5.0 && TMath::Abs(jet_eta) < 3.0 && jet_flavor==4 && met_et > 10"),
161 TCut(
"jet_pt>5.0 && TMath::Abs(jet_eta) < 3.0 && (jet_flavor<4||jet_flavor==21) && met_et > 10"),
162 "nTrain_Signal=50000:nTrain_Background=500000:nTest_Signal=50000:nTest_Background=500000:SplitMode=Random:NormMode=NumEvents:!V");
163 loader_etagger.PrepareTrainingAndTestTree(TCut(
"jet_pt>5.0 && TMath::Abs(jet_eta) < 3.0 && jet_flavor==4 && met_et > 10"),
164 TCut(
"jet_pt>5.0 && TMath::Abs(jet_eta) < 3.0 && (jet_flavor<4||jet_flavor==21) && met_et > 10"),
165 "nTrain_Signal=100000:nTrain_Background=1000000:nTest_Signal=100000:nTest_Background=1000000:SplitMode=Random:NormMode=NumEvents:!V");
166 loader_mutagger.PrepareTrainingAndTestTree(TCut(
"jet_pt>5.0 && TMath::Abs(jet_eta) < 3.0 && jet_flavor==4 && met_et > 10"),
167 TCut(
"jet_pt>5.0 && TMath::Abs(jet_eta) < 3.0 && (jet_flavor<4||jet_flavor==21) && met_et > 10"),
168 "nTrain_Signal=100000:nTrain_Background=1000000:nTest_Signal=100000:nTest_Background=1000000:SplitMode=Random:NormMode=NumEvents:!V");
169 loader_ip3dtagger.PrepareTrainingAndTestTree(TCut(
"jet_pt>5.0 && TMath::Abs(jet_eta) < 3.0 && jet_flavor==4 && met_et > 10"),
170 TCut(
"jet_pt>5.0 && TMath::Abs(jet_eta) < 3.0 && (jet_flavor<4||jet_flavor==21) && met_et > 10"),
171 "nTrain_Signal=10000:nTrain_Background=100000:nTest_Signal=10000:nTest_Background=100000:SplitMode=Random:NormMode=NumEvents:!V");
179 factory.BookMethod(&loader_ktagger, TMVA::Types::kMLP,
"CharmKTagger",
180 "!H:!V:NeuronType=ReLU:VarTransform=Norm:NCycles=1000:HiddenLayers=N+12:TestRate=5:!UseRegulator");
194 factory.TrainAllMethods();
197 factory.TestAllMethods();
198 factory.EvaluateAllMethods();
202 pad = factory.GetROCCurve(&loader_ktagger);
208 pad->SaveAs(
"CharmJetClassification_ROC.pdf");