00001 #include <fstream>
00002 #include <iostream>
00003 #include <iomanip>
00004 #include "utils.h"
00005 #include "cheezyparser.h"
00006 #include "parametermap.h"
00007 #include "sou1d_legendre.h"
00008 #include "sou1d_laguerre.h"
00009 #include "sou1d_hermite.h"
00010 #include "sou1d_chebyshev.h"
00011 #include "sou1d_histo.h"
00012 #include "sou1d_gauss.h"
00013 #include "sou1d_bsplines.h"
00014 #include "yasper.h"
00015 #include "bspline_imager1d.h"
00016 #include "basisfunc_imager1d.h"
00017 #include "sou3d_ylm.h"
00018 #include "corr3d_ylm.h"
00019 #include "corr3d_histo.h"
00020 #include "uncoupled_imager3d.h"
00021
00022
00023 void getHelp(void){
00024 cout<<"\nUsage: diver [mode] <input file>"<<endl;
00025 cout<<" To get this message, use \"-help\" "<<endl;
00026 cout<<" \"-bspline\" : Use Basis Spline basis for source"<<endl;
00027 cout<<" \"-chebyshev\" : Use Chebyshev polynomial basis for source"<<endl;
00028 cout<<" \"-hermite\" : Use Hermite polynomial basis for source"<<endl;
00029 cout<<" \"-histogram\" : Use Histogram basis for source"<<endl;
00030 cout<<" \"-laguerre\" : Use Laguerre polynomial basis for source"<<endl;
00031 cout<<" \"-legendre\" : Use Legendre polynomial basis for source"<<endl;
00032 cout<<" \"-3d\" : Perform a 3d imaging"<<endl;
00033 cout<<" \"-restore\" : Restore the correlation from the image for cross-checking the result"<<endl;
00034 exit(0);
00035 }
00036
00037
00038 int main( int argc, char* argv[] ){
00039 cout << "*** Demonstration InVERter: a CorAL imaging code ***"<<endl;
00040 cout << endl;
00041
00042
00043 if (argc==1) getHelp();
00044 vector<string> modeList;
00045 string inFile;
00046 bool got_file = false;
00047 bool three_d_problem = true;
00048 bool restore = false;
00049 for (int iarg = 1; iarg<argc; ++iarg){
00050 string sarg(argv[iarg]);
00051 if ( sarg == "-help" ) getHelp();
00052 if ( sarg == "-h" ) getHelp();
00053 if ( sarg == "--help" ) getHelp();
00054 if ( sarg == "-3d" or sarg == "-restore" ) {
00055 if ( sarg == "-3d" ) three_d_problem = true;
00056 if ( sarg == "-restore" ) restore = true;
00057 }
00058 else if ( sarg.substr(0,1) == "-" ) modeList.push_back(sarg);
00059 else {
00060 inFile = sarg;
00061 got_file = true;
00062 }
00063 }
00064 if ( !got_file ) throw MESSAGE << "No imput file specified. Halting!!"<<ENDM_FATAL;
00065 if ( !file_exists( inFile ) ) throw MESSAGE << "File "<< inFile <<" not found. Halting!!"<<ENDM_FATAL;
00066
00067
00068 parameterMap settings, input_correlation_settings, imaged_source_settings, restored_correlation_settings;
00069 parameter::ReadParsFromFile(settings, inFile);
00070 string correlation_filename = parameter::getS( settings, "correlation_file", "pion_correlation.dat" );
00071 string source_filename = parameter::getS( settings, "imaged_source_file", "imaged_source.dat" );
00072 string restored_correlation_filename = parameter::getS( settings, "restored_correlation_file", "restored_pion_correlation.dat" );
00073 parameter::ReadParsFromFile( input_correlation_settings, correlation_filename );
00074
00075 if ( three_d_problem ) {
00076
00077
00078 cout << "Reading 3d correlation ..."<<endl;
00079 CCorrFtn3dSphr corrin( "pi0", "pi0", false );
00080 corrin.Read( input_correlation_settings );
00081 corrin.readTerms();
00082 CCorrFtn3dSphr corrout( "pi0", "pi0", false );
00083 corrout.Read( input_correlation_settings );
00084 cout << endl;
00085
00086
00087 yasper::ptr< CGeneralImager3d > pImager;
00088 for ( vector<string>::iterator it=modeList.begin(); it!=modeList.end(); ++it ) {
00089 if ( *it == "-legendre" ) pImager = new UncoupledLegendrePolyImager3d;
00090 else if ( *it == "-bspline" ) pImager = new UncoupledBasisSplineImager3d;
00091 else if ( *it == "-laguerre" ) pImager = new UncoupledLaguerrePolyImager3d;
00092 else if ( *it == "-chebyshev" ) pImager = new UncoupledChebyshevPolyImager3d;
00093 else if ( *it == "-histogram" ) pImager = new UncoupledHistoImager3d;
00094 else if ( *it == "-hermite" ) pImager = new UncoupledHermitePolyImager3d;
00095 else MESSAGE<<"Unknown mode: '"<<*it<<ENDM_WARN;
00096 }
00097 pImager->Read( parameter::getMap( settings, "imager_settings" ) );
00098
00099
00100 CSourceFtn3dSphr< CSourceFtn1dLegendrePoly > sourceLeg;
00101 CSourceFtn3dSphr< CSourceFtn1dBSpline > sourceBsp;
00102 CSourceFtn3dSphr< CSourceFtn1dLaguerrePoly > sourceLag;
00103 CSourceFtn3dSphr< CSourceFtn1dChebyshevPoly > sourceChb;
00104 CSourceFtn3dSphr< CSourceFtn1dHisto > sourceHis;
00105 CSourceFtn3dSphr< CSourceFtn1dHermitePoly > sourceHer;
00106
00107
00108
00109 CSourceFtnBase* pSource;
00110 for ( vector<string>::iterator it=modeList.begin(); it!=modeList.end(); ++it ) {
00111 if ( *it == "-legendre" ) pSource = &sourceLeg;
00112 else if ( *it == "-bspline" ) pSource = &sourceBsp;
00113 else if ( *it == "-laguerre" ) pSource = &sourceLag;
00114 else if ( *it == "-chebyshev" ) pSource = &sourceChb;
00115 else if ( *it == "-histogram" ) pSource = &sourceHis;
00116 else if ( *it == "-hermite" ) pSource = &sourceHer;
00117 else MESSAGE<<"Unknown mode: '"<<*it<<ENDM_WARN;
00118 }
00119
00120 pSource->Read( parameter::getMap( settings, "source_settings" ) );
00121
00122
00123 pImager->convertCorrelationToSource( corrin, *pSource, settings );
00124
00125
00126 pSource->Write( imaged_source_settings );
00127
00128
00129
00130 for ( vector<string>::iterator it=modeList.begin(); it!=modeList.end(); ++it ) {
00131 if ( *it == "-legendre" ) sourceLeg.writeTerms();
00132 else if ( *it == "-bspline" ) sourceBsp.writeTerms();
00133 else if ( *it == "-laguerre" ) sourceLag.writeTerms();
00134 else if ( *it == "-chebyshev" ) sourceChb.writeTerms();
00135 else if ( *it == "-histogram" ) sourceHis.writeTerms();
00136 else if ( *it == "-hermite" ) sourceHer.writeTerms();
00137 else MESSAGE<<"Unknown mode: '"<<*it<<ENDM_WARN;
00138 }
00139
00140
00141 if ( restore ) {
00142 pImager->convertSourceToCorrelation( *pSource, corrout, settings );
00143 corrout.Write( restored_correlation_settings );
00144 corrout.writeTerms();
00145 }
00146
00147
00148
00149 }
00150 else {
00151 cout << "Reading 1d correlation ..."<<endl;
00152
00153 CCorrFtn1dHisto corrin( "pi0", "pi0", false );
00154 CCorrFtn1dHisto corrout( "pi0", "pi0", false );
00155 corrin.Read( input_correlation_settings );
00156 corrout.Read( input_correlation_settings );
00157
00158
00159 yasper::ptr< CSourceFtnBase > pSource;
00160 yasper::ptr< CBasisFuncImager1d > pImager;
00161 for ( vector<string>::iterator it=modeList.begin(); it!=modeList.end(); ++it ) {
00162 if ( *it == "-legendre" ) {
00163 pSource = new CSourceFtn1dLegendrePoly;
00164 pImager = new CBasisFuncImager1d;
00165 }
00166 else if ( *it == "-bspline" ) {
00167 pSource = new CSourceFtn1dBSpline;
00168 pImager = new CBasisSplineImager1d;
00169 }
00170 else if ( *it == "-laguerre" ) {
00171 pSource = new CSourceFtn1dLaguerrePoly;
00172 pImager = new CBasisFuncImager1d;
00173 }
00174 else if ( *it == "-chebyshev" ) {
00175 pSource = new CSourceFtn1dChebyshevPoly;
00176 pImager = new CBasisFuncImager1d;
00177 }
00178 else if ( *it == "-histogram" ) {
00179 pSource = new CSourceFtn1dHisto;
00180 pImager = new CBasisFuncImager1d;
00181 }
00182 else if ( *it == "-hermite" ) {
00183 pSource = new CSourceFtn1dHermitePoly;
00184 pImager = new CBasisFuncImager1d;
00185 }
00186 else MESSAGE<<"Unknown mode: '"<<*it<<ENDM_WARN;
00187 }
00188
00189
00190 pSource->Read( parameter::getMap( settings, "source_settings" ) );
00191 pImager->Read( parameter::getMap( settings, "imager_settings" ) );
00192
00193
00194 pImager->convertCorrelationToSource( corrin, *pSource, settings );
00195 if ( restore ) pImager->convertSourceToCorrelation( *pSource, corrout, settings );
00196
00197
00198 pSource->Write( imaged_source_settings );
00199 if ( restore ) corrout.Write( restored_correlation_settings );
00200 }
00201
00202
00203 parameter::WriteParsToFile( imaged_source_settings, source_filename );
00204 if ( restore ) parameter::WriteParsToFile( restored_correlation_settings, restored_correlation_filename );
00205
00206 return true;
00207 }