Newer
Older
Shaojun Lu
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/*
* MegatileLayerGridXY.cpp
*
* Created on: April 19, 2016
* Author: S. Lu, DESY
* D Jeans UTokyo
*/
#define VERBOSEcoterra 1
#include "DDSegmentation/MegatileLayerGridXY.h"
#include <cassert>
namespace DD4hep {
namespace DDSegmentation {
/// default constructor using an encoding string
MegatileLayerGridXY::MegatileLayerGridXY(const std::string& cellEncoding) :
CartesianGrid(cellEncoding) {
// define type and description
_type = "MegatileLayerGridXY";
// _description = "Cartesian segmentation in the local XY-plane for both Normal wafer and Magic wafer(depending on the layer dimensions)";
_description = "Cartesian segmentation in the local XY-plane: megatiles with dead areas; integer number of megatiles and cells";
//////// setup in the compact-steering file (i.e., ILD_o3_v05.xml)////
// for example,
// <segmentation type="MegatileLayerGridXY" yer_nCells="36" layer_nStripsX="2" layer_nStripsY="36" deadWidth="0" layer_configuration="TL"/>
registerParameter("nMegaY", "number of megatiles along Z", _nMegaY , 1 , SegmentationParameter::NoUnit, true);
// _nMegaY is given by Ecal_n_wafers_per_tower from "model_parameters_ILD_o3_v05.xml"
registerParameter("layer_nCells", "division of megatile into square tiles", _nCells, 36 , SegmentationParameter::NoUnit, true);
registerParameter("layer_nStripsX", "division of megatile into strips (1)", _nStripsX, 4 , SegmentationParameter::NoUnit, true);
registerParameter("layer_nStripsY", "division of megatile into strips (2)", _nStripsY, 36 , SegmentationParameter::NoUnit, true);
registerParameter("deadWidth", "width of dead region at edge of megatile", _deadWidth, 0., SegmentationParameter::LengthUnit, true);
registerIdentifier("identifier_x", "Cell ID identifier for X", _xId, "cellX");
registerIdentifier("identifier_y", "Cell ID identifier for Y", _yId, "cellY");
registerParameter("identifier_wafer", "Cell encoding identifier for wafer", _identifierWafer, std::string("wafer"),
SegmentationParameter::NoUnit, true);
// registerParameter("identifier_wafer_y", "Cell encoding identifier for wafer in y", _identifierWaferY, std::string("waferY"),
// SegmentationParameter::NoUnit, true);
registerParameter("identifier_layer", "Cell encoding identifier for layer", _identifierLayer, std::string("layer"),
SegmentationParameter::NoUnit, true);
// registerParameter("identifier_deadArea", "Cell encoding identifier for dead area", _identifierGR, std::string("deadArea"),
// SegmentationParameter::NoUnit, true);
//registerParameter("layer_configuration", "layer configuration (S, T, L)", _layerConfig, std::string("TLS"), SegmentationParameter::NoUnit, true);
registerParameter("layer_configuration", "layer configuration (S, T, L)", _layerConfig, std::string("TLS"), SegmentationParameter::NoUnit, true);
_calculated=false;
}
/// destructor
MegatileLayerGridXY::~MegatileLayerGridXY() {
}
void MegatileLayerGridXY::calculateDerivedQuantities() const {
if (_calculated) return; // already up to date
///// g514 coterra _megaSize = _totalSizeX / _nMegaX ; // size of square megatile in this layer
///// Here we determine standard strip dimension. Therefore, we use the standard EBU dimension.
// Therefore we use global values _megaSize determined with _totalSizeY and _nMegaY.
_megaSize = _totalSizeY / _nMegaY ; // size of square megatile in this layer
_gridSizeL = (_megaSize - 2.*_deadWidth) / _nStripsX ; // size of cell within megatile (x)
_gridSizeT = (_megaSize - 2.*_deadWidth) / _nStripsY ;
_gridSizeS = (_megaSize - 2.*_deadWidth) / _nCells;
std::cout << "calculateDerivedQuantities: total X width: " << _totalSizeX << " / nMega: " << _nMegaY << " = " << _megaSize << " ; dead width = " << _deadWidth <<
" ; nstripsX,Y, nCells : " << _nStripsX << " " << _nStripsY << " " << _nCells <<
" ; stripX,Y/cell size: " << _gridSizeL << " " << _gridSizeT << " " << _gridSizeS << std::endl;
_calculated=true;
return;
}
/// determine the position based on the cell ID
Vector3D MegatileLayerGridXY::position(const CellID& cID) const {
calculateDerivedQuantities();
_decoder->setValue(cID);
unsigned int LayerIndex;
unsigned int WaferIndex;
unsigned int CellIndexX;
unsigned int CellIndexY;
Vector3D cellPosition;
LayerIndex = (*_decoder)[_identifierLayer];
WaferIndex = (*_decoder)[_identifierWafer];
// WaferIndexY = (*_decoder)[_identifierWaferY];
CellIndexX = (*_decoder)[_xId];
CellIndexY = (*_decoder)[_yId];
#if 0
// offset of area
cellPosition.X = - _totalSizeX[ LayerIndex ] / 2.;
cellPosition.Y = - _totalSizeY / 2.;
#if VERBOSEcoterra
std::cout << "with offset: cellPosition.X = " << cellPosition.X << ", cellPosition.Y = " << cellPosition.Y << std::endl;
#endif
// WaferIndex is stard with 1.
int WaferIndexX = ( WaferIndex - 1 ) / _nMegaY + 1;
int WaferIndexY = WaferIndex%_nMegaY + 1;
#if VERBOSEcoterra
std::cout << "WaferIndexY = WaferIndex%_nMegaY + 1; " << WaferIndexY << " = " << WaferIndex << " % " << _nMegaY << " + " << 1 << std::endl;
#endif
cellPosition.X += (WaferIndexX - 1) * _megaSize;
cellPosition.Y += (WaferIndexY - 1) * _megaSize;
#if VERBOSEcoterra
std::cout << "WaferIndexX = " << WaferIndexX << ", WaferIndexY = " << WaferIndexY << std::endl;
std::cout << "+ WaferIndexX*_megaSize: cellPosition.X = " << cellPosition.X << ", cellPosition.Y = " << cellPosition.Y << std::endl;
#endif
#endif
double regulatingEBUSizeX = _waferOffsetX[LayerIndex][WaferIndex] * 2;
double regulatingEBUSizeY = _waferOffsetY[LayerIndex][WaferIndex] * 2;
std::vector<double> celldims = layercellDimensions( LayerIndex );
cellPosition.X = -regulatingEBUSizeX / 2.;
cellPosition.Y = -regulatingEBUSizeY / 2.; // _megaSize includes two _deadWidth.
cellPosition.Y += (CellIndexY + 0.5) * celldims[1];
double XfromEdge = 0;
//double d_regulation = _megaSize - regulatingEBUSizeX;
//if ( d_regulation > 0.1 && celldims[0] > celldims[1]*1.5 ) {
#if VERBOSEcoterra
if ( _isRegulatingEBU[LayerIndex][WaferIndex] ) {
std::cout << "regulatingEBUSizeX, regulatingEBUSizeY(layer) = " << regulatingEBUSizeX << ", " << regulatingEBUSizeY
<< "(" << LayerIndex << ")" << std::endl;
std::cout << "CellIndexX, Y = " << CellIndexX << ", " << CellIndexY << ", celldims[0], [1] = " << celldims[0]
<< ", " << celldims[1] << std::endl;
std::cout << "cellPosition.X, Y = " << cellPosition.X << ", " << cellPosition.Y << std::endl;
}
#endif
int n_cellX = regulatingEBUSizeX / celldims[0];
if ( _isRegulatingEBU[LayerIndex][WaferIndex] && celldims[0] > celldims[1]*1.5
&&CellIndexX == (unsigned int)(n_cellX - 1) ) {
XfromEdge = ( n_cellX -1) * celldims[0] + ( regulatingEBUSizeX-( n_cellX -1) * celldims[0] )/2;
#if VERBOSEcoterra
std::cout << "This hit is out of regulation EBU=> merged into neighbour strip; XfromEdge = " << XfromEdge << std::endl;
#endif
} else {
XfromEdge = (CellIndexX + 0.5) * celldims[0];
}
////////////////cellPosition.X += _deadWidth + XfromEdge;
cellPosition.X += XfromEdge;
#if VERBOSEcoterra
std::cout << "+ _deadWidth + ( CellIndexX + 0.5 )*celldims[0]: cellPosition.X = " << cellPosition.X << ", cellPosition.Y = " << cellPosition.Y << std::endl;
std::cout << "CellIndexX * celldims[0] = " << CellIndexX << " x " << celldims[0]
<< ", CellIndexY * celldims[1] = " << CellIndexY << " x " << celldims[1]
<< ", _isRegulatingEBU[" << LayerIndex << "][" << WaferIndex << "] = " << _isRegulatingEBU[LayerIndex][WaferIndex]
<< std::endl;
std::cout << "in MegatileLayerGridXY: regulatingEBUSizeX = " << regulatingEBUSizeX << std::endl;
#endif
return cellPosition;
}
/// determine the cell ID based on the position
CellID MegatileLayerGridXY::cellID(const Vector3D& localPosition, const Vector3D& /* globalPosition */, const VolumeID& vID) const {
calculateDerivedQuantities();
_decoder->setValue(vID);
unsigned int layerIndex = (*_decoder)[_identifierLayer];
unsigned int waferIndex = (*_decoder)[_identifierWafer];
double _x = localPosition.X;
double _y = localPosition.Y;
int _cellIndexX(-1);
int _cellIndexY(-1);
// std::cout << "hello3 " << _x << " " << _y << std::endl;
std::vector<double> celldims = layercellDimensions( layerIndex );
#if VERBOSEcoterra
std::cout << "in cellID before area check" << std::endl;
std::cout << "_x = localPosition.X: " << _x << " = " << localPosition.X << ", _waferOffsetX["
<< layerIndex << "][" << waferIndex << "] = " << _waferOffsetX[layerIndex][waferIndex] << std::endl;
std::cout << "_y = localPosition.Y: " << _y << " = " << localPosition.Y << ", _waferOffsetY["
<< layerIndex << "][" << waferIndex << "] = " << _waferOffsetY[layerIndex][waferIndex] << std::endl;
// std::cout << "_waferIndexX = " << _waferIndexX[][] << std::endl;
// std::cout << "_waferIndexY = " << _waferIndexY << std::endl;
std::cout << "_megaSize = " << _megaSize << std::endl;
#endif
double WaferOffsetX = _waferOffsetX[layerIndex][waferIndex];
double WaferOffsetY = _waferOffsetY[layerIndex][waferIndex];
#if VERBOSEcoterra
std::cout << "WaferOffsetX = " << _waferOffsetX[layerIndex][waferIndex]
<< " layer, wafer = " << layerIndex << ", " << waferIndex
<< std::endl;
#endif
// _waferOffsetX has negative sign. <<<---??? not true!!
if ( _x < -WaferOffsetX || _x > WaferOffsetX ||
_y < -WaferOffsetY || _y > WaferOffsetY ) {
#if VERBOSEcoterra
std::cout << "This hit falls down in to dead width." << std::endl;
#endif
// dead area at edge of wafer
} else {
// localPosition.X is in a coordination which center is at the center of wafer.
// _waferOffsetX is 1/2 of wafer_dim_x,
// and wafer_dim_x is already subtracted with the guard ring (deadWidth);
// _x should be interpret in a coodination who's origin is on the edge of wafre... negative--> positive sign.
_x += WaferOffsetX;
_y += WaferOffsetY;
#if VERBOSEcoterra
if ( _isRegulatingEBU[layerIndex][waferIndex] ) {
std::cout << "in cellID on hit " << std::endl;
std::cout << "_x = localPosition.X + _waferOffsetX; => " << _x << " = " << localPosition.X << " + " << WaferOffsetX << std::endl;
std::cout << "_y = localPosition.Y + _waferOffsetY; => " << _y << " = " << localPosition.Y << " + " << WaferOffsetY << std::endl;
// std::cout << "_waferIndexX = " << _waferIndexX << std::endl;
// std::cout << "_waferIndexY = " << _waferIndexY << std::endl;
std::cout << "_megaSize = " << _megaSize << std::endl;
}
#endif
// edge of active area of megatile
_cellIndexX = int ( _x / celldims[0] );
_cellIndexY = int ( _y / celldims[1] );
#if VERBOSEcoterra
std::cout << "in cellID after subtract other wafers" << std::endl;
std::cout << "_x = " << _x << " and _y = " << _y << " _deadWidth = " << _deadWidth << "; in cellID" << std::endl;
if ( _isRegulatingEBU[layerIndex][waferIndex] && celldims[0] < celldims[1]*1.5 ) {
int temp_n_cellX = WaferOffsetX * 2 / celldims[0];
// if ( _cellIndexX > temp_n_cellX - 1 ) {
std::cout << "EXESS hit in transeverse layer WaferOffsetX = " << WaferOffsetX
<< ", celldims[0] = " << celldims[0]
<< ", _cellIndexX = " << _cellIndexX
<< ", _x = " << _x
<< ", _megaSize = " << _megaSize
<< ", temp_n_cellX = " << temp_n_cellX
<< std::endl;
// }
}
#endif
if ( _isRegulatingEBU[layerIndex][waferIndex] && celldims[0] > celldims[1]*1.5 ) {
int n_cellX = WaferOffsetX * 2 / celldims[0]; // How many strip-row can stay on this EBU.
if ( _cellIndexX > n_cellX - 1 ) { // hit position is out of this EBU.
_cellIndexX -= 1;
#if VERBOSEcoterra
std::cout << "This hit is out of regulation EBU=> merged into neighbour strip; _cellIndexX = " << _cellIndexX << std::endl;
#endif
}
}
}
// std::cout << " wafer, cell indx " << _waferIndexX << " " << _waferIndexY << " , " << _cellIndexX << " " << _cellIndexY << std::endl;
/////xxxxxxxxxxxxxxxxxxx
if ( _isRegulatingEBU[layerIndex][waferIndex] ) {
// _cellIndexX = 0;
}
(*_decoder)[_xId] = _cellIndexX;
(*_decoder)[_yId] = _cellIndexY;
//_waferIndexX(Y) were calculated in SEcal04Hybrid_Barrel using setWaferIndexX(Y)
// (*_decoder)[_identifierWaferX] = _waferIndexX;
// (*_decoder)[_identifierWaferY] = _waferIndexY;
return _decoder->getValue();
}
std::vector<double> MegatileLayerGridXY::cellDimensions(const CellID& cID) const {
_decoder->setValue( cID );
unsigned int _layerIndex = (*_decoder)[_identifierLayer];
return layercellDimensions(_layerIndex);
}
std::vector<double> MegatileLayerGridXY::layercellDimensions(const int layerIndex) const {
calculateDerivedQuantities();
unsigned int mm = layerIndex % _layerConfig.length();
const char laytype = _layerConfig.at(mm);
double xsize(0);
double ysize(0);
if ( laytype=='S' ) { // square cell
xsize = ysize = _gridSizeS;
} else if ( laytype=='T' ) { // transverse
xsize = _gridSizeT;
ysize = _gridSizeL;
} else if ( laytype=='L' ) { // transverse
xsize = _gridSizeL;
ysize = _gridSizeT;
} else {
assert(0);
}
// std::cout << laytype << " " << xsize << " " << ysize << std::endl;
#if __cplusplus >= 201103L
// return {_gridSizeX[_layerIndex], _gridSizeY[_layerIndex]};
// return {_gridSizeX, _gridSizeY};
return {xsize, ysize};
#else
std::vector<double> cellDims(2,0.0);
//cellDims[0] = _gridSizeX[_layerIndex];
//cellDims[1] = _gridSizeY[_layerIndex];
//cellDims[0] = _gridSizeX;
//cellDims[1] = _gridSizeY;
cellDims[0] = xsize;
cellDims[1] = ysize;
return cellDims;
#endif
}
REGISTER_SEGMENTATION(MegatileLayerGridXY)
} /* namespace DDSegmentation */
} /* namespace DD4hep */