CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/FastSimulation/EgammaElectronAlgos/plugins/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 "FastSimulation/EgammaElectronAlgos/plugins/FastElectronSeedProducer.h"
00020 #include "FastSimulation/EgammaElectronAlgos/interface/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 & 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   // get Hcal Rechit collection
00132   edm::Handle<HBHERecHitCollection> hbhe ;
00133   delete mhbhe_ ;
00134   if (e.getByLabel(hcalRecHits_,hbhe))
00135    { mhbhe_=  new HBHERecHitMetaCollection(*hbhe) ; }
00136   else
00137    { mhbhe_ = 0 ; }
00138 
00139   // define cone for H/E
00140 //  delete doubleConeSel_;
00141 //  doubleConeSel_ = new CaloDualConeSelector(0.,hOverEConeSize_,caloGeom_.product(),DetId::Hcal) ;
00142 
00143   // HCAL iso deposits
00144   delete hcalIso_ ;
00145   hcalIso_ = new EgammaHcalIsolation(hOverEConeSize_,0.,hOverEHBMinE_,hOverEHFMinE_,0.,0.,caloGeom_,mhbhe_) ;
00146 
00147   // Get the two supercluster collections
00148   for (unsigned int i=0; i<2; i++) {
00149 
00150     // invoke algorithm
00151     edm::Handle<reco::SuperClusterCollection> clusters;
00152     e.getByLabel(clusters_[i],clusters);
00153     reco::SuperClusterRefVector clusterRefs;
00154     filterClusters(clusters,/*mhbhe_,*/clusterRefs) ;
00155     matcher_->run(e,clusterRefs,theGSRecHits,theSimTracks,initialSeedColl_,*seeds);
00156 
00157   }
00158 
00159   // Save event content
00160   std::auto_ptr<reco::ElectronSeedCollection> pSeeds(seeds) ;
00161   e.put(pSeeds);
00162 
00163 }
00164 
00165 
00166 void
00167 FastElectronSeedProducer::filterClusters
00168  ( const edm::Handle<reco::SuperClusterCollection> & superClusters,
00169    //HBHERecHitMetaCollection * mhbhe,
00170    reco::SuperClusterRefVector & sclRefs )
00171  {
00172   // filter the superclusters
00173   // - with EtCut
00174   // - with HoE using calo cone
00175   for (unsigned int i=0;i<superClusters->size();++i)
00176    {
00177     const reco::SuperCluster & scl=(*superClusters)[i] ;
00178     if (scl.energy()/cosh(scl.eta())>SCEtCut_)
00179      {
00180 //      //double HoE=calc_(&scl,mhbhe);
00181 //        double HoE = 0. ;
00182 //      double hcalE = 0. ;
00183 //      if (mhbhe_)
00184 //       {
00185 //        math::XYZPoint caloPos = scl.position() ;
00186 //        GlobalPoint pclu(caloPos.x(),caloPos.y(),caloPos.z()) ;
00187 //        std::auto_ptr<CaloRecHitMetaCollectionV> chosen
00188 //         = doubleConeSel_->select(pclu,*mhbhe_) ;
00189 //        CaloRecHitMetaCollectionV::const_iterator i ;
00190 //        for ( i = chosen->begin () ; i != chosen->end () ; ++i )
00191 //         {
00192 //          double hcalHit_E = i->energy() ;
00193 //          if ( i->detid().subdetId()==HcalBarrel && hcalHit_E > hOverEHBMinE_)
00194 //           { hcalE += hcalHit_E ; } //HB case
00195 //          //if ( i->detid().subdetId()==HcalBarrel)
00196 //          // { std::cout << "[ElectronSeedProducer] HcalBarrel: hcalHit_E, hOverEHBMinE_ " << hcalHit_E << " " << hOverEHBMinE_ << std::endl; }
00197 //          if ( i->detid().subdetId()==HcalEndcap && hcalHit_E > hOverEHFMinE_)
00198 //           { hcalE += hcalHit_E ; } //HF case
00199 //          //if ( i->detid().subdetId()==HcalEndcap)
00200 //          // { std::cout << "[ElectronSeedProducer] HcalEndcap: hcalHit_E, hOverEHFMinE_ " << hcalHit_E << " " << hOverEHFMinE_ << std::endl; }
00201 //         }
00202 //       }
00203 //      HoE = hcalE/scl.energy() ;
00204       //double hcalE = hcalHelper_->hcalESum(scl), HoE = hcalE/scl.energy() ;
00205       double newHcalE = hcalIso_->getHcalESum(&scl), newHoE = newHcalE/scl.energy() ;
00206       //std::cout << "[ElectronSeedProducer] HoE, maxHOverE_ " << newHoE << " " << HoE << " " << maxHOverE_ << std::endl ;
00207       if (newHoE<=maxHOverE_)
00208        { sclRefs.push_back(edm::Ref<reco::SuperClusterCollection>(superClusters,i)) ; }
00209      }
00210    }
00211 
00212   LogDebug("ElectronSeedProducer")<<"Filtered out "
00213     <<sclRefs.size()<<" superclusters from "<<superClusters->size() ;
00214  }