Skip to content

Commit

Permalink
Merge CMSSW_10_6_X into CMSSW_10_6_DEVEL_X.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmsbuild committed Mar 4, 2019
2 parents 2021b82 + 946f702 commit 4879c48
Show file tree
Hide file tree
Showing 10 changed files with 499 additions and 575 deletions.
41 changes: 15 additions & 26 deletions RecoEgamma/EgammaElectronAlgos/interface/GsfElectronAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,10 @@ class GsfElectronAlgo {
) ;

// main methods
void checkSetup( const edm::EventSetup & ) ;
void beginEvent( edm::Event & ) ;
void displayInternalElectrons( const std::string & title ) const ;
void clonePreviousElectrons() ;
void completeElectrons(const gsfAlgoHelpers::HeavyObjectCache*) ; // do not redo cloned electrons done previously
void addPflowInfo() ; // now deprecated
void setAmbiguityData( bool ignoreNotPreselected = true ) ;
void removeNotPreselectedElectrons() ;
void removeAmbiguousElectrons() ;
reco::GsfElectronCollection & electrons() ;
void setMVAInputs(const std::map<reco::GsfTrackRef,reco::GsfElectron::MvaInput> & mvaInputs) ;
void setMVAOutputs(const gsfAlgoHelpers::HeavyObjectCache*,
const std::map<reco::GsfTrackRef,reco::GsfElectron::MvaOutput> & mvaOutputs) ;
void endEvent() ;
void completeElectrons( reco::GsfElectronCollection & electrons, // do not redo cloned electrons done previously
edm::Event const& event,
edm::EventSetup const& eventSetup,
const gsfAlgoHelpers::HeavyObjectCache* hoc);

private :

Expand Down Expand Up @@ -266,7 +256,6 @@ class GsfElectronAlgo {
const MultiTrajectoryStateMode mtsMode ;
} ;


//===================================================================
// GsfElectronAlgo::EventData
//===================================================================
Expand All @@ -278,7 +267,7 @@ class GsfElectronAlgo {
( const reco::TrackRef &, const reco::GsfTrackRef & ) ;

// general
edm::Event * event ;
edm::Event const* event ;
const reco::BeamSpot * beamspot ;

// input collections
Expand Down Expand Up @@ -310,8 +299,6 @@ class GsfElectronAlgo {

bool originalCtfTrackCollectionRetreived = false ;
bool originalGsfTrackCollectionRetreived = false ;

reco::GsfElectronCollection electrons ;
} ;

//===================================================================
Expand Down Expand Up @@ -357,23 +344,25 @@ class GsfElectronAlgo {

GeneralData generalData_ ;
EventSetupData eventSetupData_ ;
std::unique_ptr<EventData> eventData_ ;
std::unique_ptr<ElectronData> electronData_ ;

EleTkIsolFromCands tkIsol03Calc_;
EleTkIsolFromCands tkIsol04Calc_;

void createElectron(const gsfAlgoHelpers::HeavyObjectCache*) ;
void checkSetup( edm::EventSetup const& eventSetup ) ;
EventData beginEvent( edm::Event const& event ) ;

void createElectron(reco::GsfElectronCollection & electrons, ElectronData & electronData, EventData & eventData, const gsfAlgoHelpers::HeavyObjectCache*) ;

void setMVAepiBasedPreselectionFlag(reco::GsfElectron & ele);
void setCutBasedPreselectionFlag( reco::GsfElectron & ele, const reco::BeamSpot & ) ;
void setPflowPreselectionFlag( reco::GsfElectron & ele ) ;
bool isPreselected( reco::GsfElectron const& ele ) ;

template<bool full5x5>
void calculateShowerShape( const reco::SuperClusterRef &, bool pflow,
reco::GsfElectron::ShowerShape & ) ;
void calculateSaturationInfo(const reco::SuperClusterRef&, reco::GsfElectron::SaturationInfo&);
void calculateShowerShape( const reco::SuperClusterRef &,
ElectronHcalHelper const& hcalHelper,
reco::GsfElectron::ShowerShape &,
EventData const& eventData );
void calculateSaturationInfo(const reco::SuperClusterRef&, reco::GsfElectron::SaturationInfo&,
EventData const& eventData);

// associations
const reco::SuperClusterRef getTrSuperCluster( const reco::GsfTrackRef & trackRef ) ;
Expand Down
634 changes: 128 additions & 506 deletions RecoEgamma/EgammaElectronAlgos/src/GsfElectronAlgo.cc

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,16 @@ GEDGsfElectronProducer::GEDGsfElectronProducer( const edm::ParameterSet & cfg, c
produces<edm::ValueMap<reco::GsfElectronRef> >();
}

GEDGsfElectronProducer::~GEDGsfElectronProducer() {}

// ------------ method called to produce the data ------------
void GEDGsfElectronProducer::produce( edm::Event & event, const edm::EventSetup & setup )
{
beginEvent(event,setup) ;
matchWithPFCandidates(event);
algo_->completeElectrons(globalCache()) ;
algo_->setMVAOutputs(globalCache(),gsfMVAOutputMap_);
algo_->setMVAInputs(gsfMVAInputMap_);
fillEvent(event) ;
reco::GsfElectronCollection electrons;
algo_->completeElectrons(electrons, event, setup, globalCache()) ;
setMVAOutputs(electrons, globalCache(),gsfMVAOutputMap_, event.get(inputCfg_.vtxCollectionTag));
for(auto& el : electrons) el.setMvaInput(gsfMVAInputMap_.find(el.gsfTrack())->second); // set MVA inputs
fillEvent(electrons, event) ;

// ValueMap
auto valMap_p = std::make_unique<edm::ValueMap<reco::GsfElectronRef>>();
Expand All @@ -54,8 +53,6 @@ void GEDGsfElectronProducer::produce( edm::Event & event, const edm::EventSetup
valMapFiller.fill();
event.put(std::move(valMap_p));
// Done with the ValueMap

endEvent() ;
}

void GEDGsfElectronProducer::fillGsfElectronValueMap(edm::Event & event, edm::ValueMap<reco::GsfElectronRef>::Filler & filler)
Expand Down Expand Up @@ -134,3 +131,19 @@ void GEDGsfElectronProducer::matchWithPFCandidates(edm::Event & event)
}
}
}


void GEDGsfElectronProducer::setMVAOutputs(reco::GsfElectronCollection& electrons,
const gsfAlgoHelpers::HeavyObjectCache* hoc,
const std::map<reco::GsfTrackRef, reco::GsfElectron::MvaOutput>& mvaOutputs,
reco::VertexCollection const& vertices) const
{
for (auto el = electrons.begin(); el != electrons.end(); el++) {
float mva_NIso_Value = hoc->sElectronMVAEstimator->mva(*el, vertices);
float mva_Iso_Value = hoc->iElectronMVAEstimator->mva(*el, vertices.size());
GsfElectron::MvaOutput mvaOutput;
mvaOutput.mva_e_pi = mva_NIso_Value;
mvaOutput.mva_Isolated = mva_Iso_Value;
el->setMvaOutput(mvaOutput);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class GEDGsfElectronProducer : public GsfElectronBaseProducer
{
public:

explicit GEDGsfElectronProducer( const edm::ParameterSet &, const gsfAlgoHelpers::HeavyObjectCache* ) ;
~GEDGsfElectronProducer() override ;
explicit GEDGsfElectronProducer( const edm::ParameterSet &, const gsfAlgoHelpers::HeavyObjectCache* ) ;
void produce( edm::Event &, const edm::EventSetup & ) override ;

private:
Expand All @@ -22,6 +21,10 @@ class GEDGsfElectronProducer : public GsfElectronBaseProducer
private:
void fillGsfElectronValueMap(edm::Event & event, edm::ValueMap<reco::GsfElectronRef>::Filler & filler);
void matchWithPFCandidates(edm::Event & event);
void setMVAOutputs(reco::GsfElectronCollection & electrons,
const gsfAlgoHelpers::HeavyObjectCache*,
const std::map<reco::GsfTrackRef,reco::GsfElectron::MvaOutput> & mvaOutputs,
reco::VertexCollection const& vertices) const;

} ;

Expand Down
172 changes: 159 additions & 13 deletions RecoEgamma/EgammaElectronProducers/plugins/GsfElectronBaseProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,28 @@
#include "DataFormats/EcalRecHit/interface/EcalSeverityLevel.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"

#include "RecoEgamma/EgammaElectronAlgos/interface/EgAmbiguityTools.h"
#include "RecoEgamma/EgammaElectronAlgos/interface/ElectronUtilities.h"
#include "DataFormats/ParticleFlowReco/interface/GsfPFRecTrack.h"


namespace {

void logElectrons(reco::GsfElectronCollection const& electrons, edm::Event const& event, const std::string& title)
{
LogTrace("GsfElectronAlgo") << "========== " << title << " ==========";
LogTrace("GsfElectronAlgo") << "Event: " << event.id();
LogTrace("GsfElectronAlgo") << "Number of electrons: " << electrons.size();
for (auto const& ele : electrons) {
LogTrace("GsfElectronAlgo") << "Electron with charge, pt, eta, phi: " << ele.charge() << " , " << ele.pt()
<< " , " << ele.eta() << " , " << ele.phi();
}
LogTrace("GsfElectronAlgo") << "=================================================";
}

} // namespace


using namespace reco;

void GsfElectronBaseProducer::fillDescriptions( edm::ConfigurationDescriptions & descriptions )
Expand Down Expand Up @@ -357,34 +379,31 @@ void GsfElectronBaseProducer::beginEvent( edm::Event & event, const edm::EventSe
checkEcalSeedingParameters(edm::parameterSet(*seeds.provenance())) ;
}
}

// init the algo
algo_->checkSetup(setup) ;
algo_->beginEvent(event) ;
}

void GsfElectronBaseProducer::fillEvent( edm::Event & event )
void GsfElectronBaseProducer::fillEvent( reco::GsfElectronCollection & electrons, edm::Event & event )
{
// all electrons
algo_->displayInternalElectrons("GsfElectronAlgo Info (before preselection)") ;
logElectrons(electrons, event, "GsfElectronAlgo Info (before preselection)") ;
// preselection
if (strategyCfg_.applyPreselection)
{
algo_->removeNotPreselectedElectrons() ;
algo_->displayInternalElectrons("GsfElectronAlgo Info (after preselection)") ;
electrons.erase( std::remove_if(electrons.begin(), electrons.end(),
[this](auto const& ele){ return !isPreselected(ele); }), electrons.end() );
logElectrons(electrons, event, "GsfElectronAlgo Info (after preselection)") ;
}
// ambiguity
algo_->setAmbiguityData() ;
setAmbiguityData(electrons,event) ;
if (strategyCfg_.applyAmbResolution)
{
algo_->removeAmbiguousElectrons() ;
algo_->displayInternalElectrons("GsfElectronAlgo Info (after amb. solving)") ;
electrons.erase( std::remove_if(electrons.begin(), electrons.end(),
std::mem_fn(&reco::GsfElectron::ambiguous)), electrons.end() );
logElectrons(electrons, event, "GsfElectronAlgo Info (after amb. solving)") ;
}
// final filling
orphanHandle_ = event.emplace(electronPutToken_, std::move(algo_->electrons()));
orphanHandle_ = event.emplace(electronPutToken_, std::move(electrons));
}

void GsfElectronBaseProducer::endEvent() { algo_->endEvent(); }

void GsfElectronBaseProducer::checkEcalSeedingParameters( edm::ParameterSet const & pset )
{
Expand All @@ -406,3 +425,130 @@ void GsfElectronBaseProducer::checkEcalSeedingParameters( edm::ParameterSet cons
if (cutsCfg_.minSCEtEndcaps<seedConfiguration.getParameter<double>("SCEtCut"))
{ edm::LogWarning("GsfElectronAlgo|InconsistentParameters") <<"The minimum super-cluster Et in endcaps is lower than during ecal seeding." ; }
}

//=======================================================================================
// Ambiguity solving
//=======================================================================================

void GsfElectronBaseProducer::setAmbiguityData(reco::GsfElectronCollection& electrons,
edm::Event const& event,
bool ignoreNotPreselected) const
{
// Getting required event data
auto const& beamspot = event.get(inputCfg_.beamSpotTag);
auto gsfPfRecTracks = strategyCfg_.useGsfPfRecTracks ? event.getHandle(inputCfg_.gsfPfRecTracksTag)
: edm::Handle<reco::GsfPFRecTrackCollection>{};
auto const& barrelRecHits = event.get(inputCfg_.barrelRecHitCollection);
auto const& endcapRecHits = event.get(inputCfg_.endcapRecHitCollection);

if (strategyCfg_.ambSortingStrategy == 0) {
std::sort(electrons.begin(), electrons.end(), EgAmbiguityTools::isBetter);
} else if (strategyCfg_.ambSortingStrategy == 1) {
std::sort(electrons.begin(), electrons.end(), EgAmbiguityTools::isInnerMost);
} else {
throw cms::Exception("GsfElectronAlgo|UnknownAmbiguitySortingStrategy")
<< "value of strategyCfg_.ambSortingStrategy is : " << strategyCfg_.ambSortingStrategy;
}

// init
for (auto e1 = electrons.begin(); e1 != electrons.end(); ++e1) {
e1->clearAmbiguousGsfTracks();
e1->setAmbiguous(false);
}

// get ambiguous from GsfPfRecTracks
if (strategyCfg_.useGsfPfRecTracks) {
for (auto& e1 : electrons) {
bool found = false;
for (auto const& gsfPfRecTrack : *gsfPfRecTracks.product()) {
if (gsfPfRecTrack.gsfTrackRef() == e1.gsfTrack()) {
if (found) {
edm::LogWarning("GsfElectronAlgo") << "associated gsfPfRecTrack already found";
} else {
found = true;
for (auto const& duplicate : gsfPfRecTrack.convBremGsfPFRecTrackRef()) {
e1.addAmbiguousGsfTrack(duplicate->gsfTrackRef());
}
}
}
}
}
}
// or search overlapping clusters
else {
for (auto e1 = electrons.begin(); e1 != electrons.end(); ++e1) {
if (e1->ambiguous())
continue;
if (ignoreNotPreselected && !isPreselected(*e1))
continue;

SuperClusterRef scRef1 = e1->superCluster();
CaloClusterPtr eleClu1 = e1->electronCluster();
LogDebug("GsfElectronAlgo") << "Blessing electron with E/P " << e1->eSuperClusterOverP() << ", cluster "
<< scRef1.get() << " & track " << e1->gsfTrack().get();

for (auto e2 = e1 + 1; e2 != electrons.end(); ++e2) {
if (e2->ambiguous())
continue;
if (ignoreNotPreselected && !isPreselected(*e2))
continue;

SuperClusterRef scRef2 = e2->superCluster();
CaloClusterPtr eleClu2 = e2->electronCluster();

// search if same cluster
bool sameCluster = false;
if (strategyCfg_.ambClustersOverlapStrategy == 0) {
sameCluster = (scRef1 == scRef2);
} else if (strategyCfg_.ambClustersOverlapStrategy == 1) {
float eMin = 1.;
float threshold = eMin * cosh(EleRelPoint(scRef1->position(), beamspot.position()).eta());
sameCluster =
((EgAmbiguityTools::sharedEnergy(*eleClu1, *eleClu2, barrelRecHits, endcapRecHits) >= threshold) ||
(EgAmbiguityTools::sharedEnergy(*scRef1->seed(), *eleClu2, barrelRecHits, endcapRecHits) >= threshold) ||
(EgAmbiguityTools::sharedEnergy(*eleClu1, *scRef2->seed(), barrelRecHits, endcapRecHits) >= threshold) ||
(EgAmbiguityTools::sharedEnergy(*scRef1->seed(), *scRef2->seed(), barrelRecHits, endcapRecHits) >=
threshold));
} else {
throw cms::Exception("GsfElectronAlgo|UnknownAmbiguityClustersOverlapStrategy")
<< "value of strategyCfg_.ambClustersOverlapStrategy is : " << strategyCfg_.ambClustersOverlapStrategy;
}

// main instructions
if (sameCluster) {
LogDebug("GsfElectronAlgo") << "Discarding electron with E/P " << e2->eSuperClusterOverP() << ", cluster "
<< scRef2.get() << " and track " << e2->gsfTrack().get();
e1->addAmbiguousGsfTrack(e2->gsfTrack());
e2->setAmbiguous(true);
} else if (e1->gsfTrack() == e2->gsfTrack()) {
edm::LogWarning("GsfElectronAlgo") << "Forgetting electron with E/P " << e2->eSuperClusterOverP()
<< ", cluster " << scRef2.get() << " and track " << e2->gsfTrack().get();
e2->setAmbiguous(true);
}
}
}
}
}


bool GsfElectronBaseProducer::isPreselected(GsfElectron const& ele) const
{
bool passCutBased = ele.passingCutBasedPreselection();
bool passPF = ele.passingPflowPreselection();
// it is worth nothing for gedGsfElectrons, this does nothing as its not set
// till GedGsfElectron finaliser, this is always false
if (strategyCfg_.gedElectronMode) {
bool passmva = ele.passingMvaPreselection();
if (!ele.ecalDrivenSeed()) {
if (ele.pt() > strategyCfg_.MaxElePtForOnlyMVA)
return passmva && passCutBased;
else
return passmva;
} else
return (passCutBased || passPF || passmva);
} else {
return passCutBased || passPF;
}

return true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ class GsfElectronBaseProducer : public edm::stream::EDProducer< edm::GlobalCache
GsfElectronAlgo * algo_ ;

void beginEvent( edm::Event &, const edm::EventSetup & ) ;
void fillEvent( edm::Event & ) ;
void endEvent() ;
void fillEvent( reco::GsfElectronCollection & electrons, edm::Event & event ) ;
const edm::OrphanHandle<reco::GsfElectronCollection> & orphanHandle() const { return orphanHandle_;}

// configurables
Expand All @@ -65,6 +64,9 @@ class GsfElectronBaseProducer : public edm::stream::EDProducer< edm::GlobalCache

private :

bool isPreselected( reco::GsfElectron const& ele ) const ;
void setAmbiguityData( reco::GsfElectronCollection & electrons, edm::Event const& event, bool ignoreNotPreselected = true ) const ;

// check expected configuration of previous modules
bool ecalSeedingParametersChecked_ ;
void checkEcalSeedingParameters( edm::ParameterSet const & ) ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ GsfElectronEcalDrivenProducer::~GsfElectronEcalDrivenProducer()
// ------------ method called to produce the data ------------
void GsfElectronEcalDrivenProducer::produce( edm::Event & event, const edm::EventSetup & setup )
{
beginEvent(event,setup) ;
algo_->completeElectrons(globalCache()) ;
fillEvent(event) ;
endEvent() ;
reco::GsfElectronCollection electrons;
algo_->completeElectrons(electrons, event, setup, globalCache()) ;
fillEvent(electrons, event) ;
}
Loading

0 comments on commit 4879c48

Please sign in to comment.