CMS 3D CMS Logo

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