CMS 3D CMS Logo

PedsFullNoiseHistosUsingDb.cc
Go to the documentation of this file.
1 
8 #include <iostream>
9 
10 using namespace sistrip;
11 
12 // -----------------------------------------------------------------------------
15  DQMStore* bei,
16  SiStripConfigDb* const db,
19  pset.getParameter<edm::ParameterSet>("PedsFullNoiseParameters"), bei, sistrip::PEDS_FULL_NOISE),
21  PedsFullNoiseHistograms(pset.getParameter<edm::ParameterSet>("PedsFullNoiseParameters"), bei) {
22  LogTrace(mlDqmClient_) << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
23  << " Constructing object...";
24 
25  highThreshold_ = this->pset().getParameter<double>("HighThreshold");
26  lowThreshold_ = this->pset().getParameter<double>("LowThreshold");
27 
28  LogTrace(mlDqmClient_) << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
29  << " Set FED zero suppression high/low threshold to " << highThreshold_ << "/"
30  << lowThreshold_;
31 
32  disableBadStrips_ = this->pset().getParameter<bool>("DisableBadStrips");
33  keepStripsDisabled_ = this->pset().getParameter<bool>("KeepStripsDisabled");
34  skipEmptyStrips_ = this->pset().getParameter<bool>("SkipEmptyStrips");
35  uploadOnlyStripBadChannelBit_ = this->pset().getParameter<bool>("UploadOnlyStripBadChannelBit");
36  uploadPedsFullNoiseDBTable_ = this->pset().getParameter<bool>("UploadPedsFullNoiseDBTable");
37 
38  LogTrace(mlDqmClient_) << "[PedestalsHistosUsingDb::" << __func__ << "]"
39  << " Disabling strips: " << disableBadStrips_
40  << " ; keeping previously disabled strips: " << keepStripsDisabled_
41  << " ; skip strips with no data: " << skipEmptyStrips_
42  << " ; upload only bad channel bit: " << uploadOnlyStripBadChannelBit_;
43 
45  this->pset().existsAs<bool>("doSelectiveUpload") ? this->pset().getParameter<bool>("doSelectiveUpload") : false;
46  LogTrace(mlDqmClient_) << "[PedestalsHistosUsingDb::" << __func__ << "]"
47  << " Selective upload of modules set to : " << allowSelectiveUpload_;
48 }
49 
50 // -----------------------------------------------------------------------------
53  LogTrace(mlDqmClient_) << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
54  << " Destructing object...";
55 }
56 
57 // -----------------------------------------------------------------------------
60  LogTrace(mlDqmClient_) << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]";
61 
62  if (!db()) {
63  edm::LogError(mlDqmClient_) << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
64  << " NULL pointer to SiStripConfigDb interface!"
65  << " Aborting upload...";
66  return;
67  }
68 
69  // Update FED descriptions with new peds/noise values
71  update(feds);
72  if (doUploadConf()) { // check whether the upload HD config is set to true
73 
74  edm::LogVerbatim(mlDqmClient_) << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
75  << " Uploading pedestals/noise to DB...";
76 
77  db()->uploadFedDescriptions(); // change the FED version
78 
79  edm::LogVerbatim(mlDqmClient_) << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
80  << " Completed database upload of " << feds.size() << " FED descriptions!";
81  } else {
82  edm::LogWarning(mlDqmClient_) << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
83  << " TEST! No pedestals/noise values will be uploaded to DB...";
84  }
85 }
86 
87 // -----------------------------------------------------------------------------
90  // Iterate through feds and update fed descriptions
91  uint16_t updated = 0;
92  SiStripConfigDb::FedDescriptionsV::const_iterator ifed;
93 
94  for (ifed = feds.begin(); ifed != feds.end(); ifed++) { // Loop on the FED for this partition
95 
96  for (uint16_t ichan = 0; ichan < sistrip::FEDCH_PER_FED; ichan++) {
97  // Build FED and FEC keys from the cabling object i.e. checking if there is a connection
98  const FedChannelConnection& conn = cabling()->fedConnection((*ifed)->getFedId(), ichan);
99  if (conn.fecCrate() == sistrip::invalid_ || conn.fecSlot() == sistrip::invalid_ ||
100  conn.fecRing() == sistrip::invalid_ || conn.ccuAddr() == sistrip::invalid_ ||
101  conn.ccuChan() == sistrip::invalid_ || conn.lldChannel() == sistrip::invalid_)
102  continue;
103 
104  // build the FED and FEC key from the connection object
105  SiStripFedKey fed_key(conn.fedId(), SiStripFedKey::feUnit(conn.fedCh()), SiStripFedKey::feChan(conn.fedCh()));
106 
107  SiStripFecKey fec_key(
108  conn.fecCrate(), conn.fecSlot(), conn.fecRing(), conn.ccuAddr(), conn.ccuChan(), conn.lldChannel());
109 
110  // Locate appropriate analysis object --> based on FEC keys cause they are per lldChannel
111  Analyses::const_iterator iter = data(allowSelectiveUpload_).find(fec_key.key());
112  if (iter != data(allowSelectiveUpload_).end()) {
113  PedsFullNoiseAnalysis* anal = dynamic_cast<PedsFullNoiseAnalysis*>(iter->second);
114 
115  if (!anal) {
116  edm::LogError(mlDqmClient_) << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
117  << " NULL pointer to analysis object!";
118  continue;
119  }
120 
121  // Determine the pedestal shift to apply --> this is standard in the pedestal paylaod to avoid loss of signal from common-mode subtraction
122  uint32_t pedshift = 127;
123  for (uint16_t iapv = 0; iapv < sistrip::APVS_PER_FEDCH; iapv++) {
124  uint32_t pedmin = (uint32_t)anal->pedsMin()[iapv];
125  pedshift = pedmin < pedshift ? pedmin : pedshift;
126  }
127 
128  // Iterate through APVs and strips
129  for (uint16_t iapv = 0; iapv < sistrip::APVS_PER_FEDCH; iapv++) {
130  for (uint16_t istr = 0; istr < anal->peds()[iapv].size(); istr++) { // Loop on the pedestal for each APV
131 
132  if (not uploadOnlyStripBadChannelBit_ and anal->peds()[iapv][istr] < 1.) { //@@ ie, zero
134  << "[PedestalsHistosUsingDb::" << __func__ << "]"
135  << " Skipping ZERO pedestal value (ie, NO UPLOAD TO DB!) for FedKey/Id/Ch: " << hex << setw(8)
136  << setfill('0') << fed_key.key() << dec << "/" << (*ifed)->getFedId() << "/" << ichan
137  << " and device with FEC/slot/ring/CCU/LLD " << fec_key.fecCrate() << "/" << fec_key.fecSlot() << "/"
138  << fec_key.fecRing() << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << "/"
139  << fec_key.channel();
140  continue; //@@ do not upload
141  }
142 
143  // get the information on the strip as it was on the db
144  Fed9U::Fed9UAddress addr(ichan, iapv, istr);
145  Fed9U::Fed9UStripDescription temp = (*ifed)->getFedStrips().getStrip(addr);
146 
147  // determine whether we need to disable the strip
148  bool disableStrip = false;
149  std::stringstream ss_disable;
150 
151  if (temp.getDisable()) { // strip already disabled in the database
152  ss_disable << "Already Disabled: " << conn.fecCrate() << " " << conn.fecSlot() << " " << conn.fecRing()
153  << " " << conn.ccuAddr() << " " << conn.ccuChan() << " " << conn.lldChannel() << " " << iapv
154  << " " << istr << std::endl;
156  disableStrip = true; // in case one wants to keep them disabled
157  }
158 
159  // to disable new strips
160  if (disableBadStrips_) {
161  SiStripFedKey fed_key(anal->fedKey());
162  PedsFullNoiseAnalysis::VInt dead = anal->deadStrip()[iapv];
163  if (not skipEmptyStrips_ and // if one don't want to skip dead strips
164  find(dead.begin(), dead.end(), istr) != dead.end()) {
165  disableStrip = true;
166  ss_disable << "Disabling Dead Strip: " << conn.fecCrate() << " " << conn.fecSlot() << " "
167  << conn.fecRing() << " " << conn.ccuAddr() << " " << conn.ccuChan() << " "
168  << conn.lldChannel() << " " << iapv << " " << istr << std::endl;
169  }
170 
171  PedsFullNoiseAnalysis::VInt badcChan =
172  anal->badStrip()[iapv]; // new feature --> this is the sample of the whole bad strips from the analysis
173  if (not disableStrip) {
174  if (find(badcChan.begin(), badcChan.end(), istr) != badcChan.end()) {
175  disableStrip = true;
176  ss_disable << "Disabling Bad strip: " << conn.fecCrate() << " " << conn.fecSlot() << " "
177  << conn.fecRing() << " " << conn.ccuAddr() << " " << conn.ccuChan() << " "
178  << conn.lldChannel() << " " << iapv << " " << istr << std::endl;
179  }
180  }
181  }
182 
183  if (edm::isDebugEnabled())
184  LogTrace(mlDqmClient_) << ss_disable.str();
185 
186  uint32_t pedestalVal = 0;
187  float noiseVal = 0;
188  float lowThr = 0;
189  float highThr = 0;
190 
191  // download the previous pedestal/noise payload from the DB
193  pedestalVal = static_cast<uint32_t>(temp.getPedestal());
194  noiseVal = static_cast<float>(temp.getNoise());
195  lowThr = static_cast<float>(temp.getLowThresholdFactor());
196  highThr = static_cast<float>(temp.getHighThresholdFactor());
197  } else {
198  pedestalVal = static_cast<uint32_t>(anal->peds()[iapv][istr] - pedshift);
199  noiseVal = anal->noise()[iapv][istr];
200  lowThr = lowThreshold_;
201  highThr = highThreshold_;
202  }
203 
205  Fed9U::Fed9UStripDescription data(pedestalVal, highThr, lowThr, noiseVal, disableStrip);
206 
207  std::stringstream ss;
208  if (data.getDisable() && edm::isDebugEnabled()) {
209  ss << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
210  << " Disabling strip in Fed9UStripDescription object..." << std::endl
211  << " for FED id/channel and APV/strip : " << fed_key.fedId() << "/" << fed_key.fedChannel() << " "
212  << iapv << "/" << istr << std::endl
213  << " and crate/FEC/ring/CCU/module : " << fec_key.fecCrate() << "/" << fec_key.fecSlot() << "/"
214  << fec_key.fecRing() << "/" << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << std::endl
215  << " from ped/noise/high/low/disable : " << static_cast<uint32_t>(temp.getPedestal()) << "/"
216  << static_cast<float>(temp.getHighThresholdFactor()) << "/"
217  << static_cast<float>(temp.getLowThresholdFactor()) << "/" << static_cast<float>(temp.getNoise())
218  << "/" << static_cast<uint16_t>(temp.getDisable()) << std::endl;
219  }
220 
221  (*ifed)->getFedStrips().setStrip(addr, data);
222 
223  if (data.getDisable() && edm::isDebugEnabled()) {
224  ss << " to ped/noise/high/low/disable : " << static_cast<uint32_t>(data.getPedestal()) << "/"
225  << static_cast<float>(data.getHighThresholdFactor()) << "/"
226  << static_cast<float>(data.getLowThresholdFactor()) << "/" << static_cast<float>(data.getNoise())
227  << "/" << static_cast<uint16_t>(data.getDisable()) << std::endl;
228  LogTrace(mlDqmClient_) << ss.str();
229  }
230  } // end loop on strips
231  } // end loop on apvs
232  updated++;
233  } else { // device not found in the analysis
234  if (deviceIsPresent(fec_key)) {
235  edm::LogWarning(mlDqmClient_) << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
236  << " Unable to find pedestals/noise for FedKey/Id/Ch: " << hex << setw(8)
237  << setfill('0') << fed_key.key() << dec << "/" << (*ifed)->getFedId() << "/"
238  << ichan << " and device with FEC/slot/ring/CCU/LLD " << fec_key.fecCrate()
239  << "/" << fec_key.fecSlot() << "/" << fec_key.fecRing() << "/"
240  << fec_key.ccuAddr() << "/" << fec_key.ccuChan() << "/" << fec_key.channel();
241  }
242  }
243  }
244  }
245 
246  edm::LogVerbatim(mlDqmClient_) << "[PedsFullNoiseHistosUsingDb::" << __func__ << "]"
247  << " Updated FED pedestals/noise for " << updated << " channels";
248 }
249 
250 // -----------------------------------------------------------------------------
253  PedsFullNoiseAnalysis* anal = dynamic_cast<PedsFullNoiseAnalysis*>(analysis->second);
254 
255  if (!anal) {
256  return;
257  }
258 
259  SiStripFecKey fec_key(anal->fecKey());
260  SiStripFedKey fed_key(anal->fedKey());
261 
262  for (uint16_t iapv = 0; iapv < 2; ++iapv) {
263  // Create a description for the standard pedestal analysis
264  PedestalsAnalysisDescription* pedestalDescription;
265  pedestalDescription =
266  new PedestalsAnalysisDescription(anal->deadStripBit()[iapv],
267  anal->badStripBit()[iapv],
268  anal->pedsMean()[iapv],
269  anal->pedsSpread()[iapv],
270  anal->noiseMean()[iapv],
271  anal->noiseSpread()[iapv],
272  anal->rawMean()[iapv],
273  anal->rawSpread()[iapv],
274  anal->pedsMax()[iapv],
275  anal->pedsMin()[iapv],
276  anal->noiseMax()[iapv],
277  anal->noiseMin()[iapv],
278  anal->rawMax()[iapv],
279  anal->rawMin()[iapv],
280  fec_key.fecCrate(),
281  fec_key.fecSlot(),
282  fec_key.fecRing(),
283  fec_key.ccuAddr(),
284  fec_key.ccuChan(),
285  SiStripFecKey::i2cAddr(fec_key.lldChan(), !iapv),
286  db()->dbParams().partitions().begin()->second.partitionName(),
287  db()->dbParams().partitions().begin()->second.runNumber(),
288  anal->isValid(),
289  "",
290  fed_key.fedId(),
291  fed_key.feUnit(),
292  fed_key.feChan(),
293  fed_key.fedApv());
294 
295  // Add comments
296  typedef std::vector<std::string> Strings;
297  Strings errors = anal->getErrorCodes();
298  Strings::const_iterator istr = errors.begin();
299  Strings::const_iterator jstr = errors.end();
300  for (; istr != jstr; ++istr) {
301  pedestalDescription->addComments(*istr);
302  }
303 
304  // Store description
305  desc.push_back(pedestalDescription);
306 
307  // Create description
309  PedsFullNoiseAnalysisDescription* pedsFullNoiseDescription;
310  pedsFullNoiseDescription = new PedsFullNoiseAnalysisDescription(
311  anal->deadStrip()[iapv],
312  anal->badStrip()[iapv],
313  anal->shiftedStrip()[iapv], // bad strip-id within an APV due to offset
314  anal->lowNoiseStrip()[iapv], // bad strip-id within an APV due to noise
315  anal->largeNoiseStrip()[iapv], // bad strip-id within an APV due to noise
316  anal->largeNoiseSignificance()[iapv], // bad strip-id within an APV due to noise significance
317  anal->badFitStatus()[iapv], // bad strip-id within an APV due to fit status
318  anal->badADProbab()[iapv], // bad strip-id within an APV due to AD probab
319  anal->badKSProbab()[iapv], // bad strip-id within an APV due to KS probab
320  anal->badJBProbab()[iapv], // bad strip-id within an APV due to JB probab
321  anal->badChi2Probab()[iapv], // bad strip-id within an APV due to Chi2 probab
322  anal->badTailStrip()[iapv], // bad strip-id within an APV due to tail
323  anal->badDoublePeakStrip()[iapv], // bad strip-id within an APV due to Double peaks
325  anal->adProbab()[iapv], // one value oer strip
326  anal->ksProbab()[iapv], // one value oer strip
327  anal->jbProbab()[iapv], // one value oer strip
328  anal->chi2Probab()[iapv], // one value oer strip
330  anal->residualRMS()[iapv],
331  anal->residualSigmaGaus()[iapv],
332  anal->noiseSignificance()[iapv],
333  anal->residualSkewness()[iapv],
334  anal->residualKurtosis()[iapv],
335  anal->residualIntegralNsigma()[iapv],
336  anal->residualIntegral()[iapv],
338  fec_key.fecCrate(),
339  fec_key.fecSlot(),
340  fec_key.fecRing(),
341  fec_key.ccuAddr(),
342  fec_key.ccuChan(),
343  SiStripFecKey::i2cAddr(fec_key.lldChan(), !iapv),
344  db()->dbParams().partitions().begin()->second.partitionName(),
345  db()->dbParams().partitions().begin()->second.runNumber(),
346  anal->isValid(),
347  "",
348  fed_key.fedId(),
349  fed_key.feUnit(),
350  fed_key.feChan(),
351  fed_key.fedApv());
352  istr = errors.begin();
353  jstr = errors.end();
354  for (; istr != jstr; ++istr) {
355  pedsFullNoiseDescription->addComments(*istr);
356  }
357 
358  // Store description
359  desc.push_back(pedsFullNoiseDescription);
360  }
361  }
362 }
Log< level::Info, true > LogVerbatim
bool isDebugEnabled()
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void update(SiStripConfigDb::FedDescriptionsRange)
const uint16_t & feChan() const
Analyses & data(bool getMaskedData=false)
const uint16_t & feUnit() const
A container class for generic run and event-related info, information required by the commissioning a...
Definition: SiStripFedKey.h:56
bool deviceIsPresent(const SiStripFecKey &)
FedDescriptionsRange getFedDescriptions(std::string partition="")
std::vector< std::string > Strings
Definition: MsgTools.h:18
FedChannelConnection fedConnection(uint16_t fed_id, uint16_t fed_ch) const
FedDescriptions::range FedDescriptionsRange
static const char mlDqmClient_[]
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:172
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
const_iterator_range partitions() const
sistrip classes
#define LogTrace(id)
Histogram-based analysis for pedestal run.
Utility class that identifies a position within the strip tracker control structure, down to the level of an APV25.
Definition: SiStripFecKey.h:45
uint16_t fedChannel() const
const uint16_t & i2cAddr() const
Class containning control, module, detector and connection information, at the level of a FED channel...
SiStripConfigDb *const db() const
An interface class to the DeviceFactory.
const uint32_t & key() const
Definition: SiStripKey.h:120
SiStripFedCabling *const cabling() const
std::vector< uint16_t > VInt
const uint16_t & fedId() const
void create(SiStripConfigDb::AnalysisDescriptionsV &, Analysis) override
void uploadFedDescriptions(std::string partition="")
static const uint16_t invalid_
Definition: Constants.h:16
PedsFullNoiseHistosUsingDb(const edm::ParameterSet &pset, DQMStore *, SiStripConfigDb *const, edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken)
HLT enums.
static const uint16_t FEDCH_PER_FED
std::vector< AnalysisDescription * > AnalysisDescriptionsV
conn
Definition: getInfo.py:9
const edm::ParameterSet & pset() const
Definition: errors.py:1
const SiStripDbParams & dbParams() const
Log< level::Warning, false > LogWarning
static const uint16_t APVS_PER_FEDCH