3 #include "CLHEP/Matrix/Matrix.h" 4 #include "TMatrixDEigen.h" 15 std::vector<CSCPairResidualsConstraint *> &residualsConstraints) {
36 if (
fixed == *alignable) {
42 throw cms::Exception(
"BadConfig") <<
"Cannot fix unrecognized alignable " <<
fixed << std::endl;
45 int numConstraints = 0;
46 std::vector<edm::ParameterSet>
constraints = iConfig.
getParameter<std::vector<edm::ParameterSet> >(
"constraints");
56 <<
" in constraint " << numConstraints <<
" of fitter " <<
m_name << std::endl;
59 <<
" in constraint " << numConstraints <<
" of fitter " <<
m_name << std::endl;
61 throw cms::Exception(
"BadConfig") <<
"Non-positive uncertainty in constraint " << numConstraints <<
" of fitter " 66 <<
" is not allowed in constraint " << numConstraints <<
" of fitter " <<
m_name 83 if (
i !=
j && id_j != -1) {
87 int next_chamber = cscid_i.
chamber() + 1;
88 if (cscid_i.
station() > 1 && cscid_i.
ring() == 1 && next_chamber == 19)
90 else if (!(cscid_i.
station() > 1 && cscid_i.
ring() == 1) && next_chamber == 37)
93 cscid_i.
ring() == cscid_j.
ring() && next_chamber == cscid_j.
chamber()) {
97 residualsConstraints.push_back(residualsConstraint);
106 std::map<int, bool> touched;
112 throw cms::Exception(
"BadConfig") <<
"Fitter " <<
m_name <<
" is not a connected graph (no way to get to " 129 touched[alignable] =
true;
134 if (alignable == (*constraint)->i() || alignable == (*constraint)->j()) {
135 if (!touched[(*constraint)->i()])
136 walk(touched, (*constraint)->i());
137 if (!touched[(*constraint)->j()])
138 walk(touched, (*constraint)->j());
144 if (alignable.size() != 9)
147 if (alignable[0] ==
'M' && alignable[1] ==
'E') {
149 if (alignable[2] ==
'+')
151 else if (alignable[2] ==
'-')
156 if (alignable[3] ==
'1')
158 else if (alignable[3] ==
'2')
160 else if (alignable[3] ==
'3')
162 else if (alignable[3] ==
'4')
165 if (alignable[4] ==
'/' &&
station != -1) {
167 if (alignable[5] ==
'1')
169 else if (alignable[5] ==
'2')
171 else if (alignable[5] ==
'3')
173 else if (alignable[5] ==
'4')
178 if (alignable[6] ==
'/' &&
ring != -1) {
180 if (alignable[7] ==
'0' && alignable[8] ==
'1')
182 else if (alignable[7] ==
'0' && alignable[8] ==
'2')
184 else if (alignable[7] ==
'0' && alignable[8] ==
'3')
186 else if (alignable[7] ==
'0' && alignable[8] ==
'4')
188 else if (alignable[7] ==
'0' && alignable[8] ==
'5')
190 else if (alignable[7] ==
'0' && alignable[8] ==
'6')
192 else if (alignable[7] ==
'0' && alignable[8] ==
'7')
194 else if (alignable[7] ==
'0' && alignable[8] ==
'8')
196 else if (alignable[7] ==
'0' && alignable[8] ==
'9')
198 else if (alignable[7] ==
'1' && alignable[8] ==
'0')
200 else if (alignable[7] ==
'1' && alignable[8] ==
'1')
202 else if (alignable[7] ==
'1' && alignable[8] ==
'2')
204 else if (alignable[7] ==
'1' && alignable[8] ==
'3')
206 else if (alignable[7] ==
'1' && alignable[8] ==
'4')
208 else if (alignable[7] ==
'1' && alignable[8] ==
'5')
210 else if (alignable[7] ==
'1' && alignable[8] ==
'6')
212 else if (alignable[7] ==
'1' && alignable[8] ==
'7')
214 else if (alignable[7] ==
'1' && alignable[8] ==
'8')
216 else if (alignable[7] ==
'1' && alignable[8] ==
'9')
218 else if (alignable[7] ==
'2' && alignable[8] ==
'0')
220 else if (alignable[7] ==
'2' && alignable[8] ==
'1')
222 else if (alignable[7] ==
'2' && alignable[8] ==
'2')
224 else if (alignable[7] ==
'2' && alignable[8] ==
'3')
226 else if (alignable[7] ==
'2' && alignable[8] ==
'4')
228 else if (alignable[7] ==
'2' && alignable[8] ==
'5')
230 else if (alignable[7] ==
'2' && alignable[8] ==
'6')
232 else if (alignable[7] ==
'2' && alignable[8] ==
'7')
234 else if (alignable[7] ==
'2' && alignable[8] ==
'8')
236 else if (alignable[7] ==
'2' && alignable[8] ==
'9')
238 else if (alignable[7] ==
'3' && alignable[8] ==
'0')
240 else if (alignable[7] ==
'3' && alignable[8] ==
'1')
242 else if (alignable[7] ==
'3' && alignable[8] ==
'2')
244 else if (alignable[7] ==
'3' && alignable[8] ==
'3')
246 else if (alignable[7] ==
'3' && alignable[8] ==
'4')
248 else if (alignable[7] ==
'3' && alignable[8] ==
'5')
250 else if (alignable[7] ==
'3' && alignable[8] ==
'6')
276 double sumFixed = 0.;
288 double s = lambda * sumFixed * sumFixed;
292 if ((*constraint)->valid()) {
293 s +=
pow((*constraint)->value() -
A[(*constraint)->i()] +
A[(*constraint)->j()], 2) / (*constraint)->error() /
294 (*constraint)->error();
305 if ((*constraint)->valid()) {
306 double d = 2. * (*constraint)->value() / (*constraint)->error() / (*constraint)->error();
307 if ((*constraint)->i() ==
k)
309 if ((*constraint)->j() ==
k)
331 if ((*constraint)->valid()) {
332 d = 2. / (*constraint)->error() / (*constraint)->error();
335 if (
k ==
l && ((*constraint)->i() ==
k || (*constraint)->j() ==
k))
337 if (((*constraint)->i() ==
k && (*constraint)->j() ==
l) || ((*constraint)->j() ==
k && (*constraint)->i() ==
l))
358 double oldchi2 =
chi2(
A, lambda);
364 <<
"Matrix inversion failed for fitter " <<
m_name <<
" matrix is " << M << std::endl;
385 tmatrix[
i][
j] = M[
i][
j];
388 TMatrixDEigen tmatrixdeigen(tmatrix);
389 const TMatrixD &basis = tmatrixdeigen.GetEigenVectors();
390 TMatrixD invbasis = tmatrixdeigen.GetEigenVectors();
392 TMatrixD diagonalized = invbasis * (tmatrix * basis);
395 std::vector<double> coefficient;
396 std::vector<std::string> modename;
397 std::vector<long> modeid;
399 coefficient.push_back(invbasis[
i][
j]);
405 coefficient, modename, modeid,
sqrt(2. * fabs(diagonalized[
i][
i])) * (diagonalized[
i][
i] >= 0. ? 1. : -1.));
411 if ((*constraint)->valid()) {
412 double residual = (*constraint)->value() -
A[(*constraint)->i()] +
A[(*constraint)->j()];
415 (*constraint)->value(),
416 (*constraint)->error(),
418 residual / (*constraint)->error());
429 double sum_phipos_residuals = 0.;
430 double num_valid = 0.;
431 double sum_radius = 0.;
432 double num_total = 0.;
437 if (residualsConstraint !=
nullptr) {
438 if (residualsConstraint->
valid()) {
439 sum_phipos_residuals += residualsConstraint->
value();
443 sum_radius += residualsConstraint->
radius(
true);
447 if (num_valid == 0. || num_total == 0.)
449 double average_phi_residual = sum_phipos_residuals / num_valid;
450 double average_radius = sum_radius / num_total;
458 if (residualsConstraint !=
nullptr) {
464 const DetId alsoid2(alsoid);
475 alignable->setAlignmentParameters(parnew);
477 alignable->alignmentParameters()->setValid(
true);
478 if (also !=
nullptr) {
T getParameter(std::string const &) const
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
void walk(std::map< int, bool > &touched, int alignable) const
std::vector< std::string > m_alignables
void radiusCorrection(AlignableNavigator *alignableNavigator, AlignmentParameterStore *alignmentParameterStore, bool combineME11) const
CSCChamberFitter(const edm::ParameterSet &iConfig, std::vector< CSCPairResidualsConstraint *> &residualsConstraints)
int index(std::string alignable) const
void applyParameters(void)
Obsolete: Use AlignableNavigator::alignableDetFromDetId and alignableFromAlignableDet.
Log< level::Error, false > LogError
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t V
void setAlignmentParameters(AlignmentParameters *dap)
Set the AlignmentParameters.
CLHEP::HepMatrix AlgebraicMatrix
void setValid(bool v)
Set validity flag.
double value() const override
std::vector< CSCPairConstraint * > m_constraints
double hessian(int k, int l, double lambda) const
double chi2(const AlgebraicVector &A, double lambda) const
bool fit(std::vector< CSCAlignmentCorrections *> &corrections) const
long alignableId(std::string alignable) const
CLHEP::HepVector AlgebraicVector
bool valid() const override
constexpr uint32_t rawId() const
get the raw id
double lhsVector(int k) const
double radius(bool is_i) const
CLHEP::HepSymMatrix AlgebraicSymMatrix
bool isFrame(int i) const
std::vector< int > m_frames
virtual AlignmentParameters * cloneFromSelected(const AlgebraicVector &par, const AlgebraicSymMatrix &cov) const =0
AlignableDetOrUnitPtr alignableFromDetId(const DetId &detid)
Returns AlignableDetOrUnitPtr corresponding to given DetId.