Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Analysis/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ o2_add_library(AnalysisCore
SOURCES src/CorrelationContainer.cxx
src/TrackSelection.cxx
src/TriggerAliases.cxx
src/HFConfigurables.cxx
src/BasicPDGManager.cxx
PUBLIC_LINK_LIBRARIES O2::Framework O2::AnalysisDataModel)

o2_target_root_dictionary(AnalysisCore
Expand All @@ -21,6 +23,8 @@ o2_target_root_dictionary(AnalysisCore
include/AnalysisCore/TrackSelectionDefaults.h
include/AnalysisCore/TriggerAliases.h
include/AnalysisCore/MC.h
include/AnalysisCore/HFConfigurables.h
include/AnalysisCore/BasicPDGManager.h
LINKDEF src/AnalysisCoreLinkDef.h)

o2_add_executable(merger
Expand Down
46 changes: 46 additions & 0 deletions Analysis/Core/include/AnalysisCore/BasicPDGManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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.

#ifndef O2_BASICPDGMANAGER_H
#define O2_BASICPDGMANAGER_H
#include "TDatabasePDG.h"

namespace o2::pdg
{
class PDGManagerInstance
{
public:
PDGManagerInstance(const char* path = "");
~PDGManagerInstance();
void setDatabasePath(const char* path);
void reReadDatabase();
TParticlePDG* GetParticle(int pdgcode);

private:
std::string dbPath;
TDatabasePDG* db;
};

class BasicPDGManager : public PDGManagerInstance
{
public:
static BasicPDGManager& instance()
{
static BasicPDGManager inst{};
return inst;
}

private:
using PDGManagerInstance::PDGManagerInstance;
};
} // namespace o2::pdg

#endif // O2_BASICPDGMANAGER_H
44 changes: 44 additions & 0 deletions Analysis/Core/src/BasicPDGManager.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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 "AnalysisCore/BasicPDGManager.h"

namespace o2::pdg
{
PDGManagerInstance::PDGManagerInstance(const char* path)
: dbPath{path}
{
db = new TDatabasePDG();
db->ReadPDGTable(path);
}

PDGManagerInstance::~PDGManagerInstance()
{
db->Delete();
}

void PDGManagerInstance::setDatabasePath(const char* path)
{
dbPath = path;
}

void PDGManagerInstance::reReadDatabase()
{
if (db != nullptr) {
db->ReadPDGTable(dbPath.c_str());
}
}

TParticlePDG* PDGManagerInstance::GetParticle(int pdgcode)
{
return db->GetParticle(pdgcode);
}
} // namespace o2::pdg
6 changes: 6 additions & 0 deletions Analysis/Tutorials/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,9 @@ o2_add_dpl_workflow(multiprocess-example
JOB_POOL analysis
PUBLIC_LINK_LIBRARIES O2::Framework O2::AnalysisCore O2::AnalysisDataModel
COMPONENT_NAME AnalysisTutorial)

o2_add_dpl_workflow(using-pdg
SOURCES src/usingPDGService.cxx
JOB_POOL analysis
PUBLIC_LINK_LIBRARIES O2::Framework O2::AnalysisCore O2::AnalysisDataModel
COMPONENT_NAME AnalysisTutorial)
41 changes: 41 additions & 0 deletions Analysis/Tutorials/src/usingPDGService.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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 "Framework/runDataProcessing.h"
#include "Framework/AnalysisTask.h"
#include "AnalysisCore/MC.h"
#include "AnalysisCore/BasicPDGManager.h"

using namespace o2;
using namespace o2::framework;

struct UsePdgDatabase {
Service<o2::pdg::BasicPDGManager> pdg;
OutputObj<TH1F> particleCharges{TH1F("charges", ";charge;entries", 201, -10.1, 10.1)};

void process(aod::McCollision const&, aod::McParticles const& particles)
{
for (auto& particle : particles) {
auto pdgInfo = pdg->GetParticle(particle.pdgCode());
if (pdgInfo != nullptr) {
particleCharges->Fill(pdgInfo->Charge());
} else {
LOGF(warn, "[%d] unknown particle with PDG code %d", particle.globalIndex(), particle.pdgCode());
}
}
}
};

WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
{
return WorkflowSpec{
adaptAnalysisTask<UsePdgDatabase>(cfgc)};
}