CMS 3D CMS Logo

ME0DigiPreRecoProducer.cc
Go to the documentation of this file.
9 
13 
16 
17 #include <sstream>
18 #include <string>
19 #include <map>
20 #include <vector>
21 
22 namespace CLHEP {
23  class HepRandomEngine;
24 }
25 
27  : digiPreRecoModelString_(ps.getParameter<std::string>("digiPreRecoModelString"))
28 {
29  produces<ME0DigiPreRecoCollection>();
30 
32  if (!rng.isAvailable()){
33  throw cms::Exception("Configuration")
34  << "ME0DigiPreRecoProducer::ME0PreRecoDigiProducer() - RandomNumberGeneratorService is not present in configuration file.\n"
35  << "Add the service in the configuration file or remove the modules that require it.";
36  }
38  LogDebug("ME0DigiPreRecoProducer") << "Using ME0" + digiPreRecoModelString_ + "Model";
39 
40  std::string mix_(ps.getParameter<std::string>("mixLabel"));
41  std::string collection_(ps.getParameter<std::string>("inputCollection"));
42 
43  cf_token = consumes<CrossingFrame<PSimHit> >(edm::InputTag(mix_, collection_));
44 }
45 
46 
48 {
49  delete me0DigiPreRecoModel_;
50 }
51 
52 
54 {
55  // set geometry
57  eventSetup.get<MuonGeometryRecord>().get(hGeom);
60 }
61 
62 
64 {
66  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
67 
69  e.getByToken(cf_token, cf);
70 
71  std::unique_ptr<MixCollection<PSimHit> > hits( new MixCollection<PSimHit>(cf.product()) );
72 
73  // Create empty output
74  std::unique_ptr<ME0DigiPreRecoCollection> digis(new ME0DigiPreRecoCollection());
75 
76  // arrange the hits by eta partition
77  std::map<uint32_t, edm::PSimHitContainer> hitMap;
78  for(auto &hit: *hits){
79  hitMap[hit.detUnitId()].push_back(hit);
80  }
81 
82  // simulate signal and noise for each eta partition
83  const auto & etaPartitions(me0DigiPreRecoModel_->getGeometry()->etaPartitions());
84 
85  for(auto &roll: etaPartitions){
86  const ME0DetId detId(roll->id());
87  const uint32_t rawId(detId.rawId());
88  const auto & simHits(hitMap[rawId]);
89 
90  LogDebug("ME0DigiPreRecoProducer")
91  << "ME0DigiPreRecoProducer: found " << simHits.size() << " hit(s) in eta partition" << rawId;
92 
93  me0DigiPreRecoModel_->simulateSignal(roll, simHits, engine);
94  me0DigiPreRecoModel_->simulateNoise(roll, engine);
95  me0DigiPreRecoModel_->fillDigis(rawId, *digis);
96  }
97 
98  // store them in the event
99  e.put(std::move(digis));
100 }
101 
#define LogDebug(id)
virtual void setup()=0
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
void fillDigis(int rollDetId, ME0DigiPreRecoCollection &)
ME0DigiPreRecoModel * me0DigiPreRecoModel_
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
ME0DigiPreRecoProducer(const edm::ParameterSet &ps)
void setGeometry(const ME0Geometry *geom)
MuonDigiCollection< ME0DetId, ME0DigiPreReco > ME0DigiPreRecoCollection
virtual void simulateNoise(const ME0EtaPartition *, CLHEP::HepRandomEngine *engine)=0
const ME0Geometry * getGeometry()
virtual void simulateSignal(const ME0EtaPartition *, const edm::PSimHitContainer &, CLHEP::HepRandomEngine *engine)=0
virtual void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< CrossingFrame< PSimHit > > cf_token
const std::vector< ME0EtaPartition const * > & etaPartitions() const
Return a vector of all ME0 eta partitions.
Definition: ME0Geometry.cc:59
T const * product() const
Definition: Handle.h:81
const T & get() const
Definition: EventSetup.h:56
StreamID streamID() const
Definition: Event.h:81
def move(src, dest)
Definition: eostools.py:510
T get(const Candidate &c)
Definition: component.h:55
Definition: Run.h:42