Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:30:49

0001 #include "SimMuon/RPCDigitizer/src/RPCSimSetUp.h"
0002 #include "SimMuon/RPCDigitizer/src/RPCDigiProducer.h"
0003 #include "SimMuon/RPCDigitizer/src/RPCDigitizer.h"
0004 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0005 #include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
0006 #include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
0007 #include "DataFormats/Common/interface/Handle.h"
0008 #include "FWCore/Framework/interface/ESHandle.h"
0009 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0010 #include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
0011 #include "FWCore/Framework/interface/Event.h"
0012 #include "FWCore/Framework/interface/EventSetup.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0015 #include "SimMuon/RPCDigitizer/src/RPCSynchronizer.h"
0016 #include <sstream>
0017 #include <string>
0018 
0019 #include <map>
0020 #include <vector>
0021 
0022 #include "FWCore/Framework/interface/MakerMacros.h"
0023 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
0024 
0025 //Random Number
0026 #include "FWCore/ServiceRegistry/interface/Service.h"
0027 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
0028 #include "FWCore/Utilities/interface/Exception.h"
0029 #include "CLHEP/Random/RandFlat.h"
0030 
0031 namespace CLHEP {
0032   class HepRandomEngine;
0033 }
0034 
0035 RPCDigiProducer::RPCDigiProducer(const edm::ParameterSet& ps) {
0036   produces<RPCDigiCollection>();
0037   produces<RPCDigitizerSimLinks>("RPCDigiSimLink");
0038 
0039   //Name of Collection used for create the XF
0040   mix_ = ps.getParameter<std::string>("mixLabel");
0041   collection_for_XF = ps.getParameter<std::string>("InputCollection");
0042 
0043   edm::Service<edm::RandomNumberGenerator> rng;
0044   if (!rng.isAvailable()) {
0045     throw cms::Exception("Configuration")
0046         << "RPCDigitizer requires the RandomNumberGeneratorService\n"
0047            "which is not present in the configuration file.  You must add the service\n"
0048            "in the configuration file or remove the modules that require it.";
0049   }
0050   theRPCSimSetUp = new RPCSimSetUp(ps);
0051   theDigitizer = new RPCDigitizer(ps);
0052   crossingFrameToken = consumes<CrossingFrame<PSimHit>>(edm::InputTag(mix_, collection_for_XF));
0053   geomToken = esConsumes<RPCGeometry, MuonGeometryRecord, edm::Transition::BeginRun>();
0054   noiseToken = esConsumes<RPCStripNoises, RPCStripNoisesRcd, edm::Transition::BeginRun>();
0055   clsToken = esConsumes<RPCClusterSize, RPCClusterSizeRcd, edm::Transition::BeginRun>();
0056 }
0057 
0058 RPCDigiProducer::~RPCDigiProducer() {
0059   delete theDigitizer;
0060   delete theRPCSimSetUp;
0061 }
0062 
0063 void RPCDigiProducer::beginRun(const edm::Run& r, const edm::EventSetup& eventSetup) {
0064   edm::ESHandle<RPCGeometry> hGeom = eventSetup.getHandle(geomToken);
0065   const RPCGeometry* pGeom = &*hGeom;
0066 
0067   edm::ESHandle<RPCStripNoises> noiseRcd = eventSetup.getHandle(noiseToken);
0068 
0069   edm::ESHandle<RPCClusterSize> clsRcd = eventSetup.getHandle(clsToken);
0070 
0071   theRPCSimSetUp->setGeometry(pGeom);
0072   theRPCSimSetUp->setRPCSetUp(noiseRcd->getVNoise(), clsRcd->getCls());
0073   //    theRPCSimSetUp->setRPCSetUp(noiseRcd->getVNoise(), noiseRcd->getCls());
0074 
0075   theDigitizer->setGeometry(pGeom);
0076   // theRPCSimSetUp->setGeometry( pGeom );
0077   theDigitizer->setRPCSimSetUp(theRPCSimSetUp);
0078 }
0079 
0080 void RPCDigiProducer::produce(edm::Event& e, const edm::EventSetup& eventSetup) {
0081   edm::Service<edm::RandomNumberGenerator> rng;
0082   CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
0083 
0084   LogDebug("RPCDigiProducer") << "[RPCDigiProducer::produce] got the CLHEP::HepRandomEngine engine from the "
0085                                  "edm::Event.streamID() and edm::Service<edm::RandomNumberGenerator>";
0086   LogDebug("RPCDigiProducer") << "[RPCDigiProducer::produce] test the CLHEP::HepRandomEngine by firing once RandFlat "
0087                                  "---- this must be the first time in SimMuon/RPCDigitizer";
0088   LogDebug("RPCDigiProducer")
0089       << "[RPCDigiProducer::produce] to activate the test go in RPCDigiProducer.cc and uncomment the line below";
0090   // LogDebug ("RPCDigiProducer")<<"[RPCDigiProducer::produce] Fired RandFlat :: "<<CLHEP::RandFlat::shoot(engine);
0091 
0092   // Obsolate code, based on getByLabel
0093   //  e.getByLabel(mix_, collection_for_XF, cf);
0094   //New code, based on tokens
0095   const edm::Handle<CrossingFrame<PSimHit>>& cf = e.getHandle(crossingFrameToken);
0096 
0097   std::unique_ptr<MixCollection<PSimHit>> hits(new MixCollection<PSimHit>(cf.product()));
0098 
0099   // Create empty output
0100   std::unique_ptr<RPCDigiCollection> pDigis(new RPCDigiCollection());
0101   std::unique_ptr<RPCDigitizerSimLinks> RPCDigitSimLink(new RPCDigitizerSimLinks());
0102 
0103   // run the digitizer
0104   theDigitizer->doAction(*hits, *pDigis, *RPCDigitSimLink, engine);
0105 
0106   // store them in the event
0107   e.put(std::move(pDigis));
0108   e.put(std::move(RPCDigitSimLink), "RPCDigiSimLink");
0109 }