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