CMS 3D CMS Logo

HLTRechitInRegionsProducer.cc
Go to the documentation of this file.
1 // C/C++ headers
2 #include <vector>
3 #include <memory>
4 
5 // Framework
12 
13 // Reconstruction Classes
22 
23 // Geometry
31 
32 // Level 1 Trigger
37 
43 
46 
47 // Reco candidates
50 
53 
54 // Geometry and topology
62 
63 // Level 1 Trigger
68 
69 template <typename T1>
71  typedef std::vector<T1> T1Collection;
72  typedef typename T1::const_iterator T1iterator;
73 
74 public:
76  ~HLTRechitInRegionsProducer() override = default;
77 
78  void produce(edm::Event&, edm::EventSetup const&) override;
79  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
80 
81 private:
82  void eventSetupConsumes();
83 
84  void getEtaPhiRegions(std::vector<RectangularEtaPhiRegion>*, T1Collection const&, edm::EventSetup const&, bool const);
85 
86  const bool useUncalib_;
87 
88  const bool doIsolated_;
89 
92  const double l1LowerThr_;
93  const double l1UpperThr_;
95 
96  const double regionEtaMargin_;
97  const double regionPhiMargin_;
98 
99  const std::vector<edm::InputTag> hitLabels;
100  const std::vector<std::string> productLabels;
101 
102  std::vector<edm::EDGetTokenT<EcalRecHitCollection>> hitTokens;
103  std::vector<edm::EDGetTokenT<EcalUncalibratedRecHitCollection>> uncalibHitTokens;
104 
107 };
108 
109 template <typename T1>
111  : useUncalib_(ps.getParameter<bool>("useUncalib")),
112  doIsolated_(ps.getParameter<bool>("doIsolated")),
113  l1TokenIsolated_(doIsolated_ ? consumes<T1Collection>(ps.getParameter<edm::InputTag>("l1TagIsolated"))
114  : edm::EDGetTokenT<T1Collection>()),
115  l1TokenNonIsolated_(consumes<T1Collection>(ps.getParameter<edm::InputTag>("l1TagNonIsolated"))),
116  l1LowerThr_(ps.getParameter<double>("l1LowerThr")),
117  l1UpperThr_(ps.getParameter<double>("l1UpperThr")),
118  l1LowerThrIgnoreIsolation_(ps.getParameter<double>("l1LowerThrIgnoreIsolation")),
119  regionEtaMargin_(ps.getParameter<double>("regionEtaMargin")),
120  regionPhiMargin_(ps.getParameter<double>("regionPhiMargin")),
121  hitLabels(ps.getParameter<std::vector<edm::InputTag>>("ecalhitLabels")),
122  productLabels(ps.getParameter<std::vector<std::string>>("productLabels")) {
124 
125  if (useUncalib_) {
126  for (unsigned int i = 0; i < hitLabels.size(); i++) {
127  uncalibHitTokens.push_back(consumes<EcalUncalibratedRecHitCollection>(hitLabels[i]));
128  produces<EcalUncalibratedRecHitCollection>(productLabels[i]);
129  }
130  } else {
131  for (unsigned int i = 0; i < hitLabels.size(); i++) {
132  hitTokens.push_back(consumes<EcalRecHitCollection>(hitLabels[i]));
133  produces<EcalRecHitCollection>(productLabels[i]);
134  }
135  }
136 }
137 
138 template <>
140  caloGeometryToken_ = esConsumes();
141  l1CaloGeometryToken_ = esConsumes();
142 }
143 
144 template <typename T1>
146  caloGeometryToken_ = esConsumes();
147 }
148 
149 template <typename T1>
152  std::vector<std::string> productTags;
153  productTags.push_back("EcalRegionalRecHitsEB");
154  productTags.push_back("EcalRegionalRecHitsEE");
155  desc.add<std::vector<std::string>>("productLabels", productTags);
156  std::vector<edm::InputTag> inputTags;
157  inputTags.push_back(edm::InputTag("hltEcalRegionalEgammaRecHit:EcalRecHitsEB"));
158  inputTags.push_back(edm::InputTag("hltEcalRegionalEgammaRecHit:EcalRecHitsEE"));
159  inputTags.push_back(edm::InputTag("hltESRegionalEgammaRecHit:EcalRecHitsES"));
160  desc.add<std::vector<edm::InputTag>>("ecalhitLabels", inputTags);
161  desc.add<edm::InputTag>("l1TagIsolated", edm::InputTag("l1extraParticles", "Isolated"));
162  desc.add<edm::InputTag>("l1TagNonIsolated", edm::InputTag("l1extraParticles", "NonIsolated"));
163  desc.add<bool>("useUncalib", true);
164  desc.add<bool>("doIsolated", true);
165  desc.add<double>("l1LowerThr", 5.0);
166  desc.add<double>("l1UpperThr", 999.);
167  desc.add<double>("l1LowerThrIgnoreIsolation", 0.0);
168  desc.add<double>("regionEtaMargin", 0.14);
169  desc.add<double>("regionPhiMargin", 0.4);
171 }
172 
173 template <typename T1>
175  // get the collection geometry:
176  auto const& geometry = eventSetup.getData(caloGeometryToken_);
177  const CaloSubdetectorGeometry* geometry_p;
178  std::unique_ptr<const CaloSubdetectorTopology> topology;
179 
180  //Get the L1 EM Particle Collection
181  edm::Handle<T1Collection> emIsolColl;
182  if (doIsolated_) {
183  evt.getByToken(l1TokenIsolated_, emIsolColl);
184  }
185 
186  std::vector<RectangularEtaPhiRegion> regions;
187  if (doIsolated_)
188  getEtaPhiRegions(&regions, *emIsolColl, eventSetup, true);
189 
190  if (!doIsolated_ or (l1LowerThrIgnoreIsolation_ < 64))
191  getEtaPhiRegions(&regions, evt.get(l1TokenNonIsolated_), eventSetup, false);
192 
193  if (useUncalib_) {
195  for (unsigned int i = 0; i < hitLabels.size(); i++) {
196  auto uhits = std::make_unique<EcalUncalibratedRecHitCollection>();
197 
198  evt.getByToken(uncalibHitTokens[i], urhcH[i]);
199  if (!(urhcH[i].isValid())) {
200  edm::LogError("ProductNotFound") << "could not get a handle on the EcalRecHitCollection! ("
201  << hitLabels[i].encode() << ")" << std::endl;
202  return;
203  }
204  const EcalUncalibratedRecHitCollection* uncalibRecHits = urhcH[i].product();
205 
206  if (!uncalibRecHits->empty()) {
207  if ((*uncalibRecHits)[0].id().subdetId() == EcalBarrel) {
208  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
209  topology = std::make_unique<EcalBarrelTopology>(geometry);
210  } else if ((*uncalibRecHits)[0].id().subdetId() == EcalEndcap) {
211  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
212  topology = std::make_unique<EcalEndcapTopology>(geometry);
213  } else if ((*uncalibRecHits)[0].id().subdetId() == EcalPreshower) {
214  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
215  topology = std::make_unique<EcalPreshowerTopology>();
216  } else
217  throw(std::runtime_error("\n\nProducer encountered invalied ecalhitcollection type.\n\n"));
218 
219  if (!regions.empty()) {
221 
222  for (it = uncalibRecHits->begin(); it != uncalibRecHits->end(); it++) {
223  auto this_cell = geometry_p->getGeometry(it->id());
224 
225  std::vector<RectangularEtaPhiRegion>::const_iterator region;
226  for (region = regions.begin(); region != regions.end(); region++) {
227  if (region->inRegion(this_cell->etaPos(), this_cell->phiPos())) {
228  uhits->push_back(*it);
229  break;
230  }
231  }
232  }
233  }
234  }
235  evt.put(std::move(uhits), productLabels[i]);
236  }
237 
238  } else {
240  for (unsigned int i = 0; i < hitLabels.size(); i++) {
241  auto hits = std::make_unique<EcalRecHitCollection>();
242 
243  evt.getByToken(hitTokens[i], rhcH[i]);
244  if (!(rhcH[i].isValid())) {
245  edm::LogError("ProductNotFound") << "could not get a handle on the EcalRecHitCollection! ("
246  << hitLabels[i].encode() << ")" << std::endl;
247  return;
248  }
249  const EcalRecHitCollection* recHits = rhcH[i].product();
250 
251  if (!recHits->empty()) {
252  if ((*recHits)[0].id().subdetId() == EcalBarrel) {
253  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
254  topology = std::make_unique<EcalBarrelTopology>(geometry);
255  } else if ((*recHits)[0].id().subdetId() == EcalEndcap) {
256  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
257  topology = std::make_unique<EcalEndcapTopology>(geometry);
258  } else if ((*recHits)[0].id().subdetId() == EcalPreshower) {
259  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
260  topology = std::make_unique<EcalPreshowerTopology>();
261  } else
262  throw(std::runtime_error("\n\nProducer encountered invalied ecalhitcollection type.\n\n"));
263 
264  if (!regions.empty()) {
266  for (it = recHits->begin(); it != recHits->end(); it++) {
267  auto this_cell = geometry_p->getGeometry(it->id());
268 
269  std::vector<RectangularEtaPhiRegion>::const_iterator region;
270  for (region = regions.begin(); region != regions.end(); region++) {
271  if (region->inRegion(this_cell->etaPos(), this_cell->phiPos())) {
272  hits->push_back(*it);
273  break;
274  }
275  }
276  }
277  }
278  }
279  evt.put(std::move(hits), productLabels[i]);
280  }
281  }
282 }
283 
284 template <>
286  std::vector<RectangularEtaPhiRegion>* theRegions,
287  T1Collection const& theCandidateCollection,
289  bool const isolatedCase) {
290  auto const& l1CaloGeom = eventSetup.getData(l1CaloGeometryToken_);
291 
292  for (unsigned int candItr = 0; candItr < theCandidateCollection.size(); candItr++) {
293  const l1extra::L1EmParticle& emItr = theCandidateCollection.at(candItr);
294 
295  if (!isolatedCase) {
296  if (doIsolated_ and (emItr.et() < l1LowerThrIgnoreIsolation_))
297  continue;
298  }
299 
300  if ((emItr.et() > l1LowerThr_) and (emItr.et() < l1UpperThr_)) {
301  // Access the GCT hardware object corresponding to the L1Extra EM object.
302  int etaIndex = emItr.gctEmCand()->etaIndex();
303  int phiIndex = emItr.gctEmCand()->phiIndex();
304 
305  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
306  double etaLow = l1CaloGeom.etaBinLowEdge(etaIndex);
307  double etaHigh = l1CaloGeom.etaBinHighEdge(etaIndex);
308  double phiLow = l1CaloGeom.emJetPhiBinLowEdge(phiIndex);
309  double phiHigh = l1CaloGeom.emJetPhiBinHighEdge(phiIndex);
310 
311  etaLow -= regionEtaMargin_;
312  etaHigh += regionEtaMargin_;
313  phiLow -= regionPhiMargin_;
314  phiHigh += regionPhiMargin_;
315 
316  theRegions->push_back(RectangularEtaPhiRegion(etaLow, etaHigh, phiLow, phiHigh));
317  }
318  }
319 }
320 
321 template <typename T1>
322 void HLTRechitInRegionsProducer<T1>::getEtaPhiRegions(std::vector<RectangularEtaPhiRegion>* theRegions,
323  T1Collection const& theCandidateCollection,
324  edm::EventSetup const&,
325  bool const) {
326  for (unsigned int candItr = 0; candItr < theCandidateCollection.size(); candItr++) {
327  const T1& emItr = theCandidateCollection.at(candItr);
328  if ((emItr.et() > l1LowerThr_) and (emItr.et() < l1UpperThr_)) {
329  double etaLow = emItr.eta() - regionEtaMargin_;
330  double etaHigh = emItr.eta() + regionEtaMargin_;
331  double phiLow = emItr.phi() - regionPhiMargin_;
332  double phiHigh = emItr.phi() + regionPhiMargin_;
333 
334  theRegions->push_back(RectangularEtaPhiRegion(etaLow, etaHigh, phiLow, phiHigh));
335  }
336  }
337 }
338 
341 
unsigned etaIndex() const override
get eta index -6 to -0, +0 to +6 (bit 3 is sign, 1 for -ve Z, 0 for +ve Z)
Definition: L1GctEmCand.h:62
HLTRechitInRegionsProducer(const edm::ParameterSet &ps)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
HLTRechitInRegionsProducer< reco::RecoChargedCandidate > MuonHLTRechitInRegionsProducer
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:347
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const std::vector< edm::InputTag > hitLabels
HLTRechitInRegionsProducer< l1extra::L1EmParticle > EgammaHLTRechitInRegionsProducer
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
T const * product() const
Definition: Handle.h:70
const std::vector< std::string > productLabels
std::vector< T >::const_iterator const_iterator
const edm::EDGetTokenT< T1Collection > l1TokenIsolated_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:536
std::string defaultModuleLabel()
~HLTRechitInRegionsProducer() override=default
Log< level::Error, false > LogError
std::vector< edm::EDGetTokenT< EcalRecHitCollection > > hitTokens
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
const L1GctEmCand * gctEmCand() const
Definition: L1EmParticle.h:50
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const_iterator begin() const
void produce(edm::Event &, edm::EventSetup const &) override
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
const_iterator end() const
inputTags
All input tags are specified in this pset for convenience.
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::ESGetToken< L1CaloGeometry, L1CaloGeometryRecord > l1CaloGeometryToken_
double et() const final
transverse energy
HLT enums.
const edm::EDGetTokenT< T1Collection > l1TokenNonIsolated_
unsigned phiIndex() const override
get phi index (0-17)
Definition: L1GctEmCand.h:68
def move(src, dest)
Definition: eostools.py:511
std::vector< edm::EDGetTokenT< EcalUncalibratedRecHitCollection > > uncalibHitTokens
void getEtaPhiRegions(std::vector< RectangularEtaPhiRegion > *, T1Collection const &, edm::EventSetup const &, bool const)