Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DQM/SiStripCommissioningSources/interface/CalibrationScanTask.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 CalibrationScanTask::CalibrationScanTask(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, "CalibrationScanTask"),
0023       runType_(rtype),
0024       nBins_(0),
0025       lastISHA_(1000),
0026       lastVFS_(1000),
0027       lastCalChan_(1000),
0028       lastCalSel_(1000),
0029       lastLatency_(1000),
0030       extrainfo_(),
0031       run_(run) {
0032   // each latency point is 25ns, each calSel is 25/8 --> 64 points = 8 calsel + 8 latency --> as set in the DAQ configuration
0033   if (runType_ == sistrip::CALIBRATION_SCAN)
0034     nBins_ = 64;
0035   // each latency point is 25ns, each calSel is 25/8 --> 80 points = 8 calsel + 10 latency --> as set in the DAQ configuration
0036   else if (runType_ == sistrip::CALIBRATION_SCAN_DECO)
0037     nBins_ = 80;
0038 
0039   LogDebug("Commissioning") << "[CalibrationScanTask::CalibrationScanTask] Constructing object...";
0040   // load the pedestals
0041   SiStripPedestals::Range detPedRange = pedestals.getRange(conn.detId());
0042   int start = conn.apvPairNumber() * 256;
0043   int stop = start + 256;
0044   int value = 0;
0045   ped.reserve(256);
0046   LogDebug("Commissioning") << "[CalibrationScanTask::CalibrationScanTask] Loading pedestal for " << conn.detId();
0047   if (conn.detId() == 0)
0048     return;
0049   for (int strip = start; strip < stop; ++strip) {
0050     value = int(pedestals.getPed(strip, detPedRange));
0051     if (value > 895)
0052       value -= 1024;
0053     ped.push_back(value);
0054   }
0055 }
0056 
0057 // -----------------------------------------------------------------------------
0058 //
0059 CalibrationScanTask::~CalibrationScanTask() {
0060   LogDebug("Commissioning") << "[CalibrationScanTask::CalibrationScanTask] Destructing object...";
0061 }
0062 
0063 // -----------------------------------------------------------------------------
0064 //
0065 void CalibrationScanTask::book() {
0066   if (calib1_.find(extrainfo_) == calib1_.end()) {
0067     // construct the histo titles and book two histograms: one per APV --> all strip in one APV are considered to fill histogram
0068     std::string title = SiStripHistoTitle(sistrip::EXPERT_HISTO,
0069                                           runType_,
0070                                           sistrip::FED_KEY,
0071                                           fedKey(),
0072                                           sistrip::APV,
0073                                           connection().i2cAddr(0),
0074                                           extrainfo_)
0075                             .title();
0076 
0077     dqm()->setCurrentFolder(directory_);
0078     calib1_[extrainfo_] = HistoSet();
0079     if (runType_ == sistrip::CALIBRATION_SCAN)
0080       calib1_[extrainfo_].histo(dqm()->book1D(title, title, nBins_, 0, 200));
0081     else if (runType_ == sistrip::CALIBRATION_SCAN_DECO)
0082       calib1_[extrainfo_].histo(dqm()->book1D(title, title, nBins_, 0, 250));
0083     calib1_[extrainfo_].isProfile_ = false;
0084     calib1_[extrainfo_].vNumOfEntries_.resize(nBins_, 0);
0085   }
0086 
0087   if (calib2_.find(extrainfo_) == calib2_.end()) {
0088     std::string title = SiStripHistoTitle(sistrip::EXPERT_HISTO,
0089                                           runType_,
0090                                           sistrip::FED_KEY,
0091                                           fedKey(),
0092                                           sistrip::APV,
0093                                           connection().i2cAddr(1),
0094                                           extrainfo_)
0095                             .title();
0096 
0097     dqm()->setCurrentFolder(directory_);
0098     calib2_[extrainfo_] = HistoSet();
0099     if (runType_ == sistrip::CALIBRATION_SCAN)
0100       calib2_[extrainfo_].histo(dqm()->book1D(title, title, nBins_, 0, 200));
0101     else if (runType_ == sistrip::CALIBRATION_SCAN_DECO)
0102       calib2_[extrainfo_].histo(dqm()->book1D(title, title, nBins_, 0, 250));
0103     calib2_[extrainfo_].isProfile_ = false;
0104     calib2_[extrainfo_].vNumOfEntries_.resize(nBins_, 0);
0105   }
0106 }
0107 
0108 // -----------------------------------------------------------------------------
0109 //
0110 void CalibrationScanTask::fill(const SiStripEventSummary& summary, const edm::DetSet<SiStripRawDigi>& digis) {
0111   if (lastISHA_ != summary.isha() or
0112       lastVFS_ != summary.vfs()) {  // triggered only when there is a change in isha and vfs
0113     lastISHA_ = summary.isha();
0114     lastVFS_ = summary.vfs();
0115     lastCalSel_ = summary.calSel();
0116     lastLatency_ = summary.latency();
0117     lastCalChan_ = summary.calChan();
0118     extrainfo_ = "isha_" + std::to_string(lastISHA_) + "_vfs_" + std::to_string(lastVFS_);
0119     book();  // book histograms and load the right one
0120   } else {
0121     lastISHA_ = summary.isha();
0122     lastVFS_ = summary.vfs();
0123     lastCalSel_ = summary.calSel();
0124     lastLatency_ = summary.latency();
0125     lastCalChan_ = summary.calChan();
0126     extrainfo_ = "isha_" + std::to_string(lastISHA_) + "_vfs_" + std::to_string(lastVFS_);
0127   }
0128 
0129   // retrieve the delay from the EventSummary
0130   int bin = 0;
0131   if (runType_ == sistrip::CALIBRATION_SCAN)
0132     bin = (100 - summary.latency()) * 8 + (7 - summary.calSel());
0133   else if (runType_ == sistrip::CALIBRATION_SCAN_DECO)
0134     bin = (102 - summary.latency()) * 8 + (7 - summary.calSel());
0135 
0136   // Digis are obtained for an APV pair.strips 0->127  : calib1_ strips 128->255: calib2_
0137   // then, only some strips are fired at a time, we use calChan to know that
0138   int isub = lastCalChan_ < 4 ? lastCalChan_ + 4 : lastCalChan_ - 4;
0139   for (int k = 0; k < 16; ++k) {
0140     // all strips of the APV are merged in
0141     updateHistoSet(calib1_[extrainfo_],
0142                    bin,
0143                    digis.data[lastCalChan_ + k * 8].adc() - ped[lastCalChan_ + k * 8] -
0144                        (digis.data[isub + k * 8].adc() - ped[isub + k * 8]));
0145     updateHistoSet(calib2_[extrainfo_],
0146                    bin,
0147                    digis.data[128 + lastCalChan_ + k * 8].adc() - ped[128 + lastCalChan_ + k * 8] -
0148                        (digis.data[128 + isub + k * 8].adc() - ped[128 + isub + k * 8]));
0149   }
0150   update();  //TODO: temporary: find a better solution later
0151 }
0152 
0153 // -----------------------------------------------------------------------------
0154 //
0155 void CalibrationScanTask::update() {
0156   LogDebug("Commissioning") << "[CalibrationScanTask::update]";  // huge output
0157   for (auto element : calib1_)
0158     updateHistoSet(element.second);
0159   for (auto element : calib2_)
0160     updateHistoSet(element.second);
0161 }
0162 
0163 void CalibrationScanTask::setCurrentFolder(const std::string& dir) { directory_ = dir; }