1 #ifndef HITFINDERCOUNTER35T_H 2 #define HITFINDERCOUNTER35T_H 30 #include "art_root_io/TFileService.h" 31 #include "art_root_io/TFileDirectory.h" 50 #include "nurandom/RandomUtils/NuRandomService.h" 51 #include "CLHEP/Random/RandomEngine.h" 81 int pnpoly(
int nvert,
float *vertx,
float *verty,
float testx,
float testy );
83 void FindPlaneGradient( std::vector < recob::Hit > HitVector,
float &Gradient,
float& Intercept );
84 void MatrixGradient ( TMatrixD
X, TMatrixD
Y,
size_t MatSize,
float &Gradient,
float &Intercept );
85 double DistToLine (
float Gradient,
float Intercept,
double X,
double Y);
86 std::vector<recob::Hit>
FindUniqueHits( std::vector < recob::Hit >
const GoodHits,
unsigned int Plane,
unsigned int TPC );
90 std::vector < std::pair < std::vector < recob::Hit >,
size_t > > &NewBad,
91 std::vector < std::pair < recob::Hit, size_t > > & NewGood,
size_t HitsSize );
93 std::vector < std::pair < std::vector < recob::Hit >,
size_t > > &InputBadVector,
94 std::vector < std::pair < std::vector < recob::Hit >,
size_t > > &OutputBadVector,
95 std::vector < std::pair < recob::Hit, size_t > > &OutputGoodVector );
97 std::vector < std::pair < std::vector < recob::Hit >,
size_t > > &InputBadVector,
98 std::vector < std::pair < std::vector < recob::Hit >,
size_t > > &OutputBadVector,
99 std::vector < std::pair < recob::Hit, size_t > > &OutputGoodVector );
101 std::vector < std::pair < std::vector < recob::Hit >,
size_t > > &InputBadVector,
102 std::vector < std::pair < std::vector < recob::Hit >,
size_t > > &OutputBadVector,
103 std::vector < std::pair < recob::Hit, size_t > > &OutputGoodVector );
105 std::vector < std::pair < std::vector < recob::Hit >,
size_t > > &InputBadVector,
106 std::vector < std::pair < std::vector < recob::Hit >,
size_t > > &OutputBadVector,
107 std::vector < std::pair < recob::Hit, size_t > > &OutputGoodVector );
142 ,
fDebug (pset.get<
bool>(
"Debug"))
163 double UWireLongDriftStart[3], UWireLongDriftEnd[3], UWireShortDriftStart[3], UWireShortDriftEnd[3];
164 double VWireLongDriftStart[3], VWireLongDriftEnd[3], VWireShortDriftStart[3], VWireShortDriftEnd[3];
177 TwoDLineHist = tfs->make<TH2F>(
"TwoDLineHist",
"Plot of collection plane hit positions in the XZ plane; Z position (cm); X position (cm)", 320, -5, 155, 800, -50, 350 );
191 std::vector< art::Ptr< raw::ExternalTrigger> > trigs;
197 std::vector< art::Ptr< recob::Hit> > hits;
201 auto const* detprop = lar::providerFrom<detinfo::DetectorPropertiesService>();
206 for (
size_t CLoop=0; CLoop < trigs.size(); ++CLoop) {
207 for (
size_t CLoop2=0; CLoop2 < trigs.size(); ++CLoop2) {
208 if ( fabs( trigs[CLoop]->GetTrigTime() - trigs[CLoop2]->GetTrigTime()) >
fCoincidenceTolerance )
continue;
209 if ( CLoop == CLoop2 )
continue;
214 if ( ( trigs[CLoop]->GetTrigID() >= 6 && trigs[CLoop]->GetTrigID() <= 15 && trigs[CLoop2]->GetTrigID() >= 28 && trigs[CLoop2]->GetTrigID() <= 37 )
215 || ( trigs[CLoop]->GetTrigID() <= 5 && trigs[CLoop2]->GetTrigID() >= 22 && trigs[CLoop2]->GetTrigID() <= 27 )
216 || ( trigs[CLoop]->GetTrigID() >= 16 && trigs[CLoop]->GetTrigID() <= 21 && trigs[CLoop2]->GetTrigID() >= 38 && trigs[CLoop2]->GetTrigID() <= 43 )
218 if (
fDebug) std::cout <<
"I have a match..." 219 <<
"CLoop " << CLoop <<
", ID " << trigs[CLoop]->GetTrigID() <<
", time " << trigs[CLoop]->GetTrigTime() <<
"..." 220 <<
"CLoop2 " << CLoop2 <<
", ID " << trigs[CLoop2]->GetTrigID() <<
", Time " << trigs[CLoop2]->GetTrigTime()
236 <<
". They correspond to TrigIDs " << IDA <<
" and " << IDB <<
", and times " << TimeA <<
" (" << TickA <<
") and " << TimeB <<
" (" << TickB <<
")" 242 art::FindOneP<raw::RawDigit> ChannelHitRawDigits (HitListHandle, evt,
fHitsModuleLabel);
243 art::FindOneP<recob::Wire> ChannelHitWires (HitListHandle, evt,
fHitsModuleLabel);
248 ChannelHitWires.isValid(),
249 ChannelHitRawDigits.isValid()
253 std::vector < std::pair < std::vector < recob::Hit >,
size_t > > UnDisambigHits;
270 float VertexX[4] = { (float)it1->second.second[0][0], (
float)it1->second.second[1][0], (float)it2->second.second[1][0], (
float)it2->second.second[0][0]};
271 float VertexY[4] = { (float)it1->second.second[0][1], (
float)it1->second.second[2][1], (float)it2->second.second[2][1], (
float)it2->second.second[0][1]};
272 float VertexZ[4] = { (float)it1->second.second[0][2], (
float)it1->second.second[1][2], (float)it2->second.second[1][2], (
float)it2->second.second[0][2]};
279 if (
fDebug) std::cout <<
"\nCounter1, with TrigID " << trigs.at(
ExternalTrigIndexVec[TrigInd].first)->GetTrigID() <<
" (" << it1->first <<
") has corners......" 280 <<
"( " << it1->second.second[0][0] <<
", " << it1->second.second[0][1] <<
", " << it1->second.second[0][2] <<
") and " 281 <<
"( " << it1->second.second[1][0] <<
", " << it1->second.second[1][1] <<
", " << it1->second.second[1][2] <<
") and " 282 <<
"( " << it1->second.second[2][0] <<
", " << it1->second.second[2][1] <<
", " << it1->second.second[2][2] <<
") and " 283 <<
"( " << it1->second.second[3][0] <<
", " << it1->second.second[3][1] <<
", " << it1->second.second[3][2] <<
") " 284 <<
"\nCounter2, with TrigID " << trigs.at(
ExternalTrigIndexVec[TrigInd].second)->GetTrigID() <<
" (" << it2->first <<
") has corners......" 285 <<
"( " << it2->second.second[0][0] <<
", " << it2->second.second[0][1] <<
", " << it2->second.second[0][2] <<
") and " 286 <<
"( " << it2->second.second[1][0] <<
", " << it2->second.second[1][1] <<
", " << it2->second.second[1][2] <<
") and " 287 <<
"( " << it2->second.second[2][0] <<
", " << it2->second.second[2][1] <<
", " << it2->second.second[2][2] <<
") and " 288 <<
"( " << it2->second.second[3][0] <<
", " << it2->second.second[3][1] <<
", " << it2->second.second[3][2] <<
") " 289 <<
"\nVertexX has co-ords " << VertexX[0] <<
" " << VertexX[1] <<
" " << VertexX[2] <<
" " << VertexX[3]
290 <<
"\nVertexY has co-ords " << VertexY[0] <<
" " << VertexY[1] <<
" " << VertexY[2] <<
" " << VertexY[3]
291 <<
"\nVertexZ has co-ords " << VertexZ[0] <<
" " << VertexZ[1] <<
" " << VertexZ[2] <<
" " << VertexZ[3]
302 float c1x = it1->second.first.X();
303 float c1z = it1->second.first.Z();
304 float c2x = it2->second.first.X();
305 float c2z = it2->second.first.Z();
308 float slope = ((c1x-c2x)/(c1z-c2z));
314 else if (trignum == 112 || trignum == 113)
316 float slope = ((c1z-c2z)/(c1x-c2x));
324 doHitLineFitAlg =
false;
328 std::vector<dune::HitLineFitAlg::HitLineFitData> fitdata;
330 std::map<unsigned int, size_t> index_convert;
331 unsigned int fitdataindex = 0;
336 for(
size_t HitInd = 0; HitInd < hits.size(); HitInd++ ) {
337 if ( hits[HitInd]->PeakTime()-
TrigTime < 0 )
continue;
338 if( hits[HitInd]->View() !=
geo::kZ )
continue;
341 bool KeepHit =
false;
345 double WireStart[3], WireEnd[3];
347 float DriftDist = (0.5 *(hits[HitInd]->PeakTime()-
TrigTime) * fDriftVelocity );
348 if ( hits[HitInd]->WireID().TPC % 2 == 0) {
349 DriftDist = -DriftDist;
351 float HitXPos = DriftDist + WireStart[0];
353 KeepHit =
pnpoly( 4, VertexX, VertexZ, HitXPos, (
float)WireEnd[2] );
371 else if (trignum == 112 || trignum == 113)
374 hlfd.
hitVert = (float)WireEnd[2];
381 fitdata.push_back(hlfd);
382 index_convert[fitdataindex] = HitInd;
392 if (!doHitLineFitAlg)
394 for (
unsigned int i_fd = 0; i_fd < fitdata.size(); ++i_fd)
398 hcol.emplace_back(*hits[index_convert[i_fd]],wire,rawdigits);
401 else if (retval != 1 && doHitLineFitAlg)
403 std::cout <<
"No line fit could be found, or not enough hits in counter shadow to make a line" <<
std::endl;
409 for (
unsigned int i_fd = 0; i_fd < fitdata.size(); ++i_fd)
411 if (fitdata[i_fd].hitREAL)
415 hcol.emplace_back(*hits[index_convert[i_fd]],wire,rawdigits);
420 std::cout <<
"After collection wires for TrigInd " << TrigInd <<
", hcol has size " << hcol.size() <<
std::endl;
425 for(
size_t HitInd = 0; HitInd < hits.size(); HitInd++ ) {
426 if ( hits[HitInd]->PeakTime()-
TrigTime < 0 )
continue;
427 if ( hits[HitInd]->View() ==
geo::kZ )
continue;
432 float DriftDist = (0.5 *(hits[HitInd]->PeakTime()-
TrigTime) * fDriftVelocity );
433 float HitPosShortDrift =
UVStartEndPointsX[ hits[HitInd]->View()*2 ] - DriftDist;
434 float HitPosLongDrift =
UVStartEndPointsX[ 1 + hits[HitInd]->View()*2 ] + DriftDist;
436 bool CouldBeShortDrift =
true;
437 bool CouldBeLongDrift =
true;
438 if ( HitPosShortDrift < SmallestX ) CouldBeShortDrift =
false;
439 if ( HitPosLongDrift > BiggestX ) CouldBeLongDrift =
false;
440 if ( !CouldBeShortDrift && !CouldBeLongDrift )
continue;
451 std::vector< recob::Hit > TempHitsVec;
452 int Channel = hits[HitInd]->Channel();
454 for (
unsigned int ch=0; ch<WireList.size(); ++ch) {
455 if ( !CouldBeShortDrift && (WireList[ch].TPC%2 == 0) )
continue;
456 if ( !CouldBeLongDrift && (WireList[ch].TPC%2 != 0) )
continue;
458 double WStart[3], WEnd[3];
465 for (
int WPass=0; WPass < NPoints; ++WPass) {
466 double ThisXPos = HitPosLongDrift;
467 if (WireList[ch].TPC%2 == 0) ThisXPos = HitPosShortDrift;
468 double ThisYPos = WStart[1] + ( WPass * (WEnd[1]-WStart[1])/(NPoints-1) );
469 double ThisZPos = WStart[2] + ( WPass * (WEnd[2]-WStart[2])/(NPoints-1) );
471 bool GoodWire =
false;
473 GoodWire =
pnpoly ( 4, VertexX, VertexZ, ThisXPos, ThisZPos );
474 if (!GoodWire)
continue;
479 GoodWire =
pnpoly ( 4, VertexY, VertexZ, ThisYPos, ThisZPos );
481 GoodWire =
pnpoly ( 4, VertexX, VertexY, ThisXPos, ThisYPos );
483 if (!GoodWire)
continue;
486 if ( WireList[ch].
Wire == hits[HitInd]->WireID().
Wire && WireList[ch].TPC == hits[HitInd]->WireID().TPC ) {
487 TempHitsVec.push_back( *hits[HitInd] );
489 recob::Hit hit( hits[HitInd]->
Channel(), hits[HitInd]->StartTick(), hits[HitInd]->EndTick(), hits[HitInd]->PeakTime(),
490 hits[HitInd]->SigmaPeakTime(), hits[HitInd]->RMS(), hits[HitInd]->PeakAmplitude(),
491 hits[HitInd]->SigmaPeakAmplitude(), hits[HitInd]->SummedADC(), hits[HitInd]->Integral(),
492 hits[HitInd]->SigmaIntegral(), hits[HitInd]->Multiplicity(), hits[HitInd]->LocalIndex(),
493 hits[HitInd]->GoodnessOfFit(), hits[HitInd]->DegreesOfFreedom(), hits[HitInd]->View(),
494 hits[HitInd]->SignalType(), WireList[ch]
496 TempHitsVec.push_back( hit );
501 if (TempHitsVec.size() == 0)
continue;
502 if (TempHitsVec.size() == 1) {
505 hcol.emplace_back(TempHitsVec[0], wire, rawdigits);
507 UnDisambigHits.push_back( std::make_pair(TempHitsVec, HitInd) );
510 std::cout <<
"After Induction planes for TrigInd " << TrigInd <<
" hcol now has size " << hcol.size() <<
std::endl;
512 std::cout <<
"After all trigger indexes the vectors have sizes: hits -> " << hits.size() <<
", hcol -> " << hcol.size() <<
", UnDisambigHits -> " << UnDisambigHits.size() <<
std::endl;
515 std::vector<recob::Hit>
const &Peak = hcol.peek();
516 int TPC1, TPC2, TPC3, TPC4, TPC5, TPC6, TPC7, TPC0;
517 TPC1 = TPC2 = TPC3 = TPC4 = TPC5 = TPC6 = TPC7 = TPC0 = 0;
518 for (
size_t qq=0; qq<Peak.size(); ++qq) {
519 if (Peak[qq].WireID().TPC == 0) ++TPC0;
520 else if (Peak[qq].WireID().TPC == 1) ++TPC1;
521 else if (Peak[qq].WireID().TPC == 2) ++TPC2;
522 else if (Peak[qq].WireID().TPC == 3) ++TPC3;
523 else if (Peak[qq].WireID().TPC == 4) ++TPC4;
524 else if (Peak[qq].WireID().TPC == 5) ++TPC5;
525 else if (Peak[qq].WireID().TPC == 6) ++TPC6;
526 else if (Peak[qq].WireID().TPC == 7) ++TPC7;
528 if (
fDebug) std::cout <<
"\n\nI have these hits in each TPC " << TPC0 <<
" " << TPC1 <<
" " << TPC2 <<
" " << TPC3 <<
" " << TPC4 <<
" " << TPC5 <<
" " << TPC6 <<
" " << TPC7 <<
"\n\n" <<
std::endl;
533 std::vector < std::pair < std::vector <recob::Hit>,
size_t > > StillUnDisambigHits;
534 std::vector < std::pair < recob::Hit, size_t > > NowGoodHits;
537 std::cout <<
"\nNow to do my next step....fit hits to a 2D line in XZ and find which ambiguous hit is closer..." <<
std::endl;
538 std::vector < recob::Hit >
const &NextGoodHits = hcol.peek();
540 TwoDimXZLineFit( NextGoodHits, UnDisambigHits, StillUnDisambigHits, NowGoodHits );
541 for (
size_t NowDisambig=0; NowDisambig < NowGoodHits.size(); ++NowDisambig ) {
542 size_t WhichRawHit = NowGoodHits[NowDisambig].second;
545 hcol.emplace_back(NowGoodHits[NowDisambig].first, wire, rawdigits);
547 OutAndClearVector( UnDisambigHits, StillUnDisambigHits, NowGoodHits, hcol.size() );
551 std::cout <<
"\nNow to do my next step....fit hits to a 2D line in each TPC / Plane combination and find which ambiguous hit is closer..." <<
std::endl;
552 std::vector < recob::Hit >
const &NewerGoodHits = hcol.peek();
554 TwoDimPlaneLineFit( NewerGoodHits, UnDisambigHits, StillUnDisambigHits, NowGoodHits );
555 for (
size_t NowDisambig=0; NowDisambig < NowGoodHits.size(); ++NowDisambig ) {
556 size_t WhichRawHit = NowGoodHits[NowDisambig].second;
559 hcol.emplace_back(NowGoodHits[NowDisambig].first, wire, rawdigits);
561 OutAndClearVector( UnDisambigHits, StillUnDisambigHits, NowGoodHits, hcol.size() );
565 std::cout <<
"\nNow to do my next step....if induction wire crosses a collection wire with a good hit..." <<
std::endl;
566 std::vector < recob::Hit >
const &NewHits = hcol.peek();
568 CrossCollection( NewHits, UnDisambigHits, StillUnDisambigHits, NowGoodHits );
569 for (
size_t NowDisambig=0; NowDisambig < NowGoodHits.size(); ++NowDisambig ) {
570 size_t WhichRawHit = NowGoodHits[NowDisambig].second;
573 hcol.emplace_back(NowGoodHits[NowDisambig].first, wire, rawdigits);
575 OutAndClearVector( UnDisambigHits, StillUnDisambigHits, NowGoodHits, hcol.size() );
579 std::cout <<
"\nNow to do my next step....if any adjacent wires have hits on them..." <<
std::endl;
580 std::vector < recob::Hit >
const &NewGoodHits = hcol.peek();
582 AdjacentWireWidth( NewGoodHits, UnDisambigHits, StillUnDisambigHits, NowGoodHits );
583 for (
size_t NowDisambig=0; NowDisambig < NowGoodHits.size(); ++NowDisambig ) {
584 size_t WhichRawHit = NowGoodHits[NowDisambig].second;
587 hcol.emplace_back(NowGoodHits[NowDisambig].first, wire, rawdigits);
589 OutAndClearVector( UnDisambigHits, StillUnDisambigHits, NowGoodHits, hcol.size() );
592 std::cout <<
"\nAfter all that the vectors have sizes: hits -> " << hits.size() <<
", hcol -> " << hcol.size() <<
std::endl;
622 for (i = 0, j = nvert-1; i < nvert; j = i++) {
623 if ( ((verty[i]>testy) != (verty[j]>testy)) &&
624 (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) )
632 TMatrixD
X(HitVector.size(), 2);
633 TMatrixD
Y(HitVector.size(), 1);
634 for (
size_t HitLoop=0; HitLoop<HitVector.size(); ++HitLoop) {
635 double WireEnd[3], WireStart[3];
638 if ( HitVector[HitLoop].WireID().TPC % 2 == 0) {
639 DriftDist = -DriftDist;
642 X[HitLoop][0] = WireStart[2];
644 Y[HitLoop].Assign(DriftDist + WireStart[0]);
645 TwoDLineHist->Fill(WireStart[2], DriftDist + WireStart[0]);
651 TMatrixD
X(HitVector.size(), 2);
652 TMatrixD
Y(HitVector.size(), 1);
653 for (
size_t HitLoop=0; HitLoop<HitVector.size(); ++HitLoop) {
654 X[HitLoop][0] = HitVector[HitLoop].WireID().Wire;
656 Y[HitLoop][0] = HitVector[HitLoop].PeakTime();
663 std::cout <<
"Can't construct a line, so giving null values." <<
std::endl;
664 Gradient = Intercept = 0;
667 TMatrixD X_T(2,MatSize);
671 TMatrixD X_T_x_X_inv = X_T*
X;
672 X_T_x_X_inv.Invert();
675 TMatrixD params = X_T_x_X_inv * X_T *
Y;
676 Gradient = params[0][0];
677 Intercept = params[1][0];
678 if (
fDebug) std::cout <<
"My line is of form: y = " << Gradient <<
"x + " << Intercept <<
std::endl;
684 double Dist = fabs( (Gradient*X) - Y + Intercept ) /
pow( 1 + (Gradient*Gradient), 0.5);
690 std::vector<recob::Hit> PlaneHits;
691 for (
size_t HitLoop=0; HitLoop<GoodHits.size(); ++HitLoop) {
692 if ( GoodHits[HitLoop].WireID().Plane !=
Plane )
continue;
693 if ( TPC != 10 && GoodHits[HitLoop].WireID().TPC != TPC )
continue;
694 PlaneHits.emplace_back(GoodHits[HitLoop]);
697 std::vector<recob::Hit> UniqPlaneHits;
698 for (
size_t HitLoop=0; HitLoop<PlaneHits.size(); ++HitLoop) {
699 unsigned int ThisChannel = PlaneHits[HitLoop].Channel();
701 for (
size_t HitLoop2=0; HitLoop2<PlaneHits.size(); ++HitLoop2) {
702 if (PlaneHits[HitLoop2].
Channel() == ThisChannel) ++NHits;
704 if (NHits==1) UniqPlaneHits.emplace_back(PlaneHits[HitLoop]);
708 for (
size_t Q=0; Q<UniqPlaneHits.size(); ++Q)
709 if ( UniqPlaneHits[Q].WireID().TPC%2 != 0 ) ++NLong;
710 double rat = (double)UniqPlaneHits.size() / (double)NLong;
712 std::vector<recob::Hit> LongHit;
713 for (
size_t W=0;
W<UniqPlaneHits.size(); ++
W)
714 if ( UniqPlaneHits[
W].WireID().TPC%2 != 0 )
715 LongHit.emplace_back(UniqPlaneHits[
W]);
718 return UniqPlaneHits;
724 for (
size_t CloseLoop=0; CloseLoop < CloseHits.size(); ++CloseLoop) {
725 if (CloseHits[CloseLoop] == 0)
continue;
727 for (
size_t CloseLoop2=0; CloseLoop2 < CloseHits.size(); ++CloseLoop2) {
728 if (CloseLoop == CloseLoop2 )
continue;
729 if (CloseHits[CloseLoop2]!=0) GoodHit = -1;
737 double MinDist = DBL_MAX;
739 for (
size_t CloseLoop=0; CloseLoop < CloseHits.size(); ++CloseLoop) {
740 if ( CloseHits[CloseLoop] == MinDist ) {
743 if ( CloseHits[CloseLoop] < MinDist ) {
744 MinDist = CloseHits[CloseLoop];
749 std::vector<int> ReturnVec;
751 ReturnVec.push_back( GoodHit );
753 for (
size_t CloseLoop=0; CloseLoop < CloseHits.size(); ++CloseLoop)
754 if ( CloseHits[CloseLoop] == MinDist )
755 ReturnVec.push_back( CloseLoop );
761 std::vector < std::pair < std::vector < recob::Hit >,
size_t > > &NewBad,
762 std::vector < std::pair < recob::Hit, size_t > > &NewGood,
size_t HitsSize ) {
763 std::cout <<
"The vectors have sizes: UnDisambigHits -> " << InitialBad.size()
764 <<
", StillUndisambigHits -> " << NewBad.size()
765 <<
", NowGoodHits -> " << NewGood.size() <<
", hcol -> " << HitsSize <<
std::endl;
772 std::vector < std::pair < std::vector < recob::Hit >,
size_t > > &InputBadVector,
773 std::vector < std::pair < std::vector < recob::Hit >,
size_t > > &OutputBadVector,
774 std::vector < std::pair < recob::Hit, size_t > > &OutputGoodVector ) {
775 if (!InputBadVector.size())
return;
776 for (
size_t QuestHit=0; QuestHit<InputBadVector.size(); ++QuestHit) {
777 std::vector<int> CloseHits;
778 std::vector< recob::Hit > Hitting = InputBadVector[QuestHit].first;
779 for (
size_t ThisQuest=0; ThisQuest<Hitting.size(); ++ThisQuest) {
781 for (
size_t HitLoop=0; HitLoop<GoodHits.size(); ++HitLoop) {
782 if ( GoodHits[HitLoop].View() !=
geo::kZ )
continue;
783 if ( Hitting[ThisQuest].WireID().TPC != GoodHits[HitLoop].WireID().TPC )
continue;
784 if ( fabs( Hitting[ThisQuest].PeakTime() - GoodHits[HitLoop].PeakTime() ) >=
fCollectionTimeWidth )
continue;
787 if (!
fGeom->
WireIDsIntersect( Hitting[ThisQuest].WireID(), GoodHits[HitLoop].WireID(), Intersect ) )
continue;
790 CloseHits.push_back(ThisNearHit);
795 OutputGoodVector.emplace_back( std::make_pair(Hitting[GoodHit], InputBadVector[QuestHit].
second ) );
797 OutputBadVector.push_back(InputBadVector[QuestHit]);
803 std::vector < std::pair < std::vector < recob::Hit >,
size_t > > &InputBadVector,
804 std::vector < std::pair < std::vector < recob::Hit >,
size_t > > &OutputBadVector,
805 std::vector < std::pair < recob::Hit, size_t > > &OutputGoodVector ) {
806 if (!InputBadVector.size())
return;
807 for (
size_t QuestHit=0; QuestHit<InputBadVector.size(); ++QuestHit) {
808 std::vector<int> CloseHits;
809 std::vector< recob::Hit > Hitting = InputBadVector[QuestHit].first;
810 for (
size_t ThisQuest=0; ThisQuest<Hitting.size(); ++ThisQuest) {
812 for (
size_t HitLoop=0; HitLoop<GoodHits.size(); ++HitLoop) {
813 if ( Hitting[ThisQuest].WireID().TPC != GoodHits[HitLoop].WireID().TPC )
continue;
814 if ( Hitting[ThisQuest].WireID().Plane != GoodHits[HitLoop].WireID().Plane )
continue;
816 if ( fabs( Hitting[ThisQuest].PeakTime() - GoodHits[HitLoop].PeakTime() ) >=
fAdjacentTimeWidth )
continue;
819 CloseHits.push_back(ThisNearHit);
824 OutputGoodVector.emplace_back( std::make_pair(Hitting[GoodHit], InputBadVector[QuestHit].
second ) );
826 OutputBadVector.push_back(InputBadVector[QuestHit]);
832 std::vector < std::pair < std::vector < recob::Hit >,
size_t > > &InputBadVector,
833 std::vector < std::pair < std::vector < recob::Hit >,
size_t > > &OutputBadVector,
834 std::vector < std::pair < recob::Hit, size_t > > &OutputGoodVector ) {
835 if (!InputBadVector.size())
return;
837 std::vector<recob::Hit> UniqColHits =
FindUniqueHits( GoodHits, 2, 10 );
838 if (!UniqColHits.size()) {
839 std::cout <<
"I have no unique collection plane wires, so can't do anything..." <<
std::endl;
840 for (
size_t q=0; q<InputBadVector.size(); ++q)
841 OutputBadVector.push_back(InputBadVector[q]);
844 if (
fDebug) std::cout <<
"I have " << UniqColHits.size() <<
" unique collection plane hits " <<
std::endl;
846 float Gradient, Intercept;
850 if ( Gradient == 0 && Intercept == 0 ) {
851 for (
size_t BadLoop=0; BadLoop < InputBadVector.size(); ++BadLoop) {
852 OutputBadVector.push_back( InputBadVector[BadLoop]);
856 for (
size_t BadLoop=0; BadLoop < InputBadVector.size(); ++BadLoop) {
858 std::vector<double> CloseHits;
859 std::vector< recob::Hit > Hitting = InputBadVector[BadLoop].first;
860 for (
size_t ThisQuest=0; ThisQuest<Hitting.size(); ++ThisQuest) {
862 double WireEnd[3], WireStart[3];
865 if ( Hitting[ThisQuest].WireID().TPC % 2 == 0) {
866 DriftDist = -DriftDist;
868 double HitPosX = DriftDist + WireStart[0];
869 double HitPosZ = (WireStart[2] + WireEnd[2])/2;
870 double distance =
DistToLine ( Gradient, Intercept, HitPosZ, HitPosX );
872 CloseHits.push_back(distance);
880 if (WhichIndexes.size() == 1 ) {
882 OutputGoodVector.emplace_back( std::make_pair(Hitting[WhichIndexes[0]], InputBadVector[BadLoop].
second ) );
886 if ( WhichIndexes.size() == Hitting.size() ) {
887 OutputBadVector.push_back(InputBadVector[BadLoop]);
889 std::vector<recob::Hit> BadHits;
890 for (
size_t aa=0; aa<WhichIndexes.size(); ++aa) {
891 BadHits.push_back( Hitting[ WhichIndexes[aa] ] );
893 OutputBadVector.push_back( std::make_pair( BadHits, InputBadVector[BadLoop].
second ) );
901 std::vector < std::pair < std::vector < recob::Hit >,
size_t > > &InputBadVector,
902 std::vector < std::pair < std::vector < recob::Hit >,
size_t > > &OutputBadVector,
903 std::vector < std::pair < recob::Hit, size_t > > &OutputGoodVector ) {
904 if (!InputBadVector.size())
return;
908 std::vector< std::pair< unsigned int, unsigned int > > WhichTPCPl;
909 std::vector< std::pair < std::vector < recob::Hit >,
size_t > > TPCPlaneCombs;
910 for (
size_t HitLoop=0; HitLoop < InputBadVector.size(); ++HitLoop) {
911 std::vector< recob::Hit >
Hits = InputBadVector[HitLoop].first;
912 unsigned int FirstTPC = Hits[0].WireID().TPC;
913 for (
size_t ThisHit=0; ThisHit<Hits.size(); ++ThisHit ) {
914 if ( Hits[ThisHit].WireID().TPC != FirstTPC ) {
915 if (
fDebug) std::cout <<
"First hit is in TPC " << FirstTPC <<
", whilst hit " << ThisHit <<
" is in TPC " << Hits[ThisHit].WireID().TPC <<
" giving up on this hit" <<
std::endl;
916 OutputBadVector.push_back( InputBadVector[HitLoop]);
921 std::vector<recob::Hit> CombHits;
922 for (
size_t aa=0; aa<Hits.size(); ++aa) {
923 CombHits.push_back( Hits[aa] );
925 TPCPlaneCombs.push_back( std::make_pair( CombHits, InputBadVector[HitLoop].
second ) );
928 for (
size_t aa=0; aa<WhichTPCPl.size(); ++aa)
929 if (WhichTPCPl[aa].first == FirstTPC && WhichTPCPl[aa].second == Hits[0].WireID().Plane )
932 WhichTPCPl.push_back( std::make_pair( FirstTPC, Hits[0].WireID().
Plane ) );
938 for (
size_t LineIndex=0; LineIndex<WhichTPCPl.size(); ++LineIndex) {
939 unsigned int ThisTPC = WhichTPCPl[LineIndex].first;
940 unsigned int ThisPl = WhichTPCPl[LineIndex].second;
941 std::vector<recob::Hit> UniqHits =
FindUniqueHits( GoodHits, ThisPl, ThisTPC );
942 if ( !UniqHits.size() ) {
943 std::cout <<
"I have no unique hits on TPC " << ThisTPC <<
", Plane " << ThisPl <<
std::endl;
947 if (
fDebug) std::cout <<
"I have " << UniqHits.size() <<
" unique hits on TPC " << ThisTPC <<
", Plane " << ThisPl <<
std::endl;
950 float Gradient, Intercept;
954 for (
size_t HitLoop=0; HitLoop < TPCPlaneCombs.size(); ++HitLoop) {
955 std::vector< recob::Hit >
Hits = TPCPlaneCombs[HitLoop].first;
957 if ( Hits[0].WireID().TPC != ThisTPC || Hits[0].WireID().Plane != ThisPl )
continue;
959 if ( Gradient == 0 && Intercept == 0 ) {
960 OutputBadVector.push_back( TPCPlaneCombs[HitLoop]);
964 double MinDist = DBL_MAX;
965 for (
size_t ThisHit=0; ThisHit<Hits.size(); ++ThisHit ) {
966 double distance =
DistToLine( Gradient, Intercept, (
double)Hits[ThisHit].WireID().
Wire, (
double)Hits[ThisHit].PeakTime() );
968 if ( distance < MinDist ) {
970 WhichIndex = ThisHit;
975 OutputGoodVector.emplace_back( std::make_pair(Hits[WhichIndex], TPCPlaneCombs[HitLoop].
second ) );
982 #endif // COUNTERHITFINDER35T_H
Pedestal provider class for DUNE.
void FindPlaneGradient(std::vector< recob::Hit > HitVector, float &Gradient, float &Intercept)
EventNumber_t event() const
int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy)
Declaration of signal hit object.
void CrossCollection(std::vector< recob::Hit > const GoodHits, std::vector< std::pair< std::vector< recob::Hit >, size_t > > &InputBadVector, std::vector< std::pair< std::vector< recob::Hit >, size_t > > &OutputBadVector, std::vector< std::pair< recob::Hit, size_t > > &OutputGoodVector)
EDProducer(fhicl::ParameterSet const &pset)
int FitLine(std::vector< HitLineFitData > &data, HitLineFitResults &bestfit)
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
Definition of basic raw digits.
Planes which measure Z direction.
void TwoDimXZLineFit(std::vector< recob::Hit > const GoodHits, std::vector< std::pair< std::vector< recob::Hit >, size_t > > &InputBadVector, std::vector< std::pair< std::vector< recob::Hit >, size_t > > &OutputBadVector, std::vector< std::pair< recob::Hit, size_t > > &OutputGoodVector)
std::vector< recob::Hit > FindUniqueHits(std::vector< recob::Hit > const GoodHits, unsigned int Plane, unsigned int TPC)
std::map< unsigned int, std::pair< TVector3, std::vector< TVector3 > > > CounterPositionMap
static void declare_products(art::ProducesCollector &collector, std::string instance_name="", bool doWireAssns=true, bool doRawDigitAssns=true)
Declares the hit products we are going to fill.
std::vector< std::pair< unsigned int, unsigned int > > ExternalTrigIndexVec
void SetSeed(UInt_t seed)
Helper functions to create a hit.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
void produce(art::Event &evt) override
void MatrixGradient(TMatrixD X, TMatrixD Y, size_t MatSize, float &Gradient, float &Intercept)
A class handling a collection of hits and its associations.
#define DEFINE_ART_MODULE(klass)
unsigned int fCollectionTimeWidth
Collect all the RawData header files together.
std::string fHitsModuleLabel
void SetParameter(int i, double startValue, double minValue, double maxValue)
void OutAndClearVector(std::vector< std::pair< std::vector< recob::Hit >, size_t > > &InitialBad, std::vector< std::pair< std::vector< recob::Hit >, size_t > > &NewBad, std::vector< std::pair< recob::Hit, size_t > > &NewGood, size_t HitsSize)
static int max(int a, int b)
HitFinderCounter35t(fhicl::ParameterSet const &pset)
double fConvCountTimeToTicks
Definition of data types for geometry description.
unsigned int fAdjacentTimeWidth
Detector simulation of raw signals on wires.
Encapsulate the geometry of an auxiliary detector.
Encapsulate the geometry of a wire.
ProducesCollector & producesCollector() noexcept
void AdjacentWireWidth(std::vector< recob::Hit > const GoodHits, std::vector< std::pair< std::vector< recob::Hit >, size_t > > &InputBadVector, std::vector< std::pair< std::vector< recob::Hit >, size_t > > &OutputBadVector, std::vector< std::pair< recob::Hit, size_t > > &OutputGoodVector)
std::vector< int > ClosestDistance(std::vector< double > CloseHits)
std::vector< reco::ClusterHit2D * > HitVector
What follows are several highly useful typedefs which we want to expose to the outside world...
bool WireIDsIntersect(WireID const &wid1, WireID const &wid2, geo::Point_t &intersection) const
Computes the intersection between two wires.
art::PtrVector< recob::Hit > Hits
int fCoincidenceTolerance
Utility object to perform functions of association.
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Encapsulate the construction of a single detector plane.
int CheckWhichIndex(std::vector< int > CloseHits)
dune::HitLineFitAlg fFitAlg
ChannelMappingService::Channel Channel
void TwoDimPlaneLineFit(std::vector< recob::Hit > const GoodHits, std::vector< std::pair< std::vector< recob::Hit >, size_t > > &InputBadVector, std::vector< std::pair< std::vector< recob::Hit >, size_t > > &OutputBadVector, std::vector< std::pair< recob::Hit, size_t > > &OutputGoodVector)
double UVStartEndPointsX[4]
void SetHorizVertRanges(float hmin, float hmax, float vmin, float vmax)
void WireEndPoints(geo::WireID const &wireid, double *xyzStart, double *xyzEnd) const
Fills two arrays with the coordinates of the wire end points.
CLHEP::HepRandomEngine & fEngine
unsigned int fAdjacentWireWidth
double DistToLine(float Gradient, float Intercept, double X, double Y)
Declaration of basic channel signal object.
void MakeCounterPositionMap(std::string CounterDir, std::string CounterFile, std::map< unsigned int, std::pair< TVector3, std::vector< TVector3 > > > &CounterPositionMap, double fExtendCountersX=0, double fExtendCountersY=0, double fExtendCountersZ=0)
2D representation of charge deposited in the TDC/wire plane
art::ServiceHandle< geo::Geometry > fGeom
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
second_as<> second
Type of time stored in seconds, in double precision.
recob::tracking::Plane Plane
void FindXZGradient(std::vector< recob::Hit > HitVector, float &Gradient, float &Intercept)
QTextStream & endl(QTextStream &s)
Encapsulate the construction of a single detector plane.
std::string fCounterModuleLabel