Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-05 04:10:10

0001 // -*- C++ -*-
0002 //
0003 // Package:    SimMuon/RPCDigitizer/
0004 // Class:      RPCChamberMasker
0005 //
0006 /**\class RPCChamberMasker RPCChamberMasker.cc SimMuon/RPCDigitizer/plugins/RPCChamberMasker.cc
0007 
0008  Description:
0009 
0010  Implementation:
0011      Class to mask RPC digis on a for single DetIds
0012 
0013 */
0014 //
0015 // Original Author:  Borislav Pavlov
0016 //         Created:  Tue, 16 Jun 2015 13:02:20 GMT
0017 //
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 #include <string>
0023 #include <vector>
0024 #include <iostream>
0025 #include <algorithm>
0026 #include <regex>
0027 
0028 // user include files
0029 #include "FWCore/Framework/interface/Frameworkfwd.h"
0030 #include "FWCore/Framework/interface/stream/EDProducer.h"
0031 #include "FWCore/Framework/interface/ConsumesCollector.h"
0032 #include "FWCore/Framework/interface/ESHandle.h"
0033 #include "FWCore/Framework/interface/Event.h"
0034 #include "FWCore/Framework/interface/MakerMacros.h"
0035 #include "FWCore/Framework/interface/EventSetup.h"
0036 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0037 
0038 #include "DataFormats/RPCDigi/interface/RPCDigiCollection.h"
0039 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
0040 #include "CondFormats/RecoMuonObjects/interface/MuonSystemAging.h"
0041 #include "CondFormats/DataRecord/interface/MuonSystemAgingRcd.h"
0042 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
0043 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0044 
0045 #include "FWCore/ServiceRegistry/interface/Service.h"
0046 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
0047 #include "CLHEP/Random/RandomEngine.h"
0048 //
0049 // class declaration
0050 //
0051 
0052 class RPCChamberMasker : public edm::stream::EDProducer<> {
0053 public:
0054   explicit RPCChamberMasker(const edm::ParameterSet&);
0055   ~RPCChamberMasker() override;
0056 
0057   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0058 
0059 private:
0060   void produce(edm::Event&, const edm::EventSetup&) override;
0061 
0062   void beginRun(edm::Run const&, edm::EventSetup const&) override;
0063   void endRun(edm::Run const&, edm::EventSetup const&) override;
0064 
0065   // ----------member data ---------------------------
0066   edm::InputTag digiTag_;
0067   edm::EDGetTokenT<RPCDigiCollection> m_digiTag;
0068   std::map<RPCDetId, float> m_ChEffs;
0069   bool theRE31_off;
0070   bool theRE41_off;
0071 
0072   edm::ESGetToken<RPCGeometry, MuonGeometryRecord> rpcGeomToken_;
0073   edm::ESGetToken<MuonSystemAging, MuonSystemAgingRcd> agingObjToken_;
0074 };
0075 
0076 //
0077 // constants, enums and typedefs
0078 //
0079 
0080 //
0081 // static data member definitions
0082 //
0083 
0084 //
0085 // constructors and destructor
0086 //
0087 RPCChamberMasker::RPCChamberMasker(const edm::ParameterSet& iConfig)
0088     : digiTag_(iConfig.getParameter<edm::InputTag>("digiTag")) {
0089   m_digiTag = consumes<RPCDigiCollection>(digiTag_);
0090   produces<RPCDigiCollection>();
0091 
0092   theRE31_off = iConfig.getParameter<bool>("descopeRE31");
0093   theRE41_off = iConfig.getParameter<bool>("descopeRE41");
0094   rpcGeomToken_ = esConsumes();
0095   agingObjToken_ = esConsumes();
0096 }
0097 
0098 RPCChamberMasker::~RPCChamberMasker() {}
0099 
0100 //
0101 // member functions
0102 //
0103 
0104 // ------------ method called to produce the data  ------------
0105 void RPCChamberMasker::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0106   using namespace edm;
0107   edm::Service<edm::RandomNumberGenerator> randGenService;
0108   CLHEP::HepRandomEngine& randGen = randGenService->getEngine(iEvent.streamID());
0109 
0110   std::unique_ptr<RPCDigiCollection> filteredDigis(new RPCDigiCollection());
0111   if (!digiTag_.label().empty()) {
0112     edm::Handle<RPCDigiCollection> rpcDigis;
0113     iEvent.getByToken(m_digiTag, rpcDigis);
0114 
0115     for (const auto& rpcLayerId : (*rpcDigis)) {
0116       int id = (rpcLayerId.first).rawId();
0117       auto chEffIt = m_ChEffs.find(id);
0118       if ((chEffIt != m_ChEffs.end()) && (randGen.flat() <= chEffIt->second))
0119         filteredDigis->put(rpcLayerId.second, rpcLayerId.first);
0120     }
0121   }
0122   iEvent.put(std::move(filteredDigis));
0123 }
0124 
0125 // ------------ method called when starting to processes a run  ------------
0126 
0127 void RPCChamberMasker::beginRun(edm::Run const& run, edm::EventSetup const& iSetup) {
0128   m_ChEffs.clear();
0129 
0130   auto rpcGeom = iSetup.getHandle(rpcGeomToken_);
0131   auto agingObj = iSetup.getHandle(agingObjToken_);
0132 
0133   const auto rolls = rpcGeom->rolls();
0134 
0135   for (const auto* roll : rolls) {
0136     RPCDetId rollId = roll->id();
0137     uint32_t rollRawId = rollId.rawId();
0138 
0139     Float_t chamberEff = 1.;
0140     for (const auto& agingPair : agingObj->m_RPCChambEffs) {
0141       if (agingPair.first == rollRawId) {
0142         chamberEff = agingPair.second;
0143         break;
0144       }
0145 
0146       if (theRE31_off && (roll->isIRPC() && (rollId.station() == 3))) {
0147         chamberEff = 0;
0148       }
0149       if (theRE41_off && (roll->isIRPC() && (rollId.station() == 4))) {
0150         chamberEff = 0;
0151       }
0152     }
0153     m_ChEffs[rollId] = chamberEff;
0154   }
0155 }
0156 
0157 // ------------ method called when ending the processing of a run  ------------
0158 
0159 void RPCChamberMasker::endRun(edm::Run const&, edm::EventSetup const&) {}
0160 
0161 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0162 void RPCChamberMasker::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0163   edm::ParameterSetDescription desc;
0164   desc.add<edm::InputTag>("digiTag", edm::InputTag("preRPCDigis"));
0165   desc.add<bool>("descopeRE31", false);
0166   desc.add<bool>("descopeRE41", false);
0167   descriptions.add("rpcChamberMasker", desc);
0168 }
0169 
0170 //define this as a plug-in
0171 DEFINE_FWK_MODULE(RPCChamberMasker);