Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:36:52

0001 // -*- C++ -*-
0002 //
0003 // Package:    L1Trigger/L1TCommon
0004 // Class:      L1TComparisonResultFilter
0005 //
0006 /**\class L1TComparisonResultFilter L1TComparisonResultFilter.cc L1Trigger/L1TCommon/plugins/L1TComparisonResultFilter.cc
0007 
0008  Description: Filters on result of L1T object comparison. Events where the collections match are passing.
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Thomas Reis
0015 //         Created:  Fri, 19 Jan 2018 14:08:35 GMT
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <algorithm>
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/stream/EDFilter.h"
0026 
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029 
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 #include "FWCore/Utilities/interface/StreamID.h"
0032 
0033 #include "DataFormats/L1Trigger/interface/L1TObjComparison.h"
0034 
0035 //
0036 // class declaration
0037 //
0038 
0039 template <typename T>
0040 class L1TComparisonResultFilter : public edm::stream::EDFilter<> {
0041 public:
0042   explicit L1TComparisonResultFilter(const edm::ParameterSet&);
0043   ~L1TComparisonResultFilter() override = default;
0044 
0045   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0046 
0047 private:
0048   void beginStream(edm::StreamID) override{};
0049   bool filter(edm::Event&, const edm::EventSetup&) override;
0050   void endStream() override {}
0051 
0052   // ----------member data ---------------------------
0053   edm::InputTag inputTag_;
0054 
0055   edm::EDGetTokenT<l1t::ObjectRefPairBxCollection<T>> pairCollToken_;
0056   edm::EDGetTokenT<l1t::ObjectRefBxCollection<T>> coll1Token_;
0057   edm::EDGetTokenT<l1t::ObjectRefBxCollection<T>> coll2Token_;
0058 
0059   // Maximal mismatch sizes
0060   // Only analyse the corresponding property if max is not negative
0061   const int maxBxRangeDiff_;
0062   const int maxExcess_;
0063   const int maxSize_;
0064 
0065   // Invert the final result
0066   const bool invert_;
0067 };
0068 
0069 //
0070 // constructors and destructor
0071 //
0072 template <typename T>
0073 L1TComparisonResultFilter<T>::L1TComparisonResultFilter(const edm::ParameterSet& iConfig)
0074     : inputTag_(iConfig.getParameter<edm::InputTag>("objComparisonColl")),
0075       maxBxRangeDiff_(iConfig.getParameter<int>("maxBxRangeDiff")),
0076       maxExcess_(iConfig.getParameter<int>("maxExcess")),
0077       maxSize_(iConfig.getParameter<int>("maxSize")),
0078       invert_(iConfig.getParameter<bool>("invert")) {
0079   if (maxBxRangeDiff_ > -1 || maxExcess_ > -1) {
0080     // Take all input tags needed from the same module
0081     edm::InputTag coll1Tag(inputTag_.label(), "collection1ExcessObjects");
0082     edm::InputTag coll2Tag(inputTag_.label(), "collection2ExcessObjects");
0083     coll1Token_ = consumes<l1t::ObjectRefBxCollection<T>>(coll1Tag);
0084     coll2Token_ = consumes<l1t::ObjectRefBxCollection<T>>(coll2Tag);
0085   }
0086   if (maxSize_ > -1) {
0087     pairCollToken_ = consumes<l1t::ObjectRefPairBxCollection<T>>(inputTag_);
0088   }
0089 }
0090 
0091 //
0092 // member functions
0093 //
0094 
0095 // ------------ method called on each new Event  ------------
0096 template <typename T>
0097 bool L1TComparisonResultFilter<T>::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0098   bool pass = true;
0099 
0100   if (maxBxRangeDiff_ > -1 || maxExcess_ > -1) {
0101     edm::Handle<l1t::ObjectRefBxCollection<T>> bxColl1;
0102     edm::Handle<l1t::ObjectRefBxCollection<T>> bxColl2;
0103     iEvent.getByToken(coll1Token_, bxColl1);
0104     iEvent.getByToken(coll2Token_, bxColl2);
0105 
0106     // Check if BX ranges match
0107     if (maxBxRangeDiff_ > -1) {
0108       const auto bxRange1 = bxColl1->getLastBX() - bxColl1->getFirstBX() + 1;
0109       const auto bxRange2 = bxColl2->getLastBX() - bxColl2->getFirstBX() + 1;
0110       pass &= (std::abs(bxRange1 - bxRange2) <= maxBxRangeDiff_);
0111     }
0112 
0113     // If the BX range check passed check if number of objects per BX matches
0114     if (pass && maxExcess_ > -1) {
0115       const auto firstCommonBx = std::max(bxColl1->getFirstBX(), bxColl2->getFirstBX());
0116       const auto lastCommonBx = std::min(bxColl1->getLastBX(), bxColl2->getLastBX());
0117       for (auto iBx = firstCommonBx; iBx <= lastCommonBx; ++iBx) {
0118         pass &= (bxColl1->size(iBx) <= static_cast<unsigned>(maxExcess_));
0119         pass &= (bxColl2->size(iBx) <= static_cast<unsigned>(maxExcess_));
0120         if (!pass)
0121           break;
0122       }
0123     }
0124   }
0125 
0126   // If the previous checks passed check if there are mismatching objects
0127   if (pass && maxSize_ > -1) {
0128     edm::Handle<l1t::ObjectRefPairBxCollection<T>> bxPairColl;
0129     iEvent.getByToken(pairCollToken_, bxPairColl);
0130 
0131     pass &= (bxPairColl->size() <= static_cast<unsigned>(maxSize_));
0132   }
0133 
0134   if (invert_) {
0135     return !pass;
0136   }
0137   return pass;
0138 }
0139 
0140 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0141 template <typename T>
0142 void L1TComparisonResultFilter<T>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0143   edm::ParameterSetDescription desc;
0144   desc.add<edm::InputTag>("objComparisonColl", edm::InputTag("objComparisonColl"))
0145       ->setComment("Object comparison collection");
0146   desc.add<int>("maxBxRangeDiff", -1)->setComment("Maximal BX range difference");
0147   desc.add<int>("maxExcess", -1)->setComment("Maximal allowed excess objects per BX");
0148   desc.add<int>("maxSize", -1)->setComment("Maximal allowed mismatches");
0149   desc.add<bool>("invert", false)->setComment("Invert final result");
0150   descriptions.addWithDefaultLabel(desc);
0151 }
0152 
0153 //define plugins for different L1T objects
0154 #include "DataFormats/L1TGlobal/interface/GlobalAlgBlk.h"
0155 #include "DataFormats/L1Trigger/interface/EGamma.h"
0156 #include "DataFormats/L1Trigger/interface/Tau.h"
0157 #include "DataFormats/L1Trigger/interface/Jet.h"
0158 #include "DataFormats/L1Trigger/interface/EtSum.h"
0159 #include "DataFormats/L1Trigger/interface/Muon.h"
0160 #include "DataFormats/L1TMuon/interface/RegionalMuonCand.h"
0161 #include "DataFormats/L1TMuon/interface/RegionalMuonCandFwd.h"
0162 typedef L1TComparisonResultFilter<GlobalAlgBlk> L1TGlobalAlgBlkComparisonResultFilter;
0163 typedef L1TComparisonResultFilter<l1t::EGamma> L1TEGammaComparisonResultFilter;
0164 typedef L1TComparisonResultFilter<l1t::Tau> L1TTauComparisonResultFilter;
0165 typedef L1TComparisonResultFilter<l1t::Jet> L1TJetComparisonResultFilter;
0166 typedef L1TComparisonResultFilter<l1t::EtSum> L1TEtSumComparisonResultFilter;
0167 typedef L1TComparisonResultFilter<l1t::Muon> L1TMuonComparisonResultFilter;
0168 typedef L1TComparisonResultFilter<l1t::RegionalMuonCand> L1TRegionalMuonCandComparisonResultFilter;
0169 DEFINE_FWK_MODULE(L1TGlobalAlgBlkComparisonResultFilter);
0170 DEFINE_FWK_MODULE(L1TEGammaComparisonResultFilter);
0171 DEFINE_FWK_MODULE(L1TTauComparisonResultFilter);
0172 DEFINE_FWK_MODULE(L1TJetComparisonResultFilter);
0173 DEFINE_FWK_MODULE(L1TEtSumComparisonResultFilter);
0174 DEFINE_FWK_MODULE(L1TMuonComparisonResultFilter);
0175 DEFINE_FWK_MODULE(L1TRegionalMuonCandComparisonResultFilter);