CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/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 
00040 EgammaHLTEcalRecIsolationProducer::EgammaHLTEcalRecIsolationProducer(const edm::ParameterSet& config) : conf_(config)
00041 {
00042   // use configuration file to setup input/output collection names
00043   //inputs
00044   recoEcalCandidateProducer_    = conf_.getParameter<edm::InputTag>("recoEcalCandidateProducer");
00045   ecalBarrelRecHitProducer_       = conf_.getParameter<edm::InputTag>("ecalBarrelRecHitProducer");
00046   ecalBarrelRecHitCollection_     = conf_.getParameter<edm::InputTag>("ecalBarrelRecHitCollection");
00047   ecalEndcapRecHitProducer_       = conf_.getParameter<edm::InputTag>("ecalEndcapRecHitProducer");
00048   ecalEndcapRecHitCollection_     = conf_.getParameter<edm::InputTag>("ecalEndcapRecHitCollection");
00049 
00050   //vetos
00051   egIsoPtMinBarrel_               = conf_.getParameter<double>("etMinBarrel");
00052   egIsoEMinBarrel_                = conf_.getParameter<double>("eMinBarrel");
00053   egIsoPtMinEndcap_               = conf_.getParameter<double>("etMinEndcap");
00054   egIsoEMinEndcap_                = conf_.getParameter<double>("eMinEndcap");
00055   egIsoConeSizeInBarrel_          = conf_.getParameter<double>("intRadiusBarrel");
00056   egIsoConeSizeInEndcap_          = conf_.getParameter<double>("intRadiusEndcap");
00057   egIsoConeSizeOut_         = conf_.getParameter<double>("extRadius");
00058   egIsoJurassicWidth_       = conf_.getParameter<double>("jurassicWidth");
00059 
00060 
00061   // options
00062   useIsolEt_ = conf_.getParameter<bool>("useIsolEt");
00063   tryBoth_   = conf_.getParameter<bool>("tryBoth");
00064   subtract_  = conf_.getParameter<bool>("subtract");
00065   useNumCrystals_ = conf_.getParameter<bool>("useNumCrystals");
00066 
00067   //register your products
00068   produces < reco::RecoEcalCandidateIsolationMap >();
00069   
00070 }
00071 
00072 EgammaHLTEcalRecIsolationProducer::~EgammaHLTEcalRecIsolationProducer(){}
00073 
00074 // ------------ method called to produce the data  ------------
00075 
00076 void EgammaHLTEcalRecIsolationProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup){
00077 
00078   // Get the RecoEcalCandidate Collection
00079   edm::Handle<reco::RecoEcalCandidateCollection> recoecalcandHandle;
00080   iEvent.getByLabel(recoEcalCandidateProducer_,recoecalcandHandle);
00081 
00082   // Next get Ecal hits barrel
00083   edm::Handle<EcalRecHitCollection> ecalBarrelRecHitHandle; //EcalRecHitCollection is a typedef to
00084   iEvent.getByLabel(ecalBarrelRecHitProducer_.label(),ecalBarrelRecHitCollection_.label(), ecalBarrelRecHitHandle);
00085 
00086   // Next get Ecal hits endcap
00087   edm::Handle<EcalRecHitCollection> ecalEndcapRecHitHandle;
00088   iEvent.getByLabel(ecalEndcapRecHitProducer_.label(), ecalEndcapRecHitCollection_.label(),ecalEndcapRecHitHandle);
00089 
00090   //create the meta hit collections inorder that we can pass them into the isolation objects
00091 
00092   EcalRecHitMetaCollection ecalBarrelHits(*ecalBarrelRecHitHandle);
00093   EcalRecHitMetaCollection ecalEndcapHits(*ecalEndcapRecHitHandle);
00094 
00095   //Get Calo Geometry
00096   edm::ESHandle<CaloGeometry> pG;
00097   iSetup.get<CaloGeometryRecord>().get(pG);
00098   const CaloGeometry* caloGeom = pG.product();
00099 
00100   //prepare product
00101   reco::RecoEcalCandidateIsolationMap isoMap;
00102 
00103   //create algorithm objects
00104   EgammaRecHitIsolation ecalBarrelIsol(egIsoConeSizeOut_,egIsoConeSizeInBarrel_,egIsoJurassicWidth_,egIsoPtMinBarrel_,egIsoEMinBarrel_,edm::ESHandle<CaloGeometry>(caloGeom),&ecalBarrelHits,DetId::Ecal);
00105   ecalBarrelIsol.setUseNumCrystals(useNumCrystals_);
00106   EgammaRecHitIsolation ecalEndcapIsol(egIsoConeSizeOut_,egIsoConeSizeInEndcap_,egIsoJurassicWidth_,egIsoPtMinEndcap_,egIsoEMinEndcap_,edm::ESHandle<CaloGeometry>(caloGeom),&ecalEndcapHits,DetId::Ecal);
00107   ecalEndcapIsol.setUseNumCrystals(useNumCrystals_);
00108 
00109   for (reco::RecoEcalCandidateCollection::const_iterator iRecoEcalCand= recoecalcandHandle->begin(); iRecoEcalCand!=recoecalcandHandle->end(); iRecoEcalCand++) {
00110     
00111     //create reference for storage in isolation map
00112     reco::RecoEcalCandidateRef recoecalcandref(reco::RecoEcalCandidateRef(recoecalcandHandle,iRecoEcalCand -recoecalcandHandle ->begin()));
00113     
00114     //ecal isolation is centered on supecluster
00115     reco::SuperClusterRef superClus = iRecoEcalCand->get<reco::SuperClusterRef>();
00116 
00117     //i need to know if its in the barrel/endcap so I get the supercluster handle to find out the detector eta
00118     //this might not be the best way, are we guaranteed that eta<1.5 is barrel
00119     //this can be safely replaced by another method which determines where the emobject is
00120     //then we either get the isolation Et or isolation Energy depending on user selection
00121     float isol =0.;
00122 
00123     if(tryBoth_){ //barrel + endcap
00124       if(useIsolEt_) isol =  ecalBarrelIsol.getEtSum(&(*iRecoEcalCand)) + ecalEndcapIsol.getEtSum(&(*iRecoEcalCand));
00125       else           isol =  ecalBarrelIsol.getEnergySum(&(*iRecoEcalCand)) + ecalEndcapIsol.getEnergySum(&(*iRecoEcalCand));
00126     }
00127     else if( fabs(superClus->eta())<1.479) { //barrel
00128       if(useIsolEt_) isol =  ecalBarrelIsol.getEtSum(&(*iRecoEcalCand));
00129       else           isol =  ecalBarrelIsol.getEnergySum(&(*iRecoEcalCand));
00130     }
00131     else{ //endcap
00132       if(useIsolEt_) isol =  ecalEndcapIsol.getEtSum(&(*iRecoEcalCand));
00133       else           isol =  ecalEndcapIsol.getEnergySum(&(*iRecoEcalCand));
00134     }
00135 
00136     //we subtract off the electron energy here as well
00137     double subtractVal=0;
00138 
00139     if(useIsolEt_) subtractVal = superClus.get()->rawEnergy()*sin(2*atan(exp(-superClus.get()->eta())));
00140     else           subtractVal = superClus.get()->rawEnergy();
00141 
00142     if(subtract_) isol-= subtractVal;
00143 
00144 
00145 
00146     isoMap.insert(recoecalcandref, isol);
00147 
00148   }
00149 
00150   std::auto_ptr<reco::RecoEcalCandidateIsolationMap> isolMap(new reco::RecoEcalCandidateIsolationMap(isoMap));
00151   iEvent.put(isolMap);
00152 
00153 }
00154 
00155