11 #include "GaudiKernel/MsgStream.h"
12 #include "GaudiKernel/ITHistSvc.h"
36 #include <TDecompLU.h>
38 #define MIN_TRACK_SEC 50 // min number of tracks per sector
96 std::string tree_title =
"Ambank " +
std::to_string(0) +
" matrices";
97 m_good_tree =
new TTree(tree_name.c_str(), tree_title.c_str());
103 return StatusCode::SUCCESS;
120 return StatusCode::SUCCESS;
127 TTree *old_tree = (TTree*)
file->Get(
"slice");
148 old_tree->GetEntry(0);
151 TTree *new_tree =
new TTree(
"slice",
"Slice boundaries");
176 return StatusCode::SUCCESS;
188 std::string tree_title =
"Ambank " +
std::to_string(0) +
" constants";
189 m_ctree =
new TTree(tree_name.c_str(), tree_title.c_str());
197 m_ctree->Branch(
"sectorID", &anInt,
"sectorID[nplane]/I");
198 m_ctree->Branch(
"hashID", &anInt,
"hashID[nplane]/I");
199 m_ctree->Branch(
"nhit", &aFloat,
"nhit/F");
201 m_ctree->Branch(
"Cd", &aDouble,
"Cd/D");
202 m_ctree->Branch(
"Cc", &aDouble,
"Cc/D");
203 m_ctree->Branch(
"Cf", &aDouble,
"Cf/D");
204 m_ctree->Branch(
"Cz0", &aDouble,
"Cz0/D");
205 m_ctree->Branch(
"Co", &aDouble,
"Co/D");
207 m_ctree->Branch(
"Vc", &aDouble,
"Vc[ndim]/D");
208 m_ctree->Branch(
"Vd", &aDouble,
"Vd[ndim]/D");
209 m_ctree->Branch(
"Vf", &aDouble,
"Vf[ndim]/D");
210 m_ctree->Branch(
"Vz0", &aDouble,
"Vz0[ndim]/D");
211 m_ctree->Branch(
"Vo", &aDouble,
"Vo[ndim]/D");
213 m_ctree->Branch(
"kernel", &aDouble,
"kernel[nkernel]/D");
214 m_ctree->Branch(
"kaverages", &aDouble,
"kaverages[nkaverages]/D");
217 return StatusCode::SUCCESS;
226 if (!
file.is_open())
return;
230 while (
file >> sector)
232 if (sector >= nSectors)
256 std::vector<module_t> & modules =
reader.getModules();
272 if (!success)
continue;
296 unsigned int nusable = acc_norm.
nusable() - 1;
298 coordsToUse[missing] =
false;
302 coordsToUse[missing+1] =
false;
336 std::vector<double> inv_covariance =
invert(
m_nCoords, mtx_reduced, coordsToUse);
339 std::vector<double> eigvals;
342 eigen(nusable,
m_nCoords, mtx_reduced, coordsToUse, eigvals, eigvecs);
345 geo =
makeConsts(acc_norm, coordsToUse, inv_covariance, eigvals, eigvecs);
358 float coverage =
static_cast<float>(
acc.track_bins.size());
359 m_ctree->SetBranchAddress(
"sectorID",
acc.FTK_modules.data());
360 m_ctree->SetBranchAddress(
"hashID", modules.data());
361 m_ctree->SetBranchAddress(
"nhit", &coverage);
363 m_ctree->SetBranchAddress(
"Cc", &
geo.pars.qOverPt);
364 m_ctree->SetBranchAddress(
"Cd", &
geo.pars.d0);
365 m_ctree->SetBranchAddress(
"Cf", &
geo.pars.phi);
366 m_ctree->SetBranchAddress(
"Cz0", &
geo.pars.z0);
367 m_ctree->SetBranchAddress(
"Co", &
geo.pars.eta);
369 m_ctree->SetBranchAddress(
"Vc",
geo.Vcurvature.data());
370 m_ctree->SetBranchAddress(
"Vd",
geo.Vd0.data());
371 m_ctree->SetBranchAddress(
"Vf",
geo.Vphi.data());
372 m_ctree->SetBranchAddress(
"Vz0",
geo.Vz0.data());
373 m_ctree->SetBranchAddress(
"Vo",
geo.Veta.data());
375 m_ctree->SetBranchAddress(
"kaverages",
geo.kaverages.data());
376 m_ctree->SetBranchAddress(
"kernel",
geo.kernel.data());
396 if (TMath::IsNaN(
value))
404 #define CHECK_NAN(var) (isNAN((var), #var))
461 double coverage =
static_cast<double>(
acc.track_bins.size());
462 size_t nCoords =
acc.hit_coords.size();
465 acc.pars[
i] /= coverage;
467 for (
unsigned i = 0;
i < nCoords;
i++)
469 acc.hit_coords[
i] /= coverage;
471 else acc.coords_usable[
i] =
true;
475 for (
unsigned i = 0;
i < nCoords;
i++)
477 acc.hit_x_QoP[
i] = (
acc.hit_x_QoP[
i] -
acc.hit_coords[
i] *
acc.pars.qOverPt * coverage) / (coverage-1);
478 acc.hit_x_d0[
i] = (
acc.hit_x_d0[
i] -
acc.hit_coords[
i] *
acc.pars.d0 * coverage) / (coverage-1);
479 acc.hit_x_z0[
i] = (
acc.hit_x_z0[
i] -
acc.hit_coords[
i] *
acc.pars.z0 * coverage) / (coverage-1);
480 acc.hit_x_phi[
i] = (
acc.hit_x_phi[
i] -
acc.hit_coords[
i] *
acc.pars.phi * coverage) / (coverage-1);
481 acc.hit_x_eta[
i] = (
acc.hit_x_eta[
i] -
acc.hit_coords[
i] *
acc.pars.eta * coverage) / (coverage-1);
484 for (
unsigned j =
i ; j < nCoords; ++j)
486 acc.covariance[j * nCoords +
i] =
acc.covariance[
i * nCoords + j] =
487 (
acc.covariance[
i * nCoords + j] -
acc.hit_coords[
i] *
acc.hit_coords[j] * coverage) / (coverage-1);
496 std::vector<double>
const & inv_covariance,
499 size_t nCoords =
acc.hit_coords.size();
510 if (!usable[
i])
continue;
511 for (
size_t j = 0; j < nCoords; j++)
513 if (!usable[j])
continue;
515 geo.kernel(
i, j) = eigvecs(
i, j) / sqrt(eigvals[
i]);
517 geo.kaverages[
i] += -
geo.kernel(
i, j) *
acc.hit_coords[j];
522 for (
size_t i = 0;
i < nCoords;
i++)
525 geo.pars.qOverPt += -
geo.Vcurvature[
i] *
acc.hit_coords[
i];
531 geo.real =
static_cast<int>(
acc.track_bins.size());
546 std::vector<double>
x(
n);
548 for (
size_t i = 0;
i <
n;
i++)
549 for (
size_t j = 0; j <
n; j++)
550 x[
i] +=
A[
i *
n + j] *
b[j];
574 TMatrixD mtx(
n,
n, mtx_v.data());
575 TMatrixD newmtx(nDimToUse, nDimToUse);
578 for (
size_t i = 0;
i <
n;
i++)
580 if (!usable[
i])
continue;
583 for (
size_t j = 0; j <
n; j++)
585 if (!usable[j])
continue;
586 newmtx[counteri][counterj] = mtx[
i][j];
589 assert(counterj == nDimToUse);
592 assert(counteri == nDimToUse);
608 std::vector<double> inv(n_full * n_full);
613 for (
size_t i = 0;
i < n_full;
i++)
615 if (!usable[
i])
continue;
618 for (
size_t j = 0; j < n_full; j++)
620 if (!usable[j])
continue;
621 inv[
i*n_full + j] = mtx[counteri][counterj];
648 TVectorD eigvals_redu;
649 TMatrixD eigvecs_redu = mtx.EigenVectors(eigvals_redu);
652 eigvals_full.resize(n_full, 0);
653 eigvecs_full.
resize(n_full, n_full, 0);
657 size_t j_redu = n_redu - 1;
658 for (
size_t i_full = 0; i_full < n_full; i_full++)
660 if (!usable[i_full])
continue;
663 for (
size_t j_full = 0; j_full < n_full; j_full++)
665 if (!usable[j_full])
continue;
666 eigvecs_full(i_full, j_full) = eigvecs_redu[i_redu][j_redu];
669 eigvals_full[i_full] = eigvals_redu[j_redu];
678 for (
size_t i = 0;
i <
size;
i++)
679 total += vec1[
i] *
vec2[
i];
688 if (!usable[
i])
continue;
691 auto project = [&](std::vector<double> & hit_x_par,
double &
par)
693 double pr =
dot(hit_x_par.data(),
geo.kernel[
i], nCoords) /
norm;
694 for (
int j = 0; j < nCoords; j++) hit_x_par[j] += -
geo.kernel(
i,j) *
pr;
713 return StatusCode::SUCCESS;
731 for (
int missing = 0; missing <
m_nLayers; missing++) {
743 return StatusCode::SUCCESS;
757 FILE *sector_file = fopen(sector_filename.c_str(),
"w");
758 FILE *sectorHW_file = fopen(sectorHW_filename.c_str(),
"w");
765 while (
reader.nextEntry())
768 size_t sector =
reader.getEntry();
770 fprintf(sector_file,
"%zu ", sector);
771 fprintf(sectorHW_file,
"%zu ", sector);
774 fprintf(sector_file,
"%d ",
acc.FTK_modules[
i]);
775 fprintf(sectorHW_file,
"%d ",
reader.getModules()[
i]);
777 fprintf(sector_file,
"0 %zu",
acc.track_bins.size());
778 fprintf(sector_file,
"\n");
779 fprintf(sectorHW_file,
"0 %zu",
acc.track_bins.size());
780 fprintf(sectorHW_file,
"\n");
787 fclose(sectorHW_file);
789 slice.saveSlices(slice_filename);
796 FILE *const_file = fopen(
filename.c_str(),
"w");
798 fprintf(const_file,
"! *** RECONSTRUCTION GEOMETRY CONSTANTS ***\n");
799 fprintf(const_file,
"\n");
800 fprintf(const_file,
"Version 2 ! File format version number\n");
801 fprintf(const_file,
"\n");
802 fprintf(const_file,
"! *** PHI is now in GLOBAL coordinate system ***\n");
803 fprintf(const_file,
" NPLANES\n");
805 fprintf(const_file,
" NSECTORS\n");
806 fprintf(const_file,
"%zu\n",geo_consts.size());
807 fprintf(const_file,
" NDIM\n");
808 fprintf(const_file,
" 2\n");
812 for (
size_t sector = 0; sector < geo_consts.size(); sector++)
815 fprintf(const_file,
"sector\n");
816 fprintf(const_file,
"%zu\n", sector);
818 fprintf(const_file,
" Vc \n");
820 fprintf(const_file,
"%e\n",geo_consts[sector].Vcurvature[
i]);
823 fprintf(const_file,
" Vd \n");
825 fprintf(const_file,
"%e\n",geo_consts[sector].Vd0[
i]);
828 fprintf(const_file,
" Vf \n");
830 fprintf(const_file,
"%e\n",geo_consts[sector].Vphi[
i]);
833 fprintf(const_file,
" Vz0 \n");
835 fprintf(const_file,
"%e\n",geo_consts[sector].Vz0[
i]);
838 fprintf(const_file,
" Vo \n");
840 fprintf(const_file,
"%e\n",geo_consts[sector].Veta[
i]);
843 fprintf(const_file,
"kaverages\n");
845 fprintf(const_file,
"%e\n",
m_geo_consts[sector].kaverages[
i]);
848 fprintf(const_file,
"kernel\n");
851 fprintf(const_file,
"%e\n",geo_consts[sector].kernel(
i, j));
855 fprintf(const_file,
"Cc\n");
856 fprintf(const_file,
"%e\n",geo_consts[sector].
pars.qOverPt);
858 fprintf(const_file,
"Cd\n");
859 fprintf(const_file,
"%e\n",geo_consts[sector].
pars.d0);
861 fprintf(const_file,
"Cf\n");
862 fprintf(const_file,
"%e\n",geo_consts[sector].
pars.phi);
864 fprintf(const_file,
"Cz0\n");
865 fprintf(const_file,
"%e\n",geo_consts[sector].
pars.z0);
867 fprintf(const_file,
"Co\n");
868 fprintf(const_file,
"%e\n",geo_consts[sector].
pars.eta);