CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/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 #include "CommonTools/Utils/interface/StringToEnumValue.h"
00007 
00008 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00009 
00010 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00011 #include "RecoCaloTools/Selectors/interface/CaloDualConeSelector.h"
00012 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00013 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
00014 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00015 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
00016 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
00017 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00018 #include "RecoCaloTools/MetaCollections/interface/CaloRecHitMetaCollections.h"
00019 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00020 
00021 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00022 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00023 
00024 #include "DataFormats/DetId/interface/DetIdCollection.h"
00025 
00026 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
00027 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
00028 
00029 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h"
00030 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h"
00031 
00032 EleIsoDetIdCollectionProducer::EleIsoDetIdCollectionProducer(const edm::ParameterSet& iConfig) :
00033             recHitsLabel_(iConfig.getParameter< edm::InputTag > ("recHitsLabel")),
00034             emObjectLabel_(iConfig.getParameter< edm::InputTag > ("emObjectLabel")),
00035             energyCut_(iConfig.getParameter<double>("energyCut")),
00036             etCut_(iConfig.getParameter<double>("etCut")),
00037             etCandCut_(iConfig.getParameter<double> ("etCandCut")),
00038             outerRadius_(iConfig.getParameter<double>("outerRadius")),
00039             innerRadius_(iConfig.getParameter<double>("innerRadius")),
00040             interestingDetIdCollection_(iConfig.getParameter<std::string>("interestingDetIdCollection"))
00041  {
00042 
00043    const std::vector<std::string> flagnamesEB = 
00044      iConfig.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEB");
00045    
00046    const std::vector<std::string> flagnamesEE =
00047      iConfig.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEE");
00048    
00049    flagsexclEB_= 
00050      StringToEnumValue<EcalRecHit::Flags>(flagnamesEB);
00051    
00052    flagsexclEE_=
00053      StringToEnumValue<EcalRecHit::Flags>(flagnamesEE);
00054    
00055    const std::vector<std::string> severitynamesEB = 
00056      iConfig.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcludedEB");
00057    
00058    severitiesexclEB_= 
00059      StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEB);
00060 
00061    const std::vector<std::string> severitynamesEE = 
00062      iConfig.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcludedEE");
00063    
00064    severitiesexclEE_= 
00065      StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEE);
00066    
00067    //register your products
00068    produces< DetIdCollection > (interestingDetIdCollection_) ;
00069 }
00070 
00071 EleIsoDetIdCollectionProducer::~EleIsoDetIdCollectionProducer() 
00072 {}
00073 
00074 void EleIsoDetIdCollectionProducer::beginJob () 
00075 {}
00076 
00077 // ------------ method called to produce the data  ------------
00078     void
00079 EleIsoDetIdCollectionProducer::produce (edm::Event& iEvent, const edm::EventSetup& iSetup) {
00080     using namespace edm;
00081     using namespace std;
00082 
00083     //Get EM Object
00084     Handle<reco::GsfElectronCollection> emObjectH;
00085     iEvent.getByLabel(emObjectLabel_,emObjectH);
00086 
00087     // take EcalRecHits
00088     Handle<EcalRecHitCollection> recHitsH;
00089     iEvent.getByLabel(recHitsLabel_,recHitsH);
00090     std::auto_ptr<CaloRecHitMetaCollectionV> recHits_(0); 
00091     recHits_ = std::auto_ptr<CaloRecHitMetaCollectionV>(new EcalRecHitMetaCollection(*recHitsH));
00092 
00093     edm::ESHandle<CaloGeometry> pG;
00094     iSetup.get<CaloGeometryRecord>().get(pG);    
00095     const CaloGeometry* caloGeom = pG.product();
00096 
00097     //Get the channel status from the db
00098     //edm::ESHandle<EcalChannelStatus> chStatus;
00099     //iSetup.get<EcalChannelStatusRcd>().get(chStatus);
00100 
00101     edm::ESHandle<EcalSeverityLevelAlgo> sevlv;
00102     iSetup.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
00103     const EcalSeverityLevelAlgo* sevLevel = sevlv.product();
00104 
00105     CaloDualConeSelector *doubleConeSel_ = 0;
00106     if(recHitsLabel_.instance() == "EcalRecHitsEB")
00107         doubleConeSel_= new CaloDualConeSelector(innerRadius_,outerRadius_, &*pG, DetId::Ecal, EcalBarrel);
00108     else if(recHitsLabel_.instance() == "EcalRecHitsEE")
00109         doubleConeSel_= new CaloDualConeSelector(innerRadius_,outerRadius_, &*pG, DetId::Ecal, EcalEndcap);
00110 
00111     //Create empty output collections
00112     std::auto_ptr< DetIdCollection > detIdCollection (new DetIdCollection() ) ;
00113 
00114     reco::GsfElectronCollection::const_iterator emObj;
00115     if(doubleConeSel_) { //if cone selector was created
00116         for (emObj = emObjectH->begin(); emObj != emObjectH->end();  emObj++) { //Loop over candidates
00117 
00118             if(emObj->et() < etCandCut_) continue; //don't calculate if object hasn't enough energy
00119             
00120             GlobalPoint pclu (emObj->caloPosition().x(),emObj->caloPosition().y(),emObj->caloPosition().z());
00121             std::auto_ptr<CaloRecHitMetaCollectionV> chosen = doubleConeSel_->select(pclu,*recHits_);
00122 
00123             CaloRecHitMetaCollectionV::const_iterator recIt;
00124             for (recIt = chosen->begin(); recIt!= chosen->end () ; ++recIt) { // Select RecHits 
00125 
00126               if (recIt->energy() < energyCut_) 
00127                 continue;  //dont fill if below E noise value
00128 
00129               double et = recIt->energy() * 
00130                 caloGeom->getPosition(recIt->detid()).perp() / 
00131                 caloGeom->getPosition(recIt->detid()).mag();
00132 
00133               bool isBarrel = false;
00134               if (fabs(caloGeom->getPosition(recIt->detid()).eta() < 1.479)) 
00135                 isBarrel = true;
00136               
00137               if (et < etCut_) 
00138                 continue;  //dont fill if below ET noise value
00139 
00140               std::vector<int>::const_iterator sit;
00141               int severityFlag = sevLevel->severityLevel(((EcalRecHit*)(&*recIt))->detid(), *recHitsH);
00142               if (isBarrel) {
00143                 sit = std::find(severitiesexclEB_.begin(), severitiesexclEB_.end(), severityFlag);
00144                 if (sit != severitiesexclEB_.end())
00145                   continue;
00146               } else {
00147                 sit = std::find(severitiesexclEE_.begin(), severitiesexclEE_.end(), severityFlag);
00148                 if (sit != severitiesexclEE_.end())
00149                   continue;
00150               }
00151 
00152               std::vector<int>::const_iterator vit;
00153               if (isBarrel) {
00154                 vit = std::find(flagsexclEB_.begin(), flagsexclEB_.end(), ((EcalRecHit*)(&*recIt))->recoFlag());
00155                 if (vit != flagsexclEB_.end())
00156                   continue;
00157               } else {
00158                 vit = std::find(flagsexclEE_.begin(), flagsexclEE_.end(), ((EcalRecHit*)(&*recIt))->recoFlag());
00159                 if (vit != flagsexclEE_.end())
00160                   continue;
00161               }
00162 
00163               if(std::find(detIdCollection->begin(),detIdCollection->end(),recIt->detid()) == detIdCollection->end()) 
00164                 detIdCollection->push_back(recIt->detid()); 
00165             } //end rechits
00166             
00167         } //end candidates
00168         
00169         delete doubleConeSel_;
00170     } //end if cone selector was created
00171     
00172     iEvent.put( detIdCollection, interestingDetIdCollection_ );
00173 }