LDMX Software
EcalTriggerGeometry.cxx
2
3#include <sstream>
4
8
9namespace ecal {
10static const int LAYERS_IDENTICAL = 0x01;
11static const int MODULES_MASK = 0xFF00;
12static const int INPLANE_IDENTICAL = 0x0100;
13
15 const ldmx::EcalGeometry* ecalGeom)
16 : ConditionsObject(CONDITIONS_OBJECT_NAME),
17 symmetry_{symmetry},
18 ecal_geometry_{ecalGeom} {
19 if ((symmetry_ & MODULES_MASK) == INPLANE_IDENTICAL) {
20 // first set is the same regardless of alignment...
21 int tcell = 0;
23 for (int v = 1; v <= 10; v += 3) {
24 for (int u = 1; u <= 10; u += 3) {
25 ldmx::EcalTriggerID tid(0, 0, tcell);
26 std::vector<ldmx::EcalID> pids;
27 for (int du = -1; du <= 1; du++) {
28 for (int dv = -1; dv <= 1; dv++) {
29 ldmx::EcalID pid(0, 0, u + du, v + dv);
30 precision2trigger_[pid] = tid;
31 pids.push_back(pid);
32 }
33 }
34 trigger2precision_[tid] = pids;
35 tcell++;
36 }
37 }
39 for (int v = 13; v <= 22; v += 3) {
40 for (int u = v - 10; u <= v; u += 3) {
41 ldmx::EcalTriggerID tid(0, 0, tcell);
42 std::vector<ldmx::EcalID> pids;
43 for (int dv = -1; dv <= 1; dv++) {
44 for (int du = -1; du <= 1; du++) {
45 // changes directions here
46 ldmx::EcalID pid(0, 0, u + du + dv, v + dv);
47 precision2trigger_[pid] = tid;
48 pids.push_back(pid);
49 }
50 }
51 trigger2precision_[tid] = pids;
52 tcell++;
53 }
54 }
55 // right side
56 for (int v = 2; v <= 22; v += 3) {
57 int irow = (v - 2) / 3;
58 for (int icol = 0; icol <= std::min(irow, 3); icol++) {
59 if (irow - icol >= 4) continue;
60 ldmx::EcalTriggerID tid(0, 0, tcell);
61 std::vector<ldmx::EcalID> pids;
62 int u = 13 + 3 * icol;
63 for (int dv = -1; dv <= 1; dv++) {
64 for (int du = -1; du <= 1; du++) {
65 ldmx::EcalID pid(0, 0, u + du, v + du + dv);
66 precision2trigger_[pid] = tid;
67 pids.push_back(pid);
68 }
69 }
70 trigger2precision_[tid] = pids;
71 tcell++;
72 }
73 }
74
75 } else {
76 // raise an exception...
77 }
78}
79
81 ldmx::EcalTriggerID triggerCell) const {
83 std::vector<ldmx::EcalID> retval;
84 if ((symmetry_ & MODULES_MASK) == INPLANE_IDENTICAL) {
85 eff_id = ldmx::EcalTriggerID(0, 0, triggerCell.triggercell());
86 }
87 auto ptr = trigger2precision_.find(eff_id);
88 if (ptr != trigger2precision_.end()) {
89 for (auto idz : ptr->second) {
90 retval.push_back(
91 ldmx::EcalID(triggerCell.layer(), triggerCell.module(), idz.cell()));
92 }
93 }
94 return retval;
95}
96
98 ldmx::EcalTriggerID triggerCell) const {
100 if ((symmetry_ & MODULES_MASK) == INPLANE_IDENTICAL) {
101 eff_id = ldmx::EcalTriggerID(0, 0, triggerCell.triggercell());
102 }
103 auto ptr = trigger2precision_.find(eff_id);
104 if (ptr == trigger2precision_.end()) {
105 std::stringstream ss;
106 ss << "Unable to find trigger cell " << triggerCell;
107 EXCEPTION_RAISE("EcalGeometryException", ss.str());
108 }
109
110 return ldmx::EcalID(triggerCell.layer(), triggerCell.module(),
111 ptr->second[4].cell());
112}
113
115 ldmx::EcalID precisionCell) const {
116 ldmx::EcalID eff_id;
117 if ((symmetry_ & MODULES_MASK) == INPLANE_IDENTICAL) {
118 eff_id = ldmx::EcalID(0, 0, precisionCell.cell());
119 }
120 auto ptr = precision2trigger_.find(eff_id);
121 if (ptr == precision2trigger_.end()) {
122 return ldmx::EcalTriggerID(0, 0, 0); // not ideal
123 } else {
124 return ldmx::EcalTriggerID(precisionCell.layer(), precisionCell.module(),
125 ptr->second.triggercell());
126 }
127}
128
129// as it happens, the fifth precision cell in the list is the center cell
130std::tuple<double, double, double> EcalTriggerGeometry::globalPosition(
131 ldmx::EcalTriggerID triggerCell) const {
132 if (!ecal_geometry_) return std::make_tuple(0, 0, 0);
133 ldmx::EcalID pid = centerInTriggerCell(triggerCell);
134 return ecal_geometry_->getPosition(pid);
135}
136
137std::pair<double, double> EcalTriggerGeometry::localPosition(
138 ldmx::EcalTriggerID triggerCell) const {
139 if (!ecal_geometry_) return std::make_pair(0, 0);
140 ldmx::EcalID pid = centerInTriggerCell(triggerCell);
142}
143
145 public:
149 EcalTriggerGeometryProvider(const std::string& name,
150 const std::string& tagname,
151 const framework::config::Parameters& parameters,
153 : ConditionsObjectProvider(EcalTriggerGeometry::CONDITIONS_OBJECT_NAME,
154 tagname, parameters, process),
155 ecal_trigger_geometry_{nullptr} {}
156
159 if (ecal_trigger_geometry_ != nullptr) delete ecal_trigger_geometry_;
160 ecal_trigger_geometry_ = nullptr;
161 }
162
169 virtual std::pair<const framework::ConditionsObject*,
172 if (ecal_trigger_geometry_ == nullptr) {
173 std::pair<const framework::ConditionsObject*, framework::ConditionsIOV>
174 cond_ecal_geom = requestParentCondition(
175 ldmx::EcalGeometry::CONDITIONS_OBJECT_NAME, context);
176 const ldmx::EcalGeometry* ecalgeom =
177 dynamic_cast<const ldmx::EcalGeometry*>(cond_ecal_geom.first);
178 ecal_trigger_geometry_ = new EcalTriggerGeometry(
179 INPLANE_IDENTICAL | LAYERS_IDENTICAL, ecalgeom);
180 }
181 return std::make_pair(ecal_trigger_geometry_,
183 context.getRun(), context.getRun(), true, true));
184 }
185
191
192 private:
193 EcalTriggerGeometry* ecal_trigger_geometry_;
194};
195
196} // namespace ecal
Base class for provider of conditions information like pedestals, gains, electronics maps,...
#define DECLARE_CONDITIONS_PROVIDER(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...
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.
const ldmx::EcalGeometry * ecal_geometry_
Reference to the Ecal geometry used for trigger geometry information.
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:34
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:26
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