CMS 3D CMS Logo

PedeSteererWeakModeConstraints.cc
Go to the documentation of this file.
1 
10 
12 
14 
25 
27 // for 'type identification' as Alignable
31 // GF doubts the need of these includes from include checker campaign:
37 // end of doubt
38 
40 
41 #include <fstream>
42 #include <sstream>
43 #include <algorithm>
44 
45 // from ROOT
46 #include <TSystem.h>
47 #include <TMath.h>
48 
49 #include <iostream>
50 
52  const std::vector<double>& co,
53  const std::string& c,
54  const std::vector<std::pair<Alignable*, std::string> >& alisFile,
55  const int sd,
56  const align::Alignables& ex,
57  const int instance,
58  const bool downToLowestLevel)
59  : coefficients_(co),
60  constraintName_(c),
61  levelsFilenames_(alisFile),
62  excludedAlignables_(ex),
63  sysdeformation_(sd),
64  instance_(instance),
65  downToLowestLevel_(downToLowestLevel) {}
66 
67 //_________________________________________________________________________
69  const PedeLabelerBase* labels,
70  const std::vector<edm::ParameterSet>& config,
71  std::string sf)
72  : myLabels_(labels),
73  myConfig_(config),
74  steerFile_(sf),
75  alignableObjectId_{AlignableObjectId::commonObjectIdProvider(aliTracker, nullptr)} {
76  unsigned int psetnr = 0;
77  std::set<std::string> steerFilePrefixContainer;
78  for (const auto& pset : myConfig_) {
79  this->verifyParameterNames(pset, psetnr);
80  psetnr++;
81 
82  const auto coefficients = pset.getParameter<std::vector<double> >("coefficients");
83  const auto dm = pset.exists("deadmodules") ? pset.getParameter<std::vector<unsigned int> >("deadmodules")
84  : std::vector<unsigned int>();
85  std::string name = pset.getParameter<std::string>("constraint");
86  std::transform(name.begin(), name.end(), name.begin(), ::tolower);
87  const auto ignoredInstances = pset.exists("ignoredInstances")
88  ? pset.getUntrackedParameter<std::vector<unsigned int> >("ignoredInstances")
89  : std::vector<unsigned int>();
90 
91  const auto downToLowestLevel =
92  pset.exists("downToLowestLevel") ? pset.getUntrackedParameter<bool>("downToLowestLevel") : false;
93 
94  AlignmentParameterSelector selector(aliTracker, nullptr, nullptr);
95  selector.clear();
96  selector.addSelections(pset.getParameter<edm::ParameterSet>("levels"));
97 
98  const auto& alis = selector.selectedAlignables();
99 
100  AlignmentParameterSelector selector_excludedalignables(aliTracker, nullptr, nullptr);
101  selector_excludedalignables.clear();
102  if (pset.exists("excludedAlignables")) {
103  selector_excludedalignables.addSelections(pset.getParameter<edm::ParameterSet>("excludedAlignables"));
104  }
105  const auto& excluded_alis = selector_excludedalignables.selectedAlignables();
106 
107  //check that the name of the deformation is known and that the number
108  //of provided parameter is right.
109  auto sysdeformation = this->verifyDeformationName(name, coefficients);
110 
111  if (deadmodules_.empty()) { //fill the list of dead modules only once
112  edm::LogInfo("Alignment") << "@SUB=PedeSteererWeakModeConstraints"
113  << "Load list of dead modules (size = " << dm.size() << ").";
114  for (const auto& it : dm)
115  deadmodules_.push_back(it);
116  }
117 
118  // loop over all IOVs/momentum ranges
119  for (unsigned int instance = 0; instance < myLabels_->maxNumberOfParameterInstances(); ++instance) {
120  // check if this IOV/momentum range is to be ignored:
121  if (std::find(ignoredInstances.begin(), ignoredInstances.end(), instance) != ignoredInstances.end()) {
122  continue;
123  }
124  std::stringstream defaultsteerfileprefix;
125  defaultsteerfileprefix << "autosteerFilePrefix_" << name << "_" << psetnr << "_" << instance;
126 
127  const auto steerFilePrefix = pset.exists("steerFilePrefix") ? pset.getParameter<std::string>("steerFilePrefix") +
128  "_" + std::to_string(instance)
129  : defaultsteerfileprefix.str();
130 
131  const auto levelsFilenames = this->makeLevelsFilenames(steerFilePrefixContainer, alis, steerFilePrefix);
132 
133  //Add the configuration data for this constraint to the container of config data
134  ConstraintsConfigContainer_.emplace_back(GeometryConstraintConfigData(
135  coefficients, name, levelsFilenames, sysdeformation, excluded_alis, instance, downToLowestLevel));
136  }
137  }
138 }
139 
140 //_________________________________________________________________________
141 std::pair<align::GlobalPoint, align::GlobalPoint> PedeSteererWeakModeConstraints::getDoubleSensorPosition(
142  const Alignable* ali) const {
143  const auto aliPar = dynamic_cast<TwoBowedSurfacesAlignmentParameters*>(ali->alignmentParameters());
144  if (aliPar) {
145  const auto ySplit = aliPar->ySplit();
146  const auto halfLength = 0.5 * ali->surface().length();
147  const auto yM1 = 0.5 * (ySplit - halfLength); // y_mean of surface 1
148  const auto yM2 = yM1 + halfLength; // y_mean of surface 2
149  const auto pos_sensor0(ali->surface().toGlobal(align::LocalPoint(0., yM1, 0.)));
150  const auto pos_sensor1(ali->surface().toGlobal(align::LocalPoint(0., yM2, 0.)));
151  return std::make_pair(pos_sensor0, pos_sensor1);
152  } else {
153  throw cms::Exception("Alignment") << "[PedeSteererWeakModeConstraints::getDoubleSensorPosition]"
154  << " Dynamic cast to double sensor parameters failed.";
155  return std::make_pair(align::GlobalPoint(0.0, 0.0, 0.0), align::GlobalPoint(0.0, 0.0, 0.0));
156  }
157 }
158 
159 //_________________________________________________________________________
161  unsigned int nConstraints = 0;
162  for (auto& iC : ConstraintsConfigContainer_) {
163  //loop over all HLS for which the constraint is to be determined
164  for (const auto& iHLS : iC.levelsFilenames_) {
165  //determine next active sub-alignables for iHLS
166  align::Alignables aliDaughts;
167  if (iC.downToLowestLevel_) {
168  if (!iHLS.first->lastCompsWithParams(aliDaughts)) {
169  edm::LogWarning("Alignment") << "@SUB=PedeSteererWeakModeConstraints::createAlignablesDataStructure"
170  << "Some but not all component branches "
171  << alignableObjectId_.idToString(iHLS.first->alignableObjectId())
172  << " with params!";
173  }
174  } else {
175  if (!iHLS.first->firstCompsWithParams(aliDaughts)) {
176  edm::LogWarning("Alignment") << "@SUB=PedeSteererWeakModeConstraints::createAlignablesDataStructure"
177  << "Some but not all daughters of "
178  << alignableObjectId_.idToString(iHLS.first->alignableObjectId())
179  << " with params!";
180  }
181  }
182  ++nConstraints;
183 
184  std::list<Alignable*> usedinconstraint;
185  for (const auto& iD : aliDaughts) {
186  bool isNOTdead = true;
187  for (const auto& iDeadmodules : deadmodules_) {
188  if ((iD->alignableObjectId() == align::AlignableDetUnit || iD->alignableObjectId() == align::AlignableDet) &&
189  iD->geomDetId().rawId() == iDeadmodules) {
190  isNOTdead = false;
191  break;
192  }
193  }
194  //check if the module is excluded
195  for (const auto& iEx : iC.excludedAlignables_) {
196  if (iD->id() == iEx->id() && iD->alignableObjectId() == iEx->alignableObjectId()) {
197  //if(iD->geomDetId().rawId() == (*iEx)->geomDetId().rawId()) {
198  isNOTdead = false;
199  break;
200  }
201  }
202  const bool issubcomponent = this->checkMother(iD, iHLS.first);
203  if (issubcomponent) {
204  if (isNOTdead) {
205  usedinconstraint.push_back(iD);
206  }
207  } else {
208  //sanity check
209  throw cms::Exception("Alignment") << "[PedeSteererWeakModeConstraints::createAlignablesDataStructure]"
210  << " Sanity check failed. Alignable defined as active sub-component, "
211  << " but in fact its not a daugther of "
212  << alignableObjectId_.idToString(iHLS.first->alignableObjectId());
213  }
214  }
215 
216  if (!usedinconstraint.empty()) {
217  iC.HLSsubdets_.push_back(std::make_pair(iHLS.first, usedinconstraint));
218  } else {
219  edm::LogInfo("Alignment") << "@SUB=PedeSteererWeakModeConstraints"
220  << "No sub-components for "
221  << alignableObjectId_.idToString(iHLS.first->alignableObjectId()) << " at ("
222  << iHLS.first->globalPosition().x() << "," << iHLS.first->globalPosition().y() << ","
223  << iHLS.first->globalPosition().z() << ") selected. Skip constraint";
224  }
225  if (aliDaughts.empty()) {
226  edm::LogWarning("Alignment") << "@SUB=PedeSteererWeakModeConstraints::createAlignablesDataStructure"
227  << "No active sub-alignables found for "
228  << alignableObjectId_.idToString(iHLS.first->alignableObjectId()) << " at ("
229  << iHLS.first->globalPosition().x() << "," << iHLS.first->globalPosition().y()
230  << "," << iHLS.first->globalPosition().z() << ").";
231  }
232  }
233  }
234  return nConstraints;
235 }
236 
237 //_________________________________________________________________________
238 double PedeSteererWeakModeConstraints::getX(const int sysdeformation,
239  const align::GlobalPoint& pos,
240  const double phase) const {
241  double x = 0.0;
242 
243  const double r = TMath::Sqrt(pos.x() * pos.x() + pos.y() * pos.y());
244 
245  switch (sysdeformation) {
246  case SystematicDeformations::kTwist:
247  case SystematicDeformations::kZexpansion:
248  x = pos.z();
249  break;
250  case SystematicDeformations::kSagitta:
251  case SystematicDeformations::kRadial:
252  case SystematicDeformations::kTelescope:
253  case SystematicDeformations::kLayerRotation:
254  x = r;
255  break;
256  case SystematicDeformations::kBowing:
257  x = pos.z() * pos.z(); //TMath::Abs(pos.z());
258  break;
259  case SystematicDeformations::kElliptical:
260  x = r * TMath::Cos(2.0 * pos.phi() + phase);
261  break;
262  case SystematicDeformations::kSkew:
263  x = TMath::Cos(pos.phi() + phase);
264  break;
265  };
266 
267  return x;
268 }
269 
270 //_________________________________________________________________________
271 double PedeSteererWeakModeConstraints::getCoefficient(const int sysdeformation,
272  const align::GlobalPoint& pos,
273  const GlobalPoint gUDirection,
274  const GlobalPoint gVDirection,
275  const GlobalPoint gWDirection,
276  const int iParameter,
277  const double& x0,
278  const std::vector<double>& constraintparameters) const {
279  if (iParameter < 0 || iParameter > 2) {
280  throw cms::Exception("Alignment") << "[PedeSteererWeakModeConstraints::getCoefficient]"
281  << " iParameter has to be in the range [0,2] but"
282  << " it is equal to " << iParameter << ".";
283  }
284 
285  //global vectors pointing in u,v,w direction
286  const std::vector<double> vec_u = {pos.x() - gUDirection.x(), pos.y() - gUDirection.y(), pos.z() - gUDirection.z()};
287  const std::vector<double> vec_v = {pos.x() - gVDirection.x(), pos.y() - gVDirection.y(), pos.z() - gVDirection.z()};
288  const std::vector<double> vec_w = {pos.x() - gWDirection.x(), pos.y() - gWDirection.y(), pos.z() - gWDirection.z()};
289 
290  //FIXME: how to make inner vectors const?
291  const std::vector<std::vector<double> > global_vecs = {vec_u, vec_v, vec_w};
292 
293  const double n = TMath::Sqrt(global_vecs.at(iParameter).at(0) * global_vecs.at(iParameter).at(0) +
294  global_vecs.at(iParameter).at(1) * global_vecs.at(iParameter).at(1) +
295  global_vecs.at(iParameter).at(2) * global_vecs.at(iParameter).at(2));
296  const double r = TMath::Sqrt(pos.x() * pos.x() + pos.y() * pos.y());
297 
298  const double phase = this->getPhase(constraintparameters);
299  //const double radial_direction[3] = {TMath::Sin(phase), TMath::Cos(phase), 0.0};
300  const std::vector<double> radial_direction = {TMath::Sin(phase), TMath::Cos(phase), 0.0};
301  //is equal to unity by construction ...
302  const double norm_radial_direction =
303  TMath::Sqrt(radial_direction.at(0) * radial_direction.at(0) + radial_direction.at(1) * radial_direction.at(1) +
304  radial_direction.at(2) * radial_direction.at(2));
305 
306  //const double phi_direction[3] = { -1.0 * pos.y(), pos.x(), 0.0};
307  const std::vector<double> phi_direction = {-1.0 * pos.y(), pos.x(), 0.0};
308  const double norm_phi_direction =
309  TMath::Sqrt(phi_direction.at(0) * phi_direction.at(0) + phi_direction.at(1) * phi_direction.at(1) +
310  phi_direction.at(2) * phi_direction.at(2));
311 
312  //const double z_direction[3] = {0.0, 0.0, 1.0};
313  static const std::vector<double> z_direction = {0.0, 0.0, 1.0};
314  const double norm_z_direction =
315  TMath::Sqrt(z_direction.at(0) * z_direction.at(0) + z_direction.at(1) * z_direction.at(1) +
316  z_direction.at(2) * z_direction.at(2));
317 
318  //unit vector pointing from the origin to the module position in the transverse plane
319  const std::vector<double> rDirection = {pos.x(), pos.y(), 0.0};
320  const double norm_rDirection = TMath::Sqrt(rDirection.at(0) * rDirection.at(0) + rDirection.at(1) * rDirection.at(1) +
321  rDirection.at(2) * rDirection.at(2));
322 
323  double coeff = 0.0;
324  double dot_product = 0.0;
325  double normalisation_factor = 1.0;
326 
327  //see https://indico.cern.ch/getFile.py/access?contribId=15&sessionId=1&resId=0&materialId=slides&confId=127126
328  switch (sysdeformation) {
329  case SystematicDeformations::kTwist:
330  case SystematicDeformations::kLayerRotation:
331  dot_product = phi_direction.at(0) * global_vecs.at(iParameter).at(0) +
332  phi_direction.at(1) * global_vecs.at(iParameter).at(1) +
333  phi_direction.at(2) * global_vecs.at(iParameter).at(2);
334  normalisation_factor = r * n * norm_phi_direction;
335  break;
336  case SystematicDeformations::kZexpansion:
337  case SystematicDeformations::kTelescope:
338  case SystematicDeformations::kSkew:
339  dot_product = global_vecs.at(iParameter).at(0) * z_direction.at(0) +
340  global_vecs.at(iParameter).at(1) * z_direction.at(1) +
341  global_vecs.at(iParameter).at(2) * z_direction.at(2);
342  normalisation_factor = (n * norm_z_direction);
343  break;
344  case SystematicDeformations::kRadial:
345  case SystematicDeformations::kBowing:
346  case SystematicDeformations::kElliptical:
347  dot_product = global_vecs.at(iParameter).at(0) * rDirection.at(0) +
348  global_vecs.at(iParameter).at(1) * rDirection.at(1) +
349  global_vecs.at(iParameter).at(2) * rDirection.at(2);
350  normalisation_factor = (n * norm_rDirection);
351  break;
352  case SystematicDeformations::kSagitta:
353  dot_product = global_vecs.at(iParameter).at(0) * radial_direction.at(0) +
354  global_vecs.at(iParameter).at(1) * radial_direction.at(1) +
355  global_vecs.at(iParameter).at(2) * radial_direction.at(2);
356  normalisation_factor = (n * norm_radial_direction);
357  break;
358  default:
359  break;
360  }
361 
362  if (TMath::Abs(normalisation_factor) > 0.0) {
363  coeff = dot_product * (this->getX(sysdeformation, pos, phase) - x0) / normalisation_factor;
364  } else {
365  throw cms::Exception("Alignment") << "[PedeSteererWeakModeConstraints::getCoefficient]"
366  << " Normalisation factor"
367  << "for coefficient calculation equal to zero! Misconfiguration?";
368  }
369  return coeff;
370 }
371 
372 //_________________________________________________________________________
373 bool PedeSteererWeakModeConstraints::checkSelectionShiftParameter(const Alignable* ali, unsigned int iParameter) const {
374  bool isselected = false;
375  const std::vector<bool>& aliSel = ali->alignmentParameters()->selector();
376  //exclude non-shift parameters
377  if ((iParameter <= 2) || (iParameter >= 9 && iParameter <= 11)) {
378  if (!aliSel.at(iParameter)) {
379  isselected = false;
380  } else {
381  auto params = ali->alignmentParameters();
382  auto selVar = dynamic_cast<SelectionUserVariables*>(params->userVariables());
383  if (selVar) {
384  if (selVar->fullSelection().size() <= (iParameter + 1)) {
385  throw cms::Exception("Alignment")
386  << "[PedeSteererWeakModeConstraints::checkSelectionShiftParameter]"
387  << " Can not access selected alignment variables of alignable "
388  << alignableObjectId_.idToString(ali->alignableObjectId()) << "at (" << ali->globalPosition().x() << ","
389  << ali->globalPosition().y() << "," << ali->globalPosition().z() << ") "
390  << "for parameter number " << (iParameter + 1) << ".";
391  }
392  }
393  const char selChar = (selVar ? selVar->fullSelection().at(iParameter) : '1');
394  // if(selChar == '1') { //FIXME??? what about 'r'?
395  if (selChar == '1' || selChar == 'r') {
396  isselected = true;
397  } else {
398  isselected = false;
399  }
400  }
401  }
402  return isselected;
403 }
404 
405 //_________________________________________________________________________
407  //'delete' output files which means: close them
408  for (auto& it : ConstraintsConfigContainer_) {
409  for (auto& iFile : it.mapFileName_) {
410  if (iFile.second) {
411  delete iFile.second;
412  iFile.second = nullptr;
413  } else {
414  throw cms::Exception("FileCloseProblem") << "[PedeSteererWeakModeConstraints]"
415  << " can not close file " << iFile.first << ".";
416  }
417  }
418  }
419 }
420 
421 //_________________________________________________________________________
422 void PedeSteererWeakModeConstraints::writeOutput(const std::list<std::pair<unsigned int, double> >& output,
424  const Alignable* iHLS,
425  double sum_xi_x0) {
426  std::ofstream* ofile = getFile(it, iHLS);
427 
428  if (ofile == nullptr) {
429  throw cms::Exception("FileFindError") << "[PedeSteererWeakModeConstraints] Cannot find output file.";
430  } else {
431  if (!output.empty()) {
432  const double constr = sum_xi_x0 * it.coefficients_.front();
433  (*ofile) << "Constraint " << std::scientific << constr << std::endl;
434  for (const auto& ioutput : output) {
435  (*ofile) << std::fixed << ioutput.first << " " << std::scientific << ioutput.second << std::endl;
436  }
437  }
438  }
439 }
440 
441 //_________________________________________________________________________
443  const Alignable* iHLS) const {
444  std::ofstream* file = nullptr;
445 
446  for (const auto& ilevelsFilename : it.levelsFilenames_) {
447  if (ilevelsFilename.first->id() == iHLS->id() &&
448  ilevelsFilename.first->alignableObjectId() == iHLS->alignableObjectId()) {
449  const auto iFile = it.mapFileName_.find(ilevelsFilename.second);
450  if (iFile != it.mapFileName_.end()) {
451  file = iFile->second;
452  }
453  }
454  }
455 
456  return file;
457 }
458 
459 //_________________________________________________________________________
460 double PedeSteererWeakModeConstraints::getX0(const std::pair<Alignable*, std::list<Alignable*> >& iHLS,
461  const GeometryConstraintConfigData& it) const {
462  double nmodules = 0.0;
463  double x0 = 0.0;
464 
465  for (const auto& ali : iHLS.second) {
466  align::PositionType pos = ali->globalPosition();
467  bool alignableIsFloating = false; //means: true=alignable is able to move in at least one direction
468 
469  //test whether at least one variable has been selected in the configuration
470  for (unsigned int iParameter = 0; static_cast<int>(iParameter) < ali->alignmentParameters()->size(); iParameter++) {
471  if (this->checkSelectionShiftParameter(ali, iParameter)) {
472  alignableIsFloating = true;
473  // //verify that alignable has just one label -- meaning no IOV-dependence etc
474  // const unsigned int nInstances = myLabels_->numberOfParameterInstances(ali, iParameter);
475  // if(nInstances > 1) {
476  // throw cms::Exception("PedeSteererWeakModeConstraints")
477  // << "@SUB=PedeSteererWeakModeConstraints::ConstructConstraints"
478  // << " Weak mode constraints are only supported for alignables which have"
479  // << " just one label. However, e.g. alignable"
480  // << " " << alignableObjectId_.idToString(ali->alignableObjectId())
481  // << "at (" << ali->globalPosition().x() << ","<< ali->globalPosition().y() << "," << ali->globalPosition().z()<< "), "
482  // << " was configured to have >1 label. Remove e.g. IOV-dependence for this (and other) alignables which are used in the constraint.";
483  // }
484  break;
485  }
486  }
487  //at least one parameter of the alignable can be changed in the alignment
488  if (alignableIsFloating) {
489  const auto phase = this->getPhase(it.coefficients_);
490  if (ali->alignmentParameters()->type() != AlignmentParametersFactory::kTwoBowedSurfaces) {
491  x0 += this->getX(it.sysdeformation_, pos, phase);
492  nmodules++;
493  } else {
494  std::pair<align::GlobalPoint, align::GlobalPoint> sensorpositions = this->getDoubleSensorPosition(ali);
495  x0 += this->getX(it.sysdeformation_, sensorpositions.first, phase) +
496  this->getX(it.sysdeformation_, sensorpositions.second, phase);
497  nmodules++;
498  nmodules++;
499  }
500  }
501  }
502  if (nmodules > 0) {
503  x0 = x0 / nmodules;
504  } else {
505  throw cms::Exception("Alignment") << "@SUB=PedeSteererWeakModeConstraints::ConstructConstraints"
506  << " Number of selected modules equal to zero. Check configuration!";
507  x0 = 1.0;
508  }
509  return x0;
510 }
511 
512 //_________________________________________________________________________
514  //FIXME: split the code of the method into smaller pieces/submethods
515 
516  //create the data structures that store the alignables
517  //for which the constraints need to be calculated and
518  //their association to high-level structures
519  const auto nConstraints = this->createAlignablesDataStructure();
520 
521  std::vector<std::list<std::pair<unsigned int, double> > > createdConstraints;
522 
523  //calculate constraints
524  //loop over all constraints
525  for (const auto& it : ConstraintsConfigContainer_) {
526  //loop over all subdets for which constraints are determined
527  for (const auto& iHLS : it.HLSsubdets_) {
528  double sum_xi_x0 = 0.0;
529  std::list<std::pair<unsigned int, double> > output;
530 
531  const double x0 = this->getX0(iHLS, it);
532 
533  for (std::list<Alignable*>::const_iterator iAlignables = iHLS.second.begin(); iAlignables != iHLS.second.end();
534  iAlignables++) {
535  const Alignable* ali = (*iAlignables);
536  const auto aliLabel =
537  myLabels_->alignableLabelFromParamAndInstance(const_cast<Alignable*>(ali), 0, it.instance_);
538  const AlignableSurface& surface = ali->surface();
539 
540  const LocalPoint lUDirection(1., 0., 0.), lVDirection(0., 1., 0.), lWDirection(0., 0., 1.);
541 
542  GlobalPoint gUDirection = surface.toGlobal(lUDirection), gVDirection = surface.toGlobal(lVDirection),
543  gWDirection = surface.toGlobal(lWDirection);
544 
545  const bool isDoubleSensor = ali->alignmentParameters()->type() == AlignmentParametersFactory::kTwoBowedSurfaces;
546 
547  const auto sensorpositions = isDoubleSensor ? this->getDoubleSensorPosition(ali)
548  : std::make_pair(ali->globalPosition(), align::PositionType());
549 
550  const auto& pos_sensor0 = sensorpositions.first;
551  const auto& pos_sensor1 = sensorpositions.second;
552  const auto phase = this->getPhase(it.coefficients_);
553  const auto x_sensor0 = this->getX(it.sysdeformation_, pos_sensor0, phase);
554  const auto x_sensor1 = isDoubleSensor ? this->getX(it.sysdeformation_, pos_sensor1, phase) : 0.0;
555 
556  sum_xi_x0 += (x_sensor0 - x0) * (x_sensor0 - x0);
557  if (isDoubleSensor) {
558  sum_xi_x0 += (x_sensor1 - x0) * (x_sensor1 - x0);
559  }
560  const int numparameterlimit = ali->alignmentParameters()->size(); //isDoubleSensor ? 18 : 3;
561 
562  for (int iParameter = 0; iParameter < numparameterlimit; iParameter++) {
563  int localindex = 0;
564  if (iParameter == 0 || iParameter == 9)
565  localindex = 0;
566  if (iParameter == 1 || iParameter == 10)
567  localindex = 1;
568  if (iParameter == 2 || iParameter == 11)
569  localindex = 2;
570 
571  if ((iParameter >= 0 && iParameter <= 2) || (iParameter >= 9 && iParameter <= 11)) {
572  } else {
573  continue;
574  }
575  if (!this->checkSelectionShiftParameter(ali, iParameter)) {
576  continue;
577  }
578  //do it for each 'instance' separately? -> IOV-dependence, no
579  const auto paramLabel = myLabels_->parameterLabel(aliLabel, iParameter);
580 
581  const auto& pos = (iParameter <= 2) ? pos_sensor0 : pos_sensor1;
582  //select only u,v,w
583  if (iParameter == 0 || iParameter == 1 || iParameter == 2 || iParameter == 9 || iParameter == 10 ||
584  iParameter == 11) {
585  const double coeff = this->getCoefficient(
586  it.sysdeformation_, pos, gUDirection, gVDirection, gWDirection, localindex, x0, it.coefficients_);
587  if (TMath::Abs(coeff) > 0.0) {
588  //nothing
589  } else {
590  edm::LogWarning("PedeSteererWeakModeConstraints")
591  << "@SUB=PedeSteererWeakModeConstraints::getCoefficient"
592  << "Coefficient of alignable " << alignableObjectId_.idToString(ali->alignableObjectId()) << " at ("
593  << ali->globalPosition().x() << "," << ali->globalPosition().y() << "," << ali->globalPosition().z()
594  << ") "
595  << " in subdet " << alignableObjectId_.idToString(iHLS.first->alignableObjectId())
596  << " for parameter " << localindex << " equal to zero. This alignable is used in the constraint"
597  << " '" << it.constraintName_
598  << "'. The id is: alignable->geomDetId().rawId() = " << ali->geomDetId().rawId() << ".";
599  }
600  output.push_back(std::make_pair(paramLabel, coeff));
601  }
602  }
603  }
604 
605  if (std::find(createdConstraints.begin(), createdConstraints.end(), output) != createdConstraints.end()) {
606  // check if linearly dependent constraint exists already:
607  auto outFile = getFile(it, iHLS.first);
608  if (outFile == nullptr) {
609  throw cms::Exception("FileFindError") << "[PedeSteererWeakModeConstraints] Cannot find output file.";
610  } else {
611  *outFile << "! The constraint for this IOV/momentum range" << std::endl
612  << "! has been removed because the used parameters" << std::endl
613  << "! are not IOV or momentum-range dependent." << std::endl;
614  }
615  continue;
616  }
617  this->writeOutput(output, it, iHLS.first, sum_xi_x0);
618  createdConstraints.push_back(output);
619  }
620  }
621  this->closeOutputfiles();
622 
623  return nConstraints;
624 }
625 
626 //_________________________________________________________________________
627 bool PedeSteererWeakModeConstraints::checkMother(const Alignable* const lowleveldet, const Alignable* const HLS) const {
628  if (lowleveldet->id() == HLS->id() && lowleveldet->alignableObjectId() == HLS->alignableObjectId()) {
629  return true;
630  } else {
631  if (lowleveldet->mother() == nullptr)
632  return false;
633  else
634  return this->checkMother(lowleveldet->mother(), HLS);
635  }
636 }
637 
638 //_________________________________________________________________________
640  const auto parameterNames = pset.getParameterNames();
641  for (const auto& name : parameterNames) {
642  if (name != "coefficients" && name != "deadmodules" && name != "constraint" && name != "steerFilePrefix" &&
643  name != "levels" && name != "excludedAlignables" && name != "ignoredInstances" && name != "downToLowestLevel") {
644  throw cms::Exception("BadConfig") << "@SUB=PedeSteererWeakModeConstraints::verifyParameterNames:"
645  << " Unknown parameter name '" << name << "' in PSet number " << psetnr
646  << ". Maybe a typo?";
647  }
648  }
649 }
650 
651 //_________________________________________________________________________
652 const std::vector<std::pair<Alignable*, std::string> > PedeSteererWeakModeConstraints::makeLevelsFilenames(
653  std::set<std::string>& steerFilePrefixContainer,
654  const align::Alignables& alis,
655  const std::string& steerFilePrefix) const {
656  //check whether the prefix is unique
657  if (steerFilePrefixContainer.find(steerFilePrefix) != steerFilePrefixContainer.end()) {
658  throw cms::Exception("BadConfig") << "[PedeSteererWeakModeConstraints] Steering file"
659  << " prefix '" << steerFilePrefix << "' already exists. Specify unique names!";
660  } else {
661  steerFilePrefixContainer.insert(steerFilePrefix);
662  }
663 
664  std::vector<std::pair<Alignable*, std::string> > levelsFilenames;
665  for (const auto& ali : alis) {
666  std::stringstream n;
667  n << steerFile_ << "_" << steerFilePrefix //<< "_" << name
668  << "_" << alignableObjectId_.idToString(ali->alignableObjectId()) << "_" << ali->id() << "_"
669  << ali->alignableObjectId() << ".txt";
670 
671  levelsFilenames.push_back(std::make_pair(ali, n.str()));
672  }
673  return levelsFilenames;
674 }
675 
676 //_________________________________________________________________________
678  const std::vector<double>& coefficients) const {
679  int sysdeformation = SystematicDeformations::kUnknown;
680 
681  if (name == "twist") {
682  sysdeformation = SystematicDeformations::kTwist;
683  } else if (name == "zexpansion") {
684  sysdeformation = SystematicDeformations::kZexpansion;
685  } else if (name == "sagitta") {
686  sysdeformation = SystematicDeformations::kSagitta;
687  } else if (name == "radial") {
688  sysdeformation = SystematicDeformations::kRadial;
689  } else if (name == "telescope") {
690  sysdeformation = SystematicDeformations::kTelescope;
691  } else if (name == "layerrotation") {
692  sysdeformation = SystematicDeformations::kLayerRotation;
693  } else if (name == "bowing") {
694  sysdeformation = SystematicDeformations::kBowing;
695  } else if (name == "skew") {
696  sysdeformation = SystematicDeformations::kSkew;
697  } else if (name == "elliptical") {
698  sysdeformation = SystematicDeformations::kElliptical;
699  }
700 
701  if (sysdeformation == SystematicDeformations::kUnknown) {
702  throw cms::Exception("BadConfig") << "[PedeSteererWeakModeConstraints]"
703  << " specified configuration option '" << name << "' not known.";
704  }
705  if ((sysdeformation == SystematicDeformations::kSagitta || sysdeformation == SystematicDeformations::kElliptical ||
706  sysdeformation == SystematicDeformations::kSkew) &&
707  coefficients.size() != 2) {
708  throw cms::Exception("BadConfig") << "[PedeSteererWeakModeConstraints]"
709  << " Excactly two parameters using the coefficient"
710  << " variable have to be provided for the " << name << " constraint.";
711  }
712  if ((sysdeformation == SystematicDeformations::kTwist || sysdeformation == SystematicDeformations::kZexpansion ||
713  sysdeformation == SystematicDeformations::kTelescope ||
714  sysdeformation == SystematicDeformations::kLayerRotation || sysdeformation == SystematicDeformations::kRadial ||
715  sysdeformation == SystematicDeformations::kBowing) &&
716  coefficients.size() != 1) {
717  throw cms::Exception("BadConfig") << "[PedeSteererWeakModeConstraints]"
718  << " Excactly ONE parameter using the coefficient"
719  << " variable have to be provided for the " << name << " constraint.";
720  }
721 
722  if (coefficients.empty()) {
723  throw cms::Exception("BadConfig") << "[PedeSteererWeakModeConstraints]"
724  << " At least one coefficient has to be specified.";
725  }
726  return sysdeformation;
727 }
728 
729 //_________________________________________________________________________
730 double PedeSteererWeakModeConstraints::getPhase(const std::vector<double>& coefficients) const {
731  return coefficients.size() == 2 ? coefficients.at(1) : 0.0; //treat second parameter as phase otherwise return 0
732 }
733 
734 //_________________________________________________________________________
SummaryClient_cfi.labels
labels
Definition: SummaryClient_cfi.py:61
PedeSteererWeakModeConstraints::verifyDeformationName
int verifyDeformationName(const std::string &name, const std::vector< double > &coefficients) const
Definition: PedeSteererWeakModeConstraints.cc:677
GeometryConstraintConfigData
Definition: PedeSteererWeakModeConstraints.h:34
alignBH_cfg.fixed
fixed
Definition: alignBH_cfg.py:54
AlignmentParametersFactory.h
MessageLogger.h
PedeSteererWeakModeConstraints::closeOutputfiles
void closeOutputfiles()
Definition: PedeSteererWeakModeConstraints.cc:406
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
GeometryConstraintConfigData::coefficients_
const std::vector< double > coefficients_
Definition: PedeSteererWeakModeConstraints.h:43
ecaldqm::kUnknown
Definition: DBWriterWorkers.cc:55
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
AlignmentParameterSelector.h
TwoBowedSurfacesAlignmentParameters.h
GeometryConstraintConfigData::sysdeformation_
const int sysdeformation_
Definition: PedeSteererWeakModeConstraints.h:50
Alignable
Definition: Alignable.h:27
pos
Definition: PixelAliasList.h:18
PedeSteererWeakModeConstraints::checkSelectionShiftParameter
bool checkSelectionShiftParameter(const Alignable *ali, unsigned int iParameter) const
Definition: PedeSteererWeakModeConstraints.cc:373
AlignableExtras.h
AlignableObjectId::commonObjectIdProvider
static AlignableObjectId commonObjectIdProvider(const AlignableObjectId &, const AlignableObjectId &)
Definition: AlignableObjectId.cc:336
align::PositionType
Point3DBase< Scalar, GlobalTag > PositionType
Definition: Definitions.h:28
GeomDetType.h
DDAxes::x
PedeSteererWeakModeConstraints.h
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
PedeSteererWeakModeConstraints::constructConstraints
unsigned int constructConstraints(const align::Alignables &)
Definition: PedeSteererWeakModeConstraints.cc:513
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
AlignableSurface::length
align::Scalar length() const
Definition: AlignableSurface.h:32
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
PedeLabelerBase.h
RigidBodyAlignmentParameters.h
AlignmentParametersFactory::kTwoBowedSurfaces
Definition: AlignmentParametersFactory.h:28
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
config
Definition: config.py:1
AlignmentParameters::type
virtual int type() const =0
tell type (AlignmentParametersFactory::ParametersType - but no circular dependency)
PedeSteererWeakModeConstraints::getDoubleSensorPosition
std::pair< align::GlobalPoint, align::GlobalPoint > getDoubleSensorPosition(const Alignable *ali) const
Definition: PedeSteererWeakModeConstraints.cc:141
PedeSteererWeakModeConstraints::verifyParameterNames
void verifyParameterNames(const edm::ParameterSet &pset, unsigned int psetnr) const
Definition: PedeSteererWeakModeConstraints.cc:639
Abs
T Abs(T a)
Definition: MathUtil.h:49
LocalError.h
cms::cuda::co
__host__ __device__ VT * co
Definition: prefixScan.h:47
Alignable::alignableObjectId
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
PedeSteererWeakModeConstraints::PedeSteererWeakModeConstraints
PedeSteererWeakModeConstraints(AlignableTracker *aliTracker, const PedeLabelerBase *labels, const std::vector< edm::ParameterSet > &config, std::string sf)
Definition: PedeSteererWeakModeConstraints.cc:68
PedeLabelerBase::alignableLabelFromParamAndInstance
virtual unsigned int alignableLabelFromParamAndInstance(Alignable *alignable, unsigned int param, unsigned int instance) const =0
str
#define str(s)
Definition: TestProcessor.cc:53
AlignableTracker
Definition: AlignableTracker.h:17
PedeSteererWeakModeConstraints::getPhase
double getPhase(const std::vector< double > &coefficients) const
Definition: PedeSteererWeakModeConstraints.cc:730
PedeSteererWeakModeConstraints::myLabels_
const PedeLabelerBase * myLabels_
Definition: PedeSteererWeakModeConstraints.h:132
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
AlignableSurface::toGlobal
align::GlobalPoints toGlobal(const align::LocalPoints &) const
Return in global coord given a set of local points.
Definition: AlignableSurface.cc:15
Alignable::surface
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:132
Point3DBase
Definition: Point3DBase.h:10
AlignmentParameterStore.h
PedeSteererWeakModeConstraints::ConstraintsConfigContainer_
std::list< GeometryConstraintConfigData > ConstraintsConfigContainer_
Definition: PedeSteererWeakModeConstraints.h:130
DTLayer.h
L1TdeCSCTF_cfi.outFile
outFile
Definition: L1TdeCSCTF_cfi.py:5
SiPixelPI::phase
phase
Definition: SiPixelPayloadInspectorHelper.h:39
geometryDiff.file
file
Definition: geometryDiff.py:13
PedeSteererWeakModeConstraints::getX0
double getX0(const std::pair< Alignable *, std::list< Alignable * > > &iHLS, const GeometryConstraintConfigData &it) const
Definition: PedeSteererWeakModeConstraints.cc:460
align::AlignableDetUnit
Definition: StructureType.h:19
edm::ParameterSet
Definition: ParameterSet.h:47
AlignableMuon.h
BowedSurfaceAlignmentDerivatives.h
PedeSteererWeakModeConstraints::~PedeSteererWeakModeConstraints
~PedeSteererWeakModeConstraints()
Alignable::id
align::ID id() const
Return the ID of Alignable, i.e. DetId of 'first' component GeomDet(Unit).
Definition: Alignable.h:180
SelectionUserVariables.h
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
PedeSteererWeakModeConstraints::createAlignablesDataStructure
unsigned int createAlignablesDataStructure()
Definition: PedeSteererWeakModeConstraints.cc:160
GeometryConstraintConfigData::levelsFilenames_
const std::vector< std::pair< Alignable *, std::string > > levelsFilenames_
Definition: PedeSteererWeakModeConstraints.h:45
Alignable::geomDetId
const DetId & geomDetId() const
Definition: Alignable.h:177
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
symbols.dm
dm
Definition: symbols.py:75
PedeLabelerBase
Definition: PedeLabelerBase.h:33
Utilities.h
PedeSteererWeakModeConstraints::deadmodules_
std::list< align::ID > deadmodules_
Definition: PedeSteererWeakModeConstraints.h:127
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PedeSteererWeakModeConstraints::alignableObjectId_
const AlignableObjectId alignableObjectId_
Definition: PedeSteererWeakModeConstraints.h:138
volumeBasedMagneticField_160812_cfi.paramLabel
paramLabel
Definition: volumeBasedMagneticField_160812_cfi.py:37
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
alignCSCRings.r
r
Definition: alignCSCRings.py:93
PedeSteererWeakModeConstraints::writeOutput
void writeOutput(const std::list< std::pair< unsigned int, double > > &output, const GeometryConstraintConfigData &it, const Alignable *iHLS, double sum_xi_x0)
Definition: PedeSteererWeakModeConstraints.cc:422
AlignableObjectId.h
align::AlignableDet
Definition: StructureType.h:20
GeomDet.h
align::Alignables
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
PedeSteererWeakModeConstraints::getFile
std::ofstream * getFile(const GeometryConstraintConfigData &it, const Alignable *iHLS) const
Definition: PedeSteererWeakModeConstraints.cc:442
AlignableSurface
Definition: AlignableSurface.h:20
Exception
Definition: hltDiff.cc:245
PedeLabelerBase::parameterLabel
virtual unsigned int parameterLabel(unsigned int aliLabel, unsigned int parNum) const =0
returns the label for a given alignable parameter number combination
Alignable.h
AlignmentParameters::size
int size(void) const
Get number of parameters.
Definition: AlignmentParameters.cc:131
GeometryConstraintConfigData::GeometryConstraintConfigData
GeometryConstraintConfigData(const std::vector< double > &co, const std::string &c, const std::vector< std::pair< Alignable *, std::string > > &alisFile, const int sd, const align::Alignables &ex, const int instance, const bool downToLowestLevel)
Definition: PedeSteererWeakModeConstraints.cc:51
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
AlignmentParameters::selector
const std::vector< bool > & selector(void) const
Get alignment parameter selector vector.
Definition: AlignmentParameters.cc:48
AlignableObjectId::idToString
const char * idToString(align::StructureType type) const
Definition: AlignableObjectId.cc:273
sd
double sd
Definition: CascadeWrapper.h:113
AlignableTracker.h
PedeSteererWeakModeConstraints::steerFile_
const std::string steerFile_
Definition: PedeSteererWeakModeConstraints.h:136
PedeSteererWeakModeConstraints::makeLevelsFilenames
const std::vector< std::pair< Alignable *, std::string > > makeLevelsFilenames(std::set< std::string > &steerFilePrefixContainer, const align::Alignables &alis, const std::string &steerFilePrefix) const
Definition: PedeSteererWeakModeConstraints.cc:652
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
Alignable::globalPosition
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:135
PedeSteererWeakModeConstraints::checkMother
bool checkMother(const Alignable *const lowleveldet, const Alignable *const HLS) const
Definition: PedeSteererWeakModeConstraints.cc:627
PedeSteererWeakModeConstraints::getX
double getX(const int sysdeformation, const align::GlobalPoint &pos, const double phase) const
Definition: PedeSteererWeakModeConstraints.cc:238
Alignable::alignmentParameters
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:58
GlobalPoint.h
AlignmentParameterSelector
Definition: AlignmentParameterSelector.h:26
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
PedeSteererWeakModeConstraints::getCoefficient
double getCoefficient(const int sysdeformation, const align::GlobalPoint &pos, const GlobalPoint gUDirection, const GlobalPoint gVDirection, const GlobalPoint gWDirection, const int iParameter, const double &x0, const std::vector< double > &constraintparameters) const
Definition: PedeSteererWeakModeConstraints.cc:271
GeometryConstraintConfigData::mapFileName_
std::map< std::string, std::ofstream * > mapFileName_
Definition: PedeSteererWeakModeConstraints.h:47
Alignable::mother
Alignable * mother() const
Return pointer to container alignable (if any)
Definition: Alignable.h:91
TrackerAlignableId.h
PedeSteerer.h