CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 std::vector< Alignable * > &alis)
 
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::GlobalPoint
getDoubleSensorPosition (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 std::vector< Alignable * > &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

std::list
< GeometryConstraintConfigData
ConstraintsConfigContainer_
 
std::list< align::IDdeadmodules_
 
const std::vector
< edm::ParameterSet
myConfig_
 
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 55 of file PedeSteererWeakModeConstraints.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

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

Definition at line 76 of file PedeSteererWeakModeConstraints.cc.

References AlignmentParameterSelector::addSelections(), AlignmentParameterSelector::clear(), ConstraintsConfigContainer_, deadmodules_, symbols::dm, spr::find(), instance, makeLevelsFilenames(), PedeLabelerBase::maxNumberOfParameterInstances(), myConfig_, myLabels_, mergeVDriftHistosByStation::name, TrackValidation_cff::pset, AlignmentParameterSelector::selectedAlignables(), AlCaHLTBitMon_QueryRunRegistry::string, create_public_lumi_plots::transform, verifyDeformationName(), and verifyParameterNames().

80  :
81  myLabels_(labels),
83  steerFile_(sf)
84 {
85  unsigned int psetnr = 0;
86  std::set<std::string> steerFilePrefixContainer;
87  for(const auto& pset: myConfig_) {
88  this->verifyParameterNames(pset, psetnr);
89  psetnr++;
90 
91  const auto coefficients = pset.getParameter<std::vector<double> > ("coefficients");
92  const auto dm = pset.exists("deadmodules") ?
93  pset.getParameter<std::vector<unsigned int> >("deadmodules") : std::vector<unsigned int>();
94  std::string name = pset.getParameter<std::string> ("constraint");
95  std::transform(name.begin(), name.end(), name.begin(), ::tolower);
96  const auto ignoredInstances = pset.exists("ignoredInstances") ?
97  pset.getUntrackedParameter<std::vector<unsigned int> >("ignoredInstances"):
98  std::vector<unsigned int>();
99 
100  const auto downToLowestLevel = pset.exists("downToLowestLevel") ?
101  pset.getUntrackedParameter<bool>("downToLowestLevel"): false;
102 
103  AlignmentParameterSelector selector(aliTracker, nullptr, nullptr);
104  selector.clear();
105  selector.addSelections(pset.getParameter<edm::ParameterSet> ("levels"));
106 
107  const auto& alis = selector.selectedAlignables();
108 
109  AlignmentParameterSelector selector_excludedalignables(aliTracker, nullptr, nullptr);
110  selector_excludedalignables.clear();
111  if(pset.exists("excludedAlignables")) {
112  selector_excludedalignables.addSelections(pset.getParameter<edm::ParameterSet> ("excludedAlignables"));
113  }
114  const auto& excluded_alis = selector_excludedalignables.selectedAlignables();
115 
116  //check that the name of the deformation is known and that the number
117  //of provided parameter is right.
118  auto sysdeformation = this->verifyDeformationName(name,coefficients);
119 
120  if(deadmodules_.size() == 0) { //fill the list of dead modules only once
121  edm::LogInfo("Alignment") << "@SUB=PedeSteererWeakModeConstraints"
122  << "Load list of dead modules (size = " << dm.size()<< ").";
123  for(const auto& it: dm) deadmodules_.push_back(it);
124  }
125 
126  // loop over all IOVs/momentum ranges
127  for (unsigned int instance = 0;
129  ++instance) {
130  // check if this IOV/momentum range is to be ignored:
131  if (std::find(ignoredInstances.begin(), ignoredInstances.end(), instance)
132  != ignoredInstances.end()) {
133  continue;
134  }
135  std::stringstream defaultsteerfileprefix;
136  defaultsteerfileprefix << "autosteerFilePrefix_" << name << "_" << psetnr
137  << "_" << instance;
138 
139  const auto steerFilePrefix = pset.exists("steerFilePrefix") ?
140  pset.getParameter<std::string> ("steerFilePrefix") + "_" + std::to_string(instance) :
141  defaultsteerfileprefix.str();
142 
143  const auto levelsFilenames = this->makeLevelsFilenames(steerFilePrefixContainer,
144  alis,
145  steerFilePrefix);
146 
147  //Add the configuration data for this constraint to the container of config data
148  ConstraintsConfigContainer_.emplace_back
149  (GeometryConstraintConfigData(coefficients,
150  name,
151  levelsFilenames,
152  sysdeformation,
153  excluded_alis,
154  instance,
155  downToLowestLevel));
156  }
157 
158  }
159 }
void verifyParameterNames(const edm::ParameterSet &pset, unsigned int psetnr) const
static PFTauRenderPlugin instance
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
const std::vector< std::pair< Alignable *, std::string > > makeLevelsFilenames(std::set< std::string > &steerFilePrefixContainer, const std::vector< Alignable * > &alis, const std::string &steerFilePrefix) const
tuple dm
Definition: symbols.py:65
int verifyDeformationName(const std::string &name, const std::vector< double > &coefficients) const
const std::vector< edm::ParameterSet > myConfig_
virtual unsigned int maxNumberOfParameterInstances() const =0
returns the maximum number of instances for any parameter of an Alignable*
std::list< GeometryConstraintConfigData > ConstraintsConfigContainer_

Member Function Documentation

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

Definition at line 697 of file PedeSteererWeakModeConstraints.cc.

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

Referenced by createAlignablesDataStructure().

699 {
700  if(lowleveldet->id() == HLS->id() && lowleveldet->alignableObjectId() == HLS->alignableObjectId()) {
701  return true;
702  } else {
703  if(lowleveldet->mother() == nullptr)
704  return false;
705  else
706  return this->checkMother(lowleveldet->mother(),HLS);
707  }
708 }
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:185
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
bool checkMother(const Alignable *const lowleveldet, const Alignable *const HLS) const
Alignable * mother() const
Return pointer to container alignable (if any)
Definition: Alignable.h:90
bool PedeSteererWeakModeConstraints::checkSelectionShiftParameter ( const Alignable ali,
unsigned int  iParameter 
) const
private

Definition at line 412 of file PedeSteererWeakModeConstraints.cc.

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

Referenced by constructConstraints(), and getX0().

414 {
415  bool isselected = false;
416  const std::vector<bool> &aliSel= ali->alignmentParameters()->selector();
417  //exclude non-shift parameters
418  if((iParameter <= 2)
419  || (iParameter >= 9 && iParameter <=11)) {
420  if(!aliSel.at(iParameter)) {
421  isselected = false;
422  } else {
423  auto params = ali->alignmentParameters();
424  auto selVar = dynamic_cast<SelectionUserVariables*>(params->userVariables());
425  if (selVar) {
426  if(selVar->fullSelection().size() <= (iParameter+1)) {
427  throw cms::Exception("Alignment")
428  << "[PedeSteererWeakModeConstraints::checkSelectionShiftParameter]"
429  << " Can not access selected alignment variables of alignable "
431  << "at (" << ali->globalPosition().x() << ","<< ali->globalPosition().y() << "," << ali->globalPosition().z()<< ") "
432  << "for parameter number " << (iParameter+1) << ".";
433  }
434  }
435  const char selChar = (selVar ? selVar->fullSelection().at(iParameter) : '1');
436  // if(selChar == '1') { //FIXME??? what about 'r'?
437  if(selChar == '1' || selChar == 'r') {
438  isselected = true;
439  } else {
440  isselected = false;
441  }
442  }
443  }
444  return isselected;
445 }
T y() const
Definition: PV3DBase.h:63
const std::vector< bool > & selector(void) const
Get alignment parameter selector vector.
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:57
T z() const
Definition: PV3DBase.h:64
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:134
static const char * idToString(align::StructureType type)
T x() const
Definition: PV3DBase.h:62
void PedeSteererWeakModeConstraints::closeOutputfiles ( )
private

Definition at line 449 of file PedeSteererWeakModeConstraints.cc.

References ConstraintsConfigContainer_, and Exception.

Referenced by constructConstraints().

450 {
451  //'delete' output files which means: close them
452  for(auto& it: ConstraintsConfigContainer_) {
453  for(auto& iFile:it.mapFileName_) {
454  if(iFile.second) {
455  delete iFile.second;
456  iFile.second = nullptr;
457  } else {
458  throw cms::Exception("FileCloseProblem")
459  << "[PedeSteererWeakModeConstraints]" << " can not close file " << iFile.first << ".";
460  }
461  }
462  }
463 }
std::list< GeometryConstraintConfigData > ConstraintsConfigContainer_
unsigned int PedeSteererWeakModeConstraints::constructConstraints ( const std::vector< Alignable * > &  alis)

Definition at line 567 of file PedeSteererWeakModeConstraints.cc.

References Abs(), PedeLabelerBase::alignableLabelFromParamAndInstance(), Alignable::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_, GetRecoTauVFromDQM_MC_cff::outFile, convertSQLitetoXML_cfg::output, PedeLabelerBase::parameterLabel(), 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().

568 {
569  //FIXME: split the code of the method into smaller pieces/submethods
570 
571  //create the data structures that store the alignables
572  //for which the constraints need to be calculated and
573  //their association to high-level structures
574  const auto nConstraints = this->createAlignablesDataStructure();
575 
576  std::vector<std::list<std::pair<unsigned int,double> > > createdConstraints;
577 
578  //calculate constraints
579  //loop over all constraints
580  for(const auto& it: ConstraintsConfigContainer_) {
581 
582  //loop over all subdets for which constraints are determined
583  for(const auto& iHLS : it.HLSsubdets_) {
584  double sum_xi_x0 = 0.0;
585  std::list<std::pair<unsigned int,double> > output;
586 
587  const double x0 = this->getX0(iHLS, it);
588 
589  for(std::list<Alignable*>::const_iterator iAlignables = iHLS.second.begin();
590  iAlignables != iHLS.second.end(); iAlignables++) {
591  const Alignable *ali = (*iAlignables);
592  const auto aliLabel = myLabels_->alignableLabelFromParamAndInstance(const_cast<Alignable*>(ali), 0, it.instance_);
593  const AlignableSurface &surface = ali->surface();
594 
595  const LocalPoint lUDirection(1.,0.,0.),
596  lVDirection(0.,1.,0.),
597  lWDirection(0.,0.,1.);
598 
599  GlobalPoint gUDirection = surface.toGlobal(lUDirection),
600  gVDirection = surface.toGlobal(lVDirection),
601  gWDirection = surface.toGlobal(lWDirection);
602 
603  const bool isDoubleSensor = ali->alignmentParameters()->type() == AlignmentParametersFactory::kTwoBowedSurfaces;
604 
605  const auto sensorpositions =
606  isDoubleSensor ? this->getDoubleSensorPosition(ali) : std::make_pair(ali->globalPosition(), align::PositionType ());
607 
608  const auto& pos_sensor0 = sensorpositions.first;
609  const auto& pos_sensor1 = sensorpositions.second;
610  const auto phase = this->getPhase(it.coefficients_);
611  const auto x_sensor0 = this->getX(it.sysdeformation_,pos_sensor0,phase);
612  const auto x_sensor1 = isDoubleSensor ? this->getX(it.sysdeformation_,pos_sensor1,phase) : 0.0;
613 
614  sum_xi_x0 += ( x_sensor0 - x0 ) * ( x_sensor0 - x0 );
615  if(isDoubleSensor) {
616  sum_xi_x0 += ( x_sensor1 - x0 ) * ( x_sensor1 - x0 );
617  }
618  const int numparameterlimit = ali->alignmentParameters()->size(); //isDoubleSensor ? 18 : 3;
619 
620  for(int iParameter = 0; iParameter < numparameterlimit; iParameter++) {
621  int localindex = 0;
622  if(iParameter == 0 || iParameter == 9)
623  localindex = 0;
624  if(iParameter == 1 || iParameter == 10)
625  localindex = 1;
626  if(iParameter == 2 || iParameter == 11)
627  localindex = 2;
628 
629  if((iParameter >= 0 && iParameter <= 2)
630  || (iParameter >= 9 && iParameter <=11)) {
631  } else {
632  continue;
633  }
634  if(! this->checkSelectionShiftParameter(ali,iParameter) ) {
635  continue;
636  }
637  //do it for each 'instance' separately? -> IOV-dependence, no
638  const auto paramLabel = myLabels_->parameterLabel(aliLabel, iParameter);
639 
640  const auto& pos = (iParameter <= 2) ? pos_sensor0 : pos_sensor1;
641  //select only u,v,w
642  if(iParameter == 0 || iParameter == 1 || iParameter == 2
643  || iParameter == 9 || iParameter == 10 || iParameter == 11) {
644  const double coeff = this->getCoefficient(it.sysdeformation_,
645  pos,
646  gUDirection,
647  gVDirection,
648  gWDirection,
649  localindex,
650  x0,
651  it.coefficients_);
652  if(TMath::Abs(coeff) > 0.0) {
653  //nothing
654  } else {
655  edm::LogWarning("PedeSteererWeakModeConstraints")
656  << "@SUB=PedeSteererWeakModeConstraints::getCoefficient"
657  << "Coefficient of alignable "
659  << " at (" << ali->globalPosition().x() << ","<< ali->globalPosition().y() << "," << ali->globalPosition().z()<< ") "
660  << " in subdet " << AlignableObjectId::idToString(iHLS.first->alignableObjectId())
661  << " for parameter " << localindex << " equal to zero. This alignable is used in the constraint"
662  << " '" << it.constraintName_ << "'. The id is: alignable->geomDetId().rawId() = "
663  << ali->geomDetId().rawId() << ".";
664  }
665  output.push_back(std::make_pair (paramLabel, coeff));
666  }
667  }
668 
669 
670  }
671 
672  if (std::find(createdConstraints.begin(), createdConstraints.end(), output)
673  != createdConstraints.end()) {
674  // check if linearly dependent constraint exists already:
675  auto outFile = getFile(it, iHLS.first);
676  if (outFile == nullptr) {
677  throw cms::Exception("FileFindError")
678  << "[PedeSteererWeakModeConstraints] Cannot find output file.";
679  } else {
680  *outFile << "! The constraint for this IOV/momentum range" << std::endl
681  << "! has been removed because the used parameters" << std::endl
682  << "! are not IOV or momentum-range dependent." << std::endl;
683  }
684  continue;
685  }
686  this->writeOutput(output, it, iHLS.first, sum_xi_x0);
687  createdConstraints.push_back(output);
688  }
689  }
690  this->closeOutputfiles();
691 
692  return nConstraints;
693 }
bool checkSelectionShiftParameter(const Alignable *ali, unsigned int iParameter) const
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
void writeOutput(const std::list< std::pair< unsigned int, double > > &output, const GeometryConstraintConfigData &it, const Alignable *iHLS, double sum_xi_x0)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:57
virtual unsigned int parameterLabel(unsigned int aliLabel, unsigned int parNum) const =0
returns the label for a given alignable parameter number combination
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
Point3DBase< Scalar, GlobalTag > PositionType
Definition: Definitions.h:30
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
T Abs(T a)
Definition: MathUtil.h:49
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
virtual unsigned int alignableLabelFromParamAndInstance(Alignable *alignable, unsigned int param, unsigned int instance) const =0
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:131
virtual int type() const =0
tell type (AlignmentParametersFactory::ParametersType - but no circular dependency) ...
int size(void) const
Get number of parameters.
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.
double getCoefficient(const int sysdeformation, const align::GlobalPoint &pos, const GlobalPoint gUDirection, const GlobalPoint gVDirection, const GlobalPoint gWDirection, const int iParameter, const double &x0, const std::vector< double > &constraintparameters) const
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:134
static const char * idToString(align::StructureType type)
T x() const
Definition: PV3DBase.h:62
const DetId & geomDetId() const
Definition: Alignable.h:182
std::list< GeometryConstraintConfigData > ConstraintsConfigContainer_
unsigned int PedeSteererWeakModeConstraints::createAlignablesDataStructure ( )
private

Definition at line 185 of file PedeSteererWeakModeConstraints.cc.

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

Referenced by constructConstraints().

186 {
187  unsigned int nConstraints = 0;
188  for(auto& iC: ConstraintsConfigContainer_) {
189  //loop over all HLS for which the constraint is to be determined
190  for(const auto& iHLS: iC.levelsFilenames_) {
191  //determine next active sub-alignables for iHLS
192  std::vector<Alignable*> aliDaughts;
193  if (iC.downToLowestLevel_) {
194  if (!iHLS.first->lastCompsWithParams(aliDaughts)) {
195  edm::LogWarning("Alignment")
196  << "@SUB=PedeSteererWeakModeConstraints::createAlignablesDataStructure"
197  << "Some but not all component branches "
198  << AlignableObjectId::idToString(iHLS.first->alignableObjectId())
199  << " with params!";
200  }
201  } else {
202  if (!iHLS.first->firstCompsWithParams(aliDaughts)) {
203  edm::LogWarning("Alignment")
204  << "@SUB=PedeSteererWeakModeConstraints::createAlignablesDataStructure"
205  << "Some but not all daughters of "
206  << AlignableObjectId::idToString(iHLS.first->alignableObjectId())
207  << " with params!";
208  }
209  }
210  ++nConstraints;
211 
212  std::list<Alignable*> usedinconstraint;
213  for (const auto& iD: aliDaughts) {
214  bool isNOTdead = true;
215  for(const auto& iDeadmodules: deadmodules_) {
216  if( (iD->alignableObjectId() == align::AlignableDetUnit
217  || iD->alignableObjectId() == align::AlignableDet)
218  && iD->geomDetId().rawId() == iDeadmodules) {
219  isNOTdead = false;
220  break;
221  }
222  }
223  //check if the module is excluded
224  for(const auto& iEx: iC.excludedAlignables_) {
225  if(iD->id() == iEx->id() && iD->alignableObjectId() == iEx->alignableObjectId() ) {
226  //if(iD->geomDetId().rawId() == (*iEx)->geomDetId().rawId()) {
227  isNOTdead = false;
228  break;
229  }
230  }
231  const bool issubcomponent = this->checkMother(iD,iHLS.first);
232  if(issubcomponent) {
233  if(isNOTdead) {
234  usedinconstraint.push_back(iD);
235  }
236  } else {
237  //sanity check
238  throw cms::Exception("Alignment")
239  << "[PedeSteererWeakModeConstraints::createAlignablesDataStructure]"
240  << " Sanity check failed. Alignable defined as active sub-component, "
241  << " but in fact its not a daugther of " << AlignableObjectId::idToString(iHLS.first->alignableObjectId());
242  }
243  }
244 
245  if( usedinconstraint.size() > 0){
246  iC.HLSsubdets_.push_back(std::make_pair(iHLS.first, usedinconstraint));
247  } else {
248  edm::LogInfo("Alignment") << "@SUB=PedeSteererWeakModeConstraints"
249  << "No sub-components for "
250  << AlignableObjectId::idToString(iHLS.first->alignableObjectId())
251  << " at (" << iHLS.first->globalPosition().x()
252  << ","<< iHLS.first->globalPosition().y()
253  << "," << iHLS.first->globalPosition().z()
254  << ") selected. Skip constraint";
255  }
256  if(aliDaughts.size() == 0) {
257  edm::LogWarning("Alignment") << "@SUB=PedeSteererWeakModeConstraints::createAlignablesDataStructure"
258  << "No active sub-alignables found for "
259  << AlignableObjectId::idToString(iHLS.first->alignableObjectId())
260  << " at (" << iHLS.first->globalPosition().x() << ","<< iHLS.first->globalPosition().y() << "," << iHLS.first->globalPosition().z() << ").";
261  }
262 
263 
264  }
265  }
266  return nConstraints;
267 }
bool checkMother(const Alignable *const lowleveldet, const Alignable *const HLS) const
static const char * idToString(align::StructureType type)
std::list< GeometryConstraintConfigData > ConstraintsConfigContainer_
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 306 of file PedeSteererWeakModeConstraints.cc.

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

Referenced by constructConstraints().

313 {
314 
315 
316  if(iParameter < 0 || iParameter > 2) {
317  throw cms::Exception("Alignment")
318  << "[PedeSteererWeakModeConstraints::getCoefficient]" << " iParameter has to be in the range [0,2] but"
319  << " it is equal to " << iParameter << ".";
320  }
321 
322 
323  //global vectors pointing in u,v,w direction
324  const std::vector<double> vec_u = {pos.x() - gUDirection.x(), pos.y() - gUDirection.y(), pos.z() - gUDirection.z()};
325  const std::vector<double> vec_v = {pos.x() - gVDirection.x(), pos.y() - gVDirection.y(), pos.z() - gVDirection.z()};
326  const std::vector<double> vec_w = {pos.x() - gWDirection.x(), pos.y() - gWDirection.y(), pos.z() - gWDirection.z()};
327 
328  //FIXME: how to make inner vectors const?
329  const std::vector<std::vector<double> > global_vecs = {vec_u, vec_v, vec_w};
330 
331  const double n = TMath::Sqrt( global_vecs.at(iParameter).at(0) * global_vecs.at(iParameter).at(0)
332  + global_vecs.at(iParameter).at(1) * global_vecs.at(iParameter).at(1)
333  + global_vecs.at(iParameter).at(2) * global_vecs.at(iParameter).at(2) );
334  const double r = TMath::Sqrt( pos.x() * pos.x() + pos.y() * pos.y() );
335 
336  const double phase = this->getPhase(constraintparameters);
337  //const double radial_direction[3] = {TMath::Sin(phase), TMath::Cos(phase), 0.0};
338  const std::vector<double> radial_direction = {TMath::Sin(phase), TMath::Cos(phase), 0.0};
339  //is equal to unity by construction ...
340  const double norm_radial_direction = TMath::Sqrt(radial_direction.at(0) * radial_direction.at(0)
341  + radial_direction.at(1) * radial_direction.at(1)
342  + radial_direction.at(2) * radial_direction.at(2));
343 
344  //const double phi_direction[3] = { -1.0 * pos.y(), pos.x(), 0.0};
345  const std::vector<double> phi_direction = {-1.0 * pos.y(), pos.x(), 0.0};
346  const double norm_phi_direction = TMath::Sqrt(phi_direction.at(0) * phi_direction.at(0)
347  + phi_direction.at(1) * phi_direction.at(1)
348  + phi_direction.at(2) * phi_direction.at(2));
349 
350  //const double z_direction[3] = {0.0, 0.0, 1.0};
351  static const std::vector<double> z_direction = {0.0, 0.0, 1.0};
352  const double norm_z_direction = TMath::Sqrt(z_direction.at(0)*z_direction.at(0)
353  + z_direction.at(1)*z_direction.at(1)
354  + z_direction.at(2)*z_direction.at(2));
355 
356  //unit vector pointing from the origin to the module position in the transverse plane
357  const std::vector<double> rDirection = {pos.x(), pos.y(), 0.0};
358  const double norm_rDirection = TMath::Sqrt(rDirection.at(0) * rDirection.at(0)
359  + rDirection.at(1) * rDirection.at(1)
360  + rDirection.at(2) * rDirection.at(2));
361 
362  double coeff = 0.0;
363  double dot_product = 0.0;
364  double normalisation_factor = 1.0;
365 
366  //see https://indico.cern.ch/getFile.py/access?contribId=15&sessionId=1&resId=0&materialId=slides&confId=127126
367  switch(sysdeformation) {
368  case SystematicDeformations::kTwist:
369  case SystematicDeformations::kLayerRotation:
370  dot_product = phi_direction.at(0) * global_vecs.at(iParameter).at(0)
371  + phi_direction.at(1) * global_vecs.at(iParameter).at(1)
372  + phi_direction.at(2) * global_vecs.at(iParameter).at(2);
373  normalisation_factor = r * n * norm_phi_direction;
374  break;
375  case SystematicDeformations::kZexpansion :
376  case SystematicDeformations::kTelescope:
377  case SystematicDeformations::kSkew:
378  dot_product = global_vecs.at(iParameter).at(0) * z_direction.at(0)
379  + global_vecs.at(iParameter).at(1) * z_direction.at(1)
380  + global_vecs.at(iParameter).at(2) * z_direction.at(2);
381  normalisation_factor = ( n * norm_z_direction);
382  break;
383  case SystematicDeformations::kRadial:
384  case SystematicDeformations::kBowing:
385  case SystematicDeformations::kElliptical:
386  dot_product = global_vecs.at(iParameter).at(0) * rDirection.at(0)
387  + global_vecs.at(iParameter).at(1) * rDirection.at(1)
388  + global_vecs.at(iParameter).at(2) * rDirection.at(2);
389  normalisation_factor = ( n * norm_rDirection);
390  break;
391  case SystematicDeformations::kSagitta:
392  dot_product = global_vecs.at(iParameter).at(0) * radial_direction.at(0)
393  + global_vecs.at(iParameter).at(1) * radial_direction.at(1)
394  + global_vecs.at(iParameter).at(2) * radial_direction.at(2);
395  normalisation_factor = ( n * norm_radial_direction);
396  break;
397  default: break;
398  }
399 
400  if(TMath::Abs(normalisation_factor) > 0.0) {
401  coeff = dot_product * ( this->getX(sysdeformation,pos,phase) - x0 ) / normalisation_factor;
402  } else {
403  throw cms::Exception("Alignment")
404  << "[PedeSteererWeakModeConstraints::getCoefficient]" << " Normalisation factor"
405  << "for coefficient calculation equal to zero! Misconfiguration?";
406  }
407  return coeff;
408 }
T y() const
Definition: PV3DBase.h:63
double getX(const int sysdeformation, const align::GlobalPoint &pos, const double phase) const
T z() const
Definition: PV3DBase.h:64
T Abs(T a)
Definition: MathUtil.h:49
double getPhase(const std::vector< double > &coefficients) const
T x() const
Definition: PV3DBase.h:62
std::list<GeometryConstraintConfigData>& PedeSteererWeakModeConstraints::getConfigData ( )
inline

Definition at line 69 of file PedeSteererWeakModeConstraints.h.

References ConstraintsConfigContainer_.

Referenced by PedeSteerer::buildSubSteer().

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

Definition at line 163 of file PedeSteererWeakModeConstraints.cc.

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

Referenced by constructConstraints(), and getX0().

164 {
165  const auto aliPar =
167  if(aliPar) {
168  const auto ySplit = aliPar->ySplit();
169  const auto halfLength = 0.5 * ali->surface().length();
170  const auto yM1 = 0.5 * (ySplit - halfLength); // y_mean of surface 1
171  const auto yM2 = yM1 + halfLength; // y_mean of surface 2
172  const auto pos_sensor0(ali->surface().toGlobal(align::LocalPoint(0.,yM1,0.)));
173  const auto pos_sensor1(ali->surface().toGlobal(align::LocalPoint(0.,yM2,0.)));
174  return std::make_pair(pos_sensor0, pos_sensor1);
175  } else {
176  throw cms::Exception("Alignment")
177  << "[PedeSteererWeakModeConstraints::getDoubleSensorPosition]"
178  << " Dynamic cast to double sensor parameters failed.";
179  return std::make_pair( align::GlobalPoint(0.0, 0.0, 0.0), align::GlobalPoint(0.0, 0.0, 0.0));
180  }
181 }
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:57
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:131
align::Scalar length() const
align::GlobalPoints toGlobal(const align::LocalPoints &) const
Return in global coord given a set of local points.
std::ofstream * PedeSteererWeakModeConstraints::getFile ( const GeometryConstraintConfigData it,
const Alignable iHLS 
) const
private

Definition at line 490 of file PedeSteererWeakModeConstraints.cc.

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

Referenced by constructConstraints(), and writeOutput().

492 {
493  std::ofstream* file = nullptr;
494 
495  for(const auto& ilevelsFilename: it.levelsFilenames_) {
496  if(ilevelsFilename.first->id() == iHLS->id() &&
497  ilevelsFilename.first->alignableObjectId() == iHLS->alignableObjectId()) {
498 
499  const auto iFile = it.mapFileName_.find(ilevelsFilename.second);
500  if(iFile != it.mapFileName_.end()) {
501  file = iFile->second;
502  }
503  }
504  }
505 
506  return file;
507 }
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:185
std::map< std::string, std::ofstream * > mapFileName_
const std::vector< std::pair< Alignable *, std::string > > levelsFilenames_
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
double PedeSteererWeakModeConstraints::getPhase ( const std::vector< double > &  coefficients) const
private

Definition at line 816 of file PedeSteererWeakModeConstraints.cc.

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

817 {
818  return coefficients.size() == 2 ? coefficients.at(1) : 0.0; //treat second parameter as phase otherwise return 0
819 }
double PedeSteererWeakModeConstraints::getX ( const int  sysdeformation,
const align::GlobalPoint pos,
const double  phase 
) const
private

Definition at line 271 of file PedeSteererWeakModeConstraints.cc.

References PV3DBase< T, PVType, FrameType >::phi(), alignCSCRings::r, x, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

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

274 {
275  double x = 0.0;
276 
277  const double r = TMath::Sqrt(pos.x() * pos.x() + pos.y() * pos.y());
278 
279  switch(sysdeformation) {
280  case SystematicDeformations::kTwist:
281  case SystematicDeformations::kZexpansion:
282  x = pos.z();
283  break;
284  case SystematicDeformations::kSagitta:
285  case SystematicDeformations::kRadial:
286  case SystematicDeformations::kTelescope:
287  case SystematicDeformations::kLayerRotation:
288  x = r;
289  break;
290  case SystematicDeformations::kBowing:
291  x = pos.z() * pos.z(); //TMath::Abs(pos.z());
292  break;
293  case SystematicDeformations::kElliptical:
294  x = r * TMath::Cos(2.0 * pos.phi() + phase);
295  break;
296  case SystematicDeformations::kSkew:
297  x = TMath::Cos(pos.phi() + phase);
298  break;
299  };
300 
301  return x;
302 }
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
T y() const
Definition: PV3DBase.h:63
T z() const
Definition: PV3DBase.h:64
T x() const
Definition: PV3DBase.h:62
double PedeSteererWeakModeConstraints::getX0 ( const std::pair< Alignable *, std::list< Alignable * > > &  iHLS,
const GeometryConstraintConfigData it 
) const
private

Definition at line 511 of file PedeSteererWeakModeConstraints.cc.

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

Referenced by constructConstraints().

513 {
514  double nmodules = 0.0;
515  double x0 = 0.0;
516 
517  for(const auto& ali: iHLS.second) {
518  align::PositionType pos = ali->globalPosition();
519  bool alignableIsFloating = false; //means: true=alignable is able to move in at least one direction
520 
521  //test whether at least one variable has been selected in the configuration
522  for(unsigned int iParameter = 0;
523  static_cast<int>(iParameter) < ali->alignmentParameters()->size(); iParameter++) {
524  if(this->checkSelectionShiftParameter(ali,iParameter) ) {
525  alignableIsFloating = true;
526  // //verify that alignable has just one label -- meaning no IOV-dependence etc
527  // const unsigned int nInstances = myLabels_->numberOfParameterInstances(ali, iParameter);
528  // if(nInstances > 1) {
529  // throw cms::Exception("PedeSteererWeakModeConstraints")
530  // << "@SUB=PedeSteererWeakModeConstraints::ConstructConstraints"
531  // << " Weak mode constraints are only supported for alignables which have"
532  // << " just one label. However, e.g. alignable"
533  // << " " << AlignableObjectId::idToString(ali->alignableObjectId())
534  // << "at (" << ali->globalPosition().x() << ","<< ali->globalPosition().y() << "," << ali->globalPosition().z()<< "), "
535  // << " was configured to have >1 label. Remove e.g. IOV-dependence for this (and other) alignables which are used in the constraint.";
536  // }
537  break;
538  }
539  }
540  //at least one parameter of the alignable can be changed in the alignment
541  if(alignableIsFloating) {
542  const auto phase = this->getPhase(it.coefficients_);
543  if(ali->alignmentParameters()->type() != AlignmentParametersFactory::kTwoBowedSurfaces ) {
544  x0 += this->getX(it.sysdeformation_,pos,phase);
545  nmodules++;
546  } else {
547  std::pair<align::GlobalPoint, align::GlobalPoint> sensorpositions = this->getDoubleSensorPosition(ali);
548  x0 += this->getX(it.sysdeformation_,sensorpositions.first,phase) + this->getX(it.sysdeformation_,sensorpositions.second,phase);
549  nmodules++;
550  nmodules++;
551  }
552  }
553  }
554  if(nmodules>0) {
555  x0 = x0 / nmodules;
556  } else {
557  throw cms::Exception("Alignment")
558  << "@SUB=PedeSteererWeakModeConstraints::ConstructConstraints"
559  << " Number of selected modules equal to zero. Check configuration!";
560  x0 = 1.0;
561  }
562  return x0;
563 }
bool checkSelectionShiftParameter(const Alignable *ali, unsigned int iParameter) const
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< double > coefficients_
double getPhase(const std::vector< double > &coefficients) const
const std::vector< std::pair< Alignable *, std::string > > PedeSteererWeakModeConstraints::makeLevelsFilenames ( std::set< std::string > &  steerFilePrefixContainer,
const std::vector< Alignable * > &  alis,
const std::string &  steerFilePrefix 
) const
private

Definition at line 732 of file PedeSteererWeakModeConstraints.cc.

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

Referenced by PedeSteererWeakModeConstraints().

735 {
736  //check whether the prefix is unique
737  if(steerFilePrefixContainer.find(steerFilePrefix) != steerFilePrefixContainer.end()) {
738  throw cms::Exception("BadConfig") << "[PedeSteererWeakModeConstraints] Steering file"
739  << " prefix '" << steerFilePrefix << "' already exists. Specify unique names!";
740  } else {
741  steerFilePrefixContainer.insert(steerFilePrefix);
742  }
743 
744  std::vector<std::pair<Alignable*, std::string> > levelsFilenames;
745  for(const auto& ali: alis) {
746  std::stringstream n;
747  n << steerFile_ << "_" << steerFilePrefix //<< "_" << name
748  << "_" << AlignableObjectId::idToString(ali->alignableObjectId())
749  << "_" << ali->id() << "_" << ali->alignableObjectId() << ".txt";
750 
751  levelsFilenames.push_back(std::make_pair(ali, n.str()));
752  }
753  return levelsFilenames;
754 }
static const char * idToString(align::StructureType type)
int PedeSteererWeakModeConstraints::verifyDeformationName ( const std::string &  name,
const std::vector< double > &  coefficients 
) const
private

Definition at line 758 of file PedeSteererWeakModeConstraints.cc.

References Exception, and ecaldqm::kUnknown.

Referenced by PedeSteererWeakModeConstraints().

760 {
761  int sysdeformation = SystematicDeformations::kUnknown;
762 
763  if(name == "twist") {
764  sysdeformation = SystematicDeformations::kTwist;
765  } else if(name == "zexpansion") {
766  sysdeformation = SystematicDeformations::kZexpansion;
767  } else if(name == "sagitta") {
768  sysdeformation = SystematicDeformations::kSagitta;
769  } else if(name == "radial") {
770  sysdeformation = SystematicDeformations::kRadial;
771  } else if(name == "telescope") {
772  sysdeformation = SystematicDeformations::kTelescope;
773  } else if(name == "layerrotation") {
774  sysdeformation = SystematicDeformations::kLayerRotation;
775  } else if(name == "bowing") {
776  sysdeformation = SystematicDeformations::kBowing;
777  } else if(name == "skew") {
778  sysdeformation = SystematicDeformations::kSkew;
779  } else if(name == "elliptical") {
780  sysdeformation = SystematicDeformations::kElliptical;
781  }
782 
783  if(sysdeformation == SystematicDeformations::kUnknown) {
784  throw cms::Exception("BadConfig")
785  << "[PedeSteererWeakModeConstraints]" << " specified configuration option '"
786  << name << "' not known.";
787  }
788  if((sysdeformation == SystematicDeformations::kSagitta
789  || sysdeformation == SystematicDeformations::kElliptical
790  || sysdeformation == SystematicDeformations::kSkew) && coefficients.size() != 2) {
791  throw cms::Exception("BadConfig")
792  << "[PedeSteererWeakModeConstraints]" << " Excactly two parameters using the coefficient"
793  << " variable have to be provided for the " << name << " constraint.";
794  }
795  if((sysdeformation == SystematicDeformations::kTwist
796  || sysdeformation == SystematicDeformations::kZexpansion
797  || sysdeformation == SystematicDeformations::kTelescope
798  || sysdeformation == SystematicDeformations::kLayerRotation
799  || sysdeformation == SystematicDeformations::kRadial
800  || sysdeformation == SystematicDeformations::kBowing) && coefficients.size() != 1) {
801  throw cms::Exception("BadConfig")
802  << "[PedeSteererWeakModeConstraints]" << " Excactly ONE parameter using the coefficient"
803  << " variable have to be provided for the " << name << " constraint.";
804  }
805 
806  if(coefficients.size() == 0) {
807  throw cms::Exception("BadConfig")
808  << "[PedeSteererWeakModeConstraints]" << " At least one coefficient has to be specified.";
809  }
810  return sysdeformation;
811 }
void PedeSteererWeakModeConstraints::verifyParameterNames ( const edm::ParameterSet pset,
unsigned int  psetnr 
) const
private

Definition at line 712 of file PedeSteererWeakModeConstraints.cc.

References Exception, edm::ParameterSet::getParameterNames(), and mergeVDriftHistosByStation::name.

Referenced by PedeSteererWeakModeConstraints().

714 {
715  const auto parameterNames = pset.getParameterNames();
716  for (const auto& name: parameterNames) {
717  if(name != "coefficients"
718  && name != "deadmodules" && name != "constraint"
719  && name != "steerFilePrefix" && name != "levels"
720  && name != "excludedAlignables" && name != "ignoredInstances"
721  && name != "downToLowestLevel"
722  ) {
723  throw cms::Exception("BadConfig")
724  << "@SUB=PedeSteererWeakModeConstraints::verifyParameterNames:"
725  << " Unknown parameter name '" << name << "' in PSet number " << psetnr << ". Maybe a typo?";
726  }
727  }
728 }
std::vector< std::string > getParameterNames() const
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 467 of file PedeSteererWeakModeConstraints.cc.

References GeometryConstraintConfigData::coefficients_, Exception, getFile(), checklumidiff::ofile, and convertSQLitetoXML_cfg::output.

Referenced by constructConstraints().

471 {
472  std::ofstream* ofile = getFile(it, iHLS);
473 
474  if(ofile == nullptr) {
475  throw cms::Exception("FileFindError")
476  << "[PedeSteererWeakModeConstraints] Cannot find output file.";
477  } else {
478  if(output.size() > 0) {
479  const double constr = sum_xi_x0 * it.coefficients_.front();
480  (*ofile) << "Constraint " << std::scientific << constr << std::endl;
481  for(const auto& ioutput: output) {
482  (*ofile) << std::fixed << ioutput.first << " " << std::scientific << ioutput.second << std::endl;
483  }
484  }
485  }
486 }
std::ofstream * getFile(const GeometryConstraintConfigData &it, const Alignable *iHLS) const
const std::vector< double > coefficients_

Member Data Documentation

std::list<GeometryConstraintConfigData> PedeSteererWeakModeConstraints::ConstraintsConfigContainer_
private
std::list<align::ID> PedeSteererWeakModeConstraints::deadmodules_
private
const std::vector<edm::ParameterSet> PedeSteererWeakModeConstraints::myConfig_
private

Definition at line 133 of file PedeSteererWeakModeConstraints.h.

Referenced by PedeSteererWeakModeConstraints().

const PedeLabelerBase* PedeSteererWeakModeConstraints::myLabels_
private
const std::string PedeSteererWeakModeConstraints::steerFile_
private

Definition at line 135 of file PedeSteererWeakModeConstraints.h.

Referenced by makeLevelsFilenames().