Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:07

0001 
0002 /*
0003 */
0004 
0005 #include "IOMC/EventVertexGenerators/interface/PassThroughEvtVtxGenerator.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 //#include "HepMC/GenEvent.h"
0022 // #include "CLHEP/Vector/ThreeVector.h"
0023 // #include "HepMC/SimpleVector.h"
0024 
0025 using namespace edm;
0026 using namespace CLHEP;
0027 //using namespace HepMC;
0028 
0029 PassThroughEvtVtxGenerator::PassThroughEvtVtxGenerator(const ParameterSet& pset) : BaseEvtVtxGenerator(pset) {
0030   Service<RandomNumberGenerator> rng;
0031   if (!rng.isAvailable()) {
0032     throw cms::Exception("Configuration")
0033         << "The PassThroughEvtVtxGenerator requires the RandomNumberGeneratorService\n"
0034            "which is not present in the configuration file. \n"
0035            "You must add the service\n"
0036            "in the configuration file or remove the modules that require it.";
0037   }
0038   sourceToken = consumes<edm::HepMCProduct>(pset.getParameter<edm::InputTag>("src"));
0039 }
0040 
0041 PassThroughEvtVtxGenerator::~PassThroughEvtVtxGenerator() {}
0042 
0043 HepMC::FourVector PassThroughEvtVtxGenerator::newVertex(CLHEP::HepRandomEngine*) const {
0044   return HepMC::FourVector(0., 0., 0., 0);
0045 }
0046 
0047 void PassThroughEvtVtxGenerator::produce(Event& evt, const EventSetup&) {
0048   edm::Service<edm::RandomNumberGenerator> rng;
0049 
0050   Handle<HepMCProduct> HepUnsmearedMCEvt;
0051 
0052   evt.getByToken(sourceToken, HepUnsmearedMCEvt);
0053 
0054   // Copy the HepMC::GenEvent
0055   HepMC::GenEvent* genevt = new HepMC::GenEvent(*HepUnsmearedMCEvt->GetEvent());
0056   std::unique_ptr<edm::HepMCProduct> HepMCEvt(new edm::HepMCProduct(genevt));
0057 
0058   evt.put(std::move(HepMCEvt));
0059 
0060   return;
0061 }