CMS 3D CMS Logo

ME0DigiProducer.cc
Go to the documentation of this file.
12 
16 
19 
20 #include <sstream>
21 #include <string>
22 #include <map>
23 #include <vector>
24 
25 namespace CLHEP {
26  class HepRandomEngine;
27 }
28 
30  : ME0DigiModel_{ME0DigiModelFactory::get()->create("ME0" + ps.getParameter<std::string>("digiModelString") + "Model",
31  ps)}
32 {
33  produces<ME0DigiCollection>();
34  produces<StripDigiSimLinks>("ME0");
35  produces<ME0DigiSimLinks>("ME0");
36 
38  if (!rng.isAvailable()){
39  throw cms::Exception("Configuration")
40  << "ME0DigiProducer::ME0DigiProducer() - RandomNumberGeneratorService is not present in configuration file.\n"
41  << "Add the service in the configuration file or remove the modules that require it.";
42  }
43 
44  LogDebug("ME0DigiProducer") << "Using ME0" + ps.getParameter<std::string>("digiModelString") + "Model";
45 
46  std::string mix_(ps.getParameter<std::string>("mixLabel"));
47  std::string collection_(ps.getParameter<std::string>("inputCollection"));
48 
49  cf_token = consumes<CrossingFrame<PSimHit> >(edm::InputTag(mix_, collection_));
50 }
51 
52 
54 
55 
56 void ME0DigiProducer::beginRun(const edm::Run&, const edm::EventSetup& eventSetup)
57 {
59  eventSetup.get<MuonGeometryRecord>().get(hGeom);
60  ME0DigiModel_->setGeometry(&*hGeom);
61  ME0DigiModel_->setup();
62 }
63 
64 
66 {
68  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
69 
71  e.getByToken(cf_token, cf);
72 
74 
75  // Create empty output
76  auto digis = std::make_unique<ME0DigiCollection>();
77  auto stripDigiSimLinks = std::make_unique<StripDigiSimLinks>();
78  auto me0DigiSimLinks = std::make_unique<ME0DigiSimLinks>();
79 
80  // arrange the hits by eta partition
81  std::map<uint32_t, edm::PSimHitContainer> hitMap;
82  for (const auto& hit: hits){
83  hitMap[hit.detUnitId()].emplace_back(hit);
84  }
85 
86  // simulate signal and noise for each eta partition
87  const auto & etaPartitions(ME0DigiModel_->getGeometry()->etaPartitions());
88 
89  for (const auto& roll: etaPartitions){
90  const ME0DetId detId(roll->id());
91  const uint32_t rawId(detId.rawId());
92  const auto & simHits(hitMap[rawId]);
93 
94  LogDebug("ME0DigiProducer")
95  << "ME0DigiProducer: found " << simHits.size() << " hit(s) in eta partition" << rawId;
96 
97  ME0DigiModel_->simulateSignal(roll, simHits, engine);
98  ME0DigiModel_->simulateNoise(roll, engine);
99  ME0DigiModel_->fillDigis(rawId, *digis);
100  (*stripDigiSimLinks).insert(ME0DigiModel_->stripDigiSimLinks());
101  (*me0DigiSimLinks).insert(ME0DigiModel_->me0DigiSimLinks());
102  }
103 
104  // store them in the event
105  e.put(std::move(digis));
106  e.put(std::move(stripDigiSimLinks),"ME0");
107  e.put(std::move(me0DigiSimLinks),"ME0");
108 }
109 
#define LogDebug(id)
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
void beginRun(const edm::Run &, const edm::EventSetup &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
ME0DigiProducer(const edm::ParameterSet &ps)
std::unique_ptr< ME0DigiModel > ME0DigiModel_
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
~ME0DigiProducer() override
T const * product() const
Definition: Handle.h:74
T get() const
Definition: EventSetup.h:71
StreamID streamID() const
Definition: Event.h:95
edm::EDGetTokenT< CrossingFrame< PSimHit > > cf_token
void produce(edm::Event &, const edm::EventSetup &) override
def move(src, dest)
Definition: eostools.py:511
T get(const Candidate &c)
Definition: component.h:55
Definition: Run.h:45