CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes | Static 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_
 

Static Private Attributes

static const int lastLayerEE = 28
 

Detailed Description

Definition at line 27 of file ClusterTools.h.

Constructor & Destructor Documentation

ClusterTools::ClusterTools ( )

Definition at line 19 of file ClusterTools.cc.

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

Definition at line 22 of file ClusterTools.cc.

23  :
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  }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
const edm::EDGetTokenT< HGCRecHitCollection > fhtok
Definition: ClusterTools.h:57
const edm::EDGetTokenT< HGCRecHitCollection > eetok
Definition: ClusterTools.h:57
const edm::EDGetTokenT< HGCRecHitCollection > bhtok
Definition: ClusterTools.h:57
hgcal::ClusterTools::~ClusterTools ( )
inline

Definition at line 31 of file ClusterTools.h.

31 {}

Member Function Documentation

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

Definition at line 44 of file ClusterTools.cc.

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

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::Forward ) {
51  switch( id.subdetId() ) {
52  case HGCEE:
53  energy += eerh_->find(id)->energy()*fraction;
54  break;
55  case HGCHEF:
56  {
57  const float temp = fhrh_->find(id)->energy();
58  energy += temp*fraction;
59  energyHad += temp*fraction;
60  }
61  break;
62  default:
63  throw cms::Exception("HGCalClusterTools")
64  << " Cluster contains hits that are not from HGCal! " << std::endl;
65  }
66  } else if ( id.det() == DetId::Hcal && id.subdetId() == HcalEndcap ) {
67  const float temp = bhrh_->find(id)->energy();
68  energy += temp*fraction;
69  energyHad += temp*fraction;
70  } else {
71  throw cms::Exception("HGCalClusterTools")
72  << " Cluster contains hits that are not from HGCal! " << std::endl;
73  }
74  }
75  float fraction = -1.f;
76  if( energy > 0.f ) {
77  fraction = energyHad/energy;
78  }
79  return fraction;
80 }
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:195
double f[11][100]
const HGCRecHitCollection * eerh_
Definition: ClusterTools.h:58
iterator find(key_type k)
const HGCRecHitCollection * bhrh_
Definition: ClusterTools.h:58
const HGCRecHitCollection * fhrh_
Definition: ClusterTools.h:58
void ClusterTools::getEvent ( const edm::Event ev)

Definition at line 29 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.

29  {
30  rhtools_.getEvent(ev);
32  ev.getByToken(eetok, temp);
33  eerh_ = temp.product();
34  ev.getByToken(fhtok, temp);
35  fhrh_ = temp.product();
36  ev.getByToken(bhtok, temp);
37  bhrh_ = temp.product();
38 }
void getEvent(const edm::Event &)
Definition: RecHitTools.cc:58
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
RecHitTools rhtools_
Definition: ClusterTools.h:56
const HGCRecHitCollection * eerh_
Definition: ClusterTools.h:58
T const * product() const
Definition: Handle.h:81
const edm::EDGetTokenT< HGCRecHitCollection > fhtok
Definition: ClusterTools.h:57
const edm::EDGetTokenT< HGCRecHitCollection > eetok
Definition: ClusterTools.h:57
const HGCRecHitCollection * bhrh_
Definition: ClusterTools.h:58
const edm::EDGetTokenT< HGCRecHitCollection > bhtok
Definition: ClusterTools.h:57
const HGCRecHitCollection * fhrh_
Definition: ClusterTools.h:58
void ClusterTools::getEventSetup ( const edm::EventSetup es)

Definition at line 40 of file ClusterTools.cc.

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

40  {
42 }
void getEventSetup(const edm::EventSetup &)
Definition: RecHitTools.cc:61
RecHitTools rhtools_
Definition: ClusterTools.h:56
int ClusterTools::getLayer ( const DetId  detid) const

Definition at line 110 of file ClusterTools.cc.

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

Referenced by getWidths().

110  {
111  return rhtools_.getLayerWithOffset(detid);
112 }
RecHitTools rhtools_
Definition: ClusterTools.h:56
unsigned int getLayerWithOffset(const DetId &) const
Definition: RecHitTools.cc:176
double ClusterTools::getMultiClusterEnergy ( const reco::HGCalMultiCluster clu) const

Definition at line 114 of file ClusterTools.cc.

References reco::HGCalMultiCluster::clusters().

Referenced by getMultiClusterPosition().

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

Definition at line 83 of file ClusterTools.cc.

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

83  {
84  if( clu.clusters().size() == 0 ) return math::XYZPoint();
85 
86  double acc_x = 0.0;
87  double acc_y = 0.0;
88  double acc_z = 0.0;
89  double totweight = 0.;
90  double mcenergy = getMultiClusterEnergy(clu);
91  for( const auto& ptr : clu.clusters() ) {
92  if (mcenergy != 0) {
93  if(ptr->energy()<.01*mcenergy) continue; //cutoff < 1% layer contribution
94  }
95  const double weight = ptr->energy(); // weigth each corrdinate only by the total energy of the layer cluster
96  acc_x += ptr->x()*weight;
97  acc_y += ptr->y()*weight;
98  acc_z += ptr->z()*weight;
99  totweight += weight;
100  }
101  if (totweight != 0) {
102  acc_x /= totweight;
103  acc_y /= totweight;
104  acc_z /= totweight;
105  }
106  // return x/y/z in absolute coordinates
107  return math::XYZPoint(acc_x,acc_y,acc_z);
108 }
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 122 of file ClusterTools.cc.

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

122  {
123 
124  if (getLayer(clus.hitsAndFractions()[0].first) > lastLayerEE) 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.) continue;
139 
141  if (id.det()==DetId::Forward && id.subdetId()==HGCEE) {
142  const HGCRecHit * theHit = &(*eerh_->find(id));
143 
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 
163  if (sumw<=0.) 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 }
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:129
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
std::vector< HGCRecHit >::const_iterator const_iterator
Definition: weight.py:1
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:195
U second(std::pair< T, U > const &p)
RecHitTools rhtools_
Definition: ClusterTools.h:56
float energy() const
Definition: CaloRecHit.h:17
T sqrt(T t)
Definition: SSEVec.h:18
double energy() const
cluster energy
Definition: CaloCluster.h:124
int getLayer(const DetId) const
const HGCRecHitCollection * eerh_
Definition: ClusterTools.h:58
Definition: DetId.h:18
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
GlobalPoint getPosition(const DetId &id) const
Definition: RecHitTools.cc:77
T eta() const
Definition: PV3DBase.h:76
iterator find(key_type k)
static const int lastLayerEE
Definition: ClusterTools.h:59
static int position[264][3]
Definition: ReadPGInfo.cc:509
std::vector<size_t> hgcal::ClusterTools::sort_by_z ( const reco::HGCalMultiCluster v) const
inlineprivate

Definition at line 48 of file ClusterTools.h.

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

48  {
49  std::vector<size_t> idx(v.size());
50  std::iota (std::begin(idx), std::end(idx), 0);
51  sort(idx.begin(), idx.end(),
52  [&v](size_t i1, size_t i2) {return v.clusters()[i1]->z() < v.clusters()[i2]->z();});
53  return idx;
54  }
unsigned int size() const
const edm::PtrVector< reco::BasicCluster > & clusters() const
#define end
Definition: vmac.h:37
#define begin
Definition: vmac.h:30

Member Data Documentation

const HGCRecHitCollection * hgcal::ClusterTools::bhrh_
private

Definition at line 58 of file ClusterTools.h.

Referenced by getClusterHadronFraction(), and getEvent().

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

Definition at line 57 of file ClusterTools.h.

Referenced by getEvent().

const HGCRecHitCollection* hgcal::ClusterTools::eerh_
private

Definition at line 58 of file ClusterTools.h.

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

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

Definition at line 57 of file ClusterTools.h.

Referenced by getEvent().

const HGCRecHitCollection * hgcal::ClusterTools::fhrh_
private

Definition at line 58 of file ClusterTools.h.

Referenced by getClusterHadronFraction(), and getEvent().

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

Definition at line 57 of file ClusterTools.h.

Referenced by getEvent().

const int hgcal::ClusterTools::lastLayerEE = 28
staticprivate

Definition at line 59 of file ClusterTools.h.

Referenced by getWidths().

RecHitTools hgcal::ClusterTools::rhtools_
private

Definition at line 56 of file ClusterTools.h.

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