Skip to content

Commit

Permalink
feat: convert calorimetry JFactoryT to JChainFactoryT (#785)
Browse files Browse the repository at this point in the history
All of the calorimetry factories are currently JFactoryT instead of
JChainFactoryT, which means that they don't allow for providing a
configuration object in the plugin (think: BEMC.cc).

This converts all calorimetry JFactoryT factories to JChainFactoryT,
which requires that we specify also the set of input tags, and the
output tag in the JChainFactoryGeneratorT constructor in the plugin.
These are therefore removed from the factories since they are set in the
plugin.

The third argument of the JChainFactoryGeneratorT can become the config
object, which can now be introduced in a separate PR, algorithm by
algorithm.

All this fits in a three-step process towards simplification:
- make calorimetry algorithms accept external config objects
- collect all configuration in plugin
- remove or reduce dedicate factory code
  • Loading branch information
wdconinc authored Jul 23, 2023
1 parent 81edf9b commit 3283395
Show file tree
Hide file tree
Showing 71 changed files with 642 additions and 664 deletions.
17 changes: 13 additions & 4 deletions src/detectors/B0ECAL/B0ECAL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//
//

#include <extensions/jana/JChainFactoryGeneratorT.h>
#include <extensions/jana/JChainMultifactoryGeneratorT.h>

#include <factories/calorimetry/CalorimeterClusterRecoCoG_factoryT.h>
Expand All @@ -26,10 +27,18 @@ extern "C" {

InitJANAPlugin(app);

app->Add(new JFactoryGeneratorT<RawCalorimeterHit_factory_B0ECalRawHits>());
app->Add(new JFactoryGeneratorT<CalorimeterHit_factory_B0ECalRecHits>());
app->Add(new JFactoryGeneratorT<ProtoCluster_factory_B0ECalTruthProtoClusters>());
app->Add(new JFactoryGeneratorT<ProtoCluster_factory_B0ECalIslandProtoClusters>());
app->Add(new JChainFactoryGeneratorT<RawCalorimeterHit_factory_B0ECalRawHits>(
{"B0ECalHits"}, "B0ECalRawHits"
));
app->Add(new JChainFactoryGeneratorT<CalorimeterHit_factory_B0ECalRecHits>(
{"B0ECalRawHits"}, "B0ECalRecHits"
));
app->Add(new JChainFactoryGeneratorT<ProtoCluster_factory_B0ECalTruthProtoClusters>(
{"B0ECalRecHits", "B0ECalHits"}, "B0ECalTruthProtoClusters"
));
app->Add(new JChainFactoryGeneratorT<ProtoCluster_factory_B0ECalIslandProtoClusters>(
{"B0ECalRecHits"}, "B0ECalIslandProtoClusters"
));

app->Add(
new JChainMultifactoryGeneratorT<Cluster_factory_B0ECalClusters>(
Expand Down
15 changes: 7 additions & 8 deletions src/detectors/B0ECAL/CalorimeterHit_factory_B0ECalRecHits.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@

#include <edm4eic/CalorimeterHitCollection.h>

#include <services/io/podio/JFactoryPodioT.h>
#include <extensions/jana/JChainFactoryT.h>
#include <algorithms/calorimetry/CalorimeterHitReco.h>
#include <services/log/Log_service.h>
#include <extensions/spdlog/SpdlogExtensions.h>

class CalorimeterHit_factory_B0ECalRecHits : public eicrecon::JFactoryPodioT<edm4eic::CalorimeterHit>, CalorimeterHitReco {
class CalorimeterHit_factory_B0ECalRecHits : public JChainFactoryT<edm4eic::CalorimeterHit>, CalorimeterHitReco {

public:
//------------------------------------------
// Constructor
CalorimeterHit_factory_B0ECalRecHits(){
SetTag("B0ECalRecHits");
CalorimeterHit_factory_B0ECalRecHits(std::vector<std::string> default_input_tags)
: JChainFactoryT<edm4eic::CalorimeterHit>(std::move(default_input_tags)) {
m_log = japp->GetService<Log_service>()->logger(GetTag());
}

//------------------------------------------
// Init
void Init() override{
auto app = GetApplication();
InitDataTags(GetPluginName() + ":" + GetTag());

m_input_tag = "B0ECalRawHits";
auto app = GetApplication();

// digitization settings, must be consistent with digi class
m_capADC=16384;//{this, "capacityADC", 8096};
Expand All @@ -49,7 +49,6 @@ class CalorimeterHit_factory_B0ECalRecHits : public eicrecon::JFactoryPodioT<edm
m_localDetElement=""; // from ATHENA's reconstruction.py (i.e. not defined there)
u_localDetFields={}; // from ATHENA's reconstruction.py (i.e. not defined there)

app->SetDefaultParameter("B0ECAL:B0ECalRecHits:input_tag", m_input_tag, "Name of input collection to use");
app->SetDefaultParameter("B0ECAL:B0ECalRecHits:capacityADC", m_capADC);
app->SetDefaultParameter("B0ECAL:B0ECalRecHits:dynamicRangeADC", m_dyRangeADC);
app->SetDefaultParameter("B0ECAL:B0ECalRecHits:pedestalMean", m_pedMeanADC);
Expand Down Expand Up @@ -79,7 +78,7 @@ class CalorimeterHit_factory_B0ECalRecHits : public eicrecon::JFactoryPodioT<edm
// Process
void Process(const std::shared_ptr<const JEvent> &event) override{
// Prefill inputs
rawhits = event->Get<edm4hep::RawCalorimeterHit>(m_input_tag);
rawhits = event->Get<edm4hep::RawCalorimeterHit>(GetInputTags()[0]);

// Call Process for generic algorithm
AlgorithmProcess();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,28 @@

#include <random>

#include <services/io/podio/JFactoryPodioT.h>
#include <extensions/jana/JChainFactoryT.h>
#include <services/geometry/dd4hep/JDD4hep_service.h>
#include <algorithms/calorimetry/CalorimeterIslandCluster.h>
#include <services/log/Log_service.h>
#include <extensions/spdlog/SpdlogExtensions.h>

class ProtoCluster_factory_B0ECalIslandProtoClusters : public eicrecon::JFactoryPodioT<edm4eic::ProtoCluster>, CalorimeterIslandCluster {
class ProtoCluster_factory_B0ECalIslandProtoClusters : public JChainFactoryT<edm4eic::ProtoCluster>, CalorimeterIslandCluster {

public:
//------------------------------------------
// Constructor
ProtoCluster_factory_B0ECalIslandProtoClusters(){
SetTag("B0ECalIslandProtoClusters");
ProtoCluster_factory_B0ECalIslandProtoClusters(std::vector<std::string> default_input_tags)
: JChainFactoryT<edm4eic::ProtoCluster>(std::move(default_input_tags)) {
m_log = japp->GetService<Log_service>()->logger(GetTag());
}

//------------------------------------------
// Init
void Init() override{
InitDataTags(GetPluginName() + ":" + GetTag());

auto app = GetApplication();
m_input_tag = "B0ECalRecHits";

// adjacency matrix
m_geoSvcName = "GeoSvc";
Expand All @@ -51,7 +52,6 @@ class ProtoCluster_factory_B0ECalIslandProtoClusters : public eicrecon::JFactory
u_transverseEnergyProfileMetric = "globalDistEtaPhi";
u_transverseEnergyProfileScale = 1.;

app->SetDefaultParameter("B0ECAL:B0ECalIslandProtoClusters:input_tag", m_input_tag, "Name of input collection to use");
app->SetDefaultParameter("B0ECAL:B0ECalIslandProtoClusters:geoServiceName", m_geoSvcName);
app->SetDefaultParameter("B0ECAL:B0ECalIslandProtoClusters:readoutClass", m_readout);
app->SetDefaultParameter("B0ECAL:B0ECalIslandProtoClusters:sectorDist", m_sectorDist);
Expand Down Expand Up @@ -82,7 +82,7 @@ class ProtoCluster_factory_B0ECalIslandProtoClusters : public eicrecon::JFactory
// Process
void Process(const std::shared_ptr<const JEvent> &event) override{
// Prefill inputs
hits = event->Get<edm4eic::CalorimeterHit>(m_input_tag);
hits = event->Get<edm4eic::CalorimeterHit>(GetInputTags()[0]);

// Call Process for generic algorithm
AlgorithmProcess();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,26 @@

#include <edm4eic/ProtoClusterCollection.h>

#include <services/io/podio/JFactoryPodioT.h>
#include <extensions/jana/JChainFactoryT.h>
#include <services/geometry/dd4hep/JDD4hep_service.h>
#include <algorithms/calorimetry/CalorimeterTruthClustering.h>



class ProtoCluster_factory_B0ECalTruthProtoClusters : public eicrecon::JFactoryPodioT<edm4eic::ProtoCluster>, CalorimeterTruthClustering {
class ProtoCluster_factory_B0ECalTruthProtoClusters : public JChainFactoryT<edm4eic::ProtoCluster>, CalorimeterTruthClustering {

public:
//------------------------------------------
// Constructor
ProtoCluster_factory_B0ECalTruthProtoClusters(){
SetTag("B0ECalTruthProtoClusters");
ProtoCluster_factory_B0ECalTruthProtoClusters(std::vector<std::string> default_input_tags)
: JChainFactoryT<edm4eic::ProtoCluster>(std::move(default_input_tags)) {
m_log = japp->GetService<Log_service>()->logger(GetTag());
}

//------------------------------------------
// Init
void Init() override{
auto app = GetApplication();
m_inputHit_tag="B0ECalRecHits";
m_inputMCHit_tag="B0ECalHits";

app->SetDefaultParameter("EEMC:B0ECalTruthProtoClusters:inputHit_tag", m_inputHit_tag, "Name of input collection to use");
InitDataTags(GetPluginName() + ":" + GetTag());

AlgorithmInit(m_log);
}
Expand All @@ -46,8 +42,8 @@ class ProtoCluster_factory_B0ECalTruthProtoClusters : public eicrecon::JFactoryP
// Process
void Process(const std::shared_ptr<const JEvent> &event) override{
// Prefill inputs
m_inputHits = event->Get<edm4eic::CalorimeterHit>(m_inputHit_tag);
m_mcHits = event->Get<edm4hep::SimCalorimeterHit>(m_inputMCHit_tag);
m_inputHits = event->Get<edm4eic::CalorimeterHit>(GetInputTags()[0]);
m_mcHits = event->Get<edm4hep::SimCalorimeterHit>(GetInputTags()[1]);

// Call Process for generic algorithm
AlgorithmProcess();
Expand All @@ -56,9 +52,4 @@ class ProtoCluster_factory_B0ECalTruthProtoClusters : public eicrecon::JFactoryP
Set(m_outputProtoClusters);
m_outputProtoClusters.clear(); // not really needed, but better to not leave dangling pointers around
}

private:
// Name of input data type (collection)
std::string m_inputHit_tag;
std::string m_inputMCHit_tag;
};
14 changes: 7 additions & 7 deletions src/detectors/B0ECAL/RawCalorimeterHit_factory_B0ECalRawHits.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,33 @@
#include <Evaluator/DD4hepUnits.h>
#include <JANA/JEvent.h>

#include <services/io/podio/JFactoryPodioT.h>
#include <extensions/jana/JChainFactoryT.h>
#include <services/geometry/dd4hep/JDD4hep_service.h>
#include <algorithms/calorimetry/CalorimeterHitDigi.h>
#include <services/log/Log_service.h>
#include <extensions/spdlog/SpdlogExtensions.h>



class RawCalorimeterHit_factory_B0ECalRawHits : public eicrecon::JFactoryPodioT<edm4hep::RawCalorimeterHit>, CalorimeterHitDigi {
class RawCalorimeterHit_factory_B0ECalRawHits : public JChainFactoryT<edm4hep::RawCalorimeterHit>, CalorimeterHitDigi {

public:

//------------------------------------------
// Constructor
RawCalorimeterHit_factory_B0ECalRawHits() {
SetTag("B0ECalRawHits");
RawCalorimeterHit_factory_B0ECalRawHits(std::vector<std::string> default_input_tags)
: JChainFactoryT<edm4hep::RawCalorimeterHit>(std::move(default_input_tags)) {
m_log = japp->GetService<Log_service>()->logger(GetTag());
}

//------------------------------------------
// Init
void Init() override {
InitDataTags(GetPluginName() + ":" + GetTag());

auto app = GetApplication();

// Set default values for all config. parameters in CalorimeterHitDigi algorithm
m_input_tag = "B0ECalHits";
u_eRes = {0.0 * sqrt(dd4hep::GeV), 0.02, 0.0 * dd4hep::GeV};
m_tRes = 0.0 * dd4hep::ns;
m_capADC = 16384;
Expand All @@ -54,7 +55,6 @@ class RawCalorimeterHit_factory_B0ECalRawHits : public eicrecon::JFactoryPodioT<


// This is another option for exposing the data members as JANA configuration parameters.
app->SetDefaultParameter("B0ECAL:B0ECalRawHits:input_tag", m_input_tag, "Name of input collection to use");
app->SetDefaultParameter("B0ECAL:B0ECalRawHits:energyResolutions",u_eRes);
app->SetDefaultParameter("B0ECAL:B0ECalRawHits:timeResolution", m_tRes);
app->SetDefaultParameter("B0ECAL:B0ECalRawHits:capacityADC", m_capADC);
Expand All @@ -81,7 +81,7 @@ class RawCalorimeterHit_factory_B0ECalRawHits : public eicrecon::JFactoryPodioT<
// Process
void Process(const std::shared_ptr<const JEvent> &event) override {
// Prefill inputs
simhits = event->Get<edm4hep::SimCalorimeterHit>(m_input_tag);
simhits = event->Get<edm4hep::SimCalorimeterHit>(GetInputTags()[0]);

// Call Process for generic algorithm
AlgorithmProcess();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,24 @@

#include <random>

#include <services/io/podio/JFactoryPodioT.h>
#include <extensions/jana/JChainFactoryT.h>
#include <services/geometry/dd4hep/JDD4hep_service.h>
#include <algorithms/calorimetry/CalorimeterTruthClustering.h>

class TruthCluster_factory_B0ECalTruthProtoClusters : public eicrecon::JFactoryPodioT<edm4eic::ProtoCluster>, CalorimeterTruthClustering {
class TruthCluster_factory_B0ECalTruthProtoClusters : public JChainFactoryT<edm4eic::ProtoCluster>, CalorimeterTruthClustering {

public:
//------------------------------------------
// Constructor
TruthCluster_factory_B0ECalTruthProtoClusters(){
SetTag("B0ECalTruthProtoClusters");
TruthCluster_factory_B0ECalTruthProtoClusters(std::vector<std::string> default_input_tags)
: JChainFactoryT<edm4eic::ProtoCluster>(std::move(default_input_tags)) {
m_log = japp->GetService<Log_service>()->logger(GetTag());
}

//------------------------------------------
// Init
void Init() override{
auto app = GetApplication();
m_inputHit_tag = "B0ECalTruthProtoClusters";
m_inputMCHit_tag = "B0ECalHits";

app->SetDefaultParameter("EEMC:B0ECalTruthProtoClusters:inputHit_tag", m_inputHit_tag, "Name of input collection to use");
InitDataTags(GetPluginName() + ":" + GetTag());

AlgorithmInit(m_log);
}
Expand All @@ -42,8 +38,8 @@ class TruthCluster_factory_B0ECalTruthProtoClusters : public eicrecon::JFactoryP
// Process
void Process(const std::shared_ptr<const JEvent> &event) override{
// Prefill inputs
m_inputHits = event->Get<edm4eic::CalorimeterHit>(m_inputHit_tag);
m_mcHits = event->Get<edm4hep::SimCalorimeterHit>(m_inputMCHit_tag);
m_inputHits = event->Get<edm4eic::CalorimeterHit>(GetInputTags()[0][0]);
m_mcHits = event->Get<edm4hep::SimCalorimeterHit>(GetInputTags()[0][1]);

// Call Process for generic algorithm
AlgorithmProcess();
Expand All @@ -52,10 +48,4 @@ class TruthCluster_factory_B0ECalTruthProtoClusters : public eicrecon::JFactoryP
Set(m_outputProtoClusters);
m_outputProtoClusters.clear(); // not really needed, but better to not leave dangling pointers around
}

private:
// Name of input data type (collection)
std::string m_inputHit_tag;
std::string m_inputMCHit_tag;

};
Loading

0 comments on commit 3283395

Please sign in to comment.