File indexing completed on 2024-09-07 04:34:55
0001
0002 #include "CalibMuon/CSCCalibration/interface/CSCConditions.h"
0003
0004 #include "CalibMuon/CSCCalibration/interface/CSCChannelMapperBase.h"
0005 #include "CalibMuon/CSCCalibration/interface/CSCIndexerBase.h"
0006
0007 #include "FWCore/Framework/interface/ESHandle.h"
0008 #include "FWCore/Framework/interface/ESWatcher.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/EventSetup.h"
0011 #include "FWCore/Framework/interface/MakerMacros.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013
0014 #include "CondFormats/CSCObjects/interface/CSCChamberTimeCorrections.h"
0015 #include "CondFormats/CSCObjects/interface/CSCDBChipSpeedCorrection.h"
0016 #include "CondFormats/CSCObjects/interface/CSCDBCrosstalk.h"
0017 #include "CondFormats/CSCObjects/interface/CSCDBGains.h"
0018 #include "CondFormats/CSCObjects/interface/CSCDBGasGainCorrection.h"
0019 #include "CondFormats/CSCObjects/interface/CSCDBPedestals.h"
0020
0021 #include "CondFormats/CSCObjects/interface/CSCBadChambers.h"
0022 #include "CondFormats/CSCObjects/interface/CSCBadStrips.h"
0023 #include "CondFormats/CSCObjects/interface/CSCBadWires.h"
0024
0025 CSCConditions::CSCConditions(const edm::ParameterSet &ps, edm::ConsumesCollector cc)
0026 : theGains(),
0027 theCrosstalk(),
0028 thePedestals(),
0029 theNoiseMatrix(),
0030 theBadStrips(),
0031 theBadWires(),
0032 theBadChambers(),
0033 theChipCorrections(),
0034 theChamberTimingCorrections(),
0035 theGasGainCorrections(),
0036 indexer_(nullptr),
0037 mapper_(nullptr),
0038 readBadChannels_(false),
0039 readBadChambers_(false),
0040 useTimingCorrections_(false),
0041 useGasGainCorrections_(false),
0042 idOfBadChannelWords_(CSCDetId()),
0043 badStripWord_(0),
0044 badWireWord_(0),
0045 theAverageGain(-1.0) {
0046 readBadChannels_ = ps.getParameter<bool>("readBadChannels");
0047 readBadChambers_ = ps.getParameter<bool>("readBadChambers");
0048 useTimingCorrections_ = ps.getParameter<bool>("CSCUseTimingCorrections");
0049 useGasGainCorrections_ = ps.getParameter<bool>("CSCUseGasGainCorrections");
0050 indexerToken_ = cc.esConsumes<CSCIndexerBase, CSCIndexerRecord>();
0051 mapperToken_ = cc.esConsumes<CSCChannelMapperBase, CSCChannelMapperRecord>();
0052 gainsToken_ = cc.esConsumes<CSCDBGains, CSCDBGainsRcd>();
0053 crosstalkToken_ = cc.esConsumes<CSCDBCrosstalk, CSCDBCrosstalkRcd>();
0054 pedestalsToken_ = cc.esConsumes<CSCDBPedestals, CSCDBPedestalsRcd>();
0055 noiseMatrixToken_ = cc.esConsumes<CSCDBNoiseMatrix, CSCDBNoiseMatrixRcd>();
0056 if (useTimingCorrections()) {
0057 chipCorrectionsToken_ = cc.esConsumes<CSCDBChipSpeedCorrection, CSCDBChipSpeedCorrectionRcd>();
0058 chamberTimingCorrectionsToken_ = cc.esConsumes<CSCChamberTimeCorrections, CSCChamberTimeCorrectionsRcd>();
0059 }
0060 if (readBadChannels()) {
0061 badStripsToken_ = cc.esConsumes<CSCBadStrips, CSCBadStripsRcd>();
0062 badWiresToken_ = cc.esConsumes<CSCBadWires, CSCBadWiresRcd>();
0063 }
0064 if (readBadChambers()) {
0065 badChambersToken_ = cc.esConsumes<CSCBadChambers, CSCBadChambersRcd>();
0066 }
0067 if (useGasGainCorrections()) {
0068 gasGainCorrectionsToken_ = cc.esConsumes<CSCDBGasGainCorrection, CSCDBGasGainCorrectionRcd>();
0069 }
0070 }
0071
0072 CSCConditions::~CSCConditions() {}
0073
0074 void CSCConditions::initializeEvent(const edm::EventSetup &es) {
0075
0076 indexer_ = es.getHandle(indexerToken_);
0077 mapper_ = es.getHandle(mapperToken_);
0078
0079
0080 theGains = es.getHandle(gainsToken_);
0081
0082 theCrosstalk = es.getHandle(crosstalkToken_);
0083
0084 thePedestals = es.getHandle(pedestalsToken_);
0085
0086 theNoiseMatrix = es.getHandle(noiseMatrixToken_);
0087
0088 if (useTimingCorrections()) {
0089
0090 theChipCorrections = es.getHandle(chipCorrectionsToken_);
0091
0092
0093 theChamberTimingCorrections = es.getHandle(chamberTimingCorrectionsToken_);
0094 }
0095
0096 if (readBadChannels()) {
0097
0098 theBadStrips = es.getHandle(badStripsToken_);
0099
0100 theBadWires = es.getHandle(badWiresToken_);
0101
0102
0103
0104
0105
0106
0107
0108 }
0109
0110
0111 if (gainsWatcher_.check(es)) {
0112 theAverageGain = -1.0;
0113 }
0114
0115 if (readBadChambers()) {
0116
0117 theBadChambers = es.getHandle(badChambersToken_);
0118 }
0119
0120 if (useGasGainCorrections()) {
0121 theGasGainCorrections = es.getHandle(gasGainCorrectionsToken_);
0122 }
0123
0124
0125 }
0126
0127 void CSCConditions::fillBadChannelWords(const CSCDetId &id) {
0128
0129
0130
0131
0132 if (id != idOfBadChannelWords()) {
0133
0134 setIdOfBadChannelWords(id);
0135
0136
0137 badStripWord_.reset();
0138 badWireWord_.reset();
0139
0140 if (readBadChannels()) {
0141
0142 CSCDetId idraw = mapper_->rawCSCDetId(id);
0143 fillBadStripWord(idraw);
0144 fillBadWireWord(idraw);
0145 }
0146 }
0147 }
0148
0149
0150
0151 void CSCConditions::fillBadStripWord(const CSCDetId &id) {
0152
0153
0154
0155 int inputIndex = indexer_->chamberIndex(id);
0156 short inputLayer = id.layer();
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166 for (size_t i = 0; i < theBadStrips->chambers.size(); ++i) {
0167 int indexc = theBadStrips->chambers[i].chamber_index;
0168 if (indexc != inputIndex)
0169 continue;
0170
0171 int start = theBadStrips->chambers[i].pointer;
0172 int nbad = theBadStrips->chambers[i].bad_channels;
0173
0174 for (int j = start - 1; j < start - 1 + nbad; ++j) {
0175 short lay = theBadStrips->channels[j].layer;
0176 if (lay != inputLayer)
0177 continue;
0178
0179 short chan = theBadStrips->channels[j].channel;
0180
0181
0182
0183
0184 badStripWord_.set(chan - 1, true);
0185
0186 }
0187 }
0188 }
0189
0190 void CSCConditions::fillBadWireWord(const CSCDetId &id) {
0191
0192
0193
0194 int inputIndex = indexer_->chamberIndex(id);
0195 short inputLayer = id.layer();
0196
0197
0198
0199 for (size_t i = 0; i < theBadWires->chambers.size(); ++i) {
0200 int indexc = theBadWires->chambers[i].chamber_index;
0201
0202 if (indexc != inputIndex)
0203 continue;
0204
0205 int start = theBadWires->chambers[i].pointer;
0206 int nbad = theBadWires->chambers[i].bad_channels;
0207
0208 for (int j = start - 1; j < start - 1 + nbad; ++j) {
0209 short lay = theBadWires->channels[j].layer;
0210 if (lay != inputLayer)
0211 continue;
0212
0213 short chan = theBadWires->channels[j].channel;
0214
0215
0216
0217 badWireWord_.set(chan - 1,
0218 true);
0219 }
0220 }
0221 }
0222
0223 bool CSCConditions::isInBadChamber(const CSCDetId &id) const {
0224
0225
0226
0227
0228
0229 if (readBadChambers()) {
0230 CSCDetId idraw = mapper_->rawCSCDetId(id);
0231 int index = indexer_->chamberIndex(idraw);
0232 return theBadChambers->isInBadChamber(index);
0233 } else
0234 return false;
0235 }
0236
0237 float CSCConditions::gain(const CSCDetId &id, int geomChannel) const {
0238 assert(theGains.isValid());
0239 CSCDetId idraw = mapper_->rawCSCDetId(id);
0240 int iraw = mapper_->rawStripChannel(id, geomChannel);
0241 int index = indexer_->stripChannelIndex(idraw, iraw) - 1;
0242 return float(theGains->gain(index)) / theGains->scale();
0243 }
0244
0245 float CSCConditions::pedestal(const CSCDetId &id, int geomChannel) const {
0246 assert(thePedestals.isValid());
0247 CSCDetId idraw = mapper_->rawCSCDetId(id);
0248 int iraw = mapper_->rawStripChannel(id, geomChannel);
0249 int index = indexer_->stripChannelIndex(idraw, iraw) - 1;
0250 return float(thePedestals->pedestal(index)) / thePedestals->scale_ped();
0251 }
0252
0253 float CSCConditions::pedestalSigma(const CSCDetId &id, int geomChannel) const {
0254 assert(thePedestals.isValid());
0255 CSCDetId idraw = mapper_->rawCSCDetId(id);
0256 int iraw = mapper_->rawStripChannel(id, geomChannel);
0257 int index = indexer_->stripChannelIndex(idraw, iraw) - 1;
0258 return float(thePedestals->pedestal_rms(index)) / thePedestals->scale_rms();
0259 }
0260
0261 float CSCConditions::crosstalkIntercept(const CSCDetId &id, int geomChannel, bool leftRight) const {
0262 assert(theCrosstalk.isValid());
0263 CSCDetId idraw = mapper_->rawCSCDetId(id);
0264 int iraw = mapper_->rawStripChannel(id, geomChannel);
0265 int index = indexer_->stripChannelIndex(idraw, iraw) - 1;
0266
0267 return leftRight ? float(theCrosstalk->rinter(index)) / theCrosstalk->iscale()
0268 : float(theCrosstalk->linter(index)) / theCrosstalk->iscale();
0269 }
0270
0271 float CSCConditions::crosstalkSlope(const CSCDetId &id, int geomChannel, bool leftRight) const {
0272 assert(theCrosstalk.isValid());
0273 CSCDetId idraw = mapper_->rawCSCDetId(id);
0274 int iraw = mapper_->rawStripChannel(id, geomChannel);
0275 int index = indexer_->stripChannelIndex(idraw, iraw) - 1;
0276
0277 return leftRight ? float(theCrosstalk->rslope(index)) / theCrosstalk->sscale()
0278 : float(theCrosstalk->lslope(index)) / theCrosstalk->sscale();
0279 }
0280
0281 const CSCDBNoiseMatrix::Item &CSCConditions::noiseMatrix(const CSCDetId &id, int geomChannel) const {
0282
0283
0284
0285
0286 assert(theNoiseMatrix.isValid());
0287 CSCDetId idraw = mapper_->rawCSCDetId(id);
0288 int iraw = mapper_->rawStripChannel(id, geomChannel);
0289 int index = indexer_->stripChannelIndex(idraw, iraw) - 1;
0290 return theNoiseMatrix->item(index);
0291 }
0292
0293 void CSCConditions::noiseMatrixElements(const CSCDetId &id, int geomChannel, std::vector<float> &me) const {
0294 assert(me.size() > 11);
0295 const CSCDBNoiseMatrix::Item &item = noiseMatrix(id, geomChannel);
0296 me[0] = float(item.elem33) / theNoiseMatrix->scale();
0297 me[1] = float(item.elem34) / theNoiseMatrix->scale();
0298 me[2] = float(item.elem35) / theNoiseMatrix->scale();
0299 me[3] = float(item.elem44) / theNoiseMatrix->scale();
0300 me[4] = float(item.elem45) / theNoiseMatrix->scale();
0301 me[5] = float(item.elem46) / theNoiseMatrix->scale();
0302 me[6] = float(item.elem55) / theNoiseMatrix->scale();
0303 me[7] = float(item.elem56) / theNoiseMatrix->scale();
0304 me[8] = float(item.elem57) / theNoiseMatrix->scale();
0305 me[9] = float(item.elem66) / theNoiseMatrix->scale();
0306 me[10] = float(item.elem67) / theNoiseMatrix->scale();
0307 me[11] = float(item.elem77) / theNoiseMatrix->scale();
0308 }
0309
0310 void CSCConditions::crossTalk(const CSCDetId &id, int geomChannel, std::vector<float> &ct) const {
0311 assert(theCrosstalk.isValid());
0312 CSCDetId idraw = mapper_->rawCSCDetId(id);
0313 int iraw = mapper_->rawStripChannel(id, geomChannel);
0314 int index = indexer_->stripChannelIndex(idraw, iraw) - 1;
0315
0316 ct[0] = float(theCrosstalk->lslope(index)) / theCrosstalk->sscale();
0317 ct[1] = float(theCrosstalk->linter(index)) / theCrosstalk->iscale();
0318 ct[2] = float(theCrosstalk->rslope(index)) / theCrosstalk->sscale();
0319 ct[3] = float(theCrosstalk->rinter(index)) / theCrosstalk->iscale();
0320 }
0321
0322 float CSCConditions::chipCorrection(const CSCDetId &id, int geomChannel) const {
0323 if (useTimingCorrections()) {
0324 assert(theChipCorrections.isValid());
0325 CSCDetId idraw = mapper_->rawCSCDetId(id);
0326 int iraw = mapper_->rawStripChannel(id, geomChannel);
0327 int ichip = indexer_->chipIndex(iraw);
0328 int index = indexer_->chipIndex(idraw, ichip) - 1;
0329 return float(theChipCorrections->value(index)) / theChipCorrections->scale();
0330 } else
0331 return 0;
0332 }
0333 float CSCConditions::chamberTimingCorrection(const CSCDetId &id) const {
0334 if (useTimingCorrections()) {
0335 assert(theChamberTimingCorrections.isValid());
0336 CSCDetId idraw = mapper_->rawCSCDetId(id);
0337 int index = indexer_->chamberIndex(idraw) - 1;
0338 return float(
0339 theChamberTimingCorrections->item(index).cfeb_tmb_skew_delay * 1. / theChamberTimingCorrections->precision() +
0340 theChamberTimingCorrections->item(index).cfeb_timing_corr * 1. / theChamberTimingCorrections->precision() +
0341 (theChamberTimingCorrections->item(index).cfeb_cable_delay * 25.));
0342 } else
0343 return 0;
0344 }
0345 float CSCConditions::anodeBXoffset(const CSCDetId &id) const {
0346 if (useTimingCorrections()) {
0347 assert(theChamberTimingCorrections.isValid());
0348 CSCDetId idraw = mapper_->rawCSCDetId(id);
0349 int index = indexer_->chamberIndex(idraw) - 1;
0350 return float(theChamberTimingCorrections->item(index).anode_bx_offset * 1. /
0351 theChamberTimingCorrections->precision());
0352 } else
0353 return 0;
0354 }
0355
0356
0357
0358
0359
0360 float CSCConditions::averageGain() const {
0361 const float loEdge = 5.0;
0362 const float hiEdge = 10.0;
0363 const float loLimit = 6.0;
0364 const float hiLimit = 9.0;
0365 const float expectedAverage = 7.5;
0366
0367 if (theAverageGain > 0.)
0368 return theAverageGain;
0369
0370 int n_strip = 0;
0371 float gain_tot = 0.;
0372
0373 CSCDBGains::GainContainer::const_iterator it;
0374 for (it = theGains->gains.begin(); it != theGains->gains.end(); ++it) {
0375 float the_gain = float(it->gain_slope) / theGains->scale();
0376 if (the_gain > loEdge && the_gain < hiEdge) {
0377 gain_tot += the_gain;
0378 ++n_strip;
0379 }
0380 }
0381
0382
0383 if (n_strip > 0) {
0384 theAverageGain = gain_tot / n_strip;
0385 }
0386
0387
0388 if (theAverageGain < loLimit || theAverageGain > hiLimit) {
0389
0390
0391
0392 theAverageGain = expectedAverage;
0393 }
0394
0395 return theAverageGain;
0396 }
0397
0398 float CSCConditions::gasGainCorrection(const CSCDetId &id, int geomChannel, int iwiregroup) const {
0399 if (useGasGainCorrections()) {
0400 assert(theGasGainCorrections.isValid());
0401 CSCDetId idraw = mapper_->rawCSCDetId(id);
0402 int iraw = mapper_->rawStripChannel(id, geomChannel);
0403 int index = indexer_->gasGainIndex(idraw, iraw, iwiregroup) - 1;
0404 return float(theGasGainCorrections->value(index));
0405 } else {
0406 return 1.;
0407 }
0408 }
0409
0410 int CSCConditions::channelFromStrip(const CSCDetId &id, int geomStrip) const {
0411 return mapper_->channelFromStrip(id, geomStrip);
0412 }
0413
0414 int CSCConditions::rawStripChannel(const CSCDetId &id, int geomChannel) const {
0415 return mapper_->rawStripChannel(id, geomChannel);
0416 }
0417
0418 void CSCConditions::print() const
0419
0420 {
0421
0422
0423
0424
0425
0426
0427
0428
0429
0430
0431
0432
0433
0434
0435
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445
0446
0447
0448
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463 }