40 #include <TMatrixFfwd.h>
42 #include <TMatrixTUtils.h>
45 #pragma GCC diagnostic push
46 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
47 #include <boost/graph/adjacency_list.hpp>
48 #pragma GCC diagnostic pop
50 #include <boost/graph/connected_components.hpp>
61 using namespace boost;
69 inline constexpr
T square(
const T&
x ) {
return x*
x; }
101 if (GetZClustering())
130 , m_clusterlist(nullptr)
131 , m_clusterhitassoc(nullptr)
132 , m_makeZClustering(
true)
148 cout <<
PHWHERE <<
"DST Node missing, doing nothing." << endl;
162 auto trkrclusters = findNode::getClass<TrkrClusterContainer>(dstNode,
"TRKR_CLUSTER");
171 dstNode->addNode(DetNode);
177 DetNode->
addNode(TrkrClusterContainerNode);
180 auto clusterhitassoc = findNode::getClass<TrkrClusterHitAssoc>(topNode,
"TRKR_CLUSTERHITASSOC");
189 dstNode->addNode(DetNode);
200 mClusHitsVerbose = findNode::getClass<ClusHitsVerbose>(topNode,
"Trkr_SvtxClusHitsVerbose");
208 dstNode->addNode(DetNode);
212 DetNode->addNode(newNode);
224 cout <<
"====================== MvtxClusterizer::InitRun() =====================" << endl;
225 cout <<
" Z-dimension Clustering = " << boolalpha <<
m_makeZClustering << noboolalpha << endl;
226 cout <<
"===========================================================================" << endl;
236 m_hits = findNode::getClass<TrkrHitSetContainer>(topNode,
"TRKR_HITSET");
239 cout <<
PHWHERE <<
"ERROR: Can't find node TRKR_HITSET" << endl;
244 m_rawhits = findNode::getClass<RawHitSetContainer>(topNode,
"TRKR_RAWHITSET");
247 std::cout <<
PHWHERE <<
"ERROR: Can't find node TRKR_HITSET" << std::endl;
253 m_clusterlist = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER");
256 cout <<
PHWHERE <<
" ERROR: Can't find TRKR_CLUSTER." << endl;
261 m_clusterhitassoc = findNode::getClass<TrkrClusterHitAssoc>(topNode,
"TRKR_CLUSTERHITASSOC");
264 cout <<
PHWHERE <<
" ERROR: Can't find TRKR_CLUSTERHITASSOC" << endl;
283 cout <<
"Entering MvtxClusterizer::ClusterMvtx " << endl;
286 if (!geom_container)
return;
296 hitsetitr != hitsetrange.second;
307 cout <<
"MvtxClusterizer found hitsetkey " << hitsetitr->first <<
" layer " << layer <<
" stave " << stave <<
" chip " << chip <<
" strobe " << strobe << endl;
314 std::vector <std::pair< TrkrDefs::hitkey, TrkrHit*> > hitvec;
318 hitr != hitrangei.second;
321 hitvec.push_back(make_pair(hitr->first, hitr->second));
323 if (
Verbosity() > 2) cout <<
"hitvec.size(): " << hitvec.size() << endl;
327 for (
unsigned int i = 0;
i < hitvec.size();
i++)
332 std::cout <<
" hitkey " <<
hitkey <<
" row " << row <<
" col " <<
col << std::endl;
338 typedef adjacency_list<vecS, vecS, undirectedS> Graph;
342 for (
unsigned int i = 0;
i < hitvec.size();
i++)
344 for (
unsigned int j = 0;
j < hitvec.size();
j++)
353 vector<int> component(num_vertices(G));
356 connected_components(G, &component[0]);
360 set<int> cluster_ids;
362 multimap<int, std::pair<TrkrDefs::hitkey, TrkrHit*> >
clusters;
363 for (
unsigned int i = 0;
i < component.size();
i++)
365 cluster_ids.insert(component[
i]);
366 clusters.insert(make_pair(component[i], hitvec[i]));
368 int total_clusters = 0;
369 for (set<int>::iterator clusiter = cluster_ids.begin(); clusiter != cluster_ids.end(); ++clusiter)
371 int clusid = *clusiter;
372 auto clusrange = clusters.equal_range(clusid);
374 if (
Verbosity() > 2) cout <<
"Filling cluster id " << clusid <<
" of " <<
std::distance(cluster_ids.begin(),clusiter )<< endl;
382 std::map<int,unsigned int> m_phi, m_z;
387 const unsigned int nhits =
std::distance( clusrange.first, clusrange.second );
389 double locclusx = NAN;
390 double locclusz = NAN;
398 for (
auto mapiter = clusrange.first; mapiter != clusrange.second; ++mapiter)
401 const auto energy = (mapiter->second).second->getAdc();
408 auto pnew = m_phi.try_emplace(row,
energy);
409 if (!pnew.second) pnew.first->second +=
energy;
411 pnew = m_z.try_emplace(col,
energy);
412 if (!pnew.second) pnew.first->second +=
energy;
416 auto local_coords = layergeom->get_local_coords_from_pixel(row,col);
423 local_coords.SetY( 1
e-4 );
426 locxsum += local_coords.X();
427 loczsum += local_coords.Z();
435 for (
auto& hit : m_phi) {
436 std::cout <<
" m_phi(" << hit.first <<
" : " << hit.second<<
") " << std::endl;
446 locclusx = locxsum / nhits;
447 locclusz = loczsum / nhits;
449 const double pitch = layergeom->get_pixel_x();
450 const double length = layergeom->get_pixel_z();
451 const double phisize = phibins.size() * pitch;
454 static const double invsqrt12 = 1./std::sqrt(12);
463 double phierror = pitch * invsqrt12;
465 static constexpr std::array<double, 7> scalefactors_phi = {{ 0.36, 0.6,0.37,0.49,0.4,0.37,0.33 }};
466 if(phibins.size() == 1 && zbins.size() == 1) phierror*=scalefactors_phi[0];
467 else if(phibins.size() == 2 && zbins.size() == 1) phierror*=scalefactors_phi[1];
468 else if(phibins.size() == 1 && zbins.size() == 2) phierror*=scalefactors_phi[2];
469 else if( phibins.size() == 2 && zbins.size() == 2 ) phierror*=scalefactors_phi[0];
470 else if( phibins.size() == 2 && zbins.size() == 3 ) phierror*=scalefactors_phi[1];
471 else if( phibins.size() == 3 && zbins.size() == 2 ) phierror*=scalefactors_phi[2];
472 else if( phibins.size() == 3 && zbins.size() == 3 ) phierror*=scalefactors_phi[3];
480 static constexpr std::array<double, 4> scalefactors_z = {{ 0.47, 0.48, 0.71, 0.55 }};
481 double zerror = length*invsqrt12;
482 if( zbins.size() == 2 && phibins.size() == 2 ) zerror*=scalefactors_z[0];
483 else if( zbins.size() == 2 && phibins.size() == 3 ) zerror*=scalefactors_z[1];
484 else if( zbins.size() == 3 && phibins.size() == 2 ) zerror*=scalefactors_z[2];
485 else if( zbins.size() == 3 && phibins.size() == 3 ) zerror*=scalefactors_z[3];
488 cout <<
" MvtxClusterizer: cluskey " << ckey <<
" layer " << layer <<
" rad " << layergeom->get_radius() <<
" phibins " << phibins.size() <<
" pitch " << pitch <<
" phisize " << phisize
489 <<
" zbins " << zbins.size() <<
" length " << length <<
" zsize " << zsize
490 <<
" local x " << locclusx <<
" local y " << locclusz
493 auto clus = std::make_unique<TrkrClusterv5>();
496 clus->setLocalX(locclusx);
497 clus->setLocalY(locclusz);
498 clus->setPhiError(phierror);
499 clus->setZError(zerror);
500 clus->setPhiSize(phibins.size());
501 clus->setZSize(zbins.size());
504 clus->setSubSurfKey(0);
526 cout <<
"Entering MvtxClusterizer::ClusterMvtx " << endl;
529 if (!geom_container)
return;
539 hitsetitr != hitsetrange.second;
550 cout <<
"MvtxClusterizer found hitsetkey " << hitsetitr->first <<
" layer " << layer <<
" stave " << stave <<
" chip " << chip <<
" strobe " << strobe << endl;
557 std::vector <RawHit*> hitvec;
561 hitr != hitrangei.second;
564 hitvec.push_back((*hitr));
566 if (
Verbosity() > 2) cout <<
"hitvec.size(): " << hitvec.size() << endl;
570 typedef adjacency_list<vecS, vecS, undirectedS> Graph;
574 for (
unsigned int i = 0;
i < hitvec.size();
i++)
576 for (
unsigned int j = 0;
j < hitvec.size();
j++)
585 vector<int> component(num_vertices(G));
588 connected_components(G, &component[0]);
592 set<int> cluster_ids;
596 for (
unsigned int i = 0;
i < component.size();
i++)
598 cluster_ids.insert(component[
i]);
599 clusters.insert(make_pair(component[i], hitvec[i]));
603 for (set<int>::iterator clusiter = cluster_ids.begin(); clusiter != cluster_ids.end(); ++clusiter)
605 int clusid = *clusiter;
606 auto clusrange = clusters.equal_range(clusid);
608 if (
Verbosity() > 2) cout <<
"Filling cluster id " << clusid <<
" of " <<
std::distance(cluster_ids.begin(),clusiter )<< endl;
620 const unsigned int nhits =
std::distance( clusrange.first, clusrange.second );
622 double locclusx = NAN;
623 double locclusz = NAN;
631 for (
auto mapiter = clusrange.first; mapiter != clusrange.second; ++mapiter)
634 int col = (mapiter->second)->getPhiBin();
635 int row = (mapiter->second)->
getTBin();
640 auto local_coords = layergeom->get_local_coords_from_pixel(row,col);
647 local_coords.SetY( 1
e-4 );
650 locxsum += local_coords.X();
651 loczsum += local_coords.Z();
658 locclusx = locxsum / nhits;
659 locclusz = loczsum / nhits;
661 const double pitch = layergeom->get_pixel_x();
663 const double length = layergeom->get_pixel_z();
665 const double phisize = phibins.size() * pitch;
668 static const double invsqrt12 = 1./std::sqrt(12);
677 double phierror = pitch * invsqrt12;
679 static constexpr std::array<double, 7> scalefactors_phi = {{ 0.36, 0.6,0.37,0.49,0.4,0.37,0.33 }};
680 if(phibins.size() == 1 && zbins.size() == 1) phierror*=scalefactors_phi[0];
681 else if(phibins.size() == 2 && zbins.size() == 1) phierror*=scalefactors_phi[1];
682 else if(phibins.size() == 1 && zbins.size() == 2) phierror*=scalefactors_phi[2];
683 else if( phibins.size() == 2 && zbins.size() == 2 ) phierror*=scalefactors_phi[0];
684 else if( phibins.size() == 2 && zbins.size() == 3 ) phierror*=scalefactors_phi[1];
685 else if( phibins.size() == 3 && zbins.size() == 2 ) phierror*=scalefactors_phi[2];
686 else if( phibins.size() == 3 && zbins.size() == 3 ) phierror*=scalefactors_phi[3];
694 static constexpr std::array<double, 4> scalefactors_z = {{ 0.47, 0.48, 0.71, 0.55 }};
695 double zerror = length*invsqrt12;
696 if( zbins.size() == 2 && phibins.size() == 2 ) zerror*=scalefactors_z[0];
697 else if( zbins.size() == 2 && phibins.size() == 3 ) zerror*=scalefactors_z[1];
698 else if( zbins.size() == 3 && phibins.size() == 2 ) zerror*=scalefactors_z[2];
699 else if( zbins.size() == 3 && phibins.size() == 3 ) zerror*=scalefactors_z[3];
702 cout <<
" MvtxClusterizer: cluskey " << ckey <<
" layer " << layer <<
" rad " << layergeom->get_radius() <<
" phibins " << phibins.size() <<
" pitch " << pitch <<
" phisize " << phisize
703 <<
" zbins " << zbins.size() <<
" length " << length <<
" zsize " << zsize
704 <<
" local x " << locclusx <<
" local y " << locclusz
707 auto clus = std::make_unique<TrkrClusterv5>();
710 clus->setLocalX(locclusx);
711 clus->setLocalY(locclusz);
712 clus->setPhiError(phierror);
713 clus->setZError(zerror);
714 clus->setPhiSize(phibins.size());
715 clus->setZSize(zbins.size());
718 clus->setSubSurfKey(0);
742 TrkrClusterContainer *clusterlist = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER");
743 if (!clusterlist)
return;
745 cout <<
"================= After MvtxClusterizer::process_event() ====================" << endl;
747 cout <<
" There are " << clusterlist->
size() <<
" clusters recorded: " << endl;
751 cout <<
"===========================================================================" << endl;