CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/RecoLocalCalo/EcalRecProducers/plugins/EcalRecHitProducer.cc

Go to the documentation of this file.
00001 
00010 #include "RecoLocalCalo/EcalRecProducers/plugins/EcalRecHitProducer.h"
00011 
00012 #include "DataFormats/Common/interface/Handle.h"
00013 #include "FWCore/Framework/interface/ESHandle.h"
00014 
00015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00016 
00017 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00018 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00019 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00020 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00021 #include "DataFormats/EcalDetId/interface/EcalElectronicsId.h"
00022 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
00023 #include "DataFormats/EcalDetId/interface/EcalScDetId.h"
00024 
00025 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
00026 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
00027 
00028 #include "RecoLocalCalo/EcalRecProducers/interface/EcalRecHitWorkerFactory.h"
00029 
00030 
00031 EcalRecHitProducer::EcalRecHitProducer(const edm::ParameterSet& ps)
00032 {
00033         ebUncalibRecHitCollection_ = ps.getParameter<edm::InputTag>("EBuncalibRecHitCollection");
00034         eeUncalibRecHitCollection_ = ps.getParameter<edm::InputTag>("EEuncalibRecHitCollection");
00035         ebRechitCollection_        = ps.getParameter<std::string>("EBrechitCollection");
00036         eeRechitCollection_        = ps.getParameter<std::string>("EErechitCollection");
00037 
00038         recoverEBIsolatedChannels_   = ps.getParameter<bool>("recoverEBIsolatedChannels");
00039         recoverEEIsolatedChannels_   = ps.getParameter<bool>("recoverEEIsolatedChannels");
00040         recoverEBVFE_                = ps.getParameter<bool>("recoverEBVFE");
00041         recoverEEVFE_                = ps.getParameter<bool>("recoverEEVFE");
00042         recoverEBFE_                 = ps.getParameter<bool>("recoverEBFE");
00043         recoverEEFE_                 = ps.getParameter<bool>("recoverEEFE");
00044         killDeadChannels_            = ps.getParameter<bool>("killDeadChannels");
00045 
00046         ebDetIdToBeRecovered_        = ps.getParameter<edm::InputTag>("ebDetIdToBeRecovered");
00047         eeDetIdToBeRecovered_        = ps.getParameter<edm::InputTag>("eeDetIdToBeRecovered");
00048         ebFEToBeRecovered_           = ps.getParameter<edm::InputTag>("ebFEToBeRecovered");
00049         eeFEToBeRecovered_           = ps.getParameter<edm::InputTag>("eeFEToBeRecovered");
00050 
00051         produces< EBRecHitCollection >(ebRechitCollection_);
00052         produces< EERecHitCollection >(eeRechitCollection_);
00053 
00054         std::string componentType = ps.getParameter<std::string>("algo");
00055         worker_ = EcalRecHitWorkerFactory::get()->create(componentType, ps);
00056 
00057         // to recover problematic channels
00058         componentType = ps.getParameter<std::string>("algoRecover");
00059         workerRecover_ = EcalRecHitWorkerFactory::get()->create(componentType, ps);
00060 }
00061 
00062 EcalRecHitProducer::~EcalRecHitProducer()
00063 {
00064         delete worker_;
00065         delete workerRecover_;
00066 }
00067 
00068 void
00069 EcalRecHitProducer::produce(edm::Event& evt, const edm::EventSetup& es)
00070 {
00071         using namespace edm;
00072 
00073         Handle< EBUncalibratedRecHitCollection > pEBUncalibRecHits;
00074         Handle< EEUncalibratedRecHitCollection > pEEUncalibRecHits;
00075 
00076         const EBUncalibratedRecHitCollection*  ebUncalibRecHits = 0;
00077         const EEUncalibratedRecHitCollection*  eeUncalibRecHits = 0; 
00078 
00079         // get the barrel uncalib rechit collection
00080         if ( ebUncalibRecHitCollection_.label() != "" && ebUncalibRecHitCollection_.instance() != "" ) {
00081                 evt.getByLabel( ebUncalibRecHitCollection_, pEBUncalibRecHits);
00082                 if ( pEBUncalibRecHits.isValid() ) {
00083                         ebUncalibRecHits = pEBUncalibRecHits.product();
00084                         LogDebug("EcalRecHitDebug") << "total # EB uncalibrated rechits: " << ebUncalibRecHits->size();
00085                 } else {
00086                         edm::LogError("EcalRecHitError") << "Error! can't get the product " << ebUncalibRecHitCollection_;
00087                 }
00088         }
00089 
00090         if ( eeUncalibRecHitCollection_.label() != "" && eeUncalibRecHitCollection_.instance() != "" ) {
00091                 evt.getByLabel( eeUncalibRecHitCollection_, pEEUncalibRecHits);
00092                 if ( pEEUncalibRecHits.isValid() ) {
00093                         eeUncalibRecHits = pEEUncalibRecHits.product(); // get a ptr to the product
00094                         LogDebug("EcalRecHitDebug") << "total # EE uncalibrated rechits: " << eeUncalibRecHits->size();
00095                 } else {
00096                         edm::LogError("EcalRecHitError") << "Error! can't get the product " << eeUncalibRecHitCollection_;
00097                 }
00098         }
00099 
00100         // collection of rechits to put in the event
00101         std::auto_ptr< EBRecHitCollection > ebRecHits( new EBRecHitCollection );
00102         std::auto_ptr< EERecHitCollection > eeRecHits( new EERecHitCollection );
00103 
00104         worker_->set(es);
00105 
00106         if ( recoverEBIsolatedChannels_ || recoverEEIsolatedChannels_
00107                 || recoverEBFE_ || recoverEEFE_
00108                 || recoverEBVFE_ || recoverEEVFE_
00109                 || killDeadChannels_ ) {
00110                 workerRecover_->set(es);
00111         }
00112 
00113         if (ebUncalibRecHits)
00114         {
00115                 // loop over uncalibrated rechits to make calibrated ones
00116                 for(EBUncalibratedRecHitCollection::const_iterator it  = ebUncalibRecHits->begin(); it != ebUncalibRecHits->end(); ++it) {
00117                         worker_->run(evt, *it, *ebRecHits);
00118                 }
00119         }
00120 
00121         if (eeUncalibRecHits)
00122         {
00123                 // loop over uncalibrated rechits to make calibrated ones
00124                 for(EEUncalibratedRecHitCollection::const_iterator it  = eeUncalibRecHits->begin(); it != eeUncalibRecHits->end(); ++it) {
00125                         worker_->run(evt, *it, *eeRecHits);
00126                 }
00127         }
00128 
00129         // sort collections before attempting recovery, to avoid insertion of double recHits
00130         ebRecHits->sort();
00131         eeRecHits->sort();
00132         
00133         if ( recoverEBIsolatedChannels_ || recoverEBFE_ || killDeadChannels_ )
00134         {
00135                 edm::Handle< std::set<EBDetId> > pEBDetId;
00136                 const std::set<EBDetId> * detIds = 0;
00137                 if ( ebDetIdToBeRecovered_.label() != "" && ebDetIdToBeRecovered_.instance() != "" ) {
00138                         evt.getByLabel( ebDetIdToBeRecovered_, pEBDetId);
00139                         if ( pEBDetId.isValid() ) {
00140                                 detIds = pEBDetId.product();
00141                         } else {
00142                                 edm::LogError("EcalRecHitError") << "Error! can't get the product " << ebDetIdToBeRecovered_;
00143                         }
00144                 }
00145                 if ( detIds ) {
00146                         edm::ESHandle<EcalChannelStatus> chStatus;
00147                         es.get<EcalChannelStatusRcd>().get(chStatus);
00148                         for( std::set<EBDetId>::const_iterator it = detIds->begin(); it != detIds->end(); ++it ) {
00149                                 // get channel status map to treat dead VFE separately
00150                                 EcalChannelStatusMap::const_iterator chit = chStatus->find( *it );
00151                                 EcalChannelStatusCode chStatusCode = 1;
00152                                 if ( chit != chStatus->end() ) {
00153                                         chStatusCode = *chit;
00154                                 } else {
00155                                         edm::LogError("EcalRecHitProducerError") << "No channel status found for xtal "
00156                                                 << (*it).rawId()
00157                                                 << "! something wrong with EcalChannelStatus in your DB? ";
00158                                 }
00159                                 EcalUncalibratedRecHit urh;
00160                                 if ( (chStatusCode.getStatusCode() & 0x001F) == 12 ) { // dead VFE (from DB info)
00161                                         // uses the EcalUncalibratedRecHit to pass the DetId info
00162                                         urh = EcalUncalibratedRecHit( *it, 0, 0, 0, 0, EcalRecHitWorkerBaseClass::EB_VFE );
00163                                         if ( recoverEBVFE_ || killDeadChannels_ ) workerRecover_->run( evt, urh, *ebRecHits );
00164                                 } else {
00165                                         // uses the EcalUncalibratedRecHit to pass the DetId info
00166                                         urh = EcalUncalibratedRecHit( *it, 0, 0, 0, 0, EcalRecHitWorkerBaseClass::EB_single );
00167                                         if ( recoverEBIsolatedChannels_ || killDeadChannels_ ) workerRecover_->run( evt, urh, *ebRecHits );
00168                                 }
00169                                 
00170                         }
00171                 }
00172         }
00173 
00174         if ( recoverEEIsolatedChannels_ || recoverEEVFE_ || killDeadChannels_ )
00175         {
00176                 edm::Handle< std::set<EEDetId> > pEEDetId;
00177                 const std::set<EEDetId> * detIds = 0;
00178                 if ( eeDetIdToBeRecovered_.label() != "" && eeDetIdToBeRecovered_.instance() != "" ) {
00179                         evt.getByLabel( eeDetIdToBeRecovered_, pEEDetId);
00180                         if ( pEEDetId.isValid() ) {
00181                                 detIds = pEEDetId.product();
00182                         } else {
00183                                 edm::LogError("EcalRecHitError") << "Error! can't get the product " << eeDetIdToBeRecovered_;
00184                         }
00185                 }
00186                 if ( detIds ) {
00187                         edm::ESHandle<EcalChannelStatus> chStatus;
00188                         es.get<EcalChannelStatusRcd>().get(chStatus);
00189                         for( std::set<EEDetId>::const_iterator it = detIds->begin(); it != detIds->end(); ++it ) {
00190                                 // get channel status map to treat dead VFE separately
00191                                 EcalChannelStatusMap::const_iterator chit = chStatus->find( *it );
00192                                 EcalChannelStatusCode chStatusCode = 1;
00193                                 if ( chit != chStatus->end() ) {
00194                                         chStatusCode = *chit;
00195                                 } else {
00196                                         edm::LogError("EcalRecHitProducerError") << "No channel status found for xtal "
00197                                                 << (*it).rawId()
00198                                                 << "! something wrong with EcalChannelStatus in your DB? ";
00199                                 }
00200                                 EcalUncalibratedRecHit urh;
00201                                 if ( (chStatusCode.getStatusCode() & 0x001F) == 12 ) { // dead VFE (from DB info)
00202                                         // uses the EcalUncalibratedRecHit to pass the DetId info
00203                                         urh = EcalUncalibratedRecHit( *it, 0, 0, 0, 0, EcalRecHitWorkerBaseClass::EE_VFE );
00204                                         if ( recoverEEVFE_ || killDeadChannels_ ) workerRecover_->run( evt, urh, *eeRecHits );
00205                                 } else {
00206                                         // uses the EcalUncalibratedRecHit to pass the DetId info
00207                                         urh = EcalUncalibratedRecHit( *it, 0, 0, 0, 0, EcalRecHitWorkerBaseClass::EE_single );
00208                                         if ( recoverEEIsolatedChannels_ || killDeadChannels_ ) workerRecover_->run( evt, urh, *eeRecHits );
00209                                 }
00210                         }
00211                 }
00212         }
00213 
00214         if ( recoverEBFE_ || killDeadChannels_ )
00215         {
00216                 edm::Handle< std::set<EcalTrigTowerDetId> > pEBFEId;
00217                 const std::set<EcalTrigTowerDetId> * ttIds = 0;
00218                 if ( ebFEToBeRecovered_.label() != "" && ebFEToBeRecovered_.instance() != "" ) {
00219                         evt.getByLabel( ebFEToBeRecovered_, pEBFEId);
00220                         if ( pEBFEId.isValid() ) {
00221                                 ttIds = pEBFEId.product();
00222                         } else {
00223                                 edm::LogError("EcalRecHitError") << "Error! can't get the product " << ebFEToBeRecovered_;
00224                         }
00225                 }
00226                 if ( ttIds ) {
00227                         for( std::set<EcalTrigTowerDetId>::const_iterator it = ttIds->begin(); it != ttIds->end(); ++it ) {
00228                                 // uses the EcalUncalibratedRecHit to pass the DetId info
00229                                 int ieta = (((*it).ietaAbs()-1)*5+1)*(*it).zside(); // from EcalTrigTowerConstituentsMap
00230                                 int iphi = ((*it).iphi()-1)*5+11;                   // from EcalTrigTowerConstituentsMap
00231                                 if( iphi <= 0 ) iphi += 360;                        // from EcalTrigTowerConstituentsMap
00232                                 EcalUncalibratedRecHit urh( EBDetId(ieta, iphi, EBDetId::ETAPHIMODE), 0, 0, 0, 0, EcalRecHitWorkerBaseClass::EB_FE );
00233                                 workerRecover_->run( evt, urh, *ebRecHits );
00234                         }
00235                 }
00236         }
00237 
00238         if ( recoverEEFE_ || killDeadChannels_ )
00239         {
00240                 edm::Handle< std::set<EcalScDetId> > pEEFEId;
00241                 const std::set<EcalScDetId> * scIds = 0;
00242                 if ( eeFEToBeRecovered_.label() != "" && eeFEToBeRecovered_.instance() != "" ) {
00243                         evt.getByLabel( eeFEToBeRecovered_, pEEFEId);
00244                         if ( pEEFEId.isValid() ) {
00245                                 scIds = pEEFEId.product();
00246                         } else {
00247                                 edm::LogError("EcalRecHitError") << "Error! can't get the product " << eeFEToBeRecovered_;
00248                         }
00249                 }
00250                 if ( scIds ) {
00251                         for( std::set<EcalScDetId>::const_iterator it = scIds->begin(); it != scIds->end(); ++it ) {
00252                                 // uses the EcalUncalibratedRecHit to pass the DetId info
00253                                 if (EEDetId::validDetId( ((*it).ix()-1)*5+1, ((*it).iy()-1)*5+1, (*it).zside() )) {
00254                                         EcalUncalibratedRecHit urh( EEDetId( ((*it).ix()-1)*5+1, ((*it).iy()-1)*5+1, (*it).zside() ), 0, 0, 0, 0, EcalRecHitWorkerBaseClass::EE_FE );
00255                                         workerRecover_->run( evt, urh, *eeRecHits );
00256                                 }
00257                         }
00258                 }
00259         }
00260 
00261         // put the collection of recunstructed hits in the event   
00262         LogInfo("EcalRecHitInfo") << "total # EB calibrated rechits: " << ebRecHits->size();
00263         LogInfo("EcalRecHitInfo") << "total # EE calibrated rechits: " << eeRecHits->size();
00264 
00265         evt.put( ebRecHits, ebRechitCollection_ );
00266         evt.put( eeRecHits, eeRechitCollection_ );
00267 }
00268 
00269 #include "FWCore/Framework/interface/MakerMacros.h"
00270 DEFINE_FWK_MODULE( EcalRecHitProducer );