@@ -34,7 +34,8 @@ namespace mu2e {
3434 _mass(GlobalConstantsHandle<ParticleDataList>()->particle(_pdgId).mass()),
3535 _czmin(conf().czmin()),
3636 _czmax(conf().czmax()),
37- _spectrum(BinnedSpectrum(conf().spectrum.get<fhicl::ParameterSet>()))
37+ _spectrum(BinnedSpectrum(conf().spectrum.get<fhicl::ParameterSet>())),
38+ _flatSpectrum(conf().spectrum.get<fhicl::ParameterSet>().get<std::string>(" spectrumShape" , " " ) == "flat")
3839 {
3940 if (_czmin > _czmax || _czmin < -1 . || _czmax > 1 .) throw cet::exception (" BADCONFIG" ) << " DIOGenerator cos(theta_z) range is not defined\n " ;
4041
@@ -45,6 +46,8 @@ namespace mu2e {
4546 }
4647
4748 auto fullconfig = conf ().spectrum .get <fhicl::ParameterSet>();
49+ _emin = fullconfig.get <double >(" elow" , _spectrum.getXMin ());
50+ _emax = fullconfig.get <double >(" ehi" , _spectrum.getXMax ());
4851 fullconfig.erase (std::string (" elow" ));
4952 fullconfig.erase (std::string (" ehi" ));
5053 fullconfig.put (std::string (" elow" ),double (0.0 ));
@@ -59,6 +62,7 @@ namespace mu2e {
5962 double pdfmin = _spectrum.getPDF (0 );
6063 double binsize = _spectrum.getBinWidth ();
6164 fullintegral += 0.5 *pdfmin*pmin/binsize;
65+ _energy_fraction = (fullintegral > 0 .) ? integral / fullintegral : 0 .;
6266 std::cout << " Cos(theta_z) min " << _czmin << " max " << _czmax << std::endl;
6367 std::cout << " Restricted Spectrum min " << _spectrum.getAbscissa (0 ) << " max " << _spectrum.getAbscissa (_spectrum.getNbins ()-1 ) << std::endl;
6468 std::cout << " Full Spectrum min " << fullspect.getAbscissa (0 ) << " max " << fullspect.getAbscissa (fullspect.getNbins ()-1 ) << std::endl;
@@ -72,6 +76,7 @@ namespace mu2e {
7276
7377 std::vector<ParticleGeneratorTool::Kinematic> generate () override ;
7478 void generate (std::unique_ptr<GenParticleCollection>& out, const IO ::StoppedParticleF& stop) override ;
79+ std::unique_ptr<SpectrumConfig> spectrumConfig () override ;
7580
7681 void finishInitialization (art::RandomNumberGenerator::base_engine_t & eng, const std::string&, const bool isPrimary) override {
7782 _isPrimary = isPrimary;
@@ -87,6 +92,10 @@ namespace mu2e {
8792 const double _czmin;
8893 const double _czmax;
8994 BinnedSpectrum _spectrum;
95+ double _emin;
96+ double _emax;
97+ double _energy_fraction;
98+ bool _flatSpectrum;
9099
91100 std::unique_ptr<RandomUnitSphere> _randomUnitSphere;
92101 std::unique_ptr<CLHEP ::RandGeneral> _randSpectrum;
@@ -124,5 +133,13 @@ namespace mu2e {
124133 }
125134 }
126135
136+ std::unique_ptr<SpectrumConfig> DIOGenerator::spectrumConfig () {
137+ auto config = std::make_unique<SpectrumConfig>();
138+ config->add_var (SpectrumConfig::RestrictedVar (" energy" , _energy_fraction , _emin , _emax,
139+ _flatSpectrum ? SpectrumConfig::Type::kFlat : SpectrumConfig::Type::kPhysical ));
140+ config->add_var (SpectrumConfig::RestrictedVar (" cosz" , (_czmax - _czmin)/2 ., _czmin, _czmax));
141+ return config;
142+ }
143+
127144}
128145DEFINE_ART_CLASS_TOOL (mu2e::DIOGenerator)
0 commit comments