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  const edm::ESHandle<CaloGeometry>& 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_;
116 };
117 
118 template <typename CaloObjType, typename CaloObjCollType>
120  const std::vector<edm::ParameterSet> etaPhiRegions =
121  para.getParameter<std::vector<edm::ParameterSet>>("etaPhiRegions");
122  for (auto& pset : etaPhiRegions) {
123  const std::string type = pset.getParameter<std::string>("type");
124  etaPhiRegionData_.emplace_back(createEtaPhiRegionData(
125  type,
126  pset,
127  consumesCollector())); //meh I was going to use a factory but it was going to be overly complex for my needs
128  }
129 
130  outputProductNames_ = para.getParameter<std::vector<std::string>>("outputProductNames");
131  inputCollTags_ = para.getParameter<std::vector<edm::InputTag>>("inputCollTags");
132  if (outputProductNames_.size() != inputCollTags_.size()) {
133  throw cms::Exception("InvalidConfiguration")
134  << " error outputProductNames and inputCollTags must be the same size, they are " << outputProductNames_.size()
135  << " vs " << inputCollTags_.size();
136  }
137  for (unsigned int collNr = 0; collNr < inputCollTags_.size(); collNr++) {
138  inputTokens_.push_back(consumes<CaloObjCollType>(inputCollTags_[collNr]));
139  produces<CaloObjCollType>(outputProductNames_[collNr]);
140  }
141 }
142 
143 template <typename CaloObjType, typename CaloObjCollType>
145  edm::ConfigurationDescriptions& descriptions) {
147  std::vector<std::string> outputProductNames;
148  outputProductNames.push_back("EcalRegionalRecHitsEB");
149  desc.add<std::vector<std::string>>("outputProductNames", outputProductNames);
150  std::vector<edm::InputTag> inputColls;
151  inputColls.push_back(edm::InputTag("hltHcalDigis"));
152  desc.add<std::vector<edm::InputTag>>("inputCollTags", inputColls);
153  std::vector<edm::ParameterSet> etaPhiRegions;
154 
155  edm::ParameterSet ecalCandPSet;
156  ecalCandPSet.addParameter<std::string>("type", "RecoEcalCandidate");
157  ecalCandPSet.addParameter<double>("minEt", -1);
158  ecalCandPSet.addParameter<double>("maxEt", -1);
159  ecalCandPSet.addParameter<double>("maxDeltaR", 0.5);
160  ecalCandPSet.addParameter<double>("maxDEta", 0.);
161  ecalCandPSet.addParameter<double>("maxDPhi", 0.);
162  ecalCandPSet.addParameter<edm::InputTag>("inputColl", edm::InputTag("hltEgammaCandidates"));
163  etaPhiRegions.push_back(ecalCandPSet);
164 
165  edm::ParameterSetDescription etaPhiRegionDesc;
166  etaPhiRegionDesc.add<std::string>("type");
167  etaPhiRegionDesc.add<double>("minEt");
168  etaPhiRegionDesc.add<double>("maxEt");
169  etaPhiRegionDesc.add<double>("maxDeltaR");
170  etaPhiRegionDesc.add<double>("maxDEta");
171  etaPhiRegionDesc.add<double>("maxDPhi");
172  etaPhiRegionDesc.add<edm::InputTag>("inputColl");
173  desc.addVPSet("etaPhiRegions", etaPhiRegionDesc, etaPhiRegions);
174 
176 }
177 
178 template <typename CaloObjType, typename CaloObjCollType>
180  const edm::EventSetup& setup) {
181  // get the collection geometry:
182  edm::ESHandle<CaloGeometry> caloGeomHandle;
183  setup.get<CaloGeometryRecord>().get(caloGeomHandle);
184 
185  std::vector<EtaPhiRegion> regions;
186  std::for_each(etaPhiRegionData_.begin(),
187  etaPhiRegionData_.end(),
188  [&event, &regions](const std::unique_ptr<EtaPhiRegionDataBase>& input) {
189  input->getEtaPhiRegions(event, regions);
190  });
191 
192  for (size_t inputCollNr = 0; inputCollNr < inputTokens_.size(); inputCollNr++) {
194  event.getByToken(inputTokens_[inputCollNr], inputColl);
195 
196  if (!(inputColl.isValid())) {
197  edm::LogError("ProductNotFound") << "could not get a handle on the " << typeid(CaloObjCollType).name()
198  << " named " << inputCollTags_[inputCollNr].encode() << std::endl;
199  continue;
200  }
201  auto outputColl = makeFilteredColl(inputColl, caloGeomHandle, regions);
202  event.put(std::move(outputColl), outputProductNames_[inputCollNr]);
203  }
204 }
205 
206 template <typename CaloObjType, typename CaloObjCollType>
209  const edm::ESHandle<CaloGeometry>& caloGeomHandle,
210  const std::vector<EtaPhiRegion>& regions) {
211  auto outputColl = std::make_unique<CaloObjCollType>();
212  if (!inputColl->empty()) {
213  const CaloSubdetectorGeometry* subDetGeom = caloGeomHandle->getSubdetectorGeometry(inputColl->begin()->id());
214  if (!regions.empty()) {
215  for (const CaloObjType& obj : *inputColl) {
216  auto objGeom = subDetGeom->getGeometry(obj.id());
217  if (objGeom == nullptr) {
218  //wondering what to do here
219  //something is very very wrong
220  //given HLT should never crash or throw, decided to log an error
221  //update: so turns out HCAL can pass through calibration channels in QIE11 so for that module, its an expected behaviour
222  //so we check if the ID is valid
223  if (validIDForGeom(obj.id())) {
224  edm::LogError("HLTCaloObjInRegionsProducer")
225  << "for an object of type " << typeid(CaloObjType).name() << " the geometry returned null for id "
226  << DetId(obj.id()).rawId() << " with initial ID " << DetId(inputColl->begin()->id()).rawId()
227  << " in HLTCaloObjsInRegion, this shouldnt be possible and something has gone wrong, auto accepting "
228  "hit";
229  }
230  outputColl->push_back(obj);
231  continue;
232  }
233  float eta = objGeom->getPosition().eta();
234  float phi = objGeom->getPosition().phi();
235 
236  for (const auto& region : regions) {
237  if (region(eta, phi)) {
238  outputColl->push_back(obj);
239  break;
240  }
241  }
242  }
243  } //end check of empty regions
244  } //end check of empty rec-hits
245  return outputColl;
246 }
247 
248 //tells us if an ID should have a valid geometry
249 //it assumes that all IDs do except those specifically mentioned
250 //HCAL for example have laser calibs in the digi collection so
251 //so we have to ensure that HCAL is HB,HE or HO
252 template <typename CaloObjType, typename CaloObjCollType>
254  if (id.det() == DetId::Hcal) {
255  if (id.subdetId() == HcalSubdetector::HcalEmpty || id.subdetId() == HcalSubdetector::HcalOther) {
256  return false;
257  }
258  }
259  return true;
260 }
261 
262 template <typename CaloObjType, typename CaloObjCollType>
264  const std::string& type, const edm::ParameterSet& para, edm::ConsumesCollector&& consumesColl) {
265  if (type == "L1EGamma") {
266  return new EtaPhiRegionData<l1t::EGammaBxCollection>(para, consumesColl);
267  } else if (type == "L1Jet") {
268  return new EtaPhiRegionData<l1t::JetBxCollection>(para, consumesColl);
269  } else if (type == "L1Muon") {
270  return new EtaPhiRegionData<l1t::MuonBxCollection>(para, consumesColl);
271  } else if (type == "L1Tau") {
272  return new EtaPhiRegionData<l1t::TauBxCollection>(para, consumesColl);
273  } else if (type == "RecoEcalCandidate") {
274  return new EtaPhiRegionData<reco::RecoEcalCandidateCollection>(para, consumesColl);
275  } else if (type == "RecoChargedCandidate") {
276  return new EtaPhiRegionData<reco::RecoChargedCandidateCollection>(para, consumesColl);
277  } else if (type == "Electron") {
278  return new EtaPhiRegionData<reco::Electron>(para, consumesColl);
279  } else {
280  //this is a major issue and could lead to rather subtle efficiency losses, so if its incorrectly configured, we're aborting the job!
281  throw cms::Exception("InvalidConfig")
282  << " type " << type
283  << " is not recognised, this means the rec-hit you think you are keeping may not be and you should fix this "
284  "error as it can lead to hard to find efficiency loses"
285  << std::endl;
286  }
287 }
288 
289 template <typename CandCollType>
291  std::vector<EtaPhiRegion>& regions) const {
293  event.getByToken(token_, cands);
294 
295  for (auto const& cand : *cands) {
296  if (cand.et() >= minEt_ && (maxEt_ < 0 || cand.et() < maxEt_)) {
297  regions.push_back(EtaPhiRegion(cand.eta(), cand.phi(), maxDeltaR_, maxDEta_, maxDPhi_));
298  }
299  }
300 }
301 
303 
307 
312 
316 
324 
325 //these two classes are intended to ultimately replace the EcalRecHit and EcalUncalibratedRecHit
326 //instances of HLTRecHitInAllL1RegionsProducer, particulary as we're free of legacy / stage-1 L1 now
333 
334 // HGCAL Digis
338 
339 // HGCAL RecHits
defaultModuleLabel.h
ConfigurationDescriptions.h
HcalOther
Definition: HcalAssistant.h:38
HLT_2018_cff.inputColl
inputColl
Definition: HLT_2018_cff.py:13213
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 >
CaloGeometryRecord
Definition: CaloGeometryRecord.h:30
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:178
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
HGCRecHit.h
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:262
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
edm::ESHandle< CaloGeometry >
EtaPhiRegionData::maxEt_
float maxEt_
Definition: HLTCaloObjInRegionsProducer.cc:76
EtaPhiRegionDataBase
Definition: HLTCaloObjInRegionsProducer.cc:63
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
ElectronFwd.h
CaloSubdetectorGeometry.h
HLT_2018_cff.outputColl
outputColl
Definition: HLT_2018_cff.py:78853
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
defaultModuleLabel
std::string defaultModuleLabel()
Definition: defaultModuleLabel.h:16
Event.h
PVValHelper::phi
Definition: PVValidationHelpers.h:68
edm::ParameterSetDescription::addVPSet
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
Definition: ParameterSetDescription.h:149
reco::deltaR2
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
HLTCaloObjInRegionsProducer::outputProductNames_
std::vector< std::string > outputProductNames_
Definition: HLTCaloObjInRegionsProducer.cc:111
edm::ParameterSet::addParameter
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:124
cand
Definition: decayParser.h:34
QIE10DataFrame.h
HGCDigiCollections.h
EtaPhiRegionDataBase::EtaPhiRegionDataBase
EtaPhiRegionDataBase()
Definition: HLTCaloObjInRegionsProducer.cc:65
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
HcalSubdetector.h
EtaPhiRegion::maxDPhi_
float maxDPhi_
Definition: HLTCaloObjInRegionsProducer.cc:57
get
#define get
HLTCaloObjInRegionsProducer::inputTokens_
std::vector< edm::EDGetTokenT< CaloObjCollType > > inputTokens_
Definition: HLTCaloObjInRegionsProducer.cc:113
EcalRecHit.h
EtaPhiRegion::maxDEta_
float maxDEta_
Definition: HLTCaloObjInRegionsProducer.cc:56
DDAxes::phi
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
HLTCaloObjInRegionsProducer::inputCollTags_
std::vector< edm::InputTag > inputCollTags_
Definition: HLTCaloObjInRegionsProducer.cc:112
CaloCellGeometry.h
HLTCaloObjInRegionsProducer::validIDForGeom
static bool validIDForGeom(const DetId &id)
Definition: HLTCaloObjInRegionsProducer.cc:252
Electron.h
type
type
Definition: HCALResponse.h:21
eostools.move
def move(src, dest)
Definition: eostools.py:511
RecoEcalCandidate.h
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:118
HLT_2018_cff.region
region
Definition: HLT_2018_cff.py:81479
HLT_2018_cff.cands
cands
Definition: HLT_2018_cff.py:13762
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:289
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
HLTCaloObjInRegionsProducer::makeFilteredColl
static std::unique_ptr< CaloObjCollType > makeFilteredColl(const edm::Handle< CaloObjCollType > &inputColl, const edm::ESHandle< CaloGeometry > &caloGeomHandle, const std::vector< EtaPhiRegion > &regions)
Definition: HLTCaloObjInRegionsProducer.cc:206
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
event
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of "!*" before the partial wildcard feature was incorporated). The per-event "cost" of each negative criterion with multiple relevant triggers is about the same as ! *was in the past
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:39
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:143
HGCUncalibratedRecHit.h