Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:08:35

0001 #include "DQM/SiStripCommissioningSources/interface/CommissioningTask.h"
0002 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0003 #include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
0004 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
0005 #include "DQM/SiStripCommon/interface/ExtractTObject.h"
0006 #include "DQM/SiStripCommon/interface/UpdateTProfile.h"
0007 #include "DQMServices/Core/interface/DQMStore.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "TAxis.h"
0010 #include <iostream>
0011 #include <iostream>
0012 
0013 using namespace sistrip;
0014 
0015 // -----------------------------------------------------------------------------
0016 //
0017 CommissioningTask::CommissioningTask(DQMStore* dqm, const FedChannelConnection& conn, const std::string& my_name)
0018     : dqm_(dqm),
0019       updateFreq_(0),
0020       fillCntr_(0),
0021       connection_(conn),
0022       fedKey_(0),
0023       fecKey_(0),
0024       booked_(false),
0025       myName_(my_name),
0026       eventSetup_(nullptr) {
0027   uint16_t fed_ch = connection_.fedCh();
0028   fedKey_ = SiStripFedKey(connection_.fedId(), SiStripFedKey::feUnit(fed_ch), SiStripFedKey::feChan(fed_ch)).key();
0029   fecKey_ = SiStripFecKey(connection_.fecCrate(),
0030                           connection_.fecSlot(),
0031                           connection_.fecRing(),
0032                           connection_.ccuAddr(),
0033                           connection_.ccuChan(),
0034                           connection_.lldChannel())
0035                 .key();
0036 
0037   LogTrace(mlDqmSource_) << "[CommissioningTask::" << __func__ << "]"
0038                          << " Constructing '" << myName_ << "' object for FecKey/FedKey: "
0039                          << "0x" << std::hex << std::setw(8) << std::setfill('0') << fecKey_ << std::dec << "/"
0040                          << "0x" << std::hex << std::setw(8) << std::setfill('0') << fedKey_ << std::dec
0041                          << " and Crate/FEC/ring/CCU/module/LLDchan: " << connection_.fecCrate() << "/"
0042                          << connection_.fecSlot() << "/" << connection_.fecRing() << "/" << connection_.ccuAddr() << "/"
0043                          << connection_.ccuChan() << "/" << connection_.lldChannel()
0044                          << " and FedId/Ch: " << connection_.fedId() << "/" << connection_.fedCh();
0045 }
0046 
0047 // -----------------------------------------------------------------------------
0048 //
0049 CommissioningTask::~CommissioningTask() {
0050   LogTrace(mlDqmSource_) << "[CommissioningTask::" << __func__ << "]"
0051                          << " Destructing object for FED id/ch "
0052                          << " Constructing '" << myName_ << "' object for FecKey/FedKey: "
0053                          << "0x" << std::hex << std::setw(8) << std::setfill('0') << fecKey_ << std::dec << "/"
0054                          << "0x" << std::hex << std::setw(8) << std::setfill('0') << fedKey_ << std::dec
0055                          << " and Crate/FEC/ring/CCU/module/LLDchan: " << connection_.fecCrate() << "/"
0056                          << connection_.fecSlot() << "/" << connection_.fecRing() << "/" << connection_.ccuAddr() << "/"
0057                          << connection_.ccuChan() << "/" << connection_.lldChannel()
0058                          << " and FedId/Ch: " << connection_.fedId() << "/" << connection_.fedCh();
0059   //@@ do not delete EventSetup pointer!
0060 }
0061 
0062 // -----------------------------------------------------------------------------
0063 //
0064 CommissioningTask::HistoSet::HistoSet()
0065     : vNumOfEntries_(),
0066       vSumOfContents_(),
0067       vSumOfSquares_(),
0068       isProfile_(true),
0069       explicitFill_(false),
0070       histo_(nullptr),
0071       axis_(nullptr) {
0072   ;
0073 }
0074 
0075 // -----------------------------------------------------------------------------
0076 //
0077 CommissioningTask::CompactHistoSet::CompactHistoSet() : vNumOfEntries_(), explicitFill_(false), histo_(nullptr) { ; }
0078 
0079 // -----------------------------------------------------------------------------
0080 //
0081 CommissioningTask::MonitorElement* CommissioningTask::HistoSet::histo() { return histo_; }
0082 
0083 // -----------------------------------------------------------------------------
0084 //
0085 CommissioningTask::MonitorElement* CommissioningTask::CompactHistoSet::histo() { return histo_; }
0086 
0087 // -----------------------------------------------------------------------------
0088 //
0089 void CommissioningTask::HistoSet::histo(MonitorElement* me) {
0090   histo_ = me;
0091   TH1* histo = ExtractTObject<TH1>().extract(histo_);
0092   if (histo_) {
0093     axis_ = histo->GetXaxis();
0094   }
0095   //TProfile* prof = ExtractTObject<TProfile>().extract( histo_ );
0096   //if ( prof ) { prof->SetErrorOption("s"); }
0097 }
0098 
0099 // -----------------------------------------------------------------------------
0100 //
0101 void CommissioningTask::CompactHistoSet::histo(MonitorElement* me) { histo_ = me; }
0102 
0103 // -----------------------------------------------------------------------------
0104 //
0105 uint32_t CommissioningTask::HistoSet::bin(float value) {
0106   if (!axis_) {
0107     return 0;
0108   }
0109   float range = axis_->GetXmax() - axis_->GetXmin();
0110   if (range > 0.) {
0111     int32_t bin = static_cast<int32_t>((value - axis_->GetXmin()) * (axis_->GetNbins() / range)) + 1;
0112     if (bin < 0) {
0113       return 0;
0114     } else if (bin > axis_->GetNbins()) {
0115       return static_cast<uint32_t>(axis_->GetNbins() + 1);
0116     } else {
0117       return bin;
0118     }
0119   } else {
0120     return 0;
0121   }
0122 }
0123 
0124 // -----------------------------------------------------------------------------
0125 //
0126 void CommissioningTask::book() {
0127   edm::LogWarning(mlDqmSource_) << "[CommissioningTask::" << __func__ << "]"
0128                                 << " No derived implementation exists!";
0129 }
0130 
0131 // -----------------------------------------------------------------------------
0132 //
0133 void CommissioningTask::fill(const SiStripEventSummary& summary, const edm::DetSet<SiStripRawDigi>& digis) {
0134   edm::LogWarning(mlDqmSource_) << "[CommissioningTask::" << __func__ << "]"
0135                                 << " No derived implementation exists!";
0136 }
0137 
0138 // -----------------------------------------------------------------------------
0139 //
0140 void CommissioningTask::fill(const SiStripEventSummary& summary,
0141                              const edm::DetSet<SiStripRawDigi>& digis,
0142                              const edm::DetSet<SiStripRawDigi>& digisAlt) {
0143   edm::LogWarning(mlDqmSource_) << "[CommissioningTask::" << __func__ << "]"
0144                                 << " No derived implementation exists!";
0145 }
0146 
0147 // -----------------------------------------------------------------------------
0148 //
0149 void CommissioningTask::fill(const SiStripEventSummary& summary,
0150                              const edm::DetSet<SiStripRawDigi>& digis,
0151                              const edm::DetSet<SiStripRawDigi>& digisAlt,
0152                              const std::vector<uint16_t>& stripOnCluster) {
0153   edm::LogWarning(mlDqmSource_) << "[CommissioningTask::" << __func__ << "]"
0154                                 << " No derived implementation exists!";
0155 }
0156 
0157 // -----------------------------------------------------------------------------
0158 //
0159 void CommissioningTask::fill(const SiStripEventSummary& summary,
0160                              const uint16_t& fed_id,
0161                              const std::map<uint16_t, float>& fed_ch) {
0162   edm::LogWarning(mlDqmSource_) << "[CommissioningTask::" << __func__ << "]"
0163                                 << " No derived implementation exists!";
0164 }
0165 
0166 // -----------------------------------------------------------------------------
0167 //
0168 void CommissioningTask::update() {
0169   edm::LogWarning(mlDqmSource_) << "[CommissioningTask::" << __func__ << "]"
0170                                 << " No derived implementation exists!";
0171 }
0172 
0173 // -----------------------------------------------------------------------------
0174 //
0175 void CommissioningTask::bookHistograms() {
0176   book();
0177   booked_ = true;
0178 }
0179 
0180 // -----------------------------------------------------------------------------
0181 //
0182 void CommissioningTask::fillHistograms(const SiStripEventSummary& summary, const edm::DetSet<SiStripRawDigi>& digis) {
0183   if (!booked_) {
0184     edm::LogWarning(mlDqmSource_) << "[CommissioningTask::" << __func__ << "]"
0185                                   << " Attempting to fill histos that haven't been booked yet!";
0186     return;
0187   }
0188   fillCntr_++;
0189   fill(summary, digis);
0190   if (updateFreq_ && !(fillCntr_ % updateFreq_)) {
0191     update();
0192   }
0193 }
0194 
0195 // -----------------------------------------------------------------------------
0196 //
0197 void CommissioningTask::fillHistograms(const SiStripEventSummary& summary,
0198                                        const edm::DetSet<SiStripRawDigi>& digis,
0199                                        const edm::DetSet<SiStripRawDigi>& digisAlt) {
0200   if (!booked_) {
0201     edm::LogWarning(mlDqmSource_) << "[CommissioningTask::" << __func__ << "]"
0202                                   << " Attempting to fill histos that haven't been booked yet!";
0203     return;
0204   }
0205   fillCntr_++;
0206   fill(summary, digis, digisAlt);
0207   if (updateFreq_ && !(fillCntr_ % updateFreq_)) {
0208     update();
0209   }
0210 }
0211 
0212 // -----------------------------------------------------------------------------
0213 //
0214 void CommissioningTask::fillHistograms(const SiStripEventSummary& summary,
0215                                        const edm::DetSet<SiStripRawDigi>& digis,
0216                                        const edm::DetSet<SiStripRawDigi>& digisAlt,
0217                                        const std::vector<uint16_t>& stripOnCluster) {
0218   if (!booked_) {
0219     edm::LogWarning(mlDqmSource_) << "[CommissioningTask::" << __func__ << "]"
0220                                   << " Attempting to fill histos that haven't been booked yet!";
0221     return;
0222   }
0223   fillCntr_++;
0224   fill(summary, digis, digisAlt, stripOnCluster);
0225   if (updateFreq_ && !(fillCntr_ % updateFreq_)) {
0226     update();
0227   }
0228 }
0229 
0230 // -----------------------------------------------------------------------------
0231 //
0232 void CommissioningTask::fillHistograms(const SiStripEventSummary& summary,
0233                                        const uint16_t& fed_id,
0234                                        const std::map<uint16_t, float>& fed_ch) {
0235   if (!booked_) {
0236     edm::LogWarning(mlDqmSource_) << "[CommissioningTask::" << __func__ << "]"
0237                                   << " Attempting to fill histos that haven't been booked yet!";
0238     return;
0239   }
0240   fillCntr_++;
0241   fill(summary, fed_id, fed_ch);
0242   if (updateFreq_ && !(fillCntr_ % updateFreq_)) {
0243     update();
0244   }
0245 }
0246 
0247 // -----------------------------------------------------------------------------
0248 //
0249 void CommissioningTask::updateHistograms() { update(); }
0250 
0251 // -----------------------------------------------------------------------------
0252 //
0253 void CommissioningTask::updateHistoSet(HistoSet& histo_set, const uint32_t& bin) {
0254   float value = 1.;
0255   updateHistoSet(histo_set, bin, value);
0256 }
0257 
0258 // -----------------------------------------------------------------------------
0259 //
0260 void CommissioningTask::updateHistoSet(CompactHistoSet& histo_set, const uint32_t& bin) {
0261   short value = 1;
0262   updateHistoSet(histo_set, bin, value);
0263 }
0264 
0265 // -----------------------------------------------------------------------------
0266 //
0267 void CommissioningTask::updateHistoSet(HistoSet& histo_set, const float& value) {
0268   float weight = 1.;
0269   updateHistoSet(histo_set, histo_set.bin(value), weight);
0270 }
0271 
0272 // -----------------------------------------------------------------------------
0273 //
0274 void CommissioningTask::updateHistoSet(HistoSet& histo_set, const uint32_t& bin, const float& value) {
0275   // Check bin number
0276   if (bin >= histo_set.vNumOfEntries_.size() && !histo_set.explicitFill_) {
0277     edm::LogWarning(mlDqmSource_) << "[CommissioningTask::" << __func__ << "]"
0278                                   << " Unexpected bin number " << bin << " when filling histogram of size "
0279                                   << histo_set.vNumOfEntries_.size();
0280     return;
0281   }
0282 
0283   // Check if histo is TProfile or not
0284   if (!histo_set.isProfile_) {
0285     // Set entries
0286     if (histo_set.explicitFill_) {
0287       float origVal = histo_set.histo()->getBinContent(bin + 1);
0288       histo_set.histo()->setBinContent(bin + 1, origVal + value);
0289     } else {
0290       histo_set.vNumOfEntries_[bin] += value;
0291     }
0292   } else {
0293     // Set entries
0294     histo_set.vNumOfEntries_[bin]++;
0295 
0296     // Check bin number
0297     if (bin >= histo_set.vSumOfContents_.size() || bin >= histo_set.vSumOfSquares_.size()) {
0298       edm::LogWarning(mlDqmSource_) << "[CommissioningTask::" << __func__ << "]"
0299                                     << " Unexpected bin when filling histogram: " << bin;
0300       return;
0301     }
0302 
0303     // Set sum of contents and squares
0304     histo_set.vSumOfContents_[bin] += value;
0305     histo_set.vSumOfSquares_[bin] += value * value;
0306   }
0307 }
0308 
0309 // -----------------------------------------------------------------------------
0310 //
0311 void CommissioningTask::updateHistoSet(CompactHistoSet& histo_set, const uint32_t& bin, const short& value) {
0312   // Check bin number
0313   if (bin >= histo_set.vNumOfEntries_.size() && !histo_set.explicitFill_) {
0314     edm::LogWarning(mlDqmSource_) << "[CommissioningTask::" << __func__ << "]"
0315                                   << " Unexpected bin number " << bin << " when filling histogram of size "
0316                                   << histo_set.vNumOfEntries_.size();
0317     return;
0318   }
0319 
0320   if (histo_set.explicitFill_) {
0321     float origVal = histo_set.histo()->getBinContent(bin + 1);
0322     histo_set.histo()->setBinContent(bin + 1, origVal + value);
0323   } else {
0324     // Set entries
0325     histo_set.vNumOfEntries_[bin] += value;
0326   }
0327 }
0328 
0329 // -----------------------------------------------------------------------------
0330 //
0331 void CommissioningTask::updateHistoSet(HistoSet& histo_set) {
0332   // Check if histo exists
0333   if (!histo_set.histo()) {
0334     edm::LogWarning(mlDqmSource_) << "[CommissioningTask::" << __func__ << "]"
0335                                   << " NULL pointer to MonitorElement!";
0336     return;
0337   }
0338 
0339   if (!histo_set.explicitFill_) {
0340     if (histo_set.isProfile_) {
0341       TProfile* prof = ExtractTObject<TProfile>().extract(histo_set.histo());
0342       // if ( prof ) { prof->SetErrorOption("s"); } //@@ necessary?
0343       const static UpdateTProfile profile;
0344       for (uint32_t ibin = 0; ibin < histo_set.vNumOfEntries_.size(); ibin++) {
0345         profile.setBinContents(prof,
0346                                ibin + 1,
0347                                histo_set.vNumOfEntries_[ibin],
0348                                histo_set.vSumOfContents_[ibin],
0349                                histo_set.vSumOfSquares_[ibin]);
0350       }
0351 
0352     } else {
0353       for (uint32_t ibin = 0; ibin < histo_set.vNumOfEntries_.size(); ibin++) {
0354         histo_set.histo()->setBinContent(ibin + 1, histo_set.vNumOfEntries_[ibin]);
0355       }
0356     }
0357   }
0358 }
0359 
0360 // -----------------------------------------------------------------------------
0361 //
0362 void CommissioningTask::updateHistoSet(CompactHistoSet& histo_set) {
0363   // Check if histo exists
0364   if (!histo_set.histo()) {
0365     edm::LogWarning(mlDqmSource_) << "[CommissioningTask::" << __func__ << "]"
0366                                   << " NULL pointer to MonitorElement!";
0367     return;
0368   }
0369 
0370   if (!histo_set.explicitFill_) {
0371     for (uint32_t ibin = 0; ibin < histo_set.vNumOfEntries_.size(); ibin++) {
0372       histo_set.histo()->setBinContent(ibin + 1, histo_set.vNumOfEntries_[ibin]);
0373     }
0374   }
0375 }