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 CaloTSamples< float, 10 > EcalSamples
 
typedef CorrelatedNoisifier
< EcalCorrMatrix
Noisifier
 

Public Member Functions

virtual void analogToDigital (const EcalSamples &clf, EcalDataFrame &df) const
 from EcalSamples 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 EcalSamples &ecalSamples, 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.

Definition at line 28 of file EcalCoder.h.

Member Enumeration Documentation

anonymous enum
Enumerator
NBITS 
MAXADC 
ADCGAINSWITCH 
NGAINS 

Definition at line 30 of file EcalCoder.h.

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

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 12 of file EcalCoder.cc.

References m_ebCorrNoise, and m_eeCorrNoise.

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

dtor

Definition at line 35 of file EcalCoder.cc.

36 {
37 }

Member Function Documentation

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

from EcalSamples to EcalDataFrame

Definition at line 73 of file EcalCoder.cc.

References encode(), EcalDataFrame::setSize(), and CaloTSamplesBase< Ttype >::size().

Referenced by EcalElectronicsSim::analogToDigital().

75 {
76  df.setSize( clf.size() ) ;
77  encode( clf, df );
78 /* std::cout<<" **Id=" ;
79  if( CaloGenericDetId( clf.id() ).isEB() )
80  {
81  std::cout<<EBDetId( clf.id() ) ;
82  }
83  else
84  {
85  std::cout<<EEDetId( clf.id() ) ;
86  }
87  std::cout<<", size="<<df.size();
88  for( int i ( 0 ) ; i != df.size() ; ++i )
89  {
90  std::cout<<", "<<df[i];
91  }
92  std::cout<<std::endl ;*/
93 }
void setSize(int)
Definition: EcalDataFrame.h:42
void encode(const EcalSamples &ecalSamples, EcalDataFrame &df) const
produce the pulse-shape
Definition: EcalCoder.cc:96
void EcalCoder::encode ( const EcalSamples ecalSamples,
EcalDataFrame df 
) const
private

produce the pulse-shape

Definition at line 96 of file EcalCoder.cc.

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

Referenced by analogToDigital().

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

Definition at line 323 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().

325 {
326  /*
327  EcalGainRatios::EcalGainRatioMap::const_iterator grit=m_gainRatios->getMap().find(detId.rawId());
328  EcalMGPAGainRatio mgpa;
329  if( grit!=m_gainRatios->getMap().end() ){
330  mgpa = grit->second;
331  Gains[0] = 0.;
332  Gains[3] = 1.;
333  Gains[2] = mgpa.gain6Over1() ;
334  Gains[1] = Gains[2]*(mgpa.gain12Over6()) ;
335  LogDebug("EcalCoder") << "Gains for " << detId.rawId() << "\n" << " 1 = " << Gains[1] << "\n" << " 2 = " << Gains[2] << "\n" << " 3 = " << Gains[3];
336  } else {
337  edm::LogError("EcalCoder") << "Could not find gain ratios for " << detId.rawId() << " among the " << m_gainRatios->getMap().size();
338  }
339  */
340 
342  Gains[0] = 0.;
343  Gains[3] = 1.;
344  Gains[2] = (*grit).gain6Over1();
345  Gains[1] = Gains[2]*( (*grit).gain12Over6() );
346 
347 
348  if ( (detId.subdetId() != EcalBarrel) && (detId.subdetId() != EcalEndcap) )
349  {
350  edm::LogError("EcalCoder") << "Could not find gain ratios for " << detId.rawId() << " among the " << m_gainRatios->getMap().size();
351  }
352 
353 }
const EcalGainRatios * m_gainRatios
Definition: EcalCoder.h:91
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 356 of file EcalCoder.cc.

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

Referenced by encode().

358 {
359  EcalIntercalibConstantMC thisconst = 1.;
360  // find intercalib constant for this xtal
361  const EcalIntercalibConstantMCMap &icalMap = m_intercals->getMap();
362  EcalIntercalibConstantMCMap::const_iterator icalit = icalMap.find(detId);
363  if( icalit!=icalMap.end() )
364  {
365  thisconst = (*icalit);
366  if ( icalconst == 0. ) { thisconst = 1.; }
367  }
368  else
369  {
370  edm::LogError("EcalCoder") << "No intercalib const found for xtal " << detId.rawId() << "! something wrong with EcalIntercalibConstants in your DB? ";
371  }
372  icalconst = thisconst;
373 }
const self & getMap() const
const EcalIntercalibConstantsMC * m_intercals
Definition: EcalCoder.h:93
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 265 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().

269 {
270  /*
271  EcalPedestalsMapIterator mapItr
272  = m_peds->m_pedestals.find(detId.rawId());
273  // should I care if it doesn't get found?
274  if(mapItr == m_peds->m_pedestals.end()) {
275  edm::LogError("EcalCoder") << "Could not find pedestal for " << detId.rawId() << " among the " << m_peds->m_pedestals.size();
276  } else {
277  EcalPedestals::Item item = mapItr->second;
278  */
279 
280  /*
281  EcalPedestals::Item const & item = (*m_peds)(detId);
282  ped = item.mean(gainId);
283  width = item.rms(gainId);
284  */
285 
287  ped = (*itped).mean(gainId);
288  width = (*itped).rms(gainId);
289 
290  if ( (detId.subdetId() != EcalBarrel) && (detId.subdetId() != EcalEndcap) )
291  {
292  edm::LogError("EcalCoder") << "Could not find pedestal for " << detId.rawId() << " among the " << m_peds->getMap().size();
293  }
294 
295  /*
296  switch(gainId) {
297  case 0:
298  ped = 0.;
299  width = 0.;
300  case 1:
301  ped = item.mean_x12;
302  width = item.rms_x12;
303  break;
304  case 2:
305  ped = item.mean_x6;
306  width = item.rms_x6;
307  break;
308  case 3:
309  ped = item.mean_x1;
310  width = item.rms_x1;
311  break;
312  default:
313  edm::LogError("EcalCoder") << "Bad Pedestal " << gainId;
314  break;
315  }
316  */
317 
318  LogDebug("EcalCoder") << "Pedestals for " << detId.rawId() << " gain range " << gainId << " : \n" << "Mean = " << ped << " rms = " << width;
319 }
#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:89
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 67 of file EcalCoder.cc.

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

Referenced by encode().

68 {
69  return detId.subdetId() == EcalBarrel ? m_maxEneEB : m_maxEneEE ;
70 }
double m_maxEneEE
Definition: EcalCoder.h:96
double m_maxEneEB
Definition: EcalCoder.h:95
void EcalCoder::setFullScaleEnergy ( double  EBscale,
double  EEscale 
)

Definition at line 40 of file EcalCoder.cc.

References m_maxEneEB, and m_maxEneEE.

Referenced by EcalDigiProducer::checkCalibrations().

42 {
43  m_maxEneEB = EBscale ;
44  m_maxEneEE = EEscale ;
45 }
double m_maxEneEE
Definition: EcalCoder.h:96
double m_maxEneEB
Definition: EcalCoder.h:95
void EcalCoder::setGainRatios ( const EcalGainRatios gainRatios)

Definition at line 55 of file EcalCoder.cc.

References m_gainRatios.

Referenced by EcalDigiProducer::checkCalibrations().

56 {
57  m_gainRatios = gainRatios ;
58 }
const EcalGainRatios * m_gainRatios
Definition: EcalCoder.h:91
void EcalCoder::setIntercalibConstants ( const EcalIntercalibConstantsMC ical)

Definition at line 61 of file EcalCoder.cc.

References m_intercals.

Referenced by EcalDigiProducer::checkCalibrations().

62 {
63  m_intercals = ical ;
64 }
const EcalIntercalibConstantsMC * m_intercals
Definition: EcalCoder.h:93
void EcalCoder::setPedestals ( const EcalPedestals pedestals)

can be fetched every event from the EventSetup

Definition at line 49 of file EcalCoder.cc.

References m_peds.

Referenced by EcalDigiProducer::checkCalibrations().

50 {
51  m_peds = pedestals ;
52 }
const EcalPedestals * m_peds
Definition: EcalCoder.h:89

Member Data Documentation

bool EcalCoder::m_addNoise
private

Definition at line 98 of file EcalCoder.h.

Referenced by encode().

const Noisifier* EcalCoder::m_ebCorrNoise[3]
private

Definition at line 100 of file EcalCoder.h.

Referenced by EcalCoder(), and encode().

const Noisifier* EcalCoder::m_eeCorrNoise[3]
private

Definition at line 101 of file EcalCoder.h.

Referenced by EcalCoder(), and encode().

const EcalGainRatios* EcalCoder::m_gainRatios
private

Definition at line 91 of file EcalCoder.h.

Referenced by findGains(), and setGainRatios().

const EcalIntercalibConstantsMC* EcalCoder::m_intercals
private

Definition at line 93 of file EcalCoder.h.

Referenced by findIntercalibConstant(), and setIntercalibConstants().

double EcalCoder::m_maxEneEB
private

Definition at line 95 of file EcalCoder.h.

Referenced by fullScaleEnergy(), and setFullScaleEnergy().

double EcalCoder::m_maxEneEE
private

Definition at line 96 of file EcalCoder.h.

Referenced by fullScaleEnergy(), and setFullScaleEnergy().

const EcalPedestals* EcalCoder::m_peds
private

Definition at line 89 of file EcalCoder.h.

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