1
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
3
* MAUS is free software: you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation, either version 3 of the License, or
6
* (at your option) any later version.
8
* MAUS is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with MAUS. If not, see <http://www.gnu.org/licenses/>.
20
* Various tools encapsulated in a class for use with SciFi data
21
* (in particular during Pattern Recognition).
32
#include "src/common_cpp/DataStructure/SciFiEvent.hh"
33
#include "src/common_cpp/DataStructure/SciFiSpacePoint.hh"
34
#include "src/common_cpp/Recon/SciFi/SimpleLine.hh"
35
#include "src/common_cpp/Recon/SciFi/SimpleCircle.hh"
37
namespace SciFiTools {
39
/** @brief Calculates the turning angle of a spacepoint w.r.t. the x' axis
41
* Calculates the turning angle from the x' axis, returning (phi_i + phi_0). In the case that
42
* x0 and y0 are used, it returns phi_0. Do not confuse the returned angle with phi_i itself,
43
* the turning angle wrt the x' axis not the x axis.
45
* @param xpos - x position of spacepoint
46
* @param ypos - y position of spacepoint
47
* @param circle - Contains the helix center
50
double calc_phi(double xpos, double ypos, const MAUS::SimpleCircle &circle);
52
/** @brief Calculate the residuals of a straight line to a spacepoint
53
* @param sp - The spacepoint
54
* @param line_x - The x projection of the line
55
* @param line_y - The y projection of the line
56
* @param dx - x residual
57
* @param dy - y residual
59
void calc_straight_residual(const MAUS::SciFiSpacePoint *sp, const MAUS::SimpleLine &line_x,
60
const MAUS::SimpleLine &line_y, double &dx, double &dy);
62
/** @brief Calculate the residual of a circle to a spacepoint
63
* @param sp - The spacepoint
64
* @param c - The circle (x0, y0 and rho must be set)
66
double calc_circle_residual(const MAUS::SciFiSpacePoint *sp, const MAUS::SimpleCircle &c);
68
/** @brief Take two spoints and return 2 straight lines connecting them, 1 in x-z, 1 in y-z
69
* @param sp1 - The first spacepoint
70
* @param sp2 - The second spacepoint
71
* @param line_x - The output line in x-z
72
* @param line_y - The output line in y-z
74
void draw_line(const MAUS::SciFiSpacePoint *sp1, const MAUS::SciFiSpacePoint *sp2,
75
MAUS::SimpleLine &line_x, MAUS::SimpleLine &line_y);
77
/** @brief Calculate the determinant for a 3*3 ROOT matrix
79
* Calculate the determinant for a 3*3 ROOT matrix (the in-built ROOT method falls over
80
* in the case of a singular matrix)
82
* @param m - The 3*3 ROOT TMatrixD (a matrix of doubles)
85
double det3by3(const TMatrixD &m);
87
/** @brief Create a circle from 3 spacepoints
89
* Create a circle from 3 spacepoints. A circle is unambiguously defined by 3 points.
90
* For 3 spacepoints we can make a simple circle without requiring least squares fitting.
91
* See the tracker documentation for a description of algorithms.
93
* @param sp1 - The first spacepoint
94
* @param sp2 - The second spacepoint
95
* @param sp3 - The third spacepoint
97
MAUS::SimpleCircle make_3pt_circle(const MAUS::SciFiSpacePoint *sp1,
98
const MAUS::SciFiSpacePoint *sp2,
99
const MAUS::SciFiSpacePoint *sp3);
101
/** @brief Short function to calculate the remainder of a division of num / denom
103
* Short function to calculate the remainder of a division of num / denom, slightly
104
* different to cmath's fod
106
* @param num - the numerator
107
* @param denom - the denominator
109
double my_mod(const double num, const double denom);
111
/** @brief Count the number of stations that have unused spacepoint
112
* @param spnts_by_station - Input 2D vector of spacepoints sorted by station
114
int num_stations_with_unused_spnts(const MAUS::SpacePoint2dPArray &spnts_by_station);
116
/** @brief Changes dphi vector to ds vector (scalar multiplication of each element phi by R).
117
* @param R - radius of helix
118
* @param phi - vector containing turning angle for each spacepoint
120
std::vector<double> phi_to_s(const double R, const std::vector<double> &phi);
122
/** @brief Create a 2D vector of SciFi spacepoints sorted by tracker station
124
* Take an input vector of spacepoints and output a 2D vector of spacepoints
125
* where the first index is the station the spacepoint is located in.
127
* @param spnts - A vector of all the input spacepoints
128
* @param spnts_by_station - Output 2D vector of spacepoints sorted by station
131
void sort_by_station(const MAUS::SciFiSpacePointPArray &spnts,
132
MAUS::SpacePoint2dPArray &spnts_by_station);
134
/** @brief Create a 2D vector of SciFi spacepoints sorted by tracker
136
* Take an input vector of spacepoints and output a 2D vector of spacepoints
137
* where the first index is the tracker the spacepoint is located in.
139
* @param spnts - A vector of all the input spacepoints
142
MAUS::SpacePoint2dPArray sort_by_tracker(const std::vector<MAUS::SciFiSpacePoint*> &spnts);
144
/** @brief Count and return how many tracker stations have at least 1 unused spacepoint
145
* @param spnts_by_station - Input 2D vector of spacepoints sorted by station
146
* @param stations_hit - Output vector holding the numbers of each station with at
147
* least 1 unused spacepoint
148
* @param stations_not_hit - Output vector holding the numbers of each station with
149
* no unused spacepoints
151
void stations_with_unused_spnts(const MAUS::SpacePoint2dPArray &spnts_by_station,
152
std::vector<int> &stations_hit,
153
std::vector<int> &stations_not_hit);
155
} // ~namespace SciFiTools