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 void CSCRecoConditions::stripWeights( const CSCDetId& id, float* weights ) const {
00038
00039 short int is = id.station();
00040 short int ir = id.ring();
00041
00042 short int strip1 = 1;
00043 short int nStrips = 80;
00044 if ( is == 1 && ir == 1) nStrips = 64;
00045 if ( is == 1 && ir == 3) nStrips = 64;
00046
00047 if ( ir == 4 ) {
00048 const CSCDetId testId( id.endcap(), 1, 1, id.chamber(), id.layer() );
00049 strip1 = 65;
00050 for ( short int i = 0; i < 16; ++i) {
00051 float w = stripWeight(testId, strip1+i);
00052
00053
00054 weights[i] = w;
00055 weights[i+16] = w;
00056 weights[i+32] = w;
00057 }
00058 }
00059 else {
00060 for ( short int i = 0; i < nStrips; ++i) {
00061 weights[i] = stripWeight(id, strip1+i);
00062 }
00063 }
00064 }
00065
00066 void CSCRecoConditions::noiseMatrix( const CSCDetId& id, int centralStrip, std::vector<float>& nMatrix ) const {
00067
00068
00069
00070 nMatrix.clear();
00071
00072
00073
00074 float elem[15];
00075 elem[0] = 8.64;
00076 elem[1] = 3.47;
00077 elem[2] = 2.45;
00078 elem[3] = 8.60;
00079 elem[4] = 3.28;
00080 elem[5] = 1.88;
00081 elem[6] = 8.61;
00082 elem[7] = 3.18;
00083 elem[8] = 1.99;
00084 elem[9] = 7.67;
00085 elem[10] = 2.64;
00086 elem[11] = 0.;
00087 elem[12] = 7.71;
00088 elem[13] = 0.;
00089 elem[14] = 0.;
00090
00091 short int strip1 = centralStrip;
00092 short int triplet[3];
00093 bool isME1a = (id.ring()==4);
00094 CSCDetId id1;
00095
00096
00097
00098 if ( isME1a ) {
00099
00100 strip1 = centralStrip%16;
00101 if (strip1 == 0) strip1 = 16;
00102 strip1 += 64;
00103 id1=CSCDetId( id.endcap(), 1, 1, id.chamber(), id.layer() );
00104
00105 if (strip1 == 65) {
00106 triplet[0]=80;
00107 triplet[1]=65;
00108 triplet[2]=66;
00109 } else if (strip1 == 80) {
00110 triplet[0]=79;
00111 triplet[1]=80;
00112 triplet[2]=65;
00113 } else {
00114 triplet[0]=strip1-1;
00115 triplet[1]=strip1;
00116 triplet[2]=strip1+1;
00117
00118 }
00119 }
00120 else {
00121 triplet[0]=strip1-1;
00122 triplet[1]=strip1;
00123 triplet[2]=strip1+1;
00124 }
00125
00126 for ( short int i = 0; i < 3; ++i) {
00127
00128 short int channel = triplet[i];
00129 float w;
00130 std::vector<float> me(12);
00131
00132 if ( isME1a ) {
00133 w = stripWeight(id1, channel);
00134 theConditions.noiseMatrixElements(id1, channel, me);
00135 }
00136 else {
00137 w = stripWeight(id, channel);
00138 theConditions.noiseMatrixElements(id, channel, me);
00139 }
00140 w = w*w;
00141 for ( short int j=0; j<11; ++j ) {
00142 elem[j] = me[j] * w;
00143 }
00144 elem[11]= 0.;
00145 elem[12]= me[11] * w;
00146 elem[13]= 0.;
00147 elem[14]= 0.;
00148
00149
00150 bool isFlawed = false;
00151 for ( int k = 0; k < 15; ++k) {
00152
00153 if (elem[k] < 0.001) elem[k] = 0.001;
00154
00155 if (elem[k] > 50.) isFlawed = true;
00156 }
00157
00158 if ( isFlawed ) {
00159
00160 elem[0] = 8.64;
00161 elem[1] = 3.47;
00162 elem[2] = 2.45;
00163 elem[3] = 8.60;
00164 elem[4] = 3.28;
00165 elem[5] = 1.88;
00166 elem[6] = 8.61;
00167 elem[7] = 3.18;
00168 elem[8] = 1.99;
00169 elem[9] = 7.67;
00170 elem[10] = 2.64;
00171 elem[11] = 0.;
00172 elem[12] = 7.71;
00173 elem[13] = 0.;
00174 elem[14] = 0.;
00175 }
00176
00177 for (int k = 0; k < 15; ++k) nMatrix.push_back( elem[k] );
00178 }
00179 }
00180
00181 void CSCRecoConditions::crossTalk( const CSCDetId& id, int centralStrip, std::vector<float>& xtalks) const {
00182
00183 xtalks.clear();
00184
00185 short int strip1 = centralStrip;
00186 short int triplet[3];
00187 bool isME1a = (id.ring()==4);
00188 CSCDetId id1;
00189
00190
00191
00192 if ( isME1a ) {
00193
00194 strip1 = centralStrip%16;
00195 if (strip1 == 0) strip1 = 16;
00196 strip1 += 64;
00197 id1=CSCDetId( id.endcap(), 1, 1, id.chamber(), id.layer() );
00198
00199 if (strip1 == 65) {
00200 triplet[0]=80;
00201 triplet[1]=65;
00202 triplet[2]=66;
00203 } else if (strip1 == 80) {
00204 triplet[0]=79;
00205 triplet[1]=80;
00206 triplet[2]=65;
00207 } else {
00208 triplet[0]=strip1-1;
00209 triplet[1]=strip1;
00210 triplet[2]=strip1+1;
00211 }
00212 }
00213 else {
00214 triplet[0]=strip1-1;
00215 triplet[1]=strip1;
00216 triplet[2]=strip1+1;
00217 }
00218
00219
00220 short int idx = 0;
00221 for ( short int i = 0; i < 3; ++i) {
00222
00223 short int channel = triplet[i];
00224 std::vector<float> ct(4);
00225
00226 if ( isME1a ) {
00227 theConditions.crossTalk(id1, channel, ct);
00228 }
00229 else {
00230 theConditions.crossTalk(id, channel, ct);
00231 }
00232
00233 xtalks.push_back(ct[0]);
00234 xtalks.push_back(ct[1]);
00235 xtalks.push_back(ct[2]);
00236 xtalks.push_back(ct[3]);
00237 ++idx;
00238 }
00239 }
00240
00244
00245 bool CSCRecoConditions::nearBadStrip( const CSCDetId& id, int geomStrip ) const {
00246
00247 CSCChannelTranslator translate;
00248 CSCDetId idraw = translate.rawCSCDetId( id );
00249 int geomChan = translate.channelFromStrip( id, geomStrip );
00250 int rawChan = translate.rawStripChannel( id, geomChan );
00251
00252 const std::bitset<80>& badStrips = theConditions.badStripWord(idraw);
00253
00254 bool nearBad = false;
00255 if( rawChan>1 && rawChan<80 ){
00256 nearBad = (badStrips.test(rawChan) || badStrips.test(rawChan-2));
00257 }
00258 return nearBad;
00259 }
00260
00262 const std::bitset<112>& CSCRecoConditions::badWireWord( const CSCDetId& id ) const {
00263 return theConditions.badWireWord( id );
00264 }
00265
00266
00267 float CSCRecoConditions::stripWeight( const CSCDetId& id, int channel ) const {
00268 float w = averageGain() / theConditions.gain(id, channel);
00269
00270
00271 if (w > 1.5) w = 1.5;
00272 if (w < 0.5) w = 0.5;
00273 return w;
00274 }