diff --git a/Common/TableProducer/CMakeLists.txt b/Common/TableProducer/CMakeLists.txt index d6980ea729f..d49a3f76877 100644 --- a/Common/TableProducer/CMakeLists.txt +++ b/Common/TableProducer/CMakeLists.txt @@ -75,6 +75,12 @@ o2physics_add_dpl_workflow(ft0-corrected-table PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore COMPONENT_NAME Analysis) +o2physics_add_dpl_workflow(ft0-corrected-table-mc-override + SOURCES ft0CorrectedTableMcOverride.cxx + PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore + COMPONENT_NAME Analysis) + + o2physics_add_dpl_workflow(track-propagation SOURCES trackPropagation.cxx PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore diff --git a/Common/TableProducer/ft0CorrectedTable.cxx b/Common/TableProducer/ft0CorrectedTable.cxx index d3396544e6c..a0a40a234dd 100644 --- a/Common/TableProducer/ft0CorrectedTable.cxx +++ b/Common/TableProducer/ft0CorrectedTable.cxx @@ -10,10 +10,10 @@ // or submit itself to any jurisdiction. #include "Common/Core/CollisionTypeHelper.h" +#include "Common/Core/MetadataHelper.h" #include "Common/DataModel/EventSelection.h" #include "Common/DataModel/FT0Corrected.h" -#include #include #include #include @@ -40,14 +40,7 @@ using namespace o2::aod; struct ft0CorrectedTable { // Configurables - Configurable resoFT0A{"resoFT0A", 20.f, "FT0A resolution in ps for the MC override"}; - Configurable resoFT0C{"resoFT0C", 20.f, "FT0C resolution in ps for the MC override"}; Configurable addHistograms{"addHistograms", false, "Add QA histograms"}; - Configurable cfgCollisionSystem{"collisionSystem", -2, "Collision system: -2 (use cfg values), -1 (autoset), 0 (pp), 1 (PbPb), 2 (XeXe), 3 (pPb)"}; - Configurable cfgUrl{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; - Configurable cfgPathGrpLhcIf{"ccdb-path-grplhcif", "GLO/Config/GRPLHCIF", "Path on the CCDB for the GRPLHCIF object"}; - Configurable cfgTimestamp{"ccdb-timestamp", -1, "timestamp of the object"}; - Service ccdb; // Producer Produces table; @@ -58,24 +51,6 @@ struct ft0CorrectedTable { HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject}; void init(o2::framework::InitContext&) { - if (doprocessStandard && doprocessWithBypassFT0timeInMC) { - LOG(fatal) << "Both processStandard and processWithBypassFT0timeInMC are enabled. Pick one of the two"; - } - if (!doprocessStandard && !doprocessWithBypassFT0timeInMC) { - LOG(fatal) << "No process is enabled. Pick one"; - } - ccdb->setURL(cfgUrl); - ccdb->setTimestamp(cfgTimestamp); - ccdb->setCaching(true); - ccdb->setLocalObjectValidityChecking(); - // Not later than now objects - ccdb->setCreatedNotAfter(std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count()); - - if (doprocessWithBypassFT0timeInMC) { - // From ps to ns - resoFT0A.value = resoFT0A.value / 1000.f; - resoFT0C.value = resoFT0C.value / 1000.f; - } if (!addHistograms) { return; } @@ -84,16 +59,11 @@ struct ft0CorrectedTable { histos.add("t0AC", "t0AC", kTH1D, {{1000, -1000, 1000, "t0AC (ns)"}}); histos.add("deltat0AC", "deltat0AC", kTH1D, {{1000, -1, 1, "#Deltat0AC (ns)"}}); histos.add("deltat0ACps", "deltat0ACps", kTH1D, {{1000, -1000, 1000, "#Deltat0AC (ps)"}}); - if (doprocessWithBypassFT0timeInMC) { - histos.add("MC/deltat0A", "t0A", kTH1D, {{1000, -50, 50, "t0A (ps)"}}); - histos.add("MC/deltat0C", "t0C", kTH1D, {{1000, -50, 50, "t0C (ps)"}}); - histos.add("MC/deltat0AC", "t0AC", kTH1D, {{1000, -50, 50, "t0AC (ps)"}}); - } } - void processStandard(soa::Join const& collisions, - BCsWithMatchings const&, - aod::FT0s const&) + void process(soa::Join const& collisions, + BCsWithMatchings const&, + aod::FT0s const&) { table.reserve(collisions.size()); float t0A = 1e10f; @@ -131,94 +101,14 @@ struct ft0CorrectedTable { table(t0A, t0C); } } - PROCESS_SWITCH(ft0CorrectedTable, processStandard, "Process standard table (default)", true); - - void processWithBypassFT0timeInMC(soa::Join const& collisions, - soa::Join const& bcs, - aod::FT0s const&, - aod::McCollisions const&) - { - if (cfgCollisionSystem.value == -1) { - o2::parameters::GRPLHCIFData* grpo = ccdb->template getForTimeStamp(cfgPathGrpLhcIf, - bcs.iteratorAt(0).timestamp()); - cfgCollisionSystem.value = CollisionSystemType::getCollisionTypeFromGrp(grpo); - switch (cfgCollisionSystem.value) { - case CollisionSystemType::kCollSyspp: - resoFT0A.value = 24.f; - resoFT0C.value = 24.f; - break; - case CollisionSystemType::kCollSysPbPb: - resoFT0A.value = 5.65f; - resoFT0C.value = 5.65f; - break; - default: - break; - } - // Resolution is given in ps - resoFT0A.value = resoFT0A.value / 1000.f; - resoFT0C.value = resoFT0C.value / 1000.f; - } - table.reserve(collisions.size()); - float t0A = 1e10f; - float t0C = 1e10f; - float eventtimeMC = 1e10f; - float posZMC = 0; - bool hasMCcoll = false; - - for (const auto& collision : collisions) { - hasMCcoll = false; - eventtimeMC = 1e10f; - t0A = 1e10f; - t0C = 1e10f; - posZMC = 0; - const float vertexPV = collision.posZ(); - const float vertex_corr = vertexPV * invLightSpeedCm2NS; - constexpr float dummyTime = 30.; // Due to HW limitations time can be only within range (-25,25) ns, dummy time is around 32 ns - if (collision.has_mcCollision()) { - hasMCcoll = true; - const auto& collisionMC = collision.mcCollision(); - eventtimeMC = collisionMC.t(); - posZMC = collisionMC.posZ(); - } - if (collision.has_foundFT0()) { - const auto& ft0 = collision.foundFT0(); - const std::bitset<8>& triggers = ft0.triggerMask(); - const bool ora = triggers[o2::ft0::Triggers::bitA]; - const bool orc = triggers[o2::ft0::Triggers::bitC]; - - if (ora && ft0.timeA() < dummyTime) { - t0A = ft0.timeA(); - if (hasMCcoll) { - const float diff = eventtimeMC - posZMC * invLightSpeedCm2NS + gRandom->Gaus(0.f, resoFT0A); - t0A = diff; - } - t0A += vertex_corr; - } - if (orc && ft0.timeC() < dummyTime) { - t0C = ft0.timeC(); - if (hasMCcoll) { - const float diff = eventtimeMC + posZMC * invLightSpeedCm2NS + gRandom->Gaus(0.f, resoFT0C); - t0C = diff; - } - t0C -= vertex_corr; - } - } - LOGF(debug, " T0 collision time T0A = %f, T0C = %f", t0A, t0C); - if (addHistograms) { - histos.fill(HIST("t0A"), t0A); - histos.fill(HIST("t0C"), t0C); - histos.fill(HIST("t0AC"), (t0A + t0C) * 0.5f); - histos.fill(HIST("deltat0AC"), t0A - t0C); - if (hasMCcoll) { - histos.fill(HIST("MC/deltat0A"), (t0A - eventtimeMC) * 1000.f); - histos.fill(HIST("MC/deltat0C"), (t0C - eventtimeMC) * 1000.f); - histos.fill(HIST("MC/deltat0AC"), ((t0A + t0C) * 0.5f - eventtimeMC) * 1000.f); - } - } - table(t0A, t0C); - } - } - PROCESS_SWITCH(ft0CorrectedTable, processWithBypassFT0timeInMC, "Process MC with bypass of the AO2D information. Use with care!", false); }; -WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) { return WorkflowSpec{adaptAnalysisTask(cfgc)}; } +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) +{ + o2::common::core::MetadataHelper metadataInfo; + metadataInfo.initMetadata(cfgc); + if (metadataInfo.isMC() && !metadataInfo.isCommitInSoftwareTag("63bc2e3893851ef0f849bb4c98c65eae1ba21e47")) { + LOG(fatal) << "This workflow should not be used with this AO2D. Use the MC override instead"; + } + return WorkflowSpec{adaptAnalysisTask(cfgc)}; +} diff --git a/Common/TableProducer/ft0CorrectedTableMcOverride.cxx b/Common/TableProducer/ft0CorrectedTableMcOverride.cxx new file mode 100644 index 00000000000..067a4e6cf11 --- /dev/null +++ b/Common/TableProducer/ft0CorrectedTableMcOverride.cxx @@ -0,0 +1,180 @@ +// 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. + +#include "Common/Core/CollisionTypeHelper.h" +#include "Common/Core/MetadataHelper.h" +#include "Common/DataModel/EventSelection.h" +#include "Common/DataModel/FT0Corrected.h" + +#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::aod; + +struct ft0CorrectedTableMcOverride { + // Configurables + Configurable resoFT0A{"resoFT0A", 20.f, "FT0A resolution in ps for the MC override"}; + Configurable resoFT0C{"resoFT0C", 20.f, "FT0C resolution in ps for the MC override"}; + Configurable addHistograms{"addHistograms", false, "Add QA histograms"}; + Configurable cfgCollisionSystem{"collisionSystem", -2, "Collision system: -2 (use cfg values), -1 (autoset), 0 (pp), 1 (PbPb), 2 (XeXe), 3 (pPb)"}; + Configurable cfgUrl{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; + Configurable cfgPathGrpLhcIf{"ccdb-path-grplhcif", "GLO/Config/GRPLHCIF", "Path on the CCDB for the GRPLHCIF object"}; + Configurable cfgTimestamp{"ccdb-timestamp", -1, "timestamp of the object"}; + Service ccdb; + + // Producer + Produces table; + using BCsWithMatchings = soa::Join; + using CollisionEvSel = soa::Join::iterator; + static constexpr float invLightSpeedCm2NS = 1.f / o2::constants::physics::LightSpeedCm2NS; + + HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject}; + void init(o2::framework::InitContext&) + { + ccdb->setURL(cfgUrl); + ccdb->setTimestamp(cfgTimestamp); + ccdb->setCaching(true); + ccdb->setLocalObjectValidityChecking(); + // Not later than now objects + ccdb->setCreatedNotAfter(std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count()); + + // From ps to ns + resoFT0A.value = resoFT0A.value / 1000.f; + resoFT0C.value = resoFT0C.value / 1000.f; + if (!addHistograms) { + return; + } + histos.add("t0A", "t0A", kTH1D, {{1000, -1, 1, "t0A (ns)"}}); + histos.add("t0C", "t0C", kTH1D, {{1000, -1, 1, "t0C (ns)"}}); + histos.add("t0AC", "t0AC", kTH1D, {{1000, -1000, 1000, "t0AC (ns)"}}); + histos.add("deltat0AC", "deltat0AC", kTH1D, {{1000, -1, 1, "#Deltat0AC (ns)"}}); + histos.add("deltat0ACps", "deltat0ACps", kTH1D, {{1000, -1000, 1000, "#Deltat0AC (ps)"}}); + histos.add("MC/deltat0A", "t0A", kTH1D, {{1000, -50, 50, "t0A (ps)"}}); + histos.add("MC/deltat0C", "t0C", kTH1D, {{1000, -50, 50, "t0C (ps)"}}); + histos.add("MC/deltat0AC", "t0AC", kTH1D, {{1000, -50, 50, "t0AC (ps)"}}); + } + + void process(soa::Join const& collisions, + soa::Join const& bcs, + aod::FT0s const&, + aod::McCollisions const&) + { + if (cfgCollisionSystem.value == -1) { + o2::parameters::GRPLHCIFData* grpo = ccdb->template getForTimeStamp(cfgPathGrpLhcIf, + bcs.iteratorAt(0).timestamp()); + cfgCollisionSystem.value = CollisionSystemType::getCollisionTypeFromGrp(grpo); + switch (cfgCollisionSystem.value) { + case CollisionSystemType::kCollSyspp: + resoFT0A.value = 24.f; + resoFT0C.value = 24.f; + break; + case CollisionSystemType::kCollSysPbPb: + resoFT0A.value = 5.65f; + resoFT0C.value = 5.65f; + break; + default: + break; + } + // Resolution is given in ps + resoFT0A.value = resoFT0A.value / 1000.f; + resoFT0C.value = resoFT0C.value / 1000.f; + } + table.reserve(collisions.size()); + float t0A = 1e10f; + float t0C = 1e10f; + float eventtimeMC = 1e10f; + float posZMC = 0; + bool hasMCcoll = false; + + for (const auto& collision : collisions) { + hasMCcoll = false; + eventtimeMC = 1e10f; + t0A = 1e10f; + t0C = 1e10f; + posZMC = 0; + const float vertexPV = collision.posZ(); + const float vertex_corr = vertexPV * invLightSpeedCm2NS; + constexpr float dummyTime = 30.; // Due to HW limitations time can be only within range (-25,25) ns, dummy time is around 32 ns + if (collision.has_mcCollision()) { + hasMCcoll = true; + const auto& collisionMC = collision.mcCollision(); + eventtimeMC = collisionMC.t(); + posZMC = collisionMC.posZ(); + } + if (collision.has_foundFT0()) { + const auto& ft0 = collision.foundFT0(); + const std::bitset<8>& triggers = ft0.triggerMask(); + const bool ora = triggers[o2::ft0::Triggers::bitA]; + const bool orc = triggers[o2::ft0::Triggers::bitC]; + + if (ora && ft0.timeA() < dummyTime) { + t0A = ft0.timeA(); + if (hasMCcoll) { + const float diff = eventtimeMC - posZMC * invLightSpeedCm2NS + gRandom->Gaus(0.f, resoFT0A); + t0A = diff; + } + t0A += vertex_corr; + } + if (orc && ft0.timeC() < dummyTime) { + t0C = ft0.timeC(); + if (hasMCcoll) { + const float diff = eventtimeMC + posZMC * invLightSpeedCm2NS + gRandom->Gaus(0.f, resoFT0C); + t0C = diff; + } + t0C -= vertex_corr; + } + } + LOGF(debug, " T0 collision time T0A = %f, T0C = %f", t0A, t0C); + if (addHistograms) { + histos.fill(HIST("t0A"), t0A); + histos.fill(HIST("t0C"), t0C); + histos.fill(HIST("t0AC"), (t0A + t0C) * 0.5f); + histos.fill(HIST("deltat0AC"), t0A - t0C); + if (hasMCcoll) { + histos.fill(HIST("MC/deltat0A"), (t0A - eventtimeMC) * 1000.f); + histos.fill(HIST("MC/deltat0C"), (t0C - eventtimeMC) * 1000.f); + histos.fill(HIST("MC/deltat0AC"), ((t0A + t0C) * 0.5f - eventtimeMC) * 1000.f); + } + } + table(t0A, t0C); + } + } +}; + +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) +{ + o2::common::core::MetadataHelper metadataInfo; + metadataInfo.initMetadata(cfgc); + if (metadataInfo.isCommitInSoftwareTag("63bc2e3893851ef0f849bb4c98c65eae1ba21e47")) { + LOG(fatal) << "This workflow should not be used with this AO2D. Use standard workflow instead"; + } + return WorkflowSpec{adaptAnalysisTask(cfgc)}; +}