Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:53:39

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