16 const std::string& name,
17 const IInterface* parent ) :
18 base_class(
type, name, parent )
27 m_selectionFunction = [](
const std::vector<const xAOD::AFPSiHitsCluster*>&) {
return true; };
32 std::vector<int> plane{0, 0, 0, 0};
34 for (
auto&& cluster : t) {
35 const int p = cluster->pixelLayerID();
39 auto HasAnyClusters = [](
int n) {
return n > 0; };
47 std::vector<int> plane{0, 0, 0, 0};
49 for (
auto&& cluster : t) {
50 const int p = cluster->pixelLayerID();
54 auto HasMultipleClusters = [](
int n) {
return n > 1; };
56 if (std::any_of(plane.begin(), plane.end(), HasMultipleClusters)) {
return false; }
67 return StatusCode::FAILURE;
72 return StatusCode::SUCCESS;
80 const double xa =
a->xLocal();
81 const double ya =
a->yLocal();
83 const double xb = b->xLocal();
84 const double yb = b->yLocal();
86 const double dx = xa - xb;
87 const double dy = ya - yb;
89 return dx * dx + dy * dy <= maxDistanceSq;
96 std::vector<const xAOD::AFPSiHitsCluster*> track;
97 track.push_back(init);
99 std::vector<const xAOD::AFPSiHitsCluster*> newNeighbours;
103 newNeighbours.clear();
104 for (
auto&& b : toJoin) {
106 for (
auto&&
a : track) {
111 newNeighbours.push_back(b);
117 for (
auto& t : newNeighbours) {
121 }
while (!newNeighbours.empty());
131 double meanx = 0, meany = 0;
132 for (
const auto& [
y,
x] : YX) {
139 double numerator = 0, denominator = 0;
140 for (
const auto& [
y,
x] : YX) {
141 const double dy =
y - meany;
142 const double dx =
x - meanx;
144 numerator += dx * dy;
145 denominator += dx * dx;
147 if (denominator == 0){
148 ATH_MSG_WARNING(
"AFPSiDLinRegTool::linearRegression: denominator is zero");
151 const double slope = numerator / denominator;
152 const double position = meany - slope * meanx;
154 return {position, slope};
161 if(!clusters.isValid())
164 return StatusCode::SUCCESS;
168 std::list<const xAOD::AFPSiHitsCluster*> clustersInStation;
169 std::copy_if(clusters->begin(), clusters->end(), std::back_inserter(clustersInStation),
170 [
this](
auto cluster) { return cluster->stationID() == m_stationID; });
176 while (!clustersInStation.empty())
179 const auto *
const initialCluster = clustersInStation.front();
180 clustersInStation.pop_front();
187 ATH_MSG_DEBUG(
"track candidate of size " << clusterOfClusters.size() <<
" did not pass selection.");
191 auto *track = outputContainer->push_back(std::make_unique<xAOD::AFPTrack>());
197 for (
const auto *
const cluster : clusterOfClusters) {
200 track->addCluster(clusterLink);
203 const int nClusters = track->clusters().size();
207 track->setNClusters(nClusters);
212 outputContainer->pop_back();
223 if (nClusters == 1) {
224 x = (*(track->clusters().at(0)))->xLocal();
225 y = (*(track->clusters().at(0)))->yLocal();
229 std::vector<std::pair<double, double>> XZ;
230 std::vector<std::pair<double, double>> YZ;
232 for (
int i = 0; i < nClusters; i++) {
242 std::tie(
x, xSlope) = linregx;
243 std::tie(
y, ySlope) = linregy;
245 for (
int i = 0; i < nClusters; i++) {
248 const double z = cluster->
zLocal();
252 const double dx = cluster->
xLocal() - (
x + xSlope *
z);
253 const double dy = cluster->
yLocal() - (
y + ySlope *
z);
255 chi2 += dx * dx / (ex * ex);
256 chi2 += dy * dy / (ey * ey);
261 track->setChi2(
chi2);
263 track->setXSlope(xSlope);
265 track->setYSlope(ySlope);
266 track->setZLocal(0.);
270 std::vector<int> clustersPlane{0, 0, 0, 0};
271 for (
const auto& cl : track->clusters()) {
272 ++clustersPlane[(*cl)->pixelLayerID()];
274 auto HasNoClusters = [](
int n) {
return n == 0; };
275 track->setNHoles(std::count_if(clustersPlane.begin(), clustersPlane.end(), HasNoClusters));
278 ATH_MSG_DEBUG(
"new track with " << track->clusters().size() <<
" clusters, x: " << track->xLocal()
279 <<
", y: " << track->yLocal() <<
", sx: " << track->xSlope()
280 <<
", sy: " << track->ySlope() <<
", chi2: " << track->chi2());
281 for (
auto&& cluster : track->clusters())
283 ATH_MSG_DEBUG(
'\t' << (*cluster)->xLocal() <<
" " << (*cluster)->yLocal() <<
" " << (*cluster)->zLocal());
287 return StatusCode::SUCCESS;
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define CHECK(...)
Evaluate an expression and check for errors.
ElementLink implementation for ROOT usage.
bool toContainedElement(BaseConstReference container, ElementType element)
Set link to point to given element (slowest).
float zLocal() const
Cluster position along Z axis in station local coordinate system.
float yLocalErr() const
Uncertainty of cluster position along Y axis in station local coordinate system.
float xLocal() const
Cluster position along X axis in station local coordinate system.
float yLocal() const
Cluster position along Y axis in station local coordinate system.
float xLocalErr() const
Uncertainty of cluster position along X axis in station local coordinate system.
static constexpr int linReg
linear regression algorithm id=1
double chi2(TH1 *h0, TH1 *h1)
AFPSiHitsCluster_v1 AFPSiHitsCluster