CMS 3D CMS Logo

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