Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:40

0001 #include "CondFormats/SiStripObjects/interface/PedsFullNoiseAnalysis.h"
0002 #include "DataFormats/SiStripCommon/interface/SiStripHistoTitle.h"
0003 #include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include <iostream>
0006 #include <iomanip>
0007 #include <cmath>
0008 
0009 using namespace sistrip;
0010 
0011 // ----------------------------------------------------------------------------
0012 //
0013 PedsFullNoiseAnalysis::PedsFullNoiseAnalysis(const uint32_t& key)
0014     : CommissioningAnalysis(key, "PedsFullNoiseAnalysis"),
0015       peds_(2, VFloat(128, sistrip::invalid_)),
0016       noise_(2, VFloat(128, sistrip::invalid_)),
0017       raw_(2, VFloat(128, sistrip::invalid_)),
0018       adProbab_(2, VFloat(128, sistrip::invalid_)),
0019       ksProbab_(2, VFloat(128, sistrip::invalid_)),
0020       jbProbab_(2, VFloat(128, sistrip::invalid_)),
0021       chi2Probab_(2, VFloat(128, sistrip::invalid_)),
0022       residualRMS_(2, VFloat(128, sistrip::invalid_)),
0023       residualSigmaGaus_(2, VFloat(128, sistrip::invalid_)),
0024       noiseSignificance_(2, VFloat(128, sistrip::invalid_)),
0025       residualMean_(2, VFloat(128, sistrip::invalid_)),
0026       residualSkewness_(2, VFloat(128, sistrip::invalid_)),
0027       residualKurtosis_(2, VFloat(128, sistrip::invalid_)),
0028       residualIntegralNsigma_(2, VFloat(128, sistrip::invalid_)),
0029       residualIntegral_(2, VFloat(128, sistrip::invalid_)),
0030       badStripBit_(2, VInt(128, sistrip::invalid_)),
0031       deadStripBit_(2, VInt(128, sistrip::invalid_)),
0032       deadStrip_(2, VInt(0, sistrip::invalid_)),
0033       badStrip_(2, VInt(0, sistrip::invalid_)),
0034       shiftedStrip_(2, VInt(0, sistrip::invalid_)),
0035       lowNoiseStrip_(2, VInt(0, sistrip::invalid_)),
0036       largeNoiseStrip_(2, VInt(0, sistrip::invalid_)),
0037       largeNoiseSignificance_(2, VInt(0, sistrip::invalid_)),
0038       badFitStatus_(2, VInt(0, sistrip::invalid_)),
0039       badADProbab_(2, VInt(0, sistrip::invalid_)),
0040       badKSProbab_(2, VInt(0, sistrip::invalid_)),
0041       badJBProbab_(2, VInt(0, sistrip::invalid_)),
0042       badChi2Probab_(2, VInt(0, sistrip::invalid_)),
0043       badTailStrip_(2, VInt(0, sistrip::invalid_)),
0044       badDoublePeakStrip_(2, VInt(0, sistrip::invalid_)),
0045       pedsMean_(2, sistrip::invalid_),
0046       pedsSpread_(2, sistrip::invalid_),
0047       noiseMean_(2, sistrip::invalid_),
0048       noiseSpread_(2, sistrip::invalid_),
0049       rawMean_(2, sistrip::invalid_),
0050       rawSpread_(2, sistrip::invalid_),
0051       pedsMax_(2, sistrip::invalid_),
0052       pedsMin_(2, sistrip::invalid_),
0053       noiseMax_(2, sistrip::invalid_),
0054       noiseMin_(2, sistrip::invalid_),
0055       rawMax_(2, sistrip::invalid_),
0056       rawMin_(2, sistrip::invalid_),
0057       legacy_(false) {
0058   // for flag bits one reserve at max 128 positions since will be filled with strip id only if the strip is bad
0059   for (auto iapv : deadStrip_)
0060     iapv.reserve(128);
0061   for (auto iapv : badStrip_)
0062     iapv.reserve(128);
0063   for (auto iapv : shiftedStrip_)
0064     iapv.reserve(128);
0065   for (auto iapv : lowNoiseStrip_)
0066     iapv.reserve(128);
0067   for (auto iapv : largeNoiseStrip_)
0068     iapv.reserve(128);
0069   for (auto iapv : largeNoiseSignificance_)
0070     iapv.reserve(128);
0071   for (auto iapv : badFitStatus_)
0072     iapv.reserve(128);
0073   for (auto iapv : badADProbab_)
0074     iapv.reserve(128);
0075   for (auto iapv : badKSProbab_)
0076     iapv.reserve(128);
0077   for (auto iapv : badJBProbab_)
0078     iapv.reserve(128);
0079   for (auto iapv : badChi2Probab_)
0080     iapv.reserve(128);
0081   for (auto iapv : badTailStrip_)
0082     iapv.reserve(128);
0083   for (auto iapv : badDoublePeakStrip_)
0084     iapv.reserve(128);
0085 }
0086 
0087 // ----------------------------------------------------------------------------
0088 //
0089 PedsFullNoiseAnalysis::PedsFullNoiseAnalysis()
0090     : CommissioningAnalysis("PedsFullNoiseAnalysis"),
0091       peds_(2, VFloat(128, sistrip::invalid_)),
0092       noise_(2, VFloat(128, sistrip::invalid_)),
0093       raw_(2, VFloat(128, sistrip::invalid_)),
0094       adProbab_(2, VFloat(128, sistrip::invalid_)),
0095       ksProbab_(2, VFloat(128, sistrip::invalid_)),
0096       jbProbab_(2, VFloat(128, sistrip::invalid_)),
0097       chi2Probab_(2, VFloat(128, sistrip::invalid_)),
0098       residualRMS_(2, VFloat(128, sistrip::invalid_)),
0099       residualSigmaGaus_(2, VFloat(128, sistrip::invalid_)),
0100       noiseSignificance_(2, VFloat(128, sistrip::invalid_)),
0101       residualMean_(2, VFloat(128, sistrip::invalid_)),
0102       residualSkewness_(2, VFloat(128, sistrip::invalid_)),
0103       residualKurtosis_(2, VFloat(128, sistrip::invalid_)),
0104       residualIntegralNsigma_(2, VFloat(128, sistrip::invalid_)),
0105       residualIntegral_(2, VFloat(128, sistrip::invalid_)),
0106       badStripBit_(2, VInt(128, sistrip::invalid_)),
0107       deadStripBit_(2, VInt(128, sistrip::invalid_)),
0108       deadStrip_(2, VInt(0, sistrip::invalid_)),
0109       badStrip_(2, VInt(0, sistrip::invalid_)),
0110       shiftedStrip_(2, VInt(0, sistrip::invalid_)),
0111       lowNoiseStrip_(2, VInt(0, sistrip::invalid_)),
0112       largeNoiseStrip_(2, VInt(0, sistrip::invalid_)),
0113       largeNoiseSignificance_(2, VInt(0, sistrip::invalid_)),
0114       badFitStatus_(2, VInt(0, sistrip::invalid_)),
0115       badADProbab_(2, VInt(0, sistrip::invalid_)),
0116       badKSProbab_(2, VInt(0, sistrip::invalid_)),
0117       badJBProbab_(2, VInt(0, sistrip::invalid_)),
0118       badChi2Probab_(2, VInt(0, sistrip::invalid_)),
0119       badTailStrip_(2, VInt(0, sistrip::invalid_)),
0120       badDoublePeakStrip_(2, VInt(128, sistrip::invalid_)),
0121       pedsMean_(2, sistrip::invalid_),
0122       pedsSpread_(2, sistrip::invalid_),
0123       noiseMean_(2, sistrip::invalid_),
0124       noiseSpread_(2, sistrip::invalid_),
0125       rawMean_(2, sistrip::invalid_),
0126       rawSpread_(2, sistrip::invalid_),
0127       pedsMax_(2, sistrip::invalid_),
0128       pedsMin_(2, sistrip::invalid_),
0129       noiseMax_(2, sistrip::invalid_),
0130       noiseMin_(2, sistrip::invalid_),
0131       rawMax_(2, sistrip::invalid_),
0132       rawMin_(2, sistrip::invalid_),
0133       legacy_(false) {
0134   // for flag bits one reserve at max 128 positions since will be filled with strip id only if the strip is bad
0135   for (auto iapv : deadStrip_)
0136     iapv.reserve(128);
0137   for (auto iapv : badStrip_)
0138     iapv.reserve(128);
0139   for (auto iapv : shiftedStrip_)
0140     iapv.reserve(128);
0141   for (auto iapv : lowNoiseStrip_)
0142     iapv.reserve(128);
0143   for (auto iapv : largeNoiseStrip_)
0144     iapv.reserve(128);
0145   for (auto iapv : largeNoiseSignificance_)
0146     iapv.reserve(128);
0147   for (auto iapv : badFitStatus_)
0148     iapv.reserve(128);
0149   for (auto iapv : badADProbab_)
0150     iapv.reserve(128);
0151   for (auto iapv : badKSProbab_)
0152     iapv.reserve(128);
0153   for (auto iapv : badJBProbab_)
0154     iapv.reserve(128);
0155   for (auto iapv : badChi2Probab_)
0156     iapv.reserve(128);
0157   for (auto iapv : badTailStrip_)
0158     iapv.reserve(128);
0159   for (auto iapv : badDoublePeakStrip_)
0160     iapv.reserve(128);
0161 }
0162 
0163 // ----------------------------------------------------------------------------
0164 //
0165 void PedsFullNoiseAnalysis::reset() {
0166   peds_ = VVFloat(2, VFloat(128, sistrip::invalid_));
0167   noise_ = VVFloat(2, VFloat(128, sistrip::invalid_));
0168   raw_ = VVFloat(2, VFloat(128, sistrip::invalid_));
0169   adProbab_ = VVFloat(2, VFloat(128, sistrip::invalid_));
0170   ksProbab_ = VVFloat(2, VFloat(128, sistrip::invalid_));
0171   jbProbab_ = VVFloat(2, VFloat(128, sistrip::invalid_));
0172   chi2Probab_ = VVFloat(2, VFloat(128, sistrip::invalid_));
0173   residualRMS_ = VVFloat(2, VFloat(128, sistrip::invalid_));
0174   residualSigmaGaus_ = VVFloat(2, VFloat(128, sistrip::invalid_));
0175   noiseSignificance_ = VVFloat(2, VFloat(128, sistrip::invalid_));
0176   residualMean_ = VVFloat(2, VFloat(128, sistrip::invalid_));
0177   residualSkewness_ = VVFloat(2, VFloat(128, sistrip::invalid_));
0178   residualKurtosis_ = VVFloat(2, VFloat(128, sistrip::invalid_));
0179   residualIntegralNsigma_ = VVFloat(2, VFloat(128, sistrip::invalid_));
0180   residualIntegral_ = VVFloat(2, VFloat(128, sistrip::invalid_));
0181 
0182   deadStrip_ = VVInt(2, VInt(0, sistrip::invalid_));
0183   badStrip_ = VVInt(2, VInt(0, sistrip::invalid_));
0184   badStripBit_ = VVInt(2, VInt(128, sistrip::invalid_));
0185   deadStripBit_ = VVInt(2, VInt(128, sistrip::invalid_));
0186   shiftedStrip_ = VVInt(2, VInt(0, sistrip::invalid_));
0187   lowNoiseStrip_ = VVInt(2, VInt(0, sistrip::invalid_));
0188   largeNoiseStrip_ = VVInt(2, VInt(0, sistrip::invalid_));
0189   largeNoiseSignificance_ = VVInt(2, VInt(0, sistrip::invalid_));
0190   badFitStatus_ = VVInt(2, VInt(0, sistrip::invalid_));
0191   badADProbab_ = VVInt(2, VInt(0, sistrip::invalid_));
0192   badKSProbab_ = VVInt(2, VInt(0, sistrip::invalid_));
0193   badJBProbab_ = VVInt(2, VInt(0, sistrip::invalid_));
0194   badChi2Probab_ = VVInt(2, VInt(0, sistrip::invalid_));
0195   badTailStrip_ = VVInt(2, VInt(0, sistrip::invalid_));
0196   badDoublePeakStrip_ = VVInt(2, VInt(0, sistrip::invalid_));
0197 
0198   // for flag bits one reserve at max 128 positions since will be filled with strip id only if the strip is bad
0199   for (auto iapv : deadStrip_)
0200     iapv.reserve(128);
0201   for (auto iapv : badStrip_)
0202     iapv.reserve(128);
0203   for (auto iapv : shiftedStrip_)
0204     iapv.reserve(128);
0205   for (auto iapv : lowNoiseStrip_)
0206     iapv.reserve(128);
0207   for (auto iapv : largeNoiseStrip_)
0208     iapv.reserve(128);
0209   for (auto iapv : largeNoiseSignificance_)
0210     iapv.reserve(128);
0211   for (auto iapv : badFitStatus_)
0212     iapv.reserve(128);
0213   for (auto iapv : badADProbab_)
0214     iapv.reserve(128);
0215   for (auto iapv : badKSProbab_)
0216     iapv.reserve(128);
0217   for (auto iapv : badJBProbab_)
0218     iapv.reserve(128);
0219   for (auto iapv : badChi2Probab_)
0220     iapv.reserve(128);
0221   for (auto iapv : badTailStrip_)
0222     iapv.reserve(128);
0223   for (auto iapv : badDoublePeakStrip_)
0224     iapv.reserve(128);
0225 
0226   pedsMean_ = VFloat(2, sistrip::invalid_);
0227   pedsSpread_ = VFloat(2, sistrip::invalid_);
0228   noiseMean_ = VFloat(2, sistrip::invalid_);
0229   noiseSpread_ = VFloat(2, sistrip::invalid_);
0230   rawMean_ = VFloat(2, sistrip::invalid_);
0231   rawSpread_ = VFloat(2, sistrip::invalid_);
0232   pedsMax_ = VFloat(2, sistrip::invalid_);
0233   pedsMin_ = VFloat(2, sistrip::invalid_);
0234   noiseMax_ = VFloat(2, sistrip::invalid_);
0235   noiseMin_ = VFloat(2, sistrip::invalid_);
0236   rawMax_ = VFloat(2, sistrip::invalid_);
0237   rawMin_ = VFloat(2, sistrip::invalid_);
0238 
0239   legacy_ = false;
0240 }
0241 
0242 // ----------------------------------------------------------------------------
0243 //
0244 bool PedsFullNoiseAnalysis::isValid() const {
0245   return (pedsMean_[0] < sistrip::maximum_ && pedsMean_[1] < sistrip::maximum_ && pedsSpread_[0] < sistrip::maximum_ &&
0246           pedsSpread_[1] < sistrip::maximum_ && noiseMean_[0] < sistrip::maximum_ &&
0247           noiseMean_[1] < sistrip::maximum_ && noiseSpread_[0] < sistrip::maximum_ &&
0248           noiseSpread_[1] < sistrip::maximum_ && rawMean_[0] < sistrip::maximum_ && rawMean_[1] < sistrip::maximum_ &&
0249           rawSpread_[0] < sistrip::maximum_ && rawSpread_[1] < sistrip::maximum_ && pedsMax_[0] < sistrip::maximum_ &&
0250           pedsMax_[1] < sistrip::maximum_ && pedsMin_[0] < sistrip::maximum_ && pedsMin_[1] < sistrip::maximum_ &&
0251           noiseMax_[0] < sistrip::maximum_ && noiseMax_[1] < sistrip::maximum_ && noiseMin_[0] < sistrip::maximum_ &&
0252           noiseMin_[1] < sistrip::maximum_ && rawMax_[0] < sistrip::maximum_ && rawMax_[1] < sistrip::maximum_ &&
0253           rawMin_[0] < sistrip::maximum_ && rawMin_[1] < sistrip::maximum_ && getErrorCodes().empty());
0254 }
0255 
0256 // ----------------------------------------------------------------------------
0257 //
0258 void PedsFullNoiseAnalysis::summary(std::stringstream& ss) const {
0259   SiStripFecKey fec_key(fecKey());
0260   SiStripFedKey fed_key(fedKey());
0261 
0262   sistrip::RunType type = SiStripEnumsAndStrings::runType(myName());
0263 
0264   std::stringstream extra1, extra2, extra3;
0265   if (legacy_) {
0266     extra1 << sistrip::extrainfo::pedsAndRawNoise_;
0267     extra2 << sistrip::extrainfo::pedsAndCmSubNoise_;
0268     extra3 << sistrip::extrainfo::commonMode_;
0269   } else {
0270     extra1 << sistrip::extrainfo::pedestals_;
0271     extra2 << sistrip::extrainfo::rawNoise_;
0272     extra3 << sistrip::extrainfo::commonMode_;
0273   }
0274 
0275   std::string title1 = SiStripHistoTitle(sistrip::EXPERT_HISTO,
0276                                          type,
0277                                          sistrip::FED_KEY,
0278                                          fed_key.key(),
0279                                          sistrip::LLD_CHAN,
0280                                          fec_key.lldChan(),
0281                                          extra1.str())
0282                            .title();
0283   std::string title2 = SiStripHistoTitle(sistrip::EXPERT_HISTO,
0284                                          type,
0285                                          sistrip::FED_KEY,
0286                                          fed_key.key(),
0287                                          sistrip::LLD_CHAN,
0288                                          fec_key.lldChan(),
0289                                          extra2.str())
0290                            .title();
0291   std::string title3 = SiStripHistoTitle(sistrip::EXPERT_HISTO,
0292                                          type,
0293                                          sistrip::FED_KEY,
0294                                          fed_key.key(),
0295                                          sistrip::APV,
0296                                          SiStripFecKey::i2cAddr(fec_key.lldChan(), true),
0297                                          extra3.str())
0298                            .title();
0299   std::string title4 = SiStripHistoTitle(sistrip::EXPERT_HISTO,
0300                                          type,
0301                                          sistrip::FED_KEY,
0302                                          fed_key.key(),
0303                                          sistrip::APV,
0304                                          SiStripFecKey::i2cAddr(fec_key.lldChan(), false),
0305                                          extra3.str())
0306                            .title();
0307 
0308   ss << " Summary"
0309      << ":" << (isValid() ? "Valid" : "Invalid") << ":" << sistrip::controlView_ << ":" << fec_key.fecCrate() << "/"
0310      << fec_key.fecSlot() << "/" << fec_key.fecRing() << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << ":"
0311      << sistrip::dqmRoot_ << sistrip::dir_ << "Collate" << sistrip::dir_
0312      << SiStripFecKey(fec_key.fecCrate(), fec_key.fecSlot(), fec_key.fecRing(), fec_key.ccuAddr(), fec_key.ccuChan())
0313             .path()
0314      << ":" << title1 << ";" << title2 << ";" << title3 << ";" << title4 << std::endl;
0315 }
0316 
0317 // ----------------------------------------------------------------------------
0318 //
0319 void PedsFullNoiseAnalysis::print(std::stringstream& ss, uint32_t iapv) {
0320   if (iapv == 1 || iapv == 2) {
0321     iapv--;
0322   } else {
0323     iapv = 0;
0324   }
0325 
0326   if (peds_[iapv].size() < 128 || noise_[iapv].size() < 128 || raw_[iapv].size() < 128) {
0327     edm::LogWarning(mlCommissioning_) << "[" << myName() << "::" << __func__ << "]"
0328                                       << " Unexpected number of pedestal/noise values: " << peds_[iapv].size() << ", "
0329                                       << noise_[iapv].size() << ", " << raw_[iapv].size();
0330     return;
0331   }
0332 
0333   header(ss);
0334   ss << " Monitorables for APV number     : " << iapv;
0335   if (iapv == 0) {
0336     ss << " (first of pair)";
0337   } else if (iapv == 1) {
0338     ss << " (second of pair)";
0339   }
0340   ss << std::endl;
0341   ss << std::fixed << std::setprecision(2);
0342   ss << " Example peds/noise for strips   : "
0343      << "     0,     31,     63,    127" << std::endl
0344      << "  Peds                     [ADC] : " << std::setw(6) << peds_[iapv][0] << ", " << std::setw(6)
0345      << peds_[iapv][31] << ", " << std::setw(6) << peds_[iapv][63] << ", " << std::setw(6) << peds_[iapv][127]
0346      << std::endl
0347      << "  Noise                    [ADC] : " << std::setw(6) << noise_[iapv][0] << ", " << std::setw(6)
0348      << noise_[iapv][31] << ", " << std::setw(6) << noise_[iapv][63] << ", " << std::setw(6) << noise_[iapv][127]
0349      << std::endl
0350      << "  Raw noise                [ADC] : " << std::setw(6) << raw_[iapv][0] << ", " << std::setw(6) << raw_[iapv][31]
0351      << ", " << std::setw(6) << raw_[iapv][63] << ", " << std::setw(6) << raw_[iapv][127] << std::endl
0352      << " Dead strips (<5s)       [strip] : (" << deadStrip_[iapv].size() << " in total) ";
0353 
0354   for (uint16_t ii = 0; ii < deadStrip_[iapv].size(); ii++) {
0355     ss << deadStrip_[iapv][ii] << " ";
0356   }
0357 
0358   ss << std::endl;
0359   ss << " Bad strips (>5s)      [strip] : (" << badStrip_[iapv].size() << " in total) ";
0360   for (uint16_t ii = 0; ii < badStrip_[iapv].size(); ii++) {
0361     ss << badStrip_[iapv][ii] << " ";
0362   }
0363   ss << std::endl;
0364   ss << " Mean peds +/- spread      [ADC] : " << pedsMean_[iapv] << " +/- " << pedsSpread_[iapv] << std::endl
0365      << " Min/Max pedestal          [ADC] : " << pedsMin_[iapv] << " <-> " << pedsMax_[iapv] << std::endl
0366      << " Mean noise +/- spread     [ADC] : " << noiseMean_[iapv] << " +/- " << noiseSpread_[iapv] << std::endl
0367      << " Min/Max noise             [ADC] : " << noiseMin_[iapv] << " <-> " << noiseMax_[iapv] << std::endl
0368      << " Mean raw noise +/- spread [ADC] : " << rawMean_[iapv] << " +/- " << rawSpread_[iapv] << std::endl
0369      << " Min/Max raw noise         [ADC] : " << rawMin_[iapv] << " <-> " << rawMax_[iapv] << std::endl
0370      << " Normalised noise                : "
0371      << "(yet to be implemented...)" << std::endl
0372      << std::boolalpha << " isValid                         : " << isValid() << std::endl
0373      << std::noboolalpha << " Error codes (found " << std::setw(2) << std::setfill(' ') << getErrorCodes().size()
0374      << ")          : ";
0375   if (getErrorCodes().empty()) {
0376     ss << "(none)";
0377   } else {
0378     VString::const_iterator istr = getErrorCodes().begin();
0379     VString::const_iterator jstr = getErrorCodes().end();
0380     for (; istr != jstr; ++istr) {
0381       ss << *istr << " ";
0382     }
0383   }
0384   ss << std::endl;
0385 }