Skip to content

Commit 2b7d194

Browse files
noferinishahor02
authored andcommitted
tuning of TOF cal fits
1 parent 52ef5fe commit 2b7d194

2 files changed

Lines changed: 42 additions & 5 deletions

File tree

Detectors/TOF/calibration/include/TOFCalibration/TOFChannelCalibrator.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class TOFChannelData
120120

121121
private:
122122
float mRange = o2::tof::Geo::BC_TIME_INPS * 0.5;
123-
int mNBins = 1000;
123+
int mNBins = 2000;
124124
float mV2Bin;
125125
std::array<boostHisto, 18> mHisto;
126126
std::vector<int> mEntries; // vector containing number of entries per channel
@@ -191,7 +191,11 @@ class TOFChannelCalibrator final : public o2::calibration::TimeSlotCalibration<T
191191
}
192192
#ifdef DEBUGGING
193193
mFitCal = new TProfile("fitCal", ";channel;offset (ps)", 157248, 0, 157248);
194-
mChannelDist = new TH2F("channelDist", ";channel; t - t_{exp}^{#pi} (ps)", 157248, 0, 157248, 1000, -100000, 100000);
194+
int nbins = mNBins;
195+
if (nbins > 2000) { // not more than 2000 otherwise it will cause overflow in the bin indexing
196+
nbins = 2000;
197+
}
198+
mChannelDist = new TH2F("channelDist", ";channel; t - t_{exp}^{#pi} (ps)", 157248, 0, 157248, nbins, -mRange, mRange);
195199
#endif
196200
}
197201

Detectors/TOF/calibration/src/TOFChannelCalibrator.cxx

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,19 +698,52 @@ void TOFChannelCalibrator<T>::finalizeSlotWithTracks(Slot& slot)
698698
fitValues.fill(-99999999);
699699
histoValues.clear();
700700
// more efficient way
701+
int imax = nbins / 2;
702+
double maxval = 0;
703+
double binwidth = 2 * range / nbins;
704+
int binrange = int(1500 / binwidth) + 1;
705+
float minRange = -range;
706+
float maxRange = range;
707+
int nbinsUsed = 0;
701708
for (unsigned j = chinsector; j <= chinsector; ++j) {
709+
for (unsigned i = 0; i < nbins; ++i) { // find peak
710+
const auto& v = histo.at(i, j);
711+
if (v > maxval) {
712+
maxval = v;
713+
imax = i;
714+
}
715+
}
716+
717+
float renorm = 1.; // to avoid fit problem when stats is too large (bad chi2)
718+
if (maxval > 10) {
719+
renorm = 10. / maxval;
720+
}
721+
702722
for (unsigned i = 0; i < nbins; ++i) {
703723
const auto& v = histo.at(i, j);
704724
LOG(debug) << "channel = " << ich << ", in sector = " << sector << " (where it is channel = " << chinsector << ") bin = " << i << " value = " << v;
705-
histoValues.push_back(v);
725+
if (i >= imax - binrange && i < imax + binrange) {
726+
histoValues.push_back(v * renorm);
727+
nbinsUsed++;
728+
} // not count for entries far from the peak (fit optimization)
706729
}
707730
}
708731

709-
double fitres = fitGaus(nbins, histoValues.data(), -range, range, fitValues, nullptr, 2., true);
732+
minRange = (imax - nbins / 2 - binrange) * binwidth;
733+
maxRange = (imax - nbins / 2 + binrange) * binwidth;
734+
735+
double fitres = fitGaus(nbinsUsed, histoValues.data(), minRange, maxRange, fitValues, nullptr, 2., false);
710736
LOG(info) << "channel = " << ich << " fitted by thread = " << ithread;
711-
if (fitres >= 0) {
737+
if (fitres > -3) {
712738
LOG(info) << "Channel " << ich << " :: Fit result " << fitres << " Mean = " << fitValues[1] << " Sigma = " << fitValues[2];
713739
} else {
740+
#ifdef DEBUGGING
741+
FILE* f = fopen(Form("%d.cal", ich), "w");
742+
for (int i = 0; i < histoValues.size(); i++) {
743+
fprintf(f, "%d %f %f\n", i, minRange + binwidth * i, histoValues[i]);
744+
}
745+
fclose(f);
746+
#endif
714747
LOG(info) << "Channel " << ich << " :: Fit failed with result = " << fitres;
715748
ts.setFractionUnderPeak(ich / Geo::NPADSXSECTOR, ich % Geo::NPADSXSECTOR, -1);
716749
ts.setSigmaPeak(ich / Geo::NPADSXSECTOR, ich % Geo::NPADSXSECTOR, 99999);

0 commit comments

Comments
 (0)