32 double vWire = 0, DirX, DirY, DirZ, DirU, dX, dU, arg;
33 unsigned short ipl, lastpl, indx;
63 DirX = 1 - DirY * DirY - DirZ * DirZ;
65 if (DirX < 0) DirX = 0;
90 std::vector<TVector3>& TrkDir,
91 std::vector<TVector3>& TrkDirErr,
102 if (hitX.size() < 2)
return;
103 if (hitX.size() != hitWID.size())
return;
104 if (hitX.size() != hitXErr.size())
return;
105 if (hitX.size() != TrkDir.size())
return;
108 const unsigned int ntrks = hitX.size();
109 const unsigned int npars = 3 + 2 * ntrks;
110 unsigned int npts = 0;
111 for (
unsigned int itk = 0; itk < ntrks; ++itk)
112 npts += hitX[itk].
size();
114 if (npts < ntrks)
return;
126 for (
unsigned int ipl = 0; ipl < nplanes; ++ipl) {
142 for (
unsigned int itk = 0; itk < ntrks; ++itk) {
145 for (std::size_t iht = 0; iht < hitWID[itk].size(); ++iht) {
155 std::vector<double> par(npars);
156 std::vector<double> stp(npars);
157 std::vector<double> parerr(npars);
159 TMinuit* gMin =
new TMinuit(npars);
169 gMin->mnexcm(
"SET PRINT", arglist, 1, errFlag);
172 for (
unsigned int ipar = 0; ipar < 3u; ++ipar) {
175 gMin->mnparm(ipar,
"", par[ipar], stp[ipar], -1E6, 1E6, errFlag);
180 for (
unsigned int itk = 0; itk < ntrks; ++itk) {
181 unsigned int ipar = 3 + 2 * itk;
184 gMin->mnparm(ipar,
"", par[ipar], stp[ipar], -1.05, 1.05, errFlag);
188 gMin->mnparm(ipar,
"", par[ipar], stp[ipar], -1.05, 1.05, errFlag);
193 gMin->mnexcm(
"SET STRATEGY", arglist, 1, errFlag);
198 gMin->mnexcm(
"MIGRAD", arglist, 2, errFlag);
202 gMin->mnexcm(
"CALL", arglist, 1, errFlag);
206 for (
unsigned short ip = 0; ip < par.size(); ++ip) {
207 gMin->GetParameter(ip, par[ip], parerr[ip]);
211 for (
unsigned int ipar = 0; ipar < 3u; ++ipar) {
212 VtxPos[ipar] = par[ipar];
213 VtxPosErr[ipar] = parerr[ipar];
216 bool returnTrkDirErrs = (TrkDirErr.size() == TrkDir.size());
217 for (
unsigned int itk = 0; itk < ntrks; ++itk) {
218 unsigned int const ipar = 3 + 2 * itk;
219 double arg = 1 - par[ipar] * par[ipar] - par[ipar + 1] * par[ipar + 1];
220 if (arg < 0) arg = 0;
221 TrkDir[itk](0) = sqrt(arg);
222 TrkDir[itk](1) = par[ipar];
223 TrkDir[itk](2) = par[ipar + 1];
224 if (returnTrkDirErrs) {
226 double errY = parerr[ipar] / par[ipar];
227 double errZ = parerr[ipar + 1] / par[ipar + 1];
228 TrkDirErr[itk](0) = sqrt(arg * (errY * errY + errZ * errZ));
229 TrkDirErr[itk](1) = parerr[ipar];
230 TrkDirErr[itk](2) = parerr[ipar + 1];
Length_t WireCoordinate(Point_t const &pos, PlaneID const &planeid) const
Returns the index of the nearest wire to the specified position.
std::vector< std::vector< unsigned short > > Wire
Encapsulate the construction of a single cyostat.
unsigned int Nplanes() const
Number of planes in this tpc.
The data type to uniquely identify a Plane.
std::vector< std::vector< double > > HitX
constexpr auto abs(T v)
Returns the absolute value of the argument.
std::vector< std::vector< unsigned short > > Plane
CryostatID_t Cryostat
Index of cryostat.
std::array< double, 3 > OrthY
TPCGeo const & TPC(TPCID const &tpcid=tpc_zero) const
Returns the specified TPC.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
std::vector< TVector3 > Dir
std::vector< std::vector< double > > HitXErr
The data type to uniquely identify a TPC.
std::array< double, 3 > FirstWire
Definition of data types for geometry description.
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
void VertexFit(std::vector< std::vector< geo::WireID >> const &hitWID, std::vector< std::vector< double >> const &hitX, std::vector< std::vector< double >> const &hitXErr, TVector3 &VtxPos, TVector3 &VtxPosErr, std::vector< TVector3 > &TrkDir, std::vector< TVector3 > &TrkDirErr, float &ChiDOF) const
static void fcnVtxPos(Int_t &, Double_t *, Double_t &fval, double *par, Int_t flag)
art::ServiceHandle< geo::Geometry const > geom
TPCID_t TPC
Index of the TPC within its cryostat.
std::array< double, 3 > OrthZ
static VertexFitMinuitStruct fVtxFitMinStr
Length_t WirePitch(PlaneID const &planeid=plane_zero) const
Returns the distance between two consecutive wires.
Encapsulate the construction of a single detector plane.