/* * PndLmdAlignStructs.h * * Header-only file to collect all structs used during SensorAlignment * * Created on: Jul 20, 2017 * Author: Roman Klasen, roklasen@uni-mainz.de or klasen@kph.uni-mainz.de */ #ifndef LMD_LMDSENSORALIGNMENT_PNDLMDALIGNSTRUCTS_H_ #define LMD_LMDSENSORALIGNMENT_PNDLMDALIGNSTRUCTS_H_ #include "PndLmdHitPair.h" #include #include #include #include using std::max; using std::min; using std::cout; using std::vector; struct dynamicCutHandler{ int _overlapID; bool _ready; std::vector samples; double _minDist, _maxDist, _hardMax, _curveWidth; dynamicCutHandler(){ _overlapID = 0; _minDist = _maxDist = 0.0; _hardMax = 32*80e-4; //sensors should not be farther than 32 pixels, 2,5mm! _curveWidth = 150e-4; //empirical value, see report march 26th 2017 _ready = false; } void addToSamples(PndLmdHitPair pair){ //set first sample data if(samples.size() == 0){ _overlapID = pair.getOverlapId(); _minDist = pair.getDistance(); } else{ if(_overlapID != pair.getOverlapId()){ cout << "something is wrong! stored OverlapID does not match added ID!\n"; return; } } //100 should suffice, but more is always better if(samples.size() > 150){ _ready = true; } double thisDistance=pair.getDistance(); _minDist = std::min(_minDist, thisDistance); _maxDist = std::max(_maxDist, std::min(thisDistance, _hardMax) ); //never choose maximum higher than hardMax // store distance only if in valid range, some distances are too large if(thisDistance >= _minDist && thisDistance <= _maxDist){ samples.push_back(pair.getDistance()); } return; } void calcMinAndMax(){ int noOfBuckets = 128; std::vector buckets(noOfBuckets); for(int iSample=0; iSample= 0 && bucket < noOfBuckets){ //increment that bucket buckets[bucket]++; } else{ cout << "I screwed up, this should not happen.\n"; } } //find max bucket: int bucket=0; int maxentries = buckets[0]; for(int iBucket=1; iBucket= maxentries ){ maxentries = buckets[iBucket]; bucket = iBucket; } } //calc min and max distance _minDist = std::max( ((bucket * _maxDist) / noOfBuckets ) - _curveWidth, 0.0 ); //in case min is negative _maxDist = std::min( ((bucket * _maxDist) / noOfBuckets ) + _curveWidth , _hardMax); //in case max overflows return; } bool ready(){ return _ready; } double getMinDist(){ return _minDist; } double getMaxDist(){ return _maxDist; } }; //simple pixel hit, maybe not even necessary struct pixelHit{ int _sensorId; double _col; double _row; double x() const{ return _col; } pixelHit(int idVal, double colVal, double rowVal){ _sensorId = idVal; _col=colVal; _row=rowVal; } pixelHit(){ _col=-1; _row=-1; _sensorId=-1; } }; /* * contains multiple pixelHits that form a cluster. most routines are for checking, * if two separate pixelHits belong to the same cluster */ struct pixelCluster{ int _sensorId; double centerCol, centerRow;//,centerZ; double clusterSize; vector pixelHits; bool clusterReady; pixelCluster(){ _sensorId=-1; centerCol=-1; centerRow=-1;//centerZ=-1; clusterSize=-1; clusterReady=false; } pixelCluster(const pixelHit &hit){ _sensorId=hit._sensorId; pixelHits.push_back(hit); centerCol=-1; centerRow=-1;//centerZ=-1; clusterSize=-1; clusterReady=false; } pixelCluster(const pixelCluster& copy){ _sensorId=copy._sensorId; for(size_t i=0; ipixelHits.size(); i++){ _col1 = this->pixelHits[i]._col; _row1 = this->pixelHits[i]._row; for(size_t j=0; j0){ deltax=deltax+1; } if(deltax<0){ deltax=deltax-1; } double deltay=(pixelHits[i]._row-pixelHits[j]._row); if(deltay>0){ deltay=deltay+1; } if(deltay<0){ deltay=deltay-1; } tempDistance = sqrt(deltax*deltax + deltay*deltay); clusterSize=max(clusterSize, tempDistance); } } } clusterReady=true; } void printPixels(){ for(size_t i=0; i