37 edm::LogWarning(
"Alignment") <<
"[MuonMillepedeAlgorithm] constructed.";
49 ptCut =
cfg.getParameter<
double>(
"ptCut");
61 edm::LogWarning(
"Alignment") <<
"[MuonMillepedeAlgorithm] Initializing...";
74 std::map<std::string, TMatrixD *>
map;
79 TFile file_it(name_f);
81 if (file_it.IsZombie())
84 TList *m_list = file_it.GetListOfKeys();
85 if (m_list ==
nullptr) {
88 TKey *
index = (TKey *)m_list->First();
89 if (
index ==
nullptr) {
91 if (
index !=
nullptr) {
94 TMatrixD *mat = (TMatrixD *)
index->ReadObj();
95 std::map<std::string, TMatrixD *>::iterator node =
map.find(
objectName);
96 if (node ==
map.end()) {
97 TMatrixD *n_mat =
new TMatrixD(mat->GetNrows(), mat->GetNcols());
102 }
while (
index !=
nullptr);
110 std::map<std::string, TMatrixD *>::iterator m_it =
map.begin();
111 for (; m_it !=
map.end(); ++m_it) {
112 if (m_it->first.find(
"_invCov") != std::string::npos) {
113 std::string id_s = m_it->first.substr(0, m_it->first.find(
"_invCov"));
120 TMatrixD invMat(m_it->second->GetNrows(), m_it->second->GetNcols());
121 invMat = *(m_it->second);
124 TMatrixD weightMat(m_it->second->GetNcols(), 1);
125 weightMat = *(
map[id_w]);
127 TMatrixD solution(m_it->second->GetNrows(), 1);
128 solution = invMat * weightMat;
133 invMat.Write(cov.c_str());
134 n.Write(id_n.c_str());
135 solution.Write(sol.c_str());
150 edm::LogWarning(
"Alignment") <<
"[MuonMillepedeAlgorithm] Terminating";
159 ali->alignmentParameters()->setValid(
true);
162 edm::LogWarning(
"Alignment") <<
"[MuonMillepedeAlgorithm] Writing aligned parameters to file: "
167 std::map<std::string, AlgebraicMatrix *>::iterator invCov_it =
map_invCov.begin();
168 std::map<std::string, AlgebraicMatrix *>::iterator weightRes_it =
map_weightRes.begin();
169 std::map<std::string, AlgebraicMatrix *>::iterator n_it =
map_N.begin();
170 for (; n_it !=
map_N.end(); ++invCov_it, ++weightRes_it, ++n_it) {
171 TMatrixD tmat_invcov(0, 0);
172 this->
toTMat(invCov_it->second, &tmat_invcov);
173 TMatrixD tmat_weightres(0, 0);
174 this->
toTMat(weightRes_it->second, &tmat_weightres);
175 TMatrixD tmat_n(0, 0);
176 this->
toTMat(n_it->second, &tmat_n);
178 tmat_invcov.Write(invCov_it->first.c_str());
179 tmat_weightres.Write(weightRes_it->first.c_str());
180 tmat_n.Write(n_it->first.c_str());
188 tmat_mat->ResizeTo(am_mat->num_row(), am_mat->num_col());
189 for (
int c_i = 0; c_i < am_mat->num_row(); ++c_i) {
190 for (
int c_j = 0; c_j < am_mat->num_col(); ++c_j) {
191 (*tmat_mat)(c_i, c_j) = (*am_mat)[c_i][c_j];
206 for (ConstTrajTrackPairCollection::const_iterator it =
tracks.begin(); it !=
tracks.end(); it++) {
216 int nhit =
track->numberOfValidHits();
218 LogDebug(
"Alignment") <<
"New track pt,eta,phi,chi2n,hits: " <<
pt <<
"," <<
eta <<
"," <<
phi <<
"," <<
chi2n
224 std::vector<const TransientTrackingRecHit *> hitvec;
225 std::vector<TrajectoryStateOnSurface> tsosvec;
227 std::vector<TrajectoryMeasurement> measurements = traj->
measurements();
230 for (std::vector<TrajectoryMeasurement>::iterator im = measurements.begin(); im != measurements.end(); im++) {
238 hitvec.push_back(
hit);
239 tsosvec.push_back(tsos);
250 std::vector<TrajectoryStateOnSurface>::const_iterator itsos = tsosvec.begin();
251 std::vector<const TransientTrackingRecHit *>::const_iterator ihit = hitvec.begin();
255 while (itsos != tsosvec.end()) {
257 const GeomDet *det = (*ihit)->det();
264 if (ali !=
nullptr && (*ihit)->geographicalId().subdetId() == 1) {
267 if ((*ihit)->dimension() == 4 || ((*ihit)->dimension() == 2 && m_Chamber.station() == 4))
287 int m_index[] = {2, 3, 0, 1};
288 for (
int c_ei = 0; c_ei < 4; ++c_ei) {
289 for (
int c_ej = 0; c_ej < 4; ++c_ej) {
290 CovMat[m_index[c_ei]][m_index[c_ej]] = rawCovMat(c_ei + 1, c_ej + 1);
296 CovMat.invert(inv_check);
297 if (inv_check != 0) {
298 edm::LogError(
"Alignment") <<
"Covariance Matrix inversion failed";
306 if (m_Chamber.station() == 4) {
308 residuals[0][0] = ihit4D[2] - alivec[3];
309 residuals[1][0] = 0.0;
310 residuals[2][0] = ihit4D[0] - alivec[1];
311 residuals[3][0] = 0.0;
327 residuals[0][0] = ihit4D[2] - alivec[3];
328 residuals[1][0] = ihit4D[3] - alivec[4];
329 residuals[2][0] = ihit4D[0] - alivec[1];
330 residuals[3][0] = ihit4D[1] - alivec[2];
336 std::vector<bool> mb4_mask;
339 mb4_mask.push_back(
true);
340 mb4_mask.push_back(
false);
341 mb4_mask.push_back(
true);
342 mb4_mask.push_back(
true);
343 mb4_mask.push_back(
true);
344 mb4_mask.push_back(
false);
352 if (m_Chamber.station() == 4) {
353 for (
int icor = 0; icor < 6; ++icor) {
358 nAlignParam = derivsAux.num_row();
362 if (m_Chamber.station() == 4) {
364 for (
int icor = 0; icor < 6; ++icor) {
366 for (
int ccor = 0; ccor < 4; ++ccor) {
367 derivs[der_c][ccor] = derivsAux[icor][ccor];
394 name,
sizeof(
name),
"Chamber_%d_%d_%d", m_Chamber.wheel(), m_Chamber.station(), m_Chamber.sector());
416 this->
updateInfo(invCov, weightRes, residuals, chamId);
448 std::map<std::string, AlgebraicMatrix *>::iterator node =
map_invCov.find(id_invCov);
454 map_invCov.insert(make_pair(id_invCov, f_invCov));
456 map_N.insert(make_pair(id_n, f_n));
458 for (
int iCount = 0; iCount < 4; ++iCount) {
460 snprintf(
name,
sizeof(
name),
"%s_var_%d",
id.c_str(), iCount);
473 (*
map_N[id_n])[0][0]++;
475 for (
int iCount = 0; iCount < 4; ++iCount) {
477 snprintf(
name,
sizeof(
name),
"%s_var_%d",
id.c_str(), iCount);