Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-07 23:36:46

0001 // system include files
0002 #include <memory>
0003 // user include files
0004 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0005 #include "FWCore/Framework/interface/Frameworkfwd.h"
0006 
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 
0012 #include "FWCore/ServiceRegistry/interface/Service.h"
0013 #include "FWCore/Utilities/interface/Exception.h"
0014 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
0015 
0016 #include "SimGeneral/NoiseGenerators/interface/GaussianTailNoiseGenerator.h"
0017 
0018 #include <TFile.h>
0019 #include <TH1F.h>
0020 #include <TROOT.h>
0021 
0022 class GaussianTailNoiseGeneratorTest : public edm::one::EDAnalyzer<> {
0023 public:
0024   explicit GaussianTailNoiseGeneratorTest(const edm::ParameterSet &);
0025   ~GaussianTailNoiseGeneratorTest() override;
0026 
0027 private:
0028   void beginJob() override;
0029   void analyze(const edm::Event &, const edm::EventSetup &) override;
0030   void endJob() override;
0031   // ----------member data ---------------------------
0032   std::string filename_;
0033   TFile *hFile;
0034   TH1F *randNumber;
0035   GaussianTailNoiseGenerator *genNoise;
0036 };
0037 
0038 namespace CLHEP {
0039   class HepRandomEngine;
0040 }
0041 
0042 GaussianTailNoiseGeneratorTest::GaussianTailNoiseGeneratorTest(const edm::ParameterSet &iConfig)
0043     : filename_(iConfig.getParameter<std::string>("FileName")) {
0044   // now do what ever initialization is needed
0045   edm::Service<edm::RandomNumberGenerator> rng;
0046   if (!rng.isAvailable()) {
0047     throw cms::Exception("Configuration") << "GaussianTailNoiseGeneratorTest requires the "
0048                                              "RandomNumberGeneratorService\n"
0049                                              "which is not present in the configuration file.  You must add the "
0050                                              "service\n"
0051                                              "in the configuration file or remove the modules that require it.";
0052   }
0053   genNoise = new GaussianTailNoiseGenerator();
0054 }
0055 
0056 GaussianTailNoiseGeneratorTest::~GaussianTailNoiseGeneratorTest() { delete genNoise; }
0057 
0058 //
0059 // member functions
0060 //
0061 
0062 // ------------ method called to for each event  ------------
0063 void GaussianTailNoiseGeneratorTest::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0064   float threshold = 2.;
0065   int numStrips = 512;
0066   float noiseRMS = 5 * 250;
0067 
0068   std::vector<std::pair<int, float>> generatedNoise;
0069 
0070   edm::Service<edm::RandomNumberGenerator> rng;
0071   genNoise->generate(numStrips, threshold, noiseRMS, generatedNoise, &rng->getEngine(iEvent.streamID()));
0072 
0073   typedef std::vector<std::pair<int, float>>::const_iterator VI;
0074 
0075   for (VI p = generatedNoise.begin(); p != generatedNoise.end(); p++) {
0076     randNumber->Fill((*p).second);
0077   }
0078 }
0079 
0080 // ------------ method called once each job just before starting event loop
0081 // ------------
0082 void GaussianTailNoiseGeneratorTest::beginJob() {
0083   hFile = new TFile(filename_.c_str(), "RECREATE");
0084   randNumber = new TH1F("randNumber", "Random Number Distribution", 200, 2000, 6000);
0085 }
0086 
0087 // ------------ method called once each job just after ending the event loop
0088 // ------------
0089 void GaussianTailNoiseGeneratorTest::endJob() {
0090   hFile->Write();
0091   hFile->Close();
0092 
0093   return;
0094 }
0095 
0096 // define this as a plug-in
0097 DEFINE_FWK_MODULE(GaussianTailNoiseGeneratorTest);