CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoLocalCalo/EcalRecProducers/plugins/EcalRecHitProducer.cc

Go to the documentation of this file.
00001 
00010 #include "RecoLocalCalo/EcalRecProducers/plugins/EcalRecHitProducer.h"
00011 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalCleaningAlgo.h"
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         edm::ParameterSet cleaningPs = 
00062           ps.getParameter<edm::ParameterSet>("cleaningConfig");
00063         cleaningAlgo_ = new EcalCleaningAlgo(cleaningPs);
00064 }
00065 
00066 EcalRecHitProducer::~EcalRecHitProducer()
00067 {
00068         delete worker_;
00069         delete workerRecover_;
00070         delete cleaningAlgo_;
00071 }
00072 
00073 void
00074 EcalRecHitProducer::produce(edm::Event& evt, const edm::EventSetup& es)
00075 {
00076         using namespace edm;
00077 
00078         Handle< EBUncalibratedRecHitCollection > pEBUncalibRecHits;
00079         Handle< EEUncalibratedRecHitCollection > pEEUncalibRecHits;
00080 
00081         const EBUncalibratedRecHitCollection*  ebUncalibRecHits = 0;
00082         const EEUncalibratedRecHitCollection*  eeUncalibRecHits = 0; 
00083 
00084         // get the barrel uncalib rechit collection
00085         if ( ebUncalibRecHitCollection_.label() != "" && ebUncalibRecHitCollection_.instance() != "" ) {
00086                 evt.getByLabel( ebUncalibRecHitCollection_, pEBUncalibRecHits);
00087                 if ( pEBUncalibRecHits.isValid() ) {
00088                         ebUncalibRecHits = pEBUncalibRecHits.product();
00089                         LogDebug("EcalRecHitDebug") << "total # EB uncalibrated rechits: " << ebUncalibRecHits->size();
00090                 } else {
00091                         edm::LogError("EcalRecHitError") << "Error! can't get the product " << ebUncalibRecHitCollection_;
00092                 }
00093         }
00094 
00095         if ( eeUncalibRecHitCollection_.label() != "" && eeUncalibRecHitCollection_.instance() != "" ) {
00096                 evt.getByLabel( eeUncalibRecHitCollection_, pEEUncalibRecHits);
00097                 if ( pEEUncalibRecHits.isValid() ) {
00098                         eeUncalibRecHits = pEEUncalibRecHits.product(); // get a ptr to the product
00099                         LogDebug("EcalRecHitDebug") << "total # EE uncalibrated rechits: " << eeUncalibRecHits->size();
00100                 } else {
00101                         edm::LogError("EcalRecHitError") << "Error! can't get the product " << eeUncalibRecHitCollection_;
00102                 }
00103         }
00104 
00105         // collection of rechits to put in the event
00106         std::auto_ptr< EBRecHitCollection > ebRecHits( new EBRecHitCollection );
00107         std::auto_ptr< EERecHitCollection > eeRecHits( new EERecHitCollection );
00108 
00109         worker_->set(es);
00110 
00111         if ( recoverEBIsolatedChannels_ || recoverEEIsolatedChannels_
00112                 || recoverEBFE_ || recoverEEFE_
00113                 || recoverEBVFE_ || recoverEEVFE_
00114                 || killDeadChannels_ ) {
00115                 workerRecover_->set(es);
00116         }
00117 
00118         if (ebUncalibRecHits)
00119         {
00120                 // loop over uncalibrated rechits to make calibrated ones
00121                 for(EBUncalibratedRecHitCollection::const_iterator it  = ebUncalibRecHits->begin(); it != ebUncalibRecHits->end(); ++it) {
00122                         worker_->run(evt, *it, *ebRecHits);
00123                 }
00124         }
00125 
00126         if (eeUncalibRecHits)
00127         {
00128                 // loop over uncalibrated rechits to make calibrated ones
00129                 for(EEUncalibratedRecHitCollection::const_iterator it  = eeUncalibRecHits->begin(); it != eeUncalibRecHits->end(); ++it) {
00130                         worker_->run(evt, *it, *eeRecHits);
00131                 }
00132         }
00133 
00134         // sort collections before attempting recovery, to avoid insertion of double recHits
00135         ebRecHits->sort();
00136         eeRecHits->sort();
00137         
00138         if ( recoverEBIsolatedChannels_ || recoverEBFE_ || killDeadChannels_ )
00139         {
00140                 edm::Handle< std::set<EBDetId> > pEBDetId;
00141                 const std::set<EBDetId> * detIds = 0;
00142                 if ( ebDetIdToBeRecovered_.label() != "" && ebDetIdToBeRecovered_.instance() != "" ) {
00143                         evt.getByLabel( ebDetIdToBeRecovered_, pEBDetId);
00144                         if ( pEBDetId.isValid() ) {
00145                                 detIds = pEBDetId.product();
00146                         } else {
00147                                 edm::LogError("EcalRecHitError") << "Error! can't get the product " << ebDetIdToBeRecovered_;
00148                         }
00149                 }
00150                 if ( detIds ) {
00151                         edm::ESHandle<EcalChannelStatus> chStatus;
00152                         es.get<EcalChannelStatusRcd>().get(chStatus);
00153                         for( std::set<EBDetId>::const_iterator it = detIds->begin(); it != detIds->end(); ++it ) {
00154                                 // get channel status map to treat dead VFE separately
00155                                 EcalChannelStatusMap::const_iterator chit = chStatus->find( *it );
00156                                 EcalChannelStatusCode chStatusCode = 1;
00157                                 if ( chit != chStatus->end() ) {
00158                                         chStatusCode = *chit;
00159                                 } else {
00160                                         edm::LogError("EcalRecHitProducerError") << "No channel status found for xtal "
00161                                                 << (*it).rawId()
00162                                                 << "! something wrong with EcalChannelStatus in your DB? ";
00163                                 }
00164                                 EcalUncalibratedRecHit urh;
00165                                 if ( (chStatusCode.getStatusCode() & 0x001F) == 12 ) { // dead VFE (from DB info)
00166                                         // uses the EcalUncalibratedRecHit to pass the DetId info
00167                                         urh = EcalUncalibratedRecHit( *it, 0, 0, 0, 0, EcalRecHitWorkerBaseClass::EB_VFE );
00168                                         if ( recoverEBVFE_ || killDeadChannels_ ) workerRecover_->run( evt, urh, *ebRecHits );
00169                                 } else {
00170                                         // uses the EcalUncalibratedRecHit to pass the DetId info
00171                                         urh = EcalUncalibratedRecHit( *it, 0, 0, 0, 0, EcalRecHitWorkerBaseClass::EB_single );
00172                                         if ( recoverEBIsolatedChannels_ || killDeadChannels_ ) workerRecover_->run( evt, urh, *ebRecHits );
00173                                 }
00174                                 
00175                         }
00176                 }
00177         }
00178 
00179         if ( recoverEEIsolatedChannels_ || recoverEEVFE_ || killDeadChannels_ )
00180         {
00181                 edm::Handle< std::set<EEDetId> > pEEDetId;
00182                 const std::set<EEDetId> * detIds = 0;
00183                 if ( eeDetIdToBeRecovered_.label() != "" && eeDetIdToBeRecovered_.instance() != "" ) {
00184                         evt.getByLabel( eeDetIdToBeRecovered_, pEEDetId);
00185                         if ( pEEDetId.isValid() ) {
00186                                 detIds = pEEDetId.product();
00187                         } else {
00188                                 edm::LogError("EcalRecHitError") << "Error! can't get the product " << eeDetIdToBeRecovered_;
00189                         }
00190                 }
00191                 if ( detIds ) {
00192                         edm::ESHandle<EcalChannelStatus> chStatus;
00193                         es.get<EcalChannelStatusRcd>().get(chStatus);
00194                         for( std::set<EEDetId>::const_iterator it = detIds->begin(); it != detIds->end(); ++it ) {
00195                                 // get channel status map to treat dead VFE separately
00196                                 EcalChannelStatusMap::const_iterator chit = chStatus->find( *it );
00197                                 EcalChannelStatusCode chStatusCode = 1;
00198                                 if ( chit != chStatus->end() ) {
00199                                         chStatusCode = *chit;
00200                                 } else {
00201                                         edm::LogError("EcalRecHitProducerError") << "No channel status found for xtal "
00202                                                 << (*it).rawId()
00203                                                 << "! something wrong with EcalChannelStatus in your DB? ";
00204                                 }
00205                                 EcalUncalibratedRecHit urh;
00206                                 if ( (chStatusCode.getStatusCode() & 0x001F) == 12 ) { // dead VFE (from DB info)
00207                                         // uses the EcalUncalibratedRecHit to pass the DetId info
00208                                         urh = EcalUncalibratedRecHit( *it, 0, 0, 0, 0, EcalRecHitWorkerBaseClass::EE_VFE );
00209                                         if ( recoverEEVFE_ || killDeadChannels_ ) workerRecover_->run( evt, urh, *eeRecHits );
00210                                 } else {
00211                                         // uses the EcalUncalibratedRecHit to pass the DetId info
00212                                         urh = EcalUncalibratedRecHit( *it, 0, 0, 0, 0, EcalRecHitWorkerBaseClass::EE_single );
00213                                         if ( recoverEEIsolatedChannels_ || killDeadChannels_ ) workerRecover_->run( evt, urh, *eeRecHits );
00214                                 }
00215                         }
00216                 }
00217         }
00218 
00219         if ( recoverEBFE_ || killDeadChannels_ )
00220         {
00221                 edm::Handle< std::set<EcalTrigTowerDetId> > pEBFEId;
00222                 const std::set<EcalTrigTowerDetId> * ttIds = 0;
00223                 if ( ebFEToBeRecovered_.label() != "" && ebFEToBeRecovered_.instance() != "" ) {
00224                         evt.getByLabel( ebFEToBeRecovered_, pEBFEId);
00225                         if ( pEBFEId.isValid() ) {
00226                                 ttIds = pEBFEId.product();
00227                         } else {
00228                                 edm::LogError("EcalRecHitError") << "Error! can't get the product " << ebFEToBeRecovered_;
00229                         }
00230                 }
00231                 if ( ttIds ) {
00232                         for( std::set<EcalTrigTowerDetId>::const_iterator it = ttIds->begin(); it != ttIds->end(); ++it ) {
00233                                 // uses the EcalUncalibratedRecHit to pass the DetId info
00234                                 int ieta = (((*it).ietaAbs()-1)*5+1)*(*it).zside(); // from EcalTrigTowerConstituentsMap
00235                                 int iphi = ((*it).iphi()-1)*5+11;                   // from EcalTrigTowerConstituentsMap
00236                                 if( iphi <= 0 ) iphi += 360;                        // from EcalTrigTowerConstituentsMap
00237                                 EcalUncalibratedRecHit urh( EBDetId(ieta, iphi, EBDetId::ETAPHIMODE), 0, 0, 0, 0, EcalRecHitWorkerBaseClass::EB_FE );
00238                                 workerRecover_->run( evt, urh, *ebRecHits );
00239                         }
00240                 }
00241         }
00242 
00243         if ( recoverEEFE_ || killDeadChannels_ )
00244         {
00245                 edm::Handle< std::set<EcalScDetId> > pEEFEId;
00246                 const std::set<EcalScDetId> * scIds = 0;
00247                 if ( eeFEToBeRecovered_.label() != "" && eeFEToBeRecovered_.instance() != "" ) {
00248                         evt.getByLabel( eeFEToBeRecovered_, pEEFEId);
00249                         if ( pEEFEId.isValid() ) {
00250                                 scIds = pEEFEId.product();
00251                         } else {
00252                                 edm::LogError("EcalRecHitError") << "Error! can't get the product " << eeFEToBeRecovered_;
00253                         }
00254                 }
00255                 if ( scIds ) {
00256                         for( std::set<EcalScDetId>::const_iterator it = scIds->begin(); it != scIds->end(); ++it ) {
00257                                 // uses the EcalUncalibratedRecHit to pass the DetId info
00258                                 if (EEDetId::validDetId( ((*it).ix()-1)*5+1, ((*it).iy()-1)*5+1, (*it).zside() )) {
00259                                         EcalUncalibratedRecHit urh( EEDetId( ((*it).ix()-1)*5+1, ((*it).iy()-1)*5+1, (*it).zside() ), 0, 0, 0, 0, EcalRecHitWorkerBaseClass::EE_FE );
00260                                         workerRecover_->run( evt, urh, *eeRecHits );
00261                                 }
00262                         }
00263                 }
00264         }
00265 
00266         // if not sorted, find will not work
00267         ebRecHits->sort();
00268         eeRecHits->sort();
00269 
00270         // cleaning of anomalous signals, aka spikes
00271         EcalRecHitCollection::iterator rh;
00272         for (rh=ebRecHits->begin(); rh!=ebRecHits->end(); ++rh){
00273           EcalRecHit::Flags state=cleaningAlgo_->checkTopology(rh->id(),*ebRecHits);
00274           if (state!=EcalRecHit::kGood) { 
00275             rh->unsetFlag(EcalRecHit::kGood);
00276             rh->setFlag(state);
00277           }
00278         }
00279         
00280         for (rh=eeRecHits->begin(); rh!=eeRecHits->end(); ++rh){
00281           EcalRecHit::Flags state=cleaningAlgo_->checkTopology(rh->id(),*eeRecHits);
00282           if (state!=EcalRecHit::kGood) {
00283             rh->unsetFlag(EcalRecHit::kGood);
00284             rh->setFlag(state);
00285           }
00286         }
00287 
00288         // put the collection of recunstructed hits in the event   
00289         LogInfo("EcalRecHitInfo") << "total # EB calibrated rechits: " << ebRecHits->size();
00290         LogInfo("EcalRecHitInfo") << "total # EE calibrated rechits: " << eeRecHits->size();
00291 
00292         evt.put( ebRecHits, ebRechitCollection_ );
00293         evt.put( eeRecHits, eeRechitCollection_ );
00294 }
00295 
00296 #include "FWCore/Framework/interface/MakerMacros.h"
00297 DEFINE_FWK_MODULE( EcalRecHitProducer );