CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/RecoParticleFlow/PFClusterProducer/plugins/PFRecHitProducerPS.cc

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   // access to the collections of rechits
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   // get the ps geometry
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   // ShR 28 Jul 2008: check if geometry is NULL. If so we are using
00067   // partial CMS gemoetry in Pilot1/2 scenarios which do not include the preshower
00068   if(!psGeometry) {
00069     LogDebug("PFRecHitProducerPS") << "No EcalPreshower geometry available. putting empty PS rechits collection in event";
00070     return;
00071   }
00072 
00073 
00074   // get the ps topology
00075   EcalPreshowerTopology psTopology(geoHandle);
00076 
00077   // process rechits
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       // if( !pfrh ) continue; // problem with this rechit. skip it
00147 
00148       rechits.push_back( *pfrh );
00149       delete pfrh;
00150       idSortedRecHits.insert( make_pair(detid.rawId(), rechits.size()-1 ) );   
00151     }
00152   }
00153 
00154   // do navigation
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   const CaloSubdetectorGeometry* othergeometry = 0;
00181   
00182   switch( rh.layer() ) {
00183   case PFLayer::ECAL_ENDCAP: 
00184     topology = &endcapTopology;
00185     geometry = &endcapGeometry;
00186     break;
00187   case PFLayer::ECAL_BARREL: 
00188     topology = &barrelTopology;
00189     geometry = &barrelGeometry;
00190     break;
00191   case PFLayer::HCAL_ENDCAP:
00192     topology = &endcapTopology;
00193     geometry = &endcapGeometry;
00194     othergeometry = &barrelGeometry;
00195     break;
00196   case PFLayer::HCAL_BARREL1:
00197     topology = &barrelTopology;
00198     geometry = &barrelGeometry;
00199     othergeometry = &endcapGeometry;
00200     break;
00201   case PFLayer::PS1:
00202   case PFLayer::PS2:
00203     topology = &barrelTopology;
00204     geometry = &barrelGeometry;
00205     othergeometry = &endcapGeometry;
00206     break;
00207   default:
00208     assert(0);
00209   }
00210   
00211   assert( topology && geometry );
00212 
00213   CaloNavigator<DetId> navigator(detid, topology);
00214 
00215   DetId north = navigator.north();  
00216   
00217   DetId northeast(0);
00218   if( north != DetId(0) ) {
00219     northeast = navigator.east();  
00220   }
00221   navigator.home();
00222 
00223 
00224   DetId south = navigator.south();
00225 
00226   
00227 
00228   DetId southwest(0); 
00229   if( south != DetId(0) ) {
00230     southwest = navigator.west();
00231   }
00232   navigator.home();
00233 
00234 
00235   DetId east = navigator.east();
00236   DetId southeast;
00237   if( east != DetId(0) ) {
00238     southeast = navigator.south(); 
00239   }
00240   navigator.home();
00241   DetId west = navigator.west();
00242   DetId northwest;
00243   if( west != DetId(0) ) {   
00244     northwest = navigator.north();  
00245   }
00246   navigator.home();
00247     
00248   IDH i = sortedHits.find( north.rawId() );
00249   if(i != sortedHits.end() ) 
00250     rh.add4Neighbour( i->second );
00251   
00252   i = sortedHits.find( northeast.rawId() );
00253   if(i != sortedHits.end() ) 
00254     rh.add8Neighbour( i->second );
00255   
00256   i = sortedHits.find( south.rawId() );
00257   if(i != sortedHits.end() ) 
00258     rh.add4Neighbour( i->second );
00259     
00260   i = sortedHits.find( southwest.rawId() );
00261   if(i != sortedHits.end() ) 
00262     rh.add8Neighbour( i->second );
00263     
00264   i = sortedHits.find( east.rawId() );
00265   if(i != sortedHits.end() ) 
00266     rh.add4Neighbour( i->second );
00267     
00268   i = sortedHits.find( southeast.rawId() );
00269   if(i != sortedHits.end() ) 
00270     rh.add8Neighbour( i->second );
00271     
00272   i = sortedHits.find( west.rawId() );
00273   if(i != sortedHits.end() ) 
00274      rh.add4Neighbour( i->second );
00275    
00276   i = sortedHits.find( northwest.rawId() );
00277   if(i != sortedHits.end() ) 
00278     rh.add8Neighbour( i->second );
00279     
00280 
00281 }
00282