52 const std::vector<double>&
co,
54 const std::vector<std::pair<Alignable*, std::string> >& alisFile,
58 const bool downToLowestLevel)
61 levelsFilenames_(alisFile),
62 excludedAlignables_(ex),
65 downToLowestLevel_(downToLowestLevel) {}
70 const std::vector<edm::ParameterSet>&
config,
76 unsigned int psetnr = 0;
77 std::set<std::string> steerFilePrefixContainer;
78 for (
const auto&
pset : myConfig_) {
79 this->verifyParameterNames(
pset, psetnr);
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>();
87 const auto ignoredInstances =
pset.exists(
"ignoredInstances")
88 ?
pset.getUntrackedParameter<std::vector<unsigned int> >(
"ignoredInstances")
89 : std::vector<unsigned int>();
91 const auto downToLowestLevel =
92 pset.exists(
"downToLowestLevel") ?
pset.getUntrackedParameter<
bool>(
"downToLowestLevel") :
false;
98 const auto& alis =
selector.selectedAlignables();
101 selector_excludedalignables.clear();
102 if (
pset.exists(
"excludedAlignables")) {
103 selector_excludedalignables.addSelections(
pset.getParameter<
edm::ParameterSet>(
"excludedAlignables"));
105 const auto& excluded_alis = selector_excludedalignables.selectedAlignables();
109 auto sysdeformation = this->verifyDeformationName(
name, coefficients);
111 if (deadmodules_.empty()) {
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);
121 if (
std::find(ignoredInstances.begin(), ignoredInstances.end(),
instance) != ignoredInstances.end()) {
124 std::stringstream defaultsteerfileprefix;
125 defaultsteerfileprefix <<
"autosteerFilePrefix_" <<
name <<
"_" << psetnr <<
"_" <<
instance;
127 const auto steerFilePrefix =
pset.exists(
"steerFilePrefix") ?
pset.getParameter<
std::string>(
"steerFilePrefix") +
129 : defaultsteerfileprefix.
str();
131 const auto levelsFilenames = this->makeLevelsFilenames(steerFilePrefixContainer, alis, steerFilePrefix);
135 coefficients,
name, levelsFilenames, sysdeformation, excluded_alis,
instance, downToLowestLevel));
145 const auto ySplit = aliPar->
ySplit();
147 const auto yM1 = 0.5 * (ySplit - halfLength);
148 const auto yM2 = yM1 + halfLength;
151 return std::make_pair(pos_sensor0, pos_sensor1);
153 throw cms::Exception(
"Alignment") <<
"[PedeSteererWeakModeConstraints::getDoubleSensorPosition]" 154 <<
" Dynamic cast to double sensor parameters failed.";
161 unsigned int nConstraints = 0;
164 for (
const auto& iHLS : iC.levelsFilenames_) {
167 if (iC.downToLowestLevel_) {
168 if (!iHLS.first->lastCompsWithParams(aliDaughts)) {
169 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteererWeakModeConstraints::createAlignablesDataStructure" 170 <<
"Some but not all component branches " 175 if (!iHLS.first->firstCompsWithParams(aliDaughts)) {
176 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteererWeakModeConstraints::createAlignablesDataStructure" 177 <<
"Some but not all daughters of " 184 std::list<Alignable*> usedinconstraint;
185 for (
const auto& iD : aliDaughts) {
186 bool isNOTdead =
true;
189 iD->geomDetId().rawId() == iDeadmodules) {
195 for (
const auto& iEx : iC.excludedAlignables_) {
196 if (iD->id() == iEx->id() && iD->alignableObjectId() == iEx->alignableObjectId()) {
202 const bool issubcomponent = this->
checkMother(iD, iHLS.first);
203 if (issubcomponent) {
205 usedinconstraint.push_back(iD);
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 " 216 if (!usedinconstraint.empty()) {
217 iC.HLSsubdets_.push_back(std::make_pair(iHLS.first, usedinconstraint));
219 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteererWeakModeConstraints" 220 <<
"No sub-components for " 222 << iHLS.first->globalPosition().x() <<
"," << iHLS.first->globalPosition().y() <<
"," 223 << iHLS.first->globalPosition().z() <<
") selected. Skip constraint";
225 if (aliDaughts.empty()) {
226 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteererWeakModeConstraints::createAlignablesDataStructure" 227 <<
"No active sub-alignables found for " 229 << iHLS.first->globalPosition().x() <<
"," << iHLS.first->globalPosition().y()
230 <<
"," << iHLS.first->globalPosition().z() <<
").";
240 const double phase)
const {
243 const double r = TMath::Sqrt(
pos.x() *
pos.x() +
pos.y() *
pos.y());
245 switch (sysdeformation) {
246 case SystematicDeformations::kTwist:
247 case SystematicDeformations::kZexpansion:
250 case SystematicDeformations::kSagitta:
251 case SystematicDeformations::kRadial:
252 case SystematicDeformations::kTelescope:
253 case SystematicDeformations::kLayerRotation:
256 case SystematicDeformations::kBowing:
259 case SystematicDeformations::kElliptical:
262 case SystematicDeformations::kSkew:
276 const int iParameter,
278 const std::vector<double>& constraintparameters)
const {
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 <<
".";
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()};
291 const std::vector<std::vector<double> > global_vecs = {vec_u, vec_v, vec_w};
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());
300 const std::vector<double> radial_direction = {TMath::Sin(
phase), TMath::Cos(
phase), 0.0};
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));
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));
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));
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));
324 double dot_product = 0.0;
325 double normalisation_factor = 1.0;
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;
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);
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);
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);
362 if (TMath::Abs(normalisation_factor) > 0.0) {
363 coeff = dot_product * (this->
getX(sysdeformation,
pos,
phase) - x0) / normalisation_factor;
365 throw cms::Exception(
"Alignment") <<
"[PedeSteererWeakModeConstraints::getCoefficient]" 366 <<
" Normalisation factor" 367 <<
"for coefficient calculation equal to zero! Misconfiguration?";
374 bool isselected =
false;
377 if ((iParameter <= 2) || (iParameter >= 9 && iParameter <= 11)) {
378 if (!aliSel.at(iParameter)) {
384 if (selVar->fullSelection().size() <= (iParameter + 1)) {
386 <<
"[PedeSteererWeakModeConstraints::checkSelectionShiftParameter]" 387 <<
" Can not access selected alignment variables of alignable " 390 <<
"for parameter number " << (iParameter + 1) <<
".";
393 const char selChar = (selVar ? selVar->fullSelection().at(iParameter) :
'1');
395 if (selChar ==
'1' || selChar ==
'r') {
409 for (
auto& iFile : it.mapFileName_) {
412 iFile.second =
nullptr;
414 throw cms::Exception(
"FileCloseProblem") <<
"[PedeSteererWeakModeConstraints]" 415 <<
" can not close file " << iFile.first <<
".";
426 std::ofstream* ofile =
getFile(it, iHLS);
428 if (ofile ==
nullptr) {
429 throw cms::Exception(
"FileFindError") <<
"[PedeSteererWeakModeConstraints] Cannot find output file.";
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;
444 std::ofstream*
file =
nullptr;
447 if (ilevelsFilename.first->id() == iHLS->
id() &&
449 const auto iFile = it.
mapFileName_.find(ilevelsFilename.second);
451 file = iFile->second;
462 double nmodules = 0.0;
465 for (
const auto& ali : iHLS.second) {
467 bool alignableIsFloating =
false;
470 for (
unsigned int iParameter = 0;
static_cast<int>(iParameter) < ali->alignmentParameters()->size(); iParameter++) {
472 alignableIsFloating =
true;
488 if (alignableIsFloating) {
505 throw cms::Exception(
"Alignment") <<
"@SUB=PedeSteererWeakModeConstraints::ConstructConstraints" 506 <<
" Number of selected modules equal to zero. Check configuration!";
521 std::vector<std::list<std::pair<unsigned int, double> > > createdConstraints;
527 for (
const auto& iHLS : it.HLSsubdets_) {
528 double sum_xi_x0 = 0.0;
529 std::list<std::pair<unsigned int, double> >
output;
531 const double x0 = this->
getX0(iHLS, it);
533 for (std::list<Alignable*>::const_iterator iAlignables = iHLS.second.begin(); iAlignables != iHLS.second.end();
539 const LocalPoint lUDirection(1., 0., 0.), lVDirection(0., 1., 0.), lWDirection(0., 0., 1.);
542 gWDirection = surface.
toGlobal(lWDirection);
549 const auto& pos_sensor0 = sensorpositions.first;
550 const auto& pos_sensor1 = sensorpositions.second;
552 const auto x_sensor0 = this->
getX(it.sysdeformation_, pos_sensor0,
phase);
553 const auto x_sensor1 = isDoubleSensor ? this->
getX(it.sysdeformation_, pos_sensor1,
phase) : 0.0;
555 sum_xi_x0 += (x_sensor0 - x0) * (x_sensor0 - x0);
556 if (isDoubleSensor) {
557 sum_xi_x0 += (x_sensor1 - x0) * (x_sensor1 - x0);
561 for (
int iParameter = 0; iParameter < numparameterlimit; iParameter++) {
563 if (iParameter == 0 || iParameter == 9)
565 if (iParameter == 1 || iParameter == 10)
567 if (iParameter == 2 || iParameter == 11)
570 if ((iParameter >= 0 && iParameter <= 2) || (iParameter >= 9 && iParameter <= 11)) {
580 const auto&
pos = (iParameter <= 2) ? pos_sensor0 : pos_sensor1;
582 if (iParameter == 0 || iParameter == 1 || iParameter == 2 || iParameter == 9 || iParameter == 10 ||
585 it.sysdeformation_,
pos, gUDirection, gVDirection, gWDirection, localindex, x0, it.coefficients_);
586 if (TMath::Abs(coeff) > 0.0) {
590 <<
"@SUB=PedeSteererWeakModeConstraints::getCoefficient" 595 <<
" for parameter " << localindex <<
" equal to zero. This alignable is used in the constraint" 596 <<
" '" << it.constraintName_
597 <<
"'. The id is: alignable->geomDetId().rawId() = " << ali->
geomDetId().
rawId() <<
".";
604 if (
std::find(createdConstraints.begin(), createdConstraints.end(),
output) != createdConstraints.end()) {
608 throw cms::Exception(
"FileFindError") <<
"[PedeSteererWeakModeConstraints] Cannot find output file.";
610 *
outFile <<
"! The constraint for this IOV/momentum range" << std::endl
611 <<
"! has been removed because the used parameters" << std::endl
612 <<
"! are not IOV or momentum-range dependent." << std::endl;
616 this->
writeOutput(output, it, iHLS.first, sum_xi_x0);
617 createdConstraints.push_back(
output);
630 if (lowleveldet->
mother() ==
nullptr)
639 const auto parameterNames =
pset.getParameterNames();
640 for (
const auto&
name : parameterNames) {
641 if (
name !=
"coefficients" &&
name !=
"deadmodules" &&
name !=
"constraint" &&
name !=
"steerFilePrefix" &&
642 name !=
"levels" &&
name !=
"excludedAlignables" &&
name !=
"ignoredInstances" &&
name !=
"downToLowestLevel") {
643 throw cms::Exception(
"BadConfig") <<
"@SUB=PedeSteererWeakModeConstraints::verifyParameterNames:" 644 <<
" Unknown parameter name '" <<
name <<
"' in PSet number " << psetnr
645 <<
". Maybe a typo?";
652 std::set<std::string>& steerFilePrefixContainer,
656 if (steerFilePrefixContainer.find(steerFilePrefix) != steerFilePrefixContainer.end()) {
657 throw cms::Exception(
"BadConfig") <<
"[PedeSteererWeakModeConstraints] Steering file" 658 <<
" prefix '" << steerFilePrefix <<
"' already exists. Specify unique names!";
660 steerFilePrefixContainer.insert(steerFilePrefix);
663 std::vector<std::pair<Alignable*, std::string> > levelsFilenames;
664 for (
const auto& ali : alis) {
668 << ali->alignableObjectId() <<
".txt";
670 levelsFilenames.push_back(std::make_pair(ali,
n.str()));
672 return levelsFilenames;
677 const std::vector<double>& coefficients)
const {
680 if (
name ==
"twist") {
681 sysdeformation = SystematicDeformations::kTwist;
682 }
else if (
name ==
"zexpansion") {
683 sysdeformation = SystematicDeformations::kZexpansion;
684 }
else if (
name ==
"sagitta") {
685 sysdeformation = SystematicDeformations::kSagitta;
686 }
else if (
name ==
"radial") {
687 sysdeformation = SystematicDeformations::kRadial;
688 }
else if (
name ==
"telescope") {
689 sysdeformation = SystematicDeformations::kTelescope;
690 }
else if (
name ==
"layerrotation") {
691 sysdeformation = SystematicDeformations::kLayerRotation;
692 }
else if (
name ==
"bowing") {
693 sysdeformation = SystematicDeformations::kBowing;
694 }
else if (
name ==
"skew") {
695 sysdeformation = SystematicDeformations::kSkew;
696 }
else if (
name ==
"elliptical") {
697 sysdeformation = SystematicDeformations::kElliptical;
701 throw cms::Exception(
"BadConfig") <<
"[PedeSteererWeakModeConstraints]" 702 <<
" specified configuration option '" <<
name <<
"' not known.";
704 if ((sysdeformation == SystematicDeformations::kSagitta || sysdeformation == SystematicDeformations::kElliptical ||
705 sysdeformation == SystematicDeformations::kSkew) &&
706 coefficients.size() != 2) {
707 throw cms::Exception(
"BadConfig") <<
"[PedeSteererWeakModeConstraints]" 708 <<
" Excactly two parameters using the coefficient" 709 <<
" variable have to be provided for the " <<
name <<
" constraint.";
711 if ((sysdeformation == SystematicDeformations::kTwist || sysdeformation == SystematicDeformations::kZexpansion ||
712 sysdeformation == SystematicDeformations::kTelescope ||
713 sysdeformation == SystematicDeformations::kLayerRotation || sysdeformation == SystematicDeformations::kRadial ||
714 sysdeformation == SystematicDeformations::kBowing) &&
715 coefficients.size() != 1) {
716 throw cms::Exception(
"BadConfig") <<
"[PedeSteererWeakModeConstraints]" 717 <<
" Excactly ONE parameter using the coefficient" 718 <<
" variable have to be provided for the " <<
name <<
" constraint.";
721 if (coefficients.empty()) {
722 throw cms::Exception(
"BadConfig") <<
"[PedeSteererWeakModeConstraints]" 723 <<
" At least one coefficient has to be specified.";
725 return sysdeformation;
730 return coefficients.size() == 2 ? coefficients.at(1) : 0.0;
align::GlobalPoints toGlobal(const align::LocalPoints &) const
Return in global coord given a set of local points.
unsigned int constructConstraints(const align::Alignables &)
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Alignable * mother() const
Return pointer to container alignable (if any)
const std::vector< std::pair< Alignable *, std::string > > levelsFilenames_
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
static AlignableObjectId commonObjectIdProvider(const AlignableObjectId &, const AlignableObjectId &)
static PFTauRenderPlugin instance
std::ofstream * getFile(const GeometryConstraintConfigData &it, const Alignable *iHLS) const
std::list< align::ID > deadmodules_
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)
__host__ __device__ VT * co
static std::string to_string(const XMLCh *ch)
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
GeometryConstraintConfigData(const std::vector< double > &co, const std::string &c, const std::vector< std::pair< Alignable *, std::string > > &alisFile, const int sd, const align::Alignables &ex, const int instance, const bool downToLowestLevel)
const std::string steerFile_
const PositionType & globalPosition() const
Return the global position of the object.
~PedeSteererWeakModeConstraints()
std::map< std::string, std::ofstream * > mapFileName_
int verifyDeformationName(const std::string &name, const std::vector< double > &coefficients) const
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
bool checkMother(const Alignable *const lowleveldet, const Alignable *const HLS) const
const AlignableObjectId alignableObjectId_
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
int size(void) const
Get number of parameters.
const std::vector< double > coefficients_
PedeSteererWeakModeConstraints(AlignableTracker *aliTracker, const PedeLabelerBase *labels, const std::vector< edm::ParameterSet > &config, std::string sf)
const int sysdeformation_
Log< level::Info, false > LogInfo
double getPhase(const std::vector< double > &coefficients) const
align::ID id() const
Return the ID of Alignable, i.e. DetId of 'first' component GeomDet(Unit).
virtual int type() const =0
tell type (AlignmentParametersFactory::ParametersType - but no circular dependency) ...
const char * idToString(align::StructureType type) const
const DetId & geomDetId() const
virtual unsigned int alignableLabelFromParamAndInstance(const Alignable *alignable, unsigned int param, unsigned int instance) const =0
constexpr uint32_t rawId() const
get the raw id
double getX(const int sysdeformation, const align::GlobalPoint &pos, const double phase) const
align::Scalar length() const
const std::vector< bool > & selector(void) const
Get alignment parameter selector vector.
const std::vector< std::pair< Alignable *, std::string > > makeLevelsFilenames(std::set< std::string > &steerFilePrefixContainer, const align::Alignables &alis, const std::string &steerFilePrefix) const
std::vector< Alignable * > Alignables
void verifyParameterNames(const edm::ParameterSet &pset, unsigned int psetnr) const
unsigned int createAlignablesDataStructure()
Log< level::Warning, false > LogWarning
const PedeLabelerBase * myLabels_
std::list< GeometryConstraintConfigData > ConstraintsConfigContainer_
double getX0(const std::pair< Alignable *, std::list< Alignable *> > &iHLS, const GeometryConstraintConfigData &it) const