230 larprop = lar::providerFrom<detinfo::LArPropertiesService>();
231 detprop = lar::providerFrom<detinfo::DetectorPropertiesService>();
234 std::vector<std::map<int,double> > vtimemap(3);
235 std::vector<std::map<int,art::Ptr<recob::Hit> > > vhitmap(3);
238 for (
size_t ihit = 0; ihit<fHits.size(); ++ihit){
240 unsigned int w = hitWireID.
Wire;
241 unsigned int pl = hitWireID.
Plane;
242 double time = fHits[ihit]->PeakTime();
243 time -= detprop->GetXTicksOffset(fHits[ihit]->WireID().
Plane,
244 fHits[ihit]->WireID().TPC,
245 fHits[ihit]->WireID().Cryostat);
246 vtimemap[pl][
w] = time;
247 vhitmap[pl][
w] = fHits[ihit];
254 unsigned maxnumhits0 = 0;
255 unsigned maxnumhits1 = 0;
257 std::vector<double> tmin(vtimemap.size());
258 std::vector<double> tmax(vtimemap.size());
259 for (
size_t iclu = 0; iclu<vtimemap.size(); ++iclu){
264 for (
size_t iclu = 0; iclu<vtimemap.size(); ++iclu){
265 for (
auto itime = vtimemap[iclu].
begin(); itime!=vtimemap[iclu].end(); ++itime){
266 if (itime->second>tmax[iclu]){
267 tmax[iclu] = itime->second;
269 if (itime->second<tmin[iclu]){
270 tmin[iclu] = itime->second;
273 if (vtimemap[iclu].size()>maxnumhits0){
276 maxnumhits1 = maxnumhits0;
279 maxnumhits0 = vtimemap[iclu].size();
281 else if (vtimemap[iclu].size()>maxnumhits1){
283 maxnumhits1 = vtimemap[iclu].size();
290 for (
int iclu = 0; iclu<(int)vtimemap.size(); ++iclu){
291 if (iclu!=iclu1&&iclu!=iclu2) iclu3 = iclu;
294 if (iclu1!=-1&&iclu2!=-1){
296 auto ihit = vhitmap[iclu1].begin();
297 auto itime = vtimemap[iclu1].begin();
298 while (itime!=vtimemap[iclu1].
end()){
301 vtimemap[iclu1].erase(itime++);
302 vhitmap[iclu1].erase(ihit++);
310 ihit = vhitmap[iclu2].begin();
311 itime = vtimemap[iclu2].begin();
312 while (itime!=vtimemap[iclu2].
end()){
315 vtimemap[iclu2].erase(itime++);
316 vhitmap[iclu2].erase(ihit++);
325 if (!vtimemap[iclu1].size()){
330 if (!vtimemap[iclu2].size()){
336 if ((!vtimemap[iclu1].size())||(!vtimemap[iclu2].size()))
return;
339 auto times1 = vtimemap[iclu1].begin();
340 auto timee1 = vtimemap[iclu1].end();
342 auto times2 = vtimemap[iclu2].begin();
343 auto timee2 = vtimemap[iclu2].end();
346 double ts1 = times1->second;
347 double te1 = timee1->second;
348 double ts2 = times2->second;
349 double te2 = timee2->second;
352 if (std::abs(ts1-ts2)+std::abs(te1-te2)>std::abs(ts1-te2)+std::abs(te1-ts2)){
356 double timetick = detprop->SamplingRate()*1
e-3;
357 double Efield_drift = detprop->Efield(0);
358 double Temperature = detprop->Temperature();
360 double driftvelocity = detprop->DriftVelocity(Efield_drift,Temperature);
361 double timepitch = driftvelocity*timetick;
364 vhitmap[0].
begin()->second->WireID().Plane,
365 vhitmap[0].begin()->second->WireID().TPC,
366 vhitmap[0].begin()->second->WireID().Cryostat);
369 std::vector<double> vtracklength;
370 for (
size_t iclu = 0; iclu<vtimemap.size(); ++iclu){
372 double tracklength = 0;
373 if (vtimemap[iclu].size()==1){
374 tracklength = wire_pitch;
376 else if (!vtimemap[iclu].empty()) {
378 wend = vtimemap[iclu].cend();
379 double t0 = iw->first, w0 = iw->second;
380 while (++iw != wend) {
381 tracklength += std::sqrt(
sqr((iw->first-w0)*wire_pitch)+
sqr((iw->second-t0)*timepitch));
386 vtracklength.push_back(tracklength);
389 std::map<int,int> maxhitsMatch;
391 auto ihit1 = vhitmap[iclu1].begin();
392 for (
auto itime1 = vtimemap[iclu1].
begin();
393 itime1 != vtimemap[iclu1].end();
395 std::vector<art::Ptr<recob::Hit>> sp_hits;
396 sp_hits.push_back(ihit1->second);
397 double hitcoord[3] = {0.,0.,0.};
399 if (vtimemap[iclu1].size()==1){
400 length1 = wire_pitch;
403 for (
auto iw1 = vtimemap[iclu1].
begin(); iw1!=itime1; ++iw1){
406 length1 += std::sqrt(std::pow((iw1->first-iw2->first)*wire_pitch,2)
407 +std::pow((iw1->second-iw2->second)*timepitch,2));
410 double difference = 1e10;
411 auto matchedtime = vtimemap[iclu2].end();
412 auto matchedhit = vhitmap[iclu2].end();
414 auto ihit2 = vhitmap[iclu2].begin();
415 for (
auto itime2 = vtimemap[iclu2].
begin();
416 itime2!=vtimemap[iclu2].end();
418 if (maxhitsMatch[itime2->first])
continue;
420 if (vtimemap[iclu2].size()==1){
421 length2 = wire_pitch;
424 for (
auto iw1 = vtimemap[iclu2].
begin(); iw1!=itime2; ++iw1){
427 length2 += std::sqrt(std::pow((iw1->first-iw2->first)*wire_pitch,2)+std::pow((iw1->second-iw2->second)*timepitch,2));
430 if (rev) length2 = vtracklength[iclu2] - length2;
431 length2 = vtracklength[iclu1]/vtracklength[iclu2]*length2;
432 bool timematch = std::abs(itime1->second-itime2->second)<
ftmatch;
433 if (timematch &&std::abs(length2-length1)<difference){
434 difference = std::abs(length2-length1);
435 matchedtime = itime2;
440 hitcoord[0] = detprop->ConvertTicksToX(matchedtime->second+
441 detprop->GetXTicksOffset((matchedhit->second)->WireID().Plane,
442 (matchedhit->second)->WireID().TPC,
443 (matchedhit->second)->WireID().Cryostat),
444 (matchedhit->second)->WireID().Plane,
445 (matchedhit->second)->WireID().TPC,
446 (matchedhit->second)->WireID().Cryostat);
460 hitcoord[1]=tmpWIDI.
y;
461 hitcoord[2]=tmpWIDI.
z;
464 if (hitcoord[1]>-1e9&&hitcoord[2]>-1e9){
465 maxhitsMatch[matchedtime->first] = 1;
466 sp_hits.push_back(matchedhit->second);
469 if (sp_hits.size()>1){
470 trajPos.push_back(TVector3(hitcoord));
code to link reconstructed objects back to the MC truth information
double z
z position of intersection
double ftmatch
tolerance for time matching (in ticks)
std::vector< TVector3 > trajPos
WireID_t Wire
Index of the wire within its plane.
geo::Length_t WirePitch(geo::PlaneID const &planeid) const
Returns the distance between two consecutive wires.
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
PlaneID_t Plane
Index of the plane within its TPC.
double fsmatch
tolerance for distance matching (in cm)
void swap(art::HLTGlobalStatus &lhs, art::HLTGlobalStatus &rhs)
bool WireIDsIntersect(WireID const &wid1, WireID const &wid2, geo::Point_t &intersection) const
Computes the intersection between two wires.
const detinfo::LArProperties * larprop
double y
y position of intersection
art::ServiceHandle< geo::Geometry > geom
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
recob::tracking::Plane Plane
const detinfo::DetectorProperties * detprop
std::vector< std::vector< art::Ptr< recob::Hit > > > trajHit