Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:23

0001 #include "DataFormats/HLTReco/interface/EgammaObject.h"
0002 
0003 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidate.h"
0004 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
0005 #include "DataFormats/EgammaReco/interface/ElectronSeed.h"
0006 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
0007 
0008 trigger::EgammaObject::EgammaObject(const reco::RecoEcalCandidate& ecalCand)
0009     : TriggerObject(ecalCand), hasPixelMatch_(false), superCluster_(ecalCand.superCluster()) {}
0010 
0011 void trigger::EgammaObject::setSeeds(reco::ElectronSeedRefVector seeds) {
0012   seeds_ = std::move(seeds);
0013   hasPixelMatch_ = false;
0014   for (const auto& seed : seeds_) {
0015     if (!seed->hitInfo().empty()) {
0016       hasPixelMatch_ = true;
0017       break;
0018     }
0019   }
0020 }
0021 
0022 bool trigger::EgammaObject::hasVar(const std::string& varName) const {
0023   return std::binary_search(vars_.begin(), vars_.end(), varName, VarComparer());
0024 }
0025 
0026 float trigger::EgammaObject::var(const std::string& varName, const bool raiseExcept) const {
0027   //here we have a guaranteed sorted vector with unique entries
0028   auto varIt = std::equal_range(vars_.begin(), vars_.end(), varName, VarComparer());
0029   if (varIt.first != varIt.second)
0030     return varIt.first->second;
0031   else if (raiseExcept) {
0032     cms::Exception ex("AttributeError");
0033     ex << " error variable " << varName << " is not present, variables present are " << varNamesStr();
0034     throw ex;
0035   } else {
0036     return std::numeric_limits<float>::max();
0037   }
0038 }
0039 
0040 std::vector<std::string> trigger::EgammaObject::varNames() const {
0041   std::vector<std::string> names;
0042   names.reserve(vars_.size());
0043   for (const auto& var : vars_) {
0044     names.push_back(var.first);
0045   }
0046   return names;
0047 }
0048 
0049 std::string trigger::EgammaObject::varNamesStr() const {
0050   std::string retVal;
0051   auto names = varNames();
0052   for (const auto& name : names) {
0053     if (!retVal.empty())
0054       retVal += " ";
0055     retVal += name;
0056   }
0057   return retVal;
0058 }
0059 
0060 void trigger::EgammaObject::setVars(std::vector<std::pair<std::string, float>> vars) {
0061   vars_ = std::move(vars);
0062   std::sort(vars_.begin(), vars_.end(), [](auto& lhs, auto& rhs) { return lhs.first < rhs.first; });
0063 }