CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/RecoEcal/EgammaClusterProducers/src/InterestingDetIdCollectionProducer.cc

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 #include "RecoEcal/EgammaCoreTools/interface/EcalTools.h"
00023 
00024 // $Id: InterestingDetIdCollectionProducer.cc,v 1.10 2011/05/19 14:29:48 argiro Exp $
00025 
00026 InterestingDetIdCollectionProducer::InterestingDetIdCollectionProducer(const edm::ParameterSet& iConfig) 
00027 {
00028 
00029   recHitsLabel_ = iConfig.getParameter< edm::InputTag > ("recHitsLabel");
00030   basicClusters_ = iConfig.getParameter< edm::InputTag > ("basicClustersLabel");
00031 
00032   interestingDetIdCollection_ = iConfig.getParameter<std::string>("interestingDetIdCollection");
00033   
00034   minimalEtaSize_ = iConfig.getParameter<int> ("etaSize");
00035   minimalPhiSize_ = iConfig.getParameter<int> ("phiSize");
00036   if ( minimalPhiSize_ % 2 == 0 ||  minimalEtaSize_ % 2 == 0)
00037     edm::LogError("InterestingDetIdCollectionProducerError") << "Size of eta/phi should be odd numbers";
00038  
00039    //register your products
00040   produces< DetIdCollection > (interestingDetIdCollection_) ;
00041 
00042   severityLevel_  = iConfig.getParameter<int>("severityLevel");
00043   keepNextToDead_ = iConfig.getParameter<bool>("keepNextToDead");
00044   keepNextToBoundary_ = iConfig.getParameter<bool>("keepNextToBoundary");
00045 }
00046 
00047 
00048 InterestingDetIdCollectionProducer::~InterestingDetIdCollectionProducer()
00049 {}
00050 
00051 void InterestingDetIdCollectionProducer::beginRun (edm::Run & run, const edm::EventSetup & iSetup)  
00052 {
00053   edm::ESHandle<CaloTopology> theCaloTopology;
00054   iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
00055   caloTopology_ = &(*theCaloTopology); 
00056 
00057   edm::ESHandle<EcalSeverityLevelAlgo> sevLv;
00058   iSetup.get<EcalSeverityLevelAlgoRcd>().get(sevLv);
00059   severity_ = sevLv.product();
00060 }
00061 
00062 // ------------ method called to produce the data  ------------
00063 void
00064 InterestingDetIdCollectionProducer::produce (edm::Event& iEvent, 
00065                                 const edm::EventSetup& iSetup)
00066 {
00067    using namespace edm;
00068    using namespace std;
00069 
00070    // take BasicClusters
00071   Handle<reco::BasicClusterCollection> pClusters;
00072   iEvent.getByLabel(basicClusters_, pClusters);
00073   
00074   // take EcalRecHits
00075   Handle<EcalRecHitCollection> recHitsHandle;
00076   iEvent.getByLabel(recHitsLabel_,recHitsHandle);
00077 
00078   //Create empty output collections
00079   std::vector<DetId> indexToStore;
00080   indexToStore.reserve(1000);
00081 
00082   reco::BasicClusterCollection::const_iterator clusIt;
00083 
00084   std::vector<DetId> xtalsToStore;
00085   xtalsToStore.reserve(50);
00086   for (clusIt=pClusters->begin(); clusIt!=pClusters->end(); clusIt++) {
00087     //PG barrel
00088     
00089     float eMax=0.;
00090     DetId eMaxId(0);
00091 
00092     std::vector<std::pair<DetId,float> > clusterDetIds = (*clusIt).hitsAndFractions();
00093     std::vector<std::pair<DetId,float> >::iterator posCurrent;
00094 
00095     EcalRecHit testEcalRecHit;
00096     
00097     for(posCurrent = clusterDetIds.begin(); posCurrent != clusterDetIds.end(); posCurrent++)
00098       {
00099         EcalRecHitCollection::const_iterator itt = recHitsHandle->find((*posCurrent).first);
00100         if ((!((*posCurrent).first.null())) && (itt != recHitsHandle->end()) && ((*itt).energy() > eMax) )
00101           {
00102             eMax = (*itt).energy();
00103             eMaxId = (*itt).id();
00104           }
00105       }
00106     
00107     if (eMaxId.null())
00108     continue;
00109     
00110     const CaloSubdetectorTopology* topology  = caloTopology_->getSubdetectorTopology(eMaxId.det(),eMaxId.subdetId());
00111 
00112     xtalsToStore=topology->getWindow(eMaxId,minimalEtaSize_,minimalPhiSize_);
00113     std::vector<std::pair<DetId,float > > xtalsInClus=(*clusIt).hitsAndFractions();
00114     
00115     for (unsigned int ii=0;ii<xtalsInClus.size();ii++)
00116       {
00117           xtalsToStore.push_back(xtalsInClus[ii].first);
00118       }
00119     
00120     indexToStore.insert(indexToStore.end(),xtalsToStore.begin(),xtalsToStore.end());
00121   }
00122 
00123 
00124  
00125   for (EcalRecHitCollection::const_iterator it = recHitsHandle->begin(); it != recHitsHandle->end(); ++it) {
00126     // also add recHits of dead TT if the corresponding TP is saturated
00127     if ( it->checkFlag(EcalRecHit::kTPSaturated) ) {
00128       indexToStore.push_back(it->id());
00129     }
00130     // add hits for severities above a threshold
00131     if ( severityLevel_>=0 && 
00132          severity_->severityLevel(*it) >=severityLevel_){
00133       
00134       indexToStore.push_back(it->id());
00135     } 
00136     if (keepNextToDead_) {
00137       // also keep channels next to dead ones
00138       if (EcalTools::isNextToDead(it->id(), iSetup)) {
00139         indexToStore.push_back(it->id());
00140       }
00141     } 
00142 
00143     if (keepNextToBoundary_){
00144       // keep channels around EB/EE boundary
00145       if (it->id().subdetId() == EcalBarrel){
00146         EBDetId ebid(it->id());
00147         if (abs(ebid.ieta())== 85)
00148           indexToStore.push_back(it->id());
00149       } else {
00150      
00151         if (EEDetId::isNextToRingBoundary(it->id()))
00152           indexToStore.push_back(it->id());
00153       }
00154 
00155     }
00156     
00157   }
00158 
00159   //unify the vector
00160   std::sort(indexToStore.begin(),indexToStore.end());
00161   std::unique(indexToStore.begin(),indexToStore.end());
00162   
00163   std::auto_ptr< DetIdCollection > detIdCollection (new DetIdCollection(indexToStore) ) ;
00164 
00165  
00166   iEvent.put( detIdCollection, interestingDetIdCollection_ );
00167 
00168 }