Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "CondFormats/SiStripObjects/interface/DaqScopeModeAnalysis.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 const float DaqScopeModeAnalysis::tickMarkHeightThreshold_ = 50.;      // [ADC]
0012 const float DaqScopeModeAnalysis::frameFindingThreshold_ = (2. / 3.);  // fraction of tick mark height
0013 
0014 // ----------------------------------------------------------------------------
0015 //
0016 DaqScopeModeAnalysis::DaqScopeModeAnalysis(const uint32_t& key)
0017     : CommissioningAnalysis(key, "DaqScopeModeAnalysis"),
0018       height_(1. * sistrip::invalid_),
0019       base_(1. * sistrip::invalid_),
0020       peak_(1. * sistrip::invalid_),
0021       peds_(2, VFloat(128, sistrip::invalid_)),
0022       noise_(2, VFloat(128, sistrip::invalid_)),
0023       raw_(2, VFloat(128, sistrip::invalid_)),
0024       dead_(2, VInt(0, sistrip::invalid_)),
0025       noisy_(2, VInt(0, sistrip::invalid_)),
0026       pedsMean_(2, sistrip::invalid_),
0027       pedsSpread_(2, sistrip::invalid_),
0028       noiseMean_(2, sistrip::invalid_),
0029       noiseSpread_(2, sistrip::invalid_),
0030       rawMean_(2, sistrip::invalid_),
0031       rawSpread_(2, sistrip::invalid_),
0032       pedsMax_(2, sistrip::invalid_),
0033       pedsMin_(2, sistrip::invalid_),
0034       noiseMax_(2, sistrip::invalid_),
0035       noiseMin_(2, sistrip::invalid_),
0036       rawMax_(2, sistrip::invalid_),
0037       rawMin_(2, sistrip::invalid_) {
0038   dead_[0].reserve(256);
0039   dead_[1].reserve(256);
0040   noisy_[0].reserve(256);
0041   noisy_[1].reserve(256);
0042 }
0043 
0044 // ----------------------------------------------------------------------------
0045 //
0046 DaqScopeModeAnalysis::DaqScopeModeAnalysis()
0047     : CommissioningAnalysis("DaqScopeModeAnalysis"),
0048       height_(1. * sistrip::invalid_),
0049       base_(1. * sistrip::invalid_),
0050       peak_(1. * sistrip::invalid_),
0051       peds_(2, VFloat(128, sistrip::invalid_)),
0052       noise_(2, VFloat(128, sistrip::invalid_)),
0053       raw_(2, VFloat(128, sistrip::invalid_)),
0054       dead_(2, VInt(0, sistrip::invalid_)),
0055       noisy_(2, VInt(0, sistrip::invalid_)),
0056       pedsMean_(2, sistrip::invalid_),
0057       pedsSpread_(2, sistrip::invalid_),
0058       noiseMean_(2, sistrip::invalid_),
0059       noiseSpread_(2, sistrip::invalid_),
0060       rawMean_(2, sistrip::invalid_),
0061       rawSpread_(2, sistrip::invalid_),
0062       pedsMax_(2, sistrip::invalid_),
0063       pedsMin_(2, sistrip::invalid_),
0064       noiseMax_(2, sistrip::invalid_),
0065       noiseMin_(2, sistrip::invalid_),
0066       rawMax_(2, sistrip::invalid_),
0067       rawMin_(2, sistrip::invalid_) {
0068   dead_[0].reserve(256);
0069   dead_[1].reserve(256);
0070   noisy_[0].reserve(256);
0071   noisy_[1].reserve(256);
0072 }
0073 
0074 // ----------------------------------------------------------------------------
0075 //
0076 void DaqScopeModeAnalysis::reset() {
0077   height_ = 1. * sistrip::invalid_;
0078   base_ = 1. * sistrip::invalid_;
0079   peak_ = 1. * sistrip::invalid_;
0080 
0081   peds_ = VVFloat(2, VFloat(128, sistrip::invalid_));
0082   noise_ = VVFloat(2, VFloat(128, sistrip::invalid_));
0083   raw_ = VVFloat(2, VFloat(128, sistrip::invalid_));
0084   dead_ = VVInt(2, VInt(0, sistrip::invalid_));
0085   noisy_ = VVInt(2, VInt(0, sistrip::invalid_));
0086   pedsMean_ = VFloat(2, sistrip::invalid_);
0087   pedsSpread_ = VFloat(2, sistrip::invalid_);
0088   noiseMean_ = VFloat(2, sistrip::invalid_);
0089   noiseSpread_ = VFloat(2, sistrip::invalid_);
0090   rawMean_ = VFloat(2, sistrip::invalid_);
0091   rawSpread_ = VFloat(2, sistrip::invalid_);
0092   pedsMax_ = VFloat(2, sistrip::invalid_);
0093   pedsMin_ = VFloat(2, sistrip::invalid_);
0094   noiseMax_ = VFloat(2, sistrip::invalid_);
0095   noiseMin_ = VFloat(2, sistrip::invalid_);
0096   rawMax_ = VFloat(2, sistrip::invalid_);
0097   rawMin_ = VFloat(2, sistrip::invalid_);
0098   dead_[0].reserve(256);
0099   dead_[1].reserve(256);
0100   noisy_[0].reserve(256);
0101   noisy_[1].reserve(256);
0102 }
0103 
0104 // ----------------------------------------------------------------------------
0105 //
0106 uint16_t DaqScopeModeAnalysis::frameFindingThreshold() const {
0107   if ((getErrorCodes().empty() || getErrorCodes()[0] == "TickMarkRecovered") && base_ < sistrip::valid_ &&
0108       peak_ < sistrip::valid_ && height_ < sistrip::valid_ && height_ > tickMarkHeightThreshold_) {
0109     return ((static_cast<uint16_t>(base_ + height_ * DaqScopeModeAnalysis::frameFindingThreshold_) / 32) * 32);
0110   } else {
0111     return sistrip::invalid_;
0112   }
0113 }
0114 
0115 // ----------------------------------------------------------------------------
0116 //
0117 bool DaqScopeModeAnalysis::foundTickMark() const {
0118   return ((getErrorCodes().empty() || getErrorCodes()[0] == "TickMarkRecovered") && base_ < sistrip::valid_ &&
0119           peak_ < sistrip::valid_ && height_ < sistrip::valid_ && frameFindingThreshold() < sistrip::valid_);
0120 }
0121 
0122 // ----------------------------------------------------------------------------
0123 //
0124 bool DaqScopeModeAnalysis::isValid() const {
0125   return (getErrorCodes().empty() && base_ < sistrip::valid_ && peak_ < sistrip::valid_ && height_ < sistrip::valid_ &&
0126           frameFindingThreshold() < sistrip::valid_ && pedsMean_[0] < sistrip::maximum_ &&
0127           pedsMean_[1] < sistrip::maximum_ && pedsSpread_[0] < sistrip::maximum_ &&
0128           pedsSpread_[1] < sistrip::maximum_ && noiseMean_[0] < sistrip::maximum_ &&
0129           noiseMean_[1] < sistrip::maximum_ && noiseSpread_[0] < sistrip::maximum_ &&
0130           noiseSpread_[1] < sistrip::maximum_ && rawMean_[0] < sistrip::maximum_ && rawMean_[1] < sistrip::maximum_ &&
0131           rawSpread_[0] < sistrip::maximum_ && rawSpread_[1] < sistrip::maximum_ && pedsMax_[0] < sistrip::maximum_ &&
0132           pedsMax_[1] < sistrip::maximum_ && pedsMin_[0] < sistrip::maximum_ && pedsMin_[1] < sistrip::maximum_ &&
0133           noiseMax_[0] < sistrip::maximum_ && noiseMax_[1] < sistrip::maximum_ && noiseMin_[0] < sistrip::maximum_ &&
0134           noiseMin_[1] < sistrip::maximum_ && rawMax_[0] < sistrip::maximum_ && rawMax_[1] < sistrip::maximum_ &&
0135           rawMin_[0] < sistrip::maximum_ && rawMin_[1] < sistrip::maximum_);
0136 }
0137 
0138 // ----------------------------------------------------------------------------
0139 //
0140 void DaqScopeModeAnalysis::print(std::stringstream& ss, uint32_t iapv) {
0141   if (iapv == 1 || iapv == 2) {
0142     iapv--;
0143   } else {
0144     iapv = 0;
0145   }
0146 
0147   header(ss);
0148   ss << std::fixed << std::setprecision(2) << " Tick mark bottom (baseline)       [ADC] : " << base_ << std::endl
0149      << " Tick mark top                     [ADC] : " << peak_ << std::endl
0150      << " Tick mark height                  [ADC] : " << height_ << std::endl
0151      << " Frame finding threshold           [ADC] : " << frameFindingThreshold() << std::endl
0152      << std::boolalpha << " Tick mark found                         : " << foundTickMark() << std::endl
0153      << " isValid                                 : " << isValid() << std::endl;
0154 
0155   if (peds_[iapv].size() < 128 || noise_[iapv].size() < 128 || raw_[iapv].size() < 128) {
0156     edm::LogWarning(mlCommissioning_) << "[" << myName() << "::" << __func__ << "]"
0157                                       << " Unexpected number of pedestal/noise values: " << peds_[iapv].size() << ", "
0158                                       << noise_[iapv].size() << ", " << raw_[iapv].size();
0159     return;
0160   }
0161 
0162   ss << " Monitorables for APV number     : " << iapv;
0163   if (iapv == 0) {
0164     ss << " (first of pair)";
0165   } else if (iapv == 1) {
0166     ss << " (second of pair)";
0167   }
0168   ss << std::endl;
0169   ss << std::fixed << std::setprecision(2);
0170   ss << " Example peds/noise for strips   : "
0171      << "     0,     31,     63,    127" << std::endl
0172      << "  Peds                     [ADC] : " << std::setw(6) << peds_[iapv][0] << ", " << std::setw(6)
0173      << peds_[iapv][31] << ", " << std::setw(6) << peds_[iapv][63] << ", " << std::setw(6) << peds_[iapv][127]
0174      << std::endl
0175      << "  Noise                    [ADC] : " << std::setw(6) << noise_[iapv][0] << ", " << std::setw(6)
0176      << noise_[iapv][31] << ", " << std::setw(6) << noise_[iapv][63] << ", " << std::setw(6) << noise_[iapv][127]
0177      << std::endl
0178      << "  Raw noise                [ADC] : " << std::setw(6) << raw_[iapv][0] << ", " << std::setw(6) << raw_[iapv][31]
0179      << ", " << std::setw(6) << raw_[iapv][63] << ", " << std::setw(6) << raw_[iapv][127] << std::endl
0180      << " Dead strips (<5s)       [strip] : (" << dead_[iapv].size() << " in total) ";
0181   for (uint16_t ii = 0; ii < dead_[iapv].size(); ii++) {
0182     ss << dead_[iapv][ii] << " ";
0183   }
0184 
0185   ss << std::endl;
0186   ss << " Noisy strips (>5s)      [strip] : (" << noisy_[iapv].size() << " in total) ";
0187   for (uint16_t ii = 0; ii < noisy_[iapv].size(); ii++) {
0188     ss << noisy_[iapv][ii] << " ";
0189   }
0190   ss << std::endl;
0191   ss << " Mean peds +/- spread      [ADC] : " << pedsMean_[iapv] << " +/- " << pedsSpread_[iapv] << std::endl
0192      << " Min/Max pedestal          [ADC] : " << pedsMin_[iapv] << " <-> " << pedsMax_[iapv] << std::endl
0193      << " Mean noise +/- spread     [ADC] : " << noiseMean_[iapv] << " +/- " << noiseSpread_[iapv] << std::endl
0194      << " Min/Max noise             [ADC] : " << noiseMin_[iapv] << " <-> " << noiseMax_[iapv] << std::endl
0195      << " Mean raw noise +/- spread [ADC] : " << rawMean_[iapv] << " +/- " << rawSpread_[iapv] << std::endl
0196      << " Min/Max raw noise         [ADC] : " << rawMin_[iapv] << " <-> " << rawMax_[iapv] << std::endl
0197      << " Normalised noise                : "
0198      << "(yet to be implemented...)" << std::endl
0199      << std::boolalpha << " isValid                         : " << isValid() << std::endl
0200      << std::noboolalpha << " Error codes (found " << std::setw(2) << std::setfill(' ') << getErrorCodes().size()
0201      << ")          : ";
0202   if (getErrorCodes().empty()) {
0203     ss << "(none)";
0204   } else {
0205     VString::const_iterator istr = getErrorCodes().begin();
0206     VString::const_iterator jstr = getErrorCodes().end();
0207     for (; istr != jstr; ++istr) {
0208       ss << *istr << " ";
0209     }
0210   }
0211   ss << std::endl;
0212 }
0213 
0214 // ----------------------------------------------------------------------------
0215 //
0216 void DaqScopeModeAnalysis::summary(std::stringstream& ss) const {
0217   SiStripFecKey fec_key(fecKey());
0218   SiStripFedKey fed_key(fedKey());
0219 
0220   sistrip::RunType type = SiStripEnumsAndStrings::runType(myName());
0221 
0222   std::stringstream extra1, extra2, extra3, extra4, extra5, extra6;
0223   extra1 << sistrip::extrainfo::pedestals_;
0224   extra2 << sistrip::extrainfo::rawNoise_;
0225   extra3 << sistrip::extrainfo::commonMode_;
0226   extra4 << sistrip::extrainfo::scopeModeFrame_;
0227   extra5 << sistrip::extrainfo::scopeModeHeaderLow_;
0228   extra6 << sistrip::extrainfo::scopeModeHeaderHigh_;
0229 
0230   std::string title1 = SiStripHistoTitle(sistrip::EXPERT_HISTO,
0231                                          type,
0232                                          sistrip::FED_KEY,
0233                                          fed_key.key(),
0234                                          sistrip::LLD_CHAN,
0235                                          fec_key.lldChan(),
0236                                          extra1.str())
0237                            .title();
0238   std::string title2 = SiStripHistoTitle(sistrip::EXPERT_HISTO,
0239                                          type,
0240                                          sistrip::FED_KEY,
0241                                          fed_key.key(),
0242                                          sistrip::LLD_CHAN,
0243                                          fec_key.lldChan(),
0244                                          extra2.str())
0245                            .title();
0246   std::string title3 = SiStripHistoTitle(sistrip::EXPERT_HISTO,
0247                                          type,
0248                                          sistrip::FED_KEY,
0249                                          fed_key.key(),
0250                                          sistrip::APV,
0251                                          SiStripFecKey::i2cAddr(fec_key.lldChan(), true),
0252                                          extra3.str())
0253                            .title();
0254   std::string title4 = SiStripHistoTitle(sistrip::EXPERT_HISTO,
0255                                          type,
0256                                          sistrip::FED_KEY,
0257                                          fed_key.key(),
0258                                          sistrip::APV,
0259                                          SiStripFecKey::i2cAddr(fec_key.lldChan(), false),
0260                                          extra3.str())
0261                            .title();
0262 
0263   std::string title5 = SiStripHistoTitle(sistrip::EXPERT_HISTO,
0264                                          type,
0265                                          sistrip::FED_KEY,
0266                                          fed_key.key(),
0267                                          sistrip::LLD_CHAN,
0268                                          SiStripFecKey::i2cAddr(fec_key.lldChan()),
0269                                          extra4.str())
0270                            .title();
0271 
0272   std::string title6 = SiStripHistoTitle(sistrip::EXPERT_HISTO,
0273                                          type,
0274                                          sistrip::FED_KEY,
0275                                          fed_key.key(),
0276                                          sistrip::LLD_CHAN,
0277                                          SiStripFecKey::i2cAddr(fec_key.lldChan()),
0278                                          extra5.str())
0279                            .title();
0280 
0281   std::string title7 = SiStripHistoTitle(sistrip::EXPERT_HISTO,
0282                                          type,
0283                                          sistrip::FED_KEY,
0284                                          fed_key.key(),
0285                                          sistrip::LLD_CHAN,
0286                                          SiStripFecKey::i2cAddr(fec_key.lldChan()),
0287                                          extra6.str())
0288                            .title();
0289 
0290   ss << " Summary"
0291      << ":" << (isValid() ? "Valid" : "Invalid") << ":" << sistrip::controlView_ << ":" << fec_key.fecCrate() << "/"
0292      << fec_key.fecSlot() << "/" << fec_key.fecRing() << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << ":"
0293      << sistrip::dqmRoot_ << sistrip::dir_ << "Collate" << sistrip::dir_
0294      << SiStripFecKey(fec_key.fecCrate(), fec_key.fecSlot(), fec_key.fecRing(), fec_key.ccuAddr(), fec_key.ccuChan())
0295             .path()
0296      << ":" << title1 << ";" << title2 << ";" << title3 << ";" << title4 << ";" << title5 << ";" << title6 << ";"
0297      << title7 << std::endl;
0298 }