@@ -37,19 +37,26 @@ void KrBoxClusterFinder::loadGainMapFromFile(const std::string_view calDetFileNa
3737 LOGP (info, " Loaded gain map object '{}' from file '{}'" , calDetFileName, gainMapName);
3838}
3939
40- // Fill the map with all digits.
41- // You can pass a CalDet file to it so that the cluster finder can already correct for gain inhomogeneities
42- // The CalDet File should contain the relative Gain of each Pad.
43- void KrBoxClusterFinder::fillAndCorrectMap (std::vector<o2::tpc::Digit>& eventSector, const int sector)
40+ void KrBoxClusterFinder::resetADCMap ()
4441{
4542 // Reset whole map:
4643 for (int iTime = 0 ; iTime < MaxTimes; iTime++) {
4744 for (int iRow = 0 ; iRow < MaxRows; iRow++) {
48- for (int iPad = 0 ; iPad < MaxPads; iPad++) {
49- mMapOfAllDigits [iTime][iRow][iPad] = 0 ;
50- }
45+ std::fill (mMapOfAllDigits [iTime][iRow].begin (), mMapOfAllDigits [iTime][iRow].end (), 0 .);
46+ // for (int iPad = 0; iPad < MaxPads; iPad++) {
47+ // mMapOfAllDigits[iTime][iRow][iPad] = 0;
48+ // }
5149 }
5250 }
51+ }
52+
53+ // Fill the map with all digits.
54+ // You can pass a CalDet file to it so that the cluster finder can already correct for gain inhomogeneities
55+ // The CalDet File should contain the relative Gain of each Pad.
56+ void KrBoxClusterFinder::fillAndCorrectMap (std::vector<o2::tpc::Digit>& eventSector, const int sector)
57+ {
58+ mSector = sector;
59+ resetADCMap ();
5360
5461 if (eventSector.size () == 0 ) {
5562 // prevents a segementation fault if the envent contains no data
@@ -62,34 +69,49 @@ void KrBoxClusterFinder::fillAndCorrectMap(std::vector<o2::tpc::Digit>& eventSec
6269 return ;
6370 }
6471
65- const auto correctionFactorCalDet = mGainMap .get ();
66-
6772 // Fill digits map
6873 for (const auto & digit : eventSector) {
74+ const int cru = digit.getCRU ();
6975 const int time = digit.getTimeStamp ();
7076 const int row = digit.getRow ();
7177 const int pad = digit.getPad ();
78+ const float adcValue = digit.getChargeFloat ();
7279
73- float correctionFactor = 1.0 ;
80+ fillADCValue (cru, row, pad, time, adcValue);
81+ }
82+ }
7483
75- if (correctionFactorCalDet) {
76- int padNum = mMapperInstance .globalPadNumber (PadPos (row, pad));
77- correctionFactor = correctionFactorCalDet->getValue (sector, padNum);
78- }
79- // Every row starts at pad zero. But the number of pads in a row is not a constant.
80- // If we would just fill the map naively, we would put pads next to each other, which are not neighbours on the pad plane.
81- // Hence, we need to correct for this:
82- const int pads = mMapperInstance .getNumberOfPadsInRowSector (row);
83- const int corPad = pad - (pads / 2 ) + (MaxPads / 2 );
84-
85- if (correctionFactor == 0 ) {
86- LOGP (warning, " Encountered correction factor which is zero." );
87- LOGP (warning, " Digit will be set to 0!" );
88- mMapOfAllDigits [time][row][corPad] = 0 ;
89- } else {
90- mMapOfAllDigits [time][row][corPad] = digit.getChargeFloat () / correctionFactor;
91- }
84+ void KrBoxClusterFinder::fillADCValue (int cru, int rowInSector, int padInRow, int timeBin, float adcValue)
85+ {
86+ if (timeBin >= MaxTimes) {
87+ return ;
9288 }
89+
90+ // Every row starts at pad zero. But the number of pads in a row is not a constant.
91+ // If we would just fill the map naively, we would put pads next to each other, which are not neighbours on the pad plane.
92+ // Hence, we need to correct for this:
93+ mSector = cru / CRU::CRUperSector;
94+ const int pads = mMapperInstance .getNumberOfPadsInRowSector (rowInSector);
95+ const int corPad = padInRow - (pads / 2 ) + (MaxPads / 2 );
96+
97+ const auto correctionFactorCalDet = mGainMap .get ();
98+ if (!correctionFactorCalDet) {
99+ mMapOfAllDigits [timeBin][rowInSector][corPad] = adcValue;
100+ return ;
101+ }
102+
103+ int padNum = mMapperInstance .globalPadNumber (PadPos (rowInSector, padInRow));
104+ float correctionFactor = correctionFactorCalDet->getValue (mSector , padNum);
105+
106+ if (correctionFactor == 0 ) {
107+ LOGP (warning, " Encountered correction factor which is zero." );
108+ LOGP (warning, " Digit will be set to 0!" );
109+ adcValue = 0 ;
110+ } else {
111+ adcValue /= correctionFactor;
112+ }
113+
114+ mMapOfAllDigits [timeBin][rowInSector][corPad] = adcValue;
93115}
94116
95117// #################################################
@@ -114,6 +136,7 @@ void KrBoxClusterFinder::updateTempClusterFinal()
114136 // Since every padrow is shifted such that neighbouring pads are indeed neighbours, we have to shift once back:
115137 mTempCluster .meanPad = mTempCluster .meanPad + (corPadsMean / 2.0 ) - (MaxPads / 2.0 );
116138 mTempCluster .maxChargePad = mTempCluster .maxChargePad + (corPadsMaxCharge / 2.0 ) - (MaxPads / 2.0 );
139+ mTempCluster .sector = (decltype (mTempCluster .sector ))mSector ;
117140}
118141
119142// Function to update the temporal cluster.
@@ -145,7 +168,7 @@ void KrBoxClusterFinder::updateTempCluster(float tempCharge, int tempPad, int te
145168
146169// This function finds and evaluates all clusters in a 3D mMapOfAllDigits generated by the
147170// mMapOfAllDigitsCreator function, this function also updates the cluster tree
148- std::vector<std::tuple<int , int , int >> KrBoxClusterFinder::findLocalMaxima ()
171+ std::vector<std::tuple<int , int , int >> KrBoxClusterFinder::findLocalMaxima (bool directFilling )
149172{
150173 std::vector<std::tuple<int , int , int >> localMaximaCoords;
151174 // loop over whole mMapOfAllDigits the find clusters
@@ -222,7 +245,11 @@ std::vector<std::tuple<int, int, int>> KrBoxClusterFinder::findLocalMaxima()
222245 if (!thisIsMax) {
223246 continue ;
224247 } else {
225- localMaximaCoords.emplace_back (std::make_tuple (iPad, iRow, iTime));
248+ if (directFilling) {
249+ buildCluster (iPad, iRow, iTime, directFilling);
250+ } else {
251+ localMaximaCoords.emplace_back (std::make_tuple (iPad, iRow, iTime));
252+ }
226253 }
227254 }
228255 }
@@ -247,9 +274,8 @@ std::vector<std::tuple<int, int, int>> KrBoxClusterFinder::findLocalMaxima()
247274// for loop over whole cluster, to determine if a charge should be added
248275// conditions are extrapolation of the 5x5 cluster case to arbitrary
249276// cluster sizes in 3 dimensions
250- KrCluster KrBoxClusterFinder::buildCluster (int clusterCenterPad, int clusterCenterRow, int clusterCenterTime)
277+ KrCluster KrBoxClusterFinder::buildCluster (int clusterCenterPad, int clusterCenterRow, int clusterCenterTime, bool directFilling )
251278{
252- mTempCluster = KrCluster ();
253279 mTempCluster .reset ();
254280
255281 setMaxClusterSize (clusterCenterRow);
@@ -346,6 +372,11 @@ KrCluster KrBoxClusterFinder::buildCluster(int clusterCenterPad, int clusterCent
346372 // At the end, out mTempCluster should contain all digits that were assigned to the cluster.
347373 // So before returning it, we update it one last time to calculate the correct means and sigmas.
348374 updateTempClusterFinal ();
375+
376+ if (directFilling) {
377+ mClusters .emplace_back (mTempCluster );
378+ }
379+
349380 return mTempCluster ;
350381}
351382
@@ -365,4 +396,4 @@ void KrBoxClusterFinder::setMaxClusterSize(int row)
365396 mMaxClusterSizePad = mMaxClusterSizePadOROC3 ;
366397 mMaxClusterSizeRow = mMaxClusterSizeRowOROC3 ;
367398 }
368- }
399+ }
0 commit comments