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