Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:12:57

0001 #include "DQMOffline/L1Trigger/interface/L1TCommon.h"
0002 #include "DataFormats/Math/interface/deltaR.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 #include <iostream>
0006 
0007 namespace dqmoffline {
0008   namespace l1t {
0009 
0010     std::vector<unsigned int> getTriggerIndices(const std::vector<std::string> &requestedTriggers,
0011                                                 const std::vector<std::string> &triggersInEvent) {
0012       std::vector<unsigned int> triggerIndices;
0013 
0014       for (const auto &requestedTriggerName : requestedTriggers) {
0015         std::string name(requestedTriggerName);
0016         std::size_t wildcarPosition = name.find('*');
0017         if (wildcarPosition != std::string::npos) {
0018           // take everything up to the wildcard
0019           name = name.substr(0, wildcarPosition - 1);
0020         }
0021 
0022         unsigned int triggerIndex = 0;
0023         for (const auto &triggerName : triggersInEvent) {
0024           if (triggerName.find(name) != std::string::npos) {
0025             triggerIndices.push_back(triggerIndex);
0026             break;
0027           }
0028           ++triggerIndex;
0029         }
0030       }
0031       return triggerIndices;
0032     }
0033 
0034     std::vector<bool> getTriggerResults(const std::vector<unsigned int> &triggers,
0035                                         const edm::TriggerResults &triggerResults) {
0036       std::vector<bool> results;
0037       results.resize(triggers.size());
0038 
0039       for (unsigned int index = 0; index < triggers.size(); ++index) {
0040         if (triggers[index] >= triggerResults.size()) {
0041           results[index] = false;
0042           continue;
0043         }
0044 
0045         if (triggerResults.accept(triggers[index])) {
0046           results[index] = true;
0047         } else {
0048           results[index] = false;
0049         }
0050       }
0051       return results;
0052     }
0053 
0054     std::vector<unsigned int> getFiredTriggerIndices(const std::vector<unsigned int> &triggers,
0055                                                      const std::vector<bool> &triggerResults) {
0056       std::vector<unsigned int> results;
0057       // std::copy_if instead?
0058       for (unsigned int i = 0; i < triggerResults.size(); ++i) {
0059         if (triggerResults[i]) {
0060           results.push_back(triggers[i]);
0061         }
0062       }
0063       return results;
0064     }
0065 
0066     bool passesAnyTriggerFromList(const std::vector<unsigned int> &triggers,
0067                                   const edm::TriggerResults &triggerResults) {
0068       std::vector<bool> results = dqmoffline::l1t::getTriggerResults(triggers, triggerResults);
0069       if (std::count(results.begin(), results.end(), true) == 0) {
0070         return false;
0071       }
0072       return true;
0073     }
0074 
0075     trigger::TriggerObjectCollection getTriggerObjects(const std::vector<edm::InputTag> &hltFilters,
0076                                                        const trigger::TriggerEvent &triggerEvent) {
0077       trigger::TriggerObjectCollection triggerObjects = triggerEvent.getObjects();
0078       trigger::TriggerObjectCollection results;
0079 
0080       for (const auto &filter : hltFilters) {
0081         const unsigned filterIndex = triggerEvent.filterIndex(filter);
0082 
0083         if (filterIndex < triggerEvent.sizeFilters()) {
0084           const trigger::Keys &triggerKeys(triggerEvent.filterKeys(filterIndex));
0085           const size_t nTriggers = triggerEvent.filterIds(filterIndex).size();
0086           for (size_t i = 0; i < nTriggers; ++i) {
0087             results.push_back(triggerObjects[triggerKeys[i]]);
0088           }
0089         }
0090       }
0091       // sort by ET
0092       typedef trigger::TriggerObject trigObj;
0093       std::sort(results.begin(), results.end(), [](const trigObj &obj1, const trigObj &obj2) {
0094         return obj1.et() > obj2.et();
0095       });
0096       return results;
0097     }
0098 
0099     std::vector<edm::InputTag> getHLTFilters(const std::vector<unsigned int> &triggers,
0100                                              const HLTConfigProvider &hltConfig,
0101                                              const std::string triggerProcess) {
0102       std::vector<edm::InputTag> results;
0103       for (auto trigger : triggers) {
0104         unsigned int hltIndexOffset(2);
0105         unsigned int moduleIndex = hltConfig.size(trigger) - hltIndexOffset;
0106         const std::vector<std::string> &modules(hltConfig.moduleLabels(trigger));
0107         std::string module(modules[moduleIndex]);
0108         edm::InputTag filterInputTag = edm::InputTag(module, "", triggerProcess);
0109         results.push_back(filterInputTag);
0110       }
0111       return results;
0112     }
0113 
0114     trigger::TriggerObjectCollection getMatchedTriggerObjects(double eta,
0115                                                               double phi,
0116                                                               double maxDeltaR,
0117                                                               const trigger::TriggerObjectCollection triggerObjects) {
0118       trigger::TriggerObjectCollection results;
0119       typedef trigger::TriggerObject trigObj;
0120       std::copy_if(
0121           triggerObjects.begin(),
0122           triggerObjects.end(),
0123           std::back_inserter(results),
0124           [eta, phi, maxDeltaR](const trigObj &obj) { return deltaR(obj.eta(), obj.phi(), eta, phi) < maxDeltaR; });
0125       return results;
0126     }
0127 
0128   }  // namespace l1t
0129 }  // namespace dqmoffline