Go to the documentation of this file.00001 #include "RecoParticleFlow/PFClusterTools/interface/PFClusterWidthAlgo.h"
00002 #include "DataFormats/ParticleFlowReco/interface/PFRecHitFraction.h"
00003 #include "DataFormats/ParticleFlowReco/interface/PFRecHitFwd.h"
00004 #include "DataFormats/ParticleFlowReco/interface/PFRecHit.h"
00005 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00006 #include "TMath.h"
00007 #include <algorithm>
00008 using namespace std;
00009 using namespace reco;
00010
00011
00012
00013 PFClusterWidthAlgo::PFClusterWidthAlgo(const std::vector<const reco::PFCluster *>& pfclust,
00014 const EBRecHitCollection * ebRecHits,
00015 const EERecHitCollection * eeRecHits){
00016
00017
00018 double numeratorEtaWidth = 0.;
00019 double numeratorPhiWidth = 0.;
00020 double sclusterE = 0.;
00021 double posX = 0.;
00022 double posY = 0.;
00023 double posZ = 0.;
00024 sigmaEtaEta_ = 0.;
00025
00026 unsigned int nclust= pfclust.size();
00027 if(nclust == 0 ) {
00028 etaWidth_ = 0.;
00029 phiWidth_ = 0.;
00030 sigmaEtaEta_ = 0.;
00031 }
00032 else {
00033
00034 for(unsigned int icl=0;icl<nclust;++icl) {
00035 double e = pfclust[icl]->energy();
00036 sclusterE += e;
00037 posX += e * pfclust[icl]->position().X();
00038 posY += e * pfclust[icl]->position().Y();
00039 posZ += e * pfclust[icl]->position().Z();
00040 }
00041
00042 posX /=sclusterE;
00043 posY /=sclusterE;
00044 posZ /=sclusterE;
00045
00046 double denominator = sclusterE;
00047
00048 math::XYZPoint pflowSCPos(posX,posY,posZ);
00049
00050 double scEta = pflowSCPos.eta();
00051 double scPhi = pflowSCPos.phi();
00052
00053 double SeedClusEnergy = -1.;
00054 unsigned int SeedDetID = 0;
00055 double SeedEta = -1.;
00056 double SeedPhi = -1.;
00057
00058 for(unsigned int icl=0; icl<nclust; ++icl) {
00059 const std::vector< reco::PFRecHitFraction >& PFRecHits = pfclust[icl]->recHitFractions();
00060
00061
00062 for ( std::vector< reco::PFRecHitFraction >::const_iterator it = PFRecHits.begin();
00063 it != PFRecHits.end(); ++it) {
00064 const PFRecHitRef& RefPFRecHit = it->recHitRef();
00065 double energyHit=0;
00066
00067
00068 if(ebRecHits && eeRecHits )
00069 {
00070
00071 unsigned index=it-PFRecHits.begin();
00072 DetId id=pfclust[icl]->hitsAndFractions()[index].first;
00073
00074 if(id.det()==DetId::Ecal && id.subdetId()==EcalBarrel)
00075 {
00076 EBRecHitCollection::const_iterator itcheck=ebRecHits->find(id);
00077 if(itcheck!=ebRecHits->end())
00078 energyHit= itcheck->energy();
00079
00080
00081 }
00082 if(id.det()==DetId::Ecal && id.subdetId()==EcalEndcap)
00083 {
00084 EERecHitCollection::const_iterator itcheck=eeRecHits->find(id);
00085 if(itcheck!=eeRecHits->end())
00086 energyHit= itcheck->energy();
00087
00088
00089 }
00090 }
00091 else
00092 energyHit = RefPFRecHit->energy();
00093
00094
00095 if(icl==0) {
00096 if (energyHit > SeedClusEnergy) {
00097 SeedClusEnergy = energyHit;
00098 SeedEta = RefPFRecHit->position().eta();
00099 SeedPhi = RefPFRecHit->position().phi();
00100 SeedDetID = RefPFRecHit->detId();
00101 }
00102 }
00103
00104
00105 double dPhi = RefPFRecHit->position().phi() - scPhi;
00106 if (dPhi > + TMath::Pi()) { dPhi = TMath::TwoPi() - dPhi; }
00107 if (dPhi < - TMath::Pi()) { dPhi = TMath::TwoPi() + dPhi; }
00108 double dEta = RefPFRecHit->position().eta() - scEta;
00109 if ( energyHit > 0 ) {
00110 numeratorEtaWidth += energyHit * dEta * dEta;
00111 numeratorPhiWidth += energyHit * dPhi * dPhi;
00112 }
00113 }
00114 }
00115
00116
00117 const std::vector< reco::PFRecHitFraction >& PFRecHits = pfclust[0]->recHitFractions();
00118 for ( std::vector< reco::PFRecHitFraction >::const_iterator it = PFRecHits.begin();
00119 it != PFRecHits.end(); ++it) {
00120 const PFRecHitRef& RefPFRecHit = it->recHitRef();
00121 if(!RefPFRecHit.isAvailable())
00122 return;
00123 double energyHit = RefPFRecHit->energy();
00124 if (RefPFRecHit->detId() != SeedDetID) {
00125 float diffEta = RefPFRecHit->position().eta() - SeedEta;
00126 sigmaEtaEta_ += (diffEta*diffEta) * (energyHit/SeedClusEnergy);
00127 }
00128 }
00129 if (sigmaEtaEta_ == 0.) sigmaEtaEta_ = 0.00000001;
00130
00131 etaWidth_ = sqrt(numeratorEtaWidth / denominator);
00132 phiWidth_ = sqrt(numeratorPhiWidth / denominator);
00133
00134
00135 }
00136 }
00137 PFClusterWidthAlgo::~PFClusterWidthAlgo()
00138 {
00139 }