00001 #include <RecoLocalMuon/CSCRecHitD/src/CSCRecoConditions.h>
00002 #include <CondFormats/CSCObjects/interface/CSCChannelTranslator.h>
00003 #include <iostream>
00004
00005 CSCRecoConditions::CSCRecoConditions( const edm::ParameterSet & ps ) : theConditions( ps ) {
00006 }
00007
00008 CSCRecoConditions::~CSCRecoConditions() {
00009 }
00010
00011 void CSCRecoConditions::initializeEvent( const edm::EventSetup& es ) {
00012 theConditions.initializeEvent( es );
00013 }
00014
00015
00016 float CSCRecoConditions::gain(const CSCDetId & id, int channel) const {
00017 CSCChannelTranslator translate;
00018 CSCDetId idraw = translate.rawCSCDetId( id );
00019 int iraw = translate.rawStripChannel( id, channel );
00020 return theConditions.gain(idraw, iraw);
00021 }
00022
00023 float CSCRecoConditions::pedestal(const CSCDetId & id, int channel) const {
00024 CSCChannelTranslator translate;
00025 CSCDetId idraw = translate.rawCSCDetId( id );
00026 int iraw = translate.rawStripChannel( id, channel );
00027 return theConditions.pedestal(idraw, iraw);
00028 }
00029
00030 float CSCRecoConditions::pedestalSigma(const CSCDetId & id, int channel) const {
00031 CSCChannelTranslator translate;
00032 CSCDetId idraw = translate.rawCSCDetId( id );
00033 int iraw = translate.rawStripChannel( id, channel );
00034 return theConditions.pedestalSigma(idraw, iraw);
00035 }
00036
00037 float CSCRecoConditions::chipCorrection(const CSCDetId & id, int geomStrip) const {
00038
00039 CSCChannelTranslator translate;
00040
00041 CSCDetId idraw = translate.rawCSCDetId( id );
00042
00043 int geomChannel = translate.channelFromStrip( id, geomStrip );
00044
00045
00046 int iraw = translate.rawStripChannel( id, geomChannel);
00047
00048 return theConditions.chipCorrection(idraw, iraw);
00049 }
00050
00051 float CSCRecoConditions::chamberTimingCorrection(const CSCDetId & id) const {
00052 CSCChannelTranslator translate;
00053
00054 CSCDetId idraw = translate.rawCSCDetId( id );
00055 return theConditions.chamberTimingCorrection(idraw);
00056 }
00057
00058 float CSCRecoConditions::anodeBXoffset(const CSCDetId & id) const {
00059 CSCChannelTranslator translate;
00060
00061 CSCDetId idraw = translate.rawCSCDetId( id );
00062 return theConditions.anodeBXoffset(idraw);
00063 }
00064
00065 void CSCRecoConditions::stripWeights( const CSCDetId& id, float* weights ) const {
00066
00067 short int is = id.station();
00068 short int ir = id.ring();
00069
00070 short int strip1 = 1;
00071 short int nStrips = 80;
00072 if ( is == 1 && ir == 1) nStrips = 64;
00073 if ( is == 1 && ir == 3) nStrips = 64;
00074
00075 if ( ir == 4 ) {
00076 const CSCDetId testId( id.endcap(), 1, 1, id.chamber(), id.layer() );
00077 strip1 = 65;
00078 for ( short int i = 0; i < 16; ++i) {
00079 float w = stripWeight(testId, strip1+i);
00080
00081
00082 weights[i] = w;
00083 weights[i+16] = w;
00084 weights[i+32] = w;
00085 }
00086 }
00087 else {
00088 for ( short int i = 0; i < nStrips; ++i) {
00089 weights[i] = stripWeight(id, strip1+i);
00090 }
00091 }
00092 }
00093
00094 void CSCRecoConditions::noiseMatrix( const CSCDetId& id, int centralStrip, std::vector<float>& nMatrix ) const {
00095
00096
00097
00098 nMatrix.clear();
00099
00100
00101
00102 float elem[15];
00103 elem[0] = 8.64;
00104 elem[1] = 3.47;
00105 elem[2] = 2.45;
00106 elem[3] = 8.60;
00107 elem[4] = 3.28;
00108 elem[5] = 1.88;
00109 elem[6] = 8.61;
00110 elem[7] = 3.18;
00111 elem[8] = 1.99;
00112 elem[9] = 7.67;
00113 elem[10] = 2.64;
00114 elem[11] = 0.;
00115 elem[12] = 7.71;
00116 elem[13] = 0.;
00117 elem[14] = 0.;
00118
00119 short int strip1 = centralStrip;
00120 short int triplet[3];
00121 bool isME1a = (id.ring()==4);
00122 CSCDetId id1;
00123
00124
00125
00126 if ( isME1a ) {
00127
00128 strip1 = centralStrip%16;
00129 if (strip1 == 0) strip1 = 16;
00130 strip1 += 64;
00131 id1=CSCDetId( id.endcap(), 1, 1, id.chamber(), id.layer() );
00132
00133 if (strip1 == 65) {
00134 triplet[0]=80;
00135 triplet[1]=65;
00136 triplet[2]=66;
00137 } else if (strip1 == 80) {
00138 triplet[0]=79;
00139 triplet[1]=80;
00140 triplet[2]=65;
00141 } else {
00142 triplet[0]=strip1-1;
00143 triplet[1]=strip1;
00144 triplet[2]=strip1+1;
00145
00146 }
00147 }
00148 else {
00149 triplet[0]=strip1-1;
00150 triplet[1]=strip1;
00151 triplet[2]=strip1+1;
00152 }
00153
00154 for ( short int i = 0; i < 3; ++i) {
00155
00156 short int channel = triplet[i];
00157 float w;
00158 std::vector<float> me(12);
00159
00160 if ( isME1a ) {
00161 w = stripWeight(id1, channel);
00162 theConditions.noiseMatrixElements(id1, channel, me);
00163 }
00164 else {
00165 w = stripWeight(id, channel);
00166 theConditions.noiseMatrixElements(id, channel, me);
00167 }
00168 w = w*w;
00169 for ( short int j=0; j<11; ++j ) {
00170 elem[j] = me[j] * w;
00171 }
00172 elem[11]= 0.;
00173 elem[12]= me[11] * w;
00174 elem[13]= 0.;
00175 elem[14]= 0.;
00176
00177
00178 bool isFlawed = false;
00179 for ( int k = 0; k < 15; ++k) {
00180
00181 if (elem[k] < 0.001) elem[k] = 0.001;
00182
00183 if (elem[k] > 50.) isFlawed = true;
00184 }
00185
00186 if ( isFlawed ) {
00187
00188 elem[0] = 8.64;
00189 elem[1] = 3.47;
00190 elem[2] = 2.45;
00191 elem[3] = 8.60;
00192 elem[4] = 3.28;
00193 elem[5] = 1.88;
00194 elem[6] = 8.61;
00195 elem[7] = 3.18;
00196 elem[8] = 1.99;
00197 elem[9] = 7.67;
00198 elem[10] = 2.64;
00199 elem[11] = 0.;
00200 elem[12] = 7.71;
00201 elem[13] = 0.;
00202 elem[14] = 0.;
00203 }
00204
00205 for (int k = 0; k < 15; ++k) nMatrix.push_back( elem[k] );
00206 }
00207 }
00208
00209 void CSCRecoConditions::crossTalk( const CSCDetId& id, int centralStrip, std::vector<float>& xtalks) const {
00210
00211 xtalks.clear();
00212
00213 short int strip1 = centralStrip;
00214 short int triplet[3];
00215 bool isME1a = (id.ring()==4);
00216 CSCDetId id1;
00217
00218
00219
00220 if ( isME1a ) {
00221
00222 strip1 = centralStrip%16;
00223 if (strip1 == 0) strip1 = 16;
00224 strip1 += 64;
00225 id1=CSCDetId( id.endcap(), 1, 1, id.chamber(), id.layer() );
00226
00227 if (strip1 == 65) {
00228 triplet[0]=80;
00229 triplet[1]=65;
00230 triplet[2]=66;
00231 } else if (strip1 == 80) {
00232 triplet[0]=79;
00233 triplet[1]=80;
00234 triplet[2]=65;
00235 } else {
00236 triplet[0]=strip1-1;
00237 triplet[1]=strip1;
00238 triplet[2]=strip1+1;
00239 }
00240 }
00241 else {
00242 triplet[0]=strip1-1;
00243 triplet[1]=strip1;
00244 triplet[2]=strip1+1;
00245 }
00246
00247
00248 short int idx = 0;
00249 for ( short int i = 0; i < 3; ++i) {
00250
00251 short int channel = triplet[i];
00252 std::vector<float> ct(4);
00253
00254 if ( isME1a ) {
00255 theConditions.crossTalk(id1, channel, ct);
00256 }
00257 else {
00258 theConditions.crossTalk(id, channel, ct);
00259 }
00260
00261 xtalks.push_back(ct[0]);
00262 xtalks.push_back(ct[1]);
00263 xtalks.push_back(ct[2]);
00264 xtalks.push_back(ct[3]);
00265 ++idx;
00266 }
00267 }
00268
00272
00273 bool CSCRecoConditions::nearBadStrip( const CSCDetId& id, int geomStrip ) const {
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289 bool nearBad = (badStrip(id,geomStrip-1) || badStrip(id,geomStrip+1));
00290
00291
00292 return nearBad;
00293 }
00294
00296
00297 bool CSCRecoConditions::badStrip( const CSCDetId& id, int geomStrip ) const {
00298
00299 bool aBadS = false;
00300 if(geomStrip>0 && geomStrip<81){
00301 CSCChannelTranslator translate;
00302 CSCDetId idraw = translate.rawCSCDetId( id );
00303 int geomChan = translate.channelFromStrip( id, geomStrip );
00304 int rawChan = translate.rawStripChannel( id, geomChan );
00305
00306 const std::bitset<80>& badStrips = theConditions.badStripWord(idraw);
00307
00308 if( rawChan>0 && rawChan<81 ){
00309 aBadS = badStrips.test(rawChan-1);
00310 }
00311 }
00312 return aBadS;
00313 }
00314
00316 const std::bitset<112>& CSCRecoConditions::badWireWord( const CSCDetId& id ) const {
00317 return theConditions.badWireWord( id );
00318 }
00319
00320
00321 float CSCRecoConditions::stripWeight( const CSCDetId& id, int channel ) const {
00322 float w = averageGain() / theConditions.gain(id, channel);
00323
00324
00325 if (w > 1.5) w = 1.5;
00326 if (w < 0.5) w = 0.5;
00327 return w;
00328 }
00329
00330 float CSCRecoConditions::gasGainCorrection(const CSCDetId & id, int geomStrip, int wire ) const {
00331
00332 CSCChannelTranslator translate;
00333
00334 CSCDetId idraw = translate.rawCSCDetId( id );
00335
00336 int geomChannel = translate.channelFromStrip( id, geomStrip );
00337
00338
00339 int iraw = translate.rawStripChannel( id, geomChannel);
00340
00341 return theConditions.gasGainCorrection(idraw, iraw, wire);
00342 }
00343