From 8dae8c0559c33d1aa999b0183a0baf46dfc0c782 Mon Sep 17 00:00:00 2001 From: Daiki Sekihata Date: Fri, 3 Jul 2026 14:58:32 +0200 Subject: [PATCH] [Common] clean up 4 codes --- Common/TableProducer/CMakeLists.txt | 21 - Common/TableProducer/centralityTable.cxx | 795 ------------------- Common/TableProducer/multiplicityTable.cxx | 844 --------------------- Common/TableProducer/timestamp.cxx | 147 ---- Common/TableProducer/trackPropagation.cxx | 377 --------- 5 files changed, 2184 deletions(-) delete mode 100644 Common/TableProducer/centralityTable.cxx delete mode 100644 Common/TableProducer/multiplicityTable.cxx delete mode 100644 Common/TableProducer/timestamp.cxx delete mode 100644 Common/TableProducer/trackPropagation.cxx diff --git a/Common/TableProducer/CMakeLists.txt b/Common/TableProducer/CMakeLists.txt index 26af3c092f1..6526cb41772 100644 --- a/Common/TableProducer/CMakeLists.txt +++ b/Common/TableProducer/CMakeLists.txt @@ -34,11 +34,6 @@ o2physics_add_dpl_workflow(event-selection-service-run2 O2::DataFormatsITSMFT COMPONENT_NAME Analysis) -o2physics_add_dpl_workflow(multiplicity-table - SOURCES multiplicityTable.cxx - PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore - COMPONENT_NAME Analysis) - o2physics_add_dpl_workflow(multcenttable SOURCES multCentTable.cxx PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore @@ -49,16 +44,6 @@ o2physics_add_dpl_workflow(multiplicity-extra-table PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore COMPONENT_NAME Analysis) -o2physics_add_dpl_workflow(centrality-table - SOURCES centralityTable.cxx - PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore - COMPONENT_NAME Analysis) - -o2physics_add_dpl_workflow(timestamp - SOURCES timestamp.cxx - PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore - COMPONENT_NAME Analysis) - o2physics_add_dpl_workflow(weak-decay-indices SOURCES weakDecayIndices.cxx PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore @@ -69,12 +54,6 @@ o2physics_add_dpl_workflow(ft0-corrected-table PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore COMPONENT_NAME Analysis) -o2physics_add_dpl_workflow(track-propagation - SOURCES trackPropagation.cxx - PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore - COMPONENT_NAME Analysis) - - o2physics_add_dpl_workflow(propagationservice SOURCES propagationService.cxx PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore O2::DCAFitter KFParticle::KFParticle O2Physics::TPCDriftManager diff --git a/Common/TableProducer/centralityTable.cxx b/Common/TableProducer/centralityTable.cxx deleted file mode 100644 index 26fc9dab09a..00000000000 --- a/Common/TableProducer/centralityTable.cxx +++ /dev/null @@ -1,795 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. -// -/// \file centralityTable.cxx -/// \brief Task to produce the centrality tables associated to each of the required centrality estimators -/// -/// \author ALICE -// - -#include "Common/Core/MetadataHelper.h" -#include "Common/Core/TableHelper.h" -#include "Common/DataModel/Centrality.h" -#include "Common/DataModel/EventSelection.h" -#include "Common/DataModel/Multiplicity.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -using namespace o2; -using namespace o2::framework; - -o2::common::core::MetadataHelper metadataInfo; // Metadata helper - -static constexpr int kCentRun2V0Ms = 0; -static constexpr int kCentRun2V0As = 1; -static constexpr int kCentRun2SPDTrks = 2; -static constexpr int kCentRun2SPDClss = 3; -static constexpr int kCentRun2CL0s = 4; -static constexpr int kCentRun2CL1s = 5; -static constexpr int kCentFV0As = 6; -static constexpr int kCentFT0Ms = 7; -static constexpr int kCentFT0As = 8; -static constexpr int kCentFT0Cs = 9; -static constexpr int kCentFT0CVariant1s = 10; -static constexpr int kCentFDDMs = 11; -static constexpr int kCentNTPVs = 12; -static constexpr int kCentNGlobals = 13; -static constexpr int kCentMFTs = 14; -static constexpr int NTables = 15; -static constexpr int NParameters = 1; -static const std::vector tableNames{"CentRun2V0Ms", - "CentRun2V0As", - "CentRun2SPDTrks", - "CentRun2SPDClss", - "CentRun2CL0s", - "CentRun2CL1s", - "CentFV0As", - "CentFT0Ms", - "CentFT0As", - "CentFT0Cs", - "CentFT0CVariant1s", - "CentFDDMs", - "CentNTPVs", - "CentNGlobals", - "CentMFTs"}; -static const std::vector parameterNames{"Enable"}; -static const int defaultParameters[NTables][NParameters]{{-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}}; - -struct CentralityTable { - Produces centRun2V0M; - Produces centRun2V0A; - Produces centRun2SPDTracklets; - Produces centRun2SPDClusters; - Produces centRun2CL0; - Produces centRun2CL1; - Produces centFV0A; - Produces centFT0M; - Produces centFT0A; - Produces centFT0C; - Produces centFT0CVariant1; - Produces centFDDM; - Produces centNTPV; - Produces centNGlobals; - Produces centMFTs; - Service ccdb; - Configurable> enabledTables{"enabledTables", - {defaultParameters[0], NTables, NParameters, tableNames, parameterNames}, - "Produce tables depending on needs. Values different than -1 override the automatic setup: the corresponding table can be set off (0) or on (1)"}; - struct : ConfigurableGroup { - Configurable ccdbUrl{"ccdbUrl", "http://alice-ccdb.cern.ch", "The CCDB endpoint url address"}; - Configurable ccdbPath{"ccdbPath", "Centrality/Estimators", "The CCDB path for centrality/multiplicity information"}; - Configurable genName{"genName", "", "Genearator name: HIJING, PYTHIA8, ... Default: \"\""}; - Configurable doNotCrashOnNull{"doNotCrashOnNull", false, {"Option to not crash on null and instead fill required tables with dummy info"}}; - Configurable reconstructionPass{"reconstructionPass", "", {"Apass to use when fetching the calibration tables. Empty (default) does not check for any pass. Use `metadata` to fetch it from the AO2D metadata. Otherwise it will override the metadata."}}; - } ccdbConfig; - - Configurable embedINELgtZEROselection{"embedINELgtZEROselection", false, {"Option to do percentile 100.5 if not INELgtZERO"}}; - Configurable produceHistograms{"produceHistograms", false, {"Option to produce debug histograms"}}; - ConfigurableAxis binsPercentile{"binsPercentile", {VARIABLE_WIDTH, 0, 0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009, 0.01, 0.011, 0.012, 0.013, 0.014, 0.015, 0.016, 0.017, 0.018, 0.019, 0.02, 0.021, 0.022, 0.023, 0.024, 0.025, 0.026, 0.027, 0.028, 0.029, 0.03, 0.031, 0.032, 0.033, 0.034, 0.035, 0.036, 0.037, 0.038, 0.039, 0.04, 0.041, 0.042, 0.043, 0.044, 0.045, 0.046, 0.047, 0.048, 0.049, 0.05, 0.051, 0.052, 0.053, 0.054, 0.055, 0.056, 0.057, 0.058, 0.059, 0.06, 0.061, 0.062, 0.063, 0.064, 0.065, 0.066, 0.067, 0.068, 0.069, 0.07, 0.071, 0.072, 0.073, 0.074, 0.075, 0.076, 0.077, 0.078, 0.079, 0.08, 0.081, 0.082, 0.083, 0.084, 0.085, 0.086, 0.087, 0.088, 0.089, 0.09, 0.091, 0.092, 0.093, 0.094, 0.095, 0.096, 0.097, 0.098, 0.099, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4, 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6, 0.61, 0.62, 0.63, 0.64, 0.65, 0.66, 0.67, 0.68, 0.69, 0.7, 0.71, 0.72, 0.73, 0.74, 0.75, 0.76, 0.77, 0.78, 0.79, 0.8, 0.81, 0.82, 0.83, 0.84, 0.85, 0.86, 0.87, 0.88, 0.89, 0.9, 0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5.0, 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0, 6.1, 6.2, 6.3, 6.4, 6.5, 6.6, 6.7, 6.8, 6.9, 7.0, 7.1, 7.2, 7.3, 7.4, 7.5, 7.6, 7.7, 7.8, 7.9, 8.0, 8.1, 8.2, 8.3, 8.4, 8.5, 8.6, 8.7, 8.8, 8.9, 9.0, 9.1, 9.2, 9.3, 9.4, 9.5, 9.6, 9.7, 9.8, 9.9, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 40.0, 41.0, 42.0, 43.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 50.0, 51.0, 52.0, 53.0, 54.0, 55.0, 56.0, 57.0, 58.0, 59.0, 60.0, 61.0, 62.0, 63.0, 64.0, 65.0, 66.0, 67.0, 68.0, 69.0, 70.0, 71.0, 72.0, 73.0, 74.0, 75.0, 76.0, 77.0, 78.0, 79.0, 80.0, 81.0, 82.0, 83.0, 84.0, 85.0, 86.0, 87.0, 88.0, 89.0, 90.0, 91.0, 92.0, 93.0, 94.0, 95.0, 96.0, 97.0, 98.0, 99.0, 100.0}, "Binning of the percentile axis"}; - ConfigurableAxis binsPVcontr{"binsPVcontr", {100, 0.f, 100.f}, "PV mult."}; - - int mRunNumber; - struct TagRun2V0MCalibration { - bool mCalibrationStored = false; - TFormula* mMCScale = nullptr; - float mMCScalePars[6] = {0.0}; - TH1* mhVtxAmpCorrV0A = nullptr; - TH1* mhVtxAmpCorrV0C = nullptr; - TH1* mhMultSelCalib = nullptr; - } Run2V0MInfo; - struct TagRun2V0ACalibration { - bool mCalibrationStored = false; - TH1* mhVtxAmpCorrV0A = nullptr; - TH1* mhMultSelCalib = nullptr; - } Run2V0AInfo; - struct TagRun2SPDTrackletsCalibration { - bool mCalibrationStored = false; - TH1* mhVtxAmpCorr = nullptr; - TH1* mhMultSelCalib = nullptr; - } Run2SPDTksInfo; - struct TagRun2SPDClustersCalibration { - bool mCalibrationStored = false; - TH1* mhVtxAmpCorrCL0 = nullptr; - TH1* mhVtxAmpCorrCL1 = nullptr; - TH1* mhMultSelCalib = nullptr; - } Run2SPDClsInfo; - struct TagRun2CL0Calibration { - bool mCalibrationStored = false; - TH1* mhVtxAmpCorr = nullptr; - TH1* mhMultSelCalib = nullptr; - } Run2CL0Info; - struct TagRun2CL1Calibration { - bool mCalibrationStored = false; - TH1* mhVtxAmpCorr = nullptr; - TH1* mhMultSelCalib = nullptr; - } Run2CL1Info; - struct CalibrationInfo { - std::string name = ""; - bool mCalibrationStored = false; - TH1* mhMultSelCalib = nullptr; - float mMCScalePars[6] = {0.0}; - TFormula* mMCScale = nullptr; - explicit CalibrationInfo(std::string name) - : name(name), - mCalibrationStored(false), - mhMultSelCalib(nullptr), - mMCScalePars{0.0}, - mMCScale(nullptr) - { - } - bool isSane(bool fatalize = false) - { - if (!mhMultSelCalib) { - return true; - } - for (int i = 1; i < mhMultSelCalib->GetNbinsX() + 1; i++) { - if (mhMultSelCalib->GetXaxis()->GetBinLowEdge(i) > mhMultSelCalib->GetXaxis()->GetBinUpEdge(i)) { - if (fatalize) { - LOG(fatal) << "Centrality calibration table " << name << " has bins with low edge > up edge"; - } - LOG(warning) << "Centrality calibration table " << name << " has bins with low edge > up edge"; - return false; - } - } - return true; - } - }; - CalibrationInfo fv0aInfo = CalibrationInfo("FV0"); - CalibrationInfo ft0mInfo = CalibrationInfo("FT0"); - CalibrationInfo ft0aInfo = CalibrationInfo("FT0A"); - CalibrationInfo ft0cInfo = CalibrationInfo("FT0C"); - CalibrationInfo ft0cVariant1Info = CalibrationInfo("FT0Cvar1"); - CalibrationInfo fddmInfo = CalibrationInfo("FDD"); - CalibrationInfo ntpvInfo = CalibrationInfo("NTracksPV"); - CalibrationInfo nGlobalInfo = CalibrationInfo("NGlobal"); - CalibrationInfo mftInfo = CalibrationInfo("MFT"); - std::vector mEnabledTables; // Vector of enabled tables - std::array isTableEnabled; - - // Debug output - HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject}; - OutputObj listCalib{"calib-list", OutputObjHandlingPolicy::QAObject}; - - void init(InitContext& context) - { - LOG(info) << "Initializing centrality table producer"; - if (doprocessRun3FT0 == true) { - LOG(fatal) << "FT0 only mode is automatically enabled in Run3 mode. Please disable it and enable processRun3."; - } - if (doprocessRun2 == false && doprocessRun3 == false && doprocessRun3Complete == false) { - LOGF(fatal, "Neither processRun2 nor processRun3 nor processRun3Complete enabled. Please choose one."); - } - if (doprocessRun2 == true && doprocessRun3 == true) { - LOGF(fatal, "Cannot enable processRun2 and processRun3 at the same time. Please choose one."); - } - - /* Checking the tables which are requested in the workflow and enabling them */ - for (int i = 0; i < NTables; i++) { - int f = enabledTables->get(tableNames[i].c_str(), "Enable"); - o2::common::core::enableFlagIfTableRequired(context, tableNames[i], f); - if (f == 1) { - if (tableNames[i].find("Run2") != std::string::npos) { - if (doprocessRun3) { - LOG(fatal) << "Cannot enable Run2 table `" << tableNames[i] << "` while running in Run3 mode. Please check and disable them."; - } - } else { - if (doprocessRun2) { - LOG(fatal) << "Cannot enable Run3 table `" << tableNames[i] << "` while running in Run2 mode. Please check and disable them."; - } - } - isTableEnabled[i] = true; - mEnabledTables.push_back(i); - } - } - - if (mEnabledTables.size() == 0) { - LOGF(fatal, "No table enabled. Please enable at least one table."); - } - std::sort(mEnabledTables.begin(), mEnabledTables.end()); - - // Check if FT0 is the only centrality needed - if (mEnabledTables.size() == 1 && isTableEnabled[kCentFT0Ms] == true) { - LOG(info) << "FT0 only mode is enabled"; - doprocessRun3FT0.value = true; - doprocessRun3.value = false; - } - - ccdb->setURL(ccdbConfig.ccdbUrl); - ccdb->setCaching(true); - ccdb->setLocalObjectValidityChecking(); - ccdb->setFatalWhenNull(false); - mRunNumber = 0; - listCalib.setObject(new TList); - if (!produceHistograms.value) { - return; - } - - histos.add("FT0M/percentile", "FT0M percentile.", HistType::kTH1D, {{binsPercentile, "FT0M percentile"}}); - histos.add("FT0M/percentilevsPV", "percentile vs PV mult.", HistType::kTH2D, {{binsPercentile, "FT0M percentile"}, {binsPVcontr, "PV mult."}}); - histos.add("FT0M/MultvsPV", "FT0M mult. vs PV mult.", HistType::kTH2D, {{1000, 0, 5000, "FT0M mult."}, {binsPVcontr, "PV mult."}}); - - histos.add("FT0A/percentile", "FT0A percentile.", HistType::kTH1D, {{binsPercentile, "FT0A percentile"}}); - histos.add("FT0A/percentilevsPV", "percentile vs PV mult.", HistType::kTH2D, {{binsPercentile, "FT0A percentile"}, {binsPVcontr, "PV mult."}}); - histos.add("FT0A/MultvsPV", "FT0A mult. vs PV mult.", HistType::kTH2D, {{1000, 0, 5000, "FT0A mult."}, {binsPVcontr, "PV mult."}}); - - histos.add("FT0C/percentile", "FT0C percentile.", HistType::kTH1D, {{binsPercentile, "FT0C percentile"}}); - histos.add("FT0C/percentilevsPV", "percentile vs PV mult.", HistType::kTH2D, {{binsPercentile, "FT0C percentile"}, {binsPVcontr, "PV mult."}}); - histos.add("FT0C/MultvsPV", "FT0C mult. vs PV mult.", HistType::kTH2D, {{1000, 0, 5000, "FT0C mult."}, {binsPVcontr, "PV mult."}}); - - histos.addClone("FT0M/", "sel8FT0M/"); - histos.addClone("FT0C/", "sel8FT0C/"); - histos.addClone("FT0A/", "sel8FT0A/"); - - histos.print(); - } - - using BCsWithTimestampsAndRun2Infos = soa::Join; - - void processRun2(soa::Join::iterator const& collision, BCsWithTimestampsAndRun2Infos const&) - { - /* check the previous run number */ - auto bc = collision.bc_as(); - if (bc.runNumber() != mRunNumber) { - mRunNumber = bc.runNumber(); // mark that this run has been attempted already regardless of outcome - LOGF(debug, "timestamp=%llu", bc.timestamp()); - TList* callst = nullptr; - if (ccdbConfig.reconstructionPass.value == "") { - callst = ccdb->getForRun(ccdbConfig.ccdbPath, bc.runNumber()); - } else if (ccdbConfig.reconstructionPass.value == "metadata") { - std::map metadata; - metadata["RecoPassName"] = metadataInfo.get("RecoPassName"); - LOGF(info, "Loading CCDB for reconstruction pass (from metadata): %s", metadataInfo.get("RecoPassName")); - callst = ccdb->getSpecificForRun(ccdbConfig.ccdbPath, bc.runNumber(), metadata); - } else { - std::map metadata; - metadata["RecoPassName"] = ccdbConfig.reconstructionPass.value; - LOGF(info, "Loading CCDB for reconstruction pass (from provided argument): %s", ccdbConfig.reconstructionPass.value); - callst = ccdb->getSpecificForRun(ccdbConfig.ccdbPath, bc.runNumber(), metadata); - } - - Run2V0MInfo.mCalibrationStored = false; - Run2V0AInfo.mCalibrationStored = false; - Run2SPDTksInfo.mCalibrationStored = false; - Run2SPDClsInfo.mCalibrationStored = false; - Run2CL0Info.mCalibrationStored = false; - Run2CL1Info.mCalibrationStored = false; - if (callst != nullptr) { - auto getccdb = [callst](const char* ccdbhname) { - TH1* h = reinterpret_cast(callst->FindObject(ccdbhname)); - return h; - }; - auto getformulaccdb = [callst](const char* ccdbhname) { - TFormula* f = reinterpret_cast(callst->FindObject(ccdbhname)); - return f; - }; - if (isTableEnabled[kCentRun2V0Ms]) { - LOGF(debug, "Getting new histograms with %d run number for %d run number", mRunNumber, bc.runNumber()); - Run2V0MInfo.mhVtxAmpCorrV0A = getccdb("hVtx_fAmplitude_V0A_Normalized"); - Run2V0MInfo.mhVtxAmpCorrV0C = getccdb("hVtx_fAmplitude_V0C_Normalized"); - Run2V0MInfo.mhMultSelCalib = getccdb("hMultSelCalib_V0M"); - Run2V0MInfo.mMCScale = getformulaccdb(TString::Format("%s-V0M", ccdbConfig.genName->c_str()).Data()); - if ((Run2V0MInfo.mhVtxAmpCorrV0A != nullptr) && (Run2V0MInfo.mhVtxAmpCorrV0C != nullptr) && (Run2V0MInfo.mhMultSelCalib != nullptr)) { - if (ccdbConfig.genName->length() != 0) { - if (Run2V0MInfo.mMCScale != nullptr) { - for (int ixpar = 0; ixpar < 6; ++ixpar) { - Run2V0MInfo.mMCScalePars[ixpar] = Run2V0MInfo.mMCScale->GetParameter(ixpar); - } - } else { - if (!ccdbConfig.doNotCrashOnNull) { // default behaviour: crash - LOGF(fatal, "MC Scale information from V0M for run %d not available", bc.runNumber()); - } else { // only if asked: continue filling with non-valid values (105) - LOGF(info, "MC Scale information from V0M for run %d not available", bc.runNumber()); - } - } - } - Run2V0MInfo.mCalibrationStored = true; - } else { - if (!ccdbConfig.doNotCrashOnNull) { // default behaviour: crash - LOGF(fatal, "Calibration information from V0M for run %d corrupted", bc.runNumber()); - } else { // only if asked: continue filling with non-valid values (105) - LOGF(info, "Calibration information from V0M for run %d corrupted, will fill V0M tables with dummy values", bc.runNumber()); - } - } - } - if (isTableEnabled[kCentRun2V0As]) { - LOGF(debug, "Getting new histograms with %d run number for %d run number", mRunNumber, bc.runNumber()); - Run2V0AInfo.mhVtxAmpCorrV0A = getccdb("hVtx_fAmplitude_V0A_Normalized"); - Run2V0AInfo.mhMultSelCalib = getccdb("hMultSelCalib_V0A"); - if ((Run2V0AInfo.mhVtxAmpCorrV0A != nullptr) && (Run2V0AInfo.mhMultSelCalib != nullptr)) { - Run2V0AInfo.mCalibrationStored = true; - } else { - if (!ccdbConfig.doNotCrashOnNull) { // default behaviour: crash - LOGF(fatal, "Calibration information from V0A for run %d corrupted", bc.runNumber()); - } else { // only if asked: continue filling with non-valid values (105) - LOGF(info, "Calibration information from V0A for run %d corrupted, will fill V0A tables with dummy values", bc.runNumber()); - } - } - } - if (isTableEnabled[kCentRun2SPDTrks]) { - LOGF(debug, "Getting new histograms with %d run number for %d run number", mRunNumber, bc.runNumber()); - Run2SPDTksInfo.mhVtxAmpCorr = getccdb("hVtx_fnTracklets_Normalized"); - Run2SPDTksInfo.mhMultSelCalib = getccdb("hMultSelCalib_SPDTracklets"); - if ((Run2SPDTksInfo.mhVtxAmpCorr != nullptr) && (Run2SPDTksInfo.mhMultSelCalib != nullptr)) { - Run2SPDTksInfo.mCalibrationStored = true; - } else { - if (!ccdbConfig.doNotCrashOnNull) { // default behaviour: crash - LOGF(fatal, "Calibration information from SPD tracklets for run %d corrupted", bc.runNumber()); - } else { // only if asked: continue filling with non-valid values (105) - LOGF(info, "Calibration information from SPD tracklets for run %d corrupted, will fill SPD tracklets tables with dummy values", bc.runNumber()); - } - } - } - if (isTableEnabled[kCentRun2SPDClss]) { - LOGF(debug, "Getting new histograms with %d run number for %d run number", mRunNumber, bc.runNumber()); - Run2SPDClsInfo.mhVtxAmpCorrCL0 = getccdb("hVtx_fnSPDClusters0_Normalized"); - Run2SPDClsInfo.mhVtxAmpCorrCL1 = getccdb("hVtx_fnSPDClusters1_Normalized"); - Run2SPDClsInfo.mhMultSelCalib = getccdb("hMultSelCalib_SPDClusters"); - if ((Run2SPDClsInfo.mhVtxAmpCorrCL0 != nullptr) && (Run2SPDClsInfo.mhVtxAmpCorrCL1 != nullptr) && (Run2SPDClsInfo.mhMultSelCalib != nullptr)) { - Run2SPDClsInfo.mCalibrationStored = true; - } else { - if (!ccdbConfig.doNotCrashOnNull) { // default behaviour: crash - LOGF(fatal, "Calibration information from SPD clusters for run %d corrupted", bc.runNumber()); - } else { // only if asked: continue filling with non-valid values (105) - LOGF(info, "Calibration information from SPD clusters for run %d corrupted, will fill SPD clusters tables with dummy values", bc.runNumber()); - } - } - } - if (isTableEnabled[kCentRun2CL0s]) { - LOGF(debug, "Getting new histograms with %d run number for %d run number", mRunNumber, bc.runNumber()); - Run2CL0Info.mhVtxAmpCorr = getccdb("hVtx_fnSPDClusters0_Normalized"); - Run2CL0Info.mhMultSelCalib = getccdb("hMultSelCalib_CL0"); - if ((Run2CL0Info.mhVtxAmpCorr != nullptr) && (Run2CL0Info.mhMultSelCalib != nullptr)) { - Run2CL0Info.mCalibrationStored = true; - } else { - if (!ccdbConfig.doNotCrashOnNull) { // default behaviour: crash - LOGF(fatal, "Calibration information from CL0 multiplicity for run %d corrupted", bc.runNumber()); - } else { // only if asked: continue filling with non-valid values (105) - LOGF(info, "Calibration information from CL0 multiplicity for run %d corrupted, will fill CL0 multiplicity tables with dummy values", bc.runNumber()); - } - } - } - if (isTableEnabled[kCentRun2CL1s]) { - LOGF(debug, "Getting new histograms with %d run number for %d run number", mRunNumber, bc.runNumber()); - Run2CL1Info.mhVtxAmpCorr = getccdb("hVtx_fnSPDClusters1_Normalized"); - Run2CL1Info.mhMultSelCalib = getccdb("hMultSelCalib_CL1"); - if ((Run2CL1Info.mhVtxAmpCorr != nullptr) && (Run2CL1Info.mhMultSelCalib != nullptr)) { - Run2CL1Info.mCalibrationStored = true; - } else { - if (!ccdbConfig.doNotCrashOnNull) { // default behaviour: crash - LOGF(fatal, "Calibration information from CL1 multiplicity for run %d corrupted", bc.runNumber()); - } else { // only if asked: continue filling with non-valid values (105) - LOGF(info, "Calibration information from CL1 multiplicity for run %d corrupted, will fill CL1 multiplicity tables with dummy values", bc.runNumber()); - } - } - } - } else { - if (!ccdbConfig.doNotCrashOnNull) { // default behaviour: crash - LOGF(fatal, "Centrality calibration is not available in CCDB for run=%d at timestamp=%llu", bc.runNumber(), bc.timestamp()); - } else { // only if asked: continue filling with non-valid values (105) - LOGF(info, "Centrality calibration is not available in CCDB for run=%d at timestamp=%llu, will fill tables with dummy values", bc.runNumber(), bc.timestamp()); - } - } - } - - auto scaleMC = [](float x, const float pars[6]) { - return std::pow(((pars[0] + pars[1] * std::pow(x, pars[2])) - pars[3]) / pars[4], 1.0f / pars[5]); - }; - - if (isTableEnabled[kCentRun2V0Ms]) { - float cV0M = 105.0f; - if (Run2V0MInfo.mCalibrationStored) { - float v0m; - if (Run2V0MInfo.mMCScale != nullptr) { - v0m = scaleMC(collision.multFV0M(), Run2V0MInfo.mMCScalePars); - LOGF(debug, "Unscaled v0m: %f, scaled v0m: %f", collision.multFV0M(), v0m); - } else { - v0m = collision.multFV0A() * Run2V0MInfo.mhVtxAmpCorrV0A->GetBinContent(Run2V0MInfo.mhVtxAmpCorrV0A->FindFixBin(collision.posZ())) + - collision.multFV0C() * Run2V0MInfo.mhVtxAmpCorrV0C->GetBinContent(Run2V0MInfo.mhVtxAmpCorrV0C->FindFixBin(collision.posZ())); - } - cV0M = Run2V0MInfo.mhMultSelCalib->GetBinContent(Run2V0MInfo.mhMultSelCalib->FindFixBin(v0m)); - } - LOGF(debug, "centRun2V0M=%.0f", cV0M); - // fill centrality columns - centRun2V0M(cV0M); - } - if (isTableEnabled[kCentRun2V0As]) { - float cV0A = 105.0f; - if (Run2V0AInfo.mCalibrationStored) { - float v0a = collision.multFV0A() * Run2V0AInfo.mhVtxAmpCorrV0A->GetBinContent(Run2V0AInfo.mhVtxAmpCorrV0A->FindFixBin(collision.posZ())); - cV0A = Run2V0AInfo.mhMultSelCalib->GetBinContent(Run2V0AInfo.mhMultSelCalib->FindFixBin(v0a)); - } - LOGF(debug, "centRun2V0A=%.0f", cV0A); - // fill centrality columns - centRun2V0A(cV0A); - } - if (isTableEnabled[kCentRun2SPDTrks]) { - float cSPD = 105.0f; - if (Run2SPDTksInfo.mCalibrationStored) { - float spdm = collision.multTracklets() * Run2SPDTksInfo.mhVtxAmpCorr->GetBinContent(Run2SPDTksInfo.mhVtxAmpCorr->FindFixBin(collision.posZ())); - cSPD = Run2SPDTksInfo.mhMultSelCalib->GetBinContent(Run2SPDTksInfo.mhMultSelCalib->FindFixBin(spdm)); - } - LOGF(debug, "centSPDTracklets=%.0f", cSPD); - centRun2SPDTracklets(cSPD); - } - if (isTableEnabled[kCentRun2SPDClss]) { - float cSPD = 105.0f; - if (Run2SPDClsInfo.mCalibrationStored) { - float spdm = bc.spdClustersL0() * Run2SPDClsInfo.mhVtxAmpCorrCL0->GetBinContent(Run2SPDClsInfo.mhVtxAmpCorrCL0->FindFixBin(collision.posZ())) + - bc.spdClustersL1() * Run2SPDClsInfo.mhVtxAmpCorrCL1->GetBinContent(Run2SPDClsInfo.mhVtxAmpCorrCL1->FindFixBin(collision.posZ())); - cSPD = Run2SPDClsInfo.mhMultSelCalib->GetBinContent(Run2SPDClsInfo.mhMultSelCalib->FindFixBin(spdm)); - } - LOGF(debug, "centSPDClusters=%.0f", cSPD); - centRun2SPDClusters(cSPD); - } - if (isTableEnabled[kCentRun2CL0s]) { - float cCL0 = 105.0f; - if (Run2CL0Info.mCalibrationStored) { - float cl0m = bc.spdClustersL0() * Run2CL0Info.mhVtxAmpCorr->GetBinContent(Run2CL0Info.mhVtxAmpCorr->FindFixBin(collision.posZ())); - cCL0 = Run2CL0Info.mhMultSelCalib->GetBinContent(Run2CL0Info.mhMultSelCalib->FindFixBin(cl0m)); - } - LOGF(debug, "centCL0=%.0f", cCL0); - centRun2CL0(cCL0); - } - if (isTableEnabled[kCentRun2CL1s]) { - float cCL1 = 105.0f; - if (Run2CL1Info.mCalibrationStored) { - float cl1m = bc.spdClustersL1() * Run2CL1Info.mhVtxAmpCorr->GetBinContent(Run2CL1Info.mhVtxAmpCorr->FindFixBin(collision.posZ())); - cCL1 = Run2CL1Info.mhMultSelCalib->GetBinContent(Run2CL1Info.mhMultSelCalib->FindFixBin(cl1m)); - } - LOGF(debug, "centCL1=%.0f", cCL1); - centRun2CL1(cCL1); - } - } - - using BCsWithTimestamps = soa::Join; - - template - void produceRun3Tables(CollisionType const& collisions) - { - // do memory reservation for the relevant tables only, please - for (auto const& table : mEnabledTables) { - switch (table) { - case kCentFV0As: - centFV0A.reserve(collisions.size()); - break; - case kCentFT0Ms: - centFT0M.reserve(collisions.size()); - break; - case kCentFT0As: - centFT0A.reserve(collisions.size()); - break; - case kCentFT0Cs: - centFT0C.reserve(collisions.size()); - break; - case kCentFT0CVariant1s: - centFT0CVariant1.reserve(collisions.size()); - break; - case kCentFDDMs: - centFDDM.reserve(collisions.size()); - break; - case kCentNTPVs: - centNTPV.reserve(collisions.size()); - break; - case kCentNGlobals: - centNGlobals.reserve(collisions.size()); - break; - case kCentMFTs: - centMFTs.reserve(collisions.size()); - break; - default: - LOGF(fatal, "Table %d not supported in Run3", table); - break; - } - } - - for (auto const& collision : collisions) { - /* check the previous run number */ - auto bc = collision.template bc_as(); - if (bc.runNumber() != mRunNumber) { - mRunNumber = bc.runNumber(); // mark that this run has been attempted already regardless of outcome - LOGF(info, "timestamp=%llu, run number=%d", bc.timestamp(), bc.runNumber()); - TList* callst = nullptr; - // Check if the ccdb path is a root file - if (ccdbConfig.ccdbPath.value.find(".root") != std::string::npos) { - TFile f(ccdbConfig.ccdbPath.value.c_str(), "READ"); - f.GetObject(ccdbConfig.reconstructionPass.value.c_str(), callst); - if (!callst) { - f.ls(); - LOG(fatal) << "No calibration list " << ccdbConfig.reconstructionPass.value << " found in the file " << ccdbConfig.ccdbPath.value; - } - } else { - if (ccdbConfig.reconstructionPass.value == "") { - callst = ccdb->getForRun(ccdbConfig.ccdbPath, bc.runNumber()); - } else if (ccdbConfig.reconstructionPass.value == "metadata") { - std::map metadata; - metadata["RecoPassName"] = metadataInfo.get("RecoPassName"); - LOGF(info, "Loading CCDB for reconstruction pass (from metadata): %s", metadataInfo.get("RecoPassName")); - callst = ccdb->getSpecificForRun(ccdbConfig.ccdbPath, bc.runNumber(), metadata); - } else { - std::map metadata; - metadata["RecoPassName"] = ccdbConfig.reconstructionPass.value; - LOGF(info, "Loading CCDB for reconstruction pass (from provided argument): %s", ccdbConfig.reconstructionPass.value); - callst = ccdb->getSpecificForRun(ccdbConfig.ccdbPath, bc.runNumber(), metadata); - } - } - - fv0aInfo.mCalibrationStored = false; - ft0mInfo.mCalibrationStored = false; - ft0aInfo.mCalibrationStored = false; - ft0cInfo.mCalibrationStored = false; - ft0cVariant1Info.mCalibrationStored = false; - fddmInfo.mCalibrationStored = false; - ntpvInfo.mCalibrationStored = false; - nGlobalInfo.mCalibrationStored = false; - mftInfo.mCalibrationStored = false; - if (callst != nullptr) { - if (produceHistograms) { - listCalib->Add(callst->Clone(Form("%i", bc.runNumber()))); - } - LOGF(info, "Getting new histograms with %d run number for %d run number", mRunNumber, bc.runNumber()); - auto getccdb = [callst, bc](struct CalibrationInfo& estimator, const Configurable generatorName) { // TODO: to consider the name inside the estimator structure - estimator.mhMultSelCalib = reinterpret_cast(callst->FindObject(TString::Format("hCalibZeq%s", estimator.name.c_str()).Data())); - estimator.mMCScale = reinterpret_cast(callst->FindObject(TString::Format("%s-%s", generatorName->c_str(), estimator.name.c_str()).Data())); - if (estimator.mhMultSelCalib != nullptr) { - if (generatorName->length() != 0) { - LOGF(info, "Retrieving MC calibration for %d, generator name: %s", bc.runNumber(), generatorName->c_str()); - if (estimator.mMCScale != nullptr) { - for (int ixpar = 0; ixpar < 6; ++ixpar) { - estimator.mMCScalePars[ixpar] = estimator.mMCScale->GetParameter(ixpar); - LOGF(info, "Parameter index %i value %.5f", ixpar, estimator.mMCScalePars[ixpar]); - } - } else { - LOGF(warning, "MC Scale information from %s for run %d not available", estimator.name.c_str(), bc.runNumber()); - } - } - estimator.mCalibrationStored = true; - estimator.isSane(); - } else { - LOGF(info, "Calibration information from %s for run %d not available, will fill this estimator with invalid values and continue (no crash).", estimator.name.c_str(), bc.runNumber()); - } - }; - - for (auto const& table : mEnabledTables) { - switch (table) { - case kCentFV0As: - getccdb(fv0aInfo, ccdbConfig.genName); - break; - case kCentFT0Ms: - getccdb(ft0mInfo, ccdbConfig.genName); - break; - case kCentFT0As: - getccdb(ft0aInfo, ccdbConfig.genName); - break; - case kCentFT0Cs: - getccdb(ft0cInfo, ccdbConfig.genName); - break; - case kCentFT0CVariant1s: - getccdb(ft0cVariant1Info, ccdbConfig.genName); - break; - case kCentFDDMs: - getccdb(fddmInfo, ccdbConfig.genName); - break; - case kCentNTPVs: - getccdb(ntpvInfo, ccdbConfig.genName); - break; - case kCentNGlobals: - getccdb(nGlobalInfo, ccdbConfig.genName); - break; - case kCentMFTs: - getccdb(mftInfo, ccdbConfig.genName); - break; - default: - LOGF(fatal, "Table %d not supported in Run3", table); - break; - } - } - } else { - if (!ccdbConfig.doNotCrashOnNull) { // default behaviour: crash - LOGF(fatal, "Centrality calibration is not available in CCDB for run=%d at timestamp=%llu", bc.runNumber(), bc.timestamp()); - } else { // only if asked: continue filling with non-valid values (105) - LOGF(info, "Centrality calibration is not available in CCDB for run=%d at timestamp=%llu, will fill tables with dummy values", bc.runNumber(), bc.timestamp()); - } - } - } - - /** - * @brief Populates a table with data based on the given calibration information and multiplicity. - * - * @param table The table to populate. - * @param estimator The calibration information. - * @param multiplicity The multiplicity value. - */ - - auto populateTable = [&](auto& table, struct CalibrationInfo& estimator, float multiplicity) { - const bool assignOutOfRange = embedINELgtZEROselection && !collision.isInelGt0(); - auto scaleMC = [](float x, const float pars[6]) { - return std::pow(((pars[0] + pars[1] * std::pow(x, pars[2])) - pars[3]) / pars[4], 1.0f / pars[5]); - }; - - float percentile = 105.0f; - float scaledMultiplicity = multiplicity; - if (estimator.mCalibrationStored) { - if (estimator.mMCScale != nullptr) { - scaledMultiplicity = scaleMC(multiplicity, estimator.mMCScalePars); - LOGF(debug, "Unscaled %s multiplicity: %f, scaled %s multiplicity: %f", estimator.name.c_str(), multiplicity, estimator.name.c_str(), scaledMultiplicity); - } - percentile = estimator.mhMultSelCalib->GetBinContent(estimator.mhMultSelCalib->FindFixBin(scaledMultiplicity)); - if (assignOutOfRange) - percentile = 100.5f; - } - LOGF(debug, "%s centrality/multiplicity percentile = %.0f for a zvtx eq %s value %.0f", estimator.name.c_str(), percentile, estimator.name.c_str(), scaledMultiplicity); - table(percentile); - return percentile; - }; - - for (auto const& table : mEnabledTables) { - switch (table) { - case kCentFV0As: - if constexpr (enableCentFV0) { - populateTable(centFV0A, fv0aInfo, collision.multZeqFV0A()); - } - break; - case kCentFT0Ms: - if constexpr (enableCentFT0) { - const float perC = populateTable(centFT0M, ft0mInfo, collision.multZeqFT0A() + collision.multZeqFT0C()); - if (produceHistograms.value) { - histos.fill(HIST("FT0M/percentile"), perC); - histos.fill(HIST("FT0M/percentilevsPV"), perC, collision.multNTracksPV()); - histos.fill(HIST("FT0M/MultvsPV"), collision.multZeqFT0A() + collision.multZeqFT0C(), collision.multNTracksPV()); - if (collision.sel8()) { - histos.fill(HIST("sel8FT0M/percentile"), perC); - histos.fill(HIST("sel8FT0M/percentilevsPV"), perC, collision.multNTracksPV()); - histos.fill(HIST("sel8FT0M/MultvsPV"), collision.multZeqFT0A() + collision.multZeqFT0C(), collision.multNTracksPV()); - } - } - } - break; - case kCentFT0As: - if constexpr (enableCentFT0) { - const float perC = populateTable(centFT0A, ft0aInfo, collision.multZeqFT0A()); - if (produceHistograms.value) { - histos.fill(HIST("FT0A/percentile"), perC); - histos.fill(HIST("FT0A/percentilevsPV"), perC, collision.multNTracksPV()); - histos.fill(HIST("FT0A/MultvsPV"), collision.multZeqFT0A() + collision.multZeqFT0C(), collision.multNTracksPV()); - if (collision.sel8()) { - histos.fill(HIST("sel8FT0A/percentile"), perC); - histos.fill(HIST("sel8FT0A/percentilevsPV"), perC, collision.multNTracksPV()); - histos.fill(HIST("sel8FT0A/MultvsPV"), collision.multZeqFT0A() + collision.multZeqFT0C(), collision.multNTracksPV()); - } - } - } - break; - case kCentFT0Cs: - if constexpr (enableCentFT0) { - const float perC = populateTable(centFT0C, ft0cInfo, collision.multZeqFT0C()); - if (produceHistograms.value) { - histos.fill(HIST("FT0C/percentile"), perC); - histos.fill(HIST("FT0C/percentilevsPV"), perC, collision.multNTracksPV()); - histos.fill(HIST("FT0C/MultvsPV"), collision.multZeqFT0A() + collision.multZeqFT0C(), collision.multNTracksPV()); - if (collision.sel8()) { - histos.fill(HIST("sel8FT0C/percentile"), perC); - histos.fill(HIST("sel8FT0C/percentilevsPV"), perC, collision.multNTracksPV()); - histos.fill(HIST("sel8FT0C/MultvsPV"), collision.multZeqFT0A() + collision.multZeqFT0C(), collision.multNTracksPV()); - } - } - } - break; - case kCentFT0CVariant1s: - if constexpr (enableCentFT0) { - populateTable(centFT0CVariant1, ft0cVariant1Info, collision.multZeqFT0C()); - } - break; - case kCentFDDMs: - if constexpr (enableCentFDD) { - populateTable(centFDDM, fddmInfo, collision.multZeqFDDA() + collision.multZeqFDDC()); - } - break; - case kCentNTPVs: - if constexpr (enableCentNTPV) { - populateTable(centNTPV, ntpvInfo, collision.multZeqNTracksPV()); - } - break; - case kCentNGlobals: - if constexpr (enableCentNGlobal) { - populateTable(centNGlobals, nGlobalInfo, collision.multNTracksGlobal()); - } - break; - case kCentMFTs: - if constexpr (enableCentMFT) { - populateTable(centMFTs, mftInfo, collision.mftNtracks()); - } - break; - default: - LOGF(fatal, "Table %d not supported in Run3", table); - break; - } - } - } - } - - void processRun3Complete(soa::Join const& collisions, BCsWithTimestamps const&) - { - produceRun3Tables(collisions); - } - - void processRun3(soa::Join const& collisions, BCsWithTimestamps const&) - { - produceRun3Tables(collisions); - } - - void processRun3FT0(soa::Join const& collisions, BCsWithTimestamps const&) - { - produceRun3Tables(collisions); - } - - // Process switches - PROCESS_SWITCH(CentralityTable, processRun2, "Provide Run2 calibrated centrality/multiplicity percentiles tables", true); - PROCESS_SWITCH(CentralityTable, processRun3Complete, "Provide Run3 calibrated centrality/multiplicity percentiles tables using MFT and global tracks (requires extra subscriptions)", false); - PROCESS_SWITCH(CentralityTable, processRun3, "Provide Run3 calibrated centrality/multiplicity percentiles tables", false); - PROCESS_SWITCH(CentralityTable, processRun3FT0, "Provide Run3 calibrated centrality/multiplicity percentiles tables for FT0 only", false); -}; - -WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) -{ - metadataInfo.initMetadata(cfgc); - return WorkflowSpec{adaptAnalysisTask(cfgc)}; -} diff --git a/Common/TableProducer/multiplicityTable.cxx b/Common/TableProducer/multiplicityTable.cxx deleted file mode 100644 index 2c9ff5df025..00000000000 --- a/Common/TableProducer/multiplicityTable.cxx +++ /dev/null @@ -1,844 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. -// -/// \file multiplicityTable.cxx -/// \brief Produces multiplicity tables -/// -/// \author ALICE -/// - -#include "PWGMM/Mult/DataModel/bestCollisionTable.h" - -#include "Common/Core/MetadataHelper.h" -#include "Common/Core/TableHelper.h" -#include "Common/DataModel/EventSelection.h" -#include "Common/DataModel/Multiplicity.h" -#include "Common/DataModel/TrackSelectionTables.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -using namespace o2; -using namespace o2::framework; -using namespace o2::framework::expressions; - -o2::common::core::MetadataHelper metadataInfo; // Metadata helper - -static constexpr int kFV0Mults = 0; -static constexpr int kFT0Mults = 1; -static constexpr int kFDDMults = 2; -static constexpr int kZDCMults = 3; -static constexpr int kTrackletMults = 4; -static constexpr int kTPCMults = 5; -static constexpr int kPVMults = 6; -static constexpr int kMultsExtra = 7; -static constexpr int kMultSelections = 8; -static constexpr int kFV0MultZeqs = 9; -static constexpr int kFT0MultZeqs = 10; -static constexpr int kFDDMultZeqs = 11; -static constexpr int kPVMultZeqs = 12; -static constexpr int kMultMCExtras = 13; -static constexpr int Ntables = 14; - -// Checking that the Zeq tables are after the normal ones -static_assert(kFV0Mults < kFV0MultZeqs); -static_assert(kFT0Mults < kFT0MultZeqs); -static_assert(kFDDMults < kFDDMultZeqs); -static_assert(kPVMults < kPVMultZeqs); - -static constexpr int Nparameters = 1; -static const std::vector tableNames{"FV0Mults", // 0 - "FT0Mults", // 1 - "FDDMults", // 2 - "ZDCMults", // 3 - "TrackletMults", // 4 - "TPCMults", // 5 - "PVMults", // 6 - "MultsExtra", // 7 - "MultSelections", // 8 - "FV0MultZeqs", // 9 - "FT0MultZeqs", // 10 - "FDDMultZeqs", // 11 - "PVMultZeqs", // 12 - "MultMCExtras"}; // 13 -static const std::vector parameterNames{"Enable"}; -static const int defaultParameters[Ntables][Nparameters]{{-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}}; - -struct MultiplicityTable { - SliceCache cache; - Produces tableFV0; // 0 - Produces tableFV0AOuter; // 0-bis (produced with FV0) - Produces tableFT0; // 1 - Produces tableFDD; // 2 - Produces tableZDC; // 3 - Produces tableTracklet; // 4 - Produces tableTpc; // 5 - Produces tablePv; // 6 - Produces tableExtra; // 7 - Produces multSelections; // 8 - Produces tableFV0Zeqs; // 9 - Produces tableFT0Zeqs; // 10 - Produces tableFDDZeqs; // 11 - Produces tablePVZeqs; // 12 - Produces tableExtraMc; // 13 - Produces tableExtraMult2MCExtras; - Produces multHepMCHIs; // Not accounted for, produced using custom process function to avoid dependencies - Produces mftMults; // Not accounted for, produced using custom process function to avoid dependencies - Produces multsGlobal; // Not accounted for, produced based on process function processGlobalTrackingCounters - - // For vertex-Z corrections in calibration - Service ccdb; - Service pdg; - - using Run2Tracks = soa::Join; - Partition run2tracklets = (aod::track::trackType == static_cast(o2::aod::track::TrackTypeEnum::Run2Tracklet)); - Partition tracksWithTPC = (aod::track::tpcNClsFindable > (uint8_t)0); - Partition pvContribTracks = (nabs(aod::track::eta) < 0.8f) && ((aod::track::flags & static_cast(o2::aod::track::PVContributor)) == static_cast(o2::aod::track::PVContributor)); - Partition pvContribTracksEta1 = (nabs(aod::track::eta) < 1.0f) && ((aod::track::flags & static_cast(o2::aod::track::PVContributor)) == static_cast(o2::aod::track::PVContributor)); - Preslice perCol = aod::track::collisionId; - Preslice perColIU = aod::track::collisionId; - Preslice perCollisionMFT = o2::aod::fwdtrack::collisionId; - - using BCsWithRun3Matchings = soa::Join; - - // Configurable - Configurable doVertexZeq{"doVertexZeq", 1, "if 1: do vertex Z eq mult table"}; - Configurable fractionOfEvents{"fractionOfEvents", 2.0, "Fractions of events to keep in case the QA is used"}; - Configurable> enabledTables{"enabledTables", - {defaultParameters[0], Ntables, Nparameters, tableNames, parameterNames}, - "Produce tables depending on needs. Values different than -1 override the automatic setup: the corresponding table can be set off (0) or on (1)"}; - - struct : ConfigurableGroup { - Configurable ccdburl{"ccdburl", "http://alice-ccdb.cern.ch", "The CCDB endpoint url address"}; - Configurable ccdbPath{"ccdbPath", "Centrality/Calibration", "The CCDB path for centrality/multiplicity information"}; - Configurable reconstructionPass{"reconstructionPass", "", {"Apass to use when fetching the calibration tables. Empty (default) does not check for any pass. Use `metadata` to fetch it from the AO2D metadata. Otherwise it will override the metadata."}}; - } ccdbConfig; - - Configurable produceHistograms{"produceHistograms", false, {"Option to produce debug histograms"}}; - Configurable autoSetupFromMetadata{"autoSetupFromMetadata", true, {"Autosetup the Run 2 and Run 3 processing from the metadata"}}; - - int mRunNumber; - bool lCalibLoaded; - TList* lCalibObjects; - TProfile* hVtxZFV0A; - TProfile* hVtxZFT0A; - TProfile* hVtxZFT0C; - TProfile* hVtxZFDDA; - - TProfile* hVtxZFDDC; - TProfile* hVtxZNTracks; - std::vector mEnabledTables; // Vector of enabled tables - - // Debug output - HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::QAObject}; - OutputObj listCalib{"calib-list", OutputObjHandlingPolicy::QAObject}; - - unsigned int randomSeed = 0; - void init(InitContext& context) - { - // If both Run 2 and Run 3 data process flags are enabled then we check the metadata - if (autoSetupFromMetadata && metadataInfo.isFullyDefined()) { - LOG(info) << "Autosetting the processing from the metadata"; - if (doprocessRun2 == true && doprocessRun3 == true) { - if (metadataInfo.isRun3()) { - doprocessRun2.value = false; - } else { - doprocessRun3.value = false; - } - } - } - - randomSeed = static_cast(std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count()); - if (doprocessRun2 == false && doprocessRun3 == false) { - LOGF(fatal, "Neither processRun2 nor processRun3 enabled. Please choose one."); - } - if (doprocessRun2 == true && doprocessRun3 == true) { - LOGF(fatal, "Cannot enable processRun2 and processRun3 at the same time. Please choose one."); - } - - bool tEnabled[Ntables] = {false}; - for (int i = 0; i < Ntables; i++) { - int f = enabledTables->get(tableNames[i].c_str(), "Enable"); - o2::common::core::enableFlagIfTableRequired(context, tableNames[i], f); - if (f == 1) { - tEnabled[i] = true; - mEnabledTables.push_back(i); - if (fractionOfEvents <= 1.f && (tableNames[i] != "MultsExtra")) { - LOG(fatal) << "Cannot have a fraction of events <= 1 and multiplicity table consumed."; - } - } - } - // Handle the custom cases. - if (tEnabled[kMultMCExtras]) { - if (enabledTables->get(tableNames[kMultMCExtras].c_str(), "Enable") == -1) { - doprocessMC.value = true; - LOG(info) << "Enabling MC processing due to " << tableNames[kMultMCExtras] << " table being enabled."; - } - } - - // Check that the tables are enabled consistenly - if (tEnabled[kFV0MultZeqs] && !tEnabled[kFV0Mults]) { // FV0 - mEnabledTables.push_back(kFV0Mults); - LOG(info) << "Cannot have the " << tableNames[kFV0MultZeqs] << " table enabled and not the one on " << tableNames[kFV0Mults] << ". Enabling it."; - } - if (tEnabled[kFT0MultZeqs] && !tEnabled[kFT0Mults]) { // FT0 - mEnabledTables.push_back(kFT0Mults); - LOG(info) << "Cannot have the " << tableNames[kFT0MultZeqs] << " table enabled and not the one on " << tableNames[kFT0Mults] << ". Enabling it."; - } - if (tEnabled[kFDDMultZeqs] && !tEnabled[kFDDMults]) { // FDD - mEnabledTables.push_back(kFDDMults); - LOG(info) << "Cannot have the " << tableNames[kFDDMultZeqs] << " table enabled and not the one on " << tableNames[kFDDMults] << ". Enabling it."; - } - if (tEnabled[kPVMultZeqs] && !tEnabled[kPVMults]) { // PV - mEnabledTables.push_back(kPVMults); - LOG(info) << "Cannot have the " << tableNames[kPVMultZeqs] << " table enabled and not the one on " << tableNames[kPVMults] << ". Enabling it."; - } - std::sort(mEnabledTables.begin(), mEnabledTables.end()); - - mRunNumber = 0; - lCalibLoaded = false; - lCalibObjects = nullptr; - hVtxZFV0A = nullptr; - hVtxZFT0A = nullptr; - hVtxZFT0C = nullptr; - hVtxZFDDA = nullptr; - hVtxZFDDC = nullptr; - hVtxZNTracks = nullptr; - - ccdb->setURL(ccdbConfig.ccdburl); - ccdb->setCaching(true); - ccdb->setLocalObjectValidityChecking(); - ccdb->setFatalWhenNull(false); // don't fatal, please - exception is caught explicitly (as it should) - - listCalib.setObject(new TList); - if (!produceHistograms.value) { - return; - } - histos.add("FT0A", "FT0A vs FT0A eq.", HistType::kTH2D, {{1000, 0, 1000, "FT0A multiplicity"}, {1000, 0, 1000, "FT0A multiplicity eq."}}); - histos.add("FT0C", "FT0C vs FT0C eq.", HistType::kTH2D, {{1000, 0, 1000, "FT0C multiplicity"}, {1000, 0, 1000, "FT0C multiplicity eq."}}); - histos.add("FT0CMultvsPV", "FT0C vs mult.", HistType::kTH2D, {{1000, 0, 1000, "FT0C mult."}, {100, 0, 100, "PV mult."}}); - histos.add("FT0AMultvsPV", "FT0A vs mult.", HistType::kTH2D, {{1000, 0, 1000, "FT0A mult."}, {100, 0, 100, "PV mult."}}); - } - - /// Dummy process function for BCs, needed in case both Run2 and Run3 process functions are disabled - void process(aod::BCs const&) {} - - void processRun2(aod::Run2MatchedSparse::iterator const& collision, - Run2Tracks const&, - aod::BCs const&, - aod::Zdcs const&, - aod::FV0As const&, - aod::FV0Cs const&, - aod::FT0s const&) - { - float multFV0A = 0.f; - float multFV0C = 0.f; - float multFT0A = 0.f; - float multFT0C = 0.f; - float multFDDA = 0.f; - float multFDDC = 0.f; - float multZNA = 0.f; - float multZNC = 0.f; - - auto trackletsGrouped = run2tracklets->sliceByCached(aod::track::collisionId, collision.globalIndex(), cache); - auto tracksGrouped = tracksWithTPC->sliceByCached(aod::track::collisionId, collision.globalIndex(), cache); - int multTracklets = trackletsGrouped.size(); - int multTPC = tracksGrouped.size(); - int multNContribs = 0; - int multNContribsEta1 = 0; - int multNContribsEtaHalf = 0; - - if (collision.has_fv0a()) { - for (const auto& amplitude : collision.fv0a().amplitude()) { - multFV0A += amplitude; - } - } - if (collision.has_fv0c()) { - for (const auto& amplitude : collision.fv0c().amplitude()) { - multFV0C += amplitude; - } - } - if (collision.has_ft0()) { - auto ft0 = collision.ft0(); - for (const auto& amplitude : ft0.amplitudeA()) { - multFT0A += amplitude; - } - for (const auto& amplitude : ft0.amplitudeC()) { - multFT0C += amplitude; - } - } - if (collision.has_zdc()) { - auto zdc = collision.zdc(); - multZNA = zdc.energyCommonZNA(); - multZNC = zdc.energyCommonZNC(); - } - - // Try to do something Similar to https://github.com/alisw/AliPhysics/blob/22862a945004f719f8e9664c0264db46e7186a48/OADB/AliPPVsMultUtils.cxx#L541C26-L541C37 - for (const auto& tracklet : trackletsGrouped) { - if (std::abs(tracklet.eta()) < 1.0) { - multNContribsEta1++; - } - if (std::abs(tracklet.eta()) < 0.8) { - multNContribs++; - } - if (std::abs(tracklet.eta()) < 0.5) { - multNContribsEtaHalf++; - } - } - - LOGF(debug, "multFV0A=%5.0f multFV0C=%5.0f multFT0A=%5.0f multFT0C=%5.0f multFDDA=%5.0f multFDDC=%5.0f multZNA=%6.0f multZNC=%6.0f multTracklets=%i multTPC=%i multNContribsEta1=%i multNContribs=%i multNContribsEtaHalf=%i", multFV0A, multFV0C, multFT0A, multFT0C, multFDDA, multFDDC, multZNA, multZNC, multTracklets, multTPC, multNContribs, multNContribsEta1, multNContribsEtaHalf); - tableFV0(multFV0A, multFV0C); - tableFT0(multFT0A, multFT0C); - tableFDD(multFDDA, multFDDC); - tableZDC(multZNA, multZNC, 0.0f, 0.0f, 0.0f, 0.0f); - tableTracklet(multTracklets); - tableTpc(multTPC); - tablePv(multNContribs, multNContribsEta1, multNContribsEtaHalf); - } - - using Run3TracksIU = soa::Join; - Partition tracksIUWithTPC = (aod::track::tpcNClsFindable > (uint8_t)0); - Partition pvAllContribTracksIU = ((aod::track::flags & static_cast(o2::aod::track::PVContributor)) == static_cast(o2::aod::track::PVContributor)); - Partition pvContribTracksIU = (nabs(aod::track::eta) < 0.8f) && ((aod::track::flags & static_cast(o2::aod::track::PVContributor)) == static_cast(o2::aod::track::PVContributor)); - Partition pvContribTracksIUEta1 = (nabs(aod::track::eta) < 1.0f) && ((aod::track::flags & static_cast(o2::aod::track::PVContributor)) == static_cast(o2::aod::track::PVContributor)); - Partition pvContribTracksIUEtaHalf = (nabs(aod::track::eta) < 0.5f) && ((aod::track::flags & static_cast(o2::aod::track::PVContributor)) == static_cast(o2::aod::track::PVContributor)); - - void processRun3(soa::Join const& collisions, - Run3TracksIU const&, - BCsWithRun3Matchings const&, - aod::Zdcs const&, - aod::FV0As const&, - aod::FT0s const&, - aod::FDDs const&) - { - // reserve memory - for (const auto& i : mEnabledTables) { - switch (i) { - case kFV0Mults: // FV0 - tableFV0.reserve(collisions.size()); - tableFV0AOuter.reserve(collisions.size()); - break; - case kFT0Mults: // FT0 - tableFT0.reserve(collisions.size()); - break; - case kFDDMults: // FDD - tableFDD.reserve(collisions.size()); - break; - case kZDCMults: // ZDC - tableZDC.reserve(collisions.size()); - break; - case kTrackletMults: // Tracklets (Run 2 only, nothing to do) (to be removed!) - tableTracklet.reserve(collisions.size()); - break; - case kTPCMults: // TPC - tableTpc.reserve(collisions.size()); - break; - case kPVMults: // PV multiplicity - tablePv.reserve(collisions.size()); - break; - case kMultsExtra: // Extra information - tableExtra.reserve(collisions.size()); - break; - case kMultSelections: // Extra information - multSelections.reserve(collisions.size()); - break; - case kFV0MultZeqs: // Equalized multiplicity for FV0 - tableFV0Zeqs.reserve(collisions.size()); - break; - case kFT0MultZeqs: // Equalized multiplicity for FT0 - tableFT0Zeqs.reserve(collisions.size()); - break; - case kFDDMultZeqs: // Equalized multiplicity for FDD - tableFDDZeqs.reserve(collisions.size()); - break; - case kPVMultZeqs: // Equalized multiplicity for PV - tablePVZeqs.reserve(collisions.size()); - break; - case kMultMCExtras: // MC extra information (nothing to do in the data) - break; - default: - LOG(fatal) << "Unknown table requested: " << i; - break; - } - } - - // Initializing multiplicity values - float multFV0A = 0.f; - float multFV0AOuter = 0.f; - float multFV0C = 0.f; - float multFT0A = 0.f; - float multFT0C = 0.f; - float multFDDA = 0.f; - float multFDDC = 0.f; - float multZNA = -1.f; - float multZNC = -1.f; - float multZEM1 = -1.f; - float multZEM2 = -1.f; - float multZPA = -1.f; - float multZPC = -1.f; - - float multZeqFV0A = 0.f; - float multZeqFT0A = 0.f; - float multZeqFT0C = 0.f; - float multZeqFDDA = 0.f; - float multZeqFDDC = 0.f; - float multZeqNContribs = 0.f; - - for (auto const& collision : collisions) { - if ((fractionOfEvents < 1.f) && (static_cast(rand_r(&randomSeed)) / static_cast(RAND_MAX)) > fractionOfEvents) { // Skip events that are not sampled (only for the QA) - return; - } - int multNContribs = 0; - int multNContribsEta1 = 0; - int multNContribsEtaHalf = 0; - - /* check the previous run number */ - const auto& bc = collision.bc_as(); - if (doVertexZeq > 0) { - if (bc.runNumber() != mRunNumber) { - mRunNumber = bc.runNumber(); // mark this run as at least tried - if (ccdbConfig.reconstructionPass.value == "") { - lCalibObjects = ccdb->getForRun(ccdbConfig.ccdbPath, mRunNumber); - } else if (ccdbConfig.reconstructionPass.value == "metadata") { - std::map metadata; - metadata["RecoPassName"] = metadataInfo.get("RecoPassName"); - LOGF(info, "Loading CCDB for reconstruction pass (from metadata): %s", metadataInfo.get("RecoPassName")); - lCalibObjects = ccdb->getSpecificForRun(ccdbConfig.ccdbPath, mRunNumber, metadata); - } else { - std::map metadata; - metadata["RecoPassName"] = ccdbConfig.reconstructionPass.value; - LOGF(info, "Loading CCDB for reconstruction pass (from provided argument): %s", ccdbConfig.reconstructionPass.value); - lCalibObjects = ccdb->getSpecificForRun(ccdbConfig.ccdbPath, mRunNumber, metadata); - } - - if (lCalibObjects) { - if (produceHistograms) { - listCalib->Add(lCalibObjects->Clone(Form("%i", bc.runNumber()))); - } - - hVtxZFV0A = static_cast(lCalibObjects->FindObject("hVtxZFV0A")); - hVtxZFT0A = static_cast(lCalibObjects->FindObject("hVtxZFT0A")); - hVtxZFT0C = static_cast(lCalibObjects->FindObject("hVtxZFT0C")); - hVtxZFDDA = static_cast(lCalibObjects->FindObject("hVtxZFDDA")); - hVtxZFDDC = static_cast(lCalibObjects->FindObject("hVtxZFDDC")); - hVtxZNTracks = static_cast(lCalibObjects->FindObject("hVtxZNTracksPV")); - lCalibLoaded = true; - // Capture error - if (!hVtxZFV0A || !hVtxZFT0A || !hVtxZFT0C || !hVtxZFDDA || !hVtxZFDDC || !hVtxZNTracks) { - LOGF(error, "Problem loading CCDB objects! Please check"); - lCalibLoaded = false; - } - } else { - LOGF(error, "Problem loading CCDB object! Please check"); - lCalibLoaded = false; - } - } - } - - for (const auto& i : mEnabledTables) { - switch (i) { - case kFV0Mults: // FV0 - { - multFV0A = 0.f; - multFV0AOuter = 0.f; - multFV0C = 0.f; - // using FV0 row index from event selection task - if (collision.has_foundFV0()) { - const auto& fv0 = collision.foundFV0(); - for (size_t ii = 0; ii < fv0.amplitude().size(); ii++) { - auto amplitude = fv0.amplitude()[ii]; - auto channel = fv0.channel()[ii]; - multFV0A += amplitude; - if (channel > 7) { - multFV0AOuter += amplitude; - } - } - } else { - multFV0A = -999.f; - multFV0C = -999.f; - } - tableFV0(multFV0A, multFV0C); - tableFV0AOuter(multFV0AOuter); - LOGF(debug, "multFV0A=%5.0f multFV0C=%5.0f", multFV0A, multFV0C); - } break; - case kFT0Mults: // FT0 - { - multFT0A = 0.f; - multFT0C = 0.f; - // using FT0 row index from event selection task - if (collision.has_foundFT0()) { - const auto& ft0 = collision.foundFT0(); - for (const auto& amplitude : ft0.amplitudeA()) { - multFT0A += amplitude; - } - for (const auto& amplitude : ft0.amplitudeC()) { - multFT0C += amplitude; - } - } else { - multFT0A = -999.f; - multFT0C = -999.f; - } - tableFT0(multFT0A, multFT0C); - LOGF(debug, "multFT0A=%5.0f multFT0C=%5.0f", multFV0A, multFV0C); - } break; - case kFDDMults: // FDD - { - multFDDA = 0.f; - multFDDC = 0.f; - // using FDD row index from event selection task - if (collision.has_foundFDD()) { - const auto& fdd = collision.foundFDD(); - for (const auto& amplitude : fdd.chargeA()) { - multFDDA += amplitude; - } - for (const auto& amplitude : fdd.chargeC()) { - multFDDC += amplitude; - } - } else { - multFDDA = -999.f; - multFDDC = -999.f; - } - tableFDD(multFDDA, multFDDC); - LOGF(debug, "multFDDA=%5.0f multFDDC=%5.0f", multFDDA, multFDDC); - } break; - case kZDCMults: // ZDC - { - if (bc.has_zdc()) { - multZNA = bc.zdc().amplitudeZNA(); - multZNC = bc.zdc().amplitudeZNC(); - multZEM1 = bc.zdc().amplitudeZEM1(); - multZEM2 = bc.zdc().amplitudeZEM2(); - multZPA = bc.zdc().amplitudeZPA(); - multZPC = bc.zdc().amplitudeZPC(); - } else { - multZNA = -999.f; - multZNC = -999.f; - multZEM1 = -999.f; - multZEM2 = -999.f; - multZPA = -999.f; - multZPC = -999.f; - } - tableZDC(multZNA, multZNC, multZEM1, multZEM2, multZPA, multZPC); - LOGF(debug, "multZNA=%6.0f multZNC=%6.0f", multZNA, multZNC); - } break; - case kTrackletMults: // Tracklets (only Run2) nothing to do (to be removed!) - { - tableTracklet(0); - } break; - case kTPCMults: // TPC - { - const auto& tracksGrouped = tracksIUWithTPC->sliceByCached(aod::track::collisionId, collision.globalIndex(), cache); - const int multTPC = tracksGrouped.size(); - tableTpc(multTPC); - LOGF(debug, "multTPC=%i", multTPC); - } break; - case kPVMults: // PV multiplicity - { - // use only one single grouping operation, then do loop - const auto& tracksThisCollision = pvContribTracksIUEta1.sliceByCached(aod::track::collisionId, collision.globalIndex(), cache); - multNContribsEta1 = tracksThisCollision.size(); - for (const auto& track : tracksThisCollision) { - if (std::abs(track.eta()) < 0.8) { - multNContribs++; - } - if (std::abs(track.eta()) < 0.5) { - multNContribsEtaHalf++; - } - } - - tablePv(multNContribs, multNContribsEta1, multNContribsEtaHalf); - LOGF(debug, "multNContribs=%i, multNContribsEta1=%i, multNContribsEtaHalf=%i", multNContribs, multNContribsEta1, multNContribsEtaHalf); - } break; - case kMultsExtra: // Extra - { - int nHasITS = 0, nHasTPC = 0, nHasTOF = 0, nHasTRD = 0; - int nITSonly = 0, nTPConly = 0, nITSTPC = 0; - const auto& pvAllContribsGrouped = pvAllContribTracksIU->sliceByCached(aod::track::collisionId, collision.globalIndex(), cache); - const auto& tpcTracksGrouped = tracksIUWithTPC->sliceByCached(aod::track::collisionId, collision.globalIndex(), cache); - - for (const auto& track : pvAllContribsGrouped) { - if (track.hasITS()) { - nHasITS++; - if (track.hasTPC()) - nITSTPC++; - if (!track.hasTPC() && !track.hasTOF() && !track.hasTRD()) - nITSonly++; - } - if (track.hasTPC()) { - nHasTPC++; - if (!track.hasITS() && !track.hasTOF() && !track.hasTRD()) - nTPConly++; - } - if (track.hasTOF()) - nHasTOF++; - if (track.hasTRD()) - nHasTRD++; - } - - int nAllTracksTPCOnly = 0; - int nAllTracksITSTPC = 0; - for (const auto& track : tpcTracksGrouped) { - if (track.hasITS()) { - nAllTracksITSTPC++; - } else { - nAllTracksTPCOnly++; - } - } - - tableExtra(collision.numContrib(), collision.chi2(), collision.collisionTimeRes(), - mRunNumber, collision.posZ(), collision.sel8(), - nHasITS, nHasTPC, nHasTOF, nHasTRD, nITSonly, nTPConly, nITSTPC, - nAllTracksTPCOnly, nAllTracksITSTPC, - collision.trackOccupancyInTimeRange(), - collision.ft0cOccupancyInTimeRange(), - collision.flags()); - } break; - case kMultSelections: // Multiplicity selections - { - multSelections(collision.selection_raw()); - } break; - case kFV0MultZeqs: // Z equalized FV0 - { - if (std::fabs(collision.posZ()) < 15.0f && lCalibLoaded) { - multZeqFV0A = hVtxZFV0A->Interpolate(0.0) * multFV0A / hVtxZFV0A->Interpolate(collision.posZ()); - } - tableFV0Zeqs(multZeqFV0A); - } break; - case kFT0MultZeqs: // Z equalized FT0 - { - if (std::fabs(collision.posZ()) < 15.0f && lCalibLoaded) { - multZeqFT0A = hVtxZFT0A->Interpolate(0.0) * multFT0A / hVtxZFT0A->Interpolate(collision.posZ()); - multZeqFT0C = hVtxZFT0C->Interpolate(0.0) * multFT0C / hVtxZFT0C->Interpolate(collision.posZ()); - } - if (produceHistograms.value) { - histos.fill(HIST("FT0A"), multFT0A, multZeqFT0A); - histos.fill(HIST("FT0C"), multFT0C, multZeqFT0C); - histos.fill(HIST("FT0AMultvsPV"), multZeqFT0A, multNContribs); - histos.fill(HIST("FT0CMultvsPV"), multZeqFT0C, multNContribs); - } - tableFT0Zeqs(multZeqFT0A, multZeqFT0C); - } break; - case kFDDMultZeqs: // Z equalized FDD - { - if (std::fabs(collision.posZ()) < 15.0f && lCalibLoaded) { - multZeqFDDA = hVtxZFDDA->Interpolate(0.0) * multFDDA / hVtxZFDDA->Interpolate(collision.posZ()); - multZeqFDDC = hVtxZFDDC->Interpolate(0.0) * multFDDC / hVtxZFDDC->Interpolate(collision.posZ()); - } - tableFDDZeqs(multZeqFDDA, multZeqFDDC); - } break; - case kPVMultZeqs: // Z equalized PV - { - if (std::fabs(collision.posZ()) < 15.0f && lCalibLoaded) { - multZeqNContribs = hVtxZNTracks->Interpolate(0.0) * multNContribs / hVtxZNTracks->Interpolate(collision.posZ()); - } - tablePVZeqs(multZeqNContribs); - } break; - case kMultMCExtras: // MC only (nothing to do) - { - } break; - default: // Default - { - LOG(fatal) << "Unknown table requested: " << i; - } break; - } - } - } - } - - // one loop better than multiple sliceby calls - // FIT FT0C: -3.3 < η < -2.1 - // FOT FT0A: 3.5 < η < 4.9 - Filter mcParticleFilter = (aod::mcparticle::eta < 7.0f) && (aod::mcparticle::eta > -7.0f); - using McParticlesFiltered = soa::Filtered; - - void processMC(aod::McCollision const& mcCollision, McParticlesFiltered const& mcParticles) - { - int multFT0A = 0; - int multFV0A = 0; - int multFT0C = 0; - int multFDDA = 0; - int multFDDC = 0; - int multBarrelEta05 = 0; - int multBarrelEta08 = 0; - int multBarrelEta10 = 0; - for (auto const& mcPart : mcParticles) { - if (!mcPart.isPhysicalPrimary()) { - continue; - } - - auto charge = 0.; - auto* p = pdg->GetParticle(mcPart.pdgCode()); - if (p != nullptr) { - charge = p->Charge(); - } - if (std::abs(charge) < 1e-3) { - continue; // reject neutral particles in counters - } - - if (std::abs(mcPart.eta()) < 1.0) { - multBarrelEta10++; - if (std::abs(mcPart.eta()) < 0.8) { - multBarrelEta08++; - if (std::abs(mcPart.eta()) < 0.5) { - multBarrelEta05++; - } - } - } - if (-3.3 < mcPart.eta() && mcPart.eta() < -2.1) - multFT0C++; - if (3.5 < mcPart.eta() && mcPart.eta() < 4.9) - multFT0A++; - if (2.2 < mcPart.eta() && mcPart.eta() < 5.0) - multFV0A++; - if (-6.9 < mcPart.eta() && mcPart.eta() < -4.9) - multFDDC++; - if (4.7 < mcPart.eta() && mcPart.eta() < 6.3) - multFDDA++; - } - tableExtraMc(multFT0A, multFT0C, multFV0A, multFDDA, multFDDC, multBarrelEta05, multBarrelEta08, multBarrelEta10, mcCollision.posZ()); - } - - void processMC2Mults(soa::Join::iterator const& collision) - { - tableExtraMult2MCExtras(collision.mcCollisionId()); // interlink - } - - Configurable minPtGlobalTrack{"minPtGlobalTrack", 0.15, "min. pT for global tracks"}; - Configurable maxPtGlobalTrack{"maxPtGlobalTrack", 1e+10, "max. pT for global tracks"}; - Configurable minNclsITSGlobalTrack{"minNclsITSGlobalTrack", 5, "min. number of ITS clusters for global tracks"}; - Configurable minNclsITSibGlobalTrack{"minNclsITSibGlobalTrack", 1, "min. number of ITSib clusters for global tracks"}; - - using Run3Tracks = soa::Join; - Partition pvContribGlobalTracksEta1 = (minPtGlobalTrack < aod::track::pt && aod::track::pt < maxPtGlobalTrack) && (nabs(aod::track::eta) < 1.0f) && ((aod::track::flags & static_cast(o2::aod::track::PVContributor)) == static_cast(o2::aod::track::PVContributor)) && requireQualityTracksInFilter(); - - void processHepMCHeavyIons(aod::HepMCHeavyIons const& hepmchis) - { - for (auto const& hepmchi : hepmchis) { - multHepMCHIs(hepmchi.mcCollisionId(), - hepmchi.ncollHard(), - hepmchi.npartProj(), - hepmchi.npartTarg(), - hepmchi.ncoll(), - hepmchi.impactParameter()); - } - } - - void processGlobalTrackingCounters(aod::Collision const& collision, soa::Join const& tracksIU, Run3Tracks const&) - { - // counter from Igor - int nGlobalTracks = 0; - int multNbrContribsEta05GlobalTrackWoDCA = 0; - int multNbrContribsEta08GlobalTrackWoDCA = 0; - int multNbrContribsEta10GlobalTrackWoDCA = 0; - - auto pvContribGlobalTracksEta1PerCollision = pvContribGlobalTracksEta1->sliceByCached(aod::track::collisionId, collision.globalIndex(), cache); - - for (const auto& track : pvContribGlobalTracksEta1PerCollision) { - if (track.itsNCls() < minNclsITSGlobalTrack || track.itsNClsInnerBarrel() < minNclsITSibGlobalTrack) { - continue; - } - multNbrContribsEta10GlobalTrackWoDCA++; - - if (std::abs(track.eta()) < 0.8) { - multNbrContribsEta08GlobalTrackWoDCA++; - } - if (std::abs(track.eta()) < 0.5) { - multNbrContribsEta05GlobalTrackWoDCA++; - } - } - - for (const auto& track : tracksIU) { - if (std::fabs(track.eta()) < 0.8 && track.tpcNClsFound() >= 80 && track.tpcNClsCrossedRows() >= 100) { - if (track.isGlobalTrack()) { - nGlobalTracks++; - } - } - } - - LOGF(debug, "nGlobalTracks = %d, multNbrContribsEta08GlobalTrackWoDCA = %d, multNbrContribsEta10GlobalTrackWoDCA = %d, multNbrContribsEta05GlobalTrackWoDCA = %d", nGlobalTracks, multNbrContribsEta08GlobalTrackWoDCA, multNbrContribsEta10GlobalTrackWoDCA, multNbrContribsEta05GlobalTrackWoDCA); - - multsGlobal(nGlobalTracks, multNbrContribsEta08GlobalTrackWoDCA, multNbrContribsEta10GlobalTrackWoDCA, multNbrContribsEta05GlobalTrackWoDCA); - } - - void processRun3MFT(soa::Join::iterator const&, - o2::aod::MFTTracks const& mftTracks, - soa::SmallGroups const& retracks) - { - int nAllTracks = 0; - int nTracks = 0; - - for (const auto& track : mftTracks) { - if (track.nClusters() >= 5) { // hardcoded for now - nAllTracks++; - } - } - - if (retracks.size() > 0) { - for (const auto& retrack : retracks) { - auto track = retrack.mfttrack(); - if (track.nClusters() < 5) { - continue; // min cluster requirement - } - if ((track.eta() > -2.0f) && (track.eta() < -3.9f)) { - continue; // too far to be of true interest - } - if (std::abs(retrack.bestDCAXY()) > 2.0f) { - continue; // does not point to PV properly - } - nTracks++; - } - } - mftMults(nAllTracks, nTracks); - } - - // Process switches - PROCESS_SWITCH(MultiplicityTable, processRun2, "Produce Run 2 multiplicity tables. Autoset if both processRun2 and processRun3 are enabled", true); - PROCESS_SWITCH(MultiplicityTable, processRun3, "Produce Run 3 multiplicity tables. Autoset if both processRun2 and processRun3 are enabled", true); - PROCESS_SWITCH(MultiplicityTable, processGlobalTrackingCounters, "Produce Run 3 global counters", false); - PROCESS_SWITCH(MultiplicityTable, processMC, "Produce MC multiplicity tables", false); - PROCESS_SWITCH(MultiplicityTable, processMC2Mults, "Produce MC -> Mult map", false); - PROCESS_SWITCH(MultiplicityTable, processHepMCHeavyIons, "Produce MultHepMCHIs tables", false); - PROCESS_SWITCH(MultiplicityTable, processRun3MFT, "Produce MFT mult tables", false); -}; - -WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) -{ - // Parse the metadata - metadataInfo.initMetadata(cfgc); - return WorkflowSpec{adaptAnalysisTask(cfgc)}; -} diff --git a/Common/TableProducer/timestamp.cxx b/Common/TableProducer/timestamp.cxx deleted file mode 100644 index 30ad84150c5..00000000000 --- a/Common/TableProducer/timestamp.cxx +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -/// -/// \file timestamp.cxx -/// \author Nicolò Jacazio -/// \since 2020-06-22 -/// \brief A task to fill the timestamp table from run number. -/// Uses headers from CCDB -/// -#include "Common/Core/MetadataHelper.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -using namespace o2::framework; -using namespace o2::header; -using namespace o2; - -o2::common::core::MetadataHelper metadataInfo; // Metadata helper - -struct TimestampTask { - Produces timestampTable; /// Table with SOR timestamps produced by the task - Service ccdb; /// CCDB manager to access orbit-reset timestamp - o2::ccdb::CcdbApi ccdb_api; /// API to access CCDB headers - Configurable fatalOnInvalidTimestamp{"fatalOnInvalidTimestamp", false, "Generate fatal error for invalid timestamps"}; - std::map mapRunToOrbitReset; /// Cache of orbit reset timestamps - std::map> mapRunToRunDuration; /// Cache of run duration timestamps - int lastRunNumber = 0; /// Last run number processed - int64_t orbitResetTimestamp = 0; /// Orbit-reset timestamp in us - std::pair runDuration; /// Pair of SOR and EOR timestamps - - // Configurables - Configurable verbose{"verbose", false, "verbose mode"}; - Configurable rct_path{"rct-path", "RCT/Info/RunInformation", "path to the ccdb RCT objects for the SOR timestamps"}; - Configurable orbit_reset_path{"orbit-reset-path", "CTP/Calib/OrbitReset", "path to the ccdb orbit-reset objects"}; - Configurable url{"ccdb-url", "http://alice-ccdb.cern.ch", "URL of the CCDB database"}; - Configurable isRun2MC{"isRun2MC", -1, "Running mode: enable only for Run 2 MC. Timestamps are set to SOR timestamp. Default: -1 (autoset from metadata) 0 (Standard) 1 (Run 2 MC)"}; - - void init(o2::framework::InitContext&) - { - LOGF(info, "Initializing TimestampTask"); - ccdb->setURL(url.value); // Setting URL of CCDB manager from configuration - ccdb_api.init(url.value); - if (!ccdb_api.isHostReachable()) { - LOGF(fatal, "CCDB host %s is not reacheable, cannot go forward", url.value.data()); - } - if (isRun2MC.value == -1) { - if ((!metadataInfo.isRun3()) && metadataInfo.isMC()) { - isRun2MC.value = 1; - LOG(info) << "Autosetting the Run2 MC mode based on metadata"; - } else { - isRun2MC.value = 0; - } - } - } - - void process(aod::BC const& bc) - { - int runNumber = bc.runNumber(); - // We need to set the orbit-reset timestamp for the run number. - // This is done with caching if the run number was already processed before. - // If not the orbit-reset timestamp for the run number is queried from CCDB and added to the cache - if (runNumber == lastRunNumber) { // The run number coincides to the last run processed - LOGF(debug, "Using orbit-reset timestamp from last call"); - } else if (mapRunToOrbitReset.count(runNumber)) { // The run number was already requested before: getting it from cache! - LOGF(debug, "Getting orbit-reset timestamp from cache"); - orbitResetTimestamp = mapRunToOrbitReset[runNumber]; - runDuration = mapRunToRunDuration[runNumber]; - } else { // The run was not requested before: need to acccess CCDB! - LOGF(debug, "Getting start-of-run and end-of-run timestamps from CCDB"); - runDuration = ccdb->getRunDuration(runNumber, true); /// fatalise if timestamps are not found - int64_t sorTimestamp = runDuration.first; // timestamp of the SOR/SOX/STF in ms - int64_t eorTimestamp = runDuration.second; // timestamp of the EOR/EOX/ETF in ms - - const bool isUnanchoredRun3MC = runNumber >= 300000 && runNumber < 500000; - if (isRun2MC.value == 1 || isUnanchoredRun3MC) { - // isRun2MC: bc/orbit distributions are not simulated in Run2 MC. All bcs are set to 0. - // isUnanchoredRun3MC: assuming orbit-reset is done in the beginning of each run - // Setting orbit-reset timestamp to start-of-run timestamp - orbitResetTimestamp = sorTimestamp * 1000; // from ms to us - } else if (runNumber < 300000) { // Run 2 - LOGF(debug, "Getting orbit-reset timestamp using start-of-run timestamp from CCDB"); - auto ctp = ccdb->getForTimeStamp>(orbit_reset_path.value.data(), sorTimestamp); - orbitResetTimestamp = (*ctp)[0]; - } else { - // sometimes orbit is reset after SOR. Using EOR timestamps for orbitReset query is more reliable - LOGF(debug, "Getting orbit-reset timestamp using end-of-run timestamp from CCDB"); - auto ctp = ccdb->getForTimeStamp>(orbit_reset_path.value.data(), eorTimestamp / 2 + sorTimestamp / 2); - orbitResetTimestamp = (*ctp)[0]; - } - - // Adding the timestamp to the cache map - std::pair::iterator, bool> check; - check = mapRunToOrbitReset.insert(std::pair(runNumber, orbitResetTimestamp)); - if (!check.second) { - LOGF(fatal, "Run number %i already existed with a orbit-reset timestamp of %llu", runNumber, check.first->second); - } - mapRunToRunDuration[runNumber] = runDuration; - LOGF(info, "Add new run number %i with orbit-reset timestamp %llu, SOR: %llu, EOR: %llu to cache", runNumber, orbitResetTimestamp, runDuration.first, runDuration.second); - } - - if (verbose.value) { - LOGF(info, "Orbit-reset timestamp for run number %i found: %llu us", runNumber, orbitResetTimestamp); - } - int64_t timestamp{(orbitResetTimestamp + int64_t(bc.globalBC() * o2::constants::lhc::LHCBunchSpacingNS * 1e-3)) / 1000}; // us -> ms - if (timestamp < runDuration.first || timestamp > runDuration.second) { - if (fatalOnInvalidTimestamp.value) { - LOGF(fatal, "Timestamp %llu us is out of run duration [%llu, %llu] ms", timestamp, runDuration.first, runDuration.second); - } else { - LOGF(debug, "Timestamp %llu us is out of run duration [%llu, %llu] ms", timestamp, runDuration.first, runDuration.second); - } - } - timestampTable(timestamp); - } -}; - -WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) -{ - // Parse the metadata - metadataInfo.initMetadata(cfgc); - - return WorkflowSpec{adaptAnalysisTask(cfgc)}; -} diff --git a/Common/TableProducer/trackPropagation.cxx b/Common/TableProducer/trackPropagation.cxx deleted file mode 100644 index cb27b54210f..00000000000 --- a/Common/TableProducer/trackPropagation.cxx +++ /dev/null @@ -1,377 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -// -// Task to add a table of track parameters propagated to the primary vertex -// - -#include "Common/Core/TableHelper.h" -#include "Common/Core/trackUtilities.h" -#include "Common/DataModel/TrackSelectionTables.h" -#include "Common/Tools/TrackTuner.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - -// The Run 3 AO2D stores the tracks at the point of innermost update. For a track with ITS this is the innermost (or second innermost) -// ITS layer. For a track without ITS, this is the TPC inner wall or for loopers in the TPC even a radius beyond that. -// In order to use the track parameters, the tracks have to be propagated to the collision vertex which is done by this task. -// The task consumes the TracksIU and TracksCovIU tables and produces Tracks and TracksCov to which then the user analysis can subscribe. -// -// This task is not needed for Run 2 converted data. -// There are two versions of the task (see process flags), one producing also the covariance matrix and the other only the tracks table. - -using namespace o2; -using namespace o2::framework; -// using namespace o2::framework::expressions; - -struct TrackPropagation { - Produces tracksParPropagated; - Produces tracksParExtensionPropagated; - - Produces tracksParCovPropagated; - Produces tracksParCovExtensionPropagated; - - Produces tracksDCA; - Produces tracksDCACov; - - Produces tunertable; - - Service ccdb; - - bool fillTracksDCA = false; - bool fillTracksDCACov = false; - int runNumber = -1; - - o2::base::Propagator::MatCorrType matCorr = o2::base::Propagator::MatCorrType::USEMatCorrLUT; - - const o2::dataformats::MeanVertexObject* mMeanVtx = nullptr; - o2::parameters::GRPMagField* grpmag = nullptr; - o2::base::MatLayerCylSet* lut = nullptr; - TrackTuner trackTunerObj; - - Configurable ccdburl{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; - Configurable lutPath{"lutPath", "GLO/Param/MatLUT", "Path of the Lut parametrization"}; - Configurable geoPath{"geoPath", "GLO/Config/GeometryAligned", "Path of the geometry file"}; - Configurable grpmagPath{"grpmagPath", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object"}; - Configurable mVtxPath{"mVtxPath", "GLO/Calib/MeanVertex", "Path of the mean vertex file"}; - Configurable minPropagationRadius{"minPropagationDistance", o2::constants::geom::XTPCInnerRef + 0.1, "Only tracks which are at a smaller radius will be propagated, defaults to TPC inner wall"}; - // for TrackTuner only (MC smearing) - Configurable useTrackTuner{"useTrackTuner", false, "Apply track tuner corrections to MC"}; - Configurable fillTrackTunerTable{"fillTrackTunerTable", false, "flag to fill track tuner table"}; - Configurable trackTunerConfigSource{"trackTunerConfigSource", aod::track_tuner::InputString, "1: input string; 2: TrackTuner Configurables"}; - Configurable trackTunerParams{"trackTunerParams", "debugInfo=0|updateTrackDCAs=1|updateTrackCovMat=1|updateCurvature=0|updateCurvatureIU=0|updatePulls=0|isInputFileFromCCDB=1|pathInputFile=Users/m/mfaggin/test/inputsTrackTuner/PbPb2022|nameInputFile=trackTuner_DataLHC22sPass5_McLHC22l1b2_run529397.root|pathFileQoverPt=Users/h/hsharma/qOverPtGraphs|nameFileQoverPt=D0sigma_Data_removal_itstps_MC_LHC22b1b.root|usePvRefitCorrections=0|qOverPtMC=-1.|qOverPtData=-1.", "TrackTuner parameter initialization (format: =|=)"}; - ConfigurableAxis axisPtQA{"axisPtQA", {VARIABLE_WIDTH, 0.0f, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f, 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f, 1.7f, 1.8f, 1.9f, 2.0f, 2.2f, 2.4f, 2.6f, 2.8f, 3.0f, 3.2f, 3.4f, 3.6f, 3.8f, 4.0f, 4.4f, 4.8f, 5.2f, 5.6f, 6.0f, 6.5f, 7.0f, 7.5f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 17.0f, 19.0f, 21.0f, 23.0f, 25.0f, 30.0f, 35.0f, 40.0f, 50.0f}, "pt axis for QA histograms"}; - OutputObj trackTunedTracks{TH1D("trackTunedTracks", "", 1, 0.5, 1.5), OutputObjHandlingPolicy::AnalysisObject}; - - // OutputObj hDCAxyVsPtRec{TH2F("hDCAxyVsPtRec", ";DCAxy;PtRec", 600, -0.15, 0.15, axisPtQA)}; - // OutputObj hDCAxyVsPtMC{TH2F("hDCAxyVsPtMC", ";DCAxy;PtMC", 600, -0.15, 0.15, axisPtQA)}; - - using TracksIUWithMc = soa::Join; - - HistogramRegistry registry{"registry"}; - - void init(o2::framework::InitContext& initContext) - { - int nEnabledProcesses = 0; - if (doprocessStandard) { - LOG(info) << "Enabling processStandard"; - nEnabledProcesses++; - } - if (doprocessCovarianceMc) { - LOG(info) << "Enabling processCovarianceMc"; - nEnabledProcesses++; - } - - if (doprocessCovariance) { - LOG(info) << "Enabling processCovariance"; - nEnabledProcesses++; - } - - if (doprocessStandardWithPID) { - LOG(info) << "Enabling processStandardWithPID"; - nEnabledProcesses++; - } - if (doprocessCovarianceWithPID) { - LOG(info) << "Enabling processCovarianceWithPID"; - nEnabledProcesses++; - } - if (nEnabledProcesses != 1) { - LOG(fatal) << "Exactly one process flag must be set to true. Please choose one."; - } - // Checking if the tables are requested in the workflow and enabling them - fillTracksDCA = o2::common::core::isTableRequiredInWorkflow(initContext, "TracksDCA"); - fillTracksDCACov = o2::common::core::isTableRequiredInWorkflow(initContext, "TracksDCACov"); - - ccdb->setURL(ccdburl); - ccdb->setCaching(true); - ccdb->setLocalObjectValidityChecking(); - - // Histograms for track tuner - AxisSpec axisBinsDCA = {600, -0.15f, 0.15f, "#it{dca}_{xy} (cm)"}; - registry.add("hDCAxyVsPtRec", "hDCAxyVsPtRec", kTH2F, {axisBinsDCA, axisPtQA}); - registry.add("hDCAxyVsPtMC", "hDCAxyVsPtMC", kTH2F, {axisBinsDCA, axisPtQA}); - registry.add("hDCAzVsPtRec", "hDCAzVsPtRec", kTH2F, {axisBinsDCA, axisPtQA}); - registry.add("hDCAzVsPtMC", "hDCAzVsPtMC", kTH2F, {axisBinsDCA, axisPtQA}); - - /// TrackTuner initialization - if (useTrackTuner) { - std::string outputStringParams = ""; - switch (trackTunerConfigSource) { - case aod::track_tuner::InputString: - outputStringParams = trackTunerObj.configParams(trackTunerParams); - break; - case aod::track_tuner::Configurables: - outputStringParams = trackTunerObj.configParams(); - break; - - default: - LOG(fatal) << "TrackTuner configuration source not defined. Fix it! (Supported options: input string (1); Configurables (2))"; - break; - } - - trackTunerObj.getDcaGraphs(); - trackTunedTracks->SetTitle(outputStringParams.c_str()); - trackTunedTracks->GetXaxis()->SetBinLabel(1, "all tracks"); - } - } - - void initCCDB(aod::BCsWithTimestamps::iterator const& bc) - { - if (runNumber == bc.runNumber()) { - return; - } - - // load matLUT for this timestamp - if (!lut) { - LOG(info) << "Loading material look-up table for timestamp: " << bc.timestamp(); - lut = o2::base::MatLayerCylSet::rectifyPtrFromFile(ccdb->getForTimeStamp(lutPath, bc.timestamp())); - } else { - LOG(info) << "Material look-up table already in place. Not reloading."; - } - - grpmag = ccdb->getForTimeStamp(grpmagPath, bc.timestamp()); - LOG(info) << "Setting magnetic field to current " << grpmag->getL3Current() << " A for run " << bc.runNumber() << " from its GRPMagField CCDB object"; - o2::base::Propagator::initFieldFromGRP(grpmag); - o2::base::Propagator::Instance()->setMatLUT(lut); - mMeanVtx = ccdb->getForTimeStamp(mVtxPath, bc.timestamp()); - runNumber = bc.runNumber(); - } - - // Running variables - std::array mDcaInfo; - o2::dataformats::DCA mDcaInfoCov; - o2::dataformats::VertexBase mVtx; - o2::track::TrackParametrization mTrackPar; - o2::track::TrackParametrizationWithError mTrackParCov; - - template - void fillTrackTables(TTrack const& tracks, - TParticle const&, - aod::Collisions const&, - aod::BCsWithTimestamps const& bcs) - { - if (bcs.size() == 0) { - return; - } - initCCDB(bcs.begin()); - - if constexpr (fillCovMat) { - tracksParCovPropagated.reserve(tracks.size()); - tracksParCovExtensionPropagated.reserve(tracks.size()); - if (fillTracksDCACov) { - tracksDCACov.reserve(tracks.size()); - } - } else { - tracksParPropagated.reserve(tracks.size()); - tracksParExtensionPropagated.reserve(tracks.size()); - if (fillTracksDCA) { - tracksDCA.reserve(tracks.size()); - } - } - - for (auto& track : tracks) { - if constexpr (fillCovMat) { - if (fillTracksDCA || fillTracksDCACov) { - mDcaInfoCov.set(999, 999, 999, 999, 999); - } - setTrackParCov(track, mTrackParCov); - if constexpr (useTrkPid) { - mTrackParCov.setPID(track.pidForTracking()); - } - } else { - if (fillTracksDCA) { - mDcaInfo[0] = 999; - mDcaInfo[1] = 999; - } - setTrackPar(track, mTrackPar); - if constexpr (useTrkPid) { - mTrackPar.setPID(track.pidForTracking()); - } - } - // auto trackParCov = getTrackParCov(track); - aod::track::TrackTypeEnum trackType = (aod::track::TrackTypeEnum)track.trackType(); - // std::array trackPxPyPz; - // std::array trackPxPyPzTuned = {0.0, 0.0, 0.0}; - double q2OverPtNew = -9999.; - // Only propagate tracks which have passed the innermost wall of the TPC (e.g. skipping loopers etc). Others fill unpropagated. - if (track.trackType() == aod::track::TrackIU && track.x() < minPropagationRadius) { - if constexpr (isMc && fillCovMat) { // checking MC and fillCovMat block begins - // bool hasMcParticle = track.has_mcParticle(); - if (useTrackTuner) { - trackTunedTracks->Fill(1); // all tracks - bool hasMcParticle = track.has_mcParticle(); - if (hasMcParticle) { - auto mcParticle = track.mcParticle(); - trackTunerObj.tuneTrackParams(mcParticle, mTrackParCov, matCorr, &mDcaInfoCov, trackTunedTracks); - q2OverPtNew = mTrackParCov.getQ2Pt(); - } - } - } // MC and fillCovMat block ends - bool isPropagationOK = true; - - if (track.has_collision()) { - auto const& collision = track.collision(); - if constexpr (fillCovMat) { - mVtx.setPos({collision.posX(), collision.posY(), collision.posZ()}); - mVtx.setCov(collision.covXX(), collision.covXY(), collision.covYY(), collision.covXZ(), collision.covYZ(), collision.covZZ()); - isPropagationOK = o2::base::Propagator::Instance()->propagateToDCABxByBz(mVtx, mTrackParCov, 2.f, matCorr, &mDcaInfoCov); - } else { - isPropagationOK = o2::base::Propagator::Instance()->propagateToDCABxByBz({collision.posX(), collision.posY(), collision.posZ()}, mTrackPar, 2.f, matCorr, &mDcaInfo); - } - } else { - if constexpr (fillCovMat) { - mVtx.setPos({mMeanVtx->getX(), mMeanVtx->getY(), mMeanVtx->getZ()}); - mVtx.setCov(mMeanVtx->getSigmaX() * mMeanVtx->getSigmaX(), 0.0f, mMeanVtx->getSigmaY() * mMeanVtx->getSigmaY(), 0.0f, 0.0f, mMeanVtx->getSigmaZ() * mMeanVtx->getSigmaZ()); - isPropagationOK = o2::base::Propagator::Instance()->propagateToDCABxByBz(mVtx, mTrackParCov, 2.f, matCorr, &mDcaInfoCov); - } else { - isPropagationOK = o2::base::Propagator::Instance()->propagateToDCABxByBz({mMeanVtx->getX(), mMeanVtx->getY(), mMeanVtx->getZ()}, mTrackPar, 2.f, matCorr, &mDcaInfo); - } - } - if (isPropagationOK) { - trackType = aod::track::Track; - } - // filling some QA histograms for track tuner test purpose - if constexpr (isMc && fillCovMat) { // checking MC and fillCovMat block begins - if (track.has_mcParticle() && isPropagationOK) { - auto mcParticle1 = track.mcParticle(); - // && abs(mcParticle1.pdgCode())==211 - if (mcParticle1.isPhysicalPrimary()) { - registry.fill(HIST("hDCAxyVsPtRec"), mDcaInfoCov.getY(), mTrackParCov.getPt()); - registry.fill(HIST("hDCAxyVsPtMC"), mDcaInfoCov.getY(), mcParticle1.pt()); - registry.fill(HIST("hDCAzVsPtRec"), mDcaInfoCov.getZ(), mTrackParCov.getPt()); - registry.fill(HIST("hDCAzVsPtMC"), mDcaInfoCov.getZ(), mcParticle1.pt()); - } - } - } // MC and fillCovMat block ends - } - // Filling modified Q/Pt values at IU/production point by track tuner in track tuner table - if (useTrackTuner && fillTrackTunerTable) { - tunertable(q2OverPtNew); - } - // LOG(info) << " trackPropagation (this value filled in tuner table)--> " << q2OverPtNew; - if constexpr (fillCovMat) { - tracksParPropagated(track.collisionId(), trackType, mTrackParCov.getX(), mTrackParCov.getAlpha(), mTrackParCov.getY(), mTrackParCov.getZ(), mTrackParCov.getSnp(), mTrackParCov.getTgl(), mTrackParCov.getQ2Pt()); - tracksParExtensionPropagated(mTrackParCov.getPt(), mTrackParCov.getP(), mTrackParCov.getEta(), mTrackParCov.getPhi()); - // TODO do we keep the rho as 0? Also the sigma's are duplicated information - tracksParCovPropagated(std::sqrt(mTrackParCov.getSigmaY2()), std::sqrt(mTrackParCov.getSigmaZ2()), std::sqrt(mTrackParCov.getSigmaSnp2()), - std::sqrt(mTrackParCov.getSigmaTgl2()), std::sqrt(mTrackParCov.getSigma1Pt2()), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - tracksParCovExtensionPropagated(mTrackParCov.getSigmaY2(), mTrackParCov.getSigmaZY(), mTrackParCov.getSigmaZ2(), mTrackParCov.getSigmaSnpY(), - mTrackParCov.getSigmaSnpZ(), mTrackParCov.getSigmaSnp2(), mTrackParCov.getSigmaTglY(), mTrackParCov.getSigmaTglZ(), mTrackParCov.getSigmaTglSnp(), - mTrackParCov.getSigmaTgl2(), mTrackParCov.getSigma1PtY(), mTrackParCov.getSigma1PtZ(), mTrackParCov.getSigma1PtSnp(), mTrackParCov.getSigma1PtTgl(), - mTrackParCov.getSigma1Pt2()); - if (fillTracksDCA) { - tracksDCA(mDcaInfoCov.getY(), mDcaInfoCov.getZ()); - } - if (fillTracksDCACov) { - tracksDCACov(mDcaInfoCov.getSigmaY2(), mDcaInfoCov.getSigmaZ2()); - } - } else { - tracksParPropagated(track.collisionId(), trackType, mTrackPar.getX(), mTrackPar.getAlpha(), mTrackPar.getY(), mTrackPar.getZ(), mTrackPar.getSnp(), mTrackPar.getTgl(), mTrackPar.getQ2Pt()); - tracksParExtensionPropagated(mTrackPar.getPt(), mTrackPar.getP(), mTrackPar.getEta(), mTrackPar.getPhi()); - if (fillTracksDCA) { - tracksDCA(mDcaInfo[0], mDcaInfo[1]); - } - } - } - } - - void processStandard(aod::StoredTracksIU const& tracks, aod::Collisions const& collisions, aod::BCsWithTimestamps const& bcs) - { - fillTrackTables(tracks, tracks, collisions, bcs); - } - PROCESS_SWITCH(TrackPropagation, processStandard, "Process without covariance", true); - - void processStandardWithPID(soa::Join const& tracks, aod::Collisions const& collisions, aod::BCsWithTimestamps const& bcs) - { - fillTrackTables, /*Particle*/ soa::Join, /*isMc = */ false, /*fillCovMat =*/false, /*useTrkPid =*/true>(tracks, tracks, collisions, bcs); - } - PROCESS_SWITCH(TrackPropagation, processStandardWithPID, "Process without covariance and with PID in tracking", false); - - // ----------------------- - void processCovarianceMc(TracksIUWithMc const& tracks, aod::McParticles const& mcParticles, aod::Collisions const& collisions, aod::BCsWithTimestamps const& bcs) - { - // auto table_extension = soa::Extend(tracks); - fillTrackTables(tracks, mcParticles, collisions, bcs); - } - PROCESS_SWITCH(TrackPropagation, processCovarianceMc, "Process with covariance on MC", false); - - void processCovariance(soa::Join const& tracks, aod::Collisions const& collisions, aod::BCsWithTimestamps const& bcs) - { - fillTrackTables, /*Particle*/ soa::Join, /*isMc = */ false, /*fillCovMat =*/true, /*useTrkPid =*/false>(tracks, tracks, collisions, bcs); - } - PROCESS_SWITCH(TrackPropagation, processCovariance, "Process with covariance", false); - // ------------------------ - - void processCovarianceWithPID(soa::Join const& tracks, aod::Collisions const& collisions, aod::BCsWithTimestamps const& bcs) - { - fillTrackTables, /*Particle*/ soa::Join, /*isMc = */ false, /*fillCovMat =*/true, /*useTrkPid =*/false>(tracks, tracks, collisions, bcs); - } - PROCESS_SWITCH(TrackPropagation, processCovarianceWithPID, "Process with covariance and with PID in tracking", false); -}; - -//**************************************************************************************** -/** - * Workflow definition. - */ -//**************************************************************************************** -WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) -{ - WorkflowSpec workflow{adaptAnalysisTask(cfgc)}; - return workflow; -}