diff --git a/.clang-format b/.clang-format index d94a292..a5890c8 100644 --- a/.clang-format +++ b/.clang-format @@ -1,75 +1,75 @@ --- -Language: Cpp +Language: Cpp AccessModifierOffset: -2 AlignAfterOpenBracket: Align AlignArrayOfStructures: None AlignConsecutiveAssignments: - Enabled: false + Enabled: false AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false + AcrossComments: false + AlignCompound: false AlignFunctionDeclarations: false AlignFunctionPointers: false - PadOperators: true + PadOperators: true AlignConsecutiveBitFields: - Enabled: false + Enabled: false AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false + AcrossComments: false + AlignCompound: false AlignFunctionDeclarations: false AlignFunctionPointers: false - PadOperators: false + PadOperators: false AlignConsecutiveDeclarations: - Enabled: false + Enabled: false AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false + AcrossComments: false + AlignCompound: false AlignFunctionDeclarations: true AlignFunctionPointers: false - PadOperators: false + PadOperators: false AlignConsecutiveMacros: - Enabled: false + Enabled: false AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false + AcrossComments: false + AlignCompound: false AlignFunctionDeclarations: false AlignFunctionPointers: false - PadOperators: false + PadOperators: false AlignConsecutiveShortCaseStatements: - Enabled: false + Enabled: false AcrossEmptyLines: false - AcrossComments: false + AcrossComments: false AlignCaseArrows: false AlignCaseColons: false AlignConsecutiveTableGenBreakingDAGArgColons: - Enabled: false + Enabled: false AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false + AcrossComments: false + AlignCompound: false AlignFunctionDeclarations: false AlignFunctionPointers: false - PadOperators: false + PadOperators: false AlignConsecutiveTableGenCondOperatorColons: - Enabled: false + Enabled: false AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false + AcrossComments: false + AlignCompound: false AlignFunctionDeclarations: false AlignFunctionPointers: false - PadOperators: false + PadOperators: false AlignConsecutiveTableGenDefinitionColons: - Enabled: false + Enabled: false AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false + AcrossComments: false + AlignCompound: false AlignFunctionDeclarations: false AlignFunctionPointers: false - PadOperators: false + PadOperators: false AlignEscapedNewlines: Right -AlignOperands: Align +AlignOperands: Align AlignTrailingComments: - Kind: Always - OverEmptyLines: 0 + Kind: Always + OverEmptyLines: 0 AllowAllArgumentsOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true AllowBreakBeforeNoexceptSpecifier: Never @@ -89,21 +89,21 @@ BinPackArguments: false BinPackParameters: false BitFieldColonSpacing: Both BraceWrapping: - AfterCaseLabel: false - AfterClass: false + AfterCaseLabel: false + AfterClass: false AfterControlStatement: Never - AfterEnum: false + AfterEnum: false AfterExternBlock: false - AfterFunction: true - AfterNamespace: false + AfterFunction: true + AfterNamespace: false AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - BeforeCatch: false - BeforeElse: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false BeforeLambdaBody: false - BeforeWhile: false - IndentBraces: false + BeforeWhile: false + IndentBraces: false SplitEmptyFunction: true SplitEmptyRecord: false SplitEmptyNamespace: false @@ -111,7 +111,7 @@ BreakAdjacentStringLiterals: true BreakAfterAttributes: Leave BreakAfterJavaFieldAnnotations: false BreakAfterReturnType: None -BreakArrays: true +BreakArrays: true BreakBeforeBinaryOperators: None BreakBeforeConceptDeclarations: Always BreakBeforeBraces: Custom @@ -123,14 +123,14 @@ BreakFunctionDefinitionParameters: false BreakInheritanceList: AfterColon BreakStringLiterals: true BreakTemplateDeclarations: Yes -ColumnLimit: 100 -CommentPragmas: '^ IWYU pragma:' +ColumnLimit: 100 +CommentPragmas: "^ IWYU pragma:" CompactNamespaces: false ConstructorInitializerIndentWidth: 2 ContinuationIndentWidth: 2 Cpp11BracedListStyle: true DerivePointerAlignment: false -DisableFormat: false +DisableFormat: false EmptyLineAfterAccessModifier: Never EmptyLineBeforeAccessModifier: LogicalBlock ExperimentalAutoDetectBinPacking: false @@ -141,22 +141,22 @@ ForEachMacros: - BOOST_FOREACH IfMacros: - KJ_IF_MAYBE -IncludeBlocks: Preserve +IncludeBlocks: Preserve IncludeCategories: - - Regex: '^"(llvm|llvm-c|clang|clang-c)/' - Priority: 2 - SortPriority: 0 - CaseSensitive: false - - Regex: '^(<|"(gtest|gmock|isl|json)/)' - Priority: 3 - SortPriority: 0 - CaseSensitive: false - - Regex: '.*' - Priority: 1 - SortPriority: 0 - CaseSensitive: false -IncludeIsMainRegex: '(Test)?$' -IncludeIsMainSourceRegex: '' + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: ".*" + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: "(Test)?$" +IncludeIsMainSourceRegex: "" IndentAccessModifiers: false IndentCaseBlocks: false IndentCaseLabels: false @@ -165,29 +165,29 @@ IndentExternBlock: AfterExternBlock IndentGotoLabels: true IndentPPDirectives: None IndentRequiresClause: true -IndentWidth: 2 +IndentWidth: 2 IndentWrappedFunctionNames: false -InsertBraces: false +InsertBraces: false InsertNewlineAtEOF: false InsertTrailingCommas: None IntegerLiteralSeparator: - Binary: 0 + Binary: 0 BinaryMinDigits: 0 - Decimal: 0 + Decimal: 0 DecimalMinDigits: 0 - Hex: 0 - HexMinDigits: 0 + Hex: 0 + HexMinDigits: 0 JavaScriptQuotes: Leave JavaScriptWrapImports: true KeepEmptyLines: - AtEndOfFile: false - AtStartOfBlock: true - AtStartOfFile: false -KeepFormFeed: false + AtEndOfFile: false + AtStartOfBlock: true + AtStartOfFile: false +KeepFormFeed: false LambdaBodyIndentation: Signature -LineEnding: DeriveLF -MacroBlockBegin: '' -MacroBlockEnd: '' +LineEnding: DeriveLF +MacroBlockBegin: "" +MacroBlockEnd: "" MainIncludeChar: Quote MaxEmptyLinesToKeep: 1 NamespaceIndentation: All @@ -210,10 +210,10 @@ PenaltyExcessCharacter: 1000000 PenaltyIndentedWhitespace: 0 PenaltyReturnTypeOnItsOwnLine: 200 PointerAlignment: Left -PPIndentWidth: -1 +PPIndentWidth: -1 QualifierAlignment: Right ReferenceAlignment: Pointer -ReflowComments: false +ReflowComments: false RemoveBracesLLVM: false RemoveEmptyLinesInUnwrappedLines: false RemoveParentheses: Leave @@ -223,7 +223,7 @@ RequiresExpressionIndentation: OuterScope SeparateDefinitionBlocks: Leave ShortNamespaceLines: 1 SkipMacroDefinitionBody: false -SortIncludes: CaseSensitive +SortIncludes: CaseSensitive SortJavaStaticImport: Before SortUsingDeclarations: LexicographicNumeric SpaceAfterCStyleCast: false @@ -242,7 +242,7 @@ SpaceBeforeParensOptions: AfterForeachMacros: true AfterFunctionDefinitionName: false AfterFunctionDeclarationName: false - AfterIfMacros: true + AfterIfMacros: true AfterOverloadedOperator: false AfterPlacementOperator: true AfterRequiresInClause: false @@ -252,28 +252,28 @@ SpaceBeforeRangeBasedForLoopColon: true SpaceBeforeSquareBrackets: false SpaceInEmptyBlock: false SpacesBeforeTrailingComments: 1 -SpacesInAngles: Never +SpacesInAngles: Never SpacesInContainerLiterals: true SpacesInLineCommentPrefix: - Minimum: 1 - Maximum: -1 -SpacesInParens: Never + Minimum: 1 + Maximum: -1 +SpacesInParens: Never SpacesInParensOptions: ExceptDoubleParentheses: false - InCStyleCasts: false + InCStyleCasts: false InConditionalStatements: false InEmptyParentheses: false - Other: false + Other: false SpacesInSquareBrackets: false -Standard: Latest +Standard: Latest StatementAttributeLikeMacros: - Q_EMIT StatementMacros: - Q_UNUSED - QT_REQUIRE_VERSION TableGenBreakInsideDAGArg: DontBreak -TabWidth: 8 -UseTab: Never +TabWidth: 8 +UseTab: Never VerilogBreakBetweenInstancePorts: true WhitespaceSensitiveMacros: - BOOST_PP_STRINGIZE diff --git a/.gersemirc b/.gersemirc new file mode 100644 index 0000000..acc04e9 --- /dev/null +++ b/.gersemirc @@ -0,0 +1,13 @@ +# gersemi is an opinionated formatter and does not support the same +# level of configuration as cmake-format. The previous settings from +# .cmake-format.json (dangle_align and dangle_parens) are not +# supported and have no direct equivalents. + +definitions: [] +disable_formatting: false +extensions: [] +indent: 2 +line_length: 99 +list_expansion: favour-inlining +unsafe: false +warn_about_unknown_commands: false diff --git a/.markdownlint.yaml b/.markdownlint.yaml new file mode 100644 index 0000000..8f4673f --- /dev/null +++ b/.markdownlint.yaml @@ -0,0 +1,2 @@ +MD013: + ignore_code_blocks: true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..85b9a54 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,60 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks + +# Everything in copied_from_larsoft_minor_edits is copied from larsoft and should not be modified. +# It is excluded from pre-commit checks to avoid unnecessary noise. +exclude: ^migration/gauss_hit_finder/copied_from_larsoft_minor_edits/ + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-toml + - id: check-merge-conflict + - id: check-vcs-permalinks + - id: check-executables-have-shebangs + - id: mixed-line-ending + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.15.19 + hooks: + - id: ruff-format + types_or: [python, pyi] + - id: ruff + types_or: [python, pyi] + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v20.1.8 + hooks: + - id: clang-format + types_or: [c++, c, cuda] + - repo: local + hooks: + - id: fix-header-guards + name: fix C++ header guards + entry: python3 scripts/fix_header_guards.py + language: system + files: \.(h|hpp)$ + - repo: https://github.com/BlankSpruce/gersemi-pre-commit + rev: 0.27.7 + hooks: + - id: gersemi + - repo: https://github.com/google/go-jsonnet + rev: v0.22.0 + hooks: + - id: jsonnet-format + - id: jsonnet-lint + # The files in test/max-parallelism import files that are generated during the build. + # We therefore exclude them from linting, but still format them. + exclude: ^test/max-parallelism + - repo: https://github.com/rbubley/mirrors-prettier + rev: v3.8.4 + hooks: + - id: prettier + types_or: [yaml] + - repo: https://github.com/DavidAnson/markdownlint-cli2 + rev: v0.22.1 + hooks: + - id: markdownlint-cli2 + args: [--fix] diff --git a/README.md b/README.md index 1eae253..7e8982a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Phlex examples -This repository contains examples of the use of the [Phlex framework](https://github.com/framework-r-d/phlex). +This repository contains examples of the use of the +[Phlex framework](https://github.com/framework-r-d/phlex). ## Building this repository @@ -11,12 +12,14 @@ git clone -b phlex-v0.3 https://github.com/Framework-R-D/phlex-examples.git ``` Now create a build directory: + ```console mkdir build-phlex-examples cd build-phlex-examples ``` -The repository can now be easily built by activating [the environment you created when installing Phlex](https://github.com/Framework-R-D/phlex/blob/main/INSTALLATION.md#creating-and-installing-the-phlex-environment): +The repository can now be easily built by activating +[the environment you created when installing Phlex](https://github.com/Framework-R-D/phlex/blob/main/INSTALLATION.md#creating-and-installing-the-phlex-environment): ```console spack env activate my-phlex-environment @@ -60,7 +63,8 @@ Processed layers: │ └ spill: 10 -[2025-12-22 13:17:51.760] [info] CPU time: 0.21204s Real time: 0.26498s CPU efficiency: 80.02% +[2025-12-22 13:17:51.760] [info] CPU time: 0.21204s Real time: 0.26498s + CPU efficiency: 80.02% [2025-12-22 13:17:51.760] [info] Max. RSS: 268.848 MB ``` @@ -94,7 +98,8 @@ Processed layers: ### Job with Python algorithms -To run a job that uses a Python algorithm, the `PYTHONPATH` environment variable must be adjusted to include the directory with the Python module: +To run a job that uses a Python algorithm, the `PYTHONPATH` environment variable +must be adjusted to include the directory with the Python module: ```console export PYTHONPATH=$(realpath ../phlex-examples):${PYTHONPATH} @@ -111,12 +116,14 @@ Processed layers: job -[2025-12-22 13:50:08.013] [info] CPU time: 0.01022s Real time: 0.01483s CPU efficiency: 68.91% +[2025-12-22 13:50:08.013] [info] CPU time: 0.01022s Real time: 0.01483s + CPU efficiency: 68.91% [2025-12-22 13:50:08.013] [info] Max. RSS: 29.628 MB ``` > [!NOTE] > For Phlex v0.1.0, Python data products: +> > - Cannot be written to output files > - Must belong to the `"job"` data layer > diff --git a/migration/doc/conf.py b/migration/doc/conf.py index d055437..026df93 100644 --- a/migration/doc/conf.py +++ b/migration/doc/conf.py @@ -7,16 +7,20 @@ import subprocess import sys -sys.path.insert(0, os.path.abspath('.') + '/_extensions') +sys.path.insert(0, os.path.abspath(".") + "/_extensions") # -- Project information ----------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information -project = 'Migration Guide' -copyright = '2026, Fermi Forward Discovery Group, LLC' -author = '' +project = "Migration Guide" +copyright = "2026, Fermi Forward Discovery Group, LLC" +author = "" -git_commit = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('ascii').strip() +git_commit = ( + subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]) + .decode("ascii") + .strip() +) release = f"0.1.alpha ({git_commit})" @@ -24,18 +28,18 @@ # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration extensions = [ - 'sphinx.ext.autosectionlabel', + "sphinx.ext.autosectionlabel", ] -exclude_patterns = ['.venv/**', '.venv'] +exclude_patterns = [".venv/**", ".venv"] autosectionlabel_prefix_document = True numfig = True numfig_format = { - 'code-block': 'Listing %s', - 'figure': 'Fig. %s', - 'section': 'Section %s', - 'table': 'Table %s', + "code-block": "Listing %s", + "figure": "Fig. %s", + "section": "Section %s", + "table": "Table %s", } @@ -54,23 +58,20 @@ # -- Options for HTML output ------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output -html_theme = 'bizstyle' -html_logo = 'art-to-phlex.png' -html_static_path = ['_static'] -html_style = 'phlexframework.css' +html_theme = "bizstyle" +html_logo = "art-to-phlex.png" +html_static_path = ["_static"] +html_style = "phlexframework.css" html_last_updated_fmt = "" # Equivalent to showing (e.g.) May 29, 2025 # -- Options for LaTeX output ------------------------------------------------ # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-latex-output -latex_logo = 'art-to-phlex.png' +latex_logo = "art-to-phlex.png" latex_elements = {} -latex_documents = [("index", - "phlex-migration-guide.tex", - project, - author, - "manual", - False)] +latex_documents = [ + ("index", "phlex-migration-guide.tex", project, author, "manual", False) +] latex_table_style = ["booktabs"] diff --git a/migration/gauss_hit_finder/CMakeLists.txt b/migration/gauss_hit_finder/CMakeLists.txt index 0980581..8ab5f63 100644 --- a/migration/gauss_hit_finder/CMakeLists.txt +++ b/migration/gauss_hit_finder/CMakeLists.txt @@ -1,20 +1,22 @@ # Proxies for framework-agnostic experiment libraries # N.B. The specified library type should be SHARED. -add_library(find_hits_with_gaussians SHARED - find_hits_with_gaussians_design0.cpp - find_hits_with_gaussians_design1.cpp - find_hits_with_gaussians_design2.cpp - find_hits_with_gaussians_design3.cpp - cand_hit_standard.cpp - copied_from_larsoft_minor_edits/Hit.cxx - copied_from_larsoft_minor_edits/geo_types.cxx - copied_from_larsoft_minor_edits/CandHitStandard.cxx - copied_from_larsoft_minor_edits/PeakFitterMrqdt.cxx - copied_from_larsoft_minor_edits/HitFilterAlg.cxx - copied_from_larsoft_minor_edits/MarqFitAlg.cxx - copied_from_larsoft_minor_edits/Wire.cxx - wire_serialization.cpp - print_hits_to_file.cpp +add_library( + find_hits_with_gaussians + SHARED + find_hits_with_gaussians_design0.cpp + find_hits_with_gaussians_design1.cpp + find_hits_with_gaussians_design2.cpp + find_hits_with_gaussians_design3.cpp + cand_hit_standard.cpp + copied_from_larsoft_minor_edits/Hit.cxx + copied_from_larsoft_minor_edits/geo_types.cxx + copied_from_larsoft_minor_edits/CandHitStandard.cxx + copied_from_larsoft_minor_edits/PeakFitterMrqdt.cxx + copied_from_larsoft_minor_edits/HitFilterAlg.cxx + copied_from_larsoft_minor_edits/MarqFitAlg.cxx + copied_from_larsoft_minor_edits/Wire.cxx + wire_serialization.cpp + print_hits_to_file.cpp ) target_link_libraries(find_hits_with_gaussians PRIVATE TBB::tbb fmt::fmt) @@ -27,21 +29,26 @@ set(designs 0 1 2 3) # Register experiment libraries with Phlex foreach(d IN LISTS designs) - add_library(find_hits_with_gaussians_design${d}_hof MODULE - register_find_hits_with_gaussians_design${d}.cpp) - target_link_libraries(find_hits_with_gaussians_design${d}_hof PRIVATE - phlex::module find_hits_with_gaussians) + add_library( + find_hits_with_gaussians_design${d}_hof + MODULE + register_find_hits_with_gaussians_design${d}.cpp + ) + target_link_libraries( + find_hits_with_gaussians_design${d}_hof + PRIVATE phlex::module find_hits_with_gaussians + ) endforeach() -add_library(find_hits_with_gaussians_cell_id_hof MODULE - register_find_hits_with_gaussians_cell_id.cpp) -target_link_libraries(find_hits_with_gaussians_cell_id_hof PRIVATE - phlex::module) +add_library( + find_hits_with_gaussians_cell_id_hof + MODULE + register_find_hits_with_gaussians_cell_id.cpp +) +target_link_libraries(find_hits_with_gaussians_cell_id_hof PRIVATE phlex::module) -add_library(print_hits_to_file_hof MODULE - register_print_hits_to_file.cpp) -target_link_libraries(print_hits_to_file_hof PRIVATE - phlex::module find_hits_with_gaussians) +add_library(print_hits_to_file_hof MODULE register_print_hits_to_file.cpp) +target_link_libraries(print_hits_to_file_hof PRIVATE phlex::module find_hits_with_gaussians) file(GLOB test_files ${CMAKE_CURRENT_SOURCE_DIR}/*.dat) file(COPY ${test_files} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) @@ -81,17 +88,18 @@ endif() set(all_run_tests "") foreach(d IN LISTS designs) - set(run_test "GausHitFinderTestDesign${d}") - set(fixture "GausHitFinderDesign${d}Fixture") + set(run_test "GausHitFinderTestDesign${d}") + set(fixture "GausHitFinderDesign${d}Fixture") set(output_prefix "hits_design${d}") # --- Run test --- - add_test(NAME ${run_test} - COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/run_test.sh - $ - ${CMAKE_CURRENT_SOURCE_DIR}/test_find_hits_with_gaussians_design${d}.jsonnet - ${output_prefix} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test( + NAME ${run_test} + COMMAND + bash ${CMAKE_CURRENT_SOURCE_DIR}/run_test.sh $ + ${CMAKE_CURRENT_SOURCE_DIR}/test_find_hits_with_gaussians_design${d}.jsonnet ${output_prefix} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) set_tests_properties(${run_test} PROPERTIES FIXTURES_SETUP ${fixture}) list(APPEND all_run_tests ${run_test}) @@ -101,23 +109,20 @@ foreach(d IN LISTS designs) if(CMAKE_SYSTEM_NAME STREQUAL "Linux") add_test( NAME ${compare_test} - COMMAND diff -q -s - ${CMAKE_CURRENT_SOURCE_DIR}/art_hits_${n}.txt - ${CMAKE_CURRENT_BINARY_DIR}/${output_prefix}_${n}.txt + COMMAND + diff -q -s ${CMAKE_CURRENT_SOURCE_DIR}/art_hits_${n}.txt + ${CMAKE_CURRENT_BINARY_DIR}/${output_prefix}_${n}.txt ) elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") add_test( NAME ${compare_test} - COMMAND ${Python3_EXECUTABLE} - ${CMAKE_CURRENT_SOURCE_DIR}/compare_hits.py - ${CMAKE_CURRENT_SOURCE_DIR}/art_hits_${n}.txt - ${CMAKE_CURRENT_BINARY_DIR}/${output_prefix}_${n}.txt + COMMAND + ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/compare_hits.py + ${CMAKE_CURRENT_SOURCE_DIR}/art_hits_${n}.txt + ${CMAKE_CURRENT_BINARY_DIR}/${output_prefix}_${n}.txt ) else() - add_test( - NAME ${compare_test} - COMMAND ${CMAKE_COMMAND} -E false - ) + add_test(NAME ${compare_test} COMMAND ${CMAKE_COMMAND} -E false) endif() set_tests_properties(${compare_test} PROPERTIES FIXTURES_REQUIRED ${fixture}) endforeach() diff --git a/migration/gauss_hit_finder/README.md b/migration/gauss_hit_finder/README.md index fb65fd2..caf1243 100644 --- a/migration/gauss_hit_finder/README.md +++ b/migration/gauss_hit_finder/README.md @@ -21,7 +21,7 @@ v10_05_00 of larreco which was the version in use with DUNE software at the time the migration work was started. If there is a request, I can update the example to a more recent version. -# Work in Progress +## Work in Progress This is work in progress. It is not final. It is intended that this example will change as we learn more about using @@ -37,7 +37,7 @@ As we run tests, it may point to problems in phlex and this may guide which areas developers should focus on to fix issues and remove performance bottlenecks. -# Files in this directory +## Files in this directory ## Interesting files that are the heart of the example @@ -135,9 +135,9 @@ these files should be deleted to remove duplication. These files are in the subdirectory: - ```phlex-examples/migration/gauss_hit_finder/copied_from_larsoft_minor_edits``` +`phlex-examples/migration/gauss_hit_finder/copied_from_larsoft_minor_edits` -# Where more work is needed +## Where more work is needed The first example was implemented as a single `phlex` transform. Does it make sense to split it with unfolds @@ -197,7 +197,7 @@ Here is a list of the files that were used as a basis for this example, but significantly modified from the LArSoft version: -``` +```text https://github.com/LArSoft/larreco/blob/develop/larreco/HitFinder/GausHitFinder_module.cc ``` @@ -207,7 +207,7 @@ as `art Tools`, but otherwise the changes are minimal. Here is a list of the files that were copied from LArSoft with minimal modifications: -``` +```text https://github.com/LArSoft/larreco/blob/develop/larreco/HitFinder/HitFinderTools/CandHitStandard_tool.cc https://github.com/LArSoft/larreco/blob/develop/larreco/HitFinder/HitFinderTools/PeakFitterMrqdt_tool.cc https://github.com/LArSoft/larreco/blob/develop/larreco/HitFinder/HitFilterAlg.h @@ -261,19 +261,30 @@ avoid depending on ROOT in `phlex` code for now (slightly edited). Are we allowed to depend on ROOT in `phlex` algorithm code? That could easily be restored if the build system allows it. -# Testing +## Testing -This was tested by running `GausHitFinder` with the `art` framework and running the modified `GausHitFinder` with the `phlex` framework. The two processes used identical input (the `std::vector`). The output `std::vector` objects were compared using a text file printed during each process. The output was identical except for the following: +This was tested by running `GausHitFinder` with the `art` framework and running +the modified `GausHitFinder` with the `phlex` framework. The two processes used +identical input (the `std::vector`). The output `std::vector` +objects were compared using a text file printed during each process. The output +was identical except for the following: -Two output data members of `Hit` were ignored because they depend on the `Geometry` and that is not implemented yet for `phlex`. In the `phlex` version, these data members are filled with default values. -``` +Two output data members of `Hit` were ignored because they depend on the +`Geometry` and that is not implemented yet for `phlex`. In the `phlex` version, +these data members are filled with default values. + +```cpp geo::SigType_t fSignalType; ///< signal type for the plane of the hit geo::WireID fWireID; ///< WireID for the hit (Cryostat, TPC, Plane, Wire) ``` -This was done for all `phlex` versions of GausHitFinder. The output of all versions are identical with each other and with the `art` version. +This was done for all `phlex` versions of GausHitFinder. The output of all +versions are identical with each other and with the `art` version. -The `phlex` process was run with multithreading and that causes the order of `Hit` objects to vary from one execution to the next and also the order of events to vary. In the comparison the `Hit` objects were sorted and we had to be careful to compare matching events. +The `phlex` process was run with multithreading and that causes the order of +`Hit` objects to vary from one execution to the next and also the order of +events to vary. In the comparison the `Hit` objects were sorted and we had to +be careful to compare matching events. Contact the `phlex` group if you are interested in details related to running `art` side of this test or want the input files (or diff --git a/migration/gauss_hit_finder/cand_hit_standard.cpp b/migration/gauss_hit_finder/cand_hit_standard.cpp index 9525201..e58597a 100644 --- a/migration/gauss_hit_finder/cand_hit_standard.cpp +++ b/migration/gauss_hit_finder/cand_hit_standard.cpp @@ -6,10 +6,9 @@ namespace examples { - merge_hit_candidate_vec - cand_hit_standard::find_and_merge_hit_candidates( - wire_roi_data const& roi_data, - std::vector const& roi_thresholds) { + merge_hit_candidate_vec cand_hit_standard::find_and_merge_hit_candidates( + wire_roi_data const& roi_data, std::vector const& roi_thresholds) + { hit_candidate_vec hit_candidates; find_hit_candidates(roi_data.range.begin(), @@ -21,7 +20,8 @@ namespace examples { merge_hit_candidate_vec merged_hit_candidates; // If no hits then nothing to do here - if (hit_candidates.empty()) return merged_hit_candidates; + if (hit_candidates.empty()) + return merged_hit_candidates; // The idea is to group hits that "touch" so they can be part of common fit, those that // don't "touch" are fit independently. So here we build the output vector to achieve that @@ -29,7 +29,7 @@ namespace examples { int last_tick = hit_candidates.front().stop_tick; // Step through the input hit candidates and group them by proximity - for (const auto& hit_candidate : hit_candidates) { + for (auto const& hit_candidate : hit_candidates) { // Check condition that we have a new grouping if (int(hit_candidate.start_tick) - last_tick > 1) { merged_hit_candidates.emplace_back(grouped_hit_candidates); @@ -42,16 +42,18 @@ namespace examples { } // Check end condition - if (!grouped_hit_candidates.empty()) merged_hit_candidates.emplace_back(grouped_hit_candidates); + if (!grouped_hit_candidates.empty()) + merged_hit_candidates.emplace_back(grouped_hit_candidates); return merged_hit_candidates; } void cand_hit_standard::find_hit_candidates(std::vector::const_iterator start, - std::vector::const_iterator stop, - const std::size_t roi_start_tick, - const float roi_threshold, - hit_candidate_vec& hit_candidates) { + std::vector::const_iterator stop, + std::size_t const roi_start_tick, + float const roi_threshold, + hit_candidate_vec& hit_candidates) + { // Need a minimum number of ticks to do any work here if (std::distance(start, stop) > 4) { // Find the highest peak in the range given @@ -66,10 +68,12 @@ namespace examples { while (first != start) { // Check for pathology where waveform goes too negative - if (*first < -roi_threshold) break; + if (*first < -roi_threshold) + break; // Check both sides of first and look for min/inflection point - if (*first < *(first + 1) && *first <= *(first - 1)) break; + if (*first < *(first + 1) && *first <= *(first - 1)) + break; --first; } @@ -84,10 +88,12 @@ namespace examples { while (last != stop - 1) { // Check for pathology where value goes too negative - if (*last < -roi_threshold) break; + if (*last < -roi_threshold) + break; // Check both sides of last and look for min/inflection point - if (*last <= *(last + 1) && *last < *(last - 1)) break; + if (*last <= *(last + 1) && *last < *(last - 1)) + break; ++last; } diff --git a/migration/gauss_hit_finder/cand_hit_standard.hpp b/migration/gauss_hit_finder/cand_hit_standard.hpp index 2f1ed2e..f6f90a8 100644 --- a/migration/gauss_hit_finder/cand_hit_standard.hpp +++ b/migration/gauss_hit_finder/cand_hit_standard.hpp @@ -1,5 +1,5 @@ -#ifndef PHLEX_EXAMPLES_MIGRATION_GAUSS_HIT_FINDER_CAND_HIT_STANDARD_HPP -#define PHLEX_EXAMPLES_MIGRATION_GAUSS_HIT_FINDER_CAND_HIT_STANDARD_HPP +#ifndef MIGRATION_GAUSS_HIT_FINDER_CAND_HIT_STANDARD_HPP +#define MIGRATION_GAUSS_HIT_FINDER_CAND_HIT_STANDARD_HPP //////////////////////////////////////////////////////////////////////// /// \file cand_hit_standard.hpp @@ -16,16 +16,15 @@ namespace examples { namespace cand_hit_standard { - merge_hit_candidate_vec find_and_merge_hit_candidates( - wire_roi_data const& roi_data, - std::vector const& roi_thresholds); + merge_hit_candidate_vec find_and_merge_hit_candidates(wire_roi_data const& roi_data, + std::vector const& roi_thresholds); void find_hit_candidates(std::vector::const_iterator start, std::vector::const_iterator stop, - const std::size_t roi_start_tick, - const float roi_threshold, + std::size_t const roi_start_tick, + float const roi_threshold, hit_candidate_vec& hit_candidates); } // namespace cand_hit_standard } // namespace examples -#endif // PHLEX_EXAMPLES_MIGRATION_GAUSS_HIT_FINDER_CAND_HIT_STANDARD_HPP +#endif // MIGRATION_GAUSS_HIT_FINDER_CAND_HIT_STANDARD_HPP diff --git a/migration/gauss_hit_finder/compare_hits.py b/migration/gauss_hit_finder/compare_hits.py index 742bc2b..69303d8 100644 --- a/migration/gauss_hit_finder/compare_hits.py +++ b/migration/gauss_hit_finder/compare_hits.py @@ -3,6 +3,7 @@ import sys + def compare_files(reference, test): # read the contents of both files into lists of lines # OK because the files are small, a few MB @@ -12,8 +13,10 @@ def compare_files(reference, test): test_lines = f.readlines() if len(ref_lines) != len(test_lines): - print(f"FAIL: Line count differs: {reference} has {len(ref_lines)} lines, " - f"{test} has {len(test_lines)} lines") + print( + f"FAIL: Line count differs: {reference} has {len(ref_lines)} lines, " + f"{test} has {len(test_lines)} lines" + ) return False total = len(ref_lines) diff --git a/migration/gauss_hit_finder/find_hits_with_gaussians_design0.cpp b/migration/gauss_hit_finder/find_hits_with_gaussians_design0.cpp index 3fac2fc..ec4aec1 100644 --- a/migration/gauss_hit_finder/find_hits_with_gaussians_design0.cpp +++ b/migration/gauss_hit_finder/find_hits_with_gaussians_design0.cpp @@ -14,30 +14,36 @@ #include "tbb/concurrent_vector.h" #include "tbb/parallel_for.h" -#include "find_hits_with_gaussians_design0.hpp" #include "copied_from_larsoft_minor_edits/ICandidateHitFinder.h" +#include "find_hits_with_gaussians_design0.hpp" namespace { // This is an edited copy of the TMath::Gaus function from ROOT, since we // don't want to depend on ROOT in this example. - double Gaus(double x, double mean, double sigma, bool norm) { - if (sigma == 0) return 1.e30; - double arg = (x-mean)/sigma; + double Gaus(double x, double mean, double sigma, bool norm) + { + if (sigma == 0) + return 1.e30; + double arg = (x - mean) / sigma; // for |arg| > 39 result is zero in double precision - if (arg < -39.0 || arg > 39.0) return 0.0; - double res = std::exp(-0.5*arg*arg); - if (!norm) return res; - return res/(2.50662827463100024*sigma); //sqrt(2*Pi)=2.50662827463100024 + if (arg < -39.0 || arg > 39.0) + return 0.0; + double res = std::exp(-0.5 * arg * arg); + if (!norm) + return res; + return res / (2.50662827463100024 * sigma); //sqrt(2*Pi)=2.50662827463100024 } } namespace examples { - std::vector find_hits_with_gaussians_design0(find_hits_with_gaussians_design0_cfg const& cfg, - std::vector const& wires, - std::vector> const& cand_hit_standard, - PeakFitterMrqdt const& peak_fitter_mrqdt, - HitFilterAlg const& hit_filter_alg) { + std::vector find_hits_with_gaussians_design0( + find_hits_with_gaussians_design0_cfg const& cfg, + std::vector const& wires, + std::vector> const& cand_hit_standard, + PeakFitterMrqdt const& peak_fitter_mrqdt, + HitFilterAlg const& hit_filter_alg) + { std::cout << "Finding hits with Gaussians." << std::endl; @@ -78,7 +84,7 @@ namespace examples { charge += peakAmp * Gaus(sigPos, peakMean, peakWidth, false); return charge; }; - + //############################## //### Looping over the wires ### //############################## @@ -115,13 +121,13 @@ namespace examples { // ################################################# // ### Set up to loop over ROI's for this wire ### // ################################################# - const recob::Wire::RegionsOfInterest_t& signalROI = wire->SignalROI(); + recob::Wire::RegionsOfInterest_t const& signalROI = wire->SignalROI(); tbb::parallel_for( static_cast(0), signalROI.n_ranges(), [&](size_t rangeIter) { - const auto& range = signalROI.range(rangeIter); + auto const& range = signalROI.range(rangeIter); // ROI start time raw::TDCtick_t roiFirstBinTick = range.begin_index(); @@ -132,8 +138,7 @@ namespace examples { examples::ICandidateHitFinder::HitCandidateVec hitCandidateVec; examples::ICandidateHitFinder::MergeHitCandidateVec mergedCandidateHitVec; - cand_hit_standard.at(plane)->findHitCandidates( - range, 0, channel, hitCandidateVec); + cand_hit_standard.at(plane)->findHitCandidates(range, 0, channel, hitCandidateVec); cand_hit_standard.at(plane)->MergeHitCandidates( range, hitCandidateVec, mergedCandidateHitVec); @@ -148,7 +153,8 @@ namespace examples { // ### Putting in a protection in case things went wrong ### // ### In the end, this primarily catches the case where ### // ### a fake pulse is at the start of the ROI ### - if (endT - startT < 5) continue; + if (endT - startT < 5) + continue; // ####################################################### // ### Clearing the parameter vector for the new Pulse ### @@ -187,7 +193,8 @@ namespace examples { // ### depend on the fhicl parameter fLongPulseWidth ### // ### Also do this if chi^2 is too large ### // ####################################################### - if (mergedCands.size() > cfg.max_multi_hit || nGausForFit * chi2PerNDF > cfg.chi2_ndf) { + if (mergedCands.size() > cfg.max_multi_hit || + nGausForFit * chi2PerNDF > cfg.chi2_ndf) { int longPulseWidth = cfg.long_pulse_width_vec.at(plane); int nHitsThisPulse = (endT - startT) / longPulseWidth; @@ -196,7 +203,8 @@ namespace examples { longPulseWidth = (endT - startT) / nHitsThisPulse; } - if (nHitsThisPulse * longPulseWidth < endT - startT) nHitsThisPulse++; + if (nHitsThisPulse * longPulseWidth < endT - startT) + nHitsThisPulse++; int firstTick = startT; int lastTick = std::min(firstTick + longPulseWidth, endT); @@ -248,7 +256,7 @@ namespace examples { float nsigmaADC(2.0); float newright(0); float newleft(0); - for (const auto& peakParams : peakParamsVec) { + for (auto const& peakParams : peakParamsVec) { // Extract values for this hit float peakAmp = peakParams.peakAmplitude; float peakMean = peakParams.peakCenter; @@ -292,8 +300,8 @@ namespace examples { float charge = chargeFunc(peakMean, peakAmp, peakWidth, cfg.area_norms_vec[plane], startT, endT); ; - float chargeErr = - std::sqrt(std::numbers::pi) * (peakAmpErr * peakWidthErr + peakWidthErr * peakAmpErr); + float chargeErr = std::sqrt(std::numbers::pi) * + (peakAmpErr * peakWidthErr + peakWidthErr * peakAmpErr); // ### limits for getting sums std::vector::const_iterator sumStartItr = range.begin() + startT; @@ -326,46 +334,52 @@ namespace examples { } //protection to avoid negative ranges - if (newright - newleft < 0) continue; + if (newright - newleft < 0) + continue; //avoid ranges out of ROI if it happens - if (HitsumStartItr < sumStartItr) HitsumStartItr = sumStartItr; + if (HitsumStartItr < sumStartItr) + HitsumStartItr = sumStartItr; - if (HitsumEndItr > sumEndItr) HitsumEndItr = sumEndItr; + if (HitsumEndItr > sumEndItr) + HitsumEndItr = sumEndItr; - if (HitsumStartItr > HitsumEndItr) continue; + if (HitsumStartItr > HitsumEndItr) + continue; // ### Sum of ADC counts double ROIsumADC = std::accumulate(sumStartItr, sumEndItr, 0.); double HitsumADC = std::accumulate(HitsumStartItr, HitsumEndItr, 0.); - recob::Hit hit(wire->Channel(), - startT + roiFirstBinTick, - endT + roiFirstBinTick, - peakMean + roiFirstBinTick, - peakMeanErr, - peakWidth, - peakAmp, - peakAmpErr, - ROIsumADC, - HitsumADC, - charge, - chargeErr, - nGausForFit, - numHits, - chi2PerNDF, - NDF, - wire->View(), - // Geometry system for Phlex is not yet implemented, - // so we just set signal type to 0 (kInduction) for now. - geo::kInduction, - // art::ServiceHandle()->Get().SignalType(wire.Channel()), - // wid also comes from the Geometry, which is not yet implemented, so we just set - // it to a default value for now. - geo::WireID()); - // wid); - - if (cfg.filter_hits) filteredHitVec.push_back(hit); + recob::Hit hit( + wire->Channel(), + startT + roiFirstBinTick, + endT + roiFirstBinTick, + peakMean + roiFirstBinTick, + peakMeanErr, + peakWidth, + peakAmp, + peakAmpErr, + ROIsumADC, + HitsumADC, + charge, + chargeErr, + nGausForFit, + numHits, + chi2PerNDF, + NDF, + wire->View(), + // Geometry system for Phlex is not yet implemented, + // so we just set signal type to 0 (kInduction) for now. + geo::kInduction, + // art::ServiceHandle()->Get().SignalType(wire.Channel()), + // wid also comes from the Geometry, which is not yet implemented, so we just set + // it to a default value for now. + geo::WireID()); + // wid); + + if (cfg.filter_hits) + filteredHitVec.push_back(hit); // This loop will store ALL hits hitstruct tmp{std::move(hit)}; @@ -388,7 +402,7 @@ namespace examples { // is in descending order of peak height, not ascending.) std::sort(filteredHitVec.begin(), filteredHitVec.end(), - [](const auto& left, const auto& right) { + [](auto const& left, auto const& right) { return left.PeakAmplitude() > right.PeakAmplitude(); }); @@ -408,7 +422,7 @@ namespace examples { std::vector::iterator smallHitItr = std::find_if(filteredHitVec.begin(), filteredHitVec.end(), - [largestPH, threshold](const auto& hit) { + [largestPH, threshold](auto const& hit) { return hit.PeakAmplitude() < 8. && hit.PeakAmplitude() / largestPH < threshold; }); @@ -420,13 +434,13 @@ namespace examples { // Resort in time order std::sort(filteredHitVec.begin(), filteredHitVec.end(), - [](const auto& left, const auto& right) { + [](auto const& left, auto const& right) { return left.PeakTime() < right.PeakTime(); }); } // Copy the hits we want to keep to the filtered hit collection - for (const auto& filteredHit : filteredHitVec) { + for (auto const& filteredHit : filteredHitVec) { if (!cfg.filter_hits || hit_filter_alg.IsGoodHit(filteredHit)) { hitstruct tmp{std::move(filteredHit)}; filthitstruct_vec.push_back(std::move(tmp)); @@ -434,10 +448,10 @@ namespace examples { } } } //<---End loop over merged candidate hits - } //<---End looping over ROI's - ); //end tbb parallel for - } //<---End looping over all the wires - ); //end tbb parallel for + } //<---End looping over ROI's + ); //end tbb parallel for + } //<---End looping over all the wires + ); //end tbb parallel for std::vector hits; diff --git a/migration/gauss_hit_finder/find_hits_with_gaussians_design0.hpp b/migration/gauss_hit_finder/find_hits_with_gaussians_design0.hpp index 23d4eb8..d473d1f 100644 --- a/migration/gauss_hit_finder/find_hits_with_gaussians_design0.hpp +++ b/migration/gauss_hit_finder/find_hits_with_gaussians_design0.hpp @@ -1,5 +1,5 @@ -#ifndef PHLEX_EXAMPLES_FIND_HITS_WITH_GAUSSIANS_DESIGN0_HPP -#define PHLEX_EXAMPLES_FIND_HITS_WITH_GAUSSIANS_DESIGN0_HPP +#ifndef MIGRATION_GAUSS_HIT_FINDER_FIND_HITS_WITH_GAUSSIANS_DESIGN0_HPP +#define MIGRATION_GAUSS_HIT_FINDER_FIND_HITS_WITH_GAUSSIANS_DESIGN0_HPP // See README.md for some general comments about this example. @@ -36,7 +36,6 @@ #include "copied_from_larsoft_minor_edits/PeakFitterMrqdt.h" #include "copied_from_larsoft_minor_edits/Wire.h" - namespace examples { struct find_hits_with_gaussians_design0_cfg { @@ -44,22 +43,22 @@ namespace examples { std::vector long_max_hits_vec; /// long_pulse_width_vec; /// - area_norms_vec; /// area_norms_vec; /// pulse_height_cuts; std::vector pulse_width_cuts; std::vector pulse_ratio_cuts; }; - std::vector find_hits_with_gaussians_design0(find_hits_with_gaussians_design0_cfg const& cfg, - std::vector const& wires, - std::vector> const& cand_hit_standard, - PeakFitterMrqdt const& peak_fitter_mrqdt, - HitFilterAlg const& hit_filter_alg); + std::vector find_hits_with_gaussians_design0( + find_hits_with_gaussians_design0_cfg const& cfg, + std::vector const& wires, + std::vector> const& cand_hit_standard, + PeakFitterMrqdt const& peak_fitter_mrqdt, + HitFilterAlg const& hit_filter_alg); } -#endif // PHLEX_EXAMPLES_FIND_HITS_WITH_GAUSSIANS_DESIGN0_HPP +#endif // MIGRATION_GAUSS_HIT_FINDER_FIND_HITS_WITH_GAUSSIANS_DESIGN0_HPP diff --git a/migration/gauss_hit_finder/find_hits_with_gaussians_design1.cpp b/migration/gauss_hit_finder/find_hits_with_gaussians_design1.cpp index 7ef2257..1ab06f9 100644 --- a/migration/gauss_hit_finder/find_hits_with_gaussians_design1.cpp +++ b/migration/gauss_hit_finder/find_hits_with_gaussians_design1.cpp @@ -14,9 +14,9 @@ #include "tbb/parallel_for.h" -#include "copied_from_larsoft_minor_edits/geo_types.h" // geo::View_t, geo::SignalType, geo::WireID #include "copied_from_larsoft_minor_edits/ICandidateHitFinder.h" -#include "copied_from_larsoft_minor_edits/RawTypes.h" // raw::ChannelID_t +#include "copied_from_larsoft_minor_edits/RawTypes.h" // raw::ChannelID_t +#include "copied_from_larsoft_minor_edits/geo_types.h" // geo::View_t, geo::SignalType, geo::WireID #include "find_hits_with_gaussians_design1.hpp" namespace { @@ -39,8 +39,7 @@ namespace { namespace examples { - unfold_wire_vector_design1::unfold_wire_vector_design1( - std::vector const& wires) : + unfold_wire_vector_design1::unfold_wire_vector_design1(std::vector const& wires) : begin_{wires.begin()}, end_{wires.end()} { // Probably eventually delete the following line @@ -53,7 +52,10 @@ namespace examples { return begin_; } - bool unfold_wire_vector_design1::predicate(const_iterator current) const { return current != end_; } + bool unfold_wire_vector_design1::predicate(const_iterator current) const + { + return current != end_; + } std::pair unfold_wire_vector_design1::unfold(const_iterator current) const diff --git a/migration/gauss_hit_finder/find_hits_with_gaussians_design1.hpp b/migration/gauss_hit_finder/find_hits_with_gaussians_design1.hpp index db6a4f1..0a12607 100644 --- a/migration/gauss_hit_finder/find_hits_with_gaussians_design1.hpp +++ b/migration/gauss_hit_finder/find_hits_with_gaussians_design1.hpp @@ -1,5 +1,5 @@ -#ifndef PHLEX_EXAMPLES_FIND_HITS_WITH_GAUSSIANS_DESIGN1_HPP -#define PHLEX_EXAMPLES_FIND_HITS_WITH_GAUSSIANS_DESIGN1_HPP +#ifndef MIGRATION_GAUSS_HIT_FINDER_FIND_HITS_WITH_GAUSSIANS_DESIGN1_HPP +#define MIGRATION_GAUSS_HIT_FINDER_FIND_HITS_WITH_GAUSSIANS_DESIGN1_HPP // See README.md for some general comments about this example. @@ -46,7 +46,6 @@ namespace examples { class unfold_wire_vector_design1 { public: - explicit unfold_wire_vector_design1(std::vector const& wires); using const_iterator = std::vector::const_iterator; @@ -69,25 +68,25 @@ namespace examples { std::vector long_max_hits_vec; /// long_pulse_width_vec; /// - area_norms_vec; /// area_norms_vec; /// pulse_height_cuts; std::vector pulse_width_cuts; std::vector pulse_ratio_cuts; }; - tbb::concurrent_vector find_hits_with_gaussians_design1(find_hits_with_gaussians_design1_cfg const& cfg, - recob::Wire const& wire, - std::vector> const& cand_hit_standard, - PeakFitterMrqdt const& peak_fitter_mrqdt, - HitFilterAlg const& hit_filter_alg); + tbb::concurrent_vector find_hits_with_gaussians_design1( + find_hits_with_gaussians_design1_cfg const& cfg, + recob::Wire const& wire, + std::vector> const& cand_hit_standard, + PeakFitterMrqdt const& peak_fitter_mrqdt, + HitFilterAlg const& hit_filter_alg); // Third, define the fold, fills the output vector of hits void fold_hits_into_vector_design1(std::vector& hits, tbb::concurrent_vector const& hits_from_wire); } -#endif // PHLEX_EXAMPLES_FIND_HITS_WITH_GAUSSIANS_DESIGN1_HPP +#endif // MIGRATION_GAUSS_HIT_FINDER_FIND_HITS_WITH_GAUSSIANS_DESIGN1_HPP diff --git a/migration/gauss_hit_finder/find_hits_with_gaussians_design2.cpp b/migration/gauss_hit_finder/find_hits_with_gaussians_design2.cpp index a2a074e..b9b1e28 100644 --- a/migration/gauss_hit_finder/find_hits_with_gaussians_design2.cpp +++ b/migration/gauss_hit_finder/find_hits_with_gaussians_design2.cpp @@ -11,9 +11,9 @@ #include #include -#include "copied_from_larsoft_minor_edits/geo_types.h" // geo::View_t, geo::SignalType, geo::WireID #include "copied_from_larsoft_minor_edits/ICandidateHitFinder.h" -#include "copied_from_larsoft_minor_edits/RawTypes.h" // raw::ChannelID_t +#include "copied_from_larsoft_minor_edits/RawTypes.h" // raw::ChannelID_t +#include "copied_from_larsoft_minor_edits/geo_types.h" // geo::View_t, geo::SignalType, geo::WireID #include "find_hits_with_gaussians_design2.hpp" namespace { @@ -40,8 +40,7 @@ namespace examples { // First unfold: vector -> individual Wire objects // --------------------------------------------------------------- - unfold_wire_vector_design2::unfold_wire_vector_design2( - std::vector const& wires) : + unfold_wire_vector_design2::unfold_wire_vector_design2(std::vector const& wires) : begin_{wires.begin()}, end_{wires.end()} { // Probably eventually delete the following line @@ -54,7 +53,10 @@ namespace examples { return begin_; } - bool unfold_wire_vector_design2::predicate(const_iterator current) const { return current != end_; } + bool unfold_wire_vector_design2::predicate(const_iterator current) const + { + return current != end_; + } std::pair unfold_wire_vector_design2::unfold(const_iterator current) const @@ -72,20 +74,15 @@ namespace examples { unfold_wire_design2::unfold_wire_design2(recob::Wire const& wire) : wire_{wire}, n_ranges_{wire.SignalROI().n_ranges()} - {} - - unfold_wire_design2::state_type unfold_wire_design2::initial_value() const { - return 0; } - bool unfold_wire_design2::predicate(state_type current) const - { - return current < n_ranges_; - } + unfold_wire_design2::state_type unfold_wire_design2::initial_value() const { return 0; } - std::pair - unfold_wire_design2::unfold(state_type current) const + bool unfold_wire_design2::predicate(state_type current) const { return current < n_ranges_; } + + std::pair unfold_wire_design2::unfold( + state_type current) const { recob::Wire::RegionsOfInterest_t const& signalROI = wire_.SignalROI(); @@ -99,7 +96,8 @@ namespace examples { // plane = wid.Plane; geo::PlaneID::PlaneID_t plane = 0; - wire_roi_data data{signalROI.range(current), wire_.Channel(), static_cast(wire_.View()), plane}; + wire_roi_data data{ + signalROI.range(current), wire_.Channel(), static_cast(wire_.View()), plane}; return std::make_pair(current + 1, std::move(data)); } @@ -162,8 +160,7 @@ namespace examples { examples::ICandidateHitFinder::MergeHitCandidateVec mergedCandidateHitVec; cand_hit_standard.at(plane)->findHitCandidates(range, 0, channel, hitCandidateVec); - cand_hit_standard.at(plane)->MergeHitCandidates( - range, hitCandidateVec, mergedCandidateHitVec); + cand_hit_standard.at(plane)->MergeHitCandidates(range, hitCandidateVec, mergedCandidateHitVec); // ####################################################### // ### Lets loop over the pulses we found on this wire ### @@ -421,11 +418,10 @@ namespace examples { // Sort in ascending peak height // (I believe the preceding comment is incorrect. The sort below // is in descending order of peak height, not ascending.) - std::sort(filteredHitVec.begin(), - filteredHitVec.end(), - [](auto const& left, auto const& right) { - return left.PeakAmplitude() > right.PeakAmplitude(); - }); + std::sort( + filteredHitVec.begin(), filteredHitVec.end(), [](auto const& left, auto const& right) { + return left.PeakAmplitude() > right.PeakAmplitude(); + }); // Reject if the first hit fails the PH/wid cuts if (filteredHitVec.front().PeakAmplitude() < cfg.pulse_height_cuts.at(plane) || @@ -441,9 +437,7 @@ namespace examples { float threshold(cfg.pulse_ratio_cuts.at(plane)); std::vector::iterator smallHitItr = std::find_if( - filteredHitVec.begin(), - filteredHitVec.end(), - [largestPH, threshold](auto const& hit) { + filteredHitVec.begin(), filteredHitVec.end(), [largestPH, threshold](auto const& hit) { return hit.PeakAmplitude() < 8. && hit.PeakAmplitude() / largestPH < threshold; }); @@ -452,11 +446,10 @@ namespace examples { filteredHitVec.resize(std::distance(filteredHitVec.begin(), smallHitItr)); // Resort in time order - std::sort(filteredHitVec.begin(), - filteredHitVec.end(), - [](auto const& left, auto const& right) { - return left.PeakTime() < right.PeakTime(); - }); + std::sort( + filteredHitVec.begin(), filteredHitVec.end(), [](auto const& left, auto const& right) { + return left.PeakTime() < right.PeakTime(); + }); } // Copy the hits we want to keep to the filtered hit collection diff --git a/migration/gauss_hit_finder/find_hits_with_gaussians_design2.hpp b/migration/gauss_hit_finder/find_hits_with_gaussians_design2.hpp index 27a5163..67a1453 100644 --- a/migration/gauss_hit_finder/find_hits_with_gaussians_design2.hpp +++ b/migration/gauss_hit_finder/find_hits_with_gaussians_design2.hpp @@ -1,5 +1,5 @@ -#ifndef PHLEX_EXAMPLES_FIND_HITS_WITH_GAUSSIANS_DESIGN2_HPP -#define PHLEX_EXAMPLES_FIND_HITS_WITH_GAUSSIANS_DESIGN2_HPP +#ifndef MIGRATION_GAUSS_HIT_FINDER_FIND_HITS_WITH_GAUSSIANS_DESIGN2_HPP +#define MIGRATION_GAUSS_HIT_FINDER_FIND_HITS_WITH_GAUSSIANS_DESIGN2_HPP // Design2 extends design1 by also replacing the inner parallel_for // (over ROIs) with a second unfold-transform-fold. @@ -71,7 +71,7 @@ namespace examples { public: explicit unfold_wire_design2(recob::Wire const& wire); - using state_type = std::size_t; // index into signalROI ranges + using state_type = std::size_t; // index into signalROI ranges state_type initial_value() const; bool predicate(state_type current) const; @@ -90,11 +90,10 @@ namespace examples { std::vector long_max_hits_vec; /// long_pulse_width_vec; /// - area_norms_vec; /// area_norms_vec; /// pulse_height_cuts; std::vector pulse_width_cuts; @@ -125,4 +124,4 @@ namespace examples { void fold_hits_into_vector_design2(std::vector& hits, std::vector const& hits_from_wire); } -#endif // PHLEX_EXAMPLES_FIND_HITS_WITH_GAUSSIANS_DESIGN2_HPP +#endif // MIGRATION_GAUSS_HIT_FINDER_FIND_HITS_WITH_GAUSSIANS_DESIGN2_HPP diff --git a/migration/gauss_hit_finder/find_hits_with_gaussians_design3.cpp b/migration/gauss_hit_finder/find_hits_with_gaussians_design3.cpp index c3bdf84..946dc11 100644 --- a/migration/gauss_hit_finder/find_hits_with_gaussians_design3.cpp +++ b/migration/gauss_hit_finder/find_hits_with_gaussians_design3.cpp @@ -9,8 +9,8 @@ #include #include +#include "copied_from_larsoft_minor_edits/RawTypes.h" // raw::ChannelID_t #include "copied_from_larsoft_minor_edits/geo_types.h" // geo::View_t, geo::SignalType, geo::WireID -#include "copied_from_larsoft_minor_edits/RawTypes.h" // raw::ChannelID_t #include "find_hits_with_gaussians_design3.hpp" namespace { @@ -19,8 +19,8 @@ namespace { // In the near future, when we migrate the peak fitter code to // be a transform, we should make it also use hit_candidate_vec // and delete this copy. - examples::ICandidateHitFinder::HitCandidateVec - to_legacy_candidates(examples::hit_candidate_vec const& candidates) + examples::ICandidateHitFinder::HitCandidateVec to_legacy_candidates( + examples::hit_candidate_vec const& candidates) { examples::ICandidateHitFinder::HitCandidateVec result; result.reserve(candidates.size()); @@ -61,8 +61,7 @@ namespace examples { // First unfold: vector -> individual Wire objects // --------------------------------------------------------------- - unfold_wire_vector_design3::unfold_wire_vector_design3( - std::vector const& wires) : + unfold_wire_vector_design3::unfold_wire_vector_design3(std::vector const& wires) : begin_{wires.begin()}, end_{wires.end()} { // Probably eventually delete the following line @@ -75,7 +74,10 @@ namespace examples { return begin_; } - bool unfold_wire_vector_design3::predicate(const_iterator current) const { return current != end_; } + bool unfold_wire_vector_design3::predicate(const_iterator current) const + { + return current != end_; + } std::pair unfold_wire_vector_design3::unfold(const_iterator current) const @@ -93,20 +95,15 @@ namespace examples { unfold_wire_design3::unfold_wire_design3(recob::Wire const& wire) : wire_{wire}, n_ranges_{wire.SignalROI().n_ranges()} - {} - - unfold_wire_design3::state_type unfold_wire_design3::initial_value() const { - return 0; } - bool unfold_wire_design3::predicate(state_type current) const - { - return current < n_ranges_; - } + unfold_wire_design3::state_type unfold_wire_design3::initial_value() const { return 0; } + + bool unfold_wire_design3::predicate(state_type current) const { return current < n_ranges_; } - std::pair - unfold_wire_design3::unfold(state_type current) const + std::pair unfold_wire_design3::unfold( + state_type current) const { recob::Wire::RegionsOfInterest_t const& signalROI = wire_.SignalROI(); @@ -120,7 +117,8 @@ namespace examples { // plane = wid.Plane; geo::PlaneID::PlaneID_t plane = 0; - wire_roi_data data{signalROI.range(current), wire_.Channel(), static_cast(wire_.View()), plane}; + wire_roi_data data{ + signalROI.range(current), wire_.Channel(), static_cast(wire_.View()), plane}; return std::make_pair(current + 1, std::move(data)); } @@ -446,11 +444,10 @@ namespace examples { // Sort in ascending peak height // (I believe the preceding comment is incorrect. The sort below // is in descending order of peak height, not ascending.) - std::sort(filteredHitVec.begin(), - filteredHitVec.end(), - [](auto const& left, auto const& right) { - return left.PeakAmplitude() > right.PeakAmplitude(); - }); + std::sort( + filteredHitVec.begin(), filteredHitVec.end(), [](auto const& left, auto const& right) { + return left.PeakAmplitude() > right.PeakAmplitude(); + }); // Reject if the first hit fails the PH/wid cuts if (filteredHitVec.front().PeakAmplitude() < cfg.pulse_height_cuts.at(plane) || @@ -466,9 +463,7 @@ namespace examples { float threshold(cfg.pulse_ratio_cuts.at(plane)); std::vector::iterator smallHitItr = std::find_if( - filteredHitVec.begin(), - filteredHitVec.end(), - [largestPH, threshold](auto const& hit) { + filteredHitVec.begin(), filteredHitVec.end(), [largestPH, threshold](auto const& hit) { return hit.PeakAmplitude() < 8. && hit.PeakAmplitude() / largestPH < threshold; }); @@ -477,11 +472,10 @@ namespace examples { filteredHitVec.resize(std::distance(filteredHitVec.begin(), smallHitItr)); // Resort in time order - std::sort(filteredHitVec.begin(), - filteredHitVec.end(), - [](auto const& left, auto const& right) { - return left.PeakTime() < right.PeakTime(); - }); + std::sort( + filteredHitVec.begin(), filteredHitVec.end(), [](auto const& left, auto const& right) { + return left.PeakTime() < right.PeakTime(); + }); } // Copy the hits we want to keep to the filtered hit collection diff --git a/migration/gauss_hit_finder/find_hits_with_gaussians_design3.hpp b/migration/gauss_hit_finder/find_hits_with_gaussians_design3.hpp index 09fef51..315d89b 100644 --- a/migration/gauss_hit_finder/find_hits_with_gaussians_design3.hpp +++ b/migration/gauss_hit_finder/find_hits_with_gaussians_design3.hpp @@ -1,5 +1,5 @@ -#ifndef PHLEX_EXAMPLES_FIND_HITS_WITH_GAUSSIANS_DESIGN3_HPP -#define PHLEX_EXAMPLES_FIND_HITS_WITH_GAUSSIANS_DESIGN3_HPP +#ifndef MIGRATION_GAUSS_HIT_FINDER_FIND_HITS_WITH_GAUSSIANS_DESIGN3_HPP +#define MIGRATION_GAUSS_HIT_FINDER_FIND_HITS_WITH_GAUSSIANS_DESIGN3_HPP // Design3 extends design2 by extracting the candidate-hit-finding step // (cand_hit_standard) into a separate transform that runs after the @@ -72,7 +72,7 @@ namespace examples { public: explicit unfold_wire_design3(recob::Wire const& wire); - using state_type = std::size_t; // index into signalROI ranges + using state_type = std::size_t; // index into signalROI ranges state_type initial_value() const; bool predicate(state_type current) const; @@ -92,11 +92,10 @@ namespace examples { std::vector long_max_hits_vec; /// long_pulse_width_vec; /// - area_norms_vec; /// area_norms_vec; /// pulse_height_cuts; std::vector pulse_width_cuts; @@ -136,4 +135,4 @@ namespace examples { void fold_hits_into_vector_design3(std::vector& hits, std::vector const& hits_from_wire); } -#endif // PHLEX_EXAMPLES_FIND_HITS_WITH_GAUSSIANS_DESIGN3_HPP +#endif // MIGRATION_GAUSS_HIT_FINDER_FIND_HITS_WITH_GAUSSIANS_DESIGN3_HPP diff --git a/migration/gauss_hit_finder/hit_candidate.hpp b/migration/gauss_hit_finder/hit_candidate.hpp index 1c16edd..11124ca 100644 --- a/migration/gauss_hit_finder/hit_candidate.hpp +++ b/migration/gauss_hit_finder/hit_candidate.hpp @@ -6,8 +6,8 @@ /// type aliases used across the gauss hit finder code. /// //////////////////////////////////////////////////////////////////////// -#ifndef PHLEX_EXAMPLES_MIGRATION_GAUSS_HIT_FINDER_HIT_CANDIDATE_HPP -#define PHLEX_EXAMPLES_MIGRATION_GAUSS_HIT_FINDER_HIT_CANDIDATE_HPP +#ifndef MIGRATION_GAUSS_HIT_FINDER_HIT_CANDIDATE_HPP +#define MIGRATION_GAUSS_HIT_FINDER_HIT_CANDIDATE_HPP #include #include @@ -30,4 +30,4 @@ namespace examples { using merge_hit_candidate_vec = std::vector; } -#endif // PHLEX_EXAMPLES_MIGRATION_GAUSS_HIT_FINDER_HIT_CANDIDATE_HPP +#endif // MIGRATION_GAUSS_HIT_FINDER_HIT_CANDIDATE_HPP diff --git a/migration/gauss_hit_finder/print_hits_to_file.cpp b/migration/gauss_hit_finder/print_hits_to_file.cpp index ec7a7a7..af917e8 100644 --- a/migration/gauss_hit_finder/print_hits_to_file.cpp +++ b/migration/gauss_hit_finder/print_hits_to_file.cpp @@ -14,7 +14,8 @@ namespace examples { void print_hits_to_file(std::string const& filename_prefix, int cell_id, - std::vector const& input_hits) { + std::vector const& input_hits) + { std::vector hits = input_hits; @@ -23,7 +24,7 @@ namespace examples { // the output from the art version of GausHitFinder. The parallel_for // loops and unfold-transform-fold execution map both scramble the // order and make comparisons difficult. - std::sort(hits.begin(), hits.end(), [](const recob::Hit& a, const recob::Hit& b) { + std::sort(hits.begin(), hits.end(), [](recob::Hit const& a, recob::Hit const& b) { if (a.PeakTime() != b.PeakTime()) { return a.PeakTime() < b.PeakTime(); } @@ -36,8 +37,7 @@ namespace examples { return a.EndTick() < b.EndTick(); }); - std::string filename = filename_prefix + "_" + - std::to_string(cell_id) + ".txt"; + std::string filename = filename_prefix + "_" + std::to_string(cell_id) + ".txt"; auto file = fmt::output_file(filename); file.print("Contents of a std::vector\n\n"); diff --git a/migration/gauss_hit_finder/print_hits_to_file.hpp b/migration/gauss_hit_finder/print_hits_to_file.hpp index b055869..d008442 100644 --- a/migration/gauss_hit_finder/print_hits_to_file.hpp +++ b/migration/gauss_hit_finder/print_hits_to_file.hpp @@ -1,5 +1,5 @@ -#ifndef PHLEX_EXAMPLES_PRINT_HITS_HPP -#define PHLEX_EXAMPLES_PRINT_HITS_HPP +#ifndef MIGRATION_GAUSS_HIT_FINDER_PRINT_HITS_TO_FILE_HPP +#define MIGRATION_GAUSS_HIT_FINDER_PRINT_HITS_TO_FILE_HPP #include #include @@ -13,4 +13,4 @@ namespace examples { std::vector const& input_hits); } -#endif // PHLEX_EXAMPLES_PRINT_HITS_HPP +#endif // MIGRATION_GAUSS_HIT_FINDER_PRINT_HITS_TO_FILE_HPP diff --git a/migration/gauss_hit_finder/register_find_hits_with_gaussians_cell_id.cpp b/migration/gauss_hit_finder/register_find_hits_with_gaussians_cell_id.cpp index 71b2c88..76e071b 100644 --- a/migration/gauss_hit_finder/register_find_hits_with_gaussians_cell_id.cpp +++ b/migration/gauss_hit_finder/register_find_hits_with_gaussians_cell_id.cpp @@ -10,7 +10,6 @@ PHLEX_REGISTER_PROVIDERS(m, config) { auto const layer = config.get("layer"); - m.provide("cell_id", [](data_cell_index const& id) -> int { - return id.number(); - }).output_product("cell_info", "", experimental::identifier{layer}); + m.provide("cell_id", [](data_cell_index const& id) -> int { return id.number(); }) + .output_product("cell_info", "", experimental::identifier{layer}); } diff --git a/migration/gauss_hit_finder/register_find_hits_with_gaussians_design0.cpp b/migration/gauss_hit_finder/register_find_hits_with_gaussians_design0.cpp index 0cdd145..81e6ce7 100644 --- a/migration/gauss_hit_finder/register_find_hits_with_gaussians_design0.cpp +++ b/migration/gauss_hit_finder/register_find_hits_with_gaussians_design0.cpp @@ -12,41 +12,40 @@ #include "copied_from_larsoft_minor_edits/PeakFitterMrqdt.h" #include "copied_from_larsoft_minor_edits/Wire.h" -#include "phlex/module.hpp" #include "find_hits_with_gaussians_design0.hpp" +#include "phlex/module.hpp" using namespace phlex; namespace { - examples::find_hits_with_gaussians_design0_cfg main_cfg(configuration config) { - return { - .filter_hits = config.get("filter_hits"), - .long_max_hits_vec = config.get>("long_max_hits_vec"), - .long_pulse_width_vec = config.get>("long_pulse_width_vec"), - .max_multi_hit = config.get("max_multi_hit"), - .area_method = config.get("area_method"), - .area_norms_vec = config.get>("area_norms_vec"), - .chi2_ndf = config.get("chi2_ndf"), - .pulse_height_cuts = config.get>("pulse_height_cuts"), - .pulse_width_cuts = config.get>("pulse_width_cuts"), - .pulse_ratio_cuts = config.get>("pulse_ratio_cuts") - }; + examples::find_hits_with_gaussians_design0_cfg main_cfg(configuration config) + { + return {.filter_hits = config.get("filter_hits"), + .long_max_hits_vec = config.get>("long_max_hits_vec"), + .long_pulse_width_vec = config.get>("long_pulse_width_vec"), + .max_multi_hit = config.get("max_multi_hit"), + .area_method = config.get("area_method"), + .area_norms_vec = config.get>("area_norms_vec"), + .chi2_ndf = config.get("chi2_ndf"), + .pulse_height_cuts = config.get>("pulse_height_cuts"), + .pulse_width_cuts = config.get>("pulse_width_cuts"), + .pulse_ratio_cuts = config.get>("pulse_ratio_cuts")}; } - std::vector> make_cand_hit_standard_vec(configuration config) { + std::vector> make_cand_hit_standard_vec( + configuration config) + { auto finder_configs = config.get("cand_hit_standard_configs"); std::vector> result(finder_configs.keys().size()); for (auto const& key : finder_configs.keys()) { auto finder_config = finder_configs.get(key); auto hit_finder = std::make_shared( - examples::CandHitStandardCfg{ - .fRoiThreshold = finder_config.get("roiThreshold") - }); + examples::CandHitStandardCfg{.fRoiThreshold = finder_config.get("roiThreshold")}); unsigned int plane = finder_config.get("Plane"); if (plane >= result.size()) { std::cerr << "Error: plane number " << plane - << " is out of range for cand_hit_standard_vec of size " - << result.size() << std::endl; + << " is out of range for cand_hit_standard_vec of size " << result.size() + << std::endl; throw std::runtime_error("Invalid plane number"); } result[plane] = std::move(hit_finder); @@ -54,24 +53,22 @@ namespace { return result; } - std::shared_ptr make_peak_fitter_mrqdt(configuration config) { + std::shared_ptr make_peak_fitter_mrqdt(configuration config) + { auto fitter_config = config.get("peak_fitter_mrqdt_config"); return std::make_shared( - examples::PeakFitterMrqdtCfg{ - .fMinWidth = fitter_config.get("min_width"), - .fMaxWidthMult = fitter_config.get("max_width_mult"), - .fPeakRange = fitter_config.get("peak_range_fact"), - .fAmpRange = fitter_config.get("peak_amp_range") - }); + examples::PeakFitterMrqdtCfg{.fMinWidth = fitter_config.get("min_width"), + .fMaxWidthMult = fitter_config.get("max_width_mult"), + .fPeakRange = fitter_config.get("peak_range_fact"), + .fAmpRange = fitter_config.get("peak_amp_range")}); } - std::shared_ptr make_hit_filter_alg(configuration config) { + std::shared_ptr make_hit_filter_alg(configuration config) + { auto filter_config = config.get("hit_filter_alg_config"); - return std::make_shared( - examples::HitFilterAlgCfg{ - .fMinPulseHeight = filter_config.get>("min_pulse_height"), - .fMinPulseSigma = filter_config.get>("min_pulse_sigma") - }); + return std::make_shared(examples::HitFilterAlgCfg{ + .fMinPulseHeight = filter_config.get>("min_pulse_height"), + .fMinPulseSigma = filter_config.get>("min_pulse_sigma")}); } } @@ -79,19 +76,16 @@ PHLEX_REGISTER_ALGORITHMS(m, config) { auto const layer = config.get("layer"); - m.transform("find_hits_with_gaussians_design0", - [cfg = main_cfg(config), - cand_hit_standard_vec = make_cand_hit_standard_vec(config), - peak_fitter_mrqdt = make_peak_fitter_mrqdt(config), - hit_filter_alg = make_hit_filter_alg(config)] - (std::vector const& wires) { - return examples::find_hits_with_gaussians_design0(cfg, - wires, - cand_hit_standard_vec, - *peak_fitter_mrqdt, - *hit_filter_alg); - }, - concurrency::unlimited) + m.transform( + "find_hits_with_gaussians_design0", + [cfg = main_cfg(config), + cand_hit_standard_vec = make_cand_hit_standard_vec(config), + peak_fitter_mrqdt = make_peak_fitter_mrqdt(config), + hit_filter_alg = make_hit_filter_alg(config)](std::vector const& wires) { + return examples::find_hits_with_gaussians_design0( + cfg, wires, cand_hit_standard_vec, *peak_fitter_mrqdt, *hit_filter_alg); + }, + concurrency::unlimited) .input_family(product_selector{.creator = "wires", .layer = layer, .suffix = ""}) .output_product_suffixes("hits"); } diff --git a/migration/gauss_hit_finder/register_find_hits_with_gaussians_design1.cpp b/migration/gauss_hit_finder/register_find_hits_with_gaussians_design1.cpp index 2cc183a..320ab9b 100644 --- a/migration/gauss_hit_finder/register_find_hits_with_gaussians_design1.cpp +++ b/migration/gauss_hit_finder/register_find_hits_with_gaussians_design1.cpp @@ -21,35 +21,34 @@ using namespace phlex; namespace { - examples::find_hits_with_gaussians_design1_cfg main_cfg(configuration config) { - return { - .filter_hits = config.get("filter_hits"), - .long_max_hits_vec = config.get>("long_max_hits_vec"), - .long_pulse_width_vec = config.get>("long_pulse_width_vec"), - .max_multi_hit = config.get("max_multi_hit"), - .area_method = config.get("area_method"), - .area_norms_vec = config.get>("area_norms_vec"), - .chi2_ndf = config.get("chi2_ndf"), - .pulse_height_cuts = config.get>("pulse_height_cuts"), - .pulse_width_cuts = config.get>("pulse_width_cuts"), - .pulse_ratio_cuts = config.get>("pulse_ratio_cuts") - }; + examples::find_hits_with_gaussians_design1_cfg main_cfg(configuration config) + { + return {.filter_hits = config.get("filter_hits"), + .long_max_hits_vec = config.get>("long_max_hits_vec"), + .long_pulse_width_vec = config.get>("long_pulse_width_vec"), + .max_multi_hit = config.get("max_multi_hit"), + .area_method = config.get("area_method"), + .area_norms_vec = config.get>("area_norms_vec"), + .chi2_ndf = config.get("chi2_ndf"), + .pulse_height_cuts = config.get>("pulse_height_cuts"), + .pulse_width_cuts = config.get>("pulse_width_cuts"), + .pulse_ratio_cuts = config.get>("pulse_ratio_cuts")}; } - std::vector> make_cand_hit_standard_vec(configuration config) { + std::vector> make_cand_hit_standard_vec( + configuration config) + { auto finder_configs = config.get("cand_hit_standard_configs"); std::vector> result(finder_configs.keys().size()); for (auto const& key : finder_configs.keys()) { auto finder_config = finder_configs.get(key); auto hit_finder = std::make_shared( - examples::CandHitStandardCfg{ - .fRoiThreshold = finder_config.get("roiThreshold") - }); + examples::CandHitStandardCfg{.fRoiThreshold = finder_config.get("roiThreshold")}); unsigned int plane = finder_config.get("Plane"); if (plane >= result.size()) { std::cerr << "Error: plane number " << plane - << " is out of range for cand_hit_standard_vec of size " - << result.size() << std::endl; + << " is out of range for cand_hit_standard_vec of size " << result.size() + << std::endl; throw std::runtime_error("Invalid plane number"); } result[plane] = std::move(hit_finder); @@ -57,24 +56,22 @@ namespace { return result; } - std::shared_ptr make_peak_fitter_mrqdt(configuration config) { + std::shared_ptr make_peak_fitter_mrqdt(configuration config) + { auto fitter_config = config.get("peak_fitter_mrqdt_config"); return std::make_shared( - examples::PeakFitterMrqdtCfg{ - .fMinWidth = fitter_config.get("min_width"), - .fMaxWidthMult = fitter_config.get("max_width_mult"), - .fPeakRange = fitter_config.get("peak_range_fact"), - .fAmpRange = fitter_config.get("peak_amp_range") - }); + examples::PeakFitterMrqdtCfg{.fMinWidth = fitter_config.get("min_width"), + .fMaxWidthMult = fitter_config.get("max_width_mult"), + .fPeakRange = fitter_config.get("peak_range_fact"), + .fAmpRange = fitter_config.get("peak_amp_range")}); } - std::shared_ptr make_hit_filter_alg(configuration config) { + std::shared_ptr make_hit_filter_alg(configuration config) + { auto filter_config = config.get("hit_filter_alg_config"); - return std::make_shared( - examples::HitFilterAlgCfg{ - .fMinPulseHeight = filter_config.get>("min_pulse_height"), - .fMinPulseSigma = filter_config.get>("min_pulse_sigma") - }); + return std::make_shared(examples::HitFilterAlgCfg{ + .fMinPulseHeight = filter_config.get>("min_pulse_height"), + .fMinPulseSigma = filter_config.get>("min_pulse_sigma")}); } } @@ -84,27 +81,29 @@ PHLEX_REGISTER_ALGORITHMS(m, config) auto const layer_unfold_output = config.get("layer_unfold_output"); m.unfold("unfold_wire_vector_design1", - &examples::unfold_wire_vector_design1::predicate, - &examples::unfold_wire_vector_design1::unfold, - layer_unfold_output, - concurrency::unlimited) + &examples::unfold_wire_vector_design1::predicate, + &examples::unfold_wire_vector_design1::unfold, + layer_unfold_output, + concurrency::unlimited) .input_family(product_selector{.creator = "wires", .layer = layer_unfold_input, .suffix = ""}); - m.transform("find_hits_with_gaussians_design1", - [cfg = main_cfg(config), - cand_hit_standard_vec = make_cand_hit_standard_vec(config), - peak_fitter_mrqdt = make_peak_fitter_mrqdt(config), - hit_filter_alg = make_hit_filter_alg(config)] - (recob::Wire const& wire) { - return examples::find_hits_with_gaussians_design1(cfg, - wire, - cand_hit_standard_vec, - *peak_fitter_mrqdt, - *hit_filter_alg); - }, - concurrency::unlimited) - .input_family(product_selector{.creator = "unfold_wire_vector_design1", .layer = layer_unfold_output}); + m.transform( + "find_hits_with_gaussians_design1", + [cfg = main_cfg(config), + cand_hit_standard_vec = make_cand_hit_standard_vec(config), + peak_fitter_mrqdt = make_peak_fitter_mrqdt(config), + hit_filter_alg = make_hit_filter_alg(config)](recob::Wire const& wire) { + return examples::find_hits_with_gaussians_design1( + cfg, wire, cand_hit_standard_vec, *peak_fitter_mrqdt, *hit_filter_alg); + }, + concurrency::unlimited) + .input_family( + product_selector{.creator = "unfold_wire_vector_design1", .layer = layer_unfold_output}); - m.fold("fold_hits_into_vector_design1", examples::fold_hits_into_vector_design1, concurrency::serial, layer_unfold_input) - .input_family(product_selector{.creator = "find_hits_with_gaussians_design1", .layer = layer_unfold_output}); + m.fold("fold_hits_into_vector_design1", + examples::fold_hits_into_vector_design1, + concurrency::serial, + layer_unfold_input) + .input_family(product_selector{.creator = "find_hits_with_gaussians_design1", + .layer = layer_unfold_output}); } diff --git a/migration/gauss_hit_finder/register_find_hits_with_gaussians_design2.cpp b/migration/gauss_hit_finder/register_find_hits_with_gaussians_design2.cpp index 73f271e..f1e57bc 100644 --- a/migration/gauss_hit_finder/register_find_hits_with_gaussians_design2.cpp +++ b/migration/gauss_hit_finder/register_find_hits_with_gaussians_design2.cpp @@ -21,35 +21,34 @@ using namespace phlex; namespace { - examples::find_hits_with_gaussians_design2_cfg main_cfg(configuration config) { - return { - .filter_hits = config.get("filter_hits"), - .long_max_hits_vec = config.get>("long_max_hits_vec"), - .long_pulse_width_vec = config.get>("long_pulse_width_vec"), - .max_multi_hit = config.get("max_multi_hit"), - .area_method = config.get("area_method"), - .area_norms_vec = config.get>("area_norms_vec"), - .chi2_ndf = config.get("chi2_ndf"), - .pulse_height_cuts = config.get>("pulse_height_cuts"), - .pulse_width_cuts = config.get>("pulse_width_cuts"), - .pulse_ratio_cuts = config.get>("pulse_ratio_cuts") - }; + examples::find_hits_with_gaussians_design2_cfg main_cfg(configuration config) + { + return {.filter_hits = config.get("filter_hits"), + .long_max_hits_vec = config.get>("long_max_hits_vec"), + .long_pulse_width_vec = config.get>("long_pulse_width_vec"), + .max_multi_hit = config.get("max_multi_hit"), + .area_method = config.get("area_method"), + .area_norms_vec = config.get>("area_norms_vec"), + .chi2_ndf = config.get("chi2_ndf"), + .pulse_height_cuts = config.get>("pulse_height_cuts"), + .pulse_width_cuts = config.get>("pulse_width_cuts"), + .pulse_ratio_cuts = config.get>("pulse_ratio_cuts")}; } - std::vector> make_cand_hit_standard_vec(configuration config) { + std::vector> make_cand_hit_standard_vec( + configuration config) + { auto finder_configs = config.get("cand_hit_standard_configs"); std::vector> result(finder_configs.keys().size()); for (auto const& key : finder_configs.keys()) { auto finder_config = finder_configs.get(key); auto hit_finder = std::make_shared( - examples::CandHitStandardCfg{ - .fRoiThreshold = finder_config.get("roiThreshold") - }); + examples::CandHitStandardCfg{.fRoiThreshold = finder_config.get("roiThreshold")}); unsigned int plane = finder_config.get("Plane"); if (plane >= result.size()) { std::cerr << "Error: plane number " << plane - << " is out of range for cand_hit_standard_vec of size " - << result.size() << std::endl; + << " is out of range for cand_hit_standard_vec of size " << result.size() + << std::endl; throw std::runtime_error("Invalid plane number"); } result[plane] = std::move(hit_finder); @@ -57,24 +56,22 @@ namespace { return result; } - std::shared_ptr make_peak_fitter_mrqdt(configuration config) { + std::shared_ptr make_peak_fitter_mrqdt(configuration config) + { auto fitter_config = config.get("peak_fitter_mrqdt_config"); return std::make_shared( - examples::PeakFitterMrqdtCfg{ - .fMinWidth = fitter_config.get("min_width"), - .fMaxWidthMult = fitter_config.get("max_width_mult"), - .fPeakRange = fitter_config.get("peak_range_fact"), - .fAmpRange = fitter_config.get("peak_amp_range") - }); + examples::PeakFitterMrqdtCfg{.fMinWidth = fitter_config.get("min_width"), + .fMaxWidthMult = fitter_config.get("max_width_mult"), + .fPeakRange = fitter_config.get("peak_range_fact"), + .fAmpRange = fitter_config.get("peak_amp_range")}); } - std::shared_ptr make_hit_filter_alg(configuration config) { + std::shared_ptr make_hit_filter_alg(configuration config) + { auto filter_config = config.get("hit_filter_alg_config"); - return std::make_shared( - examples::HitFilterAlgCfg{ - .fMinPulseHeight = filter_config.get>("min_pulse_height"), - .fMinPulseSigma = filter_config.get>("min_pulse_sigma") - }); + return std::make_shared(examples::HitFilterAlgCfg{ + .fMinPulseHeight = filter_config.get>("min_pulse_height"), + .fMinPulseSigma = filter_config.get>("min_pulse_sigma")}); } } @@ -92,45 +89,47 @@ PHLEX_REGISTER_ALGORITHMS(m, config) &examples::unfold_wire_vector_design2::unfold, layer_wire, concurrency::unlimited) - .input_family(product_selector{.creator = "wires", .layer = layer_vector_of_wires, .suffix = ""}); + .input_family( + product_selector{.creator = "wires", .layer = layer_vector_of_wires, .suffix = ""}); // --------------------------------------------------------------- // Inner unfold: wire -> roi // --------------------------------------------------------------- m.unfold("unfold_wire_design2", - &examples::unfold_wire_design2::predicate, - &examples::unfold_wire_design2::unfold, - layer_roi, - concurrency::unlimited) + &examples::unfold_wire_design2::predicate, + &examples::unfold_wire_design2::unfold, + layer_roi, + concurrency::unlimited) .input_family(product_selector{.creator = "unfold_wire_vector_design2", .layer = layer_wire}); // --------------------------------------------------------------- // Transform: processes a single ROI // --------------------------------------------------------------- - m.transform("find_hits_with_gaussians_design2", - [cfg = main_cfg(config), - cand_hit_standard_vec = make_cand_hit_standard_vec(config), - peak_fitter_mrqdt = make_peak_fitter_mrqdt(config), - hit_filter_alg = make_hit_filter_alg(config)] - (examples::wire_roi_data const& roi_data) { - return examples::find_hits_with_gaussians_design2(cfg, - roi_data, - cand_hit_standard_vec, - *peak_fitter_mrqdt, - *hit_filter_alg); - }, - concurrency::unlimited) + m.transform( + "find_hits_with_gaussians_design2", + [cfg = main_cfg(config), + cand_hit_standard_vec = make_cand_hit_standard_vec(config), + peak_fitter_mrqdt = make_peak_fitter_mrqdt(config), + hit_filter_alg = make_hit_filter_alg(config)](examples::wire_roi_data const& roi_data) { + return examples::find_hits_with_gaussians_design2( + cfg, roi_data, cand_hit_standard_vec, *peak_fitter_mrqdt, *hit_filter_alg); + }, + concurrency::unlimited) .input_family(product_selector{.creator = "unfold_wire_design2", .layer = layer_roi}); // --------------------------------------------------------------- // Inner fold: roi -> wire (collects hits from ROIs of one wire) // --------------------------------------------------------------- m.fold("fold_roi_hits_design2", examples::fold_roi_hits_design2, concurrency::serial, layer_wire) - .input_family(product_selector{.creator = "find_hits_with_gaussians_design2", .layer = layer_roi}); + .input_family( + product_selector{.creator = "find_hits_with_gaussians_design2", .layer = layer_roi}); // --------------------------------------------------------------- // Outer fold: wire -> spill (collects hits from all wires) // --------------------------------------------------------------- - m.fold("fold_hits_into_vector_design2", examples::fold_hits_into_vector_design2, concurrency::serial, layer_vector_of_wires) + m.fold("fold_hits_into_vector_design2", + examples::fold_hits_into_vector_design2, + concurrency::serial, + layer_vector_of_wires) .input_family(product_selector{.creator = "fold_roi_hits_design2", .layer = layer_wire}); } diff --git a/migration/gauss_hit_finder/register_find_hits_with_gaussians_design3.cpp b/migration/gauss_hit_finder/register_find_hits_with_gaussians_design3.cpp index b5e5fad..267870d 100644 --- a/migration/gauss_hit_finder/register_find_hits_with_gaussians_design3.cpp +++ b/migration/gauss_hit_finder/register_find_hits_with_gaussians_design3.cpp @@ -12,48 +12,45 @@ #include "phlex/core/product_selector.hpp" #include "phlex/module.hpp" +#include "cand_hit_standard.hpp" #include "copied_from_larsoft_minor_edits/HitFilterAlg.h" #include "copied_from_larsoft_minor_edits/PeakFitterMrqdt.h" #include "copied_from_larsoft_minor_edits/Wire.h" -#include "cand_hit_standard.hpp" #include "find_hits_with_gaussians_design3.hpp" using namespace phlex; namespace { - examples::find_hits_with_gaussians_design3_cfg main_cfg(configuration config) { - return { - .filter_hits = config.get("filter_hits"), - .long_max_hits_vec = config.get>("long_max_hits_vec"), - .long_pulse_width_vec = config.get>("long_pulse_width_vec"), - .max_multi_hit = config.get("max_multi_hit"), - .area_method = config.get("area_method"), - .area_norms_vec = config.get>("area_norms_vec"), - .chi2_ndf = config.get("chi2_ndf"), - .pulse_height_cuts = config.get>("pulse_height_cuts"), - .pulse_width_cuts = config.get>("pulse_width_cuts"), - .pulse_ratio_cuts = config.get>("pulse_ratio_cuts") - }; + examples::find_hits_with_gaussians_design3_cfg main_cfg(configuration config) + { + return {.filter_hits = config.get("filter_hits"), + .long_max_hits_vec = config.get>("long_max_hits_vec"), + .long_pulse_width_vec = config.get>("long_pulse_width_vec"), + .max_multi_hit = config.get("max_multi_hit"), + .area_method = config.get("area_method"), + .area_norms_vec = config.get>("area_norms_vec"), + .chi2_ndf = config.get("chi2_ndf"), + .pulse_height_cuts = config.get>("pulse_height_cuts"), + .pulse_width_cuts = config.get>("pulse_width_cuts"), + .pulse_ratio_cuts = config.get>("pulse_ratio_cuts")}; } - std::shared_ptr make_peak_fitter_mrqdt(configuration config) { + std::shared_ptr make_peak_fitter_mrqdt(configuration config) + { auto fitter_config = config.get("peak_fitter_mrqdt_config"); return std::make_shared( - examples::PeakFitterMrqdtCfg{ - .fMinWidth = fitter_config.get("min_width"), - .fMaxWidthMult = fitter_config.get("max_width_mult"), - .fPeakRange = fitter_config.get("peak_range_fact"), - .fAmpRange = fitter_config.get("peak_amp_range") - }); + examples::PeakFitterMrqdtCfg{.fMinWidth = fitter_config.get("min_width"), + .fMaxWidthMult = fitter_config.get("max_width_mult"), + .fPeakRange = fitter_config.get("peak_range_fact"), + .fAmpRange = fitter_config.get("peak_amp_range")}); } - std::shared_ptr make_hit_filter_alg(configuration config) { + std::shared_ptr make_hit_filter_alg(configuration config) + { auto filter_config = config.get("hit_filter_alg_config"); - return std::make_shared( - examples::HitFilterAlgCfg{ - .fMinPulseHeight = filter_config.get>("min_pulse_height"), - .fMinPulseSigma = filter_config.get>("min_pulse_sigma") - }); + return std::make_shared(examples::HitFilterAlgCfg{ + .fMinPulseHeight = filter_config.get>("min_pulse_height"), + .fMinPulseSigma = filter_config.get>("min_pulse_sigma")}); } } @@ -71,28 +68,29 @@ PHLEX_REGISTER_ALGORITHMS(m, config) &examples::unfold_wire_vector_design3::unfold, layer_wire, concurrency::unlimited) - .input_family(product_selector{.creator = "wires", .layer = layer_vector_of_wires, .suffix = ""}); + .input_family( + product_selector{.creator = "wires", .layer = layer_vector_of_wires, .suffix = ""}); // --------------------------------------------------------------- // Inner unfold: wire -> roi // --------------------------------------------------------------- m.unfold("unfold_wire_design3", - &examples::unfold_wire_design3::predicate, - &examples::unfold_wire_design3::unfold, - layer_roi, - concurrency::unlimited) + &examples::unfold_wire_design3::predicate, + &examples::unfold_wire_design3::unfold, + layer_roi, + concurrency::unlimited) .input_family(product_selector{.creator = "unfold_wire_vector_design3", .layer = layer_wire}); // --------------------------------------------------------------- // Candidate hit finding: wire_roi_data -> merge_hit_candidate_vec // --------------------------------------------------------------- - m.transform("cand_hit_standard", - [roi_threshold = config.get>("roi_threshold")] - (examples::wire_roi_data const& roi_data) { - return examples::cand_hit_standard::find_and_merge_hit_candidates( - roi_data, roi_threshold); - }, - concurrency::unlimited) + m.transform( + "cand_hit_standard", + [roi_threshold = + config.get>("roi_threshold")](examples::wire_roi_data const& roi_data) { + return examples::cand_hit_standard::find_and_merge_hit_candidates(roi_data, roi_threshold); + }, + concurrency::unlimited) .input_family(product_selector{.creator = "unfold_wire_design3", .layer = layer_roi}); // --------------------------------------------------------------- @@ -101,19 +99,17 @@ PHLEX_REGISTER_ALGORITHMS(m, config) // second unfold and the merge_hit_candidate_vec from // cand_hit_standard. // --------------------------------------------------------------- - m.transform("find_hits_with_gaussians_design3", - [cfg = main_cfg(config), - peak_fitter_mrqdt = make_peak_fitter_mrqdt(config), - hit_filter_alg = make_hit_filter_alg(config)] - (examples::wire_roi_data const& roi_data, - examples::merge_hit_candidate_vec const& merged_candidates) { - return examples::find_hits_with_gaussians_design3(cfg, - roi_data, - merged_candidates, - *peak_fitter_mrqdt, - *hit_filter_alg); - }, - concurrency::unlimited) + m.transform( + "find_hits_with_gaussians_design3", + [cfg = main_cfg(config), + peak_fitter_mrqdt = make_peak_fitter_mrqdt(config), + hit_filter_alg = + make_hit_filter_alg(config)](examples::wire_roi_data const& roi_data, + examples::merge_hit_candidate_vec const& merged_candidates) { + return examples::find_hits_with_gaussians_design3( + cfg, roi_data, merged_candidates, *peak_fitter_mrqdt, *hit_filter_alg); + }, + concurrency::unlimited) .input_family(product_selector{.creator = "unfold_wire_design3", .layer = layer_roi}, product_selector{.creator = "cand_hit_standard", .layer = layer_roi}); @@ -121,11 +117,15 @@ PHLEX_REGISTER_ALGORITHMS(m, config) // Inner fold: roi -> wire (collects hits from ROIs of one wire) // --------------------------------------------------------------- m.fold("fold_roi_hits_design3", examples::fold_roi_hits_design3, concurrency::serial, layer_wire) - .input_family(product_selector{.creator = "find_hits_with_gaussians_design3", .layer = layer_roi}); + .input_family( + product_selector{.creator = "find_hits_with_gaussians_design3", .layer = layer_roi}); // --------------------------------------------------------------- // Outer fold: wire -> spill (collects hits from all wires) // --------------------------------------------------------------- - m.fold("fold_hits_into_vector_design3", examples::fold_hits_into_vector_design3, concurrency::serial, layer_vector_of_wires) + m.fold("fold_hits_into_vector_design3", + examples::fold_hits_into_vector_design3, + concurrency::serial, + layer_vector_of_wires) .input_family(product_selector{.creator = "fold_roi_hits_design3", .layer = layer_wire}); } diff --git a/migration/gauss_hit_finder/register_print_hits_to_file.cpp b/migration/gauss_hit_finder/register_print_hits_to_file.cpp index 381b2a2..3b20bc3 100644 --- a/migration/gauss_hit_finder/register_print_hits_to_file.cpp +++ b/migration/gauss_hit_finder/register_print_hits_to_file.cpp @@ -20,12 +20,12 @@ PHLEX_REGISTER_ALGORITHMS(m, config) auto const layer = config.get("layer"); auto const filename_prefix = config.get("filename_prefix"); - m.observe("print_hits_to_file", - [filename_prefix](int cell_id, std::vector const& hits) { - examples::print_hits_to_file(filename_prefix, cell_id, hits); - }, - concurrency::unlimited) - .input_family( - product_selector{.creator = "cell_info", .layer = layer}, - product_selector{.creator = creator, .layer = layer}); + m.observe( + "print_hits_to_file", + [filename_prefix](int cell_id, std::vector const& hits) { + examples::print_hits_to_file(filename_prefix, cell_id, hits); + }, + concurrency::unlimited) + .input_family(product_selector{.creator = "cell_info", .layer = layer}, + product_selector{.creator = creator, .layer = layer}); } diff --git a/migration/gauss_hit_finder/test_find_hits_with_gaussians_design0.jsonnet b/migration/gauss_hit_finder/test_find_hits_with_gaussians_design0.jsonnet index 675a358..d9883c1 100644 --- a/migration/gauss_hit_finder/test_find_hits_with_gaussians_design0.jsonnet +++ b/migration/gauss_hit_finder/test_find_hits_with_gaussians_design0.jsonnet @@ -27,7 +27,7 @@ area_method: 0, area_norms_vec: [13.25, 13.25, 13.25], chi2_ndf: 50.0, - pulse_height_cuts: [3.0, 3.0, 3.0], + pulse_height_cuts: [3.0, 3.0, 3.0], pulse_width_cuts: [2.0, 1.5, 1.0], pulse_ratio_cuts: [0.35, 0.40, 0.20], cand_hit_standard_configs: { diff --git a/migration/gauss_hit_finder/test_find_hits_with_gaussians_design1.jsonnet b/migration/gauss_hit_finder/test_find_hits_with_gaussians_design1.jsonnet index 01900d6..0de1f80 100644 --- a/migration/gauss_hit_finder/test_find_hits_with_gaussians_design1.jsonnet +++ b/migration/gauss_hit_finder/test_find_hits_with_gaussians_design1.jsonnet @@ -28,7 +28,7 @@ area_method: 0, area_norms_vec: [13.25, 13.25, 13.25], chi2_ndf: 50.0, - pulse_height_cuts: [3.0, 3.0, 3.0], + pulse_height_cuts: [3.0, 3.0, 3.0], pulse_width_cuts: [2.0, 1.5, 1.0], pulse_ratio_cuts: [0.35, 0.40, 0.20], cand_hit_standard_configs: { diff --git a/migration/gauss_hit_finder/test_find_hits_with_gaussians_design2.jsonnet b/migration/gauss_hit_finder/test_find_hits_with_gaussians_design2.jsonnet index b6dc4ad..9a5f6e2 100644 --- a/migration/gauss_hit_finder/test_find_hits_with_gaussians_design2.jsonnet +++ b/migration/gauss_hit_finder/test_find_hits_with_gaussians_design2.jsonnet @@ -29,7 +29,7 @@ area_method: 0, area_norms_vec: [13.25, 13.25, 13.25], chi2_ndf: 50.0, - pulse_height_cuts: [3.0, 3.0, 3.0], + pulse_height_cuts: [3.0, 3.0, 3.0], pulse_width_cuts: [2.0, 1.5, 1.0], pulse_ratio_cuts: [0.35, 0.40, 0.20], cand_hit_standard_configs: { diff --git a/migration/gauss_hit_finder/test_find_hits_with_gaussians_design3.jsonnet b/migration/gauss_hit_finder/test_find_hits_with_gaussians_design3.jsonnet index 38d2ae1..f80989e 100644 --- a/migration/gauss_hit_finder/test_find_hits_with_gaussians_design3.jsonnet +++ b/migration/gauss_hit_finder/test_find_hits_with_gaussians_design3.jsonnet @@ -30,7 +30,7 @@ area_method: 0, area_norms_vec: [13.25, 13.25, 13.25], chi2_ndf: 50.0, - pulse_height_cuts: [3.0, 3.0, 3.0], + pulse_height_cuts: [3.0, 3.0, 3.0], pulse_width_cuts: [2.0, 1.5, 1.0], pulse_ratio_cuts: [0.35, 0.40, 0.20], peak_fitter_mrqdt_config: { diff --git a/migration/gauss_hit_finder/wire_roi_data.hpp b/migration/gauss_hit_finder/wire_roi_data.hpp index 196275e..aaeb70e 100644 --- a/migration/gauss_hit_finder/wire_roi_data.hpp +++ b/migration/gauss_hit_finder/wire_roi_data.hpp @@ -1,10 +1,10 @@ -#ifndef PHLEX_EXAMPLES_MIGRATION_GAUSS_HIT_FINDER_WIRE_ROI_DATA_HPP -#define PHLEX_EXAMPLES_MIGRATION_GAUSS_HIT_FINDER_WIRE_ROI_DATA_HPP +#ifndef MIGRATION_GAUSS_HIT_FINDER_WIRE_ROI_DATA_HPP +#define MIGRATION_GAUSS_HIT_FINDER_WIRE_ROI_DATA_HPP -#include "copied_from_larsoft_minor_edits/geo_types.h" #include "copied_from_larsoft_minor_edits/RawTypes.h" // raw::ChannelID_t -#include "copied_from_larsoft_minor_edits/sparse_vector.h" #include "copied_from_larsoft_minor_edits/Wire.h" +#include "copied_from_larsoft_minor_edits/geo_types.h" +#include "copied_from_larsoft_minor_edits/sparse_vector.h" namespace examples { @@ -26,4 +26,4 @@ namespace examples { } // namespace examples -#endif // PHLEX_EXAMPLES_MIGRATION_GAUSS_HIT_FINDER_WIRE_ROI_DATA_HPP +#endif // MIGRATION_GAUSS_HIT_FINDER_WIRE_ROI_DATA_HPP diff --git a/migration/gauss_hit_finder/wire_serialization.cpp b/migration/gauss_hit_finder/wire_serialization.cpp index 5eb6241..a5bb2f4 100644 --- a/migration/gauss_hit_finder/wire_serialization.cpp +++ b/migration/gauss_hit_finder/wire_serialization.cpp @@ -1,129 +1,136 @@ +#include "wire_serialization.hpp" +#include "copied_from_larsoft_minor_edits/sparse_vector.h" #include #include -#include "copied_from_larsoft_minor_edits/sparse_vector.h" -#include "wire_serialization.hpp" -bool write_wires_to_file(std::vector const& wires, - std::string const& filename) { - std::ofstream out(filename, std::ios::binary); - if (!out) { - throw std::runtime_error("Failed to open file for writing: " + filename); +bool write_wires_to_file(std::vector const& wires, std::string const& filename) +{ + std::ofstream out(filename, std::ios::binary); + if (!out) { + throw std::runtime_error("Failed to open file for writing: " + filename); + } + + // Write number of wires + size_t num_wires = wires.size(); + out.write(reinterpret_cast(&num_wires), sizeof(num_wires)); + + for (auto const& wire : wires) { + // Write channel ID + raw::ChannelID_t channel = wire.Channel(); + out.write(reinterpret_cast(&channel), sizeof(channel)); + + // Write view + geo::View_t view = wire.View(); + out.write(reinterpret_cast(&view), sizeof(view)); + + // Write sparse vector data + auto const& signal_roi = wire.SignalROI(); + size_t nominal_size = signal_roi.size(); + out.write(reinterpret_cast(&nominal_size), sizeof(nominal_size)); + + // Write number of ranges + size_t num_ranges = std::distance(signal_roi.begin_range(), signal_roi.end_range()); + out.write(reinterpret_cast(&num_ranges), sizeof(num_ranges)); + + // Write each range + for (auto range_it = signal_roi.begin_range(); range_it != signal_roi.end_range(); ++range_it) { + // Write range offset and last + size_t offset = range_it->begin_index(); + size_t last = range_it->end_index(); + out.write(reinterpret_cast(&offset), sizeof(offset)); + out.write(reinterpret_cast(&last), sizeof(last)); + + // Write number of values + size_t num_values = range_it->size(); + out.write(reinterpret_cast(&num_values), sizeof(num_values)); + + // Write values + if (num_values > 0) { + // Create a temporary vector to hold the values + std::vector values(range_it->begin(), range_it->end()); + out.write(reinterpret_cast(values.data()), num_values * sizeof(float)); + } } - - // Write number of wires - size_t num_wires = wires.size(); - out.write(reinterpret_cast(&num_wires), sizeof(num_wires)); - - for (const auto& wire : wires) { - // Write channel ID - raw::ChannelID_t channel = wire.Channel(); - out.write(reinterpret_cast(&channel), sizeof(channel)); - - // Write view - geo::View_t view = wire.View(); - out.write(reinterpret_cast(&view), sizeof(view)); - - // Write sparse vector data - const auto& signal_roi = wire.SignalROI(); - size_t nominal_size = signal_roi.size(); - out.write(reinterpret_cast(&nominal_size), sizeof(nominal_size)); - - // Write number of ranges - size_t num_ranges = std::distance(signal_roi.begin_range(), signal_roi.end_range()); - out.write(reinterpret_cast(&num_ranges), sizeof(num_ranges)); - - // Write each range - for (auto range_it = signal_roi.begin_range(); range_it != signal_roi.end_range(); ++range_it) { - // Write range offset and last - size_t offset = range_it->begin_index(); - size_t last = range_it->end_index(); - out.write(reinterpret_cast(&offset), sizeof(offset)); - out.write(reinterpret_cast(&last), sizeof(last)); - - // Write number of values - size_t num_values = range_it->size(); - out.write(reinterpret_cast(&num_values), sizeof(num_values)); - - // Write values - if (num_values > 0) { - // Create a temporary vector to hold the values - std::vector values(range_it->begin(), range_it->end()); - out.write(reinterpret_cast(values.data()), - num_values * sizeof(float)); - } - } - } - out.close(); - return out.good(); + } + out.close(); + return out.good(); } -std::optional> read_wires_from_file(std::string const& filename) { - std::ifstream in(filename, std::ios::binary); - if (!in) { - throw std::runtime_error("Failed to open file for reading: " + filename); +std::optional> read_wires_from_file(std::string const& filename) +{ + std::ifstream in(filename, std::ios::binary); + if (!in) { + throw std::runtime_error("Failed to open file for reading: " + filename); + } + + std::vector wires; + + // Read number of wires + size_t num_wires; + in.read(reinterpret_cast(&num_wires), sizeof(num_wires)); + if (!in) + return std::nullopt; + + wires.reserve(num_wires); + + for (size_t i = 0; i < num_wires; ++i) { + // Read channel ID + raw::ChannelID_t channel; + in.read(reinterpret_cast(&channel), sizeof(channel)); + if (!in) + return std::nullopt; + + // Read view + geo::View_t view; + in.read(reinterpret_cast(&view), sizeof(view)); + if (!in) + return std::nullopt; + + // Read sparse vector data + size_t nominal_size; + in.read(reinterpret_cast(&nominal_size), sizeof(nominal_size)); + if (!in) + return std::nullopt; + + // Read number of ranges + size_t num_ranges; + in.read(reinterpret_cast(&num_ranges), sizeof(num_ranges)); + if (!in) + return std::nullopt; + + // Create sparse vector + lar::sparse_vector signal_roi; + signal_roi.resize(nominal_size); + + // Read each range + for (size_t j = 0; j < num_ranges; ++j) { + // Read range offset and last + size_t offset, last; + in.read(reinterpret_cast(&offset), sizeof(offset)); + in.read(reinterpret_cast(&last), sizeof(last)); + if (!in) + return std::nullopt; + + // Read number of values + size_t num_values; + in.read(reinterpret_cast(&num_values), sizeof(num_values)); + if (!in) + return std::nullopt; + + // Read values + std::vector values(num_values); + if (num_values > 0) { + in.read(reinterpret_cast(values.data()), num_values * sizeof(float)); + if (!in) + return std::nullopt; + } + + // Add range to sparse vector + signal_roi.add_range(offset, values); } - std::vector wires; - - // Read number of wires - size_t num_wires; - in.read(reinterpret_cast(&num_wires), sizeof(num_wires)); - if (!in) return std::nullopt; - - wires.reserve(num_wires); - - for (size_t i = 0; i < num_wires; ++i) { - // Read channel ID - raw::ChannelID_t channel; - in.read(reinterpret_cast(&channel), sizeof(channel)); - if (!in) return std::nullopt; - - // Read view - geo::View_t view; - in.read(reinterpret_cast(&view), sizeof(view)); - if (!in) return std::nullopt; - - // Read sparse vector data - size_t nominal_size; - in.read(reinterpret_cast(&nominal_size), sizeof(nominal_size)); - if (!in) return std::nullopt; - - // Read number of ranges - size_t num_ranges; - in.read(reinterpret_cast(&num_ranges), sizeof(num_ranges)); - if (!in) return std::nullopt; - - // Create sparse vector - lar::sparse_vector signal_roi; - signal_roi.resize(nominal_size); - - // Read each range - for (size_t j = 0; j < num_ranges; ++j) { - // Read range offset and last - size_t offset, last; - in.read(reinterpret_cast(&offset), sizeof(offset)); - in.read(reinterpret_cast(&last), sizeof(last)); - if (!in) return std::nullopt; - - // Read number of values - size_t num_values; - in.read(reinterpret_cast(&num_values), sizeof(num_values)); - if (!in) return std::nullopt; - - // Read values - std::vector values(num_values); - if (num_values > 0) { - in.read(reinterpret_cast(values.data()), - num_values * sizeof(float)); - if (!in) return std::nullopt; - } - - // Add range to sparse vector - signal_roi.add_range(offset, values); - } - - // Create wire - wires.emplace_back(std::move(signal_roi), channel, view); - } - return wires; + // Create wire + wires.emplace_back(std::move(signal_roi), channel, view); + } + return wires; } diff --git a/migration/gauss_hit_finder/wire_serialization.hpp b/migration/gauss_hit_finder/wire_serialization.hpp index f038856..048147f 100644 --- a/migration/gauss_hit_finder/wire_serialization.hpp +++ b/migration/gauss_hit_finder/wire_serialization.hpp @@ -1,15 +1,14 @@ -#ifndef PHLEX_EXAMPLES_WIRE_SERIALIZATION_H -#define PHLEX_EXAMPLES_WIRE_SERIALIZATION_H +#ifndef MIGRATION_GAUSS_HIT_FINDER_WIRE_SERIALIZATION_HPP +#define MIGRATION_GAUSS_HIT_FINDER_WIRE_SERIALIZATION_HPP +#include "copied_from_larsoft_minor_edits/Wire.h" #include #include #include #include -#include "copied_from_larsoft_minor_edits/Wire.h" -bool write_wires_to_file(std::vector const& wires, - std::string const& filename); +bool write_wires_to_file(std::vector const& wires, std::string const& filename); std::optional> read_wires_from_file(std::string const& filename); -#endif // PHLEX_EXAMPLES_WIRE_SERIALIZATION_H +#endif // MIGRATION_GAUSS_HIT_FINDER_WIRE_SERIALIZATION_HPP diff --git a/migration/gauss_hit_finder/wires_source.cpp b/migration/gauss_hit_finder/wires_source.cpp index e1422f5..f862685 100644 --- a/migration/gauss_hit_finder/wires_source.cpp +++ b/migration/gauss_hit_finder/wires_source.cpp @@ -23,15 +23,15 @@ PHLEX_REGISTER_PROVIDERS(m, config) { auto const layer = config.get("layer"); - m.provide("provide_wires", [](data_cell_index const& id) -> std::vector { - std::string filename = std::string("wires_") + std::to_string(id.number()) + ".dat"; - - - if (auto wires = read_wires_from_file(filename)) { - return *wires; - } - throw std::runtime_error("Failure while reading from file: " + filename); - return {}; - }) + m.provide("provide_wires", + [](data_cell_index const& id) -> std::vector { + std::string filename = std::string("wires_") + std::to_string(id.number()) + ".dat"; + + if (auto wires = read_wires_from_file(filename)) { + return *wires; + } + throw std::runtime_error("Failure while reading from file: " + filename); + return {}; + }) .output_product("wires", "", experimental::identifier{layer}); } diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..117c205 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,2 @@ +[lint.per-file-ignores] +"migration/doc/conf.py" = ["A001", "S607"] diff --git a/scripts/fix_header_guards.py b/scripts/fix_header_guards.py new file mode 100755 index 0000000..fa0d870 --- /dev/null +++ b/scripts/fix_header_guards.py @@ -0,0 +1,154 @@ +#!/usr/bin/env python3 +"""Check and fix header guards to enforce naming convention.""" + +from __future__ import annotations + +import argparse +import re +import sys +from pathlib import Path + + +def normalize_guard_component(component: str) -> str: + """Convert a path component to a non-reserved macro identifier token.""" + normalized = re.sub(r"[^A-Z0-9_]", "_", component.upper()) + normalized = re.sub(r"_+", "_", normalized) + if not normalized or not normalized[0].isalpha(): + return f"FILE_{normalized}" if normalized else "FILE" + return normalized + + +def compute_expected_guard(file_path: Path, root: Path) -> str: + """Compute expected guard macro: X_Y_HEADER_EXT.""" + rel = file_path.relative_to(root) + # Include directory components only; a top-level header has none. + parts = [normalize_guard_component(part) for part in rel.parts[:-1]] + parts.extend( + [normalize_guard_component(rel.stem), normalize_guard_component(rel.suffix[1:])] + ) + return "_".join(parts) + + +def check_header_guard(file_path: Path, root: Path) -> tuple[bool, str | None]: + """Check if header guard is correct. Returns (is_valid, expected_guard).""" + content = file_path.read_text(encoding="utf-8") + lines = content.splitlines(keepends=True) + + if len(lines) < 3: + return True, None + + expected = compute_expected_guard(file_path, root) + + ifndef_idx = define_idx = None + ifndef_macro = define_macro = endif_macro = None + + for i in range(min(10, len(lines))): + if m := re.match(r"#ifndef\s+(\S+)\s*$", lines[i]): + ifndef_idx, ifndef_macro = i, m.group(1) + elif m := re.match(r"#define\s+(.+?)\s*$", lines[i]): + define_idx, define_macro = i, m.group(1) + break + + for i in range(len(lines) - 1, -1, -1): + line = lines[i].strip() + if line.startswith("#endif"): + if m := re.match(r"#endif\s*//\s*(\S+)\s*$", lines[i]): + endif_macro = m.group(1) + break + + if ifndef_idx is None or define_idx is None: + return True, None + + if ifndef_macro == define_macro == endif_macro == expected: + return True, None + + return False, expected + + +def fix_header_guard(file_path: Path, root: Path) -> bool: + """Fix header guard. Returns True if modified.""" + content = file_path.read_text(encoding="utf-8") + lines = content.splitlines(keepends=True) + + if len(lines) < 3: + return False + + expected = compute_expected_guard(file_path, root) + + ifndef_idx = define_idx = endif_idx = None + + for i in range(min(10, len(lines))): + if re.match(r"#ifndef\s+\S+\s*$", lines[i]): + ifndef_idx = i + elif re.match(r"#define\s+.+\s*$", lines[i]): + define_idx = i + break + + for i in range(len(lines) - 1, -1, -1): + line = lines[i].strip() + if line.startswith("#endif"): + endif_idx = i + break + + if ifndef_idx is None or define_idx is None: + return False + + modified = False + if lines[ifndef_idx] != f"#ifndef {expected}\n": + lines[ifndef_idx] = f"#ifndef {expected}\n" + modified = True + if lines[define_idx] != f"#define {expected}\n": + lines[define_idx] = f"#define {expected}\n" + modified = True + if endif_idx is not None and lines[endif_idx] != f"#endif // {expected}\n": + lines[endif_idx] = f"#endif // {expected}\n" + modified = True + + if modified: + file_path.write_text("".join(lines), encoding="utf-8") + return modified + + +def main() -> None: + """Check or fix header guards in C++ header files.""" + parser = argparse.ArgumentParser(description="Check/fix header guards") + parser.add_argument("paths", nargs="+", help="Files or directories") + parser.add_argument("--check", action="store_true", help="Check only") + parser.add_argument("--root", type=Path, default=Path.cwd(), help="Root path") + args = parser.parse_args() + + root = args.root.resolve() + bad_files = [] + + for arg in args.paths: + path = Path(arg).resolve() + files = [path] if path.is_file() else [*path.rglob("*.hpp"), *path.rglob("*.h")] + for f in files: + if f.suffix not in {".hpp", ".h"}: + continue + if args.check: + valid, expected = check_header_guard(f, root) + if not valid: + bad_files.append((f, expected)) + else: + if fix_header_guard(f, root): + bad_files.append((f, None)) + + if args.check: + if bad_files: + print(f"Found {len(bad_files)} files with incorrect guards:") + for f, expected in bad_files: + print(f" {f.relative_to(root)}: expected {expected}") + sys.exit(1) + print("All header guards are correct.") + else: + if bad_files: + print(f"Fixed {len(bad_files)} files:") + for f, _ in bad_files: + print(f" {f.relative_to(root)}") + else: + print("No header guards needed fixing.") + + +if __name__ == "__main__": + main() diff --git a/scripts/test_fix_header_guards.py b/scripts/test_fix_header_guards.py new file mode 100644 index 0000000..6d84b8c --- /dev/null +++ b/scripts/test_fix_header_guards.py @@ -0,0 +1,71 @@ +"""Regression tests for header guard naming.""" + +from pathlib import Path +import tempfile +import unittest + +from scripts.fix_header_guards import ( + check_header_guard, + compute_expected_guard, + fix_header_guard, +) + + +class ComputeExpectedGuardTests(unittest.TestCase): + def test_top_level_header_guard(self) -> None: + root = Path("/project") + + self.assertEqual( + compute_expected_guard(root / "my_geometry.hpp", root), "MY_GEOMETRY_HPP" + ) + + def test_nested_header_guard(self) -> None: + root = Path("/project") + + self.assertEqual( + compute_expected_guard( + root / "migration" / "geometry" / "my-geometry.hpp", root + ), + "MIGRATION_GEOMETRY_MY_GEOMETRY_HPP", + ) + + def test_normalizes_non_identifier_path_characters(self) -> None: + root = Path("/project") + + self.assertEqual( + compute_expected_guard( + root / "1.0-release" / "2nd.geometry.hpp", root + ), + "FILE_1_0_RELEASE_FILE_2ND_GEOMETRY_HPP", + ) + + def test_collapses_repeated_underscores(self) -> None: + root = Path("/project") + + self.assertEqual( + compute_expected_guard(root / "a..b.hpp", root), "A_B_HPP" + ) + self.assertEqual( + compute_expected_guard(root / "foo__bar.hpp", root), "FOO_BAR_HPP" + ) + + def test_fixes_malformed_top_level_guard(self) -> None: + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + header = root / "my_geometry.hpp" + header.write_text( + "#ifndef MY_GEOMETRY.HPP_MY_GEOMETRY_HPP\n" + "#define MY_GEOMETRY .HPP_MY_GEOMETRY_HPP\n" + "#endif // MY_GEOMETRY.HPP_MY_GEOMETRY_HPP\n", + encoding="utf-8", + ) + + self.assertFalse(check_header_guard(header, root)[0]) + self.assertTrue(fix_header_guard(header, root)) + self.assertTrue(check_header_guard(header, root)[0]) + self.assertEqual( + header.read_text(encoding="utf-8"), + "#ifndef MY_GEOMETRY_HPP\n" + "#define MY_GEOMETRY_HPP\n" + "#endif // MY_GEOMETRY_HPP\n", + ) diff --git a/split_square_verify.cpp b/split_square_verify.cpp index 9c115c4..ad3d2bd 100644 --- a/split_square_verify.cpp +++ b/split_square_verify.cpp @@ -32,24 +32,20 @@ PHLEX_REGISTER_ALGORITHMS(m, config) auto const parent_layer = config.get("parent_layer"); auto const child_layer = config.get("child_layer"); - m.unfold( - "split", - &VectorSplitter::predicate, - &VectorSplitter::unfold, - child_layer, - concurrency::unlimited) - .input_family(product_selector{ - .creator = "input", .layer = parent_layer, .suffix = "numbers"}) + m.unfold("split", + &VectorSplitter::predicate, + &VectorSplitter::unfold, + child_layer, + concurrency::unlimited) + .input_family(product_selector{.creator = "input", .layer = parent_layer, .suffix = "numbers"}) .output_product_suffixes("number"); m.transform( "square", [](int n) { return n * n; }, concurrency::unlimited) - .input_family( - product_selector{.creator = "split", .layer = child_layer, .suffix = "number"}) + .input_family(product_selector{.creator = "split", .layer = child_layer, .suffix = "number"}) .output_product_suffixes("squared"); m.observe( "verify", [](int sq) { assert(sq >= 0); }, concurrency::unlimited) - .input_family( - product_selector{.creator = "square", .layer = child_layer, .suffix = "squared"}); + .input_family(product_selector{.creator = "square", .layer = child_layer, .suffix = "squared"}); } diff --git a/subtract.py b/subtract.py index 5e16c6b..8875690 100644 --- a/subtract.py +++ b/subtract.py @@ -4,6 +4,7 @@ real. It serves as a "Hello, World" equivalent for running Python code. """ + def subtract(i: int, j: int) -> int: """Subtract 'j' from 'i' and return the difference. @@ -36,6 +37,6 @@ def PHLEX_REGISTER_ALGORITHMS(m, config): Returns: None """ - m.transform(subtract, - input_family = config["input"], - output_product_suffixes = config["output"]) + m.transform( + subtract, input_family=config["input"], output_product_suffixes=config["output"] + )