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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
#include "CalibTracker/SiStripChannelGain/interface/APVGainHelpers.h"
#include "DataFormats/DetId/interface/DetId.h"
#include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
#include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
/** Brief Extract from the DetId the subdetector type.
* Return an integer which is associated to the subdetector type. The integer
* coding for phase0/phase1 geometry follows:
*
* 3 - TIB
* 4 - TID
* 5 - TOB
* 6 - TEC
*/
int APVGain::subdetectorId(uint32_t det_id) { return DetId(det_id).subdetId(); };
/** Brief Extract from a char * the subdetector type.
* Return an integer whioch is associated to the subdetector type. The integer
* coding follows:
*
* 3 - TIB
* 4 - TID
* 5 - TOB
* 6 - TEC
*
* The char * string is expected to have a 3 char descriptor of the subdetector
* type in front.
*/
int APVGain::subdetectorId(const std::string& tag) {
std::string d = tag.substr(0, 3);
if (d == "TIB")
return 3;
if (d == "TID")
return 4;
if (d == "TOB")
return 5;
if (d == "TEC")
return 6;
return 0;
};
/** Brief Extract the subdetector side from the Det Id
* Return and integer whose coding is
* 0 - no side description can be applied
* 1 - for negative side
* 2 - for positive side
*/
int APVGain::subdetectorSide(uint32_t det_id, const TrackerTopology* topo) { return topo->side(det_id); }
/** Brief Extract the subdetector side from a char * descriptor
* Return and integer whose coding is
* 0 - no side description can be applied
* 1 - for negative side
* 2 - for positive side
*
* The char * descriptor is expected to have either "minus" or "plus"
* string to specify the sign. If no sign spec is found 0 is returned.
*/
int APVGain::subdetectorSide(const std::string& tag) {
std::size_t m = tag.find("minus");
std::size_t p = tag.find("plus");
if (m != std::string::npos)
return 1;
if (p != std::string::npos)
return 2;
return 0;
}
/** Brief Extract the sensor thickness from the Det Id
* Return and integer whose coding is
* 0 - no thickness can be determined
* 1 - for thin sensors
* 2 - for thick sensors
*/
int APVGain::thickness(uint32_t det_id) {
if (APVGain::subdetectorId(det_id) >= SiStripDetId::TIB) {
SiStripDetId siStripDetId(det_id);
if (siStripDetId.subdetId() == SiStripDetId::TOB) {
return 2; // so it is TOB (thick)
}
if (siStripDetId.moduleGeometry() == SiStripModuleGeometry::W5 ||
siStripDetId.moduleGeometry() == SiStripModuleGeometry::W6 ||
siStripDetId.moduleGeometry() == SiStripModuleGeometry::W7) {
return 2; // so it is TEC ring 5-7 (thick)
}
return 1; // so it is TEC ring 1-4 or TIB or TID (thin)
} else {
return 0;
}
}
/** Brief Extract the thickness from a char * descriptor
* Return and integer whose coding is
* 0 - no thicnkness can be determined
* 1 - for thin sensors
* 2 - for thick sensors
*
* The char * descriptor is expected to have either "thin" or "thick"
* string to specify the thickness. If no sign spec is found 0 is returned.
*/
int APVGain::thickness(const std::string& tag) {
std::size_t thin = tag.find("thin");
std::size_t thick = tag.find("thick");
if (thin != std::string::npos)
return 1;
if (thick != std::string::npos)
return 2;
return 0;
}
/** Brief Extract the detector plane position from a DetId.
* Return an integer that represent the detector plane where the module sits.
* For the barrel detectors (TIB and TOB) the detector plane is the layer, e.g.
* ranging from 1 to 4 in the TIB and from 1 to 6 in the TOB. For the endcap
* detectors the detector plane is the wheel number with a sign in front to
* tell in which side the wheel is sitting.
*/
int APVGain::subdetectorPlane(uint32_t det_id, const TrackerTopology* topo) {
if (topo) {
if (APVGain::subdetectorId(det_id) == StripSubdetector::TIB)
return topo->tibLayer(det_id);
else if (APVGain::subdetectorId(det_id) == StripSubdetector::TID)
return (2 * topo->tidSide(det_id) - 3) * topo->tidWheel(det_id);
else if (APVGain::subdetectorId(det_id) == StripSubdetector::TOB)
return topo->tobLayer(det_id);
else if (APVGain::subdetectorId(det_id) == StripSubdetector::TEC)
return (2 * topo->tecSide(det_id) - 3) * topo->tecWheel(det_id);
}
return 0;
};
/** Brief Extract from a char * the subdetector type.
* Return an integer whioch is the detector plane where the module sits.
* The char * string is expected to have the subdetector plane put at its
* end after an "_" char.
*/
int APVGain::subdetectorPlane(const std::string& tag) {
std::size_t p = (tag.find("layer") != std::string::npos) ? tag.find("layer") : tag.find("wheel");
if (p != std::string::npos) {
std::size_t start = tag.find('_', p + 1) + 1;
std::size_t stop = tag.find('_', start);
std::string plane = tag.substr(start, stop - start);
return atoi(plane.c_str());
}
return 0;
};
/** Brief Fetch the Monitor Element corresponding to a DetId.
* */
std::vector<APVGain::MonitorElement*> APVGain::FetchMonitor(std::vector<APVGain::APVmon> histos,
uint32_t det_id,
const TrackerTopology* topo) {
std::vector<MonitorElement*> found = std::vector<MonitorElement*>();
int sThick = APVGain::thickness(det_id);
int sId = APVGain::subdetectorId(det_id);
int sPlane = APVGain::subdetectorPlane(det_id, topo);
int sSide = APVGain::subdetectorSide(det_id, topo);
auto it = histos.begin();
LogDebug("APVGainHelpers") << "sId: " << sId << " sPlane: " << sPlane << " sSide: " << sSide << std::endl;
while (it != histos.end()) {
std::string tag = (*it).getMonitor()->getName();
int subdetectorThickness = (*it).getThickness();
int subdetectorId = (*it).getSubdetectorId();
int subdetectorSide = (*it).getSubdetectorSide();
int subdetectorPlane = (*it).getSubdetectorPlane();
bool match = (subdetectorId == 0 || subdetectorId == sId) &&
(subdetectorPlane == 0 || subdetectorPlane == sPlane) &&
(subdetectorSide == 0 || subdetectorSide == sSide) &&
(subdetectorThickness == 0 || subdetectorThickness == sThick);
if (match) {
found.emplace_back((*it).getMonitor());
LogDebug("APVGainHelpers") << det_id << " found: " << tag << std::endl;
(*it).printAll();
}
it++;
}
return found;
}
/** Brief Fetch the Monitor Element index corresponding to a DetId.
* */
std::vector<unsigned int> APVGain::FetchIndices(std::map<unsigned int, APVloc> theMap,
uint32_t det_id,
const TrackerTopology* topo) {
std::vector<unsigned int> found_indices = std::vector<unsigned int>();
int sThick = APVGain::thickness(det_id);
int sId = APVGain::subdetectorId(det_id);
int sPlane = APVGain::subdetectorPlane(det_id, topo);
int sSide = APVGain::subdetectorSide(det_id, topo);
for (auto& element : theMap) {
int subdetectorThickness = element.second.m_thickness;
int subdetectorId = element.second.m_subdetectorId;
int subdetectorSide = element.second.m_subdetectorSide;
int subdetectorPlane = element.second.m_subdetectorPlane;
bool match = (subdetectorId == 0 || subdetectorId == sId) &&
(subdetectorPlane == 0 || subdetectorPlane == sPlane) &&
(subdetectorSide == 0 || subdetectorSide == sSide) &&
(subdetectorThickness == 0 || subdetectorThickness == sThick);
if (match) {
found_indices.push_back(element.first);
}
}
return found_indices;
}
std::vector<std::pair<std::string, std::string>> APVGain::monHnames(std::vector<std::string> VH,
bool allPlanes,
const char* tag) {
std::vector<std::pair<std::string, std::string>> out;
// total number of measurement layers/wheels in the Strips Tracker
// 4(TIB) + 6(TOB) + 3(TID+) + 3(TID-) + 9(TEC+) + 9(TEC-)
constexpr int countOfPlanes = 34;
int re = (allPlanes) ? countOfPlanes + VH.size() : VH.size();
out.reserve(re);
std::string Tag = tag;
if (!Tag.empty())
Tag = "__" + Tag;
std::string h_tag = "";
std::string h_tit = "";
if (allPlanes) {
// Names of monitoring histogram for TIB layers
constexpr int TIBlayers = 4; //number of TIB layers.
for (int i = 1; i <= TIBlayers; i++) {
h_tag = "TIB_layer_" + std::to_string(i) + Tag;
h_tit = h_tag;
std::replace(h_tit.begin(), h_tit.end(), '_', ' ');
out.push_back(std::pair<std::string, std::string>(h_tag, h_tit));
}
// Names of monitoring histogram for TOB layers
constexpr int TOBlayers = 6; //number of TOB layers
for (int i = 1; i <= TOBlayers; i++) {
h_tag = "TOB_layer_" + std::to_string(i) + Tag;
h_tit = h_tag;
std::replace(h_tit.begin(), h_tit.end(), '_', ' ');
out.push_back(std::pair<std::string, std::string>(h_tag, h_tit));
}
// Names of monitoring histogram for TID wheels
constexpr int TIDwheels = 3; //number of TID wheels
for (int i = -TIDwheels; i <= TIDwheels; i++) {
if (i == 0)
continue;
if (i < 0)
h_tag = "TIDminus_wheel_" + std::to_string(i) + Tag;
else
h_tag = "TIDplus_wheel_" + std::to_string(i) + Tag;
h_tit = h_tag;
std::replace(h_tit.begin(), h_tit.end(), '_', ' ');
out.push_back(std::pair<std::string, std::string>(h_tag, h_tit));
}
// Names of monitoring histogram for TEC wheels
constexpr int TECwheels = 9; //number of TEC wheels
for (int i = -TECwheels; i <= TECwheels; i++) {
if (i == 0)
continue;
if (i < 0)
h_tag = "TECminus_wheel_" + std::to_string(i) + Tag;
else
h_tag = "TECplus_wheel_" + std::to_string(i) + Tag;
h_tit = h_tag;
std::replace(h_tit.begin(), h_tit.end(), '_', ' ');
out.push_back(std::pair<std::string, std::string>(h_tag, h_tit));
}
}
for (unsigned int i = 0; i < VH.size(); i++) {
h_tag = VH[i] + Tag;
h_tit = h_tag;
std::replace(h_tit.begin(), h_tit.end(), '_', ' ');
out.push_back(std::pair<std::string, std::string>(h_tag, h_tit));
}
return out;
}
|