Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:30:43

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/global/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::global::EDProducer<> {
0064 public:
0065   explicit DTChamberMasker(const edm::ParameterSet &);
0066 
0067   static void fillDescriptions(edm::ConfigurationDescriptions &);
0068 
0069 private:
0070   void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;
0071 
0072   void createMaskedChamberCollection(edm::ESHandle<DTGeometry> &);
0073 
0074   // ----------member data ---------------------------
0075 
0076   const edm::EDGetTokenT<DTDigiCollection> m_digiToken;
0077   const edm::EDPutTokenT<DTDigiCollection> m_putToken;
0078   const edm::ESGetToken<MuonSystemAging, MuonSystemAgingRcd> m_agingObjToken;
0079 };
0080 
0081 //
0082 // constants, enums and typedefs
0083 //
0084 
0085 //
0086 // constructors and destructor
0087 //
0088 DTChamberMasker::DTChamberMasker(const edm::ParameterSet &iConfig)
0089     : m_digiToken(consumes(iConfig.getParameter<edm::InputTag>("digiTag"))),
0090       m_putToken(produces()),
0091       m_agingObjToken(esConsumes()) {}
0092 
0093 //
0094 // member functions
0095 //
0096 
0097 // ------------ method called to produce the data  ------------
0098 void DTChamberMasker::produce(edm::StreamID, edm::Event &event, const edm::EventSetup &conditions) const {
0099   edm::Service<edm::RandomNumberGenerator> randGenService;
0100   CLHEP::HepRandomEngine &randGen = randGenService->getEngine(event.streamID());
0101 
0102   MuonSystemAging const &agingObj = conditions.getData(m_agingObjToken);
0103 
0104   auto const &chEffs = agingObj.m_DTChambEffs;
0105 
0106   DTDigiCollection filteredDigis;
0107 
0108   if (!m_digiToken.isUninitialized()) {
0109     edm::Handle<DTDigiCollection> dtDigis;
0110     event.getByToken(m_digiToken, dtDigis);
0111 
0112     for (const auto &dtLayerId : (*dtDigis)) {
0113       uint32_t rawId = (dtLayerId.first).chamberId().rawId();
0114       auto chEffIt = chEffs.find(rawId);
0115 
0116       if (chEffIt == chEffs.end() || randGen.flat() <= chEffIt->second)
0117         filteredDigis.put(dtLayerId.second, dtLayerId.first);
0118     }
0119   }
0120 
0121   event.emplace(m_putToken, std::move(filteredDigis));
0122 }
0123 
0124 // ------------ method fills 'descriptions' with the allowed parameters for the
0125 // module  ------------
0126 void DTChamberMasker::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0127   edm::ParameterSetDescription desc;
0128   desc.add<edm::InputTag>("digiTag", edm::InputTag("simMuonDTDigis"));
0129   descriptions.add("dtChamberMasker", desc);
0130 }
0131 
0132 // define this as a plug-in
0133 DEFINE_FWK_MODULE(DTChamberMasker);