34 #include <unordered_map>
46 std::ostringstream valOStr;
49 while (valStr.size() > 1 && valStr.back() ==
'0') {
52 if (valStr.size() > 1 && valStr.back() ==
'.') {
55 auto decPoint = valStr.find(
'.');
56 if (decPoint != std::string::npos) {
57 valStr.replace(decPoint, 1,
"p");
60 valStr.replace(0, 1,
"M");
65 std::vector<std::unique_ptr<int>> countRecHits(
const T& recHitHandle,
const std::vector<double>&
thresholds) {
68 count = std::make_unique<int>(0);
69 if (recHitHandle.isValid()) {
70 for (
const auto&
recHit : *recHitHandle) {
71 for (
size_t thresNr = 0; thresNr <
thresholds.size(); thresNr++) {
91 template <
typename CollType,
typename RefType>
94 std::vector<RefType>& orgRefs,
95 float maxDR2 = 0.4 * 0.4)
const;
100 template <
typename RecHitCollection>
104 float maxDR2 = 0.4 * 0.4)
const;
115 template <
typename T>
122 template <
typename T>
129 for (
size_t tagNr = 0; tagNr <
inputTags.size(); tagNr++) {
133 template <
typename T>
138 const auto& collectionPSets =
pset.getParameter<std::vector<edm::ParameterSet>>(
tagname);
139 for (
const auto& collPSet : collectionPSets) {
142 tokens.emplace_back(std::make_pair(
token,
label));
147 template <
typename T,
typename H>
149 auto valueMap = std::make_unique<edm::ValueMap<T>>();
180 produces<L1TrackCollection>();
181 produces<L1TrackTruthPairCollection>();
182 produces<TrackingParticleCollection>();
183 produces<reco::CaloClusterCollection>(
"hgcalLayerClusters");
184 produces<edm::ValueMap<std::pair<float, float>>>(
"hgcalLayerClustersTime");
186 produces<HGCRecHitCollection>(tokenLabel.second);
188 produces<int>(
"countHgcalRecHits" + tokenLabel.second +
"Thres" + convertToProdNameStr(thres) +
"GeV");
201 desc.add<
double>(
"minPtToSaveHits", 0.);
202 desc.add<
bool>(
"saveHitsPlusPi",
true);
203 desc.add<
bool>(
"saveHitsPlusHalfPi",
true);
204 desc.add<std::vector<double>>(
"recHitCountThresholds",
std::vector{0., 0.5, 1.0, 1.5, 2.0});
205 std::vector<edm::ParameterSet> ecalDefaults(2);
209 std::vector<edm::ParameterSet> hgcalDefaults(3);
210 hgcalDefaults[0].addParameter(
"src",
edm::InputTag(
"HGCalRecHit",
"HGCEERecHits"));
211 hgcalDefaults[0].addParameter(
"label",
std::string(
"HGCEERecHits"));
212 hgcalDefaults[1].addParameter(
"src",
edm::InputTag(
"HGCalRecHit",
"HGCHEFRecHits"));
213 hgcalDefaults[1].addParameter(
"label",
std::string(
"HGCHEFRecHits"));
214 hgcalDefaults[2].addParameter(
"src",
edm::InputTag(
"HGCalRecHit",
"HGCHEBRecHits"));
215 hgcalDefaults[2].addParameter(
"label",
std::string(
"HGCHEBRecHits"));
216 desc.addVPSet(
"hgcal", tokenLabelDesc, hgcalDefaults);
217 descriptions.
add((
"hltEgammaHLTPhase2ExtraProducer"),
desc);
232 auto handle =
event.getHandle(tokenLabel.first);
237 for (
const auto& tokenLabel : tokenLabels) {
238 auto handle =
event.getHandle(tokenLabel.first);
240 for (
size_t thresNr = 0; thresNr <
thresholds.size(); thresNr++) {
243 prefixLabel + tokenLabel.second +
"Thres" + convertToProdNameStr(thres) +
"GeV");
251 std::vector<edm::Ref<reco::CaloClusterCollection>> orgHGCalLayerClusterRefs;
253 std::vector<std::pair<float, float>> timesFiltered;
254 timesFiltered.reserve(orgHGCalLayerClusterRefs.size());
255 for (
auto& clusRef : orgHGCalLayerClusterRefs) {
256 timesFiltered.push_back((*hgcalLayerClustersTime)[clusRef]);
258 auto hgcalLayerClustersFilteredHandle =
event.put(
std::move(hgcalLayerClustersFiltered),
"hgcalLayerClusters");
259 event.put(
makeValueMap(hgcalLayerClustersFilteredHandle, timesFiltered),
"hgcalLayerClustersTime");
261 std::vector<edm::Ref<L1TrackCollection>> orgL1TrkRefs;
262 auto l1TrksFiltered =
filterObjs(*egTrigObjs, l1trks, orgL1TrkRefs);
263 std::vector<edm::Ref<TrackingParticleCollection>> orgTPRefs;
264 auto trkPartsFiltered =
filterObjs(*egTrigObjs, trkParts, orgTPRefs);
267 std::unordered_map<size_t, size_t> orgTPIndxToNewIndx;
268 for (
size_t refNr = 0; refNr < orgTPRefs.size(); refNr++) {
269 orgTPIndxToNewIndx.insert(std::make_pair(orgTPRefs[refNr].
key(), refNr));
275 auto l1TrkExtraColl = std::make_unique<L1TrackTruthPairCollection>();
277 for (
size_t l1TrkNr = 0; l1TrkNr < orgL1TrkRefs.size(); l1TrkNr++) {
278 auto orgTrkRef = orgL1TrkRefs[l1TrkNr];
281 if (l1TrkToTrkPartMap->isGenuine(orgTrkPtr))
283 if (l1TrkToTrkPartMap->isLooselyGenuine(orgTrkPtr))
285 if (l1TrkToTrkPartMap->isCombinatoric(orgTrkPtr))
287 if (l1TrkToTrkPartMap->isUnknown(orgTrkPtr))
290 auto orgTPRef = l1TrkToTrkPartMap->findTrackingParticlePtr(orgTrkPtr);
291 auto getNewTPRef = [&orgTPIndxToNewIndx, &orgTPRef, &trkPartsFiltHandle]() {
292 auto newIndexPair = orgTPIndxToNewIndx.find(orgTPRef.key());
293 if (newIndexPair != orgTPIndxToNewIndx.end()) {
298 auto newTPRef = getNewTPRef();
302 l1TrkExtraColl->push_back(l1TrkExtra);
307 template <
typename CollType,
typename RefType>
310 std::vector<RefType>& orgRefs,
311 float maxDR2)
const {
312 auto filteredObjs = std::make_unique<CollType>();
319 std::vector<std::pair<float, float>> etaPhisTmp;
320 for (
const auto& egTrigObj : egTrigObjs) {
322 etaPhisTmp.push_back({egTrigObj.eta(), egTrigObj.phi()});
324 for (
const auto& gsfTrk : egTrigObj.gsfTracks()) {
325 etaPhisTmp.push_back({gsfTrk->eta(), gsfTrk->phi()});
329 std::vector<std::pair<float, float>> etaPhis;
330 for (
const auto& etaPhi : etaPhisTmp) {
331 etaPhis.push_back(etaPhi);
333 etaPhis.push_back({etaPhi.first, etaPhi.second + 3.14159});
335 etaPhis.push_back({etaPhi.first, etaPhi.second + 3.14159 / 2.});
338 auto deltaR2Match = [&etaPhis, &maxDR2](
float eta,
float phi) {
339 for (
auto& etaPhi : etaPhis) {
346 for (
size_t objNr = 0; objNr <
objs->size(); objNr++) {
347 RefType ref(
objs, objNr);
348 if (deltaR2Match(ref->eta(), ref->phi())) {
349 filteredObjs->push_back(*ref);
350 orgRefs.push_back(ref);
356 template <
typename RecHitCollection>
361 float maxDR2)
const {
362 auto filteredHits = std::make_unique<RecHitCollection>();
366 std::vector<std::pair<float, float>> etaPhis;
367 for (
const auto& egTrigObj : egTrigObjs) {
369 etaPhis.push_back({egTrigObj.eta(), egTrigObj.phi()});
371 etaPhis.push_back({egTrigObj.eta(), egTrigObj.phi() + 3.14159});
373 etaPhis.push_back({egTrigObj.eta(), egTrigObj.phi() + 3.14159 / 2.});
379 for (
auto& etaPhi : etaPhis) {
390 if (deltaR2Match(cellGeom->getPosition()))
391 filteredHits->push_back(
hit);
393 throw cms::Exception(
"GeomError") <<
"could not get geometry for det id " <<
hit.
id().rawId();