Skip to content

Commit ffe7d19

Browse files
authored
fix(qudarap): treat missing scintillation ICDF as non-fatal (#291)
Some GDML geometries define only optical/Cerenkov material properties and do not include scintillation properties such as FASTCOMPONENT, SLOWCOMPONENT, or REEMISSIONPROB. In those cases U4Scint does not generate `icdf.npy`, so `QSim::UploadComponents` should skip `QScint` setup instead of reporting an error for a valid non-scintillating geometry. Resolves #265
1 parent 51b48c7 commit ffe7d19

3 files changed

Lines changed: 78 additions & 42 deletions

File tree

qudarap/QSim.cc

Lines changed: 60 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,10 @@ void QSim::UploadComponents( const SSim* ssim )
167167
LOG(LEVEL) << " propcom null, snam::PROPCOM " << snam::PROPCOM ;
168168
}
169169

170-
171170
const NP* icdf = ssim->get(snam::ICDF);
172-
if( icdf == nullptr )
171+
if (icdf == nullptr)
173172
{
174-
LOG(error) << " icdf null, snam::ICDF " << snam::ICDF ;
173+
LOG(LEVEL) << " no scintillation ICDF, skip QScint upload. snam::ICDF: " << snam::ICDF;
175174
}
176175
else
177176
{
@@ -180,7 +179,6 @@ void QSim::UploadComponents( const SSim* ssim )
180179
LOG(LEVEL) << scint->desc();
181180
}
182181

183-
184182
// TODO: make this more like the others : acting on the available inputs rather than the mode
185183
bool is_simtrace = SEventConfig::IsRGModeSimtrace() ;
186184
if(is_simtrace == false )
@@ -324,21 +322,23 @@ void QSim::init()
324322
bool MISSING_PMT = REQUIRE_PMT == true && has_PMT == false ;
325323

326324
LOG(LEVEL)
327-
<< " MISSING_PMT " << ( MISSING_PMT ? "YES" : "NO " )
328-
<< " has_PMT " << ( has_PMT ? "YES" : "NO " )
329-
<< " QSim::pmt " << ( pmt ? "YES" : "NO " )
330-
<< " QSim::pmt->d_pmt " << ( sim->pmt ? "YES" : "NO " )
331-
<< " [" << _QSim__REQUIRE_PMT << "] " << ( REQUIRE_PMT ? "YES" : "NO " )
332-
;
333-
334-
LOG_IF(fatal, MISSING_PMT )
325+
<< " MISSING_PMT " << (MISSING_PMT ? "YES" : "NO ")
326+
<< " has_PMT " << (has_PMT ? "YES" : "NO ")
327+
<< " QSim::pmt " << (pmt ? "YES" : "NO ")
328+
<< " QSim::pmt->d_pmt " << (sim->pmt ? "YES" : "NO ")
329+
<< " QSim::scint " << (scint ? "YES" : "NO ")
330+
<< " QSim::scint->d_scint " << (sim->scint ? "YES" : "NO ")
331+
<< " [" << _QSim__REQUIRE_PMT << "] " << (REQUIRE_PMT ? "YES" : "NO ");
332+
333+
LOG_IF(fatal, MISSING_PMT)
335334
<< " MISSING_PMT ABORT "
336-
<< " MISSING_PMT " << ( MISSING_PMT ? "YES" : "NO " )
337-
<< " has_PMT " << ( has_PMT ? "YES" : "NO " )
338-
<< " QSim::pmt " << ( pmt ? "YES" : "NO " )
339-
<< " QSim::pmt->d_pmt " << ( sim->pmt ? "YES" : "NO " )
340-
<< " [" << _QSim__REQUIRE_PMT << "] " << ( REQUIRE_PMT ? "YES" : "NO " )
341-
;
335+
<< " MISSING_PMT " << (MISSING_PMT ? "YES" : "NO ")
336+
<< " has_PMT " << (has_PMT ? "YES" : "NO ")
337+
<< " QSim::pmt " << (pmt ? "YES" : "NO ")
338+
<< " QSim::pmt->d_pmt " << (sim->pmt ? "YES" : "NO ")
339+
<< " QSim::scint " << (scint ? "YES" : "NO ")
340+
<< " QSim::scint->d_scint " << (sim->scint ? "YES" : "NO ")
341+
<< " [" << _QSim__REQUIRE_PMT << "] " << (REQUIRE_PMT ? "YES" : "NO ");
342342

343343
assert(MISSING_PMT == false) ;
344344
if(MISSING_PMT) std::raise(SIGINT);
@@ -350,6 +350,26 @@ void QSim::init()
350350
LOG(LEVEL) << descComponents() ;
351351
}
352352

353+
bool QSim::hasScint() const
354+
{
355+
return sim != nullptr && scint != nullptr && sim->scint != nullptr;
356+
}
357+
358+
void QSim::requireScint(const char *caller) const
359+
{
360+
bool missing_scint = hasScint() == false;
361+
362+
LOG_IF(fatal, missing_scint)
363+
<< caller << " requires scintillation data, but QSim was initialized without QScint"
364+
<< " scint " << (scint ? "YES" : "NO ") << " sim " << (sim ? "YES" : "NO ")
365+
<< " sim->scint " << (sim && sim->scint ? "YES" : "NO ") << " snam::ICDF "
366+
<< snam::ICDF;
367+
368+
assert(missing_scint == false);
369+
if (missing_scint)
370+
std::raise(SIGINT);
371+
}
372+
353373
/**
354374
QSim::setLauncher
355375
------------------
@@ -898,6 +918,7 @@ qsim* QSim::getDevicePtr() const
898918

899919
char QSim::getScintTexFilterMode() const
900920
{
921+
requireScint("QSim::getScintTexFilterMode");
901922
return scint->tex->getFilterMode() ;
902923
}
903924

@@ -941,25 +962,24 @@ std::string QSim::descComponents() const
941962
{
942963
std::stringstream ss ;
943964
ss << std::endl
944-
<< "QSim::descComponents"
945-
<< std::endl
946-
<< " (QBase)base " << ( base ? "YES" : "NO " ) << std::endl
947-
<< " (QEvt)qev " << ( qev ? "YES" : "NO " ) << std::endl
948-
<< " (SEvt)sev " << ( sev ? "YES" : "NO " ) << std::endl
949-
<< " (QRng)rng " << ( rng ? "YES" : "NO " ) << std::endl
950-
<< " (QScint)scint " << ( scint ? "YES" : "NO " ) << std::endl
951-
<< " (QCerenkov)cerenkov " << ( cerenkov ? "YES" : "NO " ) << std::endl
952-
<< " (QBnd)bnd " << ( bnd ? "YES" : "NO " ) << std::endl
953-
<< " (QOptical)optical " << ( optical ? "YES" : "NO " ) << std::endl
954-
<< " (QDebug)debug_ " << ( debug_ ? "YES" : "NO " ) << std::endl
955-
<< " (QProp)prop " << ( prop ? "YES" : "NO " ) << std::endl
956-
<< " (QPMT)pmt " << ( pmt ? "YES" : "NO " ) << std::endl
957-
<< " (QMultiFilm)multifilm " << ( multifilm ? "YES" : "NO " ) << std::endl
958-
<< " (qsim)sim " << ( sim ? "YES" : "NO " ) << std::endl
959-
<< " (qsim)d_sim " << ( d_sim ? "YES" : "NO " ) << std::endl
960-
<< " (qdebug)dbg " << ( dbg ? "YES" : "NO " ) << std::endl
961-
<< " (qdebug)d_dbg " << ( d_dbg ? "YES" : "NO " ) << std::endl
962-
;
965+
<< "QSim::descComponents" << std::endl
966+
<< " (QBase)base " << (base ? "YES" : "NO ") << std::endl
967+
<< " (QEvt)qev " << (qev ? "YES" : "NO ") << std::endl
968+
<< " (SEvt)sev " << (sev ? "YES" : "NO ") << std::endl
969+
<< " (QRng)rng " << (rng ? "YES" : "NO ") << std::endl
970+
<< " (QScint)scint " << (scint ? "YES" : "NO ") << std::endl
971+
<< " (QCerenkov)cerenkov " << (cerenkov ? "YES" : "NO ") << std::endl
972+
<< " (QBnd)bnd " << (bnd ? "YES" : "NO ") << std::endl
973+
<< " (QOptical)optical " << (optical ? "YES" : "NO ") << std::endl
974+
<< " (QDebug)debug_ " << (debug_ ? "YES" : "NO ") << std::endl
975+
<< " (QProp)prop " << (prop ? "YES" : "NO ") << std::endl
976+
<< " (QPMT)pmt " << (pmt ? "YES" : "NO ") << std::endl
977+
<< " (QMultiFilm)multifilm " << (multifilm ? "YES" : "NO ") << std::endl
978+
<< " (qsim)sim " << (sim ? "YES" : "NO ") << std::endl
979+
<< " (qsim)hasScint " << (hasScint() ? "YES" : "NO ") << std::endl
980+
<< " (qsim)d_sim " << (d_sim ? "YES" : "NO ") << std::endl
981+
<< " (qdebug)dbg " << (dbg ? "YES" : "NO ") << std::endl
982+
<< " (qdebug)d_dbg " << (d_dbg ? "YES" : "NO ") << std::endl;
963983
std::string s = ss.str();
964984
return s ;
965985
}
@@ -1171,6 +1191,7 @@ extern void QSim_scint_wavelength( dim3 numBlocks, dim3 threadsPerBlock, qsim*
11711191

11721192
NP* QSim::scint_wavelength(unsigned num_wavelength, unsigned& hd_factor )
11731193
{
1194+
requireScint("QSim::scint_wavelength");
11741195

11751196
bool qsim_disable_hd = ssys::getenvbool("QSIM_DISABLE_HD");
11761197
hd_factor = qsim_disable_hd ? 0u : scint->tex->getHDFactor() ;
@@ -1239,6 +1260,8 @@ extern void QSim_dbg_gs_generate(dim3 numBlocks, dim3 threadsPerBlock, qsim* sim
12391260
NP* QSim::dbg_gs_generate(unsigned num_photon, unsigned type )
12401261
{
12411262
assert( type == SCINT_GENERATE || type == CERENKOV_GENERATE );
1263+
if (type == SCINT_GENERATE)
1264+
requireScint("QSim::dbg_gs_generate");
12421265

12431266
configureLaunch( num_photon, 1 );
12441267
sphoton* d_photon = QU::device_alloc<sphoton>(num_photon, "QSim::dbg_gs_generate:num_photon") ;
@@ -2053,5 +2076,3 @@ std::string QSim::Switches() // static
20532076
{
20542077
return Desc(',');
20552078
}
2056-
2057-

qudarap/QSim.cu

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ __global__ void _QSim_scint_wavelength(qsim* sim, float* wavelength, unsigned nu
8181
unsigned id = blockIdx.x*blockDim.x + threadIdx.x;
8282
if (id >= num_wavelength) return;
8383

84+
if (sim->scint == nullptr)
85+
{
86+
if (id == 0)
87+
printf("//_QSim_scint_wavelength missing scint, returning zeros \n");
88+
wavelength[id] = 0.f;
89+
return;
90+
}
91+
8492
RNG rng ;
8593
sim->rng->init(rng, 0, id ) ;
8694

@@ -161,7 +169,14 @@ __global__ void _QSim_dbg_gs_generate(qsim* sim, qdebug* dbg, sphoton* photon, u
161169
else if( type == SCINT_GENERATE )
162170
{
163171
const quad6& gs = (const quad6&)dbg->scint_gs ;
164-
sim->scint->generate(p, rng, gs, idx, gsid );
172+
if (sim->scint != nullptr)
173+
{
174+
sim->scint->generate(p, rng, gs, idx, gsid );
175+
}
176+
else if (idx == 0)
177+
{
178+
printf("//_QSim_dbg_gs_generate missing scint, leaving photon zeroed \n");
179+
}
165180
}
166181
photon[idx] = p ;
167182
}

qudarap/QSim.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ struct QUDARAP_API QSim
9898
private:
9999
QSim();
100100
void init();
101+
void requireScint(const char *caller) const;
101102

102103
static constexpr const char* _QSim__REQUIRE_PMT = "QSim__REQUIRE_PMT" ;
103104
static const bool REQUIRE_PMT;
@@ -141,7 +142,7 @@ public:
141142
std::string desc() const ;
142143
std::string descFull() const ;
143144
std::string descComponents() const ;
144-
145+
bool hasScint() const;
145146

146147
// TODO: relocate non-essential methods into tests or elsewhere
147148

@@ -213,4 +214,3 @@ public:
213214
static std::string Switches();
214215
};
215216

216-

0 commit comments

Comments
 (0)