Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Timeframe splitting #1510

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/global/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ add_subdirectory(reco)
add_subdirectory(pid)
add_subdirectory(pid_lut)
add_subdirectory(beam)
add_subdirectory(splitting)
34 changes: 34 additions & 0 deletions src/global/splitting/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
cmake_minimum_required(VERSION 3.16)

get_filename_component(PLUGIN_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)

# Function creates ${PLUGIN_NAME}_plugin and ${PLUGIN_NAME}_library targets
# Setting default includes, libraries and installation paths
plugin_add(${PLUGIN_NAME} PLUGIN_USE_CC_ONLY)

# The macro grabs sources as *.cc *.cpp *.c and headers as *.h *.hh *.hpp Then
# correctly sets sources for ${_name}_plugin and ${_name}_library targets Adds
# headers to the correct installation directory
plugin_glob_all(${PLUGIN_NAME})

# Find dependencies plugin_add_dd4hep(${PLUGIN_NAME}#)
# plugin_add_acts(${PLUGIN_NAME}) plugin_add_cern_root(${PLUGIN_NAME})
plugin_add_event_model(${PLUGIN_NAME})

# Add include directories (works same as target_include_directories)
# plugin_include_directories(${PLUGIN_NAME} SYSTEM PUBLIC ... )

# Add libraries (same as target_include_directories but for both plugin and
# library)
plugin_link_libraries(${PLUGIN_NAME} algorithms_digi_library
algorithms_tracking_library)
#
# Add include directories (works same as target_include_directories)
# plugin_include_directories(${PLUGIN_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}
# SYSTEM PUBLIC ${podio_INCLUDE_DIR} ${EDM4HEP_INCLUDE_DIR}
# ${DD4hep_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} ${EDM4EIC_INCLUDE_DIRS})
#
# Add libraries (works same as target_include_directories)
# plugin_link_libraries(${PLUGIN_NAME} ${ROOT_LIBRARIES}
# algorithms_tracking_library EDM4HEP::edm4hep EDM4EIC::edm4eic spdlog::spdlog
# Boost::boost ${ROOT_EG_LIBRARY})
44 changes: 44 additions & 0 deletions src/global/splitting/TimeframeSplitter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2024, Jefferson Science Associates, LLC.
// Subject to the terms in the LICENSE file found in the top-level directory.
Comment on lines +1 to +2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Copyright 2024, Jefferson Science Associates, LLC.
// Subject to the terms in the LICENSE file found in the top-level directory.
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (C) 2024, Nathan Brei


#pragma once

#include <JANA/JEventUnfolder.h>

struct TimeframeSplitter : public JEventUnfolder {

// PodioInput<ExampleCluster> m_timeslice_clusters_in {this, {.name = "ts_protoclusters", .level = JEventLevel::Timeslice}};

// PodioOutput<ExampleCluster> m_event_clusters_out {this, "evt_protoclusters"};
// PodioOutput<EventInfo> m_event_info_out {this, "evt_info"};

TimeframeSplitter() {
SetTypeName(NAME_OF_THIS);
SetParentLevel(JEventLevel::Timeslice);
SetChildLevel(JEventLevel::PhysicsEvent);
}


Result Unfold(const JEvent& parent, JEvent& child, int child_idx) override {

auto timeslice_nr = parent.GetEventNumber();
size_t event_nr = 100*timeslice_nr + child_idx;
child.SetEventNumber(event_nr);

// For now, a one-to-one relationship between timeslices and events

/*
auto event_clusters_out = std::make_unique<ExampleClusterCollection>();
event_clusters_out->setSubsetCollection(true);
event_clusters_out->push_back(m_timeslice_clusters_in()->at(child_idx));

auto event_info_out = std::make_unique<EventInfoCollection>();
event_info_out->push_back(MutableEventInfo(event_nr, timeslice_nr, 0));

m_event_clusters_out() = std::move(event_clusters_out);
m_event_info_out() = std::move(event_info_out);
*/

return (child_idx == 2) ? Result::NextChildNextParent : Result::NextChildKeepParent;
}
};
28 changes: 28 additions & 0 deletions src/global/splitting/splitting.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2024, Jefferson Science Associates, LLC.
// Subject to the terms in the LICENSE file found in the top-level directory.

Comment on lines +1 to +3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Copyright 2024, Jefferson Science Associates, LLC.
// Subject to the terms in the LICENSE file found in the top-level directory.
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (C) 2024, Nathan Brei


#include "TimeframeSplitter.h"
#include <JANA/JApplication.h>


extern "C"{
void InitPlugin(JApplication *app) {

InitJANAPlugin(app);

// Unfolder that takes timeframes and splits them into physics events.
app->Add(new TimeframeSplitter());

// Factory that produces timeslice-level protoclusters from timeslice-level hits
/*
app->Add(new JOmniFactoryGeneratorT<MyProtoclusterFactory>(
{ .tag = "timeslice_protoclusterizer",
.level = JEventLevel::Timeslice,
.input_names = {"hits"},
.output_names = {"ts_protoclusters"}
}));
*/

}
} // "C"
34 changes: 34 additions & 0 deletions src/services/io/podio/JEventSourcePODIO_generator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (C) 2024, Nathan Brei


#include <JANA/JEventSourceGenerator.h>
#include "JEventSourcePODIO.h"


class JEventSourcePODIO_generator : public JEventSourceGenerator {

JEventSource* MakeJEventSource(std::string resource_name) override {

auto* source = new JEventSourcePODIO(resource_name, nullptr);
source->SetResourceName(resource_name);

// Check if the string "timeslices" appears anywhere in our filename.
// If so, we assume the file contains timeslices, otherwise it contains physics events.
// Another approach might be to peek at the file's contents
if (resource_name.find("timeslices") != std::string::npos) {
source->SetLevel(JEventLevel::Timeslice);
}
else {
source->SetLevel(JEventLevel::PhysicsEvent);
}
return source;
}

double CheckOpenable(std::string resource_name) override {
// In theory, we should check whether PODIO can open the file and
// whether it contains an 'events' or 'timeslices' tree. If not, return 0.
if (resource_name.find(".root") != std::string::npos) {
return 0.01;
}
return 0;
}
};
5 changes: 2 additions & 3 deletions src/services/io/podio/podio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
//

#include <JANA/JApplication.h>
#include <JANA/JEventSourceGeneratorT.h>

#include "JEventProcessorPODIO.h"
#include "JEventSourcePODIO.h"
#include "JEventSourcePODIO_generator.h"


// Make this a JANA plugin
extern "C" {
void InitPlugin(JApplication *app) {
InitJANAPlugin(app);
app->Add(new JEventSourceGeneratorT<JEventSourcePODIO>());
app->Add(new JEventSourcePODIO_generator);

// Disable this behavior for now so one can run eicrecon with only the
// input file as an argument.
Expand Down
1 change: 1 addition & 0 deletions src/utilities/eicrecon/eicrecon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ std::vector<std::string> EICRECON_DEFAULT_PLUGINS = {
"LUMISPECCAL",
"podio",
"janatop",
"splitter"
};

int main( int narg, char **argv)
Expand Down
Loading