CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/HLTrigger/HLTfilters/src/HLTSinglet.cc

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