Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:28

0001 /** \class HLTSmartSinglet
0002  *
0003  * See header file for documentation
0004  *
0005  *
0006  *  \author Martin Grunewald
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 // constructors and destructor
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 // member functions
0053 //
0054 
0055 // ------------ method called to produce the data  ------------
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   // All HLT filters must create and fill an HLT filter object,
0069   // recording any reconstructed physics objects satisfying (or not)
0070   // this HLT filter, and place it in the Event.
0071 
0072   // The filter object
0073   if (saveTags())
0074     filterproduct.addCollectionTag(inputTag_);
0075 
0076   // Ref to Candidate object to be recorded in filter object
0077   TRef ref;
0078 
0079   // get hold of collection of objects
0080   Handle<TCollection> objects;
0081   iEvent.getByToken(inputToken_, objects);
0082 
0083   // look at all objects, check cuts and add to filter object
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   // filter decision
0095   bool accept(n >= min_N_);
0096 
0097   return accept;
0098 }