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