/* University College London Dept of P&A course in C/C++ 3C59 | all rights reserved 2000 | | Module: Consolidation excercise: | | Title: Compton Analysis | | Description: Main program to run the analysis | | | | Author: P.Clarke */ #include #include #include "Datum.h" #include "DataReader.h" #include "Minimiser.h" int main() { // First lets make an empty vector which can hold the Datums std::vector measurements ; // Now make a helper object which knows how to read the data from a file DataReader myReader ; // Use the reader to fill the measurements vector from a file measurements = myReader.readFromFile( "compton.dat") ; // Dump out the input set for verification for( int ind=0; ind < measurements.size() ; ++ind ) measurements[ind].dump() ; // Now we are ready to perform the minimisation loop // Set some initial parameters float initialMass = 450.0 ; float initialIncrement = 1.0 ; float convergenceLimit = 0.00001 ; // Make a minimiser and initialise it Minimiser massFitter ; massFitter.initialise( initialMass, initialIncrement, convergenceLimit ) ; // .......... // Start a minimisation loop which will terminate when the minimiser tells me to float chisq ; while( massFitter.stillGoing() ) { // Reset the chisqared chisq = 0. ; // Get a mass value for this iteration of the minimiser float mass = massFitter.currentParameter() ; // calculate the corresponding chisq for( ind=0; ind < measurements.size(); ++ind ) { chisq += measurements[ind].chiSquared( mass ) ; } // tell the minimiser the chisw massFitter.setChisq( chisq ) ; // Thats the end of the loop std::cout << "At end of loop the mass was " << mass << " and chisq " << chisq << std::endl; } // .......... // At this point we have finished and can print out the final value std::cout << "\n The best fit mass was: " << massFitter.currentParameter() << " with a chisq/df of " << chisq << "/" << measurements.size()-1 << std::endl ; return 1 ; }