CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
hgcal::ClusterTools Class Reference

#include <ClusterTools.h>

Public Member Functions

 ClusterTools ()
 
 ClusterTools (const edm::ParameterSet &, edm::ConsumesCollector &)
 
float getClusterHadronFraction (const reco::CaloCluster &) const
 
void getEvent (const edm::Event &)
 
void getEventSetup (const edm::EventSetup &)
 
int getLayer (const DetId) const
 
double getMultiClusterEnergy (const reco::HGCalMultiCluster &) const
 
math::XYZPoint getMultiClusterPosition (const reco::HGCalMultiCluster &) const
 
bool getWidths (const reco::CaloCluster &clus, double &sigmaetaeta, double &sigmaphiphi, double &sigmaetaetalog, double &sigmaphiphilog) const
 
 ~ClusterTools ()
 

Private Member Functions

std::vector< size_t > sort_by_z (const reco::HGCalMultiCluster &v) const
 

Private Attributes

const HGCRecHitCollectionbhrh_
 
const edm::EDGetTokenT< HGCRecHitCollectionbhtok
 
const HGCRecHitCollectioneerh_
 
const edm::EDGetTokenT< HGCRecHitCollectioneetok
 
const HGCRecHitCollectionfhrh_
 
const edm::EDGetTokenT< HGCRecHitCollectionfhtok
 
RecHitTools rhtools_
 

Detailed Description

Definition at line 26 of file ClusterTools.h.

Constructor & Destructor Documentation

◆ ClusterTools() [1/2]

ClusterTools::ClusterTools ( )

Definition at line 21 of file ClusterTools.cc.

21 {}

◆ ClusterTools() [2/2]

ClusterTools::ClusterTools ( const edm::ParameterSet conf,
edm::ConsumesCollector sumes 
)

Definition at line 23 of file ClusterTools.cc.

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"))) {}

◆ ~ClusterTools()

hgcal::ClusterTools::~ClusterTools ( )
inline

Definition at line 30 of file ClusterTools.h.

30 {}

Member Function Documentation

◆ getClusterHadronFraction()

float ClusterTools::getClusterHadronFraction ( const reco::CaloCluster clus) const

Definition at line 44 of file ClusterTools.cc.

44  {
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 }

References bhrh_, eerh_, HCALHighEnergyHPDFilter_cfi::energy, Exception, f, fhrh_, edm::SortedCollection< T, SORT >::find(), DetId::Forward, HLT_2018_cff::fraction, DetId::Hcal, HcalEndcap, DetId::HGCalEE, DetId::HGCalHSc, DetId::HGCalHSi, HGCEE, HGCHEF, hfClusterShapes_cfi::hits, reco::CaloCluster::hitsAndFractions(), and groupFilesInBlocks::temp.

◆ getEvent()

void ClusterTools::getEvent ( const edm::Event ev)

Definition at line 28 of file ClusterTools.cc.

28  {
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 }

References bhrh_, bhtok, eerh_, eetok, ev, fhrh_, fhtok, and groupFilesInBlocks::temp.

◆ getEventSetup()

void ClusterTools::getEventSetup ( const edm::EventSetup es)

◆ getLayer()

int ClusterTools::getLayer ( const DetId  detid) const

Definition at line 117 of file ClusterTools.cc.

117 { return rhtools_.getLayerWithOffset(detid); }

References hgcal::RecHitTools::getLayerWithOffset(), and rhtools_.

Referenced by getWidths().

◆ getMultiClusterEnergy()

double ClusterTools::getMultiClusterEnergy ( const reco::HGCalMultiCluster clu) const

Definition at line 119 of file ClusterTools.cc.

119  {
120  double acc = 0.0;
121  for (const auto& ptr : clu.clusters()) {
122  acc += ptr->energy();
123  }
124  return acc;
125 }

References reco::HGCalMultiCluster::clusters().

Referenced by getMultiClusterPosition().

◆ getMultiClusterPosition()

math::XYZPoint ClusterTools::getMultiClusterPosition ( const reco::HGCalMultiCluster clu) const

Definition at line 88 of file ClusterTools.cc.

88  {
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 }

References reco::HGCalMultiCluster::clusters(), getMultiClusterEnergy(), and mps_merge::weight.

◆ getWidths()

bool ClusterTools::getWidths ( const reco::CaloCluster clus,
double &  sigmaetaeta,
double &  sigmaphiphi,
double &  sigmaetaetalog,
double &  sigmaphiphilog 
) const

Definition at line 127 of file ClusterTools.cc.

131  {
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 }

References eerh_, CaloRecHit::energy(), reco::CaloCluster::energy(), PV3DBase< T, PVType, FrameType >::eta(), edm::SortedCollection< T, SORT >::find(), dqmdumpme::first, DetId::Forward, getLayer(), hgcal::RecHitTools::getPosition(), DetId::HGCalEE, HGCEE, reco::CaloCluster::hitsAndFractions(), hgcal::RecHitTools::lastLayerEE(), dqm-mbProfile::log, SiStripPI::max, PV3DBase< T, PVType, FrameType >::phi(), reco::CaloCluster::position(), position, rhtools_, edm::second(), mathSSE::sqrt(), and mps_merge::weight.

◆ sort_by_z()

std::vector<size_t> hgcal::ClusterTools::sort_by_z ( const reco::HGCalMultiCluster v) const
inlineprivate

Definition at line 51 of file ClusterTools.h.

51  {
52  std::vector<size_t> idx(v.size());
53  std::iota(std::begin(idx), std::end(idx), 0);
54  sort(
55  idx.begin(), idx.end(), [&v](size_t i1, size_t i2) { return v.clusters()[i1]->z() < v.clusters()[i2]->z(); });
56  return idx;
57  }

References begin, end, testProducerWithPsetDescEmpty_cfi::i1, testProducerWithPsetDescEmpty_cfi::i2, training_settings::idx, and findQualityFiles::v.

Member Data Documentation

◆ bhrh_

const HGCRecHitCollection * hgcal::ClusterTools::bhrh_
private

Definition at line 61 of file ClusterTools.h.

Referenced by getClusterHadronFraction(), and getEvent().

◆ bhtok

const edm::EDGetTokenT<HGCRecHitCollection> hgcal::ClusterTools::bhtok
private

Definition at line 60 of file ClusterTools.h.

Referenced by getEvent().

◆ eerh_

const HGCRecHitCollection* hgcal::ClusterTools::eerh_
private

Definition at line 61 of file ClusterTools.h.

Referenced by getClusterHadronFraction(), getEvent(), and getWidths().

◆ eetok

const edm::EDGetTokenT<HGCRecHitCollection> hgcal::ClusterTools::eetok
private

Definition at line 60 of file ClusterTools.h.

Referenced by getEvent().

◆ fhrh_

const HGCRecHitCollection * hgcal::ClusterTools::fhrh_
private

Definition at line 61 of file ClusterTools.h.

Referenced by getClusterHadronFraction(), and getEvent().

◆ fhtok

const edm::EDGetTokenT<HGCRecHitCollection> hgcal::ClusterTools::fhtok
private

Definition at line 60 of file ClusterTools.h.

Referenced by getEvent().

◆ rhtools_

RecHitTools hgcal::ClusterTools::rhtools_
private

Definition at line 59 of file ClusterTools.h.

Referenced by getEventSetup(), getLayer(), and getWidths().

hgcal::ClusterTools::bhtok
const edm::EDGetTokenT< HGCRecHitCollection > bhtok
Definition: ClusterTools.h:60
testProducerWithPsetDescEmpty_cfi.i2
i2
Definition: testProducerWithPsetDescEmpty_cfi.py:46
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
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
CaloGeometryRecord
Definition: CaloGeometryRecord.h:30
mps_merge.weight
weight
Definition: mps_merge.py:88
DetId::Hcal
Definition: DetId.h:28
testProducerWithPsetDescEmpty_cfi.i1
i1
Definition: testProducerWithPsetDescEmpty_cfi.py:45
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
findQualityFiles.v
v
Definition: findQualityFiles.py:179
hgcal::ClusterTools::rhtools_
RecHitTools rhtools_
Definition: ClusterTools.h:59
edm::Handle
Definition: AssociativeIterator.h:50
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
training_settings.idx
idx
Definition: training_settings.py:16
dqmdumpme.first
first
Definition: dqmdumpme.py:55
end
#define end
Definition: vmac.h:39
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
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
edm::ESHandle< CaloGeometry >
relativeConstraints.geom
geom
Definition: relativeConstraints.py:72
edm::ConsumesCollector::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: ConsumesCollector.h:49
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
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
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
get
#define get
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
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
edm::SortedCollection::find
iterator find(key_type k)
Definition: SortedCollection.h:240
HcalEndcap
Definition: HcalAssistant.h:34
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
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
HGCHEF
Definition: ForwardSubdetector.h:9
DetId::Forward
Definition: DetId.h:30
hgcal::RecHitTools::getPosition
GlobalPoint getPosition(const DetId &id) const
Definition: RecHitTools.cc:126
reco::CaloCluster::energy
double energy() const
cluster energy
Definition: CaloCluster.h:149
HLT_2018_cff.fraction
fraction
Definition: HLT_2018_cff.py:51317
edm::InputTag
Definition: InputTag.h:15
begin
#define begin
Definition: vmac.h:32
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