CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
EcalCoder Class Reference

#include <EcalCoder.h>

Public Types

enum  { NBITS = 12, MAXADC = 4095, ADCGAINSWITCH = 4079, NGAINS = 3 }
 
typedef CorrelatedNoisifier
< EcalCorrMatrix
Noisifier
 

Public Member Functions

virtual void analogToDigital (const CaloSamples &clf, EcalDataFrame &df) const
 from CaloSamples to EcalDataFrame More...
 
 EcalCoder (bool addNoise, Noisifier *ebCorrNoise0, Noisifier *eeCorrNoise0=0, Noisifier *ebCorrNoise1=0, Noisifier *eeCorrNoise1=0, Noisifier *ebCorrNoise2=0, Noisifier *eeCorrNoise2=0)
 ctor More...
 
void setFullScaleEnergy (double EBscale, double EEscale)
 
void setGainRatios (const EcalGainRatios *gainRatios)
 
void setIntercalibConstants (const EcalIntercalibConstantsMC *ical)
 
void setPedestals (const EcalPedestals *pedestals)
 can be fetched every event from the EventSetup More...
 
virtual ~EcalCoder ()
 dtor More...
 

Private Member Functions

void encode (const CaloSamples &caloSamples, EcalDataFrame &df) const
 produce the pulse-shape More...
 
void findGains (const DetId &detId, double theGains[]) const
 
void findIntercalibConstant (const DetId &detId, double &icalconst) const
 
void findPedestal (const DetId &detId, int gainId, double &pedestal, double &width) const
 not yet implemented More...
 
double fullScaleEnergy (const DetId &did) const
 limit on the energy scale due to the electronics range More...
 

Private Attributes

bool m_addNoise
 
const Noisifierm_ebCorrNoise [3]
 
const Noisifierm_eeCorrNoise [3]
 
const EcalGainRatiosm_gainRatios
 
const EcalIntercalibConstantsMCm_intercals
 
double m_maxEneEB
 
double m_maxEneEE
 
const EcalPedestalsm_peds
 

Detailed Description

Definition at line 22 of file EcalCoder.h.

Member Typedef Documentation

Definition at line 26 of file EcalCoder.h.

Member Enumeration Documentation

anonymous enum
Enumerator
NBITS 
MAXADC 
ADCGAINSWITCH 
NGAINS 

Definition at line 28 of file EcalCoder.h.

28  { NBITS = 12 , // number of available bits
29  MAXADC = 4095 , // 2^12 -1, adc max range
30  ADCGAINSWITCH = 4079 , // adc gain switch
31  NGAINS = 3 // number of electronic gains
32  };

Constructor & Destructor Documentation

EcalCoder::EcalCoder ( bool  addNoise,
EcalCoder::Noisifier ebCorrNoise0,
EcalCoder::Noisifier eeCorrNoise0 = 0,
EcalCoder::Noisifier ebCorrNoise1 = 0,
EcalCoder::Noisifier eeCorrNoise1 = 0,
EcalCoder::Noisifier ebCorrNoise2 = 0,
EcalCoder::Noisifier eeCorrNoise2 = 0 
)

ctor

Definition at line 9 of file EcalCoder.cc.

References m_ebCorrNoise, and m_eeCorrNoise.

15  :
16  m_peds ( 0 ) ,
17  m_gainRatios ( 0 ) ,
18  m_intercals ( 0 ) ,
19  m_maxEneEB ( 1668.3 ) , // 4095(MAXADC)*12(gain 2)*0.035(GeVtoADC)*0.97
20  m_maxEneEE ( 2859.9 ) , // 4095(MAXADC)*12(gain 2)*0.060(GeVtoADC)*0.97
21  m_addNoise ( addNoise )
22 {
23  m_ebCorrNoise[0] = ebCorrNoise0 ;
24  assert( 0 != m_ebCorrNoise[0] ) ;
25  m_eeCorrNoise[0] = eeCorrNoise0 ;
26  m_ebCorrNoise[1] = ebCorrNoise1 ;
27  m_eeCorrNoise[1] = eeCorrNoise1 ;
28  m_ebCorrNoise[2] = ebCorrNoise2 ;
29  m_eeCorrNoise[2] = eeCorrNoise2 ;
30 }
bool m_addNoise
Definition: EcalCoder.h:96
const EcalGainRatios * m_gainRatios
Definition: EcalCoder.h:89
const EcalIntercalibConstantsMC * m_intercals
Definition: EcalCoder.h:91
double m_maxEneEE
Definition: EcalCoder.h:94
const Noisifier * m_ebCorrNoise[3]
Definition: EcalCoder.h:98
const Noisifier * m_eeCorrNoise[3]
Definition: EcalCoder.h:99
const EcalPedestals * m_peds
Definition: EcalCoder.h:87
double m_maxEneEB
Definition: EcalCoder.h:93
EcalCoder::~EcalCoder ( )
virtual

dtor

Definition at line 32 of file EcalCoder.cc.

33 {
34 }

Member Function Documentation

void EcalCoder::analogToDigital ( const CaloSamples clf,
EcalDataFrame df 
) const
virtual

from CaloSamples to EcalDataFrame

Definition at line 70 of file EcalCoder.cc.

References encode(), EcalDataFrame::setSize(), and CaloSamples::size().

Referenced by EcalElectronicsSim::analogToDigital().

72 {
73  df.setSize( clf.size() ) ;
74  encode( clf, df );
75 }
void setSize(int)
Definition: EcalDataFrame.h:40
int size() const
get the size
Definition: CaloSamples.h:24
void encode(const CaloSamples &caloSamples, EcalDataFrame &df) const
produce the pulse-shape
Definition: EcalCoder.cc:78
void EcalCoder::encode ( const CaloSamples caloSamples,
EcalDataFrame df 
) const
private

produce the pulse-shape

Definition at line 78 of file EcalCoder.cc.

References ecalMGPA::adc(), ADCGAINSWITCH, generateEDF::done, EcalBarrel, findGains(), findIntercalibConstant(), findPedestal(), fullScaleEnergy(), ecalMGPA::gainId(), EcalMGPASample::gainId(), i, CaloSamples::id(), j, LogDebug, m_addNoise, m_ebCorrNoise, m_eeCorrNoise, m_peds, MAXADC, NGAINS, CorrelatedNoisifier< M >::noisify(), EcalDataFrame::sample(), EcalDataFrame::setSample(), CaloSamples::size(), mathSSE::sqrt(), and funct::true.

Referenced by analogToDigital().

80 {
81  assert( 0 != m_peds ) ;
82 
83  const unsigned int csize ( caloSamples.size() ) ;
84 
85 
86  DetId detId = caloSamples.id();
87  double Emax = fullScaleEnergy(detId);
88 
89  //....initialisation
90  if ( caloSamples[5] > 0. ) LogDebug("EcalCoder") << "Input caloSample" << "\n" << caloSamples;
91 
92  double LSB[NGAINS+1];
93  double pedestals[NGAINS+1];
94  double widths[NGAINS+1];
95  double gains[NGAINS+1];
96  int maxADC[NGAINS+1];
97  double trueRMS[NGAINS+1];
98 
99  double icalconst = 1. ;
100  findIntercalibConstant( detId, icalconst );
101 
102  for( unsigned int igain ( 0 ); igain <= NGAINS ; ++igain )
103  {
104  // fill in the pedestal and width
105  findPedestal( detId ,
106  igain ,
107  pedestals[igain] ,
108  widths[igain] ) ;
109 
110  if( 0 < igain )
111  trueRMS[igain] = std::sqrt( widths[igain]*widths[igain] - 1./12. ) ;
112 
113  // set nominal value first
114  findGains( detId ,
115  gains );
116 
117  LSB[igain] = 0.;
118  if ( igain > 0 ) LSB[igain]= Emax/(MAXADC*gains[igain]);
119  maxADC[igain] = ADCGAINSWITCH; // saturation at 4080 for middle and high gains x6 & x12
120  if ( igain == NGAINS ) maxADC[igain] = MAXADC; // saturation at 4095 for low gain x1
121  }
122 
123  CaloSamples noiseframe[] = { CaloSamples( detId , csize ) ,
124  CaloSamples( detId , csize ) ,
125  CaloSamples( detId , csize ) } ;
126 
127  const Noisifier* noisy[3] = { ( 0 == m_eeCorrNoise[0] ||
128  EcalBarrel == detId.subdetId() ?
129  m_ebCorrNoise[0] :
130  m_eeCorrNoise[0] ) ,
131  ( EcalBarrel == detId.subdetId() ?
132  m_ebCorrNoise[1] :
133  m_eeCorrNoise[1] ) ,
134  ( EcalBarrel == detId.subdetId() ?
135  m_ebCorrNoise[2] :
136  m_eeCorrNoise[2] ) } ;
137 
138  if( m_addNoise )
139  {
140  noisy[0]->noisify( noiseframe[0] ) ; // high gain
141  if( 0 == noisy[1] ) noisy[0]->noisify( noiseframe[1] ,
142  &noisy[0]->vecgau() ) ; // med
143  if( 0 == noisy[2] ) noisy[0]->noisify( noiseframe[2] ,
144  &noisy[0]->vecgau() ) ; // low
145  }
146 
147  int wait = 0 ;
148  int gainId = 0 ;
149  bool isSaturated = 0;
150 
151  for( unsigned int i ( 0 ) ; i != csize ; ++i )
152  {
153  bool done ( false ) ;
154  int adc = MAXADC ;
155  if( 0 == wait ) gainId = 1 ;
156 
157  // see which gain bin it fits in
158  int igain ( gainId - 1 ) ;
159  do
160  {
161  ++igain ;
162 
163 // if( igain != gainId ) std::cout <<"$$$$ Gain switch from " << gainId
164 // <<" to "<< igain << std::endl ;
165 
166  if( 1 != igain && // not high gain
167  m_addNoise && // want to add noise
168  0 != noisy[igain-1] && // exists
169  noiseframe[igain-1].isBlank() ) // not already done
170  {
171  noisy[igain-1]->noisify( noiseframe[igain-1] ,
172  &noisy[0]->vecgau() ) ;
173 // std::cout<<"....noisifying gain level = "<<igain<<std::endl ;
174  }
175 
176  // noiseframe filled with zeros if !m_addNoise
177  const double signal ( pedestals[igain] +
178  caloSamples[i] /( LSB[igain]*icalconst ) +
179  trueRMS[igain]*noiseframe[igain-1][i] ) ;
180 
181  const int isignal ( signal ) ;
182  const int tmpadc ( signal - (double)isignal < 0.5 ?
183  isignal : isignal + 1 ) ;
184  // LogDebug("EcalCoder") << "DetId " << detId.rawId() << " gain " << igain << " caloSample "
185  // << caloSamples[i] << " pededstal " << pedestals[igain]
186  // << " noise " << widths[igain] << " conversion factor " << LSB[igain]
187  // << " result (ped,tmpadc)= " << ped << " " << tmpadc;
188 
189  if( tmpadc <= maxADC[igain] )
190  {
191  adc = tmpadc;
192  done = true ;
193  }
194  }
195  while( !done &&
196  igain < 3 ) ;
197 
198  if (igain == 1 )
199  {
200  wait = 0 ;
201  gainId = igain ;
202  }
203  else
204  {
205  if (igain == gainId) --wait ;
206  else
207  {
208  wait = 5 ;
209  gainId = igain ;
210  }
211  }
212 
213 
214  // change the gain for saturation
215  int storeGainId = gainId;
216  if ( gainId == 3 && adc == MAXADC )
217  {
218  storeGainId = 0;
219  isSaturated = true;
220  }
221  // LogDebug("EcalCoder") << " Writing out frame " << i << " ADC = " << adc << " gainId = " << gainId << " storeGainId = " << storeGainId ;
222 
223  df.setSample( i, EcalMGPASample( adc, storeGainId ) );
224  }
225  // handle saturation properly according to IN-2007/056
226  // N.B. - FIXME
227  // still missing the possibility for a signal to pass the saturation threshold
228  // again within the 5 subsequent samples (higher order effect).
229 
230  if ( isSaturated )
231  {
232  for (int i = 0 ; i < caloSamples.size() ; ++i)
233  {
234  if ( df.sample(i).gainId() == 0 )
235  {
236  int hyst = i+1+2;
237  for ( int j = i+1; j < hyst && j < caloSamples.size(); ++j )
238  {
239  df.setSample(j, EcalMGPASample(MAXADC, 0));
240  }
241  }
242  }
243  }
244 }
int adc(sample_type sample)
get the ADC sample (12 bits)
#define LogDebug(id)
bool m_addNoise
Definition: EcalCoder.h:96
int i
Definition: DBlmapReader.cc:9
int gainId(sample_type sample)
get the gainId (2 bits)
CorrelatedNoisifier< EcalCorrMatrix > Noisifier
Definition: EcalCoder.h:26
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:28
int gainId() const
get the gainId (2 bits)
double fullScaleEnergy(const DetId &did) const
limit on the energy scale due to the electronics range
Definition: EcalCoder.cc:64
const Noisifier * m_ebCorrNoise[3]
Definition: EcalCoder.h:98
const Noisifier * m_eeCorrNoise[3]
Definition: EcalCoder.h:99
T sqrt(T t)
Definition: SSEVec.h:28
int j
Definition: DBlmapReader.cc:9
void findGains(const DetId &detId, double theGains[]) const
Definition: EcalCoder.cc:305
const EcalPedestals * m_peds
Definition: EcalCoder.h:87
Definition: DetId.h:20
int size() const
get the size
Definition: CaloSamples.h:24
void setSample(int i, EcalMGPASample sam)
Definition: EcalDataFrame.h:42
void noisify(T &frame, const VecDou *rangau=0) const
DetId id() const
get the (generic) id
Definition: CaloSamples.h:21
void findIntercalibConstant(const DetId &detId, double &icalconst) const
Definition: EcalCoder.cc:338
void findPedestal(const DetId &detId, int gainId, double &pedestal, double &width) const
not yet implemented
Definition: EcalCoder.cc:247
void EcalCoder::findGains ( const DetId detId,
double  theGains[] 
) const
private

Definition at line 305 of file EcalCoder.cc.

References EcalBarrel, EcalEndcap, EcalCondObjectContainer< T >::find(), EcalCondObjectContainer< T >::getMap(), m_gainRatios, DetId::rawId(), EcalCondObjectContainer< T >::size(), and DetId::subdetId().

Referenced by encode().

307 {
308  /*
309  EcalGainRatios::EcalGainRatioMap::const_iterator grit=m_gainRatios->getMap().find(detId.rawId());
310  EcalMGPAGainRatio mgpa;
311  if( grit!=m_gainRatios->getMap().end() ){
312  mgpa = grit->second;
313  Gains[0] = 0.;
314  Gains[3] = 1.;
315  Gains[2] = mgpa.gain6Over1() ;
316  Gains[1] = Gains[2]*(mgpa.gain12Over6()) ;
317  LogDebug("EcalCoder") << "Gains for " << detId.rawId() << "\n" << " 1 = " << Gains[1] << "\n" << " 2 = " << Gains[2] << "\n" << " 3 = " << Gains[3];
318  } else {
319  edm::LogError("EcalCoder") << "Could not find gain ratios for " << detId.rawId() << " among the " << m_gainRatios->getMap().size();
320  }
321  */
322 
324  Gains[0] = 0.;
325  Gains[3] = 1.;
326  Gains[2] = (*grit).gain6Over1();
327  Gains[1] = Gains[2]*( (*grit).gain12Over6() );
328 
329 
330  if ( (detId.subdetId() != EcalBarrel) && (detId.subdetId() != EcalEndcap) )
331  {
332  edm::LogError("EcalCoder") << "Could not find gain ratios for " << detId.rawId() << " among the " << m_gainRatios->getMap().size();
333  }
334 
335 }
const EcalGainRatios * m_gainRatios
Definition: EcalCoder.h:89
const self & getMap() const
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
std::vector< Item >::const_iterator const_iterator
const_iterator find(uint32_t rawId) const
void EcalCoder::findIntercalibConstant ( const DetId detId,
double &  icalconst 
) const
private

Definition at line 338 of file EcalCoder.cc.

References EcalCondObjectContainer< T >::end(), EcalCondObjectContainer< T >::find(), EcalCondObjectContainer< T >::getMap(), m_intercals, and DetId::rawId().

Referenced by encode().

340 {
341  EcalIntercalibConstantMC thisconst = 1.;
342  // find intercalib constant for this xtal
343  const EcalIntercalibConstantMCMap &icalMap = m_intercals->getMap();
344  EcalIntercalibConstantMCMap::const_iterator icalit = icalMap.find(detId);
345  if( icalit!=icalMap.end() )
346  {
347  thisconst = (*icalit);
348  if ( icalconst == 0. ) { thisconst = 1.; }
349  }
350  else
351  {
352  edm::LogError("EcalCoder") << "No intercalib const found for xtal " << detId.rawId() << "! something wrong with EcalIntercalibConstants in your DB? ";
353  }
354  icalconst = thisconst;
355 }
const self & getMap() const
const EcalIntercalibConstantsMC * m_intercals
Definition: EcalCoder.h:91
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
std::vector< Item >::const_iterator const_iterator
const_iterator find(uint32_t rawId) const
const_iterator end() const
float EcalIntercalibConstantMC
void EcalCoder::findPedestal ( const DetId detId,
int  gainId,
double &  pedestal,
double &  width 
) const
private

not yet implemented

Definition at line 247 of file EcalCoder.cc.

References EcalBarrel, EcalEndcap, EcalCondObjectContainer< T >::find(), EcalCondObjectContainer< T >::getMap(), LogDebug, m_peds, DetId::rawId(), EcalCondObjectContainer< T >::size(), DetId::subdetId(), and tablePrinter::width.

Referenced by encode().

251 {
252  /*
253  EcalPedestalsMapIterator mapItr
254  = m_peds->m_pedestals.find(detId.rawId());
255  // should I care if it doesn't get found?
256  if(mapItr == m_peds->m_pedestals.end()) {
257  edm::LogError("EcalCoder") << "Could not find pedestal for " << detId.rawId() << " among the " << m_peds->m_pedestals.size();
258  } else {
259  EcalPedestals::Item item = mapItr->second;
260  */
261 
262  /*
263  EcalPedestals::Item const & item = (*m_peds)(detId);
264  ped = item.mean(gainId);
265  width = item.rms(gainId);
266  */
267 
269  ped = (*itped).mean(gainId);
270  width = (*itped).rms(gainId);
271 
272  if ( (detId.subdetId() != EcalBarrel) && (detId.subdetId() != EcalEndcap) )
273  {
274  edm::LogError("EcalCoder") << "Could not find pedestal for " << detId.rawId() << " among the " << m_peds->getMap().size();
275  }
276 
277  /*
278  switch(gainId) {
279  case 0:
280  ped = 0.;
281  width = 0.;
282  case 1:
283  ped = item.mean_x12;
284  width = item.rms_x12;
285  break;
286  case 2:
287  ped = item.mean_x6;
288  width = item.rms_x6;
289  break;
290  case 3:
291  ped = item.mean_x1;
292  width = item.rms_x1;
293  break;
294  default:
295  edm::LogError("EcalCoder") << "Bad Pedestal " << gainId;
296  break;
297  }
298  */
299 
300  LogDebug("EcalCoder") << "Pedestals for " << detId.rawId() << " gain range " << gainId << " : \n" << "Mean = " << ped << " rms = " << width;
301 }
#define LogDebug(id)
int gainId(sample_type sample)
get the gainId (2 bits)
const self & getMap() const
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
const EcalPedestals * m_peds
Definition: EcalCoder.h:87
std::vector< Item >::const_iterator const_iterator
const_iterator find(uint32_t rawId) const
double EcalCoder::fullScaleEnergy ( const DetId did) const
private

limit on the energy scale due to the electronics range

Definition at line 64 of file EcalCoder.cc.

References EcalBarrel, m_maxEneEB, m_maxEneEE, and DetId::subdetId().

Referenced by encode().

65 {
66  return detId.subdetId() == EcalBarrel ? m_maxEneEB : m_maxEneEE ;
67 }
double m_maxEneEE
Definition: EcalCoder.h:94
double m_maxEneEB
Definition: EcalCoder.h:93
void EcalCoder::setFullScaleEnergy ( double  EBscale,
double  EEscale 
)

Definition at line 37 of file EcalCoder.cc.

References m_maxEneEB, and m_maxEneEE.

Referenced by EcalDigiProducer::checkCalibrations(), and EcalTBDigiProducer::checkCalibrations().

39 {
40  m_maxEneEB = EBscale ;
41  m_maxEneEE = EEscale ;
42 }
double m_maxEneEE
Definition: EcalCoder.h:94
double m_maxEneEB
Definition: EcalCoder.h:93
void EcalCoder::setGainRatios ( const EcalGainRatios gainRatios)

Definition at line 52 of file EcalCoder.cc.

References m_gainRatios.

Referenced by EcalDigiProducer::checkCalibrations(), and EcalTBDigiProducer::checkCalibrations().

53 {
54  m_gainRatios = gainRatios ;
55 }
const EcalGainRatios * m_gainRatios
Definition: EcalCoder.h:89
void EcalCoder::setIntercalibConstants ( const EcalIntercalibConstantsMC ical)

Definition at line 58 of file EcalCoder.cc.

References m_intercals.

Referenced by EcalDigiProducer::checkCalibrations(), and EcalTBDigiProducer::checkCalibrations().

59 {
60  m_intercals = ical ;
61 }
const EcalIntercalibConstantsMC * m_intercals
Definition: EcalCoder.h:91
void EcalCoder::setPedestals ( const EcalPedestals pedestals)

can be fetched every event from the EventSetup

Definition at line 46 of file EcalCoder.cc.

References m_peds.

Referenced by EcalDigiProducer::checkCalibrations(), and EcalTBDigiProducer::checkCalibrations().

47 {
48  m_peds = pedestals ;
49 }
const EcalPedestals * m_peds
Definition: EcalCoder.h:87

Member Data Documentation

bool EcalCoder::m_addNoise
private

Definition at line 96 of file EcalCoder.h.

Referenced by encode().

const Noisifier* EcalCoder::m_ebCorrNoise[3]
private

Definition at line 98 of file EcalCoder.h.

Referenced by EcalCoder(), and encode().

const Noisifier* EcalCoder::m_eeCorrNoise[3]
private

Definition at line 99 of file EcalCoder.h.

Referenced by EcalCoder(), and encode().

const EcalGainRatios* EcalCoder::m_gainRatios
private

Definition at line 89 of file EcalCoder.h.

Referenced by findGains(), and setGainRatios().

const EcalIntercalibConstantsMC* EcalCoder::m_intercals
private

Definition at line 91 of file EcalCoder.h.

Referenced by findIntercalibConstant(), and setIntercalibConstants().

double EcalCoder::m_maxEneEB
private

Definition at line 93 of file EcalCoder.h.

Referenced by fullScaleEnergy(), and setFullScaleEnergy().

double EcalCoder::m_maxEneEE
private

Definition at line 94 of file EcalCoder.h.

Referenced by fullScaleEnergy(), and setFullScaleEnergy().

const EcalPedestals* EcalCoder::m_peds
private

Definition at line 87 of file EcalCoder.h.

Referenced by encode(), findPedestal(), and setPedestals().