CMS 3D CMS Logo

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