File indexing completed on 2024-04-06 12:23:29
0001 #include "PhysicsTools/Heppy/interface/TriggerBitChecker.h"
0002 #include "FWCore/Common/interface/TriggerNames.h"
0003
0004 namespace heppy {
0005
0006 TriggerBitChecker::TriggerBitChecker(const std::string &path) : paths_(1, returnPathStruct(path)) { rmstar(); }
0007
0008 TriggerBitChecker::TriggerBitChecker(const std::vector<std::string> &paths) : paths_(paths.size()) {
0009 for (size_t i = 0; i < paths.size(); ++i)
0010 paths_[i] = returnPathStruct(paths[i]);
0011 rmstar();
0012 }
0013
0014 TriggerBitChecker::pathStruct TriggerBitChecker::returnPathStruct(const std::string &path) const {
0015 pathStruct newPathStruct(path);
0016 if (path[0] > 48 && path[0] <= 57 ) {
0017 newPathStruct.first = atoi(path.substr(0, path.find('-')).c_str());
0018 newPathStruct.last = atoi(path.substr(path.find('-') + 1, path.find(':') - path.find('-') - 1).c_str());
0019 newPathStruct.pathName = path.substr(path.find(':') + 1);
0020 }
0021 return newPathStruct;
0022 }
0023
0024 bool TriggerBitChecker::check(const edm::EventBase &event, const edm::TriggerResults &result) const {
0025 if (result.parameterSetID() != lastID_) {
0026 syncIndices(event, result);
0027 lastID_ = result.parameterSetID();
0028 }
0029 for (std::vector<unsigned int>::const_iterator it = indices_.begin(), ed = indices_.end(); it != ed; ++it) {
0030 if (result.accept(*it))
0031 return true;
0032 }
0033 return false;
0034 }
0035
0036 bool TriggerBitChecker::check_unprescaled(const edm::EventBase &event,
0037 const edm::TriggerResults &result_tr,
0038 const pat::PackedTriggerPrescales &result) const {
0039 if (result_tr.parameterSetID() != lastID_) {
0040 syncIndices(event, result_tr);
0041 lastID_ = result_tr.parameterSetID();
0042 }
0043 bool outcome = true;
0044 for (std::vector<unsigned int>::const_iterator it = indices_.begin(), ed = indices_.end(); it != ed; ++it) {
0045 if (result.getPrescaleForIndex<double>(*it) != 1) {
0046 outcome = false;
0047 break;
0048 }
0049 }
0050 return outcome;
0051 }
0052
0053 void TriggerBitChecker::syncIndices(const edm::EventBase &event, const edm::TriggerResults &result) const {
0054 indices_.clear();
0055 const edm::TriggerNames &names = event.triggerNames(result);
0056 std::vector<pathStruct>::const_iterator itp, bgp = paths_.begin(), edp = paths_.end();
0057 for (size_t i = 0, n = names.size(); i < n; ++i) {
0058 const std::string &thispath = names.triggerName(i);
0059 for (itp = bgp; itp != edp; ++itp) {
0060 if (thispath.find(itp->pathName) == 0 && event.id().run() >= itp->first && event.id().run() <= itp->last)
0061 indices_.push_back(i);
0062 }
0063 }
0064 }
0065
0066 void TriggerBitChecker::rmstar() {
0067 std::vector<pathStruct>::iterator itp, bgp = paths_.begin(), edp = paths_.end();
0068 for (itp = bgp; itp != edp; ++itp) {
0069 std::string::size_type idx = itp->pathName.find('*');
0070 if (idx != std::string::npos)
0071 itp->pathName.erase(idx);
0072 }
0073 }
0074 }