File indexing completed on 2023-03-17 11:12:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/Framework/interface/Frameworkfwd.h"
0016 #include "FWCore/Framework/interface/stream/EDProducer.h"
0017 #include "FWCore/Framework/interface/ESHandle.h"
0018 #include "FWCore/Framework/interface/Event.h"
0019 #include "FWCore/Framework/interface/MakerMacros.h"
0020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0021 #include "FWCore/Utilities/interface/EDGetToken.h"
0022 #include "FWCore/Utilities/interface/InputTag.h"
0023 #include "FWCore/Utilities/interface/ESGetToken.h"
0024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0025
0026 #include "CondFormats/L1TObjects/interface/L1TUtmTriggerMenu.h"
0027 #include "CondFormats/DataRecord/interface/L1TUtmTriggerMenuRcd.h"
0028 #include "L1Trigger/L1TGlobal/plugins/TriggerMenuParser.h"
0029
0030 #include <FWCore/ParameterSet/interface/ConfigurationDescriptions.h>
0031 #include <FWCore/ParameterSet/interface/ParameterSetDescription.h>
0032
0033
0034
0035 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
0036
0037 #include "DataFormats/L1Trigger/interface/BXVector.h"
0038
0039 #include "DataFormats/L1TGlobal/interface/GlobalExtBlk.h"
0040
0041 using namespace std;
0042 using namespace edm;
0043 using namespace l1t;
0044
0045
0046
0047
0048
0049 class L1TExtCondLegacyToStage2 : public stream::EDProducer<> {
0050 public:
0051 explicit L1TExtCondLegacyToStage2(const ParameterSet&);
0052 ~L1TExtCondLegacyToStage2() override;
0053
0054 static void fillDescriptions(ConfigurationDescriptions& descriptions);
0055
0056 private:
0057 void produce(edm::Event&, const edm::EventSetup&) override;
0058
0059
0060
0061
0062
0063
0064
0065
0066 int bxFirst_;
0067 int bxLast_;
0068
0069
0070 edm::EDGetTokenT<L1GlobalTriggerReadoutRecord> gtReadoutRecordToken;
0071
0072
0073 edm::ESGetToken<L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd> l1GtMenuToken;
0074
0075 unsigned long long m_l1GtMenuCacheID;
0076 std::map<std::string, unsigned int> m_extBitMap;
0077 };
0078
0079
0080
0081
0082 L1TExtCondLegacyToStage2::L1TExtCondLegacyToStage2(const ParameterSet& iConfig)
0083 : bxFirst_(iConfig.getParameter<int>("bxFirst")),
0084 bxLast_(iConfig.getParameter<int>("bxLast")),
0085 gtReadoutRecordToken(
0086 consumes<L1GlobalTriggerReadoutRecord>(iConfig.getParameter<edm::InputTag>("LegacyGtReadoutRecord"))),
0087 l1GtMenuToken(esConsumes<L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd>()) {
0088
0089 produces<GlobalExtBlkBxCollection>();
0090
0091 m_l1GtMenuCacheID = 0ULL;
0092 }
0093
0094 L1TExtCondLegacyToStage2::~L1TExtCondLegacyToStage2() {}
0095
0096
0097
0098
0099
0100
0101 void L1TExtCondLegacyToStage2::produce(Event& iEvent, const EventSetup& iSetup) {
0102 LogDebug("L1TExtCondLegacyToStage2") << "L1TExtCondLegacyToStage2::produce function called...\n";
0103
0104
0105
0106 unsigned long long l1GtMenuCacheID = iSetup.get<L1TUtmTriggerMenuRcd>().cacheIdentifier();
0107
0108 if (m_l1GtMenuCacheID != l1GtMenuCacheID) {
0109 edm::ESHandle<L1TUtmTriggerMenu> l1GtMenu = iSetup.getHandle(l1GtMenuToken);
0110 const L1TUtmTriggerMenu* utml1GtMenu = l1GtMenu.product();
0111
0112
0113 TriggerMenuParser gtParser = TriggerMenuParser();
0114
0115 std::map<std::string, unsigned int> extBitMap = gtParser.getExternalSignals(utml1GtMenu);
0116
0117 m_l1GtMenuCacheID = l1GtMenuCacheID;
0118 m_extBitMap = extBitMap;
0119 }
0120
0121 bool foundBptxAND = (m_extBitMap.find("BPTX_plus_AND_minus.v0") != m_extBitMap.end());
0122 bool foundBptxPlus = (m_extBitMap.find("BPTX_plus.v0") != m_extBitMap.end());
0123 bool foundBptxMinus = (m_extBitMap.find("BPTX_minus.v0") != m_extBitMap.end());
0124 bool foundBptxOR = (m_extBitMap.find("BPTX_plus_OR_minus.v0") != m_extBitMap.end());
0125
0126 unsigned int bitBptxAND = m_extBitMap["BPTX_plus_AND_minus.v0"];
0127 unsigned int bitBptxPlus = m_extBitMap["BPTX_plus.v0"];
0128 unsigned int bitBptxMinus = m_extBitMap["BPTX_minus.v0"];
0129 unsigned int bitBptxOR = m_extBitMap["BPTX_plus_OR_minus.v0"];
0130
0131 edm::Handle<L1GlobalTriggerReadoutRecord> gtReadoutRecord;
0132 iEvent.getByToken(gtReadoutRecordToken, gtReadoutRecord);
0133
0134
0135 GlobalExtBlk extCond_bx_m2;
0136 GlobalExtBlk extCond_bx_m1;
0137 GlobalExtBlk extCond_bx_0;
0138 GlobalExtBlk extCond_bx_p1;
0139 GlobalExtBlk extCond_bx_p2;
0140
0141 if (gtReadoutRecord.isValid()) {
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157 for (int ibx = 0; ibx < 5; ibx++) {
0158 int useBx = ibx - 2;
0159 if (useBx < bxFirst_ || useBx > bxLast_)
0160 continue;
0161
0162
0163
0164
0165 const TechnicalTriggerWord& gtTTWord = gtReadoutRecord->technicalTriggerWord(useBx);
0166 int tbitNumber = 0;
0167 TechnicalTriggerWord::const_iterator GTtbitItr;
0168 bool passBptxAND = false;
0169 bool passBptxPlus = false;
0170 bool passBptxMinus = false;
0171 bool passBptxOR = false;
0172 for (GTtbitItr = gtTTWord.begin(); GTtbitItr != gtTTWord.end(); GTtbitItr++) {
0173 int pass_l1t_tech = 0;
0174 if (*GTtbitItr)
0175 pass_l1t_tech = 1;
0176
0177 if (pass_l1t_tech == 1) {
0178 if (tbitNumber == 0)
0179 passBptxAND = true;
0180 else if (tbitNumber == 1)
0181 passBptxPlus = true;
0182 else if (tbitNumber == 2)
0183 passBptxMinus = true;
0184 else if (tbitNumber == 3)
0185 passBptxOR = true;
0186 }
0187
0188 tbitNumber++;
0189 }
0190
0191 if (useBx == -2) {
0192 if (passBptxAND && foundBptxAND)
0193 extCond_bx_m2.setExternalDecision(bitBptxAND, true);
0194 if (passBptxPlus && foundBptxPlus)
0195 extCond_bx_m2.setExternalDecision(bitBptxPlus, true);
0196 if (passBptxMinus && foundBptxMinus)
0197 extCond_bx_m2.setExternalDecision(bitBptxMinus, true);
0198 if (passBptxOR && foundBptxOR)
0199 extCond_bx_m2.setExternalDecision(bitBptxOR, true);
0200 } else if (useBx == -1) {
0201 if (passBptxAND && foundBptxAND)
0202 extCond_bx_m1.setExternalDecision(bitBptxAND, true);
0203 if (passBptxPlus && foundBptxPlus)
0204 extCond_bx_m1.setExternalDecision(bitBptxPlus, true);
0205 if (passBptxMinus && foundBptxMinus)
0206 extCond_bx_m1.setExternalDecision(bitBptxMinus, true);
0207 if (passBptxOR && foundBptxOR)
0208 extCond_bx_m1.setExternalDecision(bitBptxOR, true);
0209 } else if (useBx == 0) {
0210 if (passBptxAND && foundBptxAND)
0211 extCond_bx_0.setExternalDecision(bitBptxAND, true);
0212 if (passBptxPlus && foundBptxPlus)
0213 extCond_bx_0.setExternalDecision(bitBptxPlus, true);
0214 if (passBptxMinus && foundBptxMinus)
0215 extCond_bx_0.setExternalDecision(bitBptxMinus, true);
0216 if (passBptxOR && foundBptxOR)
0217 extCond_bx_0.setExternalDecision(bitBptxOR, true);
0218 } else if (useBx == 1) {
0219 if (passBptxAND && foundBptxAND)
0220 extCond_bx_p1.setExternalDecision(bitBptxAND, true);
0221 if (passBptxPlus && foundBptxPlus)
0222 extCond_bx_p1.setExternalDecision(bitBptxPlus, true);
0223 if (passBptxMinus && foundBptxMinus)
0224 extCond_bx_p1.setExternalDecision(bitBptxMinus, true);
0225 if (passBptxOR && foundBptxOR)
0226 extCond_bx_p1.setExternalDecision(bitBptxOR, true);
0227 } else if (useBx == 2) {
0228 if (passBptxAND && foundBptxAND)
0229 extCond_bx_p2.setExternalDecision(bitBptxAND, true);
0230 if (passBptxPlus && foundBptxPlus)
0231 extCond_bx_p2.setExternalDecision(bitBptxPlus, true);
0232 if (passBptxMinus && foundBptxMinus)
0233 extCond_bx_p2.setExternalDecision(bitBptxMinus, true);
0234 if (passBptxOR && foundBptxOR)
0235 extCond_bx_p2.setExternalDecision(bitBptxOR, true);
0236 }
0237 }
0238 } else {
0239 LogWarning("MissingProduct") << "Input L1GlobalTriggerReadoutRecord collection not found\n";
0240 }
0241
0242
0243 std::unique_ptr<GlobalExtBlkBxCollection> extCond(new GlobalExtBlkBxCollection(0, bxFirst_, bxLast_));
0244
0245
0246 if (-2 >= bxFirst_ && -2 <= bxLast_)
0247 extCond->push_back(-2, extCond_bx_m2);
0248 if (-1 >= bxFirst_ && -1 <= bxLast_)
0249 extCond->push_back(-1, extCond_bx_m1);
0250 if (0 >= bxFirst_ && 0 <= bxLast_)
0251 extCond->push_back(0, extCond_bx_0);
0252 if (1 >= bxFirst_ && 1 <= bxLast_)
0253 extCond->push_back(1, extCond_bx_p1);
0254 if (2 >= bxFirst_ && 2 <= bxLast_)
0255 extCond->push_back(2, extCond_bx_p2);
0256
0257 iEvent.put(std::move(extCond));
0258 }
0259
0260
0261 void L1TExtCondLegacyToStage2::fillDescriptions(ConfigurationDescriptions& descriptions) {
0262
0263 edm::ParameterSetDescription desc;
0264 desc.add<int>("bxFirst", -2);
0265 desc.add<int>("bxLast", 2);
0266 desc.add<edm::InputTag>("LegacyGtReadoutRecord", edm::InputTag("unpackLegacyGtDigis"));
0267 descriptions.add("l1GtExtCondLegacyToStage2", desc);
0268 }
0269
0270
0271 DEFINE_FWK_MODULE(L1TExtCondLegacyToStage2);