Project

General

Profile

Feature #624

TransferMap cleanup

Added by Rogers, Chris about 10 years ago. Updated over 9 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Optics
Target version:
Start date:
05 August 2011
Due date:
01 January 2012
% Done:

100%

Estimated time:
Workflow:
Closed

Description

Place I want Peter to look at is the TransferMap class

src/legacy/Optics/TransferMap.*

This is responsible for making a polynomial mapping from z0 to z1. Wraps the general PolynomialVector class (which does mapping of some vector of x1,x2,x3... to y1,y2,y3,...) and specialises to mapping
(x,px,y,py,t,energy) at input to (x,px,y,py,t,energy) at output. PolynomialVector is at src/legacy/Interface/PolynomialVector.*.

Includes method for transporting PhaseSpaceVector object (particle position/momentum) and CovarianceMatrix object (beam envelope).

At the moment there is a sort of mix of code, either we take a mapping from a CLHEP::HepMatrix to do first order mapping (x_out = const*x_in) and a tensor object to do higher order mapping (x_out = const*x_in*x_in, etc). Or we take a PolynomialVector to do mapping at all orders.

We need to get rid of the CLHEP::HepMatrix/Tensor way, this was not the right way to implement the code (my fault). Then add some documentation
and tests according to the new C++ style guide.

Peter will probably want to have a look at the code then ask some questions. Once he has an account on micemine I can assign as an issue.


Related issues

Related to MAUS - Feature #66: Optics refactorClosedLane, Peter26 May 201101 January 2012

Actions
#1

Updated by Rogers, Chris about 10 years ago

Part of email fomr Peter:

I'm still trying to figure out what the code is doing and what exactly is obsolete. Any details along these lines would be much appreciated.

Response:

I added some overview documentation on what the optics is doing to #66.

So the job is to delete the following member data:-
HepMatrix _firstOrderMap;
Tensor3 _secondOrderMap;
std::vector<Tensor*> _higherOrderMaps;
OpticsModel* _optics;
static int _order;
bool _canonicalMap;

The fundamental functionality that I really want to keep alive:-
CovarianceMatrix operator*(const CovarianceMatrix& aCovMatrix) const;
PhaseSpaceVector operator*(const PhaseSpaceVector& aPhaseSpaceVector) const;

Mark any functions that get broken as deprecated (anything that talks to Tensor, Tensor3, HepMatrix); they should raise an exception if they are called:-
TransferMap(HepMatrix firstOrderMap, PhaseSpaceVector referenceIn, PhaseSpaceVector referenceOut, OpticsModel* Optics);
TransferMap(HepMatrix transverseMap, HepMatrix longitudinalMap, PhaseSpaceVector referenceIn, PhaseSpaceVector referenceOut, OpticsModel* Optics);
TransferMap(PhaseSpaceVector referenceIn, OpticsModel* Optics);

void SetFirstOrderMap(const HepMatrix transverseMap, const HepMatrix longitudinalMap);
void SetFirstOrderMap(const HepMatrix firstOrderMap);
void SetSecondOrderMap(Tensor3 secondOrderMap) {_secondOrderMap = secondOrderMap;}
void SetReferenceOutZ(double z) {_referenceTrajectoryOut.setZ(z);}
void IncrementReferenceOutZ(double dz) {SetReferenceOutZ(_referenceTrajectoryOut.z()+dz);}
void SetOpticsModel(OpticsModel* optics) {_optics = optics;}
HepMatrix GetTransverseMap()   const {return _firstOrderMap.sub(3,6,3,6);}
HepMatrix GetLongitudinalMap() const {return _firstOrderMap.sub(1,2,1,2);}
//Accessor for second and higher order maps
Tensor3 GetSecondOrderMap() const {return _secondOrderMap;}
Tensor GetMap(int order) const;
bool IsCanonical() {return _canonicalMap;}
bool IsCanonical(bool can) {_canonicalMap = can; return _canonicalMap;}
//order
static void SetOrder(int order) {_order = order;}
static int GetOrder() {return _order;}

You probably want to keep the function for now, so that you don't have to go into any other stuff. Then make sure it is possible to do cpplint and get no errors. Then add tests for any functions that survive the cull and are not marked as deprecated (so, add tests in tests/cpp_unit/Optics).

#2

Updated by Rogers, Chris almost 10 years ago

  • Due date set to 01 January 2012
#3

Updated by Lane, Peter almost 10 years ago

I made all of the deprecation changes and had it compiling at one point. I don't understand how TransferMap is supposed to operate on CovarianceMatrix or PhaseSpaceVector without using GetFirstOrderMap (which uses HepMatrix and, as I understand, should be deprecated). Feedback would be appreciated.

I am fixing up CovarianceMatrix right now (issue #477) since part of the essential functionality of TransferMap uses CovarianceMatrix and I'm stuck on TransferMap.

I think I've figured out the data card stuff and found the Optics.cc test app in tests/integration/test_optics/. That means I at least should be able to create a valid CovarianceMatrix soon for testing with TransferMap.

I'm still not sure how to create a valid TransferMap with appropriate reference trajectories. I'm also not sure how to tell if TransferMap is working correctly (i.e. what valid output would be from TransferMap operating on a CovarianceMatrix or PhaseSpaceVector).

Chris R., you said not to test matrix multiplication, but I don't see how I can test anything without doing some sort of multiplication. After all, that's basically all TransferMap is supposed to do now. Comments?

#4

Updated by Lane, Peter almost 10 years ago

  • Workflow set to New Issue

I have committed TransferMap unit tests in my dev branch under cpp_unit/Optics.

One test case transports a PhaseSpaceVector using a first-order PolynomialVector that represents a reflection about the 6-D origin. I don't think I need to do anything more complicated with this since PolynomialVector is tested separately.

The other test case transports a CovarianceMatrix using a first-order PolynomialVector. I looked into arbitrary order transport, but the mathematics seem to suggest I need a representation of the covariance matrix of dimension equal to that of the polynomial vector. I'm not sure where to go with that.

To complete this work I created new templated (for double and gsl_complex) Matrix and Vector classes that are based off of MMatrix and MVector. I pulled the complex operator stuff out of MVector, cleaned it up, and put it in a seperate set of source files (Complex.*). I also created a SymmetricMatrix class based off of HepSymMatrix which is a subclass of Matrix<double>. The CovarianceMatrix class, furthermore, is now a subclass of SymmetricMatrix. Also, PhaseSpaceVector is now a subclass of Vector<double>.

I still have to correct some cpplint issues and figure out where to put the cleaned up and new code. Right now it's all still in legacy/...

#5

Updated by Lane, Peter over 9 years ago

I moved the new vector and matrix classes to common_cpp/Maths. I moved the new CovarianceMatrix, PhaseSpaceVector, and TransferMap classes in common_cpp/Optics. I resolved all of the cpplint errors for these classes except some which aren't valid. I removed MVector and MMatrix and updated all classes that used these to use the new classes.

I also moved PolynomialVector into Maths, but I largely left this unchanged and did not attempt to fix any cpplint errors. I should probably do that at some point, but I'll shift that off onto issue #66. I suppose some supporting files such Interpolator should have been moved as well (more #66 tasks I guess).

#6

Updated by Lane, Peter over 9 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

TransferMap has been cleaned up and unit tests have been added to cpp_unit/Optics. A merge to the trunk should commence shortly.

#7

Updated by Rogers, Chris over 9 years ago

  • Status changed from Closed to Open
  • % Done changed from 100 to 0
  • Workflow changed from New Issue to Under Test

Bumped back to in test until coverage is a bit higher

#8

Updated by Lane, Peter over 9 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

Unit test coverage is above 80%. Closing.

#9

Updated by Rogers, Chris over 9 years ago

  • Target version changed from Future MAUS release to MAUS-v0.1.4
  • Workflow changed from Under Test to Closed

Also available in: Atom PDF