CMS 3D CMS Logo

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 &) override
 
void calculateAndSetPositions (reco::PFClusterCollection &) override
 
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 &)
 
virtual ~PFCPositionCalculatorBase ()=default
 

Private Member Functions

void calculateAndSetPositionActual (reco::PFCluster &) const
 

Private Attributes

std::tuple< std::vector< int >,std::vector< int >, std::vector< 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 13 of file Basic2DGenericPFlowPositionCalc.h.

Constructor & Destructor Documentation

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

Definition at line 15 of file Basic2DGenericPFlowPositionCalc.h.

References _logWeightDenom, _posCalcNCrystals, _timeResolutionCalcBarrel, _timeResolutionCalcEndcap, calculateAndSetPosition(), calculateAndSetPositions(), particleFlowClusterHBHE_cfi::depths, particleFlowRecHitHBHE_cfi::detectorEnum, Exception, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterSet(), edm::ParameterSet::getParameterSetVector(), mps_fire::i, operator=(), muonDTDigis_cfi::pset, and AlCaHLTBitMon_QueryRunRegistry::string.

15  :
17  _posCalcNCrystals(conf.getParameter<int>("posCalcNCrystals")),
18  _minAllowedNorm(conf.getParameter<double>("minAllowedNormalization"))
19  {
20 
21  std::vector<int> detectorEnum;
22  std::vector<int> depths;
23  std::vector<double> logWeightDenom;
24  std::vector<float> logWeightDenomInv;
25 
26  if(conf.exists("logWeightDenominatorByDetector")) {
27 
28  const std::vector<edm::ParameterSet>& logWeightDenominatorByDetectorPSet = conf.getParameterSetVector("logWeightDenominatorByDetector");
29 
30  for( const auto& pset : logWeightDenominatorByDetectorPSet ) {
31  if(!pset.exists("detector")) {
32  throw cms::Exception("logWeightDenominatorByDetectorPSet")
33  << "logWeightDenominator : detector not specified";
34  }
35 
36  const std::string& det = pset.getParameter<std::string>("detector");
37 
38  if (det==std::string("HCAL_BARREL1") || det==std::string("HCAL_ENDCAP")) {
39  std::vector<int> depthsT=pset.getParameter<std::vector<int> >("depths");
40  std::vector<double> logWeightDenomT=pset.getParameter<std::vector<double> >("logWeightDenominator");
41  if(logWeightDenomT.size()!=depthsT.size()) {
42  throw cms::Exception("logWeightDenominator")
43  << "logWeightDenominator mismatch with the numbers of depths";
44  }
45  for(unsigned int i=0;i < depthsT.size();++i){
46  if(det==std::string("HCAL_BARREL1")) detectorEnum.push_back(1);
47  if(det==std::string("HCAL_ENDCAP")) detectorEnum.push_back(2);
48  depths.push_back(depthsT[i]);
49  logWeightDenom.push_back(logWeightDenomT[i]);
50  }
51  }
52  }
53  } else {
54  detectorEnum.push_back(0);
55  depths.push_back(0);
56  logWeightDenom.push_back(conf.getParameter<double>("logWeightDenominator"));
57  }
58 
59  for(unsigned int i=0;i < depths.size();++i){
60  logWeightDenomInv.push_back(1./logWeightDenom[i]);
61  }
62 
63  // _logWeightDenom = std::make_pair(depths,logWeightDenomInv);
64  _logWeightDenom = std::make_tuple(detectorEnum,depths,logWeightDenomInv);
65 
66  _timeResolutionCalcBarrel.reset(nullptr);
67  if( conf.exists("timeResolutionCalcBarrel") ) {
68  const edm::ParameterSet& timeResConf =
69  conf.getParameterSet("timeResolutionCalcBarrel");
71  }
72  _timeResolutionCalcEndcap.reset(nullptr);
73  if( conf.exists("timeResolutionCalcEndcap") ) {
74  const edm::ParameterSet& timeResConf =
75  conf.getParameterSet("timeResolutionCalcEndcap");
77  }
78 
79  switch( _posCalcNCrystals ) {
80  case 5:
81  case 9:
82  case -1:
83  break;
84  default:
85  edm::LogError("Basic2DGenericPFlowPositionCalc") << "posCalcNCrystals not valid";
86  assert(0); // bug
87  }
88 
89 
90  }
T getParameter(std::string const &) const
VParameterSet const & getParameterSetVector(std::string const &name) const
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::tuple< std::vector< int >,std::vector< int >, std::vector< float > > _logWeightDenom
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)
overridevirtual
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, electrons_cff::bool, reco::PFCluster::calculatePositionREP(), bookConverter::compute(), declareDynArray, egammaForCoreTracking_cff::depth, reco::PFRecHit::depth(), particleFlowRecHitHBHE_cfi::detectorEnum, reco::PFRecHit::detId(), Exception, f, myMath::fast_logf(), objects.autophobj::float, dedxEstimators_cff::fraction, PFLayer::HCAL_BARREL1, PFLayer::HCAL_ENDCAP, photonIsolationHIProducer_cfi::hf, hfClusterShapes_cfi::hits, mps_fire::i, createfilelist::int, GeomDetEnumerators::isBarrel(), edm::isNotFinite(), gen::k, reco::PFRecHit::layer(), SiStripPI::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::PFCluster::setTimeError(), jetUpdater_cfi::sort, mathSSE::sqrt(), electronIdCutBased_cfi::threshold, reco::PFRecHit::time(), mitigatedMETSequence_cff::U, 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;};
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 
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  if (resGiven) {
106  cluster.setTimeError(std::sqrt(1.0f/float(cl_timeweight)));
107  }
108  cluster.setLayer(max_e_layer);
109 
110  // calculate the position
111  double depth = 0.0;
112  double position_norm = 0.0;
113  double x(0.0),y(0.0),z(0.0);
114  if( nullptr != mySeed.hit ) {
115  auto seedNeighbours = mySeed.hit->neighbours();
116  switch( _posCalcNCrystals ) {
117  case 5:
118  seedNeighbours = mySeed.hit->neighbours4();
119  break;
120  case 9:
121  seedNeighbours = mySeed.hit->neighbours8();
122  break;
123  default:
124  break;
125  }
126 
127  auto compute = [&](LHit const& rhf) {
128  const reco::PFRecHit & refhit = *rhf.hit;
129 
130  int cell_layer = (int)refhit.layer();
131  float threshold=0;
132 
133  for (unsigned int j=0; j<(std::get<2>(_logWeightDenom)).size(); ++j) {
134  // barrel is detecor type1
135  int detectorEnum=std::get<0>(_logWeightDenom)[j];
136  int depth=std::get<1>(_logWeightDenom)[j];
137 
138  if( ( cell_layer == PFLayer::HCAL_BARREL1 && detectorEnum==1 && refhit.depth()== depth)
139  || ( cell_layer == PFLayer::HCAL_ENDCAP && detectorEnum==2 && refhit.depth()== depth)
140  || detectorEnum==0
141  ) threshold=std::get<2>(_logWeightDenom)[j];
142 
143  }
144 
145  const auto rh_energy = rhf.energy * rhf.fraction;
146  const auto norm = ( rhf.fraction < _minFractionInCalc ?
147  0.0f :
148  std::max(0.0f,vdt::fast_logf(rh_energy*threshold)) );
149  const auto rhpos_xyz = refhit.position()*norm;
150  x += rhpos_xyz.x();
151  y += rhpos_xyz.y();
152  z += rhpos_xyz.z();
153  depth += refhit.depth()*norm;
154  position_norm += norm;
155 
156  };
157 
158  if(_posCalcNCrystals != -1) // sorted to make neighbour search faster (maybe)
159  std::sort(hits.begin(),hits.end(),[](LHit const& a, LHit const& b) { return a.hit<b.hit;});
160 
161 
162  if(_posCalcNCrystals == -1)
163  for( auto const & rhf : hits ) compute(rhf);
164  else { // only seed and its neighbours
165  compute(mySeed);
166  // search seedNeighbours to find energy fraction in cluster (sic)
167  unInitDynArray(reco::PFRecHit const *,seedNeighbours.size(),nei);
168  for(auto k : seedNeighbours){
169  nei.push_back(recHitCollection+k);
170  }
171  std::sort(nei.begin(),nei.end());
172  struct LHitLess {
173  auto operator()(LHit const &a, reco::PFRecHit const * b) const {return a.hit<b;}
174  auto operator()(reco::PFRecHit const * b, LHit const &a) const {return b<a.hit;}
175  };
176  std::set_intersection(hits.begin(),hits.end(),nei.begin(),nei.end(),
177  boost::make_function_output_iterator(compute),
178  LHitLess()
179  );
180  }
181  } else {
182  throw cms::Exception("Basic2DGenerticPFlowPositionCalc")
183  << "Cluster seed hit is null, something is wrong with PFlow RecHit!";
184  }
185 
186  if( position_norm < _minAllowedNorm ) {
187  edm::LogError("WeirdClusterNormalization")
188  << "PFCluster too far from seeding cell: set position to (0,0,0).";
189  cluster.setPosition(math::XYZPoint(0,0,0));
190  cluster.calculatePositionREP();
191  } else {
192  const double norm_inverse = 1.0/position_norm;
193  x *= norm_inverse;
194  y *= norm_inverse;
195  z *= norm_inverse;
196  depth *= norm_inverse;
197  cluster.setPosition(math::XYZPoint(x,y,z));
198  cluster.setDepth(depth);
199  cluster.calculatePositionREP();
200  }
201 }
void setLayer(PFLayer::Layer layer)
set layer
Definition: PFCluster.cc:112
float time() const
timing for cleaned hits
Definition: PFRecHit.h:102
unsigned detId() const
rechit detId
Definition: PFRecHit.h:93
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
void setPosition(const math::XYZPoint &p)
Definition: CaloCluster.h:117
bool isBarrel(GeomDetEnumerators::SubDetector m)
void setTime(float time, float timeError=0)
Definition: PFCluster.h:92
void setEnergy(double energy)
Definition: CaloCluster.h:113
PositionType const & position() const
rechit cell centre x, y, z
Definition: PFRecHit.h:117
int depth() const
depth for segemntation
Definition: PFRecHit.h:105
PFLayer::Layer layer() const
rechit layer
Definition: PFRecHit.h:96
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
T sqrt(T t)
Definition: SSEVec.h:18
std::tuple< std::vector< int >,std::vector< int >, std::vector< float > > _logWeightDenom
#define unInitDynArray(T, n, x)
Definition: DynArray.h:58
double f[11][100]
int k[5][pyjets_maxn]
Layer
layer definition
Definition: PFLayer.h:31
void setTimeError(float timeError)
Definition: PFCluster.h:93
DetId seed() const
return DetId of seed
Definition: CaloCluster.h:207
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
def compute(min, max)
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
#define UNLIKELY(x)
Definition: Likely.h:21
float fast_logf(float x)
void Basic2DGenericPFlowPositionCalc::calculateAndSetPositions ( reco::PFClusterCollection clusters)
overridevirtual

Implements PFCPositionCalculatorBase.

Definition at line 29 of file Basic2DGenericPFlowPositionCalc.cc.

References calculateAndSetPositionActual().

Referenced by Basic2DGenericPFlowPositionCalc(), and calculateAndSetPosition().

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

std::tuple<std::vector<int> ,std::vector<int> , std::vector<float> > Basic2DGenericPFlowPositionCalc::_logWeightDenom
private
const float Basic2DGenericPFlowPositionCalc::_minAllowedNorm
private

Definition at line 101 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