CMS 3D CMS Logo

HcalAmplifier.cc
Go to the documentation of this file.
15 
17 
18 #include "CLHEP/Random/RandGaussQ.h"
19 #include "CLHEP/Random/RandFlat.h"
20 
21 #include <cmath>
22 #include <cmath>
23 
24 HcalAmplifier::HcalAmplifier(const CaloVSimParameterMap* parameters, bool addNoise, bool PreMix1, bool PreMix2)
25  : theDbService(nullptr),
26  theParameterMap(parameters),
27  theNoiseSignalGenerator(nullptr),
28  theIonFeedbackSim(nullptr),
29  theTimeSlewSim(nullptr),
30  theStartingCapId(0),
31  addNoise_(addNoise),
32  preMixDigi_(PreMix1),
33  preMixAdd_(PreMix2) {}
34 
39 }
40 
41 void HcalAmplifier::amplify(CaloSamples& frame, CLHEP::HepRandomEngine* engine) const {
42  if (theIonFeedbackSim) {
44  }
45  pe2fC(frame);
46 
47  if (frame.id().det() == DetId::Hcal && ((frame.id().subdetId() == HcalGenericDetId::HcalGenBarrel) ||
48  (frame.id().subdetId() == HcalGenericDetId::HcalGenEndcap))) {
49  const HcalSimParameters& params = static_cast<const HcalSimParameters&>(theParameterMap->simParameters(frame.id()));
50  if (params.delayQIE() > 0)
51  applyQIEdelay(frame, params.delayQIE());
52  }
53 
54  // don't bother for blank signals
55  if (theTimeSlewSim && frame.size() > 4 && frame[4] > 1.e-6) {
57  }
58 
59  // if we are combining pre-mixed digis, we need noise and peds
61  addPedestals(frame, engine);
62  }
63  LogDebug("HcalAmplifier") << frame;
64 }
65 
68  frame *= parameters.photoelectronsToAnalog(frame.id());
69 }
70 
72  DetId detId(cs.id());
73  int maxbin = cs.size();
74  int precisebin = cs.preciseSize();
75  CaloSamples data(detId, maxbin, precisebin); // make a temporary copy
76  data = cs;
77  data.setBlank();
78  data.resetPrecise();
79 
80  for (int i = 0; i < precisebin; i++) {
81  if (i < 2 * delayQIE)
82  data.preciseAtMod(i) += 0.;
83  else
84  data.preciseAtMod(i) += cs.preciseAt(i - 2 * delayQIE);
85  int samplebin = (int)i * maxbin / precisebin;
86  data[samplebin] += data.preciseAt(i);
87  }
88 
89  cs = data; // update the sample
90 }
91 
92 void HcalAmplifier::addPedestals(CaloSamples& frame, CLHEP::HepRandomEngine* engine) const {
93  assert(theDbService != nullptr);
94  HcalGenericDetId hcalGenDetId(frame.id());
95  HcalGenericDetId::HcalGenericSubdetector hcalSubDet = hcalGenDetId.genericSubdet();
96 
97  if (!((frame.id().subdetId() == HcalGenericDetId::HcalGenBarrel) ||
98  (frame.id().subdetId() == HcalGenericDetId::HcalGenEndcap) ||
99  (frame.id().subdetId() == HcalGenericDetId::HcalGenForward) ||
100  (frame.id().subdetId() == HcalGenericDetId::HcalGenOuter)))
101  return;
102 
103  if (hcalGenDetId.isHcalCastorDetId())
104  return;
105  if (hcalGenDetId.isHcalZDCDetId())
106  return;
107 
108  const HcalCalibrationWidths& calibWidths = theDbService->getHcalCalibrationWidths(hcalGenDetId);
109  const HcalCalibrations& calibs = theDbService->getHcalCalibrations(hcalGenDetId);
110 
111  double noise[32] = {0.}; //big enough
112  if (addNoise_) {
113  double gauss[32]; //big enough
114  for (int i = 0; i < frame.size(); i++)
115  gauss[i] = CLHEP::RandGaussQ::shoot(engine, 0., 1.);
116  makeNoise(hcalSubDet, calibWidths, frame.size(), gauss, noise);
117  }
118 
119  if (!preMixDigi_) { // if we are doing initial premix, no pedestals
120  for (int tbin = 0; tbin < frame.size(); ++tbin) {
121  int capId = (theStartingCapId + tbin) % 4;
122  double pedestal = calibs.pedestal(capId) + noise[tbin];
123  frame[tbin] += pedestal;
124  }
125  }
126 }
127 
130  int fFrames,
131  double* fGauss,
132  double* fNoise) const {
133  // This is a simplified noise generation scheme using only the diagonal elements
134  // (proposed by Salavat Abduline).
135  // This is direct adaptation of the code in HcalPedestalWidth.cc
136 
137  // average over capId's
138  double s_xx_mean = 0.25 * (width.pedestal(0) * width.pedestal(0) + width.pedestal(1) * width.pedestal(1) +
139  width.pedestal(2) * width.pedestal(2) + width.pedestal(3) * width.pedestal(3));
140 
141  // Off-diagonal element approximation
142  // In principle should come from averaging the values of elements (0.1), (1,2), (2,3), (3,0)
143  // For now use the definition below (but keep structure of the code structure for development)
144  double s_xy_mean = -0.5 * s_xx_mean;
145  // Use different parameter for HF to reproduce the noise rate after zero suppression.
146  // Steven Won/Jim Hirschauer/Radek Ofierzynski 18.03.2010
147  if (hcalSubDet == HcalGenericDetId::HcalGenForward)
148  s_xy_mean = 0.08 * s_xx_mean;
149 
150  double term = s_xx_mean * s_xx_mean - 2. * s_xy_mean * s_xy_mean;
151 
152  if (term < 0.)
153  term = 1.e-50;
154  double sigma = sqrt(0.5 * (s_xx_mean + sqrt(term)));
155  double corr = sigma == 0. ? 0. : 0.5 * s_xy_mean / sigma;
156 
157  for (int i = 0; i < fFrames; i++) {
158  fNoise[i] = fGauss[i] * sigma;
159  if (i > 0)
160  fNoise[i] += fGauss[i - 1] * corr;
161  if (i < fFrames - 1)
162  fNoise[i] += fGauss[i + 1] * corr;
163  }
164 }
HcalAmplifier::pe2fC
void pe2fC(CaloSamples &frame) const
Definition: HcalAmplifier.cc:66
HcalPedestal.h
hcalSimParameters_cfi.delayQIE
delayQIE
Definition: hcalSimParameters_cfi.py:25
service
Definition: service.py:1
ApeEstimator_cff.width
width
Definition: ApeEstimator_cff.py:24
BeamSpotPI::parameters
parameters
Definition: BeamSpotPayloadInspectorHelper.h:30
HcalCalibrations.h
mps_fire.i
i
Definition: mps_fire.py:428
HcalSimParameters.h
HcalDbService::getHcalCalibrationWidths
const HcalCalibrationWidths & getHcalCalibrationWidths(const HcalGenericDetId &fId) const
Definition: HcalDbService.cc:70
HcalAmplifier::amplify
virtual void amplify(CaloSamples &linearFrame, CLHEP::HepRandomEngine *) const
Definition: HcalAmplifier.cc:41
MessageLogger.h
CaloVSimParameterMap
Definition: CaloVSimParameterMap.h:7
HcalGenericDetId
Definition: HcalGenericDetId.h:15
fwrapper::cs
unique_ptr< ClusterSequence > cs
Definition: fastjetfortran_madfks.cc:47
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
CaloSamples.h
HcalTimeSlewSim::delay
void delay(CaloSamples &samples, CLHEP::HepRandomEngine *, const HcalTimeSlew *hcalTimeSlew_delay) const
Definition: HcalTimeSlewSim.cc:28
DetId::Hcal
Definition: DetId.h:28
HcalAmplifier::theTimeSlew
const HcalTimeSlew * theTimeSlew
Definition: HcalAmplifier.h:37
cms::cuda::assert
assert(be >=bs)
HcalGenericDetId::HcalGenEndcap
Definition: HcalGenericDetId.h:20
HcalAmplifier::HcalAmplifier
HcalAmplifier(const CaloVSimParameterMap *parameters, bool addNoise, bool PreMix1, bool PreMix2)
Definition: HcalAmplifier.cc:24
HPDIonFeedbackSim::addThermalNoise
void addThermalNoise(CaloSamples &samples, CLHEP::HepRandomEngine *)
Definition: HPDIonFeedbackSim.cc:96
HcalDbService::getHcalCalibrations
const HcalCalibrations & getHcalCalibrations(const HcalGenericDetId &fId) const
Definition: HcalDbService.cc:65
CaloVNoiseSignalGenerator.h
DetId
Definition: DetId.h:17
HcalAmplifier::theParameterMap
const CaloVSimParameterMap * theParameterMap
Definition: HcalAmplifier.h:55
HcalGain.h
alignCSCRings.corr
dictionary corr
Definition: alignCSCRings.py:124
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
CaloSimParameters
Main class for Parameters in different subdetectors.
Definition: CaloSimParameters.h:14
CaloVSimParameterMap::simParameters
virtual const CaloSimParameters & simParameters(const DetId &id) const =0
HcalCalibrations
Definition: HcalCalibrations.h:9
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
HcalGenericDetId::HcalGenericSubdetector
HcalGenericSubdetector
Definition: HcalGenericDetId.h:17
HcalAmplifier::applyQIEdelay
void applyQIEdelay(CaloSamples &frame, int delayQIE) const
Definition: HcalAmplifier.cc:71
HcalDetId.h
HcalAmplifier::theDbService
const HcalDbService * theDbService
Definition: HcalAmplifier.h:54
HcalAmplifier::preMixDigi_
bool preMixDigi_
Definition: HcalAmplifier.h:61
createfilelist.int
int
Definition: createfilelist.py:10
CaloVSimParameterMap.h
HcalGenericDetId::HcalGenBarrel
Definition: HcalGenericDetId.h:19
EcalCondDBWriter_cfi.pedestal
pedestal
Definition: EcalCondDBWriter_cfi.py:49
CaloSamples
Definition: CaloSamples.h:14
gpuVertexFinder::noise
__shared__ int noise
Definition: gpuFitVertices.h:50
HPDIonFeedbackSim.h
HcalAmplifier::addNoise_
bool addNoise_
Definition: HcalAmplifier.h:60
HcalSimParameters
Definition: HcalSimParameters.h:10
HcalAmplifier::theTimeSlewSim
HcalTimeSlewSim * theTimeSlewSim
Definition: HcalAmplifier.h:58
HcalDbService
Definition: HcalDbService.h:23
HcalAmplifier::theIonFeedbackSim
HPDIonFeedbackSim * theIonFeedbackSim
Definition: HcalAmplifier.h:57
HcalCalibrations::pedestal
constexpr double pedestal(int fCapId) const
get pedestal for capid=0..3
Definition: HcalCalibrations.h:46
HcalPedestalWidth.h
HcalGenericDetId::genericSubdet
HcalGenericSubdetector genericSubdet() const
Definition: HcalGenericDetId.cc:21
amptDefault_cfi.frame
frame
Definition: amptDefault_cfi.py:12
HcalAmplifier::preMixAdd_
bool preMixAdd_
Definition: HcalAmplifier.h:62
HcalAmplifier::makeNoise
void makeNoise(HcalGenericDetId::HcalGenericSubdetector hcalSubDet, const HcalCalibrationWidths &width, int fFrames, double *fGauss, double *fNoise) const
Definition: HcalAmplifier.cc:128
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
HcalAmplifier::addPedestals
void addPedestals(CaloSamples &frame, CLHEP::HepRandomEngine *) const
Definition: HcalAmplifier.cc:92
HcalDbService.h
HcalGenericDetId::HcalGenOuter
Definition: HcalGenericDetId.h:21
HcalGainWidth.h
HcalAmplifier.h
HcalAmplifier::theNoiseSignalGenerator
const CaloVNoiseSignalGenerator * theNoiseSignalGenerator
Definition: HcalAmplifier.h:56
HcalCalibrationWidths
Definition: HcalCalibrationWidths.h:9
HcalGenericDetId::HcalGenForward
Definition: HcalGenericDetId.h:22
HPDIonFeedbackSim::setDbService
void setDbService(const HcalDbService *service)
Definition: HPDIonFeedbackSim.h:34
CaloVNoiseSignalGenerator::contains
bool contains(const DetId &detId) const
Definition: CaloVNoiseSignalGenerator.cc:23
HcalTimeSlewSim.h
HcalAmplifier::setDbService
void setDbService(const HcalDbService *service)
the Producer will probably update this every event
Definition: HcalAmplifier.cc:35
HcalAmplifier::theStartingCapId
unsigned theStartingCapId
Definition: HcalAmplifier.h:59