CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GEMDigiProducer.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  : digiModelString_(ps.getParameter<std::string>("digiModelString"))
31 {
32  produces<GEMDigiCollection>();
33  produces<StripDigiSimLinks>("GEM");
34 
36  if (!rng.isAvailable()){
37  throw cms::Exception("Configuration")
38  << "GEMDigiProducer::GEMDigiProducer() - RandomNumberGeneratorService is not present in configuration file.\n"
39  << "Add the service in the configuration file or remove the modules that require it.";
40  }
41  gemDigiModel_ = GEMDigiModelFactory::get()->create("GEM" + digiModelString_ + "Model", ps);
42  LogDebug("GEMDigiProducer") << "Using GEM" + digiModelString_ + "Model";
43 
44  std::string mix_(ps.getParameter<std::string>("mixLabel"));
45  std::string collection_(ps.getParameter<std::string>("inputCollection"));
46 
47  cf_token = consumes<CrossingFrame<PSimHit> >(edm::InputTag(mix_, collection_));
48 }
49 
50 
52 {
53  delete gemDigiModel_;
54 }
55 
56 
57 void GEMDigiProducer::beginRun(const edm::Run&, const edm::EventSetup& eventSetup)
58 {
60  eventSetup.get<MuonGeometryRecord>().get(hGeom);
61  gemDigiModel_->setGeometry(&*hGeom);
63 }
64 
65 
67 {
69  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
70 
72  e.getByToken(cf_token, cf);
73 
74  std::auto_ptr<MixCollection<PSimHit> > hits(new MixCollection<PSimHit>(cf.product()));
75 
76  // Create empty output
77  std::auto_ptr<GEMDigiCollection> digis(new GEMDigiCollection());
78  std::auto_ptr<StripDigiSimLinks> stripDigiSimLinks(new StripDigiSimLinks() );
79 
80  // arrange the hits by eta partition
81  std::map<uint32_t, edm::PSimHitContainer> hitMap;
82  for(auto &hit: *hits){
83  hitMap[hit.detUnitId()].push_back(hit);
84  }
85 
86  // simulate signal and noise for each eta partition
87  const auto & etaPartitions(gemDigiModel_->getGeometry()->etaPartitions());
88 
89  for(auto &roll: etaPartitions){
90  const GEMDetId detId(roll->id());
91  const uint32_t rawId(detId.rawId());
92  const auto & simHits(hitMap[rawId]);
93 
94  LogDebug("GEMDigiProducer")
95  << "GEMDigiProducer: found " << simHits.size() << " hit(s) in eta partition" << rawId;
96 
97  gemDigiModel_->simulateSignal(roll, simHits, engine);
98  gemDigiModel_->simulateNoise(roll, engine);
99  gemDigiModel_->fillDigis(rawId, *digis);
100  (*stripDigiSimLinks).insert(gemDigiModel_->stripDigiSimLinks());
101  }
102 
103  // store them in the event
104  e.put(digis);
105  e.put(stripDigiSimLinks,"GEM");
106 }
107 
#define LogDebug(id)
T getParameter(std::string const &) const
void setGeometry(const GEMGeometry *geom)
Definition: GEMDigiModel.h:39
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
std::string digiModelString_
const GEMGeometry * getGeometry()
Definition: GEMDigiModel.h:41
virtual void simulateNoise(const GEMEtaPartition *, CLHEP::HepRandomEngine *engine)=0
edm::DetSetVector< StripDigiSimLink > StripDigiSimLinks
GEMDigiModel * gemDigiModel_
MuonDigiCollection< GEMDetId, GEMDigi > GEMDigiCollection
virtual void simulateSignal(const GEMEtaPartition *, const edm::PSimHitContainer &, CLHEP::HepRandomEngine *engine)=0
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
const StripDigiSimLinks & stripDigiSimLinks() const
Definition: GEMDigiModel.h:54
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
virtual void setup()=0
const std::vector< const GEMEtaPartition * > & etaPartitions() const
Return a vector of all GEM eta partitions.
Definition: GEMGeometry.cc:63
GEMDigiProducer(const edm::ParameterSet &ps)
edm::EDGetTokenT< CrossingFrame< PSimHit > > cf_token
T const * product() const
Definition: Handle.h:81
virtual ~GEMDigiProducer()
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
const T & get() const
Definition: EventSetup.h:56
tuple simHits
Definition: trackerHits.py:16
virtual void produce(edm::Event &, const edm::EventSetup &) override
StreamID streamID() const
Definition: Event.h:80
void fillDigis(int rollDetId, GEMDigiCollection &)
Definition: GEMDigiModel.cc:5
T get(const Candidate &c)
Definition: component.h:55
Definition: Run.h:43