LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
TrackProducerFromPFParticle Class Reference

Produce a reco::Track collection, as a result of the fit of an existing recob::PFParticle collection. More...

Inheritance diagram for TrackProducerFromPFParticle:
art::EDProducer art::ProducerBase art::Consumer art::EngineCreator art::ProductRegistryHelper

Public Types

using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
template<typename UserConfig , typename KeysToIgnore = void>
using Table = ProducerBase::Table< UserConfig, KeysToIgnore >
 

Public Member Functions

 TrackProducerFromPFParticle (fhicl::ParameterSet const &p)
 
 TrackProducerFromPFParticle (TrackProducerFromPFParticle const &)=delete
 
 TrackProducerFromPFParticle (TrackProducerFromPFParticle &&)=delete
 
TrackProducerFromPFParticleoperator= (TrackProducerFromPFParticle const &)=delete
 
TrackProducerFromPFParticleoperator= (TrackProducerFromPFParticle &&)=delete
 
void produce (art::Event &e) override
 
template<typename PROD , BranchType B = InEvent>
ProductID getProductID (std::string const &instanceName={}) const
 
template<typename PROD , BranchType B>
ProductID getProductID (ModuleDescription const &moduleDescription, std::string const &instanceName) const
 
bool modifiesEvent () const
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< T > consumes (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< T > consumesView (InputTag const &it)
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< T > mayConsume (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< T > mayConsumeView (InputTag const &it)
 
base_engine_tcreateEngine (seed_t seed)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make, label_t const &engine_label)
 
seed_t get_seed_value (fhicl::ParameterSet const &pset, char const key[]="seed", seed_t const implicit_seed=-1)
 

Static Public Member Functions

static cet::exempt_ptr< Consumernon_module_context ()
 

Protected Member Functions

CurrentProcessingContext const * currentContext () const
 
void validateConsumedProduct (BranchType const bt, ProductInfo const &pi)
 
void prepareForJob (fhicl::ParameterSet const &pset)
 
void showMissingConsumes () const
 

Private Attributes

std::unique_ptr< trkmkr::TrackMakertrackMaker_
 
art::InputTag pfpInputTag
 
art::InputTag trkInputTag
 
art::InputTag shwInputTag
 
bool doTrackFitHitInfo_
 
bool doSpacePoints_
 
bool spacePointsFromTrajP_
 
bool trackFromPF_
 
bool showerFromPF_
 
bool seedFromPF_
 

Detailed Description

Produce a reco::Track collection, as a result of the fit of an existing recob::PFParticle collection.

This producer takes an input an existing recob::PFParticle collection and refits the associated tracks; it can make track fits of the associated showers as well, but this is experimental - do it at your own risk. The mandatory outputs are: the resulting recob::Track collection, the associated hits, and the association between the input PFParticle and the output Track. Optional outputs are recob::TrackFitHitInfo and recob::SpacePoint collections, plus the Assns of SpacePoints to Hits. An option is provided to create SpacePoints from the TrajectoryPoints in the Track. The fit is performed by an user-defined tool, which must inherit from larreco/TrackFinder/TrackMaker.

Parameters: trackMaker (fhicl::ParameterSet for the trkmkr::TrackMaker tool used to do the fit), inputCollection (art::InputTag of the input recob::Track collection), doTrackFitHitInfo (bool to decide whether to produce recob::TrackFitHitInfo's), doSpacePoints (bool to decide whether to produce recob::SpacePoint's), spacePointsFromTrajP (bool to decide whether the produced recob::SpacePoint's are taken from the recob::tracking::TrajectoryPoint_t's of the fitted recob::Track), trackFromPF (bool to decide whether to fit the recob::Track associated to the recob::PFParticle), and showerFromPF (bool to decide whether to fit the recob::Shower associated to the recob::PFParticle - this option is intended to mitigate possible problems due to tracks being mis-identified as showers) seedFromPF (bool to decide whether to fit the recob::PFParticle using the associated seed)

Author
G. Cerati (FNAL, MicroBooNE)
Date
2017
Version
1.0

Definition at line 52 of file TrackProducerFromPFParticle_module.cc.

Member Typedef Documentation

using art::EDProducer::ModuleType = EDProducer
inherited

Definition at line 34 of file EDProducer.h.

template<typename UserConfig , typename KeysToIgnore = void>
using art::EDProducer::Table = ProducerBase::Table<UserConfig, KeysToIgnore>
inherited

Definition at line 43 of file EDProducer.h.

using art::EDProducer::WorkerType = WorkerT<EDProducer>
inherited

Definition at line 35 of file EDProducer.h.

Constructor & Destructor Documentation

TrackProducerFromPFParticle::TrackProducerFromPFParticle ( fhicl::ParameterSet const &  p)
explicit

Definition at line 78 of file TrackProducerFromPFParticle_module.cc.

References doSpacePoints_, doTrackFitHitInfo_, fhicl::ParameterSet::get(), pfpInputTag, seedFromPF_, showerFromPF_, shwInputTag, spacePointsFromTrajP_, trackFromPF_, and trkInputTag.

79  : trackMaker_{art::make_tool<trkmkr::TrackMaker>(p.get<fhicl::ParameterSet>("trackMaker"))}
80  , pfpInputTag{p.get<art::InputTag>("inputCollection")}
81  , doTrackFitHitInfo_{p.get<bool>("doTrackFitHitInfo")}
82  , doSpacePoints_{p.get<bool>("doSpacePoints")}
83  , spacePointsFromTrajP_{p.get<bool>("spacePointsFromTrajP")}
84  , trackFromPF_{p.get<bool>("trackFromPF")}
85  , showerFromPF_{p.get<bool>("showerFromPF")}
86  , seedFromPF_{p.get<bool>("seedFromPF")}
87 {
88  //
89  if (p.has_key("trackInputTag")) trkInputTag = p.get<art::InputTag>("trackInputTag");
90  else trkInputTag = pfpInputTag;
91  if (p.has_key("showerInputTag")) shwInputTag = p.get<art::InputTag>("showerInputTag");
92  else shwInputTag = pfpInputTag;
93  produces<std::vector<recob::Track> >();
94  produces<art::Assns<recob::Track, recob::Hit, recob::TrackHitMeta> >();
95  produces<art::Assns<recob::PFParticle, recob::Track> >();
96  if (doTrackFitHitInfo_) produces<std::vector<std::vector<recob::TrackFitHitInfo> > >();
97  if (doSpacePoints_) {
98  produces<std::vector<recob::SpacePoint> >();
99  produces<art::Assns<recob::Hit, recob::SpacePoint> >();
100  }
101 }
std::unique_ptr< trkmkr::TrackMaker > trackMaker_
TrackProducerFromPFParticle::TrackProducerFromPFParticle ( TrackProducerFromPFParticle const &  )
delete
TrackProducerFromPFParticle::TrackProducerFromPFParticle ( TrackProducerFromPFParticle &&  )
delete

Member Function Documentation

template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::consumes ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::consumes ( InputTag const &  it)
inherited

Definition at line 147 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

148 {
149  if (!moduleContext_)
150  return ProductToken<T>::invalid();
151 
152  consumables_[BT].emplace_back(ConsumableType::Product,
153  TypeID{typeid(T)},
154  it.label(),
155  it.instance(),
156  it.process());
157  return ProductToken<T>{it};
158 }
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename T , art::BranchType BT>
void art::Consumer::consumesMany ( )
inherited

Definition at line 162 of file Consumer.h.

163 {
164  if (!moduleContext_)
165  return;
166 
167  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
168 }
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::consumesView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::consumesView ( InputTag const &  it)
inherited

Definition at line 172 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

173 {
174  if (!moduleContext_)
175  return ViewToken<T>::invalid();
176 
177  consumables_[BT].emplace_back(ConsumableType::ViewElement,
178  TypeID{typeid(T)},
179  it.label(),
180  it.instance(),
181  it.process());
182  return ViewToken<T>{it};
183 }
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
EngineCreator::base_engine_t & EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make 
)
inherited

Definition at line 32 of file EngineCreator.cc.

References art::EngineCreator::rng().

34 {
35  return rng()->createEngine(
36  placeholder_schedule_id(), seed, kind_of_engine_to_make);
37 }
long seed
Definition: chem4.cc:68
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
EngineCreator::base_engine_t & EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make,
label_t const &  engine_label 
)
inherited

Definition at line 40 of file EngineCreator.cc.

References art::EngineCreator::rng().

43 {
44  return rng()->createEngine(
45  placeholder_schedule_id(), seed, kind_of_engine_to_make, engine_label);
46 }
long seed
Definition: chem4.cc:68
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
CurrentProcessingContext const * art::EDProducer::currentContext ( ) const
protectedinherited

Definition at line 120 of file EDProducer.cc.

References art::EDProducer::current_context_.

121  {
122  return current_context_.get();
123  }
CPC_exempt_ptr current_context_
Definition: EDProducer.h:116
EngineCreator::seed_t EngineCreator::get_seed_value ( fhicl::ParameterSet const &  pset,
char const  key[] = "seed",
seed_t const  implicit_seed = -1 
)
inherited

Definition at line 49 of file EngineCreator.cc.

References fhicl::ParameterSet::get().

Referenced by art::MixFilter< T >::initEngine_().

52 {
53  auto const& explicit_seeds = pset.get<std::vector<int>>(key, {});
54  return explicit_seeds.empty() ? implicit_seed : explicit_seeds.front();
55 }
template<typename PROD , BranchType B>
ProductID art::EDProducer::getProductID ( std::string const &  instanceName = {}) const
inlineinherited

Definition at line 123 of file EDProducer.h.

References art::EDProducer::moduleDescription_.

124  {
125  return ProducerBase::getProductID<PROD, B>(moduleDescription_,
126  instanceName);
127  }
ModuleDescription moduleDescription_
Definition: EDProducer.h:115
template<typename PROD , BranchType B>
ProductID art::ProducerBase::getProductID ( ModuleDescription const &  moduleDescription,
std::string const &  instanceName 
) const
inherited

Definition at line 56 of file ProducerBase.h.

References B, and art::ModuleDescription::moduleLabel().

Referenced by art::ProducerBase::modifiesEvent().

58  {
59  auto const& pd =
60  get_ProductDescription<PROD>(B, md.moduleLabel(), instanceName);
61  return pd.productID();
62  }
Int_t B
Definition: plot.C:25
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::mayConsume ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::mayConsume ( InputTag const &  it)
inherited

Definition at line 190 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

191 {
192  if (!moduleContext_)
193  return ProductToken<T>::invalid();
194 
195  consumables_[BT].emplace_back(ConsumableType::Product,
196  TypeID{typeid(T)},
197  it.label(),
198  it.instance(),
199  it.process());
200  return ProductToken<T>{it};
201 }
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename T , art::BranchType BT>
void art::Consumer::mayConsumeMany ( )
inherited

Definition at line 205 of file Consumer.h.

206 {
207  if (!moduleContext_)
208  return;
209 
210  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
211 }
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::mayConsumeView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::mayConsumeView ( InputTag const &  it)
inherited

Definition at line 215 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

216 {
217  if (!moduleContext_)
218  return ViewToken<T>::invalid();
219 
220  consumables_[BT].emplace_back(ConsumableType::ViewElement,
221  TypeID{typeid(T)},
222  it.label(),
223  it.instance(),
224  it.process());
225  return ViewToken<T>{it};
226 }
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
bool art::ProducerBase::modifiesEvent ( ) const
inlineinherited

Definition at line 40 of file ProducerBase.h.

References art::ProducerBase::getProductID().

41  {
42  return true;
43  }
TrackProducerFromPFParticle& TrackProducerFromPFParticle::operator= ( TrackProducerFromPFParticle const &  )
delete
TrackProducerFromPFParticle& TrackProducerFromPFParticle::operator= ( TrackProducerFromPFParticle &&  )
delete
void art::Consumer::prepareForJob ( fhicl::ParameterSet const &  pset)
protectedinherited

Definition at line 89 of file Consumer.cc.

References fhicl::ParameterSet::get_if_present().

Referenced by art::EDProducer::doBeginJob(), art::EDFilter::doBeginJob(), and art::EDAnalyzer::doBeginJob().

90 {
91  if (!moduleContext_)
92  return;
93 
94  pset.get_if_present("errorOnMissingConsumes", requireConsumes_);
95  for (auto& consumablesPerBranch : consumables_) {
96  cet::sort_all(consumablesPerBranch);
97  }
98 }
bool requireConsumes_
Definition: Consumer.h:137
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
void TrackProducerFromPFParticle::produce ( art::Event e)
overridevirtual

Implements art::EDProducer.

Definition at line 103 of file TrackProducerFromPFParticle_module.cc.

References util::associated_groups(), d, DEFINE_ART_MODULE, dir, recob::Shower::Direction(), doSpacePoints_, doTrackFitHitInfo_, e, recob::Seed::GetDirection(), recob::Seed::GetPoint(), util::groupByIndex(), trkmkr::OptionalOutputs::initSpacePoints(), trkmkr::OptionalOutputs::initTrackFitInfos(), max, recob::Track::NumberTrajectoryPoints(), pfpInputTag, seed, seedFromPF_, tca::seeds, showerFromPF_, recob::Shower::ShowerStart(), shwInputTag, trkmkr::OptionalOutputs::spacePointHitPairs(), spacePointsFromTrajP_, track, trkmkr::OptionalOutputs::trackFitHitInfos(), trackFromPF_, trackMaker_, and trkInputTag.

104 {
105  // Output collections
106  auto outputTracks = std::make_unique<std::vector<recob::Track> >();
107  auto outputHits = std::make_unique<art::Assns<recob::Track, recob::Hit, recob::TrackHitMeta> >();
108  auto outputPfpTAssn = std::make_unique<art::Assns<recob::PFParticle, recob::Track> >();
109  auto outputHitInfo = std::make_unique<std::vector<std::vector<recob::TrackFitHitInfo> > >();
110  auto outputSpacePoints = std::make_unique<std::vector<recob::SpacePoint> >();
111  auto outputHitSpacePointAssn = std::make_unique<art::Assns<recob::Hit, recob::SpacePoint> >();
112  //
113  // PtrMakers for Assns
114  art::PtrMaker<recob::Track> trackPtrMaker(e, *this);
115  art::PtrMaker<recob::SpacePoint>* spacePointPtrMaker = nullptr;
116  if (doSpacePoints_) spacePointPtrMaker = new art::PtrMaker<recob::SpacePoint>(e, *this);
117  //
118  // Input from event
119  art::ValidHandle<std::vector<recob::PFParticle> > inputPfps = e.getValidHandle<std::vector<recob::PFParticle> >(pfpInputTag);
120  std::unique_ptr<art::FindManyP<recob::Track> > assocTracks;
122  std::unique_ptr<art::FindManyP<recob::Shower> > assocShowers;
123  std::unique_ptr<art::FindManyP<recob::Seed> > assocSeeds;
124  if (trackFromPF_) {
125  assocTracks = std::unique_ptr<art::FindManyP<recob::Track> >(new art::FindManyP<recob::Track>(inputPfps, e, pfpInputTag));
126  tkHitsAssn = *e.getValidHandle<art::Assns<recob::Track, recob::Hit> >(trkInputTag);
127  }
128  if (showerFromPF_) assocShowers = std::unique_ptr<art::FindManyP<recob::Shower> >(new art::FindManyP<recob::Shower>(inputPfps, e, pfpInputTag));
129  if (seedFromPF_) assocSeeds = std::unique_ptr<art::FindManyP<recob::Seed> >(new art::FindManyP<recob::Seed>(inputPfps, e, pfpInputTag));
130  const auto& trackHitsGroups = util::associated_groups(tkHitsAssn);
131  //
132  std::unique_ptr<art::FindManyP<recob::Cluster> > assocClusters = std::unique_ptr<art::FindManyP<recob::Cluster> >(new art::FindManyP<recob::Cluster>(inputPfps, e, pfpInputTag));
134  const auto& clusterHitsGroups = util::associated_groups(clHitsAssn);
135  //
136  // Initialize tool for this event
137  trackMaker_->initEvent(e);
138  //
139  // Loop over pfps to fit
140  for (unsigned int iPfp = 0; iPfp < inputPfps->size(); ++iPfp) {
141  //
142  const art::Ptr<recob::PFParticle> pfp(inputPfps, iPfp);
143  //
144  if (trackFromPF_) {
145  // Tracks associated to PFParticles
146  const std::vector<art::Ptr<recob::Track> >& tracks = assocTracks->at(iPfp);
147  // Loop over tracks to refit
148  for (art::Ptr<recob::Track> const& track: tracks) {
149  //
150  // Get track and its hits
151  std::vector<art::Ptr<recob::Hit> > inHits;
152  decltype(auto) hitsRange = util::groupByIndex(trackHitsGroups, track.key());
153  for (art::Ptr<recob::Hit> const& hit: hitsRange) inHits.push_back(hit);
154  //
155  // Declare output objects
156  recob::Track outTrack;
157  std::vector<art::Ptr<recob::Hit> > outHits;
158  trkmkr::OptionalOutputs optionals;
159  if (doTrackFitHitInfo_) optionals.initTrackFitInfos();
160  if (doSpacePoints_ && !spacePointsFromTrajP_) optionals.initSpacePoints();
161  //
162  // Invoke tool to fit track and fill output objects
163  bool fitok = trackMaker_->makeTrack(track, inHits, outTrack, outHits, optionals);
164  if (!fitok) continue;
165  //
166  // Check that the requirement Nhits == Npoints is satisfied
167  // We also require the hits to the in the same order as the points (this cannot be enforced, can it?)
168  if (outTrack.NumberTrajectoryPoints()!=outHits.size()) {
169  throw cet::exception("TrackProducerFromPFParticle") << "Produced recob::Track required to have 1-1 correspondance between hits and points.\n";
170  }
171  //
172  // Fill output collections, including Assns
173  outputTracks->emplace_back(std::move(outTrack));
174  const art::Ptr<recob::Track> aptr = trackPtrMaker(outputTracks->size()-1);
175  outputPfpTAssn->addSingle(pfp, aptr);
176  unsigned int ip = 0;
177  for (auto const& trhit: outHits) {
178  recob::TrackHitMeta metadata(outputTracks->back().HasValidPoint(ip) ? ip : std::numeric_limits<int>::max(), -std::numeric_limits<double>::max());
179  outputHits->addSingle(aptr, trhit, metadata);
180  //
181  if (doSpacePoints_ && spacePointsFromTrajP_ && outputTracks->back().HasValidPoint(ip)) {
182  auto& tp = outputTracks->back().Trajectory().LocationAtPoint(ip);
183  const double fXYZ[3] = {tp.X(),tp.Y(),tp.Z()};
184  const double fErrXYZ[6] = {0};
185  recob::SpacePoint sp(fXYZ, fErrXYZ, -1.);
186  outputSpacePoints->emplace_back(std::move(sp));
187  const art::Ptr<recob::SpacePoint> apsp = (*spacePointPtrMaker)(outputSpacePoints->size()-1);
188  outputHitSpacePointAssn->addSingle(trhit, apsp);
189  }
190  ip++;
191  }
193  auto osp = optionals.spacePointHitPairs();
194  for (auto it = osp.begin(); it!=osp.end(); ++it ) {
195  outputSpacePoints->emplace_back(std::move(it->first));
196  const art::Ptr<recob::SpacePoint> apsp = (*spacePointPtrMaker)(outputSpacePoints->size()-1);
197  outputHitSpacePointAssn->addSingle(it->second,apsp);
198  }
199  }
200  if (doTrackFitHitInfo_) {
201  outputHitInfo->emplace_back(optionals.trackFitHitInfos());
202  }
203  }
204  }
205  //
206  if (showerFromPF_) {
207  //
208  // Showers associated to PFParticles
209  const std::vector<art::Ptr<recob::Shower> >& showers = assocShowers->at(iPfp);
210  // if there is more than one shower the logic below to get the hits does not work! this works, at least for uboone
211  if (showers.size()!=1) continue;
212  //
213  // Get hits for shower (through the chain pfp->clusters->hits)
214  std::vector<art::Ptr<recob::Hit> > inHits;
215  const std::vector<art::Ptr<recob::Cluster> > clustersRange = assocClusters->at(iPfp);
216  for (art::Ptr<recob::Cluster> const& cluster: clustersRange) {
217  // for hits we use groupByIndex since it preserves the order (and we can use it since each cluster must have associated hits)
218  decltype(auto) hitsRange = util::groupByIndex(clusterHitsGroups, cluster.key());
219  for (art::Ptr<recob::Hit> const& hit: hitsRange) inHits.push_back(hit);
220  }
221  // Loop over showers to refit (should be only one)
222  for (unsigned int iShower = 0; iShower < showers.size(); ++iShower) {
223  //
224  // Get the shower and convert/hack it into a trajectory so that the fit is initialized
225  art::Ptr<recob::Shower> shower = showers[iShower];
226  recob::tracking::Point_t pos(shower->ShowerStart().X(),shower->ShowerStart().Y(),shower->ShowerStart().Z());
227  recob::tracking::Vector_t dir(shower->Direction().X(),shower->Direction().Y(),shower->Direction().Z());
228  std::vector<recob::tracking::Point_t> p;
229  std::vector<recob::tracking::Vector_t> d;
230  for (unsigned int i=0; i<inHits.size(); ++i) {
231  p.push_back(pos);
232  d.push_back(dir);
233  }
234  recob::TrackTrajectory traj(std::move(p), std::move(d), recob::TrackTrajectory::Flags_t(p.size()), false);
235  //
236  // Declare output objects
237  recob::Track outTrack;
238  std::vector<art::Ptr<recob::Hit> > outHits;
239  trkmkr::OptionalOutputs optionals;
240  if (doTrackFitHitInfo_) optionals.initTrackFitInfos();
242  //
243  // Invoke tool to fit track and fill output objects
244  bool fitok = trackMaker_->makeTrack(traj, iPfp, inHits, outTrack, outHits, optionals);
245  if (!fitok) continue;
246  //
247  // Check that the requirement Nhits == Npoints is satisfied
248  // We also require the hits to the in the same order as the points (this cannot be enforced, can it?)
249  if (outTrack.NumberTrajectoryPoints()!=outHits.size()) {
250  throw cet::exception("TrackProducerFromPFParticle") << "Produced recob::Track required to have 1-1 correspondance between hits and points.\n";
251  }
252  //
253  // Fill output collections, including Assns
254  outputTracks->emplace_back(std::move(outTrack));
255  const art::Ptr<recob::Track> aptr = trackPtrMaker(outputTracks->size()-1);
256  outputPfpTAssn->addSingle(pfp, aptr);
257  unsigned int ip = 0;
258  for (auto const& trhit: outHits) {
259  recob::TrackHitMeta metadata(outputTracks->back().HasValidPoint(ip) ? ip : std::numeric_limits<int>::max(), -std::numeric_limits<double>::max());
260  outputHits->addSingle(aptr, trhit, metadata);
261  //
262  if (doSpacePoints_ && spacePointsFromTrajP_ && outputTracks->back().HasValidPoint(ip)) {
263  auto& tp = outputTracks->back().Trajectory().LocationAtPoint(ip);
264  const double fXYZ[3] = {tp.X(),tp.Y(),tp.Z()};
265  const double fErrXYZ[6] = {0};
266  recob::SpacePoint sp(fXYZ, fErrXYZ, -1.);
267  outputSpacePoints->emplace_back(std::move(sp));
268  const art::Ptr<recob::SpacePoint> apsp = (*spacePointPtrMaker)(outputSpacePoints->size()-1);
269  outputHitSpacePointAssn->addSingle(trhit, apsp);
270  }
271  ip++;
272  }
274  auto osp = optionals.spacePointHitPairs();
275  for (auto it = osp.begin(); it!=osp.end(); ++it ) {
276  outputSpacePoints->emplace_back(std::move(it->first));
277  const art::Ptr<recob::SpacePoint> apsp = (*spacePointPtrMaker)(outputSpacePoints->size()-1);
278  outputHitSpacePointAssn->addSingle(it->second,apsp);
279  }
280  }
281  if (doTrackFitHitInfo_) {
282  outputHitInfo->emplace_back(optionals.trackFitHitInfos());
283  }
284  }
285  }
286  //
287  //
288  if (seedFromPF_) {
289  //
290  // Seeds associated to PFParticles
291  const std::vector<art::Ptr<recob::Seed> >& seeds = assocSeeds->at(iPfp);
292  // if there is more than one seed the logic below to get the hits does not work! this works, at least for uboone
293  if (seeds.size()!=1) continue;
294  //
295  // Get hits for pfp (through the chain pfp->clusters->hits)
296  std::vector<art::Ptr<recob::Hit> > inHits;
297  const std::vector<art::Ptr<recob::Cluster> > clustersRange = assocClusters->at(iPfp);
298  for (art::Ptr<recob::Cluster> const& cluster: clustersRange) {
299  // for hits we use groupByIndex since it preserves the order (and we can use it since each cluster must have associated hits)
300  decltype(auto) hitsRange = util::groupByIndex(clusterHitsGroups, cluster.key());
301  for (art::Ptr<recob::Hit> const& hit: hitsRange) inHits.push_back(hit);
302  }
303  if (inHits.size()<4) continue;
304  // Loop over seeds should be only one)
305  for (unsigned int iS = 0; iS < seeds.size(); ++iS) {
306  //
307  // Get the seed and convert/hack it into a trajectory so that the fit is initialized
308  art::Ptr<recob::Seed> seed = seeds[iS];
309  double p0[3], pe[3];
310  seed->GetPoint(p0,pe);
311  double d0[3], de[3];
312  seed->GetDirection(d0,de);
313  recob::tracking::Point_t pos(p0[0],p0[1],p0[2]);
314  recob::tracking::Vector_t dir(d0[0],d0[1],d0[2]);
315  std::vector<recob::tracking::Point_t> p;
316  std::vector<recob::tracking::Vector_t> d;
317  for (unsigned int i=0; i<inHits.size(); ++i) {
318  p.push_back(pos);
319  d.push_back(dir);
320  }
321  recob::TrackTrajectory traj(std::move(p), std::move(d), recob::TrackTrajectory::Flags_t(p.size()), false);
322  //
323  // Declare output objects
324  recob::Track outTrack;
325  std::vector<art::Ptr<recob::Hit> > outHits;
326  trkmkr::OptionalOutputs optionals;
327  if (doTrackFitHitInfo_) optionals.initTrackFitInfos();
329  //
330  // Invoke tool to fit track and fill output objects
331  bool fitok = trackMaker_->makeTrack(traj, iPfp, inHits, outTrack, outHits, optionals);
332  if (!fitok) continue;
333  //
334  // Check that the requirement Nhits == Npoints is satisfied
335  // We also require the hits to the in the same order as the points (this cannot be enforced, can it?)
336  if (outTrack.NumberTrajectoryPoints()!=outHits.size()) {
337  throw cet::exception("TrackProducerFromPFParticle") << "Produced recob::Track required to have 1-1 correspondance between hits and points.\n";
338  }
339  //
340  // Fill output collections, including Assns
341  outputTracks->emplace_back(std::move(outTrack));
342  const art::Ptr<recob::Track> aptr = trackPtrMaker(outputTracks->size()-1);
343  outputPfpTAssn->addSingle(pfp, aptr);
344  unsigned int ip = 0;
345  for (auto const& trhit: outHits) {
346  recob::TrackHitMeta metadata(outputTracks->back().HasValidPoint(ip) ? ip : std::numeric_limits<int>::max(), -std::numeric_limits<double>::max());
347  outputHits->addSingle(aptr, trhit, metadata);
348  //
349  if (doSpacePoints_ && spacePointsFromTrajP_ && outputTracks->back().HasValidPoint(ip)) {
350  auto& tp = outputTracks->back().Trajectory().LocationAtPoint(ip);
351  const double fXYZ[3] = {tp.X(),tp.Y(),tp.Z()};
352  const double fErrXYZ[6] = {0};
353  recob::SpacePoint sp(fXYZ, fErrXYZ, -1.);
354  outputSpacePoints->emplace_back(std::move(sp));
355  const art::Ptr<recob::SpacePoint> apsp = (*spacePointPtrMaker)(outputSpacePoints->size()-1);
356  outputHitSpacePointAssn->addSingle(trhit, apsp);
357  }
358  ip++;
359  }
361  auto osp = optionals.spacePointHitPairs();
362  for (auto it = osp.begin(); it!=osp.end(); ++it ) {
363  outputSpacePoints->emplace_back(std::move(it->first));
364  const art::Ptr<recob::SpacePoint> apsp = (*spacePointPtrMaker)(outputSpacePoints->size()-1);
365  outputHitSpacePointAssn->addSingle(it->second,apsp);
366  }
367  }
368  if (doTrackFitHitInfo_) {
369  outputHitInfo->emplace_back(optionals.trackFitHitInfos());
370  }
371  }
372  }
373  //
374  }
375  //
376  // Put collections in the event
377  e.put(std::move(outputTracks));
378  e.put(std::move(outputHits));
379  e.put(std::move(outputPfpTAssn));
380  if (doTrackFitHitInfo_) {
381  e.put(std::move(outputHitInfo));
382  }
383  if (doSpacePoints_) {
384  e.put(std::move(outputSpacePoints));
385  e.put(std::move(outputHitSpacePointAssn));
386  }
387  if (doSpacePoints_) delete spacePointPtrMaker;
388 }
const TVector3 & ShowerStart() const
Definition: Shower.h:192
Namespace for general, non-LArSoft-specific utilities.
Definition: PIDAAlg.h:17
void initTrackFitInfos()
initialize the output vector of TrackFitHitInfos
Definition: TrackMaker.h:102
Reconstruction base classes.
void GetPoint(double *Pt, double *Err) const
Definition: Seed.cxx:112
auto groupByIndex(Groups &&groups, std::size_t index) -> decltype(auto)
Returns the group within groups with the specified index.
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
Definition: Track.h:105
STL namespace.
for(int i=0;i< 401;i++)
Data related to recob::Hit associated with recob::Track.The purpose is to collect several variables t...
Definition: TrackHitMeta.h:43
Cluster finding and building.
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
auto associated_groups(A const &assns)
Helper functions to access associations in order.
std::unique_ptr< trkmkr::TrackMaker > trackMaker_
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< Coord_t >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space. See recob::tracking::Coord_t for more details on the ...
Definition: TrackingTypes.h:29
Int_t max
Definition: plot.C:27
if(nlines<=0)
long seed
Definition: chem4.cc:68
A trajectory in space reconstructed from hits.
Float_t d
Definition: plot.C:237
const TVector3 & Direction() const
Definition: Shower.h:189
std::vector< PointFlags_t > Flags_t
Type of point flag list.
Detector simulation of raw signals on wires.
std::vector< SpHitPair > spacePointHitPairs()
get the output vector of SpHitPair by releasing and moving
Definition: TrackMaker.h:119
std::vector< TrajPoint > seeds
Definition: DataStructs.cxx:11
std::vector< recob::TrackFitHitInfo > trackFitHitInfos()
get the output vector of TrackFitHitInfos by releasing and moving
Definition: TrackMaker.h:114
TDirectory * dir
Definition: macro.C:5
HLT enums.
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Float_t e
Definition: plot.C:34
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< Coord_t >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space. See recob::tracking::Coord_t for more detai...
Definition: TrackingTypes.h:26
Float_t track
Definition: plot.C:34
Definition: Track.hh:43
void GetDirection(double *Dir, double *Err) const
Definition: Seed.cxx:102
void initSpacePoints()
initialize the output vector of SpHitPair
Definition: TrackMaker.h:106
Struct holding optional TrackMaker outputs.
Definition: TrackMaker.h:73
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:52
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void art::Consumer::showMissingConsumes ( ) const
protectedinherited

Definition at line 125 of file Consumer.cc.

Referenced by art::EDProducer::doEndJob(), art::EDFilter::doEndJob(), art::EDAnalyzer::doEndJob(), and art::RootOutput::endJob().

126 {
127  if (!moduleContext_)
128  return;
129 
130  // If none of the branches have missing consumes statements, exit early.
131  if (std::all_of(cbegin(missingConsumes_),
132  cend(missingConsumes_),
133  [](auto const& perBranch) { return perBranch.empty(); }))
134  return;
135 
136  constexpr cet::HorizontalRule rule{60};
137  mf::LogPrint log{"MTdiagnostics"};
138  log << '\n'
139  << rule('=') << '\n'
140  << "The following consumes (or mayConsume) statements are missing from\n"
141  << module_context(moduleDescription_) << '\n'
142  << rule('-') << '\n';
143 
144  cet::for_all_with_index(
145  missingConsumes_, [&log](std::size_t const i, auto const& perBranch) {
146  for (auto const& pi : perBranch) {
147  log << " "
148  << assemble_consumes_statement(static_cast<BranchType>(i), pi)
149  << '\n';
150  }
151  });
152  log << rule('=');
153 }
cet::exempt_ptr< ModuleDescription const > moduleDescription_
Definition: Consumer.h:140
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
bool moduleContext_
Definition: Consumer.h:136
ConsumableProductSets missingConsumes_
Definition: Consumer.h:139
void art::Consumer::validateConsumedProduct ( BranchType const  bt,
ProductInfo const &  pi 
)
protectedinherited

Definition at line 101 of file Consumer.cc.

References art::errors::ProductRegistrationFailure.

103 {
104  // Early exits if consumes tracking has been disabled or if the
105  // consumed product is an allowed consumable.
106  if (!moduleContext_)
107  return;
108 
109  if (cet::binary_search_all(consumables_[bt], pi))
110  return;
111 
112  if (requireConsumes_) {
114  "Consumer: an error occurred during validation of a "
115  "retrieved product\n\n")
116  << "The following consumes (or mayConsume) statement is missing from\n"
117  << module_context(moduleDescription_) << ":\n\n"
118  << " " << assemble_consumes_statement(bt, pi) << "\n\n";
119  }
120 
121  missingConsumes_[bt].insert(pi);
122 }
cet::exempt_ptr< ModuleDescription const > moduleDescription_
Definition: Consumer.h:140
bool requireConsumes_
Definition: Consumer.h:137
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
ConsumableProductSets missingConsumes_
Definition: Consumer.h:139

Member Data Documentation

bool TrackProducerFromPFParticle::doSpacePoints_
private

Definition at line 71 of file TrackProducerFromPFParticle_module.cc.

Referenced by produce(), and TrackProducerFromPFParticle().

bool TrackProducerFromPFParticle::doTrackFitHitInfo_
private

Definition at line 70 of file TrackProducerFromPFParticle_module.cc.

Referenced by produce(), and TrackProducerFromPFParticle().

art::InputTag TrackProducerFromPFParticle::pfpInputTag
private

Definition at line 67 of file TrackProducerFromPFParticle_module.cc.

Referenced by produce(), and TrackProducerFromPFParticle().

bool TrackProducerFromPFParticle::seedFromPF_
private

Definition at line 75 of file TrackProducerFromPFParticle_module.cc.

Referenced by produce(), and TrackProducerFromPFParticle().

bool TrackProducerFromPFParticle::showerFromPF_
private

Definition at line 74 of file TrackProducerFromPFParticle_module.cc.

Referenced by produce(), and TrackProducerFromPFParticle().

art::InputTag TrackProducerFromPFParticle::shwInputTag
private

Definition at line 69 of file TrackProducerFromPFParticle_module.cc.

Referenced by produce(), and TrackProducerFromPFParticle().

bool TrackProducerFromPFParticle::spacePointsFromTrajP_
private

Definition at line 72 of file TrackProducerFromPFParticle_module.cc.

Referenced by produce(), and TrackProducerFromPFParticle().

bool TrackProducerFromPFParticle::trackFromPF_
private

Definition at line 73 of file TrackProducerFromPFParticle_module.cc.

Referenced by produce(), and TrackProducerFromPFParticle().

std::unique_ptr<trkmkr::TrackMaker> TrackProducerFromPFParticle::trackMaker_
private

Definition at line 66 of file TrackProducerFromPFParticle_module.cc.

Referenced by produce().

art::InputTag TrackProducerFromPFParticle::trkInputTag
private

Definition at line 68 of file TrackProducerFromPFParticle_module.cc.

Referenced by produce(), and TrackProducerFromPFParticle().


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