CbmRoot
Loading...
Searching...
No Matches
CbmClusteringA1.cxx
Go to the documentation of this file.
1/* Copyright (C) 2012-2016 GSI/JINR-LIT, Darmstadt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Grigory Kozlov, Andrey Lebedev [committer] */
4
5/*
6 * CbmClusteringA1.cxx
7 *
8 * Created on: Apr 4, 2012
9 * Author: kozlov
10 */
11
12#include "CbmClusteringA1.h"
13
15#include "CbmMCTrack.h"
16#include "CbmMuchDigi.h"
17#include "CbmMuchGeoScheme.h"
18#include "CbmMuchLayerSide.h"
19#include "CbmMuchModuleGem.h"
20#include "CbmMuchPad.h"
21#include "CbmMuchPixelHit.h"
22#include "CbmMuchPoint.h"
23#include "CbmStsHit.h"
24#include "CbmStsPoint.h"
25#include "FairRootManager.h"
26
27#include <cassert>
28#include <iostream>
29
30using std::cout;
31using std::endl;
32using std::vector;
33
34CbmClusteringA1::CbmClusteringA1() : fA1(), fA2(), fS(), fClusters(), fNumbersOfPads()
35{
36 fNofPads = 0;
38 fNofClusters = 0;
39}
40
42{
43 //Initialization
44 fNofPads = moduleGeo->GetNPads();
45 fNofActivePads = moduleGeo->GetAPadsNom();
47 fA1 = new UInt_t[fNofPads];
48 fA2 = new UInt_t[fNofPads];
49 fS = new Bool_t[fNofPads];
50 fNumbersOfPads = new Int_t[fNofPads];
51 Int_t nom = 0;
52 for (Int_t iPad = 0; iPad < fNofPads; iPad++) {
53 fA1[iPad] = moduleGeo->GetPadCharge(iPad); //Filling primary array of charges
54 fA2[iPad] = 0;
55 fS[iPad] = 0;
56 fNumbersOfPads[iPad] = 0;
57 if (fA1[iPad] > 0) {
58 fS[iPad] = 1; //Filling array of states
59 nom++;
60 fNumbersOfPads[iPad] = nom; //Filling array of relations Pad/Cluster
61 }
62 }
63}
64
66{
67 delete[] fA1;
68 delete[] fA2;
69 delete[] fS;
70 delete[] fNumbersOfPads;
71 delete[] fClusters;
72}
73
75{
76 //algVersion == 1 -> all neighbors
77 //algVersion == 2 -> only good neighbors
78 Int_t localMaximum;
79 Int_t temp;
80 UInt_t temp1;
81 //First step of clustering algorithm: Creating relationships between objects
82 for (Int_t iPad = 0; iPad < fNofPads; iPad++) {
83 if (fA1[iPad] > 0) {
84 localMaximum = iPad;
85 if (algVersion == 1) {
86 for (Int_t nPad = 0; nPad < moduleGeo->GetNeighborsNum(iPad); nPad++) {
87 if (fA1[moduleGeo->GetNeighbor(iPad, nPad)] > fA1[localMaximum]) {
88 localMaximum = moduleGeo->GetNeighbor(iPad, nPad);
89 }
90 }
91 }
92 if (algVersion == 2) {
93 for (Int_t nPad = 0; nPad < moduleGeo->GetGoodNeighborsNum(iPad); nPad++) {
94 if (fA1[moduleGeo->GetNeighbor(iPad, nPad)] > fA1[localMaximum]) {
95 localMaximum = moduleGeo->GetNeighbor(iPad, nPad);
96 }
97 }
98 }
99 if ((algVersion != 1) && (algVersion != 2)) {
100 std::cout << "Error! Unsupported version of the algorithm.\n";
101 }
102 fA2[localMaximum] += fA1[iPad]; //Filling secondary array of charges
103 //fA2[iPad] -= fA1[iPad]; //For a special cases
104 if (iPad != localMaximum) {
105 fA2[iPad] = 0;
107 ChangeClusters(moduleGeo, iPad, fNumbersOfPads[iPad], fNumbersOfPads[localMaximum],
108 algVersion); //Changing relationships
109 }
110 }
111 }
112 //Second step of clustering algorithm: Creating clusters by relationships
113 fClusters = new Cluster[(Int_t)(fNofActivePads)];
114 for (Int_t iPad = 0; iPad < (Int_t)(fNofActivePads); iPad++) //All clusters are empty
115 {
116 fClusters[iPad].fNCluster = 0;
117 fClusters[iPad].fNofPads = 0;
118 fClusters[iPad].fCharge = 0;
119 fClusters[iPad].fX = 0;
120 fClusters[iPad].fY = 0;
121 fClusters[iPad].fPadsInCluster.clear();
122 fClusters[iPad].fNPadsInCluster.clear();
123 fClusters[iPad].fPadsCharges.clear();
124 }
125
126 Int_t nomCl = 0;
127 Int_t Replase = 0;
128 for (Int_t iPad = 0; iPad < fNofPads; iPad++) {
129 if ((fA2[iPad] != 0) && (fS[iPad] == 1)) {
130 Replase = fNumbersOfPads[iPad];
131 nomCl++;
132 Int_t padInCluster = 0;
133 for (Int_t nPad = 0; nPad < fNofPads; nPad++) {
134 if ((fNumbersOfPads[nPad] == Replase) && (moduleGeo->GetPadCharge(nPad) > 0) && (fS[nPad] == 1)) {
135 //Filling clusters
136 fNumbersOfPads[nPad] = nomCl;
137 fS[nPad] = 0;
138 fClusters[nomCl - 1].fNCluster = nomCl;
139 fClusters[nomCl - 1].fX += (moduleGeo->GetX0(nPad) * moduleGeo->GetPadCharge(nPad));
140 fClusters[nomCl - 1].fY += (moduleGeo->GetY0(nPad) * moduleGeo->GetPadCharge(nPad));
141 fClusters[nomCl - 1].fCharge += moduleGeo->GetPadCharge(nPad);
142 fClusters[nomCl - 1].fPadsInCluster.push_back(moduleGeo->GetDigiNum(nPad));
143 fClusters[nomCl - 1].fNPadsInCluster.push_back(nPad);
144 fClusters[nomCl - 1].fPadsCharges.push_back(fA1[nPad]);
145 padInCluster++;
146 fClusters[nomCl - 1].fNofPads = padInCluster;
147 }
148 }
149 }
150 }
151 //Hits calculation
152 for (Int_t iCl = 0; iCl < nomCl; iCl++) {
153 if (fClusters[iCl].fCharge == 0) {
154 cout << " - MainClusteringA1: Warning! DIVISION ON ZERO!";
155 break;
156 }
157 fClusters[iCl].fX = fClusters[iCl].fX / fClusters[iCl].fCharge;
158 fClusters[iCl].fY = fClusters[iCl].fY / fClusters[iCl].fCharge;
159 }
160 fNofClusters = nomCl;
161}
162
163void CbmClusteringA1::ChangeClusters(CbmClusteringGeometry* moduleGeo, Int_t nPad, Int_t Cl0, Int_t Cl1, Int_t vers)
164{
165 fNumbersOfPads[nPad] = Cl1;
166 Int_t nofNeighbors = 0;
167 if (vers == 1) nofNeighbors = moduleGeo->GetNeighborsNum(nPad);
168 if (vers == 2) nofNeighbors = moduleGeo->GetGoodNeighborsNum(nPad);
169 for (Int_t iPad = 0; iPad < nofNeighbors; iPad++) {
170 if (fNumbersOfPads[moduleGeo->GetNeighbor(nPad, iPad)] == Cl0) {
171 ChangeClusters(moduleGeo, moduleGeo->GetNeighbor(nPad, iPad), Cl0, Cl1, vers);
172 }
173 }
174}
175
176Int_t CbmClusteringA1::GetCluster(Int_t iCluster) { return fClusters[iCluster].fNCluster; }
177Float_t CbmClusteringA1::GetX0(Int_t iCluster) { return fClusters[iCluster].fX; }
178Float_t CbmClusteringA1::GetY0(Int_t iCluster) { return fClusters[iCluster].fY; }
179UInt_t CbmClusteringA1::GetClCharge(Int_t iCluster) { return fClusters[iCluster].fCharge; }
180Int_t CbmClusteringA1::GetNofPads(Int_t iCluster) { return fClusters[iCluster].fNofPads; }
181Int_t CbmClusteringA1::GetPadInCluster(Int_t iCluster, Int_t iPad) { return fClusters[iCluster].fPadsInCluster[iPad]; }
182
183Int_t CbmClusteringA1::GetNPadInCluster(Int_t iCluster, Int_t iPad)
184{
185 return fClusters[iCluster].fNPadsInCluster[iPad];
186}
187
188vector<Int_t> CbmClusteringA1::GetPads(Int_t iCluster) { return fClusters[iCluster].fPadsInCluster; }
189
190UInt_t CbmClusteringA1::GetPadCharge(Int_t iCluster, Int_t iPad) { return fClusters[iCluster].fPadsCharges[iPad]; }
Class for pixel hits in MUCH detector.
Data class for a reconstructed hit in the STS.
std::vector< Int_t > GetPads(Int_t iCluster)
Int_t GetPadInCluster(Int_t iCluster, Int_t iPad)
UInt_t GetPadCharge(Int_t iCluster, Int_t iPad)
Int_t GetNPadInCluster(Int_t iCluster, Int_t iPad)
virtual ~CbmClusteringA1()
Int_t GetCluster(Int_t iCluster)
void MainClusteringA1(CbmClusteringGeometry *moduleGeo, Int_t algVersion)
void ChangeClusters(CbmClusteringGeometry *moduleGeo, Int_t nPad, Int_t Cl0, Int_t Cl1, Int_t algVersion)
Int_t GetNofPads() const
Float_t GetX0(Int_t iCluster)
Float_t GetY0(Int_t iCluster)
UInt_t GetClCharge(Int_t iCluster)
Int_t GetGoodNeighborsNum(Int_t iPad)
Int_t GetNeighbor(Int_t iPad, Int_t iNeighbor)
std::vector< Int_t > fNPadsInCluster
std::vector< Int_t > fPadsInCluster
std::vector< Int_t > fPadsCharges