31useTMVACNN = opt[0]
if len(opt) > 0
else False
32useTMVADNN = opt[2]
if len(opt) > 2
else False
33useTMVABDT = opt[3]
if len(opt) > 3
else False
40def MakeImagesTree(n, nh, nw):
43 fileOutName =
"images_data_16x16.root"
50 sX2 = sX1 + delta_sigma
51 sY2 = sY1 - delta_sigma
52 h1 = ROOT.TH2D(
"h1",
"h1", nh, 0, 10, nw, 0, 10)
53 h2 = ROOT.TH2D(
"h2",
"h2", nh, 0, 10, nw, 0, 10)
54 f1 = ROOT.TF2(
"f1",
"xygaus")
55 f2 = ROOT.TF2(
"f2",
"xygaus")
56 sgn = ROOT.TTree(
"sig_tree",
"signal_tree")
57 bkg = ROOT.TTree(
"bkg_tree",
"background_tree")
59 f =
TFile(fileOutName,
"RECREATE")
60 x1 = ROOT.std.vector[
"float"](ntot)
61 x2 = ROOT.std.vector[
"float"](ntot)
65 bkg.Branch(
"vars",
"std::vector<float>", x1)
66 sgn.Branch(
"vars",
"std::vector<float>", x2)
71 f1.SetParameters(1, 5, sX1, 5, sY1)
72 f2.SetParameters(1, 5, sX2, 5, sY2)
73 ROOT.gRandom.SetSeed(0)
74 ROOT.Info(
"TMVA_CNN_Classification",
"Filling ROOT tree \n")
77 print(
"Generating image event ...", i)
82 f1.SetParameter(1, ROOT.gRandom.Uniform(3, 7))
83 f1.SetParameter(3, ROOT.gRandom.Uniform(3, 7))
84 f2.SetParameter(1, ROOT.gRandom.Uniform(3, 7))
85 f2.SetParameter(3, ROOT.gRandom.Uniform(3, 7))
87 h1.FillRandom(f1, nRndmEvts)
88 h2.FillRandom(f2, nRndmEvts)
94 x1[m] = h1.GetBinContent(k + 1, l + 1) + ROOT.gRandom.Gaus(0, pixelNoise)
95 x2[m] = h2.GetBinContent(k + 1, l + 1) + ROOT.gRandom.Gaus(0, pixelNoise)
103 print(
"Signal and background tree with images data written to the file %s", f.GetName())
108hasGPU =
"tmva-gpu" in ROOT.gROOT.GetConfigFeatures()
109hasCPU =
"tmva-cpu" in ROOT.gROOT.GetConfigFeatures()
113if (
not hasCPU
and not hasGPU) :
114 ROOT.Warning(
"TMVA_CNN_Classificaton",
"ROOT is not supporting tmva-cpu and tmva-gpu skip using TMVA-DNN and TMVA-CNN")
120 "TMVA_CNN_Classificaton",
121 "TMVA is not build with GPU or CPU multi-thread support. Cannot use TMVA Deep Learning for CNN",
124writeOutputFile =
True
131if "imt" in ROOT.gROOT.GetConfigFeatures():
133 ROOT.gSystem.Setenv(
"OMP_NUM_THREADS",
"1")
136 print(
"Running in serial mode since ROOT does not support MT")
143 outputFile =
TFile.Open(
"TMVA_CNN_ClassificationOutput.root",
"RECREATE")
168 "TMVA_CNN_Classification",
174 AnalysisType=
"Classification",
175 Transformations=
None,
198inputFileName =
"images_data_16x16.root"
201if ROOT.gSystem.AccessPathName(inputFileName):
202 MakeImagesTree(nevt, 16, 16)
206 ROOT.Warning(
"TMVA_CNN_Classification",
"Error opening input file %s - exit", inputFileName.Data())
214signalTree = inputFile.Get(
"sig_tree")
215backgroundTree = inputFile.Get(
"bkg_tree")
217nEventsSig = signalTree.GetEntries()
218nEventsBkg = backgroundTree.GetEntries()
222backgroundWeight = 1.0
225loader.AddSignalTree(signalTree, signalWeight)
226loader.AddBackgroundTree(backgroundTree, backgroundWeight)
230loader.AddVariablesArray(
"vars", imgSize)
248nTrainSig = 0.8 * nEventsSig
249nTrainBkg = 0.8 * nEventsBkg
253loader.PrepareTrainingAndTestTree(
256 nTrain_Signal=nTrainSig,
257 nTrain_Background=nTrainBkg,
260 NormMode=
"NumEvents",
262 CalcCorrelations=
False,
288 BoostType=
"AdaBoost",
291 BaggedSampleFraction=0.5,
292 SeparationType=
"GiniIndex",
303 layoutString = ROOT.TString(
304 "DENSE|100|RELU,BNORM,DENSE|100|RELU,BNORM,DENSE|100|RELU,BNORM,DENSE|100|RELU,DENSE|1|LINEAR"
310 trainingString1 = ROOT.TString(
311 "LearningRate=1e-3,Momentum=0.9,Repetitions=1,"
312 "ConvergenceSteps=5,BatchSize=100,TestRepetitions=1,"
313 "WeightDecay=1e-4,Regularization=None,"
314 "Optimizer=ADAM,DropConfig=0.0+0.0+0.0+0."
316 trainingString1 +=
",MaxEpochs=" + str(max_epochs)
319 dnnMethodName =
"TMVA_DNN_CPU"
325 dnnMethodName =
"TMVA_DNN_GPU"
333 ErrorStrategy=
"CROSSENTROPY",
335 WeightInitialization=
"XAVIER",
337 TrainingStrategy=trainingString1,
338 Architecture=dnnOptions
371 trainingString1 = ROOT.TString(
372 "LearningRate=1e-3,Momentum=0.9,Repetitions=1,"
373 "ConvergenceSteps=5,BatchSize=100,TestRepetitions=1,"
374 "WeightDecay=1e-4,Regularization=None,"
375 "Optimizer=ADAM,DropConfig=0.0+0.0+0.0+0.0"
377 trainingString1 +=
",MaxEpochs=" + str(max_epochs)
380 cnnMethodName =
"TMVA_CNN_CPU"
385 cnnMethodName =
"TMVA_CNN_GPU"
393 ErrorStrategy=
"CROSSENTROPY",
395 WeightInitialization=
"XAVIER",
396 InputLayout=
"1|16|16",
397 Layout=
"CONV|10|3|3|1|1|1|1|RELU,BNORM,CONV|10|3|3|1|1|1|1|RELU,MAXPOOL|2|2|1|1,RESHAPE|FLAT,DENSE|100|RELU,DENSE|1|LINEAR",
398 TrainingStrategy=trainingString1,
399 Architecture=cnnOptions,
404factory.TrainAllMethods()
408factory.TestAllMethods()
410factory.EvaluateAllMethods()
414c1 = factory.GetROCCurve(loader)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
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.
This is the main MVA steering class.
void EnableImplicitMT(UInt_t numthreads=0)
Enable ROOT's implicit multi-threading for all objects and methods that provide an internal paralleli...
UInt_t GetThreadPoolSize()
Returns the size of ROOT's thread pool.