CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 
00012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014 
00015 #include "DataFormats/Common/interface/Handle.h"
00016 #include "DataFormats/Common/interface/Ref.h"
00017 #include "DataFormats/L1Trigger/interface/L1EmParticle.h"
00018 #include "DataFormats/L1Trigger/interface/L1EtMissParticle.h"
00019 #include "DataFormats/L1Trigger/interface/L1JetParticle.h"
00020 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
00021 
00022 #include "HLTrigger/HLTfilters/interface/HLTSinglet.h"
00023 
00024 
00025 // extract the candidate type
00026 template<typename T, int Tid>
00027 trigger::TriggerObjectType getObjectType(const T &) {
00028   return static_cast<trigger::TriggerObjectType>(Tid);
00029 }
00030 
00031 // specialize for type l1extra::L1EmParticle
00032 template<int Tid>
00033 trigger::TriggerObjectType getObjectType(const l1extra::L1EmParticle & candidate) {
00034   switch (candidate.type()) {
00035     case l1extra::L1EmParticle::kIsolated:
00036       return trigger::TriggerL1IsoEG;
00037     case l1extra::L1EmParticle::kNonIsolated:
00038       return trigger::TriggerL1NoIsoEG;
00039     default:
00040       return static_cast<trigger::TriggerObjectType>(Tid);
00041   }
00042 }
00043 
00044 // specialize for type l1extra::L1EtMissParticle
00045 template<int Tid>
00046 trigger::TriggerObjectType getObjectType(const l1extra::L1EtMissParticle & candidate) {
00047   switch (candidate.type()) {
00048     case l1extra::L1EtMissParticle::kMET:
00049       return trigger::TriggerL1ETM;
00050     case l1extra::L1EtMissParticle::kMHT:
00051       return trigger::TriggerL1HTM;
00052     default:
00053       return static_cast<trigger::TriggerObjectType>(Tid);
00054   }
00055 }
00056 
00057 // specialize for type l1extra::L1JetParticle
00058 template<int Tid>
00059 trigger::TriggerObjectType getObjectType(const l1extra::L1JetParticle & candidate) {
00060   switch (candidate.type()) {
00061     case l1extra::L1JetParticle::kCentral:
00062       return trigger::TriggerL1CenJet;
00063     case l1extra::L1JetParticle::kForward:
00064       return trigger::TriggerL1ForJet;
00065     case l1extra::L1JetParticle::kTau:
00066       return trigger::TriggerL1TauJet;
00067     default:
00068       return static_cast<trigger::TriggerObjectType>(Tid);
00069   }
00070 }
00071 
00072 
00073 //
00074 // constructors and destructor
00075 //
00076 template<typename T, int Tid>
00077 HLTSinglet<T,Tid>::HLTSinglet(const edm::ParameterSet& iConfig) :
00078   inputTag_ (iConfig.template getParameter<edm::InputTag>("inputTag")),
00079   saveTags_  (iConfig.template getParameter<bool>("saveTags")),
00080   min_Pt_   (iConfig.template getParameter<double>       ("MinPt"   )),
00081   max_Eta_  (iConfig.template getParameter<double>       ("MaxEta"  )),
00082   min_N_    (iConfig.template getParameter<int>          ("MinN"    ))
00083 {
00084    LogDebug("") << "Input/ptcut/etacut/ncut : "
00085                 << inputTag_.encode() << " "
00086                 << min_Pt_ << " " << max_Eta_ << " " << min_N_ ;
00087 
00088    //register your products
00089    produces<trigger::TriggerFilterObjectWithRefs>();
00090 }
00091 
00092 template<typename T, int Tid>
00093 HLTSinglet<T,Tid>::~HLTSinglet()
00094 {
00095 }
00096 
00097 //
00098 // member functions
00099 //
00100 
00101 // ------------ method called to produce the data  ------------
00102 template<typename T, int Tid> 
00103 bool
00104 HLTSinglet<T,Tid>::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00105 {
00106    using namespace std;
00107    using namespace edm;
00108    using namespace reco;
00109    using namespace trigger;
00110 
00111    typedef vector<T> TCollection;
00112    typedef Ref<TCollection> TRef;
00113 
00114    // All HLT filters must create and fill an HLT filter object,
00115    // recording any reconstructed physics objects satisfying (or not)
00116    // this HLT filter, and place it in the Event.
00117 
00118    // The filter object
00119    auto_ptr<TriggerFilterObjectWithRefs>
00120      filterobject (new TriggerFilterObjectWithRefs(path(),module()));
00121    if (saveTags_) filterobject->addCollectionTag(inputTag_);
00122    // Ref to Candidate object to be recorded in filter object
00123    TRef ref;
00124 
00125 
00126    // get hold of collection of objects
00127    Handle<TCollection> objects;
00128    iEvent.getByLabel (inputTag_,objects);
00129 
00130    // look at all objects, check cuts and add to filter object
00131    int n(0);
00132    typename TCollection::const_iterator i ( objects->begin() );
00133    for (; i!=objects->end(); i++) {
00134      if ( (i->pt() >= min_Pt_) && 
00135           ( (max_Eta_ < 0.0) || (std::abs(i->eta()) <= max_Eta_) ) ) {
00136        n++;
00137        ref=TRef(objects,distance(objects->begin(),i));
00138        filterobject->addObject(getObjectType<T, Tid>(*i),ref);
00139      }
00140    }
00141 
00142    // filter decision
00143    bool accept(n>=min_N_);
00144 
00145    // put filter object into the Event
00146    iEvent.put(filterobject);
00147 
00148    return accept;
00149 }
00150 
00151