CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Attributes
PositionCalc Class Reference

#include <PositionCalc.h>

Public Types

typedef std::vector< std::pair< DetId, double > > HitsAndEnergies
 
typedef std::vector< std::pair< DetId, float > > HitsAndFractions
 

Public Member Functions

template<typename HitType >
math::XYZPoint Calculate_Location (const HitsAndFractions &iDetIds, const edm::SortedCollection< HitType > *iRecHits, const CaloSubdetectorGeometry *iSubGeom, const CaloSubdetectorGeometry *iESGeom=nullptr)
 
const PositionCalcoperator= (const PositionCalc &rhs)
 
 PositionCalc (const edm::ParameterSet &par)
 
 PositionCalc ()
 

Private Attributes

const CaloSubdetectorGeometrym_esGeom
 
bool m_esMinus
 
bool m_esPlus
 
bool param_LogWeighted_
 
double param_T0_barl_
 
double param_T0_endc_
 
double param_T0_endcPresh_
 
double param_W0_
 
double param_X0_
 

Detailed Description

Definition at line 29 of file PositionCalc.h.

Member Typedef Documentation

◆ HitsAndEnergies

typedef std::vector<std::pair<DetId, double> > PositionCalc::HitsAndEnergies

Definition at line 32 of file PositionCalc.h.

◆ HitsAndFractions

typedef std::vector<std::pair<DetId, float> > PositionCalc::HitsAndFractions

Definition at line 31 of file PositionCalc.h.

Constructor & Destructor Documentation

◆ PositionCalc() [1/2]

PositionCalc::PositionCalc ( const edm::ParameterSet par)

Definition at line 4 of file PositionCalc.cc.

5  : param_LogWeighted_(par.getParameter<bool>("LogWeighted")),
6  param_T0_barl_(par.getParameter<double>("T0_barl")),
7  param_T0_endc_(par.getParameter<double>("T0_endc")),
8  param_T0_endcPresh_(par.getParameter<double>("T0_endcPresh")),
9  param_W0_(par.getParameter<double>("W0")),
10  param_X0_(par.getParameter<double>("X0")),
11  m_esGeom(nullptr),
12  m_esPlus(false),
13  m_esMinus(false) {}
double param_T0_endc_
Definition: PositionCalc.h:54
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
double param_W0_
Definition: PositionCalc.h:56
double param_X0_
Definition: PositionCalc.h:57
bool param_LogWeighted_
Definition: PositionCalc.h:52
double param_T0_endcPresh_
Definition: PositionCalc.h:55
double param_T0_barl_
Definition: PositionCalc.h:53
const CaloSubdetectorGeometry * m_esGeom
Definition: PositionCalc.h:59

◆ PositionCalc() [2/2]

PositionCalc::PositionCalc ( )
inline

Definition at line 37 of file PositionCalc.h.

37 {};

Member Function Documentation

◆ Calculate_Location()

template<typename HitType >
math::XYZPoint PositionCalc::Calculate_Location ( const HitsAndFractions iDetIds,
const edm::SortedCollection< HitType > *  iRecHits,
const CaloSubdetectorGeometry iSubGeom,
const CaloSubdetectorGeometry iESGeom = nullptr 
)

Definition at line 65 of file PositionCalc.h.

References hcalRecHitTable_cff::depth, EcalBarrel, cosmicPhotonAnalyzer_cfi::eMax, edm::SortedCollection< T, SORT >::empty(), edm::SortedCollection< T, SORT >::end(), hcalRecHitTable_cff::energy, Exception, edm::SortedCollection< T, SORT >::find(), DivergingColor::frac, CaloSubdetectorGeometry::getGeometry(), CaloSubdetectorGeometry::getValidDetIds(), dqmiolumiharvest::j, dqm-mbProfile::log, LogDebug, m_esGeom, m_esMinus, m_esPlus, SiStripPI::max, HLT_2024v12_cff::maxDepth, dqmiodumpmetadata::n, DetId::null(), param_LogWeighted_, param_T0_barl_, param_T0_endc_, param_T0_endcPresh_, param_W0_, param_X0_, DetId::subdetId(), mps_merge::weight, z, and zw().

Referenced by DQMSourcePi0::analyze(), HybridClusterAlgo::e2Et(), HybridClusterAlgo::et25(), PhotonProducer::fillPhotonCollection(), Multi5x5ClusterAlgo::mainSearch(), HybridClusterAlgo::mainSearch(), IslandClusterAlgo::makeCluster(), CosmicClusterAlgo::makeCluster(), Multi5x5ClusterAlgo::makeCluster(), EgammaHLTNxNClusterProducer::makeNxNClusters(), PiZeroAnalyzer::makePizero(), and ecaldqm::PiZeroTask::runOnEBRecHits().

68  {
69  typedef edm::SortedCollection<HitType> HitTypeCollection;
70  math::XYZPoint returnValue(0, 0, 0);
71 
72  // Throw an error if the cluster was not initialized properly
73 
74  if (nullptr == iRecHits || nullptr == iSubGeom) {
75  throw cms::Exception("PositionCalc") << "Calculate_Location() called uninitialized or wrong initialization.";
76  }
77 
78  if (!iDetIds.empty() && !iRecHits->empty()) {
79  HitsAndEnergies detIds;
80  detIds.reserve(iDetIds.size());
81 
82  double eTot(0);
83  double eMax(0);
84  DetId maxId;
85 
86  // Check that DetIds are nonzero
87  typename HitTypeCollection::const_iterator endRecHits(iRecHits->end());
88  HitsAndFractions::const_iterator n, endDiDs(iDetIds.end());
89  for (n = iDetIds.begin(); n != endDiDs; ++n) {
90  const DetId dId((*n).first);
91  const float frac((*n).second);
92  if (!dId.null()) {
93  typename HitTypeCollection::const_iterator iHit(iRecHits->find(dId));
94  if (iHit != endRecHits) {
95  const double energy(iHit->energy() * frac);
96  detIds.push_back(std::make_pair(dId, energy));
97  if (0.0 < energy) { // only save positive energies
98  if (eMax < energy) {
99  eMax = energy;
100  maxId = dId;
101  }
102  eTot += energy;
103  }
104  }
105  }
106  }
107 
108  if (0.0 >= eTot) {
109  LogDebug("ZeroClusterEnergy") << "cluster with 0 energy: " << eTot << " size: " << detIds.size()
110  << " , returning (0,0,0)";
111  } else {
112  // first time or when es geom changes set flags
113  if (nullptr != iESGeom && m_esGeom != iESGeom) {
114  m_esGeom = iESGeom;
115  for (uint32_t ic(0); (ic != m_esGeom->getValidDetIds().size()) && ((!m_esPlus) || (!m_esMinus)); ++ic) {
116  const double z(m_esGeom->getGeometry(m_esGeom->getValidDetIds()[ic])->getPosition().z());
117  m_esPlus = m_esPlus || (0 < z);
118  m_esMinus = m_esMinus || (0 > z);
119  }
120  }
121 
122  //Select the correct value of the T0 parameter depending on subdetector
123  auto center_cell(iSubGeom->getGeometry(maxId));
124  const double ctreta(center_cell->getPosition().eta());
125 
126  // for barrel, use barrel T0;
127  // for endcap: if preshower present && in preshower fiducial,
128  // use preshower T0
129  // else use endcap only T0
130  const double preshowerStartEta = 1.653;
131  const int subdet = maxId.subdetId();
132  const double T0(subdet == EcalBarrel ? param_T0_barl_
133  : (((preshowerStartEta < fabs(ctreta)) &&
134  (((0 < ctreta) && m_esPlus) || ((0 > ctreta) && m_esMinus)))
136  : param_T0_endc_));
137 
138  // Calculate shower depth
139  const float maxDepth(param_X0_ * (T0 + log(eTot)));
140  const float maxToFront(center_cell->getPosition().mag()); // to front face
141 
142  // Loop over hits and get weights
143  double total_weight = 0;
144  const double eTot_inv = 1.0 / eTot;
145  const double logETot_inv = (param_LogWeighted_ ? log(eTot_inv) : 0);
146 
147  double xw(0);
148  double yw(0);
149  double zw(0);
150 
151  HitsAndEnergies::const_iterator j, hAndE_end = detIds.end();
152  for (j = detIds.begin(); j != hAndE_end; ++j) {
153  const DetId dId((*j).first);
154  const double e_j((*j).second);
155 
156  double weight = 0;
157  if (param_LogWeighted_) {
158  if (e_j > 0.0) {
159  weight = std::max(0., param_W0_ + log(e_j) + logETot_inv);
160  } else {
161  weight = 0;
162  }
163  } else {
164  weight = e_j * eTot_inv;
165  }
166 
167  auto cell(iSubGeom->getGeometry(dId));
168  const float depth(maxDepth + maxToFront - cell->getPosition().mag());
169 
170  const GlobalPoint pos(cell->getPosition(depth));
171 
172  xw += weight * pos.x();
173  yw += weight * pos.y();
174  zw += weight * pos.z();
175 
176  total_weight += weight;
177  }
178  returnValue = math::XYZPoint(xw / total_weight, yw / total_weight, zw / total_weight);
179  }
180  }
181  return returnValue;
182 }
double param_T0_endc_
Definition: PositionCalc.h:54
double param_W0_
Definition: PositionCalc.h:56
Definition: weight.py:1
double param_X0_
Definition: PositionCalc.h:57
bool param_LogWeighted_
Definition: PositionCalc.h:52
double param_T0_endcPresh_
Definition: PositionCalc.h:55
virtual const std::vector< DetId > & getValidDetIds(DetId::Detector det=DetId::Detector(0), int subdet=0) const
Get a list of valid detector ids (for the given subdetector)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
const_iterator end() const
Definition: DetId.h:17
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
double param_T0_barl_
Definition: PositionCalc.h:53
iterator find(key_type k)
auto zw(V v) -> Vec2< typename std::remove_reference< decltype(v[0])>::type >
Definition: ExtVec.h:71
const CaloSubdetectorGeometry * m_esGeom
Definition: PositionCalc.h:59
std::vector< std::pair< DetId, double > > HitsAndEnergies
Definition: PositionCalc.h:32
#define LogDebug(id)

◆ operator=()

const PositionCalc & PositionCalc::operator= ( const PositionCalc rhs)

Definition at line 15 of file PositionCalc.cc.

References m_esGeom, m_esMinus, m_esPlus, param_LogWeighted_, param_T0_barl_, param_T0_endc_, param_T0_endcPresh_, param_W0_, and param_X0_.

15  {
20  param_W0_ = rhs.param_W0_;
21  param_X0_ = rhs.param_X0_;
22 
23  m_esGeom = rhs.m_esGeom;
24  m_esPlus = rhs.m_esPlus;
25  m_esMinus = rhs.m_esMinus;
26  return *this;
27 }
double param_T0_endc_
Definition: PositionCalc.h:54
double param_W0_
Definition: PositionCalc.h:56
double param_X0_
Definition: PositionCalc.h:57
bool param_LogWeighted_
Definition: PositionCalc.h:52
double param_T0_endcPresh_
Definition: PositionCalc.h:55
double param_T0_barl_
Definition: PositionCalc.h:53
const CaloSubdetectorGeometry * m_esGeom
Definition: PositionCalc.h:59

Member Data Documentation

◆ m_esGeom

const CaloSubdetectorGeometry* PositionCalc::m_esGeom
private

Definition at line 59 of file PositionCalc.h.

Referenced by Calculate_Location(), and operator=().

◆ m_esMinus

bool PositionCalc::m_esMinus
private

Definition at line 61 of file PositionCalc.h.

Referenced by Calculate_Location(), and operator=().

◆ m_esPlus

bool PositionCalc::m_esPlus
private

Definition at line 60 of file PositionCalc.h.

Referenced by Calculate_Location(), and operator=().

◆ param_LogWeighted_

bool PositionCalc::param_LogWeighted_
private

Definition at line 52 of file PositionCalc.h.

Referenced by Calculate_Location(), and operator=().

◆ param_T0_barl_

double PositionCalc::param_T0_barl_
private

Definition at line 53 of file PositionCalc.h.

Referenced by Calculate_Location(), and operator=().

◆ param_T0_endc_

double PositionCalc::param_T0_endc_
private

Definition at line 54 of file PositionCalc.h.

Referenced by Calculate_Location(), and operator=().

◆ param_T0_endcPresh_

double PositionCalc::param_T0_endcPresh_
private

Definition at line 55 of file PositionCalc.h.

Referenced by Calculate_Location(), and operator=().

◆ param_W0_

double PositionCalc::param_W0_
private

Definition at line 56 of file PositionCalc.h.

Referenced by Calculate_Location(), and operator=().

◆ param_X0_

double PositionCalc::param_X0_
private

Definition at line 57 of file PositionCalc.h.

Referenced by Calculate_Location(), and operator=().