CMS 3D CMS Logo

CastorAmplifier.cc
Go to the documentation of this file.
11 
12 #include "CLHEP/Random/RandGaussQ.h"
13 
14 #include <iostream>
15 
17  : theDbService(nullptr), theParameterMap(parameters), theStartingCapId(0), addNoise_(addNoise) {}
18 
19 void CastorAmplifier::amplify(CaloSamples &frame, CLHEP::HepRandomEngine *engine) const {
21  assert(theDbService != nullptr);
22  HcalGenericDetId hcalGenDetId(frame.id());
23  const CastorPedestal *peds = theDbService->getPedestal(hcalGenDetId);
24  const CastorPedestalWidth *pwidths = theDbService->getPedestalWidth(hcalGenDetId);
25  if (!peds || !pwidths) {
26  edm::LogError("CastorAmplifier") << "Could not fetch HCAL/CASTOR conditions for channel " << hcalGenDetId;
27  } else {
28  double gauss[32]; // big enough
29  double noise[32]; // big enough
30  double fCperPE = parameters.photoelectronsToAnalog(frame.id());
31  double nominalfCperPE = parameters.getNominalfCperPE();
32 
33  for (int i = 0; i < frame.size(); i++) {
34  gauss[i] = CLHEP::RandGaussQ::shoot(engine, 0., 1.);
35  }
36  if (addNoise_) {
37  pwidths->makeNoise(frame.size(), gauss, noise);
38  }
39  for (int tbin = 0; tbin < frame.size(); ++tbin) {
40  int capId = (theStartingCapId + tbin) % 4;
41  double pedestal = peds->getValue(capId);
42  if (addNoise_) {
43  pedestal += noise[tbin] * (fCperPE / nominalfCperPE);
44  }
45  frame[tbin] *= fCperPE;
46  frame[tbin] += pedestal;
47  }
48  }
49  LogDebug("CastorAmplifier") << frame;
50 }
#define LogDebug(id)
unsigned theStartingCapId
double getNominalfCperPE() const
const CastorPedestal * getPedestal(const HcalGenericDetId &fId) const
CastorAmplifier(const CastorSimParameterMap *parameters, bool addNoise)
const CastorSimParameterMap * theParameterMap
#define nullptr
const CastorDbService * theDbService
double photoelectronsToAnalog(const DetId &detId) const override
void makeNoise(unsigned fFrames, const double *fGauss, double *fNoise) const
CastorSimParameters castorParameters() const
accessors
virtual void amplify(CaloSamples &linearFrame, CLHEP::HepRandomEngine *) const
int size() const
get the size
Definition: CaloSamples.h:24
const CastorPedestalWidth * getPedestalWidth(const HcalGenericDetId &fId) const
DetId id() const
get the (generic) id
Definition: CaloSamples.h:21