CMS 3D CMS Logo

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