CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
Basic2DGenericPFlowPositionCalc Class Reference

#include <Basic2DGenericPFlowPositionCalc.h>

Inheritance diagram for Basic2DGenericPFlowPositionCalc:
PFCPositionCalculatorBase

Public Member Functions

 Basic2DGenericPFlowPositionCalc (const edm::ParameterSet &conf)
 
 Basic2DGenericPFlowPositionCalc (const Basic2DGenericPFlowPositionCalc &)=delete
 
void calculateAndSetPosition (reco::PFCluster &)
 
void calculateAndSetPositions (reco::PFClusterCollection &)
 
Basic2DGenericPFlowPositionCalcoperator= (const Basic2DGenericPFlowPositionCalc &)=delete
 
- Public Member Functions inherited from PFCPositionCalculatorBase
const std::string & name () const
 
PosCalcoperator= (const PosCalc &)=delete
 
 PFCPositionCalculatorBase (const edm::ParameterSet &conf)
 
 PFCPositionCalculatorBase (const PosCalc &)=delete
 
virtual void update (const edm::EventSetup &)
 
 ~PFCPositionCalculatorBase ()
 

Private Member Functions

void calculateAndSetPositionActual (reco::PFCluster &) const
 

Private Attributes

const float _logWeightDenom
 
const float _minAllowedNorm
 
const int _posCalcNCrystals
 
std::unique_ptr
< CaloRecHitResolutionProvider
_timeResolutionCalcBarrel
 
std::unique_ptr
< CaloRecHitResolutionProvider
_timeResolutionCalcEndcap
 

Additional Inherited Members

- Protected Attributes inherited from PFCPositionCalculatorBase
const float _minFractionInCalc
 

Detailed Description

Definition at line 12 of file Basic2DGenericPFlowPositionCalc.h.

Constructor & Destructor Documentation

Basic2DGenericPFlowPositionCalc::Basic2DGenericPFlowPositionCalc ( const edm::ParameterSet conf)
inline

Definition at line 14 of file Basic2DGenericPFlowPositionCalc.h.

References _posCalcNCrystals, _timeResolutionCalcBarrel, _timeResolutionCalcEndcap, assert(), edm::ParameterSet::exists(), edm::ParameterSet::getParameterSet(), and NULL.

14  :
16  _posCalcNCrystals(conf.getParameter<int>("posCalcNCrystals")),
17  _logWeightDenom(1./conf.getParameter<double>("logWeightDenominator")),
18  _minAllowedNorm(conf.getParameter<double>("minAllowedNormalization"))
19 
20  {
22  if( conf.exists("timeResolutionCalcBarrel") ) {
23  const edm::ParameterSet& timeResConf =
24  conf.getParameterSet("timeResolutionCalcBarrel");
26  }
28  if( conf.exists("timeResolutionCalcEndcap") ) {
29  const edm::ParameterSet& timeResConf =
30  conf.getParameterSet("timeResolutionCalcEndcap");
32  }
33 
34  switch( _posCalcNCrystals ) {
35  case 5:
36  case 9:
37  case -1:
38  break;
39  default:
40  edm::LogError("Basic2DGenericPFlowPositionCalc") << "posCalcNCrystals not valid";
41  assert(0); // bug
42  }
43 
44 
45  }
T getParameter(std::string const &) const
assert(m_qm.get())
bool exists(std::string const &parameterName) const
checks if a parameter exists
#define NULL
Definition: scimark2.h:8
ParameterSet const & getParameterSet(std::string const &) const
std::unique_ptr< CaloRecHitResolutionProvider > _timeResolutionCalcBarrel
std::unique_ptr< CaloRecHitResolutionProvider > _timeResolutionCalcEndcap
PFCPositionCalculatorBase(const edm::ParameterSet &conf)
Basic2DGenericPFlowPositionCalc::Basic2DGenericPFlowPositionCalc ( const Basic2DGenericPFlowPositionCalc )
delete

Member Function Documentation

void Basic2DGenericPFlowPositionCalc::calculateAndSetPosition ( reco::PFCluster cluster)
virtual

Implements PFCPositionCalculatorBase.

Definition at line 24 of file Basic2DGenericPFlowPositionCalc.cc.

References calculateAndSetPositionActual().

24  {
26 }
void calculateAndSetPositionActual(reco::PFCluster &) const
void Basic2DGenericPFlowPositionCalc::calculateAndSetPositionActual ( reco::PFCluster cluster) const
private

Definition at line 36 of file Basic2DGenericPFlowPositionCalc.cc.

References _logWeightDenom, _minAllowedNorm, PFCPositionCalculatorBase::_minFractionInCalc, _posCalcNCrystals, _timeResolutionCalcBarrel, _timeResolutionCalcEndcap, a, b, reco::PFCluster::calculatePositionREP(), bookConverter::compute(), declareDynArray, reco::PFRecHit::depth(), HLT_FULL_cff::depth, reco::PFRecHit::detId(), relval_parameters_module::energy, reco::PFRecHit::energy(), Exception, f, myMath::fast_logf(), HLT_FULL_cff::fraction, i, GeomDetEnumerators::isBarrel(), edm::isNotFinite(), relval_2017::k, reco::PFRecHit::layer(), bookConverter::max, ecalTB2006H4_GenSimDigiReco_cfg::mySeed, nhits, PFLayer::NONE, AlCaHLTBitMon_ParallelJobs::p, reco::PFRecHit::position(), reco::PFCluster::recHitFractions(), reco::CaloCluster::seed(), reco::PFCluster::setDepth(), reco::CaloCluster::setEnergy(), reco::PFCluster::setLayer(), reco::CaloCluster::setPosition(), reco::PFCluster::setTime(), reco::PFRecHit::time(), unInitDynArray, unlikely, x, y, and z.

Referenced by calculateAndSetPosition(), and calculateAndSetPositions().

36  {
37  if( !cluster.seed() ) {
38  throw cms::Exception("ClusterWithNoSeed")
39  << " Found a cluster with no seed: " << cluster;
40  }
41  double cl_energy = 0;
42  double cl_time = 0;
43  double cl_timeweight=0.0;
44  double max_e = 0.0;
45  PFLayer::Layer max_e_layer = PFLayer::NONE;
46  // find the seed and max layer and also calculate time
47  //Michalis : Even if we dont use timing in clustering here we should fill
48  //the time information for the cluster. This should use the timing resolution(1/E)
49  //so the weight should be fraction*E^2
50  //calculate a simplistic depth now. The log weighted will be done
51  //in different stage
52 
53 
54  auto const recHitCollection = &(*cluster.recHitFractions()[0].recHitRef()) - cluster.recHitFractions()[0].recHitRef().key();
55  auto nhits = cluster.recHitFractions().size();
56  struct LHit{ reco::PFRecHit const * hit; float energy; float fraction;};
57  declareDynArray(LHit,nhits,hits);
58  for(auto i=0U; i<nhits; ++i) {
59  auto const & hf = cluster.recHitFractions()[i];
60  auto k = hf.recHitRef().key();
61  auto p = recHitCollection+k;
62  hits[i]= {p,(*p).energy(), float(hf.fraction())};
63  }
64 
65 
66  bool resGiven = bool(_timeResolutionCalcBarrel) & bool(_timeResolutionCalcEndcap);
67  LHit mySeed={nullptr};
68  for( auto const & rhf : hits ) {
69  const reco::PFRecHit & refhit = *rhf.hit;
70  if( refhit.detId() == cluster.seed() ) mySeed = rhf;
71  const auto rh_fraction = rhf.fraction;
72  const auto rh_rawenergy = rhf.energy;
73  const auto rh_energy = rh_rawenergy * rh_fraction;
74 #ifdef PF_DEBUG
75  if unlikely( edm::isNotFinite(rh_energy) ) {
76  throw cms::Exception("PFClusterAlgo")
77  <<"rechit " << refhit.detId() << " has a NaN energy... "
78  << "The input of the particle flow clustering seems to be corrupted.";
79  }
80 #endif
81  cl_energy += rh_energy;
82  // If time resolution is given, calculated weighted average
83  if ( resGiven ) {
84  double res2 = 1.e-4;
85  int cell_layer = (int)refhit.layer();
86  res2 = isBarrel(cell_layer) ? 1./_timeResolutionCalcBarrel->timeResolution2(rh_rawenergy) :
87  1./_timeResolutionCalcEndcap->timeResolution2(rh_rawenergy);
88  cl_time += rh_fraction*refhit.time()*res2;
89  cl_timeweight += rh_fraction*res2;
90  }
91  else { // assume resolution = 1/E**2
92  const double rh_rawenergy2 = rh_rawenergy*rh_rawenergy;
93  cl_timeweight+=rh_rawenergy2*rh_fraction;
94  cl_time += rh_rawenergy2*rh_fraction*refhit.time();
95  }
96 
97  if( rh_energy > max_e ) {
98  max_e = rh_energy;
99  max_e_layer = refhit.layer();
100  }
101  }
102 
103  cluster.setEnergy(cl_energy);
104  cluster.setTime(cl_time/cl_timeweight);
105  cluster.setLayer(max_e_layer);
106 
107  // calculate the position
108  double depth = 0.0;
109  double position_norm = 0.0;
110  double x(0.0),y(0.0),z(0.0);
111  if( nullptr != mySeed.hit ) {
112  auto seedNeighbours = mySeed.hit->neighbours();
113  switch( _posCalcNCrystals ) {
114  case 5:
115  seedNeighbours = mySeed.hit->neighbours4();
116  break;
117  case 9:
118  seedNeighbours = mySeed.hit->neighbours8();
119  break;
120  default:
121  break;
122  }
123 
124  auto compute = [&](LHit const& rhf) {
125  const reco::PFRecHit & refhit = *rhf.hit;
126  const auto rh_energy = rhf.energy * rhf.fraction;
127  const auto norm = ( rhf.fraction < _minFractionInCalc ?
128  0.0f :
129  std::max(0.0f,vdt::fast_logf(rh_energy*_logWeightDenom)) );
130  const auto rhpos_xyz = refhit.position()*norm;
131  x += rhpos_xyz.x();
132  y += rhpos_xyz.y();
133  z += rhpos_xyz.z();
134  depth += refhit.depth()*norm;
135  position_norm += norm;
136  };
137 
138  if(_posCalcNCrystals != -1) // sorted to make neighbour search faster (maybe)
139  std::sort(hits.begin(),hits.end(),[](LHit const& a, LHit const& b) { return a.hit<b.hit;});
140 
141 
142  if(_posCalcNCrystals == -1)
143  for( auto const & rhf : hits ) compute(rhf);
144  else { // only seed and its neighbours
145  compute(mySeed);
146  // search seedNeighbours to find energy fraction in cluster (sic)
147  unInitDynArray(reco::PFRecHit const *,seedNeighbours.size(),nei);
148  for(auto k : seedNeighbours){
149  nei.push_back(recHitCollection+k);
150  }
151  std::sort(nei.begin(),nei.end());
152  struct LHitLess {
153  auto operator()(LHit const &a, reco::PFRecHit const * b) const {return a.hit<b;}
154  auto operator()(reco::PFRecHit const * b, LHit const &a) const {return b<a.hit;}
155  };
156  std::set_intersection(hits.begin(),hits.end(),nei.begin(),nei.end(),
157  boost::make_function_output_iterator(compute),
158  LHitLess()
159  );
160  }
161  } else {
162  throw cms::Exception("Basic2DGenerticPFlowPositionCalc")
163  << "Cluster seed hit is null, something is wrong with PFlow RecHit!";
164  }
165 
166  if( position_norm < _minAllowedNorm ) {
167  edm::LogError("WeirdClusterNormalization")
168  << "PFCluster too far from seeding cell: set position to (0,0,0).";
169  cluster.setPosition(math::XYZPoint(0,0,0));
170  cluster.calculatePositionREP();
171  } else {
172  const double norm_inverse = 1.0/position_norm;
173  x *= norm_inverse;
174  y *= norm_inverse;
175  z *= norm_inverse;
176  depth *= norm_inverse;
177  cluster.setPosition(math::XYZPoint(x,y,z));
178  cluster.setDepth(depth);
179  cluster.calculatePositionREP();
180  }
181 }
void setLayer(PFLayer::Layer layer)
set layer
Definition: PFCluster.cc:120
int i
Definition: DBlmapReader.cc:9
float time() const
timing for cleaned hits
Definition: PFRecHit.h:118
unsigned detId() const
rechit detId
Definition: PFRecHit.h:108
void setPosition(const math::XYZPoint &p)
Definition: CaloCluster.h:112
bool isBarrel(GeomDetEnumerators::SubDetector m)
void setTime(float time, float timeError=0)
Definition: PFCluster.h:92
void setEnergy(double energy)
Definition: CaloCluster.h:108
PositionType const & position() const
rechit cell centre x, y, z
Definition: PFRecHit.h:129
int depth() const
depth for segemntation
Definition: PFRecHit.h:121
PFLayer::Layer layer() const
rechit layer
Definition: PFRecHit.h:111
#define unlikely(x)
bool isNotFinite(T x)
Definition: isFinite.h:10
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
Definition: PFRecHit.h:31
void calculatePositionREP()
computes posrep_ once and for all
Definition: PFCluster.h:100
#define unInitDynArray(T, n, x)
Definition: DynArray.h:58
double f[11][100]
float energy() const
rechit energy
Definition: PFRecHit.h:114
Layer
layer definition
Definition: PFLayer.h:31
DetId seed() const
return DetId of seed
Definition: CaloCluster.h:202
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
std::unique_ptr< CaloRecHitResolutionProvider > _timeResolutionCalcBarrel
double b
Definition: hdecay.h:120
std::unique_ptr< CaloRecHitResolutionProvider > _timeResolutionCalcEndcap
double a
Definition: hdecay.h:121
void setDepth(double depth)
Definition: PFCluster.h:94
const std::vector< reco::PFRecHitFraction > & recHitFractions() const
vector of rechit fractions
Definition: PFCluster.h:72
#define declareDynArray(T, n, x)
Definition: DynArray.h:59
float fast_logf(float x)
void Basic2DGenericPFlowPositionCalc::calculateAndSetPositions ( reco::PFClusterCollection clusters)
virtual

Implements PFCPositionCalculatorBase.

Definition at line 29 of file Basic2DGenericPFlowPositionCalc.cc.

References calculateAndSetPositionActual().

29  {
30  for( reco::PFCluster& cluster : clusters ) {
32  }
33 }
void calculateAndSetPositionActual(reco::PFCluster &) const
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:47
Basic2DGenericPFlowPositionCalc& Basic2DGenericPFlowPositionCalc::operator= ( const Basic2DGenericPFlowPositionCalc )
delete

Member Data Documentation

const float Basic2DGenericPFlowPositionCalc::_logWeightDenom
private

Definition at line 55 of file Basic2DGenericPFlowPositionCalc.h.

Referenced by calculateAndSetPositionActual().

const float Basic2DGenericPFlowPositionCalc::_minAllowedNorm
private

Definition at line 56 of file Basic2DGenericPFlowPositionCalc.h.

Referenced by calculateAndSetPositionActual().

const int Basic2DGenericPFlowPositionCalc::_posCalcNCrystals
private
std::unique_ptr<CaloRecHitResolutionProvider> Basic2DGenericPFlowPositionCalc::_timeResolutionCalcBarrel
private
std::unique_ptr<CaloRecHitResolutionProvider> Basic2DGenericPFlowPositionCalc::_timeResolutionCalcEndcap
private