CMS 3D CMS Logo

HLTRecHitInAllL1RegionsProducer.cc
Go to the documentation of this file.
1 #include <memory>
2 
13 
14 // Reco candidates (might not need)
17 
18 // Geometry and topology
24 
25 // Level 1 Trigger
32 
36 
39 
42 
44 
46 
47 //this is a re-write of HLTRechitInRegionsProducer to be able to handle arbitary L1 collections as inputs
48 //in the process, some of the cruft was cleaned up but it mantains almost all the old behaviour
49 //think the only difference now is that it wont throw if its not ECALBarrel, ECALEndcap or ECAL PS rec-hit type
51 public:
52  virtual ~L1RegionDataBase() {}
53  virtual void getEtaPhiRegions(const edm::Event&,
54  const edm::EventSetup&,
55  std::vector<RectangularEtaPhiRegion>&) const = 0;
56 };
57 
58 template <typename T1>
60 private:
61  double const minEt_;
62  double const maxEt_;
63  double const regionEtaMargin_;
64  double const regionPhiMargin_;
67 
68  void eventSetupConsumes(edm::ConsumesCollector& consumesColl);
69 
70 public:
72  : minEt_(para.getParameter<double>("minEt")),
73  maxEt_(para.getParameter<double>("maxEt")),
74  regionEtaMargin_(para.getParameter<double>("regionEtaMargin")),
75  regionPhiMargin_(para.getParameter<double>("regionPhiMargin")),
76  token_(consumesColl.consumes<T1>(para.getParameter<edm::InputTag>("inputColl"))) {
77  eventSetupConsumes(consumesColl);
78  }
79 
80  void getEtaPhiRegions(const edm::Event&,
81  const edm::EventSetup&,
82  std::vector<RectangularEtaPhiRegion>&) const override;
83  template <typename T2>
84  bool isEmpty(const T2& coll) const {
85  return coll.empty();
86  }
87  template <typename T2>
88  static typename T2::const_iterator beginIt(const T2& coll) {
89  return coll.begin();
90  }
91  template <typename T2>
92  static typename T2::const_iterator endIt(const T2& coll) {
93  return coll.end();
94  }
95  template <typename T2>
96  bool isEmpty(const BXVector<T2>& coll) const {
97  return (coll.size() == 0 or coll.isEmpty(0));
98  }
99  template <typename T2>
100  static typename BXVector<T2>::const_iterator beginIt(const BXVector<T2>& coll) {
101  return coll.begin(0);
102  }
103  template <typename T2>
104  static typename BXVector<T2>::const_iterator endIt(const BXVector<T2>& coll) {
105  return coll.end(0);
106  }
107 };
108 
109 template <typename RecHitType>
112 
113 public:
116 
117  void produce(edm::Event&, const edm::EventSetup&) override;
118  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
119 
120 private:
122  const edm::ParameterSet&,
123  edm::ConsumesCollector&&); //calling function owns this
124 
125  std::vector<std::unique_ptr<L1RegionDataBase>> l1RegionData_;
126 
127  std::vector<edm::InputTag> recHitLabels_;
128  std::vector<std::string> productLabels_;
129 
130  std::vector<edm::EDGetTokenT<RecHitCollectionType>> recHitTokens_;
131 
133 };
134 
135 template <typename RecHitType>
137  : caloGeometryToken_{esConsumes()} {
138  const std::vector<edm::ParameterSet> l1InputRegions =
139  para.getParameter<std::vector<edm::ParameterSet>>("l1InputRegions");
140  for (auto& pset : l1InputRegions) {
141  const std::string type = pset.getParameter<std::string>("type");
142  // meh I was going to use a factory but it was going to be overly complex for my needs
143  l1RegionData_.emplace_back(createL1RegionData(type, pset, consumesCollector()));
144  }
145  recHitLabels_ = para.getParameter<std::vector<edm::InputTag>>("recHitLabels");
146  productLabels_ = para.getParameter<std::vector<std::string>>("productLabels");
147 
148  for (unsigned int collNr = 0; collNr < recHitLabels_.size(); collNr++) {
149  recHitTokens_.push_back(consumes<RecHitCollectionType>(recHitLabels_[collNr]));
150  produces<RecHitCollectionType>(productLabels_[collNr]);
151  }
152 }
153 
154 template <typename RecHitType>
157  std::vector<std::string> productTags;
158  productTags.push_back("EcalRegionalRecHitsEB");
159  productTags.push_back("EcalRegionalRecHitsEE");
160  desc.add<std::vector<std::string>>("productLabels", productTags);
161  std::vector<edm::InputTag> recHitLabels;
162  recHitLabels.push_back(edm::InputTag("hltEcalRegionalEgammaRecHit:EcalRecHitsEB"));
163  recHitLabels.push_back(edm::InputTag("hltEcalRegionalEgammaRecHit:EcalRecHitsEE"));
164  recHitLabels.push_back(edm::InputTag("hltESRegionalEgammaRecHit:EcalRecHitsES"));
165  desc.add<std::vector<edm::InputTag>>("recHitLabels", recHitLabels);
166  std::vector<edm::ParameterSet> l1InputRegions;
167 
168  edm::ParameterSet emIsoPSet;
169  emIsoPSet.addParameter<std::string>("type", "L1EmParticle");
170  emIsoPSet.addParameter<double>("minEt", 5);
171  emIsoPSet.addParameter<double>("maxEt", 999);
172  emIsoPSet.addParameter<double>("regionEtaMargin", 0.14);
173  emIsoPSet.addParameter<double>("regionPhiMargin", 0.4);
174  emIsoPSet.addParameter<edm::InputTag>("inputColl", edm::InputTag("hltL1extraParticles:NonIsolated"));
175  l1InputRegions.push_back(emIsoPSet);
176  edm::ParameterSet emNonIsoPSet;
177  emNonIsoPSet.addParameter<std::string>("type", "L1EmParticle");
178  emNonIsoPSet.addParameter<double>("minEt", 5);
179  emNonIsoPSet.addParameter<double>("maxEt", 999);
180  emNonIsoPSet.addParameter<double>("regionEtaMargin", 0.14);
181  emNonIsoPSet.addParameter<double>("regionPhiMargin", 0.4);
182  emNonIsoPSet.addParameter<edm::InputTag>("inputColl", edm::InputTag("hltL1extraParticles:Isolated"));
183  l1InputRegions.push_back(emNonIsoPSet);
184 
185  // Why no Central Jets here? They are present in the python config, e.g. OnLine_HLT_GRun.py
186  // SHarper: because these are the default parameters designed to reproduce the original (no jets) behaviour
187  //
188  edm::ParameterSet egPSet;
189  egPSet.addParameter<std::string>("type", "EGamma");
190  egPSet.addParameter<double>("minEt", 5);
191  egPSet.addParameter<double>("maxEt", 999);
192  egPSet.addParameter<double>("regionEtaMargin", 0.4);
193  egPSet.addParameter<double>("regionPhiMargin", 0.5);
194  egPSet.addParameter<edm::InputTag>("inputColl", edm::InputTag("hltCaloStage2Digis"));
195  l1InputRegions.push_back(egPSet);
196 
198  jetPSet.addParameter<std::string>("type", "EGamma");
199  jetPSet.addParameter<double>("minEt", 200);
200  jetPSet.addParameter<double>("maxEt", 999);
201  jetPSet.addParameter<double>("regionEtaMargin", 0.4);
202  jetPSet.addParameter<double>("regionPhiMargin", 0.5);
203  jetPSet.addParameter<edm::InputTag>("inputColl", edm::InputTag("hltCaloStage2Digis"));
204  l1InputRegions.push_back(jetPSet);
205 
206  edm::ParameterSetDescription l1InputRegionDesc;
207  l1InputRegionDesc.add<std::string>("type");
208  l1InputRegionDesc.add<double>("minEt");
209  l1InputRegionDesc.add<double>("maxEt");
210  l1InputRegionDesc.add<double>("regionEtaMargin");
211  l1InputRegionDesc.add<double>("regionPhiMargin");
212  l1InputRegionDesc.add<edm::InputTag>("inputColl");
213  desc.addVPSet("l1InputRegions", l1InputRegionDesc, l1InputRegions);
214 
216 }
217 
218 template <typename RecHitType>
220  // get the collection geometry:
221  auto const& caloGeom = setup.getData(caloGeometryToken_);
222 
223  std::vector<RectangularEtaPhiRegion> regions;
224  std::for_each(l1RegionData_.begin(),
225  l1RegionData_.end(),
226  [&event, &setup, &regions](const std::unique_ptr<L1RegionDataBase>& input) {
227  input->getEtaPhiRegions(event, setup, regions);
228  });
229 
230  for (size_t recHitCollNr = 0; recHitCollNr < recHitTokens_.size(); recHitCollNr++) {
232  event.getByToken(recHitTokens_[recHitCollNr], recHits);
233 
234  if (!(recHits.isValid())) {
235  edm::LogError("ProductNotFound") << "could not get a handle on the " << typeid(RecHitCollectionType).name()
236  << " named " << recHitLabels_[recHitCollNr].encode() << std::endl;
237  continue;
238  }
239 
240  auto filteredRecHits = std::make_unique<RecHitCollectionType>();
241 
242  if (!recHits->empty()) {
243  const CaloSubdetectorGeometry* subDetGeom = caloGeom.getSubdetectorGeometry(recHits->front().id());
244  if (!regions.empty()) {
245  for (const RecHitType& recHit : *recHits) {
246  auto this_cell = subDetGeom->getGeometry(recHit.id());
247  for (const auto& region : regions) {
248  if (region.inRegion(this_cell->etaPos(), this_cell->phiPos())) {
249  filteredRecHits->push_back(recHit);
250  break;
251  }
252  }
253  }
254  } //end check of empty regions
255  } //end check of empty rec-hits
256  // std::cout <<"putting fileter coll in "<<filteredRecHits->size()<<std::endl;
257  event.put(std::move(filteredRecHits), productLabels_[recHitCollNr]);
258  } //end loop over all rec hit collections
259 }
260 
261 template <typename RecHitType>
263  const std::string& type, const edm::ParameterSet& para, edm::ConsumesCollector&& consumesColl) {
264  if (type == "L1EmParticle") {
265  return new L1RegionData<l1extra::L1EmParticleCollection>(para, consumesColl);
266  } else if (type == "L1JetParticle") {
267  return new L1RegionData<l1extra::L1JetParticleCollection>(para, consumesColl);
268  } else if (type == "L1MuonParticle") {
269  return new L1RegionData<l1extra::L1MuonParticleCollection>(para, consumesColl);
270  } else if (type == "EGamma") {
271  return new L1RegionData<l1t::EGammaBxCollection>(para, consumesColl);
272  } else if (type == "Jet") {
273  return new L1RegionData<l1t::JetBxCollection>(para, consumesColl);
274  } else if (type == "Muon") {
275  return new L1RegionData<l1t::MuonBxCollection>(para, consumesColl);
276  } else if (type == "Tau") {
277  return new L1RegionData<l1t::TauBxCollection>(para, consumesColl);
278  } else {
279  //this is a major issue and could lead to rather subtle efficiency losses, so if its incorrectly configured, we're aborting the job!
280  throw cms::Exception("InvalidConfig")
281  << " type " << type
282  << " is not recognised, this means the rec-hit you think you are keeping may not be and you should fix this "
283  "error as it can lead to hard to find efficiency loses"
284  << std::endl;
285  }
286 }
287 
288 template <typename L1CollType>
290 
291 template <typename L1CollType>
293  const edm::EventSetup&,
294  std::vector<RectangularEtaPhiRegion>& regions) const {
295  edm::Handle<L1CollType> l1Cands;
296  event.getByToken(token_, l1Cands);
297 
298  if (isEmpty(*l1Cands)) {
299  LogDebug("HLTRecHitInAllL1RegionsProducerL1RegionData")
300  << "The input collection of L1T candidates is empty (L1CollType = \""
301  << edm::typeDemangle(typeid(L1CollType).name()) << "\"). No regions selected.";
302  return;
303  }
304 
305  for (auto l1CandIt = beginIt(*l1Cands); l1CandIt != endIt(*l1Cands); ++l1CandIt) {
306  if (l1CandIt->et() >= minEt_ && l1CandIt->et() < maxEt_) {
307  double etaLow = l1CandIt->eta() - regionEtaMargin_;
308  double etaHigh = l1CandIt->eta() + regionEtaMargin_;
309  double phiLow = l1CandIt->phi() - regionPhiMargin_;
310  double phiHigh = l1CandIt->phi() + regionPhiMargin_;
311 
312  regions.push_back(RectangularEtaPhiRegion(etaLow, etaHigh, phiLow, phiHigh));
313  }
314  }
315 }
316 
317 template <>
319  l1CaloGeometryToken_ = consumesColl.esConsumes();
320 }
321 
322 template <>
324  const edm::Event& event, const edm::EventSetup& setup, std::vector<RectangularEtaPhiRegion>& regions) const {
326  event.getByToken(token_, l1Cands);
327 
328  auto const& l1CaloGeom = setup.getData(l1CaloGeometryToken_);
329 
330  for (const auto& l1Cand : *l1Cands) {
331  if (l1Cand.et() >= minEt_ && l1Cand.et() < maxEt_) {
332  // Access the GCT hardware object corresponding to the L1Extra EM object.
333  int etaIndex = l1Cand.gctJetCand()->etaIndex();
334  int phiIndex = l1Cand.gctJetCand()->phiIndex();
335 
336  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
337  double etaLow = l1CaloGeom.etaBinLowEdge(etaIndex);
338  double etaHigh = l1CaloGeom.etaBinHighEdge(etaIndex);
339  double phiLow = l1CaloGeom.emJetPhiBinLowEdge(phiIndex);
340  double phiHigh = l1CaloGeom.emJetPhiBinHighEdge(phiIndex);
341 
342  etaLow -= regionEtaMargin_;
343  etaHigh += regionEtaMargin_;
344  phiLow -= regionPhiMargin_;
345  phiHigh += regionPhiMargin_;
346 
347  regions.push_back(RectangularEtaPhiRegion(etaLow, etaHigh, phiLow, phiHigh));
348  }
349  }
350 }
351 
352 template <>
354  l1CaloGeometryToken_ = consumesColl.esConsumes();
355 }
356 
357 template <>
359  const edm::Event& event, const edm::EventSetup& setup, std::vector<RectangularEtaPhiRegion>& regions) const {
361  event.getByToken(token_, l1Cands);
362 
363  auto const& l1CaloGeom = setup.getData(l1CaloGeometryToken_);
364 
365  for (const auto& l1Cand : *l1Cands) {
366  if (l1Cand.et() >= minEt_ && l1Cand.et() < maxEt_) {
367  // Access the GCT hardware object corresponding to the L1Extra EM object.
368  int etaIndex = l1Cand.gctEmCand()->etaIndex();
369  int phiIndex = l1Cand.gctEmCand()->phiIndex();
370 
371  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
372  double etaLow = l1CaloGeom.etaBinLowEdge(etaIndex);
373  double etaHigh = l1CaloGeom.etaBinHighEdge(etaIndex);
374  double phiLow = l1CaloGeom.emJetPhiBinLowEdge(phiIndex);
375  double phiHigh = l1CaloGeom.emJetPhiBinHighEdge(phiIndex);
376 
377  etaLow -= regionEtaMargin_;
378  etaHigh += regionEtaMargin_;
379  phiLow -= regionPhiMargin_;
380  phiHigh += regionPhiMargin_;
381 
382  regions.push_back(RectangularEtaPhiRegion(etaLow, etaHigh, phiLow, phiHigh));
383  }
384  }
385 }
386 
389 
HLTRecHitInAllL1RegionsProducer< EcalUncalibratedRecHit > HLTEcalUncalibratedRecHitInAllL1RegionsProducer
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void getEtaPhiRegions(const edm::Event &, const edm::EventSetup &, std::vector< RectangularEtaPhiRegion > &) const override
bool isEmpty(const T2 &coll) const
void eventSetupConsumes(edm::ConsumesCollector &consumesColl)
std::vector< std::unique_ptr< L1RegionDataBase > > l1RegionData_
constexpr SubDetector subDetGeom[21]
void produce(edm::Event &, const edm::EventSetup &) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
L1RegionData(const edm::ParameterSet &para, edm::ConsumesCollector &consumesColl)
static BXVector< T2 >::const_iterator beginIt(const BXVector< T2 > &coll)
HLTRecHitInAllL1RegionsProducer(const edm::ParameterSet &ps)
std::string defaultModuleLabel()
bool isEmpty(int bx) const
Log< level::Error, false > LogError
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
static std::string const input
Definition: EdmProvDump.cc:50
const_iterator begin(int bx) const
unsigned size(int bx) const
HLTRecHitInAllL1RegionsProducer< EcalRecHit > HLTEcalRecHitInAllL1RegionsProducer
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
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:136
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static T2::const_iterator endIt(const T2 &coll)
edm::EDGetTokenT< T1 > const token_
std::string typeDemangle(char const *mangledName)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const_iterator end(int bx) const
HLT enums.
virtual void getEtaPhiRegions(const edm::Event &, const edm::EventSetup &, std::vector< RectangularEtaPhiRegion > &) const =0
static BXVector< T2 >::const_iterator endIt(const BXVector< T2 > &coll)
static T2::const_iterator beginIt(const T2 &coll)
std::vector< edm::EDGetTokenT< RecHitCollectionType > > recHitTokens_
L1RegionDataBase * createL1RegionData(const std::string &, const edm::ParameterSet &, edm::ConsumesCollector &&)
bool isEmpty(const BXVector< T2 > &coll) const
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
edm::ESGetToken< L1CaloGeometry, L1CaloGeometryRecord > l1CaloGeometryToken_
#define LogDebug(id)