CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ME0DigiPreRecoProducer.cc
Go to the documentation of this file.
1 #ifndef SimMuon_GEMDigitizer_ME0DigiPreRecoProducer_h
2 #define SimMuon_GEMDigitizer_ME0DigiPreRecoProducer_h
3 
16 
21 
24 
27 
28 #include <sstream>
29 #include <string>
30 #include <map>
31 #include <vector>
32 
33 namespace CLHEP {
34  class HepRandomEngine;
35 }
36 
38 public:
39  explicit ME0DigiPreRecoProducer(const edm::ParameterSet& ps);
40 
41  ~ME0DigiPreRecoProducer() override;
42 
43  void beginRun(const edm::Run&, const edm::EventSetup&) override;
44 
45  void produce(edm::Event&, const edm::EventSetup&) override;
46 
47 private:
48  //Name of Collection used for create the XF
51 
53  std::unique_ptr<ME0DigiPreRecoModel> me0DigiPreRecoModel_;
54 };
55 
57  : digiPreRecoModelString_(ps.getParameter<std::string>("digiPreRecoModelString")),
58  me0DigiPreRecoModel_{ME0DigiPreRecoModelFactory::get()->create("ME0" + digiPreRecoModelString_ + "Model", ps)} {
59  produces<ME0DigiPreRecoCollection>();
60 
62  if (!rng.isAvailable()) {
63  throw cms::Exception("Configuration")
64  << "ME0DigiPreRecoProducer::ME0PreRecoDigiProducer() - RandomNumberGeneratorService is not present in "
65  "configuration file.\n"
66  << "Add the service in the configuration file or remove the modules that require it.";
67  }
68  LogDebug("ME0DigiPreRecoProducer") << "Using ME0" + digiPreRecoModelString_ + "Model";
69 
70  std::string mix_(ps.getParameter<std::string>("mixLabel"));
71  std::string collection_(ps.getParameter<std::string>("inputCollection"));
72 
73  cf_token = consumes<CrossingFrame<PSimHit> >(edm::InputTag(mix_, collection_));
74  geom_token_ = esConsumes<ME0Geometry, MuonGeometryRecord, edm::Transition::BeginRun>();
75 }
76 
78 
80  // set geometry
82  me0DigiPreRecoModel_->setGeometry(&*hGeom);
83  me0DigiPreRecoModel_->setup();
84 }
85 
88  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
89 
91  e.getByToken(cf_token, cf);
92 
94 
95  // Create empty output
96  auto digis = std::make_unique<ME0DigiPreRecoCollection>();
97 
98  // arrange the hits by eta partition
99  std::map<uint32_t, edm::PSimHitContainer> hitMap;
100  for (const auto& hit : hits) {
101  hitMap[hit.detUnitId()].push_back(hit);
102  }
103 
104  // simulate signal and noise for each eta partition
105  const auto& etaPartitions(me0DigiPreRecoModel_->getGeometry()->etaPartitions());
106 
107  for (const auto& roll : etaPartitions) {
108  const ME0DetId detId(roll->id());
109  const uint32_t rawId(detId.rawId());
110  const auto& simHits(hitMap[rawId]);
111 
112  LogDebug("ME0DigiPreRecoProducer") << "ME0DigiPreRecoProducer: found " << simHits.size()
113  << " hit(s) in eta partition" << rawId;
114 
115  me0DigiPreRecoModel_->simulateSignal(roll, simHits, engine);
116  me0DigiPreRecoModel_->simulateNoise(roll, engine);
117  me0DigiPreRecoModel_->fillDigis(rawId, *digis);
118  }
119 
120  // store them in the event
121  e.put(std::move(digis));
122 }
123 
125 #endif
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::unique_ptr< ME0DigiPreRecoModel > me0DigiPreRecoModel_
void beginRun(const edm::Run &, const edm::EventSetup &) override
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
ME0DigiPreRecoProducer(const edm::ParameterSet &ps)
def move
Definition: eostools.py:511
~ME0DigiPreRecoProducer() override
void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< CrossingFrame< PSimHit > > cf_token
T const * product() const
Definition: Handle.h:70
tuple simHits
Definition: trackerHits.py:16
edm::ESGetToken< ME0Geometry, MuonGeometryRecord > geom_token_
StreamID streamID() const
Definition: Event.h:98
#define get
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
Definition: Run.h:45
#define LogDebug(id)