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
00057 for(unsigned int icl=0; icl<nclust; ++icl) {
00058 const std::vector< reco::PFRecHitFraction >& PFRecHits = pfclust[icl]->recHitFractions();
00059
00060
00061 for ( std::vector< reco::PFRecHitFraction >::const_iterator it = PFRecHits.begin();
00062 it != PFRecHits.end(); ++it) {
00063 const PFRecHitRef& RefPFRecHit = it->recHitRef();
00064 double energyHit=0;
00065
00066
00067 if(ebRecHits && eeRecHits )
00068 {
00069
00070 unsigned index=it-PFRecHits.begin();
00071 DetId id=pfclust[icl]->hitsAndFractions()[index].first;
00072
00073 if(id.det()==DetId::Ecal && id.subdetId()==EcalBarrel)
00074 {
00075 EBRecHitCollection::const_iterator itcheck=ebRecHits->find(id);
00076 if(itcheck!=ebRecHits->end())
00077 energyHit= itcheck->energy();
00078
00079
00080 }
00081 if(id.det()==DetId::Ecal && id.subdetId()==EcalEndcap)
00082 {
00083 EERecHitCollection::const_iterator itcheck=eeRecHits->find(id);
00084 if(itcheck!=eeRecHits->end())
00085 energyHit= itcheck->energy();
00086
00087
00088 }
00089 }
00090 else
00091 energyHit = RefPFRecHit->energy();
00092
00093
00094 if(icl==0) {
00095 if (energyHit > SeedClusEnergy) {
00096 SeedClusEnergy = energyHit;
00097 SeedEta = RefPFRecHit->position().eta();
00098 SeedDetID = RefPFRecHit->detId();
00099 }
00100 }
00101
00102
00103 double dPhi = RefPFRecHit->position().phi() - scPhi;
00104 if (dPhi > + TMath::Pi()) { dPhi = TMath::TwoPi() - dPhi; }
00105 if (dPhi < - TMath::Pi()) { dPhi = TMath::TwoPi() + dPhi; }
00106 double dEta = RefPFRecHit->position().eta() - scEta;
00107 if ( energyHit > 0 ) {
00108 numeratorEtaWidth += energyHit * dEta * dEta;
00109 numeratorPhiWidth += energyHit * dPhi * dPhi;
00110 }
00111 }
00112 }
00113
00114
00115 const std::vector< reco::PFRecHitFraction >& PFRecHits = pfclust[0]->recHitFractions();
00116 for ( std::vector< reco::PFRecHitFraction >::const_iterator it = PFRecHits.begin();
00117 it != PFRecHits.end(); ++it) {
00118 const PFRecHitRef& RefPFRecHit = it->recHitRef();
00119 if(!RefPFRecHit.isAvailable())
00120 return;
00121 double energyHit = RefPFRecHit->energy();
00122 if (RefPFRecHit->detId() != SeedDetID) {
00123 float diffEta = RefPFRecHit->position().eta() - SeedEta;
00124 sigmaEtaEta_ += (diffEta*diffEta) * (energyHit/SeedClusEnergy);
00125 }
00126 }
00127 if (sigmaEtaEta_ == 0.) sigmaEtaEta_ = 0.00000001;
00128
00129 etaWidth_ = sqrt(numeratorEtaWidth / denominator);
00130 phiWidth_ = sqrt(numeratorPhiWidth / denominator);
00131
00132
00133 }
00134 }
00135 PFClusterWidthAlgo::~PFClusterWidthAlgo()
00136 {
00137 }