Go to the documentation of this file.00001
00002 #include <iostream>
00003 #include <vector>
00004 #include <memory>
00005
00006
00007 #include "FWCore/Framework/interface/Event.h"
00008 #include "FWCore/Framework/interface/EventSetup.h"
00009 #include "DataFormats/Common/interface/Handle.h"
00010 #include "FWCore/Framework/interface/ESHandle.h"
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012 #include "FWCore/Utilities/interface/Exception.h"
00013
00014
00015 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00016 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00017 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00018 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00019 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
00020 #include "DataFormats/EgammaReco/interface/BasicClusterShapeAssociation.h"
00021
00022
00023 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00024 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00025 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00026 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00027 #include "Geometry/CaloTopology/interface/EcalEndcapTopology.h"
00028 #include "Geometry/CaloTopology/interface/EcalBarrelTopology.h"
00029 #include "Geometry/CaloTopology/interface/CaloTopology.h"
00030 #include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h"
00031
00032
00033
00034 #include "RecoEcal/EgammaCoreTools/interface/PositionCalc.h"
00035
00036
00037
00038 #include "RecoEgamma/EgammaHLTProducers/interface/EgammaHLTNxNClusterProducer.h"
00039
00040
00041
00042 using namespace edm;
00043 using namespace std;
00044
00045 EgammaHLTNxNClusterProducer::EgammaHLTNxNClusterProducer(const edm::ParameterSet& ps)
00046 {
00047
00048
00049 doBarrel_ = ps.getParameter<bool>("doBarrel");
00050 doEndcaps_ = ps.getParameter<bool>("doEndcaps");
00051
00052 barrelHitProducer_ = ps.getParameter< edm::InputTag > ("barrelHitProducer");
00053 endcapHitProducer_ = ps.getParameter< edm::InputTag > ("endcapHitProducer");
00054
00055 clusEtaSize_ = ps.getParameter<int> ("clusEtaSize");
00056 clusPhiSize_ = ps.getParameter<int> ("clusPhiSize");
00057
00058
00059
00060
00061 barrelClusterCollection_ = ps.getParameter<std::string>("barrelClusterCollection");
00062 endcapClusterCollection_ = ps.getParameter<std::string>("endcapClusterCollection");
00063
00064
00065 clusSeedThr_ = ps.getParameter<double> ("clusSeedThr");
00066 clusSeedThrEndCap_ = ps.getParameter<double> ("clusSeedThrEndCap");
00067
00068 useRecoFlag_ = ps.getParameter<bool>("useRecoFlag");
00069 flagLevelRecHitsToUse_ = ps.getParameter<int>("flagLevelRecHitsToUse");
00070
00071 useDBStatus_ = ps.getParameter<bool>("useDBStatus");
00072 statusLevelRecHitsToUse_ = ps.getParameter<int>("statusLevelRecHitsToUse");
00073
00074
00075 posCalculator_ = PositionCalc( ps.getParameter<edm::ParameterSet>("posCalcParameters") );
00076
00077
00078 maxNumberofSeeds_ = ps.getParameter<int> ("maxNumberofSeeds");
00079 maxNumberofClusters_ = ps.getParameter<int> ("maxNumberofClusters");
00080
00081
00082 debug_ = ps.getParameter<int> ("debugLevel");
00083
00084 produces< reco::BasicClusterCollection >(barrelClusterCollection_);
00085 produces< reco::BasicClusterCollection >(endcapClusterCollection_);
00086
00087
00088
00089 }
00090
00091
00092 EgammaHLTNxNClusterProducer::~EgammaHLTNxNClusterProducer()
00093 {
00094
00095 }
00096
00097
00098 void EgammaHLTNxNClusterProducer::produce(edm::Event& evt, const edm::EventSetup& es)
00099 {
00100
00101
00102 if(doBarrel_){
00103 Handle<EcalRecHitCollection> barrelRecHitsHandle;
00104 evt.getByLabel(barrelHitProducer_,barrelRecHitsHandle);
00105 if (!barrelRecHitsHandle.isValid()) {
00106 LogDebug("") << "EgammaHLTNxNClusterProducer Error! can't get product eb hit!" << std::endl;
00107 }
00108
00109 const EcalRecHitCollection *hits_eb = barrelRecHitsHandle.product();
00110 if( debug_>=2 ) LogDebug("")<<"EgammaHLTNxNClusterProducer nEBrechits: "<< evt.id().run()<<" event "<<evt.id().event() <<" "<< hits_eb->size()<<std::endl;
00111
00112 makeNxNClusters(evt,es,hits_eb, reco::CaloID::DET_ECAL_BARREL);
00113
00114 }
00115
00116
00117 if(doEndcaps_){
00118 Handle<EcalRecHitCollection> endcapRecHitsHandle;
00119 evt.getByLabel(endcapHitProducer_,endcapRecHitsHandle);
00120 if (!endcapRecHitsHandle.isValid()) {
00121 LogDebug("") << "EgammaHLTNxNClusterProducer Error! can't get product ee hit!" << std::endl;
00122 }
00123
00124 const EcalRecHitCollection *hits_ee = endcapRecHitsHandle.product();
00125 if( debug_>=2 ) LogDebug("")<<"EgammaHLTNxNClusterProducer nEErechits: "<< evt.id().run()<<" event "<<evt.id().event() <<" "<< hits_ee->size()<<std::endl;
00126 makeNxNClusters(evt,es,hits_ee, reco::CaloID::DET_ECAL_ENDCAP);
00127 }
00128
00129
00130
00131 }
00132
00133
00134
00135 bool EgammaHLTNxNClusterProducer::checkStatusOfEcalRecHit(const EcalChannelStatus &channelStatus,const EcalRecHit &rh){
00136
00137 if(useRecoFlag_ ){
00138 int flag = rh.recoFlag();
00139 if( flagLevelRecHitsToUse_ ==0){
00140 if( flag != 0) return false;
00141 }
00142 else if( flagLevelRecHitsToUse_ ==1){
00143 if( flag !=0 && flag != 4 ) return false;
00144 }
00145 else if( flagLevelRecHitsToUse_ ==2){
00146 if( flag !=0 && flag != 4 && flag != 6 && flag != 7) return false;
00147 }
00148 }
00149 if ( useDBStatus_){
00150 int status = int(channelStatus[rh.id().rawId()].getStatusCode());
00151 if ( status > statusLevelRecHitsToUse_ ) return false;
00152 }
00153
00154 return true;
00155 }
00156
00157
00158
00159
00160 void EgammaHLTNxNClusterProducer::makeNxNClusters(edm::Event &evt, const edm::EventSetup &es,
00161 const EcalRecHitCollection *hits, const reco::CaloID::Detectors detector)
00162 {
00163
00164
00166 edm::ESHandle<EcalChannelStatus> csHandle;
00167 if ( useDBStatus_ ) es.get<EcalChannelStatusRcd>().get(csHandle);
00168 const EcalChannelStatus &channelStatus = *csHandle;
00169
00170
00171 std::vector<EcalRecHit> seeds;
00172
00173 double clusterSeedThreshold ;
00174 if (detector == reco::CaloID::DET_ECAL_BARREL){
00175 clusterSeedThreshold = clusSeedThr_;
00176 }else{
00177 clusterSeedThreshold = clusSeedThrEndCap_;
00178 }
00179
00180
00181 for(EcalRecHitCollection::const_iterator itt = hits->begin(); itt != hits->end(); itt++){
00182 double energy = itt->energy();
00183 if( ! checkStatusOfEcalRecHit(channelStatus, *itt) ) continue;
00184 if (energy > clusterSeedThreshold ) seeds.push_back(*itt);
00185
00186 if( int(seeds.size()) > maxNumberofSeeds_){
00187 seeds.clear();
00188 break;
00189 }
00190 }
00191
00192
00193 edm::ESHandle<CaloGeometry> geoHandle;
00194 es.get<CaloGeometryRecord>().get(geoHandle);
00195
00196 const CaloSubdetectorGeometry *geometry_p;
00197 CaloSubdetectorTopology *topology_p;
00198 if (detector == reco::CaloID::DET_ECAL_BARREL) {
00199 geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
00200 topology_p = new EcalBarrelTopology(geoHandle);
00201 }else {
00202 geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
00203 topology_p = new EcalEndcapTopology(geoHandle);
00204 }
00205
00206 const CaloSubdetectorGeometry *geometryES_p;
00207 geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
00208
00209
00210
00211 std::vector<reco::BasicCluster> clusters;
00212 std::vector<DetId> usedXtals;
00213
00214
00215 sort(seeds.begin(), seeds.end(), ecalRecHitSort());
00216
00217
00218
00219 for (std::vector<EcalRecHit>::iterator itseed=seeds.begin(); itseed!=seeds.end(); itseed++) {
00220 DetId seed_id = itseed->id();
00221 std::vector<DetId>::const_iterator usedIds;
00222
00223 std::vector<DetId>::iterator itdet = find(usedXtals.begin(),usedXtals.end(),seed_id);
00224 if(itdet != usedXtals.end()) continue;
00225
00226 std::vector<DetId> clus_v = topology_p->getWindow(seed_id,clusEtaSize_,clusPhiSize_);
00227 std::vector<std::pair<DetId, float> > clus_used;
00228
00229 float clus_energy = 0;
00230
00231 for (std::vector<DetId>::iterator det=clus_v.begin(); det!=clus_v.end(); det++) {
00232 DetId detid = *det;
00233
00234
00235 std::vector<DetId>::iterator itdet = find(usedXtals.begin(),usedXtals.end(),detid);
00236 if(itdet != usedXtals.end()) continue;
00237
00238 EcalRecHitCollection::const_iterator hit = hits->find(detid);
00239 if( hit == hits->end()) continue;
00240
00241 if( ! checkStatusOfEcalRecHit(channelStatus, *hit) ) continue;
00242
00243 usedXtals.push_back(detid);
00244 clus_used.push_back(std::pair<DetId, float>(detid, 1.) );
00245 clus_energy += hit->energy();
00246
00247 }
00248
00249 if( clus_energy <= 0 ) continue;
00250
00251 math::XYZPoint clus_pos = posCalculator_.Calculate_Location(clus_used,hits,geometry_p,geometryES_p);
00252
00253 if (debug_>=2 ) LogDebug("")<<"nxn_cluster in run "<< evt.id().run()<<" event "<<evt.id().event()<<" energy: "<<clus_energy <<" eta: "<< clus_pos.Eta()<<" phi: "<< clus_pos.Phi()<<" nRecHits: "<< clus_used.size() <<std::endl;
00254
00255 clusters.push_back(reco::BasicCluster(clus_energy, clus_pos, reco::CaloID(detector), clus_used, reco::CaloCluster::island, seed_id));
00256 if( int(clusters.size()) > maxNumberofClusters_){
00257 clusters.clear();
00258 break;
00259 }
00260
00261 }
00262
00263
00264
00265 std::auto_ptr< reco::BasicClusterCollection > clusters_p(new reco::BasicClusterCollection);
00266 clusters_p->assign(clusters.begin(), clusters.end());
00267 if (detector == reco::CaloID::DET_ECAL_BARREL){
00268 if(debug_>=1) LogDebug("")<<"nxnclusterProducer: "<<clusters_p->size() <<" made in barrel"<<std::endl;
00269 evt.put(clusters_p, barrelClusterCollection_);
00270 }
00271 else {
00272 if(debug_>=1) LogDebug("")<<"nxnclusterProducer: "<<clusters_p->size() <<" made in endcap"<<std::endl;
00273 evt.put(clusters_p, endcapClusterCollection_);
00274 }
00275
00276 }
00277
00278