FairRoot/PandaRoot
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
PndFtsHoughSpace Class Reference

Class for Hough space based on TH2S (for the moment). Saves the hits which enter this Hough space and finds peaks. More...

#include <PndFtsHoughSpace.h>

Inheritance diagram for PndFtsHoughSpace:

Public Member Functions

 PndFtsHoughSpace (const char *name=0, const Int_t refIndex=-1, PndFtsHoughSpaceBinning binning=PndFtsHoughSpaceBinning(), Double_t zRefPos=0., Double_t interceptZx=0., PndFtsHoughTrackCand *associatedTrackCand=0, PndFtsHoughTrackerTask *trackerTask=0)
 
 ~PndFtsHoughSpace ()
 
std::vector< PndFtsHoughTrackletFindAllPeaksScanPathsMergeBins (const UInt_t minHeight)
 Finds all peaks that satisfy the minimum height requirement minHeight. More...
 
std::vector< PndFtsHoughTrackletFindAllPeaksScanPathsMergeBinsCalculatingPaths (const UInt_t minHeight)
 Finds all peaks that satisfy the minimum height requirement minHeight. More...
 
std::vector< PndFtsHoughTrackletFindAllPeaksWithTSpectrum2 (const UInt_t minHeight)
 Finds all peaks that satisfy the minimum height requirement minHeight. More...
 
std::vector< PndFtsHoughTrackletFindAllPeaksBinsWoMergingWithSearchWindow (const UInt_t minHeight, const Int_t vicinityLength=0)
 Finds all peaks that satisfy the minimum height requirement minHeight. More...
 
std::vector< PndFtsHoughTrackletFindAllPeaksBlanko (const UInt_t minHeight)
 Finds all peaks that satisfy the minimum height requirement minHeight. More...
 
void FillHoughSpace ()
 Fills the Hough space using the equation which corresponds to the name of the Hough space. More...
 
void Print () const
 
void setVerbose (Int_t verbose)
 
Double_t getInterceptZx () const
 
Double_t getZRefPos () const
 
UInt_t GetNHits () const
 
 ClassDef (PndFtsHoughSpace, 1)
 

Private Member Functions

void throwError (const TString s) const
 For error reporting. More...
 
Bool_t setParametersForHsOption ()
 
void filterInputHits ()
 
void AddHitToHS (UInt_t hitId, Double_t rho)
 
void AddHitToHS (FairLink link, Double_t rho)
 
Bool_t IsHitFromTubeIdAlreadyAdded (const Int_t tubeIdToAdd)
 
const PndFtsHitgetHitFromHS (UInt_t index) const
 
Int_t getHitIdFromHS (UInt_t index) const
 
const TVector3 CalculateHitPosFromIntersectionsWithZxTrackModel (const PndFtsHit *const myHit) const
 
const TVector3 GetRawOrCalculatedHitPos (const PndFtsHit *const myHit) const
 
void AddHitsToTrackletByCalculating (PndFtsHoughTracklet *currentTracklet, Int_t locmax)
 
Bool_t FillHoles (const Int_t lastBinX, const Int_t lastBinY, const Int_t currentBinY, IdxPath *ptrThetaYIdxPathVec)
 Makes sure there are no holes in the Hough space by filling them with a line. More...
 
Double_t equationParabola (Double_t thetaRad, Double_t hitZShifted, Double_t hitXShifted, Double_t By)
 
Double_t equationParabolaPz (Double_t thetaRad, Double_t hitZShifted, Double_t hitXShifted, Double_t By)
 
Double_t equationLineZxOrZy (Double_t thetaRad, Double_t hitZShifted, Double_t hitXLabSys)
 
TString GetDebugOutName (TString title="", Int_t param=-1) const
 For writing out debugging histograms. More...
 
void WriteHistoOfHoughSpace () const
 For writing out Hough spaces as histograms (for debugging purposes). More...
 
TH2S MakeEmptyHistoOfSameDimensions (TString specifier="", Int_t index=-1) const
 Makes a new empty histogram with the same binning and limits as this. More...
 
void WriteHistoOfAllPeaks (const std::vector< PndFtsHoughSpacePeak > &peaksToPlot) const
 For writing out peaks in Hough spaces as histograms (for debugging purposes). More...
 
void WriteHistoOfAllPaths () const
 For writing out paths (how the Hough space was filled seen from one hit) as histograms (for debugging purposes). More...
 
void WriteHistoOfAllPathsForEachMcTruthTrack () const
 For writing out paths from hits which stem from the same MC truth tracks (how the Hough space would be filled if only hits from one track were present) as histograms (for debugging and parameter optimization purposes). More...
 
void PrintFoundTracklets (const std::vector< PndFtsHoughTracklet > &tracklets) const
 
Double_t getByFromBField (Double_t hitXLabSys, Double_t hitYLabSys, Double_t hitZLabSys)
 

Private Attributes

PndFtsHoughTrackerTaskfTrackerTask
 
HitIdxPathMap fHitThetaYIdxPath
 
Int_t fVerbose
 
const Int_t fRefIndex
 for debugging output (to which index in some loop does this Hough space and its output belong to) More...
 
Int_t fFtsBranchId
 @ brief FTS Hits More...
 
std::vector< PndTrackCandHitfHitId
 
PndFtsHoughTrackCandfAssociatedTrackCand
 hits relevant for this Hough space More...
 
Double_t fOnlyUseHitsFromZ
 
Double_t fOnlyUseHitsUpToZ
 
Bool_t fUseNonSkewedStraws
 
Bool_t fUseSkewedStraws
 
Bool_t fKeepBConstant
 
Double_t fZRefPos
 
Double_t fInterceptZx
 
FairField * fField
 

Static Private Attributes

static const Bool_t fCorrectPzx = kFALSE
 

Detailed Description

Class for Hough space based on TH2S (for the moment). Saves the hits which enter this Hough space and finds peaks.

Author
Martin J. Galuska <martin [dot] j [dot] galuska (at) physik [dot] uni (minus) giessen [dot] de>

Note //! after a member means for root that it should not write it to disk when the object is saved

TODO Save path through Hough spaces with global indices!!! TODO: Separate peak finder from Hough space

The angle (theta in rad) is always on x-axis, the value on the y-axis depends on the kind of Hough transform:

HT type yValue
parabola Q/p_{zx}
line intercept (Achsenabschnitt) (in z-x- or z-y-plane)

All FTS hits are scanned within the constructor by filterInputHits(). The hits which are relevant for this Hough space are saved in fHitId and can be accessed with getHit(UInt_t index).

Created: 21.02.2014

Definition at line 67 of file PndFtsHoughSpace.h.

Constructor & Destructor Documentation

PndFtsHoughSpace::PndFtsHoughSpace ( const char *  name = 0,
const Int_t  refIndex = -1,
PndFtsHoughSpaceBinning  binning = PndFtsHoughSpaceBinning(),
Double_t  zRefPos = 0.,
Double_t  interceptZx = 0.,
PndFtsHoughTrackCand associatedTrackCand = 0,
PndFtsHoughTrackerTask trackerTask = 0 
)

Definition at line 129 of file PndFtsHoughSpace.cxx.

References fField, fFtsBranchId, filterInputHits(), fTrackerTask, fVerbose, PndFtsHoughTrackerTask::GetVerbose(), and setParametersForHsOption().

141  :
142  TH2S(name, name,
143  binning.getNBinsTheta(), binning.getThetaRadLow(), binning.getThetaRadHigh(),
144  binning.getNBinsY(),binning.getYLow(),binning.getYHigh()),
145  fTrackerTask(trackerTask),
146  fVerbose(0),
147  fRefIndex(refIndex),
148  fFtsBranchId(0),
149  fAssociatedTrackCand(associatedTrackCand),
150  fZRefPos(zRefPos),
151  fInterceptZx(interceptZx),
152  // set from tracker task
153  fField(0)
154 {
155  if (0==fTrackerTask){
156  std::cerr << "PndFtsHoughSpace FATAL ERROR Tracker task pointer not set.\n";
157  } else {
159  if(3<fVerbose) std::cout << "PndFtsHoughSpace called with tracker ptr " << fTrackerTask << '\n';
160  fFtsBranchId = fTrackerTask->getFtsBranchId();
161  fField = fTrackerTask->getMagneticFieldPtr();
162 
164  filterInputHits();
165  }
166 }
PndFtsHoughTrackCand * fAssociatedTrackCand
hits relevant for this Hough space
const Int_t fRefIndex
for debugging output (to which index in some loop does this Hough space and its output belong to) ...
Bool_t setParametersForHsOption()
TString name
Int_t fFtsBranchId
@ brief FTS Hits
PndFtsHoughTrackerTask * fTrackerTask
PndFtsHoughSpace::~PndFtsHoughSpace ( )

Definition at line 168 of file PndFtsHoughSpace.cxx.

169 {
170 
171 }

Member Function Documentation

void PndFtsHoughSpace::AddHitsToTrackletByCalculating ( PndFtsHoughTracklet currentTracklet,
Int_t  locmax 
)
private

Definition at line 757 of file PndFtsHoughSpace.cxx.

References PndTrackCand::AddHit(), Double_t, equationLineZxOrZy(), equationParabola(), equationParabolaPz(), fFtsBranchId, fInterceptZx, fVerbose, fZRefPos, getByFromBField(), getHitFromHS(), getHitIdFromHS(), GetNHits(), GetRawOrCalculatedHitPos(), PndFtsHoughTracklet::getSecondVal(), max(), min(), throwError(), and TString.

Referenced by FindAllPeaksBinsWoMergingWithSearchWindow().

757  {
759  // TODO this is messy, because the code is very similar to FillHoughSpace. Probably, I should find a way to merge it
760  // add hits which are in the peak to the tracklet
761  // 1 calculate the 2nd value for the next higher/lower theta bin of peak theta
762  // 2 If peak 2nd value is within [min hit 2nd value - half width, max hit 2nd value + half width] add the hit to the tracklet
763  // 3 otherwise the hit is not in the peak
764 
765  // This is more complicated to check, but also true
766  // A calculate the 2nd value for peak theta
767  // B If hit 2nd value is within [peak 2nd value - peakSecondHw, peak 2nd value + peakSecondHw] add the hit
768  // C If hit 2nd value is < peak 2nd value - peakSecondHw, hit is in peak if the 2nd value of the next higher/lower theta bin is >= peak 2nd value
769  // D If hit 2nd value is > peak 2nd value + peakSecondHw, hit is in peak if the 2nd value of the next lower/higher theta bin is <= peak 2nd value
770  // E otherwise the hit is not in the peak
771 
772  const Int_t xfirst = fXaxis.GetFirst();
773  const Int_t xlast = fXaxis.GetLast();
774  //const Int_t yfirst = fYaxis.GetFirst(); //[R.K. 01/2017] unused variable?
775  //const Int_t ylast = fYaxis.GetLast(); //[R.K. 01/2017] unused variable?
776 
777  // 1 calculate the 2nd value for the next higher/lower theta bin of peak theta
778  UInt_t thetaBinLo = locmax-1;
779  UInt_t thetaBinHi = locmax+1;
780  // special case if we are at the edge of the Hough space
781  if ((int)thetaBinLo>xfirst) {
782  thetaBinLo=xfirst;
783  }
784  if ((int)thetaBinHi>xlast) {
785  thetaBinHi=xlast;
786  }
787 
788  // get theta values
789  const Double_t thetaRadLo = fXaxis.GetBinCenter(thetaBinLo);
790  const Double_t thetaRadHi = fXaxis.GetBinCenter(thetaBinHi);
791 
792  // for storing the values to be calculated in Hough transform (yValue = offset for line, yValue = Q/pzx for parabola)
793  Double_t yValLo = 0.;
794  Double_t yValHi = 0.;
795 
796 
797  for (size_t iHit = 0; iHit < GetNHits(); iHit++)
798  {
799  const PndFtsHit* myHit = getHitFromHS(iHit);
800 
801  // get hit position
802  const TVector3 hitPos = GetRawOrCalculatedHitPos(myHit);
803 
804  Double_t hitXLabSys = hitPos.X();
805  Double_t hitYLabSys = hitPos.Y();
806  Double_t hitZLabSys = hitPos.Z();
807  Double_t hitXShifted = hitXLabSys - fInterceptZx; // shifts all x positions of hits so that they go through x=0 at z=zOffset (for parabola)
808  Double_t hitZShifted = hitZLabSys - fZRefPos; // z coordinate in local coordinate system (for parabola and for line)
809 
810  // y component of B field
811  Double_t By = getByFromBField(hitXLabSys, hitYLabSys, hitZLabSys);
812 
813  const TString option = GetName();
814  if ("parabola" == option)
815  {
816  // Use shifted x and shifted z for parabola
817  yValLo = equationParabola(thetaRadLo, hitZShifted, hitXShifted, By);
818  yValHi = equationParabola(thetaRadHi, hitZShifted, hitXShifted, By);
819  if (9<fVerbose) {
820  std::cout << "Q/pzx = " << yValLo << '\n';
821  std::cout << "Q/pzx = " << yValHi << '\n';
822  }
823  }
824  else if ("parabolapz" == option)
825  {
826  yValLo = equationParabolaPz(thetaRadLo, hitZShifted, hitXShifted, By);
827  yValHi = equationParabolaPz(thetaRadHi, hitZShifted, hitXShifted, By);
828 
829  if (9<fVerbose) {
830  std::cout << "pz/Q = " << yValLo << '\n';
831  std::cout << "pz/Q = " << yValHi << '\n';
832  }
833  }
834  else if ( ("lineBeforeDipole" == option) || ("lineBehindDipole" == option) )
835  {
836  // Use real x and shifted z for line
837 
838  yValLo = equationLineZxOrZy(thetaRadLo, hitZShifted, hitXLabSys);
839  yValHi = equationLineZxOrZy(thetaRadHi, hitZShifted, hitXLabSys);
840 
841  if (9<fVerbose) {
842  std::cout << "xLP/PL = " << yValLo << '\n';
843  std::cout << "xLP/PL = " << yValHi << '\n';
844  }
845  }
846  else if ("lineZy" == option)
847  {
848  // Use real x and shifted z for line
849 
850  yValLo = equationLineZxOrZy(thetaRadLo, hitZShifted, hitYLabSys);
851  yValHi = equationLineZxOrZy(thetaRadHi, hitZShifted, hitYLabSys);
852 
853  if (9<fVerbose) {
854  std::cout << "xLP = " << yValLo << '\n';
855  std::cout << "xLP = " << yValHi << '\n';
856  }
857  }
858  else
859  {
860  throwError("Error in FillHoughSpace! option " + option + " is not implemented!");
861  }
862 
863 
864  // 2 If peak 2nd value is within [min hit 2nd value - half width, max hit 2nd value + half width] add the hit to the tracklet
865  const Double_t yMin = std::min(yValLo,yValHi);
866  const Double_t yMax = std::max(yValLo,yValHi);
867  const Double_t yMinHw = fYaxis.GetBinWidth(yMin)/2.;
868  const Double_t yMaxHw = fYaxis.GetBinWidth(yMax)/2.;
869 
870 
871  const Double_t peakSecondVal = currentTracklet->getSecondVal();
872  if ( (yMin-yMinHw <= peakSecondVal) && (yMax+yMaxHw >= peakSecondVal) ){
873  currentTracklet->AddHit(fFtsBranchId, getHitIdFromHS(iHit), hitZLabSys);
874  }
875 
876  } // loop over hits
877 }
Double_t equationParabola(Double_t thetaRad, Double_t hitZShifted, Double_t hitXShifted, Double_t By)
Double_t equationParabolaPz(Double_t thetaRad, Double_t hitZShifted, Double_t hitXShifted, Double_t By)
const TVector3 GetRawOrCalculatedHitPos(const PndFtsHit *const myHit) const
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:26
Double_t getByFromBField(Double_t hitXLabSys, Double_t hitYLabSys, Double_t hitZLabSys)
void throwError(const TString s) const
For error reporting.
void AddHit(UInt_t detId, UInt_t hitId, Double_t rho)
Double_t
Double_t getSecondVal() const
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:25
UInt_t GetNHits() const
Int_t fFtsBranchId
@ brief FTS Hits
Double_t equationLineZxOrZy(Double_t thetaRad, Double_t hitZShifted, Double_t hitXLabSys)
Int_t getHitIdFromHS(UInt_t index) const
const PndFtsHit * getHitFromHS(UInt_t index) const
void PndFtsHoughSpace::AddHitToHS ( UInt_t  hitId,
Double_t  rho 
)
inlineprivate

Definition at line 88 of file PndFtsHoughSpace.cxx.

References fFtsBranchId, fHitId, fTrackerTask, PndFtsHoughTrackerTask::GetFtsHit(), PndFtsHit::GetTubeID(), and IsHitFromTubeIdAlreadyAdded().

Referenced by filterInputHits().

89 {
90  const PndFtsHit *const hitToAdd = fTrackerTask->GetFtsHit(hitId);
91  const Int_t tubeIdToAdd = hitToAdd->GetTubeID();
92 
93 
94  if (kFALSE == IsHitFromTubeIdAlreadyAdded(tubeIdToAdd)) {
95  fHitId.push_back(PndTrackCandHit(fFtsBranchId, hitId, rho));
96  }
97 }
Bool_t IsHitFromTubeIdAlreadyAdded(const Int_t tubeIdToAdd)
std::vector< PndTrackCandHit > fHitId
Int_t GetTubeID() const
Definition: PndFtsHit.h:70
Int_t fFtsBranchId
@ brief FTS Hits
const PndFtsHit * GetFtsHit(UInt_t hitId) const
Returns pointer to the hit with index hitId in the FTS hit array.
PndFtsHoughTrackerTask * fTrackerTask
void PndFtsHoughSpace::AddHitToHS ( FairLink  link,
Double_t  rho 
)
inlineprivate

Definition at line 100 of file PndFtsHoughSpace.cxx.

References fHitId, fTrackerTask, PndFtsHoughTrackerTask::GetFtsHit(), PndFtsHit::GetTubeID(), and IsHitFromTubeIdAlreadyAdded().

101 {
102  const PndFtsHit *const hitToAdd = fTrackerTask->GetFtsHit(link.GetIndex());
103  const Int_t tubeIdToAdd = hitToAdd->GetTubeID();
104 
105  if (kFALSE == IsHitFromTubeIdAlreadyAdded(tubeIdToAdd)) {
106  fHitId.push_back(PndTrackCandHit(link.GetType(), link.GetIndex(), rho));
107  }
108 }
Bool_t IsHitFromTubeIdAlreadyAdded(const Int_t tubeIdToAdd)
std::vector< PndTrackCandHit > fHitId
Int_t GetTubeID() const
Definition: PndFtsHit.h:70
const PndFtsHit * GetFtsHit(UInt_t hitId) const
Returns pointer to the hit with index hitId in the FTS hit array.
PndFtsHoughTrackerTask * fTrackerTask
const TVector3 PndFtsHoughSpace::CalculateHitPosFromIntersectionsWithZxTrackModel ( const PndFtsHit *const  myHit) const
inlineprivate

Definition at line 396 of file PndFtsHoughSpace.h.

References Double_t, fAssociatedTrackCand, fTrackerTask, PndFtsHoughTrackerTask::GetFtsTube(), PndFtsTube::GetPosition(), PndFtsTube::GetWireDirection(), PndFtsHoughTrackCand::getXLabSys(), and throwError().

Referenced by GetRawOrCalculatedHitPos().

396  {
397  if (0==fAssociatedTrackCand) throwError("No track cand associated with Hough space. Cannot calculate possible hit pos. from track model.");
398 
399  const PndFtsTube *ftsTube = fTrackerTask->GetFtsTube(myHit);
400  const TVector3 wireDirection = ftsTube->GetWireDirection();
401  const TVector3 wireCenter = ftsTube->GetPosition();
402 
403  const Double_t hitZLabSys = wireCenter.Z();
404 
405  // calculate xTM according to track model at hitZLabSys
406  const Double_t xTM = fAssociatedTrackCand->getXLabSys(hitZLabSys);
407  // calculate param which is needed for xStraw = xTM
408  // xTM = wireCenter.X() + param*wireDirection.X()
409  const Double_t param = ( xTM - wireCenter.X() ) / wireDirection.X();
410  // calculate corresponding yStraw
411  const Double_t yStraw = wireCenter.Y() + param*wireDirection.Y();
412 
413  TVector3 crossingPosition(xTM,yStraw,hitZLabSys);
414  return crossingPosition;
415 }
PndFtsHoughTrackCand * fAssociatedTrackCand
hits relevant for this Hough space
TVector3 GetWireDirection() const
Definition: PndFtsTube.cxx:83
void throwError(const TString s) const
For error reporting.
Double_t
TVector3 GetPosition() const
Definition: PndFtsTube.cxx:68
const PndFtsTube * GetFtsTube(const PndFtsHit *const myHit) const
Returns pointer to the FTS tube corresponding to input FTS hit.
Double_t getXLabSys(const Double_t zLabSys) const
PndFtsHoughTrackerTask * fTrackerTask
PndFtsHoughSpace::ClassDef ( PndFtsHoughSpace  ,
 
)
Double_t PndFtsHoughSpace::equationLineZxOrZy ( Double_t  thetaRad,
Double_t  hitZShifted,
Double_t  hitXLabSys 
)
inlineprivate

Definition at line 312 of file PndFtsHoughSpace.h.

References Double_t.

Referenced by AddHitsToTrackletByCalculating(), FillHoughSpace(), and FindAllPeaksScanPathsMergeBinsCalculatingPaths().

313  { // TODO: Check if that also works in zy plane
314  // calculate b which is the distance of point on line at z = zOffset from z axis
315  Double_t yVal = -tan(thetaRad)*hitZShifted+hitXLabSys;
316  return yVal;
317  }
Double_t
Double_t PndFtsHoughSpace::equationParabola ( Double_t  thetaRad,
Double_t  hitZShifted,
Double_t  hitXShifted,
Double_t  By 
)
inlineprivate

Definition at line 282 of file PndFtsHoughSpace.h.

References c, cos(), Double_t, n, and sin().

Referenced by AddHitsToTrackletByCalculating(), FillHoughSpace(), and FindAllPeaksScanPathsMergeBinsCalculatingPaths().

283  {
284  // for parabola equation
285  const Double_t n = 1.;
286  const Double_t e = 1.;
287  const Double_t c = n * e / 2.;
288 
289  Double_t yVal = 1. / c / By * (-hitZShifted * sin(thetaRad) + hitXShifted * cos(thetaRad))/ pow((hitZShifted * cos(thetaRad) + hitXShifted * sin(thetaRad)), 2);
290 
291  // next line is with rotation as in paper (I believe it is incorrect)
292  // value = 1. / c / By * (hitZshifted * sin(realtheta) - hitXshifted * cos(realtheta))/ pow((hitZshifted * cos(realtheta) + hitXshifted * sin(realtheta)), 2);
293  return yVal;
294  };
friend F32vec4 cos(const F32vec4 &a)
Definition: P4_F32vec4.h:112
friend F32vec4 sin(const F32vec4 &a)
Definition: P4_F32vec4.h:111
int n
Double_t
Double_t PndFtsHoughSpace::equationParabolaPz ( Double_t  thetaRad,
Double_t  hitZShifted,
Double_t  hitXShifted,
Double_t  By 
)
inlineprivate

Definition at line 296 of file PndFtsHoughSpace.h.

References c, cos(), Double_t, n, and sin().

Referenced by AddHitsToTrackletByCalculating(), FillHoughSpace(), and FindAllPeaksScanPathsMergeBinsCalculatingPaths().

297  {
298  // for parabola equation
299  const Double_t n = 1.;
300  const Double_t e = 1.;
301  const Double_t c = n * e / 2.;
302 
303  // Use shifted x and shifted z for parabola
304  Double_t yVal = c*By*pow((hitZShifted * cos(thetaRad) + hitXShifted * sin(thetaRad)), 2)/(-hitZShifted * sin(thetaRad) + hitXShifted * cos(thetaRad));
305 
306  // next line is with rotation as in paper (I believe it is incorrect)
307  // value = c*By*pow((hitZshifted * cos(realtheta) + hitXshifted * sin(realtheta)), 2)/(hitZshifted * sin(realtheta) - hitXshifted * cos(realtheta));
308 
309  return yVal;
310  };
friend F32vec4 cos(const F32vec4 &a)
Definition: P4_F32vec4.h:112
friend F32vec4 sin(const F32vec4 &a)
Definition: P4_F32vec4.h:111
int n
Double_t
Bool_t PndFtsHoughSpace::FillHoles ( const Int_t  lastBinX,
const Int_t  lastBinY,
const Int_t  currentBinY,
IdxPath ptrThetaYIdxPathVec 
)
inlineprivate

Makes sure there are no holes in the Hough space by filling them with a line.

Fills holes between (lastBinX, lastBinY) and (currentBinX, currentBinY) = (lastBinX+1, currentBinY) with a line.

Holes can only appear in the yDirection and cannot appear in theta direction: We go from one bin to the next. From lower theta values to the next higher value.

Parameters
lastBinX
lastBinY
currentBinY
ptrThetaYIdxPathVecPointer to the vector which contains the path through the Hough space. If any holes are filled, the interpolated values will be written into this vector.
Returns

Definition at line 338 of file PndFtsHoughSpace.cxx.

References fVerbose.

Referenced by FillHoughSpace().

344 {
345  // determine how many holes we have to fill
346  const Int_t nHolesToFill = abs(currentBinY-lastBinY)-1;
347  for (Int_t iCorrect = 1; iCorrect <= nHolesToFill; ++iCorrect)
348  {
349  const Int_t xCorrect = round(float(iCorrect)/float(nHolesToFill)); // gives 0 or 1
350  Int_t yCorrect;
351  if (currentBinY > lastBinY)
352  {
353  // we go up in the second value, therefore, we need to add to the yValue
354  yCorrect = iCorrect;
355  }
356  else
357  {
358  yCorrect = -iCorrect;
359  }
360 
361 
362  const Int_t interpolateBinX = lastBinX+xCorrect;
363  const Int_t interpolateBinY = lastBinY+yCorrect;
364 
365  const Int_t interpolatedGlobalBin = GetBin(interpolateBinX,interpolateBinY);
366  AddBinContent(interpolatedGlobalBin);
367 
368  // save interpolated globalBin into path vector
369  ptrThetaYIdxPathVec->push_back(interpolatedGlobalBin);
370 
371  if (8<fVerbose)
372  {
373  std::cout << "I am filling hole " << iCorrect << " of " << nHolesToFill << '\n';
374  std::cout << "interpolatedGlobalBin = " << interpolatedGlobalBin << '\n';
375  std::cout << "(lastBinX, lastBinY) = (" << lastBinX << ", " << lastBinY << ")" << '\n';
376  std::cout << "(lastBinX+1, currentBinY) = (" << lastBinX+1 << ", " << currentBinY << ")" << '\n';
377  std::cout << "xCorrect = " << xCorrect << " yCorrect = " << yCorrect << '\n';
378  std::cout << "(interpolateBinX, interpolateBinY) = (" << interpolateBinX << ", " << interpolateBinY << ")" << '\n';
379  }
380  }// for iCorrect
381  return kTRUE;
382 }
void PndFtsHoughSpace::FillHoughSpace ( )

Fills the Hough space using the equation which corresponds to the name of the Hough space.

If something goes wrong the function throws a runtime_error (probably Hough space name is set incorrectly).

!!! WARNING The theta values (in rad) are NOT the same as in the interaction point. They are always calculated relative to a shifted coordinate system and only 2-dimensional (either in z-x- or z-y-plane) !!!

The angle (theta in rad) to the z-axis in the z-x- or z-y-plane at a z reference position will be scanned from theta corresponding to lowest bin to theta corresponding to highest bin of x-axis.

TODO For each hit the "path" through the 2d histogram is saved for peak finding.

y component of B field will be read from field maps if fKeepBConstant is kFALSE.

Parameters
[in]Runningindex, only needed for Debugging output of Hough spaces

Definition at line 386 of file PndFtsHoughSpace.cxx.

References Bool_t, Double_t, equationLineZxOrZy(), equationParabola(), equationParabolaPz(), fHitThetaYIdxPath, Fill(), FillHoles(), fInterceptZx, fKeepBConstant, fTrackerTask, fVerbose, fZRefPos, getByFromBField(), getHitFromHS(), GetNHits(), GetRawOrCalculatedHitPos(), PndFtsHoughTrackerTask::GetSaveDebugInfo(), throwError(), TString, WriteHistoOfAllPaths(), WriteHistoOfAllPathsForEachMcTruthTrack(), and WriteHistoOfHoughSpace().

Referenced by PndFtsHoughTrackFinder::FindLinesBeforeDipoleZx(), PndFtsHoughTrackFinder::FindLinesBehindDipoleZx(), PndFtsHoughTrackFinder::FindMatchingParabolaToLineBeforeDipoleZxAndAddLineBehindDipole(), and PndFtsHoughTrackFinder::FindZyLineMatchingToLineParabolaLineInZx().

387 {
388  // make sure we have hits in the Hough space
389  if (0==GetNHits()){
390  if(1<fVerbose) Info("FillHoughSpace","No hits in Hough space.");
391  return;
392  }
393 
394 
395  // make Hough space according to the Hough transform I want to do
396  const TString option = GetName();
397 
398 
399  // for storing the value to be calculated in Hough transform (yValue = offset for line, yValue = Q/p_{zx} for parabola)
400  Double_t yVal = 0.;
401 
402  // store bin numbers for last and current entry (for making sure that there are no holes in the histogram)
403  Int_t globalBin = 0;
404  Int_t currentBinX = 0, currentBinY = 0, currentBinZ = 0;
405  Int_t lastBinX = 0, lastBinY = 0;
406 
407  Bool_t firstEntry = kTRUE; // is used to indicate when holes in histogram have to be filled, set this to kTRUE for the first entry FOR EACH HIT
408 
409 
410 
411  // This produces the Hough space for a parabola or a line (with constant B field or with B field read from field maps)
412  for (size_t iHit = 0; iHit < GetNHits(); iHit++)
413  {
414  firstEntry = kTRUE;
415  const PndFtsHit* myHit = getHitFromHS(iHit);
416 
417 
418  // get hit position
419  TVector3 hitPos = GetRawOrCalculatedHitPos(myHit);
420  Double_t hitXLabSys = hitPos.X();
421  Double_t hitYLabSys = hitPos.Y();
422  Double_t hitZLabSys = hitPos.Z();
423  Double_t hitXShifted = hitXLabSys - fInterceptZx; // shifts all x positions of hits so that they go through x=0 at z=zOffset (for parabola)
424  Double_t hitZShifted = hitZLabSys - fZRefPos; // z coordinate in local coordinate system (for parabola and for line)
425 
426 
427 
428  if (1<fVerbose) {
429  std::cout << "Doing " << option << " Hough transform for hit (hitZLabSys, hitXLabSys) = (" << hitZLabSys << ", " << hitXLabSys << ") cm";
430  if (kTRUE == fKeepBConstant) { std::cout << " ignoring B field maps\n"; } else { std::cout << " reading B field maps\n"; }
431  }
432 
433  // y component of B field
434  Double_t By = getByFromBField(hitXLabSys, hitYLabSys, hitZLabSys);
435 
436 
437  //------------------
438  // theta scan
439  //------------------
440 
441  // get indices for first and last bins on x-axis
442  Int_t iThetaFirst = fXaxis.GetFirst();
443  Int_t iThetaLast = fXaxis.GetLast();
444 
445  // save path for each hit
446  IdxPath globalBinPathVec;
447 
448  // calculate Hough transform for hit iHit
449  // for each hit a scan in theta is done by going through the x-axis of the Hough space from lower to higher values
450  for (Int_t iTheta = iThetaFirst; iTheta < iThetaLast; ++iTheta)
451  {
452  // get theta value corresponding to iTheta
453  Double_t thetaRad = fXaxis.GetBinCenter(iTheta); // theta has to be stored in rad
454  if (9<fVerbose) { std::cout << " for thetaRad = " << thetaRad << '\n'; }
455 
456  // calculate yVal depending on which Hough transform we need
457  if ("parabola" == option)
458  {
459  // Use shifted x and shifted z for parabola
460  yVal = equationParabola(thetaRad, hitZShifted, hitXShifted, By);
461  if (9<fVerbose) { std::cout << "Q/pzx = " << yVal; }
462  }
463  else if ("parabolapz" == option)
464  {
465  // Use shifted x and shifted z for parabola
466  yVal = equationParabolaPz(thetaRad, hitZShifted, hitXShifted, By);
467  if (9<fVerbose) { std::cout << "pz/Q = " << yVal; }
468  }
469  else if ( ("lineBeforeDipole" == option) || ("lineBehindDipole" == option) )
470  {
471  // Use real x and shifted z for line
472  yVal = equationLineZxOrZy(thetaRad, hitZShifted, hitXLabSys);
473  if (9<fVerbose) { std::cout << "xLP/PL = " << yVal; }
474  }
475  else if ("lineZy" == option)
476  {
477  // Use real x and shifted z for line
478  yVal = equationLineZxOrZy(thetaRad, hitZShifted, hitYLabSys);
479  if (9<fVerbose) { std::cout << "yLine = " << yVal; }
480  }
481  else
482  {
483  // should never happen
484  throwError("in FillHoughSpace! option " + option + " is not implemented!");
485  }
486 
487 
488 
489 
490 
491  // Insert "point" into Hough space and check in which bins we filled
492  globalBin = Fill(thetaRad,yVal);
493  if (5<fVerbose) { std::cout << "Hough point was filled into Hough space. globalbin = " << globalBin << " for option" << option <<'\n'; }
494  // Find currentBinX(=iTheta) and currentBinY from globalBin
495  GetBinXYZ(globalBin, currentBinX, currentBinY, currentBinZ);
496 
497 
498 
499  // if Fill was into a real bin (and not into over-/underflow) remove holes in Hough space (by assuming a straight line in between neighboring points)
500  // for each theta 1 yVal is calculated, so holes will only appear in yVal, not in theta
501  if (globalBin>=0) // -1 would mean over- or underflow
502  {
503  if (5<fVerbose) { std::cout << "OK! Hough point was NOT written to over- or underflow of histogram. Setting firstEntry to kFALSE now. "<< option <<'\n'; }
504 
505  // TODO Remove the following check for optimization, it should always be true
506  if (currentBinX != iTheta){
507  std::cerr << "\n\nError in FillHoughSpace! Hough point was filled into xBin " << currentBinX << " and not in " << iTheta << "\n";
508  std::cerr << "iThetaFirst = " << iThetaLast << " iThetaLast = " << iThetaLast << "\n";
509  std::cerr << "Over- or underflow on y-axis or FATAL error!\n\n\n";
510  }
511 
512  // fill holes if the current Hough point is not the first entry in Hough space for the hit
513  if (kFALSE == firstEntry)
514  {
515  if (5<fVerbose)
516  {
517  std::cout << "This is not the first point of the hit in the histogram. I will fix all holes which might be between this entry and the last one in the histogram"<<'\n';
518  }
519 
520  FillHoles(lastBinX, lastBinY, currentBinY, &globalBinPathVec);
521 
522  } // if not first entry to be written into histogram
523  else
524  {
525  // ++nHitsInHoughSpace; // count hits for making of Hough space (only once per hit)
526  if (5<fVerbose) { std::cout << "This is the first point of the hit in the histogram. I will not try to fix any holes in the " << option << " histogram"<<'\n';}
527  }
528 
529 
530  firstEntry = kFALSE;
531 
532  // save calculated globalBin into path vector
533  globalBinPathVec.push_back(globalBin);
534 
535  } // if NOT filled into over- or underflow
536  else
537  {
538  if (9<fVerbose) { std::cout << "Watch out! Point was written to over- or underflow of histogram. firstEntry is set to kTRUE. "<< option <<'\n'; }
539  firstEntry = kTRUE; // otherwise, algorithm connects first point which does not go into over-/underflow with (0,0)
540  }
541 
542  if (9<fVerbose) { std::cout << "currentBinY = " << currentBinY << " lastBinY = " << lastBinY << '\n'; }
543  lastBinX = currentBinX;
544  lastBinY = currentBinY;
545 
546 
547  } // for theta
548  // std::cout << "map before iHit " << iHit << ": " << fHitThetaYIdxPath << '\n';
549  // save the final path for the hit
550  if ( 0 < globalBinPathVec.size() ){
551  HitIdxPathPair hitPathPair( iHit, globalBinPathVec );
552  fHitThetaYIdxPath.insert( hitPathPair );
553  }
554  } // for iHit
555  if (1<fVerbose) std::cout << "map after all hits: " << fHitThetaYIdxPath << '\n';
556  if (0 < fTrackerTask->GetSaveDebugInfo()) {
560  }
561 }
std::vector< Int_t > IdxPath
Double_t equationParabola(Double_t thetaRad, Double_t hitZShifted, Double_t hitXShifted, Double_t By)
Double_t equationParabolaPz(Double_t thetaRad, Double_t hitZShifted, Double_t hitXShifted, Double_t By)
const TVector3 GetRawOrCalculatedHitPos(const PndFtsHit *const myHit) const
Bool_t FillHoles(const Int_t lastBinX, const Int_t lastBinY, const Int_t currentBinY, IdxPath *ptrThetaYIdxPathVec)
Makes sure there are no holes in the Hough space by filling them with a line.
Double_t getByFromBField(Double_t hitXLabSys, Double_t hitYLabSys, Double_t hitZLabSys)
void throwError(const TString s) const
For error reporting.
Double_t
Int_t GetSaveDebugInfo() const
Returns the verbosity level.
void WriteHistoOfAllPathsForEachMcTruthTrack() const
For writing out paths from hits which stem from the same MC truth tracks (how the Hough space would b...
void WriteHistoOfAllPaths() const
For writing out paths (how the Hough space was filled seen from one hit) as histograms (for debugging...
UInt_t GetNHits() const
HISThit_ene Fill(sum_hit_ene)
void WriteHistoOfHoughSpace() const
For writing out Hough spaces as histograms (for debugging purposes).
Double_t equationLineZxOrZy(Double_t thetaRad, Double_t hitZShifted, Double_t hitXLabSys)
HitIdxPathMap fHitThetaYIdxPath
const PndFtsHit * getHitFromHS(UInt_t index) const
PndFtsHoughTrackerTask * fTrackerTask
std::pair< Int_t, IdxPath > HitIdxPathPair
void PndFtsHoughSpace::filterInputHits ( )
private

Definition at line 286 of file PndFtsHoughSpace.cxx.

References AddHitToHS(), Double_t, fOnlyUseHitsFromZ, fOnlyUseHitsUpToZ, fTrackerTask, fUseNonSkewedStraws, fUseSkewedStraws, fVerbose, PndFtsHoughTrackerTask::GetFtsHit(), PndFtsHit::GetLayerID(), PndFtsHoughTrackerTask::GetNFtsHits(), GetNHits(), and PndFtsHit::GetSkewed().

Referenced by PndFtsHoughSpace().

287 {
288  if (3<fVerbose) {
289  std::cout << "All FTS hits in event " << fTrackerTask->GetNFtsHits() << "\n";
290  }
291 
292  for (int iHit = 0; iHit < fTrackerTask->GetNFtsHits(); iHit++)
293  {
294  const PndFtsHit *const myHit = fTrackerTask->GetFtsHit(iHit);
295 
296  // Skip hits from skewed or non-skewed straws (if I wish not to use them)
297  if (0 != myHit->GetSkewed())
298  {
299  // hit comes from skewed straw
300  if (kFALSE == fUseSkewedStraws)
301  {
302  if (3<fVerbose) {std::cout << "Skipping hit with index " << iHit << ", because it comes from a skewed straw! LayerID = " << myHit->GetLayerID() << '\n';}
303  continue;
304  }
305 
306  } else {
307  // hit comes from non-skewed straw
308  if (kFALSE == fUseNonSkewedStraws)
309  {
310  if (3<fVerbose) {std::cout << "Skipping hit with index " << iHit << ", because it comes from a non-skewed straw! LayerID = " << myHit->GetLayerID() << '\n';}
311  continue;
312  }
313 
314  }
315 
316 
317 
318  // only hits with z component between fOnlyUseHitsFromZ and fOnlyUseHitsUpToZ will be used in the Hough transform
319  const Double_t hitZLabSys = myHit->GetZ();
320  if ( (hitZLabSys < fOnlyUseHitsFromZ) || (hitZLabSys > fOnlyUseHitsUpToZ) ){
321  if (3<fVerbose) {std::cout << "Skipping hit with index " << iHit << " , because its z " << hitZLabSys << " is not in [" << fOnlyUseHitsFromZ << ", " << fOnlyUseHitsUpToZ << "]\n";}
322  continue;
323  }
324 
325  // add surviving hits to the hit vector (z coordinate as sorting parameter chosen)
326  if (2<fVerbose) { std::cout << "Adding hit with index " << iHit << " to the Hough space hit vector.\n"; }
327  AddHitToHS(iHit,hitZLabSys);
328 
329  } // for loop over all hits
330  if (1<fVerbose) std::cout << GetNHits() << " hits in Hough space.\n";
331 }
Double_t fOnlyUseHitsFromZ
Int_t GetLayerID() const
Definition: PndFtsHit.h:74
Int_t GetNFtsHits() const
Returns the event number.
Double_t
UInt_t GetNHits() const
const PndFtsHit * GetFtsHit(UInt_t hitId) const
Returns pointer to the hit with index hitId in the FTS hit array.
Double_t fOnlyUseHitsUpToZ
Int_t GetSkewed() const
Definition: PndFtsHit.h:75
void AddHitToHS(UInt_t hitId, Double_t rho)
PndFtsHoughTrackerTask * fTrackerTask
std::vector< PndFtsHoughTracklet > PndFtsHoughSpace::FindAllPeaksBinsWoMergingWithSearchWindow ( const UInt_t  minHeight,
const Int_t  vicinityLength = 0 
)

Finds all peaks that satisfy the minimum height requirement minHeight.

Parameters
minHeightonly bins of at least this height are regarded as possibly belonging to a peak.
Returns
tracklets containing all values found for the peaks in the Hough space. They will contain the hitIds of all hits that contribute to the peaks.

Definition at line 882 of file PndFtsHoughSpace.cxx.

References AddHitsToTrackletByCalculating(), Double_t, fTrackerTask, fVerbose, fZRefPos, GetEntries(), max(), PrintFoundTracklets(), and PndFtsHoughTracklet::SetHoughTransformResults().

883 {
884  std::vector<PndFtsHoughTracklet> tracklets; // for output
885 
886  // check if Hough space has at least one entry
887  if (1>GetEntries())
888  {
889  if(1<fVerbose) std::cout << "Hough Space is empty. No peak can be found. Return empty tracklet vector." << '\n';
890  return tracklets;
891  }
892 
893 
894  // peak finder based on weighted means (only for 2D histograms implemented)
895 
896 
897  // the following is an adaptation of the TH1::GetMaximumBin() code
898 
899 
900 
901  // define vicinityLength for search window which determines an effective height of the bin
902  // set vicinityLength 0 for not using a search window
903  // search window has size (2*vicinityLength+1)^2
904 
905 
906  // move search window over histogram and select highest value
907  Int_t locmax, locmay, locmaz; // location of maximum (x,y,z)
908 
909  // -*-*-*-*-*Return location of bin with maximum value in the range*-*
910  // ======================================================
911  Int_t binNumber, binx, biny;
912  //, binz=0; //[R.K. 01/2017] unused variable?
913  // get values for first and last bins on each axis and take into account that we might want a search window (make sure search window stays within histogram)
914  const Int_t xfirst = fXaxis.GetFirst()+vicinityLength;
915  const Int_t xlast = fXaxis.GetLast()-vicinityLength;
916  const Int_t yfirst = fYaxis.GetFirst()+vicinityLength;
917  const Int_t ylast = fYaxis.GetLast()-vicinityLength;
918  // Int_t zfirst = fZaxis->GetFirst()+vicinityLength;
919  // Int_t zlast = fZaxis->GetLast()-vicinityLength;
920 
921  // find all peaks that have a height >= minHeight
922  Double_t currentHeight;
923  locmax = locmay = locmaz = 0;
924  // for (binz=zfirst;binz<=zlast;binz++) {
925  for (biny=yfirst;biny<=ylast;biny++) {
926  for (binx=xfirst;binx<=xlast;binx++) {
927  currentHeight = 0.;
928  // iterate over vicinity
929  for (Int_t xVicinityBin = -vicinityLength; xVicinityBin <= vicinityLength; ++xVicinityBin)
930  {
931  for (Int_t yVicinityBin = -vicinityLength; yVicinityBin <= vicinityLength; ++yVicinityBin)
932  {
933  binNumber = GetBin(binx+xVicinityBin,biny+yVicinityBin); //,binz);
934  currentHeight += 1./(1.+std::max(abs(xVicinityBin),abs(yVicinityBin)))*GetBinContent(binNumber); // linear, unendlich norm
935  // currentHeight += 1./(1.+abs(xVicinity) +abs(yVicinity))*houghspace->GetBinContent(binNumber); // linear
936  // currentHeight += 1./(1.+pow(max(xVicinity,yVicinity),2))*houghspace->GetBinContent(binNumber); // quadratic, unendlich norm
937  }
938  }
939  if (currentHeight >= minHeight) {
940  locmax = binx;
941  locmay = biny;
942  // locmaz = binz;
943  // get values corresponding to the peak
944  Double_t peakThetaVal = fXaxis.GetBinCenter(locmax);
945  Double_t peakSecondVal = fYaxis.GetBinCenter(locmay);
946 
947  //Int_t binmaxglobal = Fill(peakThetaVal, peakSecondVal, 0); // returns binnumber without modifying the histogram //[R.K. 01/2017] unused variable?
948  Double_t peakThetaHw = fXaxis.GetBinWidth(peakThetaVal)/2.;
949  Double_t peakSecondHw = fYaxis.GetBinWidth(peakSecondVal)/2.;
950 
951  // create tracklet and push it back to output
952  PndFtsHoughTracklet currentTracklet(fZRefPos, fTrackerTask);
953  currentTracklet.SetHoughTransformResults(peakThetaVal, peakSecondVal, currentHeight, peakThetaHw, peakSecondHw);
954 
955  // Add hits to tracklet
956  AddHitsToTrackletByCalculating(&currentTracklet, locmax);
957 
958  tracklets.push_back(currentTracklet);
959  } // height is big enough
960  } // x loop
961  } // y loop
962  // } // z loop
963 
964 
965  if (1<fVerbose) PrintFoundTracklets(tracklets);
966  return tracklets;
967 }
void AddHitsToTrackletByCalculating(PndFtsHoughTracklet *currentTracklet, Int_t locmax)
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:26
Class for saving the result of one Hough transform for FTS PR.
Double_t
cout<<"will loop over "<< t-> GetEntries()
Definition: root2ascii.C:17
void PrintFoundTracklets(const std::vector< PndFtsHoughTracklet > &tracklets) const
PndFtsHoughTrackerTask * fTrackerTask
std::vector< PndFtsHoughTracklet > PndFtsHoughSpace::FindAllPeaksBlanko ( const UInt_t  minHeight)

Finds all peaks that satisfy the minimum height requirement minHeight.

Parameters
minHeightonly bins of at least this height are regarded as possibly belonging to a peak.
Returns
tracklets containing all values found for the peaks in the Hough space. They will contain the hitIds of all hits that contribute to the peaks.

Definition at line 1455 of file PndFtsHoughSpace.cxx.

References fVerbose, GetEntries(), PrintFoundTracklets(), and throwError().

1456 {
1457  std::vector<PndFtsHoughTracklet> tracklets; // for output
1458 
1459  // check if Hough space has at least one entry
1460  if (1>GetEntries())
1461  {
1462  if(1<fVerbose) std::cout << "Hough Space is empty. No peak can be found. Return empty tracklet vector." << '\n';
1463  return tracklets;
1464  }
1465 
1466 
1467  // code goes here
1468  throwError("This peak finder is not implemented!");
1469 
1470 
1471 
1472 
1473  if (1<fVerbose) PrintFoundTracklets(tracklets);
1474  return tracklets;
1475 }
void throwError(const TString s) const
For error reporting.
cout<<"will loop over "<< t-> GetEntries()
Definition: root2ascii.C:17
void PrintFoundTracklets(const std::vector< PndFtsHoughTracklet > &tracklets) const
std::vector< PndFtsHoughTracklet > PndFtsHoughSpace::FindAllPeaksScanPathsMergeBins ( const UInt_t  minHeight)

Finds all peaks that satisfy the minimum height requirement minHeight.

Parameters
minHeightonly bins of at least this height are regarded as possibly belonging to a peak.
Returns
tracklets containing all values found for the peaks in the Hough space. They will contain the hitIds of all hits that contribute to the peaks.

Definition at line 973 of file PndFtsHoughSpace.cxx.

References PndFtsHoughSpacePeak::addBin(), PndTrackCand::AddHit(), Bool_t, Double_t, fFtsBranchId, fHitThetaYIdxPath, fTrackerTask, fVerbose, fZRefPos, GetEntries(), PndFtsHoughSpacePeak::getHeight(), getHitFromHS(), getHitIdFromHS(), GetRawOrCalculatedHitPos(), PndFtsHoughTrackerTask::GetSaveDebugInfo(), PndFtsHoughSpacePeak::isFinished(), max(), min(), PrintFoundTracklets(), PndFtsHoughSpacePeak::replaceBins(), PndFtsHoughSpacePeak::setFinished(), PndFtsHoughTracklet::SetHoughTransformResults(), and WriteHistoOfAllPeaks().

Referenced by PndFtsHoughTrackFinder::FindZyLineMatchingToLineParabolaLineInZx().

974 {
975  std::vector<PndFtsHoughTracklet> tracklets; // for output
976 
977  // check if Hough space has at least one entry
978  if (1>GetEntries())
979  {
980  if(1<fVerbose) std::cout << "Hough Space is empty. No peak can be found. Return empty tracklet vector." << '\n';
981  return tracklets;
982  }
983 
984 
985 
986  // this peak finder is only implemented for 2D histograms
987 
988  // for each hit scan the Hough space along the hit's path -> this reduces the 2d peak finding to nHits 1d problems plus peak merging.
989  // require bin height >= minHeight
990  // and that we are on a rising edge
991 
992 
993  std::vector< PndFtsHoughSpacePeak > peaksForOneHit; // stores (possible) peaks for one hit
994  std::vector< PndFtsHoughSpacePeak > mergedPeaksForAllHits; // stores merged peaks for all hits
995  mergedPeaksForAllHits.clear();
996 
997  // hit loop
998  for (HitIdxPathMap::const_iterator itMap = fHitThetaYIdxPath.begin(); itMap != fHitThetaYIdxPath.end(); ++itMap){
999  const Int_t hitIdx = itMap->first;
1000  IdxPath path = itMap->second;
1001  peaksForOneHit.clear();
1002 
1003  // loop over bins along the path
1004  for (int iGlobalBin = 0; iGlobalBin < (int)path.size(); ++iGlobalBin){
1005  // current bin
1006  const Int_t currBinNumber = path[iGlobalBin];
1007  const Int_t currHeight = GetBinContent(currBinNumber);
1008 
1009  // check if we already found a peak candidate
1010  const Int_t nPeaksSoFar = peaksForOneHit.size();
1011  if ( 0 < nPeaksSoFar ){ // if we already have a peak, we might need to continue building it
1012  PndFtsHoughSpacePeak& currPeak = peaksForOneHit[nPeaksSoFar-1]; // get last peak
1013  if ( kFALSE == currPeak.isFinished() ){ // continue building up current peak
1014  if ( currHeight < currPeak.getHeight() ) currPeak.setFinished(kTRUE);
1015  if ( currHeight == currPeak.getHeight() ) currPeak.addBin(currBinNumber, hitIdx);
1016  if ( currHeight > currPeak.getHeight() ) currPeak.replaceBins(currHeight, currBinNumber, hitIdx);
1017  continue; // do not create a new peak as we were building an old one
1018  }
1019  } // we have already >= 1 peaks
1020 
1021  if ( (int)minHeight <= currHeight ) { // Bin could belong to a peak
1022 
1023 
1024  // Make sure we are not on a falling edge by checking that the previous position was strictly lower!
1025  // previous bin
1026  const Int_t prevIdx = std::max(0, iGlobalBin-1); // make sure we stay within bounds of vector
1027  const Int_t prevBinNumber = path[prevIdx];
1028  const Int_t prevHeight = GetBinContent(prevBinNumber);
1029 
1030  Bool_t rising = prevHeight < currHeight;
1031  if ( 0 == iGlobalBin ) rising = kTRUE; // always save if we are at the beginning
1032 
1033  if ( kTRUE == rising ){ // we are on rising edge
1034  // Add a new peak (only if we do not continue a nonfinished existing one)
1035  // either we did not have any peaks or the last peak was already finished
1036  PndFtsHoughSpacePeak newPeak(currHeight, currBinNumber, hitIdx);
1037  peaksForOneHit.push_back(newPeak);
1038  }
1039  }
1040 
1041 
1042  }// loop over bins along the path
1043 
1044  // now merge peaksForOneHit with mergedPeaksForAllHits
1045  // loop over found peaks for latest hit and all merged hits, compare if they have overlaps, if so merge
1046  for (UInt_t iPeaksForOneHit = 0; iPeaksForOneHit < peaksForOneHit.size(); ++iPeaksForOneHit){
1047  Bool_t merged = kFALSE;
1048  for (UInt_t iPeaksForAllHits = 0; iPeaksForAllHits < mergedPeaksForAllHits.size(); ++iPeaksForAllHits){
1049  if ( mergedPeaksForAllHits[iPeaksForAllHits].binsOverlapWith(peaksForOneHit[iPeaksForOneHit]) ) {
1050  mergedPeaksForAllHits[iPeaksForAllHits].mergeWith(peaksForOneHit[iPeaksForOneHit]);
1051  merged = kTRUE;
1052  //continue; // skip checking with all other peaks as they cannot overlap anymore (TODO Check if that is true)
1053  }
1054  }
1055  if ( kFALSE==merged ) mergedPeaksForAllHits.push_back(peaksForOneHit[iPeaksForOneHit]); // add peaks which could not be merged with preexisting ones
1056  }
1057  }// hit loop
1058 
1059  if ( 0 < fTrackerTask->GetSaveDebugInfo() ) WriteHistoOfAllPeaks(mergedPeaksForAllHits);
1060 
1061 
1062  // Build up tracklets from peaks by going through vector of merged peaks
1063  for (UInt_t iPeaks = 0; iPeaks < mergedPeaksForAllHits.size(); ++iPeaks){
1064  const Double_t currentHeight = mergedPeaksForAllHits[iPeaks].getHeight();
1065  const std::set<Int_t>& binsInPeak = mergedPeaksForAllHits[iPeaks].getBins();
1066  // calculate center and halfwidth (HW) in theta and in secondVal for all global bins in peak
1067  // save min and max values
1068  Double_t minThetaVal = 0., maxThetaVal = 0., minSecondVal = 0., maxSecondVal = 0.;
1069  for (std::set< Int_t >::iterator itBin = binsInPeak.begin(); itBin != binsInPeak.end(); ++itBin){
1070  Int_t currentBinX = 0, currentBinY = 0, currentBinZ = 0;
1071  GetBinXYZ(*itBin, currentBinX, currentBinY, currentBinZ); // get bin numbers for x, y (and z) axis
1072  // get values for corresponding to global bin number
1073  const Double_t currThetaVal = fXaxis.GetBinCenter(currentBinX);
1074  const Double_t currSecondVal = fYaxis.GetBinCenter(currentBinY);
1075 
1076  if ( binsInPeak.begin() == itBin ){ // initialize values if this is the first bin
1077  minThetaVal = currThetaVal;
1078  maxThetaVal = currThetaVal;
1079  minSecondVal = currSecondVal;
1080  maxSecondVal = currSecondVal;
1081  } else { // save min and max
1082  minThetaVal = std::min(minThetaVal,currThetaVal);
1083  maxThetaVal = std::max(maxThetaVal,currThetaVal);
1084  minSecondVal = std::min(minSecondVal,currSecondVal);
1085  maxSecondVal = std::max(maxSecondVal,currSecondVal);
1086  }
1087  }
1088 
1089  const Double_t peakThetaVal = (maxThetaVal + minThetaVal)/2.;
1090  const Double_t peakSecondVal = (maxSecondVal + minSecondVal)/2.;
1091  const Double_t peakThetaHw = (maxThetaVal - minThetaVal)/2. + fXaxis.GetBinWidth(peakThetaVal)/2.;
1092  const Double_t peakSecondHw = (maxSecondVal - minSecondVal)/2. + fYaxis.GetBinWidth(peakSecondVal)/2.;
1093 
1094 
1095 
1096  // create tracklet, add hits and push it back to output
1097  PndFtsHoughTracklet currentTracklet(fZRefPos, fTrackerTask);
1098  currentTracklet.SetHoughTransformResults(peakThetaVal, peakSecondVal, currentHeight, peakThetaHw, peakSecondHw);
1099  // add hits to tracklet
1100  const std::set<Int_t>& hitIdsInPeak = mergedPeaksForAllHits[iPeaks].getHitIds();
1101  for (std::set< Int_t >::iterator itHitId= hitIdsInPeak.begin(); itHitId != hitIdsInPeak.end(); ++itHitId){
1102  const Int_t hitIndex = getHitIdFromHS(*itHitId);
1103  const PndFtsHit* myHit = getHitFromHS(*itHitId);
1104  // get hit position
1105  const TVector3 hitPos = GetRawOrCalculatedHitPos(myHit);
1106  Double_t hitZLabSys = hitPos.Z();
1107  currentTracklet.AddHit(fFtsBranchId, hitIndex, hitZLabSys);
1108  }
1109  tracklets.push_back(currentTracklet);
1110  }
1111 
1112 
1113  if (1<fVerbose) PrintFoundTracklets(tracklets);
1114  return tracklets;
1115 }
Bool_t isFinished() const
std::vector< Int_t > IdxPath
void setFinished(Bool_t newVal)
Class for saving peaks of a Hough space.
const TVector3 GetRawOrCalculatedHitPos(const PndFtsHit *const myHit) const
void WriteHistoOfAllPeaks(const std::vector< PndFtsHoughSpacePeak > &peaksToPlot) const
For writing out peaks in Hough spaces as histograms (for debugging purposes).
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:26
Class for saving the result of one Hough transform for FTS PR.
void replaceBins(Int_t height, Int_t firstBin, Int_t firstHitIdx)
Double_t
Int_t GetSaveDebugInfo() const
Returns the verbosity level.
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:25
Int_t fFtsBranchId
@ brief FTS Hits
Int_t getHitIdFromHS(UInt_t index) const
cout<<"will loop over "<< t-> GetEntries()
Definition: root2ascii.C:17
HitIdxPathMap fHitThetaYIdxPath
void addBin(Int_t binNumber, Int_t hitIdx)
void PrintFoundTracklets(const std::vector< PndFtsHoughTracklet > &tracklets) const
const PndFtsHit * getHitFromHS(UInt_t index) const
PndFtsHoughTrackerTask * fTrackerTask
std::vector< PndFtsHoughTracklet > PndFtsHoughSpace::FindAllPeaksScanPathsMergeBinsCalculatingPaths ( const UInt_t  minHeight)

Finds all peaks that satisfy the minimum height requirement minHeight.

Parameters
minHeightonly bins of at least this height are regarded as possibly belonging to a peak.
Returns
tracklets containing all values found for the peaks in the Hough space. They will contain the hitIds of all hits that contribute to the peaks.

Definition at line 1120 of file PndFtsHoughSpace.cxx.

References PndTrackCand::AddHit(), Double_t, equationLineZxOrZy(), equationParabola(), equationParabolaPz(), fFtsBranchId, fHitId, fInterceptZx, fTrackerTask, fVerbose, fZRefPos, getByFromBField(), GetEntries(), getHitFromHS(), GetNHits(), GetRawOrCalculatedHitPos(), max(), min(), PrintFoundTracklets(), PndFtsHoughTracklet::SetHoughTransformResults(), throwError(), and TString.

1121 {
1122  std::vector<PndFtsHoughTracklet> tracklets; // for output
1123 
1124  // check if Hough space has at least one entry
1125  if (1>GetEntries())
1126  {
1127  if(1<fVerbose) std::cout << "Hough Space is empty. No peak can be found. Return empty tracklet vector." << '\n';
1128  return tracklets;
1129  }
1130 
1131 
1132  // code goes here
1133  throwError("This peak finder is not fully implemented!");
1134 
1135  // peak finder only for 2D histograms implemented
1136 
1137  // the following is an adaptation of the TH1::GetMaximumBin() code
1138 
1139 
1140  // get values for first and last bins on each axis
1141  Int_t xFirstBin = fXaxis.GetFirst();
1142  Int_t xLastBin = fXaxis.GetLast();
1143  Int_t yFirstBin = fYaxis.GetFirst();
1144  Int_t yLastBin = fYaxis.GetLast();
1145  // Int_t zfirst = fZaxis->GetFirst();
1146  // Int_t zlast = fZaxis->GetLast();
1147 
1148  // find all peaks that have a height >= minHeight
1149  // go from low to high in theta <- SUPER IMPORTANT
1150  Int_t currBinNumber;
1151  Double_t currHeight;
1152  Int_t peakBinX = 0;
1153  Int_t peakBinY = 0;
1154  //Int_t peakBinZ = 0; // location of maximum (x,y,z) //[R.K. 01/2017] unused variable?
1155 
1156  for (Int_t currBinX=xFirstBin; currBinX<=xLastBin; ++currBinX) {
1157  for (Int_t currBinY=yFirstBin; currBinY<=yLastBin; ++currBinY) {
1158  // for (binz=zfirst;binz<=zlast;binz++) {
1159 
1160  currBinNumber = GetBin(currBinX,currBinY); // binz
1161  currHeight = GetBinContent(currBinNumber);
1162  if (minHeight > currHeight) {
1163  // currBinNumber is not high enough to be considered a peak
1164  SetBinContent(currBinNumber,0); // DEBUG: Uncomment this if you want to produce nice Hough space plots for demonstration
1165  continue;
1166  }
1167  // I found a potential peak, so I check the neighbors in next higher theta bins
1168  // I save the currently highest peak
1169  // I set the last visited peak = current peak and move to the next neighbor
1170  // if neighbor < highest peak and neighbor <= last peak, but above the minHeight, I set it to 0. I save its height as the last height.
1171 
1172  // if neighbor is higher than the last peak, I set the last visited bin to 0 and move on
1173  // if neighbor is the same height as last peak, I find the middle and set all others to 0 and I widen the errors of the middle bin
1174 
1175  Int_t iBinX = 0; // for moving to neighbors in x direction
1176 
1177  // save info of highest peak found while searching neighbors
1178  Int_t combinedPeakBinXLow=currBinX; // saves in which x (thetaRad) bin a peak starts
1179  Int_t combinedPeakBinXHigh=currBinX; // saves in which x (thetaRad) bin a peak ends
1180  Double_t combinedPeakHeight=currHeight;
1181 
1182  // save info of last visited neighbor
1183  //Int_t lastVisitedBinX = currBinX; //[R.K. 01/2017] unused variable
1184  //Int_t lastVisitedBinNumber = currBinNumber; //[R.K. 01/2017] unused variable
1185  Double_t lastVisitedHeight = currHeight;
1186 
1187  // storing the current neighbor bin
1188  Int_t currNeighborBinX = currBinX;
1189  Int_t currNeighborBinNumber = currBinNumber;
1190  Double_t currNeighborHeight = currHeight;
1191 
1192  do{
1193  ++iBinX; // to move along the x bins
1194  // set current neighbor
1195  currNeighborBinX = currBinX+iBinX;
1196  if (currNeighborBinX>xLastBin){
1197  break;
1198  }
1199  currNeighborBinNumber = GetBin(currNeighborBinX,currBinY); // binz
1200  currNeighborHeight = GetBinContent(currNeighborBinNumber);
1201 
1202  if (minHeight > currNeighborHeight){
1203  // end of peak region in x direction found, I can get out of the loop
1204  SetBinContent(currNeighborBinNumber,0); // DEBUG: Uncomment this if you want to produce nice Hough space plots for demonstration
1205  break;
1206  }
1207 
1208  if (currNeighborHeight > combinedPeakHeight){
1209  // actually peak starts with neighbor (or even later), but current bin is not in peak
1210  for (Int_t xBinToDel=combinedPeakBinXLow; xBinToDel<= combinedPeakBinXHigh; ++xBinToDel){
1211  Int_t BinNumberToDel = GetBin(xBinToDel,currBinY);
1212  SetBinContent(BinNumberToDel,0);
1213  }
1214  combinedPeakBinXLow = currNeighborBinX;
1215  combinedPeakBinXHigh = currNeighborBinX;
1216  combinedPeakHeight = currNeighborHeight;
1217  } else if (currNeighborHeight < combinedPeakHeight){
1218  if (currNeighborHeight <= lastVisitedHeight){
1219  // peak is dropping, delete current bin (which is at the falling edge of the peak)
1220  SetBinContent(currNeighborBinNumber,0);
1221  } else {
1222  // next peak starts rising, I can end the loop
1223  break;
1224  }
1225  } else if (currNeighborHeight == combinedPeakHeight){
1226  // peak is spread over several bins
1227  combinedPeakBinXHigh = currNeighborBinX;
1228  }
1229  //lastVisitedBinX = currNeighborBinX; //[R.K. 01/2017] unused variable
1230  //lastVisitedBinNumber = currNeighborBinNumber; //[R.K. 01/2017] unused variable
1231  lastVisitedHeight = currNeighborHeight;
1232 
1233  } while(kTRUE);
1234 
1235 
1236  // DEBUG: uncomment this if you want to produce nice Hough space plots for demonstration
1237  // remove the peak which was found, otherwise it (or parts of it) might be found again
1238  for (Int_t xBinToDel=combinedPeakBinXLow; xBinToDel<= combinedPeakBinXHigh; ++xBinToDel){
1239  Int_t BinNumberToDel = GetBin(xBinToDel,currBinY);
1240  SetBinContent(BinNumberToDel,0);
1241  }
1242 
1243 
1244 
1245 
1246  // peak is in the middle
1247  peakBinX = (combinedPeakBinXHigh+combinedPeakBinXLow)/2; // if sum is not an even number, I have to correct for that later
1248  peakBinY = currBinY;
1249  // locmaz = binz;
1250  // get values corresponding to the peak
1251  Double_t peakThetaVal = fXaxis.GetBinCenter(peakBinX);
1252  Double_t peakSecondVal = fYaxis.GetBinCenter(peakBinY);
1253 
1254  // correct peak value if mean for peak cannot be divided by 2 without remainder
1255  if (0!=(combinedPeakBinXHigh+combinedPeakBinXLow)%2){
1256  peakThetaVal+=fXaxis.GetBinWidth(peakThetaVal)/2.;
1257  }
1258 
1259  // get full width of peak = (highest bin + halfwidth) - (lowest bin - halfwidth)
1260  Double_t combinedPeakThetaLowEdge = fXaxis.GetBinCenter(combinedPeakBinXLow) - fXaxis.GetBinWidth(combinedPeakBinXLow)/2.;
1261  Double_t combinedPeakThetaHighEdge = fXaxis.GetBinCenter(combinedPeakBinXHigh) + fXaxis.GetBinWidth(combinedPeakBinXHigh)/2.;
1262 
1263  Double_t peakThetaHw = (combinedPeakThetaHighEdge-combinedPeakThetaLowEdge)/2.;
1264  Double_t peakSecondHw = fYaxis.GetBinWidth(peakSecondVal)/2.;
1265 
1266  // create tracklet and push it back to output
1267  PndFtsHoughTracklet currentTracklet(fZRefPos, fTrackerTask);
1268  currentTracklet.SetHoughTransformResults(peakThetaVal, peakSecondVal, currHeight, peakThetaHw, peakSecondHw);
1269 
1271  // TODO this is messy, because the code is very similar to FillHoughSpace. Probably, I should find a way to merge it
1272  // add hits which are in the peak to the tracklet
1273  // 1 calculate the 2nd value for the next higher/lower theta bin of combined peak theta
1274  // 2 If peak 2nd value is within [min hit 2nd value - half width, max hit 2nd value + half width] add the hit to the tracklet
1275  // 3 otherwise the hit is not in the peak
1276 
1277  // This is more complicated to check, but also true
1278  // A calculate the 2nd value for peak theta
1279  // B If hit 2nd value is within [peak 2nd value - peakSecondHw, peak 2nd value + peakSecondHw] add the hit
1280  // C If hit 2nd value is < peak 2nd value - peakSecondHw, hit is in peak if the 2nd value of the next higher/lower theta bin is >= peak 2nd value
1281  // D If hit 2nd value is > peak 2nd value + peakSecondHw, hit is in peak if the 2nd value of the next lower/higher theta bin is <= peak 2nd value
1282  // E otherwise the hit is not in the peak
1283 
1284  // 1 calculate the 2nd value for the next higher/lower theta bin of peak theta
1285  UInt_t thetaBinLo = combinedPeakBinXLow-1;
1286  UInt_t thetaBinHi = combinedPeakBinXHigh+1;
1287  // special case if we are at the edge of the Hough space
1288  if ((int)thetaBinLo>xFirstBin) {
1289  thetaBinLo=xFirstBin;
1290  }
1291  if ((int)thetaBinHi>xLastBin) {
1292  thetaBinHi=xLastBin;
1293  }
1294 
1295  // get theta values
1296  const Double_t thetaRadLo = fXaxis.GetBinCenter(thetaBinLo);
1297  const Double_t thetaRadHi = fXaxis.GetBinCenter(thetaBinHi);
1298 
1299  // for storing the values to be calculated in Hough transform (yValue = offset for line, yValue = Q/pzx for parabola)
1300  Double_t yValLo = 0.;
1301  Double_t yValHi = 0.;
1302 
1303  for (size_t iHit = 0; iHit < GetNHits(); iHit++)
1304  {
1305  const PndFtsHit* myHit = getHitFromHS(iHit);
1306 
1307  // get hit position
1308  const TVector3 hitPos = GetRawOrCalculatedHitPos(myHit);
1309 
1310 
1311  Double_t hitXLabSys = hitPos.X();
1312  Double_t hitYLabSys = hitPos.Y();
1313  Double_t hitZLabSys = hitPos.Z();
1314  Double_t hitXShifted = hitXLabSys - fInterceptZx; // shifts all x positions of hits so that they go through x=0 at z=zOffset (for parabola)
1315  Double_t hitZShifted = hitZLabSys - fZRefPos; // z coordinate in local coordinate system (for parabola and for line)
1316 
1317  // y component of B field
1318  Double_t By = getByFromBField(hitXLabSys, hitYLabSys, hitZLabSys);
1319 
1320  const TString option = GetName();
1321  if ("parabola" == option)
1322  {
1323  // Use shifted x and shifted z for parabola
1324  yValLo = equationParabola(thetaRadLo, hitZShifted, hitXShifted, By);
1325  yValHi = equationParabola(thetaRadHi, hitZShifted, hitXShifted, By);
1326  if (9<fVerbose) {
1327  std::cout << "Q/pzx = " << yValLo << '\n';
1328  std::cout << "Q/pzx = " << yValHi << '\n';
1329  }
1330  }
1331  else if ("parabolapz" == option)
1332  {
1333  yValLo = equationParabolaPz(thetaRadLo, hitZShifted, hitXShifted, By);
1334  yValHi = equationParabolaPz(thetaRadHi, hitZShifted, hitXShifted, By);
1335 
1336  if (9<fVerbose) {
1337  std::cout << "pz/Q = " << yValLo << '\n';
1338  std::cout << "pz/Q = " << yValHi << '\n';
1339  }
1340  }
1341  else if ( ("lineBeforeDipole" == option) || ("lineBehindDipole" == option) )
1342  {
1343  // Use real x and shifted z for line
1344 
1345  yValLo = equationLineZxOrZy(thetaRadLo, hitZShifted, hitXLabSys);
1346  yValHi = equationLineZxOrZy(thetaRadHi, hitZShifted, hitXLabSys);
1347 
1348  if (9<fVerbose) {
1349  std::cout << "xLP/PL = " << yValLo << '\n';
1350  std::cout << "xLP/PL = " << yValHi << '\n';
1351  }
1352  }
1353  else if ("lineZy" == option)
1354  {
1355  // Use real x and shifted z for line
1356 
1357  yValLo = equationLineZxOrZy(thetaRadLo, hitZShifted, hitYLabSys);
1358  yValHi = equationLineZxOrZy(thetaRadHi, hitZShifted, hitYLabSys);
1359 
1360  if (9<fVerbose) {
1361  std::cout << "xLP = " << yValLo << '\n';
1362  std::cout << "xLP = " << yValHi << '\n';
1363  }
1364  }
1365  else
1366  {
1367  throwError("Error in FillHoughSpace! option " + option + " is not implemented!");
1368  }
1369 
1370 
1371  // 2 If peak 2nd value is within [min hit 2nd value - half width, max hit 2nd value + half width] add the hit to the tracklet
1372  const Double_t yMin = std::min(yValLo,yValHi);
1373  const Double_t yMax = std::max(yValLo,yValHi);
1374  const Double_t yMinHw = fYaxis.GetBinWidth(yMin)/2.;
1375  const Double_t yMaxHw = fYaxis.GetBinWidth(yMax)/2.;
1376 
1377 
1378 
1379  if ( (yMin-yMinHw <= peakSecondVal) && (yMax+yMaxHw >= peakSecondVal) ){
1380  Int_t hitIndex = fHitId.at(iHit).GetHitId();
1381  currentTracklet.AddHit(fFtsBranchId, hitIndex, hitZLabSys);
1382  }
1383 
1384  } // loop over hits
1386  tracklets.push_back(currentTracklet);
1387  // } // z loop
1388  } // y loop
1389  } // x loop
1390 
1391  if (1<fVerbose) PrintFoundTracklets(tracklets);
1392  return tracklets;
1393 }
Double_t equationParabola(Double_t thetaRad, Double_t hitZShifted, Double_t hitXShifted, Double_t By)
Double_t equationParabolaPz(Double_t thetaRad, Double_t hitZShifted, Double_t hitXShifted, Double_t By)
const TVector3 GetRawOrCalculatedHitPos(const PndFtsHit *const myHit) const
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:26
std::vector< PndTrackCandHit > fHitId
Double_t getByFromBField(Double_t hitXLabSys, Double_t hitYLabSys, Double_t hitZLabSys)
void throwError(const TString s) const
For error reporting.
Class for saving the result of one Hough transform for FTS PR.
Double_t
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:25
UInt_t GetNHits() const
Int_t fFtsBranchId
@ brief FTS Hits
Double_t equationLineZxOrZy(Double_t thetaRad, Double_t hitZShifted, Double_t hitXLabSys)
cout<<"will loop over "<< t-> GetEntries()
Definition: root2ascii.C:17
void PrintFoundTracklets(const std::vector< PndFtsHoughTracklet > &tracklets) const
const PndFtsHit * getHitFromHS(UInt_t index) const
PndFtsHoughTrackerTask * fTrackerTask
std::vector< PndFtsHoughTracklet > PndFtsHoughSpace::FindAllPeaksWithTSpectrum2 ( const UInt_t  minHeight)

Finds all peaks that satisfy the minimum height requirement minHeight.

Parameters
minHeightonly bins of at least this height are regarded as possibly belonging to a peak.
Returns
tracklets containing all values found for the peaks in the Hough space. They will contain the hitIds of all hits that contribute to the peaks.

Definition at line 1398 of file PndFtsHoughSpace.cxx.

References Double_t, Fill(), fTrackerTask, fVerbose, fZRefPos, GetEntries(), PrintFoundTracklets(), s, PndFtsHoughTracklet::SetHoughTransformResults(), and throwError().

1399 {
1400  std::vector<PndFtsHoughTracklet> tracklets; // for output
1401 
1402  // check if Hough space has at least one entry
1403  if (1>GetEntries())
1404  {
1405  if(1<fVerbose) std::cout << "Hough Space is empty. No peak can be found. Return empty tracklet vector." << '\n';
1406  return tracklets;
1407  }
1408 
1409 
1410  // code goes here
1411  throwError("This peak finder is not fully implemented!");
1412 
1413  // TODO: This peakfinder should be rechecked!
1414  // TODO: This peakfinder does not assign hits to the tracklets (so far)
1415  Int_t maxpeaks = 20;
1416  // Finding the peaks (as in example macro)
1417  TSpectrum2 s(maxpeaks,3); // second argument: higher = peaks can be closer together (1 enforces 3 sigma seperation between peaks)
1418  s.SetAverageWindow(3); // standard is 3 (for Markov smoothing)
1419  s.SetDeconIterations(100); // standard is 3, more is better
1420  // 2nd parameter: sigma of searched peaks = 2 standard
1421  // 4th parameter: threshold: (default=0.05) peaks with amplitude less than threshold*highest_peak are discarded. 0<threshold<1
1422  // Int_t nfound = s.Search(houghspace, 2,"nobackground,nomarkov",0.5); // works ok for line and for parabola, kind of...
1423  Int_t nfound = s.Search(this, 2,"",0.5); // TODO: does this work for my derived class?!?
1424  Double_t *xpeaks = (Double_t*)s.GetPositionX();
1425  Double_t *ypeaks = (Double_t*)s.GetPositionY();
1426  s.Print();
1427 
1428  // for output
1429  for (Int_t iPeak = 0; iPeak < nfound; ++iPeak){
1430  Double_t peakThetaVal = xpeaks[iPeak];
1431  Double_t peakSecondVal = ypeaks[iPeak];
1432 
1433  Int_t binmaxglobal = Fill(peakThetaVal, peakSecondVal, 0); // returns binnumber without modifying the histogram
1434  Double_t peakThetaHw = fXaxis.GetBinWidth(peakThetaVal)/2.;
1435  Double_t peakSecondHw = fYaxis.GetBinWidth(peakSecondVal)/2.;
1436 
1437 
1438  Double_t currentHeight = GetBinContent(binmaxglobal);
1439 
1440  // create tracklet and push it back to output
1441  PndFtsHoughTracklet currentTracklet(fZRefPos, fTrackerTask);
1442  currentTracklet.SetHoughTransformResults(peakThetaVal, peakSecondVal, currentHeight, peakThetaHw, peakSecondHw);
1443  tracklets.push_back(currentTracklet);
1444  }
1445  // binmaxglobal = houghspace->Fill(peakTheta, peakSecond, 0); // returns binnumber without modifying the histogram
1446 
1447 
1448 
1449  if (1<fVerbose) PrintFoundTracklets(tracklets);
1450  return tracklets;
1451 }
TLorentzVector s
Definition: Pnd2DStar.C:50
void throwError(const TString s) const
For error reporting.
Class for saving the result of one Hough transform for FTS PR.
Double_t
HISThit_ene Fill(sum_hit_ene)
cout<<"will loop over "<< t-> GetEntries()
Definition: root2ascii.C:17
void PrintFoundTracklets(const std::vector< PndFtsHoughTracklet > &tracklets) const
PndFtsHoughTrackerTask * fTrackerTask
Double_t PndFtsHoughSpace::getByFromBField ( Double_t  hitXLabSys,
Double_t  hitYLabSys,
Double_t  hitZLabSys 
)
inlineprivate

Definition at line 434 of file PndFtsHoughSpace.h.

References Double_t, fField, and fKeepBConstant.

Referenced by AddHitsToTrackletByCalculating(), FillHoughSpace(), and FindAllPeaksScanPathsMergeBinsCalculatingPaths().

435  {
436  Double_t By = 0.;
437  // set y component of B field constant
438  if (kTRUE == fKeepBConstant) {
439  // do not take B field into account
440  By = 1.;
441  } else {
442  // Use B field information
443  Double_t po[3], BB[3];
444  po[0] = hitXLabSys; // Use magnetic field at real (not shifted) x position
445  po[1] = hitYLabSys;
446  po[2] = hitZLabSys;
447  fField->GetFieldValue(po, BB); //return value in KG (G3)
448  By = BB[1] / 10.; // By is y-component of magnetic field in Tesla
449  }
450  return By;
451 }
Double_t
TString PndFtsHoughSpace::GetDebugOutName ( TString  title = "",
Int_t  param = -1 
) const
inlineprivate

For writing out debugging histograms.

Definition at line 418 of file PndFtsHoughSpace.h.

References fRefIndex, fTrackerTask, PndFtsHoughTrackerTask::GetEventNr(), and TString.

Referenced by WriteHistoOfAllPaths(), WriteHistoOfAllPathsForEachMcTruthTrack(), WriteHistoOfAllPeaks(), and WriteHistoOfHoughSpace().

418  {
419  TString debugOut = "/home/plots/";
420  debugOut+=fTrackerTask->GetEventNr();
421  debugOut += title;
422  if (-1!=fRefIndex){
423  debugOut+="-rId";
424  debugOut+=fRefIndex;
425  }
426  if (-1!=param){
427  debugOut+=param;
428  }
429  debugOut += ".rtg"; // root textual graphics ;) -- actually just a macro // png does not work in this way
430  return debugOut;
431 }
const Int_t fRefIndex
for debugging output (to which index in some loop does this Hough space and its output belong to) ...
UInt_t GetEventNr() const
Returns the save debug flag.
PndFtsHoughTrackerTask * fTrackerTask
const PndFtsHit * PndFtsHoughSpace::getHitFromHS ( UInt_t  index) const
inlineprivate

Definition at line 374 of file PndFtsHoughSpace.h.

References fHitId, fTrackerTask, PndFtsHoughTrackerTask::GetFtsHit(), GetNHits(), and throwError().

Referenced by AddHitsToTrackletByCalculating(), FillHoughSpace(), FindAllPeaksScanPathsMergeBins(), FindAllPeaksScanPathsMergeBinsCalculatingPaths(), and IsHitFromTubeIdAlreadyAdded().

374  {
375  if (GetNHits() < index) throwError("index too high");
376 
377  Int_t hitIndex = fHitId.at(index).GetHitId();
378  const PndFtsHit *const myHit = (PndFtsHit*) fTrackerTask->GetFtsHit(hitIndex);
379  return myHit;
380 }
std::vector< PndTrackCandHit > fHitId
void throwError(const TString s) const
For error reporting.
UInt_t GetNHits() const
const PndFtsHit * GetFtsHit(UInt_t hitId) const
Returns pointer to the hit with index hitId in the FTS hit array.
PndFtsHoughTrackerTask * fTrackerTask
Int_t PndFtsHoughSpace::getHitIdFromHS ( UInt_t  index) const
inlineprivate

Definition at line 190 of file PndFtsHoughSpace.h.

References fHitId.

Referenced by AddHitsToTrackletByCalculating(), FindAllPeaksScanPathsMergeBins(), and WriteHistoOfAllPathsForEachMcTruthTrack().

190 { return fHitId.at(index).GetHitId(); }; // gets the FTS hit Id corresponding to index
std::vector< PndTrackCandHit > fHitId
Double_t PndFtsHoughSpace::getInterceptZx ( ) const
inline

Definition at line 170 of file PndFtsHoughSpace.h.

References fInterceptZx.

170 { return fInterceptZx; };
UInt_t PndFtsHoughSpace::GetNHits ( ) const
inline
const TVector3 PndFtsHoughSpace::GetRawOrCalculatedHitPos ( const PndFtsHit *const  myHit) const
inlineprivate

Definition at line 383 of file PndFtsHoughSpace.h.

References CalculateHitPosFromIntersectionsWithZxTrackModel(), and PndFtsHit::GetSkewed().

Referenced by AddHitsToTrackletByCalculating(), FillHoughSpace(), FindAllPeaksScanPathsMergeBins(), and FindAllPeaksScanPathsMergeBinsCalculatingPaths().

385  {
386  // get hit position
387  TVector3 hitPos;
388  if (kFALSE == myHit->GetSkewed()) {
389  myHit->Position(hitPos);
390  } else {
392  }
393  return hitPos;
394 }
const TVector3 CalculateHitPosFromIntersectionsWithZxTrackModel(const PndFtsHit *const myHit) const
Int_t GetSkewed() const
Definition: PndFtsHit.h:75
Double_t PndFtsHoughSpace::getZRefPos ( ) const
inline

Definition at line 172 of file PndFtsHoughSpace.h.

References fZRefPos.

172 { return fZRefPos; };
Bool_t PndFtsHoughSpace::IsHitFromTubeIdAlreadyAdded ( const Int_t  tubeIdToAdd)
inlineprivate

Definition at line 111 of file PndFtsHoughSpace.cxx.

References getHitFromHS(), GetNHits(), and PndFtsHit::GetTubeID().

Referenced by AddHitToHS().

112 {
113  // return kFALSE; // uncomment this line to switch off testing for duplicates
114  for (size_t iTestHit = 0; iTestHit < GetNHits(); ++iTestHit)
115  {
116  const PndFtsHit* myTestHit = getHitFromHS(iTestHit);
117 
118  const Int_t tubeIdTestHit = myTestHit->GetTubeID();
119 
120  if ( tubeIdToAdd == tubeIdTestHit ) return kTRUE;
121 
122  } // for loop over all hits which have already been added to the Hough space
123  return kFALSE;
124 };
Int_t GetTubeID() const
Definition: PndFtsHit.h:70
UInt_t GetNHits() const
const PndFtsHit * getHitFromHS(UInt_t index) const
TH2S PndFtsHoughSpace::MakeEmptyHistoOfSameDimensions ( TString  specifier = "",
Int_t  index = -1 
) const
private

Makes a new empty histogram with the same binning and limits as this.

Definition at line 563 of file PndFtsHoughSpace.cxx.

References TString.

Referenced by WriteHistoOfAllPaths(), WriteHistoOfAllPathsForEachMcTruthTrack(), and WriteHistoOfAllPeaks().

563  {
564  // for getting rid of warning about potential memory leak (same name for mutliple different histos)
565  static Int_t histoCounter = 0;
566  TString newname = GetName();
567  newname += histoCounter;
568  // std::cout<<newname << '\n';
569  ++histoCounter;
570 
571  TString newTitle = GetName();
572  if (""!=specifier){
573  newTitle += " ";
574  newTitle += specifier;
575  }
576  if (-1 < index){
577  newTitle += " ";
578  newTitle += index;
579  }
580  TH2S peaks(newname, newTitle, fXaxis.GetNbins(), fXaxis.GetXmin(),
581  fXaxis.GetXmax(), fYaxis.GetNbins(), fYaxis.GetXmin(),
582  fYaxis.GetXmax());
583  return peaks;
584 }
void PndFtsHoughSpace::Print ( ) const
inline

Definition at line 356 of file PndFtsHoughSpace.h.

References fInterceptZx, fZRefPos, and Print().

356  {
357  std::cout << "=========== PndFtsHoughSpace::Print() ==========" << '\n';
358  std::cout << "fZRefPos = " << fZRefPos << '\n';
359  std::cout << "fInterceptZx = " << fInterceptZx << 'n';
360  TH2S::Print();
361 }
MechFsc Print()
void PndFtsHoughSpace::PrintFoundTracklets ( const std::vector< PndFtsHoughTracklet > &  tracklets) const
inlineprivate

Definition at line 363 of file PndFtsHoughSpace.h.

References fVerbose, and i.

Referenced by FindAllPeaksBinsWoMergingWithSearchWindow(), FindAllPeaksBlanko(), FindAllPeaksScanPathsMergeBins(), FindAllPeaksScanPathsMergeBinsCalculatingPaths(), and FindAllPeaksWithTSpectrum2().

363  {
364  std::cout << tracklets.size() << " peaks found for " << GetName() << '\n';
365  if (10<fVerbose){
366  for (UInt_t i=0; i< tracklets.size(); ++i)
367  {
368  tracklets[i].Print();
369  }
370  }
371 }
Int_t i
Definition: run_full.C:25
Bool_t PndFtsHoughSpace::setParametersForHsOption ( )
private

Definition at line 174 of file PndFtsHoughSpace.cxx.

References fInterceptZx, fKeepBConstant, fOnlyUseHitsFromZ, fOnlyUseHitsUpToZ, fUseNonSkewedStraws, fUseSkewedStraws, fVerbose, GetXaxis(), GetYaxis(), throwError(), and TString.

Referenced by PndFtsHoughSpace().

175 {
176  // use option instead of GetName() or fName (even though it is the same)
177  const TString option = GetName();
178 
179  fKeepBConstant = kTRUE; // kFALSE only for testing
180 
181  // set parameters according to the Hough transform I want to do
182  if ("lineBeforeDipole" == option)
183  {
184  // make sure hits are not shifted for line hough transform
185  if (0!=fInterceptZx) {
186  std::cout << "PndFtsHoughSpace: " << "fInterceptZx was set to " << fInterceptZx << " That is not correct for line HT of stations before dipole field!\n";
187  std::cout << "Will set interceptZx to 0 for " << option << '\n';
188  fInterceptZx = 0.;
189  }
190 
191  fUseNonSkewedStraws = kTRUE;
192  fUseSkewedStraws = kFALSE;
193 
194  // Line for stations 1+2
195  fOnlyUseHitsFromZ = 100.; // Set = 100. if you want to use all FTS hits, higher if you want to exclude hits that are closer to the interaction point than the value
196  fOnlyUseHitsUpToZ = 380.; // Set = 1000. if you want to use all FTS hits, lower if you want to exclude hits that are further away from the interaction point than the value
197 
198  GetXaxis()->SetTitle("#theta [rad]");
199  GetYaxis()->SetTitle("x [cm]");
200  }
201  else if ("parabola" == option)
202  {
203  fUseNonSkewedStraws = kTRUE;
204  fUseSkewedStraws = kFALSE;
205 
206  // parabola for stations 3-5
207  fOnlyUseHitsFromZ = 380.; // Set = 100. if you want to use all FTS hits, higher if you want to exclude hits that are closer to the interaction point than the value
208  fOnlyUseHitsUpToZ = 630.; // Set = 1000. if you want to use all FTS hits, lower if you want to exclude hits that are further away from the interaction point than the value
209 
210  GetXaxis()->SetTitle("#theta [rad]");
211  GetYaxis()->SetTitle("x_{LP} [cm]");
212  }
213  else if ("parabolapz" == option)
214  {
215  fUseNonSkewedStraws = kTRUE;
216  fUseSkewedStraws = kFALSE;
217 
218  // parabola for stations 3-5
219  fOnlyUseHitsFromZ = 380.; // Set = 100. if you want to use all FTS hits, higher if you want to exclude hits that are closer to the interaction point than the value
220  fOnlyUseHitsUpToZ = 630.; // Set = 1000. if you want to use all FTS hits, lower if you want to exclude hits that are further away from the interaction point than the value
221 
222  GetXaxis()->SetTitle("#theta [rad]");
223  GetYaxis()->SetTitle("x_{LP} [cm]");
224  }
225  else if ("lineBehindDipole" == option)
226  {
227  // make sure hits are not shifted for line hough transform
228  if (0!=fInterceptZx) {
229  std::cout << "PndFtsHoughSpace: " << "fInterceptZx was set to " << fInterceptZx << " That is not correct for line HT of stations after dipole field!\n";
230  std::cout << "Will set interceptZx to 0 for " << option << '\n';
231  fInterceptZx = 0.;
232  }
233 
234  fUseNonSkewedStraws = kTRUE;
235  fUseSkewedStraws = kFALSE;
236 
237  // Line for stations 5+6
238  fOnlyUseHitsFromZ = 550.; // Set = 100. if you want to use all FTS hits, higher if you want to exclude hits that are closer to the interaction point than the value
239  fOnlyUseHitsUpToZ = 1000.; // Set = 1000. if you want to use all FTS hits, lower if you want to exclude hits that are further away from the interaction point than the value
240 
241  GetXaxis()->SetTitle("#theta [rad]");
242  GetYaxis()->SetTitle("x [cm]");
243  }
244  else if ("lineZy" == option)
245  {
246  // make sure hits are not shifted for line hough transform
247  if (0!=fInterceptZx) {
248  std::cout << "PndFtsHoughSpace: " << "fInterceptZx was set to " << fInterceptZx << " That is not correct for line HT of all stations in zy plane!\n";
249  std::cout << "Will set interceptZx to 0 for " << option << '\n';
250  fInterceptZx = 0.;
251  }
252 
253  fUseNonSkewedStraws = kFALSE;
254  fUseSkewedStraws = kTRUE;
255 
256  // Line for all FTS stations
257  fOnlyUseHitsFromZ = 100.; // Set = 100. if you want to use all FTS hits, higher if you want to exclude hits that are closer to the interaction point than the value
258  fOnlyUseHitsUpToZ = 1000.; // Set = 1000. if you want to use all FTS hits, lower if you want to exclude hits that are further away from the interaction point than the value
259 
260  GetXaxis()->SetTitle("#theta [rad]");
261  GetYaxis()->SetTitle("y [cm]");
262  }
263  else
264  {
265  throwError("in PndFtsHoughSpace! option " + option + " is not implemented!");
266  }
267 
268  if (3<fVerbose)
269  {
270  std::cout << "HoughSpace parameters successfully set for option " << option << '\n';
271  if (10<fVerbose)
272  {
273  std::cout << "fUseNonSkewedStraws " << fUseNonSkewedStraws << '\n';
274  std::cout << "fUseSkewedStraws " << fUseSkewedStraws << '\n';
275  std::cout << "fOnlyUseHitsFromZ " << fOnlyUseHitsFromZ << '\n';
276  std::cout << "fOnlyUseHitsUpToZ " << fOnlyUseHitsUpToZ << '\n';
277 
278  std::cout << "fInterceptZx " << fInterceptZx << '\n';
279  }
280  }
281  return kTRUE;
282 }
Double_t fOnlyUseHitsFromZ
hz_h GetYaxis() -> SetTitle("Counts")
hz_h GetXaxis() -> SetTitle("Z position")
void throwError(const TString s) const
For error reporting.
Double_t fOnlyUseHitsUpToZ
void PndFtsHoughSpace::setVerbose ( Int_t  verbose)
inline

Definition at line 168 of file PndFtsHoughSpace.h.

References fVerbose, and verbose.

168 { fVerbose = verbose; };
#define verbose
void PndFtsHoughSpace::throwError ( const TString  s) const
inlineprivate
void PndFtsHoughSpace::WriteHistoOfAllPaths ( ) const
private

For writing out paths (how the Hough space was filled seen from one hit) as histograms (for debugging purposes).

Definition at line 610 of file PndFtsHoughSpace.cxx.

References Bool_t, Double_t, fHitThetaYIdxPath, fTrackerTask, GetDebugOutName(), PndFtsHoughTrackerTask::GetSaveDebugInfo(), GetXaxis(), GetYaxis(), PndFtsHoughTrackerTask::kHitCurvesExclusively, PndFtsHoughTrackerTask::kHitCurvesProjected, MakeEmptyHistoOfSameDimensions(), and TString.

Referenced by FillHoughSpace().

610  {
611  // test if we need to do anything here
614  if ( (kTRUE == saveExclusively) && (kTRUE == saveProjected) )return;
615 
616  // filling each path in separate histo
617  for (HitIdxPathMap::const_iterator itPath = fHitThetaYIdxPath.begin(); itPath != fHitThetaYIdxPath.end(); ++itPath) {
618  const Int_t currHit = itPath->first;
619  TH2S onePathProjected = MakeEmptyHistoOfSameDimensions("PathProjected", currHit);
620  TH2S onePathExclusively = MakeEmptyHistoOfSameDimensions("PathExclusively", currHit);
621  const IdxPath& currPath = itPath->second;
622 
623  Int_t lastBinNumber = -1;
624  for (size_t iGlobalBin = 0; iGlobalBin < currPath.size(); ++iGlobalBin) {
625  const Int_t currBinNumber = currPath[iGlobalBin];
626  // warn if we accidently saved the same bin twice in the path
627  if ( currBinNumber == lastBinNumber ) std::cerr << "FATAL! Bin " << currBinNumber << " twice in a row! in hit " << currHit << '\n';
628  lastBinNumber = currBinNumber;
629 
630  if ( kTRUE == saveProjected){
631  const Double_t currHeight = GetBinContent(currBinNumber); // get height of Hough space
632  onePathProjected.SetBinContent(currBinNumber, currHeight);
633  }
634 
635  if ( kTRUE == saveExclusively){
636  Int_t currBinX = 0, currBinY = 0, notUsedBinZ = 0;
637  GetBinXYZ(currBinNumber, currBinX, currBinY, notUsedBinZ); // Find currBinX and currBinY from globalBin
638  const Double_t currXVal = GetXaxis()->GetBinCenter(currBinX);
639  const Double_t currYVal = GetYaxis()->GetBinCenter(currBinY);
640  onePathExclusively.Fill(currXVal,currYVal); // exclusive fill
641  }
642  }
643  TString outNameProj = GetDebugOutName(onePathProjected.GetTitle());
644  if ( kTRUE == saveProjected ) onePathProjected.SaveAs(outNameProj, "LEGO2");
645  TString outNameExcl = GetDebugOutName(onePathExclusively.GetTitle());
646  if ( kTRUE == saveExclusively ) onePathExclusively.SaveAs(outNameExcl, "LEGO2");
647  }
648 }
std::vector< Int_t > IdxPath
TH2S MakeEmptyHistoOfSameDimensions(TString specifier="", Int_t index=-1) const
Makes a new empty histogram with the same binning and limits as this.
hz_h GetYaxis() -> SetTitle("Counts")
hz_h GetXaxis() -> SetTitle("Z position")
Double_t
Int_t GetSaveDebugInfo() const
Returns the verbosity level.
HitIdxPathMap fHitThetaYIdxPath
PndFtsHoughTrackerTask * fTrackerTask
TString GetDebugOutName(TString title="", Int_t param=-1) const
For writing out debugging histograms.
void PndFtsHoughSpace::WriteHistoOfAllPathsForEachMcTruthTrack ( ) const
private

For writing out paths from hits which stem from the same MC truth tracks (how the Hough space would be filled if only hits from one track were present) as histograms (for debugging and parameter optimization purposes).

Definition at line 654 of file PndFtsHoughSpace.cxx.

References Bool_t, Double_t, fHitThetaYIdxPath, fTrackerTask, GetDebugOutName(), getHitIdFromHS(), PndFtsHoughTrackerTask::getMcTruthIdForHitId(), PndFtsHoughTrackerTask::GetSaveDebugInfo(), GetXaxis(), GetYaxis(), PndFtsHoughTrackerTask::kMcTruthPeaksExclusively, PndFtsHoughTrackerTask::kMcTruthPeaksProjected, MakeEmptyHistoOfSameDimensions(), map, and TString.

Referenced by FillHoughSpace().

654  {
655  // test if we need to do anything here
658  if ( (kTRUE == saveExclusively) && (kTRUE == saveProjected) )return;
659 
660 
661  // create map collecting histos of all hit indices from same Mc truth track
662  std::map<Int_t, std::pair < TH2S, TH2S > > mcTruthIdHistos;
663 
664  for (HitIdxPathMap::const_iterator itPath = fHitThetaYIdxPath.begin(); itPath != fHitThetaYIdxPath.end(); ++itPath) {
665 
666  // figure out to which MC Truth track hit belongs
667  const Int_t currHit = itPath->first;
668  const Int_t hitId = getHitIdFromHS(currHit);
669  const Int_t mcTruthId = fTrackerTask->getMcTruthIdForHitId(hitId);
670 
671  // if MC truth index not yet in map add new histo
672  std::map<Int_t, std::pair < TH2S, TH2S > >::iterator itFind;
673  itFind = mcTruthIdHistos.find(mcTruthId);
674  if ( mcTruthIdHistos.end() == itFind ){// not found
675  TH2S newHisto = MakeEmptyHistoOfSameDimensions("McTruthPeak projected", mcTruthId);
676  TH2S newHisto2 = MakeEmptyHistoOfSameDimensions("McTruthPeak exclusive", mcTruthId);
677  std::pair<TH2S, TH2S > histoPair( newHisto, newHisto2 );
678  std::pair<Int_t, std::pair<TH2S, TH2S > > mcTruthIdHistosPair( mcTruthId, histoPair );
679  mcTruthIdHistos.insert( mcTruthIdHistosPair );
680  itFind = mcTruthIdHistos.find(mcTruthId); // now histos can be found in map
681  }
682 
683  // Fill current path into correct histo (first as projection, second as if only hits from same mc truth track were filled)
684  const IdxPath& currPath = itPath->second;
685  for (size_t iGlobalBin = 0; iGlobalBin < currPath.size(); ++iGlobalBin) {
686  Int_t currBinNumber = currPath[iGlobalBin];
687  std::pair<TH2S, TH2S >& histoPair = itFind->second;
688 
689  if ( kTRUE == saveProjected ){
690  const Double_t currHeight = GetBinContent(currBinNumber); // get height of Hough space
691  histoPair.first.SetBinContent(currBinNumber, currHeight); // projection
692  }
693 
694  if ( kTRUE == saveExclusively ){
695  Int_t currBinX = 0, currBinY = 0, notUsedBinZ = 0;
696  GetBinXYZ(currBinNumber, currBinX, currBinY, notUsedBinZ); // Find currBinX and currBinY from globalBin
697  const Double_t currXVal = GetXaxis()->GetBinCenter(currBinX);
698  const Double_t currYVal = GetYaxis()->GetBinCenter(currBinY);
699  histoPair.second.Fill(currXVal,currYVal); // exclusive fill
700  }
701  }
702  }
703  // loop over all histos that have been created
704  for ( std::map<Int_t, std::pair<TH2S, TH2S > >::const_iterator itHisto = mcTruthIdHistos.begin(); itHisto != mcTruthIdHistos.end(); ++itHisto) {
705  const std::pair<TH2S, TH2S >& histoPair = itHisto->second;
706  TString outNameProjection = GetDebugOutName(histoPair.first.GetTitle());
707  TString outNameExclusive = GetDebugOutName(histoPair.second.GetTitle());
708  if ( kTRUE == saveProjected ) histoPair.first.SaveAs(outNameProjection, "LEGO2");
709  if ( kTRUE == saveExclusively ) histoPair.second.SaveAs(outNameExclusive, "LEGO2");
710  }
711 }
std::vector< Int_t > IdxPath
Int_t getMcTruthIdForHitId(UInt_t hitId) const
TH2S MakeEmptyHistoOfSameDimensions(TString specifier="", Int_t index=-1) const
Makes a new empty histogram with the same binning and limits as this.
PndTransMap * map
Definition: sim_emc_apd.C:99
hz_h GetYaxis() -> SetTitle("Counts")
hz_h GetXaxis() -> SetTitle("Z position")
Double_t
Int_t GetSaveDebugInfo() const
Returns the verbosity level.
Int_t getHitIdFromHS(UInt_t index) const
HitIdxPathMap fHitThetaYIdxPath
PndFtsHoughTrackerTask * fTrackerTask
TString GetDebugOutName(TString title="", Int_t param=-1) const
For writing out debugging histograms.
void PndFtsHoughSpace::WriteHistoOfAllPeaks ( const std::vector< PndFtsHoughSpacePeak > &  peaksToPlot) const
private

For writing out peaks in Hough spaces as histograms (for debugging purposes).

Definition at line 586 of file PndFtsHoughSpace.cxx.

References Bool_t, Double_t, fTrackerTask, GetDebugOutName(), PndFtsHoughTrackerTask::GetSaveDebugInfo(), PndFtsHoughTrackerTask::kAllFoundPeaksTogether, PndFtsHoughTrackerTask::kEachFoundPeakSeparately, MakeEmptyHistoOfSameDimensions(), and TString.

Referenced by FindAllPeaksScanPathsMergeBins().

586  {
587  // test if we need to do anything here
590  if ( (kTRUE == saveEachSeparately) && (kTRUE == saveAllTogether) )return;
591 
592  // write out histograms containing found peaks
593  // filling all peaks in separate histos and all together in one histo
594  TH2S allPeaks = MakeEmptyHistoOfSameDimensions("AllPeaks");
595  for (UInt_t iPeak = 0; iPeak < peaksToPlot.size(); ++iPeak) {
596  TH2S onePeak = MakeEmptyHistoOfSameDimensions("Peak", iPeak);
597  const Double_t currHeight = peaksToPlot[iPeak].getHeight();
598  const std::set<Int_t>& binsInPeak = peaksToPlot[iPeak].getBins();
599  for (std::set<Int_t>::iterator itBin = binsInPeak.begin(); itBin != binsInPeak.end(); ++itBin) {
600  onePeak.SetBinContent(*itBin, currHeight);
601  allPeaks.SetBinContent(*itBin, currHeight);
602  }
603  TString outNameOne = GetDebugOutName(onePeak.GetTitle(), currHeight);
604  if ( kTRUE == saveEachSeparately ) onePeak.SaveAs(outNameOne, "LEGO2");
605  }
606  TString outNameAll = GetDebugOutName(allPeaks.GetTitle());
607  if ( kTRUE == saveAllTogether ) allPeaks.SaveAs(outNameAll, "LEGO2");
608 }
TH2S MakeEmptyHistoOfSameDimensions(TString specifier="", Int_t index=-1) const
Makes a new empty histogram with the same binning and limits as this.
Double_t
Int_t GetSaveDebugInfo() const
Returns the verbosity level.
PndFtsHoughTrackerTask * fTrackerTask
TString GetDebugOutName(TString title="", Int_t param=-1) const
For writing out debugging histograms.
void PndFtsHoughSpace::WriteHistoOfHoughSpace ( ) const
private

For writing out Hough spaces as histograms (for debugging purposes).

Definition at line 715 of file PndFtsHoughSpace.cxx.

References fTrackerTask, GetDebugOutName(), PndFtsHoughTrackerTask::GetSaveDebugInfo(), PndFtsHoughTrackerTask::kHoughSpaces, and TString.

Referenced by FillHoughSpace().

715  {
717 
718  // Int_t index = fHoughSpaces->GetEntriesFast();
719  // PndFtsHoughSpace* myHoughSpace = new ((*fHoughSpaces)[index])PndFtsHoughSpace(*houghSpace);
720  TString title = GetTitle();
721  title += " histo";
722  TString outName = GetDebugOutName(title);
723  SaveAs(outName, "LEGO2"); // resulting files need to have PndFtsHoughSpace replaced with TH2S
724  // sed -i 's/PndFtsHoughSpace/TH2S/g' *.rtg
725 
726 
727  // fOutFile = FairRootManager::Instance()->GetOutFile();
728  // if (0==fOutFile)
729  // {
730  // std::cout << "WriteHistograms: Cannot get outfile.\n";
731  // }
732  // else
733  // {
734  // // fOutFile->cd();
735  // // fOutFile->cd("PndFtsHoughTrackerTask");
736  // if(3<fVerbose) std::cout << "WriteHistograms: Got outfile for debugging output.\n";
737  // if (0!=houghSpace)
738  // {
739  // TString histNameOld = houghSpace->GetName();
740  // TString histNameNew = houghSpace->GetName();
741  // histNameNew+=fEventNr;
742  // houghSpace->SetName(histNameNew);
743  // houghSpace->Write();
744  // houghSpace->SetName(histNameOld);
745  // }
746  // // fOutFile->cd();
747  // }
748 }
Int_t GetSaveDebugInfo() const
Returns the verbosity level.
PndFtsHoughTrackerTask * fTrackerTask
TString GetDebugOutName(TString title="", Int_t param=-1) const
For writing out debugging histograms.

Member Data Documentation

PndFtsHoughTrackCand* PndFtsHoughSpace::fAssociatedTrackCand
private

hits relevant for this Hough space

///<< first index is detId, second index is hit Id For skewed hits a track candidate is needed

Definition at line 216 of file PndFtsHoughSpace.h.

Referenced by CalculateHitPosFromIntersectionsWithZxTrackModel().

const Bool_t PndFtsHoughSpace::fCorrectPzx = kFALSE
staticprivate

Definition at line 254 of file PndFtsHoughSpace.h.

FairField* PndFtsHoughSpace::fField
private

Definition at line 248 of file PndFtsHoughSpace.h.

Referenced by getByFromBField(), and PndFtsHoughSpace().

Int_t PndFtsHoughSpace::fFtsBranchId
private
std::vector<PndTrackCandHit> PndFtsHoughSpace::fHitId
private
HitIdxPathMap PndFtsHoughSpace::fHitThetaYIdxPath
private

For each hit index the "path through the Hough space" [ordered globalbins which were filled during the thetaRad scan] is saved This is useful for peak finding. Map index: hit index, use as argument of getHit. The map gives the vector of globalbins which were filled during the theta scan for the hit.

Definition at line 205 of file PndFtsHoughSpace.h.

Referenced by FillHoughSpace(), FindAllPeaksScanPathsMergeBins(), WriteHistoOfAllPaths(), and WriteHistoOfAllPathsForEachMcTruthTrack().

Double_t PndFtsHoughSpace::fInterceptZx
private
Bool_t PndFtsHoughSpace::fKeepBConstant
private

Definition at line 225 of file PndFtsHoughSpace.h.

Referenced by FillHoughSpace(), getByFromBField(), and setParametersForHsOption().

Double_t PndFtsHoughSpace::fOnlyUseHitsFromZ
private

Definition at line 220 of file PndFtsHoughSpace.h.

Referenced by filterInputHits(), and setParametersForHsOption().

Double_t PndFtsHoughSpace::fOnlyUseHitsUpToZ
private

Definition at line 221 of file PndFtsHoughSpace.h.

Referenced by filterInputHits(), and setParametersForHsOption().

const Int_t PndFtsHoughSpace::fRefIndex
private

for debugging output (to which index in some loop does this Hough space and its output belong to)

Definition at line 209 of file PndFtsHoughSpace.h.

Referenced by GetDebugOutName().

PndFtsHoughTrackerTask* PndFtsHoughSpace::fTrackerTask
private
Bool_t PndFtsHoughSpace::fUseNonSkewedStraws
private

Definition at line 222 of file PndFtsHoughSpace.h.

Referenced by filterInputHits(), and setParametersForHsOption().

Bool_t PndFtsHoughSpace::fUseSkewedStraws
private

Definition at line 223 of file PndFtsHoughSpace.h.

Referenced by filterInputHits(), and setParametersForHsOption().

Int_t PndFtsHoughSpace::fVerbose
private
Double_t PndFtsHoughSpace::fZRefPos
private

The documentation for this class was generated from the following files: