Skip to content

Commit

Permalink
Merge pull request AliceO2Group#7 from AliceO2Group/dev
Browse files Browse the repository at this point in the history
sync with master
  • Loading branch information
arvindkhuntia authored Dec 5, 2019
2 parents 21b1b64 + dcd993c commit 3d0d8ec
Show file tree
Hide file tree
Showing 8 changed files with 751 additions and 2 deletions.
1 change: 1 addition & 0 deletions Detectors/TRD/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ o2_add_library(TRDBase
src/TRDGeometry.cxx
src/TRDGeometryFlat.cxx
src/TRDCommonParam.cxx
src/TRDDiffAndTimeStructEstimator.cxx
src/TRDSimParam.cxx
src/PadResponse.cxx
src/Digit.cxx
Expand Down
1 change: 1 addition & 0 deletions Detectors/TRD/base/include/TRDBase/TRDCommonParam.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class TRDCommonParam
bool IsArgon() const { return (mGasMixture == kArgon); }
int GetGasMixture() const { return mGasMixture; }
float GetSamplingFrequency() const { return mSamplingFrequency; }
bool GetCachedField() const { return mField; }

// Cached magnetic field, to be called by the user before using GetDiffCoeff or GetOmegaTau
bool cacheMagField();
Expand Down
60 changes: 60 additions & 0 deletions Detectors/TRD/base/include/TRDBase/TRDDiffandTimeStructEstimator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// 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_TRDDIFFANDTIMESTRUCTESTIMATOR_H
#define O2_TRDDIFFANDTIMESTRUCTESTIMATOR_H

#include <array>

namespace o2
{
namespace trd
{

// CONTANT TIME STRUCTURE DATA FROM GARFIELD
constexpr int ktimebin = 38;
constexpr int kZbin = 11;

/// A class to calculate diffusion and time structure values (GARFIELD model)
/// (used in digitization). Class was split off trom TRDCommonParam
/// and is no longer a singleton so that we can use it in a multithreaded context.
class TRDDiffusionAndTimeStructEstimator
{
public:
TRDDiffusionAndTimeStructEstimator() = default;

/// determines the diffusion coefficients as a function of drift velocity
bool GetDiffCoeff(float& dl, float& dt, float vdrift);

/// determines drift time as function of drift velocity and coordinates
float TimeStruct(float vdrift, float xd, float z);

private:
void SampleTimeStruct(float vdrift);

std::array<float, ktimebin * kZbin> mTimeStruct1; //! cached Time Structure of Drift Cells (for last vdrift value)
std::array<float, ktimebin * kZbin> mTimeStruct2; //! cached Time Structure of Drift Cells (for last vdrift value)
float mVDlo; //! Lower drift velocity, for interpolation
float mVDhi; //! Higher drift velocity, for interpolation
float mInvBinWidth; //! caching 1/(mVDhi - mVDlo)
float mTimeLastVdrift = -1.f; //! The structures are valid for this mLastVdrift (caching)

// for the diffusion part
float mDiffLastVdrift = -1.f;
float mDiffusionL = -1.f;
float mDiffusionT = -1.f;

// ClassDef(TRDDiffusionAndTimeStructEstimator, 1);
};

} // namespace trd
} // namespace o2

#endif //O2_TRDDIFFANDTIMESTRUCTESTIMATOR_H
578 changes: 578 additions & 0 deletions Detectors/TRD/base/src/TRDDiffAndTimeStructEstimator.cxx

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions Detectors/TRD/base/test/testTRDDiffusionCoefficient.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "TRDBase/TRDCommonParam.h"
#include "TRDBase/TRDDiffandTimeStructEstimator.h"

#include "Field/MagneticField.h"
#include <TGeoGlobalMagField.h>
Expand All @@ -43,5 +44,16 @@ BOOST_AUTO_TEST_CASE(TRDDiffusionCoefficient_test1)
BOOST_CHECK_CLOSE(dt, 0.0179734, 0.1);
}

/// \brief Test time structure
BOOST_AUTO_TEST_CASE(TRDTimeStructure_test)
{
auto commonParam = TRDCommonParam::Instance();
TRDDiffusionAndTimeStructEstimator estimator;
BOOST_CHECK_CLOSE(estimator.TimeStruct(1.48, 1., 0.1), commonParam->TimeStruct(1.48, 1., 0.1), 0.001);
BOOST_CHECK_CLOSE(estimator.TimeStruct(1.1, 1., 0.1), commonParam->TimeStruct(1.1, 1., 0.1), 0.001);
BOOST_CHECK_CLOSE(estimator.TimeStruct(2, 1., 0.1), commonParam->TimeStruct(2, 1., 0.1), 0.001);
BOOST_CHECK_CLOSE(estimator.TimeStruct(4, 1., 0.1), commonParam->TimeStruct(4, 1., 0.1), 0.001);
}

} // namespace trd
} // namespace o2
1 change: 1 addition & 0 deletions Framework/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ foreach(b
DeviceMetricsInfo
InputRecord
TableBuilder
WorkflowHelpers
ASoA
HistogramRegistry
)
Expand Down
14 changes: 12 additions & 2 deletions Framework/Core/src/WorkflowHelpers.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -623,15 +623,25 @@ std::vector<InputSpec> WorkflowHelpers::computeDanglingOutputs(WorkflowSpec cons
std::vector<DataMatcherId> inputs;
std::vector<DataMatcherId> outputs;
std::vector<InputSpec> results;
size_t totalInputs = 0;
size_t totalOutputs = 0;

for (auto& spec : workflow) {
totalInputs += spec.inputs.size();
totalOutputs += spec.outputs.size();
}

inputs.reserve(totalInputs);
outputs.reserve(totalOutputs);

/// Prepare an index to do the iterations quickly.
for (size_t wi = 0, we = workflow.size(); wi != we; ++wi) {
auto& spec = workflow[wi];
for (size_t ii = 0, ie = spec.inputs.size(); ii != ie; ++ii) {
inputs.push_back(DataMatcherId{wi, ii});
inputs.emplace_back(DataMatcherId{wi, ii});
}
for (size_t oi = 0, oe = spec.outputs.size(); oi != oe; ++oi) {
outputs.push_back(DataMatcherId{wi, oi});
outputs.emplace_back(DataMatcherId{wi, oi});
}
}

Expand Down
86 changes: 86 additions & 0 deletions Framework/Core/test/benchmark_WorkflowHelpers.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// 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.
#include "Framework/WorkflowSpec.h"
#include "Framework/DataSpecUtils.h"
#include "Framework/OutputSpec.h"
#include "../src/WorkflowHelpers.h"
#include <benchmark/benchmark.h>
#include <algorithm>

using namespace o2::framework;

static void BM_CreateGraphOverhead(benchmark::State& state)
{

for (auto _ : state) {
std::vector<InputSpec> inputSpecs;
std::vector<OutputSpec> outputSpecs;

for (size_t i = 0; i < state.range(); ++i) {
auto subSpec = static_cast<o2::header::DataHeader::SubSpecificationType>(i);
inputSpecs.emplace_back(InputSpec{"y", "TST", "A", subSpec});
outputSpecs.emplace_back(OutputSpec{{"y"}, "TST", "A", subSpec});
}

WorkflowSpec workflow{
{"A",
{},
outputSpecs},
{"B", inputSpecs}};

std::vector<DeviceConnectionEdge> logicalEdges;
std::vector<OutputSpec> outputs;
std::vector<LogicalForwardInfo> availableForwardsInfo;

WorkflowHelpers::verifyWorkflow(workflow);
WorkflowHelpers::injectServiceDevices(workflow);
WorkflowHelpers::constructGraph(workflow,
logicalEdges,
outputs,
availableForwardsInfo);
}
}

BENCHMARK(BM_CreateGraphOverhead)->Range(1, 1 << 10);

static void BM_CreateGraphReverseOverhead(benchmark::State& state)
{

for (auto _ : state) {
std::vector<InputSpec> inputSpecs;
std::vector<OutputSpec> outputSpecs;

for (size_t i = 0; i < state.range(); ++i) {
auto subSpec = static_cast<o2::header::DataHeader::SubSpecificationType>(i);
auto subSpecReverse = static_cast<o2::header::DataHeader::SubSpecificationType>(state.range() - i - 1);
inputSpecs.emplace_back(InputSpec{"y", "TST", "A", subSpec});
outputSpecs.emplace_back(OutputSpec{{"y"}, "TST", "A", subSpecReverse});
}

WorkflowSpec workflow{
{"A",
{},
outputSpecs},
{"B", inputSpecs}};

std::vector<DeviceConnectionEdge> logicalEdges;
std::vector<OutputSpec> outputs;
std::vector<LogicalForwardInfo> availableForwardsInfo;

WorkflowHelpers::verifyWorkflow(workflow);
WorkflowHelpers::injectServiceDevices(workflow);
WorkflowHelpers::constructGraph(workflow, logicalEdges,
outputs,
availableForwardsInfo);
}
}

BENCHMARK(BM_CreateGraphReverseOverhead)->Range(1, 1 << 10);
BENCHMARK_MAIN();

0 comments on commit 3d0d8ec

Please sign in to comment.