00001 #ifndef CaloSimAlgos_CaloTDigitizer_h
00002 #define CaloSimAlgos_CaloTDigitizer_h
00003
00009 #include "SimCalorimetry/CaloSimAlgos/interface/CaloHitResponse.h"
00010 #include "SimCalorimetry/CaloSimAlgos/interface/CaloVNoiseHitGenerator.h"
00011 #include "SimCalorimetry/CaloSimAlgos/interface/CaloVNoiseSignalGenerator.h"
00012 #include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
00013 #include "SimDataFormats/CaloHit/interface/PCaloHit.h"
00014 #include <cassert>
00015
00016 template<class Traits>
00017 class CaloTDigitizer
00018 {
00019 public:
00023 typedef typename Traits::ElectronicsSim ElectronicsSim;
00024 typedef typename Traits::Digi Digi;
00025 typedef typename Traits::DigiCollection DigiCollection;
00026
00027 CaloTDigitizer(CaloHitResponse * hitResponse, ElectronicsSim * electronicsSim, bool addNoise)
00028 : theHitResponse(hitResponse),
00029 theNoiseHitGenerator(0),
00030 theNoiseSignalGenerator(0),
00031 theElectronicsSim(electronicsSim),
00032 theDetIds(0),
00033 addNoise_(addNoise)
00034 {
00035 }
00036
00037
00039 ~CaloTDigitizer() {}
00040
00042 void setDetIds(const std::vector<DetId> & detIds) {theDetIds = detIds;}
00043
00044 void setNoiseHitGenerator(CaloVNoiseHitGenerator * generator)
00045 {
00046 theNoiseHitGenerator = generator;
00047 }
00048
00049 void setNoiseSignalGenerator(CaloVNoiseSignalGenerator * generator)
00050 {
00051 theNoiseSignalGenerator = generator;
00052 }
00053
00054
00056 void run(MixCollection<PCaloHit> & input, DigiCollection & output) {
00057 assert(theDetIds.size() != 0);
00058
00059 theHitResponse->run(input);
00060
00061 if(theNoiseHitGenerator != 0) addNoiseHits();
00062 if(theNoiseSignalGenerator != 0) addNoiseSignals();
00063 theElectronicsSim->newEvent();
00064
00065
00066 int nDigisExpected = addNoise_ ? theDetIds.size() : theHitResponse->nSignals();
00067 output.reserve(nDigisExpected);
00068
00069
00070 for(std::vector<DetId>::const_iterator idItr = theDetIds.begin();
00071 idItr != theDetIds.end(); ++idItr)
00072 {
00073 Digi digi(*idItr);
00074 CaloSamples * analogSignal = theHitResponse->findSignal(*idItr);
00075 bool needToDeleteSignal = false;
00076
00077 if(analogSignal == 0 && addNoise_) {
00078
00079
00080 analogSignal = new CaloSamples(theHitResponse->makeBlankSignal(*idItr));
00081 needToDeleteSignal = true;
00082 }
00083 if(analogSignal != 0) {
00084 theElectronicsSim->analogToDigital(*analogSignal , digi);
00085 output.push_back(digi);
00086 if(needToDeleteSignal) delete analogSignal;
00087 }
00088 }
00089
00090
00091 theHitResponse->clear();
00092 }
00093
00094
00095 void addNoiseHits()
00096 {
00097 std::vector<PCaloHit> noiseHits;
00098 theNoiseHitGenerator->getNoiseHits(noiseHits);
00099 for(std::vector<PCaloHit>::const_iterator hitItr = noiseHits.begin(),
00100 hitEnd = noiseHits.end(); hitItr != hitEnd; ++hitItr)
00101 {
00102 theHitResponse->add(*hitItr);
00103 }
00104 }
00105
00106 void addNoiseSignals()
00107 {
00108 std::vector<CaloSamples> noiseSignals;
00109
00110 theNoiseSignalGenerator->getNoiseSignals(noiseSignals);
00111 for(std::vector<CaloSamples>::const_iterator signalItr = noiseSignals.begin(),
00112 signalEnd = noiseSignals.end(); signalItr != signalEnd; ++signalItr)
00113 {
00114 theHitResponse->add(*signalItr);
00115 }
00116 }
00117
00118 private:
00119 CaloHitResponse * theHitResponse;
00120 CaloVNoiseHitGenerator * theNoiseHitGenerator;
00121 CaloVNoiseSignalGenerator * theNoiseSignalGenerator;
00122 ElectronicsSim * theElectronicsSim;
00123 std::vector<DetId> theDetIds;
00124 bool addNoise_;
00125 };
00126
00127 #endif
00128