18 , fIndexXYZ(kNColumns, vector<vector<Int_t>>(kNRows, vector<Int_t>(kNLayers, -1)))
27 for (Int_t r = 0; r <
GetNRows(); ++r) {
28 fIndexXYZ[c][r].clear();
51 Int_t index = fIndexXYZ[column][row][layer];
53 Double_t t1 = fTime[index];
54 Double_t e1 = fEdep[index];
55 t2 = (t2 > t1 ? t1 : t2);
64 fCell.push_back(cell);
65 fColumn.push_back(column);
67 fLayer.push_back(layer);
74 Double_t distance = TMath::Sqrt(TMath::Sq(x) + TMath::Sq(y) + TMath::Sq(z));
75 Double_t beta = (distance * 1.E-2) / (t2 * 1.E-9) / TMath::C();
76 fBeta.push_back(beta);
77 fIndexTime.push_back(fNCells);
78 fIndexEdep.push_back(fNCells);
79 fIndexBeta.push_back(fNCells);
82 fIndexXYZ[column][row][layer] = fNCells;
86 for (Int_t
i = fNCells;
i > 0; --
i) {
87 if (fTime[fIndexTime[
i - 1]] < fTime[fIndexTime[
i]])
89 temp = fIndexTime[
i - 1];
90 fIndexTime[
i - 1] = fIndexTime[
i];
93 for (Int_t
i = fNCells;
i > 0; --
i) {
94 if (fEdep[fIndexEdep[
i - 1]] > fEdep[fIndexEdep[
i]])
96 temp = fIndexEdep[
i - 1];
97 fIndexEdep[
i - 1] = fIndexEdep[
i];
100 for (Int_t
i = fNCells;
i > 0; --
i) {
101 if (fBeta[fIndexBeta[
i - 1]] > fBeta[fIndexBeta[
i]])
103 temp = fIndexBeta[
i - 1];
104 fIndexBeta[
i - 1] = fIndexBeta[
i];
105 fIndexBeta[
i] = temp;
123 for (Int_t iCell = 0; iCell < fNCells; ++iCell) {
124 if (fEdep[iCell] > threshold)
132 return fIndexXYZ.size();
137 return fIndexXYZ[0].size();
142 return fIndexXYZ[0][0].size();
188 if (i_cluster < 0 || i_cluster >= fNClusters)
190 return fClusters[i_cluster];
195 if (i_cluster >= fNClusters || i_cluster < 0)
197 return fClusterStatus[i_cluster];
202 if (i_cluster >= fNClusters || i_cluster < 0)
205 fClusterStatus[i_cluster] = status;
211 fClusters.push_back(cl);
220 i_cluster = fNClusters - 1;
221 if (i_cell < 0 || i_cell >= fNCells)
223 if (i_cluster < 0 || i_cluster >= fNClusters)
226 Int_t
i = fCell[i_cell];
227 Int_t c = fColumn[i_cell];
228 Int_t r = fRow[i_cell];
229 Int_t l = fLayer[i_cell];
230 Double_t x = fXcoord[i_cell];
231 Double_t y = fYcoord[i_cell];
232 Double_t z = fZcoord[i_cell];
233 Double_t t = fTime[i_cell];
234 Double_t e = fEdep[i_cell];
235 Double_t b = fBeta[i_cell];
236 cl->
AddCell(
i, c, r, l, x, y, z, t, e, b);
238 --fNUncheckedCellsInEvent;
243 fNUncheckedCellsInEvent = fNCells;
244 while (fNUncheckedCellsInEvent > 0) {
247 for (Int_t iTime = 0; iTime < fNCells; ++iTime) {
248 Int_t iCell = fIndexTime[iTime];
261 Int_t iCellInCluster = 0;
262 while (iCellInCluster < cl->
GetNCells()) {
264 for (Int_t dIx : {-1, 0, 1}) {
268 for (Int_t dIy : {-1, 0, 1}) {
269 Int_t
iY = cl->
GetRows()[iCellInCluster] + dIy;
272 for (Int_t dIz : {-1, 0, 1}) {
278 Int_t iNeighbour = fIndexXYZ[
iX][
iY][
iZ];
295 fNUncheckedCellsInEvent = fNCells;
296 while (fNUncheckedCellsInEvent > 0) {
299 for (Int_t iTime = 0; iTime < fNCells; ++iTime) {
300 Int_t iCell = fIndexTime[iTime];
312 Bool_t checkAllLayers = kFALSE;
314 checkAllLayers = kTRUE;
316 Int_t iCellInCluster = 0;
317 while (iCellInCluster < cl->
GetNCells()) {
319 for (Int_t dIx : {-1, 0, 1}) {
323 for (Int_t dIy : {-1, 0, 1}) {
324 Int_t
iY = cl->
GetRows()[iCellInCluster] + dIy;
327 if (checkAllLayers) {
330 Int_t iNeighbour = fIndexXYZ[
iX][
iY][
iZ];
337 for (Int_t dIz : {-1, 0, 1}) {
343 Int_t iNeighbour = fIndexXYZ[
iX][
iY][
iZ];
361 fNUncheckedCellsInEvent = fNCells;
362 while (fNUncheckedCellsInEvent > 0) {
365 for (Int_t iBeta = 0; iBeta < fNCells; ++iBeta) {
366 Int_t iCell = fIndexBeta[iBeta];
379 Int_t iCellInCluster = 0;
380 while (iCellInCluster < cl->
GetNCells()) {
382 for (Int_t dIx : {-1, 0, 1}) {
386 for (Int_t dIy : {-1, 0, 1}) {
387 Int_t
iY = cl->
GetRows()[iCellInCluster] + dIy;
390 for (Int_t dIz : {-1, 0, 1}) {
396 Int_t iNeighbour = fIndexXYZ[
iX][
iY][
iZ];
413 fNUncheckedCellsInEvent = fNCells;
414 while (fNUncheckedCellsInEvent > 0) {
417 for (Int_t iBeta = 0; iBeta < fNCells; ++iBeta) {
418 Int_t iCell = fIndexBeta[iBeta];
431 Int_t iCellInCluster = 0;
432 while (iCellInCluster < cl->
GetNCells()) {
434 for (Int_t dIx : {-1, 0, 1}) {
438 for (Int_t dIy : {-1, 0, 1}) {
439 Int_t
iY = cl->
GetRows()[iCellInCluster] + dIy;
442 for (Int_t dIz : {-1, 0, 1, 2}) {
448 Int_t iNeighbour = fIndexXYZ[
iX][
iY][
iZ];
465 fNUncheckedCellsInEvent = fNCells;
466 while (fNUncheckedCellsInEvent > 0) {
469 for (Int_t iBeta = 0; iBeta < fNCells; ++iBeta) {
470 Int_t iCell = fIndexBeta[iBeta];
482 Double_t beta0 = fBeta[iCell1];
484 Int_t iCellInCluster = 0;
485 while (iCellInCluster < cl->
GetNCells()) {
487 for (Int_t dIx : {-1, 0, 1}) {
491 for (Int_t dIy : {-1, 0, 1}) {
492 Int_t
iY = cl->
GetRows()[iCellInCluster] + dIy;
495 for (Int_t dIz : {-1, 0, 1}) {
501 Int_t iNeighbour = fIndexXYZ[
iX][
iY][
iZ];
504 if (fCellStatus[iNeighbour] ==
kIsUsed)
506 if (TMath::Abs(fBeta[iNeighbour] - beta0) > cut_beta)
521 fNUncheckedCellsInEvent = fNCells;
522 while (fNUncheckedCellsInEvent > 0) {
525 for (Int_t iTime = 0; iTime < fNCells; ++iTime) {
526 Int_t iCell = fIndexTime[iTime];
539 Double_t x0 = cl->
GetX()[0];
540 Double_t y0 = cl->
GetY()[0];
541 Double_t
z0 = cl->
GetZ()[0];
542 Double_t t0 = cl->
GetTime()[0];
545 Int_t iCellInCluster = 0;
546 while (iCellInCluster < cl->
GetNCells()) {
547 Double_t x1 = cl->
GetX()[iCellInCluster];
548 Double_t y1 = cl->
GetY()[iCellInCluster];
549 Double_t z1 = cl->
GetZ()[iCellInCluster];
550 Double_t t1 = cl->
GetTime()[iCellInCluster];
552 for (Int_t dIx : {-1, 0, 1}) {
556 for (Int_t dIy : {-1, 0, 1}) {
557 Int_t
iY = cl->
GetRows()[iCellInCluster] + dIy;
560 for (Int_t dIz : {-1, 0, 1}) {
566 Int_t iNeighbour = fIndexXYZ[
iX][
iY][
iZ];
569 Double_t x2 = cl->
GetX()[iNeighbour];
570 Double_t y2 = cl->
GetY()[iNeighbour];
571 Double_t z2 = cl->
GetZ()[iNeighbour];
572 Double_t t2 = cl->
GetTime()[iNeighbour];
573 Double_t distance21 =
574 TMath::Sqrt(TMath::Sq(x2 - x1) + TMath::Sq(y2 - y1) + TMath::Sq(z2 - z1));
575 Double_t distance20 =
576 TMath::Sqrt(TMath::Sq(x2 - x0) + TMath::Sq(y2 - y0) + TMath::Sq(z2 -
z0));
577 Double_t d_time20 = t2 - t0;
578 Double_t d_time21 = t2 - t1;
580 d_time20 <= 0 ? -1. : distance20 * 1.E-2 / (d_time20 * 1.E-9) / TMath::C();
582 d_time21 <= 0 ? -1. : distance21 * 1.E-2 / (d_time21 * 1.E-9) / TMath::C();
583 if (beta20 > 1. || beta20 < 0.)
585 if (beta21 > 1. || beta21 < 0.)
587 if (TMath::Abs(beta21 - beta0) > cut_beta)
589 if (fCellStatus[iNeighbour] ==
kIsUsed)
605 if (i_cluster_1 == i_cluster_2)
607 Int_t i1 =
min(i_cluster_1, i_cluster_2);
608 Int_t i2 =
max(i_cluster_1, i_cluster_2);
613 for (Int_t iCell2 = 0; iCell2 < cl2->
GetNCells(); ++iCell2) {
619 fClusters.erase(fClusters.begin() + i2);
620 fClusterStatus.erase(fClusterStatus.begin() + i2);
629 for (Int_t iCluster = 0; iCluster < fNClusters; ++iCluster) {
646 Double_t weight_ncells,
647 Double_t weight_nclusters,
648 Double_t threshold12)
652 Int_t n_clusters = 0;
654 for (Int_t iCluster = 0; iCluster < fNClusters; ++iCluster) {
665 Double_t separation_parameter = weight_edep * edep + weight_ncells * n_cells + weight_nclusters * n_clusters;
666 if (separation_parameter > threshold12)
673 for (Int_t
i = 0;
i < fNCells; ++
i) {
684 fIndexTime.pop_back();
685 fIndexEdep.pop_back();
686 fIndexBeta.pop_back();
687 fCellStatus.pop_back();
692 for (Int_t r = 0; r <
GetNRows(); ++r) {
694 fIndexXYZ[c][r][l] = -1;
699 for (Int_t
i = 0;
i < fNClusters; ++
i) {
700 fClusters.pop_back();
701 fClusterStatus.pop_back();
708 cout <<
"----------------------------- BmnNdetClusterFinder -----------------------------" << endl;
709 for (Int_t
i = 0;
i < fNCells; ++
i) {
710 cout << fCell[
i] <<
" cell (" << fColumn[
i] <<
", " << fRow[
i] <<
", " << fLayer[
i] <<
"): ";
711 cout <<
" i: " << fIndexXYZ[fColumn[
i]][fRow[
i]][fLayer[
i]];
712 cout <<
"\tX: " << fXcoord[
i] <<
"[cm], Y: " << fYcoord[
i] <<
"[cm], Z: " << fZcoord[
i] <<
"[cm]";
713 cout <<
"\tt: " << fTime[
i] <<
"[ns], Edep: " << 1.E3 * fEdep[
i] <<
"[MeV]" << endl;
717 cout <<
"Sorted time" << endl;
718 for (Int_t
i = 0;
i < fNCells; ++
i) {
719 cout << fIndexTime[
i] <<
"(" << fTime[fIndexTime[
i]] <<
"), ";
723 cout <<
"Sorted edep" << endl;
724 for (Int_t
i = 0;
i < fNCells; ++
i) {
725 cout << fIndexEdep[
i] <<
"(" << fEdep[fIndexEdep[
i]] <<
"), ";
729 cout <<
"Sorted beta" << endl;
730 for (Int_t
i = 0;
i < fNCells; ++
i) {
731 cout << fIndexBeta[
i] <<
"(" << fBeta[fIndexBeta[
i]] <<
"), ";
734 cout <<
"------------------------------------------------------------------------------------" << endl;
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
vector< Double_t > GetZ()
void Clear()
Clear all vectors, set fNCells=0.
vector< Int_t > GetCells()
vector< Double_t > GetTime()
vector< Int_t > GetLayers()
vector< Double_t > GetEdep()
BmnNdetClusterFinder(const Int_t kNColumns=11, const Int_t kNRows=11, const Int_t kNLayers=16)
Default constructor.
Int_t SelectNeutrons(Double_t cut_angle=45., Int_t cut_ncells=3, Bool_t check_border=kFALSE)
Int_t CalculateNumberOfNeutrons(Double_t weight_edep=1., Double_t weight_ncells=0.01, Double_t weight_nclusters=0.05, Double_t threshold12=0.)
Int_t FindClusters4(Double_t cut_beta=0.01)
Int_t FindClusters3(Double_t cut_beta=0.03)
vector< Double_t > GetY()
vector< Int_t > GetColumns()
BmnNdetCluster * AddCluster()
Int_t GetClusterStatus(Int_t i_cluster)
vector< Double_t > GetBeta()
BmnNdetCluster * GetCluster(Int_t i_cluster)
eClusterStatus
Status of the cluster.
void SetClusterStatus(Int_t i_cluster, eClusterStatus status)
vector< Int_t > GetRows()
Int_t MergeClusters(Int_t i_cluster_1, Int_t i_cluster_2)
vector< Double_t > GetX()
void Fill(Int_t cell, Int_t column, Int_t row, Int_t layer, Double_t x, Double_t y, Double_t z, Double_t t, Double_t e_dep)
void AddCellToCluster(Int_t i_cell, Int_t i_cluster)
~BmnNdetClusterFinder()
Default destructor.
Class for description of recognized cluster in Bmn Ndet detector.
vector< Double_t > GetZ()
Double_t EnergyDeposited(Double_t threshold=0.003)
vector< Double_t > GetBeta()
vector< Int_t > GetLayers()
void AddCell(Int_t cell, Int_t column, Int_t row, Int_t layer, Double_t x, Double_t y, Double_t z, Double_t t, Double_t e_dep, Double_t beta=-1.)
vector< Double_t > GetTime()
vector< Double_t > GetY()
vector< Double_t > GetEdep()
vector< Int_t > GetColumns()
vector< Double_t > GetX()
Bool_t StartsOnBorder(Int_t size_x=11, Int_t size_y=11, Int_t size_z=8)
vector< Int_t > GetRows()