29 #include "canvas/Persistency/Common/FindManyP.h" 30 #include "art_root_io/TFileService.h" 37 #include "nug4/ParticleNavigation/ParticleList.h" 82 class TwoCRTMatchingProducer;
96 bool moduleMatcher(
int module1,
int module2);
151 consumes < std::vector < CRT::Trigger >> (
fCRTLabel);
152 consumes < std::vector < art::Assns < sim::AuxDetSimChannel, CRT::Trigger >>> (
fCRTLabel);
153 produces< std::vector<anab::T0> >();
155 produces< std::vector<anab::CosmicTag> >();
156 produces< art::Assns<recob::Track, anab::T0> >();
157 produces< art::Assns<recob::Track, anab::CosmicTag> >();
158 produces< art::Assns<CRT::Trigger, anab::CosmicTag> >();
166 if ((module1 == 6 && (module2 == 10 || module2 == 11)) || (module1 == 14 && (module2 == 10 || module2 == 11)) || (module1 == 19 && (module2 == 26 || module2 == 27)) || (module1 == 31 && (module2 == 26 || module2 == 27)) || (module1 == 7 && (module2 == 12 || module2 == 13)) || (module1 == 15 && (module2 == 12 || module2 == 13)) || (module1 == 18 && (module2 == 24 || module2 == 25)) || (module1 == 30 && (module2 == 24 || module2 == 25)) || (module1 == 1 && (module2 == 4 || module2 == 5)) || (module1 == 9 && (module2 == 4 || module2 == 5)) || (module1 == 16 && (module2 == 20 || module2 == 21)) || (module1 == 28 && (module2 == 20 || module2 == 21)) || (module1 == 0 && (module2 == 2 || module2 == 3)) || (module1 == 8 && (module2 == 2 || module2 == 3)) || (module1 == 17 && (module2 == 22 || module2 == 23)) || (module1 == 29 && (module2 == 22 || module2 == 23)))
return 1;
175 bool fMCCSwitch=!
event.isRealData();
177 std::unique_ptr< std::vector<anab::T0> > T0col(
new std::vector<anab::T0>);
178 auto CRTTrack=std::make_unique< std::vector< anab::CosmicTag > > ();
200 timeStamp=timingHandle->at(0).GetTimeStamp();
215 vector < art::Ptr < CRT::Trigger > > crtList;
216 auto crtListHandle =
event.getHandle < vector < CRT::Trigger > >(
fCRTLabel);
220 const auto & triggers =
event.getValidHandle < std::vector < CRT::Trigger >> (
fCRTLabel);
222 art::FindManyP < sim::AuxDetSimChannel > trigToSim(triggers, event,
fCRTLabel);
227 auto const* SCE = lar::providerFrom<spacecharge::SpaceChargeService>();
230 std::unordered_map < size_t, double > prevTimes;
234 for (
const auto &
trigger: * triggers) {
235 const auto & hits =
trigger.Hits();
236 for (
const auto &
hit: hits) {
257 const auto & trigGeo = geom -> AuxDet(
trigger.Channel());
258 const auto & csens = trigGeo.SensitiveVolume(
hit.Channel());
259 const auto center = csens.GetCenter();
272 for (
unsigned int f_test = 0; f_test <
tempHits_F.size(); f_test++) {
274 const auto & trigGeo = geom -> AuxDet(
tempHits_F[
f].module);
275 const auto & trigGeo2 = geom -> AuxDet(
tempHits_F[f_test].module);
278 const auto hit1Center = hit1Geo.GetCenter();
280 const auto & hit2Geo = trigGeo2.SensitiveVolume(
tempHits_F[f_test].channel);
281 const auto hit2Center = hit2Geo.GetCenter();
286 double hitX = hit1Center.X();
291 double hitYPrelim=hit2Center.Y();
299 double hitY=hitYPrelim;
300 double hitZ = (hit1Center.Z() + hit2Center.Z()) / 2.
f;
314 for (
unsigned int f_test = 0; f_test <
tempHits_B.size(); f_test++) {
317 const auto & trigGeo = geom -> AuxDet(
tempHits_B[
f].module);
318 const auto & trigGeo2 = geom -> AuxDet(
tempHits_B[f_test].module);
320 const auto hit1Center = hit1Geo.GetCenter();
322 const auto & hit2Geo = trigGeo2.SensitiveVolume(
tempHits_B[f_test].channel);
323 const auto hit2Center = hit2Geo.GetCenter();
328 double hitX = hit1Center.X();
336 double hitYPrelim = hit2Center.Y();
342 double hitY=hitYPrelim;
345 double hitZ = (hit1Center.Z() + hit2Center.Z()) / 2.
f;
359 vector < art::Ptr < recob::Track > > trackList;
360 auto trackListHandle =
event.getHandle < vector < recob::Track > >(
fTrackModuleLabel);
361 if (trackListHandle) {
369 vector<art::Ptr<recob::PFParticle> > pfplist;
370 auto PFPListHandle =
event.getHandle< std::vector<recob::PFParticle> >(
"pandora");
372 if(pfplist.size()<1)
return;
373 art::FindManyP<anab::T0> trk_t0_assn_v(PFPListHandle, event ,
"pandora");
374 art::FindManyP<recob::PFParticle> pfp_trk_assn(trackListHandle,event,
"pandoraTrack");
375 int nTracksReco = trackList.size();
376 art::FindManyP < recob::Hit > hitsFromTrack(trackListHandle, event,
fTrackModuleLabel);
378 for (
int iRecoTrack = 0; iRecoTrack < nTracksReco; ++iRecoTrack) {
379 std::vector< art::Ptr<recob::Hit> > allHits = hitsFromTrack.at(iRecoTrack);
383 std::vector<art::Ptr<recob::PFParticle>> pfps=pfp_trk_assn.at(iRecoTrack);
384 if(!pfps.size())
continue;
385 std::vector<art::Ptr<anab::T0>> t0s=trk_t0_assn_v.at(pfps[0].
key());
388 double trackStartPositionZ_noSCE = trackList[iRecoTrack]->Vertex().Z();
389 double trackEndPositionZ_noSCE = trackList[iRecoTrack] ->
End().Z();
391 double trackStartPositionX_notCorrected = trackList[iRecoTrack]->Vertex().X();
392 double trackStartPositionY_noSCE = trackList[iRecoTrack]->Vertex().Y();
395 double trackEndPositionX_notCorrected = trackList[iRecoTrack] ->
End().X();
396 double trackEndPositionY_noSCE = trackList[iRecoTrack] ->
End().Y();
399 int lastHit=allHits.size()-2;
400 if (trackStartPositionZ_noSCE>trackEndPositionZ_noSCE){
401 trackEndPositionZ_noSCE = trackList[iRecoTrack]->Vertex().Z();
402 trackStartPositionZ_noSCE = trackList[iRecoTrack] ->
End().Z();
403 trackEndPositionX_notCorrected = trackList[iRecoTrack]->Vertex().X();
404 trackEndPositionY_noSCE = trackList[iRecoTrack]->Vertex().Y();
407 trackStartPositionX_notCorrected=trackList[iRecoTrack] ->
End().X();
408 trackStartPositionY_noSCE = trackList[iRecoTrack] ->
End().Y();
419 if ((trackEndPositionZ_noSCE > 660 && trackStartPositionZ_noSCE < 50) || (trackStartPositionZ_noSCE > 660 && trackEndPositionZ_noSCE < 50)) {
421 double min_delta = DBL_MAX;
422 double best_XF = DBL_MAX;
423 double best_YF = DBL_MAX;
424 double best_ZF = DBL_MAX;
425 double best_XB = DBL_MAX;
426 double best_YB = DBL_MAX;
427 double best_ZB = DBL_MAX;
428 double best_dotProductCos = DBL_MAX;
429 double best_deltaXF = DBL_MAX;
430 double best_deltaYF = DBL_MAX;
431 double best_deltaXB = DBL_MAX;
432 double best_deltaYB = DBL_MAX;
433 double best_T=DBL_MAX;
456 double trackStartPositionX_noSCE=trackStartPositionX_notCorrected;
457 double trackEndPositionX_noSCE=trackEndPositionX_notCorrected;
460 if (!fMCCSwitch) RDOffset=111;
461 double ticksOffset=0;
463 if (!fMCCSwitch) ticksOffset = (t0+RDOffset)/25.
f+detProp.GetXTicksOffset(allHits[firstHit]->WireID().Plane, allHits[firstHit]->WireID().TPC, allHits[firstHit]->WireID().Cryostat);
465 else if (fMCCSwitch) ticksOffset = (t0/500.f)+detProp.GetXTicksOffset(allHits[firstHit]->WireID().Plane, allHits[firstHit]->WireID().TPC, allHits[firstHit]->WireID().Cryostat);
467 xOffset=detProp.ConvertTicksToX(ticksOffset,allHits[firstHit]->
WireID().
Plane, allHits[firstHit]->
WireID().
TPC, allHits[firstHit]->
WireID().Cryostat);
470 trackStartPositionX_noSCE=trackStartPositionX_notCorrected-xOffset;
471 trackEndPositionX_noSCE=trackEndPositionX_notCorrected-xOffset;
474 double trackStartPositionX=trackStartPositionX_noSCE;
475 double trackStartPositionY=trackStartPositionY_noSCE;
476 double trackStartPositionZ=trackStartPositionZ_noSCE;
478 double trackEndPositionX=trackEndPositionX_noSCE;
479 double trackEndPositionY=trackEndPositionY_noSCE;
480 double trackEndPositionZ=trackEndPositionZ_noSCE;
484 trackStartPositionX -= posOffsets_F.X();
485 trackStartPositionY += posOffsets_F.Y();
486 trackStartPositionZ += posOffsets_F.Z();
488 trackEndPositionX -= posOffsets_B.X();
489 trackEndPositionY += posOffsets_B.Y();
490 trackEndPositionZ += posOffsets_B.Z();
499 TVector3 trackStart(trackStartPositionX, trackStartPositionY, trackStartPositionZ);
500 TVector3 trackEnd(trackEndPositionX, trackEndPositionY, trackEndPositionZ);
501 TVector3 v1(X1,Y1,Z1);
502 TVector3 v2(X2, Y2, Z2);
504 TVector3 v4(trackStartPositionX,
506 trackStartPositionZ);
507 TVector3 v5(trackEndPositionX,
510 TVector3 trackVector = (v5-v4).Unit();
511 TVector3 hitVector=(v2-v1).Unit();
516 double predictedHitPositionY1 = (v1.Z()-v5.Z())/(v4.Z()-v5.Z())*(v4.Y()-v5.Y())+v5.Y();
517 double predictedHitPositionY2 = (v2.Z()-v5.Z())/(v4.Z()-v5.Z())*(v4.Y()-v5.Y())+v5.Y();
519 double predictedHitPositionX1 = (v1.Z()-v5.Z())/(v4.Z()-v5.Z())*(v4.X()-v5.X())+v5.X();
520 double predictedHitPositionX2 = (v2.Z()-v5.Z())/(v4.Z()-v5.Z())*(v4.X()-v5.X())+v5.X();
522 double dotProductCos=trackVector*hitVector;
524 double deltaX1 = (predictedHitPositionX1-X1);
525 double deltaX2 = (predictedHitPositionX2-X2);
527 double deltaY1 = (predictedHitPositionY1-Y1);
529 double deltaY2 = (predictedHitPositionY2-Y2);
545 best_dotProductCos = dotProductCos;
546 best_deltaXF = deltaX1;
547 best_deltaYF = deltaY1;
548 best_deltaXB = deltaX2;
549 best_deltaYB = deltaY2;
555 if (!fMCCSwitch) best_T=(111.f+best_T)*20.
f;
564 std::vector<float> hitF;
565 std::vector<float> hitB;
566 hitF.push_back(best_XF); hitF.push_back(best_YF); hitF.push_back(best_ZF);
567 hitB.push_back(best_XB); hitB.push_back(best_YB); hitB.push_back(best_ZB);
571 T0col->push_back(
anab::T0(best_T, 13,2,iRecoTrack,best_dotProductCos));
572 util::CreateAssn(*
this, event, *CRTTrack, trackList[iRecoTrack], *TPCCRTassn);
574 util::CreateAssn(*
this, event, *CRTTrack, crtList[best_trigXF], *CRTTriggerassn);
575 util::CreateAssn(*
this, event, *CRTTrack, crtList[best_trigYF], *CRTTriggerassn);
577 util::CreateAssn(*
this, event, *CRTTrack, crtList[best_trigXB], *CRTTriggerassn);
579 util::CreateAssn(*
this, event, *CRTTrack, crtList[best_trigYB], *CRTTriggerassn);
code to link reconstructed objects back to the MC truth information
std::vector< recoHits > primaryHits_B
bool moduleMatcher(int module1, int module2)
geo::TPCID PositionToTPCID(geo::Point_t const &point) const
Returns the ID of the TPC at specified location.
std::string fTrackModuleLabel
std::vector< recoHits > primaryHits_F
art framework interface to geometry description
#define DEFINE_ART_MODULE(klass)
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
TwoCRTMatchingProducer(fhicl::ParameterSet const &p)
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.
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.
void produce(art::Event &event) override
Declaration of signal hit object.
int fFronttoBackTimingCut
Provides recob::Track data product.
constexpr auto const & deepestIndex() const
Returns the value of the deepest ID available (TPC's).
std::vector< tempHits > tempHits_B
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
recob::tracking::Plane Plane
std::vector< tempHits > tempHits_F
Event finding and building.
int fModuletoModuleTimingCut