Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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 "DataFormats/Common/interface/Ref.h"
0010 #include "FWCore/Utilities/interface/EDGetToken.h"
0011 
0012 #include "FWCore/Framework/interface/MakerMacros.h"
0013 
0014 #include "L1Trigger/Phase2L1GT/interface/L1GTScales.h"
0015 #include "L1GTSingleCollectionCut.h"
0016 #include "L1GTDeltaCut.h"
0017 #include "L1GTSingleInOutLUT.h"
0018 
0019 #include <set>
0020 
0021 #include <ap_int.h>
0022 
0023 using namespace l1t;
0024 
0025 class L1GTTripleObjectCond : public edm::global::EDFilter<> {
0026 public:
0027   explicit L1GTTripleObjectCond(const edm::ParameterSet&);
0028   ~L1GTTripleObjectCond() override = default;
0029 
0030   static void fillDescriptions(edm::ConfigurationDescriptions&);
0031 
0032 private:
0033   bool filter(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
0034 
0035   const L1GTScales scales_;
0036 
0037   const L1GTSingleCollectionCut collection1Cuts_;
0038   const L1GTSingleCollectionCut collection2Cuts_;
0039   const L1GTSingleCollectionCut collection3Cuts_;
0040 
0041   const bool enable_sanity_checks_;
0042   const bool inv_mass_checks_;
0043 
0044   const L1GTDeltaCut delta12Cuts_;
0045   const L1GTDeltaCut delta13Cuts_;
0046   const L1GTDeltaCut delta23Cuts_;
0047 
0048   const edm::EDGetTokenT<P2GTCandidateCollection> token1_;
0049   const edm::EDGetTokenT<P2GTCandidateCollection> token2_;
0050   const edm::EDGetTokenT<P2GTCandidateCollection> token3_;
0051 };
0052 
0053 L1GTTripleObjectCond::L1GTTripleObjectCond(const edm::ParameterSet& config)
0054     : scales_(config.getParameter<edm::ParameterSet>("scales")),
0055       collection1Cuts_(config.getParameter<edm::ParameterSet>("collection1"), config, scales_),
0056       collection2Cuts_(config.getParameter<edm::ParameterSet>("collection2"), config, scales_),
0057       collection3Cuts_(config.getParameter<edm::ParameterSet>("collection3"), config, scales_),
0058       enable_sanity_checks_(config.getUntrackedParameter<bool>("sanity_checks")),
0059       inv_mass_checks_(config.getUntrackedParameter<bool>("inv_mass_checks")),
0060       delta12Cuts_(
0061           config.getParameter<edm::ParameterSet>("delta12"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
0062       delta13Cuts_(
0063           config.getParameter<edm::ParameterSet>("delta13"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
0064       delta23Cuts_(
0065           config.getParameter<edm::ParameterSet>("delta23"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
0066       token1_(consumes<P2GTCandidateCollection>(collection1Cuts_.tag())),
0067       token2_(collection1Cuts_.tag() == collection2Cuts_.tag()
0068                   ? token1_
0069                   : consumes<P2GTCandidateCollection>(collection2Cuts_.tag())),
0070       token3_(collection1Cuts_.tag() == collection3Cuts_.tag()
0071                   ? token1_
0072                   : (collection2Cuts_.tag() == collection3Cuts_.tag()
0073                          ? token2_
0074                          : consumes<P2GTCandidateCollection>(collection3Cuts_.tag()))) {
0075   produces<P2GTCandidateVectorRef>(collection1Cuts_.tag().instance());
0076 
0077   if (!(collection1Cuts_.tag() == collection2Cuts_.tag())) {
0078     produces<P2GTCandidateVectorRef>(collection2Cuts_.tag().instance());
0079   }
0080 
0081   if (!(collection1Cuts_.tag() == collection3Cuts_.tag()) && !(collection2Cuts_.tag() == collection3Cuts_.tag())) {
0082     produces<P2GTCandidateVectorRef>(collection3Cuts_.tag().instance());
0083   }
0084 
0085   if (inv_mass_checks_) {
0086     produces<InvariantMassErrorCollection>();
0087   }
0088 }
0089 
0090 void L1GTTripleObjectCond::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0091   edm::ParameterSetDescription desc;
0092 
0093   edm::ParameterSetDescription collection1Desc;
0094   L1GTSingleCollectionCut::fillPSetDescription(collection1Desc);
0095   desc.add<edm::ParameterSetDescription>("collection1", collection1Desc);
0096 
0097   edm::ParameterSetDescription collection2Desc;
0098   L1GTSingleCollectionCut::fillPSetDescription(collection2Desc);
0099   desc.add<edm::ParameterSetDescription>("collection2", collection2Desc);
0100 
0101   edm::ParameterSetDescription collection3Desc;
0102   L1GTSingleCollectionCut::fillPSetDescription(collection3Desc);
0103   desc.add<edm::ParameterSetDescription>("collection3", collection3Desc);
0104 
0105   edm::ParameterSetDescription scalesDesc;
0106   L1GTScales::fillPSetDescription(scalesDesc);
0107   desc.add<edm::ParameterSetDescription>("scales", scalesDesc);
0108 
0109   desc.addUntracked<bool>("sanity_checks", false);
0110   desc.addUntracked<bool>("inv_mass_checks", false);
0111 
0112   edm::ParameterSetDescription delta12Desc;
0113   L1GTDeltaCut::fillPSetDescription(delta12Desc);
0114   desc.add<edm::ParameterSetDescription>("delta12", delta12Desc);
0115 
0116   edm::ParameterSetDescription delta13Desc;
0117   L1GTDeltaCut::fillPSetDescription(delta13Desc);
0118   desc.add<edm::ParameterSetDescription>("delta13", delta13Desc);
0119 
0120   edm::ParameterSetDescription delta23Desc;
0121   L1GTDeltaCut::fillPSetDescription(delta23Desc);
0122   desc.add<edm::ParameterSetDescription>("delta23", delta23Desc);
0123 
0124   L1GTDeltaCut::fillLUTDescriptions(desc);
0125 
0126   descriptions.addWithDefaultLabel(desc);
0127 }
0128 
0129 bool L1GTTripleObjectCond::filter(edm::StreamID, edm::Event& event, const edm::EventSetup& setup) const {
0130   edm::Handle<P2GTCandidateCollection> col1 = event.getHandle(token1_);
0131   edm::Handle<P2GTCandidateCollection> col2 = event.getHandle(token2_);
0132   edm::Handle<P2GTCandidateCollection> col3 = event.getHandle(token3_);
0133 
0134   bool condition_result = false;
0135 
0136   std::set<std::size_t> triggeredIdcs1;
0137   std::set<std::size_t> triggeredIdcs2;
0138   std::set<std::size_t> triggeredIdcs3;
0139 
0140   InvariantMassErrorCollection massErrors;
0141 
0142   for (std::size_t idx1 = 0; idx1 < col1->size(); ++idx1) {
0143     for (std::size_t idx2 = 0; idx2 < col2->size(); ++idx2) {
0144       for (std::size_t idx3 = 0; idx3 < col3->size(); ++idx3) {
0145         // If we're looking at the same collection then we shouldn't use the same object in one comparison.
0146         if (col1.product() == col2.product() && idx1 == idx2) {
0147           continue;
0148         }
0149 
0150         if (col1.product() == col3.product() && idx1 == idx3) {
0151           continue;
0152         }
0153 
0154         if (col2.product() == col3.product() && idx2 == idx3) {
0155           continue;
0156         }
0157 
0158         bool pass = true;
0159         pass &= collection1Cuts_.checkObject(col1->at(idx1));
0160         pass &= collection2Cuts_.checkObject(col2->at(idx2));
0161         pass &= collection3Cuts_.checkObject(col3->at(idx3));
0162         pass &= delta12Cuts_.checkObjects(col1->at(idx1), col2->at(idx2), massErrors);
0163         pass &= delta13Cuts_.checkObjects(col1->at(idx1), col3->at(idx3), massErrors);
0164         pass &= delta23Cuts_.checkObjects(col2->at(idx2), col3->at(idx3), massErrors);
0165 
0166         condition_result |= pass;
0167 
0168         if (pass) {
0169           triggeredIdcs1.emplace(idx1);
0170 
0171           if (col1.product() != col2.product()) {
0172             triggeredIdcs2.emplace(idx2);
0173           } else {
0174             triggeredIdcs1.emplace(idx2);
0175           }
0176 
0177           if (col1.product() != col3.product() && col2.product() != col3.product()) {
0178             triggeredIdcs3.emplace(idx3);
0179           } else if (col1.product() == col3.product()) {
0180             triggeredIdcs1.emplace(idx3);
0181           } else {
0182             triggeredIdcs2.emplace(idx3);
0183           }
0184         }
0185       }
0186     }
0187   }
0188 
0189   if (condition_result) {
0190     std::unique_ptr<P2GTCandidateVectorRef> triggerCol1 = std::make_unique<P2GTCandidateVectorRef>();
0191 
0192     for (std::size_t idx : triggeredIdcs1) {
0193       triggerCol1->push_back(P2GTCandidateRef(col1, idx));
0194     }
0195     event.put(std::move(triggerCol1), collection1Cuts_.tag().instance());
0196 
0197     if (col1.product() != col2.product()) {
0198       std::unique_ptr<P2GTCandidateVectorRef> triggerCol2 = std::make_unique<P2GTCandidateVectorRef>();
0199 
0200       for (std::size_t idx : triggeredIdcs2) {
0201         triggerCol2->push_back(P2GTCandidateRef(col2, idx));
0202       }
0203       event.put(std::move(triggerCol2), collection2Cuts_.tag().instance());
0204     }
0205 
0206     if (col1.product() != col3.product() && col2.product() != col3.product()) {
0207       std::unique_ptr<P2GTCandidateVectorRef> triggerCol3 = std::make_unique<P2GTCandidateVectorRef>();
0208 
0209       for (std::size_t idx : triggeredIdcs3) {
0210         triggerCol3->push_back(P2GTCandidateRef(col3, idx));
0211       }
0212       event.put(std::move(triggerCol3), collection3Cuts_.tag().instance());
0213     }
0214   }
0215 
0216   if (inv_mass_checks_) {
0217     event.put(std::make_unique<InvariantMassErrorCollection>(std::move(massErrors)), "");
0218   }
0219 
0220   return condition_result;
0221 }
0222 
0223 DEFINE_FWK_MODULE(L1GTTripleObjectCond);