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