CMS 3D CMS Logo

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