Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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