4 #include "StFstScanRadiusClusterAlgo.h"
5 #include "StFstUtil/StFstCollection.h"
6 #include "StFstUtil/StFstRawHitCollection.h"
7 #include "StEvent/StFstRawHit.h"
8 #include "StFstUtil/StFstClusterCollection.h"
9 #include "StFstUtil/StFstCluster.h"
10 #include "StEvent/StFstConsts.h"
24 Int_t clusterType = kFstScanRadiusClusterAlgo;
25 Int_t maxTb = -1, usedTb = -1;
26 Int_t disk = 0, wedge = 0, sensor = -1, apv = -1;
27 Float_t meanRStrip = -1., maxRStrip = -1, meanPhiStrip = -1;
28 Float_t totCharge = 0., totChargeErr = 0.;
29 Int_t clusterSize = 0, clusterSizeR = 0, clusterSizePhi = 0;
30 unsigned short idTruth = 0;
33 Int_t nTimeBins = fstCollection.getNumTimeBins();
36 rawHitsOriginal.sortByGeoId();
39 std::vector<StFstRawHit *> rawHitsVec[kFstNumSensorsPerWedge][kFstNumPhiSegPerSensor];
40 std::vector<StFstCluster *> clustersVec[kFstNumSensorsPerWedge][kFstNumPhiSegPerSensor];
41 std::vector<StFstRawHit *> rawHitsToMerge;
43 for (
int sensorIdx = 0; sensorIdx < kFstNumSensorsPerWedge; sensorIdx++) {
44 for (
int phiIdx = 0; phiIdx < kFstNumPhiSegPerSensor; phiIdx++) {
45 rawHitsVec[sensorIdx][phiIdx].reserve(kFstNumRStripsPerSensor);
46 clustersVec[sensorIdx][phiIdx].reserve(kFstNumRStripsPerSensor);
50 rawHitsToMerge.reserve(kFstNumRStripsPerSensor);
52 for (std::vector< StFstRawHit * >::iterator rawHitPtr = rawHitsOriginal.getRawHitVec().begin(); rawHitPtr != rawHitsOriginal.getRawHitVec().end(); ++rawHitPtr) {
53 int sensorIndex = (int)(*rawHitPtr)->getSensor();
54 int phiIndex = (int)(*rawHitPtr)->getPhiStrip();
55 rawHitsVec[sensorIndex][phiIndex].push_back(
new StFstRawHit( *(*rawHitPtr)) );
61 for (
int sensorIdx = 0; sensorIdx < kFstNumSensorsPerWedge; sensorIdx++)
64 for (
int phiIdx = 0; phiIdx < kFstNumPhiSegPerSensor; phiIdx++)
66 while ( !rawHitsVec[sensorIdx][phiIdx].empty() )
68 rawHitTemp = rawHitsVec[sensorIdx][phiIdx].back();
69 delete rawHitsVec[sensorIdx][phiIdx].back();
70 rawHitsVec[sensorIdx][phiIdx].pop_back();
71 rawHitsToMerge.push_back(rawHitTemp);
75 std::vector<StFstRawHit *>::iterator rawHitsToMergePtr = rawHitsToMerge.begin();
76 rawHitMaxAdcTemp = *rawHitsToMergePtr;
79 while (rawHitsToMergePtr != rawHitsToMerge.end() && !rawHitsVec[sensorIdx][phiIdx].empty()) {
80 rawHitTemp = rawHitsVec[sensorIdx][phiIdx].back();
81 delete rawHitsVec[sensorIdx][phiIdx].back();
82 rawHitsVec[sensorIdx][phiIdx].pop_back();
85 rawHitsToMerge.push_back(rawHitTemp);
87 if ( rawHitTemp->getCharge(rawHitTemp->getMaxTimeBin()) > (*rawHitsToMergePtr)->getCharge((*rawHitsToMergePtr)->getMaxTimeBin()) )
88 rawHitMaxAdcTemp = rawHitTemp;
94 maxTb = rawHitMaxAdcTemp->getMaxTimeBin();
97 if (maxTb < 0 || maxTb >= nTimeBins) maxTb = rawHitMaxAdcTemp->getDefaultTimeBin();
99 if (mTimeBin < nTimeBins) usedTb = mTimeBin;
102 disk = rawHitMaxAdcTemp->
getDisk();
103 wedge = rawHitMaxAdcTemp->
getWedge();
105 apv = rawHitMaxAdcTemp->
getApv();
106 meanPhiStrip = (float)rawHitMaxAdcTemp->
getPhiStrip();
107 clusterSize = nToMerge;
108 clusterSizeR = nToMerge;
111 float tempChargeErr[nToMerge], tempRStrip[nToMerge];
113 for (
int i = 0; i < nToMerge; i++) {
114 tempChargeErr[i] = 0.; tempRStrip[i] = 0.;
117 float tempSumCharge = 0, tempSumChargeErrSquare = 0.;
122 for (rawHitsToMergePtr = rawHitsToMerge.begin(); rawHitsToMergePtr != rawHitsToMerge.end() && mergeIdx < nToMerge; ++rawHitsToMergePtr, ++mergeIdx) {
123 tempChargeErr[mergeIdx] = (*rawHitsToMergePtr)->getChargeErr(usedTb);
124 tempRStrip[mergeIdx] = (float)(*rawHitsToMergePtr)->getRStrip();
125 tempSumCharge += (*rawHitsToMergePtr)->getCharge(usedTb);
126 if ( (*rawHitsToMergePtr)->getSeedhitflag() == 1 ) ++nToSeedhit;
132 for (
int iRawHit = 0; iRawHit < nToMerge; iRawHit++) {
133 if(tempRStrip[iRawHit]>maxRStrip)
134 maxRStrip = tempRStrip[iRawHit];
135 meanRStrip = maxRStrip;
136 tempSumChargeErrSquare += tempChargeErr[iRawHit] * tempChargeErr[iRawHit];
139 totCharge = tempSumCharge;
140 totChargeErr = sqrt(tempSumChargeErrSquare / nToMerge);
143 newCluster =
new StFstCluster((
int)wedge * 10000 + clusterLabel, disk, wedge, sensor, apv, meanRStrip, meanPhiStrip, totCharge, totChargeErr, clusterType);
144 newCluster->setNRawHits(clusterSize);
145 newCluster->setNRawHitsR(clusterSizeR);
146 newCluster->setNRawHitsPhi(clusterSizePhi);
147 newCluster->setMaxTimeBin(maxTb);
148 newCluster->setIdTruth(idTruth);
150 clustersVec[sensorIdx][phiIdx].push_back(newCluster);
154 rawHitsToMerge.clear();
159 std::vector<StFstCluster *>::iterator clusterIt1, clusterIt2;
160 for (
int phiIdx1 = 0; phiIdx1 < kFstNumPhiSegPerSensor - 1; phiIdx1++) {
161 int phiIdx2 = phiIdx1 + 1;
163 if (clustersVec[sensorIdx][phiIdx1].size() > 0 && clustersVec[sensorIdx][phiIdx2].size() > 0) {
164 for (clusterIt1 = clustersVec[sensorIdx][phiIdx1].begin(); clusterIt1 != clustersVec[sensorIdx][phiIdx1].end() && !clustersVec[sensorIdx][phiIdx1].empty(); clusterIt1++) {
165 for (clusterIt2 = clustersVec[sensorIdx][phiIdx2].begin(); clusterIt2 != clustersVec[sensorIdx][phiIdx2].end() && !clustersVec[sensorIdx][phiIdx1].empty(); clusterIt2++) {
166 float rstripDfstance = (*clusterIt1)->getMeanRStrip() - (*clusterIt2)->getMeanRStrip();
168 if (TMath::Abs(rstripDfstance) < 3.5) {
169 maxTb = (*clusterIt1)->getMaxTimeBin();
170 idTruth = (*clusterIt1)->getIdTruth();
171 apv = (*clusterIt1)->getApv();
172 if((*clusterIt1)->getTotCharge() < (*clusterIt2)->getTotCharge()) {
173 maxTb = (*clusterIt2)->getMaxTimeBin();
174 idTruth = (*clusterIt2)->getIdTruth();
175 apv = (*clusterIt2)->getApv();
178 totCharge = (*clusterIt1)->getTotCharge() + (*clusterIt2)->getTotCharge();
179 totChargeErr = sqrt(((*clusterIt1)->getTotChargeErr() * (*clusterIt1)->getTotChargeErr() * (*clusterIt1)->getNRawHits() + (*clusterIt2)->getTotChargeErr() * (*clusterIt2)->getTotChargeErr() * (*clusterIt2)->getNRawHits()) / ((*clusterIt1)->getNRawHits() + (*clusterIt2)->getNRawHits()));
180 clusterSize = (*clusterIt1)->getNRawHits() + (*clusterIt2)->getNRawHits();
181 int maxClusterR1 = (*clusterIt1)->getMeanRStrip();
182 int minClusterR1 = (*clusterIt1)->getMeanRStrip() - (*clusterIt1)->getNRawHitsR() + 1;
183 int maxClusterR2 = (*clusterIt2)->getMeanRStrip();
184 int minClusterR2 = (*clusterIt2)->getMeanRStrip() - (*clusterIt2)->getNRawHitsR() + 1;
185 int maxClusterR = maxClusterR1 > maxClusterR2 ? maxClusterR1 : maxClusterR2;
186 int minClusterR = minClusterR1 < minClusterR2 ? minClusterR1 : minClusterR2;
187 clusterSizeR = maxClusterR - minClusterR + 1;
188 clusterSizePhi = (*clusterIt1)->getNRawHitsPhi() + (*clusterIt2)->getNRawHitsPhi();
189 meanRStrip = (*clusterIt1)->getMeanRStrip();
190 if ((*clusterIt2)->getMeanRStrip() > (*clusterIt1)->getMeanRStrip())
191 meanRStrip = (*clusterIt2)->getMeanRStrip();
192 meanPhiStrip = (*clusterIt1)->getMeanPhiStrip() * (*clusterIt1)->getTotCharge() / totCharge + (*clusterIt2)->getMeanPhiStrip() * (*clusterIt2)->getTotCharge() / totCharge;
194 (*clusterIt2)->setMeanRStrip(meanRStrip);
195 (*clusterIt2)->setMeanPhiStrip(meanPhiStrip);
196 (*clusterIt2)->setTotCharge(totCharge);
197 (*clusterIt2)->setTotChargeErr(totChargeErr);
198 (*clusterIt2)->setNRawHits(clusterSize);
199 (*clusterIt2)->setNRawHitsR(clusterSizeR);
200 (*clusterIt2)->setNRawHitsPhi(clusterSizePhi);
201 (*clusterIt2)->setIdTruth(idTruth);
202 (*clusterIt2)->setApv(apv);
204 int distance1 = std::distance(clustersVec[sensorIdx][phiIdx1].begin(), clusterIt1);
206 clustersVec[sensorIdx][phiIdx1].erase(clusterIt1);
209 clusterIt1 = clustersVec[sensorIdx][phiIdx1].begin();
220 std::vector<StFstCluster *>::iterator clusterIt;
222 for (
int sensorIdx = 0; sensorIdx < kFstNumSensorsPerWedge; sensorIdx++) {
223 for (
int phiIdx = 0; phiIdx < kFstNumPhiSegPerSensor; phiIdx++) {
224 if (clustersVec[sensorIdx][phiIdx].size() <= 0)
continue;
226 for (clusterIt = clustersVec[sensorIdx][phiIdx].begin(); clusterIt != clustersVec[sensorIdx][phiIdx].end(); ++clusterIt)
227 clusters.getClusterVec().push_back(*clusterIt);
229 rawHitsVec[sensorIdx][phiIdx].clear();
230 clustersVec[sensorIdx][phiIdx].clear();
unsigned char getSensor() const
0-2
unsigned char getDisk() const
1-3
unsigned char getPhiStrip() const
0-127
unsigned char getApv() const
0-15
unsigned short getIdTruth() const
for embedding, 0 as background
unsigned char getWedge() const
1-36