File indexing completed on 2023-03-17 11:15:45
0001 #ifndef PhysicsTools_Heppy_TriggerBitChecker_h
0002 #define PhysicsTools_Heppy_TriggerBitChecker_h
0003
0004 #include <vector>
0005 #include <string>
0006 #include <iostream>
0007 #include <cassert>
0008 #include <type_traits>
0009
0010 #include "DataFormats/Common/interface/TriggerResults.h"
0011 #include "DataFormats/PatCandidates/interface/PackedTriggerPrescales.h"
0012 #include "FWCore/Common/interface/EventBase.h"
0013
0014 namespace heppy {
0015
0016 class TriggerBitChecker {
0017 public:
0018 struct pathStruct {
0019 pathStruct(const std::string &s) : pathName(s), first(0), last(99999999) {}
0020 pathStruct() : pathName(), first(0), last(99999999) {}
0021 std::string pathName;
0022 unsigned int first;
0023 unsigned int last;
0024 };
0025
0026 TriggerBitChecker(const std::string &path = "DUMMY");
0027 TriggerBitChecker(const std::vector<std::string> &paths);
0028 ~TriggerBitChecker() {}
0029
0030 bool check(const edm::EventBase &event, const edm::TriggerResults &result) const;
0031
0032 bool check_unprescaled(const edm::EventBase &event,
0033 const edm::TriggerResults &result_tr,
0034 const pat::PackedTriggerPrescales &result) const;
0035
0036
0037
0038 template <typename T = int>
0039 T getprescale(const edm::EventBase &event,
0040 const edm::TriggerResults &result_tr,
0041 const pat::PackedTriggerPrescales &result) const;
0042
0043 private:
0044
0045 std::vector<pathStruct> paths_;
0046
0047 mutable edm::ParameterSetID lastID_;
0048 mutable std::vector<unsigned int> indices_;
0049
0050
0051 void syncIndices(const edm::EventBase &event, const edm::TriggerResults &result) const;
0052 pathStruct returnPathStruct(const std::string &path) const;
0053
0054
0055 void rmstar();
0056 };
0057
0058 template <typename T>
0059 T TriggerBitChecker::getprescale(const edm::EventBase &event,
0060 const edm::TriggerResults &result_tr,
0061 const pat::PackedTriggerPrescales &result) const {
0062 static_assert(std::is_same_v<T, double>,
0063 "\n\n\tPlease use getprescale<double> "
0064 "(other types for trigger prescales are not supported anymore by TriggerBitChecker)");
0065 if (result_tr.parameterSetID() != lastID_) {
0066 syncIndices(event, result_tr);
0067 lastID_ = result_tr.parameterSetID();
0068 }
0069 if (indices_.empty()) {
0070 return -999;
0071 }
0072 if (indices_.size() > 1) {
0073 std::cout << " trying to get prescale for multiple trigger objects at the same time" << std::endl;
0074 assert(0);
0075 }
0076
0077 return result.getPrescaleForIndex<T>(*(indices_.begin()));
0078 }
0079
0080 }
0081
0082 #endif