File indexing completed on 2024-04-06 12:19:01
0001
0002
0003
0004
0005 #include "IOMC/EventVertexGenerators/interface/BaseEvtVtxGenerator.h"
0006
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009
0010 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
0011 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
0012
0013 #include "FWCore/ServiceRegistry/interface/Service.h"
0014 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
0015
0016 #include "FWCore/Utilities/interface/Exception.h"
0017
0018 #include "DataFormats/Provenance/interface/Provenance.h"
0019 #include "FWCore/Utilities/interface/EDMException.h"
0020
0021
0022
0023
0024
0025 using namespace edm;
0026 using namespace CLHEP;
0027
0028
0029 BaseEvtVtxGenerator::BaseEvtVtxGenerator(const ParameterSet& pset) {
0030 Service<RandomNumberGenerator> rng;
0031 if (!rng.isAvailable()) {
0032 throw cms::Exception("Configuration") << "The BaseEvtVtxGenerator requires the RandomNumberGeneratorService\n"
0033 "which is not present in the configuration file. \n"
0034 "You must add the service\n"
0035 "in the configuration file or remove the modules that require it.";
0036 }
0037
0038 sourceToken = consumes<edm::HepMCProduct>(pset.getParameter<edm::InputTag>("src"));
0039 produces<edm::HepMCProduct>();
0040 }
0041
0042 BaseEvtVtxGenerator::~BaseEvtVtxGenerator() {}
0043
0044 void BaseEvtVtxGenerator::produce(Event& evt, const EventSetup&) {
0045 edm::Service<edm::RandomNumberGenerator> rng;
0046 CLHEP::HepRandomEngine* engine = &rng->getEngine(evt.streamID());
0047
0048 Handle<HepMCProduct> HepUnsmearedMCEvt;
0049
0050 evt.getByToken(sourceToken, HepUnsmearedMCEvt);
0051
0052
0053 HepMC::GenEvent* genevt = new HepMC::GenEvent(*HepUnsmearedMCEvt->GetEvent());
0054 std::unique_ptr<edm::HepMCProduct> HepMCEvt(new edm::HepMCProduct(genevt));
0055
0056
0057 HepMCEvt->applyVtxGen(newVertex(engine));
0058
0059
0060 HepMCEvt->boostToLab(GetInvLorentzBoost(), "vertex");
0061 HepMCEvt->boostToLab(GetInvLorentzBoost(), "momentum");
0062
0063 evt.put(std::move(HepMCEvt));
0064
0065 return;
0066 }