00001 #include <iostream>
00002 #include <fstream>
00003 #include <iomanip>
00004 #include <string>
00005 #include "yasper.h"
00006 #include "message.h"
00007 #include "parametermap.h"
00008 #include "cheezyparser.h"
00009 #include "kernel_chooser.h"
00010 #include "sou1d_legendre.h"
00011 #include "sou1d_laguerre.h"
00012 #include "sou1d_hermite.h"
00013 #include "sou1d_chebyshev.h"
00014 #include "sou1d_histo.h"
00015 #include "sou1d_bsplines.h"
00016 #include "kernel.h"
00017 #include "crombergintegrator.h"
00018 #include "constants.h"
00019
00020 using namespace std;
00021
00022
00023
00024
00025 void plotSource( yasper::ptr< CBasisFunctionExpansion1d > pExpansion, const parameterMap& inMap );
00026 void plotCorrelation( yasper::ptr< CBasisFunctionExpansion1d > pExpansion, CKernel* pKernel, const parameterMap& inMap );
00027 void getHelp(void);
00028 int main(int argc, char* argv[]);
00029
00030
00031
00032
00033 class CBFPLOTIntegrand{
00034 public:
00035 CBFPLOTIntegrand( yasper::ptr< CBasisFunctionExpansion1d > _pExpansion, CKernel* _pKernel, int _i, int _l, double _q ):
00036 pExpansion(_pExpansion), pKernel(_pKernel), index(_i), l(_l), q(_q){}
00037 yasper::ptr< CBasisFunctionExpansion1d > pExpansion;
00038 CKernel* pKernel;
00039 int index, l;
00040 double q;
00041 static double f( void* instance, double r ){
00042 CBFPLOTIntegrand* inst = static_cast< CBFPLOTIntegrand* >(instance);
00043 return 4.0 * PI * r * r *
00044 inst->pKernel->GetValue( inst->l, inst->q, r ) *
00045 inst->pExpansion->basisFunction( r, inst->index );
00046 }
00047 };
00048
00049
00050
00051
00052
00053
00055 void getHelp(void){
00056 cout<<"\n";
00057 cout<<"\n";
00058 cout<<"\nUsage: bfplot <option> [inputFile.dat]"<<endl;
00059 cout<<" options -h, -help, --help all print this message, then quit"<<endl;
00060 cout<<" -legendre Print out Legendre polynomial basis" <<endl;
00061 cout<<" -bspline Print out Basis Spline basis" <<endl;
00062 cout<<" -laguerre Print out Laguerre function basis" <<endl;
00063 cout<<" -chebyshev Print out Chebyshev polynomial basis" <<endl;
00064 cout<<" -histogram Print out Histogram basis" <<endl;
00065 cout<<" -hermite Print out Hermite function basis" <<endl;
00066 cout<<" -convolve Convolve basis funcs with kernel too" <<endl;
00067 exit(0);
00068 }
00069
00070
00071 int main(int argc, char* argv[]){
00072
00073 cout << "*** Widget to PLOT the Basis Functions (BFPLOT) using CorAL ***"<<endl;
00074 cout << endl;
00075
00076 bool got_file = false;
00077 bool convolve_with_kernel=false;
00078
00079 MESSAGE << CMessage::warning;
00080
00081
00082 if (argc==1) getHelp();
00083 string paramFile("");
00084 vector<string> modeList;
00085 for (int iarg = 1; iarg<argc; ++iarg){
00086 string sarg(argv[iarg]);
00087 if (sarg=="-help") getHelp();
00088 if (sarg=="--help") getHelp();
00089 if (sarg=="-h") getHelp();
00090 if (sarg=="-convolve") convolve_with_kernel=true;
00091 else if (sarg.substr(0,1)=="-") modeList.push_back(sarg);
00092 else {
00093 paramFile = sarg;
00094 got_file = true;
00095 }
00096 }
00097
00098
00099 if (!got_file) {
00100 MESSAGE<<"No inputFile parameter file given!!"<<ENDM_WARN;
00101 getHelp();
00102 }
00103 parameterMap inMap;
00104 parameter::ReadParsFromFile(inMap, paramFile);
00105
00106 yasper::ptr<CBasisFunctionExpansion1d> pExpansion;
00107 for ( vector<string>::iterator it=modeList.begin(); it!=modeList.end(); ++it)
00108 {
00109 if ( *it == "-legendre" ) { pExpansion = new CLegendrePolynomialExpansion1d; }
00110 else if ( *it == "-bspline" ) { pExpansion = new CBasisSpline1d; }
00111 else if ( *it == "-laguerre" ) { pExpansion = new CLaguerrePolynomialExpansion1d; }
00112 else if ( *it == "-chebyshev" ) { pExpansion = new CChebyshevPolynomialExpansion1d; }
00113 else if ( *it == "-histogram" ) { pExpansion = new CHistogram1d; }
00114 else if ( *it == "-hermite" ) { pExpansion = new CHermiteFunctionExpansion1d; }
00115 else MESSAGE<<"Unknown mode: '"<<*it<<ENDM_WARN;
00116 }
00117 pExpansion->Read( inMap );
00118 plotSource( pExpansion, inMap );
00119
00120 if (inMap.hasKey("particle1")&&inMap.hasKey("particle2")&&inMap.hasKey("param_filename")&&convolve_with_kernel) {
00121 string p1 = parameter::getS(inMap, "particle1", "pi+");
00122 string p2 = parameter::getS(inMap, "particle2", "pi+");
00123 CKernel* pKernel = chooseKernel( p1, p2, inMap );
00124 plotCorrelation( pExpansion, pKernel, inMap );
00125 }
00126
00127 return true;
00128 }
00129
00130
00131 void plotSource( yasper::ptr< CBasisFunctionExpansion1d > pExpansion, const parameterMap& inMap ){
00132 string outFile = parameter::getS(inMap,"basis_func_plot_file","output_r_basis_funcs.dat");
00133 cout << " Plotting basis functions in r-space to " << outFile << endl;
00134 ofstream fout(outFile.c_str());
00135 for (int i=0; i<pExpansion->ndata; ++i) {
00136 fout << endl;
00137 for (int n=0;n<100;++n) {
00138 double r = (pExpansion->getLeftSupport(i)-pExpansion->getRightSupport(i))*double(n)/100.0 + pExpansion->getRightSupport(i);
00139 fout << r << " " << pExpansion->basisFunction(r,i)<<endl;
00140 }
00141 }
00142
00143 }
00144
00145
00146 void plotCorrelation( yasper::ptr< CBasisFunctionExpansion1d > pExpansion, CKernel* pKernel, const parameterMap& inMap ){
00147 string outFile = parameter::getS(inMap,"convoluted_basis_func_plot_file","output_q_basis_funcs.dat");
00148 cout << " Plotting basis functions in q-space to " << outFile << endl;
00149 ofstream fout(outFile.c_str());
00150 double qmin=parameter::getD(inMap,"qmin",0.0);
00151 double qmax=parameter::getD(inMap,"qmax",100.0);
00152 CBFPLOTIntegrand integrand( pExpansion, pKernel, 0, parameter::getI(inMap,"l",0), 0.0 );
00153 CRombergIntegrator integrator( static_cast<void*>(&integrand), CBFPLOTIntegrand::f );
00154 for (int i=0; i<pExpansion->ndata; ++i) {
00155 fout << endl;
00156 integrand.index = i;
00157 for (int n=0;n<100;++n) {
00158 double q = (qmax-qmin)*double(n)/100.0 + qmin;
00159 integrand.q = q;
00160 fout << q << " " << integrator.compute(pExpansion->getLeftSupport(i),pExpansion->getRightSupport(i))<<endl;
00161 }
00162 }
00163
00164 }
00165