CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/RecoEcal/EgammaClusterProducers/src/InterestingTrackEcalDetIdProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    InterestingTrackEcalDetIdProducer
00004 // Class:      InterestingTrackEcalDetIdProducer
00005 // 
00013 //
00014 // Original Author:  
00015 //         Created:  Wed Sep 22 17:02:51 CEST 2010
00016 // $Id: InterestingTrackEcalDetIdProducer.cc,v 1.1 2011/01/21 09:03:21 argiro Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDProducer.h"
00027 #include "FWCore/Framework/interface/Event.h"
00028 #include "FWCore/Framework/interface/MakerMacros.h"
00029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00030 
00031 #include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h"
00032 #include "Geometry/CaloTopology/interface/CaloTopology.h"
00033 #include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h"
00034 
00035 #include "DataFormats/DetId/interface/DetIdCollection.h"
00036 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00037 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00038 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00039 
00040 #include "DataFormats/TrackReco/interface/Track.h"
00041 
00042 #include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h"
00043 #include "TrackingTools/TrackAssociator/interface/TrackAssociatorParameters.h"
00044 
00045 
00046 //
00047 // class declaration
00048 //
00049 
00050 class InterestingTrackEcalDetIdProducer : public edm::EDProducer {
00051    public:
00052       explicit InterestingTrackEcalDetIdProducer(const edm::ParameterSet&);
00053       ~InterestingTrackEcalDetIdProducer();
00054 
00055    private:
00056       virtual void beginJob() ;
00057       virtual void produce(edm::Event&, const edm::EventSetup&);
00058       virtual void endJob() ;
00059       void beginRun(edm::Run&, const edm::EventSetup&);
00060 
00061       
00062       // ----------member data ---------------------------
00063       edm::InputTag trackCollection_;
00064       edm::ParameterSet trackAssociatorPS_;
00065 
00066       double minTrackPt_;
00067 
00068       const CaloTopology* caloTopology_;
00069       TrackDetectorAssociator trackAssociator_; 
00070       TrackAssociatorParameters trackAssociatorParameters_; 
00071 
00072 
00073 };
00074 
00075 //
00076 // constants, enums and typedefs
00077 //
00078 
00079 
00080 //
00081 // static data member definitions
00082 //
00083 
00084 //
00085 // constructors and destructor
00086 //
00087 InterestingTrackEcalDetIdProducer::InterestingTrackEcalDetIdProducer(const edm::ParameterSet& iConfig) :
00088   trackCollection_ (iConfig.getParameter<edm::InputTag>("TrackCollection")),
00089   trackAssociatorPS_ (iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters")),
00090   minTrackPt_ (iConfig.getParameter<double>("MinTrackPt"))
00091 
00092 {
00093   trackAssociator_.useDefaultPropagator();
00094   trackAssociatorParameters_.loadParameters(trackAssociatorPS_);
00095 
00096   produces<DetIdCollection>(); 
00097 }
00098 
00099 
00100 InterestingTrackEcalDetIdProducer::~InterestingTrackEcalDetIdProducer()
00101 {
00102  
00103    // do anything here that needs to be done at desctruction time
00104    // (e.g. close files, deallocate resources etc.)
00105 
00106 }
00107 
00108 
00109 //
00110 // member functions
00111 //
00112 
00113 // ------------ method called to produce the data  ------------
00114 void
00115 InterestingTrackEcalDetIdProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00116 {
00117    using namespace edm;
00118 
00119    std::auto_ptr< DetIdCollection > interestingDetIdCollection( new DetIdCollection() ) ;
00120 
00121    // Get tracks from event
00122    edm::Handle<reco::TrackCollection> tracks;
00123    iEvent.getByLabel(trackCollection_,tracks);
00124 
00125    // Loop over tracks
00126    for(reco::TrackCollection::const_iterator tkItr = tracks->begin(); tkItr != tracks->end(); ++tkItr)
00127    {
00128      if(tkItr->pt() < minTrackPt_)
00129        continue;
00130 
00131      TrackDetMatchInfo info = trackAssociator_.associate( iEvent, iSetup, 
00132          trackAssociator_.getFreeTrajectoryState(iSetup, *tkItr),
00133          trackAssociatorParameters_ );
00134 
00135      DetId centerId = info.findMaxDeposition(TrackDetMatchInfo::EcalRecHits);
00136 
00137      if(centerId.rawId()==0)
00138        continue;
00139 
00140      // Find 5x5 around max
00141      const CaloSubdetectorTopology* topology = caloTopology_->getSubdetectorTopology(DetId::Ecal,centerId.subdetId());
00142      const std::vector<DetId>& ids = topology->getWindow(centerId, 5, 5);
00143      for(std::vector<DetId>::const_iterator idItr = ids.begin(); idItr != ids.end(); ++idItr)
00144      {
00145        if(std::find(interestingDetIdCollection->begin(), interestingDetIdCollection->end(), *idItr)
00146            == interestingDetIdCollection->end())
00147          interestingDetIdCollection->push_back(*idItr);
00148      }
00149 
00150    }
00151 
00152    iEvent.put(interestingDetIdCollection);
00153 
00154 }
00155 
00156 void InterestingTrackEcalDetIdProducer::beginRun(edm::Run & run, const edm::EventSetup & iSetup)  
00157 {
00158   edm::ESHandle<CaloTopology> theCaloTopology;
00159   iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
00160   caloTopology_ = &(*theCaloTopology); 
00161 }
00162 
00163 // ------------ method called once each job just before starting event loop  ------------
00164 void 
00165 InterestingTrackEcalDetIdProducer::beginJob()
00166 {
00167 }
00168 
00169 // ------------ method called once each job just after ending the event loop  ------------
00170 void 
00171 InterestingTrackEcalDetIdProducer::endJob() {
00172 }
00173 
00174 //define this as a plug-in
00175 DEFINE_FWK_MODULE(InterestingTrackEcalDetIdProducer);