File indexing completed on 2024-04-06 11:59:42
0001 #include "CalibTracker/SiStripChannelGain/interface/APVGainHelpers.h"
0002 #include "DataFormats/DetId/interface/DetId.h"
0003
0004 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0005 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 int APVGain::subdetectorId(uint32_t det_id) { return DetId(det_id).subdetId(); };
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 int APVGain::subdetectorId(const std::string& tag) {
0031 std::string d = tag.substr(0, 3);
0032 if (d == "TIB")
0033 return 3;
0034 if (d == "TID")
0035 return 4;
0036 if (d == "TOB")
0037 return 5;
0038 if (d == "TEC")
0039 return 6;
0040 return 0;
0041 };
0042
0043
0044
0045
0046
0047
0048
0049 int APVGain::subdetectorSide(uint32_t det_id, const TrackerTopology* topo) { return topo->side(det_id); }
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060 int APVGain::subdetectorSide(const std::string& tag) {
0061 std::size_t m = tag.find("minus");
0062 std::size_t p = tag.find("plus");
0063 if (m != std::string::npos)
0064 return 1;
0065 if (p != std::string::npos)
0066 return 2;
0067 return 0;
0068 }
0069
0070
0071
0072
0073
0074
0075
0076 int APVGain::thickness(uint32_t det_id) {
0077 if (APVGain::subdetectorId(det_id) >= SiStripDetId::TIB) {
0078 SiStripDetId siStripDetId(det_id);
0079 if (siStripDetId.subdetId() == SiStripDetId::TOB) {
0080 return 2;
0081 }
0082 if (siStripDetId.moduleGeometry() == SiStripModuleGeometry::W5 ||
0083 siStripDetId.moduleGeometry() == SiStripModuleGeometry::W6 ||
0084 siStripDetId.moduleGeometry() == SiStripModuleGeometry::W7) {
0085 return 2;
0086 }
0087 return 1;
0088 } else {
0089 return 0;
0090 }
0091 }
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102 int APVGain::thickness(const std::string& tag) {
0103 std::size_t thin = tag.find("thin");
0104 std::size_t thick = tag.find("thick");
0105 if (thin != std::string::npos)
0106 return 1;
0107 if (thick != std::string::npos)
0108 return 2;
0109 return 0;
0110 }
0111
0112
0113
0114
0115
0116
0117
0118
0119 int APVGain::subdetectorPlane(uint32_t det_id, const TrackerTopology* topo) {
0120 if (topo) {
0121 if (APVGain::subdetectorId(det_id) == StripSubdetector::TIB)
0122 return topo->tibLayer(det_id);
0123 else if (APVGain::subdetectorId(det_id) == StripSubdetector::TID)
0124 return (2 * topo->tidSide(det_id) - 3) * topo->tidWheel(det_id);
0125 else if (APVGain::subdetectorId(det_id) == StripSubdetector::TOB)
0126 return topo->tobLayer(det_id);
0127 else if (APVGain::subdetectorId(det_id) == StripSubdetector::TEC)
0128 return (2 * topo->tecSide(det_id) - 3) * topo->tecWheel(det_id);
0129 }
0130 return 0;
0131 };
0132
0133
0134
0135
0136
0137
0138 int APVGain::subdetectorPlane(const std::string& tag) {
0139 std::size_t p = (tag.find("layer") != std::string::npos) ? tag.find("layer") : tag.find("wheel");
0140 if (p != std::string::npos) {
0141 std::size_t start = tag.find('_', p + 1) + 1;
0142 std::size_t stop = tag.find('_', start);
0143 std::string plane = tag.substr(start, stop - start);
0144 return atoi(plane.c_str());
0145 }
0146 return 0;
0147 };
0148
0149
0150
0151 std::vector<APVGain::MonitorElement*> APVGain::FetchMonitor(std::vector<APVGain::APVmon> histos,
0152 uint32_t det_id,
0153 const TrackerTopology* topo) {
0154 std::vector<MonitorElement*> found = std::vector<MonitorElement*>();
0155 int sThick = APVGain::thickness(det_id);
0156 int sId = APVGain::subdetectorId(det_id);
0157 int sPlane = APVGain::subdetectorPlane(det_id, topo);
0158 int sSide = APVGain::subdetectorSide(det_id, topo);
0159 auto it = histos.begin();
0160
0161 LogDebug("APVGainHelpers") << "sId: " << sId << " sPlane: " << sPlane << " sSide: " << sSide << std::endl;
0162
0163 while (it != histos.end()) {
0164 std::string tag = (*it).getMonitor()->getName();
0165 int subdetectorThickness = (*it).getThickness();
0166 int subdetectorId = (*it).getSubdetectorId();
0167 int subdetectorSide = (*it).getSubdetectorSide();
0168 int subdetectorPlane = (*it).getSubdetectorPlane();
0169
0170 bool match = (subdetectorId == 0 || subdetectorId == sId) &&
0171 (subdetectorPlane == 0 || subdetectorPlane == sPlane) &&
0172 (subdetectorSide == 0 || subdetectorSide == sSide) &&
0173 (subdetectorThickness == 0 || subdetectorThickness == sThick);
0174
0175 if (match) {
0176 found.emplace_back((*it).getMonitor());
0177 LogDebug("APVGainHelpers") << det_id << " found: " << tag << std::endl;
0178 (*it).printAll();
0179 }
0180 it++;
0181 }
0182 return found;
0183 }
0184
0185
0186
0187 std::vector<unsigned int> APVGain::FetchIndices(std::map<unsigned int, APVloc> theMap,
0188 uint32_t det_id,
0189 const TrackerTopology* topo) {
0190 std::vector<unsigned int> found_indices = std::vector<unsigned int>();
0191
0192 int sThick = APVGain::thickness(det_id);
0193 int sId = APVGain::subdetectorId(det_id);
0194 int sPlane = APVGain::subdetectorPlane(det_id, topo);
0195 int sSide = APVGain::subdetectorSide(det_id, topo);
0196
0197 for (auto& element : theMap) {
0198 int subdetectorThickness = element.second.m_thickness;
0199 int subdetectorId = element.second.m_subdetectorId;
0200 int subdetectorSide = element.second.m_subdetectorSide;
0201 int subdetectorPlane = element.second.m_subdetectorPlane;
0202
0203 bool match = (subdetectorId == 0 || subdetectorId == sId) &&
0204 (subdetectorPlane == 0 || subdetectorPlane == sPlane) &&
0205 (subdetectorSide == 0 || subdetectorSide == sSide) &&
0206 (subdetectorThickness == 0 || subdetectorThickness == sThick);
0207
0208 if (match) {
0209 found_indices.push_back(element.first);
0210 }
0211 }
0212 return found_indices;
0213 }
0214
0215 std::vector<std::pair<std::string, std::string>> APVGain::monHnames(std::vector<std::string> VH,
0216 bool allPlanes,
0217 const char* tag) {
0218 std::vector<std::pair<std::string, std::string>> out;
0219
0220
0221
0222 constexpr int countOfPlanes = 34;
0223
0224 int re = (allPlanes) ? countOfPlanes + VH.size() : VH.size();
0225 out.reserve(re);
0226
0227 std::string Tag = tag;
0228 if (Tag.length())
0229 Tag = "__" + Tag;
0230
0231 std::string h_tag = "";
0232 std::string h_tit = "";
0233
0234 if (allPlanes) {
0235
0236 constexpr int TIBlayers = 4;
0237 for (int i = 1; i <= TIBlayers; i++) {
0238 h_tag = "TIB_layer_" + std::to_string(i) + Tag;
0239 h_tit = h_tag;
0240 std::replace(h_tit.begin(), h_tit.end(), '_', ' ');
0241 out.push_back(std::pair<std::string, std::string>(h_tag, h_tit));
0242 }
0243
0244 constexpr int TOBlayers = 6;
0245 for (int i = 1; i <= TOBlayers; i++) {
0246 h_tag = "TOB_layer_" + std::to_string(i) + Tag;
0247 h_tit = h_tag;
0248 std::replace(h_tit.begin(), h_tit.end(), '_', ' ');
0249 out.push_back(std::pair<std::string, std::string>(h_tag, h_tit));
0250 }
0251
0252 constexpr int TIDwheels = 3;
0253 for (int i = -TIDwheels; i <= TIDwheels; i++) {
0254 if (i == 0)
0255 continue;
0256 if (i < 0)
0257 h_tag = "TIDminus_wheel_" + std::to_string(i) + Tag;
0258 else
0259 h_tag = "TIDplus_wheel_" + std::to_string(i) + Tag;
0260 h_tit = h_tag;
0261 std::replace(h_tit.begin(), h_tit.end(), '_', ' ');
0262 out.push_back(std::pair<std::string, std::string>(h_tag, h_tit));
0263 }
0264
0265 constexpr int TECwheels = 9;
0266 for (int i = -TECwheels; i <= TECwheels; i++) {
0267 if (i == 0)
0268 continue;
0269 if (i < 0)
0270 h_tag = "TECminus_wheel_" + std::to_string(i) + Tag;
0271 else
0272 h_tag = "TECplus_wheel_" + std::to_string(i) + Tag;
0273 h_tit = h_tag;
0274 std::replace(h_tit.begin(), h_tit.end(), '_', ' ');
0275 out.push_back(std::pair<std::string, std::string>(h_tag, h_tit));
0276 }
0277 }
0278
0279 for (unsigned int i = 0; i < VH.size(); i++) {
0280 h_tag = VH[i] + Tag;
0281 h_tit = h_tag;
0282 std::replace(h_tit.begin(), h_tit.end(), '_', ' ');
0283 out.push_back(std::pair<std::string, std::string>(h_tag, h_tit));
0284 }
0285
0286 return out;
0287 }