Skip to content

Commit

Permalink
Changed Snakefile and preprocess_model_training_data.cxx to include t…
Browse files Browse the repository at this point in the history
…he Low Pt model training
  • Loading branch information
David Ruth committed Feb 12, 2024
1 parent acbb6c5 commit 5496e3c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
38 changes: 36 additions & 2 deletions benchmarks/roman_pots/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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}
"""
19 changes: 16 additions & 3 deletions benchmarks/roman_pots/preprocess_model_training_data.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<float> mc_px_array = { tree_reader, "MCParticles.momentum.x" };
TTreeReaderArray<float> mc_py_array = { tree_reader, "MCParticles.momentum.y" };
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -127,21 +130,31 @@ 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]);
double slope_y = (rpHitLayerTwo[1] - rpHitLayerOne[1]) / (rpHitLayerTwo[2] - rpHitLayerOne[2]);

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++;
} // event loop

inputRootFile->Close();
outputTrainingFile.close();
outputTrainingFile_lo.close();

return;
}
Expand Down

0 comments on commit 5496e3c

Please sign in to comment.