test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCDQM_Detector.cc
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: Detector.cc
5  *
6  * Description: Class Detector implementation
7  *
8  * Version: 1.0
9  * Created: 05/19/2008 10:59:34 AM
10  * Revision: none
11  * Compiler: gcc
12  *
13  * Author: Valdas Rapsevicius (VR), Valdas.Rapsevicius@cern.ch
14  * Company: CERN, CH
15  *
16  * =====================================================================================
17  */
18 
19 #ifdef CSC_RENDER_PLUGIN
20 #include "CSCDQM_Detector.h"
21 #else
22 #include "CSCDQM_Detector.h"
23 #endif
24 
25 namespace cscdqm {
26 
33  Detector::Detector(const unsigned int p_partitions_x, const unsigned int p_partitions_y) {
34 
35  partitions_x = p_partitions_x;
36  partitions_y = p_partitions_y;
37 
38  unsigned int i = 0;
39  Address adr;
40 
41  adr.mask.layer = false;
42  adr.mask.side = adr.mask.station = adr.mask.ring = adr.mask.chamber = adr.mask.cfeb = adr.mask.hv = true;
43 
45  for (adr.side = 1; adr.side <= N_SIDES; adr.side++) {
46  float sign = +1.0;
47  if(adr.side == 2) sign = -1.0;
48  for (adr.station = 1; adr.station <= N_STATIONS; adr.station++) {
49  for (adr.ring = 1; adr.ring <= NumberOfRings(adr.station); adr.ring++) {
50  for (adr.chamber = 1; adr.chamber <= NumberOfChambers(adr.station, adr.ring); adr.chamber++) {
51  for (adr.cfeb = 1; adr.cfeb <= NumberOfChamberCFEBs(adr.station, adr.ring); adr.cfeb++) {
52  for (adr.hv = 1; adr.hv <= NumberOfChamberHVs(adr.station, adr.ring); adr.hv++) {
53 
54  float z = Z(adr.station, adr.ring);
55  float r_min = RMinHV(adr.station, adr.ring, adr.hv);
56  float r_max = RMaxHV(adr.station, adr.ring, adr.hv);
57  float eta_min = sign * Eta(r_min, z);
58  float eta_max = sign * Eta(r_max, z);
59  float x_min = EtaToX(eta_min);
60  float x_max = EtaToX(eta_max);
61  float phi_min = 0;
62  float phi_max = 0;
63 
64  if(adr.station == 1 && adr.ring == 1 && adr.hv == 1) {
65  phi_min = PhiMinCFEB(adr.station, adr.ring, adr.chamber, 1);
66  phi_max = PhiMaxCFEB(adr.station, adr.ring, adr.chamber, NumberOfChamberCFEBs(adr.station, adr.ring));
67  } else {
68  phi_min = PhiMinCFEB(adr.station, adr.ring, adr.chamber, adr.cfeb);
69  phi_max = PhiMaxCFEB(adr.station, adr.ring, adr.chamber, adr.cfeb);
70  }
71 
72  float y_min = PhiToY(phi_min);
73  float y_max = PhiToY(phi_max);
74 
75  boxes[i].adr = adr;
76 
77  float xboxmin = (x_min < x_max ? x_min : x_max);
78  float xboxmax = (x_max > x_min ? x_max : x_min);
79  float yboxmin = (y_min < y_max ? y_min : y_max);
80  float yboxmax = (y_max > y_min ? y_max : y_min);
81 
82  boxes[i].xmin = xboxmin;
83  boxes[i].xmax = xboxmax;
84  boxes[i].ymin = yboxmin;
85  boxes[i].ymax = yboxmax;
86 
90  unsigned int x1 = int(floor(xboxmin / PARTITION_STEP_X)) + int(partitions_x / 2);
91  unsigned int x2 = int( ceil(xboxmax / PARTITION_STEP_X)) + int(partitions_x / 2);
92  unsigned int y1 = int(floor(yboxmin / PARTITION_STEP_Y));
93  unsigned int y2 = int( ceil(yboxmax / PARTITION_STEP_Y));
94 
95  for (unsigned int x = x1; x < x2; x++) {
96  for (unsigned int y = y1; y < y2; y++) {
97 
98  unsigned int index = PARTITION_INDEX(x, y);
99  PartitionMapIterator iter = partitions.find(index);
100  if (iter == partitions.end()) {
101  std::vector<unsigned int> v;
102  partitions.insert(std::make_pair(index, v));
103  }
104  partitions[index].push_back(i);
105 
106  }
107  }
108 
109  i++;
110 
111  }
112  }
113  }
114  }
115  }
116 
117  }
118 
120  adr.mask.side = adr.mask.ring = adr.mask.chamber = adr.mask.layer = adr.mask.cfeb = adr.mask.hv = false;
121  adr.mask.station = true;
122  adr.station = 1;
123  station_area[0] = Area(adr);
124  adr.station = 2;
125  station_area[1] = Area(adr);
126  adr.station = 3;
127  station_area[2] = Area(adr);
128  adr.station = 4;
129  station_area[3] = Area(adr);
130 
131  }
132 
138  const float Detector::Area(const unsigned int station) const {
139  if (station > 0 && station <= N_STATIONS) {
140  return station_area[station - 1];
141  }
142  return 0;
143  }
144 
153  unsigned int Detector::GlobalChamberIndex(unsigned int side, unsigned int station, unsigned int ring, unsigned int chamber) const {
154  Address adr, iadr;
155  adr.mask.side = adr.mask.station = adr.mask.ring = adr.mask.chamber = true;
156  adr.mask.layer = adr.mask.cfeb = adr.mask.hv = false;
157  adr.side = side;
158  adr.station = station;
159  adr.ring = ring;
160  adr.chamber = chamber;
161  iadr = adr;
162 
163  unsigned int i = 1;
164  for (iadr.side = 1; iadr.side <= N_SIDES; iadr.side++) {
165  for (iadr.station = 1; iadr.station <= N_STATIONS; iadr.station++) {
166  for (iadr.ring = 1; iadr.ring <= NumberOfRings(iadr.station); iadr.ring++) {
167  for (iadr.chamber = 1; iadr.chamber <= NumberOfChambers(iadr.station, iadr.ring); iadr.chamber++) {
168  if (iadr == adr) {
169  return i;
170  }
171  i += 1;
172  }
173  }
174  }
175  }
176  return 0;
177  }
178 
184  const float Detector::Area(const Address& adr) const {
185  float a = 0;
186  for(unsigned int i = 0; i < N_ELEMENTS; i++ ) {
187  if (boxes[i].adr == adr) {
188  a += fabs((boxes[i].xmax - boxes[i].xmin) * (boxes[i].ymax - boxes[i].ymin));
189  }
190  }
191  return a;
192  }
193 
199  const unsigned int Detector::NumberOfRings(const unsigned int station) const {
200  if (station == 1) return 3;
201  if (station == 2) return 2;
202  if (station == 3) return 2;
203  if (station == 4) return 2;
204  return 0;
205  }
206 
213  const unsigned int Detector::NumberOfChambers(const unsigned int station, const unsigned int ring) const {
214  if(station == 1 && ring == 1) return 36;
215  if(station == 1 && ring == 2) return 36;
216  if(station == 1 && ring == 3) return 36;
217  if(station == 2 && ring == 1) return 18;
218  if(station == 2 && ring == 2) return 36;
219  if(station == 3 && ring == 1) return 18;
220  if(station == 3 && ring == 2) return 36;
221  if(station == 4 && ring == 1) return 18;
222  if(station == 4 && ring == 2) return 36;
223  return 0;
224  }
225 
232  const unsigned int Detector::NumberOfChamberCFEBs(const unsigned int station, const unsigned int ring) const {
233  if(station == 1 && ring == 1) return 4;
234  if(station == 1 && ring == 2) return 5;
235  if(station == 1 && ring == 3) return 4;
236  if(station == 2 && ring == 1) return 5;
237  if(station == 2 && ring == 2) return 5;
238  if(station == 3 && ring == 1) return 5;
239  if(station == 3 && ring == 2) return 5;
240  if(station == 4 && ring == 1) return 5;
241  if(station == 4 && ring == 2) return 5;
242  return 0;
243  }
244 
251  const unsigned int Detector::NumberOfChamberHVs(const unsigned int station, const unsigned int ring) const {
252  if(station == 1 && ring == 1) return 2;
253  if(station == 1 && ring == 2) return 3;
254  if(station == 1 && ring == 3) return 3;
255  if(station == 2 && ring == 1) return 3;
256  if(station == 2 && ring == 2) return 5;
257  if(station == 3 && ring == 1) return 3;
258  if(station == 3 && ring == 2) return 5;
259  if(station == 4 && ring == 1) return 3;
260  if(station == 4 && ring == 2) return 5;
261  return 0;
262  }
263 
269  void Detector::PrintAddress(const Address& adr) const {
270 
271  std::cout << "Side (" << std::boolalpha << adr.mask.side << ")";
272  if (adr.mask.side) std::cout << " = " << adr.side;
273 
274  std::cout << ", Station (" << std::boolalpha << adr.mask.station << ")";
275  if (adr.mask.station) std::cout << " = " << adr.station;
276 
277  std::cout << ", Ring (" << std::boolalpha << adr.mask.ring << ")";
278  if (adr.mask.ring) std::cout << " = " << adr.ring;
279 
280  std::cout << ", Chamber (" << std::boolalpha << adr.mask.chamber << ")";
281  if (adr.mask.chamber) std::cout << " = " << adr.chamber;
282 
283  std::cout << ", Layer (" << std::boolalpha << adr.mask.layer << ")";
284  if (adr.mask.layer) std::cout << " = " << adr.layer;
285 
286  std::cout << ", CFEB (" << std::boolalpha << adr.mask.cfeb << ")";
287  if (adr.mask.cfeb) std::cout << " = " << adr.cfeb;
288 
289  std::cout << ", HV (" << std::boolalpha << adr.mask.hv << ")";
290  if (adr.mask.hv) std::cout << " = " << adr.hv;
291 
292  std::cout << std::endl;
293  }
294 
302  const bool Detector::NextAddress(unsigned int& i, const Address*& adr, const Address& mask) const {
303  for(; i < N_ELEMENTS; i++ ) {
304  if (boxes[i].adr == mask) {
305  adr = &boxes[i].adr;
306  i++;
307  return true;
308  }
309  }
310  return false;
311  }
312 
320  const bool Detector::NextAddressBox(unsigned int& i, const AddressBox*& box, const Address& mask) const {
321 
322  for(; i < N_ELEMENTS; i++ ) {
323  if (boxes[i].adr == mask) {
324  box = &boxes[i];
325  i++;
326  return true;
327  }
328  }
329  return false;
330  }
331 
340  const bool Detector::NextAddressBoxByPartition (unsigned int& i, const unsigned int px, const unsigned int py, AddressBox*& box) {
341 
342  unsigned int index = PARTITION_INDEX(px, py);
343 
344  PartitionMapIterator iter = partitions.find(index);
345  if (iter != partitions.end()) {
346  if (i < partitions[index].size()) {
347  box = &boxes[partitions[index].at(i)];
348  i++;
349  return true;
350  }
351  }
352  return false;
353 
354  }
355 
356  const float Detector::Eta(const float r, const float z) const {
357  if(r > 0.0 || z > 0.0) {
358  float sin_theta = r / sqrt(r * r + z * z);
359  float cos_theta = z / sqrt(r * r + z * z);
360  return - log(sin_theta / (cos_theta + 1));
361  }
362  if(r == 0.0) return FLT_MAX;
363  return 0.0;
364  }
365 
366 
372  const float Detector::EtaToX(const float eta) const {
373  float x_min = -2.5;
374  float x_max = 2.5;
375  float eta_min = -2.5;
376  float eta_max = 2.5;
377  float a = (x_max - x_min) / (eta_max - eta_min);
378  float b = (eta_max * x_min - eta_min * x_max) / (eta_max - eta_min);
379  return a * eta + b;
380  }
381 
387  const float Detector::PhiToY(const float phi) const {
388  float y_min = 0.0;
389  float y_max = 2.0 * 3.14159;
390  float phi_min = 0.0;
391  float phi_max = 2.0 * 3.14159;
392  float a = (y_max - y_min) / (phi_max - phi_min);
393  float b = (phi_max * y_min - phi_min * y_max) / (phi_max - phi_min);
394  return a * phi + b;
395  }
396 
403  const float Detector::Z(const int station, const int ring) const {
404  float z_csc = 0;
405 
406  if(station == 1 && ring == 1) z_csc = (5834.5 + 6101.5) / 2.0;
407  if(station == 1 && ring == 2) z_csc = (6790.0 + 7064.3) / 2.0;
408  if(station == 1 && ring == 3) z_csc = 6888.0;
409  if(station == 2) z_csc = (8098.0 + 8346.0) / 2.0;
410  if(station == 3) z_csc = (9414.8 + 9166.8) / 2.0;
411  if(station == 4) z_csc = 10630.0; // has to be corrected
412 
413  return z_csc;
414  }
415 
423  const float Detector::RMinHV(const int station, const int ring, const int n_hv) const {
424  float r_min_hv = 0;
425 
426  if(station == 1 && ring == 1) {
427  if(n_hv == 1) r_min_hv = 1060.0;
428  if(n_hv == 2) r_min_hv = 1500.0;
429  }
430 
431  if(station == 1 && ring == 2) {
432  if(n_hv == 1) r_min_hv = 2815.0;
433  if(n_hv == 2) r_min_hv = 3368.2;
434  if(n_hv == 3) r_min_hv = 4025.7;
435  }
436 
437  if(station == 1 && ring == 3) {
438  if(n_hv == 1) r_min_hv = 5120.0;
439  if(n_hv == 2) r_min_hv = 5724.1;
440  if(n_hv == 3) r_min_hv = 6230.2;
441  }
442 
443  if(station == 2 && ring == 1) {
444  if(n_hv == 1) r_min_hv = 1469.2;
445  if(n_hv == 2) r_min_hv = 2152.3;
446  if(n_hv == 3) r_min_hv = 2763.7;
447  }
448 
449  if(station == 3 && ring == 1) {
450  if(n_hv == 1) r_min_hv = 1668.9;
451  if(n_hv == 2) r_min_hv = 2164.9;
452  if(n_hv == 3) r_min_hv = 2763.8;
453  }
454 
455  if(station == 4 && ring == 1) {
456  if(n_hv == 1) r_min_hv = 1876.1;
457  if(n_hv == 2) r_min_hv = 2365.9;
458  if(n_hv == 3) r_min_hv = 2865.0;
459  }
460 
461  if((station == 2 || station == 3 || station == 4) && ring == 2) {
462  if(n_hv == 1) r_min_hv = 3640.2;
463  if(n_hv == 2) r_min_hv = 4446.3;
464  if(n_hv == 3) r_min_hv = 5053.2;
465  if(n_hv == 4) r_min_hv = 5660.1;
466  if(n_hv == 5) r_min_hv = 6267.0;
467  }
468 
469  return r_min_hv;
470  }
471 
479  const float Detector::RMaxHV(const int station, const int ring, const int n_hv) const {
480  float r_max_hv = 0;
481 
482  if(station == 1 && ring == 1) {
483  if(n_hv == 1) r_max_hv = 1500.0;
484  if(n_hv == 2) r_max_hv = 2565.0;
485  }
486 
487  if(station == 1 && ring == 2) {
488  if(n_hv == 1) r_max_hv = 3368.2;
489  if(n_hv == 2) r_max_hv = 4025.7;
490  if(n_hv == 3) r_max_hv = 4559.9;
491  }
492 
493  if(station == 1 && ring == 3) {
494  if(n_hv == 1) r_max_hv = 5724.1;
495  if(n_hv == 2) r_max_hv = 6230.2;
496  if(n_hv == 3) r_max_hv = 6761.5;
497  }
498 
499  if(station == 2 && ring == 1) {
500  if(n_hv == 1) r_max_hv = 2152.3;
501  if(n_hv == 2) r_max_hv = 2763.7;
502  if(n_hv == 3) r_max_hv = 3365.8;
503  }
504 
505  if(station == 3 && ring == 1) {
506  if(n_hv == 1) r_max_hv = 2164.9;
507  if(n_hv == 2) r_max_hv = 2763.8;
508  if(n_hv == 3) r_max_hv = 3365.8;
509  }
510 
511  if(station == 4 && ring == 1) {
512  if(n_hv == 1) r_max_hv = 2365.9;
513  if(n_hv == 2) r_max_hv = 2865.0;
514  if(n_hv == 3) r_max_hv = 3356.3;
515  }
516 
517  if((station == 2 || station == 3 || station == 4) && ring == 2) {
518  if(n_hv == 1) r_max_hv = 4446.3;
519  if(n_hv == 2) r_max_hv = 5053.2;
520  if(n_hv == 3) r_max_hv = 5660.1;
521  if(n_hv == 4) r_max_hv = 6267.0;
522  if(n_hv == 5) r_max_hv = 6870.8;
523  }
524 
525  return r_max_hv;
526  }
527 
536  const float Detector::PhiMinCFEB(const int station, const int ring, const int chamber, const int cfeb) const {
537  float phi_min_cfeb;
538 
539  int n_cfeb = NumberOfChamberCFEBs(station, ring);
540  int n_chambers = NumberOfChambers(station, ring);
541 
542  phi_min_cfeb = 0.0 + 2.0 * 3.14159 / ((float) (n_chambers)) * ((float) (chamber - 1) + (float) (cfeb - 1) / (float) (n_cfeb));
543 
544  return phi_min_cfeb;
545  }
546 
555  const float Detector::PhiMaxCFEB(const int station, const int ring, const int chamber, const int cfeb) const {
556  float phi_max_cfeb;
557 
558  int n_cfeb = NumberOfChamberCFEBs(station, ring);
559  int n_chambers = NumberOfChambers(station, ring);
560 
561  phi_max_cfeb = 0.0 + 2.0 * 3.14159 / (float) n_chambers * ((float) (chamber - 1) + (float) (cfeb) / (float) n_cfeb);
562 
563  return phi_max_cfeb;
564  }
565 
572  const bool Detector::AddressFromString(const std::string& str_address, Address& adr) const {
573 
574  std::vector<std::string> tokens;
575  Utility::splitString(str_address, ",", tokens);
576 
577  if (tokens.size() != ADDR_SIZE) return false;
578 
579  for (unsigned int r = 0; r < ADDR_SIZE; r++) {
580 
581  std::string token = tokens.at(r);
582  Utility::trimString(token);
583  bool mask = false;
584  unsigned int num = 0;
585 
586  if (token.compare("*") != 0) {
587  if(stringToNumber<unsigned int>(num, token, std::dec)) {
588  mask = true;
589  } else {
590  return false;
591  }
592  }
593 
594  switch (r) {
595  case 0:
596  adr.mask.side = mask;
597  adr.side = num;
598  break;
599  case 1:
600  adr.mask.station = mask;
601  adr.station = num;
602  break;
603  case 2:
604  adr.mask.ring = mask;
605  adr.ring = num;
606  break;
607  case 3:
608  adr.mask.chamber = mask;
609  adr.chamber = num;
610  break;
611  case 4:
612  adr.mask.layer = mask;
613  adr.layer = num;
614  break;
615  case 5:
616  adr.mask.cfeb = mask;
617  adr.cfeb = num;
618  break;
619  case 6:
620  adr.mask.hv = mask;
621  adr.hv = num;
622  }
623 
624  }
625 
626  return true;
627 
628  }
629 
630 }
PartitionMap partitions
static void splitString(const std::string &str, const std::string &delim, std::vector< std::string > &results)
Split string according to delimiter.
int i
Definition: DBlmapReader.cc:9
const bool AddressFromString(const std::string &str_address, Address &adr) const
Construct address from string.
unsigned int partitions_y
unsigned int layer
PartitionMap::iterator PartitionMapIterator
const float Area(const unsigned int station) const
Calculate station area in eta/phi space.
const bool NextAddressBox(unsigned int &i, const AddressBox *&box, const Address &mask) const
Address box iterator by mask.
const float Z(const int station, const int ring) const
Get Z parameter (used in address eta/phi calculation)
unsigned int partitions_x
void PrintAddress(const Address &adr) const
Prints address for debugging.
double sign(double x)
const float RMinHV(const int station, const int ring, const int n_hv) const
Get R min parameter (used in address eta/phi calculation)
Area covered by Address in eta/phy space.
const unsigned int NumberOfRings(const unsigned int station) const
Returns the number of rings for the given station.
Detector(const unsigned int p_partitions_x=0, const unsigned int p_partitions_y=0)
Constructor.
const float EtaToX(const float eta) const
Transform eta coordinate to local canvas coordinate.
const bool NextAddressBoxByPartition(unsigned int &i, const unsigned int px, const unsigned int py, AddressBox *&box)
Address box iterator by partition.
#define PARTITION_INDEX(x, y)
const unsigned int NumberOfChamberCFEBs(const unsigned int station, const unsigned int ring) const
Returns the number of CFEBs per Chamber on given Station/Ring.
#define PARTITION_STEP_Y
const bool NextAddress(unsigned int &i, const Address *&adr, const Address &mask) const
Address iterator by mask.
static void trimString(std::string &str)
Trim string.
const unsigned int NumberOfChamberHVs(const unsigned int station, const unsigned int ring) const
Returns the number of HVs per Chamber on given Station/Ring.
T x() const
Cartesian x coordinate.
unsigned int cfeb
T sqrt(T t)
Definition: SSEVec.h:18
unsigned int chamber
#define N_ELEMENTS
unsigned int hv
const float PhiMinCFEB(const int station, const int ring, const int chamber, const int cfeb) const
Get Min phi boundary for particular CFEB.
unsigned int station
#define N_STATIONS
#define PARTITION_STEP_X
#define N_SIDES
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
const float Eta(const float r, const float z) const
AddressMask mask
const float PhiToY(const float phi) const
Transform phi coordinate to local canvas coordinate.
#define ADDR_SIZE
tuple cout
Definition: gather_cfg.py:145
unsigned int GlobalChamberIndex(unsigned int side, unsigned int station, unsigned int ring, unsigned int chamber) const
Return global chamber index on his geometric location.
AddressBox boxes[9540]
unsigned int side
const unsigned int NumberOfChambers(const unsigned int station, const unsigned int ring) const
Returns the number of chambers for the given station and ring.
Structure to store detector addresses of any granularity: from whole detector to the single HV elemen...
tuple size
Write out results.
unsigned int ring
const float PhiMaxCFEB(const int station, const int ring, const int chamber, const int cfeb) const
Get Max phi boundary for particular CFEB.
const float RMaxHV(const int station, const int ring, const int n_hv) const
Get R max parameter (used in address eta/phi calculation)