Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:11:31

0001 #include "DQM/SiStripCommissioningClients/interface/ApvTimingHistograms.h"
0002 #include "CondFormats/SiStripObjects/interface/ApvTimingAnalysis.h"
0003 #include "DQM/SiStripCommissioningAnalysis/interface/ApvTimingAlgorithm.h"
0004 #include "DQM/SiStripCommissioningSummary/interface/ApvTimingSummaryFactory.h"
0005 #include "DQM/SiStripCommon/interface/ExtractTObject.h"
0006 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "TProfile.h"
0009 #include <iostream>
0010 #include <memory>
0011 
0012 #include <sstream>
0013 #include <iomanip>
0014 
0015 using namespace std;
0016 using namespace sistrip;
0017 
0018 // -----------------------------------------------------------------------------
0019 /** */
0020 ApvTimingHistograms::ApvTimingHistograms(const edm::ParameterSet& pset, DQMStore* bei)
0021     : CommissioningHistograms(pset.getParameter<edm::ParameterSet>("ApvTimingParameters"), bei, sistrip::APV_TIMING) {
0022   factory_ = std::make_unique<ApvTimingSummaryFactory>();
0023   LogTrace(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
0024                          << " Constructing object...";
0025 }
0026 
0027 // -----------------------------------------------------------------------------
0028 /** */
0029 ApvTimingHistograms::~ApvTimingHistograms() {
0030   LogTrace(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
0031                          << " Destructing object...";
0032 }
0033 
0034 // -----------------------------------------------------------------------------
0035 /** */
0036 void ApvTimingHistograms::histoAnalysis(bool debug) {
0037   LogTrace(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]";
0038 
0039   // Some initialisation
0040   uint16_t valid = 0;
0041   HistosMap::const_iterator iter;
0042   Analyses::iterator ianal;
0043   std::map<std::string, uint16_t> errors;
0044 
0045   // Clear map holding analysis objects
0046   for (ianal = data().begin(); ianal != data().end(); ianal++) {
0047     if (ianal->second) {
0048       delete ianal->second;
0049     }
0050   }
0051   data().clear();
0052 
0053   // Reset minimum / maximum delays
0054   float time_min = 1. * sistrip::invalid_;
0055   float time_max = -1. * sistrip::invalid_;
0056   uint32_t device_min = sistrip::invalid_;
0057   uint32_t device_max = sistrip::invalid_;
0058 
0059   // Iterate through map containing histograms
0060   for (iter = histos().begin(); iter != histos().end(); iter++) {
0061     // Check vector of histos is not empty
0062     if (iter->second.empty()) {
0063       edm::LogWarning(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
0064                                     << " Zero histograms found!";
0065       continue;
0066     }
0067 
0068     // Retrieve pointers to histos
0069     std::vector<TH1*> profs;
0070     Histos::const_iterator ihis = iter->second.begin();
0071     for (; ihis != iter->second.end(); ihis++) {
0072       TProfile* prof = ExtractTObject<TProfile>().extract((*ihis)->me_);
0073       if (prof) {
0074         profs.push_back(prof);
0075       }
0076     }
0077 
0078     // Perform histo analysis
0079     ApvTimingAnalysis* anal = new ApvTimingAnalysis(iter->first);
0080     ApvTimingAlgorithm algo(this->pset(), anal);
0081     algo.analysis(profs);
0082     data()[iter->first] = anal;
0083 
0084     // Check if tick mark found
0085     if (!anal->foundTickMark()) {
0086       continue;
0087     }
0088 
0089     // Find maximum time
0090     if (anal->time() > time_max) {
0091       time_max = anal->time();
0092       device_max = iter->first;
0093     }
0094 
0095     // Find minimum time
0096     if (anal->time() < time_min) {
0097       time_min = anal->time();
0098       device_min = iter->first;
0099     }
0100   }
0101 
0102   // Adjust maximum (and minimum) delay(s) to find optimum sampling point(s)
0103   if (time_max > sistrip::valid_ || time_max < -1. * sistrip::valid_) {
0104     edm::LogWarning(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
0105                                   << " Unable to set maximum time! Found unexpected value: " << time_max;
0106 
0107   } else {
0108     SiStripFecKey min(device_min);
0109     edm::LogVerbatim(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
0110                                    << " Crate/FEC/Ring/CCU/module/channel: " << min.fecCrate() << "/" << min.fecSlot()
0111                                    << "/" << min.fecRing() << "/" << min.ccuAddr() << "/" << min.ccuChan() << "/"
0112                                    << min.lldChan() << " has minimum time for tick mark rising edge [ns]: " << time_min;
0113 
0114     SiStripFecKey max(device_max);
0115     edm::LogVerbatim(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
0116                                    << " Crate/FEC/Ring/CCU/module/channel: " << max.fecCrate() << "/" << max.fecSlot()
0117                                    << "/" << max.fecRing() << "/" << max.ccuAddr() << "/" << max.ccuChan() << "/"
0118                                    << max.lldChan() << " has maximum time for tick mark rising edge [ns]: " << time_max;
0119 
0120     edm::LogVerbatim(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
0121                                    << " Difference b/w minimum and maximum times"
0122                                    << " for tick mark rising edges [ns] is: " << (time_max - time_min);
0123   }
0124 
0125   // Set reference time for all analysis objects
0126   for (ianal = data().begin(); ianal != data().end(); ianal++) {
0127     ApvTimingAnalysis* anal = dynamic_cast<ApvTimingAnalysis*>(ianal->second);
0128     if (!anal) {
0129       continue;
0130     }
0131     anal->refTime(time_max, this->pset().getParameter<int>("TargetDelay"));
0132     if (anal->isValid()) {
0133       valid++;
0134     }
0135     if (!anal->getErrorCodes().empty()) {
0136       errors[anal->getErrorCodes()[0]]++;
0137     }
0138   }
0139 
0140   if (!histos().empty()) {
0141     edm::LogVerbatim(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
0142                                    << " Analyzed histograms for " << histos().size() << " FED channels, of which "
0143                                    << valid << " (" << 100 * valid / histos().size() << "%) are valid.";
0144   } else {
0145     edm::LogWarning(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
0146                                   << " No histograms to analyze!";
0147   }
0148 
0149   if (!histos().empty()) {
0150     edm::LogVerbatim(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
0151                                    << " Analyzed histograms for " << histos().size() << " FED channels, of which "
0152                                    << valid << " (" << 100 * valid / histos().size() << "%) are valid.";
0153     if (!errors.empty()) {
0154       uint16_t count = 0;
0155       std::stringstream ss;
0156       ss << std::endl;
0157       std::map<std::string, uint16_t>::const_iterator ii;
0158       for (ii = errors.begin(); ii != errors.end(); ++ii) {
0159         ss << " " << ii->first << ": " << ii->second << std::endl;
0160         count += ii->second;
0161       }
0162       edm::LogWarning(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
0163                                     << " Found " << count << " errors (" << 100 * count / histos().size()
0164                                     << "%): " << ss.str();
0165     }
0166   } else {
0167     edm::LogWarning(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
0168                                   << " No histograms to analyze!";
0169   }
0170 }