82 std::map<int, TOPDigit*> hitInfoMap;
83 for (
auto& digit : digits) {
85 if (digit.getHitQuality() == TOPDigit::c_Junk)
continue;
87 const auto* rawDigit = digit.getRelated<
TOPRawDigit>();
88 if (!rawDigit)
continue;
91 if (waveform and
isCrossTalk(waveform->getWaveform(), TMath::FloorNint(digit.getRawTime()), digit.getPulseHeight()))
92 digit.setHitQuality(TOPDigit::c_CrossTalk);
95 int slotId = digit.getModuleID();
96 unsigned int channelId = digit.getChannel();
97 double rawTime = digit.getRawTime();
98 for (
auto& digit2 : digits) {
99 if (digit2.getChannel() != channelId || digit2.getModuleID() != slotId)
continue;
100 if (digit2.getHitQuality() == TOPDigit::c_CrossTalk
102 digit.setHitQuality(TOPDigit::c_CrossTalk);
106 if (digit.getHitQuality() == TOPDigit::c_CrossTalk)
continue;
108 int globalPixelId = (digit.getModuleID() - 1) * 512 + digit.
getPixelID() - 1;
109 while (hitInfoMap.count(globalPixelId) > 0)globalPixelId += 10000;
110 hitInfoMap[globalPixelId] = &digit;
113 for (
auto& digit : digits) {
115 if (digit.getHitQuality() == TOPDigit::c_Junk
116 || digit.getHitQuality() == TOPDigit::c_CrossTalk)
continue;
118 short pixelId = digit.getPixelID();
119 short slotId = digit.getModuleID();
120 short pmtId = digit.getPMTNumber();
121 double hitTime = digit.getTime();
122 double charge = digit.getIntegral();
123 bool isPrimaryChargeShare =
true;
124 std::vector<TOPDigit*> vSecondaryCandidates;
126 const int adjacentPixelIds[] = { pixelId - 1 - c_NPixelsPerRow, pixelId - c_NPixelsPerRow, pixelId + 1 - c_NPixelsPerRow, pixelId + 1,
127 pixelId + 1 + c_NPixelsPerRow, pixelId + c_NPixelsPerRow, pixelId - 1 + c_NPixelsPerRow, pixelId - 1
130 for (
const auto& adjacentPixelId : adjacentPixelIds) {
131 if (adjacentPixelId > 0 && adjacentPixelId <= 512) {
132 int globalPixelId = (slotId - 1) * 512 + adjacentPixelId - 1;
133 while (hitInfoMap.count(globalPixelId) > 0) {
135 if (pmtId != hitInfoMap[globalPixelId]->getPMTNumber()
136 or TMath::Abs(hitTime - hitInfoMap[globalPixelId]->getTime()) >
m_timeCut) {
137 globalPixelId += 10000;
continue;
140 float adjacentIntegral = hitInfoMap[globalPixelId]->getIntegral();
142 if (charge > adjacentIntegral
143 or (charge == adjacentIntegral && pixelId > hitInfoMap[globalPixelId]->getPixelID())) {
144 vSecondaryCandidates.push_back(hitInfoMap[globalPixelId]);
145 hitInfoMap[globalPixelId]->setSecondaryChargeShare();
147 isPrimaryChargeShare =
false;
150 globalPixelId += 10000;
152 if (!isPrimaryChargeShare)
break;
156 if (isPrimaryChargeShare && vSecondaryCandidates.size() > 0) {
157 digit.setPrimaryChargeShare();
160 for (
auto& vSecondaryCandidate : vSecondaryCandidates) {
161 digit.setPulseHeight(digit.getPulseHeight() + vSecondaryCandidate->getPulseHeight());
162 vSecondaryCandidate->setPulseHeight(0.0);
164 digit.setIntegral(digit.getIntegral() + vSecondaryCandidate->getIntegral());
165 vSecondaryCandidate->setIntegral(0.0);
176 int nWfmSampling = wfm.size();
177 for (
int iWin = 0 ; iWin < 16 ; iWin++) {
181 if (jRawTime > 0 && jRawTime < nWfmSampling - 1 && wfm[jRawTime] < height / 2. && wfm[jRawTime + 1] > height / 2.) {
182 bool preValleyExist =
false;
183 short preValleyDepth = -1;
186 for (
int iSample = jRawTime ; iSample - 1 > 0 ; iSample--) {
188 else if (wfm[iSample] - wfm[iSample - 1] >= 0)
continue;
190 preValleyDepth = (-1) * wfm[iSample];
194 preValleyExist =
true;
200 if (!preValleyExist)
return false;
204 short valley_adc = 9999;
205 for (
int jSample = jRawTime ; jSample < nWfmSampling - 1 ; jSample++) {
207 if ((wfm[jSample + 1] - wfm[jSample])*sign > 0)
continue;
209 if (sign < 0 && valley_adc > height + 1)
210 valley_adc = wfm[jSample];
211 if (sign > 0 && valley_adc < height) {
218 sign = (sign > 0 ? -1 : 1);