CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
36  theDbService = service;
39 }
40 
41 void HcalAmplifier::amplify(CaloSamples& frame, CLHEP::HepRandomEngine* engine) const {
42  if (theIonFeedbackSim) {
43  theIonFeedbackSim->addThermalNoise(frame, engine);
44  }
45  pe2fC(frame);
46  // don't bother for blank signals
47  if (theTimeSlewSim && frame.size() > 4 && frame[4] > 1.e-6) {
48  theTimeSlewSim->delay(frame, engine, theTimeSlew);
49  }
50 
51  // if we are combining pre-mixed digis, we need noise and peds
52  if (theNoiseSignalGenerator == nullptr || preMixAdd_ || !theNoiseSignalGenerator->contains(frame.id())) {
53  addPedestals(frame, engine);
54  }
55  LogDebug("HcalAmplifier") << frame;
56 }
57 
60  frame *= parameters.photoelectronsToAnalog(frame.id());
61 }
62 
63 void HcalAmplifier::addPedestals(CaloSamples& frame, CLHEP::HepRandomEngine* engine) const {
64  assert(theDbService != nullptr);
65  HcalGenericDetId hcalGenDetId(frame.id());
66  HcalGenericDetId::HcalGenericSubdetector hcalSubDet = hcalGenDetId.genericSubdet();
67 
68  if (!((frame.id().subdetId() == HcalGenericDetId::HcalGenBarrel) ||
72  return;
73 
74  if (hcalGenDetId.isHcalCastorDetId())
75  return;
76  if (hcalGenDetId.isHcalZDCDetId())
77  return;
78 
79  const HcalCalibrationWidths& calibWidths = theDbService->getHcalCalibrationWidths(hcalGenDetId);
80  const HcalCalibrations& calibs = theDbService->getHcalCalibrations(hcalGenDetId);
81 
82  double noise[32] = {0.}; //big enough
83  if (addNoise_) {
84  double gauss[32]; //big enough
85  for (int i = 0; i < frame.size(); i++)
86  gauss[i] = CLHEP::RandGaussQ::shoot(engine, 0., 1.);
87  makeNoise(hcalSubDet, calibWidths, frame.size(), gauss, noise);
88  }
89 
90  if (!preMixDigi_) { // if we are doing initial premix, no pedestals
91  for (int tbin = 0; tbin < frame.size(); ++tbin) {
92  int capId = (theStartingCapId + tbin) % 4;
93  double pedestal = calibs.pedestal(capId) + noise[tbin];
94  frame[tbin] += pedestal;
95  }
96  }
97 }
98 
101  int fFrames,
102  double* fGauss,
103  double* fNoise) const {
104  // This is a simplified noise generation scheme using only the diagonal elements
105  // (proposed by Salavat Abduline).
106  // This is direct adaptation of the code in HcalPedestalWidth.cc
107 
108  // average over capId's
109  double s_xx_mean = 0.25 * (width.pedestal(0) * width.pedestal(0) + width.pedestal(1) * width.pedestal(1) +
110  width.pedestal(2) * width.pedestal(2) + width.pedestal(3) * width.pedestal(3));
111 
112  // Off-diagonal element approximation
113  // In principle should come from averaging the values of elements (0.1), (1,2), (2,3), (3,0)
114  // For now use the definition below (but keep structure of the code structure for development)
115  double s_xy_mean = -0.5 * s_xx_mean;
116  // Use different parameter for HF to reproduce the noise rate after zero suppression.
117  // Steven Won/Jim Hirschauer/Radek Ofierzynski 18.03.2010
118  if (hcalSubDet == HcalGenericDetId::HcalGenForward)
119  s_xy_mean = 0.08 * s_xx_mean;
120 
121  double term = s_xx_mean * s_xx_mean - 2. * s_xy_mean * s_xy_mean;
122 
123  if (term < 0.)
124  term = 1.e-50;
125  double sigma = sqrt(0.5 * (s_xx_mean + sqrt(term)));
126  double corr = sigma == 0. ? 0. : 0.5 * s_xy_mean / sigma;
127 
128  for (int i = 0; i < fFrames; i++) {
129  fNoise[i] = fGauss[i] * sigma;
130  if (i > 0)
131  fNoise[i] += fGauss[i - 1] * corr;
132  if (i < fFrames - 1)
133  fNoise[i] += fGauss[i + 1] * corr;
134  }
135 }
#define LogDebug(id)
void setDbService(const HcalDbService *service)
the Producer will probably update this every event
const CaloVNoiseSignalGenerator * theNoiseSignalGenerator
Definition: HcalAmplifier.h:55
const CaloVSimParameterMap * theParameterMap
Definition: HcalAmplifier.h:54
#define nullptr
const HcalTimeSlew * theTimeSlew
Definition: HcalAmplifier.h:37
Main class for Parameters in different subdetectors.
HcalAmplifier(const CaloVSimParameterMap *parameters, bool addNoise, bool PreMix1, bool PreMix2)
void addThermalNoise(CaloSamples &samples, CLHEP::HepRandomEngine *)
double pedestal(int fCapId) const
get pedestal width for capid=0..3
const HcalDbService * theDbService
Definition: HcalAmplifier.h:53
T sqrt(T t)
Definition: SSEVec.h:19
virtual const CaloSimParameters & simParameters(const DetId &id) const =0
bool contains(const DetId &detId) const
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
void delay(CaloSamples &samples, CLHEP::HepRandomEngine *, const HcalTimeSlew *hcalTimeSlew_delay) const
const HcalCalibrationWidths & getHcalCalibrationWidths(const HcalGenericDetId &fId) const
virtual void amplify(CaloSamples &linearFrame, CLHEP::HepRandomEngine *) const
HcalTimeSlewSim * theTimeSlewSim
Definition: HcalAmplifier.h:57
JetCorrectorParameters corr
Definition: classes.h:5
constexpr double pedestal(int fCapId) const
get pedestal for capid=0..3
int size() const
get the size
Definition: CaloSamples.h:24
unsigned theStartingCapId
Definition: HcalAmplifier.h:58
void addPedestals(CaloSamples &frame, CLHEP::HepRandomEngine *) const
void pe2fC(CaloSamples &frame) const
void makeNoise(HcalGenericDetId::HcalGenericSubdetector hcalSubDet, const HcalCalibrationWidths &width, int fFrames, double *fGauss, double *fNoise) const
DetId id() const
get the (generic) id
Definition: CaloSamples.h:21
HPDIonFeedbackSim * theIonFeedbackSim
Definition: HcalAmplifier.h:56
HcalGenericSubdetector genericSubdet() const
const HcalCalibrations & getHcalCalibrations(const HcalGenericDetId &fId) const
void setDbService(const HcalDbService *service)
double photoelectronsToAnalog() const
the factor which goes from photoelectrons to whatever gets read by ADCs