File indexing completed on 2024-04-06 12:20:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include "FWCore/Framework/interface/EventSetup.h"
0013 #include "FWCore/Framework/interface/Frameworkfwd.h"
0014 #include "FWCore/Framework/interface/stream/EDProducer.h"
0015 #include "FWCore/Framework/interface/ESHandle.h"
0016 #include "FWCore/Framework/interface/Event.h"
0017 #include "FWCore/Framework/interface/MakerMacros.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "FWCore/Utilities/interface/EDGetToken.h"
0020 #include "FWCore/Utilities/interface/InputTag.h"
0021 #include "FWCore/Utilities/interface/ESGetToken.h"
0022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0023
0024 #include "CondFormats/L1TObjects/interface/L1TUtmTriggerMenu.h"
0025 #include "CondFormats/DataRecord/interface/L1TUtmTriggerMenuRcd.h"
0026 #include "L1Trigger/L1TGlobal/plugins/TriggerMenuParser.h"
0027
0028 #include <FWCore/ParameterSet/interface/ConfigurationDescriptions.h>
0029 #include <FWCore/ParameterSet/interface/ParameterSetDescription.h>
0030
0031 #include "DataFormats/L1Trigger/interface/BXVector.h"
0032 #include "DataFormats/L1TGlobal/interface/GlobalExtBlk.h"
0033 #include "DataFormats/TCDS/interface/TCDSRecord.h"
0034
0035 #include <vector>
0036
0037 using namespace std;
0038 using namespace edm;
0039 using namespace l1t;
0040
0041
0042
0043
0044
0045 class L1TExtCondProducer : public stream::EDProducer<> {
0046 public:
0047 explicit L1TExtCondProducer(const ParameterSet&);
0048 ~L1TExtCondProducer() override;
0049
0050 static void fillDescriptions(ConfigurationDescriptions& descriptions);
0051
0052 private:
0053 void produce(edm::Event&, const edm::EventSetup&) override;
0054
0055
0056
0057
0058
0059
0060
0061
0062 int bxFirst_;
0063 int bxLast_;
0064
0065 bool setBptxAND_;
0066 bool setBptxPlus_;
0067 bool setBptxMinus_;
0068 bool setBptxOR_;
0069
0070 unsigned long long m_l1GtMenuCacheID;
0071 std::map<std::string, unsigned int> m_extBitMap;
0072
0073 unsigned int m_triggerRulePrefireVetoBit;
0074
0075 bool makeTriggerRulePrefireVetoBit_;
0076 edm::EDGetTokenT<TCDSRecord> tcdsRecordToken_;
0077 edm::InputTag tcdsInputTag_;
0078 edm::ESGetToken<L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd> l1GtMenuToken_;
0079 };
0080
0081
0082
0083
0084 L1TExtCondProducer::L1TExtCondProducer(const ParameterSet& iConfig)
0085 : bxFirst_(iConfig.getParameter<int>("bxFirst")),
0086 bxLast_(iConfig.getParameter<int>("bxLast")),
0087 setBptxAND_(iConfig.getParameter<bool>("setBptxAND")),
0088 setBptxPlus_(iConfig.getParameter<bool>("setBptxPlus")),
0089 setBptxMinus_(iConfig.getParameter<bool>("setBptxMinus")),
0090 setBptxOR_(iConfig.getParameter<bool>("setBptxOR")),
0091 tcdsInputTag_(iConfig.getParameter<edm::InputTag>("tcdsRecordLabel")),
0092 l1GtMenuToken_(esConsumes<L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd>()) {
0093 makeTriggerRulePrefireVetoBit_ = false;
0094
0095 m_triggerRulePrefireVetoBit = GlobalExtBlk::maxExternalConditions - 1;
0096
0097 tcdsRecordToken_ = consumes<TCDSRecord>(tcdsInputTag_);
0098
0099 if (!(tcdsInputTag_ == edm::InputTag(""))) {
0100 makeTriggerRulePrefireVetoBit_ = true;
0101 }
0102
0103
0104 produces<GlobalExtBlkBxCollection>();
0105
0106
0107 m_l1GtMenuCacheID = 0ULL;
0108 }
0109
0110 L1TExtCondProducer::~L1TExtCondProducer() {}
0111
0112
0113
0114
0115
0116
0117 void L1TExtCondProducer::produce(Event& iEvent, const EventSetup& iSetup) {
0118 LogDebug("L1TExtCondProducer") << "L1TExtCondProducer::produce function called...\n";
0119
0120
0121
0122 unsigned long long l1GtMenuCacheID = iSetup.get<L1TUtmTriggerMenuRcd>().cacheIdentifier();
0123
0124 if (m_l1GtMenuCacheID != l1GtMenuCacheID) {
0125 edm::ESHandle<L1TUtmTriggerMenu> l1GtMenu = iSetup.getHandle(l1GtMenuToken_);
0126 const L1TUtmTriggerMenu* utml1GtMenu = l1GtMenu.product();
0127
0128
0129 TriggerMenuParser gtParser = TriggerMenuParser();
0130
0131 std::map<std::string, unsigned int> extBitMap = gtParser.getExternalSignals(utml1GtMenu);
0132
0133 m_l1GtMenuCacheID = l1GtMenuCacheID;
0134 m_extBitMap = extBitMap;
0135 }
0136
0137 edm::Handle<TCDSRecord> tcdsRecordH;
0138 iEvent.getByToken(tcdsRecordToken_, tcdsRecordH);
0139 makeTriggerRulePrefireVetoBit_ = makeTriggerRulePrefireVetoBit_ && tcdsRecordH.isValid();
0140
0141 bool TriggerRulePrefireVetoBit(false);
0142
0143
0144 if (iEvent.isRealData() && makeTriggerRulePrefireVetoBit_) {
0145 const auto& tcdsRecord = *tcdsRecordH.product();
0146
0147 uint64_t thisEvent = (tcdsRecord.getBXID() - 1) + tcdsRecord.getOrbitNr() * 3564ull;
0148
0149 std::vector<uint64_t> eventHistory;
0150 for (auto&& l1a : tcdsRecord.getFullL1aHistory()) {
0151 eventHistory.push_back(thisEvent - ((l1a.getBXID() - 1) + l1a.getOrbitNr() * 3564ull));
0152 }
0153
0154
0155 if (eventHistory.size() >= 4) {
0156
0157 if (eventHistory[0] < 3ull) {
0158 edm::LogError("L1TExtCondProducer") << "Found an L1A in an impossible location?! (1 in 3)";
0159 }
0160
0161 if (eventHistory[0] == 3ull)
0162 TriggerRulePrefireVetoBit = true;
0163
0164
0165 if (eventHistory[0] < 25ull and eventHistory[1] < 25ull) {
0166 edm::LogError("L1TExtCondProducer") << "Found an L1A in an impossible location?! (2 in 25)";
0167 }
0168 if (eventHistory[0] < 25ull and eventHistory[1] == 25ull)
0169 TriggerRulePrefireVetoBit = true;
0170
0171
0172 if (eventHistory[0] < 100ull and eventHistory[1] < 100ull and eventHistory[2] <= 100ull) {
0173 if (eventHistory[2] == 100ull)
0174 TriggerRulePrefireVetoBit = true;
0175 else
0176 edm::LogError("L1TExtCondProducer") << "Found an L1A in an impossible location?! (3 in 100)";
0177 }
0178
0179
0180 if (eventHistory[0] < 240ull and eventHistory[1] < 240ull and eventHistory[2] < 240ull and
0181 eventHistory[3] <= 240ull) {
0182 if (eventHistory[3] == 240ull)
0183 TriggerRulePrefireVetoBit = true;
0184 else
0185 edm::LogError("L1TExtCondProducer") << "Found an L1A in an impossible location?! (4 in 240)";
0186 }
0187 }
0188 }
0189
0190 GlobalExtBlk extCond_bx;
0191
0192
0193 std::unique_ptr<GlobalExtBlkBxCollection> extCond(new GlobalExtBlkBxCollection(0, bxFirst_, bxLast_));
0194
0195 bool foundBptxAND = (m_extBitMap.find("BPTX_plus_AND_minus.v0") != m_extBitMap.end());
0196 bool foundBptxPlus = (m_extBitMap.find("BPTX_plus.v0") != m_extBitMap.end());
0197 bool foundBptxMinus = (m_extBitMap.find("BPTX_minus.v0") != m_extBitMap.end());
0198 bool foundBptxOR = (m_extBitMap.find("BPTX_plus_OR_minus.v0") != m_extBitMap.end());
0199
0200
0201 if (setBptxAND_ && foundBptxAND)
0202 extCond_bx.setExternalDecision(m_extBitMap["BPTX_plus_AND_minus.v0"], true);
0203 if (setBptxPlus_ && foundBptxPlus)
0204 extCond_bx.setExternalDecision(m_extBitMap["BPTX_plus.v0"], true);
0205 if (setBptxMinus_ && foundBptxMinus)
0206 extCond_bx.setExternalDecision(m_extBitMap["BPTX_minus.v0"], true);
0207 if (setBptxOR_ && foundBptxOR)
0208 extCond_bx.setExternalDecision(m_extBitMap["BPTX_plus_OR_minus.v0"], true);
0209
0210
0211 foundBptxAND = (m_extBitMap.find("ZeroBias_BPTX_AND_VME") != m_extBitMap.end());
0212 foundBptxPlus = (m_extBitMap.find("BPTX_B1_VME") != m_extBitMap.end());
0213 foundBptxMinus = (m_extBitMap.find("BPTX_B2_VME") != m_extBitMap.end());
0214 foundBptxOR = (m_extBitMap.find("BPTX_OR_VME") != m_extBitMap.end());
0215
0216
0217 if (setBptxAND_ && foundBptxAND)
0218 extCond_bx.setExternalDecision(m_extBitMap["ZeroBias_BPTX_AND_VME"], true);
0219 if (setBptxPlus_ && foundBptxPlus)
0220 extCond_bx.setExternalDecision(m_extBitMap["BPTX_B1_VME"], true);
0221 if (setBptxMinus_ && foundBptxMinus)
0222 extCond_bx.setExternalDecision(m_extBitMap["BPTX_B2_VME"], true);
0223 if (setBptxOR_ && foundBptxOR)
0224 extCond_bx.setExternalDecision(m_extBitMap["BPTX_OR_VME"], true);
0225
0226
0227 if (TriggerRulePrefireVetoBit)
0228 extCond_bx.setExternalDecision(m_triggerRulePrefireVetoBit, true);
0229
0230
0231 for (int iBx = bxFirst_; iBx <= bxLast_; iBx++) {
0232 extCond->push_back(iBx, extCond_bx);
0233 }
0234
0235 iEvent.put(std::move(extCond));
0236 }
0237
0238
0239 void L1TExtCondProducer::fillDescriptions(ConfigurationDescriptions& descriptions) {
0240
0241 edm::ParameterSetDescription desc;
0242 desc.add<bool>("setBptxMinus", true);
0243 desc.add<bool>("setBptxAND", true);
0244 desc.add<int>("bxFirst", -2);
0245 desc.add<bool>("setBptxOR", true);
0246 desc.add<int>("bxLast", 2);
0247 desc.add<bool>("setBptxPlus", true);
0248 desc.add<edm::InputTag>("tcdsRecordLabel", edm::InputTag(""));
0249 descriptions.add("simGtExtFakeProd", desc);
0250 }
0251
0252
0253 DEFINE_FWK_MODULE(L1TExtCondProducer);