54 electronToken_(consumes<
edm::
View<
reco::GsfElectron>>(iConfig.getParameter<
edm::
InputTag>(
"electronSource"))),
56 embedGsfElectronCore_(iConfig.getParameter<
bool>(
"embedGsfElectronCore")),
57 embedGsfTrack_(iConfig.getParameter<
bool>(
"embedGsfTrack")),
58 embedSuperCluster_(iConfig.getParameter<
bool>(
"embedSuperCluster")),
59 embedPflowSuperCluster_(iConfig.getParameter<
bool>(
"embedPflowSuperCluster")),
60 embedSeedCluster_(iConfig.getParameter<
bool>(
"embedSeedCluster")),
61 embedBasicClusters_(iConfig.getParameter<
bool>(
"embedBasicClusters")),
62 embedPreshowerClusters_(iConfig.getParameter<
bool>(
"embedPreshowerClusters")),
63 embedPflowBasicClusters_(iConfig.getParameter<
bool>(
"embedPflowBasicClusters")),
64 embedPflowPreshowerClusters_(iConfig.getParameter<
bool>(
"embedPflowPreshowerClusters")),
65 embedTrack_(iConfig.getParameter<
bool>(
"embedTrack")),
66 addGenMatch_(iConfig.getParameter<
bool>(
"addGenMatch")),
67 embedGenMatch_(addGenMatch_ ? iConfig.getParameter<
bool>(
"embedGenMatch") :
false),
68 embedRecHits_(iConfig.getParameter<
bool>(
"embedRecHits")),
70 useParticleFlow_(iConfig.getParameter<
bool>(
"useParticleFlow")),
71 usePfCandidateMultiMap_(iConfig.getParameter<
bool>(
"usePfCandidateMultiMap")),
72 pfElecToken_(!usePfCandidateMultiMap_
76 iConfig.getParameter<
edm::
InputTag>(
"pfCandidateMap"))
78 pfCandidateMultiMapToken_(usePfCandidateMultiMap_
80 iConfig.getParameter<
edm::
InputTag>(
"pfCandidateMultiMap"))
82 embedPFCandidate_(iConfig.getParameter<
bool>(
"embedPFCandidate")),
84 addMVAVariables_(iConfig.getParameter<
bool>(
"addMVAVariables")),
85 reducedBarrelRecHitCollection_(iConfig.getParameter<
edm::
InputTag>(
"reducedBarrelRecHitCollection")),
86 reducedBarrelRecHitCollectionToken_(mayConsume<
EcalRecHitCollection>(reducedBarrelRecHitCollection_)),
87 reducedEndcapRecHitCollection_(iConfig.getParameter<
edm::
InputTag>(
"reducedEndcapRecHitCollection")),
88 reducedEndcapRecHitCollectionToken_(mayConsume<
EcalRecHitCollection>(reducedEndcapRecHitCollection_)),
89 ecalClusterToolsESGetTokens_{consumesCollector()},
91 addPFClusterIso_(iConfig.getParameter<
bool>(
"addPFClusterIso")),
92 addPuppiIsolation_(iConfig.getParameter<
bool>(
"addPuppiIsolation")),
96 embedHighLevelSelection_(iConfig.getParameter<
bool>(
"embedHighLevelSelection")),
97 beamLineToken_(consumes<reco::BeamSpot>(iConfig.getParameter<
edm::InputTag>(
"beamLineSrc"))),
98 pvToken_(mayConsume<std::vector<reco::Vertex>>(iConfig.getParameter<
edm::InputTag>(
"pvSrc"))),
99 addElecID_(iConfig.getParameter<
bool>(
"addElectronID")),
101 isolator_(iConfig.exists(
"userIsolation") ? iConfig.getParameter<
edm::ParameterSet>(
"userIsolation")
105 addEfficiencies_(iConfig.getParameter<
bool>(
"addEfficiencies")),
106 addResolutions_(iConfig.getParameter<
bool>(
"addResolutions")),
107 useUserData_(iConfig.exists(
"userData"))
118 iConfig.getParameter<std::vector<edm::InputTag>>(
"genParticleMatch"),
119 [
this](
edm::InputTag const&
tag) { return consumes<edm::Association<reco::GenParticleCollection>>(tag); });
123 if (addResolutions_) {
126 if (addPuppiIsolation_) {
128 PUPPIIsolation_charged_hadrons_ =
129 consumes<edm::ValueMap<float>>(iConfig.getParameter<
edm::InputTag>(
"puppiIsolationChargedHadrons"));
130 PUPPIIsolation_neutral_hadrons_ =
131 consumes<edm::ValueMap<float>>(iConfig.getParameter<
edm::InputTag>(
"puppiIsolationNeutralHadrons"));
132 PUPPIIsolation_photons_ =
133 consumes<edm::ValueMap<float>>(iConfig.getParameter<
edm::InputTag>(
"puppiIsolationPhotons"));
135 PUPPINoLeptonsIsolation_charged_hadrons_ =
136 consumes<edm::ValueMap<float>>(iConfig.getParameter<
edm::InputTag>(
"puppiNoLeptonsIsolationChargedHadrons"));
137 PUPPINoLeptonsIsolation_neutral_hadrons_ =
138 consumes<edm::ValueMap<float>>(iConfig.getParameter<
edm::InputTag>(
"puppiNoLeptonsIsolationNeutralHadrons"));
139 PUPPINoLeptonsIsolation_photons_ =
140 consumes<edm::ValueMap<float>>(iConfig.getParameter<
edm::InputTag>(
"puppiNoLeptonsIsolationPhotons"));
146 elecIDSrcs_.push_back(NameTag(
"", iConfig.getParameter<
edm::InputTag>(
"electronIDSource")));
151 if (!elecIDSrcs_.empty()) {
153 <<
"PATElectronProducer: you can't specify both 'electronIDSource' and 'electronIDSources'\n";
158 for (std::vector<std::string>::const_iterator it =
names.begin(), ed =
names.end(); it != ed; ++it) {
163 if (elecIDSrcs_.empty()) {
165 <<
"PATElectronProducer: id addElectronID is true, you must specify either:\n"
166 <<
"\tInputTag electronIDSource = <someTag>\n"
168 <<
"\tPSet electronIDSources = { \n"
169 <<
"\t\tInputTag <someName> = <someTag> // as many as you want \n "
174 elecIDSrcs_, [
this](NameTag
const&
tag) {
return mayConsume<edm::ValueMap<float>>(
tag.second); });
196 computeMiniIso_ = iConfig.getParameter<
bool>(
"computeMiniIso");
197 miniIsoParamsE_ = iConfig.getParameter<std::vector<double>>(
"miniIsoParamsE");
198 miniIsoParamsB_ = iConfig.getParameter<std::vector<double>>(
"miniIsoParamsB");
199 if (computeMiniIso_ && (miniIsoParamsE_.size() != 9 || miniIsoParamsB_.size() != 9)) {
200 throw cms::Exception(
"ParameterError") <<
"miniIsoParams must have exactly 9 elements.\n";
203 pcToken_ = consumes<pat::PackedCandidateCollection>(iConfig.getParameter<
edm::InputTag>(
"pfCandsForMiniIso"));
206 readIsolationLabels(iConfig,
"isoDeposits", isoDepositLabels_, isoDepositTokens_);
208 readIsolationLabels(iConfig,
"isolationValues", isolationValueLabels_, isolationValueTokens_);
210 readIsolationLabels(iConfig,
"isolationValuesNoPFId", isolationValueLabelsNoPFId_, isolationValueNoPFIdTokens_);
212 if (addEfficiencies_) {
223 if (useParticleFlow_ && usePfCandidateMultiMap_)
224 throw cms::Exception(
"Configuration",
"usePfCandidateMultiMap not supported when useParticleFlow is set to true");
227 produces<std::vector<Electron>>();
234 if (
iEvent.isRealData()) {
300 std::vector<edm::Handle<edm::ValueMap<float>>> idhandles;
301 std::vector<pat::Electron::IdPair> ids;
316 bool beamSpotIsValid =
false;
317 bool primaryVertexIsValid =
false;
331 if (pvHandle.
isValid() && !pvHandle->empty()) {
333 primaryVertexIsValid =
true;
336 <<
"No primary vertex available from EventSetup, not adding high level selection \n";
358 std::vector<Electron>*
patElectrons =
new std::vector<Electron>();
373 bool MatchedToAmbiguousGsfTrack =
false;
378 if (
Matched || MatchedToAmbiguousGsfTrack)
383 if (itElectron->gsfTrack() ==
i->gsfTrackRef()) {
386 for (
auto const& it : itElectron->ambiguousGsfTracks()) {
387 MatchedToAmbiguousGsfTrack |= (
bool)(
i->gsfTrackRef() == it);
391 if (
Matched || MatchedToAmbiguousGsfTrack) {
401 (*PUPPIIsolation_neutral_hadrons)[elePtr],
402 (*PUPPIIsolation_photons)[elePtr]);
404 (*PUPPINoLeptonsIsolation_neutral_hadrons)[elePtr],
405 (*PUPPINoLeptonsIsolation_photons)[elePtr]);
429 if (
track.isNonnull() &&
track.isAvailable()) {
434 ip3d = ip3dpv.second.value();
443 ids[
i].second = (*idhandles[
i])[elecsRef];
446 ids.push_back(std::make_pair(
"pf_evspi", pfRef->mva_e_pi()));
447 ids.push_back(std::make_pair(
"pf_evsmu", pfRef->mva_e_mu()));
453 const auto& vCov = lazyTools.localCovariances(*(itElectron->superCluster()->seed()));
469 std::vector<DetId> selectedCells;
470 bool barrel = itElectron->isEB();
474 clusIt != itElectron->superCluster()->clustersEnd();
477 DetId seed = lazyTools.getMaximum(**clusIt).first;
479 std::vector<DetId> dets5x5 =
482 selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
485 for (
const std::pair<DetId, float>&
hit : (*clusIt)->hitsAndFractions()) {
486 selectedCells.push_back(
hit.first);
493 clusIt != itElectron->parentSuperCluster()->clustersEnd();
496 DetId seed = lazyTools.getMaximum(**clusIt).first;
498 std::vector<DetId> dets5x5 =
501 selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
504 for (
const std::pair<DetId, float>&
hit : (*clusIt)->hitsAndFractions()) {
505 selectedCells.push_back(
hit.first);
511 std::sort(selectedCells.begin(), selectedCells.end());
512 std::unique(selectedCells.begin(), selectedCells.end());
525 unsigned nSelectedCells = selectedCells.size();
526 for (
unsigned icell = 0; icell < nSelectedCells; ++icell) {
532 selectedRecHits.
sort();
537 bool passconversionveto =
false;
538 if (hConversions.isValid()) {
580 bool pfCandsPresent =
false, valMapPresent =
false;
609 }
else if (pfCandsPresent) {
617 if (trkRef == pfTrkRef) {
624 }
else if (valMapPresent) {
649 for (
size_t j = 0, nd =
deposits.size();
j < nd; ++
j) {
656 ids[
i].second = (*idhandles[
i])[elecsRef];
673 if (
track.isNonnull() &&
track.isAvailable()) {
678 ip3d = ip3dpv.second.value();
684 const auto& vCov = lazyTools.localCovariances(*(itElectron->superCluster()->seed()));
703 (*PUPPIIsolation_neutral_hadrons)[elePtr],
704 (*PUPPIIsolation_photons)[elePtr]);
706 (*PUPPINoLeptonsIsolation_neutral_hadrons)[elePtr],
707 (*PUPPINoLeptonsIsolation_photons)[elePtr]);
713 std::vector<DetId> selectedCells;
714 bool barrel = itElectron->isEB();
718 clusIt != itElectron->superCluster()->clustersEnd();
721 DetId seed = lazyTools.getMaximum(**clusIt).first;
723 std::vector<DetId> dets5x5 =
726 selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
729 for (
const std::pair<DetId, float>&
hit : (*clusIt)->hitsAndFractions()) {
730 selectedCells.push_back(
hit.first);
737 clusIt != itElectron->parentSuperCluster()->clustersEnd();
740 DetId seed = lazyTools.getMaximum(**clusIt).first;
742 std::vector<DetId> dets5x5 =
745 selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
748 for (
const std::pair<DetId, float>&
hit : (*clusIt)->hitsAndFractions()) {
749 selectedCells.push_back(
hit.first);
755 std::sort(selectedCells.begin(), selectedCells.end());
756 std::unique(selectedCells.begin(), selectedCells.end());
769 unsigned nSelectedCells = selectedCells.size();
770 for (
unsigned icell = 0; icell < nSelectedCells; ++icell) {
776 selectedRecHits.
sort();
781 bool passconversionveto =
false;
782 if (hConversions.isValid()) {
808 std::unique_ptr<std::vector<Electron>> ptr(
patElectrons);
864 for (
size_t i = 0,
n = genMatches.size();
i <
n; ++
i) {
885 for (
size_t j = 0, nd =
deposits.size();
j < nd; ++
j) {
950 for (
size_t i = 0,
n = genMatches.size();
i <
n; ++
i) {
967 for (
size_t j = 0, nd =
deposits.size();
j < nd; ++
j) {
993 if (anElectron.
isEE())
1023 iDesc.
setComment(
"PAT electron producer module");
1032 "ecalPFClusterIsoMap",
edm::InputTag(
"electronEcalPFClusterIsolationProducer"),
true) and
1034 "hcalPFClusterIsoMap",
edm::InputTag(
"electronHcalPFClusterIsolationProducer"),
true))
or
1040 "puppiIsolationChargedHadrons",
1041 edm::InputTag(
"egmElectronPUPPIIsolation",
"h+-DR030-BarVeto000-EndVeto001"),
1044 "puppiIsolationNeutralHadrons",
1045 edm::InputTag(
"egmElectronPUPPIIsolation",
"h0-DR030-BarVeto000-EndVeto000"),
1048 "puppiIsolationPhotons",
1049 edm::InputTag(
"egmElectronPUPPIIsolation",
"gamma-DR030-BarVeto000-EndVeto008"),
1052 "puppiNoLeptonsIsolationChargedHadrons",
1053 edm::InputTag(
"egmElectronPUPPINoLeptonsIsolation",
"gamma-DR030-BarVeto000-EndVeto008"),
1056 "puppiNoLeptonsIsolationNeutralHadrons",
1057 edm::InputTag(
"egmElectronPUPPINoLeptonsIsolation",
"gamma-DR030-BarVeto000-EndVeto008"),
1060 "puppiNoLeptonsIsolationPhotons",
1061 edm::InputTag(
"egmElectronPUPPINoLeptonsIsolation",
"gamma-DR030-BarVeto000-EndVeto008"),
1066 iDesc.
add<
bool>(
"embedGsfElectronCore",
true)->setComment(
"embed external gsf electron core");
1067 iDesc.
add<
bool>(
"embedGsfTrack",
true)->setComment(
"embed external gsf track");
1068 iDesc.
add<
bool>(
"embedSuperCluster",
true)->setComment(
"embed external super cluster");
1069 iDesc.
add<
bool>(
"embedPflowSuperCluster",
true)->setComment(
"embed external super cluster");
1070 iDesc.
add<
bool>(
"embedSeedCluster",
true)->setComment(
"embed external seed cluster");
1071 iDesc.
add<
bool>(
"embedBasicClusters",
true)->setComment(
"embed external basic clusters");
1072 iDesc.
add<
bool>(
"embedPreshowerClusters",
true)->setComment(
"embed external preshower clusters");
1073 iDesc.
add<
bool>(
"embedPflowBasicClusters",
true)->setComment(
"embed external pflow basic clusters");
1074 iDesc.
add<
bool>(
"embedPflowPreshowerClusters",
true)->setComment(
"embed external pflow preshower clusters");
1075 iDesc.
add<
bool>(
"embedTrack",
false)->setComment(
"embed external track");
1076 iDesc.
add<
bool>(
"embedRecHits",
true)->setComment(
"embed external RecHits");
1080 ->setComment(
"particle flow input collection");
1083 "take ParticleFlow candidates from pfCandidateMultiMap instead of matching to pfElectrons by Gsf track "
1088 iDesc.
add<
bool>(
"useParticleFlow",
false)->setComment(
"whether to use particle flow or not");
1089 iDesc.
add<
bool>(
"embedPFCandidate",
false)->setComment(
"embed external particle flow object");
1092 iDesc.
add<
bool>(
"addGenMatch",
true)->setComment(
"add MC matching");
1093 iDesc.
add<
bool>(
"embedGenMatch",
false)->setComment(
"embed MC matched MC information");
1094 std::vector<edm::InputTag> emptySourceVector;
1098 ->
setComment(
"input with MC match information");
1101 iDesc.
add<
bool>(
"addElectronID",
true)->setComment(
"add electron ID variables");
1108 ->
setComment(
"input with electron ID variables");
1111 iDesc.
add<
bool>(
"computeMiniIso",
false)->setComment(
"whether or not to compute and store electron mini-isolation");
1113 ->setComment(
"collection to use to compute mini-iso");
1114 iDesc.
add<std::vector<double>>(
"miniIsoParamsE", std::vector<double>())
1115 ->setComment(
"mini-iso parameters to use for endcap electrons");
1116 iDesc.
add<std::vector<double>>(
"miniIsoParamsB", std::vector<double>())
1117 ->setComment(
"mini-iso parameters to use for barrel electrons");
1130 isoDepositsPSet.
addOptional<std::vector<edm::InputTag>>(
"user");
1131 iDesc.
addOptional(
"isoDeposits", isoDepositsPSet);
1144 isolationValuesPSet.
addOptional<std::vector<edm::InputTag>>(
"user");
1145 iDesc.
addOptional(
"isolationValues", isolationValuesPSet);
1158 isolationValuesNoPFIdPSet.
addOptional<std::vector<edm::InputTag>>(
"user");
1159 iDesc.
addOptional(
"isolationValuesNoPFId", isolationValuesNoPFIdPSet);
1164 iDesc.
add(
"efficiencies", efficienciesPSet);
1165 iDesc.
add<
bool>(
"addEfficiencies",
false);
1173 iDesc.
add<
bool>(
"addMVAVariables",
true)->setComment(
"embed extra variables in pat::Electron : sip3d, sigmaIEtaIPhi");
1179 iDesc.
add(
"userIsolation", isolationPSet);
1184 iDesc.
add<
bool>(
"embedHighLevelSelection",
true)->setComment(
"embed high level selection");
1188 ->
setComment(
"input with high level selection");
1190 ->
setComment(
"input with high level selection");
1192 descriptions.
add(
"PATElectronProducer", iDesc);
1201 bool primaryVertexIsValid,
1203 bool beamspotIsValid) {
1211 std::pair<bool, Measurement1D>
result =
1213 double d0_corr =
result.second.value();
1214 double d0_err = primaryVertexIsValid ?
result.second.error() : -1.0;
1226 d0_corr =
result.second.value();
1227 d0_err = beamspotIsValid ?
result.second.error() : -1.0;