CMS 3D CMS Logo

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