CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_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             severityLevelCut_(iConfig.getParameter<int>("severityLevelCut"))
00042             //severityRecHitThreshold_(iConfig.getParameter<double>("severityRecHitThreshold")),
00043             //spIdString_(iConfig.getParameter<std::string>("spikeIdString")),
00044             //spIdThreshold_(iConfig.getParameter<double>("spikeIdThreshold")),
00045    {
00046 
00047      const std::vector<std::string> flagnames = 
00048        iConfig.getParameter<std::vector<std::string> >("recHitFlagsToBeExcluded");
00049 
00050      v_chstatus_=     StringToEnumValue<EcalRecHit::Flags>(flagnames);
00051 
00052 //     if     ( !spIdString_.compare("kE1OverE9") )                  spId_ = EcalSeverityLevelAlgo::kE1OverE9;
00053 //     else if( !spIdString_.compare("kSwissCross") )                spId_ = EcalSeverityLevelAlgo::kSwissCross;
00054 //     else if( !spIdString_.compare("kSwissCrossBordersIncluded") ) spId_ = EcalSeverityLevelAlgo::kSwissCrossBordersIncluded;
00055 //     else                                                          spId_ = EcalSeverityLevelAlgo::kSwissCross;
00056     
00057     //register your products
00058     produces< DetIdCollection > (interestingDetIdCollection_) ;
00059 }
00060 
00061 GamIsoDetIdCollectionProducer::~GamIsoDetIdCollectionProducer() {}
00062 
00063 void GamIsoDetIdCollectionProducer::beginJob () 
00064 {}
00065 
00066 // ------------ method called to produce the data  ------------
00067     void
00068 GamIsoDetIdCollectionProducer::produce (edm::Event& iEvent, 
00069         const edm::EventSetup& iSetup)
00070 {
00071     using namespace edm;
00072     using namespace std;
00073 
00074     //Get EM Object
00075     Handle<reco::PhotonCollection> emObjectH;
00076     iEvent.getByLabel(emObjectLabel_,emObjectH);
00077 
00078     // take EcalRecHits
00079     Handle<EcalRecHitCollection> recHitsH;
00080     iEvent.getByLabel(recHitsLabel_,recHitsH);
00081     std::auto_ptr<CaloRecHitMetaCollectionV> recHits_(0); 
00082     recHits_ = std::auto_ptr<CaloRecHitMetaCollectionV>(new EcalRecHitMetaCollection(*recHitsH));
00083 
00084     edm::ESHandle<CaloGeometry> pG;
00085     iSetup.get<CaloGeometryRecord>().get(pG);    
00086     const CaloGeometry* caloGeom = pG.product();
00087 
00088     //Get the channel status from the db
00089     edm::ESHandle<EcalChannelStatus> chStatus;
00090     iSetup.get<EcalChannelStatusRcd>().get(chStatus);
00091 
00092     edm::ESHandle<EcalSeverityLevelAlgo> sevlv;
00093     iSetup.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
00094     const EcalSeverityLevelAlgo* sevLevel = sevlv.product();
00095 
00096     CaloDualConeSelector *doubleConeSel_ = 0;
00097     if(recHitsLabel_.instance() == "EcalRecHitsEB")
00098         doubleConeSel_= new CaloDualConeSelector(innerRadius_,outerRadius_, &*pG, DetId::Ecal, EcalBarrel);
00099     else if(recHitsLabel_.instance() == "EcalRecHitsEE")
00100         doubleConeSel_= new CaloDualConeSelector(innerRadius_,outerRadius_, &*pG, DetId::Ecal, EcalEndcap);
00101 
00102     //Create empty output collections
00103     std::auto_ptr< DetIdCollection > detIdCollection (new DetIdCollection() ) ;
00104 
00105     reco::PhotonCollection::const_iterator emObj;
00106     if(doubleConeSel_) { //if cone selector was created
00107         for (emObj = emObjectH->begin(); emObj != emObjectH->end();  emObj++) { //Loop over candidates
00108 
00109             if(emObj->et() < etCandCut_) continue;
00110             
00111             GlobalPoint pclu (emObj->caloPosition().x(),emObj->caloPosition().y(),emObj->caloPosition().z());
00112             std::auto_ptr<CaloRecHitMetaCollectionV> chosen = doubleConeSel_->select(pclu,*recHits_);
00113 
00114             CaloRecHitMetaCollectionV::const_iterator recIt;
00115             for (recIt = chosen->begin(); recIt!= chosen->end () ; ++recIt) { // Select RecHits 
00116 
00117                 if ( fabs(recIt->energy()) < energyCut_) continue;  //dont fill if below E noise value
00118 
00119                 double et = recIt->energy() *
00120                             caloGeom->getPosition(recIt->detid()).perp() /
00121                             caloGeom->getPosition(recIt->detid()).mag();
00122                 
00123                 if ( fabs(et) < etCut_) continue;  //dont fill if below ET noise value
00124 
00125                 //make sure we have a barrel rechit                                     
00126                 //call the severity level method                                        
00127                 //passing the EBDetId                                                   
00128                 //the rechit collection in order to calculate the swiss crss            
00129                 //and the EcalChannelRecHitRcd                                          
00130                 //only consider rechits with ET >                                       
00131                 //the SpikeId method (currently kE1OverE9 or kSwissCross)               
00132                 //cut value for above                                                   
00133                 //then if the severity level is too high, we continue to the next rechit
00134                 if(recHitsLabel_.instance() == "EcalRecHitsEB" && 
00135                    sevLevel->severityLevel(EBDetId(recIt->detid()), *recHitsH)>= severityLevelCut_) continue;                                  
00136                 //                       *chStatus,                                 
00137                   //                        severityRecHitThreshold_,                 
00138                 //    spId_,                                    
00139                   //      spIdThreshold_                            
00140                   //  ) >= severityLevelCut_) continue;              
00141 
00142                 //Check based on flags to protect from recovered channels from non-read towers
00143                 //Assumption is that v_chstatus_ is empty unless doFlagChecks() has been called
00144                 std::vector<int>::const_iterator vit = std::find( v_chstatus_.begin(), v_chstatus_.end(),  ((EcalRecHit*)(&*recIt))->recoFlag() );
00145                 if ( vit != v_chstatus_.end() ) continue; // the recHit has to be excluded from the iso sum
00146 
00147                 if(std::find(detIdCollection->begin(),detIdCollection->end(),recIt->detid()) == detIdCollection->end()) 
00148                     detIdCollection->push_back(recIt->detid());
00149             } //end rechits
00150 
00151         } //end candidates
00152 
00153         delete doubleConeSel_;
00154     } //end if cone selector was created
00155     
00156     iEvent.put( detIdCollection, interestingDetIdCollection_ );
00157 }