12 #include <sys/types.h> 34 double vWire = 0, DirX, DirY, DirZ, DirU, dX, dU, arg;
35 unsigned short ipl, lastpl, indx;
58 if(std::abs(DirU) < 1
E-3 || std::abs(dU) < 1
E-3) {
63 DirX = 1 - DirY * DirY - DirZ * DirZ;
65 if(DirX < 0) DirX = 0;
90 TVector3& VtxPos, TVector3& VtxPosErr,
91 std::vector<TVector3>& TrkDir, 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, itk;
111 for(itk = 0; itk < ntrks; ++itk) npts += hitX[itk].size();
113 if(npts < ntrks)
return;
116 unsigned int cstat, tpc, nplanes, ipl, iht;
117 cstat = hitWID[0][0].Cryostat;
118 tpc = hitWID[0][0].TPC;
127 for(ipl = 0; ipl < nplanes; ++ipl) {
140 for(itk = 0; itk < ntrks; ++itk) {
143 for(iht = 0; iht < hitWID[itk].size(); ++iht) {
153 std::vector<double> par(npars);
154 std::vector<double> stp(npars);
155 std::vector<double> parerr(npars);
157 TMinuit *gMin =
new TMinuit(npars);
167 gMin->mnexcm(
"SET PRINT", arglist, 1, errFlag);
171 for(ipar = 0; ipar < 3; ++ipar) {
174 gMin->mnparm(ipar,
"", par[ipar], stp[ipar], -1E6, 1E6, errFlag);
179 for(itk = 0; itk < ntrks; ++itk) {
183 gMin->mnparm(ipar,
"", par[ipar], stp[ipar], -1.05, 1.05, errFlag);
187 gMin->mnparm(ipar,
"", par[ipar], stp[ipar], -1.05, 1.05, errFlag);
201 gMin->mnexcm(
"SET STRATEGY", arglist, 1, errFlag);
206 gMin->mnexcm(
"MIGRAD", arglist, 2, errFlag);
210 gMin->mnexcm(
"CALL", arglist, 1, errFlag);
214 for(
unsigned short ip = 0; ip < par.size(); ++ip) {
215 gMin->GetParameter(ip, par[ip], parerr[ip]);
219 for(ipar = 0; ipar < 3; ++ipar) {
220 VtxPos[ipar] = par[ipar];
221 VtxPosErr[ipar] = parerr[ipar];
224 bool returnTrkDirErrs = (TrkDirErr.size() == TrkDir.size());
225 for(itk = 0; itk < ntrks; ++itk) {
227 double arg = 1 - par[ipar] * par[ipar] - par[ipar + 1] * par[ipar + 1];
229 TrkDir[itk](0) = sqrt(arg);
230 TrkDir[itk](1) = par[ipar];
231 TrkDir[itk](2) = par[ipar + 1];
232 if(returnTrkDirErrs) {
234 double errY = parerr[ipar] / par[ipar];
235 double errZ = parerr[ipar + 1] / par[ipar + 1];
236 TrkDirErr[itk](0) = sqrt(arg * (errY * errY + errZ * errZ));
237 TrkDirErr[itk](1) = parerr[ipar];
238 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
art::ServiceHandle< geo::Geometry > geom
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.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
std::vector< TVector3 > Dir
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
std::array< double, 3 > FirstWire
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.
std::vector< std::vector< double > > HitXErr
std::array< double, 3 > OrthZ
static VertexFitMinuitStruct fVtxFitMinStr