Skip to content

Commit a1792d4

Browse files
benedikt-voelkelBenedikt Volkel
andauthored
Introduce proper generator IDs (#11509)
* Introduce proper generator IDs * 3 values * global ID assigend to a o2::eventgen::PrimaryGenerator * cocktail constituent ID in case a o2::eventgen::Generator consists of multiple cocktail constituents. If a specific constituent is used for an event, that event will be flagged with that ID * source ID to mark source in emebdding scenarios * all 3 values are encoded into a single short, passed to mcCollision table at the end * provide decoding via helper functions/dynamic columns in mcCOllision table Set the IDs * Global ID (and short description) * can be set via o2-sim --confKeyValues \ "PrimaryGenerator.id=3;PrimaryGenerator.description=a specific gen" * Each cocktail constituent must first be registered via o2::eventgen::Generator::addCocktailConstituent(int, std::string) then, each egnerated event must set a valid ID during o2::eventgen::Generator::GenerateEvent or o2::eventgen::Generator::importParticles if cocktail constituents are set but no valid ID is given, no event will be generated * source ID is derived by the framework as before, not up to the user * combine MC Gen ID and particle status to MCGenProperties (naming not final, MCGenHelper, MCGenUtils?) Please consider the following formatting changes * Be consistent with Run1 and Run2 * rename cocktail to subGenerator everywhere * a cocktail should stay a cocktail of different generators * remove comment in AnalysisDataModel * Adjust ID ranges * generator ID from 0 to 127 (included) * sub-generator ID from -1 to 30 (included) * source ID from 0 to 15 (included) --------- Co-authored-by: Benedikt Volkel <benedikt.volkel@cern.ch>
1 parent b7aa213 commit a1792d4

22 files changed

Lines changed: 277 additions & 31 deletions

DataFormats/simulation/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,8 @@ o2_add_test(MCGenStatus
8484
SOURCES test/testMCGenStatus.cxx
8585
COMPONENT_NAME SimulationDataFormat
8686
PUBLIC_LINK_LIBRARIES O2::SimulationDataFormat)
87+
88+
o2_add_test(MCGenId
89+
SOURCES test/testMCGenId.cxx
90+
COMPONENT_NAME SimulationDataFormat
91+
PUBLIC_LINK_LIBRARIES O2::SimulationDataFormat)

DataFormats/simulation/include/SimulationDataFormat/MCGenStatus.h renamed to DataFormats/simulation/include/SimulationDataFormat/MCGenProperties.h

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111

12-
#ifndef ALICEO2_SIMDATA_MCGENSTATUS_H_
13-
#define ALICEO2_SIMDATA_MCGENSTATUS_H_
12+
#ifndef ALICEO2_SIMDATA_MCGENPROPERTIES_H_
13+
#define ALICEO2_SIMDATA_MCGENPROPERTIES_H_
1414

1515
namespace o2
1616
{
@@ -76,6 +76,57 @@ inline int getGenStatusCode(int encoded)
7676

7777
} // namespace mcgenstatus
7878

79+
namespace mcgenid
80+
{
81+
82+
// Define some common properties that can be set for Generators
83+
class GeneratorProperty
84+
{
85+
public:
86+
typedef const char* Property;
87+
static constexpr Property GENERATORID{"generator_id"};
88+
static constexpr Property GENERATORDESCRIPTION{"generator_description"};
89+
static constexpr Property SUBGENERATORID{"subgenerator_id"};
90+
static constexpr Property SUBGENERATORDESCRIPTIONMAP{"subgenerator_description_map"};
91+
};
92+
93+
// internal structure to allow encoding of generator IDs and map different numbers to a single short
94+
union MCGenIdEncoding {
95+
MCGenIdEncoding() : fullEncoding(0) {}
96+
MCGenIdEncoding(int enc) : fullEncoding(enc) {}
97+
MCGenIdEncoding(int generatorId, int sourceId, int subGeneratorId) : generatorId(generatorId), sourceId(sourceId), subGeneratorId(subGeneratorId) {}
98+
short fullEncoding;
99+
struct {
100+
unsigned short generatorId : 7; // an additional identifier for a generator which can be set by the user
101+
unsigned short sourceId : 4; // ID used in embedding scenarios
102+
unsigned short subGeneratorId : 5; // sub generator ID in case a generator implements some additional logic
103+
};
104+
};
105+
106+
inline short getEncodedGenId(int generatorId, int sourceId, int subGeneratorId = -1)
107+
{
108+
109+
return MCGenIdEncoding(generatorId, sourceId, subGeneratorId + 1).fullEncoding;
110+
}
111+
112+
inline int getGeneratorId(short encoded)
113+
{
114+
115+
return static_cast<int>(MCGenIdEncoding(encoded).generatorId);
116+
}
117+
118+
inline int getSourceId(short encoded)
119+
{
120+
return static_cast<int>(MCGenIdEncoding(encoded).sourceId);
121+
}
122+
123+
inline int getSubGeneratorId(short encoded)
124+
{
125+
return static_cast<int>(MCGenIdEncoding(encoded).subGeneratorId) - 1;
126+
}
127+
128+
} // namespace mcgenid
129+
79130
} // namespace o2
80131

81132
#endif

DataFormats/simulation/include/SimulationDataFormat/MCTrack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#define ALICEO2_DATA_MCTRACK_H_
1818

1919
#include "SimulationDataFormat/ParticleStatus.h"
20-
#include "SimulationDataFormat/MCGenStatus.h"
20+
#include "SimulationDataFormat/MCGenProperties.h"
2121
#include "DetectorsCommonDataFormats/DetID.h"
2222
#include "Rtypes.h"
2323
#include "SimulationDataFormat/O2DatabasePDG.h"

DataFormats/simulation/include/SimulationDataFormat/MCUtils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
#ifndef O2_MCUTILS_H
1717
#define O2_MCUTILS_H
1818

19+
#include <string>
1920
#include <SimulationDataFormat/MCTrack.h>
20-
#include <SimulationDataFormat/MCGenStatus.h>
2121
#include <SimulationDataFormat/ParticleStatus.h>
2222
#include "TPDGCode.h"
2323
#include "TParticle.h"
@@ -26,6 +26,7 @@ namespace o2
2626
{
2727
namespace mcutils
2828
{
29+
2930
/// A couple of functions to query on MC tracks ( that needs navigation within the global container
3031
/// of available tracks. It is a class so as to make it available for interactive ROOT more easily.
3132
class MCTrackNavigator
@@ -79,7 +80,6 @@ class MCGenHelper
7980
// Has to be in a class as a static methid. Just in a namespace it doesn't work to use this function in ROOT macros.
8081
static void encodeParticleStatusAndTracking(TParticle& particle, bool wanttracking = true);
8182
static void encodeParticleStatusAndTracking(TParticle& particle, int hepmcStatus, int genStatus, bool wanttracking = true);
82-
8383
ClassDefNV(MCGenHelper, 1)
8484
};
8585

DataFormats/simulation/src/MCUtils.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//
1515

1616
#include <SimulationDataFormat/MCUtils.h>
17-
#include <SimulationDataFormat/MCGenStatus.h>
17+
#include <SimulationDataFormat/MCGenProperties.h>
1818

1919
namespace o2::mcutils
2020
{
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
#define BOOST_TEST_MODULE Test MCGenId class
13+
#define BOOST_TEST_MAIN
14+
#define BOOST_TEST_DYN_LINK
15+
#include <boost/test/unit_test.hpp>
16+
#include "SimulationDataFormat/MCGenProperties.h"
17+
18+
using namespace o2::mcgenid;
19+
20+
BOOST_AUTO_TEST_CASE(MCGenId_test)
21+
{
22+
// possible generator IDs range from 0 to 127 (included)
23+
constexpr int highGenerator{128};
24+
// possible sub-generator IDs range from -1 to 30 (included)
25+
constexpr int highSubGenerator{31};
26+
// possible soufce IDs range from 0 to 15 (included)
27+
constexpr int highSource{16};
28+
29+
// test all combinations
30+
for (int sourceId = 0; sourceId < highSource; sourceId++) {
31+
for (int generatorId = 0; generatorId < highGenerator; generatorId++) {
32+
for (int subGeneratorId = -1; subGeneratorId < highSubGenerator; subGeneratorId++) {
33+
auto encoded = getEncodedGenId(generatorId, sourceId, subGeneratorId);
34+
// decode them
35+
auto sourceIdAfter = getSourceId(encoded);
36+
auto generatorIdAfter = getGeneratorId(encoded);
37+
auto subGeneratorIdAfter = getSubGeneratorId(encoded);
38+
39+
std::cout << "SourceID: " << sourceId << " ==> " << sourceIdAfter << "\n"
40+
<< "generatorId: " << generatorId << " ==> " << generatorIdAfter << "\n"
41+
<< "subGeneratorId: " << subGeneratorId << " ==> " << subGeneratorIdAfter << "\n";
42+
43+
// check if original and decoded numbers are the same
44+
BOOST_CHECK(sourceIdAfter == sourceId);
45+
BOOST_CHECK(generatorIdAfter == generatorId);
46+
BOOST_CHECK(subGeneratorId == subGeneratorIdAfter);
47+
}
48+
}
49+
}
50+
}

DataFormats/simulation/test/testMCGenStatus.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <boost/test/unit_test.hpp>
1616
#include "SimulationDataFormat/MCTrack.h"
1717
#include "SimulationDataFormat/ParticleStatus.h"
18-
#include "SimulationDataFormat/MCGenStatus.h"
18+
#include "SimulationDataFormat/MCGenProperties.h"
1919
#include "SimulationDataFormat/MCUtils.h"
2020
#include "TFile.h"
2121
#include "TParticle.h"

Detectors/AOD/src/AODProducerWorkflowSpec.cxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
#include "SimulationDataFormat/MCTrack.h"
7272
#include "SimulationDataFormat/MCTruthContainer.h"
7373
#include "SimulationDataFormat/MCUtils.h"
74+
#include "SimulationDataFormat/MCGenProperties.h"
7475
#include "ZDCBase/Constants.h"
7576
#include "TPCBase/ParameterElectronics.h"
7677
#include "GPUTPCGMMergedTrackHit.h"
@@ -1854,10 +1855,10 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
18541855
if (nParts == 1 || sourceID == 0) {
18551856
// FIXME:
18561857
// use generators' names for generatorIDs (?)
1857-
short generatorID = sourceID;
18581858
auto& header = mcReader->getMCEventHeader(sourceID, eventID);
1859+
bool isValid{};
18591860
mcCollisionsCursor(bcID,
1860-
generatorID,
1861+
o2::mcgenid::getEncodedGenId(header.getInfo<int>(o2::mcgenid::GeneratorProperty::GENERATORID, isValid), sourceID, header.getInfo<int>(o2::mcgenid::GeneratorProperty::SUBGENERATORID, isValid)),
18611862
truncateFloatFraction(header.GetX(), mCollisionPosition),
18621863
truncateFloatFraction(header.GetY(), mCollisionPosition),
18631864
truncateFloatFraction(header.GetZ(), mCollisionPosition),

Framework/Core/include/Framework/AnalysisDataModel.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "CommonConstants/PhysicsConstants.h"
2020
#include "CommonConstants/GeomConstants.h"
2121
#include "CommonConstants/ZDCConstants.h"
22-
#include "SimulationDataFormat/MCGenStatus.h"
22+
#include "SimulationDataFormat/MCGenProperties.h"
2323

2424
using namespace o2::constants::math;
2525

@@ -1270,14 +1270,20 @@ using Run2BCInfo = Run2BCInfos::iterator;
12701270
namespace mccollision
12711271
{
12721272
DECLARE_SOA_INDEX_COLUMN(BC, bc); //! BC index
1273-
// TODO enum to be added to O2
1274-
DECLARE_SOA_COLUMN(GeneratorsID, generatorsID, short); //!
1273+
DECLARE_SOA_COLUMN(GeneratorsID, generatorsID, short); //! disentangled generator IDs should be accessed from dynamic columns using getGenId, getCocktailId and getSourceId
12751274
DECLARE_SOA_COLUMN(PosX, posX, float); //! X vertex position in cm
12761275
DECLARE_SOA_COLUMN(PosY, posY, float); //! Y vertex position in cm
12771276
DECLARE_SOA_COLUMN(PosZ, posZ, float); //! Z vertex position in cm
12781277
DECLARE_SOA_COLUMN(T, t, float); //! Collision time relative to given bc in ns
12791278
DECLARE_SOA_COLUMN(Weight, weight, float); //! MC weight
12801279
DECLARE_SOA_COLUMN(ImpactParameter, impactParameter, float); //! Impact parameter for A-A
1280+
DECLARE_SOA_DYNAMIC_COLUMN(GetGeneratorId, getGeneratorId, //! The global generator ID which might have been assigned by the user
1281+
[](short generatorsID) -> int { return o2::mcgenid::getGeneratorId(generatorsID); });
1282+
DECLARE_SOA_DYNAMIC_COLUMN(GetSubGeneratorId, getSubGeneratorId, //! A specific sub-generator ID in case the generator has some sub-generator logic
1283+
[](short generatorsID) -> int { return o2::mcgenid::getSubGeneratorId(generatorsID); });
1284+
DECLARE_SOA_DYNAMIC_COLUMN(GetSourceId, getSourceId, //! The source ID to differentiate between signals and background in an embedding simulation
1285+
[](short generatorsID) -> int { return o2::mcgenid::getSourceId(generatorsID); });
1286+
12811287
} // namespace mccollision
12821288

12831289
DECLARE_SOA_TABLE(McCollisions, "AOD", "MCCOLLISION", //! MC collision table

Generators/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ o2_add_library(Generators
3030
src/GeneratorFromFile.cxx
3131
src/GeneratorFromO2KineParam.cxx
3232
src/PrimaryGenerator.cxx
33+
src/PrimaryGeneratorParam.cxx
3334
src/TriggerExternalParam.cxx
3435
src/TriggerParticleParam.cxx
3536
src/BoxGunParam.cxx
@@ -71,6 +72,7 @@ set(headers
7172
include/Generators/GeneratorFromFile.h
7273
include/Generators/GeneratorFromO2KineParam.h
7374
include/Generators/PrimaryGenerator.h
75+
include/Generators/PrimaryGeneratorParam.h
7476
include/Generators/TriggerExternalParam.h
7577
include/Generators/TriggerParticleParam.h
7678
include/Generators/BoxGunParam.h
@@ -81,11 +83,11 @@ set(headers
8183

8284
if (pythia6_FOUND)
8385
list(APPEND headers include/Generators/GeneratorPythia6.h
84-
include/Generators/GeneratorPythia6Param.h)
86+
include/Generators/GeneratorPythia6Param.h)
8587
endif()
8688

8789
if(pythia_FOUND)
88-
list(APPEND headers
90+
list(APPEND headers
8991
include/Generators/GeneratorPythia8.h
9092
include/Generators/DecayerPythia8.h
9193
include/Generators/GeneratorPythia8Param.h
@@ -137,8 +139,8 @@ o2_add_test_root_macro(share/external/trigger_mpi.C
137139
o2_add_test_root_macro(share/egconfig/pythia8_userhooks_charm.C
138140
PUBLIC_LINK_LIBRARIES O2::Generators
139141
LABELS generators)
140-
endif()
141-
142+
endif()
143+
142144
o2_data_file(COPY share/external DESTINATION Generators)
143145
o2_data_file(COPY share/egconfig DESTINATION Generators)
144146
o2_data_file(COPY share/pythia8 DESTINATION Generators)

0 commit comments

Comments
 (0)