10#include "ecl/utility/Position.h"
13#include <ecl/geometry/ECLGeometryPar.h>
16#include <framework/logging/Logger.h>
28 B2Vector3D computePositionLiLo(
const std::vector<ECLCalDigit>& digits, std::vector<double>& weights,
29 const std::vector<double>& parameters)
33 const double energySum = computeEnergySum(digits, weights);
34 if (energySum <= 0.0) {
35 B2WARNING(
"ECL computePositionLiLo() energy sum zero or negative: " << energySum <<
", return (0, 0, 0)");
37 return liloPointError;
41 const double offset = parameters[0] - parameters[1] * TMath::Exp(-parameters[2] * energySum);
50 double logWeightSum = 0.0;
52 int nInLogWeightSum = 0;
53 double firstPhi = -999.;
54 double firstTheta = -999.;
55 bool foundSecondPhi =
false;
56 bool foundSecondTheta =
false;
59 for (
const auto& digit : digits) {
60 const double energy = digit.getEnergy();
61 const int cellid = digit.getCellId();
62 const double weight = weights.at(nTotal);
63 const B2Vector3D position = geom->GetCrystalPos(cellid - 1);
64 const double theta = position.Theta();
65 const double phi = position.Phi();
69 const double linearWeight = energy * weight / energySum;
70 const double logWeight = offset + TMath::Log(linearWeight);
73 linearPositionVector += linearWeight * position;
76 if (logWeight > 0.0) {
79 logPositionVector += logWeight * position;
80 logWeightSum += logWeight;
84 if (nInLogWeightSum == 1) {
88 if (!foundSecondPhi and fabs(phi - firstPhi) > 1e-4) {
89 foundSecondPhi =
true;
92 and fabs(theta - firstTheta) > 1e-4) {
93 foundSecondTheta =
true;
100 if (nInLogWeightSum > 0) logPositionVector *= 1. / logWeightSum;
104 liloPoint.SetTheta(foundSecondTheta ? logPositionVector.Theta() : linearPositionVector.Theta());
105 liloPoint.SetPhi(foundSecondPhi ? logPositionVector.Phi() : linearPositionVector.Phi());
106 liloPoint.SetMag(nInLogWeightSum > 0 ? logPositionVector.Mag() : linearPositionVector.Mag());
112 double computeEnergySum(
const std::vector<ECLCalDigit>& digits, std::vector<double>& weights)
117 for (
const auto& digit : digits) {
118 sum += digit.getEnergy() * weights.at(n);
static ECLGeometryPar * Instance()
Static method to get a reference to the ECLGeometryPar instance.
B2Vector3< double > B2Vector3D
typedef for common usage with double
Abstract base class for different kinds of events.