CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RPCDigiProducer.cc
Go to the documentation of this file.
17 #include <sstream>
18 #include <string>
19 
20 #include <map>
21 #include <vector>
22 
25 
26 //Random Number
30 #include "CLHEP/Random/RandFlat.h"
31 
32 namespace CLHEP {
33  class HepRandomEngine;
34 }
35 
37  produces<RPCDigiCollection>();
38  produces<RPCDigitizerSimLinks>("RPCDigiSimLink");
39 
40  //Name of Collection used for create the XF
41  mix_ = ps.getParameter<std::string>("mixLabel");
42  collection_for_XF = ps.getParameter<std::string>("InputCollection");
43 
45  if (!rng.isAvailable()) {
46  throw cms::Exception("Configuration")
47  << "RPCDigitizer requires the RandomNumberGeneratorService\n"
48  "which is not present in the configuration file. You must add the service\n"
49  "in the configuration file or remove the modules that require it.";
50  }
51  theRPCSimSetUp = new RPCSimSetUp(ps);
52  theDigitizer = new RPCDigitizer(ps);
53  crossingFrameToken = consumes<CrossingFrame<PSimHit>>(edm::InputTag(mix_, collection_for_XF));
54  geomToken = esConsumes<RPCGeometry, MuonGeometryRecord, edm::Transition::BeginRun>();
55  noiseToken = esConsumes<RPCStripNoises, RPCStripNoisesRcd, edm::Transition::BeginRun>();
56  clsToken = esConsumes<RPCClusterSize, RPCClusterSizeRcd, edm::Transition::BeginRun>();
57 }
58 
60  delete theDigitizer;
61  delete theRPCSimSetUp;
62 }
63 
64 void RPCDigiProducer::beginRun(const edm::Run& r, const edm::EventSetup& eventSetup) {
66  const RPCGeometry* pGeom = &*hGeom;
67 
68  edm::ESHandle<RPCStripNoises> noiseRcd = eventSetup.getHandle(noiseToken);
69 
71 
73  theRPCSimSetUp->setRPCSetUp(noiseRcd->getVNoise(), clsRcd->getCls());
74  // theRPCSimSetUp->setRPCSetUp(noiseRcd->getVNoise(), noiseRcd->getCls());
75 
76  theDigitizer->setGeometry(pGeom);
77  // theRPCSimSetUp->setGeometry( pGeom );
79 }
80 
83  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
84 
85  LogDebug("RPCDigiProducer") << "[RPCDigiProducer::produce] got the CLHEP::HepRandomEngine engine from the "
86  "edm::Event.streamID() and edm::Service<edm::RandomNumberGenerator>";
87  LogDebug("RPCDigiProducer") << "[RPCDigiProducer::produce] test the CLHEP::HepRandomEngine by firing once RandFlat "
88  "---- this must be the first time in SimMuon/RPCDigitizer";
89  LogDebug("RPCDigiProducer")
90  << "[RPCDigiProducer::produce] to activate the test go in RPCDigiProducer.cc and uncomment the line below";
91  // LogDebug ("RPCDigiProducer")<<"[RPCDigiProducer::produce] Fired RandFlat :: "<<CLHEP::RandFlat::shoot(engine);
92 
94  // Obsolate code, based on getByLabel
95  // e.getByLabel(mix_, collection_for_XF, cf);
96  //New code, based on tokens
98 
99  std::unique_ptr<MixCollection<PSimHit>> hits(new MixCollection<PSimHit>(cf.product()));
100 
101  // Create empty output
102  std::unique_ptr<RPCDigiCollection> pDigis(new RPCDigiCollection());
103  std::unique_ptr<RPCDigitizerSimLinks> RPCDigitSimLink(new RPCDigitizerSimLinks());
104 
105  // run the digitizer
106  theDigitizer->doAction(*hits, *pDigis, *RPCDigitSimLink, engine);
107 
108  // store them in the event
109  e.put(std::move(pDigis));
110  e.put(std::move(RPCDigitSimLink), "RPCDigiSimLink");
111 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
std::string mix_
std::string collection_for_XF
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
edm::ESGetToken< RPCGeometry, MuonGeometryRecord > geomToken
RPCDigiProducer(const edm::ParameterSet &ps)
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
void setGeometry(const RPCGeometry *geom)
sets geometry
Definition: RPCDigitizer.h:46
void setGeometry(const RPCGeometry *geom)
sets geometry
Definition: RPCSimSetUp.h:47
RPCSimSetUp * theRPCSimSetUp
edm::ESGetToken< RPCStripNoises, RPCStripNoisesRcd > noiseToken
void setRPCSimSetUp(RPCSimSetUp *simsetup)
Definition: RPCDigitizer.h:48
MuonDigiCollection< RPCDetId, RPCDigi > RPCDigiCollection
def move
Definition: eostools.py:511
void doAction(MixCollection< PSimHit > &simHits, RPCDigiCollection &rpcDigis, RPCDigiSimLinks &rpcDigiSimLink, CLHEP::HepRandomEngine *)
Definition: RPCDigitizer.cc:19
T const * product() const
Definition: Handle.h:70
edm::ESGetToken< RPCClusterSize, RPCClusterSizeRcd > clsToken
RPCDigitizer::RPCDigiSimLinks RPCDigitizerSimLinks
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void produce(edm::Event &e, const edm::EventSetup &c) override
StreamID streamID() const
Definition: Event.h:98
void beginRun(const edm::Run &, const edm::EventSetup &) override
RPCDigitizer * theDigitizer
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
~RPCDigiProducer() override
void setRPCSetUp(const std::vector< RPCStripNoises::NoiseItem > &vnoise, const std::vector< float > &vcls)
Definition: RPCSimSetUp.cc:42
Definition: Run.h:45
edm::EDGetTokenT< CrossingFrame< PSimHit > > crossingFrameToken
#define LogDebug(id)