~chris-rogers/maus/emr_mc_digitization

« back to all changes in this revision

Viewing changes to src/common_cpp/Recon/SciFi/SciFiTools.hh

  • Committer: Chris Rogers
  • Date: 2014-04-16 11:48:45 UTC
  • mfrom: (707 merge)
  • mto: This revision was merged to the branch mainline in revision 711.
  • Revision ID: chris.rogers@stfc.ac.uk-20140416114845-h3u3q7pdcxkxvovs
Update to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
 
2
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 */
 
17
 
 
18
/** @class SciFiTools
 
19
 *
 
20
 * Various tools encapsulated in a class for use with SciFi data
 
21
 * (in particular during Pattern Recognition).
 
22
 *
 
23
 */
 
24
 
 
25
// C++ headers
 
26
#include <vector>
 
27
 
 
28
// ROOT headers
 
29
#include "TMatrixD.h"
 
30
 
 
31
// MAUS headers
 
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"
 
36
 
 
37
namespace SciFiTools {
 
38
 
 
39
    /** @brief Calculates the turning angle of a spacepoint w.r.t. the x' axis
 
40
     *
 
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.
 
44
     * 
 
45
     * @param xpos - x position of spacepoint
 
46
     * @param ypos - y position of  spacepoint
 
47
     * @param circle - Contains the helix center
 
48
     *
 
49
     */
 
50
    double calc_phi(double xpos, double ypos, const MAUS::SimpleCircle &circle);
 
51
 
 
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
 
58
     */
 
59
    void calc_straight_residual(const MAUS::SciFiSpacePoint *sp, const MAUS::SimpleLine &line_x,
 
60
                                const MAUS::SimpleLine &line_y, double &dx, double &dy);
 
61
 
 
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) 
 
65
     */
 
66
    double calc_circle_residual(const MAUS::SciFiSpacePoint *sp, const MAUS::SimpleCircle &c);
 
67
 
 
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
 
73
     */
 
74
    void draw_line(const MAUS::SciFiSpacePoint *sp1, const MAUS::SciFiSpacePoint *sp2,
 
75
                   MAUS::SimpleLine &line_x, MAUS::SimpleLine &line_y);
 
76
 
 
77
    /** @brief Calculate the determinant for a 3*3 ROOT matrix
 
78
     *
 
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)
 
81
     *
 
82
     * @param m - The 3*3 ROOT TMatrixD (a matrix of doubles)
 
83
     *
 
84
     */
 
85
    double det3by3(const TMatrixD &m);
 
86
 
 
87
    /** @brief Create a circle from 3 spacepoints
 
88
     *
 
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.
 
92
     *
 
93
     *  @param sp1 - The first spacepoint
 
94
     *  @param sp2 - The second spacepoint
 
95
     *  @param sp3 - The third spacepoint
 
96
     */
 
97
    MAUS::SimpleCircle make_3pt_circle(const MAUS::SciFiSpacePoint *sp1,
 
98
                                       const MAUS::SciFiSpacePoint *sp2,
 
99
                                       const MAUS::SciFiSpacePoint *sp3);
 
100
 
 
101
    /** @brief Short function to calculate the remainder of a division of num / denom
 
102
     *
 
103
     * Short function to calculate the remainder of a division of num / denom, slightly 
 
104
     * different to cmath's fod
 
105
     *
 
106
     * @param num - the numerator
 
107
     * @param denom - the denominator
 
108
     */
 
109
    double my_mod(const double num, const double denom);
 
110
 
 
111
    /** @brief Count the number of stations that have unused spacepoint
 
112
     *  @param spnts_by_station - Input 2D vector of spacepoints sorted by station
 
113
     */
 
114
    int num_stations_with_unused_spnts(const MAUS::SpacePoint2dPArray &spnts_by_station);
 
115
 
 
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
 
119
     */
 
120
     std::vector<double> phi_to_s(const double R, const std::vector<double> &phi);
 
121
 
 
122
    /** @brief Create a 2D vector of SciFi spacepoints sorted by tracker station
 
123
     *
 
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.
 
126
     *
 
127
     *  @param spnts - A vector of all the input spacepoints
 
128
     *  @param spnts_by_station - Output 2D vector of spacepoints sorted by station
 
129
     *
 
130
     */
 
131
    void sort_by_station(const MAUS::SciFiSpacePointPArray &spnts,
 
132
                         MAUS::SpacePoint2dPArray &spnts_by_station);
 
133
 
 
134
    /** @brief Create a 2D vector of SciFi spacepoints sorted by tracker
 
135
     *
 
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.
 
138
     *
 
139
     *  @param spnts - A vector of all the input spacepoints
 
140
     *
 
141
     */
 
142
    MAUS::SpacePoint2dPArray sort_by_tracker(const std::vector<MAUS::SciFiSpacePoint*> &spnts);
 
143
 
 
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
 
150
     */
 
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);
 
154
 
 
155
} // ~namespace SciFiTools