CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/HLTrigger/HLTfilters/src/HLTSmartSinglet.cc

Go to the documentation of this file.
00001 
00012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00013 #include "HLTrigger/HLTfilters/interface/HLTSmartSinglet.h"
00014 
00015 #include "DataFormats/Common/interface/Handle.h"
00016 
00017 #include "DataFormats/Common/interface/Ref.h"
00018 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
00019 
00020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00021 
00022 //
00023 // constructors and destructor
00024 //
00025 template<typename T, int Tid>
00026 HLTSmartSinglet<T,Tid>::HLTSmartSinglet(const edm::ParameterSet& iConfig) :
00027   inputTag_ (iConfig.template getParameter<edm::InputTag>("inputTag")),
00028   saveTag_  (iConfig.template getUntrackedParameter<bool>("saveTag",false)),
00029   cut_      (iConfig.template getParameter<std::string>  ("cut"     )),
00030   min_N_    (iConfig.template getParameter<int>          ("MinN"    )),
00031   select_   (cut_                                                    )
00032 {
00033    LogDebug("") << "Input/cut/ncut : " << inputTag_.encode() << " " << cut_<< " " << min_N_ ;
00034 
00035    //register your products
00036    produces<trigger::TriggerFilterObjectWithRefs>();
00037 }
00038 
00039 template<typename T, int Tid>
00040 HLTSmartSinglet<T,Tid>::~HLTSmartSinglet()
00041 {
00042 }
00043 
00044 //
00045 // member functions
00046 //
00047 
00048 // ------------ method called to produce the data  ------------
00049 template<typename T, int Tid> 
00050 bool
00051 HLTSmartSinglet<T,Tid>::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00052 {
00053    using namespace std;
00054    using namespace edm;
00055    using namespace reco;
00056    using namespace trigger;
00057 
00058    typedef vector<T> TCollection;
00059    typedef Ref<TCollection> TRef;
00060 
00061    // All HLT filters must create and fill an HLT filter object,
00062    // recording any reconstructed physics objects satisfying (or not)
00063    // this HLT filter, and place it in the Event.
00064 
00065    // The filter object
00066    auto_ptr<TriggerFilterObjectWithRefs>
00067      filterObject (new TriggerFilterObjectWithRefs(path(),module()));
00068    if (saveTag_) filterObject->addCollectionTag(inputTag_);
00069    // Ref to Candidate object to be recorded in filter object
00070    TRef ref;
00071 
00072 
00073    // get hold of collection of objects
00074    Handle<TCollection> objects;
00075    iEvent.getByLabel (inputTag_,objects);
00076 
00077    // look at all objects, check cuts and add to filter object
00078    int n(0);
00079    typename TCollection::const_iterator i ( objects->begin() );
00080    for (; i!=objects->end(); i++) {
00081      if (select_(*i)) {
00082        n++;
00083        ref=TRef(objects,distance(objects->begin(),i));
00084        filterObject->addObject(Tid,ref);
00085      }
00086    }
00087 
00088    // filter decision
00089    bool accept(n>=min_N_);
00090 
00091    // put filter object into the Event
00092    iEvent.put(filterObject);
00093 
00094    return accept;
00095 }