CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MESetBinningUtils2.cc
Go to the documentation of this file.
2 
4 
6 
7 #include <algorithm>
8 
9 #include "TMath.h"
10 
11 namespace ecaldqm
12 {
13  namespace binning
14  {
15  int
16  xlow_(int _iSM)
17  {
18  switch(_iSM){
19  case kEEm01: case kEEp01: return 20;
20  case kEEm02: case kEEp02: return 0;
21  case kEEm03: case kEEp03: return 0;
22  case kEEm04: case kEEp04: return 5;
23  case kEEm05: case kEEp05: return 35;
24  case kEEm06: case kEEp06: return 55;
25  case kEEm07: case kEEp07: return 60;
26  case kEEm08: case kEEp08: return 55;
27  case kEEm09: case kEEp09: return 50;
28  default: break;
29  }
30 
31  if(_iSM >= kEBmLow && _iSM <= kEBpHigh) return 0;
32 
33  return 0;
34  }
35 
36  int
37  ylow_(int _iSM)
38  {
39  switch(_iSM){
40  case kEEm01: case kEEp01: case kEEm09: case kEEp09: return 60;
41  case kEEm02: case kEEp02: case kEEm08: case kEEp08: return 50;
42  case kEEm03: case kEEp03: case kEEm07: case kEEp07: return 25;
43  case kEEm04: case kEEp04: case kEEm06: case kEEp06: return 5;
44  case kEEm05: case kEEp05: return 0;
45  default: break;
46  }
47 
48  if(_iSM >= kEBmLow && _iSM <= kEBmHigh) return ((_iSM - kEBmLow) % 18) * 20;
49  if(_iSM >= kEBpLow && _iSM <= kEBpHigh) return (-1 - ((_iSM - kEBpLow) % 18)) * 20;
50 
51  return 0;
52  }
53 
54  AxisSpecs
55  getBinningEB_(BinningType _btype, bool _isMap, int _axis)
56  {
57  AxisSpecs specs;
58 
59  if(!_isMap){
60  switch(_btype){
61  case kTCC:
62  specs.nbins = 36;
63  specs.low = 9.;
64  specs.high = 45.;
65  specs.title = "iTCC";
66  break;
67  case kDCC:
68  specs.nbins = 36;
69  specs.low = 9.;
70  specs.high = 45.;
71  break;
72  case kProjEta:
73  specs.nbins = nEBEtaBins;
74  specs.low = -etaBound;
75  specs.high = etaBound;
76  specs.title = "eta";
77  break;
78  case kProjPhi:
79  specs.nbins = nPhiBins;
80  specs.low = -TMath::Pi() / 18.;
81  specs.high = TMath::Pi() * 35./18.;
82  specs.title = "phi";
83  break;
84  default:
85  break;
86  }
87  }
88  else{
89  switch(_btype){
90  case kCrystal:
91  if(_axis == 1)
92  specs.nbins = 360;
93  else if(_axis == 2)
94  specs.nbins = 170;
95  break;
96  case kSuperCrystal:
97  case kTriggerTower:
98  if(_axis == 1)
99  specs.nbins = 72;
100  else if(_axis == 2)
101  specs.nbins = 34;
102  break;
103  default:
104  return specs;
105  }
106 
107  if(_axis == 1){
108  specs.low = 0.;
109  specs.high = 360.;
110  specs.title = "iphi";
111  }
112  else if(_axis == 2){
113  specs.low = -85.;
114  specs.high = 85.;
115  specs.title = "ieta";
116  }
117  }
118 
119  return specs;
120  }
121 
122  AxisSpecs
123  getBinningEE_(BinningType _btype, bool _isMap, int _zside, int _axis)
124  {
125  AxisSpecs specs;
126 
127  if(!_isMap){
128  switch(_btype){
129  case kTCC:
130  specs.nbins = _zside ? 36 : 72;
131  specs.low = 0.;
132  specs.high = _zside ? 36. : 72.;
133  specs.title = "iTCC";
134  break;
135  case kDCC:
136  specs.nbins = _zside ? 9 : 18;
137  specs.low = 0.;
138  specs.high = _zside ? 9. : 18.;
139  break;
140  case kProjEta:
141  if(_zside == 0){
142  specs.nbins = nEEEtaBins / (3. - etaBound) * 6.;
143  specs.low = -3.;
144  specs.high = 3.;
145  }
146  else{
147  specs.nbins = nEEEtaBins;
148  specs.low = _zside < 0 ? -3. : etaBound;
149  specs.high = _zside < 0 ? -etaBound : 3.;
150  }
151  specs.title = "eta";
152  break;
153  case kProjPhi:
154  specs.nbins = nPhiBins;
155  specs.low = -TMath::Pi() / 18.;
156  specs.high = TMath::Pi() * 35./18.;
157  specs.title = "phi";
158  break;
159  default:
160  break;
161  }
162  }else{
163  switch(_btype){
164  case kCrystal:
165  case kTriggerTower:
166  if(_axis == 1)
167  specs.nbins = _zside ? 100 : 200;
168  if(_axis == 2)
169  specs.nbins = 100;
170  break;
171  case kSuperCrystal:
172  if(_axis == 1)
173  specs.nbins = _zside ? 20 : 40;
174  if(_axis == 2)
175  specs.nbins = 20;
176  break;
177  default:
178  return specs;
179  }
180 
181  if(_axis == 1){
182  specs.low = 0.;
183  specs.high = _zside ? 100. : 200.;
184  specs.title = "ix";
185  }
186  else if(_axis == 2){
187  specs.low = 0.;
188  specs.high = 100.;
189  specs.title = "iy";
190  }
191  }
192 
193  return specs;
194  }
195 
196  AxisSpecs
197  getBinningSM_(BinningType _btype, bool _isMap, unsigned _iObj, int _axis)
198  {
199  AxisSpecs specs;
200 
201  unsigned iSM(_iObj);
202 
203  const bool isBarrel(iSM >= kEBmLow && iSM <= kEBpHigh);
204 
205  if(!_isMap){
206  switch(_btype){
207  case kCrystal:
208  specs.nbins = isBarrel ? 1700 : getElectronicsMap()->dccConstituents(iSM + 1).size();
209  specs.low = 0.;
210  specs.high = specs.nbins;
211  specs.title = "crystal";
212  break;
213  case kTriggerTower:
214  specs.nbins = isBarrel ? 68 : 80;
215  specs.low = 0.;
216  specs.high = specs.nbins;
217  specs.title = "tower";
218  break;
219  case kSuperCrystal:
220  specs.nbins = isBarrel ? 68 : nSuperCrystals(iSM + 1);
221  specs.low = 0.;
222  specs.high = specs.nbins;
223  specs.title = "tower";
224  break;
225  default:
226  break;
227  }
228  }else{
229  int nEEX(nEESMX);
230  int nEEY(nEESMY);
231  if(iSM == kEEm02 || iSM == kEEm08 || iSM == kEEp02 || iSM == kEEp08) nEEX = nEESMXExt;
232  if(iSM == kEEm01 || iSM == kEEm05 || iSM == kEEm09 || iSM == kEEp01 || iSM == kEEp05 || iSM == kEEp09) nEEX = nEESMXRed;
233  if(iSM == kEEm03 || iSM == kEEm07 || iSM == kEEp03 || iSM == kEEp07) nEEY = nEESMYRed;
234 
235  switch(_btype){
236  case kCrystal:
237  if(_axis == 1)
238  specs.nbins = isBarrel ? nEBSMEta : nEEX;
239  else if(_axis == 2)
240  specs.nbins = isBarrel ? nEBSMPhi : nEEY;
241  break;
242  case kTriggerTower:
243  if(_axis == 1)
244  specs.nbins = isBarrel ? nEBSMEta / 5 : nEEX;
245  else if(_axis == 2)
246  specs.nbins = isBarrel ? nEBSMPhi / 5 : nEEY;
247  break;
248  case kSuperCrystal:
249  if(_axis == 1)
250  specs.nbins = isBarrel ? nEBSMEta / 5 : nEEX / 5;
251  else if(_axis == 2)
252  specs.nbins = isBarrel ? nEBSMPhi / 5 : nEEY / 5;
253  break;
254  default:
255  return specs;
256  }
257 
258  if(_axis == 1){
259  specs.low = xlow_(iSM);
260  specs.high = specs.low + (isBarrel ? nEBSMEta : nEEX);
261  specs.title = isBarrel ? (iSM < kEBpLow ? "-ieta" : "ieta") : "ix";
262  }
263  else if(_axis == 2){
264  specs.low = ylow_(iSM);
265  specs.high = specs.low + (isBarrel ? nEBSMPhi : nEEY);
266  specs.title = isBarrel ? "iphi" : "iy";
267  }
268  }
269 
270  return specs;
271  }
272 
273  AxisSpecs
274  getBinningSMMEM_(BinningType _btype, bool _isMap, unsigned _iObj, int _axis)
275  {
276  AxisSpecs specs;
277 
278  unsigned iSM(memDCCId(_iObj) - 1);
279 
280  if(iSM == unsigned(-1) || _btype != kCrystal) return specs;
281 
282  if(_axis == 1){
283  specs.nbins = 10;
284  specs.low = 0.;
285  specs.high = 10.;
286  if(_isMap) specs.title = "pseudo-strip";
287  else specs.title = "iPN";
288  }
289  else if(_axis == 2){
290  specs.nbins = 1;
291  specs.low = 0.;
292  specs.high = 5.;
293  specs.title = "channel";
294  }
295 
296  return specs;
297  }
298 
299  AxisSpecs
300  getBinningEcal_(BinningType _btype, bool _isMap, int _axis)
301  {
302  AxisSpecs specs;
303 
304  if(!_isMap){
305  switch(_btype){
306  case kTCC:
307  specs.nbins = 108;
308  specs.low = 0.;
309  specs.high = 108.;
310  specs.title = "iTCC";
311  break;
312  case kDCC:
313  specs.nbins = 54;
314  specs.low = 0.;
315  specs.high = 54.;
316  specs.title = "iDCC";
317  break;
318  case kProjEta:
319  specs.nbins = nEBEtaBins + 2 * nEEEtaBins;
320  specs.edges = new double[specs.nbins + 1];
321  for(int i(0); i <= nEEEtaBins; i++)
322  specs.edges[i] = -3. + (3. - etaBound) / nEEEtaBins * i;
323  for(int i(1); i <= nEBEtaBins; i++)
324  specs.edges[i + nEEEtaBins] = -etaBound + 2. * etaBound / nEBEtaBins * i;
325  for(int i(1); i <= nEEEtaBins; i++)
326  specs.edges[i + nEEEtaBins + nEBEtaBins] = etaBound + (3. - etaBound) / nEEEtaBins * i;
327  specs.title = "eta";
328  break;
329  case kProjPhi:
330  specs.nbins = nPhiBins;
331  specs.low = -TMath::Pi() / 18.;
332  specs.high = TMath::Pi() * 35./18.;
333  specs.title = "phi";
334  break;
335  default:
336  break;
337  }
338  }
339  else{
340  switch(_btype){
341  case kDCC:
342  if(_axis == 1){
343  specs.nbins = 9;
344  specs.low = 0.;
345  specs.high = 9.;
346  }
347  else if(_axis == 2){
348  specs.nbins = 6;
349  specs.low = 0.;
350  specs.high = 6.;
351  }
352  break;
353  default:
354  break;
355  }
356  }
357 
358  return specs;
359  }
360 
361  AxisSpecs
362  getBinningMEM_(BinningType _btype, bool _isMap, int _subdet, int _axis)
363  {
364  AxisSpecs specs;
365 
366  if(_btype != kCrystal) return specs;
367 
368  int nbins(44);
369  if(_subdet == EcalBarrel) nbins = 36;
370  else if(_subdet == EcalEndcap) nbins = 8;
371 
372  if(_axis == 1){
373  specs.nbins = nbins;
374  specs.low = 0.;
375  specs.high = nbins;
376  }
377  else if(_axis == 2){
378  specs.nbins = 10;
379  specs.low = 0.;
380  specs.high = 10.;
381  specs.title = "iPN";
382  }
383 
384  return specs;
385  }
386 
387  int
388  findBinCrystal_(ObjectType _otype, const DetId& _id, int _iSM/* = -1*/)
389  {
390  int xbin(0), ybin(0);
391  int nbinsX(0);
392  int subdet(_id.subdetId());
393 
394  if(subdet == EcalBarrel){
395  EBDetId ebid(_id);
396  int iphi(ebid.iphi());
397  int ieta(ebid.ieta());
398  switch(_otype){
399  case kEB:
400  xbin = iphi;
401  ybin = ieta < 0 ? ieta + 86 : ieta + 85;
402  nbinsX = 360;
403  break;
404  case kSM:
405  case kEBSM:
406  xbin = ieta < 0 ? -ieta : ieta;
407  ybin = ieta < 0 ? (iphi - 1) % 20 + 1 : 20 - (iphi - 1) % 20;
408  nbinsX = nEBSMEta;
409  break;
410  default:
411  break;
412  }
413  }
414  else if(subdet == EcalEndcap){
415  EEDetId eeid(_id);
416  int ix(eeid.ix());
417  int iy(eeid.iy());
418  switch(_otype){
419  case kEE:
420  xbin = eeid.zside() < 0 ? ix : ix + 100;
421  ybin = iy;
422  nbinsX = 200;
423  break;
424  case kEEm:
425  case kEEp:
426  xbin = ix;
427  ybin = iy;
428  nbinsX = 100;
429  break;
430  case kSM:
431  case kEESM:
432  {
433  int iSM(_iSM >= 0 ? _iSM : dccId(_id) - 1);
434  xbin = ix - xlow_(iSM);
435  ybin = iy - ylow_(iSM);
436  if(iSM == kEEm02 || iSM == kEEm08 || iSM == kEEp02 || iSM == kEEp08)
437  nbinsX = nEESMXExt;
438  else if(iSM == kEEm01 || iSM == kEEm05 || iSM == kEEm09 || iSM == kEEp01 || iSM == kEEp05 || iSM == kEEp09)
439  nbinsX = nEESMXRed;
440  else
441  nbinsX = nEESMX;
442  }
443  break;
444  default:
445  break;
446  }
447  }
448  else if(subdet == EcalLaserPnDiode){
449  EcalPnDiodeDetId pnid(_id);
450  switch(_otype){
451  case kSMMEM:
452  case kEBSMMEM:
453  case kEESMMEM:
454  xbin = pnid.iPnId();
455  ybin = 1;
456  nbinsX = 10;
457  break;
458  case kMEM:
459  xbin = memDCCIndex(dccId(_id)) + 1;
460  ybin = pnid.iPnId();
461  nbinsX = 44;
462  break;
463  case kEBMEM:
464  xbin = memDCCIndex(dccId(_id)) - 3;
465  ybin = pnid.iPnId();
466  nbinsX = 36;
467  break;
468  case kEEMEM:
469  xbin = memDCCIndex(dccId(_id)) + 1;
470  if(xbin > kEEmHigh + 1) xbin -= 36;
471  ybin = pnid.iPnId();
472  nbinsX = 8;
473  break;
474  default:
475  break;
476  }
477  }
478 
479  return (nbinsX + 2) * ybin + xbin;
480  }
481 
482  int
484  {
485  return findBinCrystal_(_otype, getElectronicsMap()->getDetId(_id));
486  }
487 
488  int
490  {
491  int xbin(0);
492  int ybin(0);
493  int nbinsX(0);
494  int subdet(_id.subdetId());
495 
496  if((subdet == EcalTriggerTower && !isEndcapTTId(_id)) || subdet == EcalBarrel){
497  EcalTrigTowerDetId ttid;
498  if(subdet == EcalBarrel) ttid = EBDetId(_id).tower();
499  else ttid = _id;
500 
501  int ieta(ttid.ieta());
502  int iphi((ttid.iphi() + 1) % 72 + 1);
503  switch(_otype){
504  case kEB:
505  xbin = iphi;
506  ybin = ieta < 0 ? ieta + 18 : ieta + 17;
507  nbinsX = 72;
508  break;
509  case kSM:
510  case kEBSM:
511  xbin = ieta < 0 ? -ieta : ieta;
512  ybin = ieta < 0 ? (iphi - 1) % 4 + 1 : 4 - (iphi - 1) % 4;
513  nbinsX = 17;
514  break;
515  default:
516  break;
517  }
518  }
519  else if(subdet == EcalEndcap){
520  unsigned tccid(tccId(_id));
521  unsigned iSM(tccid <= 36 ? tccid % 18 / 2 : (tccid - 72) % 18 / 2);
522  return findBinCrystal_(_otype, _id, iSM);
523  }
524 
525  return (nbinsX + 2) * ybin + xbin;
526  }
527 
528  int
529  findBinSuperCrystal_(ObjectType _otype, const DetId& _id, int _iSM/* -1*/)
530  {
531  int xbin(0);
532  int ybin(0);
533  int nbinsX(0);
534  int subdet(_id.subdetId());
535 
536  if(subdet == EcalBarrel){
537  EBDetId ebid(_id);
538  int iphi(ebid.iphi());
539  int ieta(ebid.ieta());
540  switch(_otype){
541  case kEB:
542  xbin = (iphi - 1) / 5 + 1;
543  ybin = (ieta < 0 ? ieta + 85 : ieta + 84) / 5 + 1;
544  nbinsX = 72;
545  break;
546  case kSM:
547  case kEBSM:
548  xbin = (ieta < 0 ? -ieta - 1 : ieta - 1) / 5 + 1;
549  ybin = (ieta < 0 ? (iphi - 1) % 20 : 19 - (iphi - 1) % 20) / 5 + 1;
550  nbinsX = nEBSMEta / 5;
551  break;
552  default:
553  break;
554  }
555  }
556  else if(subdet == EcalEndcap){
557  if(isEcalScDetId(_id)){
558  EcalScDetId scid(_id);
559  int ix(scid.ix());
560  int iy(scid.iy());
561  switch(_otype){
562  case kEE:
563  {
564  int zside(scid.zside());
565  xbin = zside < 0 ? ix : ix + 20;
566  ybin = iy;
567  nbinsX = 40;
568  }
569  break;
570  case kEEm:
571  case kEEp:
572  xbin = ix;
573  ybin = iy;
574  nbinsX = 20;
575  break;
576  case kSM:
577  case kEESM:
578  {
579  int iSM(_iSM >= 0 ? _iSM : dccId(_id) - 1);
580  xbin = ix - xlow_(iSM) / 5;
581  ybin = iy - ylow_(iSM) / 5;
582  if(iSM == kEEm02 || iSM == kEEm08 || iSM == kEEp02 || iSM == kEEp08)
583  nbinsX = nEESMXExt / 5;
584  else if(iSM == kEEm01 || iSM == kEEm05 || iSM == kEEm09 || iSM == kEEp01 || iSM == kEEp05 || iSM == kEEp09)
585  nbinsX = nEESMXRed / 5;
586  else
587  nbinsX = nEESMX / 5;
588  }
589  break;
590  default:
591  break;
592  }
593  }
594  else{
595  EEDetId eeid(_id);
596  int ix(eeid.ix());
597  int iy(eeid.iy());
598  switch(_otype){
599  case kEE:
600  xbin = (eeid.zside() < 0 ? ix - 1 : ix + 99) / 5 + 1;
601  ybin = (iy - 1) / 5 + 1;
602  nbinsX = 40;
603  break;
604  case kEEm:
605  case kEEp:
606  xbin = (ix - 1) / 5 + 1;
607  ybin = (iy - 1) / 5 + 1;
608  nbinsX = 20;
609  break;
610  case kSM:
611  case kEESM:
612  {
613  int iSM(_iSM >= 0 ? _iSM : dccId(_id) - 1);
614  xbin = (ix - xlow_(iSM) - 1) / 5 + 1;
615  ybin = (iy - ylow_(iSM) - 1) / 5 + 1;
616  if(iSM == kEEm02 || iSM == kEEm08 || iSM == kEEp02 || iSM == kEEp08)
617  nbinsX = nEESMXExt / 5;
618  else if(iSM == kEEm01 || iSM == kEEm05 || iSM == kEEm09 || iSM == kEEp01 || iSM == kEEp05 || iSM == kEEp09)
619  nbinsX = nEESMXRed / 5;
620  else
621  nbinsX = nEESMX / 5;
622  }
623  break;
624  default:
625  break;
626  }
627  }
628  }
629  else if(subdet == EcalTriggerTower && !isEndcapTTId(_id)){
630  EcalTrigTowerDetId ttid(_id);
631  int ieta(ttid.ieta());
632  int iphi((ttid.iphi() + 1) % 72 + 1);
633  switch(_otype){
634  case kEB:
635  xbin = iphi;
636  ybin = ieta < 0 ? ieta + 18 : ieta + 17;
637  nbinsX = 72;
638  break;
639  case kSM:
640  case kEBSM:
641  xbin = ieta < 0 ? -ieta : ieta;
642  ybin = ieta < 0 ? (iphi - 1) % 4 + 1 : 4 - (iphi - 1) % 4;
643  nbinsX = nEBSMEta / 5;
644  break;
645  default:
646  break;
647  }
648  }
649 
650  return (nbinsX + 2) * ybin + xbin;
651  }
652 
653  int
655  {
656  int xbin(0);
657  int ybin(0);
658  int nbinsX(0);
659  int iDCC(_id.dccId() - 1);
660 
661  if(iDCC >= kEBmLow && iDCC <= kEBpHigh){
662  unsigned towerid(_id.towerId());
663  bool isEBm(iDCC <= kEBmHigh);
664  switch(_otype){
665  case kEB:
666  xbin = 4 * ((iDCC - 9) % 18) + (isEBm ? towerid - 1 : 68 - towerid) % 4 + 1;
667  ybin = (towerid - 1) / 4 * (isEBm ? -1 : 1) + (isEBm ? 18 : 17);
668  break;
669  case kSM:
670  case kEBSM:
671  xbin = (towerid - 1) / 4 + 1;
672  ybin = (isEBm ? towerid - 1 : 68 - towerid) % 4 + 1;
673  break;
674  default:
675  break;
676  }
677  }
678  else{
679  return findBinSuperCrystal_(_otype, EEDetId(getElectronicsMap()->getDetId(_id)).sc());
680  }
681 
682  return (nbinsX + 2) * ybin + xbin;
683  }
684  }
685 }
const double Pi
int findBinCrystal_(ObjectType, DetId const &, int=-1)
unsigned memDCCIndex(unsigned)
int i
Definition: DBlmapReader.cc:9
int findBinTriggerTower_(ObjectType, DetId const &)
int ix() const
Definition: EEDetId.h:76
std::vector< DetId > dccConstituents(int dccId) const
Get the constituent detids for this dccId.
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
double const etaBound
EcalElectronicsMapping const * getElectronicsMap()
unsigned tccId(DetId const &)
int towerId() const
get the tower id
int zside(DetId const &)
unsigned nSuperCrystals(unsigned)
int ieta() const
get the tower ieta
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
bool isEndcapTTId(DetId const &)
int iPnId() const
get the PnId
int findBinSuperCrystal_(ObjectType, DetId const &, int=-1)
int ix() const
Definition: EcalScDetId.h:71
AxisSpecs getBinningSMMEM_(BinningType, bool, unsigned, int)
int zside() const
Definition: EEDetId.h:70
AxisSpecs getBinningEB_(BinningType, bool, int)
int iy() const
Definition: EEDetId.h:82
EcalTrigTowerDetId tower() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.h:59
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
AxisSpecs getBinningSM_(BinningType, bool, unsigned, int)
int dccId() const
get the DCC (Ecal Local DCC value not global one) id
int iy() const
Definition: EcalScDetId.h:77
bool isEcalScDetId(DetId const &)
unsigned memDCCId(unsigned)
Definition: DetId.h:18
int iphi() const
get the tower iphi
int zside() const
Definition: EcalScDetId.h:65
AxisSpecs getBinningEE_(BinningType, bool, int, int)
AxisSpecs getBinningMEM_(BinningType, bool, int, int)
unsigned dccId(DetId const &)
AxisSpecs getBinningEcal_(BinningType, bool, int)