00001 // -*- C++ -*- 00002 // 00003 // Package: ReduceHcalRecHitCollectionProducer 00004 // Class: ReduceHcalRecHitCollectionProducer 00005 // 00006 /*\class ReduceHcalRecHitCollectionProducer ReduceHcalRecHitCollectionProducer.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: ReduceHcalRecHitCollectionProducer.cc,v 1.2 2013/02/27 22:47:59 wmtan 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 #include "FWCore/Utilities/interface/InputTag.h" 00031 #include "FWCore/ParameterSet/interface/ParameterSet.h" 00032 00033 00034 #include "FWCore/MessageLogger/interface/MessageLogger.h" 00035 #include "FWCore/Framework/interface/EventSetup.h" 00036 #include "DataFormats/Common/interface/Handle.h" 00037 #include "FWCore/Framework/interface/ESHandle.h" 00038 00039 #include "DataFormats/TrackReco/interface/Track.h" 00040 #include "DataFormats/TrackReco/interface/TrackFwd.h" 00041 #include "DataFormats/TrackReco/interface/TrackExtra.h" 00042 00043 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h" 00044 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" 00045 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" 00046 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h" 00047 #include "DataFormats/HcalDetId/interface/HcalDetId.h" 00048 #include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h" 00049 #include "TrackingTools/TrackAssociator/interface/TrackAssociatorParameters.h" 00050 #include "TrackingTools/TrackAssociator/interface/TrackDetMatchInfo.h" 00051 00052 #include "DataFormats/EcalDetId/interface/EBDetId.h" 00053 #include "DataFormats/EcalDetId/interface/EEDetId.h" 00054 #include "DataFormats/DetId/interface/DetIdCollection.h" 00055 00056 #include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h" 00057 #include "Geometry/CaloTopology/interface/CaloTopology.h" 00058 #include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h" 00059 00060 #include <iostream> 00061 00062 // 00063 // class declaration 00064 // 00065 00066 class ReduceHcalRecHitCollectionProducer : public edm::EDProducer { 00067 public: 00068 explicit ReduceHcalRecHitCollectionProducer(const edm::ParameterSet&); 00069 ~ReduceHcalRecHitCollectionProducer(); 00070 virtual void produce(edm::Event&, const edm::EventSetup&) override; 00071 private: 00072 edm::InputTag recHitsLabel_; 00073 std::string reducedHitsCollection_; 00074 edm::InputTag inputCollection_; 00075 TrackDetectorAssociator trackAssociator_; 00076 TrackAssociatorParameters parameters_; 00077 double ptcut_; 00078 // ----------member data --------------------------- 00079 }; 00080 00081 // 00082 // constants, enums and typedefs 00083 // 00084 00085 00086 // 00087 // static data member definitions 00088 // 00089 00090 // 00091 // constructors and destructor 00092 // 00093 ReduceHcalRecHitCollectionProducer::ReduceHcalRecHitCollectionProducer(const edm::ParameterSet& iConfig) 00094 { 00095 recHitsLabel_ = iConfig.getParameter< edm::InputTag > ("recHitsLabel"); 00096 00097 reducedHitsCollection_ = iConfig.getParameter<std::string>("reducedHitsCollection"); 00098 00099 //register your products 00100 produces< HBHERecHitCollection > (reducedHitsCollection_) ; 00101 00102 inputCollection_ = iConfig.getParameter< edm::InputTag >("inputCollection"); ptcut_= iConfig.getParameter< double >("TrackPt"); 00103 00104 produces< DetIdCollection >() ; 00105 // TrackAssociator parameters 00106 edm::ParameterSet parameters = iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters"); 00107 parameters_.loadParameters( parameters ); 00108 trackAssociator_.useDefaultPropagator(); 00109 00110 } 00111 00112 00113 ReduceHcalRecHitCollectionProducer::~ReduceHcalRecHitCollectionProducer() 00114 { 00115 00116 // do anything here that needs to be done at desctruction time 00117 // (e.g. close files, deallocate resources etc.) 00118 00119 } 00120 00121 00122 // 00123 // member functions 00124 // 00125 00126 // ------------ method called to produce the data ------------ 00127 void 00128 ReduceHcalRecHitCollectionProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) 00129 { 00130 using namespace edm; 00131 00132 using namespace std; 00133 00134 using reco::TrackCollection; 00135 00136 Handle<HBHERecHitCollection> recHitsHandle; 00137 iEvent.getByLabel(recHitsLabel_,recHitsHandle); 00138 if( !recHitsHandle.isValid() ) 00139 { 00140 edm::LogError("ReduceHcalRecHitCollectionProducer") << "RecHit collection not found"; 00141 return; 00142 } 00143 00144 //Create empty output collections 00145 std::auto_ptr< HBHERecHitCollection > miniRecHitCollection (new HBHERecHitCollection) ; 00146 00147 //loop through tracks. 00148 Handle<TrackCollection> tkTracks; 00149 iEvent.getByLabel(inputCollection_,tkTracks); 00150 std::auto_ptr< DetIdCollection > interestingDetIdCollection( new DetIdCollection() ) ; 00151 for(TrackCollection::const_iterator itTrack = tkTracks->begin(); 00152 itTrack != tkTracks->end(); 00153 ++itTrack) { 00154 if(itTrack->pt()>ptcut_){ 00155 00156 TrackDetMatchInfo info = trackAssociator_.associate(iEvent, iSetup, *itTrack, parameters_, TrackDetectorAssociator::InsideOut); 00157 00158 if(info.crossedHcalIds.size()>0){ 00159 //loop through hits in the cone 00160 for(std::vector<const HBHERecHit*>::const_iterator hit = info.hcalRecHits.begin(); 00161 hit != info.hcalRecHits.end(); ++hit) 00162 { 00163 DetId hitid=(*hit)->id(); 00164 HBHERecHitCollection::const_iterator iRecHit = recHitsHandle->find(hitid); 00165 if ( (iRecHit != recHitsHandle->end()) && (miniRecHitCollection->find(hitid) == miniRecHitCollection->end()) ) 00166 miniRecHitCollection->push_back(*iRecHit); 00167 } 00168 00169 00170 } 00171 } 00172 } 00173 00174 iEvent.put( miniRecHitCollection,reducedHitsCollection_ ); 00175 00176 00177 00178 } 00179 //define this as a plug-in 00180 DEFINE_FWK_MODULE(ReduceHcalRecHitCollectionProducer);