42 std::ostringstream valOStr;
43 valOStr << std::fixed << std::setprecision(precision) <<
val;
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) {
62 std::vector<std::unique_ptr<int>>
counts(thresholds.size());
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++) {
68 if (recHit.energy() >= thresholds[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>
143 tokens.resize(inputTags.size());
144 for (
size_t tagNr = 0; tagNr < inputTags.size(); tagNr++) {
145 tokens[tagNr] = cc.
consumes<
T>(inputTags[tagNr]);
148 template <
typename T>
154 for (
const auto& collPSet : collectionPSets) {
157 tokens.emplace_back(token,
std::move(label));
166 for (
const auto& collPSet : collectionPSets) {
172 tokens.emplace_back(objTokens,
std::move(label));
199 minPtToSaveHits_(
pset.getParameter<
double>(
"minPtToSaveHits")),
200 saveHitsPlusPi_(
pset.getParameter<
bool>(
"saveHitsPlusPi")),
201 saveHitsPlusHalfPi_(
pset.getParameter<
bool>(
"saveHitsPlusHalfPi")),
202 recHitCountThresholds_(
pset.getParameter<std::vector<double>>(
"recHitCountThresholds")) {
203 consumesMany<reco::RecoEcalCandidateIsolationMap>();
205 for (
auto& tokenLabel :
tokens_.egCands) {
206 produces<trigger::EgammaObjectCollection>(tokenLabel.second);
208 for (
auto& tokenLabel :
tokens_.ecal) {
209 produces<EcalRecHitCollection>(tokenLabel.second);
210 for (
const auto& thres : recHitCountThresholds_) {
211 produces<int>(
"countEcalRecHits" + tokenLabel.second +
"Thres" + convertToProdNameStr(thres) +
"GeV");
214 for (
auto& tokenLabel :
tokens_.hcal) {
215 produces<HBHERecHitCollection>(tokenLabel.second);
216 for (
const auto& thres : recHitCountThresholds_) {
217 produces<int>(
"countHcalRecHits" + tokenLabel.second +
"Thres" + convertToProdNameStr(thres) +
"GeV");
220 for (
auto& tokenLabel :
tokens_.trks) {
221 produces<reco::TrackCollection>(tokenLabel.second);
223 for (
auto& tokenLabel :
tokens_.pfClusIso) {
224 produces<reco::PFClusterCollection>(tokenLabel.second);
230 desc.
add<
double>(
"minPtToSaveHits", 0.);
231 desc.
add<
bool>(
"saveHitsPlusPi",
false);
232 desc.
add<
bool>(
"saveHitsPlusHalfPi",
true);
233 desc.
add<std::vector<double>>(
"recHitCountThresholds",
std::vector{0., 0.5, 1.0, 1.5, 2.0});
240 std::vector<edm::ParameterSet> egCandsDefaults(1);
241 egCandsDefaults[0].addParameter(
"ecalCands",
edm::InputTag(
"hltEgammaCandidates"));
242 egCandsDefaults[0].addParameter(
"pixelSeeds",
edm::InputTag(
"hltEgammaElectronPixelSeeds"));
243 egCandsDefaults[0].addParameter(
"gsfTracks",
edm::InputTag(
"hltEgammaGsfTracks"));
244 egCandsDefaults[0].addParameter(
"label",
std::string(
""));
249 std::vector<edm::ParameterSet> ecalDefaults(2);
250 ecalDefaults[0].addParameter(
"src",
edm::InputTag(
"hltEcalRecHit",
"EcalRecHitsEB"));
251 ecalDefaults[0].addParameter(
"label",
std::string(
"EcalRecHitsEB"));
252 ecalDefaults[1].addParameter(
"src",
edm::InputTag(
"hltEcalRecHit",
"EcalRecHitsEE"));
253 ecalDefaults[1].addParameter(
"label",
std::string(
"EcalRecHitsEE"));
254 std::vector<edm::ParameterSet> hcalDefaults(1);
255 hcalDefaults[0].addParameter(
"src",
edm::InputTag(
"hltHbhereco"));
256 hcalDefaults[0].addParameter(
"label",
std::string(
""));
257 std::vector<edm::ParameterSet> trksDefaults(1);
258 trksDefaults[0].addParameter(
"src",
edm::InputTag(
"generalTracks"));
259 trksDefaults[0].addParameter(
"label",
std::string(
""));
260 std::vector<edm::ParameterSet> pfClusIsoDefaults(3);
261 pfClusIsoDefaults[0].addParameter(
"src",
edm::InputTag(
"hltParticleFlowClusterECALL1Seeded"));
262 pfClusIsoDefaults[0].addParameter(
"label",
std::string(
"Ecal"));
263 pfClusIsoDefaults[1].addParameter(
"src",
edm::InputTag(
"hltParticleFlowClusterECALUnseeded"));
264 pfClusIsoDefaults[1].addParameter(
"label",
std::string(
"EcalUnseeded"));
265 pfClusIsoDefaults[2].addParameter(
"src",
edm::InputTag(
"hltParticleFlowClusterHCAL"));
266 pfClusIsoDefaults[2].addParameter(
"label",
std::string(
"Hcal"));
268 desc.
addVPSet(
"egCands", egCandsDesc, egCandsDefaults);
269 desc.
addVPSet(
"ecal", tokenLabelDesc, ecalDefaults);
270 desc.
addVPSet(
"hcal", tokenLabelDesc, hcalDefaults);
271 desc.
addVPSet(
"trks", tokenLabelDesc, trksDefaults);
272 desc.
addVPSet(
"pfClusIso", tokenLabelDesc, pfClusIsoDefaults);
274 descriptions.
add((
"hltEgammaHLTExtraProducer"), desc);
280 std::vector<edm::Handle<reco::RecoEcalCandidateIsolationMap>> valueMapHandles;
281 event.getManyByType(valueMapHandles);
283 std::vector<std::unique_ptr<trigger::EgammaObjectCollection>> egTrigObjColls;
285 auto ecalCandsHandle =
event.getHandle(egCandsToken.first.ecalCands);
286 auto gsfTrksHandle =
event.getHandle(egCandsToken.first.gsfTracks);
287 auto pixelSeedsHandle =
event.getHandle(egCandsToken.first.pixelSeeds);
289 auto egTrigObjs = std::make_unique<trigger::EgammaObjectCollection>();
290 for (
size_t candNr = 0; ecalCandsHandle.isValid() && candNr < ecalCandsHandle->size(); candNr++) {
292 egTrigObjs->push_back(*candRef);
293 auto& egTrigObj = egTrigObjs->back();
294 setVars(egTrigObj, candRef, valueMapHandles);
296 setSeeds(egTrigObj, pixelSeedsHandle);
298 egTrigObjColls.emplace_back(
std::move(egTrigObjs));
303 auto filterAndStoreRecHits = [caloGeomHandle, &
event,
this](
const auto& egTrigObjs,
const auto& tokenLabels) {
304 for (
const auto& tokenLabel : tokenLabels) {
305 auto handle =
event.getHandle(tokenLabel.first);
312 for (
const auto& tokenLabel : tokenLabels) {
313 auto handle =
event.getHandle(tokenLabel.first);
315 for (
size_t thresNr = 0; thresNr < thresholds.size(); thresNr++) {
316 const auto& thres = thresholds[thresNr];
318 prefixLabel + tokenLabel.second +
"Thres" + convertToProdNameStr(thres) +
"GeV");
323 auto filterAndStore = [&
event,
this](
const auto& egTrigObjs,
const auto& tokenLabels,
auto filterFunc) {
324 for (
const auto& tokenLabel : tokenLabels) {
325 auto handle =
event.getHandle(tokenLabel.first);
326 auto filtered = (this->*filterFunc)(egTrigObjs,
handle, 0.4 * 0.4);
331 filterAndStoreRecHits(egTrigObjColls,
tokens_.
ecal);
332 filterAndStoreRecHits(egTrigObjColls,
tokens_.
hcal);
338 for (
size_t collNr = 0; collNr < egTrigObjColls.size(); collNr++) {
347 std::vector<std::pair<std::string, float>>
vars;
348 for (
auto& valueMapHandle : valueMapHandles) {
349 auto mapIt = valueMapHandle->find(ecalCandRef);
350 if (mapIt != valueMapHandle->end()) {
352 if (!valueMapHandle.provenance()->productInstanceName().empty()) {
353 name +=
"_" + valueMapHandle.provenance()->productInstanceName();
355 vars.emplace_back(
std::move(name), mapIt->val);
363 if (!gsfTrksHandle.
isValid()) {
368 for (
size_t trkNr = 0; gsfTrksHandle.
isValid() && trkNr < gsfTrksHandle->size(); trkNr++) {
374 if (scRefFromTrk == scRef) {
375 gsfTrkRefs.push_back(trkRef);
388 if (!eleSeedsHandle.
isValid()) {
393 for (
size_t seedNr = 0; eleSeedsHandle.
isValid() && seedNr < eleSeedsHandle->size(); seedNr++) {
399 trigObjSeeds.push_back(eleSeed);
406 template <
typename RecHitCollection>
408 const std::vector<std::unique_ptr<trigger::EgammaObjectCollection>>& egTrigObjColls,
411 float maxDR2)
const {
412 auto filteredHits = std::make_unique<RecHitCollection>();
416 std::vector<std::pair<float, float>> etaPhis;
417 for (
const auto& egTrigObjs : egTrigObjColls) {
418 for (
const auto& egTrigObj : *egTrigObjs) {
420 etaPhis.push_back({egTrigObj.eta(), egTrigObj.phi()});
422 etaPhis.push_back({egTrigObj.eta(), egTrigObj.phi() + 3.14159});
424 etaPhis.push_back({egTrigObj.eta(), egTrigObj.phi() + 3.14159 / 2.});
428 auto deltaR2Match = [&etaPhis, &maxDR2](
const GlobalPoint& pos) {
429 float eta = pos.eta();
430 float phi = pos.phi();
431 for (
auto& etaPhi : etaPhis) {
432 if (
reco::deltaR2(eta, phi, etaPhi.first, etaPhi.second) < maxDR2)
438 for (
auto&
hit : *recHits) {
442 if (deltaR2Match(cellGeom->getPosition()))
443 filteredHits->push_back(
hit);
445 throw cms::Exception(
"GeomError") <<
"could not get geometry for det id " <<
hit.
id().rawId();
452 const std::vector<std::unique_ptr<trigger::EgammaObjectCollection>>& egTrigObjColls,
454 float maxDR2)
const {
455 auto filteredTrks = std::make_unique<reco::TrackCollection>();
461 std::vector<std::pair<float, float>> etaPhisTmp;
462 for (
const auto& egTrigObjs : egTrigObjColls) {
463 for (
const auto& egTrigObj : *egTrigObjs) {
465 etaPhisTmp.push_back({egTrigObj.eta(), egTrigObj.phi()});
467 for (
const auto& gsfTrk : egTrigObj.gsfTracks()) {
468 etaPhisTmp.push_back({gsfTrk->eta(), gsfTrk->phi()});
473 std::vector<std::pair<float, float>> etaPhis;
474 for (
const auto& etaPhi : etaPhisTmp) {
475 etaPhis.push_back(etaPhi);
477 etaPhis.push_back({etaPhi.first, etaPhi.second + 3.14159});
479 etaPhis.push_back({etaPhi.first, etaPhi.second + 3.14159 / 2.});
482 auto deltaR2Match = [&etaPhis, &maxDR2](
float eta,
float phi) {
483 for (
auto& etaPhi : etaPhis) {
490 for (
auto& trk : *trks) {
491 if (deltaR2Match(trk.eta(), trk.phi()))
492 filteredTrks->push_back(trk);
498 const std::vector<std::unique_ptr<trigger::EgammaObjectCollection>>& egTrigObjColls,
500 float maxDR2)
const {
501 auto filteredPFClus = std::make_unique<reco::PFClusterCollection>();
503 return filteredPFClus;
505 std::vector<std::pair<float, float>> etaPhis;
506 for (
const auto& egTrigObjs : egTrigObjColls) {
507 for (
const auto& egTrigObj : *egTrigObjs) {
509 etaPhis.push_back({egTrigObj.eta(), egTrigObj.phi()});
511 etaPhis.push_back({egTrigObj.eta(), egTrigObj.phi() + 3.14159});
513 etaPhis.push_back({egTrigObj.eta(), egTrigObj.phi() + 3.14159 / 2.});
517 auto deltaR2Match = [&etaPhis, &maxDR2](
float eta,
float phi) {
518 for (
auto& etaPhi : etaPhis) {
525 for (
auto& clus : *pfClus) {
526 if (deltaR2Match(clus.eta(), clus.phi()))
527 filteredPFClus->push_back(clus);
529 return filteredPFClus;
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
constexpr SubDetector subDetGeom[21]
void setVars(std::vector< std::pair< std::string, float >> vars)
#define DEFINE_FWK_MODULE(type)
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
const reco::SuperClusterRef & superCluster() const
void setGsfTracks(reco::GsfTrackRefVector trks)
edm::RefVector< GsfTrackCollection > GsfTrackRefVector
vector of reference to GsfTrack in the same collection
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::vector< edm::EDGetTokenT< int > > tokens_
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
void setSeeds(reco::ElectronSeedRefVector seeds)
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.
T getParameter(std::string const &) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const