100 typedef std::vector<edm::Handle<edm::Association<reco::GenParticleCollection>>>
GenAssociations;
102 std::vector<edm::EDGetTokenT<edm::Association<reco::GenParticleCollection>>>
genMatchTokens_;
161 bool primaryVertexIsValid,
163 bool beamspotIsValid);
170 template <
typename T>
172 const char* psetName,
177 typedef std::pair<std::string, edm::InputTag>
NameTag;
217 template <
typename T>
219 const char* psetName,
224 if (iConfig.
exists(psetName)) {
227 if (depconf.
exists(
"tracker"))
229 if (depconf.
exists(
"ecal"))
231 if (depconf.
exists(
"hcal"))
233 if (depconf.
exists(
"pfAllParticles")) {
236 if (depconf.
exists(
"pfChargedHadrons")) {
240 if (depconf.
exists(
"pfChargedAll")) {
243 if (depconf.
exists(
"pfPUChargedHadrons")) {
247 if (depconf.
exists(
"pfNeutralHadrons")) {
251 if (depconf.
exists(
"pfPhotons")) {
254 if (depconf.
exists(
"user")) {
255 std::vector<edm::InputTag> userdeps = depconf.
getParameter<std::vector<edm::InputTag>>(
"user");
256 std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
258 for (; it != ed; ++it, ++
key) {
272 electronToken_(consumes<
edm::
View<
reco::GsfElectron>>(iConfig.getParameter<
edm::
InputTag>(
"electronSource"))),
274 embedGsfElectronCore_(iConfig.getParameter<
bool>(
"embedGsfElectronCore")),
275 embedGsfTrack_(iConfig.getParameter<
bool>(
"embedGsfTrack")),
276 embedSuperCluster_(iConfig.getParameter<
bool>(
"embedSuperCluster")),
277 embedPflowSuperCluster_(iConfig.getParameter<
bool>(
"embedPflowSuperCluster")),
278 embedSeedCluster_(iConfig.getParameter<
bool>(
"embedSeedCluster")),
279 embedBasicClusters_(iConfig.getParameter<
bool>(
"embedBasicClusters")),
280 embedPreshowerClusters_(iConfig.getParameter<
bool>(
"embedPreshowerClusters")),
281 embedPflowBasicClusters_(iConfig.getParameter<
bool>(
"embedPflowBasicClusters")),
282 embedPflowPreshowerClusters_(iConfig.getParameter<
bool>(
"embedPflowPreshowerClusters")),
283 embedTrack_(iConfig.getParameter<
bool>(
"embedTrack")),
284 addGenMatch_(iConfig.getParameter<
bool>(
"addGenMatch")),
285 embedGenMatch_(addGenMatch_ ? iConfig.getParameter<
bool>(
"embedGenMatch") :
false),
286 embedRecHits_(iConfig.getParameter<
bool>(
"embedRecHits")),
288 useParticleFlow_(iConfig.getParameter<
bool>(
"useParticleFlow")),
289 usePfCandidateMultiMap_(iConfig.getParameter<
bool>(
"usePfCandidateMultiMap")),
290 pfElecToken_(!usePfCandidateMultiMap_
294 iConfig.getParameter<
edm::
InputTag>(
"pfCandidateMap"))
296 pfCandidateMultiMapToken_(usePfCandidateMultiMap_
298 iConfig.getParameter<
edm::
InputTag>(
"pfCandidateMultiMap"))
300 embedPFCandidate_(iConfig.getParameter<
bool>(
"embedPFCandidate")),
302 addMVAVariables_(iConfig.getParameter<
bool>(
"addMVAVariables")),
303 reducedBarrelRecHitCollection_(iConfig.getParameter<
edm::
InputTag>(
"reducedBarrelRecHitCollection")),
304 reducedBarrelRecHitCollectionToken_(mayConsume<
EcalRecHitCollection>(reducedBarrelRecHitCollection_)),
305 reducedEndcapRecHitCollection_(iConfig.getParameter<
edm::
InputTag>(
"reducedEndcapRecHitCollection")),
306 reducedEndcapRecHitCollectionToken_(mayConsume<
EcalRecHitCollection>(reducedEndcapRecHitCollection_)),
307 ecalClusterToolsESGetTokens_{consumesCollector()},
309 addPFClusterIso_(iConfig.getParameter<
bool>(
"addPFClusterIso")),
310 addPuppiIsolation_(iConfig.getParameter<
bool>(
"addPuppiIsolation")),
314 embedHighLevelSelection_(iConfig.getParameter<
bool>(
"embedHighLevelSelection")),
315 beamLineToken_(consumes<reco::BeamSpot>(iConfig.getParameter<
edm::InputTag>(
"beamLineSrc"))),
316 pvToken_(mayConsume<std::vector<reco::Vertex>>(iConfig.getParameter<
edm::InputTag>(
"pvSrc"))),
317 addElecID_(iConfig.getParameter<
bool>(
"addElectronID")),
319 isolator_(iConfig.exists(
"userIsolation") ? iConfig.getParameter<
edm::ParameterSet>(
"userIsolation")
323 addEfficiencies_(iConfig.getParameter<
bool>(
"addEfficiencies")),
324 addResolutions_(iConfig.getParameter<
bool>(
"addResolutions")),
325 useUserData_(iConfig.exists(
"userData")),
336 iConfig.getParameter<std::vector<edm::InputTag>>(
"genParticleMatch"),
337 [
this](
edm::InputTag const&
tag) { return consumes<edm::Association<reco::GenParticleCollection>>(tag); });
341 if (addResolutions_) {
344 if (addPuppiIsolation_) {
346 PUPPIIsolation_charged_hadrons_ =
347 consumes<edm::ValueMap<float>>(iConfig.getParameter<
edm::InputTag>(
"puppiIsolationChargedHadrons"));
348 PUPPIIsolation_neutral_hadrons_ =
349 consumes<edm::ValueMap<float>>(iConfig.getParameter<
edm::InputTag>(
"puppiIsolationNeutralHadrons"));
350 PUPPIIsolation_photons_ =
351 consumes<edm::ValueMap<float>>(iConfig.getParameter<
edm::InputTag>(
"puppiIsolationPhotons"));
353 PUPPINoLeptonsIsolation_charged_hadrons_ =
354 consumes<edm::ValueMap<float>>(iConfig.getParameter<
edm::InputTag>(
"puppiNoLeptonsIsolationChargedHadrons"));
355 PUPPINoLeptonsIsolation_neutral_hadrons_ =
356 consumes<edm::ValueMap<float>>(iConfig.getParameter<
edm::InputTag>(
"puppiNoLeptonsIsolationNeutralHadrons"));
357 PUPPINoLeptonsIsolation_photons_ =
358 consumes<edm::ValueMap<float>>(iConfig.getParameter<
edm::InputTag>(
"puppiNoLeptonsIsolationPhotons"));
364 elecIDSrcs_.push_back(NameTag(
"", iConfig.getParameter<
edm::InputTag>(
"electronIDSource")));
369 if (!elecIDSrcs_.empty()) {
371 <<
"PATElectronProducer: you can't specify both 'electronIDSource' and 'electronIDSources'\n";
376 for (std::vector<std::string>::const_iterator it =
names.begin(), ed =
names.end(); it != ed; ++it) {
381 if (elecIDSrcs_.empty()) {
383 <<
"PATElectronProducer: id addElectronID is true, you must specify either:\n"
384 <<
"\tInputTag electronIDSource = <someTag>\n"
386 <<
"\tPSet electronIDSources = { \n"
387 <<
"\t\tInputTag <someName> = <someTag> // as many as you want \n "
392 elecIDSrcs_, [
this](NameTag
const&
tag) {
return mayConsume<edm::ValueMap<float>>(
tag.second); });
414 computeMiniIso_ = iConfig.getParameter<
bool>(
"computeMiniIso");
415 miniIsoParamsE_ = iConfig.getParameter<std::vector<double>>(
"miniIsoParamsE");
416 miniIsoParamsB_ = iConfig.getParameter<std::vector<double>>(
"miniIsoParamsB");
417 if (computeMiniIso_ && (miniIsoParamsE_.size() != 9 || miniIsoParamsB_.size() != 9)) {
418 throw cms::Exception(
"ParameterError") <<
"miniIsoParams must have exactly 9 elements.\n";
421 pcToken_ = consumes<pat::PackedCandidateCollection>(iConfig.getParameter<
edm::InputTag>(
"pfCandsForMiniIso"));
424 readIsolationLabels(iConfig,
"isoDeposits", isoDepositLabels_, isoDepositTokens_);
426 readIsolationLabels(iConfig,
"isolationValues", isolationValueLabels_, isolationValueTokens_);
428 readIsolationLabels(iConfig,
"isolationValuesNoPFId", isolationValueLabelsNoPFId_, isolationValueNoPFIdTokens_);
430 if (addEfficiencies_) {
441 if (useParticleFlow_ && usePfCandidateMultiMap_)
442 throw cms::Exception(
"Configuration",
"usePfCandidateMultiMap not supported when useParticleFlow is set to true");
445 produces<std::vector<Electron>>();
452 if (
iEvent.isRealData()) {
516 std::vector<edm::Handle<edm::ValueMap<float>>> idhandles;
517 std::vector<pat::Electron::IdPair> ids;
532 bool beamSpotIsValid =
false;
533 bool primaryVertexIsValid =
false;
547 if (pvHandle.
isValid() && !pvHandle->empty()) {
549 primaryVertexIsValid =
true;
552 <<
"No primary vertex available from EventSetup, not adding high level selection \n";
574 std::vector<Electron>*
patElectrons =
new std::vector<Electron>();
589 bool MatchedToAmbiguousGsfTrack =
false;
594 if (
Matched || MatchedToAmbiguousGsfTrack)
599 if (itElectron->gsfTrack() ==
i->gsfTrackRef()) {
602 for (
auto const& it : itElectron->ambiguousGsfTracks()) {
603 MatchedToAmbiguousGsfTrack |= (
bool)(
i->gsfTrackRef() == it);
607 if (
Matched || MatchedToAmbiguousGsfTrack) {
617 (*PUPPIIsolation_neutral_hadrons)[elePtr],
618 (*PUPPIIsolation_photons)[elePtr]);
620 (*PUPPINoLeptonsIsolation_neutral_hadrons)[elePtr],
621 (*PUPPINoLeptonsIsolation_photons)[elePtr]);
645 if (
track.isNonnull() &&
track.isAvailable()) {
650 ip3d = ip3dpv.second.value();
659 ids[
i].second = (*idhandles[
i])[elecsRef];
662 ids.push_back(std::make_pair(
"pf_evspi", pfRef->mva_e_pi()));
663 ids.push_back(std::make_pair(
"pf_evsmu", pfRef->mva_e_mu()));
669 const auto& vCov = lazyTools.localCovariances(*(itElectron->superCluster()->seed()));
685 std::vector<DetId> selectedCells;
686 bool barrel = itElectron->isEB();
690 clusIt != itElectron->superCluster()->clustersEnd();
693 DetId seed = lazyTools.getMaximum(**clusIt).first;
695 std::vector<DetId> dets5x5 =
698 selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
701 for (
const std::pair<DetId, float>&
hit : (*clusIt)->hitsAndFractions()) {
702 selectedCells.push_back(
hit.first);
709 clusIt != itElectron->parentSuperCluster()->clustersEnd();
712 DetId seed = lazyTools.getMaximum(**clusIt).first;
714 std::vector<DetId> dets5x5 =
717 selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
720 for (
const std::pair<DetId, float>&
hit : (*clusIt)->hitsAndFractions()) {
721 selectedCells.push_back(
hit.first);
727 std::sort(selectedCells.begin(), selectedCells.end());
728 std::unique(selectedCells.begin(), selectedCells.end());
741 unsigned nSelectedCells = selectedCells.size();
742 for (
unsigned icell = 0; icell < nSelectedCells; ++icell) {
748 selectedRecHits.
sort();
753 bool passconversionveto =
false;
754 if (hConversions.isValid()) {
796 bool pfCandsPresent =
false, valMapPresent =
false;
825 }
else if (pfCandsPresent) {
833 if (trkRef == pfTrkRef) {
840 }
else if (valMapPresent) {
865 for (
size_t j = 0, nd =
deposits.size();
j < nd; ++
j) {
872 ids[
i].second = (*idhandles[
i])[elecsRef];
889 if (
track.isNonnull() &&
track.isAvailable()) {
894 ip3d = ip3dpv.second.value();
900 const auto& vCov = lazyTools.localCovariances(*(itElectron->superCluster()->seed()));
919 (*PUPPIIsolation_neutral_hadrons)[elePtr],
920 (*PUPPIIsolation_photons)[elePtr]);
922 (*PUPPINoLeptonsIsolation_neutral_hadrons)[elePtr],
923 (*PUPPINoLeptonsIsolation_photons)[elePtr]);
929 std::vector<DetId> selectedCells;
930 bool barrel = itElectron->isEB();
934 clusIt != itElectron->superCluster()->clustersEnd();
937 DetId seed = lazyTools.getMaximum(**clusIt).first;
939 std::vector<DetId> dets5x5 =
942 selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
945 for (
const std::pair<DetId, float>&
hit : (*clusIt)->hitsAndFractions()) {
946 selectedCells.push_back(
hit.first);
953 clusIt != itElectron->parentSuperCluster()->clustersEnd();
956 DetId seed = lazyTools.getMaximum(**clusIt).first;
958 std::vector<DetId> dets5x5 =
961 selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
964 for (
const std::pair<DetId, float>&
hit : (*clusIt)->hitsAndFractions()) {
965 selectedCells.push_back(
hit.first);
971 std::sort(selectedCells.begin(), selectedCells.end());
972 std::unique(selectedCells.begin(), selectedCells.end());
985 unsigned nSelectedCells = selectedCells.size();
986 for (
unsigned icell = 0; icell < nSelectedCells; ++icell) {
992 selectedRecHits.
sort();
997 bool passconversionveto =
false;
998 if (hConversions.isValid()) {
1000 passconversionveto =
1004 passconversionveto =
1024 std::unique_ptr<std::vector<Electron>> ptr(
patElectrons);
1080 for (
size_t i = 0,
n = genMatches.size();
i <
n; ++
i) {
1101 for (
size_t j = 0, nd =
deposits.size();
j < nd; ++
j) {
1166 for (
size_t i = 0,
n = genMatches.size();
i <
n; ++
i) {
1183 for (
size_t j = 0, nd =
deposits.size();
j < nd; ++
j) {
1209 if (anElectron.
isEE())
1239 iDesc.
setComment(
"PAT electron producer module");
1248 "ecalPFClusterIsoMap",
edm::InputTag(
"electronEcalPFClusterIsolationProducer"),
true) and
1250 "hcalPFClusterIsoMap",
edm::InputTag(
"electronHcalPFClusterIsolationProducer"),
true))
or
1256 "puppiIsolationChargedHadrons",
1257 edm::InputTag(
"egmElectronPUPPIIsolation",
"h+-DR030-BarVeto000-EndVeto001"),
1260 "puppiIsolationNeutralHadrons",
1261 edm::InputTag(
"egmElectronPUPPIIsolation",
"h0-DR030-BarVeto000-EndVeto000"),
1264 "puppiIsolationPhotons",
1265 edm::InputTag(
"egmElectronPUPPIIsolation",
"gamma-DR030-BarVeto000-EndVeto008"),
1268 "puppiNoLeptonsIsolationChargedHadrons",
1269 edm::InputTag(
"egmElectronPUPPINoLeptonsIsolation",
"gamma-DR030-BarVeto000-EndVeto008"),
1272 "puppiNoLeptonsIsolationNeutralHadrons",
1273 edm::InputTag(
"egmElectronPUPPINoLeptonsIsolation",
"gamma-DR030-BarVeto000-EndVeto008"),
1276 "puppiNoLeptonsIsolationPhotons",
1277 edm::InputTag(
"egmElectronPUPPINoLeptonsIsolation",
"gamma-DR030-BarVeto000-EndVeto008"),
1282 iDesc.
add<
bool>(
"embedGsfElectronCore",
true)->setComment(
"embed external gsf electron core");
1283 iDesc.
add<
bool>(
"embedGsfTrack",
true)->setComment(
"embed external gsf track");
1284 iDesc.
add<
bool>(
"embedSuperCluster",
true)->setComment(
"embed external super cluster");
1285 iDesc.
add<
bool>(
"embedPflowSuperCluster",
true)->setComment(
"embed external super cluster");
1286 iDesc.
add<
bool>(
"embedSeedCluster",
true)->setComment(
"embed external seed cluster");
1287 iDesc.
add<
bool>(
"embedBasicClusters",
true)->setComment(
"embed external basic clusters");
1288 iDesc.
add<
bool>(
"embedPreshowerClusters",
true)->setComment(
"embed external preshower clusters");
1289 iDesc.
add<
bool>(
"embedPflowBasicClusters",
true)->setComment(
"embed external pflow basic clusters");
1290 iDesc.
add<
bool>(
"embedPflowPreshowerClusters",
true)->setComment(
"embed external pflow preshower clusters");
1291 iDesc.
add<
bool>(
"embedTrack",
false)->setComment(
"embed external track");
1292 iDesc.
add<
bool>(
"embedRecHits",
true)->setComment(
"embed external RecHits");
1296 ->setComment(
"particle flow input collection");
1299 "take ParticleFlow candidates from pfCandidateMultiMap instead of matching to pfElectrons by Gsf track "
1304 iDesc.
add<
bool>(
"useParticleFlow",
false)->setComment(
"whether to use particle flow or not");
1305 iDesc.
add<
bool>(
"embedPFCandidate",
false)->setComment(
"embed external particle flow object");
1308 iDesc.
add<
bool>(
"addGenMatch",
true)->setComment(
"add MC matching");
1309 iDesc.
add<
bool>(
"embedGenMatch",
false)->setComment(
"embed MC matched MC information");
1310 std::vector<edm::InputTag> emptySourceVector;
1314 ->
setComment(
"input with MC match information");
1317 iDesc.
add<
bool>(
"addElectronID",
true)->setComment(
"add electron ID variables");
1324 ->
setComment(
"input with electron ID variables");
1327 iDesc.
add<
bool>(
"computeMiniIso",
false)->setComment(
"whether or not to compute and store electron mini-isolation");
1329 ->setComment(
"collection to use to compute mini-iso");
1330 iDesc.
add<std::vector<double>>(
"miniIsoParamsE", std::vector<double>())
1331 ->setComment(
"mini-iso parameters to use for endcap electrons");
1332 iDesc.
add<std::vector<double>>(
"miniIsoParamsB", std::vector<double>())
1333 ->setComment(
"mini-iso parameters to use for barrel electrons");
1346 isoDepositsPSet.
addOptional<std::vector<edm::InputTag>>(
"user");
1347 iDesc.
addOptional(
"isoDeposits", isoDepositsPSet);
1360 isolationValuesPSet.
addOptional<std::vector<edm::InputTag>>(
"user");
1361 iDesc.
addOptional(
"isolationValues", isolationValuesPSet);
1374 isolationValuesNoPFIdPSet.
addOptional<std::vector<edm::InputTag>>(
"user");
1375 iDesc.
addOptional(
"isolationValuesNoPFId", isolationValuesNoPFIdPSet);
1380 iDesc.
add(
"efficiencies", efficienciesPSet);
1381 iDesc.
add<
bool>(
"addEfficiencies",
false);
1389 iDesc.
add<
bool>(
"addMVAVariables",
true)->setComment(
"embed extra variables in pat::Electron : sip3d, sigmaIEtaIPhi");
1395 iDesc.
add(
"userIsolation", isolationPSet);
1400 iDesc.
add<
bool>(
"embedHighLevelSelection",
true)->setComment(
"embed high level selection");
1404 ->
setComment(
"input with high level selection");
1406 ->
setComment(
"input with high level selection");
1408 descriptions.
add(
"PATElectronProducer", iDesc);
1417 bool primaryVertexIsValid,
1419 bool beamspotIsValid) {
1427 std::pair<bool, Measurement1D>
result =
1429 double d0_corr =
result.second.value();
1430 double d0_err = primaryVertexIsValid ?
result.second.error() : -1.0;
1442 d0_corr =
result.second.value();
1443 d0_err = beamspotIsValid ?
result.second.error() : -1.0;