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