Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:30:13

0001 // -*- C++ -*-
0002 //
0003 // Package:    SimMuon/DTDigitizer
0004 // Class:      DTChamberMasker
0005 //
0006 /**\class DTChamberMasker DTChamberMasker.cc
0007  SimMuon/DTDigitizer/plugins/DTChamberMasker.cc
0008 
0009  Description: Class to mask DT digis on a chamber by chamber basis
0010 
0011 */
0012 //
0013 // Original Author:  Carlo Battilana
0014 //         Created:  Sun, 11 Jan 2015 15:12:51 GMT
0015 //
0016 //
0017 
0018 // system include files
0019 #include <algorithm>
0020 #include <iostream>
0021 #include <map>
0022 #include <memory>
0023 #include <string>
0024 
0025 // user include files
0026 #include "FWCore/Framework/interface/ConsumesCollector.h"
0027 #include "FWCore/Framework/interface/Frameworkfwd.h"
0028 #include "FWCore/Framework/interface/stream/EDProducer.h"
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 
0031 #include "DataFormats/Common/interface/Handle.h"
0032 #include "FWCore/Framework/interface/Event.h"
0033 #include "FWCore/Framework/interface/Run.h"
0034 
0035 #include "FWCore/Framework/interface/ESHandle.h"
0036 #include "FWCore/Utilities/interface/ESGetToken.h"
0037 #include "FWCore/Framework/interface/EventSetup.h"
0038 
0039 #include "FWCore/Framework/interface/MakerMacros.h"
0040 
0041 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0042 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0043 
0044 #include "Geometry/DTGeometry/interface/DTChamber.h"
0045 #include "Geometry/DTGeometry/interface/DTLayer.h"
0046 
0047 #include "DataFormats/DTDigi/interface/DTDigiCollection.h"
0048 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
0049 #include "DataFormats/MuonDetId/interface/DTLayerId.h"
0050 #include "DataFormats/MuonDetId/interface/DTWireId.h"
0051 
0052 #include "CondFormats/DataRecord/interface/MuonSystemAgingRcd.h"
0053 #include "CondFormats/RecoMuonObjects/interface/MuonSystemAging.h"
0054 
0055 #include "CLHEP/Random/RandomEngine.h"
0056 #include "FWCore/ServiceRegistry/interface/Service.h"
0057 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
0058 
0059 //
0060 // class declaration
0061 //
0062 
0063 class DTChamberMasker : public edm::stream::EDProducer<> {
0064 public:
0065   explicit DTChamberMasker(const edm::ParameterSet &);
0066   ~DTChamberMasker() override;
0067 
0068   static void fillDescriptions(edm::ConfigurationDescriptions &);
0069 
0070 private:
0071   void produce(edm::Event &, const edm::EventSetup &) override;
0072 
0073   void beginRun(edm::Run const &, edm::EventSetup const &) override;
0074 
0075   void createMaskedChamberCollection(edm::ESHandle<DTGeometry> &);
0076 
0077   // ----------member data ---------------------------
0078 
0079   edm::EDGetTokenT<DTDigiCollection> m_digiToken;
0080   edm::ESGetToken<MuonSystemAging, MuonSystemAgingRcd> m_agingObjToken;
0081   std::map<unsigned int, float> m_ChEffs;
0082 };
0083 
0084 //
0085 // constants, enums and typedefs
0086 //
0087 
0088 //
0089 // constructors and destructor
0090 //
0091 DTChamberMasker::DTChamberMasker(const edm::ParameterSet &iConfig)
0092     : m_digiToken(consumes<DTDigiCollection>(iConfig.getParameter<edm::InputTag>("digiTag"))),
0093       m_agingObjToken(esConsumes<MuonSystemAging, MuonSystemAgingRcd>()) {
0094   produces<DTDigiCollection>();
0095 }
0096 
0097 DTChamberMasker::~DTChamberMasker() {}
0098 
0099 //
0100 // member functions
0101 //
0102 
0103 // ------------ method called to produce the data  ------------
0104 void DTChamberMasker::produce(edm::Event &event, const edm::EventSetup &conditions) {
0105   edm::Service<edm::RandomNumberGenerator> randGenService;
0106   CLHEP::HepRandomEngine &randGen = randGenService->getEngine(event.streamID());
0107 
0108   std::unique_ptr<DTDigiCollection> filteredDigis(new DTDigiCollection());
0109 
0110   if (!m_digiToken.isUninitialized()) {
0111     edm::Handle<DTDigiCollection> dtDigis;
0112     event.getByToken(m_digiToken, dtDigis);
0113 
0114     for (const auto &dtLayerId : (*dtDigis)) {
0115       uint32_t rawId = (dtLayerId.first).chamberId().rawId();
0116       auto chEffIt = m_ChEffs.find(rawId);
0117 
0118       if (chEffIt == m_ChEffs.end() || randGen.flat() <= chEffIt->second)
0119         filteredDigis->put(dtLayerId.second, dtLayerId.first);
0120     }
0121   }
0122 
0123   event.put(std::move(filteredDigis));
0124 }
0125 
0126 // ------------ method called when starting to processes a run  ------------
0127 void DTChamberMasker::beginRun(edm::Run const &run, edm::EventSetup const &iSetup) {
0128   m_ChEffs.clear();
0129 
0130   edm::ESHandle<MuonSystemAging> agingObj = iSetup.getHandle(m_agingObjToken);
0131 
0132   m_ChEffs = agingObj->m_DTChambEffs;
0133 }
0134 
0135 // ------------ method fills 'descriptions' with the allowed parameters for the
0136 // module  ------------
0137 void DTChamberMasker::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0138   edm::ParameterSetDescription desc;
0139   desc.add<edm::InputTag>("digiTag", edm::InputTag("simMuonDTDigis"));
0140   descriptions.add("dtChamberMasker", desc);
0141 }
0142 
0143 // define this as a plug-in
0144 DEFINE_FWK_MODULE(DTChamberMasker);