CMS 3D CMS Logo

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