Go to the documentation of this file.00001 #ifndef HcalSimAlgos_HcalSignalGenerator_h
00002 #define HcalSimAlgos_HcalSignalGenerator_h
00003
00004 #include "SimCalorimetry/HcalSimAlgos/interface/HcalBaseSignalGenerator.h"
00005 #include "FWCore/Framework/interface/ESHandle.h"
00006 #include "FWCore/Framework/interface/EventSetup.h"
00007 #include "FWCore/Framework/interface/Event.h"
00008 #include "FWCore/Framework/interface/EventPrincipal.h"
00009 #include "CalibFormats/HcalObjects/interface/HcalCoderDb.h"
00010 #include "CalibFormats/HcalObjects/interface/HcalCalibrations.h"
00011 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00012 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00013 #include "SimCalorimetry/HcalSimAlgos/interface/HcalElectronicsSim.h"
00014 #include "SimCalorimetry/HcalSimAlgos/interface/HcalDigitizerTraits.h"
00015 #include "DataFormats/Common/interface/Handle.h"
00016
00021 #include <iostream>
00022
00023 template<class HCALDIGITIZERTRAITS>
00024 class HcalSignalGenerator : public HcalBaseSignalGenerator
00025 {
00026 public:
00027 typedef typename HCALDIGITIZERTRAITS::Digi DIGI;
00028 typedef typename HCALDIGITIZERTRAITS::DigiCollection COLLECTION;
00029
00030 HcalSignalGenerator(const edm::InputTag & inputTag)
00031 : HcalBaseSignalGenerator(), theEvent(0), theEventPrincipal(0), theInputTag(inputTag) {}
00032
00033 virtual ~HcalSignalGenerator() {}
00034
00035 void initializeEvent(const edm::Event * event, const edm::EventSetup * eventSetup)
00036 {
00037 theEvent = event;
00038 eventSetup->get<HcalDbRecord>().get(theConditions);
00039 theParameterMap->setDbService(theConditions.product());
00040 }
00041
00043 void initializeEvent(const edm::EventPrincipal * eventPrincipal, const edm::EventSetup * eventSetup)
00044 {
00045 theEventPrincipal = eventPrincipal;
00046 eventSetup->get<HcalDbRecord>().get(theConditions);
00047 theParameterMap->setDbService(theConditions.product());
00048 }
00049
00050 virtual void fill()
00051 {
00052 theNoiseSignals.clear();
00053 edm::Handle<COLLECTION> pDigis;
00054 const COLLECTION * digis = 0;
00055
00056 if(theEvent)
00057 {
00058 if( theEvent->getByLabel(theInputTag, pDigis) ) {
00059 digis = pDigis.product();
00060 LogTrace("HcalSignalGenerator") << "total # digis for " << theInputTag << " " << digis->size();
00061 }
00062 else
00063 {
00064 throw cms::Exception("HcalSignalGenerator") << "Cannot find input data " << theInputTag;
00065 }
00066 }
00067 else if(theEventPrincipal)
00068 {
00069 boost::shared_ptr<edm::Wrapper<COLLECTION> const> digisPTR =
00070 edm::getProductByTag<COLLECTION>(*theEventPrincipal, theInputTag );
00071 if(digisPTR) {
00072 digis = digisPTR->product();
00073 }
00074 }
00075 else
00076 {
00077 throw cms::Exception("HcalSignalGenerator") << "No Event or EventPrincipal was set";
00078 }
00079
00080 if (digis)
00081 {
00082
00083 for(typename COLLECTION::const_iterator it = digis->begin();
00084 it != digis->end(); ++it)
00085 {
00086
00087 if((it == digis->begin()) && theElectronicsSim)
00088 {
00089 int startingCapId = (*it)[0].capid();
00090 theElectronicsSim->setStartingCapId(startingCapId);
00091 theParameterMap->setFrameSize(it->id(), it->size());
00092 }
00093
00094 theNoiseSignals.push_back(samplesInPE(*it));
00095 }
00096 }
00097 }
00098
00099 private:
00100
00101 CaloSamples samplesInPE(const DIGI & digi)
00102 {
00103
00104 HcalDetId cell = digi.id();
00105
00106 const HcalQIECoder* channelCoder = theConditions->getHcalCoder (cell);
00107 const HcalQIEShape* channelShape = theConditions->getHcalShape (cell);
00108 HcalCoderDb coder (*channelCoder, *channelShape);
00109 CaloSamples result;
00110 coder.adc2fC(digi, result);
00111 fC2pe(result);
00112 return result;
00113 }
00114
00115
00117 const edm::Event * theEvent;
00118 const edm::EventPrincipal * theEventPrincipal;
00119 edm::ESHandle<HcalDbService> theConditions;
00121 edm::InputTag theInputTag;
00122 };
00123
00124 typedef HcalSignalGenerator<HBHEDigitizerTraits> HBHESignalGenerator;
00125 typedef HcalSignalGenerator<HODigitizerTraits> HOSignalGenerator;
00126 typedef HcalSignalGenerator<HFDigitizerTraits> HFSignalGenerator;
00127 typedef HcalSignalGenerator<ZDCDigitizerTraits> ZDCSignalGenerator;
00128
00129 #endif
00130