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

First pass at KalSeedCollection sculpting modules #1342

Draft
wants to merge 1 commit 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
24 changes: 24 additions & 0 deletions Blinding/inc/KalSeedPrescaleTool.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Ed Callaghan
// Interface for art tool to calculate a KalSeed-dependent functional prescale
// September 2024

#ifndef Blinding_KalSeedPrescaleTool_hh
#define Blinding_KalSeedPrescaleTool_hh

#include "Offline/RecoDataProducts/inc/KalSeed.hh"

namespace mu2e{
class KalSeedPrescaleTool{
public:
KalSeedPrescaleTool() = default;
double AcceptanceRate(const KalSeed&);

protected:
virtual double calculate_acceptance_rate(const KalSeed&) = 0;

private:
/**/
};
} // namespace mu2e

#endif
59 changes: 59 additions & 0 deletions Blinding/inc/MomentumLookupKalSeedPrescaleTool.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Ed Callaghan
// art tool to prescale KalSeeds via a lookup-table on the momentum
// September 2024

#ifndef Blinding_MomentumLookupKalSeedPrescaleTool_hh
#define Blinding_MomentumLookupKalSeedPrescaleTool_hh

// stl
#include <vector>

// art
#include "art/Utilities/ToolConfigTable.h"
#include "art/Utilities/ToolMacros.h"

// fhiclcpp
#include "fhiclcpp/types/Atom.h"
#include "fhiclcpp/types/Comment.h"
#include "fhiclcpp/types/Name.h"
#include "fhiclcpp/types/Sequence.h"

// mu2e
#include "Offline/Blinding/inc/UnivariateLookupKalSeedPrescaleTool.hh"
#include "Offline/DataProducts/inc/SurfaceId.hh"

namespace mu2e{
class MomentumLookupKalSeedPrescaleTool: public UnivariateLookupKalSeedPrescaleTool{
public:
struct Config{
fhicl::Sequence<std::string> surface_ids{
fhicl::Name("SurfaceIds"),
fhicl::Comment("Prioritized sequence of mu2e::SurfaceIds at which tracks may be sampled")
};
fhicl::Atom<double> momentum_start{
fhicl::Name("momentum_start"),
fhicl::Comment("Leftmost defined momentum value of lookup table")
};
fhicl::Atom<double> momentum_step_size{
fhicl::Name("momentum_step_size"),
fhicl::Comment("Abscissa step size of lookup table")
};
fhicl::Sequence<double> prescale{
fhicl::Name("prescale"),
fhicl::Comment("Sequence containing the coordinates of lookup table")
};
};

using Parameters = art::ToolConfigTable<Config>;
MomentumLookupKalSeedPrescaleTool(const Parameters&);

protected:
SurfaceIdCollection _surface_ids;
double calculate_observable(const KalSeed&);

private:
/**/
};
} // namespace mu2e

#endif
60 changes: 60 additions & 0 deletions Blinding/inc/QuasiImpactParameterLookupKalSeedPrescaleTool.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Ed Callaghan
// art tool to prescale KalSeeds via a lookup-table on the ~minimum DS radial coordinate
// September 2024

#ifndef Blinding_QuasiImpactParameterLookupKalSeedPrescaleTool_hh
#define Blinding_QuasiImpactParameterLookupKalSeedPrescaleTool_hh

// stl
#include <cmath>
#include <vector>

// art
#include "art/Utilities/ToolConfigTable.h"
#include "art/Utilities/ToolMacros.h"

// fhiclcpp
#include "fhiclcpp/types/Atom.h"
#include "fhiclcpp/types/Comment.h"
#include "fhiclcpp/types/Name.h"
#include "fhiclcpp/types/Sequence.h"

// mu2e
#include "Offline/Blinding/inc/UnivariateLookupKalSeedPrescaleTool.hh"
#include "Offline/DataProducts/inc/SurfaceId.hh"

namespace mu2e{
class QuasiImpactParameterLookupKalSeedPrescaleTool: public UnivariateLookupKalSeedPrescaleTool{
public:
struct Config{
fhicl::Sequence<std::string> surface_ids{
fhicl::Name("SurfaceIds"),
fhicl::Comment("Prioritized sequence of mu2e::SurfaceIds at which tracks may be sampled")
};
fhicl::Atom<double> radius_start{
fhicl::Name("radius_start"),
fhicl::Comment("Leftmost defined radius value of lookup table")
};
fhicl::Atom<double> radius_step_size{
fhicl::Name("radius_step_size"),
fhicl::Comment("Abscissa step size of lookup table")
};
fhicl::Sequence<double> prescale{
fhicl::Name("prescale"),
fhicl::Comment("Sequence containing the coordinates of lookup table")
};
};

using Parameters = art::ToolConfigTable<Config>;
QuasiImpactParameterLookupKalSeedPrescaleTool(const Parameters&);

protected:
SurfaceIdCollection _surface_ids;
double calculate_observable(const KalSeed&);

private:
/**/
};
} // namespace mu2e

#endif
60 changes: 60 additions & 0 deletions Blinding/inc/TrackerExitAzimuthLookupKalSeedPrescaleTool.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Ed Callaghan
// art tool to prescale KalSeeds via a lookup-table on the tracker exit azimuthal coordinate
// September 2024

#ifndef Blinding_TrackerExitAzimuthLookupKalSeedPrescaleTool_hh
#define Blinding_TrackerExitAzimuthLookupKalSeedPrescaleTool_hh

// stl
#include <cmath>
#include <vector>

// art
#include "art/Utilities/ToolConfigTable.h"
#include "art/Utilities/ToolMacros.h"

// fhiclcpp
#include "fhiclcpp/types/Atom.h"
#include "fhiclcpp/types/Comment.h"
#include "fhiclcpp/types/Name.h"
#include "fhiclcpp/types/Sequence.h"

// mu2e
#include "Offline/Blinding/inc/UnivariateLookupKalSeedPrescaleTool.hh"
#include "Offline/DataProducts/inc/SurfaceId.hh"

namespace mu2e{
class TrackerExitAzimuthLookupKalSeedPrescaleTool: public UnivariateLookupKalSeedPrescaleTool{
public:
struct Config{
fhicl::Sequence<std::string> surface_ids{
fhicl::Name("SurfaceIds"),
fhicl::Comment("Prioritized sequence of mu2e::SurfaceIds at which tracks may be sampled")
};
fhicl::Atom<double> azimuth_start{
fhicl::Name("azimuth_start"),
fhicl::Comment("Leftmost defined azimuthal value of lookup table")
};
fhicl::Atom<double> azimuth_step_size{
fhicl::Name("azimuth_step_size"),
fhicl::Comment("Abscissa step size of lookup table")
};
fhicl::Sequence<double> prescale{
fhicl::Name("prescale"),
fhicl::Comment("Sequence containing the coordinates of lookup table")
};
};

using Parameters = art::ToolConfigTable<Config>;
TrackerExitAzimuthLookupKalSeedPrescaleTool(const Parameters&);

protected:
SurfaceIdCollection _surface_ids;
double calculate_observable(const KalSeed&);

private:
/**/
};
} // namespace mu2e

#endif
39 changes: 39 additions & 0 deletions Blinding/inc/UnivariateLookupKalSeedPrescaleTool.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Ed Callaghan
// Interface for art tool to calculate a single-variable functional prescale
// September 2024

#ifndef Blinding_UnivariateLookupKalSeedPrescaleTool_hh
#define Blinding_UnivariateLookupKalSeedPrescaleTool_hh

// stl
#include <vector>

// boost
#include <boost/math/interpolators/cardinal_cubic_b_spline.hpp>

// mu2e
#include "Offline/Blinding/inc/KalSeedPrescaleTool.hh"
#include "Offline/RecoDataProducts/inc/KalSeed.hh"

using boost::math::interpolators::cardinal_cubic_b_spline;

namespace mu2e{
class UnivariateLookupKalSeedPrescaleTool: public KalSeedPrescaleTool{
public:
UnivariateLookupKalSeedPrescaleTool(double,
double,
std::vector<double>);

protected:
cardinal_cubic_b_spline<double> _spline;
double _xmin;
double _xmax;
double calculate_acceptance_rate(const KalSeed&) override;
virtual double calculate_observable(const KalSeed&) = 0;

private:
/**/
};
} // namespace mu2e

#endif
104 changes: 104 additions & 0 deletions Blinding/src/KalSeedFunctionalPrescale_module.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Ed Callaghan
// Apply a functional prescale calculated from KalSeed by configurable rule
// September 2024

// stl
#include <memory>

// art
#include "art/Framework/Core/EDProducer.h"
#include "art/Framework/Core/detail/EngineCreator.h"
#include "art/Framework/Principal/Event.h"
#include "art/Framework/Services/Optional/RandomNumberGenerator.h"
#include "art/Framework/Services/Registry/ServiceHandle.h"
#include "art/Utilities/make_tool.h"

// cetlib_except
#include "cetlib_except/exception.h"

// clhep
#include "CLHEP/Random/RandFlat.h"

// fhiclcpp
#include "fhiclcpp/ParameterSet.h"
#include "fhiclcpp/types/Atom.h"
#include "fhiclcpp/types/Comment.h"
#include "fhiclcpp/types/DelegatedParameter.h"
#include "fhiclcpp/types/Name.h"

// mu2e
#include "Offline/Blinding/inc/KalSeedPrescaleTool.hh"
#include "Offline/RecoDataProducts/inc/KalSeed.hh"
#include "Offline/SeedService/inc/SeedService.hh"

namespace mu2e{
class KalSeedFunctionalPrescale: public art::EDProducer{
public:
struct Config{
fhicl::Atom<art::InputTag> kalseed_tag{
fhicl::Name("KalSeedCollection"),
fhicl::Comment("art::InputTag of KalSeedCollection to prescale")
};
fhicl::DelegatedParameter tool_config{
fhicl::Name("tool"),
fhicl::Comment("Configuration for prescale calculation tool")
};
};

using Parameters = art::EDProducer::Table<Config>;
KalSeedFunctionalPrescale(const Parameters&);

protected:
art::InputTag _kalseed_tag;
std::unique_ptr<KalSeedPrescaleTool> _tool;
art::RandomNumberGenerator::base_engine_t& _engine;
std::unique_ptr<CLHEP::RandFlat> _uniform;

bool Query(const KalSeed&);

private:
void produce(art::Event&);
};

KalSeedFunctionalPrescale::KalSeedFunctionalPrescale(const Parameters& config):
art::EDProducer(config),
_kalseed_tag(config().kalseed_tag()),
_engine(createEngine(art::ServiceHandle<SeedService>()->getSeed())){
// instantiate prescale calculator and rng
auto tool_config = config().tool_config.get<fhicl::ParameterSet>();
_tool = art::make_tool<KalSeedPrescaleTool>(tool_config);
_uniform = std::make_unique<CLHEP::RandFlat>(_engine);
// framework hook
this->consumes<KalSeedCollection>(_kalseed_tag);
this->produces<KalSeedCollection>();
}

bool KalSeedFunctionalPrescale::Query(const KalSeed& kalseed){
// calculate probability to pass the track
double acceptance_rate = _tool->AcceptanceRate(kalseed);
double x = _uniform->fire();

// pass the track with that probability
auto rv = false;
if (x < acceptance_rate){
rv = true;
}

return rv;
}

void KalSeedFunctionalPrescale::produce(art::Event& event){
auto handle = event.getValidHandle<KalSeedCollection>(_kalseed_tag);
auto accepted = std::make_unique<KalSeedCollection>();
for (const auto& kalseed: *handle){
auto passed = this->Query(kalseed);
if (passed){
accepted->push_back(kalseed);
}
}

event.put(std::move(accepted));
}
} // namespace mu2e

DEFINE_ART_MODULE(mu2e::KalSeedFunctionalPrescale)
12 changes: 12 additions & 0 deletions Blinding/src/KalSeedPrescaleTool.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Ed Callaghan
// Interface for art tool to calculate a KalSeed-dependent functional prescale
// September 2024

#include "Offline/Blinding/inc/KalSeedPrescaleTool.hh"

namespace mu2e{
double KalSeedPrescaleTool::AcceptanceRate(const KalSeed& kalseed){
auto rv = this->calculate_acceptance_rate(kalseed);
return rv;
}
} // namespace mu2e
Loading