Skip to content

Commit

Permalink
Merge pull request #27003 from Dr15Jones/consumesTrackFitters
Browse files Browse the repository at this point in the history
Modernized ES modules in TrackingTools/TrackFitters
  • Loading branch information
cmsbuild committed Jun 4, 2019
2 parents d9313af + 8475148 commit 3daca04
Show file tree
Hide file tree
Showing 24 changed files with 1,061 additions and 1,228 deletions.
140 changes: 73 additions & 67 deletions TrackingTools/TrackFitters/interface/DebugHelpers.h
Expand Up @@ -13,84 +13,90 @@
#include "DataFormats/MuonDetId/interface/MuonSubdetId.h"

namespace {
inline
void dump(TrackingRecHit const & hit, int hitcounter, const std::string& msgCat) {
inline void dump(TrackingRecHit const& hit, int hitcounter, const std::string& msgCat) {
if (hit.isValid()) {
LogTrace(msgCat)<< " ----------------- HIT #" << hitcounter << " (VALID)-----------------------\n"
<< " HIT IS AT R " << hit.globalPosition().perp() << "\n"
<< " HIT IS AT Z " << hit.globalPosition().z() << "\n"
<< " HIT IS AT Phi " << hit.globalPosition().phi() << "\n"
<< " HIT IS AT Loc " << hit.localPosition() << "\n"
<< " WITH LocError " << hit.localPositionError() << "\n"
<< " HIT IS AT Glo " << hit.globalPosition() << "\n"
<< "SURFACE POSITION" << "\n"
<< hit.surface()->position()<<"\n"
<< "SURFACE ROTATION" << "\n"
<< hit.surface()->rotation()
<< "dimension " << hit.dimension();
LogTrace(msgCat) << " ----------------- HIT #" << hitcounter << " (VALID)-----------------------\n"
<< " HIT IS AT R " << hit.globalPosition().perp() << "\n"
<< " HIT IS AT Z " << hit.globalPosition().z() << "\n"
<< " HIT IS AT Phi " << hit.globalPosition().phi() << "\n"
<< " HIT IS AT Loc " << hit.localPosition() << "\n"
<< " WITH LocError " << hit.localPositionError() << "\n"
<< " HIT IS AT Glo " << hit.globalPosition() << "\n"
<< "SURFACE POSITION"
<< "\n"
<< hit.surface()->position() << "\n"
<< "SURFACE ROTATION"
<< "\n"
<< hit.surface()->rotation() << "dimension " << hit.dimension();

DetId hitId = hit.geographicalId();

LogDebug(msgCat) << " hit det=" << hitId.rawId();

if(hitId.det() == DetId::Tracker) {
switch(hitId.subdetId()) {
case StripSubdetector::TIB:
LogDebug(msgCat) << " I am TIB"; break;
case StripSubdetector::TOB:
LogDebug(msgCat) << " I am TOB"; break;
case StripSubdetector::TEC:
LogDebug(msgCat) << " I am TEC"; break;
case StripSubdetector::TID:
LogDebug(msgCat) << " I am TID"; break;
case PixelSubdetector::PixelBarrel:
LogDebug(msgCat) << " I am PixBar"; break;
case PixelSubdetector::PixelEndcap:
LogDebug(msgCat) << " I am PixFwd"; break;
default:
LogDebug(msgCat) << " UNKNOWN TRACKER HIT TYPE ";
}
}
else if(hitId.det() == DetId::Muon) {
if(hitId.subdetId() == MuonSubdetId::DT)
LogDebug(msgCat) << " I am DT " << DTWireId(hitId);
else if (hitId.subdetId() == MuonSubdetId::CSC )
LogDebug(msgCat) << " I am CSC " << CSCDetId(hitId);
else if (hitId.subdetId() == MuonSubdetId::RPC )
LogDebug(msgCat) << " I am RPC " << RPCDetId(hitId);
else if (hitId.subdetId() == MuonSubdetId::GEM )
LogDebug(msgCat) << " I am GEM " << GEMDetId(hitId);
if (hitId.det() == DetId::Tracker) {
switch (hitId.subdetId()) {
case StripSubdetector::TIB:
LogDebug(msgCat) << " I am TIB";
break;
case StripSubdetector::TOB:
LogDebug(msgCat) << " I am TOB";
break;
case StripSubdetector::TEC:
LogDebug(msgCat) << " I am TEC";
break;
case StripSubdetector::TID:
LogDebug(msgCat) << " I am TID";
break;
case PixelSubdetector::PixelBarrel:
LogDebug(msgCat) << " I am PixBar";
break;
case PixelSubdetector::PixelEndcap:
LogDebug(msgCat) << " I am PixFwd";
break;
default:
LogDebug(msgCat) << " UNKNOWN TRACKER HIT TYPE ";
}
} else if (hitId.det() == DetId::Muon) {
if (hitId.subdetId() == MuonSubdetId::DT)
LogDebug(msgCat) << " I am DT " << DTWireId(hitId);
else if (hitId.subdetId() == MuonSubdetId::CSC)
LogDebug(msgCat) << " I am CSC " << CSCDetId(hitId);
else if (hitId.subdetId() == MuonSubdetId::RPC)
LogDebug(msgCat) << " I am RPC " << RPCDetId(hitId);
else if (hitId.subdetId() == MuonSubdetId::GEM)
LogDebug(msgCat) << " I am GEM " << GEMDetId(hitId);

else if (hitId.subdetId() == MuonSubdetId::ME0 )
LogDebug(msgCat) << " I am ME0 " << ME0DetId(hitId);
else
LogDebug(msgCat) << " UNKNOWN MUON HIT TYPE ";
}
else
LogDebug(msgCat) << " UNKNOWN HIT TYPE ";
else if (hitId.subdetId() == MuonSubdetId::ME0)
LogDebug(msgCat) << " I am ME0 " << ME0DetId(hitId);
else
LogDebug(msgCat) << " UNKNOWN MUON HIT TYPE ";
} else
LogDebug(msgCat) << " UNKNOWN HIT TYPE ";

} else {
LogDebug(msgCat)
<< " ----------------- INVALID HIT #" << hitcounter << " -----------------------";
LogDebug(msgCat) << " ----------------- INVALID HIT #" << hitcounter << " -----------------------";
}
}
}
#include <sstream>
inline void dump(TrajectoryStateOnSurface const & tsos, const char * header, const std::string& msgCat) {
std::ostringstream ss; ss<< " weights ";
for (auto const & c : tsos.components()) ss << c.weight() << '/';
ss << "\nmomentums ";
for (auto const & c : tsos.components()) ss << c.globalMomentum().mag() << '/';
ss << "\ndeltap/p ";
for (auto const & c : tsos.components()) ss << std::sqrt(tsos.curvilinearError().matrix()(0,0))/c.globalMomentum().mag() << '/';
LogTrace(msgCat)
<< header << "! size " << tsos.components().size() << ss.str() << "\n"
<<" with local position " << tsos.localPosition() << "\n"
<< tsos;
}
}
inline void dump(TrajectoryStateOnSurface const& tsos, const char* header, const std::string& msgCat) {
std::ostringstream ss;
ss << " weights ";
for (auto const& c : tsos.components())
ss << c.weight() << '/';
ss << "\nmomentums ";
for (auto const& c : tsos.components())
ss << c.globalMomentum().mag() << '/';
ss << "\ndeltap/p ";
for (auto const& c : tsos.components())
ss << std::sqrt(tsos.curvilinearError().matrix()(0, 0)) / c.globalMomentum().mag() << '/';
LogTrace(msgCat) << header << "! size " << tsos.components().size() << ss.str() << "\n"
<< " with local position " << tsos.localPosition() << "\n"
<< tsos;
}
} // namespace
#else
namespace {
inline void dump(TrackingRecHit const &, int, const std::string&) {}
inline void dump(TrajectoryStateOnSurface const &, const char *, const std::string&){}
}
inline void dump(TrackingRecHit const &, int, const std::string &) {}
inline void dump(TrajectoryStateOnSurface const &, const char *, const std::string &) {}
} // namespace
#endif
51 changes: 19 additions & 32 deletions TrackingTools/TrackFitters/interface/KFSplittingFitter.h
Expand Up @@ -12,55 +12,42 @@
#include "TrackingTools/TrackFitters/interface/RecHitSplitter.h"

class KFSplittingFitter final : public TrajectoryFitter {

private:

typedef RecHitSplitter::RecHitContainer RecHitContainer;
typedef RecHitSplitter::RecHitContainer RecHitContainer;

typedef TrajectoryStateOnSurface TSOS;
typedef FreeTrajectoryState FTS;
typedef TrajectoryMeasurement TM;

public:

KFSplittingFitter(const Propagator& aPropagator,
const TrajectoryStateUpdator& aUpdator,
const MeasurementEstimator& aEstimator) :
fitter(aPropagator, aUpdator, aEstimator) {}

const MeasurementEstimator& aEstimator)
: fitter(aPropagator, aUpdator, aEstimator) {}

KFSplittingFitter(const Propagator* aPropagator,
const TrajectoryStateUpdator* aUpdator,
const MeasurementEstimator* aEstimator) :
fitter(aPropagator, aUpdator, aEstimator) {}
const TrajectoryStateUpdator* aUpdator,
const MeasurementEstimator* aEstimator)
: fitter(aPropagator, aUpdator, aEstimator) {}

std::unique_ptr<TrajectoryFitter> clone() const override {
return std::unique_ptr<TrajectoryFitter>(
new KFSplittingFitter(fitter.propagator(),
fitter.updator(),
fitter.estimator()));
std::unique_ptr<TrajectoryFitter> clone() const override {
return std::unique_ptr<TrajectoryFitter>(
new KFSplittingFitter(fitter.propagator(), fitter.updator(), fitter.estimator()));
}

Trajectory fitOne(const Trajectory& aTraj,
fitType type) const override;
Trajectory fitOne(const Trajectory& aTraj, fitType type) const override;
Trajectory fitOne(const TrajectorySeed& aSeed, const RecHitContainer& hits, fitType type) const override;
Trajectory fitOne(const TrajectorySeed& aSeed,
const RecHitContainer& hits,
fitType type) const override;
Trajectory fitOne(const TrajectorySeed& aSeed,
const RecHitContainer& hits,
const TSOS& firstPredTsos,
fitType type) const override;
const RecHitContainer& hits,
const TSOS& firstPredTsos,
fitType type) const override;

void setHitCloner(TkCloner const * hc) override{
fitter.setHitCloner(hc);
}

private :
void setHitCloner(TkCloner const* hc) override { fitter.setHitCloner(hc); }

void sorter(const RecHitContainer& hits, PropagationDirection dir, RecHitContainer & result) const;

KFTrajectoryFitter fitter;
private:
void sorter(const RecHitContainer& hits, PropagationDirection dir, RecHitContainer& result) const;

KFTrajectoryFitter fitter;
};

#endif //CD_KFSplittingFitter_H_
#endif //CD_KFSplittingFitter_H_
114 changes: 51 additions & 63 deletions TrackingTools/TrackFitters/interface/KFTrajectoryFitter.h
Expand Up @@ -19,103 +19,91 @@

#include <memory>

class KFTrajectoryFitter final: public TrajectoryFitter {

class KFTrajectoryFitter final : public TrajectoryFitter {
private:

typedef TrajectoryStateOnSurface TSOS;
typedef FreeTrajectoryState FTS;
typedef TrajectoryMeasurement TM;

public:


// backward compatible (too many places it uses as such...)
KFTrajectoryFitter(const Propagator& aPropagator,
const TrajectoryStateUpdator& aUpdator,
const MeasurementEstimator& aEstimator,
int minHits = 3,
const DetLayerGeometry* detLayerGeometry=nullptr,
TkCloner const * hc=nullptr) :
thePropagator(aPropagator.clone()),
theUpdator(aUpdator.clone()),
theEstimator(aEstimator.clone()),
theHitCloner(hc),
theGeometry(detLayerGeometry),
minHits_(minHits),
owner(true){
if(!theGeometry) theGeometry = &dummyGeometry;
const TrajectoryStateUpdator& aUpdator,
const MeasurementEstimator& aEstimator,
int minHits = 3,
const DetLayerGeometry* detLayerGeometry = nullptr,
TkCloner const* hc = nullptr)
: thePropagator(aPropagator.clone()),
theUpdator(aUpdator.clone()),
theEstimator(aEstimator.clone()),
theHitCloner(hc),
theGeometry(detLayerGeometry),
minHits_(minHits),
owner(true) {
if (!theGeometry)
theGeometry = &dummyGeometry;
// FIXME. Why this first constructor is needed? who is using it? Can it be removed?
// it is uses in many many places
}

}

KFTrajectoryFitter(const Propagator* aPropagator,
const TrajectoryStateUpdator* aUpdator,
const MeasurementEstimator* aEstimator,
int minHits = 3,
const DetLayerGeometry* detLayerGeometry=nullptr,
TkCloner const * hc=nullptr) :
thePropagator(aPropagator),
theUpdator(aUpdator),
theEstimator(aEstimator),
theHitCloner(hc),
theGeometry(detLayerGeometry),
minHits_(minHits),
owner(false){
if(!theGeometry) theGeometry = &dummyGeometry;
}
const TrajectoryStateUpdator* aUpdator,
const MeasurementEstimator* aEstimator,
int minHits = 3,
const DetLayerGeometry* detLayerGeometry = nullptr,
TkCloner const* hc = nullptr)
: thePropagator(aPropagator),
theUpdator(aUpdator),
theEstimator(aEstimator),
theHitCloner(hc),
theGeometry(detLayerGeometry),
minHits_(minHits),
owner(false) {
if (!theGeometry)
theGeometry = &dummyGeometry;
}

~KFTrajectoryFitter() override{
~KFTrajectoryFitter() override {
if (owner) {
delete thePropagator;
delete theUpdator;
delete theEstimator;
}
}

Trajectory fitOne(const Trajectory& aTraj,fitType) const override;
Trajectory fitOne(const TrajectorySeed& aSeed,
const RecHitContainer& hits,fitType) const override;
Trajectory fitOne(const Trajectory& aTraj, fitType) const override;
Trajectory fitOne(const TrajectorySeed& aSeed, const RecHitContainer& hits, fitType) const override;

Trajectory fitOne(const TrajectorySeed& aSeed,
const RecHitContainer& hits,
const TSOS& firstPredTsos,fitType) const override;

const Propagator* propagator() const {return thePropagator;}
const TrajectoryStateUpdator* updator() const {return theUpdator;}
const MeasurementEstimator* estimator() const {return theEstimator;}

std::unique_ptr<TrajectoryFitter> clone() const override
{
return owner ?
std::unique_ptr<TrajectoryFitter>(new KFTrajectoryFitter(*thePropagator,
*theUpdator,
*theEstimator,
minHits_,theGeometry,theHitCloner)) :
std::unique_ptr<TrajectoryFitter>(new KFTrajectoryFitter(thePropagator,
theUpdator,
theEstimator,
minHits_,
theGeometry,theHitCloner));
const RecHitContainer& hits,
const TSOS& firstPredTsos,
fitType) const override;

const Propagator* propagator() const { return thePropagator; }
const TrajectoryStateUpdator* updator() const { return theUpdator; }
const MeasurementEstimator* estimator() const { return theEstimator; }

std::unique_ptr<TrajectoryFitter> clone() const override {
return owner ? std::unique_ptr<TrajectoryFitter>(new KFTrajectoryFitter(
*thePropagator, *theUpdator, *theEstimator, minHits_, theGeometry, theHitCloner))
: std::unique_ptr<TrajectoryFitter>(new KFTrajectoryFitter(
thePropagator, theUpdator, theEstimator, minHits_, theGeometry, theHitCloner));
}

// FIXME a prototype: final inplementaiton may differ
void setHitCloner(TkCloner const * hc) override { theHitCloner = hc;}

// FIXME a prototype: final inplementaiton may differ
void setHitCloner(TkCloner const* hc) override { theHitCloner = hc; }

private:
KFTrajectoryFitter(KFTrajectoryFitter const&) = delete;


static const DetLayerGeometry dummyGeometry;
const Propagator* thePropagator;
const TrajectoryStateUpdator* theUpdator;
const MeasurementEstimator* theEstimator;
TkCloner const * theHitCloner=nullptr;
TkCloner const* theHitCloner = nullptr;
const DetLayerGeometry* theGeometry;
int minHits_;
bool owner;
};

#endif //CD_KFTrajectoryFitter_H_
#endif //CD_KFTrajectoryFitter_H_

0 comments on commit 3daca04

Please sign in to comment.