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::ClusterTools ( )

Definition at line 20 of file ClusterTools.cc.

20 {}
ClusterTools::ClusterTools ( const edm::ParameterSet conf,
edm::ConsumesCollector sumes 
)

Definition at line 22 of file ClusterTools.cc.

23  : eetok(sumes.consumes<HGCRecHitCollection>(conf.getParameter<edm::InputTag>("HGCEEInput"))),
24  fhtok(sumes.consumes<HGCRecHitCollection>(conf.getParameter<edm::InputTag>("HGCFHInput"))),
25  bhtok(sumes.consumes<HGCRecHitCollection>(conf.getParameter<edm::InputTag>("HGCBHInput"))) {}
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
const edm::EDGetTokenT< HGCRecHitCollection > fhtok
Definition: ClusterTools.h:60
const edm::EDGetTokenT< HGCRecHitCollection > eetok
Definition: ClusterTools.h:60
const edm::EDGetTokenT< HGCRecHitCollection > bhtok
Definition: ClusterTools.h:60
hgcal::ClusterTools::~ClusterTools ( )
inline

Definition at line 30 of file ClusterTools.h.

30 {}

Member Function Documentation

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

Definition at line 40 of file ClusterTools.cc.

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.

40  {
41  float energy = 0.f, energyHad = 0.f;
42  const auto& hits = clus.hitsAndFractions();
43  for (const auto& hit : hits) {
44  const auto& id = hit.first;
45  const float fraction = hit.second;
46  if (id.det() == DetId::HGCalEE) {
47  energy += eerh_->find(id)->energy() * fraction;
48  } else if (id.det() == DetId::HGCalHSi) {
49  const float temp = fhrh_->find(id)->energy();
50  energy += temp * fraction;
51  energyHad += temp * fraction;
52  } else if (id.det() == DetId::HGCalHSc) {
53  const float temp = bhrh_->find(id)->energy();
54  energy += temp * fraction;
55  energyHad += temp * fraction;
56  } else if (id.det() == DetId::Forward) {
57  switch (id.subdetId()) {
58  case HGCEE:
59  energy += eerh_->find(id)->energy() * fraction;
60  break;
61  case HGCHEF: {
62  const float temp = fhrh_->find(id)->energy();
63  energy += temp * fraction;
64  energyHad += temp * fraction;
65  } break;
66  default:
67  throw cms::Exception("HGCalClusterTools") << " Cluster contains hits that are not from HGCal! " << std::endl;
68  }
69  } else if (id.det() == DetId::Hcal && id.subdetId() == HcalEndcap) {
70  const float temp = bhrh_->find(id)->energy();
71  energy += temp * fraction;
72  energyHad += temp * fraction;
73  } else {
74  throw cms::Exception("HGCalClusterTools") << " Cluster contains hits that are not from HGCal! " << std::endl;
75  }
76  }
77  float fraction = -1.f;
78  if (energy > 0.f) {
79  fraction = energyHad / energy;
80  }
81  return fraction;
82 }
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:209
double f[11][100]
const HGCRecHitCollection * eerh_
Definition: ClusterTools.h:61
iterator find(key_type k)
const HGCRecHitCollection * bhrh_
Definition: ClusterTools.h:61
const HGCRecHitCollection * fhrh_
Definition: ClusterTools.h:61
void ClusterTools::getEvent ( const edm::Event ev)

Definition at line 27 of file ClusterTools.cc.

References bhrh_, bhtok, eerh_, eetok, fhrh_, fhtok, edm::Event::getByToken(), hgcal::RecHitTools::getEvent(), edm::Handle< T >::product(), rhtools_, and groupFilesInBlocks::temp.

27  {
28  rhtools_.getEvent(ev);
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 }
void getEvent(const edm::Event &)
Definition: RecHitTools.cc:68
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
RecHitTools rhtools_
Definition: ClusterTools.h:59
const HGCRecHitCollection * eerh_
Definition: ClusterTools.h:61
T const * product() const
Definition: Handle.h:69
const edm::EDGetTokenT< HGCRecHitCollection > fhtok
Definition: ClusterTools.h:60
const edm::EDGetTokenT< HGCRecHitCollection > eetok
Definition: ClusterTools.h:60
const HGCRecHitCollection * bhrh_
Definition: ClusterTools.h:61
const edm::EDGetTokenT< HGCRecHitCollection > bhtok
Definition: ClusterTools.h:60
const HGCRecHitCollection * fhrh_
Definition: ClusterTools.h:61
void ClusterTools::getEventSetup ( const edm::EventSetup es)

Definition at line 38 of file ClusterTools.cc.

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

38 { rhtools_.getEventSetup(es); }
void getEventSetup(const edm::EventSetup &)
Definition: RecHitTools.cc:70
RecHitTools rhtools_
Definition: ClusterTools.h:59
int ClusterTools::getLayer ( const DetId  detid) const

Definition at line 113 of file ClusterTools.cc.

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

Referenced by getWidths().

113 { return rhtools_.getLayerWithOffset(detid); }
RecHitTools rhtools_
Definition: ClusterTools.h:59
unsigned int getLayerWithOffset(const DetId &) const
Definition: RecHitTools.cc:355
double ClusterTools::getMultiClusterEnergy ( const reco::HGCalMultiCluster clu) const

Definition at line 115 of file ClusterTools.cc.

References reco::HGCalMultiCluster::clusters().

Referenced by getMultiClusterPosition().

115  {
116  double acc = 0.0;
117  for (const auto& ptr : clu.clusters()) {
118  acc += ptr->energy();
119  }
120  return acc;
121 }
const edm::PtrVector< reco::BasicCluster > & clusters() const
math::XYZPoint ClusterTools::getMultiClusterPosition ( const reco::HGCalMultiCluster clu) const

Definition at line 84 of file ClusterTools.cc.

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

84  {
85  if (clu.clusters().empty())
86  return math::XYZPoint();
87 
88  double acc_x = 0.0;
89  double acc_y = 0.0;
90  double acc_z = 0.0;
91  double totweight = 0.;
92  double mcenergy = getMultiClusterEnergy(clu);
93  for (const auto& ptr : clu.clusters()) {
94  if (mcenergy != 0) {
95  if (ptr->energy() < .01 * mcenergy)
96  continue; //cutoff < 1% layer contribution
97  }
98  const double weight = ptr->energy(); // weigth each corrdinate only by the total energy of the layer cluster
99  acc_x += ptr->x() * weight;
100  acc_y += ptr->y() * weight;
101  acc_z += ptr->z() * weight;
102  totweight += weight;
103  }
104  if (totweight != 0) {
105  acc_x /= totweight;
106  acc_y /= totweight;
107  acc_z /= totweight;
108  }
109  // return x/y/z in absolute coordinates
110  return math::XYZPoint(acc_x, acc_y, acc_z);
111 }
Definition: weight.py:1
const edm::PtrVector< reco::BasicCluster > & clusters() const
double getMultiClusterEnergy(const reco::HGCalMultiCluster &) const
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
bool ClusterTools::getWidths ( const reco::CaloCluster clus,
double &  sigmaetaeta,
double &  sigmaphiphi,
double &  sigmaetaetalog,
double &  sigmaphiphilog 
) const

Definition at line 123 of file ClusterTools.cc.

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.

127  {
128  if (getLayer(clus.hitsAndFractions()[0].first) > (int)rhtools_.lastLayerEE())
129  return false;
130  const math::XYZPoint& position(clus.position());
131  unsigned nhit = clus.hitsAndFractions().size();
132 
133  sigmaetaeta = 0.;
134  sigmaphiphi = 0.;
135  sigmaetaetal = 0.;
136  sigmaphiphil = 0.;
137 
138  double sumw = 0.;
139  double sumlogw = 0.;
140 
141  for (unsigned int ih = 0; ih < nhit; ++ih) {
142  const DetId& id = (clus.hitsAndFractions())[ih].first;
143  if ((clus.hitsAndFractions())[ih].second == 0.)
144  continue;
145 
146  if ((id.det() == DetId::HGCalEE) || (id.det() == DetId::Forward && id.subdetId() == HGCEE)) {
147  const HGCRecHit* theHit = &(*eerh_->find(id));
148 
149  GlobalPoint cellPos = rhtools_.getPosition(id);
150  double weight = theHit->energy();
151  // take w0=2 To be optimized
152  double logweight = 0;
153  if (clus.energy() != 0) {
154  logweight = std::max(0., 2 + log(theHit->energy() / clus.energy()));
155  }
156  double deltaetaeta2 = (cellPos.eta() - position.eta()) * (cellPos.eta() - position.eta());
157  double deltaphiphi2 = (cellPos.phi() - position.phi()) * (cellPos.phi() - position.phi());
158  sigmaetaeta += deltaetaeta2 * weight;
159  sigmaphiphi += deltaphiphi2 * weight;
160  sigmaetaetal += deltaetaeta2 * logweight;
161  sigmaphiphil += deltaphiphi2 * logweight;
162  sumw += weight;
163  sumlogw += logweight;
164  }
165  }
166 
167  if (sumw <= 0.)
168  return false;
169 
170  sigmaetaeta /= sumw;
171  sigmaetaeta = std::sqrt(sigmaetaeta);
172  sigmaphiphi /= sumw;
173  sigmaphiphi = std::sqrt(sigmaphiphi);
174 
175  if (sumlogw != 0) {
176  sigmaetaetal /= sumlogw;
177  sigmaetaetal = std::sqrt(sigmaetaetal);
178  sigmaphiphil /= sumlogw;
179  sigmaphiphil = std::sqrt(sigmaphiphil);
180  }
181 
182  return true;
183 }
constexpr float energy() const
Definition: CaloRecHit.h:29
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:153
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
Definition: weight.py:1
U second(std::pair< T, U > const &p)
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:209
RecHitTools rhtools_
Definition: ClusterTools.h:59
T sqrt(T t)
Definition: SSEVec.h:19
double energy() const
cluster energy
Definition: CaloCluster.h:148
int getLayer(const DetId) const
unsigned int lastLayerEE() const
Definition: RecHitTools.h:62
const HGCRecHitCollection * eerh_
Definition: ClusterTools.h:61
Definition: DetId.h:17
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
GlobalPoint getPosition(const DetId &id) const
Definition: RecHitTools.cc:129
T eta() const
Definition: PV3DBase.h:73
iterator find(key_type k)
static int position[264][3]
Definition: ReadPGInfo.cc:289
std::vector<size_t> hgcal::ClusterTools::sort_by_z ( const reco::HGCalMultiCluster v) const
inlineprivate

Definition at line 51 of file ClusterTools.h.

References begin, reco::HGCalMultiCluster::clusters(), end, testProducerWithPsetDescEmpty_cfi::i1, testProducerWithPsetDescEmpty_cfi::i2, training_settings::idx, reco::HGCalMultiCluster::size(), and findQualityFiles::v.

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  }
unsigned int size() const
const edm::PtrVector< reco::BasicCluster > & clusters() const
#define end
Definition: vmac.h:39
#define begin
Definition: vmac.h:32

Member Data Documentation

const HGCRecHitCollection * hgcal::ClusterTools::bhrh_
private

Definition at line 61 of file ClusterTools.h.

Referenced by getClusterHadronFraction(), and getEvent().

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

Definition at line 60 of file ClusterTools.h.

Referenced by getEvent().

const HGCRecHitCollection* hgcal::ClusterTools::eerh_
private

Definition at line 61 of file ClusterTools.h.

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

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

Definition at line 60 of file ClusterTools.h.

Referenced by getEvent().

const HGCRecHitCollection * hgcal::ClusterTools::fhrh_
private

Definition at line 61 of file ClusterTools.h.

Referenced by getClusterHadronFraction(), and getEvent().

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

Definition at line 60 of file ClusterTools.h.

Referenced by getEvent().

RecHitTools hgcal::ClusterTools::rhtools_
private

Definition at line 59 of file ClusterTools.h.

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