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
00018
00019 float CSCRecoConditions::pedestal(const CSCDetId& id, int geomChannel) const {
00020 LogTrace("CSCRecoConditions") << id << " geomChannel " << geomChannel << " pedestal " << theConditions.pedestal(id, geomChannel);
00021 return theConditions.pedestal(id, geomChannel);
00022 }
00023
00024 float CSCRecoConditions::pedestalSigma(const CSCDetId& id, int geomChannel) const {
00025 return theConditions.pedestalSigma(id, geomChannel);
00026 }
00027
00028 float CSCRecoConditions::gain(const CSCDetId& id, int geomChannel) const {
00029 LogTrace("CSCRecoConditions") << id << " geomChannel " << geomChannel << " gain " << theConditions.gain(id, geomChannel);
00030 return theConditions.gain(id, geomChannel);
00031 }
00032
00034
00035 float CSCRecoConditions::chipCorrection(const CSCDetId & id, int geomStrip) const {
00036
00037 int geomChannel = theConditions.channelFromStrip( id, geomStrip );
00038 return theConditions.chipCorrection(id, geomChannel);
00039 }
00040
00041
00042
00043
00044
00045
00046 void CSCRecoConditions::stripWeights( const CSCDetId& id, short int nstrips, float* weights ) const {
00047
00048 for ( short int i = 1; i < nstrips+1; ++i) {
00049 weights[i-1] = stripWeight(id, i) ;
00050 }
00051 }
00052
00053
00054
00055
00056 float CSCRecoConditions::stripWeight( const CSCDetId& id, int geomStrip ) const {
00057 int geomChannel = theConditions.channelFromStrip( id, geomStrip );
00058 float w = averageGain() / gain(id, geomChannel);
00059
00060 if (w > 1.5) w = 1.5;
00061 if (w < 0.5) w = 0.5;
00062 LogTrace("CSCRecoConditions") << id << " geomStrip " << geomStrip << " stripWeight " << w;
00063 return w;
00064 }
00065
00066 void CSCRecoConditions::noiseMatrix( const CSCDetId& id, int geomStrip, std::vector<float>& nMatrix ) const {
00067
00068
00069
00070 nMatrix.clear();
00071
00072
00073 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.};
00074
00075 float elem[15];
00076
00077 for ( short int i = geomStrip-1; i < geomStrip+2; ++i) {
00078
00079 std::vector<float> me(12);
00080
00081 float w = stripWeight(id, i);
00082 w = w*w;
00083 int geomChannel = theConditions.channelFromStrip( id, i );
00084 theConditions.noiseMatrixElements(id, geomChannel, me);
00085 for ( short int j=0; j<11; ++j ) {
00086 elem[j] = me[j] * w;
00087 }
00088 elem[11]= 0.;
00089 elem[12]= me[11] * w;
00090 elem[13]= 0.;
00091 elem[14]= 0.;
00092
00093
00094 bool isFlawed = false;
00095 for ( short int k = 0; k < 15; ++k) {
00096 if (elem[k] < 0.001) elem[k] = 0.001;
00097 if (elem[k] > 50.) isFlawed = true;
00098 }
00099
00100 if ( isFlawed ) {
00101
00102 for ( short int m = 0; m < 15; ++m ) { elem[m] = fakeme12[m]; }
00103 }
00104
00105 for (int k = 0; k < 15; ++k) { nMatrix.push_back( elem[k] ); }
00106 }
00107 }
00108
00109 void CSCRecoConditions::crossTalk( const CSCDetId& id, int geomStrip, std::vector<float>& xtalks) const {
00110
00111
00112
00113 xtalks.clear();
00114
00115 for ( short int i = geomStrip-1; i < geomStrip+2; ++i) {
00116 int geomChannel = theConditions.channelFromStrip( id, i );
00117 std::vector<float> ct(4);
00118 theConditions.crossTalk(id, geomChannel, ct);
00119 xtalks.push_back(ct[0]);
00120 xtalks.push_back(ct[1]);
00121 xtalks.push_back(ct[2]);
00122 xtalks.push_back(ct[3]);
00123 }
00124 }
00125
00127 bool CSCRecoConditions::nearBadStrip( const CSCDetId& id, int geomStrip ) const {
00128 bool nearBad = (badStrip(id,geomStrip-1) || badStrip(id,geomStrip+1));
00129 return nearBad;
00130 }
00131
00133 bool CSCRecoConditions::badStrip( const CSCDetId& id, int geomStrip ) const {
00134
00135
00136 bool aBadS = false;
00137 if(geomStrip>0 && geomStrip<81){
00138 int geomChan = theConditions.channelFromStrip( id, geomStrip );
00139 const std::bitset<80>& badStrips = theConditions.badStripWord(id);
00140
00141 int rawChan = theConditions.rawStripChannel( id, geomChan );
00142 if( rawChan>0 && rawChan<81 ){
00143 aBadS = badStrips.test(rawChan-1);
00144
00145 }
00146 }
00147 return aBadS;
00148 }
00149
00151 const std::bitset<112>& CSCRecoConditions::badWireWord( const CSCDetId& id ) const {
00152 return theConditions.badWireWord( id );
00153 }
00154
00155 float CSCRecoConditions::chamberTimingCorrection(const CSCDetId & id) const {
00156 return theConditions.chamberTimingCorrection(id);
00157 }
00158
00159 float CSCRecoConditions::anodeBXoffset(const CSCDetId & id) const {
00160 return theConditions.anodeBXoffset(id);
00161 }
00162
00163 float CSCRecoConditions::gasGainCorrection(const CSCDetId & id, int geomStrip, int wiregroup ) const {
00164 int geomChannel = theConditions.channelFromStrip( id, geomStrip);
00165 return theConditions.gasGainCorrection(id, geomChannel, wiregroup);
00166 }