CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCConditions.cc
Go to the documentation of this file.
1 
3 
6 
9 
16 
23 
30 
32 
36 
38 : theGains(), theCrosstalk(), thePedestals(), theNoiseMatrix(),
39  theBadStrips(), theBadWires(), theBadChambers(),
40  theChipCorrections(), theChamberTimingCorrections(), theGasGainCorrections(),
41  indexer_(0), mapper_(0),
42  readBadChannels_(false), readBadChambers_(false),
43  useTimingCorrections_(false), useGasGainCorrections_(false),
44  idOfBadChannelWords_(CSCDetId()), badStripWord_(0), badWireWord_(0), theAverageGain( -1.0 )
45 {
46  readBadChannels_ = ps.getParameter<bool>("readBadChannels");
47  readBadChambers_ = ps.getParameter<bool>("readBadChambers");
48  useTimingCorrections_ = ps.getParameter<bool>("CSCUseTimingCorrections");
49  useGasGainCorrections_ = ps.getParameter<bool>("CSCUseGasGainCorrections");
50 
51 }
52 
53 
55 
57 {
58  // Algorithms
59  es.get<CSCIndexerRecord>().get( indexer_ );
60  es.get<CSCChannelMapperRecord>().get( mapper_ );
61 
62  // Strip gains
63  es.get<CSCDBGainsRcd>().get( theGains );
64  // Strip X-talk
65  es.get<CSCDBCrosstalkRcd>().get( theCrosstalk );
66  // Strip pedestals
67  es.get<CSCDBPedestalsRcd>().get( thePedestals );
68  // Strip autocorrelation noise matrix
70 
71  if ( useTimingCorrections()){
72  // Buckeye chip speeds
74  // Cable lengths from chambers to peripheral crate and additional chamber level timing correction
76  }
77 
78  if ( readBadChannels() ) {
79  // Bad strip channels
80  es.get<CSCBadStripsRcd>().get( theBadStrips );
81  // Bad wiregroup channels
82  es.get<CSCBadWiresRcd>().get( theBadWires );
83 
84  //@@ if( badStripsWatcher_.check( es ) ) {
85  // fillBadStripWords();
86  //@@ }
87  //@@ if( badWiresWatcher_.check( es ) ) {
88  // fillBadWireWords();
89  //@ }
90 
91  }
92 
93  // Has GainsRcd changed?
94  if( gainsWatcher_.check( es ) ) { // Yes...
95  theAverageGain = -1.0; // ...reset, so next access will recalculate it
96  }
97 
98  if ( readBadChambers() ) {
99  // Entire bad chambers
100  es.get<CSCBadChambersRcd>().get( theBadChambers );
101  }
102 
103  if ( useGasGainCorrections()){
105  }
106 
107 // print();
108 }
109 
111 
112  // input CSCDetId is expected to be an offline value i.e. different for ME1/1A and ME1/1B
113 
114  // Only update content if necessary
115  if ( id != idOfBadChannelWords() ) {
116 
117  // store offline CSCDetId for the two bad channel words
119 
120  // reset to all zeroes
121  badStripWord_.reset();
122  badWireWord_.reset();
123 
124  if ( readBadChannels() ) {
125  // convert to online CSCDetId since that is how conditions data are stored
126  CSCDetId idraw = mapper_->rawCSCDetId( id );
127  fillBadStripWord( idraw );
128  fillBadWireWord( idraw );
129  }
130  }
131 }
132 
134 
136 
137  // Input CSCDetId is expected to be a 'raw' value
138 
139  // Find linear index of chamber for input CSCDetId
140  int inputIndex = indexer_->chamberIndex( id );
141  short inputLayer = id.layer();
142 
143  // Does this chamber occur in bad channel list? If so, unpack its bad channels
144 
145  // chambers is a vector<BadChamber>
146  // channels is a vector<BadChannel>
147  // Each BadChamber contains its index (1-468 or 540 w. ME42), the no. of bad channels,
148  // and the index within vector<BadChannel> where this chamber's bad channels start.
149 
150  for ( size_t i=0; i<theBadStrips->chambers.size(); ++i ) { // loop over bad chambers
151  int indexc = theBadStrips->chambers[i].chamber_index;
152  if (indexc != inputIndex ) continue; // next iteration if not a match
153 
154  int start = theBadStrips->chambers[i].pointer;
155  int nbad = theBadStrips->chambers[i].bad_channels;
156 
157  for ( int j=start-1; j<start-1+nbad; ++j ) { // bad channels in this chamber
158  short lay = theBadStrips->channels[j].layer; // value 1-6
159  if ( lay != inputLayer ) continue;
160 
161  short chan = theBadStrips->channels[j].channel; // value 1-80 (->112 for unganged ME1/1A)
162  // Flags so far unused (and unset in conditins data)
163  // short f1 = theBadStrips->channels[j].flag1;
164  // short f2 = theBadStrips->channels[j].flag2;
165  // short f3 = theBadStrips->channels[j].flag3;
166  badStripWord_.set( chan-1, 1 ); // set bit 0-79 (111) in 80 (112)-bit bitset representing this layer
167  } // j
168  } // i
169 
170 }
171 
173 
174  // Input CSCDetId is expected to be a 'raw' value
175 
176  // Find linear index of chamber for input CSCDetId
177  int inputIndex = indexer_->chamberIndex( id );
178  short inputLayer = id.layer();
179 
180  // unpack what we've read from theBadWires
181 
182  for ( size_t i=0; i<theBadWires->chambers.size(); ++i ) { // loop over bad chambers
183  int indexc = theBadWires->chambers[i].chamber_index;
184 
185  if (indexc != inputIndex ) continue; // next iteration if not a match
186 
187  int start = theBadWires->chambers[i].pointer;
188  int nbad = theBadWires->chambers[i].bad_channels;
189 
190  for ( int j=start-1; j<start-1+nbad; ++j ) { // bad channels in this chamber
191  short lay = theBadWires->channels[j].layer; // value 1-6
192  if ( lay != inputLayer ) continue;
193 
194  short chan = theBadWires->channels[j].channel; // value 1-112
195  // short f1 = theBadWires->channels[j].flag1;
196  // short f2 = theBadWires->channels[j].flag2;
197  // short f3 = theBadWires->channels[j].flag3;
198  badWireWord_.set( chan-1, 1 ); // set bit 0-111 in 112-bit bitset representing this layer
199  } // j
200  } // i
201 
202 }
203 
204 bool CSCConditions::isInBadChamber( const CSCDetId& id ) const {
205  //@@ We do not consider the possibility of having ME1/1A & ME1/1B independently 'bad'.
206  //@@ To do that we would need to define separate chamber indexes for ME1/1A & ME1/1B.
207 
208  if ( readBadChambers() ) {
209  CSCDetId idraw = mapper_->rawCSCDetId( id );
210  int index = indexer_->chamberIndex( idraw );
211  return theBadChambers->isInBadChamber( index );
212  }
213  else return false;
214 }
215 
216 float CSCConditions::gain(const CSCDetId & id, int geomChannel) const
217 {
218  assert(theGains.isValid());
219  CSCDetId idraw = mapper_->rawCSCDetId( id );
220  int iraw = mapper_->rawStripChannel( id, geomChannel );
221  int index = indexer_->stripChannelIndex( idraw, iraw ) - 1; // NOTE THE MINUS ONE!
222  return float( theGains->gain(index) ) /theGains->scale();
223 }
224 
225 float CSCConditions::pedestal(const CSCDetId & id, int geomChannel) const
226 {
227  assert(thePedestals.isValid());
228  CSCDetId idraw = mapper_->rawCSCDetId( id );
229  int iraw = mapper_->rawStripChannel( id, geomChannel );
230  int index = indexer_->stripChannelIndex( idraw, iraw ) - 1; // NOTE THE MINUS ONE!
231  return float( thePedestals->pedestal(index) )/thePedestals->scale_ped();
232 }
233 
234 
235 float CSCConditions::pedestalSigma(const CSCDetId& id, int geomChannel) const
236 {
237  assert(thePedestals.isValid());
238  CSCDetId idraw = mapper_->rawCSCDetId( id );
239  int iraw = mapper_->rawStripChannel( id, geomChannel );
240  int index = indexer_->stripChannelIndex( idraw, iraw ) - 1; // NOTE THE MINUS ONE!
241  return float( thePedestals->pedestal_rms(index) )/thePedestals->scale_rms();
242 }
243 
244 
245 float CSCConditions::crosstalkIntercept(const CSCDetId& id, int geomChannel, bool leftRight) const
246 {
247  assert(theCrosstalk.isValid());
248  CSCDetId idraw = mapper_->rawCSCDetId( id );
249  int iraw = mapper_->rawStripChannel( id, geomChannel );
250  int index = indexer_->stripChannelIndex( idraw, iraw ) - 1; // NOTE THE MINUS ONE!
251  // resistive fraction is at the peak, where t=0
252  return leftRight ? float ( theCrosstalk->rinter(index) )/theCrosstalk->iscale()
253  : float ( theCrosstalk->linter(index) )/theCrosstalk->iscale() ;
254 }
255 
256 
257 float CSCConditions::crosstalkSlope(const CSCDetId& id, int geomChannel, bool leftRight) const
258 {
259  assert(theCrosstalk.isValid());
260  CSCDetId idraw = mapper_->rawCSCDetId( id );
261  int iraw = mapper_->rawStripChannel( id, geomChannel );
262  int index = indexer_->stripChannelIndex( idraw, iraw ) - 1; // NOTE THE MINUS ONE!
263  // resistive fraction is at the peak, where t=0
264  return leftRight ? float ( theCrosstalk->rslope(index) )/theCrosstalk->sscale()
265  : float ( theCrosstalk->lslope(index) )/theCrosstalk->sscale() ;
266 }
267 
268 const CSCDBNoiseMatrix::Item & CSCConditions::noiseMatrix(const CSCDetId& id, int geomChannel) const
269 {
270  //@@ BEWARE - THIS FUNCTION DOES NOT APPLY SCALE FACTOR USED IN PACKING VALUES IN CONDITIONS DATA
271  //@@ MAY BE AN ERROR? WHO WOULD WANT ACCESS WITHOUT IT?
272 
273  assert(theNoiseMatrix.isValid());
274  CSCDetId idraw = mapper_->rawCSCDetId( id );
275  int iraw = mapper_->rawStripChannel( id, geomChannel );
276  int index = indexer_->stripChannelIndex( idraw, iraw ) - 1; // NOTE THE MINUS ONE!
277  return theNoiseMatrix->item(index);
278 }
279 
280 void CSCConditions::noiseMatrixElements( const CSCDetId& id, int geomChannel, std::vector<float>& me ) const {
281  assert(me.size() > 11 );
282  const CSCDBNoiseMatrix::Item& item = noiseMatrix(id, geomChannel); // i.e. the function above
283  me[0] = float ( item.elem33 )/theNoiseMatrix->scale();
284  me[1] = float ( item.elem34 )/theNoiseMatrix->scale();
285  me[2] = float ( item.elem35 )/theNoiseMatrix->scale();
286  me[3] = float ( item.elem44 )/theNoiseMatrix->scale();
287  me[4] = float ( item.elem45 )/theNoiseMatrix->scale();
288  me[5] = float ( item.elem46 )/theNoiseMatrix->scale();
289  me[6] = float ( item.elem55 )/theNoiseMatrix->scale();
290  me[7] = float ( item.elem56 )/theNoiseMatrix->scale();
291  me[8] = float ( item.elem57 )/theNoiseMatrix->scale();
292  me[9] = float ( item.elem66 )/theNoiseMatrix->scale();
293  me[10] = float ( item.elem67 )/theNoiseMatrix->scale();
294  me[11] = float ( item.elem77 )/theNoiseMatrix->scale();
295 }
296 
297 void CSCConditions::crossTalk( const CSCDetId& id, int geomChannel, std::vector<float>& ct ) const {
298  assert(theCrosstalk.isValid());
299  CSCDetId idraw = mapper_->rawCSCDetId( id );
300  int iraw = mapper_->rawStripChannel( id, geomChannel );
301  int index = indexer_->stripChannelIndex( idraw, iraw ) - 1; // NOTE THE MINUS ONE!
302 
303  ct[0] = float ( theCrosstalk->lslope(index) )/theCrosstalk->sscale();
304  ct[1] = float ( theCrosstalk->linter(index) )/theCrosstalk->iscale();
305  ct[2] = float ( theCrosstalk->rslope(index) )/theCrosstalk->sscale();
306  ct[3] = float ( theCrosstalk->rinter(index) )/theCrosstalk->iscale();
307 }
308 
309 float CSCConditions::chipCorrection(const CSCDetId & id, int geomChannel) const
310 {
311  if ( useTimingCorrections() ){
312  assert(theChipCorrections.isValid());
313  CSCDetId idraw = mapper_->rawCSCDetId( id );
314  int iraw = mapper_->rawStripChannel( id, geomChannel);
315  int ichip = indexer_->chipIndex(iraw); // converts 1-80 to 1-5 (chip#, CFEB#)
316  int index = indexer_->chipIndex(idraw, ichip) - 1; // NOTE THE MINUS ONE!
317  return float ( theChipCorrections->value(index) )/theChipCorrections->scale();
318  }
319  else
320  return 0;
321 }
323 {
324  if ( useTimingCorrections() ){
326  CSCDetId idraw = mapper_->rawCSCDetId( id );
327  int index = indexer_->chamberIndex(idraw) - 1; // NOTE THE MINUS ONE!
328  return float (
329  theChamberTimingCorrections->item(index).cfeb_tmb_skew_delay*1./theChamberTimingCorrections->precision()
330  + theChamberTimingCorrections->item(index).cfeb_timing_corr*1./theChamberTimingCorrections->precision()
331  + (theChamberTimingCorrections->item(index).cfeb_cable_delay*25. )
332 );
333  }
334  else
335  return 0;
336 }
337 float CSCConditions::anodeBXoffset(const CSCDetId & id) const
338 {
339  if ( useTimingCorrections() ){
341  CSCDetId idraw = mapper_->rawCSCDetId( id );
342  int index = indexer_->chamberIndex(idraw) - 1; // NOTE THE MINUS ONE!
343  return float ( theChamberTimingCorrections->item(index).anode_bx_offset*1./theChamberTimingCorrections->precision() );
344  }
345  else
346  return 0;
347 }
348 
354 
355  const float loEdge = 5.0; // consider gains above this
356  const float hiEdge = 10.0; // consider gains below this
357  const float loLimit = 6.0; // lowest acceptable average gain
358  const float hiLimit = 9.0; // highest acceptable average gain
359  const float expectedAverage = 7.5; // default average gain
360 
361  if ( theAverageGain > 0. ) return theAverageGain; // only recalculate if necessary
362 
363  int n_strip = 0;
364  float gain_tot = 0.;
365 
366  CSCDBGains::GainContainer::const_iterator it;
367  for ( it=theGains->gains.begin(); it!=theGains->gains.end(); ++it ) {
368  float the_gain = float( it->gain_slope )/theGains->scale();
369  if (the_gain > loEdge && the_gain < hiEdge ) {
370  gain_tot += the_gain;
371  ++n_strip;
372  }
373  }
374 
375  // Average gain
376  if ( n_strip > 0 ) {
377  theAverageGain = gain_tot / n_strip;
378  }
379 
380  // Average gain has been around 7.5 in real data
381  if ( theAverageGain < loLimit || theAverageGain > hiLimit ) {
382  // LogTrace("CSC") << "Average CSC strip gain = "
383  // << theAverageGain << " is reset to expected value " << expectedAverage;
384  theAverageGain = expectedAverage;
385  }
386 
387  return theAverageGain;
388 }
389 //
390 float CSCConditions::gasGainCorrection( const CSCDetId & id, int geomChannel, int iwiregroup ) const
391 {
392  if ( useGasGainCorrections() ){
393  assert(theGasGainCorrections.isValid());
394  CSCDetId idraw = mapper_->rawCSCDetId( id );
395  int iraw = mapper_->rawStripChannel( id, geomChannel );
396  int index = indexer_->gasGainIndex(idraw, iraw, iwiregroup) - 1; // NOTE THE MINUS ONE!
397  return float ( theGasGainCorrections->value(index) );
398  } else {
399  return 1.;
400  }
401 }
402 
403 int CSCConditions::channelFromStrip( const CSCDetId& id, int geomStrip) const
404 { return mapper_->channelFromStrip(id, geomStrip); }
405 
406 int CSCConditions::rawStripChannel( const CSCDetId& id, int geomChannel) const
407 { return mapper_->rawStripChannel( id, geomChannel); }
408 
409 
411  //@@ HAS NOT BEEN UPDATED THROUGH SEVERAL VERSIONS OF THE CONDITIONS DATA
412 {
413 /*
414  std::cout << "SIZES: GAINS: " << theGains->gains.size()
415  << " PEDESTALS: " << thePedestals->pedestals.size()
416  << " NOISES " << theNoiseMatrix->matrix.size() << std::endl;;
417 
418  std::map< int,std::vector<CSCDBGains::Item> >::const_iterator layerGainsItr = theGains->gains.begin(),
419  lastGain = theGains->gains.end();
420  for( ; layerGainsItr != lastGain; ++layerGainsItr)
421  {
422  std::cout << "GAIN " << layerGainsItr->first
423  << " STRIPS " << layerGainsItr->second.size() << " "
424  << layerGainsItr->second[0].gain_slope
425  << " " << layerGainsItr->second[0].gain_intercept << std::endl;
426  }
427 
428  std::map< int,std::vector<CSCDBPedestals::Item> >::const_iterator pedestalItr = thePedestals->pedestals.begin(),
429  lastPedestal = thePedestals->pedestals.end();
430  for( ; pedestalItr != lastPedestal; ++pedestalItr)
431  {
432  std::cout << "PEDS " << pedestalItr->first << " "
433  << " STRIPS " << pedestalItr->second.size() << " ";
434  for(int i = 1; i < 80; ++i)
435  {
436  std::cout << pedestalItr->second[i-1].rms << " " ;
437  }
438  std::cout << std::endl;
439  }
440 
441  std::map< int,std::vector<CSCDBCrosstalk::Item> >::const_iterator crosstalkItr = theCrosstalk->crosstalk.begin(),
442  lastCrosstalk = theCrosstalk->crosstalk.end();
443  for( ; crosstalkItr != lastCrosstalk; ++crosstalkItr)
444  {
445  std::cout << "XTALKS " << crosstalkItr->first
446  << " STRIPS " << crosstalkItr->second.size() << " "
447  << crosstalkItr->second[5].xtalk_slope_left << " "
448  << crosstalkItr->second[5].xtalk_slope_right << " "
449  << crosstalkItr->second[5].xtalk_intercept_left << " "
450  << crosstalkItr->second[5].xtalk_intercept_right << std::endl;
451  }
452 */
453 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
edm::ESHandle< CSCDBGasGainCorrection > theGasGainCorrections
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
edm::ESHandle< CSCDBNoiseMatrix > theNoiseMatrix
edm::ESHandle< CSCBadWires > theBadWires
float pedestalSigma(const CSCDetId &detId, int channel) const
static ped rms in ADC counts
void noiseMatrixElements(const CSCDetId &id, int channel, std::vector< float > &me) const
fill vector (dim 12, must be allocated by caller) with noise matrix elements (scaled to float) ...
void fillBadChannelWords(const CSCDetId &id)
Fill bad channel words - one for strips, one for wires, for an offline CSCDetId.
edm::ESHandle< CSCChamberTimeCorrections > theChamberTimingCorrections
bool useTimingCorrections() const
did we request reading timing correction info from db?
const CSCDBNoiseMatrix::Item & noiseMatrix(const CSCDetId &detId, int channel) const
raw noise matrix (unscaled short int elements)
void print() const
edm::ESHandle< CSCBadStrips > theBadStrips
float chipCorrection(const CSCDetId &detId, int channel) const
chip speed correction in ns given detId (w/layer) and strip channel
float chamberTimingCorrection(const CSCDetId &detId) const
chamber timing correction in ns given detId of chamber
edm::ESHandle< CSCIndexerBase > indexer_
void crossTalk(const CSCDetId &id, int channel, std::vector< float > &ct) const
fill vector (dim 4, must be allocated by caller) with crosstalk sl, il, sr, ir
edm::ESWatcher< CSCDBGainsRcd > gainsWatcher_
float anodeBXoffset(const CSCDetId &detId) const
anode bx offset in bx given detId of chamber
void fillBadWireWord(const CSCDetId &id)
bool useTimingCorrections_
std::bitset< 112 > badWireWord_
float pedestal(const CSCDetId &detId, int channel) const
static ped in ADC counts
edm::ESHandle< CSCChannelMapperBase > mapper_
bool readBadChannels() const
did we request reading bad channel info from db?
bool useGasGainCorrections_
int rawStripChannel(const CSCDetId &id, int geomChannel) const
edm::ESHandle< CSCBadChambers > theBadChambers
int j
Definition: DBlmapReader.cc:9
int channelFromStrip(const CSCDetId &id, int geomStrip) const
feedthrough for external access
edm::ESHandle< CSCDBGains > theGains
void initializeEvent(const edm::EventSetup &es)
fetch database content via EventSetup
void fillBadStripWord(const CSCDetId &id)
fill bad channel words for offline id
float crosstalkSlope(const CSCDetId &detId, int channel, bool leftRight) const
crosstalk slope for left and right
float crosstalkIntercept(const CSCDetId &detId, int channel, bool leftRight) const
crosstalk intercept for left and right
bool isInBadChamber(const CSCDetId &id) const
Is the gven chamber flagged as bad?
float gain(const CSCDetId &detId, int channel) const
gain per channel
CSCConditions(const edm::ParameterSet &ps)
edm::ESHandle< CSCDBChipSpeedCorrection > theChipCorrections
edm::ESHandle< CSCDBCrosstalk > theCrosstalk
bool readBadChambers() const
did we request reading bad chamber info from db?
const T & get() const
Definition: EventSetup.h:55
string const
Definition: compareJSON.py:14
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
void setIdOfBadChannelWords(const CSCDetId &id)
Set id for current content of bad channel words - this is offline id i.e. separate for ME11A &amp; ME11B...
const CSCDetId & idOfBadChannelWords() const
the offline CSCDetId of current bad channel words
Definition: CSCConditions.h:99
float gasGainCorrection(const CSCDetId &detId, int strip, int wire) const
gas gain correction as a function of detId (w/layer), strip, and wire channels
float averageGain() const
average gain over entire CSC system (logically const although must be cached here).
bool useGasGainCorrections() const
did we request reading gas gain correction info from db?
volatile std::atomic< bool > shutdown_flag false
float theAverageGain
bool isValid() const
Definition: ESHandle.h:47
edm::ESHandle< CSCDBPedestals > thePedestals
std::bitset< 112 > badStripWord_