CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
PedeSteererWeakModeConstraints Class Reference

#include <PedeSteererWeakModeConstraints.h>

Public Member Functions

unsigned int constructConstraints (const align::Alignables &)
 
std::list< GeometryConstraintConfigData > & getConfigData ()
 
 PedeSteererWeakModeConstraints (AlignableTracker *aliTracker, const PedeLabelerBase *labels, const std::vector< edm::ParameterSet > &config, std::string sf)
 
 ~PedeSteererWeakModeConstraints ()
 

Private Types

enum  SystematicDeformations {
  kUnknown = 0, kTwist, kZexpansion, kSagitta,
  kRadial, kTelescope, kLayerRotation, kElliptical,
  kBowing, kSkew
}
 

Private Member Functions

bool checkMother (const Alignable *const lowleveldet, const Alignable *const HLS) const
 
bool checkSelectionShiftParameter (const Alignable *ali, unsigned int iParameter) const
 
void closeOutputfiles ()
 
unsigned int createAlignablesDataStructure ()
 
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
 
std::pair< align::GlobalPoint, align::GlobalPointgetDoubleSensorPosition (const Alignable *ali) const
 
std::ofstream * getFile (const GeometryConstraintConfigData &it, const Alignable *iHLS) const
 
double getPhase (const std::vector< double > &coefficients) const
 
double getX (const int sysdeformation, const align::GlobalPoint &pos, const double phase) const
 
double getX0 (const std::pair< Alignable *, std::list< Alignable *> > &iHLS, const GeometryConstraintConfigData &it) const
 
const std::vector< std::pair< Alignable *, std::string > > makeLevelsFilenames (std::set< std::string > &steerFilePrefixContainer, const align::Alignables &alis, const std::string &steerFilePrefix) const
 
int verifyDeformationName (const std::string &name, const std::vector< double > &coefficients) const
 
void verifyParameterNames (const edm::ParameterSet &pset, unsigned int psetnr) const
 
void writeOutput (const std::list< std::pair< unsigned int, double > > &output, const GeometryConstraintConfigData &it, const Alignable *iHLS, double sum_xi_x0)
 

Private Attributes

const AlignableObjectId alignableObjectId_
 
std::list< GeometryConstraintConfigDataConstraintsConfigContainer_
 
std::list< align::IDdeadmodules_
 
const std::vector< edm::ParameterSetmyConfig_
 
const PedeLabelerBasemyLabels_
 
const std::string steerFile_
 

Detailed Description

Provides steering of weak mode constraints for Pede according to configuration

Author
: Joerg Behr date : February 2013

Definition at line 56 of file PedeSteererWeakModeConstraints.h.

Member Enumeration Documentation

◆ SystematicDeformations

Constructor & Destructor Documentation

◆ ~PedeSteererWeakModeConstraints()

PedeSteererWeakModeConstraints::~PedeSteererWeakModeConstraints ( )
default

◆ PedeSteererWeakModeConstraints()

PedeSteererWeakModeConstraints::PedeSteererWeakModeConstraints ( AlignableTracker aliTracker,
const PedeLabelerBase labels,
const std::vector< edm::ParameterSet > &  config,
std::string  sf 
)

Definition at line 68 of file PedeSteererWeakModeConstraints.cc.

References AlignableObjectId::commonObjectIdProvider().

72  : myLabels_(labels),
74  steerFile_(sf),
76  unsigned int psetnr = 0;
77  std::set<std::string> steerFilePrefixContainer;
78  for (const auto& pset : myConfig_) {
79  this->verifyParameterNames(pset, psetnr);
80  psetnr++;
81 
82  const auto coefficients = pset.getParameter<std::vector<double> >("coefficients");
83  const auto dm = pset.exists("deadmodules") ? pset.getParameter<std::vector<unsigned int> >("deadmodules")
84  : std::vector<unsigned int>();
85  std::string name = pset.getParameter<std::string>("constraint");
86  std::transform(name.begin(), name.end(), name.begin(), ::tolower);
87  const auto ignoredInstances = pset.exists("ignoredInstances")
88  ? pset.getUntrackedParameter<std::vector<unsigned int> >("ignoredInstances")
89  : std::vector<unsigned int>();
90 
91  const auto downToLowestLevel =
92  pset.exists("downToLowestLevel") ? pset.getUntrackedParameter<bool>("downToLowestLevel") : false;
93 
94  AlignmentParameterSelector selector(aliTracker, nullptr, nullptr);
95  selector.clear();
96  selector.addSelections(pset.getParameter<edm::ParameterSet>("levels"));
97 
98  const auto& alis = selector.selectedAlignables();
99 
100  AlignmentParameterSelector selector_excludedalignables(aliTracker, nullptr, nullptr);
101  selector_excludedalignables.clear();
102  if (pset.exists("excludedAlignables")) {
103  selector_excludedalignables.addSelections(pset.getParameter<edm::ParameterSet>("excludedAlignables"));
104  }
105  const auto& excluded_alis = selector_excludedalignables.selectedAlignables();
106 
107  //check that the name of the deformation is known and that the number
108  //of provided parameter is right.
109  auto sysdeformation = this->verifyDeformationName(name, coefficients);
110 
111  if (deadmodules_.empty()) { //fill the list of dead modules only once
112  edm::LogInfo("Alignment") << "@SUB=PedeSteererWeakModeConstraints"
113  << "Load list of dead modules (size = " << dm.size() << ").";
114  for (const auto& it : dm)
115  deadmodules_.push_back(it);
116  }
117 
118  // loop over all IOVs/momentum ranges
119  for (unsigned int instance = 0; instance < myLabels_->maxNumberOfParameterInstances(); ++instance) {
120  // check if this IOV/momentum range is to be ignored:
121  if (std::find(ignoredInstances.begin(), ignoredInstances.end(), instance) != ignoredInstances.end()) {
122  continue;
123  }
124  std::stringstream defaultsteerfileprefix;
125  defaultsteerfileprefix << "autosteerFilePrefix_" << name << "_" << psetnr << "_" << instance;
126 
127  const auto steerFilePrefix = pset.exists("steerFilePrefix") ? pset.getParameter<std::string>("steerFilePrefix") +
128  "_" + std::to_string(instance)
129  : defaultsteerfileprefix.str();
130 
131  const auto levelsFilenames = this->makeLevelsFilenames(steerFilePrefixContainer, alis, steerFilePrefix);
132 
133  //Add the configuration data for this constraint to the container of config data
135  coefficients, name, levelsFilenames, sysdeformation, excluded_alis, instance, downToLowestLevel));
136  }
137  }
138 }
static AlignableObjectId commonObjectIdProvider(const AlignableObjectId &, const AlignableObjectId &)
static PFTauRenderPlugin instance
std::string to_string(const V &value)
Definition: OMSAccess.h:71
Definition: config.py:1
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
int verifyDeformationName(const std::string &name, const std::vector< double > &coefficients) const
const std::vector< edm::ParameterSet > myConfig_
Log< level::Info, false > LogInfo
const std::vector< std::pair< Alignable *, std::string > > makeLevelsFilenames(std::set< std::string > &steerFilePrefixContainer, const align::Alignables &alis, const std::string &steerFilePrefix) const
void verifyParameterNames(const edm::ParameterSet &pset, unsigned int psetnr) const
#define str(s)
virtual unsigned int maxNumberOfParameterInstances() const =0
returns the maximum number of instances for any parameter of an Alignable*
std::list< GeometryConstraintConfigData > ConstraintsConfigContainer_
unsigned transform(const HcalDetId &id, unsigned transformCode)

Member Function Documentation

◆ checkMother()

bool PedeSteererWeakModeConstraints::checkMother ( const Alignable *const  lowleveldet,
const Alignable *const  HLS 
) const
private

Definition at line 627 of file PedeSteererWeakModeConstraints.cc.

References Alignable::alignableObjectId(), Alignable::id(), and Alignable::mother().

Referenced by createAlignablesDataStructure().

627  {
628  if (lowleveldet->id() == HLS->id() && lowleveldet->alignableObjectId() == HLS->alignableObjectId()) {
629  return true;
630  } else {
631  if (lowleveldet->mother() == nullptr)
632  return false;
633  else
634  return this->checkMother(lowleveldet->mother(), HLS);
635  }
636 }
Alignable * mother() const
Return pointer to container alignable (if any)
Definition: Alignable.h:91
bool checkMother(const Alignable *const lowleveldet, const Alignable *const HLS) const
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:180

◆ checkSelectionShiftParameter()

bool PedeSteererWeakModeConstraints::checkSelectionShiftParameter ( const Alignable ali,
unsigned int  iParameter 
) const
private

Definition at line 373 of file PedeSteererWeakModeConstraints.cc.

References Alignable::alignableObjectId(), alignableObjectId_, Alignable::alignmentParameters(), Exception, Alignable::globalPosition(), AlignableObjectId::idToString(), submitPVValidationJobs::params, AlignmentParameters::selector(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by constructConstraints(), and getX0().

373  {
374  bool isselected = false;
375  const std::vector<bool>& aliSel = ali->alignmentParameters()->selector();
376  //exclude non-shift parameters
377  if ((iParameter <= 2) || (iParameter >= 9 && iParameter <= 11)) {
378  if (!aliSel.at(iParameter)) {
379  isselected = false;
380  } else {
381  auto params = ali->alignmentParameters();
382  auto selVar = dynamic_cast<SelectionUserVariables*>(params->userVariables());
383  if (selVar) {
384  if (selVar->fullSelection().size() <= (iParameter + 1)) {
385  throw cms::Exception("Alignment")
386  << "[PedeSteererWeakModeConstraints::checkSelectionShiftParameter]"
387  << " Can not access selected alignment variables of alignable "
388  << alignableObjectId_.idToString(ali->alignableObjectId()) << "at (" << ali->globalPosition().x() << ","
389  << ali->globalPosition().y() << "," << ali->globalPosition().z() << ") "
390  << "for parameter number " << (iParameter + 1) << ".";
391  }
392  }
393  const char selChar = (selVar ? selVar->fullSelection().at(iParameter) : '1');
394  // if(selChar == '1') { //FIXME??? what about 'r'?
395  if (selChar == '1' || selChar == 'r') {
396  isselected = true;
397  } else {
398  isselected = false;
399  }
400  }
401  }
402  return isselected;
403 }
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:58
T z() const
Definition: PV3DBase.h:61
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:135
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
const char * idToString(align::StructureType type) const
const std::vector< bool > & selector(void) const
Get alignment parameter selector vector.

◆ closeOutputfiles()

void PedeSteererWeakModeConstraints::closeOutputfiles ( )
private

Definition at line 406 of file PedeSteererWeakModeConstraints.cc.

References ConstraintsConfigContainer_, and Exception.

Referenced by constructConstraints().

406  {
407  //'delete' output files which means: close them
408  for (auto& it : ConstraintsConfigContainer_) {
409  for (auto& iFile : it.mapFileName_) {
410  if (iFile.second) {
411  delete iFile.second;
412  iFile.second = nullptr;
413  } else {
414  throw cms::Exception("FileCloseProblem") << "[PedeSteererWeakModeConstraints]"
415  << " can not close file " << iFile.first << ".";
416  }
417  }
418  }
419 }
std::list< GeometryConstraintConfigData > ConstraintsConfigContainer_

◆ constructConstraints()

unsigned int PedeSteererWeakModeConstraints::constructConstraints ( const align::Alignables alis)

Definition at line 513 of file PedeSteererWeakModeConstraints.cc.

References PedeLabelerBase::alignableLabelFromParamAndInstance(), Alignable::alignableObjectId(), alignableObjectId_, Alignable::alignmentParameters(), checkSelectionShiftParameter(), closeOutputfiles(), ConstraintsConfigContainer_, createAlignablesDataStructure(), Exception, spr::find(), Alignable::geomDetId(), getCoefficient(), getDoubleSensorPosition(), getFile(), getPhase(), getX(), getX0(), Alignable::globalPosition(), AlignableObjectId::idToString(), AlignmentParametersFactory::kTwoBowedSurfaces, myLabels_, L1TdeCSCTF_cfi::outFile, convertSQLitetoXML_cfg::output, PedeLabelerBase::parameterLabel(), volumeBasedMagneticField_160812_cfi::paramLabel, DetId::rawId(), AlignmentParameters::size(), Alignable::surface(), AlignableSurface::toGlobal(), AlignmentParameters::type(), writeOutput(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by PedeSteerer::buildSubSteer().

513  {
514  //FIXME: split the code of the method into smaller pieces/submethods
515 
516  //create the data structures that store the alignables
517  //for which the constraints need to be calculated and
518  //their association to high-level structures
519  const auto nConstraints = this->createAlignablesDataStructure();
520 
521  std::vector<std::list<std::pair<unsigned int, double> > > createdConstraints;
522 
523  //calculate constraints
524  //loop over all constraints
525  for (const auto& it : ConstraintsConfigContainer_) {
526  //loop over all subdets for which constraints are determined
527  for (const auto& iHLS : it.HLSsubdets_) {
528  double sum_xi_x0 = 0.0;
529  std::list<std::pair<unsigned int, double> > output;
530 
531  const double x0 = this->getX0(iHLS, it);
532 
533  for (std::list<Alignable*>::const_iterator iAlignables = iHLS.second.begin(); iAlignables != iHLS.second.end();
534  iAlignables++) {
535  const Alignable* ali = (*iAlignables);
536  const auto aliLabel =
537  myLabels_->alignableLabelFromParamAndInstance(const_cast<Alignable*>(ali), 0, it.instance_);
538  const AlignableSurface& surface = ali->surface();
539 
540  const LocalPoint lUDirection(1., 0., 0.), lVDirection(0., 1., 0.), lWDirection(0., 0., 1.);
541 
542  GlobalPoint gUDirection = surface.toGlobal(lUDirection), gVDirection = surface.toGlobal(lVDirection),
543  gWDirection = surface.toGlobal(lWDirection);
544 
545  const bool isDoubleSensor = ali->alignmentParameters()->type() == AlignmentParametersFactory::kTwoBowedSurfaces;
546 
547  const auto sensorpositions = isDoubleSensor ? this->getDoubleSensorPosition(ali)
548  : std::make_pair(ali->globalPosition(), align::PositionType());
549 
550  const auto& pos_sensor0 = sensorpositions.first;
551  const auto& pos_sensor1 = sensorpositions.second;
552  const auto phase = this->getPhase(it.coefficients_);
553  const auto x_sensor0 = this->getX(it.sysdeformation_, pos_sensor0, phase);
554  const auto x_sensor1 = isDoubleSensor ? this->getX(it.sysdeformation_, pos_sensor1, phase) : 0.0;
555 
556  sum_xi_x0 += (x_sensor0 - x0) * (x_sensor0 - x0);
557  if (isDoubleSensor) {
558  sum_xi_x0 += (x_sensor1 - x0) * (x_sensor1 - x0);
559  }
560  const int numparameterlimit = ali->alignmentParameters()->size(); //isDoubleSensor ? 18 : 3;
561 
562  for (int iParameter = 0; iParameter < numparameterlimit; iParameter++) {
563  int localindex = 0;
564  if (iParameter == 0 || iParameter == 9)
565  localindex = 0;
566  if (iParameter == 1 || iParameter == 10)
567  localindex = 1;
568  if (iParameter == 2 || iParameter == 11)
569  localindex = 2;
570 
571  if ((iParameter >= 0 && iParameter <= 2) || (iParameter >= 9 && iParameter <= 11)) {
572  } else {
573  continue;
574  }
575  if (!this->checkSelectionShiftParameter(ali, iParameter)) {
576  continue;
577  }
578  //do it for each 'instance' separately? -> IOV-dependence, no
579  const auto paramLabel = myLabels_->parameterLabel(aliLabel, iParameter);
580 
581  const auto& pos = (iParameter <= 2) ? pos_sensor0 : pos_sensor1;
582  //select only u,v,w
583  if (iParameter == 0 || iParameter == 1 || iParameter == 2 || iParameter == 9 || iParameter == 10 ||
584  iParameter == 11) {
585  const double coeff = this->getCoefficient(
586  it.sysdeformation_, pos, gUDirection, gVDirection, gWDirection, localindex, x0, it.coefficients_);
587  if (TMath::Abs(coeff) > 0.0) {
588  //nothing
589  } else {
590  edm::LogWarning("PedeSteererWeakModeConstraints")
591  << "@SUB=PedeSteererWeakModeConstraints::getCoefficient"
592  << "Coefficient of alignable " << alignableObjectId_.idToString(ali->alignableObjectId()) << " at ("
593  << ali->globalPosition().x() << "," << ali->globalPosition().y() << "," << ali->globalPosition().z()
594  << ") "
595  << " in subdet " << alignableObjectId_.idToString(iHLS.first->alignableObjectId())
596  << " for parameter " << localindex << " equal to zero. This alignable is used in the constraint"
597  << " '" << it.constraintName_
598  << "'. The id is: alignable->geomDetId().rawId() = " << ali->geomDetId().rawId() << ".";
599  }
600  output.push_back(std::make_pair(paramLabel, coeff));
601  }
602  }
603  }
604 
605  if (std::find(createdConstraints.begin(), createdConstraints.end(), output) != createdConstraints.end()) {
606  // check if linearly dependent constraint exists already:
607  auto outFile = getFile(it, iHLS.first);
608  if (outFile == nullptr) {
609  throw cms::Exception("FileFindError") << "[PedeSteererWeakModeConstraints] Cannot find output file.";
610  } else {
611  *outFile << "! The constraint for this IOV/momentum range" << std::endl
612  << "! has been removed because the used parameters" << std::endl
613  << "! are not IOV or momentum-range dependent." << std::endl;
614  }
615  continue;
616  }
617  this->writeOutput(output, it, iHLS.first, sum_xi_x0);
618  createdConstraints.push_back(output);
619  }
620  }
621  this->closeOutputfiles();
622 
623  return nConstraints;
624 }
align::GlobalPoints toGlobal(const align::LocalPoints &) const
Return in global coord given a set of local points.
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:58
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:132
T z() const
Definition: PV3DBase.h:61
std::ofstream * getFile(const GeometryConstraintConfigData &it, const Alignable *iHLS) const
std::pair< align::GlobalPoint, align::GlobalPoint > getDoubleSensorPosition(const Alignable *ali) const
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:19
bool checkSelectionShiftParameter(const Alignable *ali, unsigned int iParameter) const
virtual unsigned int parameterLabel(unsigned int aliLabel, unsigned int parNum) const =0
returns the label for a given alignable parameter number combination
Point3DBase< Scalar, GlobalTag > PositionType
Definition: Definitions.h:28
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:135
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
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
int size(void) const
Get number of parameters.
virtual unsigned int alignableLabelFromParamAndInstance(Alignable *alignable, unsigned int param, unsigned int instance) const =0
double getPhase(const std::vector< double > &coefficients) const
virtual int type() const =0
tell type (AlignmentParametersFactory::ParametersType - but no circular dependency) ...
const char * idToString(align::StructureType type) const
const DetId & geomDetId() const
Definition: Alignable.h:177
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
double getX(const int sysdeformation, const align::GlobalPoint &pos, const double phase) const
Log< level::Warning, false > LogWarning
std::list< GeometryConstraintConfigData > ConstraintsConfigContainer_
double getX0(const std::pair< Alignable *, std::list< Alignable *> > &iHLS, const GeometryConstraintConfigData &it) const

◆ createAlignablesDataStructure()

unsigned int PedeSteererWeakModeConstraints::createAlignablesDataStructure ( )
private

Definition at line 160 of file PedeSteererWeakModeConstraints.cc.

References align::AlignableDet, align::AlignableDetUnit, alignableObjectId_, checkMother(), ConstraintsConfigContainer_, deadmodules_, Exception, and AlignableObjectId::idToString().

Referenced by constructConstraints().

160  {
161  unsigned int nConstraints = 0;
162  for (auto& iC : ConstraintsConfigContainer_) {
163  //loop over all HLS for which the constraint is to be determined
164  for (const auto& iHLS : iC.levelsFilenames_) {
165  //determine next active sub-alignables for iHLS
166  align::Alignables aliDaughts;
167  if (iC.downToLowestLevel_) {
168  if (!iHLS.first->lastCompsWithParams(aliDaughts)) {
169  edm::LogWarning("Alignment") << "@SUB=PedeSteererWeakModeConstraints::createAlignablesDataStructure"
170  << "Some but not all component branches "
171  << alignableObjectId_.idToString(iHLS.first->alignableObjectId())
172  << " with params!";
173  }
174  } else {
175  if (!iHLS.first->firstCompsWithParams(aliDaughts)) {
176  edm::LogWarning("Alignment") << "@SUB=PedeSteererWeakModeConstraints::createAlignablesDataStructure"
177  << "Some but not all daughters of "
178  << alignableObjectId_.idToString(iHLS.first->alignableObjectId())
179  << " with params!";
180  }
181  }
182  ++nConstraints;
183 
184  std::list<Alignable*> usedinconstraint;
185  for (const auto& iD : aliDaughts) {
186  bool isNOTdead = true;
187  for (const auto& iDeadmodules : deadmodules_) {
188  if ((iD->alignableObjectId() == align::AlignableDetUnit || iD->alignableObjectId() == align::AlignableDet) &&
189  iD->geomDetId().rawId() == iDeadmodules) {
190  isNOTdead = false;
191  break;
192  }
193  }
194  //check if the module is excluded
195  for (const auto& iEx : iC.excludedAlignables_) {
196  if (iD->id() == iEx->id() && iD->alignableObjectId() == iEx->alignableObjectId()) {
197  //if(iD->geomDetId().rawId() == (*iEx)->geomDetId().rawId()) {
198  isNOTdead = false;
199  break;
200  }
201  }
202  const bool issubcomponent = this->checkMother(iD, iHLS.first);
203  if (issubcomponent) {
204  if (isNOTdead) {
205  usedinconstraint.push_back(iD);
206  }
207  } else {
208  //sanity check
209  throw cms::Exception("Alignment") << "[PedeSteererWeakModeConstraints::createAlignablesDataStructure]"
210  << " Sanity check failed. Alignable defined as active sub-component, "
211  << " but in fact its not a daugther of "
212  << alignableObjectId_.idToString(iHLS.first->alignableObjectId());
213  }
214  }
215 
216  if (!usedinconstraint.empty()) {
217  iC.HLSsubdets_.push_back(std::make_pair(iHLS.first, usedinconstraint));
218  } else {
219  edm::LogInfo("Alignment") << "@SUB=PedeSteererWeakModeConstraints"
220  << "No sub-components for "
221  << alignableObjectId_.idToString(iHLS.first->alignableObjectId()) << " at ("
222  << iHLS.first->globalPosition().x() << "," << iHLS.first->globalPosition().y() << ","
223  << iHLS.first->globalPosition().z() << ") selected. Skip constraint";
224  }
225  if (aliDaughts.empty()) {
226  edm::LogWarning("Alignment") << "@SUB=PedeSteererWeakModeConstraints::createAlignablesDataStructure"
227  << "No active sub-alignables found for "
228  << alignableObjectId_.idToString(iHLS.first->alignableObjectId()) << " at ("
229  << iHLS.first->globalPosition().x() << "," << iHLS.first->globalPosition().y()
230  << "," << iHLS.first->globalPosition().z() << ").";
231  }
232  }
233  }
234  return nConstraints;
235 }
bool checkMother(const Alignable *const lowleveldet, const Alignable *const HLS) const
Log< level::Info, false > LogInfo
const char * idToString(align::StructureType type) const
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
Log< level::Warning, false > LogWarning
std::list< GeometryConstraintConfigData > ConstraintsConfigContainer_

◆ getCoefficient()

double PedeSteererWeakModeConstraints::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
private

Definition at line 271 of file PedeSteererWeakModeConstraints.cc.

References Exception, getPhase(), getX(), dqmiodumpmetadata::n, alignCSCRings::r, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by constructConstraints().

278  {
279  if (iParameter < 0 || iParameter > 2) {
280  throw cms::Exception("Alignment") << "[PedeSteererWeakModeConstraints::getCoefficient]"
281  << " iParameter has to be in the range [0,2] but"
282  << " it is equal to " << iParameter << ".";
283  }
284 
285  //global vectors pointing in u,v,w direction
286  const std::vector<double> vec_u = {pos.x() - gUDirection.x(), pos.y() - gUDirection.y(), pos.z() - gUDirection.z()};
287  const std::vector<double> vec_v = {pos.x() - gVDirection.x(), pos.y() - gVDirection.y(), pos.z() - gVDirection.z()};
288  const std::vector<double> vec_w = {pos.x() - gWDirection.x(), pos.y() - gWDirection.y(), pos.z() - gWDirection.z()};
289 
290  //FIXME: how to make inner vectors const?
291  const std::vector<std::vector<double> > global_vecs = {vec_u, vec_v, vec_w};
292 
293  const double n = TMath::Sqrt(global_vecs.at(iParameter).at(0) * global_vecs.at(iParameter).at(0) +
294  global_vecs.at(iParameter).at(1) * global_vecs.at(iParameter).at(1) +
295  global_vecs.at(iParameter).at(2) * global_vecs.at(iParameter).at(2));
296  const double r = TMath::Sqrt(pos.x() * pos.x() + pos.y() * pos.y());
297 
298  const double phase = this->getPhase(constraintparameters);
299  //const double radial_direction[3] = {TMath::Sin(phase), TMath::Cos(phase), 0.0};
300  const std::vector<double> radial_direction = {TMath::Sin(phase), TMath::Cos(phase), 0.0};
301  //is equal to unity by construction ...
302  const double norm_radial_direction =
303  TMath::Sqrt(radial_direction.at(0) * radial_direction.at(0) + radial_direction.at(1) * radial_direction.at(1) +
304  radial_direction.at(2) * radial_direction.at(2));
305 
306  //const double phi_direction[3] = { -1.0 * pos.y(), pos.x(), 0.0};
307  const std::vector<double> phi_direction = {-1.0 * pos.y(), pos.x(), 0.0};
308  const double norm_phi_direction =
309  TMath::Sqrt(phi_direction.at(0) * phi_direction.at(0) + phi_direction.at(1) * phi_direction.at(1) +
310  phi_direction.at(2) * phi_direction.at(2));
311 
312  //const double z_direction[3] = {0.0, 0.0, 1.0};
313  static const std::vector<double> z_direction = {0.0, 0.0, 1.0};
314  const double norm_z_direction =
315  TMath::Sqrt(z_direction.at(0) * z_direction.at(0) + z_direction.at(1) * z_direction.at(1) +
316  z_direction.at(2) * z_direction.at(2));
317 
318  //unit vector pointing from the origin to the module position in the transverse plane
319  const std::vector<double> rDirection = {pos.x(), pos.y(), 0.0};
320  const double norm_rDirection = TMath::Sqrt(rDirection.at(0) * rDirection.at(0) + rDirection.at(1) * rDirection.at(1) +
321  rDirection.at(2) * rDirection.at(2));
322 
323  double coeff = 0.0;
324  double dot_product = 0.0;
325  double normalisation_factor = 1.0;
326 
327  //see https://indico.cern.ch/getFile.py/access?contribId=15&sessionId=1&resId=0&materialId=slides&confId=127126
328  switch (sysdeformation) {
329  case SystematicDeformations::kTwist:
330  case SystematicDeformations::kLayerRotation:
331  dot_product = phi_direction.at(0) * global_vecs.at(iParameter).at(0) +
332  phi_direction.at(1) * global_vecs.at(iParameter).at(1) +
333  phi_direction.at(2) * global_vecs.at(iParameter).at(2);
334  normalisation_factor = r * n * norm_phi_direction;
335  break;
336  case SystematicDeformations::kZexpansion:
337  case SystematicDeformations::kTelescope:
338  case SystematicDeformations::kSkew:
339  dot_product = global_vecs.at(iParameter).at(0) * z_direction.at(0) +
340  global_vecs.at(iParameter).at(1) * z_direction.at(1) +
341  global_vecs.at(iParameter).at(2) * z_direction.at(2);
342  normalisation_factor = (n * norm_z_direction);
343  break;
344  case SystematicDeformations::kRadial:
345  case SystematicDeformations::kBowing:
346  case SystematicDeformations::kElliptical:
347  dot_product = global_vecs.at(iParameter).at(0) * rDirection.at(0) +
348  global_vecs.at(iParameter).at(1) * rDirection.at(1) +
349  global_vecs.at(iParameter).at(2) * rDirection.at(2);
350  normalisation_factor = (n * norm_rDirection);
351  break;
352  case SystematicDeformations::kSagitta:
353  dot_product = global_vecs.at(iParameter).at(0) * radial_direction.at(0) +
354  global_vecs.at(iParameter).at(1) * radial_direction.at(1) +
355  global_vecs.at(iParameter).at(2) * radial_direction.at(2);
356  normalisation_factor = (n * norm_radial_direction);
357  break;
358  default:
359  break;
360  }
361 
362  if (TMath::Abs(normalisation_factor) > 0.0) {
363  coeff = dot_product * (this->getX(sysdeformation, pos, phase) - x0) / normalisation_factor;
364  } else {
365  throw cms::Exception("Alignment") << "[PedeSteererWeakModeConstraints::getCoefficient]"
366  << " Normalisation factor"
367  << "for coefficient calculation equal to zero! Misconfiguration?";
368  }
369  return coeff;
370 }
T z() const
Definition: PV3DBase.h:61
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
double getPhase(const std::vector< double > &coefficients) const
double getX(const int sysdeformation, const align::GlobalPoint &pos, const double phase) const

◆ getConfigData()

std::list<GeometryConstraintConfigData>& PedeSteererWeakModeConstraints::getConfigData ( )
inline

Definition at line 69 of file PedeSteererWeakModeConstraints.h.

References ConstraintsConfigContainer_.

Referenced by PedeSteerer::buildSubSteer().

std::list< GeometryConstraintConfigData > ConstraintsConfigContainer_

◆ getDoubleSensorPosition()

std::pair< align::GlobalPoint, align::GlobalPoint > PedeSteererWeakModeConstraints::getDoubleSensorPosition ( const Alignable ali) const
private

Definition at line 141 of file PedeSteererWeakModeConstraints.cc.

References Alignable::alignmentParameters(), Exception, AlignableSurface::length(), Alignable::surface(), AlignableSurface::toGlobal(), and TwoBowedSurfacesAlignmentParameters::ySplit().

Referenced by constructConstraints(), and getX0().

142  {
143  const auto aliPar = dynamic_cast<TwoBowedSurfacesAlignmentParameters*>(ali->alignmentParameters());
144  if (aliPar) {
145  const auto ySplit = aliPar->ySplit();
146  const auto halfLength = 0.5 * ali->surface().length();
147  const auto yM1 = 0.5 * (ySplit - halfLength); // y_mean of surface 1
148  const auto yM2 = yM1 + halfLength; // y_mean of surface 2
149  const auto pos_sensor0(ali->surface().toGlobal(align::LocalPoint(0., yM1, 0.)));
150  const auto pos_sensor1(ali->surface().toGlobal(align::LocalPoint(0., yM2, 0.)));
151  return std::make_pair(pos_sensor0, pos_sensor1);
152  } else {
153  throw cms::Exception("Alignment") << "[PedeSteererWeakModeConstraints::getDoubleSensorPosition]"
154  << " Dynamic cast to double sensor parameters failed.";
155  return std::make_pair(align::GlobalPoint(0.0, 0.0, 0.0), align::GlobalPoint(0.0, 0.0, 0.0));
156  }
157 }
align::GlobalPoints toGlobal(const align::LocalPoints &) const
Return in global coord given a set of local points.
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:58
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:132
align::Scalar length() const

◆ getFile()

std::ofstream * PedeSteererWeakModeConstraints::getFile ( const GeometryConstraintConfigData it,
const Alignable iHLS 
) const
private

Definition at line 442 of file PedeSteererWeakModeConstraints.cc.

References Alignable::alignableObjectId(), geometryDiff::file, Alignable::id(), GeometryConstraintConfigData::levelsFilenames_, and GeometryConstraintConfigData::mapFileName_.

Referenced by constructConstraints(), and writeOutput().

443  {
444  std::ofstream* file = nullptr;
445 
446  for (const auto& ilevelsFilename : it.levelsFilenames_) {
447  if (ilevelsFilename.first->id() == iHLS->id() &&
448  ilevelsFilename.first->alignableObjectId() == iHLS->alignableObjectId()) {
449  const auto iFile = it.mapFileName_.find(ilevelsFilename.second);
450  if (iFile != it.mapFileName_.end()) {
451  file = iFile->second;
452  }
453  }
454  }
455 
456  return file;
457 }
const std::vector< std::pair< Alignable *, std::string > > levelsFilenames_
std::map< std::string, std::ofstream * > mapFileName_
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:180

◆ getPhase()

double PedeSteererWeakModeConstraints::getPhase ( const std::vector< double > &  coefficients) const
private

Definition at line 730 of file PedeSteererWeakModeConstraints.cc.

Referenced by constructConstraints(), getCoefficient(), and getX0().

730  {
731  return coefficients.size() == 2 ? coefficients.at(1) : 0.0; //treat second parameter as phase otherwise return 0
732 }

◆ getX()

double PedeSteererWeakModeConstraints::getX ( const int  sysdeformation,
const align::GlobalPoint pos,
const double  phase 
) const
private

Definition at line 238 of file PedeSteererWeakModeConstraints.cc.

References alignCSCRings::r, and x.

Referenced by constructConstraints(), getCoefficient(), and getX0().

240  {
241  double x = 0.0;
242 
243  const double r = TMath::Sqrt(pos.x() * pos.x() + pos.y() * pos.y());
244 
245  switch (sysdeformation) {
246  case SystematicDeformations::kTwist:
247  case SystematicDeformations::kZexpansion:
248  x = pos.z();
249  break;
250  case SystematicDeformations::kSagitta:
251  case SystematicDeformations::kRadial:
252  case SystematicDeformations::kTelescope:
253  case SystematicDeformations::kLayerRotation:
254  x = r;
255  break;
256  case SystematicDeformations::kBowing:
257  x = pos.z() * pos.z(); //TMath::Abs(pos.z());
258  break;
259  case SystematicDeformations::kElliptical:
260  x = r * TMath::Cos(2.0 * pos.phi() + phase);
261  break;
262  case SystematicDeformations::kSkew:
263  x = TMath::Cos(pos.phi() + phase);
264  break;
265  };
266 
267  return x;
268 }

◆ getX0()

double PedeSteererWeakModeConstraints::getX0 ( const std::pair< Alignable *, std::list< Alignable *> > &  iHLS,
const GeometryConstraintConfigData it 
) const
private

Definition at line 460 of file PedeSteererWeakModeConstraints.cc.

References checkSelectionShiftParameter(), GeometryConstraintConfigData::coefficients_, Exception, getDoubleSensorPosition(), getPhase(), getX(), AlignmentParametersFactory::kTwoBowedSurfaces, and GeometryConstraintConfigData::sysdeformation_.

Referenced by constructConstraints().

461  {
462  double nmodules = 0.0;
463  double x0 = 0.0;
464 
465  for (const auto& ali : iHLS.second) {
466  align::PositionType pos = ali->globalPosition();
467  bool alignableIsFloating = false; //means: true=alignable is able to move in at least one direction
468 
469  //test whether at least one variable has been selected in the configuration
470  for (unsigned int iParameter = 0; static_cast<int>(iParameter) < ali->alignmentParameters()->size(); iParameter++) {
471  if (this->checkSelectionShiftParameter(ali, iParameter)) {
472  alignableIsFloating = true;
473  // //verify that alignable has just one label -- meaning no IOV-dependence etc
474  // const unsigned int nInstances = myLabels_->numberOfParameterInstances(ali, iParameter);
475  // if(nInstances > 1) {
476  // throw cms::Exception("PedeSteererWeakModeConstraints")
477  // << "@SUB=PedeSteererWeakModeConstraints::ConstructConstraints"
478  // << " Weak mode constraints are only supported for alignables which have"
479  // << " just one label. However, e.g. alignable"
480  // << " " << alignableObjectId_.idToString(ali->alignableObjectId())
481  // << "at (" << ali->globalPosition().x() << ","<< ali->globalPosition().y() << "," << ali->globalPosition().z()<< "), "
482  // << " was configured to have >1 label. Remove e.g. IOV-dependence for this (and other) alignables which are used in the constraint.";
483  // }
484  break;
485  }
486  }
487  //at least one parameter of the alignable can be changed in the alignment
488  if (alignableIsFloating) {
489  const auto phase = this->getPhase(it.coefficients_);
490  if (ali->alignmentParameters()->type() != AlignmentParametersFactory::kTwoBowedSurfaces) {
491  x0 += this->getX(it.sysdeformation_, pos, phase);
492  nmodules++;
493  } else {
494  std::pair<align::GlobalPoint, align::GlobalPoint> sensorpositions = this->getDoubleSensorPosition(ali);
495  x0 += this->getX(it.sysdeformation_, sensorpositions.first, phase) +
496  this->getX(it.sysdeformation_, sensorpositions.second, phase);
497  nmodules++;
498  nmodules++;
499  }
500  }
501  }
502  if (nmodules > 0) {
503  x0 = x0 / nmodules;
504  } else {
505  throw cms::Exception("Alignment") << "@SUB=PedeSteererWeakModeConstraints::ConstructConstraints"
506  << " Number of selected modules equal to zero. Check configuration!";
507  x0 = 1.0;
508  }
509  return x0;
510 }
std::pair< align::GlobalPoint, align::GlobalPoint > getDoubleSensorPosition(const Alignable *ali) const
bool checkSelectionShiftParameter(const Alignable *ali, unsigned int iParameter) const
const std::vector< double > coefficients_
double getPhase(const std::vector< double > &coefficients) const
double getX(const int sysdeformation, const align::GlobalPoint &pos, const double phase) const

◆ makeLevelsFilenames()

const std::vector< std::pair< Alignable *, std::string > > PedeSteererWeakModeConstraints::makeLevelsFilenames ( std::set< std::string > &  steerFilePrefixContainer,
const align::Alignables alis,
const std::string &  steerFilePrefix 
) const
private

Definition at line 652 of file PedeSteererWeakModeConstraints.cc.

References alignableObjectId_, Exception, AlignableObjectId::idToString(), dqmiodumpmetadata::n, and steerFile_.

655  {
656  //check whether the prefix is unique
657  if (steerFilePrefixContainer.find(steerFilePrefix) != steerFilePrefixContainer.end()) {
658  throw cms::Exception("BadConfig") << "[PedeSteererWeakModeConstraints] Steering file"
659  << " prefix '" << steerFilePrefix << "' already exists. Specify unique names!";
660  } else {
661  steerFilePrefixContainer.insert(steerFilePrefix);
662  }
663 
664  std::vector<std::pair<Alignable*, std::string> > levelsFilenames;
665  for (const auto& ali : alis) {
666  std::stringstream n;
667  n << steerFile_ << "_" << steerFilePrefix //<< "_" << name
668  << "_" << alignableObjectId_.idToString(ali->alignableObjectId()) << "_" << ali->id() << "_"
669  << ali->alignableObjectId() << ".txt";
670 
671  levelsFilenames.push_back(std::make_pair(ali, n.str()));
672  }
673  return levelsFilenames;
674 }
const char * idToString(align::StructureType type) const

◆ verifyDeformationName()

int PedeSteererWeakModeConstraints::verifyDeformationName ( const std::string &  name,
const std::vector< double > &  coefficients 
) const
private

Definition at line 677 of file PedeSteererWeakModeConstraints.cc.

References Exception, ecaldqm::kUnknown, and Skims_PA_cff::name.

678  {
679  int sysdeformation = SystematicDeformations::kUnknown;
680 
681  if (name == "twist") {
682  sysdeformation = SystematicDeformations::kTwist;
683  } else if (name == "zexpansion") {
684  sysdeformation = SystematicDeformations::kZexpansion;
685  } else if (name == "sagitta") {
686  sysdeformation = SystematicDeformations::kSagitta;
687  } else if (name == "radial") {
688  sysdeformation = SystematicDeformations::kRadial;
689  } else if (name == "telescope") {
690  sysdeformation = SystematicDeformations::kTelescope;
691  } else if (name == "layerrotation") {
692  sysdeformation = SystematicDeformations::kLayerRotation;
693  } else if (name == "bowing") {
694  sysdeformation = SystematicDeformations::kBowing;
695  } else if (name == "skew") {
696  sysdeformation = SystematicDeformations::kSkew;
697  } else if (name == "elliptical") {
698  sysdeformation = SystematicDeformations::kElliptical;
699  }
700 
701  if (sysdeformation == SystematicDeformations::kUnknown) {
702  throw cms::Exception("BadConfig") << "[PedeSteererWeakModeConstraints]"
703  << " specified configuration option '" << name << "' not known.";
704  }
705  if ((sysdeformation == SystematicDeformations::kSagitta || sysdeformation == SystematicDeformations::kElliptical ||
706  sysdeformation == SystematicDeformations::kSkew) &&
707  coefficients.size() != 2) {
708  throw cms::Exception("BadConfig") << "[PedeSteererWeakModeConstraints]"
709  << " Excactly two parameters using the coefficient"
710  << " variable have to be provided for the " << name << " constraint.";
711  }
712  if ((sysdeformation == SystematicDeformations::kTwist || sysdeformation == SystematicDeformations::kZexpansion ||
713  sysdeformation == SystematicDeformations::kTelescope ||
714  sysdeformation == SystematicDeformations::kLayerRotation || sysdeformation == SystematicDeformations::kRadial ||
715  sysdeformation == SystematicDeformations::kBowing) &&
716  coefficients.size() != 1) {
717  throw cms::Exception("BadConfig") << "[PedeSteererWeakModeConstraints]"
718  << " Excactly ONE parameter using the coefficient"
719  << " variable have to be provided for the " << name << " constraint.";
720  }
721 
722  if (coefficients.empty()) {
723  throw cms::Exception("BadConfig") << "[PedeSteererWeakModeConstraints]"
724  << " At least one coefficient has to be specified.";
725  }
726  return sysdeformation;
727 }

◆ verifyParameterNames()

void PedeSteererWeakModeConstraints::verifyParameterNames ( const edm::ParameterSet pset,
unsigned int  psetnr 
) const
private

Definition at line 639 of file PedeSteererWeakModeConstraints.cc.

References Exception, Skims_PA_cff::name, and muonDTDigis_cfi::pset.

639  {
640  const auto parameterNames = pset.getParameterNames();
641  for (const auto& name : parameterNames) {
642  if (name != "coefficients" && name != "deadmodules" && name != "constraint" && name != "steerFilePrefix" &&
643  name != "levels" && name != "excludedAlignables" && name != "ignoredInstances" && name != "downToLowestLevel") {
644  throw cms::Exception("BadConfig") << "@SUB=PedeSteererWeakModeConstraints::verifyParameterNames:"
645  << " Unknown parameter name '" << name << "' in PSet number " << psetnr
646  << ". Maybe a typo?";
647  }
648  }
649 }

◆ writeOutput()

void PedeSteererWeakModeConstraints::writeOutput ( const std::list< std::pair< unsigned int, double > > &  output,
const GeometryConstraintConfigData it,
const Alignable iHLS,
double  sum_xi_x0 
)
private

Definition at line 422 of file PedeSteererWeakModeConstraints.cc.

References GeometryConstraintConfigData::coefficients_, Exception, alignBH_cfg::fixed, getFile(), and convertSQLitetoXML_cfg::output.

Referenced by constructConstraints().

425  {
426  std::ofstream* ofile = getFile(it, iHLS);
427 
428  if (ofile == nullptr) {
429  throw cms::Exception("FileFindError") << "[PedeSteererWeakModeConstraints] Cannot find output file.";
430  } else {
431  if (!output.empty()) {
432  const double constr = sum_xi_x0 * it.coefficients_.front();
433  (*ofile) << "Constraint " << std::scientific << constr << std::endl;
434  for (const auto& ioutput : output) {
435  (*ofile) << std::fixed << ioutput.first << " " << std::scientific << ioutput.second << std::endl;
436  }
437  }
438  }
439 }
std::ofstream * getFile(const GeometryConstraintConfigData &it, const Alignable *iHLS) const
const std::vector< double > coefficients_

Member Data Documentation

◆ alignableObjectId_

const AlignableObjectId PedeSteererWeakModeConstraints::alignableObjectId_
private

◆ ConstraintsConfigContainer_

std::list<GeometryConstraintConfigData> PedeSteererWeakModeConstraints::ConstraintsConfigContainer_
private

◆ deadmodules_

std::list<align::ID> PedeSteererWeakModeConstraints::deadmodules_
private

Definition at line 128 of file PedeSteererWeakModeConstraints.h.

Referenced by createAlignablesDataStructure().

◆ myConfig_

const std::vector<edm::ParameterSet> PedeSteererWeakModeConstraints::myConfig_
private

Definition at line 135 of file PedeSteererWeakModeConstraints.h.

◆ myLabels_

const PedeLabelerBase* PedeSteererWeakModeConstraints::myLabels_
private

Definition at line 133 of file PedeSteererWeakModeConstraints.h.

Referenced by constructConstraints().

◆ steerFile_

const std::string PedeSteererWeakModeConstraints::steerFile_
private

Definition at line 137 of file PedeSteererWeakModeConstraints.h.

Referenced by makeLevelsFilenames().