34 auto numberOfCoordinates = coordinates.size();
35 if (numberOfCoordinates != 4) {
36 std::cerr <<
"Invalid size of the coordinates vector!" << std::endl;
41 if (hDet->GetBinContent(coordinates[0], coordinates[1]) > upperLimit * averageGain) {
43 if (sizeOfHotArea > 0 && sizeOfHotArea < areaContainedWithin) {
46 }
else if (hDet->GetBinContent(coordinates[2], coordinates[3]) > upperLimit * averageGain) {
48 if (sizeOfHotArea > 0 && sizeOfHotArea < areaContainedWithin) {
51 }
else if (hDet->GetBinContent(coordinates[0], coordinates[1]) == 0 && hDet->GetBinContent(coordinates[2], coordinates[3]) != 0) {
53 if (sizeOfHotArea > 0 && sizeOfHotArea < areaContainedWithin) {
61 if (hDet->GetBinContent(coordinates[0], coordinates[1]) == 0 || hDet->GetBinContent(coordinates[2], coordinates[3]) == 0) {
65 float xCenter = hDet->GetNbinsX() / 2.;
66 float yCenter = hDet->GetNbinsY() / 2.;
68 std::vector<float> vCenter, vPad1, vPad2;
69 vCenter.push_back(hDet->GetNbinsX() / 2.);
70 vCenter.push_back(hDet->GetNbinsY() / 2.);
72 vPad1.push_back(hDet->GetXaxis()->GetBinCenter(coordinates[0]));
73 vPad1.push_back(hDet->GetYaxis()->GetBinCenter(coordinates[1]));
75 vPad2.push_back(hDet->GetXaxis()->GetBinCenter(coordinates[2]));
76 vPad2.push_back(hDet->GetYaxis()->GetBinCenter(coordinates[3]));
81 if ((dist1 < dist2) && ((hDet->GetBinContent(coordinates[2], coordinates[3]) - hDet->GetBinContent(coordinates[0], coordinates[1])) > allowedDifference)) {
85 if ((dist1 > dist2) && ((hDet->GetBinContent(coordinates[0], coordinates[1]) - hDet->GetBinContent(coordinates[2], coordinates[3])) > allowedDifference)) {
92 std::vector<int> coordinates = {-1, -1, -1, -1};
94 int colMax = hDet->GetNbinsX();
95 int rowMax = hDet->GetNbinsY();
98 if (!(shiftcolumn == 1 && shiftrow == 0) && !(shiftcolumn == 0 && shiftrow == 1)) {
103 if ((column >= colMax) || (
row >= rowMax)) {
107 if ((column == colMax && shiftcolumn == 1) || (
row == rowMax && shiftrow == 1)) {
111 float gain1 = hDet->GetBinContent(column,
row);
112 float gain2 = hDet->GetBinContent(column + shiftcolumn,
row + shiftrow);
114 if ((gain1 == 0 && gain2 > 0) || (gain1 > 0 && gain2 == 0) || (abs(gain1 - gain2) > allowedDifference)) {
115 coordinates[0] = column;
116 coordinates[1] =
row;
117 coordinates[2] = column + shiftcolumn;
118 coordinates[3] =
row + shiftrow;
132 for (
int irow = 0; irow < hDet->GetNbinsY(); irow++) {
133 for (
int icol = 0; icol < hDet->GetNbinsX(); icol++) {
134 float currentGain = TMath::Abs(hDet->GetBinContent(icol + 1, irow + 1));
135 if (currentGain == 0) {
138 average += currentGain;
142 average /= nBinsUsed;
151 auto numberOfCoordinates =
pad1.size();
152 if (numberOfCoordinates !=
pad2.size()) {
153 std::cerr <<
"Something fishy with the pad coordinates!" << std::endl;
157 for (
int i = 0;
i < numberOfCoordinates;
i++) {
169 if (sNewName ==
"") {
170 sNewName = hDet->GetName();
171 sNewName +=
"_normalized";
173 TH2F* hDetNormalized = (TH2F*)hDet->Clone(sNewName.Data());
177 for (
int irow = 0; irow < hDet->GetNbinsY(); irow++) {
178 for (
int icol = 0; icol < hDet->GetNbinsX(); icol++) {
179 float currentGain = hDet->GetBinContent(hDet->GetXaxis()->FindBin(icol), hDet->GetYaxis()->FindBin(irow));
180 float newGain = currentGain / average;
181 hDetNormalized->SetBinContent(hDetNormalized->GetXaxis()->FindBin(icol), hDetNormalized->GetYaxis()->FindBin(irow), newGain);
185 return hDetNormalized;
191 float currentGain = hDet->GetBinContent(column + 1,
row + 1);
193 if (currentGain != 0) {
197 hDet->SetBinContent(column + 1,
row + 1, factor * newGain);
205 if (sNewName ==
"") {
206 sNewName = hDet->GetName();
207 sNewName +=
"_filled";
209 TH2F* hDetFilled = (TH2F*)hDet->Clone(sNewName);
211 TH2F* hDetTemp = (TH2F*)hDet->Clone(
"hDetTemp");
213 std::vector<std::vector<int>> emptyBinsColRow =
findEmpty(hDetTemp);
216 auto nEmptyBins = emptyBinsColRow.size();
218 int firstFilledX = hDetFilled->FindFirstBinAbove();
219 int lastFilledX = hDetFilled->FindLastBinAbove();
220 int nBinsX = hDetFilled->GetNbinsX();
222 int firstFilledY = hDetFilled->FindFirstBinAbove(0, 2);
223 int lastFilledY = hDetFilled->FindLastBinAbove(0, 2);
224 int nBinsY = hDetFilled->GetNbinsY();
226 while (nEmptyBins != 0) {
228 for (
int ibin = 0; ibin < nEmptyBins; ibin++) {
230 int flippedCoordinateX = nBinsX - hDetFilled->GetXaxis()->FindBin(emptyBinsColRow[ibin][0]) + 1;
231 int flippedCoordinateY = nBinsY - hDetFilled->GetYaxis()->FindBin(emptyBinsColRow[ibin][1]) + 1;
232 float mirroredGain = hDetFilled->GetBinContent(flippedCoordinateX, hDetFilled->GetYaxis()->FindBin(emptyBinsColRow[ibin][1]));
234 if (mirroredGain == 0) {
235 mirroredGain = hDetFilled->GetBinContent(hDetFilled->GetXaxis()->FindBin(emptyBinsColRow[ibin][0]), flippedCoordinateY);
238 if (mirroredGain == 0) {
243 if (mirroredGain < 0) {
246 fillInTheGap(hDetFilled, emptyBinsColRow[ibin][0], emptyBinsColRow[ibin][1], factor * mirroredGain);
249 auto nEmptyPrevious = emptyBinsColRow.size();
250 emptyBinsColRow.clear();
251 hDetTemp = (TH2F*)hDetFilled->Clone(
"hDetTemp");
253 nEmptyBins = emptyBinsColRow.size();
254 if (nEmptyPrevious == nEmptyBins) {
266 std::vector<std::vector<int>> emptyBins;
268 for (
int irow = 0; irow < hDetectorMap->GetNbinsY(); irow++) {
269 for (
int icolumn = 0; icolumn < hDetectorMap->GetNbinsX(); icolumn++) {
270 float gain = hDetectorMap->GetBinContent(icolumn + 1, irow + 1);
272 std::vector<int> coordinates;
273 coordinates.push_back(icolumn);
274 coordinates.push_back(irow);
275 emptyBins.push_back(coordinates);
285 std::vector<std::vector<int>> suspiciousBinPairs;
289 int xFirst = hDet->FindFirstBinAbove();
290 int xLast = hDet->FindLastBinAbove();
292 int yFirst = hDet->FindFirstBinAbove(0, 2);
293 int yLast = hDet->FindLastBinAbove(0, 2);
297 for (
int irow = 0; irow < hDet->GetNbinsY(); irow++) {
299 int thisRow = hDet->GetXaxis()->FindBin(irow);
302 for (
int icolumn = 0; icolumn < hDet->GetNbinsX(); icolumn++) {
304 int thisColumn = hDet->GetXaxis()->FindBin(icolumn);
307 std::vector<int> pair =
compareGain(hDet, thisColumn, thisRow, 1, 0, allowedDifference);
308 if (!(std::any_of(pair.begin(), pair.end(), [](
int i) { return i == -1; }))) {
309 suspiciousBinPairs.push_back(pair);
313 pair =
compareGain(hDet, thisColumn, thisRow, 0, 1, allowedDifference);
314 if (!(std::any_of(pair.begin(), pair.end(), [](
int i) { return i == -1; }))) {
315 suspiciousBinPairs.push_back(pair);
322 return suspiciousBinPairs;
329 std::vector<float> gainNeighbor;
332 for (
int irow = 0; irow < nbuffer; irow++) {
335 if (rowNeighbor < 0 || rowNeighbor >= hDet->GetNbinsY()) {
338 for (
int icol = 0; icol < nbuffer; icol++) {
339 if (icol == 1 && irow == 1) {
342 int colNeighbor = (column -
offset) + icol;
343 if (colNeighbor < 0 || colNeighbor >= hDet->GetNbinsX()) {
346 float tempGain = TMath::Abs(hDet->GetBinContent(hDet->GetXaxis()->FindBin(colNeighbor), hDet->GetYaxis()->FindBin(rowNeighbor)));
350 gainNeighbor.push_back(tempGain);
353 auto numberOfNeighbors = gainNeighbor.size();
354 if (numberOfNeighbors < 1) {
358 average = std::accumulate(gainNeighbor.begin(), gainNeighbor.end(),
decltype(gainNeighbor)::value_type(0.0)) / numberOfNeighbors;
367 if (sDetName ==
"") {
368 sDetName = Form(
"hDet%i", nDet);
370 int nTrdRows = NROWC1;
371 int detInSupermodule = nDet % 30;
372 if (detInSupermodule >= 12 && detInSupermodule <= 17) {
376 TH2F* hDetector =
new TH2F(sDetName.Data(), sDetName.Data(), NCOLUMN, 0, NCOLUMN, nTrdRows, 0, nTrdRows);
380 int nentries =
tree->GetEntries();
381 for (
int ientry = 0; ientry < nentries; ientry++) {
382 tree->GetEntry(ientry);
383 if ((
int)mDet != nDet) {
386 if (mChi < 0 || mAmp <= 0 || mSgm <= 0 || mSgm > 1000) {
392 if (mAdc < mingain || mAdc > maxgain) {
395 hDetector->SetBinContent(hDetector->GetXaxis()->FindBin(mCol), hDetector->GetYaxis()->FindBin(mRow), mAdc);
402 bool isIsolated = kFALSE;
404 int nSurroundingNotHot = 0;
405 int nMaxHot = TMath::Power(matrixSize + 2, 2) - TMath::Power(matrixSize, 2);
406 float averageAround = 0.;
410 if ((column == 1 || column == hDet->GetNbinsX()) &&
row > 1 && row < hDet->GetNbinsY()) {
411 nHotOffset = matrixSize + 2;
412 }
else if ((
row == 1 ||
row == hDet->GetNbinsY()) && column > 1 && column < hDet->GetNbinsX()) {
413 nHotOffset = matrixSize + 2;
414 }
else if ((column == 1 || column == hDet->GetNbinsX()) && (
row == 1 ||
row == hDet->GetNbinsY())) {
415 nHotOffset = nMaxHot / 2 + 1;
418 for (
int i = 0;
i < matrixSize + 2;
i++) {
420 for (
int j = 0;
j < matrixSize + 2;
j++) {
422 if ((-1 < icol) && (icol < matrixSize) && (-1 < jrow) && (jrow < matrixSize)) {
425 float temp = TMath::Abs(hDet->GetBinContent(column + icol,
row + jrow));
428 averageAround += temp;
429 }
else if (temp == 0) {
430 nSurroundingNotHot++;
436 averageAround /= nUsedBins;
438 if (averageAround < 2 * averageGain && nSurroundingNotHot <= nHotOffset) {
440 }
else if (nSurroundingNotHot == nMaxHot) {
450 bool isContained = kFALSE;
451 while (!isContained) {
465 if (!hDet || hDet->GetEntries() != 0) {
466 std::cout <<
"Histogram does not exist or is not empty!";
469 for (
int icol = 0; icol < hDet->GetNbinsX(); icol++) {
470 for (
int irow = 0; irow < hDet->GetNbinsY(); irow++) {
471 hDet->SetBinContent(icol + 1, irow + 1, valueToSet);
478 if (!hDet || hDet->GetEntries() == 0) {
481 for (
int icol = 0; icol < nsize; icol++) {
482 for (
int irow = 0; irow < hDet->GetNbinsY(); irow++) {
483 hDet->SetBinContent(icol + 1, irow + 1, 0);
484 hDet->SetBinContent(hDet->GetNbinsX() - icol, irow, 0);
491 if (!hDet || hDet->GetEntries() == 0) {
496 for (
int irow = 0; irow < hDet->GetNbinsY(); irow++) {
497 for (
int icol = 0; icol < hDet->GetNbinsX(); icol++) {
498 float value = hDet->GetBinContent(icol + 1, irow + 1);
499 if (
value > upperLimit * average ||
value < lowerLimit * average) {
500 hDet->SetBinContent(icol + 1, irow + 1, 0);
508 if (!hDet || hDet->GetEntries() == 0) {
509 std::cerr <<
"invalid histogram!" << std::endl;
514 hDet->SetBinContent(xcloser, ycloser, newGain);
519 for (
int jrow = 0; jrow < nsize; jrow++) {
520 for (
int icol = 0; icol < nsize; icol++) {
521 hDet->SetBinContent(column + icol,
row + jrow, 0);
528 tree->SetBranchAddress(
"det", &mDet);
529 tree->SetBranchAddress(
"col", &mCol);
530 tree->SetBranchAddress(
"row", &mRow);
531 tree->SetBranchAddress(
"mean", &mAdc);
532 tree->SetBranchAddress(
"chi2", &mChi);
533 tree->SetBranchAddress(
"sigma", &mSgm);
534 tree->SetBranchAddress(
"amplitude", &mAmp);
539 std::vector<std::vector<int>> SuspiciousBinPairs =
findInhomogeneities(hDet, allowedDifference);
540 auto numberOfPairs = SuspiciousBinPairs.size();
541 if (numberOfPairs == 0) {
545 for (
int i = 0;
i < numberOfPairs;
i++) {
546 std::vector<int> susPair = SuspiciousBinPairs[
i];
554 if (!hDet || hDet->GetEntries() == 0) {
559 sName = hDet->GetName();
560 sName +=
"_transformed";
563 int nCols = hDet->GetNbinsX();
564 int nRows = hDet->GetNbinsY();
566 TH2F* hDetCopy =
new TH2F(sName.Data(), sName.Data(), nCols, 0, nCols, nRows, 0, nRows);
568 for (
int icol = 0; icol < nCols; icol++) {
569 for (
int irow = 0; irow < nRows; irow++) {
570 hDetCopy->SetBinContent(icol + 1, irow + 1, TMath::Abs(hDet->GetBinContent(icol + 1, irow + 1)));
TH2F * fillTheMap(TH2F *hDet, TString sNewName="", int nbuffer=3)
void removeExtremePads(TH2F *hDet, float upperLimit=2., float lowerLimit=0.5)
void setTreeBranches(TTree *tree)
void removeEdges(TH2F *hDet, int nsize=2)
TH2F * transformMapIntoAbsoluteValues(TH2F *hDet, TString sName="")
void replaceIsolatedHotPads(TH2F *hDet, int column, int row, int nsize)
void replacePadCloserToCenter(TH2F *hDet, int column, int row)
bool isHotAreaIsolated(TH2F *hDet, int column, int row, int matrixSize=1)
std::vector< std::vector< int > > findInhomogeneities(TH2F *hDet, float allowedDifference)
int isolatedHotPadsContainmentSize(TH2F *hDet, int column, int row)
void fillInTheGap(TH2F *hDet, int column, int row, float newGain)
std::vector< int > compareGain(TH2F *hDet, int column, int row, int shiftcolumn, int shiftrow, float allowedDifference)
void populateEmptyNormalizedMap(TH2F *hDet, float valueToSet=-1)
float computeDetectorAverage(TH2F *hDet)
void checkIfIsolatedHotPadCandidate(TH2F *hDet, std::vector< int > coordinates, float upperLimit=1.5, int areaContainedWithin=4)
std::vector< std::vector< int > > findEmpty(TH2F *hDetectorMap)
TH2F * createNormalizedMap(TH2F *hDet, TString sNewName="")
float getAverageFromNeighbors(TH2F *hDet, int column, int row, int nbuffer=3)
void checkIfSmallerCloserToCenter(TH2F *hDet, std::vector< int > coordinates, float allowedDifference)
TH2F * getDetectorMap(TTree *tree, int nDet, float mingain=0, float maxgain=10 '000, TString sDetName="")
void smoothenTheDetector(TH2F *hDet, float allowedDifference=1000)
float computeDistance(std::vector< float > pad1, std::vector< float > pad2)
GLsizei GLsizei GLfloat distance
GLsizei const GLfloat * value
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))