Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:26:15

0001 #include "EventFilter/RPCRawToDigi/plugins/RPCDigiMerger.h"
0002 
0003 #include <memory>
0004 
0005 #include "DataFormats/Common/interface/Handle.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0012 #include "FWCore/Utilities/interface/CRC16.h"
0013 #include "FWCore/Utilities/interface/InputTag.h"
0014 
0015 #include "DataFormats/RPCDigi/interface/RPCDigiCollection.h"
0016 
0017 using namespace edm;
0018 using namespace std;
0019 
0020 RPCDigiMerger::RPCDigiMerger(edm::ParameterSet const& config)
0021     : bx_minTwinMux_(config.getParameter<int>("bxMinTwinMux")),
0022       bx_maxTwinMux_(config.getParameter<int>("bxMaxTwinMux")),
0023       bx_minOMTF_(config.getParameter<int>("bxMinOMTF")),
0024       bx_maxOMTF_(config.getParameter<int>("bxMaxOMTF")),
0025       bx_minCPPF_(config.getParameter<int>("bxMinCPPF")),
0026       bx_maxCPPF_(config.getParameter<int>("bxMaxCPPF")) {
0027   produces<RPCDigiCollection>();
0028   simRPC_token_ = consumes<RPCDigiCollection>(config.getParameter<edm::InputTag>("inputTagSimRPCDigis"));
0029   // protection against empty InputTag to allow for Data/MC compatibility
0030   if (not config.getParameter<edm::InputTag>("inputTagTwinMuxDigis").label().empty()) {
0031     twinMux_token_ = consumes<RPCDigiCollection>(config.getParameter<edm::InputTag>("inputTagTwinMuxDigis"));
0032   }
0033   if (not config.getParameter<edm::InputTag>("inputTagOMTFDigis").label().empty()) {
0034     omtf_token_ = consumes<RPCDigiCollection>(config.getParameter<edm::InputTag>("inputTagOMTFDigis"));
0035   }
0036   if (not config.getParameter<edm::InputTag>("inputTagCPPFDigis").label().empty()) {
0037     cppf_token_ = consumes<RPCDigiCollection>(config.getParameter<edm::InputTag>("inputTagCPPFDigis"));
0038   }
0039 }
0040 
0041 RPCDigiMerger::~RPCDigiMerger() {}
0042 
0043 void RPCDigiMerger::fillDescriptions(edm::ConfigurationDescriptions& descs) {
0044   edm::ParameterSetDescription desc;
0045   desc.add<edm::InputTag>("inputTagSimRPCDigis", edm::InputTag("simMuonRPCDigis", ""));
0046   desc.add<edm::InputTag>("inputTagTwinMuxDigis", edm::InputTag("", ""));
0047   desc.add<edm::InputTag>("inputTagOMTFDigis", edm::InputTag("", ""));
0048   desc.add<edm::InputTag>("inputTagCPPFDigis", edm::InputTag("", ""));
0049   desc.add<edm::InputTag>("InputLabel", edm::InputTag(" "));
0050   desc.add<int>("bxMinTwinMux", -2);
0051   desc.add<int>("bxMaxTwinMux", 2);
0052   desc.add<int>("bxMinOMTF", -3);
0053   desc.add<int>("bxMaxOMTF", 4);
0054   desc.add<int>("bxMinCPPF", -2);
0055   desc.add<int>("bxMaxCPPF", 2);
0056 
0057   descs.add("rpcDigiMerger", desc);
0058 }
0059 
0060 void RPCDigiMerger::beginRun(edm::Run const& run, edm::EventSetup const& setup) {}
0061 
0062 void RPCDigiMerger::produce(edm::Event& event, edm::EventSetup const& setup) {
0063   // Get the digis
0064   // new RPCDigiCollection
0065   std::unique_ptr<RPCDigiCollection> rpc_digi_collection(new RPCDigiCollection());
0066 
0067   //Check if its Data
0068   if (not(cppf_token_.isUninitialized() && omtf_token_.isUninitialized() && twinMux_token_.isUninitialized())) {
0069     // loop over TwinMux digis
0070     // protection against empty InputTag to allow for Data/MC compatibility
0071     if (not twinMux_token_.isUninitialized()) {
0072       Handle<RPCDigiCollection> TwinMux_digis;
0073       event.getByToken(twinMux_token_, TwinMux_digis);
0074       for (const auto&& rpcdgIt : (*TwinMux_digis)) {
0075         // The layerId
0076         const RPCDetId& rpcId = rpcdgIt.first;
0077         // Get the iterators over the digis associated with this LayerId
0078         const RPCDigiCollection::Range& range = rpcdgIt.second;
0079         rpc_digi_collection->put(range, rpcId);
0080       }
0081     }
0082     // loop over CPPF digis
0083     // protection against empty InputTag to allow for Data/MC compatibility
0084     if (not cppf_token_.isUninitialized()) {
0085       Handle<RPCDigiCollection> CPPF_digis;
0086       event.getByToken(cppf_token_, CPPF_digis);
0087       for (const auto&& rpcdgIt : (*CPPF_digis)) {
0088         // The layerId
0089         const RPCDetId& rpcId = rpcdgIt.first;
0090         // Get the iterators over the digis associated with this LayerId
0091         const RPCDigiCollection::Range& range = rpcdgIt.second;
0092         rpc_digi_collection->put(range, rpcId);
0093       }
0094     }
0095     // loop over OMTF digis
0096     // protection against empty InputTag to allow for Data/MC compatibility
0097     if (not omtf_token_.isUninitialized()) {
0098       Handle<RPCDigiCollection> OMTF_digis;
0099       event.getByToken(omtf_token_, OMTF_digis);
0100       for (const auto& rpcdgIt : (*OMTF_digis)) {
0101         // The layerId
0102         const RPCDetId& rpcId = rpcdgIt.first;
0103         // Get the iterators over the digis associated with this LayerId
0104         const RPCDigiCollection::Range& range = rpcdgIt.second;
0105         // accepts only rings: RE-2_R3 ; RE-1_R3 ; RE+1_R3 ; RE+2_R3 ;
0106         if (((rpcId.region() == -1 || rpcId.region() == 1) && (rpcId.ring() == 3) &&
0107              (rpcId.station() == 1 || rpcId.station() == 2))) {
0108           rpc_digi_collection->put(range, rpcId);
0109         }
0110       }
0111     }
0112   } else {  //its MC
0113     // SimRPCDigis collection
0114     Handle<RPCDigiCollection> SimRPC_digis;
0115     event.getByToken(simRPC_token_, SimRPC_digis);
0116 
0117     RPCDetId rpc_det_id;
0118     std::vector<RPCDigi> local_rpc_digis;
0119 
0120     // loop over SimRPC digis
0121     for (const auto& rpc_digi : (*SimRPC_digis)) {
0122       // The layerId
0123       const RPCDetId& rpcId = rpc_digi.first;
0124       // Get the iterators over the digis associated with this LayerId
0125       const RPCDigiCollection::Range& range = rpc_digi.second;
0126 
0127       if (rpcId != rpc_det_id) {
0128         if (!local_rpc_digis.empty()) {
0129           rpc_digi_collection->put(RPCDigiCollection::Range(local_rpc_digis.begin(), local_rpc_digis.end()),
0130                                    rpc_det_id);
0131           local_rpc_digis.clear();
0132         }
0133         rpc_det_id = rpcId;
0134       }
0135       for (std::vector<RPCDigi>::const_iterator id = range.first; id != range.second; id++) {
0136         const RPCDigi& dit = (*id);
0137         //Barrel
0138         if (rpcId.region() == 0) {
0139           //TwinMux
0140           if (dit.bx() >= bx_minTwinMux_ && dit.bx() <= bx_maxTwinMux_) {
0141             local_rpc_digis.push_back(dit);
0142           }
0143         }
0144         //EndCap
0145         if (rpcId.region() == -1 || rpcId.region() == 1) {
0146           //OMTF
0147           if (rpcId.ring() == 3 && (rpcId.station() == 1 || rpcId.station() == 2) && dit.bx() >= bx_minOMTF_ &&
0148               dit.bx() <= bx_maxOMTF_) {
0149             local_rpc_digis.push_back(dit);
0150           }
0151           //CPPF
0152           if (((rpcId.ring() == 2) || (rpcId.ring() == 3 && (rpcId.station() == 3 || rpcId.station() == 4))) &&
0153               (dit.bx() >= bx_minCPPF_ && dit.bx() <= bx_maxCPPF_)) {
0154             local_rpc_digis.push_back(dit);
0155           }
0156         }
0157       }
0158     }
0159     if (!local_rpc_digis.empty()) {
0160       rpc_digi_collection->put(RPCDigiCollection::Range(local_rpc_digis.begin(), local_rpc_digis.end()), rpc_det_id);
0161     }
0162   }
0163   // "put" into the event
0164   event.put(std::move(rpc_digi_collection));
0165 }
0166 
0167 #include "FWCore/Framework/interface/MakerMacros.h"
0168 DEFINE_FWK_MODULE(RPCDigiMerger);