CMS 3D CMS Logo

ME0DigiProducer.cc
Go to the documentation of this file.
1 #ifndef SimMuon_GEMDigitizer_ME0DigiProducer_h
2 #define SimMuon_GEMDigitizer_ME0DigiProducer_h
3 
16 
23 
26 
29 
30 #include <sstream>
31 #include <string>
32 #include <map>
33 #include <vector>
34 
35 namespace CLHEP {
36  class HepRandomEngine;
37 }
38 
40 public:
42 
43  explicit ME0DigiProducer(const edm::ParameterSet& ps);
44 
45  ~ME0DigiProducer() override;
46 
47  void beginRun(const edm::Run&, const edm::EventSetup&) override;
48 
49  void produce(edm::Event&, const edm::EventSetup&) override;
50 
51 private:
52  //Name of Collection used for create the XF
55 
56  std::unique_ptr<ME0DigiModel> ME0DigiModel_;
57 };
58 
60  : ME0DigiModel_{
61  ME0DigiModelFactory::get()->create("ME0" + ps.getParameter<std::string>("digiModelString") + "Model", ps)} {
62  produces<ME0DigiCollection>();
63  produces<ME0DigiSimLinks>("ME0");
64 
66  if (!rng.isAvailable()) {
67  throw cms::Exception("Configuration")
68  << "ME0DigiProducer::ME0DigiProducer() - RandomNumberGeneratorService is not present in configuration file.\n"
69  << "Add the service in the configuration file or remove the modules that require it.";
70  }
71 
72  LogDebug("ME0DigiProducer") << "Using ME0" + ps.getParameter<std::string>("digiModelString") + "Model";
73 
74  std::string mix_(ps.getParameter<std::string>("mixLabel"));
75  std::string collection_(ps.getParameter<std::string>("inputCollection"));
76 
77  cf_token = consumes<CrossingFrame<PSimHit> >(edm::InputTag(mix_, collection_));
78  geom_token_ = esConsumes<ME0Geometry, MuonGeometryRecord, edm::Transition::BeginRun>();
79 }
80 
82 
85  ME0DigiModel_->setGeometry(&*hGeom);
86  ME0DigiModel_->setup();
87 }
88 
91  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
92 
94  e.getByToken(cf_token, cf);
95 
97 
98  // Create empty output
99  auto digis = std::make_unique<ME0DigiCollection>();
100  auto me0DigiSimLinks = std::make_unique<ME0DigiSimLinks>();
101 
102  // arrange the hits by eta partition
103  std::map<uint32_t, edm::PSimHitContainer> hitMap;
104  for (const auto& hit : hits) {
105  hitMap[hit.detUnitId()].emplace_back(hit);
106  }
107 
108  // simulate signal and noise for each eta partition
109  const auto& etaPartitions(ME0DigiModel_->getGeometry()->etaPartitions());
110 
111  for (const auto& roll : etaPartitions) {
112  const ME0DetId detId(roll->id());
113  const uint32_t rawId(detId.rawId());
114  const auto& simHits(hitMap[rawId]);
115 
116  LogDebug("ME0DigiProducer") << "ME0DigiProducer: found " << simHits.size() << " hit(s) in eta partition" << rawId;
117 
118  ME0DigiModel_->simulateSignal(roll, simHits, engine);
119  ME0DigiModel_->simulateNoise(roll, engine);
120  ME0DigiModel_->fillDigis(rawId, *digis);
121  (*me0DigiSimLinks).insert(ME0DigiModel_->me0DigiSimLinks());
122  }
123 
124  // store them in the event
125  e.put(std::move(digis));
126  e.put(std::move(me0DigiSimLinks), "ME0");
127 }
128 
130 #endif
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void beginRun(const edm::Run &, const edm::EventSetup &) override
T const * product() const
Definition: Handle.h:70
ME0DigiProducer(const edm::ParameterSet &ps)
std::unique_ptr< ME0DigiModel > ME0DigiModel_
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
edm::ESGetToken< ME0Geometry, MuonGeometryRecord > geom_token_
~ME0DigiProducer() override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::DetSetVector< ME0DigiSimLink > ME0DigiSimLinks
edm::EDGetTokenT< CrossingFrame< PSimHit > > cf_token
#define get
void produce(edm::Event &, const edm::EventSetup &) override
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45
#define LogDebug(id)