Skip to content

Commit

Permalink
Merge pull request #22 from tomeichlersmith/clang-format
Browse files Browse the repository at this point in the history
Clang format
  • Loading branch information
tomeichlersmith authored Sep 18, 2023
2 parents e173101 + e26648f commit 88ad650
Show file tree
Hide file tree
Showing 17 changed files with 849 additions and 751 deletions.
42 changes: 22 additions & 20 deletions app/extract_library.cxx
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
/**
/**
* @file extract_library.cxx
* definition of g4db-extract-library executable
*/

#include <iostream>
#include <fstream>
#include <iostream>

#include "G4DarkBreM/ParseLibrary.h"

/**
* printout how to use g4db-extract-library
*/
void usage() {
std::cout <<
"USAGE:\n"
" g4db-extract-library [options] db-lib\n"
"\n"
" Extract the input DB event library into a single CSV file\n"
"\n"
"ARGUMENTS\n"
" db-lib : dark brem event library to load and extract\n"
"\n"
"OPTIONS\n"
" -h,--help : produce this help and exit\n"
" -o,--output : output file to write extracted events to\n"
" use the input library name with the '.csv' extension added by default\n"
" --aprime-id : A' ID number as used in the LHE files\n"
std::cout
<< "USAGE:\n"
" g4db-extract-library [options] db-lib\n"
"\n"
" Extract the input DB event library into a single CSV file\n"
"\n"
"ARGUMENTS\n"
" db-lib : dark brem event library to load and extract\n"
"\n"
"OPTIONS\n"
" -h,--help : produce this help and exit\n"
" -o,--output : output file to write extracted events to\n"
" use the input library name with the '.csv' "
"extension added by default\n"
" --aprime-id : A' ID number as used in the LHE files\n"
<< std::flush;
}

Expand All @@ -42,13 +43,13 @@ int main(int argc, char* argv[]) try {
usage();
return 0;
} else if (arg == "-o" or arg == "--output") {
if (i_arg+1 >= argc) {
if (i_arg + 1 >= argc) {
std::cerr << arg << " requires an argument after it" << std::endl;
return 1;
}
output_filename = argv[++i_arg];
} else if (arg == "--aprime-id") {
if (i_arg+1 >= argc) {
if (i_arg + 1 >= argc) {
std::cerr << arg << " requires an argument after it" << std::endl;
return 1;
}
Expand All @@ -69,12 +70,13 @@ int main(int argc, char* argv[]) try {
if (output_filename.empty()) {
// remove trailing slash if present
if (db_lib.back() == '/') db_lib.pop_back();
output_filename = db_lib+".csv";
output_filename = db_lib + ".csv";
}

std::ofstream output{output_filename};
if (not output.is_open()) {
std::cerr << "ERROR: Unable to open " << output_filename << " for writing." << std::endl;
std::cerr << "ERROR: Unable to open " << output_filename << " for writing."
<< std::endl;
return 2;
}

Expand Down
100 changes: 54 additions & 46 deletions app/scale.cxx
Original file line number Diff line number Diff line change
@@ -1,48 +1,57 @@
/**
/**
* @file scale.cxx
* definition of g4db-scale executable
*/

#include <iostream>
#include <fstream>
#include <iostream>

#include "G4DarkBreM/G4APrime.h"
#include "G4DarkBreM/G4DarkBreMModel.h"
#include "G4Electron.hh"
#include "G4MuonMinus.hh"

#include "G4DarkBreM/G4DarkBreMModel.h"
#include "G4DarkBreM/G4APrime.h"

/**
* printout how to use g4db-scale
*/
void usage() {
std::cout <<
"USAGE:\n"
" g4db-scale [options] db-lib\n"
"\n"
"Run the scaling procedure for the input incident energy and madgraph file\n"
"\n"
"This executable is a low-level way to directly test the scaling procedure implemented\n"
"inside the G4DarkBreMModel without cluttering the results with the rest of the Geant4\n"
"simulation machinery. This means a better understanding of how the model functions is\n"
"necessary to be able to effectively use this program.\n"
" - The 'incident energy' input here is the energy of the lepton JUST BEFORE it dark brems.\n"
" - The scaling procedure should scale from a MG sample at an energy ABOVE the incident energy\n"
" - The scaling procedure generates the recoil lepton's kinematics assuming the incident\n"
" lepton is traveling along the z-axis. The user is expected to rotate to the actual incident\n"
" frame and calculate the outgoing dark photon kinematics assuming conservation of momentum.\n"
"\n"
"ARGUMENTS\n"
" db-lib : dark brem event library to load and sample\n"
"\n"
"OPTIONS\n"
" -h,--help : produce this help and exit\n"
" -o,--output : output file to write scaled events to\n"
" -E,--incident-energy : energy of incident lepton in GeV\n"
" -Z,--target-Z : atomic Z of target nucleus to scale to\n"
" -N,--num-events : number of events to sample and scale\n"
" -M,--ap-mass : mass of dark photon in MeV\n"
" --muons : pass to set lepton to muons (otherwise electrons)\n"
std::cout
<< "USAGE:\n"
" g4db-scale [options] db-lib\n"
"\n"
"Run the scaling procedure for the input incident energy and madgraph "
"file\n"
"\n"
"This executable is a low-level way to directly test the scaling "
"procedure implemented\n"
"inside the G4DarkBreMModel without cluttering the results with the "
"rest of the Geant4\n"
"simulation machinery. This means a better understanding of how the "
"model functions is\n"
"necessary to be able to effectively use this program.\n"
" - The 'incident energy' input here is the energy of the lepton JUST "
"BEFORE it dark brems.\n"
" - The scaling procedure should scale from a MG sample at an energy "
"ABOVE the incident energy\n"
" - The scaling procedure generates the recoil lepton's kinematics "
"assuming the incident\n"
" lepton is traveling along the z-axis. The user is expected to "
"rotate to the actual incident\n"
" frame and calculate the outgoing dark photon kinematics assuming "
"conservation of momentum.\n"
"\n"
"ARGUMENTS\n"
" db-lib : dark brem event library to load and sample\n"
"\n"
"OPTIONS\n"
" -h,--help : produce this help and exit\n"
" -o,--output : output file to write scaled events to\n"
" -E,--incident-energy : energy of incident lepton in GeV\n"
" -Z,--target-Z : atomic Z of target nucleus to scale to\n"
" -N,--num-events : number of events to sample and scale\n"
" -M,--ap-mass : mass of dark photon in MeV\n"
" --muons : pass to set lepton to muons (otherwise "
"electrons)\n"
<< std::flush;
}

Expand Down Expand Up @@ -70,31 +79,31 @@ int main(int argc, char* argv[]) try {
} else if (arg == "--muons") {
muons = true;
} else if (arg == "-o" or arg == "--output") {
if (i_arg+1 >= argc) {
if (i_arg + 1 >= argc) {
std::cerr << arg << " requires an argument after it" << std::endl;
return 1;
}
output_filename = argv[++i_arg];
} else if (arg == "-E" or arg == "--incident-energy") {
if (i_arg+1 >= argc) {
if (i_arg + 1 >= argc) {
std::cerr << arg << " requires an argument after it" << std::endl;
return 1;
}
incident_energy = std::stod(argv[++i_arg]);
} else if (arg == "-Z" or arg == "--target-Z") {
if (i_arg+1 >= argc) {
if (i_arg + 1 >= argc) {
std::cerr << arg << " requires an argument after it" << std::endl;
return 1;
}
target_Z = std::stod(argv[++i_arg]);
} else if (arg == "-M" or arg == "--ap-mass") {
if (i_arg+1 >= argc) {
if (i_arg + 1 >= argc) {
std::cerr << arg << " requires an argument after it" << std::endl;
return 1;
}
ap_mass = std::stod(argv[++i_arg]);
} else if (arg == "-N" or arg == "--num-events") {
if (i_arg+1 >= argc) {
if (i_arg + 1 >= argc) {
std::cerr << arg << " requires an argument after it" << std::endl;
return 1;
}
Expand All @@ -120,17 +129,17 @@ int main(int argc, char* argv[]) try {
}

// the process accesses the A' mass from the G4 particle
G4APrime::Initialize(ap_mass/GeV);
G4APrime::Initialize(ap_mass / GeV);
// create the model, this is where the LHE file is parsed
// into an in-memory library to sample and scale from
g4db::G4DarkBreMModel db_model(
db_lib, muons,
0.0, // threshold
1.0, // epsilon
0.0, // threshold
1.0, // epsilon
g4db::G4DarkBreMModel::ScalingMethod::ForwardOnly);
db_model.PrintInfo();
printf(" %-16s %f\n", "Lepton Mass [MeV]:", lepton_mass);
printf(" %-16s %f\n", "A' Mass [MeV]:", ap_mass/MeV);
printf(" %-16s %f\n", "A' Mass [MeV]:", ap_mass / MeV);

std::ofstream f{output_filename};
if (not f.is_open()) {
Expand All @@ -140,12 +149,11 @@ int main(int argc, char* argv[]) try {
f << "recoil_energy,recoil_px,recoil_py,recoil_pz\n";

for (int i_event{0}; i_event < num_events; ++i_event) {
G4ThreeVector recoil = db_model.scale(target_Z, incident_energy, lepton_mass);
double recoil_energy = sqrt(recoil.mag2() + lepton_mass*lepton_mass);
G4ThreeVector recoil =
db_model.scale(target_Z, incident_energy, lepton_mass);
double recoil_energy = sqrt(recoil.mag2() + lepton_mass * lepton_mass);

f << recoil_energy << ','
<< recoil.x() << ','
<< recoil.y() << ','
f << recoil_energy << ',' << recoil.x() << ',' << recoil.y() << ','
<< recoil.z() << '\n';
}

Expand Down
Loading

0 comments on commit 88ad650

Please sign in to comment.