Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:58

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::produce(edm::Event& event, edm::EventSetup const& setup) {
0061   // Get the digis
0062   // new RPCDigiCollection
0063   std::unique_ptr<RPCDigiCollection> rpc_digi_collection(new RPCDigiCollection());
0064 
0065   //Check if its Data
0066   if (not(cppf_token_.isUninitialized() && omtf_token_.isUninitialized() && twinMux_token_.isUninitialized())) {
0067     // loop over TwinMux digis
0068     // protection against empty InputTag to allow for Data/MC compatibility
0069     if (not twinMux_token_.isUninitialized()) {
0070       Handle<RPCDigiCollection> TwinMux_digis;
0071       event.getByToken(twinMux_token_, TwinMux_digis);
0072       for (const auto&& rpcdgIt : (*TwinMux_digis)) {
0073         // The layerId
0074         const RPCDetId& rpcId = rpcdgIt.first;
0075         // Get the iterators over the digis associated with this LayerId
0076         const RPCDigiCollection::Range& range = rpcdgIt.second;
0077         rpc_digi_collection->put(range, rpcId);
0078       }
0079     }
0080     // loop over CPPF digis
0081     // protection against empty InputTag to allow for Data/MC compatibility
0082     if (not cppf_token_.isUninitialized()) {
0083       Handle<RPCDigiCollection> CPPF_digis;
0084       event.getByToken(cppf_token_, CPPF_digis);
0085       for (const auto&& rpcdgIt : (*CPPF_digis)) {
0086         // The layerId
0087         const RPCDetId& rpcId = rpcdgIt.first;
0088         // Get the iterators over the digis associated with this LayerId
0089         const RPCDigiCollection::Range& range = rpcdgIt.second;
0090         rpc_digi_collection->put(range, rpcId);
0091       }
0092     }
0093     // loop over OMTF digis
0094     // protection against empty InputTag to allow for Data/MC compatibility
0095     if (not omtf_token_.isUninitialized()) {
0096       Handle<RPCDigiCollection> OMTF_digis;
0097       event.getByToken(omtf_token_, OMTF_digis);
0098       for (const auto& rpcdgIt : (*OMTF_digis)) {
0099         // The layerId
0100         const RPCDetId& rpcId = rpcdgIt.first;
0101         // Get the iterators over the digis associated with this LayerId
0102         const RPCDigiCollection::Range& range = rpcdgIt.second;
0103         // accepts only rings: RE-2_R3 ; RE-1_R3 ; RE+1_R3 ; RE+2_R3 ;
0104         if (((rpcId.region() == -1 || rpcId.region() == 1) && (rpcId.ring() == 3) &&
0105              (rpcId.station() == 1 || rpcId.station() == 2))) {
0106           rpc_digi_collection->put(range, rpcId);
0107         }
0108       }
0109     }
0110   } else {  //its MC
0111     // SimRPCDigis collection
0112     Handle<RPCDigiCollection> SimRPC_digis;
0113     event.getByToken(simRPC_token_, SimRPC_digis);
0114 
0115     RPCDetId rpc_det_id;
0116     std::vector<RPCDigi> local_rpc_digis;
0117 
0118     // loop over SimRPC digis
0119     for (const auto& rpc_digi : (*SimRPC_digis)) {
0120       // The layerId
0121       const RPCDetId& rpcId = rpc_digi.first;
0122       // Get the iterators over the digis associated with this LayerId
0123       const RPCDigiCollection::Range& range = rpc_digi.second;
0124 
0125       if (rpcId != rpc_det_id) {
0126         if (!local_rpc_digis.empty()) {
0127           rpc_digi_collection->put(RPCDigiCollection::Range(local_rpc_digis.begin(), local_rpc_digis.end()),
0128                                    rpc_det_id);
0129           local_rpc_digis.clear();
0130         }
0131         rpc_det_id = rpcId;
0132       }
0133       for (std::vector<RPCDigi>::const_iterator id = range.first; id != range.second; id++) {
0134         const RPCDigi& dit = (*id);
0135         //Barrel
0136         if (rpcId.region() == 0) {
0137           //TwinMux
0138           if (dit.bx() >= bx_minTwinMux_ && dit.bx() <= bx_maxTwinMux_) {
0139             local_rpc_digis.push_back(dit);
0140           }
0141         }
0142         //EndCap
0143         if (rpcId.region() == -1 || rpcId.region() == 1) {
0144           //OMTF
0145           if (rpcId.ring() == 3 && (rpcId.station() == 1 || rpcId.station() == 2) && dit.bx() >= bx_minOMTF_ &&
0146               dit.bx() <= bx_maxOMTF_) {
0147             local_rpc_digis.push_back(dit);
0148           }
0149           //CPPF
0150           if (((rpcId.ring() == 2) || (rpcId.ring() == 3 && (rpcId.station() == 3 || rpcId.station() == 4))) &&
0151               (dit.bx() >= bx_minCPPF_ && dit.bx() <= bx_maxCPPF_)) {
0152             local_rpc_digis.push_back(dit);
0153           }
0154         }
0155       }
0156     }
0157     if (!local_rpc_digis.empty()) {
0158       rpc_digi_collection->put(RPCDigiCollection::Range(local_rpc_digis.begin(), local_rpc_digis.end()), rpc_det_id);
0159     }
0160   }
0161   // "put" into the event
0162   event.put(std::move(rpc_digi_collection));
0163 }
0164 
0165 #include "FWCore/Framework/interface/MakerMacros.h"
0166 DEFINE_FWK_MODULE(RPCDigiMerger);