Calculation of several variables related to sliding linear fit.
110 const TwoDSlidingFitResult slidingFitResultLarge(
113 if (slidingFitResult.GetLayerFitResultMap().empty())
114 throw StatusCodeException(STATUS_CODE_NOT_INITIALIZED);
116 straightLineLengthLarge =
117 (slidingFitResultLarge.GetGlobalMaxLayerPosition() - slidingFitResultLarge.GetGlobalMinLayerPosition()).GetMagnitude();
118 rmsSlidingLinearFit = 0.f;
122 CartesianVector previousFitPosition(slidingFitResult.GetGlobalMinLayerPosition());
125 for (
const auto &mapEntry : slidingFitResult.GetLayerFitResultMap())
127 const LayerFitResult &layerFitResult(mapEntry.second);
128 rmsSlidingLinearFit += layerFitResult.GetRms();
130 CartesianVector thisFitPosition(0.
f, 0.
f, 0.
f);
131 slidingFitResult.GetGlobalPosition(layerFitResult.GetL(), layerFitResult.GetFitT(), thisFitPosition);
134 slidingFitResultLarge.GetLayerFitResultMap().find(slidingFitResultLarge.GetLayer(layerFitResult.GetL()));
136 if (slidingFitResultLarge.GetLayerFitResultMap().end() == iterLarge)
137 throw StatusCodeException(STATUS_CODE_FAILURE);
139 diffWithStraightLineVector.push_back(static_cast<float>(std::fabs(layerFitResult.GetFitT() - iterLarge->second.GetFitT())));
141 const float thisGapLength((thisFitPosition - previousFitPosition).GetMagnitude());
142 const float minZ(
std::min(thisFitPosition.GetZ(), previousFitPosition.GetZ()));
143 const float maxZ(
std::max(thisFitPosition.GetZ(), previousFitPosition.GetZ()));
145 if ((maxZ - minZ) > std::numeric_limits<float>::epsilon())
148 const float correctedGapLength(thisGapLength * (1.
f - gapZ / (maxZ - minZ)));
150 if (correctedGapLength > maxFitGapLength)
151 maxFitGapLength = correctedGapLength;
154 dTdLMin =
std::min(dTdLMin, static_cast<float>(layerFitResult.GetGradient()));
155 dTdLMax =
std::max(dTdLMax, static_cast<float>(layerFitResult.GetGradient()));
156 previousFitPosition = thisFitPosition;
159 if (diffWithStraightLineVector.empty())
160 throw StatusCodeException(STATUS_CODE_FAILURE);
162 diffWithStraightLineMean = 0.f;
163 diffWithStraightLineSigma = 0.f;
165 for (
const float diffWithStraightLine : diffWithStraightLineVector)
166 diffWithStraightLineMean += diffWithStraightLine;
168 diffWithStraightLineMean /=
static_cast<float>(diffWithStraightLineVector.size());
170 for (
const float diffWithStraightLine : diffWithStraightLineVector)
171 diffWithStraightLineSigma += (diffWithStraightLine - diffWithStraightLineMean) * (diffWithStraightLine - diffWithStraightLineMean);
173 if (diffWithStraightLineSigma < 0.
f)
174 throw StatusCodeException(STATUS_CODE_FAILURE);
176 diffWithStraightLineSigma = std::sqrt(diffWithStraightLineSigma / static_cast<float>(diffWithStraightLineVector.size()));
177 dTdLWidth = dTdLMax - dTdLMin;
179 catch (
const StatusCodeException &)
181 straightLineLengthLarge = -1.f;
182 diffWithStraightLineMean = -1.f;
183 diffWithStraightLineSigma = -1.f;
185 maxFitGapLength = -1.f;
186 rmsSlidingLinearFit = -1.f;
static float CalculateGapDeltaZ(const pandora::Pandora &pandora, const float minZ, const float maxZ, const pandora::HitType hitType)
Calculate the total distance within a given 2D region that is composed of detector gaps...
static pandora::HitType GetClusterHitType(const pandora::Cluster *const pCluster)
Get the hit type associated with a two dimensional cluster.
static float GetWireZPitch(const pandora::Pandora &pandora, const float maxWirePitchDiscrepancy=0.01)
Return the wire pitch.
unsigned int m_slidingLinearFitWindow
The sliding linear fit window.
static int max(int a, int b)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
unsigned int m_slidingLinearFitWindowLarge
The sliding linear fit window - should be large, providing a simple linear fit.
Dft::FloatVector FloatVector