CMS 3D CMS Logo

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