def test1(self): 'detector hierarchy from xml' from instrument.nixml import parse_file instrument = parse_file( 'ARCS.xml' ) import instrument.geometers as ig instrument.geometer.changeRequestCoordinateSystem( ig.coordinateSystem( coordinate_system ) ) assignLocalGeometers( instrument, coordinate_system = coordinate_system ) detectorSystem = instrument.getDetectorSystem() tofparams = 0, 10e-3, 1e-4 detectorSystem.tofparams = tofparams dims = getDetectorHierarchyDimensions( instrument ) dims = [ dim for name, dim in dims ] mca = md.eventModeMCA( outfilename, dims ) detectorSystem.mca = mca cds = mh.scattererEngine( detectorSystem, coordinate_system = coordinate_system ) for i in range(nevents): if i%1000 == 0: print i ev = mcni.neutron( r = (0,0,0), v = (1500,0,2000) ) cds.scatter(ev) continue instrument.geometer = instrument.global_geometer return
def detectorcomponent(name, instrumentxml, coordinate_system, tofparams, outfilename): import mccomposite.extensions.Copy import mccomposite.extensions.HollowCylinder import mccomponents.detector.optional_extensions.Detector from instrument.nixml import parse_file instrument = parse_file(instrumentxml) import instrument.geometers as ig instrument.geometer.changeRequestCoordinateSystem( ig.coordinateSystem(coordinate_system)) from mccomponents.detector.utils import \ getDetectorHierarchyDimensions, assignLocalGeometers assignLocalGeometers(instrument, coordinate_system=coordinate_system) detectorSystem = instrument.getDetectorSystem() detectorSystem.tofparams = tofparams dims = getDetectorHierarchyDimensions(instrument) dims = [dim for name, dim in dims] mca = eventModeMCA(outfilename, dims) detectorSystem.mca = mca import mccomponents.homogeneous_scatterer as mh cds = mh.scattererEngine(detectorSystem, coordinate_system=coordinate_system) instrument.geometer = instrument.global_geometer cds.name = name return cds
def events2Idpt( events, instrument, tofparams ): from mccomponents.detector.utils import \ getDetectorHierarchyDimensions dims = getDetectorHierarchyDimensions( instrument ) # 1st attempt to create axes from histogram import histogram, axis, arange axes = [ axis('%sID' % name.lower(), range(n)) for name, n in dims ] # the first level of detectors (tubes, packs, or others) need # special attention. ids of that level could be not continuous. detectorSystem = instrument.getDetectorSystem() assert len(detectorSystem.elements()) == dims[0][1] ids = [ element.id() for element in detectorSystem.elements() ] axes[0] = axis( axes[0].name(), ids ) detaxes = axes #tof axis tmin, tmax, tstep = tofparams tofaxis = axis( 'tof', boundaries = arange( tmin, tmax+tstep/10., tstep ), unit = 'second' ) #all axes axes = detaxes + [tofaxis] #histogram hist = histogram( 'Idpt', axes ) #get the numpy array which will accept events npixels = hist.size()/tofaxis.size() Ipixtof = hist.data().storage().asNumarray() Ipixtof.shape = npixels, -1 events2Ipixtof( events, Ipixtof ) return hist
def test1(self): 'detector hierarchy from xml' from instrument.nixml import parse_file instrument = parse_file('ARCS.xml') import instrument.geometers as ig instrument.geometer.changeRequestCoordinateSystem( ig.coordinateSystem(coordinate_system)) assignLocalGeometers(instrument, coordinate_system=coordinate_system) detectorSystem = instrument.getDetectorSystem() tofparams = 0, 10e-3, 1e-4 detectorSystem.tofparams = tofparams dims = getDetectorHierarchyDimensions(instrument) dims = [dim for name, dim in dims] mca = md.eventModeMCA(outfilename, dims) detectorSystem.mca = mca cds = mh.scattererEngine(detectorSystem, coordinate_system=coordinate_system) for i in range(nevents): if i % 1000 == 0: print i ev = mcni.neutron(r=(0, 0, 0), v=(2000, 1500, 0)) cds.scatter(ev) continue instrument.geometer = instrument.global_geometer return
def events2Idpt(events, instrument, tofparams): from mccomponents.detector.utils import \ getDetectorHierarchyDimensions dims = getDetectorHierarchyDimensions(instrument) # 1st attempt to create axes from histogram import histogram, axis, arange axes = [axis('%sID' % name.lower(), range(n)) for name, n in dims] # the first level of detectors (tubes, packs, or others) need # special attention. ids of that level could be not continuous. detectorSystem = instrument.getDetectorSystem() assert len(detectorSystem.elements()) == dims[0][1] ids = [element.id() for element in detectorSystem.elements()] axes[0] = axis(axes[0].name(), ids) detaxes = axes #tof axis tmin, tmax, tstep = tofparams tofaxis = axis('tof', boundaries=arange(tmin, tmax + tstep / 10., tstep), unit='second') #all axes axes = detaxes + [tofaxis] #histogram hist = histogram('Idpt', axes) #get the numpy array which will accept events npixels = hist.size() / tofaxis.size() Ipixtof = hist.data().storage().asNumarray() Ipixtof.shape = npixels, -1 events2Ipixtof(events, Ipixtof) return hist