40 Name(
"inputTrajectoryLabel"),
41 Comment(
"Label of recob::Trajectory or recob::TrackTrajectory Collection to be fit")};
43 Name(
"isTrackTrajectory"),
44 Comment(
"If true, we assume the input collection is made of recob::TrackTrajectory " 45 "objects, otherwise of recob::Trajectory objects.")};
48 Comment(
"Label of sim::MCTrack Collection to be used for initial momentum estimate. Used " 49 "only if momFromMC is set to true.")};
56 Comment(
"Flag used to get initial momentum estimate from " 57 "trkf::TrackMomentumCalculator::GetTrackMomentum().")};
60 Comment(
"Flag used to get initial momentum estimate from inputMCLabel collection.")};
62 Name(
"momentumInGeV"),
63 Comment(
"Fixed momentum estimate value, to be used when momFromCalo, momFromLength and " 64 "momFromMC are all false, or if the estimate is not available.")
68 Comment(
"Default particle id hypothesis in case no valid id is provided either via " 69 "PFParticle or in the ParticleId collection.")};
72 Comment(
"Assume track direction from as the one giving positive " 73 "dot product with vector specified by dirVec.")};
75 Comment(
"Fhicl sequence defining the vector used when " 76 "dirFromVec=true. It must have 3 elements.")};
78 Name(
"alwaysInvertDir"),
79 Comment(
"If true, fit all tracks from end to vertex assuming inverted direction.")};
81 Name(
"produceTrackFitHitInfo"),
82 Comment(
"Option to produce (or not) the detailed TrackFitHitInfo.")};
84 Name(
"produceSpacePoints"),
85 Comment(
"Option to produce (or not) the associated SpacePoints.")};
87 Name(
"keepInputTrajectoryPoints"),
88 Comment(
"Option to keep positions and directions from input trajectory. The fit will " 89 "provide only covariance matrices, chi2, ndof, particle Id and absolute momentum. " 90 "It may also modify the trajectory point flags. In order to avoid inconsistencies, " 91 "it has to be used with the following fitter options all set to false: " 92 "sortHitsByPlane, sortOutputHitsMinLength, skipNegProp.")};
146 if (
p_().options().pFromMC() ||
p_().options().dirFromMC())
149 isTT =
p_().inputs().isTrackTrajectory();
151 produces<std::vector<recob::Track>>();
152 produces<art::Assns<recob::Track, recob::Hit>>();
153 produces<art::Assns<recob::Track, recob::Hit, recob::TrackHitMeta>>();
154 if (
isTT) { produces<art::Assns<recob::TrackTrajectory, recob::Track>>(); }
156 produces<art::Assns<recob::Trajectory, recob::Track>>();
158 if (
p_().options().produceTrackFitHitInfo()) {
159 produces<std::vector<std::vector<recob::TrackFitHitInfo>>>();
161 if (
p_().options().produceSpacePoints()) {
162 produces<std::vector<recob::SpacePoint>>();
163 produces<art::Assns<recob::Hit, recob::SpacePoint>>();
168 unsigned int nDirs = 0;
169 if (
p_().options().dirFromMC()) nDirs++;
170 if (
p_().options().dirFromVec()) nDirs++;
171 if (
p_().options().alwaysInvertDir()) nDirs++;
174 <<
"Incompatible configuration parameters: only at most one can be set to true among " 175 "dirFromMC, dirFromVec, and alwaysInvertDir." 179 unsigned int nPFroms = 0;
180 if (
p_().options().pFromLength()) nPFroms++;
181 if (
p_().options().pFromMC()) nPFroms++;
184 <<
"Incompatible configuration parameters: only at most one can be set to true among " 185 "pFromLength, and pFromMC." 189 if (
p_().options().keepInputTrajectoryPoints()) {
190 if (
p_().fitter().sortHitsByPlane() ||
p_().fitter().sortOutputHitsMinLength() ||
191 p_().fitter().skipNegProp()) {
193 <<
"Incompatible configuration parameters: keepInputTrajectoryPoints needs the following " 194 "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>>();
224 if (
p_().options().pFromMC() ||
p_().options().dirFromMC()) {
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);
352 e.
put(std::move(outputTracks));
353 e.
put(std::move(outputHitsMeta));
354 e.
put(std::move(outputHits));
355 if (
p_().options().produceTrackFitHitInfo()) { e.
put(std::move(outputHitInfo)); }
356 if (
p_().options().produceSpacePoints()) {
357 e.
put(std::move(outputSpacePoints));
358 e.
put(std::move(outputHitSpacePointAssn));
361 e.
put(std::move(outputTTjTAssn));
363 e.
put(std::move(outputTjTAssn));
373 std::vector<Point_t> positions(np);
374 std::vector<Vector_t> momenta(np);
375 std::vector<recob::TrajectoryPointFlags> outFlags(np);
377 for (
unsigned int p = 0; p < np; ++p) {
380 auto op = flag.fromHit();
383 auto mask = flag.mask();
394 std::move(covs.first),
395 std::move(covs.second),
399 for (
auto h : inHits)
400 outHits.push_back(h);
407 double result =
p_().options().pval();
409 else if (
p_().options().pFromMC() && pMC > 0.) {
417 int result =
p_().options().pdgId();
422 TVector3& mcdir)
const 425 if (
p_().options().alwaysInvertDir()) {
return true; }
426 else if (
p_().options().dirFromMC()) {
428 if ((mcdir.X() * tdir.X() + mcdir.Y() * tdir.Y() + mcdir.Z() * tdir.Z()) < 0.) result =
true;
430 else if (
p_().options().dirFromVec()) {
431 std::array<float, 3>
dir =
p_().options().dirVec();
433 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
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:
int ParticleId() const
Access to various track properties.
ProductID getProductID(std::string const &instance_name="") const
Declaration of signal hit object.
EDProducer(fhicl::ParameterSet const &pset)
recob::tracking::SMatrixSym55 SMatrixSym55
float Chi2() const
Access to various track properties.
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
Access to position, momentum or covariance at the start and end of the track.
const_iterator begin() const
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Vector_t VertexDirection() const
Returns the direction of the trajectory at the first point.
double Length(size_t startAt=0) const
Returns the approximate length of the trajectory.
EDProductGetter const * productGetter(ProductID const pid) const
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:
Provides recob::Track data product.
double setMomValue(const recob::TrackTrajectory *ptraj, const double pMC, const int pId) const
Class def header for mctrack data container.
int Ndof() const
Access to various track properties.
const TLorentzVector & Momentum() const
const_iterator end() const
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
std::vector< recob::TrackFitHitInfo > trackFitHitInfos()
get the output vector of TrackFitHitInfos by releasing and moving
const std::string & Process() const
PointFlags_t const & FlagsAtPoint(size_t i) const
Access to i-th TrajectoryPoint or its Flags.
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