39 Name(
"inputTrajectoryLabel"),
40 Comment(
"Label of recob::Trajectory or recob::TrackTrajectory Collection to be fit")};
42 Name(
"isTrackTrajectory"),
43 Comment(
"If true, we assume the input collection is made of recob::TrackTrajectory " 44 "objects, otherwise of recob::Trajectory objects.")};
47 Comment(
"Label of sim::MCTrack Collection to be used for initial momentum estimate. Used " 48 "only if momFromMC is set to true.")};
55 Comment(
"Flag used to get initial momentum estimate from " 56 "trkf::TrackMomentumCalculator::GetTrackMomentum().")};
59 Comment(
"Flag used to get initial momentum estimate from inputMCLabel collection.")};
61 Name(
"momentumInGeV"),
62 Comment(
"Fixed momentum estimate value, to be used when momFromCalo, momFromLength and " 63 "momFromMC are all false, or if the estimate is not available.")
67 Comment(
"Default particle id hypothesis in case no valid id is provided either via " 68 "PFParticle or in the ParticleId collection.")};
71 Comment(
"Assume track direction from as the one giving positive " 72 "dot product with vector specified by dirVec.")};
74 Comment(
"Fhicl sequence defining the vector used when " 75 "dirFromVec=true. It must have 3 elements.")};
77 Name(
"alwaysInvertDir"),
78 Comment(
"If true, fit all tracks from end to vertex assuming inverted direction.")};
80 Name(
"produceTrackFitHitInfo"),
81 Comment(
"Option to produce (or not) the detailed TrackFitHitInfo.")};
83 Name(
"produceSpacePoints"),
84 Comment(
"Option to produce (or not) the associated SpacePoints.")};
86 Name(
"keepInputTrajectoryPoints"),
87 Comment(
"Option to keep positions and directions from input trajectory. The fit will " 88 "provide only covariance matrices, chi2, ndof, particle Id and absolute momentum. " 89 "It may also modify the trajectory point flags. In order to avoid inconsistencies, " 90 "it has to be used with the following fitter options all set to false: " 91 "sortHitsByPlane, sortOutputHitsMinLength, skipNegProp.")};
148 isTT =
p_().inputs().isTrackTrajectory();
150 produces<std::vector<recob::Track>>();
151 produces<art::Assns<recob::Track, recob::Hit>>();
152 produces<art::Assns<recob::Track, recob::Hit, recob::TrackHitMeta>>();
153 if (
isTT) { produces<art::Assns<recob::TrackTrajectory, recob::Track>>(); }
155 produces<art::Assns<recob::Trajectory, recob::Track>>();
157 if (
p_().options().produceTrackFitHitInfo()) {
158 produces<std::vector<std::vector<recob::TrackFitHitInfo>>>();
160 if (
p_().options().produceSpacePoints()) {
161 produces<std::vector<recob::SpacePoint>>();
162 produces<art::Assns<recob::Hit, recob::SpacePoint>>();
167 unsigned int nDirs = 0;
168 if (
p_().options().dirFromMC()) nDirs++;
169 if (
p_().options().dirFromVec()) nDirs++;
170 if (
p_().options().alwaysInvertDir()) nDirs++;
173 <<
"Incompatible configuration parameters: only at most one can be set to true among " 174 "dirFromMC, dirFromVec, and alwaysInvertDir." 178 unsigned int nPFroms = 0;
179 if (
p_().
options().pFromLength()) nPFroms++;
183 <<
"Incompatible configuration parameters: only at most one can be set to true among " 184 "pFromLength, and pFromMC." 188 if (
p_().
options().keepInputTrajectoryPoints()) {
189 if (
p_().fitter().sortHitsByPlane() ||
p_().fitter().sortOutputHitsMinLength() ||
190 p_().fitter().skipNegProp()) {
192 <<
"Incompatible configuration parameters: keepInputTrajectoryPoints needs the following " 193 "fitter options all set to false: sortHitsByPlane, sortOutputHitsMinLength, skipNegProp." 203 auto outputTracks = std::make_unique<std::vector<recob::Track>>();
204 auto outputHitsMeta =
205 std::make_unique<art::Assns<recob::Track, recob::Hit, recob::TrackHitMeta>>();
206 auto outputHits = std::make_unique<art::Assns<recob::Track, recob::Hit>>();
207 auto outputHitInfo = std::make_unique<std::vector<std::vector<recob::TrackFitHitInfo>>>();
210 auto outputTTjTAssn = std::make_unique<art::Assns<recob::TrackTrajectory, recob::Track>>();
211 auto outputTjTAssn = std::make_unique<art::Assns<recob::Trajectory, recob::Track>>();
213 auto const tid = e.
getProductID<std::vector<recob::Track>>();
216 auto outputSpacePoints = std::make_unique<std::vector<recob::SpacePoint>>();
217 auto outputHitSpacePointAssn = std::make_unique<art::Assns<recob::Hit, recob::SpacePoint>>();
218 auto const spid = e.
getProductID<std::vector<recob::SpacePoint>>();
227 for (
unsigned int iMC = 0; iMC < simTracks->size(); ++iMC) {
230 if (mctrack.
PdgCode() != 13)
continue;
231 if (mctrack.
Process() !=
"primary")
continue;
233 mcdir = TVector3(mctrack.
Start().
Momentum().X() * 0.001 / pMC,
241 unsigned int nTrajs = 0;
245 const std::vector<recob::TrackTrajectory>* trackTrajectoryVec =
nullptr;
246 const std::vector<recob::Trajectory>* trajectoryVec =
nullptr;
253 <<
"Cannot find recob::TrackTrajectory art::Handle with inputTag " <<
trajectoryInputTag;
254 trackTrajectoryVec = inputTrackTrajectoryH.
product();
255 trackTrajectoryHitsAssn =
258 nTrajs = trackTrajectoryVec->size();
265 trajectoryVec = inputTrajectoryH.
product();
268 nTrajs = trajectoryVec->size();
273 for (
unsigned int iTraj = 0; iTraj < nTrajs; ++iTraj) {
276 (
isTT ? trackTrajectoryVec->at(iTraj) :
278 std::vector<recob::TrajectoryPointFlags>()));
281 std::vector<art::Ptr<recob::Hit>> inHits;
283 for (
auto it = trackTrajectoryHitsAssn->
begin(); it != trackTrajectoryHitsAssn->
end(); ++it) {
284 if (it->first.key() == iTraj)
285 inHits.push_back(it->second);
286 else if (inHits.size() > 0)
291 for (
auto it = trajectoryHitsAssn->
begin(); it != trajectoryHitsAssn->
end(); ++it) {
292 if (it->first.key() == iTraj)
293 inHits.push_back(it->second);
294 else if (inHits.size() > 0)
300 const bool flipDir =
setDirFlip(&inTraj, mcdir);
303 std::vector<art::Ptr<recob::Hit>> outHits;
318 if (!fitok)
continue;
320 if (
p_().
options().keepInputTrajectoryPoints()) {
324 outputTracks->emplace_back(
std::move(outTrack));
327 for (
auto const& trhit : outHits) {
330 outputHitsMeta->addSingle(aptr, trhit, metadata);
331 outputHits->addSingle(aptr, trhit);
332 if (
p_().
options().produceSpacePoints() && outputTracks->back().HasValidPoint(ip)) {
333 auto& tp = outputTracks->back().Trajectory().LocationAtPoint(ip);
334 double fXYZ[3] = {tp.X(), tp.Y(), tp.Z()};
335 double fErrXYZ[6] = {0};
337 outputSpacePoints->emplace_back(
std::move(sp));
339 outputHitSpacePointAssn->addSingle(trhit, apsp);
356 if (
p_().
options().produceSpacePoints()) {
374 std::vector<Point_t> positions(np);
375 std::vector<Vector_t> momenta(np);
376 std::vector<recob::TrajectoryPointFlags> outFlags(np);
378 for (
unsigned int p = 0;
p < np; ++
p) {
381 auto op = flag.fromHit();
384 auto mask = flag.mask();
400 for (
auto h : inHits)
401 outHits.push_back(
h);
409 double result =
p_().options().pval();
411 else if (
p_().options().pFromMC() && pMC > 0.) {
420 int result =
p_().options().pdgId();
426 TVector3& mcdir)
const 429 if (
p_().
options().alwaysInvertDir()) {
return true; }
432 if ((mcdir.X() *
tdir.X() + mcdir.Y() *
tdir.Y() + mcdir.Z() *
tdir.Z()) < 0.) result =
true;
434 else if (
p_().options().dirFromVec()) {
435 std::array<float, 3>
dir =
p_().options().dirVec();
437 if ((dir[0] *
tdir.X() + dir[1] *
tdir.Y() + dir[2] *
tdir.Z()) < 0.) result =
true;
trkf::TrackKalmanFitter kalmanFitter
void restoreInputPoints(const recob::TrackTrajectory &track, const std::vector< art::Ptr< recob::Hit >> &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit >> &outHits) const
double VertexMomentum() const
Fit tracks using Kalman Filter fit+smooth.
void initTrackFitInfos()
initialize the output vector of TrackFitHitInfos
ProductID getProductID(std::string const &instance_name="") const
static constexpr Flag_t NoPoint
The trajectory point is not defined.
T DirectionAtPoint(unsigned int p) const
Direction at point p. Use e.g. as:
EDProducer(fhicl::ParameterSet const &pset)
recob::tracking::SMatrixSym55 SMatrixSym55
ChannelGroupService::Name Name
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
bool fitTrack(detinfo::DetectorPropertiesData const &detProp, const recob::TrackTrajectory &traj, int tkID, const SMatrixSym55 &covVtx, const SMatrixSym55 &covEnd, const std::vector< art::Ptr< recob::Hit >> &hits, const double pval, const int pdgid, const bool flipDirection, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit >> &outHits, trkmkr::OptionalOutputs &optionals) const
Fit track starting from TrackTrajectory.
Class for propagation of a trkf::TrackState to a recob::tracking::Plane.
void produce(art::Event &e) override
art::InputTag simTrackInputTag
std::pair< SMatrixSym55, SMatrixSym55 > Covariances() const
const_iterator begin() const
Vector_t VertexDirection() const
Returns the direction of the trajectory at the first point.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
double Length(size_t startAt=0) const
Returns the approximate length of the trajectory.
T const * product() const
#define DEFINE_ART_MODULE(klass)
trkf::TrackMomentumCalculator tmc
TrackStatePropagator prop
A trajectory in space reconstructed from hits.
T LocationAtPoint(unsigned int p) const
Position at point p. Use e.g. as:
EDProductGetter const * productGetter(ProductID const pid) const
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
double setMomValue(const recob::TrackTrajectory *ptraj, const double pMC, const int pId) const
Class def header for mctrack data container.
const TLorentzVector & Momentum() const
const_iterator end() const
Declaration of signal hit object.
std::vector< recob::TrackFitHitInfo > trackFitHitInfos()
get the output vector of TrackFitHitInfos by releasing and moving
const std::string & Process() const
Provides recob::Track data product.
PointFlags_t const & FlagsAtPoint(size_t i) const
const MCStep & Start() const
bool setDirFlip(const recob::TrackTrajectory *ptraj, TVector3 &mcdir) const
TrackCollectionProxyElement< TrackCollProxy > Track
Proxy to an element of a proxy collection of recob::Track objects.
art::InputTag trajectoryInputTag
KalmanFilterTrajectoryFitter & operator=(KalmanFilterTrajectoryFitter const &)=delete
Struct holding optional TrackMaker outputs.
Set of flags pertaining a point of the track.
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
double GetTrackMomentum(double trkrange, int pdg) const
KalmanFilterTrajectoryFitter(Parameters const &p)
cet::coded_exception< error, detail::translate > exception