Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion EventGenerator/inc/ParticleGeneratorTool.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ namespace mu2e {
CLHEP::HepLorentzVector fourmom;
};

virtual void finishInitialization(art::RandomNumberGenerator::base_engine_t& eng, const std::string& materialName) = 0;
virtual void finishInitialization(art::RandomNumberGenerator::base_engine_t& eng, const std::string& materialName,
const bool isPrimary) = 0;

virtual std::vector<Kinematic> generate() = 0;

// This interface should be removed when we retire ntuple-based muon resampling
virtual void generate(std::unique_ptr<GenParticleCollection>& out, const IO::StoppedParticleF& stop) = 0;

virtual ~ParticleGeneratorTool() noexcept = default;

bool _isPrimary = true; // flag to indicate if this is for primary generation or not
};
}

Expand Down
22 changes: 14 additions & 8 deletions EventGenerator/src/DIOGenerator_tool.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "art/Utilities/ToolMacros.h"
#include "cetlib_except/exception.h"

#include "CLHEP/Random/RandPoissonQ.h"
#include "CLHEP/Random/RandGeneral.h"
#include "CLHEP/Random/RandFlat.h"

#include "Offline/EventGenerator/inc/ParticleGeneratorTool.hh"

Expand Down Expand Up @@ -73,9 +73,11 @@ namespace mu2e {
std::vector<ParticleGeneratorTool::Kinematic> generate() override;
void generate(std::unique_ptr<GenParticleCollection>& out, const IO::StoppedParticleF& stop) override;

void finishInitialization(art::RandomNumberGenerator::base_engine_t& eng, const std::string&) override {
void finishInitialization(art::RandomNumberGenerator::base_engine_t& eng, const std::string&, const bool isPrimary) override {
_isPrimary = isPrimary;
_randomUnitSphere = std::make_unique<RandomUnitSphere>(eng, _czmin, _czmax);
_randSpectrum = std::make_unique<CLHEP::RandGeneral>(eng, _spectrum.getPDF(), _spectrum.getNbins());
_randFlat = std::make_unique<CLHEP::RandFlat>(eng);
}

private:
Expand All @@ -88,20 +90,24 @@ namespace mu2e {

std::unique_ptr<RandomUnitSphere> _randomUnitSphere;
std::unique_ptr<CLHEP::RandGeneral> _randSpectrum;
std::unique_ptr<CLHEP::RandFlat> _randFlat;
};


std::vector<ParticleGeneratorTool::Kinematic> DIOGenerator::generate() {
std::vector<ParticleGeneratorTool::Kinematic> res;
const double r = (_czmax - _czmin)/2.;
if(_isPrimary || _randFlat->fire() <= r) {

double energy = _spectrum.sample(_randSpectrum->fire());
double energy = _spectrum.sample(_randSpectrum->fire());

const double p = energy * sqrt(1 - std::pow(_mass/energy,2));
CLHEP::Hep3Vector p3 = _randomUnitSphere->fire(p);
CLHEP::HepLorentzVector fourmom(p3, energy);
const double p = energy * sqrt(1 - std::pow(_mass/energy,2));
CLHEP::Hep3Vector p3 = _randomUnitSphere->fire(p);
CLHEP::HepLorentzVector fourmom(p3, energy);

ParticleGeneratorTool::Kinematic k{_pdgId, ProcessCode::mu2eMuonDecayAtRest, fourmom};
res.emplace_back(k);
ParticleGeneratorTool::Kinematic k{_pdgId, ProcessCode::mu2eMuonDecayAtRest, fourmom};
res.emplace_back(k);
}

return res;
}
Expand Down
3 changes: 2 additions & 1 deletion EventGenerator/src/Mu2eXGenerator_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ namespace mu2e {
std::vector<ParticleGeneratorTool::Kinematic> generate() override;
void generate(std::unique_ptr<GenParticleCollection>& out, const IO::StoppedParticleF& stop) override;

void finishInitialization(art::RandomNumberGenerator::base_engine_t& eng, const std::string&) override {
void finishInitialization(art::RandomNumberGenerator::base_engine_t& eng, const std::string&, const bool isPrimary) override {
_isPrimary = isPrimary;
_randomUnitSphere = std::make_unique<RandomUnitSphere>(eng);
_randSpectrum = std::make_unique<CLHEP::RandGeneral>(eng, _spectrum.getPDF(), _spectrum.getNbins());
}
Expand Down
9 changes: 4 additions & 5 deletions EventGenerator/src/MuCap1809keVGammaGenerator_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ namespace mu2e {
using Comment=fhicl::Comment;
fhicl::Atom<double> czMin {Name("czmin") , Comment("Restrict cos(theta_z) minimum"), -1.};
fhicl::Atom<double> czMax {Name("czmax") , Comment("Restrict cos(theta_z) maximum"), 1.};
fhicl::Atom<bool> fireAll{Name("fireAll"), Comment("Add a photon to all events, otherwise use the branching fraction"), false};
};
typedef art::ToolConfigTable<PhysConfig> Parameters;

explicit MuCap1809keVGammaGenerator(Parameters const& conf) :
_czMin(conf().czMin()),
_czMax(conf().czMax()),
_fireAll(conf().fireAll()),
_pdgId(PDGCode::gamma),
_mass(GlobalConstantsHandle<ParticleDataList>()->particle(_pdgId).mass()),
_randomUnitSphere(nullptr),
Expand All @@ -39,7 +37,8 @@ namespace mu2e {
std::vector<ParticleGeneratorTool::Kinematic> generate() override;
void generate(std::unique_ptr<GenParticleCollection>& out, const IO::StoppedParticleF& stop) override;

void finishInitialization(art::RandomNumberGenerator::base_engine_t& eng, const std::string& material) override {
void finishInitialization(art::RandomNumberGenerator::base_engine_t& eng, const std::string& material, const bool isPrimary) override {
_isPrimary = isPrimary;
_energy = GlobalConstantsHandle<PhysicsParams>()->get1809keVGammaEnergy(material);
_intensity = GlobalConstantsHandle<PhysicsParams>()->get1809keVGammaIntensity(material);
_randomUnitSphere = std::make_unique<RandomUnitSphere>(eng, _czMin, _czMax);
Expand All @@ -49,7 +48,6 @@ namespace mu2e {
private:
double _czMin;
double _czMax;
bool _fireAll;
PDGCode::type _pdgId;
double _mass;
double _energy = 0.;
Expand All @@ -62,7 +60,8 @@ namespace mu2e {
std::vector<ParticleGeneratorTool::Kinematic> MuCap1809keVGammaGenerator::generate() {
std::vector<ParticleGeneratorTool::Kinematic> res;

if (_fireAll || _randFlat->fire() < _intensity) {
const double intensity = _intensity * (_czMax - _czMin)/2.; // account for potential cz selection in the intensity
if (_isPrimary || _randFlat->fire() < intensity) {
const double momentum = _energy * sqrt(1 - std::pow(_mass/_energy,2));
CLHEP::Hep3Vector p3 = _randomUnitSphere->fire(momentum);
CLHEP::HepLorentzVector fourmom(p3, _energy);
Expand Down
24 changes: 18 additions & 6 deletions EventGenerator/src/MuCapDeuteronGenerator_tool.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "art/Utilities/ToolMacros.h"
#include "cetlib_except/exception.h"

#include "CLHEP/Random/RandPoissonQ.h"
#include "CLHEP/Random/RandGeneral.h"
Expand All @@ -25,23 +26,32 @@ namespace mu2e {

fhicl::DelegatedParameter spectrum{Name("spectrum"), Comment("Parameters for BinnedSpectrum)")};
fhicl::Atom<std::string> spectrumVariable{Name("spectrumVariable"), Comment("Variable that spectrum is defined in (\"totalEnergy\", \"kineticEnergy\", or \"momentum\")")};
fhicl::Atom<double> czMin{Name("czmin"), Comment("Restrict cos(theta_z) minimum"), -1.};
fhicl::Atom<double> czMax{Name("czmax"), Comment("Restrict cos(theta_z) maximum"), 1.};

};
typedef art::ToolConfigTable<PhysConfig> Parameters;

explicit MuCapDeuteronGenerator(Parameters const& conf) :
_pdgId(PDGCode::deuteron),
_mass(GlobalConstantsHandle<ParticleDataList>()->particle(_pdgId).mass()),
_spectrum(BinnedSpectrum(conf().spectrum.get<fhicl::ParameterSet>())),
_spectrumVariable(parseSpectrumVar(conf().spectrumVariable()))
{}
_spectrumVariable(parseSpectrumVar(conf().spectrumVariable())),
_czMin(conf().czMin()),
_czMax(conf().czMax())
{
if(_czMin < -1. || _czMax > 1. || _czMin > _czMax) throw cet::exception("BADCONFIG") << "Cos(theta_z) range unphysical: " << _czMin << " - " << _czMax;
}

std::vector<ParticleGeneratorTool::Kinematic> generate() override;
void generate(std::unique_ptr<GenParticleCollection>& out, const IO::StoppedParticleF& stop) override;

void finishInitialization(art::RandomNumberGenerator::base_engine_t& eng, const std::string& material) override {
void finishInitialization(art::RandomNumberGenerator::base_engine_t& eng, const std::string& material, const bool isPrimary) override {
_isPrimary = isPrimary;
_rate = GlobalConstantsHandle<PhysicsParams>()->getCaptureDeuteronRate(material);
_randomUnitSphere = std::make_unique<RandomUnitSphere>(eng);
_randomPoissonQ = std::make_unique<CLHEP::RandPoissonQ>(eng, _rate);
const double rate = _rate * (_czMax - _czMin)/2.; // accouunt for potential cz selection in the produced rates
_randomUnitSphere = std::make_unique<RandomUnitSphere>(eng, _czMin, _czMax);
_randomPoissonQ = std::make_unique<CLHEP::RandPoissonQ>(eng, rate);
_randSpectrum = std::make_unique<CLHEP::RandGeneral>(eng, _spectrum.getPDF(), _spectrum.getNbins());
}

Expand All @@ -52,6 +62,8 @@ namespace mu2e {

BinnedSpectrum _spectrum;
SpectrumVar _spectrumVariable;
double _czMin;
double _czMax;

std::unique_ptr<CLHEP::RandPoissonQ> _randomPoissonQ;
std::unique_ptr<RandomUnitSphere> _randomUnitSphere;
Expand All @@ -62,7 +74,7 @@ namespace mu2e {
std::vector<ParticleGeneratorTool::Kinematic> MuCapDeuteronGenerator::generate() {
std::vector<ParticleGeneratorTool::Kinematic> res;

int n_gen = _randomPoissonQ->fire();
const int n_gen = (_isPrimary) ? 1 : _randomPoissonQ->fire();
for (int i_gen = 0; i_gen < n_gen; ++i_gen) {
double energy = _spectrum.sample(_randSpectrum->fire());

Expand Down
23 changes: 17 additions & 6 deletions EventGenerator/src/MuCapNeutronGenerator_tool.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "art/Utilities/ToolMacros.h"
#include "cetlib_except/exception.h"

#include "CLHEP/Random/RandPoissonQ.h"
#include "CLHEP/Random/RandGeneral.h"
Expand All @@ -25,23 +26,31 @@ namespace mu2e {

fhicl::DelegatedParameter spectrum{Name("spectrum"), Comment("Parameters for BinnedSpectrum)")};
fhicl::Atom<std::string> spectrumVariable{Name("spectrumVariable"), Comment("Variable that spectrum is defined in (\"totalEnergy\", \"kineticEnergy\", or \"momentum\")")};
fhicl::Atom<double> czMin{Name("czmin"), Comment("Restrict cos(theta_z) minimum"), -1.};
fhicl::Atom<double> czMax{Name("czmax"), Comment("Restrict cos(theta_z) maximum"), 1.};
};
typedef art::ToolConfigTable<PhysConfig> Parameters;

explicit MuCapNeutronGenerator(Parameters const& conf) :
_pdgId(PDGCode::n0),
_mass(GlobalConstantsHandle<ParticleDataList>()->particle(_pdgId).mass()),
_spectrum(BinnedSpectrum(conf().spectrum.get<fhicl::ParameterSet>())),
_spectrumVariable(parseSpectrumVar(conf().spectrumVariable()))
{}
_spectrumVariable(parseSpectrumVar(conf().spectrumVariable())),
_czMin(conf().czMin()),
_czMax(conf().czMax())
{
if(_czMin < -1. || _czMax > 1. || _czMin > _czMax) throw cet::exception("BADCONFIG") << "Cos(theta_z) range unphysical: " << _czMin << " - " << _czMax;
}

std::vector<ParticleGeneratorTool::Kinematic> generate() override;
void generate(std::unique_ptr<GenParticleCollection>& out, const IO::StoppedParticleF& stop) override;

void finishInitialization(art::RandomNumberGenerator::base_engine_t& eng, const std::string& material) override {
void finishInitialization(art::RandomNumberGenerator::base_engine_t& eng, const std::string& material, const bool isPrimary) override {
_isPrimary = isPrimary;
_rate = GlobalConstantsHandle<PhysicsParams>()->getCaptureNeutronRate(material);
_randomUnitSphere = std::make_unique<RandomUnitSphere>(eng);
_randomPoissonQ = std::make_unique<CLHEP::RandPoissonQ>(eng, _rate);
const double rate = _rate * (_czMax - _czMin)/2.; // accouunt for potential cz selection in the produced rates
_randomUnitSphere = std::make_unique<RandomUnitSphere>(eng, _czMin, _czMax);
_randomPoissonQ = std::make_unique<CLHEP::RandPoissonQ>(eng, rate);
_randSpectrum = std::make_unique<CLHEP::RandGeneral>(eng, _spectrum.getPDF(), _spectrum.getNbins());
}

Expand All @@ -52,6 +61,8 @@ namespace mu2e {

BinnedSpectrum _spectrum;
SpectrumVar _spectrumVariable;
double _czMin;
double _czMax;

std::unique_ptr<CLHEP::RandPoissonQ> _randomPoissonQ;
std::unique_ptr<RandomUnitSphere> _randomUnitSphere;
Expand All @@ -61,7 +72,7 @@ namespace mu2e {
std::vector<ParticleGeneratorTool::Kinematic> MuCapNeutronGenerator::generate() {
std::vector<ParticleGeneratorTool::Kinematic> res;

int n_gen = _randomPoissonQ->fire();
const int n_gen = (_isPrimary) ? 1 : _randomPoissonQ->fire();
for (int i_gen = 0; i_gen < n_gen; ++i_gen) {
double energy = _spectrum.sample(_randSpectrum->fire());

Expand Down
23 changes: 17 additions & 6 deletions EventGenerator/src/MuCapPhotonGenerator_tool.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "art/Utilities/ToolMacros.h"
#include "cetlib_except/exception.h"

#include "CLHEP/Random/RandPoissonQ.h"
#include "CLHEP/Random/RandGeneral.h"
Expand All @@ -22,27 +23,37 @@ namespace mu2e {
using Comment=fhicl::Comment;

fhicl::DelegatedParameter spectrum{Name("spectrum"), Comment("Parameters for BinnedSpectrum)")};
fhicl::Atom<double> czMin{Name("czmin"), Comment("Restrict cos(theta_z) minimum"), -1.};
fhicl::Atom<double> czMax{Name("czmax"), Comment("Restrict cos(theta_z) maximum"), 1.};
};
typedef art::ToolConfigTable<PhysConfig> Parameters;

explicit MuCapPhotonGenerator(Parameters const& conf) :
_spectrum(BinnedSpectrum(conf().spectrum.get<fhicl::ParameterSet>()))
{}
_spectrum(BinnedSpectrum(conf().spectrum.get<fhicl::ParameterSet>())),
_czMin(conf().czMin()),
_czMax(conf().czMax())
{
if(_czMin < -1. || _czMax > 1. || _czMin > _czMax) throw cet::exception("BADCONFIG") << "Cos(theta_z) range unphysical: " << _czMin << " - " << _czMax;
}

std::vector<ParticleGeneratorTool::Kinematic> generate() override;
void generate(std::unique_ptr<GenParticleCollection>& out, const IO::StoppedParticleF& stop) override;

void finishInitialization(art::RandomNumberGenerator::base_engine_t& eng, const std::string& material) override {
void finishInitialization(art::RandomNumberGenerator::base_engine_t& eng, const std::string& material, const bool isPrimary) override {
_isPrimary = isPrimary;
_rate = GlobalConstantsHandle<PhysicsParams>()->getCapturePhotonRate(material);
_randomUnitSphere = std::make_unique<RandomUnitSphere>(eng);
_randomPoissonQ = std::make_unique<CLHEP::RandPoissonQ>(eng, _rate);
const double rate = _rate * (_czMax - _czMin)/2.; // accouunt for potential cz selection in the produced rates
_randomUnitSphere = std::make_unique<RandomUnitSphere>(eng, _czMin, _czMax);
_randomPoissonQ = std::make_unique<CLHEP::RandPoissonQ>(eng, rate);
_randSpectrum = std::make_unique<CLHEP::RandGeneral>(eng, _spectrum.getPDF(), _spectrum.getNbins());
}

private:
double _rate = 0.;

BinnedSpectrum _spectrum;
double _czMin;
double _czMax;

std::unique_ptr<CLHEP::RandPoissonQ> _randomPoissonQ;
std::unique_ptr<RandomUnitSphere> _randomUnitSphere;
Expand All @@ -53,7 +64,7 @@ namespace mu2e {
std::vector<ParticleGeneratorTool::Kinematic> MuCapPhotonGenerator::generate() {
std::vector<ParticleGeneratorTool::Kinematic> res;

int n_gen = _randomPoissonQ->fire();
const int n_gen = (_isPrimary) ? 1 : _randomPoissonQ->fire();
for (int i_gen = 0; i_gen < n_gen; ++i_gen) {
double energy = _spectrum.sample(_randSpectrum->fire());
const double p = energy;
Expand Down
23 changes: 17 additions & 6 deletions EventGenerator/src/MuCapProtonGenerator_tool.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "art/Utilities/ToolMacros.h"
#include "cetlib_except/exception.h"

#include "CLHEP/Random/RandPoissonQ.h"
#include "CLHEP/Random/RandGeneral.h"
Expand All @@ -25,23 +26,31 @@ namespace mu2e {

fhicl::DelegatedParameter spectrum{Name("spectrum"), Comment("Parameters for BinnedSpectrum)")};
fhicl::Atom<std::string> spectrumVariable{Name("spectrumVariable"), Comment("Variable that spectrum is defined in (\"totalEnergy\", \"kineticEnergy\", or \"momentum\")")};
fhicl::Atom<double> czMin{Name("czmin"), Comment("Restrict cos(theta_z) minimum"), -1.};
fhicl::Atom<double> czMax{Name("czmax"), Comment("Restrict cos(theta_z) maximum"), 1.};
};
typedef art::ToolConfigTable<PhysConfig> Parameters;

explicit MuCapProtonGenerator(Parameters const& conf) :
_pdgId(PDGCode::proton),
_mass(GlobalConstantsHandle<ParticleDataList>()->particle(_pdgId).mass()),
_spectrum(BinnedSpectrum(conf().spectrum.get<fhicl::ParameterSet>())),
_spectrumVariable(parseSpectrumVar(conf().spectrumVariable()))
{}
_spectrumVariable(parseSpectrumVar(conf().spectrumVariable())),
_czMin(conf().czMin()),
_czMax(conf().czMax())
{
if(_czMin < -1. || _czMax > 1. || _czMin > _czMax) throw cet::exception("BADCONFIG") << "Cos(theta_z) range unphysical: " << _czMin << " - " << _czMax;
}

std::vector<ParticleGeneratorTool::Kinematic> generate() override;
void generate(std::unique_ptr<GenParticleCollection>& out, const IO::StoppedParticleF& stop) override;

void finishInitialization(art::RandomNumberGenerator::base_engine_t& eng, const std::string& material) override {
void finishInitialization(art::RandomNumberGenerator::base_engine_t& eng, const std::string& material, const bool isPrimary) override {
_isPrimary = isPrimary;
_rate = GlobalConstantsHandle<PhysicsParams>()->getCaptureProtonRate(material);
_randomUnitSphere = std::make_unique<RandomUnitSphere>(eng);
_randomPoissonQ = std::make_unique<CLHEP::RandPoissonQ>(eng, _rate);
const double rate = _rate * (_czMax - _czMin)/2.; // accouunt for potential cz selection in the produced rates
_randomUnitSphere = std::make_unique<RandomUnitSphere>(eng, _czMin, _czMax);
_randomPoissonQ = std::make_unique<CLHEP::RandPoissonQ>(eng, rate);
_randSpectrum = std::make_unique<CLHEP::RandGeneral>(eng, _spectrum.getPDF(), _spectrum.getNbins());
}

Expand All @@ -52,6 +61,8 @@ namespace mu2e {

BinnedSpectrum _spectrum;
SpectrumVar _spectrumVariable;
double _czMin;
double _czMax;

std::unique_ptr<CLHEP::RandPoissonQ> _randomPoissonQ;
std::unique_ptr<RandomUnitSphere> _randomUnitSphere;
Expand All @@ -61,7 +72,7 @@ namespace mu2e {
std::vector<ParticleGeneratorTool::Kinematic> MuCapProtonGenerator::generate() {
std::vector<ParticleGeneratorTool::Kinematic> res;

int n_gen = _randomPoissonQ->fire();
const int n_gen = (_isPrimary) ? 1 : _randomPoissonQ->fire();
for (int i_gen = 0; i_gen < n_gen; ++i_gen) {
double energy = _spectrum.sample(_randSpectrum->fire());

Expand Down
4 changes: 2 additions & 2 deletions EventGenerator/src/MuStopProductsGun_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ namespace mu2e {
const auto cap_psets = conf_.captureProducts.get<std::vector<fhicl::ParameterSet>>();
for (const auto& i_cap_pset : cap_psets) {
_muonCaptureGenerators.push_back(art::make_tool<ParticleGeneratorTool>(i_cap_pset));
_muonCaptureGenerators.back()->finishInitialization(eng_, material_);
_muonCaptureGenerators.back()->finishInitialization(eng_, material_, false);
}
const auto decay_psets = conf_.decayProducts.get<std::vector<fhicl::ParameterSet>>();
for (const auto& i_decay_pset : decay_psets) {
_muonDecayGenerators.push_back(art::make_tool<ParticleGeneratorTool>(i_decay_pset));
_muonDecayGenerators.back()->finishInitialization(eng_, material_);
_muonDecayGenerators.back()->finishInitialization(eng_, material_, false);
}
}

Expand Down
3 changes: 2 additions & 1 deletion EventGenerator/src/MuplusMichelGenerator_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ namespace mu2e {
std::vector<ParticleGeneratorTool::Kinematic> generate() override;
void generate(std::unique_ptr<GenParticleCollection>& out, const IO::StoppedParticleF& stop) override;

void finishInitialization(art::RandomNumberGenerator::base_engine_t& eng, const std::string&) override {
void finishInitialization(art::RandomNumberGenerator::base_engine_t& eng, const std::string&, const bool isPrimary) override {
_isPrimary = isPrimary;
_randomUnitSphere = std::make_unique<RandomUnitSphere>(eng);
_randSpectrum = std::make_unique<CLHEP::RandGeneral>(eng, _spectrum.getPDF(), _spectrum.getNbins());
}
Expand Down
Loading