3 #include <tpc/TpcDefs.h>
27 #include <TMatrixFfwd.h>
29 #include <TMatrixTUtils.h>
43 , m_clusterlist(nullptr)
44 , m_clusterhitassoc(nullptr)
45 , zz_shaping_correction(0.0754)
58 double centval = adcval[phibin][zbin];
62 for (
int iz = zbin - 4; iz <= zbin + 4; iz++)
63 for (
int iphi = phibin - 2; iphi <= phibin + 2; iphi++)
72 if (adcval[iphi][iz] > centval)
87 for (
int iphi = phibin + 1; iphi < phibin + 4; iphi++)
91 if (adcval[iphi][zbin] <= 0)
94 if (adcval[iphi][zbin] <= adcval[iphi - 1][zbin])
100 for (
int iphi = phibin - 1; iphi > phibin - 4; iphi--)
104 if (adcval[iphi][zbin] <= 0)
107 if (adcval[iphi][zbin] <= adcval[iphi + 1][zbin])
115 for (
int iz = zbin + 1; iz < zbin + 10; iz++)
119 if (adcval[phibin][iz] <= 0)
122 if (adcval[phibin][iz] <= adcval[phibin][iz - 1])
128 for (
int iz = zbin - 1; iz > zbin - 10; iz--)
132 if (adcval[phibin][iz] <= 0)
135 if (adcval[phibin][iz] <= adcval[phibin][iz + 1])
150 cout <<
PHWHERE <<
"DST Node missing, doing nothing." << endl;
155 TrkrClusterContainer *trkrclusters = findNode::getClass<TrkrClusterContainer>(dstNode,
"TRKR_CLUSTER");
164 dstNode->addNode(DetNode);
170 DetNode->
addNode(TrkrClusterContainerNode);
173 TrkrClusterHitAssoc *clusterhitassoc = findNode::getClass<TrkrClusterHitAssoc>(topNode,
"TRKR_CLUSTERHITASSOC");
174 if (!clusterhitassoc)
182 dstNode->addNode(DetNode);
195 int print_layer = 47;
198 std::cout <<
"TpcPrototypeClusterizer::Process_Event" << std::endl;
204 cout <<
PHWHERE <<
"DST Node missing, doing nothing." << endl;
209 m_hits = findNode::getClass<TrkrHitSetContainer>(topNode,
"TRKR_HITSET");
212 cout <<
PHWHERE <<
"ERROR: Can't find node TRKR_HITSET" << endl;
217 m_clusterlist = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER");
220 cout <<
PHWHERE <<
" ERROR: Can't find TRKR_CLUSTER." << endl;
225 m_clusterhitassoc = findNode::getClass<TrkrClusterHitAssoc>(topNode,
"TRKR_CLUSTERHITASSOC");
228 cout <<
PHWHERE <<
" ERROR: Can't find TRKR_CLUSTERHITASSOC" << endl;
233 findNode::getClass<PHG4CylinderCellGeomContainer>(topNode,
"CYLINDERCELLGEOM_SVTX");
236 std::cout <<
PHWHERE <<
"ERROR: Can't find node CYLINDERCELLGEOM_SVTX" << std::endl;
246 hitsetitr != hitsetrange.second;
251 cout <<
"TpcPrototypeClusterizer process hitsetkey " << hitsetitr->first
282 std::vector<std::vector<double>> adcval(NPhiBins, std::vector<double>(NZBins, 0));
286 hitr != hitrangei.second;
291 if (hitr->second->getAdc() > 0)
292 adcval[phibin][zbin] = (
double) hitr->second->getAdc() -
pedestal;
296 cout <<
" add hit in layer " << layer <<
" with phibin " << phibin <<
" zbin " << zbin <<
" adcval " << hitr->second->getAdc() <<
"->" << adcval[phibin][zbin] << endl;
299 vector<int> phibinlo;
300 vector<int> phibinhi;
305 hitr != hitrangei.second;
317 get_cluster(phibin, zbin, phiup, phidown, zup, zdown, adcval);
319 if (phiup == 0 && phidown == 0 && zup == 0 and zdown == 0)
continue;
322 phibinlo.push_back(phibin - phidown);
323 phibinhi.push_back(phibin + phiup);
324 zbinlo.push_back(zbin - zdown);
325 zbinhi.push_back(zbin + zup);
329 cout <<
" cluster found in layer " << layer <<
" around hitkey " << hitr->first <<
" with zbin " << zbin <<
" zup " << zup <<
" zdown " << zdown
330 <<
" phibin " << phibin <<
" phiup " << phiup <<
" phidown " << phidown << endl;
334 for (
unsigned int iclus = 0; iclus < phibinlo.size(); iclus++)
339 double phi_sum = 0.0;
340 double adc_sum = 0.0;
343 if (layer == print_layer)
345 cout <<
"iclus " << iclus <<
" layer " << layer <<
" radius " << radius << endl;
346 cout <<
" z bin range " << zbinlo[iclus] <<
" to " << zbinhi[iclus] <<
" phibin range " << phibinlo[iclus] <<
" to " << phibinhi[iclus] << endl;
349 std::vector<TrkrDefs::hitkey> hitkeyvec;
350 for (
int iphi = phibinlo[iclus]; iphi <= phibinhi[iclus]; iphi++)
352 for (
int iz = zbinlo[iclus]; iz <= zbinhi[iclus]; iz++)
357 zsum += z * adcval[iphi][iz];
358 phi_sum += phi_center * adcval[iphi][iz];
359 adc_sum += adcval[iphi][iz];
362 if (adcval[iphi][iz] != 0)
365 hitkeyvec.push_back(hitkey);
370 if (adc_sum < 10)
continue;
373 double clusphi = phi_sum / adc_sum;
374 double clusz = zsum / adc_sum;
380 double phi_size = (
double) (phibinhi[iclus] - phibinlo[iclus] + 1) * radius * layergeom->
get_phistep();
381 double z_size = (
double) (zbinhi[iclus] - zbinlo[iclus] + 1) * layergeom->
get_zstep();
384 double dphi2_adc = 0.0;
385 double dphi_adc = 0.0;
386 double dz2_adc = 0.0;
388 for (
int iz = zbinlo[iclus]; iz <= zbinhi[iclus]; iz++)
390 for (
int iphi = phibinlo[iclus]; iphi <= phibinhi[iclus]; iphi++)
393 dphi2_adc += dphi * dphi * adcval[iphi][iz];
394 dphi_adc += dphi * adcval[iphi][iz];
397 dz2_adc += dz * dz * adcval[iphi][iz];
398 dz_adc += dz * adcval[iphi][iz];
401 double phi_cov = (dphi2_adc / adc_sum - dphi_adc * dphi_adc / (adc_sum * adc_sum));
402 double z_cov = dz2_adc / adc_sum - dz_adc * dz_adc / (adc_sum * adc_sum);
414 double phi_err = radius * sqrt(phi_cov / (adc_sum * 0.14));
416 phi_err = radius * layergeom->
get_phistep() / sqrt(12.0);
418 double z_err = sqrt(z_cov / (adc_sum * 0.14));
420 z_err = layergeom->
get_zstep() / sqrt(12.0);
430 clus->setAdc(adc_sum);
431 clus->setPosition(0, radius * cos(clusphi));
432 clus->setPosition(1, radius * sin(clusphi));
433 clus->setPosition(2, clusz);
441 DIM[1][1] = phi_size / radius * phi_size / radius;
445 DIM[2][2] = z_size * z_size;
452 ERR[1][1] = phi_err * phi_err;
456 ERR[2][2] = z_err * z_err;
459 ROT[0][0] = cos(clusphi);
460 ROT[0][1] = -sin(clusphi);
462 ROT[1][0] = sin(clusphi);
463 ROT[1][1] = cos(clusphi);
469 TMatrixF ROT_T(3, 3);
470 ROT_T.Transpose(ROT);
472 TMatrixF COVAR_DIM(3, 3);
473 COVAR_DIM = ROT * DIM * ROT_T;
475 clus->setSize(0, 0, COVAR_DIM[0][0]);
476 clus->setSize(0, 1, COVAR_DIM[0][1]);
477 clus->setSize(0, 2, COVAR_DIM[0][2]);
478 clus->setSize(1, 0, COVAR_DIM[1][0]);
479 clus->setSize(1, 1, COVAR_DIM[1][1]);
480 clus->setSize(1, 2, COVAR_DIM[1][2]);
481 clus->setSize(2, 0, COVAR_DIM[2][0]);
482 clus->setSize(2, 1, COVAR_DIM[2][1]);
483 clus->setSize(2, 2, COVAR_DIM[2][2]);
486 TMatrixF COVAR_ERR(3, 3);
487 COVAR_ERR = ROT * ERR * ROT_T;
489 clus->setError(0, 0, COVAR_ERR[0][0]);
490 clus->setError(0, 1, COVAR_ERR[0][1]);
491 clus->setError(0, 2, COVAR_ERR[0][2]);
492 clus->setError(1, 0, COVAR_ERR[1][0]);
493 clus->setError(1, 1, COVAR_ERR[1][1]);
494 clus->setError(1, 2, COVAR_ERR[1][2]);
495 clus->setError(2, 0, COVAR_ERR[2][0]);
496 clus->setError(2, 1, COVAR_ERR[2][1]);
497 clus->setError(2, 2, COVAR_ERR[2][2]);
508 for (
unsigned int i = 0;
i < hitkeyvec.size();
i++)
518 cout <<
"Dump clusters after TpcPrototypeClusterizer" << endl;
524 cout <<
"Dump cluster hit associations after TpcPrototypeClusterizer" << endl;