LDMX Software
Functions
DetectorIDTest.cxx File Reference

Test the operation of DetectorID class. More...

#include <catch2/catch_test_macros.hpp>
#include <sstream>
#include "DetDescr/DetectorID.h"
#include "DetDescr/DetectorIDInterpreter.h"
#include "DetDescr/EcalID.h"
#include "DetDescr/HcalID.h"
#include "DetDescr/SimSpecialID.h"
#include "DetDescr/TrackerID.h"
#include "DetDescr/TrigScintID.h"

Go to the source code of this file.

Functions

 TEST_CASE ("DetectorID", "[DetDescr][functionality]")
 Test for DetectorID function.
 

Detailed Description

Test the operation of DetectorID class.

Definition in file DetectorIDTest.cxx.

Function Documentation

◆ TEST_CASE()

TEST_CASE ( "DetectorID"  ,
""  [DetDescr][functionality] 
)

Test for DetectorID function.

First argument is name of this test. Second argument is tags to group tests together.

Definition at line 22 of file DetectorIDTest.cxx.

22 {
23 using namespace ldmx;
24 DetectorID did_null;
25 DetectorID did_raw(0x40000000);
26 DetectorID did_ecal(SD_ECAL, 0x1010);
27 DetectorID did_hcal(SD_HCAL, 0x0010);
28 DetectorID did_tk(SD_TRACKER_RECOIL, 0x0010);
29 DetectorID did_ts(SD_TRIGGER_SCINT, 0x22);
30 DetectorID did_ss(SD_SIM_SPECIAL, 0x24);
31
32 CHECK_NOTHROW(DetectorIDInterpreter());
33
34 SECTION("Detector ID") {
35 REQUIRE(did_null.null());
36 REQUIRE(did_raw.subdet() == EID_TRACKER);
37 REQUIRE(did_ecal.subdet() == SD_ECAL);
38 REQUIRE(did_ecal.raw() == 0x14001010);
39 REQUIRE(did_ecal < did_raw);
40 REQUIRE(did_ecal != did_null);
41 }
42 SECTION("EcalID") {
43 EcalID eid_empty;
44 EcalID eid_raw(0x14002020);
45
46 REQUIRE_THROWS(EcalID(did_raw));
47 REQUIRE_THROWS(EcalID(0x829018));
48 REQUIRE_NOTHROW(EcalID(did_ecal));
49 REQUIRE_NOTHROW(EcalID(did_ecal.raw()));
50 // choose big values to check collisions
51 EcalID eid(50, 15, 500);
52
53 REQUIRE(eid.raw() == 0x1464f1f4);
54
55 REQUIRE(eid.layer() == 50);
56 REQUIRE(eid.layer() == eid.getLayerID());
57 REQUIRE(eid.module() == 15);
58 REQUIRE(eid.module() == eid.getModuleID());
59 REQUIRE(eid.cell() == 500);
60 REQUIRE(eid.cell() == eid.getCellID());
61
62 std::stringstream ss;
63 ss << eid;
64
65 REQUIRE(ss.str() == "Ecal(50,15,500[92,23])");
66
67 DetectorIDInterpreter dii(eid);
68
69 CHECK(dii.getFieldValue("layer") == 50);
70 CHECK(dii.getFieldValue("module") == 15);
71 CHECK(dii.getFieldValue("cell") == 500);
72
73 dii.setFieldValue("layer", 23);
74 dii.setFieldValue("module", 13);
75 dii.setFieldValue("cell", 223);
76
77 eid = EcalID(dii.getId());
78
79 CHECK(eid.layer() == 23);
80 CHECK(eid.module() == 13);
81 CHECK(eid.cell() == 223);
82 }
83 SECTION("HcalID") {
84 HcalID hid_empty;
85 HcalID hid_raw(0x18002020);
86
87 REQUIRE_THROWS(HcalID(did_raw));
88 REQUIRE_THROWS(HcalID(0x829018));
89 REQUIRE_NOTHROW(HcalID(did_hcal));
90 REQUIRE_NOTHROW(HcalID(did_hcal.raw()));
91
92 // choose big values to check collisions
93 HcalID hid(HcalID::LEFT, 250, 245);
94
95 REQUIRE(hid.raw() == 0x1813e8f5);
96
97 REQUIRE(hid.layer() == 250);
98 REQUIRE(hid.layer() == hid.getLayerID());
99 REQUIRE(hid.section() == HcalID::LEFT);
100 REQUIRE(hid.section() == hid.getSection());
101 REQUIRE(hid.strip() == 245);
102 REQUIRE(hid.strip() == hid.getStrip());
103
104 std::stringstream ss;
105 ss << hid;
106
107 REQUIRE(ss.str() == "Hcal(4,250,245)");
108
109 DetectorIDInterpreter dii(hid);
110
111 CHECK(dii.getFieldValue("layer") == 250);
112 CHECK(dii.getFieldValue("section") == 4);
113 CHECK(dii.getFieldValue("strip") == 245);
114
115 dii.setFieldValue("layer", 23);
116 dii.setFieldValue("section", 1);
117 dii.setFieldValue("strip", 223);
118
119 hid = HcalID(dii.getId());
120
121 CHECK(hid.layer() == 23);
122 CHECK(hid.section() == 1);
123 CHECK(hid.strip() == 223);
124 }
125
126 SECTION("TrackerID") {
127 TrackerID tid_empty;
128 TrackerID tid_raw(0x10002020);
129
130 REQUIRE_THROWS(TrackerID(did_raw));
131 REQUIRE_THROWS(TrackerID(0x829018));
132 REQUIRE_NOTHROW(TrackerID(did_tk));
133 REQUIRE_NOTHROW(TrackerID(did_tk.raw()));
134
135 // choose big values to check collisions
136 TrackerID tid(SD_TRACKER_TAGGER, 250, 30);
137 // choose big values to check collisions
138 TrackerID tid2(SD_TRACKER_RECOIL, 220, 17);
139
140 REQUIRE(tid.raw() == 0x4001efa);
141 REQUIRE(tid2.raw() == 0x100011dc);
142
143 REQUIRE(tid.layer() == 250);
144 REQUIRE(tid.module() == 30);
145
146 REQUIRE(tid2.layer() == 220);
147 REQUIRE(tid2.module() == 17);
148
149 std::stringstream ss;
150 ss << tid << tid2;
151
152 REQUIRE(ss.str() == "Tagger(250,30)Recoil(220,17)");
153
154 DetectorIDInterpreter dii(tid);
155
156 CHECK(dii.getFieldValue("layer") == 250);
157 CHECK(dii.getFieldValue("module") == 30);
158
159 dii.setFieldValue("layer", 213);
160 dii.setFieldValue("module", 23);
161
162 tid = TrackerID(dii.getId());
163
164 CHECK(tid.layer() == 213);
165 CHECK(tid.module() == 23);
166 }
167 SECTION("TrigScintID") {
168 TrigScintID ts_id_empty;
169 TrigScintID ts_id_raw(0x08002020);
170
171 REQUIRE_THROWS(TrigScintID(did_raw));
172 REQUIRE_THROWS(TrigScintID(0x829018));
173 REQUIRE_NOTHROW(TrigScintID(did_ts));
174 REQUIRE_NOTHROW(TrigScintID(did_ts.raw()));
175
176 // choose big values to check collisions
177 TrigScintID ts_id(250, 245);
178
179 CHECK(ts_id.raw() == 0x800faf5);
180
181 REQUIRE(ts_id.module() == 250);
182 REQUIRE(ts_id.getModule() == 250);
183 REQUIRE(ts_id.bar() == 245);
184 REQUIRE(ts_id.bar() == ts_id.getBarID());
185
186 std::stringstream ss;
187 ss << ts_id;
188
189 REQUIRE(ss.str() == "TrigScint(250,245)");
190
191 DetectorIDInterpreter dii(ts_id);
192
193 CHECK(dii.getFieldValue("bar") == 245);
194 CHECK(dii.getFieldValue("module") == 250);
195
196 dii.setFieldValue("bar", 213);
197 dii.setFieldValue("module", 23);
198
199 ts_id = TrigScintID(dii.getId());
200
201 CHECK(ts_id.bar() == 213);
202 CHECK(ts_id.module() == 23);
203 }
204 SECTION("SimSpecialID") {
205 SimSpecialID ssid_empty;
206 SimSpecialID ssid_raw(0x1C002020);
207
208 REQUIRE_THROWS(SimSpecialID(did_raw));
209 REQUIRE_THROWS(SimSpecialID(0x829018));
210 REQUIRE_NOTHROW(SimSpecialID(did_ss));
211 REQUIRE_NOTHROW(SimSpecialID(did_ss.raw()));
212
213 // choose big values to check collisions
214 SimSpecialID ssid = SimSpecialID::ScoringPlaneID(3210);
216
217 CHECK(ssid.raw() == 0x1c400c8a);
218 CHECK(ssid2.raw() == 0x1c4fedcb);
219
220 REQUIRE(ssid.getSubtype() == SimSpecialID::SCORING_PLANE);
221 REQUIRE(ssid2.getSubtype() == 1);
222
223 REQUIRE(ssid.plane() == 3210);
224 REQUIRE(ssid2.plane() == 3531);
225 REQUIRE(ssid.subtypePayload() == 3210);
226 REQUIRE(ssid2.subtypePayload() == 0xfedcb);
227
228 std::stringstream ss;
229 ss << ssid << ssid2;
230
231 REQUIRE(ss.str() ==
232 "SimSpecial(ScoringPlane 3210)SimSpecial(ScoringPlane 3531)");
233
234 DetectorIDInterpreter dii(ssid);
235
236 CHECK(dii.getFieldValue("subtype") == 1);
237 CHECK(dii.getFieldValue("payload") == 3210);
238 }
239}
Class provides an "introspection" capability for the 32-bit packed IDs used for uniquely identifying ...
Defines a 32-bit packed ID for uniquely identifying hits and detector components.
Definition DetectorID.h:35
bool null() const
Definition DetectorID.h:60
RawValue raw() const
Definition DetectorID.h:68
Extension of DetectorID providing access to ECal layers and cell numbers in a hex grid.
Definition EcalID.h:20
Implements detector ids for HCal subdetector.
Definition HcalID.h:19
Implements detector ids for special simulation-derived hits like scoring planes.
int plane() const
Get the value of the plane field from the ID, if it is a scoring plane.
RawValue subtypePayload() const
Get the raw payload contents.
SimSpecialType
Encodes which of several possible special types this SimSpecial ID is.
Extension of DetectorID providing access to layer and module number for tracker IDs.
Definition TrackerID.h:20
Class that defines the detector ID of the trigger scintillator.
Definition TrigScintID.h:14

References ldmx::TrigScintID::bar(), ldmx::EcalID::cell(), ldmx::TrigScintID::getBarID(), ldmx::EcalID::getCellID(), ldmx::DetectorIDInterpreter::getFieldValue(), ldmx::DetectorIDInterpreter::getId(), ldmx::EcalID::getLayerID(), ldmx::HcalID::getLayerID(), ldmx::TrigScintID::getModule(), ldmx::EcalID::getModuleID(), ldmx::HcalID::getStrip(), ldmx::EcalID::layer(), ldmx::HcalID::layer(), ldmx::TrackerID::layer(), ldmx::EcalID::module(), ldmx::TrackerID::module(), ldmx::TrigScintID::module(), ldmx::DetectorID::null(), ldmx::SimSpecialID::plane(), ldmx::DetectorID::raw(), ldmx::DetectorIDInterpreter::setFieldValue(), ldmx::HcalID::strip(), ldmx::DetectorID::subdet(), and ldmx::SimSpecialID::subtypePayload().