CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/RecoLocalMuon/CSCRecHitD/src/CSCRecoConditions.cc

Go to the documentation of this file.
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   //printf("RecoCondition before translation e:%d s:%d r:%d c:%d l:%d strip:%d \n",id.endcap(),id.station(), id.ring(),id.chamber(),id.layer(),geomStrip);
00039   CSCChannelTranslator translate;
00040   // If ME1/4, set ring = 1
00041   CSCDetId idraw = translate.rawCSCDetId( id );
00042   // If ME1/4, collapse 48 chips into 16 electronics channel (1-48) -> (1-16)
00043   int geomChannel = translate.channelFromStrip( id, geomStrip );
00044   // Translate geometry-oriented strip channels into raw channels 
00045   // reordering ME+1/1a and ME-1/1b and moving ME1/1a (1-16)->(65-80)
00046   int iraw = translate.rawStripChannel( id, geomChannel);
00047   //printf("RecoCondition after  translation e:%d s:%d r:%d c:%d l:%d strip:%d \n",idraw.endcap(),idraw.station(), idraw.ring(),idraw.chamber(),idraw.layer(),iraw);
00048   return theConditions.chipCorrection(idraw, iraw);
00049 }
00050 
00051 float CSCRecoConditions::chamberTimingCorrection(const CSCDetId & id) const { 
00052   CSCChannelTranslator translate;
00053   // If ME1/4, set ring = 1
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   // If ME1/4, set ring = 1
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; // ME1b
00073   if ( is == 1 && ir == 3) nStrips = 64; // ME13
00074 
00075   if ( ir == 4 ) { // ME1a
00076     const CSCDetId testId( id.endcap(), 1, 1, id.chamber(), id.layer() ); // create ME11 detId
00077     strip1 = 65; // ME1a channels are 65-80 in ME11
00078     for ( short int i = 0; i < 16; ++i) {
00079       float w = stripWeight(testId, strip1+i);
00080 
00081       // Unfold ganged channels in ME1a
00082       weights[i]    = w;
00083       weights[i+16] = w;
00084       weights[i+32] = w;
00085     }
00086   } 
00087   else { // non-ME1a chambers
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   // nMatrix will be filled with expanded noise matrix elements for 
00097   // channel 'centralStrip' and its immediate neighbours
00098   nMatrix.clear();
00099 
00100   // Initialize values in case we can't find chamber with constants
00101   // These are ME1/2 constants...
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   // ME1/a constants are stored in channels 65-80 of ME11, ME1/b in channels 1-64.
00125   // ME1/a channels are ganged - 48 strips to 16 channels.
00126   if ( isME1a ) { // ME1a
00127 
00128     strip1 = centralStrip%16;     // strip#   1-48
00129     if (strip1 == 0) strip1 = 16; // channel# 1-16
00130     strip1 += 64;                 // strip1   65-80
00131     id1=CSCDetId( id.endcap(), 1, 1, id.chamber(), id.layer() ); // ME11 detId
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 { // non-ME1a
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     // Test that elements make sense:
00178     bool isFlawed = false;      
00179     for ( int k = 0; k < 15; ++k) {
00180       // make sure the number isn't too close to zero...
00181       if (elem[k] < 0.001) elem[k] = 0.001;
00182       // make sure the number isn't too big...
00183       if (elem[k] > 50.) isFlawed = true; 
00184     }
00185 
00186     if ( isFlawed ) {
00187       // These are fake ME1/2:
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   // ME1/a constants are stored in channels 65-80 of ME11, ME1/b in channels 1-64.
00219   // ME1/a channels are ganged - 48 strips to 16 channels.
00220   if ( isME1a ) { // ME1a
00221 
00222     strip1 = centralStrip%16;     // strip#   1-48
00223     if (strip1 == 0) strip1 = 16; // channel# 1-16
00224     strip1 += 64;                 // strip1   65-80
00225     id1=CSCDetId( id.endcap(), 1, 1, id.chamber(), id.layer() ); // ME11 detId
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 { // non-ME1a
00242       triplet[0]=strip1-1;
00243       triplet[1]=strip1;
00244       triplet[2]=strip1+1;
00245   }
00246 
00247   // For 3 neighbouring strips get crosstalks
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   // Note ME1A strip runs 1-48 
00275   /*
00276   CSCChannelTranslator translate;
00277   CSCDetId idraw = translate.rawCSCDetId( id );
00278   int geomChan = translate.channelFromStrip( id, geomStrip ); 
00279   int rawChan = translate.rawStripChannel( id, geomChan ); 
00280 
00281   const std::bitset<80>& badStrips = theConditions.badStripWord(idraw);
00282 
00283   bool nearBad = false;
00284   if( rawChan>1 && rawChan<80 ){ // 80 bits max, labelled 0-79. Test 1-78 for neighbours.
00285     nearBad = (badStrips.test(rawChan) || badStrips.test(rawChan-2));
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   // Note ME1A strip runs 1-48 
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 ){ // 80 bits max, labelled 0-79. Test 0-79 (i.e. any - that's the idea)
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 // This expects raw ME11 detId for ME1b (channels 1-64) & for ME1a (channels 65-80)
00321 float CSCRecoConditions::stripWeight( const CSCDetId& id, int channel ) const {
00322    float w = averageGain() / theConditions.gain(id, channel);
00323   
00324    // Weights are forced to lie within 0.5 and 1.5
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   //printf("RecoCondition before translation e:%d s:%d r:%d c:%d l:%d strip:%d wire:%d \n",id.endcap(),id.station(), id.ring(),id.chamber(),id.layer(),geomStrip,wire);
00332   CSCChannelTranslator translate;
00333   // If ME1/4, set ring = 1
00334   CSCDetId idraw = translate.rawCSCDetId( id );
00335   // If ME1/4, collapse 48 chips into 16 electronics channel (1-48) -> (1-16)
00336   int geomChannel = translate.channelFromStrip( id, geomStrip );
00337   // Translate geometry-oriented strip channels into raw channels 
00338   // reordering ME+1/1a and ME-1/1b and moving ME1/1a (1-16)->(65-80)
00339   int iraw = translate.rawStripChannel( id, geomChannel);
00340   //printf("RecoCondition after  translation e:%d s:%d r:%d c:%d l:%d strip:%d \n",idraw.endcap(),idraw.station(), idraw.ring(),idraw.chamber(),idraw.layer(),iraw);
00341   return theConditions.gasGainCorrection(idraw, iraw, wire);
00342 }
00343