EICrecon
JANA based reconstruction for the EPIC detector
Loading...
Searching...
No Matches
PhotoMultiplierHitDigi.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// Copyright (C) 2022, 2023, Chao Peng, Thomas Britton, Christopher Dilks, Luigi Dello Stritto
3
4/* General PhotoMultiplier Digitization
5 *
6 * Apply the given quantum efficiency for photon detection
7 * Converts the number of detected photons to signal amplitude
8 *
9 * Author: Chao Peng (ANL)
10 * Date: 10/02/2020
11 *
12 * Ported from Juggler by Thomas Britton (JLab)
13 */
14
15#pragma once
16
17#include <DD4hep/Detector.h>
18#include <DD4hep/Objects.h>
19#include <DDRec/CellIDPositionConverter.h>
20#include <Math/GenVector/Cartesian3D.h>
21#include <Math/GenVector/DisplacementVector3D.h>
22#include <algorithms/algorithm.h>
23#include <algorithms/geo.h>
24#include <edm4eic/EDM4eicVersion.h>
25#include <edm4eic/MCRecoTrackerHitAssociationCollection.h>
26#include <edm4eic/RawTrackerHitCollection.h>
27#include <edm4hep/EventHeaderCollection.h>
28#include <edm4hep/SimTrackerHitCollection.h>
29#include <fmt/format.h> // IWYU pragma: keep
30#include <stdint.h>
31#include <cstddef>
32#include <functional>
33#include <gsl/pointers>
34#include <iterator>
35#include <random>
36#include <stdexcept>
37#include <string>
38#include <string_view>
39#include <unordered_map>
40#include <utility>
41#include <vector>
42
46
47#if EDM4EIC_BUILD_VERSION >= EDM4EIC_VERSION(8, 7, 0)
48#include <edm4eic/MCRecoTrackerHitLinkCollection.h>
49#endif
50
51namespace eicrecon {
52
53using PhotoMultiplierHitDigiAlgorithm = algorithms::Algorithm<
54 algorithms::Input<edm4hep::EventHeaderCollection, edm4hep::SimTrackerHitCollection>,
55 algorithms::Output<edm4eic::RawTrackerHitCollection,
56#if EDM4EIC_BUILD_VERSION >= EDM4EIC_VERSION(8, 7, 0)
57 edm4eic::MCRecoTrackerHitLinkCollection,
58#endif
59 edm4eic::MCRecoTrackerHitAssociationCollection>>;
60
62 public WithPodConfig<PhotoMultiplierHitDigiConfig> {
63
64public:
65 PhotoMultiplierHitDigi(std::string_view name)
67 {"eventHeaderCollection", "inputHitCollection"},
68 {"outputRawHitCollection",
69#if EDM4EIC_BUILD_VERSION >= EDM4EIC_VERSION(8, 7, 0)
70 "outputHitLinks",
71#endif
72 "outputRawHitAssociations"},
73 "Digitize within ADC range, add pedestal, convert time "
74 "with smearing resolution."} {
75 }
76
77 void init() final;
78 void process(const Input&, const Output&) const final;
79
80 // EDM datatype member types
81 using CellIDType = decltype(edm4hep::SimTrackerHitData::cellID);
82 using TimeType = decltype(edm4hep::SimTrackerHitData::time);
83
84 // local structure to hold data for a hit
85 struct HitData {
86 uint32_t npe;
87 double signal;
89 std::vector<std::size_t> sim_hit_indices;
90 };
91
92 // set `m_VisitAllRngPixels`, a visitor to run an action (type
93 // `function<void(cellID)>`) on a selection of random CellIDs; must be
94 // defined externally, since this would be detector-specific
95 void SetVisitRngCellIDs(std::function<void(std::function<void(CellIDType)>, float)> visitor) {
96 m_VisitRngCellIDs = visitor;
97 }
98
99 // set `m_PixelGapMask`, which takes `cellID` and MC hit position, returning
100 // true if the hit position is on a pixel, or false if on a pixel gap; must be
101 // defined externally, since this would be detector-specific
102 void SetPixelGapMask(std::function<bool(CellIDType, dd4hep::Position)> mask) {
103 m_PixelGapMask = mask;
104 }
105
106protected:
107 // visitor of all possible CellIDs (set with SetVisitRngCellIDs)
108 std::function<void(std::function<void(CellIDType)>, float)> m_VisitRngCellIDs =
109 [](std::function<void(CellIDType)> /* visitor_action */,
110 float /* p */) { /* default no-op */ };
111
112 // pixel gap mask
113 std::function<bool(CellIDType, dd4hep::Position)> m_PixelGapMask =
114 [](CellIDType /* cellID */, dd4hep::Position /* pos_hit_global */) {
115 throw std::runtime_error("pixel gap cuts enabled, but none defined");
116 return false;
117 };
118
119private:
120 // add a hit to local `hit_groups` data structure
121 void InsertHit(std::unordered_map<CellIDType, std::vector<HitData>>& hit_groups, CellIDType id,
122 double amp, TimeType time, std::size_t sim_hit_index,
123 std::default_random_engine& generator, std::normal_distribution<double>& gaussian,
124 bool is_noise_hit = false) const;
125
126 const dd4hep::Detector* m_detector{algorithms::GeoSvc::instance().detector()};
127 const dd4hep::rec::CellIDPositionConverter* m_converter{
128 algorithms::GeoSvc::instance().cellIDPositionConverter()};
129
130 const algorithms::UniqueIDGenSvc& m_uid = algorithms::UniqueIDGenSvc::instance();
131
132 // std::default_random_engine generator; // TODO: need something more appropriate here
133 // std::normal_distribution<double> m_normDist; // defaults to mean=0, sigma=1
134
135 std::vector<std::pair<double, double>> qeff;
136 void qe_init();
137 template <class RndmIter, typename T, class Compare>
138 RndmIter interval_search(RndmIter beg, RndmIter end, const T& val, Compare comp) const;
139 bool qe_pass(double ev, double rand) const;
140};
141} // namespace eicrecon
Definition UniqueIDGenSvc.h:23
Definition PhotoMultiplierHitDigi.h:62
PhotoMultiplierHitDigi(std::string_view name)
Definition PhotoMultiplierHitDigi.h:65
void SetPixelGapMask(std::function< bool(CellIDType, dd4hep::Position)> mask)
Definition PhotoMultiplierHitDigi.h:102
decltype(edm4hep::SimTrackerHitData::time) TimeType
Definition PhotoMultiplierHitDigi.h:82
decltype(edm4hep::SimTrackerHitData::cellID) CellIDType
Definition PhotoMultiplierHitDigi.h:81
void SetVisitRngCellIDs(std::function< void(std::function< void(CellIDType)>, float)> visitor)
Definition PhotoMultiplierHitDigi.h:95
Definition WithPodConfig.h:22
-client
Definition CalorimeterClusterRecoCoG.cc:37
algorithms::Algorithm< algorithms::Input< edm4hep::EventHeaderCollection, edm4hep::SimTrackerHitCollection >, algorithms::Output< edm4eic::RawTrackerHitCollection, edm4eic::MCRecoTrackerHitLinkCollection, edm4eic::MCRecoTrackerHitAssociationCollection > > PhotoMultiplierHitDigiAlgorithm
Definition PhotoMultiplierHitDigi.h:59
Definition PhotoMultiplierHitDigi.h:85
TimeType time
Definition PhotoMultiplierHitDigi.h:88
std::vector< std::size_t > sim_hit_indices
Definition PhotoMultiplierHitDigi.h:89
uint32_t npe
Definition PhotoMultiplierHitDigi.h:86
double signal
Definition PhotoMultiplierHitDigi.h:87