12
12
#include " MantidAPI/SpectrumInfo.h"
13
13
#include " MantidAPI/WorkspaceGroup.h"
14
14
#include " MantidAPI/WorkspaceUnitValidator.h"
15
+ #include " MantidAlgorithms/BeamProfileFactory.h"
15
16
#include " MantidDataObjects/WorkspaceCreation.h"
16
17
#include " MantidGeometry/IDetector.h"
17
18
#include " MantidGeometry/Instrument.h"
@@ -35,6 +36,8 @@ using namespace Geometry;
35
36
using HistogramData::interpolateLinearInplace;
36
37
using namespace Kernel ;
37
38
using namespace Mantid ::DataObjects;
39
+ using Mantid::Algorithms::BeamProfileFactory;
40
+ using Mantid::Geometry::Raster;
38
41
39
42
namespace {
40
43
// the maximum number of elements to combine at once in the pairwise summation
@@ -278,37 +281,46 @@ void PaalmanPingsAbsorptionCorrection::exec() {
278
281
setProperty (" OutputWorkspace" , outWS);
279
282
}
280
283
281
- // / Calculate the distances for L1 (for both self-absorption and
282
- // / absorption by other object) and element size for each element in
283
- // / the sample and container
284
- void PaalmanPingsAbsorptionCorrection::initialiseCachedDistances () {
285
- // First, check if a 'gauge volume' has been defined. If not, it's the same as
286
- // the sample.
287
- auto integrationVolume = std::shared_ptr<const IObject>(m_sampleObject->clone ());
284
+ Raster PaalmanPingsAbsorptionCorrection::rasterize (const IObject *object) {
285
+ IObject_const_sptr integrationVolume;
288
286
if (m_inputWS->run ().hasProperty (" GaugeVolume" )) {
289
287
integrationVolume = constructGaugeVolume ();
288
+ } else {
289
+ try {
290
+ auto beamProfile = BeamProfileFactory::createBeamProfile (*m_inputWS->getInstrument (), Mantid::API::Sample ());
291
+ integrationVolume = beamProfile->getIntersectionWithSample (*object);
292
+ } catch (const std::invalid_argument &) {
293
+ // If createBeamProfile fails, the beam parameters are not defined
294
+ // If getIntersectionWithSample fails, the beam misses the object
295
+ // In either case we will just fall back to using the whole sample below.
296
+ }
297
+ if (integrationVolume == nullptr ) {
298
+ // If the beam profile is not defined, use the sample object
299
+ integrationVolume = std::shared_ptr<const IObject>(object->clone ());
300
+ }
290
301
}
291
302
292
- auto raster = Geometry::Rasterize::calculate (m_beamDirection, *integrationVolume, *m_sampleObject, m_cubeSideSample);
303
+ return Geometry::Rasterize::calculate (m_beamDirection, *integrationVolume, *object, m_cubeSideSample);
304
+ }
305
+
306
+ // / Calculate the distances for L1 (for both self-absorption and
307
+ // / absorption by other object) and element size for each element in
308
+ // / the sample and container
309
+ void PaalmanPingsAbsorptionCorrection::initialiseCachedDistances () {
310
+ auto raster = rasterize (m_sampleObject);
293
311
m_sampleVolume = raster.totalvolume ;
294
312
if (raster.l1 .size () == 0 )
295
- throw std::runtime_error (" Failed to rasterize shape" );
313
+ throw std::runtime_error (" Failed to rasterize sample shape" );
296
314
// move over the information
297
315
m_numSampleVolumeElements = raster.l1 .size ();
298
316
m_sampleL1s = std::move (raster.l1 );
299
317
m_sampleElementPositions = std::move (raster.position );
300
318
m_sampleElementVolumes = std::move (raster.volume );
301
-
302
319
// now for the container
303
- integrationVolume = std::shared_ptr<const IObject>(m_containerObject->clone ());
304
- if (m_inputWS->run ().hasProperty (" GaugeVolume" )) {
305
- integrationVolume = constructGaugeVolume ();
306
- }
307
-
308
- raster = Geometry::Rasterize::calculate (m_beamDirection, *integrationVolume, *m_containerObject, m_cubeSideContainer);
320
+ raster = rasterize (m_containerObject);
309
321
m_containerVolume = raster.totalvolume ;
310
322
if (raster.l1 .size () == 0 )
311
- throw std::runtime_error (" Failed to rasterize shape" );
323
+ throw std::runtime_error (" Failed to rasterize container shape" );
312
324
// move over the information
313
325
m_numContainerVolumeElements = raster.l1 .size ();
314
326
m_containerL1s = std::move (raster.l1 );
0 commit comments