16 #include <boost/cstdint.hpp>
59 const std::vector<std::pair<Alignable*,std::string> >& alisFile,
61 const std::vector<Alignable*>& ex,
63 const bool downToLowestLevel
67 levelsFilenames_(alisFile),
68 excludedAlignables_(ex),
71 downToLowestLevel_(downToLowestLevel)
78 const std::vector<edm::ParameterSet> &
config,
85 unsigned int psetnr = 0;
86 std::set<std::string> steerFilePrefixContainer;
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>();
96 const auto ignoredInstances =
pset.exists(
"ignoredInstances") ?
97 pset.getUntrackedParameter<std::vector<unsigned int> >(
"ignoredInstances"):
98 std::vector<unsigned int>();
100 const auto downToLowestLevel =
pset.exists(
"downToLowestLevel") ?
101 pset.getUntrackedParameter<
bool>(
"downToLowestLevel"):
false;
107 const auto& alis = selector.selectedAlignables();
110 selector_excludedalignables.
clear();
111 if(
pset.exists(
"excludedAlignables")) {
121 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteererWeakModeConstraints"
122 <<
"Load list of dead modules (size = " << dm.size()<<
").";
132 != ignoredInstances.end()) {
135 std::stringstream defaultsteerfileprefix;
136 defaultsteerfileprefix <<
"autosteerFilePrefix_" << name <<
"_" << psetnr
139 const auto steerFilePrefix =
pset.exists(
"steerFilePrefix") ?
140 pset.getParameter<
std::string> (
"steerFilePrefix") +
"_" + std::to_string(instance) :
141 defaultsteerfileprefix.str();
162 std::pair<align::GlobalPoint, align::GlobalPoint>
168 const auto ySplit = aliPar->
ySplit();
170 const auto yM1 = 0.5 * (ySplit - halfLength);
171 const auto yM2 = yM1 + halfLength;
174 return std::make_pair(pos_sensor0, pos_sensor1);
177 <<
"[PedeSteererWeakModeConstraints::getDoubleSensorPosition]"
178 <<
" Dynamic cast to double sensor parameters failed.";
187 unsigned int nConstraints = 0;
190 for(
const auto& iHLS: iC.levelsFilenames_) {
192 std::vector<Alignable*> aliDaughts;
193 if (iC.downToLowestLevel_) {
194 if (!iHLS.first->lastCompsWithParams(aliDaughts)) {
196 <<
"@SUB=PedeSteererWeakModeConstraints::createAlignablesDataStructure"
197 <<
"Some but not all component branches "
202 if (!iHLS.first->firstCompsWithParams(aliDaughts)) {
204 <<
"@SUB=PedeSteererWeakModeConstraints::createAlignablesDataStructure"
205 <<
"Some but not all daughters of "
212 std::list<Alignable*> usedinconstraint;
213 for (
const auto& iD: aliDaughts) {
214 bool isNOTdead =
true;
218 && iD->geomDetId().rawId() == iDeadmodules) {
224 for(
const auto& iEx: iC.excludedAlignables_) {
225 if(iD->id() == iEx->id() && iD->alignableObjectId() == iEx->alignableObjectId() ) {
231 const bool issubcomponent = this->
checkMother(iD,iHLS.first);
234 usedinconstraint.push_back(iD);
239 <<
"[PedeSteererWeakModeConstraints::createAlignablesDataStructure]"
240 <<
" Sanity check failed. Alignable defined as active sub-component, "
245 if( usedinconstraint.size() > 0){
246 iC.HLSsubdets_.push_back(std::make_pair(iHLS.first, usedinconstraint));
248 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteererWeakModeConstraints"
249 <<
"No sub-components for "
251 <<
" at (" << iHLS.first->globalPosition().x()
252 <<
","<< iHLS.first->globalPosition().y()
253 <<
"," << iHLS.first->globalPosition().z()
254 <<
") selected. Skip constraint";
256 if(aliDaughts.size() == 0) {
257 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteererWeakModeConstraints::createAlignablesDataStructure"
258 <<
"No active sub-alignables found for "
260 <<
" at (" << iHLS.first->globalPosition().x() <<
","<< iHLS.first->globalPosition().y() <<
"," << iHLS.first->globalPosition().z() <<
").";
273 const double phase)
const
277 const double r = TMath::Sqrt(pos.
x() * pos.
x() + pos.
y() * pos.
y());
279 switch(sysdeformation) {
280 case SystematicDeformations::kTwist:
281 case SystematicDeformations::kZexpansion:
284 case SystematicDeformations::kSagitta:
285 case SystematicDeformations::kRadial:
286 case SystematicDeformations::kTelescope:
287 case SystematicDeformations::kLayerRotation:
290 case SystematicDeformations::kBowing:
291 x = pos.
z() * pos.
z();
293 case SystematicDeformations::kElliptical:
294 x = r * TMath::Cos(2.0 * pos.
phi() + phase);
296 case SystematicDeformations::kSkew:
297 x = TMath::Cos(pos.
phi() + phase);
311 const int iParameter,
const double &x0,
312 const std::vector<double> &constraintparameters)
const
316 if(iParameter < 0 || iParameter > 2) {
318 <<
"[PedeSteererWeakModeConstraints::getCoefficient]" <<
" iParameter has to be in the range [0,2] but"
319 <<
" it is equal to " << iParameter <<
".";
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()};
329 const std::vector<std::vector<double> > global_vecs = {vec_u, vec_v, vec_w};
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() );
336 const double phase = this->
getPhase(constraintparameters);
338 const std::vector<double> radial_direction = {TMath::Sin(phase), TMath::Cos(phase), 0.0};
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));
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));
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));
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));
363 double dot_product = 0.0;
364 double normalisation_factor = 1.0;
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;
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);
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);
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);
401 coeff = dot_product * ( this->
getX(sysdeformation,pos,phase) - x0 ) / normalisation_factor;
404 <<
"[PedeSteererWeakModeConstraints::getCoefficient]" <<
" Normalisation factor"
405 <<
"for coefficient calculation equal to zero! Misconfiguration?";
413 unsigned int iParameter)
const
415 bool isselected =
false;
419 || (iParameter >= 9 && iParameter <=11)) {
420 if(!aliSel.at(iParameter)) {
426 if(selVar->fullSelection().size() <= (iParameter+1)) {
428 <<
"[PedeSteererWeakModeConstraints::checkSelectionShiftParameter]"
429 <<
" Can not access selected alignment variables of alignable "
432 <<
"for parameter number " << (iParameter+1) <<
".";
435 const char selChar = (selVar ? selVar->fullSelection().at(iParameter) :
'1');
437 if(selChar ==
'1' || selChar ==
'r') {
453 for(
auto& iFile:it.mapFileName_) {
456 iFile.second =
nullptr;
459 <<
"[PedeSteererWeakModeConstraints]" <<
" can not close file " << iFile.first <<
".";
474 if(ofile ==
nullptr) {
476 <<
"[PedeSteererWeakModeConstraints] Cannot find output file.";
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;
493 std::ofstream*
file =
nullptr;
496 if(ilevelsFilename.first->id() == iHLS->
id() &&
499 const auto iFile = it.
mapFileName_.find(ilevelsFilename.second);
501 file = iFile->second;
514 double nmodules = 0.0;
517 for(
const auto& ali: iHLS.second) {
519 bool alignableIsFloating =
false;
522 for(
unsigned int iParameter = 0;
523 static_cast<int>(iParameter) < ali->alignmentParameters()->size(); iParameter++) {
525 alignableIsFloating =
true;
541 if(alignableIsFloating) {
558 <<
"@SUB=PedeSteererWeakModeConstraints::ConstructConstraints"
559 <<
" Number of selected modules equal to zero. Check configuration!";
576 std::vector<std::list<std::pair<unsigned int,double> > > createdConstraints;
583 for(
const auto& iHLS : it.HLSsubdets_) {
584 double sum_xi_x0 = 0.0;
585 std::list<std::pair<unsigned int,double> >
output;
587 const double x0 = this->
getX0(iHLS, it);
589 for(std::list<Alignable*>::const_iterator iAlignables = iHLS.second.begin();
590 iAlignables != iHLS.second.end(); iAlignables++) {
596 lVDirection(0.,1.,0.),
597 lWDirection(0.,0.,1.);
600 gVDirection = surface.
toGlobal(lVDirection),
601 gWDirection = surface.
toGlobal(lWDirection);
605 const auto sensorpositions =
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;
614 sum_xi_x0 += ( x_sensor0 - x0 ) * ( x_sensor0 - x0 );
616 sum_xi_x0 += ( x_sensor1 - x0 ) * ( x_sensor1 - x0 );
620 for(
int iParameter = 0; iParameter < numparameterlimit; iParameter++) {
622 if(iParameter == 0 || iParameter == 9)
624 if(iParameter == 1 || iParameter == 10)
626 if(iParameter == 2 || iParameter == 11)
629 if((iParameter >= 0 && iParameter <= 2)
630 || (iParameter >= 9 && iParameter <=11)) {
640 const auto& pos = (iParameter <= 2) ? pos_sensor0 : pos_sensor1;
642 if(iParameter == 0 || iParameter == 1 || iParameter == 2
643 || iParameter == 9 || iParameter == 10 || iParameter == 11) {
656 <<
"@SUB=PedeSteererWeakModeConstraints::getCoefficient"
657 <<
"Coefficient of alignable "
661 <<
" for parameter " << localindex <<
" equal to zero. This alignable is used in the constraint"
662 <<
" '" << it.constraintName_ <<
"'. The id is: alignable->geomDetId().rawId() = "
665 output.push_back(std::make_pair (paramLabel, coeff));
672 if (
std::find(createdConstraints.begin(), createdConstraints.end(),
output)
673 != createdConstraints.end()) {
678 <<
"[PedeSteererWeakModeConstraints] Cannot find output file.";
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;
686 this->
writeOutput(output, it, iHLS.first, sum_xi_x0);
687 createdConstraints.push_back(output);
703 if(lowleveldet->
mother() ==
nullptr)
713 unsigned int psetnr)
const
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"
724 <<
"@SUB=PedeSteererWeakModeConstraints::verifyParameterNames:"
725 <<
" Unknown parameter name '" <<
name <<
"' in PSet number " << psetnr <<
". Maybe a typo?";
731 const std::vector<std::pair<Alignable*, std::string> >
733 const std::vector<Alignable*> &alis,
737 if(steerFilePrefixContainer.find(steerFilePrefix) != steerFilePrefixContainer.end()) {
738 throw cms::Exception(
"BadConfig") <<
"[PedeSteererWeakModeConstraints] Steering file"
739 <<
" prefix '" << steerFilePrefix <<
"' already exists. Specify unique names!";
741 steerFilePrefixContainer.insert(steerFilePrefix);
744 std::vector<std::pair<Alignable*, std::string> > levelsFilenames;
745 for(
const auto& ali: alis) {
749 <<
"_" << ali->id() <<
"_" << ali->alignableObjectId() <<
".txt";
751 levelsFilenames.push_back(std::make_pair(ali, n.str()));
753 return levelsFilenames;
759 const std::vector<double> &coefficients)
const
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;
785 <<
"[PedeSteererWeakModeConstraints]" <<
" specified configuration option '"
786 << name <<
"' not known.";
788 if((sysdeformation == SystematicDeformations::kSagitta
789 || sysdeformation == SystematicDeformations::kElliptical
790 || sysdeformation == SystematicDeformations::kSkew) && coefficients.size() != 2) {
792 <<
"[PedeSteererWeakModeConstraints]" <<
" Excactly two parameters using the coefficient"
793 <<
" variable have to be provided for the " << name <<
" constraint.";
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) {
802 <<
"[PedeSteererWeakModeConstraints]" <<
" Excactly ONE parameter using the coefficient"
803 <<
" variable have to be provided for the " << name <<
" constraint.";
806 if(coefficients.size() == 0) {
808 <<
"[PedeSteererWeakModeConstraints]" <<
" At least one coefficient has to be specified.";
810 return sysdeformation;
818 return coefficients.size() == 2 ? coefficients.at(1) : 0.0;
align::ID id() const
Return the ID of Alignable, i.e. DetId of 'first' component GeomDet(Unit).
bool checkSelectionShiftParameter(const Alignable *ali, unsigned int iParameter) const
void verifyParameterNames(const edm::ParameterSet &pset, unsigned int psetnr) const
static PFTauRenderPlugin instance
std::list< align::ID > deadmodules_
Geom::Phi< T > phi() 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< bool > & selector(void) const
Get alignment parameter selector vector.
std::map< std::string, std::ofstream * > mapFileName_
void writeOutput(const std::list< std::pair< unsigned int, double > > &output, const GeometryConstraintConfigData &it, const Alignable *iHLS, double sum_xi_x0)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
unsigned int constructConstraints(const std::vector< Alignable * > &alis)
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
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
Point3DBase< Scalar, GlobalTag > PositionType
const std::string steerFile_
void clear()
remove all selected Alignables and geometrical restrictions
~PedeSteererWeakModeConstraints()
const std::vector< std::pair< Alignable *, std::string > > levelsFilenames_
const std::vector< std::pair< Alignable *, std::string > > makeLevelsFilenames(std::set< std::string > &steerFilePrefixContainer, const std::vector< Alignable * > &alis, const std::string &steerFilePrefix) const
std::ofstream * getFile(const GeometryConstraintConfigData &it, const Alignable *iHLS) const
double getX0(const std::pair< Alignable *, std::list< Alignable * > > &iHLS, const GeometryConstraintConfigData &it) const
int verifyDeformationName(const std::string &name, const std::vector< double > &coefficients) const
GeometryConstraintConfigData(const std::vector< double > &co, const std::string &c, const std::vector< std::pair< Alignable *, std::string > > &alisFile, const int sd, const std::vector< Alignable * > &ex, const int instance, const bool downToLowestLevel)
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
const std::vector< double > coefficients_
std::vector< std::string > getParameterNames() const
PedeSteererWeakModeConstraints(AlignableTracker *aliTracker, const PedeLabelerBase *labels, const std::vector< edm::ParameterSet > &config, std::string sf)
const std::vector< edm::ParameterSet > myConfig_
virtual unsigned int alignableLabelFromParamAndInstance(Alignable *alignable, unsigned int param, unsigned int instance) const =0
const int sysdeformation_
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
const align::Alignables & selectedAlignables() const
vector of alignables selected so far
virtual int type() const =0
tell type (AlignmentParametersFactory::ParametersType - but no circular dependency) ...
align::Scalar length() const
int size(void) const
Get number of parameters.
double getPhase(const std::vector< double > &coefficients) const
unsigned int createAlignablesDataStructure()
align::GlobalPoints toGlobal(const align::LocalPoints &) const
Return in global coord given a set of local points.
unsigned int addSelections(const edm::ParameterSet &pSet)
double getCoefficient(const int sysdeformation, const align::GlobalPoint &pos, const GlobalPoint gUDirection, const GlobalPoint gVDirection, const GlobalPoint gWDirection, const int iParameter, const double &x0, const std::vector< double > &constraintparameters) const
const PositionType & globalPosition() const
Return the global position of the object.
bool checkMother(const Alignable *const lowleveldet, const Alignable *const HLS) const
static const char * idToString(align::StructureType type)
const PedeLabelerBase * myLabels_
Alignable * mother() const
Return pointer to container alignable (if any)
const DetId & geomDetId() const
virtual unsigned int maxNumberOfParameterInstances() const =0
returns the maximum number of instances for any parameter of an Alignable*
std::list< GeometryConstraintConfigData > ConstraintsConfigContainer_
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run