CMS 3D CMS Logo

PedsFullNoiseTask.cc
Go to the documentation of this file.
1 
3 
11 
12 // -----------------------------------------------------------------------------
13 //
15  : CommissioningTask(dqm, conn, "PedsFullNoiseTask"), nstrips_(256) {
16  LogTrace(sistrip::mlDqmSource_) << "[PedsFullNoiseTask::" << __func__ << "]"
17  << " Constructing object...";
18  edm::ParameterSet params = pset.getParameter<edm::ParameterSet>("PedsFullNoiseParameters");
19  nskip_ = params.getParameter<int>("NrEvToSkipAtStart");
20  skipped_ = false;
21  nevpeds_ = params.getParameter<int>("NrEvForPeds");
22  pedsdone_ = false;
23  nadcnoise_ = params.getParameter<int>("NrPosBinsNoiseHist");
24  fillnoiseprofile_ = params.getParameter<bool>("FillNoiseProfile");
25  useavgcm_ = params.getParameter<bool>("UseAverageCommonMode");
26  usefloatpeds_ = params.getParameter<bool>("UseFloatPedestals");
27 }
28 
29 // -----------------------------------------------------------------------------
30 //
32  LogTrace(sistrip::mlDqmSource_) << "[PedsFullNoiseTask::" << __func__ << "]"
33  << " Destructing object...";
34 }
35 
36 // -----------------------------------------------------------------------------
37 //
39  LogTrace(sistrip::mlDqmSource_) << "[PedsFullNoiseTask::" << __func__ << "]";
40 
41  // pedestal profile histo
42  pedhist_.isProfile_ = true;
43  pedhist_.explicitFill_ = false;
44  if (!pedhist_.explicitFill_) {
45  pedhist_.vNumOfEntries_.resize(nstrips_, 0);
47  pedhist_.vSumOfSquares_.resize(nstrips_, 0);
48  }
52  fedKey(),
54  connection().lldChannel(),
56  .title();
57  pedhist_.histo(dqm()->bookProfile(titleped, titleped, nstrips_, -0.5, nstrips_ * 1. - 0.5, 1025, 0., 1025.));
58 
59  // Noise profile
60  noiseprof_.isProfile_ = true;
61  noiseprof_.explicitFill_ = false;
66  }
70  fedKey(),
72  connection().lldChannel(),
74  .title();
75  noiseprof_.histo(dqm()->bookProfile(titlenoise, titlenoise, nstrips_, -0.5, nstrips_ * 1. - 0.5, 1025, 0., 1025.));
76 
77  // noise 2D compact histo
78  noisehist_.explicitFill_ = false;
80  noisehist_.vNumOfEntries_.resize((nstrips_ + 2) * 2 * (nadcnoise_ + 2), 0);
81  }
85  fedKey(),
87  connection().lldChannel(),
89  .title();
90  noisehist_.histo(dqm()->book2S(
91  titlenoise2d, titlenoise2d, 2 * nadcnoise_, -nadcnoise_, nadcnoise_, nstrips_, -0.5, nstrips_ * 1. - 0.5));
92  hist2d_ = (TH2S*)noisehist_.histo()->getTH2S();
93 }
94 
95 // -----------------------------------------------------------------------------
96 //
98  // Check number of digis
99  uint16_t nbins = digis.data.size();
100  if (nbins != nstrips_) {
101  edm::LogWarning(sistrip::mlDqmSource_) << "[PedsFullNoiseTask::" << __func__ << "]"
102  << " " << nstrips_ << " digis expected, but got " << nbins << ". Skipping.";
103  return;
104  }
105 
106  // get the event number of the first event, not necessarily 1 (parallel processing on FUs)
107  static int32_t firstev = summary.event();
108 
109  // skipping events
110  if (!skipped_) {
111  if (static_cast<int32_t>(summary.event()) - firstev < nskip_) {
112  return;
113  } else { // when all events are skipped
114  skipped_ = true;
115  if (nskip_ > 0)
116  LogTrace(sistrip::mlDqmSource_) << "[PedsFullNoiseTask::" << __func__ << "]"
117  << " Done skipping events. Now starting pedestals.";
118  }
119  }
120 
121  // determine pedestals - decoupled from noise determination
122  if (!pedsdone_) {
123  if (static_cast<int32_t>(summary.event()) - firstev < nskip_ + nevpeds_) {
124  // estimate the pedestals
125  for (uint16_t istrip = 0; istrip < nstrips_; ++istrip) {
126  updateHistoSet(pedhist_, istrip, digis.data[istrip].adc());
127  }
128  return;
129  } else { // when pedestals are done
130  pedsdone_ = true;
131  // cache the pedestal values for use in the 2D noise estimation
132  peds_.clear();
133  pedsfl_.clear();
134  for (uint16_t iapv = 0; iapv < 2; ++iapv) {
135  for (uint16_t ibin = 0; ibin < 128; ++ibin) {
136  uint16_t istrip = (iapv * 128) + ibin;
137  if (usefloatpeds_) {
138  pedsfl_.push_back(1. * pedhist_.vSumOfContents_.at(istrip) / pedhist_.vNumOfEntries_.at(istrip));
139  } else {
140  peds_.push_back(
141  static_cast<int16_t>(1. * pedhist_.vSumOfContents_.at(istrip) / pedhist_.vNumOfEntries_.at(istrip)));
142  }
143  }
144  }
145  LogTrace(sistrip::mlDqmSource_) << "[PedsFullNoiseTask::" << __func__ << "]"
146  << " Rough pedestals done. Now starting noise measurements.";
147  }
148  }
149 
150  // fill (or not) the old-style niose profile
151  if (fillnoiseprofile_) {
152  // Calc common mode for both APVs
153  std::vector<int32_t> cm;
154  cm.resize(2, 0);
155  std::vector<uint16_t> adc;
156  for (uint16_t iapv = 0; iapv < 2; iapv++) {
157  adc.clear();
158  adc.reserve(128);
159  for (uint16_t ibin = 0; ibin < 128; ibin++) {
160  if ((iapv * 128) + ibin < nbins) {
161  adc.push_back(digis.data.at((iapv * 128) + ibin).adc());
162  }
163  }
164  sort(adc.begin(), adc.end());
165  // take median as common mode
166  uint16_t index = adc.size() % 2 ? adc.size() / 2 : adc.size() / 2 - 1;
167  cm[iapv] = static_cast<int16_t>(adc[index]);
168  }
169  // 1D noise profile - see also further processing in the update() method
170  for (uint16_t istrip = 0; istrip < nstrips_; ++istrip) {
171  // calculate the noise in the old way, by subtracting the common mode, but without pedestal subtraction
172  int16_t noiseval = static_cast<int16_t>(digis.data.at(istrip).adc()) - cm[istrip / 128];
173  updateHistoSet(noiseprof_, istrip, noiseval);
174  }
175  }
176 
177  // 2D noise histogram
178  std::vector<int16_t> noisevals, noisevalssorted;
179  std::vector<float> noisevalsfl, noisevalssortedfl;
180  for (uint16_t iapv = 0; iapv < 2; ++iapv) {
181  float totadc = 0;
182  noisevals.clear();
183  noisevalsfl.clear();
184  noisevalssorted.clear();
185  noisevalssortedfl.clear();
186  for (uint16_t ibin = 0; ibin < 128; ++ibin) {
187  uint16_t istrip = (iapv * 128) + ibin;
188  // calculate the noise after subtracting the pedestal
189  if (usefloatpeds_) { // if float pedestals -> before FED processing
190  noisevalsfl.push_back(static_cast<float>(digis.data.at(istrip).adc()) - pedsfl_.at(istrip));
191  // now we still have a possible constant shift of the adc values with respect to 0, so we prepare to calculate the median of this shift
192  if (useavgcm_) { // if average CM -> before FED processing
193  totadc += noisevalsfl[ibin];
194  } else { // if median CM -> after FED processing
195  noisevalssortedfl.push_back(noisevalsfl[ibin]);
196  }
197  } else { // if integer pedestals -> after FED processing
198  noisevals.push_back(static_cast<int16_t>(digis.data.at(istrip).adc()) - peds_.at(istrip));
199  // now we still have a possible constant shift of the adc values with respect to 0, so we prepare to calculate the median of this shift
200  if (useavgcm_) { // if average CM -> before FED processing
201  totadc += noisevals[ibin];
202  } else { // if median CM -> after FED processing
203  noisevalssorted.push_back(noisevals[ibin]);
204  }
205  }
206  }
207  // calculate the common mode shift to apply
208  float cmshift = 0;
209  if (useavgcm_) { // if average CM -> before FED processing
210  if (usefloatpeds_) { // if float pedestals -> before FED processing
211  cmshift = totadc / 128;
212  } else { // if integer pedestals -> after FED processing
213  cmshift = static_cast<int16_t>(totadc / 128);
214  }
215  } else { // if median CM -> after FED processing
216  if (usefloatpeds_) { // if float pedestals -> before FED processing
217  // get the median common mode
218  sort(noisevalssortedfl.begin(), noisevalssortedfl.end());
219  uint16_t index = noisevalssortedfl.size() % 2 ? noisevalssortedfl.size() / 2 : noisevalssortedfl.size() / 2 - 1;
220  cmshift = noisevalssortedfl[index];
221  } else { // if integer pedestals -> after FED processing
222  // get the median common mode
223  sort(noisevalssorted.begin(), noisevalssorted.end());
224  uint16_t index = noisevalssorted.size() % 2 ? noisevalssorted.size() / 2 : noisevalssorted.size() / 2 - 1;
225  cmshift = noisevalssorted[index];
226  }
227  }
228  // now loop again to calculate the CM+pedestal subtracted noise values
229  for (uint16_t ibin = 0; ibin < 128; ++ibin) {
230  uint16_t istrip = (iapv * 128) + ibin;
231  // subtract the remaining common mode after subtraction of the rough pedestals
232  float noiseval = (usefloatpeds_ ? noisevalsfl[ibin] : noisevals[ibin]) - cmshift;
233  // retrieve the linear binnr through the histogram
234  uint32_t binnr = hist2d_->GetBin(static_cast<int>(noiseval + nadcnoise_), istrip + 1);
235  // store the noise value in the 2D histo
236  updateHistoSet(noisehist_, binnr); // no value, so weight 1
237  }
238  }
239 }
240 
241 // -----------------------------------------------------------------------------
242 //
244  // pedestals
246 
247  if (fillnoiseprofile_) {
248  // noise profile (does not use HistoSet directly, as want to plot noise as "contents", not "error")
250  for (uint16_t ii = 0; ii < noiseprof_.vNumOfEntries_.size(); ++ii) {
251  float mean = 0.;
252  float spread = 0.;
253  float entries = noiseprof_.vNumOfEntries_[ii];
254  if (entries > 0.) {
255  mean = noiseprof_.vSumOfContents_[ii] / entries;
256  spread = sqrt(noiseprof_.vSumOfSquares_[ii] / entries -
257  mean * mean); // nice way to calculate std dev: Sum (x-<x>)^2 / N
258  }
259  float error = spread / sqrt(entries); // uncertainty on std.dev. when no uncertainty on mean
260  UpdateTProfile::setBinContent(histo, ii + 1, entries, spread, error);
261  }
262  }
263 
264  // noise 2D histo
266 }
267 // -----------------------------------------------------------------------------
std::vector< float > vNumOfEntries_
Utility class that holds histogram title.
static const char mlDqmSource_[]
std::vector< float > vSumOfContents_
#define LogTrace(id)
void updateHistoSet(HistoSet &, const uint32_t &bin, const float &value)
static const char noise2D_[]
Class containning control, module, detector and connection information, at the level of a FED channel...
T sqrt(T t)
Definition: SSEVec.h:23
static void setBinContent(TProfile *const profile, const uint32_t &bin, const double &entries, const double &mean, const double &spread)
void update() override
static const char noiseProfile_[]
const uint32_t & fedKey() const
DQMStore *const dqm() const
ii
Definition: cuy.py:589
int extract(std::vector< int > *output, const std::string &dati)
static const char pedestals_[]
CompactHistoSet noisehist_
std::vector< int16_t > peds_
collection_type data
Definition: DetSet.h:80
PedsFullNoiseTask(DQMStore *dqm, const FedChannelConnection &conn, const edm::ParameterSet &pset)
void histo(MonitorElement *)
~PedsFullNoiseTask() override
conn
Definition: getInfo.py:9
std::vector< double > vSumOfSquares_
void book() override
const std::string & title() const
const FedChannelConnection & connection() const
Log< level::Warning, false > LogWarning
void fill(const SiStripEventSummary &, const edm::DetSet< SiStripRawDigi > &) override
Definition: DQMStore.h:18
uint16_t *__restrict__ uint16_t const *__restrict__ adc
std::vector< float > pedsfl_