Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:14:39

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 /** Brief Extract from the DetId the subdetector type.
0008  * Return an integer which is associated to the subdetector type. The integer
0009  * coding for phase0/phase1 geometry follows:
0010  *
0011  *  3 - TIB
0012  *  4 - TID
0013  *  5 - TOB
0014  *  6 - TEC
0015  */
0016 int APVGain::subdetectorId(uint32_t det_id) { return DetId(det_id).subdetId(); };
0017 
0018 /** Brief Extract from a char * the subdetector type.
0019  * Return an integer whioch is associated to the subdetector type. The integer
0020  * coding follows:
0021  *
0022  * 3 - TIB
0023  * 4 - TID
0024  * 5 - TOB
0025  * 6 - TEC
0026  *
0027  * The char * string is expected to have a 3 char descriptor of the subdetector
0028  * type in front.
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 /** Brief Extract the subdetector side from the Det Id
0044  * Return and integer whose coding is
0045  *   0 - no side description can be applied
0046  *   1 - for negative side
0047  *   2 - for positive side
0048  */
0049 int APVGain::subdetectorSide(uint32_t det_id, const TrackerTopology* topo) { return topo->side(det_id); }
0050 
0051 /** Brief Extract the subdetector side from a char * descriptor
0052  * Return and integer whose coding is
0053  *   0 - no side description can be applied
0054  *   1 - for negative side
0055  *   2 - for positive side
0056  *
0057  *   The char * descriptor is expected to have either "minus" or "plus"
0058  *   string to specify the sign. If no sign spec is found 0 is returned.
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 /** Brief Extract the sensor thickness from the Det Id
0071  * Return and integer whose coding is
0072  *   0 - no thickness can be determined
0073  *   1 - for thin sensors
0074  *   2 - for thick sensors
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;  // so it is TOB (thick)
0081     }
0082     if (siStripDetId.moduleGeometry() == SiStripModuleGeometry::W5 ||
0083         siStripDetId.moduleGeometry() == SiStripModuleGeometry::W6 ||
0084         siStripDetId.moduleGeometry() == SiStripModuleGeometry::W7) {
0085       return 2;  // so it is TEC ring 5-7 (thick)
0086     }
0087     return 1;  // so it is TEC ring 1-4 or TIB or TID (thin)
0088   } else {
0089     return 0;
0090   }
0091 }
0092 
0093 /** Brief Extract the thickness from a char * descriptor
0094  * Return and integer whose coding is
0095  *   0 - no thicnkness can be determined
0096  *   1 - for thin sensors
0097  *   2 - for thick sensors
0098  *
0099  *   The char * descriptor is expected to have either "thin" or "thick"
0100  *   string to specify the thickness. If no sign spec is found 0 is returned.
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 /** Brief Extract the detector plane position from a DetId.
0113  * Return an integer that represent the detector plane where the module sits.
0114  * For the barrel detectors (TIB and TOB) the detector plane is the layer, e.g.
0115  * ranging from 1 to 4 in the TIB and from 1 to 6 in the TOB. For the endcap 
0116  * detectors the detector plane is the wheel number with a sign in front to 
0117  * tell in which side the wheel is sitting.
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 /** Brief Extract from a char * the subdetector type.
0134  * Return an integer whioch is the detector plane where the module sits.
0135  * The char * string is expected to have the subdetector plane put at its
0136  * end after an "_" char.
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 /** Brief Fetch the Monitor Element corresponding to a DetId.
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 /** Brief Fetch the Monitor Element index corresponding to a DetId.
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   // total number of measurement layers/wheels in the Strips Tracker
0221   // 4(TIB) + 6(TOB) + 3(TID+) + 3(TID-) + 9(TEC+) + 9(TEC-)
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     // Names of monitoring histogram for TIB layers
0236     constexpr int TIBlayers = 4;  //number of TIB layers.
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     // Names of monitoring histogram for TOB layers
0244     constexpr int TOBlayers = 6;  //number of TOB layers
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     // Names of monitoring histogram for TID wheels
0252     constexpr int TIDwheels = 3;  //number of TID wheels
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     // Names of monitoring histogram for TEC wheels
0265     constexpr int TECwheels = 9;  //number of TEC wheels
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 }