CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/RecoEcal/EgammaCoreTools/src/SuperClusterShapeAlgo.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 
00003 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00004 #include "RecoEcal/EgammaCoreTools/interface/SuperClusterShapeAlgo.h"
00005 #include "Geometry/EcalAlgo/interface/EcalBarrelGeometry.h"
00006 #include "Geometry/CaloTopology/interface/EcalBarrelTopology.h"
00007 #include "Geometry/CaloTopology/interface/EcalEndcapTopology.h"
00008 #include "Geometry/CaloTopology/interface/EcalPreshowerTopology.h"
00009 
00010 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00011 #include "DataFormats/Math/interface/Point3D.h"
00012 #include "DataFormats/Math/interface/Vector3D.h"
00013 
00014 SuperClusterShapeAlgo::SuperClusterShapeAlgo(const EcalRecHitCollection* hits,
00015                                              const CaloSubdetectorGeometry* geo) : 
00016   recHits_(hits), geometry_(geo) { }
00017 
00018 void SuperClusterShapeAlgo::Calculate_Covariances(const reco::SuperCluster &passedCluster)
00019 {
00020   double numeratorEtaWidth = 0;
00021   double numeratorPhiWidth = 0;
00022 
00023   double scEnergy = passedCluster.energy();
00024   double denominator = scEnergy;
00025 
00026   double scEta    = passedCluster.position().eta();
00027   double scPhi    = passedCluster.position().phi();
00028 
00029   std::vector<std::pair<DetId,float> > detId = passedCluster.hitsAndFractions();
00030   // Loop over recHits associated with the given SuperCluster
00031   for(std::vector<std::pair<DetId,float> >::iterator hit = detId.begin();
00032       hit != detId.end(); ++hit) {
00033     EcalRecHitCollection::const_iterator rHit = recHits_->find((*hit).first);
00034  //FIXME: THIS IS JUST A WORKAROUND A FIX SHOULD BE APPLIED  
00035  if(rHit == recHits_->end()) {
00036     continue; 
00037    }
00038     const CaloCellGeometry *this_cell = geometry_->getGeometry(rHit->id());
00039     if ( this_cell == 0 ) {
00040       //edm::LogInfo("SuperClusterShapeAlgo") << "pointer to the cell in Calculate_Covariances is NULL!";
00041       continue;
00042     }
00043     GlobalPoint position = this_cell->getPosition();
00044     double energyHit = rHit->energy();
00045     
00046     //form differences
00047     double dPhi = position.phi() - scPhi;
00048     if (dPhi > + Geom::pi()) { dPhi = Geom::twoPi() - dPhi; }
00049     if (dPhi < - Geom::pi()) { dPhi = Geom::twoPi() + dPhi; }
00050 
00051     double dEta = position.eta() - scEta;
00052 
00053     if ( energyHit > 0 ) {
00054       numeratorEtaWidth += energyHit * dEta * dEta;
00055       numeratorPhiWidth += energyHit * dPhi * dPhi;
00056     }
00057       
00058     etaWidth_ = sqrt(numeratorEtaWidth / denominator);
00059     phiWidth_ = sqrt(numeratorPhiWidth / denominator);
00060   }
00061 }