Contents
- Description
- Field Summary
- Constructor Summary
- Method Summary
- Field Details
- Constructor Details
- Method Details
- getHalfWavePlate()
- size()
- addState(HelicityState)
- getBitInQuartet(HelicityBit, int)
- searchIndex(long)
- predictIndex(long)
- getState(int)
- searchState(long)
- get(int)
- search(long)
- search(long, int)
- getGenerated(int)
- predictGenerated(long)
- initialized()
- show()
- getTimestamp(int)
- analyze()
- integrityCheck()
- initialize(HipoReader)
- initialize(List)
- initialize(String...)
- getStates()
- addStream(TreeSet)
- addStream(SchemaFactory, ConstantsManager, List)
- getBanks(SchemaFactory)
- writeFlips(HipoWriterSorted, int)
- writeFlips(HipoWriterSorted, TreeSet)
Class HelicitySequence
java.lang.Object
org.jlab.detector.helicity.HelicitySequence
- Direct Known Subclasses:
HelicitySequenceDelayed
Stores a sequence of helicity states and provides timestamp- or state-count-
based search of helicity state based on the measured sequence or pseudo-random
generator sequence, and provides some integrity checking of the sequence,
including comparing the measured and generator sequences.
____________________________________________________________________
Getter methods naming convention:
Prefixes:
"get" - based on state count
"search" - based on finding timestamp in the measured sequence
"predict" - based on generator seed time and expected periodicity
Suffixes:
"Generated" - use the psuedo-random generator's sequence
____________________________________________________________________
The generator methods are able to look past the measured range, while the
non-generator methods cannot.
The inputs to initialize the sequence are
HelicityState
objects, one
per window at the helicity board clock frequency, which contain important
information for constructing and validating the sequence (e.g. helicity and
sync bits and timestamps).
The return values from getters are just HelicityBit
objects and
represent the HWP-corrected helicity.
See HelicityAnalysisSimple
for an example on using this class.- Author:
- baltzell
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
protected final HelicityGenerator
protected final Map
<Long, HelicityGenerator> protected boolean
protected double
protected HelicityPattern
protected final List
<HelicityState> static final double
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
addState
(HelicityState state) Add a state to the sequence, unless the same timestamp already exists or it has undefined bits, and keep them ordered by timestamp.void
addStream
(TreeSet<HelicityState> states) Detect and add state changes from a "stream" of measured helicities to the sequence.void
addStream
(org.jlab.jnp.hipo4.data.SchemaFactory schema, ConstantsManager conman, List<String> filenames) protected final boolean
analyze()
Analyze the sequence, prune false states, initialize the generator.protected HelicityBit
get
(int n) Get the nth state in the measured sequence.List
<org.jlab.jnp.hipo4.data.Bank> getBanks
(org.jlab.jnp.hipo4.data.SchemaFactory schema) Get a list of HEL::flip banks corresponding to this sequencestatic final HelicityBit
getBitInQuartet
(HelicityBit firstBit, int bitIndex) Given the first helicity state in a quartet, get another bit in that quartet.protected HelicityBit
getGenerated
(int n) Predict the nth state in the sequence.boolean
protected HelicityState
getState
(int n) Get the nth state in the measured sequence.long
getTimestamp
(int index) Get the TI-timestamp of a state in the sequence.void
initialize
(String... filenames) void
initialize
(List<String> filenames) void
initialize
(org.jlab.jnp.hipo4.io.HipoReader reader) boolean
Get whether the pseudo-random generator is initialized.final boolean
Perform integrity checking on the sequence.predictGenerated
(long timestamp) Predict the state of a TI timestamp.int
predictIndex
(long timestamp) Get the state index of a TI timestamp, based only on the first measured state's timestamp and the helicity periodicity.search
(long timestamp) Find the state corresponding to a given timestamp in the measured sequence.search
(long timestamp, int offset) Find the state corresponding to a given timestamp in the measured sequence.protected final int
searchIndex
(long timestamp) Get the state index of a TI timestamp, based on binary search within the measured sequence.protected HelicityState
searchState
(long timestamp) Find the state corresponding to a given timestamp in the measured sequence.void
show()
final int
size()
Get the the number of states in the sequence.void
writeFlips
(org.jlab.jnp.hipo4.io.HipoWriterSorted writer, int tag) Write all states from this sequence into new HEL::flip banks in new, tagged eventsstatic void
writeFlips
(org.jlab.jnp.hipo4.io.HipoWriterSorted writer, TreeSet<HelicityState> stream) Write all state changes from a stream into new HEL::flip banks in new, tagged events
-
Field Details
-
Constructor Details
-
Method Details
-
getHalfWavePlate
public boolean getHalfWavePlate() -
size
public final int size()Get the the number of states in the sequence.- Returns:
- the number of states
-
addState
Add a state to the sequence, unless the same timestamp already exists or it has undefined bits, and keep them ordered by timestamp. Note, theseHelicityState
s do not have to be added in order, as they will be automatically ordered by timestamp upon insertion.- Parameters:
state
- the state to add- Returns:
- whether the state was added
-
getBitInQuartet
Given the first helicity state in a quartet, get another bit in that quartet.- Parameters:
firstBit
- first helicity state in the quartetbitIndex
- index of the state to retrieve (0/1/2/3)- Returns:
- the requested bit
-
searchIndex
protected final int searchIndex(long timestamp) Get the state index of a TI timestamp, based on binary search within the measured sequence. This returns invalid (-1) if the timestamp is not contained within the range of measured states.- Parameters:
timestamp
- TI timestamp (i.e. RUN::config.timestamp)- Returns:
- index
-
predictIndex
public int predictIndex(long timestamp) Get the state index of a TI timestamp, based only on the first measured state's timestamp and the helicity periodicity. This returns invalid (-1) if the timestamp is before the measured states.- Parameters:
timestamp
-- Returns:
- index
-
getState
Get the nth state in the measured sequence.- Parameters:
n
- the index of the state, where 0 corresponds to the first state- Returns:
- the helicity state, null if outside the mesaured range
-
searchState
Find the state corresponding to a given timestamp in the measured sequence.- Parameters:
timestamp
- TI timestamp (i.e. RUN::config.timestamp)- Returns:
- the helicity state, null if timestamp is outside of measured range
-
get
Get the nth state in the measured sequence.- Parameters:
n
- the index of the state, where 0 corresponds to the first state- Returns:
- the helicity state, HelicityBit.UDF if outside the mesaured range
-
search
Find the state corresponding to a given timestamp in the measured sequence.- Parameters:
timestamp
- TI timestamp (i.e. RUN::config.timestamp)- Returns:
- the helicity state, null if timestamp is outside of measured range
-
search
Find the state corresponding to a given timestamp in the measured sequence.- Parameters:
timestamp
- TI timestamp (i.e. RUN::config.timestamp)offset
- number of states offset- Returns:
- the helicity state, null if timestamp is outside of measured range
-
getGenerated
Predict the nth state in the sequence. This uses the pseudo-random sequence of the helicity hardware to generate the sequence into the infinite future and requires that enough states were provided to initialize it. Returns null if generator cannot be initialized or the state is before the measured ones (i.e. negative).- Parameters:
n
- the index of the state- Returns:
- the helicity bit
-
predictGenerated
Predict the state of a TI timestamp. This uses the pseudo-random sequence of the helicity hardware to generate the sequence into the infinite future and requires that enough states were provided to initialize it. Returns null if generator cannot be initialized or timestamp is before the generator timestamp.- Parameters:
timestamp
- TI timestamp (i.e. RUN::config.timestamp)- Returns:
- the helicity bit
-
initialized
public boolean initialized()Get whether the pseudo-random generator is initialized. This must be true before calling the predict methods, because they require a working generator. The number of valid states required to intialize the generator isinvalid reference
HelicityGenerator.REGISTER_SIZE
- Returns:
- whether initialized
-
show
public void show() -
getTimestamp
public long getTimestamp(int index) Get the TI-timestamp of a state in the sequence.- Parameters:
index
- the index of the state- Returns:
- the timestamp of the state
-
analyze
protected final boolean analyze()Analyze the sequence, prune false states, initialize the generator.- Returns:
- sequence integrity
-
integrityCheck
public final boolean integrityCheck()Perform integrity checking on the sequence.- Returns:
- whether the integrity checking succeeded
-
initialize
public void initialize(org.jlab.jnp.hipo4.io.HipoReader reader) -
initialize
-
initialize
-
getStates
-
addStream
Detect and add state changes from a "stream" of measured helicities to the sequence. WARNING: Unlike addState, this requires that previously added states are all earlier in time than the input stream. NOTE: In order to detect state changes, TreeSet is used to ensure the input state stream is sorted by timestamp, HelicityState's natural order.- Parameters:
states
- stream of states
-
addStream
public void addStream(org.jlab.jnp.hipo4.data.SchemaFactory schema, ConstantsManager conman, List<String> filenames) - Parameters:
schema
-conman
-filenames
-
-
getBanks
Get a list of HEL::flip banks corresponding to this sequence- Parameters:
schema
-- Returns:
- list of HEL::flip banks
-
writeFlips
public void writeFlips(org.jlab.jnp.hipo4.io.HipoWriterSorted writer, int tag) Write all states from this sequence into new HEL::flip banks in new, tagged events- Parameters:
writer
-tag
-
-
writeFlips
public static void writeFlips(org.jlab.jnp.hipo4.io.HipoWriterSorted writer, TreeSet<HelicityState> stream) Write all state changes from a stream into new HEL::flip banks in new, tagged events- Parameters:
writer
-stream
-
-