Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F9501261
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Subscribers
None
View Options
diff --git a/test/test_function_parser.cpp b/test/test_function_parser.cpp
index 51e29bb..2f2f5c8 100644
--- a/test/test_function_parser.cpp
+++ b/test/test_function_parser.cpp
@@ -1,36 +1,35 @@
#include "CepGen/Core/Functional.h"
#include <string>
#include <iostream>
-#include <assert.h>
using namespace std;
int
main()
{
const double epsilon = 1.e-9; // tolerance
{ // test with a 1-variable function
const double exp_result_test1 = 6.795704571;
CepGen::Functional<1> test1( "2.5*exp(0.1*x)", { "x" } );
- assert( fabs( test1.eval( 10. ) - exp_result_test1 ) < epsilon );
- assert( fabs( test1.eval( { 10. } ) - exp_result_test1 ) < epsilon );
+ if ( fabs( test1.eval( 10. ) - exp_result_test1 ) > epsilon ) throw CepGen::Exception( __PRETTY_FUNCTION__, "Test 1.1 failed!", CepGen::FatalError );
+ if ( fabs( test1.eval( { 10. } ) - exp_result_test1 ) > epsilon ) throw CepGen::Exception( __PRETTY_FUNCTION__, "Test 1.2 failed!", CepGen::FatalError );
cout << "Test 1 passed!" << endl;
}
{ // test with a 2-variables function
CepGen::Functional<2> test2( "sqrt(a^2+b^2)", { "a", "b" } );
- assert( fabs( test2.eval( { 3, 4 } ) - 5.0 ) < epsilon );
+ if ( fabs( test2.eval( { 3, 4 } ) - 5.0 ) > epsilon ) throw CepGen::Exception( __PRETTY_FUNCTION__, "Test 2 failed!", CepGen::FatalError );
cout << "Test 2 passed!" << endl;
}
{ // test with an invalid function
CepGen::Functional<1> test3( "a**2", { "a" } );
bool passed = true;
try { test3.eval( 10 ); passed = false; } catch ( CepGen::Exception& e ) {}
try { test3.eval( { 10 } ); passed = false; } catch ( CepGen::Exception& e ) {}
- assert( passed == true );
+ if ( !passed ) throw CepGen::Exception( __PRETTY_FUNCTION__, "Test 3 failed!", CepGen::FatalError );
cout << "Test 3 passed!" << endl;
}
return 0;
}
diff --git a/test/test_function_parser_rootcomp.cxx b/test/test_function_parser_rootcomp.cxx
index 278dd34..e020203 100644
--- a/test/test_function_parser_rootcomp.cxx
+++ b/test/test_function_parser_rootcomp.cxx
@@ -1,55 +1,54 @@
#include "TGraph.h"
#include "TF1.h"
#include "TMultiGraph.h"
#include "Canvas.h"
#include <iostream>
#include "CepGen/Core/Functional.h"
-#include <assert.h>
using namespace std;
int main( int argc, char* argv[] )
{
const unsigned short num_points = 100;
const double min_x = -1., max_x = 10.;
TGraph gr_fb, gr_rt;
TF1 f_rt( "f_rt", "TMath::Min(1.,TMath::Exp(-x/10))", min_x, max_x );
CepGen::Functional<1> test1( "min(1,exp(-x/10))", { "x" } );
for ( unsigned short i = 0; i < num_points; ++i ) {
const double x = min_x + ( max_x-min_x )/( num_points-1 )*i;
gr_rt.SetPoint( i, x, f_rt.Eval( x ) );
try {
gr_fb.SetPoint( i, x, test1.eval( x ) );
} catch ( const CepGen::Exception& e ) { e.dump(); }
}
TGraph gr_diff;
double chi2 = 0.;
for ( unsigned short i = 0; i < gr_fb.GetN(); ++i ) {
gr_diff.SetPoint( i, gr_fb.GetX()[i], gr_fb.GetY()[i]-gr_rt.GetY()[i] );
chi2 += pow( gr_fb.GetY()[i]-gr_rt.GetY()[i], 2 );
}
chi2 = sqrt( chi2 );
- assert( chi2<1.e-9 );
+ if ( chi2 > 1.e-9 ) throw CepGen::Exception( __PRETTY_FUNCTION__, Form( "Test failed with chi2 = %.5e!", chi2 ), CepGen::FatalError );
cout << "Test passed!" << endl;
if ( argc > 1 && !strcmp( argv[1], "draw" ) ) {
CepGen::Canvas c( "test_graph", "CepGen validation" );
TMultiGraph mg;
mg.Add( &gr_fb );
mg.Add( &gr_rt );
mg.Add( &gr_diff );
mg.Draw( "al" );
c.AddLegendEntry( &gr_fb, "Functional", "l" );
c.AddLegendEntry( &gr_rt, "ROOT", "l" );
c.AddLegendEntry( &gr_diff, "Difference", "l" );
gr_fb.SetLineWidth( 3 );
gr_fb.SetLineStyle( 2 );
gr_diff.SetLineColor( kRed );
c.Prettify( mg.GetHistogram() );
c.Save( "pdf" );
}
return 0;
}
diff --git a/test/test_physics_processes.cpp b/test/test_physics_processes.cpp
index 435f033..940469b 100644
--- a/test/test_physics_processes.cpp
+++ b/test/test_physics_processes.cpp
@@ -1,86 +1,87 @@
#include "CepGen/Generator.h"
#include "CepGen/Processes/GamGamLL.h"
#include "CepGen/Processes/PPtoLL.h"
#include <assert.h>
int
main( int argc, char* argv[] )
{
typedef std::map<std::string,std::pair<double,double> > KinematicsMap;
typedef std::map<float, KinematicsMap> ValuesAtCutMap;
// values defined at pt(single lepton)>15 GeV, |eta(single lepton)|<2.5, mX<1000 GeV
// process -> { pt cut -> { kinematics -> ( sigma, delta(sigma) ) } }
std::map<std::string,ValuesAtCutMap> values_map = {
//--- LPAIR values at sqrt(s) = 13 TeV
{ "1_lpair", {
{ 15.0, { // pt cut
{ "1_elastic", { 4.1994803e-1, 8.328e-4 } },
{ "2_singlediss", { 4.8504819e-1, 1.171e-3 } },
{ "3_doublediss", { 6.35650e-1, 1.93968e-3 } }
} }
} },
//--- PPTOLL values
{ "2_pptoll", { {} } },
};
const double num_sigma = 3.0;
CepGen::Logger::get().level = CepGen::Logger::Nothing;
Timer tmr;
CepGen::Generator mg;
mg.parameters->kinematics.setSqrtS( 13.e3 );
mg.parameters->kinematics.eta_min = -2.5;
mg.parameters->kinematics.eta_max = 2.5;
mg.parameters->kinematics.mx_max = 1000.;
mg.parameters->vegas.ncvg = 50000;
mg.parameters->vegas.itvg = 5;
Information( Form( "Initial configuration time: %.3f ms", tmr.elapsed()*1.e3 ) );
tmr.reset();
unsigned short num_tests = 0, num_tests_passed = 0;
for ( const auto& values_vs_generator : values_map ) { // loop over all generators
if ( values_vs_generator.first == "1_lpair" ) mg.parameters->setProcess( new CepGen::Process::GamGamLL );
else if ( values_vs_generator.first == "2_pptoll" ) mg.parameters->setProcess( new CepGen::Process::PPtoLL );
else { InError( Form( "Unrecognized generator mode: %s", values_vs_generator.first.c_str() ) ); break; }
for ( const auto& values_vs_cut : values_vs_generator.second ) { // loop over the single lepton pT cut
mg.parameters->kinematics.pt_min = values_vs_cut.first;
for ( const auto& values_vs_kin : values_vs_cut.second ) { // loop over all possible kinematics
if ( values_vs_kin.first == "1_elastic" ) mg.parameters->kinematics.mode = CepGen::Kinematics::ElasticElastic;
else if ( values_vs_kin.first == "2_singlediss" ) mg.parameters->kinematics.mode = CepGen::Kinematics::InelasticElastic;
else if ( values_vs_kin.first == "3_doublediss" ) mg.parameters->kinematics.mode = CepGen::Kinematics::InelasticInelastic;
else { InError( Form( "Unrecognized kinematics mode: %s", values_vs_kin.first.c_str() ) ); break; }
Information( Form( "Process: %s/%s\n\tConfiguration time: %.3f ms", values_vs_generator.first.c_str(), values_vs_kin.first.c_str(), tmr.elapsed()*1.e3 ) );
tmr.reset();
mg.clearRun();
const double xsec_ref = values_vs_kin.second.first, err_xsec_ref = values_vs_kin.second.second;
double xsec_cepgen, err_xsec_cepgen;
mg.computeXsection( xsec_cepgen, err_xsec_cepgen );
const double sigma = ( fabs( xsec_ref-xsec_cepgen ) ) / sqrt( err_xsec_cepgen*err_xsec_cepgen + err_xsec_ref*err_xsec_ref );
Information( Form( "Computed cross section:\n\tRef. = %.3e +/- %.3e\n\tCepGen = %.3e +/- %.3e\n\tPull: %.6f", xsec_ref, err_xsec_ref, xsec_cepgen, err_xsec_cepgen, sigma ) );
Information( Form( "Computation time: %.3f ms", tmr.elapsed()*1.e3 ) );
tmr.reset();
if ( fabs( sigma )<num_sigma ) num_tests_passed++;
+ else throw CepGen::Exception( __PRETTY_FUNCTION__, Form( "Test %s/%s failed!", values_vs_generator.first.c_str(), values_vs_kin.first.c_str() ), CepGen::FatalError );
num_tests++;
std::cout << "Test " << num_tests_passed << "/" << num_tests << " passed!" << std::endl;
}
}
}
Information( "ALL TESTS PASSED!" );
return 0;
}
diff --git a/test/test_vegas.cpp b/test/test_vegas.cpp
index 2334e8f..be89e1c 100644
--- a/test/test_vegas.cpp
+++ b/test/test_vegas.cpp
@@ -1,29 +1,28 @@
#include "CepGen/Generator.h"
#include "CepGen/Processes/TestProcess.h"
#include <iostream>
-#include <assert.h>
using namespace std;
int
main( int argc, char* argv[] )
{
const double exact = 1.3932039296856768591842462603255;
CepGen::Logger::get().level = CepGen::Logger::Nothing;
CepGen::Generator mg;
mg.parameters->setProcess( new CepGen::Process::TestProcess );
mg.parameters->vegas.ncvg = 500000;
//mg.parameters->vegas.itvg = 5;
double result, error;
mg.computeXsection( result, error );
- assert( fabs( exact - result ) < 2.0 * error );
+ if ( fabs( exact - result ) > 2.0 * error ) throw CepGen::Exception( __PRETTY_FUNCTION__, Form( "pull = %.5e", fabs( exact-result )/error ), CepGen::FatalError );
cout << "Test 1 passed!" << endl;
return 0;
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Feb 23, 2:10 PM (2 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4486479
Default Alt Text
(8 KB)
Attached To
rCEPGEN CepGen - public repository
Event Timeline
Log In to Comment