CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/SimCalorimetry/HcalSimProducers/src/HcalDigitizer.cc

Go to the documentation of this file.
00001 #include "SimCalorimetry/HcalSimProducers/interface/HcalDigitizer.h"
00002 #include "SimCalorimetry/HcalSimProducers/src/HcalTestHitGenerator.h"
00003 #include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
00004 #include "SimCalorimetry/HcalSimAlgos/interface/HcalSimParameterMap.h"
00005 #include "SimCalorimetry/HcalSimAlgos/interface/HcalShapes.h"
00006 #include "SimCalorimetry/HcalSimAlgos/interface/HcalElectronicsSim.h"
00007 #include "SimCalorimetry/CaloSimAlgos/interface/CaloHitResponse.h"
00008 #include "SimCalorimetry/HcalSimAlgos/interface/HcalAmplifier.h"
00009 #include "SimCalorimetry/HcalSimAlgos/interface/HcalCoderFactory.h"
00010 #include "SimCalorimetry/HcalSimAlgos/interface/HcalHitCorrection.h"
00011 #include "SimCalorimetry/HcalSimAlgos/interface/HcalTimeSlewSim.h"
00012 #include "SimCalorimetry/HcalSimAlgos/interface/HcalSimParameterMap.h"
00013 #include "SimCalorimetry/HcalSimAlgos/interface/HcalSiPMHitResponse.h"
00014 #include "SimCalorimetry/HcalSimAlgos/interface/HPDIonFeedbackSim.h"
00015 #include "DataFormats/Common/interface/Handle.h"
00016 #include "FWCore/Framework/interface/ESHandle.h"
00017 #include "FWCore/Framework/interface/Event.h"
00018 #include "FWCore/Framework/interface/EventSetup.h"
00019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00021 #include "SimCalorimetry/CaloSimAlgos/interface/CaloTDigitizer.h"
00022 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00023 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00024 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00025 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00026 #include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
00027 #include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
00028 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00029 #include "FWCore/ServiceRegistry/interface/Service.h"
00030 #include "DataFormats/HcalDetId/interface/HcalZDCDetId.h"
00031 #include "SimCalorimetry/HcalSimAlgos/interface/HPDNoiseGenerator.h"
00032 #include "CondFormats/HcalObjects/interface/HcalCholeskyMatrix.h"
00033 #include "CondFormats/HcalObjects/interface/HcalCholeskyMatrices.h"
00034 #include <boost/foreach.hpp>
00035 using namespace std;
00036 
00037 namespace HcalDigitizerImpl {
00038 
00039   template<typename SIPMDIGITIZER>
00040   void fillSiPMCells(const vector<int> & siPMCells, SIPMDIGITIZER * siPMDigitizer)
00041   {
00042     std::vector<DetId> siPMDetIds;
00043     siPMDetIds.reserve(siPMCells.size());
00044     for(std::vector<int>::const_iterator idItr = siPMCells.begin();
00045         idItr != siPMCells.end(); ++idItr)
00046     {
00047       siPMDetIds.push_back(DetId(*idItr));
00048     }
00049     siPMDigitizer->setDetIds(siPMDetIds);
00050   }
00051 
00052   // if both exist, assume the SiPM one has cells filled, and
00053   // assign the rest to the HPD
00054   template<typename HPDDIGITIZER, typename SIPMDIGITIZER>
00055   void fillCells(const vector<DetId>& allCells,
00056                  HPDDIGITIZER * hpdDigitizer,
00057                  SIPMDIGITIZER * siPMDigitizer)
00058   {
00059     // if both digitizers exist, split up the cells
00060     if(siPMDigitizer && hpdDigitizer)
00061     {
00062       std::vector<DetId> siPMDetIds = siPMDigitizer->detIds();
00063       std::sort(siPMDetIds.begin(), siPMDetIds.end());
00064       std::vector<DetId> sortedCells = allCells;
00065       std::sort(sortedCells.begin(), sortedCells.end());
00066       std::vector<DetId> hpdCells;
00067       std::set_difference(sortedCells.begin(), sortedCells.end(),
00068                           siPMDetIds.begin(), siPMDetIds.end(),
00069                           std::back_inserter(hpdCells) );
00070       hpdDigitizer->setDetIds(hpdCells);
00071     }
00072     else
00073     {
00074       if(siPMDigitizer) siPMDigitizer->setDetIds(allCells);
00075       if(hpdDigitizer) hpdDigitizer->setDetIds(allCells);
00076     }
00077   }
00078 } // namespace HcaiDigitizerImpl
00079 
00080 
00081 HcalDigitizer::HcalDigitizer(const edm::ParameterSet& ps) 
00082 : theGeometry(0),
00083   theParameterMap(new HcalSimParameterMap(ps)),
00084   theShapes(new HcalShapes()),
00085   theHBHEResponse(0),
00086   theHBHESiPMResponse(0),
00087   theHOResponse(0),   
00088   theHOSiPMResponse(0),
00089   theHFResponse(new CaloHitResponse(theParameterMap, theShapes)),
00090   theZDCResponse(new CaloHitResponse(theParameterMap, theShapes)),
00091   theHBHEAmplifier(0),
00092   theHFAmplifier(0),
00093   theHOAmplifier(0),
00094   theZDCAmplifier(0),
00095   theIonFeedback(0),
00096   theCoderFactory(0),
00097   theHBHEElectronicsSim(0),
00098   theHFElectronicsSim(0),
00099   theHOElectronicsSim(0),
00100   theZDCElectronicsSim(0),
00101   theHBHEHitFilter(),
00102   theHFHitFilter(ps.getParameter<bool>("doHFWindow")),
00103   theHOHitFilter(),
00104   theHOSiPMHitFilter(HcalOuter),
00105   theZDCHitFilter(),
00106   theHitCorrection(0),
00107   theNoiseGenerator(0),
00108   theNoiseHitGenerator(0),
00109   theHBHEDigitizer(0),
00110   theHBHESiPMDigitizer(0),
00111   theHODigitizer(0),
00112   theHOSiPMDigitizer(0),
00113   theHFDigitizer(0),
00114   theZDCDigitizer(0),
00115   theHBHEDetIds(),
00116   theHOHPDDetIds(),
00117   theHOSiPMDetIds(),
00118   isZDC(true),
00119   isHCAL(true),
00120   zdcgeo(true),
00121   hbhegeo(true),
00122   hogeo(true),
00123   hfgeo(true),
00124   theHOSiPMCode(ps.getParameter<edm::ParameterSet>("ho").getParameter<int>("siPMCode"))
00125 {
00126   bool doNoise = ps.getParameter<bool>("doNoise");
00127   bool useOldNoiseHB = ps.getParameter<bool>("useOldHB");
00128   bool useOldNoiseHE = ps.getParameter<bool>("useOldHE");
00129   bool useOldNoiseHF = ps.getParameter<bool>("useOldHF");
00130   bool useOldNoiseHO = ps.getParameter<bool>("useOldHO");
00131   bool doEmpty = ps.getParameter<bool>("doEmpty");
00132   double HBtp = ps.getParameter<double>("HBTuningParameter");
00133   double HEtp = ps.getParameter<double>("HETuningParameter");
00134   double HFtp = ps.getParameter<double>("HFTuningParameter");
00135   double HOtp = ps.getParameter<double>("HOTuningParameter");
00136 
00137   // need to make copies, because they might get different noise generators
00138   theHBHEAmplifier = new HcalAmplifier(theParameterMap, doNoise);
00139   theHFAmplifier = new HcalAmplifier(theParameterMap, doNoise);
00140   theHOAmplifier = new HcalAmplifier(theParameterMap, doNoise);
00141   theZDCAmplifier = new HcalAmplifier(theParameterMap, doNoise);
00142   theHBHEAmplifier->setHBtuningParameter(HBtp);
00143   theHBHEAmplifier->setHEtuningParameter(HEtp);
00144   theHFAmplifier->setHFtuningParameter(HFtp);
00145   theHOAmplifier->setHOtuningParameter(HOtp);
00146   theHBHEAmplifier->setUseOldHB(useOldNoiseHB);
00147   theHBHEAmplifier->setUseOldHE(useOldNoiseHE);
00148   theHFAmplifier->setUseOldHF(useOldNoiseHF);
00149   theHOAmplifier->setUseOldHO(useOldNoiseHO);
00150 
00151   theCoderFactory = new HcalCoderFactory(HcalCoderFactory::DB);
00152   theHBHEElectronicsSim = new HcalElectronicsSim(theHBHEAmplifier, theCoderFactory);
00153   theHFElectronicsSim = new HcalElectronicsSim(theHFAmplifier, theCoderFactory);
00154   theHOElectronicsSim = new HcalElectronicsSim(theHOAmplifier, theCoderFactory);
00155   theZDCElectronicsSim = new HcalElectronicsSim(theZDCAmplifier, theCoderFactory);
00156 
00157   // a code of 1 means make all cells SiPM
00158   std::vector<int> hbSiPMCells(ps.getParameter<edm::ParameterSet>("hb").getParameter<std::vector<int> >("siPMCells"));
00159   //std::vector<int> hoSiPMCells(ps.getParameter<edm::ParameterSet>("ho").getParameter<std::vector<int> >("siPMCells"));
00160   // 0 means none, 1 means all, and 2 means use hardcoded
00161 
00162   bool doHBHEHPD = hbSiPMCells.empty() || (hbSiPMCells[0] != 1);
00163   bool doHOHPD = (theHOSiPMCode != 1);
00164   bool doHBHESiPM = !hbSiPMCells.empty();
00165   bool doHOSiPM = (theHOSiPMCode != 0);
00166   if(doHBHEHPD)
00167   {
00168     theHBHEResponse = new CaloHitResponse(theParameterMap, theShapes);
00169     theHBHEResponse->setHitFilter(&theHBHEHitFilter);
00170     theHBHEDigitizer = new HBHEDigitizer(theHBHEResponse, theHBHEElectronicsSim, doEmpty);
00171   }
00172   if(doHOHPD) 
00173   {
00174     theHOResponse = new CaloHitResponse(theParameterMap, theShapes);
00175     theHOResponse->setHitFilter(&theHOHitFilter);
00176     theHODigitizer = new HODigitizer(theHOResponse, theHOElectronicsSim, doEmpty);
00177   }
00178 
00179   if(doHBHESiPM)
00180   {
00181     theHBHESiPMResponse = new HcalSiPMHitResponse(theParameterMap, theShapes);
00182     theHBHESiPMResponse->setHitFilter(&theHBHEHitFilter);
00183     theHBHESiPMDigitizer = new HBHEDigitizer(theHBHESiPMResponse, theHBHEElectronicsSim, doEmpty);
00184   }
00185   if(doHOSiPM)
00186   {
00187     theHOSiPMResponse = new HcalSiPMHitResponse(theParameterMap, theShapes);
00188     theHOSiPMResponse->setHitFilter(&theHOSiPMHitFilter);
00189     theHOSiPMDigitizer = new HODigitizer(theHOSiPMResponse, theHOElectronicsSim, doEmpty);
00190   }
00191 
00192   // if both are present, fill the SiPM cells now
00193   if(doHBHEHPD && doHBHESiPM)
00194   {
00195     HcalDigitizerImpl::fillSiPMCells(hbSiPMCells, theHBHESiPMDigitizer);
00196   }
00197 
00198   theHFResponse->setHitFilter(&theHFHitFilter);
00199   theZDCResponse->setHitFilter(&theZDCHitFilter);
00200 
00201   bool doTimeSlew = ps.getParameter<bool>("doTimeSlew");
00202   if(doTimeSlew) {
00203     // no time slewing for HF
00204     /*  
00205     theHitCorrection = new HcalHitCorrection(theParameterMap);
00206     if(theHBHEResponse) theHBHEResponse->setHitCorrection(theHitCorrection);
00207     if(theHBHESiPMResponse) theHBHESiPMResponse->setHitCorrection(theHitCorrection);
00208     if(theHOResponse) theHOResponse->setHitCorrection(theHitCorrection);
00209     if(theHOSiPMResponse) theHOSiPMResponse->setHitCorrection(theHitCorrection);
00210     theZDCResponse->setHitCorrection(theHitCorrection);
00211     */ 
00212     theTimeSlewSim = new HcalTimeSlewSim(theParameterMap);
00213     theHBHEAmplifier->setTimeSlewSim(theTimeSlewSim);
00214     theHOAmplifier->setTimeSlewSim(theTimeSlewSim);
00215     theZDCAmplifier->setTimeSlewSim(theTimeSlewSim);
00216   }
00217 
00218   theHFDigitizer = new HFDigitizer(theHFResponse, theHFElectronicsSim, doEmpty);
00219   theZDCDigitizer = new ZDCDigitizer(theZDCResponse, theZDCElectronicsSim, doEmpty);
00220 
00221   bool doHPDNoise = ps.getParameter<bool>("doHPDNoise");
00222   if(doHPDNoise) {
00223     //edm::ParameterSet hpdNoisePset = ps.getParameter<edm::ParameterSet>("HPDNoiseLibrary");
00224     theNoiseGenerator = new HPDNoiseGenerator(ps); 
00225     if(theHBHEDigitizer) theHBHEDigitizer->setNoiseSignalGenerator(theNoiseGenerator);
00226     if(theHBHESiPMDigitizer) theHBHESiPMDigitizer->setNoiseSignalGenerator(theNoiseGenerator);
00227   }
00228 
00229   if(ps.getParameter<bool>("doIonFeedback") && theHBHEResponse)
00230   {
00231     theIonFeedback = new HPDIonFeedbackSim(ps, theShapes);
00232     theHBHEResponse->setPECorrection(theIonFeedback);
00233     if(ps.getParameter<bool>("doThermalNoise"))
00234     {
00235       theHBHEAmplifier->setIonFeedbackSim(theIonFeedback);
00236     }
00237   }
00238 
00239   if(ps.getParameter<bool>("injectTestHits") ){
00240     theNoiseHitGenerator = new HcalTestHitGenerator(ps);
00241     if(theHBHEDigitizer) theHBHEDigitizer->setNoiseHitGenerator(theNoiseHitGenerator);
00242     if(theHBHESiPMDigitizer) theHBHESiPMDigitizer->setNoiseHitGenerator(theNoiseHitGenerator);
00243     if(theHODigitizer) theHODigitizer->setNoiseHitGenerator(theNoiseHitGenerator);
00244     if(theHOSiPMDigitizer) theHOSiPMDigitizer->setNoiseHitGenerator(theNoiseHitGenerator);
00245     theHFDigitizer->setNoiseHitGenerator(theNoiseHitGenerator);
00246     theZDCDigitizer->setNoiseHitGenerator(theNoiseHitGenerator);
00247   }
00248 
00249   edm::Service<edm::RandomNumberGenerator> rng;
00250   if ( ! rng.isAvailable()) {
00251     throw cms::Exception("Configuration")
00252       << "HcalDigitizer requires the RandomNumberGeneratorService\n"
00253          "which is not present in the configuration file.  You must add the service\n"
00254          "in the configuration file or remove the modules that require it.";
00255   }
00256 
00257   CLHEP::HepRandomEngine& engine = rng->getEngine();
00258   if(theHBHEDigitizer) theHBHEDigitizer->setRandomEngine(engine);
00259   if(theHBHESiPMDigitizer) theHBHESiPMDigitizer->setRandomEngine(engine);
00260   if(theHODigitizer) theHODigitizer->setRandomEngine(engine);
00261   if(theHOSiPMDigitizer) theHOSiPMDigitizer->setRandomEngine(engine);
00262   if(theIonFeedback) theIonFeedback->setRandomEngine(engine);
00263   if(theTimeSlewSim) theTimeSlewSim->setRandomEngine(engine);
00264   theHFDigitizer->setRandomEngine(engine);
00265   theZDCDigitizer->setRandomEngine(engine);
00266 
00267   if (theHitCorrection!=0) theHitCorrection->setRandomEngine(engine);
00268 
00269   hitsProducer_ = ps.getParameter<std::string>("hitsProducer");
00270 }
00271 
00272 
00273 HcalDigitizer::~HcalDigitizer() {
00274   delete theHBHEDigitizer;
00275   delete theHBHESiPMDigitizer;
00276   delete theHODigitizer;
00277   delete theHOSiPMDigitizer;
00278   delete theHFDigitizer;
00279   delete theZDCDigitizer;
00280   delete theParameterMap;
00281   delete theHBHEResponse;
00282   delete theHBHESiPMResponse;
00283   delete theHOResponse;
00284   delete theHOSiPMResponse;
00285   delete theHFResponse;
00286   delete theZDCResponse;
00287   delete theHBHEElectronicsSim;
00288   delete theHFElectronicsSim;
00289   delete theHOElectronicsSim;
00290   delete theZDCElectronicsSim;
00291   delete theHBHEAmplifier;
00292   delete theHFAmplifier;
00293   delete theHOAmplifier;
00294   delete theZDCAmplifier;
00295   delete theCoderFactory;
00296   delete theHitCorrection;
00297   delete theNoiseGenerator;
00298 }
00299 
00300 
00301 void HcalDigitizer::setHBHENoiseSignalGenerator(HcalBaseSignalGenerator * noiseGenerator)
00302 {
00303   noiseGenerator->setParameterMap(theParameterMap);
00304   noiseGenerator->setElectronicsSim(theHBHEElectronicsSim);
00305   theHBHEDigitizer->setNoiseSignalGenerator(noiseGenerator);
00306   theHBHEAmplifier->setNoiseSignalGenerator(noiseGenerator);
00307 }
00308 
00309 void HcalDigitizer::setHFNoiseSignalGenerator(HcalBaseSignalGenerator * noiseGenerator)
00310 {
00311   noiseGenerator->setParameterMap(theParameterMap);
00312   noiseGenerator->setElectronicsSim(theHFElectronicsSim);
00313   theHFDigitizer->setNoiseSignalGenerator(noiseGenerator);
00314   theHFAmplifier->setNoiseSignalGenerator(noiseGenerator);
00315 }
00316 
00317 void HcalDigitizer::setHONoiseSignalGenerator(HcalBaseSignalGenerator * noiseGenerator)
00318 {
00319   noiseGenerator->setParameterMap(theParameterMap);
00320   noiseGenerator->setElectronicsSim(theHOElectronicsSim);
00321   theHODigitizer->setNoiseSignalGenerator(noiseGenerator);
00322   theHOAmplifier->setNoiseSignalGenerator(noiseGenerator);
00323 }
00324 
00325 void HcalDigitizer::setZDCNoiseSignalGenerator(HcalBaseSignalGenerator * noiseGenerator)
00326 {
00327   noiseGenerator->setParameterMap(theParameterMap);
00328   noiseGenerator->setElectronicsSim(theZDCElectronicsSim);
00329   theZDCDigitizer->setNoiseSignalGenerator(noiseGenerator);
00330   theZDCAmplifier->setNoiseSignalGenerator(noiseGenerator);
00331 }
00332 
00333 
00334 void HcalDigitizer::produce(edm::Event& e, const edm::EventSetup& eventSetup) {
00335   // get the appropriate gains, noises, & widths for this event
00336   edm::ESHandle<HcalDbService> conditions;
00337   eventSetup.get<HcalDbRecord>().get(conditions);
00338   theHBHEAmplifier->setDbService(conditions.product());
00339   theHFAmplifier->setDbService(conditions.product());
00340   theHOAmplifier->setDbService(conditions.product());
00341   theZDCAmplifier->setDbService(conditions.product());
00342 
00343   theCoderFactory->setDbService(conditions.product());
00344   theParameterMap->setDbService(conditions.product());
00345 
00346    edm::ESHandle<HcalCholeskyMatrices> refCholesky;
00347    eventSetup.get<HcalCholeskyMatricesRcd>().get(refCholesky);
00348    const HcalCholeskyMatrices * myCholesky = refCholesky.product();
00349   
00350    edm::ESHandle<HcalPedestals> pedshandle;
00351    eventSetup.get<HcalPedestalsRcd>().get(pedshandle);
00352    const HcalPedestals *  myADCPedestals = pedshandle.product();
00353 
00354   theHBHEAmplifier->setCholesky(myCholesky);
00355   theHFAmplifier->setCholesky(myCholesky);
00356   theHOAmplifier->setCholesky(myCholesky);
00357   
00358   theHBHEAmplifier->setADCPeds(myADCPedestals);
00359   theHFAmplifier->setADCPeds(myADCPedestals);
00360   theHOAmplifier->setADCPeds(myADCPedestals);
00361 
00362 
00363   // Step A: Get Inputs
00364   edm::Handle<CrossingFrame<PCaloHit> > cf, zdccf;
00365 
00366   // test access to SimHits for HcalHits and ZDC hits
00367   const std::string zdcHitsName(hitsProducer_+"ZDCHITS");
00368   e.getByLabel("mix", zdcHitsName , zdccf);
00369   MixCollection<PCaloHit> * colzdc = 0 ;
00370   if(zdccf.isValid()){
00371     colzdc = new MixCollection<PCaloHit>(zdccf.product());
00372   }else{
00373     edm::LogInfo("HcalDigitizer") << "We don't have ZDC hit collection available ";
00374     isZDC = false;
00375   }
00376 
00377   const std::string hcalHitsName(hitsProducer_+"HcalHits");
00378   e.getByLabel("mix", hcalHitsName ,cf);
00379   MixCollection<PCaloHit> * col = 0 ;
00380   if(cf.isValid()){
00381     col = new MixCollection<PCaloHit>(cf.product());
00382   }else{
00383     edm::LogInfo("HcalDigitizer") << "We don't have HCAL hit collection available ";
00384     isHCAL = false;
00385   }
00386 
00387   if(theHitCorrection != 0)
00388   {
00389     theHitCorrection->clear();
00390     if(isHCAL)
00391       theHitCorrection->fillChargeSums(*col);
00392   }
00393 
00394   // Step B: Create empty output
00395   std::auto_ptr<HBHEDigiCollection> hbheResult(new HBHEDigiCollection());
00396   std::auto_ptr<HODigiCollection> hoResult(new HODigiCollection());
00397   std::auto_ptr<HFDigiCollection> hfResult(new HFDigiCollection());
00398   std::auto_ptr<ZDCDigiCollection> zdcResult(new ZDCDigiCollection());
00399 
00400   // Step C: Invoke the algorithm, passing in inputs and getting back outputs.
00401   if(isHCAL&&hbhegeo)
00402   {
00403     if(theHBHEDigitizer) theHBHEDigitizer->run(*col, *hbheResult);
00404     if(theHBHESiPMDigitizer) theHBHESiPMDigitizer->run(*col, *hbheResult);
00405   }
00406   if(isHCAL&&hogeo)
00407   {
00408     if(theHODigitizer) theHODigitizer->run(*col, *hoResult);
00409     if(theHOSiPMDigitizer) theHOSiPMDigitizer->run(*col, *hoResult);
00410   }
00411   if(isHCAL&&hfgeo)
00412     theHFDigitizer->run(*col, *hfResult);  
00413   if(isZDC&&zdcgeo) 
00414     theZDCDigitizer->run(*colzdc, *zdcResult);
00415   
00416   edm::LogInfo("HcalDigitizer") << "HCAL HBHE digis : " << hbheResult->size();
00417   edm::LogInfo("HcalDigitizer") << "HCAL HO digis   : " << hoResult->size();
00418   edm::LogInfo("HcalDigitizer") << "HCAL HF digis   : " << hfResult->size();
00419   edm::LogInfo("HcalDigitizer") << "HCAL ZDC digis   : " << zdcResult->size();
00420   // Step D: Put outputs into event
00421   e.put(hbheResult);
00422   e.put(hoResult);
00423   e.put(hfResult);
00424   e.put(zdcResult);
00425 
00426   if(theHitCorrection) {
00427     theHitCorrection->clear();
00428   }
00429 }
00430 
00431 
00432 void HcalDigitizer::beginRun(const edm::EventSetup & es)
00433 {
00434   checkGeometry(es);
00435   theShapes->beginRun(es);
00436 }
00437 
00438 
00439 void HcalDigitizer::endRun()
00440 {
00441   theShapes->endRun();
00442 }
00443 
00444 
00445 void HcalDigitizer::checkGeometry(const edm::EventSetup & eventSetup) {
00446   // TODO find a way to avoid doing this every event
00447   edm::ESHandle<CaloGeometry> geometry;
00448   eventSetup.get<CaloGeometryRecord>().get(geometry);
00449   // See if it's been updated
00450   if(&*geometry != theGeometry)
00451   {
00452     theGeometry = &*geometry;
00453     updateGeometry(eventSetup);
00454   }
00455 }
00456 
00457 
00458 void  HcalDigitizer::updateGeometry(const edm::EventSetup & eventSetup)
00459 {
00460   if(theHBHEResponse) theHBHEResponse->setGeometry(theGeometry);
00461   if(theHBHESiPMResponse) theHBHESiPMResponse->setGeometry(theGeometry);
00462   if(theHOResponse) theHOResponse->setGeometry(theGeometry);
00463   if(theHOSiPMResponse) theHOSiPMResponse->setGeometry(theGeometry);
00464   theHFResponse->setGeometry(theGeometry);
00465   theZDCResponse->setGeometry(theGeometry);
00466 
00467   const vector<DetId>& hbCells = theGeometry->getValidDetIds(DetId::Hcal, HcalBarrel);
00468   const vector<DetId>& heCells = theGeometry->getValidDetIds(DetId::Hcal, HcalEndcap);
00469   const vector<DetId>& hoCells = theGeometry->getValidDetIds(DetId::Hcal, HcalOuter);
00470   const vector<DetId>& hfCells = theGeometry->getValidDetIds(DetId::Hcal, HcalForward);
00471   const vector<DetId>& zdcCells = theGeometry->getValidDetIds(DetId::Calo, HcalZDCDetId::SubdetectorId);
00472   //const vector<DetId>& hcalTrigCells = geometry->getValidDetIds(DetId::Hcal, HcalTriggerTower);
00473   //const vector<DetId>& hcalCalib = geometry->getValidDetIds(DetId::Calo, HcalCastorDetId::SubdetectorId);
00474   //std::cout<<"HcalDigitizer::CheckGeometry number of cells: "<<zdcCells.size()<<std::endl;
00475   if(zdcCells.empty()) zdcgeo = false;
00476   if(hbCells.empty() && heCells.empty()) hbhegeo = false;
00477   if(hoCells.empty()) hogeo = false;
00478   if(hfCells.empty()) hfgeo = false;
00479   // combine HB & HE
00480 
00481 
00482   theHBHEDetIds = hbCells;
00483   theHBHEDetIds.insert(theHBHEDetIds.end(), heCells.begin(), heCells.end());
00484 
00485   HcalDigitizerImpl::fillCells(theHBHEDetIds, theHBHEDigitizer, theHBHESiPMDigitizer);
00486   //HcalDigitizerImpl::fillCells(hoCells, theHODigitizer, theHOSiPMDigitizer);
00487   buildHOSiPMCells(hoCells, eventSetup);
00488   theHFDigitizer->setDetIds(hfCells);
00489   theZDCDigitizer->setDetIds(zdcCells); 
00490 }
00491 
00492 
00493 void HcalDigitizer::buildHOSiPMCells(const std::vector<DetId>& allCells, const edm::EventSetup & eventSetup)
00494 {
00495   // all HPD
00496   if(theHOSiPMCode == 0)
00497   {
00498     theHODigitizer->setDetIds(allCells);
00499   }
00500   else if(theHOSiPMCode == 1)
00501   {
00502     theHOSiPMDigitizer->setDetIds(allCells);
00503     // FIXME pick Zecotek or hamamatsu?
00504   } 
00505   else if(theHOSiPMCode == 2)
00506   {
00507     std::vector<HcalDetId> zecotekDetIds, hamamatsuDetIds;
00508     edm::ESHandle<HcalMCParams> p;
00509     eventSetup.get<HcalMCParamsRcd>().get(p);
00510     HcalMCParams mcParams(*p.product());
00511     for(std::vector<DetId>::const_iterator detItr = allCells.begin();
00512         detItr != allCells.end(); ++detItr)
00513     {
00514       HcalDetId hcalId(*detItr);
00515       int shapeType = mcParams.getValues(*detItr)->signalShape();
00516       if(shapeType == HcalShapes::ZECOTEK) {
00517         zecotekDetIds.push_back(hcalId);
00518         theHOSiPMDetIds.push_back(*detItr);
00519       }
00520       else if(shapeType == HcalShapes::HAMAMATSU) {
00521         hamamatsuDetIds.push_back(hcalId);
00522         theHOSiPMDetIds.push_back(*detItr);
00523       }
00524       else {
00525         theHOHPDDetIds.push_back(*detItr);
00526       }
00527     }
00528 
00529     assert(theHODigitizer);
00530     assert(theHOSiPMDigitizer);
00531     theHODigitizer->setDetIds(theHOHPDDetIds);
00532     theHOSiPMDigitizer->setDetIds(theHOSiPMDetIds);
00533     theHOSiPMHitFilter.setDetIds(theHOSiPMDetIds);
00534     // FIXME not applying a HitFilter to the HPDs, for now
00535     theParameterMap->setHOZecotekDetIds(zecotekDetIds);
00536     theParameterMap->setHOHamamatsuDetIds(hamamatsuDetIds);
00537 
00538     // make sure we don't got through this exercise again
00539     theHOSiPMCode = -2;
00540   }
00541 }
00542 
00543       
00544     
00545