CMS 3D CMS Logo

PedestalsTask.cc
Go to the documentation of this file.
8 #include <algorithm>
9 #include <cmath>
10 
11 using namespace sistrip;
12 
13 // -----------------------------------------------------------------------------
14 //
16  : CommissioningTask(dqm, conn, "PedestalsTask"), peds_(), cm_() {
17  LogTrace(mlDqmSource_) << "[PedestalsTask::" << __func__ << "]"
18  << " Constructing object...";
19 }
20 
21 // -----------------------------------------------------------------------------
22 //
24  LogTrace(mlDqmSource_) << "[PedestalsTask::" << __func__ << "]"
25  << " Destructing object...";
26 }
27 
28 // -----------------------------------------------------------------------------
29 //
31  LogTrace(mlDqmSource_) << "[PedestalsTask::" << __func__ << "]";
32 
33  uint16_t nbins;
35  std::string extra_info;
36  peds_.resize(2);
37  nbins = 256;
38 
39  // Pedestals histogram
40  extra_info = sistrip::extrainfo::pedestals_;
41  peds_[0].isProfile_ = true;
42 
46  fedKey(),
48  connection().lldChannel(),
49  extra_info)
50  .title();
51 
52  peds_[0].histo(dqm()->bookProfile(title, title, nbins, -0.5, nbins * 1. - 0.5, 1025, 0., 1025.));
53 
54  peds_[0].vNumOfEntries_.resize(nbins, 0);
55  peds_[0].vSumOfContents_.resize(nbins, 0);
56  peds_[0].vSumOfSquares_.resize(nbins, 0);
57 
58  // Noise histogram
59  extra_info = sistrip::extrainfo::noise_;
60  peds_[1].isProfile_ = true;
61 
65  fedKey(),
67  connection().lldChannel(),
68  extra_info)
69  .title();
70 
71  peds_[1].histo(dqm()->bookProfile(title, title, nbins, -0.5, nbins * 1. - 0.5, 1025, 0., 1025.));
72 
73  peds_[1].vNumOfEntries_.resize(nbins, 0);
74  peds_[1].vSumOfContents_.resize(nbins, 0);
75  peds_[1].vSumOfSquares_.resize(nbins, 0);
76 
77  // Common mode histograms
78  cm_.resize(2);
79  nbins = 1024;
80  for (uint16_t iapv = 0; iapv < 2; iapv++) {
84  fedKey(),
86  connection().i2cAddr(iapv),
88  .title();
89 
90  cm_[iapv].histo(dqm()->book1D(title, title, nbins, -0.5, nbins * 1. - 0.5));
91  cm_[iapv].isProfile_ = false;
92 
93  cm_[iapv].vNumOfEntries_.resize(nbins, 0);
94  cm_[iapv].vNumOfEntries_.resize(nbins, 0);
95  }
96 }
97 
98 // -----------------------------------------------------------------------------
99 //
101  if (digis.data.size() != peds_[0].vNumOfEntries_.size()) {
102  edm::LogWarning(mlDqmSource_) << "[PedestalsTask::" << __func__ << "]"
103  << " Unexpected number of digis: " << digis.data.size();
104  return;
105  }
106 
107  // Check number of digis
108  uint16_t nbins = peds_[0].vNumOfEntries_.size();
109  if (digis.data.size() < nbins) {
110  nbins = digis.data.size();
111  }
112 
113  //@@ Inefficient!!!
114  uint16_t napvs = nbins / 128;
115  std::vector<uint32_t> cm;
116  cm.resize(napvs, 0);
117 
118  // Calc common mode for both APVs
119  std::vector<uint16_t> adc;
120  for (uint16_t iapv = 0; iapv < napvs; iapv++) {
121  adc.clear();
122  adc.reserve(128);
123  for (uint16_t ibin = 0; ibin < 128; ibin++) {
124  if ((iapv * 128) + ibin < nbins) {
125  adc.push_back(digis.data[(iapv * 128) + ibin].adc()); //@@ VIRGIN RAW DATA (MUX, APV READOUT)
126  }
127  }
128  sort(adc.begin(), adc.end());
129  uint16_t index = adc.size() % 2 ? adc.size() / 2 : adc.size() / 2 - 1;
130  if (!adc.empty()) {
131  cm[iapv] = static_cast<uint32_t>(adc[index]);
132  }
133  }
134 
135  for (uint16_t ibin = 0; ibin < nbins; ibin++) {
136  updateHistoSet(peds_[0], ibin, digis.data[ibin].adc()); // peds and raw noise
137  float diff = static_cast<float>(digis.data[ibin].adc()) - static_cast<float>(cm[ibin / 128]);
138  updateHistoSet(peds_[1], ibin, diff); // residuals and real noise
139  }
140 
141  if (cm.size() < cm_.size()) {
142  edm::LogWarning(mlDqmSource_) << "[PedestalsTask::" << __func__ << "]"
143  << " Fewer CM values than expected: " << cm.size();
144  }
145 
146  updateHistoSet(cm_[0], cm[0]);
147  updateHistoSet(cm_[1], cm[1]);
148 }
149 
150 // -----------------------------------------------------------------------------
151 //
153  // Pedestals
154  updateHistoSet(peds_[0]);
155 
156  // Noise (cannot use HistoSet directly, as want to plot noise as "contents", not "error")
157  TProfile* histo = ExtractTObject<TProfile>().extract(peds_[1].histo());
158  for (uint16_t ii = 0; ii < peds_[1].vNumOfEntries_.size(); ++ii) {
159  float mean = 0.;
160  float spread = 0.;
161  float entries = peds_[1].vNumOfEntries_[ii];
162  if (entries > 0.) {
163  mean = peds_[1].vSumOfContents_[ii] / entries;
164  spread = sqrt(peds_[1].vSumOfSquares_[ii] / entries - mean * mean);
165  }
166 
167  float noise = spread;
168  float error = 0; // sqrt(entries) / entries;
169 
171  }
172 
173  // Common mode
174  updateHistoSet(cm_[0]);
175  updateHistoSet(cm_[1]);
176 }
static const char noise_[]
void fill(const SiStripEventSummary &, const edm::DetSet< SiStripRawDigi > &) override
Utility class that holds histogram title.
static const char mlDqmSource_[]
sistrip classes
#define LogTrace(id)
void updateHistoSet(HistoSet &, const uint32_t &bin, const float &value)
PedestalsTask(DQMStore *, const FedChannelConnection &)
Class containning control, module, detector and connection information, at the level of a FED channel...
T sqrt(T t)
Definition: SSEVec.h:23
std::vector< HistoSet > peds_
Definition: PedestalsTask.h:20
static void setBinContent(TProfile *const profile, const uint32_t &bin, const double &entries, const double &mean, const double &spread)
static const char commonMode_[]
const uint32_t & fedKey() const
void update() override
std::vector< HistoSet > cm_
Definition: PedestalsTask.h:21
DQMStore *const dqm() const
ii
Definition: cuy.py:589
int extract(std::vector< int > *output, const std::string &dati)
static const char pedestals_[]
void book() override
collection_type data
Definition: DetSet.h:80
conn
Definition: getInfo.py:9
const std::string & title() const
const FedChannelConnection & connection() const
Log< level::Warning, false > LogWarning
Definition: DQMStore.h:18
~PedestalsTask() override
uint16_t *__restrict__ uint16_t const *__restrict__ adc