CMS 3D CMS Logo

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