CMS 3D CMS Logo

PixelBarrelName.cc
Go to the documentation of this file.
2 
4 
5 //#include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
7 
8 #include <sstream>
9 #include <iostream>
10 
11 using namespace std;
12 
13 namespace {
14  // ladder limits
15  // for phase 0
16  const int lL[2][12] ={{5,15,26, 8,24,41,11,33,56, 0, 0, 0},
17  {3, 9,16, 7,21,36,11,33,56,16,48,81}};
18  // for phase 1
19  //const int lL[12] ={ 3, 9,16, 7,21,36,11,33,56,16,48,81};
20  //const bool phase1 = false; // this has to come from the trackerTopology class
21 }
22 
24  : PixelModuleName(true), thePart(mO), theLayer(0),
25  theModule(0), theLadder(0), phase1(phase) {
26 
27  theLayer = tt->pxbLayer(id);
28  int oldModule = tt->pxbModule(id); // CMSSW convention
29  int oldLadder = tt->pxbLadder(id); // CMSSW convention
30 
31  int ladder = convertLadderNumber(oldLadder); // convert to online convention
32  int module = oldModule-4; // convert
33  if (module<=0) module--;
34 
35  //
36  // part
37  //
38  if (module < 0 && ladder < 0) thePart = mO;
39  else if (module > 0 && ladder < 0) thePart = pO;
40  else if (module < 0 && ladder > 0) thePart = mI;
41  else if (module > 0 && ladder > 0) thePart = pI;
42 
43  //
44  // ladder
45  //
46  theLadder = abs(ladder);
47 
48  //
49  // module
50  //
51  theModule = abs(module);
52 
53 }
54 
55 // Old constructor, works with the old pixel classes DO NOT USE
58  theModule(0), theLadder(0), phase1(phase) {
59 
60  // uint32_t rawId = id.rawId();
61  PXBDetId cmssw_numbering(id);
62 
63  theLayer = cmssw_numbering.layer();
64 
65  int oldModule = cmssw_numbering.module() -4; if (oldModule<=0) oldModule--;
66  int oldLadder = cmssw_numbering.ladder();
67 
68  if(phase1) { // phase 1
69 
70  if (theLayer == 1) {
71  if (oldLadder <= 3) oldLadder = 4-oldLadder; // +1, ..., +3
72  else if (oldLadder >= 4 && oldLadder <= 9 ) oldLadder = 3-oldLadder; // -1, ..., -6
73  else if (oldLadder >= 10) oldLadder = 16-oldLadder; // +6, ..., +4
74  }
75  else if (theLayer == 2) {
76  if (oldLadder <= 7) oldLadder = 8-oldLadder;
77  else if (oldLadder >= 8 && oldLadder <= 21) oldLadder = 7-oldLadder;
78  else if (oldLadder >= 22) oldLadder = 36-oldLadder;
79  }
80  else if (theLayer == 3) {
81  if (oldLadder <= 11) oldLadder = 12-oldLadder;
82  else if (oldLadder >= 12 && oldLadder <= 33) oldLadder = 11-oldLadder;
83  else if (oldLadder >= 34) oldLadder = 56-oldLadder;
84  }
85  else if (theLayer == 4) {
86  if (oldLadder <= 16) oldLadder = 17-oldLadder;
87  else if (oldLadder >= 17 && oldLadder <= 48) oldLadder = 16-oldLadder;
88  else if (oldLadder >= 49) oldLadder = 81-oldLadder;
89  }
90 
91  } else { // phase 0
92 
93  if (theLayer == 1) {
94  if (oldLadder <= 5) oldLadder = 6-oldLadder;
95  else if (oldLadder >= 6 && oldLadder <= 15 ) oldLadder = 5-oldLadder;
96  else if (oldLadder >= 16) oldLadder = 26-oldLadder;
97  }
98  else if (theLayer == 2) {
99  if (oldLadder <= 8) oldLadder = 9-oldLadder;
100  else if (oldLadder >= 9 && oldLadder <= 24) oldLadder = 8-oldLadder;
101  else if (oldLadder >= 25) oldLadder = 41-oldLadder;
102  }
103  else if (theLayer == 3) {
104  if (oldLadder <= 11) oldLadder = 12-oldLadder;
105  else if (oldLadder >= 12 && oldLadder <= 33) oldLadder = 11-oldLadder;
106  else if (oldLadder >= 34) oldLadder = 56-oldLadder;
107  }
108  } // end phase 0/1
109 
110  //
111  // part
112  //
113  if (oldModule < 0 && oldLadder < 0) thePart = mO;
114  else if (oldModule > 0 && oldLadder < 0) thePart = pO;
115  else if (oldModule < 0 && oldLadder > 0) thePart = mI;
116  else if (oldModule > 0 && oldLadder > 0) thePart = pI;
117 
118 
119  //
120  // ladder
121  //
122  theLadder = abs(oldLadder);
123 
124  //
125  // module
126  //
127  theModule = abs(oldModule);
128 
129 }
130 
131 
132 // convert ladder number
134  int ladder=-1;
135  int ind=0;
136  if(phase1) ind=1;
137 
138  if (theLayer == 1) {
139  if (oldLadder <= lL[ind][0] )
140  ladder =(lL[ind][0]+1)-oldLadder;
141  else if (oldLadder >= (lL[ind][0]+1) && oldLadder <= lL[ind][1])
142  ladder = lL[ind][0]-oldLadder;
143  else if (oldLadder >= (lL[ind][1]+1) )
144  ladder = lL[ind][2]-oldLadder;
145 
146  } else if (theLayer == 2) {
147 
148  if (oldLadder <= lL[ind][3])
149  ladder =(lL[ind][3]+1)-oldLadder;
150  else if (oldLadder >= (lL[ind][3]+1) && oldLadder <= lL[ind][4])
151  ladder = lL[ind][3]-oldLadder;
152  else if (oldLadder >= (lL[ind][4]+1))
153  ladder = lL[ind][5]-oldLadder;
154 
155  } else if (theLayer == 3) {
156 
157  if (oldLadder <= lL[ind][6])
158  ladder = (lL[ind][6]+1)-oldLadder;
159  else if (oldLadder >= (lL[ind][6]+1) && oldLadder <= lL[ind][7])
160  ladder = lL[ind][6]-oldLadder;
161  else if (oldLadder >= (lL[ind][7]+1))
162  ladder = lL[ind][8]-oldLadder;
163 
164  } else if (theLayer == 4) {
165 
166  if (oldLadder <= lL[ind][9])
167  ladder =(lL[ind][9]+1)-oldLadder;
168  else if (oldLadder >= (lL[ind][9]+1) && oldLadder <= lL[ind][10])
169  ladder = lL[ind][9]-oldLadder;
170  else if (oldLadder >= (lL[ind][10]+1))
171  ladder = lL[ind][11]-oldLadder;
172 
173  }
174 
175  return ladder;
176 }
177 
178 // constructor from name string
181  theModule(0), theLadder(0), phase1(phase) {
182 
183  // parse the name string
184  // first, check to make sure this is an BPix name, should start with "BPix_"
185  // also check to make sure the needed parts are present
186  if ( (name.substr(0, 5) != "BPix_") ||
187  (name.find("_B") == string::npos) ||
188  (name.find("_LYR") == string::npos) ||
189  (name.find("_LDR") == string::npos) ||
190  (name.find("_MOD") == string::npos) ) {
191  edm::LogError ("BadNameString|SiPixel")
192  << "Bad name string in PixelBarrelName::PixelBarrelName(std::string): "
193  << name;
194  return;
195  }
196 
197  // strip off ROC part if it's there
198  if (name.find("_ROC") != string::npos)
199  name = name.substr(0, name.find("_ROC"));
200 
201  // find shell
202  string shellString = name.substr(name.find("_B")+2, name.find("_SEC")-name.find("_B")-2);
203  if (shellString == "mO") thePart = mO;
204  else if (shellString == "mI") thePart = mI;
205  else if (shellString == "pO") thePart = pO;
206  else if (shellString == "pI") thePart = pI;
207  else {
208  edm::LogError ("BadNameString|SiPixel")
209  << "Unable to determine shell in PixelBarrelName::PixelBarrelName(std::string): "
210  << name;
211  }
212 
213  // find the layer
214  string layerString = name.substr(name.find("_LYR")+4, name.find("_LDR")-name.find("_LYR")-4);
215  if (layerString == "1") theLayer = 1;
216  else if (layerString == "2") theLayer = 2;
217  else if (layerString == "3") theLayer = 3;
218  else if (phase1 && layerString == "4") theLayer = 4;
219  else {
220  edm::LogError ("BadNameString|SiPixel")
221  << "Unable to determine layer in PixelBarrelName::PixelBarrelName(std::string): "
222  << name;
223  }
224 
225  // find the ladder
226  string ladderString = name.substr(name.find("_LDR")+4, name.find("_MOD")-name.find("_LDR")-4);
227 
228  if(phase1) { // phase 1 ladders
229  // do we want to kee the "F" for phase1?
230  if (ladderString.substr(ladderString.size()-1, 1) == "F") {
231  int ladderNum = atoi(ladderString.substr(0, ladderString.size() -1).c_str());
232  if (theLayer == 1 && ladderNum >= 1 && ladderNum <= 6) theLadder = ladderNum;
233  else if (theLayer == 2 && ladderNum >= 1 && ladderNum <= 14) theLadder = ladderNum;
234  else if (theLayer == 3 && ladderNum >= 1 && ladderNum <= 22) theLadder = ladderNum;
235  else if (theLayer == 4 && ladderNum >= 1 && ladderNum <= 32) theLadder = ladderNum;
236  else {
237  edm::LogError ("BadNameString|SiPixel")
238  << "Unable to determine ladder in PixelBarrelNameUpgrade::PixelBarrelName(std::string): "
239  << name;
240  }
241  } // full ladders
242  else {
243  edm::LogError ("BadNameString|SiPixel")
244  << "Unable to determine ladder in PixelBarrelNameUpgrade::PixelBarrelName(std::string): "
245  << name;
246  }
247 
248 
249  } else { // phase 0 ladders
250 
251  if (ladderString == "1H") theLadder = 1;
252  else if (ladderString == "10H" && theLayer == 1) theLadder = 10;
253  else if (ladderString == "16H" && theLayer == 2) theLadder = 16;
254  else if (ladderString == "22H" && theLayer == 3) theLadder = 22;
255  else if (ladderString.substr(ladderString.size()-1, 1) == "F") {
256  int ladderNum = atoi(ladderString.substr(0, ladderString.size() -1).c_str());
257  if (theLayer == 1 && ladderNum > 1 && ladderNum < 10) theLadder = ladderNum;
258  else if (theLayer == 2 && ladderNum > 1 && ladderNum < 16) theLadder = ladderNum;
259  else if (theLayer == 3 && ladderNum > 1 && ladderNum < 22) theLadder = ladderNum;
260  else {
261  edm::LogError ("BadNameString|SiPixel")
262  << "Unable to determine ladder in PixelBarrelName::PixelBarrelName(std::string): "
263  << name;
264  }
265  } // full ladders
266  else {
267  edm::LogError ("BadNameString|SiPixel")
268  << "Unable to determine ladder in PixelBarrelName::PixelBarrelName(std::string): "
269  << name;
270  }
271  } // phase0/1
272 
273  // find the module
274  string moduleString = name.substr(name.find("_MOD")+4, name.size()-name.find("_MOD")-4);
275  if (moduleString == "1") theModule = 1;
276  else if (moduleString == "2") theModule = 2;
277  else if (moduleString == "3") theModule = 3;
278  else if (moduleString == "4") theModule = 4;
279  else {
280  edm::LogError ("BadNameString|SiPixel")
281  << "Unable to determine module in PixelBarrelName::PixelBarrelName(std::string): "
282  << name;
283  }
284 
285 } // PixelBarrelName::PixelBarrelName(std::string name)
286 
288 {
289  int sector = 0;
290 
291  if (theLayer==1) {
292 
293  if(phase1) { // phase 1
294  // Layer 1 for phase1 is special, modules on a ladder are shared in different sectors
295  // Ladder Module Sector
296  // 1 2,3,4 1
297  // 1 1 2
298  // 2 3,4 2
299  // 2 1,2 3
300  // 3 4 3
301  // 3 1,2,3 4
302  // 4 2,3,4 5
303  // 4 1 6
304  // 5 3,4 6
305  // 5 1,2 7
306  // 6 4 7
307  // 6 1,2,3 8
308 
309  switch (theLadder) {
310  case 1 : { // ladder 1
311  if(theModule>=2) {sector = 1; break;} // mods 2,3,4
312  else {sector = 2; break;} // mods 1
313  }
314  case 2 : { // ladder 2
315  if(theModule>=3) {sector = 2; break;} // mods 3,4
316  else {sector = 3; break;} // mods 1,2
317  }
318  case 3 : { // ladder 3
319  if(theModule>=4) {sector = 3; break;}
320  else {sector = 4; break;}
321  sector = 3; break;
322  }
323  case 4 : { // ladder 4
324  if(theModule>=2) {sector = 5; break;}
325  else {sector = 6; break;}
326  sector = 6; break;
327  }
328  case 5 : { // ladder 5
329  if(theModule>=3) {sector = 6; break;}
330  else {sector = 7; break;}
331  sector = 7; break;
332  }
333  case 6 : { // ladder 6
334  if(theModule>=4) {sector = 7; break;} // mods 4
335  else {sector = 8; break;} // mods 1,2,3
336  sector = 8; break;
337  }
338  default: ;
339  };
340 
341  } else { // phase 0
342  switch (theLadder) {
343  case 1 : case 2: {sector = 1; break;}
344  case 3 : {sector = 2; break;}
345  case 4 : {sector = 3; break;}
346  case 5 : {sector = 4; break;}
347  case 6 : {sector = 5; break;}
348  case 7 : {sector = 6; break;}
349  case 8 : {sector = 7; break;}
350  case 9 : case 10:{sector = 8; break;}
351  default: ;
352  };
353  } // phase0/1
354 
355  } else if (theLayer==2) {
356 
357  if(phase1) { // phase 1
358  switch (theLadder) {
359  case 1: case 2: {sector = 1; break;}
360  case 3: case 4: {sector = 2; break;}
361  case 5: {sector = 3; break;}
362  case 6: case 7: {sector = 4; break;}
363  case 8: case 9: {sector = 5; break;}
364  case 10: {sector = 6; break;}
365  case 11: case 12: {sector = 7; break;}
366  case 13: case 14: {sector = 8; break;}
367  default: ;
368  };
369 
370  } else { // phase 0
371  switch (theLadder) {
372  case 1 : case 2: {sector = 1; break;}
373  case 3 : case 4: {sector = 2; break;}
374  case 5 : case 6: {sector = 3; break;}
375  case 7 : case 8: {sector = 4; break;}
376  case 9 : case 10: {sector = 5; break;}
377  case 11 : case 12: {sector = 6; break;}
378  case 13 : case 14: {sector = 7; break;}
379  case 15 : case 16: {sector = 8; break;}
380  default: ;
381  };
382  } // enad phase0/1
383 
384  } else if (theLayer==3) {
385 
386  if(phase1) { // phase 1
387  switch (theLadder) {
388  case 1: case 2: {sector = 1; break;}
389  case 3: case 4: case 5: {sector = 2; break;}
390  case 6: case 7: case 8: {sector = 3; break;}
391  case 9: case 10: case 11: {sector = 4; break;}
392  case 12: case 13: case 14: {sector = 5; break;}
393  case 15: case 16: case 17: {sector = 6; break;}
394  case 18: case 19: case 20: {sector = 7; break;}
395  case 21: case 22: {sector = 8; break;}
396  default: ;
397  };
398 
399  } else { // phase 0
400  switch (theLadder) {
401  case 1 : case 2: case 3: {sector = 1; break;}
402  case 4 : case 5: case 6: {sector = 2; break;}
403  case 7 : case 8: case 9: {sector = 3; break;}
404  case 10 : case 11: {sector = 4; break;}
405  case 12 : case 13: {sector = 5; break;}
406  case 14 : case 15: case 16: {sector = 6; break;}
407  case 17 : case 18: case 19: {sector = 7; break;}
408  case 20 : case 21: case 22: {sector = 8; break;}
409  default: ;
410  };
411  } // end phase 0/1
412 
413  } else if (theLayer==4) {
414 
415  if(phase1) { // phase 1
416  switch (theLadder) {
417  case 1 : case 2: case 3: case 4: {sector = 1; break;}
418  case 5 : case 6: case 7: case 8: {sector = 2; break;}
419  case 9 : case 10: case 11: case 12: {sector = 3; break;}
420  case 13 : case 14: case 15: case 16: {sector = 4; break;}
421  case 17 : case 18: case 19: case 20: {sector = 5; break;}
422  case 21 : case 22: case 23: case 24: {sector = 6; break;}
423  case 25 : case 26: case 27: case 28: {sector = 7; break;}
424  case 29 : case 30: case 31: case 32: {sector = 8; break;}
425  default: ;
426  };
427  } // end phase1
428 
429  } // layer
430 
431  return sector;
432 
433 }
434 
436 {
437  bool halfModule = false;
438 
439  if(!phase1) {
440  if (theLadder == 1) halfModule = true;
441  if (theLayer == 1 && theLadder == 10) halfModule = true;
442  if (theLayer == 2 && theLadder == 16) halfModule = true;
443  if (theLayer == 3 && theLadder == 22) halfModule = true;
444  }
445  return halfModule;
446 }
447 
449 {
451 }
452 
454 {
455  if ( o.isBarrel() ) {
456  const PixelBarrelName *other = dynamic_cast<const PixelBarrelName*>(&o);
457  return ( other
458  && thePart == other->thePart
459  && theLayer == other->theLayer
460  && theModule == other->theModule
461  && theLadder == other->theLadder);
462  } else return false;
463 }
464 
465 string PixelBarrelName::name() const
466 {
467  std::ostringstream stm;
468 
469  stm<<"BPix_B"<<thePart<<"_SEC"<<sectorName()<<"_LYR"<<theLayer<<"_LDR"<<theLadder;
470  if ( isHalfModule() ) stm <<"H"; else stm <<"F";
471  stm << "_MOD" << theModule;
472 
473  return stm.str();
474 }
475 
476 // return the DetId, uses the new topology class
478  uint32_t layer = 0;
479  uint32_t ladder = 0;
480  uint32_t module = 0;
481 
482  layer = layerName();
483  int tmpLadder = ladderName();
484  uint32_t tmpModule = moduleName();
485 
486  // translate the ladder number from the naming convention to the cmssw convention
487  bool outer = false;
488  Shell shell = thePart;
489  int ind=0;
490  if(phase1) ind=1;
491  outer = (shell == mO) || (shell == pO);
492  if (outer) {
493  if (layer == 1)
494  ladder = tmpLadder + lL[ind][0];
495  else if (layer == 2)
496  ladder = tmpLadder + lL[ind][3];
497  else if (layer == 3)
498  ladder = tmpLadder + lL[ind][6];
499  else if (layer == 4)
500  ladder = tmpLadder + lL[ind][9];
501  } // outer
502  else { // inner
503  if (layer == 1) {
504  if (tmpLadder <= lL[ind][0]) ladder = (lL[ind][0]+1) - tmpLadder;
505  else ladder = lL[ind][2] - tmpLadder;
506  } else if (layer == 2) {
507  if (tmpLadder <= lL[ind][3]) ladder = (lL[ind][3]+1) - tmpLadder;
508  else ladder = lL[ind][5] - tmpLadder;
509  } else if (layer == 3) {
510  if (tmpLadder <= lL[ind][6]) ladder = (lL[ind][6]+1) - tmpLadder;
511  else ladder = lL[ind][8] - tmpLadder;
512  } else if (layer == 4) {
513  if (tmpLadder <= lL[ind][9]) ladder = (lL[ind][9]+1) - tmpLadder;
514  else ladder = lL[ind][11] - tmpLadder;
515  } // layer
516  } // inner
517 
518  // translate the module number from naming convention to cmssw convention
519  // numbering starts at positive z
520  if (shell == pO || shell == pI)
521  module = tmpModule + 4;
522  else // negative z side
523  module = 5 - tmpModule;
524 
525  DetId id = tt->pxbDetId(layer, ladder, module);
526  return id;
527 }
528 
529 // return the pixel DetId, obsolete, uses the old index class
531 
532  uint32_t layer = 0;
533  uint32_t ladder = 0;
534  uint32_t module = 0;
535 
536  layer = layerName();
537  uint32_t tmpLadder = ladderName();
538  uint32_t tmpModule = moduleName();
539 
540  // translate the ladder number from the naming convention to the cmssw convention
541  bool outer = false;
542  Shell shell = thePart;
543  outer = (shell == mO) || (shell == pO);
544 
545  if(phase1) { // phase 1
546 
547  if (outer) { // outer
548  if (layer == 1)
549  ladder = tmpLadder + 3;
550  else if (layer == 2)
551  ladder = tmpLadder + 7;
552  else if (layer == 3)
553  ladder = tmpLadder + 11;
554  else if (layer == 4)
555  ladder = tmpLadder + 16;
556  } else { // inner
557  if (layer == 1) {
558  if (tmpLadder <= 3) ladder = 4 - tmpLadder;
559  else if (tmpLadder <= 6) ladder = 16 - tmpLadder;
560  } else if (layer == 2) {
561  if (tmpLadder <= 7) ladder = 8 - tmpLadder;
562  else if (tmpLadder <= 14) ladder = 36 - tmpLadder;
563  } else if (layer == 3) {
564  if (tmpLadder <= 11) ladder = 12 - tmpLadder;
565  else if (tmpLadder <= 22) ladder = 56 - tmpLadder;
566  } else if (layer == 4) {
567  if (tmpLadder <= 16) ladder = 17 - tmpLadder;
568  else if (tmpLadder <= 32) ladder = 81 - tmpLadder;
569  } // layer
570  } // inner
571 
572  } else { // phase 0
573  if (outer) { // outer
574  if (layer == 1)
575  ladder = tmpLadder + 5;
576  else if (layer == 2)
577  ladder = tmpLadder + 8;
578  else if (layer == 3)
579  ladder = tmpLadder + 11;
580  } else { // inner
581  if (layer == 1) { // layer 1
582  if (tmpLadder <= 5) ladder = 6 - tmpLadder;
583  else if (tmpLadder <= 10) ladder = 26 - tmpLadder;
584  } else if (layer == 2) { // layer 2
585  if (tmpLadder <= 8) ladder = 9 - tmpLadder;
586  else if (tmpLadder <= 16) ladder = 41 - tmpLadder;
587  } else if (layer == 3) { // layer 3
588  if (tmpLadder <= 11) ladder = 12 - tmpLadder;
589  else if (tmpLadder <= 22) ladder = 56 - tmpLadder;
590  } // end layer
591  } // inner
592 
593  } // phase
594 
595 
596  // translate the module number from naming convention to cmssw convention
597  // numbering starts at positive z
598  if (shell == pO || shell == pI)
599  module = tmpModule + 4;
600  else // negative z side
601  module = 5 - tmpModule;
602 
603  return PXBDetId(layer, ladder, module);
604 }
605 
606 std::ostream & operator<<( std::ostream& out, const PixelBarrelName::Shell& t)
607 {
608  switch (t) {
609  case(PixelBarrelName::pI) : {out << "pI"; break;}
610  case(PixelBarrelName::pO) : {out << "pO"; break;}
611  case(PixelBarrelName::mI) : {out << "mI"; break;}
612  case(PixelBarrelName::mO) : {out << "mO"; break;}
613  default: out << "unknown";
614  };
615  return out;
616 }
int moduleName() const
module id (index in z)
int convertLadderNumber(int oldLadder)
bool operator==(const PixelModuleName &) const override
check equality of modules from datamemebers
unsigned int pxbLadder(const DetId &id) const
unsigned int pxbModule(const DetId &id) const
unsigned int ladder() const
ladder id
Definition: PXBDetId.h:39
unsigned int layer() const
layer id
Definition: PXBDetId.h:35
bool isHalfModule() const
full or half module
int sectorName() const
sector id
unsigned int module() const
det id
Definition: PXBDetId.h:43
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::string name() const override
from base class
std::ostream & operator<<(std::ostream &out, const PixelBarrelName::Shell &t)
unsigned int pxbLayer(const DetId &id) const
virtual bool isBarrel() const
true for barrel modules
Definition: DetId.h:18
int ladderName() const
ladder id (index in phi)
int layerName() const
layer id
PixelBarrelName(const DetId &, const TrackerTopology *tt, bool phase=false)
ctor from DetId
Definition: shell.py:1
DetId pxbDetId(uint32_t layer, uint32_t ladder, uint32_t module) const
Definition: vlib.h:208
PXBDetId getDetId()
return the DetId
PixelModuleName::ModuleType moduleType() const override
module Type