Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use algorithms properties in CalorimeterClusterRecoCoG (2) #1165

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/algorithms/calorimetry/CalorimeterClusterRecoCoG.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <vector>

#include "CalorimeterClusterRecoCoG.h"
#include "algorithms/calorimetry/CalorimeterClusterRecoCoGConfig.h"

namespace eicrecon {

Expand All @@ -40,12 +39,12 @@ namespace eicrecon {
m_log = logger;

// select weighting method
std::string ew = m_cfg.energyWeight;
std::string ew = m_energyWeight;
// make it case-insensitive
std::transform(ew.begin(), ew.end(), ew.begin(), [](char s) { return std::tolower(s); });
auto it = weightMethods.find(ew);
if (it == weightMethods.end()) {
m_log->error("Cannot find energy weighting method {}, choose one from [{}]", m_cfg.energyWeight, boost::algorithm::join(weightMethods | boost::adaptors::map_keys, ", "));
m_log->error("Cannot find energy weighting method {}, choose one from [{}]", m_energyWeight, boost::algorithm::join(weightMethods | boost::adaptors::map_keys, ", "));
return;
}
weightFunc = it->second;
Expand Down Expand Up @@ -185,7 +184,7 @@ std::optional<edm4eic::Cluster> CalorimeterClusterRecoCoG::reconstruct(const edm
maxHitEta = eta;
}
}
cl.setEnergy(totalE / m_cfg.sampFrac);
cl.setEnergy(totalE / m_samplingFraction);
cl.setEnergyError(0.);
cl.setTime(time);
cl.setTimeError(timeError);
Expand All @@ -197,7 +196,7 @@ std::optional<edm4eic::Cluster> CalorimeterClusterRecoCoG::reconstruct(const edm
const auto& hit = pcl.getHits()[i];
const auto weight = pcl.getWeights()[i];
// _DBG_<<" -- weight = " << weight << " E=" << hit.getEnergy() << " totalE=" <<totalE << " log(E/totalE)=" << std::log(hit.getEnergy()/totalE) << std::endl;
float w = weightFunc(hit.getEnergy() * weight, totalE, m_cfg.logWeightBase, 0);
float w = weightFunc(hit.getEnergy() * weight, totalE, m_logWeightBase, 0);
tw += w;
v = v + (hit.getPosition() * w);
}
Expand All @@ -209,7 +208,7 @@ std::optional<edm4eic::Cluster> CalorimeterClusterRecoCoG::reconstruct(const edm
cl.setPositionError({}); // @TODO: Covariance matrix

// Optionally constrain the cluster to the hit eta values
if (m_cfg.enableEtaBounds) {
if (m_enableEtaBounds) {
const bool overflow = (edm4hep::utils::eta(cl.getPosition()) > maxHitEta);
const bool underflow = (edm4hep::utils::eta(cl.getPosition()) < minHitEta);
if (overflow || underflow) {
Expand Down Expand Up @@ -249,7 +248,7 @@ std::optional<edm4eic::Cluster> CalorimeterClusterRecoCoG::reconstruct(const edm

for (const auto& hit : pcl.getHits()) {

float w = weightFunc(hit.getEnergy(), cl.getEnergy(), m_cfg.logWeightBase, 0);
float w = weightFunc(hit.getEnergy(), cl.getEnergy(), m_logWeightBase, 0);

// theta, phi
Eigen::Vector2f pos2D( edm4hep::utils::anglePolar( hit.getPosition() ), edm4hep::utils::angleAzimuthal( hit.getPosition() ) );
Expand Down
14 changes: 9 additions & 5 deletions src/algorithms/calorimetry/CalorimeterClusterRecoCoG.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
#include <string_view>
#include <utility>

#include "CalorimeterClusterRecoCoGConfig.h"
#include "algorithms/interfaces/WithPodConfig.h"

static double constWeight(double /*E*/, double /*tE*/, double /*p*/, int /*type*/) { return 1.0; }
static double linearWeight(double E, double /*tE*/, double /*p*/, int /*type*/) { return E; }
static double logWeight(double E, double tE, double base, int /*type*/) {
Expand Down Expand Up @@ -61,8 +58,7 @@ namespace eicrecon {
>;

class CalorimeterClusterRecoCoG
: public CalorimeterClusterRecoCoGAlgorithm,
public WithPodConfig<CalorimeterClusterRecoCoGConfig> {
: public CalorimeterClusterRecoCoGAlgorithm {

public:
CalorimeterClusterRecoCoG(std::string_view name)
Expand All @@ -87,6 +83,14 @@ namespace eicrecon {

std::optional<edm4eic::Cluster> reconstruct(const edm4eic::ProtoCluster& pcl) const;

Property<double> m_samplingFraction{this, "samplingFraction", 1.0, "Sampling fraction"};
Property<double> m_logWeightBase{this, "logWeightBase", 3.6, "Weight base for log weighting"};
Property<std::string> m_energyWeight{this, "energyWeight", "log", "Default hit weight method"};
// Constrain the cluster position eta to be within
// the eta of the contributing hits. This is useful to avoid edge effects
// for endcaps.
Property<bool> m_enableEtaBounds{this, "enableEtaBounds", false, "Constrain cluster to hit eta?"};

};

} // eicrecon
16 changes: 8 additions & 8 deletions src/detectors/B0ECAL/B0ECAL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ extern "C" {
{"B0ECalClusters", // edm4eic::Cluster
"B0ECalClusterAssociations"}, // edm4eic::MCRecoClusterParticleAssociation
{
.energyWeight = "log",
.sampFrac = 1.0,
.logWeightBase = 3.6,
.enableEtaBounds = false
{"energyWeight", "log"},
{"samplingFraction", 1.0},
{"logWeightBase", 3.6},
{"enableEtaBounds", false}
},
app
)
Expand All @@ -97,10 +97,10 @@ extern "C" {
{"B0ECalTruthClusters", // edm4eic::Cluster
"B0ECalTruthClusterAssociations"}, // edm4eic::MCRecoClusterParticleAssociation
{
.energyWeight = "log",
.sampFrac = 1.0,
.logWeightBase = 6.2,
.enableEtaBounds = false
{"energyWeight", "log"},
{"samplingFraction", 1.0},
{"logWeightBase", 6.2},
{"enableEtaBounds", false}
},
app
)
Expand Down
8 changes: 4 additions & 4 deletions src/detectors/BEMC/BEMC.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ extern "C" {
{"EcalBarrelScFiClusters", // edm4eic::Cluster
"EcalBarrelScFiClusterAssociations"}, // edm4eic::MCRecoClusterParticleAssociation
{
.energyWeight = "log",
.sampFrac = 1.0,
.logWeightBase = 6.2,
.enableEtaBounds = false
{"energyWeight", "log"},
{"samplingFraction", 1.0},
{"logWeightBase", 6.2},
{"enableEtaBounds", false}
},
app // TODO: Remove me once fixed
)
Expand Down
16 changes: 8 additions & 8 deletions src/detectors/BHCAL/BHCAL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ extern "C" {
{"HcalBarrelClusters", // edm4eic::Cluster
"HcalBarrelClusterAssociations"}, // edm4eic::MCRecoClusterParticleAssociation
{
.energyWeight = "log",
.sampFrac = 1.0,
.logWeightBase = 6.2,
.enableEtaBounds = false
{"energyWeight", "log"},
{"samplingFraction", 1.0},
{"logWeightBase", 6.2},
{"enableEtaBounds", false}
},
app // TODO: Remove me once fixed
)
Expand All @@ -119,10 +119,10 @@ extern "C" {
{"HcalBarrelTruthClusters", // edm4eic::Cluster
"HcalBarrelTruthClusterAssociations"}, // edm4eic::MCRecoClusterParticleAssociation
{
.energyWeight = "log",
.sampFrac = 1.0,
.logWeightBase = 6.2,
.enableEtaBounds = false
{"energyWeight", "log"},
{"samplingFraction", 1.0},
{"logWeightBase", 6.2},
{"enableEtaBounds", false}
},
app // TODO: Remove me once fixed
)
Expand Down
16 changes: 8 additions & 8 deletions src/detectors/EEMC/EEMC.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ extern "C" {
{"EcalEndcapNTruthClusters", // edm4eic::Cluster
"EcalEndcapNTruthClusterAssociations"}, // edm4eic::MCRecoClusterParticleAssociation
{
.energyWeight = "log",
.sampFrac = 1.0,
.logWeightBase = 4.6,
.enableEtaBounds = false
{"energyWeight", "log"},
{"samplingFraction", 1.0},
{"logWeightBase", 4.6},
{"enableEtaBounds", false}
},
app // TODO: Remove me once fixed
)
Expand All @@ -104,10 +104,10 @@ extern "C" {
{"EcalEndcapNClusters", // edm4eic::Cluster
"EcalEndcapNClusterAssociations"}, // edm4eic::MCRecoClusterParticleAssociation
{
.energyWeight = "log",
.sampFrac = 1.0,
.logWeightBase = 3.6,
.enableEtaBounds = false,
{"energyWeight", "log"},
{"samplingFraction", 1.0},
{"logWeightBase", 3.6},
{"enableEtaBounds", false}
},
app // TODO: Remove me once fixed
)
Expand Down
16 changes: 8 additions & 8 deletions src/detectors/EHCAL/EHCAL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ extern "C" {
{"HcalEndcapNTruthClusters", // edm4eic::Cluster
"HcalEndcapNTruthClusterAssociations"}, // edm4eic::MCRecoClusterParticleAssociation
{
.energyWeight = "log",
.sampFrac = 1.0,
.logWeightBase = 6.2,
.enableEtaBounds = false
{"energyWeight", "log"},
{"samplingFraction", 1.0},
{"logWeightBase", 6.2},
{"enableEtaBounds", false}
},
app // TODO: Remove me once fixed
)
Expand All @@ -108,10 +108,10 @@ extern "C" {
{"HcalEndcapNClusters", // edm4eic::Cluster
"HcalEndcapNClusterAssociations"}, // edm4eic::MCRecoClusterParticleAssociation
{
.energyWeight = "log",
.sampFrac = 1.0,
.logWeightBase = 6.2,
.enableEtaBounds = false,
{"energyWeight", "log"},
{"samplingFraction", 1.0},
{"logWeightBase", 6.2},
{"enableEtaBounds", false}
},
app // TODO: Remove me once fixed
)
Expand Down
32 changes: 16 additions & 16 deletions src/detectors/FEMC/FEMC.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ extern "C" {
{"EcalEndcapPTruthClusters", // edm4eic::Cluster
"EcalEndcapPTruthClusterAssociations"}, // edm4eic::MCRecoClusterParticleAssociation
{
.energyWeight = "log",
.sampFrac = 1.0,
.logWeightBase = 6.2,
.enableEtaBounds = true
{"energyWeight", "log"},
{"samplingFraction", 1.0},
{"logWeightBase", 6.2},
{"enableEtaBounds", true}
},
app // TODO: Remove me once fixed
)
Expand All @@ -104,10 +104,10 @@ extern "C" {
{"EcalEndcapPClusters", // edm4eic::Cluster
"EcalEndcapPClusterAssociations"}, // edm4eic::MCRecoClusterParticleAssociation
{
.energyWeight = "log",
.sampFrac = 1.0,
.logWeightBase = 3.6,
.enableEtaBounds = false,
{"energyWeight", "log"},
{"samplingFraction", 1.0},
{"logWeightBase", 3.6},
{"enableEtaBounds", false}
},
app // TODO: Remove me once fixed
)
Expand Down Expand Up @@ -173,10 +173,10 @@ extern "C" {
{"EcalEndcapPInsertTruthClusters", // edm4eic::Cluster
"EcalEndcapPInsertTruthClusterAssociations"}, // edm4eic::MCRecoClusterParticleAssociation
{
.energyWeight = "log",
.sampFrac = 1.0,
.logWeightBase = 6.2,
.enableEtaBounds = true
{"energyWeight", "log"},
{"samplingFraction", 1.0},
{"logWeightBase", 6.2},
{"enableEtaBounds", true}
},
app // TODO: Remove me once fixed
)
Expand All @@ -190,10 +190,10 @@ extern "C" {
{"EcalEndcapPInsertClusters", // edm4eic::Cluster
"EcalEndcapPInsertClusterAssociations"}, // edm4eic::MCRecoClusterParticleAssociation
{
.energyWeight = "log",
.sampFrac = 1.0,
.logWeightBase = 3.6,
.enableEtaBounds = false,
{"energyWeight", "log"},
{"samplingFraction", 1.0},
{"logWeightBase", 3.6},
{"enableEtaBounds", false}
},
app // TODO: Remove me once fixed
)
Expand Down
32 changes: 16 additions & 16 deletions src/detectors/FHCAL/FHCAL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ extern "C" {
{"HcalEndcapPInsertTruthClusters", // edm4eic::Cluster
"HcalEndcapPInsertTruthClusterAssociations"}, // edm4eic::MCRecoClusterParticleAssociation
{
.energyWeight = "log",
.sampFrac = 1.0,
.logWeightBase = 3.6,
.enableEtaBounds = true
{"energyWeight", "log"},
{"samplingFraction", 1.0},
{"logWeightBase", 3.6},
{"enableEtaBounds", true}
},
app // TODO: Remove me once fixed
)
Expand All @@ -112,10 +112,10 @@ extern "C" {
{"HcalEndcapPInsertClusters", // edm4eic::Cluster
"HcalEndcapPInsertClusterAssociations"}, // edm4eic::MCRecoClusterParticleAssociation
{
.energyWeight = "log",
.sampFrac = 1.0,
.logWeightBase = 6.2,
.enableEtaBounds = false,
{"energyWeight", "log"},
{"samplingFraction", 1.0},
{"logWeightBase", 6.2},
{"enableEtaBounds", false}
},
app // TODO: Remove me once fixed
)
Expand Down Expand Up @@ -223,10 +223,10 @@ extern "C" {
{"LFHCALTruthClusters", // edm4eic::Cluster
"LFHCALTruthClusterAssociations"}, // edm4eic::MCRecoClusterParticleAssociation
{
.energyWeight = "log",
.sampFrac = 1.0,
.logWeightBase = 4.5,
.enableEtaBounds = false
{"energyWeight", "log"},
{"samplingFraction", 1.0},
{"logWeightBase", 4.5},
{"enableEtaBounds", false}
},
app // TODO: Remove me once fixed
)
Expand All @@ -240,10 +240,10 @@ extern "C" {
{"LFHCALClusters", // edm4eic::Cluster
"LFHCALClusterAssociations"}, // edm4eic::MCRecoClusterParticleAssociation
{
.energyWeight = "log",
.sampFrac = 1.0,
.logWeightBase = 4.5,
.enableEtaBounds = false,
{"energyWeight", "log"},
{"samplingFraction", 1.0},
{"logWeightBase", 4.5},
{"enableEtaBounds", false}
},
app // TODO: Remove me once fixed
)
Expand Down
16 changes: 8 additions & 8 deletions src/detectors/LUMISPECCAL/LUMISPECCAL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ extern "C" {
{"EcalLumiSpecClusters", // edm4eic::Cluster
"EcalLumiSpecClusterAssociations"}, // edm4eic::MCRecoClusterParticleAssociation
{
.energyWeight = "log",
.sampFrac = 1.0,
.logWeightBase = 3.6,
.enableEtaBounds = false
{"energyWeight", "log"},
{"samplingFraction", 1.0},
{"logWeightBase", 3.6},
{"enableEtaBounds", false}
},
app // TODO: Remove me once fixed
)
Expand All @@ -97,10 +97,10 @@ extern "C" {
{"EcalLumiSpecTruthClusters", // edm4eic::Cluster
"EcalLumiSpecTruthClusterAssociations"}, // edm4eic::MCRecoClusterParticleAssociation
{
.energyWeight = "log",
.sampFrac = 1.0,
.logWeightBase = 4.6,
.enableEtaBounds = false
{"energyWeight", "log"},
{"samplingFraction", 1.0},
{"logWeightBase", 4.6},
{"enableEtaBounds", false}
},
app // TODO: Remove me once fixed
)
Expand Down
Loading
Loading