4 #include <unordered_set>
52 preshowerEcalHits_(doPreshowerEcalHits_
61 applyPhotonCalibOnData_(
config.getParameter<
bool>(
"applyPhotonCalibOnData")),
62 applyPhotonCalibOnMC_(
config.getParameter<
bool>(
"applyPhotonCalibOnMC")),
63 applyGsfElectronCalibOnData_(
config.getParameter<
bool>(
"applyGsfElectronCalibOnData")),
64 applyGsfElectronCalibOnMC_(
config.getParameter<
bool>(
"applyGsfElectronCalibOnMC")),
66 outPhotons_(
"reducedGedPhotons"),
67 outPhotonCores_(
"reducedGedPhotonCores"),
68 outOOTPhotons_(
"reducedOOTPhotons"),
69 outOOTPhotonCores_(
"reducedOOTPhotonCores"),
70 outGsfElectrons_(
"reducedGedGsfElectrons"),
71 outGsfElectronCores_(
"reducedGedGsfElectronCores"),
72 outGsfTracks_(
"reducedGsfTracks"),
73 outConversions_(
"reducedConversions"),
74 outSingleConversions_(
"reducedSingleLegConversions"),
75 outSuperClusters_(
"reducedSuperClusters"),
76 outEBEEClusters_(
"reducedEBEEClusters"),
77 outESClusters_(
"reducedESClusters"),
78 outOOTSuperClusters_(
"reducedOOTSuperClusters"),
79 outOOTEBEEClusters_(
"reducedOOTEBEEClusters"),
80 outOOTESClusters_(
"reducedOOTESClusters"),
81 outEBRecHits_(
"reducedEBRecHits"),
82 outEERecHits_(
"reducedEERecHits"),
83 outESRecHits_(
"reducedESRecHits"),
84 outHBHERecHits_(
"reducedHBHEHits"),
85 outPhotonPfCandMap_(
"reducedPhotonPfCandMap"),
86 outGsfElectronPfCandMap_(
"reducedGsfElectronPfCandMap"),
88 outGsfElectronIds_(
config.getParameter<
std::vector<
std::
string>>(
"gsfElectronIDOutput")),
89 outPhotonFloatValueMaps_(
config.getParameter<
std::vector<
std::
string>>(
"photonFloatValueMapOutput")),
90 outOOTPhotonFloatValueMaps_(
config.getParameter<
std::vector<
std::
string>>(
"ootPhotonFloatValueMapOutput")),
91 outGsfElectronFloatValueMaps_(
config.getParameter<
std::vector<
std::
string>>(
"gsfElectronFloatValueMapOutput")),
93 slimRelinkPhotonSel_(
config.getParameter<
std::
string>(
"slimRelinkPhotons")),
96 slimRelinkOOTPhotonSel_(
config.getParameter<
std::
string>(
"slimRelinkOOTPhotons")),
97 relinkOOTPhotonSel_(
config.getParameter<
std::
string>(
"relinkOOTPhotons")),
98 keepGsfElectronSel_(
config.getParameter<
std::
string>(
"keepGsfElectrons")),
99 slimRelinkGsfElectronSel_(
config.getParameter<
std::
string>(
"slimRelinkGsfElectrons")),
100 relinkGsfElectronSel_(
config.getParameter<
std::
string>(
"relinkGsfElectrons")),
103 if (not aTag.
label().empty())
104 ootPhotonT_ = consumes<reco::PhotonCollection>(aTag);
106 const std::vector<edm::InputTag>& photonidinputs =
config.getParameter<std::vector<edm::InputTag>>(
"photonIDSources");
111 const std::vector<edm::InputTag>& gsfelectronidinputs =
112 config.getParameter<std::vector<edm::InputTag>>(
"gsfElectronIDSources");
117 const std::vector<edm::InputTag>& photonpfclusterisoinputs =
118 config.getParameter<std::vector<edm::InputTag>>(
"photonFloatValueMapSources");
123 const std::vector<edm::InputTag>& ootphotonpfclusterisoinputs =
124 config.getParameter<std::vector<edm::InputTag>>(
"ootPhotonFloatValueMapSources");
129 const std::vector<edm::InputTag>& gsfelectronpfclusterisoinputs =
130 config.getParameter<std::vector<edm::InputTag>>(
"gsfElectronFloatValueMapSources");
173 produces<edm::ValueMap<bool>>(outid);
176 produces<edm::ValueMap<float>>(outid);
179 produces<edm::ValueMap<float>>(outid);
183 produces<edm::ValueMap<float>>(outid);
187 produces<edm::ValueMap<float>>(outid);
236 std::vector<edm::Handle<edm::ValueMap<bool>>> photonIdHandles(
photonIdTs_.size());
242 std::vector<edm::Handle<edm::ValueMap<float>>> gsfElectronIdHandles(
gsfElectronIdTs_.size());
251 theEvent.
getByToken(photonFloatValueMapT, photonFloatValueMapHandles[
index++]);
258 theEvent.
getByToken(ootPhotonFloatValueMapT, ootPhotonFloatValueMapHandles[
index++]);
265 theEvent.
getByToken(gsfElectronFloatValueMapT, gsfElectronFloatValueMapHandles[
index++]);
290 auto photons = std::make_unique<reco::PhotonCollection>();
291 auto photonCores = std::make_unique<reco::PhotonCoreCollection>();
292 auto ootPhotons = std::make_unique<reco::PhotonCollection>();
293 auto ootPhotonCores = std::make_unique<reco::PhotonCoreCollection>();
294 auto gsfElectrons = std::make_unique<reco::GsfElectronCollection>();
295 auto gsfElectronCores = std::make_unique<reco::GsfElectronCoreCollection>();
296 auto gsfTracks = std::make_unique<reco::GsfTrackCollection>();
297 auto conversions = std::make_unique<reco::ConversionCollection>();
299 auto superClusters = std::make_unique<reco::SuperClusterCollection>();
300 auto ebeeClusters = std::make_unique<reco::CaloClusterCollection>();
301 auto esClusters = std::make_unique<reco::CaloClusterCollection>();
302 auto ootSuperClusters = std::make_unique<reco::SuperClusterCollection>();
303 auto ootEbeeClusters = std::make_unique<reco::CaloClusterCollection>();
304 auto ootEsClusters = std::make_unique<reco::CaloClusterCollection>();
305 auto ebRecHits = std::make_unique<EcalRecHitCollection>();
306 auto eeRecHits = std::make_unique<EcalRecHitCollection>();
307 auto esRecHits = std::make_unique<EcalRecHitCollection>();
308 auto hbheRecHits = std::make_unique<HBHERecHitCollection>();
309 auto photonPfCandMap = std::make_unique<edm::ValueMap<std::vector<reco::PFCandidateRef>>>();
310 auto gsfElectronPfCandMap = std::make_unique<edm::ValueMap<std::vector<reco::PFCandidateRef>>>();
313 std::map<reco::PhotonCoreRef, unsigned int> photonCoreMap;
314 std::map<reco::PhotonCoreRef, unsigned int> ootPhotonCoreMap;
315 std::map<reco::GsfElectronCoreRef, unsigned int> gsfElectronCoreMap;
316 std::map<reco::GsfTrackRef, unsigned int> gsfTrackMap;
317 std::map<reco::ConversionRef, unsigned int> conversionMap;
318 std::map<reco::ConversionRef, unsigned int> singleConversionMap;
319 std::map<reco::SuperClusterRef, unsigned int> superClusterMap;
320 std::map<reco::CaloClusterPtr, unsigned int> ebeeClusterMap;
321 std::map<reco::CaloClusterPtr, unsigned int> esClusterMap;
322 std::map<reco::SuperClusterRef, unsigned int> ootSuperClusterMap;
323 std::map<reco::CaloClusterPtr, unsigned int> ootEbeeClusterMap;
324 std::map<reco::CaloClusterPtr, unsigned int> ootEsClusterMap;
325 std::unordered_set<DetId> rechitMap;
326 std::unordered_set<DetId> hcalRechitMap;
328 std::unordered_set<unsigned int> superClusterFullRelinkMap;
329 std::unordered_set<unsigned int> ootSuperClusterFullRelinkMap;
332 std::vector<std::vector<reco::PFCandidateRef>> pfCandIsoPairVecPho;
333 std::vector<std::vector<reco::PFCandidateRef>> pfCandIsoPairVecEle;
336 std::vector<std::vector<bool>> photonIdVals(photonIdHandles.size());
337 std::vector<std::vector<float>> gsfElectronIdVals(gsfElectronIdHandles.size());
338 std::vector<std::vector<float>> photonFloatValueMapVals(photonFloatValueMapHandles.size());
339 std::vector<std::vector<float>> ootPhotonFloatValueMapVals(ootPhotonFloatValueMapHandles.size());
340 std::vector<std::vector<float>> gsfElectronFloatValueMapVals(gsfElectronFloatValueMapHandles.size());
344 for (
const auto&
photon : *photonHandle) {
349 auto& newPhoton =
photons->back();
352 calibratePhoton(newPhoton, photonref, *photonCalibEnergyHandle, *photonCalibEnergyErrHandle);
363 pfCandIsoPairVecPho.push_back((*photonPfCandMapHandle)[photonref]);
367 for (
const auto& photonIdHandle : photonIdHandles) {
368 photonIdVals[subindex++].push_back((*photonIdHandle)[photonref]);
372 for (
const auto& photonFloatValueMapHandle : photonFloatValueMapHandles) {
373 photonFloatValueMapVals[subindex++].push_back((*photonFloatValueMapHandle)[photonref]);
412 for (
const auto& ootPhoton : *ootPhotonHandle) {
425 for (
const auto& ootPhotonFloatValueMapHandle : ootPhotonFloatValueMapHandles) {
426 ootPhotonFloatValueMapVals[subindex++].push_back((*ootPhotonFloatValueMapHandle)[ootPhotonref]);
441 linkSuperCluster(ootSuperCluster, ootSuperClusterMap, *ootSuperClusters, relink, ootSuperClusterFullRelinkMap);
443 linkHcalHits(*ootPhoton.superCluster(), *hbheHitHandle, hcalRechitMap);
449 for (
const auto& gsfElectron : *gsfElectronHandle) {
459 *gsfElectronCalibEnergyHandle,
460 *gsfElectronCalibEnergyErrHandle,
461 *gsfElectronCalibEcalEnergyHandle,
462 *gsfElectronCalibEcalEnergyErrHandle);
471 pfCandIsoPairVecEle.push_back((*gsfElectronPfCandMapHandle)[gsfElectronref]);
475 for (
const auto& gsfElectronIdHandle : gsfElectronIdHandles) {
476 gsfElectronIdVals[subindex++].push_back((*gsfElectronIdHandle)[gsfElectronref]);
480 for (
const auto& gsfElectronFloatValueMapHandle : gsfElectronFloatValueMapHandles) {
481 gsfElectronFloatValueMapVals[subindex++].push_back((*gsfElectronFloatValueMapHandle)[gsfElectronref]);
485 linkCore(gsfElectronCore, *gsfElectronCores, gsfElectronCoreMap);
490 if (!gsfTrackMap.count(gsfTrack)) {
492 gsfTrackMap[gsfTrack] =
gsfTracks->size() - 1;
497 igsf != gsfElectron.ambiguousGsfTracksEnd();
500 if (!gsfTrackMap.count(ambigGsfTrack)) {
502 gsfTrackMap[ambigGsfTrack] =
gsfTracks->size() - 1;
534 linkHcalHits(*gsfElectron.superCluster(), *hbheHitHandle, hcalRechitMap);
545 bool fullrelink = superClusterFullRelinkMap.count(
index++);
548 superCluster.clearHitsAndFractions();
573 for (
auto& ootSuperCluster : *ootSuperClusters) {
579 bool fullrelink = ootSuperClusterFullRelinkMap.count(
index++);
582 ootSuperCluster.clearHitsAndFractions();
601 for (
const EcalRecHit& rechit : *barrelHitHandle) {
602 if (rechitMap.count(rechit.detid())) {
603 ebRecHits->push_back(rechit);
607 for (
const EcalRecHit& rechit : *endcapHitHandle) {
608 if (rechitMap.count(rechit.detid())) {
609 eeRecHits->push_back(rechit);
617 for (
const EcalRecHit& rechit : *preshowerHitHandle) {
618 if (rechitMap.count(rechit.detid())) {
619 esRecHits->push_back(rechit);
625 for (
const HBHERecHit& rechit : *hbheHitHandle) {
626 if (hcalRechitMap.count(rechit.detid())) {
627 hbheRecHits->push_back(rechit);
642 relinkCaloClusters(superCluster, ebeeClusterMap, esClusterMap, outEBEEClusterHandle, outESClusterHandle);
655 ootSuperCluster, ootEbeeClusterMap, ootEsClusterMap, outOOTEBEEClusterHandle, outOOTESClusterHandle);
723 std::vector<reco::GsfTrackRef> ambigTracksInThisElectron;
726 igsf != gsfElectron.ambiguousGsfTracksEnd();
728 ambigTracksInThisElectron.push_back(*igsf);
732 gsfElectron.clearAmbiguousGsfTracks();
735 for (
const auto& it : ambigTracksInThisElectron) {
736 const auto& gsftkmapped = gsfTrackMap.find(it);
738 if (gsftkmapped != gsfTrackMap.end()) {
740 gsfElectron.addAmbiguousGsfTrack(gsftkref);
742 throw cms::Exception(
"There must be a problem with linking and mapping of ambiguous gsf tracks...");
745 if (gsfElectron.ambiguousGsfTracksSize() > 0)
746 gsfElectron.setAmbiguous(
true);
748 ambigTracksInThisElectron.clear();
763 fillerPhotons.insert(outPhotonHandle, pfCandIsoPairVecPho.begin(), pfCandIsoPairVecPho.end());
764 fillerPhotons.fill();
768 fillerGsfElectrons.insert(outGsfElectronHandle, pfCandIsoPairVecEle.begin(), pfCandIsoPairVecEle.end());
769 fillerGsfElectrons.fill();
776 auto oMap = std::make_unique<MapType>();
778 typename MapType::Filler
filler(*oMap);
779 filler.insert(refH, vec.begin(), vec.end());
787 for (
auto const& vals : photonIdVals) {
793 for (
auto const& vals : gsfElectronIdVals) {
799 for (
auto const& vals : photonFloatValueMapVals) {
806 for (
auto const& vals : ootPhotonFloatValueMapVals) {
813 for (
auto const& vals : gsfElectronFloatValueMapVals) {
818 template <
typename T,
typename U>
820 if (!coreMap.count(
core)) {
827 std::map<reco::SuperClusterRef, unsigned int>& superClusterMap,
830 std::unordered_set<unsigned int>& superClusterFullRelinkMap) {
831 const auto& mappedsc = superClusterMap.find(superCluster);
834 unsigned int mappedscidx = 0;
835 if (mappedsc == superClusterMap.end()) {
838 superClusterMap[superCluster] = mappedscidx;
840 mappedscidx = mappedsc->second;
845 superClusterFullRelinkMap.insert(mappedscidx);
850 std::map<reco::ConversionRef, unsigned int>& conversionMap) {
851 for (
const auto& convref : convrefs) {
859 std::map<reco::ConversionRef, unsigned int>& conversionMap) {
875 std::map<reco::ConversionRef, unsigned int>& conversionMap) {
890 std::map<reco::ConversionRef, unsigned int>& conversionMap) {
891 if (!conversionMap.count(convref)) {
899 std::map<reco::CaloClusterPtr, unsigned int>& caloClusterMap) {
900 if (!caloClusterMap.count(caloCluster)) {
901 caloClusters.push_back(*caloCluster);
902 caloClusterMap[caloCluster] = caloClusters.size() - 1;
908 std::map<reco::CaloClusterPtr, unsigned int>& ebeeClusterMap,
909 std::unordered_set<DetId>& rechitMap,
914 std::map<reco::CaloClusterPtr, unsigned int>& esClusterMap) {
915 for (
const auto& cluster : superCluster.
clusters()) {
918 for (
const auto& hitfrac : cluster->hitsAndFractions()) {
919 rechitMap.insert(hitfrac.first);
922 bool barrel = cluster->hitsAndFractions().front().first.subdetId() ==
EcalBarrel;
924 DetId seed = EcalClusterTools::getMaximum(*cluster, rhcol).first;
926 std::vector<DetId> dets5x5 =
928 for (
const auto& detid : dets5x5) {
929 rechitMap.insert(detid);
935 for (
const auto& hitfrac : cluster->hitsAndFractions()) {
936 rechitMap.insert(hitfrac.first);
943 std::unordered_set<DetId>& hcalDetIds) {
948 const std::map<reco::CaloClusterPtr, unsigned int>& ebeeClusterMap,
949 const std::map<reco::CaloClusterPtr, unsigned int>& esClusterMap,
953 const auto& seedmapped = ebeeClusterMap.find(superCluster.
seed());
954 if (seedmapped != ebeeClusterMap.end()) {
962 for (
const auto& cluster : superCluster.
clusters()) {
963 const auto& clustermapped = ebeeClusterMap.find(cluster);
964 if (clustermapped != ebeeClusterMap.end()) {
981 const auto& clustermapped = esClusterMap.find(cluster);
982 if (clustermapped != esClusterMap.end()) {
992 if (!esclusters.
empty()) {
997 template <
typename T>
1000 const std::map<reco::SuperClusterRef, unsigned int>& superClusterMap,
1002 const auto& scmapped = superClusterMap.find(
core.superCluster());
1003 if (scmapped != superClusterMap.end()) {
1006 core.setSuperCluster(scref);
1011 const std::map<reco::GsfTrackRef, unsigned int>& gsfTrackMap,
1013 const auto& gsftkmapped = gsfTrackMap.find(gsfElectronCore.
gsfTrack());
1014 if (gsftkmapped != gsfTrackMap.end()) {
1022 const std::map<reco::ConversionRef, unsigned int>& conversionMap,
1025 for (
const auto& convref : convrefs) {
1026 const auto& convmapped = conversionMap.find(convref);
1027 if (convmapped != conversionMap.end()) {
1032 outconvrefs.
clear();
1036 if (!outconvrefs.
empty()) {
1042 const std::map<reco::PhotonCoreRef, unsigned int>& photonCoreMap,
1044 const auto& coremapped = photonCoreMap.find(
photon.photonCore());
1045 if (coremapped != photonCoreMap.end()) {
1048 photon.setPhotonCore(coreref);
1054 const std::map<reco::GsfElectronCoreRef, unsigned int>& gsfElectronCoreMap,
1056 const auto& coremapped = gsfElectronCoreMap.find(gsfElectron.
core());
1057 if (coremapped != gsfElectronCoreMap.end()) {
1068 float newEnergy = energyMap[oldPhoRef];
1069 float newEnergyErr = energyErrMap[oldPhoRef];
1070 photon.setCorrectedEnergy(reco::Photon::P4type::regression2, newEnergy, newEnergyErr,
true);
1079 const float newEnergy = energyMap[oldEleRef];
1080 const float newEnergyErr = energyErrMap[oldEleRef];
1081 const float newEcalEnergy = ecalEnergyMap[oldEleRef];
1082 const float newEcalEnergyErr = ecalEnergyErrMap[oldEleRef];
1086 const float corr = newEnergy / oldP4.E();
1088 electron.setCorrectedEcalEnergy(newEcalEnergy);
1089 electron.setCorrectedEcalEnergyError(newEcalEnergyErr);
1093 electron.correctMomentum(newP4,
electron.trackMomentumError(), newEnergyErr);