test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFClusterWidthAlgo.cc
Go to the documentation of this file.
7 #include "TMath.h"
8 #include <algorithm>
9 using namespace std;
10 using namespace reco;
11 
12 
13 
14 PFClusterWidthAlgo::PFClusterWidthAlgo(const std::vector<const reco::PFCluster *>& pfclust) {
15 
16 
17  double numeratorEtaWidth = 0.;
18  double numeratorPhiWidth = 0.;
19  double sclusterE = 0.;
20  double posX = 0.;
21  double posY = 0.;
22  double posZ = 0.;
23  sigmaEtaEta_ = 0.;
24 
25  unsigned int nclust= pfclust.size();
26  if(nclust == 0 ) {
27  etaWidth_ = 0.;
28  phiWidth_ = 0.;
29  sigmaEtaEta_ = 0.;
30  }
31  else {
32 
33  //first loop, compute supercluster position at ecal face, and energy sum from rechit loop
34  //in order to be consistent with variance calculation
35  for(unsigned int icl=0; icl<nclust; ++icl) {
36  const std::vector< reco::PFRecHitFraction >& PFRecHits = pfclust[icl]->recHitFractions();
37 
38  for ( std::vector< reco::PFRecHitFraction >::const_iterator it = PFRecHits.begin();
39  it != PFRecHits.end(); ++it) {
40  const PFRecHitRef& RefPFRecHit = it->recHitRef();
41  //compute rechit energy taking into account fractions
42  double energyHit = RefPFRecHit->energy()*it->fraction();
43 
44  sclusterE += energyHit;
45  posX += energyHit*RefPFRecHit->position().x();
46  posY += energyHit*RefPFRecHit->position().y();
47  posZ += energyHit*RefPFRecHit->position().z();
48 
49  }
50  } // end for ncluster
51 
52  double denominator = sclusterE;
53 
54  posX /=sclusterE;
55  posY /=sclusterE;
56  posZ /=sclusterE;
57 
58  math::XYZPoint pflowSCPos(posX,posY,posZ);
59 
60  double scEta = pflowSCPos.eta();
61  double scPhi = pflowSCPos.phi();
62 
63  double SeedClusEnergy = -1.;
64  unsigned int SeedDetID = 0;
65  double SeedEta = -1.;
66 
67  //second loop, compute variances
68  for(unsigned int icl=0; icl<nclust; ++icl) {
69  const auto & PFRecHits = pfclust[icl]->recHitFractions();
70 
71  for ( auto it = PFRecHits.begin();
72  it != PFRecHits.end(); ++it) {
73  const PFRecHitRef& RefPFRecHit = it->recHitRef();
74  //compute rechit energy taking into account fractions
75  double energyHit = RefPFRecHit->energy()*it->fraction();
76 
77  //only for the first cluster (from GSF) find the seed
78  if(icl==0) {
79  if (energyHit > SeedClusEnergy) {
80  SeedClusEnergy = energyHit;
81  SeedEta = RefPFRecHit->position().eta();
82  SeedDetID = RefPFRecHit->detId();
83  }
84  }
85 
86  double dPhi = reco::deltaPhi(RefPFRecHit->positionREP().phi(),scPhi);
87  double dEta = RefPFRecHit->positionREP().eta() - scEta;
88  numeratorEtaWidth += energyHit * dEta * dEta;
89  numeratorPhiWidth += energyHit * dPhi * dPhi;
90  }
91  } // end for ncluster
92 
93  //for the first cluster (from GSF) computed sigmaEtaEta
94  const auto & PFRecHits = pfclust[0]->recHitFractions();
95  for ( auto it = PFRecHits.begin();
96  it != PFRecHits.end(); ++it) {
97  const auto & RefPFRecHit = it->recHitRef();
98  if(!RefPFRecHit.isAvailable())
99  return;
100  double energyHit = RefPFRecHit->energy();
101  if (RefPFRecHit->detId() != SeedDetID) {
102  float diffEta = RefPFRecHit->positionREP().eta() - SeedEta;
103  sigmaEtaEta_ += (diffEta*diffEta) * (energyHit/SeedClusEnergy);
104  }
105  }
106  if (sigmaEtaEta_ == 0.) sigmaEtaEta_ = 0.00000001;
107 
108  etaWidth_ = std::sqrt(numeratorEtaWidth / denominator);
109  phiWidth_ = std::sqrt(numeratorPhiWidth / denominator);
110 
111 
112  } // endif ncluster > 0
113 }
115 {
116 }
list denominator
Definition: cuy.py:484
double dPhi(double phi1, double phi2)
Definition: JetUtil.h:30
T sqrt(T t)
Definition: SSEVec.h:18
double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:22
PFClusterWidthAlgo(const std::vector< const reco::PFCluster * > &pfclust)
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12