Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:32

0001 #ifndef CSCCalibration_CSCConditions_h
0002 #define CSCCalibration_CSCConditions_h
0003 
0004 #include "CondFormats/DataRecord/interface/CSCChamberTimeCorrectionsRcd.h"
0005 #include "CondFormats/DataRecord/interface/CSCDBChipSpeedCorrectionRcd.h"
0006 #include "CondFormats/DataRecord/interface/CSCDBCrosstalkRcd.h"
0007 #include "CondFormats/DataRecord/interface/CSCDBGasGainCorrectionRcd.h"
0008 #include "CondFormats/DataRecord/interface/CSCDBNoiseMatrixRcd.h"
0009 #include "CondFormats/DataRecord/interface/CSCDBPedestalsRcd.h"
0010 #include "CondFormats/CSCObjects/interface/CSCDBNoiseMatrix.h"
0011 #include "CondFormats/DataRecord/interface/CSCBadStripsRcd.h"
0012 #include "CondFormats/DataRecord/interface/CSCBadWiresRcd.h"
0013 #include "CondFormats/DataRecord/interface/CSCDBGainsRcd.h"
0014 #include "CalibMuon/CSCCalibration/interface/CSCChannelMapperRecord.h"
0015 #include "CalibMuon/CSCCalibration/interface/CSCIndexerRecord.h"
0016 #include "CondFormats/DataRecord/interface/CSCBadChambersRcd.h"
0017 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
0018 #include "FWCore/Framework/interface/ESHandle.h"
0019 #include "FWCore/Framework/interface/ESWatcher.h"
0020 #include "FWCore/Framework/interface/Frameworkfwd.h"
0021 #include "FWCore/Framework/interface/ConsumesCollector.h"
0022 #include "FWCore/Utilities/interface/ESGetToken.h"
0023 #include <bitset>
0024 #include <vector>
0025 
0026 class CSCDBGains;
0027 class CSCDBPedestals;
0028 class CSCDBCrosstalk;
0029 class CSCBadStrips;
0030 class CSCBadWires;
0031 class CSCBadChambers;
0032 class CSCDBChipSpeedCorrection;
0033 class CSCChamberTimeCorrections;
0034 class CSCDBGasGainCorrection;
0035 class CSCIndexerBase;
0036 class CSCChannelMapperBase;
0037 
0038 /**  Encapsulates a user interface into the CSC conditions
0039  *
0040  * \author Rick Wilkinson
0041  * \author Tim Cox
0042  *
0043  * Interfaces generally use "channels" which count from 1 and are 'geometric'
0044  * i.e. in the order matching local coordinates. This is the channel labelling
0045  * in CSCStripDigi (and CSCWireDigi) after internal corrections within
0046  * CSCRawToDigi.
0047  *
0048  * The input CSCDetId is also 'geometric channel level' i.e. ME11A has its own
0049  * CSCDetId even in the ganged case,
0050  *
0051  * Ganged ME1a channels are 1-16 (and unganged, of course, 1-48)
0052  *
0053  * From CMSSW 61X, this class also handles separate algorithm versions for
0054  * indexing the conditions data and for mapping between online and offline
0055  * channel labelling.
0056  */
0057 
0058 class CSCConditions {
0059 public:
0060   explicit CSCConditions(const edm::ParameterSet &ps, edm::ConsumesCollector);
0061   ~CSCConditions();
0062 
0063   /// fetch database content via EventSetup
0064   void initializeEvent(const edm::EventSetup &es);
0065 
0066   /// gain per channel
0067   float gain(const CSCDetId &detId, int channel) const;
0068   /// overall calibration precision
0069   float gainSigma(const CSCDetId &detId, int channel) const { return 0.005; }
0070 
0071   /// static ped in ADC counts
0072   float pedestal(const CSCDetId &detId, int channel) const;
0073   /// static ped rms in ADC counts
0074   float pedestalSigma(const CSCDetId &detId, int channel) const;
0075 
0076   /// crosstalk slope for left and right
0077   float crosstalkSlope(const CSCDetId &detId, int channel, bool leftRight) const;
0078   /// crosstalk intercept for left and right
0079   float crosstalkIntercept(const CSCDetId &detId, int channel, bool leftRight) const;
0080 
0081   /// raw noise matrix (unscaled short int elements)
0082   const CSCDBNoiseMatrix::Item &noiseMatrix(const CSCDetId &detId, int channel) const;
0083 
0084   /// fill vector (dim 12, must be allocated by caller) with noise matrix
0085   /// elements (scaled to float)
0086   void noiseMatrixElements(const CSCDetId &id, int channel, std::vector<float> &me) const;
0087 
0088   /// fill vector (dim 4, must be allocated by caller) with crosstalk sl, il,
0089   /// sr, ir
0090   void crossTalk(const CSCDetId &id, int channel, std::vector<float> &ct) const;
0091 
0092   /// chip speed correction in ns given detId (w/layer) and strip channel
0093   float chipCorrection(const CSCDetId &detId, int channel) const;
0094 
0095   /// chamber timing correction in ns given detId of chamber
0096   float chamberTimingCorrection(const CSCDetId &detId) const;
0097 
0098   /// anode bx offset in bx given detId of chamber
0099   float anodeBXoffset(const CSCDetId &detId) const;
0100 
0101   /// bad strip channel word for a CSCLayer - 1 bit per channel
0102   const std::bitset<112> &badStripWord() const { return badStripWord_; }
0103 
0104   /// bad wiregroup channel word for a CSCLayer - 1 bit per channel
0105   const std::bitset<112> &badWireWord() const { return badWireWord_; }
0106 
0107   /// the offline CSCDetId of current bad channel words
0108   const CSCDetId &idOfBadChannelWords() const { return idOfBadChannelWords_; }
0109 
0110   void print() const;
0111 
0112   /// Is the gven chamber flagged as bad?
0113   bool isInBadChamber(const CSCDetId &id) const;
0114 
0115   /// did we request reading bad channel info from db?
0116   bool readBadChannels() const { return readBadChannels_; }
0117 
0118   /// did we request reading bad chamber info from db?
0119   bool readBadChambers() const { return readBadChambers_; }
0120 
0121   /// did we request reading timing correction info from db?
0122   bool useTimingCorrections() const { return useTimingCorrections_; }
0123 
0124   /// Fill bad channel words - one for strips, one for wires, for an offline
0125   /// CSCDetId
0126   void fillBadChannelWords(const CSCDetId &id);
0127 
0128   /// average gain over entire CSC system (logically const although must be
0129   /// cached here).
0130   float averageGain() const;
0131 
0132   /// gas gain correction as a function of detId (w/layer), strip, and wire
0133   /// channels
0134   float gasGainCorrection(const CSCDetId &detId, int strip, int wire) const;
0135 
0136   /// did we request reading gas gain correction info from db?
0137   bool useGasGainCorrections() const { return useGasGainCorrections_; }
0138 
0139   /// feedthrough for external access
0140   int channelFromStrip(const CSCDetId &id, int geomStrip) const;
0141   int rawStripChannel(const CSCDetId &id, int geomChannel) const;
0142 
0143 private:
0144   /// fill bad channel words for offline id
0145   void fillBadStripWord(const CSCDetId &id);
0146   void fillBadWireWord(const CSCDetId &id);
0147   /// Set id for current content of bad channel words - this is offline id i.e.
0148   /// separate for ME11A & ME11B
0149   void setIdOfBadChannelWords(const CSCDetId &id) { idOfBadChannelWords_ = id; }
0150 
0151   // handles to conditions data
0152 
0153   edm::ESHandle<CSCDBGains> theGains;
0154   edm::ESHandle<CSCDBCrosstalk> theCrosstalk;
0155   edm::ESHandle<CSCDBPedestals> thePedestals;
0156   edm::ESHandle<CSCDBNoiseMatrix> theNoiseMatrix;
0157   edm::ESHandle<CSCBadStrips> theBadStrips;
0158   edm::ESHandle<CSCBadWires> theBadWires;
0159   edm::ESHandle<CSCBadChambers> theBadChambers;
0160   edm::ESHandle<CSCDBChipSpeedCorrection> theChipCorrections;
0161   edm::ESHandle<CSCChamberTimeCorrections> theChamberTimingCorrections;
0162   edm::ESHandle<CSCDBGasGainCorrection> theGasGainCorrections;
0163 
0164   // handles to algorithm versions
0165 
0166   edm::ESHandle<CSCIndexerBase> indexer_;
0167   edm::ESHandle<CSCChannelMapperBase> mapper_;
0168 
0169   //EventSetup Tokens for Handles
0170   edm::ESGetToken<CSCDBGains, CSCDBGainsRcd> gainsToken_;
0171   edm::ESGetToken<CSCDBCrosstalk, CSCDBCrosstalkRcd> crosstalkToken_;
0172   edm::ESGetToken<CSCDBPedestals, CSCDBPedestalsRcd> pedestalsToken_;
0173   edm::ESGetToken<CSCDBNoiseMatrix, CSCDBNoiseMatrixRcd> noiseMatrixToken_;
0174   edm::ESGetToken<CSCBadStrips, CSCBadStripsRcd> badStripsToken_;
0175   edm::ESGetToken<CSCBadWires, CSCBadWiresRcd> badWiresToken_;
0176   edm::ESGetToken<CSCBadChambers, CSCBadChambersRcd> badChambersToken_;
0177   edm::ESGetToken<CSCDBChipSpeedCorrection, CSCDBChipSpeedCorrectionRcd> chipCorrectionsToken_;
0178   edm::ESGetToken<CSCChamberTimeCorrections, CSCChamberTimeCorrectionsRcd> chamberTimingCorrectionsToken_;
0179   edm::ESGetToken<CSCDBGasGainCorrection, CSCDBGasGainCorrectionRcd> gasGainCorrectionsToken_;
0180   edm::ESGetToken<CSCIndexerBase, CSCIndexerRecord> indexerToken_;
0181   edm::ESGetToken<CSCChannelMapperBase, CSCChannelMapperRecord> mapperToken_;
0182 
0183   // logical flags controlling some conditions data usage
0184 
0185   bool readBadChannels_;        // flag whether or not to even attempt reading bad
0186                                 // channel info from db
0187   bool readBadChambers_;        // flag whether or not to even attempt reading bad
0188                                 // chamber info from db
0189   bool useTimingCorrections_;   // flag whether or not to even attempt reading
0190                                 // timing correction info from db
0191   bool useGasGainCorrections_;  // flag whether or not to even attempt reading
0192                                 // gas-gain correction info from db
0193 
0194   // Cache bad channel content for current CSC layer
0195   CSCDetId idOfBadChannelWords_;
0196   std::bitset<112> badStripWord_;
0197   std::bitset<112> badWireWord_;
0198 
0199   mutable float theAverageGain;  // average over entire system, subject to some
0200                                  // constraints!
0201 
0202   edm::ESWatcher<CSCDBGainsRcd> gainsWatcher_;
0203   //@@ remove until we have real information to use
0204   //  edm::ESWatcher<CSCBadStripsRcd> badStripsWatcher_;
0205   //  edm::ESWatcher<CSCBadWiresRcd> badWiresWatcher_;
0206 
0207   // Total number of CSC layers in the system, with full ME42 installed.
0208   enum elayers { MAX_LAYERS = 3240 };
0209 };
0210 
0211 #endif