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 
13 {
14 
15 // uint32_t rawId = id.rawId();
16  PXBDetId cmssw_numbering(id);
17 
18 
19  theLayer = cmssw_numbering.layer();
20 
21  int oldModule = cmssw_numbering.module() -4; if (oldModule<=0) oldModule--; // -4, ..., -1, +1, ...,+4
22 
23  int oldLadder = cmssw_numbering.ladder();
24 
25  if (theLayer == 1) {
26  if (oldLadder <= 3) oldLadder = 4-oldLadder; // +1, ..., +3
27  else if (oldLadder >= 4 && oldLadder <= 9 ) oldLadder = 3-oldLadder; // -1, ..., -6
28  else if (oldLadder >= 10) oldLadder = 16-oldLadder; // +6, ..., +4
29  }
30  else if (theLayer == 2) {
31  if (oldLadder <= 7) oldLadder = 8-oldLadder;
32  else if (oldLadder >= 8 && oldLadder <= 21) oldLadder = 7-oldLadder;
33  else if (oldLadder >= 22) oldLadder = 36-oldLadder;
34  }
35  else if (theLayer == 3) {
36  if (oldLadder <= 11) oldLadder = 12-oldLadder;
37  else if (oldLadder >= 12 && oldLadder <= 33) oldLadder = 11-oldLadder;
38  else if (oldLadder >= 34) oldLadder = 56-oldLadder;
39  }
40  else if (theLayer == 4) {
41  if (oldLadder <= 16) oldLadder = 17-oldLadder;
42  else if (oldLadder >= 17 && oldLadder <= 48) oldLadder = 16-oldLadder;
43  else if (oldLadder >= 49) oldLadder = 81-oldLadder;
44  }
45 
46  //
47  // part
48  //
49  if (oldModule < 0 && oldLadder < 0) thePart = mO;
50  else if (oldModule > 0 && oldLadder < 0) thePart = pO;
51  else if (oldModule < 0 && oldLadder > 0) thePart = mI;
52  else if (oldModule > 0 && oldLadder > 0) thePart = pI;
53  //std::cout << "(oldModule, oldLadder)============(" << oldModule << ", "<< oldLadder<<" )" << std::endl;
54 
55  //
56  // ladder
57  //
58  theLadder = abs(oldLadder);
59 
60  //
61  // module
62  //
63  theModule = abs(oldModule);
64 
65 }
66 
67 
68 // constructor from name string
71  theModule(0), theLadder(0) {
72  std::cout<<"NAME="<<name<<std::endl;
73  // parse the name string
74  // first, check to make sure this is an BPix name, should start with "BPix_"
75  // also check to make sure the needed parts are present
76  if ( (name.substr(0, 5) != "BPix_") ||
77  (name.find("_B") == string::npos) ||
78  (name.find("_LYR") == string::npos) ||
79  (name.find("_LDR") == string::npos) ||
80  (name.find("_MOD") == string::npos) ) {
81  edm::LogError ("BadNameString|SiPixel")
82  << "Bad name string in PixelBarrelNameUpgrade::PixelBarrelName(std::string): "
83  << name;
84  return;
85  }
86 
87  // strip off ROC part if it's there
88  if (name.find("_ROC") != string::npos)
89  name = name.substr(0, name.find("_ROC"));
90 
91  // find shell
92  string shellString = name.substr(name.find("_B")+2, name.find("_SEC")-name.find("_B")-2);
93  if (shellString == "mO") thePart = mO;
94  else if (shellString == "mI") thePart = mI;
95  else if (shellString == "pO") thePart = pO;
96  else if (shellString == "pI") thePart = pI;
97  else {
98  edm::LogError ("BadNameString|SiPixel")
99  << "Unable to determine shell in PixelBarrelNameUpgrade::PixelBarrelName(std::string): "
100  << name;
101  }
102 
103  // find the layer
104  string layerString = name.substr(name.find("_LYR")+4, name.find("_LDR")-name.find("_LYR")-4);
105  if (layerString == "1") theLayer = 1;
106  else if (layerString == "2") theLayer = 2;
107  else if (layerString == "3") theLayer = 3;
108  else if (layerString == "4") theLayer = 4;
109  else {
110  edm::LogError ("BadNameString|SiPixel")
111  << "Unable to determine layer in PixelBarrelNameUpgrade::PixelBarrelName(std::string): "
112  << name;
113  }
114 
115  // find the ladder
116  string ladderString = name.substr(name.find("_LDR")+4, name.find("_MOD")-name.find("_LDR")-4);
117  if (ladderString.substr(ladderString.size()-1, 1) == "F") {
118  int ladderNum = atoi(ladderString.substr(0, ladderString.size() -1).c_str());
119  if (theLayer == 1 && ladderNum >= 1 && ladderNum <= 6) theLadder = ladderNum;
120  else if (theLayer == 2 && ladderNum >= 1 && ladderNum <= 14) theLadder = ladderNum;
121  else if (theLayer == 3 && ladderNum >= 1 && ladderNum <= 22) theLadder = ladderNum;
122  else if (theLayer == 4 && ladderNum >= 1 && ladderNum <= 32) theLadder = ladderNum;
123  else {
124  edm::LogError ("BadNameString|SiPixel")
125  << "Unable to determine ladder in PixelBarrelNameUpgrade::PixelBarrelName(std::string): "
126  << name;
127  }
128  } // full ladders
129  else {
130  edm::LogError ("BadNameString|SiPixel")
131  << "Unable to determine ladder in PixelBarrelNameUpgrade::PixelBarrelName(std::string): "
132  << name;
133  }
134 
135  // find the module
136  string moduleString = name.substr(name.find("_MOD")+4, name.size()-name.find("_MOD")-4);
137  if (moduleString == "1") theModule = 1;
138  else if (moduleString == "2") theModule = 2;
139  else if (moduleString == "3") theModule = 3;
140  else if (moduleString == "4") theModule = 4;
141  else {
142  edm::LogError ("BadNameString|SiPixel")
143  << "Unable to determine module in PixelBarrelNameUpgrade::PixelBarrelName(std::string): "
144  << name;
145  }
146 
147 } // PixelBarrelNameUpgrade::PixelBarrelName(std::string name)
148 
149 
151 {
152  int sector = 0;
153  if (theLayer==1) {
154  switch (theLadder) {
155  case 1 : {sector = 1; break;}
156  case 2 : {sector = 2; break;}
157  case 3 : {sector = 3; break;}
158  case 4 : {sector = 6; break;}
159  case 5 : {sector = 7; break;}
160  case 6 : {sector = 8; break;}
161  default: ;
162  };
163  } else if (theLayer==2) {
164  switch (theLadder) {
165  case 1 : case 2: {sector = 1; break;}
166  case 3 : case 4: {sector = 2; break;}
167  case 5 : case 6: {sector = 3; break;}
168  case 7 : {sector = 4; break;}
169  case 8 : {sector = 5; break;}
170  case 9 : case 10: {sector = 6; break;}
171  case 11 : case 12: {sector = 7; break;}
172  case 13 : case 14: {sector = 8; break;}
173  default: ;
174  };
175  } else if (theLayer==3) {
176  switch (theLadder) {
177  case 1 : case 2: case 3: {sector = 1; break;}
178  case 4 : case 5: case 6: {sector = 2; break;}
179  case 7 : case 8: case 9: {sector = 3; break;}
180  case 10 : case 11: {sector = 4; break;}
181  case 12 : case 13: {sector = 5; break;}
182  case 14 : case 15: case 16: {sector = 6; break;}
183  case 17 : case 18: case 19: {sector = 7; break;}
184  case 20 : case 21: case 22: {sector = 8; break;}
185  default: ;
186  };
187  }
188  else if (theLayer==4) {
189  switch (theLadder) {
190  case 1 : case 2: case 3: case 4: {sector = 1; break;}
191  case 5 : case 6: case 7: case 8: {sector = 2; break;}
192  case 9 : case 10: case 11: case 12: {sector = 3; break;}
193  case 13 : case 14: case 15: case 16: {sector = 4; break;}
194  case 17 : case 18: case 19: case 20: {sector = 5; break;}
195  case 21 : case 22: case 23: case 24: {sector = 6; break;}
196  case 25 : case 26: case 27: case 28: {sector = 7; break;}
197  case 29 : case 30: case 31: case 32: {sector = 8; break;}
198  default: ;
199  };
200  }
201 
202 
203  return sector;
204 
205 }
206 
207 //---- this needs to be removed --------------------------------
208 //---- there is no half module in the upgraded geometry!!! -----
210 {
211  bool halfModule = false;
212 // if (theLadder == 1) halfModule = true;
213 // if (theLayer == 1 && theLadder == 10) halfModule = true;
214 // if (theLayer == 2 && theLadder == 16) halfModule = true;
215 // if (theLayer == 3 && theLadder == 22) halfModule = true;
216  return halfModule;
217 }
218 
219 
221 {
223 }
224 
225 
226 
228 {
229  if ( o.isBarrel() ) {
230  const PixelBarrelNameUpgrade *other = dynamic_cast<const PixelBarrelNameUpgrade*>(&o);
231  return ( other
232  && thePart == other->thePart
233  && theLayer == other->theLayer
234  && theModule == other->theModule
235  && theLadder == other->theLadder);
236  } else return false;
237 }
238 
239 
241 {
242  std::ostringstream stm;
243 
244  stm<<"BPix_B"<<thePart<<"_SEC"<<sectorName()<<"_LYR"<<theLayer<<"_LDR"<<theLadder;
245  stm <<"F";
246  stm << "_MOD" << theModule;
247 
248  return stm.str();
249 }
250 /*
251 string PixelBarrelNameUpgrade::name() const
252 {
253  std::ostringstream stm;
254 
255  stm<<"BPix_B"<<thePart<<"_SEC"<<sectorName()<<"_LYR"<<theLayer<<"_LDR"<<theLadder;
256  if ( isHalfModule() ) stm <<"H"; else stm <<"F";
257  stm << "_MOD" << theModule;
258 
259  return stm.str();
260 }
261 */
262 
263 // return the DetId
265 
266  uint32_t layer = 0;
267  uint32_t ladder = 0;
268  uint32_t module = 0;
269 
270  layer = layerName();
271  uint32_t tmpLadder = ladderName();
272  uint32_t tmpModule = moduleName();
273 
274  // translate the ladder number from the naming convention to the cmssw convention
275  bool outer = false;
276  Shell shell = thePart;
277  outer = (shell == mO) || (shell == pO);
278  if (outer) {
279  if (layer == 1)
280  ladder = tmpLadder + 3;
281  else if (layer == 2)
282  ladder = tmpLadder + 7;
283  else if (layer == 3)
284  ladder = tmpLadder + 11;
285  else if (layer == 4)
286  ladder = tmpLadder + 16;
287  } // outer
288  else { // inner
289  if (layer == 1) {
290  if (tmpLadder <= 3) ladder = 4 - tmpLadder;
291  else if (tmpLadder <= 6) ladder = 16 - tmpLadder;
292  } // layer 1
293  else if (layer == 2) {
294  if (tmpLadder <= 7) ladder = 8 - tmpLadder;
295  else if (tmpLadder <= 14) ladder = 36 - tmpLadder;
296  } // layer 2
297  else if (layer == 3) {
298  if (tmpLadder <= 11) ladder = 12 - tmpLadder;
299  else if (tmpLadder <= 22) ladder = 56 - tmpLadder;
300  } // layer 3
301  else if (layer == 4) {
302  if (tmpLadder <= 16) ladder = 17 - tmpLadder;
303  else if (tmpLadder <= 32) ladder = 81 - tmpLadder;
304  } // layer 4
305  } // inner
306 
307  // translate the module number from naming convention to cmssw convention
308  // numbering starts at positive z
309  if (shell == pO || shell == pI)
310  module = tmpModule + 4;
311  else // negative z side
312  module = 5 - tmpModule;
313 
314  return PXBDetId(layer, ladder, module);
315 
316 } // PXBDetId PixelBarrelNameUpgrade::getDetId()
317 
318 
319 
320 std::ostream & operator<<( std::ostream& out, const PixelBarrelNameUpgrade::Shell& t)
321 {
322  switch (t) {
323  case(PixelBarrelNameUpgrade::pI) : {out << "pI"; break;}
324  case(PixelBarrelNameUpgrade::pO) : {out << "pO"; break;}
325  case(PixelBarrelNameUpgrade::mI) : {out << "mI"; break;}
326  case(PixelBarrelNameUpgrade::mO) : {out << "mO"; break;}
327  default: out << "unknown";
328  };
329  return out;
330 }
331 
332 
int sectorName() const
sector id
PixelBarrelNameUpgrade(const DetId &)
ctor from DetId
std::ostream & operator<<(std::ostream &out, const PixelBarrelNameUpgrade::Shell &t)
bool isHalfModule() const
full or half module
virtual std::string name() const
from base class
unsigned int ladder() const
ladder id
Definition: PXBDetId.h:39
unsigned int layer() const
layer id
Definition: PXBDetId.h:35
PXBDetId getDetId()
return the DetId
unsigned int module() const
det id
Definition: PXBDetId.h:43
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
virtual PixelModuleName::ModuleType moduleType() const
module Type
virtual bool isBarrel() const
true for barrel modules
Definition: DetId.h:18
int ladderName() const
ladder id (index in phi)
virtual bool operator==(const PixelModuleName &) const
check equality of modules from datamemebers
int moduleName() const
module id (index in z)
Definition: shell.py:1
Definition: vlib.h:208
int layerName() const
layer id