26 #include "art_root_io/TFileService.h" 27 #include "canvas/Persistency/Common/FindManyP.h" 28 #include "cetlib_except/exception.h" 52 accepted_particle(
int apdg)
106 ,
fHist(pset.get<
bool>(
"Hist"))
112 ,
fMaxTcut(pset.get<
double>(
"MaxTcut"))
114 produces<std::vector<recob::Track>>();
115 produces<std::vector<recob::SpacePoint>>();
116 produces<art::Assns<recob::Track, recob::Hit>>();
117 produces<art::Assns<recob::Track, recob::SpacePoint>>();
118 produces<art::Assns<recob::SpacePoint, recob::Hit>>();
123 <<
"TrackKalmanCheater configured with the following parameters:\n" 139 art::TFileDirectory
dir = tfs->mkdir(
"hitkalman",
"TrackKalmanCheater histograms");
141 fHIncChisq = dir.make<TH1F>(
"IncChisq",
"Incremental Chisquare", 100, 0., 20.);
142 fHPull = dir.make<TH1F>(
"Pull",
"Hit Pull", 100, -10., 10.);
164 std::unique_ptr<std::vector<recob::Track>>
tracks(
new std::vector<recob::Track>);
165 std::unique_ptr<art::Assns<recob::Track, recob::Hit>> th_assn(
167 std::unique_ptr<art::Assns<recob::Track, recob::SpacePoint>> tsp_assn(
173 std::unique_ptr<std::vector<recob::SpacePoint>> spts(
new std::vector<recob::SpacePoint>);
174 std::unique_ptr<art::Assns<recob::SpacePoint, recob::Hit>> sph_assn(
179 std::deque<KGTrack> kalman_tracks;
207 int nclus = clusterh->size();
209 for (
int i = 0; i < nclus; ++i) {
211 std::vector<art::Ptr<recob::Hit>> clushits = fm.at(i);
212 int nhits = clushits.size();
216 ihit != clushits.end();
230 int nhits = hith->size();
233 for (
int i = 0; i < nhits; ++i)
240 std::map<int, art::PtrVector<recob::Hit>> hitmap;
249 std::vector<sim::TrackIDE> tids = bt_serv->
HitToTrackIDEs(clockData, *ihit);
255 int trackID = itid->trackID;
259 hitmap[trackID].push_back(*ihit);
265 sim::ParticleList
const& plist = pi_serv->
ParticleList();
267 auto const det_prop =
280 if (!part)
throw cet::exception(
"TrackKalmanCheater") <<
"no particle!\n";
286 if (not accepted_particle(apdg)) {
continue; }
291 if (hitmap.count(trackid) != 0) nhit = hitmap[trackid].
size();
293 const TLorentzVector& mom = part->
Momentum();
296 log <<
"Trackid=" << trackid <<
", pdgid=" << pdg <<
", status=" << stat
297 <<
", NHit=" << nhit <<
"\n" 298 <<
" x = " << pos.X() <<
", y = " << pos.Y() <<
", z = " << pos.Z() <<
"\n" 299 <<
" px= " << mom.Px() <<
", py= " << mom.Py() <<
", pz= " << mom.Pz() <<
"\n";
305 double px = mom.Px();
306 double py = mom.Py();
307 double pz = mom.Pz();
310 if (nhit > 0 && pz != 0.) {
316 std::shared_ptr<const Surface> psurf(
new SurfYZPlane(0., y, z, 0.));
329 cont.
fill(det_prop, trackhits, -1);
334 std::vector<unsigned int> planehits(3, 0);
336 ih != trackhits.
end();
341 if (plane >= planehits.size()) {
342 throw cet::exception(
"TrackKalmanCheater") <<
"plane " << plane <<
"...\n";
346 unsigned int prefplane = 0;
347 for (
unsigned int i = 0; i < planehits.size(); ++i) {
348 if (planehits[i] > planehits[prefplane]) prefplane = i;
361 kalman_tracks.push_back(trg);
374 for (
auto const& trg : kalman_tracks) {
378 const std::multimap<double, KHitTrack>& trackmap = trg.getTrackMap();
380 ih != trackmap.end();
383 const std::shared_ptr<const KHitBase>&
hit = trh.
getHit();
384 double chisq = hit->getChisq();
397 tracks->reserve(kalman_tracks.size());
398 for (
auto const& kalman_track : kalman_tracks) {
400 kalman_track.fillTrack(det_prop, tracks->back(), tracks->size() - 1);
405 std::vector<unsigned int> hittpindex;
406 kalman_track.fillHits(hits, hittpindex);
411 int nspt = spts->size();
421 for (
unsigned int ispt = nspt; ispt < spts->size(); ++ispt) {
452 mf::LogInfo(
"TrackKalmanCheater") <<
"TrackKalmanCheater statistics:\n" 453 <<
" Number of events = " <<
fNumEvent <<
"\n" 454 <<
" Number of tracks created = " <<
fNumTrack;
void endJob() override
End job method.
void reserve(size_type n)
TrackDirection
Track direction enum.
const std::shared_ptr< const KHitBase > & getHit() const
Measurement.
const TLorentzVector & Position(const int i=0) const
Propagate to PropYZPlane surface.
void fill(const detinfo::DetectorPropertiesData &clock_data, const art::PtrVector< recob::Hit > &hits, int only_plane) override
ProductID getProductID(std::string const &instance_name="") const
A KHitContainer for KHitWireX type measurements.
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
bool smoothTrackIter(int niter, KGTrack &trg, const Propagator &prop) const
Iteratively smooth a track.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::string fClusterModuleLabel
Clustered Hits.
geo::WireID WireID() const
Planar surface parallel to x-axis.
EDProducer(fhicl::ParameterSet const &pset)
KalmanFilterAlg fKFAlg
Kalman filter algorithm.
const KVector< N >::type & getResVector() const
Residual vector.
const art::PtrVector< recob::Hit > & getAssociatedHits(const recob::SpacePoint &spt) const
int fNumEvent
Number of events seen.
art framework interface to geometry description
std::enable_if_t< std::is_arithmetic_v< T >, T > hypot(T x, T y)
std::string fHitModuleLabel
Unclustered Hits.
void produce(art::Event &e) override
bool isValid() const noexcept
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
bool fUseClusterHits
Use cluster hits or all hits?
TrackKalmanCheater(fhicl::ParameterSet const &pset)
const KSymMatrix< N >::type & getResError() const
Residual error matrix.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
typename data_t::const_iterator const_iterator
bool buildTrack(const KTrack &trk, KGTrack &trg, const Propagator &prop, const Propagator::PropDirection dir, KHitContainer &hits, bool linear) const
Make a new track.
#define DEFINE_ART_MODULE(klass)
void push_back(Ptr< U > const &p)
Kalman filter measurement class template.
EDProductGetter const * productGetter(ProductID const pid) const
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
bool CreateAssn(PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
Creates a single one-to-one association.
void beginJob() override
Begin job method.
KVector< 5 >::type TrackVector
Track state vector, dimension 5.
PlaneID_t Plane
Index of the plane within its TPC.
void fillSpacePoints(detinfo::DetectorPropertiesData const &detProp, std::vector< recob::SpacePoint > &spts, std::multimap< double, KHitTrack > const &trackMap) const
Fill a collection of space points.
Detector simulation of raw signals on wires.
const sim::ParticleList & ParticleList() const
Declaration of signal hit object.
int fNumTrack
Number of tracks produced.
void setPlane(int plane)
Set preferred view plane.
const TLorentzVector & Momentum(const int i=0) const
bool fHist
Make histograms.
SpacePointAlg fSpacePointAlg
Space point algorithm.
Provides recob::Track data product.
TH1F * fHIncChisq
Incremental chisquare.
static constexpr double fm
2D representation of charge deposited in the TDC/wire plane
double fMaxTcut
Maximum delta ray energy in MeV for restricted dE/dx.
Algorithm for generating space points from hits.
bool fitMomentum(const KGTrack &trg, const Propagator &prop, KETrack &tremom) const
Estimate track momentum using either range or multiple scattering.
bool updateMomentum(const KETrack &tremom, const Propagator &prop, KGTrack &trg) const
Set track momentum at each track surface.
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
cet::coded_exception< error, detail::translate > exception