CMS 3D CMS Logo

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