diff --git a/StRoot/StGeant4Maker/StGeant4Maker.cxx b/StRoot/StGeant4Maker/StGeant4Maker.cxx index 3a1c725..c21f093 100644 --- a/StRoot/StGeant4Maker/StGeant4Maker.cxx +++ b/StRoot/StGeant4Maker/StGeant4Maker.cxx @@ -350,11 +350,6 @@ struct SD2Table_MTD { g2t_hit.xglobal[1] = (hit->position_in[1] + hit->position_out[1]) * 0.5; g2t_hit.xglobal[2] = (hit->position_in[2] + hit->position_out[2]) * 0.5; - LOG_INFO << "g2t_hit.xglobal = " - << g2t_hit.xglobal[0] << " " - << g2t_hit.xglobal[1] << " " - << g2t_hit.xglobal[2] << " " << endm; - g2t_hit.tof = (hit->position_in[3] + hit->position_out[3]) * 0.5; g2t_hit.p[0] = (hit->momentum_in[0] + hit->momentum_out[0]) * 0.5; g2t_hit.p[1] = (hit->momentum_in[1] + hit->momentum_out[1]) * 0.5; diff --git a/macros/initStarG3.C b/macros/initStarG3.C index 842c6f9..094486a 100644 --- a/macros/initStarG3.C +++ b/macros/initStarG3.C @@ -71,6 +71,12 @@ void Kinematics() void initStarG3( const char* tag="dev2021", Int_t nevents=0, Int_t rngSeed=1234 ) { + // Add a few things to the include path + gSystem->AddIncludePath(" -IStRoot -I${STAR}/StRoot -Igeom -IStarVMC -I${STAR}/StarVMC -IStarVMC/Geometry/macros -I.${STAR_HOST_SYS}/include "); + gEnv->SetValue("Logger.Colors","YES"); + + gSystem->SetAclicMode(TSystem::kDebug); + gROOT->ProcessLine(".L bfc.C"); { TString simple = tag; simple += " geant gstar usexgeom agml "; @@ -89,6 +95,8 @@ void initStarG3( const char* tag="dev2021", Int_t nevents=0, Int_t rngSeed=1234 gSystem->Load( "libMathMore.so" ); gSystem->Load( "xgeometry.so" ); + gSystem->Load( "StEpdUtil.so" ); + // Setup RNG seed and map all ROOT TRandom here StarRandom::seed( rngSeed ); StarRandom::capture(); diff --git a/starsim++ b/starsim++ new file mode 100755 index 0000000..02a88dd --- /dev/null +++ b/starsim++ @@ -0,0 +1,5 @@ +#!/bin/csh -f + +root4star macros/initStarG3.C $argv + + diff --git a/tests/unit-test-summary b/tests/unit-test-summary new file mode 100755 index 0000000..b9d3416 --- /dev/null +++ b/tests/unit-test-summary @@ -0,0 +1,93 @@ +#!/usr/bin/env python + +import re +import sys +import argparse +import subprocess + +ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])') + +TEST_REPORT = re.compile( '.*\[(.*)\].*-(.*)-' ) + +TEST_PASS = {} +TEST_FAIL = {} +TEST_TOTAL = {} +TEST_KEYS = [] + +count = 0 + +p = argparse.ArgumentParser() +p.add_argument('input', nargs='?', + type=argparse.FileType(), default=sys.stdin) +args = p.parse_args() + +# Number of test lines with passes and failures +npass_line = 0 +nfail_line = 0 + +# Number of test lines which completely pass / fail +npass_complete = 0 +nfail_complete = 0 + +for line in args.input.readlines(): + line = line.replace(' | ','') + line = ansi_escape.sub('',line) + m = TEST_REPORT.match(line) + if m: + group1 = m.group(1) + group2 = m.group(2) + + count = count + 1 + + try: + TEST_TOTAL[group1] = TEST_TOTAL[group1] + 1 + except KeyError: + TEST_TOTAL[group1] = 1 + TEST_PASS[group1] = 0 + TEST_FAIL[group1] = 0 + TEST_KEYS.append(group1) + + + if 'passed' == group2: + TEST_PASS[group1] = TEST_PASS[group1] + 1 + + if 'failed' == group2: + TEST_FAIL[group1] = TEST_FAIL[group1] + 1 + + +print "" +print "Summary of tests" +print "----------------------------------------------------------------------" +print "pass | fail | total | test" +print "----------------------------------------------------------------------" + +for key in TEST_KEYS: + + npass = TEST_PASS[key] + nfail = TEST_FAIL[key] + count = TEST_TOTAL[key] + + if ( npass == count ): + npass_complete = npass_complete + 1 + if ( nfail == count ): + nfail_complete = nfail_complete + 1 + if ( npass != 0 ): + npass_line = npass_line + 1 + if ( nfail != 0 ): + nfail_line = nfail_line + 1 + + + if ( nfail == 0 ): + print "%4i | %4i | %4i %s"%(npass,nfail,count,key) + else: + print "%4i | %4i | %4i [!] %s"%(npass,nfail,count,key) + +print "----------------------------------------------------------------------" +print "N tests w/ passes = " + str(npass_line) +print "N tests w/ failures = " + str(nfail_line) +print "N tests w/ complete passes = " + str(npass_complete) +print "N tests w/ complete failures = " + str(nfail_complete) + + + + diff --git a/tests/unit_test_eem_hits.C b/tests/unit_test_eem_hits.C index 0d710ef..9a3451f 100644 --- a/tests/unit_test_eem_hits.C +++ b/tests/unit_test_eem_hits.C @@ -229,36 +229,36 @@ void unit_test_eem_hits() { result = Form(" ... sector=%i ", sector ) + result; return result; }); - check_emc_hit( Form("The sector of the hit should be %i",sector),hit,[=](const g2t_emc_hit_st* h) { + check_emc_hit( "The hit has the expected sector",hit,[=](const g2t_emc_hit_st* h) { std::string result = FAIL; int volumeId = h->volume_id; EEmcVolumeId id = decode_eemc_volume_id( volumeId ); if ( sector ==id.sector ) result = PASS; - result = Form(" ... sector=%i ", id.sector ) + result; + result = Form(" expect %i actual %i ", id.sector,sector ) + result; return result; }); - check_emc_hit( Form("The sub-sector of the hit should be %i",subsector),hit,[=](const g2t_emc_hit_st* h) { + check_emc_hit( "The hit has the expected subsector",hit,[=](const g2t_emc_hit_st* h) { std::string result = FAIL; int volumeId = h->volume_id; EEmcVolumeId id = decode_eemc_volume_id( volumeId ); if ( id.subsector == subsector ) result = PASS; - result = Form(" ... subsector=%i ", id.subsector ) + result; + result = Form(" expect %i actual %i ", id.subsector,subsector ) + result; return result; }); - check_emc_hit( Form("The phibin of the hit should be %i",phibin),hit,[=](const g2t_emc_hit_st* h) { + check_emc_hit( "The hit has the expected phibin",hit,[=](const g2t_emc_hit_st* h) { std::string result = FAIL; int volumeId = h->volume_id; EEmcVolumeId id = decode_eemc_volume_id( volumeId ); if ( id.phibin == phibin ) result = PASS; - result = Form(" ... phibin=%i ", id.phibin ) + result; + result = Form(" expect %i actual %i ", id.phibin, phibin ) + result; return result; }); - check_emc_hit( Form("The etabin of the hit should be %i",etabin),hit,[=](const g2t_emc_hit_st* h) { + check_emc_hit( "The hit has the expected eta bin",hit,[=](const g2t_emc_hit_st* h) { std::string result = FAIL; int volumeId = h->volume_id; EEmcVolumeId id = decode_eemc_volume_id( volumeId ); if ( etabin == id.etabin ) result = PASS; - result = Form(" ... etabin=%i ", id.etabin ) + result; + result = Form(" expect %i actual %i ", id.etabin, etabin ) + result; return result; }); check_emc_hit( "The depth of the hit should be 1-5",hit,[=](const g2t_emc_hit_st* h) { diff --git a/tests/unit_test_emc_hits.C b/tests/unit_test_emc_hits.C index f86e1e9..bbd222e 100644 --- a/tests/unit_test_emc_hits.C +++ b/tests/unit_test_emc_hits.C @@ -27,7 +27,7 @@ std::vector cells; //___________________________________________________________________ void throw_muon_in_bemc_tower( double eta, double phid, int charge = 1 ) { - throw_muon( eta, phid, 50.0, charge ); // energetic + throw_muon( eta, phid, 10.0, charge ); // energetic _eta = eta; _phid = phid; @@ -76,7 +76,7 @@ void unit_test_emc_hits() { check_track( "The start vertex should be in the vertex table", [=](const g2t_track_st* t){ std::string result = FAIL; int istart = t->start_vertex_p; - const g2t_vertex_st* vertex = (istart>0) ? static_cast( vertex_table->At(istart-1) ) : 0; + const g2t_vertex_st* vertex = (istart>0 && istart <= vertex_table->GetNRows()) ? static_cast( vertex_table->At(istart-1) ) : 0; if ( vertex ) { result = PASS; } @@ -91,7 +91,7 @@ void unit_test_emc_hits() { int istart = t->start_vertex_p; const g2t_vertex_st* v = 0; - if ( istart > 0 ) + if ( istart > 0 && istart <= vertex_table->GetNRows() ) v = static_cast( vertex_table->At(istart-1) ); else result = " no vertex in table " + result; @@ -123,10 +123,18 @@ void unit_test_emc_hits() { if ( t->eta ==-999 ) result = FAIL; return result; }); - check_track( Form("The track should have an eta=%f",_eta), [=](const g2t_track_st* t){ + check_track( "The track should has the expected eta", [=](const g2t_track_st* t){ double delta = abs(t->eta-_eta); - return abs(t->eta-_eta)<1E-5 ?PASS:FAIL; + std::string result = FAIL; + if ( abs(t->eta-_eta)<1E-5 ) + result = PASS; + result = Form(" expect %f got %f ", _eta, t->eta ) + result; + return result; }); + // check_track( "The track should has the expected phi", [=](const g2t_track_st* t){ + // double delta = abs(t->phi-_phi); + // return delta<1E-5 ?PASS:FAIL; + // }); check_track( "Expect 2 hits in the dev2021 geometry", [=](const g2t_track_st* t){ int n = t->n_emc_hit; std::string result = FAIL; @@ -139,15 +147,6 @@ void unit_test_emc_hits() { auto hit = static_cast( hit_table->At(i) ); if ( 0==hit ) continue; // skip null entries if ( 1!=hit->track_p ) continue; // not interested in secondaries - - check_emc_hit( "Print the hit...", hit, [=](const g2t_emc_hit_st* h) { - LOG_TEST << "id=" << h->id - << " track_p=" << h->track_p - << " volume_id=" << h->volume_id - << " de=" << h->de - << std::endl; - return PASS; - }); check_emc_hit( "Energy deposition is positive", hit, [=]( const g2t_emc_hit_st* hit ) { std::string result = FAIL; if ( hit->de > 0 ) result = PASS; @@ -173,7 +172,7 @@ void unit_test_emc_hits() { int volId = h->volume_id; int tow = (h->volume_id % 100000) / 100; std::string result = FAIL; - if ( tow>=1 && tow<= 40 ) result = PASS; + if ( tow>=1 && tow<= 60 ) result = PASS; result = Form("phibin=%i ",tow) + result; return result; }); @@ -193,7 +192,8 @@ void unit_test_emc_hits() { result = Form("super layer=%i ",tow) + result; return result; }); - check_emc_hit( Form("Expected volume ID is %i (or %i)",cell.volumeId,cell.volumeId+1), hit, [=]( const g2t_emc_hit_st* h) { + std::string side = (eta>0)?"west":"east"; + check_emc_hit( Form("Hit has the expected volume ID %s",side.c_str()), hit, [=]( const g2t_emc_hit_st* h) { std::string result = FAIL; if ( cell.volumeId == h->volume_id || cell.volumeId+1 == h->volume_id ) result = PASS; result = Form(" got volume id %i expect %i or %i ",h->volume_id,cell.volumeId,cell.volumeId+1) + result; diff --git a/tests/unit_test_epd_response.C b/tests/unit_test_epd_response.C index 88e8b8f..34f3ca4 100644 --- a/tests/unit_test_epd_response.C +++ b/tests/unit_test_epd_response.C @@ -1,4 +1,5 @@ #include "tests/unit_tests.h" +#include //___________________________________________________________________ double _eta = 0; @@ -36,11 +37,10 @@ void unit_test_epd_response( int nevents=5000 ) { assert(sf>0); float sum = 0.; auto* table = dynamic_cast( chain->GetDataSet( name ) ) ; - if (table) - table->Print(0,1); + if (0!=table) for ( int i=0;iGetNRows();i++ ){ const g2t_epd_hit_st* hit = static_cast( table->At(i) ); - sum+=hit->de; + if ( hit ) sum+=hit->de; }; return 1000.0*sum; }; diff --git a/tests/unit_test_fcs_hits.C b/tests/unit_test_fcs_hits.C index dffd1c0..d6843de 100644 --- a/tests/unit_test_fcs_hits.C +++ b/tests/unit_test_fcs_hits.C @@ -2061,13 +2061,14 @@ void unit_test_fcs_hits() { auto* chain = StMaker::GetChain(); { + const double pz = 10.0; auto* _kine = dynamic_cast( chain->GetMaker("StarKine") ); auto* particle = _kine->AddParticle( "mu+" ); particle->SetPx( 0. ); particle->SetPy( 0. ); - particle->SetPz( 250. ); + particle->SetPz( pz ); double mass = particle->GetMass(); - double ener = sqrt( 250.*250. + mass*mass ); + double ener = sqrt( pz*pz + mass*mass ); particle->SetEnergy(ener); chain->Clear(); chain->Make(); @@ -2080,7 +2081,6 @@ void unit_test_fcs_hits() { else hit_table = dynamic_cast( chain->GetDataSet("g2t_hca_hit") ) ; - LOG_TEST << GIVEN << "a 500 GeV muon @ eta=" << cell.eta << " phi=" << cell.phi << " volume=" << cell.volumeId << std::endl; check_track( "A muon must have been processed by geant", [=](const g2t_track_st* t){ @@ -2160,8 +2160,9 @@ void unit_test_fcs_hits() { // if ( t->n_pre_hit < 1 ) result = FAIL; // return result; // }); + - check_emc_hit( Form("Expect the most energetic hit to have volumeId=%i",cell.volumeId), [=](const g2t_emc_hit_st* h){ + check_emc_hit( Form("The hit has the expected volume ID %s",(dowcal)?"WCAL":"HCAL"), [=](const g2t_emc_hit_st* h){ int volumeId = h->volume_id; int expected = cell.volumeId; int nhits = hit_table->GetNRows(); @@ -2177,8 +2178,9 @@ void unit_test_fcs_hits() { } std::string result = PASS; if ( actual != expected ) { - result = Form(" got volumeId=%i ", actual ) + FAIL; + result = FAIL; } + result = Form("(expect=%i actual=%i)",expected,actual) + result; return result; }); diff --git a/tests/unit_test_mtd_hits.C b/tests/unit_test_mtd_hits.C index 221c036..85d049d 100644 --- a/tests/unit_test_mtd_hits.C +++ b/tests/unit_test_mtd_hits.C @@ -64,9 +64,8 @@ void unit_test_mtd_hits( int longtest=0, double _pt=25.0 ) { auto* chain = StMaker::GetChain(); vertex_table = dynamic_cast( chain->GetDataSet("g2t_vertex") ); track_table = dynamic_cast( chain->GetDataSet("g2t_track") ); - if ( hit_table = dynamic_cast( chain->GetDataSet("g2t_mtd_hit") ) ) { - hit_table->Print(0,1); - } + hit_table = dynamic_cast( chain->GetDataSet("g2t_mtd_hit") ); + check_track( "A muon must have been processed by geant", [=](const g2t_track_st* t){ @@ -156,6 +155,8 @@ void unit_test_mtd_hits( int longtest=0, double _pt=25.0 ) { return result; }); + if ( 0==hit_table ) continue; + for ( int i=0;iGetNRows();i++ ) { auto hit = static_cast( hit_table->At(i) ); diff --git a/tests/unit_tests.h b/tests/unit_tests.h index 8c8e646..daa4ff6 100644 --- a/tests/unit_tests.h +++ b/tests/unit_tests.h @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include #include