Skip to content

Commit

Permalink
rework casting scheme inside of cut applicator so that it makes more …
Browse files Browse the repository at this point in the history
…sense and works
  • Loading branch information
lgray committed Aug 18, 2014
1 parent d8159ee commit 653342d
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ VersionedElectronIdProducer(const edm::ParameterSet& iConfig) {
forPat_.back()->setConsumes(consumesCollector());
} else {
forGsf_.emplace_back( new VersionedGsfElectronSelector(the_id) );
std::cout << "made the selector" << std::endl;
calculated_md5 = forGsf_.back()->md5String();
std::cout << "got the md5" << std::endl;
forGsf_.back()->setConsumes(consumesCollector());
std::cout << "set consumes" << std::endl;
}
if( idMD5 != calculated_md5 ) {
throw cms::Exception("IdConfigurationNotValidated")
Expand Down
18 changes: 12 additions & 6 deletions EgammaAnalysis/ElectronTools/plugins/cuts/GsfEleDzCut.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GsfEleDzCut : public CutApplicatorWithEventContentBase {
}

private:
const double _dzCutValue;
const double _dzCutValueEB,_dzCutValueEE,_barrelCutOff;
edm::Handle<reco::VertexCollection> _vtxs;
};

Expand All @@ -28,7 +28,9 @@ DEFINE_EDM_PLUGIN(CutApplicatorFactory,

GsfEleDzCut::GsfEleDzCut(const edm::ParameterSet& c) :
CutApplicatorWithEventContentBase(c),
_dzCutValue(c.getParameter<double>("dzCutValue")){
_dzCutValueEB(c.getParameter<double>("dzCutValueEB")),
_dzCutValueEE(c.getParameter<double>("dzCutValueEE")),
_barrelCutOff(c.getParameter<double>("barrelCutOff")) {
edm::InputTag vertextag = c.getParameter<edm::InputTag>("vertexSrc");
contentTags_.emplace("vertices",vertextag);
}
Expand All @@ -46,9 +48,13 @@ void GsfEleDzCut::getEventContent(const edm::EventBase& ev) {
CutApplicatorBase::result_type
GsfEleDzCut::
operator()(const reco::GsfElectronRef& cand) const{
const unsigned dzCutValue =
( std::abs(cand->superCluster()->position().eta()) < _barrelCutOff ?
_dzCutValueEB : _dzCutValueEE );

const reco::VertexCollection& vtxs = *_vtxs;
const double dxy = ( vtxs.size() ?
cand->gsfTrack()->dz(vtxs[0].position()) :
cand->gsfTrack()->dz() );
return dxy < _dzCutValue;
const double dz = ( vtxs.size() ?
cand->gsfTrack()->dz(vtxs[0].position()) :
cand->gsfTrack()->dz() );
return dz < dzCutValue;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ class GsfEleSigmaIEtaIEtaCut : public CutApplicatorBase {
public:
GsfEleSigmaIEtaIEtaCut(const edm::ParameterSet& c) :
CutApplicatorBase(c),
_sigmaIEtaIEtaCutValueEB(c.getParameter<double>("sigmaIEtaIEtaCutValue")),
_sigmaIEtaIEtaCutValueEE(c.getParameter<double>("sigmaIEtaIEtaCutValue")),
_sigmaIEtaIEtaCutValueEB(c.getParameter<double>("sigmaIEtaIEtaCutValueEB")),
_sigmaIEtaIEtaCutValueEE(c.getParameter<double>("sigmaIEtaIEtaCutValueEE")),
_barrelCutOff(c.getParameter<double>("barrelCutOff")) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,22 @@
dxyCutValueEB = cms.double(0.02),
dxyCutValueEE = cms.double(0.02),
vertexSrc = cms.InputTag("offlinePrimaryVertices"),
barrelCutoff = cms.double(ebCutOff),
barrelCutOff = cms.double(ebCutOff),
needsAdditionalProducts = cms.bool(True),
isIgnored = cms.bool(False)),
cms.PSet( cutName = cms.string('GsfEleDzCut'),
dzCutValueEB = cms.double(0.1),
dzCutValueEE = cms.double(0.1),
vertexSrc = cms.InputTag("offlinePrimaryVertices"),
barrelCutoff = cms.double(ebCutOff),
barrelCutOff = cms.double(ebCutOff),
needsAdditionalProducts = cms.bool(True),
isIgnored = cms.bool(False)),
cms.PSet( cutName = cms.string('GsfEleEInverseMinusPInverseCut'),
eInverseMinusPInverseCutValueEB = cms.double(0.05),
eInverseMinusPInverseCutValueEE = cms.double(0.05),
barrelCutoff = cms.double(ebCutOff)),
barrelCutOff = cms.double(ebCutOff),
needsAdditionalProducts = cms.bool(False),
isIgnored = cms.bool(False)),
cms.PSet( cutName = cms.string('GsfEleDeltaBetaIsoCutStandalone'),
isoCutEBLowPt = cms.double(0.13),
isoCutEBHighPt = cms.double(0.13),
Expand All @@ -71,7 +73,7 @@
isRelativeIso = cms.bool(True),
deltaBetaConstant = cms.double(0.5),
ptCutOff = cms.double(20.0),
barrelCutoff = cms.double(ebCutOff),
barrelCutOff = cms.double(ebCutOff),
needsAdditionalProducts = cms.bool(False),
isIgnored = cms.bool(False)),
cms.PSet( cutName = cms.string('GsfEleConversionVetoCut'),
Expand All @@ -82,11 +84,11 @@
cms.PSet( cutName = cms.string('GsfEleMissingHitsCut'),
maxMissingHitsEB = cms.uint32(0),
maxMissingHitsEE = cms.uint32(0),
barrelCutoff = cms.double(ebCutOff),
needsAdditionalProducts = cms.bool(True),
barrelCutOff = cms.double(ebCutOff),
needsAdditionalProducts = cms.bool(False),
isIgnored = cms.bool(False))
)
)

central_id_registry.register(cutBasedElectronID_CSA14_50ns_V0_standalone_tight.idName,
'57e95ddf2a8fa38fe6bdddcd060040c1')
'fb58e10ab7e555d5bb975828a8fd755f')
11 changes: 8 additions & 3 deletions EgammaAnalysis/ElectronTools/src/VersionedGsfElectronSelector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ initialize( const edm::ParameterSet& conf ) {
const std::string& name = cut.getParameter<std::string>("cutName");
const bool needsContent = cut.getParameter<bool>("needsAdditionalProducts");
const bool ignored = cut.getParameter<bool>("isIgnored");
cuts_.emplace_back(CutApplicatorFactory::get()->create(name,cut));
const auto* plugin = CutApplicatorFactory::get()->create(name,cut);
if( plugin != nullptr ) {
cuts_.emplace_back(CutApplicatorFactory::get()->create(name,cut));
} else {
throw cms::Exception("BadPluginName")
<< "The requested cut: " << name << " is not available!";
}
needs_event_content_.push_back(needsContent);
push_back(name);
set(name);
Expand All @@ -46,8 +52,7 @@ operator()(const reco::GsfElectronRef & electron,pat::strbitset & ret ) {
<< "VersionedGsfElectronSelector not initialized!" << std::endl;
}
for( unsigned i = 0; i < cuts_.size(); ++i ) {
reco::CandidateRef temp(electron.id(),electron.key(),
electron.productGetter());
reco::CandidateBaseRef temp(electron);
const bool result = (*cuts_[i])(temp);
if( result || ignoreCut(cut_indices_[i]) ) {
passCut(ret,cut_indices_[i]);
Expand Down
11 changes: 8 additions & 3 deletions EgammaAnalysis/ElectronTools/src/VersionedPatElectronSelector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ initialize( const edm::ParameterSet& conf ) {
const std::string& name = cut.getParameter<std::string>("cutName");
const bool needsContent = cut.getParameter<bool>("needsAdditionalProducts");
const bool ignored = cut.getParameter<bool>("isIgnored");
cuts_.emplace_back(CutApplicatorFactory::get()->create(name,cut));
const auto* plugin = CutApplicatorFactory::get()->create(name,cut);
if( plugin != nullptr ) {
cuts_.emplace_back(CutApplicatorFactory::get()->create(name,cut));
} else {
throw cms::Exception("BadPluginName")
<< "The requested cut: " << name << " is not available!";
}
needs_event_content_.push_back(needsContent);
push_back(name);
set(name);
Expand All @@ -46,8 +52,7 @@ operator()(const pat::ElectronRef & electron,pat::strbitset & ret ) {
<< "VersionedPatElectronSelector not initialized!" << std::endl;
}
for( unsigned i = 0; i < cuts_.size(); ++i ) {
reco::CandidateRef temp(electron.id(),electron.key(),
electron.productGetter());
reco::CandidateBaseRef temp(electron);
const bool result = (*cuts_[i])(temp);
if( result || ignoreCut(cut_indices_[i]) ) {
passCut(ret,cut_indices_[i]);
Expand Down
2 changes: 1 addition & 1 deletion PhysicsTools/SelectorUtils/interface/CandidateCut.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "DataFormats/Candidate/interface/CandidateFwd.h"

namespace candidate_functions {
class CandidateCut : public std::unary_function<reco::CandidateRef,bool>{
class CandidateCut : public std::unary_function<reco::CandidateBaseRef,bool>{
public:
virtual result_type operator()(const argument_type&) const = 0;
virtual ~CandidateCut() {}
Expand Down
2 changes: 1 addition & 1 deletion PhysicsTools/SelectorUtils/plugins/EtaMultiRangeCut.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ DEFINE_EDM_PLUGIN(CutApplicatorFactory,EtaMultiRangeCut,"EtaMultiRangeCut");

CutApplicatorBase::result_type
EtaMultiRangeCut::
asCandidate(const CutApplicatorBase::argument_type& cand) const{
asCandidate(const argument_type& cand) const{
const double the_eta = ( _absEta ? std::abs(cand->eta()) : cand->eta() );
bool result = false;
for(const auto& range : _ranges ) {
Expand Down
2 changes: 1 addition & 1 deletion PhysicsTools/SelectorUtils/plugins/MinPtCutInEtaRanges.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ DEFINE_EDM_PLUGIN(CutApplicatorFactory,MinPtCutInEtaRanges,

CutApplicatorBase::result_type
MinPtCutInEtaRanges::
asCandidate(const CutApplicatorBase::argument_type& cand) const{
asCandidate(const argument_type& cand) const{
const double the_eta = ( _absEta ? std::abs(cand->eta()) : cand->eta() );
bool result = false;
for( unsigned i = 0; i < _ranges.size(); ++i ) {
Expand Down
29 changes: 18 additions & 11 deletions PhysicsTools/SelectorUtils/src/CutApplicatorBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,66 @@ EDM_REGISTER_PLUGINFACTORY(CutApplicatorFactory,"CutApplicatorFactory");

CutApplicatorBase::result_type
CutApplicatorBase::
operator()(const CutApplicatorBase::argument_type& arg) const {
operator()(const CutApplicatorBase::argument_type& arg) const {
if( arg.isNull() ) {
throw cms::Exception("BadProductRef")
<< _name << "received a bad product ref to process!" << std::endl;
}

switch(candidateType()) {
case ELECTRON:
{
const reco::GsfElectronRef ele(arg.id(),arg.key(),arg.productGetter());
const reco::GsfElectronRef ele = arg.castTo<reco::GsfElectronRef>();
return this->operator()(ele);
}
break;
case MUON:
{
const reco::MuonRef mu(arg.id(),arg.key(),arg.productGetter());
const reco::MuonRef mu = arg.castTo<reco::MuonRef>();
return this->operator()(mu);
}
break;
case PHOTON:
{
const reco::PhotonRef pho(arg.id(),arg.key(),arg.productGetter());
const reco::PhotonRef pho = arg.castTo<reco::PhotonRef>();
return this->operator()(pho);
}
break;
case TAU:
{
const reco::PFTauRef tau(arg.id(),arg.key(),arg.productGetter());
const reco::PFTauRef tau = arg.castTo<reco::PFTauRef>();
return this->operator()(tau);
}
break;
case PATELECTRON:
{
const pat::ElectronRef ele(arg.id(),arg.key(),arg.productGetter());
const pat::ElectronRef ele = arg.castTo<pat::ElectronRef>();
return this->operator()(ele);
}
break;
case PATMUON:
{
const pat::MuonRef mu(arg.id(),arg.key(),arg.productGetter());
const pat::MuonRef mu = arg.castTo<pat::MuonRef>();
return this->operator()(mu);
}
break;
case PATPHOTON:
{
const pat::PhotonRef pho(arg.id(),arg.key(),arg.productGetter());
const pat::PhotonRef pho = arg.castTo<pat::PhotonRef>();
return this->operator()(pho);
}
break;
case PATTAU:
{
const pat::TauRef tau(arg.id(),arg.key(),arg.productGetter());
const pat::TauRef tau = arg.castTo<pat::TauRef>();
return this->operator()(tau);
}
break;
case NONE:
return asCandidate(arg);
break;
{
return asCandidate(arg);
break;
}
default:
throw cms::Exception("BadCandidateType")
<< "Unknown candidate type";
Expand Down

0 comments on commit 653342d

Please sign in to comment.