00001 #include <RecoLocalMuon/CSCRecHitD/src/CSCRecoConditions.h>
00002 #include <CondFormats/CSCObjects/interface/CSCChannelTranslator.h>
00003 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00004 #include <iostream>
00005
00006 CSCRecoConditions::CSCRecoConditions( const edm::ParameterSet & ps ) : theConditions( ps ) {
00007 }
00008
00009 CSCRecoConditions::~CSCRecoConditions() {
00010 }
00011
00012 void CSCRecoConditions::initializeEvent( const edm::EventSetup& es ) {
00013 theConditions.initializeEvent( es );
00014 }
00015
00017
00018 float CSCRecoConditions::pedestal(const CSCDetId& id, int channel) const {
00019 CSCChannelTranslator translate;
00020 CSCDetId idraw = translate.rawCSCDetId( id );
00021 int iraw = translate.rawStripChannel( id, channel );
00022 LogTrace("CSCRecoConditions") << id << " channel " << channel << " raw channel " << iraw << " pedestal " << theConditions.pedestal(idraw, iraw);
00023 return theConditions.pedestal(idraw, iraw);
00024 }
00025
00026 float CSCRecoConditions::pedestalSigma(const CSCDetId& id, int channel) const {
00027 CSCChannelTranslator translate;
00028 CSCDetId idraw = translate.rawCSCDetId( id );
00029 int iraw = translate.rawStripChannel( id, channel );
00030 return theConditions.pedestalSigma(idraw, iraw);
00031 }
00032
00034
00035 float CSCRecoConditions::gain(const CSCDetId& id, int geomStrip) const {
00036 CSCChannelTranslator translate;
00037 CSCDetId idraw = translate.rawCSCDetId( id );
00038 int geomChannel = translate.channelFromStrip( id, geomStrip );
00039 int iraw = translate.rawStripChannel( id, geomChannel );
00040 LogTrace("CSCRecoConditions") << id << " geomStrip " << geomStrip << " raw channel " << iraw << " gain " << theConditions.gain(idraw, iraw);
00041 return theConditions.gain(idraw, iraw);
00042 }
00043
00044 float CSCRecoConditions::chipCorrection(const CSCDetId & id, int geomStrip) const {
00045 CSCChannelTranslator translate;
00046 CSCDetId idraw = translate.rawCSCDetId( id );
00047 int geomChannel = translate.channelFromStrip( id, geomStrip );
00048 int iraw = translate.rawStripChannel( id, geomChannel);
00049 return theConditions.chipCorrection(idraw, iraw);
00050 }
00051
00052
00053
00054
00055 void CSCRecoConditions::stripWeights( const CSCDetId& id, short int nstrips, float* weights ) const {
00056
00057 for ( short int i = 1; i < nstrips+1; ++i) {
00058 weights[i-1] = stripWeight(id, i) ;
00059 }
00060 }
00061
00062
00063
00064
00065 float CSCRecoConditions::stripWeight( const CSCDetId& id, int geomStrip ) const {
00066 float w = averageGain() / gain(id, geomStrip);
00067
00068 if (w > 1.5) w = 1.5;
00069 if (w < 0.5) w = 0.5;
00070 LogTrace("CSCRecoConditions") << id << " geomStrip " << geomStrip << " stripWeight " << w;
00071 return w;
00072 }
00073 void CSCRecoConditions::noiseMatrix( const CSCDetId& id, int centralStrip, std::vector<float>& nMatrix ) const {
00074
00075
00076
00077 nMatrix.clear();
00078
00079
00080 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.};
00081
00082 float elem[15];
00083 CSCChannelTranslator translate;
00084
00085 for ( short int i = centralStrip-1; i < centralStrip+2; ++i) {
00086
00087 std::vector<float> me(12);
00088
00089 float w = stripWeight(id, i);
00090 w = w*w;
00091 CSCDetId idraw = translate.rawCSCDetId( id );
00092 int geomChannel = translate.channelFromStrip( id, i );
00093 int iraw = translate.rawStripChannel( id, geomChannel);
00094 theConditions.noiseMatrixElements(idraw, iraw, me);
00095 for ( short int j=0; j<11; ++j ) {
00096 elem[j] = me[j] * w;
00097 }
00098 elem[11]= 0.;
00099 elem[12]= me[11] * w;
00100 elem[13]= 0.;
00101 elem[14]= 0.;
00102
00103
00104 bool isFlawed = false;
00105 for ( short int k = 0; k < 15; ++k) {
00106 if (elem[k] < 0.001) elem[k] = 0.001;
00107 if (elem[k] > 50.) isFlawed = true;
00108 }
00109
00110 if ( isFlawed ) {
00111
00112 for ( short int m = 0; m < 15; ++m ) { elem[m] = fakeme12[m]; }
00113 }
00114
00115 for (int k = 0; k < 15; ++k) { nMatrix.push_back( elem[k] ); }
00116 }
00117 }
00118
00119 void CSCRecoConditions::crossTalk( const CSCDetId& id, int centralStrip, std::vector<float>& xtalks) const {
00120
00121
00122
00123 xtalks.clear();
00124
00125 CSCChannelTranslator translate;
00126 for ( short int i = centralStrip-1; i < centralStrip+2; ++i) {
00127 CSCDetId idraw = translate.rawCSCDetId( id );
00128 int geomChannel = translate.channelFromStrip( id, i );
00129 int iraw = translate.rawStripChannel( id, geomChannel );
00130
00131 std::vector<float> ct(4);
00132 theConditions.crossTalk(idraw, iraw, ct);
00133 xtalks.push_back(ct[0]);
00134 xtalks.push_back(ct[1]);
00135 xtalks.push_back(ct[2]);
00136 xtalks.push_back(ct[3]);
00137 }
00138 }
00139
00141 bool CSCRecoConditions::nearBadStrip( const CSCDetId& id, int geomStrip ) const {
00142 bool nearBad = (badStrip(id,geomStrip-1) || badStrip(id,geomStrip+1));
00143 return nearBad;
00144 }
00146 bool CSCRecoConditions::badStrip( const CSCDetId& id, int geomStrip ) const {
00147 bool aBadS = false;
00148 if(geomStrip>0 && geomStrip<81){
00149 CSCChannelTranslator translate;
00150 CSCDetId idraw = translate.rawCSCDetId( id );
00151 int geomChan = translate.channelFromStrip( id, geomStrip );
00152 int rawChan = translate.rawStripChannel( id, geomChan );
00153
00154 const std::bitset<80>& badStrips = theConditions.badStripWord(idraw);
00155
00156 if( rawChan>0 && rawChan<81 ){
00157 aBadS = badStrips.test(rawChan-1);
00158
00159 }
00160 }
00161 return aBadS;
00162 }
00163
00165 const std::bitset<112>& CSCRecoConditions::badWireWord( const CSCDetId& id ) const {
00166 return theConditions.badWireWord( id );
00167 }
00168
00169 float CSCRecoConditions::chamberTimingCorrection(const CSCDetId & id) const {
00170 CSCChannelTranslator translate;
00171 CSCDetId idraw = translate.rawCSCDetId( id );
00172 return theConditions.chamberTimingCorrection(idraw);
00173 }
00174
00175 float CSCRecoConditions::anodeBXoffset(const CSCDetId & id) const {
00176 CSCChannelTranslator translate;
00177 CSCDetId idraw = translate.rawCSCDetId( id );
00178 return theConditions.anodeBXoffset(idraw);
00179 }
00180
00181 float CSCRecoConditions::gasGainCorrection(const CSCDetId & id, int geomStrip, int wire ) const {
00182 CSCChannelTranslator translate;
00183 CSCDetId idraw = translate.rawCSCDetId( id );
00184 int geomChannel = translate.channelFromStrip( id, geomStrip );
00185 int iraw = translate.rawStripChannel( id, geomChannel);
00186 return theConditions.gasGainCorrection(idraw, iraw, wire);
00187 }