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: migrate PhotoMultiplierDigi_factory to JOmniFactory #1177

Merged
merged 2 commits into from
Jan 10, 2024
Merged
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
20 changes: 5 additions & 15 deletions src/algorithms/digi/PhotoMultiplierHitDigi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
#include "algorithms/digi/PhotoMultiplierHitDigiConfig.h"

//------------------------
// AlgorithmInit
// init
//------------------------
void eicrecon::PhotoMultiplierHitDigi::AlgorithmInit(const dd4hep::Detector* detector, const dd4hep::rec::CellIDPositionConverter* converter, std::shared_ptr<spdlog::logger>& logger)
void eicrecon::PhotoMultiplierHitDigi::init(const dd4hep::Detector* detector, const dd4hep::rec::CellIDPositionConverter* converter, std::shared_ptr<spdlog::logger>& logger)
{
// services
m_detector = detector;
Expand Down Expand Up @@ -66,24 +66,14 @@ void eicrecon::PhotoMultiplierHitDigi::AlgorithmInit(const dd4hep::Detector* det
}



//------------------------
// AlgorithmChangeRun
//------------------------
void eicrecon::PhotoMultiplierHitDigi::AlgorithmChangeRun() {
/// This is automatically run before Process, when a new run number is seen
/// Usually we update our calibration constants by asking a JService
/// to give us the latest data for this run number
}

//------------------------
// AlgorithmProcess
// process
//------------------------
eicrecon::PhotoMultiplierHitDigiResult eicrecon::PhotoMultiplierHitDigi::AlgorithmProcess(
eicrecon::PhotoMultiplierHitDigiResult eicrecon::PhotoMultiplierHitDigi::process(
const edm4hep::SimTrackerHitCollection* sim_hits
)
{
m_log->trace("{:=^70}"," call PhotoMultiplierHitDigi::AlgorithmProcess ");
m_log->trace("{:=^70}"," call PhotoMultiplierHitDigi::process ");
std::unordered_map<CellIDType, std::vector<HitData>> hit_groups;
// collect the photon hit in the same cell
// calculate signal
Expand Down
9 changes: 3 additions & 6 deletions src/algorithms/digi/PhotoMultiplierHitDigi.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,9 @@ class PhotoMultiplierHitDigi : public WithPodConfig<PhotoMultiplierHitDigiConfig

public:
PhotoMultiplierHitDigi() = default;
~PhotoMultiplierHitDigi(){}
void AlgorithmInit(const dd4hep::Detector* detector, const dd4hep::rec::CellIDPositionConverter* converter, std::shared_ptr<spdlog::logger>& logger);
void AlgorithmChangeRun();
PhotoMultiplierHitDigiResult AlgorithmProcess(
const edm4hep::SimTrackerHitCollection* sim_hits
);
~PhotoMultiplierHitDigi(){};
void init(const dd4hep::Detector* detector, const dd4hep::rec::CellIDPositionConverter* converter, std::shared_ptr<spdlog::logger>& logger);
PhotoMultiplierHitDigiResult process(const edm4hep::SimTrackerHitCollection* sim_hits);

// EDM datatype member types
using CellIDType = decltype(edm4hep::SimTrackerHitData::cellID);
Expand Down
1 change: 0 additions & 1 deletion src/detectors/BTRK/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ plugin_link_libraries(${PLUGIN_NAME}
algorithms_digi_library
algorithms_tracking_library
tracking_library
digi_library
)
5 changes: 0 additions & 5 deletions src/detectors/DIRC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,3 @@ plugin_glob_all(${PLUGIN_NAME})
# Find dependencies
plugin_add_event_model(${PLUGIN_NAME})
plugin_add_dd4hep(${PLUGIN_NAME})

# Add libraries
plugin_link_libraries(${PLUGIN_NAME}
digi_library
)
4 changes: 2 additions & 2 deletions src/detectors/DIRC/DIRC.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

// algorithm configurations
#include "algorithms/digi/PhotoMultiplierHitDigiConfig.h"
#include "extensions/jana/JChainMultifactoryGeneratorT.h"
#include "extensions/jana/JOmniFactoryGeneratorT.h"
// factories
#include "global/digi/PhotoMultiplierHitDigi_factory.h"

Expand Down Expand Up @@ -65,7 +65,7 @@ extern "C" {


// digitization
app->Add(new JChainMultifactoryGeneratorT<PhotoMultiplierHitDigi_factory>(
app->Add(new JOmniFactoryGeneratorT<PhotoMultiplierHitDigi_factory>(
"DIRCRawHits",
{"DIRCBarHits"},
{"DIRCRawHits", "DIRCRawHitsAssociations"},
Expand Down
5 changes: 0 additions & 5 deletions src/detectors/DRICH/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,3 @@ plugin_add_irt(${PLUGIN_NAME})
plugin_add_event_model(${PLUGIN_NAME})
plugin_add_dd4hep(${PLUGIN_NAME})
plugin_add_acts(${PLUGIN_NAME})

# Add libraries
plugin_link_libraries(${PLUGIN_NAME}
digi_library
)
3 changes: 2 additions & 1 deletion src/detectors/DRICH/DRICH.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "algorithms/pid/IrtCherenkovParticleIDConfig.h"
#include "algorithms/pid/MergeParticleIDConfig.h"
#include "extensions/jana/JChainMultifactoryGeneratorT.h"
#include "extensions/jana/JOmniFactoryGeneratorT.h"
// factories
#include "global/digi/PhotoMultiplierHitDigi_factory.h"
#include "global/pid/IrtCherenkovParticleID_factory.h"
Expand Down Expand Up @@ -101,7 +102,7 @@ extern "C" {
// clang-format off

// digitization
app->Add(new JChainMultifactoryGeneratorT<PhotoMultiplierHitDigi_factory>(
app->Add(new JOmniFactoryGeneratorT<PhotoMultiplierHitDigi_factory>(
"DRICHRawHits",
{"DRICHHits"},
{"DRICHRawHits", "DRICHRawHitsAssociations"},
Expand Down
1 change: 0 additions & 1 deletion src/global/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
cmake_minimum_required(VERSION 3.16)

add_subdirectory( tracking )
add_subdirectory( digi )
add_subdirectory( reco )
add_subdirectory( pid )
28 changes: 0 additions & 28 deletions src/global/digi/CMakeLists.txt

This file was deleted.

95 changes: 0 additions & 95 deletions src/global/digi/PhotoMultiplierHitDigi_factory.cc

This file was deleted.

76 changes: 49 additions & 27 deletions src/global/digi/PhotoMultiplierHitDigi_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,65 @@
#include "algorithms/digi/PhotoMultiplierHitDigi.h"
#include "algorithms/digi/PhotoMultiplierHitDigiConfig.h"
// JANA
#include "extensions/jana/JChainMultifactoryT.h"
#include "extensions/jana/JOmniFactory.h"
// services
#include "extensions/spdlog/SpdlogMixin.h"
#include "services/geometry/dd4hep/DD4hep_service.h"
#include "services/geometry/richgeo/RichGeo_service.h"
#include "services/geometry/richgeo/ReadoutGeo.h"

namespace eicrecon {

class PhotoMultiplierHitDigi_factory :
public JChainMultifactoryT<PhotoMultiplierHitDigiConfig>,
public SpdlogMixin {
class PhotoMultiplierHitDigi_factory :
public JOmniFactory<PhotoMultiplierHitDigi_factory, PhotoMultiplierHitDigiConfig> {

public:
private:
PhotoMultiplierHitDigi m_algo;

explicit PhotoMultiplierHitDigi_factory(
std::string tag,
const std::vector<std::string>& input_tags,
const std::vector<std::string>& output_tags,
PhotoMultiplierHitDigiConfig cfg
):
JChainMultifactoryT<PhotoMultiplierHitDigiConfig>(std::move(tag), input_tags, output_tags, cfg) {
DeclarePodioOutput<edm4eic::RawTrackerHit>(GetOutputTags()[0]);
DeclarePodioOutput<edm4eic::MCRecoTrackerHitAssociation>(GetOutputTags()[1]);
}
PodioInput<edm4hep::SimTrackerHit> m_sim_hits_input {this};
PodioOutput<edm4eic::RawTrackerHit> m_raw_hits_output {this};
PodioOutput<edm4eic::MCRecoTrackerHitAssociation> m_raw_assocs_output {this};

/** One time initialization **/
void Init() override;
ParameterRef<unsigned long> m_seed {this, "seed", config().seed, "random number generator seed"};
ParameterRef<double> m_hitTimeWindow {this, "hitTimeWindow", config().hitTimeWindow, ""};
ParameterRef<double> m_timeResolution {this, "timeResolution", config().timeResolution, ""};
ParameterRef<double> m_speMean {this, "speMean", config().speMean, ""};
ParameterRef<double> m_speError {this, "speError", config().speError, ""};
ParameterRef<double> m_pedMean {this, "pedMean", config().pedMean, ""};
ParameterRef<double> m_pedError {this, "pedError", config().pedError, ""};
ParameterRef<bool> m_enablePixelGaps {this, "enablePixelGaps", config().enablePixelGaps, "enable/disable removal of hits in gaps between pixels"};
ParameterRef<double> m_safetyFactor {this, "safetyFactor", config().safetyFactor, "overall safety factor"};
ParameterRef<bool> m_enableNoise {this, "enableNoise", config().enableNoise, ""};
ParameterRef<double> m_noiseRate {this, "noiseRate", config().noiseRate, ""};
ParameterRef<double> m_noiseTimeWindow {this, "noiseTimeWindow", config().noiseTimeWindow, ""};
//ParameterRef<std::vector<std::pair<double, double>>> m_quantumEfficiency {this, "quantumEfficiency", config().quantumEfficiency, ""};

/** On run change preparations **/
void BeginRun(const std::shared_ptr<const JEvent> &event) override;
Service<DD4hep_service> m_DD4hepSvc {this};
Service<RichGeo_service> m_RichGeoSvc {this};

/** Event by event processing **/
void Process(const std::shared_ptr<const JEvent> &event) override;
public:
void Configure() {

private:
// Initialize richgeo ReadoutGeo and set random CellID visitor lambda (if a RICH)
if (GetPluginName() == "DRICH" || GetPluginName() == "PFRICH") {
m_RichGeoSvc().GetReadoutGeo(GetPluginName())->SetSeed(config().seed);
m_algo.SetVisitRngCellIDs(
[this] (std::function<void(PhotoMultiplierHitDigi::CellIDType)> lambda, float p) { m_RichGeoSvc().GetReadoutGeo(GetPluginName())->VisitAllRngPixels(lambda, p); }
);
m_algo.SetPixelGapMask(
[this] (PhotoMultiplierHitDigi::CellIDType cellID, dd4hep::Position pos) { return m_RichGeoSvc().GetReadoutGeo(GetPluginName())->PixelGapMask(cellID, pos); }
);
}

eicrecon::PhotoMultiplierHitDigi m_digi_algo; /// Actual digitisation algorithm
std::shared_ptr<richgeo::ReadoutGeo> m_readoutGeo;
};
m_algo.applyConfig(config());
m_algo.init(m_DD4hepSvc().detector(), m_DD4hepSvc().converter(), logger());
}

}
void ChangeRun(int64_t run_number) {
}

void Process(int64_t run_number, uint64_t event_number) {
std::tie(m_raw_hits_output(), m_raw_assocs_output()) = m_algo.process(m_sim_hits_input());
}
};

} // eicrecon
Loading