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