368 timeStamp=timingHandle->at(0).GetTimeStamp();
373 auto const* SCE = lar::providerFrom<spacecharge::SpaceChargeService>();
382 if(timeStamp.GetFlags()!= 13)
return;}
398 cout <<
"Getting triggers" <<
endl;
399 const auto & triggers =
event.getValidHandle < std::vector < CRT::Trigger >> (
fCRTLabel);
401 art::FindManyP < sim::AuxDetSimChannel > trigToSim(triggers,
event,
fCRTLabel);
409 std::unordered_map < size_t, double > prevTimes;
411 cout <<
"Looking for hits in Triggers" <<
endl;
414 for (
const auto &
trigger: * triggers) {
415 const auto & hits =
trigger.Hits();
416 for (
const auto &
hit: hits) {
423 tHits.module =
trigger.Channel();
424 tHits.channel=
hit.Channel();
425 tHits.adc =
hit.ADC();
429 tHits.module =
trigger.Channel();
430 tHits.channel=
hit.Channel();
431 tHits.adc =
hit.ADC();
432 tHits.triggerTime=
trigger.Timestamp();
436 tHits.triggerNumber=trigID;
437 const auto & trigGeo = geom -> AuxDet(
trigger.Channel());
438 const auto & csens = trigGeo.SensitiveVolume(
hit.Channel());
439 const auto center = csens.GetCenter();
448 cout <<
"Hits compiled for event: " <<
nEvents <<
endl;
449 cout <<
"Number of Hits above Threshold: " << hitID <<
endl;
452 for (
unsigned int f_test = 0; f_test <
tempHits_F.size(); f_test++) {
454 const auto & trigGeo = geom -> AuxDet(
tempHits_F[
f].module);
455 const auto & trigGeo2 = geom -> AuxDet(
tempHits_F[f_test].module);
458 const auto hit1Center = hit1Geo.GetCenter();
460 const auto & hit2Geo = trigGeo2.SensitiveVolume(
tempHits_F[f_test].channel);
461 const auto hit2Center = hit2Geo.GetCenter();
466 double hitX = hit1Center.X();
471 double hitYPrelim=hit2Center.Y();
479 double hitY=hitYPrelim;
480 double hitZ = (hit1Center.Z() + hit2Center.Z()) / 2.
f;
483 rHits.hitPositionX = hitX;
484 rHits.hitPositionY = hitY;
485 rHits.hitPositionZ = hitZ;
494 rHits.trigNumberY=
tempHits_F[f_test].triggerNumber;
501 for (
unsigned int f_test = 0; f_test <
tempHits_B.size(); f_test++) {
504 const auto & trigGeo = geom -> AuxDet(
tempHits_B[
f].module);
505 const auto & trigGeo2 = geom -> AuxDet(
tempHits_B[f_test].module);
506 const auto & hit1Geo = trigGeo.SensitiveVolume(
tempHits_B[
f].channel);
507 const auto hit1Center = hit1Geo.GetCenter();
509 const auto & hit2Geo = trigGeo2.SensitiveVolume(
tempHits_B[f_test].channel);
510 const auto hit2Center = hit2Geo.GetCenter();
515 double hitX = hit1Center.X();
523 double hitYPrelim = hit2Center.Y();
529 double hitY=hitYPrelim;
532 double hitZ = (hit1Center.Z() + hit2Center.Z()) / 2.
f;
535 rHits.hitPositionX = hitX;
536 rHits.hitPositionY = hitY;
537 rHits.hitPositionZ = hitZ;
545 rHits.trigNumberY=
tempHits_B[f_test].triggerNumber;
556 vector < art::Ptr < recob::Track > > trackList;
557 auto trackListHandle =
event.getHandle < vector < recob::Track > >(
fTrackModuleLabel);
558 if (trackListHandle) {
562 vector<art::Ptr<recob::PFParticle> > pfplist;
563 auto PFPListHandle =
event.getHandle< std::vector<recob::PFParticle> >(
"pandora");
566 if (pfplist.size()<1)
return;
567 art::FindManyP<anab::T0> trk_t0_assn_v(PFPListHandle,
event ,
"pandora");
568 art::FindManyP<recob::PFParticle> pfp_trk_assn(trackListHandle,
event,
"pandoraTrack");
570 art::FindManyP<recob::Hit> trackHits(trackListHandle,
event,
"pandoraTrack");
571 int nTracksReco = trackList.size();
573 std::vector<art::Ptr<recob::Hit>> hitlist;
574 auto hitListHandle =
event.getHandle< std::vector<recob::Hit> >(
"hitpdune");
582 art::FindManyP<anab::Calorimetry> fmcal(trackListHandle,
event,
"pandoracalo");
585 for (
int iRecoTrack = 0; iRecoTrack < nTracksReco; ++iRecoTrack) {
586 if (pfplist.size()<1)
break;
587 std::vector< art::Ptr<recob::Hit> > allHits = hitsFromTrack.at(iRecoTrack);
592 std::vector<art::Ptr<recob::PFParticle>> pfps=pfp_trk_assn.at(iRecoTrack);
593 if(!pfps.size())
continue;
594 std::vector<art::Ptr<anab::T0>> t0s=trk_t0_assn_v.at(pfps[0].
key());
606 double trackStartPositionZ_noSCE = trackList[iRecoTrack]->Vertex().Z();
607 double trackEndPositionZ_noSCE = trackList[iRecoTrack] ->
End().Z();
609 double trackStartPositionX_notCorrected = trackList[iRecoTrack]->Vertex().X();
610 double trackStartPositionY_noSCE = trackList[iRecoTrack]->Vertex().Y();
613 double trackEndPositionX_notCorrected = trackList[iRecoTrack] ->
End().X();
614 double trackEndPositionY_noSCE = trackList[iRecoTrack] ->
End().Y();
618 if (trackStartPositionZ_noSCE>trackEndPositionZ_noSCE){
619 trackEndPositionZ_noSCE = trackList[iRecoTrack]->Vertex().Z();
620 trackStartPositionZ_noSCE = trackList[iRecoTrack] ->
End().Z();
621 trackEndPositionX_notCorrected = trackList[iRecoTrack]->Vertex().X();
622 trackEndPositionY_noSCE = trackList[iRecoTrack]->Vertex().Y();
625 trackStartPositionX_notCorrected=trackList[iRecoTrack] ->
End().X();
626 trackStartPositionY_noSCE = trackList[iRecoTrack] ->
End().Y();
637 if ((trackEndPositionZ_noSCE > 660 && trackStartPositionZ_noSCE < 50) || (trackStartPositionZ_noSCE > 660 && trackEndPositionZ_noSCE < 50)) {
640 double min_delta = DBL_MAX;
641 double best_XF = DBL_MAX;
642 double best_YF = DBL_MAX;
643 double best_ZF = DBL_MAX;
644 double best_XB = DBL_MAX;
645 double best_YB = DBL_MAX;
646 double best_ZB = DBL_MAX;
647 double best_dotProductCos = DBL_MAX;
648 double best_deltaXF = DBL_MAX;
649 double best_deltaYF = DBL_MAX;
650 double best_deltaXB = DBL_MAX;
651 double best_deltaYB = DBL_MAX;
652 double best_T=DBL_MAX;
653 int bestHitIndex_F=0;
654 int bestHitIndex_B=0;
683 double trackStartPositionX_noSCE=trackStartPositionX_notCorrected;
684 double trackEndPositionX_noSCE=trackEndPositionX_notCorrected;
689 double ticksOffset=0;
691 if (!
fMCCSwitch) ticksOffset = (t0+RDOffset)/25.
f+detProp.GetXTicksOffset(allHits[firstHit]->WireID().Plane, allHits[firstHit]->WireID().TPC, allHits[firstHit]->WireID().Cryostat);
693 else if (
fMCCSwitch) ticksOffset = (t0/500.f)+detProp.GetXTicksOffset(allHits[firstHit]->WireID().Plane, allHits[firstHit]->WireID().TPC, allHits[firstHit]->WireID().Cryostat);
695 xOffset=detProp.ConvertTicksToX(ticksOffset,allHits[firstHit]->
WireID().
Plane, allHits[firstHit]->
WireID().
TPC, allHits[firstHit]->
WireID().Cryostat);
698 trackStartPositionX_noSCE=trackStartPositionX_notCorrected-xOffset;
699 trackEndPositionX_noSCE=trackEndPositionX_notCorrected-xOffset;
703 double trackStartPositionX=trackStartPositionX_noSCE;
704 double trackStartPositionY=trackStartPositionY_noSCE;
705 double trackStartPositionZ=trackStartPositionZ_noSCE;
707 double trackEndPositionX=trackEndPositionX_noSCE;
708 double trackEndPositionY=trackEndPositionY_noSCE;
709 double trackEndPositionZ=trackEndPositionZ_noSCE;
713 trackStartPositionX -= posOffsets_F.X();
714 trackStartPositionY += posOffsets_F.Y();
715 trackStartPositionZ += posOffsets_F.Z();
717 trackEndPositionX -= posOffsets_B.X();
718 trackEndPositionY += posOffsets_B.Y();
719 trackEndPositionZ += posOffsets_B.Z();
728 TVector3 trackStart(trackStartPositionX, trackStartPositionY, trackStartPositionZ);
729 TVector3 trackEnd(trackEndPositionX, trackEndPositionY, trackEndPositionZ);
730 TVector3 v1(X1,Y1,Z1);
731 TVector3 v2(X2, Y2, Z2);
733 TVector3 v4(trackStartPositionX,
735 trackStartPositionZ);
736 TVector3 v5(trackEndPositionX,
739 TVector3 trackVector = (v5-v4).Unit();
740 TVector3 hitVector=(v2-v1).Unit();
745 double predictedHitPositionY1 = (v1.Z()-v5.Z())/(v4.Z()-v5.Z())*(v4.Y()-v5.Y())+v5.Y();
746 double predictedHitPositionY2 = (v2.Z()-v5.Z())/(v4.Z()-v5.Z())*(v4.Y()-v5.Y())+v5.Y();
748 double predictedHitPositionX1 = (v1.Z()-v5.Z())/(v4.Z()-v5.Z())*(v4.X()-v5.X())+v5.X();
749 double predictedHitPositionX2 = (v2.Z()-v5.Z())/(v4.Z()-v5.Z())*(v4.X()-v5.X())+v5.X();
751 double dotProductCos=trackVector*hitVector;
753 double deltaX1 = (predictedHitPositionX1-X1);
754 double deltaX2 = (predictedHitPositionX2-X2);
756 double deltaY1 = (predictedHitPositionY1-Y1);
758 double deltaY2 = (predictedHitPositionY2-Y2);
773 best_dotProductCos = dotProductCos;
775 best_deltaXF = deltaX1;
776 best_deltaYF = deltaY1;
777 best_deltaXB = deltaX2;
778 best_deltaYB = deltaY2;
793 X_F=best_XF;
Y_F=best_YF;
Z_F=best_ZF;
X_B=best_XB;
Y_B=best_YB;
Z_B=best_ZB;
int f=bestHitIndex_F;
int b=bestHitIndex_B;
800 double trackStartPositionX_noSCE=trackStartPositionX_notCorrected;
801 double trackEndPositionX_noSCE=trackEndPositionX_notCorrected;
804 double ticksOffset=0;
807 ticksOffset=t0/500.f+detProp.GetXTicksOffset(allHits[firstHit]->
WireID().
Plane, allHits[firstHit]->
WireID().
TPC, allHits[firstHit]->
WireID().Cryostat);
809 xOffset=detProp.ConvertTicksToX(ticksOffset,allHits[firstHit]->
WireID().
Plane, allHits[firstHit]->
WireID().
TPC, allHits[firstHit]->
WireID().Cryostat);
811 trackStartPositionX_noSCE=trackStartPositionX_notCorrected-xOffset;
812 trackEndPositionX_noSCE=trackEndPositionX_notCorrected-xOffset;
816 double trackStartPositionX=trackStartPositionX_noSCE;
817 double trackStartPositionY=trackStartPositionY_noSCE;
818 double trackStartPositionZ=trackStartPositionZ_noSCE;
820 double trackEndPositionX=trackEndPositionX_noSCE;
821 double trackEndPositionY=trackEndPositionY_noSCE;
822 double trackEndPositionZ=trackEndPositionZ_noSCE;
825 TVector3 trackStart(trackStartPositionX, trackStartPositionY, trackStartPositionZ);
826 TVector3 trackEnd(trackEndPositionX, trackEndPositionY, trackEndPositionZ);
829 tPair.tempId = tempId;
830 tPair.recoId = iRecoTrack;
837 tPair.dotProductCos=best_dotProductCos;
859 tPair.endTPC=allHits[0]->WireID().TPC;
861 tPair.xOffset=xOffset;
863 tPair.trackStartPosition=trackStart;
864 tPair.trackEndPosition=trackEnd;
866 if (t0s.empty()) tPair.pandoraT0Check=0;
867 else tPair.pandoraT0Check=1;
883 vector < tracksPair > allUniqueTracksPair;
890 cout<<
"Number of reco and CRT pairs: "<<allUniqueTracksPair.size()<<
endl;
892 if (allUniqueTracksPair.size() > 0) {
893 for (
unsigned int u = 0; u < allUniqueTracksPair.size(); u++) {
894 trackID = allUniqueTracksPair[u].recoId;
899 deltaX_F=allUniqueTracksPair[u].deltaX_F;
900 deltaX_B=allUniqueTracksPair[u].deltaX_B;
901 deltaY_F=allUniqueTracksPair[u].deltaY_F;
902 deltaY_B=allUniqueTracksPair[u].deltaY_B;
903 dotCos=allUniqueTracksPair[u].dotProductCos;
904 trackX1=allUniqueTracksPair[u].trackStartPosition.X();
905 trackY1=allUniqueTracksPair[u].trackStartPosition.Y();
906 trackZ1=allUniqueTracksPair[u].trackStartPosition.Z();
908 trackX2=allUniqueTracksPair[u].trackEndPosition.X();
909 trackY2=allUniqueTracksPair[u].trackEndPosition.Y();
910 trackZ2=allUniqueTracksPair[u].trackEndPosition.Z();
912 moduleX_F=allUniqueTracksPair[u].moduleX1;
913 moduleX_B=allUniqueTracksPair[u].moduleX2;
914 moduleY_F=allUniqueTracksPair[u].moduleY1;
915 moduleY_B=allUniqueTracksPair[u].moduleY2;
917 adcX_F=allUniqueTracksPair[u].adcX1;
918 adcY_F=allUniqueTracksPair[u].adcY1;
919 adcX_B=allUniqueTracksPair[u].adcX2;
920 adcY_B=allUniqueTracksPair[u].adcY2;
922 stripX_F=allUniqueTracksPair[u].stripX1;
923 stripX_B=allUniqueTracksPair[u].stripX2;
924 stripY_F=allUniqueTracksPair[u].stripY1;
925 stripY_B=allUniqueTracksPair[u].stripY2;
927 X_F=allUniqueTracksPair[u].X1;
928 Y_F=allUniqueTracksPair[u].Y1;
929 Z_F=allUniqueTracksPair[u].Z1;
931 X_B=allUniqueTracksPair[u].X2;
932 Y_B=allUniqueTracksPair[u].Y2;
933 Z_B=allUniqueTracksPair[u].Z2;
935 endTPC=allUniqueTracksPair[u].endTPC;
938 mccT0=allUniqueTracksPair[u].mccT0;
941 CRT_TOF=allUniqueTracksPair[u].timeDiff;
960 const size_t lastPoint=trackList[iRecoTrack]->NumberTrajectoryPoints();
961 for (
size_t trackpoint = 0; trackpoint < lastPoint; ++trackpoint) {
962 double trackPosX=trackList[iRecoTrack] -> LocationAtPoint(trackpoint).X()-
measuredXOffset;
963 double trackPosY=trackList[iRecoTrack] -> LocationAtPoint(trackpoint).Y();
964 double trackPosZ=trackList[iRecoTrack] -> LocationAtPoint(trackpoint).Z();
966 if (trackPosY==-999)
continue;
967 if (trackPosX==-999)
continue;
968 TVector3 trackPos(trackPosX, trackPosY, trackPosZ);
993 std::vector<art::Ptr<anab::Calorimetry>> calos=fmcal.at(iRecoTrack);
995 for(
size_t ical = 0; ical<calos.size(); ++ical){
996 if (calos[ical]->
PlaneID().Plane!=2)
continue;
998 const size_t NHits=calos[ical]->dEdx().size();
999 for(
size_t iHit = 0; iHit < NHits; ++iHit){
1001 const auto& TrkPos = (calos[ical] -> XYZ()[iHit]);
1003 trkdqdx=(calos[ical]->dQdx()[iHit]);
1004 size_t tpIndex=(calos[ical]->TpIndices()[iHit]);
1005 if (hitlist[tpIndex]->Multiplicity()>1)
continue;
1006 trkhitt0=hitlist[tpIndex]->PeakTime()*500.f;
1008 crtt0=allUniqueTracksPair[u].t0;
1012 WireID=hitlist[tpIndex]->WireID().Wire;
1013 TPCID=hitlist[tpIndex]->WireID().TPC;
1014 sumADC=hitlist[tpIndex]->SummedADC();
1015 sigmaHit=hitlist[tpIndex]->SigmaIntegral();
1016 rangeTime=hitlist[tpIndex]->EndTick()-hitlist[tpIndex]->StartTick();
code to link reconstructed objects back to the MC truth information
double averageSignedDistanceYZ
double signedPointToLineDistance(double firstPoint1, double firstPoint2, double secondPoint1, double secondPoint2, double trackPoint1, double trackPoint2)
double averageSignedDistanceXZ
double averageSignedDistance
std::string fTrackModuleLabel
bool moduleMatcher(int module1, int module2)
geo::TPCID PositionToTPCID(geo::Point_t const &point) const
Returns the ID of the TPC at specified location.
int fModuletoModuleTimingCut
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
Detector simulation of raw signals on wires.
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
std::vector< tempHits > tempHits_F
std::vector< recoHits > primaryHits_B
double signed3dDistance(double firstPoint1, double firstPoint2, double firstPoint3, double secondPoint1, double secondPoint2, double secondPoint3, TVector3 trackPos)
std::vector< tracksPair > allTracksPair
std::vector< tempHits > tempHits_B
constexpr auto const & deepestIndex() const
Returns the value of the deepest ID available (TPC's).
detail::Node< FrameID, bool > PlaneID
int fFronttoBackTimingCut
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
recob::tracking::Plane Plane
std::vector< recoHits > primaryHits_F
QTextStream & endl(QTextStream &s)
Event finding and building.