46 : fAPAGeo(pset.get<
fhicl::ParameterSet >(
"APAGeometryAlg"))
95 std::vector< art::Ptr<recob::Hit> > ChHits;
100 unsigned int skipNoise(0);
102 for(
size_t h = 0; h < ChHits.size(); h++ ){
113 unsigned int apa(0), cryo(0);
120 std::pair<double,double> ChanTime( hit->
Channel()*1., hit->
PeakTime()*1. );
128 mf::LogWarning(
"DisambigAlg")<<
"\nSkipped "<< skipNoise <<
" induction noise hits using the BackTrackerService.\n" 129 <<
"This is only to temporarily deal with the excessive amount of noise due to the bad deconvolution.\n";
131 mf::LogVerbatim(
"RunDisambig")<<
"\n~~~~~~~~~~~ Running Disambiguation ~~~~~~~~~~~\n";
133 std::map<unsigned int, std::vector< art::Ptr< recob::Hit> > >
::iterator APA_it;
135 unsigned int apa = APA_it->first;
157 <<
fnDVSoFar[apa] <<
" / " << fnVSoFar[apa] <<
" V";
167 <<
fnDVSoFar[apa] <<
" / " << fnVSoFar[apa] <<
" V";
172 unsigned int nDisambig(1);
173 while(nDisambig > 0){
181 <<
fnDVSoFar[apa] <<
" / " << fnVSoFar[apa] <<
" V";
206 std::pair<double,double> ChanTime( hit->
Channel()*1., hit->
PeakTime()*1. );
210 mf::LogWarning(
"InvalidWireID") <<
"wid is invalid, hit not being made\n";
213 std::pair<art::Ptr<recob::Hit>,
geo::WireID> Dhit(hit, wid);
242 return (AsT<=BsT && BsT<=AeT) || (AsT<=BeT && BeT<=AeT) ||
243 (BsT<=AsT && AsT<=BeT) || (BsT<=AeT && AeT<=BeT);
257 unsigned int peakT = hit->
PeakTime();
260 std::vector<bool> IsReasonableWid(hitwids.size(),
false);
261 unsigned short nPossibleWids(0);
262 for(
size_t w=0;
w<hitwids.size();
w++){
265 double xyzStart[3] = {0.};
double xyzEnd[3] = {0.};
268 double zminPos(xyzStart[2]), zmaxPos(xyzEnd[2]);
271 TVector3 tpcCenter(0,0,0);
272 unsigned int tpc = 2*apa + side - cryo*
geom->
NTPC();
276 TVector3 Min(tpcCenter); Min[2] = zminPos;
277 TVector3 Max(tpcCenter); Max[2] = zmaxPos;
283 if( chan <= ZminChan || ZmaxChan <= chan )
continue;
293 IsReasonableWid[
w] =
true; nPossibleWids++;
break; }
300 if(nPossibleWids==0){
301 std::vector<double> xyz;
303 catch(...){
continue; }
305 mf::LogWarning (
"UniqueTimeSeg") <<
"U/V hit inconsistent with Z info; peak time is " 306 << peakT <<
" in APA " << apa <<
" on channel " << hit->
Channel();
308 else if(nPossibleWids==1){
309 for(
size_t d=0;
d<hitwids.size();
d++)
312 else if(nPossibleWids==2){
340 throw cet::exception(
"MakeCloseHits") <<
"Function not meant for non-wrapped channels.\n";
345 int tempchan = Dchan + ext;
346 if( tempchan < (
int)firstChan ) tempchan += ChanPerView;
347 if( tempchan > (
int)(firstChan+ChanPerView-1) ) tempchan -= ChanPerView;
354 unsigned int apa(0), cryo(0);
356 unsigned int MakeCount(0);
363 if( !(Dmin <= st && st <= Dmax) && !(Dmin <= et && et <= Dmax) )
continue;
368 for(
size_t w=0;
w<wids.size();
w++){
369 if( wids[
w].TPC != Dwid.
TPC )
continue;
370 if( (
int)(wids[
w].Wire)-(
int)(Dwid.
Wire) != ext )
continue;
374 std::pair<double,double> ChanTime( closeHit->
Channel()*1., closeHit->
PeakTime()*1. );
405 unsigned int nExtended(1);
406 while( nExtended > 0 ){
410 for(
size_t h=0; h < hits.size(); h++){
411 std::pair<double,double> ChanTime( hits[h]->Channel()*1., hits[h]->PeakTime()*1. );
413 double stD = hits[h]->PeakTimePlusRMS(-1.);
414 double etD = hits[h]->PeakTimePlusRMS(+1.);
415 double hitWindow = etD - stD;
420 unsigned int extensions = 0;
421 for(
unsigned int ext=1; ext <
fNChanJumps+1; ext++ ){
424 double timeExt = hitWindow*ext;
425 N += this->
MakeCloseHits( (
int)(-ext), Dwid, stD-5-timeExt, etD+5+timeExt);
426 N += this->
MakeCloseHits( (
int)(ext), Dwid, stD-5-timeExt, etD+5+timeExt);
429 nExtended += extensions;
450 double pi = 3.14159265;
455 for(
size_t h=0; h<
fAPAToHits[apa].size(); h++){
458 unsigned int plane = 0;
if(view==
geo::kV){ plane = 1; }
else if(view==
geo::kZ) plane = 2;
459 std::vector<double> ChanTimeCenter(2, 0.);
467 std::vector<std::vector<double> > CloseHitsChanTime;
468 std::vector<double> FurthestCloseChanTime(2,0.);
469 std::vector<double> ClosestChanTime(2,0.);
double minDist =
fCloseHitsRadius+1.;
472 for(
size_t c=0; c<
fAPAToHits[apa].size(); c++){
474 if(view!=closehit->
View())
continue;
476 unsigned int plane = 0;
if(view==
geo::kV){ plane = 1; }
else if(view==
geo::kZ) plane = 2;
477 std::vector<double> ChanTimeClose(2, 0.);
484 if(ChanTimeClose == ChanTimeCenter)
continue;
486 double ChanDist = ChanTimeClose[0]-ChanTimeCenter[0];
487 if( ChanDist > ChanDistRange/2 ) ChanDist = ChanDistRange - ChanDist;
489 double distance = std::sqrt( std::pow(ChanDist,2)
490 + std::pow(ChanTimeClose[1]-ChanTimeCenter[1],2) );
492 if( distance <=
fCloseHitsRadius ) CloseHitsChanTime.push_back(ChanTimeClose);
494 if( distance < minDist ){
495 ClosestChanTime = ChanTimeClose;
501 if(CloseHitsChanTime.size()<5)
continue;
503 double minRad(2*pi+1.), maxRad(0.);
504 bool CloseToNegPi(
false), CloseToPosPi(
false);
505 for(
size_t i=0; i<CloseHitsChanTime.size(); i++){
506 std::vector<double> ThisChanTime(CloseHitsChanTime[i]);
508 double ChanDist = ThisChanTime[0]-ChanTimeCenter[0];
509 if( ChanDist > ChanDistRange/2 ) ChanDist = ChanDistRange - ChanDist;
510 double hitrad = std::atan2( ThisChanTime[1]-ChanTimeCenter[1] ,
512 if( hitrad > maxRad ) maxRad = hitrad;
513 if( hitrad < minRad ) minRad = hitrad;
514 if( hitrad + fMaxEndPRadRange > pi ) CloseToPosPi =
true;
515 else if( hitrad - fMaxEndPRadRange < -pi ) CloseToNegPi =
true;
519 if(CloseToPosPi&&CloseToNegPi){
520 for(
size_t i=0; i<CloseHitsChanTime.size(); i++){
521 std::vector<double> ThisChanTime(CloseHitsChanTime[i]);
523 double ChanDist = ThisChanTime[0]-ChanTimeCenter[0];
524 if( ChanDist > ChanDistRange/2 ) ChanDist = ChanDistRange - ChanDist;
525 double hitrad = std::atan2( ThisChanTime[1]-ChanTimeCenter[1] ,
527 if( hitrad > 0 ) hitrad = pi - hitrad;
528 if( hitrad < 0 ) hitrad = -pi - hitrad;
529 if( hitrad > maxRad ) maxRad = hitrad;
530 if( hitrad < minRad ) minRad = hitrad;
534 if( maxRad - minRad < fMaxEndPRadRange )
fAPAToEndPHits[apa].push_back( centhit );
540 <<
" endpoint hits in apa " << apa << std::endl;
544 <<
" at time " << epHit->
PeakTime() << std::endl;
563 mf::LogVerbatim(
"UseEndPts") <<
" APA " << apa <<
" has no endpoints.";
568 std::vector<std::vector< art::Ptr<recob::Hit> > > EndPMatch;
569 unsigned short nZendPts(0);
570 for(
size_t ep=0; ep<endPts.size(); ep++){
571 if(endPts[ep]->View()!=
geo::kZ)
continue;
574 unsigned short Umatch(0), Vmatch(0);
578 for(
size_t p=0; p<endPts.size(); p++){
579 if(endPts[p]->View()==
geo::kU){
584 }
else if(endPts[p]->View()==
geo::kV){
593 TVector3 tpcCenter(0,0,0);
594 unsigned int tpc(endPts[ep]->WireID().TPC), cryo(endPts[ep]->WireID().Cryostat);
598 if(Umatch == 1 && Vmatch == 1){
600 std::vector<double> yzEndPt
602 double intersect[3] = {tpcCenter[0], yzEndPt[0], yzEndPt[1]};
609 }
else if(Umatch == 1 && Vmatch != 1){
611 std::vector< geo::WireIDIntersection > widIntersects;
613 if( widIntersects.size() == 0 )
continue;
614 else if( widIntersects.size() == 1 ){
615 double intersect[3] = {tpcCenter[0], widIntersects[0].y, widIntersects[0].z};
619 for(
size_t i=0; i < widIntersects.size(); i++){
624 }
else if(Umatch == 1 && Vmatch != 1){
626 std::vector< geo::WireIDIntersection > widIntersects;
628 if( widIntersects.size() == 0 )
continue;
629 else if( widIntersects.size() == 1 ){
630 double intersect[3] = {tpcCenter[0], widIntersects[0].y, widIntersects[0].z};
634 for(
size_t i=0; i < widIntersects.size(); i++){
645 if( nZendPts==0 && endPts.size()==2 && this->
HitsOverlapInTime(endPts[0],endPts[1]) ){
646 std::vector< geo::WireIDIntersection > widIntersects;
648 if( widIntersects.size() == 1 ){
649 TVector3 tpcCenter(0,0,0);
650 unsigned int cryo = endPts[0]->WireID().Cryostat;
651 unsigned int tpc = widIntersects[0].TPC;
653 double intersect[3] = {tpcCenter[0], widIntersects[0].y, widIntersects[0].z};
654 unsigned int plane0(0), plane1(0);
655 if( endPts[0]->View()==
geo::kV ) plane0=1;
656 if( endPts[1]->View()==
geo::kV ) plane1=1;
661 }
else if( widIntersects.size() > 1 ){
662 for(
size_t i=0; i < widIntersects.size(); i++){
679 unsigned int nU(0), nV(0);
686 unsigned int nDU(0), nDV(0);
709 unsigned int nDisambiguations(0);
715 std::pair<double,double> ambigChanTime(ambigchan*1.,ambighit->
PeakTime());
719 std::vector<unsigned int> widDcounts (ambigwids.size(), 0);
720 std::vector<unsigned int> widAcounts (ambigwids.size(), 0);
733 std::pair<double,double> ChanTime(chan*1.,hit->
PeakTime());
736 for(
size_t a=0; a<ambigwids.size(); a++)
742 for(
size_t a=0; a<ambigwids.size(); a++)
743 for(
size_t w=0;
w<wids.size();
w++)
744 if( ambigwids[a].TPC == wids[
w].TPC &&
752 unsigned int Dcount(0), Acount(0);
753 for(
size_t d=0;
d<widDcounts.size();
d++) Dcount += widDcounts[
d];
754 for(
size_t a=0; a<widAcounts.size(); a++) Acount += widAcounts[a];
755 for(
size_t d=0;
d<widDcounts.size();
d++){
756 if( Dcount == widDcounts[
d] && Dcount>0 && Acount==0 ){
758 nDisambiguations++; } }
759 for(
size_t a=0; a<widAcounts.size(); a++){
760 if( Acount == widAcounts[a] && Acount==1 ){
769 return nDisambiguations;
bool APAChannelsIntersect(uint32_t chan1, uint32_t chan2, std::vector< geo::WireIDIntersection > &IntersectVector)
If the channels intersect, get all intersections.
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
std::map< std::pair< double, double >, geo::WireID > fChanTimeToWid
If a hit is disambiguated, map its chan and peak time to the chosen wireID.
Encapsulate the construction of a single cyostat.
const std::vector< double > HitToXYZ(const recob::Hit &hit)
double fCloseHitsRadius
Distance (cm) away from a hit to look when checking if it's an endpoint.
std::map< unsigned int, unsigned int > fnDVSoFar
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
geo::WireID WireID() const
Initial tdc tick for hit.
apa::APAGeometryAlg fAPAGeo
unsigned int ChannelToAPA(uint32_t chan)
Get number of the APA containing the given channel.
Declaration of signal hit object.
std::map< unsigned int, unsigned int > fnVSoFar
bool isValid
Whether this ID points to a valid element.
void Crawl(unsigned int apa)
Extend what we disambiguation we do have in apa.
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
CryostatID_t Cryostat
Index of cryostat.
Planes which measure Z direction.
geo::View_t View() const
View for the plane of the hit.
WireID_t Wire
Index of the wire within its plane.
bool HitsOverlapInTime(art::Ptr< recob::Hit > hitA, art::Ptr< recob::Hit > hitB)
geo::Length_t WirePitch(geo::PlaneID const &planeid) const
Returns the distance between two consecutive wires.
std::vector< std::pair< art::Ptr< recob::Hit >, geo::WireID > > fDisambigHits
The final list of hits to pass back to be made.
art::ServiceHandle< cheat::BackTrackerService > bt_serv
For TEMPORARY monitering of potential problems.
void TrivialDisambig(unsigned int apa)
Make the easiest and safest disambiguations in apa.
std::map< unsigned int, std::vector< art::Ptr< recob::Hit > > > fAPAToEndPHits
\ todo: Channel/APA to hits can be done in a unified way
uint32_t FirstChannelInView(geo::View_t geoview, unsigned int apa, unsigned int cryo)
void AssessDisambigSoFar(unsigned int apa)
See how much disambiguation has been done in this apa so far.
virtual double TimeOffsetV() const =0
T get(std::string const &key) const
std::map< raw::ChannelID_t, std::vector< art::Ptr< recob::Hit > > > fChannelToHits
DisambigAlg(fhicl::ParameterSet const &pset)
std::vector< double > ThreeChanPos(uint32_t u, uint32_t v, uint32_t z)
Find the center of the 3 intersections, choose best if multiple.
virtual double TimeOffsetZ() const =0
std::map< unsigned int, double > fVeffSoFar
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
PlaneID_t Plane
Index of the plane within its TPC.
unsigned int fNChanJumps
Number of channels the crawl can jump over.
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
void reconfigure(fhicl::ParameterSet const &p)
float PeakTimeMinusRMS(float sigmas=+1.) const
Returns a time sigmas RMS away from the peak time.
unsigned int FindChanTimeEndPts(unsigned int apa)
Basic endpoint-hit finder per apa.
Detector simulation of raw signals on wires.
unsigned int CompareViews(unsigned int apa)
Compare U and V to see if one says something about the other.
Encapsulate the geometry of a wire.
unsigned int NTPC(unsigned int cstat=0) const
Returns the total number of TPCs in the specified cryostat.
void UseEndPts(unsigned int apa)
Try to associate endpoint hits and crawl from there.
bool WireIDsIntersect(WireID const &wid1, WireID const &wid2, geo::Point_t &intersection) const
Computes the intersection between two wires.
virtual double ConvertTicksToX(double ticks, int p, int t, int c) const =0
raw::ChannelID_t PlaneWireToChannel(WireID const &wireid) const
Returns the ID of the TPC channel connected to the specified wire.
float PeakTime() const
Time of the signal peak, in tick units.
std::map< unsigned int, std::map< std::pair< double, double >, bool > > fHasBeenDisambiged
Convenient way to keep track of disambiguation so far.
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane.
unsigned int ChannelsInView(geo::View_t geoview)
const TPCGeo & TPC(unsigned int itpc) const
Return the itpc'th TPC in the cryostat.
std::map< unsigned int, std::vector< art::Ptr< recob::Hit > > > fAPAToHits
std::map< unsigned int, std::vector< art::Ptr< recob::Hit > > > fAPAToUVHits
bool fCrawl
\ todo: Write function that compares hits more detailedly
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
std::map< unsigned int, std::vector< std::pair< art::Ptr< recob::Hit >, geo::WireID > > > fAPAToDHits
Hold the disambiguations per APA.
std::map< unsigned int, std::vector< art::Ptr< recob::Hit > > > fAPAToZHits
void WireEndPoints(geo::WireID const &wireid, double *xyzStart, double *xyzEnd) const
Fills two arrays with the coordinates of the wire end points.
Declaration of basic channel signal object.
std::map< unsigned int, double > fUeffSoFar
void MakeDisambigHit(art::Ptr< recob::Hit > hit, geo::WireID, unsigned int apa)
Makes a disambiguated hit while keeping track of what has already been disambiguated.
float PeakTimePlusRMS(float sigmas=+1.) const
Returns a time sigmas RMS away from the peak time.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
art::ServiceHandle< geo::Geometry > geom
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
TPCID_t TPC
Index of the TPC within its cryostat.
raw::ChannelID_t NearestChannel(geo::Point_t const &worldLoc, geo::PlaneID const &planeid) const
Returns the ID of the channel nearest to the specified position.
std::map< unsigned int, unsigned int > fnUSoFar
virtual double TimeOffsetU() const =0
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
void LocalToWorld(const double *tpc, double *world) const
Transform point from local TPC frame to world frame.
unsigned int MakeCloseHits(int ext, geo::WireID wid, double Dmin, double Dmax)
Having disambiguated a time range on a wireID, extend to neighboring channels.
const detinfo::DetectorProperties * detprop
cet::coded_exception< error, detail::translate > exception
Encapsulate the construction of a single detector plane.
void RunDisambig(art::Handle< std::vector< recob::Hit > > GausHits)
Run disambiguation as currently configured.
geo::WireID NearestWireIDOnChan(const double WorldLoc[3], uint32_t chan, unsigned int const plane, unsigned int const tpc=0, unsigned int const cstat=0)
std::map< unsigned int, unsigned int > fnDUSoFar