Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:42

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   for (const auto& var : vars_) {
0043     names.push_back(var.first);
0044   }
0045   return names;
0046 }
0047 
0048 std::string trigger::EgammaObject::varNamesStr() const {
0049   std::string retVal;
0050   auto names = varNames();
0051   for (const auto& name : names) {
0052     if (!retVal.empty())
0053       retVal += " ";
0054     retVal += name;
0055   }
0056   return retVal;
0057 }
0058 
0059 void trigger::EgammaObject::setVars(std::vector<std::pair<std::string, float>> vars) {
0060   vars_ = std::move(vars);
0061   std::sort(vars_.begin(), vars_.end(), [](auto& lhs, auto& rhs) { return lhs.first < rhs.first; });
0062 }