File indexing completed on 2024-09-07 04:35:56
0001 #ifndef DataFormats_PatCandidates_TriggerObjectStandAlone_h
0002 #define DataFormats_PatCandidates_TriggerObjectStandAlone_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 #include "DataFormats/PatCandidates/interface/TriggerObject.h"
0024 #include "DataFormats/Common/interface/TriggerResults.h"
0025 #include "FWCore/Common/interface/EventBase.h"
0026 namespace edm {
0027 class TriggerNames;
0028 }
0029
0030 namespace pat {
0031
0032 class TriggerObjectStandAlone : public TriggerObject {
0033
0034
0035
0036
0037
0038 std::vector<std::string> filterLabels_;
0039 std::vector<uint16_t> filterLabelIndices_;
0040
0041
0042 std::vector<std::string> pathNames_;
0043 std::vector<uint16_t> pathIndices_;
0044
0045
0046
0047
0048
0049 std::vector<bool> pathLastFilterAccepted_;
0050
0051
0052
0053 std::vector<bool> pathL3FilterAccepted_;
0054
0055 edm::ParameterSetID psetId_;
0056
0057
0058
0059
0060 static const char wildcard_ = '*';
0061
0062
0063
0064
0065 bool hasAnyName(const std::string &name, const std::vector<std::string> &nameVec) const;
0066
0067 void addFilterOrCondition(const std::string &name) {
0068 if (!hasFilterOrCondition(name))
0069 filterLabels_.push_back(name);
0070 };
0071
0072 void addPathOrAlgorithm(const std::string &name, bool pathLastFilterAccepted, bool pathL3FilterAccepted);
0073
0074 const std::vector<std::string> &filtersOrConditions() const {
0075 checkIfFiltersAreUnpacked();
0076 return filterLabels_;
0077 };
0078
0079 std::vector<std::string> pathsOrAlgorithms(bool pathLastFilterAccepted, bool pathL3FilterAccepted) const;
0080
0081 bool hasFilterOrCondition(const std::string &name) const;
0082
0083 bool hasPathOrAlgorithm(const std::string &name, bool pathLastFilterAccepted, bool pathL3FilterAccepted) const;
0084
0085 bool hasLastFilter() const {
0086 return (!pathLastFilterAccepted_.empty() && pathLastFilterAccepted_.size() == pathNames_.size());
0087 };
0088 bool hasL3Filter() const {
0089 return (!pathL3FilterAccepted_.empty() && pathL3FilterAccepted_.size() == pathNames_.size());
0090 };
0091
0092
0093 bool checkIfPathsAreUnpacked(bool throwIfPacked = true) const;
0094
0095 bool checkIfFiltersAreUnpacked(bool throwIfPacked = true) const;
0096
0097 public:
0098
0099
0100
0101 TriggerObjectStandAlone();
0102
0103 TriggerObjectStandAlone(const TriggerObject &trigObj);
0104
0105 TriggerObjectStandAlone(const trigger::TriggerObject &trigObj);
0106
0107 TriggerObjectStandAlone(const reco::LeafCandidate &leafCand);
0108
0109 TriggerObjectStandAlone(const reco::Particle::LorentzVector &vec, int id = 0);
0110 TriggerObjectStandAlone(const reco::Particle::PolarLorentzVector &vec, int id = 0);
0111 TriggerObjectStandAlone(const TriggerObjectStandAlone &) = default;
0112
0113
0114 ~TriggerObjectStandAlone() override {}
0115
0116
0117
0118 TriggerObjectStandAlone copy() const { return *this; }
0119
0120
0121 void addFilterLabel(const std::string &filterLabel) { addFilterOrCondition(filterLabel); };
0122
0123 void addConditionName(const std::string &conditionName) { addFilterOrCondition(conditionName); };
0124
0125 void addPathName(const std::string &pathName,
0126 bool pathLastFilterAccepted = true,
0127 bool pathL3FilterAccepted = true) {
0128 addPathOrAlgorithm(pathName, pathLastFilterAccepted, pathL3FilterAccepted);
0129 };
0130
0131 void addAlgorithmName(const std::string &algorithmName, bool algoCondAccepted = true) {
0132 addPathOrAlgorithm(algorithmName, algoCondAccepted, false);
0133 };
0134
0135 const std::vector<std::string> &filterLabels() const { return filtersOrConditions(); };
0136
0137 const std::vector<std::string> &conditionNames() const { return filtersOrConditions(); };
0138
0139 std::vector<std::string> pathNames(bool pathLastFilterAccepted = false, bool pathL3FilterAccepted = true) const {
0140 return pathsOrAlgorithms(pathLastFilterAccepted, pathL3FilterAccepted);
0141 };
0142
0143 std::vector<std::string> algorithmNames(bool algoCondAccepted = true) const {
0144 return pathsOrAlgorithms(algoCondAccepted, false);
0145 };
0146
0147 TriggerObject triggerObject();
0148
0149 bool hasFilterLabel(const std::string &filterLabel) const { return hasFilterOrCondition(filterLabel); };
0150
0151 bool hasConditionName(const std::string &conditionName) const { return hasFilterOrCondition(conditionName); };
0152
0153 bool hasPathName(const std::string &pathName,
0154 bool pathLastFilterAccepted = false,
0155 bool pathL3FilterAccepted = true) const {
0156 return hasPathOrAlgorithm(pathName, pathLastFilterAccepted, pathL3FilterAccepted);
0157 };
0158
0159 bool hasAlgorithmName(const std::string &algorithmName, bool algoCondAccepted = true) const {
0160 return hasPathOrAlgorithm(algorithmName, algoCondAccepted, false);
0161 };
0162
0163 bool hasCollection(const std::string &collName) const override;
0164 bool hasCollection(const edm::InputTag &collName) const override { return hasCollection(collName.encode()); };
0165
0166 bool hasPathLastFilterAccepted() const { return hasLastFilter(); };
0167 bool hasAlgoCondAccepted() const { return hasLastFilter(); };
0168 bool hasPathL3FilterAccepted() const { return hasL3Filter(); };
0169
0170
0171
0172
0173
0174
0175 bool filter(const std::string &filterLabel) const { return hasFilterLabel(filterLabel); };
0176
0177 bool cond(const std::string &conditionName) const { return hasConditionName(conditionName); };
0178
0179 bool path(const std::string &pathName,
0180 unsigned pathLastFilterAccepted = 0,
0181 unsigned pathL3FilterAccepted = 1) const {
0182 return hasPathName(pathName, bool(pathLastFilterAccepted), bool(pathL3FilterAccepted));
0183 };
0184
0185 bool algo(const std::string &algorithmName, unsigned algoCondAccepted = 1) const {
0186 return hasAlgorithmName(algorithmName, bool(algoCondAccepted));
0187 };
0188
0189 bool coll(const std::string &collName) const override { return hasCollection(collName); };
0190
0191
0192 void setPSetID(const edm::ParameterSetID &psetId) { psetId_ = psetId; }
0193
0194 const edm::ParameterSetID &psetID() const { return psetId_; }
0195
0196 void packFilterLabels(const edm::EventBase &event, const edm::TriggerResults &res);
0197
0198 void packPathNames(const edm::TriggerNames &names);
0199
0200 void unpackPathNames(const edm::TriggerNames &names);
0201
0202 void packFilterLabels(const std::vector<std::string> &labels);
0203
0204 void unpackFilterLabels(const std::vector<std::string> &labels);
0205
0206 void unpackFilterLabels(const edm::EventBase &event, const edm::TriggerResults &res);
0207
0208 void unpackNamesAndLabels(const edm::EventBase &event, const edm::TriggerResults &res);
0209
0210
0211 void packP4();
0212
0213 std::vector<std::string> const *allLabels(edm::ParameterSetID const &psetid,
0214 const edm::EventBase &event,
0215 const edm::TriggerResults &res) const;
0216 };
0217
0218
0219 typedef std::vector<TriggerObjectStandAlone> TriggerObjectStandAloneCollection;
0220
0221 typedef edm::Ref<TriggerObjectStandAloneCollection> TriggerObjectStandAloneRef;
0222
0223 typedef edm::RefProd<TriggerObjectStandAloneCollection> TriggerObjectStandAloneRefProd;
0224
0225 typedef edm::RefVector<TriggerObjectStandAloneCollection> TriggerObjectStandAloneRefVector;
0226
0227 typedef edm::RefVectorIterator<TriggerObjectStandAloneCollection> TriggerObjectStandAloneRefVectorIterator;
0228
0229 typedef edm::Association<TriggerObjectStandAloneCollection> TriggerObjectStandAloneMatch;
0230
0231 }
0232
0233 #endif