CMS 3D CMS Logo

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  partitions_x = p_partitions_x;
35  partitions_y = p_partitions_y;
36 
37  unsigned int i = 0;
38  Address adr;
39 
40  adr.mask.layer = false;
41  adr.mask.side = adr.mask.station = adr.mask.ring = adr.mask.chamber = adr.mask.cfeb = adr.mask.hv = true;
42 
44  for (adr.side = 1; adr.side <= N_SIDES; adr.side++) {
45  float sign = +1.0;
46  if (adr.side == 2)
47  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  float z = Z(adr.station, adr.ring);
54  float r_min = RMinHV(adr.station, adr.ring, adr.hv);
55  float r_max = RMaxHV(adr.station, adr.ring, adr.hv);
56  float eta_min = sign * Eta(r_min, z);
57  float eta_max = sign * Eta(r_max, z);
58  float x_min = EtaToX(eta_min);
59  float x_max = EtaToX(eta_max);
60  float phi_min = 0;
61  float phi_max = 0;
62 
63  if (adr.station == 1 && adr.ring == 1 && adr.hv == 1) {
64  phi_min = PhiMinCFEB(adr.station, adr.ring, adr.chamber, 1);
65  phi_max = PhiMaxCFEB(adr.station, adr.ring, adr.chamber, NumberOfChamberCFEBs(adr.station, adr.ring));
66  } else {
67  phi_min = PhiMinCFEB(adr.station, adr.ring, adr.chamber, adr.cfeb);
68  phi_max = PhiMaxCFEB(adr.station, adr.ring, adr.chamber, adr.cfeb);
69  }
70 
71  float y_min = PhiToY(phi_min);
72  float y_max = PhiToY(phi_max);
73 
74  boxes[i].adr = adr;
75 
76  float xboxmin = (x_min < x_max ? x_min : x_max);
77  float xboxmax = (x_max > x_min ? x_max : x_min);
78  float yboxmin = (y_min < y_max ? y_min : y_max);
79  float yboxmax = (y_max > y_min ? y_max : y_min);
80 
81  boxes[i].xmin = xboxmin;
82  boxes[i].xmax = xboxmax;
83  boxes[i].ymin = yboxmin;
84  boxes[i].ymax = yboxmax;
85 
89  unsigned int x1 = int(floor(xboxmin / PARTITION_STEP_X)) + int(partitions_x / 2);
90  unsigned int x2 = int(ceil(xboxmax / PARTITION_STEP_X)) + int(partitions_x / 2);
91  unsigned int y1 = int(floor(yboxmin / PARTITION_STEP_Y));
92  unsigned int y2 = int(ceil(yboxmax / PARTITION_STEP_Y));
93 
94  for (unsigned int x = x1; x < x2; x++) {
95  for (unsigned int y = y1; y < y2; y++) {
96  unsigned int index = PARTITION_INDEX(x, y);
98  if (iter == partitions.end()) {
99  std::vector<unsigned int> v;
100  partitions.insert(std::make_pair(index, v));
101  }
102  partitions[index].push_back(i);
103  }
104  }
105 
106  i++;
107  }
108  }
109  }
110  }
111  }
112  }
113 
115  adr.mask.side = adr.mask.ring = adr.mask.chamber = adr.mask.layer = adr.mask.cfeb = adr.mask.hv = false;
116  adr.mask.station = true;
117  adr.station = 1;
118  station_area[0] = Area(adr);
119  adr.station = 2;
120  station_area[1] = Area(adr);
121  adr.station = 3;
122  station_area[2] = Area(adr);
123  adr.station = 4;
124  station_area[3] = Area(adr);
125  }
126 
132  const float Detector::Area(const unsigned int station) const {
133  if (station > 0 && station <= N_STATIONS) {
134  return station_area[station - 1];
135  }
136  return 0;
137  }
138 
147  unsigned int Detector::GlobalChamberIndex(unsigned int side,
148  unsigned int station,
149  unsigned int ring,
150  unsigned int chamber) const {
151  Address adr, iadr;
152  adr.mask.side = adr.mask.station = adr.mask.ring = adr.mask.chamber = true;
153  adr.mask.layer = adr.mask.cfeb = adr.mask.hv = false;
154  adr.layer = adr.cfeb = adr.hv = 0;
155  adr.side = side;
156  adr.station = station;
157  adr.ring = ring;
158  adr.chamber = chamber;
159  iadr = adr;
160 
161  unsigned int i = 1;
162  for (iadr.side = 1; iadr.side <= N_SIDES; iadr.side++) {
163  for (iadr.station = 1; iadr.station <= N_STATIONS; iadr.station++) {
164  for (iadr.ring = 1; iadr.ring <= NumberOfRings(iadr.station); iadr.ring++) {
165  for (iadr.chamber = 1; iadr.chamber <= NumberOfChambers(iadr.station, iadr.ring); iadr.chamber++) {
166  if (iadr == adr) {
167  return i;
168  }
169  i += 1;
170  }
171  }
172  }
173  }
174  return 0;
175  }
176 
182  const float Detector::Area(const Address& adr) const {
183  float a = 0;
184  for (unsigned int i = 0; i < N_ELEMENTS; i++) {
185  if (boxes[i].adr == adr) {
186  a += fabs((boxes[i].xmax - boxes[i].xmin) * (boxes[i].ymax - boxes[i].ymin));
187  }
188  }
189  return a;
190  }
191 
197  const unsigned int Detector::NumberOfRings(const unsigned int station) const {
198  if (station == 1)
199  return 3;
200  if (station == 2)
201  return 2;
202  if (station == 3)
203  return 2;
204  if (station == 4)
205  return 2;
206  return 0;
207  }
208 
215  const unsigned int Detector::NumberOfChambers(const unsigned int station, const unsigned int ring) const {
216  if (station == 1 && ring == 1)
217  return 36;
218  if (station == 1 && ring == 2)
219  return 36;
220  if (station == 1 && ring == 3)
221  return 36;
222  if (station == 2 && ring == 1)
223  return 18;
224  if (station == 2 && ring == 2)
225  return 36;
226  if (station == 3 && ring == 1)
227  return 18;
228  if (station == 3 && ring == 2)
229  return 36;
230  if (station == 4 && ring == 1)
231  return 18;
232  if (station == 4 && ring == 2)
233  return 36;
234  return 0;
235  }
236 
243  const unsigned int Detector::NumberOfChamberCFEBs(const unsigned int station, const unsigned int ring) const {
244  if (station == 1 && ring == 1)
245  return 4;
246  if (station == 1 && ring == 2)
247  return 5;
248  if (station == 1 && ring == 3)
249  return 4;
250  if (station == 2 && ring == 1)
251  return 5;
252  if (station == 2 && ring == 2)
253  return 5;
254  if (station == 3 && ring == 1)
255  return 5;
256  if (station == 3 && ring == 2)
257  return 5;
258  if (station == 4 && ring == 1)
259  return 5;
260  if (station == 4 && ring == 2)
261  return 5;
262  return 0;
263  }
264 
271  const unsigned int Detector::NumberOfChamberHVs(const unsigned int station, const unsigned int ring) const {
272  if (station == 1 && ring == 1)
273  return 2;
274  if (station == 1 && ring == 2)
275  return 3;
276  if (station == 1 && ring == 3)
277  return 3;
278  if (station == 2 && ring == 1)
279  return 3;
280  if (station == 2 && ring == 2)
281  return 5;
282  if (station == 3 && ring == 1)
283  return 3;
284  if (station == 3 && ring == 2)
285  return 5;
286  if (station == 4 && ring == 1)
287  return 3;
288  if (station == 4 && ring == 2)
289  return 5;
290  return 0;
291  }
292 
298  void Detector::PrintAddress(const Address& adr) const {
299  std::cout << "Side (" << std::boolalpha << adr.mask.side << ")";
300  if (adr.mask.side)
301  std::cout << " = " << adr.side;
302 
303  std::cout << ", Station (" << std::boolalpha << adr.mask.station << ")";
304  if (adr.mask.station)
305  std::cout << " = " << adr.station;
306 
307  std::cout << ", Ring (" << std::boolalpha << adr.mask.ring << ")";
308  if (adr.mask.ring)
309  std::cout << " = " << adr.ring;
310 
311  std::cout << ", Chamber (" << std::boolalpha << adr.mask.chamber << ")";
312  if (adr.mask.chamber)
313  std::cout << " = " << adr.chamber;
314 
315  std::cout << ", Layer (" << std::boolalpha << adr.mask.layer << ")";
316  if (adr.mask.layer)
317  std::cout << " = " << adr.layer;
318 
319  std::cout << ", CFEB (" << std::boolalpha << adr.mask.cfeb << ")";
320  if (adr.mask.cfeb)
321  std::cout << " = " << adr.cfeb;
322 
323  std::cout << ", HV (" << std::boolalpha << adr.mask.hv << ")";
324  if (adr.mask.hv)
325  std::cout << " = " << adr.hv;
326 
327  std::cout << std::endl;
328  }
329 
337  const bool Detector::NextAddress(unsigned int& i, const Address*& adr, const Address& mask) const {
338  for (; i < N_ELEMENTS; i++) {
339  if (boxes[i].adr == mask) {
340  adr = &boxes[i].adr;
341  i++;
342  return true;
343  }
344  }
345  return false;
346  }
347 
355  const bool Detector::NextAddressBox(unsigned int& i, const AddressBox*& box, const Address& mask) const {
356  for (; i < N_ELEMENTS; i++) {
357  if (boxes[i].adr == mask) {
358  box = &boxes[i];
359  i++;
360  return true;
361  }
362  }
363  return false;
364  }
365 
374  const bool Detector::NextAddressBoxByPartition(unsigned int& i,
375  const unsigned int px,
376  const unsigned int py,
377  AddressBox*& box) {
378  unsigned int index = PARTITION_INDEX(px, py);
379 
381  if (iter != partitions.end()) {
382  if (i < partitions[index].size()) {
383  box = &boxes[partitions[index].at(i)];
384  i++;
385  return true;
386  }
387  }
388  return false;
389  }
390 
391  const float Detector::Eta(const float r, const float z) const {
392  if (r > 0.0 || z > 0.0) {
393  float sin_theta = r / sqrt(r * r + z * z);
394  float cos_theta = z / sqrt(r * r + z * z);
395  return -log(sin_theta / (cos_theta + 1));
396  }
397  if (r == 0.0)
398  return FLT_MAX;
399  return 0.0;
400  }
401 
407  const float Detector::EtaToX(const float eta) const {
408  float x_min = -2.5;
409  float x_max = 2.5;
410  float eta_min = -2.5;
411  float eta_max = 2.5;
412  float a = (x_max - x_min) / (eta_max - eta_min);
413  float b = (eta_max * x_min - eta_min * x_max) / (eta_max - eta_min);
414  return a * eta + b;
415  }
416 
422  const float Detector::PhiToY(const float phi) const {
423  float y_min = 0.0;
424  float y_max = 2.0 * 3.14159;
425  float phi_min = 0.0;
426  float phi_max = 2.0 * 3.14159;
427  float a = (y_max - y_min) / (phi_max - phi_min);
428  float b = (phi_max * y_min - phi_min * y_max) / (phi_max - phi_min);
429  return a * phi + b;
430  }
431 
438  const float Detector::Z(const int station, const int ring) const {
439  float z_csc = 0;
440 
441  if (station == 1 && ring == 1)
442  z_csc = (5834.5 + 6101.5) / 2.0;
443  if (station == 1 && ring == 2)
444  z_csc = (6790.0 + 7064.3) / 2.0;
445  if (station == 1 && ring == 3)
446  z_csc = 6888.0;
447  if (station == 2)
448  z_csc = (8098.0 + 8346.0) / 2.0;
449  if (station == 3)
450  z_csc = (9414.8 + 9166.8) / 2.0;
451  if (station == 4)
452  z_csc = 10630.0; // has to be corrected
453 
454  return z_csc;
455  }
456 
464  const float Detector::RMinHV(const int station, const int ring, const int n_hv) const {
465  float r_min_hv = 0;
466 
467  if (station == 1 && ring == 1) {
468  if (n_hv == 1)
469  r_min_hv = 1060.0;
470  if (n_hv == 2)
471  r_min_hv = 1500.0;
472  }
473 
474  if (station == 1 && ring == 2) {
475  if (n_hv == 1)
476  r_min_hv = 2815.0;
477  if (n_hv == 2)
478  r_min_hv = 3368.2;
479  if (n_hv == 3)
480  r_min_hv = 4025.7;
481  }
482 
483  if (station == 1 && ring == 3) {
484  if (n_hv == 1)
485  r_min_hv = 5120.0;
486  if (n_hv == 2)
487  r_min_hv = 5724.1;
488  if (n_hv == 3)
489  r_min_hv = 6230.2;
490  }
491 
492  if (station == 2 && ring == 1) {
493  if (n_hv == 1)
494  r_min_hv = 1469.2;
495  if (n_hv == 2)
496  r_min_hv = 2152.3;
497  if (n_hv == 3)
498  r_min_hv = 2763.7;
499  }
500 
501  if (station == 3 && ring == 1) {
502  if (n_hv == 1)
503  r_min_hv = 1668.9;
504  if (n_hv == 2)
505  r_min_hv = 2164.9;
506  if (n_hv == 3)
507  r_min_hv = 2763.8;
508  }
509 
510  if (station == 4 && ring == 1) {
511  if (n_hv == 1)
512  r_min_hv = 1876.1;
513  if (n_hv == 2)
514  r_min_hv = 2365.9;
515  if (n_hv == 3)
516  r_min_hv = 2865.0;
517  }
518 
519  if ((station == 2 || station == 3 || station == 4) && ring == 2) {
520  if (n_hv == 1)
521  r_min_hv = 3640.2;
522  if (n_hv == 2)
523  r_min_hv = 4446.3;
524  if (n_hv == 3)
525  r_min_hv = 5053.2;
526  if (n_hv == 4)
527  r_min_hv = 5660.1;
528  if (n_hv == 5)
529  r_min_hv = 6267.0;
530  }
531 
532  return r_min_hv;
533  }
534 
542  const float Detector::RMaxHV(const int station, const int ring, const int n_hv) const {
543  float r_max_hv = 0;
544 
545  if (station == 1 && ring == 1) {
546  if (n_hv == 1)
547  r_max_hv = 1500.0;
548  if (n_hv == 2)
549  r_max_hv = 2565.0;
550  }
551 
552  if (station == 1 && ring == 2) {
553  if (n_hv == 1)
554  r_max_hv = 3368.2;
555  if (n_hv == 2)
556  r_max_hv = 4025.7;
557  if (n_hv == 3)
558  r_max_hv = 4559.9;
559  }
560 
561  if (station == 1 && ring == 3) {
562  if (n_hv == 1)
563  r_max_hv = 5724.1;
564  if (n_hv == 2)
565  r_max_hv = 6230.2;
566  if (n_hv == 3)
567  r_max_hv = 6761.5;
568  }
569 
570  if (station == 2 && ring == 1) {
571  if (n_hv == 1)
572  r_max_hv = 2152.3;
573  if (n_hv == 2)
574  r_max_hv = 2763.7;
575  if (n_hv == 3)
576  r_max_hv = 3365.8;
577  }
578 
579  if (station == 3 && ring == 1) {
580  if (n_hv == 1)
581  r_max_hv = 2164.9;
582  if (n_hv == 2)
583  r_max_hv = 2763.8;
584  if (n_hv == 3)
585  r_max_hv = 3365.8;
586  }
587 
588  if (station == 4 && ring == 1) {
589  if (n_hv == 1)
590  r_max_hv = 2365.9;
591  if (n_hv == 2)
592  r_max_hv = 2865.0;
593  if (n_hv == 3)
594  r_max_hv = 3356.3;
595  }
596 
597  if ((station == 2 || station == 3 || station == 4) && ring == 2) {
598  if (n_hv == 1)
599  r_max_hv = 4446.3;
600  if (n_hv == 2)
601  r_max_hv = 5053.2;
602  if (n_hv == 3)
603  r_max_hv = 5660.1;
604  if (n_hv == 4)
605  r_max_hv = 6267.0;
606  if (n_hv == 5)
607  r_max_hv = 6870.8;
608  }
609 
610  return r_max_hv;
611  }
612 
621  const float Detector::PhiMinCFEB(const int station, const int ring, const int chamber, const int cfeb) const {
622  float phi_min_cfeb;
623 
624  int n_cfeb = NumberOfChamberCFEBs(station, ring);
625  int n_chambers = NumberOfChambers(station, ring);
626 
627  phi_min_cfeb =
628  0.0 + 2.0 * 3.14159 / ((float)(n_chambers)) * ((float)(chamber - 1) + (float)(cfeb - 1) / (float)(n_cfeb));
629 
630  return phi_min_cfeb;
631  }
632 
641  const float Detector::PhiMaxCFEB(const int station, const int ring, const int chamber, const int cfeb) const {
642  float phi_max_cfeb;
643 
644  int n_cfeb = NumberOfChamberCFEBs(station, ring);
645  int n_chambers = NumberOfChambers(station, ring);
646 
647  phi_max_cfeb = 0.0 + 2.0 * 3.14159 / (float)n_chambers * ((float)(chamber - 1) + (float)(cfeb) / (float)n_cfeb);
648 
649  return phi_max_cfeb;
650  }
651 
658  const bool Detector::AddressFromString(const std::string& str_address, Address& adr) const {
659  std::vector<std::string> tokens;
660  Utility::splitString(str_address, ",", tokens);
661 
662  if (tokens.size() != ADDR_SIZE)
663  return false;
664 
665  for (unsigned int r = 0; r < ADDR_SIZE; r++) {
666  std::string token = tokens.at(r);
668  bool mask = false;
669  unsigned int num = 0;
670 
671  if (token != "*") {
672  if (stringToNumber<unsigned int>(num, token, std::dec)) {
673  mask = true;
674  } else {
675  return false;
676  }
677  }
678 
679  switch (r) {
680  case 0:
681  adr.mask.side = mask;
682  adr.side = num;
683  break;
684  case 1:
685  adr.mask.station = mask;
686  adr.station = num;
687  break;
688  case 2:
689  adr.mask.ring = mask;
690  adr.ring = num;
691  break;
692  case 3:
693  adr.mask.chamber = mask;
694  adr.chamber = num;
695  break;
696  case 4:
697  adr.mask.layer = mask;
698  adr.layer = num;
699  break;
700  case 5:
701  adr.mask.cfeb = mask;
702  adr.cfeb = num;
703  break;
704  case 6:
705  adr.mask.hv = mask;
706  adr.hv = num;
707  }
708  }
709 
710  return true;
711  }
712 
713 } // namespace cscdqm
const bool NextAddressBox(unsigned int &i, const AddressBox *&box, const Address &mask) const
Address box iterator by mask.
size
Write out results.
PartitionMap partitions
static void splitString(const std::string &str, const std::string &delim, std::vector< std::string > &results)
Split string according to delimiter.
constexpr int32_t ceil(float num)
unsigned int partitions_y
unsigned int layer
PartitionMap::iterator PartitionMapIterator
unsigned int GlobalChamberIndex(unsigned int side, unsigned int station, unsigned int ring, unsigned int chamber) const
Return global chamber index on his geometric location.
unsigned int partitions_x
const float EtaToX(const float eta) const
Transform eta coordinate to local canvas coordinate.
const float PhiMaxCFEB(const int station, const int ring, const int chamber, const int cfeb) const
Get Max phi boundary for particular CFEB.
Area covered by Address in eta/phy space.
Detector(const unsigned int p_partitions_x=0, const unsigned int p_partitions_y=0)
Constructor.
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)
constexpr uint32_t mask
Definition: gpuClustering.h:24
#define PARTITION_STEP_Y
static void trimString(std::string &str)
Trim string.
const float Area(const unsigned int station) const
Calculate station area in eta/phi space.
unsigned int cfeb
T sqrt(T t)
Definition: SSEVec.h:19
const float Z(const int station, const int ring) const
Get Z parameter (used in address eta/phi calculation)
const float PhiToY(const float phi) const
Transform phi coordinate to local canvas coordinate.
const unsigned int NumberOfChamberCFEBs(const unsigned int station, const unsigned int ring) const
Returns the number of CFEBs per Chamber on given Station/Ring.
unsigned int chamber
#define N_ELEMENTS
unsigned int hv
const unsigned int NumberOfRings(const unsigned int station) const
Returns the number of rings for the given station.
unsigned int station
#define N_STATIONS
const float RMaxHV(const int station, const int ring, const int n_hv) const
Get R max parameter (used in address eta/phi calculation)
const float RMinHV(const int station, const int ring, const int n_hv) const
Get R min parameter (used in address eta/phi calculation)
const bool AddressFromString(const std::string &str_address, Address &adr) const
Construct address from string.
#define PARTITION_STEP_X
const unsigned int NumberOfChambers(const unsigned int station, const unsigned int ring) const
Returns the number of chambers for the given station and ring.
#define N_SIDES
const float PhiMinCFEB(const int station, const int ring, const int chamber, const int cfeb) const
Get Min phi boundary for particular CFEB.
double b
Definition: hdecay.h:118
const bool NextAddress(unsigned int &i, const Address *&adr, const Address &mask) const
Address iterator by mask.
double a
Definition: hdecay.h:119
AddressMask mask
void PrintAddress(const Address &adr) const
Prints address for debugging.
#define ADDR_SIZE
float x
AddressBox boxes[9540]
unsigned int side
Structure to store detector addresses of any granularity: from whole detector to the single HV elemen...
const float Eta(const float r, const float z) const
unsigned int ring
const unsigned int NumberOfChamberHVs(const unsigned int station, const unsigned int ring) const
Returns the number of HVs per Chamber on given Station/Ring.