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 #include <cassert>
16 
18  : theDbService(nullptr), theParameterMap(parameters), theStartingCapId(0), addNoise_(addNoise) {}
19 
20 void CastorAmplifier::amplify(CaloSamples &frame, CLHEP::HepRandomEngine *engine) const {
22  assert(theDbService != nullptr);
23  HcalGenericDetId hcalGenDetId(frame.id());
24  const CastorPedestal *peds = theDbService->getPedestal(hcalGenDetId);
25  const CastorPedestalWidth *pwidths = theDbService->getPedestalWidth(hcalGenDetId);
26  if (!peds || !pwidths) {
27  edm::LogError("CastorAmplifier") << "Could not fetch HCAL/CASTOR conditions for channel " << hcalGenDetId;
28  } else {
29  double gauss[32]; // big enough
30  double noise[32]; // big enough
31  double fCperPE = parameters.photoelectronsToAnalog(frame.id());
32  double nominalfCperPE = parameters.getNominalfCperPE();
33 
34  for (int i = 0; i < frame.size(); i++) {
35  gauss[i] = CLHEP::RandGaussQ::shoot(engine, 0., 1.);
36  }
37  if (addNoise_) {
38  pwidths->makeNoise(frame.size(), gauss, noise);
39  }
40  for (int tbin = 0; tbin < frame.size(); ++tbin) {
41  int capId = (theStartingCapId + tbin) % 4;
42  double pedestal = peds->getValue(capId);
43  if (addNoise_) {
44  pedestal += noise[tbin] * (fCperPE / nominalfCperPE);
45  }
46  frame[tbin] *= fCperPE;
47  frame[tbin] += pedestal;
48  }
49  }
50  LogDebug("CastorAmplifier") << frame;
51 }
unsigned theStartingCapId
CastorAmplifier(const CastorSimParameterMap *parameters, bool addNoise)
const CastorSimParameterMap * theParameterMap
const CastorDbService * theDbService
virtual void amplify(CaloSamples &linearFrame, CLHEP::HepRandomEngine *) const
Log< level::Error, false > LogError
assert(be >=bs)
void makeNoise(unsigned fFrames, const double *fGauss, double *fNoise) const
const CastorPedestalWidth * getPedestalWidth(const HcalGenericDetId &fId) const
const CastorPedestal * getPedestal(const HcalGenericDetId &fId) const
CastorSimParameters castorParameters() const
accessors
#define LogDebug(id)