Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addition of soft electron mva, after fixing #4565 merge conflicts #4842

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Configuration/Skimming/src/LeptonRecoSkim.cc
Expand Up @@ -115,7 +115,7 @@ LeptonRecoSkim::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
if(elpt>ptElecMin) {
NtotalElectrons++;
nElecPassingCut++;
if(electron.mva()>-0.1) NmvaElectrons++;
if(electron.mva_e_pi()>-0.1) NmvaElectrons++;
}
LogDebug("LeptonRecoSkim") << "elpt = " << elpt << endl;
// } // closes if (electron.ecalDrivenSeed()) {
Expand Down
2 changes: 1 addition & 1 deletion DQMOffline/EGamma/plugins/ElectronAnalyzer.cc
Expand Up @@ -469,7 +469,7 @@ void ElectronAnalyzer::analyze( const edm::Event& iEvent, const edm::EventSetup


// pflow
h1_mva->Fill(gsfIter->mva()) ;
h1_mva->Fill(gsfIter->mva_e_pi()) ;
if (gsfIter->ecalDrivenSeed()) h1_provenance->Fill(1.) ;
if (gsfIter->trackerDrivenSeed()) h1_provenance->Fill(-1.) ;
if (gsfIter->trackerDrivenSeed()||gsfIter->ecalDrivenSeed()) h1_provenance->Fill(0.);
Expand Down
2 changes: 1 addition & 1 deletion DQMOffline/EGamma/plugins/ElectronTagProbeAnalyzer.cc
Expand Up @@ -439,7 +439,7 @@ void ElectronTagProbeAnalyzer::analyze( const edm::Event& iEvent, const edm::Eve
h1_classes->Fill(eleClass);

// pflow
h1_mva->Fill(bestGsfElectron.mva()) ;
h1_mva->Fill(bestGsfElectron.mva_e_pi()) ;
if (bestGsfElectron.ecalDrivenSeed()) h1_provenance->Fill(1.) ;
if (bestGsfElectron.trackerDrivenSeed()) h1_provenance->Fill(-1.) ;
if (bestGsfElectron.trackerDrivenSeed()||bestGsfElectron.ecalDrivenSeed()) h1_provenance->Fill(0.);
Expand Down
8 changes: 5 additions & 3 deletions DataFormats/EgammaCandidates/interface/GsfElectron.h
Expand Up @@ -589,10 +589,11 @@ class GsfElectron : public RecoCandidate
struct MvaOutput
{
int status ; // see PFCandidateElectronExtra::StatusFlag
float mva ;
float mva_Isolated ;
float mva_e_pi ;
float mvaByPassForIsolated ; // complementary MVA used in preselection
MvaOutput()
: status(-1), mva(-999999999.), mvaByPassForIsolated(-999999999.)
: status(-1), mva_Isolated(-999999999.),mva_e_pi(-999999999.), mvaByPassForIsolated(-999999999.)
{}
} ;

Expand All @@ -609,7 +610,8 @@ class GsfElectron : public RecoCandidate
void setMvaOutput( const MvaOutput & mo ) { mvaOutput_ = mo ; }

// for backward compatibility
float mva() const { return mvaOutput_.mva ; }
float mva_Isolated() const { return mvaOutput_.mva_Isolated ; }
float mva_e_pi() const { return mvaOutput_.mva_e_pi ; }

private:

Expand Down
7 changes: 6 additions & 1 deletion DataFormats/EgammaCandidates/src/classes_def.xml
Expand Up @@ -193,11 +193,16 @@
<version ClassVersion="11" checksum="2106253688"/>
<version ClassVersion="10" checksum="2786166332"/>
</class>
<class name="reco::GsfElectron::MvaOutput" ClassVersion="12">
<class name="reco::GsfElectron::MvaOutput" ClassVersion="13">
<version ClassVersion="13" checksum="632217271"/>
<version ClassVersion="12" checksum="3102257169"/>
<version ClassVersion="11" checksum="1838996036"/>
<version ClassVersion="10" checksum="2145829729"/>
</class>
<ioread sourceClass="reco::GsfElectron::MvaOutput" version="[1-12]" targetClass="reco::GsfElectron::MvaOutput" source="float mva;" target="mva_e_pi">
<![CDATA[mva_e_pi = onfile.mva;]]>
</ioread>

<class name="reco::GsfElectron::ClassificationVariables" ClassVersion="11">
<version ClassVersion="11" checksum="2094185381"/>
</class>
Expand Down
10 changes: 7 additions & 3 deletions DataFormats/ParticleFlowCandidate/interface/PFCandidate.h
Expand Up @@ -287,12 +287,13 @@ namespace reco {
/// to 1 otherwise
/// For neutral particles, it is set to the default value

void set_mva_Isolated( float mvaI ){ mva_Isolated_=mvaI;}
// mva for isolated electrons
float mva_Isolated() const { return mva_Isolated_;}

void set_mva_e_pi( float mva ){ mva_e_pi_=mva;}

void set_mva_e_pi( float mvaNI ){ mva_e_pi_=mvaNI;}
/// mva for electron-pion discrimination
float mva_e_pi() const { return mva_e_pi_;}


/// set mva for electron-muon discrimination
void set_mva_e_mu( float mva ) { mva_e_mu_=mva;}
Expand Down Expand Up @@ -454,6 +455,9 @@ namespace reco {

PFVertexType vertexType_;

// mva for isolated electrons
float mva_Isolated_;

/// mva for electron-pion discrimination
float mva_e_pi_;

Expand Down
4 changes: 4 additions & 0 deletions DataFormats/ParticleFlowCandidate/src/PFCandidate.cc
Expand Up @@ -41,6 +41,7 @@ PFCandidate::PFCandidate() :
flags_(0),
deltaP_(0.),
vertexType_(kCandVertex),
mva_Isolated_(bigMva_),
mva_e_pi_(bigMva_),
mva_e_mu_(bigMva_),
mva_pi_mu_(bigMva_),
Expand Down Expand Up @@ -81,6 +82,7 @@ PFCandidate::PFCandidate( Charge charge,
flags_(0),
deltaP_(0.),
vertexType_(kCandVertex),
mva_Isolated_(bigMva_),
mva_e_pi_(bigMva_),
mva_e_mu_(bigMva_),
mva_pi_mu_(bigMva_),
Expand Down Expand Up @@ -139,6 +141,7 @@ PFCandidate::PFCandidate( PFCandidate const& iOther) :
flags_(iOther.flags_),
deltaP_(iOther.deltaP_),
vertexType_(iOther.vertexType_),
mva_Isolated_(iOther.mva_Isolated_),
mva_e_pi_(iOther.mva_e_pi_),
mva_e_mu_(iOther.mva_e_mu_),
mva_pi_mu_(iOther.mva_pi_mu_),
Expand Down Expand Up @@ -180,6 +183,7 @@ PFCandidate& PFCandidate::operator=(PFCandidate const& iOther) {
flags_=iOther.flags_;
deltaP_=iOther.deltaP_;
vertexType_=iOther.vertexType_;
mva_Isolated_=iOther.mva_Isolated_;
mva_e_pi_=iOther.mva_e_pi_;
mva_e_mu_=iOther.mva_e_mu_;
mva_pi_mu_=iOther.mva_pi_mu_;
Expand Down
3 changes: 2 additions & 1 deletion DataFormats/ParticleFlowCandidate/src/classes_def.xml
@@ -1,10 +1,11 @@
<lcgdict>

<class name="reco::PFCandidate" ClassVersion="13">
<class name="reco::PFCandidate" ClassVersion="14">
<version ClassVersion="10" checksum="536762407"/>
<version ClassVersion="11" checksum="2503588164"/>
<version ClassVersion="12" checksum="2782366916"/>
<version ClassVersion="13" checksum="3911979988"/>
<version ClassVersion="14" checksum="3379420193"/>
<field name="elementsInBlocks_" transient="true"/>
<field name="getter_" transient="true"/>
<field name="refsCollectionCache_" transient="true"/>
Expand Down
2 changes: 1 addition & 1 deletion PhysicsTools/SelectorUtils/interface/PFElectronSelector.h
Expand Up @@ -114,7 +114,7 @@ class PFElectronSelector : public Selector<pat::Electron> {

ret.set(false);

double mva = electron.mva();
double mva = electron.mva_e_pi();
double missingHits = electron.gsfTrack()->hitPattern().numberOfHits(reco::HitPattern::MISSING_INNER_HITS);
double corr_d0 = electron.dB();

Expand Down
2 changes: 1 addition & 1 deletion RecoBTag/SoftLepton/plugins/SoftLepton.cc
Expand Up @@ -165,7 +165,7 @@ SoftLepton::produce(edm::Event & event, const edm::EventSetup & setup) {
leptonId = SoftLeptonProperties::Quality::egammaElectronId;
for (GsfElectronView::const_iterator electron = h_electrons->begin(); electron != h_electrons->end(); ++electron) {
LeptonIds &id = leptons[reco::TrackBaseRef(electron->gsfTrack())];
id[SoftLeptonProperties::Quality::pfElectronId] = electron->mva();
id[SoftLeptonProperties::Quality::pfElectronId] = electron->mva_e_pi();
if (haveLeptonCands)
id[SoftLeptonProperties::Quality::btagElectronCands] = (*h_leptonCands)[h_electrons->refAt(electron - h_electrons->begin())];
}
Expand Down
5 changes: 3 additions & 2 deletions RecoEgamma/EgammaElectronAlgos/interface/GsfElectronAlgo.h
Expand Up @@ -48,7 +48,7 @@ class EcalClusterFunctionBaseClass ;
#include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h"

#include "RecoEgamma/ElectronIdentification/interface/SoftElectronMVAEstimator.h"

#include "RecoEgamma/ElectronIdentification/interface/ElectronMVAEstimator.h"

#include <list>
#include <string>
Expand Down Expand Up @@ -204,7 +204,8 @@ class GsfElectronAlgo {
const EcalRecHitsConfiguration &,
EcalClusterFunctionBaseClass * superClusterErrorFunction,
EcalClusterFunctionBaseClass * crackCorrectionFunction,
const SoftElectronMVAEstimator::Configuration & mvaCfg,
const SoftElectronMVAEstimator::Configuration & mva_NIso_Cfg,
const ElectronMVAEstimator::Configuration & mva_Iso_Cfg,
const RegressionHelper::Configuration & regCfg
) ;

Expand Down
29 changes: 19 additions & 10 deletions RecoEgamma/EgammaElectronAlgos/src/GsfElectronAlgo.cc
Expand Up @@ -70,7 +70,8 @@ struct GsfElectronAlgo::GeneralData
const EcalRecHitsConfiguration &,
EcalClusterFunctionBaseClass * superClusterErrorFunction,
EcalClusterFunctionBaseClass * crackCorrectionFunction,
const SoftElectronMVAEstimator::Configuration & mvaCfg ,
const SoftElectronMVAEstimator::Configuration & mva_NIso_Cfg ,
const ElectronMVAEstimator::Configuration & mva_Iso_Cfg ,
const RegressionHelper::Configuration &) ;
~GeneralData() ;

Expand All @@ -87,6 +88,7 @@ struct GsfElectronAlgo::GeneralData
EcalClusterFunctionBaseClass * superClusterErrorFunction ;
EcalClusterFunctionBaseClass * crackCorrectionFunction ;
SoftElectronMVAEstimator *sElectronMVAEstimator;
ElectronMVAEstimator *iElectronMVAEstimator;
const RegressionHelper::Configuration regCfg;
RegressionHelper * regHelper;
} ;
Expand All @@ -102,7 +104,9 @@ struct GsfElectronAlgo::GeneralData
const EcalRecHitsConfiguration & recHitsConfig,
EcalClusterFunctionBaseClass * superClusterErrorFunc,
EcalClusterFunctionBaseClass * crackCorrectionFunc,
const SoftElectronMVAEstimator::Configuration & mvaConfig,
const SoftElectronMVAEstimator::Configuration & mva_NIso_Config,
const ElectronMVAEstimator::Configuration & mva_Iso_Config,

const RegressionHelper::Configuration & regConfig
)
: inputCfg(inputConfig),
Expand All @@ -115,7 +119,8 @@ struct GsfElectronAlgo::GeneralData
hcalHelperPflow(new ElectronHcalHelper(hcalConfigPflow)),
superClusterErrorFunction(superClusterErrorFunc),
crackCorrectionFunction(crackCorrectionFunc),
sElectronMVAEstimator(new SoftElectronMVAEstimator(mvaConfig)),
sElectronMVAEstimator(new SoftElectronMVAEstimator(mva_NIso_Config)),
iElectronMVAEstimator(new ElectronMVAEstimator(mva_Iso_Config)),
regCfg(regConfig),
regHelper(new RegressionHelper(regConfig))
{}
Expand All @@ -125,6 +130,7 @@ GsfElectronAlgo::GeneralData::~GeneralData()
delete hcalHelper ;
delete hcalHelperPflow ;
delete sElectronMVAEstimator;
delete iElectronMVAEstimator;
delete regHelper;
}

Expand Down Expand Up @@ -648,10 +654,11 @@ GsfElectronAlgo::GsfElectronAlgo
const EcalRecHitsConfiguration & recHitsCfg,
EcalClusterFunctionBaseClass * superClusterErrorFunction,
EcalClusterFunctionBaseClass * crackCorrectionFunction,
const SoftElectronMVAEstimator::Configuration & mvaCfg,
const SoftElectronMVAEstimator::Configuration & mva_NIso_Cfg,
const ElectronMVAEstimator::Configuration & mva_Iso_Cfg,
const RegressionHelper::Configuration & regCfg
)
: generalData_(new GeneralData(inputCfg,strategyCfg,cutsCfg,cutsCfgPflow,hcalCfg,hcalCfgPflow,isoCfg,recHitsCfg,superClusterErrorFunction,crackCorrectionFunction,mvaCfg,regCfg)),
: generalData_(new GeneralData(inputCfg,strategyCfg,cutsCfg,cutsCfgPflow,hcalCfg,hcalCfgPflow,isoCfg,recHitsCfg,superClusterErrorFunction,crackCorrectionFunction,mva_NIso_Cfg,mva_Iso_Cfg,regCfg)),
eventSetupData_(new EventSetupData),
eventData_(0), electronData_(0)
{}
Expand Down Expand Up @@ -986,7 +993,7 @@ void GsfElectronAlgo::addPflowInfo()
else
{ (*el)->setP4(GsfElectron::P4_PFLOW_COMBINATION,pfElectron->p4(GsfElectron::P4_PFLOW_COMBINATION),pfElectron->p4Error(GsfElectron::P4_PFLOW_COMBINATION),true) ; }
double noCutMin = -999999999. ;
if ((*el)->mva()<noCutMin) { throw cms::Exception("GsfElectronAlgo|UnexpectedMvaValue")<<"unexpected MVA value: "<<(*el)->mva() ; }
if ((*el)->mva_e_pi()<noCutMin) { throw cms::Exception("GsfElectronAlgo|UnexpectedMvaValue")<<"unexpected MVA value: "<<(*el)->mva_e_pi() ; }
}
}
}
Expand Down Expand Up @@ -1181,9 +1188,9 @@ void GsfElectronAlgo::setPflowPreselectionFlag( GsfElectron * ele )
ele->setPassMvaPreselection(false) ;

if (ele->core()->ecalDrivenSeed())
{ if (ele->mvaOutput().mva>=generalData_->cutsCfg.minMVA) ele->setPassMvaPreselection(true) ; }
{ if (ele->mvaOutput().mva_e_pi>=generalData_->cutsCfg.minMVA) ele->setPassMvaPreselection(true) ; }
else
{ if (ele->mvaOutput().mva>=generalData_->cutsCfgPflow.minMVA) ele->setPassMvaPreselection(true) ; }
{ if (ele->mvaOutput().mva_e_pi>=generalData_->cutsCfgPflow.minMVA) ele->setPassMvaPreselection(true) ; }

if (ele->passingMvaPreselection())
{ LogTrace("GsfElectronAlgo") << "Main mva criterion is satisfied" ; }
Expand Down Expand Up @@ -1229,9 +1236,11 @@ void GsfElectronAlgo::setMVAOutputs(const std::map<reco::GsfTrackRef,reco::GsfEl
el++ )
{
if(generalData_->strategyCfg.gedElectronMode==true){
float mvaValue=generalData_->sElectronMVAEstimator->mva( *(*el),*(eventData_->event));
float mva_NIso_Value= generalData_->sElectronMVAEstimator->mva( *(*el),*(eventData_->event));
float mva_Iso_Value = generalData_->iElectronMVAEstimator->mva( *(*el), eventData_->vertices->size() );
GsfElectron::MvaOutput mvaOutput ;
mvaOutput.mva = mvaValue ;
mvaOutput.mva_e_pi = mva_NIso_Value ;
mvaOutput.mva_Isolated = mva_Iso_Value ;
(*el)->setMvaOutput(mvaOutput);
}
else{
Expand Down
Expand Up @@ -123,7 +123,6 @@ void GEDGsfElectronProducer::matchWithPFCandidates(edm::Event & event)
if( it->gsfTrackRef().isNonnull()) {

reco::GsfElectron::MvaOutput myMvaOutput;
myMvaOutput.mva = it->mva_e_pi();
// at the moment, undefined
myMvaOutput.status = it->egammaExtraRef()->electronStatus() ;
gsfMVAOutputMap_[it->gsfTrackRef()] = myMvaOutput;
Expand Down
Expand Up @@ -365,7 +365,8 @@ GsfElectronBaseProducer::GsfElectronBaseProducer( const edm::ParameterSet& cfg )
}


mvaCfg_.vweightsfiles=cfg.getParameter<std::vector<std::string>>("SoftElecMVAFilesString");
mva_NIso_Cfg_.vweightsfiles=cfg.getParameter<std::vector<std::string>>("SoftElecMVAFilesString");
mva_Iso_Cfg_.vweightsfiles=cfg.getParameter<std::vector<std::string>>("ElecMVAFilesString");
// create algo
algo_ = new GsfElectronAlgo
( inputCfg_, strategyCfg_,
Expand All @@ -374,7 +375,8 @@ GsfElectronBaseProducer::GsfElectronBaseProducer( const edm::ParameterSet& cfg )
isoCfg,recHitsCfg,
superClusterErrorFunction,
crackCorrectionFunction,
mvaCfg_,
mva_NIso_Cfg_,
mva_Iso_Cfg_,
regressionCfg
) ;

Expand Down
Expand Up @@ -52,7 +52,8 @@ class GsfElectronBaseProducer : public edm::stream::EDProducer<>
GsfElectronAlgo::CutsConfiguration cutsCfgPflow_ ;
ElectronHcalHelper::Configuration hcalCfg_ ;
ElectronHcalHelper::Configuration hcalCfgPflow_ ;
SoftElectronMVAEstimator::Configuration mvaCfg_ ;
SoftElectronMVAEstimator::Configuration mva_NIso_Cfg_ ;
ElectronMVAEstimator::Configuration mva_Iso_Cfg_ ;
private :

// check expected configuration of previous modules
Expand Down
Expand Up @@ -162,6 +162,9 @@
SoftElecMVAFilesString = cms.vstring(
"RecoEgamma/ElectronIdentification/data/TMVA_BDTSoftElectrons_7Feb2014.weights.xml"
),
ElecMVAFilesString = cms.vstring(
"RecoEgamma/ElectronIdentification/data/TMVA_BDTSimpleCat_17Feb2011.weights.xml"
),
)


Expand Down
6 changes: 6 additions & 0 deletions RecoEgamma/EgammaElectronProducers/python/gsfElectrons_cfi.py
Expand Up @@ -160,6 +160,9 @@
SoftElecMVAFilesString = cms.vstring(
"RecoEgamma/ElectronIdentification/data/TMVA_BDTSoftElectrons_9Dec2013.weights.xml"
),
ElecMVAFilesString = cms.vstring(
"RecoEgamma/ElectronIdentification/data/TMVA_BDTSimpleCat_17Feb2011.weights.xml"
),

)

Expand Down Expand Up @@ -331,6 +334,9 @@
SoftElecMVAFilesString = cms.vstring(
"RecoEgamma/ElectronIdentification/data/TMVA_BDTSoftElectrons_7Feb2014.weights.xml"
),
ElecMVAFilesString = cms.vstring(
"RecoEgamma/ElectronIdentification/data/TMVA_BDTSimpleCat_17Feb2011.weights.xml"
),
)


Expand Up @@ -7,12 +7,17 @@

class ElectronMVAEstimator {
public:
struct Configuration{
std::vector<std::string> vweightsfiles;
};
ElectronMVAEstimator();
ElectronMVAEstimator(std::string fileName);
ElectronMVAEstimator(const Configuration & );
~ElectronMVAEstimator() {;}
double mva(const reco::GsfElectron& myElectron, int nvertices=0);

private:
const Configuration cfg_;
void bindVariables();
void init(std::string fileName);

Expand Down
Expand Up @@ -132,13 +132,13 @@ bool ElectronIdMVABased::filter(edm::Event& iEvent, const edm::EventSetup& iSetu
if (eleEta <= 1.485 && mvaVal > thresholdBarrel && isoDr03 < thresholdIsoBarrel) {
mvaElectrons->push_back( *egIter );
reco::GsfElectron::MvaOutput myMvaOutput;
myMvaOutput.mva = mvaVal;
myMvaOutput.mva_Isolated = mvaVal;
mvaElectrons->back().setMvaOutput(myMvaOutput);
}
else if (eleEta > 1.485 && mvaVal > thresholdEndcap && isoDr03 < thresholdIsoEndcap) {
mvaElectrons->push_back( *egIter );
reco::GsfElectron::MvaOutput myMvaOutput;
myMvaOutput.mva = mvaVal;
myMvaOutput.mva_Isolated = mvaVal;
mvaElectrons->back().setMvaOutput(myMvaOutput);
}

Expand Down