Skip to content

Commit

Permalink
Merge pull request #60 from klendathu2k/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
klendathu2k authored Nov 18, 2020
2 parents a7249f6 + aaf499a commit b7407db
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 40 deletions.
5 changes: 0 additions & 5 deletions StRoot/StGeant4Maker/StGeant4Maker.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions macros/initStarG3.C
Original file line number Diff line number Diff line change
Expand Up @@ -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 ";
Expand All @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions starsim++
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/csh -f

root4star macros/initStarG3.C $argv


93 changes: 93 additions & 0 deletions tests/unit-test-summary
Original file line number Diff line number Diff line change
@@ -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)




16 changes: 8 additions & 8 deletions tests/unit_test_eem_hits.C
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
32 changes: 16 additions & 16 deletions tests/unit_test_emc_hits.C
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ std::vector<Cell> 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;

Expand Down Expand Up @@ -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<const g2t_vertex_st*>( vertex_table->At(istart-1) ) : 0;
const g2t_vertex_st* vertex = (istart>0 && istart <= vertex_table->GetNRows()) ? static_cast<const g2t_vertex_st*>( vertex_table->At(istart-1) ) : 0;
if ( vertex ) {
result = PASS;
}
Expand All @@ -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<const g2t_vertex_st*>( vertex_table->At(istart-1) );
else
result = " no vertex in table " + result;
Expand Down Expand Up @@ -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;
Expand All @@ -139,15 +147,6 @@ void unit_test_emc_hits() {
auto hit = static_cast<const g2t_emc_hit_st*>( 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;
Expand All @@ -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;
});
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions tests/unit_test_epd_response.C
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "tests/unit_tests.h"
#include <TRandom.h>

//___________________________________________________________________
double _eta = 0;
Expand Down Expand Up @@ -36,11 +37,10 @@ void unit_test_epd_response( int nevents=5000 ) {
assert(sf>0);
float sum = 0.;
auto* table = dynamic_cast<TTable*>( chain->GetDataSet( name ) ) ;
if (table)
table->Print(0,1);
if (0!=table)
for ( int i=0;i<table->GetNRows();i++ ){
const g2t_epd_hit_st* hit = static_cast<const g2t_epd_hit_st*>( table->At(i) );
sum+=hit->de;
if ( hit ) sum+=hit->de;
};
return 1000.0*sum;
};
Expand Down
12 changes: 7 additions & 5 deletions tests/unit_test_fcs_hits.C
Original file line number Diff line number Diff line change
Expand Up @@ -2061,13 +2061,14 @@ void unit_test_fcs_hits() {

auto* chain = StMaker::GetChain();
{
const double pz = 10.0;
auto* _kine = dynamic_cast<StarKinematics*>( 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();
Expand All @@ -2080,7 +2081,6 @@ void unit_test_fcs_hits() {
else
hit_table = dynamic_cast<TTable*>( 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){
Expand Down Expand Up @@ -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();
Expand All @@ -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;
});

Expand Down
7 changes: 4 additions & 3 deletions tests/unit_test_mtd_hits.C
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ void unit_test_mtd_hits( int longtest=0, double _pt=25.0 ) {
auto* chain = StMaker::GetChain();
vertex_table = dynamic_cast<TTable*>( chain->GetDataSet("g2t_vertex") );
track_table = dynamic_cast<TTable*>( chain->GetDataSet("g2t_track") );
if ( hit_table = dynamic_cast<TTable*>( chain->GetDataSet("g2t_mtd_hit") ) ) {
hit_table->Print(0,1);
}
hit_table = dynamic_cast<TTable*>( chain->GetDataSet("g2t_mtd_hit") );



check_track( "A muon must have been processed by geant", [=](const g2t_track_st* t){
Expand Down Expand Up @@ -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;i<hit_table->GetNRows();i++ ) {

auto hit = static_cast<const g2t_mtd_hit_st*>( hit_table->At(i) );
Expand Down
2 changes: 2 additions & 0 deletions tests/unit_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <g2t_fts_hit.h>
#include <g2t_emc_hit.h>
#include <g2t_epd_hit.h>
#include <g2t_ctf_hit.h>
#include <g2t_mtd_hit.h>
#include <TTable.h>
#include <TROOT.h>
#include <string>
Expand Down

0 comments on commit b7407db

Please sign in to comment.