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

miniAOD fixes from e/gamma merged together for 7412patch2 #11345

Merged
merged 12 commits into from Sep 18, 2015
Merged
Expand Up @@ -588,6 +588,7 @@ void EGExtraInfoModifierFromDB::modifyObject(pat::Photon& pho) const {
eval[12] = pho.sigmaIetaIeta();

float sipip=0, sieip=0, e2x5Max=0, e2x5Left=0, e2x5Right=0, e2x5Top=0, e2x5Bottom=0;
assignValue(ptr, ph_conf.tag_float_token_map.find(std::string("sigmaIetaIphi"))->second.second, pho_vmaps, sieip);
assignValue(ptr, ph_conf.tag_float_token_map.find(std::string("sigmaIphiIphi"))->second.second, pho_vmaps, sipip);
assignValue(ptr, ph_conf.tag_float_token_map.find(std::string("e2x5Max"))->second.second, pho_vmaps, e2x5Max);
assignValue(ptr, ph_conf.tag_float_token_map.find(std::string("e2x5Left"))->second.second, pho_vmaps, e2x5Left);
Expand Down
Expand Up @@ -288,7 +288,7 @@ fillMVAVariables(const edm::Ptr<reco::Candidate>& particle,
// Energy matching
allMVAVars.fbrem = eleRecoPtr->fbrem();

allMVAVars.gsfhits = eleRecoPtr->gsfTrack()->found();
allMVAVars.gsfhits = eleRecoPtr->gsfTrack()->hitPattern().trackerLayersWithMeasurement();
allMVAVars.expectedMissingInnerHits = eleRecoPtr->gsfTrack()
->hitPattern().numberOfHits(reco::HitPattern::MISSING_INNER_HITS);

Expand All @@ -305,7 +305,8 @@ fillMVAVariables(const edm::Ptr<reco::Candidate>& particle,

allMVAVars.EoP = eleRecoPtr->eSuperClusterOverP();
allMVAVars.eleEoPout = eleRecoPtr->eEleClusterOverPout();
allMVAVars.IoEmIoP = (1.0/eleRecoPtr->ecalEnergy()) - (1.0 / eleRecoPtr->p());
float pAtVertex = eleRecoPtr->trackMomentumAtVtx().R();
allMVAVars.IoEmIoP = (1.0/eleRecoPtr->ecalEnergy()) - (1.0 / pAtVertex );

// Geometrical matchings
allMVAVars.deta = eleRecoPtr->deltaEtaSuperClusterTrackAtVtx();
Expand Down

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions RecoEgamma/ElectronIdentification/test/BuildFile.xml
Expand Up @@ -6,10 +6,19 @@
<use name="CondFormats/EgammaObjects"/>
<use name="DataFormats/EgammaCandidates"/>
<use name="DataFormats/EcalRecHit"/>
<use name="CommonTools/UtilAlgos"/>
<use name="root"/>
<use name="rootcore"/>
<use name="RecoEgamma/EgammaTools"/>
<use name="RecoEgamma/ElectronIdentification"/>

<library name="RecoEgammaElectronIdentificationVIDExample" file="VIDUsageExample.cc">
<flags EDM_PLUGIN="1"/>
</library>

<environment>
<bin file="runtestRecoEgammaElectronIdentification.cpp">
<flags TEST_RUNNER_ARGS=" /bin/bash RecoEgamma/ElectronIdentification/test runtests.sh"/>
<use name="FWCore/Utilities"/>
</bin>
</environment>
80 changes: 80 additions & 0 deletions RecoEgamma/ElectronIdentification/test/runElectron_VID.py
@@ -0,0 +1,80 @@
import FWCore.ParameterSet.Config as cms
import sys

process = cms.Process("TestElectrons")

process.load("FWCore.MessageService.MessageLogger_cfi")
process.MessageLogger.cerr.FwkReport.reportEvery = 100

process.load("Configuration.StandardSequences.GeometryDB_cff")

process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
# NOTE: the pick the right global tag!
# for PHYS14 scenario PU4bx50 : global tag is ???
# for PHYS14 scenario PU20bx25: global tag is PHYS14_25_V1
# as a rule, find the global tag in the DAS under the Configs for given dataset
#process.GlobalTag.globaltag = 'PHYS14_25_V1::All'
from Configuration.AlCa.GlobalTag import GlobalTag
process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_mc', '')

#
# Define input data to read
#
process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(1000) )

inputFilesAOD = cms.untracked.vstring(
# AOD test files from /store/relval/CMSSW_7_4_8_patch1/RelValZEE_13/GEN-SIM-RECO/PU25ns_MCRUN2_74_V11_mulTrh-v1
'/store/relval/CMSSW_7_4_8_patch1/RelValZEE_13/GEN-SIM-RECO/PU25ns_MCRUN2_74_V11_mulTrh-v1/00000/001C7DBD-583C-E511-9107-0025905A60B2.root',
'/store/relval/CMSSW_7_4_8_patch1/RelValZEE_13/GEN-SIM-RECO/PU25ns_MCRUN2_74_V11_mulTrh-v1/00000/124BE41A-493C-E511-B909-0026189438DF.root',
'/store/relval/CMSSW_7_4_8_patch1/RelValZEE_13/GEN-SIM-RECO/PU25ns_MCRUN2_74_V11_mulTrh-v1/00000/AC6B87BB-953C-E511-8A84-002618943918.root',
'/store/relval/CMSSW_7_4_8_patch1/RelValZEE_13/GEN-SIM-RECO/PU25ns_MCRUN2_74_V11_mulTrh-v1/00000/C438BB08-5D3C-E511-9726-0025905A6084.root',
'/store/relval/CMSSW_7_4_8_patch1/RelValZEE_13/GEN-SIM-RECO/PU25ns_MCRUN2_74_V11_mulTrh-v1/00000/C89CDBD4-443C-E511-B817-0026189438A2.root',
'/store/relval/CMSSW_7_4_8_patch1/RelValZEE_13/GEN-SIM-RECO/PU25ns_MCRUN2_74_V11_mulTrh-v1/00000/F838C1BD-953C-E511-A59C-0025905A7786.root'
)

inputFilesMiniAOD = cms.untracked.vstring(
# MiniAOD test files from /store/relval/CMSSW_7_4_8_patch1/RelValZEE_13/MINIAODSIM/PU25ns_MCRUN2_74_V11_mulTrh-v1
'/store/relval/CMSSW_7_4_8_patch1/RelValZEE_13/MINIAODSIM/PU25ns_MCRUN2_74_V11_mulTrh-v1/00000/445E75C0-953C-E511-95A1-0025905A6056.root',
'/store/relval/CMSSW_7_4_8_patch1/RelValZEE_13/MINIAODSIM/PU25ns_MCRUN2_74_V11_mulTrh-v1/00000/D85014C3-953C-E511-B0C0-003048FFD71E.root'
)

# Set up input/output depending on the format
# You can list here either AOD or miniAOD files, but not both types mixed
#

print sys.argv[2]
useAOD = bool(int(sys.argv[2]))

if useAOD == True :
inputFiles = inputFilesAOD
outputFile = "electron_ntuple.root"
print("AOD input files are used")
else :
inputFiles = inputFilesMiniAOD
outputFile = "electron_ntuple_mini.root"
print("MiniAOD input files are used")
process.source = cms.Source ("PoolSource", fileNames = inputFiles )

#
# Set up electron ID (VID framework)
#

from PhysicsTools.SelectorUtils.tools.vid_id_tools import *
# turn on VID producer, indicate data format to be
# DataFormat.AOD or DataFormat.MiniAOD, as appropriate
if useAOD == True :
dataFormat = DataFormat.AOD
else :
dataFormat = DataFormat.MiniAOD

switchOnVIDElectronIdProducer(process, dataFormat)

# define which IDs we want to produce
my_id_modules = [sys.argv[3]]

#add them to the VID producer
for idmod in my_id_modules:
setupAllVIDIdsInModule(process,idmod,setupVIDElectronSelection)

# Make sure to add the ID sequence upstream from the user analysis module
process.p = cms.Path(process.egmGsfElectronIDSequence)
@@ -0,0 +1,3 @@
#include "FWCore/Utilities/interface/TestHelper.h"

RUNTEST()
15 changes: 15 additions & 0 deletions RecoEgamma/ElectronIdentification/test/runtests.sh
@@ -0,0 +1,15 @@
function die { echo $1: status $2 ; exit $2; }

ids_to_test=(
"RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_PHYS14_PU20bx25_V2_cff"
"RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Spring15_25ns_V1_cff"
"RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Spring15_50ns_V1_cff"
"RecoEgamma.ElectronIdentification.Identification.heepElectronID_HEEPV60_cff"
"RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring15_25ns_nonTrig_V1_cff"
)

for id_set in "${ids_to_test[@]}"; do
echo Checking: $id_set
cmsRun ${LOCAL_TEST_DIR}/runElectron_VID.py 1 $id_set || die "Failure using runElectron_VID.py on AOD $id_set" $?
cmsRun ${LOCAL_TEST_DIR}/runElectron_VID.py 0 $id_set || die "Failure using runElectron_VID.py on MiniAOD $id_set" $?
done
Expand Up @@ -18,16 +18,71 @@

#include <memory>
#include <vector>
#include <unordered_map>

namespace {
// Cluster shapes
constexpr char sigmaIPhiIPhi_[] = "sigmaIPhiIPhi";
constexpr char sigmaIEtaIPhi_[] = "sigmaIEtaIPhi";
constexpr char e2x5Max_[] = "e2x5Max";
constexpr char e2x5Left_[] = "e2x5Left";
constexpr char e2x5Right_[] = "e2x5Right";
constexpr char e2x5Top_[] = "e2x5Top";
constexpr char e2x5Bottom_[] = "e2x5Bottom";
enum reg_float_vars { k_sigmaIPhiIPhi = 0,
k_sigmaIEtaIPhi,
k_e2x5Max,
k_e2x5Left,
k_e2x5Right,
k_e2x5Top,
k_e2x5Bottom,
k_NFloatVars };

enum reg_int_vars { k_NIntVars = 0 };

static const std::vector<std::string> float_var_names( { "sigmaIPhiIPhi",
"sigmaIEtaIPhi",
"e2x5Max",
"e2x5Left",
"e2x5Right",
"e2x5Top",
"e2x5Bottom" } );

static const std::vector<std::string> integer_var_names( { } );

inline void set_map_val( const reg_float_vars index, const float value,
std::unordered_map<std::string,float>& map) {
map[float_var_names[index]] = value;
}
inline void set_map_val( const reg_int_vars index, const int value,
std::unordered_map<std::string,int>& map) {
map[integer_var_names[index]] = value;
}

template<typename T>
inline void check_map(const std::unordered_map<std::string,T>& map, unsigned exp_size) {
if( map.size() != exp_size ) {
throw cms::Exception("PhotonRegressionWeirdConfig")
<< "variable map size: " << map.size()
<< " not equal to expected size: " << exp_size << " !"
<< " The regression variable calculation code definitely has a bug, fix it!";
}
}

template<typename LazyTools,typename SeedType>
inline void calculateValues(EcalClusterLazyToolsBase* tools_tocast,
const SeedType& the_seed,
std::unordered_map<std::string,float>& float_vars,
std::unordered_map<std::string,int>& /*int_vars*/ ) {
LazyTools* tools = static_cast<LazyTools*>(tools_tocast);

float spp = -999;
std::vector<float> vCov = tools->localCovariances( the_seed );
spp = (isnan(vCov[2]) ? 0. : sqrt(vCov[2]));
float sep = vCov[1];

set_map_val(k_sigmaIPhiIPhi, spp, float_vars);
set_map_val(k_sigmaIEtaIPhi, sep, float_vars);

set_map_val(k_e2x5Max, tools->e2x5Max(the_seed), float_vars);
set_map_val(k_e2x5Left, tools->e2x5Left(the_seed), float_vars);
set_map_val(k_e2x5Right, tools->e2x5Right(the_seed), float_vars);
set_map_val(k_e2x5Top, tools->e2x5Top(the_seed), float_vars);
set_map_val(k_e2x5Bottom, tools->e2x5Bottom(the_seed), float_vars);
}
}

class PhotonRegressionValueMapProducer : public edm::stream::EDProducer<> {
Expand All @@ -43,9 +98,10 @@ class PhotonRegressionValueMapProducer : public edm::stream::EDProducer<> {

virtual void produce(edm::Event&, const edm::EventSetup&) override;

template<typename T>
void writeValueMap(edm::Event &iEvent,
const edm::Handle<edm::View<reco::Photon> > & handle,
const std::vector<float> & values,
const std::vector<T> & values,
const std::string & label) const ;

// The object that will compute 5x5 quantities
Expand Down Expand Up @@ -95,43 +151,18 @@ PhotonRegressionValueMapProducer::PhotonRegressionValueMapProducer(const edm::Pa
// Declare producibles
//
// Cluster shapes
produces<edm::ValueMap<float> >(sigmaIPhiIPhi_);
produces<edm::ValueMap<float> >(sigmaIEtaIPhi_);
produces<edm::ValueMap<float> >(e2x5Max_);
produces<edm::ValueMap<float> >(e2x5Left_);
produces<edm::ValueMap<float> >(e2x5Right_);
produces<edm::ValueMap<float> >(e2x5Top_);
produces<edm::ValueMap<float> >(e2x5Bottom_);
for( const std::string& name : float_var_names ) {
produces<edm::ValueMap<float> >(name);
}

for( const std::string& name : integer_var_names ) {
produces<edm::ValueMap<int> >(name);
}
}

PhotonRegressionValueMapProducer::~PhotonRegressionValueMapProducer()
{}

template<typename LazyTools,typename SeedType>
inline void calculateValues(EcalClusterLazyToolsBase* tools_tocast,
const SeedType& the_seed,
std::vector<float>& sigmaIPhiIPhi,
std::vector<float>& sigmaIEtaIPhi,
std::vector<float>& e2x5Max,
std::vector<float>& e2x5Left,
std::vector<float>& e2x5Right,
std::vector<float>& e2x5Top,
std::vector<float>& e2x5Bottom) {
LazyTools* tools = static_cast<LazyTools*>(tools_tocast);

float spp = -999;
std::vector<float> vCov = tools->localCovariances( the_seed );
spp = (isnan(vCov[2]) ? 0. : sqrt(vCov[2]));
float sep = vCov[1];
sigmaIPhiIPhi.push_back(spp);
sigmaIEtaIPhi.push_back(sep);
e2x5Max .push_back(tools->e2x5Max(the_seed) );
e2x5Left .push_back(tools->e2x5Left(the_seed) );
e2x5Right .push_back(tools->e2x5Right(the_seed) );
e2x5Top .push_back(tools->e2x5Top(the_seed) );
e2x5Bottom.push_back(tools->e2x5Bottom(the_seed) );
}

void PhotonRegressionValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {

using namespace edm;
Expand Down Expand Up @@ -179,14 +210,11 @@ void PhotonRegressionValueMapProducer::produce(edm::Event& iEvent, const edm::Ev
}
}

// Cluster shapes
std::vector<float> sigmaIPhiIPhi;
std::vector<float> sigmaIEtaIPhi;
std::vector<float> e2x5Max;
std::vector<float> e2x5Left;
std::vector<float> e2x5Right;
std::vector<float> e2x5Top;
std::vector<float> e2x5Bottom;
std::vector<std::vector<float> > float_vars(k_NFloatVars);
std::vector<std::vector<int> > int_vars(k_NIntVars);

std::unordered_map<std::string,float> float_vars_map;
std::unordered_map<std::string,int> int_vars_map;

// reco::Photon::superCluster() is virtual so we can exploit polymorphism
for (unsigned idxpho = 0; idxpho < src->size(); ++idxpho) {
Expand All @@ -200,47 +228,52 @@ void PhotonRegressionValueMapProducer::produce(edm::Event& iEvent, const edm::Ev
if( use_full5x5_ ) {
calculateValues<noZS::EcalClusterLazyTools>(lazyTools.get(),
theseed,
sigmaIPhiIPhi,
sigmaIEtaIPhi,
e2x5Max,
e2x5Left,
e2x5Right,
e2x5Top,
e2x5Bottom);
float_vars_map,
int_vars_map);
} else {
calculateValues<EcalClusterLazyTools>(lazyTools.get(),
theseed,
sigmaIPhiIPhi,
sigmaIEtaIPhi,
e2x5Max,
e2x5Left,
e2x5Right,
e2x5Top,
e2x5Bottom);
}
float_vars_map,
int_vars_map);
}

check_map(float_vars_map, k_NFloatVars);
check_map(int_vars_map, k_NIntVars);

for( unsigned i = 0; i < float_vars.size(); ++i ) {
float_vars[i].emplace_back(float_vars_map.at(float_var_names[i]));
}


for( unsigned i = 0; i < int_vars.size(); ++i ) {
int_vars[i].emplace_back(int_vars_map.at(integer_var_names[i]));
}

}

for( unsigned i = 0; i < float_vars.size(); ++i ) {
writeValueMap(iEvent, src, float_vars[i], float_var_names[i]);
}

for( unsigned i = 0; i < int_vars.size(); ++i ) {
writeValueMap(iEvent, src, int_vars[i], integer_var_names[i]);
}

// Cluster shapes
writeValueMap(iEvent, src, sigmaIPhiIPhi, sigmaIPhiIPhi_);
writeValueMap(iEvent, src, sigmaIEtaIPhi, sigmaIEtaIPhi_);
writeValueMap(iEvent, src, e2x5Max, e2x5Max_);
writeValueMap(iEvent, src, e2x5Left, e2x5Left_);
writeValueMap(iEvent, src, e2x5Right, e2x5Right_);
writeValueMap(iEvent, src, e2x5Top, e2x5Top_);
writeValueMap(iEvent, src, e2x5Bottom, e2x5Bottom_);

lazyTools.reset(nullptr);
}

template<typename T>
void PhotonRegressionValueMapProducer::writeValueMap(edm::Event &iEvent,
const edm::Handle<edm::View<reco::Photon> > & handle,
const std::vector<float> & values,
const std::vector<T> & values,
const std::string & label) const
{
using namespace edm;
using namespace std;
auto_ptr<ValueMap<float> > valMap(new ValueMap<float>());
edm::ValueMap<float>::Filler filler(*valMap);
typedef ValueMap<T> TValueMap;

auto_ptr<TValueMap> valMap(new TValueMap());
typename TValueMap::Filler filler(*valMap);
filler.insert(handle, values.begin(), values.end());
filler.fill();
iEvent.put(valMap, label);
Expand Down
6 changes: 6 additions & 0 deletions RecoEgamma/PhotonIdentification/test/BuildFile.xml
@@ -0,0 +1,6 @@
<environment>
<bin file="runtestRecoEgammaPhotonIdentification.cpp">
<flags TEST_RUNNER_ARGS=" /bin/bash RecoEgamma/PhotonIdentification/test runtests.sh"/>
<use name="FWCore/Utilities"/>
</bin>
</environment>