CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/FastSimulation/EgammaElectronAlgos/src/FastElectronSeedProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    ElectronProducers
00004 // Class:      FastElectronSeedProducer
00005 //
00013 //
00014 // Original Author:  Patrick Janot
00015 //
00016 //
00017 
00018 // user include files
00019 #include "FastElectronSeedProducer.h"
00020 #include "FastElectronSeedGenerator.h"
00021 
00022 #include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaHcalIsolation.h"
00023 #include "RecoEgamma/EgammaTools/interface/HoECalculator.h"
00024 #include "RecoCaloTools/Selectors/interface/CaloConeSelector.h"
00025 
00026 #include "FWCore/Framework/interface/Event.h"
00027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00029 
00030 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00031 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00032 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00033 
00034 #include "DataFormats/TrackerRecHit2D/interface/SiTrackerGSMatchedRecHit2DCollection.h"
00035 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
00036 #include "DataFormats/EgammaReco/interface/ElectronSeed.h"
00037 #include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h"
00038 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00039 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
00040 
00041 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
00042 
00043 #include <iostream>
00044 
00045 FastElectronSeedProducer::FastElectronSeedProducer(const edm::ParameterSet& iConfig)
00046  : matcher_(0), caloGeomCacheId_(0), hcalIso_(0), /*doubleConeSel_(0),*/ mhbhe_(0)
00047  {
00048   edm::ParameterSet pset = iConfig.getParameter<edm::ParameterSet>("SeedConfiguration");
00049   SCEtCut_=pset.getParameter<double>("SCEtCut");
00050   maxHOverE_=pset.getParameter<double>("maxHOverE");
00051   hOverEConeSize_=pset.getParameter<double>("hOverEConeSize");
00052   hOverEHBMinE_=pset.getParameter<double>("hOverEHBMinE");
00053   hOverEHFMinE_=pset.getParameter<double>("hOverEHFMinE");
00054   fromTrackerSeeds_=pset.getParameter<bool>("fromTrackerSeeds");
00055   initialSeeds_=pset.getParameter<edm::InputTag>("initialSeeds");
00056 
00057   matcher_ = new FastElectronSeedGenerator(pset,
00058                                               iConfig.getParameter<double>("pTMin"),
00059                                               iConfig.getParameter<edm::InputTag>("beamSpot"));
00060 
00061  //  get labels from config'
00062   clusters_[0]=iConfig.getParameter<edm::InputTag>("barrelSuperClusters");
00063   clusters_[1]=iConfig.getParameter<edm::InputTag>("endcapSuperClusters");
00064   simTracks_=iConfig.getParameter<edm::InputTag>("simTracks");
00065   trackerHits_=iConfig.getParameter<edm::InputTag>("trackerHits");
00066   hcalRecHits_= pset.getParameter<edm::InputTag>("hcalRecHits");
00067 
00068   //register your products
00069   produces<reco::ElectronSeedCollection>();
00070 
00071 }
00072 
00073 
00074 FastElectronSeedProducer::~FastElectronSeedProducer()
00075  {
00076   // do anything here that needs to be done at desctruction time
00077   // (e.g. close files, deallocate resources etc.)
00078   delete matcher_ ;
00079   delete mhbhe_ ;
00080   //delete doubleConeSel_ ;
00081   delete hcalIso_ ;
00082  }
00083 
00084 void
00085 FastElectronSeedProducer::beginRun(edm::Run const& run, const edm::EventSetup & es)
00086  {
00087   // get calo geometry
00088   if (caloGeomCacheId_!=es.get<CaloGeometryRecord>().cacheIdentifier())
00089    {
00090         es.get<CaloGeometryRecord>().get(caloGeom_);
00091         caloGeomCacheId_=es.get<CaloGeometryRecord>().cacheIdentifier();
00092    }
00093 
00094 //  // The H/E calculator
00095 //  calc_=HoECalculator(caloGeom_);
00096 
00097   matcher_->setupES(es) ;
00098 
00099  }
00100 
00101 void
00102 FastElectronSeedProducer::produce(edm::Event& e, const edm::EventSetup& iSetup)
00103 {
00104   LogDebug("FastElectronSeedProducer")<<"[FastElectronSeedProducer::produce] entering " ;
00105 
00106   // get initial TrajectorySeeds if necessary
00107   if (fromTrackerSeeds_) {
00108 
00109     edm::Handle<TrajectorySeedCollection> hSeeds;
00110     e.getByLabel(initialSeeds_, hSeeds);
00111     initialSeedColl_ = const_cast<TrajectorySeedCollection *> (hSeeds.product());
00112 
00113   } else {
00114 
00115     initialSeedColl_=0;// not needed in this case
00116 
00117   }
00118 
00119   reco::ElectronSeedCollection * seeds = new reco::ElectronSeedCollection ;
00120 
00121   // Get the Monte Carlo truth (SimTracks)
00122   edm::Handle<edm::SimTrackContainer> theSTC;
00123   e.getByLabel(simTracks_,theSTC);
00124   const edm::SimTrackContainer* theSimTracks = &(*theSTC);
00125 
00126   // Get the collection of Tracker RecHits
00127   edm::Handle<SiTrackerGSMatchedRecHit2DCollection> theRHC;
00128   e.getByLabel(trackerHits_, theRHC);
00129   const SiTrackerGSMatchedRecHit2DCollection* theGSRecHits = &(*theRHC);
00130 
00131   //Retrieve tracker topology from geometry
00132   edm::ESHandle<TrackerTopology> tTopoHand;
00133   iSetup.get<IdealGeometryRecord>().get(tTopoHand);
00134   const TrackerTopology *tTopo=tTopoHand.product();
00135 
00136 
00137   // get Hcal Rechit collection
00138   edm::Handle<HBHERecHitCollection> hbhe ;
00139   delete mhbhe_ ;
00140   if (e.getByLabel(hcalRecHits_,hbhe))
00141    { mhbhe_=  new HBHERecHitMetaCollection(*hbhe) ; }
00142   else
00143    { mhbhe_ = 0 ; }
00144 
00145   // define cone for H/E
00146 //  delete doubleConeSel_;
00147 //  doubleConeSel_ = new CaloDualConeSelector(0.,hOverEConeSize_,caloGeom_.product(),DetId::Hcal) ;
00148 
00149   // HCAL iso deposits
00150   delete hcalIso_ ;
00151   hcalIso_ = new EgammaHcalIsolation(hOverEConeSize_,0.,hOverEHBMinE_,hOverEHFMinE_,0.,0.,caloGeom_,mhbhe_) ;
00152 
00153   // Get the two supercluster collections
00154   for (unsigned int i=0; i<2; i++) {
00155 
00156     // invoke algorithm
00157     edm::Handle<reco::SuperClusterCollection> clusters;
00158     e.getByLabel(clusters_[i],clusters);
00159     reco::SuperClusterRefVector clusterRefs;
00160     filterClusters(clusters,/*mhbhe_,*/clusterRefs) ;
00161     matcher_->run(e,clusterRefs,theGSRecHits,theSimTracks,initialSeedColl_,tTopo,*seeds);
00162 
00163   }
00164 
00165   // Save event content
00166   std::auto_ptr<reco::ElectronSeedCollection> pSeeds(seeds) ;
00167   e.put(pSeeds);
00168 
00169 }
00170 
00171 
00172 void
00173 FastElectronSeedProducer::filterClusters
00174  ( const edm::Handle<reco::SuperClusterCollection> & superClusters,
00175    //HBHERecHitMetaCollection * mhbhe,
00176    reco::SuperClusterRefVector & sclRefs )
00177  {
00178   // filter the superclusters
00179   // - with EtCut
00180   // - with HoE using calo cone
00181   for (unsigned int i=0;i<superClusters->size();++i)
00182    {
00183     const reco::SuperCluster & scl=(*superClusters)[i] ;
00184     if (scl.energy()/cosh(scl.eta())>SCEtCut_)
00185      {
00186 //      //double HoE=calc_(&scl,mhbhe);
00187 //        double HoE = 0. ;
00188 //      double hcalE = 0. ;
00189 //      if (mhbhe_)
00190 //       {
00191 //        math::XYZPoint caloPos = scl.position() ;
00192 //        GlobalPoint pclu(caloPos.x(),caloPos.y(),caloPos.z()) ;
00193 //        std::auto_ptr<CaloRecHitMetaCollectionV> chosen
00194 //         = doubleConeSel_->select(pclu,*mhbhe_) ;
00195 //        CaloRecHitMetaCollectionV::const_iterator i ;
00196 //        for ( i = chosen->begin () ; i != chosen->end () ; ++i )
00197 //         {
00198 //          double hcalHit_E = i->energy() ;
00199 //          if ( i->detid().subdetId()==HcalBarrel && hcalHit_E > hOverEHBMinE_)
00200 //           { hcalE += hcalHit_E ; } //HB case
00201 //          //if ( i->detid().subdetId()==HcalBarrel)
00202 //          // { std::cout << "[ElectronSeedProducer] HcalBarrel: hcalHit_E, hOverEHBMinE_ " << hcalHit_E << " " << hOverEHBMinE_ << std::endl; }
00203 //          if ( i->detid().subdetId()==HcalEndcap && hcalHit_E > hOverEHFMinE_)
00204 //           { hcalE += hcalHit_E ; } //HF case
00205 //          //if ( i->detid().subdetId()==HcalEndcap)
00206 //          // { std::cout << "[ElectronSeedProducer] HcalEndcap: hcalHit_E, hOverEHFMinE_ " << hcalHit_E << " " << hOverEHFMinE_ << std::endl; }
00207 //         }
00208 //       }
00209 //      HoE = hcalE/scl.energy() ;
00210       //double hcalE = hcalHelper_->hcalESum(scl), HoE = hcalE/scl.energy() ;
00211       double newHcalE = hcalIso_->getHcalESum(&scl), newHoE = newHcalE/scl.energy() ;
00212       //std::cout << "[ElectronSeedProducer] HoE, maxHOverE_ " << newHoE << " " << HoE << " " << maxHOverE_ << std::endl ;
00213       if (newHoE<=maxHOverE_)
00214        { sclRefs.push_back(edm::Ref<reco::SuperClusterCollection>(superClusters,i)) ; }
00215      }
00216    }
00217 
00218   LogDebug("ElectronSeedProducer")<<"Filtered out "
00219     <<sclRefs.size()<<" superclusters from "<<superClusters->size() ;
00220  }