Skip to content

Commit 2fed5e8

Browse files
authored
Merge pull request #1730 from michaelmackenzie/DIOSphereRange
Allow for restricted cos(theta_z) in DIO generation
2 parents 32f8cbc + 331511e commit 2fed5e8

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

EventGenerator/src/DIOGenerator_tool.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "art/Utilities/ToolMacros.h"
2+
#include "cetlib_except/exception.h"
23

34
#include "CLHEP/Random/RandPoissonQ.h"
45
#include "CLHEP/Random/RandGeneral.h"
@@ -22,15 +23,21 @@ namespace mu2e {
2223
using Name=fhicl::Name;
2324
using Comment=fhicl::Comment;
2425

26+
fhicl::Atom<double> czmin {Name("czmin") , Comment("Restrict cos(theta_z) minimum"), -1.};
27+
fhicl::Atom<double> czmax {Name("czmax") , Comment("Restrict cos(theta_z) maximum"), 1.};
2528
fhicl::DelegatedParameter spectrum{Name("spectrum"), Comment("Parameters for BinnedSpectrum)")};
2629
};
2730
typedef art::ToolConfigTable<PhysConfig> Parameters;
2831

2932
explicit DIOGenerator(Parameters const& conf) :
3033
_pdgId(PDGCode::e_minus),
3134
_mass(GlobalConstantsHandle<ParticleDataList>()->particle(_pdgId).mass()),
35+
_czmin(conf().czmin()),
36+
_czmax(conf().czmax()),
3237
_spectrum(BinnedSpectrum(conf().spectrum.get<fhicl::ParameterSet>()))
3338
{
39+
if(_czmin > _czmax || _czmin < -1. || _czmax > 1.) throw cet::exception("BADCONFIG") << "DIOGenerator cos(theta_z) range is not defined\n";
40+
3441
// compute normalization
3542
double integral(0.0);
3643
for(size_t ibin=0;ibin < _spectrum.getNbins();++ibin){
@@ -52,26 +59,31 @@ namespace mu2e {
5259
double pdfmin = _spectrum.getPDF(0);
5360
double binsize = _spectrum.getBinWidth();
5461
fullintegral += 0.5*pdfmin*pmin/binsize;
62+
std::cout << "Cos(theta_z) min " << _czmin << " max " << _czmax << std::endl;
5563
std::cout << "Restricted Spectrum min " << _spectrum.getAbscissa(0) << " max " << _spectrum.getAbscissa(_spectrum.getNbins()-1) << std::endl;
5664
std::cout << "Full Spectrum min " << fullspect.getAbscissa(0) << " max " << fullspect.getAbscissa(fullspect.getNbins()-1) << std::endl;
5765
std::cout << "Restricted Spectrum integral " << integral << std::endl;
66+
std::cout << "Restricted Spectrum integral*cos(theta_z) restriction " << integral*((_czmax - _czmin)/2.) << std::endl;
5867
std::cout << "Full Spectrum integral " << fullintegral << std::endl;
5968
std::cout << "Sampled spectrum fraction " << integral/fullintegral << std::endl;
69+
std::cout << "Sampled spectrum fraction (with cos(theta_z)) " << (integral/fullintegral)*((_czmax - _czmin)/2.) << std::endl;
6070

6171
}
6272

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

6676
void finishInitialization(art::RandomNumberGenerator::base_engine_t& eng, const std::string&) override {
67-
_randomUnitSphere = std::make_unique<RandomUnitSphere>(eng);
77+
_randomUnitSphere = std::make_unique<RandomUnitSphere>(eng, _czmin, _czmax);
6878
_randSpectrum = std::make_unique<CLHEP::RandGeneral>(eng, _spectrum.getPDF(), _spectrum.getNbins());
6979
}
7080

7181
private:
7282
PDGCode::type _pdgId;
7383
double _mass;
7484

85+
const double _czmin;
86+
const double _czmax;
7587
BinnedSpectrum _spectrum;
7688

7789
std::unique_ptr<RandomUnitSphere> _randomUnitSphere;

0 commit comments

Comments
 (0)