Skip to content

Commit 352e06d

Browse files
jesgumaalkin
authored andcommitted
add test code
1 parent 48d0560 commit 352e06d

5 files changed

Lines changed: 374 additions & 37 deletions

File tree

ALICE3/TableProducer/OTF/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,18 @@ o2physics_add_dpl_workflow(on-the-fly-detector-geometry-provider
3838
SOURCES onTheFlyDetectorGeometryProvider.cxx
3939
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore O2Physics::ALICE3Core O2Physics::FastTracker
4040
COMPONENT_NAME Analysis)
41+
42+
o2physics_add_dpl_workflow(test-ccdb-consumer-0
43+
SOURCES testCcdbConsumer0.cxx
44+
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore O2Physics::ALICE3Core O2Physics::FastTracker
45+
COMPONENT_NAME Analysis)
46+
47+
o2physics_add_dpl_workflow(test-ccdb-consumer-1
48+
SOURCES testCcdbConsumer1.cxx
49+
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore O2Physics::ALICE3Core O2Physics::FastTracker
50+
COMPONENT_NAME Analysis)
51+
52+
o2physics_add_dpl_workflow(test-ccdb-consumer-2
53+
SOURCES testCcdbConsumer2.cxx
54+
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore O2Physics::ALICE3Core O2Physics::FastTracker
55+
COMPONENT_NAME Analysis)

ALICE3/TableProducer/OTF/onTheFlyDetectorGeometryProvider.cxx

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,15 @@
1616
/// \author Nicolò Jacazio <nicolo.jacazio@cern.ch>, Universita del Piemonte Orientale (IT)
1717
///
1818

19-
#include "GeometryContainer.h"
19+
#include "ALICE3/Core/FastTracker.h"
20+
#include "ALICE3/DataModel/OTFLUT.h"
2021

2122
#include <CCDB/BasicCCDBManager.h>
22-
#include <Framework/AnalysisDataModel.h>
23-
#include <Framework/AnalysisHelpers.h>
2423
#include <Framework/AnalysisTask.h>
25-
#include <Framework/Configurable.h>
2624
#include <Framework/HistogramRegistry.h>
27-
#include <Framework/HistogramSpec.h>
28-
#include <Framework/InitContext.h>
29-
#include <Framework/OutputObjHeader.h>
3025
#include <Framework/runDataProcessing.h>
3126

32-
#include <TH1.h>
33-
#include <TString.h>
34-
35-
#include <cstdlib>
27+
#include <map>
3628
#include <string>
3729
#include <vector>
3830

@@ -42,40 +34,55 @@ struct OnTheFlyDetectorGeometryProvider {
4234
o2::framework::Configurable<std::vector<std::string>> detectorConfiguration{"detectorConfiguration",
4335
std::vector<std::string>{"$O2PHYSICS_ROOT/share/alice3/a3geometry_v3.ini"},
4436
"Paths of the detector geometry configuration files"};
37+
o2::framework::Produces<o2::aod::Timestamps> tableTimestamps;
4538
o2::framework::Service<o2::ccdb::BasicCCDBManager> ccdb;
39+
40+
bool ccdbIsInitialized = false;
4641
void init(o2::framework::InitContext&)
4742
{
48-
ccdb->setURL("http://alice-ccdb.cern.ch");
49-
ccdb->setTimestamp(-1);
50-
o2::fastsim::GeometryContainer geometryContainer; // Checking that the geometry files can be accessed and loaded
51-
geometryContainer.setCcdbManager(ccdb.operator->());
52-
LOG(info) << "On-the-fly detector geometry provider running.";
53-
if (detectorConfiguration.value.empty()) {
54-
LOG(fatal) << "No detector configuration files provided.";
55-
return;
56-
}
57-
int idx = 0;
58-
for (std::string& configFile : detectorConfiguration.value) {
59-
LOG(info) << "Loading detector geometry from configuration file: " << configFile;
60-
histos.add<TH1>(Form("GeometryConfigFile_%d", idx++), configFile.c_str(), o2::framework::HistType::kTH1D, {{1, 0, 1}})->Fill(0.5);
61-
geometryContainer.addEntry(configFile);
62-
}
43+
// o2::fastsim::GeometryContainer geometryContainer; // Checking that the geometry files can be accessed and loaded
44+
// geometryContainer.setCcdbManager(ccdb.operator->());
45+
// LOG(info) << "On-the-fly detector geometry provider running.";
46+
// if (detectorConfiguration.value.empty()) {
47+
// LOG(fatal) << "No detector configuration files provided.";
48+
// return;
49+
// }
50+
// int idx = 0;
51+
// for (std::string& configFile : detectorConfiguration.value) {
52+
// LOG(info) << "Loading detector geometry from configuration file: " << configFile;
53+
// histos.add<TH1>(Form("GeometryConfigFile_%d", idx++), configFile.c_str(), o2::framework::HistType::kTH1D, {{1, 0, 1}})->Fill(0.5);
54+
// geometryContainer.addEntry(configFile);
55+
// }
6356

64-
// First we check that the magnetic field is consistent
65-
const int nGeometries = geometryContainer.getNumberOfConfigurations();
66-
const float mMagneticField = geometryContainer.getFloatValue(0, "global", "magneticfield");
67-
for (int icfg = 0; icfg < nGeometries; ++icfg) {
68-
const float cfgBfield = geometryContainer.getFloatValue(icfg, "global", "magneticfield");
69-
if (std::abs(cfgBfield - mMagneticField) > 1e-3) {
70-
LOG(fatal) << "Inconsistent magnetic field values between configurations 0 and " << icfg << ": " << mMagneticField << " vs " << cfgBfield;
71-
}
72-
}
57+
// // First we check that the magnetic field is consistent
58+
// const int nGeometries = geometryContainer.getNumberOfConfigurations();
59+
// const float mMagneticField = geometryContainer.getFloatValue(0, "global", "magneticfield");
60+
// for (int icfg = 0; icfg < nGeometries; ++icfg) {
61+
// const float cfgBfield = geometryContainer.getFloatValue(icfg, "global", "magneticfield");
62+
// if (std::abs(cfgBfield - mMagneticField) > 1e-3) {
63+
// LOG(fatal) << "Inconsistent magnetic field values between configurations 0 and " << icfg << ": " << mMagneticField << " vs " << cfgBfield;
64+
// }
65+
// }
7366
LOG(info) << "Initialization completed";
7467
}
7568

69+
void initCCDB()
70+
{
71+
if (!ccdbIsInitialized) {
72+
tableTimestamps(o2::upgrade::TimestampLUT); // c2b3d801393540b7bddb949d600b199f, ecacb915-3d70-11f0-ac6f-808de0f5250c
73+
ccdbIsInitialized = true;
74+
LOG(info) << "CCDB initialization completed";
75+
}
76+
}
77+
7678
void process(o2::aod::McCollisions const& mcCollisions, o2::aod::McParticles const& mcParticles)
7779
{
78-
LOG(debug) << "On-the-fly detector geometry provider processing " << mcCollisions.size() << " collisions and " << mcParticles.size() << " particles.";
80+
initCCDB();
81+
for (const auto& mcCollision : mcCollisions) {
82+
LOG(debug)<< "On-the-fly detector geometry provider processing " << mcCollision.size() << " collisions and " << mcParticles.size() << " particles.";
83+
}
84+
85+
LOG(debug)<< "On-the-fly detector geometry provider processing " << mcCollisions.size() << " collisions and " << mcParticles.size() << " particles.";
7986
}
8087
};
8188

@@ -103,4 +110,4 @@ o2::framework::WorkflowSpec defineDataProcessing(o2::framework::ConfigContext co
103110
spec.push_back(adaptAnalysisTask<OnTheFlyDetectorGeometryUser>(cfgc));
104111
#endif
105112
return spec;
106-
}
113+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
/// \file TestCcdbConsumer0.cxx
13+
///
14+
/// \brief Reader and and provider of the detector geometry for on-the-fly simulation
15+
///
16+
/// \author Nicolò Jacazio <nicolo.jacazio@cern.ch>, Universita del Piemonte Orientale (IT)
17+
///
18+
19+
#include "ALICE3/Core/FlatTrackSmearer.h"
20+
#include "ALICE3/Core/FlatLutEntry.h"
21+
#include "ALICE3/Core/FastTracker.h"
22+
#include "ALICE3/Core/TrackUtilities.h"
23+
#include "ALICE3/DataModel/OTFLUT.h"
24+
#include <Framework/O2DatabasePDGPlugin.h>
25+
#include <TPDGCode.h>
26+
27+
#include <CCDB/BasicCCDBManager.h>
28+
#include <Framework/AnalysisTask.h>
29+
#include <Framework/HistogramRegistry.h>
30+
#include <Framework/runDataProcessing.h>
31+
32+
#include <map>
33+
#include <string>
34+
#include <vector>
35+
36+
struct TestCcdbConsumer0 {
37+
o2::framework::HistogramRegistry histos{"Histos", {}, o2::framework::OutputObjHandlingPolicy::AnalysisObject};
38+
o2::framework::ConfigurableAxis axisDeltaPt{"axisDeltaPt", {200, -0.2f, +0.2f}, "#Delta p_{T}"};
39+
40+
o2::framework::Service<o2::framework::O2DatabasePDG> pdgDB;
41+
const std::unordered_set<int> pdgsToBeHandled = {PDG_t::kElectron, PDG_t::kMuonMinus, PDG_t::kPiPlus, PDG_t::kKPlus, PDG_t::kProton};
42+
43+
void init(o2::framework::InitContext&)
44+
{
45+
histos.add("hDeltaPtEl", "hDeltaPtEl", o2::framework::kTH1D, {axisDeltaPt});
46+
histos.add("hDeltaPtMu", "hDeltaPtMu", o2::framework::kTH1D, {axisDeltaPt});
47+
histos.add("hDeltaPtPi", "hDeltaPtPi", o2::framework::kTH1D, {axisDeltaPt});
48+
histos.add("hDeltaPtKa", "hDeltaPtKa", o2::framework::kTH1D, {axisDeltaPt});
49+
histos.add("hDeltaPtPr", "hDeltaPtPr", o2::framework::kTH1D, {axisDeltaPt});
50+
LOG(info) << "Initialization completed";
51+
}
52+
53+
void process(o2::aod::McCollisions const& mcCollisions, o2::aod::McParticles const& mcParticles, o2::aod::A3LookUpTables const& luts)
54+
{
55+
for (const auto& mcCollision : mcCollisions) {
56+
o2::delphes::DelphesO2TrackSmearer smearer;
57+
const auto thisTable = luts.rawIteratorAt(0);
58+
// smearer.viewTable(static_cast<int>(PDG_t::kElectron), thisTable.lutEl());
59+
// smearer.viewTable(static_cast<int>(PDG_t::kMuonMinus), thisTable.lutMu());
60+
// smearer.viewTable(static_cast<int>(PDG_t::kPiPlus), thisTable.lutPi());
61+
// smearer.viewTable(static_cast<int>(PDG_t::kKPlus), thisTable.lutKa());
62+
// smearer.viewTable(static_cast<int>(PDG_t::kProton), thisTable.lutPr());
63+
// for (const auto& mcParticle : mcParticles) {
64+
// if (!pdgsToBeHandled.count(std::abs(mcParticle.pdgCode()))) {
65+
// continue;
66+
// }
67+
68+
// o2::track::TrackParCov trackParCov = o2::upgrade::convertMCParticleToO2Track(mcParticle, pdgDB);
69+
// smearer.smearTrack(trackParCov, std::abs(mcParticle.pdgCode()), mcParticles.size());
70+
71+
// switch (std::abs(mcParticle.pdgCode())) {
72+
// case PDG_t::kElectron:
73+
// histos.fill(HIST("hDeltaPtEl"), (trackParCov.getPt() - mcParticle.pt()) / trackParCov.getPt());
74+
// break;
75+
// case PDG_t::kMuonMinus:
76+
// histos.fill(HIST("hDeltaPtMu"), (trackParCov.getPt() - mcParticle.pt()) / trackParCov.getPt());
77+
// break;
78+
// case PDG_t::kPiPlus:
79+
// histos.fill(HIST("hDeltaPtPi"), (trackParCov.getPt() - mcParticle.pt()) / trackParCov.getPt());
80+
// break;
81+
// case PDG_t::kKPlus:
82+
// histos.fill(HIST("hDeltaPtKa"), (trackParCov.getPt() - mcParticle.pt()) / trackParCov.getPt());
83+
// break;
84+
// case PDG_t::kProton:
85+
// histos.fill(HIST("hDeltaPtPr"), (trackParCov.getPt() - mcParticle.pt()) / trackParCov.getPt());
86+
// break;
87+
// default:
88+
// break;
89+
// }
90+
// }
91+
}
92+
}
93+
};
94+
95+
o2::framework::WorkflowSpec defineDataProcessing(o2::framework::ConfigContext const& cfgc)
96+
{
97+
o2::framework::WorkflowSpec spec;
98+
spec.push_back(adaptAnalysisTask<TestCcdbConsumer0>(cfgc));
99+
return spec;
100+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
/// \file TestCcdbConsumer1.cxx
13+
///
14+
/// \brief Reader and and provider of the detector geometry for on-the-fly simulation
15+
///
16+
/// \author Nicolò Jacazio <nicolo.jacazio@cern.ch>, Universita del Piemonte Orientale (IT)
17+
///
18+
19+
#include "ALICE3/Core/FlatTrackSmearer.h"
20+
#include "ALICE3/Core/FlatLutEntry.h"
21+
#include "ALICE3/Core/FastTracker.h"
22+
#include "ALICE3/Core/TrackUtilities.h"
23+
#include "ALICE3/DataModel/OTFLUT.h"
24+
#include <Framework/O2DatabasePDGPlugin.h>
25+
#include <TPDGCode.h>
26+
27+
#include <CCDB/BasicCCDBManager.h>
28+
#include <Framework/AnalysisTask.h>
29+
#include <Framework/HistogramRegistry.h>
30+
#include <Framework/runDataProcessing.h>
31+
32+
#include <map>
33+
#include <string>
34+
#include <vector>
35+
36+
struct TestCcdbConsumer1 {
37+
o2::framework::HistogramRegistry histos{"Histos", {}, o2::framework::OutputObjHandlingPolicy::AnalysisObject};
38+
o2::framework::ConfigurableAxis axisDeltaPt{"axisDeltaPt", {200, -0.2f, +0.2f}, "#Delta p_{T}"};
39+
40+
o2::delphes::DelphesO2TrackSmearer smearer;
41+
o2::framework::Service<o2::framework::O2DatabasePDG> pdgDB;
42+
const std::unordered_set<int> pdgsToBeHandled = {PDG_t::kElectron, PDG_t::kMuonMinus, PDG_t::kPiPlus, PDG_t::kKPlus, PDG_t::kProton};
43+
44+
void init(o2::framework::InitContext&)
45+
{
46+
histos.add("hDeltaPtEl", "hDeltaPtEl", o2::framework::kTH1D, {axisDeltaPt});
47+
histos.add("hDeltaPtMu", "hDeltaPtMu", o2::framework::kTH1D, {axisDeltaPt});
48+
histos.add("hDeltaPtPi", "hDeltaPtPi", o2::framework::kTH1D, {axisDeltaPt});
49+
histos.add("hDeltaPtKa", "hDeltaPtKa", o2::framework::kTH1D, {axisDeltaPt});
50+
histos.add("hDeltaPtPr", "hDeltaPtPr", o2::framework::kTH1D, {axisDeltaPt});
51+
LOG(info) << "Initialization completed";
52+
}
53+
54+
void process(o2::aod::McCollisions const& mcCollisions, o2::aod::McParticles const& mcParticles, o2::aod::A3LookUpTables const& luts)
55+
{
56+
const auto thisTable = luts.rawIteratorAt(0);
57+
auto lutEl = thisTable.lutEl();
58+
auto lutMu = thisTable.lutMu();
59+
auto lutPi = thisTable.lutPi();
60+
auto lutKa = thisTable.lutKa();
61+
auto lutPr = thisTable.lutPr();
62+
smearer.viewTable(PDG_t::kElectron, reinterpret_cast<const uint8_t*>(lutEl.data()), lutEl.size());
63+
smearer.viewTable(PDG_t::kMuonMinus, reinterpret_cast<const uint8_t*>(lutMu.data()), lutMu.size());
64+
smearer.viewTable(PDG_t::kPiPlus, reinterpret_cast<const uint8_t*>(lutPi.data()), lutPi.size());
65+
smearer.viewTable(PDG_t::kKPlus, reinterpret_cast<const uint8_t*>(lutKa.data()), lutKa.size());
66+
smearer.viewTable(PDG_t::kProton, reinterpret_cast<const uint8_t*>(lutPr.data()), lutPr.size());
67+
68+
for (const auto& mcCollision : mcCollisions) {
69+
for (const auto& mcParticle : mcParticles) {
70+
if (!pdgsToBeHandled.count(std::abs(mcParticle.pdgCode()))) {
71+
continue;
72+
}
73+
74+
o2::track::TrackParCov trackParCov = o2::upgrade::convertMCParticleToO2Track(mcParticle, pdgDB);
75+
smearer.smearTrack(trackParCov, std::abs(mcParticle.pdgCode()), mcParticles.size());
76+
77+
const int pdg = std::abs(mcParticle.pdgCode());
78+
switch (pdg) {
79+
case PDG_t::kElectron:
80+
histos.fill(HIST("hDeltaPtEl"), (trackParCov.getPt() - mcParticle.pt()) / trackParCov.getPt());
81+
break;
82+
case PDG_t::kMuonMinus:
83+
histos.fill(HIST("hDeltaPtMu"), (trackParCov.getPt() - mcParticle.pt()) / trackParCov.getPt());
84+
break;
85+
case PDG_t::kPiPlus:
86+
histos.fill(HIST("hDeltaPtPi"), (trackParCov.getPt() - mcParticle.pt()) / trackParCov.getPt());
87+
break;
88+
case PDG_t::kKPlus:
89+
histos.fill(HIST("hDeltaPtKa"), (trackParCov.getPt() - mcParticle.pt()) / trackParCov.getPt());
90+
break;
91+
case PDG_t::kProton:
92+
histos.fill(HIST("hDeltaPtPr"), (trackParCov.getPt() - mcParticle.pt()) / trackParCov.getPt());
93+
break;
94+
default:
95+
break;
96+
}
97+
}
98+
}
99+
}
100+
};
101+
102+
103+
o2::framework::WorkflowSpec defineDataProcessing(o2::framework::ConfigContext const& cfgc)
104+
{
105+
o2::framework::WorkflowSpec spec;
106+
spec.push_back(adaptAnalysisTask<TestCcdbConsumer1>(cfgc));
107+
return spec;
108+
}

0 commit comments

Comments
 (0)