Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
trkf::KalmanFilterFinalTrackFitter Class Reference
Inheritance diagram for trkf::KalmanFilterFinalTrackFitter:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Classes

struct  Config
 
struct  Inputs
 
struct  Options
 

Public Types

using Parameters = art::EDProducer::Table< Config >
 
- Public Types inherited from art::EDProducer
using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
- Public Types inherited from art::detail::Producer
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 
- Public Types inherited from art::Modifier
template<typename UserConfig , typename UserKeysToIgnore = void>
using Table = ProducerTable< UserConfig, detail::ModuleConfig, UserKeysToIgnore >
 

Public Member Functions

 KalmanFilterFinalTrackFitter (Parameters const &p)
 
 KalmanFilterFinalTrackFitter (KalmanFilterFinalTrackFitter const &)=delete
 
 KalmanFilterFinalTrackFitter (KalmanFilterFinalTrackFitter &&)=delete
 
KalmanFilterFinalTrackFitteroperator= (KalmanFilterFinalTrackFitter const &)=delete
 
KalmanFilterFinalTrackFitteroperator= (KalmanFilterFinalTrackFitter &&)=delete
 
- Public Member Functions inherited from art::EDProducer
 EDProducer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDProducer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Producer
virtual ~Producer () noexcept
 
 Producer (fhicl::ParameterSet const &)
 
 Producer (Producer const &)=delete
 
 Producer (Producer &&)=delete
 
Produceroperator= (Producer const &)=delete
 
Produceroperator= (Producer &&)=delete
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Modifier
 ~Modifier () noexcept
 
 Modifier ()
 
 Modifier (Modifier const &)=delete
 
 Modifier (Modifier &&)=delete
 
Modifieroperator= (Modifier const &)=delete
 
Modifieroperator= (Modifier &&)=delete
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Member Functions

void produce (art::Event &e) override
 
double setMomValue (art::Ptr< recob::Track > ptrack, const std::unique_ptr< art::FindManyP< anab::Calorimetry >> &trackCalo, const double pMC, const int pId) const
 
int setPId (const unsigned int iTrack, const std::unique_ptr< art::FindManyP< anab::ParticleID >> &trackId, const int pfPid=0) const
 
bool setDirFlip (const recob::Track &track, TVector3 &mcdir, const std::vector< art::Ptr< recob::Vertex >> *vertices=0) const
 
void restoreInputPoints (const recob::Trajectory &track, const std::vector< art::Ptr< recob::Hit >> &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit >> &outHits) const
 

Private Attributes

Parameters p_
 
TrackStatePropagator prop
 
trkf::TrackKalmanFitter kalmanFitter
 
trkf::TrackMomentumCalculator tmc {}
 
bool inputFromPF
 
art::InputTag pfParticleInputTag
 
art::InputTag trackInputTag
 
art::InputTag showerInputTag
 
art::InputTag caloInputTag
 
art::InputTag pidInputTag
 
art::InputTag simTrackInputTag
 
std::unique_ptr< art::FindManyP< anab::Calorimetry > > trackCalo
 
std::unique_ptr< art::FindManyP< anab::ParticleID > > trackId
 
std::unique_ptr< art::FindManyP< recob::Track > > assocTracks
 
std::unique_ptr< art::FindManyP< recob::Shower > > assocShowers
 
std::unique_ptr< art::FindManyP< recob::Vertex > > assocVertices
 

Additional Inherited Members

- Static Public Member Functions inherited from art::EDProducer
static void commitEvent (EventPrincipal &ep, Event &e)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 41 of file KalmanFilterFinalTrackFitter_module.cc.

Member Typedef Documentation

Definition at line 142 of file KalmanFilterFinalTrackFitter_module.cc.

Constructor & Destructor Documentation

KalmanFilterFinalTrackFitter::KalmanFilterFinalTrackFitter ( Parameters const &  p)
explicit

Definition at line 192 of file KalmanFilterFinalTrackFitter_module.cc.

194  : EDProducer{p}
195  , p_(p)
196  , prop{p_().propagator}
197  , kalmanFitter{&prop, p_().fitter}
198  , inputFromPF{p_().options().trackFromPF() || p_().options().showerFromPF()}
199 {
200 
201  if (inputFromPF) {
202  pfParticleInputTag = art::InputTag(p_().inputs().inputPFParticleLabel());
203  if (p_().options().showerFromPF())
204  showerInputTag = art::InputTag(p_().inputs().inputShowersLabel());
205  }
206  else {
207  trackInputTag = art::InputTag(p_().inputs().inputTracksLabel());
208  if (p_().options().idFromCollection())
209  pidInputTag = art::InputTag(p_().inputs().inputPidLabel());
210  }
211  if (p_().options().pFromCalo()) caloInputTag = art::InputTag(p_().inputs().inputCaloLabel());
212  if (p_().options().pFromMC() || p_().options().dirFromMC())
213  simTrackInputTag = art::InputTag(p_().inputs().inputMCLabel());
214 
215  produces<std::vector<recob::Track>>();
216  produces<art::Assns<recob::Track, recob::Hit, recob::TrackHitMeta>>();
217  produces<art::Assns<recob::Track, recob::Hit>>();
218  if (inputFromPF) { produces<art::Assns<recob::PFParticle, recob::Track>>(); }
219  if (p_().options().produceTrackFitHitInfo()) {
220  produces<std::vector<std::vector<recob::TrackFitHitInfo>>>();
221  }
222  if (p_().options().produceSpacePoints()) {
223  produces<std::vector<recob::SpacePoint>>();
224  produces<art::Assns<recob::Hit, recob::SpacePoint>>();
225  }
226 
227  //throw expections to avoid possible silent failures due to incompatible configuration options
228  if (p_().options().trackFromPF() == 0 && p_().options().idFromPF())
229  throw cet::exception("KalmanFilterFinalTrackFitter")
230  << "Incompatible configuration parameters: cannot use idFromPF=true with trackFromPF=false."
231  << "\n";
232  if (p_().options().trackFromPF() == 0 && p_().options().dirFromVtxPF())
233  throw cet::exception("KalmanFilterFinalTrackFitter")
234  << "Incompatible configuration parameters: cannot use dirFromVtxPF=true with "
235  "trackFromPF=false."
236  << "\n";
237 
238  unsigned int nIds = 0;
239  if (p_().options().idFromPF()) nIds++;
240  if (p_().options().idFromCollection()) nIds++;
241  if (nIds > 1) {
242  throw cet::exception("KalmanFilterFinalTrackFitter")
243  << "Incompatible configuration parameters: only at most one can be set to true among "
244  "idFromPF and idFromCollection."
245  << "\n";
246  }
247 
248  unsigned int nDirs = 0;
249  if (p_().options().dirFromVtxPF()) nDirs++;
250  if (p_().options().dirFromMC()) nDirs++;
251  if (p_().options().dirFromVec()) nDirs++;
252  if (p_().options().alwaysInvertDir()) nDirs++;
253  if (nDirs > 1) {
254  throw cet::exception("KalmanFilterFinalTrackFitter")
255  << "Incompatible configuration parameters: only at most one can be set to true among "
256  "dirFromVtxPF, dirFromMC, dirFromVec, and alwaysInvertDir."
257  << "\n";
258  }
259 
260  unsigned int nPFroms = 0;
261  if (p_().options().pFromCalo()) nPFroms++;
262  if (p_().options().pFromMSChi2()) nPFroms++;
263  if (p_().options().pFromLength()) nPFroms++;
264  if (p_().options().pFromMC()) nPFroms++;
265  if (nPFroms > 1) {
266  throw cet::exception("KalmanFilterFinalTrackFitter")
267  << "Incompatible configuration parameters: only at most one can be set to true among "
268  "pFromCalo, pFromMSChi2, pFromLength, and pFromMC."
269  << "\n";
270  }
271 
272  if (p_().options().keepInputTrajectoryPoints()) {
273  if (p_().fitter().sortHitsByPlane() || p_().fitter().sortOutputHitsMinLength() ||
274  p_().fitter().skipNegProp()) {
275  throw cet::exception("KalmanFilterTrajectoryFitter")
276  << "Incompatible configuration parameters: keepInputTrajectoryPoints needs the following "
277  "fitter options all set to false: sortHitsByPlane, sortOutputHitsMinLength, skipNegProp."
278  << "\n";
279  }
280  }
281 
282  if (p_().options().showerFromPF()) {
283  if (nPFroms > 0 || nIds > 0 || nDirs > 0) {
284  throw cet::exception("KalmanFilterTrajectoryFitter")
285  << "Incompatible configuration parameters: showerFromPF currently does not support "
286  "optional momentum values, particle hypotheses and directions."
287  << "\n";
288  }
289  }
290 }
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
p
Definition: test.py:223
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
trkf::KalmanFilterFinalTrackFitter::KalmanFilterFinalTrackFitter ( KalmanFilterFinalTrackFitter const &  )
delete
trkf::KalmanFilterFinalTrackFitter::KalmanFilterFinalTrackFitter ( KalmanFilterFinalTrackFitter &&  )
delete

Member Function Documentation

KalmanFilterFinalTrackFitter& trkf::KalmanFilterFinalTrackFitter::operator= ( KalmanFilterFinalTrackFitter const &  )
delete
KalmanFilterFinalTrackFitter& trkf::KalmanFilterFinalTrackFitter::operator= ( KalmanFilterFinalTrackFitter &&  )
delete
void KalmanFilterFinalTrackFitter::produce ( art::Event e)
overrideprivatevirtual

Implements art::EDProducer.

Definition at line 293 of file KalmanFilterFinalTrackFitter_module.cc.

294 {
295  auto outputTracks = std::make_unique<std::vector<recob::Track>>();
296  auto outputHitsMeta =
297  std::make_unique<art::Assns<recob::Track, recob::Hit, recob::TrackHitMeta>>();
298  auto outputHits = std::make_unique<art::Assns<recob::Track, recob::Hit>>();
299  auto outputHitInfo = std::make_unique<std::vector<std::vector<recob::TrackFitHitInfo>>>();
300 
301  auto const tid = e.getProductID<std::vector<recob::Track>>();
302  auto const tidgetter = e.productGetter(tid);
303 
304  auto outputSpacePoints = std::make_unique<std::vector<recob::SpacePoint>>();
305  auto outputHitSpacePointAssn = std::make_unique<art::Assns<recob::Hit, recob::SpacePoint>>();
306  auto const spid = e.getProductID<std::vector<recob::SpacePoint>>();
307  auto const spidgetter = e.productGetter(spid);
308 
309  //FIXME, eventually remove this (ok only for single particle MC)
310  double pMC = -1.;
311  TVector3 mcdir;
312  if (p_().options().pFromMC() || p_().options().dirFromMC()) {
314  e.getValidHandle<std::vector<sim::MCTrack>>(simTrackInputTag);
315  for (unsigned int iMC = 0; iMC < simTracks->size(); ++iMC) {
316  const sim::MCTrack& mctrack = simTracks->at(iMC);
317  //fiducial cuts on MC tracks
318  if (mctrack.PdgCode() != 13) continue;
319  if (mctrack.Process() != "primary") continue;
320  pMC = mctrack.Start().Momentum().P() * 0.001;
321  mcdir = TVector3(mctrack.Start().Momentum().X() * 0.001 / pMC,
322  mctrack.Start().Momentum().Y() * 0.001 / pMC,
323  mctrack.Start().Momentum().Z() * 0.001 / pMC);
324  break;
325  }
326  }
327 
328  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(e);
329 
330  if (inputFromPF) {
331 
332  auto outputPFAssn = std::make_unique<art::Assns<recob::PFParticle, recob::Track>>();
333 
334  auto inputPFParticle = e.getValidHandle<std::vector<recob::PFParticle>>(pfParticleInputTag);
335  if (p_().options().trackFromPF())
336  assocTracks =
337  std::make_unique<art::FindManyP<recob::Track>>(inputPFParticle, e, pfParticleInputTag);
338  if (p_().options().showerFromPF())
339  assocShowers =
340  std::make_unique<art::FindManyP<recob::Shower>>(inputPFParticle, e, showerInputTag);
341  assocVertices =
342  std::make_unique<art::FindManyP<recob::Vertex>>(inputPFParticle, e, pfParticleInputTag);
343 
344  for (unsigned int iPF = 0; iPF < inputPFParticle->size(); ++iPF) {
345 
346  if (p_().options().trackFromPF()) {
347  const std::vector<art::Ptr<recob::Track>>& tracks = assocTracks->at(iPF);
348  auto const& tkHitsAssn =
350  const std::vector<art::Ptr<recob::Vertex>>& vertices = assocVertices->at(iPF);
351 
352  if (p_().options().pFromCalo()) {
353  trackCalo = std::make_unique<art::FindManyP<anab::Calorimetry>>(tracks, e, caloInputTag);
354  }
355 
356  for (unsigned int iTrack = 0; iTrack < tracks.size(); ++iTrack) {
357 
358  const recob::Track& track = *tracks[iTrack];
359  art::Ptr<recob::Track> ptrack = tracks[iTrack];
360  const int pId = setPId(iTrack, trackId, inputPFParticle->at(iPF).PdgCode());
361  const double mom = setMomValue(ptrack, trackCalo, pMC, pId);
362  const bool flipDir = setDirFlip(track, mcdir, &vertices);
363 
364  //this is not computationally optimal, but at least preserves the order unlike FindManyP
365  std::vector<art::Ptr<recob::Hit>> inHits;
366  for (auto it = tkHitsAssn.begin(); it != tkHitsAssn.end(); ++it) {
367  if (it->first == ptrack)
368  inHits.push_back(it->second);
369  else if (inHits.size() > 0)
370  break;
371  }
372 
373  recob::Track outTrack;
374  std::vector<art::Ptr<recob::Hit>> outHits;
375  trkmkr::OptionalOutputs optionals;
376  if (p_().options().produceTrackFitHitInfo()) optionals.initTrackFitInfos();
377  bool fitok = kalmanFitter.fitTrack(detProp,
378  track.Trajectory(),
379  track.ID(),
380  track.VertexCovarianceLocal5D(),
381  track.EndCovarianceLocal5D(),
382  inHits,
383  mom,
384  pId,
385  flipDir,
386  outTrack,
387  outHits,
388  optionals);
389  if (!fitok) continue;
390 
391  if (p_().options().keepInputTrajectoryPoints()) {
392  restoreInputPoints(track.Trajectory().Trajectory(), inHits, outTrack, outHits);
393  }
394 
395  outputTracks->emplace_back(std::move(outTrack));
396  art::Ptr<recob::Track> aptr(tid, outputTracks->size() - 1, tidgetter);
397  unsigned int ip = 0;
398  for (auto const& trhit : outHits) {
399  //the fitter produces collections with 1-1 match between hits and point
401  outputHitsMeta->addSingle(aptr, trhit, metadata);
402  outputHits->addSingle(aptr, trhit);
403  ip++;
404  }
405  outputPFAssn->addSingle(art::Ptr<recob::PFParticle>(inputPFParticle, iPF), aptr);
406  outputHitInfo->emplace_back(optionals.trackFitHitInfos());
407  }
408  }
409 
410  if (p_().options().showerFromPF()) {
411  art::Ptr<recob::PFParticle> pPF(inputPFParticle, iPF);
412  const std::vector<art::Ptr<recob::Shower>>& showers = assocShowers->at(iPF);
413  if (showers.size() == 0) continue;
414  auto const& pfClustersAssn =
416  auto const& clHitsAssn =
418  std::vector<art::Ptr<recob::Hit>> inHits;
419  for (auto itpf = pfClustersAssn.begin(); itpf != pfClustersAssn.end(); ++itpf) {
420  if (itpf->first == pPF) {
421  art::Ptr<recob::Cluster> clust = itpf->second;
422  for (auto it = clHitsAssn.begin(); it != clHitsAssn.end(); ++it) {
423  if (it->first == clust) inHits.push_back(it->second);
424  }
425  }
426  else if (inHits.size() > 0)
427  break;
428  }
429  for (unsigned int iShower = 0; iShower < showers.size(); ++iShower) {
430  const recob::Shower& shower = *showers[iShower];
431  recob::Track outTrack;
432  std::vector<art::Ptr<recob::Hit>> outHits;
433  trkmkr::OptionalOutputs optionals;
434  if (p_().options().produceTrackFitHitInfo()) optionals.initTrackFitInfos();
435  Point_t pos(shower.ShowerStart().X(), shower.ShowerStart().Y(), shower.ShowerStart().Z());
436  Vector_t dir(shower.Direction().X(), shower.Direction().Y(), shower.Direction().Z());
437  auto cov = SMatrixSym55();
438  auto pid = p_().options().pdgId();
439  auto mom = p_().options().pval();
440  bool fitok = kalmanFitter.fitTrack(detProp,
441  pos,
442  dir,
443  cov,
444  inHits,
445  std::vector<recob::TrajectoryPointFlags>(),
446  shower.ID(),
447  mom,
448  pid,
449  outTrack,
450  outHits,
451  optionals);
452  if (!fitok) continue;
453 
454  outputTracks->emplace_back(std::move(outTrack));
455  art::Ptr<recob::Track> aptr(tid, outputTracks->size() - 1, tidgetter);
456  unsigned int ip = 0;
457  for (auto const& trhit : outHits) {
458  // the fitter produces collections with 1-1 match between hits and point
460  outputHitsMeta->addSingle(aptr, trhit, metadata);
461  outputHits->addSingle(aptr, trhit);
462  if (p_().options().produceSpacePoints() && outputTracks->back().HasValidPoint(ip)) {
463  auto& tp = outputTracks->back().Trajectory().LocationAtPoint(ip);
464  double fXYZ[3] = {tp.X(), tp.Y(), tp.Z()};
465  double fErrXYZ[6] = {0};
466  recob::SpacePoint sp(fXYZ, fErrXYZ, -1.);
467  outputSpacePoints->emplace_back(std::move(sp));
468  art::Ptr<recob::SpacePoint> apsp(spid, outputSpacePoints->size() - 1, spidgetter);
469  outputHitSpacePointAssn->addSingle(trhit, apsp);
470  }
471  ip++;
472  }
473  outputPFAssn->addSingle(art::Ptr<recob::PFParticle>(inputPFParticle, iPF), aptr);
474  outputHitInfo->emplace_back(optionals.trackFitHitInfos());
475  }
476  }
477  }
478  e.put(std::move(outputTracks));
479  e.put(std::move(outputHitsMeta));
480  e.put(std::move(outputHits));
481  e.put(std::move(outputPFAssn));
482  if (p_().options().produceTrackFitHitInfo()) { e.put(std::move(outputHitInfo)); }
483  if (p_().options().produceSpacePoints()) {
484  e.put(std::move(outputSpacePoints));
485  e.put(std::move(outputHitSpacePointAssn));
486  }
487  }
488  else {
489 
491  e.getValidHandle<std::vector<recob::Track>>(trackInputTag);
492  auto const& tkHitsAssn = *e.getValidHandle<art::Assns<recob::Track, recob::Hit>>(trackInputTag);
493 
494  if (p_().options().pFromCalo()) {
495  trackCalo = std::make_unique<art::FindManyP<anab::Calorimetry>>(inputTracks, e, caloInputTag);
496  }
497 
498  if (p_().options().idFromCollection()) {
499  trackId = std::make_unique<art::FindManyP<anab::ParticleID>>(inputTracks, e, pidInputTag);
500  }
501 
502  for (unsigned int iTrack = 0; iTrack < inputTracks->size(); ++iTrack) {
503 
504  const recob::Track& track = inputTracks->at(iTrack);
505  art::Ptr<recob::Track> ptrack(inputTracks, iTrack);
506  const int pId = setPId(iTrack, trackId);
507  const double mom = setMomValue(ptrack, trackCalo, pMC, pId);
508  const bool flipDir = setDirFlip(track, mcdir);
509 
510  //this is not computationally optimal, but at least preserves the order unlike FindManyP
511  std::vector<art::Ptr<recob::Hit>> inHits;
512  for (auto it = tkHitsAssn.begin(); it != tkHitsAssn.end(); ++it) {
513  if (it->first == ptrack)
514  inHits.push_back(it->second);
515  else if (inHits.size() > 0)
516  break;
517  }
518 
519  recob::Track outTrack;
520  std::vector<art::Ptr<recob::Hit>> outHits;
521  trkmkr::OptionalOutputs optionals;
522  if (p_().options().produceTrackFitHitInfo()) optionals.initTrackFitInfos();
523  bool fitok = kalmanFitter.fitTrack(detProp,
524  track.Trajectory(),
525  track.ID(),
526  track.VertexCovarianceLocal5D(),
527  track.EndCovarianceLocal5D(),
528  inHits,
529  mom,
530  pId,
531  flipDir,
532  outTrack,
533  outHits,
534  optionals);
535  if (!fitok) continue;
536 
537  if (p_().options().keepInputTrajectoryPoints()) {
538  restoreInputPoints(track.Trajectory().Trajectory(), inHits, outTrack, outHits);
539  }
540 
541  outputTracks->emplace_back(std::move(outTrack));
542  art::Ptr<recob::Track> aptr(tid, outputTracks->size() - 1, tidgetter);
543  unsigned int ip = 0;
544  for (auto const& trhit : outHits) {
545  //the fitter produces collections with 1-1 match between hits and point
547  outputHitsMeta->addSingle(aptr, trhit, metadata);
548  outputHits->addSingle(aptr, trhit);
549  if (p_().options().produceSpacePoints() && outputTracks->back().HasValidPoint(ip)) {
550  auto& tp = outputTracks->back().Trajectory().LocationAtPoint(ip);
551  double fXYZ[3] = {tp.X(), tp.Y(), tp.Z()};
552  double fErrXYZ[6] = {0};
553  recob::SpacePoint sp(fXYZ, fErrXYZ, -1.);
554  outputSpacePoints->emplace_back(std::move(sp));
555  art::Ptr<recob::SpacePoint> apsp(spid, outputSpacePoints->size() - 1, spidgetter);
556  outputHitSpacePointAssn->addSingle(trhit, apsp);
557  }
558  ip++;
559  }
560  outputHitInfo->emplace_back(optionals.trackFitHitInfos());
561  }
562  e.put(std::move(outputTracks));
563  e.put(std::move(outputHitsMeta));
564  e.put(std::move(outputHits));
565  if (p_().options().produceTrackFitHitInfo()) { e.put(std::move(outputHitInfo)); }
566  if (p_().options().produceSpacePoints()) {
567  e.put(std::move(outputSpacePoints));
568  e.put(std::move(outputHitSpacePointAssn));
569  }
570  }
571 }
const TVector3 & ShowerStart() const
Definition: Shower.h:192
Trajectory_t const & Trajectory() const
Returns the plain trajectory of this object.
void initTrackFitInfos()
initialize the output vector of TrackFitHitInfos
Definition: TrackMaker.h:150
ProductID getProductID(std::string const &instance_name="") const
Definition: DataViewImpl.h:338
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
Definition: Track.h:98
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >> Point_t
recob::tracking::SMatrixSym55 SMatrixSym55
Definition: TrackState.h:15
size_type size() const
Definition: Assns.h:497
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.
Data related to recob::Hit associated with recob::Track.The purpose is to collect several variables t...
Definition: TrackHitMeta.h:43
string dir
std::unique_ptr< art::FindManyP< recob::Vertex > > assocVertices
const_iterator begin() const
Definition: Assns.h:504
double setMomValue(art::Ptr< recob::Track > ptrack, const std::unique_ptr< art::FindManyP< anab::Calorimetry >> &trackCalo, const double pMC, const int pId) const
const double e
def move(depos, offset)
Definition: depos.py:107
EDProductGetter const * productGetter(ProductID const pid) const
int setPId(const unsigned int iTrack, const std::unique_ptr< art::FindManyP< anab::ParticleID >> &trackId, const int pfPid=0) const
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
std::unique_ptr< art::FindManyP< anab::ParticleID > > trackId
const TVector3 & Direction() const
Definition: Shower.h:189
int PdgCode() const
Definition: MCTrack.h:41
const TLorentzVector & Momentum() const
Definition: MCStep.h:38
const_iterator end() const
Definition: Assns.h:511
Definition: tracks.py:1
int ID() const
Definition: Track.h:198
const SMatrixSym55 & EndCovarianceLocal5D() const
Definition: Track.h:207
std::vector< recob::TrackFitHitInfo > trackFitHitInfos()
get the output vector of TrackFitHitInfos by releasing and moving
Definition: TrackMaker.h:174
std::unique_ptr< art::FindManyP< anab::Calorimetry > > trackCalo
std::unique_ptr< art::FindManyP< recob::Shower > > assocShowers
const std::string & Process() const
Definition: MCTrack.h:43
const MCStep & Start() const
Definition: MCTrack.h:44
recob::tracking::Vector_t Vector_t
int ID() const
Definition: Shower.h:187
const SMatrixSym55 & VertexCovarianceLocal5D() const
Definition: Track.h:206
bool setDirFlip(const recob::Track &track, TVector3 &mcdir, const std::vector< art::Ptr< recob::Vertex >> *vertices=0) const
Struct holding optional TrackMaker outputs.
Definition: TrackMaker.h:114
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:49
std::unique_ptr< art::FindManyP< recob::Track > > assocTracks
void restoreInputPoints(const recob::Trajectory &track, const std::vector< art::Ptr< recob::Hit >> &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit >> &outHits) const
void KalmanFilterFinalTrackFitter::restoreInputPoints ( const recob::Trajectory track,
const std::vector< art::Ptr< recob::Hit >> &  inHits,
recob::Track outTrack,
std::vector< art::Ptr< recob::Hit >> &  outHits 
) const
private

Definition at line 574 of file KalmanFilterFinalTrackFitter_module.cc.

579 {
580  const auto np = outTrack.NumberTrajectoryPoints();
581  std::vector<Point_t> positions(np);
582  std::vector<Vector_t> momenta(np);
583  std::vector<recob::TrajectoryPointFlags> outFlags(np);
584  //
585  for (unsigned int p = 0; p < np; ++p) {
586  auto flag = outTrack.FlagsAtPoint(p);
587  auto mom = outTrack.VertexMomentum();
588  auto op = flag.fromHit();
589  positions[op] = track.LocationAtPoint(op);
590  momenta[op] = mom * track.DirectionAtPoint(op);
591  auto mask = flag.mask();
594  outFlags[op] = recob::TrajectoryPointFlags(op, mask);
595  }
596  auto covs = outTrack.Covariances();
597  outTrack = recob::Track(
598  recob::TrackTrajectory(std::move(positions), std::move(momenta), std::move(outFlags), true),
599  outTrack.ParticleId(),
600  outTrack.Chi2(),
601  outTrack.Ndof(),
602  std::move(covs.first),
603  std::move(covs.second),
604  outTrack.ID());
605  //
606  outHits.clear();
607  for (auto h : inHits)
608  outHits.push_back(h);
609 }
double VertexMomentum() const
Definition: Track.h:142
static constexpr Flag_t NoPoint
The trajectory point is not defined.
int ParticleId() const
Definition: Track.h:171
float Chi2() const
Definition: Track.h:168
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
Definition: Track.h:102
std::pair< SMatrixSym55, SMatrixSym55 > Covariances() const
Definition: Track.h:162
Vector_t DirectionAtPoint(size_t i) const
Computes and returns the direction of the trajectory at a point.
Definition: Trajectory.cxx:117
A trajectory in space reconstructed from hits.
def move(depos, offset)
Definition: depos.py:107
p
Definition: test.py:223
Point_t const & LocationAtPoint(size_t i) const
Returns the position at the specified trajectory point.
Definition: Trajectory.h:236
int Ndof() const
Definition: Track.h:170
int ID() const
Definition: Track.h:198
PointFlags_t const & FlagsAtPoint(size_t i) const
Definition: Track.h:118
TrackCollectionProxyElement< TrackCollProxy > Track
Proxy to an element of a proxy collection of recob::Track objects.
Definition: Track.h:1036
Set of flags pertaining a point of the track.
bool KalmanFilterFinalTrackFitter::setDirFlip ( const recob::Track track,
TVector3 &  mcdir,
const std::vector< art::Ptr< recob::Vertex >> *  vertices = 0 
) const
private

Definition at line 669 of file KalmanFilterFinalTrackFitter_module.cc.

673 {
674  bool result = false;
675  if (p_().options().alwaysInvertDir()) { return true; }
676  else if (p_().options().dirFromMC()) {
677  auto tdir = track.VertexDirection();
678  if ((mcdir.X() * tdir.X() + mcdir.Y() * tdir.Y() + mcdir.Z() * tdir.Z()) < 0.) result = true;
679  }
680  else if (p_().options().dirFromVec()) {
681  std::array<float, 3> dir = p_().options().dirVec();
682  auto tdir = track.VertexDirection();
683  if ((dir[0] * tdir.X() + dir[1] * tdir.Y() + dir[2] * tdir.Z()) < 0.) result = true;
684  }
685  else if (p_().options().trackFromPF() && p_().options().dirFromVtxPF() && vertices->size() > 0) {
686  //if track end is closer to first vertex then track vertex, flip direction
687  double xyz[3];
688  (*vertices)[0]->XYZ(xyz);
689  auto& tv = track.Trajectory().Vertex();
690  auto& te = track.Trajectory().End();
691  if (((xyz[0] - te.X()) * (xyz[0] - te.X()) + (xyz[1] - te.Y()) * (xyz[1] - te.Y()) +
692  (xyz[2] - te.Z()) * (xyz[2] - te.Z())) >
693  ((xyz[0] - tv.X()) * (xyz[0] - tv.X()) + (xyz[1] - tv.Y()) * (xyz[1] - tv.Y()) +
694  (xyz[2] - tv.Z()) * (xyz[2] - tv.Z())))
695  result = true;
696  }
697  return result;
698 }
static QCString result
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
Definition: Track.h:98
Vector_t VertexDirection() const
Definition: Track.h:132
string dir
Point_t const & Vertex() const
Returns the position of the first valid point of the trajectory [cm].
Point_t const & End() const
Returns the position of the last valid point of the trajectory [cm].
double KalmanFilterFinalTrackFitter::setMomValue ( art::Ptr< recob::Track ptrack,
const std::unique_ptr< art::FindManyP< anab::Calorimetry >> &  trackCalo,
const double  pMC,
const int  pId 
) const
private

Definition at line 612 of file KalmanFilterFinalTrackFitter_module.cc.

617 {
618  double result = p_().options().pval();
619  if (p_().options().pFromMSChi2()) { result = tmc.GetMomentumMultiScatterChi2(ptrack); }
620  else if (p_().options().pFromLength()) {
621  result = tmc.GetTrackMomentum(ptrack->Length(), pId);
622  }
623  else if (p_().options().pFromCalo()) {
624  //take average energy from available views
625  const std::vector<art::Ptr<anab::Calorimetry>>& calo = trackCalo->at(ptrack.key());
626  double sumenergy = 0.;
627  int nviews = 0.;
628  for (auto caloit : calo) {
629  if (caloit->KineticEnergy() > 0.) {
630  sumenergy += caloit->KineticEnergy();
631  nviews += 1;
632  }
633  }
634  if (nviews != 0 && sumenergy != 0.) {
635  //protect against problematic cases
636  result = sumenergy / (nviews * 1000.);
637  }
638  }
639  else if (p_().options().pFromMC() && pMC > 0.) {
640  result = pMC;
641  }
642  return result;
643 }
static QCString result
double GetMomentumMultiScatterChi2(art::Ptr< recob::Track > const &trk)
double Length(size_t p=0) const
Access to various track properties.
Definition: Track.h:167
key_type key() const noexcept
Definition: Ptr.h:216
calorimetry
double GetTrackMomentum(double trkrange, int pdg) const
int KalmanFilterFinalTrackFitter::setPId ( const unsigned int  iTrack,
const std::unique_ptr< art::FindManyP< anab::ParticleID >> &  trackId,
const int  pfPid = 0 
) const
private

Definition at line 646 of file KalmanFilterFinalTrackFitter_module.cc.

650 {
651  /*
652  int result = p_().options().pdgId();
653  if (p_().options().trackFromPF() && p_().options().idFromPF()) { result = pfPid; }
654  else if (p_().options().idFromCollection()) {
655  //take the pdgId corresponding to the minimum chi2 (should we give preference to the majority? fixme)
656  double minChi2 = -1.;
657  for (auto idit : trackId->at(iTrack)) {
658  if (idit->MinChi2() > 0. && (minChi2 < 0. || idit->MinChi2() < minChi2)) {
659  result = idit->Pdg();
660  minChi2 = idit->MinChi2();
661  }
662  }
663  }
664  */
665  return -1;
666 }

Member Data Documentation

std::unique_ptr<art::FindManyP<recob::Shower> > trkf::KalmanFilterFinalTrackFitter::assocShowers
private

Definition at line 171 of file KalmanFilterFinalTrackFitter_module.cc.

std::unique_ptr<art::FindManyP<recob::Track> > trkf::KalmanFilterFinalTrackFitter::assocTracks
private

Definition at line 170 of file KalmanFilterFinalTrackFitter_module.cc.

std::unique_ptr<art::FindManyP<recob::Vertex> > trkf::KalmanFilterFinalTrackFitter::assocVertices
private

Definition at line 172 of file KalmanFilterFinalTrackFitter_module.cc.

art::InputTag trkf::KalmanFilterFinalTrackFitter::caloInputTag
private

Definition at line 164 of file KalmanFilterFinalTrackFitter_module.cc.

bool trkf::KalmanFilterFinalTrackFitter::inputFromPF
private

Definition at line 159 of file KalmanFilterFinalTrackFitter_module.cc.

trkf::TrackKalmanFitter trkf::KalmanFilterFinalTrackFitter::kalmanFitter
private

Definition at line 157 of file KalmanFilterFinalTrackFitter_module.cc.

Parameters trkf::KalmanFilterFinalTrackFitter::p_
private

Definition at line 155 of file KalmanFilterFinalTrackFitter_module.cc.

art::InputTag trkf::KalmanFilterFinalTrackFitter::pfParticleInputTag
private

Definition at line 161 of file KalmanFilterFinalTrackFitter_module.cc.

art::InputTag trkf::KalmanFilterFinalTrackFitter::pidInputTag
private

Definition at line 165 of file KalmanFilterFinalTrackFitter_module.cc.

TrackStatePropagator trkf::KalmanFilterFinalTrackFitter::prop
private

Definition at line 156 of file KalmanFilterFinalTrackFitter_module.cc.

art::InputTag trkf::KalmanFilterFinalTrackFitter::showerInputTag
private

Definition at line 163 of file KalmanFilterFinalTrackFitter_module.cc.

art::InputTag trkf::KalmanFilterFinalTrackFitter::simTrackInputTag
private

Definition at line 166 of file KalmanFilterFinalTrackFitter_module.cc.

trkf::TrackMomentumCalculator trkf::KalmanFilterFinalTrackFitter::tmc {}
mutableprivate

Definition at line 158 of file KalmanFilterFinalTrackFitter_module.cc.

std::unique_ptr<art::FindManyP<anab::Calorimetry> > trkf::KalmanFilterFinalTrackFitter::trackCalo
private

Definition at line 168 of file KalmanFilterFinalTrackFitter_module.cc.

std::unique_ptr<art::FindManyP<anab::ParticleID> > trkf::KalmanFilterFinalTrackFitter::trackId
private

Definition at line 169 of file KalmanFilterFinalTrackFitter_module.cc.

art::InputTag trkf::KalmanFilterFinalTrackFitter::trackInputTag
private

Definition at line 162 of file KalmanFilterFinalTrackFitter_module.cc.


The documentation for this class was generated from the following file: