CMS 3D CMS Logo

RPCDigiProducer.cc
Go to the documentation of this file.
20 #include <sstream>
21 #include <string>
22 
23 #include <map>
24 #include <vector>
25 
28 
29 //Random Number
33 #include "CLHEP/Random/RandFlat.h"
34 
35 namespace CLHEP {
36  class HepRandomEngine;
37 }
38 
40  produces<RPCDigiCollection>();
41  produces<RPCDigitizerSimLinks>("RPCDigiSimLink");
42 
43  //Name of Collection used for create the XF
44  mix_ = ps.getParameter<std::string>("mixLabel");
45  collection_for_XF = ps.getParameter<std::string>("InputCollection");
46 
48  if (!rng.isAvailable()) {
49  throw cms::Exception("Configuration")
50  << "RPCDigitizer requires the RandomNumberGeneratorService\n"
51  "which is not present in the configuration file. You must add the service\n"
52  "in the configuration file or remove the modules that require it.";
53  }
54  theRPCSimSetUp = new RPCSimSetUp(ps);
55  theDigitizer = new RPCDigitizer(ps);
56  crossingFrameToken = consumes<CrossingFrame<PSimHit>>(edm::InputTag(mix_, collection_for_XF));
57 }
58 
60  delete theDigitizer;
61  delete theRPCSimSetUp;
62 }
63 
64 void RPCDigiProducer::beginRun(const edm::Run& r, const edm::EventSetup& eventSetup) {
66  eventSetup.get<MuonGeometryRecord>().get(hGeom);
67  const RPCGeometry* pGeom = &*hGeom;
68 
70  eventSetup.get<RPCStripNoisesRcd>().get(noiseRcd);
71 
73  eventSetup.get<RPCClusterSizeRcd>().get(clsRcd);
74 
75  theRPCSimSetUp->setGeometry(pGeom);
76  theRPCSimSetUp->setRPCSetUp(noiseRcd->getVNoise(), clsRcd->getCls());
77  // theRPCSimSetUp->setRPCSetUp(noiseRcd->getVNoise(), noiseRcd->getCls());
78 
79  theDigitizer->setGeometry(pGeom);
80  // theRPCSimSetUp->setGeometry( pGeom );
81  theDigitizer->setRPCSimSetUp(theRPCSimSetUp);
82 }
83 
86  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
87 
88  LogDebug("RPCDigiProducer") << "[RPCDigiProducer::produce] got the CLHEP::HepRandomEngine engine from the "
89  "edm::Event.streamID() and edm::Service<edm::RandomNumberGenerator>";
90  LogDebug("RPCDigiProducer") << "[RPCDigiProducer::produce] test the CLHEP::HepRandomEngine by firing once RandFlat "
91  "---- this must be the first time in SimMuon/RPCDigitizer";
92  LogDebug("RPCDigiProducer")
93  << "[RPCDigiProducer::produce] to activate the test go in RPCDigiProducer.cc and uncomment the line below";
94  // LogDebug ("RPCDigiProducer")<<"[RPCDigiProducer::produce] Fired RandFlat :: "<<CLHEP::RandFlat::shoot(engine);
95 
97  // Obsolate code, based on getByLabel
98  // e.getByLabel(mix_, collection_for_XF, cf);
99  //New code, based on tokens
100  e.getByToken(crossingFrameToken, cf);
101 
102  std::unique_ptr<MixCollection<PSimHit>> hits(new MixCollection<PSimHit>(cf.product()));
103 
104  // Create empty output
105  std::unique_ptr<RPCDigiCollection> pDigis(new RPCDigiCollection());
106  std::unique_ptr<RPCDigitizerSimLinks> RPCDigitSimLink(new RPCDigitizerSimLinks());
107 
108  // run the digitizer
109  theDigitizer->doAction(*hits, *pDigis, *RPCDigitSimLink, engine);
110 
111  // store them in the event
112  e.put(std::move(pDigis));
113  e.put(std::move(RPCDigitSimLink), "RPCDigiSimLink");
114 }
#define LogDebug(id)
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
RPCDigiProducer(const edm::ParameterSet &ps)
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
MuonDigiCollection< RPCDetId, RPCDigi > RPCDigiCollection
std::vector< NoiseItem > const & getVNoise() const
T const * product() const
Definition: Handle.h:69
void produce(edm::Event &e, const edm::EventSetup &c) override
T get() const
Definition: EventSetup.h:73
StreamID streamID() const
Definition: Event.h:96
void beginRun(const edm::Run &, const edm::EventSetup &) override
std::vector< ClusterSizeItem > const & getCls() const
~RPCDigiProducer() override
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45