CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/RecoLocalCalo/EcalRecProducers/plugins/EcalUncalibRecHitProducer.cc

Go to the documentation of this file.
00001 #include "RecoLocalCalo/EcalRecProducers/plugins/EcalUncalibRecHitProducer.h"
00002 
00003 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00004 #include "DataFormats/Common/interface/Handle.h"
00005 
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 
00008 #include "RecoLocalCalo/EcalRecProducers/interface/EcalUncalibRecHitWorkerFactory.h"
00009 
00010 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00011 
00012 EcalUncalibRecHitProducer::EcalUncalibRecHitProducer(const edm::ParameterSet& ps)
00013 {
00014         ebDigiCollection_ = ps.getParameter<edm::InputTag>("EBdigiCollection");
00015         eeDigiCollection_ = ps.getParameter<edm::InputTag>("EEdigiCollection");
00016         ebHitCollection_  = ps.getParameter<std::string>("EBhitCollection");
00017         eeHitCollection_  = ps.getParameter<std::string>("EEhitCollection");
00018         produces< EBUncalibratedRecHitCollection >(ebHitCollection_);
00019         produces< EEUncalibratedRecHitCollection >(eeHitCollection_);
00020 
00021         std::string componentType = ps.getParameter<std::string>("algo");
00022         worker_ = EcalUncalibRecHitWorkerFactory::get()->create(componentType, ps);
00023 }
00024 
00025 EcalUncalibRecHitProducer::~EcalUncalibRecHitProducer()
00026 {
00027         delete worker_;
00028 }
00029 
00030 void
00031 EcalUncalibRecHitProducer::produce(edm::Event& evt, const edm::EventSetup& es) {
00032 
00033         using namespace edm;
00034 
00035         Handle< EBDigiCollection > pEBDigis;
00036         Handle< EEDigiCollection > pEEDigis;
00037 
00038         const EBDigiCollection* ebDigis =0;
00039         const EEDigiCollection* eeDigis =0;
00040 
00041         if ( ebDigiCollection_.label() != "" && ebDigiCollection_.instance() != "" ) {
00042                 evt.getByLabel( ebDigiCollection_, pEBDigis);
00043                 //evt.getByLabel( digiProducer_, pEBDigis);
00044                 if ( pEBDigis.isValid() ) {
00045                         ebDigis = pEBDigis.product(); // get a ptr to the produc
00046                         edm::LogInfo("EcalUncalibRecHitInfo") << "total # ebDigis: " << ebDigis->size() ;
00047                 } else {
00048                         edm::LogError("EcalUncalibRecHitError") << "Error! can't get the product " << ebDigiCollection_;
00049                 }
00050         }
00051 
00052         if ( eeDigiCollection_.label() != "" && eeDigiCollection_.instance() != "" ) {
00053                 evt.getByLabel( eeDigiCollection_, pEEDigis);
00054                 //evt.getByLabel( digiProducer_, pEEDigis);
00055                 if ( pEEDigis.isValid() ) {
00056                         eeDigis = pEEDigis.product(); // get a ptr to the product
00057                         edm::LogInfo("EcalUncalibRecHitInfo") << "total # eeDigis: " << eeDigis->size() ;
00058                 } else {
00059                         edm::LogError("EcalUncalibRecHitError") << "Error! can't get the product " << eeDigiCollection_;
00060                 }
00061         }
00062 
00063         // tranparently get things from event setup
00064         worker_->set(es);
00065 
00066         // prepare output
00067         std::auto_ptr< EBUncalibratedRecHitCollection > ebUncalibRechits( new EBUncalibratedRecHitCollection );
00068         std::auto_ptr< EEUncalibratedRecHitCollection > eeUncalibRechits( new EEUncalibratedRecHitCollection );
00069 
00070         // loop over EB digis
00071         if (ebDigis)
00072         {
00073                 ebUncalibRechits->reserve(ebDigis->size());
00074                 for(EBDigiCollection::const_iterator itdg = ebDigis->begin(); itdg != ebDigis->end(); ++itdg) {
00075                         worker_->run(evt, itdg, *ebUncalibRechits);
00076                 }
00077         }
00078 
00079         // loop over EB digis
00080         if (eeDigis)
00081         {
00082                 eeUncalibRechits->reserve(eeDigis->size());
00083                 for(EEDigiCollection::const_iterator itdg = eeDigis->begin(); itdg != eeDigis->end(); ++itdg) {
00084                         worker_->run(evt, itdg, *eeUncalibRechits);
00085                 }
00086         }
00087 
00088         // put the collection of recunstructed hits in the event
00089         evt.put( ebUncalibRechits, ebHitCollection_ );
00090         evt.put( eeUncalibRechits, eeHitCollection_ );
00091 }
00092 
00093 #include "FWCore/Framework/interface/MakerMacros.h"                                                                                                            
00094 DEFINE_FWK_MODULE( EcalUncalibRecHitProducer );