Skip to content

Commit 1faa5c8

Browse files
authored
Merge pull request #209 from brownd1978/regrow
Support for regrowing fits from seeds.
2 parents 3c80e4a + 93ea284 commit 1faa5c8

File tree

8 files changed

+215
-149
lines changed

8 files changed

+215
-149
lines changed

Detector/ElementXing.hh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ namespace KinKal {
3333
virtual KTRAJ const& referenceTrajectory() const =0; // trajectory WRT which the xing is defined
3434
virtual std::vector<MaterialXing>const& matXings() const =0; // Effect of each physical material component of this detector element on this trajectory
3535
virtual void print(std::ostream& ost=std::cout,int detail=0) const =0;
36-
// crossings without material are inactive
37-
bool active() const { return matXings().size() > 0; }
36+
virtual bool active() const =0;
3837
// momentum change and variance increase associated with crossing this element forwards in time, in spatial basis
3938
void momentumChange(SVEC3& dmom, SMAT& dmomvar) const;
4039
// parameter change associated with crossing this element forwards in time

Examples/StrawXing.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ namespace KinKal {
5757
KTRAJ const& referenceTrajectory() const override { return tpca_.particleTraj(); }
5858
std::vector<MaterialXing>const& matXings() const override { return mxings_; }
5959
void print(std::ostream& ost=std::cout,int detail=0) const override;
60+
bool active() const override { return mxings_.size() > 0; }
6061
// accessors
6162
auto const& closestApproach() const { return tpca_; }
6263
auto const& strawMaterial() const { return smat_; }

Fit/Domain.hh

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
namespace KinKal {
1212
class Domain : public TimeRange {
1313
public:
14-
Domain(double lowtime, double range, VEC3 const& bnom, double tol) : range_(lowtime,lowtime+range), bnom_(bnom), tol_(tol) {}
15-
Domain(TimeRange const& range, VEC3 const& bnom, double tol) : range_(range), bnom_(bnom), tol_(tol) {}
14+
Domain(double lowtime, double range, VEC3 const& bnom) : range_(lowtime,lowtime+range), bnom_(bnom) {}
15+
Domain(TimeRange const& range, VEC3 const& bnom) : range_(range), bnom_(bnom) {}
1616
// clone op for reinstantiation
1717
Domain(Domain const&);
1818
std::shared_ptr< Domain > clone(CloneContext&) const;
@@ -22,21 +22,17 @@ namespace KinKal {
2222
double begin() const { return range_.begin();}
2323
double end() const { return range_.end();}
2424
double mid() const { return range_.mid();}
25-
double tolerance() const { return tol_; }
2625
auto const& bnom() const { return bnom_; }
2726
void updateBNom( VEC3 const& bnom) { bnom_ = bnom; }; // used in DomainWall updating
2827
private:
2928
TimeRange range_; // range of this domain
3029
VEC3 bnom_; // nominal BField for this domain
31-
double tol_; // tolerance used to create this domain
3230
};
3331

3432
// clone op for reinstantiation
3533
Domain::Domain(Domain const& rhs):
3634
range_(rhs.range()),
37-
bnom_(rhs.bnom()),
38-
tol_(rhs.tolerance()){
39-
/**/
35+
bnom_(rhs.bnom()){
4036
}
4137

4238
std::shared_ptr<Domain> Domain::clone(CloneContext& context) const{

Fit/Status.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace KinKal {
1717
std::string comment_; // further information about the status
1818
bool usable() const { return status_ > unfit && status_ < lowNDOF; }
1919
bool needsFit() const { return status_ == unfit || status_ == unconverged; }
20-
Status(unsigned miter,unsigned iter=0) : miter_(miter), iter_(iter), status_(unfit), chisq_(NParams()){}
20+
Status(unsigned miter,unsigned iter=0,status stat=unfit,const char* comment="") : miter_(miter), iter_(iter), status_(stat), chisq_(NParams()),comment_(comment){}
2121
static std::string statusName(status stat);
2222
};
2323
std::ostream& operator <<(std::ostream& os, Status const& fitstatus );

Fit/Track.hh

Lines changed: 157 additions & 125 deletions
Large diffs are not rendered by default.

General/TimeRange.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace KinKal {
2020
bool inRange(double t) const {return t >= begin() && t < end(); }
2121
bool null() const { return end() == begin(); }
2222
bool overlaps(TimeRange const& other ) const {
23-
return inRange(other.begin()) || inRange(other.end()) || contains(other) || other.contains(*this); }
23+
return inRange(other.begin()) || other.inRange(begin()) || contains(other) || other.contains(*this); }
2424
bool contains(TimeRange const& other) const {
2525
return (begin() <= other.begin() && end() >= other.end()); }
2626
// force time to be in range

Tests/FitTest.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ int FitTest(int argc, char *argv[],KinKal::DVEC const& sigmas) {
464464
}
465465
}
466466
// create and fit the track
467-
KKTRK kktrk(config,*BF,seedtraj,thits,dxings);
467+
KKTRK kktrk(config,*BF,straj,thits,dxings);
468468
if(extend && kktrk.fitStatus().usable())kktrk.extend(exconfig,exthits, exdxings);
469469
if(!printbad)kktrk.print(cout,detail);
470470
TFile fitfile((KTRAJ::trajName() + string("FitTest") + tfname + string(".root")).c_str(),"RECREATE");

Trajectory/PiecewiseTrajectory.hh

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "KinKal/General/MomBasis.hh"
1111
#include "KinKal/General/TimeRange.hh"
1212
#include <deque>
13+
#include <array>
1314
#include <memory>
1415
#include <ostream>
1516
#include <stdexcept>
@@ -20,6 +21,8 @@ namespace KinKal {
2021
public:
2122
using KTRAJPTR = std::shared_ptr<KTRAJ>;
2223
using DKTRAJ = std::deque<KTRAJPTR>;
24+
using DKTRAJITER = DKTRAJ::iterator;
25+
using DKTRAJCITER = DKTRAJ::const_iterator;
2326
// forward calls to the pieces
2427
VEC3 position3(double time) const { return nearestPiece(time).position3(time); }
2528
VEC3 velocity(double time) const { return nearestPiece(time).velocity(time); }
@@ -55,6 +58,8 @@ namespace KinKal {
5558
KTRAJ& back() { return *pieces_.back(); }
5659
KTRAJPTR const& frontPtr() const { return pieces_.front(); }
5760
KTRAJPTR const& backPtr() const { return pieces_.back(); }
61+
void pieceRange(TimeRange const& range, DKTRAJCITER& first, DKTRAJCITER& last ) const;
62+
void pieceRange(TimeRange const& range,DKTRAJITER& first, DKTRAJITER& last );
5863
size_t nearestIndex(double time) const;
5964
DKTRAJ const& pieces() const { return pieces_; }
6065
// test for spatial gaps
@@ -68,13 +73,17 @@ namespace KinKal {
6873
template <class KTRAJ> void PiecewiseTrajectory<KTRAJ>::setRange(TimeRange const& trange, bool trim) {
6974
// trim pieces as necessary
7075
if(trim){
71-
while(pieces_.size() > 1 && trange.begin() > pieces_.front()->range().end() ) pieces_.pop_front();
72-
while(pieces_.size() > 1 && trange.end() < pieces_.back()->range().begin() ) pieces_.pop_back();
76+
auto ipiece = pieces_.begin();
77+
while (ipiece != pieces_.end() && !(trange.overlaps((*ipiece)->range())))++ipiece;
78+
if(ipiece != pieces_.begin())pieces_.erase(pieces_.begin(),--ipiece);
79+
auto jpiece=pieces_.rbegin();
80+
while(jpiece != pieces_.rend() && !(trange.overlaps((*jpiece)->range())))++jpiece;
81+
pieces_.erase(jpiece.base(),pieces_.end());
7382
} else if(trange.begin() > pieces_.front()->range().end() || trange.end() < pieces_.back()->range().begin())
74-
throw std::invalid_argument("Invalid Range");
83+
throw std::invalid_argument("PiecewiseTrajectory::setRange; Invalid Range");
7584
// update piece range
76-
pieces_.front()->setRange(TimeRange(trange.begin(),pieces_.front()->range().end()));
77-
pieces_.back()->setRange(TimeRange(pieces_.back()->range().begin(),trange.end()));
85+
pieces_.front()->range().restrict(trange);
86+
pieces_.back()->range().restrict(trange);
7887
}
7988

8089
template <class KTRAJ> PiecewiseTrajectory<KTRAJ>::PiecewiseTrajectory(KTRAJ const& piece) : pieces_(1,std::make_shared<KTRAJ>(piece))
@@ -89,13 +98,13 @@ namespace KinKal {
8998
prepend(newpiece,allowremove);
9099
break;
91100
default:
92-
throw std::invalid_argument("Invalid direction");
101+
throw std::invalid_argument("PiecewiseTrajectory::add; Invalid direction");
93102
}
94103
}
95104

96105
template <class KTRAJ> void PiecewiseTrajectory<KTRAJ>::prepend(KTRAJ const& newpiece, bool allowremove) {
97106
// new piece can't have null range
98-
if(newpiece.range().null())throw std::invalid_argument("Can't prepend null range traj");
107+
if(newpiece.range().null())throw std::invalid_argument("PiecewiseTrajectory::prepend; Can't prepend null range traj");
99108
if(pieces_.empty()){
100109
pieces_.push_back(std::make_shared<KTRAJ>(newpiece));
101110
} else {
@@ -104,7 +113,7 @@ namespace KinKal {
104113
if(allowremove)
105114
*this = PiecewiseTrajectory(newpiece);
106115
else
107-
throw std::invalid_argument("range overlap");
116+
throw std::invalid_argument("PiecewiseTrajector::prepend; range overlap");
108117
} else {
109118
// find the piece that needs to be modified
110119
size_t ipiece = nearestIndex(newpiece.range().end());
@@ -122,15 +131,15 @@ namespace KinKal {
122131
pieces_.push_front(std::make_shared<KTRAJ>(newpiece));
123132
pieces_.front()->range() = TimeRange(tmin,pieces_.front()->range().end());
124133
} else {
125-
throw std::invalid_argument("range error");
134+
throw std::invalid_argument("PiecewiseTrajectory::prepend; range error");
126135
}
127136
}
128137
}
129138
}
130139

131140
template <class KTRAJ> void PiecewiseTrajectory<KTRAJ>::append(KTRAJ const& newpiece, bool allowremove) {
132141
// new piece can't have null range
133-
if(newpiece.range().null())throw std::invalid_argument("Can't append null range traj");
142+
if(newpiece.range().null())throw std::invalid_argument("PiecewiseTrajectory::append; Can't append null range traj");
134143
if(pieces_.empty()){
135144
pieces_.push_back(std::make_shared<KTRAJ>(newpiece));
136145
} else {
@@ -139,7 +148,7 @@ namespace KinKal {
139148
if(allowremove)
140149
*this = PiecewiseTrajectory(newpiece);
141150
else
142-
throw std::invalid_argument("range overlap");
151+
throw std::invalid_argument("PiecewiseTrajectory::append; range overlap");
143152
} else {
144153
// find the piece that needs to be modified
145154
size_t ipiece = nearestIndex(newpiece.range().begin());
@@ -159,7 +168,7 @@ namespace KinKal {
159168
pieces_.push_back(std::make_shared<KTRAJ>(newpiece));
160169
pieces_.back()->range() = TimeRange(pieces_.back()->range().begin(),tmax);
161170
} else {
162-
throw std::invalid_argument("range error");
171+
throw std::invalid_argument("PiecewiseTrajectory::append; range error");
163172
}
164173
}
165174
}
@@ -253,6 +262,35 @@ namespace KinKal {
253262
return ost;
254263
}
255264

265+
template <class KTRAJ> void PiecewiseTrajectory<KTRAJ>::pieceRange(TimeRange const& range,
266+
std::deque<std::shared_ptr<KTRAJ>>::const_iterator& first,
267+
std::deque<std::shared_ptr<KTRAJ>>::const_iterator& last ) const {
268+
first = last = pieces_.end();
269+
// check for no overlap
270+
if(this->range().overlaps(range)){
271+
// find the first and last pieces which overlap with the range. They can be the same piece.
272+
first = pieces_.cbegin();
273+
while(first != pieces_.cend() && !((*first)->range().overlaps(range))) ++first;
274+
auto rlast = pieces_.crbegin();
275+
while(rlast != pieces_.crend() && !((*rlast)->range().overlaps(range))) ++rlast;
276+
last = (rlast+1).base(); // convert back to forwards-iterator
277+
}
278+
}
279+
280+
template <class KTRAJ> void PiecewiseTrajectory<KTRAJ>::pieceRange(TimeRange const& range,
281+
std::deque<std::shared_ptr<KTRAJ>>::iterator& first,
282+
std::deque<std::shared_ptr<KTRAJ>>::iterator& last) {
283+
first = last = pieces_.end();
284+
// check for no overlap
285+
if(this->range().overlaps(range)){
286+
first = pieces_.begin();
287+
while(first != pieces_.end() && !((*first)->range().overlaps(range))) ++first;
288+
auto rlast = pieces_.rbegin();
289+
while(rlast != pieces_.rend() && !((*rlast)->range().overlaps(range))) ++rlast;
290+
last= (rlast+1).base();
291+
}
292+
}
293+
256294
// clone op for reinstantiation
257295
template<class KTRAJ>
258296
PiecewiseTrajectory<KTRAJ>::PiecewiseTrajectory(PiecewiseTrajectory<KTRAJ> const& rhs){

0 commit comments

Comments
 (0)