File indexing completed on 2024-04-06 12:08:34
0001
0002 #include "DQM/SiStripCommissioningDbClients/interface/PedsFullNoiseHistosUsingDb.h"
0003 #include "CondFormats/SiStripObjects/interface/PedsFullNoiseAnalysis.h"
0004 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0005 #include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
0006 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include <iostream>
0009
0010 using namespace sistrip;
0011
0012
0013
0014 PedsFullNoiseHistosUsingDb::PedsFullNoiseHistosUsingDb(const edm::ParameterSet& pset,
0015 DQMStore* bei,
0016 SiStripConfigDb* const db,
0017 edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken)
0018 : CommissioningHistograms(
0019 pset.getParameter<edm::ParameterSet>("PedsFullNoiseParameters"), bei, sistrip::PEDS_FULL_NOISE),
0020 CommissioningHistosUsingDb(db, tTopoToken, sistrip::PEDS_FULL_NOISE),
0021 PedsFullNoiseHistograms(pset.getParameter<edm::ParameterSet>("PedsFullNoiseParameters"), bei) {
0022 LogTrace(mlDqmClient_) << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
0023 << " Constructing object...";
0024
0025 highThreshold_ = this->pset().getParameter<double>("HighThreshold");
0026 lowThreshold_ = this->pset().getParameter<double>("LowThreshold");
0027
0028 LogTrace(mlDqmClient_) << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
0029 << " Set FED zero suppression high/low threshold to " << highThreshold_ << "/"
0030 << lowThreshold_;
0031
0032 disableBadStrips_ = this->pset().getParameter<bool>("DisableBadStrips");
0033 keepStripsDisabled_ = this->pset().getParameter<bool>("KeepStripsDisabled");
0034 skipEmptyStrips_ = this->pset().getParameter<bool>("SkipEmptyStrips");
0035 uploadOnlyStripBadChannelBit_ = this->pset().getParameter<bool>("UploadOnlyStripBadChannelBit");
0036 uploadPedsFullNoiseDBTable_ = this->pset().getParameter<bool>("UploadPedsFullNoiseDBTable");
0037
0038 LogTrace(mlDqmClient_) << "[PedestalsHistosUsingDb::" << __func__ << "]"
0039 << " Disabling strips: " << disableBadStrips_
0040 << " ; keeping previously disabled strips: " << keepStripsDisabled_
0041 << " ; skip strips with no data: " << skipEmptyStrips_
0042 << " ; upload only bad channel bit: " << uploadOnlyStripBadChannelBit_;
0043
0044 allowSelectiveUpload_ =
0045 this->pset().existsAs<bool>("doSelectiveUpload") ? this->pset().getParameter<bool>("doSelectiveUpload") : false;
0046 LogTrace(mlDqmClient_) << "[PedestalsHistosUsingDb::" << __func__ << "]"
0047 << " Selective upload of modules set to : " << allowSelectiveUpload_;
0048 }
0049
0050
0051
0052 PedsFullNoiseHistosUsingDb::~PedsFullNoiseHistosUsingDb() {
0053 LogTrace(mlDqmClient_) << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
0054 << " Destructing object...";
0055 }
0056
0057
0058
0059 void PedsFullNoiseHistosUsingDb::uploadConfigurations() {
0060 LogTrace(mlDqmClient_) << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]";
0061
0062 if (!db()) {
0063 edm::LogError(mlDqmClient_) << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
0064 << " NULL pointer to SiStripConfigDb interface!"
0065 << " Aborting upload...";
0066 return;
0067 }
0068
0069
0070 SiStripConfigDb::FedDescriptionsRange feds = db()->getFedDescriptions();
0071 update(feds);
0072 if (doUploadConf()) {
0073
0074 edm::LogVerbatim(mlDqmClient_) << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
0075 << " Uploading pedestals/noise to DB...";
0076
0077 db()->uploadFedDescriptions();
0078
0079 edm::LogVerbatim(mlDqmClient_) << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
0080 << " Completed database upload of " << feds.size() << " FED descriptions!";
0081 } else {
0082 edm::LogWarning(mlDqmClient_) << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
0083 << " TEST! No pedestals/noise values will be uploaded to DB...";
0084 }
0085 }
0086
0087
0088
0089 void PedsFullNoiseHistosUsingDb::update(SiStripConfigDb::FedDescriptionsRange feds) {
0090
0091 uint16_t updated = 0;
0092 SiStripConfigDb::FedDescriptionsV::const_iterator ifed;
0093
0094 for (ifed = feds.begin(); ifed != feds.end(); ifed++) {
0095
0096 for (uint16_t ichan = 0; ichan < sistrip::FEDCH_PER_FED; ichan++) {
0097
0098 const FedChannelConnection& conn = cabling()->fedConnection((*ifed)->getFedId(), ichan);
0099 if (conn.fecCrate() == sistrip::invalid_ || conn.fecSlot() == sistrip::invalid_ ||
0100 conn.fecRing() == sistrip::invalid_ || conn.ccuAddr() == sistrip::invalid_ ||
0101 conn.ccuChan() == sistrip::invalid_ || conn.lldChannel() == sistrip::invalid_)
0102 continue;
0103
0104
0105 SiStripFedKey fed_key(conn.fedId(), SiStripFedKey::feUnit(conn.fedCh()), SiStripFedKey::feChan(conn.fedCh()));
0106
0107 SiStripFecKey fec_key(
0108 conn.fecCrate(), conn.fecSlot(), conn.fecRing(), conn.ccuAddr(), conn.ccuChan(), conn.lldChannel());
0109
0110
0111 Analyses::const_iterator iter = data(allowSelectiveUpload_).find(fec_key.key());
0112 if (iter != data(allowSelectiveUpload_).end()) {
0113 PedsFullNoiseAnalysis* anal = dynamic_cast<PedsFullNoiseAnalysis*>(iter->second);
0114
0115 if (!anal) {
0116 edm::LogError(mlDqmClient_) << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
0117 << " NULL pointer to analysis object!";
0118 continue;
0119 }
0120
0121
0122 uint32_t pedshift = 127;
0123 for (uint16_t iapv = 0; iapv < sistrip::APVS_PER_FEDCH; iapv++) {
0124 uint32_t pedmin = (uint32_t)anal->pedsMin()[iapv];
0125 pedshift = pedmin < pedshift ? pedmin : pedshift;
0126 }
0127
0128
0129 for (uint16_t iapv = 0; iapv < sistrip::APVS_PER_FEDCH; iapv++) {
0130 for (uint16_t istr = 0; istr < anal->peds()[iapv].size(); istr++) {
0131
0132 if (not uploadOnlyStripBadChannelBit_ and anal->peds()[iapv][istr] < 1.) {
0133 edm::LogWarning(mlDqmClient_)
0134 << "[PedestalsHistosUsingDb::" << __func__ << "]"
0135 << " Skipping ZERO pedestal value (ie, NO UPLOAD TO DB!) for FedKey/Id/Ch: " << hex << setw(8)
0136 << setfill('0') << fed_key.key() << dec << "/" << (*ifed)->getFedId() << "/" << ichan
0137 << " and device with FEC/slot/ring/CCU/LLD " << fec_key.fecCrate() << "/" << fec_key.fecSlot() << "/"
0138 << fec_key.fecRing() << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << "/"
0139 << fec_key.channel();
0140 continue;
0141 }
0142
0143
0144 Fed9U::Fed9UAddress addr(ichan, iapv, istr);
0145 Fed9U::Fed9UStripDescription temp = (*ifed)->getFedStrips().getStrip(addr);
0146
0147
0148 bool disableStrip = false;
0149 std::stringstream ss_disable;
0150
0151 if (temp.getDisable()) {
0152 ss_disable << "Already Disabled: " << conn.fecCrate() << " " << conn.fecSlot() << " " << conn.fecRing()
0153 << " " << conn.ccuAddr() << " " << conn.ccuChan() << " " << conn.lldChannel() << " " << iapv
0154 << " " << istr << std::endl;
0155 if (keepStripsDisabled_)
0156 disableStrip = true;
0157 }
0158
0159
0160 if (disableBadStrips_) {
0161 SiStripFedKey fed_key(anal->fedKey());
0162 PedsFullNoiseAnalysis::VInt dead = anal->deadStrip()[iapv];
0163 if (not skipEmptyStrips_ and
0164 find(dead.begin(), dead.end(), istr) != dead.end()) {
0165 disableStrip = true;
0166 ss_disable << "Disabling Dead Strip: " << conn.fecCrate() << " " << conn.fecSlot() << " "
0167 << conn.fecRing() << " " << conn.ccuAddr() << " " << conn.ccuChan() << " "
0168 << conn.lldChannel() << " " << iapv << " " << istr << std::endl;
0169 }
0170
0171 PedsFullNoiseAnalysis::VInt badcChan =
0172 anal->badStrip()[iapv];
0173 if (not disableStrip) {
0174 if (find(badcChan.begin(), badcChan.end(), istr) != badcChan.end()) {
0175 disableStrip = true;
0176 ss_disable << "Disabling Bad strip: " << conn.fecCrate() << " " << conn.fecSlot() << " "
0177 << conn.fecRing() << " " << conn.ccuAddr() << " " << conn.ccuChan() << " "
0178 << conn.lldChannel() << " " << iapv << " " << istr << std::endl;
0179 }
0180 }
0181 }
0182
0183 if (edm::isDebugEnabled())
0184 LogTrace(mlDqmClient_) << ss_disable.str();
0185
0186 uint32_t pedestalVal = 0;
0187 float noiseVal = 0;
0188 float lowThr = 0;
0189 float highThr = 0;
0190
0191
0192 if (uploadOnlyStripBadChannelBit_) {
0193 pedestalVal = static_cast<uint32_t>(temp.getPedestal());
0194 noiseVal = static_cast<float>(temp.getNoise());
0195 lowThr = static_cast<float>(temp.getLowThresholdFactor());
0196 highThr = static_cast<float>(temp.getHighThresholdFactor());
0197 } else {
0198 pedestalVal = static_cast<uint32_t>(anal->peds()[iapv][istr] - pedshift);
0199 noiseVal = anal->noise()[iapv][istr];
0200 lowThr = lowThreshold_;
0201 highThr = highThreshold_;
0202 }
0203
0204
0205 Fed9U::Fed9UStripDescription data(pedestalVal, highThr, lowThr, noiseVal, disableStrip);
0206
0207 std::stringstream ss;
0208 if (data.getDisable() && edm::isDebugEnabled()) {
0209 ss << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
0210 << " Disabling strip in Fed9UStripDescription object..." << std::endl
0211 << " for FED id/channel and APV/strip : " << fed_key.fedId() << "/" << fed_key.fedChannel() << " "
0212 << iapv << "/" << istr << std::endl
0213 << " and crate/FEC/ring/CCU/module : " << fec_key.fecCrate() << "/" << fec_key.fecSlot() << "/"
0214 << fec_key.fecRing() << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << std::endl
0215 << " from ped/noise/high/low/disable : " << static_cast<uint32_t>(temp.getPedestal()) << "/"
0216 << static_cast<float>(temp.getHighThresholdFactor()) << "/"
0217 << static_cast<float>(temp.getLowThresholdFactor()) << "/" << static_cast<float>(temp.getNoise())
0218 << "/" << static_cast<uint16_t>(temp.getDisable()) << std::endl;
0219 }
0220
0221 (*ifed)->getFedStrips().setStrip(addr, data);
0222
0223 if (data.getDisable() && edm::isDebugEnabled()) {
0224 ss << " to ped/noise/high/low/disable : " << static_cast<uint32_t>(data.getPedestal()) << "/"
0225 << static_cast<float>(data.getHighThresholdFactor()) << "/"
0226 << static_cast<float>(data.getLowThresholdFactor()) << "/" << static_cast<float>(data.getNoise())
0227 << "/" << static_cast<uint16_t>(data.getDisable()) << std::endl;
0228 LogTrace(mlDqmClient_) << ss.str();
0229 }
0230 }
0231 }
0232 updated++;
0233 } else {
0234 if (deviceIsPresent(fec_key)) {
0235 edm::LogWarning(mlDqmClient_) << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
0236 << " Unable to find pedestals/noise for FedKey/Id/Ch: " << hex << setw(8)
0237 << setfill('0') << fed_key.key() << dec << "/" << (*ifed)->getFedId() << "/"
0238 << ichan << " and device with FEC/slot/ring/CCU/LLD " << fec_key.fecCrate()
0239 << "/" << fec_key.fecSlot() << "/" << fec_key.fecRing() << "/"
0240 << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << "/" << fec_key.channel();
0241 }
0242 }
0243 }
0244 }
0245
0246 edm::LogVerbatim(mlDqmClient_) << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
0247 << " Updated FED pedestals/noise for " << updated << " channels";
0248 }
0249
0250
0251
0252 void PedsFullNoiseHistosUsingDb::create(SiStripConfigDb::AnalysisDescriptionsV& desc, Analysis analysis) {
0253 PedsFullNoiseAnalysis* anal = dynamic_cast<PedsFullNoiseAnalysis*>(analysis->second);
0254
0255 if (!anal) {
0256 return;
0257 }
0258
0259 SiStripFecKey fec_key(anal->fecKey());
0260 SiStripFedKey fed_key(anal->fedKey());
0261
0262 for (uint16_t iapv = 0; iapv < 2; ++iapv) {
0263
0264 PedestalsAnalysisDescription* pedestalDescription;
0265 pedestalDescription =
0266 new PedestalsAnalysisDescription(anal->deadStripBit()[iapv],
0267 anal->badStripBit()[iapv],
0268 anal->pedsMean()[iapv],
0269 anal->pedsSpread()[iapv],
0270 anal->noiseMean()[iapv],
0271 anal->noiseSpread()[iapv],
0272 anal->rawMean()[iapv],
0273 anal->rawSpread()[iapv],
0274 anal->pedsMax()[iapv],
0275 anal->pedsMin()[iapv],
0276 anal->noiseMax()[iapv],
0277 anal->noiseMin()[iapv],
0278 anal->rawMax()[iapv],
0279 anal->rawMin()[iapv],
0280 fec_key.fecCrate(),
0281 fec_key.fecSlot(),
0282 fec_key.fecRing(),
0283 fec_key.ccuAddr(),
0284 fec_key.ccuChan(),
0285 SiStripFecKey::i2cAddr(fec_key.lldChan(), !iapv),
0286 db()->dbParams().partitions().begin()->second.partitionName(),
0287 db()->dbParams().partitions().begin()->second.runNumber(),
0288 anal->isValid(),
0289 "",
0290 fed_key.fedId(),
0291 fed_key.feUnit(),
0292 fed_key.feChan(),
0293 fed_key.fedApv());
0294
0295
0296 typedef std::vector<std::string> Strings;
0297 Strings errors = anal->getErrorCodes();
0298 Strings::const_iterator istr = errors.begin();
0299 Strings::const_iterator jstr = errors.end();
0300 for (; istr != jstr; ++istr) {
0301 pedestalDescription->addComments(*istr);
0302 }
0303
0304
0305 desc.push_back(pedestalDescription);
0306
0307
0308 if (uploadPedsFullNoiseDBTable_) {
0309 PedsFullNoiseAnalysisDescription* pedsFullNoiseDescription;
0310 pedsFullNoiseDescription = new PedsFullNoiseAnalysisDescription(
0311 anal->deadStrip()[iapv],
0312 anal->badStrip()[iapv],
0313 anal->shiftedStrip()[iapv],
0314 anal->lowNoiseStrip()[iapv],
0315 anal->largeNoiseStrip()[iapv],
0316 anal->largeNoiseSignificance()[iapv],
0317 anal->badFitStatus()[iapv],
0318 anal->badADProbab()[iapv],
0319 anal->badKSProbab()[iapv],
0320 anal->badJBProbab()[iapv],
0321 anal->badChi2Probab()[iapv],
0322 anal->badTailStrip()[iapv],
0323 anal->badDoublePeakStrip()[iapv],
0324
0325 anal->adProbab()[iapv],
0326 anal->ksProbab()[iapv],
0327 anal->jbProbab()[iapv],
0328 anal->chi2Probab()[iapv],
0329
0330 anal->residualRMS()[iapv],
0331 anal->residualSigmaGaus()[iapv],
0332 anal->noiseSignificance()[iapv],
0333 anal->residualSkewness()[iapv],
0334 anal->residualKurtosis()[iapv],
0335 anal->residualIntegralNsigma()[iapv],
0336 anal->residualIntegral()[iapv],
0337
0338 fec_key.fecCrate(),
0339 fec_key.fecSlot(),
0340 fec_key.fecRing(),
0341 fec_key.ccuAddr(),
0342 fec_key.ccuChan(),
0343 SiStripFecKey::i2cAddr(fec_key.lldChan(), !iapv),
0344 db()->dbParams().partitions().begin()->second.partitionName(),
0345 db()->dbParams().partitions().begin()->second.runNumber(),
0346 anal->isValid(),
0347 "",
0348 fed_key.fedId(),
0349 fed_key.feUnit(),
0350 fed_key.feChan(),
0351 fed_key.fedApv());
0352 istr = errors.begin();
0353 jstr = errors.end();
0354 for (; istr != jstr; ++istr) {
0355 pedsFullNoiseDescription->addComments(*istr);
0356 }
0357
0358
0359 desc.push_back(pedsFullNoiseDescription);
0360 }
0361 }
0362 }