Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TPC track interpolation as DPL workflow, add TOF reader for matching information #3232

Merged
merged 4 commits into from
Apr 22, 2020
Merged
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
2 changes: 1 addition & 1 deletion Detectors/GlobalTrackingWorkflow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ o2_add_executable(match-workflow
PUBLIC_LINK_LIBRARIES O2::GlobalTrackingWorkflow )

add_subdirectory(tofworkflow)

add_subdirectory(tpcinterpolationworkflow)
5 changes: 3 additions & 2 deletions Detectors/GlobalTrackingWorkflow/tofworkflow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

o2_add_library(TOFWorkflow
SOURCES src/RecoWorkflowSpec.cxx
src/TOFMatchedWriterSpec.cxx
src/TOFCalibWriterSpec.cxx
src/TOFMatchedWriterSpec.cxx
src/TOFCalibWriterSpec.cxx
src/TOFMatchedReaderSpec.cxx
PUBLIC_LINK_LIBRARIES O2::Framework O2::TOFBase O2::DataFormatsTOF O2::TOFReconstruction
O2::GlobalTracking O2::GlobalTrackingWorkflow O2::TOFWorkflowUtils
O2::TOFCalibration O2::DataFormatsFT0 O2::FT0Reconstruction O2::FITWorkflow)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// 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 TOFMatchedReaderSpec.h

#ifndef O2_TOF_MATCHINFOREADER
#define O2_TOF_MATCHINFOREADER

#include "TFile.h"
#include "TTree.h"

#include "Framework/DataProcessorSpec.h"
#include "Framework/Task.h"
#include "ReconstructionDataFormats/MatchInfoTOF.h"
#include "SimulationDataFormat/MCCompLabel.h"

namespace o2
{
namespace tof
{

class TOFMatchedReader : public o2::framework::Task
{
public:
TOFMatchedReader(bool useMC) : mUseMC(useMC) {}
~TOFMatchedReader() override = default;
void init(o2::framework::InitContext& ic) final;
void run(o2::framework::ProcessingContext& pc) final;

private:
void connectTree(const std::string& filename);

bool mUseMC = false;
std::string mInFileName{"o2match_tof.root"};
std::string mInTreeName{"matchTOF"};
std::unique_ptr<TFile> mFile = nullptr;
std::unique_ptr<TTree> mTree = nullptr;
std::vector<o2::dataformats::MatchInfoTOF> mMatches, *mMatchesPtr = &mMatches;
std::vector<o2::MCCompLabel> mLabelTOF, *mLabelTOFPtr = &mLabelTOF;
std::vector<o2::MCCompLabel> mLabelTPC, *mLabelTPCPtr = &mLabelTPC;
std::vector<o2::MCCompLabel> mLabelITS, *mLabelITSPtr = &mLabelITS;
};

/// create a processor spec
/// read matched TOF clusters from a ROOT file
framework::DataProcessorSpec getTOFMatchedReaderSpec(bool useMC);

} // namespace tof
} // namespace o2

#endif /* O2_TOF_MATCHINFOREADER */
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// 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 TOFMatchedReaderSpec.cxx

#include <vector>

#include "TTree.h"
#include "TFile.h"

#include "TOFWorkflow/TOFMatchedReaderSpec.h"
#include "Framework/ControlService.h"
#include "Framework/ConfigParamRegistry.h"
#include "Headers/DataHeader.h"
#include "SimulationDataFormat/MCCompLabel.h"
#include "SimulationDataFormat/MCTruthContainer.h"
#include "ReconstructionDataFormats/MatchInfoTOF.h"

using namespace o2::framework;

namespace o2
{
namespace tof
{

void TOFMatchedReader::init(InitContext& ic)
martenole marked this conversation as resolved.
Show resolved Hide resolved
{
// get the option from the init context
LOG(INFO) << "Init TOF matching info reader!";
mInFileName = ic.options().get<std::string>("tof-matched-infile");
mInTreeName = ic.options().get<std::string>("treename");
connectTree(mInFileName);
}

void TOFMatchedReader::connectTree(const std::string& filename)
{
mTree.reset(nullptr); // in case it was already loaded
mFile.reset(TFile::Open(filename.c_str()));
assert(mFile && !mFile->IsZombie());
mTree.reset((TTree*)mFile->Get(mInTreeName.c_str()));
assert(mTree);
mTree->SetBranchAddress("TOFMatchInfo", &mMatchesPtr);
if (mUseMC) {
mTree->SetBranchAddress("MatchTOFMCTruth", &mLabelTOFPtr);
mTree->SetBranchAddress("MatchTPCMCTruth", &mLabelTPCPtr);
mTree->SetBranchAddress("MatchITSMCTruth", &mLabelITSPtr);
}
LOG(INFO) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
}

void TOFMatchedReader::run(ProcessingContext& pc)
{
auto currEntry = mTree->GetReadEntry() + 1;
assert(currEntry < mTree->GetEntries()); // this should not happen
mTree->GetEntry(currEntry);
LOG(INFO) << "Pushing " << mMatches.size() << " TOF matchings at entry " << currEntry;

pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHINFOS", 0, Lifetime::Timeframe}, mMatches);
if (mUseMC) {
pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHTOFINFOSMC", 0, Lifetime::Timeframe}, mLabelTOF);
pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHTPCINFOSMC", 0, Lifetime::Timeframe}, mLabelTPC);
pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHITSINFOSMC", 0, Lifetime::Timeframe}, mLabelITS);
}

if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
pc.services().get<ControlService>().endOfStream();
pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
}
}

DataProcessorSpec getTOFMatchedReaderSpec(bool useMC)
{
std::vector<OutputSpec> outputs;
outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHINFOS", 0, Lifetime::Timeframe);
if (useMC) {
outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHTOFINFOSMC", 0, Lifetime::Timeframe);
outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHTPCINFOSMC", 0, Lifetime::Timeframe);
outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHITSINFOSMC", 0, Lifetime::Timeframe);
}

return DataProcessorSpec{
"TOFMatchedReader",
Inputs{},
outputs,
AlgorithmSpec{adaptFromTask<TOFMatchedReader>(useMC)},
Options{
{"tof-matched-infile", VariantType::String, "o2match_tof.root", {"Name of the input file"}},
{"treename", VariantType::String, "matchTOF", {"Name of top-level TTree"}},
}};
}
} // namespace tof
} // namespace o2
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright CERN and copyright holders of ALICE O2. This software is distributed
# under the terms of the GNU General Public License v3 (GPL Version 3), copied
# verbatim in the file "COPYING".
#
# See http://alice-o2.web.cern.ch/license for full licensing information.
#
# 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.

#TODO Does the O2::GlobalTracking library need to be linked?
o2_add_library(TPCInterpolationWorkflow
SOURCES src/TPCInterpolationSpec.cxx
src/TPCResidualWriterSpec.cxx
src/TrackInterpolationReaderSpec.cxx
src/TrackInterpolationWorkflow.cxx
PUBLIC_LINK_LIBRARIES O2::GlobalTracking
O2::ITSWorkflow
O2::SpacePoints
O2::GlobalTrackingWorkflow
O2::TOFWorkflow
O2::Framework
)

o2_add_executable(scdcalib-interpolation-workflow
COMPONENT_NAME tpc
SOURCES src/tpc-interpolation-workflow.cxx
PUBLIC_LINK_LIBRARIES O2::TPCInterpolationWorkflow)
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// 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_TPC_INTERPOLATION_SPEC_H
#define O2_TPC_INTERPOLATION_SPEC_H

/// @file TPCInterpolationSpec.h

#include "DataFormatsTPC/Constants.h"
#include "SpacePoints/TrackInterpolation.h"
#include "Framework/DataProcessorSpec.h"
#include "Framework/Task.h"

using namespace o2::framework;

namespace o2
{
namespace tpc
{
class TPCInterpolationDPL : public Task
{
public:
TPCInterpolationDPL(bool useMC, const std::vector<int>& tpcClusLanes) : mUseMC(useMC), mTPCClusLanes(tpcClusLanes) {}
~TPCInterpolationDPL() override = default;
void init(InitContext& ic) final;
void run(ProcessingContext& pc) final;

private:
o2::tpc::TrackInterpolation mInterpolation; // track interpolation engine
std::vector<int> mTPCClusLanes;
std::array<std::vector<char>, o2::tpc::Constants::MAXSECTOR> mBufferedTPCClusters;

bool mUseMC{false}; ///< MC flag
};

/// create a processor spec
framework::DataProcessorSpec getTPCInterpolationSpec(bool useMC, const std::vector<int>& tpcClusLanes);

} // namespace tpc
} // namespace o2

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// 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_TPC_RESIDUAL_WRITER_H
#define O2_TPC_RESIDUAL_WRITER_H

/// @file TPCResidualWriterSpec.h

#include "TFile.h"
#include "TTree.h"

#include "Framework/DataProcessorSpec.h"
#include "Framework/Task.h"
#include <string>

namespace o2
{
namespace tpc
{

class ResidualWriterTPC : public o2::framework::Task
{
public:
ResidualWriterTPC(bool useMC = false) : mUseMC(useMC) {}
~ResidualWriterTPC() override = default;
void init(o2::framework::InitContext& ic) final;
void run(o2::framework::ProcessingContext& pc) final;
void endOfStream(o2::framework::EndOfStreamContext& ec) final;

private:
bool mUseMC = false; ///< MC flag
std::string mOutFileName = "o2residuals_tpc.root"; ///< name of output file
std::string mTreeName = "residualsTPC"; ///< name of tree containing output
std::string mOutTracksBranchName = "tracks"; ///< name of branch containing output used tracks
std::string mOutResidualsBranchName = "residuals"; ///< name of branch containing output used residuals
std::unique_ptr<TFile> mFile = nullptr;
std::unique_ptr<TTree> mTree = nullptr;
};

/// create a processor spec
framework::DataProcessorSpec getTPCResidualWriterSpec(bool useMC);

} // namespace tpc
} // namespace o2

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// 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_TPC_INTERPOLATION_READER_H
#define O2_TPC_INTERPOLATION_READER_H

/// @file TrackInterpolationReaderSpec.h

namespace o2
{
namespace tpc
{

// TODO add specification for reading TPC cluster residuals and reference tracks

} // namespace tpc
} // namespace o2

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// 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_TPC_INTERPOLATION_WORKFLOW_H
#define O2_TPC_INTERPOLATION_WORKFLOW_H

/// @file TrackInterpolationWorkflow.h

#include "Framework/WorkflowSpec.h"

namespace o2
{
namespace tpc
{

framework::WorkflowSpec getTPCInterpolationWorkflow(bool useMC);

} // namespace tpc
} // namespace o2

#endif
Loading