Go to the documentation of this file.00001 #include "RecoParticleFlow/PFClusterProducer/plugins/PFRecHitProducerPS.h"
00002
00003 #include <memory>
00004
00005 #include "DataFormats/ParticleFlowReco/interface/PFRecHit.h"
00006 #include "DataFormats/ParticleFlowReco/interface/PFLayer.h"
00007
00008 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00009 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00010 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00011
00012 #include "DataFormats/DetId/interface/DetId.h"
00013
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 #include "FWCore/Framework/interface/EventSetup.h"
00017
00018 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00019 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00020 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00021 #include "Geometry/CaloGeometry/interface/TruncatedPyramid.h"
00022 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00023
00024 #include "Geometry/CaloTopology/interface/EcalPreshowerTopology.h"
00025 #include "RecoCaloTools/Navigation/interface/CaloNavigator.h"
00026
00027
00028
00029 using namespace std;
00030 using namespace edm;
00031
00032 PFRecHitProducerPS::PFRecHitProducerPS(const edm::ParameterSet& iConfig)
00033 : PFRecHitProducer(iConfig) {
00034
00035
00036
00037
00038
00039 inputTagEcalRecHitsES_ =
00040 iConfig.getParameter<InputTag>("ecalRecHitsES");
00041 }
00042
00043
00044
00045 PFRecHitProducerPS::~PFRecHitProducerPS() {}
00046
00047
00048
00049 void PFRecHitProducerPS::createRecHits(vector<reco::PFRecHit>& rechits,
00050 vector<reco::PFRecHit>& rechitsCleaned,
00051 edm::Event& iEvent,
00052 const edm::EventSetup& iSetup) {
00053
00054 map<unsigned, unsigned > idSortedRecHits;
00055 typedef map<unsigned, unsigned >::iterator IDH;
00056
00057
00058
00059 edm::ESHandle<CaloGeometry> geoHandle;
00060 iSetup.get<CaloGeometryRecord>().get(geoHandle);
00061
00062 const CaloSubdetectorGeometry *psGeometry =
00063 geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
00064
00065
00066
00067
00068 if(!psGeometry) {
00069 LogDebug("PFRecHitProducerPS") << "No EcalPreshower geometry available. putting empty PS rechits collection in event";
00070 return;
00071 }
00072
00073
00074
00075 EcalPreshowerTopology psTopology(geoHandle);
00076
00077
00078 Handle< EcalRecHitCollection > pRecHits;
00079
00080
00081
00082 bool found = iEvent.getByLabel(inputTagEcalRecHitsES_,
00083 pRecHits);
00084
00085 if(!found) {
00086 ostringstream err;
00087 err<<"could not find rechits "<<inputTagEcalRecHitsES_;
00088 LogError("PFRecHitProducerPS")<<err.str()<<endl;
00089
00090 throw cms::Exception( "MissingProduct", err.str());
00091 }
00092 else {
00093 assert( pRecHits.isValid() );
00094
00095 const EcalRecHitCollection& psrechits = *( pRecHits.product() );
00096 typedef EcalRecHitCollection::const_iterator IT;
00097
00098 for(IT i=psrechits.begin(); i!=psrechits.end(); i++) {
00099 const EcalRecHit& hit = *i;
00100
00101 double energy = hit.energy();
00102 if( energy < thresh_Endcap_ ) continue;
00103
00104 const ESDetId& detid = hit.detid();
00105 const CaloCellGeometry *thisCell = psGeometry->getGeometry(detid);
00106
00107 if(!thisCell) {
00108 LogError("PFRecHitProducerPS")<<"warning detid "<<detid.rawId()
00109 <<" not found in preshower geometry"
00110 <<endl;
00111 return;
00112 }
00113
00114 const GlobalPoint& position = thisCell->getPosition();
00115
00116 PFLayer::Layer layer = PFLayer::NONE;
00117
00118 switch( detid.plane() ) {
00119 case 1:
00120 layer = PFLayer::PS1;
00121 break;
00122 case 2:
00123 layer = PFLayer::PS2;
00124 break;
00125 default:
00126 LogError("PFRecHitProducerPS")
00127 <<"incorrect preshower plane !! plane number "
00128 <<detid.plane()<<endl;
00129 assert(0);
00130 }
00131
00132 reco::PFRecHit *pfrh
00133 = new reco::PFRecHit( detid.rawId(), layer, energy,
00134 position.x(), position.y(), position.z(),
00135 0,0,0 );
00136
00137 const CaloCellGeometry::CornersVec& corners = thisCell->getCorners();
00138 assert( corners.size() == 8 );
00139
00140 pfrh->setNECorner( corners[0].x(), corners[0].y(), corners[0].z() );
00141 pfrh->setSECorner( corners[1].x(), corners[1].y(), corners[1].z() );
00142 pfrh->setSWCorner( corners[2].x(), corners[2].y(), corners[2].z() );
00143 pfrh->setNWCorner( corners[3].x(), corners[3].y(), corners[3].z() );
00144
00145
00146
00147
00148 rechits.push_back( *pfrh );
00149 delete pfrh;
00150 idSortedRecHits.insert( make_pair(detid.rawId(), rechits.size()-1 ) );
00151 }
00152 }
00153
00154
00155 for(unsigned i=0; i<rechits.size(); i++ ) {
00156
00157 findRecHitNeighbours( rechits[i], idSortedRecHits,
00158 psTopology,
00159 *psGeometry,
00160 psTopology,
00161 *psGeometry);
00162 }
00163 }
00164
00165
00166
00167 void
00168 PFRecHitProducerPS::findRecHitNeighbours
00169 ( reco::PFRecHit& rh,
00170 const map<unsigned,unsigned >& sortedHits,
00171 const CaloSubdetectorTopology& barrelTopology,
00172 const CaloSubdetectorGeometry& barrelGeometry,
00173 const CaloSubdetectorTopology& endcapTopology,
00174 const CaloSubdetectorGeometry& endcapGeometry ) {
00175
00176 DetId detid( rh.detId() );
00177
00178 const CaloSubdetectorTopology* topology = 0;
00179 const CaloSubdetectorGeometry* geometry = 0;
00180
00181 switch( rh.layer() ) {
00182 case PFLayer::ECAL_ENDCAP:
00183 topology = &endcapTopology;
00184 geometry = &endcapGeometry;
00185 break;
00186 case PFLayer::ECAL_BARREL:
00187 topology = &barrelTopology;
00188 geometry = &barrelGeometry;
00189 break;
00190 case PFLayer::HCAL_ENDCAP:
00191 topology = &endcapTopology;
00192 geometry = &endcapGeometry;
00193 break;
00194 case PFLayer::HCAL_BARREL1:
00195 topology = &barrelTopology;
00196 geometry = &barrelGeometry;
00197 break;
00198 case PFLayer::PS1:
00199 case PFLayer::PS2:
00200 topology = &barrelTopology;
00201 geometry = &barrelGeometry;
00202 break;
00203 default:
00204 assert(0);
00205 }
00206
00207 assert( topology && geometry );
00208
00209 CaloNavigator<DetId> navigator(detid, topology);
00210
00211 DetId north = navigator.north();
00212
00213 DetId northeast(0);
00214 if( north != DetId(0) ) {
00215 northeast = navigator.east();
00216 }
00217 navigator.home();
00218
00219
00220 DetId south = navigator.south();
00221
00222
00223
00224 DetId southwest(0);
00225 if( south != DetId(0) ) {
00226 southwest = navigator.west();
00227 }
00228 navigator.home();
00229
00230
00231 DetId east = navigator.east();
00232 DetId southeast;
00233 if( east != DetId(0) ) {
00234 southeast = navigator.south();
00235 }
00236 navigator.home();
00237 DetId west = navigator.west();
00238 DetId northwest;
00239 if( west != DetId(0) ) {
00240 northwest = navigator.north();
00241 }
00242 navigator.home();
00243
00244 IDH i = sortedHits.find( north.rawId() );
00245 if(i != sortedHits.end() )
00246 rh.add4Neighbour( i->second );
00247
00248 i = sortedHits.find( northeast.rawId() );
00249 if(i != sortedHits.end() )
00250 rh.add8Neighbour( i->second );
00251
00252 i = sortedHits.find( south.rawId() );
00253 if(i != sortedHits.end() )
00254 rh.add4Neighbour( i->second );
00255
00256 i = sortedHits.find( southwest.rawId() );
00257 if(i != sortedHits.end() )
00258 rh.add8Neighbour( i->second );
00259
00260 i = sortedHits.find( east.rawId() );
00261 if(i != sortedHits.end() )
00262 rh.add4Neighbour( i->second );
00263
00264 i = sortedHits.find( southeast.rawId() );
00265 if(i != sortedHits.end() )
00266 rh.add8Neighbour( i->second );
00267
00268 i = sortedHits.find( west.rawId() );
00269 if(i != sortedHits.end() )
00270 rh.add4Neighbour( i->second );
00271
00272 i = sortedHits.find( northwest.rawId() );
00273 if(i != sortedHits.end() )
00274 rh.add8Neighbour( i->second );
00275
00276
00277 }
00278