10 #include "vdt/vdtMath.h"
12 #include <boost/iterator/function_output_iterator.hpp>
25 std::vector<int> detectorEnum;
26 std::vector<int> depths;
27 std::vector<double> logWeightDenom;
28 std::vector<float> logWeightDenomInv;
30 if (conf.
exists(
"logWeightDenominatorByDetector")) {
31 const std::vector<edm::ParameterSet>& logWeightDenominatorByDetectorPSet =
34 for (
const auto&
pset : logWeightDenominatorByDetectorPSet) {
35 if (!
pset.exists(
"detector")) {
36 throw cms::Exception(
"logWeightDenominatorByDetectorPSet") <<
"logWeightDenominator : detector not specified";
42 std::vector<int> depthsT =
pset.getParameter<std::vector<int> >(
"depths");
43 std::vector<double> logWeightDenomT =
pset.getParameter<std::vector<double> >(
"logWeightDenominator");
44 if (logWeightDenomT.size() != depthsT.size()) {
45 throw cms::Exception(
"logWeightDenominator") <<
"logWeightDenominator mismatch with the numbers of depths";
47 for (
unsigned int i = 0;
i < depthsT.size(); ++
i) {
49 detectorEnum.push_back(1);
51 detectorEnum.push_back(2);
52 depths.push_back(depthsT[
i]);
53 logWeightDenom.push_back(logWeightDenomT[i]);
58 detectorEnum.push_back(0);
60 logWeightDenom.push_back(conf.
getParameter<
double>(
"logWeightDenominator"));
63 for (
unsigned int i = 0;
i < depths.size(); ++
i) {
64 logWeightDenomInv.push_back(1. / logWeightDenom[
i]);
68 _logWeightDenom = std::make_tuple(detectorEnum, depths, logWeightDenomInv);
71 if (conf.
exists(
"timeResolutionCalcBarrel")) {
76 if (conf.
exists(
"timeResolutionCalcEndcap")) {
87 edm::LogError(
"Basic2DGenericPFlowPositionCalc") <<
"posCalcNCrystals not valid";
112 inline bool isBarrel(
int cell_layer) {
129 if (!cluster.
seed()) {
130 throw cms::Exception(
"ClusterWithNoSeed") <<
" Found a cluster with no seed: " << cluster;
132 double cl_energy = 0;
134 double cl_timeweight = 0.0;
144 auto const recHitCollection =
155 auto k = hf.recHitRef().key();
156 auto p = recHitCollection +
k;
157 hits[
i] = {
p, (*p).energy(), float(hf.fraction())};
162 for (
auto const& rhf : hits) {
166 const auto rh_fraction = rhf.fraction;
167 const auto rh_rawenergy = rhf.energy;
168 const auto rh_energy = rh_rawenergy * rh_fraction;
171 throw cms::Exception(
"PFClusterAlgo") <<
"rechit " << refhit.
detId() <<
" has a NaN energy... "
172 <<
"The input of the particle flow clustering seems to be corrupted.";
175 cl_energy += rh_energy;
179 int cell_layer = (int)refhit.
layer();
182 cl_time += rh_fraction * refhit.
time() * res2;
183 cl_timeweight += rh_fraction * res2;
185 const double rh_rawenergy2 = rh_rawenergy * rh_rawenergy;
186 cl_timeweight += rh_rawenergy2 * rh_fraction;
187 cl_time += rh_rawenergy2 * rh_fraction * refhit.
time();
190 if (rh_energy > max_e) {
192 max_e_layer = refhit.
layer();
197 cluster.
setTime(cl_time / cl_timeweight);
204 bool single_depth =
true;
207 double position_norm = 0.0;
208 double x(0.0),
y(0.0),
z(0.0);
209 if (
nullptr != mySeed.hit) {
210 auto seedNeighbours = mySeed.hit->neighbours();
213 seedNeighbours = mySeed.hit->neighbours4();
216 seedNeighbours = mySeed.hit->neighbours8();
222 auto compute = [&](LHit
const& rhf) {
225 int cell_layer = (int)refhit.
layer();
239 ref_depth = refhit.
depth();
240 else if (refhit.
depth() != ref_depth) {
242 single_depth =
false;
244 const auto rh_energy = rhf.energy * rhf.fraction;
247 const auto rhpos_xyz = refhit.
position() * norm;
251 depth += refhit.
depth() * norm;
252 position_norm += norm;
256 std::sort(hits.begin(), hits.end(), [](LHit
const&
a, LHit
const&
b) {
return a.hit <
b.hit; });
259 for (
auto const& rhf : hits)
265 for (
auto k : seedNeighbours) {
266 nei.push_back(recHitCollection + k);
268 std::sort(nei.begin(), nei.end());
270 auto operator()(LHit
const& a,
reco::PFRecHit const*
b)
const {
return a.hit <
b; }
271 auto operator()(
reco::PFRecHit const* b, LHit
const& a)
const {
return b < a.hit; }
274 hits.begin(), hits.end(), nei.begin(), nei.end(), boost::make_function_output_iterator(
compute), LHitLess());
278 <<
"Cluster seed hit is null, something is wrong with PFlow RecHit!";
282 edm::LogError(
"WeirdClusterNormalization") <<
"PFCluster too far from seeding cell: set position to (0,0,0).";
286 const double norm_inverse = 1.0 / position_norm;
293 depth *= norm_inverse;
void setLayer(PFLayer::Layer layer)
set layer
VParameterSet const & getParameterSetVector(std::string const &name) const
void calculateAndSetPositionActual(reco::PFCluster &) const
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
float time() const
timing for cleaned hits
unsigned detId() const
rechit detId
constexpr bool isNotFinite(T x)
void setPosition(const math::XYZPoint &p)
Basic2DGenericPFlowPositionCalc(const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
void setTime(float time, float timeError=0)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
void setEnergy(double energy)
Log< level::Error, false > LogError
PositionType const & position() const
rechit cell centre x, y, z
int depth() const
depth for segemntation
PFLayer::Layer layer() const
rechit layer
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
void calculatePositionREP()
computes posrep_ once and for all
#define unInitDynArray(T, n, x)
void setTimeError(float timeError)
DetId seed() const
return DetId of seed
void calculateAndSetPositions(reco::PFClusterCollection &) override
ParameterSet const & getParameterSet(std::string const &) const
XYZPointD XYZPoint
point in space with cartesian internal representation
T getParameter(std::string const &) const
std::unique_ptr< CaloRecHitResolutionProvider > _timeResolutionCalcBarrel
const float _minFractionInCalc
void calculateAndSetPosition(reco::PFCluster &) override
const std::vector< reco::PFRecHitFraction > & recHitFractions() const
vector of rechit fractions
std::tuple< std::vector< int >, std::vector< int >, std::vector< float > > _logWeightDenom
const int _posCalcNCrystals
std::unique_ptr< CaloRecHitResolutionProvider > _timeResolutionCalcEndcap
Basic2DGenericPFlowPositionCalc & operator=(const Basic2DGenericPFlowPositionCalc &)=delete
void setDepth(double depth)
std::vector< PFCluster > PFClusterCollection
collection of PFCluster objects
#define DEFINE_EDM_PLUGIN(factory, type, name)
#define declareDynArray(T, n, x)
const float _minAllowedNorm