CMS 3D CMS Logo

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

#include <EcalLiteDTUCoder.h>

Public Types

typedef CaloTSamples< float,
ecalPh2::sampleSize
EcalSamples
 
typedef CorrelatedNoisifier
< EcalCorrMatrix_Ph2
Noisifier
 

Public Member Functions

virtual void analogToDigital (CLHEP::HepRandomEngine *, const EcalSamples &clf, EcalDataFrame_Ph2 &df) const
 from EcalSamples to EcalDataFrame_Ph2 More...
 
 EcalLiteDTUCoder (bool addNoise, bool PreMix1, Noisifier *ebCorrNoise0, Noisifier *ebCorrNoise1=nullptr)
 ctor More...
 
void setFullScaleEnergy (double EBscale)
 
void setGainRatios (float gainRatios)
 
void setIntercalibConstants (const EcalIntercalibConstantsMC *ical)
 
void setPedestals (const EcalLiteDTUPedestalsMap *pedestals)
 can be fetched every event from the EventSetup More...
 
virtual ~EcalLiteDTUCoder ()
 dtor More...
 

Private Member Functions

void encode (const EcalSamples &ecalSamples, EcalDataFrame_Ph2 &df, CLHEP::HepRandomEngine *) const
 produce the pulse-shape More...
 
void findGains (const DetId &detId, float theGains[]) const
 
void findIntercalibConstant (const DetId &detId, double &icalconst) const
 
void findPedestal (const DetId &detId, int gainId, double &pedestal, double &width) const
 
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 [ecalPh2::NGAINS]
 
float m_gainRatios
 
const EcalIntercalibConstantsMCm_intercals
 
double m_maxEneEB
 
const EcalLiteDTUPedestalsMapm_peds
 
bool m_PreMix1
 

Detailed Description

Definition at line 24 of file EcalLiteDTUCoder.h.

Member Typedef Documentation

Definition at line 26 of file EcalLiteDTUCoder.h.

Definition at line 28 of file EcalLiteDTUCoder.h.

Constructor & Destructor Documentation

EcalLiteDTUCoder::EcalLiteDTUCoder ( bool  addNoise,
bool  PreMix1,
EcalLiteDTUCoder::Noisifier ebCorrNoise0,
EcalLiteDTUCoder::Noisifier ebCorrNoise1 = nullptr 
)

ctor

Definition at line 9 of file EcalLiteDTUCoder.cc.

13  : m_peds(nullptr),
14  m_gainRatios(0),
15  m_intercals(nullptr),
16  m_maxEneEB(ecalPh2::maxEneEB), // Maximum for CATIA: LSB gain 10: 0.048 MeV
18  m_PreMix1(PreMix1),
19  m_ebCorrNoise{ebCorrNoise0, ebCorrNoise1}
20 
21 {}
const EcalLiteDTUPedestalsMap * m_peds
static constexpr double maxEneEB
Definition: EcalConstants.h:16
const Noisifier * m_ebCorrNoise[ecalPh2::NGAINS]
const EcalIntercalibConstantsMC * m_intercals
const bool addNoise
EcalLiteDTUCoder::~EcalLiteDTUCoder ( )
virtual

dtor

Definition at line 23 of file EcalLiteDTUCoder.cc.

23 {}

Member Function Documentation

void EcalLiteDTUCoder::analogToDigital ( CLHEP::HepRandomEngine *  engine,
const EcalSamples clf,
EcalDataFrame_Ph2 df 
) const
virtual

from EcalSamples to EcalDataFrame_Ph2

Definition at line 35 of file EcalLiteDTUCoder.cc.

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

37  {
38  df.setSize(clf.size());
39  encode(clf, df, engine);
40 }
void encode(const EcalSamples &ecalSamples, EcalDataFrame_Ph2 &df, CLHEP::HepRandomEngine *) const
produce the pulse-shape
void EcalLiteDTUCoder::encode ( const EcalSamples ecalSamples,
EcalDataFrame_Ph2 df,
CLHEP::HepRandomEngine *  engine 
) const
private

produce the pulse-shape

Definition at line 42 of file EcalLiteDTUCoder.cc.

References funct::abs(), gpuClustering::adc, findIntercalibConstant(), findPedestal(), fullScaleEnergy(), ecalPh2::gains, mps_fire::i, CaloTSamplesBase< Ttype >::id(), dqmiolumiharvest::j, m_addNoise, m_ebCorrNoise, m_PreMix1, ecalPh2::MAXADC, ecalPh2::NGAINS, CorrelatedNoisifier< M >::noisify(), hgc_digi::nSamples, EcalDataFrame_Ph2::setSample(), CaloTSamplesBase< Ttype >::size(), and mathSSE::sqrt().

Referenced by analogToDigital().

44  {
45  const int nSamples(ecalSamples.size());
46 
47  DetId detId = ecalSamples.id();
48  double Emax = fullScaleEnergy(detId);
49 
50  //N Gains set to 2 in the .h
51  double pedestals[ecalPh2::NGAINS];
52  double widths[ecalPh2::NGAINS];
53  double LSB[ecalPh2::NGAINS];
54  double trueRMS[ecalPh2::NGAINS];
55  int nSaturatedSamples = 0;
56  double icalconst = 1.;
57  findIntercalibConstant(detId, icalconst);
58 
59  for (unsigned int igain(0); igain < ecalPh2::NGAINS; ++igain) {
60  // fill in the pedestal and width
61  findPedestal(detId, igain, pedestals[igain], widths[igain]);
62  // insert an absolute value in the trueRMS
63  trueRMS[igain] = std::sqrt(std::abs(widths[igain] * widths[igain] - 1. / 12.));
64 
65  LSB[igain] = Emax / (ecalPh2::MAXADC * ecalPh2::gains[igain]);
66  }
67 
68  CaloSamples noiseframe[ecalPh2::NGAINS] = {
69  CaloSamples(detId, nSamples),
70  CaloSamples(detId, nSamples),
71  };
72 
73  const Noisifier* noisy[ecalPh2::NGAINS] = {m_ebCorrNoise[0], m_ebCorrNoise[1]};
74 
75  if (m_addNoise) {
76  for (unsigned int ig = 0; ig < ecalPh2::NGAINS; ++ig) {
77  noisy[ig]->noisify(noiseframe[ig], engine);
78  }
79  }
80 
81  std::vector<std::vector<int>> adctrace(nSamples);
82  int firstSaturatedSample[ecalPh2::NGAINS] = {0, 0};
83 
84  for (int i(0); i != nSamples; ++i)
85  adctrace[i].resize(ecalPh2::NGAINS);
86 
87  for (unsigned int igain = 0; igain < ecalPh2::NGAINS; ++igain) {
88  for (int i(0); i != nSamples; ++i) {
89  adctrace[i][igain] = -1;
90  }
91  }
92 
93  // fill ADC trace in gain 0 (x10) and gain 1 (x1)
94  for (unsigned int igain = 0; igain < ecalPh2::NGAINS; ++igain) {
95  for (int i(0); i != nSamples; ++i) {
96  double asignal = 0;
97  if (!m_PreMix1) {
98  asignal = pedestals[igain] + ecalSamples[i] / (LSB[igain] * icalconst) + trueRMS[igain] * noiseframe[igain][i];
99  //Analog signal value for each sample in ADC.
100  //It is corrected by the intercalibration constants
101 
102  } else {
103  // no noise nor pedestal when premixing
104  asignal = ecalSamples[i] / (LSB[igain] * icalconst);
105  }
106  int isignal = asignal;
107 
108  unsigned int adc = asignal - (double)isignal < 0.5 ? isignal : isignal + 1;
109  // gain 0 (x10) channel is saturated, readout will use gain 1 (x10), but I count the number of saturated samples
110  if (adc > ecalPh2::MAXADC) {
111  adc = ecalPh2::MAXADC;
112  if (nSaturatedSamples == 0)
113  firstSaturatedSample[igain] = i;
114  nSaturatedSamples++;
115  }
116  adctrace[i][igain] = adc;
117  }
118  if (nSaturatedSamples == 0) {
119  break; // gain 0 (x10) is not saturated, so don't bother with gain 1
120  }
121  } // for igain
122 
123  int igain = 0;
124 
125  //Limits of gain 1:
126  //The Lite DTU sends 5 samples before the saturating one, and 10 after with gain 1.
127  //we put the maximum in bin 5, but could happen that the system saturates before.
128 
129  int previousSaturatedSamples = 5;
130  int nextSaturatedSamples = 10;
131  int startingLowerGainSample = 0;
132  int endingLowerGainSample = (firstSaturatedSample[0] + nextSaturatedSamples + (nSaturatedSamples));
133 
134  if (nSaturatedSamples != 0 and (firstSaturatedSample[0] - previousSaturatedSamples) < 0) {
135  startingLowerGainSample = 0;
136  } else {
137  startingLowerGainSample = (firstSaturatedSample[0] - previousSaturatedSamples);
138  }
139 
140  //Setting values to the samples:
141  for (int j = 0; j < nSamples; ++j) {
142  if (nSaturatedSamples != 0 and j >= startingLowerGainSample and j < endingLowerGainSample) {
143  igain = 1;
144  } else {
145  igain = 0;
146  }
147  df.setSample(j, EcalLiteDTUSample(adctrace[j][igain], igain));
148  }
149 }
static constexpr unsigned int NGAINS
Definition: EcalConstants.h:8
CorrelatedNoisifier< EcalCorrMatrix_Ph2 > Noisifier
void noisify(T &frame, CLHEP::HepRandomEngine *, const VecDou *rangau=nullptr) const
double fullScaleEnergy(const DetId &did) const
limit on the energy scale due to the electronics range
static constexpr float gains[NGAINS]
Definition: EcalConstants.h:9
void findIntercalibConstant(const DetId &detId, double &icalconst) const
const Noisifier * m_ebCorrNoise[ecalPh2::NGAINS]
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
constexpr size_t nSamples
Definition: DetId.h:17
void findPedestal(const DetId &detId, int gainId, double &pedestal, double &width) const
void setSample(int i, EcalLiteDTUSample sam)
static constexpr unsigned int MAXADC
Definition: EcalConstants.h:14
uint16_t *__restrict__ uint16_t const *__restrict__ adc
void EcalLiteDTUCoder::findGains ( const DetId detId,
float  theGains[] 
) const
private
void EcalLiteDTUCoder::findIntercalibConstant ( const DetId detId,
double &  icalconst 
) const
private

Definition at line 165 of file EcalLiteDTUCoder.cc.

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

Referenced by encode().

165  {
166  EcalIntercalibConstantMC thisconst = 1.;
167  // find intercalib constant for this xtal
168  const EcalIntercalibConstantMCMap& icalMap = m_intercals->getMap();
169  EcalIntercalibConstantMCMap::const_iterator icalit = icalMap.find(detId);
170  if (icalit != icalMap.end()) {
171  thisconst = (*icalit);
172  } else {
173  LogDebug("EcalLiteDTUCoder") << "Intercalib Constant not found, put default value \n";
174  thisconst = 1.;
175  }
176 
177  if (icalconst == 0.)
178  thisconst = 1.;
179 
180  icalconst = thisconst;
181 }
const self & getMap() const
const EcalIntercalibConstantsMC * m_intercals
std::vector< Item >::const_iterator const_iterator
const_iterator find(uint32_t rawId) const
const_iterator end() const
float EcalIntercalibConstantMC
#define LogDebug(id)
void EcalLiteDTUCoder::findPedestal ( const DetId detId,
int  gainId,
double &  pedestal,
double &  width 
) const
private

Definition at line 151 of file EcalLiteDTUCoder.cc.

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

Referenced by encode().

151  {
153  if (itped != m_peds->getMap().end()) {
154  ped = (*itped).mean(gainId);
155  width = (*itped).rms(gainId);
156  LogDebug("EcalLiteDTUCoder") << "Pedestals for " << detId.rawId() << " gain range " << gainId << " : \n"
157  << "Mean = " << ped << " rms = " << width;
158  } else {
159  LogDebug("EcalLiteDTUCoder") << "Pedestals not found, put default values (ped: 12; width: 2.5) \n";
160  ped = 12.;
161  width = 2.5;
162  }
163 }
const EcalLiteDTUPedestalsMap * m_peds
const self & getMap() const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
constexpr int gainId(sample_type sample)
get the gainId (2 bits)
std::vector< Item >::const_iterator const_iterator
const_iterator find(uint32_t rawId) const
const_iterator end() const
#define LogDebug(id)
double EcalLiteDTUCoder::fullScaleEnergy ( const DetId did) const
private

limit on the energy scale due to the electronics range

Definition at line 33 of file EcalLiteDTUCoder.cc.

References m_maxEneEB.

Referenced by encode().

33 { return m_maxEneEB; }
void EcalLiteDTUCoder::setFullScaleEnergy ( double  EBscale)

Definition at line 25 of file EcalLiteDTUCoder.cc.

References m_maxEneEB, and ecalPh2::maxEneEB.

static constexpr double maxEneEB
Definition: EcalConstants.h:16
void EcalLiteDTUCoder::setGainRatios ( float  gainRatios)

Definition at line 29 of file EcalLiteDTUCoder.cc.

References m_gainRatios.

29 { m_gainRatios = gainRatios; }
void EcalLiteDTUCoder::setIntercalibConstants ( const EcalIntercalibConstantsMC ical)

Definition at line 31 of file EcalLiteDTUCoder.cc.

References m_intercals.

31 { m_intercals = ical; }
const EcalIntercalibConstantsMC * m_intercals
void EcalLiteDTUCoder::setPedestals ( const EcalLiteDTUPedestalsMap pedestals)

can be fetched every event from the EventSetup

Definition at line 27 of file EcalLiteDTUCoder.cc.

References m_peds.

27 { m_peds = pedestals; }
const EcalLiteDTUPedestalsMap * m_peds

Member Data Documentation

bool EcalLiteDTUCoder::m_addNoise
private

Definition at line 69 of file EcalLiteDTUCoder.h.

Referenced by encode().

const Noisifier* EcalLiteDTUCoder::m_ebCorrNoise[ecalPh2::NGAINS]
private

Definition at line 72 of file EcalLiteDTUCoder.h.

Referenced by encode().

float EcalLiteDTUCoder::m_gainRatios
private

Definition at line 63 of file EcalLiteDTUCoder.h.

Referenced by setGainRatios().

const EcalIntercalibConstantsMC* EcalLiteDTUCoder::m_intercals
private

Definition at line 65 of file EcalLiteDTUCoder.h.

Referenced by findIntercalibConstant(), and setIntercalibConstants().

double EcalLiteDTUCoder::m_maxEneEB
private

Definition at line 67 of file EcalLiteDTUCoder.h.

Referenced by fullScaleEnergy(), and setFullScaleEnergy().

const EcalLiteDTUPedestalsMap* EcalLiteDTUCoder::m_peds
private

Definition at line 61 of file EcalLiteDTUCoder.h.

Referenced by findPedestal(), and setPedestals().

bool EcalLiteDTUCoder::m_PreMix1
private

Definition at line 70 of file EcalLiteDTUCoder.h.

Referenced by encode().