LDMX Software
print_ecal_hex_readout.cxx
1
2#include <math.h>
3
4#include <any>
5#include <map>
6#include <string>
7
9#include "DetDescr/EcalID.h"
12#include "Framework/Configure/Parameters.h"
13#include "TCanvas.h" //for dumping map to file
14#include "TLine.h" //for module hex border
15#include "TStyle.h" //for no stats box
16#include "TText.h"
17
24int main() {
25 // first create the ecal hex readout
26
27 // These are the v12 parameters
28 // all distances in mm
29 std::vector<double> ecalSensLayersZ = {
30 7.850, 13.300, 26.400, 33.500, 47.950, 56.550, 72.250,
31 81.350, 97.050, 106.150, 121.850, 130.950, 146.650, 155.750,
32 171.450, 180.550, 196.250, 205.350, 221.050, 230.150, 245.850,
33 254.950, 270.650, 279.750, 298.950, 311.550, 330.750, 343.350,
34 362.550, 375.150, 394.350, 406.950, 426.150, 438.750};
36 params.addParameter("layerZPositions", ecalSensLayersZ);
37 params.addParameter("ecalFrontZ", 220.);
38 params.addParameter("moduleMinR", 85.0);
39 params.addParameter("nCellRHeight", 35.3);
40 params.addParameter("gap", 1.5);
41 params.addParameter("cornersSideUp", false);
42 params.addParameter("layer_shift_x", 0.);
43 params.addParameter("layer_shift_y", 0.);
44 params.addParameter("layer_shift_odd", false);
45 params.addParameter("layer_shift_odd_bilayer", false);
46 params.addParameter("verbose", 1);
47
48 ldmx::EcalGeometry* geometry_ptr = ldmx::EcalGeometry::debugMake(params);
49 ldmx::EcalGeometry& geometry(*geometry_ptr);
50
53 auto polyMap = geometry.getCellPolyMap();
54
55 TCanvas* c = new TCanvas("c", "c", 900, 900); // make square canvas
56 c->SetMargin(0.15, 0.05, 0.1, 0.1);
57 gStyle->SetOptStat(0); // no stat box
58 polyMap->SetTitle(
59 "Local Cell ID to Local Cell Position Map;"
60 "P Position Relative to Module [mm];"
61 "Q Position Relative to Module [mm]");
62 polyMap->GetXaxis()->SetTickLength(0.);
63 polyMap->GetYaxis()->SetTickLength(0.);
64 polyMap->Draw("TEXT"); // print with bin context labeled as text
65
66 double hexCornerRadius = 85.0 * (2 / sqrt(3));
67 std::vector<std::pair<double, double> > hexCorners = {
68 std::make_pair(+1. * hexCornerRadius, 0.),
69 std::make_pair(+1. * hexCornerRadius * cos(M_PI / 3),
70 +1. * hexCornerRadius * sin(M_PI / 3)),
71 std::make_pair(-1. * hexCornerRadius * cos(M_PI / 3),
72 +1. * hexCornerRadius * sin(M_PI / 3)),
73 std::make_pair(-1. * hexCornerRadius, 0.),
74 std::make_pair(-1. * hexCornerRadius * cos(M_PI / 3),
75 -1. * hexCornerRadius * sin(M_PI / 3)),
76 std::make_pair(+1. * hexCornerRadius * cos(M_PI / 3),
77 -1. * hexCornerRadius * sin(M_PI / 3)),
78 std::make_pair(+1. * hexCornerRadius, 0.)};
79 TLine moduleHexBorder{0., 0., 0., 0.};
80 moduleHexBorder.SetLineColorAlpha(kRed, 0.5);
81 moduleHexBorder.SetLineWidth(2);
82 for (int i = 1; i < hexCorners.size(); i++) {
83 moduleHexBorder.DrawLine(hexCorners.at(i - 1).first,
84 hexCorners.at(i - 1).second,
85 hexCorners.at(i).first, hexCorners.at(i).second);
86 }
87
88 c->Update();
89 c->SaveAs("Cell_ID_Cell_Position_Map.pdf");
90
91 polyMap->SetTitle(
92 "Local Cell U,V to Local Cell Position Map;X Position Relative to Module "
93 "[mm];Y Position Relative to Module [mm]");
94 polyMap->GetXaxis()->SetTickLength(0.);
95 polyMap->GetYaxis()->SetTickLength(0.);
96 polyMap->SetMaximum(1000);
97 polyMap->SetMinimum(500);
98 polyMap->Draw("hist"); // print with bin context labeled as text
99
100 for (int icell = 0; icell < 432; icell++) {
101 ldmx::EcalID id(0, 0, icell);
102 std::pair<double, double> pt = geometry.getPositionInModule(icell);
103 char text[100];
104 std::pair<unsigned int, unsigned int> uv = id.getCellUV();
105 sprintf(text, "(%d,%d)", uv.first, uv.second);
106 TText* tt = new TText(pt.first, pt.second, text);
107 tt->SetTextAlign(22);
108 tt->SetTextSize(0.012);
109 tt->Draw("SAME");
110 }
111
112 c->Update();
113 c->SaveAs("Cell_UV_Cell_Position_Map.pdf");
114
115 // and now for triggers
116 ecal::EcalTriggerGeometry trigG(0x100, geometry_ptr);
117 polyMap->SetTitle(
118 "Trigger Cell Summing Map;"
119 "P Position Relative to Module [mm];"
120 "Q Position Relative to Module [mm]");
121 polyMap->GetXaxis()->SetTickLength(0.);
122 polyMap->GetYaxis()->SetTickLength(0.);
123 polyMap->SetMaximum(4);
124 polyMap->SetMinimum(0);
125
126 for (int icell = 0; icell < 432; icell++) {
127 ldmx::EcalID id(0, 0, icell);
128 ldmx::EcalTriggerID tid = trigG.belongsTo(id);
129
130 std::cout << id << "->" << tid << std::endl;
131
132 int ival;
133 if (tid.triggercell() < 16)
134 ival = 1 + tid.triggercell() % 3;
135 else if (tid.triggercell() < 20)
136 ival = 1 + (tid.triggercell() + 1) % 3;
137 else if (tid.triggercell() < 24)
138 ival = 1 + (tid.triggercell() - 1) % 3;
139 else if (tid.triggercell() < 28)
140 ival = 1 + (tid.triggercell()) % 3;
141 else if (tid.triggercell() < 32)
142 ival = 1 + (tid.triggercell() + 1) % 3;
143 else {
144 switch (tid.triggercell()) {
145 case (32):
146 ival = 2;
147 break;
148 case (33):
149 ival = 3;
150 break;
151 case (34):
152 ival = 1;
153 break;
154 case (35):
155 ival = 0;
156 break;
157 case (36):
158 ival = 2;
159 break;
160 case (37):
161 ival = 3;
162 break;
163 case (38):
164 ival = 2;
165 break;
166 case (39):
167 ival = 1;
168 break;
169 case (40):
170 ival = 0;
171 break;
172 case (41):
173 ival = 2;
174 break;
175 case (42):
176 ival = 0;
177 break;
178 case (43):
179 ival = 2;
180 break;
181 case (44):
182 ival = 3;
183 break;
184 case (45):
185 ival = 3;
186 break;
187 case (46):
188 ival = 1;
189 break;
190 case (47):
191 ival = 0;
192 break;
193 default:
194 ival = (tid.triggercell() % 4);
195 }
196 }
197
198 polyMap->SetBinContent(icell + 1, ival);
199 }
200
201 polyMap->Draw("COL"); // print with bin context labeled as text
202
203 for (int tcell = 0; tcell < 48; tcell++) {
204 ldmx::EcalTriggerID tid(0, 0, tcell);
205 std::pair<double, double> pt = trigG.localPosition(tid);
206
207 char text[100];
208 sprintf(text, "(%d)", tcell);
209 TText* tt = new TText(pt.first, pt.second, text);
210 tt->SetTextAlign(22);
211 tt->SetTextSize(0.012);
212 tt->Draw("SAME");
213 }
214
215 c->Update();
216 c->SaveAs("TriggerCell_Position_Map.pdf");
217
218 return 0;
219}
Class that translates raw positions of ECal module hits into cells in a hexagonal readout.
Class that defines an ECal detector ID with a cell number.
Class that defines the relationship between precision cells and trigger cells and provides geometry i...
Class that defines an ECal trigger cell detector ID.
defines the relationship between precision cells and trigger cells and provides geometry information ...
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
void addParameter(const std::string &name, const T &value)
Add a parameter to the parameter list.
Definition Parameters.h:55
Translation between real-space positions and cell IDs within the ECal.
Extension of DetectorID providing access to ECal layers and cell numbers in a hex grid.
Definition EcalID.h:20
Extension of DetectorID providing access to ECal trigger cell information.
int triggercell() const
Get the value of the trigger cell field from the ID.