Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 
0002 #include "IOMC/RandomEngine/src/RandomFilter.h"
0003 
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/ServiceRegistry/interface/Service.h"
0007 #include "FWCore/Utilities/interface/Exception.h"
0008 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
0009 
0010 #include "CLHEP/Random/RandomEngine.h"
0011 
0012 using namespace edm;
0013 
0014 RandomFilter::RandomFilter(edm::ParameterSet const& ps) : acceptRate_(ps.getUntrackedParameter<double>("acceptRate")) {
0015   Service<RandomNumberGenerator> rng;
0016   if (!rng.isAvailable()) {
0017     throw cms::Exception("Configuration") << "RandomFilter requires the RandomNumberGeneratorService,\n"
0018                                              "which is not present in the configuration file.  You must add\n"
0019                                              "the service in the configuration file or remove the modules that\n"
0020                                              "require it.\n";
0021   }
0022 }
0023 
0024 RandomFilter::~RandomFilter() {}
0025 
0026 bool RandomFilter::filter(edm::Event& event, edm::EventSetup const&) {
0027   Service<RandomNumberGenerator> rng;
0028   CLHEP::HepRandomEngine& engine = rng->getEngine(event.streamID());
0029   if (engine.flat() < acceptRate_)
0030     return true;
0031   return false;
0032 }