CMS 3D CMS Logo

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