ATLAS Offline Software
Loading...
Searching...
No Matches
Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/FCAL_ChannelMap.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5// ***************************************************************************
6// Liquid Argon FCAL detector description package
7// -----------------------------------------
8//
9//
10// 10-Sep-2000 S.Simion Handling of the FCAL read-out identifiers
11// Jan-2001 R.Sobie Modify for persistency
12// Feb-2002 R.Sobie Use same FCAL geometry files as simulation
13//****************************************************************************
14
16#include <sstream>
17#include <iostream>
18#include <iomanip>
19#include <stdio.h>
20#include <cmath>
21#include <stdexcept>
22
23/* === Geometrical parameters === */
24//const double cm = 0.01;
25const double cm = 10.;
26//const double FCAL_ChannelMap::m_tubeSpacing[] = {0.75*CLHEP::cm, 0.8179*CLHEP::cm, 0.90*CLHEP::cm};
27const double FCAL_ChannelMap::m_tubeSpacing[] = {0.75*cm, 0.8179*cm, 0.90*cm};
28
30{
31 static const double root3_2 = std::sqrt(3.)/2;
32 /* === Initialize geometrical dimensions */
33 for(int i=0; i<3; i++){
34 m_tubeDx[i] = m_tubeSpacing[i] / 2.;
35 m_tubeDy[i] = m_tubeSpacing[i] * root3_2;
36 }
37
38 // FCAL1 small cells are 2x2 tubes
39 m_tileDx[0] = 2. * m_tubeSpacing[0];
40 m_tileDy[0] = 2. * m_tubeSpacing[0] * root3_2;
41
42 // FCAL2 small cells are 2x3 tubes
43 m_tileDx[1] = 2. * m_tubeSpacing[1];
44 m_tileDy[1] = 3. * m_tubeSpacing[1] * root3_2;
45
46 // FCAL3 cells are 6x6 tubes
47 m_tileDx[2] = 6. * m_tubeSpacing[2];
48 m_tileDy[2] = 6. * m_tubeSpacing[2] * root3_2;
49
50
51 m_invert_x = flag & 1;
52 m_invert_xy = flag & 2;
53
54}
55
56
61}
62
63// *********************************************************************
64// Read tube mapping tables
65//
66// Jan 23,2002 R. Sobie
67// ********************************************************************
68
69
70//original
71void FCAL_ChannelMap::add_tube(const std::string & tileName, int mod, int /*id*/, int i, int j, double x, double y) {
72
73 // Get three integers from the tileName:
74 std::istringstream tileStream1(std::string(tileName,1,1));
75 std::istringstream tileStream2(std::string(tileName,3,2));
76 std::istringstream tileStream3(std::string(tileName,6,3));
77 int a1=0,a2=0,a3=0;
78 if (tileStream1) tileStream1 >> a1;
79 if (tileStream2) tileStream2 >> a2;
80 if (tileStream3) tileStream3 >> a3;
81
82 tileName_t tilename = (a3 << 16) + a2;
83
84 TubePosition tb(tilename, x*cm, y*cm,"");
85 // Add offsets, becaues iy and ix can be negative HMA
86
87 i = i+200;
88 j = j+200;
89 // m_tubeMap[mod-1][(j << 16) + i] = tb;
90 unsigned int ThisId = (j<<16) + i;
91 tubemap_const_iterator p = m_tubeMap[mod-1].insert(m_tubeMap[mod-1].end(),std::make_pair(ThisId,tb));
92 m_tubeIndex[mod-1].push_back(p);
93}
94
95
96//Gabe: new to include HV and LARFCALELECRTODES ID
97void FCAL_ChannelMap::add_tube(const std::string & tileName, int mod, int /*id*/, int i, int j, double x, double y, const std::string & hvFT) {
98
99 // Get three integers from the tileName:
100 std::istringstream tileStream1(std::string(tileName,1,1));
101 std::istringstream tileStream2(std::string(tileName,3,2));
102 std::istringstream tileStream3(std::string(tileName,6,3));
103 int a1=0,a2=0,a3=0;
104 if (tileStream1) tileStream1 >> a1;
105 if (tileStream2) tileStream2 >> a2;
106 if (tileStream3) tileStream3 >> a3;
107
108 tileName_t tilename = (a3 << 16) + a2;
109
110 TubePosition tb(tilename, x*cm,y*cm, hvFT);
111 // Add offsets, becaues iy and ix can be negative HMA
112
113 i = i+200;
114 j = j+200;
115 // m_tubeMap[mod-1][(j << 16) + i] = tb;
116 unsigned int ThisId = (j<<16) + i;
117 tubemap_const_iterator p = m_tubeMap[mod-1].insert(m_tubeMap[mod-1].end(),std::make_pair(ThisId,tb));
118 m_tubeIndex[mod-1].push_back(p);
119}
120
122 return m_tubeIndex[isam-1][copyNo];
123}
124
125
126// *********************************************************************
127// Create tile mapping tables
128//
129// Jan 23,2002 R. Sobie
130// ********************************************************************
131void
133{
135 tubemap_const_iterator first = m_tubeMap[isam-1].begin();
136 tubemap_const_iterator last = m_tubeMap[isam-1].end();
137
138 // Loop over tubes -> find unique tiles and fill the descriptors
139 while (first != last){
140
141 tileName_t tileName = (first->second).get_tileName();
142 tile = m_tileMap[isam-1].find(tileName);
143
144 if (tile == m_tileMap[isam-1].end()){ // New tile found
145 float x = (first->second).x();
146 float y = (first->second).y();
147 unsigned int ntubes = 1;
148 TilePosition tp(x, y, ntubes);
149 m_tileMap[isam-1][tileName] = tp;
150 }
151 else{ // Existing tile
152 float x = (tile->second).x() + (first->second).x();
153 float y = (tile->second).y() + (first->second).y();
154 unsigned int ntubes = (tile->second).ntubes() + 1;
155 TilePosition tp(x, y, ntubes);
156 m_tileMap[isam-1][tileName] = tp;
157 }
158 ++first;
159 }
160
161 //
162 // List the number of tubes and tiles
163 //
164 // std::cout << "FCAL::create_tilemap: FCAL # " << isam
165 // << " Number of tiles = " << m_tileMap[isam-1].size()
166 // << " Number of tubes = " << m_tubeMap[isam-1].size()
167 // << std::endl;
168
169 // this->print_tubemap(isam);
170
171
172 //
173 // loop over tiles and set (x,y) to average tile positions
174 //
175 tileMap_const_iterator tilefirst = m_tileMap[isam-1].begin();
176 tileMap_const_iterator tilelast = m_tileMap[isam-1].end();
177 while (tilefirst != tilelast) {
178 tileName_t tileName = tilefirst->first;
179 unsigned int ntubes = (tilefirst->second).ntubes();
180 float xtubes = (float) ntubes;
181 float x = (tilefirst->second).x() / xtubes;
182 float y = (tilefirst->second).y() / xtubes;
183 TilePosition tp(x, y, ntubes);
184 m_tileMap[isam-1][tileName] = tp;
185 ++tilefirst;
186 }
187
188}
189
190//---------- for New LArFCAL_ID ------------------------
191
192// *********************************************************************
193// get Tile ID
194//
195// Original code: Stefan Simion, Randy Sobie
196// -------------------------------------------------------------------
197// This function computes the tile identifier for any given position
198// Inputs:
199// - isam the sampling number, from G3 data;
200// - x the tube x position, in CLHEP::cm, from G3 data;
201// - y the tube y position, in CLHEP::cm, from G3 data.
202// Outputs:
203// - pair of indices eta, phi
204//
205// Attention side-effect: x is changed by this function.
206// --------------------------------------------------------------------
207// June 2002 HMA
208// ***********************************************************************
209bool
210FCAL_ChannelMap::getTileID(int isam, float x_orig, float y_orig,
211 int& eta, int& phi) const
212{
213
214// /* ### MIRROR for compatibility between G3 and ASCII files ### */
215
216 float x = x_orig;
217 float y = y_orig;
218
219 if(m_invert_xy){
220 x = y_orig;
221 y = x_orig;
222 }
223
224 if(m_invert_x) x = -x;
225
226 /* === Compute the tubeID */
227 int ktx = (int) (x / m_tubeDx[isam-1]);
228 int kty = (int) (y / m_tubeDy[isam-1]);
229 if (x < 0.) ktx--;
230 if (y < 0.) kty--;
231
232 // S.M.: in case we lookup real positions inside the Tile (not only
233 // integer grids for the tubes) half of the time we are outisde a
234 // tube bin since the integer pattern of the tubes is like in this
235 // sketch:
236 //
237 // # # # #
238 // # # # #
239 // # # # #
240 //
241 // in order to avoid this problem we have to make sure the integer
242 // indices for x and y have either both to be even or both to be odd
243 // (For Module 0 one has to be odd the other even ...). We take the
244 // y-index and check for odd/even and change the x-index in case
245 // it's different from the first tube in the current sampling ...
246 //
247 // S.M. update: in case we are in a hole of the integer grid the
248 // relative x and y w.r.t to the original tube are used to assign a
249 // tube according to the hexagonal pattern.
250
251 tubemap_const_iterator it = m_tubeMap[isam-1].begin();
252 unsigned int firstId = it->first;
253
254 // take offset from actual map
255 int ix = ktx+((int)((firstId&0xffff)-it->second.x()/m_tubeDx[isam-1]))+1;
256 int iy = kty+((int)((firstId>>16)-it->second.y()/m_tubeDy[isam-1]))+1;
257
258 int isOddEven = (((firstId>>16)%2)+(firstId%2))%2;
259 bool movex = false;
260
261 if ( (iy%2) != ((ix+isOddEven)%2) ) {
262 double yc = y/m_tubeDy[isam-1] - kty - 0.5;
263 if ( fabs(yc) > 0.5/sqrt(3) ) {
264 double xk = x/m_tubeDx[isam-1] - ktx;
265 if ( xk > 0.5 ) {
266 xk = 1 - xk;
267 }
268 double yn = 0.5-xk/3;
269 if ( fabs(yc) > fabs(yn) ) {
270 if ( yc > 0 )
271 iy++;
272 else
273 iy--;
274 }
275 else
276 movex = true;
277 }
278 else
279 movex = true;
280 if ( movex ) {
281 if ( x/m_tubeDx[isam-1] - ktx > 0.5 )
282 ix++;
283 else
284 ix--;
285 }
286 }
287
288 tubeID_t tubeID = (iy << 16) + ix;
289
290 it = m_tubeMap[isam-1].find(tubeID);
291 if (it != m_tubeMap[isam-1].end()){
292 tileName_t tilename = (it->second).get_tileName();
293 phi = tilename & 0xffff;
294 eta = tilename >> 16;
295 return true ;
296 }
297 // reach here only if it failed the second time.
298
299 return false;
300
301}
302
303
304
305/* ----------------------------------------------------------------------
306 To decode the tile x position from the tile identifier
307 ---------------------------------------------------------------------- */
308float
309FCAL_ChannelMap::x(int isam, int eta, int phi) const
310{
311 if(m_invert_xy){
312 // temp turn off the flag
313 m_invert_xy=false;
314 float y1 = y(isam,eta,phi);
315 m_invert_xy=true;
316 return y1;
317 }
318 float x;
319
320 tileName_t tilename = (eta << 16) + phi ;
321
322 tileMap_const_iterator it = m_tileMap[isam-1].find(tilename);
323 if(it != m_tileMap[isam-1].end())
324 {
325 x = (it->second).x();
326 } else
327 { // can't find the tile, throw exception.
328 char l_str[200] ;
329 snprintf(l_str, sizeof(l_str),
330 "Error in FCAL_ChannelMap::x, wrong tile,phi= %d ,eta=: %d ",phi,eta);
331 std::string errorMessage(l_str);
332 throw std::range_error(errorMessage.c_str());
333 }
334
335 if(m_invert_x) {
336 return -x;
337 }
338 else {
339 return x;
340 }
341
342 return x;
343
344}
345
346
347/* ----------------------------------------------------------------------
348 To decode the tile y position from the tile identifier
349 ---------------------------------------------------------------------- */
350float
351FCAL_ChannelMap::y(int isam, int eta, int phi) const
352{
353 if(m_invert_xy){
354
355 // temp turn off the flag
356 m_invert_xy=false;
357 float x1 = x(isam,eta,phi);
358 m_invert_xy=true;
359 return x1;
360
361 }
362
363 float y;
364
365 tileName_t tilename = (eta << 16) + phi ;
366
367 tileMap_const_iterator it = m_tileMap[isam-1].find(tilename);
368 if(it != m_tileMap[isam-1].end())
369 {
370 y = (it->second).y();
371 } else
372 { // can't find the tile, throw exception.
373 char l_str[200] ;
374 snprintf(l_str, sizeof(l_str),
375 "Error in FCAL_ChannelMap::x, wrong tile,phi= %d ,eta=: %d",phi,eta);
376 std::string errorMessage(l_str);
377 throw std::range_error(errorMessage.c_str());
378 }
379
380 return y;
381}
382
383/* ----------------------------------------------------------------------
384 To decode the tile dx size from the tile identifier
385 ---------------------------------------------------------------------- */
386
387void FCAL_ChannelMap::tileSize(int sam, int ntubes, float &dx, float &dy) const {
388
389 dx = m_tubeDx[sam-1];
390 dy = m_tubeDy[sam-1];
391 // float ntubes = (it->second).ntubes();
392 if(sam == 1 || sam == 3) {
393 float scale =sqrt(ntubes);
394 dx = dx * scale;
395 dy = dy * scale;
396 }
397 else {
398 float scale = sqrt(ntubes/1.5);
399 dx = dx * scale;
400 dy = dy * scale * 1.5 ;
401 }
402
403
404 // There is a fundamental discrepancy between dx and dy. A cell will
405 // contain twice as many distinct x-positions as y-positions. Diagram:
406
407 // . . . . -
408 //. . . . -
409 // . . . . - 4 x dy
410 // . . . . -
411 // ||||||||
412 // 8 x dx
413
414 dx = 2*dx;
415
416 if(m_invert_xy){
417 // switch xy
418 float temp = dx;
419 dx = dy;
420 dy = temp;
421 }
422
423}
424
425void FCAL_ChannelMap::tileSize(int sam, int eta, int phi,
426 float& dx, float& dy ) const
427{
428
429 tileName_t tilename = (eta << 16) + phi ;
430
431 tileMap_const_iterator it = m_tileMap[sam-1].find(tilename);
432 if(it != m_tileMap[sam-1].end()) {
433 int ntubes = (it->second).ntubes();
434 tileSize(sam,ntubes,dx,dy);
435 return ;
436 }
437 else {
438 // can't find the tile, throw exception.
439 char l_str[200] ;
440 snprintf(l_str, sizeof(l_str),
441 "Error in FCAL_ChannelMap::tilesize, wrong tile,phi= %d ,eta=: %d ",phi,eta);
442 std::string errorMessage(l_str);
443 throw std::range_error(errorMessage.c_str());
444 }
445}
446
447
448// ********************** print_tubemap *************************************
449void
450FCAL_ChannelMap::print_tubemap( int imap) const
451{
453
454 std::cout << "First 10 elements of the New FCAL tube map : " << imap << std::endl;
455 std::cout.precision(5);
456 for ( int i=0; i<10; ++i, ++it)
457 std::cout << std::hex << it->first << "\t"
458 << (it->second).get_tileName() << std::dec <<"\t"
459 << (it->second).x() <<"\t"
460 << (it->second).y() << std::endl;
461
462}
463
464
465// ********************** tubemap_begin **************************************
467FCAL_ChannelMap::tubemap_begin (int imap ) const
468{
469 return m_tubeMap[imap-1].begin();
470}
471
472
473// ********************** tubemap_end ****************************************
475FCAL_ChannelMap::tubemap_end (int imap ) const
476{
477 return m_tubeMap[imap-1].end();
478}
479
480// ********************** tubemap_size ***************************************
482FCAL_ChannelMap::tubemap_size (int imap) const
483{
484 return m_tubeMap[imap-1].size();
485}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define y
#define x
bool getTileID(int isam, float x, float y, int &eta, int &phi) const
-— For the new LArFCAL_ID Identifier
void add_tube(const std::string &tileName, int mod, int id, int i, int j, double xCm, double yCm)
static const double m_tubeSpacing[]
Geometrical parameters here, in CLHEP::cm please to be compatible with G3.
tubemap_const_iterator getTubeByCopyNumber(int isam, int copyNo) const
tubemap_const_iterator tubemap_begin(int isam) const
tubeMap access functions
float x(int isam, int eta, int phi) const
For reconstruction, decoding of tile identifiers.
void tileSize(int sam, int eta, int phi, float &dx, float &dy) const
bool first
Definition DeMoScan.py:534
bool flag
Definition master.py:29