CMS 3D CMS Logo

ClusterTools.cc
Go to the documentation of this file.
2 
8 
10 
14 
15 #include "vdt/vdtMath.h"
16 
17 #include <iostream>
18 
19 using namespace hgcal;
21 
23  : eetok(sumes.consumes<HGCRecHitCollection>(conf.getParameter<edm::InputTag>("HGCEEInput"))),
24  fhtok(sumes.consumes<HGCRecHitCollection>(conf.getParameter<edm::InputTag>("HGCFHInput"))),
25  bhtok(sumes.consumes<HGCRecHitCollection>(conf.getParameter<edm::InputTag>("HGCBHInput"))) {}
26 
28  rhtools_.getEvent(ev);
30  ev.getByToken(eetok, temp);
31  eerh_ = temp.product();
32  ev.getByToken(fhtok, temp);
33  fhrh_ = temp.product();
34  ev.getByToken(bhtok, temp);
35  bhrh_ = temp.product();
36 }
37 
39 
41  float energy = 0.f, energyHad = 0.f;
42  const auto& hits = clus.hitsAndFractions();
43  for (const auto& hit : hits) {
44  const auto& id = hit.first;
45  const float fraction = hit.second;
46  if (id.det() == DetId::HGCalEE) {
47  energy += eerh_->find(id)->energy() * fraction;
48  } else if (id.det() == DetId::HGCalHSi) {
49  const float temp = fhrh_->find(id)->energy();
50  energy += temp * fraction;
51  energyHad += temp * fraction;
52  } else if (id.det() == DetId::HGCalHSc) {
53  const float temp = bhrh_->find(id)->energy();
54  energy += temp * fraction;
55  energyHad += temp * fraction;
56  } else if (id.det() == DetId::Forward) {
57  switch (id.subdetId()) {
58  case HGCEE:
59  energy += eerh_->find(id)->energy() * fraction;
60  break;
61  case HGCHEF: {
62  const float temp = fhrh_->find(id)->energy();
63  energy += temp * fraction;
64  energyHad += temp * fraction;
65  } break;
66  default:
67  throw cms::Exception("HGCalClusterTools") << " Cluster contains hits that are not from HGCal! " << std::endl;
68  }
69  } else if (id.det() == DetId::Hcal && id.subdetId() == HcalEndcap) {
70  const float temp = bhrh_->find(id)->energy();
71  energy += temp * fraction;
72  energyHad += temp * fraction;
73  } else {
74  throw cms::Exception("HGCalClusterTools") << " Cluster contains hits that are not from HGCal! " << std::endl;
75  }
76  }
77  float fraction = -1.f;
78  if (energy > 0.f) {
79  fraction = energyHad / energy;
80  }
81  return fraction;
82 }
83 
85  if (clu.clusters().empty())
86  return math::XYZPoint();
87 
88  double acc_x = 0.0;
89  double acc_y = 0.0;
90  double acc_z = 0.0;
91  double totweight = 0.;
92  double mcenergy = getMultiClusterEnergy(clu);
93  for (const auto& ptr : clu.clusters()) {
94  if (mcenergy != 0) {
95  if (ptr->energy() < .01 * mcenergy)
96  continue; //cutoff < 1% layer contribution
97  }
98  const double weight = ptr->energy(); // weigth each corrdinate only by the total energy of the layer cluster
99  acc_x += ptr->x() * weight;
100  acc_y += ptr->y() * weight;
101  acc_z += ptr->z() * weight;
102  totweight += weight;
103  }
104  if (totweight != 0) {
105  acc_x /= totweight;
106  acc_y /= totweight;
107  acc_z /= totweight;
108  }
109  // return x/y/z in absolute coordinates
110  return math::XYZPoint(acc_x, acc_y, acc_z);
111 }
112 
113 int ClusterTools::getLayer(const DetId detid) const { return rhtools_.getLayerWithOffset(detid); }
114 
116  double acc = 0.0;
117  for (const auto& ptr : clu.clusters()) {
118  acc += ptr->energy();
119  }
120  return acc;
121 }
122 
124  double& sigmaetaeta,
125  double& sigmaphiphi,
126  double& sigmaetaetal,
127  double& sigmaphiphil) const {
128  if (getLayer(clus.hitsAndFractions()[0].first) > (int)rhtools_.lastLayerEE())
129  return false;
130  const math::XYZPoint& position(clus.position());
131  unsigned nhit = clus.hitsAndFractions().size();
132 
133  sigmaetaeta = 0.;
134  sigmaphiphi = 0.;
135  sigmaetaetal = 0.;
136  sigmaphiphil = 0.;
137 
138  double sumw = 0.;
139  double sumlogw = 0.;
140 
141  for (unsigned int ih = 0; ih < nhit; ++ih) {
142  const DetId& id = (clus.hitsAndFractions())[ih].first;
143  if ((clus.hitsAndFractions())[ih].second == 0.)
144  continue;
145 
146  if ((id.det() == DetId::HGCalEE) || (id.det() == DetId::Forward && id.subdetId() == HGCEE)) {
147  const HGCRecHit* theHit = &(*eerh_->find(id));
148 
149  GlobalPoint cellPos = rhtools_.getPosition(id);
150  double weight = theHit->energy();
151  // take w0=2 To be optimized
152  double logweight = 0;
153  if (clus.energy() != 0) {
154  logweight = std::max(0., 2 + log(theHit->energy() / clus.energy()));
155  }
156  double deltaetaeta2 = (cellPos.eta() - position.eta()) * (cellPos.eta() - position.eta());
157  double deltaphiphi2 = (cellPos.phi() - position.phi()) * (cellPos.phi() - position.phi());
158  sigmaetaeta += deltaetaeta2 * weight;
159  sigmaphiphi += deltaphiphi2 * weight;
160  sigmaetaetal += deltaetaeta2 * logweight;
161  sigmaphiphil += deltaphiphi2 * logweight;
162  sumw += weight;
163  sumlogw += logweight;
164  }
165  }
166 
167  if (sumw <= 0.)
168  return false;
169 
170  sigmaetaeta /= sumw;
171  sigmaetaeta = std::sqrt(sigmaetaeta);
172  sigmaphiphi /= sumw;
173  sigmaphiphi = std::sqrt(sigmaphiphi);
174 
175  if (sumlogw != 0) {
176  sigmaetaetal /= sumlogw;
177  sigmaetaetal = std::sqrt(sigmaetaetal);
178  sigmaphiphil /= sumlogw;
179  sigmaphiphil = std::sqrt(sigmaphiphil);
180  }
181 
182  return true;
183 }
constexpr float energy() const
Definition: CaloRecHit.h:29
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:153
void getEvent(const edm::Event &)
Definition: RecHitTools.cc:68
void getEvent(const edm::Event &)
Definition: ClusterTools.cc:27
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
Definition: weight.py:1
bool ev
math::XYZPoint getMultiClusterPosition(const reco::HGCalMultiCluster &) const
Definition: ClusterTools.cc:84
void getEventSetup(const edm::EventSetup &)
Definition: RecHitTools.cc:70
U second(std::pair< T, U > const &p)
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:209
RecHitTools rhtools_
Definition: ClusterTools.h:59
const edm::PtrVector< reco::BasicCluster > & clusters() const
T sqrt(T t)
Definition: SSEVec.h:19
double f[11][100]
double energy() const
cluster energy
Definition: CaloCluster.h:148
int getLayer(const DetId) const
unsigned int lastLayerEE() const
Definition: RecHitTools.h:62
const HGCRecHitCollection * eerh_
Definition: ClusterTools.h:61
Definition: DetId.h:17
double getMultiClusterEnergy(const reco::HGCalMultiCluster &) const
unsigned int getLayerWithOffset(const DetId &) const
Definition: RecHitTools.cc:355
T const * product() const
Definition: Handle.h:69
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
GlobalPoint getPosition(const DetId &id) const
Definition: RecHitTools.cc:129
float getClusterHadronFraction(const reco::CaloCluster &) const
Definition: ClusterTools.cc:40
const edm::EDGetTokenT< HGCRecHitCollection > fhtok
Definition: ClusterTools.h:60
T eta() const
Definition: PV3DBase.h:73
const edm::EDGetTokenT< HGCRecHitCollection > eetok
Definition: ClusterTools.h:60
iterator find(key_type k)
const HGCRecHitCollection * bhrh_
Definition: ClusterTools.h:61
HLT enums.
static int position[264][3]
Definition: ReadPGInfo.cc:289
const edm::EDGetTokenT< HGCRecHitCollection > bhtok
Definition: ClusterTools.h:60
bool getWidths(const reco::CaloCluster &clus, double &sigmaetaeta, double &sigmaphiphi, double &sigmaetaetalog, double &sigmaphiphilog) const
const HGCRecHitCollection * fhrh_
Definition: ClusterTools.h:61
void getEventSetup(const edm::EventSetup &)
Definition: ClusterTools.cc:38