Skip to content

Commit

Permalink
Move determination of max element into separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Oct 19, 2022
1 parent 2c4297a commit 55dd651
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/cpp/src/UTIL/LCRelationNavigator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,49 +68,54 @@ namespace UTIL{
return _rMap[ to ].second ;
}

auto getMaxWeightIt(const EVENT::FloatVec& weights, const std::string& weightType) {
if (weightType == "track") {
std::max_element(weights.begin(), weights.end(), [](float a, float b) {
return (int(a) % 10000) / 1000. < (int(b) % 10000) / 1000.;
});
} else if (weightType == "cluster") {
std::max_element(weights.begin(), weights.end(), [](float a, float b) {
return (int(a) / 10000) / 1000. < (int(b) / 10000) /1000.;
});
}
return std::max_element(weights.begin(), weights.end());
}

const EVENT::LCObject* LCRelationNavigator::getRelatedToMaxWeightObject(EVENT::LCObject* from, const std::string& weightType) const {
const auto& objects = getRelatedToObjects(from);
const auto& weights = getRelatedToWeights(from);
if ( objects.empty() ) return nullptr;
auto maxWeightIt = std::max_element(weights.begin(), weights.end(), [](float a, float b){return a < b;});
if (weightType == "track") maxWeightIt = std::max_element(weights.begin(), weights.end(), [](float a, float b){return (int(a)%10000)/1000. < (int(b)%10000)/1000.;});
else if (weightType == "cluster") maxWeightIt = std::max_element(weights.begin(), weights.end(), [](float a, float b){return (int(a)/10000)/1000. < (int(b)/10000)/1000. ;});

const auto& weights = getRelatedToWeights(from);
const auto maxWeightIt = getMaxWeightIt(weights, weightType);
int i = std::distance(weights.begin(), maxWeightIt);
return objects[i];
return objects[i];
}

const EVENT::LCObject* LCRelationNavigator::getRelatedFromMaxWeightObject(EVENT::LCObject* to, const std::string& weightType) const {
const auto& objects = getRelatedToObjects(to);
const auto& weights = getRelatedToWeights(to);
if ( objects.empty() ) return nullptr;

auto maxWeightIt = std::max_element(weights.begin(), weights.end(), [](float a, float b){return a < b;});
if (weightType == "track") maxWeightIt = std::max_element(weights.begin(), weights.end(), [](float a, float b){return (int(a)%10000)/1000. < (int(b)%10000)/1000.;});
else if (weightType == "cluster") maxWeightIt = std::max_element(weights.begin(), weights.end(), [](float a, float b){return (int(a)/10000)/1000. < (int(b)/10000)/1000. ;});
const auto& weights = getRelatedToWeights(to);
const auto maxWeightIt = getMaxWeightIt(weights, weightType);

int i = std::distance(weights.begin(), maxWeightIt);
return objects[i];
return objects[i];
}

float LCRelationNavigator::getRelatedToMaxWeight(EVENT::LCObject* from, const std::string& weightType) const {
const auto& objects = getRelatedToObjects(from);
const auto& weights = getRelatedToWeights(from);
if ( objects.empty() ) return 0.;

if (weightType == "track") return *std::max_element(weights.begin(), weights.end(), [](float a, float b){return (int(a)%10000)/1000. < (int(b)%10000)/1000.;});
else if (weightType == "cluster") return *std::max_element(weights.begin(), weights.end(), [](float a, float b){return (int(a)/10000)/1000. < (int(b)/10000)/1000. ;});
return *std::max_element(weights.begin(), weights.end(), [](float a, float b){return a < b ;});
const auto& weights = getRelatedToWeights(from);
return *getMaxWeightIt(weights, weightType);
}

float LCRelationNavigator::getRelatedFromMaxWeight(EVENT::LCObject* to, const std::string& weightType) const {
const auto& objects = getRelatedToObjects(to);
const auto& weights = getRelatedToWeights(to);
if ( objects.empty() ) return 0.;

if (weightType == "track") return *std::max_element(weights.begin(), weights.end(), [](float a, float b){return (int(a)%10000)/1000. < (int(b)%10000)/1000.;});
else if (weightType == "cluster") return *std::max_element(weights.begin(), weights.end(), [](float a, float b){return (int(a)/10000)/1000. < (int(b)/10000)/1000. ;});
return *std::max_element(weights.begin(), weights.end(), [](float a, float b){return a < b ;});
const auto& weights = getRelatedToWeights(to);
return *getMaxWeightIt(weights, weightType);
}

void LCRelationNavigator::addRelation(EVENT::LCObject * from,
Expand Down

0 comments on commit 55dd651

Please sign in to comment.