00001 #include "RecoParticleFlow/PFClusterProducer/interface/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 edm::Event& iEvent,
00051 const edm::EventSetup& iSetup) {
00052
00053 map<unsigned, unsigned > idSortedRecHits;
00054 typedef map<unsigned, unsigned >::iterator IDH;
00055
00056
00057
00058 edm::ESHandle<CaloGeometry> geoHandle;
00059 iSetup.get<CaloGeometryRecord>().get(geoHandle);
00060
00061 const CaloSubdetectorGeometry *psGeometry =
00062 geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
00063
00064
00065
00066
00067 if(!psGeometry) {
00068 LogDebug("PFRecHitProducerPS") << "No EcalPreshower geometry available. putting empty PS rechits collection in event";
00069 return;
00070 }
00071
00072
00073
00074 EcalPreshowerTopology psTopology(geoHandle);
00075
00076
00077 Handle< EcalRecHitCollection > pRecHits;
00078
00079
00080
00081 bool found = iEvent.getByLabel(inputTagEcalRecHitsES_,
00082 pRecHits);
00083
00084 if(!found) {
00085 ostringstream err;
00086 err<<"could not find rechits "<<inputTagEcalRecHitsES_;
00087 LogError("PFRecHitProducerPS")<<err.str()<<endl;
00088
00089 throw cms::Exception( "MissingProduct", err.str());
00090 }
00091 else {
00092 assert( pRecHits.isValid() );
00093
00094 const EcalRecHitCollection& psrechits = *( pRecHits.product() );
00095 typedef EcalRecHitCollection::const_iterator IT;
00096
00097 for(IT i=psrechits.begin(); i!=psrechits.end(); i++) {
00098 const EcalRecHit& hit = *i;
00099
00100 double energy = hit.energy();
00101 if( energy < thresh_Endcap_ ) continue;
00102
00103 const ESDetId& detid = hit.detid();
00104 const CaloCellGeometry *thisCell = psGeometry->getGeometry(detid);
00105
00106 if(!thisCell) {
00107 LogError("PFRecHitProducerPS")<<"warning detid "<<detid.rawId()
00108 <<" not found in preshower geometry"
00109 <<endl;
00110 return;
00111 }
00112
00113 const GlobalPoint& position = thisCell->getPosition();
00114
00115 PFLayer::Layer layer = PFLayer::NONE;
00116
00117 switch( detid.plane() ) {
00118 case 1:
00119 layer = PFLayer::PS1;
00120 break;
00121 case 2:
00122 layer = PFLayer::PS2;
00123 break;
00124 default:
00125 LogError("PFRecHitProducerPS")
00126 <<"incorrect preshower plane !! plane number "
00127 <<detid.plane()<<endl;
00128 assert(0);
00129 }
00130
00131 reco::PFRecHit *pfrh
00132 = new reco::PFRecHit( detid.rawId(), layer, energy,
00133 position.x(), position.y(), position.z(),
00134 0,0,0 );
00135
00136 const CaloCellGeometry::CornersVec& corners = thisCell->getCorners();
00137 assert( corners.size() == 8 );
00138
00139 pfrh->setNECorner( corners[0].x(), corners[0].y(), corners[0].z() );
00140 pfrh->setSECorner( corners[1].x(), corners[1].y(), corners[1].z() );
00141 pfrh->setSWCorner( corners[2].x(), corners[2].y(), corners[2].z() );
00142 pfrh->setNWCorner( corners[3].x(), corners[3].y(), corners[3].z() );
00143
00144
00145
00146
00147 rechits.push_back( *pfrh );
00148 delete pfrh;
00149 idSortedRecHits.insert( make_pair(detid.rawId(), rechits.size()-1 ) );
00150 }
00151 }
00152
00153
00154 for(unsigned i=0; i<rechits.size(); i++ ) {
00155
00156 findRecHitNeighbours( rechits[i], idSortedRecHits,
00157 psTopology,
00158 *psGeometry,
00159 psTopology,
00160 *psGeometry);
00161 }
00162 }
00163
00164
00165
00166 void
00167 PFRecHitProducerPS::findRecHitNeighbours
00168 ( reco::PFRecHit& rh,
00169 const map<unsigned,unsigned >& sortedHits,
00170 const CaloSubdetectorTopology& barrelTopology,
00171 const CaloSubdetectorGeometry& barrelGeometry,
00172 const CaloSubdetectorTopology& endcapTopology,
00173 const CaloSubdetectorGeometry& endcapGeometry ) {
00174
00175 DetId detid( rh.detId() );
00176
00177 const CaloSubdetectorTopology* topology = 0;
00178 const CaloSubdetectorGeometry* geometry = 0;
00179 const CaloSubdetectorGeometry* othergeometry = 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 othergeometry = &barrelGeometry;
00194 break;
00195 case PFLayer::HCAL_BARREL1:
00196 topology = &barrelTopology;
00197 geometry = &barrelGeometry;
00198 othergeometry = &endcapGeometry;
00199 break;
00200 case PFLayer::PS1:
00201 case PFLayer::PS2:
00202 topology = &barrelTopology;
00203 geometry = &barrelGeometry;
00204 othergeometry = &endcapGeometry;
00205 break;
00206 default:
00207 assert(0);
00208 }
00209
00210 assert( topology && geometry );
00211
00212 CaloNavigator<DetId> navigator(detid, topology);
00213
00214 DetId north = navigator.north();
00215
00216 DetId northeast(0);
00217 if( north != DetId(0) ) {
00218 northeast = navigator.east();
00219 }
00220 navigator.home();
00221
00222
00223 DetId south = navigator.south();
00224
00225
00226
00227 DetId southwest(0);
00228 if( south != DetId(0) ) {
00229 southwest = navigator.west();
00230 }
00231 navigator.home();
00232
00233
00234 DetId east = navigator.east();
00235 DetId southeast;
00236 if( east != DetId(0) ) {
00237 southeast = navigator.south();
00238 }
00239 navigator.home();
00240 DetId west = navigator.west();
00241 DetId northwest;
00242 if( west != DetId(0) ) {
00243 northwest = navigator.north();
00244 }
00245 navigator.home();
00246
00247 IDH i = sortedHits.find( north.rawId() );
00248 if(i != sortedHits.end() )
00249 rh.add4Neighbour( i->second );
00250
00251 i = sortedHits.find( northeast.rawId() );
00252 if(i != sortedHits.end() )
00253 rh.add8Neighbour( i->second );
00254
00255 i = sortedHits.find( south.rawId() );
00256 if(i != sortedHits.end() )
00257 rh.add4Neighbour( i->second );
00258
00259 i = sortedHits.find( southwest.rawId() );
00260 if(i != sortedHits.end() )
00261 rh.add8Neighbour( i->second );
00262
00263 i = sortedHits.find( east.rawId() );
00264 if(i != sortedHits.end() )
00265 rh.add4Neighbour( i->second );
00266
00267 i = sortedHits.find( southeast.rawId() );
00268 if(i != sortedHits.end() )
00269 rh.add8Neighbour( i->second );
00270
00271 i = sortedHits.find( west.rawId() );
00272 if(i != sortedHits.end() )
00273 rh.add4Neighbour( i->second );
00274
00275 i = sortedHits.find( northwest.rawId() );
00276 if(i != sortedHits.end() )
00277 rh.add8Neighbour( i->second );
00278
00279
00280 }
00281