Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-05 04:09:42

0001 #include "DQM/SiStripMonitorSummary/interface/SiStripBaseCondObjDQM.h"
0002 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0003 #include "DataFormats/TrackerCommon/interface/SiStripSubStructure.h"
0004 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0005 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
0006 
0007 #include "TCanvas.h"
0008 
0009 SiStripBaseCondObjDQM::SiStripBaseCondObjDQM(edm::RunNumber_t iRun,
0010                                              edm::ParameterSet const &hPSet,
0011                                              edm::ParameterSet const &fPSet,
0012                                              const TrackerTopology *tTopo)
0013     : hPSet_(hPSet), fPSet_(fPSet), tTopo_(tTopo), dqmStore_(edm::Service<DQMStore>().operator->()), runNumber_(iRun) {
0014   detInfo_ =
0015       SiStripDetInfoFileReader::read(edm::FileInPath(std::string(SiStripDetInfoFileReader::kDefaultFile)).fullPath());
0016 
0017   Mod_On_ = fPSet_.getParameter<bool>("Mod_On");
0018   HistoMaps_On_ = fPSet_.getParameter<bool>("HistoMaps_On");
0019   SummaryOnLayerLevel_On_ = fPSet_.getParameter<bool>("SummaryOnLayerLevel_On");
0020   SummaryOnStringLevel_On_ = fPSet_.getParameter<bool>("SummaryOnStringLevel_On");
0021 
0022   GrandSummary_On_ = fPSet_.getParameter<bool>("GrandSummary_On");
0023 
0024   CondObj_fillId_ = hPSet_.getParameter<std::string>("CondObj_fillId");
0025   CondObj_name_ = hPSet_.getParameter<std::string>("CondObj_name");
0026 
0027   // Warning message from wrong input:
0028   if (SummaryOnLayerLevel_On_ && SummaryOnStringLevel_On_) {
0029     edm::LogWarning("SiStripBaseCondObjDQM") << "[SiStripBaseCondObjDQM::SiStripBaseCondObjDQMs] PLEASE CHECK : "
0030                                                 "String and layer level options can not be activated together"
0031                                              << std::endl;
0032   }
0033 
0034   // The OR of the two conditions allow to switch on this feature for all the
0035   // components (if the FillConditions_PSet has the TkMap_On =true) or for
0036   // single MEs (if the PSet for a ME has the TkMap_On =true)
0037   if (fPSet_.getParameter<bool>("TkMap_On") || hPSet_.getParameter<bool>("TkMap_On"))
0038     bookTkMap(hPSet_.getParameter<std::string>("TkMapName"));
0039 
0040   minValue = hPSet_.getParameter<double>("minValue");
0041   maxValue = hPSet_.getParameter<double>("maxValue");
0042 }
0043 
0044 void SiStripBaseCondObjDQM::analysis(const edm::EventSetup &eSetup_) {
0045   if (checkChanged(eSetup_)) {
0046     getConditionObject(eSetup_);
0047 
0048     // The OR of the two conditions allows to switch on this feature for all the
0049     // components (if the FillConditions_PSet has the ActiveDetIds_On =true) or
0050     // for single MEs (if the PSet for a ME has the ActiveDetIds_On =true)
0051     if (fPSet_.getParameter<bool>("ActiveDetIds_On") || hPSet_.getParameter<bool>("ActiveDetIds_On"))
0052       getActiveDetIds(eSetup_);
0053     else
0054       activeDetIds = detInfo_.getAllDetIds();
0055 
0056     selectModules(activeDetIds);
0057 
0058     if (Mod_On_) {
0059       fillModMEs(activeDetIds);
0060     }
0061     if (SummaryOnLayerLevel_On_ || SummaryOnStringLevel_On_) {
0062       fillSummaryMEs(activeDetIds);
0063     }
0064 
0065     if (fPSet_.getParameter<bool>("TkMap_On") || hPSet_.getParameter<bool>("TkMap_On")) {
0066       std::string filename = hPSet_.getParameter<std::string>("TkMapName");
0067       if (!filename.empty()) {
0068         constexpr unsigned int kSLen = 128;
0069         char sRun[kSLen];
0070         snprintf(sRun, kSLen, "_Run_%d", runNumber_);
0071         filename.insert(filename.find('.'), sRun);
0072 
0073         saveTkMap(filename, minValue, maxValue);
0074       }
0075     }
0076   }
0077 }
0078 
0079 void SiStripBaseCondObjDQM::analysisOnDemand(const edm::EventSetup &eSetup_,
0080                                              std::string requestedSubDetector,
0081                                              uint32_t requestedSide,
0082                                              uint32_t requestedLayer) {
0083   getConditionObject(eSetup_);
0084   getActiveDetIds(eSetup_);
0085 
0086   std::vector<uint32_t> requestedDetIds_;
0087   requestedDetIds_.clear();
0088 
0089   if (requestedSubDetector == "TIB") {
0090     SiStripSubStructure::getTIBDetectors(activeDetIds, requestedDetIds_, tTopo_, requestedLayer, 0, 0, 0);
0091   } else if (requestedSubDetector == "TID") {
0092     SiStripSubStructure::getTIDDetectors(activeDetIds, requestedDetIds_, tTopo_, requestedSide, requestedLayer, 0, 0);
0093   } else if (requestedSubDetector == "TOB") {
0094     SiStripSubStructure::getTOBDetectors(activeDetIds, requestedDetIds_, tTopo_, requestedLayer, 0, 0);
0095   } else if (requestedSubDetector == "TEC") {
0096     SiStripSubStructure::getTECDetectors(
0097         activeDetIds, requestedDetIds_, tTopo_, requestedSide, requestedLayer, 0, 0, 0, 0);
0098   }
0099 
0100   analysisOnDemand(eSetup_, requestedDetIds_);
0101 }
0102 
0103 void SiStripBaseCondObjDQM::analysisOnDemand(const edm::EventSetup &eSetup_, uint32_t detIdOnDemand) {
0104   if (checkChanged(eSetup_)) {
0105     getConditionObject(eSetup_);
0106 
0107     std::vector<uint32_t> vdetIdsOnDemand_;
0108     vdetIdsOnDemand_.push_back(detIdOnDemand);  // fillModMEs needs a vector
0109 
0110     fillModMEs(vdetIdsOnDemand_);
0111   }
0112 }
0113 
0114 void SiStripBaseCondObjDQM::analysisOnDemand(const edm::EventSetup &eSetup_,
0115                                              const std::vector<uint32_t> &detIdsOnDemand) {
0116   if (checkChanged(eSetup_)) {
0117     getConditionObject(eSetup_);
0118     fillSummaryMEs(detIdsOnDemand);
0119   }
0120 }
0121 
0122 //#FIXME : very long method. please factorize it
0123 void SiStripBaseCondObjDQM::selectModules(std::vector<uint32_t> &detIds_) {
0124   edm::LogInfo("SiStripBaseCondObjDQM") << "[SiStripBaseCondObjDQM::selectModules] input detIds_: " << detIds_.size()
0125                                         << std::endl;
0126 
0127   if (fPSet_.getParameter<bool>("restrictModules")) {
0128     std::vector<DetIdSelector> included_subdetsels;
0129     std::vector<std::string> included_subdets =
0130         fPSet_.getParameter<std::vector<std::string>>("ModulesToBeIncluded_DetIdSelector");
0131     for (std::vector<std::string>::const_iterator wsdps = included_subdets.begin(); wsdps != included_subdets.end();
0132          ++wsdps) {
0133       included_subdetsels.push_back(DetIdSelector(*wsdps));
0134     }
0135 
0136     std::vector<uint32_t> modulesToBeIncluded;
0137     for (const auto detid : detIds_) {
0138       for (const auto &detidsel : included_subdetsels) {
0139         if (detidsel.isSelected(detid)) {
0140           modulesToBeIncluded.push_back(detid);
0141           break;
0142           //      std::cout << "detId: " << *detid << " is selected" <<
0143           // std::endl;
0144         }
0145       }
0146     }
0147 
0148     // -----
0149     // *** exclude modules ***
0150     std::vector<DetIdSelector> excluded_subdetsels;
0151     std::vector<std::string> excluded_subdets =
0152         fPSet_.getParameter<std::vector<std::string>>("ModulesToBeExcluded_DetIdSelector");
0153     excluded_subdetsels.reserve(excluded_subdets.size());
0154     for (const auto &wsdps : excluded_subdets) {
0155       excluded_subdetsels.push_back(DetIdSelector(wsdps));
0156     }
0157 
0158     std::vector<uint32_t> modulesToBeExcluded;
0159     for (const auto detid : detIds_) {
0160       for (const auto &detidsel : excluded_subdetsels) {
0161         if (detidsel.isSelected(detid)) {
0162           modulesToBeExcluded.push_back(detid);
0163           break;
0164         }
0165       }
0166     }
0167 
0168     ModulesToBeExcluded_ = fPSet_.getParameter<std::vector<unsigned int>>("ModulesToBeExcluded");
0169     ModulesToBeIncluded_ = fPSet_.getParameter<std::vector<unsigned int>>("ModulesToBeIncluded");
0170     SubDetectorsToBeExcluded_ = fPSet_.getParameter<std::vector<std::string>>("SubDetectorsToBeExcluded");
0171 
0172     // vectors to be sorted otherwise the intersection is non computed properly
0173 
0174     std::sort(ModulesToBeExcluded_.begin(), ModulesToBeExcluded_.end());
0175     std::sort(ModulesToBeIncluded_.begin(), ModulesToBeIncluded_.end());
0176 
0177     if (modulesToBeExcluded.empty() && modulesToBeIncluded.empty() && ModulesToBeExcluded_.empty() &&
0178         ModulesToBeIncluded_.empty())
0179       edm::LogWarning("SiStripBaseCondObjDQM") << "[SiStripBaseCondObjDQM::selectModules] PLEASE CHECK : no modules "
0180                                                   "to be exclude/included in your cfg"
0181                                                << std::endl;
0182 
0183     modulesToBeIncluded.insert(modulesToBeIncluded.end(), ModulesToBeIncluded_.begin(), ModulesToBeIncluded_.end());
0184     edm::LogInfo("SiStripBaseCondObjDQM")
0185         << "[SiStripBaseCondObjDQM::selectModules] modulesToBeIncluded: " << modulesToBeIncluded.size() << std::endl;
0186     modulesToBeExcluded.insert(modulesToBeExcluded.end(), ModulesToBeExcluded_.begin(), ModulesToBeExcluded_.end());
0187     edm::LogInfo("SiStripBaseCondObjDQM")
0188         << "[SiStripBaseCondObjDQM::selectModules] modulesToBeExcluded: " << modulesToBeExcluded.size() << std::endl;
0189 
0190     // apply modules selection
0191     if (!modulesToBeIncluded.empty()) {
0192       std::vector<uint32_t> tmp;
0193       // The intersection of two sets is formed only by the elements that are
0194       // present in both sets
0195       set_intersection(detIds_.begin(),
0196                        detIds_.end(),
0197                        modulesToBeIncluded.begin(),
0198                        modulesToBeIncluded.end(),
0199                        inserter(tmp, tmp.begin()));
0200       swap(detIds_, tmp);
0201     }
0202 
0203     std::sort(detIds_.begin(), detIds_.end());
0204     if (!modulesToBeExcluded.empty()) {
0205       for (const auto mod : modulesToBeExcluded) {
0206         auto detid = std::lower_bound(detIds_.begin(), detIds_.end(), mod);
0207         if (detid != detIds_.end())
0208           detIds_.erase(detid);
0209         detid--;
0210       }
0211     }
0212 
0213     // -----
0214     // *** restrict to a particular subdetector ***
0215 
0216     if (*(SubDetectorsToBeExcluded_.begin()) != "none") {
0217       std::vector<uint32_t> tmp;
0218 
0219       for (const auto &mod : SubDetectorsToBeExcluded_) {
0220         tmp.clear();
0221 
0222         if (mod == "TIB") {
0223           SiStripSubStructure::getTIBDetectors(detIds_, tmp, tTopo_, 0, 0, 0, 0);
0224         } else if (mod == "TOB") {
0225           SiStripSubStructure::getTOBDetectors(detIds_, tmp, tTopo_, 0, 0, 0);
0226         } else if (mod == "TID") {
0227           SiStripSubStructure::getTIDDetectors(detIds_, tmp, tTopo_, 0, 0, 0, 0);
0228         } else if (mod == "TEC") {
0229           SiStripSubStructure::getTECDetectors(detIds_, tmp, tTopo_, 0, 0, 0, 0, 0, 0);
0230         } else {
0231           edm::LogWarning("SiStripBaseCondObjDQM") << "[SiStripBaseCondObjDQM::selectModules] PLEASE CHECK : no "
0232                                                       "correct (name) subdetector to be excluded in your cfg"
0233                                                    << std::endl;
0234         }
0235 
0236         const auto iterBegin_ = std::lower_bound(detIds_.begin(), detIds_.end(), *min_element(tmp.begin(), tmp.end()));
0237 
0238         const auto iterEnd_ = std::lower_bound(detIds_.begin(), detIds_.end(), *max_element(tmp.begin(), tmp.end()));
0239 
0240         for (auto detIter_ = iterEnd_; detIter_ != iterBegin_ - 1; detIter_--) {
0241           detIds_.erase(detIter_);
0242         }
0243 
0244       }  // loop SubDetectorsToBeExcluded_
0245     }
0246   }
0247   edm::LogInfo("SiStripBaseCondObjDQM") << "[SiStripBaseCondObjDQM::selectModules] output detIds_: " << detIds_.size()
0248                                         << std::endl;
0249 
0250   // -----
0251   // *** fill only one Module per layer ***
0252 
0253   if (fPSet_.getParameter<std::string>("ModulesToBeFilled") == "onlyOneModulePerLayer") {
0254     std::vector<uint32_t> tmp;
0255     std::vector<uint32_t> layerDetIds;
0256 
0257     for (unsigned int i = 1; i < 5; i++) {
0258       tmp.clear();
0259       SiStripSubStructure::getTIBDetectors(detIds_, tmp, tTopo_, i, 0, 0, 0);
0260       if (!tmp.empty()) {
0261         layerDetIds.push_back(*(tmp.begin()));
0262       }
0263     }
0264     for (unsigned int i = 1; i < 7; i++) {
0265       tmp.clear();
0266       SiStripSubStructure::getTOBDetectors(detIds_, tmp, tTopo_, i, 0, 0);
0267       if (!tmp.empty()) {
0268         layerDetIds.push_back(*(tmp.begin()));
0269       }
0270     }
0271     for (unsigned int i = 1; i < 4; i++) {
0272       tmp.clear();
0273       SiStripSubStructure::getTIDDetectors(detIds_, tmp, tTopo_, 1, i, 0, 0);
0274       if (!tmp.empty()) {
0275         layerDetIds.push_back(*(tmp.begin()));
0276       }
0277       SiStripSubStructure::getTIDDetectors(detIds_, tmp, tTopo_, 2, i, 0, 0);
0278       if (!tmp.empty()) {
0279         layerDetIds.push_back(*(tmp.begin()));
0280       }
0281     }
0282     for (unsigned int i = 1; i < 10; i++) {
0283       tmp.clear();
0284       SiStripSubStructure::getTECDetectors(detIds_, tmp, tTopo_, 1, i, 0, 0, 0, 0);
0285       if (!tmp.empty()) {
0286         layerDetIds.push_back(*(tmp.begin()));
0287       }
0288       SiStripSubStructure::getTECDetectors(detIds_, tmp, tTopo_, 2, i, 0, 0, 0, 0);
0289       if (!tmp.empty()) {
0290         layerDetIds.push_back(*(tmp.begin()));
0291       }
0292     }
0293 
0294     detIds_.clear();
0295     detIds_ = layerDetIds;
0296   }
0297   // -----
0298 
0299 }  // selectModules
0300 
0301 void SiStripBaseCondObjDQM::getModMEs(ModMEs &CondObj_ME, const uint32_t &detId_) {
0302   const auto ModMEsMap_iter = ModMEsMap_.find(detId_);
0303 
0304   if (ModMEsMap_iter != ModMEsMap_.end()) {
0305     CondObj_ME = ModMEsMap_iter->second;
0306 
0307     if ((CondObj_fillId_ == "ProfileAndCumul" || CondObj_fillId_ == "onlyProfile") && CondObj_ME.ProfileDistr) {
0308       CondObj_ME.ProfileDistr->Reset();
0309     }
0310 
0311     if ((CondObj_fillId_ == "ProfileAndCumul" || CondObj_fillId_ == "onlyCumul") && CondObj_ME.CumulDistr) {
0312       CondObj_ME.CumulDistr->Reset();
0313     } else {
0314       edm::LogWarning("SiStripBaseCondObjDQM") << "[SiStripBaseCondObjDQM::getModMEs] PLEASE CHECK : CondObj_fillId "
0315                                                   "option mispelled";
0316     }
0317     return;
0318   }
0319 
0320   // --> profile defined for all CondData
0321   if ((CondObj_fillId_ == "ProfileAndCumul" || CondObj_fillId_ == "onlyProfile")) {
0322     bookProfileMEs(CondObj_ME, detId_);
0323   }
0324 
0325   // --> cumul currently only defined for noise and apvgain
0326   if ((CondObj_fillId_ == "ProfileAndCumul" || CondObj_fillId_ == "onlyCumul") &&
0327       (CondObj_name_ == "noise" || CondObj_name_ == "apvgain"))
0328     bookCumulMEs(CondObj_ME, detId_);
0329 
0330   ModMEsMap_.insert(std::make_pair(detId_, CondObj_ME));
0331 }
0332 
0333 //%FIXME: very long method, factorize
0334 void SiStripBaseCondObjDQM::getSummaryMEs(ModMEs &CondObj_ME, const uint32_t &detId_) {
0335   std::map<uint32_t, ModMEs>::const_iterator SummaryMEsMap_iter;
0336 
0337   if (CondObj_name_ == "lorentzangle" && SummaryOnStringLevel_On_) {
0338     SummaryMEsMap_iter = SummaryMEsMap_.find(getStringNameAndId(detId_).second);
0339   } else if (CondObj_name_ == "bpcorrection" && SummaryOnStringLevel_On_) {
0340     SummaryMEsMap_iter = SummaryMEsMap_.find(getStringNameAndId(detId_).second);
0341   } else {
0342     SummaryMEsMap_iter = SummaryMEsMap_.find(getLayerNameAndId(detId_).second);
0343   }
0344 
0345   if (SummaryMEsMap_iter != SummaryMEsMap_.end()) {
0346     return;
0347   }
0348 
0349   // FIXME t's not good that the base class has to know about which derived
0350   // class shoudl exist.
0351   // please modify this part. implement virtual functions, esplicited in the
0352   // derived classes
0353   // --> currently only profile summary defined for all condition objects except
0354   // quality
0355   if ((CondObj_fillId_ == "ProfileAndCumul" || CondObj_fillId_ == "onlyProfile") &&
0356       (CondObj_name_ == "pedestal" || CondObj_name_ == "noise" || CondObj_name_ == "lowthreshold" ||
0357        CondObj_name_ == "highthreshold" || CondObj_name_ == "apvgain" || CondObj_name_ == "bpcorrection" ||
0358        CondObj_name_ == "lorentzangle")) {
0359     if (hPSet_.getParameter<bool>("FillSummaryProfileAtLayerLevel"))
0360       if (!CondObj_ME.SummaryOfProfileDistr) {
0361         bookSummaryProfileMEs(CondObj_ME, detId_);
0362       }
0363   }
0364 
0365   // --> currently only genuine cumul LA
0366   if ((CondObj_fillId_ == "ProfileAndCumul" || CondObj_fillId_ == "onlyCumul") &&
0367       (CondObj_name_ == "lorentzangle" || CondObj_name_ == "bpcorrection" || CondObj_name_ == "noise")) {
0368     if (hPSet_.getParameter<bool>("FillCumulativeSummaryAtLayerLevel"))
0369       if (!CondObj_ME.SummaryOfCumulDistr) {
0370         bookSummaryCumulMEs(CondObj_ME, detId_);
0371       }
0372   }
0373 
0374   // --> currently only summary as a function of detId for noise, pedestal and
0375   // apvgain
0376   if (CondObj_name_ == "noise" || CondObj_name_ == "lowthreshold" || CondObj_name_ == "highthreshold" ||
0377       CondObj_name_ == "apvgain" || CondObj_name_ == "pedestal" || CondObj_name_ == "quality") {
0378     if (hPSet_.getParameter<bool>("FillSummaryAtLayerLevel"))
0379       if (!CondObj_ME.SummaryDistr) {
0380         bookSummaryMEs(CondObj_ME, detId_);
0381       }
0382   }
0383 
0384   if (CondObj_name_ == "lorentzangle" && SummaryOnStringLevel_On_) {
0385     // FIXME getStringNameandId takes time. not need to call it every timne. put
0386     // the call at the beginning of the method and caache the string
0387     SummaryMEsMap_.insert(std::make_pair(getStringNameAndId(detId_).second, CondObj_ME));
0388   } else if (CondObj_name_ == "bpcorrection" && SummaryOnStringLevel_On_) {
0389     // FIXME getStringNameandId takes time. not need to call it every timne. put
0390     // the call at the beginning of the method and caache the string
0391     SummaryMEsMap_.insert(std::make_pair(getStringNameAndId(detId_).second, CondObj_ME));
0392   } else {
0393     SummaryMEsMap_.insert(std::make_pair(getLayerNameAndId(detId_).second, CondObj_ME));
0394   }
0395 }
0396 // ----
0397 
0398 //====================================================
0399 // -----
0400 void SiStripBaseCondObjDQM::bookProfileMEs(SiStripBaseCondObjDQM::ModMEs &CondObj_ME, const uint32_t &detId_) {
0401   int hProfile_NchX = 0;
0402   double hProfile_LowX = 0;
0403   double hProfile_HighX = 0;
0404 
0405   std::string hProfile_description;
0406   hProfile_description = hPSet_.getParameter<std::string>("Profile_description");
0407 
0408   std::string hProfile_xTitle, hProfile_yTitle;
0409   hProfile_xTitle = hPSet_.getParameter<std::string>("Profile_xTitle");
0410   hProfile_yTitle = hPSet_.getParameter<std::string>("Profile_yTitle");
0411 
0412   if (CondObj_name_ != "apvgain") {
0413     int nStrip = detInfo_.getNumberOfApvsAndStripLength(detId_).first * 128;
0414 
0415     hProfile_NchX = nStrip;
0416     hProfile_LowX = 0.5;
0417     hProfile_HighX = nStrip + 0.5;
0418   } else {
0419     int nApv = detInfo_.getNumberOfApvsAndStripLength(detId_).first;
0420 
0421     hProfile_NchX = nApv;
0422     hProfile_LowX = 0.5;
0423     hProfile_HighX = nApv + 0.5;
0424   }
0425 
0426   folder_organizer.setDetectorFolder(detId_, tTopo_);
0427 
0428   std::string hProfile_Name;
0429   hProfile_Name = hidmanager.createHistoId(hProfile_description, "det", detId_);
0430 
0431   std::string hProfile;
0432   hProfile = hProfile_Name;
0433 
0434   CondObj_ME.ProfileDistr = dqmStore_->book1D(hProfile_Name, hProfile, hProfile_NchX, hProfile_LowX, hProfile_HighX);
0435   CondObj_ME.ProfileDistr->setAxisTitle(hProfile_xTitle, 1);
0436   CondObj_ME.ProfileDistr->setAxisTitle(hProfile_yTitle, 2);
0437 }
0438 // -----
0439 
0440 //=============================================
0441 // -----
0442 void SiStripBaseCondObjDQM::bookCumulMEs(SiStripBaseCondObjDQM::ModMEs &CondObj_ME, const uint32_t &detId_) {
0443   int hCumul_NchX = 0;
0444   double hCumul_LowX = 0;
0445   double hCumul_HighX = 0;
0446 
0447   std::string hCumul_description;
0448   hCumul_description = hPSet_.getParameter<std::string>("Cumul_description");
0449 
0450   std::string hCumul_xTitle, hCumul_yTitle;
0451   hCumul_xTitle = hPSet_.getParameter<std::string>("Cumul_xTitle");
0452   hCumul_yTitle = hPSet_.getParameter<std::string>("Cumul_yTitle");
0453 
0454   hCumul_NchX = hPSet_.getParameter<int>("Cumul_NchX");
0455   hCumul_LowX = hPSet_.getParameter<double>("Cumul_LowX");
0456   hCumul_HighX = hPSet_.getParameter<double>("Cumul_HighX");
0457 
0458   folder_organizer.setDetectorFolder(detId_, tTopo_);
0459 
0460   std::string hCumul_name;
0461   hCumul_name = hidmanager.createHistoId(hCumul_description, "det", detId_);
0462   ;
0463 
0464   std::string hCumul_title;
0465   hCumul_title = hCumul_name;
0466 
0467   CondObj_ME.CumulDistr = dqmStore_->book1D(hCumul_name, hCumul_title, hCumul_NchX, hCumul_LowX, hCumul_HighX);
0468   CondObj_ME.CumulDistr->setAxisTitle(hCumul_xTitle, 1);
0469   CondObj_ME.CumulDistr->setAxisTitle(hCumul_yTitle, 2);
0470 }
0471 // ----
0472 
0473 //===========================================
0474 // -----
0475 //#FIXME: same comments: factorize, and remove any reference to derived classes
0476 void SiStripBaseCondObjDQM::bookSummaryProfileMEs(SiStripBaseCondObjDQM::ModMEs &CondObj_ME, const uint32_t &detId_) {
0477   std::vector<uint32_t> sameLayerDetIds_;
0478 
0479   int hSummaryOfProfile_NchX = 0;
0480   double hSummaryOfProfile_LowX = 0;
0481   double hSummaryOfProfile_HighX = 0;
0482 
0483   std::string hSummaryOfProfile_description;
0484   hSummaryOfProfile_description = hPSet_.getParameter<std::string>("SummaryOfProfile_description");
0485 
0486   std::string hSummaryOfProfile_xTitle, hSummaryOfProfile_yTitle;
0487   hSummaryOfProfile_xTitle = hPSet_.getParameter<std::string>("SummaryOfProfile_xTitle");
0488   hSummaryOfProfile_yTitle = hPSet_.getParameter<std::string>("SummaryOfProfile_yTitle");
0489 
0490   int hSummaryOfProfile_NchY;
0491   double hSummaryOfProfile_LowY, hSummaryOfProfile_HighY;
0492   hSummaryOfProfile_NchY = hPSet_.getParameter<int>("SummaryOfProfile_NchY");
0493   hSummaryOfProfile_LowY = hPSet_.getParameter<double>("SummaryOfProfile_LowY");
0494   hSummaryOfProfile_HighY = hPSet_.getParameter<double>("SummaryOfProfile_HighY");
0495 
0496   int nStrip, nApv, layerId_;
0497 
0498   if (CondObj_name_ == "lorentzangle" && SummaryOnStringLevel_On_) {
0499     layerId_ = getStringNameAndId(detId_).second;
0500   } else if (CondObj_name_ == "bpcorrection" && SummaryOnStringLevel_On_) {
0501     layerId_ = getStringNameAndId(detId_).second;
0502   } else {
0503     layerId_ = getLayerNameAndId(detId_).second;
0504   }
0505 
0506   if (CondObj_name_ == "pedestal" || CondObj_name_ == "noise" || CondObj_name_ == "lowthreshold" ||
0507       CondObj_name_ == "highthreshold") {  // plot in strip number
0508 
0509     if ((layerId_ > 610 && layerId_ < 620) ||  // TID & TEC have 768 strips at maximum
0510         (layerId_ > 620 && layerId_ < 630) || (layerId_ > 410 && layerId_ < 414) ||
0511         (layerId_ > 420 && layerId_ < 424)) {
0512       nStrip = 768;
0513     } else {
0514       nStrip = detInfo_.getNumberOfApvsAndStripLength(detId_).first * 128;
0515     }
0516 
0517     hSummaryOfProfile_NchX = nStrip;
0518     hSummaryOfProfile_LowX = 0.5;
0519     hSummaryOfProfile_HighX = nStrip + 0.5;
0520 
0521   } else if (((CondObj_name_ == "lorentzangle" || CondObj_name_ == "bpcorrection") && SummaryOnLayerLevel_On_) ||
0522              CondObj_name_ == "quality") {  // plot in detId-number
0523 
0524     // -----
0525     // get detIds belonging to same layer to fill X-axis with detId-number
0526 
0527     sameLayerDetIds_.clear();
0528 
0529     switch (DetId(detId_).subdetId()) {
0530       case StripSubdetector::TIB:
0531         SiStripSubStructure::getTIBDetectors(
0532             activeDetIds, sameLayerDetIds_, tTopo_, tTopo_->tibLayer(detId_), 0, 0, tTopo_->tibString(detId_));
0533         break;
0534       case StripSubdetector::TID:
0535         SiStripSubStructure::getTIDDetectors(activeDetIds, sameLayerDetIds_, tTopo_, 0, 0, 0, 0);
0536         break;
0537       case StripSubdetector::TOB:
0538         SiStripSubStructure::getTOBDetectors(activeDetIds, sameLayerDetIds_, tTopo_, tTopo_->tobLayer(detId_), 0, 0);
0539         break;
0540       case StripSubdetector::TEC:
0541         SiStripSubStructure::getTECDetectors(activeDetIds, sameLayerDetIds_, tTopo_, 0, 0, 0, 0, 0, 0);
0542         break;
0543     }
0544 
0545     hSummaryOfProfile_NchX = sameLayerDetIds_.size();
0546     hSummaryOfProfile_LowX = 0.5;
0547     hSummaryOfProfile_HighX = sameLayerDetIds_.size() + 0.5;
0548 
0549   } else if ((CondObj_name_ == "lorentzangle" || CondObj_name_ == "bpcorrection") &&
0550              SummaryOnStringLevel_On_) {  // plot in detId-number
0551 
0552     // -----
0553     // get detIds belonging to same string to fill X-axis with detId-number
0554 
0555     sameLayerDetIds_.clear();
0556 
0557     switch (DetId(detId_).subdetId()) {
0558       case StripSubdetector::TIB:
0559         if (tTopo_->tibIsInternalString(detId_)) {
0560           SiStripSubStructure::getTIBDetectors(
0561               activeDetIds, sameLayerDetIds_, tTopo_, tTopo_->tibLayer(detId_), 0, 1, tTopo_->tibString(detId_));
0562         } else if (tTopo_->tibIsExternalString(detId_)) {
0563           SiStripSubStructure::getTIBDetectors(
0564               activeDetIds, sameLayerDetIds_, tTopo_, tTopo_->tibLayer(detId_), 0, 2, tTopo_->tibString(detId_));
0565         }
0566         break;
0567       case StripSubdetector::TID:
0568         SiStripSubStructure::getTIDDetectors(activeDetIds, sameLayerDetIds_, tTopo_, 0, 0, 0, 0);
0569         break;
0570       case StripSubdetector::TOB:
0571         SiStripSubStructure::getTOBDetectors(
0572             activeDetIds, sameLayerDetIds_, tTopo_, tTopo_->tobLayer(detId_), 0, tTopo_->tobRod(detId_));
0573         break;
0574       case StripSubdetector::TEC:
0575         SiStripSubStructure::getTECDetectors(activeDetIds, sameLayerDetIds_, tTopo_, 0, 0, 0, 0, 0, 0);
0576         break;
0577     }
0578 
0579     hSummaryOfProfile_NchX = sameLayerDetIds_.size();
0580     hSummaryOfProfile_LowX = 0.5;
0581     hSummaryOfProfile_HighX = sameLayerDetIds_.size() + 0.5;
0582 
0583   } else if (CondObj_name_ == "apvgain") {
0584     if ((layerId_ > 610 && layerId_ < 620) ||  // TID & TEC have 6 apvs at maximum
0585         (layerId_ > 620 && layerId_ < 630) || (layerId_ > 410 && layerId_ < 414) ||
0586         (layerId_ > 420 && layerId_ < 424)) {
0587       nApv = 6;
0588     } else {
0589       nApv = detInfo_.getNumberOfApvsAndStripLength(detId_).first;
0590     }
0591 
0592     hSummaryOfProfile_NchX = nApv;
0593     hSummaryOfProfile_LowX = 0.5;
0594     hSummaryOfProfile_HighX = nApv + 0.5;
0595 
0596   } else {
0597     edm::LogWarning("SiStripBaseCondObjDQM") << "[SiStripBaseCondObjDQM::bookSummaryProfileMEs] PLEASE CHECK : "
0598                                                 "x-axis label in your cfg"
0599                                              << std::endl;
0600   }
0601 
0602   uint32_t layer_ = 0;
0603 
0604   layer_ = folder_organizer.GetSubDetAndLayer(detId_, tTopo_).second;
0605 
0606   folder_organizer.setLayerFolder(detId_, tTopo_, layer_);
0607 
0608   std::string hSummaryOfProfile_name;
0609 
0610   // ---
0611   int subdetectorId_ = ((detId_ >> 25) & 0x7);
0612 
0613   if (subdetectorId_ < 3 || subdetectorId_ > 6) {
0614     edm::LogError("SiStripBaseCondObjDQM") << "[SiStripBaseCondObjDQM::bookSummaryProfileMEs] WRONG INPUT : no "
0615                                               "such subdetector type : "
0616                                            << subdetectorId_ << " no folder set!" << std::endl;
0617     return;
0618   }
0619   // ---
0620 
0621   if ((CondObj_name_ == "lorentzangle" || CondObj_name_ == "bpcorrection") && SummaryOnStringLevel_On_) {
0622     hSummaryOfProfile_name =
0623         hidmanager.createHistoLayer(hSummaryOfProfile_description, "layer", getStringNameAndId(detId_).first, "");
0624   } else {
0625     hSummaryOfProfile_name =
0626         hidmanager.createHistoLayer(hSummaryOfProfile_description, "layer", getLayerNameAndId(detId_).first, "");
0627   }
0628 
0629   std::string hSummaryOfProfile_title;
0630   hSummaryOfProfile_title = hSummaryOfProfile_name;
0631 
0632   CondObj_ME.SummaryOfProfileDistr = dqmStore_->bookProfile(hSummaryOfProfile_name,
0633                                                             hSummaryOfProfile_title,
0634                                                             hSummaryOfProfile_NchX,
0635                                                             hSummaryOfProfile_LowX,
0636                                                             hSummaryOfProfile_HighX,
0637                                                             hSummaryOfProfile_NchY,
0638                                                             0.,
0639                                                             0.);
0640   //                                    hSummaryOfProfile_LowY,
0641   //                                    hSummaryOfProfile_HighY);
0642   CondObj_ME.SummaryOfProfileDistr->setAxisTitle(hSummaryOfProfile_xTitle, 1);
0643   CondObj_ME.SummaryOfProfileDistr->setAxisTitle(hSummaryOfProfile_yTitle, 2);
0644   CondObj_ME.SummaryOfProfileDistr->setAxisRange(hSummaryOfProfile_LowY, hSummaryOfProfile_HighY, 2);
0645 
0646   // -----
0647   // in order to get the right detId-number labelled in right bin of x-axis
0648 
0649   if (CondObj_name_ == "quality") {
0650     unsigned int iBin = 0;
0651 
0652     for (unsigned int i = 0; i < sameLayerDetIds_.size(); i++) {
0653       iBin++;
0654       char sameLayerDetIds_Name[1024];
0655       sprintf(sameLayerDetIds_Name, "%u", sameLayerDetIds_[i]);
0656       CondObj_ME.SummaryOfProfileDistr->setBinLabel(iBin, sameLayerDetIds_Name);
0657     }
0658   }
0659   if (CondObj_name_ == "lorentzangle" || CondObj_name_ == "bpcorrection") {
0660     // Put the detIds for the -z side as following the geometrical order:
0661     reverse(sameLayerDetIds_.begin(), sameLayerDetIds_.begin() + sameLayerDetIds_.size() / 2);
0662 
0663     unsigned int iBin = 0;
0664     for (unsigned int i = 0; i < sameLayerDetIds_.size(); i++) {
0665       iBin++;
0666       if (!SummaryOnStringLevel_On_) {
0667         // remove the label for detIds:
0668         CondObj_ME.SummaryOfProfileDistr->setBinLabel(iBin, "");
0669       }
0670 
0671       if (SummaryOnStringLevel_On_) {
0672         // Label with module position instead of detIds:
0673         char sameLayerDetIds_Name[1024];
0674         if (subdetectorId_ == 3) {  // re-abelling for TIB
0675           if (tTopo_->tibIsZPlusSide(sameLayerDetIds_[i])) {
0676             sprintf(sameLayerDetIds_Name, "%i", tTopo_->tibModule(sameLayerDetIds_[i]));
0677           } else if (tTopo_->tibIsZMinusSide(sameLayerDetIds_[i])) {
0678             sprintf(sameLayerDetIds_Name, "%i", -tTopo_->tibModule(sameLayerDetIds_[i]));
0679           }
0680           CondObj_ME.SummaryOfProfileDistr->setBinLabel(iBin, sameLayerDetIds_Name);
0681         } else if (subdetectorId_ == 5) {  // re-abelling for TOB
0682           if (tTopo_->tobIsZPlusSide(sameLayerDetIds_[i])) {
0683             sprintf(sameLayerDetIds_Name, "%i", tTopo_->tobModule(sameLayerDetIds_[i]));
0684           } else if (tTopo_->tobIsZMinusSide(sameLayerDetIds_[i])) {
0685             sprintf(sameLayerDetIds_Name, "%i", -tTopo_->tobModule(sameLayerDetIds_[i]));
0686           }
0687           CondObj_ME.SummaryOfProfileDistr->setBinLabel(iBin, sameLayerDetIds_Name);
0688         }
0689       }
0690     }
0691 
0692     // -----
0693 
0694   }  // if "lorentzangle"
0695 }
0696 
0697 void SiStripBaseCondObjDQM::bookSummaryCumulMEs(SiStripBaseCondObjDQM::ModMEs &CondObj_ME, const uint32_t &detId_) {
0698   int hSummaryOfCumul_NchX = 0;
0699   double hSummaryOfCumul_LowX = 0;
0700   double hSummaryOfCumul_HighX = 0;
0701 
0702   std::string hSummaryOfCumul_description;
0703   hSummaryOfCumul_description = hPSet_.getParameter<std::string>("SummaryOfCumul_description");
0704 
0705   std::string hSummaryOfCumul_xTitle, hSummaryOfCumul_yTitle;
0706   hSummaryOfCumul_xTitle = hPSet_.getParameter<std::string>("SummaryOfCumul_xTitle");
0707   hSummaryOfCumul_yTitle = hPSet_.getParameter<std::string>("SummaryOfCumul_yTitle");
0708 
0709   hSummaryOfCumul_NchX = hPSet_.getParameter<int>("SummaryOfCumul_NchX");
0710   hSummaryOfCumul_LowX = hPSet_.getParameter<double>("SummaryOfCumul_LowX");
0711   hSummaryOfCumul_HighX = hPSet_.getParameter<double>("SummaryOfCumul_HighX");
0712 
0713   uint32_t layer_ = 0;
0714 
0715   layer_ = folder_organizer.GetSubDetAndLayer(detId_, tTopo_).second;
0716 
0717   folder_organizer.setLayerFolder(detId_, tTopo_, layer_);
0718 
0719   std::string hSummaryOfCumul_name;
0720 
0721   // ---
0722   int subdetectorId_ = ((detId_ >> 25) & 0x7);
0723 
0724   if (subdetectorId_ < 3 || subdetectorId_ > 6) {
0725     edm::LogError("SiStripBaseCondObjDQM") << "[SiStripBaseCondObjDQM::bookSummaryCumulMEs] WRONG INPUT : no such "
0726                                               "subdetector type : "
0727                                            << subdetectorId_ << " no folder set!" << std::endl;
0728     return;
0729   }
0730   // ---
0731 
0732   // LA and BP Histos are plotted for each string:
0733   if ((CondObj_name_ == "lorentzangle" || CondObj_name_ == "bpcorrection") && SummaryOnStringLevel_On_) {
0734     hSummaryOfCumul_name =
0735         hidmanager.createHistoLayer(hSummaryOfCumul_description, "layer", getStringNameAndId(detId_).first, "");
0736   } else {
0737     hSummaryOfCumul_name =
0738         hidmanager.createHistoLayer(hSummaryOfCumul_description, "layer", getLayerNameAndId(detId_).first, "");
0739   }
0740 
0741   std::string hSummaryOfCumul_title;
0742   hSummaryOfCumul_title = hSummaryOfCumul_name;
0743 
0744   CondObj_ME.SummaryOfCumulDistr = dqmStore_->book1D(
0745       hSummaryOfCumul_name, hSummaryOfCumul_title, hSummaryOfCumul_NchX, hSummaryOfCumul_LowX, hSummaryOfCumul_HighX);
0746 
0747   CondObj_ME.SummaryOfCumulDistr->setAxisTitle(hSummaryOfCumul_xTitle, 1);
0748   CondObj_ME.SummaryOfCumulDistr->setAxisTitle(hSummaryOfCumul_yTitle, 2);
0749 }
0750 
0751 // FIXME same as before: factorize
0752 void SiStripBaseCondObjDQM::bookSummaryMEs(SiStripBaseCondObjDQM::ModMEs &CondObj_ME, const uint32_t &detId_) {
0753   std::vector<uint32_t> sameLayerDetIds_;
0754 
0755   int hSummary_NchX = 0;
0756   double hSummary_LowX = 0;
0757   double hSummary_HighX = 0;
0758 
0759   std::string hSummary_description;
0760   hSummary_description = hPSet_.getParameter<std::string>("Summary_description");
0761 
0762   std::string hSummary_xTitle, hSummary_yTitle;
0763   hSummary_xTitle = hPSet_.getParameter<std::string>("Summary_xTitle");
0764   hSummary_yTitle = hPSet_.getParameter<std::string>("Summary_yTitle");
0765 
0766   int hSummary_NchY;
0767   double hSummary_LowY, hSummary_HighY;
0768   hSummary_NchY = hPSet_.getParameter<int>("Summary_NchY");
0769   hSummary_LowY = hPSet_.getParameter<double>("Summary_LowY");
0770   hSummary_HighY = hPSet_.getParameter<double>("Summary_HighY");
0771 
0772   // -----
0773   // get detIds belonging to same layer to fill X-axis with detId-number
0774 
0775   sameLayerDetIds_.clear();
0776 
0777   sameLayerDetIds_ = GetSameLayerDetId(activeDetIds, detId_);
0778 
0779   hSummary_NchX = sameLayerDetIds_.size();
0780   hSummary_LowX = 0.5;
0781   hSummary_HighX = sameLayerDetIds_.size() + 0.5;
0782 
0783   uint32_t layer_ = 0;
0784 
0785   layer_ = folder_organizer.GetSubDetAndLayer(detId_, tTopo_).second;
0786 
0787   folder_organizer.setLayerFolder(detId_, tTopo_, layer_);
0788 
0789   std::string hSummary_name;
0790 
0791   // ---
0792   int subdetectorId_ = ((detId_ >> 25) & 0x7);
0793 
0794   if (subdetectorId_ < 3 || subdetectorId_ > 6) {
0795     edm::LogError("SiStripBaseCondObjDQM") << "[SiStripBaseCondObjDQM::bookSummaryMEs] WRONG INPUT : no such "
0796                                               "subdetector type : "
0797                                            << subdetectorId_ << " no folder set!" << std::endl;
0798     return;
0799   }
0800   // ---
0801 
0802   hSummary_name = hidmanager.createHistoLayer(hSummary_description, "layer", getLayerNameAndId(detId_).first, "");
0803 
0804   std::string hSummary_title;
0805   hSummary_title = hSummary_name;
0806 
0807   CondObj_ME.SummaryDistr = dqmStore_->bookProfile(
0808       hSummary_name, hSummary_title, hSummary_NchX, hSummary_LowX, hSummary_HighX, hSummary_NchY, 0., 0.);
0809   //                           hSummary_LowY,
0810   //                           hSummary_HighY);
0811   CondObj_ME.SummaryDistr->setAxisTitle(hSummary_xTitle, 1);
0812   CondObj_ME.SummaryDistr->setAxisTitle(hSummary_yTitle, 2);
0813   CondObj_ME.SummaryDistr->setAxisRange(hSummary_LowY, hSummary_HighY, 2);
0814 
0815   // -----
0816   // in order to get the right detId-number labelled in right bin of x-axis
0817   unsigned int iBin = 0;
0818 
0819   for (unsigned int i = 0; i < sameLayerDetIds_.size(); i++) {
0820     iBin++;
0821     char sameLayerDetIds_Name[1024];
0822     sprintf(sameLayerDetIds_Name, "%u", sameLayerDetIds_[i]);
0823     if (iBin % 100 == 0)
0824       CondObj_ME.SummaryDistr->setBinLabel(iBin, sameLayerDetIds_Name);
0825   }
0826 }
0827 
0828 std::pair<std::string, uint32_t> SiStripBaseCondObjDQM::getLayerNameAndId(const uint32_t &detId_) {
0829   int subdetectorId_ = ((detId_ >> 25) & 0x7);
0830   int layerId_ = 0;
0831 
0832   std::stringstream layerName;
0833 
0834   if (subdetectorId_ == 3) {  // TIB
0835 
0836     for (unsigned int i = 1; i < 5; i++) {
0837       if (tTopo_->tibLayer(detId_) == i) {
0838         layerName << "TIB__layer__" << i;
0839         layerId_ = 300 + i;
0840       }
0841     }
0842 
0843   }
0844 
0845   else if (subdetectorId_ == 4) {  // TIDD
0846 
0847     if (tTopo_->tidSide(detId_) == 1) {  // TIDD side 1
0848 
0849       for (unsigned int i = 1; i < 4; i++) {
0850         if (tTopo_->tidWheel(detId_) == i) {
0851           layerName << "TID__side__1__wheel__" << i;
0852           layerId_ = 410 + i;
0853         }
0854       }
0855 
0856     }
0857 
0858     else if (tTopo_->tidSide(detId_) == 2) {  // TIDD side 2
0859 
0860       for (unsigned int i = 1; i < 4; i++) {
0861         if (tTopo_->tidWheel(detId_) == i) {
0862           layerName << "TID__side__2__wheel__" << i;
0863           layerId_ = 420 + i;
0864         }
0865       }
0866     }
0867 
0868   }
0869 
0870   else if (subdetectorId_ == 5) {  // TOB
0871 
0872     for (unsigned int i = 1; i < 7; i++) {
0873       if (tTopo_->tobLayer(detId_) == i) {
0874         layerName << "TOB__layer__" << i;
0875         layerId_ = 500 + i;
0876       }
0877     }
0878 
0879   }
0880 
0881   else if (subdetectorId_ == 6) {  // TEC
0882 
0883     if (tTopo_->tecSide(detId_) == 1) {  // TEC side 1
0884 
0885       for (unsigned int i = 1; i < 10; i++) {
0886         if (tTopo_->tecWheel(detId_) == i) {
0887           layerName << "TEC__side__1__wheel__" << i;
0888           layerId_ = 610 + i;
0889         }
0890       }
0891 
0892     }
0893 
0894     else if (tTopo_->tecSide(detId_) == 2) {  // TEC side 2
0895 
0896       for (unsigned int i = 1; i < 10; i++) {
0897         if (tTopo_->tecWheel(detId_) == i) {
0898           layerName << "TEC__side__2__wheel__" << i;
0899           layerId_ = 620 + i;
0900         }
0901       }
0902     }
0903   }
0904 
0905   return std::make_pair(layerName.str(), layerId_);
0906 }
0907 
0908 std::pair<std::string, uint32_t> SiStripBaseCondObjDQM::getStringNameAndId(const uint32_t &detId_) {
0909   int subdetectorId_ = ((detId_ >> 25) & 0x7);
0910   int layerStringId_ = 0;
0911 
0912   std::stringstream layerStringName;
0913 
0914   if (subdetectorId_ == 3) {                                                     // TIB
0915     if (tTopo_->tibLayer(detId_) == 1 && tTopo_->tibIsInternalString(detId_)) {  // 1st layer int
0916       for (unsigned int i = 1; i < 27; i++) {
0917         if (tTopo_->tibString(detId_) == i) {
0918           layerStringName << "TIB_L1_Int_Str_" << i;
0919           layerStringId_ = 30110 + i;
0920         }
0921       }
0922     } else if (tTopo_->tibLayer(detId_) == 1 && tTopo_->tibIsExternalString(detId_)) {  // 1st layer ext
0923       for (unsigned int i = 1; i < 31; i++) {
0924         if (tTopo_->tibString(detId_) == i) {
0925           layerStringName << "TIB_L1_Ext_Str_" << i;
0926           layerStringId_ = 301200 + i;
0927         }
0928       }
0929     } else if (tTopo_->tibLayer(detId_) == 2 && tTopo_->tibIsInternalString(detId_)) {  // 2nd layer int
0930       for (unsigned int i = 1; i < 35; i++) {
0931         if (tTopo_->tibString(detId_) == i) {
0932           layerStringName << "TIB_L2_Int_Str_" << i;
0933           layerStringId_ = 302100 + i;
0934         }
0935       }
0936     } else if (tTopo_->tibLayer(detId_) == 2 && tTopo_->tibIsExternalString(detId_)) {  // 2nd layer ext
0937       for (unsigned int i = 1; i < 39; i++) {
0938         if (tTopo_->tibString(detId_) == i) {
0939           layerStringName << "TIB_L2_Ext_Str_" << i;
0940           layerStringId_ = 302200 + i;
0941         }
0942       }
0943     } else if (tTopo_->tibLayer(detId_) == 3 && tTopo_->tibIsInternalString(detId_)) {  // 3rd layer int
0944       for (unsigned int i = 1; i < 45; i++) {
0945         if (tTopo_->tibString(detId_) == i) {
0946           layerStringName << "TIB_L3_Int_Str_" << i;
0947           layerStringId_ = 303100 + i;
0948         }
0949       }
0950     } else if (tTopo_->tibLayer(detId_) == 3 && tTopo_->tibIsExternalString(detId_)) {  // 3rd layer ext
0951       for (unsigned int i = 1; i < 47; i++) {
0952         if (tTopo_->tibString(detId_) == i) {
0953           layerStringName << "TIB_L3_Ext_Str_" << i;
0954           layerStringId_ = 303200 + i;
0955         }
0956       }
0957     } else if (tTopo_->tibLayer(detId_) == 4 && tTopo_->tibIsInternalString(detId_)) {  // 4th layer int
0958       for (unsigned int i = 1; i < 53; i++) {
0959         if (tTopo_->tibString(detId_) == i) {
0960           layerStringName << "TIB_L4_Int_Str_" << i;
0961           layerStringId_ = 304100 + i;
0962         }
0963       }
0964     } else if (tTopo_->tibLayer(detId_) == 4 && tTopo_->tibIsExternalString(detId_)) {  // 4th layer ext
0965       for (unsigned int i = 1; i < 57; i++) {
0966         if (tTopo_->tibString(detId_) == i) {
0967           layerStringName << "TIB_L4_Ext_Str_" << i;
0968           layerStringId_ = 304200 + i;
0969         }
0970       }
0971     }
0972   }  // TIB
0973 
0974   else if (subdetectorId_ == 5) {         // TOB
0975     if (tTopo_->tobLayer(detId_) == 1) {  // 1st layer
0976       for (unsigned int i = 1; i < 43; i++) {
0977         if (tTopo_->tobRod(detId_) == i) {
0978           layerStringName << "TOB_L1_Rod_" << i;
0979           layerStringId_ = 50100 + i;
0980         }
0981       }
0982     } else if (tTopo_->tobLayer(detId_) == 2) {  // 2nd layer
0983       for (unsigned int i = 1; i < 49; i++) {
0984         if (tTopo_->tobRod(detId_) == i) {
0985           layerStringName << "TOB_L2_Rod_" << i;
0986           layerStringId_ = 50200 + i;
0987         }
0988       }
0989     } else if (tTopo_->tobLayer(detId_) == 3) {  // 3rd layer
0990       for (unsigned int i = 1; i < 55; i++) {
0991         if (tTopo_->tobRod(detId_) == i) {
0992           layerStringName << "TOB_L3_Rod_" << i;
0993           layerStringId_ = 50300 + i;
0994         }
0995       }
0996     } else if (tTopo_->tobLayer(detId_) == 4) {  // 4th layer
0997       for (unsigned int i = 1; i < 61; i++) {
0998         if (tTopo_->tobRod(detId_) == i) {
0999           layerStringName << "TOB_L4_Rod_" << i;
1000           layerStringId_ = 50400 + i;
1001         }
1002       }
1003     } else if (tTopo_->tobLayer(detId_) == 5) {  // 5th layer
1004       for (unsigned int i = 1; i < 67; i++) {
1005         if (tTopo_->tobRod(detId_) == i) {
1006           layerStringName << "TOB_L5_Rod_" << i;
1007           layerStringId_ = 50500 + i;
1008         }
1009       }
1010     } else if (tTopo_->tobLayer(detId_) == 6) {  // 6st layer
1011       for (unsigned int i = 1; i < 75; i++) {
1012         if (tTopo_->tobRod(detId_) == i) {
1013           layerStringName << "TOB_L6_Rod_" << i;
1014           layerStringId_ = 50600 + i;
1015         }
1016       }
1017     }
1018   }  // TOB
1019 
1020   return std::make_pair(layerStringName.str(), layerStringId_);
1021 }
1022 
1023 std::vector<uint32_t> SiStripBaseCondObjDQM::GetSameLayerDetId(const std::vector<uint32_t> &activeDetIds,
1024                                                                uint32_t selDetId) {
1025   std::vector<uint32_t> sameLayerDetIds;
1026   sameLayerDetIds.clear();
1027 
1028   switch (DetId(selDetId).subdetId()) {
1029     case StripSubdetector::TIB:
1030       SiStripSubStructure::getTIBDetectors(activeDetIds, sameLayerDetIds, tTopo_, tTopo_->tibLayer(selDetId), 0, 0, 0);
1031       break;
1032     case StripSubdetector::TID:
1033       SiStripSubStructure::getTIDDetectors(
1034           activeDetIds, sameLayerDetIds, tTopo_, tTopo_->tidSide(selDetId), tTopo_->tidWheel(selDetId), 0, 0);
1035       break;
1036     case StripSubdetector::TOB:
1037       SiStripSubStructure::getTOBDetectors(activeDetIds, sameLayerDetIds, tTopo_, tTopo_->tobLayer(selDetId), 0, 0);
1038       break;
1039     case StripSubdetector::TEC:
1040       SiStripSubStructure::getTECDetectors(
1041           activeDetIds, sameLayerDetIds, tTopo_, tTopo_->tecSide(selDetId), tTopo_->tecWheel(selDetId), 0, 0, 0, 0);
1042       break;
1043   }
1044 
1045   return sameLayerDetIds;
1046 }
1047 
1048 void SiStripBaseCondObjDQM::bookTkMap(const std::string &TkMapname) { tkMap = new TrackerMap(TkMapname); }
1049 
1050 void SiStripBaseCondObjDQM::fillTkMap(const uint32_t &detid, const float &value) { tkMap->fill(detid, value); }
1051 
1052 void SiStripBaseCondObjDQM::saveTkMap(const std::string &TkMapname, double minValue, double maxValue) {
1053   if (!tkMapScaler.empty()) {
1054     // check that saturation is below x%  below minValue and above minValue, and
1055     // in case re-arrange.
1056     float th = hPSet_.getParameter<double>("saturatedFraction");
1057 
1058     size_t imin = 0, imax = 0;
1059     float entries = 0;
1060     for (size_t i = 0; i < tkMapScaler.size(); ++i)
1061       entries += tkMapScaler[i];
1062 
1063     float min = 0;
1064     for (size_t i = 0; (i < tkMapScaler.size()) && (min < th); ++i) {
1065       min += tkMapScaler[i] / entries;
1066       imin = i;
1067     }
1068 
1069     float max = 0;
1070     // for(size_t i=tkMapScaler.size()-1;(i>=0) && (max<th);--i){ // Wrong
1071     // Since i is unsigned, i >= 0 is always true,
1072     // and the loop termination condition is never reached.
1073     // We offset the loop index by one to fix this.
1074     for (size_t j = tkMapScaler.size(); (j > 0) && (max < th); --j) {
1075       size_t i = j - 1;
1076       max += tkMapScaler[i] / entries;
1077       imax = i;
1078     }
1079 
1080     // reset maxValue;
1081     if (maxValue < imax) {
1082       edm::LogInfo("SiStripBaseCondObjDQM") << "Resetting TkMap maxValue from " << maxValue << " to " << imax;
1083       maxValue = imax;
1084     }
1085     // reset minValue;
1086     if (minValue > imin) {
1087       edm::LogInfo("SiStripBaseCondObjDQM") << "Resetting TkMap minValue from " << minValue << " to " << imin;
1088       minValue = imin;
1089     }
1090   }
1091 
1092   tkMap->save(false, minValue, maxValue, TkMapname, 4500, 2400);
1093   tkMap->setPalette(1);
1094   tkMap->showPalette(true);
1095 }
1096 
1097 void SiStripBaseCondObjDQM::end() {
1098   edm::LogInfo("SiStripBaseCondObjDQM") << "SiStripBaseCondObjDQM::end" << std::endl;
1099 }
1100 
1101 void SiStripBaseCondObjDQM::fillModMEs(const std::vector<uint32_t> &selectedDetIds) {
1102   ModMEs CondObj_ME;
1103   for (const auto det : selectedDetIds) {
1104     fillMEsForDet(CondObj_ME, det);
1105   }
1106 }
1107 
1108 //==========================
1109 void SiStripBaseCondObjDQM::fillSummaryMEs(const std::vector<uint32_t> &selectedDetIds) {
1110   for (const auto det : selectedDetIds) {
1111     fillMEsForLayer(/*SummaryMEsMap_,*/ det);
1112   }
1113 
1114   for (const auto &itm : SummaryMEsMap_) {
1115     ModMEs selME;
1116     selME = itm.second;
1117 
1118     if (hPSet_.getParameter<bool>("FillSummaryProfileAtLayerLevel") &&
1119         fPSet_.getParameter<bool>("OutputSummaryProfileAtLayerLevelAsImage")) {
1120       if (CondObj_fillId_ == "onlyProfile" || CondObj_fillId_ == "ProfileAndCumul") {
1121         TCanvas c1("c1");
1122         selME.SummaryOfProfileDistr->getTProfile()->Draw();
1123         std::string name(selME.SummaryOfProfileDistr->getTProfile()->GetTitle());
1124         name += ".png";
1125         c1.Print(name.c_str());
1126       }
1127     }
1128     if (hPSet_.getParameter<bool>("FillSummaryAtLayerLevel") &&
1129         fPSet_.getParameter<bool>("OutputSummaryAtLayerLevelAsImage")) {
1130       TCanvas c1("c1");
1131       selME.SummaryDistr->getTH1()->Draw();
1132       std::string name(selME.SummaryDistr->getTitle());
1133       name += ".png";
1134       c1.Print(name.c_str());
1135     }
1136     if (hPSet_.getParameter<bool>("FillCumulativeSummaryAtLayerLevel") &&
1137         fPSet_.getParameter<bool>("OutputCumulativeSummaryAtLayerLevelAsImage")) {
1138       if (CondObj_fillId_ == "onlyCumul" || CondObj_fillId_ == "ProfileAndCumul") {
1139         TCanvas c1("c1");
1140         selME.SummaryOfCumulDistr->getTH1()->Draw();
1141         std::string name(selME.SummaryOfCumulDistr->getTitle());
1142         name += ".png";
1143         c1.Print(name.c_str());
1144       }
1145     }
1146   }
1147 }