CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoEgamma/EgammaHLTProducers/src/EgammaHLTEcalRecIsolationProducer.cc

Go to the documentation of this file.
00001 
00002 //*****************************************************************************
00003 // File:      EgammaHLTEcalRecIsolationProducer.cc
00004 // ----------------------------------------------------------------------------
00005 // OrigAuth:  Matthias Mozer , adapted from EgammaHcalIsolationProducer by S. Harper
00006 // Institute: IIHE-VUB
00007 //=============================================================================
00008 //*****************************************************************************
00009 
00010 
00011 #include "RecoEgamma/EgammaHLTProducers/interface/EgammaHLTEcalRecIsolationProducer.h"
00012 
00013 
00014 // Framework
00015 #include "FWCore/Framework/interface/Event.h"
00016 #include "FWCore/Framework/interface/EventSetup.h"
00017 #include "DataFormats/Common/interface/Handle.h"
00018 #include "FWCore/Framework/interface/ESHandle.h"
00019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00020 #include "FWCore/Utilities/interface/Exception.h"
00021 
00022 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidate.h"
00023 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidateIsolation.h"
00024 
00025 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00026 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
00027 
00028 #include "DataFormats/DetId/interface/DetId.h"
00029 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00030 
00031 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00032 
00033 #include "DataFormats/Common/interface/RefToBase.h"
00034 #include "DataFormats/Common/interface/Ref.h"
00035 #include "DataFormats/Common/interface/RefProd.h"
00036 
00037 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
00038 
00039 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h"
00040 
00041 EgammaHLTEcalRecIsolationProducer::EgammaHLTEcalRecIsolationProducer(const edm::ParameterSet& config) : conf_(config)
00042 {
00043   // use configuration file to setup input/output collection names
00044   //inputs
00045   recoEcalCandidateProducer_    = conf_.getParameter<edm::InputTag>("recoEcalCandidateProducer");
00046   ecalBarrelRecHitProducer_       = conf_.getParameter<edm::InputTag>("ecalBarrelRecHitProducer");
00047   ecalBarrelRecHitCollection_     = conf_.getParameter<edm::InputTag>("ecalBarrelRecHitCollection");
00048   ecalEndcapRecHitProducer_       = conf_.getParameter<edm::InputTag>("ecalEndcapRecHitProducer");
00049   ecalEndcapRecHitCollection_     = conf_.getParameter<edm::InputTag>("ecalEndcapRecHitCollection");
00050 
00051   //vetos
00052   egIsoPtMinBarrel_               = conf_.getParameter<double>("etMinBarrel");
00053   egIsoEMinBarrel_                = conf_.getParameter<double>("eMinBarrel");
00054   egIsoPtMinEndcap_               = conf_.getParameter<double>("etMinEndcap");
00055   egIsoEMinEndcap_                = conf_.getParameter<double>("eMinEndcap");
00056   egIsoConeSizeInBarrel_          = conf_.getParameter<double>("intRadiusBarrel");
00057   egIsoConeSizeInEndcap_          = conf_.getParameter<double>("intRadiusEndcap");
00058   egIsoConeSizeOut_         = conf_.getParameter<double>("extRadius");
00059   egIsoJurassicWidth_       = conf_.getParameter<double>("jurassicWidth");
00060 
00061 
00062   // options
00063   useIsolEt_ = conf_.getParameter<bool>("useIsolEt");
00064   tryBoth_   = conf_.getParameter<bool>("tryBoth");
00065   subtract_  = conf_.getParameter<bool>("subtract");
00066   useNumCrystals_ = conf_.getParameter<bool>("useNumCrystals");
00067 
00068   //register your products
00069   produces < reco::RecoEcalCandidateIsolationMap >();
00070   
00071 }
00072 
00073 EgammaHLTEcalRecIsolationProducer::~EgammaHLTEcalRecIsolationProducer(){}
00074 
00075 // ------------ method called to produce the data  ------------
00076 
00077 void EgammaHLTEcalRecIsolationProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup){
00078 
00079   // Get the RecoEcalCandidate Collection
00080   edm::Handle<reco::RecoEcalCandidateCollection> recoecalcandHandle;
00081   iEvent.getByLabel(recoEcalCandidateProducer_,recoecalcandHandle);
00082 
00083   // Next get Ecal hits barrel
00084   edm::Handle<EcalRecHitCollection> ecalBarrelRecHitHandle; //EcalRecHitCollection is a typedef to
00085   iEvent.getByLabel(ecalBarrelRecHitProducer_.label(),ecalBarrelRecHitCollection_.label(), ecalBarrelRecHitHandle);
00086 
00087   // Next get Ecal hits endcap
00088   edm::Handle<EcalRecHitCollection> ecalEndcapRecHitHandle;
00089   iEvent.getByLabel(ecalEndcapRecHitProducer_.label(), ecalEndcapRecHitCollection_.label(),ecalEndcapRecHitHandle);
00090 
00091   //create the meta hit collections inorder that we can pass them into the isolation objects
00092 
00093   EcalRecHitMetaCollection ecalBarrelHits(*ecalBarrelRecHitHandle);
00094   EcalRecHitMetaCollection ecalEndcapHits(*ecalEndcapRecHitHandle);
00095 
00096   //Get Calo Geometry
00097   edm::ESHandle<CaloGeometry> pG;
00098   iSetup.get<CaloGeometryRecord>().get(pG);
00099   const CaloGeometry* caloGeom = pG.product();
00100 
00101   edm::ESHandle<EcalSeverityLevelAlgo> sevlv;
00102   iSetup.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
00103   const EcalSeverityLevelAlgo* sevLevel = sevlv.product();
00104 
00105   //prepare product
00106   reco::RecoEcalCandidateIsolationMap isoMap;
00107 
00108   //create algorithm objects
00109   EgammaRecHitIsolation ecalBarrelIsol(egIsoConeSizeOut_,egIsoConeSizeInBarrel_,egIsoJurassicWidth_,egIsoPtMinBarrel_,egIsoEMinBarrel_,edm::ESHandle<CaloGeometry>(caloGeom),&ecalBarrelHits,sevLevel,DetId::Ecal);
00110   ecalBarrelIsol.setUseNumCrystals(useNumCrystals_);
00111   EgammaRecHitIsolation ecalEndcapIsol(egIsoConeSizeOut_,egIsoConeSizeInEndcap_,egIsoJurassicWidth_,egIsoPtMinEndcap_,egIsoEMinEndcap_,edm::ESHandle<CaloGeometry>(caloGeom),&ecalEndcapHits,sevLevel,DetId::Ecal);
00112   ecalEndcapIsol.setUseNumCrystals(useNumCrystals_);
00113 
00114   for (reco::RecoEcalCandidateCollection::const_iterator iRecoEcalCand= recoecalcandHandle->begin(); iRecoEcalCand!=recoecalcandHandle->end(); iRecoEcalCand++) {
00115     
00116     //create reference for storage in isolation map
00117     reco::RecoEcalCandidateRef recoecalcandref(reco::RecoEcalCandidateRef(recoecalcandHandle,iRecoEcalCand -recoecalcandHandle ->begin()));
00118     
00119     //ecal isolation is centered on supecluster
00120     reco::SuperClusterRef superClus = iRecoEcalCand->get<reco::SuperClusterRef>();
00121 
00122     //i need to know if its in the barrel/endcap so I get the supercluster handle to find out the detector eta
00123     //this might not be the best way, are we guaranteed that eta<1.5 is barrel
00124     //this can be safely replaced by another method which determines where the emobject is
00125     //then we either get the isolation Et or isolation Energy depending on user selection
00126     float isol =0.;
00127 
00128     if(tryBoth_){ //barrel + endcap
00129       if(useIsolEt_) isol =  ecalBarrelIsol.getEtSum(&(*iRecoEcalCand)) + ecalEndcapIsol.getEtSum(&(*iRecoEcalCand));
00130       else           isol =  ecalBarrelIsol.getEnergySum(&(*iRecoEcalCand)) + ecalEndcapIsol.getEnergySum(&(*iRecoEcalCand));
00131     }
00132     else if( fabs(superClus->eta())<1.479) { //barrel
00133       if(useIsolEt_) isol =  ecalBarrelIsol.getEtSum(&(*iRecoEcalCand));
00134       else           isol =  ecalBarrelIsol.getEnergySum(&(*iRecoEcalCand));
00135     }
00136     else{ //endcap
00137       if(useIsolEt_) isol =  ecalEndcapIsol.getEtSum(&(*iRecoEcalCand));
00138       else           isol =  ecalEndcapIsol.getEnergySum(&(*iRecoEcalCand));
00139     }
00140 
00141     //we subtract off the electron energy here as well
00142     double subtractVal=0;
00143 
00144     if(useIsolEt_) subtractVal = superClus.get()->rawEnergy()*sin(2*atan(exp(-superClus.get()->eta())));
00145     else           subtractVal = superClus.get()->rawEnergy();
00146 
00147     if(subtract_) isol-= subtractVal;
00148 
00149 
00150 
00151     isoMap.insert(recoecalcandref, isol);
00152 
00153   }
00154 
00155   std::auto_ptr<reco::RecoEcalCandidateIsolationMap> isolMap(new reco::RecoEcalCandidateIsolationMap(isoMap));
00156   iEvent.put(isolMap);
00157 
00158 }
00159 
00160