Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-25 04:55:08

0001 // system include files
0002 #include <algorithm>
0003 #include <memory>
0004 #include <string>
0005 #include <type_traits>
0006 
0007 // user include files
0008 #include "FWCore/Framework/interface/ConsumesCollector.h"
0009 #include "FWCore/Framework/interface/Frameworkfwd.h"
0010 #include "FWCore/Framework/interface/stream/EDProducer.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 
0013 #include "DataFormats/Common/interface/Handle.h"
0014 #include "FWCore/Framework/interface/Event.h"
0015 #include "FWCore/Framework/interface/Run.h"
0016 
0017 #include "FWCore/Framework/interface/ESHandle.h"
0018 #include "FWCore/Utilities/interface/ESGetToken.h"
0019 #include "FWCore/Framework/interface/EventSetup.h"
0020 
0021 #include "FWCore/Framework/interface/MakerMacros.h"
0022 
0023 #include "DataFormats/CSCDigi/interface/CSCStripDigi.h"
0024 #include "DataFormats/CSCDigi/interface/CSCStripDigiCollection.h"
0025 #include "DataFormats/CSCDigi/interface/CSCWireDigi.h"
0026 #include "DataFormats/CSCDigi/interface/CSCWireDigiCollection.h"
0027 #include "DataFormats/CSCDigi/interface/CSCComparatorDigi.h"
0028 #include "DataFormats/CSCDigi/interface/CSCComparatorDigiCollection.h"
0029 #include "DataFormats/CSCDigi/interface/CSCALCTDigi.h"
0030 #include "DataFormats/CSCDigi/interface/CSCALCTDigiCollection.h"
0031 #include "DataFormats/CSCDigi/interface/CSCCLCTDigi.h"
0032 #include "DataFormats/CSCDigi/interface/CSCCLCTDigiCollection.h"
0033 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigi.h"
0034 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigiCollection.h"
0035 #include "DataFormats/CSCDigi/interface/CSCShowerDigi.h"
0036 #include "DataFormats/CSCDigi/interface/CSCShowerDigiCollection.h"
0037 #include "DataFormats/GEMDigi/interface/GEMPadDigiCluster.h"
0038 #include "DataFormats/GEMDigi/interface/GEMPadDigiClusterCollection.h"
0039 
0040 class CSCDigiFilter : public edm::stream::EDProducer<> {
0041 public:
0042   explicit CSCDigiFilter(const edm::ParameterSet &);
0043   ~CSCDigiFilter() override {}
0044 
0045   static void fillDescriptions(edm::ConfigurationDescriptions &);
0046 
0047 private:
0048   void produce(edm::Event &, const edm::EventSetup &) override;
0049 
0050   template <typename T, typename C = MuonDigiCollection<CSCDetId, T>>
0051   void filterDigis(edm::Event &event, edm::EDGetTokenT<C> &digiToken, std::unique_ptr<C> &filteredDigis);
0052 
0053   // the collections
0054   edm::EDGetTokenT<CSCStripDigiCollection> stripDigiToken_;
0055   edm::EDGetTokenT<CSCWireDigiCollection> wireDigiToken_;
0056   edm::EDGetTokenT<CSCComparatorDigiCollection> compDigiToken_;
0057   edm::EDGetTokenT<CSCCLCTDigiCollection> clctDigiToken_;
0058   edm::EDGetTokenT<CSCALCTDigiCollection> alctDigiToken_;
0059   edm::EDGetTokenT<CSCCorrelatedLCTDigiCollection> lctDigiToken_;
0060   edm::EDGetTokenT<CSCShowerDigiCollection> showerDigiToken_;
0061   edm::EDGetTokenT<GEMPadDigiClusterCollection> gemPadDigiClusterToken_;
0062 
0063   /* which chambers to select or mask? format example "ME+2/1/15"
0064      behavior:
0065      if maskedChambers_ is empty, no chambers are masked
0066      if selectedChambers_ is empty, all chambers are selected
0067   */
0068   std::vector<std::string> maskedChambers_;
0069   std::vector<std::string> selectedChambers_;
0070 
0071   // options to filter Run-3 and Phase-2 collections
0072   bool useGEMs_;
0073   bool useShowers_;
0074 };
0075 
0076 CSCDigiFilter::CSCDigiFilter(const edm::ParameterSet &iConfig)
0077     : stripDigiToken_(consumes<CSCStripDigiCollection>(iConfig.getParameter<edm::InputTag>("stripDigiTag"))),
0078       wireDigiToken_(consumes<CSCWireDigiCollection>(iConfig.getParameter<edm::InputTag>("wireDigiTag"))),
0079       compDigiToken_(consumes<CSCComparatorDigiCollection>(iConfig.getParameter<edm::InputTag>("compDigiTag"))),
0080       clctDigiToken_(consumes<CSCCLCTDigiCollection>(iConfig.getParameter<edm::InputTag>("clctDigiTag"))),
0081       alctDigiToken_(consumes<CSCALCTDigiCollection>(iConfig.getParameter<edm::InputTag>("alctDigiTag"))),
0082       lctDigiToken_(consumes<CSCCorrelatedLCTDigiCollection>(iConfig.getParameter<edm::InputTag>("lctDigiTag"))),
0083       maskedChambers_(iConfig.getParameter<std::vector<std::string>>("maskedChambers")),
0084       selectedChambers_(iConfig.getParameter<std::vector<std::string>>("selectedChambers")),
0085       useGEMs_(iConfig.getParameter<bool>("useGEMs")),
0086       useShowers_(iConfig.getParameter<bool>("useShowers")) {
0087   if (useGEMs_)
0088     gemPadDigiClusterToken_ =
0089         consumes<GEMPadDigiClusterCollection>(iConfig.getParameter<edm::InputTag>("gemPadClusterDigiTag"));
0090   if (useShowers_)
0091     showerDigiToken_ = consumes<CSCShowerDigiCollection>(iConfig.getParameter<edm::InputTag>("showerDigiTag"));
0092 
0093   produces<CSCStripDigiCollection>("MuonCSCStripDigi");
0094   produces<CSCWireDigiCollection>("MuonCSCWireDigi");
0095   produces<CSCComparatorDigiCollection>("MuonCSCComparatorDigi");
0096   produces<CSCCLCTDigiCollection>("MuonCSCCLCTDigi");
0097   produces<CSCALCTDigiCollection>("MuonCSCALCTDigi");
0098   produces<CSCCorrelatedLCTDigiCollection>("MuonCSCCorrelatedLCTDigi");
0099   if (useGEMs_)
0100     produces<GEMPadDigiClusterCollection>("MuonGEMPadDigiCluster");
0101   if (useShowers_)
0102     produces<CSCShowerDigiCollection>("MuonCSCShowerDigi");
0103 }
0104 
0105 void CSCDigiFilter::produce(edm::Event &event, const edm::EventSetup &conditions) {
0106   std::unique_ptr<CSCStripDigiCollection> filteredStripDigis(new CSCStripDigiCollection());
0107   std::unique_ptr<CSCWireDigiCollection> filteredWireDigis(new CSCWireDigiCollection());
0108   std::unique_ptr<CSCComparatorDigiCollection> filteredCompDigis(new CSCComparatorDigiCollection());
0109   std::unique_ptr<CSCCLCTDigiCollection> filteredCLCTDigis(new CSCCLCTDigiCollection());
0110   std::unique_ptr<CSCALCTDigiCollection> filteredALCTDigis(new CSCALCTDigiCollection());
0111   std::unique_ptr<CSCCorrelatedLCTDigiCollection> filteredLCTDigis(new CSCCorrelatedLCTDigiCollection());
0112   std::unique_ptr<CSCShowerDigiCollection> filteredShowerDigis(new CSCShowerDigiCollection());
0113   std::unique_ptr<GEMPadDigiClusterCollection> filteredClusterDigis(new GEMPadDigiClusterCollection());
0114 
0115   // filter the collections
0116   filterDigis<CSCStripDigi>(event, stripDigiToken_, filteredStripDigis);
0117   filterDigis<CSCWireDigi>(event, wireDigiToken_, filteredWireDigis);
0118   filterDigis<CSCComparatorDigi>(event, compDigiToken_, filteredCompDigis);
0119   filterDigis<CSCCLCTDigi>(event, clctDigiToken_, filteredCLCTDigis);
0120   filterDigis<CSCALCTDigi>(event, alctDigiToken_, filteredALCTDigis);
0121   filterDigis<CSCCorrelatedLCTDigi>(event, lctDigiToken_, filteredLCTDigis);
0122   if (useGEMs_)
0123     filterDigis<GEMPadDigiCluster>(event, gemPadDigiClusterToken_, filteredClusterDigis);
0124   if (useShowers_)
0125     filterDigis<CSCShowerDigi>(event, showerDigiToken_, filteredShowerDigis);
0126 
0127   // put the new collections into the event
0128   event.put(std::move(filteredStripDigis), "MuonCSCStripDigi");
0129   event.put(std::move(filteredWireDigis), "MuonCSCWireDigi");
0130   event.put(std::move(filteredCompDigis), "MuonCSCComparatorDigi");
0131   event.put(std::move(filteredCLCTDigis), "MuonCSCCLCTDigi");
0132   event.put(std::move(filteredALCTDigis), "MuonCSCALCTDigi");
0133   event.put(std::move(filteredLCTDigis), "MuonCSCCorrelatedLCTDigi");
0134   if (useShowers_)
0135     event.put(std::move(filteredShowerDigis), "MuonCSCShowerDigi");
0136   if (useGEMs_)
0137     event.put(std::move(filteredClusterDigis), "MuonGEMPadDigiCluster");
0138 }
0139 
0140 template <typename T, typename C>
0141 void CSCDigiFilter::filterDigis(edm::Event &event, edm::EDGetTokenT<C> &digiToken, std::unique_ptr<C> &filteredDigis) {
0142   if (!digiToken.isUninitialized()) {
0143     auto const &digis = event.get(digiToken);
0144 
0145     for (const auto &j : digis) {
0146       // use base class here
0147       const DetId &detId = j.first;
0148 
0149       CSCDetId chId;
0150 
0151       if (std::is_same<C, GEMPadDigiClusterCollection>::value) {
0152         // explicit downcast
0153         const GEMDetId gemDetId(detId);
0154 
0155         const int zendcap(gemDetId.region() == 1 ? 1 : 2);
0156         // chamber id
0157         chId = CSCDetId(zendcap, gemDetId.station(), 1, gemDetId.chamber());
0158 
0159       } else {
0160         // chamber id
0161         chId = CSCDetId(detId).chamberId();
0162       }
0163 
0164       // check for masked chambers
0165       if (std::find(maskedChambers_.begin(), maskedChambers_.end(), chId.chamberName()) != maskedChambers_.end()) {
0166         continue;
0167       }
0168       // check for selected chambers
0169       // ignore this when selectedChambers_ is empty
0170       if (!selectedChambers_.empty()) {
0171         if (std::find(selectedChambers_.begin(), selectedChambers_.end(), chId.chamberName()) ==
0172             selectedChambers_.end()) {
0173           continue;
0174         }
0175       }
0176       // add the digis that are not ignored
0177       for (auto digiItr = j.second.first; digiItr != j.second.second; ++digiItr) {
0178         if (std::is_same<C, GEMPadDigiClusterCollection>::value) {
0179           filteredDigis->insertDigi(GEMDetId(detId), *digiItr);
0180         } else {
0181           filteredDigis->insertDigi(CSCDetId(detId), *digiItr);
0182         }
0183       }
0184     }
0185   }
0186 }
0187 
0188 void CSCDigiFilter::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0189   edm::ParameterSetDescription desc;
0190   desc.add<edm::InputTag>("stripDigiTag", {"muonCSCDigis:MuonCSCStripDigi"});
0191   desc.add<edm::InputTag>("wireDigiTag", {"muonCSCDigis:MuonCSCWireDigi"});
0192   desc.add<edm::InputTag>("compDigiTag", {"muonCSCDigis:MuonCSCComparatorDigi"});
0193   desc.add<edm::InputTag>("alctDigiTag", {"muonCSCDigis:MuonCSCALCTDigi"});
0194   desc.add<edm::InputTag>("clctDigiTag", {"muonCSCDigis:MuonCSCCLCTDigi"});
0195   desc.add<edm::InputTag>("lctDigiTag", {"muonCSCDigis:MuonCSCCorrelatedLCTDigi"});
0196   desc.add<edm::InputTag>("showerDigiTag", {"muonCSCDigis:MuonCSCShowerDigi"});
0197   desc.add<edm::InputTag>("gemPadClusterDigiTag", {"muonCSCDigis:MuonGEMPadDigiCluster"});
0198   desc.add<std::vector<std::string>>("maskedChambers");
0199   desc.add<std::vector<std::string>>("selectedChambers");
0200   desc.add<bool>("useGEMs", false);
0201   desc.add<bool>("useShowers", false);
0202   descriptions.add("cscDigiFilterDef", desc);
0203 }
0204 
0205 // define this as a plug-in
0206 DEFINE_FWK_MODULE(CSCDigiFilter);