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