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<iostream>
19 #include <cmath>
20 #include <math.h>
21 
23  theDbService(0),
24  theRandGaussQ(0),
25  theRandFlat(0),
26  theParameterMap(parameters),
27  theNoiseSignalGenerator(0),
28  theIonFeedbackSim(0),
29  theTimeSlewSim(0),
30  theStartingCapId(0),
31  addNoise_(addNoise),
32  useOldHB(false),
33  useOldHE(false),
34  useOldHF(false),
35  useOldHO(false)
36 {
37 }
38 
39 
41  theDbService = service;
43 }
44 
45 
46 void HcalAmplifier::setRandomEngine(CLHEP::HepRandomEngine & engine)
47 {
48  theRandGaussQ = new CLHEP::RandGaussQ(engine);
49  theRandFlat = new CLHEP::RandFlat(engine);
51 }
52 
53 
54 void HcalAmplifier::amplify(CaloSamples & frame) const {
56  {
58  }
59  pe2fC(frame);
60  // don't bother for blank signals
61  if(theTimeSlewSim && frame[4] > 1.e-6)
62  {
63  theTimeSlewSim->delay(frame);
64  }
66  {
67  addPedestals(frame);
68  }
69  LogDebug("HcalAmplifier") << frame;
70 }
71 
72 
73 void HcalAmplifier::pe2fC(CaloSamples & frame) const
74 {
76  frame *= parameters.photoelectronsToAnalog(frame.id());
77 }
78 
79 void HcalAmplifier::setHBtuningParameter(double tp) { HB_ff = tp; }
80 void HcalAmplifier::setHEtuningParameter(double tp) { HE_ff = tp; }
81 void HcalAmplifier::setHFtuningParameter(double tp) { HF_ff = tp; }
82 void HcalAmplifier::setHOtuningParameter(double tp) { HO_ff = tp; }
83 void HcalAmplifier::setUseOldHB(bool useOld) { useOldHB = useOld; }
84 void HcalAmplifier::setUseOldHE(bool useOld) { useOldHE = useOld; }
85 void HcalAmplifier::setUseOldHF(bool useOld) { useOldHF = useOld; }
86 void HcalAmplifier::setUseOldHO(bool useOld) { useOldHO = useOld; }
87 
89 {
90  assert(theDbService != 0);
91  HcalGenericDetId hcalGenDetId(frame.id());
92  HcalGenericDetId::HcalGenericSubdetector hcalSubDet = hcalGenDetId.genericSubdet();
93 
94  bool useOld=false;
95  if(hcalSubDet==HcalGenericDetId::HcalGenBarrel) useOld = useOldHB;
96  if(hcalSubDet==HcalGenericDetId::HcalGenEndcap) useOld = useOldHE;
97  if(hcalSubDet==HcalGenericDetId::HcalGenForward) useOld = useOldHF;
98  if(hcalSubDet==HcalGenericDetId::HcalGenOuter) useOld = useOldHO;
99 
100  if(useOld)
101  {
102  const HcalCalibrationWidths & calibWidths =
103  theDbService->getHcalCalibrationWidths(hcalGenDetId);
104  const HcalCalibrations& calibs = theDbService->getHcalCalibrations(hcalGenDetId);
105 
106  double noise [32] = {0.}; //big enough
107  if(addNoise_)
108  {
109  double gauss [32]; //big enough
110  for (int i = 0; i < frame.size(); i++) gauss[i] = theRandGaussQ->fire(0., 1.);
111  makeNoiseOld(hcalSubDet, calibWidths, frame.size(), gauss, noise);
112  }
113 
114  for (int tbin = 0; tbin < frame.size(); ++tbin) {
115  int capId = (theStartingCapId + tbin)%4;
116  double pedestal = calibs.pedestal(capId) + noise[tbin];
117  frame[tbin] += pedestal;
118  }
119  return;
120  }
121 
122 
123  double fudgefactor = 1;
124  if(hcalSubDet==HcalGenericDetId::HcalGenBarrel) fudgefactor = HB_ff;
125  if(hcalSubDet==HcalGenericDetId::HcalGenEndcap) fudgefactor = HE_ff;
126  if(hcalSubDet==HcalGenericDetId::HcalGenForward) fudgefactor = HF_ff;
127  if(hcalSubDet==HcalGenericDetId::HcalGenOuter) fudgefactor = HO_ff;
128  if(hcalGenDetId.isHcalCastorDetId()) return;
129  if(hcalGenDetId.isHcalZDCDetId()) return;
130 
131  const HcalCholeskyMatrix * thisChanCholesky = myCholeskys->getValues(hcalGenDetId);
132  const HcalPedestal * thisChanADCPeds = myADCPeds->getValues(hcalGenDetId);
133  int theStartingCapId_2 = (int)floor(theRandFlat->fire(0.,4.));
134 
135  double noise [32] = {0.}; //big enough
136  if(addNoise_)
137  {
138  double gauss [32]; //big enough
139  for (int i = 0; i < frame.size(); i++) gauss[i] = theRandGaussQ->fire(0., 1.);
140  makeNoise(*thisChanCholesky, frame.size(), gauss, noise, (int)theStartingCapId_2);
141  }
142 
143  const HcalQIECoder* coder = theDbService->getHcalCoder(hcalGenDetId);
144  const HcalQIEShape* shape = theDbService->getHcalShape();
145 
146  for (int tbin = 0; tbin < frame.size(); ++tbin) {
147  int capId = (theStartingCapId_2 + tbin)%4;
148  double x = noise[tbin] * fudgefactor + thisChanADCPeds->getValue(capId);//*(values+capId); //*.70 goes here!
149  int x1=(int)std::floor(x);
150  int x2=(int)std::floor(x+1);
151  float y2=coder->charge(*shape,x2,capId);
152  float y1=coder->charge(*shape,x1,capId);
153  frame[tbin] = (y2-y1)*(x-x1)+y1;
154  }
155 }
156 
157 void HcalAmplifier::makeNoise (const HcalCholeskyMatrix & thisChanCholesky, int fFrames, double* fGauss, double* fNoise, int m) const {
158  if(fFrames > 10) return;
159 
160  for(int i = 0; i != 10; i++){
161  for(int j = 0; j != 10; j++){ //fNoise is initialized to zero in function above! Must be zero before this step
162  fNoise[i] += thisChanCholesky.getValue(m,i,j) * fGauss[j];
163  }
164  }
165 }
166 
167 void HcalAmplifier::makeNoiseOld (HcalGenericDetId::HcalGenericSubdetector hcalSubDet, const HcalCalibrationWidths& width, int fFrames, double* fGauss, double* fNoise) const
168 {
169  // This is a simplified noise generation scheme using only the diagonal elements
170  // (proposed by Salavat Abduline).
171  // This is direct adaptation of the code in HcalPedestalWidth.cc
172 
173  // average over capId's
174  double s_xx_mean = 0.25 * (width.pedestal(0)*width.pedestal(0) +
175  width.pedestal(1)*width.pedestal(1) +
176  width.pedestal(2)*width.pedestal(2) +
177  width.pedestal(3)*width.pedestal(3));
178 
179 
180  // Off-diagonal element approximation
181  // In principle should come from averaging the values of elements (0.1), (1,2), (2,3), (3,0)
182  // For now use the definition below (but keep structure of the code structure for development)
183  double s_xy_mean = -0.5 * s_xx_mean;
184  // Use different parameter for HF to reproduce the noise rate after zero suppression.
185  // Steven Won/Jim Hirschauer/Radek Ofierzynski 18.03.2010
186  if (hcalSubDet == HcalGenericDetId::HcalGenForward) s_xy_mean = 0.08 * s_xx_mean;
187 
188  double term = s_xx_mean*s_xx_mean - 2.*s_xy_mean*s_xy_mean;
189 
190  if (term < 0.) term = 1.e-50 ;
191  double sigma = sqrt (0.5 * (s_xx_mean + sqrt(term)));
192  double corr = sigma == 0. ? 0. : 0.5*s_xy_mean / sigma;
193 
194  for (int i = 0; i < fFrames; i++) {
195  fNoise [i] = fGauss[i]*sigma;
196  if (i > 0) fNoise [i] += fGauss[i-1]*corr;
197  if (i < fFrames-1) fNoise [i] += fGauss[i+1]*corr;
198  }
199 }
200 
#define LogDebug(id)
void setUseOldHB(bool useOld)
float getValue(int capid, int i, int j) const
void setHOtuningParameter(double tp)
void makeNoiseOld(HcalGenericDetId::HcalGenericSubdetector hcalSubDet, const HcalCalibrationWidths &width, int fFrames, double *fGauss, double *fNoise) const
void setDbService(const HcalDbService *service)
the Producer will probably update this every event
const CaloVNoiseSignalGenerator * theNoiseSignalGenerator
Definition: HcalAmplifier.h:65
int i
Definition: DBlmapReader.cc:9
dictionary parameters
Definition: Parameters.py:2
void addThermalNoise(CaloSamples &samples)
const CaloVSimParameterMap * theParameterMap
Definition: HcalAmplifier.h:64
void setUseOldHF(bool useOld)
double pedestal(int fCapId) const
get pedestal for capid=0..3
void setHFtuningParameter(double tp)
Main class for Parameters in different subdetectors.
CLHEP::RandGaussQ * theRandGaussQ
Definition: HcalAmplifier.h:62
void setUseOldHO(bool useOld)
const HcalTimeSlewSim * theTimeSlewSim
Definition: HcalAmplifier.h:67
void setHEtuningParameter(double tp)
void setUseOldHE(bool useOld)
double pedestal(int fCapId) const
get pedestal width for capid=0..3
void setRandomEngine(CLHEP::HepRandomEngine &engine)
need a shaper in order to set thermal noise
const HcalDbService * theDbService
Definition: HcalAmplifier.h:61
T sqrt(T t)
Definition: SSEVec.h:46
void setRandomEngine(CLHEP::HepRandomEngine &engine)
bool contains(const DetId &detId) const
int j
Definition: DBlmapReader.cc:9
virtual const CaloSimParameters & simParameters(const DetId &id) const =0
float getValue(int fCapId) const
get value for capId = 0..3
Definition: HcalPedestal.h:19
const HcalCalibrationWidths & getHcalCalibrationWidths(const HcalGenericDetId &fId) const
JetCorrectorParameters corr
Definition: classes.h:9
HcalAmplifier(const CaloVSimParameterMap *parameters, bool addNoise)
int size() const
get the size
Definition: CaloSamples.h:24
virtual void amplify(CaloSamples &linearFrame) const
void makeNoise(const HcalCholeskyMatrix &thisChanCholesky, int fFrames, double *fGauss, double *fNoise, int m) const
const HcalQIECoder * getHcalCoder(const HcalGenericDetId &fId) const
void delay(CaloSamples &samples) const
unsigned theStartingCapId
Definition: HcalAmplifier.h:68
void addPedestals(CaloSamples &frame) const
void pe2fC(CaloSamples &frame) const
const HcalCholeskyMatrix * getValues(DetId fId) const
CLHEP::RandFlat * theRandFlat
Definition: HcalAmplifier.h:63
DetId id() const
get the (generic) id
Definition: CaloSamples.h:21
HPDIonFeedbackSim * theIonFeedbackSim
Definition: HcalAmplifier.h:66
HcalGenericSubdetector genericSubdet() const
void setHBtuningParameter(double tp)
x
Definition: VDTMath.h:216
const HcalCalibrations & getHcalCalibrations(const HcalGenericDetId &fId) const
const Item * getValues(DetId fId) const
void setDbService(const HcalDbService *service)
const HcalPedestals * myADCPeds
Definition: HcalAmplifier.h:80
double photoelectronsToAnalog() const
the factor which goes from photoelectrons to whatever gets read by ADCs
const HcalQIEShape * getHcalShape() const
const HcalCholeskyMatrices * myCholeskys
Definition: HcalAmplifier.h:79
float charge(const HcalQIEShape &fShape, unsigned fAdc, unsigned fCapId) const
ADC [0..127] + capid [0..3] -&gt; fC conversion.
Definition: HcalQIECoder.cc:22