3 #include "CLHEP/Matrix/Matrix.h" 4 #include "TMatrixDEigen.h" 16 if (m_alignables.size() == 0) {
21 for (std::vector<std::string>::const_iterator alignable = m_alignables.begin(); alignable != m_alignables.end(); ++alignable) {
30 for (std::vector<std::string>::const_iterator alignable = m_alignables.begin(); alignable != m_alignables.end(); ++alignable) {
31 if (fixed == *alignable) {
36 if (
m_fixed == -1)
throw cms::Exception(
"BadConfig") <<
"Cannot fix unrecognized alignable " << fixed << std::endl;
39 int numConstraints = 0;
40 std::vector<edm::ParameterSet>
constraints = iConfig.
getParameter<std::vector<edm::ParameterSet> >(
"constraints");
49 if (error <= 0.)
throw cms::Exception(
"BadConfig") <<
"Non-positive uncertainty in constraint " << numConstraints <<
" of fitter " <<
m_name << std::endl;
57 for (
unsigned int i = 0; i < m_alignables.size(); i++) {
63 for (
unsigned int j = 0; j < m_alignables.size(); j++) {
66 if (i != j && id_j != -1) {
71 int next_chamber = cscid_i.
chamber() + 1;
72 if (cscid_i.
station() > 1 && cscid_i.
ring() == 1 && next_chamber == 19) next_chamber = 1;
73 else if (!(cscid_i.
station() > 1 && cscid_i.
ring() == 1) && next_chamber == 37) next_chamber = 1;
78 residualsConstraints.push_back(residualsConstraint);
87 std::map<int,bool> touched;
88 for (
unsigned int i = 0; i < m_alignables.size(); i++) touched[i] =
false;
90 for (
unsigned int i = 0; i < m_alignables.size(); i++) {
91 if (!touched[i])
throw cms::Exception(
"BadConfig") <<
"Fitter " <<
m_name <<
" is not a connected graph (no way to get to " << m_alignables[
i] <<
" from " << m_alignables[0] <<
", for instance)" << std::endl;
98 if (*
a == alignable)
return i;
105 touched[alignable] =
true;
108 if (alignable == (*constraint)->i() || alignable == (*constraint)->j()) {
109 if (!touched[(*constraint)->i()])
walk(touched, (*constraint)->i());
110 if (!touched[(*constraint)->j()])
walk(touched, (*constraint)->j());
116 if (alignable.size() != 9)
return -1;
118 if (alignable[0] ==
'M' && alignable[1] ==
'E') {
120 if (alignable[2] ==
'+') endcap = 1;
121 else if (alignable[2] ==
'-') endcap = 2;
125 if (alignable[3] ==
'1') station = 1;
126 else if (alignable[3] ==
'2') station = 2;
127 else if (alignable[3] ==
'3') station = 3;
128 else if (alignable[3] ==
'4') station = 4;
130 if (alignable[4] ==
'/' && station != -1) {
132 if (alignable[5] ==
'1') ring = 1;
133 else if (alignable[5] ==
'2') ring = 2;
134 else if (alignable[5] ==
'3') ring = 3;
135 else if (alignable[5] ==
'4') ring = 4;
136 if (station > 1 && ring > 2)
return -1;
138 if (alignable[6] ==
'/' && ring != -1) {
140 if (alignable[7] ==
'0' && alignable[8] ==
'1') chamber = 1;
141 else if (alignable[7] ==
'0' && alignable[8] ==
'2') chamber = 2;
142 else if (alignable[7] ==
'0' && alignable[8] ==
'3') chamber = 3;
143 else if (alignable[7] ==
'0' && alignable[8] ==
'4') chamber = 4;
144 else if (alignable[7] ==
'0' && alignable[8] ==
'5') chamber = 5;
145 else if (alignable[7] ==
'0' && alignable[8] ==
'6') chamber = 6;
146 else if (alignable[7] ==
'0' && alignable[8] ==
'7') chamber = 7;
147 else if (alignable[7] ==
'0' && alignable[8] ==
'8') chamber = 8;
148 else if (alignable[7] ==
'0' && alignable[8] ==
'9') chamber = 9;
149 else if (alignable[7] ==
'1' && alignable[8] ==
'0') chamber = 10;
150 else if (alignable[7] ==
'1' && alignable[8] ==
'1') chamber = 11;
151 else if (alignable[7] ==
'1' && alignable[8] ==
'2') chamber = 12;
152 else if (alignable[7] ==
'1' && alignable[8] ==
'3') chamber = 13;
153 else if (alignable[7] ==
'1' && alignable[8] ==
'4') chamber = 14;
154 else if (alignable[7] ==
'1' && alignable[8] ==
'5') chamber = 15;
155 else if (alignable[7] ==
'1' && alignable[8] ==
'6') chamber = 16;
156 else if (alignable[7] ==
'1' && alignable[8] ==
'7') chamber = 17;
157 else if (alignable[7] ==
'1' && alignable[8] ==
'8') chamber = 18;
158 else if (alignable[7] ==
'1' && alignable[8] ==
'9') chamber = 19;
159 else if (alignable[7] ==
'2' && alignable[8] ==
'0') chamber = 20;
160 else if (alignable[7] ==
'2' && alignable[8] ==
'1') chamber = 21;
161 else if (alignable[7] ==
'2' && alignable[8] ==
'2') chamber = 22;
162 else if (alignable[7] ==
'2' && alignable[8] ==
'3') chamber = 23;
163 else if (alignable[7] ==
'2' && alignable[8] ==
'4') chamber = 24;
164 else if (alignable[7] ==
'2' && alignable[8] ==
'5') chamber = 25;
165 else if (alignable[7] ==
'2' && alignable[8] ==
'6') chamber = 26;
166 else if (alignable[7] ==
'2' && alignable[8] ==
'7') chamber = 27;
167 else if (alignable[7] ==
'2' && alignable[8] ==
'8') chamber = 28;
168 else if (alignable[7] ==
'2' && alignable[8] ==
'9') chamber = 29;
169 else if (alignable[7] ==
'3' && alignable[8] ==
'0') chamber = 30;
170 else if (alignable[7] ==
'3' && alignable[8] ==
'1') chamber = 31;
171 else if (alignable[7] ==
'3' && alignable[8] ==
'2') chamber = 32;
172 else if (alignable[7] ==
'3' && alignable[8] ==
'3') chamber = 33;
173 else if (alignable[7] ==
'3' && alignable[8] ==
'4') chamber = 34;
174 else if (alignable[7] ==
'3' && alignable[8] ==
'5') chamber = 35;
175 else if (alignable[7] ==
'3' && alignable[8] ==
'6') chamber = 36;
177 if (station > 1 && ring == 1 && chamber > 18)
return -1;
191 for (std::vector<int>::const_iterator frame =
m_frames.begin(); frame !=
m_frames.end(); ++frame) {
192 if (i == *frame)
return true;
198 double sumFixed = 0.;
211 double s = lambda * sumFixed*sumFixed;
213 if ((*constraint)->valid()) {
214 s +=
pow((*constraint)->value() - A[(*constraint)->i()] + A[(*constraint)->j()], 2)/(*constraint)->error()/(*constraint)->error();
223 if ((*constraint)->valid()) {
224 double d = 2.*(*constraint)->value()/(*constraint)->error()/(*constraint)->error();
225 if ((*constraint)->i() ==
k) s += d;
226 if ((*constraint)->j() ==
k) s -= d;
239 if (k == l && l ==
m_fixed) s += 2.*lambda;
244 if ((*constraint)->valid()) {
245 d = 2./(*constraint)->error()/(*constraint)->error();
248 if (k == l && ((*constraint)->i() == k || (*constraint)->j() ==
k)) s +=
d;
249 if (((*constraint)->i() == k && (*constraint)->j() ==
l) || ((*constraint)->j() == k && (*constraint)->i() ==
l)) s -=
d;
269 double oldchi2 =
chi2(
A, lambda);
274 edm::LogError(
"CSCOverlapsAlignmentAlgorithm") <<
"Matrix inversion failed for fitter " <<
m_name <<
" matrix is " << M << std::endl;
294 for (
unsigned int j = 0; j <
m_alignables.size(); j++) {
295 tmatrix[
i][j] = M[
i][j];
298 TMatrixDEigen tmatrixdeigen(tmatrix);
299 TMatrixD basis = tmatrixdeigen.GetEigenVectors();
300 TMatrixD invbasis = tmatrixdeigen.GetEigenVectors();
302 TMatrixD diagonalized = invbasis * (tmatrix * basis);
305 std::vector<double> coefficient;
306 std::vector<std::string> modename;
307 std::vector<long> modeid;
308 for (
unsigned int j = 0; j <
m_alignables.size(); j++) {
309 coefficient.push_back(invbasis[
i][j]);
314 correction->
insertMode(coefficient, modename, modeid,
sqrt(2. * fabs(diagonalized[
i][
i])) * (diagonalized[i][i] >= 0. ? 1. : -1.));
318 if ((*constraint)->valid()) {
319 double residual = (*constraint)->value() -
A[(*constraint)->i()] +
A[(*constraint)->j()];
320 correction->
insertResidual(
m_alignables[(*constraint)->i()],
m_alignables[(*constraint)->j()], (*constraint)->value(), (*constraint)->error(), residual, residual/(*constraint)->error());
324 corrections.push_back(correction);
329 double sum_phipos_residuals = 0.;
330 double num_valid = 0.;
331 double sum_radius = 0.;
332 double num_total = 0.;
335 if (residualsConstraint !=
NULL) {
337 if (residualsConstraint->
valid()) {
338 sum_phipos_residuals += residualsConstraint->
value();
342 sum_radius += residualsConstraint->
radius(
true);
346 if (num_valid == 0. || num_total == 0.)
return;
347 double average_phi_residual = sum_phipos_residuals / num_valid;
348 double average_radius = sum_radius / num_total;
354 if (residualsConstraint !=
NULL) {
359 if (combineME11 && residualsConstraint->
id_i().
station() == 1 && residualsConstraint->
id_i().
ring() == 1) {
361 const DetId alsoid2(alsoid);
372 alignable->setAlignmentParameters(parnew);
374 alignable->alignmentParameters()->setValid(
true);
double hessian(int k, int l, double lambda) const
std::vector< CSCPairConstraint * > m_constraints
T getParameter(std::string const &) const
double chi2(const AlgebraicVector &A, double lambda) const
std::vector< std::string > m_alignables
virtual AlignmentParameters * cloneFromSelected(const AlgebraicVector &par, const AlgebraicSymMatrix &cov) const =0
long alignableId(std::string alignable) const
void applyParameters(void)
Obsolete: Use AlignableNavigator::alignableDetFromDetId and alignableFromAlignableDet.
CSCChamberFitter(const edm::ParameterSet &iConfig, std::vector< CSCPairResidualsConstraint * > &residualsConstraints)
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
uint32_t rawId() const
get the raw id
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)
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.
void insertCorrection(std::string name, CSCDetId id, double value)
bool fit(std::vector< CSCAlignmentCorrections * > &corrections) const
void insertResidual(std::string i, std::string j, double before, double uncert, double residual, double pull)
CLHEP::HepVector AlgebraicVector
double radius(bool is_i) const
void radiusCorrection(AlignableNavigator *alignableNavigator, AlignmentParameterStore *alignmentParameterStore, bool combineME11) const
CLHEP::HepSymMatrix AlgebraicSymMatrix
int index(std::string alignable) const
std::vector< int > m_frames
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