CMS 3D CMS Logo

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