Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-05-15 02:27:51

0001 // -*- C++ -*-
0002 //
0003 // Package:     SiStripCommon
0004 // Class  :     SiStripHistoId
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  dkcira
0010 //         Created:  Wed Feb 22 16:07:58 CET 2006
0011 //
0012 
0013 #include <iostream>
0014 #include <sstream>
0015 #include <cstdio>
0016 #include <fmt/format.h>
0017 
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019 #include "DQM/SiStripCommon/interface/SiStripHistoId.h"
0020 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0021 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0022 
0023 SiStripHistoId::SiStripHistoId() {}
0024 
0025 SiStripHistoId::~SiStripHistoId() {}
0026 
0027 std::string SiStripHistoId::createHistoId(std::string description, std::string id_type, uint32_t component_id) {
0028   size_t pos1 = description.find("__", 0);  // check if std::string 'description' contains by mistake the 'separator1'
0029   size_t pos2 = description.find("__", 0);  // check if std::string 'description' contains by mistake the 'separator2'
0030   std::string local_histo_id;
0031   std::ostringstream compid;
0032   compid << component_id;  // use std::ostringstream for casting integer to std::string
0033 
0034   if (pos1 == std::string::npos && pos2 == std::string::npos) {      // ok, not found either separator
0035     if (id_type == "fed" || id_type == "det" || id_type == "fec") {  // ok! is one of the accepted id_type-s
0036       local_histo_id = description + "__" + id_type + "__" + compid.str();
0037     } else {
0038       local_histo_id = description + "__dummy__" + compid.str();
0039       edm::LogError("SiStripHistoId") << " SiStripHistoId::WrongInput "
0040                                       << " no such type of component accepted: " << id_type
0041                                       << " id_type can be: fed, det, or fec.";
0042     }
0043   } else {
0044     local_histo_id = description + "_dummy___" + id_type + "__" + compid.str();
0045     edm::LogError("SiStripHistoId") << " SiStripHistoId::WrongInput "
0046                                     << " histogram description cannot contain: __ or: __"
0047                                     << " histogram description = " << description;
0048   }
0049   return local_histo_id;
0050 }
0051 
0052 std::string SiStripHistoId::createHistoLayer(std::string description,
0053                                              std::string id_type,
0054                                              std::string path,
0055                                              std::string flag) {
0056   size_t pos1 = description.find("__", 0);  // check if std::string 'description' contains by mistake the 'separator1'
0057   size_t pos2 = description.find("__", 0);  // check if std::string 'description' contains by mistake the 'separator2'
0058   std::string local_histo_id;
0059   if (pos1 == std::string::npos && pos2 == std::string::npos) {  // ok, not found either separator
0060     if (id_type == "fed" || id_type == "det" || id_type == "fec" || id_type == "layer" ||
0061         id_type == "ring") {  // ok! is one of the accepted id_type-s
0062       if (!flag.empty())
0063         local_histo_id = description + "__" + flag + "__" + path;
0064       else
0065         local_histo_id = description + "__" + path;
0066       LogTrace("SiStripHistoId") << "Local_histo_ID " << local_histo_id << std::endl;
0067     } else {
0068       local_histo_id = description + "___dummy___" + path;
0069       edm::LogError("SiStripHistoId") << " SiStripHistoId::WrongInput "
0070                                       << " no such type of component accepted: " << id_type
0071                                       << " id_type can be: fed, det, fec or layer ";
0072     }
0073   } else {
0074     local_histo_id = description + "_dummy___" + path;
0075     edm::LogWarning("SiStripHistoId") << " SiStripHistoId::WrongInput "
0076                                       << " histogram description cannot contain: __ or: __"
0077                                       << " histogram description = " << description;
0078   }
0079   return local_histo_id;
0080 }
0081 
0082 // std::string SiStripHistoId::getSubdetid(uint32_t id, const TrackerTopology* tTopo, bool flag_ring, bool flag_thickness) {
0083 std::string SiStripHistoId::getSubdetid(uint32_t id, const TrackerTopology* tTopo, bool flag_ring) {
0084   StripSubdetector subdet(id);
0085 
0086   if (subdet.subdetId() == StripSubdetector::TIB) {
0087     // ---------------------------  TIB  --------------------------- //
0088     return "TIB__layer__" + std::to_string(tTopo->tibLayer(id));
0089   } else if (subdet.subdetId() == StripSubdetector::TID) {
0090     // ---------------------------  TID  --------------------------- //
0091     const char* side = (tTopo->tidSide(id) == 1) ? "MINUS" : "PLUS";
0092 
0093     if (flag_ring)
0094       return fmt::format("TID__{}__ring__{}", side, tTopo->tidRing(id));
0095     else
0096       return fmt::format("TID__{}__wheel__{}", side, tTopo->tidWheel(id));
0097   } else if (subdet.subdetId() == StripSubdetector::TOB) {
0098     // ---------------------------  TOB  --------------------------- //
0099     return "TOB__layer__" + std::to_string(tTopo->tobLayer(id));
0100   } else if (subdet.subdetId() == StripSubdetector::TEC) {
0101     // ---------------------------  TEC  --------------------------- //
0102     const char* side = (tTopo->tecSide(id) == 1) ? "MINUS" : "PLUS";
0103 
0104     if (flag_ring) {
0105       return fmt::format("TEC__{}__ring__{}", side, tTopo->tecRing(id));
0106     } else {
0107       /*
0108       if (flag_thickness) {
0109         uint32_t ring = tTopo->tecRing(id);
0110         std::string thickness = (ring >= 1 && ring <= 4) ? "__THIN" : "__THICK";
0111     return fmt::format("TEC__{}__wheel__{}{}", side, tTopo->tecWheel(id), thickness);
0112       } else
0113       */
0114       return fmt::format("TEC__{}__wheel__{}", side, tTopo->tecWheel(id));
0115     }
0116   } else {
0117     // ---------------------------  ???  --------------------------- //
0118     edm::LogError("SiStripTkDQM|WrongInput")
0119         << "no such subdetector type: " << subdet.subdetId() << " no folder set!" << std::endl;
0120     return "";  // Return an empty string on error
0121   }
0122 }
0123 
0124 uint32_t SiStripHistoId::getComponentId(std::string histoid) {
0125   uint32_t local_component_id;
0126   std::istringstream input(returnIdPart(histoid, 3));
0127   input >> local_component_id;  // use std::istringstream for casting from std::string to uint32_t
0128   return local_component_id;
0129 }
0130 
0131 std::string SiStripHistoId::getComponentType(std::string histoid) { return returnIdPart(histoid, 2); }
0132 
0133 std::string SiStripHistoId::returnIdPart(std::string histoid, uint32_t whichpart) {
0134   size_t length1 = histoid.find("__", 0);
0135   if (length1 == std::string::npos) {  // no separator1 found
0136     edm::LogWarning("SiStripTkDQM|UnregularInput") << "no regular histoid. Returning 0";
0137     return "0";
0138   }
0139   std::string part1 = histoid.substr(0, length1);  // part of 'histoid' up to 'separator1'
0140   if (whichpart == 1)
0141     return part1;
0142   std::string remain1 = histoid.substr(length1 + 2);  // rest of 'histoid' starting at end of 'separator1'
0143   size_t length2 = remain1.find("__", 0);
0144   if (length2 == std::string::npos) {  // no separator2 found
0145     edm::LogWarning("SiStripTkDQM|UnregularInput") << "no regular histoid. Returning 0";
0146     return "0";
0147   }
0148   std::string part2 = remain1.substr(0, length2);  // part of 'remain1' up to 'separator2'
0149   if (whichpart == 2)
0150     return part2;
0151   std::string part3 = remain1.substr(length2 + 2);  // rest of remain1 starting at end of 'separator2'
0152   if (whichpart == 3)
0153     return part3;
0154   edm::LogWarning("SiStripTkDQM|UnregularInput") << "no such whichpart=" << whichpart << " returning 0";
0155   return "0";
0156 }