Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:20:31

0001 // -*- C++ -*-
0002 //
0003 // Class:      HLTHcalMETNoiseFilter
0004 //
0005 /**\class HLTHcalMETNoiseFilter
0006 
0007  Description: HLT filter module for rejecting MET events due to noise in the HCAL
0008 
0009  Implementation:
0010      <Notes on implementation>
0011 */
0012 //
0013 // Original Author:  Leonard Apanasevich
0014 //         Created:  Wed Mar 25 16:01:27 CDT 2009
0015 //
0016 //
0017 
0018 #include "HLTrigger/JetMET/interface/HLTHcalMETNoiseFilter.h"
0019 
0020 #include "DataFormats/Common/interface/Handle.h"
0021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0022 #include "FWCore/Framework/interface/ESHandle.h"
0023 #include "FWCore/Framework/interface/Event.h"
0024 #include "FWCore/Framework/interface/EventSetup.h"
0025 
0026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0027 
0028 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0029 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0030 #include "FWCore/Utilities/interface/InputTag.h"
0031 
0032 #include <iostream>
0033 
0034 HLTHcalMETNoiseFilter::HLTHcalMETNoiseFilter(const edm::ParameterSet& iConfig)
0035     : HcalNoiseRBXCollectionTag_(iConfig.getParameter<edm::InputTag>("HcalNoiseRBXCollection")),
0036       severity_(iConfig.getParameter<int>("severity")),
0037       maxNumRBXs_(iConfig.getParameter<int>("maxNumRBXs")),
0038       numRBXsToConsider_(iConfig.getParameter<int>("numRBXsToConsider")),
0039       needEMFCoincidence_(iConfig.getParameter<bool>("needEMFCoincidence")),
0040       minRBXEnergy_(iConfig.getParameter<double>("minRBXEnergy")),
0041       minRatio_(iConfig.getParameter<double>("minRatio")),
0042       maxRatio_(iConfig.getParameter<double>("maxRatio")),
0043       minHPDHits_(iConfig.getParameter<int>("minHPDHits")),
0044       minRBXHits_(iConfig.getParameter<int>("minRBXHits")),
0045       minHPDNoOtherHits_(iConfig.getParameter<int>("minHPDNoOtherHits")),
0046       minZeros_(iConfig.getParameter<int>("minZeros")),
0047       minHighEHitTime_(iConfig.getParameter<double>("minHighEHitTime")),
0048       maxHighEHitTime_(iConfig.getParameter<double>("maxHighEHitTime")),
0049       maxRBXEMF_(iConfig.getParameter<double>("maxRBXEMF")),
0050       minRecHitE_(iConfig.getParameter<double>("minRecHitE")),
0051       minLowHitE_(iConfig.getParameter<double>("minLowHitE")),
0052       minHighHitE_(iConfig.getParameter<double>("minHighHitE")),
0053       minR45HitE_(5.0),
0054       TS4TS5EnergyThreshold_(iConfig.getParameter<double>("TS4TS5EnergyThreshold")) {
0055   std::vector<double> TS4TS5UpperThresholdTemp = iConfig.getParameter<std::vector<double> >("TS4TS5UpperThreshold");
0056   std::vector<double> TS4TS5UpperCutTemp = iConfig.getParameter<std::vector<double> >("TS4TS5UpperCut");
0057   std::vector<double> TS4TS5LowerThresholdTemp = iConfig.getParameter<std::vector<double> >("TS4TS5LowerThreshold");
0058   std::vector<double> TS4TS5LowerCutTemp = iConfig.getParameter<std::vector<double> >("TS4TS5LowerCut");
0059 
0060   for (int i = 0; i < (int)TS4TS5UpperThresholdTemp.size() && i < (int)TS4TS5UpperCutTemp.size(); i++)
0061     TS4TS5UpperCut_.push_back(std::pair<double, double>(TS4TS5UpperThresholdTemp[i], TS4TS5UpperCutTemp[i]));
0062   sort(TS4TS5UpperCut_.begin(), TS4TS5UpperCut_.end());
0063 
0064   for (int i = 0; i < (int)TS4TS5LowerThresholdTemp.size() && i < (int)TS4TS5LowerCutTemp.size(); i++)
0065     TS4TS5LowerCut_.push_back(std::pair<double, double>(TS4TS5LowerThresholdTemp[i], TS4TS5LowerCutTemp[i]));
0066   sort(TS4TS5LowerCut_.begin(), TS4TS5LowerCut_.end());
0067 
0068   if (iConfig.existsAs<double>("minR45HitE"))
0069     minR45HitE_ = iConfig.getParameter<double>("minR45HitE");
0070 
0071   m_theHcalNoiseToken = consumes<reco::HcalNoiseRBXCollection>(HcalNoiseRBXCollectionTag_);
0072 }
0073 
0074 HLTHcalMETNoiseFilter::~HLTHcalMETNoiseFilter() = default;
0075 
0076 void HLTHcalMETNoiseFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0077   edm::ParameterSetDescription desc;
0078   desc.add<edm::InputTag>("HcalNoiseRBXCollection", edm::InputTag("hltHcalNoiseInfoProducer"));
0079   desc.add<int>("severity", 1);
0080   desc.add<int>("maxNumRBXs", 2);
0081   desc.add<int>("numRBXsToConsider", 2);
0082   desc.add<bool>("needEMFCoincidence", true);
0083   desc.add<double>("minRBXEnergy", 50.0);
0084   desc.add<double>("minRatio", -999.);
0085   desc.add<double>("maxRatio", 999.);
0086   desc.add<int>("minHPDHits", 17);
0087   desc.add<int>("minRBXHits", 999);
0088   desc.add<int>("minHPDNoOtherHits", 10);
0089   desc.add<int>("minZeros", 10);
0090   desc.add<double>("minHighEHitTime", -9999.0);
0091   desc.add<double>("maxHighEHitTime", 9999.0);
0092   desc.add<double>("maxRBXEMF", 0.02);
0093   desc.add<double>("minRecHitE", 1.5);
0094   desc.add<double>("minLowHitE", 10.0);
0095   desc.add<double>("minHighHitE", 25.0);
0096   desc.add<double>("minR45HitE", 5.0);
0097   desc.add<double>("TS4TS5EnergyThreshold", 50.0);
0098 
0099   double TS4TS5UpperThresholdArray[5] = {70, 90, 100, 400, 4000};
0100   double TS4TS5UpperCutArray[5] = {1, 0.8, 0.75, 0.72, 0.72};
0101   double TS4TS5LowerThresholdArray[7] = {100, 120, 150, 200, 300, 400, 500};
0102   double TS4TS5LowerCutArray[7] = {-1, -0.7, -0.4, -0.2, -0.08, 0, 0.1};
0103   std::vector<double> TS4TS5UpperThreshold(TS4TS5UpperThresholdArray, TS4TS5UpperThresholdArray + 5);
0104   std::vector<double> TS4TS5UpperCut(TS4TS5UpperCutArray, TS4TS5UpperCutArray + 5);
0105   std::vector<double> TS4TS5LowerThreshold(TS4TS5LowerThresholdArray, TS4TS5LowerThresholdArray + 7);
0106   std::vector<double> TS4TS5LowerCut(TS4TS5LowerCutArray, TS4TS5LowerCutArray + 7);
0107 
0108   desc.add<std::vector<double> >("TS4TS5UpperThreshold", TS4TS5UpperThreshold);
0109   desc.add<std::vector<double> >("TS4TS5UpperCut", TS4TS5UpperCut);
0110   desc.add<std::vector<double> >("TS4TS5LowerThreshold", TS4TS5LowerThreshold);
0111   desc.add<std::vector<double> >("TS4TS5LowerCut", TS4TS5LowerCut);
0112   descriptions.add("hltHcalMETNoiseFilter", desc);
0113 }
0114 
0115 //
0116 // member functions
0117 //
0118 
0119 bool HLTHcalMETNoiseFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0120   using namespace reco;
0121 
0122   // in this case, do not filter anything
0123   if (severity_ == 0)
0124     return true;
0125 
0126   // get the RBXs produced by RecoMET/METProducers/HcalNoiseInfoProducer
0127   edm::Handle<HcalNoiseRBXCollection> rbxs_h;
0128   iEvent.getByToken(m_theHcalNoiseToken, rbxs_h);
0129   if (!rbxs_h.isValid()) {
0130     edm::LogError("DataNotFound") << "HLTHcalMETNoiseFilter: Could not find HcalNoiseRBXCollection product named "
0131                                   << HcalNoiseRBXCollectionTag_ << "." << std::endl;
0132     return true;
0133   }
0134 
0135   // reject events with too many RBXs
0136   if (static_cast<int>(rbxs_h->size()) > maxNumRBXs_)
0137     return true;
0138 
0139   // create a sorted set of the RBXs, ordered by energy
0140   noisedataset_t data;
0141   for (auto const& rbx : *rbxs_h) {
0142     CommonHcalNoiseRBXData d(rbx,
0143                              minRecHitE_,
0144                              minLowHitE_,
0145                              minHighHitE_,
0146                              TS4TS5EnergyThreshold_,
0147                              TS4TS5UpperCut_,
0148                              TS4TS5LowerCut_,
0149                              minR45HitE_);
0150     data.insert(d);
0151   }
0152 
0153   // data is now sorted by RBX energy
0154   // only consider top N=numRBXsToConsider_ energy RBXs
0155   int cntr = 0;
0156   for (auto it = data.begin(); it != data.end() && cntr < numRBXsToConsider_; ++it, ++cntr) {
0157     bool passFilter = true;
0158     bool passEMF = true;
0159     if (it->energy() > minRBXEnergy_) {
0160       if (it->validRatio() && it->ratio() < minRatio_)
0161         passFilter = false;
0162       else if (it->validRatio() && it->ratio() > maxRatio_)
0163         passFilter = false;
0164       else if (it->numHPDHits() >= minHPDHits_)
0165         passFilter = false;
0166       else if (it->numRBXHits() >= minRBXHits_)
0167         passFilter = false;
0168       else if (it->numHPDNoOtherHits() >= minHPDNoOtherHits_)
0169         passFilter = false;
0170       else if (it->numZeros() >= minZeros_)
0171         passFilter = false;
0172       else if (it->minHighEHitTime() < minHighEHitTime_)
0173         passFilter = false;
0174       else if (it->maxHighEHitTime() > maxHighEHitTime_)
0175         passFilter = false;
0176       else if (!it->PassTS4TS5())
0177         passFilter = false;
0178 
0179       if (it->RBXEMF() < maxRBXEMF_)
0180         passEMF = false;
0181     }
0182 
0183     if ((needEMFCoincidence_ && !passEMF && !passFilter) || (!needEMFCoincidence_ && !passFilter)) {
0184       LogDebug("") << "HLTHcalMETNoiseFilter debug: Found a noisy RBX: "
0185                    << "energy=" << it->energy() << "; "
0186                    << "ratio=" << it->ratio() << "; "
0187                    << "# RBX hits=" << it->numRBXHits() << "; "
0188                    << "# HPD hits=" << it->numHPDHits() << "; "
0189                    << "# Zeros=" << it->numZeros() << "; "
0190                    << "min time=" << it->minHighEHitTime() << "; "
0191                    << "max time=" << it->maxHighEHitTime() << "; "
0192                    << "passTS4TS5=" << it->PassTS4TS5() << "; "
0193                    << "RBX EMF=" << it->RBXEMF() << std::endl;
0194       return false;
0195     }
0196   }
0197 
0198   // no problems found
0199   return true;
0200 }