CMS 3D CMS Logo

EcalLiteDTUCoder.cc
Go to the documentation of this file.
6 
7 #include <iostream>
8 
10  bool PreMix1,
11  EcalLiteDTUCoder::Noisifier* ebCorrNoise0,
12  EcalLiteDTUCoder::Noisifier* ebCorrNoise1)
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
17  m_addNoise(addNoise),
18  m_PreMix1(PreMix1),
19  m_ebCorrNoise{ebCorrNoise0, ebCorrNoise1}
20 
21 {}
22 
24 
26 
27 void EcalLiteDTUCoder::setPedestals(const EcalLiteDTUPedestalsMap* pedestals) { m_peds = pedestals; }
28 
29 void EcalLiteDTUCoder::setGainRatios(float gainRatios) { m_gainRatios = gainRatios; }
30 
32 
33 double EcalLiteDTUCoder::fullScaleEnergy(const DetId& detId) const { return m_maxEneEB; }
34 
35 void EcalLiteDTUCoder::analogToDigital(CLHEP::HepRandomEngine* engine,
36  const EcalSamples& clf,
37  EcalDataFrame_Ph2& df) const {
38  df.setSize(clf.size());
39  encode(clf, df, engine);
40 }
41 
42 void EcalLiteDTUCoder::encode(const EcalSamples& ecalSamples,
44  CLHEP::HepRandomEngine* engine) const {
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) {
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 }
150 
151 void EcalLiteDTUCoder::findPedestal(const DetId& detId, int gainId, double& ped, double& width) const {
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 }
164 
165 void EcalLiteDTUCoder::findIntercalibConstant(const DetId& detId, double& icalconst) const {
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 }
EcalLiteDTUCoder::setFullScaleEnergy
void setFullScaleEnergy(double EBscale)
Definition: EcalLiteDTUCoder.cc:25
EcalCondObjectContainer::getMap
const self & getMap() const
Definition: EcalCondObjectContainer.h:78
EcalCondObjectContainer::end
const_iterator end() const
Definition: EcalCondObjectContainer.h:74
ecalLiteDTU::gainId
constexpr int gainId(sample_type sample)
get the gainId (2 bits)
Definition: EcalLiteDTUSample.h:14
ApeEstimator_cff.width
width
Definition: ApeEstimator_cff.py:24
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
CaloTSamplesBase::id
DetId id() const
EcalDataFrame_Ph2
Definition: EcalDataFrame_Ph2.h:12
EcalLiteDTUCoder::findIntercalibConstant
void findIntercalibConstant(const DetId &detId, double &icalconst) const
Definition: EcalLiteDTUCoder.cc:165
EcalLiteDTUCoder::fullScaleEnergy
double fullScaleEnergy(const DetId &did) const
limit on the energy scale due to the electronics range
Definition: EcalLiteDTUCoder.cc:33
ecalPh2::MAXADC
static constexpr unsigned int MAXADC
Definition: EcalConstants.h:14
gpuClustering::adc
uint16_t *__restrict__ uint16_t const *__restrict__ adc
Definition: gpuClusterChargeCut.h:20
EcalLiteDTUCoder::m_intercals
const EcalIntercalibConstantsMC * m_intercals
Definition: EcalLiteDTUCoder.h:65
EcalLiteDTUCoder::~EcalLiteDTUCoder
virtual ~EcalLiteDTUCoder()
dtor
Definition: EcalLiteDTUCoder.cc:23
EcalLiteDTUCoder::m_gainRatios
float m_gainRatios
Definition: EcalLiteDTUCoder.h:63
EcalLiteDTUCoder::m_PreMix1
bool m_PreMix1
Definition: EcalLiteDTUCoder.h:70
EcalLiteDTUCoder::analogToDigital
virtual void analogToDigital(CLHEP::HepRandomEngine *, const EcalSamples &clf, EcalDataFrame_Ph2 &df) const
from EcalSamples to EcalDataFrame_Ph2
Definition: EcalLiteDTUCoder.cc:35
CaloTSamplesBase::size
uint32_t size() const
EcalCondObjectContainer
Definition: EcalCondObjectContainer.h:13
PresampleTask_cfi.nSamples
nSamples
Definition: PresampleTask_cfi.py:7
EcalLiteDTUCoder::setPedestals
void setPedestals(const EcalLiteDTUPedestalsMap *pedestals)
can be fetched every event from the EventSetup
Definition: EcalLiteDTUCoder.cc:27
EcalLiteDTUSample.h
CorrelatedNoisifier.h
EcalLiteDTUCoder::findPedestal
void findPedestal(const DetId &detId, int gainId, double &pedestal, double &width) const
Definition: EcalLiteDTUCoder.cc:151
DetId
Definition: DetId.h:17
EcalLiteDTUCoder::m_addNoise
bool m_addNoise
Definition: EcalLiteDTUCoder.h:69
CaloTSamples
Definition: CaloTSamples.h:14
CorrelatedNoisifier::noisify
void noisify(T &frame, CLHEP::HepRandomEngine *, const VecDou *rangau=nullptr) const
EcalDataFrame_Ph2.h
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
EcalLiteDTUCoder.h
EcalCondObjectContainer::find
const_iterator find(uint32_t rawId) const
Definition: EcalCondObjectContainer.h:53
EcalLiteDTUCoder::EcalLiteDTUCoder
EcalLiteDTUCoder(bool addNoise, bool PreMix1, Noisifier *ebCorrNoise0, Noisifier *ebCorrNoise1=nullptr)
ctor
Definition: EcalLiteDTUCoder.cc:9
EcalLiteDTUCoder::m_maxEneEB
double m_maxEneEB
Definition: EcalLiteDTUCoder.h:67
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
EcalLiteDTUSample
Definition: EcalLiteDTUSample.h:25
EcalLiteDTUCoder::m_peds
const EcalLiteDTUPedestalsMap * m_peds
Definition: EcalLiteDTUCoder.h:61
CaloSamples
Definition: CaloSamples.h:14
ecalPh2
Definition: EcalConstants.h:5
CorrelatedNoisifier
adds noise to the given frame.
Definition: EcalCoder.h:12
EcalLiteDTUCoder::setIntercalibConstants
void setIntercalibConstants(const EcalIntercalibConstantsMC *ical)
Definition: EcalLiteDTUCoder.cc:31
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
EcalIntercalibConstantMC
float EcalIntercalibConstantMC
Definition: EcalIntercalibConstantsMC.h:10
hgcalPerformanceValidation.df
df
Definition: hgcalPerformanceValidation.py:733
EcalLiteDTUCoder::encode
void encode(const EcalSamples &ecalSamples, EcalDataFrame_Ph2 &df, CLHEP::HepRandomEngine *) const
produce the pulse-shape
Definition: EcalLiteDTUCoder.cc:42
EcalLiteDTUCoder::setGainRatios
void setGainRatios(float gainRatios)
Definition: EcalLiteDTUCoder.cc:29
ecalPh2::gains
static constexpr float gains[NGAINS]
Definition: EcalConstants.h:9
EcalLiteDTUCoder::m_ebCorrNoise
const Noisifier * m_ebCorrNoise[ecalPh2::NGAINS]
Definition: EcalLiteDTUCoder.h:72
EcalCondObjectContainer::const_iterator
std::vector< Item >::const_iterator const_iterator
Definition: EcalCondObjectContainer.h:19
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ecalPh2::maxEneEB
static constexpr double maxEneEB
Definition: EcalConstants.h:16
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
ecalPh2::NGAINS
static constexpr unsigned int NGAINS
Definition: EcalConstants.h:8