void strag_dE_plan(double A, double Z, double detThick, double DetZ, double theta_old, double phi_old, double energy, double &theta_out, double &phi_out, double X, double conv_det){ // strag_dE_cyl 1.0 written by S.D.Pain on 23/02/2005 // // strag_dE_cyl 1.1 modified by S.D.Pain on 7/03/2005 // to untilise transform2.0 // // Subroutine for the calcualtion of the angular straggling in // the dE layer of a telescope, and application of its effect // on the measured angles in the E detector. // // A = A of ion // Z = Z of ion // detThick = Apparent detector thickness in um (because of incident angle) // DetPhi = azimuthal angle of detector // theta_old = polar angle of incident ion (wrt target) // phi_old = azimuthal angle of incident ion (wrt target) // energy = energy of ion // theta_new = polar angle of outgoing ion (wrt target) // phi_new = azimuthal angle of outgoing ion (wrt target) // X = radiation length of detector material // conv_det = detector thickness conversion from um to mg/cm2 // // PhiDet = azimuthal angle of incidnent ion wrt detector double detThick_mg; double length1,length2; double theta_scat,phi_scat; double theta_scatW; double theta_new,phi_new; double oldX,oldY,oldZ; double newX,newY,newZ; double X1,Y1,Z1,X2,Y2,Z2,X3,Y3,Z3; double DetSep,detAngle; double dummy,dummylength; // Calculate the detector thickness in mg/cm^2, and determine the // scattering width // detThick = 140 // energy = 5.0 detThick_mg = detThick*conv_det; straggleA(theta_scatW,energy,Z,A,detThick_mg,X); theta_scat = rndgauss0(theta_scatW); theta_scat = sqrt(theta_scat*theta_scat*2.0); phi_scat = frand()*2.0*pi; dummylength = 1.0; // Direction of the particle // Convert the incident vector to cartesian, as this will be needed later sphere2cart(dummylength,theta_old,phi_old,oldX,oldY,oldZ); // Transform the scattered ion vector to the lab coordinates (direction relative to target) transform(theta_old,phi_old,theta_scat,phi_scat,theta_new,phi_new); // Convert the scattered vector to cartesians. This will be used to // calculate the angle of the scattered ion relative to the detector. (direction again) sphere2cart(dummylength,theta_new,phi_new,newX,newY,newZ); // Separation of detectors (cm) possibly read this in at some pounsigned short DetSep = 1.0; // Calculate absolute angle of the scattered ion wrt to detector plane if(theta_new <= pi/2.0){ detAngle = theta_new; } else if(theta_new > pi/2.0){ detAngle = pi-theta_new; } // Calculate the length of the vector from the scattering pounsigned short to the // pounsigned short of incidence on the E detector length2 = DetSep/cos(detAngle); // Calculate the length of the vector from the target to // the scattering point length1 = DetZ/cos(theta_old); // the vector from target to scattering point unitV(oldX,oldY,oldZ,X1,Y1,Z1,dummy); X1 = X1*length1; Y1 = Y1*length1; Z1 = Z1*length1; // the vector from scattering pounsigned short to plane of E detector unitV(newX,newY,newZ,X2,Y2,Z2,dummy); X2 = X2*length2; Y2 = Y2*length2; Z2 = Z2*length2; // The vector from target to pounsigned short of incidence on E detector X3 = X1+X2; Y3 = Y1+Y2; Z3 = Z1+Z2; // Convert this back to spherical polars, and return theta and phi cart2sphere(X3,Y3,Z3,dummylength,theta_out,phi_out); }
int main() { cpp_dec_float_20 b = 8000; #if 0 b /= 3; std::cout << std::setprecision(30); std::cout << "size: " << sizeof(cpp_dec_float_20) << ", digits: " << std::numeric_limits<cpp_dec_float_20>::digits << std::endl; std::cout << "result = " << b << std::endl; std::cout << "rounded result = " << boost::math::round(b) << std::endl; std::cout << "rounded result = " << dec_round(b, -1) << std::endl; cpp_dec_float_20 b2("2666.67"); cpp_dec_float_20 b3 = dec_round(b, 2); std::cout << " equal? " << (dec_round(b, 2) == b2) << std::endl; std::cout << " diff = " << (b3 - b2) << std::endl; std::string s = b3.str(); std::cout << "str = " << s << std::endl; std::cout << "boost formated = " << boost::format("%.4f") % b3 << std::endl; std::cout << "stream formated = " << std::setprecision(4) << std::fixed << b3 << std::endl; std::cout << std::setprecision(20); cpp_dec_float_20 testvalue("12345.67890987654321"); std::cout << "origin value:" << testvalue << std::endl; cpp_dec_float_20 partvalue = testvalue.backend().extract_integer_part(); std::cout << "part value:" << partvalue << std::endl; //std::cout << "exp: " << testvalue.backend().exp << std::endl; double mantissa; boost::int32_t exponent; testvalue.backend().extract_parts(mantissa, exponent); std::cout << "mantissa: " << mantissa << ", exp: " << exponent << std::endl; showInternal("0.001234567"); showInternal("-0.001234567"); showInternal("1234567890987654321"); showInternal("-1234567890987654321"); showInternal("12345.67890987654321"); showInternal("-12345.67890987654321"); showInternal("123456789098765432.1"); showInternal("9999999912345678909876543212345.67890987654321"); #endif cpp_dec_float_20 tmpfee("0.29"); cpp_dec_float_20 usageV =60; cpp_dec_float_20 unitV("60"); cpp_dec_float_20 feeV; std::cout<<"tmpfee:"<<tmpfee.str().c_str()<<std::endl; std::cout<<"usageV:"<<usageV.str().c_str()<<std::endl; std::cout<<"unitV:"<<unitV.str().c_str()<<std::endl; feeV = (tmpfee *usageV)/unitV; std::cout<<"---" << (tmpfee *usageV)<<std::endl; std::cout<<"---" << (tmpfee *usageV)/60<<std::endl; std::cout<<"---" << (tmpfee *usageV)/unitV<<std::endl; std::cout<<"---" << feeV << std::endl; std::cout<<"##feeV:"<<feeV.str()<<std::endl; feeV = usageV*tmpfee; std::cout<<"feeV:"<<feeV.str().c_str()<<std::endl; int unitVV =60; feeV = usageV*tmpfee /60; std::cout<<"feeV:"<<feeV.str().c_str()<<std::endl; return 0; }