I have started a migration of a high energy physics algorithm written in FORTRAN to an object oriented approach in C++. The FORTRAN code uses a lot of global variables all across a lot of functions.

I have simplified the global variables into a set of input variables, and a set of invariants (variables calculated once at the beginning of the algorithm and then used by all the functions).

Also, I have divided the full algorithm into three logical steps, represented by three different classes. So, in a very simple way, I have something like this:

double calculateFactor(double x, double y, double z)
{
    InvariantsTypeA invA();
    InvariantsTypeB invB();

    // they need x, y and z
    invA.CalculateValues();
    invB.CalculateValues();

    Step1 s1();
    Step2 s2();
    Step3 s3();

    // they need x, y, z, invA and invB
    return s1.Eval() + s2.Eval() + s3.Eval();
}

My problem is:

  • for doing the calculations all the InvariantsTypeX and StepX objects need the input parameters (and these are not just three).
  • the three objects s1, s2 and s3 need the data of the invA and invB objects.
  • all the classes use several other classes through composition to do their job, and all those classes also need the input and the invariants (by example, s1 has a member object theta of class ThetaMatrix that needs x, z and invB to get constructed).
  • I cannot rewrite the algorithm to reduce the global values, because it follows several high energy physics formulas, and those formulas are just like that.

Is there a good pattern to share the input parameters and the invariants to all the objects used to calculate the result?

Should I use singletons? (but the calculateFactor<

Edit
Report