19 #include <boost/cstdint.hpp>
20 #include <boost/assign/list_of.hpp>
63 const std::vector<std::pair<Alignable*,std::string> > &alisFile,
65 const std::vector<Alignable*> ex
69 levelsFilenames_(alisFile),
70 excludedAlignables_(ex),
78 const std::vector<edm::ParameterSet> &
config,
85 unsigned int psetnr = 0;
86 std::set<std::string> steerFilePrefixContainer;
87 for(std::vector<edm::ParameterSet>::const_iterator pset =
myConfig_.begin();
93 const std::vector<double> coefficients = pset->getParameter<std::vector<double> > (
"coefficients");
94 const std::vector<unsigned int> dm = pset->exists(
"deadmodules") ?
95 pset->getParameter<std::vector<unsigned int> >(
"deadmodules") : std::vector<unsigned int>();
99 std::stringstream defaultsteerfileprefix;
100 defaultsteerfileprefix <<
"autosteerFilePrefix_" << name <<
"_" << psetnr;
102 std::string steerFilePrefix = pset->exists(
"steerFilePrefix") ?
103 pset->getParameter<
std::string> (
"steerFilePrefix") : defaultsteerfileprefix.str();
113 selector_excludedalignables.
clear();
114 if(pset->exists(
"excludedAlignables")) {
117 const std::vector<Alignable*> &excluded_alis = selector_excludedalignables.
selectedAlignables();
119 const std::vector<std::pair<Alignable*, std::string> > levelsFilenames = this->
makeLevelsFilenames(steerFilePrefixContainer,
133 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteererWeakModeConstraints"
134 <<
"Load list of dead modules (size = " << dm.size()<<
").";
135 for(std::vector<unsigned int>::const_iterator it = dm.begin(); it != dm.end(); it++) {
149 const double ySplit = aliPar->
ySplit();
154 const double yM1 = 0.5 * (ySplit - halfLength);
155 const double yM2 = yM1 + halfLength;
158 return std::make_pair(pos_sensor0, pos_sensor1);
161 <<
"[PedeSteererWeakModeConstraints::getDoubleSensorPosition]"
162 <<
" Dynamic cast to double sensor parameters failed.";
170 unsigned int nConstraints = 0;
174 for(std::vector<std::pair<Alignable*,std::string> >::const_iterator iHLS = iC->levelsFilenames_.begin();
175 iHLS != iC->levelsFilenames_.end(); ++iHLS) {
177 std::vector<Alignable*> aliDaughts;
178 if (!(*iHLS).first->firstCompsWithParams(aliDaughts)) {
179 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteererWeakModeConstraints::createAlignablesDataStructure"
180 <<
"Some but not all daughters of "
186 std::list<Alignable*> usedinconstraint;
187 for (std::vector<Alignable*>::const_iterator iD = aliDaughts.begin();
188 iD != aliDaughts.end(); ++iD) {
189 bool isNOTdead =
true;
190 for(std::list<unsigned int>::const_iterator iDeadmodules =
deadmodules_.begin();
194 && (*iD)->geomDetId().rawId() == (*iDeadmodules)) {
200 for(std::vector<Alignable*>::const_iterator iEx = iC->excludedAlignables_.begin();
201 iEx != iC->excludedAlignables_.end(); iEx++) {
202 if((*iD)->id() == (*iEx)->id() && (*iD)->alignableObjectId() == (*iEx)->alignableObjectId() ) {
208 const bool issubcomponent = this->
checkMother((*iD),(*iHLS).first);
211 usedinconstraint.push_back((*iD));
216 <<
"[PedeSteererWeakModeConstraints::createAlignablesDataStructure]"
217 <<
" Sanity check failed. Alignable defined as active sub-component, "
222 if( usedinconstraint.size() > 0){
223 (*iC).HLSsubdets_.push_back(std::make_pair((*iHLS).first, usedinconstraint));
225 edm::LogInfo(
"Alignment") <<
"@SUB=PedeSteererWeakModeConstraints"
226 <<
"No sub-components for "
228 <<
"at (" << (*iHLS).first->globalPosition().x() <<
","<< (*iHLS).first->globalPosition().y() <<
"," << (*iHLS).first->globalPosition().z() <<
") "
229 <<
"selected. Skip constraint";
231 if(aliDaughts.size() == 0) {
232 edm::LogWarning(
"Alignment") <<
"@SUB=PedeSteererWeakModeConstraints::createAlignablesDataStructure"
233 <<
"No active sub-alignables found for "
235 <<
" at (" << (*iHLS).first->globalPosition().x() <<
","<< (*iHLS).first->globalPosition().y() <<
"," << (*iHLS).first->globalPosition().z() <<
").";
249 const double r = TMath::Sqrt(pos.
x() * pos.
x() + pos.
y() * pos.
y());
251 switch(sysdeformation) {
252 case SystematicDeformations::kTwist:
255 case SystematicDeformations::kZexpansion:
258 case SystematicDeformations::kSagitta:
261 case SystematicDeformations::kRadial:
264 case SystematicDeformations::kTelescope:
267 case SystematicDeformations::kLayerRotation:
270 case SystematicDeformations::kBowing:
271 x = pos.
z() * pos.
z();
273 case SystematicDeformations::kElliptical:
274 x = r * TMath::Cos(2.0 * pos.
phi() + phase);
276 case SystematicDeformations::kSkew:
277 x = TMath::Cos(pos.
phi() + phase);
290 const int iParameter,
const double &x0,
291 const std::vector<double> &constraintparameters)
const
295 if(iParameter < 0 || iParameter > 2) {
297 <<
"[PedeSteererWeakModeConstraints::getCoefficient]" <<
" iParameter has to be in the range [0,2] but"
298 <<
" it is equal to " << iParameter <<
".";
303 const std::vector<double> vec_u = boost::assign::list_of(pos.
x() - gUDirection.
x())(pos.
y() - gUDirection.
y())(pos.
z() - gUDirection.
z());
304 const std::vector<double> vec_v = boost::assign::list_of(pos.
x() - gVDirection.
x())(pos.
y() - gVDirection.
y())(pos.
z() - gVDirection.
z());
305 const std::vector<double> vec_w = boost::assign::list_of(pos.
x() - gWDirection.
x())(pos.
y() - gWDirection.
y())(pos.
z() - gWDirection.
z());
308 const std::vector<std::vector<double> > global_vecs = boost::assign::list_of(vec_u)(vec_v)(vec_w);
310 const double n = TMath::Sqrt( global_vecs.at(iParameter).at(0) * global_vecs.at(iParameter).at(0)
311 + global_vecs.at(iParameter).at(1) * global_vecs.at(iParameter).at(1)
312 + global_vecs.at(iParameter).at(2) * global_vecs.at(iParameter).at(2) );
313 const double r = TMath::Sqrt( pos.
x() * pos.
x() + pos.
y() * pos.
y() );
315 const double phase = this->
getPhase(constraintparameters);
317 const std::vector<double> radial_direction = boost::assign::list_of(TMath::Sin(phase))(TMath::Cos(phase))(0.0);
319 const double norm_radial_direction = TMath::Sqrt(radial_direction.at(0) * radial_direction.at(0)
320 + radial_direction.at(1) * radial_direction.at(1)
321 + radial_direction.at(2) * radial_direction.at(2));
324 const std::vector<double> phi_direction = boost::assign::list_of(-1.0 * pos.
y())(pos.
x())(0.0);
325 const double norm_phi_direction = TMath::Sqrt(phi_direction.at(0) * phi_direction.at(0)
326 + phi_direction.at(1) * phi_direction.at(1)
327 + phi_direction.at(2) * phi_direction.at(2));
330 static const std::vector<double> z_direction = boost::assign::list_of(0.0)(0.0)(1.0);
331 const double norm_z_direction = TMath::Sqrt(z_direction.at(0)*z_direction.at(0)
332 + z_direction.at(1)*z_direction.at(1)
333 + z_direction.at(2)*z_direction.at(2));
336 const std::vector<double> rDirection = boost::assign::list_of(pos.
x())(pos.
y())(0.0);
337 const double norm_rDirection = TMath::Sqrt(rDirection.at(0) * rDirection.at(0)
338 + rDirection.at(1) * rDirection.at(1)
339 + rDirection.at(2) * rDirection.at(2));
342 double dot_product = 0.0;
343 double normalisation_factor = 1.0;
346 if(sysdeformation == SystematicDeformations::kTwist
347 || sysdeformation == SystematicDeformations::kLayerRotation) {
348 dot_product = phi_direction.at(0) * global_vecs.at(iParameter).at(0)
349 + phi_direction.at(1) * global_vecs.at(iParameter).at(1)
350 + phi_direction.at(2) * global_vecs.at(iParameter).at(2);
351 normalisation_factor = r * n * norm_phi_direction;
352 }
else if(sysdeformation == SystematicDeformations::kZexpansion
353 || sysdeformation == SystematicDeformations::kTelescope
354 || sysdeformation == SystematicDeformations::kSkew) {
355 dot_product = global_vecs.at(iParameter).at(0) * z_direction.at(0)
356 + global_vecs.at(iParameter).at(1) * z_direction.at(1)
357 + global_vecs.at(iParameter).at(2) * z_direction.at(2);
358 normalisation_factor = ( n * norm_z_direction);
359 }
else if(sysdeformation == SystematicDeformations::kRadial
360 || sysdeformation == SystematicDeformations::kBowing
361 || sysdeformation == SystematicDeformations::kElliptical) {
362 dot_product = global_vecs.at(iParameter).at(0) * rDirection.at(0)
363 + global_vecs.at(iParameter).at(1) * rDirection.at(1)
364 + global_vecs.at(iParameter).at(2) * rDirection.at(2);
365 normalisation_factor = ( n * norm_rDirection);
366 }
else if(sysdeformation == SystematicDeformations::kSagitta) {
367 dot_product = global_vecs.at(iParameter).at(0) * radial_direction.at(0)
368 + global_vecs.at(iParameter).at(1) * radial_direction.at(1)
369 + global_vecs.at(iParameter).at(2) * radial_direction.at(2);
370 normalisation_factor = ( n * norm_radial_direction);
374 coeff = dot_product * ( this->
getX(sysdeformation,pos,phase) - x0 ) / normalisation_factor;
377 <<
"[PedeSteererWeakModeConstraints::getCoefficient]" <<
" Normalisation factor"
378 <<
"for coefficient calculation equal to zero! Misconfiguration?";
386 bool isselected =
false;
390 || (iParameter >= 9 && iParameter <=11)) {
391 if(!aliSel.at(iParameter)) {
399 <<
"[PedeSteererWeakModeConstraints::checkSelectionShiftParameter]"
400 <<
" Can not access selected alignment variables of alignable "
403 <<
"for parameter number " << (iParameter+1) <<
".";
406 const char selChar = (selVar ? selVar->
fullSelection().at(iParameter) :
'1');
422 for(std::map<std::string, std::ofstream*>::iterator iFile = it->mapFileName_.begin();
423 iFile != it->mapFileName_.end(); iFile++) {
425 delete iFile->second;
428 <<
"[PedeSteererWeakModeConstraints]" <<
" can not close file " << iFile->first <<
".";
436 const std::list<GeometryConstraintConfigData>::const_iterator &it,
Alignable* iHLS,
double sum_xi_x0)
442 for(std::vector<std::pair<Alignable*, std::string> >::const_iterator ilevelsFilename = it->levelsFilenames_.begin();
443 ilevelsFilename != it->levelsFilenames_.end(); ilevelsFilename++) {
444 if((*ilevelsFilename).first->id() == iHLS->
id() && (*ilevelsFilename).first->alignableObjectId() == iHLS->
alignableObjectId()) {
446 std::map<std::string, std::ofstream*>::const_iterator iFile = it->mapFileName_.find((*ilevelsFilename).second);
447 if(iFile != it->mapFileName_.end()) {
448 ofile = (*iFile).second;
455 <<
"[PedeSteererWeakModeConstraints]" <<
" Can not find output file.";
458 const double constr = sum_xi_x0 * it->coefficients_.front();
459 (*ofile) <<
"Constraint " << std::scientific << constr << std::endl;
460 for(
std::list<std::pair<unsigned int,double> >::const_iterator ioutput =
output.begin();
461 ioutput !=
output.end(); ioutput++) {
462 (*ofile) << std::fixed << ioutput->first <<
" " << std::scientific << ioutput->second << std::endl;
470 std::list<GeometryConstraintConfigData>::iterator &it)
472 double nmodules = 0.0;
475 for(std::list<Alignable*>::iterator iAlignables = iHLS->second.begin();
476 iAlignables != iHLS->second.end(); iAlignables++) {
480 bool alignableIsFloating =
false;
483 for(
unsigned int iParameter = 0;
486 alignableIsFloating =
true;
491 <<
"@SUB=PedeSteererWeakModeConstraints::ConstructConstraints"
492 <<
" Weak mode constraints are only supported for alignables which have"
493 <<
" just one label. However, e.g. alignable"
496 <<
" was configured to have >1 label. Remove e.g. IOV-dependence for this (and other) alignables which are used in the constraint.";
502 if(alignableIsFloating) {
503 const double phase = this->
getPhase(it->coefficients_);
505 x0 += this->
getX(it->sysdeformation_,pos,phase);
509 x0 += this->
getX(it->sysdeformation_,sensorpositions.first,phase) + this->
getX(it->sysdeformation_,sensorpositions.second,phase);
518 throw cms::Exception(
"Alignment") <<
"@SUB=PedeSteererWeakModeConstraints::ConstructConstraints"
519 <<
" Number of selected modules equal to zero. Check configuration!";
541 for(
std::list<std::pair<
Alignable*, std::list<Alignable*> > >::iterator iHLS = it->HLSsubdets_.begin();
542 iHLS != it->HLSsubdets_.end(); iHLS++) {
543 double sum_xi_x0 = 0.0;
544 std::list<std::pair<unsigned int,double> >
output;
546 const double x0 = this->
getX0(iHLS, it);
548 for(std::list<Alignable*>::const_iterator iAlignables = iHLS->second.begin();
549 iAlignables != iHLS->second.end(); iAlignables++) {
555 lVDirection(0.,1.,0.),
556 lWDirection(0.,0.,1.);
559 gVDirection = surface.
toGlobal(lVDirection),
560 gWDirection = surface.
toGlobal(lWDirection);
564 const std::pair<align::GlobalPoint, align::GlobalPoint> sensorpositions =
569 const double phase = this->
getPhase(it->coefficients_);
570 const double x_sensor0 = this->
getX(it->sysdeformation_,pos_sensor0,phase);
571 const double x_sensor1 = isDoubleSensor ? this->
getX(it->sysdeformation_,pos_sensor1,phase) : 0.0;
573 sum_xi_x0 += ( x_sensor0 - x0 ) * ( x_sensor0 - x0 );
575 sum_xi_x0 += ( x_sensor1 - x0 ) * ( x_sensor1 - x0 );
579 for(
int iParameter = 0; iParameter < numparameterlimit; iParameter++) {
581 if(iParameter == 0 || iParameter == 9)
583 if(iParameter == 1 || iParameter == 10)
585 if(iParameter == 2 || iParameter == 11)
588 if((iParameter >= 0 && iParameter <= 2)
589 || (iParameter >= 9 && iParameter <=11)) {
601 if(iParameter == 0 || iParameter == 1 || iParameter == 2
602 || iParameter == 9 || iParameter == 10 || iParameter == 11) {
615 <<
"@SUB=PedeSteererWeakModeConstraints::getCoefficient"
616 <<
"Coefficient of alignable "
620 <<
" for parameter " << localindex <<
" equal to zero. This alignable is used in the constraint"
621 <<
" '" << it->constraintName_ <<
"'. The id is: alignable->geomDetId().rawId() = "
624 output.push_back(std::make_pair (paramLabel, coeff));
631 this->
writeOutput(output, it, (*iHLS).first, sum_xi_x0);
656 for ( std::vector<std::string>::const_iterator iParam = parameterNames.begin();
657 iParam != parameterNames.end(); ++iParam) {
660 name !=
"coefficients"
661 && name !=
"deadmodules" && name !=
"constraint"
662 && name !=
"steerFilePrefix" && name !=
"levels"
663 && name !=
"excludedAlignables"
666 <<
"@SUB=PedeSteererWeakModeConstraints::verifyParameterNames:"
667 <<
" Unknown parameter name '" << name <<
"' in PSet number " << psetnr <<
". Maybe a typo?";
674 std::set<std::string> &steerFilePrefixContainer,
675 const std::vector<Alignable*> &alis,
680 if(steerFilePrefixContainer.find(steerFilePrefix) != steerFilePrefixContainer.end()) {
681 throw cms::Exception(
"BadConfig") <<
"[PedeSteererWeakModeConstraints] Steering file"
682 <<
" prefix '" << steerFilePrefix <<
"' already exists. Specify unique names!";
684 steerFilePrefixContainer.insert(steerFilePrefix);
687 std::vector<std::pair<Alignable*, std::string> > levelsFilenames;
688 for(std::vector<Alignable*>::const_iterator it = alis.begin(); it != alis.end(); ++it) {
692 <<
"_" << (*it)->id() <<
"_" << (*it)->alignableObjectId() <<
".txt";
694 levelsFilenames.push_back(std::make_pair((*it),n.str()));
696 return levelsFilenames;
704 if(name ==
"twist") {
705 sysdeformation = SystematicDeformations::kTwist;
706 }
else if(name ==
"zexpansion") {
707 sysdeformation = SystematicDeformations::kZexpansion;
708 }
else if(name ==
"sagitta") {
709 sysdeformation = SystematicDeformations::kSagitta;
710 }
else if(name ==
"radial") {
711 sysdeformation = SystematicDeformations::kRadial;
712 }
else if(name ==
"telescope") {
713 sysdeformation = SystematicDeformations::kTelescope;
714 }
else if(name ==
"layerrotation") {
715 sysdeformation = SystematicDeformations::kLayerRotation;
716 }
else if(name ==
"bowing") {
717 sysdeformation = SystematicDeformations::kBowing;
718 }
else if(name ==
"skew") {
719 sysdeformation = SystematicDeformations::kSkew;
720 }
else if(name ==
"elliptical") {
721 sysdeformation = SystematicDeformations::kElliptical;
726 <<
"[PedeSteererWeakModeConstraints]" <<
" specified configuration option '"
727 << name <<
"' not known.";
729 if((sysdeformation == SystematicDeformations::kSagitta
730 || sysdeformation == SystematicDeformations::kElliptical
731 || sysdeformation == SystematicDeformations::kSkew) && coefficients.size() != 2) {
733 <<
"[PedeSteererWeakModeConstraints]" <<
" Excactly two parameters using the coefficient"
734 <<
" variable have to be provided for the " << name <<
" constraint.";
736 if((sysdeformation == SystematicDeformations::kTwist
737 || sysdeformation == SystematicDeformations::kZexpansion
738 || sysdeformation == SystematicDeformations::kTelescope
739 || sysdeformation == SystematicDeformations::kLayerRotation
740 || sysdeformation == SystematicDeformations::kRadial
741 || sysdeformation == SystematicDeformations::kBowing) && coefficients.size() != 1) {
743 <<
"[PedeSteererWeakModeConstraints]" <<
" Excactly ONE parameter using the coefficient"
744 <<
" variable have to be provided for the " << name <<
" constraint.";
747 if(coefficients.size() == 0) {
749 <<
"[PedeSteererWeakModeConstraints]" <<
" At least one coefficient has to be specified.";
751 return sysdeformation;
758 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
virtual unsigned int alignableLabel(Alignable *alignable) const =0
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.
unsigned int constructConstraints(const std::vector< Alignable * > &alis)
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
double getX0(std::list< std::pair< Alignable *, std::list< Alignable * > > >::iterator &iHLS, std::list< GeometryConstraintConfigData >::iterator &it)
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_
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
void clear()
remove all selected Alignables and geometrical restrictions
const std::vector< char > & fullSelection() const
~PedeSteererWeakModeConstraints()
void writeOutput(const std::list< std::pair< unsigned int, double > > &output, const std::list< GeometryConstraintConfigData >::const_iterator &it, Alignable *iHLS, double sum_xi_x0)
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
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
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 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)
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 PedeLabelerBase * myLabels_
Alignable * mother() const
Return pointer to container alignable (if any)
const DetId & geomDetId() const
virtual unsigned int numberOfParameterInstances(Alignable *alignable, int param=-1) const =0
returns the number of instances for a given parameter
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