Go to the documentation of this file.00001 #include "RecoEcal/EgammaClusterProducers/interface/InterestingDetIdCollectionProducer.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 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00014 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
00015
00016 #include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h"
00017 #include "Geometry/CaloTopology/interface/CaloTopology.h"
00018 #include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h"
00019
00020 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h"
00021 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h"
00022
00023
00024 InterestingDetIdCollectionProducer::InterestingDetIdCollectionProducer(const edm::ParameterSet& iConfig)
00025 {
00026
00027 recHitsLabel_ = iConfig.getParameter< edm::InputTag > ("recHitsLabel");
00028 basicClusters_ = iConfig.getParameter< edm::InputTag > ("basicClustersLabel");
00029
00030 interestingDetIdCollection_ = iConfig.getParameter<std::string>("interestingDetIdCollection");
00031
00032 minimalEtaSize_ = iConfig.getParameter<int> ("etaSize");
00033 minimalPhiSize_ = iConfig.getParameter<int> ("phiSize");
00034 if ( minimalPhiSize_ % 2 == 0 || minimalEtaSize_ % 2 == 0)
00035 edm::LogError("InterestingDetIdCollectionProducerError") << "Size of eta/phi should be odd numbers";
00036
00037
00038 produces< DetIdCollection > (interestingDetIdCollection_) ;
00039
00040 severityLevel_ = iConfig.getParameter<int>("severityLevel");
00041 }
00042
00043
00044 InterestingDetIdCollectionProducer::~InterestingDetIdCollectionProducer()
00045 {}
00046
00047 void InterestingDetIdCollectionProducer::beginRun (edm::Run & run, const edm::EventSetup & iSetup)
00048 {
00049 edm::ESHandle<CaloTopology> theCaloTopology;
00050 iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
00051 caloTopology_ = &(*theCaloTopology);
00052
00053 edm::ESHandle<EcalSeverityLevelAlgo> sevLv;
00054 iSetup.get<EcalSeverityLevelAlgoRcd>().get(sevLv);
00055 severity_ = sevLv.product();
00056 }
00057
00058
00059 void
00060 InterestingDetIdCollectionProducer::produce (edm::Event& iEvent,
00061 const edm::EventSetup& iSetup)
00062 {
00063 using namespace edm;
00064 using namespace std;
00065
00066
00067 Handle<reco::BasicClusterCollection> pClusters;
00068 iEvent.getByLabel(basicClusters_, pClusters);
00069
00070
00071 Handle<EcalRecHitCollection> recHitsHandle;
00072 iEvent.getByLabel(recHitsLabel_,recHitsHandle);
00073
00074
00075 std::auto_ptr< DetIdCollection > detIdCollection (new DetIdCollection() ) ;
00076
00077 reco::BasicClusterCollection::const_iterator clusIt;
00078
00079 for (clusIt=pClusters->begin(); clusIt!=pClusters->end(); clusIt++) {
00080
00081
00082 float eMax=0.;
00083 DetId eMaxId(0);
00084
00085 std::vector<std::pair<DetId,float> > clusterDetIds = (*clusIt).hitsAndFractions();
00086 std::vector<std::pair<DetId,float> >::iterator posCurrent;
00087
00088 EcalRecHit testEcalRecHit;
00089
00090 for(posCurrent = clusterDetIds.begin(); posCurrent != clusterDetIds.end(); posCurrent++)
00091 {
00092 EcalRecHitCollection::const_iterator itt = recHitsHandle->find((*posCurrent).first);
00093 if ((!((*posCurrent).first.null())) && (itt != recHitsHandle->end()) && ((*itt).energy() > eMax) )
00094 {
00095 eMax = (*itt).energy();
00096 eMaxId = (*itt).id();
00097 }
00098 }
00099
00100 if (eMaxId.null())
00101 continue;
00102
00103 const CaloSubdetectorTopology* topology = caloTopology_->getSubdetectorTopology(eMaxId.det(),eMaxId.subdetId());
00104 std::vector<DetId> xtalsToStore=topology->getWindow(eMaxId,minimalEtaSize_,minimalPhiSize_);
00105 std::vector<std::pair<DetId,float > > xtalsInClus=(*clusIt).hitsAndFractions();
00106
00107 for (unsigned int ii=0;ii<xtalsInClus.size();ii++)
00108 {
00109 if (std::find(xtalsToStore.begin(),xtalsToStore.end(),xtalsInClus[ii].first) == xtalsToStore.end())
00110 xtalsToStore.push_back(xtalsInClus[ii].first);
00111 }
00112
00113 for (unsigned int iCry=0;iCry<xtalsToStore.size();iCry++)
00114 {
00115 if (
00116 std::find(detIdCollection->begin(),detIdCollection->end(),xtalsToStore[iCry]) == detIdCollection->end()
00117 )
00118 detIdCollection->push_back(xtalsToStore[iCry]);
00119 }
00120 }
00121
00122
00123 for (EcalRecHitCollection::const_iterator it = recHitsHandle->begin(); it != recHitsHandle->end(); ++it) {
00124 if ( it->checkFlag(EcalRecHit::kTPSaturated) ) {
00125 if ( std::find( detIdCollection->begin(), detIdCollection->end(), it->id() ) == detIdCollection->end()
00126 ) {
00127 detIdCollection->push_back( it->id() );
00128 }
00129 }else if ( severityLevel_>=0 && severity_->severityLevel(*it) >=severityLevel_){
00130 detIdCollection->push_back( it->id() );
00131 }
00132
00133 }
00134
00135
00136 iEvent.put( detIdCollection, interestingDetIdCollection_ );
00137
00138 }