CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/HLTrigger/HLTfilters/src/HLTGlobalSums.cc

Go to the documentation of this file.
00001 
00012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00013 #include "HLTrigger/HLTfilters/interface/HLTGlobalSums.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<cmath>
00023 
00024 //
00025 // constructors and destructor
00026 //
00027 template<typename T, int Tid>
00028 HLTGlobalSums<T,Tid>::HLTGlobalSums(const edm::ParameterSet& iConfig) :
00029   inputTag_   (iConfig.template getParameter<edm::InputTag>("inputTag")),
00030   saveTag_    (iConfig.template getUntrackedParameter<bool> ("saveTag",false)),
00031   observable_ (iConfig.template getParameter<std::string>("observable")),
00032   min_        (iConfig.template getParameter<double>("Min")),
00033   max_        (iConfig.template getParameter<double>("Max")),
00034   min_N_      (iConfig.template getParameter<int>("MinN")),
00035   tid_()
00036 {
00037    LogDebug("") << "InputTags and cuts : " 
00038                 << inputTag_.encode() << " " << observable_
00039                 << " Range [" << min_ << " " << max_ << "]"
00040                 << " MinN =" << min_N_
00041      ;
00042 
00043    if (observable_=="sumEt") {
00044      tid_=Tid;
00045    } else if (observable_=="mEtSig") {
00046      if (Tid==trigger::TriggerTET) {
00047        tid_=trigger::TriggerMETSig;
00048      } else if (Tid==trigger::TriggerTHT) {
00049        tid_=trigger::TriggerMHTSig;
00050      } else {
00051        tid_=Tid;
00052      }
00053    } else if (observable_=="e_longitudinal") {
00054      if (Tid==trigger::TriggerTET) {
00055        tid_=trigger::TriggerELongit;
00056      } else if (Tid==trigger::TriggerTHT) {
00057        tid_=trigger::TriggerHLongit;
00058      } else {
00059        tid_=Tid;
00060      }
00061    } else {
00062      tid_=Tid;
00063    }
00064 
00065    //register your products
00066    produces<trigger::TriggerFilterObjectWithRefs>();
00067 }
00068 
00069 template<typename T, int Tid>
00070 HLTGlobalSums<T,Tid>::~HLTGlobalSums()
00071 {
00072 }
00073 
00074 //
00075 // member functions
00076 //
00077 
00078 // ------------ method called to produce the data  ------------
00079 template<typename T, int Tid> 
00080 bool
00081 HLTGlobalSums<T,Tid>::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00082 {
00083    using namespace std;
00084    using namespace edm;
00085    using namespace reco;
00086    using namespace trigger;
00087 
00088    typedef vector<T> TCollection;
00089    typedef Ref<TCollection> TRef;
00090 
00091    // All HLT filters must create and fill an HLT filter object,
00092    // recording any reconstructed physics objects satisfying (or not)
00093    // this HLT filter, and place it in the Event.
00094 
00095    // The filter object
00096    auto_ptr<TriggerFilterObjectWithRefs>
00097      filterobject (new TriggerFilterObjectWithRefs(path(),module()));
00098    if (saveTag_) filterobject->addCollectionTag(inputTag_);
00099    // Ref to Candidate object to be recorded in filter object
00100    TRef ref;
00101 
00102 
00103    // get hold of MET product from Event
00104    Handle<TCollection>   objects;
00105    iEvent.getByLabel(inputTag_,objects);
00106    if (!objects.isValid()) {
00107      LogDebug("") << inputTag_ << " collection not found!";
00108      iEvent.put(filterobject);
00109      return false;
00110    }
00111 
00112    LogDebug("") << "Size of MET collection: " << objects->size();
00113    if (objects->size()==0) {
00114      LogDebug("") << "MET collection does not contain a MET object!";
00115    } else if (objects->size()>1) {
00116      LogDebug("") << "MET collection contains more than one MET object!";
00117    }
00118 
00119    int n(0);
00120    double value(0.0);
00121    typename TCollection::const_iterator ibegin(objects->begin());
00122    typename TCollection::const_iterator iend(objects->end());
00123    typename TCollection::const_iterator iter;
00124    for (iter=ibegin; iter!=iend; iter++) {
00125 
00126      // get hold of value of observable to cut on
00127      if ( (tid_==TriggerTET) || (tid_==TriggerTHT) ) {
00128        value=iter->sumEt();
00129      } else if ( (tid_==TriggerMETSig) || (tid_==TriggerMHTSig) ) {
00130        value=iter->mEtSig();
00131      } else if ( (tid_==TriggerELongit) || (tid_==TriggerHLongit) ) {
00132        value=iter->e_longitudinal();
00133      } else {
00134        value=0.0;
00135      }
00136 
00137      value=std::abs(value);
00138 
00139      if ( ( (min_<0.0) || (min_<=value) ) &&
00140           ( (max_<0.0) || (value<=max_) ) ) {
00141        n++;
00142        ref=TRef(objects,distance(ibegin,iter));
00143        filterobject->addObject(tid_,ref);
00144      }
00145 
00146    }
00147 
00148    // filter decision
00149    const bool accept(n>=min_N_);
00150 
00151    // put filter object into the Event
00152    iEvent.put(filterobject);
00153 
00154    return accept;
00155 }