CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/RecoEgamma/EgammaIsolationAlgos/plugins/GamIsoDetIdCollectionProducer.cc

Go to the documentation of this file.
00001 #include "RecoEgamma/EgammaIsolationAlgos/plugins/GamIsoDetIdCollectionProducer.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/Photon.h"
00013 #include "DataFormats/EgammaCandidates/interface/PhotonFwd.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 GamIsoDetIdCollectionProducer::GamIsoDetIdCollectionProducer(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 GamIsoDetIdCollectionProducer::~GamIsoDetIdCollectionProducer() 
00072 {}
00073 
00074 void GamIsoDetIdCollectionProducer::beginJob () 
00075 {}
00076 
00077 // ------------ method called to produce the data  ------------
00078     void
00079 GamIsoDetIdCollectionProducer::produce (edm::Event& iEvent, 
00080         const edm::EventSetup& iSetup)
00081 {
00082     using namespace edm;
00083     using namespace std;
00084 
00085     //Get EM Object
00086     Handle<reco::PhotonCollection> emObjectH;
00087     iEvent.getByLabel(emObjectLabel_,emObjectH);
00088 
00089     // take EcalRecHits
00090     Handle<EcalRecHitCollection> recHitsH;
00091     iEvent.getByLabel(recHitsLabel_,recHitsH);
00092     std::auto_ptr<CaloRecHitMetaCollectionV> recHits_(0); 
00093     recHits_ = std::auto_ptr<CaloRecHitMetaCollectionV>(new EcalRecHitMetaCollection(*recHitsH));
00094 
00095     edm::ESHandle<CaloGeometry> pG;
00096     iSetup.get<CaloGeometryRecord>().get(pG);    
00097     const CaloGeometry* caloGeom = pG.product();
00098 
00099     edm::ESHandle<EcalSeverityLevelAlgo> sevlv;
00100     iSetup.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
00101     const EcalSeverityLevelAlgo* sevLevel = sevlv.product();
00102 
00103     CaloDualConeSelector *doubleConeSel_ = 0;
00104     if(recHitsLabel_.instance() == "EcalRecHitsEB")
00105         doubleConeSel_= new CaloDualConeSelector(innerRadius_,outerRadius_, &*pG, DetId::Ecal, EcalBarrel);
00106     else if(recHitsLabel_.instance() == "EcalRecHitsEE")
00107         doubleConeSel_= new CaloDualConeSelector(innerRadius_,outerRadius_, &*pG, DetId::Ecal, EcalEndcap);
00108 
00109     //Create empty output collections
00110     std::auto_ptr< DetIdCollection > detIdCollection (new DetIdCollection() ) ;
00111 
00112     reco::PhotonCollection::const_iterator emObj;
00113     if(doubleConeSel_) { //if cone selector was created
00114         for (emObj = emObjectH->begin(); emObj != emObjectH->end();  emObj++) { //Loop over candidates
00115 
00116             if(emObj->et() < etCandCut_) continue;
00117             
00118             GlobalPoint pclu (emObj->caloPosition().x(),emObj->caloPosition().y(),emObj->caloPosition().z());
00119             std::auto_ptr<CaloRecHitMetaCollectionV> chosen = doubleConeSel_->select(pclu,*recHits_);
00120 
00121             CaloRecHitMetaCollectionV::const_iterator recIt;
00122             for (recIt = chosen->begin(); recIt!= chosen->end () ; ++recIt) { // Select RecHits 
00123 
00124                 if ( (recIt->energy()) < energyCut_) continue;  //dont fill if below E noise value
00125 
00126                 double et = recIt->energy() *
00127                             caloGeom->getPosition(recIt->detid()).perp() /
00128                             caloGeom->getPosition(recIt->detid()).mag();
00129                 
00130                 if ( et < etCut_) continue;  //dont fill if below ET noise value
00131 
00132                 bool isBarrel = false;
00133                 if (fabs(caloGeom->getPosition(recIt->detid()).eta() < 1.479)) 
00134                   isBarrel = true;
00135 
00136                 int severityFlag = sevLevel->severityLevel(((EcalRecHit*)(&*recIt))->detid(), *recHitsH);
00137                 std::vector<int>::const_iterator sit;
00138                 if (isBarrel) {
00139                   sit = std::find(severitiesexclEB_.begin(), severitiesexclEB_.end(), severityFlag);
00140                   if (sit!= severitiesexclEB_.end())
00141                     continue;
00142                 } else {
00143                   sit = std::find(severitiesexclEE_.begin(), severitiesexclEE_.end(), severityFlag);
00144                   if (sit!= severitiesexclEE_.end())
00145                     continue;
00146                 }
00147 
00148                 std::vector<int>::const_iterator vit;
00149                 if (isBarrel) {
00150                   vit = std::find(flagsexclEB_.begin(), flagsexclEB_.end(), ((EcalRecHit*)(&*recIt))->recoFlag());
00151                   if (vit != flagsexclEB_.end())
00152                     continue;
00153                 } else {
00154                   vit = std::find(flagsexclEE_.begin(), flagsexclEE_.end(), ((EcalRecHit*)(&*recIt))->recoFlag());
00155                   if (vit != flagsexclEE_.end())
00156                     continue;
00157                 }
00158 
00159                 if(std::find(detIdCollection->begin(),detIdCollection->end(),recIt->detid()) == detIdCollection->end()) 
00160                     detIdCollection->push_back(recIt->detid());
00161             } //end rechits
00162 
00163         } //end candidates
00164 
00165         delete doubleConeSel_;
00166     } //end if cone selector was created
00167     
00168     iEvent.put( detIdCollection, interestingDetIdCollection_ );
00169 }