00001 #include "SimCalorimetry/HcalSimProducers/src/HcalDigiProducer.h"
00002 #include "FWCore/Framework/interface/EDProducer.h"
00003 #include "DataFormats/Common/interface/Handle.h"
00004 #include "FWCore/Framework/interface/ESHandle.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include "SimCalorimetry/CaloSimAlgos/interface/CaloTDigitizer.h"
00007 #include "SimCalorimetry/CaloSimAlgos/interface/CaloShapeIntegrator.h"
00008 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00009 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00010 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00011 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00012 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00013 #include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
00014 #include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
00015 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00016 #include "FWCore/ServiceRegistry/interface/Service.h"
00017 #include "DataFormats/HcalDetId/interface/HcalZDCDetId.h"
00018 #include "SimCalorimetry/HcalSimAlgos/interface/HPDNoiseGenerator.h"
00019 using namespace std;
00020
00021
00022 HcalDigiProducer::HcalDigiProducer(const edm::ParameterSet& ps)
00023 : theParameterMap(new HcalSimParameterMap(ps)),
00024 theHcalShape(new HcalShape()),
00025 theHFShape(new HFShape()),
00026 theZDCShape(new ZDCShape()),
00027 theHcalIntegratedShape(new CaloShapeIntegrator(theHcalShape)),
00028 theHFIntegratedShape(new CaloShapeIntegrator(theHFShape)),
00029 theZDCIntegratedShape(new CaloShapeIntegrator(theZDCShape)),
00030 theHBHEResponse(new CaloHitResponse(theParameterMap, theHcalIntegratedShape)),
00031 theHOResponse(new CaloHitResponse(theParameterMap, theHcalIntegratedShape)),
00032 theHFResponse(new CaloHitResponse(theParameterMap, theHFIntegratedShape)),
00033 theZDCResponse(new CaloHitResponse(theParameterMap, theZDCIntegratedShape)),
00034 theAmplifier(0),
00035 theCoderFactory(0),
00036 theElectronicsSim(0),
00037 theHitCorrection(0),
00038 theHPDNoiseGenerator(0),
00039 theHBHEDigitizer(0),
00040 theHODigitizer(0),
00041 theHFDigitizer(0),
00042 theZDCDigitizer(0),
00043 doZDC(true)
00044 {
00045
00046 produces<HBHEDigiCollection>();
00047 produces<HODigiCollection>();
00048 produces<HFDigiCollection>();
00049 produces<ZDCDigiCollection>();
00050
00051 theHBHEResponse->setHitFilter(&theHBHEHitFilter);
00052 theHOResponse->setHitFilter(&theHOHitFilter);
00053 theHFResponse->setHitFilter(&theHFHitFilter);
00054 theZDCResponse->setHitFilter(&theZDCHitFilter);
00055
00056 bool doTimeSlew = ps.getParameter<bool>("doTimeSlew");
00057 if(doTimeSlew) {
00058
00059 theHitCorrection = new HcalHitCorrection(theParameterMap);
00060 theHBHEResponse->setHitCorrection(theHitCorrection);
00061 theHOResponse->setHitCorrection(theHitCorrection);
00062 theZDCResponse->setHitCorrection(theHitCorrection);
00063 }
00064
00065 bool doNoise = ps.getParameter<bool>("doNoise");
00066 theAmplifier = new HcalAmplifier(theParameterMap, doNoise);
00067 theCoderFactory = new HcalCoderFactory(HcalCoderFactory::DB);
00068 theElectronicsSim = new HcalElectronicsSim(theAmplifier, theCoderFactory);
00069
00070 theHBHEDigitizer = new HBHEDigitizer(theHBHEResponse, theElectronicsSim, doNoise);
00071 theHODigitizer = new HODigitizer(theHOResponse, theElectronicsSim, doNoise);
00072 theHFDigitizer = new HFDigitizer(theHFResponse, theElectronicsSim, doNoise);
00073 theZDCDigitizer = new ZDCDigitizer(theZDCResponse, theElectronicsSim, doNoise);
00074
00075 bool doHPDNoise = ps.getParameter<bool>("doHPDNoise");
00076 if(doHPDNoise) {
00077 theHPDNoiseGenerator = new HPDNoiseGenerator(theParameterMap);
00078 theHBHEDigitizer->setNoiseSignalGenerator(theHPDNoiseGenerator);
00079 }
00080
00081 edm::Service<edm::RandomNumberGenerator> rng;
00082 if ( ! rng.isAvailable()) {
00083 throw cms::Exception("Configuration")
00084 << "HcalDigiProducer requires the RandomNumberGeneratorService\n"
00085 "which is not present in the configuration file. You must add the service\n"
00086 "in the configuration file or remove the modules that require it.";
00087 }
00088
00089 CLHEP::HepRandomEngine& engine = rng->getEngine();
00090 theAmplifier->setRandomEngine(engine);
00091 theElectronicsSim->setRandomEngine(engine);
00092
00093 hitsProducer_ = ps.getParameter<std::string>("hitsProducer");
00094
00095 }
00096
00097
00098 HcalDigiProducer::~HcalDigiProducer() {
00099 delete theHBHEDigitizer;
00100 delete theHODigitizer;
00101 delete theHFDigitizer;
00102 delete theZDCDigitizer;
00103 delete theParameterMap;
00104 delete theHcalShape;
00105 delete theHFShape;
00106 delete theZDCShape;
00107 delete theHcalIntegratedShape;
00108 delete theHFIntegratedShape;
00109 delete theZDCIntegratedShape;
00110 delete theHBHEResponse;
00111 delete theHOResponse;
00112 delete theHFResponse;
00113 delete theZDCResponse;
00114 delete theElectronicsSim;
00115 delete theAmplifier;
00116 delete theCoderFactory;
00117 delete theHitCorrection;
00118 delete theHPDNoiseGenerator;
00119 }
00120
00121
00122 void HcalDigiProducer::produce(edm::Event& e, const edm::EventSetup& eventSetup) {
00123
00124 edm::ESHandle<HcalDbService> conditions;
00125 eventSetup.get<HcalDbRecord>().get(conditions);
00126 theAmplifier->setDbService(conditions.product());
00127 theCoderFactory->setDbService(conditions.product());
00128 theParameterMap->setDbService(conditions.product());
00129
00130
00131 checkGeometry(eventSetup);
00132
00133
00134 edm::Handle<CrossingFrame<PCaloHit> > cf, zdccf;
00135
00136 const std::string hcalHitsName(hitsProducer_+"HcalHits");
00137 const std::string zdcHitsName(hitsProducer_+"ZDCHITS");
00138
00139 e.getByLabel("mix", hcalHitsName ,cf);
00140 e.getByLabel("mix", zdcHitsName , zdccf);
00141
00142
00143 std::auto_ptr<MixCollection<PCaloHit> > col(new MixCollection<PCaloHit>(cf.product()));
00144 std::auto_ptr<MixCollection<PCaloHit> > colzdc(new MixCollection<PCaloHit>(zdccf.product()));
00145
00146 if(theHitCorrection != 0)
00147 {
00148 theHitCorrection->clear();
00149 theHitCorrection->fillChargeSums(*col);
00150 theHitCorrection->fillChargeSums(*colzdc);
00151 }
00152
00153
00154 std::auto_ptr<HBHEDigiCollection> hbheResult(new HBHEDigiCollection());
00155 std::auto_ptr<HODigiCollection> hoResult(new HODigiCollection());
00156 std::auto_ptr<HFDigiCollection> hfResult(new HFDigiCollection());
00157 std::auto_ptr<ZDCDigiCollection> zdcResult(new ZDCDigiCollection());
00158
00159
00160 theHBHEDigitizer->run(*col, *hbheResult);
00161 theHODigitizer->run(*col, *hoResult);
00162 theHFDigitizer->run(*col, *hfResult);
00163 if(doZDC) {
00164
00165 }
00166 edm::LogInfo("HcalDigiProducer") << "HCAL HBHE digis : " << hbheResult->size();
00167 edm::LogInfo("HcalDigiProducer") << "HCAL HO digis : " << hoResult->size();
00168 edm::LogInfo("HcalDigiProducer") << "HCAL HF digis : " << hfResult->size();
00169 edm::LogInfo("HcalDigiProducer") << "HCAL ZDC digis : " << zdcResult->size();
00170
00171
00172 e.put(hbheResult);
00173 e.put(hoResult);
00174 e.put(hfResult);
00175 e.put(zdcResult);
00176 }
00177
00178
00179 void HcalDigiProducer::checkGeometry(const edm::EventSetup & eventSetup) {
00180
00181 edm::ESHandle<CaloGeometry> geometry;
00182 eventSetup.get<CaloGeometryRecord>().get(geometry);
00183 theHBHEResponse->setGeometry(&*geometry);
00184 theHOResponse->setGeometry(&*geometry);
00185 theHFResponse->setGeometry(&*geometry);
00186 theZDCResponse->setGeometry(&*geometry);
00187
00188 const vector<DetId>& hbCells = geometry->getValidDetIds(DetId::Hcal, HcalBarrel);
00189 const vector<DetId>& heCells = geometry->getValidDetIds(DetId::Hcal, HcalEndcap);
00190 const vector<DetId>& hoCells = geometry->getValidDetIds(DetId::Hcal, HcalOuter);
00191 const vector<DetId>& hfCells = geometry->getValidDetIds(DetId::Hcal, HcalForward);
00192 const vector<DetId>& zdcCells = geometry->getValidDetIds(DetId::Calo, HcalZDCDetId::SubdetectorId);
00193
00194
00195 if(zdcCells.size()==0) doZDC = false;
00196
00197
00198 vector<DetId> hbheCells = hbCells;
00199 hbheCells.insert(hbheCells.end(), heCells.begin(), heCells.end());
00200
00201 theHBHEDigitizer->setDetIds(hbheCells);
00202 theHODigitizer->setDetIds(hoCells);
00203 theHFDigitizer->setDetIds(hfCells);
00204 theZDCDigitizer->setDetIds(zdcCells);
00205 }
00206
00207