Skip to content
Open
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
15 changes: 11 additions & 4 deletions sbncode/CAFMaker/CAFMaker_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "sbncode/CAFMaker/FillReco.h"
#include "sbncode/CAFMaker/FillExposure.h"
#include "sbncode/CAFMaker/FillTrigger.h"
#include "sbncode/CAFMaker/SRDefaults.h"
#include "sbncode/CAFMaker/Utils.h"

// C/C++ includes
Expand Down Expand Up @@ -554,19 +555,25 @@ void CAFMaker::SBNDShiftPMTReference(StandardRecord &rec, double SBNDFrame) cons
}

void CAFMaker::FixPMTReferenceTimes(StandardRecord &rec, double PMT_reference_time) {

// Fix the flashes
for (SROpFlash &f: rec.opflashes) {
f.time += PMT_reference_time;
f.timemean += PMT_reference_time;
f.firsttime += PMT_reference_time;
}

// Fix the flash matches
for (SRSlice &s: rec.slc) {
s.fmatch.time += PMT_reference_time;
if (s.fmatch.time != SRDefaults::For(s.fmatch).time)
s.fmatch.time += PMT_reference_time;

s.barycenterFM.flashTime +=PMT_reference_time;
s.barycenterFM.flashFirstHit +=PMT_reference_time;
if (s.barycenterFM.flashTime != SRDefaults::For(s.barycenterFM).flashTime)
s.barycenterFM.flashTime += PMT_reference_time;

if (s.barycenterFM.flashFirstHit != SRDefaults::For(s.barycenterFM).flashFirstHit)
s.barycenterFM.flashFirstHit += PMT_reference_time;

}

// TODO: fix more?
Expand Down
1 change: 1 addition & 0 deletions sbncode/CAFMaker/RecoUtils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ art_make_library( LIBRARY_NAME caf_RecoUtils
larsim::MCCheater_BackTrackerService_service
larsim::MCCheater_ParticleInventoryService_service
larcorealg::Geometry
sbnanaobj::StandardRecord
)
27 changes: 27 additions & 0 deletions sbncode/CAFMaker/SRDefaults.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* @file sbncode/CAFMaker/SRDefaults.cxx
* @brief Discovery of default values in Standard Record classes.
* @author Gianluca Petrillo (petrillo@slac.stanford.edu)
* @date May 6, 2026
* @see sbncode/CAFMaker/SRDefaults.h
*/

#include "sbncode/CAFMaker/SRDefaults.h"


// -----------------------------------------------------------------------------
namespace {

template<typename... SRobjs>
std::tuple<SRobjs...> staticInit
(std::tuple<SRobjs...> objs)
{ (std::get<SRobjs>(objs).setDefault(), ...); return objs; }

} // local namespace


// -----------------------------------------------------------------------------
caf::SRDefaults::SupportedTypes const caf::SRDefaults::defaultObjs
= staticInit(caf::SRDefaults::SupportedTypes{});

// -----------------------------------------------------------------------------
103 changes: 103 additions & 0 deletions sbncode/CAFMaker/SRDefaults.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* @file sbncode/CAFMaker/SRDefaults.h
* @brief Discovery of default values in Standard Record classes.
* @author Gianluca Petrillo (petrillo@slac.stanford.edu)
* @date May 6, 2026
* @see sbncode/CAFMaker/SRDefaults.cxx
*/


#ifndef SBNCODE_CAFMAKER_SRDEFAULTS_H
#define SBNCODE_CAFMAKER_SRDEFAULTS_H

// Standard Record objects
#include "sbnanaobj/StandardRecord/SRFlashMatch.h"
#include "sbnanaobj/StandardRecord/SRTPCPMTBarycenterMatch.h"

// C/C++ standard library
#include <tuple>
#include <type_traits> // std::decay_t

// -----------------------------------------------------------------------------
namespace caf { class SRDefaults; }
/**
* @brief Collection of Standard Record objects with defaulted values.
*
* Example of usage: to test if `caf::SRFlashMatch::time` is still the default
* value:
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
* if (match.time == caf::SRDefaults::For<caf::SRFlashMatch>().time) { ... }
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Note that this may be, and usually is, different from the
* default-constructed value (e.g. `caf::SRFlashMatch{}.time`).
*
*
* Extension directions
* ---------------------
*
* Only classes that offer `setDefault()` member function can be included in
* this class. To add such a class:
* 1. include the appropriate header above;
* 2. add the name of the class as a `tuple` type in the definition of
* `SupportedTypes`.
*
* In case a class is used that is not supported, a static error on `std::get()`
* is typically emitted. In GCC 12.1.0:
* ```
* static assertion failed: the type T in std::get<T> must occur exactly once in the tuple
* ```
*
*/
class caf::SRDefaults {

public:

/// A tuple with all the types included in this object.
using SupportedTypes = std::tuple<
caf::SRFlashMatch,
caf::SRTPCPMTBarycenterMatch
>;

/// Single copy of defaulted objects.
static SupportedTypes const defaultObjs;


/**
* @brief Returns an object of type `SRobj` with its default values set.
* @tparam SRobj type of the Standard Record object to obtain
* @return a static object of type `SRobj` with its default values set
*
* A call of this method must explicitly include the template type `SRobj`,
* e.g. `caf::SRDefaults::For<caf::SRTrack>()`.
*/
template <typename SRobj>
static SRobj const& For();

/**
* @brief Returns an object of type `SRobj` with its default values set.
* @tparam SRobj type of the Standard Record object to obtain
* @return a static object of type `SRobj` with its default values set
*
* A call to this method should have as argument an existing object of the
* `SRobj` type, that can be used to omit the explicit type in the call;
* e.g., `caf::SRDefaults::For(track)`.
*/
template <typename SRobj>
static SRobj const& For(SRobj const&);

};


// -----------------------------------------------------------------------------
// --- template implementation
// -----------------------------------------------------------------------------
template <typename SRobj>
SRobj const& caf::SRDefaults::For() { return std::get<SRobj>(defaultObjs); }

template <typename SRobj>
SRobj const& caf::SRDefaults::For(SRobj const&)
{ return For<std::decay_t<SRobj>>(); }

// -----------------------------------------------------------------------------

#endif // SBNCODE_CAFMAKER_SRDEFAULTS_H
1 change: 1 addition & 0 deletions sbncode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ add_subdirectory(CosmicID)
add_subdirectory(DetSim)
add_subdirectory(Cluster3D)
add_subdirectory(HitFinder)
add_subdirectory(Utilities)

# Supera
#
Expand Down
Loading