Go to the documentation of this file.00001 #include "SimCalorimetry/CastorSim/plugins/CastorDigiProducer.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/CastorObjects/interface/CastorDbService.h"
00012 #include "CalibFormats/CastorObjects/interface/CastorDbRecord.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/HcalCastorDetId.h"
00018
00019 using namespace std;
00020
00021
00022 CastorDigiProducer::CastorDigiProducer(const edm::ParameterSet& ps)
00023 : theParameterMap(new CastorSimParameterMap(ps)),
00024 theCastorShape(new CastorShape()),
00025 theCastorIntegratedShape(new CaloShapeIntegrator(theCastorShape)),
00026 theCastorResponse(new CaloHitResponse(theParameterMap, theCastorIntegratedShape)),
00027 theAmplifier(0),
00028 theCoderFactory(0),
00029 theElectronicsSim(0),
00030 theHitCorrection(0),
00031 theCastorDigitizer(0),
00032 theCastorHits()
00033 {
00034
00035 produces<CastorDigiCollection>();
00036
00037 theCastorResponse->setHitFilter(&theCastorHitFilter);
00038
00039 bool doTimeSlew = ps.getParameter<bool>("doTimeSlew");
00040 if(doTimeSlew) {
00041
00042 theCastorResponse->setHitCorrection(theHitCorrection);
00043 }
00044
00045 bool doNoise = ps.getParameter<bool>("doNoise");
00046 theAmplifier = new CastorAmplifier(theParameterMap, doNoise);
00047 theCoderFactory = new CastorCoderFactory(CastorCoderFactory::DB);
00048 theElectronicsSim = new CastorElectronicsSim(theAmplifier, theCoderFactory);
00049
00050 theCastorDigitizer = new CastorDigitizer(theCastorResponse, theElectronicsSim, doNoise);
00051
00052 edm::Service<edm::RandomNumberGenerator> rng;
00053 if ( ! rng.isAvailable()) {
00054 throw cms::Exception("Configuration")
00055 << "CastorDigiProducer requires the RandomNumberGeneratorService\n"
00056 "which is not present in the configuration file. You must add the service\n"
00057 "in the configuration file or remove the modules that require it.";
00058 }
00059
00060 CLHEP::HepRandomEngine& engine = rng->getEngine();
00061 theAmplifier->setRandomEngine(engine);
00062 theElectronicsSim->setRandomEngine(engine);
00063 }
00064
00065
00066 CastorDigiProducer::~CastorDigiProducer() {
00067 delete theCastorDigitizer;
00068 delete theParameterMap;
00069 delete theCastorShape;
00070 delete theCastorIntegratedShape;
00071 delete theCastorResponse;
00072 delete theElectronicsSim;
00073 delete theAmplifier;
00074 delete theCoderFactory;
00075 delete theHitCorrection;
00076 }
00077
00078
00079 void CastorDigiProducer::produce(edm::Event& e, const edm::EventSetup& eventSetup) {
00080
00081 edm::ESHandle<CastorDbService> conditions;
00082 eventSetup.get<CastorDbRecord>().get(conditions);
00083 theAmplifier->setDbService(conditions.product());
00084 theCoderFactory->setDbService(conditions.product());
00085 theParameterMap->setDbService(conditions.product());
00086
00087 edm::LogInfo("CastorDigiProducer") << "checking the geometry...";
00088
00089
00090 checkGeometry(eventSetup);
00091
00092 theCastorHits.clear();
00093
00094
00095
00096 edm::Handle<CrossingFrame<PCaloHit> > castorcf;
00097 e.getByLabel("mix", "g4SimHitsCastorFI", castorcf);
00098
00099
00100 std::auto_ptr<MixCollection<PCaloHit> > colcastor(new MixCollection<PCaloHit>(castorcf.product()));
00101
00102
00103
00104 if(theHitCorrection != 0)
00105 {
00106 theHitCorrection->fillChargeSums(*colcastor);
00107 }
00108
00109
00110 std::auto_ptr<CastorDigiCollection> castorResult(new CastorDigiCollection());
00111
00112
00113 theCastorDigitizer->run(*colcastor, *castorResult);
00114
00115 edm::LogInfo("CastorDigiProducer") << "HCAL/Castor digis : " << castorResult->size();
00116
00117
00118 e.put(castorResult);
00119 }
00120
00121
00122 void CastorDigiProducer::sortHits(const edm::PCaloHitContainer & hits){
00123 for(edm::PCaloHitContainer::const_iterator hitItr = hits.begin();
00124 hitItr != hits.end(); ++hitItr){
00125 DetId detId = hitItr->id();
00126 if (detId.det()==DetId::Calo && detId.subdetId()==HcalCastorDetId::SubdetectorId){
00127 theCastorHits.push_back(*hitItr);
00128 }
00129 else {
00130 edm::LogError("CastorDigiProducer") << "Bad Hit subdetector " << detId.subdetId();
00131 }
00132 }
00133 }
00134
00135 void CastorDigiProducer::fillFakeHits() {
00136 HcalCastorDetId castorDetId(HcalCastorDetId::Section(2),true,1,1);
00137 PCaloHit castorHit(castorDetId.rawId(), 50.0, 0.);
00138
00139 theCastorHits.push_back(castorHit);
00140 }
00141
00142
00143 void CastorDigiProducer::checkGeometry(const edm::EventSetup & eventSetup) {
00144
00145 edm::ESHandle<CaloGeometry> geometry;
00146 eventSetup.get<CaloGeometryRecord>().get(geometry);
00147 theCastorResponse->setGeometry(&*geometry);
00148
00149 const vector<DetId>& castorCells = geometry->getValidDetIds(DetId::Calo, HcalCastorDetId::SubdetectorId);
00150
00151
00152 theCastorDigitizer->setDetIds(castorCells);
00153 }
00154
00155