00001 #include "RecoEcal/EgammaClusterProducers/interface/ReducedRecHitCollectionProducer.h" 00002 00003 #include "FWCore/MessageLogger/interface/MessageLogger.h" 00004 #include "FWCore/Framework/interface/EventSetup.h" 00005 #include "FWCore/Framework/interface/ESHandle.h" 00006 00007 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" 00008 00009 #include "DataFormats/EcalDetId/interface/EBDetId.h" 00010 #include "DataFormats/EcalDetId/interface/EEDetId.h" 00011 00012 #include "DataFormats/DetId/interface/DetIdCollection.h" 00013 00014 #include "DataFormats/EgammaReco/interface/BasicCluster.h" 00015 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h" 00016 00017 #include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h" 00018 #include "Geometry/CaloTopology/interface/CaloTopology.h" 00019 #include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h" 00020 00021 #include <iostream> 00022 00023 ReducedRecHitCollectionProducer::ReducedRecHitCollectionProducer(const edm::ParameterSet& iConfig) 00024 { 00025 00026 recHitsLabel_ = iConfig.getParameter< edm::InputTag > ("recHitsLabel"); 00027 interestingDetIdCollections_ = iConfig.getParameter< std::vector<edm::InputTag> > ("interestingDetIdCollections"); 00028 00029 reducedHitsCollection_ = iConfig.getParameter<std::string>("reducedHitsCollection"); 00030 00031 //register your products 00032 produces< EcalRecHitCollection > (reducedHitsCollection_) ; 00033 00034 } 00035 00036 00037 ReducedRecHitCollectionProducer::~ReducedRecHitCollectionProducer() 00038 {} 00039 00040 00041 // ------------ method called to produce the data ------------ 00042 void 00043 ReducedRecHitCollectionProducer::produce (edm::Event& iEvent, 00044 const edm::EventSetup& iSetup) 00045 { 00046 using namespace edm; 00047 using namespace std; 00048 00049 if (interestingDetIdCollections_.size() < 1) 00050 { 00051 edm::LogError("ReducedRecHitCollectionProducer") << "VInputTag collections empty" ; 00052 return; 00053 } 00054 00055 00056 Handle< DetIdCollection > detIds; 00057 iEvent.getByLabel(interestingDetIdCollections_[0],detIds); 00058 std::vector<DetId> xtalsToStore((*detIds).size()); 00059 std::copy( (*detIds).begin() , (*detIds).end() , xtalsToStore.begin() ); 00060 00061 //Merging DetIds from different collections 00062 for( unsigned int t = 1; t < interestingDetIdCollections_.size(); ++t ) 00063 { 00064 Handle< DetIdCollection > detId; 00065 iEvent.getByLabel(interestingDetIdCollections_[t],detId); 00066 if( !detId.isValid() ){ 00067 edm::LogError("MissingInput")<<"no reason to skip detid from :"<<interestingDetIdCollections_[t]; 00068 continue; 00069 } 00070 00071 for (unsigned int ii=0;ii<(*detId).size();ii++) 00072 { 00073 if (std::find(xtalsToStore.begin(),xtalsToStore.end(),(*detId)[ii]) == xtalsToStore.end()) 00074 xtalsToStore.push_back((*detId)[ii]); 00075 } 00076 } 00077 00078 Handle<EcalRecHitCollection> recHitsHandle; 00079 iEvent.getByLabel(recHitsLabel_,recHitsHandle); 00080 if( !recHitsHandle.isValid() ) 00081 { 00082 edm::LogError("ReducedRecHitCollectionProducer") << "RecHit collection not found"; 00083 return; 00084 } 00085 00086 //Create empty output collections 00087 std::auto_ptr< EcalRecHitCollection > miniRecHitCollection (new EcalRecHitCollection) ; 00088 00089 for (unsigned int iCry=0;iCry<xtalsToStore.size();iCry++) 00090 { 00091 EcalRecHitCollection::const_iterator iRecHit = recHitsHandle->find(xtalsToStore[iCry]); 00092 if ( (iRecHit != recHitsHandle->end()) && (miniRecHitCollection->find(xtalsToStore[iCry]) == miniRecHitCollection->end()) ) 00093 miniRecHitCollection->push_back(*iRecHit); 00094 } 00095 00096 // std::cout << "New Collection " << reducedHitsCollection_ << " size is " << miniRecHitCollection->size() << " original is " << recHitsHandle->size() << std::endl; 00097 iEvent.put( miniRecHitCollection,reducedHitsCollection_ ); 00098 }