CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/RecoEgamma/EgammaElectronProducers/plugins/ElectronSeedProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    ElectronProducers
00004 // Class:      ElectronSeedProducer
00005 //
00013 //
00014 // Original Author:  Ursula Berthon, Claude Charlot
00015 //         Created:  Mon Mar 27 13:22:06 CEST 2006
00016 // $Id: ElectronSeedProducer.cc,v 1.23 2011/01/14 21:25:58 chamont Exp $
00017 //
00018 //
00019 
00020 #include "ElectronSeedProducer.h"
00021 
00022 #include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaHcalIsolation.h"
00023 //#include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
00024 
00025 #include "RecoEgamma/EgammaElectronAlgos/interface/ElectronSeedGenerator.h"
00026 #include "RecoEgamma/EgammaElectronAlgos/interface/ElectronHcalHelper.h"
00027 #include "RecoEgamma/EgammaElectronAlgos/interface/SeedFilter.h"
00028 #include "RecoEgamma/EgammaElectronAlgos/interface/ElectronUtilities.h"
00029 
00030 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00031 #include "Geometry/Records/interface/CaloTopologyRecord.h"
00032 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00033 #include "RecoCaloTools/Selectors/interface/CaloConeSelector.h"
00034 
00035 #include "DataFormats/EgammaReco/interface/ElectronSeed.h"
00036 #include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h"
00037 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00038 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00039 
00040 #include "FWCore/Framework/interface/Frameworkfwd.h"
00041 #include "FWCore/Framework/interface/EDProducer.h"
00042 #include "FWCore/Framework/interface/Event.h"
00043 #include "FWCore/Framework/interface/MakerMacros.h"
00044 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00045 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00046 
00047 #include <string>
00048 
00049 using namespace reco ;
00050 
00051 ElectronSeedProducer::ElectronSeedProducer( const edm::ParameterSet& iConfig )
00052  : beamSpotTag_("offlineBeamSpot"),
00053    //conf_(iConfig),
00054    seedFilter_(0), applyHOverECut_(true), hcalHelper_(0),
00055    caloGeom_(0), caloGeomCacheId_(0), caloTopo_(0), caloTopoCacheId_(0)
00056  {
00057   conf_ = iConfig.getParameter<edm::ParameterSet>("SeedConfiguration") ;
00058 
00059   initialSeeds_ = conf_.getParameter<edm::InputTag>("initialSeeds") ;
00060   SCEtCut_ = conf_.getParameter<double>("SCEtCut") ;
00061   fromTrackerSeeds_ = conf_.getParameter<bool>("fromTrackerSeeds") ;
00062   prefilteredSeeds_ = conf_.getParameter<bool>("preFilteredSeeds") ;
00063 
00064   // new beamSpot tag
00065   if (conf_.exists("beamSpot"))
00066    { beamSpotTag_ = conf_.getParameter<edm::InputTag>("beamSpot") ; }
00067 
00068   // for H/E
00069 //  if (conf_.exists("applyHOverECut"))
00070 //   { applyHOverECut_ = conf_.getParameter<bool>("applyHOverECut") ; }
00071   applyHOverECut_ = conf_.getParameter<bool>("applyHOverECut") ;
00072   if (applyHOverECut_)
00073    {
00074     ElectronHcalHelper::Configuration hcalCfg ;
00075     hcalCfg.hOverEConeSize = conf_.getParameter<double>("hOverEConeSize") ;
00076     if (hcalCfg.hOverEConeSize>0)
00077      {
00078       hcalCfg.useTowers = true ;
00079       hcalCfg.hcalTowers = conf_.getParameter<edm::InputTag>("hcalTowers") ;
00080       hcalCfg.hOverEPtMin = conf_.getParameter<double>("hOverEPtMin") ;
00081      }
00082     hcalHelper_ = new ElectronHcalHelper(hcalCfg) ;
00083     maxHOverEBarrel_=conf_.getParameter<double>("maxHOverEBarrel") ;
00084     maxHOverEEndcaps_=conf_.getParameter<double>("maxHOverEEndcaps") ;
00085     maxHBarrel_=conf_.getParameter<double>("maxHBarrel") ;
00086     maxHEndcaps_=conf_.getParameter<double>("maxHEndcaps") ;
00087 //    hOverEConeSize_=conf_.getParameter<double>("hOverEConeSize") ;
00088 //    hOverEHBMinE_=conf_.getParameter<double>("hOverEHBMinE") ;
00089 //    hOverEHFMinE_=conf_.getParameter<double>("hOverEHFMinE") ;
00090    }
00091 
00092   matcher_ = new ElectronSeedGenerator(conf_) ;
00093 
00094   //  get collections from config'
00095   superClusters_[0]=iConfig.getParameter<edm::InputTag>("barrelSuperClusters") ;
00096   superClusters_[1]=iConfig.getParameter<edm::InputTag>("endcapSuperClusters") ;
00097 
00098   //register your products
00099   produces<ElectronSeedCollection>() ;
00100 }
00101 
00102 
00103 void ElectronSeedProducer::beginRun(edm::Run&, edm::EventSetup const&)
00104  {
00105   // FIXME: because of a bug presumably in tracker seeding,
00106   // perhaps in CombinedHitPairGenerator, badly caching some EventSetup product,
00107   // we must redo the SeedFilter for each run.
00108   if (prefilteredSeeds_) seedFilter_ = new SeedFilter(conf_) ;
00109  }
00110 
00111 void ElectronSeedProducer::endRun(edm::Run&, edm::EventSetup const&)
00112  {
00113   delete seedFilter_ ;
00114   seedFilter_ = 0 ;
00115  }
00116 
00117 ElectronSeedProducer::~ElectronSeedProducer()
00118  {
00119   delete hcalHelper_ ;
00120   delete matcher_ ;
00121  }
00122 
00123 void ElectronSeedProducer::produce(edm::Event& e, const edm::EventSetup& iSetup)
00124  {
00125   LogDebug("ElectronSeedProducer") <<"[ElectronSeedProducer::produce] entering " ;
00126 
00127   edm::Handle<reco::BeamSpot> theBeamSpot ;
00128   e.getByLabel(beamSpotTag_,theBeamSpot) ;
00129 
00130   if (hcalHelper_)
00131    {
00132     hcalHelper_->checkSetup(iSetup) ;
00133     hcalHelper_->readEvent(e) ;
00134    }
00135 
00136   // get calo geometry
00137   if (caloGeomCacheId_!=iSetup.get<CaloGeometryRecord>().cacheIdentifier()) {
00138     iSetup.get<CaloGeometryRecord>().get(caloGeom_);
00139     caloGeomCacheId_=iSetup.get<CaloGeometryRecord>().cacheIdentifier();
00140   }
00141   if (caloTopoCacheId_!=iSetup.get<CaloTopologyRecord>().cacheIdentifier()){
00142     caloTopoCacheId_=iSetup.get<CaloTopologyRecord>().cacheIdentifier();
00143     iSetup.get<CaloTopologyRecord>().get(caloTopo_);
00144   }
00145 
00146   matcher_->setupES(iSetup);
00147 
00148   // get initial TrajectorySeeds if necessary
00149   if (fromTrackerSeeds_)
00150    {
00151     if (!prefilteredSeeds_)
00152      {
00153       edm::Handle<TrajectorySeedCollection> hSeeds;
00154       e.getByLabel(initialSeeds_, hSeeds);
00155       theInitialSeedColl = const_cast<TrajectorySeedCollection *> (hSeeds.product());
00156      }
00157     else
00158      { theInitialSeedColl = new TrajectorySeedCollection ; }
00159    }
00160   else
00161    { theInitialSeedColl = 0 ; } // not needed in this case
00162 
00163   ElectronSeedCollection * seeds = new ElectronSeedCollection ;
00164 
00165   // loop over barrel + endcap
00166   for (unsigned int i=0; i<2; i++)
00167    {
00168     edm::Handle<SuperClusterCollection> clusters ;
00169     if (e.getByLabel(superClusters_[i],clusters))
00170      {
00171       SuperClusterRefVector clusterRefs ;
00172       std::vector<float> hoe1s, hoe2s ;
00173       filterClusters(*theBeamSpot,clusters,/*mhbhe_,*/clusterRefs,hoe1s,hoe2s) ;
00174       if ((fromTrackerSeeds_) && (prefilteredSeeds_))
00175        { filterSeeds(e,iSetup,clusterRefs) ; }
00176       matcher_->run(e,iSetup,clusterRefs,hoe1s,hoe2s,theInitialSeedColl,*seeds) ;
00177      }
00178    }
00179 
00180   // store the accumulated result
00181   std::auto_ptr<ElectronSeedCollection> pSeeds(seeds) ;
00182   ElectronSeedCollection::iterator is ;
00183   for ( is=pSeeds->begin() ; is!=pSeeds->end() ; is++ )
00184    {
00185     edm::RefToBase<CaloCluster> caloCluster = is->caloCluster() ;
00186     SuperClusterRef superCluster = caloCluster.castTo<SuperClusterRef>() ;
00187     LogDebug("ElectronSeedProducer")<< "new seed with "
00188       << (*is).nHits() << " hits"
00189       << ", charge " << (*is).getCharge()
00190       << " and cluster energy " << superCluster->energy()
00191       << " PID "<<superCluster.id() ;
00192    }
00193   e.put(pSeeds) ;
00194   if (fromTrackerSeeds_ && prefilteredSeeds_) delete theInitialSeedColl;
00195  }
00196 
00197 
00198 //===============================
00199 // Filter the superclusters
00200 // - with EtCut
00201 // - with HoE using calo cone
00202 //===============================
00203 
00204 void ElectronSeedProducer::filterClusters
00205  ( const reco::BeamSpot & bs,
00206    const edm::Handle<reco::SuperClusterCollection> & superClusters,
00207    /*HBHERecHitMetaCollection * mhbhe,*/ SuperClusterRefVector & sclRefs,
00208    std::vector<float> & hoe1s, std::vector<float> & hoe2s )
00209  {
00210   for (unsigned int i=0;i<superClusters->size();++i)
00211    {
00212     const SuperCluster & scl = (*superClusters)[i] ;
00213     double sclEta = EleRelPoint(scl.position(),bs.position()).eta() ;
00214     if (scl.energy()/cosh(sclEta)>SCEtCut_)
00215      {
00216 //      if ((applyHOverECut_==true)&&((hcalHelper_->hcalESum(scl)/scl.energy()) > maxHOverE_))
00217 //       { continue ; }
00218 //      sclRefs.push_back(edm::Ref<reco::SuperClusterCollection>(superClusters,i)) ;
00219        double had1, had2, had, scle ;
00220        bool HoeVeto = false ;
00221        if (applyHOverECut_==true)
00222         {
00223          had1 = hcalHelper_->hcalESumDepth1(scl);
00224          had2 = hcalHelper_->hcalESumDepth2(scl);
00225          had = had1+had2 ;
00226          scle = scl.energy() ;
00227          int detector = scl.seed()->hitsAndFractions()[0].first.subdetId() ;
00228          if (detector==EcalBarrel && (had<maxHBarrel_ || had/scle<maxHOverEBarrel_)) HoeVeto=true;
00229          else if (detector==EcalEndcap && (had<maxHEndcaps_ || had/scle<maxHOverEEndcaps_)) HoeVeto=true;
00230          if (HoeVeto)
00231           {
00232            sclRefs.push_back(edm::Ref<reco::SuperClusterCollection>(superClusters,i)) ;
00233            hoe1s.push_back(had1/scle) ;
00234            hoe2s.push_back(had2/scle) ;
00235           }
00236         }
00237        else
00238         {
00239          sclRefs.push_back(edm::Ref<reco::SuperClusterCollection>(superClusters,i)) ;
00240          hoe1s.push_back(std::numeric_limits<float>::infinity()) ;
00241          hoe2s.push_back(std::numeric_limits<float>::infinity()) ;
00242         }
00243      }
00244    }
00245   LogDebug("ElectronSeedProducer")<<"Filtered out "<<sclRefs.size()<<" superclusters from "<<superClusters->size() ;
00246  }
00247 
00248 void ElectronSeedProducer::filterSeeds
00249  ( edm::Event & event, const edm::EventSetup & setup,
00250    reco::SuperClusterRefVector & sclRefs )
00251  {
00252   for ( unsigned int i=0 ; i<sclRefs.size() ; ++i )
00253    {
00254     seedFilter_->seeds(event,setup,sclRefs[i],theInitialSeedColl) ;
00255     LogDebug("ElectronSeedProducer")<<"Number of Seeds: "<<theInitialSeedColl->size() ;
00256    }
00257  }