CMS 3D CMS Logo

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