42 std::ostringstream valOStr;
45 while (valStr.size() > 1 && valStr.back() ==
'0') {
48 if (valStr.size() > 1 && valStr.back() ==
'.') {
51 auto decPoint = valStr.find(
'.');
52 if (decPoint != std::string::npos) {
53 valStr.replace(decPoint, 1,
"p");
56 valStr.replace(0, 1,
"M");
61 std::vector<std::unique_ptr<int>> countRecHits(
const T& recHitHandle,
const std::vector<double>&
thresholds) {
64 count = std::make_unique<int>(0);
65 if (recHitHandle.isValid()) {
66 for (
const auto&
recHit : *recHitHandle) {
67 for (
size_t thresNr = 0; thresNr <
thresholds.size(); thresNr++) {
99 template <
typename RecHitCollection>
101 const std::vector<std::unique_ptr<trigger::EgammaObjectCollection>>& egTrigObjs,
104 float maxDR2 = 0.4 * 0.4)
const;
106 std::unique_ptr<reco::TrackCollection>
filterTrks(
107 const std::vector<std::unique_ptr<trigger::EgammaObjectCollection>>& egTrigObjs,
109 float maxDR2 = 0.4 * 0.4)
const;
112 const std::vector<std::unique_ptr<trigger::EgammaObjectCollection>>& egTrigObjs,
114 float maxDR2 = 0.4 * 0.4)
const;
123 std::vector<std::pair<EgObjTokens, std::string>>
egCands;
130 template <
typename T>
137 template <
typename T>
144 for (
size_t tagNr = 0; tagNr <
inputTags.size(); tagNr++) {
148 template <
typename T>
153 const auto& collectionPSets =
pset.getParameter<std::vector<edm::ParameterSet>>(
tagname);
154 for (
const auto& collPSet : collectionPSets) {
165 const auto& collectionPSets =
pset.getParameter<std::vector<edm::ParameterSet>>(
tagname);
166 for (
const auto& collPSet : collectionPSets) {
200 consumesMany<reco::RecoEcalCandidateIsolationMap>();
203 produces<trigger::EgammaObjectCollection>(tokenLabel.second);
206 produces<EcalRecHitCollection>(tokenLabel.second);
208 produces<int>(
"countEcalRecHits" + tokenLabel.second +
"Thres" + convertToProdNameStr(thres) +
"GeV");
212 produces<HBHERecHitCollection>(tokenLabel.second);
214 produces<int>(
"countHcalRecHits" + tokenLabel.second +
"Thres" + convertToProdNameStr(thres) +
"GeV");
218 produces<reco::TrackCollection>(tokenLabel.second);
221 produces<reco::PFClusterCollection>(tokenLabel.second);
227 desc.add<
double>(
"minPtToSaveHits", 0.);
228 desc.add<
bool>(
"saveHitsPlusPi",
false);
229 desc.add<
bool>(
"saveHitsPlusHalfPi",
true);
230 desc.add<std::vector<double>>(
"recHitCountThresholds",
std::vector{0., 0.5, 1.0, 1.5, 2.0});
237 std::vector<edm::ParameterSet> egCandsDefaults(1);
238 egCandsDefaults[0].addParameter(
"ecalCands",
edm::InputTag(
"hltEgammaCandidates"));
239 egCandsDefaults[0].addParameter(
"pixelSeeds",
edm::InputTag(
"hltEgammaElectronPixelSeeds"));
240 egCandsDefaults[0].addParameter(
"gsfTracks",
edm::InputTag(
"hltEgammaGsfTracks"));
241 egCandsDefaults[0].addParameter(
"label",
std::string(
""));
246 std::vector<edm::ParameterSet> ecalDefaults(2);
247 ecalDefaults[0].addParameter(
"src",
edm::InputTag(
"hltEcalRecHit",
"EcalRecHitsEB"));
248 ecalDefaults[0].addParameter(
"label",
std::string(
"EcalRecHitsEB"));
249 ecalDefaults[1].addParameter(
"src",
edm::InputTag(
"hltEcalRecHit",
"EcalRecHitsEE"));
250 ecalDefaults[1].addParameter(
"label",
std::string(
"EcalRecHitsEE"));
251 std::vector<edm::ParameterSet> hcalDefaults(1);
252 hcalDefaults[0].addParameter(
"src",
edm::InputTag(
"hltHbhereco"));
253 hcalDefaults[0].addParameter(
"label",
std::string(
""));
254 std::vector<edm::ParameterSet> trksDefaults(1);
255 trksDefaults[0].addParameter(
"src",
edm::InputTag(
"generalTracks"));
256 trksDefaults[0].addParameter(
"label",
std::string(
""));
257 std::vector<edm::ParameterSet> pfClusIsoDefaults(3);
258 pfClusIsoDefaults[0].addParameter(
"src",
edm::InputTag(
"hltParticleFlowClusterECALL1Seeded"));
259 pfClusIsoDefaults[0].addParameter(
"label",
std::string(
"Ecal"));
260 pfClusIsoDefaults[1].addParameter(
"src",
edm::InputTag(
"hltParticleFlowClusterECALUnseeded"));
261 pfClusIsoDefaults[1].addParameter(
"label",
std::string(
"EcalUnseeded"));
262 pfClusIsoDefaults[2].addParameter(
"src",
edm::InputTag(
"hltParticleFlowClusterHCAL"));
263 pfClusIsoDefaults[2].addParameter(
"label",
std::string(
"Hcal"));
265 desc.addVPSet(
"egCands", egCandsDesc, egCandsDefaults);
266 desc.addVPSet(
"ecal", tokenLabelDesc, ecalDefaults);
267 desc.addVPSet(
"hcal", tokenLabelDesc, hcalDefaults);
268 desc.addVPSet(
"trks", tokenLabelDesc, trksDefaults);
269 desc.addVPSet(
"pfClusIso", tokenLabelDesc, pfClusIsoDefaults);
271 descriptions.
add((
"hltEgammaHLTExtraProducer"),
desc);
277 std::vector<edm::Handle<reco::RecoEcalCandidateIsolationMap>> valueMapHandles;
278 event.getManyByType(valueMapHandles);
280 std::vector<std::unique_ptr<trigger::EgammaObjectCollection>> egTrigObjColls;
282 auto ecalCandsHandle =
event.getHandle(egCandsToken.first.ecalCands);
283 auto gsfTrksHandle =
event.getHandle(egCandsToken.first.gsfTracks);
284 auto pixelSeedsHandle =
event.getHandle(egCandsToken.first.pixelSeeds);
286 auto egTrigObjs = std::make_unique<trigger::EgammaObjectCollection>();
287 for (
size_t candNr = 0; ecalCandsHandle.isValid() && candNr < ecalCandsHandle->size(); candNr++) {
289 egTrigObjs->push_back(*candRef);
290 auto& egTrigObj = egTrigObjs->back();
291 setVars(egTrigObj, candRef, valueMapHandles);
293 setSeeds(egTrigObj, pixelSeedsHandle);
295 egTrigObjColls.emplace_back(
std::move(egTrigObjs));
301 auto filterAndStoreRecHits = [caloGeomHandle, &
event,
this](
const auto& egTrigObjs,
const auto& tokenLabels) {
302 for (
const auto& tokenLabel : tokenLabels) {
303 auto handle =
event.getHandle(tokenLabel.first);
310 for (
const auto& tokenLabel : tokenLabels) {
311 auto handle =
event.getHandle(tokenLabel.first);
313 for (
size_t thresNr = 0; thresNr <
thresholds.size(); thresNr++) {
316 prefixLabel + tokenLabel.second +
"Thres" + convertToProdNameStr(thres) +
"GeV");
321 auto filterAndStore = [&
event,
this](
const auto& egTrigObjs,
const auto& tokenLabels,
auto filterFunc) {
322 for (
const auto& tokenLabel : tokenLabels) {
323 auto handle =
event.getHandle(tokenLabel.first);
324 auto filtered = (this->*filterFunc)(egTrigObjs,
handle, 0.4 * 0.4);
329 filterAndStoreRecHits(egTrigObjColls,
tokens_.
ecal);
330 filterAndStoreRecHits(egTrigObjColls,
tokens_.
hcal);
336 for (
size_t collNr = 0; collNr < egTrigObjColls.size(); collNr++) {
345 std::vector<std::pair<std::string, float>>
vars;
346 for (
auto& valueMapHandle : valueMapHandles) {
347 auto mapIt = valueMapHandle->find(ecalCandRef);
348 if (mapIt != valueMapHandle->end()) {
350 if (!valueMapHandle.provenance()->productInstanceName().empty()) {
351 name +=
"_" + valueMapHandle.provenance()->productInstanceName();
361 if (!gsfTrksHandle.
isValid()) {
366 for (
size_t trkNr = 0; gsfTrksHandle.
isValid() && trkNr < gsfTrksHandle->size(); trkNr++) {
372 if (scRefFromTrk == scRef) {
373 gsfTrkRefs.push_back(trkRef);
386 if (!eleSeedsHandle.
isValid()) {
391 for (
size_t seedNr = 0; eleSeedsHandle.
isValid() && seedNr < eleSeedsHandle->size(); seedNr++) {
397 trigObjSeeds.push_back(eleSeed);
404 template <
typename RecHitCollection>
406 const std::vector<std::unique_ptr<trigger::EgammaObjectCollection>>& egTrigObjColls,
409 float maxDR2)
const {
410 auto filteredHits = std::make_unique<RecHitCollection>();
414 std::vector<std::pair<float, float>> etaPhis;
415 for (
const auto& egTrigObjs : egTrigObjColls) {
416 for (
const auto& egTrigObj : *egTrigObjs) {
418 etaPhis.push_back({egTrigObj.eta(), egTrigObj.phi()});
420 etaPhis.push_back({egTrigObj.eta(), egTrigObj.phi() + 3.14159});
422 etaPhis.push_back({egTrigObj.eta(), egTrigObj.phi() + 3.14159 / 2.});
429 for (
auto& etaPhi : etaPhis) {
440 if (deltaR2Match(cellGeom->getPosition()))
441 filteredHits->push_back(
hit);
443 throw cms::Exception(
"GeomError") <<
"could not get geometry for det id " <<
hit.
id().rawId();
450 const std::vector<std::unique_ptr<trigger::EgammaObjectCollection>>& egTrigObjColls,
452 float maxDR2)
const {
453 auto filteredTrks = std::make_unique<reco::TrackCollection>();
459 std::vector<std::pair<float, float>> etaPhisTmp;
460 for (
const auto& egTrigObjs : egTrigObjColls) {
461 for (
const auto& egTrigObj : *egTrigObjs) {
463 etaPhisTmp.push_back({egTrigObj.eta(), egTrigObj.phi()});
465 for (
const auto& gsfTrk : egTrigObj.gsfTracks()) {
466 etaPhisTmp.push_back({gsfTrk->eta(), gsfTrk->phi()});
471 std::vector<std::pair<float, float>> etaPhis;
472 for (
const auto& etaPhi : etaPhisTmp) {
473 etaPhis.push_back(etaPhi);
475 etaPhis.push_back({etaPhi.first, etaPhi.second + 3.14159});
477 etaPhis.push_back({etaPhi.first, etaPhi.second + 3.14159 / 2.});
480 auto deltaR2Match = [&etaPhis, &maxDR2](
float eta,
float phi) {
481 for (
auto& etaPhi : etaPhis) {
488 for (
auto& trk : *
trks) {
489 if (deltaR2Match(trk.eta(), trk.phi()))
490 filteredTrks->push_back(trk);
496 const std::vector<std::unique_ptr<trigger::EgammaObjectCollection>>& egTrigObjColls,
498 float maxDR2)
const {
499 auto filteredPFClus = std::make_unique<reco::PFClusterCollection>();
501 return filteredPFClus;
503 std::vector<std::pair<float, float>> etaPhis;
504 for (
const auto& egTrigObjs : egTrigObjColls) {
505 for (
const auto& egTrigObj : *egTrigObjs) {
507 etaPhis.push_back({egTrigObj.eta(), egTrigObj.phi()});
509 etaPhis.push_back({egTrigObj.eta(), egTrigObj.phi() + 3.14159});
511 etaPhis.push_back({egTrigObj.eta(), egTrigObj.phi() + 3.14159 / 2.});
515 auto deltaR2Match = [&etaPhis, &maxDR2](
float eta,
float phi) {
516 for (
auto& etaPhi : etaPhis) {
523 for (
auto& clus : *pfClus) {
524 if (deltaR2Match(clus.eta(), clus.phi()))
525 filteredPFClus->push_back(clus);
527 return filteredPFClus;