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

Cleanups and improvements to support extrapolation #187

Merged
merged 49 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
dbed7ab
Add extrapolation function
brownd1978 Dec 28, 2023
8ca2e3b
Changes for extension: working
brownd1978 Dec 28, 2023
de7e8ec
Fix config
brownd1978 Dec 28, 2023
18f2fad
Fix state initialization
brownd1978 Dec 29, 2023
1007c52
Simplify NDOF testing
brownd1978 Dec 29, 2023
d70410b
Minor fix
brownd1978 Dec 29, 2023
cd063af
Rename BField effect for greater clarity
brownd1978 Dec 29, 2023
bfd6c33
Cleanup and fix some implementation bugs: working
brownd1978 Dec 30, 2023
dc7c2f9
go back to c__17
brownd1978 Dec 30, 2023
46b22e8
Update buildtest
brownd1978 Jan 1, 2024
714ac7a
Another try
brownd1978 Jan 1, 2024
7f5deee
Refactor SensorTraj; not yet working
brownd1978 Jan 3, 2024
e77a25a
Revert to old setup.
brownd1978 Jan 3, 2024
7dddb27
Fixes
brownd1978 Jan 3, 2024
4d41587
small fix
brownd1978 Jan 4, 2024
64b47fa
Fix time order problem: still some tension
brownd1978 Jan 4, 2024
be9104d
Fix some bugs
brownd1978 Jan 5, 2024
7a75d78
Add protections against failed fits and CA
brownd1978 Jan 5, 2024
6e2d0a5
Extend the iteration range to include the bounding domains
brownd1978 Jan 10, 2024
ce5774c
Fix some latent bugs
brownd1978 Jan 11, 2024
2ca03b1
Fix range after domain extension
brownd1978 Jan 11, 2024
b2e8a00
Extend domains as part of processEnds
brownd1978 Jan 13, 2024
0797f81
Remove unneeded extra cache. Make names more consistent
brownd1978 Jan 14, 2024
8447e8f
Remove redundant time direction argument in material xing.
brownd1978 Jan 14, 2024
49196f6
Fix comment
brownd1978 Jan 14, 2024
b756622
Fix typo
brownd1978 Jan 14, 2024
d8a1c64
Make previous and next domains explicit for DW
brownd1978 Jan 16, 2024
e6e2af9
Fix extrapolation
brownd1978 Jan 19, 2024
b85fea6
Improve intersection and add some options
brownd1978 Jan 20, 2024
8da66c2
Change Domain storage to shared_ptr
brownd1978 Jan 21, 2024
14e651d
Change DW Domain storage to shared_ptr
brownd1978 Jan 21, 2024
00f0926
Add BField payload to Domain
brownd1978 Jan 21, 2024
d52b7cf
Intermediate commit
brownd1978 Jan 22, 2024
6b4bef9
Clarify DW updating
brownd1978 Jan 22, 2024
62a07b5
Fix install
brownd1978 Feb 9, 2024
db76ac1
fix
brownd1978 Feb 9, 2024
3837e3a
Fix conflict
brownd1978 Feb 9, 2024
813a51c
Adjust parameters: still failing
brownd1978 Feb 13, 2024
99fc5b4
Small cleanups. Improve state test
brownd1978 Feb 18, 2024
ab5a3a2
Remove cached mbar value: this MUST be calculated from bnom to insure…
brownd1978 Feb 18, 2024
4050174
Intermediate commit for improvements to DW
brownd1978 Feb 23, 2024
55c1946
Small tweak
brownd1978 Feb 24, 2024
ad9dbcb
Fix dPardB call. Fix dB testing. Add state testing: this is not yet…
brownd1978 Feb 25, 2024
ddaebf7
Clarification and simplification
brownd1978 Feb 26, 2024
ceddeb5
Rename and simplify som variables. Correct implementation of bnom ma…
brownd1978 Feb 26, 2024
c3b7645
Fix LH bnom derivs and update DW
brownd1978 Mar 3, 2024
6557ca2
Use correct Bnom setting in DW append. Move Db testing to BField uni…
brownd1978 Mar 13, 2024
157aefe
Allow synchronizing phi0
brownd1978 Mar 13, 2024
b6e53d9
Turn off gradient bfield testing for now as the MC is broken.
brownd1978 Mar 14, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
matrix:
os: ["ubuntu-latest", "macos-latest"]
python-version: ["3.9"]
root-version: ["6.26.10"]
root-version: ["6.30.2"]
build-type: ["Debug", "Release"]

steps:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ KinKal/UnitTests/Dict.cc
debug/*
*.root
.DS_Store
.vscode
.vscode/*
.*.swp
12 changes: 5 additions & 7 deletions Detector/ElementXing.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "KinKal/General/MomBasis.hh"
#include "KinKal/Detector/MaterialXing.hh"
#include "KinKal/Trajectory/ParticleTrajectory.hh"
#include "KinKal/General/TimeDir.hh"
#include "KinKal/Detector/Hit.hh"
#include "KinKal/Fit/MetaIterConfig.hh"
#include <vector>
Expand All @@ -25,27 +24,26 @@ namespace KinKal {
virtual ~ElementXing() {}
virtual void updateReference(KTRAJPTR const& ktrajptr) = 0; // update the trajectory reference
virtual void updateState(MetaIterConfig const& config,bool first) =0; // update the state according to this meta-config
virtual Parameters parameters(TimeDir tdir) const =0; // parameter change induced by this element crossing WRT the reference
virtual Parameters params() const =0; // parameter change induced by this element crossing WRT the reference parameters going forwards in time
virtual double time() const=0; // time the particle crosses thie element
virtual double transitTime() const=0; // time to cross this element
virtual KTRAJ const& referenceTrajectory() const =0; // trajectory WRT which the xing is defined
virtual std::vector<MaterialXing>const& matXings() const =0; // Effect of each physical material component of this detector element on this trajectory
virtual void print(std::ostream& ost=std::cout,int detail=0) const =0;
// crossings without material are inactive
bool active() const { return matXings().size() > 0; }
// calculate the cumulative material effect from these crossings
void materialEffects(TimeDir tdir, std::array<double,3>& dmom, std::array<double,3>& momvar) const;
// calculate the cumulative material effect from all the materials in this element crossing going forwards in time
void materialEffects(std::array<double,3>& dmom, std::array<double,3>& momvar) const;
// sum radiation fraction
double radiationFraction() const;
static double elossFactor(TimeDir const& tdir) { return tdir == TimeDir::forwards ? 1.0 : -1.0; }
private:
};

template <class KTRAJ> void ElementXing<KTRAJ>::materialEffects(TimeDir tdir, std::array<double,3>& dmom, std::array<double,3>& momvar) const {
template <class KTRAJ> void ElementXing<KTRAJ>::materialEffects(std::array<double,3>& dmom, std::array<double,3>& momvar) const {
// compute the derivative of momentum to energy, at the reference trajectory
double mom = referenceTrajectory().momentum(time());
double mass = referenceTrajectory().mass();
double dmFdE = elossFactor(tdir)*sqrt(mom*mom+mass*mass)/(mom*mom); // dimension of 1/E
double dmFdE = sqrt(mom*mom+mass*mass)/(mom*mom); // dimension of 1/E
// loop over crossings for this detector piece
for(auto const& mxing : matXings()){
// compute FRACTIONAL momentum change and variance on that in the given direction
Expand Down
19 changes: 8 additions & 11 deletions Detector/StrawXing.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "KinKal/Detector/ElementXing.hh"
#include "KinKal/Detector/StrawMaterial.hh"
#include "KinKal/Detector/StrawXingConfig.hh"
#include "KinKal/Trajectory/Line.hh"
#include "KinKal/Trajectory/SensorLine.hh"
#include "KinKal/Trajectory/PiecewiseClosestApproach.hh"

namespace KinKal {
Expand All @@ -16,15 +16,15 @@ namespace KinKal {
using PTRAJ = ParticleTrajectory<KTRAJ>;
using KTRAJPTR = std::shared_ptr<KTRAJ>;
using EXING = ElementXing<KTRAJ>;
using PCA = PiecewiseClosestApproach<KTRAJ,Line>;
using CA = ClosestApproach<KTRAJ,Line>;
using PCA = PiecewiseClosestApproach<KTRAJ,SensorLine>;
using CA = ClosestApproach<KTRAJ,SensorLine>;
// construct from PCA and material
StrawXing(PCA const& pca, StrawMaterial const& smat);
virtual ~StrawXing() {}
// ElementXing interface
void updateReference(KTRAJPTR const& ktrajptr) override;
void updateState(MetaIterConfig const& config,bool first) override;
Parameters parameters(TimeDir tdir) const override;
Parameters params() const override;
double time() const override { return tpca_.particleToca() + toff_; } // offset time WRT TOCA to avoid exact overlapp with the wire hit
double transitTime() const override; // time to cross this element
KTRAJ const& referenceTrajectory() const override { return tpca_.particleTraj(); }
Expand All @@ -36,7 +36,7 @@ namespace KinKal {
auto const& config() const { return sxconfig_; }
auto precision() const { return tpca_.precision(); }
private:
Line axis_; // straw axis, expressed as a timeline
SensorLine axis_; // straw axis, expressed as a timeline
StrawMaterial const& smat_;
CA tpca_; // result of most recent TPOCA
double toff_; // small time offset
Expand Down Expand Up @@ -78,7 +78,7 @@ namespace KinKal {
if(mxings_.size() > 0){
// compute the parameter effect for forwards time
std::array<double,3> dmom = {0.0,0.0,0.0}, momvar = {0.0,0.0,0.0};
this->materialEffects(TimeDir::forwards, dmom, momvar);
this->materialEffects(dmom, momvar);
// get the parameter derivative WRT momentum
DPDV dPdM = referenceTrajectory().dPardM(time());
double mommag = referenceTrajectory().momentum(time());
Expand All @@ -101,11 +101,8 @@ namespace KinKal {
}
}

template <class KTRAJ> Parameters StrawXing<KTRAJ>::parameters(TimeDir tdir) const {
if(tdir == TimeDir::forwards)
return fparams_;
else
return Parameters(-fparams_.parameters(),fparams_.covariance());
template <class KTRAJ> Parameters StrawXing<KTRAJ>::params() const {
return fparams_;
}

template <class KTRAJ> double StrawXing<KTRAJ>::transitTime() const {
Expand Down
2 changes: 1 addition & 1 deletion Examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ROOT_GENERATE_DICTIONARY(ExamplesDict
# headers to include in ROOT dictionary
HitInfo.hh
BFieldInfo.hh
DomainWallInfo.hh
ParticleTrajectoryInfo.hh
MaterialInfo.hh
LINKDEF LinkDef.h
Expand Down
10 changes: 5 additions & 5 deletions Examples/BFieldInfo.hh → Examples/DomainWallInfo.hh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

#ifndef KinKal_BFieldInfo_hh
#define KinKal_BFieldInfo_hh
#ifndef KinKal_DomainWallInfo_hh
#define KinKal_DomainWallInfo_hh
#include <vector>
namespace KinKal {
struct BFieldInfo {
BFieldInfo(){};
struct DomainWallInfo {
DomainWallInfo(){};
Int_t active_;
Float_t time_, range_;
static std::string leafnames() { return std::string("active/i:time/f:range/f"); }
};
typedef std::vector<BFieldInfo> KKBFIV;
typedef std::vector<DomainWallInfo> KKBFIV;
}
#endif
4 changes: 2 additions & 2 deletions Examples/LinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#pragma link C++ class KinKal::HitInfo+;
#pragma link C++ class vector<KinKal::HitInfo>+;
#pragma link C++ class KinKal::BFieldInfo+;
#pragma link C++ class vector<KinKal::BFieldInfo>+;
#pragma link C++ class KinKal::DomainWallInfo+;
#pragma link C++ class vector<KinKal::DomainWallInfo>+;
#pragma link C++ class KinKal::MaterialInfo+;
#pragma link C++ class vector<KinKal::MaterialInfo>+;
#pragma link C++ class KinKal::ParticleTrajectoryInfo+;
Expand Down
25 changes: 12 additions & 13 deletions Examples/ScintHit.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
// simple hit subclass representing a time measurement using scintillator light from a crystal or plastic scintillator
//
#include "KinKal/Detector/ResidualHit.hh"
#include "KinKal/Trajectory/Line.hh"
#include "KinKal/Trajectory/SensorLine.hh"
#include "KinKal/Trajectory/PiecewiseClosestApproach.hh"
#include <stdexcept>
namespace KinKal {

template <class KTRAJ> class ScintHit : public ResidualHit<KTRAJ> {
public:
using PTRAJ = ParticleTrajectory<KTRAJ>;
using PCA = PiecewiseClosestApproach<KTRAJ,Line>;
using CA = ClosestApproach<KTRAJ,Line>;
using PCA = PiecewiseClosestApproach<KTRAJ,SensorLine>;
using CA = ClosestApproach<KTRAJ,SensorLine>;
using RESIDHIT = ResidualHit<KTRAJ>;
using HIT = Hit<KTRAJ>;
using KTRAJPTR = std::shared_ptr<KTRAJ>;
Expand All @@ -35,7 +35,7 @@ namespace KinKal {
double widthVariance() const { return wvar_; }
auto precision() const { return tpca_.precision(); }
private:
Line saxis_; // symmetry axis of this sensor
SensorLine saxis_; // symmetry axis of this sensor
double tvar_; // variance in the time measurement: assumed independent of propagation distance/time
double wvar_; // variance in transverse position of the sensor/measurement in mm. Assumes cylindrical error, could be more general
CA tpca_; // reference time and position of closest approach to the axis
Expand All @@ -54,7 +54,7 @@ namespace KinKal {

template <class KTRAJ> void ScintHit<KTRAJ>::updateReference(KTRAJPTR const& ktrajptr) {
// use previous hint, or initialize from the sensor time
CAHint tphint = tpca_.usable() ? tpca_.hint() : CAHint(saxis_.t0(), saxis_.t0());
CAHint tphint = tpca_.usable() ? tpca_.hint() : CAHint(saxis_.measurementTime(), saxis_.measurementTime());
tpca_ = CA(ktrajptr,saxis_,tphint,precision());
if(!tpca_.usable())throw std::runtime_error("ScintHit TPOCA failure");
}
Expand All @@ -64,22 +64,21 @@ namespace KinKal {
// early in the fit when t0 has very large errors.
// If it is unphysical try to adjust it back using a better hint.
auto ppos = tpca_.particlePoca().Vect();
auto sstart = saxis_.startPosition();
auto send = saxis_.endPosition();
double slen = (send-sstart).R();
auto const& sstart = saxis_.start();
auto const& send = saxis_.end();
// tolerance should come from the config. Should also test relative to the error. FIXME
double tol = slen*1.0;
double sdist = (ppos - saxis_.position3(saxis_.timeAtMidpoint())).Dot(saxis_.direction());
if( (ppos-sstart).Dot(saxis_.direction()) < -tol ||
(ppos-send).Dot(saxis_.direction()) > tol) {
double tol = saxis_.length()*1.0;
double sdist = (ppos - saxis_.middle()).Dot(saxis_.direction());
if( (ppos-sstart).Dot(saxis_.direction()) < -tol || (ppos-send).Dot(saxis_.direction()) > tol) {
// adjust hint to the middle and try agian
double sspeed = tpca_.particleTraj().velocity(tpca_.particleToca()).Dot(saxis_.direction());

auto tphint = tpca_.hint();
tphint.particleToca_ -= sdist/sspeed;
tpca_ = CA(tpca_.particleTrajPtr(),saxis_,tphint,precision());
// should check if this is still unphysical and disable the hit if so FIXME
sdist = (tpca_.particlePoca().Vect() - saxis_.middle()).Dot(saxis_.direction());
}

// residual is just delta-T at CA.
// the variance includes the measurement variance and the tranvserse size (which couples to the relative direction)
// Might want to do more updating (set activity) based on DOCA in future: TODO
Expand Down
10 changes: 5 additions & 5 deletions Examples/SimpleWireHit.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "KinKal/Examples/DOCAWireHitUpdater.hh"
#include "KinKal/Examples/WireHitStructs.hh"
#include "KinKal/Trajectory/ParticleTrajectory.hh"
#include "KinKal/Trajectory/Line.hh"
#include "KinKal/Trajectory/SensorLine.hh"
#include "KinKal/Trajectory/PiecewiseClosestApproach.hh"
#include "KinKal/Trajectory/ClosestApproach.hh"
#include "KinKal/General/BFieldMap.hh"
Expand All @@ -18,8 +18,8 @@ namespace KinKal {
template <class KTRAJ> class SimpleWireHit : public ResidualHit<KTRAJ> {
public:
using HIT = Hit<KTRAJ>;
using PCA = PiecewiseClosestApproach<KTRAJ,Line>;
using CA = ClosestApproach<KTRAJ,Line>;
using PCA = PiecewiseClosestApproach<KTRAJ,SensorLine>;
using CA = ClosestApproach<KTRAJ,SensorLine>;
using KTRAJPTR = std::shared_ptr<KTRAJ>;
enum Dimension { dresid=0, tresid=1}; // residual dimensions

Expand Down Expand Up @@ -49,7 +49,7 @@ namespace KinKal {
private:
BFieldMap const& bfield_; // drift calculation requires the BField for ExB effects
WireHitState whstate_; // current state
Line wire_; // local linear approximation to the wire of this hit, encoding all (local) position and time information.
SensorLine wire_; // local linear approximation to the wire of this hit, encoding all (local) position and time information.
// the start time is the measurement time, the direction is from
// the physical source of the signal (particle) to the measurement recording location (electronics), the direction magnitude
// is the effective signal propagation velocity along the wire, and the time range describes the active wire length
Expand Down Expand Up @@ -129,7 +129,7 @@ namespace KinKal {
return rresid_[ires];
}

template <class KTRAJ> ClosestApproach<KTRAJ,Line> SimpleWireHit<KTRAJ>::unbiasedClosestApproach() const {
template <class KTRAJ> ClosestApproach<KTRAJ,SensorLine> SimpleWireHit<KTRAJ>::unbiasedClosestApproach() const {
// compute the unbiased closest approach; this is brute force, but works
auto const& ca = this->closestApproach();
auto uparams = HIT::unbiasedParameters();
Expand Down
105 changes: 0 additions & 105 deletions Fit/BField.hh

This file was deleted.

Loading
Loading