4 #include "StIstScanClusterAlgo.h"
5 #include "StIstUtil/StIstCollection.h"
6 #include "StIstUtil/StIstRawHitCollection.h"
7 #include "StIstUtil/StIstRawHit.h"
8 #include "StIstUtil/StIstClusterCollection.h"
9 #include "StIstUtil/StIstCluster.h"
10 #include "StIstUtil/StIstConsts.h"
24 Int_t clusterType = kIstScanClusterAlgo;
25 Int_t maxTb = -1, usedTb = -1;
26 Int_t ladder = 0, sensor = 0;
27 Float_t meanRow = 0., meanColumn = 0.;
28 Float_t totCharge = 0., totChargeErr = 0.;
29 Int_t clusterSize = 0, clusterSizeRPhi = 0, clusterSizeZ = 0;
30 unsigned short idTruth = 0;
33 Int_t nTimeBins = istCollection.getNumTimeBins();
36 rawHitsOriginal.sortByGeoId();
41 std::vector<StIstRawHit *> rawHitsToMerge;
52 for (std::vector< StIstRawHit * >::iterator rawHitPtr = rawHitsOriginal.getRawHitVec().begin(); rawHitPtr != rawHitsOriginal.getRawHitVec().end(); ++rawHitPtr) {
53 int sensorIndex = (int)(*rawHitPtr)->getSensor();
54 int columnIndex = (int)(*rawHitPtr)->getColumn();
55 rawHitsVec[sensorIndex - 1][columnIndex - 1].push_back(
new StIstRawHit( *(*rawHitPtr)) );
66 while ( !rawHitsVec[sensorIdx][columnIdx].empty() )
68 rawHitTemp = rawHitsVec[sensorIdx][columnIdx].back();
69 rawHitsVec[sensorIdx][columnIdx].pop_back();
70 rawHitsToMerge.push_back(rawHitTemp);
75 std::vector<StIstRawHit *>::iterator rawHitsToMergePtr = rawHitsToMerge.begin();
76 rawHitMaxAdcTemp = *rawHitsToMergePtr;
80 while (rawHitsToMergePtr != rawHitsToMerge.end() && !rawHitsVec[sensorIdx][columnIdx].empty()) {
81 rawHitTemp = rawHitsVec[sensorIdx][columnIdx].back();
82 rawHitTempBack = rawHitsVec[sensorIdx][columnIdx].back();
84 if ( (*rawHitsToMergePtr)->getRow() == rawHitTemp->
getRow() + 1 ) {
85 rawHitsVec[sensorIdx][columnIdx].pop_back();
87 if (!rawHitsVec[sensorIdx][columnIdx].empty()) {
88 rawHitNext = rawHitsVec[sensorIdx][columnIdx].back();
90 if ( (rawHitTemp->
getRow() == rawHitNext->
getRow() + 1) &&
91 (rawHitTemp->getCharge(rawHitTemp->getMaxTimeBin()) < (*rawHitsToMergePtr)->getCharge((*rawHitsToMergePtr)->getMaxTimeBin())) &&
92 (rawHitTemp->getCharge(rawHitTemp->getMaxTimeBin()) < rawHitNext->getCharge(rawHitNext->getMaxTimeBin())) )
94 float weightBack = rawHitNext->getCharge(rawHitNext->getMaxTimeBin()) / ((*rawHitsToMergePtr)->getCharge((*rawHitsToMergePtr)->getMaxTimeBin()) + rawHitNext->getCharge(rawHitNext->getMaxTimeBin()));
96 for (
int iTB = 0; iTB < nTimeBins; iTB++) {
97 rawHitTempBack->setCharge(weightBack * rawHitTemp->getCharge(iTB), iTB);
98 rawHitTemp->setCharge((1.0 - weightBack) * rawHitTemp->getCharge(iTB), iTB);
101 rawHitsVec[sensorIdx][columnIdx].push_back(rawHitTempBack);
106 rawHitsToMerge.push_back(rawHitTemp);
108 if ( rawHitTemp->getCharge(rawHitTemp->getMaxTimeBin()) > (*rawHitsToMergePtr)->getCharge((*rawHitsToMergePtr)->getMaxTimeBin()) )
109 rawHitMaxAdcTemp = rawHitTemp;
116 maxTb = rawHitMaxAdcTemp->getMaxTimeBin();
119 if (maxTb < 0 || maxTb >= nTimeBins) maxTb = rawHitMaxAdcTemp->getDefaultTimeBin();
121 if (mTimeBin < nTimeBins) usedTb = mTimeBin;
126 meanColumn = (float)rawHitMaxAdcTemp->
getColumn();
127 clusterSize = nToMerge;
128 clusterSizeRPhi = nToMerge;
131 float tempCharge[nToMerge], tempChargeErr[nToMerge], tempRow[nToMerge];
133 for (
int i = 0; i < nToMerge; i++) {
134 tempCharge[i] = 0.; tempChargeErr[i] = 0.; tempRow[i] = 0.;
137 float tempSumCharge = 0, tempSumChargeErrSquare = 0.;
140 for (rawHitsToMergePtr = rawHitsToMerge.begin(); rawHitsToMergePtr != rawHitsToMerge.end() && mergeIdx < nToMerge; ++rawHitsToMergePtr, ++mergeIdx) {
141 tempCharge[mergeIdx] = (*rawHitsToMergePtr)->getCharge(usedTb);
142 tempChargeErr[mergeIdx] = (*rawHitsToMergePtr)->getChargeErr(usedTb);
143 tempRow[mergeIdx] = (float)(*rawHitsToMergePtr)->getRow();
144 tempSumCharge += (*rawHitsToMergePtr)->getCharge(usedTb);
149 for (
int iRawHit = 0; iRawHit < nToMerge; iRawHit++) {
150 meanRow += tempRow[iRawHit] * tempCharge[iRawHit] / tempSumCharge;
151 tempSumChargeErrSquare += tempChargeErr[iRawHit] * tempChargeErr[iRawHit];
154 totCharge = tempSumCharge;
155 totChargeErr = sqrt(tempSumChargeErrSquare / nToMerge);
157 newCluster =
new StIstCluster((
int)ladder * 10000 + clusterLabel, ladder, sensor, meanRow, meanColumn, totCharge, totChargeErr, clusterType);
158 newCluster->setNRawHits(clusterSize);
159 newCluster->setNRawHitsRPhi(clusterSizeRPhi);
160 newCluster->setNRawHitsZ(clusterSizeZ);
161 newCluster->setMaxTimeBin(maxTb);
162 newCluster->setIdTruth(idTruth);
164 clustersVec[sensorIdx][columnIdx].push_back(newCluster);
167 rawHitsToMerge.clear();
172 std::vector<StIstCluster *>::iterator clusterIt1, clusterIt2;
174 for (
int columnIdx1 = 0; columnIdx1 < kIstNumColumnsPerSensor - 1; columnIdx1++) {
175 int columnIdx2 = columnIdx1 + 1;
177 if (clustersVec[sensorIdx][columnIdx1].size() > 0 && clustersVec[sensorIdx][columnIdx2].size() > 0) {
178 for (clusterIt1 = clustersVec[sensorIdx][columnIdx1].begin(); clusterIt1 != clustersVec[sensorIdx][columnIdx1].end() && !clustersVec[sensorIdx][columnIdx1].empty(); clusterIt1++) {
179 for (clusterIt2 = clustersVec[sensorIdx][columnIdx2].begin(); clusterIt2 != clustersVec[sensorIdx][columnIdx2].end() && !clustersVec[sensorIdx][columnIdx1].empty(); clusterIt2++) {
180 float rowDistance = (*clusterIt1)->getMeanRow() - (*clusterIt2)->getMeanRow();
182 if (TMath::Abs(rowDistance) < 0.5) {
183 maxTb = (*clusterIt1)->getMaxTimeBin();
184 idTruth = (*clusterIt1)->getIdTruth();
185 if((*clusterIt1)->getTotCharge() < (*clusterIt2)->getTotCharge()) {
186 maxTb = (*clusterIt2)->getMaxTimeBin();
187 idTruth = (*clusterIt2)->getIdTruth();
190 totCharge = (*clusterIt1)->getTotCharge() + (*clusterIt2)->getTotCharge();
191 totChargeErr = sqrt(((*clusterIt1)->getTotChargeErr() * (*clusterIt1)->getTotChargeErr() * (*clusterIt1)->getNRawHits() + (*clusterIt2)->getTotChargeErr() * (*clusterIt2)->getTotChargeErr() * (*clusterIt2)->getNRawHits()) / ((*clusterIt1)->getNRawHits() + (*clusterIt2)->getNRawHits()));
192 clusterSize = (*clusterIt1)->getNRawHits() + (*clusterIt2)->getNRawHits();
193 clusterSizeRPhi = (*clusterIt1)->getNRawHitsRPhi() + (*clusterIt2)->getNRawHitsRPhi() - 1;
194 clusterSizeZ = (*clusterIt1)->getNRawHitsZ() + (*clusterIt2)->getNRawHitsZ();
195 meanRow = (*clusterIt1)->getMeanRow() * (*clusterIt1)->getTotCharge() / totCharge + (*clusterIt2)->getMeanRow() * (*clusterIt2)->getTotCharge() / totCharge;
196 meanColumn = (*clusterIt1)->getMeanColumn() * (*clusterIt1)->getTotCharge() / totCharge + (*clusterIt2)->getMeanColumn() * (*clusterIt2)->getTotCharge() / totCharge;
198 (*clusterIt2)->setMeanRow(meanRow);
199 (*clusterIt2)->setMeanColumn(meanColumn);
200 (*clusterIt2)->setTotCharge(totCharge);
201 (*clusterIt2)->setTotChargeErr(totChargeErr);
202 (*clusterIt2)->setNRawHits(clusterSize);
203 (*clusterIt2)->setNRawHitsRPhi(clusterSizeRPhi);
204 (*clusterIt2)->setNRawHitsZ(clusterSizeZ);
205 (*clusterIt2)->setIdTruth(idTruth);
207 int distance1 = std::distance(clustersVec[sensorIdx][columnIdx1].begin(), clusterIt1);
208 clustersVec[sensorIdx][columnIdx1].erase(clusterIt1);
211 clusterIt1 = clustersVec[sensorIdx][columnIdx1].begin();
222 std::vector<StIstCluster *>::iterator clusterIt;
226 if (clustersVec[sensorIdx][columnIdx].size() <= 0)
continue;
228 for (clusterIt = clustersVec[sensorIdx][columnIdx].begin(); clusterIt != clustersVec[sensorIdx][columnIdx].end(); ++clusterIt)
229 clusters.getClusterVec().push_back(*clusterIt);
231 rawHitsVec[sensorIdx][columnIdx].clear();
232 clustersVec[sensorIdx][columnIdx].clear();
unsigned char getLadder() const
1-24
unsigned char getColumn() const
1-12
unsigned char getRow() const
1-64
const int kIstNumColumnsPerSensor
12 columns in beam direction per each sensor
unsigned short getIdTruth() const
for embedding, 0 as background
const int kIstNumSensorsPerLadder
6 sensor per one IST Ladder
unsigned char getSensor() const
1-6
const int kIstNumRowsPerSensor
64 rows in r-phi direction per each sensor