Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:26:08

0001 // -*- C++ -*-
0002 //
0003 // Package:    L1Trigger/PrefireAnalysis
0004 // Class:      TriggerRulePrefireVetoFilter
0005 //
0006 /**\class TriggerRulePrefireVetoFilter TriggerRulePrefireVetoFilter.cc L1Trigger/PrefireAnalysis/plugins/TriggerRulePrefireVetoFilter.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011     [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Nicholas Charles Smith
0015 //         Created:  Mon, 28 May 2018 15:39:05 GMT
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <iostream>
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/stream/EDFilter.h"
0026 
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029 
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 #include "FWCore/Utilities/interface/StreamID.h"
0032 
0033 #include "DataFormats/TCDS/interface/TCDSRecord.h"
0034 
0035 //
0036 // class declaration
0037 //
0038 
0039 class TriggerRulePrefireVetoFilter : public edm::stream::EDFilter<> {
0040 public:
0041   explicit TriggerRulePrefireVetoFilter(const edm::ParameterSet&);
0042   ~TriggerRulePrefireVetoFilter() override;
0043 
0044   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0045 
0046 private:
0047   void beginStream(edm::StreamID) override;
0048   bool filter(edm::Event&, const edm::EventSetup&) override;
0049   void endStream() override;
0050 
0051   //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
0052   //virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
0053   //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0054   //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0055 
0056   // ----------member data ---------------------------
0057   edm::EDGetTokenT<TCDSRecord> tcdsRecordToken_;
0058 };
0059 
0060 //
0061 // constants, enums and typedefs
0062 //
0063 
0064 //
0065 // static data member definitions
0066 //
0067 
0068 //
0069 // constructors and destructor
0070 //
0071 TriggerRulePrefireVetoFilter::TriggerRulePrefireVetoFilter(const edm::ParameterSet& iConfig)
0072     : tcdsRecordToken_(consumes<TCDSRecord>(iConfig.getParameter<edm::InputTag>("tcdsRecordLabel"))) {
0073   //now do what ever initialization is needed
0074 }
0075 
0076 TriggerRulePrefireVetoFilter::~TriggerRulePrefireVetoFilter() {
0077   // do anything here that needs to be done at destruction time
0078   // (e.g. close files, deallocate resources etc.)
0079 }
0080 
0081 //
0082 // member functions
0083 //
0084 
0085 // ------------ method called on each new Event  ------------
0086 bool TriggerRulePrefireVetoFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0087   edm::Handle<TCDSRecord> tcdsRecordH;
0088   iEvent.getByToken(tcdsRecordToken_, tcdsRecordH);
0089   const auto& tcdsRecord = *tcdsRecordH.product();
0090 
0091   uint64_t thisEvent = (tcdsRecord.getBXID() - 1) + tcdsRecord.getOrbitNr() * 3564ull;
0092 
0093   std::vector<uint64_t> eventHistory;
0094   for (auto&& l1a : tcdsRecord.getFullL1aHistory()) {
0095     eventHistory.push_back(thisEvent - ((l1a.getBXID() - 1) + l1a.getOrbitNr() * 3564ull));
0096   }
0097 
0098   // should be 16 according to TCDSRecord.h, we only care about the last 4
0099   if (eventHistory.size() < 4) {
0100     edm::LogError("TriggerRulePrefireVetoFilter") << "Unexpectedly small L1A history from TCDSRecord";
0101   }
0102 
0103   // No more than 1 L1A in 3 BX
0104   if (eventHistory[0] < 3ull) {
0105     edm::LogError("TriggerRulePrefireVetoFilter") << "Found an L1A in an impossible location?! (1 in 3)";
0106   }
0107   if (eventHistory[0] == 3ull)
0108     return true;
0109 
0110   // No more than 2 L1As in 25 BX
0111   if (eventHistory[0] < 25ull and eventHistory[1] < 25ull) {
0112     edm::LogError("TriggerRulePrefireVetoFilter") << "Found an L1A in an impossible location?! (2 in 25)";
0113   }
0114   if (eventHistory[0] < 25ull and eventHistory[1] == 25ull)
0115     return true;
0116 
0117   // No more than 3 L1As in 100 BX
0118   if (eventHistory[0] < 100ull and eventHistory[1] < 100ull and eventHistory[2] < 100ull) {
0119     edm::LogError("TriggerRulePrefireVetoFilter") << "Found an L1A in an impossible location?! (3 in 100)";
0120   }
0121   if (eventHistory[0] < 100ull and eventHistory[1] < 100ull and eventHistory[2] == 100ull)
0122     return true;
0123 
0124   // No more than 4 L1As in 240 BX
0125   if (eventHistory[0] < 240ull and eventHistory[1] < 240ull and eventHistory[2] < 240ull and eventHistory[3] < 240ull) {
0126     edm::LogError("TriggerRulePrefireVetoFilter") << "Found an L1A in an impossible location?! (4 in 240)";
0127   }
0128   if (eventHistory[0] < 240ull and eventHistory[1] < 240ull and eventHistory[2] < 240ull and eventHistory[3] == 240ull)
0129     return true;
0130 
0131   return false;
0132 }
0133 
0134 // ------------ method called once each stream before processing any runs, lumis or events  ------------
0135 void TriggerRulePrefireVetoFilter::beginStream(edm::StreamID) {}
0136 
0137 // ------------ method called once each stream after processing all runs, lumis and events  ------------
0138 void TriggerRulePrefireVetoFilter::endStream() {}
0139 
0140 // ------------ method called when starting to processes a run  ------------
0141 /*
0142 void
0143 TriggerRulePrefireVetoFilter::beginRun(edm::Run const&, edm::EventSetup const&)
0144 { 
0145 }
0146 */
0147 
0148 // ------------ method called when ending the processing of a run  ------------
0149 /*
0150 void
0151 TriggerRulePrefireVetoFilter::endRun(edm::Run const&, edm::EventSetup const&)
0152 {
0153 }
0154 */
0155 
0156 // ------------ method called when starting to processes a luminosity block  ------------
0157 /*
0158 void
0159 TriggerRulePrefireVetoFilter::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
0160 {
0161 }
0162 */
0163 
0164 // ------------ method called when ending the processing of a luminosity block  ------------
0165 /*
0166 void
0167 TriggerRulePrefireVetoFilter::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
0168 {
0169 }
0170 */
0171 
0172 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0173 void TriggerRulePrefireVetoFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0174   //The following says we do not know what parameters are allowed so do no validation
0175   // Please change this to state exactly what you do use, even if it is no parameters
0176   edm::ParameterSetDescription desc;
0177   desc.setUnknown();
0178   descriptions.addDefault(desc);
0179 }
0180 //define this as a plug-in
0181 DEFINE_FWK_MODULE(TriggerRulePrefireVetoFilter);