Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:59

0001 #include <RecoLocalMuon/CSCRecHitD/src/CSCRecoConditions.h>
0002 #include <CondFormats/CSCObjects/interface/CSCChannelTranslator.h>
0003 #include <FWCore/MessageLogger/interface/MessageLogger.h>
0004 #include <iostream>
0005 
0006 CSCRecoConditions::CSCRecoConditions(const edm::ParameterSet& ps, edm::ConsumesCollector cc) : theConditions(ps, cc) {}
0007 
0008 CSCRecoConditions::~CSCRecoConditions() {}
0009 
0010 void CSCRecoConditions::initializeEvent(const edm::EventSetup& es) { theConditions.initializeEvent(es); }
0011 
0012 /// Fill badStrip word and badWire word for given CSC layer, id
0013 void CSCRecoConditions::fillBadChannelWords(const CSCDetId& id) { theConditions.fillBadChannelWords(id); }
0014 
0015 /// gains & pedestals are requested by geometric channel (as in CSCStripDigi-
0016 /// e.g. 1-16 for ganged ME1a, and with any readout flips already removed)
0017 
0018 float CSCRecoConditions::pedestal(const CSCDetId& id, int geomChannel) const {
0019   LogTrace("CSCRecoConditions") << id << " geomChannel " << geomChannel << " pedestal "
0020                                 << theConditions.pedestal(id, geomChannel);
0021   return theConditions.pedestal(id, geomChannel);
0022 }
0023 
0024 float CSCRecoConditions::pedestalSigma(const CSCDetId& id, int geomChannel) const {
0025   return theConditions.pedestalSigma(id, geomChannel);
0026 }
0027 
0028 float CSCRecoConditions::gain(const CSCDetId& id, int geomChannel) const {
0029   LogTrace("CSCRecoConditions") << id << " geomChannel " << geomChannel << " gain "
0030                                 << theConditions.gain(id, geomChannel);
0031   return theConditions.gain(id, geomChannel);
0032 }
0033 
0034 /// All other functions are accessed by geometrical strip label (i.e. strip number according to local coordinates)
0035 
0036 float CSCRecoConditions::chipCorrection(const CSCDetId& id, int geomStrip) const {
0037   // geometric strip to geometric channel (e.g. ME1a, 1-48->1-16 ganged or 1-48 unganged)
0038   int geomChannel = theConditions.channelFromStrip(id, geomStrip);
0039   return theConditions.chipCorrection(id, geomChannel);
0040 }
0041 
0042 //  stripWeights is required in CSCHitFromStripOnly.
0043 // - Has nstrips in arg list because caller already has this value from CSCChamberSpecs.
0044 // - We only have gains per geometric channel of course, and we only apply them by channel too
0045 // (in CSCHitFromStripOnly), but we may as well fill values for each strip.
0046 
0047 void CSCRecoConditions::stripWeights(const CSCDetId& id, short int nstrips, float* weights) const {
0048   for (short int i = 1; i < nstrips + 1; ++i) {
0049     weights[i - 1] = stripWeight(id, i);
0050   }
0051 }
0052 
0053 //  Calculate weight as 1/(gain/average gain)
0054 //  Input is offline CSCDetId (e.g. ir=4 for ME1A), and geom strip # (e.g. 1-48 for ME1A)
0055 
0056 float CSCRecoConditions::stripWeight(const CSCDetId& id, int geomStrip) const {
0057   int geomChannel = theConditions.channelFromStrip(id, geomStrip);
0058   float w = averageGain() / gain(id, geomChannel);  // averageGain() from CSCConditions
0059   // Weights are forced to lie within 0.5 and 1.5
0060   if (w > 1.5)
0061     w = 1.5;
0062   if (w < 0.5)
0063     w = 0.5;
0064   LogTrace("CSCRecoConditions") << id << " geomStrip " << geomStrip << " stripWeight " << w;
0065   return w;
0066 }
0067 
0068 void CSCRecoConditions::noiseMatrix(const CSCDetId& id, int geomStrip, std::vector<float>& nMatrix) const {
0069   // nMatrix will be filled with expanded noise matrix elements for strip 'geomStrip' and its immediate neighbours
0070 
0071   nMatrix.clear();
0072 
0073   // These are ME1/2 constants as fall-back
0074   const float fakeme12[15] = {8.64, 3.47, 2.45, 8.60, 3.28, 1.88, 8.61, 3.18, 1.99, 7.67, 2.64, 0., 7.71, 0., 0.};
0075 
0076   float elem[15];
0077 
0078   for (short int i = geomStrip - 1; i < geomStrip + 2; ++i) {
0079     std::vector<float> me(12);
0080 
0081     float w = stripWeight(id, i);
0082     w = w * w;
0083     int geomChannel = theConditions.channelFromStrip(id, i);
0084     theConditions.noiseMatrixElements(id, geomChannel, me);
0085     for (short int j = 0; j < 11; ++j) {
0086       elem[j] = me[j] * w;
0087     }
0088     elem[11] = 0.;
0089     elem[12] = me[11] * w;
0090     elem[13] = 0.;
0091     elem[14] = 0.;
0092 
0093     // Test that elements make sense:
0094     bool isFlawed = false;
0095     for (short int k = 0; k < 15; ++k) {
0096       if (elem[k] < 0.001)
0097         elem[k] = 0.001;  // fix if too small...
0098       if (elem[k] > 50.)
0099         isFlawed = true;  // fail if too big...
0100     }
0101 
0102     if (isFlawed) {
0103       // These are fake ME1/2:
0104       for (short int m = 0; m < 15; ++m) {
0105         elem[m] = fakeme12[m];
0106       }
0107     }
0108 
0109     for (int k = 0; k < 15; ++k) {
0110       nMatrix.push_back(elem[k]);
0111     }
0112   }
0113 }
0114 
0115 void CSCRecoConditions::crossTalk(const CSCDetId& id, int geomStrip, std::vector<float>& xtalks) const {
0116   // xtalks will be filled with crosstalk for geomStrip and its immediate neighbours
0117 
0118   xtalks.clear();
0119 
0120   for (short int i = geomStrip - 1; i < geomStrip + 2; ++i) {
0121     int geomChannel = theConditions.channelFromStrip(id, i);
0122     std::vector<float> ct(4);
0123     theConditions.crossTalk(id, geomChannel, ct);
0124     xtalks.push_back(ct[0]);
0125     xtalks.push_back(ct[1]);
0126     xtalks.push_back(ct[2]);
0127     xtalks.push_back(ct[3]);
0128   }
0129 }
0130 
0131 ///  Is an immediate neighbour a bad strip?
0132 bool CSCRecoConditions::nearBadStrip(const CSCDetId& id, int geomStrip, int nstrips) const {
0133   bool nearBad = (badStrip(id, geomStrip - 1, nstrips) || badStrip(id, geomStrip + 1, nstrips));
0134   return nearBad;
0135 }
0136 
0137 /// Is strip itself a bad strip?
0138 bool CSCRecoConditions::badStrip(const CSCDetId& id, int geomStrip, int nstrips) const {
0139   // input nstrips is no. of strips in the layer (could get this from CSCChamberSpecs or CSCLayerGeometry
0140   // but then need a CSCLayer*)
0141 
0142   bool bad = true;  // if geomStrip out of range, call strip bad
0143 
0144   if (id != theConditions.idOfBadChannelWords()) {
0145     bad = false;  // if bad channel words for this id not filled, call strip good
0146     return bad;
0147   }
0148 
0149   if (geomStrip > 0 && geomStrip <= nstrips) {
0150     bad = false;  // default to good
0151     int geomChan = theConditions.channelFromStrip(id, geomStrip);
0152     int rawChan = theConditions.rawStripChannel(id, geomChan);
0153     if (rawChan > 0 && rawChan < 113) {
0154       const std::bitset<112>& badStrips = theConditions.badStripWord();
0155       bad = badStrips.test(rawChan - 1);  // 112 bits max, labelled 0-111.
0156     }
0157   }
0158   return bad;
0159 }
0160 
0161 /// Get bad wiregroup word
0162 const std::bitset<112>& CSCRecoConditions::badWireWord(const CSCDetId& id) const { return theConditions.badWireWord(); }
0163 
0164 float CSCRecoConditions::chamberTimingCorrection(const CSCDetId& id) const {
0165   return theConditions.chamberTimingCorrection(id);
0166 }
0167 
0168 float CSCRecoConditions::anodeBXoffset(const CSCDetId& id) const { return theConditions.anodeBXoffset(id); }
0169 
0170 float CSCRecoConditions::gasGainCorrection(const CSCDetId& id, int geomStrip, int wiregroup) const {
0171   int geomChannel = theConditions.channelFromStrip(id, geomStrip);
0172   return theConditions.gasGainCorrection(id, geomChannel, wiregroup);
0173 }