From 392fed939eb01a4387b276c85f3f55b7dca58ef9 Mon Sep 17 00:00:00 2001 From: bainbrid Date: Wed, 25 Nov 2020 17:56:57 +0100 Subject: [PATCH 01/21] support for GBRForest stored in ROOT files --- CommonTools/MVAUtils/BuildFile.xml | 14 ++++---- CommonTools/MVAUtils/bin/BuildFile.xml | 4 +++ .../MVAUtils/bin/convertXMLToGBRForestROOT.cc | 34 +++++++++++++++++++ CommonTools/MVAUtils/src/GBRForestTools.cc | 13 +++++++ 4 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 CommonTools/MVAUtils/bin/BuildFile.xml create mode 100644 CommonTools/MVAUtils/bin/convertXMLToGBRForestROOT.cc diff --git a/CommonTools/MVAUtils/BuildFile.xml b/CommonTools/MVAUtils/BuildFile.xml index 26b7b5c239e4e..f0798188522fc 100644 --- a/CommonTools/MVAUtils/BuildFile.xml +++ b/CommonTools/MVAUtils/BuildFile.xml @@ -1,10 +1,10 @@ - - - - - - - + + + + + + + diff --git a/CommonTools/MVAUtils/bin/BuildFile.xml b/CommonTools/MVAUtils/bin/BuildFile.xml new file mode 100644 index 0000000000000..147f2d969912d --- /dev/null +++ b/CommonTools/MVAUtils/bin/BuildFile.xml @@ -0,0 +1,4 @@ + + + + diff --git a/CommonTools/MVAUtils/bin/convertXMLToGBRForestROOT.cc b/CommonTools/MVAUtils/bin/convertXMLToGBRForestROOT.cc new file mode 100644 index 0000000000000..3c7c9f5805fd7 --- /dev/null +++ b/CommonTools/MVAUtils/bin/convertXMLToGBRForestROOT.cc @@ -0,0 +1,34 @@ +#include "CommonTools/MVAUtils/interface/GBRForestTools.h" + +#include "TFile.h" + +#include +#include + +int main(int argc, char **argv) { + if (argc != 3) { + std::cout << "Please pass a (gzipped) BDT weight file and a name for the output ROOT file." << std::endl; + return 1; + } + + char *inputFileName = argv[1]; + char *outputFileName = argv[2]; + + if (!std::filesystem::exists(inputFileName)) { + std::cout << "Input file " << inputFileName << " does not exists." << std::endl; + return 1; + } + + if (std::filesystem::exists(outputFileName)) { + std::cout << "Output file " << outputFileName << " already exists." << std::endl; + return 1; + } + + auto gbrForest = createGBRForest(inputFileName); + std::cout << "Read GBRForest " << inputFileName << " successfully." << std::endl; + + TFile{outputFileName, "RECREATE"}.WriteObject(gbrForest.get(), "gbrForest"); + std::cout << "GBRForest written to " << outputFileName << " successfully." << std::endl; + + return 0; +} diff --git a/CommonTools/MVAUtils/src/GBRForestTools.cc b/CommonTools/MVAUtils/src/GBRForestTools.cc index 6f40fd3059cd5..18b366383e123 100644 --- a/CommonTools/MVAUtils/src/GBRForestTools.cc +++ b/CommonTools/MVAUtils/src/GBRForestTools.cc @@ -3,11 +3,14 @@ #include "FWCore/ParameterSet/interface/FileInPath.h" #include "FWCore/Utilities/interface/Exception.h" +#include "TFile.h" + #include #include #include #include #include +#include namespace { @@ -117,6 +120,16 @@ namespace { } std::unique_ptr init(const std::string& weightsFileFullPath, std::vector& varNames) { + // + // Load weights file, for ROOT file + // + if (reco::details::hasEnding(weightsFileFullPath, ".root")) { + TFile gbrForestFile(weightsFileFullPath.c_str()); + // Use the copy-constructor of GBRForest to copy the GBRForest. + // In this way, the ROOT file can be closed. + return std::make_unique(*(GBRForest*)gbrForestFile.Get("gbrForest")); + } + // // Load weights file, for gzipped or raw xml file // From 3eab02feeee268aedc16f112157244ae00f15de1 Mon Sep 17 00:00:00 2001 From: bainbrid Date: Wed, 25 Nov 2020 18:21:28 +0100 Subject: [PATCH 02/21] handle both old (e.g. 2019Aug07) and new (2020Sept15) BDT models, rekey ElectronSeed BDT ValueMaps, code review --- .../interface/LowPtGsfElectronFeatures.h | 52 ++ .../plugins/BuildFile.xml | 1 + .../plugins/LowPtGsfElectronIDProducer.cc | 180 +++-- .../LowPtGsfElectronSeedValueMapsProducer.cc | 177 +++-- .../lowPtGsfElectronSeedValueMaps_cff.py | 14 +- .../python/lowPtGsfElectronSequence_cff.py | 4 +- .../src/LowPtGsfElectronFeatures.cc | 678 ++++++++++++++++++ 7 files changed, 1007 insertions(+), 99 deletions(-) create mode 100644 RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h create mode 100644 RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc diff --git a/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h b/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h new file mode 100644 index 0000000000000..89e81b2b60d17 --- /dev/null +++ b/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h @@ -0,0 +1,52 @@ +#ifndef RecoEgamma_EgammaElectronProducers_LowPtGsfElectronFeatures_h +#define RecoEgamma_EgammaElectronProducers_LowPtGsfElectronFeatures_h + +#include "DataFormats/BeamSpot/interface/BeamSpot.h" +#include "DataFormats/Common/interface/Ptr.h" +#include "DataFormats/Common/interface/Ref.h" +#include "DataFormats/Common/interface/RefToPtr.h" +#include "DataFormats/Common/interface/View.h" +#include "DataFormats/EgammaCandidates/interface/GsfElectron.h" +#include "DataFormats/ParticleFlowReco/interface/PreId.h" +#include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h" +#include + +namespace lowptgsfeleseed { + + std::vector features(const reco::PreId& ecal, + const reco::PreId& hcal, + double rho, + const reco::BeamSpot& spot, + noZS::EcalClusterLazyTools& ecalTools); + +} + +namespace lowptgsfeleid { + + // feature list for new model (2019Sept15) + std::vector features_V1(reco::GsfElectron const& ele, float rho, float unbiased, float field_z); + + // feature list for original models (2019Aug07 and earlier) + std::vector features_V0(reco::GsfElectron const& ele, float rho, float unbiased); + + // Find most energetic clusters + void findEnergeticClusters(reco::SuperCluster const&, int&, float&, float&, int&, int&); + + // Track-cluster matching for most energetic clusters + void trackClusterMatching(reco::SuperCluster const&, + reco::GsfTrack const&, + bool const&, + GlobalPoint const&, + float&, + float&, + float&, + float&, + float&, + float&, + float&, + float&, + float&); + +} // namespace lowptgsfeleid + +#endif // RecoEgamma_EgammaElectronProducers_LowPtGsfElectronFeatures_h diff --git a/RecoEgamma/EgammaElectronProducers/plugins/BuildFile.xml b/RecoEgamma/EgammaElectronProducers/plugins/BuildFile.xml index f73674f445d0e..66ffcb6442d43 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/BuildFile.xml +++ b/RecoEgamma/EgammaElectronProducers/plugins/BuildFile.xml @@ -11,6 +11,7 @@ + diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc index f4c65dde72c11..4bd7ec2656528 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc @@ -4,52 +4,131 @@ #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" #include "FWCore/Utilities/interface/InputTag.h" -#include "RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/global/EDProducer.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "CommonTools/MVAUtils/interface/GBRForestTools.h" +#include "DataFormats/EgammaCandidates/interface/GsfElectron.h" +#include "DataFormats/PatCandidates/interface/Electron.h" +#include "DataFormats/EgammaReco/interface/SuperCluster.h" +#include "DataFormats/GsfTrackReco/interface/GsfTrack.h" +#include "DataFormats/TrackReco/interface/Track.h" +#include "DataFormats/Math/interface/LorentzVector.h" +#include "FWCore/Framework/interface/Event.h" +#include "MagneticField/Engine/interface/MagneticField.h" +#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" +#include "RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h" +#include +#include //////////////////////////////////////////////////////////////////////////////// // -LowPtGsfElectronIDProducer::LowPtGsfElectronIDProducer( const edm::ParameterSet& conf, - const lowptgsfeleid::HeavyObjectCache* ) : - gsfElectrons_(consumes(conf.getParameter("electrons"))), - rho_(consumes(conf.getParameter("rho"))), - names_(conf.getParameter< std::vector >("ModelNames")), - passThrough_(conf.getParameter("PassThrough")), - minPtThreshold_(conf.getParameter("MinPtThreshold")), - maxPtThreshold_(conf.getParameter("MaxPtThreshold")) -{ - for ( const auto& name : names_ ) { - produces< edm::ValueMap >(name); - } -} +class LowPtGsfElectronIDProducer final : public edm::global::EDProducer<> { +public: + explicit LowPtGsfElectronIDProducer(const edm::ParameterSet&); + + void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; + + static void fillDescriptions(edm::ConfigurationDescriptions&); + +private: + double eval( + const std::string& name, const edm::Ptr&, double rho, float unbiased, float field_z) const; + + const edm::EDGetTokenT > electrons_; + const edm::EDGetTokenT rho_; + const edm::EDGetTokenT > unbiased_; + const std::vector names_; + const bool passThrough_; + const double minPtThreshold_; + const double maxPtThreshold_; + std::vector > models_; + const std::vector thresholds_; + const std::string version_; +}; //////////////////////////////////////////////////////////////////////////////// // -LowPtGsfElectronIDProducer::~LowPtGsfElectronIDProducer() {} +LowPtGsfElectronIDProducer::LowPtGsfElectronIDProducer(const edm::ParameterSet& conf) + : electrons_(consumes >(conf.getParameter("electrons"))), + rho_(consumes(conf.getParameter("rho"))), + unbiased_(consumes >(conf.getParameter("unbiased"))), + names_(conf.getParameter >("ModelNames")), + passThrough_(conf.getParameter("PassThrough")), + minPtThreshold_(conf.getParameter("MinPtThreshold")), + maxPtThreshold_(conf.getParameter("MaxPtThreshold")), + thresholds_(conf.getParameter >("ModelThresholds")), + version_(conf.getParameter("Version")) { + for (auto& weights : conf.getParameter >("ModelWeights")) { + models_.push_back(createGBRForest(edm::FileInPath(weights))); + } + if (names_.size() != models_.size()) { + throw cms::Exception("Incorrect configuration") + << "'ModelNames' size (" << names_.size() << ") != 'ModelWeights' size (" << models_.size() << ").\n"; + } + if (models_.size() != thresholds_.size()) { + throw cms::Exception("Incorrect configuration") + << "'ModelWeights' size (" << models_.size() << ") != 'ModelThresholds' size (" << thresholds_.size() << ").\n"; + } + if (version_ != "V0" && version_ != "V1") { + throw cms::Exception("Incorrect configuration") << "Unknown Version: " << version_ << "\n"; + } + for (const auto& name : names_) { + produces >(name); + } +} //////////////////////////////////////////////////////////////////////////////// // -void LowPtGsfElectronIDProducer::produce( edm::Event& event, const edm::EventSetup& setup ) { +void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const edm::EventSetup& setup) const { + // Get z-component of B field + edm::ESHandle field; + setup.get().get(field); + math::XYZVector zfield(field->inTesla(GlobalPoint(0, 0, 0))); // Pileup edm::Handle rho; - event.getByToken(rho_,rho); - if ( !rho.isValid() ) { edm::LogError("Problem with rho handle"); } + event.getByToken(rho_, rho); + if (!rho.isValid()) { + std::ostringstream os; + os << "Problem accessing rho collection for low-pT electrons" << std::endl; + throw cms::Exception("InvalidHandle", os.str()); + } // Retrieve GsfElectrons from Event - edm::Handle gsfElectrons; - event.getByToken(gsfElectrons_,gsfElectrons); - if ( !gsfElectrons.isValid() ) { edm::LogError("Problem with gsfElectrons handle"); } + edm::Handle > electrons; + event.getByToken(electrons_, electrons); + if (!electrons.isValid()) { + std::ostringstream os; + os << "Problem accessing low-pT electrons collection" << std::endl; + throw cms::Exception("InvalidHandle", os.str()); + } + + // ElectronSeed unbiased BDT + edm::Handle > unbiasedH; + event.getByToken(unbiased_, unbiasedH); // Iterate through Electrons, evaluate BDT, and store result - std::vector< std::vector > output; - for ( unsigned int iname = 0; iname < names_.size(); ++iname ) { - output.push_back( std::vector(gsfElectrons->size(),-999.) ); + std::vector > output; + for (unsigned int iname = 0; iname < names_.size(); ++iname) { + output.emplace_back(electrons->size(), -999.); } - for ( unsigned int iele = 0; iele < gsfElectrons->size(); iele++ ) { - reco::GsfElectronRef ele(gsfElectrons,iele); + for (unsigned int iele = 0; iele < electrons->size(); iele++) { + edm::Ptr ele(electrons, iele); + + if (ele->core().isNull()) { + continue; + } + const auto& gsf = ele->core()->gsfTrack(); // reco::GsfTrackRef + if (gsf.isNull()) { + continue; + } + float unbiased = (*unbiasedH)[gsf]; + //if ( !passThrough_ && ( ele->pt() < minPtThreshold_ ) ) { continue; } - for ( unsigned int iname = 0; iname < names_.size(); ++iname ) { - output[iname][iele] = globalCache()->eval( names_[iname], ele, *rho ); + for (unsigned int iname = 0; iname < names_.size(); ++iname) { + output[iname][iele] = eval(names_[iname], ele, *rho, unbiased, zfield.z()); } } @@ -57,10 +136,28 @@ void LowPtGsfElectronIDProducer::produce( edm::Event& event, const edm::EventSet for ( unsigned int iname = 0; iname < names_.size(); ++iname ) { auto ptr = std::make_unique< edm::ValueMap >( edm::ValueMap() ); edm::ValueMap::Filler filler(*ptr); - filler.insert(gsfElectrons, output[iname].begin(), output[iname].end()); + filler.insert(electrons, output[iname].begin(), output[iname].end()); filler.fill(); - reco::GsfElectronRef ele(gsfElectrons,0); - event.put(std::move(ptr),names_[iname]); + event.put(std::move(ptr), names_[iname]); + } +} + +////////////////////////////////////////////////////////////////////////////////////////// +// +double LowPtGsfElectronIDProducer::eval( + const std::string& name, const edm::Ptr& ele, double rho, float unbiased, float field_z) const { + auto iter = std::find(names_.begin(), names_.end(), name); + if (iter != names_.end()) { + int index = std::distance(names_.begin(), iter); + std::vector inputs; + if (version_ == "V0") { + inputs = lowptgsfeleid::features_V0(*ele, rho, unbiased); + } else if (version_ == "V1") { + inputs = lowptgsfeleid::features_V1(*ele, rho, unbiased, field_z); + } + return models_.at(index)->GetResponse(inputs.data()); + } else { + throw cms::Exception("Unknown model name") << "'Name given: '" << name << "'. Check against configuration file.\n"; } } @@ -70,15 +167,18 @@ void LowPtGsfElectronIDProducer::produce( edm::Event& event, const edm::EventSet void LowPtGsfElectronIDProducer::fillDescriptions( edm::ConfigurationDescriptions& descriptions ) { edm::ParameterSetDescription desc; - desc.add("electrons",edm::InputTag("lowPtGsfElectrons")); - desc.add("rho",edm::InputTag("fixedGridRhoFastjetAllTmp")); - desc.add< std::vector >("ModelNames",std::vector()); - desc.add< std::vector >("ModelWeights",std::vector()); - desc.add< std::vector >("ModelThresholds",std::vector()); - desc.add("PassThrough",false); - desc.add("MinPtThreshold",0.5); - desc.add("MaxPtThreshold",15.); - descriptions.add("defaultLowPtGsfElectronID",desc); + desc.add("electrons", edm::InputTag("lowPtGsfElectrons")); + desc.add("unbiased", edm::InputTag("lowPtGsfElectronSeedValueMaps:unbiased")); + desc.add("rho", edm::InputTag("fixedGridRhoFastjetAllTmp")); + desc.add >("ModelNames", {""}); + desc.add >( + "ModelWeights", {"RecoEgamma/ElectronIdentification/data/LowPtElectrons/LowPtElectrons_ID_2020Sept15.root"}); + desc.add >("ModelThresholds", {-99.}); + desc.add("PassThrough", false); + desc.add("MinPtThreshold", 0.5); + desc.add("MaxPtThreshold", 15.); + desc.add("Version", "V1"); + descriptions.add("lowPtGsfElectronID", desc); } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedValueMapsProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedValueMapsProducer.cc index a38504e3e7e97..ef7cdc2443037 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedValueMapsProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedValueMapsProducer.cc @@ -1,4 +1,5 @@ #include "DataFormats/Common/interface/Handle.h" +#include "DataFormats/EgammaCandidates/interface/GsfElectron.h" #include "DataFormats/EgammaReco/interface/ElectronSeed.h" #include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h" #include "DataFormats/GsfTrackReco/interface/GsfTrack.h" @@ -8,65 +9,132 @@ #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" #include "FWCore/Utilities/interface/InputTag.h" -#include "RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedValueMapsProducer.h" +#include "DataFormats/Common/interface/ValueMap.h" +#include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h" +#include "DataFormats/ParticleFlowReco/interface/PreIdFwd.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "FWCore/Utilities/interface/transform.h" + +#include +#include + +class LowPtGsfElectronSeedValueMapsProducer : public edm::stream::EDProducer<> { +public: + explicit LowPtGsfElectronSeedValueMapsProducer(const edm::ParameterSet&); + + void produce(edm::Event&, const edm::EventSetup&) override; + + static void fillDescriptions(edm::ConfigurationDescriptions&); + +private: + edm::EDGetTokenT gsfTracks_; + edm::EDGetTokenT > preIdsValueMap_; + std::vector names_; + const bool rekey_; + edm::EDGetTokenT gsfElectrons_; + std::vector > > floatValueMaps_; +}; //////////////////////////////////////////////////////////////////////////////// // -LowPtGsfElectronSeedValueMapsProducer::LowPtGsfElectronSeedValueMapsProducer( const edm::ParameterSet& conf ) : - gsfTracks_(consumes(conf.getParameter("gsfTracks"))), - preIdsValueMap_(consumes< edm::ValueMap >(conf.getParameter("preIdsValueMap"))), - names_(conf.getParameter< std::vector >("ModelNames")) -{ - for ( const auto& name : names_ ) { produces< edm::ValueMap >(name); } +LowPtGsfElectronSeedValueMapsProducer::LowPtGsfElectronSeedValueMapsProducer(const edm::ParameterSet& conf) + : gsfTracks_(), + preIdsValueMap_(), + names_(), + rekey_(conf.getParameter("rekey")), + gsfElectrons_(), + floatValueMaps_() { + if (rekey_) { + gsfElectrons_ = consumes(conf.getParameter("gsfElectrons")); + std::vector tags = conf.getParameter >("floatValueMaps"); + for (const auto& tag : tags) { + floatValueMaps_ = edm::vector_transform( + tags, [this](edm::InputTag const& tag) { return consumes >(tag); }); + names_.push_back(tag.instance()); + produces >(tag.instance()); + } + } else { + gsfTracks_ = consumes(conf.getParameter("gsfTracks")); + preIdsValueMap_ = consumes >(conf.getParameter("preIdsValueMap")); + names_ = conf.getParameter >("ModelNames"); + for (const auto& name : names_) { + produces >(name); + } + } } //////////////////////////////////////////////////////////////////////////////// // -LowPtGsfElectronSeedValueMapsProducer::~LowPtGsfElectronSeedValueMapsProducer() {} +void LowPtGsfElectronSeedValueMapsProducer::produce(edm::Event& event, const edm::EventSetup&) { + if (rekey_ == false) { + // TRANSFORM VALUEMAP OF PREID OBJECTS KEYED BY KF TRACK ... + // .. INTO VALUEMAP OF FLOATS (BDT SCORE) KEYED BY GSF TRACK ... -//////////////////////////////////////////////////////////////////////////////// -// -void LowPtGsfElectronSeedValueMapsProducer::produce( edm::Event& event, const edm::EventSetup& setup ) { - - // Retrieve GsfTracks from Event - edm::Handle gsfTracks; - event.getByToken(gsfTracks_,gsfTracks); - if ( !gsfTracks.isValid() ) { edm::LogError("Problem with gsfTracks handle"); } - - // Retrieve PreIds from Event - edm::Handle< edm::ValueMap > preIdsValueMap; - event.getByToken(preIdsValueMap_,preIdsValueMap); - if ( !preIdsValueMap.isValid() ) { edm::LogError("Problem with preIdsValueMap handle"); } - - // Iterate through GsfTracks, extract BDT output, and store result in ValueMap for each model - std::vector< std::vector > output; - for ( unsigned int iname = 0; iname < names_.size(); ++iname ) { - output.push_back( std::vector(gsfTracks->size(),-999.) ); - } - for ( unsigned int igsf = 0; igsf < gsfTracks->size(); igsf++ ) { - reco::GsfTrackRef gsf(gsfTracks,igsf); - if ( gsf.isNonnull() && - gsf->extra().isNonnull() && - gsf->extra()->seedRef().isNonnull() ) { - reco::ElectronSeedRef seed = gsf->extra()->seedRef().castTo(); - if ( seed.isNonnull() && seed->ctfTrack().isNonnull() ) { - const reco::PreIdRef preid = (*preIdsValueMap)[seed->ctfTrack()]; - if ( preid.isNonnull() ) { - for ( unsigned int iname = 0; iname < names_.size(); ++iname ) { - output[iname][igsf] = preid->mva(iname); - } - } + // Retrieve GsfTracks from Event + auto gsfTracks = event.getHandle(gsfTracks_); + + // Retrieve PreIds from Event + auto preIdsValueMap = event.getHandle(preIdsValueMap_); + + // Iterate through GsfTracks, extract BDT output, and store result in ValueMap for each model + std::vector > output; + for (unsigned int iname = 0; iname < names_.size(); ++iname) { + output.push_back(std::vector(gsfTracks->size(), -999.)); + } + auto const& gsfTracksV = *gsfTracks; + for (unsigned int igsf = 0; igsf < gsfTracksV.size(); igsf++) { + const reco::GsfTrack& gsf = gsfTracksV[igsf]; + if (gsf.extra().isNonnull() && gsf.extra()->seedRef().isNonnull()) { + reco::ElectronSeedRef seed = gsf.extra()->seedRef().castTo(); + if (seed.isNonnull() && seed->ctfTrack().isNonnull()) { + const reco::PreIdRef preid = (*preIdsValueMap)[seed->ctfTrack()]; + if (preid.isNonnull()) { + for (unsigned int iname = 0; iname < names_.size(); ++iname) { + output[iname][igsf] = preid->mva(iname); + } + } + } } } - } - - // Create and put ValueMap in Event - for ( unsigned int iname = 0; iname < names_.size(); ++iname ) { - auto ptr = std::make_unique< edm::ValueMap >( edm::ValueMap() ); - edm::ValueMap::Filler filler(*ptr); - filler.insert(gsfTracks, output[iname].begin(), output[iname].end()); - filler.fill(); - event.put(std::move(ptr),names_[iname]); + + // Create and put ValueMap in Event + for (unsigned int iname = 0; iname < names_.size(); ++iname) { + auto ptr = std::make_unique >(edm::ValueMap()); + edm::ValueMap::Filler filler(*ptr); + filler.insert(gsfTracks, output[iname].begin(), output[iname].end()); + filler.fill(); + event.put(std::move(ptr), names_[iname]); + } + + } else { + // TRANSFORM VALUEMAP OF FLOATS (BDT SCORE) KEYED BY GSF TRACK ... + // .. INTO VALUEMAP OF FLOATS (BDT SCORE) KEYED BY GSF ELECTRON ... + + // Retrieve GsfElectrons from Event + auto gsfElectrons = event.getHandle(gsfElectrons_); + + // Retrieve float ValueMaps from Event + for (unsigned int idx = 0; idx < names_.size(); ++idx) { + // Extract ValueMap from Event + auto const& floatValueMap = event.get(floatValueMaps_[idx]); + + // Store BDT scores in vector + std::vector output(gsfElectrons->size(), -99.); + auto const& gsfElectronsV = *gsfElectrons; + for (unsigned int iele = 0; iele < gsfElectronsV.size(); iele++) { + const reco::GsfElectron& ele = gsfElectronsV[iele]; + reco::GsfTrackRef gsf = ele.gsfTrack(); + output[iele] = floatValueMap[gsf]; + } + // Create and put ValueMap in Event + auto ptr = std::make_unique >(edm::ValueMap()); + edm::ValueMap::Filler filler(*ptr); + filler.insert(gsfElectrons, output.begin(), output.end()); + filler.fill(); + event.put(std::move(ptr), names_[idx]); + } } } @@ -76,10 +144,13 @@ void LowPtGsfElectronSeedValueMapsProducer::produce( edm::Event& event, const ed void LowPtGsfElectronSeedValueMapsProducer::fillDescriptions( edm::ConfigurationDescriptions& descriptions ) { edm::ParameterSetDescription desc; - desc.add("gsfTracks",edm::InputTag("lowPtGsfEleGsfTracks")); - desc.add("preIdsValueMap",edm::InputTag("lowPtGsfElectronSeeds")); - desc.add< std::vector >("ModelNames",std::vector()); - descriptions.add("defaultLowPtGsfElectronSeedValueMaps",desc); + desc.add("gsfTracks", edm::InputTag("lowPtGsfEleGsfTracks")); + desc.add("preIdsValueMap", edm::InputTag("lowPtGsfElectronSeeds")); + desc.add >("ModelNames", {"unbiased", "ptbiased"}); + desc.add("rekey", false); + desc.add("gsfElectrons", edm::InputTag()); + desc.add >("floatValueMaps", std::vector()); + descriptions.add("lowPtGsfElectronSeedValueMaps", desc); } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeedValueMaps_cff.py b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeedValueMaps_cff.py index 014cf4c57aa81..4ee7a8a749796 100644 --- a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeedValueMaps_cff.py +++ b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeedValueMaps_cff.py @@ -1,7 +1,11 @@ import FWCore.ParameterSet.Config as cms +# Low pT Electron value maps +from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronSeedValueMaps_cfi import lowPtGsfElectronSeedValueMaps -from RecoEgamma.EgammaElectronProducers.defaultLowPtGsfElectronSeedValueMaps_cfi import defaultLowPtGsfElectronSeedValueMaps - -lowPtGsfElectronSeedValueMaps = defaultLowPtGsfElectronSeedValueMaps.clone( - ModelNames = cms.vstring(['unbiased','ptbiased']) - ) +# Low pT Electron value maps, rekeyed by reco::GsfElectron +rekeyLowPtGsfElectronSeedValueMaps = lowPtGsfElectronSeedValueMaps.clone( + rekey=True, + gsfElectrons="lowPtGsfElectrons", + floatValueMaps=["lowPtGsfElectronSeedValueMaps:unbiased", + "lowPtGsfElectronSeedValueMaps:ptbiased"], +) diff --git a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py index 342eaf1a609e7..c4ae5dd94cb41 100644 --- a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py +++ b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py @@ -67,9 +67,10 @@ # Low pT Electron value maps from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronSeedValueMaps_cff import lowPtGsfElectronSeedValueMaps +from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronSeedValueMaps_cff import rekeyLowPtGsfElectronSeedValueMaps # Low pT Electron ID -from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronID_cff import lowPtGsfElectronID +from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronID_cfi import lowPtGsfElectronID # Full sequence lowPtGsfElectronTask = cms.Task(lowPtGsfElePfTracks, @@ -82,6 +83,7 @@ lowPtGsfElectronCores, lowPtGsfElectrons, lowPtGsfElectronSeedValueMaps, + rekeyLowPtGsfElectronSeedValueMaps, lowPtGsfElectronID ) lowPtGsfElectronSequence = cms.Sequence(lowPtGsfElectronTask) diff --git a/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc b/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc new file mode 100644 index 0000000000000..eab8b00884abe --- /dev/null +++ b/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc @@ -0,0 +1,678 @@ +#include "RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h" +#include "CommonTools/BaseParticlePropagator/interface/BaseParticlePropagator.h" +#include "DataFormats/GsfTrackReco/interface/GsfTrack.h" +#include "DataFormats/ParticleFlowReco/interface/PFCluster.h" +#include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h" +#include "DataFormats/TrackReco/interface/Track.h" +#include "DataFormats/TrackReco/interface/TrackFwd.h" +#include "TVector3.h" +#include + +namespace lowptgsfeleseed { + + //////////////////////////////////////////////////////////////////////////////// + // + std::vector features(const reco::PreId& ecal, + const reco::PreId& hcal, + double rho, + const reco::BeamSpot& spot, + noZS::EcalClusterLazyTools& tools) { + float trk_pt_ = -1.; + float trk_eta_ = -1.; + float trk_phi_ = -1.; + float trk_p_ = -1.; + float trk_nhits_ = -1.; + float trk_high_quality_ = -1.; + float trk_chi2red_ = -1.; + float rho_ = -1.; + float ktf_ecal_cluster_e_ = -1.; + float ktf_ecal_cluster_deta_ = -42.; + float ktf_ecal_cluster_dphi_ = -42.; + float ktf_ecal_cluster_e3x3_ = -1.; + float ktf_ecal_cluster_e5x5_ = -1.; + float ktf_ecal_cluster_covEtaEta_ = -42.; + float ktf_ecal_cluster_covEtaPhi_ = -42.; + float ktf_ecal_cluster_covPhiPhi_ = -42.; + float ktf_ecal_cluster_r9_ = -0.1; + float ktf_ecal_cluster_circularity_ = -0.1; + float ktf_hcal_cluster_e_ = -1.; + float ktf_hcal_cluster_deta_ = -42.; + float ktf_hcal_cluster_dphi_ = -42.; + float preid_gsf_dpt_ = -1.; + float preid_trk_gsf_chiratio_ = -1.; + float preid_gsf_chi2red_ = -1.; + float trk_dxy_sig_ = -1.; // must be last (not used by unbiased model) + + // Tracks + const auto& trk = ecal.trackRef(); // reco::TrackRef + if (trk.isNonnull()) { + trk_pt_ = trk->pt(); + trk_eta_ = trk->eta(); + trk_phi_ = trk->phi(); + trk_p_ = trk->p(); + trk_nhits_ = static_cast(trk->found()); + trk_high_quality_ = static_cast(trk->quality(reco::TrackBase::qualityByName("highPurity"))); + trk_chi2red_ = trk->normalizedChi2(); + if (trk->dxy(spot) > 0.) { + trk_dxy_sig_ = trk->dxyError() / trk->dxy(spot); //@@ to be consistent with the training based on 94X MC + } + ktf_ecal_cluster_dphi_ *= trk->charge(); //@@ to be consistent with the training based on 94X MC + } + + // Rho + rho_ = static_cast(rho); + + // ECAL clusters + const auto& ecal_clu = ecal.clusterRef(); // reco::PFClusterRef + if (ecal_clu.isNonnull()) { + ktf_ecal_cluster_e_ = ecal_clu->energy(); + ktf_ecal_cluster_deta_ = ecal.geomMatching()[0]; + ktf_ecal_cluster_dphi_ = ecal.geomMatching()[1]; + ktf_ecal_cluster_e3x3_ = tools.e3x3(*ecal_clu); + ktf_ecal_cluster_e5x5_ = tools.e5x5(*ecal_clu); + const auto& covs = tools.localCovariances(*ecal_clu); + ktf_ecal_cluster_covEtaEta_ = covs[0]; + ktf_ecal_cluster_covEtaPhi_ = covs[1]; + ktf_ecal_cluster_covPhiPhi_ = covs[2]; + if (ktf_ecal_cluster_e_ > 0.) { + ktf_ecal_cluster_r9_ = ktf_ecal_cluster_e3x3_ / ktf_ecal_cluster_e_; + } + if (ktf_ecal_cluster_e5x5_ > 0.) { + ktf_ecal_cluster_circularity_ = 1. - tools.e1x5(*ecal_clu) / ktf_ecal_cluster_e5x5_; + } else { + ktf_ecal_cluster_circularity_ = -0.1; + } + } + + // HCAL clusters + const auto& hcal_clu = hcal.clusterRef(); // reco::PFClusterRef + if (hcal_clu.isNonnull()) { + ktf_hcal_cluster_e_ = hcal_clu->energy(); + ktf_hcal_cluster_deta_ = hcal.geomMatching()[0]; + ktf_hcal_cluster_dphi_ = hcal.geomMatching()[1]; + } + + // PreId + preid_gsf_dpt_ = ecal.dpt(); + preid_trk_gsf_chiratio_ = ecal.chi2Ratio(); + preid_gsf_chi2red_ = ecal.gsfChi2(); + + // Set contents of vector + std::vector output = {trk_pt_, + trk_eta_, + trk_phi_, + trk_p_, + trk_nhits_, + trk_high_quality_, + trk_chi2red_, + rho_, + ktf_ecal_cluster_e_, + ktf_ecal_cluster_deta_, + ktf_ecal_cluster_dphi_, + ktf_ecal_cluster_e3x3_, + ktf_ecal_cluster_e5x5_, + ktf_ecal_cluster_covEtaEta_, + ktf_ecal_cluster_covEtaPhi_, + ktf_ecal_cluster_covPhiPhi_, + ktf_ecal_cluster_r9_, + ktf_ecal_cluster_circularity_, + ktf_hcal_cluster_e_, + ktf_hcal_cluster_deta_, + ktf_hcal_cluster_dphi_, + preid_gsf_dpt_, + preid_trk_gsf_chiratio_, + preid_gsf_chi2red_, + trk_dxy_sig_}; + return output; + }; + +} // namespace lowptgsfeleseed + +namespace lowptgsfeleid { + + std::vector features_V1(reco::GsfElectron const& ele, float rho, float unbiased, float field_z) { + float eid_rho = -999.; + float eid_sc_eta = -999.; + float eid_shape_full5x5_r9 = -999.; + float eid_sc_etaWidth = -999.; + float eid_sc_phiWidth = -999.; + float eid_shape_full5x5_HoverE = -999.; + float eid_trk_nhits = -999.; + float eid_trk_chi2red = -999.; + float eid_gsf_chi2red = -999.; + float eid_brem_frac = -999.; + float eid_gsf_nhits = -999.; + float eid_match_SC_EoverP = -999.; + float eid_match_eclu_EoverP = -999.; + float eid_match_SC_dEta = -999.; + float eid_match_SC_dPhi = -999.; + float eid_match_seed_dEta = -999.; + float eid_sc_E = -999.; + float eid_trk_p = -999.; + float gsf_mode_p = -999.; + float core_shFracHits = -999.; + float gsf_bdtout1 = -999.; + float gsf_dr = -999.; + float trk_dr = -999.; + float sc_Nclus = -999.; + float sc_clus1_nxtal = -999.; + float sc_clus1_dphi = -999.; + float sc_clus2_dphi = -999.; + float sc_clus1_deta = -999.; + float sc_clus2_deta = -999.; + float sc_clus1_E = -999.; + float sc_clus2_E = -999.; + float sc_clus1_E_ov_p = -999.; + float sc_clus2_E_ov_p = -999.; + + // KF tracks + if (ele.core().isNonnull()) { + reco::TrackRef trk = ele.closestCtfTrackRef(); + if (trk.isNonnull()) { + eid_trk_p = (float)trk->p(); + eid_trk_nhits = (float)trk->found(); + eid_trk_chi2red = (float)trk->normalizedChi2(); + TVector3 trkTV3(0, 0, 0); + trkTV3.SetPtEtaPhi(trk->pt(), trk->eta(), trk->phi()); + TVector3 eleTV3(0, 0, 0); + eleTV3.SetPtEtaPhi(ele.pt(), ele.eta(), ele.phi()); + trk_dr = eleTV3.DeltaR(trkTV3); + } + } + + // GSF tracks + if (ele.core().isNonnull()) { + reco::GsfTrackRef gsf = ele.core()->gsfTrack(); + if (gsf.isNonnull()) { + gsf_mode_p = gsf->pMode(); + eid_gsf_nhits = (float)gsf->found(); + eid_gsf_chi2red = gsf->normalizedChi2(); + TVector3 gsfTV3(0, 0, 0); + gsfTV3.SetPtEtaPhi(gsf->ptMode(), gsf->etaMode(), gsf->phiMode()); + TVector3 eleTV3(0, 0, 0); + eleTV3.SetPtEtaPhi(ele.pt(), ele.eta(), ele.phi()); + gsf_dr = eleTV3.DeltaR(gsfTV3); + } + } + + // Super clusters + if (ele.core().isNonnull()) { + reco::SuperClusterRef sc = ele.core()->superCluster(); + if (sc.isNonnull()) { + eid_sc_E = sc->energy(); + eid_sc_eta = sc->eta(); + eid_sc_etaWidth = sc->etaWidth(); + eid_sc_phiWidth = sc->phiWidth(); + sc_Nclus = sc->clustersSize(); + } + } + + // Track-cluster matching + eid_match_seed_dEta = ele.deltaEtaSeedClusterTrackAtCalo(); + eid_match_eclu_EoverP = (1. / ele.ecalEnergy()) - (1. / ele.p()); + eid_match_SC_EoverP = ele.eSuperClusterOverP(); + eid_match_SC_dEta = ele.deltaEtaSuperClusterTrackAtVtx(); + eid_match_SC_dPhi = ele.deltaPhiSuperClusterTrackAtVtx(); + + // Shower shape vars + eid_shape_full5x5_HoverE = ele.full5x5_hcalOverEcal(); + eid_shape_full5x5_r9 = ele.full5x5_r9(); + + // Misc + eid_rho = rho; + + eid_brem_frac = ele.fbrem(); + core_shFracHits = ele.shFracInnerHits(); + + // Unbiased BDT from ElectronSeed + gsf_bdtout1 = unbiased; + + // Clusters + if (ele.core().isNonnull()) { + reco::GsfTrackRef gsf = ele.core()->gsfTrack(); + if (gsf.isNonnull()) { + reco::SuperClusterRef sc = ele.core()->superCluster(); + if (sc.isNonnull()) { + // Propagate electron track to ECAL surface + double mass2 = 0.000511 * 0.000511; + float p2 = pow(gsf->p(), 2); + float energy = sqrt(mass2 + p2); + XYZTLorentzVector mom = XYZTLorentzVector(gsf->px(), gsf->py(), gsf->pz(), energy); + XYZTLorentzVector pos = XYZTLorentzVector(gsf->vx(), gsf->vy(), gsf->vz(), 0.); + RawParticle particle(mom, pos); + BaseParticlePropagator propagator(particle, 0., 0., field_z); + particle.setCharge(gsf->charge()); + propagator.propagateToEcalEntrance(true); // true only first half loop , false more than one loop + bool reach_ECAL = propagator.getSuccess(); // 0 does not reach ECAL, 1 yes barrel, 2 yes endcaps + GlobalPoint ecal_pos(particle.x(), // ECAL entry point for track + particle.y(), + particle.z()); + + // Track-cluster matching for most energetic clusters + sc_clus1_nxtal = -999; + sc_clus1_dphi = -999.; + sc_clus2_dphi = -999.; + sc_clus1_deta = -999.; + sc_clus2_deta = -999.; + sc_clus1_E = -999.; + sc_clus2_E = -999.; + sc_clus1_E_ov_p = -999.; + sc_clus2_E_ov_p = -999.; + trackClusterMatching(*sc, + *gsf, + reach_ECAL, + ecal_pos, + sc_clus1_nxtal, + sc_clus1_dphi, + sc_clus2_dphi, + sc_clus1_deta, + sc_clus2_deta, + sc_clus1_E, + sc_clus2_E, + sc_clus1_E_ov_p, + sc_clus2_E_ov_p); + sc_clus1_nxtal = (int)sc_clus1_nxtal; + + } // sc.isNonnull() + } // gsf.isNonnull() + } // clusters + + // Out-of-range + eid_rho = std::clamp(eid_rho, 0.f, 100.f); + eid_sc_eta = std::clamp(eid_sc_eta, -5.f, 5.f); + eid_shape_full5x5_r9 = std::clamp(eid_shape_full5x5_r9, 0.f, 2.f); + eid_sc_etaWidth = std::clamp(eid_sc_etaWidth, 0.f, 3.14f); + eid_sc_phiWidth = std::clamp(eid_sc_phiWidth, 0.f, 3.14f); + eid_shape_full5x5_HoverE = std::clamp(eid_shape_full5x5_HoverE, 0.f, 50.f); + eid_trk_nhits = std::clamp(eid_trk_nhits, -1.f, 50.f); + eid_trk_chi2red = std::clamp(eid_trk_chi2red, -1.f, 50.f); + eid_gsf_chi2red = std::clamp(eid_gsf_chi2red, -1.f, 100.f); + if (eid_brem_frac < 0.) + eid_brem_frac = -1.; // + if (eid_brem_frac > 1.) + eid_brem_frac = 1.; // + eid_gsf_nhits = std::clamp(eid_gsf_nhits, -1.f, 50.f); + eid_match_SC_EoverP = std::clamp(eid_match_SC_EoverP, 0.f, 100.f); + eid_match_eclu_EoverP = std::clamp(eid_match_eclu_EoverP, -1.f, 1.f); + eid_match_SC_dEta = std::clamp(eid_match_SC_dEta, -10.f, 10.f); + eid_match_SC_dPhi = std::clamp(eid_match_SC_dPhi, -3.14f, 3.14f); + eid_match_seed_dEta = std::clamp(eid_match_seed_dEta, -10.f, 10.f); + eid_sc_E = std::clamp(eid_sc_E, 0.f, 1000.f); + eid_trk_p = std::clamp(eid_trk_p, -1.f, 1000.f); + gsf_mode_p = std::clamp(gsf_mode_p, 0.f, 1000.f); + core_shFracHits = std::clamp(core_shFracHits, 0.f, 1.f); + gsf_bdtout1 = std::clamp(gsf_bdtout1, -20.f, 20.f); + if (gsf_dr < 0.) + gsf_dr = 5.; // + if (gsf_dr > 5.) + gsf_dr = 5.; // + if (trk_dr < 0.) + trk_dr = 5.; // + if (trk_dr > 5.) + trk_dr = 5.; // + sc_Nclus = std::clamp(sc_Nclus, 0.f, 20.f); + sc_clus1_nxtal = std::clamp(sc_clus1_nxtal, 0.f, 100.f); + sc_clus1_dphi = std::clamp(sc_clus1_dphi, -3.14f, 3.14f); + sc_clus2_dphi = std::clamp(sc_clus2_dphi, -3.14f, 3.14f); + sc_clus1_deta = std::clamp(sc_clus1_deta, -5.f, 5.f); + sc_clus2_deta = std::clamp(sc_clus2_deta, -5.f, 5.f); + sc_clus1_E = std::clamp(sc_clus1_E, 0.f, 1000.f); + sc_clus2_E = std::clamp(sc_clus2_E, 0.f, 1000.f); + if (sc_clus1_E_ov_p < 0.) + sc_clus1_E_ov_p = -1.; // + if (sc_clus2_E_ov_p < 0.) + sc_clus2_E_ov_p = -1.; // + + // Set contents of vector + std::vector output = {eid_rho, + eid_sc_eta, + eid_shape_full5x5_r9, + eid_sc_etaWidth, + eid_sc_phiWidth, + eid_shape_full5x5_HoverE, + eid_trk_nhits, + eid_trk_chi2red, + eid_gsf_chi2red, + eid_brem_frac, + eid_gsf_nhits, + eid_match_SC_EoverP, + eid_match_eclu_EoverP, + eid_match_SC_dEta, + eid_match_SC_dPhi, + eid_match_seed_dEta, + eid_sc_E, + eid_trk_p, + gsf_mode_p, + core_shFracHits, + gsf_bdtout1, + gsf_dr, + trk_dr, + sc_Nclus, + sc_clus1_nxtal, + sc_clus1_dphi, + sc_clus2_dphi, + sc_clus1_deta, + sc_clus2_deta, + sc_clus1_E, + sc_clus2_E, + sc_clus1_E_ov_p, + sc_clus2_E_ov_p}; + return output; + } + + //////////////////////////////////////////////////////////////////////////////// + // feature list for original models (2019Aug07 and earlier) + std::vector features_V0(reco::GsfElectron const& ele, float rho, float unbiased) { + float eid_rho = -999.; + float eid_sc_eta = -999.; + float eid_shape_full5x5_r9 = -999.; + float eid_sc_etaWidth = -999.; + float eid_sc_phiWidth = -999.; + float eid_shape_full5x5_HoverE = -999.; + float eid_trk_nhits = -999.; + float eid_trk_chi2red = -999.; + float eid_gsf_chi2red = -999.; + float eid_brem_frac = -999.; + float eid_gsf_nhits = -999.; + float eid_match_SC_EoverP = -999.; + float eid_match_eclu_EoverP = -999.; + float eid_match_SC_dEta = -999.; + float eid_match_SC_dPhi = -999.; + float eid_match_seed_dEta = -999.; + float eid_sc_E = -999.; + float eid_trk_p = -999.; + float gsf_mode_p = -999.; + float core_shFracHits = -999.; + float gsf_bdtout1 = -999.; + float gsf_dr = -999.; + float trk_dr = -999.; + float sc_Nclus = -999.; + float sc_clus1_nxtal = -999.; + float sc_clus1_dphi = -999.; + float sc_clus2_dphi = -999.; + float sc_clus1_deta = -999.; + float sc_clus2_deta = -999.; + float sc_clus1_E = -999.; + float sc_clus2_E = -999.; + float sc_clus1_E_ov_p = -999.; + float sc_clus2_E_ov_p = -999.; + + // KF tracks + if (ele.core().isNonnull()) { + const auto& trk = ele.closestCtfTrackRef(); // reco::TrackRef + if (trk.isNonnull()) { + eid_trk_p = (float)trk->p(); + eid_trk_nhits = (float)trk->found(); + eid_trk_chi2red = (float)trk->normalizedChi2(); + TVector3 trkTV3(0, 0, 0); + trkTV3.SetPtEtaPhi(trk->pt(), trk->eta(), trk->phi()); + TVector3 eleTV3(0, 0, 0); + eleTV3.SetPtEtaPhi(ele.pt(), ele.eta(), ele.phi()); + trk_dr = eleTV3.DeltaR(trkTV3); + } + } + + // GSF tracks + if (ele.core().isNonnull()) { + const auto& gsf = ele.core()->gsfTrack(); // reco::GsfTrackRef + if (gsf.isNonnull()) { + gsf_mode_p = gsf->pMode(); + eid_gsf_nhits = (float)gsf->found(); + eid_gsf_chi2red = gsf->normalizedChi2(); + TVector3 gsfTV3(0, 0, 0); + gsfTV3.SetPtEtaPhi(gsf->ptMode(), gsf->etaMode(), gsf->phiMode()); + TVector3 eleTV3(0, 0, 0); + eleTV3.SetPtEtaPhi(ele.pt(), ele.eta(), ele.phi()); + gsf_dr = eleTV3.DeltaR(gsfTV3); + } + } + + // Super clusters + if (ele.core().isNonnull()) { + const auto& sc = ele.core()->superCluster(); // reco::SuperClusterRef + if (sc.isNonnull()) { + eid_sc_E = sc->energy(); + eid_sc_eta = sc->eta(); + eid_sc_etaWidth = sc->etaWidth(); + eid_sc_phiWidth = sc->phiWidth(); + sc_Nclus = (float)sc->clustersSize(); + } + } + + // Track-cluster matching + eid_match_seed_dEta = ele.deltaEtaSeedClusterTrackAtCalo(); + eid_match_eclu_EoverP = (1. / ele.ecalEnergy()) - (1. / ele.p()); + eid_match_SC_EoverP = ele.eSuperClusterOverP(); + eid_match_SC_dEta = ele.deltaEtaSuperClusterTrackAtVtx(); + eid_match_SC_dPhi = ele.deltaPhiSuperClusterTrackAtVtx(); + + // Shower shape vars + eid_shape_full5x5_HoverE = ele.full5x5_hcalOverEcal(); + eid_shape_full5x5_r9 = ele.full5x5_r9(); + + // Misc + eid_rho = rho; + + eid_brem_frac = ele.fbrem(); + core_shFracHits = (float)ele.shFracInnerHits(); + + // Unbiased BDT from ElectronSeed + gsf_bdtout1 = unbiased; + + // Clusters + if (ele.core().isNonnull()) { + const auto& gsf = ele.core()->gsfTrack(); // reco::GsfTrackRef + if (gsf.isNonnull()) { + const auto& sc = ele.core()->superCluster(); // reco::SuperClusterRef + if (sc.isNonnull()) { + // Propagate electron track to ECAL surface + double mass2 = 0.000511 * 0.000511; + float p2 = pow(gsf->p(), 2); + float energy = sqrt(mass2 + p2); + math::XYZTLorentzVector mom = math::XYZTLorentzVector(gsf->px(), gsf->py(), gsf->pz(), energy); + math::XYZTLorentzVector pos = math::XYZTLorentzVector(gsf->vx(), gsf->vy(), gsf->vz(), 0.); + float field_z = 3.8; + BaseParticlePropagator mypart(RawParticle(mom, pos, gsf->charge()), 0, 0, field_z); + mypart.propagateToEcalEntrance(true); // true only first half loop , false more than one loop + bool reach_ECAL = mypart.getSuccess(); // 0 does not reach ECAL, 1 yes barrel, 2 yes endcaps + + // ECAL entry point for track + GlobalPoint ecal_pos( + mypart.particle().vertex().x(), mypart.particle().vertex().y(), mypart.particle().vertex().z()); + + // Track-cluster matching for most energetic clusters + sc_clus1_nxtal = -999.; + sc_clus1_dphi = -999.; + sc_clus2_dphi = -999.; + sc_clus1_deta = -999.; + sc_clus2_deta = -999.; + sc_clus1_E = -999.; + sc_clus2_E = -999.; + sc_clus1_E_ov_p = -999.; + sc_clus2_E_ov_p = -999.; + trackClusterMatching(*sc, + *gsf, + reach_ECAL, + ecal_pos, + sc_clus1_nxtal, + sc_clus1_dphi, + sc_clus2_dphi, + sc_clus1_deta, + sc_clus2_deta, + sc_clus1_E, + sc_clus2_E, + sc_clus1_E_ov_p, + sc_clus2_E_ov_p); + + } // sc.isNonnull() + } // gsf.isNonnull() + } // clusters + + // Out-of-range + eid_sc_eta = std::clamp(eid_sc_eta, -5.f, 5.f); + eid_shape_full5x5_r9 = std::clamp(eid_shape_full5x5_r9, 0.f, 2.f); + eid_sc_etaWidth = std::clamp(eid_sc_etaWidth, 0.f, 3.14f); + eid_sc_phiWidth = std::clamp(eid_sc_phiWidth, 0.f, 3.14f); + eid_shape_full5x5_HoverE = std::clamp(eid_shape_full5x5_HoverE, 0.f, 50.f); + eid_trk_nhits = std::clamp(eid_trk_nhits, -1.f, 50.f); + eid_trk_chi2red = std::clamp(eid_trk_chi2red, -1.f, 50.f); + eid_gsf_chi2red = std::clamp(eid_gsf_chi2red, -1.f, 100.f); + if (eid_brem_frac < 0.) + eid_brem_frac = -1.; // + if (eid_brem_frac > 1.) + eid_brem_frac = 1.; // + eid_gsf_nhits = std::clamp(eid_gsf_nhits, -1.f, 50.f); + eid_match_SC_EoverP = std::clamp(eid_match_SC_EoverP, 0.f, 100.f); + eid_match_eclu_EoverP = std::clamp(eid_match_eclu_EoverP, -1.f, 1.f); + eid_match_SC_dEta = std::clamp(eid_match_SC_dEta, -10.f, 10.f); + eid_match_SC_dPhi = std::clamp(eid_match_SC_dPhi, -3.14f, 3.14f); + eid_match_seed_dEta = std::clamp(eid_match_seed_dEta, -10.f, 10.f); + eid_sc_E = std::clamp(eid_sc_E, 0.f, 1000.f); + eid_trk_p = std::clamp(eid_trk_p, -1.f, 1000.f); + gsf_mode_p = std::clamp(gsf_mode_p, 0.f, 1000.f); + core_shFracHits = std::clamp(core_shFracHits, 0.f, 1.f); + gsf_bdtout1 = std::clamp(gsf_bdtout1, -20.f, 20.f); + if (gsf_dr < 0.) + gsf_dr = 5.; // + if (gsf_dr > 5.) + gsf_dr = 5.; // + if (trk_dr < 0.) + trk_dr = 5.; // + if (trk_dr > 5.) + trk_dr = 5.; // + sc_Nclus = std::clamp(sc_Nclus, 0.f, 20.f); + sc_clus1_nxtal = std::clamp(sc_clus1_nxtal, 0.f, 100.f); + if (sc_clus1_dphi < -3.14) + sc_clus1_dphi = -5.; // + if (sc_clus1_dphi > 3.14) + sc_clus1_dphi = 5.; // + if (sc_clus2_dphi < -3.14) + sc_clus2_dphi = -5.; // + if (sc_clus2_dphi > 3.14) + sc_clus2_dphi = 5.; // + sc_clus1_deta = std::clamp(sc_clus1_deta, -5.f, 5.f); + sc_clus2_deta = std::clamp(sc_clus2_deta, -5.f, 5.f); + sc_clus1_E = std::clamp(sc_clus1_E, 0.f, 1000.f); + sc_clus2_E = std::clamp(sc_clus2_E, 0.f, 1000.f); + if (sc_clus1_E_ov_p < 0.) + sc_clus1_E_ov_p = -1.; // + if (sc_clus2_E_ov_p < 0.) + sc_clus2_E_ov_p = -1.; // + + // Set contents of vector + std::vector output = {eid_rho, + eid_sc_eta, + eid_shape_full5x5_r9, + eid_sc_etaWidth, + eid_sc_phiWidth, + eid_shape_full5x5_HoverE, + eid_trk_nhits, + eid_trk_chi2red, + eid_gsf_chi2red, + eid_brem_frac, + eid_gsf_nhits, + eid_match_SC_EoverP, + eid_match_eclu_EoverP, + eid_match_SC_dEta, + eid_match_SC_dPhi, + eid_match_seed_dEta, + eid_sc_E, + eid_trk_p, + gsf_mode_p, + core_shFracHits, + gsf_bdtout1, + gsf_dr, + trk_dr, + sc_Nclus, + sc_clus1_nxtal, + sc_clus1_dphi, + sc_clus2_dphi, + sc_clus1_deta, + sc_clus2_deta, + sc_clus1_E, + sc_clus2_E, + sc_clus1_E_ov_p, + sc_clus2_E_ov_p}; + return output; + } + + //////////////////////////////////////////////////////////////////////////////// + // Find most energetic clusters + void findEnergeticClusters( + reco::SuperCluster const& sc, int& clusNum, float& maxEne1, float& maxEne2, int& i1, int& i2) { + if (sc.clustersSize() > 0 && sc.clustersBegin() != sc.clustersEnd()) { + for (auto const& cluster : sc.clusters()) { + if (cluster->energy() > maxEne1) { + maxEne1 = cluster->energy(); + i1 = clusNum; + } + clusNum++; + } + if (sc.clustersSize() > 1) { + clusNum = 0; + for (auto const& cluster : sc.clusters()) { + if (clusNum != i1) { + if (cluster->energy() > maxEne2) { + maxEne2 = cluster->energy(); + i2 = clusNum; + } + } + clusNum++; + } + } + } // loop over clusters + } + + //////////////////////////////////////////////////////////////////////////////// + // Track-cluster matching for most energetic clusters + void trackClusterMatching(reco::SuperCluster const& sc, + reco::GsfTrack const& gsf, + bool const& reach_ECAL, + GlobalPoint const& ecal_pos, + float& sc_clus1_nxtal, + float& sc_clus1_dphi, + float& sc_clus2_dphi, + float& sc_clus1_deta, + float& sc_clus2_deta, + float& sc_clus1_E, + float& sc_clus2_E, + float& sc_clus1_E_ov_p, + float& sc_clus2_E_ov_p) { + // Iterate through ECAL clusters and sort in energy + int clusNum = 0; + float maxEne1 = -1; + float maxEne2 = -1; + int i1 = -1; + int i2 = -1; + findEnergeticClusters(sc, clusNum, maxEne1, maxEne2, i1, i2); + + // track-clusters match + clusNum = 0; + if (sc.clustersSize() > 0 && sc.clustersBegin() != sc.clustersEnd()) { + for (auto const& cluster : sc.clusters()) { + float deta = ecal_pos.eta() - cluster->eta(); + float dphi = reco::deltaPhi(ecal_pos.phi(), cluster->phi()); + if (clusNum == i1) { + sc_clus1_E = cluster->energy(); + if (gsf.pMode() > 0) + sc_clus1_E_ov_p = cluster->energy() / gsf.pMode(); + sc_clus1_nxtal = (float)cluster->size(); + if (reach_ECAL > 0) { + sc_clus1_deta = deta; + sc_clus1_dphi = dphi; + } + } else if (clusNum == i2) { + sc_clus2_E = cluster->energy(); + if (gsf.pMode() > 0) + sc_clus2_E_ov_p = cluster->energy() / gsf.pMode(); + if (reach_ECAL > 0) { + sc_clus2_deta = deta; + sc_clus2_dphi = dphi; + } + } + clusNum++; + } + } + } + +} // namespace lowptgsfeleid From e134d2335fe94cbff84ae79e2e2a338ea15465d3 Mon Sep 17 00:00:00 2001 From: bainbrid Date: Wed, 25 Nov 2020 18:24:29 +0100 Subject: [PATCH 03/21] enable embedding of edm::Ptr in pat::Electron --- DataFormats/PatCandidates/src/classes_def_objects.xml | 2 ++ .../plugins/EGExtraInfoModifierFromValueMaps.cc | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/DataFormats/PatCandidates/src/classes_def_objects.xml b/DataFormats/PatCandidates/src/classes_def_objects.xml index 9a2cd10b18b6c..56defc2734792 100644 --- a/DataFormats/PatCandidates/src/classes_def_objects.xml +++ b/DataFormats/PatCandidates/src/classes_def_objects.xml @@ -486,6 +486,8 @@ + + diff --git a/RecoEgamma/EgammaTools/plugins/EGExtraInfoModifierFromValueMaps.cc b/RecoEgamma/EgammaTools/plugins/EGExtraInfoModifierFromValueMaps.cc index db42b292a3edb..62b2461991e0a 100644 --- a/RecoEgamma/EgammaTools/plugins/EGExtraInfoModifierFromValueMaps.cc +++ b/RecoEgamma/EgammaTools/plugins/EGExtraInfoModifierFromValueMaps.cc @@ -1,4 +1,5 @@ #include "RecoEgamma/EgammaTools/interface/EGExtraInfoModifierFromValueMaps.h" +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" using EGExtraInfoModifierFromFloatValueMaps = EGExtraInfoModifierFromValueMaps; DEFINE_EDM_PLUGIN(ModifyObjectValueFactory, @@ -38,5 +39,10 @@ DEFINE_EDM_PLUGIN(ModifyObjectValueFactory, using EGExtraInfoModifierFromEGIDValueMaps = EGExtraInfoModifierFromValueMaps; DEFINE_EDM_PLUGIN(ModifyObjectValueFactory, - EGExtraInfoModifierFromEGIDValueMaps, - "EGExtraInfoModifierFromEGIDValueMaps"); + EGExtraInfoModifierFromEGIDValueMaps, + "EGExtraInfoModifierFromEGIDValueMaps"); + +using EGExtraInfoModifierFromPackedCandPtrValueMaps = EGExtraInfoModifierFromValueMaps >; +DEFINE_EDM_PLUGIN(ModifyObjectValueFactory, + EGExtraInfoModifierFromPackedCandPtrValueMaps, + "EGExtraInfoModifierFromPackedCandPtrValueMaps"); From 220f959ea70d82ff1eca190299ee62464c4a3c3a Mon Sep 17 00:00:00 2001 From: bainbrid Date: Wed, 25 Nov 2020 18:40:24 +0100 Subject: [PATCH 04/21] add 'ele2packed' and 'ele2lost' ValueMaps, embed IDs and Ptrs, select based on ID score, add run2_miniAOD_UL modifier, code review --- PhysicsTools/PatAlgos/plugins/BuildFile.xml | 1 + .../LowPtGSFToPackedCandidateLinker.cc | 273 ++++++++++-------- .../lowPtElectronProducer_cff.py | 80 +++-- .../producersLayer1/patCandidates_cff.py | 9 + .../lowPtElectronSelector_cfi.py | 6 +- .../selectedPatCandidates_cff.py | 8 + .../slimming/slimmedLowPtElectrons_cff.py | 11 + .../slimming/slimmedLowPtElectrons_cfi.py | 23 +- .../PatAlgos/python/slimming/slimming_cff.py | 12 +- .../PatAlgos/test/IntegrationTest_cfg.py | 1 + .../test/patTuple_addTriggerInfo_cfg.py | 1 + 11 files changed, 265 insertions(+), 160 deletions(-) create mode 100644 PhysicsTools/PatAlgos/python/slimming/slimmedLowPtElectrons_cff.py diff --git a/PhysicsTools/PatAlgos/plugins/BuildFile.xml b/PhysicsTools/PatAlgos/plugins/BuildFile.xml index e7d2c6386a13a..29d6b64440915 100644 --- a/PhysicsTools/PatAlgos/plugins/BuildFile.xml +++ b/PhysicsTools/PatAlgos/plugins/BuildFile.xml @@ -11,6 +11,7 @@ + diff --git a/PhysicsTools/PatAlgos/plugins/LowPtGSFToPackedCandidateLinker.cc b/PhysicsTools/PatAlgos/plugins/LowPtGSFToPackedCandidateLinker.cc index 9c992daaa0966..9dc3a049ffe69 100644 --- a/PhysicsTools/PatAlgos/plugins/LowPtGSFToPackedCandidateLinker.cc +++ b/PhysicsTools/PatAlgos/plugins/LowPtGSFToPackedCandidateLinker.cc @@ -1,10 +1,11 @@ #include #include "DataFormats/Candidate/interface/Candidate.h" +#include "DataFormats/Common/interface/RefToPtr.h" #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" #include "DataFormats/GsfTrackReco/interface/GsfTrack.h" #include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h" +#include "DataFormats/PatCandidates/interface/Electron.h" #include "DataFormats/PatCandidates/interface/PackedCandidate.h" #include "DataFormats/Common/interface/Association.h" #include "FWCore/Framework/interface/global/EDProducer.h" @@ -19,6 +20,9 @@ #include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h" #include "FWCore/Framework/interface/MakerMacros.h" +typedef edm::Ptr PackedCandidatePtr; +typedef std::vector PackedCandidatePtrCollection; + class LowPtGSFToPackedCandidateLinker : public edm::global::EDProducer<> { public: explicit LowPtGSFToPackedCandidateLinker(const edm::ParameterSet&); @@ -28,135 +32,162 @@ class LowPtGSFToPackedCandidateLinker : public edm::global::EDProducer<> { static void fillDescriptions(edm::ConfigurationDescriptions&); private: - const edm::EDGetTokenT pfcands_; - const edm::EDGetTokenT packed_; - const edm::EDGetTokenT lost_tracks_; - const edm::EDGetTokenT tracks_; - const edm::EDGetTokenT > pf2packed_; - const edm::EDGetTokenT > lost2trk_; - const edm::EDGetTokenT< edm::Association > gsf2trk_; - const edm::EDGetTokenT< std::vector > gsftracks_; + const edm::EDGetTokenT pfcands_; + const edm::EDGetTokenT packed_; + const edm::EDGetTokenT lost_tracks_; + const edm::EDGetTokenT tracks_; + const edm::EDGetTokenT > pf2packed_; + const edm::EDGetTokenT > lost2trk_; + const edm::EDGetTokenT > gsf2trk_; + const edm::EDGetTokenT > gsftracks_; + const edm::EDGetTokenT > electrons_; }; -LowPtGSFToPackedCandidateLinker::LowPtGSFToPackedCandidateLinker(const edm::ParameterSet& iConfig) : - pfcands_{consumes(iConfig.getParameter("PFCandidates"))}, - packed_{consumes(iConfig.getParameter("packedCandidates"))}, - lost_tracks_{consumes(iConfig.getParameter("lostTracks"))}, - tracks_{consumes(iConfig.getParameter("tracks"))}, - pf2packed_{consumes >(iConfig.getParameter("packedCandidates"))}, - lost2trk_{consumes >(iConfig.getParameter("lostTracks"))}, - gsf2trk_{consumes >(iConfig.getParameter("gsfToTrack"))}, - gsftracks_{consumes >(iConfig.getParameter("gsfTracks"))} { - produces< edm::Association > ("packedCandidates"); - produces< edm::Association > ("lostTracks"); - } +LowPtGSFToPackedCandidateLinker::LowPtGSFToPackedCandidateLinker(const edm::ParameterSet& iConfig) + : pfcands_{consumes(iConfig.getParameter("PFCandidates"))}, + packed_{consumes(iConfig.getParameter("packedCandidates"))}, + lost_tracks_{consumes(iConfig.getParameter("lostTracks"))}, + tracks_{consumes(iConfig.getParameter("tracks"))}, + pf2packed_{consumes >( + iConfig.getParameter("packedCandidates"))}, + lost2trk_{consumes >( + iConfig.getParameter("lostTracks"))}, + gsf2trk_{consumes >(iConfig.getParameter("gsfToTrack"))}, + gsftracks_{consumes >(iConfig.getParameter("gsfTracks"))}, + electrons_{consumes >(iConfig.getParameter("electrons"))} { + produces >("gsf2packed"); + produces >("gsf2lost"); + produces >("ele2packed"); + produces >("ele2lost"); +} LowPtGSFToPackedCandidateLinker::~LowPtGSFToPackedCandidateLinker() {} void LowPtGSFToPackedCandidateLinker::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const { - edm::Handle pfcands; - iEvent.getByToken(pfcands_, pfcands); - - edm::Handle packed; - iEvent.getByToken(packed_, packed); - - edm::Handle lost_tracks; - iEvent.getByToken(lost_tracks_, lost_tracks); - - edm::Handle > pf2packed; - iEvent.getByToken(pf2packed_, pf2packed); - - edm::Handle > lost2trk_assoc; - iEvent.getByToken(lost2trk_, lost2trk_assoc); - - edm::Handle > gsftracks; - iEvent.getByToken(gsftracks_, gsftracks); - - edm::Handle tracks; - iEvent.getByToken(tracks_, tracks); - - edm::Handle > gsf2trk; - iEvent.getByToken(gsf2trk_, gsf2trk); - - // collection sizes, for reference - const size_t npf = pfcands->size(); - const size_t npacked = packed->size(); - const size_t nlost = lost_tracks->size(); - const size_t ntracks = tracks->size(); - const size_t ngsf = gsftracks->size(); - - //store index mapping in vectors for easy and fast access - std::vector trk2packed(ntracks, npacked); - std::vector trk2lost(ntracks, nlost); - - //store auxiliary mappings for association - std::vector gsf2pack(ngsf, -1); - std::vector gsf2lost(ngsf, -1); - - //electrons will never store their track (they store the Gsf track) - //map PackedPF <--> Track - for(unsigned int icand=0; icand < npf; ++icand) { - edm::Ref pf_ref(pfcands,icand); - const reco::PFCandidate &cand = pfcands->at(icand); - auto packed_ref = (*pf2packed)[pf_ref]; - if(cand.charge() && packed_ref.isNonnull() && cand.trackRef().isNonnull() - && cand.trackRef().id() == tracks.id() ) { - size_t trkid = cand.trackRef().index(); - size_t packid = packed_ref.index(); - trk2packed[trkid] = packid; - } - } - - //map LostTrack <--> Track - for(unsigned int itrk=0; itrk < ntracks; ++itrk) { - reco::TrackRef key(tracks, itrk); - pat::PackedCandidateRef lostTrack = (*lost2trk_assoc)[key]; - if(lostTrack.isNonnull()) { - size_t ilost = lostTrack.index(); //assumes that LostTracks are all made from the same track collection - trk2lost[itrk] = ilost; - } - } - - //map Track --> GSF and fill GSF --> PackedCandidates and GSF --> Lost associations - for(unsigned int igsf=0; igsf < ngsf; ++igsf) { - reco::GsfTrackRef gref(gsftracks, igsf); - reco::TrackRef trk = (*gsf2trk)[gref]; - if(trk.id() != tracks.id()) { - throw cms::Exception("WrongCollection", "The reco::Track collection used to match against the GSF Tracks was not used to produce such tracks"); - } - size_t trkid = trk.index(); - - if(trk2packed[trkid] != npacked) { - gsf2pack[igsf] = trk2packed[trkid]; - } - if(trk2lost[trkid] != nlost) { - gsf2lost[igsf] = trk2lost[trkid]; - } - } - - // create output collections from the mappings - auto assoc_gsf2pack = std::make_unique< edm::Association >(packed); - edm::Association::Filler gsf2pack_filler(*assoc_gsf2pack); - gsf2pack_filler.insert(gsftracks, gsf2pack.begin(), gsf2pack.end()); - gsf2pack_filler.fill(); - iEvent.put(std::move(assoc_gsf2pack), "packedCandidates"); - - auto assoc_gsf2lost = std::make_unique< edm::Association >(lost_tracks); - edm::Association::Filler gsf2lost_filler(*assoc_gsf2lost); - gsf2lost_filler.insert(gsftracks, gsf2lost.begin(), gsf2lost.end()); - gsf2lost_filler.fill(); - iEvent.put(std::move(assoc_gsf2lost), "lostTracks"); + auto pfcands = iEvent.getHandle(pfcands_); + auto packed = iEvent.getHandle(packed_); + auto lost_tracks = iEvent.getHandle(lost_tracks_); + auto pf2packed = iEvent.getHandle(pf2packed_); + auto lost2trk_assoc = iEvent.getHandle(lost2trk_); + auto gsftracks = iEvent.getHandle(gsftracks_); + auto tracks = iEvent.getHandle(tracks_); + auto gsf2trk = iEvent.getHandle(gsf2trk_); + auto electrons = iEvent.getHandle(electrons_); + + // collection sizes, for reference + const size_t npf = pfcands->size(); + const size_t npacked = packed->size(); + const size_t nlost = lost_tracks->size(); + const size_t ntracks = tracks->size(); + const size_t ngsf = gsftracks->size(); + const size_t nele = electrons->size(); + + //store index mapping in vectors for easy and fast access + std::vector trk2packed(ntracks, npacked); + std::vector trk2lost(ntracks, nlost); + + //store auxiliary mappings for association + std::vector gsf2pack(ngsf, -1); + std::vector gsf2lost(ngsf, -1); + PackedCandidatePtrCollection ele2packedptr(nele, PackedCandidatePtr(packed, -1)); + PackedCandidatePtrCollection ele2lostptr(nele, PackedCandidatePtr(lost_tracks, -1)); + + //electrons will never store their track (they store the Gsf track) + //map PackedPF <--> Track + for (unsigned int icand = 0; icand < npf; ++icand) { + edm::Ref pf_ref(pfcands, icand); + const reco::PFCandidate& cand = pfcands->at(icand); + auto packed_ref = (*pf2packed)[pf_ref]; + if (cand.charge() && packed_ref.isNonnull() && cand.trackRef().isNonnull() && cand.trackRef().id() == tracks.id()) { + size_t trkid = cand.trackRef().index(); + trk2packed[trkid] = packed_ref.index(); + } + } + + //map LostTrack <--> Track + for (unsigned int itrk = 0; itrk < ntracks; ++itrk) { + reco::TrackRef key(tracks, itrk); + pat::PackedCandidateRef lostTrack = (*lost2trk_assoc)[key]; + if (lostTrack.isNonnull()) { + trk2lost[itrk] = lostTrack.index(); // assumes that LostTracks are all made from the same track collection + } + } + + //map Track --> GSF and fill GSF --> PackedCandidates and GSF --> Lost associations + for (unsigned int igsf = 0; igsf < ngsf; ++igsf) { + reco::GsfTrackRef gsf_ref(gsftracks, igsf); + reco::TrackRef trk_ref = (*gsf2trk)[gsf_ref]; + if (trk_ref.id() != tracks.id()) { + throw cms::Exception( + "WrongCollection", + "The reco::Track collection used to match against the GSF Tracks was not used to produce such tracks"); + } + size_t trkid = trk_ref.index(); + if (trk2packed[trkid] != npacked) { + gsf2pack[igsf] = trk2packed[trkid]; + } + if (trk2lost[trkid] != nlost) { + gsf2lost[igsf] = trk2lost[trkid]; + } + } + + //map Electron-->pat::PFCandidatePtr via Electron-->GsfTrack-->Track and Track-->pat::PFCandidatePtr + for (unsigned int iele = 0; iele < nele; ++iele) { + auto const& ele = (*electrons)[iele]; + reco::GsfTrackRef gsf_ref = ele.core()->gsfTrack(); + reco::TrackRef trk_ref = (*gsf2trk)[gsf_ref]; + if (trk_ref.id() != tracks.id()) { + throw cms::Exception( + "WrongCollection", + "The reco::Track collection used to match against the GSF Tracks was not used to produce such tracks"); + } + size_t trkid = trk_ref.index(); + auto packedIdx = trk2packed[trkid]; + if (packedIdx != npacked) { + ele2packedptr[iele] = PackedCandidatePtr(packed, packedIdx); + } + auto lostIdx = trk2lost[trkid]; + if (lostIdx != nlost) { + ele2lostptr[iele] = PackedCandidatePtr(lost_tracks, lostIdx); + } + } + + // create output collections from the mappings + auto assoc_gsf2pack = std::make_unique >(packed); + edm::Association::Filler gsf2pack_filler(*assoc_gsf2pack); + gsf2pack_filler.insert(gsftracks, gsf2pack.begin(), gsf2pack.end()); + gsf2pack_filler.fill(); + iEvent.put(std::move(assoc_gsf2pack), "gsf2packed"); + + auto assoc_gsf2lost = std::make_unique >(lost_tracks); + edm::Association::Filler gsf2lost_filler(*assoc_gsf2lost); + gsf2lost_filler.insert(gsftracks, gsf2lost.begin(), gsf2lost.end()); + gsf2lost_filler.fill(); + iEvent.put(std::move(assoc_gsf2lost), "gsf2lost"); + + auto map_ele2packedptr = std::make_unique >(); + edm::ValueMap::Filler ele2packedptr_filler(*map_ele2packedptr); + ele2packedptr_filler.insert(electrons, ele2packedptr.begin(), ele2packedptr.end()); + ele2packedptr_filler.fill(); + iEvent.put(std::move(map_ele2packedptr), "ele2packed"); + + auto map_ele2lostptr = std::make_unique >(); + edm::ValueMap::Filler ele2lostptr_filler(*map_ele2lostptr); + ele2lostptr_filler.insert(electrons, ele2lostptr.begin(), ele2lostptr.end()); + ele2lostptr_filler.fill(); + iEvent.put(std::move(map_ele2lostptr), "ele2lost"); } void LowPtGSFToPackedCandidateLinker::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - edm::ParameterSetDescription desc; - desc.add("PFCandidates", edm::InputTag("particleFlow")); - desc.add("packedCandidates", edm::InputTag("packedPFCandidates")); - desc.add("lostTracks", edm::InputTag("lostTracks")); - desc.add("tracks", edm::InputTag("generalTracks")); - desc.add("gsfToTrack", edm::InputTag("lowPtGsfToTrackLinks")); - desc.add("gsfTracks", edm::InputTag("lowPtGsfEleGsfTracks")); - descriptions.add("lowPtGsfLinksDefault", desc); + edm::ParameterSetDescription desc; + desc.add("PFCandidates", edm::InputTag("particleFlow")); + desc.add("packedCandidates", edm::InputTag("packedPFCandidates")); + desc.add("lostTracks", edm::InputTag("lostTracks")); + desc.add("tracks", edm::InputTag("generalTracks")); + desc.add("gsfToTrack", edm::InputTag("lowPtGsfToTrackLinks")); + desc.add("gsfTracks", edm::InputTag("lowPtGsfEleGsfTracks")); + desc.add("electrons", edm::InputTag("selectedPatLowPtElectrons")); + descriptions.add("lowPtGsfLinksDefault", desc); } DEFINE_FWK_MODULE(LowPtGSFToPackedCandidateLinker); diff --git a/PhysicsTools/PatAlgos/python/producersLayer1/lowPtElectronProducer_cff.py b/PhysicsTools/PatAlgos/python/producersLayer1/lowPtElectronProducer_cff.py index b64a33f7a3e3f..f6f745d01b956 100644 --- a/PhysicsTools/PatAlgos/python/producersLayer1/lowPtElectronProducer_cff.py +++ b/PhysicsTools/PatAlgos/python/producersLayer1/lowPtElectronProducer_cff.py @@ -11,42 +11,49 @@ ) patLowPtElectrons = patElectrons.clone( - # input collections + + # Input collection electronSource = sourceElectrons, - genParticleMatch = cms.InputTag("lowPtElectronMatch"), - # overrides - addElectronID = cms.bool(False), - addGenMatch = cms.bool(True), - addMVAVariables = cms.bool(False), - addPFClusterIso = cms.bool(False), - electronIDSources = cms.PSet(), - computeMiniIso = cms.bool(False), - isoDeposits = cms.PSet(), - isolationValues = cms.PSet(), - isolationValuesNoPFId = cms.PSet(), - miniIsoParamsB = cms.vdouble(), - miniIsoParamsE = cms.vdouble(), - usePfCandidateMultiMap = cms.bool(False), - # embedding - embedBasicClusters = cms.bool(False), - embedGenMatch = cms.bool(False), - embedGsfElectronCore = cms.bool(False), - embedGsfTrack = cms.bool(False), - embedHighLevelSelection = cms.bool(False), - embedPFCandidate = cms.bool(False), - embedPflowBasicClusters = cms.bool(False), - embedPflowPreshowerClusters = cms.bool(False), - embedPflowSuperCluster = cms.bool(False), - embedPreshowerClusters = cms.bool(False), - embedRecHits = cms.bool(False), - embedSeedCluster = cms.bool(False), - embedSuperCluster = cms.bool(False), - embedTrack = cms.bool(True), - ) + + # MC matching + genParticleMatch = "lowPtElectronMatch", + + # Electron ID + addElectronID = True, + electronIDSources = dict( + unbiased = cms.InputTag("rekeyLowPtGsfElectronSeedValueMaps:unbiased"), + ptbiased = cms.InputTag("rekeyLowPtGsfElectronSeedValueMaps:ptbiased"), + ID = cms.InputTag("lowPtGsfElectronID"), + ), + + # Embedding of RECO/AOD items + + # Embedding of RECO/AOD items + embedTrack = True, + embedGsfElectronCore = True, + embedGsfTrack = True, + embedSuperCluster = True, + embedSeedCluster = True, + embedBasicClusters = True, + embedPreshowerClusters = False, + embedRecHits = False, + embedPflowSuperCluster = False, + embedPflowBasicClusters = False, + embedPflowPreshowerClusters = False, + embedPFCandidate = False, + + # Miscellaneous flags + addMVAVariables = False, + embedHighLevelSelection = False, + isoDeposits = cms.PSet(), + isolationValues = cms.PSet(), + isolationValuesNoPFId = cms.PSet(), + +) makePatLowPtElectronsTask = cms.Task( lowPtElectronMatch, - patLowPtElectrons + patLowPtElectrons, ) makePatLowPtElectrons = cms.Sequence(makePatLowPtElectronsTask) @@ -61,3 +68,12 @@ electronSource = "gedGsfElectrons", genParticleMatch = "electronMatch" ) + +# Schedule rekeying of seed BDT ValueMaps by reco::GsfElectron for run2_miniAOD_UL +from Configuration.ProcessModifiers.run2_miniAOD_UL_cff import run2_miniAOD_UL +from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronSeedValueMaps_cff import rekeyLowPtGsfElectronSeedValueMaps +from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronID_cfi import lowPtGsfElectronID +_makePatLowPtElectronsTask = makePatLowPtElectronsTask.copy() +_makePatLowPtElectronsTask.add(rekeyLowPtGsfElectronSeedValueMaps) +_makePatLowPtElectronsTask.add(lowPtGsfElectronID) +run2_miniAOD_UL.toReplaceWith(makePatLowPtElectronsTask,_makePatLowPtElectronsTask) diff --git a/PhysicsTools/PatAlgos/python/producersLayer1/patCandidates_cff.py b/PhysicsTools/PatAlgos/python/producersLayer1/patCandidates_cff.py index 436e4504b1c58..d5f030c665c64 100644 --- a/PhysicsTools/PatAlgos/python/producersLayer1/patCandidates_cff.py +++ b/PhysicsTools/PatAlgos/python/producersLayer1/patCandidates_cff.py @@ -34,8 +34,17 @@ makePatJetsTask, makePatMETsTask ) + patCandidates = cms.Sequence(patCandidateSummary, patCandidatesTask) from Configuration.Eras.Modifier_pp_on_AA_2018_cff import pp_on_AA_2018 pp_on_AA_2018.toReplaceWith(patCandidatesTask, patCandidatesTask.copyAndExclude([makePatOOTPhotonsTask])) pp_on_AA_2018.toModify(patCandidateSummary.candidates, func = lambda list: list.remove(cms.InputTag("patOOTPhotons")) ) + +from Configuration.Eras.Modifier_run2_miniAOD_94XFall17_cff import run2_miniAOD_94XFall17 +from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy +_mAOD = (run2_miniAOD_94XFall17 | run2_miniAOD_80XLegacy) +(pp_on_AA_2018 | _mAOD).toReplaceWith(patCandidatesTask, + patCandidatesTask.copyAndExclude([makePatLowPtElectronsTask])) +(pp_on_AA_2018 | _mAOD).toModify(patCandidateSummary.candidates, + func = lambda list: list.remove(cms.InputTag("patLowPtElectrons")) ) diff --git a/PhysicsTools/PatAlgos/python/selectionLayer1/lowPtElectronSelector_cfi.py b/PhysicsTools/PatAlgos/python/selectionLayer1/lowPtElectronSelector_cfi.py index 17b510bf0b51b..7ea6b50afd8b8 100644 --- a/PhysicsTools/PatAlgos/python/selectionLayer1/lowPtElectronSelector_cfi.py +++ b/PhysicsTools/PatAlgos/python/selectionLayer1/lowPtElectronSelector_cfi.py @@ -6,9 +6,13 @@ # selectedPatLowPtElectrons = cms.EDFilter("PATElectronSelector", src = cms.InputTag("patLowPtElectrons"), - cut = cms.string("") + cut = cms.string("pt>1. && electronID('ID')>1.5"), ) +# Modifier for bParking (fully open selection) +from Configuration.Eras.Modifier_bParking_cff import bParking +bParking.toModify(selectedPatLowPtElectrons,cut = "") + # Modifiers for legacy AOD from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy from Configuration.Eras.Modifier_run2_miniAOD_94XFall17_cff import run2_miniAOD_94XFall17 diff --git a/PhysicsTools/PatAlgos/python/selectionLayer1/selectedPatCandidates_cff.py b/PhysicsTools/PatAlgos/python/selectionLayer1/selectedPatCandidates_cff.py index 8521d05a34ada..674fcc7af1aec 100644 --- a/PhysicsTools/PatAlgos/python/selectionLayer1/selectedPatCandidates_cff.py +++ b/PhysicsTools/PatAlgos/python/selectionLayer1/selectedPatCandidates_cff.py @@ -38,3 +38,11 @@ from Configuration.Eras.Modifier_pp_on_AA_2018_cff import pp_on_AA_2018 pp_on_AA_2018.toReplaceWith(selectedPatCandidatesTask, selectedPatCandidatesTask.copyAndExclude([selectedPatOOTPhotons])) pp_on_AA_2018.toModify(selectedPatCandidateSummary.candidates, func = lambda list: list.remove(cms.InputTag("selectedPatOOTPhotons")) ) + +from Configuration.Eras.Modifier_run2_miniAOD_94XFall17_cff import run2_miniAOD_94XFall17 +from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy +_mAOD = (run2_miniAOD_94XFall17 | run2_miniAOD_80XLegacy) +(pp_on_AA_2018 | _mAOD).toReplaceWith(selectedPatCandidatesTask, + selectedPatCandidatesTask.copyAndExclude([selectedPatLowPtElectrons])) +(pp_on_AA_2018 | _mAOD).toModify(selectedPatCandidateSummary.candidates, + func = lambda list: list.remove(cms.InputTag("selectedPatLowPtElectrons")) ) diff --git a/PhysicsTools/PatAlgos/python/slimming/slimmedLowPtElectrons_cff.py b/PhysicsTools/PatAlgos/python/slimming/slimmedLowPtElectrons_cff.py new file mode 100644 index 0000000000000..73e67d9d1a08c --- /dev/null +++ b/PhysicsTools/PatAlgos/python/slimming/slimmedLowPtElectrons_cff.py @@ -0,0 +1,11 @@ +import FWCore.ParameterSet.Config as cms + +from PhysicsTools.PatAlgos.slimming.slimmedLowPtElectrons_cfi import slimmedLowPtElectrons +from PhysicsTools.PatAlgos.slimming.lowPtGsfLinks_cfi import lowPtGsfLinks +from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronID_cfi import lowPtGsfElectronID + +# Task +slimmedLowPtElectronsTask = cms.Task( + lowPtGsfLinks, + slimmedLowPtElectrons, +) diff --git a/PhysicsTools/PatAlgos/python/slimming/slimmedLowPtElectrons_cfi.py b/PhysicsTools/PatAlgos/python/slimming/slimmedLowPtElectrons_cfi.py index 1095a37703ca2..684512a4ce0fd 100644 --- a/PhysicsTools/PatAlgos/python/slimming/slimmedLowPtElectrons_cfi.py +++ b/PhysicsTools/PatAlgos/python/slimming/slimmedLowPtElectrons_cfi.py @@ -20,7 +20,26 @@ saveNonZSClusterShapes = cms.string("1"), # save additional user floats: (sigmaIetaIeta,sigmaIphiIphi,sigmaIetaIphi,r9,e1x5_over_e5x5)_NoZS reducedBarrelRecHitCollection = cms.InputTag("reducedEcalRecHitsEB"), reducedEndcapRecHitCollection = cms.InputTag("reducedEcalRecHitsEE"), - modifyElectrons = cms.bool(False), - modifierConfig = cms.PSet( modifications = cms.VPSet() ) + modifyElectrons = cms.bool(True), + modifierConfig = cms.PSet( + modifications = cms.VPSet( + cms.PSet( + electron_config = cms.PSet( + ele2packed = cms.InputTag("lowPtGsfLinks:ele2packed"), + electronSrc = cms.InputTag("selectedPatLowPtElectrons"), + ), + modifierName = cms.string('EGExtraInfoModifierFromPackedCandPtrValueMaps'), + photon_config = cms.PSet() + ), + cms.PSet( + electron_config = cms.PSet( + ele2lost = cms.InputTag("lowPtGsfLinks:ele2lost"), + electronSrc = cms.InputTag("selectedPatLowPtElectrons"), + ), + modifierName = cms.string('EGExtraInfoModifierFromPackedCandPtrValueMaps'), + photon_config = cms.PSet() + ), + ) + ) ) diff --git a/PhysicsTools/PatAlgos/python/slimming/slimming_cff.py b/PhysicsTools/PatAlgos/python/slimming/slimming_cff.py index f774236d2b476..81c69b447ed5a 100644 --- a/PhysicsTools/PatAlgos/python/slimming/slimming_cff.py +++ b/PhysicsTools/PatAlgos/python/slimming/slimming_cff.py @@ -13,8 +13,7 @@ from PhysicsTools.PatAlgos.slimming.slimmedCaloJets_cfi import * from PhysicsTools.PatAlgos.slimming.slimmedGenJets_cfi import * from PhysicsTools.PatAlgos.slimming.slimmedElectrons_cfi import * -from PhysicsTools.PatAlgos.slimming.slimmedLowPtElectrons_cfi import * -from PhysicsTools.PatAlgos.slimming.lowPtGsfLinks_cfi import * +from PhysicsTools.PatAlgos.slimming.slimmedLowPtElectrons_cff import * from PhysicsTools.PatAlgos.slimming.slimmedTrackExtras_cff import * from PhysicsTools.PatAlgos.slimming.slimmedMuons_cfi import * from PhysicsTools.PatAlgos.slimming.slimmedPhotons_cfi import * @@ -45,8 +44,7 @@ slimmedGenJets, slimmedGenJetsAK8, slimmedElectrons, - slimmedLowPtElectrons, - lowPtGsfLinks, + slimmedLowPtElectronsTask, slimmedMuonTrackExtras, slimmedMuons, slimmedPhotons, @@ -66,6 +64,12 @@ from Configuration.Eras.Modifier_pp_on_AA_2018_cff import pp_on_AA_2018 pp_on_AA_2018.toReplaceWith(slimmingTask, slimmingTask.copyAndExclude([slimmedOOTPhotons])) +from Configuration.Eras.Modifier_run2_miniAOD_94XFall17_cff import run2_miniAOD_94XFall17 +from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy +_mAOD = (run2_miniAOD_94XFall17 | run2_miniAOD_80XLegacy) +(pp_on_AA_2018 | _mAOD).toReplaceWith(slimmingTask, + slimmingTask.copyAndExclude([slimmedLowPtElectronsTask])) + from Configuration.Eras.Modifier_phase2_timing_cff import phase2_timing _phase2_timing_slimmingTask = cms.Task(slimmingTask.copy(), offlineSlimmedPrimaryVertices4D) diff --git a/PhysicsTools/PatAlgos/test/IntegrationTest_cfg.py b/PhysicsTools/PatAlgos/test/IntegrationTest_cfg.py index 4808105fcf8fa..fa1bd5897bfd7 100644 --- a/PhysicsTools/PatAlgos/test/IntegrationTest_cfg.py +++ b/PhysicsTools/PatAlgos/test/IntegrationTest_cfg.py @@ -22,6 +22,7 @@ process.selectedPatCandidates ) +process.patLowPtElectrons.addElectronID = False process.patLowPtElectrons.electronSource = "gedGsfElectrons" process.patLowPtElectrons.genParticleMatch = "electronMatch" process.selectedPatLowPtElectrons.cut = "pt>99999." diff --git a/PhysicsTools/PatAlgos/test/patTuple_addTriggerInfo_cfg.py b/PhysicsTools/PatAlgos/test/patTuple_addTriggerInfo_cfg.py index 313f0465bb950..9e7c2fe6ffa7e 100644 --- a/PhysicsTools/PatAlgos/test/patTuple_addTriggerInfo_cfg.py +++ b/PhysicsTools/PatAlgos/test/patTuple_addTriggerInfo_cfg.py @@ -18,6 +18,7 @@ process.selectedPatCandidates ) +process.patLowPtElectrons.addElectronID = False process.patLowPtElectrons.electronSource = "gedGsfElectrons" process.patLowPtElectrons.genParticleMatch = "electronMatch" process.selectedPatLowPtElectrons.cut = "pt>99999." From 4c9c3943d2cebb45c82cbaacf1ed777f13e71417 Mon Sep 17 00:00:00 2001 From: bainbrid Date: Wed, 25 Nov 2020 18:47:22 +0100 Subject: [PATCH 05/21] add low-pT electrons to MINIAOD by default, modify collections in RECO/AOD and MINIAOD --- .../python/slimming/MicroEventContent_cff.py | 17 +++-------------- .../python/RecoEgamma_EventContent_cff.py | 4 ++-- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py b/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py index ae3ca344121b1..49dee70da9bc4 100644 --- a/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py +++ b/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py @@ -90,6 +90,9 @@ 'keep recoTracks_displacedStandAloneMuons__*', # L1 prefiring weights 'keep *_prefiringweight_*_*', + # patLowPtElectrons + 'keep *_slimmedLowPtElectrons_*_*', + 'keep *_gsfTracksOpenConversions_*_*', ) ) @@ -116,20 +119,6 @@ ) ) -# Only add low pT electrons for bParking era -from Configuration.Eras.Modifier_bParking_cff import bParking -_bParking_extraCommands = ['keep *_slimmedLowPtElectrons_*_*', - 'keep recoGsfElectronCores_lowPtGsfElectronCores_*_*', - 'keep recoSuperClusters_lowPtGsfElectronSuperClusters_*_*', - 'keep recoCaloClusters_lowPtGsfElectronSuperClusters_*_*', - 'keep recoGsfTracks_lowPtGsfEleGsfTracks_*_*', - 'keep floatedmValueMap_lowPtGsfElectronSeedValueMaps_*_*', - 'keep floatedmValueMap_lowPtGsfElectronID_*_*', - 'keep *_lowPtGsfLinks_*_*', - 'keep *_gsfTracksOpenConversions_*_*', - ] -bParking.toModify(MicroEventContent, outputCommands = MicroEventContent.outputCommands + _bParking_extraCommands) - # --- Only for 2018 data & MC _run2_HCAL_2018_extraCommands = ["keep *_packedPFCandidates_hcalDepthEnergyFractions_*"] from Configuration.Eras.Modifier_run2_HCAL_2018_cff import run2_HCAL_2018 diff --git a/RecoEgamma/Configuration/python/RecoEgamma_EventContent_cff.py b/RecoEgamma/Configuration/python/RecoEgamma_EventContent_cff.py index 908e887d2765a..14aa78239405a 100644 --- a/RecoEgamma/Configuration/python/RecoEgamma_EventContent_cff.py +++ b/RecoEgamma/Configuration/python/RecoEgamma_EventContent_cff.py @@ -168,8 +168,8 @@ 'keep *_lowPtGsfToTrackLinks_*_*', 'keep recoSuperClusters_lowPtGsfElectronSuperClusters_*_*', 'keep floatedmValueMap_lowPtGsfElectronSeedValueMaps_*_*', - 'keep floatedmValueMap_lowPtGsfElectronID_*_*', - ) + 'keep floatedmValueMap_rekeyLowPtGsfElectronSeedValueMaps_*_*', + 'keep floatedmValueMap_lowPtGsfElectronID_*_*') ) # mods for HGCAL From eeb7230d5406823f3609c654e36e2cb3a245271c Mon Sep 17 00:00:00 2001 From: bainbrid Date: Thu, 26 Nov 2020 01:00:53 +0100 Subject: [PATCH 06/21] revert to boost/filesystem --- CommonTools/MVAUtils/bin/convertXMLToGBRForestROOT.cc | 6 +++--- CommonTools/MVAUtils/src/GBRForestTools.cc | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CommonTools/MVAUtils/bin/convertXMLToGBRForestROOT.cc b/CommonTools/MVAUtils/bin/convertXMLToGBRForestROOT.cc index 3c7c9f5805fd7..9dcda320d01c2 100644 --- a/CommonTools/MVAUtils/bin/convertXMLToGBRForestROOT.cc +++ b/CommonTools/MVAUtils/bin/convertXMLToGBRForestROOT.cc @@ -2,7 +2,7 @@ #include "TFile.h" -#include +#include #include int main(int argc, char **argv) { @@ -14,12 +14,12 @@ int main(int argc, char **argv) { char *inputFileName = argv[1]; char *outputFileName = argv[2]; - if (!std::filesystem::exists(inputFileName)) { + if (!boost::filesystem::exists(inputFileName)) { std::cout << "Input file " << inputFileName << " does not exists." << std::endl; return 1; } - if (std::filesystem::exists(outputFileName)) { + if (boost::filesystem::exists(outputFileName)) { std::cout << "Output file " << outputFileName << " already exists." << std::endl; return 1; } diff --git a/CommonTools/MVAUtils/src/GBRForestTools.cc b/CommonTools/MVAUtils/src/GBRForestTools.cc index 18b366383e123..3234c6d41e37e 100644 --- a/CommonTools/MVAUtils/src/GBRForestTools.cc +++ b/CommonTools/MVAUtils/src/GBRForestTools.cc @@ -10,7 +10,6 @@ #include #include #include -#include namespace { From ceb38e6a471f42f74bb3f12abaf915ef5217c9b3 Mon Sep 17 00:00:00 2001 From: bainbrid Date: Thu, 26 Nov 2020 01:01:13 +0100 Subject: [PATCH 07/21] add missing lib --- RecoEgamma/EgammaElectronProducers/BuildFile.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/RecoEgamma/EgammaElectronProducers/BuildFile.xml b/RecoEgamma/EgammaElectronProducers/BuildFile.xml index 69d9727f84652..1484c2266539e 100644 --- a/RecoEgamma/EgammaElectronProducers/BuildFile.xml +++ b/RecoEgamma/EgammaElectronProducers/BuildFile.xml @@ -1,3 +1,4 @@ + From 6b29469b5d09d2e2ba138859e81f88bbed853d22 Mon Sep 17 00:00:00 2001 From: bainbrid Date: Wed, 2 Dec 2020 16:24:31 +0100 Subject: [PATCH 08/21] prevent copy of GBRForest after read --- CommonTools/MVAUtils/src/GBRForestTools.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CommonTools/MVAUtils/src/GBRForestTools.cc b/CommonTools/MVAUtils/src/GBRForestTools.cc index 3234c6d41e37e..979bf4ab140af 100644 --- a/CommonTools/MVAUtils/src/GBRForestTools.cc +++ b/CommonTools/MVAUtils/src/GBRForestTools.cc @@ -124,9 +124,7 @@ namespace { // if (reco::details::hasEnding(weightsFileFullPath, ".root")) { TFile gbrForestFile(weightsFileFullPath.c_str()); - // Use the copy-constructor of GBRForest to copy the GBRForest. - // In this way, the ROOT file can be closed. - return std::make_unique(*(GBRForest*)gbrForestFile.Get("gbrForest")); + return std::unique_ptr(reinterpret_cast(gbrForestFile.Get("gbrForest"))); } // From e87d57d4558dbff74e8fd22cc002fcc0bee9420c Mon Sep 17 00:00:00 2001 From: bainbrid Date: Wed, 2 Dec 2020 16:25:01 +0100 Subject: [PATCH 09/21] switch to fixedGridRhoFastjetAll, tidy up --- .../plugins/LowPtGsfElectronIDProducer.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc index 4bd7ec2656528..6b2d8cf39a3c2 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc @@ -1,7 +1,8 @@ +#include "CommonTools/BaseParticlePropagator/interface/BaseParticlePropagator.h" #include "DataFormats/Common/interface/Handle.h" +#include "DataFormats/Common/interface/Ptr.h" #include "DataFormats/Common/interface/ValueMap.h" -#include "DataFormats/EgammaCandidates/interface/GsfElectron.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "DataFormats/Common/interface/View.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" #include "FWCore/Utilities/interface/InputTag.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" @@ -131,10 +132,10 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const output[iname][iele] = eval(names_[iname], ele, *rho, unbiased, zfield.z()); } } - + // Create and put ValueMap in Event - for ( unsigned int iname = 0; iname < names_.size(); ++iname ) { - auto ptr = std::make_unique< edm::ValueMap >( edm::ValueMap() ); + for (unsigned int iname = 0; iname < names_.size(); ++iname) { + auto ptr = std::make_unique >(edm::ValueMap()); edm::ValueMap::Filler filler(*ptr); filler.insert(electrons, output[iname].begin(), output[iname].end()); filler.fill(); @@ -159,17 +160,16 @@ double LowPtGsfElectronIDProducer::eval( } else { throw cms::Exception("Unknown model name") << "'Name given: '" << name << "'. Check against configuration file.\n"; } - + return 0.; } ////////////////////////////////////////////////////////////////////////////////////////// // -void LowPtGsfElectronIDProducer::fillDescriptions( edm::ConfigurationDescriptions& descriptions ) -{ +void LowPtGsfElectronIDProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; desc.add("electrons", edm::InputTag("lowPtGsfElectrons")); desc.add("unbiased", edm::InputTag("lowPtGsfElectronSeedValueMaps:unbiased")); - desc.add("rho", edm::InputTag("fixedGridRhoFastjetAllTmp")); + desc.add("rho", edm::InputTag("fixedGridRhoFastjetAll")); desc.add >("ModelNames", {""}); desc.add >( "ModelWeights", {"RecoEgamma/ElectronIdentification/data/LowPtElectrons/LowPtElectrons_ID_2020Sept15.root"}); From 3ebcce3a1112785e1199333340efceef5faf22a9 Mon Sep 17 00:00:00 2001 From: bainbrid Date: Wed, 2 Dec 2020 16:25:19 +0100 Subject: [PATCH 10/21] remove obsolete headers --- .../plugins/LowPtGsfElectronIDProducer.h | 45 ------------------- .../LowPtGsfElectronSeedValueMapsProducer.h | 33 -------------- 2 files changed, 78 deletions(-) delete mode 100644 RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.h delete mode 100644 RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedValueMapsProducer.h diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.h b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.h deleted file mode 100644 index 2589ce9d1a8e8..0000000000000 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef RecoEgamma_EgammaElectronProducers_LowPtGsfElectronIDProducer_h -#define RecoEgamma_EgammaElectronProducers_LowPtGsfElectronIDProducer_h - -#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h" -#include "FWCore/Framework/interface/ESHandle.h" -#include "FWCore/Framework/interface/stream/EDProducer.h" -#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" -#include "RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronIDHeavyObjectCache.h" -#include -#include - -class LowPtGsfElectronIDProducer final : -public edm::stream::EDProducer< edm::GlobalCache > { - - public: - - explicit LowPtGsfElectronIDProducer( const edm::ParameterSet&, - const lowptgsfeleid::HeavyObjectCache* ); - - ~LowPtGsfElectronIDProducer() override; - - static std::unique_ptr - initializeGlobalCache( const edm::ParameterSet& conf ) { - return std::make_unique(lowptgsfeleid::HeavyObjectCache(conf)); - } - - static void globalEndJob( lowptgsfeleid::HeavyObjectCache const* ) {} - - void produce( edm::Event&, const edm::EventSetup& ) override; - - static void fillDescriptions( edm::ConfigurationDescriptions& ); - - private: - - const edm::EDGetTokenT gsfElectrons_; - const edm::EDGetTokenT rho_; - const std::vector names_; - const bool passThrough_; - const double minPtThreshold_; - const double maxPtThreshold_; - -}; - -#endif // RecoEgamma_EgammaElectronProducers_LowPtGsfElectronIDProducer_h - diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedValueMapsProducer.h b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedValueMapsProducer.h deleted file mode 100644 index 28f70374e5510..0000000000000 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedValueMapsProducer.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef RecoEgamma_EgammaElectronProducers_LowPtGsfElectronSeedValueMapsProducer_h -#define RecoEgamma_EgammaElectronProducers_LowPtGsfElectronSeedValueMapsProducer_h - -#include "DataFormats/Common/interface/ValueMap.h" -#include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h" -#include "DataFormats/ParticleFlowReco/interface/PreIdFwd.h" -#include "FWCore/Framework/interface/ESHandle.h" -#include "FWCore/Framework/interface/stream/EDProducer.h" -#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" -#include -#include - -class LowPtGsfElectronSeedValueMapsProducer : public edm::stream::EDProducer<> { - - public: - - explicit LowPtGsfElectronSeedValueMapsProducer( const edm::ParameterSet& ); - - ~LowPtGsfElectronSeedValueMapsProducer() override; - - void produce( edm::Event&, const edm::EventSetup& ) override; - - static void fillDescriptions( edm::ConfigurationDescriptions& ); - - private: - - const edm::EDGetTokenT gsfTracks_; - const edm::EDGetTokenT< edm::ValueMap > preIdsValueMap_; - const std::vector names_; - -}; - -#endif // RecoEgamma_EgammaElectronProducers_LowPtGsfElectronSeedValueMapsProducer_h From af519cf2448313e055022047d9ebe5471dd95ca8 Mon Sep 17 00:00:00 2001 From: bainbrid Date: Wed, 2 Dec 2020 16:27:09 +0100 Subject: [PATCH 11/21] bug fix concerning BaseParticlePropagator usage; removed lowptgsfeleseed::features method --- .../interface/LowPtGsfElectronFeatures.h | 10 -- .../src/LowPtGsfElectronFeatures.cc | 130 +----------------- 2 files changed, 4 insertions(+), 136 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h b/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h index 89e81b2b60d17..469a8d16b89b7 100644 --- a/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h +++ b/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h @@ -11,16 +11,6 @@ #include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h" #include -namespace lowptgsfeleseed { - - std::vector features(const reco::PreId& ecal, - const reco::PreId& hcal, - double rho, - const reco::BeamSpot& spot, - noZS::EcalClusterLazyTools& ecalTools); - -} - namespace lowptgsfeleid { // feature list for new model (2019Sept15) diff --git a/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc b/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc index eab8b00884abe..7f6f5636d9037 100644 --- a/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc +++ b/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc @@ -8,126 +8,6 @@ #include "TVector3.h" #include -namespace lowptgsfeleseed { - - //////////////////////////////////////////////////////////////////////////////// - // - std::vector features(const reco::PreId& ecal, - const reco::PreId& hcal, - double rho, - const reco::BeamSpot& spot, - noZS::EcalClusterLazyTools& tools) { - float trk_pt_ = -1.; - float trk_eta_ = -1.; - float trk_phi_ = -1.; - float trk_p_ = -1.; - float trk_nhits_ = -1.; - float trk_high_quality_ = -1.; - float trk_chi2red_ = -1.; - float rho_ = -1.; - float ktf_ecal_cluster_e_ = -1.; - float ktf_ecal_cluster_deta_ = -42.; - float ktf_ecal_cluster_dphi_ = -42.; - float ktf_ecal_cluster_e3x3_ = -1.; - float ktf_ecal_cluster_e5x5_ = -1.; - float ktf_ecal_cluster_covEtaEta_ = -42.; - float ktf_ecal_cluster_covEtaPhi_ = -42.; - float ktf_ecal_cluster_covPhiPhi_ = -42.; - float ktf_ecal_cluster_r9_ = -0.1; - float ktf_ecal_cluster_circularity_ = -0.1; - float ktf_hcal_cluster_e_ = -1.; - float ktf_hcal_cluster_deta_ = -42.; - float ktf_hcal_cluster_dphi_ = -42.; - float preid_gsf_dpt_ = -1.; - float preid_trk_gsf_chiratio_ = -1.; - float preid_gsf_chi2red_ = -1.; - float trk_dxy_sig_ = -1.; // must be last (not used by unbiased model) - - // Tracks - const auto& trk = ecal.trackRef(); // reco::TrackRef - if (trk.isNonnull()) { - trk_pt_ = trk->pt(); - trk_eta_ = trk->eta(); - trk_phi_ = trk->phi(); - trk_p_ = trk->p(); - trk_nhits_ = static_cast(trk->found()); - trk_high_quality_ = static_cast(trk->quality(reco::TrackBase::qualityByName("highPurity"))); - trk_chi2red_ = trk->normalizedChi2(); - if (trk->dxy(spot) > 0.) { - trk_dxy_sig_ = trk->dxyError() / trk->dxy(spot); //@@ to be consistent with the training based on 94X MC - } - ktf_ecal_cluster_dphi_ *= trk->charge(); //@@ to be consistent with the training based on 94X MC - } - - // Rho - rho_ = static_cast(rho); - - // ECAL clusters - const auto& ecal_clu = ecal.clusterRef(); // reco::PFClusterRef - if (ecal_clu.isNonnull()) { - ktf_ecal_cluster_e_ = ecal_clu->energy(); - ktf_ecal_cluster_deta_ = ecal.geomMatching()[0]; - ktf_ecal_cluster_dphi_ = ecal.geomMatching()[1]; - ktf_ecal_cluster_e3x3_ = tools.e3x3(*ecal_clu); - ktf_ecal_cluster_e5x5_ = tools.e5x5(*ecal_clu); - const auto& covs = tools.localCovariances(*ecal_clu); - ktf_ecal_cluster_covEtaEta_ = covs[0]; - ktf_ecal_cluster_covEtaPhi_ = covs[1]; - ktf_ecal_cluster_covPhiPhi_ = covs[2]; - if (ktf_ecal_cluster_e_ > 0.) { - ktf_ecal_cluster_r9_ = ktf_ecal_cluster_e3x3_ / ktf_ecal_cluster_e_; - } - if (ktf_ecal_cluster_e5x5_ > 0.) { - ktf_ecal_cluster_circularity_ = 1. - tools.e1x5(*ecal_clu) / ktf_ecal_cluster_e5x5_; - } else { - ktf_ecal_cluster_circularity_ = -0.1; - } - } - - // HCAL clusters - const auto& hcal_clu = hcal.clusterRef(); // reco::PFClusterRef - if (hcal_clu.isNonnull()) { - ktf_hcal_cluster_e_ = hcal_clu->energy(); - ktf_hcal_cluster_deta_ = hcal.geomMatching()[0]; - ktf_hcal_cluster_dphi_ = hcal.geomMatching()[1]; - } - - // PreId - preid_gsf_dpt_ = ecal.dpt(); - preid_trk_gsf_chiratio_ = ecal.chi2Ratio(); - preid_gsf_chi2red_ = ecal.gsfChi2(); - - // Set contents of vector - std::vector output = {trk_pt_, - trk_eta_, - trk_phi_, - trk_p_, - trk_nhits_, - trk_high_quality_, - trk_chi2red_, - rho_, - ktf_ecal_cluster_e_, - ktf_ecal_cluster_deta_, - ktf_ecal_cluster_dphi_, - ktf_ecal_cluster_e3x3_, - ktf_ecal_cluster_e5x5_, - ktf_ecal_cluster_covEtaEta_, - ktf_ecal_cluster_covEtaPhi_, - ktf_ecal_cluster_covPhiPhi_, - ktf_ecal_cluster_r9_, - ktf_ecal_cluster_circularity_, - ktf_hcal_cluster_e_, - ktf_hcal_cluster_deta_, - ktf_hcal_cluster_dphi_, - preid_gsf_dpt_, - preid_trk_gsf_chiratio_, - preid_gsf_chi2red_, - trk_dxy_sig_}; - return output; - }; - -} // namespace lowptgsfeleseed - namespace lowptgsfeleid { std::vector features_V1(reco::GsfElectron const& ele, float rho, float unbiased, float field_z) { @@ -239,14 +119,12 @@ namespace lowptgsfeleid { float energy = sqrt(mass2 + p2); XYZTLorentzVector mom = XYZTLorentzVector(gsf->px(), gsf->py(), gsf->pz(), energy); XYZTLorentzVector pos = XYZTLorentzVector(gsf->vx(), gsf->vy(), gsf->vz(), 0.); - RawParticle particle(mom, pos); - BaseParticlePropagator propagator(particle, 0., 0., field_z); - particle.setCharge(gsf->charge()); + BaseParticlePropagator propagator(RawParticle(mom, pos, gsf->charge()), 0, 0, field_z); + propagator.propagateToEcalEntrance(true); // true only first half loop , false more than one loop bool reach_ECAL = propagator.getSuccess(); // 0 does not reach ECAL, 1 yes barrel, 2 yes endcaps - GlobalPoint ecal_pos(particle.x(), // ECAL entry point for track - particle.y(), - particle.z()); + // ECAL entry point for track + GlobalPoint ecal_pos(propagator.particle().x(), propagator.particle().y(), propagator.particle().z()); // Track-cluster matching for most energetic clusters sc_clus1_nxtal = -999; From dcfdd0181c5bcedf967cb2a1d331edfe4d0ab928 Mon Sep 17 00:00:00 2001 From: bainbrid Date: Wed, 2 Dec 2020 16:33:36 +0100 Subject: [PATCH 12/21] scram build code-format --- .../LowPtGSFToPackedCandidateLinker.cc | 12 +++---- .../LowPtGsfElectronSeedValueMapsProducer.cc | 4 +-- .../src/LowPtGsfElectronFeatures.cc | 2 +- .../EGExtraInfoModifierFromValueMaps.cc | 34 +++++++++---------- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/PhysicsTools/PatAlgos/plugins/LowPtGSFToPackedCandidateLinker.cc b/PhysicsTools/PatAlgos/plugins/LowPtGSFToPackedCandidateLinker.cc index 9dc3a049ffe69..a82b2fd3ac561 100644 --- a/PhysicsTools/PatAlgos/plugins/LowPtGSFToPackedCandidateLinker.cc +++ b/PhysicsTools/PatAlgos/plugins/LowPtGSFToPackedCandidateLinker.cc @@ -25,12 +25,12 @@ typedef std::vector PackedCandidatePtrCollection; class LowPtGSFToPackedCandidateLinker : public edm::global::EDProducer<> { public: - explicit LowPtGSFToPackedCandidateLinker(const edm::ParameterSet&); - ~LowPtGSFToPackedCandidateLinker() override; - - void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; - static void fillDescriptions(edm::ConfigurationDescriptions&); - + explicit LowPtGSFToPackedCandidateLinker(const edm::ParameterSet&); + ~LowPtGSFToPackedCandidateLinker() override; + + void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; + static void fillDescriptions(edm::ConfigurationDescriptions&); + private: const edm::EDGetTokenT pfcands_; const edm::EDGetTokenT packed_; diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedValueMapsProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedValueMapsProducer.cc index ef7cdc2443037..876b71a6a143b 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedValueMapsProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedValueMapsProducer.cc @@ -136,13 +136,11 @@ void LowPtGsfElectronSeedValueMapsProducer::produce(edm::Event& event, const edm event.put(std::move(ptr), names_[idx]); } } - } ////////////////////////////////////////////////////////////////////////////////////////// // -void LowPtGsfElectronSeedValueMapsProducer::fillDescriptions( edm::ConfigurationDescriptions& descriptions ) -{ +void LowPtGsfElectronSeedValueMapsProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; desc.add("gsfTracks", edm::InputTag("lowPtGsfEleGsfTracks")); desc.add("preIdsValueMap", edm::InputTag("lowPtGsfElectronSeeds")); diff --git a/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc b/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc index 7f6f5636d9037..5ab6abae8129a 100644 --- a/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc +++ b/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc @@ -119,7 +119,7 @@ namespace lowptgsfeleid { float energy = sqrt(mass2 + p2); XYZTLorentzVector mom = XYZTLorentzVector(gsf->px(), gsf->py(), gsf->pz(), energy); XYZTLorentzVector pos = XYZTLorentzVector(gsf->vx(), gsf->vy(), gsf->vz(), 0.); - BaseParticlePropagator propagator(RawParticle(mom, pos, gsf->charge()), 0, 0, field_z); + BaseParticlePropagator propagator(RawParticle(mom, pos, gsf->charge()), 0, 0, field_z); propagator.propagateToEcalEntrance(true); // true only first half loop , false more than one loop bool reach_ECAL = propagator.getSuccess(); // 0 does not reach ECAL, 1 yes barrel, 2 yes endcaps diff --git a/RecoEgamma/EgammaTools/plugins/EGExtraInfoModifierFromValueMaps.cc b/RecoEgamma/EgammaTools/plugins/EGExtraInfoModifierFromValueMaps.cc index 62b2461991e0a..03c12943026c4 100644 --- a/RecoEgamma/EgammaTools/plugins/EGExtraInfoModifierFromValueMaps.cc +++ b/RecoEgamma/EgammaTools/plugins/EGExtraInfoModifierFromValueMaps.cc @@ -3,41 +3,39 @@ using EGExtraInfoModifierFromFloatValueMaps = EGExtraInfoModifierFromValueMaps; DEFINE_EDM_PLUGIN(ModifyObjectValueFactory, - EGExtraInfoModifierFromFloatValueMaps, - "EGExtraInfoModifierFromFloatValueMaps"); + EGExtraInfoModifierFromFloatValueMaps, + "EGExtraInfoModifierFromFloatValueMaps"); using EGExtraInfoModifierFromIntValueMaps = EGExtraInfoModifierFromValueMaps; -DEFINE_EDM_PLUGIN(ModifyObjectValueFactory, - EGExtraInfoModifierFromIntValueMaps, - "EGExtraInfoModifierFromIntValueMaps"); +DEFINE_EDM_PLUGIN(ModifyObjectValueFactory, EGExtraInfoModifierFromIntValueMaps, "EGExtraInfoModifierFromIntValueMaps"); using EGExtraInfoModifierFromBoolValueMaps = EGExtraInfoModifierFromValueMaps; DEFINE_EDM_PLUGIN(ModifyObjectValueFactory, - EGExtraInfoModifierFromBoolValueMaps, - "EGExtraInfoModifierFromBoolValueMaps"); + EGExtraInfoModifierFromBoolValueMaps, + "EGExtraInfoModifierFromBoolValueMaps"); -using EGExtraInfoModifierFromBoolToIntValueMaps = EGExtraInfoModifierFromValueMaps; +using EGExtraInfoModifierFromBoolToIntValueMaps = EGExtraInfoModifierFromValueMaps; DEFINE_EDM_PLUGIN(ModifyObjectValueFactory, - EGExtraInfoModifierFromBoolToIntValueMaps, - "EGExtraInfoModifierFromBoolToIntValueMaps"); + EGExtraInfoModifierFromBoolToIntValueMaps, + "EGExtraInfoModifierFromBoolToIntValueMaps"); using EGExtraInfoModifierFromUIntValueMaps = EGExtraInfoModifierFromValueMaps; DEFINE_EDM_PLUGIN(ModifyObjectValueFactory, - EGExtraInfoModifierFromUIntValueMaps, - "EGExtraInfoModifierFromUIntValueMaps"); + EGExtraInfoModifierFromUIntValueMaps, + "EGExtraInfoModifierFromUIntValueMaps"); -using EGExtraInfoModifierFromUIntToIntValueMaps = EGExtraInfoModifierFromValueMaps; +using EGExtraInfoModifierFromUIntToIntValueMaps = EGExtraInfoModifierFromValueMaps; DEFINE_EDM_PLUGIN(ModifyObjectValueFactory, - EGExtraInfoModifierFromUIntToIntValueMaps, - "EGExtraInfoModifierFromUIntToIntValueMaps"); + EGExtraInfoModifierFromUIntToIntValueMaps, + "EGExtraInfoModifierFromUIntToIntValueMaps"); #include "DataFormats/PatCandidates/interface/VIDCutFlowResult.h" using EGExtraInfoModifierFromVIDCutFlowResultValueMaps = EGExtraInfoModifierFromValueMaps; DEFINE_EDM_PLUGIN(ModifyObjectValueFactory, - EGExtraInfoModifierFromVIDCutFlowResultValueMaps, - "EGExtraInfoModifierFromVIDCutFlowResultValueMaps"); + EGExtraInfoModifierFromVIDCutFlowResultValueMaps, + "EGExtraInfoModifierFromVIDCutFlowResultValueMaps"); -using EGExtraInfoModifierFromEGIDValueMaps = EGExtraInfoModifierFromValueMaps; +using EGExtraInfoModifierFromEGIDValueMaps = EGExtraInfoModifierFromValueMaps; DEFINE_EDM_PLUGIN(ModifyObjectValueFactory, EGExtraInfoModifierFromEGIDValueMaps, "EGExtraInfoModifierFromEGIDValueMaps"); From 074b7e3aa7f6de81edbbdfe73b36495f1f184267 Mon Sep 17 00:00:00 2001 From: bainbrid Date: Thu, 3 Dec 2020 14:36:38 +0100 Subject: [PATCH 13/21] add rekeyLowPtGsfElectronSeedValueMaps to RECO and FEVT --- RecoEgamma/Configuration/python/RecoEgamma_EventContent_cff.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RecoEgamma/Configuration/python/RecoEgamma_EventContent_cff.py b/RecoEgamma/Configuration/python/RecoEgamma_EventContent_cff.py index 14aa78239405a..6f661aa503296 100644 --- a/RecoEgamma/Configuration/python/RecoEgamma_EventContent_cff.py +++ b/RecoEgamma/Configuration/python/RecoEgamma_EventContent_cff.py @@ -49,6 +49,7 @@ 'keep *_lowPtGsfToTrackLinks_*_*', 'keep recoSuperClusters_lowPtGsfElectronSuperClusters_*_*', 'keep floatedmValueMap_lowPtGsfElectronSeedValueMaps_*_*', + 'keep floatedmValueMap_rekeyLowPtGsfElectronSeedValueMaps_*_*', 'keep floatedmValueMap_lowPtGsfElectronID_*_*', ) ) @@ -114,6 +115,7 @@ 'keep *_lowPtGsfToTrackLinks_*_*', 'keep recoSuperClusters_lowPtGsfElectronSuperClusters_*_*', 'keep floatedmValueMap_lowPtGsfElectronSeedValueMaps_*_*', + 'keep floatedmValueMap_rekeyLowPtGsfElectronSeedValueMaps_*_*', 'keep floatedmValueMap_lowPtGsfElectronID_*_*', ) ) From ade0d0b86a578cd90486099cd7ed3cbdb90ae9e0 Mon Sep 17 00:00:00 2001 From: bainbrid Date: Sun, 6 Dec 2020 18:56:15 +0100 Subject: [PATCH 14/21] revert to original 'Autumn18' model for RECO, use 2020Sept15 for UL reminiAOD --- .../lowPtElectronProducer_cff.py | 20 +++++++++-- .../slimming/slimmedLowPtElectrons_cff.py | 1 - .../plugins/LowPtGsfElectronIDProducer.cc | 36 ++++++++++--------- .../python/lowPtGsfElectronSequence_cff.py | 2 +- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/PhysicsTools/PatAlgos/python/producersLayer1/lowPtElectronProducer_cff.py b/PhysicsTools/PatAlgos/python/producersLayer1/lowPtElectronProducer_cff.py index f6f745d01b956..9926a18ffd610 100644 --- a/PhysicsTools/PatAlgos/python/producersLayer1/lowPtElectronProducer_cff.py +++ b/PhysicsTools/PatAlgos/python/producersLayer1/lowPtElectronProducer_cff.py @@ -72,8 +72,24 @@ # Schedule rekeying of seed BDT ValueMaps by reco::GsfElectron for run2_miniAOD_UL from Configuration.ProcessModifiers.run2_miniAOD_UL_cff import run2_miniAOD_UL from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronSeedValueMaps_cff import rekeyLowPtGsfElectronSeedValueMaps -from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronID_cfi import lowPtGsfElectronID +from RecoEgamma.EgammaElectronProducers.defaultLowPtGsfElectronID_cfi import defaultLowPtGsfElectronID +run2_miniAOD_UL.toModify( + defaultLowPtGsfElectronID, + rho = "fixedGridRhoFastjetAll", + ModelNames = [''], + ModelWeights = ["RecoEgamma/ElectronIdentification/data/LowPtElectrons/LowPtElectrons_ID_2020Sept15.root"], + ModelThresholds = [-99.], + Version = "V1", +) +run2_miniAOD_UL.toModify( + patLowPtElectrons, + electronIDSources = dict( + unbiased = cms.InputTag("rekeyLowPtGsfElectronSeedValueMaps:unbiased"), + ptbiased = cms.InputTag("rekeyLowPtGsfElectronSeedValueMaps:ptbiased"), + ID = cms.InputTag("defaultLowPtGsfElectronID"), + ) +) _makePatLowPtElectronsTask = makePatLowPtElectronsTask.copy() _makePatLowPtElectronsTask.add(rekeyLowPtGsfElectronSeedValueMaps) -_makePatLowPtElectronsTask.add(lowPtGsfElectronID) +_makePatLowPtElectronsTask.add(defaultLowPtGsfElectronID) run2_miniAOD_UL.toReplaceWith(makePatLowPtElectronsTask,_makePatLowPtElectronsTask) diff --git a/PhysicsTools/PatAlgos/python/slimming/slimmedLowPtElectrons_cff.py b/PhysicsTools/PatAlgos/python/slimming/slimmedLowPtElectrons_cff.py index 73e67d9d1a08c..ab4d571e45864 100644 --- a/PhysicsTools/PatAlgos/python/slimming/slimmedLowPtElectrons_cff.py +++ b/PhysicsTools/PatAlgos/python/slimming/slimmedLowPtElectrons_cff.py @@ -2,7 +2,6 @@ from PhysicsTools.PatAlgos.slimming.slimmedLowPtElectrons_cfi import slimmedLowPtElectrons from PhysicsTools.PatAlgos.slimming.lowPtGsfLinks_cfi import lowPtGsfLinks -from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronID_cfi import lowPtGsfElectronID # Task slimmedLowPtElectronsTask = cms.Task( diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc index 6b2d8cf39a3c2..532effef0bbae 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc @@ -10,7 +10,7 @@ #include "FWCore/Framework/interface/global/EDProducer.h" #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" #include "CommonTools/MVAUtils/interface/GBRForestTools.h" -#include "DataFormats/EgammaCandidates/interface/GsfElectron.h" +#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h" #include "DataFormats/PatCandidates/interface/Electron.h" #include "DataFormats/EgammaReco/interface/SuperCluster.h" #include "DataFormats/GsfTrackReco/interface/GsfTrack.h" @@ -20,6 +20,7 @@ #include "MagneticField/Engine/interface/MagneticField.h" #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" #include "RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h" +#include "RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronIDHeavyObjectCache.h" #include #include @@ -35,9 +36,9 @@ class LowPtGsfElectronIDProducer final : public edm::global::EDProducer<> { private: double eval( - const std::string& name, const edm::Ptr&, double rho, float unbiased, float field_z) const; + const std::string& name, const reco::GsfElectronRef&, double rho, float unbiased, float field_z) const; - const edm::EDGetTokenT > electrons_; + const edm::EDGetTokenT electrons_; const edm::EDGetTokenT rho_; const edm::EDGetTokenT > unbiased_; const std::vector names_; @@ -52,7 +53,7 @@ class LowPtGsfElectronIDProducer final : public edm::global::EDProducer<> { //////////////////////////////////////////////////////////////////////////////// // LowPtGsfElectronIDProducer::LowPtGsfElectronIDProducer(const edm::ParameterSet& conf) - : electrons_(consumes >(conf.getParameter("electrons"))), + : electrons_(consumes(conf.getParameter("electrons"))), rho_(consumes(conf.getParameter("rho"))), unbiased_(consumes >(conf.getParameter("unbiased"))), names_(conf.getParameter >("ModelNames")), @@ -72,7 +73,7 @@ LowPtGsfElectronIDProducer::LowPtGsfElectronIDProducer(const edm::ParameterSet& throw cms::Exception("Incorrect configuration") << "'ModelWeights' size (" << models_.size() << ") != 'ModelThresholds' size (" << thresholds_.size() << ").\n"; } - if (version_ != "V0" && version_ != "V1") { + if (version_ != "V0" && version_ != "V1" && version_ != "") { throw cms::Exception("Incorrect configuration") << "Unknown Version: " << version_ << "\n"; } for (const auto& name : names_) { @@ -98,7 +99,7 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const } // Retrieve GsfElectrons from Event - edm::Handle > electrons; + edm::Handle electrons; event.getByToken(electrons_, electrons); if (!electrons.isValid()) { std::ostringstream os; @@ -116,7 +117,7 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const output.emplace_back(electrons->size(), -999.); } for (unsigned int iele = 0; iele < electrons->size(); iele++) { - edm::Ptr ele(electrons, iele); + reco::GsfElectronRef ele(electrons, iele); if (ele->core().isNull()) { continue; @@ -146,12 +147,16 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const ////////////////////////////////////////////////////////////////////////////////////////// // double LowPtGsfElectronIDProducer::eval( - const std::string& name, const edm::Ptr& ele, double rho, float unbiased, float field_z) const { + const std::string& name, const reco::GsfElectronRef& ele, double rho, float unbiased, float field_z) const { auto iter = std::find(names_.begin(), names_.end(), name); if (iter != names_.end()) { int index = std::distance(names_.begin(), iter); std::vector inputs; - if (version_ == "V0") { + if (version_ == "") { // Original XML model + lowptgsfeleid::Features features; + features.set(ele,rho); + inputs = features.get(); + } else if (version_ == "V0") { inputs = lowptgsfeleid::features_V0(*ele, rho, unbiased); } else if (version_ == "V1") { inputs = lowptgsfeleid::features_V1(*ele, rho, unbiased, field_z); @@ -169,16 +174,15 @@ void LowPtGsfElectronIDProducer::fillDescriptions(edm::ConfigurationDescriptions edm::ParameterSetDescription desc; desc.add("electrons", edm::InputTag("lowPtGsfElectrons")); desc.add("unbiased", edm::InputTag("lowPtGsfElectronSeedValueMaps:unbiased")); - desc.add("rho", edm::InputTag("fixedGridRhoFastjetAll")); - desc.add >("ModelNames", {""}); - desc.add >( - "ModelWeights", {"RecoEgamma/ElectronIdentification/data/LowPtElectrons/LowPtElectrons_ID_2020Sept15.root"}); - desc.add >("ModelThresholds", {-99.}); + desc.add("rho", edm::InputTag("fixedGridRhoFastjetAllTmp")); + desc.add >("ModelNames",std::vector()); + desc.add >("ModelWeights",std::vector()); + desc.add >("ModelThresholds",std::vector()); desc.add("PassThrough", false); desc.add("MinPtThreshold", 0.5); desc.add("MaxPtThreshold", 15.); - desc.add("Version", "V1"); - descriptions.add("lowPtGsfElectronID", desc); + desc.add("Version", ""); + descriptions.add("defaultLowPtGsfElectronID",desc); } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py index c4ae5dd94cb41..313e719370ba0 100644 --- a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py +++ b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py @@ -70,7 +70,7 @@ from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronSeedValueMaps_cff import rekeyLowPtGsfElectronSeedValueMaps # Low pT Electron ID -from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronID_cfi import lowPtGsfElectronID +from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronID_cff import lowPtGsfElectronID # Full sequence lowPtGsfElectronTask = cms.Task(lowPtGsfElePfTracks, From b5359cc5ff86bf0143de71211a3c1e5eb67e060f Mon Sep 17 00:00:00 2001 From: bainbrid Date: Sun, 6 Dec 2020 19:14:44 +0100 Subject: [PATCH 15/21] scram build code-format --- .../plugins/LowPtGsfElectronIDProducer.cc | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc index 532effef0bbae..6390a6e3d9fc3 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc @@ -35,8 +35,7 @@ class LowPtGsfElectronIDProducer final : public edm::global::EDProducer<> { static void fillDescriptions(edm::ConfigurationDescriptions&); private: - double eval( - const std::string& name, const reco::GsfElectronRef&, double rho, float unbiased, float field_z) const; + double eval(const std::string& name, const reco::GsfElectronRef&, double rho, float unbiased, float field_z) const; const edm::EDGetTokenT electrons_; const edm::EDGetTokenT rho_; @@ -73,7 +72,7 @@ LowPtGsfElectronIDProducer::LowPtGsfElectronIDProducer(const edm::ParameterSet& throw cms::Exception("Incorrect configuration") << "'ModelWeights' size (" << models_.size() << ") != 'ModelThresholds' size (" << thresholds_.size() << ").\n"; } - if (version_ != "V0" && version_ != "V1" && version_ != "") { + if (version_ != "V0" && version_ != "V1" && !version_.empty()) { throw cms::Exception("Incorrect configuration") << "Unknown Version: " << version_ << "\n"; } for (const auto& name : names_) { @@ -152,9 +151,9 @@ double LowPtGsfElectronIDProducer::eval( if (iter != names_.end()) { int index = std::distance(names_.begin(), iter); std::vector inputs; - if (version_ == "") { // Original XML model + if (version_.empty()) { // Original XML model lowptgsfeleid::Features features; - features.set(ele,rho); + features.set(ele, rho); inputs = features.get(); } else if (version_ == "V0") { inputs = lowptgsfeleid::features_V0(*ele, rho, unbiased); @@ -175,14 +174,14 @@ void LowPtGsfElectronIDProducer::fillDescriptions(edm::ConfigurationDescriptions desc.add("electrons", edm::InputTag("lowPtGsfElectrons")); desc.add("unbiased", edm::InputTag("lowPtGsfElectronSeedValueMaps:unbiased")); desc.add("rho", edm::InputTag("fixedGridRhoFastjetAllTmp")); - desc.add >("ModelNames",std::vector()); - desc.add >("ModelWeights",std::vector()); - desc.add >("ModelThresholds",std::vector()); + desc.add >("ModelNames", std::vector()); + desc.add >("ModelWeights", std::vector()); + desc.add >("ModelThresholds", std::vector()); desc.add("PassThrough", false); desc.add("MinPtThreshold", 0.5); desc.add("MaxPtThreshold", 15.); desc.add("Version", ""); - descriptions.add("defaultLowPtGsfElectronID",desc); + descriptions.add("defaultLowPtGsfElectronID", desc); } ////////////////////////////////////////////////////////////////////////////////////////// From 40916e680d00adf2f9489e09df4dba29325067e9 Mon Sep 17 00:00:00 2001 From: bainbrid Date: Tue, 8 Dec 2020 12:23:42 +0100 Subject: [PATCH 16/21] slava: add gbrForestFile.Close(nodelete) --- CommonTools/MVAUtils/src/GBRForestTools.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CommonTools/MVAUtils/src/GBRForestTools.cc b/CommonTools/MVAUtils/src/GBRForestTools.cc index 979bf4ab140af..988f9f80a9b42 100644 --- a/CommonTools/MVAUtils/src/GBRForestTools.cc +++ b/CommonTools/MVAUtils/src/GBRForestTools.cc @@ -124,7 +124,9 @@ namespace { // if (reco::details::hasEnding(weightsFileFullPath, ".root")) { TFile gbrForestFile(weightsFileFullPath.c_str()); - return std::unique_ptr(reinterpret_cast(gbrForestFile.Get("gbrForest"))); + std::unique_ptr up(reinterpret_cast(gbrForestFile.Get("gbrForest"))); + gbrForestFile.Close("nodelete"); + return up; } // From ee6ceb36b6b166d07d876ac9b27c12749a6ba3eb Mon Sep 17 00:00:00 2001 From: bainbrid Date: Tue, 8 Dec 2020 12:24:52 +0100 Subject: [PATCH 17/21] slava: use run2_miniAOD_UL in lowPtGsfElectronID_cff --- .../lowPtElectronProducer_cff.py | 20 ++----------------- .../python/lowPtGsfElectronID_cff.py | 9 +++++++++ 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/PhysicsTools/PatAlgos/python/producersLayer1/lowPtElectronProducer_cff.py b/PhysicsTools/PatAlgos/python/producersLayer1/lowPtElectronProducer_cff.py index 9926a18ffd610..5de821f0aed5a 100644 --- a/PhysicsTools/PatAlgos/python/producersLayer1/lowPtElectronProducer_cff.py +++ b/PhysicsTools/PatAlgos/python/producersLayer1/lowPtElectronProducer_cff.py @@ -72,24 +72,8 @@ # Schedule rekeying of seed BDT ValueMaps by reco::GsfElectron for run2_miniAOD_UL from Configuration.ProcessModifiers.run2_miniAOD_UL_cff import run2_miniAOD_UL from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronSeedValueMaps_cff import rekeyLowPtGsfElectronSeedValueMaps -from RecoEgamma.EgammaElectronProducers.defaultLowPtGsfElectronID_cfi import defaultLowPtGsfElectronID -run2_miniAOD_UL.toModify( - defaultLowPtGsfElectronID, - rho = "fixedGridRhoFastjetAll", - ModelNames = [''], - ModelWeights = ["RecoEgamma/ElectronIdentification/data/LowPtElectrons/LowPtElectrons_ID_2020Sept15.root"], - ModelThresholds = [-99.], - Version = "V1", -) -run2_miniAOD_UL.toModify( - patLowPtElectrons, - electronIDSources = dict( - unbiased = cms.InputTag("rekeyLowPtGsfElectronSeedValueMaps:unbiased"), - ptbiased = cms.InputTag("rekeyLowPtGsfElectronSeedValueMaps:ptbiased"), - ID = cms.InputTag("defaultLowPtGsfElectronID"), - ) -) +from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronID_cff import lowPtGsfElectronID _makePatLowPtElectronsTask = makePatLowPtElectronsTask.copy() _makePatLowPtElectronsTask.add(rekeyLowPtGsfElectronSeedValueMaps) -_makePatLowPtElectronsTask.add(defaultLowPtGsfElectronID) +_makePatLowPtElectronsTask.add(lowPtGsfElectronID) run2_miniAOD_UL.toReplaceWith(makePatLowPtElectronsTask,_makePatLowPtElectronsTask) diff --git a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronID_cff.py b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronID_cff.py index 09f1db56328ed..15cb46811b4eb 100644 --- a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronID_cff.py +++ b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronID_cff.py @@ -9,3 +9,12 @@ ]), ModelThresholds = cms.vdouble([-10.]) ) + +from Configuration.ProcessModifiers.run2_miniAOD_UL_cff import run2_miniAOD_UL +run2_miniAOD_UL.toModify( + lowPtGsfElectronID, + rho = "fixedGridRhoFastjetAll", + ModelWeights = ["RecoEgamma/ElectronIdentification/data/LowPtElectrons/LowPtElectrons_ID_2020Sept15.root"], + ModelThresholds = [-99.], + Version = "V1", +) From c1513e275eca1bd8a919fc448d6e8b37cb582b2e Mon Sep 17 00:00:00 2001 From: bainbrid Date: Tue, 8 Dec 2020 17:37:45 +0100 Subject: [PATCH 18/21] slava: remove rekey module from RECO sequence --- .../python/lowPtGsfElectronSequence_cff.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py index 313e719370ba0..342eaf1a609e7 100644 --- a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py +++ b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py @@ -67,7 +67,6 @@ # Low pT Electron value maps from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronSeedValueMaps_cff import lowPtGsfElectronSeedValueMaps -from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronSeedValueMaps_cff import rekeyLowPtGsfElectronSeedValueMaps # Low pT Electron ID from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronID_cff import lowPtGsfElectronID @@ -83,7 +82,6 @@ lowPtGsfElectronCores, lowPtGsfElectrons, lowPtGsfElectronSeedValueMaps, - rekeyLowPtGsfElectronSeedValueMaps, lowPtGsfElectronID ) lowPtGsfElectronSequence = cms.Sequence(lowPtGsfElectronTask) From d5297a2b3adc431ae72a0c8bc3c015f40d920424 Mon Sep 17 00:00:00 2001 From: bainbrid Date: Tue, 8 Dec 2020 17:38:19 +0100 Subject: [PATCH 19/21] slava: only add low pT electrons to MINIAOD for bParking and run2_miniAOD_UL --- .../PatAlgos/python/slimming/MicroEventContent_cff.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py b/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py index 49dee70da9bc4..cf6fe37f71cc2 100644 --- a/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py +++ b/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py @@ -90,9 +90,6 @@ 'keep recoTracks_displacedStandAloneMuons__*', # L1 prefiring weights 'keep *_prefiringweight_*_*', - # patLowPtElectrons - 'keep *_slimmedLowPtElectrons_*_*', - 'keep *_gsfTracksOpenConversions_*_*', ) ) @@ -119,6 +116,14 @@ ) ) +# Only add low pT electrons for run2_miniAOD_UL or bParking era +from Configuration.ProcessModifiers.run2_miniAOD_UL_cff import run2_miniAOD_UL +from Configuration.Eras.Modifier_bParking_cff import bParking +_lowPt_extraCommands = ['keep *_slimmedLowPtElectrons_*_*', + 'keep *_gsfTracksOpenConversions_*_*',] +(bParking | run2_miniAOD_UL).toModify(MicroEventContent, + outputCommands = MicroEventContent.outputCommands + _lowPt_extraCommands) + # --- Only for 2018 data & MC _run2_HCAL_2018_extraCommands = ["keep *_packedPFCandidates_hcalDepthEnergyFractions_*"] from Configuration.Eras.Modifier_run2_HCAL_2018_cff import run2_HCAL_2018 From 692e790578ad6e1682d43974fe2bfd4dffffe56c Mon Sep 17 00:00:00 2001 From: bainbrid Date: Tue, 8 Dec 2020 17:56:02 +0100 Subject: [PATCH 20/21] Fixes a unit test failure in TauAnalysis/MCEmbeddingTools (back port of #32400) --- TauAnalysis/MCEmbeddingTools/python/customisers.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index 8de84adc1da29..d208ff19f0abf 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -408,11 +408,15 @@ def customiseMerging(process, changeProcessname=True,reselect=False): # process.merge_step.remove(process.gedPhotonsTmp) # process.merge_step.remove(process.particleFlowTmp) process.merge_step.remove(process.hcalnoise) + process.merge_step.remove(process.lowPtGsfElectronTask) + process.merge_step.remove(process.gsfTracksOpenConversions) process.load('CommonTools.ParticleFlow.genForPF2PAT_cff') process.merge_step += process.genForPF2PATSequence + process.slimmingTask.remove(process.slimmedLowPtElectronsTask) + process.schedule.insert(0,process.merge_step) # process.load('PhysicsTools.PatAlgos.slimming.slimmedGenJets_cfi') From 541fb89365aa00273164f994feec42dc721def14 Mon Sep 17 00:00:00 2001 From: bainbrid Date: Tue, 8 Dec 2020 21:03:55 +0100 Subject: [PATCH 21/21] schedule rekeyLowPtGsfElectronSeedValueMaps and lowPtGsfElectronID for bParking --- .../python/producersLayer1/lowPtElectronProducer_cff.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/PhysicsTools/PatAlgos/python/producersLayer1/lowPtElectronProducer_cff.py b/PhysicsTools/PatAlgos/python/producersLayer1/lowPtElectronProducer_cff.py index 5de821f0aed5a..4a95b97d76edd 100644 --- a/PhysicsTools/PatAlgos/python/producersLayer1/lowPtElectronProducer_cff.py +++ b/PhysicsTools/PatAlgos/python/producersLayer1/lowPtElectronProducer_cff.py @@ -69,11 +69,12 @@ genParticleMatch = "electronMatch" ) -# Schedule rekeying of seed BDT ValueMaps by reco::GsfElectron for run2_miniAOD_UL +# Schedule rekeying of seed BDT ValueMaps by reco::GsfElectron for run2_miniAOD_UL and bParking from Configuration.ProcessModifiers.run2_miniAOD_UL_cff import run2_miniAOD_UL +from Configuration.Eras.Modifier_bParking_cff import bParking from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronSeedValueMaps_cff import rekeyLowPtGsfElectronSeedValueMaps from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronID_cff import lowPtGsfElectronID _makePatLowPtElectronsTask = makePatLowPtElectronsTask.copy() _makePatLowPtElectronsTask.add(rekeyLowPtGsfElectronSeedValueMaps) _makePatLowPtElectronsTask.add(lowPtGsfElectronID) -run2_miniAOD_UL.toReplaceWith(makePatLowPtElectronsTask,_makePatLowPtElectronsTask) +(bParking | run2_miniAOD_UL).toReplaceWith(makePatLowPtElectronsTask,_makePatLowPtElectronsTask)