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.
21 
23 : theGains(),
24  theCrosstalk(),
25  thePedestals(),
26  theNoiseMatrix(),
27  theBadStrips(),
28  theBadWires(),
29  theBadChambers(),
30  theChipCorrections(),
31  theChamberTimingCorrections(),
32  theGasGainCorrections(),
33  readBadChannels_(false), readBadChambers_(false),useTimingCorrections_(false),useGasGainCorrections_(false),
34  theAverageGain( -1.0 )
35 {
36  readBadChannels_ = ps.getParameter<bool>("readBadChannels");
37  readBadChambers_ = ps.getParameter<bool>("readBadChambers");
38  useTimingCorrections_ = ps.getParameter<bool>("CSCUseTimingCorrections");
39  useGasGainCorrections_ = ps.getParameter<bool>("CSCUseGasGainCorrections");
40  // set size to hold all layers, using enum defined in .h
41  badStripWords.resize( MAX_LAYERS, 0 );
42  badWireWords.resize( MAX_LAYERS, 0 );
43 }
44 
45 
47 {
48 }
49 
51 {
52  // Strip gains
53  es.get<CSCDBGainsRcd>().get( theGains );
54  // Strip X-talk
55  es.get<CSCDBCrosstalkRcd>().get( theCrosstalk );
56  // Strip pedestals
57  es.get<CSCDBPedestalsRcd>().get( thePedestals );
58  // Strip autocorrelation noise matrix
60 
61  if ( useTimingCorrections()){
62  // Buckeye chip speeds
64  // Cable lengths from chambers to peripheral crate and additional chamber level timing correction
66  }
67 
68  if ( readBadChannels() ) {
69  // Bad strip channels
70  es.get<CSCBadStripsRcd>().get( theBadStrips );
71  // Bad wiregroup channels
72  es.get<CSCBadWiresRcd>().get( theBadWires );
73 
74  //@@ if( badStripsWatcher_.check( es ) ) {
76  //@@ }
77  //@@ if( badWiresWatcher_.check( es ) ) {
79  //@ }
80 
81  }
82 
83  // Has GainsRcd changed?
84  if( gainsWatcher_.check( es ) ) { // Yes...
85  theAverageGain = -1.0; // ...reset, so next access will recalculate it
86  }
87 
88  if ( readBadChambers() ) {
89  // Entire bad chambers
91  }
92 
93  if ( useGasGainCorrections()){
95  }
96 
97 // print();
98 }
99 
101  // reset existing values
102  badStripWords.assign( MAX_LAYERS, 0 );
103  if ( readBadChannels() ) {
104  // unpack what we've read from theBadStrips
105 
106  // chambers is a vector<BadChamber>
107  // channels is a vector<BadChannel>
108  // Each BadChamber contains its index (1-468 or 540 w. ME42), the no. of bad channels,
109  // and the index within vector<BadChannel> where this chamber's bad channels start.
110 
111  CSCIndexer indexer;
112 
113  for ( size_t i=0; i<theBadStrips->chambers.size(); ++i ) { // loop over bad chambers
114  int indexc = theBadStrips->chambers[i].chamber_index;
115  int start = theBadStrips->chambers[i].pointer; // where this chamber's bad channels start in vector<BadChannel>
116  int nbad = theBadStrips->chambers[i].bad_channels;
117 
118  CSCDetId id = indexer.detIdFromChamberIndex( indexc ); // We need this to build layer index (1-2808)
119 
120  for ( int j=start-1; j<start-1+nbad; ++j ) { // bad channels in this chamber
121  short lay = theBadStrips->channels[j].layer; // value 1-6
122  short chan = theBadStrips->channels[j].channel; // value 1-80
123  // short f1 = theBadStrips->channels[j].flag1;
124  // short f2 = theBadStrips->channels[j].flag2;
125  // short f3 = theBadStrips->channels[j].flag3;
126  int indexl = indexer.layerIndex( id.endcap(), id.station(), id.ring(), id.chamber(), lay );
127  badStripWords[indexl-1].set( chan-1, 1 ); // set bit 0-79 in 80-bit bitset representing this layer
128  } // j
129  } // i
130 
131  }
132 }
133 
135  // reset existing values
136  badWireWords.assign( MAX_LAYERS, 0 );
137  if ( readBadChannels() ) {
138  // unpack what we've read from theBadWires
139  CSCIndexer indexer;
140 
141  for ( size_t i=0; i<theBadWires->chambers.size(); ++i ) { // loop over bad chambers
142  int indexc = theBadWires->chambers[i].chamber_index;
143  int start = theBadWires->chambers[i].pointer; // where this chamber's bad channels start in vector<BadChannel>
144  int nbad = theBadWires->chambers[i].bad_channels;
145 
146  CSCDetId id = indexer.detIdFromChamberIndex( indexc ); // We need this to build layer index (1-2808)
147 
148  for ( int j=start-1; j<start-1+nbad; ++j ) { // bad channels in this chamber
149  short lay = theBadWires->channels[j].layer; // value 1-6
150  short chan = theBadWires->channels[j].channel; // value 1-80
151  // short f1 = theBadWires->channels[j].flag1;
152  // short f2 = theBadWires->channels[j].flag2;
153  // short f3 = theBadWires->channels[j].flag3;
154  int indexl = indexer.layerIndex( id.endcap(), id.station(), id.ring(), id.chamber(), lay );
155  badWireWords[indexl-1].set( chan-1, 1 ); // set bit 0-111 in 112-bit bitset representing this layer
156  } // j
157  } // i
158 
159  }
160 }
161 
162 bool CSCConditions::isInBadChamber( const CSCDetId& id ) const {
163  if ( readBadChambers() ) return theBadChambers->isInBadChamber( id );
164  else return false;
165 }
166 
168  //@@ NEEDS THOROUGH UPDATING
169 {
170 /*
171  std::cout << "SIZES: GAINS: " << theGains->gains.size()
172  << " PEDESTALS: " << thePedestals->pedestals.size()
173  << " NOISES " << theNoiseMatrix->matrix.size() << std::endl;;
174 
175  std::map< int,std::vector<CSCDBGains::Item> >::const_iterator layerGainsItr = theGains->gains.begin(),
176  lastGain = theGains->gains.end();
177  for( ; layerGainsItr != lastGain; ++layerGainsItr)
178  {
179  std::cout << "GAIN " << layerGainsItr->first
180  << " STRIPS " << layerGainsItr->second.size() << " "
181  << layerGainsItr->second[0].gain_slope
182  << " " << layerGainsItr->second[0].gain_intercept << std::endl;
183  }
184 
185  std::map< int,std::vector<CSCDBPedestals::Item> >::const_iterator pedestalItr = thePedestals->pedestals.begin(),
186  lastPedestal = thePedestals->pedestals.end();
187  for( ; pedestalItr != lastPedestal; ++pedestalItr)
188  {
189  std::cout << "PEDS " << pedestalItr->first << " "
190  << " STRIPS " << pedestalItr->second.size() << " ";
191  for(int i = 1; i < 80; ++i)
192  {
193  std::cout << pedestalItr->second[i-1].rms << " " ;
194  }
195  std::cout << std::endl;
196  }
197 
198  std::map< int,std::vector<CSCDBCrosstalk::Item> >::const_iterator crosstalkItr = theCrosstalk->crosstalk.begin(),
199  lastCrosstalk = theCrosstalk->crosstalk.end();
200  for( ; crosstalkItr != lastCrosstalk; ++crosstalkItr)
201  {
202  std::cout << "XTALKS " << crosstalkItr->first
203  << " STRIPS " << crosstalkItr->second.size() << " "
204  << crosstalkItr->second[5].xtalk_slope_left << " "
205  << crosstalkItr->second[5].xtalk_slope_right << " "
206  << crosstalkItr->second[5].xtalk_intercept_left << " "
207  << crosstalkItr->second[5].xtalk_intercept_right << std::endl;
208  }
209 */
210 }
211 
212 float CSCConditions::gain(const CSCDetId & detId, int channel) const
213 {
214  assert(theGains.isValid());
215  return float( theGains->item(detId, channel).gain_slope )/theGains->factor_gain;
216 }
217 
218 
219 float CSCConditions::pedestal(const CSCDetId & detId, int channel) const
220 {
221  assert(thePedestals.isValid());
222  return float ( thePedestals->item(detId, channel).ped )/thePedestals->factor_ped;
223 }
224 
225 
226 float CSCConditions::pedestalSigma(const CSCDetId&detId, int channel) const
227 {
228  assert(thePedestals.isValid());
229  return float ( thePedestals->item(detId, channel).rms )/thePedestals->factor_rms;
230 }
231 
232 
233 float CSCConditions::crosstalkIntercept(const CSCDetId&detId, int channel, bool leftRight) const
234 {
235  assert(theCrosstalk.isValid());
236  const CSCDBCrosstalk::Item & item = theCrosstalk->item(detId, channel);
237 
238  // resistive fraction is at the peak, where t=0
239  return leftRight ? float ( item.xtalk_intercept_right )/theCrosstalk->factor_intercept
240  : float ( item.xtalk_intercept_left )/theCrosstalk->factor_intercept ;
241 }
242 
243 
244 float CSCConditions::crosstalkSlope(const CSCDetId&detId, int channel, bool leftRight) const
245 {
246  assert(theCrosstalk.isValid());
247  const CSCDBCrosstalk::Item & item = theCrosstalk->item(detId, channel);
248 
249  // resistive fraction is at the peak, where t=0
250  return leftRight ? float ( item.xtalk_slope_right )/theCrosstalk->factor_slope
251  : float ( item.xtalk_slope_left )/theCrosstalk->factor_slope ;
252 }
253 
254 const CSCDBNoiseMatrix::Item & CSCConditions::noiseMatrix(const CSCDetId& detId, int channel) const
255 {
256  assert(theNoiseMatrix.isValid());
257  return theNoiseMatrix->item(detId, channel);
258 }
259 
260 void CSCConditions::noiseMatrixElements( const CSCDetId& id, int channel, std::vector<float>& me ) const {
261  assert(me.size()>11);
262  const CSCDBNoiseMatrix::Item& item = noiseMatrix(id, channel);
263  me[0] = float ( item.elem33 )/theNoiseMatrix->factor_noise;
264  me[1] = float ( item.elem34 )/theNoiseMatrix->factor_noise;
265  me[2] = float ( item.elem35 )/theNoiseMatrix->factor_noise;
266  me[3] = float ( item.elem44 )/theNoiseMatrix->factor_noise;
267  me[4] = float ( item.elem45 )/theNoiseMatrix->factor_noise;
268  me[5] = float ( item.elem46 )/theNoiseMatrix->factor_noise;
269  me[6] = float ( item.elem55 )/theNoiseMatrix->factor_noise;
270  me[7] = float ( item.elem56 )/theNoiseMatrix->factor_noise;
271  me[8] = float ( item.elem57 )/theNoiseMatrix->factor_noise;
272  me[9] = float ( item.elem66 )/theNoiseMatrix->factor_noise;
273  me[10] = float ( item.elem67 )/theNoiseMatrix->factor_noise;
274  me[11] = float ( item.elem77 )/theNoiseMatrix->factor_noise;
275 }
276 
277 void CSCConditions::crossTalk( const CSCDetId& id, int channel, std::vector<float>& ct ) const {
278  assert(theCrosstalk.isValid());
279  const CSCDBCrosstalk::Item & item = theCrosstalk->item(id, channel);
280  ct[0] = float ( item.xtalk_slope_left )/theCrosstalk->factor_slope;
281  ct[1] = float ( item.xtalk_intercept_left )/theCrosstalk->factor_intercept;
282  ct[2] = float ( item.xtalk_slope_right )/theCrosstalk->factor_slope;
283  ct[3] = float ( item.xtalk_intercept_right )/theCrosstalk->factor_intercept;
284 }
285 
286 float CSCConditions::chipCorrection(const CSCDetId & detId, int stripChannel) const
287 {
288  if ( useTimingCorrections() ){
289  assert(theChipCorrections.isValid());
290  CSCIndexer indexer;
291  int chip = indexer.chipIndex(stripChannel); //Converts 1-80(64) in a layer to 1-5(4), expects ME1/1a to be channel 65-80
292  //printf("CSCCondition e:%d s:%d r:%d c:%d l:%d strip:%d chip: %d\n",detId.endcap(),detId.station(), detId.ring(),detId.chamber(),detId.layer(),stripChannel,chip);
293  return float ( theChipCorrections->item(detId,chip).speedCorr )/theChipCorrections->factor_speedCorr;
294  }
295  else
296  return 0;
297 }
299 {
300  if ( useTimingCorrections() ){
302  return float ( theChamberTimingCorrections->item(detId).cfeb_tmb_skew_delay*1./theChamberTimingCorrections->factor_precision
303  + theChamberTimingCorrections->item(detId).cfeb_timing_corr*1./theChamberTimingCorrections->factor_precision
304  + (theChamberTimingCorrections->item(detId).cfeb_cable_delay*25.)
305 );
306  }
307  else
308  return 0;
309 }
310 float CSCConditions::anodeBXoffset(const CSCDetId & detId) const
311 {
312  if ( useTimingCorrections() ){
314  return float ( theChamberTimingCorrections->item(detId).anode_bx_offset*1./theChamberTimingCorrections->factor_precision);
315  }
316  else
317  return 0;
318 }
319 
320 const std::bitset<80>& CSCConditions::badStripWord( const CSCDetId& id ) const {
321  CSCIndexer indexer;
322  return badStripWords[indexer.layerIndex(id) - 1];
323 }
324 
325 const std::bitset<112>& CSCConditions::badWireWord( const CSCDetId& id ) const {
326  CSCIndexer indexer;
327  return badWireWords[indexer.layerIndex(id) - 1];
328 }
329 
335 
336  const float loEdge = 5.0; // consider gains above this
337  const float hiEdge = 10.0; // consider gains below this
338  const float loLimit = 6.0; // lowest acceptable average gain
339  const float hiLimit = 9.0; // highest acceptable average gain
340  const float expectedAverage = 7.5; // default average gain
341 
342  if ( theAverageGain > 0. ) return theAverageGain; // only recalculate if necessary
343 
344  int n_strip = 0;
345  float gain_tot = 0.;
346 
347  CSCDBGains::GainContainer::const_iterator it;
348  for ( it=theGains->gains.begin(); it!=theGains->gains.end(); ++it ) {
349  float the_gain = float( it->gain_slope )/theGains->factor_gain;
350  if (the_gain > loEdge && the_gain < hiEdge ) {
351  gain_tot += the_gain;
352  ++n_strip;
353  }
354  }
355 
356  // Average gain
357  if ( n_strip > 0 ) {
358  theAverageGain = gain_tot / n_strip;
359  }
360 
361  // Average gain has been around 7.5 in real data
362  if ( theAverageGain < loLimit || theAverageGain > hiLimit ) {
363  // LogTrace("CSC") << "Average CSC strip gain = "
364  // << theAverageGain << " is reset to expected value " << expectedAverage;
365  theAverageGain = expectedAverage;
366  }
367 
368  return theAverageGain;
369 }
370 //
371 float CSCConditions::gasGainCorrection(const CSCDetId & detId, int strip, int wiregroup) const
372 {
373  if ( useGasGainCorrections() ){
374  assert(theGasGainCorrections.isValid());
375  //printf("CSCCondition e:%d s:%d r:%d c:%d l:%d strip:%d wire:%d\n",detId.endcap(),detId.station(),detId.ring(),detId.chamber(),detId.layer(),strip,wiregroup);
376  return float ( theGasGainCorrections->item(detId,strip,wiregroup).gainCorr );
377 
378  } else {
379  return 1.;
380  }
381 }
T getParameter(std::string const &) const
const std::bitset< 80 > & badStripWord(const CSCDetId &id) const
return bad channel words per CSCLayer - 1 bit per channel
int i
Definition: DBlmapReader.cc:9
edm::ESHandle< CSCDBGasGainCorrection > theGasGainCorrections
edm::ESHandle< CSCDBNoiseMatrix > theNoiseMatrix
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16
edm::ESHandle< CSCBadWires > theBadWires
float pedestalSigma(const CSCDetId &detId, int channel) const
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?
Definition: CSCConditions.h:90
const CSCDBNoiseMatrix::Item & noiseMatrix(const CSCDetId &detId, int channel) const
return raw noise matrix (unscaled short int elements)
void print() const
edm::ESHandle< CSCBadStrips > theBadStrips
float chipCorrection(const CSCDetId &detId, int channel) const
std::vector< std::bitset< 112 > > badWireWords
float chamberTimingCorrection(const CSCDetId &detId) const
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
bool useTimingCorrections_
float pedestal(const CSCDetId &detId, int channel) const
in ADC counts
bool readBadChannels() const
did we request reading bad channel info from db?
Definition: CSCConditions.h:84
bool useGasGainCorrections_
CSCDetId detIdFromChamberIndex(IndexType ici) const
Definition: CSCIndexer.cc:62
edm::ESHandle< CSCBadChambers > theBadChambers
int j
Definition: DBlmapReader.cc:9
edm::ESHandle< CSCDBGains > theGains
void initializeEvent(const edm::EventSetup &es)
fetch the maps from the database
const std::bitset< 112 > & badWireWord(const CSCDetId &id) const
float crosstalkSlope(const CSCDetId &detId, int channel, bool leftRight) const
float crosstalkIntercept(const CSCDetId &detId, int channel, bool leftRight) const
bool isInBadChamber(const CSCDetId &id) const
Is the gven chamber flagged as bad?
float gain(const CSCDetId &detId, int channel) const
channels count from 1
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?
Definition: CSCConditions.h:87
const T & get() const
Definition: EventSetup.h:55
string const
Definition: compareJSON.py:14
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:59
IndexType layerIndex(const CSCDetId &id) const
Definition: CSCIndexer.h:80
IndexType chipIndex(IndexType ie, IndexType is, IndexType ir, IndexType ic, IndexType il, IndexType ichip) const
Definition: CSCIndexer.h:237
float gasGainCorrection(const CSCDetId &detId, int strip, int wire) const
gas gain correction as a function of detId (w/layer), strip, and wire
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