16 #include <boost/cstdint.hpp> 59 const std::vector<std::pair<Alignable*,std::string> >& alisFile,
63 const bool downToLowestLevel
67 levelsFilenames_(alisFile),
68 excludedAlignables_(ex),
71 downToLowestLevel_(downToLowestLevel)
78 const std::vector<edm::ParameterSet> &
config,
86 unsigned int psetnr = 0;
87 std::set<std::string> steerFilePrefixContainer;
92 const auto coefficients =
pset.getParameter<std::vector<double> > (
"coefficients");
93 const auto dm =
pset.exists(
"deadmodules") ?
94 pset.getParameter<std::vector<unsigned int> >(
"deadmodules") : std::vector<unsigned int>();
97 const auto ignoredInstances =
pset.exists(
"ignoredInstances") ?
98 pset.getUntrackedParameter<std::vector<unsigned int> >(
"ignoredInstances"):
99 std::vector<unsigned int>();
101 const auto downToLowestLevel =
pset.exists(
"downToLowestLevel") ?
102 pset.getUntrackedParameter<
bool>(
"downToLowestLevel"):
false;
108 const auto& alis = selector.selectedAlignables();
111 selector_excludedalignables.
clear();
112 if(
pset.exists(
"excludedAlignables")) {
122 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteererWeakModeConstraints" 123 <<
"Load list of dead modules (size = " << dm.size()<<
").";
133 != ignoredInstances.end()) {
136 std::stringstream defaultsteerfileprefix;
137 defaultsteerfileprefix <<
"autosteerFilePrefix_" << name <<
"_" << psetnr
140 const auto steerFilePrefix =
pset.exists(
"steerFilePrefix") ?
141 pset.getParameter<
std::string> (
"steerFilePrefix") +
"_" + std::to_string(instance) :
142 defaultsteerfileprefix.str();
163 std::pair<align::GlobalPoint, align::GlobalPoint>
169 const auto ySplit = aliPar->
ySplit();
171 const auto yM1 = 0.5 * (ySplit - halfLength);
172 const auto yM2 = yM1 + halfLength;
175 return std::make_pair(pos_sensor0, pos_sensor1);
178 <<
"[PedeSteererWeakModeConstraints::getDoubleSensorPosition]" 179 <<
" Dynamic cast to double sensor parameters failed.";
188 unsigned int nConstraints = 0;
191 for(
const auto& iHLS: iC.levelsFilenames_) {
194 if (iC.downToLowestLevel_) {
195 if (!iHLS.first->lastCompsWithParams(aliDaughts)) {
197 <<
"@SUB=PedeSteererWeakModeConstraints::createAlignablesDataStructure" 198 <<
"Some but not all component branches " 203 if (!iHLS.first->firstCompsWithParams(aliDaughts)) {
205 <<
"@SUB=PedeSteererWeakModeConstraints::createAlignablesDataStructure" 206 <<
"Some but not all daughters of " 213 std::list<Alignable*> usedinconstraint;
214 for (
const auto& iD: aliDaughts) {
215 bool isNOTdead =
true;
219 && iD->geomDetId().rawId() == iDeadmodules) {
225 for(
const auto& iEx: iC.excludedAlignables_) {
226 if(iD->id() == iEx->id() && iD->alignableObjectId() == iEx->alignableObjectId() ) {
232 const bool issubcomponent = this->
checkMother(iD,iHLS.first);
235 usedinconstraint.push_back(iD);
240 <<
"[PedeSteererWeakModeConstraints::createAlignablesDataStructure]" 241 <<
" Sanity check failed. Alignable defined as active sub-component, " 246 if( !usedinconstraint.empty()){
247 iC.HLSsubdets_.push_back(std::make_pair(iHLS.first, usedinconstraint));
249 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteererWeakModeConstraints" 250 <<
"No sub-components for " 252 <<
" at (" << iHLS.first->globalPosition().x()
253 <<
","<< iHLS.first->globalPosition().y()
254 <<
"," << iHLS.first->globalPosition().z()
255 <<
") selected. Skip constraint";
257 if(aliDaughts.empty()) {
258 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteererWeakModeConstraints::createAlignablesDataStructure" 259 <<
"No active sub-alignables found for " 261 <<
" at (" << iHLS.first->globalPosition().x() <<
","<< iHLS.first->globalPosition().y() <<
"," << iHLS.first->globalPosition().z() <<
").";
274 const double phase)
const 278 const double r = TMath::Sqrt(pos.
x() * pos.
x() + pos.
y() * pos.
y());
280 switch(sysdeformation) {
281 case SystematicDeformations::kTwist:
282 case SystematicDeformations::kZexpansion:
285 case SystematicDeformations::kSagitta:
286 case SystematicDeformations::kRadial:
287 case SystematicDeformations::kTelescope:
288 case SystematicDeformations::kLayerRotation:
291 case SystematicDeformations::kBowing:
292 x = pos.
z() * pos.
z();
294 case SystematicDeformations::kElliptical:
295 x = r * TMath::Cos(2.0 * pos.
phi() +
phase);
297 case SystematicDeformations::kSkew:
312 const int iParameter,
const double &x0,
313 const std::vector<double> &constraintparameters)
const 317 if(iParameter < 0 || iParameter > 2) {
319 <<
"[PedeSteererWeakModeConstraints::getCoefficient]" <<
" iParameter has to be in the range [0,2] but" 320 <<
" it is equal to " << iParameter <<
".";
325 const std::vector<double> vec_u = {pos.
x() - gUDirection.
x(), pos.
y() - gUDirection.
y(), pos.
z() - gUDirection.
z()};
326 const std::vector<double> vec_v = {pos.
x() - gVDirection.
x(), pos.
y() - gVDirection.
y(), pos.
z() - gVDirection.
z()};
327 const std::vector<double> vec_w = {pos.
x() - gWDirection.
x(), pos.
y() - gWDirection.
y(), pos.
z() - gWDirection.
z()};
330 const std::vector<std::vector<double> > global_vecs = {vec_u, vec_v, vec_w};
332 const double n = TMath::Sqrt( global_vecs.at(iParameter).at(0) * global_vecs.at(iParameter).at(0)
333 + global_vecs.at(iParameter).at(1) * global_vecs.at(iParameter).at(1)
334 + global_vecs.at(iParameter).at(2) * global_vecs.at(iParameter).at(2) );
335 const double r = TMath::Sqrt( pos.
x() * pos.
x() + pos.
y() * pos.
y() );
339 const std::vector<double> radial_direction = {TMath::Sin(phase), TMath::Cos(phase), 0.0};
341 const double norm_radial_direction = TMath::Sqrt(radial_direction.at(0) * radial_direction.at(0)
342 + radial_direction.at(1) * radial_direction.at(1)
343 + radial_direction.at(2) * radial_direction.at(2));
346 const std::vector<double> phi_direction = {-1.0 * pos.
y(), pos.
x(), 0.0};
347 const double norm_phi_direction = TMath::Sqrt(phi_direction.at(0) * phi_direction.at(0)
348 + phi_direction.at(1) * phi_direction.at(1)
349 + phi_direction.at(2) * phi_direction.at(2));
352 static const std::vector<double> z_direction = {0.0, 0.0, 1.0};
353 const double norm_z_direction = TMath::Sqrt(z_direction.at(0)*z_direction.at(0)
354 + z_direction.at(1)*z_direction.at(1)
355 + z_direction.at(2)*z_direction.at(2));
358 const std::vector<double> rDirection = {pos.
x(), pos.
y(), 0.0};
359 const double norm_rDirection = TMath::Sqrt(rDirection.at(0) * rDirection.at(0)
360 + rDirection.at(1) * rDirection.at(1)
361 + rDirection.at(2) * rDirection.at(2));
364 double dot_product = 0.0;
365 double normalisation_factor = 1.0;
368 switch(sysdeformation) {
369 case SystematicDeformations::kTwist:
370 case SystematicDeformations::kLayerRotation:
371 dot_product = phi_direction.at(0) * global_vecs.at(iParameter).at(0)
372 + phi_direction.at(1) * global_vecs.at(iParameter).at(1)
373 + phi_direction.at(2) * global_vecs.at(iParameter).at(2);
374 normalisation_factor = r * n * norm_phi_direction;
376 case SystematicDeformations::kZexpansion :
377 case SystematicDeformations::kTelescope:
378 case SystematicDeformations::kSkew:
379 dot_product = global_vecs.at(iParameter).at(0) * z_direction.at(0)
380 + global_vecs.at(iParameter).at(1) * z_direction.at(1)
381 + global_vecs.at(iParameter).at(2) * z_direction.at(2);
382 normalisation_factor = ( n * norm_z_direction);
384 case SystematicDeformations::kRadial:
385 case SystematicDeformations::kBowing:
386 case SystematicDeformations::kElliptical:
387 dot_product = global_vecs.at(iParameter).at(0) * rDirection.at(0)
388 + global_vecs.at(iParameter).at(1) * rDirection.at(1)
389 + global_vecs.at(iParameter).at(2) * rDirection.at(2);
390 normalisation_factor = ( n * norm_rDirection);
392 case SystematicDeformations::kSagitta:
393 dot_product = global_vecs.at(iParameter).at(0) * radial_direction.at(0)
394 + global_vecs.at(iParameter).at(1) * radial_direction.at(1)
395 + global_vecs.at(iParameter).at(2) * radial_direction.at(2);
396 normalisation_factor = ( n * norm_radial_direction);
402 coeff = dot_product * ( this->
getX(sysdeformation,pos,phase) - x0 ) / normalisation_factor;
405 <<
"[PedeSteererWeakModeConstraints::getCoefficient]" <<
" Normalisation factor" 406 <<
"for coefficient calculation equal to zero! Misconfiguration?";
414 unsigned int iParameter)
const 416 bool isselected =
false;
420 || (iParameter >= 9 && iParameter <=11)) {
421 if(!aliSel.at(iParameter)) {
427 if(selVar->fullSelection().size() <= (iParameter+1)) {
429 <<
"[PedeSteererWeakModeConstraints::checkSelectionShiftParameter]" 430 <<
" Can not access selected alignment variables of alignable " 433 <<
"for parameter number " << (iParameter+1) <<
".";
436 const char selChar = (selVar ? selVar->fullSelection().at(iParameter) :
'1');
438 if(selChar ==
'1' || selChar ==
'r') {
454 for(
auto& iFile:it.mapFileName_) {
457 iFile.second =
nullptr;
460 <<
"[PedeSteererWeakModeConstraints]" <<
" can not close file " << iFile.first <<
".";
475 if(ofile ==
nullptr) {
477 <<
"[PedeSteererWeakModeConstraints] Cannot find output file.";
481 (*ofile) <<
"Constraint " << std::scientific << constr << std::endl;
482 for(
const auto& ioutput:
output) {
483 (*ofile) <<
std::fixed << ioutput.first <<
" " << std::scientific << ioutput.second << std::endl;
494 std::ofstream*
file =
nullptr;
497 if(ilevelsFilename.first->id() == iHLS->
id() &&
500 const auto iFile = it.
mapFileName_.find(ilevelsFilename.second);
502 file = iFile->second;
515 double nmodules = 0.0;
518 for(
const auto& ali: iHLS.second) {
520 bool alignableIsFloating =
false;
523 for(
unsigned int iParameter = 0;
524 static_cast<int>(iParameter) < ali->alignmentParameters()->size(); iParameter++) {
526 alignableIsFloating =
true;
542 if(alignableIsFloating) {
559 <<
"@SUB=PedeSteererWeakModeConstraints::ConstructConstraints" 560 <<
" Number of selected modules equal to zero. Check configuration!";
577 std::vector<std::list<std::pair<unsigned int,double> > > createdConstraints;
584 for(
const auto& iHLS : it.HLSsubdets_) {
585 double sum_xi_x0 = 0.0;
586 std::list<std::pair<unsigned int,double> >
output;
588 const double x0 = this->
getX0(iHLS, it);
590 for(std::list<Alignable*>::const_iterator iAlignables = iHLS.second.begin();
591 iAlignables != iHLS.second.end(); iAlignables++) {
597 lVDirection(0.,1.,0.),
598 lWDirection(0.,0.,1.);
601 gVDirection = surface.
toGlobal(lVDirection),
602 gWDirection = surface.
toGlobal(lWDirection);
606 const auto sensorpositions =
609 const auto& pos_sensor0 = sensorpositions.first;
610 const auto& pos_sensor1 = sensorpositions.second;
612 const auto x_sensor0 = this->
getX(it.sysdeformation_,pos_sensor0,
phase);
613 const auto x_sensor1 = isDoubleSensor ? this->
getX(it.sysdeformation_,pos_sensor1,
phase) : 0.0;
615 sum_xi_x0 += ( x_sensor0 - x0 ) * ( x_sensor0 - x0 );
617 sum_xi_x0 += ( x_sensor1 - x0 ) * ( x_sensor1 - x0 );
621 for(
int iParameter = 0; iParameter < numparameterlimit; iParameter++) {
623 if(iParameter == 0 || iParameter == 9)
625 if(iParameter == 1 || iParameter == 10)
627 if(iParameter == 2 || iParameter == 11)
630 if((iParameter >= 0 && iParameter <= 2)
631 || (iParameter >= 9 && iParameter <=11)) {
641 const auto&
pos = (iParameter <= 2) ? pos_sensor0 : pos_sensor1;
643 if(iParameter == 0 || iParameter == 1 || iParameter == 2
644 || iParameter == 9 || iParameter == 10 || iParameter == 11) {
657 <<
"@SUB=PedeSteererWeakModeConstraints::getCoefficient" 658 <<
"Coefficient of alignable " 662 <<
" for parameter " << localindex <<
" equal to zero. This alignable is used in the constraint" 663 <<
" '" << it.constraintName_ <<
"'. The id is: alignable->geomDetId().rawId() = " 666 output.push_back(std::make_pair (paramLabel, coeff));
673 if (
std::find(createdConstraints.begin(), createdConstraints.end(),
output)
674 != createdConstraints.end()) {
679 <<
"[PedeSteererWeakModeConstraints] Cannot find output file.";
681 *
outFile <<
"! The constraint for this IOV/momentum range" << std::endl
682 <<
"! has been removed because the used parameters" << std::endl
683 <<
"! are not IOV or momentum-range dependent." << std::endl;
687 this->
writeOutput(output, it, iHLS.first, sum_xi_x0);
688 createdConstraints.push_back(output);
704 if(lowleveldet->
mother() ==
nullptr)
714 unsigned int psetnr)
const 717 for (
const auto&
name: parameterNames) {
718 if(
name !=
"coefficients" 719 &&
name !=
"deadmodules" &&
name !=
"constraint" 720 &&
name !=
"steerFilePrefix" &&
name !=
"levels" 721 &&
name !=
"excludedAlignables" &&
name !=
"ignoredInstances" 722 &&
name !=
"downToLowestLevel" 725 <<
"@SUB=PedeSteererWeakModeConstraints::verifyParameterNames:" 726 <<
" Unknown parameter name '" <<
name <<
"' in PSet number " << psetnr <<
". Maybe a typo?";
732 const std::vector<std::pair<Alignable*, std::string> >
738 if(steerFilePrefixContainer.find(steerFilePrefix) != steerFilePrefixContainer.end()) {
739 throw cms::Exception(
"BadConfig") <<
"[PedeSteererWeakModeConstraints] Steering file" 740 <<
" prefix '" << steerFilePrefix <<
"' already exists. Specify unique names!";
742 steerFilePrefixContainer.insert(steerFilePrefix);
745 std::vector<std::pair<Alignable*, std::string> > levelsFilenames;
746 for(
const auto& ali: alis) {
750 <<
"_" << ali->id() <<
"_" << ali->alignableObjectId() <<
".txt";
752 levelsFilenames.push_back(std::make_pair(ali, n.str()));
754 return levelsFilenames;
760 const std::vector<double> &coefficients)
const 764 if(name ==
"twist") {
765 sysdeformation = SystematicDeformations::kTwist;
766 }
else if(name ==
"zexpansion") {
767 sysdeformation = SystematicDeformations::kZexpansion;
768 }
else if(name ==
"sagitta") {
769 sysdeformation = SystematicDeformations::kSagitta;
770 }
else if(name ==
"radial") {
771 sysdeformation = SystematicDeformations::kRadial;
772 }
else if(name ==
"telescope") {
773 sysdeformation = SystematicDeformations::kTelescope;
774 }
else if(name ==
"layerrotation") {
775 sysdeformation = SystematicDeformations::kLayerRotation;
776 }
else if(name ==
"bowing") {
777 sysdeformation = SystematicDeformations::kBowing;
778 }
else if(name ==
"skew") {
779 sysdeformation = SystematicDeformations::kSkew;
780 }
else if(name ==
"elliptical") {
781 sysdeformation = SystematicDeformations::kElliptical;
786 <<
"[PedeSteererWeakModeConstraints]" <<
" specified configuration option '" 787 << name <<
"' not known.";
789 if((sysdeformation == SystematicDeformations::kSagitta
790 || sysdeformation == SystematicDeformations::kElliptical
791 || sysdeformation == SystematicDeformations::kSkew) && coefficients.size() != 2) {
793 <<
"[PedeSteererWeakModeConstraints]" <<
" Excactly two parameters using the coefficient" 794 <<
" variable have to be provided for the " << name <<
" constraint.";
796 if((sysdeformation == SystematicDeformations::kTwist
797 || sysdeformation == SystematicDeformations::kZexpansion
798 || sysdeformation == SystematicDeformations::kTelescope
799 || sysdeformation == SystematicDeformations::kLayerRotation
800 || sysdeformation == SystematicDeformations::kRadial
801 || sysdeformation == SystematicDeformations::kBowing) && coefficients.size() != 1) {
803 <<
"[PedeSteererWeakModeConstraints]" <<
" Excactly ONE parameter using the coefficient" 804 <<
" variable have to be provided for the " << name <<
" constraint.";
807 if(coefficients.empty()) {
809 <<
"[PedeSteererWeakModeConstraints]" <<
" At least one coefficient has to be specified.";
811 return sysdeformation;
819 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
unsigned int constructConstraints(const align::Alignables &)
void verifyParameterNames(const edm::ParameterSet &pset, unsigned int psetnr) const
const std::vector< std::pair< Alignable *, std::string > > makeLevelsFilenames(std::set< std::string > &steerFilePrefixContainer, const align::Alignables &alis, const std::string &steerFilePrefix) const
static AlignableObjectId commonObjectIdProvider(const AlignableObjectId &, const AlignableObjectId &)
static PFTauRenderPlugin instance
std::list< align::ID > deadmodules_
Geom::Phi< T > phi() const
constexpr uint32_t rawId() const
get the raw id
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)
virtual unsigned int maxNumberOfParameterInstances() const =0
returns the maximum number of instances for any parameter of an Alignable*
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
virtual int type() const =0
tell type (AlignmentParametersFactory::ParametersType - but no circular dependency) ...
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_
void clear()
remove all selected Alignables and geometrical restrictions
~PedeSteererWeakModeConstraints()
const std::vector< std::pair< Alignable *, std::string > > levelsFilenames_
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
const AlignableObjectId alignableObjectId_
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
virtual unsigned int parameterLabel(unsigned int aliLabel, unsigned int parNum) const =0
returns the label for a given alignable parameter number combination
const std::vector< double > coefficients_
virtual unsigned int alignableLabelFromParamAndInstance(Alignable *alignable, unsigned int param, unsigned int instance) const =0
std::vector< std::string > getParameterNames() const
PedeSteererWeakModeConstraints(AlignableTracker *aliTracker, const PedeLabelerBase *labels, const std::vector< edm::ParameterSet > &config, std::string sf)
const std::vector< edm::ParameterSet > myConfig_
const 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
align::Scalar length() const
int size(void) const
Get number of parameters.
const char * idToString(align::StructureType type) const
std::vector< Alignable * > Alignables
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
const PedeLabelerBase * myLabels_
Alignable * mother() const
Return pointer to container alignable (if any)
const DetId & geomDetId() const
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