00001 #include "oscar_source_generator_3dcart.h"
00002 #include "constants.h"
00003 #include "tnt_array1d_utils.h"
00004 #include "misc.h"
00005 #include "cheezyparser.h"
00006
00007
00008
00009
00010 bool COSCARSourceGenerator3dCart::Read( const parameterMap& m ){
00011 bool result = COSCARSourceGeneratorBase::Read(m);
00012 fold[iSide] = parameter::getB( m, "fold_side", fold[iSide] );
00013 fold[iOut] = parameter::getB( m, "fold_out", fold[iOut] );
00014 fold[iLong] = parameter::getB( m, "fold_long", fold[iLong] );
00015 return result;
00016 }
00017
00018
00019
00020 bool COSCARSourceGenerator3dCart::Write( parameterMap& m){
00021 bool result = COSCARSourceGeneratorBase::Write(m);
00022 parameter::set( m, "fold_side", fold[iSide] );
00023 parameter::set( m, "fold_out", fold[iOut] );
00024 parameter::set( m, "fold_long", fold[iLong] );
00025 return result;
00026 }
00027
00028
00029
00030 bool COSCARSourceGenerator3dCart::addOnePair( const COSCARLine& p1, const COSCARLine& p2 ){
00031
00032 double r[3];
00033 getSideOutLong( r_cm, r );
00034
00035 for ( int i=0; i<3; ++i ) if ( fold[i] ) r[i] = abs( r[i] );
00036
00037 maxS = std::max( r[iSide], maxS );
00038 minS = std::min( r[iSide], minS );
00039 maxO = std::max( r[iOut], maxO );
00040 minO = std::min( r[iOut], minO );
00041 maxL = std::max( r[iLong], maxL );
00042 minL = std::min( r[iLong], minL );
00043 int iBin = result.whatBin( r[0], r[1], r[2] );
00044 if ( iBin >= 0 && iBin < result.ndata ) {
00045 result.data[iBin] += 1;
00046 result.uncert[iBin] += 1;
00047 }
00048 return true;
00049 }
00050
00051
00052
00053 bool COSCARSourceGenerator3dCart::postProcessPairs( void ){
00054 cout << " Normalizing 3D source function...\n";
00055 double integral=0.0, dintegral=0.0;
00056 double flip_factor=1.0;
00057 for (int i=0;i<3;++i) if (fold[i]) flip_factor*=2.0;
00058 double rweight=result.binVolume()*flip_factor;
00059 result.covmtx_is_active=false;
00060 for (int i=0;i<result.ndata;++i) {
00061 result.data[i]=result.data[i]/double(totalPairs)/rweight;
00062 integral += result.data[i]*rweight;
00063 }
00064 for (int i=0;i<result.ndata;++i) {
00065 double u = result.uncert[i]/double(totalPairs)/rweight/rweight-result.data[i]*result.data[i];
00066 if ( u < -1e-6 ) throw MESSAGE <<"Bad u: "<<u<<ENDM_FATAL;
00067 result.uncert[i]=sqrt(abs(u/double(totalPairs)));
00068 dintegral += pow(result.uncert[i]*rweight,2.0);
00069 }
00070 cout << " Some parameters from the legal pairs:\n";
00071 cout << " maxS:" << maxS << ", minS:" << minS << "\n";
00072 cout << " maxO:" << maxO << ", minO:" << minO << "\n";
00073 cout << " maxL:" << maxL << ", minL:" << minL << "\n";
00074 cout << " Number of good pairs: " << totalPairs << endl;
00075 cout << " Cross-checking integral of Cartesian binned source function..."<<endl;
00076 cout << " Integral of source: " << integral << "+/-" << sqrt(dintegral) << endl;
00077 cout << " 'Flip factor' due to assumed symmetries: " << flip_factor << endl;
00078 return true;
00079 }
00080
00081
00082 CSourceFtn3dHisto COSCARSourceGenerator3dCart::generateSource( vector<COSCARLine> plist, const parameterMap& m ){
00083
00084
00085 parameterMap souMap;
00086 souMap = parameter::getMap( m,"source_settings" );
00087 result.Read(souMap);
00088
00089
00090 Read(m);
00091
00092
00093 filterParticles( plist );
00094
00095
00096 accumulatePairs();
00097
00098 return result;
00099 }