12 #include "vdt/vdtMath.h" 14 #include <boost/iterator/function_output_iterator.hpp> 29 std::vector<double> logWeightDenom;
30 std::vector<float> logWeightDenomInv;
32 const auto& logWeightDenominatorByDetectorPSet = conf.
getParameterSetVector(
"logWeightDenominatorByDetector");
33 if (!logWeightDenominatorByDetectorPSet.empty()) {
34 for (
const auto&
pset : logWeightDenominatorByDetectorPSet) {
37 throw cms::Exception(
"logWeightDenominatorByDetectorPSet") <<
"logWeightDenominator : detector not specified";
41 std::vector<int> depthsT =
pset.getParameter<std::vector<int> >(
"depths");
42 std::vector<double> logWeightDenomT =
pset.getParameter<std::vector<double> >(
"logWeightDenominator");
43 if (logWeightDenomT.size() != depthsT.size()) {
44 throw cms::Exception(
"logWeightDenominator") <<
"logWeightDenominator mismatch with the numbers of depths";
46 for (
unsigned int i = 0;
i < depthsT.size(); ++
i) {
52 logWeightDenom.push_back(logWeightDenomT[
i]);
59 logWeightDenom.push_back(conf.
getParameter<
double>(
"logWeightDenominator"));
62 for (
unsigned int i = 0;
i <
depths.size(); ++
i) {
63 logWeightDenomInv.push_back(1. / logWeightDenom[
i]);
70 const auto& timeResConfBarrel = conf.
getParameterSet(
"timeResolutionCalcBarrel");
71 if (!timeResConfBarrel.empty() && timeResConfBarrel.getParameter<
double>(
"threshHighE") >= 0)
74 const auto& timeResConfEndcap = conf.
getParameterSet(
"timeResolutionCalcEndcap");
75 if (!timeResConfEndcap.empty() && timeResConfEndcap.getParameter<
double>(
"threshHighE") >= 0)
84 edm::LogError(
"Basic2DGenericPFlowPositionCalc") <<
"posCalcNCrystals not valid";
97 std::tuple<std::vector<int>, std::vector<int>, std::vector<float> >
_logWeightDenom;
109 inline bool isBarrel(
int cell_layer) {
128 if (!cluster.
seed()) {
129 throw cms::Exception(
"ClusterWithNoSeed") <<
" Found a cluster with no seed: " << cluster;
131 double cl_energy = 0;
133 double cl_timeweight = 0.0;
143 auto const recHitCollection =
154 auto k =
hf.recHitRef().key();
155 auto p = recHitCollection +
k;
161 for (
auto const& rhf :
hits) {
165 const auto rh_fraction = rhf.fraction;
166 const auto rh_rawenergy = rhf.energy;
167 const auto rh_energy = rh_rawenergy * rh_fraction;
170 throw cms::Exception(
"PFClusterAlgo") <<
"rechit " << refhit.
detId() <<
" has a NaN energy... " 171 <<
"The input of the particle flow clustering seems to be corrupted.";
174 cl_energy += rh_energy;
178 int cell_layer = (
int)refhit.
layer();
181 cl_time += rh_fraction * refhit.
time() * res2;
182 cl_timeweight += rh_fraction * res2;
184 const double rh_rawenergy2 = rh_rawenergy * rh_rawenergy;
185 cl_timeweight += rh_rawenergy2 * rh_fraction;
186 cl_time += rh_rawenergy2 * rh_fraction * refhit.
time();
189 if (rh_energy > max_e) {
191 max_e_layer = refhit.
layer();
196 cluster.
setTime(cl_time / cl_timeweight);
203 bool single_depth =
true;
206 double position_norm = 0.0;
207 double x(0.0),
y(0.0),
z(0.0);
208 if (
nullptr !=
mySeed.hit) {
209 auto seedNeighbours =
mySeed.hit->neighbours();
212 seedNeighbours =
mySeed.hit->neighbours4();
215 seedNeighbours =
mySeed.hit->neighbours8();
221 auto compute = [&](LHit
const& rhf) {
224 int cell_layer = (
int)refhit.
layer();
227 if (hcalCuts !=
nullptr &&
247 ref_depth = refhit.
depth();
248 else if (refhit.
depth() != ref_depth) {
250 single_depth =
false;
252 const auto rh_energy = rhf.energy * rhf.fraction;
255 const auto rhpos_xyz = refhit.
position() * norm;
260 position_norm += norm;
267 for (
auto const& rhf :
hits)
273 for (
auto k : seedNeighbours) {
274 nei.push_back(recHitCollection +
k);
282 hits.begin(),
hits.end(), nei.begin(), nei.end(), boost::make_function_output_iterator(
compute), LHitLess());
286 <<
"Cluster seed hit is null, something is wrong with PFlow RecHit!";
290 edm::LogError(
"WeirdClusterNormalization") <<
"PFCluster too far from seeding cell: set position to (0,0,0).";
294 const double norm_inverse = 1.0 / position_norm;
301 depth *= norm_inverse;
void setLayer(PFLayer::Layer layer)
set layer
T getParameter(std::string const &) const
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
constexpr bool isNotFinite(T x)
uint32_t cc[maxCellsPerHit]
void setPosition(const math::XYZPoint &p)
DetId seed() const
return DetId of seed
Basic2DGenericPFlowPositionCalc(const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
ParameterSet const & getParameterSet(std::string const &) const
void setTime(float time, float timeError=0)
PFLayer::Layer layer() const
rechit layer
const std::vector< reco::PFRecHitFraction > & recHitFractions() const
vector of rechit fractions
void setEnergy(double energy)
float time() const
timing for cleaned hits
Log< level::Error, false > LogError
PositionType const & position() const
rechit cell centre x, y, z
void calculateAndSetPositionActual(reco::PFCluster &, const HcalPFCuts *) const
void calculateAndSetPosition(reco::PFCluster &, const HcalPFCuts *) override
const Item * getValues(DetId fId, bool throwOnFail=true) const
unsigned detId() const
rechit detId
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)
constexpr uint32_t rawId() const
get the raw id
XYZPointD XYZPoint
point in space with cartesian internal representation
std::unique_ptr< CaloRecHitResolutionProvider > _timeResolutionCalcBarrel
const float _minFractionInCalc
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
VParameterSet const & getParameterSetVector(std::string const &name) const
void calculateAndSetPositions(reco::PFClusterCollection &, const HcalPFCuts *) override
void setDepth(double depth)
std::vector< PFCluster > PFClusterCollection
collection of PFCluster objects
#define DEFINE_EDM_PLUGIN(factory, type, name)
#define declareDynArray(T, n, x)
int depth() const
depth for segemntation
const float _minAllowedNorm