Go to the documentation of this file.00001 #include "SimCalorimetry/CastorSim/src/CastorAmplifier.h"
00002 #include "SimCalorimetry/CastorSim/src/CastorSimParameters.h"
00003 #include "CalibFormats/CastorObjects/interface/CastorDbService.h"
00004 #include "CondFormats/CastorObjects/interface/CastorPedestal.h"
00005 #include "CondFormats/CastorObjects/interface/CastorGain.h"
00006 #include "CondFormats/CastorObjects/interface/CastorPedestalWidth.h"
00007 #include "CondFormats/CastorObjects/interface/CastorGainWidth.h"
00008 #include "CalibFormats/CaloObjects/interface/CaloSamples.h"
00009 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011
00012 #include<iostream>
00013
00014 CastorAmplifier::CastorAmplifier(const CastorSimParameterMap * parameters, bool addNoise) :
00015 theDbService(0),
00016 theRandGaussQ(0),
00017 theParameterMap(parameters),
00018 theStartingCapId(0),
00019 addNoise_(addNoise)
00020 {
00021 }
00022
00023
00024 void CastorAmplifier::setRandomEngine(CLHEP::HepRandomEngine & engine)
00025 {
00026 theRandGaussQ = new CLHEP::RandGaussQ(engine);
00027 }
00028
00029 void CastorAmplifier::amplify(CaloSamples & frame) const {
00030 const CastorSimParameters & parameters = theParameterMap->castorParameters();
00031 assert(theDbService != 0);
00032 HcalGenericDetId hcalGenDetId(frame.id());
00033 const CastorPedestal* peds = theDbService->getPedestal(hcalGenDetId);
00034 const CastorPedestalWidth* pwidths = theDbService->getPedestalWidth(hcalGenDetId);
00035 if (!peds || !pwidths )
00036 {
00037 edm::LogError("CastorAmplifier") << "Could not fetch HCAL/CASTOR conditions for channel " << hcalGenDetId;
00038 }
00039
00040 double gauss [32];
00041 double noise [32];
00042 double fCperPE = parameters.photoelectronsToAnalog(frame.id());
00043
00044 for (int i = 0; i < frame.size(); i++) gauss[i] = theRandGaussQ->fire(0., 1.);
00045 pwidths->makeNoise (frame.size(), gauss, noise);
00046 for(int tbin = 0; tbin < frame.size(); ++tbin) {
00047 int capId = (theStartingCapId + tbin)%4;
00048 double pedestal = peds->getValue (capId);
00049 if(addNoise_) {
00050 pedestal += noise [tbin];
00051 }
00052 frame[tbin] *= fCperPE;
00053 frame[tbin] += pedestal;
00054 }
00055 LogDebug("CastorAmplifier") << frame;
00056 }
00057