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 
22 HcalAmplifier::HcalAmplifier(const CaloVSimParameterMap * parameters, bool addNoise, bool PreMix1, bool PreMix2) :
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  preMixDigi_(PreMix1),
33  preMixAdd_(PreMix2),
34  useOldHB(false),
35  useOldHE(false),
36  useOldHF(false),
37  useOldHO(false)
38 { }
39 
40 
42  theDbService = service;
44 }
45 
46 
47 void HcalAmplifier::setRandomEngine(CLHEP::HepRandomEngine & engine)
48 {
49  theRandGaussQ = new CLHEP::RandGaussQ(engine);
50  theRandFlat = new CLHEP::RandFlat(engine);
52 }
53 
54 
55 void HcalAmplifier::amplify(CaloSamples & frame) const {
57  {
59  }
60  pe2fC(frame);
61  // don't bother for blank signals
62  if(theTimeSlewSim && frame[4] > 1.e-6)
63  {
64  theTimeSlewSim->delay(frame);
65  }
66 
67  // if we are combining pre-mixed digis, we need noise and peds
69  {
70  addPedestals(frame);
71  }
72  LogDebug("HcalAmplifier") << frame;
73 }
74 
75 
76 void HcalAmplifier::pe2fC(CaloSamples & frame) const
77 {
79  frame *= parameters.photoelectronsToAnalog(frame.id());
80 }
81 
82 void HcalAmplifier::setHBtuningParameter(double tp) { HB_ff = tp; }
83 void HcalAmplifier::setHEtuningParameter(double tp) { HE_ff = tp; }
84 void HcalAmplifier::setHFtuningParameter(double tp) { HF_ff = tp; }
85 void HcalAmplifier::setHOtuningParameter(double tp) { HO_ff = tp; }
86 void HcalAmplifier::setUseOldHB(bool useOld) { useOldHB = useOld; }
87 void HcalAmplifier::setUseOldHE(bool useOld) { useOldHE = useOld; }
88 void HcalAmplifier::setUseOldHF(bool useOld) { useOldHF = useOld; }
89 void HcalAmplifier::setUseOldHO(bool useOld) { useOldHO = useOld; }
90 
92 {
93  assert(theDbService != 0);
94  HcalGenericDetId hcalGenDetId(frame.id());
95  HcalGenericDetId::HcalGenericSubdetector hcalSubDet = hcalGenDetId.genericSubdet();
96 
97  bool useOld=false;
98  if(hcalSubDet==HcalGenericDetId::HcalGenBarrel) useOld = useOldHB;
99  if(hcalSubDet==HcalGenericDetId::HcalGenEndcap) useOld = useOldHE;
100  if(hcalSubDet==HcalGenericDetId::HcalGenForward) useOld = useOldHF;
101  if(hcalSubDet==HcalGenericDetId::HcalGenOuter) useOld = useOldHO;
102 
103  if(useOld)
104  {
105  const HcalCalibrationWidths & calibWidths =
106  theDbService->getHcalCalibrationWidths(hcalGenDetId);
107  const HcalCalibrations& calibs = theDbService->getHcalCalibrations(hcalGenDetId);
108 
109  double noise [32] = {0.}; //big enough
110  if(addNoise_)
111  {
112  double gauss [32]; //big enough
113  for (int i = 0; i < frame.size(); i++) gauss[i] = theRandGaussQ->fire(0., 1.);
114  makeNoiseOld(hcalSubDet, calibWidths, frame.size(), gauss, noise);
115  }
116 
117  if(!preMixDigi_){ // if we are doing initial premix, no pedestals
118  for (int tbin = 0; tbin < frame.size(); ++tbin) {
119  int capId = (theStartingCapId + tbin)%4;
120  double pedestal = calibs.pedestal(capId) + noise[tbin];
121 
122  frame[tbin] += pedestal;
123  }
124  }
125  return;
126  }
127 
128 
129  double fudgefactor = 1;
130  if(hcalSubDet==HcalGenericDetId::HcalGenBarrel) fudgefactor = HB_ff;
131  if(hcalSubDet==HcalGenericDetId::HcalGenEndcap) fudgefactor = HE_ff;
132  if(hcalSubDet==HcalGenericDetId::HcalGenForward) fudgefactor = HF_ff;
133  if(hcalSubDet==HcalGenericDetId::HcalGenOuter) fudgefactor = HO_ff;
134 
135  if ( !( (frame.id().subdetId()==HcalGenericDetId::HcalGenBarrel) ||
138  (frame.id().subdetId()==HcalGenericDetId::HcalGenOuter) ) ) return;
139 
140  if(hcalGenDetId.isHcalCastorDetId()) return;
141  if(hcalGenDetId.isHcalZDCDetId()) return;
142 
143  const HcalCholeskyMatrix * thisChanCholesky = myCholeskys->getValues(hcalGenDetId,false);
144  if ( !thisChanCholesky) {
145  std::cout << "no Cholesky " << hcalSubDet << " " << hcalGenDetId.rawId() << " " << frame.id().subdetId() <<std::endl;
146  return;
147  }
148  const HcalPedestal * thisChanADCPeds = myADCPeds->getValues(hcalGenDetId);
149  int theStartingCapId_2 = (int)floor(theRandFlat->fire(0.,4.));
150 
151  double noise [32] = {0.}; //big enough
152  if(addNoise_)
153  {
154  double gauss [32]; //big enough
155  for (int i = 0; i < frame.size(); i++) gauss[i] = theRandGaussQ->fire(0., 1.);
156  makeNoise(*thisChanCholesky, frame.size(), gauss, noise, (int)theStartingCapId_2);
157  }
158 
159  const HcalQIECoder* coder = theDbService->getHcalCoder(hcalGenDetId);
160  const HcalQIEShape* shape = theDbService->getHcalShape(coder);
161 
162  for (int tbin = 0; tbin < frame.size(); ++tbin) {
163  int capId = (theStartingCapId_2 + tbin)%4;
164  double x = noise[tbin] * fudgefactor + thisChanADCPeds->getValue(capId);//*(values+capId); //*.70 goes here!
165  int x1=(int)std::floor(x);
166  int x2=(int)std::floor(x+1);
167  float y2=coder->charge(*shape,x2,capId);
168  float y1=coder->charge(*shape,x1,capId);
169  frame[tbin] = (y2-y1)*(x-x1)+y1;
170  }
171 }
172 
173 void HcalAmplifier::makeNoise (const HcalCholeskyMatrix & thisChanCholesky, int fFrames, double* fGauss, double* fNoise, int m) const {
174  if(fFrames > 10) return;
175 
176  for(int i = 0; i != 10; i++){
177  for(int j = 0; j != 10; j++){ //fNoise is initialized to zero in function above! Must be zero before this step
178  fNoise[i] += thisChanCholesky.getValue(m,i,j) * fGauss[j];
179  }
180  }
181 }
182 
183 void HcalAmplifier::makeNoiseOld (HcalGenericDetId::HcalGenericSubdetector hcalSubDet, const HcalCalibrationWidths& width, int fFrames, double* fGauss, double* fNoise) const
184 {
185  // This is a simplified noise generation scheme using only the diagonal elements
186  // (proposed by Salavat Abduline).
187  // This is direct adaptation of the code in HcalPedestalWidth.cc
188 
189  // average over capId's
190  double s_xx_mean = 0.25 * (width.pedestal(0)*width.pedestal(0) +
191  width.pedestal(1)*width.pedestal(1) +
192  width.pedestal(2)*width.pedestal(2) +
193  width.pedestal(3)*width.pedestal(3));
194 
195 
196  // Off-diagonal element approximation
197  // In principle should come from averaging the values of elements (0.1), (1,2), (2,3), (3,0)
198  // For now use the definition below (but keep structure of the code structure for development)
199  double s_xy_mean = -0.5 * s_xx_mean;
200  // Use different parameter for HF to reproduce the noise rate after zero suppression.
201  // Steven Won/Jim Hirschauer/Radek Ofierzynski 18.03.2010
202  if (hcalSubDet == HcalGenericDetId::HcalGenForward) s_xy_mean = 0.08 * s_xx_mean;
203 
204  double term = s_xx_mean*s_xx_mean - 2.*s_xy_mean*s_xy_mean;
205 
206  if (term < 0.) term = 1.e-50 ;
207  double sigma = sqrt (0.5 * (s_xx_mean + sqrt(term)));
208  double corr = sigma == 0. ? 0. : 0.5*s_xy_mean / sigma;
209 
210  for (int i = 0; i < fFrames; i++) {
211  fNoise [i] = fGauss[i]*sigma;
212  if (i > 0) fNoise [i] += fGauss[i-1]*corr;
213  if (i < fFrames-1) fNoise [i] += fGauss[i+1]*corr;
214  }
215 }
216 
#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
HcalAmplifier(const CaloVSimParameterMap *parameters, bool addNoise, bool PreMix1, bool PreMix2)
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)
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:37
const HcalCalibrationWidths & getHcalCalibrationWidths(const HcalGenericDetId &fId) const
HcalTimeSlewSim * theTimeSlewSim
Definition: HcalAmplifier.h:67
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
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
volatile std::atomic< bool > shutdown_flag false
DetId id() const
get the (generic) id
Definition: CaloSamples.h:21
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:82
double photoelectronsToAnalog() const
the factor which goes from photoelectrons to whatever gets read by ADCs
const HcalCholeskyMatrices * myCholeskys
Definition: HcalAmplifier.h:81
float charge(const HcalQIEShape &fShape, unsigned fAdc, unsigned fCapId) const
ADC [0..127] + capid [0..3] -&gt; fC conversion.
Definition: HcalQIECoder.cc:22