diff --git a/Detectors/FIT/FT0/calibration/include/FT0Calibration/FT0ChannelTimeTimeSlotContainer.h b/Detectors/FIT/FT0/calibration/include/FT0Calibration/FT0ChannelTimeTimeSlotContainer.h index 77e7bfe8d2d15..f6f0c4ce36264 100644 --- a/Detectors/FIT/FT0/calibration/include/FT0Calibration/FT0ChannelTimeTimeSlotContainer.h +++ b/Detectors/FIT/FT0/calibration/include/FT0Calibration/FT0ChannelTimeTimeSlotContainer.h @@ -29,7 +29,7 @@ class FT0ChannelTimeTimeSlotContainer final { //ranges to be discussed - static constexpr int HISTOGRAM_RANGE = 200; + static constexpr int HISTOGRAM_RANGE = 2000; static constexpr unsigned int NUMBER_OF_HISTOGRAM_BINS = 2 * HISTOGRAM_RANGE; using BoostHistogramType = boost::histogram::histogram, @@ -43,6 +43,7 @@ class FT0ChannelTimeTimeSlotContainer final [[nodiscard]] int16_t getMeanGaussianFitValue(std::size_t channelID) const; void merge(FT0ChannelTimeTimeSlotContainer* prev); void print() const; + static int sGausFitBins; private: std::size_t mMinEntries; diff --git a/Detectors/FIT/FT0/calibration/src/FT0ChannelTimeTimeSlotContainer.cxx b/Detectors/FIT/FT0/calibration/src/FT0ChannelTimeTimeSlotContainer.cxx index 84d75fc5b7cde..01c299c12d5e9 100644 --- a/Detectors/FIT/FT0/calibration/src/FT0ChannelTimeTimeSlotContainer.cxx +++ b/Detectors/FIT/FT0/calibration/src/FT0ChannelTimeTimeSlotContainer.cxx @@ -17,6 +17,8 @@ using namespace o2::ft0; +int FT0ChannelTimeTimeSlotContainer::sGausFitBins = 999; // NOT USED + FT0ChannelTimeTimeSlotContainer::FT0ChannelTimeTimeSlotContainer(std::size_t minEntries) : mMinEntries(minEntries) { @@ -65,21 +67,38 @@ int16_t FT0ChannelTimeTimeSlotContainer::getMeanGaussianFitValue(std::size_t cha return 0; } LOG(DEBUG) << " for channel " << int(channelID) << " entries " << mEntriesPerChannel[channelID]; + std::vector channelHistogramData(NUMBER_OF_HISTOGRAM_BINS); + std::vector outputGaussianFitValues; + double binWidth = (HISTOGRAM_RANGE - (-HISTOGRAM_RANGE)) / NUMBER_OF_HISTOGRAM_BINS; + double minGausFitRange = 0; + double maxGausFitRange = 0; + double MaxValOfHistogram = 0.0; + for (int iBin = 0; iBin < NUMBER_OF_HISTOGRAM_BINS; ++iBin) { channelHistogramData[iBin] = mHistogram.at(iBin, channelID); } + int maxElementIndex = std::max_element(channelHistogramData.begin(), channelHistogramData.end()) - channelHistogramData.begin(); + int maxElement = *std::max_element(channelHistogramData.begin(), channelHistogramData.end()); + + // calculating the min & max range values to fit gaussian + minGausFitRange = (-HISTOGRAM_RANGE + (maxElementIndex - sGausFitBins) * binWidth + binWidth / 2.0); + maxGausFitRange = (-HISTOGRAM_RANGE + (maxElementIndex + sGausFitBins) * binWidth + binWidth / 2.0); + double returnCode = math_utils::fitGaus(NUMBER_OF_HISTOGRAM_BINS, channelHistogramData.data(), - -HISTOGRAM_RANGE, HISTOGRAM_RANGE, outputGaussianFitValues); + minGausFitRange, maxGausFitRange, outputGaussianFitValues); + + MaxValOfHistogram = (-HISTOGRAM_RANGE + maxElementIndex * binWidth + binWidth / 2.0); if (returnCode < 0) { LOG(ERROR) << "Gaussian fit error!"; - return 0; + return static_cast(std::round(MaxValOfHistogram)); } return static_cast(std::round(outputGaussianFitValues[MEAN_VALUE_INDEX_IN_OUTPUT_VECTOR])); } + void FT0ChannelTimeTimeSlotContainer::print() const { //QC will do that part diff --git a/Detectors/FIT/FT0/calibration/testWorkflow/FT0Calibration-Workflow.cxx b/Detectors/FIT/FT0/calibration/testWorkflow/FT0Calibration-Workflow.cxx index a6c977d1d0de2..23c94dc363095 100644 --- a/Detectors/FIT/FT0/calibration/testWorkflow/FT0Calibration-Workflow.cxx +++ b/Detectors/FIT/FT0/calibration/testWorkflow/FT0Calibration-Workflow.cxx @@ -10,10 +10,16 @@ // or submit itself to any jurisdiction. #include "FT0ChannelTimeCalibrationSpec.h" +#include "FT0Calibration/FT0ChannelTimeTimeSlotContainer.h" + +using namespace o2::framework; void customize(std::vector& workflowOptions) { //probably some option will be added + std::vector options; + options.push_back(ConfigParamSpec{"time-calib-fitting-nbins", VariantType::Int, 2, {""}}); + std::swap(workflowOptions, options); } #include "Framework/runDataProcessing.h" @@ -22,6 +28,7 @@ using namespace o2::framework; WorkflowSpec defineDataProcessing(ConfigContext const& config) { WorkflowSpec workflow; + o2::ft0::FT0ChannelTimeTimeSlotContainer::sGausFitBins = config.options().get("time-calib-fitting-nbins"); workflow.emplace_back(o2::ft0::getFT0ChannelTimeCalibrationSpec()); //add calib spec here... return workflow; diff --git a/Detectors/FIT/FT0/calibration/testWorkflow/FT0ChannelTimeCalibration-Workflow.cxx b/Detectors/FIT/FT0/calibration/testWorkflow/FT0ChannelTimeCalibration-Workflow.cxx index 26e079733a2ae..1d2daa3e2c381 100644 --- a/Detectors/FIT/FT0/calibration/testWorkflow/FT0ChannelTimeCalibration-Workflow.cxx +++ b/Detectors/FIT/FT0/calibration/testWorkflow/FT0ChannelTimeCalibration-Workflow.cxx @@ -10,10 +10,16 @@ // or submit itself to any jurisdiction. #include "FT0ChannelTimeCalibrationSpec.h" +#include "FT0Calibration/FT0ChannelTimeTimeSlotContainer.h" + +using namespace o2::framework; void customize(std::vector& workflowOptions) { //probably some option will be added + std::vector options; + options.push_back(ConfigParamSpec{"time-calib-fitting-nbins", VariantType::Int, 2, {""}}); + std::swap(workflowOptions, options); } #include "Framework/runDataProcessing.h" @@ -22,6 +28,7 @@ using namespace o2::framework; WorkflowSpec defineDataProcessing(ConfigContext const& config) { WorkflowSpec workflow; + o2::ft0::FT0ChannelTimeTimeSlotContainer::sGausFitBins = config.options().get("time-calib-fitting-nbins"); workflow.emplace_back(o2::ft0::getFT0ChannelTimeCalibrationSpec()); return workflow; } diff --git a/Detectors/FIT/FT0/calibration/testWorkflow/FT0TFProcessor-Workflow.cxx b/Detectors/FIT/FT0/calibration/testWorkflow/FT0TFProcessor-Workflow.cxx index d94f30c729810..d87618c91969e 100644 --- a/Detectors/FIT/FT0/calibration/testWorkflow/FT0TFProcessor-Workflow.cxx +++ b/Detectors/FIT/FT0/calibration/testWorkflow/FT0TFProcessor-Workflow.cxx @@ -78,5 +78,6 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) WorkflowSpec workflow; workflow.emplace_back(dataProcessorSpec); + return workflow; } diff --git a/Detectors/FIT/FV0/calibration/include/FV0Calibration/FV0ChannelTimeTimeSlotContainer.h b/Detectors/FIT/FV0/calibration/include/FV0Calibration/FV0ChannelTimeTimeSlotContainer.h index 0c05f3b72a867..c8b5352b2c4cc 100644 --- a/Detectors/FIT/FV0/calibration/include/FV0Calibration/FV0ChannelTimeTimeSlotContainer.h +++ b/Detectors/FIT/FV0/calibration/include/FV0Calibration/FV0ChannelTimeTimeSlotContainer.h @@ -30,7 +30,7 @@ class FV0ChannelTimeTimeSlotContainer final { //ranges to be discussed - static constexpr int HISTOGRAM_RANGE = 200; + static constexpr int HISTOGRAM_RANGE = 2000; static constexpr unsigned int NUMBER_OF_HISTOGRAM_BINS = 2 * HISTOGRAM_RANGE; using BoostHistogramType = boost::histogram::histogram, @@ -44,6 +44,7 @@ class FV0ChannelTimeTimeSlotContainer final [[nodiscard]] int16_t getMeanGaussianFitValue(std::size_t channelID) const; void merge(FV0ChannelTimeTimeSlotContainer* prev); void print() const; + static int sGausFitBins; private: std::size_t mMinEntries; diff --git a/Detectors/FIT/FV0/calibration/src/FV0ChannelTimeTimeSlotContainer.cxx b/Detectors/FIT/FV0/calibration/src/FV0ChannelTimeTimeSlotContainer.cxx index 5e943ea88a623..b4a6f3e46d7e8 100644 --- a/Detectors/FIT/FV0/calibration/src/FV0ChannelTimeTimeSlotContainer.cxx +++ b/Detectors/FIT/FV0/calibration/src/FV0ChannelTimeTimeSlotContainer.cxx @@ -17,6 +17,8 @@ using namespace o2::fv0; +int FV0ChannelTimeTimeSlotContainer::sGausFitBins = 999; // NOT USED + FV0ChannelTimeTimeSlotContainer::FV0ChannelTimeTimeSlotContainer(std::size_t minEntries) : mMinEntries(minEntries) { @@ -65,22 +67,41 @@ int16_t FV0ChannelTimeTimeSlotContainer::getMeanGaussianFitValue(std::size_t cha if (0 == mEntriesPerChannel[channelID]) { return 0; } + LOG(DEBUG) << " for channel " << int(channelID) << " entries " << mEntriesPerChannel[channelID]; + + std::vector channelHistogramData(NUMBER_OF_HISTOGRAM_BINS, 0); - std::vector channelHistogramData(NUMBER_OF_HISTOGRAM_BINS); std::vector outputGaussianFitValues; + double binWidth = (HISTOGRAM_RANGE - (-HISTOGRAM_RANGE)) / NUMBER_OF_HISTOGRAM_BINS; + double minGausFitRange = 0; + double maxGausFitRange = 0; + double MaxValOfHistogram = 0.0; + for (int iBin = 0; iBin < NUMBER_OF_HISTOGRAM_BINS; ++iBin) { channelHistogramData[iBin] = mHistogram.at(iBin, channelID); } + int maxElementIndex = std::max_element(channelHistogramData.begin(), channelHistogramData.end()) - channelHistogramData.begin(); + int maxElement = *std::max_element(channelHistogramData.begin(), channelHistogramData.end()); + + // calculating the min & max range values to fit gaussian + minGausFitRange = (-HISTOGRAM_RANGE + (maxElementIndex - sGausFitBins) * binWidth + binWidth / 2.0); + maxGausFitRange = (-HISTOGRAM_RANGE + (maxElementIndex + sGausFitBins) * binWidth + binWidth / 2.0); + double returnCode = math_utils::fitGaus(NUMBER_OF_HISTOGRAM_BINS, channelHistogramData.data(), - -HISTOGRAM_RANGE, HISTOGRAM_RANGE, outputGaussianFitValues); + minGausFitRange, maxGausFitRange, outputGaussianFitValues); + + MaxValOfHistogram = (-HISTOGRAM_RANGE + maxElementIndex * binWidth + binWidth / 2.0); + if (returnCode < 0) { LOG(ERROR) << "Gaussian fit error!"; - return 0; + return static_cast(std::round(MaxValOfHistogram)); + //return 0; } return static_cast(std::round(outputGaussianFitValues[MEAN_VALUE_INDEX_IN_OUTPUT_VECTOR])); } + void FV0ChannelTimeTimeSlotContainer::print() const { //QC will do that part diff --git a/Detectors/FIT/FV0/calibration/workflow/FV0ChannelTimeCalibration-Workflow.cxx b/Detectors/FIT/FV0/calibration/workflow/FV0ChannelTimeCalibration-Workflow.cxx index 8aab34fb230d9..0d231c53ac67b 100644 --- a/Detectors/FIT/FV0/calibration/workflow/FV0ChannelTimeCalibration-Workflow.cxx +++ b/Detectors/FIT/FV0/calibration/workflow/FV0ChannelTimeCalibration-Workflow.cxx @@ -10,10 +10,17 @@ // or submit itself to any jurisdiction. #include "FV0ChannelTimeCalibrationSpec.h" +#include "FV0Calibration/FV0ChannelTimeTimeSlotContainer.h" + +using namespace o2::framework; void customize(std::vector& workflowOptions) { + //probably some option will be added + std::vector options; + options.push_back(ConfigParamSpec{"time-calib-fitting-nbins", VariantType::Int, 2, {""}}); + std::swap(workflowOptions, options); } #include "Framework/runDataProcessing.h" @@ -22,6 +29,7 @@ using namespace o2::framework; WorkflowSpec defineDataProcessing(ConfigContext const& config) { WorkflowSpec workflow; + o2::fv0::FV0ChannelTimeTimeSlotContainer::sGausFitBins = config.options().get("time-calib-fitting-nbins"); workflow.emplace_back(o2::fv0::getFV0ChannelTimeCalibrationSpec()); return workflow; }