CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCRecoConditions.cc
Go to the documentation of this file.
3 #include <iostream>
4 
5 CSCRecoConditions::CSCRecoConditions( const edm::ParameterSet & ps ) : theConditions( ps ) {
6 }
7 
9 }
10 
13 }
14 
15 
16 float CSCRecoConditions::gain(const CSCDetId & id, int channel) const {
17  CSCChannelTranslator translate;
18  CSCDetId idraw = translate.rawCSCDetId( id );
19  int iraw = translate.rawStripChannel( id, channel );
20  return theConditions.gain(idraw, iraw);
21 }
22 
23 float CSCRecoConditions::pedestal(const CSCDetId & id, int channel) const {
24  CSCChannelTranslator translate;
25  CSCDetId idraw = translate.rawCSCDetId( id );
26  int iraw = translate.rawStripChannel( id, channel );
27  return theConditions.pedestal(idraw, iraw);
28 }
29 
30 float CSCRecoConditions::pedestalSigma(const CSCDetId & id, int channel) const {
31  CSCChannelTranslator translate;
32  CSCDetId idraw = translate.rawCSCDetId( id );
33  int iraw = translate.rawStripChannel( id, channel );
34  return theConditions.pedestalSigma(idraw, iraw);
35 }
36 
37 float CSCRecoConditions::chipCorrection(const CSCDetId & id, int geomStrip) const {
38  //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);
39  CSCChannelTranslator translate;
40  // If ME1/4, set ring = 1
41  CSCDetId idraw = translate.rawCSCDetId( id );
42  // If ME1/4, collapse 48 chips into 16 electronics channel (1-48) -> (1-16)
43  int geomChannel = translate.channelFromStrip( id, geomStrip );
44  // Translate geometry-oriented strip channels into raw channels
45  // reordering ME+1/1a and ME-1/1b and moving ME1/1a (1-16)->(65-80)
46  int iraw = translate.rawStripChannel( id, geomChannel);
47  //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);
48  return theConditions.chipCorrection(idraw, iraw);
49 }
50 
52  CSCChannelTranslator translate;
53  // If ME1/4, set ring = 1
54  CSCDetId idraw = translate.rawCSCDetId( id );
56 }
57 
58 float CSCRecoConditions::anodeBXoffset(const CSCDetId & id) const {
59  CSCChannelTranslator translate;
60  // If ME1/4, set ring = 1
61  CSCDetId idraw = translate.rawCSCDetId( id );
62  return theConditions.anodeBXoffset(idraw);
63 }
64 
65 void CSCRecoConditions::stripWeights( const CSCDetId& id, float* weights ) const {
66 
67  short int is = id.station();
68  short int ir = id.ring();
69 
70  short int strip1 = 1;
71  short int nStrips = 80;
72  if ( is == 1 && ir == 1) nStrips = 64; // ME1b
73  if ( is == 1 && ir == 3) nStrips = 64; // ME13
74 
75  if ( ir == 4 ) { // ME1a
76  const CSCDetId testId( id.endcap(), 1, 1, id.chamber(), id.layer() ); // create ME11 detId
77  strip1 = 65; // ME1a channels are 65-80 in ME11
78  for ( short int i = 0; i < 16; ++i) {
79  float w = stripWeight(testId, strip1+i);
80 
81  // Unfold ganged channels in ME1a
82  weights[i] = w;
83  weights[i+16] = w;
84  weights[i+32] = w;
85  }
86  }
87  else { // non-ME1a chambers
88  for ( short int i = 0; i < nStrips; ++i) {
89  weights[i] = stripWeight(id, strip1+i);
90  }
91  }
92 }
93 
94 void CSCRecoConditions::noiseMatrix( const CSCDetId& id, int centralStrip, std::vector<float>& nMatrix ) const {
95 
96  // nMatrix will be filled with expanded noise matrix elements for
97  // channel 'centralStrip' and its immediate neighbours
98  nMatrix.clear();
99 
100  // Initialize values in case we can't find chamber with constants
101  // These are ME1/2 constants...
102  float elem[15];
103  elem[0] = 8.64;
104  elem[1] = 3.47;
105  elem[2] = 2.45;
106  elem[3] = 8.60;
107  elem[4] = 3.28;
108  elem[5] = 1.88;
109  elem[6] = 8.61;
110  elem[7] = 3.18;
111  elem[8] = 1.99;
112  elem[9] = 7.67;
113  elem[10] = 2.64;
114  elem[11] = 0.;
115  elem[12] = 7.71;
116  elem[13] = 0.;
117  elem[14] = 0.;
118 
119  short int strip1 = centralStrip;
120  short int triplet[3];
121  bool isME1a = (id.ring()==4);
122  CSCDetId id1;
123 
124  // ME1/a constants are stored in channels 65-80 of ME11, ME1/b in channels 1-64.
125  // ME1/a channels are ganged - 48 strips to 16 channels.
126  if ( isME1a ) { // ME1a
127 
128  strip1 = centralStrip%16; // strip# 1-48
129  if (strip1 == 0) strip1 = 16; // channel# 1-16
130  strip1 += 64; // strip1 65-80
131  id1=CSCDetId( id.endcap(), 1, 1, id.chamber(), id.layer() ); // ME11 detId
132 
133  if (strip1 == 65) {
134  triplet[0]=80;
135  triplet[1]=65;
136  triplet[2]=66;
137  } else if (strip1 == 80) {
138  triplet[0]=79;
139  triplet[1]=80;
140  triplet[2]=65;
141  } else {
142  triplet[0]=strip1-1;
143  triplet[1]=strip1;
144  triplet[2]=strip1+1;
145 
146  }
147  }
148  else { // non-ME1a
149  triplet[0]=strip1-1;
150  triplet[1]=strip1;
151  triplet[2]=strip1+1;
152  }
153 
154  for ( short int i = 0; i < 3; ++i) {
155 
156  short int channel = triplet[i];
157  float w;
158  std::vector<float> me(12);
159 
160  if ( isME1a ) {
161  w = stripWeight(id1, channel);
162  theConditions.noiseMatrixElements(id1, channel, me);
163  }
164  else {
165  w = stripWeight(id, channel);
166  theConditions.noiseMatrixElements(id, channel, me);
167  }
168  w = w*w;
169  for ( short int j=0; j<11; ++j ) {
170  elem[j] = me[j] * w;
171  }
172  elem[11]= 0.;
173  elem[12]= me[11] * w;
174  elem[13]= 0.;
175  elem[14]= 0.;
176 
177  // Test that elements make sense:
178  bool isFlawed = false;
179  for ( int k = 0; k < 15; ++k) {
180  // make sure the number isn't too close to zero...
181  if (elem[k] < 0.001) elem[k] = 0.001;
182  // make sure the number isn't too big...
183  if (elem[k] > 50.) isFlawed = true;
184  }
185 
186  if ( isFlawed ) {
187  // These are fake ME1/2:
188  elem[0] = 8.64;
189  elem[1] = 3.47;
190  elem[2] = 2.45;
191  elem[3] = 8.60;
192  elem[4] = 3.28;
193  elem[5] = 1.88;
194  elem[6] = 8.61;
195  elem[7] = 3.18;
196  elem[8] = 1.99;
197  elem[9] = 7.67;
198  elem[10] = 2.64;
199  elem[11] = 0.;
200  elem[12] = 7.71;
201  elem[13] = 0.;
202  elem[14] = 0.;
203  }
204 
205  for (int k = 0; k < 15; ++k) nMatrix.push_back( elem[k] );
206  }
207 }
208 
209 void CSCRecoConditions::crossTalk( const CSCDetId& id, int centralStrip, std::vector<float>& xtalks) const {
210 
211  xtalks.clear();
212 
213  short int strip1 = centralStrip;
214  short int triplet[3];
215  bool isME1a = (id.ring()==4);
216  CSCDetId id1;
217 
218  // ME1/a constants are stored in channels 65-80 of ME11, ME1/b in channels 1-64.
219  // ME1/a channels are ganged - 48 strips to 16 channels.
220  if ( isME1a ) { // ME1a
221 
222  strip1 = centralStrip%16; // strip# 1-48
223  if (strip1 == 0) strip1 = 16; // channel# 1-16
224  strip1 += 64; // strip1 65-80
225  id1=CSCDetId( id.endcap(), 1, 1, id.chamber(), id.layer() ); // ME11 detId
226 
227  if (strip1 == 65) {
228  triplet[0]=80;
229  triplet[1]=65;
230  triplet[2]=66;
231  } else if (strip1 == 80) {
232  triplet[0]=79;
233  triplet[1]=80;
234  triplet[2]=65;
235  } else {
236  triplet[0]=strip1-1;
237  triplet[1]=strip1;
238  triplet[2]=strip1+1;
239  }
240  }
241  else { // non-ME1a
242  triplet[0]=strip1-1;
243  triplet[1]=strip1;
244  triplet[2]=strip1+1;
245  }
246 
247  // For 3 neighbouring strips get crosstalks
248  short int idx = 0;
249  for ( short int i = 0; i < 3; ++i) {
250 
251  short int channel = triplet[i];
252  std::vector<float> ct(4);
253 
254  if ( isME1a ) {
255  theConditions.crossTalk(id1, channel, ct);
256  }
257  else {
258  theConditions.crossTalk(id, channel, ct);
259  }
260 
261  xtalks.push_back(ct[0]);
262  xtalks.push_back(ct[1]);
263  xtalks.push_back(ct[2]);
264  xtalks.push_back(ct[3]);
265  ++idx;
266  }
267 }
268 
272 
273 bool CSCRecoConditions::nearBadStrip( const CSCDetId& id, int geomStrip ) const {
274  // Note ME1A strip runs 1-48
275  /*
276  CSCChannelTranslator translate;
277  CSCDetId idraw = translate.rawCSCDetId( id );
278  int geomChan = translate.channelFromStrip( id, geomStrip );
279  int rawChan = translate.rawStripChannel( id, geomChan );
280 
281  const std::bitset<80>& badStrips = theConditions.badStripWord(idraw);
282 
283  bool nearBad = false;
284  if( rawChan>1 && rawChan<80 ){ // 80 bits max, labelled 0-79. Test 1-78 for neighbours.
285  nearBad = (badStrips.test(rawChan) || badStrips.test(rawChan-2));
286  }
287  */
288  //
289  bool nearBad = (badStrip(id,geomStrip-1) || badStrip(id,geomStrip+1));
290 
291 
292  return nearBad;
293 }
294 //
296 
297 bool CSCRecoConditions::badStrip( const CSCDetId& id, int geomStrip ) const {
298  // Note ME1A strip runs 1-48
299  bool aBadS = false;
300  if(geomStrip>0 && geomStrip<81){
301  CSCChannelTranslator translate;
302  CSCDetId idraw = translate.rawCSCDetId( id );
303  int geomChan = translate.channelFromStrip( id, geomStrip );
304  int rawChan = translate.rawStripChannel( id, geomChan );
305 
306  const std::bitset<80>& badStrips = theConditions.badStripWord(idraw);
307 
308  if( rawChan>0 && rawChan<81 ){ // 80 bits max, labelled 0-79. Test 0-79 (i.e. any - that's the idea)
309  aBadS = badStrips.test(rawChan-1);
310  }
311  }
312  return aBadS;
313 }
314 
316 const std::bitset<112>& CSCRecoConditions::badWireWord( const CSCDetId& id ) const {
317  return theConditions.badWireWord( id );
318 }
319 
320 // This expects raw ME11 detId for ME1b (channels 1-64) & for ME1a (channels 65-80)
321 float CSCRecoConditions::stripWeight( const CSCDetId& id, int channel ) const {
322  float w = averageGain() / theConditions.gain(id, channel);
323 
324  // Weights are forced to lie within 0.5 and 1.5
325  if (w > 1.5) w = 1.5;
326  if (w < 0.5) w = 0.5;
327  return w;
328 }
329 
330 float CSCRecoConditions::gasGainCorrection(const CSCDetId & id, int geomStrip, int wire ) const {
331  //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);
332  CSCChannelTranslator translate;
333  // If ME1/4, set ring = 1
334  CSCDetId idraw = translate.rawCSCDetId( id );
335  // If ME1/4, collapse 48 chips into 16 electronics channel (1-48) -> (1-16)
336  int geomChannel = translate.channelFromStrip( id, geomStrip );
337  // Translate geometry-oriented strip channels into raw channels
338  // reordering ME+1/1a and ME-1/1b and moving ME1/1a (1-16)->(65-80)
339  int iraw = translate.rawStripChannel( id, geomChannel);
340  //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);
341  return theConditions.gasGainCorrection(idraw, iraw, wire);
342 }
343 
const std::bitset< 80 > & badStripWord(const CSCDetId &id) const
return bad channel words per CSCLayer - 1 bit per channel
int i
Definition: DBlmapReader.cc:9
float pedestalSigma(const CSCDetId &detId, int channel) const
void noiseMatrixElements(const CSCDetId &id, int channel, std::vector< float > &me) const
fill vector (dim 12, must be allocated by caller) with noise matrix elements (scaled to float) ...
float gain(const CSCDetId &id, int channel) const
channels count from 1
CSCRecoConditions(const edm::ParameterSet &pset)
void noiseMatrix(const CSCDetId &id, int centralStrip, std::vector< float > &nme) const
bool nearBadStrip(const CSCDetId &id, int geomStrip) const
Is a neighbour bad?
float chipCorrection(const CSCDetId &detId, int channel) const
float averageGain() const
return average gain over entire CSC system
float chamberTimingCorrection(const CSCDetId &detId) const
float stripWeight(const CSCDetId &id, int channel) const
void crossTalk(const CSCDetId &id, int channel, std::vector< float > &ct) const
fill vector (dim 4, must be allocated by caller) with crosstalk sl, il, sr, ir
float anodeBXoffset(const CSCDetId &detId) const
float pedestal(const CSCDetId &detId, int channel) const
in ADC counts
void stripWeights(const CSCDetId &id, float *weights) const
int j
Definition: DBlmapReader.cc:9
bool badStrip(const CSCDetId &id, int geomStrip) const
Is the strip bad?
float gasGainCorrection(const CSCDetId &detId, int strip, int wire) const
returns gas-gain correction given detId (w/layer), strip, channel. This converts ME1/4 strips 1-16 to...
CSCConditions theConditions
void initializeEvent(const edm::EventSetup &es)
fetch the maps from the database
const std::bitset< 112 > & badWireWord(const CSCDetId &id) const
int k[5][pyjets_maxn]
float gain(const CSCDetId &detId, int channel) const
channels count from 1
float chipCorrection(const CSCDetId &detId, int channel) const
float anodeBXoffset(const CSCDetId &detId) const
void crossTalk(const CSCDetId &id, int centralStrip, std::vector< float > &xtalks) const
int channelFromStrip(const CSCDetId &id, int strip) const
float pedestalSigma(const CSCDetId &id, int channel) const
sigma of static pedestal in ADC counts
int rawStripChannel(const CSCDetId &id, int igeom) const
Return raw strip channel number for input geometrical channel number.
float pedestal(const CSCDetId &id, int channel) const
static pedestal in ADC counts
float gasGainCorrection(const CSCDetId &detId, int strip, int wire) const
gas gain correction as a function of detId (w/layer), strip, and wire
CSCDetId rawCSCDetId(const CSCDetId &id) const
void initializeEvent(const edm::EventSetup &es)
fetch the cond data from the database
const std::bitset< 112 > & badWireWord(const CSCDetId &id) const
Get bad wiregroup word.
float chamberTimingCorrection(const CSCDetId &detId) const
T w() const