32 double vWire = 0, DirX, DirY, DirZ, DirU, dX, dU, arg;
33 unsigned short ipl, lastpl, indx;
61 DirX = 1 - DirY * DirY - DirZ * DirZ;
63 if(DirX < 0) DirX = 0;
88 TVector3& VtxPos, TVector3& VtxPosErr,
89 std::vector<TVector3>& TrkDir, std::vector<TVector3>& TrkDirErr,
100 if(hitX.size() < 2)
return;
101 if(hitX.size() != hitWID.size())
return;
102 if(hitX.size() != hitXErr.size())
return;
103 if(hitX.size() != TrkDir.size())
return;
106 const unsigned int ntrks = hitX.size();
107 const unsigned int npars = 3 + 2 * ntrks;
108 unsigned int npts = 0, itk;
109 for(itk = 0; itk < ntrks; ++itk) npts += hitX[itk].
size();
111 if(npts < ntrks)
return;
114 unsigned int cstat, tpc, nplanes, ipl, iht;
115 cstat = hitWID[0][0].Cryostat;
116 tpc = hitWID[0][0].TPC;
125 for(ipl = 0; ipl < nplanes; ++ipl) {
138 for(itk = 0; itk < ntrks; ++itk) {
141 for(iht = 0; iht < hitWID[itk].size(); ++iht) {
151 std::vector<double> par(npars);
152 std::vector<double> stp(npars);
153 std::vector<double> parerr(npars);
155 TMinuit *gMin =
new TMinuit(npars);
165 gMin->mnexcm(
"SET PRINT", arglist, 1, errFlag);
169 for(ipar = 0; ipar < 3; ++ipar) {
172 gMin->mnparm(ipar,
"", par[ipar], stp[ipar], -1E6, 1E6, errFlag);
177 for(itk = 0; itk < ntrks; ++itk) {
181 gMin->mnparm(ipar,
"", par[ipar], stp[ipar], -1.05, 1.05, errFlag);
185 gMin->mnparm(ipar,
"", par[ipar], stp[ipar], -1.05, 1.05, errFlag);
199 gMin->mnexcm(
"SET STRATEGY", arglist, 1, errFlag);
204 gMin->mnexcm(
"MIGRAD", arglist, 2, errFlag);
208 gMin->mnexcm(
"CALL", arglist, 1, errFlag);
212 for(
unsigned short ip = 0; ip < par.size(); ++ip) {
213 gMin->GetParameter(ip, par[ip], parerr[ip]);
217 for(ipar = 0; ipar < 3; ++ipar) {
218 VtxPos[ipar] = par[ipar];
219 VtxPosErr[ipar] = parerr[ipar];
222 bool returnTrkDirErrs = (TrkDirErr.size() == TrkDir.size());
223 for(itk = 0; itk < ntrks; ++itk) {
225 double arg = 1 - par[ipar] * par[ipar] - par[ipar + 1] * par[ipar + 1];
227 TrkDir[itk](0) = sqrt(arg);
228 TrkDir[itk](1) = par[ipar];
229 TrkDir[itk](2) = par[ipar + 1];
230 if(returnTrkDirErrs) {
232 double errY = parerr[ipar] / par[ipar];
233 double errZ = parerr[ipar + 1] / par[ipar + 1];
234 TrkDirErr[itk](0) = sqrt(arg * (errY * errY + errZ * errZ));
235 TrkDirErr[itk](1) = parerr[ipar];
236 TrkDirErr[itk](2) = parerr[ipar + 1];
geo::Length_t WireCoordinate(double YPos, double ZPos, geo::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.
std::vector< std::vector< double > > HitX
std::vector< std::vector< unsigned short > > Plane
std::array< double, 3 > OrthY
geo::Length_t WirePitch(geo::PlaneID const &planeid) const
Returns the distance between two consecutive wires.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
std::vector< TVector3 > Dir
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
std::array< double, 3 > FirstWire
Definition of data types for geometry description.
Class defining a plane for tracking. It provides various functionalities to convert track parameters ...
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)
const TPCGeo & TPC(unsigned int itpc) const
Return the itpc'th TPC in the cryostat.
art::ServiceHandle< geo::Geometry const > geom
std::vector< std::vector< double > > HitXErr
std::array< double, 3 > OrthZ
static VertexFitMinuitStruct fVtxFitMinStr
Encapsulate the construction of a single detector plane.