CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/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 #include <typeinfo>
00023 
00024 //
00025 // constructors and destructor
00026 //
00027 template<typename T>
00028 HLTSmartSinglet<T>::HLTSmartSinglet(const edm::ParameterSet& iConfig) : HLTFilter(iConfig), 
00029   inputTag_    (iConfig.template getParameter<edm::InputTag>("inputTag")),
00030   triggerType_ (iConfig.template getParameter<int>("triggerType")),
00031   cut_      (iConfig.template getParameter<std::string>  ("cut"     )),
00032   min_N_    (iConfig.template getParameter<int>          ("MinN"    )),
00033   select_   (cut_                                                    )
00034 {
00035   LogDebug("") << "Input/tyre/cut/ncut : "
00036                << inputTag_.encode() << " "
00037                << triggerType_ << " "
00038                << cut_<< " "
00039                << min_N_ ;
00040 }
00041 
00042 template<typename T>
00043 HLTSmartSinglet<T>::~HLTSmartSinglet()
00044 {
00045 }
00046 
00047 template<typename T> 
00048 void
00049 HLTSmartSinglet<T>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00050   edm::ParameterSetDescription desc;
00051   makeHLTFilterDescription(desc);
00052   desc.add<edm::InputTag>("inputTag",edm::InputTag("hltCollection"));
00053   desc.add<int>("triggerType",0);
00054   desc.add<std::string>("cut","1>0");
00055   desc.add<int>("MinN",1);
00056   descriptions.add(std::string("hlt")+std::string(typeid(HLTSmartSinglet<T>).name()),desc);
00057 }
00058 
00059 //
00060 // member functions
00061 //
00062 
00063 // ------------ method called to produce the data  ------------
00064 template<typename T> 
00065 bool
00066 HLTSmartSinglet<T>::hltFilter(edm::Event& iEvent, const edm::EventSetup& iSetup, trigger::TriggerFilterObjectWithRefs & filterproduct)
00067 {
00068    using namespace std;
00069    using namespace edm;
00070    using namespace reco;
00071    using namespace trigger;
00072 
00073    typedef vector<T> TCollection;
00074    typedef Ref<TCollection> TRef;
00075 
00076    // All HLT filters must create and fill an HLT filter object,
00077    // recording any reconstructed physics objects satisfying (or not)
00078    // this HLT filter, and place it in the Event.
00079 
00080    // The filter object
00081    if (saveTags()) filterproduct.addCollectionTag(inputTag_);
00082 
00083    // Ref to Candidate object to be recorded in filter object
00084    TRef ref;
00085 
00086    // get hold of collection of objects
00087    Handle<TCollection> objects;
00088    iEvent.getByLabel (inputTag_,objects);
00089 
00090    // look at all objects, check cuts and add to filter object
00091    int n(0);
00092    typename TCollection::const_iterator i ( objects->begin() );
00093    for (; i!=objects->end(); i++) {
00094      if (select_(*i)) {
00095        n++;
00096        ref=TRef(objects,distance(objects->begin(),i));
00097        filterproduct.addObject(triggerType_,ref);
00098      }
00099    }
00100 
00101    // filter decision
00102    bool accept(n>=min_N_);
00103 
00104    return accept;
00105 }