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