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 
129  if ( !( (frame.id().subdetId()==HcalGenericDetId::HcalGenBarrel) ||
132  (frame.id().subdetId()==HcalGenericDetId::HcalGenOuter) ) ) return;
133 
134  if(hcalGenDetId.isHcalCastorDetId()) return;
135  if(hcalGenDetId.isHcalZDCDetId()) return;
136 
137  const HcalCholeskyMatrix * thisChanCholesky = myCholeskys->getValues(hcalGenDetId,false);
138  if ( !thisChanCholesky) {
139  std::cout << "no Cholesky " << hcalSubDet << " " << hcalGenDetId.rawId() << " " << frame.id().subdetId() <<std::endl;
140  return;
141  }
142  const HcalPedestal * thisChanADCPeds = myADCPeds->getValues(hcalGenDetId);
143  int theStartingCapId_2 = (int)floor(theRandFlat->fire(0.,4.));
144 
145  double noise [32] = {0.}; //big enough
146  if(addNoise_)
147  {
148  double gauss [32]; //big enough
149  for (int i = 0; i < frame.size(); i++) gauss[i] = theRandGaussQ->fire(0., 1.);
150  makeNoise(*thisChanCholesky, frame.size(), gauss, noise, (int)theStartingCapId_2);
151  }
152 
153  const HcalQIECoder* coder = theDbService->getHcalCoder(hcalGenDetId);
154  const HcalQIEShape* shape = theDbService->getHcalShape(coder);
155 
156  for (int tbin = 0; tbin < frame.size(); ++tbin) {
157  int capId = (theStartingCapId_2 + tbin)%4;
158  double x = noise[tbin] * fudgefactor + thisChanADCPeds->getValue(capId);//*(values+capId); //*.70 goes here!
159  int x1=(int)std::floor(x);
160  int x2=(int)std::floor(x+1);
161  float y2=coder->charge(*shape,x2,capId);
162  float y1=coder->charge(*shape,x1,capId);
163  frame[tbin] = (y2-y1)*(x-x1)+y1;
164  }
165 }
166 
167 void HcalAmplifier::makeNoise (const HcalCholeskyMatrix & thisChanCholesky, int fFrames, double* fGauss, double* fNoise, int m) const {
168  if(fFrames > 10) return;
169 
170  for(int i = 0; i != 10; i++){
171  for(int j = 0; j != 10; j++){ //fNoise is initialized to zero in function above! Must be zero before this step
172  fNoise[i] += thisChanCholesky.getValue(m,i,j) * fGauss[j];
173  }
174  }
175 }
176 
177 void HcalAmplifier::makeNoiseOld (HcalGenericDetId::HcalGenericSubdetector hcalSubDet, const HcalCalibrationWidths& width, int fFrames, double* fGauss, double* fNoise) const
178 {
179  // This is a simplified noise generation scheme using only the diagonal elements
180  // (proposed by Salavat Abduline).
181  // This is direct adaptation of the code in HcalPedestalWidth.cc
182 
183  // average over capId's
184  double s_xx_mean = 0.25 * (width.pedestal(0)*width.pedestal(0) +
185  width.pedestal(1)*width.pedestal(1) +
186  width.pedestal(2)*width.pedestal(2) +
187  width.pedestal(3)*width.pedestal(3));
188 
189 
190  // Off-diagonal element approximation
191  // In principle should come from averaging the values of elements (0.1), (1,2), (2,3), (3,0)
192  // For now use the definition below (but keep structure of the code structure for development)
193  double s_xy_mean = -0.5 * s_xx_mean;
194  // Use different parameter for HF to reproduce the noise rate after zero suppression.
195  // Steven Won/Jim Hirschauer/Radek Ofierzynski 18.03.2010
196  if (hcalSubDet == HcalGenericDetId::HcalGenForward) s_xy_mean = 0.08 * s_xx_mean;
197 
198  double term = s_xx_mean*s_xx_mean - 2.*s_xy_mean*s_xy_mean;
199 
200  if (term < 0.) term = 1.e-50 ;
201  double sigma = sqrt (0.5 * (s_xx_mean + sqrt(term)));
202  double corr = sigma == 0. ? 0. : 0.5*s_xy_mean / sigma;
203 
204  for (int i = 0; i < fFrames; i++) {
205  fNoise [i] = fGauss[i]*sigma;
206  if (i > 0) fNoise [i] += fGauss[i-1]*corr;
207  if (i < fFrames-1) fNoise [i] += fGauss[i+1]*corr;
208  }
209 }
210 
#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
const Item * getValues(DetId fId, bool throwOnFail=true) const
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:48
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
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
const HcalCalibrationWidths & getHcalCalibrationWidths(const HcalGenericDetId &fId) const
JetCorrectorParameters corr
Definition: classes.h:11
HcalAmplifier(const CaloVSimParameterMap *parameters, bool addNoise)
int size() const
get the size
Definition: CaloSamples.h:26
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
const HcalQIEShape * getHcalShape(const HcalGenericDetId &fId) const
unsigned theStartingCapId
Definition: HcalAmplifier.h:68
void addPedestals(CaloSamples &frame) const
void pe2fC(CaloSamples &frame) const
CLHEP::RandFlat * theRandFlat
Definition: HcalAmplifier.h:63
tuple cout
Definition: gather_cfg.py:121
DetId id() const
get the (generic) id
Definition: CaloSamples.h:23
HPDIonFeedbackSim * theIonFeedbackSim
Definition: HcalAmplifier.h:66
HcalGenericSubdetector genericSubdet() const
Definition: DDAxes.h:10
void setHBtuningParameter(double tp)
const HcalCholeskyMatrix * getValues(DetId fId, bool throwOnFail=true) const
const HcalCalibrations & getHcalCalibrations(const HcalGenericDetId &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 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