Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:02

0001 /**
0002  * \class L1GtBeamModeFilter
0003  *
0004  *
0005  * Description: see class header.
0006  *
0007  *
0008  * \author: Vasile Mihai Ghete - HEPHY Vienna
0009  *
0010  *
0011  */
0012 
0013 // this class header
0014 #include "L1Trigger/GlobalTriggerAnalyzer/interface/L1GtBeamModeFilter.h"
0015 
0016 // system include files
0017 #include <vector>
0018 #include <iostream>
0019 
0020 // user include files
0021 #include "FWCore/Framework/interface/Event.h"
0022 #include "FWCore/Framework/interface/EventSetup.h"
0023 #include "FWCore/Framework/interface/Run.h"
0024 
0025 #include "DataFormats/Common/interface/Handle.h"
0026 
0027 #include "DataFormats/Common/interface/ConditionsInEdm.h"
0028 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerEvmReadoutRecord.h"
0029 
0030 #include "FWCore/Utilities/interface/InputTag.h"
0031 
0032 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0033 #include "FWCore/MessageLogger/interface/MessageDrop.h"
0034 #include <cstdint>
0035 
0036 // constructor(s)
0037 L1GtBeamModeFilter::L1GtBeamModeFilter(const edm::ParameterSet& parSet)
0038     :
0039 
0040       m_condInEdmInputTag(parSet.getParameter<edm::InputTag>("CondInEdmInputTag")),
0041       m_l1GtEvmReadoutRecordTag(parSet.getParameter<edm::InputTag>("L1GtEvmReadoutRecordTag")),
0042       m_allowedBeamMode(parSet.getParameter<std::vector<unsigned int> >("AllowedBeamMode")),
0043       m_invertResult(parSet.getParameter<bool>("InvertResult")),
0044       m_isDebugEnabled(edm::isDebugEnabled()) {
0045   if (m_isDebugEnabled) {
0046     LogDebug("L1GtBeamModeFilter") << std::endl;
0047 
0048     LogTrace("L1GtBeamModeFilter") << "\nInput tag for ConditionsInEdm product: " << m_condInEdmInputTag
0049                                    << "\nInput tag for L1 GT EVM record:        " << m_l1GtEvmReadoutRecordTag
0050                                    << "\nAllowed beam modes:" << std::endl;
0051 
0052     for (std::vector<unsigned int>::const_iterator itMode = m_allowedBeamMode.begin();
0053          itMode != m_allowedBeamMode.end();
0054          ++itMode) {
0055       LogTrace("L1GtBeamModeFilter") << "  " << (*itMode) << std::endl;
0056     }
0057 
0058     LogTrace("L1GtBeamModeFilter") << "\nInvert result (use as NOT filter): " << m_invertResult << std::endl;
0059 
0060     LogTrace("L1GtBeamModeFilter") << std::endl;
0061   }
0062 }
0063 
0064 // destructor
0065 L1GtBeamModeFilter::~L1GtBeamModeFilter() {
0066   // empty now
0067 }
0068 
0069 // member functions
0070 
0071 bool L1GtBeamModeFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& evSetup) const {
0072   // initialize filter result
0073   bool filterResult = false;
0074 
0075   // for MC samples, return always true (not even checking validity of L1GlobalTriggerEvmReadoutRecord)
0076   // eventually, the BST information will be filled also in MC simulation to spare this check
0077 
0078   if (!(iEvent.isRealData())) {
0079     //LogDebug("L1GtBeamModeFilter") << "\nRunning on MC sample."
0080     //        << "\nAll events are automatically selected, without testing the beam mode"
0081     //        << "\n" << std::endl;
0082 
0083     if (m_invertResult) {
0084       return false;
0085     } else {
0086       return true;
0087     }
0088   }
0089 
0090   // data
0091 
0092   // initialize beam mode value
0093   uint16_t beamModeValue = 0;
0094 
0095   // get Run Data - the same code can be run in beginRun, with getByLabel from edm::Run
0096   // TODO should I cache the run/luminosity section? to be decided after moving beamMode to LumiBlock
0097   const edm::Run& iRun = iEvent.getRun();
0098 
0099   // get ConditionsInRunBlock
0100   edm::Handle<edm::ConditionsInRunBlock> condInRunBlock;
0101   iRun.getByLabel(m_condInEdmInputTag, condInRunBlock);
0102 
0103   /// valid ConditionsInRunBlock product
0104   bool condInRunBlockValid = true;
0105 
0106   if (!condInRunBlock.isValid()) {
0107     LogDebug("L1GtBeamModeFilter") << "\nConditionsInRunBlock with \n  " << m_condInEdmInputTag
0108                                    << "\nrequested in configuration, but not found in the event."
0109                                    << "\n"
0110                                    << std::endl;
0111 
0112     condInRunBlockValid = false;
0113 
0114   } else {
0115     beamModeValue = condInRunBlock->beamMode;
0116   }
0117 
0118   // fall through to L1GlobalTriggerEvmReadoutRecord if ConditionsInRunBlock
0119   // not available
0120   if (!condInRunBlockValid) {
0121     // get L1GlobalTriggerEvmReadoutRecord and beam mode
0122     edm::Handle<L1GlobalTriggerEvmReadoutRecord> gtEvmReadoutRecord;
0123     iEvent.getByLabel(m_l1GtEvmReadoutRecordTag, gtEvmReadoutRecord);
0124 
0125     if (!gtEvmReadoutRecord.isValid()) {
0126       LogDebug("L1GtBeamModeFilter") << "\nL1GlobalTriggerEvmReadoutRecord with input tag " << m_l1GtEvmReadoutRecordTag
0127                                      << "\nrequested in configuration, but not found in the event." << std::endl;
0128 
0129       // both products are missing, return false for both normal and inverted result
0130       return false;
0131 
0132     } else {
0133       beamModeValue = (gtEvmReadoutRecord->gtfeWord()).beamMode();
0134     }
0135   }
0136 
0137   LogDebug("L1GtBeamModeFilter") << "\nBeam mode: " << beamModeValue << std::endl;
0138 
0139   for (std::vector<unsigned int>::const_iterator itMode = m_allowedBeamMode.begin(); itMode != m_allowedBeamMode.end();
0140        ++itMode) {
0141     if (beamModeValue == (*itMode)) {
0142       filterResult = true;
0143 
0144       //LogTrace("L1GtBeamModeFilter") << "Event selected - beam mode: "
0145       //        << beamModeValue << "\n" << std::endl;
0146 
0147       break;
0148     }
0149   }
0150 
0151   //
0152 
0153   if (m_invertResult) {
0154     filterResult = !filterResult;
0155   }
0156 
0157   return filterResult;
0158 }