CMS 3D CMS Logo

PixelBarrelNameUpgrade.cc
Go to the documentation of this file.
2 
3 #include <sstream>
4 #include <iostream>
5 
8 
9 using namespace std;
10 
12  // uint32_t rawId = id.rawId();
13  PXBDetId cmssw_numbering(id);
14 
15  theLayer = cmssw_numbering.layer();
16 
17  int oldModule = cmssw_numbering.module() - 4;
18  if (oldModule <= 0)
19  oldModule--; // -4, ..., -1, +1, ...,+4
20 
21  int oldLadder = cmssw_numbering.ladder();
22 
23  if (theLayer == 1) {
24  if (oldLadder <= 3)
25  oldLadder = 4 - oldLadder; // +1, ..., +3
26  else if (oldLadder >= 4 && oldLadder <= 9)
27  oldLadder = 3 - oldLadder; // -1, ..., -6
28  else if (oldLadder >= 10)
29  oldLadder = 16 - oldLadder; // +6, ..., +4
30  } else if (theLayer == 2) {
31  if (oldLadder <= 7)
32  oldLadder = 8 - oldLadder;
33  else if (oldLadder >= 8 && oldLadder <= 21)
34  oldLadder = 7 - oldLadder;
35  else if (oldLadder >= 22)
36  oldLadder = 36 - oldLadder;
37  } else if (theLayer == 3) {
38  if (oldLadder <= 11)
39  oldLadder = 12 - oldLadder;
40  else if (oldLadder >= 12 && oldLadder <= 33)
41  oldLadder = 11 - oldLadder;
42  else if (oldLadder >= 34)
43  oldLadder = 56 - oldLadder;
44  } else if (theLayer == 4) {
45  if (oldLadder <= 16)
46  oldLadder = 17 - oldLadder;
47  else if (oldLadder >= 17 && oldLadder <= 48)
48  oldLadder = 16 - oldLadder;
49  else if (oldLadder >= 49)
50  oldLadder = 81 - oldLadder;
51  }
52 
53  //
54  // part
55  //
56  if (oldModule < 0 && oldLadder < 0)
57  thePart = mO;
58  else if (oldModule > 0 && oldLadder < 0)
59  thePart = pO;
60  else if (oldModule < 0 && oldLadder > 0)
61  thePart = mI;
62  else if (oldModule > 0 && oldLadder > 0)
63  thePart = pI;
64  //std::cout << "(oldModule, oldLadder)============(" << oldModule << ", "<< oldLadder<<" )" << std::endl;
65 
66  //
67  // ladder
68  //
69  theLadder = abs(oldLadder);
70 
71  //
72  // module
73  //
74  theModule = abs(oldModule);
75 }
76 
77 // constructor from name string
79  : PixelModuleName(true), thePart(mO), theLayer(0), theModule(0), theLadder(0) {
80  std::cout << "NAME=" << name << std::endl;
81  // parse the name string
82  // first, check to make sure this is an BPix name, should start with "BPix_"
83  // also check to make sure the needed parts are present
84  if ((name.substr(0, 5) != "BPix_") || (name.find("_B") == string::npos) || (name.find("_LYR") == string::npos) ||
85  (name.find("_LDR") == string::npos) || (name.find("_MOD") == string::npos)) {
86  edm::LogError("BadNameString|SiPixel")
87  << "Bad name string in PixelBarrelNameUpgrade::PixelBarrelName(std::string): " << name;
88  return;
89  }
90 
91  // strip off ROC part if it's there
92  if (name.find("_ROC") != string::npos)
93  name = name.substr(0, name.find("_ROC"));
94 
95  // find shell
96  string shellString = name.substr(name.find("_B") + 2, name.find("_SEC") - name.find("_B") - 2);
97  if (shellString == "mO")
98  thePart = mO;
99  else if (shellString == "mI")
100  thePart = mI;
101  else if (shellString == "pO")
102  thePart = pO;
103  else if (shellString == "pI")
104  thePart = pI;
105  else {
106  edm::LogError("BadNameString|SiPixel")
107  << "Unable to determine shell in PixelBarrelNameUpgrade::PixelBarrelName(std::string): " << name;
108  }
109 
110  // find the layer
111  string layerString = name.substr(name.find("_LYR") + 4, name.find("_LDR") - name.find("_LYR") - 4);
112  if (layerString == "1")
113  theLayer = 1;
114  else if (layerString == "2")
115  theLayer = 2;
116  else if (layerString == "3")
117  theLayer = 3;
118  else if (layerString == "4")
119  theLayer = 4;
120  else {
121  edm::LogError("BadNameString|SiPixel")
122  << "Unable to determine layer in PixelBarrelNameUpgrade::PixelBarrelName(std::string): " << name;
123  }
124 
125  // find the ladder
126  string ladderString = name.substr(name.find("_LDR") + 4, name.find("_MOD") - name.find("_LDR") - 4);
127  if (ladderString.substr(ladderString.size() - 1, 1) == "F") {
128  int ladderNum = atoi(ladderString.substr(0, ladderString.size() - 1).c_str());
129  if (theLayer == 1 && ladderNum >= 1 && ladderNum <= 6)
130  theLadder = ladderNum;
131  else if (theLayer == 2 && ladderNum >= 1 && ladderNum <= 14)
132  theLadder = ladderNum;
133  else if (theLayer == 3 && ladderNum >= 1 && ladderNum <= 22)
134  theLadder = ladderNum;
135  else if (theLayer == 4 && ladderNum >= 1 && ladderNum <= 32)
136  theLadder = ladderNum;
137  else {
138  edm::LogError("BadNameString|SiPixel")
139  << "Unable to determine ladder in PixelBarrelNameUpgrade::PixelBarrelName(std::string): " << name;
140  }
141  } // full ladders
142  else {
143  edm::LogError("BadNameString|SiPixel")
144  << "Unable to determine ladder in PixelBarrelNameUpgrade::PixelBarrelName(std::string): " << name;
145  }
146 
147  // find the module
148  string moduleString = name.substr(name.find("_MOD") + 4, name.size() - name.find("_MOD") - 4);
149  if (moduleString == "1")
150  theModule = 1;
151  else if (moduleString == "2")
152  theModule = 2;
153  else if (moduleString == "3")
154  theModule = 3;
155  else if (moduleString == "4")
156  theModule = 4;
157  else {
158  edm::LogError("BadNameString|SiPixel")
159  << "Unable to determine module in PixelBarrelNameUpgrade::PixelBarrelName(std::string): " << name;
160  }
161 
162 } // PixelBarrelNameUpgrade::PixelBarrelName(std::string name)
163 
165  int sector = 0;
166  if (theLayer == 1) {
167  switch (theLadder) {
168  case 1: {
169  sector = 1;
170  break;
171  }
172  case 2: {
173  sector = 2;
174  break;
175  }
176  case 3: {
177  sector = 3;
178  break;
179  }
180  case 4: {
181  sector = 6;
182  break;
183  }
184  case 5: {
185  sector = 7;
186  break;
187  }
188  case 6: {
189  sector = 8;
190  break;
191  }
192  default:;
193  };
194  } else if (theLayer == 2) {
195  switch (theLadder) {
196  case 1:
197  case 2: {
198  sector = 1;
199  break;
200  }
201  case 3:
202  case 4: {
203  sector = 2;
204  break;
205  }
206  case 5:
207  case 6: {
208  sector = 3;
209  break;
210  }
211  case 7: {
212  sector = 4;
213  break;
214  }
215  case 8: {
216  sector = 5;
217  break;
218  }
219  case 9:
220  case 10: {
221  sector = 6;
222  break;
223  }
224  case 11:
225  case 12: {
226  sector = 7;
227  break;
228  }
229  case 13:
230  case 14: {
231  sector = 8;
232  break;
233  }
234  default:;
235  };
236  } else if (theLayer == 3) {
237  switch (theLadder) {
238  case 1:
239  case 2:
240  case 3: {
241  sector = 1;
242  break;
243  }
244  case 4:
245  case 5:
246  case 6: {
247  sector = 2;
248  break;
249  }
250  case 7:
251  case 8:
252  case 9: {
253  sector = 3;
254  break;
255  }
256  case 10:
257  case 11: {
258  sector = 4;
259  break;
260  }
261  case 12:
262  case 13: {
263  sector = 5;
264  break;
265  }
266  case 14:
267  case 15:
268  case 16: {
269  sector = 6;
270  break;
271  }
272  case 17:
273  case 18:
274  case 19: {
275  sector = 7;
276  break;
277  }
278  case 20:
279  case 21:
280  case 22: {
281  sector = 8;
282  break;
283  }
284  default:;
285  };
286  } else if (theLayer == 4) {
287  switch (theLadder) {
288  case 1:
289  case 2:
290  case 3:
291  case 4: {
292  sector = 1;
293  break;
294  }
295  case 5:
296  case 6:
297  case 7:
298  case 8: {
299  sector = 2;
300  break;
301  }
302  case 9:
303  case 10:
304  case 11:
305  case 12: {
306  sector = 3;
307  break;
308  }
309  case 13:
310  case 14:
311  case 15:
312  case 16: {
313  sector = 4;
314  break;
315  }
316  case 17:
317  case 18:
318  case 19:
319  case 20: {
320  sector = 5;
321  break;
322  }
323  case 21:
324  case 22:
325  case 23:
326  case 24: {
327  sector = 6;
328  break;
329  }
330  case 25:
331  case 26:
332  case 27:
333  case 28: {
334  sector = 7;
335  break;
336  }
337  case 29:
338  case 30:
339  case 31:
340  case 32: {
341  sector = 8;
342  break;
343  }
344  default:;
345  };
346  }
347 
348  return sector;
349 }
350 
351 //---- this needs to be removed --------------------------------
352 //---- there is no half module in the upgraded geometry!!! -----
354  bool halfModule = false;
355  // if (theLadder == 1) halfModule = true;
356  // if (theLayer == 1 && theLadder == 10) halfModule = true;
357  // if (theLayer == 2 && theLadder == 16) halfModule = true;
358  // if (theLayer == 3 && theLadder == 22) halfModule = true;
359  return halfModule;
360 }
361 
364 }
365 
367  if (o.isBarrel()) {
368  const PixelBarrelNameUpgrade* other = dynamic_cast<const PixelBarrelNameUpgrade*>(&o);
369  return (other && thePart == other->thePart && theLayer == other->theLayer && theModule == other->theModule &&
370  theLadder == other->theLadder);
371  } else
372  return false;
373 }
374 
376  std::ostringstream stm;
377 
378  stm << "BPix_B" << thePart << "_SEC" << sectorName() << "_LYR" << theLayer << "_LDR" << theLadder;
379  stm << "F";
380  stm << "_MOD" << theModule;
381 
382  return stm.str();
383 }
384 /*
385 string PixelBarrelNameUpgrade::name() const
386 {
387  std::ostringstream stm;
388 
389  stm<<"BPix_B"<<thePart<<"_SEC"<<sectorName()<<"_LYR"<<theLayer<<"_LDR"<<theLadder;
390  if ( isHalfModule() ) stm <<"H"; else stm <<"F";
391  stm << "_MOD" << theModule;
392 
393  return stm.str();
394 }
395 */
396 
397 // return the DetId
399  uint32_t layer = 0;
400  uint32_t ladder = 0;
401  uint32_t module = 0;
402 
403  layer = layerName();
404  uint32_t tmpLadder = ladderName();
405  uint32_t tmpModule = moduleName();
406 
407  // translate the ladder number from the naming convention to the cmssw convention
408  bool outer = false;
409  Shell shell = thePart;
410  outer = (shell == mO) || (shell == pO);
411  if (outer) {
412  if (layer == 1)
413  ladder = tmpLadder + 3;
414  else if (layer == 2)
415  ladder = tmpLadder + 7;
416  else if (layer == 3)
417  ladder = tmpLadder + 11;
418  else if (layer == 4)
419  ladder = tmpLadder + 16;
420  } // outer
421  else { // inner
422  if (layer == 1) {
423  if (tmpLadder <= 3)
424  ladder = 4 - tmpLadder;
425  else if (tmpLadder <= 6)
426  ladder = 16 - tmpLadder;
427  } // layer 1
428  else if (layer == 2) {
429  if (tmpLadder <= 7)
430  ladder = 8 - tmpLadder;
431  else if (tmpLadder <= 14)
432  ladder = 36 - tmpLadder;
433  } // layer 2
434  else if (layer == 3) {
435  if (tmpLadder <= 11)
436  ladder = 12 - tmpLadder;
437  else if (tmpLadder <= 22)
438  ladder = 56 - tmpLadder;
439  } // layer 3
440  else if (layer == 4) {
441  if (tmpLadder <= 16)
442  ladder = 17 - tmpLadder;
443  else if (tmpLadder <= 32)
444  ladder = 81 - tmpLadder;
445  } // layer 4
446  } // inner
447 
448  // translate the module number from naming convention to cmssw convention
449  // numbering starts at positive z
450  if (shell == pO || shell == pI)
451  module = tmpModule + 4;
452  else // negative z side
453  module = 5 - tmpModule;
454 
455  return PXBDetId(layer, ladder, module);
456 
457 } // PXBDetId PixelBarrelNameUpgrade::getDetId()
458 
459 std::ostream& operator<<(std::ostream& out, const PixelBarrelNameUpgrade::Shell& t) {
460  switch (t) {
462  out << "pI";
463  break;
464  }
466  out << "pO";
467  break;
468  }
470  out << "mI";
471  break;
472  }
474  out << "mO";
475  break;
476  }
477  default:
478  out << "unknown";
479  };
480  return out;
481 }
PixelBarrelNameUpgrade(const DetId &)
ctor from DetId
std::ostream & operator<<(std::ostream &out, const PixelBarrelNameUpgrade::Shell &t)
int layerName() const
layer id
unsigned int module() const
det id
Definition: PXBDetId.h:37
bool isHalfModule() const
full or half module
unsigned int layer() const
layer id
Definition: PXBDetId.h:31
Log< level::Error, false > LogError
std::string name() const override
from base class
PXBDetId getDetId()
return the DetId
int moduleName() const
module id (index in z)
int ladderName() const
ladder id (index in phi)
PixelModuleName::ModuleType moduleType() const override
module Type
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Definition: DetId.h:17
int sectorName() const
sector id
bool operator==(const PixelModuleName &) const override
check equality of modules from datamemebers
Definition: shell.py:1
unsigned int ladder() const
ladder id
Definition: PXBDetId.h:34