Skip to content

Commit

Permalink
format the source code after large feature update
Browse files Browse the repository at this point in the history
formatting ran with clang-format and the Google style

  git ls-tree -r HEAD --name-only | egrep '(\.h|\.cxx)$' > format.list
  clang-format --style=Google -i $(cat format.list)
  • Loading branch information
tomeichlersmith committed Aug 15, 2024
1 parent ad1d40a commit 28df268
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 75 deletions.
24 changes: 11 additions & 13 deletions app/scale.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ int main(int argc, char* argv[]) try {
1.0, // epsilon
g4db::G4DarkBreMModel::ScalingMethod::ForwardOnly,
g4db::G4DarkBreMModel::XsecMethod::Auto,
50.0, // max_R_for_full
622, // aprime_lhe_id
true, // load_library
50.0, // max_R_for_full
622, // aprime_lhe_id
true, // load_library
scale_APrime);
db_model.PrintInfo();
printf(" %-16s %f\n", "Lepton Mass [MeV]:", lepton_mass * GeV / MeV);
printf(" %-16s %f\n", "A' Mass [MeV]:", ap_mass / MeV);

double lepton_mass_squared{lepton_mass * lepton_mass};
double ap_mass_squared{ap_mass * ap_mass};

Expand All @@ -164,22 +164,20 @@ int main(int argc, char* argv[]) try {
<< "centerMomentum_pz\n";

for (int i_event{0}; i_event < num_events; ++i_event) {
std::pair<G4ThreeVector, G4ThreeVector> momenta =
std::pair<G4ThreeVector, G4ThreeVector> momenta =
db_model.scale(target_Z, incident_energy, lepton_mass);
G4ThreeVector recoil = momenta.first;
double recoil_energy = sqrt(recoil.mag2() + lepton_mass_squared);
G4ThreeVector aprime = momenta.second;
double aprime_energy = sqrt(aprime.mag2() + ap_mass_squared);

// convert to GeV to match MG output
f << target_Z << ',' << incident_energy << ','
<< recoil_energy / GeV << ',' << recoil.x() / GeV << ','
<< recoil.y() / GeV << ',' << recoil.z() / GeV << ","
<< (recoil_energy + aprime_energy) / GeV << ","
<< (recoil.x() + aprime.x()) / GeV << ","
<< (recoil.y() + aprime.y()) / GeV << ","
<< (recoil.z() + aprime.z() ) / GeV
<< '\n';
f << target_Z << ',' << incident_energy << ',' << recoil_energy / GeV << ','
<< recoil.x() / GeV << ',' << recoil.y() / GeV << ',' << recoil.z() / GeV
<< "," << (recoil_energy + aprime_energy) / GeV << ","
<< (recoil.x() + aprime.x()) / GeV << ","
<< (recoil.y() + aprime.y()) / GeV << ","
<< (recoil.z() + aprime.z()) / GeV << '\n';
}

f.close();
Expand Down
22 changes: 11 additions & 11 deletions include/G4DarkBreM/G4APrime.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ class G4APrime : public G4ParticleDefinition {
*
* As with GeantDecay, the APrime will decay to e-/e+.
*/
FlatDecay = 2,
FlatDecay = 2,

/**
* Let Geant4 handle the decay. In this case, the lifetime
* must be included as a parameter of the constructor.
*
* e-/e+ is the only decay channel.
*/
GeantDecay = 3
/**
* Let Geant4 handle the decay. In this case, the lifetime
* must be included as a parameter of the constructor.
*
* e-/e+ is the only decay channel.
*/
GeantDecay = 3
};

/**
Expand All @@ -75,7 +75,7 @@ class G4APrime : public G4ParticleDefinition {
*
* @param[in] mass The mass of the APrime in MeV
* @param[in] id The PDG ID number to use for the APrime particle
* @param[in] tau The proper lifetime
* @param[in] tau The proper lifetime
* (only used if decay_mode is set to GeantDecay)
* @param[in] decay_mode G4APrime::DecayMode on whether/how to decay the A'
*
Expand All @@ -85,13 +85,13 @@ class G4APrime : public G4ParticleDefinition {
* scheme](https://pdg.lbl.gov/2007/reviews/montecarlorpp.pdf), avoiding the
* already-defined "one-of-a-kind" particles using 39, 41, and 42.
*/
static void Initialize(double mass, int id = 62, double tau = -1.0,
static void Initialize(double mass, int id = 62, double tau = -1.0,
DecayMode decay_mode = DecayMode::NoDecay);

/// Get the G4APrime::DecayMode that was provided to G4APrime::Initialize
static DecayMode getDecayMode() { return decay_mode_; }

private:
private:
/** Reference to single particle definition of A' */
static G4APrime* theAPrime;

Expand Down
47 changes: 25 additions & 22 deletions include/G4DarkBreM/G4DarkBreMModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ class G4DarkBreMModel : public PrototypeModel {
* @param[in] scale_APrime whether to scale the A' kinematics based on the
* library. If false, define A' momentum to conserve momentum without taking
* nuclear recoil into account.
* @param[in] dist_decay_min minimum flight distance [mm] at which to
* @param[in] dist_decay_min minimum flight distance [mm] at which to
* decay the A' if G4APrime::DecayMode is set to FlatDecay
* @param[in] dist_decay_max maximum flight distance [mm] at which to
* @param[in] dist_decay_max maximum flight distance [mm] at which to
* decay the A' if G4APrime::DecayMode is set to FlatDecay
*/
G4DarkBreMModel(const std::string& library_path, bool muons,
Expand Down Expand Up @@ -272,11 +272,12 @@ class G4DarkBreMModel : public PrototypeModel {
* @param[in] target_Z atomic Z of target nucleus
* @param[in] incident_energy incident total energy of the lepton [GeV]
* @param[in] lepton_mass mass of incident lepton [GeV]
* @return G4ThreeVectors representing the outgoing momenta of the recoil lepton
* and the A', respectively
* @return G4ThreeVectors representing the outgoing momenta of the recoil
* lepton and the A', respectively
*/
std::pair<G4ThreeVector, G4ThreeVector>
scale(double target_Z, double incident_energy, double lepton_mass);
std::pair<G4ThreeVector, G4ThreeVector> scale(double target_Z,
double incident_energy,
double lepton_mass);

/**
* Simulates the emission of a dark photon + lepton
Expand Down Expand Up @@ -413,35 +414,37 @@ class G4DarkBreMModel : public PrototypeModel {

/**
* whether to scale the outgoing A' momentum based on the MadGraph library.
*
*
* The same scaling method is used as for the recoil lepton.
* The difference between the azimuthal angle of the A' and the recoil lepton
* is designed to be preserved from MadGraph.
* The preservation of this angle and the overall scaling of the A' has only been validated for
* electrons with incident energies ranging from 1GeV to 10GeV and dark photon masses
* ranging from 1MeV to 100MeV. While the scaling is expected to be well behaved for muons
* and at other energy scales, users are encouraged to double-check this behavior in their
* situation and report issues to the repository. https://github.com/LDMX-Software/G4DarkBreM
* The preservation of this angle and the overall scaling of the A' has only
* been validated for electrons with incident energies ranging from 1GeV to
* 10GeV and dark photon masses ranging from 1MeV to 100MeV. While the scaling
* is expected to be well behaved for muons and at other energy scales, users
* are encouraged to double-check this behavior in their situation and report
* issues to the repository. https://github.com/LDMX-Software/G4DarkBreM
*
* If false, will define the 3-momentum of the A' to conserve 3-momentum
* with primary and recoil lepton, not taking into account the nuclear recoil.
* This is the default because then the user is able to "reconstruct" the true incident lepton's
* momentum using the recoil lepton and produced dark photon's three-momenta.
* Scaling the A' momentum is only advisable if the A' momentum _itself_ is important
* to the search (for example, when the A' decays visibly and the decay is observed
* in which case the A' momentum deciding where the decay occurs is very important).
*/
* This is the default because then the user is able to "reconstruct" the true
* incident lepton's momentum using the recoil lepton and produced dark
* photon's three-momenta. Scaling the A' momentum is only advisable if the A'
* momentum _itself_ is important to the search (for example, when the A'
* decays visibly and the decay is observed in which case the A' momentum
* deciding where the decay occurs is very important).
*/
bool scale_APrime_{false};

/**
* Minimum flight distance [mm] at which to decay the A'
* if G4APrime::DecayMode is set to FlatDecay
* Minimum flight distance [mm] at which to decay the A'
* if G4APrime::DecayMode is set to FlatDecay
*/
double dist_decay_min_{0.0};

/**
* Maximum flight distance [mm] at which to decay the A'
* if G4APrime::DecayMode is set to FlatDecay
* Maximum flight distance [mm] at which to decay the A'
* if G4APrime::DecayMode is set to FlatDecay
*/
double dist_decay_max_{1.0};

Expand Down
16 changes: 8 additions & 8 deletions src/G4DarkBreM/G4APrime.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

#include "G4DarkBreM/G4APrime.h"

#include "G4ParticleTable.hh"
#include "G4PhysicalConstants.hh"
#include "G4DecayTable.hh"
#include "G4ParticleTable.hh"
#include "G4PhaseSpaceDecayChannel.hh"
#include "G4PhysicalConstants.hh"
#include "globals.hh"

G4APrime* G4APrime::theAPrime = 0;
Expand All @@ -34,8 +34,8 @@ void G4APrime::Initialize(double mass, int id, double tau,

if (decay_mode == G4APrime::DecayMode::GeantDecay && tau < 0.0)
throw std::runtime_error(
"Invalid configuration: DecayMode set to GeantDecay but tau is negative."
);
"Invalid configuration: DecayMode set to GeantDecay but tau is "
"negative.");

G4APrime::decay_mode_ = decay_mode;

Expand All @@ -62,7 +62,7 @@ void G4APrime::Initialize(double mass, int id, double tau,
* lifetime | depends on DecayMode
* decay table | depends on DecayMode
*/

theAPrime = new G4APrime(
"A^1" /* short name */, mass * MeV, 0. /* mass width */,
0. /*electric charge */, 0 /* spin */, 0 /* parity */,
Expand All @@ -73,14 +73,14 @@ void G4APrime::Initialize(double mass, int id, double tau,

if (decay_mode != G4APrime::DecayMode::NoDecay) {
G4DecayTable* table = new G4DecayTable();
G4VDecayChannel* mode = new G4PhaseSpaceDecayChannel("A^1", 1.0, 2,
"e-", "e+");
G4VDecayChannel* mode =
new G4PhaseSpaceDecayChannel("A^1", 1.0, 2, "e-", "e+");
table->Insert(mode);

theAPrime->SetPDGStable(false);
theAPrime->SetPDGLifeTime(tau * second);
if (decay_mode == G4APrime::DecayMode::FlatDecay)
theAPrime->SetPDGLifeTime(0.0); // decay configured in G4DarkBreMModel
theAPrime->SetPDGLifeTime(0.0); // decay configured in G4DarkBreMModel
theAPrime->SetDecayTable(table);
}

Expand Down
31 changes: 16 additions & 15 deletions src/G4DarkBreM/G4DarkBreMModel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
#include "G4Electron.hh"
#include "G4EventManager.hh" //for EventID number
#include "G4MuonMinus.hh"
#include "G4PhaseSpaceDecayChannel.hh"
#include "G4PhysicalConstants.hh"
#include "G4RunManager.hh" //for VerboseLevel
#include "G4SystemOfUnits.hh"
#include "Randomize.hh"
#include "G4PhaseSpaceDecayChannel.hh"

// Boost
#include <boost/math/quadrature/gauss_kronrod.hpp>
Expand Down Expand Up @@ -402,13 +402,13 @@ G4double G4DarkBreMModel::ComputeCrossSectionPerAtom(G4double lepton_ke,
}

std::pair<G4ThreeVector, G4ThreeVector> G4DarkBreMModel::scale(
double target_Z, double incident_energy, double lepton_mass) {
double target_Z, double incident_energy, double lepton_mass) {
// mass A' in GeV
static const double MA = G4APrime::APrime()->GetPDGMass() / CLHEP::GeV;

OutgoingKinematics data = sample(target_Z, incident_energy);
double energy_factor = ((incident_energy - lepton_mass - MA) /
(data.E - lepton_mass - MA));
double energy_factor =
((incident_energy - lepton_mass - MA) / (data.E - lepton_mass - MA));
double EAcc = (data.lepton.e() - lepton_mass) * energy_factor + lepton_mass;
double Pt = data.lepton.perp();
double P = sqrt(EAcc * EAcc - lepton_mass * lepton_mass);
Expand All @@ -434,8 +434,8 @@ std::pair<G4ThreeVector, G4ThreeVector> G4DarkBreMModel::scale(
// Skip events until the transverse energy is less than the total energy.
i++;
data = sample(target_Z, incident_energy);
energy_factor = ((incident_energy - lepton_mass - MA) /
(data.E - lepton_mass - MA));
energy_factor =
((incident_energy - lepton_mass - MA) / (data.E - lepton_mass - MA));
EAcc = (data.lepton.e() - lepton_mass) * energy_factor + lepton_mass;
Pt = data.lepton.perp();
P = sqrt(EAcc * EAcc - lepton_mass * lepton_mass);
Expand Down Expand Up @@ -510,7 +510,7 @@ std::pair<G4ThreeVector, G4ThreeVector> G4DarkBreMModel::scale(
recoil.set(std::sin(ThetaAcc) * std::cos(PhiAcc),
std::sin(ThetaAcc) * std::sin(PhiAcc), std::cos(ThetaAcc));
recoil.setMag(recoilMag);

// outgoing A' momentum
G4ThreeVector aprime;
if (scale_APrime_) {
Expand All @@ -525,8 +525,9 @@ std::pair<G4ThreeVector, G4ThreeVector> G4DarkBreMModel::scale(
aprime.setMag(aPrimeMag);
} else {
// define A' momentum to be 3-momentum conserving with the recoil
double incident_momentum_mag = sqrt(incident_energy*incident_energy
- lepton_mass*lepton_mass) * GeV;
double incident_momentum_mag =
sqrt(incident_energy * incident_energy - lepton_mass * lepton_mass) *
GeV;
aprime = G4ThreeVector(0, 0, incident_momentum_mag) - recoil;
}
return std::make_pair(recoil, aprime);
Expand All @@ -542,8 +543,8 @@ void G4DarkBreMModel::GenerateChange(G4ParticleChange &particleChange,
G4double incidentEnergy =
step.GetPostStepPoint()->GetTotalEnergy() / CLHEP::GeV;

std::pair<G4ThreeVector, G4ThreeVector> outgoingMomenta
= scale(element.GetZ(), incidentEnergy, Ml);
std::pair<G4ThreeVector, G4ThreeVector> outgoingMomenta =
scale(element.GetZ(), incidentEnergy, Ml);
outgoingMomenta.first.rotateUz(track.GetMomentumDirection());
outgoingMomenta.second.rotateUz(track.GetMomentumDirection());
G4ThreeVector recoilMomentum = outgoingMomenta.first;
Expand All @@ -553,15 +554,15 @@ void G4DarkBreMModel::GenerateChange(G4ParticleChange &particleChange,
new G4DynamicParticle(G4APrime::APrime(), darkPhotonMomentum);

if (G4APrime::getDecayMode() == G4APrime::DecayMode::FlatDecay) {
double dist_decay = G4UniformRand() * (dist_decay_max_ - dist_decay_min_)
+ dist_decay_min_;
double dist_decay =
G4UniformRand() * (dist_decay_max_ - dist_decay_min_) + dist_decay_min_;
CLHEP::HepLorentzVector p4 = dphoton->Get4Momentum();
double tau_decay = dist_decay / p4.beta() / p4.gamma() / c_light;
dphoton->SetPreAssignedDecayProperTime(tau_decay);

dphoton->SetPreAssignedDecayProducts(
(new G4PhaseSpaceDecayChannel("A^1", 1.0, 2, "e-", "e+"))->
DecayIt(G4APrime::APrime()->G4APrime::APrime()->GetPDGMass()));
(new G4PhaseSpaceDecayChannel("A^1", 1.0, 2, "e-", "e+"))
->DecayIt(G4APrime::APrime()->G4APrime::APrime()->GetPDGMass()));
}

// stop tracking and create new secondary instead of primary
Expand Down
11 changes: 5 additions & 6 deletions src/G4DarkBreM/ParseLibrary.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,8 @@ void lhe(
if (ptype == aprime_lhe_id and state == 1) {
OutgoingKinematics evnt;
evnt.lepton = CLHEP::HepLorentzVector(e_px, e_py, e_pz, e_E);
evnt.centerMomentum =
CLHEP::HepLorentzVector(e_px + a_px, e_py + a_py, e_pz + a_pz,
e_E + a_E);
evnt.centerMomentum = CLHEP::HepLorentzVector(
e_px + a_px, e_py + a_py, e_pz + a_pz, e_E + a_E);
evnt.E = incident_energy;
if (target_Z < 0) {
throw std::runtime_error(
Expand Down Expand Up @@ -185,8 +184,8 @@ void csv(
int target_Z = vals[0]; // implicit drop of any decimal points
ok.E = vals[1];
ok.lepton = CLHEP::HepLorentzVector(vals[3], vals[4], vals[5], vals[2]);
ok.centerMomentum
= CLHEP::HepLorentzVector(vals[7], vals[8], vals[9], vals[6]);
ok.centerMomentum =
CLHEP::HepLorentzVector(vals[7], vals[8], vals[9], vals[6]);
lib[target_Z][ok.E].push_back(ok);
}
}
Expand All @@ -195,7 +194,7 @@ void csv(

void parseLibrary(
const std::string& path, int aprime_lhe_id,
std::map<int, std::map<double, std::vector<OutgoingKinematics>>>& lib) {
std::map<int, std::map<double, std::vector<OutgoingKinematics>>>& lib) {
if (hasEnding(path, ".csv") or hasEnding(path, ".csv.gz") or
hasEnding(path, ".lhe") or hasEnding(path, ".lhe.gz")) {
/**
Expand Down

0 comments on commit 28df268

Please sign in to comment.