CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/SUSYBSMAnalysis/Skimming/plugins/HighPtTrackEcalDetIdProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    HighPtTrackEcalDetIdProducer
00004 // Class:      HighPtTrackEcalDetIdProducer
00005 // 
00006 /*\class HighPtTrackEcalDetIdProducer HighPtTrackEcalDetIdProducer.cc 
00007 
00008  Description: [one line class summary]
00009 
00010  Implementation:
00011      [Notes on implementation]
00012 */
00013 //
00014 // Original Author:  Jie Chen
00015 //         Created:  Mon Apr 12 16:41:46 CDT 2010
00016 // $Id: HighPtTrackEcalDetIdProducer.cc,v 1.1 2010/04/14 14:30:38 jiechen 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 
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032 #include "DataFormats/Common/interface/Handle.h"
00033 #include "FWCore/Framework/interface/ESHandle.h"
00034 
00035 #include "DataFormats/TrackReco/interface/Track.h"
00036 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00037 #include "DataFormats/TrackReco/interface/TrackExtra.h"
00038 
00039 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00040 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00041 
00042 #include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h"
00043 #include "TrackingTools/TrackAssociator/interface/TrackAssociatorParameters.h"
00044 #include "TrackingTools/TrackAssociator/interface/TrackDetMatchInfo.h"
00045 
00046 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00047 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00048 #include "DataFormats/DetId/interface/DetIdCollection.h"
00049 
00050 #include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h"
00051 #include "Geometry/CaloTopology/interface/CaloTopology.h"
00052 #include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h"
00053 
00054 //
00055 // class declaration
00056 //
00057 
00058 class HighPtTrackEcalDetIdProducer : public edm::EDProducer {
00059    public:
00060       explicit HighPtTrackEcalDetIdProducer(const edm::ParameterSet&);
00061       ~HighPtTrackEcalDetIdProducer();
00062       void beginRun(edm::Run&, const edm::EventSetup&);
00063       void produce(edm::Event&, const edm::EventSetup&);
00064    private:
00065 
00066       edm::InputTag inputCollection_;
00067       const CaloTopology* caloTopology_;
00068       TrackDetectorAssociator trackAssociator_;
00069       TrackAssociatorParameters parameters_;
00070       double  ptcut_;
00071       // ----------member data ---------------------------
00072 };
00073 
00074 //
00075 // constants, enums and typedefs
00076 //
00077 
00078 
00079 //
00080 // static data member definitions
00081 //
00082 
00083 //
00084 // constructors and destructor
00085 //
00086 HighPtTrackEcalDetIdProducer::HighPtTrackEcalDetIdProducer(const edm::ParameterSet& iConfig)
00087 {
00088    inputCollection_ = iConfig.getParameter< edm::InputTag >("inputCollection");    ptcut_= iConfig.getParameter< double >("TrackPt");
00089 
00090     produces< DetIdCollection >() ;
00091    // TrackAssociator parameters
00092    edm::ParameterSet parameters = iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
00093    parameters_.loadParameters( parameters );
00094    trackAssociator_.useDefaultPropagator();
00095   
00096 }
00097 
00098 
00099 HighPtTrackEcalDetIdProducer::~HighPtTrackEcalDetIdProducer()
00100 {
00101  
00102    // do anything here that needs to be done at desctruction time
00103    // (e.g. close files, deallocate resources etc.)
00104 
00105 }
00106 
00107 
00108 //
00109 // member functions
00110 //
00111 
00112 void
00113 HighPtTrackEcalDetIdProducer::beginRun(edm::Run & run, const edm::EventSetup & iSetup)  
00114 {
00115    edm::ESHandle<CaloTopology> theCaloTopology;
00116    iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
00117    caloTopology_ = &(*theCaloTopology); 
00118 }
00119 
00120 // ------------ method called to produce the data  ------------
00121 void
00122 HighPtTrackEcalDetIdProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00123 {
00124    using namespace edm;
00125    using reco::TrackCollection;
00126 //   if(!iSetup) continue;
00127    Handle<TrackCollection> tkTracks;
00128    iEvent.getByLabel(inputCollection_,tkTracks);
00129    std::auto_ptr< DetIdCollection > interestingDetIdCollection( new DetIdCollection() ) ;
00130    for(TrackCollection::const_iterator itTrack = tkTracks->begin();
00131        itTrack != tkTracks->end();                      
00132        ++itTrack) {
00133         if(itTrack->pt()>ptcut_){
00134            TrackDetMatchInfo info = trackAssociator_.associate(iEvent, iSetup, *itTrack, parameters_, TrackDetectorAssociator::InsideOut);
00135            if(info.crossedEcalIds.size()==0) break;
00136 
00137            if(info.crossedEcalIds.size()>0){
00138               DetId centerId = info.crossedEcalIds.front();
00139 
00140               const CaloSubdetectorTopology* topology = caloTopology_->getSubdetectorTopology(DetId::Ecal,centerId.subdetId());
00141               const std::vector<DetId>& ids = topology->getWindow(centerId, 5, 5); 
00142               for ( std::vector<DetId>::const_iterator id = ids.begin(); id != ids.end(); ++id )
00143                  if(std::find(interestingDetIdCollection->begin(), interestingDetIdCollection->end(), *id) 
00144                     == interestingDetIdCollection->end()) 
00145                     interestingDetIdCollection->push_back(*id);            
00146            }
00147         }
00148 
00149    }
00150    iEvent.put(interestingDetIdCollection);
00151 
00152 }
00153 //define this as a plug-in
00154 DEFINE_FWK_MODULE(HighPtTrackEcalDetIdProducer);