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.
2 
5 
8 
15 
22 
29 
31 
35 
37 : theGains(), theCrosstalk(), thePedestals(), theNoiseMatrix(),
38  theBadStrips(), theBadWires(), theBadChambers(),
39  theChipCorrections(), theChamberTimingCorrections(), theGasGainCorrections(),
40  indexer_(0), mapper_(0),
41  readBadChannels_(false), readBadChambers_(false),
42  useTimingCorrections_(false), useGasGainCorrections_(false), theAverageGain( -1.0 )
43 {
44  readBadChannels_ = ps.getParameter<bool>("readBadChannels");
45  readBadChambers_ = ps.getParameter<bool>("readBadChambers");
46  useTimingCorrections_ = ps.getParameter<bool>("CSCUseTimingCorrections");
47  useGasGainCorrections_ = ps.getParameter<bool>("CSCUseGasGainCorrections");
48 
49  // set size to hold all layers, using enum defined in .h
50  badStripWords.resize( MAX_LAYERS, 0 );
51  badWireWords.resize( MAX_LAYERS, 0 );
52 }
53 
54 
56 
58 {
59  // Algorithms
60  es.get<CSCIndexerRecord>().get( indexer_ );
61  es.get<CSCChannelMapperRecord>().get( mapper_ );
62 
63  // Strip gains
64  es.get<CSCDBGainsRcd>().get( theGains );
65  // Strip X-talk
66  es.get<CSCDBCrosstalkRcd>().get( theCrosstalk );
67  // Strip pedestals
68  es.get<CSCDBPedestalsRcd>().get( thePedestals );
69  // Strip autocorrelation noise matrix
71 
72  if ( useTimingCorrections()){
73  // Buckeye chip speeds
75  // Cable lengths from chambers to peripheral crate and additional chamber level timing correction
77  }
78 
79  if ( readBadChannels() ) {
80  // Bad strip channels
81  es.get<CSCBadStripsRcd>().get( theBadStrips );
82  // Bad wiregroup channels
83  es.get<CSCBadWiresRcd>().get( theBadWires );
84 
85  //@@ if( badStripsWatcher_.check( es ) ) {
87  //@@ }
88  //@@ if( badWiresWatcher_.check( es ) ) {
90  //@ }
91 
92  }
93 
94  // Has GainsRcd changed?
95  if( gainsWatcher_.check( es ) ) { // Yes...
96  theAverageGain = -1.0; // ...reset, so next access will recalculate it
97  }
98 
99  if ( readBadChambers() ) {
100  // Entire bad chambers
101  es.get<CSCBadChambersRcd>().get( theBadChambers );
102  }
103 
104  if ( useGasGainCorrections()){
106  }
107 
108 // print();
109 }
110 
112  //@@ NOT YET THOUGHT THROUGH FOR UNGANGED ME11A
113 
114  // reset existing values
115  badStripWords.assign( MAX_LAYERS, 0 );
116  if ( readBadChannels() ) {
117  // unpack what we've read from theBadStrips
118 
119  // chambers is a vector<BadChamber>
120  // channels is a vector<BadChannel>
121  // Each BadChamber contains its index (1-468 or 540 w. ME42), the no. of bad channels,
122  // and the index within vector<BadChannel> where this chamber's bad channels start.
123 
124  for ( size_t i=0; i<theBadStrips->chambers.size(); ++i ) { // loop over bad chambers
125  int indexc = theBadStrips->chambers[i].chamber_index;
126  int start = theBadStrips->chambers[i].pointer; // where this chamber's bad channels start in vector<BadChannel>
127  int nbad = theBadStrips->chambers[i].bad_channels;
128 
129  CSCDetId id = indexer_->detIdFromChamberIndex( indexc ); // We need this to build layer index (1-2808)
130 
131  for ( int j=start-1; j<start-1+nbad; ++j ) { // bad channels in this chamber
132  short lay = theBadStrips->channels[j].layer; // value 1-6
133  short chan = theBadStrips->channels[j].channel; // value 1-80
134  // short f1 = theBadStrips->channels[j].flag1;
135  // short f2 = theBadStrips->channels[j].flag2;
136  // short f3 = theBadStrips->channels[j].flag3;
137  int indexl = indexer_->layerIndex( id.endcap(), id.station(), id.ring(), id.chamber(), lay );
138  badStripWords[indexl-1].set( chan-1, 1 ); // set bit 0-79 in 80-bit bitset representing this layer
139  } // j
140  } // i
141 
142  }
143 }
144 
146  // reset existing values
147  badWireWords.assign( MAX_LAYERS, 0 );
148  if ( readBadChannels() ) {
149  // unpack what we've read from theBadWires
150 
151  for ( size_t i=0; i<theBadWires->chambers.size(); ++i ) { // loop over bad chambers
152  int indexc = theBadWires->chambers[i].chamber_index;
153  int start = theBadWires->chambers[i].pointer; // where this chamber's bad channels start in vector<BadChannel>
154  int nbad = theBadWires->chambers[i].bad_channels;
155 
156  CSCDetId id = indexer_->detIdFromChamberIndex( indexc ); // We need this to build layer index (1-2808)
157 
158  for ( int j=start-1; j<start-1+nbad; ++j ) { // bad channels in this chamber
159  short lay = theBadWires->channels[j].layer; // value 1-6
160  short chan = theBadWires->channels[j].channel; // value 1-80
161  // short f1 = theBadWires->channels[j].flag1;
162  // short f2 = theBadWires->channels[j].flag2;
163  // short f3 = theBadWires->channels[j].flag3;
164  int indexl = indexer_->layerIndex( id.endcap(), id.station(), id.ring(), id.chamber(), lay );
165  badWireWords[indexl-1].set( chan-1, 1 ); // set bit 0-111 in 112-bit bitset representing this layer
166  } // j
167  } // i
168 
169  }
170 }
171 
172 bool CSCConditions::isInBadChamber( const CSCDetId& id ) const {
173  //@@ NOT YET THOUGHT THROUGH FOR UNGANGED ME11A
174 
175  if ( readBadChambers() ) {
176  CSCDetId idraw = mapper_->rawCSCDetId( id );
177  int index = indexer_->chamberIndex( idraw );
178  return theBadChambers->isInBadChamber( index );
179  }
180  else return false;
181 }
182 
183 float CSCConditions::gain(const CSCDetId & id, int geomChannel) const
184 {
185  assert(theGains.isValid());
186  CSCDetId idraw = mapper_->rawCSCDetId( id );
187  int iraw = mapper_->rawStripChannel( id, geomChannel );
188  int index = indexer_->stripChannelIndex( idraw, iraw ) - 1; // NOTE THE MINUS ONE!
189  return float( theGains->gain(index) ) /theGains->scale();
190 }
191 
192 float CSCConditions::pedestal(const CSCDetId & id, int geomChannel) const
193 {
194  assert(thePedestals.isValid());
195  CSCDetId idraw = mapper_->rawCSCDetId( id );
196  int iraw = mapper_->rawStripChannel( id, geomChannel );
197  int index = indexer_->stripChannelIndex( idraw, iraw ) - 1; // NOTE THE MINUS ONE!
198  return float( thePedestals->pedestal(index) )/thePedestals->scale_ped();
199 }
200 
201 
202 float CSCConditions::pedestalSigma(const CSCDetId& id, int geomChannel) const
203 {
204  assert(thePedestals.isValid());
205  CSCDetId idraw = mapper_->rawCSCDetId( id );
206  int iraw = mapper_->rawStripChannel( id, geomChannel );
207  int index = indexer_->stripChannelIndex( idraw, iraw ) - 1; // NOTE THE MINUS ONE!
208  return float( thePedestals->pedestal_rms(index) )/thePedestals->scale_rms();
209 }
210 
211 
212 float CSCConditions::crosstalkIntercept(const CSCDetId& id, int geomChannel, bool leftRight) const
213 {
214  assert(theCrosstalk.isValid());
215  CSCDetId idraw = mapper_->rawCSCDetId( id );
216  int iraw = mapper_->rawStripChannel( id, geomChannel );
217  int index = indexer_->stripChannelIndex( idraw, iraw ) - 1; // NOTE THE MINUS ONE!
218  // resistive fraction is at the peak, where t=0
219  return leftRight ? float ( theCrosstalk->rinter(index) )/theCrosstalk->iscale()
220  : float ( theCrosstalk->linter(index) )/theCrosstalk->iscale() ;
221 }
222 
223 
224 float CSCConditions::crosstalkSlope(const CSCDetId& id, int geomChannel, bool leftRight) const
225 {
226  assert(theCrosstalk.isValid());
227  CSCDetId idraw = mapper_->rawCSCDetId( id );
228  int iraw = mapper_->rawStripChannel( id, geomChannel );
229  int index = indexer_->stripChannelIndex( idraw, iraw ) - 1; // NOTE THE MINUS ONE!
230  // resistive fraction is at the peak, where t=0
231  return leftRight ? float ( theCrosstalk->rslope(index) )/theCrosstalk->sscale()
232  : float ( theCrosstalk->lslope(index) )/theCrosstalk->sscale() ;
233 }
234 
235 const CSCDBNoiseMatrix::Item & CSCConditions::noiseMatrix(const CSCDetId& id, int geomChannel) const
236 {
237  //@@ BEWARE - THIS FUNCTION DOES NOT APPLy SCALE FACTOR USED IN PACKING VALUES IN CONDITIONS DATA
238  //@@ MAY BE AN ERROR? WHO WOULD WANT ACCESS WITHOUT IT?
239 
240  assert(theNoiseMatrix.isValid());
241  CSCDetId idraw = mapper_->rawCSCDetId( id );
242  int iraw = mapper_->rawStripChannel( id, geomChannel );
243  int index = indexer_->stripChannelIndex( idraw, iraw ) - 1; // NOTE THE MINUS ONE!
244  return theNoiseMatrix->item(index);
245 }
246 
247 void CSCConditions::noiseMatrixElements( const CSCDetId& id, int geomChannel, std::vector<float>& me ) const {
248  assert(me.size() > 11 );
249  const CSCDBNoiseMatrix::Item& item = noiseMatrix(id, geomChannel); // i.e. the function above
250  me[0] = float ( item.elem33 )/theNoiseMatrix->scale();
251  me[1] = float ( item.elem34 )/theNoiseMatrix->scale();
252  me[2] = float ( item.elem35 )/theNoiseMatrix->scale();
253  me[3] = float ( item.elem44 )/theNoiseMatrix->scale();
254  me[4] = float ( item.elem45 )/theNoiseMatrix->scale();
255  me[5] = float ( item.elem46 )/theNoiseMatrix->scale();
256  me[6] = float ( item.elem55 )/theNoiseMatrix->scale();
257  me[7] = float ( item.elem56 )/theNoiseMatrix->scale();
258  me[8] = float ( item.elem57 )/theNoiseMatrix->scale();
259  me[9] = float ( item.elem66 )/theNoiseMatrix->scale();
260  me[10] = float ( item.elem67 )/theNoiseMatrix->scale();
261  me[11] = float ( item.elem77 )/theNoiseMatrix->scale();
262 }
263 
264 void CSCConditions::crossTalk( const CSCDetId& id, int geomChannel, std::vector<float>& ct ) const {
265  assert(theCrosstalk.isValid());
266  CSCDetId idraw = mapper_->rawCSCDetId( id );
267  int iraw = mapper_->rawStripChannel( id, geomChannel );
268  int index = indexer_->stripChannelIndex( idraw, iraw ) - 1; // NOTE THE MINUS ONE!
269 
270  ct[0] = float ( theCrosstalk->lslope(index) )/theCrosstalk->sscale();
271  ct[1] = float ( theCrosstalk->linter(index) )/theCrosstalk->iscale();
272  ct[2] = float ( theCrosstalk->rslope(index) )/theCrosstalk->sscale();
273  ct[3] = float ( theCrosstalk->rinter(index) )/theCrosstalk->iscale();
274 }
275 
276 float CSCConditions::chipCorrection(const CSCDetId & id, int geomChannel) const
277 {
278  if ( useTimingCorrections() ){
279  assert(theChipCorrections.isValid());
280  CSCDetId idraw = mapper_->rawCSCDetId( id );
281  int iraw = mapper_->rawStripChannel( id, geomChannel);
282  int ichip = indexer_->chipIndex(iraw); // converts 1-80 to 1-5 (chip#, CFEB#)
283  int index = indexer_->chipIndex(idraw, ichip) - 1; // NOTE THE MINUS ONE!
284  return float ( theChipCorrections->value(index) )/theChipCorrections->scale();
285  }
286  else
287  return 0;
288 }
290 {
291  if ( useTimingCorrections() ){
293  CSCDetId idraw = mapper_->rawCSCDetId( id );
294  int index = indexer_->chamberIndex(idraw) - 1; // NOTE THE MINUS ONE!
295  return float (
296  theChamberTimingCorrections->item(index).cfeb_tmb_skew_delay*1./theChamberTimingCorrections->precision()
297  + theChamberTimingCorrections->item(index).cfeb_timing_corr*1./theChamberTimingCorrections->precision()
298  + (theChamberTimingCorrections->item(index).cfeb_cable_delay*25. )
299 );
300  }
301  else
302  return 0;
303 }
304 float CSCConditions::anodeBXoffset(const CSCDetId & id) const
305 {
306  if ( useTimingCorrections() ){
308  CSCDetId idraw = mapper_->rawCSCDetId( id );
309  int index = indexer_->chamberIndex(idraw) - 1; // NOTE THE MINUS ONE!
310  return float ( theChamberTimingCorrections->item(index).anode_bx_offset*1./theChamberTimingCorrections->precision() );
311  }
312  else
313  return 0;
314 }
315 
316 const std::bitset<80>& CSCConditions::badStripWord( const CSCDetId& id ) const {
317  //@@ NOT YET THOUGHT THROUGH FOR UNGANGED ME11A
318 
319  CSCDetId idraw = mapper_->rawCSCDetId( id );
320  return badStripWords[indexer_->layerIndex(idraw) - 1];
321 }
322 
323 const std::bitset<112>& CSCConditions::badWireWord( const CSCDetId& id ) const {
324  //@@ NEED TO THINK ABOUT THIS SINCE ME11A & ME11B SHARE A COMMON WIRE PLANE
325  //@@ SHOULD WE JUST USE ME11B?
326 
327  CSCDetId idraw = mapper_->rawCSCDetId( id );
328  return badWireWords[indexer_->layerIndex(idraw) - 1];
329 }
330 
336 
337  const float loEdge = 5.0; // consider gains above this
338  const float hiEdge = 10.0; // consider gains below this
339  const float loLimit = 6.0; // lowest acceptable average gain
340  const float hiLimit = 9.0; // highest acceptable average gain
341  const float expectedAverage = 7.5; // default average gain
342 
343  if ( theAverageGain > 0. ) return theAverageGain; // only recalculate if necessary
344 
345  int n_strip = 0;
346  float gain_tot = 0.;
347 
348  CSCDBGains::GainContainer::const_iterator it;
349  for ( it=theGains->gains.begin(); it!=theGains->gains.end(); ++it ) {
350  float the_gain = float( it->gain_slope )/theGains->scale();
351  if (the_gain > loEdge && the_gain < hiEdge ) {
352  gain_tot += the_gain;
353  ++n_strip;
354  }
355  }
356 
357  // Average gain
358  if ( n_strip > 0 ) {
359  theAverageGain = gain_tot / n_strip;
360  }
361 
362  // Average gain has been around 7.5 in real data
363  if ( theAverageGain < loLimit || theAverageGain > hiLimit ) {
364  // LogTrace("CSC") << "Average CSC strip gain = "
365  // << theAverageGain << " is reset to expected value " << expectedAverage;
366  theAverageGain = expectedAverage;
367  }
368 
369  return theAverageGain;
370 }
371 //
372 float CSCConditions::gasGainCorrection( const CSCDetId & id, int geomChannel, int iwiregroup ) const
373 {
374  if ( useGasGainCorrections() ){
375  assert(theGasGainCorrections.isValid());
376  CSCDetId idraw = mapper_->rawCSCDetId( id );
377  int iraw = mapper_->rawStripChannel( id, geomChannel );
378  int index = indexer_->gasGainIndex(idraw, iraw, iwiregroup) - 1; // NOTE THE MINUS ONE!
379  return float ( theGasGainCorrections->value(index) );
380  } else {
381  return 1.;
382  }
383 }
384 
385 int CSCConditions::channelFromStrip( const CSCDetId& id, int geomStrip) const
386 { return mapper_->channelFromStrip(id, geomStrip); }
387 
388 int CSCConditions::rawStripChannel( const CSCDetId& id, int geomChannel) const
389 { return mapper_->rawStripChannel( id, geomChannel); }
390 
391 
393  //@@ HAS NOT BEEN UPDATED THROUGH SEVERAL VERSIONS OF THE CONDITIONS DATA
394 {
395 /*
396  std::cout << "SIZES: GAINS: " << theGains->gains.size()
397  << " PEDESTALS: " << thePedestals->pedestals.size()
398  << " NOISES " << theNoiseMatrix->matrix.size() << std::endl;;
399 
400  std::map< int,std::vector<CSCDBGains::Item> >::const_iterator layerGainsItr = theGains->gains.begin(),
401  lastGain = theGains->gains.end();
402  for( ; layerGainsItr != lastGain; ++layerGainsItr)
403  {
404  std::cout << "GAIN " << layerGainsItr->first
405  << " STRIPS " << layerGainsItr->second.size() << " "
406  << layerGainsItr->second[0].gain_slope
407  << " " << layerGainsItr->second[0].gain_intercept << std::endl;
408  }
409 
410  std::map< int,std::vector<CSCDBPedestals::Item> >::const_iterator pedestalItr = thePedestals->pedestals.begin(),
411  lastPedestal = thePedestals->pedestals.end();
412  for( ; pedestalItr != lastPedestal; ++pedestalItr)
413  {
414  std::cout << "PEDS " << pedestalItr->first << " "
415  << " STRIPS " << pedestalItr->second.size() << " ";
416  for(int i = 1; i < 80; ++i)
417  {
418  std::cout << pedestalItr->second[i-1].rms << " " ;
419  }
420  std::cout << std::endl;
421  }
422 
423  std::map< int,std::vector<CSCDBCrosstalk::Item> >::const_iterator crosstalkItr = theCrosstalk->crosstalk.begin(),
424  lastCrosstalk = theCrosstalk->crosstalk.end();
425  for( ; crosstalkItr != lastCrosstalk; ++crosstalkItr)
426  {
427  std::cout << "XTALKS " << crosstalkItr->first
428  << " STRIPS " << crosstalkItr->second.size() << " "
429  << crosstalkItr->second[5].xtalk_slope_left << " "
430  << crosstalkItr->second[5].xtalk_slope_right << " "
431  << crosstalkItr->second[5].xtalk_intercept_left << " "
432  << crosstalkItr->second[5].xtalk_intercept_right << std::endl;
433  }
434 */
435 }
T getParameter(std::string const &) const
const std::bitset< 80 > & badStripWord(const CSCDetId &id) const
bad channel words per CSCLayer - 1 bit per channel
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 fillBadStripWords()
fill bad channel words
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
std::vector< std::bitset< 112 > > badWireWords
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_
std::vector< std::bitset< 80 > > badStripWords
float anodeBXoffset(const CSCDetId &detId) const
anode bx offset in bx given detId of chamber
bool useTimingCorrections_
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?
Definition: CSCConditions.h:98
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
const std::bitset< 112 > & badWireWord(const CSCDetId &id) const
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)
void fillBadWireWords()
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:59
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?
float theAverageGain
bool isValid() const
Definition: ESHandle.h:37
edm::ESHandle< CSCDBPedestals > thePedestals