From 56f4a2084c90d09c5e919102f76c8a44dab7a75a Mon Sep 17 00:00:00 2001 From: HimanshuCERN Date: Mon, 25 Oct 2021 16:50:06 +0200 Subject: [PATCH 1/3] FIT: add time-calibration command line option --- .../FT0ChannelTimeTimeSlotContainer.h | 3 +- .../src/FT0ChannelTimeTimeSlotContainer.cxx | 36 +++++++++++++++--- .../FT0ChannelTimeCalibration-Workflow.cxx | 7 ++++ .../FV0ChannelTimeTimeSlotContainer.h | 3 +- .../src/FV0ChannelTimeTimeSlotContainer.cxx | 38 +++++++++++++++---- .../FV0ChannelTimeCalibration-Workflow.cxx | 8 ++++ 6 files changed, 80 insertions(+), 15 deletions(-) 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..c27ea704adae6 100644 --- a/Detectors/FIT/FT0/calibration/src/FT0ChannelTimeTimeSlotContainer.cxx +++ b/Detectors/FIT/FT0/calibration/src/FT0ChannelTimeTimeSlotContainer.cxx @@ -17,14 +17,18 @@ using namespace o2::ft0; +int FT0ChannelTimeTimeSlotContainer::sGausFitBins = 999; // NOT USED + FT0ChannelTimeTimeSlotContainer::FT0ChannelTimeTimeSlotContainer(std::size_t minEntries) : mMinEntries(minEntries) { + mHistogram = boost::histogram::make_histogram(boost::histogram::axis::integer<>(-HISTOGRAM_RANGE, HISTOGRAM_RANGE, "channel_times"), boost::histogram::axis::integer<>(0, o2::ft0::Nchannels_FT0, "channel_ID")); } + bool FT0ChannelTimeTimeSlotContainer::hasEnoughEntries() const { return *std::min_element(mEntriesPerChannel.begin(), mEntriesPerChannel.end()) > mMinEntries; @@ -65,21 +69,41 @@ 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); - if (returnCode < 0) { - LOG(ERROR) << "Gaussian fit error!"; - return 0; - } + minGausFitRange, maxGausFitRange, outputGaussianFitValues); - return static_cast(std::round(outputGaussianFitValues[MEAN_VALUE_INDEX_IN_OUTPUT_VECTOR])); + MaxValOfHistogram = (-HISTOGRAM_RANGE + maxElementIndex * binWidth + binWidth/2.0 ); + if (returnCode < 0) + { + LOG(ERROR) << "Gaussian fit error!"; + 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/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/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..42445dbb91acf 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,44 @@ 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); - if (returnCode < 0) { - LOG(ERROR) << "Gaussian fit error!"; - return 0; - } + minGausFitRange, maxGausFitRange, outputGaussianFitValues); + + MaxValOfHistogram = (-HISTOGRAM_RANGE + maxElementIndex * binWidth + binWidth/2.0 ); + + if (returnCode < 0) + { + LOG(ERROR) << "Gaussian fit error!"; + return static_cast(std::round(MaxValOfHistogram)); + //return 0; + } - return static_cast(std::round(outputGaussianFitValues[MEAN_VALUE_INDEX_IN_OUTPUT_VECTOR])); + 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; } From 290186ea3bd9ca7d70ba23a12e11cdb79b8bbd1f Mon Sep 17 00:00:00 2001 From: HimanshuCERN Date: Mon, 25 Oct 2021 19:29:38 +0200 Subject: [PATCH 2/3] Fix clang formatting --- .../src/FT0ChannelTimeTimeSlotContainer.cxx | 27 ++++++++----------- .../testWorkflow/FT0TFProcessor-Workflow.cxx | 1 + .../src/FV0ChannelTimeTimeSlotContainer.cxx | 27 +++++++++---------- 3 files changed, 24 insertions(+), 31 deletions(-) diff --git a/Detectors/FIT/FT0/calibration/src/FT0ChannelTimeTimeSlotContainer.cxx b/Detectors/FIT/FT0/calibration/src/FT0ChannelTimeTimeSlotContainer.cxx index c27ea704adae6..01c299c12d5e9 100644 --- a/Detectors/FIT/FT0/calibration/src/FT0ChannelTimeTimeSlotContainer.cxx +++ b/Detectors/FIT/FT0/calibration/src/FT0ChannelTimeTimeSlotContainer.cxx @@ -23,12 +23,10 @@ FT0ChannelTimeTimeSlotContainer::FT0ChannelTimeTimeSlotContainer(std::size_t min : mMinEntries(minEntries) { - mHistogram = boost::histogram::make_histogram(boost::histogram::axis::integer<>(-HISTOGRAM_RANGE, HISTOGRAM_RANGE, "channel_times"), boost::histogram::axis::integer<>(0, o2::ft0::Nchannels_FT0, "channel_ID")); } - bool FT0ChannelTimeTimeSlotContainer::hasEnoughEntries() const { return *std::min_element(mEntriesPerChannel.begin(), mEntriesPerChannel.end()) > mMinEntries; @@ -73,37 +71,34 @@ int16_t FT0ChannelTimeTimeSlotContainer::getMeanGaussianFitValue(std::size_t cha std::vector channelHistogramData(NUMBER_OF_HISTOGRAM_BINS); std::vector outputGaussianFitValues; - double binWidth = (HISTOGRAM_RANGE - (-HISTOGRAM_RANGE))/NUMBER_OF_HISTOGRAM_BINS; + 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 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 ); + 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(), minGausFitRange, maxGausFitRange, outputGaussianFitValues); - MaxValOfHistogram = (-HISTOGRAM_RANGE + maxElementIndex * binWidth + binWidth/2.0 ); - if (returnCode < 0) - { - LOG(ERROR) << "Gaussian fit error!"; - return static_cast(std::round(MaxValOfHistogram)); - } + MaxValOfHistogram = (-HISTOGRAM_RANGE + maxElementIndex * binWidth + binWidth / 2.0); + if (returnCode < 0) { + LOG(ERROR) << "Gaussian fit error!"; + return static_cast(std::round(MaxValOfHistogram)); + } - return static_cast(std::round(outputGaussianFitValues[MEAN_VALUE_INDEX_IN_OUTPUT_VECTOR])); + 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/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/src/FV0ChannelTimeTimeSlotContainer.cxx b/Detectors/FIT/FV0/calibration/src/FV0ChannelTimeTimeSlotContainer.cxx index 42445dbb91acf..b4a6f3e46d7e8 100644 --- a/Detectors/FIT/FV0/calibration/src/FV0ChannelTimeTimeSlotContainer.cxx +++ b/Detectors/FIT/FV0/calibration/src/FV0ChannelTimeTimeSlotContainer.cxx @@ -72,39 +72,36 @@ int16_t FV0ChannelTimeTimeSlotContainer::getMeanGaussianFitValue(std::size_t cha std::vector channelHistogramData(NUMBER_OF_HISTOGRAM_BINS, 0); std::vector outputGaussianFitValues; - double binWidth = (HISTOGRAM_RANGE - (-HISTOGRAM_RANGE))/NUMBER_OF_HISTOGRAM_BINS; + 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 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 ); + 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(), minGausFitRange, maxGausFitRange, outputGaussianFitValues); - MaxValOfHistogram = (-HISTOGRAM_RANGE + maxElementIndex * binWidth + binWidth/2.0 ); + MaxValOfHistogram = (-HISTOGRAM_RANGE + maxElementIndex * binWidth + binWidth / 2.0); - if (returnCode < 0) - { - LOG(ERROR) << "Gaussian fit error!"; - return static_cast(std::round(MaxValOfHistogram)); - //return 0; - } + if (returnCode < 0) { + LOG(ERROR) << "Gaussian fit error!"; + return static_cast(std::round(MaxValOfHistogram)); + //return 0; + } - return static_cast(std::round(outputGaussianFitValues[MEAN_VALUE_INDEX_IN_OUTPUT_VECTOR])); + return static_cast(std::round(outputGaussianFitValues[MEAN_VALUE_INDEX_IN_OUTPUT_VECTOR])); } - void FV0ChannelTimeTimeSlotContainer::print() const { //QC will do that part From e81aebfa7afea0a974c64920c900c8505173ace8 Mon Sep 17 00:00:00 2001 From: HimanshuCERN Date: Tue, 2 Nov 2021 13:18:28 +0100 Subject: [PATCH 3/3] FIT: add time calib option for FT0 --- .../calibration/testWorkflow/FT0Calibration-Workflow.cxx | 7 +++++++ 1 file changed, 7 insertions(+) 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;