6 const art::Ptr<recob::Track> &trk,
8 const std::vector<const recob::TrackHitMeta *> &trk_thms) {
10 if (!trk)
return false;
12 for (
unsigned i = 0; i < trk_hits.size(); i++) {
14 if (hit == trk_hits[i]) {
16 if (trk->HasValidPoint(trk_thms[i]->Index())) {
27 const std::vector<art::Ptr<recob::PFParticle>> &pfps,
30 std::vector<unsigned> pfp_nhit(pfps.size(), 0);
32 for (
const art::Ptr<recob::Hit>
h: hits) {
33 for (
unsigned i_pfp = 0; i_pfp < pfps.size(); i_pfp++) {
34 const std::vector<art::Ptr<recob::Hit>> &thispfpHits = pfp_hits[i_pfp];
36 for (
const art::Ptr<recob::Hit> &pfp_h: thispfpHits) {
49 for (
unsigned i_pfp = 0; i_pfp < pfps.size(); i_pfp++) {
50 if (pfp_nhit[i_pfp] >= hits.size() / 2)
return i_pfp;
64 float vert_wf = vhit.
vtxw;
65 float vert_x = vhit.
vtxx;
73 float slope = (hit_x - vert_x) / (hit_w - vert_wf);
74 float intercept = hit_x - slope * hit_w;
80 bool badslope =
abs(hit_w - vert_wf) < 1
e-5;
82 std::vector<art::Ptr<recob::Hit>> ret;
83 for (art::Ptr<recob::Hit>
h: hits) {
84 int this_hit_w =
h->WireID().Wire;
86 if (this_hit_plane == vhit_plane &&
87 this_hit_w == hit_w ) {
88 float h_time_lo =
h->PeakTime() -
h->RMS();
89 float h_time_hi =
h->PeakTime() +
h->RMS();
100 int vert_w = (int)((hit_w > vert_wf) ? std::floor(vert_wf) : std::ceil(vert_wf));
101 hit_w = hit_w + ((hit_w > vert_wf) ? 1 : -1);
104 std::vector<art::Ptr<recob::Hit>> ret;
105 for (art::Ptr<recob::Hit>
h: hits) {
106 int this_hit_w =
h->WireID().Wire;
108 if (this_hit_plane == vhit_plane &&
109 ((this_hit_w <= hit_w && this_hit_w >= vert_w) ||
110 (this_hit_w >= hit_w && this_hit_w <= vert_w))) {
111 float this_proj_x = slope * this_hit_w + intercept;
113 float h_time_lo =
h->PeakTime() -
h->RMS();
115 float h_time_hi =
h->PeakTime() +
h->RMS();
118 if ((h_x_A >= this_proj_x && h_x_B <= this_proj_x) ||
119 (h_x_A <= this_proj_x && h_x_B >= this_proj_x)) {
139 art::Handle<std::vector<recob::Slice>> slice_handle;
140 e.getByLabel(pfplabel, slice_handle);
142 std::vector<art::Ptr<recob::Slice>>
slices;
143 art::fill_ptr_vector(slices, slice_handle);
145 art::FindManyP<recob::PFParticle> slicePFPs(slices, e, pfplabel);
146 art::FindManyP<recob::Hit> sliceHits(slices, e, pfplabel);
148 for (
unsigned i_slc = 0; i_slc < slices.size(); i_slc++) {
149 const std::vector<art::Ptr<recob::PFParticle>> thisSlicePFPs = slicePFPs.at(i_slc);
150 art::FindManyP<recob::Cluster> pfparticleClusters(thisSlicePFPs, e, pfplabel);
152 std::vector<art::Ptr<recob::Track>> thisSliceTracks;
153 std::vector<std::vector<art::Ptr<recob::Hit>>> thisSlicePFPHits;
154 std::vector<std::vector<art::Ptr<recob::Hit>>> thisSliceTrkHits;
155 std::vector<std::vector<const recob::TrackHitMeta *>> thisSliceTrkTHMs;
157 art::FindManyP<recob::Track> pfparticleTracks(thisSlicePFPs, e, trklabel);
158 for (
unsigned i_slc_pfp = 0; i_slc_pfp < thisSlicePFPs.size(); i_slc_pfp++) {
159 thisSlicePFPHits.emplace_back();
160 const std::vector<art::Ptr<recob::Cluster>> &thisPFPClusters = pfparticleClusters.at(i_slc_pfp);
161 art::FindManyP<recob::Hit> clusterHits(thisPFPClusters, e, pfplabel);
162 for (
unsigned i_clus = 0; i_clus < thisPFPClusters.size(); i_clus++) {
163 thisSlicePFPHits.back().insert(thisSlicePFPHits.back().end(), clusterHits.at(i_clus).begin(), clusterHits.at(i_clus).end());
166 art::FindManyP<recob::Hit, recob::TrackHitMeta> FMthisTrackHits(pfparticleTracks.at(i_slc_pfp),
e, trklabel);
167 if (pfparticleTracks.at(i_slc_pfp).size()) {
168 const std::vector<art::Ptr<recob::Hit>> &thisTrackHits = FMthisTrackHits.at(0);
169 const std::vector<const recob::TrackHitMeta *> &thisTrackTHMs = FMthisTrackHits.data(0);
170 thisSliceTrkHits.push_back(thisTrackHits);
171 thisSliceTrkTHMs.push_back(thisTrackTHMs);
172 thisSliceTracks.push_back(pfparticleTracks.at(i_slc_pfp).at(0));
175 thisSliceTrkHits.emplace_back();
176 thisSliceTrkTHMs.emplace_back();
177 thisSliceTracks.emplace_back();
182 std::size_t
const sliceKey = slices[i_slc].key();
198 if (fNormTools.size()) {
199 for (
auto const &nt: fNormTools) {
200 ret = nt->Normalize(ret, e, h, location, direction, t0);
205 auto const clock_data = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e);
207 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(e, clock_data);
209 ret = ret * fCaloAlg.LifetimeCorrection(clock_data, dprop, h.
PeakTime(), 0.);
224 art::Ptr<recob::PFParticle> &stub_pfp) {
226 const std::vector<art::Ptr<recob::Hit>> &hits = fSliceHits.at(slice.key());
227 const std::vector<art::Ptr<recob::PFParticle>> &pfps = fSlicePFPs.at(slice.key());
228 const std::vector<art::Ptr<recob::Track>> &trks = fSliceTrks.at(slice.key());
229 const std::vector<std::vector<art::Ptr<recob::Hit>>> &pfp_hits = fSlicePFPHits.at(slice.key());
230 const std::vector<std::vector<art::Ptr<recob::Hit>>> &trk_hits = fSliceTrkHits.at(slice.key());
231 const std::vector<std::vector<const recob::TrackHitMeta *>> &trk_thms = fSliceTrkTHMs.at(slice.key());
233 stub_hits =
CollectHits(hits, vhit, vhit_hit, geo, dprop);
236 float vertex_w = vhit.
vtxw;
237 int stubdir = vertex_w <= vhit_hit.
WireID().
Wire ? 1 : -1;
238 std::sort(stub_hits.begin(), stub_hits.end(),
239 [stubdir](
auto const &lhs,
auto const &rhs) {
240 return lhs->WireID().Wire * stubdir < rhs->WireID().Wire * stubdir;});
243 int pfp_ind =
FindPFPInd(stub_hits, pfps, pfp_hits);
244 art::Ptr<recob::PFParticle> null;
245 stub_pfp = (pfp_ind >= 0) ? pfps[pfp_ind] : null;
250 stub.
hits.emplace_back();
251 for (
unsigned i_hit = 0; i_hit < stub_hits.size(); i_hit++) {
261 stubhit.
ontrack = (pfp_ind >= 0) ?
HitOnTrack(stub_hits[i_hit], trks[pfp_ind], trk_hits[pfp_ind], trk_thms[pfp_ind]) :
false;
262 stubhit.
wire = hit.WireID().Wire;
264 stub.
hits.back().push_back(stubhit);
268 if (pfp_ind >= 0 && trks[pfp_ind]) {
269 stub.
trkpitch.push_back(
sbn::GetPitch(geo, sce, trks[pfp_ind]->Start(), trks[pfp_ind]->StartDirection(), geo->
View(vhit_hit.
WireID()), vhit_hit.
WireID(),
true, fPositionsAreSCECorrected));
280 stub.
vtx_w.push_back(vertex_w);
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
float dqdx
charge/pitch [#elec/cm]
double Normalize(double dQdx, const art::Event &e, const recob::Hit &h, const geo::Point_t &location, const geo::Vector_t &direction, double t0)
std::map< unsigned, std::vector< art::Ptr< recob::PFParticle > > > fSlicePFPs
std::map< unsigned, std::vector< std::vector< art::Ptr< recob::Hit > > > > fSliceTrkHits
geo::Point_t spXYZ
3D location of the SpacePoint associated with this hit. Space charge corrected. [cm] ...
std::vector< geo::PlaneID > plane
The plane ID.
void Setup(const art::Event &e, const art::InputTag &pfplabel, const art::InputTag &trklabel)
geo::WireID WireID() const
geo::WireID wire
Wire that the hit is on.
float charge
Calibrated and corrected for electron lifetime [#elec].
std::vector< std::vector< StubHit > > hits
Hits on each plane. Ordered vtx->end.
The data type to uniquely identify a Plane.
geo::Point_t end
End of Stub. Space charge corrected. [cm].
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
WireID_t Wire
Index of the wire within its plane.
geo::Point_t vtx
Interaction Vertex / Start of Stub. Space charge corrected. [cm].
float charge
Calibrated and lifetime-corrected charge on the hit [#elec].
std::vector< float > vtx_w
Wire coordinate of the vertex on this plane.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
short wire
The wire this hit is on.
std::map< unsigned, std::vector< std::vector< art::Ptr< recob::Hit > > > > fSlicePFPHits
std::vector< art::Ptr< recob::Hit > > CollectHits(const std::vector< art::Ptr< recob::Hit >> &hits, const sbn::VertexHit &vhit, const recob::Hit &vhit_hit, const geo::GeometryCore *geo, const detinfo::DetectorPropertiesData &dprop)
std::vector< short > hit_w
Wire of the end point hit on this plane.
double GetPitch(const geo::GeometryCore *geo, const spacecharge::SpaceCharge *sce, geo::Point_t loc, geo::Vector_t dir, geo::View_t view, geo::TPCID tpc, bool correct_sce, bool track_is_sce_corrected, float xsign=1.)
Computes the track-pitch on a plane given an input direction and location.
Description of geometry of one entire detector.
float vtxx
X-Position of the vertex associated with this hit as seen by wire-planes. Not space charge corrected...
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
float efield_end
The E-Field at the stub end point.
float efield_vtx
The E-Field at the reconstructed vertex.
bool HitOnTrack(const art::Ptr< recob::Hit > &hit, const art::Ptr< recob::Track > &trk, const std::vector< art::Ptr< recob::Hit >> &trk_hits, const std::vector< const recob::TrackHitMeta * > &trk_thms)
std::vector< TCSlice > slices
std::map< unsigned, std::vector< std::vector< const recob::TrackHitMeta * > > > fSliceTrkTHMs
double ConvertTicksToX(double ticks, int p, int t, int c) const
float PeakTime() const
Time of the signal peak, in tick units.
Contains all timing reference information for the detector.
sbn::Stub FromVertexHit(const art::Ptr< recob::Slice > &slice, const sbn::VertexHit &vhit, const recob::Hit &vhit_hit, const geo::GeometryCore *geo, const spacecharge::SpaceCharge *sce, const detinfo::DetectorClocksData &dclock, const detinfo::DetectorPropertiesData &dprop, const art::Event &e, std::vector< art::Ptr< recob::Hit >> &stub_hits, art::Ptr< recob::PFParticle > &stub_pfp)
std::map< unsigned, std::vector< art::Ptr< recob::Hit > > > fSliceHits
double GetEfield(const detinfo::DetectorPropertiesData &dprop, const spacecharge::SpaceCharge *sce, geo::Point_t loc, geo::TPCID TPC, bool correct_loc_sce, float xsign=1.)
Get the E-Field in the presence of space charge.
int FindPFPInd(const std::vector< art::Ptr< recob::Hit >> &hits, const std::vector< art::Ptr< recob::PFParticle >> &pfps, const std::vector< std::vector< art::Ptr< recob::Hit >>> &pfp_hits)
std::vector< float > trkpitch
Pitch of the matched track on each wire [cm].
2D representation of charge deposited in the TDC/wire plane
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
std::vector< float > pitch
Pitch of stub on each wire [cm].
bool ontrack
Whether the hit is also on a track.
std::map< unsigned, std::vector< art::Ptr< recob::Track > > > fSliceTrks
geo::Point_t vtxXYZ
3D location of the Vertex associated with this hit. Space charge corrected. [cm]
float vtxw
Wire of the vertex associated with this hit. Not space charge corrected. [cm].