27 #include "art_root_io/TFileService.h" 29 #include "cetlib_except/exception.h" 54 bool accepted_particle(
int apdg)
108 ,
fHist(pset.get<
bool>(
"Hist"))
114 ,
fMaxTcut(pset.get<
double>(
"MaxTcut"))
116 produces<std::vector<recob::Track>>();
117 produces<std::vector<recob::SpacePoint>>();
118 produces<art::Assns<recob::Track, recob::Hit>>();
119 produces<art::Assns<recob::Track, recob::SpacePoint>>();
120 produces<art::Assns<recob::SpacePoint, recob::Hit>>();
125 <<
"TrackKalmanCheater configured with the following parameters:\n" 140 art::TFileDirectory
dir = tfs->mkdir(
"hitkalman",
"TrackKalmanCheater histograms");
142 fHIncChisq = dir.make<TH1F>(
"IncChisq",
"Incremental Chisquare", 100, 0., 20.);
143 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);
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();
292 const TLorentzVector& pos = part->
Position();
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();
308 double p = std::hypot(px, py, 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) {
440 evt.
put(std::move(tracks));
441 evt.
put(std::move(spts));
442 evt.
put(std::move(th_assn));
443 evt.
put(std::move(tsp_assn));
444 evt.
put(std::move(sph_assn));
451 mf::LogInfo(
"TrackKalmanCheater") <<
"TrackKalmanCheater statistics:\n" 452 <<
" Number of events = " <<
fNumEvent <<
"\n" 453 <<
" Number of tracks created = " <<
fNumTrack;
void endJob() override
End job method.
void reserve(size_type n)
TrackDirection
Track direction enum.
Basic Kalman filter track class, plus one measurement on same surface.
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
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.
ProductID getProductID(std::string const &instance_name="") const
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::string fClusterModuleLabel
Clustered Hits.
Planar surface parallel to x-axis.
Declaration of signal hit object.
EDProducer(fhicl::ParameterSet const &pset)
list_type::const_iterator const_iterator
constexpr auto abs(T v)
Returns the absolute value of the argument.
geo::WireID const & WireID() const
Initial tdc tick for hit.
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.
std::string fHitModuleLabel
Unclustered Hits.
void produce(art::Event &e) override
bool isValid() const noexcept
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
bool fUseClusterHits
Use cluster hits or all hits?
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
TrackKalmanCheater(fhicl::ParameterSet const &pset)
const KSymMatrix< N >::type & getResError() const
Residual error matrix.
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.
EDProductGetter const * productGetter(ProductID const pid) const
#define DEFINE_ART_MODULE(klass)
void push_back(Ptr< U > const &p)
Kalman filter measurement class template.
Provides recob::Track data product.
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.
Declaration of cluster object.
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
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
int fNumTrack
Number of tracks produced.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Utility object to perform functions of association.
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.
TH1F * fHIncChisq
Incremental chisquare.
A collection of KHitTracks.
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.
art framework interface to geometry description
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