Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:55:50

0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "FWCore/Framework/interface/global/EDFilter.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "DataFormats/L1Trigger/interface/P2GTCandidate.h"
0005 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0006 
0007 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0008 #include "DataFormats/Common/interface/Handle.h"
0009 #include "FWCore/Utilities/interface/EDGetToken.h"
0010 #include "DataFormats/Common/interface/Ref.h"
0011 #include "FWCore/Framework/interface/MakerMacros.h"
0012 
0013 #include "L1Trigger/Phase2L1GT/interface/L1GTInvariantMassError.h"
0014 
0015 #include "L1Trigger/Phase2L1GT/interface/L1GTScales.h"
0016 
0017 #include "L1GTOptionalParam.h"
0018 #include "L1GTSingleCollectionCut.h"
0019 #include "L1GTDeltaCut.h"
0020 #include "L1GTSingleInOutLUT.h"
0021 
0022 #include <cinttypes>
0023 #include <memory>
0024 #include <vector>
0025 #include <set>
0026 
0027 #include <ap_int.h>
0028 
0029 using namespace l1t;
0030 
0031 class L1GTDoubleObjectCond : public edm::global::EDFilter<> {
0032 public:
0033   explicit L1GTDoubleObjectCond(const edm::ParameterSet&);
0034   ~L1GTDoubleObjectCond() override = default;
0035 
0036   static void fillDescriptions(edm::ConfigurationDescriptions&);
0037 
0038 private:
0039   bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0040 
0041   const L1GTScales scales_;
0042 
0043   const L1GTSingleCollectionCut collection1Cuts_;
0044   const L1GTSingleCollectionCut collection2Cuts_;
0045 
0046   const bool enable_sanity_checks_;
0047   const bool inv_mass_checks_;
0048 
0049   const L1GTDeltaCut deltaCuts_;
0050 
0051   const edm::EDGetTokenT<P2GTCandidateCollection> token1_;
0052   const edm::EDGetTokenT<P2GTCandidateCollection> token2_;
0053 };
0054 
0055 L1GTDoubleObjectCond::L1GTDoubleObjectCond(const edm::ParameterSet& config)
0056     : scales_(config.getParameter<edm::ParameterSet>("scales")),
0057       collection1Cuts_(config.getParameterSet("collection1"), config, scales_),
0058       collection2Cuts_(config.getParameterSet("collection2"), config, scales_),
0059       enable_sanity_checks_(config.getUntrackedParameter<bool>("sanity_checks")),
0060       inv_mass_checks_(config.getUntrackedParameter<bool>("inv_mass_checks")),
0061       deltaCuts_(config, config, scales_, enable_sanity_checks_, inv_mass_checks_),
0062       token1_(consumes<P2GTCandidateCollection>(collection1Cuts_.tag())),
0063       token2_(collection1Cuts_.tag() == collection2Cuts_.tag()
0064                   ? token1_
0065                   : consumes<P2GTCandidateCollection>(collection2Cuts_.tag())) {
0066   produces<P2GTCandidateVectorRef>(collection1Cuts_.tag().instance());
0067 
0068   if (!(collection1Cuts_.tag() == collection2Cuts_.tag())) {
0069     produces<P2GTCandidateVectorRef>(collection2Cuts_.tag().instance());
0070   }
0071 
0072   if (inv_mass_checks_) {
0073     produces<InvariantMassErrorCollection>();
0074   }
0075 }
0076 
0077 void L1GTDoubleObjectCond::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0078   edm::ParameterSetDescription desc;
0079 
0080   edm::ParameterSetDescription collection1Desc;
0081   L1GTSingleCollectionCut::fillPSetDescription(collection1Desc);
0082   desc.add<edm::ParameterSetDescription>("collection1", collection1Desc);
0083 
0084   edm::ParameterSetDescription collection2Desc;
0085   L1GTSingleCollectionCut::fillPSetDescription(collection2Desc);
0086   desc.add<edm::ParameterSetDescription>("collection2", collection2Desc);
0087 
0088   desc.addUntracked<bool>("sanity_checks", false);
0089   desc.addUntracked<bool>("inv_mass_checks", false);
0090 
0091   L1GTDeltaCut::fillPSetDescription(desc);
0092   L1GTDeltaCut::fillLUTDescriptions(desc);
0093 
0094   edm::ParameterSetDescription scalesDesc;
0095   L1GTScales::fillPSetDescription(scalesDesc);
0096   desc.add<edm::ParameterSetDescription>("scales", scalesDesc);
0097 
0098   descriptions.addWithDefaultLabel(desc);
0099 }
0100 
0101 bool L1GTDoubleObjectCond::filter(edm::StreamID, edm::Event& event, const edm::EventSetup& setup) const {
0102   edm::Handle<P2GTCandidateCollection> col1 = event.getHandle(token1_);
0103   edm::Handle<P2GTCandidateCollection> col2 = event.getHandle(token2_);
0104 
0105   bool condition_result = false;
0106 
0107   std::set<std::size_t> triggeredIdcs1;
0108   std::set<std::size_t> triggeredIdcs2;
0109 
0110   InvariantMassErrorCollection massErrors;
0111 
0112   for (std::size_t idx1 = 0; idx1 < col1->size(); ++idx1) {
0113     for (std::size_t idx2 = 0; idx2 < col2->size(); ++idx2) {
0114       // If we're looking at the same collection then we shouldn't use the same object in one comparison.
0115       if (col1.product() == col2.product() && idx1 == idx2) {
0116         continue;
0117       }
0118 
0119       bool pass = true;
0120       pass &= collection1Cuts_.checkObject(col1->at(idx1));
0121       pass &= collection2Cuts_.checkObject(col2->at(idx2));
0122       pass &= deltaCuts_.checkObjects(col1->at(idx1), col2->at(idx2), massErrors);
0123 
0124       condition_result |= pass;
0125 
0126       if (pass) {
0127         triggeredIdcs1.emplace(idx1);
0128         if (col1.product() != col2.product()) {
0129           triggeredIdcs2.emplace(idx2);
0130         } else {
0131           triggeredIdcs1.emplace(idx2);
0132         }
0133       }
0134     }
0135   }
0136 
0137   if (condition_result) {
0138     std::unique_ptr<P2GTCandidateVectorRef> triggerCol1 = std::make_unique<P2GTCandidateVectorRef>();
0139 
0140     for (std::size_t idx : triggeredIdcs1) {
0141       triggerCol1->push_back(P2GTCandidateRef(col1, idx));
0142     }
0143     event.put(std::move(triggerCol1), collection1Cuts_.tag().instance());
0144 
0145     if (col1.product() != col2.product()) {
0146       std::unique_ptr<P2GTCandidateVectorRef> triggerCol2 = std::make_unique<P2GTCandidateVectorRef>();
0147 
0148       for (std::size_t idx : triggeredIdcs2) {
0149         triggerCol2->push_back(P2GTCandidateRef(col2, idx));
0150       }
0151       event.put(std::move(triggerCol2), collection2Cuts_.tag().instance());
0152     }
0153   }
0154 
0155   if (inv_mass_checks_) {
0156     event.put(std::make_unique<InvariantMassErrorCollection>(std::move(massErrors)), "");
0157   }
0158 
0159   return condition_result;
0160 }
0161 
0162 DEFINE_FWK_MODULE(L1GTDoubleObjectCond);