Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:09

0001 #include "PhysicsTools/SelectorUtils/interface/CutApplicatorWithEventContentBase.h"
0002 #include "DataFormats/EgammaCandidates/interface/Photon.h"
0003 
0004 class PhoFull5x5SigmaIEtaIEtaValueMapCut : public CutApplicatorWithEventContentBase {
0005 public:
0006   PhoFull5x5SigmaIEtaIEtaValueMapCut(const edm::ParameterSet& c);
0007 
0008   result_type operator()(const reco::PhotonPtr&) const final;
0009 
0010   void setConsumes(edm::ConsumesCollector&) final;
0011   void getEventContent(const edm::EventBase&) final;
0012 
0013   double value(const reco::CandidatePtr& cand) const final;
0014 
0015   CandidateType candidateType() const final { return PHOTON; }
0016 
0017 private:
0018   const float _cutValueEB;
0019   const float _cutValueEE;
0020   const float _barrelCutOff;
0021   edm::Handle<edm::ValueMap<float> > _full5x5SigmaIEtaIEtaMap;
0022 
0023   constexpr static char full5x5SigmaIEtaIEta_[] = "full5x5SigmaIEtaIEta";
0024 };
0025 
0026 constexpr char PhoFull5x5SigmaIEtaIEtaValueMapCut::full5x5SigmaIEtaIEta_[];
0027 
0028 DEFINE_EDM_PLUGIN(CutApplicatorFactory, PhoFull5x5SigmaIEtaIEtaValueMapCut, "PhoFull5x5SigmaIEtaIEtaValueMapCut");
0029 
0030 PhoFull5x5SigmaIEtaIEtaValueMapCut::PhoFull5x5SigmaIEtaIEtaValueMapCut(const edm::ParameterSet& c)
0031     : CutApplicatorWithEventContentBase(c),
0032       _cutValueEB(c.getParameter<double>("cutValueEB")),
0033       _cutValueEE(c.getParameter<double>("cutValueEE")),
0034       _barrelCutOff(c.getParameter<double>("barrelCutOff")) {
0035   edm::InputTag maptag = c.getParameter<edm::InputTag>("full5x5SigmaIEtaIEtaMap");
0036   contentTags_.emplace(full5x5SigmaIEtaIEta_, maptag);
0037 }
0038 
0039 void PhoFull5x5SigmaIEtaIEtaValueMapCut::setConsumes(edm::ConsumesCollector& cc) {
0040   auto full5x5SigmaIEtaIEta = cc.consumes<edm::ValueMap<float> >(contentTags_[full5x5SigmaIEtaIEta_]);
0041   contentTokens_.emplace(full5x5SigmaIEtaIEta_, full5x5SigmaIEtaIEta);
0042 }
0043 
0044 void PhoFull5x5SigmaIEtaIEtaValueMapCut::getEventContent(const edm::EventBase& ev) {
0045   ev.getByLabel(contentTags_[full5x5SigmaIEtaIEta_], _full5x5SigmaIEtaIEtaMap);
0046 }
0047 
0048 CutApplicatorBase::result_type PhoFull5x5SigmaIEtaIEtaValueMapCut::operator()(const reco::PhotonPtr& cand) const {
0049   // Figure out the cut value
0050   const float cutValue = (std::abs(cand->superCluster()->eta()) < _barrelCutOff ? _cutValueEB : _cutValueEE);
0051   float sihihval = -1.0;
0052   if (_full5x5SigmaIEtaIEtaMap.isValid() && _full5x5SigmaIEtaIEtaMap->contains(cand.id())) {
0053     sihihval = (*_full5x5SigmaIEtaIEtaMap)[cand];
0054   } else if (_full5x5SigmaIEtaIEtaMap.isValid() && _full5x5SigmaIEtaIEtaMap->idSize() == 1 &&
0055              cand.id() == edm::ProductID()) {
0056     // in case we have spoofed a ptr
0057     //note this must be a 1:1 valuemap (only one product input)
0058     sihihval = _full5x5SigmaIEtaIEtaMap->begin()[cand.key()];
0059   } else if (_full5x5SigmaIEtaIEtaMap.isValid()) {  // throw an exception
0060     sihihval = (*_full5x5SigmaIEtaIEtaMap)[cand];
0061   }
0062 
0063   // Retrieve the variable value for this particle
0064   const float full5x5SigmaIEtaIEta = _full5x5SigmaIEtaIEtaMap.isValid() ? sihihval : cand->full5x5_sigmaIetaIeta();
0065 
0066   // Apply the cut and return the result
0067   return full5x5SigmaIEtaIEta < cutValue;
0068 }
0069 
0070 double PhoFull5x5SigmaIEtaIEtaValueMapCut::value(const reco::CandidatePtr& cand) const {
0071   reco::PhotonPtr pho(cand);
0072   float sihihval = -1.0;
0073   if (_full5x5SigmaIEtaIEtaMap.isValid() && _full5x5SigmaIEtaIEtaMap->contains(cand.id())) {
0074     sihihval = (*_full5x5SigmaIEtaIEtaMap)[cand];
0075   } else if (_full5x5SigmaIEtaIEtaMap.isValid() && _full5x5SigmaIEtaIEtaMap->idSize() == 1 &&
0076              cand.id() == edm::ProductID()) {
0077     // in case we have spoofed a ptr
0078     //note this must be a 1:1 valuemap (only one product input)
0079     sihihval = _full5x5SigmaIEtaIEtaMap->begin()[cand.key()];
0080   } else if (_full5x5SigmaIEtaIEtaMap.isValid()) {  // throw an exception
0081     sihihval = (*_full5x5SigmaIEtaIEtaMap)[cand];
0082   }
0083 
0084   return _full5x5SigmaIEtaIEtaMap.isValid() ? sihihval : pho->full5x5_sigmaIetaIeta();
0085 }