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()) {
387 it != itElectron->ambiguousGsfTracksEnd();
389 MatchedToAmbiguousGsfTrack |= (
bool)(
i->gsfTrackRef() == (*it));
393 if (
Matched || MatchedToAmbiguousGsfTrack) {
403 (*PUPPIIsolation_neutral_hadrons)[elePtr],
404 (*PUPPIIsolation_photons)[elePtr]);
406 (*PUPPINoLeptonsIsolation_neutral_hadrons)[elePtr],
407 (*PUPPINoLeptonsIsolation_photons)[elePtr]);
431 if (
track.isNonnull() &&
track.isAvailable()) {
436 ip3d = ip3dpv.second.value();
445 ids[
i].second = (*idhandles[
i])[elecsRef];
448 ids.push_back(std::make_pair(
"pf_evspi", pfRef->mva_e_pi()));
449 ids.push_back(std::make_pair(
"pf_evsmu", pfRef->mva_e_mu()));
455 std::vector<float> vCov = lazyTools.localCovariances(*(itElectron->superCluster()->seed()));
471 std::vector<DetId> selectedCells;
472 bool barrel = itElectron->isEB();
476 clusIt != itElectron->superCluster()->clustersEnd();
479 DetId seed = lazyTools.getMaximum(**clusIt).first;
481 std::vector<DetId> dets5x5 =
484 selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
487 for (
const std::pair<DetId, float>&
hit : (*clusIt)->hitsAndFractions()) {
488 selectedCells.push_back(
hit.first);
495 clusIt != itElectron->parentSuperCluster()->clustersEnd();
498 DetId seed = lazyTools.getMaximum(**clusIt).first;
500 std::vector<DetId> dets5x5 =
503 selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
506 for (
const std::pair<DetId, float>&
hit : (*clusIt)->hitsAndFractions()) {
507 selectedCells.push_back(
hit.first);
513 std::sort(selectedCells.begin(), selectedCells.end());
514 std::unique(selectedCells.begin(), selectedCells.end());
527 unsigned nSelectedCells = selectedCells.size();
528 for (
unsigned icell = 0; icell < nSelectedCells; ++icell) {
534 selectedRecHits.
sort();
539 bool passconversionveto =
false;
540 if (hConversions.isValid()) {
582 bool pfCandsPresent =
false, valMapPresent =
false;
611 }
else if (pfCandsPresent) {
619 if (trkRef == pfTrkRef) {
626 }
else if (valMapPresent) {
651 for (
size_t j = 0, nd =
deposits.size();
j < nd; ++
j) {
658 ids[
i].second = (*idhandles[
i])[elecsRef];
675 if (
track.isNonnull() &&
track.isAvailable()) {
680 ip3d = ip3dpv.second.value();
686 std::vector<float> vCov = lazyTools.localCovariances(*(itElectron->superCluster()->seed()));
705 (*PUPPIIsolation_neutral_hadrons)[elePtr],
706 (*PUPPIIsolation_photons)[elePtr]);
708 (*PUPPINoLeptonsIsolation_neutral_hadrons)[elePtr],
709 (*PUPPINoLeptonsIsolation_photons)[elePtr]);
715 std::vector<DetId> selectedCells;
716 bool barrel = itElectron->isEB();
720 clusIt != itElectron->superCluster()->clustersEnd();
723 DetId seed = lazyTools.getMaximum(**clusIt).first;
725 std::vector<DetId> dets5x5 =
728 selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
731 for (
const std::pair<DetId, float>&
hit : (*clusIt)->hitsAndFractions()) {
732 selectedCells.push_back(
hit.first);
739 clusIt != itElectron->parentSuperCluster()->clustersEnd();
742 DetId seed = lazyTools.getMaximum(**clusIt).first;
744 std::vector<DetId> dets5x5 =
747 selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
750 for (
const std::pair<DetId, float>&
hit : (*clusIt)->hitsAndFractions()) {
751 selectedCells.push_back(
hit.first);
757 std::sort(selectedCells.begin(), selectedCells.end());
758 std::unique(selectedCells.begin(), selectedCells.end());
771 unsigned nSelectedCells = selectedCells.size();
772 for (
unsigned icell = 0; icell < nSelectedCells; ++icell) {
778 selectedRecHits.
sort();
783 bool passconversionveto =
false;
784 if (hConversions.isValid()) {
810 std::unique_ptr<std::vector<Electron>> ptr(
patElectrons);
866 for (
size_t i = 0,
n = genMatches.size();
i <
n; ++
i) {
887 for (
size_t j = 0, nd =
deposits.size();
j < nd; ++
j) {
952 for (
size_t i = 0,
n = genMatches.size();
i <
n; ++
i) {
969 for (
size_t j = 0, nd =
deposits.size();
j < nd; ++
j) {
995 if (anElectron.
isEE())
1025 iDesc.
setComment(
"PAT electron producer module");
1034 "ecalPFClusterIsoMap",
edm::InputTag(
"electronEcalPFClusterIsolationProducer"),
true) and
1036 "hcalPFClusterIsoMap",
edm::InputTag(
"electronHcalPFClusterIsolationProducer"),
true))
or
1042 "puppiIsolationChargedHadrons",
1043 edm::InputTag(
"egmElectronPUPPIIsolation",
"h+-DR030-BarVeto000-EndVeto001"),
1046 "puppiIsolationNeutralHadrons",
1047 edm::InputTag(
"egmElectronPUPPIIsolation",
"h0-DR030-BarVeto000-EndVeto000"),
1050 "puppiIsolationPhotons",
1051 edm::InputTag(
"egmElectronPUPPIIsolation",
"gamma-DR030-BarVeto000-EndVeto008"),
1054 "puppiNoLeptonsIsolationChargedHadrons",
1055 edm::InputTag(
"egmElectronPUPPINoLeptonsIsolation",
"gamma-DR030-BarVeto000-EndVeto008"),
1058 "puppiNoLeptonsIsolationNeutralHadrons",
1059 edm::InputTag(
"egmElectronPUPPINoLeptonsIsolation",
"gamma-DR030-BarVeto000-EndVeto008"),
1062 "puppiNoLeptonsIsolationPhotons",
1063 edm::InputTag(
"egmElectronPUPPINoLeptonsIsolation",
"gamma-DR030-BarVeto000-EndVeto008"),
1068 iDesc.
add<
bool>(
"embedGsfElectronCore",
true)->setComment(
"embed external gsf electron core");
1069 iDesc.
add<
bool>(
"embedGsfTrack",
true)->setComment(
"embed external gsf track");
1070 iDesc.
add<
bool>(
"embedSuperCluster",
true)->setComment(
"embed external super cluster");
1071 iDesc.
add<
bool>(
"embedPflowSuperCluster",
true)->setComment(
"embed external super cluster");
1072 iDesc.
add<
bool>(
"embedSeedCluster",
true)->setComment(
"embed external seed cluster");
1073 iDesc.
add<
bool>(
"embedBasicClusters",
true)->setComment(
"embed external basic clusters");
1074 iDesc.
add<
bool>(
"embedPreshowerClusters",
true)->setComment(
"embed external preshower clusters");
1075 iDesc.
add<
bool>(
"embedPflowBasicClusters",
true)->setComment(
"embed external pflow basic clusters");
1076 iDesc.
add<
bool>(
"embedPflowPreshowerClusters",
true)->setComment(
"embed external pflow preshower clusters");
1077 iDesc.
add<
bool>(
"embedTrack",
false)->setComment(
"embed external track");
1078 iDesc.
add<
bool>(
"embedRecHits",
true)->setComment(
"embed external RecHits");
1082 ->setComment(
"particle flow input collection");
1085 "take ParticleFlow candidates from pfCandidateMultiMap instead of matching to pfElectrons by Gsf track "
1090 iDesc.
add<
bool>(
"useParticleFlow",
false)->setComment(
"whether to use particle flow or not");
1091 iDesc.
add<
bool>(
"embedPFCandidate",
false)->setComment(
"embed external particle flow object");
1094 iDesc.
add<
bool>(
"addGenMatch",
true)->setComment(
"add MC matching");
1095 iDesc.
add<
bool>(
"embedGenMatch",
false)->setComment(
"embed MC matched MC information");
1096 std::vector<edm::InputTag> emptySourceVector;
1100 ->
setComment(
"input with MC match information");
1103 iDesc.
add<
bool>(
"addElectronID",
true)->setComment(
"add electron ID variables");
1110 ->
setComment(
"input with electron ID variables");
1113 iDesc.
add<
bool>(
"computeMiniIso",
false)->setComment(
"whether or not to compute and store electron mini-isolation");
1115 ->setComment(
"collection to use to compute mini-iso");
1116 iDesc.
add<std::vector<double>>(
"miniIsoParamsE", std::vector<double>())
1117 ->setComment(
"mini-iso parameters to use for endcap electrons");
1118 iDesc.
add<std::vector<double>>(
"miniIsoParamsB", std::vector<double>())
1119 ->setComment(
"mini-iso parameters to use for barrel electrons");
1132 isoDepositsPSet.
addOptional<std::vector<edm::InputTag>>(
"user");
1133 iDesc.
addOptional(
"isoDeposits", isoDepositsPSet);
1146 isolationValuesPSet.
addOptional<std::vector<edm::InputTag>>(
"user");
1147 iDesc.
addOptional(
"isolationValues", isolationValuesPSet);
1160 isolationValuesNoPFIdPSet.
addOptional<std::vector<edm::InputTag>>(
"user");
1161 iDesc.
addOptional(
"isolationValuesNoPFId", isolationValuesNoPFIdPSet);
1166 iDesc.
add(
"efficiencies", efficienciesPSet);
1167 iDesc.
add<
bool>(
"addEfficiencies",
false);
1175 iDesc.
add<
bool>(
"addMVAVariables",
true)->setComment(
"embed extra variables in pat::Electron : sip3d, sigmaIEtaIPhi");
1181 iDesc.
add(
"userIsolation", isolationPSet);
1186 iDesc.
add<
bool>(
"embedHighLevelSelection",
true)->setComment(
"embed high level selection");
1190 ->
setComment(
"input with high level selection");
1192 ->
setComment(
"input with high level selection");
1194 descriptions.
add(
"PATElectronProducer", iDesc);
1203 bool primaryVertexIsValid,
1205 bool beamspotIsValid) {
1213 std::pair<bool, Measurement1D>
result =
1215 double d0_corr =
result.second.value();
1216 double d0_err = primaryVertexIsValid ?
result.second.error() : -1.0;
1228 d0_corr =
result.second.value();
1229 d0_err = beamspotIsValid ?
result.second.error() : -1.0;