From 5496e3c6720439820c8593f09a0ca41de2fd3591 Mon Sep 17 00:00:00 2001 From: David Ruth Date: Sun, 11 Feb 2024 21:53:51 -0500 Subject: [PATCH] Changed Snakefile and preprocess_model_training_data.cxx to include the Low Pt model training --- benchmarks/roman_pots/Snakefile | 38 ++++++++++++++++++- .../preprocess_model_training_data.cxx | 19 ++++++++-- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/benchmarks/roman_pots/Snakefile b/benchmarks/roman_pots/Snakefile index d0d66e4f..86ae5e2c 100644 --- a/benchmarks/roman_pots/Snakefile +++ b/benchmarks/roman_pots/Snakefile @@ -136,10 +136,11 @@ rule roman_pots_preprocess_model_training_data: data = "results/"+DETECTOR_VERSION+"/"+DETECTOR_CONFIG+"/detector_benchmarks/"+SUBSYSTEM+"/"+BENCHMARK+"/raw_data/"+DETECTOR_VERSION+"_"+DETECTOR_CONFIG+"_{index}.edm4hep.root", script = "preprocess_model_training_data.cxx" output: - "results/"+DETECTOR_VERSION+"/"+DETECTOR_CONFIG+"/detector_benchmarks/"+SUBSYSTEM+"/"+BENCHMARK+"/processed_data/"+DETECTOR_VERSION+"_"+DETECTOR_CONFIG+"_{index}.txt" + full = "results/"+DETECTOR_VERSION+"/"+DETECTOR_CONFIG+"/detector_benchmarks/"+SUBSYSTEM+"/"+BENCHMARK+"/processed_data/"+DETECTOR_VERSION+"_"+DETECTOR_CONFIG+"_{index}.txt", + lo = "results/"+DETECTOR_VERSION+"/"+DETECTOR_CONFIG+"/detector_benchmarks/"+SUBSYSTEM+"/"+BENCHMARK+"/processed_data/"+DETECTOR_VERSION+"_"+DETECTOR_CONFIG+"_lo_{index}.txt" shell: """ - root -q -b {input.script}\"(\\\"{input.data}\\\",\\\"{output}\\\")\" + root -q -b {input.script}\"(\\\"{input.data}\\\",\\\"{output.full}\\\",\\\"{output.lo}\\\")\" """ rule roman_pots_train_model_pz: @@ -193,3 +194,36 @@ rule roman_pots_train_model_px: python {input.script} --input_files {input.data} --model_name model_px --model_dir results/{params.detector_version}/{params.detector_config}/detector_benchmarks/{params.subsystem}/{params.benchmark}/artifacts/model_px/num_epochs_{wildcards.num_epochs}/learning_rate_{wildcards.learning_rate}/size_input_{wildcards.size_input}/size_output_{wildcards.size_output}/n_layers_{wildcards.n_layers}/size_first_hidden_layer_{wildcards.size_first_hidden_layer}/multiplier_{wildcards.multiplier}/leak_rate_{wildcards.leak_rate} --num_epochs {wildcards.num_epochs} --learning_rate {wildcards.learning_rate} --size_input {wildcards.size_input} --size_output {wildcards.size_output} --n_layers {wildcards.n_layers} --size_first_hidden_layer {wildcards.size_first_hidden_layer} --multiplier {wildcards.multiplier} --leak_rate {wildcards.leak_rate} """ +rule roman_pots_train_model_py_lo: + input: + data = ["results/"+DETECTOR_VERSION+"/"+DETECTOR_CONFIG+"/detector_benchmarks/"+SUBSYSTEM+"/"+BENCHMARK+"/processed_data/"+DETECTOR_VERSION+"_"+DETECTOR_CONFIG+"_lo_{index}.txt".format(index=index) for index in NFILES], + script = "train_dense_neural_network.py" + params: + detector_version=DETECTOR_VERSION, + detector_config=DETECTOR_CONFIG, + subsystem=SUBSYSTEM, + benchmark=BENCHMARK + output: + "results/"+DETECTOR_VERSION+"/"+DETECTOR_CONFIG+"/detector_benchmarks/"+SUBSYSTEM+"/"+BENCHMARK+"/artifacts/model_py/num_epochs_{num_epochs}/learning_rate_{learning_rate}/size_input_{size_input}/size_output_{size_output}/n_layers_{n_layers}/size_first_hidden_layer_{size_first_hidden_layer}/multiplier_{multiplier}/leak_rate_{leak_rate}/model_py_lo.pt", + "results/"+DETECTOR_VERSION+"/"+DETECTOR_CONFIG+"/detector_benchmarks/"+SUBSYSTEM+"/"+BENCHMARK+"/artifacts/model_py/num_epochs_{num_epochs}/learning_rate_{learning_rate}/size_input_{size_input}/size_output_{size_output}/n_layers_{n_layers}/size_first_hidden_layer_{size_first_hidden_layer}/multiplier_{multiplier}/leak_rate_{leak_rate}/LossVsEpoch_model_py_lo.png" + shell: + """ + python {input.script} --input_files {input.data} --model_name model_py --model_dir results/{params.detector_version}/{params.detector_config}/detector_benchmarks/{params.subsystem}/{params.benchmark}/artifacts/model_py/num_epochs_{wildcards.num_epochs}/learning_rate_{wildcards.learning_rate}/size_input_{wildcards.size_input}/size_output_{wildcards.size_output}/n_layers_{wildcards.n_layers}/size_first_hidden_layer_{wildcards.size_first_hidden_layer}/multiplier_{wildcards.multiplier}/leak_rate_{wildcards.leak_rate} --num_epochs {wildcards.num_epochs} --learning_rate {wildcards.learning_rate} --size_input {wildcards.size_input} --size_output {wildcards.size_output} --n_layers {wildcards.n_layers} --size_first_hidden_layer {wildcards.size_first_hidden_layer} --multiplier {wildcards.multiplier} --leak_rate {wildcards.leak_rate} + """ + +rule roman_pots_train_model_px_lo: + input: + data = ["results/"+DETECTOR_VERSION+"/"+DETECTOR_CONFIG+"/detector_benchmarks/"+SUBSYSTEM+"/"+BENCHMARK+"/processed_data/"+DETECTOR_VERSION+"_"+DETECTOR_CONFIG+"_lo_{index}.txt".format(index=index) for index in NFILES], + script = "train_dense_neural_network.py" + params: + detector_version=DETECTOR_VERSION, + detector_config=DETECTOR_CONFIG, + subsystem=SUBSYSTEM, + benchmark=BENCHMARK + output: + "results/"+DETECTOR_VERSION+"/"+DETECTOR_CONFIG+"/detector_benchmarks/"+SUBSYSTEM+"/"+BENCHMARK+"/artifacts/model_px/num_epochs_{num_epochs}/learning_rate_{learning_rate}/size_input_{size_input}/size_output_{size_output}/n_layers_{n_layers}/size_first_hidden_layer_{size_first_hidden_layer}/multiplier_{multiplier}/leak_rate_{leak_rate}/model_px_lo.pt", + "results/"+DETECTOR_VERSION+"/"+DETECTOR_CONFIG+"/detector_benchmarks/"+SUBSYSTEM+"/"+BENCHMARK+"/artifacts/model_px/num_epochs_{num_epochs}/learning_rate_{learning_rate}/size_input_{size_input}/size_output_{size_output}/n_layers_{n_layers}/size_first_hidden_layer_{size_first_hidden_layer}/multiplier_{multiplier}/leak_rate_{leak_rate}/LossVsEpoch_model_px_lo.png" + shell: + """ + python {input.script} --input_files {input.data} --model_name model_px --model_dir results/{params.detector_version}/{params.detector_config}/detector_benchmarks/{params.subsystem}/{params.benchmark}/artifacts/model_px/num_epochs_{wildcards.num_epochs}/learning_rate_{wildcards.learning_rate}/size_input_{wildcards.size_input}/size_output_{wildcards.size_output}/n_layers_{wildcards.n_layers}/size_first_hidden_layer_{wildcards.size_first_hidden_layer}/multiplier_{wildcards.multiplier}/leak_rate_{wildcards.leak_rate} --num_epochs {wildcards.num_epochs} --learning_rate {wildcards.learning_rate} --size_input {wildcards.size_input} --size_output {wildcards.size_output} --n_layers {wildcards.n_layers} --size_first_hidden_layer {wildcards.size_first_hidden_layer} --multiplier {wildcards.multiplier} --leak_rate {wildcards.leak_rate} + """ diff --git a/benchmarks/roman_pots/preprocess_model_training_data.cxx b/benchmarks/roman_pots/preprocess_model_training_data.cxx index 748c939a..47d7e4c6 100644 --- a/benchmarks/roman_pots/preprocess_model_training_data.cxx +++ b/benchmarks/roman_pots/preprocess_model_training_data.cxx @@ -9,11 +9,11 @@ // // Author: Alex Jentsch //------------------------ - +//Low PT preprocessing added by David Ruth using namespace std; -void preprocess_model_training_data(TString inputFile, TString outputFile) { +void preprocess_model_training_data(TString inputFile, TString outputFile, TString outputFile_lo) { string fileName; TFile* inputRootFile; @@ -52,6 +52,8 @@ void preprocess_model_training_data(TString inputFile, TString outputFile) { ofstream outputTrainingFile; outputTrainingFile.open(outputFile); + ofstream outputTrainingFile_lo; + outputTrainingFile_lo.open(outputFile_lo); // MC particles TTreeReaderArray mc_px_array = { tree_reader, "MCParticles.momentum.x" }; TTreeReaderArray mc_py_array = { tree_reader, "MCParticles.momentum.y" }; @@ -81,6 +83,7 @@ void preprocess_model_training_data(TString inputFile, TString outputFile) { bool hasMCProton = false; bool hitLayerOne = false; bool hitLayerTwo = false; + bool lowPT = false; double mcProtonMomentum[3]; TVector3 mctrk; @@ -127,7 +130,12 @@ void preprocess_model_training_data(TString inputFile, TString outputFile) { hitLayerTwo = true; } } - + if (hasMCProton) { + double Pt = sqrt(pow(mcProtonMomentum[0],2) + pow(mcProtonMomentum[1],2)); + if(Pt < 0.3) { + lowPT = true; + } + } if (hasMCProton && hitLayerOne && hitLayerTwo) { double slope_x = (rpHitLayerTwo[0] - rpHitLayerOne[0]) / (rpHitLayerTwo[2] - rpHitLayerOne[2]); @@ -135,6 +143,10 @@ void preprocess_model_training_data(TString inputFile, TString outputFile) { outputTrainingFile << mcProtonMomentum[0] << "\t" << mcProtonMomentum[1] << "\t" << mcProtonMomentum[2] << "\t"; outputTrainingFile << rpHitLayerTwo[0] << "\t" << slope_x << "\t" << rpHitLayerTwo[1] << "\t" << slope_y << endl; + if (lowPT) { + outputTrainingFile_lo << mcProtonMomentum[0] << "\t" << mcProtonMomentum[1] << "\t" << mcProtonMomentum[2] << "\t"; + outputTrainingFile_lo << rpHitLayerTwo[0] << "\t" << slope_x << "\t" << rpHitLayerTwo[1] << "\t" << slope_y << endl; + } } iEvent++; @@ -142,6 +154,7 @@ void preprocess_model_training_data(TString inputFile, TString outputFile) { inputRootFile->Close(); outputTrainingFile.close(); + outputTrainingFile_lo.close(); return; }