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