File indexing completed on 2023-03-17 10:56:30
0001 #include "DQM/SiStripCommissioningSources/interface/CalibrationTask.h"
0002 #include "DataFormats/SiStripCommon/interface/SiStripHistoTitle.h"
0003 #include "DQMServices/Core/interface/DQMStore.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include <CondFormats/SiStripObjects/interface/SiStripPedestals.h>
0006
0007 #include <arpa/inet.h>
0008 #include <cstdio>
0009 #include <fstream>
0010 #include <netdb.h>
0011 #include <sys/socket.h>
0012 #include <sys/unistd.h>
0013
0014
0015
0016 CalibrationTask::CalibrationTask(DQMStore* dqm,
0017 const FedChannelConnection& conn,
0018 const sistrip::RunType& rtype,
0019 const char* filename,
0020 uint32_t run,
0021 const SiStripPedestals& pedestals)
0022 : CommissioningTask(dqm, conn, "CalibrationTask"),
0023 runType_(rtype),
0024 nBins_(0),
0025 lastCalChan_(1000),
0026 lastCalSel_(1000),
0027 lastLatency_(1000),
0028 extrainfo_(),
0029 run_(run) {
0030
0031 if (runType_ == sistrip::CALIBRATION)
0032 nBins_ = 64;
0033
0034 else if (runType_ == sistrip::CALIBRATION_DECO)
0035 nBins_ = 80;
0036
0037 LogDebug("Commissioning") << "[CalibrationTask::CalibrationTask] Constructing object...";
0038
0039
0040 SiStripPedestals::Range detPedRange = pedestals.getRange(conn.detId());
0041 int start = conn.apvPairNumber() * 256;
0042 int stop = start + 256;
0043 int value = 0;
0044 ped.reserve(256);
0045 for (int strip = start; strip < stop; ++strip) {
0046 value = int(pedestals.getPed(strip, detPedRange));
0047 if (value > 895)
0048 value -= 1024;
0049 ped.push_back(value);
0050 }
0051 }
0052
0053
0054
0055 CalibrationTask::~CalibrationTask() {
0056 LogDebug("Commissioning") << "[CalibrationTask::CalibrationTask] Destructing object...";
0057 }
0058
0059
0060
0061 void CalibrationTask::book() {
0062 LogDebug("Commissioning") << "[CalibrationTask::book]";
0063
0064
0065 if (calib1_.find(extrainfo_) == calib1_.end()) {
0066 dqm()->setCurrentFolder(directory_);
0067 calib1_[extrainfo_].resize(16);
0068 for (int i = 0; i < 16; ++i) {
0069 std::string postfix = extrainfo_ + "_istrip_" + std::to_string(i);
0070 std::string title = SiStripHistoTitle(sistrip::EXPERT_HISTO,
0071 runType_,
0072 sistrip::FED_KEY,
0073 fedKey(),
0074 sistrip::APV,
0075 connection().i2cAddr(0),
0076 postfix)
0077 .title();
0078
0079 if (runType_ == sistrip::CALIBRATION)
0080 calib1_[extrainfo_][i].histo(dqm()->book1D(title, title, nBins_, 0, 200));
0081 else if (runType_ == sistrip::CALIBRATION_DECO)
0082 calib1_[extrainfo_][i].histo(dqm()->book1D(title, title, nBins_, 0, 250));
0083 calib1_[extrainfo_][i].isProfile_ = false;
0084 calib1_[extrainfo_][i].vNumOfEntries_.resize(nBins_, 0);
0085 }
0086 }
0087
0088
0089 if (calib2_.find(extrainfo_) == calib2_.end()) {
0090 dqm()->setCurrentFolder(directory_);
0091 calib2_[extrainfo_].resize(16);
0092 for (int i = 0; i < 16; ++i) {
0093 std::string postfix = extrainfo_ + "_istrip_" + std::to_string(i);
0094 std::string title = SiStripHistoTitle(sistrip::EXPERT_HISTO,
0095 runType_,
0096 sistrip::FED_KEY,
0097 fedKey(),
0098 sistrip::APV,
0099 connection().i2cAddr(1),
0100 postfix)
0101 .title();
0102
0103 if (runType_ == sistrip::CALIBRATION)
0104 calib2_[extrainfo_][i].histo(dqm()->book1D(title, title, nBins_, 0, 200));
0105 else if (runType_ == sistrip::CALIBRATION_DECO)
0106 calib2_[extrainfo_][i].histo(dqm()->book1D(title, title, nBins_, 0, 250));
0107
0108 calib2_[extrainfo_][i].isProfile_ = false;
0109 calib2_[extrainfo_][i].vNumOfEntries_.resize(nBins_, 0);
0110 }
0111 }
0112 }
0113
0114
0115
0116 void CalibrationTask::fill(const SiStripEventSummary& summary, const edm::DetSet<SiStripRawDigi>& digis) {
0117 LogDebug("Commissioning") << "[CalibrationTask::fill]";
0118
0119 if (lastCalChan_ != summary.calChan()) {
0120 lastCalChan_ = summary.calChan();
0121 lastLatency_ = summary.latency();
0122 lastCalSel_ = summary.calSel();
0123 extrainfo_ = "calChan_" + std::to_string(lastCalChan_);
0124 book();
0125 } else {
0126 lastCalChan_ = summary.calChan();
0127 lastLatency_ = summary.latency();
0128 lastCalSel_ = summary.calSel();
0129 extrainfo_ = "calChan_" + std::to_string(lastCalChan_);
0130 }
0131
0132
0133 int isub = lastCalChan_ < 4 ? lastCalChan_ + 4 : lastCalChan_ - 4;
0134 int bin = 0;
0135
0136 if (runType_ == sistrip::CALIBRATION)
0137 bin = (100 - summary.latency()) * 8 + (7 - summary.calSel());
0138 else if (runType_ == sistrip::CALIBRATION_DECO)
0139 bin = (102 - summary.latency()) * 8 + (7 - summary.calSel());
0140
0141
0142 for (int k = 0; k < 16; ++k) {
0143 updateHistoSet(calib1_[extrainfo_][k],
0144 bin,
0145 digis.data[lastCalChan_ + k * 8].adc() - ped[lastCalChan_ + k * 8] -
0146 (digis.data[isub + k * 8].adc() - ped[isub + k * 8]));
0147 updateHistoSet(calib2_[extrainfo_][k],
0148 bin,
0149 digis.data[128 + lastCalChan_ + k * 8].adc() - ped[128 + lastCalChan_ + k * 8] -
0150 (digis.data[128 + isub + k * 8].adc() - ped[128 + isub + k * 8]));
0151 }
0152 update();
0153 }
0154
0155
0156
0157 void CalibrationTask::update() {
0158 LogDebug("Commissioning") << "[CalibrationTask::update]";
0159
0160 for (const auto& element : calib1_) {
0161 for (auto vecelement : element.second)
0162 updateHistoSet(vecelement);
0163 }
0164
0165 for (const auto& element : calib2_) {
0166 for (auto vecelement : element.second)
0167 updateHistoSet(vecelement);
0168 }
0169 }
0170
0171 void CalibrationTask::setCurrentFolder(const std::string& dir) { directory_ = dir; }