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

Realistic BTOF digitization #1635

Open
wants to merge 119 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
8123783
First commit of BTOF digitization code!
ssedd1123 Jul 18, 2024
2332d18
Update BTOFHitDigi.cc
eicsouvik Jul 19, 2024
4b907cb
Update BTOFHitDigi.h
eicsouvik Jul 19, 2024
204d472
Update BTOFHitDigi.cc
eicsouvik Jul 19, 2024
1b08022
Merge pull request #3 from eicsouvik/patch-1
ssedd1123 Jul 19, 2024
5e011e1
Merge pull request #2 from eicsouvik/patch-2
ssedd1123 Jul 19, 2024
5e17954
Merge pull request #1 from eicsouvik/patch-3
ssedd1123 Jul 19, 2024
9fbe640
Changed the algorithm of BarrelTOFNeighborFinder so it's more intuita…
Jul 19, 2024
171ffd4
Merge branch 'main' of https://github.com/ssedd1123/EICrecon
Jul 19, 2024
52a9b33
Changed spread calculation. Originally the spread were estimated with…
Jul 19, 2024
54024b6
Fixed bugs when sensor ID from barrelTOFNeighborFinder gives wrong ne…
ssedd1123 Jul 25, 2024
5e1cec4
Merge branch 'eic:main' into main
ssedd1123 Aug 3, 2024
40abca0
Updated BTOF neighbor finder. To be used with updated epic geometry w…
ssedd1123 Aug 3, 2024
72edf8b
Merge branch 'eic:main' into main
ssedd1123 Aug 26, 2024
df48d16
Merge branch 'eic:main' into main
ssedd1123 Aug 26, 2024
1d3c040
Merge branch 'eic:main' into main
ssedd1123 Aug 26, 2024
1adfd02
Sync fork.
ssedd1123 Sep 24, 2024
f373972
Added missing closing parenthesis.
ssedd1123 Sep 24, 2024
0725492
Use more realistic charge sharing parameters and bug fix on ADC heights.
ssedd1123 Sep 27, 2024
a451aed
Merge branch 'main' of https://github.com/ssedd1123/EICrecon
ssedd1123 Sep 27, 2024
ce9122d
Fixed incorrect threshold for ADC TDC.
ssedd1123 Oct 8, 2024
08c83e6
Merge branch 'eic:main' into main
ssedd1123 Oct 14, 2024
350ca3b
Move digitization code to the main branch.
ssedd1123 Oct 15, 2024
4f892ee
Formated files.
ssedd1123 Oct 15, 2024
8d8a12a
Included config content in parameter ref.
ssedd1123 Oct 15, 2024
d260635
Merge remote-tracking branch 'new-origin/main' into pr/BTOF-digitizat…
ssedd1123 Oct 15, 2024
875f0f4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 15, 2024
b12ee38
Fixed BTOF reco uncertainty estimation bug.
ssedd1123 Oct 15, 2024
0d91db5
Merge branch 'main' into pr/BTOF-digitization-clusterization
ssedd1123 Oct 21, 2024
34f4daa
Removed reconstruction for later pull request. Breaks TOF digi into t…
ssedd1123 Oct 23, 2024
9ab01c9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 23, 2024
4cf1216
Removed legacy modification to JEventProcessorPODIO.cc
ssedd1123 Oct 23, 2024
83c9b88
Merge branch 'pr/BTOF-digitization-clusterization' of https://github.…
ssedd1123 Oct 23, 2024
deaf63c
Merge branch 'main' into pr/BTOF-digitization-clusterization
ssedd1123 Oct 23, 2024
14889de
Fixed bugs on charge sharing calculation. It was assumed that all gea…
ssedd1123 Oct 23, 2024
7474a52
Merge branch 'main' into pr/BTOF-digitization-clusterization
ssedd1123 Oct 23, 2024
569090d
Moved algorithms away from src/detectors.
ssedd1123 Oct 23, 2024
33c6587
Fix spelling mistakes to make codespell happy.
ssedd1123 Oct 24, 2024
b28d49f
Removed unnecessary header files.
ssedd1123 Oct 25, 2024
8f01587
Trigger Build
ssedd1123 Oct 25, 2024
595952d
Merge branch 'main' into pr/BTOF-digitization-clusterization
ssedd1123 Nov 1, 2024
a4b5211
Update src/algorithms/digi/BTOFChargeSharing.cc
ssedd1123 Nov 1, 2024
f4f3204
Update src/algorithms/digi/TOFPulseDigitization.cc
ssedd1123 Nov 1, 2024
76fccd8
Update src/algorithms/digi/TOFPulseDigitization.cc
ssedd1123 Nov 1, 2024
310c510
Update src/algorithms/digi/BTOFChargeSharing.cc
ssedd1123 Nov 1, 2024
6e44318
Update src/algorithms/digi/TOFPulseDigitization.h
ssedd1123 Nov 1, 2024
7ecc458
Update src/algorithms/digi/TOFPulseGeneration.h
ssedd1123 Nov 1, 2024
41614b8
Update src/algorithms/digi/BTOFChargeSharing.cc
ssedd1123 Nov 1, 2024
7ca28d3
Update src/algorithms/digi/BTOFChargeSharing.h
ssedd1123 Nov 1, 2024
576055c
Update src/algorithms/digi/BTOFChargeSharing.cc
ssedd1123 Nov 1, 2024
232a3ef
Replaced magic number in BTOFChargeSharing with the correct unit.
ssedd1123 Nov 1, 2024
8043bff
Make clang-tidy-iwyu happy.
ssedd1123 Nov 1, 2024
837900a
Trigger Build
ssedd1123 Nov 2, 2024
e51c007
Update src/algorithms/digi/TOFPulseGeneration.cc
ssedd1123 Nov 2, 2024
1d3f592
Update src/algorithms/digi/TOFPulseGeneration.cc
ssedd1123 Nov 2, 2024
3e0afdc
Make clang-tidy-iwyu happy.
ssedd1123 Nov 2, 2024
89452f4
TOFPulseGeneration_factory.h: mixedCase for parameter names
veprbl Nov 4, 2024
d0040c6
TOFPulseDigitization_factory.h: ditto
veprbl Nov 4, 2024
bbc6ab0
TOFPulseDigitization_factory.h: missed
veprbl Nov 4, 2024
5664496
BTOFChargeSharing_factory.h: ditto
veprbl Nov 4, 2024
00d1890
TOFHitDigiConfig.h: rm unused suff
veprbl Nov 4, 2024
3af27a9
BTOFChargeSharing_factory.h: need algorithmsInit
veprbl Nov 4, 2024
cb3209d
TOFPulseDigitization_factory.h: ditto
veprbl Nov 4, 2024
6ba7bab
TOFPulseGeneration_factory.h: ditto
veprbl Nov 4, 2024
fa7ad55
BTOFChargeSharing.h: remove cache stuff for now
veprbl Nov 4, 2024
5f092d4
Merge branch 'main' into pr/BTOF-digitization-clusterization
veprbl Nov 5, 2024
ef00944
JEventProcessorPODIO.cc: add TOFBarrelADCTDC
veprbl Nov 5, 2024
a745e2b
Update src/services/io/podio/JEventProcessorPODIO.cc
veprbl Nov 5, 2024
dd95d6b
Added tests for TOFPulseDigitization and TOFPulseGeneration.
ssedd1123 Nov 7, 2024
d073d6b
Removed unnecessary credits.
ssedd1123 Nov 7, 2024
6e34d8a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 7, 2024
22c9fe4
Merge branch 'main' into pr/BTOF-digitization-clusterization
ssedd1123 Nov 7, 2024
ce7b6a0
Merge branch 'main' into pr/BTOF-digitization-clusterization
ssedd1123 Nov 18, 2024
d732550
Update src/algorithms/digi/TOFHitDigiConfig.h
ssedd1123 Nov 21, 2024
aef5225
Merge branch 'main' into pr/BTOF-digitization-clusterization
ssedd1123 Nov 21, 2024
40cf825
Amplitude of Landau pulse is now a configurable parameter.
ssedd1123 Nov 21, 2024
fbde72c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2024
da1321b
Beginning time of TOFPulse is now aligned to the beginning of clock c…
ssedd1123 Nov 22, 2024
515eba4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 22, 2024
fcb0e07
Make clang-tidy-iwyu happy.
ssedd1123 Nov 22, 2024
5f3d182
Merge branch 'main' into pr/BTOF-digitization-clusterization
ssedd1123 Nov 22, 2024
a1455a8
Merge branch 'main' into pr/BTOF-digitization-clusterization
ssedd1123 Nov 25, 2024
9551964
Fix typo in code.
ssedd1123 Nov 25, 2024
3d4638c
Trigger Build
ssedd1123 Nov 26, 2024
99d7bd8
Merge branch 'main' into pr/BTOF-digitization-clusterization
veprbl Dec 1, 2024
29239b7
apply clang-format
veprbl Dec 1, 2024
6a67c57
Trigger Build
ssedd1123 Dec 2, 2024
92263ed
Merge branch 'main' into pr/BTOF-digitization-clusterization
ssedd1123 Dec 2, 2024
071d7af
Merge branch 'main' into pr/BTOF-digitization-clusterization
ssedd1123 Dec 3, 2024
a1ab224
Merge branch 'main' into pr/BTOF-digitization-clusterization
ssedd1123 Dec 10, 2024
b1f7166
Added extra bits to show which EIRCOR cycle a timestampe belongs to.
ssedd1123 Dec 18, 2024
f31c553
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 18, 2024
2981788
Separate config class for PulseDigitization and PulseGeneration.
ssedd1123 Dec 18, 2024
3883f9b
Merge branch 'pr/BTOF-digitization-clusterization' of https://github.…
ssedd1123 Dec 18, 2024
9fe2773
Make clang-tidy happy.
ssedd1123 Dec 18, 2024
2401f0a
Modified slightly so it works with negative global time.
ssedd1123 Dec 18, 2024
01473d3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 18, 2024
2aab59b
Make clang-tidy happy.
ssedd1123 Dec 18, 2024
d1218e0
Merge branch 'main' into pr/BTOF-digitization-clusterization
ssedd1123 Dec 20, 2024
0093690
Update src/algorithms/digi/LGADPulseGenerationConfig.h
ssedd1123 Jan 2, 2025
6f852c0
Update src/algorithms/digi/LGADPulseDigitizationConfig.h
ssedd1123 Jan 2, 2025
231cb0a
Update src/algorithms/digi/LGADChargeSharingConfig.h
ssedd1123 Jan 2, 2025
7f8a8e3
Update src/algorithms/digi/LGADPulseGeneration.cc
ssedd1123 Jan 2, 2025
8e652c9
Removed legacy file LGADChargeSharingConfig.h
ssedd1123 Jan 2, 2025
e695627
Update src/algorithms/digi/BTOFChargeSharing.cc
ssedd1123 Jan 3, 2025
a1aa137
use private rather than protected on BTOFChargeSharing
ssedd1123 Jan 3, 2025
350d280
Merge branch 'main' into pr/BTOF-digitization-clusterization
ssedd1123 Jan 4, 2025
e9989fe
Update src/algorithms/digi/LGADPulseDigitization.cc
ssedd1123 Jan 7, 2025
542277a
BTOFChargeSharing -> LGADChargeSharing. The CellID fields to scan thr…
ssedd1123 Jan 7, 2025
f959908
Merge branch 'pr/BTOF-digitization-clusterization' of https://github.…
ssedd1123 Jan 7, 2025
018001e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 7, 2025
e761e0d
make clang-tidy-iwyu happy.
ssedd1123 Jan 7, 2025
57de8af
Merge branch 'pr/BTOF-digitization-clusterization' of https://github.…
ssedd1123 Jan 7, 2025
ab5b497
LGADPulseDigitization: add some missing std:: namespaces
veprbl Jan 8, 2025
8dd1c87
algorithms/digi: link to algorithms for use of GeoSvc
veprbl Jan 8, 2025
e6f1517
eicrecon: load evaluator before acts (acts depends on algorithms_digi…
veprbl Jan 8, 2025
09a2899
move PulseShape to become a private API
veprbl Feb 3, 2025
4076dbd
IWYU
veprbl Feb 3, 2025
46c5c9f
Merge branch 'main' into pr/BTOF-digitization-clusterization
veprbl Feb 3, 2025
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
Prev Previous commit
Next Next commit
Move digitization code to the main branch.
  • Loading branch information
ssedd1123 committed Oct 15, 2024
commit 350ca3bd933886d5a4b6997fdea89661c4a94303
152 changes: 152 additions & 0 deletions src/algorithms/tracking/BTOFHitReconstruction.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (C) 2022 Whitney Armstrong, Sylvester Joosten, Wouter Deconinck, Dmitry Romanov

#include "BTOFHitReconstruction.h"

#include <Evaluator/DD4hepUnits.h>
#include <Math/GenVector/Cartesian3D.h>
#include <Math/GenVector/DisplacementVector3D.h>
#include <edm4eic/CovDiag3f.h>
#include <edm4eic/Cov3f.h>
#include <edm4hep/Vector3f.h>
#include <fmt/core.h>
#include <spdlog/common.h>
#include <stddef.h>
#include <iterator>
#include <utility>
#include <vector>

#include "TMatrixT.h"

namespace eicrecon {

void BTOFHitReconstruction::init(const dd4hep::rec::CellIDPositionConverter* converter,
const dd4hep::Detector* detector,
std::shared_ptr<spdlog::logger>& logger) {

m_log = logger;

m_converter = converter;
m_detector = detector;
}

dd4hep::rec::CellID BTOFHitReconstruction::getDetInfos(const dd4hep::rec::CellID& id) {
// retrieve segmentation class if that hasn't been done
if(! m_decoder) {
const auto det = m_converter -> findContext(id) -> element;
auto readout = m_converter -> findReadout(det);
auto seg = readout.segmentation();
m_decoder = seg.decoder();
}

// CellID for BarrelTOF is composed of 6 parts
// system, layer, module, sensor, x, y
// If we fix x and y to zero, what remains will be the detector information only
auto id_return = id;
m_decoder -> set(id_return, "x", 0);
m_decoder -> set(id_return, "y", 0);
return id_return;
}

std::unique_ptr<edm4eic::TrackerHitCollection> BTOFHitReconstruction::process(const edm4eic::RawTrackerHitCollection& TDCADC_hits) {
using dd4hep::mm;

auto rec_hits { std::make_unique<edm4eic::TrackerHitCollection>() };

// collection of ADC values from all sensors
std::unordered_map<dd4hep::rec::CellID,
std::vector<HitInfo>> hitsBySensors;

for (const auto& TDCADC_hit : TDCADC_hits) {

auto id = TDCADC_hit.getCellID();

// Get position and dimension
auto pos = m_converter->position(id);
// Get sensors info
auto detID = this -> getDetInfos(id);
hitsBySensors[detID].emplace_back(pos.x(), pos.y(), pos.z(), int(TDCADC_hit.getCharge()), int(TDCADC_hit.getTimeStamp()), id);

}

auto geoManager = m_detector -> world().volume() -> GetGeoManager();

// loop through each sensors for Hit information
TMatrixT<double> varLocal(3, 3);
for(int i = 0; i < 3; ++i)
for(int j = 0; j < 3; ++j)
varLocal[i][j] = 0;

for (const auto& sensor : hitsBySensors) {
// INSERT clustering algorithm for each sensors here
// Right now I just perform a simple average over all hits in a sensors
// Will be problematic near the edges, but it's just an illustration
double ave_x = 0, ave_y = 0, ave_z = 0;
double tot_charge = 0;
const auto& hits = sensor.second;
// find cellID for the cell with maximum ADC value within a sensor
// I don't know why you need cellID for reconstructed hits, but we'll do it anyway
auto id = hits[0].id;
auto curr_adc = hits[0].adc;
auto first_tdc = hits[0].tdc;
for(const auto& hit : hits) {
// weigh all hits by ADC value
ave_x += hit.adc*hit.x;
ave_y += hit.adc*hit.y;
ave_z += hit.adc*hit.z;

tot_charge += hit.adc;
if(hit.adc > curr_adc) {
curr_adc = hit.adc;
id = hit.id;
}
first_tdc = std::min(first_tdc, hit.tdc);
}

ave_x /= tot_charge;
ave_y /= tot_charge;
ave_z /= tot_charge;

auto cellSize = m_converter -> cellDimensions(id);

// get rotation matrix
auto node = geoManager -> FindNode(hits[0].x, hits[0].y, hits[0].z);
auto currMatrix = geoManager -> GetCurrentMatrix();
auto rotMatrixElements = currMatrix -> GetRotationMatrix();

// rotMatrix transforms local coordinates to global coordinates
// see line 342 of https://root.cern.ch/doc/master/TGeoMatrix_8cxx_source.html#l00342
TMatrixT<double> rot(3, 3, rotMatrixElements);
TMatrixT<double> rotT(3, 3);
rotT.Transpose(rot);

varLocal[0][0] = cellSize[0]*cellSize[0] / mm / mm / 12.; // final division by 12 because I assumed uniform distribution
varLocal[1][1] = cellSize[1]*cellSize[1] / mm / mm / 12.; // Std. dev of uniformation = width/sqrt(12)
varLocal[2][2] = 0;

// transform variance. see https://robotics.stackexchange.com/questions/2556/how-to-rotate-covariance
auto varGlobal = rot*varLocal*rotT;


// adc to charge
float charge = tot_charge * m_cfg.c_slope + m_cfg.c_intercept;
// TDC to time
float time = first_tdc * m_cfg.t_slope + m_cfg.t_intercept;
// >oO trace
rec_hits->create(
id,
edm4hep::Vector3f{static_cast<float>(ave_x / mm),
static_cast<float>(ave_y / mm),
static_cast<float>(ave_z / mm)}, // mm
edm4eic::CovDiag3f{varGlobal[0][0], varGlobal[1][1], varGlobal[2][2]}, // should be the covariance of position
time, // ns
0.0F, // covariance of time
charge, // total ADC sum
0.0F); // Error on the energy

}

return std::move(rec_hits);
}

} // namespace eicrecon
44 changes: 44 additions & 0 deletions src/algorithms/tracking/BTOFHitReconstruction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (C) 2022 Whitney Armstrong, Sylvester Joosten, Wouter Deconinck, Dmitry Romanov

#pragma once

#include <DDRec/CellIDPositionConverter.h>
#include <DD4hep/Detector.h>
#include <edm4eic/RawTrackerHitCollection.h>
#include <edm4eic/TrackerHitCollection.h>
#include <spdlog/logger.h>
#include <memory>

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

namespace eicrecon {

/**
* Produces edm4eic::TrackerHit with geometric info from edm4eic::RawTrackerHit
*/
class BTOFHitReconstruction : public WithPodConfig<BTOFHitReconstructionConfig> {

public:
/// Once in a lifetime initialization
void init(const dd4hep::rec::CellIDPositionConverter* converter, const dd4hep::Detector* detector, std::shared_ptr<spdlog::logger>& logger);

/// Processes RawTrackerHit and produces a TrackerHit
std::unique_ptr<edm4eic::TrackerHitCollection> process(const edm4eic::RawTrackerHitCollection& TDCADC_hits);

private:
struct HitInfo{ double x, y, z; int adc, tdc; dd4hep::rec::CellID id;};
dd4hep::rec::CellID getDetInfos(const dd4hep::rec::CellID& id);
/** algorithm logger */
std::shared_ptr<spdlog::logger> m_log;

/// Cell ID position converter
const dd4hep::rec::CellIDPositionConverter* m_converter = nullptr;

/// fetch sensor information from cellID
const dd4hep::DDSegmentation::BitFieldCoder* m_decoder = nullptr;

const dd4hep::Detector* m_detector = nullptr;
};
}
13 changes: 13 additions & 0 deletions src/algorithms/tracking/BTOFHitReconstructionConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (C) 2022 Whitney Armstrong, Sylvester Joosten, Wouter Deconinck, Dmitry Romanov

#pragma once

namespace eicrecon {
struct BTOFHitReconstructionConfig {
// parameters that convert ADC to EDep
double c_slope = 3.86976e-7, c_intercept=2.42716e-5;
// parameters that convert TDC to hit time (ns)
double t_slope = 0.0197305, t_intercept = 0.208047;
};
}
7 changes: 3 additions & 4 deletions src/detectors/BTOF/BTOF.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "algorithms/pid_lut/PIDLookupConfig.h"
#include "extensions/jana/JOmniFactoryGeneratorT.h"
#include "factories/digi/SiliconTrackerDigi_factory.h"
#include "factories/tracking/TrackerHitReconstruction_factory.h"
#include "factories/tracking/BTOFHitReconstruction_factory.h"
#include "global/pid_lut/PIDLookup_factory.h"
#include "services/geometry/dd4hep/DD4hep_service.h"

Expand Down Expand Up @@ -45,12 +45,11 @@ void InitPlugin(JApplication *app) {
));

// Convert raw digitized hits into hits with geometry info (ready for tracking)
app->Add(new JOmniFactoryGeneratorT<TrackerHitReconstruction_factory>(
app->Add(new JOmniFactoryGeneratorT<BTOFHitReconstruction_factory>(
"TOFBarrelRecHit",
{"TOFBarrelRawHit"}, // Input data collection tags
{"TOFBarrelADCTDC"}, // Input data collection tags
{"TOFBarrelRecHit"}, // Output data tag
{
.timeResolution = 10,
},
app
)); // Hit reco default config for factories
Expand Down
12 changes: 8 additions & 4 deletions src/detectors/BTOF/BTOFHitDigi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ std::unique_ptr<edm4eic::RawTrackerHitCollection> BTOFHitDigi::execute(const edm
glandau.GetPoint(j, x1, y1);
glandau.GetPoint(j + 1, x2, y2);

if ((y1 >= (-thres[1]*adc_range/Vm) && y2 <= (-thres[1]*adc_range/Vm))) {
intersectionX = x1 + (x2 - x1) * (thres[1] - y1) / (y2 - y1);
double norm_threshold = -thres[1]*adc_range/Vm;
if (y1 >= norm_threshold && y2 <= norm_threshold) {
intersectionX = x1 + (x2 - x1) * (norm_threshold - y1) / (y2 - y1);

tdc = /*BTOFHitDigi::ToDigitalCode(*/ceil(intersectionX/0.02);//, tdc_bit);
for (; j < nBins - 1; j++) {
Expand All @@ -182,8 +183,11 @@ std::unique_ptr<edm4eic::RawTrackerHitCollection> BTOFHitDigi::execute(const edm



adc = round(-V);
rawhits -> create(neighbour, adc, tdc);
// limit the range of adc values
adc = std::min(static_cast<double>(adc_range), round(-V));
// only store valid hits
if(tdc < std::numeric_limits<int>::max() && adc > 0)
rawhits -> create(neighbour, adc, tdc);

}
//-----------------------------------------------------------
Expand Down
17 changes: 11 additions & 6 deletions src/detectors/BTOF/BarrelTOFNeighborFinder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ void BarrelTOFNeighborFinder::_findAllNeighborsInSensor(
}

try {
_converter -> position(testCell);
auto pos = _converter -> position(testCell);
if(testCell != _converter -> cellID(pos))
continue;
} catch (const std::invalid_argument& err) {
// Ignore CellID that is invalid
continue;
Expand Down Expand Up @@ -106,12 +108,15 @@ BarrelTOFNeighborFinder::findAllNeighborInSensor(const dd4hep::rec::CellID& hitC
return neighbors;
}

int BarrelTOFNeighborFinder::_getSensorID(const dd4hep::rec::CellID& hitCell) {
const dd4hep::rec::CellID BarrelTOFNeighborFinder::_getSensorID(const dd4hep::rec::CellID& hitCell) {
_initWithCell(hitCell);
// when x or y-index goes out of bound, sometimes the position will corresponds to a new sensor
// will fetch the new cellID here
auto newID = _converter->cellID(_converter->position(hitCell));
return _decoder->get(newID, "sensor");
// fix x-y, what you left with are ids that corresponds to sensor info
// cellID may change when position changes.
auto sensorID = hitCell;//_converter -> cellID(_converter -> position(hitCell));
_decoder -> set(sensorID, "x", 0);
_decoder -> set(sensorID, "y", 0);

return sensorID;
}

/****************************************
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/BTOF/BarrelTOFNeighborFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class BarrelTOFNeighborFinder {
void _findAllNeighborsInSensor(dd4hep::rec::CellID hitCell,
std::shared_ptr<std::vector<dd4hep::rec::CellID>>& ans,
std::unordered_set<dd4hep::rec::CellID>& dp);
int _getSensorID(const dd4hep::rec::CellID& hitCell);
const dd4hep::rec::CellID _getSensorID(const dd4hep::rec::CellID& hitCell);
// need to initialize the class with a cell from Barrel TOF
void _initWithCell(const dd4hep::rec::CellID& hitCell);

Expand Down
36 changes: 36 additions & 0 deletions src/factories/tracking/BTOFHitReconstruction_factory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (C) 2023 Wouter Deconinck

#pragma once

#include "algorithms/tracking/BTOFHitReconstruction.h"
#include "services/geometry/dd4hep/DD4hep_service.h"
#include "extensions/jana/JOmniFactory.h"

namespace eicrecon {

class BTOFHitReconstruction_factory :
public JOmniFactory<BTOFHitReconstruction_factory, BTOFHitReconstructionConfig> {
private:
eicrecon::BTOFHitReconstruction m_algo;

PodioInput<edm4eic::RawTrackerHit> m_raw_hits_input {this};
PodioOutput<edm4eic::TrackerHit> m_rec_hits_output {this};

Service<DD4hep_service> m_geoSvc {this};

public:
void Configure() {
m_algo.applyConfig(config());
m_algo.init(m_geoSvc().converter(), m_geoSvc().detector(), logger());
}

void ChangeRun(int64_t run_number) {
}

void Process(int64_t run_number, uint64_t event_number) {
m_rec_hits_output() = m_algo.process(*m_raw_hits_input());
}
};

} // eicrecon