CMS 3D CMS Logo

HLTHcalTowerNoiseCleanerWithrechit.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Class: HLTHcalTowerNoiseCleanerWithrechit
4 //
12 //
13 // Original Author: Alexander Mott
14 // Created: Mon Nov 21 11:32:00 CEST 2011
15 //
16 //
17 //
18 
24 
26 
36 
40 
41 #include <iostream>
42 #include <string>
43 #include <fstream>
44 #include <TVector3.h>
45 #include <TLorentzVector.h>
46 #include <set>
47 
49 
50 //#include <Point.h>
51 
53  : HcalNoiseRBXCollectionTag_(iConfig.getParameter<edm::InputTag>("HcalNoiseRBXCollection")),
54  TowerCollectionTag_(iConfig.getParameter<edm::InputTag>("CaloTowerCollection")),
55  severity_(iConfig.getParameter<int>("severity")),
56  maxNumRBXs_(iConfig.getParameter<int>("maxNumRBXs")),
57  numRBXsToConsider_(iConfig.getParameter<int>("numRBXsToConsider")),
58  needEMFCoincidence_(iConfig.getParameter<bool>("needEMFCoincidence")),
59  minRBXEnergy_(iConfig.getParameter<double>("minRBXEnergy")),
60  minRatio_(iConfig.getParameter<double>("minRatio")),
61  maxRatio_(iConfig.getParameter<double>("maxRatio")),
62  minHPDHits_(iConfig.getParameter<int>("minHPDHits")),
63  minRBXHits_(iConfig.getParameter<int>("minRBXHits")),
64  minHPDNoOtherHits_(iConfig.getParameter<int>("minHPDNoOtherHits")),
65  minZeros_(iConfig.getParameter<int>("minZeros")),
66  minHighEHitTime_(iConfig.getParameter<double>("minHighEHitTime")),
67  maxHighEHitTime_(iConfig.getParameter<double>("maxHighEHitTime")),
68  maxRBXEMF_(iConfig.getParameter<double>("maxRBXEMF")),
69  minRecHitE_(iConfig.getParameter<double>("minRecHitE")),
70  minLowHitE_(iConfig.getParameter<double>("minLowHitE")),
71  minHighHitE_(iConfig.getParameter<double>("minHighHitE")),
72  minR45HitE_(5.0),
73  TS4TS5EnergyThreshold_(iConfig.getParameter<double>("TS4TS5EnergyThreshold")) {
74  hltMinRBXRechitR45Cuts_ = iConfig.getParameter<std::vector<double> >("hltRBXRecHitR45Cuts");
75  std::vector<double> TS4TS5UpperThresholdTemp = iConfig.getParameter<std::vector<double> >("TS4TS5UpperThreshold");
76  std::vector<double> TS4TS5UpperCutTemp = iConfig.getParameter<std::vector<double> >("TS4TS5UpperCut");
77  std::vector<double> TS4TS5LowerThresholdTemp = iConfig.getParameter<std::vector<double> >("TS4TS5LowerThreshold");
78  std::vector<double> TS4TS5LowerCutTemp = iConfig.getParameter<std::vector<double> >("TS4TS5LowerCut");
79 
80  for (int i = 0; i < (int)TS4TS5UpperThresholdTemp.size() && i < (int)TS4TS5UpperCutTemp.size(); i++)
81  TS4TS5UpperCut_.push_back(std::pair<double, double>(TS4TS5UpperThresholdTemp[i], TS4TS5UpperCutTemp[i]));
82  sort(TS4TS5UpperCut_.begin(), TS4TS5UpperCut_.end());
83 
84  for (int i = 0; i < (int)TS4TS5LowerThresholdTemp.size() && i < (int)TS4TS5LowerCutTemp.size(); i++)
85  TS4TS5LowerCut_.push_back(std::pair<double, double>(TS4TS5LowerThresholdTemp[i], TS4TS5LowerCutTemp[i]));
86  sort(TS4TS5LowerCut_.begin(), TS4TS5LowerCut_.end());
87 
88  m_theHcalNoiseToken = consumes<reco::HcalNoiseRBXCollection>(HcalNoiseRBXCollectionTag_);
89  m_theCaloTowerCollectionToken = consumes<CaloTowerCollection>(TowerCollectionTag_);
90 
91  if (iConfig.existsAs<double>("minR45HitE"))
92  minR45HitE_ = iConfig.getParameter<double>("minR45HitE");
93 
94  produces<CaloTowerCollection>();
95 }
96 
98 
101  desc.add<edm::InputTag>("HcalNoiseRBXCollection", edm::InputTag("hltHcalNoiseInfoProducer"));
102  desc.add<edm::InputTag>("CaloTowerCollection", edm::InputTag("hltTowerMakerForAll"));
103  desc.add<double>("maxTowerNoiseEnergyFraction", 0.5);
104  desc.add<int>("severity", 1);
105  desc.add<int>("maxNumRBXs", 2);
106  desc.add<int>("numRBXsToConsider", 2);
107  desc.add<bool>("needEMFCoincidence", true);
108  desc.add<double>("minRBXEnergy", 50.0);
109  desc.add<double>("minRatio", -999.);
110  desc.add<double>("maxRatio", 999.);
111  desc.add<int>("minHPDHits", 17);
112  desc.add<int>("minRBXHits", 999);
113  desc.add<int>("minHPDNoOtherHits", 10);
114  desc.add<int>("minZeros", 10);
115  desc.add<double>("minHighEHitTime", -9999.0);
116  desc.add<double>("maxHighEHitTime", 9999.0);
117  desc.add<double>("maxRBXEMF", 0.02);
118  desc.add<double>("minRecHitE", 1.5);
119  desc.add<double>("minLowHitE", 10.0);
120  desc.add<double>("minHighHitE", 25.0);
121  desc.add<double>("minR45HitE", 5.0);
122  desc.add<double>("TS4TS5EnergyThreshold", 50.0);
123 
124  double TS4TS5UpperThresholdArray[5] = {70, 90, 100, 400, 4000};
125  double TS4TS5UpperCutArray[5] = {1, 0.8, 0.75, 0.72, 0.72};
126  double TS4TS5LowerThresholdArray[7] = {100, 120, 150, 200, 300, 400, 500};
127  double TS4TS5LowerCutArray[7] = {-1, -0.7, -0.4, -0.2, -0.08, 0, 0.1};
128  double hltRBXRecHitR45CutsArray[8] = {0.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0, -1.0};
129  std::vector<double> TS4TS5UpperThreshold(TS4TS5UpperThresholdArray, TS4TS5UpperThresholdArray + 5);
130  std::vector<double> TS4TS5UpperCut(TS4TS5UpperCutArray, TS4TS5UpperCutArray + 5);
131  std::vector<double> TS4TS5LowerThreshold(TS4TS5LowerThresholdArray, TS4TS5LowerThresholdArray + 7);
132  std::vector<double> TS4TS5LowerCut(TS4TS5LowerCutArray, TS4TS5LowerCutArray + 7);
133  std::vector<double> hltRBXRecHitR45Cuts(hltRBXRecHitR45CutsArray, hltRBXRecHitR45CutsArray + 8);
134 
135  desc.add<std::vector<double> >("TS4TS5UpperThreshold", TS4TS5UpperThreshold);
136  desc.add<std::vector<double> >("TS4TS5UpperCut", TS4TS5UpperCut);
137  desc.add<std::vector<double> >("TS4TS5LowerThreshold", TS4TS5LowerThreshold);
138  desc.add<std::vector<double> >("TS4TS5LowerCut", TS4TS5LowerCut);
139  desc.add<std::vector<double> >("hltRBXRecHitR45Cuts", hltRBXRecHitR45Cuts);
140  descriptions.add("hltHcalTowerNoiseCleanerWithrechit", desc);
141 }
142 
143 //
144 // member functions
145 //
146 
148  using namespace reco;
149 
150  edm::ESHandle<CaloTowerTopology> caloTowerTopology;
151  iSetup.get<HcalRecNumberingRecord>().get(caloTowerTopology);
152 
153  //get the calo MET / MHT
155  iEvent.getByToken(m_theCaloTowerCollectionToken, tower_h);
156 
157  std::set<unsigned int> noisyTowers;
158 
159  if (not tower_h.isValid()) { //No towers MET, don't do anything and accept the event
160  edm::LogError("HLTHcalTowerNoiseCleanerWithrechit") << "Input Tower Collection is not Valid";
161  return;
162  }
163 
164  // get the RBXs produced by RecoMET/METProducers/HcalNoiseInfoProducer
166  iEvent.getByToken(m_theHcalNoiseToken, rbxs_h);
167  if (!rbxs_h.isValid()) {
168  edm::LogWarning("HLTHcalTowerNoiseCleanerWithrechit")
169  << "Could not find HcalNoiseRBXCollection product named " << HcalNoiseRBXCollectionTag_ << "." << std::endl;
170  severity_ = 0;
171  }
172 
173  // create a sorted set of the RBXs, ordered by energy
175  for (auto const& rbx : *rbxs_h) {
177  minRecHitE_,
178  minLowHitE_,
179  minHighHitE_,
183  minR45HitE_);
184  data.insert(d);
185  }
186 
187  // data is now sorted by RBX energy
188  // only consider top N=numRBXsToConsider_ energy RBXs
189  if (severity_ > 0) {
190  for (auto const& it : data) {
191  // Check the Rechit-R45 filter
192  // Taken from http://cmslxr.fnal.gov/lxr/source/RecoMET/METAlgorithms/src/HcalNoiseAlgo.cc?v=CMSSW_7_4_6#0256
193  bool passRechitr45 = true;
194  int r45Count = it.r45Count();
195  double r45Fraction = it.r45Fraction();
196  double r45EnergyFraction = it.r45EnergyFraction();
197  for (int i = 0; i + 3 < (int)hltMinRBXRechitR45Cuts_.size(); i = i + 4) {
198  double Value = r45Count * hltMinRBXRechitR45Cuts_[i] + r45Fraction * hltMinRBXRechitR45Cuts_[i + 1] +
199  r45EnergyFraction * hltMinRBXRechitR45Cuts_[i + 2] + hltMinRBXRechitR45Cuts_[i + 3];
200  if (Value > 0)
201  passRechitr45 = false;
202  }
203 
204  bool passFilter = true;
205  bool passEMF = true;
206  if (it.energy() > minRBXEnergy_) {
207  if (it.validRatio() && it.ratio() < minRatio_)
208  passFilter = false;
209  else if (it.validRatio() && it.ratio() > maxRatio_)
210  passFilter = false;
211  else if (it.numHPDHits() >= minHPDHits_)
212  passFilter = false;
213  else if (it.numRBXHits() >= minRBXHits_)
214  passFilter = false;
215  else if (it.numHPDNoOtherHits() >= minHPDNoOtherHits_)
216  passFilter = false;
217  else if (it.numZeros() >= minZeros_)
218  passFilter = false;
219  else if (it.minHighEHitTime() < minHighEHitTime_)
220  passFilter = false;
221  else if (it.maxHighEHitTime() > maxHighEHitTime_)
222  passFilter = false;
223  else if (passRechitr45 == false)
224  passFilter = false;
225  if (it.RBXEMF() < maxRBXEMF_) {
226  passEMF = false;
227  }
228  }
229 
230  if ((needEMFCoincidence_ && !passEMF && !passFilter) ||
231  (!needEMFCoincidence_ && !passFilter)) { // check for noise
232  LogDebug("") << "HLTHcalTowerNoiseCleanerWithrechit debug: Found a noisy RBX: "
233  << "energy=" << it.energy() << "; "
234  << "ratio=" << it.ratio() << "; "
235  << "# RBX hits=" << it.numRBXHits() << "; "
236  << "# HPD hits=" << it.numHPDHits() << "; "
237  << "# Zeros=" << it.numZeros() << "; "
238  << "min time=" << it.minHighEHitTime() << "; "
239  << "max time=" << it.maxHighEHitTime() << "; "
240  << "RBX EMF=" << it.RBXEMF() << std::endl;
241  // add calotowers associated with this RBX to the noise list
242  edm::RefVector<CaloTowerCollection> noiseTowers = it.rbxTowers();
244  //add these calotowers to the noisy list
245  for (noiseTowersIt = noiseTowers.begin(); noiseTowersIt != noiseTowers.end(); noiseTowersIt++) {
246  edm::Ref<edm::SortedCollection<CaloTower> > tower_ref = *noiseTowersIt;
247  CaloTowerDetId id = tower_ref->id();
248  noisyTowers.insert(caloTowerTopology->denseIndex(id));
249  }
250  }
251  } // done with noise loop
252  } //if(severity_>0)
253 
254  //output collection
255  std::unique_ptr<CaloTowerCollection> OutputTowers(new CaloTowerCollection());
256 
258 
259  for (inTowersIt = tower_h->begin(); inTowersIt != tower_h->end(); inTowersIt++) {
260  const CaloTower& tower = (*inTowersIt);
261  CaloTowerDetId id = tower.id();
262 
263  if (noisyTowers.find(caloTowerTopology->denseIndex(id)) == noisyTowers.end()) { // the tower is not noisy
264  OutputTowers->push_back(*inTowersIt);
265  }
266  }
267  iEvent.put(std::move(OutputTowers));
268 }
HLTHcalTowerNoiseCleanerWithrechit::noisedataset_t
std::set< CommonHcalNoiseRBXData, noisedatacomp > noisedataset_t
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:67
ConfigurationDescriptions.h
Handle.h
CaloJet.h
electrons_cff.bool
bool
Definition: electrons_cff.py:393
mps_fire.i
i
Definition: mps_fire.py:428
edm::SortedCollection< CaloTower >::const_iterator
std::vector< CaloTower >::const_iterator const_iterator
Definition: SortedCollection.h:80
HLTHcalTowerNoiseCleanerWithrechit::TowerCollectionTag_
edm::InputTag TowerCollectionTag_
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:35
MessageLogger.h
ESHandle.h
HLTHcalTowerNoiseCleanerWithrechit::m_theHcalNoiseToken
edm::EDGetTokenT< reco::HcalNoiseRBXCollection > m_theHcalNoiseToken
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:31
HLTHcalTowerNoiseCleanerWithrechit::needEMFCoincidence_
bool needEMFCoincidence_
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:39
edm
HLT enums.
Definition: AlignableModifier.h:19
HLTHcalTowerNoiseCleanerWithrechit::HcalNoiseRBXCollectionTag_
edm::InputTag HcalNoiseRBXCollectionTag_
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:34
HLTHcalTowerNoiseCleanerWithrechit::severity_
int severity_
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:36
edm::RefVector::begin
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:223
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
hgcalTowerProducer_cfi.tower
tower
Definition: hgcalTowerProducer_cfi.py:4
HcalRecNumberingRecord.h
HLTHcalTowerNoiseCleanerWithrechit::~HLTHcalTowerNoiseCleanerWithrechit
~HLTHcalTowerNoiseCleanerWithrechit() override
Jet.h
edm::RefVector
Definition: EDProductfwd.h:27
HLTHcalTowerNoiseCleanerWithrechit::minRBXEnergy_
double minRBXEnergy_
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:40
edm::ParameterSet::existsAs
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
HLTHcalTowerNoiseCleanerWithrechit::minHPDHits_
int minHPDHits_
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:43
edm::Handle
Definition: AssociativeIterator.h:50
HLTHcalTowerNoiseCleanerWithrechit::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: HLTHcalTowerNoiseCleanerWithrechit.cc:99
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
edm::Ref
Definition: AssociativeIterator.h:58
HLTHcalTowerNoiseCleanerWithrechit::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: HLTHcalTowerNoiseCleanerWithrechit.cc:147
HLTHcalTowerNoiseCleanerWithrechit::minR45HitE_
double minR45HitE_
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:52
CommonHcalNoiseRBXData
Definition: HcalNoiseAlgo.h:11
HLTHcalTowerNoiseCleanerWithrechit::minHPDNoOtherHits_
int minHPDNoOtherHits_
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:45
edm::RefVector::end
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:228
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
edm::SortedCollection::begin
const_iterator begin() const
Definition: SortedCollection.h:262
CaloTowerCollection
edm::SortedCollection< CaloTower > CaloTowerCollection
Definition: CaloTowerDefs.h:16
HLT_FULL_cff.TS4TS5LowerThreshold
TS4TS5LowerThreshold
Definition: HLT_FULL_cff.py:8354
edm::ESHandle
Definition: DTSurvey.h:22
HLTHcalTowerNoiseCleanerWithrechit::minRecHitE_
double minRecHitE_
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:52
HLTHcalTowerNoiseCleanerWithrechit.h
ParameterSetDescription.h
CaloTowerTopology.h
HLT_FULL_cff.TS4TS5UpperThreshold
TS4TS5UpperThreshold
Definition: HLT_FULL_cff.py:8357
HcalRecNumberingRecord
Definition: HcalRecNumberingRecord.h:23
HLTHcalTowerNoiseCleanerWithrechit::TS4TS5LowerCut_
std::vector< std::pair< double, double > > TS4TS5LowerCut_
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:56
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
HLTHcalTowerNoiseCleanerWithrechit::minHighHitE_
double minHighHitE_
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:52
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
HLTHcalTowerNoiseCleanerWithrechit::HLTHcalTowerNoiseCleanerWithrechit
HLTHcalTowerNoiseCleanerWithrechit(const edm::ParameterSet &)
Definition: HLTHcalTowerNoiseCleanerWithrechit.cc:52
edm::SortedCollection::end
const_iterator end() const
Definition: SortedCollection.h:267
LorentzVector.h
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
CaloTower
Definition: CaloTower.h:26
HLTHcalTowerNoiseCleanerWithrechit::minRBXHits_
int minRBXHits_
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:44
CaloTowerDetId.h
edm::EventSetup
Definition: EventSetup.h:57
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
get
#define get
InputTag.h
CaloTowerCollection.h
HLTHcalTowerNoiseCleanerWithrechit::maxRBXEMF_
double maxRBXEMF_
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:49
HLTHcalTowerNoiseCleanerWithrechit::hltMinRBXRechitR45Cuts_
std::vector< double > hltMinRBXRechitR45Cuts_
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:59
edm::Ref::id
ProductID id() const
Accessor for product ID.
Definition: Ref.h:244
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::RefVectorIterator
Definition: EDProductfwd.h:33
HLT_FULL_cff.TS4TS5UpperCut
TS4TS5UpperCut
Definition: HLT_FULL_cff.py:8376
HLTHcalTowerNoiseCleanerWithrechit::TS4TS5EnergyThreshold_
double TS4TS5EnergyThreshold_
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:54
HLTHcalTowerNoiseCleanerWithrechit::minLowHitE_
double minLowHitE_
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:52
HLTHcalTowerNoiseCleanerWithrechit::m_theCaloTowerCollectionToken
edm::EDGetTokenT< CaloTowerCollection > m_theCaloTowerCollectionToken
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:32
HLTHcalTowerNoiseCleanerWithrechit::minRatio_
double minRatio_
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:41
Point3D.h
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
HLTHcalTowerNoiseCleanerWithrechit::maxHighEHitTime_
double maxHighEHitTime_
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:48
HLTHcalTowerNoiseCleanerWithrechit::maxRatio_
double maxRatio_
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:42
ztail.d
d
Definition: ztail.py:151
reco::JetExtendedAssociation::Value
reco::JetExtendedAssociation::JetExtendedData Value
Definition: JetExtendedAssociation.h:27
Candidate.h
ParameterSet.h
HLTHcalTowerNoiseCleanerWithrechit::minZeros_
int minZeros_
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:46
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
HLTHcalTowerNoiseCleanerWithrechit::minHighEHitTime_
double minHighEHitTime_
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:47
HLT_FULL_cff.TS4TS5LowerCut
TS4TS5LowerCut
Definition: HLT_FULL_cff.py:8360
edm::InputTag
Definition: InputTag.h:15
CaloTowerTopology::denseIndex
uint32_t denseIndex(const DetId &id) const
Definition: CaloTowerTopology.cc:235
CaloTowerDetId
Definition: CaloTowerDetId.h:12
HLTHcalTowerNoiseCleanerWithrechit::TS4TS5UpperCut_
std::vector< std::pair< double, double > > TS4TS5UpperCut_
Definition: HLTHcalTowerNoiseCleanerWithrechit.h:55