CMS 3D CMS Logo

HLTCaloObjInRegionsProducer.cc
Go to the documentation of this file.
1 #include <memory>
2 
13 
22 
27 
31 
34 
35 /**************************************************************
36 / purpose: enable filtering of calo objects in eta/phi or deltaR
37 / regions around generic objects
38 /
39 / operation : accepts all objects with
40 / (dEta <dEtaMax && dPhi < dPhiMax) || dR < dRMax
41 / so the OR of a rectangular region and cone region
42 ****************************************************************/
43 
44 //this is a struct which contains all the eta/phi regions
45 //from which to filter the calo objs
46 class EtaPhiRegion {
47 private:
48  float centreEta_;
49  float centrePhi_;
50  float maxDeltaR2_;
51  float maxDEta_;
52  float maxDPhi_;
53 
54 public:
55  EtaPhiRegion(float iEta, float iPhi, float iDR, float iDEta, float iDPhi)
56  : centreEta_(iEta), centrePhi_(iPhi), maxDeltaR2_(iDR * iDR), maxDEta_(iDEta), maxDPhi_(iDPhi) {}
58  bool operator()(float eta, float phi) const {
61  }
62 };
63 
65 public:
67  virtual ~EtaPhiRegionDataBase() = default;
68  virtual void getEtaPhiRegions(const edm::Event&, std::vector<EtaPhiRegion>&) const = 0;
69 };
70 
71 //this class stores the tokens to access the objects around which we wish to filter
72 //it makes a vector of EtaPhiRegions which are then used to filter the CaloObjs
73 template <typename T1>
75 private:
76  float minEt_;
77  float maxEt_;
78  float maxDeltaR_;
79  float maxDEta_;
80  float maxDPhi_;
82 
83 public:
85  : minEt_(para.getParameter<double>("minEt")),
86  maxEt_(para.getParameter<double>("maxEt")),
87  maxDeltaR_(para.getParameter<double>("maxDeltaR")),
88  maxDEta_(para.getParameter<double>("maxDEta")),
89  maxDPhi_(para.getParameter<double>("maxDPhi")),
90  token_(consumesColl.consumes<T1>(para.getParameter<edm::InputTag>("inputColl"))) {}
91 
92  void getEtaPhiRegions(const edm::Event&, std::vector<EtaPhiRegion>&) const override;
93 };
94 
95 template <typename CaloObjType, typename CaloObjCollType = edm::SortedCollection<CaloObjType>>
97 public:
99  ~HLTCaloObjInRegionsProducer() override {}
100 
101  void produce(edm::Event&, const edm::EventSetup&) override;
102  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
103 
104 private:
106  const edm::ParameterSet&,
107  edm::ConsumesCollector&&); //calling function owns this
108  static std::unique_ptr<CaloObjCollType> makeFilteredColl(const edm::Handle<CaloObjCollType>& inputColl,
109  CaloGeometry const& caloGeomHandle,
110  const std::vector<EtaPhiRegion>& regions);
111  static bool validIDForGeom(const DetId& id);
112  std::vector<std::string> outputProductNames_;
113  std::vector<edm::InputTag> inputCollTags_;
114  std::vector<edm::EDGetTokenT<CaloObjCollType>> inputTokens_;
115  std::vector<std::unique_ptr<EtaPhiRegionDataBase>> etaPhiRegionData_;
117 };
118 
119 template <typename CaloObjType, typename CaloObjCollType>
121  : caloGeometryToken_{esConsumes()} {
122  const std::vector<edm::ParameterSet> etaPhiRegions =
123  para.getParameter<std::vector<edm::ParameterSet>>("etaPhiRegions");
124  for (auto& pset : etaPhiRegions) {
125  const std::string type = pset.getParameter<std::string>("type");
126  etaPhiRegionData_.emplace_back(createEtaPhiRegionData(
127  type,
128  pset,
129  consumesCollector())); //meh I was going to use a factory but it was going to be overly complex for my needs
130  }
131 
132  outputProductNames_ = para.getParameter<std::vector<std::string>>("outputProductNames");
133  inputCollTags_ = para.getParameter<std::vector<edm::InputTag>>("inputCollTags");
134  if (outputProductNames_.size() != inputCollTags_.size()) {
135  throw cms::Exception("InvalidConfiguration")
136  << " error outputProductNames and inputCollTags must be the same size, they are " << outputProductNames_.size()
137  << " vs " << inputCollTags_.size();
138  }
139  for (unsigned int collNr = 0; collNr < inputCollTags_.size(); collNr++) {
140  inputTokens_.push_back(consumes<CaloObjCollType>(inputCollTags_[collNr]));
141  produces<CaloObjCollType>(outputProductNames_[collNr]);
142  }
143 }
144 
145 template <typename CaloObjType, typename CaloObjCollType>
147  edm::ConfigurationDescriptions& descriptions) {
149  std::vector<std::string> outputProductNames;
150  outputProductNames.push_back("EcalRegionalRecHitsEB");
151  desc.add<std::vector<std::string>>("outputProductNames", outputProductNames);
152  std::vector<edm::InputTag> inputColls;
153  inputColls.push_back(edm::InputTag("hltHcalDigis"));
154  desc.add<std::vector<edm::InputTag>>("inputCollTags", inputColls);
155  std::vector<edm::ParameterSet> etaPhiRegions;
156 
157  edm::ParameterSet ecalCandPSet;
158  ecalCandPSet.addParameter<std::string>("type", "RecoEcalCandidate");
159  ecalCandPSet.addParameter<double>("minEt", -1);
160  ecalCandPSet.addParameter<double>("maxEt", -1);
161  ecalCandPSet.addParameter<double>("maxDeltaR", 0.5);
162  ecalCandPSet.addParameter<double>("maxDEta", 0.);
163  ecalCandPSet.addParameter<double>("maxDPhi", 0.);
164  ecalCandPSet.addParameter<edm::InputTag>("inputColl", edm::InputTag("hltEgammaCandidates"));
165  etaPhiRegions.push_back(ecalCandPSet);
166 
167  edm::ParameterSetDescription etaPhiRegionDesc;
168  etaPhiRegionDesc.add<std::string>("type");
169  etaPhiRegionDesc.add<double>("minEt");
170  etaPhiRegionDesc.add<double>("maxEt");
171  etaPhiRegionDesc.add<double>("maxDeltaR");
172  etaPhiRegionDesc.add<double>("maxDEta");
173  etaPhiRegionDesc.add<double>("maxDPhi");
174  etaPhiRegionDesc.add<edm::InputTag>("inputColl");
175  desc.addVPSet("etaPhiRegions", etaPhiRegionDesc, etaPhiRegions);
176 
178 }
179 
180 template <typename CaloObjType, typename CaloObjCollType>
182  const edm::EventSetup& setup) {
183  // get the collection geometry:
184  auto const& caloGeom = setup.getData(caloGeometryToken_);
185 
186  std::vector<EtaPhiRegion> regions;
187  std::for_each(etaPhiRegionData_.begin(),
188  etaPhiRegionData_.end(),
189  [&event, &regions](const std::unique_ptr<EtaPhiRegionDataBase>& input) {
190  input->getEtaPhiRegions(event, regions);
191  });
192 
193  for (size_t inputCollNr = 0; inputCollNr < inputTokens_.size(); inputCollNr++) {
195  event.getByToken(inputTokens_[inputCollNr], inputColl);
196 
197  if (!(inputColl.isValid())) {
198  edm::LogError("ProductNotFound") << "could not get a handle on the " << typeid(CaloObjCollType).name()
199  << " named " << inputCollTags_[inputCollNr].encode() << std::endl;
200  continue;
201  }
202  auto outputColl = makeFilteredColl(inputColl, caloGeom, regions);
203  event.put(std::move(outputColl), outputProductNames_[inputCollNr]);
204  }
205 }
206 
207 template <typename CaloObjType, typename CaloObjCollType>
210  CaloGeometry const& caloGeomHandle,
211  const std::vector<EtaPhiRegion>& regions) {
212  auto outputColl = std::make_unique<CaloObjCollType>();
213  if (!inputColl->empty()) {
214  const CaloSubdetectorGeometry* subDetGeom = caloGeomHandle.getSubdetectorGeometry(inputColl->begin()->id());
215  if (!regions.empty()) {
216  for (const CaloObjType& obj : *inputColl) {
217  auto objGeom = subDetGeom->getGeometry(obj.id());
218  if (objGeom == nullptr) {
219  //wondering what to do here
220  //something is very very wrong
221  //given HLT should never crash or throw, decided to log an error
222  //update: so turns out HCAL can pass through calibration channels in QIE11 so for that module, its an expected behaviour
223  //so we check if the ID is valid
224  if (validIDForGeom(obj.id())) {
225  edm::LogError("HLTCaloObjInRegionsProducer")
226  << "for an object of type " << typeid(CaloObjType).name() << " the geometry returned null for id "
227  << DetId(obj.id()).rawId() << " with initial ID " << DetId(inputColl->begin()->id()).rawId()
228  << " in HLTCaloObjsInRegion, this shouldnt be possible and something has gone wrong, auto accepting "
229  "hit";
230  }
231  outputColl->push_back(obj);
232  continue;
233  }
234  float eta = objGeom->getPosition().eta();
235  float phi = objGeom->getPosition().phi();
236 
237  for (const auto& region : regions) {
238  if (region(eta, phi)) {
239  outputColl->push_back(obj);
240  break;
241  }
242  }
243  }
244  } //end check of empty regions
245  } //end check of empty rec-hits
246  return outputColl;
247 }
248 
249 //tells us if an ID should have a valid geometry
250 //it assumes that all IDs do except those specifically mentioned
251 //HCAL for example have laser calibs in the digi collection so
252 //so we have to ensure that HCAL is HB,HE or HO
253 template <typename CaloObjType, typename CaloObjCollType>
255  if (id.det() == DetId::Hcal) {
256  if (id.subdetId() == HcalSubdetector::HcalEmpty || id.subdetId() == HcalSubdetector::HcalOther) {
257  return false;
258  }
259  }
260  return true;
261 }
262 
263 template <typename CaloObjType, typename CaloObjCollType>
265  const std::string& type, const edm::ParameterSet& para, edm::ConsumesCollector&& consumesColl) {
266  if (type == "L1EGamma") {
267  return new EtaPhiRegionData<l1t::EGammaBxCollection>(para, consumesColl);
268  } else if (type == "L1Jet") {
269  return new EtaPhiRegionData<l1t::JetBxCollection>(para, consumesColl);
270  } else if (type == "L1Muon") {
271  return new EtaPhiRegionData<l1t::MuonBxCollection>(para, consumesColl);
272  } else if (type == "L1Tau") {
273  return new EtaPhiRegionData<l1t::TauBxCollection>(para, consumesColl);
274  } else if (type == "RecoEcalCandidate") {
275  return new EtaPhiRegionData<reco::RecoEcalCandidateCollection>(para, consumesColl);
276  } else if (type == "RecoChargedCandidate") {
277  return new EtaPhiRegionData<reco::RecoChargedCandidateCollection>(para, consumesColl);
278  } else if (type == "Electron") {
279  return new EtaPhiRegionData<reco::Electron>(para, consumesColl);
280  } else {
281  //this is a major issue and could lead to rather subtle efficiency losses, so if its incorrectly configured, we're aborting the job!
282  throw cms::Exception("InvalidConfig")
283  << " type " << type
284  << " is not recognised, this means the rec-hit you think you are keeping may not be and you should fix this "
285  "error as it can lead to hard to find efficiency loses"
286  << std::endl;
287  }
288 }
289 
290 template <typename CandCollType>
292  std::vector<EtaPhiRegion>& regions) const {
294  event.getByToken(token_, cands);
295 
296  for (auto const& cand : *cands) {
297  if (cand.et() >= minEt_ && (maxEt_ < 0 || cand.et() < maxEt_)) {
298  regions.push_back(EtaPhiRegion(cand.eta(), cand.phi(), maxDeltaR_, maxDEta_, maxDPhi_));
299  }
300  }
301 }
302 
304 
308 
313 
317 
325 
326 //these two classes are intended to ultimately replace the EcalRecHit and EcalUncalibratedRecHit
327 //instances of HLTRecHitInAllL1RegionsProducer, particulary as we're free of legacy / stage-1 L1 now
defaultModuleLabel.h
ConfigurationDescriptions.h
HcalOther
Definition: HcalAssistant.h:38
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
CaloTools.h
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
EtaPhiRegion::EtaPhiRegion
EtaPhiRegion(float iEta, float iPhi, float iDR, float iDEta, float iDPhi)
Definition: HLTCaloObjInRegionsProducer.cc:60
EtaPhiRegionData::maxDeltaR_
float maxDeltaR_
Definition: HLTCaloObjInRegionsProducer.cc:77
ESHandle.h
reco::deltaPhi
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
edm::EDGetTokenT< T1 >
edm
HLT enums.
Definition: AlignableModifier.h:19
Muon.h
HLTCaloObjInRegionsProducer::etaPhiRegionData_
std::vector< std::unique_ptr< EtaPhiRegionDataBase > > etaPhiRegionData_
Definition: HLTCaloObjInRegionsProducer.cc:114
DetId::Hcal
Definition: DetId.h:28
HLTCaloObjInRegionsProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: HLTCaloObjInRegionsProducer.cc:180
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
CaloGeometry::getSubdetectorGeometry
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
EDProducer.h
Jet.h
EcalUncalibratedRecHit.h
EtaPhiRegionDataBase::~EtaPhiRegionDataBase
virtual ~EtaPhiRegionDataBase()=default
HcalEmpty
Definition: HcalAssistant.h:32
edm::Handle
Definition: AssociativeIterator.h:50
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
EtaPhiRegion::centrePhi_
float centrePhi_
Definition: HLTCaloObjInRegionsProducer.cc:54
EtaPhiRegion
Definition: HLTCaloObjInRegionsProducer.cc:45
EtaPhiRegionData
Definition: HLTCaloObjInRegionsProducer.cc:73
EtaPhiRegion::maxDeltaR2_
float maxDeltaR2_
Definition: HLTCaloObjInRegionsProducer.cc:55
DetId
Definition: DetId.h:17
MakerMacros.h
CaloGeometry
Definition: CaloGeometry.h:21
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
HLTCaloObjInRegionsProducer::createEtaPhiRegionData
EtaPhiRegionDataBase * createEtaPhiRegionData(const std::string &, const edm::ParameterSet &, edm::ConsumesCollector &&)
Definition: HLTCaloObjInRegionsProducer.cc:263
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
EGamma.h
HcalDigiCollections.h
PVValHelper::eta
Definition: PVValidationHelpers.h:69
EtaPhiRegionDataBase::getEtaPhiRegions
virtual void getEtaPhiRegions(const edm::Event &, std::vector< EtaPhiRegion > &) const =0
EcalDigiCollections.h
EtaPhiRegionData::maxEt_
float maxEt_
Definition: HLTCaloObjInRegionsProducer.cc:76
EtaPhiRegionDataBase
Definition: HLTCaloObjInRegionsProducer.cc:63
HLT_FULL_cff.inputColl
inputColl
Definition: HLT_FULL_cff.py:14593
ParameterSetDescription.h
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
EtaPhiRegion::~EtaPhiRegion
~EtaPhiRegion()
Definition: HLTCaloObjInRegionsProducer.cc:62
CaloGeometryRecord.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EtaPhiRegionData::maxDEta_
float maxDEta_
Definition: HLTCaloObjInRegionsProducer.cc:78
HLT_FULL_cff.cands
cands
Definition: HLT_FULL_cff.py:15142
ElectronFwd.h
CaloSubdetectorGeometry.h
edm::ParameterSet
Definition: ParameterSet.h:47
defaultModuleLabel
std::string defaultModuleLabel()
Definition: defaultModuleLabel.h:16
Event.h
HLT_FULL_cff.outputColl
outputColl
Definition: HLT_FULL_cff.py:84571
PVValHelper::phi
Definition: PVValidationHelpers.h:68
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
reco::deltaR2
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
HLTCaloObjInRegionsProducer::makeFilteredColl
static std::unique_ptr< CaloObjCollType > makeFilteredColl(const edm::Handle< CaloObjCollType > &inputColl, CaloGeometry const &caloGeomHandle, const std::vector< EtaPhiRegion > &regions)
Definition: HLTCaloObjInRegionsProducer.cc:207
HLTCaloObjInRegionsProducer::outputProductNames_
std::vector< std::string > outputProductNames_
Definition: HLTCaloObjInRegionsProducer.cc:111
edmPickEvents.event
event
Definition: edmPickEvents.py:273
edm::ParameterSet::addParameter
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:135
cand
Definition: decayParser.h:32
QIE10DataFrame.h
HLT_FULL_cff.region
region
Definition: HLT_FULL_cff.py:88272
EtaPhiRegionDataBase::EtaPhiRegionDataBase
EtaPhiRegionDataBase()
Definition: HLTCaloObjInRegionsProducer.cc:65
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
HcalSubdetector.h
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
EtaPhiRegion::maxDPhi_
float maxDPhi_
Definition: HLTCaloObjInRegionsProducer.cc:57
HLTCaloObjInRegionsProducer::inputTokens_
std::vector< edm::EDGetTokenT< CaloObjCollType > > inputTokens_
Definition: HLTCaloObjInRegionsProducer.cc:113
edm::ESGetToken< CaloGeometry, CaloGeometryRecord >
EcalRecHit.h
EtaPhiRegion::maxDEta_
float maxDEta_
Definition: HLTCaloObjInRegionsProducer.cc:56
DDAxes::phi
HLTCaloObjInRegionsProducer::inputCollTags_
std::vector< edm::InputTag > inputCollTags_
Definition: HLTCaloObjInRegionsProducer.cc:112
CaloCellGeometry.h
HLTCaloObjInRegionsProducer::validIDForGeom
static bool validIDForGeom(const DetId &id)
Definition: HLTCaloObjInRegionsProducer.cc:253
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
Electron.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
RecoEcalCandidate.h
HLTCaloObjInRegionsProducer::caloGeometryToken_
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
Definition: HLTCaloObjInRegionsProducer.cc:115
EtaPhiRegionData::minEt_
float minEt_
Definition: HLTCaloObjInRegionsProducer.cc:75
RecoChargedCandidate.h
HLTCaloObjInRegionsProducer
Definition: HLTCaloObjInRegionsProducer.cc:95
GeomDetEnumerators::subDetGeom
constexpr SubDetector subDetGeom[21]
Definition: GeomDetEnumerators.h:40
DetId.h
EtaPhiRegion::centreEta_
float centreEta_
Definition: HLTCaloObjInRegionsProducer.cc:53
Frameworkfwd.h
HLTCaloObjInRegionsProducer::~HLTCaloObjInRegionsProducer
~HLTCaloObjInRegionsProducer() override
Definition: HLTCaloObjInRegionsProducer.cc:98
Exception
Definition: hltDiff.cc:246
CaloGeometry.h
EtaPhiRegionData::maxDPhi_
float maxDPhi_
Definition: HLTCaloObjInRegionsProducer.cc:79
HLTCaloObjInRegionsProducer::HLTCaloObjInRegionsProducer
HLTCaloObjInRegionsProducer(const edm::ParameterSet &ps)
Definition: HLTCaloObjInRegionsProducer.cc:119
QIE11DataFrame.h
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
EtaPhiRegionData::getEtaPhiRegions
void getEtaPhiRegions(const edm::Event &, std::vector< EtaPhiRegion > &) const override
Definition: HLTCaloObjInRegionsProducer.cc:290
CaloSubdetectorGeometry
Definition: CaloSubdetectorGeometry.h:22
RecoEcalCandidateFwd.h
L1TowerCalibrationProducer_cfi.iEta
iEta
Definition: L1TowerCalibrationProducer_cfi.py:60
AlignmentPI::regions
regions
Definition: AlignmentPayloadInspectorHelper.h:76
ConsumesCollector.h
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
EtaPhiRegion::operator()
bool operator()(float eta, float phi) const
Definition: HLTCaloObjInRegionsProducer.cc:63
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
EtaPhiRegionData::token_
edm::EDGetTokenT< T1 > token_
Definition: HLTCaloObjInRegionsProducer.cc:80
RecoChargedCandidateFwd.h
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
EtaPhiRegionData::EtaPhiRegionData
EtaPhiRegionData(const edm::ParameterSet &para, edm::ConsumesCollector &consumesColl)
Definition: HLTCaloObjInRegionsProducer.cc:83
HBHEDataFrame.h
HLTCaloObjInRegionsProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: HLTCaloObjInRegionsProducer.cc:145