File indexing completed on 2024-04-06 11:56:43
0001 #include "FWCore/ServiceRegistry/interface/Service.h"
0002 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0003
0004 #include "Alignment/MuonAlignmentAlgorithms/plugins/CSCAlignmentCorrections.h"
0005 #include "Alignment/MuonAlignmentAlgorithms/plugins/CSCPairResidualsConstraint.h"
0006
0007 void CSCAlignmentCorrections::plot() {
0008 edm::Service<TFileService> tFileService;
0009
0010 for (unsigned int i = 0; i < m_coefficient.size(); i++) {
0011 std::string modifiedName = m_fitterName;
0012 if (modifiedName[0] == 'M' && modifiedName[1] == 'E') {
0013 if (modifiedName[2] == '-')
0014 modifiedName[2] = 'm';
0015 else if (modifiedName[2] == '+')
0016 modifiedName[2] = 'p';
0017 if (modifiedName[4] == '/')
0018 modifiedName[4] = '_';
0019 if (modifiedName[6] == '/')
0020 modifiedName[6] = '_';
0021 } else if (modifiedName[0] == 'Y' && modifiedName[1] == 'E') {
0022 if (modifiedName[2] == '-')
0023 modifiedName[2] = 'm';
0024 else if (modifiedName[2] == '+')
0025 modifiedName[2] = 'p';
0026 }
0027
0028 std::stringstream histname, histtitle;
0029 histname << modifiedName << "_mode_" << i;
0030 histtitle << m_error[i];
0031
0032 TH1F *hist = tFileService->make<TH1F>(
0033 histname.str().c_str(), histtitle.str().c_str(), m_coefficient[i].size(), 0.5, m_coefficient[i].size() + 0.5);
0034
0035 bool showed_full_name = false;
0036 for (unsigned int j = 0; j < m_coefficient[i].size(); j++) {
0037 hist->SetBinContent(j + 1, m_coefficient[i][j]);
0038
0039 if (m_modeid[i][j] == -1 || !showed_full_name) {
0040 hist->GetXaxis()->SetBinLabel(j + 1, m_modename[i][j].c_str());
0041 } else {
0042 std::stringstream shortname;
0043 shortname << m_modename[i][j][7] << m_modename[i][j][8];
0044 hist->GetXaxis()->SetBinLabel(j + 1, shortname.str().c_str());
0045 }
0046 if (m_modeid[i][j] != -1)
0047 showed_full_name = true;
0048 }
0049
0050 th1f_modes.push_back(hist);
0051 }
0052 }
0053
0054 void CSCAlignmentCorrections::report(std::ofstream &report) {
0055 report << "cscReports.append(CSCFitterReport(\"" << m_fitterName << "\", " << m_oldchi2 << ", " << m_newchi2 << "))"
0056 << std::endl;
0057
0058 for (unsigned int i = 0; i < m_name.size(); i++) {
0059 report << "cscReports[-1].addChamberCorrection(\"" << m_name[i] << "\", " << m_id[i].rawId() << ", " << m_value[i]
0060 << ")" << std::endl;
0061 }
0062
0063 for (unsigned int i = 0; i < m_coefficient.size(); i++) {
0064 report << "cscReports[-1].addErrorMode(" << m_error[i] << ")" << std::endl;
0065
0066 for (unsigned int j = 0; j < m_coefficient[i].size(); j++) {
0067 report << "cscReports[-1].addErrorModeTerm(\"" << m_modename[i][j] << "\", " << m_modeid[i][j] << ", "
0068 << m_coefficient[i][j] << ")" << std::endl;
0069 }
0070 }
0071
0072 for (unsigned int i = 0; i < m_i.size(); i++) {
0073 report << "cscReports[-1].addCSCConstraintResidual(\"" << m_i[i] << "\", \"" << m_j[i] << "\", " << m_before[i]
0074 << ", " << m_uncert[i] << ", " << m_residual[i] << ", " << m_pull[i] << ")" << std::endl;
0075 }
0076
0077 report << std::endl;
0078 }
0079
0080 void CSCAlignmentCorrections::applyAlignment(AlignableNavigator *alignableNavigator,
0081 AlignmentParameterStore *alignmentParameterStore,
0082 int mode,
0083 bool combineME11) {
0084 for (unsigned int i = 0; i < m_name.size(); i++) {
0085
0086 bool backward =
0087 ((m_id[i].endcap() == 1 && m_id[i].station() >= 3) || (m_id[i].endcap() == 2 && m_id[i].station() < 3));
0088
0089
0090 const DetId id(m_id[i]);
0091 Alignable *alignable = alignableNavigator->alignableFromDetId(id).alignable();
0092 Alignable *also = nullptr;
0093 if (combineME11 && m_id[i].station() == 1 && m_id[i].ring() == 1) {
0094 CSCDetId alsoid(m_id[i].endcap(), 1, 4, m_id[i].chamber(), 0);
0095 const DetId alsoid2(alsoid);
0096 also = alignableNavigator->alignableFromDetId(alsoid2).alignable();
0097 }
0098
0099 AlgebraicVector params(6);
0100 AlgebraicSymMatrix cov(6);
0101
0102 if (mode == CSCPairResidualsConstraint::kModePhiy) {
0103 params[4] = m_value[i];
0104 cov[4][4] = 1e-6;
0105 } else if (mode == CSCPairResidualsConstraint::kModePhiPos) {
0106 align::GlobalPoint center = alignable->surface().toGlobal(align::LocalPoint(0., 0., 0.));
0107 double radius = sqrt(center.x() * center.x() + center.y() * center.y());
0108
0109 double phi_correction = m_value[i];
0110 params[0] = -radius * sin(phi_correction) * (backward ? -1. : 1.);
0111 params[1] = radius * (cos(phi_correction) - 1.);
0112 params[5] = phi_correction * (backward ? -1. : 1.);
0113
0114 cov[0][0] = 1e-6;
0115 cov[1][1] = 1e-6;
0116 cov[5][5] = 1e-6;
0117 } else if (mode == CSCPairResidualsConstraint::kModePhiz) {
0118 params[5] = m_value[i] * (backward ? -1. : 1.);
0119 cov[5][5] = 1e-6;
0120 } else
0121 assert(false);
0122
0123 AlignmentParameters *parnew = alignable->alignmentParameters()->cloneFromSelected(params, cov);
0124 alignable->setAlignmentParameters(parnew);
0125 alignmentParameterStore->applyParameters(alignable);
0126 alignable->alignmentParameters()->setValid(true);
0127 if (also != nullptr) {
0128 AlignmentParameters *parnew2 = also->alignmentParameters()->cloneFromSelected(params, cov);
0129 also->setAlignmentParameters(parnew2);
0130 alignmentParameterStore->applyParameters(also);
0131 also->alignmentParameters()->setValid(true);
0132 }
0133 }
0134 }