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

Fiducial volume coordaintes #63

Merged
merged 4 commits into from
Mar 6, 2024
Merged
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
337 changes: 219 additions & 118 deletions projects/detector/private/DetectorModel.cxx

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions projects/detector/private/pybindings/Axis1D.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class PyAxis1D : public LI::detector::Axis1D {
clone
);
}
std::shared_ptr<const Axis1D> create() const override {
std::shared_ptr<Axis1D> create() const override {
PYBIND11_OVERRIDE_PURE_NAME(
std::shared_ptr<const Axis1D>,
std::shared_ptr<Axis1D>,
Axis1D,
"_create",
create
Expand Down
6 changes: 3 additions & 3 deletions projects/detector/private/pybindings/DensityDistribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ class PyDensityDistribution : public LI::detector::DensityDistribution {
);
}

DensityDistribution * clone() const override {
virtual DensityDistribution * clone() const override {
PYBIND11_OVERRIDE_PURE_NAME(
DensityDistribution *,
DensityDistribution,
"_clone",
clone
);
}
std::shared_ptr<const DensityDistribution> create() const override {
virtual std::shared_ptr<DensityDistribution> create() const override {
PYBIND11_OVERRIDE_PURE_NAME(
std::shared_ptr<const DensityDistribution>,
std::shared_ptr<DensityDistribution>,
DensityDistribution,
"_create",
create
Expand Down
2 changes: 2 additions & 0 deletions projects/detector/private/pybindings/DetectorModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,7 @@ void register_DetectorModel(pybind11::module_ & m) {
.def("DetDirectionToGeoDirection", (
GeometryDirection (DetectorModel::*)(DetectorDirection const &) const
)(&DetectorModel::ToGeo))
.def("ParseFiducialVolume", (std::shared_ptr<LI::geometry::Geometry> (*)(std::string, std::string))(&DetectorModel::ParseFiducialVolume))
.def("ParseFiducialVolume", (std::shared_ptr<LI::geometry::Geometry> (*)(std::string, LI::math::Vector3D, LI::math::Quaternion))(&DetectorModel::ParseFiducialVolume))
;
}
4 changes: 2 additions & 2 deletions projects/detector/private/pybindings/Distribution1D.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class PyDistribution1D : public LI::detector::Distribution1D {
clone
);
}
std::shared_ptr<const Distribution1D> create() const override {
virtual std::shared_ptr<Distribution1D> create() const override {
PYBIND11_OVERRIDE_PURE_NAME(
std::shared_ptr<const Distribution1D>,
std::shared_ptr<Distribution1D>,
Distribution1D,
"_create",
create
Expand Down
2 changes: 1 addition & 1 deletion projects/detector/public/LeptonInjector/detector/Axis1D.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ friend cereal::access;
virtual bool compare(const Axis1D& dens_distr) const = 0;

virtual Axis1D* clone() const = 0;
virtual std::shared_ptr<const Axis1D> create() const = 0;
virtual std::shared_ptr<Axis1D> create() const = 0;

virtual double GetX(const math::Vector3D& xi) const = 0;
virtual double GetdX(const math::Vector3D& xi, const math::Vector3D& direction) const = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class CartesianAxis1D : public Axis1D {
bool compare(const Axis1D& dens_distr) const override;

Axis1D* clone() const override { return new CartesianAxis1D(*this); };
std::shared_ptr<const Axis1D> create() const override {
return std::shared_ptr<const Axis1D>(new CartesianAxis1D(*this));
std::shared_ptr<Axis1D> create() const override {
return std::shared_ptr<Axis1D>(new CartesianAxis1D(*this));
};

double GetX(const math::Vector3D& xi) const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class DensityDistribution1D<CartesianAxis1D, DistributionT, typename std::enable
};

DensityDistribution* clone() const override { return new T(*this); };
std::shared_ptr<const DensityDistribution> create() const override {
std::shared_ptr<DensityDistribution> create() override {
return std::shared_ptr<const DensityDistribution>(new T(*this));
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class DensityDistribution1D<AxisT, ConstantDistribution1D, typename std::enable_
};

DensityDistribution* clone() const override { return new T(*this); };
std::shared_ptr<const DensityDistribution> create() const override {
return std::shared_ptr<const DensityDistribution>(new T(*this));
std::shared_ptr<DensityDistribution> create() const override {
return std::shared_ptr<DensityDistribution>(new T(*this));
};

double Derivative(const math::Vector3D& xi,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class ConstantDistribution1D : public Distribution1D {
ConstantDistribution1D(double val);
bool compare(const Distribution1D& dist) const override;
Distribution1D* clone() const override { return new ConstantDistribution1D(*this); };
std::shared_ptr<const Distribution1D> create() const override {
return std::shared_ptr<const Distribution1D>(new ConstantDistribution1D(*this));
std::shared_ptr<Distribution1D> create() const override {
return std::shared_ptr<Distribution1D>(new ConstantDistribution1D(*this));
};
double Derivative(double x) const override;
double AntiDerivative(double x) const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ friend cereal::access;


virtual DensityDistribution* clone() const = 0;
virtual std::shared_ptr<const DensityDistribution> create() const = 0;
virtual std::shared_ptr<DensityDistribution> create() const = 0;

virtual double Derivative(const math::Vector3D& xi,
const math::Vector3D& direction) const = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class DensityDistribution1D
};

DensityDistribution* clone() const override { return new T(*this); };
std::shared_ptr<const DensityDistribution> create() const override {
return std::shared_ptr<const DensityDistribution>(new T(*this));
std::shared_ptr<DensityDistribution> create() const override {
return std::shared_ptr<DensityDistribution>(new T(*this));
};

double Derivative(const math::Vector3D& xi,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,13 @@ friend LI::detector::Path;

static geometry::Geometry::IntersectionList GetOuterBounds(geometry::Geometry::IntersectionList const & intersections);

static std::tuple<LI::math::Vector3D, LI::math::Quaternion> ParseDetector(std::stringstream & ss);
static std::shared_ptr<geometry::Geometry> ParseGeometryObject(std::stringstream & line);
static int ParseMaterialID(std::stringstream & line, MaterialModel const & materials);
static std::shared_ptr<detector::DensityDistribution> ParseDensityDistribution(std::stringstream & line);
static std::shared_ptr<geometry::Geometry> ParseFiducialVolume(std::string fiducial_line, std::string origin_line);
static std::shared_ptr<geometry::Geometry> ParseFiducialVolume(std::string line, LI::math::Vector3D detector_origin, LI::math::Quaternion detector_quaternion);

private:
void LoadDefaultMaterials();
void LoadDefaultSectors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ friend cereal::access;
bool operator!=(const Distribution1D& dist) const;
virtual bool compare(const Distribution1D& dist) const = 0;
virtual Distribution1D* clone() const = 0;
virtual std::shared_ptr<const Distribution1D> create() const = 0;
virtual std::shared_ptr<Distribution1D> create() const = 0;
virtual double Derivative(double x) const = 0;
virtual double AntiDerivative(double x) const = 0;
virtual double Evaluate(double x) const = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ friend cereal::access;
ExponentialDistribution1D(double sigma);
bool compare(const Distribution1D& dist) const override;
Distribution1D* clone() const override { return new ExponentialDistribution1D(*this); };
std::shared_ptr<const Distribution1D> create() const override {
return std::shared_ptr<const Distribution1D>(new ExponentialDistribution1D(*this));
std::shared_ptr<Distribution1D> create() const override {
return std::shared_ptr<Distribution1D>(new ExponentialDistribution1D(*this));
};
double Derivative(double x) const override;
double AntiDerivative(double x) const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ friend cereal::access;
PolynomialDistribution1D(const std::vector<double>&);
bool compare(const Distribution1D& dist) const override;
Distribution1D* clone() const override { return new PolynomialDistribution1D(*this); };
std::shared_ptr<const Distribution1D> create() const override {
return std::shared_ptr<const Distribution1D>(new PolynomialDistribution1D(*this));
std::shared_ptr<Distribution1D> create() const override {
return std::shared_ptr<Distribution1D>(new PolynomialDistribution1D(*this));
};
double Derivative(double x) const override;
double AntiDerivative(double x) const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ friend cereal::access;
bool compare(const Axis1D& dens_distr) const override;

Axis1D* clone() const override { return new RadialAxis1D(*this); };
std::shared_ptr<const Axis1D> create() const override {
return std::shared_ptr<const Axis1D>(new RadialAxis1D(*this));
std::shared_ptr<Axis1D> create() const override {
return std::shared_ptr<Axis1D>(new RadialAxis1D(*this));
};

double GetX(const math::Vector3D& xi) const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DensityDistribution1D<RadialAxis1D,PolynomialDistribution1D>
};

DensityDistribution* clone() const override { return new DensityDistribution1D(*this); };
std::shared_ptr<const DensityDistribution> create() const override {
std::shared_ptr<DensityDistribution> create() override {
return std::shared_ptr<const DensityDistribution>(new DensityDistribution1D(*this));
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ void SecondaryBoundedVertexDistribution::SampleVertex(std::shared_ptr<LI::utilit

// Check if fiducial volume is provided
if(fiducial_volume) {
std::vector<LI::geometry::Geometry::Intersection> fid_intersections = fiducial_volume->Intersections(detector_model->ToGeo(DetectorPosition(endcap_0)),detector_model->ToGeo(DetectorDirection(dir)));
std::vector<LI::geometry::Geometry::Intersection> fid_intersections = fiducial_volume->Intersections(endcap_0, dir);
// If the path intersects the fiducial volume, restrict position to that volume
if(!fid_intersections.empty()) {
// make sure the first intersection happens before the maximum generation length
// and the last intersection happens in front of the generation point
bool update_path = (fid_intersections.front().distance < max_length
&& fid_intersections.back().distance > 0);
if(update_path) {
DetectorPosition first_point = (fid_intersections.front().distance > 0) ? detector_model->ToDet(GeometryPosition(fid_intersections.front().position)) : DetectorPosition(endcap_0);
DetectorPosition last_point = (fid_intersections.back().distance < max_length) ? detector_model->ToDet(GeometryPosition(fid_intersections.back().position)) : DetectorPosition(endcap_1);
path.SetPoints(first_point, last_point);
LI::math::Vector3D first_point((fid_intersections.front().distance > 0) ? fid_intersections.front().position : endcap_0);
LI::math::Vector3D last_point((fid_intersections.back().distance < max_length) ? fid_intersections.back().position : endcap_1);
path.SetPoints(DetectorPosition(first_point), DetectorPosition(last_point));
}
}
}
Expand Down Expand Up @@ -128,16 +128,16 @@ double SecondaryBoundedVertexDistribution::GenerationProbability(std::shared_ptr

// Check if fiducial volume is provided
if(fiducial_volume) {
std::vector<LI::geometry::Geometry::Intersection> fid_intersections = fiducial_volume->Intersections(detector_model->ToGeo(DetectorPosition(endcap_0)),detector_model->ToGeo(DetectorDirection(dir)));
std::vector<LI::geometry::Geometry::Intersection> fid_intersections = fiducial_volume->Intersections(endcap_0, dir);
// If the path intersects the fiducial volume, restrict position to that volume
if(!fid_intersections.empty()) {
// make sure the first intersection happens before the maximum generation length
// and the last intersection happens in front of the generation point
bool update_path = (fid_intersections.front().distance < max_length
&& fid_intersections.back().distance > 0);
if(update_path) {
DetectorPosition first_point = (fid_intersections.front().distance > 0) ? detector_model->ToDet(GeometryPosition(fid_intersections.front().position)) : DetectorPosition(endcap_0);
DetectorPosition last_point = (fid_intersections.back().distance < max_length) ? detector_model->ToDet(GeometryPosition(fid_intersections.back().position)) : DetectorPosition(endcap_1);
DetectorPosition first_point((fid_intersections.front().distance > 0) ? fid_intersections.front().position : endcap_0);
DetectorPosition last_point((fid_intersections.back().distance < max_length) ? fid_intersections.back().position : endcap_1);
path.SetPoints(first_point, last_point);
}
}
Expand Down Expand Up @@ -207,16 +207,16 @@ std::tuple<LI::math::Vector3D, LI::math::Vector3D> SecondaryBoundedVertexDistrib

// Check if fiducial volume is provided
if(fiducial_volume) {
std::vector<LI::geometry::Geometry::Intersection> fid_intersections = fiducial_volume->Intersections(detector_model->ToGeo(DetectorPosition(endcap_0)),detector_model->ToGeo(DetectorDirection(dir)));
std::vector<LI::geometry::Geometry::Intersection> fid_intersections = fiducial_volume->Intersections(endcap_0, dir);
// If the path intersects the fiducial volume, restrict position to that volume
if(!fid_intersections.empty()) {
// make sure the first intersection happens before the maximum generation length
// and the last intersection happens in front of the generation point
bool update_path = (fid_intersections.front().distance < max_length
&& fid_intersections.back().distance > 0);
if(update_path) {
DetectorPosition first_point = (fid_intersections.front().distance > 0) ? detector_model->ToDet(GeometryPosition(fid_intersections.front().position)) : DetectorPosition(endcap_0);
DetectorPosition last_point = (fid_intersections.back().distance < max_length) ? detector_model->ToDet(GeometryPosition(fid_intersections.back().position)) : DetectorPosition(endcap_1);
DetectorPosition first_point((fid_intersections.front().distance > 0) ? fid_intersections.front().position : endcap_0);
DetectorPosition last_point((fid_intersections.back().distance < max_length) ? fid_intersections.back().position : endcap_1);
path.SetPoints(first_point, last_point);
}
}
Expand Down
2 changes: 1 addition & 1 deletion projects/geometry/private/Placement.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace geometry {
} // namespace geometry
} // namespace LI

std::shared_ptr<const Placement> Placement::create() const { return std::shared_ptr<const Placement>( new Placement(*this) ); }
std::shared_ptr<Placement> Placement::create() const { return std::shared_ptr<Placement>( new Placement(*this) ); }

//-------------------------------------//
// getter and setter functions
Expand Down
2 changes: 1 addition & 1 deletion projects/geometry/public/LeptonInjector/geometry/Box.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Box : public Geometry {
}
}

std::shared_ptr<const Geometry> create() const override { return std::shared_ptr<const Geometry>( new Box(*this) ); };
std::shared_ptr<Geometry> create() const override { return std::shared_ptr<Geometry>( new Box(*this) ); };
void swap(Geometry&) override;

virtual ~Box() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Cylinder : public Geometry {
}
}

std::shared_ptr<const Geometry> create() const override { return std::shared_ptr<const Geometry>( new Cylinder(*this) ); };
std::shared_ptr<Geometry> create() const override { return std::shared_ptr<Geometry>( new Cylinder(*this) ); };
void swap(Geometry&) override;

virtual ~Cylinder() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class ExtrPoly : public Geometry {
}

/* Geometry* clone() const override{ return new ExtrPoly(*this); }; */
std::shared_ptr<const Geometry> create() const override{ return std::shared_ptr<const Geometry>( new ExtrPoly(*this) ); }
std::shared_ptr<Geometry> create() const override{ return std::shared_ptr<Geometry>( new ExtrPoly(*this) ); }
void swap(Geometry&) override;

virtual ~ExtrPoly() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ friend cereal::access;
//Geometry(const nlohmann::json&);

/* virtual Geometry* clone() const = 0; // virtual constructor idiom (used for deep copies) */
virtual std::shared_ptr<const Geometry> create() const = 0;
virtual std::shared_ptr<Geometry> create() const = 0;
virtual void swap(Geometry&);

virtual ~Geometry(){};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class TriangularMesh : public Geometry {
}
}

std::shared_ptr<const Geometry> create() const override { return std::shared_ptr<const Geometry>( new TriangularMesh(*this) ); };
std::shared_ptr<Geometry> create() const override { return std::shared_ptr<Geometry>( new TriangularMesh(*this) ); };
void swap(Geometry&) override;

virtual ~TriangularMesh() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Placement
void swap(Placement& placement);
friend std::ostream& operator<<(std::ostream& os, Placement const& placement);

std::shared_ptr<const Placement> create() const;
std::shared_ptr<Placement> create() const;

//-------------------------------------//
// getter and setter functions
Expand Down
2 changes: 1 addition & 1 deletion projects/geometry/public/LeptonInjector/geometry/Sphere.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Sphere : public Geometry {
}

/* Geometry* clone() const override{ return new Sphere(*this); }; */
std::shared_ptr<const Geometry> create() const override{ return std::shared_ptr<const Geometry>( new Sphere(*this) ); }
std::shared_ptr<Geometry> create() const override{ return std::shared_ptr<Geometry>( new Sphere(*this) ); }
void swap(Geometry&) override;

virtual ~Sphere() {}
Expand Down
Loading
Loading