LDMX Software
EcalTriggerGeometry.cxx
2
3#include <iostream>
4#include <sstream>
5
9
10namespace ecal {
11static const int LAYERS_IDENTICAL = 0x01;
12static const int MODULES_MASK = 0xFF00;
13static const int INPLANE_IDENTICAL = 0x0100;
14
16 const ldmx::EcalGeometry* ecalGeom)
17 : ConditionsObject(CONDITIONS_OBJECT_NAME),
18 symmetry_{symmetry},
19 ecalGeometry_{ecalGeom} {
20 if ((symmetry_ & MODULES_MASK) == INPLANE_IDENTICAL) {
21 // first set is the same regardless of alignment...
22 int tcell = 0;
24 for (int v = 1; v <= 10; v += 3) {
25 for (int u = 1; u <= 10; u += 3) {
26 ldmx::EcalTriggerID tid(0, 0, tcell);
27 std::vector<ldmx::EcalID> pids;
28 for (int du = -1; du <= 1; du++) {
29 for (int dv = -1; dv <= 1; dv++) {
30 ldmx::EcalID pid(0, 0, u + du, v + dv);
31 precision2trigger_[pid] = tid;
32 pids.push_back(pid);
33 }
34 }
35 trigger2precision_[tid] = pids;
36 tcell++;
37 }
38 }
40 for (int v = 13; v <= 22; v += 3) {
41 for (int u = v - 10; u <= v; u += 3) {
42 ldmx::EcalTriggerID tid(0, 0, tcell);
43 std::vector<ldmx::EcalID> pids;
44 for (int dv = -1; dv <= 1; dv++) {
45 for (int du = -1; du <= 1; du++) {
46 // changes directions here
47 ldmx::EcalID pid(0, 0, u + du + dv, v + dv);
48 precision2trigger_[pid] = tid;
49 pids.push_back(pid);
50 }
51 }
52 trigger2precision_[tid] = pids;
53 tcell++;
54 }
55 }
56 // right side
57 for (int v = 2; v <= 22; v += 3) {
58 int irow = (v - 2) / 3;
59 for (int icol = 0; icol <= std::min(irow, 3); icol++) {
60 if (irow - icol >= 4) continue;
61 ldmx::EcalTriggerID tid(0, 0, tcell);
62 std::vector<ldmx::EcalID> pids;
63 int u = 13 + 3 * icol;
64 for (int dv = -1; dv <= 1; dv++) {
65 for (int du = -1; du <= 1; du++) {
66 ldmx::EcalID pid(0, 0, u + du, v + du + dv);
67 precision2trigger_[pid] = tid;
68 pids.push_back(pid);
69 }
70 }
71 trigger2precision_[tid] = pids;
72 tcell++;
73 }
74 }
75
76 } else {
77 // raise an exception...
78 }
79}
80
82 ldmx::EcalTriggerID triggerCell) const {
84 std::vector<ldmx::EcalID> retval;
85 if ((symmetry_ & MODULES_MASK) == INPLANE_IDENTICAL) {
86 effId = ldmx::EcalTriggerID(0, 0, triggerCell.triggercell());
87 }
88 auto ptr = trigger2precision_.find(effId);
89 if (ptr != trigger2precision_.end()) {
90 for (auto idz : ptr->second) {
91 retval.push_back(
92 ldmx::EcalID(triggerCell.layer(), triggerCell.module(), idz.cell()));
93 }
94 }
95 return retval;
96}
97
99 ldmx::EcalTriggerID triggerCell) const {
101 if ((symmetry_ & MODULES_MASK) == INPLANE_IDENTICAL) {
102 effId = ldmx::EcalTriggerID(0, 0, triggerCell.triggercell());
103 }
104 auto ptr = trigger2precision_.find(effId);
105 if (ptr == trigger2precision_.end()) {
106 std::stringstream ss;
107 ss << "Unable to find trigger cell " << triggerCell;
108 EXCEPTION_RAISE("EcalGeometryException", ss.str());
109 }
110
111 return ldmx::EcalID(triggerCell.layer(), triggerCell.module(),
112 ptr->second[4].cell());
113}
114
116 ldmx::EcalID precisionCell) const {
117 ldmx::EcalID effId;
118 if ((symmetry_ & MODULES_MASK) == INPLANE_IDENTICAL) {
119 effId = ldmx::EcalID(0, 0, precisionCell.cell());
120 }
121 auto ptr = precision2trigger_.find(effId);
122 if (ptr == precision2trigger_.end()) {
123 return ldmx::EcalTriggerID(0, 0, 0); // not ideal
124 } else {
125 return ldmx::EcalTriggerID(precisionCell.layer(), precisionCell.module(),
126 ptr->second.triggercell());
127 }
128}
129
130// as it happens, the fifth precision cell in the list is the center cell
131std::tuple<double, double, double> EcalTriggerGeometry::globalPosition(
132 ldmx::EcalTriggerID triggerCell) const {
133 if (!ecalGeometry_) return std::make_tuple(0, 0, 0);
134 ldmx::EcalID pid = centerInTriggerCell(triggerCell);
135 return ecalGeometry_->getPosition(pid);
136}
137
138std::pair<double, double> EcalTriggerGeometry::localPosition(
139 ldmx::EcalTriggerID triggerCell) const {
140 if (!ecalGeometry_) return std::make_pair(0, 0);
141 ldmx::EcalID pid = centerInTriggerCell(triggerCell);
143}
144
146 public:
150 EcalTriggerGeometryProvider(const std::string& name,
151 const std::string& tagname,
152 const framework::config::Parameters& parameters,
154 : ConditionsObjectProvider(EcalTriggerGeometry::CONDITIONS_OBJECT_NAME,
155 tagname, parameters, process),
156 ecalTriggerGeometry_{nullptr} {}
157
160 if (ecalTriggerGeometry_ != nullptr) delete ecalTriggerGeometry_;
161 ecalTriggerGeometry_ = nullptr;
162 }
163
170 virtual std::pair<const framework::ConditionsObject*,
173 if (ecalTriggerGeometry_ == nullptr) {
174 std::pair<const framework::ConditionsObject*, framework::ConditionsIOV>
175 cond_ecal_geom = requestParentCondition(
176 ldmx::EcalGeometry::CONDITIONS_OBJECT_NAME, context);
177 const ldmx::EcalGeometry* ecalgeom =
178 dynamic_cast<const ldmx::EcalGeometry*>(cond_ecal_geom.first);
179 ecalTriggerGeometry_ = new EcalTriggerGeometry(
180 INPLANE_IDENTICAL | LAYERS_IDENTICAL, ecalgeom);
181 }
182 return std::make_pair(ecalTriggerGeometry_,
184 context.getRun(), context.getRun(), true, true));
185 }
186
192
193 private:
194 EcalTriggerGeometry* ecalTriggerGeometry_;
195};
196
197} // namespace ecal
198DECLARE_CONDITIONS_PROVIDER_NS(ecal, EcalTriggerGeometryProvider);
Base class for provider of conditions information like pedestals, gains, electronics maps,...
#define DECLARE_CONDITIONS_PROVIDER_NS(NS, CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Class that translates raw positions of ECal module hits into cells in a hexagonal readout.
Class that defines the relationship between precision cells and trigger cells and provides geometry i...
Class that provides header information about an event such as event number and timestamp.
be configured to load conditions objects from CSV files.
EcalTriggerGeometryProvider(const std::string &name, const std::string &tagname, const framework::config::Parameters &parameters, framework::Process &process)
Class constructor.
virtual ~EcalTriggerGeometryProvider()
Destructor.
virtual std::pair< const framework::ConditionsObject *, framework::ConditionsIOV > getCondition(const ldmx::EventHeader &context)
Provides access to the EcalGeometry or EcalTriggerGeometry.
virtual void releaseConditionsObject(const framework::ConditionsObject *co)
Take no action on release, as the object is permanently owned by the Provider.
defines the relationship between precision cells and trigger cells and provides geometry information ...
std::vector< ldmx::EcalID > contentsOfTriggerCell(ldmx::EcalTriggerID triggerCell) const
Returns the set of precision (full-granularity/DAQ) cells which are associated with the given trigger...
const ldmx::EcalGeometry * ecalGeometry_
Reference to the Ecal geometry used for trigger geometry information.
std::pair< double, double > localPosition(ldmx::EcalTriggerID triggerCell) const
Returns the local (within module) center of the given trigger cell.
int symmetry_
Identifies what symmetries apply in this case, such as all layers being identical,...
EcalTriggerGeometry(int symmetry, const ldmx::EcalGeometry *ecalGeom=0)
std::map< ldmx::EcalTriggerID, std::vector< ldmx::EcalID > > trigger2precision_
Map of trigger cells to precision cells, under symmetry assumptions.
ldmx::EcalTriggerID belongsTo(ldmx::EcalID precisionCell) const
Returns which trigger cell this precision cell is associated with, or a null id if there is no such a...
std::map< ldmx::EcalID, ldmx::EcalTriggerID > precision2trigger_
Map of precision cells to trigger cells, under symmetry assumptions.
std::tuple< double, double, double > globalPosition(ldmx::EcalTriggerID triggerCell) const
Returns the center of the given trigger cell in world coordinates.
ldmx::EcalID centerInTriggerCell(ldmx::EcalTriggerID triggerCell) const
Returns the set of precision (full-granularity/DAQ) cell which is the center of the given trigger cel...
Class which defines the run/event/type range for which a given condition is valid,...
Base class for all providers of conditions objects.
std::pair< const ConditionsObject *, ConditionsIOV > requestParentCondition(const std::string &name, const ldmx::EventHeader &context)
Request another condition needed to construct this condition.
const Process & process() const
Get the process handle.
Base class for all conditions objects, very simple.
Class which represents the process under execution.
Definition Process.h:36
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
Translation between real-space positions and cell IDs within the ECal.
std::tuple< double, double, double > getPosition(EcalID id) const
Get a cell's position from its ID number.
std::pair< double, double > getPositionInModule(int cell_id) const
Get a cell's position within a module.
Extension of DetectorID providing access to ECal layers and cell numbers in a hex grid.
Definition EcalID.h:20
int cell() const
Get the value of the cell field from the ID.
Definition EcalID.h:111
int module() const
Get the value of the module field from the ID.
Definition EcalID.h:87
int layer() const
Get the value of the layer field from the ID.
Definition EcalID.h:99
Extension of DetectorID providing access to ECal trigger cell information.
int layer() const
Get the value of the layer field from the ID.
int module() const
Get the value of the module field from the ID.
int triggercell() const
Get the value of the trigger cell field from the ID.
Provides header information an event such as event number and timestamp.
Definition EventHeader.h:44
int getRun() const
Return the run number.
Definition EventHeader.h:84