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 edm::ESGetToken< CaloGeometry, CaloGeometryRecordcaloGeometryToken_
 
const HGCRecHitCollectioneerh_
 
const edm::EDGetTokenT< HGCRecHitCollectioneetok
 
const HGCRecHitCollectionfhrh_
 
const edm::EDGetTokenT< HGCRecHitCollectionfhtok
 
const std::unordered_map< DetId, const unsigned int > * hitMap_
 
const edm::EDGetTokenT< std::unordered_map< DetId, const unsigned int > > hitMapToken_
 
std::unique_ptr< MultiVectorManager< HGCRecHit > > rechitManager_
 
RecHitTools rhtools_
 

Detailed Description

Definition at line 30 of file ClusterTools.h.

Constructor & Destructor Documentation

◆ ClusterTools() [1/2]

ClusterTools::ClusterTools ( )

Definition at line 19 of file ClusterTools.cc.

19 {}

◆ ClusterTools() [2/2]

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

Definition at line 21 of file ClusterTools.cc.

References edm::ConsumesCollector::esConsumes().

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()} {}
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::vector< HGCRecHit > HGCRecHitCollection
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
Definition: ClusterTools.h:66
const edm::EDGetTokenT< std::unordered_map< DetId, const unsigned int > > hitMapToken_
Definition: ClusterTools.h:65
const edm::EDGetTokenT< HGCRecHitCollection > fhtok
Definition: ClusterTools.h:64
const edm::EDGetTokenT< HGCRecHitCollection > eetok
Definition: ClusterTools.h:64
const edm::EDGetTokenT< HGCRecHitCollection > bhtok
Definition: ClusterTools.h:64

◆ ~ClusterTools()

hgcal::ClusterTools::~ClusterTools ( )
inline

Definition at line 34 of file ClusterTools.h.

34 {}

Member Function Documentation

◆ getClusterHadronFraction()

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

Definition at line 42 of file ClusterTools.cc.

References HBHEDarkening_cff::energy, f, DetId::Forward, HLT_2024v14_cff::fraction, DetId::Hcal, HcalEndcap, DetId::HGCalHSc, DetId::HGCalHSi, HGCHEF, hitMap_, hfClusterShapes_cfi::hits, reco::CaloCluster::hitsAndFractions(), nano_mu_digi_cff::rawId, and rechitManager_.

42  {
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 }
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:210
double f[11][100]
hitCont::const_iterator hitIter
const std::unordered_map< DetId, const unsigned int > * hitMap_
Definition: ClusterTools.h:69
std::unique_ptr< MultiVectorManager< HGCRecHit > > rechitManager_
Definition: ClusterTools.h:70

◆ getEvent()

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

Definition at line 29 of file ClusterTools.cc.

References bhrh_, bhtok, eerh_, eetok, makeMEIFBenchmarkPlots::ev, fhrh_, fhtok, hitMap_, hitMapToken_, and rechitManager_.

29  {
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 }
const edm::EDGetTokenT< std::unordered_map< DetId, const unsigned int > > hitMapToken_
Definition: ClusterTools.h:65
const HGCRecHitCollection * eerh_
Definition: ClusterTools.h:68
const std::unordered_map< DetId, const unsigned int > * hitMap_
Definition: ClusterTools.h:69
const edm::EDGetTokenT< HGCRecHitCollection > fhtok
Definition: ClusterTools.h:64
const edm::EDGetTokenT< HGCRecHitCollection > eetok
Definition: ClusterTools.h:64
const HGCRecHitCollection * bhrh_
Definition: ClusterTools.h:68
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

◆ getEventSetup()

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

Definition at line 40 of file ClusterTools.cc.

References caloGeometryToken_, edm::EventSetup::getData(), rhtools_, and hgcal::RecHitTools::setGeometry().

T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
Definition: ClusterTools.h:66
RecHitTools rhtools_
Definition: ClusterTools.h:63
void setGeometry(CaloGeometry const &)
Definition: RecHitTools.cc:79

◆ getLayer()

int ClusterTools::getLayer ( const DetId  detid) const

◆ getMultiClusterEnergy()

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

Definition at line 100 of file ClusterTools.cc.

References reco::HGCalMultiCluster::clusters().

Referenced by getMultiClusterPosition().

100  {
101  double acc = 0.0;
102  for (const auto& ptr : clu.clusters()) {
103  acc += ptr->energy();
104  }
105  return acc;
106 }
const edm::PtrVector< reco::BasicCluster > & clusters() const

◆ getMultiClusterPosition()

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

Definition at line 69 of file ClusterTools.cc.

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

69  {
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 }
double getMultiClusterEnergy(const reco::HGCalMultiCluster &) const
Definition: weight.py:1
const edm::PtrVector< reco::BasicCluster > & clusters() const
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12

◆ getWidths()

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

Definition at line 108 of file ClusterTools.cc.

References reco::CaloCluster::energy(), PV3DBase< T, PVType, FrameType >::eta(), dqmdumpme::first, DetId::Forward, getLayer(), hgcal::RecHitTools::getPosition(), DetId::HGCalEE, HGCEE, hitMap_, reco::CaloCluster::hitsAndFractions(), hgcal::RecHitTools::lastLayerEE(), CrabHelper::log, WZElectronSkims53X_cff::max, PV3DBase< T, PVType, FrameType >::phi(), reco::CaloCluster::position(), position, nano_mu_digi_cff::rawId, rechitManager_, rhtools_, edm::second(), mathSSE::sqrt(), and mps_merge::weight.

112  {
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
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:210
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
T eta() const
Definition: PV3DBase.h:73
Definition: weight.py:1
int getLayer(const DetId) const
Definition: ClusterTools.cc:98
U second(std::pair< T, U > const &p)
RecHitTools rhtools_
Definition: ClusterTools.h:63
GlobalPoint getPosition(const DetId &id) const
Definition: RecHitTools.cc:140
T sqrt(T t)
Definition: SSEVec.h:23
double energy() const
cluster energy
Definition: CaloCluster.h:149
Definition: DetId.h:17
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
static int position[264][3]
Definition: ReadPGInfo.cc:289
std::unique_ptr< MultiVectorManager< HGCRecHit > > rechitManager_
Definition: ClusterTools.h:70
unsigned int lastLayerEE(bool nose=false) const
Definition: RecHitTools.h:76

◆ sort_by_z()

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

Definition at line 55 of file ClusterTools.h.

References testProducerWithPsetDescEmpty_cfi::i1, testProducerWithPsetDescEmpty_cfi::i2, heavyIonCSV_trainingSettings::idx, jetUpdater_cfi::sort, and findQualityFiles::v.

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

Member Data Documentation

◆ bhrh_

const HGCRecHitCollection * hgcal::ClusterTools::bhrh_
private

Definition at line 68 of file ClusterTools.h.

Referenced by getEvent().

◆ bhtok

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

Definition at line 64 of file ClusterTools.h.

Referenced by getEvent().

◆ caloGeometryToken_

const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> hgcal::ClusterTools::caloGeometryToken_
private

Definition at line 66 of file ClusterTools.h.

Referenced by getEventSetup().

◆ eerh_

const HGCRecHitCollection* hgcal::ClusterTools::eerh_
private

Definition at line 68 of file ClusterTools.h.

Referenced by getEvent().

◆ eetok

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

Definition at line 64 of file ClusterTools.h.

Referenced by getEvent().

◆ fhrh_

const HGCRecHitCollection * hgcal::ClusterTools::fhrh_
private

Definition at line 68 of file ClusterTools.h.

Referenced by getEvent().

◆ fhtok

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

Definition at line 64 of file ClusterTools.h.

Referenced by getEvent().

◆ hitMap_

const std::unordered_map<DetId, const unsigned int>* hgcal::ClusterTools::hitMap_
private

Definition at line 69 of file ClusterTools.h.

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

◆ hitMapToken_

const edm::EDGetTokenT<std::unordered_map<DetId, const unsigned int> > hgcal::ClusterTools::hitMapToken_
private

Definition at line 65 of file ClusterTools.h.

Referenced by getEvent().

◆ rechitManager_

std::unique_ptr<MultiVectorManager<HGCRecHit> > hgcal::ClusterTools::rechitManager_
private

Definition at line 70 of file ClusterTools.h.

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

◆ rhtools_

RecHitTools hgcal::ClusterTools::rhtools_
private

Definition at line 63 of file ClusterTools.h.

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