Skip to content

Commit c6fd02f

Browse files
author
Benedikt Volkel
committed
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
1 parent 84c87c4 commit c6fd02f

22 files changed

Lines changed: 271 additions & 30 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: 52 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,56 @@ 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 COCKTAILID{"cocktail_id"};
90+
static constexpr Property COCKTAILDESCRIPTIONMAP{"gcocktail_description_map"};
91+
};
92+
93+
// internal structure to allow convenient manipulation of properties as bits on an int to (dis)entangle HepMC and specific generator status codes
94+
union MCGenIdEncoding {
95+
MCGenIdEncoding() : fullEncoding(0) {}
96+
MCGenIdEncoding(int enc) : fullEncoding(enc) {}
97+
// To be backward-compatible, only set transport to 1 if hepmc status is 1
98+
MCGenIdEncoding(int generatorId, int sourceId, int cocktailId = -1) : generatorId(generatorId), sourceId(sourceId), cocktailId(cocktailId) {}
99+
short fullEncoding;
100+
struct {
101+
short generatorId : 5; // an additional identifier for a generator which can be set by the user
102+
short sourceId : 5; // ID used in embedding scenarios
103+
short cocktailId : 6; // reserved bits for future encodings, for instance to identify single cocktail constituents of a generator
104+
};
105+
};
106+
107+
inline short getEncodedGenId(int generatorId, int sourceId, int cocktailId = -1)
108+
{
109+
return MCGenIdEncoding(generatorId, sourceId, cocktailId).fullEncoding;
110+
}
111+
112+
inline int getGeneratorId(short encoded)
113+
{
114+
return static_cast<int>(MCGenIdEncoding(encoded).generatorId);
115+
}
116+
117+
inline int getSourceId(short encoded)
118+
{
119+
return static_cast<int>(MCGenIdEncoding(encoded).sourceId);
120+
}
121+
122+
inline int getCocktailId(short encoded)
123+
{
124+
return static_cast<int>(MCGenIdEncoding(encoded).cocktailId);
125+
}
126+
127+
} // namespace mcgenid
128+
79129
} // namespace o2
80130

81131
#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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 MCGenStatus 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+
#include "TRandom.h"
18+
19+
using namespace o2::mcgenid;
20+
21+
BOOST_AUTO_TEST_CASE(MCGenId_test)
22+
{
23+
// create 2 vectors each with some random integers
24+
constexpr size_t length{100};
25+
constexpr int low{-2};
26+
constexpr int high{16};
27+
28+
// initialise the seed (could be anything)
29+
gRandom->SetSeed();
30+
31+
for (size_t i = 0; i < length; i++) {
32+
// draw random integers
33+
auto sourceId = static_cast<int>(gRandom->Uniform(low, high));
34+
auto generatorId = static_cast<int>(gRandom->Uniform(low, high));
35+
auto cocktailId = static_cast<int>(gRandom->Uniform(low, high));
36+
37+
// encode them
38+
auto encoded = getEncodedGenId(generatorId, sourceId, cocktailId);
39+
40+
// decode them
41+
auto sourceIdAfter = getSourceId(encoded);
42+
auto generatorIdAfter = getGeneratorId(encoded);
43+
auto cocktailIdAfter = getCocktailId(encoded);
44+
45+
std::cout << "SourceID: " << sourceId << " ==> " << sourceIdAfter << "\n"
46+
<< "generatorId: " << generatorId << " ==> " << generatorIdAfter << "\n"
47+
<< "cocktailId: " << cocktailId << " ==> " << cocktailIdAfter << "\n";
48+
49+
// check if original and decoded numbers are the same
50+
BOOST_CHECK(sourceIdAfter == sourceId);
51+
BOOST_CHECK(generatorIdAfter == generatorId);
52+
BOOST_CHECK(cocktailId == cocktailIdAfter);
53+
}
54+
}

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
@@ -72,6 +72,7 @@
7272
#include "SimulationDataFormat/MCTrack.h"
7373
#include "SimulationDataFormat/MCTruthContainer.h"
7474
#include "SimulationDataFormat/MCUtils.h"
75+
#include "SimulationDataFormat/MCGenProperties.h"
7576
#include "ZDCBase/Constants.h"
7677
#include "TPCBase/ParameterElectronics.h"
7778
#include "GPUTPCGMMergedTrackHit.h"
@@ -1838,10 +1839,10 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
18381839
if (nParts == 1 || sourceID == 0) {
18391840
// FIXME:
18401841
// use generators' names for generatorIDs (?)
1841-
short generatorID = sourceID;
18421842
auto& header = mcReader->getMCEventHeader(sourceID, eventID);
1843+
bool isValid{};
18431844
mcCollisionsCursor(bcID,
1844-
generatorID,
1845+
o2::mcgenid::getEncodedGenId(header.getInfo<int>(o2::mcgenid::GeneratorProperty::GENERATORID, isValid), header.getInfo<int>(o2::mcgenid::GeneratorProperty::COCKTAILID, isValid), sourceID),
18451846
truncateFloatFraction(header.GetX(), mCollisionPosition),
18461847
truncateFloatFraction(header.GetY(), mCollisionPosition),
18471848
truncateFloatFraction(header.GetZ(), mCollisionPosition),

Framework/Core/include/Framework/AnalysisDataModel.h

Lines changed: 9 additions & 2 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

@@ -1271,13 +1271,20 @@ namespace mccollision
12711271
{
12721272
DECLARE_SOA_INDEX_COLUMN(BC, bc); //! BC index
12731273
// TODO enum to be added to O2
1274-
DECLARE_SOA_COLUMN(GeneratorsID, generatorsID, short); //!
1274+
DECLARE_SOA_COLUMN(GeneratorsID, generatorsID, short); //! disentangled generator IDs should be accessed from dynamic columns using getGenId, getCocktailId and getSourceId
12751275
DECLARE_SOA_COLUMN(PosX, posX, float); //! X vertex position in cm
12761276
DECLARE_SOA_COLUMN(PosY, posY, float); //! Y vertex position in cm
12771277
DECLARE_SOA_COLUMN(PosZ, posZ, float); //! Z vertex position in cm
12781278
DECLARE_SOA_COLUMN(T, t, float); //! Collision time relative to given bc in ns
12791279
DECLARE_SOA_COLUMN(Weight, weight, float); //! MC weight
12801280
DECLARE_SOA_COLUMN(ImpactParameter, impactParameter, float); //! Impact parameter for A-A
1281+
DECLARE_SOA_DYNAMIC_COLUMN(GetGenId, getGenId, //! The global generator ID which might have been assigned by the user
1282+
[](short generatorsID) -> int { return o2::mcgenid::getGeneratorId(generatorsID); });
1283+
DECLARE_SOA_DYNAMIC_COLUMN(GetCocktailId, getCocktailId, //! A specific cocktail ID in case the generator consisted of multiple cocktail constituents
1284+
[](short generatorsID) -> int { return o2::mcgenid::getCocktailId(generatorsID); });
1285+
DECLARE_SOA_DYNAMIC_COLUMN(GetSourceId, getSourceId, //! The source ID to differentiate between signals and background in an embedding simulation
1286+
[](short generatorsID) -> int { return o2::mcgenid::getSourceId(generatorsID); });
1287+
12811288
} // namespace mccollision
12821289

12831290
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)