File indexing completed on 2024-04-06 12:25:06
0001 #include "PhysicsTools/SelectorUtils/interface/CutApplicatorBase.h"
0002 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0003 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
0004
0005 class GsfEleEcalDrivenCut : public CutApplicatorBase {
0006 public:
0007 GsfEleEcalDrivenCut(const edm::ParameterSet& c);
0008
0009 result_type operator()(const reco::GsfElectronPtr&) const final;
0010
0011 double value(const reco::CandidatePtr& cand) const final;
0012
0013 CandidateType candidateType() const final { return ELECTRON; }
0014
0015 private:
0016 static bool isValidCutVal(int val);
0017
0018 private:
0019 enum EcalDrivenCode { IGNORE = -1, FAIL = 0, PASS = 1 };
0020 const int ecalDrivenEB_, ecalDrivenEE_;
0021 const double barrelCutOff_;
0022 };
0023
0024 DEFINE_EDM_PLUGIN(CutApplicatorFactory, GsfEleEcalDrivenCut, "GsfEleEcalDrivenCut");
0025
0026 GsfEleEcalDrivenCut::GsfEleEcalDrivenCut(const edm::ParameterSet& c)
0027 : CutApplicatorBase(c),
0028 ecalDrivenEB_(static_cast<EcalDrivenCode>(c.getParameter<int>("ecalDrivenEB"))),
0029 ecalDrivenEE_(static_cast<EcalDrivenCode>(c.getParameter<int>("ecalDrivenEE"))),
0030 barrelCutOff_(c.getParameter<double>("barrelCutOff")) {
0031 if (!isValidCutVal(ecalDrivenEB_) || !isValidCutVal(ecalDrivenEE_)) {
0032 throw edm::Exception(edm::errors::Configuration)
0033 << "error in constructing GsfEleEcalDrivenCut" << std::endl
0034 << "values of ecalDrivenEB: " << ecalDrivenEB_ << " and/or ecalDrivenEE: " << ecalDrivenEE_ << " are invalid "
0035 << std::endl
0036 << "allowed values are IGNORE:" << IGNORE << " FAIL:" << FAIL << " PASS:" << PASS;
0037 }
0038 }
0039
0040 CutApplicatorBase::result_type GsfEleEcalDrivenCut::operator()(const reco::GsfElectronPtr& cand) const {
0041 const auto ecalDrivenRequirement =
0042 std::abs(cand->superCluster()->position().eta()) < barrelCutOff_ ? ecalDrivenEB_ : ecalDrivenEE_;
0043 if (ecalDrivenRequirement == IGNORE)
0044 return true;
0045 else if (ecalDrivenRequirement == FAIL)
0046 return !cand->ecalDriven();
0047 else if (ecalDrivenRequirement == PASS)
0048 return cand->ecalDriven();
0049 else {
0050 throw edm::Exception(edm::errors::LogicError) << "error in " << __FILE__ << " line " << __LINE__ << std::endl
0051 << "default option should not be reached, code has been updated "
0052 "without changing the logic, this needs to be fixed";
0053 }
0054 }
0055
0056 double GsfEleEcalDrivenCut::value(const reco::CandidatePtr& cand) const {
0057 reco::GsfElectronPtr ele(cand);
0058 return ele->ecalDriven();
0059 }
0060
0061 bool GsfEleEcalDrivenCut::isValidCutVal(int val) {
0062 if (val == IGNORE)
0063 return true;
0064 if (val == FAIL)
0065 return true;
0066 if (val == PASS)
0067 return true;
0068 return false;
0069 }