1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
// -*- C++ -*-
//
// Package: src
// Class : RPCCompDetId
//
// Implementation:
// [Notes on implementation]
//
// Author: Marcello Maggi
// Created: Wed Nov 2 12:09:10 CET 2011
#include <iostream>
#include <sstream>
#include <iomanip>
#include "DataFormats/MuonDetId/interface/RPCCompDetId.h"
#include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
RPCCompDetId::RPCCompDetId() : DetId(DetId::Muon, MuonSubdetId::RPC), _dbname(""), _type(0) {}
RPCCompDetId::RPCCompDetId(uint32_t id) : DetId(id), _dbname(""), _type(0) {
if (det() != DetId::Muon || subdetId() != MuonSubdetId::RPC) {
throw cms::Exception("InvalidDetId") << "RPCCompDetId ctor:"
<< " det: " << det() << " subdet: " << subdetId() << " is not a valid RPC id";
}
}
RPCCompDetId::RPCCompDetId(DetId id) : DetId(id), _dbname(""), _type(0) {
if (det() != DetId::Muon || subdetId() != MuonSubdetId::RPC) {
throw cms::Exception("InvalidDetId") << "RPCCompDetId ctor:"
<< " det: " << det() << " subdet: " << subdetId() << " is not a valid RPC id";
}
}
RPCCompDetId::RPCCompDetId(int region, int ring, int station, int sector, int layer, int subsector, int type)
: DetId(DetId::Muon, MuonSubdetId::RPC), _dbname(""), _type(type) {
this->init(region, ring, station, sector, layer, subsector);
}
RPCCompDetId::RPCCompDetId(const std::string& name, int type)
: DetId(DetId::Muon, MuonSubdetId::RPC), _dbname(name), _type(type) {
this->init();
}
bool RPCCompDetId::operator<(const RPCCompDetId& r) const { return this->dbname() < r.dbname(); }
int RPCCompDetId::region() const { return int((id_ >> RegionStartBit_) & RegionMask_) + allRegionId; }
int RPCCompDetId::ring() const { return int((id_ >> RingStartBit_) & RingMask_) + allRingId; }
int RPCCompDetId::wheel() const {
int w = allRingId;
if (this->region() == 0)
w = this->ring();
return w;
}
int RPCCompDetId::station() const { return int((id_ >> StationStartBit_) & StationMask_) + allStationId; }
int RPCCompDetId::disk() const {
int d = allStationId;
if (this->region() != 0)
d = this->station();
return d;
}
int RPCCompDetId::sector() const { return int((id_ >> SectorStartBit_) & SectorMask_) + allSectorId; }
int RPCCompDetId::layer() const { return int((id_ >> LayerStartBit_) & LayerMask_) + allLayerId; }
int RPCCompDetId::subsector() const { return int((id_ >> SubSectorStartBit_) & SubSectorMask_) + allSubSectorId; }
int RPCCompDetId::type() const { return _type; }
std::string RPCCompDetId::dbname() const {
std::string a = _dbname;
if (a.empty()) {
if (this->type() == 0) {
a = this->gasDBname();
}
}
return a;
}
void RPCCompDetId::init(int region, int ring, int station, int sector, int layer, int subsector) {
int maxRing = maxRingForwardId;
if (!region) {
maxRing = maxRingBarrelId;
}
if (region < allRegionId || region > maxRegionId || ring < allRingId || ring > maxRing || station < allStationId ||
station > maxStationId || sector < allSectorId || sector > maxSectorId || layer < allLayerId ||
layer > maxLayerId || subsector < allSubSectorId || subsector > maxSubSectorId) {
throw cms::Exception("InvalidDetId") << "RPCDetId ctor:"
<< " Invalid parameters: "
<< " region " << region << " ring " << ring << " station " << station
<< " sector " << sector << " layer " << layer << " subsector " << subsector
<< std::endl;
}
int regionInBits = region - allRegionId;
int ringInBits = ring - allRingId;
int stationInBits = station - allStationId;
int sectorInBits = sector - allSectorId;
int layerInBits = layer - allLayerId;
int subSectorInBits = subsector - allSubSectorId;
id_ |= (regionInBits & RegionMask_) << RegionStartBit_ | (ringInBits & RingMask_) << RingStartBit_ |
(stationInBits & StationMask_) << StationStartBit_ | (sectorInBits & SectorMask_) << SectorStartBit_ |
(layerInBits & LayerMask_) << LayerStartBit_ | (subSectorInBits & SubSectorMask_) << SubSectorStartBit_;
}
void RPCCompDetId::init() {
if (this->type() == 0) {
this->initGas();
}
}
void RPCCompDetId::initGas() {
std::string buf(this->dbname());
// check if the name contains the dcs namespace
if (buf.find(':') != buf.npos) {
buf = buf.substr(buf.find(':') + 1, buf.npos);
}
_dbname = buf;
// Check if endcap o barrel
int region = 0;
if (buf.substr(0, 1) == "W") {
region = 0;
} else if (buf.substr(0, 2) == "EP") {
region = 1;
} else if (buf.substr(0, 2) == "EM") {
region = -1;
} else {
throw cms::Exception("InvalidDBName")
<< " RPCCompDetId: " << this->dbname() << " is not a valid DB Name for RPCCompDetId"
<< " det: " << det() << " subdet: " << subdetId();
}
int ring = allRingId;
int station = allStationId;
int sector = allSectorId;
int layer = allLayerId;
int subsector = allSubSectorId;
//Barrel
if (region == 0) {
// Extract the Wheel (named ring)
{
std::stringstream os;
os << buf.substr(2, 1);
os >> ring;
if (buf.substr(1, 1) == "M") {
ring *= -1;
}
}
//Extract the station
{
std::stringstream os;
os << buf.substr(buf.find("RB") + 2, 1);
os >> station;
}
//Extract the sector
{
std::stringstream os;
os << buf.substr(buf.find('S') + 1, 2);
os >> sector;
}
//Extract subsector of sectors 4 and 10
{
if (buf.find("4L") != buf.npos)
subsector = 1;
if (buf.find("4R") != buf.npos)
subsector = 2;
}
} else {
// Extract the Ring
{
std::stringstream os;
os << buf.substr(buf.find("_R0") + 3, 1);
os >> ring;
}
//Extract the disk (named station)
{
std::stringstream os;
os << buf.substr(2, 1);
os >> station;
}
//Extract the sector or chamber
{
std::stringstream os;
os << buf.substr(buf.find("_C") + 2, 2);
os >> sector;
}
//Extract layer
{
if (buf.find("UP") != buf.npos)
layer = 1;
if (buf.find("DW") != buf.npos)
layer = 2;
}
}
this->init(region, ring, station, sector, layer, subsector);
}
std::string RPCCompDetId::gasDBname() const {
std::stringstream os;
if (this->region() == 0) {
// Barrel
std::string wsign = "P";
if (this->wheel() < 0)
wsign = "M";
std::string lr = "";
if (this->subsector() == 1)
lr = "L";
if (this->subsector() == 2)
lr = "R";
os << "W" << wsign << abs(this->wheel()) << "_S" << std::setw(2) << std::setfill('0') << this->sector() << "_RB"
<< this->station() << lr;
} else {
// Endcap
std::string esign = "P";
if (this->region() < 0)
esign = "M";
os << "E" << esign << this->disk();
if (this->disk() == 1) {
os << "_R" << std::setw(2) << std::setfill('0') << this->ring() << "_C" << std::setw(2) << std::setfill('0')
<< this->sector() << "_C" << std::setw(2) << std::setfill('0') << this->sector() + 5;
} else {
os << "_R" << std::setw(2) << std::setfill('0') << this->ring() << "_R" << std::setw(2) << std::setfill('0')
<< this->ring() + 1 << "_C" << std::setw(2) << std::setfill('0') << this->sector() << "_C" << std::setw(2)
<< std::setfill('0') << this->sector() + 2;
}
std::string lay = "";
if (this->layer() == 1)
lay = "UP";
else if (this->layer() == 2)
lay = "DW";
os << "_" << lay;
}
return os.str();
}
std::ostream& operator<<(std::ostream& os, const RPCCompDetId& id) {
os << id.dbname();
return os;
}
|