9 #include "cetlib/search_path.h" 31 m_pcaAlg(pset.get<
fhicl::ParameterSet>(
"PrincipalComponentsAlg"))
65 if (!clusterParametersList.empty())
70 clusterParametersList.sort();
73 while(!clusterParametersList.empty() && clusterParametersList.back().getHitPairListPtr().size() <
m_clusterMinHits) clusterParametersList.pop_back();
81 for(
auto& clusterParams : clusterParametersList)
83 for(
const auto& hit3D : clusterParams.getHitPairListPtr())
85 for(
const auto& hit2D : hit3D->getHits())
89 hit2DToClusterMap[hit2D][&clusterParams].insert(hit3D);
99 clusterItr = clusterParametersList.begin();
101 while(clusterItr != clusterParametersList.end())
112 clusterItr = clusterParametersList.erase(clusterItr);
123 double minUniqueFrac,
124 double maxLostFrac)
const 143 std::set<const reco::ClusterHit2D*> hitSet;
147 std::vector<size_t> planeHit2DVec;
148 std::vector<size_t> planeUniqueHit2DVec;
150 planeHit2DVec.resize(3);
151 planeUniqueHit2DVec.resize(3);
157 for(
const auto& hitMapPair : hit2DToHit3DListMap)
159 size_t plane = hitMapPair.first->getHit().WireID().Plane;
161 planeHit2DVec[plane] += hitMapPair.second.size();
162 if (!(hitMapPair.first->getStatusBits() &
reco::ClusterHit2D::USED)) planeUniqueHit2DVec[plane] += hitMapPair.second.size();
167 int numUniqueHits(0);
170 std::vector<float> uniqueHitFracVec(3,0.);
171 int nPlanesWithHits(0);
172 int nPlanesWithUniqueHits(0);
174 size_t minPlaneCnt = planeUniqueHit2DVec.at(0);
177 for(
int idx = 0; idx < 3; idx++)
180 numTotalHits += planeHit2DVec.at(idx);
181 numUniqueHits += planeUniqueHit2DVec.at(idx);
183 if (planeHit2DVec.at(idx) > 0) nPlanesWithHits++;
184 if (planeUniqueHit2DVec.at(idx) > 0) nPlanesWithUniqueHits++;
187 uniqueHitFracVec[idx] = float(planeUniqueHit2DVec.at(idx)) /
std::max(
float(planeHit2DVec.at(idx)),
float(1.));
190 if (planeHit2DVec.at(idx) < minPlaneCnt)
192 minPlaneCnt = planeHit2DVec.at(idx);
200 if (numUniqueHits > 0.25 * numTotalHits && nPlanesWithHits > 1 && nPlanesWithUniqueHits > 1)
203 std::sort(uniqueHitFracVec.begin(),uniqueHitFracVec.end());
205 float acceptRatio = 0.;
207 if(uniqueHitFracVec[0] * uniqueHitFracVec[1] > 0.25) acceptRatio = 1.;
209 float uniqueFraction = uniqueHitFracVec[0] * uniqueHitFracVec[1] * uniqueHitFracVec[2];
212 if (uniqueFraction > 0.6 && acceptRatio > 0.)
221 for(
auto& pair : hit2DToHit3DListMap)
224 if (pair.second.empty())
226 std::cout <<
"<<<<<< no matching 3D hits for reco hit in final hit processing >>>>>>" << std::endl;
231 size_t hitPlane = pair.first->getHit().WireID().Plane;
234 if (hitPlane != minPlane && pair.second.size() > 2)
240 pair.second.sort([](
const auto&
left,
const auto&
right){
return left->getHitChiSquare() <
right->getHitChiSquare();});
247 float cutDeltaTSig =
std::min(2.0,
std::max(0.5,
double(pair.second.front()->getHitChiSquare())));
255 reco::HitPairListPtr::iterator firstBadHitItr = std::find_if(pair.second.begin(),pair.second.end(),[cutDeltaTSig](
const auto& hitPtr){
return hitPtr->getHitChiSquare() > cutDeltaTSig;});
270 std::copy(firstBadHitItr,pair.second.end(),std::back_inserter(rejectCandList));
275 for(
const auto& hit3D : rejectCandList)
277 bool rejectThisHit(
true);
278 std::vector<std::pair<reco::HitPairListPtr&,reco::HitPairListPtr::iterator>> deleteVec;
280 for(
const auto& hit2D : hit3D->getHits())
283 if (!hit2D)
continue;
288 if (removeHitList.size() < 2)
291 rejectThisHit =
false;
297 if (removeItr != removeHitList.end()) deleteVec.emplace_back(removeHitList,removeItr);
303 for(
auto& rejectPair : deleteVec) rejectPair.first.erase(rejectPair.second);
305 usedHitPairList.push_back(hit3D);
310 hitSet.insert(pair.first);
314 if (!usedHitPairList.empty())
319 for(
const auto& hit3D : usedHitPairList)
321 if (hit3D == lastHit3D)
continue;
325 if (hit3DItr != hitPairVector.end())
331 hitPairVector.erase(hit3DItr);
338 edgeMap.erase(edgeMap.find(hit3D));
357 for(
const auto& hit2D : hitSet)
374 for(
const auto& hit3D : usedHitPairList)
376 for(
const auto& hit2D : hit3D->getHits())
378 if (!hit2D)
continue;
383 if (hitToClusMapItr == hit2DToClusterMap.end())
385 std::cout <<
"*********** COULD NOT FIND ENTRY FOR 2D HIT! **************" << std::endl;
394 if (clusToHit3DMapItr == hitToClusMapItr->second.end())
396 std::cout <<
"************ DUCK! THE SKY HAS FALLEN!! *********" << std::endl;
401 if (clusToHit3DMapItr->second.size() > 1)
405 clusToHit3DMapItr->second.erase(hit3DItr);
408 hitToClusMapItr->second.erase(clusToHit3DMapItr);
ClusterParamsBuilder(fhicl::ParameterSet const &pset)
Constructor.
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
virtual ~ClusterParamsBuilder()
Destructor.
void PCAAnalysis_3D(const reco::HitPairListPtr &hitPairList, reco::PrincipalComponents &pca, bool skeletonOnly=false) const
This algorithm will create and then cluster 3D hits using DBScan.
Declaration of signal hit object.
PrincipalComponentsAlg m_pcaAlg
reco::PrincipalComponents & getSkeletonPCA()
reco::Hit2DToHit3DListMap & getHit2DToHit3DListMap()
Hit has been rejected for any reason.
void BuildClusterInfo(reco::ClusterParametersList &clusterParametersList) const
Given the results of running DBScan, format the clusters so that they can be easily transferred back ...
reco::Hit3DToEdgeMap & getHit3DToEdgeMap()
reco::HitPairListPtr & getHitPairListPtr()
reco::PlaneToClusterParamsMap & getClusterParams()
void removeUsedHitsFromMap(reco::ClusterParameters &, reco::HitPairListPtr &, reco::Hit2DToClusterMap &) const
void FillClusterParams(reco::ClusterParameters &, reco::Hit2DToClusterMap &, double minUniqueFrac=0., double maxLostFrac=1.) const
Fill the cluster parameters (expose to outside world for case of splitting/merging clusters) ...
size_t m_clusterMinHits
Data members to follow.
reco::PrincipalComponents & getFullPCA()
T get(std::string const &key) const
std::unordered_map< const reco::ClusterHit2D *, reco::HitPairListPtr > Hit2DToHit3DListMap
double m_clusterMinUniqueFraction
std::list< const reco::ClusterHit3D * > HitPairListPtr
void UpdateParameters(const reco::ClusterHit2D *hit)
Encapsulate the geometry of a wire.
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane.
std::unordered_map< const reco::ClusterHit2D *, ClusterToHitPairSetMap > Hit2DToClusterMap
std::unordered_map< const reco::ClusterHit3D *, reco::EdgeList > Hit3DToEdgeMap
double m_clusterMaxLostFraction
void configure(const fhicl::ParameterSet &)
std::list< ClusterParameters > ClusterParametersList