CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/HLTrigger/HLTfilters/src/HLTLevel1Pattern.cc

Go to the documentation of this file.
00001 
00015 #include <vector>
00016 
00017 #include "FWCore/Framework/interface/ESWatcher.h"
00018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00019 #include "FWCore/Utilities/interface/InputTag.h"
00020 #include "FWCore/Utilities/interface/Exception.h"
00021 #include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h"
00022 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskTechTrigRcd.h"
00023 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskAlgoTrigRcd.h"
00024 #include "HLTrigger/HLTcore/interface/HLTFilter.h"
00025 
00026 //
00027 // class declaration
00028 //
00029 
00030 class HLTLevel1Pattern : public HLTFilter {
00031 public:
00032   explicit HLTLevel1Pattern(const edm::ParameterSet&);
00033   ~HLTLevel1Pattern();
00034   virtual bool filter(edm::Event&, const edm::EventSetup&);
00035 
00036 private:
00037   edm::InputTag     m_gtReadoutRecord;
00038   std::string       m_triggerBit;
00039   std::vector<int>  m_bunchCrossings;
00040   std::vector<int>  m_triggerPattern;
00041   unsigned int      m_daqPartitions;
00042   unsigned int      m_triggerNumber;
00043   bool              m_triggerAlgo;
00044   bool              m_triggerMasked;
00045   bool              m_ignoreL1Mask;
00046   bool              m_invert;
00047   bool              m_throw;
00048 
00049   edm::ESWatcher<L1GtTriggerMenuRcd>         m_watchL1Menu;
00050   edm::ESWatcher<L1GtTriggerMaskAlgoTrigRcd> m_watchPhysicsMask;
00051   edm::ESWatcher<L1GtTriggerMaskTechTrigRcd> m_watchTechnicalMask;
00052 };
00053 
00054 #include <boost/foreach.hpp>
00055 
00056 #include "FWCore/Framework/interface/EventSetup.h"
00057 #include "FWCore/Framework/interface/ESHandle.h"
00058 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00059 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h"
00060 #include "CondFormats/L1TObjects/interface/L1GtTriggerMask.h"
00061 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00062 
00063 //
00064 // constructors and destructor
00065 //
00066 HLTLevel1Pattern::HLTLevel1Pattern(const edm::ParameterSet & config) :
00067   m_gtReadoutRecord( config.getParameter<edm::InputTag>     ("L1GtReadoutRecordTag") ),
00068   m_triggerBit(      config.getParameter<std::string>       ("triggerBit") ),
00069   m_bunchCrossings(  config.getParameter<std::vector<int> > ("bunchCrossings") ),
00070   m_triggerPattern(  m_bunchCrossings.size(), false ),
00071   m_daqPartitions(   config.getParameter<unsigned int>      ("daqPartitions") ),
00072   m_triggerNumber(   0 ),
00073   m_triggerAlgo(     true ),
00074   m_triggerMasked(   false ),
00075   m_ignoreL1Mask(    config.getParameter<bool>              ("ignoreL1Mask") ),
00076   m_invert(          config.getParameter<bool>              ("invert") ),
00077   m_throw (          config.getParameter<bool>              ("throw" ) )
00078 {
00079   std::vector<int> pattern( config.getParameter<std::vector<int> > ("triggerPattern") );
00080   if (pattern.size() != m_bunchCrossings.size())
00081     throw cms::Exception("Configuration") << "\"bunchCrossings\" and \"triggerPattern\" parameters do not match";
00082 
00083   for (unsigned int i = 0; i < pattern.size(); ++i)
00084     m_triggerPattern[i] = (bool) pattern[i];
00085 }
00086 
00087 HLTLevel1Pattern::~HLTLevel1Pattern()
00088 {
00089 }
00090 
00091 //
00092 // member functions
00093 //
00094 
00095 // ------------ method called to produce the data  ------------
00096 bool
00097 HLTLevel1Pattern::filter(edm::Event& event, const edm::EventSetup& setup)
00098 {
00099   // determine the L1 algo or tech bit to use
00100   if (m_watchL1Menu.check(setup)) {
00101     edm::ESHandle<L1GtTriggerMenu> h_menu;
00102     setup.get<L1GtTriggerMenuRcd>().get(h_menu);
00103 
00104     // look for an Algo L1 bit
00105     const AlgorithmMap & algoMap = h_menu->gtAlgorithmAliasMap();
00106     const AlgorithmMap & techMap = h_menu->gtTechnicalTriggerMap();
00107     AlgorithmMap::const_iterator entry;
00108     if ((entry = algoMap.find(m_triggerBit)) != algoMap.end()) {
00109         m_triggerAlgo = true;
00110         m_triggerNumber = entry->second.algoBitNumber();
00111     } else 
00112     if ((entry = techMap.find(m_triggerBit)) != techMap.end()) {
00113         m_triggerAlgo = false;
00114         m_triggerNumber = entry->second.algoBitNumber();
00115     } else {
00116       if (m_throw) {
00117         throw cms::Exception("Configuration") << "requested L1 trigger \"" << m_triggerBit << "\" does not exist in the current L1 menu";
00118       } else {
00119         return m_invert;
00120       }
00121     }
00122   }
00123 
00124   if (m_triggerAlgo) {
00125     // check the L1 algorithms mask
00126     //  - mask & partition == part. --> fully masked
00127     //  - mask & partition == 0x00  --> fully unmasked
00128     //  - mask & partition != part. --> unmasked in some partitions, consider as unmasked
00129     if (m_watchPhysicsMask.check(setup)) {
00130       edm::ESHandle<L1GtTriggerMask> h_mask;
00131       setup.get<L1GtTriggerMaskAlgoTrigRcd>().get(h_mask);
00132       m_triggerMasked = ((h_mask->gtTriggerMask()[m_triggerNumber] & m_daqPartitions) == m_daqPartitions);
00133     }
00134   } else {
00135     // check the L1 technical triggers mask
00136     //  - mask & partition == part. --> fully masked
00137     //  - mask & partition == 0x00  --> fully unmasked
00138     //  - mask & partition != part. --> unmasked in some partitions, consider as unmasked
00139     if (m_watchTechnicalMask.check(setup)) {
00140       edm::ESHandle<L1GtTriggerMask> h_mask;
00141       setup.get<L1GtTriggerMaskTechTrigRcd>().get(h_mask);
00142       m_triggerMasked = ((h_mask->gtTriggerMask()[m_triggerNumber] & m_daqPartitions) == m_daqPartitions);
00143     }
00144   }
00145 
00146   // is the L1 trigger masked ?
00147   if (not m_ignoreL1Mask and m_triggerMasked)
00148     return m_invert;
00149 
00150   // access the L1 decisions
00151   edm::Handle<L1GlobalTriggerReadoutRecord> h_gtReadoutRecord;
00152   event.getByLabel(m_gtReadoutRecord, h_gtReadoutRecord);
00153 
00154   // check the L1 algorithms results
00155   for (unsigned int i = 0; i < m_bunchCrossings.size(); ++i) {
00156     int bx = m_bunchCrossings[i];
00157     const std::vector<bool> & word = (m_triggerAlgo) ? h_gtReadoutRecord->decisionWord(bx) : h_gtReadoutRecord->technicalTriggerWord(bx);
00158     if (word.empty() or m_triggerNumber >= word.size())
00159       // L1 results not available, bail out
00160       return m_invert;
00161     bool result = word[m_triggerNumber];
00162     if (result != m_triggerPattern[i])
00163       // comparison failed, bail out
00164       return m_invert;
00165   }
00166 
00167   // comparison successful
00168   return not m_invert;
00169 }
00170 
00171 // define as a framework plugin
00172 #include "FWCore/Framework/interface/MakerMacros.h"
00173 DEFINE_FWK_MODULE(HLTLevel1Pattern);