CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/RecoEgamma/EgammaIsolationAlgos/plugins/EgammaEcalRecHitIsolationProducer.cc

Go to the documentation of this file.
00001 //*****************************************************************************
00002 // File:      EgammaEcalRecHitIsolationProducer.cc
00003 // ----------------------------------------------------------------------------
00004 // OrigAuth:  Matthias Mozer
00005 // Institute: IIHE-VUB
00006 //=============================================================================
00007 //*****************************************************************************
00008 
00009 
00010 #include "RecoEgamma/EgammaIsolationAlgos/plugins/EgammaEcalRecHitIsolationProducer.h"
00011 
00012 // Framework
00013 #include "FWCore/Framework/interface/EventSetup.h"
00014 #include "DataFormats/Common/interface/Handle.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 
00017 #include "DataFormats/Candidate/interface/Candidate.h"
00018 #include "DataFormats/Candidate/interface/CandAssociation.h"
00019 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
00020 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00021 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
00022 
00023 #include "DataFormats/DetId/interface/DetId.h"
00024 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00025 
00026 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00027 
00028 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h"
00029 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h"
00030 
00031 EgammaEcalRecHitIsolationProducer::EgammaEcalRecHitIsolationProducer(const edm::ParameterSet& config) : conf_(config)
00032 {
00033  // use configuration file to setup input/output collection names
00034  //inputs 
00035   emObjectProducer_               = conf_.getParameter<edm::InputTag>("emObjectProducer");
00036   ecalBarrelRecHitProducer_       = conf_.getParameter<edm::InputTag>("ecalBarrelRecHitProducer");
00037   ecalBarrelRecHitCollection_     = conf_.getParameter<edm::InputTag>("ecalBarrelRecHitCollection");
00038   ecalEndcapRecHitProducer_       = conf_.getParameter<edm::InputTag>("ecalEndcapRecHitProducer");
00039   ecalEndcapRecHitCollection_     = conf_.getParameter<edm::InputTag>("ecalEndcapRecHitCollection");
00040 
00041   //vetos
00042   egIsoPtMinBarrel_               = conf_.getParameter<double>("etMinBarrel");
00043   egIsoEMinBarrel_                = conf_.getParameter<double>("eMinBarrel");
00044   egIsoPtMinEndcap_               = conf_.getParameter<double>("etMinEndcap");
00045   egIsoEMinEndcap_                = conf_.getParameter<double>("eMinEndcap");
00046   egIsoConeSizeInBarrel_          = conf_.getParameter<double>("intRadiusBarrel");
00047   egIsoConeSizeInEndcap_          = conf_.getParameter<double>("intRadiusEndcap");
00048   egIsoConeSizeOut_               = conf_.getParameter<double>("extRadius");
00049   egIsoJurassicWidth_             = conf_.getParameter<double>("jurassicWidth");
00050 
00051 
00052 
00053   // options
00054   useIsolEt_      = conf_.getParameter<bool>("useIsolEt");
00055   tryBoth_        = conf_.getParameter<bool>("tryBoth");
00056   subtract_       = conf_.getParameter<bool>("subtract");
00057   useNumCrystals_ = conf_.getParameter<bool>("useNumCrystals");
00058   vetoClustered_  = conf_.getParameter<bool>("vetoClustered");
00059 
00060   //register your products
00061   produces < edm::ValueMap<double> >();
00062 }
00063 
00064 
00065 EgammaEcalRecHitIsolationProducer::~EgammaEcalRecHitIsolationProducer(){}
00066 
00067 
00068 //
00069 // member functions
00070 //
00071 
00072 // ------------ method called to produce the data  ------------
00073 void
00074 EgammaEcalRecHitIsolationProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00075 {
00076 
00077 
00078   // Get the  filtered objects
00079   edm::Handle< edm::View<reco::Candidate> > emObjectHandle;
00080   iEvent.getByLabel(emObjectProducer_,emObjectHandle);
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   edm::ESHandle<EcalSeverityLevelAlgo> sevlv;
00091   iSetup.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
00092   const EcalSeverityLevelAlgo* sevLevel = sevlv.product();
00093   //create the meta hit collections inorder that we can pass them into the isolation objects
00094 
00095   EcalRecHitMetaCollection ecalBarrelHits(*ecalBarrelRecHitHandle);
00096   EcalRecHitMetaCollection ecalEndcapHits(*ecalEndcapRecHitHandle);
00097 
00098   //Get Calo Geometry
00099   edm::ESHandle<CaloGeometry> pG;
00100   iSetup.get<CaloGeometryRecord>().get(pG);
00101   const CaloGeometry* caloGeom = pG.product();
00102 
00103   //reco::CandViewDoubleAssociations* isoMap = new reco::CandViewDoubleAssociations( reco::CandidateBaseRefProd( emObjectHandle ) );
00104   std::auto_ptr<edm::ValueMap<double> > isoMap(new edm::ValueMap<double>());
00105   edm::ValueMap<double>::Filler filler(*isoMap);
00106   std::vector<double> retV(emObjectHandle->size(),0);
00107 
00108   EgammaRecHitIsolation ecalBarrelIsol(egIsoConeSizeOut_,egIsoConeSizeInBarrel_,egIsoJurassicWidth_,egIsoPtMinBarrel_,egIsoEMinBarrel_,caloGeom,&ecalBarrelHits,sevLevel,DetId::Ecal);
00109   ecalBarrelIsol.setUseNumCrystals(useNumCrystals_);
00110   ecalBarrelIsol.setVetoClustered(vetoClustered_);
00111 
00112   EgammaRecHitIsolation ecalEndcapIsol(egIsoConeSizeOut_,egIsoConeSizeInEndcap_,egIsoJurassicWidth_,egIsoPtMinEndcap_,egIsoEMinEndcap_,caloGeom,&ecalEndcapHits,sevLevel,DetId::Ecal);
00113   ecalEndcapIsol.setUseNumCrystals(useNumCrystals_);
00114   ecalEndcapIsol.setVetoClustered(vetoClustered_);
00115   
00116   
00117   for( size_t i = 0 ; i < emObjectHandle->size(); ++i) {
00118     
00119     //i need to know if its in the barrel/endcap so I get the supercluster handle to find out the detector eta
00120     //this might not be the best way, are we guaranteed that eta<1.5 is barrel
00121     //this can be safely replaced by another method which determines where the emobject is
00122     //then we either get the isolation Et or isolation Energy depending on user selection 
00123     double isoValue =0.;
00124     
00125     reco::SuperClusterRef superClus = emObjectHandle->at(i).get<reco::SuperClusterRef>();
00126 
00127     if(tryBoth_){ //barrel + endcap
00128       if(useIsolEt_) isoValue =  ecalBarrelIsol.getEtSum(&(emObjectHandle->at(i))) + ecalEndcapIsol.getEtSum(&(emObjectHandle->at(i)));
00129       else           isoValue =  ecalBarrelIsol.getEnergySum(&(emObjectHandle->at(i))) + ecalEndcapIsol.getEnergySum(&(emObjectHandle->at(i)));
00130     }
00131     else if( fabs(superClus->eta())<1.479) { //barrel
00132       if(useIsolEt_) isoValue =  ecalBarrelIsol.getEtSum(&(emObjectHandle->at(i)));
00133       else           isoValue =  ecalBarrelIsol.getEnergySum(&(emObjectHandle->at(i)));
00134     }
00135     else{ //endcap
00136       if(useIsolEt_) isoValue =  ecalEndcapIsol.getEtSum(&(emObjectHandle->at(i)));
00137       else           isoValue =  ecalEndcapIsol.getEnergySum(&(emObjectHandle->at(i)));
00138     }
00139 
00140     //we subtract off the electron energy here as well
00141     double subtractVal=0;
00142 
00143     if(useIsolEt_) subtractVal = superClus.get()->rawEnergy()*sin(2*atan(exp(-superClus.get()->eta())));
00144     else           subtractVal = superClus.get()->rawEnergy();
00145     
00146     if(subtract_) isoValue-= subtractVal;
00147     
00148     retV[i]=isoValue;
00149     //all done, isolation is now in the map
00150 
00151   }//end of loop over em objects
00152   
00153   filler.insert(emObjectHandle,retV.begin(),retV.end());
00154   filler.fill();
00155 
00156   //std::auto_ptr<reco::CandViewDoubleAssociations> isolMap(isoMap);
00157   iEvent.put(isoMap);
00158 
00159 }
00160 
00161 //define this as a plug-in
00162 //DEFINE_FWK_MODULE(EgammaRecHitIsolation,Producer);