Skip to content
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
5 changes: 5 additions & 0 deletions DataFormats/simulation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,8 @@ o2_add_test(MCGenStatus
SOURCES test/testMCGenStatus.cxx
COMPONENT_NAME SimulationDataFormat
PUBLIC_LINK_LIBRARIES O2::SimulationDataFormat)

o2_add_test(MCGenId
SOURCES test/testMCGenId.cxx
COMPONENT_NAME SimulationDataFormat
PUBLIC_LINK_LIBRARIES O2::SimulationDataFormat)
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#ifndef ALICEO2_SIMDATA_MCGENSTATUS_H_
#define ALICEO2_SIMDATA_MCGENSTATUS_H_
#ifndef ALICEO2_SIMDATA_MCGENPROPERTIES_H_
#define ALICEO2_SIMDATA_MCGENPROPERTIES_H_

namespace o2
{
Expand Down Expand Up @@ -76,6 +76,57 @@ inline int getGenStatusCode(int encoded)

} // namespace mcgenstatus

namespace mcgenid
{

// Define some common properties that can be set for Generators
class GeneratorProperty
{
public:
typedef const char* Property;
static constexpr Property GENERATORID{"generator_id"};
static constexpr Property GENERATORDESCRIPTION{"generator_description"};
static constexpr Property SUBGENERATORID{"subgenerator_id"};
static constexpr Property SUBGENERATORDESCRIPTIONMAP{"subgenerator_description_map"};
};

// internal structure to allow encoding of generator IDs and map different numbers to a single short
union MCGenIdEncoding {
MCGenIdEncoding() : fullEncoding(0) {}
MCGenIdEncoding(int enc) : fullEncoding(enc) {}
MCGenIdEncoding(int generatorId, int sourceId, int subGeneratorId) : generatorId(generatorId), sourceId(sourceId), subGeneratorId(subGeneratorId) {}
short fullEncoding;
struct {
unsigned short generatorId : 7; // an additional identifier for a generator which can be set by the user
unsigned short sourceId : 4; // ID used in embedding scenarios
unsigned short subGeneratorId : 5; // sub generator ID in case a generator implements some additional logic
};
};

inline short getEncodedGenId(int generatorId, int sourceId, int subGeneratorId = -1)
{

return MCGenIdEncoding(generatorId, sourceId, subGeneratorId + 1).fullEncoding;
}

inline int getGeneratorId(short encoded)
{

return static_cast<int>(MCGenIdEncoding(encoded).generatorId);
}

inline int getSourceId(short encoded)
{
return static_cast<int>(MCGenIdEncoding(encoded).sourceId);
}

inline int getSubGeneratorId(short encoded)
{
return static_cast<int>(MCGenIdEncoding(encoded).subGeneratorId) - 1;
}

} // namespace mcgenid

} // namespace o2

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define ALICEO2_DATA_MCTRACK_H_

#include "SimulationDataFormat/ParticleStatus.h"
#include "SimulationDataFormat/MCGenStatus.h"
#include "SimulationDataFormat/MCGenProperties.h"
#include "DetectorsCommonDataFormats/DetID.h"
#include "Rtypes.h"
#include "SimulationDataFormat/O2DatabasePDG.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#ifndef O2_MCUTILS_H
#define O2_MCUTILS_H

#include <string>
#include <SimulationDataFormat/MCTrack.h>
#include <SimulationDataFormat/MCGenStatus.h>
#include <SimulationDataFormat/ParticleStatus.h>
#include "TPDGCode.h"
#include "TParticle.h"
Expand All @@ -26,6 +26,7 @@ namespace o2
{
namespace mcutils
{

/// A couple of functions to query on MC tracks ( that needs navigation within the global container
/// of available tracks. It is a class so as to make it available for interactive ROOT more easily.
class MCTrackNavigator
Expand Down Expand Up @@ -79,7 +80,6 @@ class MCGenHelper
// 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.
static void encodeParticleStatusAndTracking(TParticle& particle, bool wanttracking = true);
static void encodeParticleStatusAndTracking(TParticle& particle, int hepmcStatus, int genStatus, bool wanttracking = true);

ClassDefNV(MCGenHelper, 1)
};

Expand Down
2 changes: 1 addition & 1 deletion DataFormats/simulation/src/MCUtils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//

#include <SimulationDataFormat/MCUtils.h>
#include <SimulationDataFormat/MCGenStatus.h>
#include <SimulationDataFormat/MCGenProperties.h>

namespace o2::mcutils
{
Expand Down
50 changes: 50 additions & 0 deletions DataFormats/simulation/test/testMCGenId.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// 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.

#define BOOST_TEST_MODULE Test MCGenId class
#define BOOST_TEST_MAIN
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "SimulationDataFormat/MCGenProperties.h"

using namespace o2::mcgenid;

BOOST_AUTO_TEST_CASE(MCGenId_test)
{
// possible generator IDs range from 0 to 127 (included)
constexpr int highGenerator{128};
// possible sub-generator IDs range from -1 to 30 (included)
constexpr int highSubGenerator{31};
// possible soufce IDs range from 0 to 15 (included)
constexpr int highSource{16};

// test all combinations
for (int sourceId = 0; sourceId < highSource; sourceId++) {
for (int generatorId = 0; generatorId < highGenerator; generatorId++) {
for (int subGeneratorId = -1; subGeneratorId < highSubGenerator; subGeneratorId++) {
auto encoded = getEncodedGenId(generatorId, sourceId, subGeneratorId);
// decode them
auto sourceIdAfter = getSourceId(encoded);
auto generatorIdAfter = getGeneratorId(encoded);
auto subGeneratorIdAfter = getSubGeneratorId(encoded);

std::cout << "SourceID: " << sourceId << " ==> " << sourceIdAfter << "\n"
<< "generatorId: " << generatorId << " ==> " << generatorIdAfter << "\n"
<< "subGeneratorId: " << subGeneratorId << " ==> " << subGeneratorIdAfter << "\n";

// check if original and decoded numbers are the same
BOOST_CHECK(sourceIdAfter == sourceId);
BOOST_CHECK(generatorIdAfter == generatorId);
BOOST_CHECK(subGeneratorId == subGeneratorIdAfter);
}
}
}
}
2 changes: 1 addition & 1 deletion DataFormats/simulation/test/testMCGenStatus.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <boost/test/unit_test.hpp>
#include "SimulationDataFormat/MCTrack.h"
#include "SimulationDataFormat/ParticleStatus.h"
#include "SimulationDataFormat/MCGenStatus.h"
#include "SimulationDataFormat/MCGenProperties.h"
#include "SimulationDataFormat/MCUtils.h"
#include "TFile.h"
#include "TParticle.h"
Expand Down
5 changes: 3 additions & 2 deletions Detectors/AOD/src/AODProducerWorkflowSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
#include "SimulationDataFormat/MCTrack.h"
#include "SimulationDataFormat/MCTruthContainer.h"
#include "SimulationDataFormat/MCUtils.h"
#include "SimulationDataFormat/MCGenProperties.h"
#include "ZDCBase/Constants.h"
#include "TPCBase/ParameterElectronics.h"
#include "GPUTPCGMMergedTrackHit.h"
Expand Down Expand Up @@ -1838,10 +1839,10 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
if (nParts == 1 || sourceID == 0) {
// FIXME:
// use generators' names for generatorIDs (?)
short generatorID = sourceID;
auto& header = mcReader->getMCEventHeader(sourceID, eventID);
bool isValid{};
mcCollisionsCursor(bcID,
generatorID,
o2::mcgenid::getEncodedGenId(header.getInfo<int>(o2::mcgenid::GeneratorProperty::GENERATORID, isValid), sourceID, header.getInfo<int>(o2::mcgenid::GeneratorProperty::SUBGENERATORID, isValid)),
truncateFloatFraction(header.GetX(), mCollisionPosition),
truncateFloatFraction(header.GetY(), mCollisionPosition),
truncateFloatFraction(header.GetZ(), mCollisionPosition),
Expand Down
12 changes: 9 additions & 3 deletions Framework/Core/include/Framework/AnalysisDataModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "CommonConstants/PhysicsConstants.h"
#include "CommonConstants/GeomConstants.h"
#include "CommonConstants/ZDCConstants.h"
#include "SimulationDataFormat/MCGenStatus.h"
#include "SimulationDataFormat/MCGenProperties.h"

using namespace o2::constants::math;

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

} // namespace mccollision

DECLARE_SOA_TABLE(McCollisions, "AOD", "MCCOLLISION", //! MC collision table
Expand Down
10 changes: 6 additions & 4 deletions Generators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ o2_add_library(Generators
src/GeneratorFromFile.cxx
src/GeneratorFromO2KineParam.cxx
src/PrimaryGenerator.cxx
src/PrimaryGeneratorParam.cxx
src/TriggerExternalParam.cxx
src/TriggerParticleParam.cxx
src/BoxGunParam.cxx
Expand Down Expand Up @@ -71,6 +72,7 @@ set(headers
include/Generators/GeneratorFromFile.h
include/Generators/GeneratorFromO2KineParam.h
include/Generators/PrimaryGenerator.h
include/Generators/PrimaryGeneratorParam.h
include/Generators/TriggerExternalParam.h
include/Generators/TriggerParticleParam.h
include/Generators/BoxGunParam.h
Expand All @@ -81,11 +83,11 @@ set(headers

if (pythia6_FOUND)
list(APPEND headers include/Generators/GeneratorPythia6.h
include/Generators/GeneratorPythia6Param.h)
include/Generators/GeneratorPythia6Param.h)
endif()

if(pythia_FOUND)
list(APPEND headers
list(APPEND headers
include/Generators/GeneratorPythia8.h
include/Generators/DecayerPythia8.h
include/Generators/GeneratorPythia8Param.h
Expand Down Expand Up @@ -137,8 +139,8 @@ o2_add_test_root_macro(share/external/trigger_mpi.C
o2_add_test_root_macro(share/egconfig/pythia8_userhooks_charm.C
PUBLIC_LINK_LIBRARIES O2::Generators
LABELS generators)
endif()
endif()

o2_data_file(COPY share/external DESTINATION Generators)
o2_data_file(COPY share/egconfig DESTINATION Generators)
o2_data_file(COPY share/pythia8 DESTINATION Generators)
27 changes: 20 additions & 7 deletions Generators/include/Generators/Generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "Generators/Trigger.h"
#include <functional>
#include <vector>
#include <unordered_map>

namespace o2
{
Expand Down Expand Up @@ -61,12 +62,12 @@ class Generator : public FairGenerator
Bool_t Init() override;

/** Abstract method ReadEvent must be implemented by any derived class.
It has to handle the generation of input tracks (reading from input
file) and the handing of the tracks to the FairPrimaryGenerator. I
t is called from FairMCApplication.
*@param pStack The stack
*@return kTRUE if successful, kFALSE if not
**/
has to handle the generation of input tracks (reading from input
file) and the handing of the tracks to the FairPrimaryGenerator. It is
called from FairMCApplication.
*@param pStack The stack
*@return kTRUE if successful, kFALSE if not
**/
Bool_t ReadEvent(FairPrimaryGenerator* primGen) final;

/** methods to override **/
Expand Down Expand Up @@ -109,6 +110,10 @@ class Generator : public FairGenerator
Bool_t boostEvent();
Bool_t triggerEvent();

/** to handle cocktail constituents **/
void addSubGenerator(int subGeneratorId, std::string const& subGeneratorDescription);
void notifySubGenerator(int subGeneratorId) { mSubGeneratorId = subGeneratorId; }

/** generator interface **/
void* mInterface = nullptr;
std::string mInterfaceName;
Expand Down Expand Up @@ -136,7 +141,15 @@ class Generator : public FairGenerator
/** lorentz boost data members **/
Double_t mBoost;

ClassDefOverride(Generator, 1);
private:
void updateSubGeneratorInformation(o2::dataformats::MCEventHeader* header) const;

// collect an ID and a short description of sub-generator entities
std::unordered_map<int, std::string> mSubGeneratorsIdToDesc;
// the current ID of the sub-generator used in the current event (if applicable)
int mSubGeneratorId = -1;

ClassDefOverride(Generator, 2);

}; /** class Generator **/

Expand Down
2 changes: 1 addition & 1 deletion Generators/include/Generators/GeneratorExternalParam.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace eventgen
/**
** a parameter class/struct to keep the settings of
** the external event-generator and
** allow the user to modify them
** allow the user to modify them
**/
struct GeneratorExternalParam : public o2::conf::ConfigurableParamHelper<GeneratorExternalParam> {
std::string fileName = "";
Expand Down
12 changes: 11 additions & 1 deletion Generators/include/Generators/PrimaryGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class PrimaryGenerator : public FairPrimaryGenerator
// sets the vertex mode; if mode is kCCDB, a valid MeanVertexObject pointer must be given at the same time
void setVertexMode(o2::conf::VertexMode const& mode, o2::dataformats::MeanVertexObject const* obj = nullptr);

// set identifier and description
void setGeneratorId(int id) { mGeneratorId = id; }
void setGeneratorDescription(std::string const& desc) { mGeneratorDescription = desc; }

protected:
/** copy constructor **/
// PrimaryGenerator(const PrimaryGenerator&) = default;
Expand Down Expand Up @@ -113,7 +117,13 @@ class PrimaryGenerator : public FairPrimaryGenerator
o2::conf::VertexMode mVertexMode = o2::conf::VertexMode::kDiamondParam; // !vertex mode
std::unique_ptr<o2::dataformats::MeanVertexObject> mMeanVertex;

ClassDefOverride(PrimaryGenerator, 2);
private:
void setGeneratorInformation();
// generator identifier and description
int mGeneratorId = -1;
std::string mGeneratorDescription;

ClassDefOverride(PrimaryGenerator, 3);

}; /** class PrimaryGenerator **/

Expand Down
Loading