CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoEgamma/EgammaIsolationAlgos/plugins/EleIsoDetIdCollectionProducer.cc

Go to the documentation of this file.
00001 #include "RecoEgamma/EgammaIsolationAlgos/plugins/EleIsoDetIdCollectionProducer.h"
00002 
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 #include "FWCore/Framework/interface/EventSetup.h"
00005 #include "FWCore/Framework/interface/ESHandle.h"
00006 
00007 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00008 
00009 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00010 #include "RecoCaloTools/Selectors/interface/CaloDualConeSelector.h"
00011 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00012 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
00013 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00014 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
00015 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
00016 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00017 #include "RecoCaloTools/MetaCollections/interface/CaloRecHitMetaCollections.h"
00018 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00019 
00020 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00021 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00022 
00023 #include "DataFormats/DetId/interface/DetIdCollection.h"
00024 
00025 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
00026 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
00027 
00028 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h"
00029 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h"
00030 
00031 EleIsoDetIdCollectionProducer::EleIsoDetIdCollectionProducer(const edm::ParameterSet& iConfig) :
00032             recHitsLabel_(iConfig.getParameter< edm::InputTag > ("recHitsLabel")),
00033             emObjectLabel_(iConfig.getParameter< edm::InputTag > ("emObjectLabel")),
00034             energyCut_(iConfig.getParameter<double>("energyCut")),
00035             etCut_(iConfig.getParameter<double>("etCut")),
00036             etCandCut_(iConfig.getParameter<double> ("etCandCut")),
00037             outerRadius_(iConfig.getParameter<double>("outerRadius")),
00038             innerRadius_(iConfig.getParameter<double>("innerRadius")),
00039             interestingDetIdCollection_(iConfig.getParameter<std::string>("interestingDetIdCollection")),
00040             severityLevelCut_(iConfig.getParameter<int>("severityLevelCut")),
00041             //severityRecHitThreshold_(iConfig.getParameter<double>("severityRecHitThreshold")),
00042             //spIdString_(iConfig.getParameter<std::string>("spikeIdString")),
00043             //spIdThreshold_(iConfig.getParameter<double>("spikeIdThreshold")),
00044             v_chstatus_(iConfig.getParameter<std::vector<int> >("recHitFlagsToBeExcluded")) {
00045 
00046 
00047 //     if     ( !spIdString_.compare("kE1OverE9") )                  spId_ = EcalSeverityLevelAlgo::kE1OverE9;
00048 //     else if( !spIdString_.compare("kSwissCross") )                spId_ = EcalSeverityLevelAlgo::kSwissCross;
00049 //     else if( !spIdString_.compare("kSwissCrossBordersIncluded") ) spId_ = EcalSeverityLevelAlgo::kSwissCrossBordersIncluded;
00050 //     else                                                          spId_ = EcalSeverityLevelAlgo::kSwissCross;
00051     
00052     //register your products
00053     produces< DetIdCollection > (interestingDetIdCollection_) ;
00054 }
00055 
00056 EleIsoDetIdCollectionProducer::~EleIsoDetIdCollectionProducer() {}
00057 
00058 void EleIsoDetIdCollectionProducer::beginJob () 
00059 {}
00060 
00061 // ------------ method called to produce the data  ------------
00062     void
00063 EleIsoDetIdCollectionProducer::produce (edm::Event& iEvent, 
00064         const edm::EventSetup& iSetup)
00065 {
00066     using namespace edm;
00067     using namespace std;
00068 
00069     //Get EM Object
00070     Handle<reco::GsfElectronCollection> emObjectH;
00071     iEvent.getByLabel(emObjectLabel_,emObjectH);
00072 
00073     // take EcalRecHits
00074     Handle<EcalRecHitCollection> recHitsH;
00075     iEvent.getByLabel(recHitsLabel_,recHitsH);
00076     std::auto_ptr<CaloRecHitMetaCollectionV> recHits_(0); 
00077     recHits_ = std::auto_ptr<CaloRecHitMetaCollectionV>(new EcalRecHitMetaCollection(*recHitsH));
00078 
00079     edm::ESHandle<CaloGeometry> pG;
00080     iSetup.get<CaloGeometryRecord>().get(pG);    
00081     const CaloGeometry* caloGeom = pG.product();
00082 
00083     //Get the channel status from the db
00084     edm::ESHandle<EcalChannelStatus> chStatus;
00085     iSetup.get<EcalChannelStatusRcd>().get(chStatus);
00086 
00087     edm::ESHandle<EcalSeverityLevelAlgo> sevlv;
00088     iSetup.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
00089     const EcalSeverityLevelAlgo* sevLevel = sevlv.product();
00090 
00091     CaloDualConeSelector *doubleConeSel_ = 0;
00092     if(recHitsLabel_.instance() == "EcalRecHitsEB")
00093         doubleConeSel_= new CaloDualConeSelector(innerRadius_,outerRadius_, &*pG, DetId::Ecal, EcalBarrel);
00094     else if(recHitsLabel_.instance() == "EcalRecHitsEE")
00095         doubleConeSel_= new CaloDualConeSelector(innerRadius_,outerRadius_, &*pG, DetId::Ecal, EcalEndcap);
00096 
00097     //Create empty output collections
00098     std::auto_ptr< DetIdCollection > detIdCollection (new DetIdCollection() ) ;
00099 
00100     reco::GsfElectronCollection::const_iterator emObj;
00101     if(doubleConeSel_) { //if cone selector was created
00102         for (emObj = emObjectH->begin(); emObj != emObjectH->end();  emObj++) { //Loop over candidates
00103 
00104             if(emObj->et() < etCandCut_) continue; //don't calculate if object hasn't enough energy
00105             
00106             GlobalPoint pclu (emObj->caloPosition().x(),emObj->caloPosition().y(),emObj->caloPosition().z());
00107             std::auto_ptr<CaloRecHitMetaCollectionV> chosen = doubleConeSel_->select(pclu,*recHits_);
00108 
00109             CaloRecHitMetaCollectionV::const_iterator recIt;
00110             for (recIt = chosen->begin(); recIt!= chosen->end () ; ++recIt) { // Select RecHits 
00111 
00112                 if ( fabs(recIt->energy()) < energyCut_) continue;  //dont fill if below E noise value
00113 
00114 
00115                 double et = recIt->energy() * 
00116                             caloGeom->getPosition(recIt->detid()).perp() / 
00117                             caloGeom->getPosition(recIt->detid()).mag();
00118 
00119                 if ( fabs(et) < etCut_) continue;  //dont fill if below ET noise value
00120 
00121                 //make sure we have a barrel rechit                                     
00122                 //call the severity level method                                        
00123                 //passing the EBDetId                                                   
00124                 //the rechit collection in order to calculate the swiss crss            
00125                 //and the EcalChannelRecHitRcd                                          
00126                 //only consider rechits with ET >                                       
00127                 //the SpikeId method (currently kE1OverE9 or kSwissCross)               
00128                 //cut value for above                                                   
00129                 //then if the severity level is too high, we continue to the next rechit
00130                 
00131                 if(recHitsLabel_.instance() == "EcalRecHitsEB" && 
00132                    sevLevel->severityLevel(EBDetId(recIt->detid()), *recHitsH)  >= severityLevelCut_) continue;
00133                 //                       *chStatus,                                 
00134                   //      severityRecHitThreshold_,                 
00135                 //    spId_,                                    
00136                 //      spIdThreshold_                            
00137                   // ) >= severityLevelCut_) continue;              
00138 
00139                 //Check based on flags to protect from recovered channels from non-read towers
00140                 //Assumption is that v_chstatus_ is empty unless doFlagChecks() has been called
00141                 std::vector<int>::const_iterator vit = std::find( v_chstatus_.begin(), v_chstatus_.end(),  ((EcalRecHit*)(&*recIt))->recoFlag() );
00142                 if ( vit != v_chstatus_.end() ) continue; // the recHit has to be excluded from the iso sum
00143 
00144 
00145                 if(std::find(detIdCollection->begin(),detIdCollection->end(),recIt->detid()) == detIdCollection->end()) 
00146                             detIdCollection->push_back(recIt->detid()); 
00147             } //end rechits
00148 
00149         } //end candidates
00150 
00151         delete doubleConeSel_;
00152     } //end if cone selector was created
00153     
00154     iEvent.put( detIdCollection, interestingDetIdCollection_ );
00155 }