-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from francois-drielsma/develop
Keep up
- Loading branch information
Showing
5 changed files
with
180 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
"""Analysis module template. | ||
Use this template as a basis to build your own analysis script. An analysis | ||
script takes the output of the reconstruction and the post-processors and | ||
performs basic selection cuts and store the output to a CSV file. | ||
""" | ||
|
||
# Add the imports specific to this module here | ||
# import ... | ||
|
||
# Must import the analysis script base class | ||
from spine.ana.base import AnaBase | ||
|
||
# Must list the post-processor(s) here to be found by the factory. | ||
# You must also add it to the list of imported modules in the | ||
# `spine.ana.factories`! | ||
__all__ = ['TemplateAna'] | ||
|
||
|
||
class TemplateAna(AnaBase): | ||
"""Description of what the analysis script is supposed to be doing.""" | ||
name = 'segment_eval' | ||
|
||
def __init__(self, arg0, arg1, obj_type, run_mode, append_file, | ||
overwrite_file, output_prefix): | ||
"""Initialize the analysis script. | ||
Parameters | ||
---------- | ||
arg0 : type | ||
Description of arg0 | ||
arg1 : type | ||
Description of arg1 | ||
obj_type : Union[str, List[str]] | ||
Name or list of names of the object types to process | ||
run_mode : str, optional | ||
If specified, tells whether the post-processor must run on | ||
reconstructed ('reco'), true ('true') or both objects | ||
('both' or 'all') | ||
append_file : bool, default False | ||
If True, appends existing CSV files instead of creating new ones | ||
overwrite_file : bool, default False | ||
If True and the output CSV file exists, overwrite it | ||
output_prefix : str, default None | ||
Name to prefix every output CSV file with | ||
""" | ||
# Initialize the parent class | ||
super().__init__( | ||
obj_type, run_mode, append_file, overwrite_file, output_prefix) | ||
|
||
# Store parameter | ||
self.arg0 = arg0 | ||
self.arg1 = arg1 | ||
|
||
# Initialize the CSV writer(s) you want | ||
self.initialize_writer('template') | ||
|
||
# Add additional required data products | ||
self.keys['prod'] = True # Means we must have 'data' in the dictionary | ||
|
||
def process(self, data): | ||
"""Pass data products corresponding to one entry through the analysis. | ||
Parameters | ||
---------- | ||
data : dict | ||
Dictionary of data products | ||
""" | ||
# Fetch the keys you want | ||
data = data['prod'] | ||
|
||
# Loop over all requested object types | ||
for key in self.obj_keys: | ||
# Loop over all objects of that type | ||
for obj in data[key]: | ||
# Do something with the object | ||
disp = p.end_point - p.start_point | ||
|
||
# Make a dictionary of integer out of it | ||
out = {'disp_x': disp[0], 'disp_y': disp[1], 'disp_z': disp[2]} | ||
|
||
# Write the row to file | ||
self.append('template', **out) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
"""Post-processor module template. | ||
Use this template as a basis to build your own post-processor. A post-processor | ||
takes the output of the reconstruction and either | ||
- Sets additional reconstruction attributes (e.g. direction estimates) | ||
- Adds entirely new data products (e.g. trigger time) | ||
""" | ||
|
||
# Add the imports specific to this module here | ||
# import ... | ||
|
||
# Must import the post-processor base class | ||
from spine.post.base import PostBase | ||
|
||
# Must list the post-processor(s) here to be found by the factory. | ||
# You must also add it to the list of imported modules in the | ||
# `spine.post.factories`! | ||
__all__ = ['TemplateProcssor'] | ||
|
||
|
||
class TemplateProcessor(PostBase): | ||
"""Description of what the post-processor is supposed to be doing.""" | ||
name = 'template' # Name used to call the post-processor in the config | ||
|
||
def __init__(self, arg0, arg1, obj_type, run_mode): | ||
"""Initialize the post-processor. | ||
Parameters | ||
---------- | ||
arg0 : type | ||
Description of arg0 | ||
arg1 : type | ||
Description of arg1 | ||
obj_type : Union[str, List[str]] | ||
Types of objects needed in this post-processor (fragments, | ||
particles and/or interactions). This argument is shared between | ||
all post-processors. If None, does not load these objects. | ||
run_mode : str | ||
One of 'reco', 'truth' or 'both'. Determines what kind of object | ||
the post-processor has to run on. | ||
""" | ||
# Initialize the parent class | ||
super().__init__(obj_type, run_mode) | ||
|
||
# Store parameter | ||
self.arg0 = arg0 | ||
self.arg1 = arg1 | ||
|
||
# Add additional required data products | ||
self.keys['prod'] = True # Means we must have 'prod' in the dictionary | ||
|
||
def process(self, data): | ||
"""Pass data products corresponding to one entry through the processor. | ||
Parameters | ||
---------- | ||
data : dict | ||
Dictionary of data products | ||
""" | ||
# Fetch the keys you want | ||
data = data['prod'] | ||
|
||
# Loop over all requested object types | ||
for key in self.obj_keys: | ||
# Loop over all objects of that type | ||
for obj in data[key]: | ||
# Fetch points attributes | ||
points = self.get_points(obj) | ||
|
||
# Get another attribute | ||
sources = obj.sources | ||
|
||
# Do something... | ||
|
||
# Loop over requested specific types of objects | ||
for key in self.fragment_keys: | ||
# Do something... | ||
pass | ||
|
||
for key in self.particle_keys: | ||
# Do something... | ||
pass | ||
|
||
for key in self.interaction_keys: | ||
# Do something... | ||
pass | ||
|
||
# Return an update or override to the current data product dictionary | ||
return {} # Can have no return as well if objects are edited in place |