Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-22 02:39:44

0001 #include <iostream>
0002 #include <memory>
0003 
0004 #include "FWCore/Framework/interface/Run.h"
0005 #include "FWCore/ServiceRegistry/interface/Service.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
0008 #include "FWCore/Utilities/interface/Exception.h"
0009 
0010 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
0011 #include "SimDataFormats/GeneratorProducts/interface/GenRunInfoProduct.h"
0012 
0013 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
0014 
0015 #include "IOMC/ParticleGuns/interface/FlatBaseThetaGunProducer.h"
0016 
0017 using namespace edm;
0018 
0019 FlatBaseThetaGunProducer::FlatBaseThetaGunProducer(const edm::ParameterSet& pset)
0020     : fPDGTableToken(esConsumes<Transition::BeginRun>()), fEvt(nullptr) {
0021   edm::ParameterSet pgun_params = pset.getParameter<edm::ParameterSet>("PGunParameters");
0022 
0023   fPartIDs = pgun_params.getParameter<std::vector<int> >("PartID");
0024   fMinTheta = pgun_params.getParameter<double>("MinTheta");
0025   fMaxTheta = pgun_params.getParameter<double>("MaxTheta");
0026   fMinPhi = pgun_params.getParameter<double>("MinPhi");
0027   fMaxPhi = pgun_params.getParameter<double>("MaxPhi");
0028   fVerbosity = pset.getUntrackedParameter<int>("Verbosity", 0);
0029 
0030   fAddAntiParticle = pset.getParameter<bool>("AddAntiParticle");
0031 
0032   edm::Service<edm::RandomNumberGenerator> rng;
0033   if (!rng.isAvailable()) {
0034     throw cms::Exception("Configuration") << "The module inheriting from FlatBaseThetaGunProducer requires the\n"
0035                                              "RandomNumberGeneratorService, which appears to be absent.  Please\n"
0036                                              "add that service to your configuration or remove the modules that"
0037                                              "require it.";
0038   }
0039 
0040   produces<GenRunInfoProduct, Transition::EndRun>();
0041 }
0042 
0043 FlatBaseThetaGunProducer::~FlatBaseThetaGunProducer() {}
0044 
0045 void FlatBaseThetaGunProducer::beginRun(const edm::Run& r, const edm::EventSetup& es) {
0046   fPDGTable = es.getHandle(fPDGTableToken);
0047 }
0048 void FlatBaseThetaGunProducer::endRun(const Run& run, const EventSetup& es) {}
0049 
0050 void FlatBaseThetaGunProducer::endRunProduce(Run& run, const EventSetup& es) {
0051   // just create an empty product
0052   // to keep the EventContent definitions happy
0053   // later on we might put the info into the run info that this is a PGun
0054   std::unique_ptr<GenRunInfoProduct> genRunInfo(new GenRunInfoProduct());
0055   run.put(std::move(genRunInfo));
0056 }