File indexing completed on 2024-04-06 12:18:28
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "HLTSmartSinglet.h"
0012
0013 #include "DataFormats/Common/interface/Handle.h"
0014
0015 #include "DataFormats/Common/interface/Ref.h"
0016 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
0017
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019
0020 #include "HLTrigger/HLTcore/interface/defaultModuleLabel.h"
0021
0022
0023
0024
0025 template <typename T>
0026 HLTSmartSinglet<T>::HLTSmartSinglet(const edm::ParameterSet& iConfig)
0027 : HLTFilter(iConfig),
0028 inputTag_(iConfig.template getParameter<edm::InputTag>("inputTag")),
0029 inputToken_(consumes<std::vector<T>>(inputTag_)),
0030 triggerType_(iConfig.template getParameter<int>("triggerType")),
0031 cut_(iConfig.template getParameter<std::string>("cut")),
0032 min_N_(iConfig.template getParameter<int>("MinN")),
0033 select_(cut_) {
0034 LogDebug("") << "Input/tyre/cut/ncut : " << inputTag_.encode() << " " << triggerType_ << " " << cut_ << " " << min_N_;
0035 }
0036
0037 template <typename T>
0038 HLTSmartSinglet<T>::~HLTSmartSinglet() = default;
0039
0040 template <typename T>
0041 void HLTSmartSinglet<T>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0042 edm::ParameterSetDescription desc;
0043 makeHLTFilterDescription(desc);
0044 desc.add<edm::InputTag>("inputTag", edm::InputTag("hltCollection"));
0045 desc.add<int>("triggerType", 0);
0046 desc.add<std::string>("cut", "1>0");
0047 desc.add<int>("MinN", 1);
0048 descriptions.add(defaultModuleLabel<HLTSmartSinglet<T>>(), desc);
0049 }
0050
0051
0052
0053
0054
0055
0056 template <typename T>
0057 bool HLTSmartSinglet<T>::hltFilter(edm::Event& iEvent,
0058 const edm::EventSetup& iSetup,
0059 trigger::TriggerFilterObjectWithRefs& filterproduct) const {
0060 using namespace std;
0061 using namespace edm;
0062 using namespace reco;
0063 using namespace trigger;
0064
0065 typedef vector<T> TCollection;
0066 typedef Ref<TCollection> TRef;
0067
0068
0069
0070
0071
0072
0073 if (saveTags())
0074 filterproduct.addCollectionTag(inputTag_);
0075
0076
0077 TRef ref;
0078
0079
0080 Handle<TCollection> objects;
0081 iEvent.getByToken(inputToken_, objects);
0082
0083
0084 int n(0);
0085 typename TCollection::const_iterator i(objects->begin());
0086 for (; i != objects->end(); i++) {
0087 if (select_(*i)) {
0088 n++;
0089 ref = TRef(objects, distance(objects->begin(), i));
0090 filterproduct.addObject(triggerType_, ref);
0091 }
0092 }
0093
0094
0095 bool accept(n >= min_N_);
0096
0097 return accept;
0098 }