File indexing completed on 2024-07-03 04:18:04
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 "L1GTCorrelationalCut.h"
0017 #include "L1GT3BodyCut.h"
0018 #include "L1GTSingleInOutLUT.h"
0019
0020 #include <set>
0021
0022 #include <ap_int.h>
0023
0024 using namespace l1t;
0025
0026 class L1GTTripleObjectCond : public edm::global::EDFilter<> {
0027 public:
0028 explicit L1GTTripleObjectCond(const edm::ParameterSet&);
0029 ~L1GTTripleObjectCond() override = default;
0030
0031 static void fillDescriptions(edm::ConfigurationDescriptions&);
0032
0033 private:
0034 bool filter(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
0035
0036 const L1GTScales scales_;
0037
0038 const L1GTSingleCollectionCut collection1Cuts_;
0039 const L1GTSingleCollectionCut collection2Cuts_;
0040 const L1GTSingleCollectionCut collection3Cuts_;
0041
0042 const bool enable_sanity_checks_;
0043 const bool inv_mass_checks_;
0044
0045 const L1GTCorrelationalCut correl12Cuts_;
0046 const L1GTCorrelationalCut correl13Cuts_;
0047 const L1GTCorrelationalCut correl23Cuts_;
0048
0049 const L1GT3BodyCut correl123Cuts_;
0050
0051 const edm::EDGetTokenT<P2GTCandidateCollection> token1_;
0052 const edm::EDGetTokenT<P2GTCandidateCollection> token2_;
0053 const edm::EDGetTokenT<P2GTCandidateCollection> token3_;
0054 const edm::EDGetTokenT<P2GTCandidateCollection> primVertToken_;
0055 };
0056
0057 L1GTTripleObjectCond::L1GTTripleObjectCond(const edm::ParameterSet& config)
0058 : scales_(config.getParameter<edm::ParameterSet>("scales")),
0059 collection1Cuts_(config.getParameter<edm::ParameterSet>("collection1"), config, scales_),
0060 collection2Cuts_(config.getParameter<edm::ParameterSet>("collection2"), config, scales_),
0061 collection3Cuts_(config.getParameter<edm::ParameterSet>("collection3"), config, scales_),
0062 enable_sanity_checks_(config.getUntrackedParameter<bool>("sanity_checks")),
0063 inv_mass_checks_(config.getUntrackedParameter<bool>("inv_mass_checks")),
0064 correl12Cuts_(
0065 config.getParameter<edm::ParameterSet>("correl12"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
0066 correl13Cuts_(
0067 config.getParameter<edm::ParameterSet>("correl13"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
0068 correl23Cuts_(
0069 config.getParameter<edm::ParameterSet>("correl23"), config, scales_, enable_sanity_checks_, inv_mass_checks_),
0070 correl123Cuts_(config, config, scales_, inv_mass_checks_),
0071 token1_(consumes<P2GTCandidateCollection>(collection1Cuts_.tag())),
0072 token2_(collection1Cuts_.tag() == collection2Cuts_.tag()
0073 ? token1_
0074 : consumes<P2GTCandidateCollection>(collection2Cuts_.tag())),
0075 token3_(collection1Cuts_.tag() == collection3Cuts_.tag()
0076 ? token1_
0077 : (collection2Cuts_.tag() == collection3Cuts_.tag()
0078 ? token2_
0079 : consumes<P2GTCandidateCollection>(collection3Cuts_.tag()))),
0080 primVertToken_(consumes<P2GTCandidateCollection>(config.getParameter<edm::InputTag>("primVertTag"))) {
0081 produces<P2GTCandidateVectorRef>(collection1Cuts_.tag().instance());
0082
0083 if (!(collection1Cuts_.tag() == collection2Cuts_.tag())) {
0084 produces<P2GTCandidateVectorRef>(collection2Cuts_.tag().instance());
0085 }
0086
0087 if (!(collection1Cuts_.tag() == collection3Cuts_.tag()) && !(collection2Cuts_.tag() == collection3Cuts_.tag())) {
0088 produces<P2GTCandidateVectorRef>(collection3Cuts_.tag().instance());
0089 }
0090
0091 if (inv_mass_checks_) {
0092 produces<InvariantMassErrorCollection>();
0093 }
0094 }
0095
0096 void L1GTTripleObjectCond::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0097 edm::ParameterSetDescription desc;
0098
0099 edm::ParameterSetDescription collection1Desc;
0100 L1GTSingleCollectionCut::fillPSetDescription(collection1Desc);
0101 desc.add<edm::ParameterSetDescription>("collection1", collection1Desc);
0102
0103 edm::ParameterSetDescription collection2Desc;
0104 L1GTSingleCollectionCut::fillPSetDescription(collection2Desc);
0105 desc.add<edm::ParameterSetDescription>("collection2", collection2Desc);
0106
0107 edm::ParameterSetDescription collection3Desc;
0108 L1GTSingleCollectionCut::fillPSetDescription(collection3Desc);
0109 desc.add<edm::ParameterSetDescription>("collection3", collection3Desc);
0110
0111 edm::ParameterSetDescription scalesDesc;
0112 L1GTScales::fillPSetDescription(scalesDesc);
0113 desc.add<edm::ParameterSetDescription>("scales", scalesDesc);
0114
0115 desc.add<edm::InputTag>("primVertTag");
0116
0117 desc.addUntracked<bool>("sanity_checks", false);
0118 desc.addUntracked<bool>("inv_mass_checks", false);
0119
0120 edm::ParameterSetDescription correl12Desc;
0121 L1GTCorrelationalCut::fillPSetDescription(correl12Desc);
0122 desc.add<edm::ParameterSetDescription>("correl12", correl12Desc);
0123
0124 edm::ParameterSetDescription correl13Desc;
0125 L1GTCorrelationalCut::fillPSetDescription(correl13Desc);
0126 desc.add<edm::ParameterSetDescription>("correl13", correl13Desc);
0127
0128 edm::ParameterSetDescription correl23Desc;
0129 L1GTCorrelationalCut::fillPSetDescription(correl23Desc);
0130 desc.add<edm::ParameterSetDescription>("correl23", correl23Desc);
0131
0132 L1GT3BodyCut::fillPSetDescription(desc);
0133
0134 L1GTCorrelationalCut::fillLUTDescriptions(desc);
0135
0136 descriptions.addWithDefaultLabel(desc);
0137 }
0138
0139 bool L1GTTripleObjectCond::filter(edm::StreamID, edm::Event& event, const edm::EventSetup& setup) const {
0140 edm::Handle<P2GTCandidateCollection> col1 = event.getHandle(token1_);
0141 edm::Handle<P2GTCandidateCollection> col2 = event.getHandle(token2_);
0142 edm::Handle<P2GTCandidateCollection> col3 = event.getHandle(token3_);
0143 edm::Handle<P2GTCandidateCollection> primVertCol = event.getHandle(primVertToken_);
0144
0145 bool condition_result = false;
0146
0147 std::set<std::size_t> triggeredIdcs1;
0148 std::set<std::size_t> triggeredIdcs2;
0149 std::set<std::size_t> triggeredIdcs3;
0150
0151 InvariantMassErrorCollection massErrors;
0152
0153 for (std::size_t idx1 = 0; idx1 < col1->size(); ++idx1) {
0154 bool single1Pass = collection1Cuts_.checkObject(col1->at(idx1));
0155 single1Pass &= collection1Cuts_.checkPrimaryVertices(col1->at(idx1), *primVertCol);
0156
0157 for (std::size_t idx2 = 0; idx2 < col2->size(); ++idx2) {
0158 bool single2Pass = collection2Cuts_.checkObject(col2->at(idx2));
0159 single2Pass &= collection2Cuts_.checkPrimaryVertices(col2->at(idx2), *primVertCol);
0160
0161 for (std::size_t idx3 = 0; idx3 < col3->size(); ++idx3) {
0162
0163 if (col1.product() == col2.product() && idx1 == idx2) {
0164 continue;
0165 }
0166
0167 if (col1.product() == col3.product() && idx1 == idx3) {
0168 continue;
0169 }
0170
0171 if (col2.product() == col3.product() && idx2 == idx3) {
0172 continue;
0173 }
0174
0175 bool pass = single1Pass & single2Pass;
0176
0177 pass &= collection3Cuts_.checkObject(col3->at(idx3));
0178 pass &= collection3Cuts_.checkPrimaryVertices(col3->at(idx3), *primVertCol);
0179 pass &= correl12Cuts_.checkObjects(col1->at(idx1), col2->at(idx2), massErrors);
0180 pass &= correl13Cuts_.checkObjects(col1->at(idx1), col3->at(idx3), massErrors);
0181 pass &= correl23Cuts_.checkObjects(col2->at(idx2), col3->at(idx3), massErrors);
0182 pass &= correl123Cuts_.checkObjects(col1->at(idx1), col2->at(idx2), col3->at(idx3), massErrors);
0183
0184 condition_result |= pass;
0185
0186 if (pass) {
0187 triggeredIdcs1.emplace(idx1);
0188
0189 if (col1.product() != col2.product()) {
0190 triggeredIdcs2.emplace(idx2);
0191 } else {
0192 triggeredIdcs1.emplace(idx2);
0193 }
0194
0195 if (col1.product() != col3.product() && col2.product() != col3.product()) {
0196 triggeredIdcs3.emplace(idx3);
0197 } else if (col1.product() == col3.product()) {
0198 triggeredIdcs1.emplace(idx3);
0199 } else {
0200 triggeredIdcs2.emplace(idx3);
0201 }
0202 }
0203 }
0204 }
0205 }
0206
0207 if (condition_result) {
0208 std::unique_ptr<P2GTCandidateVectorRef> triggerCol1 = std::make_unique<P2GTCandidateVectorRef>();
0209
0210 for (std::size_t idx : triggeredIdcs1) {
0211 triggerCol1->push_back(P2GTCandidateRef(col1, idx));
0212 }
0213 event.put(std::move(triggerCol1), collection1Cuts_.tag().instance());
0214
0215 if (col1.product() != col2.product()) {
0216 std::unique_ptr<P2GTCandidateVectorRef> triggerCol2 = std::make_unique<P2GTCandidateVectorRef>();
0217
0218 for (std::size_t idx : triggeredIdcs2) {
0219 triggerCol2->push_back(P2GTCandidateRef(col2, idx));
0220 }
0221 event.put(std::move(triggerCol2), collection2Cuts_.tag().instance());
0222 }
0223
0224 if (col1.product() != col3.product() && col2.product() != col3.product()) {
0225 std::unique_ptr<P2GTCandidateVectorRef> triggerCol3 = std::make_unique<P2GTCandidateVectorRef>();
0226
0227 for (std::size_t idx : triggeredIdcs3) {
0228 triggerCol3->push_back(P2GTCandidateRef(col3, idx));
0229 }
0230 event.put(std::move(triggerCol3), collection3Cuts_.tag().instance());
0231 }
0232 }
0233
0234 if (inv_mass_checks_) {
0235 event.put(std::make_unique<InvariantMassErrorCollection>(std::move(massErrors)), "");
0236 }
0237
0238 return condition_result;
0239 }
0240
0241 DEFINE_FWK_MODULE(L1GTTripleObjectCond);