Skip to content

Commit

Permalink
Merge pull request #17475 from ghellwig/allow_multi-iov_millepede_90X
Browse files Browse the repository at this point in the history
[90X] Allow multi-IOV input for Millepede alignment framework
  • Loading branch information
cmsbuild committed Mar 14, 2017
2 parents 7da5de9 + ffa383d commit 937a0f7
Show file tree
Hide file tree
Showing 53 changed files with 1,640 additions and 641 deletions.
1 change: 1 addition & 0 deletions Alignment/CommonAlignment/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<export>
<lib name="1"/>
</export>
<use name="CondCore/CondDB"/>
<use name="DataFormats/GeometrySurface"/>
<use name="DataFormats/GeometryVector"/>
<use name="DataFormats/TrackingRecHit"/>
Expand Down
33 changes: 28 additions & 5 deletions Alignment/CommonAlignment/interface/Alignable.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "Alignment/CommonAlignment/interface/AlignableSurface.h"
#include "Alignment/CommonAlignment/interface/StructureType.h"
#include "Alignment/CommonAlignment/interface/Utilities.h"
#include "DataFormats/DetId/interface/DetId.h"

class AlignmentErrorsExtended;
Expand All @@ -18,9 +19,6 @@ class SurfaceDeformation;
* Any Alignable object can be moved and rotated.
* Also an alignment uncertainty can be set.
*
* $Date: 2011/09/19 11:42:35 $
* $Revision: 1.36 $
* (last update by $Author: mussgill $)
*/

class AlignmentParameters;
Expand All @@ -39,6 +37,8 @@ class Alignable
typedef align::Alignables Alignables;
typedef align::StructureType StructureType;

enum class CompConstraintType { NONE, POSITION, POSITION_Z };

/// Constructor from id and surface, setting also geomDetId
/// (AlignableNavigator relies on the fact that only AlignableDet/DetUnit have geomDetId!)
Alignable( align::ID, const AlignableSurface& );
Expand All @@ -50,6 +50,10 @@ class Alignable
/// Destructor
virtual ~Alignable();

/// Updater using id and surface.
/// The given id has to match the current id.
void update(align::ID, const AlignableSurface&);

/// Set the AlignmentParameters
void setAlignmentParameters( AlignmentParameters* dap );

Expand Down Expand Up @@ -184,6 +188,9 @@ class Alignable
/// Return the ID of Alignable, i.e. DetId of 'first' component GeomDet(Unit).
align::ID id() const { return theId; }

/// Return the alignable type of contraints wrt. its components
virtual CompConstraintType compConstraintType() const { return compConstraintType_; }

/// Recursive printout of alignable information
virtual void dump() const = 0;

Expand All @@ -203,21 +210,30 @@ class Alignable
/// cache the current position, rotation and other parameters (e.g. surface deformations), also for possible components
virtual void cacheTransformation();

/// cache for the given run the current position, rotation and other
/// parameters (e.g. surface deformations), also for possible components
virtual void cacheTransformation(const align::RunNumber&);

/// restore the previously cached transformation, also for possible components
virtual void restoreCachedTransformation();

/// restore for the given run the previously cached transformation, also for
/// possible components
virtual void restoreCachedTransformation(const align::RunNumber&);

/// Return survey info
const SurveyDet* survey() const { return theSurvey; }

/// Set survey info
void setSurvey( const SurveyDet* );

protected:
template<class T>
using Cache = std::map<align::RunNumber, T>;

void addDisplacement( const GlobalVector& displacement );
void addRotation( const RotationType& rotation );

protected:
virtual void updateMother(const GlobalVector& shift);

DetId theDetId; // used to check if Alignable is associated to a GeomDet
// ugly way to keep AlignableNavigator happy for now
Expand All @@ -233,10 +249,17 @@ class Alignable
GlobalVector theCachedDisplacement;
RotationType theCachedRotation;

CompConstraintType compConstraintType_{CompConstraintType::NONE};

Alignables theDeepComponents; // list of lowest daughters
// contain itself if Alignable is a unit

Cache<AlignableSurface> surfacesCache_;
Cache<GlobalVector> displacementsCache_;
Cache<RotationType> rotationsCache_;

private:

/// private default ctr. to enforce usage of the specialised ones
Alignable() {};

Expand Down
3 changes: 3 additions & 0 deletions Alignment/CommonAlignment/interface/AlignableBeamSpot.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class AlignableBeamSpot : public Alignable
void initialize(double x, double y, double z,
double dxdz, double dydz);

/// reset beam spot to the uninitialized state
void reset();

/// returns the DetId corresponding to the alignable beam spot. Also used
/// by BeamSpotGeomDet and BeamSpotTransientTrackingRecHit
static const DetId detId() { return DetId((DetId::Tracker<<DetId::kDetOffset)+0x1ffffff); }
Expand Down
13 changes: 13 additions & 0 deletions Alignment/CommonAlignment/interface/AlignableComposite.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class AlignableComposite : public Alignable
/// deleting its components
virtual ~AlignableComposite();

/// Updater for a composite with given rotation.
/// The given id and structure type have to match the current ones.
void update(align::ID,
StructureType aType,
const RotationType& rot = RotationType());

/// Add a component and set its mother to this alignable.
/// (Note: The component will be adopted, e.g. later deleted.)
/// Also find average position of this composite from its modules' positions.
Expand Down Expand Up @@ -101,6 +107,13 @@ class AlignableComposite : public Alignable
/// Constructor from GeomDet, only for use in AlignableDet
explicit AlignableComposite( const GeomDet* geomDet );

/// Updater from GeomDet, only for use in AlignableDet
/// The given GeomDetUnit id has to match the current id.
void update(const GeomDet* geomDet);

// avoid implicit cast of not explicitely defined version to the defined ones
template<class T> void update(T) = delete;

void setSurface( const AlignableSurface& s) { theSurface = s; }

StructureType theStructureType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class AlignableCompositeBuilder {
/// - TPBHalfBarrel (with TPBLayer as children)
/// - TPBBarrel (with TPBHalfBarrel as children)
/// Returns the number of composite Alignables which were built.
unsigned int buildAll(AlignableMap&);
unsigned int buildAll(AlignableMap&, bool update = false);

/// Return tracker alignable object ID provider derived from the tracker's geometry
const AlignableObjectId& objectIdProvider() const { return alignableObjectId_; }
Expand All @@ -49,7 +49,7 @@ class AlignableCompositeBuilder {

/// Builds the components for a given level in the hierarchy.
unsigned int buildLevel(unsigned int parentLevel, AlignableMap&,
std::ostringstream&);
std::ostringstream&, bool update = false);

/// Calculates the theoretical max. number of components for a given level
/// in the hierarchy.
Expand Down
4 changes: 4 additions & 0 deletions Alignment/CommonAlignment/interface/AlignableDet.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class AlignableDet: public AlignableComposite
/// Destructor
virtual ~AlignableDet();

/// Updater from GeomDet
/// The given GeomDet id has to match the current id.
void update(const GeomDet* geomDet, bool updateComponents = true);

/// Set the AlignmentPositionError and, if (propagateDown), to all components
virtual void setAlignmentPositionError(const AlignmentPositionError &ape, bool propagateDown);

Expand Down
11 changes: 11 additions & 0 deletions Alignment/CommonAlignment/interface/AlignableDetUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class AlignableDetUnit : public Alignable
/// Destructor
virtual ~AlignableDetUnit();

/// Updater from GeomDetUnit
/// The given GeomDetUnit id has to match the current id.
void update(const GeomDetUnit* geomDetUnit);

/// No components here => exception!
virtual void addComponent( Alignable* );

Expand Down Expand Up @@ -76,9 +80,15 @@ class AlignableDetUnit : public Alignable
/// cache the current position, rotation and other parameters (e.g. surface deformations)
virtual void cacheTransformation();

/// cache for the given run the current position, rotation and other parameters (e.g. surface deformations)
virtual void cacheTransformation(const align::RunNumber&);

/// restore the previously cached transformation
virtual void restoreCachedTransformation();

/// restore for the given run the previously cached transformation
virtual void restoreCachedTransformation(const align::RunNumber&);

/// alignment position error - for checking only, otherwise use alignmentErrors() above!
const AlignmentPositionError* alignmentPositionError() const { return theAlignmentPositionError;}

Expand All @@ -87,6 +97,7 @@ class AlignableDetUnit : public Alignable
AlignmentPositionError* theAlignmentPositionError;
SurfaceDeformation* theSurfaceDeformation;
SurfaceDeformation* theCachedSurfaceDeformation;
Cache<SurfaceDeformation*> surfaceDeformationsCache_;
};

#endif
3 changes: 3 additions & 0 deletions Alignment/CommonAlignment/interface/AlignableExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class AlignableExtras
void initializeBeamSpot(double x, double y, double z,
double dxdz, double dydz);

/// Initialize the alignable beam spot with the given parameters
void resetBeamSpot();

private:

AlignableMap alignableLists_; //< kind of map of lists of alignables
Expand Down
13 changes: 12 additions & 1 deletion Alignment/CommonAlignment/interface/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
#include <map>
#include <memory>

#include "CondCore/CondDB/interface/Time.h"
#include "CondFormats/Alignment/interface/Definitions.h"
#include "Alignment/CommonAlignment/interface/AlignableObjectId.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

class Alignable;
class AlignmentParameters;
Expand All @@ -33,6 +34,10 @@ namespace align

typedef std::map<std::pair<Alignable*, Alignable*>, AlgebraicMatrix> Correlations;

using RunNumber = cond::RealTimeType<cond::runnumber>::type;
using RunRange = std::pair<RunNumber, RunNumber>;
using RunRanges = std::vector<RunRange>;

/// Convert rotation matrix to angles about x-, y-, z-axes (frame rotation).
EulerAngles toAngles(
const RotationType&
Expand Down Expand Up @@ -70,6 +75,12 @@ namespace align
void rectify(
RotationType&
);


RunRanges makeNonOverlappingRunRanges(const edm::VParameterSet& runRanges,
const RunNumber& defaultRun);
RunRanges makeUniqueRunRanges(const edm::VParameterSet& runRanges,
const RunNumber& defaultRun);
}

#endif
77 changes: 75 additions & 2 deletions Alignment/CommonAlignment/src/Alignable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,25 @@ Alignable::~Alignable()
delete theSurvey;
}

//__________________________________________________________________________________________________
void Alignable::update(align::ID id, const AlignableSurface& surf)
{
if (theId != id) {
throw cms::Exception("Alignment")
<< "@SUB=Alignable::update\n"
<< "Current alignable ID does not match ID of the update.";
}
const auto shift = surf.position() - theSurface.position();
theSurface = surf;

// reset displacement and rotations after update
theDisplacement = GlobalVector();
theRotation = RotationType();

// recalculate containing composite's position
updateMother(shift);
}

//__________________________________________________________________________________________________
bool Alignable::firstCompsWithParams(Alignables &paramComps) const
{
Expand Down Expand Up @@ -269,7 +288,7 @@ AlignmentSurfaceDeformations* Alignable::surfaceDeformations( void ) const
return allSurfaceDeformations;

}

void Alignable::cacheTransformation()
{
// first treat itself
Expand All @@ -286,6 +305,18 @@ void Alignable::cacheTransformation()

}

void Alignable::cacheTransformation(const align::RunNumber& run)
{
// first treat itself
surfacesCache_[run] = theSurface;
displacementsCache_[run] = theDisplacement;
rotationsCache_[run] = theRotation;

// now treat components (a clean design would move that to AlignableComposite...)
const Alignables comps(this->components());
for (auto& it: comps) it->cacheTransformation(run);
}

void Alignable::restoreCachedTransformation()
{
// first treat itself
Expand All @@ -294,14 +325,33 @@ void Alignable::restoreCachedTransformation()
theRotation = theCachedRotation;

// now treat components (a clean design would move that to AlignableComposite...)
const Alignables comps(this->components());
const auto comps = this->components();

for (auto it = comps.begin(); it != comps.end(); ++it) {
(*it)->restoreCachedTransformation();
}

}

void Alignable::restoreCachedTransformation(const align::RunNumber& run)
{
if (surfacesCache_.find(run) == surfacesCache_.end()) {
throw cms::Exception("Alignment")
<< "@SUB=Alignable::restoreCachedTransformation\n"
<< "Trying to restore cached transformation for a run (" << run
<< ") that has not been cached.";
} else {
// first treat itself
theSurface = surfacesCache_[run];
theDisplacement = displacementsCache_[run];
theRotation = rotationsCache_[run];

// now treat components (a clean design would move that to AlignableComposite...)
const auto comps = this->components();
for (auto it: comps) it->restoreCachedTransformation();
}
}

//__________________________________________________________________________________________________
void Alignable::setSurvey( const SurveyDet* survey )
{
Expand All @@ -310,3 +360,26 @@ void Alignable::setSurvey( const SurveyDet* survey )
theSurvey = survey;

}

//______________________________________________________________________________
void Alignable::updateMother(const GlobalVector& shift) {

if (!theMother) return;

const auto thisComps = this->deepComponents().size();
const auto motherComps = theMother->deepComponents().size();
const auto motherShift = shift * static_cast<Scalar>(thisComps) / motherComps;

switch(theMother->compConstraintType()) {
case CompConstraintType::NONE:
break;
case CompConstraintType::POSITION_Z:
theMother->theSurface.move(GlobalVector(0,0, motherShift.z()));
theMother->updateMother(GlobalVector(0,0, motherShift.z()));
break;
case CompConstraintType::POSITION:
theMother->theSurface.move(motherShift);
theMother->updateMother(motherShift);
break;
}
}
10 changes: 10 additions & 0 deletions Alignment/CommonAlignment/src/AlignableBeamSpot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ AlignmentErrorsExtended* AlignableBeamSpot::alignmentErrors( void ) const
return m_alignmentErrors;
}

//______________________________________________________________________________
void AlignableBeamSpot::initialize(double x, double y, double z,
double dxdz, double dydz)
{
Expand All @@ -177,3 +178,12 @@ void AlignableBeamSpot::initialize(double x, double y, double z,

theInitializedFlag = true;
}

//______________________________________________________________________________
void AlignableBeamSpot::reset()
{
Alignable::update(this->id(), AlignableSurface());
delete theAlignmentPositionError;
theAlignmentPositionError = nullptr;
theInitializedFlag = false;
}

0 comments on commit 937a0f7

Please sign in to comment.