CMS 3D CMS Logo

CalibrationTask.cc
Go to the documentation of this file.
6 
7 #include <arpa/inet.h>
8 #include <cstdio>
9 #include <fstream>
10 #include <netdb.h>
11 #include <sys/socket.h>
12 #include <sys/unistd.h>
13 
14 // -----------------------------------------------------------------------------
15 //
18  const sistrip::RunType& rtype,
19  const char* filename,
20  uint32_t run,
21  const SiStripPedestals& pedestals)
22  : CommissioningTask(dqm, conn, "CalibrationTask"),
23  runType_(rtype),
24  nBins_(0),
25  lastCalChan_(1000),
26  lastCalSel_(1000),
27  lastLatency_(1000),
28  extrainfo_(),
29  run_(run) {
30  // each latency point is 25ns, each calSel is 25/8 --> 64 points = 8 calsel + 8 latency --> as set in the DAQ configuration
32  nBins_ = 64;
33  // each latency point is 25ns, each calSel is 25/8 --> 80 points = 8 calsel + 10 latency --> as set in the DAQ configuration
35  nBins_ = 80;
36 
37  LogDebug("Commissioning") << "[CalibrationTask::CalibrationTask] Constructing object...";
38 
39  // load the pedestals
40  SiStripPedestals::Range detPedRange = pedestals.getRange(conn.detId());
41  int start = conn.apvPairNumber() * 256;
42  int stop = start + 256;
43  int value = 0;
44  ped.reserve(256);
45  for (int strip = start; strip < stop; ++strip) {
46  value = int(pedestals.getPed(strip, detPedRange));
47  if (value > 895)
48  value -= 1024;
49  ped.push_back(value);
50  }
51 }
52 
53 // -----------------------------------------------------------------------------
54 //
56  LogDebug("Commissioning") << "[CalibrationTask::CalibrationTask] Destructing object...";
57 }
58 
59 // -----------------------------------------------------------------------------
60 //
62  LogDebug("Commissioning") << "[CalibrationTask::book]";
63 
64  // book 16 histograms, one for each strip in a calibration group --> APV1 --> 16 = dimension of one calChan
65  if (calib1_.find(extrainfo_) == calib1_.end()) {
67  calib1_[extrainfo_].resize(16);
68  for (int i = 0; i < 16; ++i) {
69  std::string postfix = extrainfo_ + "_istrip_" + std::to_string(i);
71  runType_,
73  fedKey(),
75  connection().i2cAddr(0),
76  postfix)
77  .title();
78 
80  calib1_[extrainfo_][i].histo(dqm()->book1D(title, title, nBins_, 0, 200));
82  calib1_[extrainfo_][i].histo(dqm()->book1D(title, title, nBins_, 0, 250));
83  calib1_[extrainfo_][i].isProfile_ = false;
84  calib1_[extrainfo_][i].vNumOfEntries_.resize(nBins_, 0);
85  }
86  }
87 
88  // book 16 histograms, one for each strip in a calibration group --> APV2 --> 16 = dimension of one calChan
89  if (calib2_.find(extrainfo_) == calib2_.end()) {
91  calib2_[extrainfo_].resize(16);
92  for (int i = 0; i < 16; ++i) {
93  std::string postfix = extrainfo_ + "_istrip_" + std::to_string(i);
95  runType_,
97  fedKey(),
99  connection().i2cAddr(1),
100  postfix)
101  .title();
102 
104  calib2_[extrainfo_][i].histo(dqm()->book1D(title, title, nBins_, 0, 200));
106  calib2_[extrainfo_][i].histo(dqm()->book1D(title, title, nBins_, 0, 250));
107 
108  calib2_[extrainfo_][i].isProfile_ = false;
109  calib2_[extrainfo_][i].vNumOfEntries_.resize(nBins_, 0);
110  }
111  }
112 }
113 
114 // -----------------------------------------------------------------------------
115 //
117  LogDebug("Commissioning") << "[CalibrationTask::fill]";
118 
119  if (lastCalChan_ != summary.calChan()) { // change in the calChan value
120  lastCalChan_ = summary.calChan();
121  lastLatency_ = summary.latency();
122  lastCalSel_ = summary.calSel();
123  extrainfo_ = "calChan_" + std::to_string(lastCalChan_);
124  book(); // book histograms and load the right one
125  } else {
126  lastCalChan_ = summary.calChan();
127  lastLatency_ = summary.latency();
128  lastCalSel_ = summary.calSel();
129  extrainfo_ = "calChan_" + std::to_string(lastCalChan_);
130  }
131 
132  // Check if CalChan changed. In that case, save, reset histo, change title, and continue
133  int isub = lastCalChan_ < 4 ? lastCalChan_ + 4 : lastCalChan_ - 4;
134  int bin = 0;
135 
137  bin = (100 - summary.latency()) * 8 + (7 - summary.calSel());
139  bin = (102 - summary.latency()) * 8 + (7 - summary.calSel());
140 
141  // Fill the histograms data-ped -(data-ped)_isub, the second term corresponds to the common mode substraction, looking at a strip far away.
142  for (int k = 0; k < 16; ++k) {
144  bin,
145  digis.data[lastCalChan_ + k * 8].adc() - ped[lastCalChan_ + k * 8] -
146  (digis.data[isub + k * 8].adc() - ped[isub + k * 8]));
148  bin,
149  digis.data[128 + lastCalChan_ + k * 8].adc() - ped[128 + lastCalChan_ + k * 8] -
150  (digis.data[128 + isub + k * 8].adc() - ped[128 + isub + k * 8]));
151  }
152  update(); //TODO: temporary: find a better solution later
153 }
154 
155 // -----------------------------------------------------------------------------
156 //
158  LogDebug("Commissioning") << "[CalibrationTask::update]"; // huge output
159 
160  for (const auto& element : calib1_) { // all pulse for different calChan
161  for (auto vecelement : element.second) // all strips in a calCan
162  updateHistoSet(vecelement);
163  }
164 
165  for (const auto& element : calib2_) { // all pulse for different calChan
166  for (auto vecelement : element.second) // all strips in a calCan
167  updateHistoSet(vecelement);
168  }
169 }
170 
Definition: start.py:1
void update() override
const Range getRange(const uint32_t &detID) const
uint16_t lastCalSel_
Utility class that holds histogram title.
void setCurrentFolder(std::string const &fullpath) override
Definition: DQMStore.h:646
std::map< std::string, std::vector< HistoSet > > calib2_
std::string extrainfo_
std::string directory_
std::pair< ContainerIterator, ContainerIterator > Range
static std::string to_string(const XMLCh *ch)
float getPed(const uint16_t &strip, const Range &range) const
uint16_t lastLatency_
void updateHistoSet(HistoSet &, const uint32_t &bin, const float &value)
Class containning control, module, detector and connection information, at the level of a FED channel...
uint16_t lastCalChan_
std::map< std::string, std::vector< HistoSet > > calib1_
sistrip::RunType runType_
CalibrationTask(DQMStore *, const FedChannelConnection &, const sistrip::RunType &, const char *filename, uint32_t run, const SiStripPedestals &pedestals)
Definition: value.py:1
const uint32_t & fedKey() const
void setCurrentFolder(const std::string &)
DQMStore *const dqm() const
std::vector< uint16_t > ped
void book() override
collection_type data
Definition: DetSet.h:80
~CalibrationTask() override
conn
Definition: getInfo.py:9
const std::string & title() const
const FedChannelConnection & connection() const
Definition: DQMStore.h:18
void fill(const SiStripEventSummary &, const edm::DetSet< SiStripRawDigi > &) override
#define LogDebug(id)