00001 #include "CalibMuon/CSCCalibration/interface/CSCConditions.h"
00002 #include "FWCore/Framework/interface/EventSetup.h"
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/ESWatcher.h"
00005 #include "FWCore/Framework/interface/ESHandle.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include "FWCore/Framework/interface/MakerMacros.h"
00008 #include "CondFormats/DataRecord/interface/CSCDBPedestalsRcd.h"
00009 #include "CondFormats/DataRecord/interface/CSCDBNoiseMatrixRcd.h"
00010 #include "CondFormats/DataRecord/interface/CSCDBCrosstalkRcd.h"
00011 #include "CondFormats/CSCObjects/interface/CSCDBGains.h"
00012 #include "CondFormats/CSCObjects/interface/CSCDBPedestals.h"
00013 #include "CondFormats/CSCObjects/interface/CSCDBCrosstalk.h"
00014 #include "CondFormats/CSCObjects/interface/CSCBadStrips.h"
00015 #include "CondFormats/CSCObjects/interface/CSCBadWires.h"
00016 #include "CondFormats/CSCObjects/interface/CSCBadChambers.h"
00017 #include "CondFormats/CSCObjects/interface/CSCDBChipSpeedCorrection.h"
00018 #include "CondFormats/CSCObjects/interface/CSCChamberTimeCorrections.h"
00019 #include "DataFormats/MuonDetId/interface/CSCIndexer.h"
00020
00021 CSCConditions::CSCConditions( const edm::ParameterSet& ps )
00022 : theGains(),
00023 theCrosstalk(),
00024 thePedestals(),
00025 theNoiseMatrix(),
00026 theBadStrips(),
00027 theBadWires(),
00028 theBadChambers(),
00029 theChipCorrections(),
00030 theChamberTimingCorrections(),
00031 readBadChannels_(false), readBadChambers_(false),useTimingCorrections_(false),
00032 theAverageGain( -1.0 )
00033 {
00034 readBadChannels_ = ps.getParameter<bool>("readBadChannels");
00035 readBadChambers_ = ps.getParameter<bool>("readBadChambers");
00036 useTimingCorrections_ = ps.getParameter<bool>("CSCUseTimingCorrections");
00037
00038 badStripWords.resize( MAX_LAYERS, 0 );
00039 badWireWords.resize( MAX_LAYERS, 0 );
00040 }
00041
00042
00043 CSCConditions::~CSCConditions()
00044 {
00045 }
00046
00047 void CSCConditions::initializeEvent(const edm::EventSetup & es)
00048 {
00049
00050 es.get<CSCDBGainsRcd>().get( theGains );
00051
00052 es.get<CSCDBCrosstalkRcd>().get( theCrosstalk );
00053
00054 es.get<CSCDBPedestalsRcd>().get( thePedestals );
00055
00056 es.get<CSCDBNoiseMatrixRcd>().get(theNoiseMatrix);
00057
00058 if ( useTimingCorrections()){
00059
00060 es.get<CSCDBChipSpeedCorrectionRcd>().get( theChipCorrections );
00061
00062 es.get<CSCChamberTimeCorrectionsRcd>().get( theChamberTimingCorrections );
00063 }
00064
00065 if ( readBadChannels() ) {
00066
00067 es.get<CSCBadStripsRcd>().get( theBadStrips );
00068
00069 es.get<CSCBadWiresRcd>().get( theBadWires );
00070
00071
00072 fillBadStripWords();
00073
00074
00075 fillBadWireWords();
00076
00077
00078 }
00079
00080
00081 if( gainsWatcher_.check( es ) ) {
00082 theAverageGain = -1.0;
00083 }
00084
00085 if ( readBadChambers() ) {
00086
00087 es.get<CSCBadChambersRcd>().get( theBadChambers );
00088 }
00089
00090
00091 }
00092
00093 void CSCConditions::fillBadStripWords(){
00094
00095 badStripWords.assign( MAX_LAYERS, 0 );
00096 if ( readBadChannels() ) {
00097
00098
00099
00100
00101
00102
00103
00104 CSCIndexer indexer;
00105
00106 for ( size_t i=0; i<theBadStrips->chambers.size(); ++i ) {
00107 int indexc = theBadStrips->chambers[i].chamber_index;
00108 int start = theBadStrips->chambers[i].pointer;
00109 int nbad = theBadStrips->chambers[i].bad_channels;
00110
00111 CSCDetId id = indexer.detIdFromChamberIndex( indexc );
00112
00113 for ( int j=start-1; j<start-1+nbad; ++j ) {
00114 short lay = theBadStrips->channels[j].layer;
00115 short chan = theBadStrips->channels[j].channel;
00116
00117
00118
00119 int indexl = indexer.layerIndex( id.endcap(), id.station(), id.ring(), id.chamber(), lay );
00120 badStripWords[indexl-1].set( chan-1, 1 );
00121 }
00122 }
00123
00124 }
00125 }
00126
00127 void CSCConditions::fillBadWireWords(){
00128
00129 badWireWords.assign( MAX_LAYERS, 0 );
00130 if ( readBadChannels() ) {
00131
00132 CSCIndexer indexer;
00133
00134 for ( size_t i=0; i<theBadWires->chambers.size(); ++i ) {
00135 int indexc = theBadWires->chambers[i].chamber_index;
00136 int start = theBadWires->chambers[i].pointer;
00137 int nbad = theBadWires->chambers[i].bad_channels;
00138
00139 CSCDetId id = indexer.detIdFromChamberIndex( indexc );
00140
00141 for ( int j=start-1; j<start-1+nbad; ++j ) {
00142 short lay = theBadWires->channels[j].layer;
00143 short chan = theBadWires->channels[j].channel;
00144
00145
00146
00147 int indexl = indexer.layerIndex( id.endcap(), id.station(), id.ring(), id.chamber(), lay );
00148 badWireWords[indexl-1].set( chan-1, 1 );
00149 }
00150 }
00151
00152 }
00153 }
00154
00155 bool CSCConditions::isInBadChamber( const CSCDetId& id ) const {
00156 if ( readBadChambers() ) return theBadChambers->isInBadChamber( id );
00157 else return false;
00158 }
00159
00160 void CSCConditions::print() const
00161
00162 {
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 }
00204
00205 float CSCConditions::gain(const CSCDetId & detId, int channel) const
00206 {
00207 assert(theGains.isValid());
00208 return float( theGains->item(detId, channel).gain_slope )/theGains->factor_gain;
00209 }
00210
00211
00212 float CSCConditions::pedestal(const CSCDetId & detId, int channel) const
00213 {
00214 assert(thePedestals.isValid());
00215 return float ( thePedestals->item(detId, channel).ped )/thePedestals->factor_ped;
00216 }
00217
00218
00219 float CSCConditions::pedestalSigma(const CSCDetId&detId, int channel) const
00220 {
00221 assert(thePedestals.isValid());
00222 return float ( thePedestals->item(detId, channel).rms )/thePedestals->factor_rms;
00223 }
00224
00225
00226 float CSCConditions::crosstalkIntercept(const CSCDetId&detId, int channel, bool leftRight) const
00227 {
00228 assert(theCrosstalk.isValid());
00229 const CSCDBCrosstalk::Item & item = theCrosstalk->item(detId, channel);
00230
00231
00232 return leftRight ? float ( item.xtalk_intercept_right )/theCrosstalk->factor_intercept
00233 : float ( item.xtalk_intercept_left )/theCrosstalk->factor_intercept ;
00234 }
00235
00236
00237 float CSCConditions::crosstalkSlope(const CSCDetId&detId, int channel, bool leftRight) const
00238 {
00239 assert(theCrosstalk.isValid());
00240 const CSCDBCrosstalk::Item & item = theCrosstalk->item(detId, channel);
00241
00242
00243 return leftRight ? float ( item.xtalk_slope_right )/theCrosstalk->factor_slope
00244 : float ( item.xtalk_slope_left )/theCrosstalk->factor_slope ;
00245 }
00246
00247 const CSCDBNoiseMatrix::Item & CSCConditions::noiseMatrix(const CSCDetId& detId, int channel) const
00248 {
00249 assert(theNoiseMatrix.isValid());
00250 return theNoiseMatrix->item(detId, channel);
00251 }
00252
00253 void CSCConditions::noiseMatrixElements( const CSCDetId& id, int channel, std::vector<float>& me ) const {
00254 assert(me.size()>11);
00255 const CSCDBNoiseMatrix::Item& item = noiseMatrix(id, channel);
00256 me[0] = float ( item.elem33 )/theNoiseMatrix->factor_noise;
00257 me[1] = float ( item.elem34 )/theNoiseMatrix->factor_noise;
00258 me[2] = float ( item.elem35 )/theNoiseMatrix->factor_noise;
00259 me[3] = float ( item.elem44 )/theNoiseMatrix->factor_noise;
00260 me[4] = float ( item.elem45 )/theNoiseMatrix->factor_noise;
00261 me[5] = float ( item.elem46 )/theNoiseMatrix->factor_noise;
00262 me[6] = float ( item.elem55 )/theNoiseMatrix->factor_noise;
00263 me[7] = float ( item.elem56 )/theNoiseMatrix->factor_noise;
00264 me[8] = float ( item.elem57 )/theNoiseMatrix->factor_noise;
00265 me[9] = float ( item.elem66 )/theNoiseMatrix->factor_noise;
00266 me[10] = float ( item.elem67 )/theNoiseMatrix->factor_noise;
00267 me[11] = float ( item.elem77 )/theNoiseMatrix->factor_noise;
00268 }
00269
00270 void CSCConditions::crossTalk( const CSCDetId& id, int channel, std::vector<float>& ct ) const {
00271 assert(theCrosstalk.isValid());
00272 const CSCDBCrosstalk::Item & item = theCrosstalk->item(id, channel);
00273 ct[0] = float ( item.xtalk_slope_left )/theCrosstalk->factor_slope;
00274 ct[1] = float ( item.xtalk_intercept_left )/theCrosstalk->factor_intercept;
00275 ct[2] = float ( item.xtalk_slope_right )/theCrosstalk->factor_slope;
00276 ct[3] = float ( item.xtalk_intercept_right )/theCrosstalk->factor_intercept;
00277 }
00278
00279 float CSCConditions::chipCorrection(const CSCDetId & detId, int stripChannel) const
00280 {
00281 if ( useTimingCorrections() ){
00282 assert(theChipCorrections.isValid());
00283 CSCIndexer indexer;
00284 int chip = indexer.chipIndex(stripChannel);
00285
00286 return float ( theChipCorrections->item(detId,chip).speedCorr )/theChipCorrections->factor_speedCorr;
00287 }
00288 else
00289 return 0;
00290 }
00291 float CSCConditions::chamberTimingCorrection(const CSCDetId & detId) const
00292 {
00293 if ( useTimingCorrections() ){
00294 assert(theChamberTimingCorrections.isValid());
00295 return float ( theChamberTimingCorrections->item(detId).cfeb_tmb_skew_delay*1./theChamberTimingCorrections->factor_precision
00296 + theChamberTimingCorrections->item(detId).cfeb_timing_corr*1./theChamberTimingCorrections->factor_precision
00297 + (theChamberTimingCorrections->item(detId).cfeb_cable_delay*25.)
00298 );
00299 }
00300 else
00301 return 0;
00302 }
00303 float CSCConditions::anodeBXoffset(const CSCDetId & detId) const
00304 {
00305 if ( useTimingCorrections() ){
00306 assert(theChamberTimingCorrections.isValid());
00307 return float ( theChamberTimingCorrections->item(detId).anode_bx_offset*1./theChamberTimingCorrections->factor_precision);
00308 }
00309 else
00310 return 0;
00311 }
00312
00313 const std::bitset<80>& CSCConditions::badStripWord( const CSCDetId& id ) const {
00314 CSCIndexer indexer;
00315 return badStripWords[indexer.layerIndex(id) - 1];
00316 }
00317
00318 const std::bitset<112>& CSCConditions::badWireWord( const CSCDetId& id ) const {
00319 CSCIndexer indexer;
00320 return badWireWords[indexer.layerIndex(id) - 1];
00321 }
00322
00327 float CSCConditions::averageGain() const {
00328
00329 const float loEdge = 5.0;
00330 const float hiEdge = 10.0;
00331 const float loLimit = 6.0;
00332 const float hiLimit = 9.0;
00333 const float expectedAverage = 7.5;
00334
00335 if ( theAverageGain > 0. ) return theAverageGain;
00336
00337 int n_strip = 0;
00338 float gain_tot = 0.;
00339
00340 CSCDBGains::GainContainer::const_iterator it;
00341 for ( it=theGains->gains.begin(); it!=theGains->gains.end(); ++it ) {
00342 float the_gain = float( it->gain_slope )/theGains->factor_gain;
00343 if (the_gain > loEdge && the_gain < hiEdge ) {
00344 gain_tot += the_gain;
00345 ++n_strip;
00346 }
00347 }
00348
00349
00350 if ( n_strip > 0 ) {
00351 theAverageGain = gain_tot / n_strip;
00352 }
00353
00354
00355 if ( theAverageGain < loLimit || theAverageGain > hiLimit ) {
00356
00357
00358 theAverageGain = expectedAverage;
00359 }
00360
00361 return theAverageGain;
00362 }