3 #include "CLHEP/Matrix/Matrix.h"
4 #include "TMatrixDEigen.h"
15 std::vector<CSCPairResidualsConstraint *> &residualsConstraints) {
18 if (m_alignables.empty()) {
23 for (std::vector<std::string>::const_iterator alignable = m_alignables.begin(); alignable != m_alignables.end();
34 for (std::vector<std::string>::const_iterator alignable = m_alignables.begin(); alignable != m_alignables.end();
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");
47 for (std::vector<edm::ParameterSet>::const_iterator
constraint = constraints.begin();
constraint != constraints.end();
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
74 for (
unsigned int i = 0; i < m_alignables.size(); i++) {
80 for (
unsigned int j = 0;
j < m_alignables.size();
j++) {
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;
107 for (
unsigned int i = 0; i < m_alignables.size(); i++)
110 for (
unsigned int i = 0; i < m_alignables.size(); i++) {
112 throw cms::Exception(
"BadConfig") <<
"Fitter " <<
m_name <<
" is not a connected graph (no way to get to "
113 << m_alignables[
i] <<
" from " << m_alignables[0] <<
", for instance)"
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')
175 if (station > 1 && ring > 2)
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')
253 if (station > 1 && ring == 1 && chamber > 18)
257 return CSCDetId(endcap, station, ring, chamber, 0).rawId();
268 for (std::vector<int>::const_iterator frame =
m_frames.begin(); frame !=
m_frames.end(); ++frame) {
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());
422 corrections.push_back(correction);
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) {
462 if (combineME11 && residualsConstraint->
id_i().
station() == 1 && residualsConstraint->
id_i().
ring() == 1) {
464 const DetId alsoid2(alsoid);
475 alignable->setAlignmentParameters(parnew);
477 alignable->alignmentParameters()->setValid(
true);
478 if (also !=
nullptr) {
double hessian(int k, int l, double lambda) const
double chi2(const AlgebraicVector &A, double lambda) const
uint16_t *__restrict__ id
std::vector< std::string > m_alignables
long alignableId(std::string alignable) const
void applyParameters(void)
Obsolete: Use AlignableNavigator::alignableDetFromDetId and alignableFromAlignableDet.
CSCChamberFitter(const edm::ParameterSet &iConfig, std::vector< CSCPairResidualsConstraint * > &residualsConstraints)
Log< level::Error, false > LogError
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
double lhsVector(int k) const
void insertMode(const std::vector< double > &coefficient, const std::vector< std::string > &modename, const std::vector< long > &modeid, double error)
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 walk(std::map< int, bool > &touched, int alignable) const
void setValid(bool v)
Set validity flag.
double value() const override
void insertCorrection(std::string name, CSCDetId id, double value)
bool fit(std::vector< CSCAlignmentCorrections * > &corrections) const
std::vector< CSCPairConstraint * > m_constraints
void insertResidual(std::string i, std::string j, double before, double uncert, double residual, double pull)
CLHEP::HepVector AlgebraicVector
bool valid() const override
double radius(bool is_i) const
T getParameter(std::string const &) const
constexpr float correction(int sizeM1, int q_f, int q_l, uint16_t upper_edge_first_pix, uint16_t lower_edge_last_pix, float lorentz_shift, float theThickness, float cot_angle, float pitch, bool first_is_big, bool last_is_big)
void radiusCorrection(AlignableNavigator *alignableNavigator, AlignmentParameterStore *alignmentParameterStore, bool combineME11) const
CLHEP::HepSymMatrix AlgebraicSymMatrix
int index(std::string alignable) 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.
Power< A, B >::type pow(const A &a, const B &b)
bool isFrame(int i) const