CMS 3D CMS Logo

utils.h
Go to the documentation of this file.
1 #ifndef rpcdqm_utils_H
2 #define rpcdqm_utils_H
3 
6 
7 #include <vector>
8 #include <iomanip>
9 #include <string>
10 
11 
12 namespace rpcdqm{
13 
15 
16  struct RPCMEHelper
17  {
18  static void setNoAlphanumeric(MonitorElement* myMe)
19  {
20  // Set no-alphanumeric flag to avoid malfunctioning in multithread environment.
21  TH2* h2 = dynamic_cast<TH2*>(myMe->getTH1());
22  if ( !h2 ) return;
23 
24  h2->GetXaxis()->SetNoAlphanumeric(true);
25  h2->GetYaxis()->SetNoAlphanumeric(true);
26  }
27  };
28 
29  class utils{
30  public:
31  int detId2RollNr(const RPCDetId & _id){
32  if(_id.region()==0){//Barrel
33  if( _id.station() ==1) {// Station1
34  if(_id.layer() ==1) { //in
35  if(_id.roll()==1) //forward
36  _cnr = 1;//RB1inF
37  else //backward
38  _cnr = 2;//RB1inB
39  } else {//out
40  if(_id.roll()==1)
41  _cnr = 3;//RB1outF
42  else
43  _cnr = 4;//RB1outB
44  }
45  }else if (_id.station()==2) {//Station 2
46  if(_id.layer()==1) {
47  if(_id.roll()==1)
48  _cnr = 5;//RB2inB
49  else if(_id.roll()==3)
50  _cnr=6;//RB2inF
51  else if(_id.roll()==2)
52  _cnr=7;//RB2inM
53  }else{
54  if(_id.roll()==2)
55  _cnr=7;//RB2outM
56  else if(_id.roll()==1)
57  _cnr=8;//RB2outB
58  else if(_id.roll()==3)
59  _cnr=9;//RB2outF
60  }
61  }else if(_id.station()==3){//Station 3
62  if(_id.subsector()==1){
63  if(_id.roll()==1)
64  _cnr=10;//RB3-B
65  else
66  _cnr=11;//RB3-F
67  } else {
68  if(_id.roll()==1)
69  _cnr=12;//RB3+B
70  else
71  _cnr=13;//RB3+F
72  }
73  } else if(_id.station()==4) {//Station 4
74  if (_id.sector()== 4) {
75  if ( _id.subsector()==2){//RB4--
76  if(_id.roll()==1)
77  _cnr=14;
78  else
79  _cnr=15;
80  }else if (_id.subsector()==3){//RB4-
81  if(_id.roll()==1)
82  _cnr=16;
83  else
84  _cnr=17;
85  }else if ( _id.subsector()==1) {//RB4+
86  if(_id.roll()==1)
87  _cnr=18;
88  else
89  _cnr=19;
90  }else if ( _id.subsector()==4){//RB4++
91  if(_id.roll()==1)
92  _cnr=20;
93  else
94  _cnr=21;
95  }
96  } else {
97  if(_id.subsector()==1) {
98  if(_id.roll()==1)
99  _cnr=14;
100  else
101  _cnr=15;
102  } else {
103  if(_id.roll()==1)
104  _cnr=16;
105  else
106  _cnr=17;
107  }
108  }
109  }
110  }else{//Endcap
111  int nsub=6;
112  if ( _id.ring()==1 && _id.station() > 1) {
113  nsub=3;
114  }
115  _cnr = (_id.subsector()-1)*3+_id.roll()+(_id.ring()-1)*nsub*3;
116  }
117  return _cnr;
118  }
119 
120  void fillvect() {
121  Wvector2.push_back(0); //Sec 0 - doen't exist ;)
122  Wvector2.push_back(1140); //Sec1
123  Wvector2.push_back(1140); //Sec2
124  Wvector2.push_back(1140); //Sec3
125  Wvector2.push_back(1236); //Sec4
126  Wvector2.push_back(1140); //Sec5
127  Wvector2.push_back(1140); //Sec6
128  Wvector2.push_back(1140); //Sec7
129  Wvector2.push_back(1116); //Sec8
130  Wvector2.push_back(1044); //Sec9
131  Wvector2.push_back(1188); //Sec10
132  Wvector2.push_back(1044); //Sec11
133  Wvector2.push_back(1166); //Sec12
134 
135  Wvector1.push_back(0); //Sec 0 - doen't exist ;)
136  Wvector1.push_back(1146); //Sec1
137  Wvector1.push_back(1146); //Sec2
138  Wvector1.push_back(1146); //Sec3
139  Wvector1.push_back(1242); //Sec4
140  Wvector1.push_back(1146); //Sec5
141  Wvector1.push_back(1146); //Sec6
142  Wvector1.push_back(1146); //Sec7
143  Wvector1.push_back(1122); //Sec8
144  Wvector1.push_back(1050); //Sec9
145  Wvector1.push_back(1194); //Sec10
146  Wvector1.push_back(1050); //Sec11
147  Wvector1.push_back(1122); //Sec12
148 
149  }
150 
151  std::vector<int> SectorStrips2(){
152  return Wvector2;
153  }
154 
155  std::vector<int> SectorStrips1(){
156  return Wvector1;
157  }
158 
159 
160  void dolabeling (bool useRollInfo) {
161 
162  if(useRollInfo){
163  ylabel[1] = "RB1in_B";
164  ylabel[2] = "RB1in_F";
165  ylabel[3] = "RB1out_B";
166  ylabel[4] = "RB1out_F";
167  ylabel[5] = "RB2in_B";
168  ylabel[6] = "RB2in_F";
169 
170  ylabel[7] = "RB2in_M";
171  ylabel[0] = "RB2out_M";
172 
173  ylabel[8] = "RB2out_B";
174  ylabel[9] = "RB2out_F";
175  ylabel[10] = "RB3-_B";
176  ylabel[11] = "RB3-_F";
177  ylabel[12] = "RB3+_B";
178  ylabel[13] = "RB3+_F";
179  ylabel[14] = "RB4,-_B";
180  ylabel[15] = "RB4,-_F";
181  ylabel[16] = "RB4+_B";
182  ylabel[17] = "RB4+_F";
183  ylabel[18] = "RB4--_B";
184  ylabel[19] = "RB4--_F";
185  ylabel[20] = "RB4++_B";
186  ylabel[21] = "RB4++_F";
187  }else{
188  ylabel[1] = "RB1in";
189  ylabel[2] = "";
190  ylabel[3] = "RB1out";
191  ylabel[4] = "";
192  ylabel[5] = "RB2in";
193  ylabel[6] = "";
194 
195  ylabel[7] = "";
196  ylabel[0] = "";
197 
198  ylabel[8] = "RB2out";
199  ylabel[9] = "";
200  ylabel[10] = "RB3-";
201  ylabel[11] = "";
202  ylabel[12] = "RB3+";
203  ylabel[13] = "";
204  ylabel[14] = "RB4,-";
205  ylabel[15] = "";
206  ylabel[16] = "RB4+";
207  ylabel[17] = "";
208  ylabel[18] = "RB4--";
209  ylabel[19] = "";
210  ylabel[20] = "RB4++";
211  ylabel[21] = "";
212  }
213 
214 
215 
216 
217 
218  }
219 
220 
221  void doEndcapLabeling(bool useRollInfo){
222 
223  std::string rolls[3];
224  rolls[0]="A";
225  rolls[1]="B";
226  rolls[2]="C";
227 
228  endcapYLabels_.clear();
229  std::stringstream myLabel;
230 
231  for(int ring = 1 ; ring <=3; ring ++){
232  for(int ch = 1; ch<=6; ch++){
233  for(int r=0; r<3; r++){
234  myLabel.str("");
235  myLabel<<"R"<<ring<<"_C"<<ch<<"_"<<rolls[r];
236  endcapYLabels_.push_back(myLabel.str());
237  }
238  }
239  }
240  }
241 
243 
244  return ylabel[i];
245 
246  }
247 
248  //use only with RollvsSector MEs
250  //before do some checks
251  if (!myMe) return;
253 
254  std::stringstream xLabel;
255 
256  for(int x = 1; x<= myMe->getNbinsX(); x++){
257  xLabel.str("");
258  xLabel<<"Sec"<<x;
259  myMe->setBinLabel(x, xLabel.str(), 1);
260  }
261  }
262 
263  //use only with RingvsSegment MEs
265  //before do some checks
266  if (!myMe) return;
268 
269  std::stringstream xLabel;
270 
271  myMe->setAxisTitle("Segments", 1);
272 
273  for(int x = 1; x<= myMe->getNbinsX(); x++){
274  xLabel.str("");
275  xLabel<<x;
276  myMe->setBinLabel(x, xLabel.str(), 1);
277  }
278 
279  }
280 
281 
282  //use only with RollvsSector MEs
283  void labelYAxisRoll(MonitorElement * myMe, int region, int ring, bool useRollInfo){
284 
285  //before do some checks
286  if (!myMe) return;
288 
289  //set bin labels
290  if(region == 0){
291 
292  //initialize label vector
293  this->dolabeling(useRollInfo);
294  if(ring == -2 || ring == 2) ylabel[7]=ylabel[0];
295 
296  for(int y = 1; y<= myMe->getNbinsY() && y<22; y++)
297  myMe->setBinLabel(y, ylabel[y], 2);
298 
299  }else{//Endcap
300 
301  this->doEndcapLabeling(useRollInfo);
302 
303  for(int y = 1; y<= myMe->getNbinsY() && y<(int)endcapYLabels_.size(); y++)
304  myMe->setBinLabel(y, endcapYLabels_[y], 2);
305 
306  }
307  }
308 
309 
310  //use only with RingvsSegment MEs
311  void labelYAxisRing(MonitorElement * myMe, int numberOfRings, bool useRollInfo){
312 
313  //before do some checks
314  if (!myMe) return;
315  std::string labels[9];
316  if(useRollInfo){
317  labels[0]= "C";
318  labels[1]= "Ring1 B";
319  labels[2]= "A";
320  labels[3]= "C";
321  labels[4]= "Ring2 B";
322  labels[5]= "A";
323  labels[6]= "C";
324  labels[7]= "Ring3 B";
325  labels[8]= "A";
326  }else{
327  labels[0]= "";
328  labels[1]= "Ring1";
329  labels[2]= "";
330  labels[3]= "";
331  labels[4]= "Ring2";
332  labels[5]= "";
333  labels[6]= "";
334  labels[7]= "Ring3";
335  labels[8]= "";
336 
337  }
338  int startBin ;
339  (numberOfRings == 2 ? startBin = 3: startBin = 0);
340 
341  //set bin labels
343  for(int y =1 ;y<= myMe->getNbinsY() && y<=9; y++ ){
344  myMe->setBinLabel(y,labels[y-1+startBin],2);
345 
346  }
347  }
348 
349 
350 
351  int detId2ChamberNr(const RPCDetId & _id){
352  if(_id.region()==0){//Barrel
353  if( _id.station() ==1) {// Station1
354  if(_id.layer() ==1) {
355 
356  ch=1; //RB1in
357 
358  } else {
359  ch=2; //RB1out
360  }
361 
362  }else if (_id.station()==2) {//Station 2
363  if(_id.layer()==1) {
364 
365  ch=3;//RB2in
366  }else{
367 
368  ch=4; //RB2out
369  }
370  }else if(_id.station()==3){//Station 3
371  if(_id.subsector()==1){
372  ch=5; //RB3+
373  } else {
374 
375  ch=6; //RB3-
376  }
377  } else if(_id.station()==4) {//Station 4
378  if (_id.sector()== 4) {
379  if ( _id.subsector()==1){
380 
381  ch=7; //RB4-
382 
383  }else if (_id.subsector()==2){
384  ch=8; //RB4+
385  }else if ( _id.subsector()==3) {
386  ch=9; //RB4--
387  }else if ( _id.subsector()==4){
388  ch=10; //RB4++
389  }
390  } else {
391  if(_id.subsector()==1) ch= 7; //RB4-
392  else ch= 8; //RB4+
393  }
394  }
395  }else{//Endcap
396  }
397  return ch;
398  }
399 
400 
401 
402 
404  if(_id.region()==0){//Barrel
405  if( _id.station() ==1) {// Station1
406  if(_id.layer() ==1) {
407 
408  ChLabel="RB1in";
409 
410  } else {
411  ChLabel="RB1out";
412  }
413 
414  }else if (_id.station()==2) {//Station 2
415  if(_id.layer()==1) {
416 
417  ChLabel="RB2in";
418  }else{
419 
420  ChLabel="RB2out";
421  }
422  }else if(_id.station()==3){//Station 3
423  if(_id.subsector()==1){
424  ChLabel="RB3+";
425  } else {
426 
427  ChLabel="RB3-";
428  }
429  } else if(_id.station()==4) {//Station 4
430  if (_id.sector()== 4) {
431  if ( _id.subsector()==1){
432 
433  ChLabel="RB4-";
434 
435  }else if (_id.subsector()==2){
436  ChLabel="RB4+";
437  }else if ( _id.subsector()==3) {
438  ChLabel="RB4--";
439  }else if ( _id.subsector()==4){
440  ChLabel="RB4++";
441  }
442  } else {
443  if(_id.subsector()==1) ChLabel="RB4-";
444  else ChLabel="RB4-";
445  }
446  }
447  }else{//Endcap
448  }
449  return ChLabel;
450  }
451 
452  private:
453  int _cnr;
454  int ch;
455  std::vector<std::string> endcapYLabels_;
457  std::vector<int> Wvector2;
458  std::vector<int> Wvector1;
460  };
461 }
462 
463 #endif
std::string detId2ChamberLabel(const RPCDetId &_id)
Definition: utils.h:403
Definition: utils.h:12
int detId2ChamberNr(const RPCDetId &_id)
Definition: utils.h:351
TH1 * getTH1() const
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
void labelXAxisSegment(MonitorElement *myMe)
Definition: utils.h:264
void labelYAxisRoll(MonitorElement *myMe, int region, int ring, bool useRollInfo)
Definition: utils.h:283
std::string YLabel(int i)
Definition: utils.h:242
std::vector< int > Wvector1
Definition: utils.h:458
void labelYAxisRing(MonitorElement *myMe, int numberOfRings, bool useRollInfo)
Definition: utils.h:311
int roll() const
Definition: RPCDetId.h:120
int ring() const
Definition: RPCDetId.h:72
std::vector< std::string > endcapYLabels_
Definition: utils.h:455
std::vector< int > SectorStrips2()
Definition: utils.h:151
std::vector< int > Wvector2
Definition: utils.h:457
void dolabeling(bool useRollInfo)
Definition: utils.h:160
int _cnr
Definition: utils.h:453
static void setNoAlphanumeric(MonitorElement *myMe)
Definition: utils.h:18
RPCMeFLag
Definition: utils.h:14
void labelXAxisSector(MonitorElement *myMe)
Definition: utils.h:249
void fillvect()
Definition: utils.h:120
int layer() const
Definition: RPCDetId.h:108
std::vector< int > SectorStrips1()
Definition: utils.h:155
int detId2RollNr(const RPCDetId &_id)
Definition: utils.h:31
int getNbinsY() const
get # of bins in Y-axis
int sector() const
Sector id: the group of chambers at same phi (and increasing r)
Definition: RPCDetId.h:102
Definition: utils.py:1
int subsector() const
SubSector id : some sectors are divided along the phi direction in subsectors (from 1 to 4 in Barrel...
Definition: RPCDetId.h:114
int getNbinsX() const
get # of bins in X-axis
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
std::string ChLabel
Definition: utils.h:456
void doEndcapLabeling(bool useRollInfo)
Definition: utils.h:221
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:63
int station() const
Definition: RPCDetId.h:96