From c45b477a09a38fb0f73f68747625d17266391c5a Mon Sep 17 00:00:00 2001 From: Marco Giacalone Date: Mon, 7 Oct 2024 09:59:11 +0200 Subject: [PATCH 01/14] Implemented flag for .root kinematics input --- .../SimConfig/include/SimConfig/SimConfig.h | 2 + Common/SimConfig/src/SimConfig.cxx | 2 + run/o2sim_parallel.cxx | 40 +++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/Common/SimConfig/include/SimConfig/SimConfig.h b/Common/SimConfig/include/SimConfig/SimConfig.h index da2f978ddf319..be5e15fce26f2 100644 --- a/Common/SimConfig/include/SimConfig/SimConfig.h +++ b/Common/SimConfig/include/SimConfig/SimConfig.h @@ -55,6 +55,7 @@ struct SimConfigData { std::string mTrigger; // chosen VMC generator trigger unsigned int mNEvents; // number of events to be simulated std::string mExtKinFileName; // file name of external kinematics file (needed for ext kinematics generator) + std::string mKineInput; // file name of external kinematics file used as input for the generation (events redirection) std::string mEmbedIntoFileName; // filename containing the reference events to be used for the embedding unsigned int mStartEvent; // index of first event to be taken float mBMax; // maximum for impact parameter sampling @@ -154,6 +155,7 @@ class SimConfig unsigned int getNEvents() const { return mConfigData.mNEvents; } std::string getExtKinematicsFileName() const { return mConfigData.mExtKinFileName; } + std::string getKineInput() const { return mConfigData.mKineInput; } std::string getEmbedIntoFileName() const { return mConfigData.mEmbedIntoFileName; } unsigned int getStartEvent() const { return mConfigData.mStartEvent; } float getBMax() const { return mConfigData.mBMax; } diff --git a/Common/SimConfig/src/SimConfig.cxx b/Common/SimConfig/src/SimConfig.cxx index 9a10b26547ce6..1dd2a208dfa0a 100644 --- a/Common/SimConfig/src/SimConfig.cxx +++ b/Common/SimConfig/src/SimConfig.cxx @@ -77,6 +77,7 @@ void SimConfig::initOptions(boost::program_options::options_description& options "forwardKine", bpo::bool_switch(), "forward kinematics on a FairMQ channel")( "noDiscOutput", bpo::bool_switch(), "switch off writing sim results to disc (useful in combination with forwardKine)"); options.add_options()("fromCollContext", bpo::value()->default_value(""), "Use a pregenerated collision context to infer number of events to simulate, how to embedd them, the vertex position etc. Takes precedence of other options such as \"--nEvents\"."); + options.add_options()("kine-input", bpo::value()->default_value(""), "Use a pregenerated kinematic .root file. The optional \':\' character with a number after it can be used to infer number of events to skip on the input file."); } void SimConfig::determineActiveModules(std::vector const& inputargs, std::vector const& skippedModules, std::vector& activeModules, bool isUpgrade) @@ -304,6 +305,7 @@ bool SimConfig::resetFromParsedMap(boost::program_options::variables_map const& mConfigData.mTrigger = vm["trigger"].as(); mConfigData.mNEvents = vm["nEvents"].as(); mConfigData.mExtKinFileName = vm["extKinFile"].as(); + mConfigData.mKineInput = vm["kine-input"].as(); mConfigData.mEmbedIntoFileName = vm["embedIntoFile"].as(); mConfigData.mStartEvent = vm["startEvent"].as(); mConfigData.mBMax = vm["bMax"].as(); diff --git a/run/o2sim_parallel.cxx b/run/o2sim_parallel.cxx index 24be9743e6a03..0475340970a75 100644 --- a/run/o2sim_parallel.cxx +++ b/run/o2sim_parallel.cxx @@ -512,6 +512,46 @@ int main(int argc, char* argv[]) } return r; } + // check if Kinematics input file is provided + LOG(info) << "Kinematics input file: " << conf.getKineInput(); + if (conf.getKineInput().size() > 0) { + std::string path = conf.getKineInput(); + std::size_t pos = path.find(':'); + std::string kinefilename; + int ntf = 1; + if (pos != std::string::npos) { + kinefilename = path.substr(0, pos); + ntf = std::stoi(path.substr(pos + 1)); + } else { + kinefilename = path; + } + LOG(info) << "Using Kinematics input file: " << kinefilename << ", TimeFrame number: " << ntf; + TFile kinefile(kinefilename.c_str(), "READ"); + if (kinefile.IsZombie()) { + LOG(fatal) << "Could not open Kinematics input file: " << kinefilename; + return 2; + } + TFile splitkinefile(Form("%s_Kine.root", conf.getOutPrefix().c_str()), "RECREATE"); + TTree* kine = (TTree*)kinefile.Get("o2sim"); + const int nentries = kine->GetEntries(); + const int nevsim = conf.getNEvents(); + TTree* kineout = kine->CloneTree(0); + ntf -= 1; + if ((ntf + 1) * nevsim > kine->GetEntries()) { + LOG(fatal) << "Not enough events in the input file to get the entries in the interval [" << ntf * nevsim << ',' << (ntf + 1) * nevsim << "]"; + return 2; + } + for (int i = ntf * nevsim; i < (ntf + 1) * nevsim; ++i) { + kine->GetEntry(i); + kineout->Fill(); + } + splitkinefile.Write(); + kinefile.Close(); + splitkinefile.Close(); + LOG(info) << "Kinematics input file processed successfully"; + LOG(info) << "Splitting time took " << timer.RealTime() << " s"; + return 0; + } gAskedEvents = conf.getNEvents(); if (conf.asService()) { From 45be6ac0a3779b7eae843dd476784d629513079f Mon Sep 17 00:00:00 2001 From: Marco Giacalone Date: Thu, 17 Oct 2024 12:10:26 +0200 Subject: [PATCH 02/14] Event pooling with order randomisation of tree entries --- Generators/include/Generators/GeneratorFromFile.h | 2 ++ Generators/include/Generators/GeneratorFromO2KineParam.h | 1 + Generators/src/GeneratorFromFile.cxx | 9 +++++++++ 3 files changed, 12 insertions(+) diff --git a/Generators/include/Generators/GeneratorFromFile.h b/Generators/include/Generators/GeneratorFromFile.h index 42656baddd402..8e26e2c371fe7 100644 --- a/Generators/include/Generators/GeneratorFromFile.h +++ b/Generators/include/Generators/GeneratorFromFile.h @@ -16,6 +16,7 @@ #include "FairGenerator.h" #include "Generators/Generator.h" +#include class TBranch; class TFile; @@ -94,6 +95,7 @@ class GeneratorFromO2Kine : public o2::eventgen::Generator bool mSkipNonTrackable = true; //! whether to pass non-trackable (decayed particles) to the MC stack bool mContinueMode = false; //! whether we want to continue simulation of previously inhibited tracks bool mRoundRobin = false; //! whether we want to take events from file in a round robin fashion + unsigned int mRandomize = 0; //! whether we want to randomize the order of events in the input file, if so this number will be used as seed std::unique_ptr mOrigMCEventHeader; //! the MC event header of the original file diff --git a/Generators/include/Generators/GeneratorFromO2KineParam.h b/Generators/include/Generators/GeneratorFromO2KineParam.h index c0e032f740aba..34db80a74ce43 100644 --- a/Generators/include/Generators/GeneratorFromO2KineParam.h +++ b/Generators/include/Generators/GeneratorFromO2KineParam.h @@ -32,6 +32,7 @@ struct GeneratorFromO2KineParam : public o2::conf::ConfigurableParamHelperSetSeed(mRandomize); + } return true; } @@ -229,6 +233,11 @@ bool GeneratorFromO2Kine::importParticles() // It might need some adjustment to make it work with secondaries or to continue // from a kinematics snapshot + // Randomize the order of events in the input file + if (mRandomize) { + mEventCounter = gRandom->Integer(mEventsAvailable); + } + if (mEventCounter < mEventsAvailable) { int particlecounter = 0; From 8621151640acc18b51ba6755e7c7dcfdc8dad2cb Mon Sep 17 00:00:00 2001 From: Marco Giacalone Date: Fri, 18 Oct 2024 10:26:46 +0200 Subject: [PATCH 03/14] Added rng seed flag --- Generators/include/Generators/GeneratorFromFile.h | 3 ++- Generators/include/Generators/GeneratorFromO2KineParam.h | 3 ++- Generators/src/GeneratorFromFile.cxx | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Generators/include/Generators/GeneratorFromFile.h b/Generators/include/Generators/GeneratorFromFile.h index 8e26e2c371fe7..09ba148f2c910 100644 --- a/Generators/include/Generators/GeneratorFromFile.h +++ b/Generators/include/Generators/GeneratorFromFile.h @@ -95,7 +95,8 @@ class GeneratorFromO2Kine : public o2::eventgen::Generator bool mSkipNonTrackable = true; //! whether to pass non-trackable (decayed particles) to the MC stack bool mContinueMode = false; //! whether we want to continue simulation of previously inhibited tracks bool mRoundRobin = false; //! whether we want to take events from file in a round robin fashion - unsigned int mRandomize = 0; //! whether we want to randomize the order of events in the input file, if so this number will be used as seed + bool mRandomize = false; //! whether we want to randomize the order of events in the input file + unsigned int mRngSeed = 0; //! randomizer seed, 0 for random value std::unique_ptr mOrigMCEventHeader; //! the MC event header of the original file diff --git a/Generators/include/Generators/GeneratorFromO2KineParam.h b/Generators/include/Generators/GeneratorFromO2KineParam.h index 34db80a74ce43..dd3016b834436 100644 --- a/Generators/include/Generators/GeneratorFromO2KineParam.h +++ b/Generators/include/Generators/GeneratorFromO2KineParam.h @@ -32,7 +32,8 @@ struct GeneratorFromO2KineParam : public o2::conf::ConfigurableParamHelperSetSeed(mRandomize); + gRandom->SetSeed(mRngSeed); } return true; From 87490401ae2b187bc3565d2aea964898a7963587 Mon Sep 17 00:00:00 2001 From: Marco Giacalone Date: Fri, 18 Oct 2024 14:55:58 +0200 Subject: [PATCH 04/14] Added possibility of random rotation of Phi in event pool --- Generators/include/Generators/GeneratorFromFile.h | 2 +- .../include/Generators/GeneratorFromO2KineParam.h | 1 + Generators/src/GeneratorFromFile.cxx | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Generators/include/Generators/GeneratorFromFile.h b/Generators/include/Generators/GeneratorFromFile.h index 09ba148f2c910..21675404a78c2 100644 --- a/Generators/include/Generators/GeneratorFromFile.h +++ b/Generators/include/Generators/GeneratorFromFile.h @@ -97,7 +97,7 @@ class GeneratorFromO2Kine : public o2::eventgen::Generator bool mRoundRobin = false; //! whether we want to take events from file in a round robin fashion bool mRandomize = false; //! whether we want to randomize the order of events in the input file unsigned int mRngSeed = 0; //! randomizer seed, 0 for random value - + bool mRandomPhi = false; //! whether we want to randomize the phi angle of the particles std::unique_ptr mOrigMCEventHeader; //! the MC event header of the original file ClassDefOverride(GeneratorFromO2Kine, 2); diff --git a/Generators/include/Generators/GeneratorFromO2KineParam.h b/Generators/include/Generators/GeneratorFromO2KineParam.h index dd3016b834436..1958006eef189 100644 --- a/Generators/include/Generators/GeneratorFromO2KineParam.h +++ b/Generators/include/Generators/GeneratorFromO2KineParam.h @@ -34,6 +34,7 @@ struct GeneratorFromO2KineParam : public o2::conf::ConfigurableParamHelperSetSeed(mRngSeed); } @@ -239,6 +240,13 @@ bool GeneratorFromO2Kine::importParticles() mEventCounter = gRandom->Integer(mEventsAvailable); } + double dPhi = 0.; + // Phi rotation + if (mRandomPhi) { + dPhi = gRandom->Uniform(2 * TMath::Pi()); + LOG(info) << "Rotating phi by " << dPhi; + } + if (mEventCounter < mEventsAvailable) { int particlecounter = 0; @@ -263,6 +271,13 @@ bool GeneratorFromO2Kine::importParticles() auto pdg = t.GetPdgCode(); auto px = t.Px(); auto py = t.Py(); + if (mRandomPhi) { + auto phi = TMath::ATan2(py, px); + auto pt = TMath::Sqrt(px * px + py * py); + phi += dPhi; + px = pt * TMath::Cos(phi); + py = pt * TMath::Sin(phi); + } auto pz = t.Pz(); auto vx = t.Vx(); auto vy = t.Vy(); From b70c6c8098991403e4b763c0b235fc1058938252 Mon Sep 17 00:00:00 2001 From: Marco Giacalone Date: Mon, 21 Oct 2024 15:39:24 +0200 Subject: [PATCH 05/14] Added GRID kine input compatibility --- Generators/include/Generators/GeneratorFromFile.h | 3 +++ Generators/src/GeneratorFromFile.cxx | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/Generators/include/Generators/GeneratorFromFile.h b/Generators/include/Generators/GeneratorFromFile.h index 21675404a78c2..7a5db3980e2cf 100644 --- a/Generators/include/Generators/GeneratorFromFile.h +++ b/Generators/include/Generators/GeneratorFromFile.h @@ -17,6 +17,7 @@ #include "FairGenerator.h" #include "Generators/Generator.h" #include +#include class TBranch; class TFile; @@ -58,6 +59,7 @@ class GeneratorFromFile : public FairGenerator int mEventsAvailable = 0; bool mSkipNonTrackable = true; //! whether to pass non-trackable (decayed particles) to the MC stack bool mFixOffShell = true; // fix particles with M_assigned != M_calculated + TGrid* mAlienInstance = nullptr; // a cached connection to TGrid (needed for Alien locations) ClassDefOverride(GeneratorFromFile, 1); }; @@ -98,6 +100,7 @@ class GeneratorFromO2Kine : public o2::eventgen::Generator bool mRandomize = false; //! whether we want to randomize the order of events in the input file unsigned int mRngSeed = 0; //! randomizer seed, 0 for random value bool mRandomPhi = false; //! whether we want to randomize the phi angle of the particles + TGrid* mAlienInstance = nullptr; // a cached connection to TGrid (needed for Alien locations) std::unique_ptr mOrigMCEventHeader; //! the MC event header of the original file ClassDefOverride(GeneratorFromO2Kine, 2); diff --git a/Generators/src/GeneratorFromFile.cxx b/Generators/src/GeneratorFromFile.cxx index 25f08cc355939..68fb758acfa1d 100644 --- a/Generators/src/GeneratorFromFile.cxx +++ b/Generators/src/GeneratorFromFile.cxx @@ -29,6 +29,13 @@ namespace eventgen { GeneratorFromFile::GeneratorFromFile(const char* name) { + if (strncmp(name, "alien:/", 7) == 0) { + mAlienInstance = TGrid::Connect("alien"); + if (!mAlienInstance) { + LOG(fatal) << "Could not connect to alien, did you check the alien token?"; + return; + } + } mEventFile = TFile::Open(name); if (mEventFile == nullptr) { LOG(fatal) << "EventFile " << name << " not found \n"; @@ -175,6 +182,13 @@ GeneratorFromO2Kine::GeneratorFromO2Kine(const char* name) setPositionUnit(1.); setTimeUnit(1.); + if (strncmp(name, "alien:/", 7) == 0) { + mAlienInstance = TGrid::Connect("alien"); + if (!mAlienInstance) { + LOG(fatal) << "Could not connect to alien, did you check the alien token?"; + return; + } + } mEventFile = TFile::Open(name); if (mEventFile == nullptr) { LOG(fatal) << "EventFile " << name << " not found"; From ce45b436d17c9d5902c9c99ba59163b9f4c4d8ed Mon Sep 17 00:00:00 2001 From: Marco Giacalone Date: Thu, 24 Oct 2024 16:53:00 +0200 Subject: [PATCH 06/14] Introduction of GeneratorHybrid class for multiple generators configurations At the moment the generation is random, but it's the starting point for event injection with external Kinematic files. The system has been tested locally and it seems to be working fine. --- Generators/CMakeLists.txt | 4 + .../include/Generators/GeneratorHybrid.h | 57 +++++++++ .../include/Generators/GeneratorHybridParam.h | 39 ++++++ Generators/src/GeneratorFactory.cxx | 15 +++ Generators/src/GeneratorHybrid.cxx | 113 ++++++++++++++++++ Generators/src/GeneratorHybridParam.cxx | 15 +++ Generators/src/GeneratorsLinkDef.h | 2 + 7 files changed, 245 insertions(+) create mode 100644 Generators/include/Generators/GeneratorHybrid.h create mode 100644 Generators/include/Generators/GeneratorHybridParam.h create mode 100644 Generators/src/GeneratorHybrid.cxx create mode 100644 Generators/src/GeneratorHybridParam.cxx diff --git a/Generators/CMakeLists.txt b/Generators/CMakeLists.txt index 855ac1adfe888..3b32d076aec1a 100644 --- a/Generators/CMakeLists.txt +++ b/Generators/CMakeLists.txt @@ -24,6 +24,8 @@ o2_add_library(Generators src/GeneratorTGenerator.cxx src/GeneratorExternalParam.cxx src/GeneratorFromFile.cxx + src/GeneratorHybrid.cxx + src/GeneratorHybridParam.cxx src/GeneratorFromO2KineParam.cxx src/GeneratorFileOrCmd.cxx src/GeneratorFileOrCmdParam.cxx @@ -68,6 +70,8 @@ set(headers include/Generators/GeneratorTGenerator.h include/Generators/GeneratorExternalParam.h include/Generators/GeneratorFromFile.h + include/Generators/GeneratorHybrid.h + include/Generators/GeneratorHybridParam.h include/Generators/GeneratorFromO2KineParam.h include/Generators/GeneratorFileOrCmd.h include/Generators/GeneratorFileOrCmdParam.h diff --git a/Generators/include/Generators/GeneratorHybrid.h b/Generators/include/Generators/GeneratorHybrid.h new file mode 100644 index 0000000000000..26687b948c86b --- /dev/null +++ b/Generators/include/Generators/GeneratorHybrid.h @@ -0,0 +1,57 @@ +// 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. + +/// \author M. Giacalone - October 2024 + +#ifndef ALICEO2_EVENTGEN_GENERATORHYBRID_H_ +#define ALICEO2_EVENTGEN_GENERATORHYBRID_H_ + +#include "Generators/Generator.h" +#include "Generators/BoxGenerator.h" +#include +#include +#include "SimulationDataFormat/MCEventHeader.h" +#include "SimulationDataFormat/MCGenProperties.h" +#include "SimulationDataFormat/ParticleStatus.h" +#include "Generators/GeneratorHybridParam.h" +#include "Generators/GeneratorFromO2KineParam.h" +#include +#include + +namespace o2 +{ +namespace eventgen +{ + +class GeneratorHybrid : public Generator +{ + + public: + GeneratorHybrid() = default; + GeneratorHybrid(std::vector gens); + ~GeneratorHybrid() = default; + + Bool_t Init() override; + Bool_t generateEvent() override; + Bool_t importParticles() override; + + private: + o2::eventgen::Generator* currentgen = nullptr; + std::vector> gens; + const std::vector generatorNames = {"extkinO2", "boxgen", "external", "pythia8", "pythia8pp", "pythia8hi", "pythia8hf", "pythia8powheg"}; + std::vector mGens; + int mIndex = -1; +}; + +} // namespace eventgen +} // namespace o2 + +#endif diff --git a/Generators/include/Generators/GeneratorHybridParam.h b/Generators/include/Generators/GeneratorHybridParam.h new file mode 100644 index 0000000000000..1b5e4544667bb --- /dev/null +++ b/Generators/include/Generators/GeneratorHybridParam.h @@ -0,0 +1,39 @@ +// 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. + +/// \author M. Giacalone - October 2024 + +#ifndef ALICEO2_EVENTGEN_GENERATORHYBRIDPARAM_H_ +#define ALICEO2_EVENTGEN_GENERATORHYBRIDPARAM_H_ + +#include "CommonUtils/ConfigurableParam.h" +#include "CommonUtils/ConfigurableParamHelper.h" + +namespace o2 +{ +namespace eventgen +{ + +/** + ** a parameter class/struct to keep the settings of + ** the Hybrid event generator and + ** allow the user to modify them + **/ + +struct GeneratorHybridParam : public o2::conf::ConfigurableParamHelper { + std::string Generators = ""; // generators to be used in the cocktail + O2ParamDef(GeneratorHybridParam, "GeneratorHybrid"); +}; + +} // end namespace eventgen +} // end namespace o2 + +#endif // ALICEO2_EVENTGEN_GENERATORHYBRIDPARAM_H_ diff --git a/Generators/src/GeneratorFactory.cxx b/Generators/src/GeneratorFactory.cxx index 5b3a5b5330617..94d9733484b47 100644 --- a/Generators/src/GeneratorFactory.cxx +++ b/Generators/src/GeneratorFactory.cxx @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #ifdef GENERATORS_WITH_PYTHIA8 @@ -26,6 +27,7 @@ #endif #include #include +#include #include "Generators/GeneratorFromO2KineParam.h" #ifdef GENERATORS_WITH_HEPMC3 #include @@ -240,6 +242,19 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair primGen->AddGenerator(boxGen); } } + } else if (genconfig.compare("hybrid") == 0) { // hybrid using multiple generators + LOG(info) << "Init hybrid generator"; + auto& hybridparam = GeneratorHybridParam::Instance(); + std::string genslist = hybridparam.Generators; + LOG(info) << "Generators list: " << genslist; + std::vector generators; + std::stringstream ss(genslist); + std::string item; + while (std::getline(ss, item, ',')) { + generators.push_back(item); + } + auto hybrid = new o2::eventgen::GeneratorHybrid(generators); + primGen->AddGenerator(hybrid); } else { LOG(fatal) << "Invalid generator"; } diff --git a/Generators/src/GeneratorHybrid.cxx b/Generators/src/GeneratorHybrid.cxx new file mode 100644 index 0000000000000..73dc21fae05f6 --- /dev/null +++ b/Generators/src/GeneratorHybrid.cxx @@ -0,0 +1,113 @@ +// 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. + +#include "Generators/GeneratorHybrid.h" +#include +#include + +namespace o2 +{ + namespace eventgen + { + GeneratorHybrid::GeneratorHybrid(std::vector inputgens) + { + auto extname = GeneratorFromO2KineParam::Instance().fileName; + for(auto gen : inputgens) + { + // Search if the generator name is inside generatorNames (which is a vector of strings) + LOG(info) << "Checking if generator " << gen << " is in the list of available generators \n"; + if (std::find(generatorNames.begin(), generatorNames.end(), gen) != generatorNames.end()) + { + LOG(info) << "Found generator " << gen << " in the list of available generators \n"; + if(gen.compare("boxgen") == 0){ + gens.push_back(std::make_unique(22, 10, -5, 5, 0, 10, 0, 360)); + mGens.push_back(gen); + } else if (gen.compare(0, 7, "pythia8") == 0) { + gens.push_back(std::make_unique()); + mGens.push_back(gen); + } else if(gen.compare("extkinO2") == 0){ + gens.push_back(std::make_unique(extname.c_str())); + mGens.push_back(gen); + } else { + LOG(info) << "Generator " << gen << " not found in the list of available generators \n"; + } + } + } + } + + Bool_t GeneratorHybrid::Init() + { + // init all sub-gens + int count = 0; + for (auto& gen : gens) + { + if (mGens[count] == "pythia8"){ + auto config = std::string(); + LOG(info) << "Setting \'Pythia8\' base configuration: " << config << std::endl; + dynamic_cast(gen.get())->setConfig(config); + } else if (mGens[count] == "pythia8pp"){ + auto config = std::string(std::getenv("O2_ROOT")) + "/share/Generators/egconfig/pythia8_inel.cfg"; + LOG(info) << "Setting \'Pythia8\' base configuration: " << config << std::endl; + dynamic_cast(gen.get())->setConfig(config); + } else if (mGens[count] == "pythia8hf") { + auto config = std::string(std::getenv("O2_ROOT")) + "/share/Generators/egconfig/pythia8_hf.cfg"; + LOG(info) << "Setting \'Pythia8\' base configuration: " << config << std::endl; + dynamic_cast(gen.get())->setConfig(config); + } else if (mGens[count] == "pythia8hi") { + auto config = std::string(std::getenv("O2_ROOT")) + "/share/Generators/egconfig/pythia8_hi.cfg"; + LOG(info) << "Setting \'Pythia8\' base configuration: " << config << std::endl; + dynamic_cast(gen.get())->setConfig(config); + } else if (mGens[count] == "pythia8powheg") { + auto config = std::string(std::getenv("O2_ROOT")) + "/share/Generators/egconfig/pythia8_powheg.cfg"; + LOG(info) << "Setting \'Pythia8\' base configuration: " << config << std::endl; + dynamic_cast(gen.get())->setConfig(config); + } + gen->Init(); + addSubGenerator(count, mGens[count]); + count++; + } + return Generator::Init(); + } + + Bool_t GeneratorHybrid::generateEvent() + { + // here we call the individual gun generators in turn + // (but we could easily call all of them to have cocktails) + mIndex = gRandom->Integer(gens.size()); + LOG(info) << "GeneratorHybrid: generating event with generator " << mGens[mIndex]; + gens[mIndex]->clearParticles(); // clear container of this class + gens[mIndex]->generateEvent(); + // notify the sub event generator + notifySubGenerator(mIndex); + return true; + } + + Bool_t GeneratorHybrid::importParticles() + { + mParticles.clear(); // clear container of mother class + gens[mIndex]->importParticles(); + std::copy(gens[mIndex]->getParticles().begin(), gens[mIndex]->getParticles().end(), std::back_insert_iterator(mParticles)); + + // we need to fix particles statuses --> need to enforce this on the importParticles level of individual generators + for (auto& p : mParticles) + { + auto st = o2::mcgenstatus::MCGenStatusEncoding(p.GetStatusCode(), p.GetStatusCode()).fullEncoding; + p.SetStatusCode(st); + p.SetBit(ParticleStatus::kToBeDone, true); + } + + return true; + } + + } // namespace eventgen +} // namespace o2 + +ClassImp(o2::eventgen::GeneratorHybrid); \ No newline at end of file diff --git a/Generators/src/GeneratorHybridParam.cxx b/Generators/src/GeneratorHybridParam.cxx new file mode 100644 index 0000000000000..e15fbb8ee4ba4 --- /dev/null +++ b/Generators/src/GeneratorHybridParam.cxx @@ -0,0 +1,15 @@ +// 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. + +/// \author M. Giacalone - October 2024 + +#include "Generators/GeneratorHybridParam.h" +O2ParamImpl(o2::eventgen::GeneratorHybridParam); \ No newline at end of file diff --git a/Generators/src/GeneratorsLinkDef.h b/Generators/src/GeneratorsLinkDef.h index 222004e0957cb..013dfe6080933 100644 --- a/Generators/src/GeneratorsLinkDef.h +++ b/Generators/src/GeneratorsLinkDef.h @@ -51,6 +51,8 @@ #endif #pragma link C++ class o2::eventgen::GeneratorFromFile + ; #pragma link C++ class o2::eventgen::GeneratorFromO2Kine + ; +#pragma link C++ class o2::eventgen::GeneratorHybrid + ; +#pragma link C++ class o2::eventgen::GeneratorHybridParam + ; #pragma link C++ class o2::eventgen::GeneratorFromO2KineParam + ; #pragma link C++ class o2::conf::ConfigurableParamHelper < o2::eventgen::GeneratorFromO2KineParam> + ; #pragma link C++ class o2::eventgen::PrimaryGenerator + ; From 8e3a4adc4f4936a8808abc8bd021a3a2863ec453 Mon Sep 17 00:00:00 2001 From: Marco Giacalone Date: Fri, 25 Oct 2024 15:22:34 +0200 Subject: [PATCH 07/14] Implemented configurations and fractions parameters for hybrid generator --- .../include/Generators/GeneratorHybrid.h | 8 +- .../include/Generators/GeneratorHybridParam.h | 5 +- Generators/src/GeneratorHybrid.cxx | 81 +++++++++++++++++-- 3 files changed, 84 insertions(+), 10 deletions(-) diff --git a/Generators/include/Generators/GeneratorHybrid.h b/Generators/include/Generators/GeneratorHybrid.h index 26687b948c86b..3d3bff77463e9 100644 --- a/Generators/include/Generators/GeneratorHybrid.h +++ b/Generators/include/Generators/GeneratorHybrid.h @@ -48,7 +48,13 @@ class GeneratorHybrid : public Generator std::vector> gens; const std::vector generatorNames = {"extkinO2", "boxgen", "external", "pythia8", "pythia8pp", "pythia8hi", "pythia8hf", "pythia8powheg"}; std::vector mGens; - int mIndex = -1; + std::vector mConfigs; + std::vector mConfsPythia8; + bool mRandomize = false; + std::vector mFractions; + int mseqCounter = 0; + int mCurrentFraction = 0; + int mIndex = 0; }; } // namespace eventgen diff --git a/Generators/include/Generators/GeneratorHybridParam.h b/Generators/include/Generators/GeneratorHybridParam.h index 1b5e4544667bb..4e237d8e4005e 100644 --- a/Generators/include/Generators/GeneratorHybridParam.h +++ b/Generators/include/Generators/GeneratorHybridParam.h @@ -29,7 +29,10 @@ namespace eventgen **/ struct GeneratorHybridParam : public o2::conf::ConfigurableParamHelper { - std::string Generators = ""; // generators to be used in the cocktail + std::string Generators = ""; // generators to be used in the cocktail, each divided by a comma + std::string Configs = ""; // configurations for the generators, each divided by a colon + bool Randomize = false; // randomize the order of the generators, if not generator using fractions + std::string Fractions = ""; // events fractions for each generator, works only for sequence O2ParamDef(GeneratorHybridParam, "GeneratorHybrid"); }; diff --git a/Generators/src/GeneratorHybrid.cxx b/Generators/src/GeneratorHybrid.cxx index 73dc21fae05f6..ab0be5501e0db 100644 --- a/Generators/src/GeneratorHybrid.cxx +++ b/Generators/src/GeneratorHybrid.cxx @@ -19,7 +19,50 @@ namespace o2 { GeneratorHybrid::GeneratorHybrid(std::vector inputgens) { - auto extname = GeneratorFromO2KineParam::Instance().fileName; + auto configs = GeneratorHybridParam::Instance().Configs; + mRandomize = GeneratorHybridParam::Instance().Randomize; + std::stringstream ss(configs); + std::string conf; + while (std::getline(ss, conf, ':')) { + mConfigs.push_back(conf); + } + if(mConfigs.size() != inputgens.size()){ + LOG(fatal) << "Number of configurations does not match the number of generators"; + } + if(mConfigs.size() == 0){ + for(auto gen : inputgens){ + mConfigs.push_back(""); + } + } + int index = 0; + if (!mRandomize) { + std::string fractions = GeneratorHybridParam::Instance().Fractions; + if(fractions.compare("") == 0){ + for (auto gen : inputgens) { + mFractions.push_back(1); + } + } + else{ + std::stringstream streamfrac(fractions); + std::string frac; + while (std::getline(streamfrac, frac, ',')) { + if(frac.compare("") == 0) + mFractions.push_back(1); + else + mFractions.push_back(std::stoi(frac)); + } + if(mFractions.size() != inputgens.size()){ + LOG(fatal) << "Number of fractions does not match the number of generators"; + return; + } + // Check if all elements of mFractions are 0 + if (std::all_of(mFractions.begin(), mFractions.end(), [](int i){ return i == 0; })) { + LOG(fatal) << "All fractions provided are 0, no simulation will be performed"; + return; + } + + } + } for(auto gen : inputgens) { // Search if the generator name is inside generatorNames (which is a vector of strings) @@ -27,19 +70,31 @@ namespace o2 if (std::find(generatorNames.begin(), generatorNames.end(), gen) != generatorNames.end()) { LOG(info) << "Found generator " << gen << " in the list of available generators \n"; - if(gen.compare("boxgen") == 0){ - gens.push_back(std::make_unique(22, 10, -5, 5, 0, 10, 0, 360)); + if (gen.compare("boxgen") == 0) { + if (mConfigs[index].compare("") == 0) { + gens.push_back(std::make_unique()); + } else { + std::stringstream ss(mConfigs[index]); + std::string pars; + std::vector params; + while (std::getline(ss, pars, ',')) { + params.push_back(std::stod(pars)); + } + gens.push_back(std::make_unique(int(params[0]), int(params[1]), params[2], params[3], params[4], params[5], params[6], params[7])); + } mGens.push_back(gen); } else if (gen.compare(0, 7, "pythia8") == 0) { gens.push_back(std::make_unique()); + mConfsPythia8.push_back(mConfigs[index]); mGens.push_back(gen); } else if(gen.compare("extkinO2") == 0){ - gens.push_back(std::make_unique(extname.c_str())); + gens.push_back(std::make_unique(mConfigs[index].c_str())); mGens.push_back(gen); } else { LOG(info) << "Generator " << gen << " not found in the list of available generators \n"; } } + index++; } } @@ -50,7 +105,7 @@ namespace o2 for (auto& gen : gens) { if (mGens[count] == "pythia8"){ - auto config = std::string(); + auto config = std::string(std::getenv("O2_ROOT")) + mConfsPythia8[count]; LOG(info) << "Setting \'Pythia8\' base configuration: " << config << std::endl; dynamic_cast(gen.get())->setConfig(config); } else if (mGens[count] == "pythia8pp"){ @@ -79,14 +134,24 @@ namespace o2 Bool_t GeneratorHybrid::generateEvent() { - // here we call the individual gun generators in turn - // (but we could easily call all of them to have cocktails) - mIndex = gRandom->Integer(gens.size()); + // Order randomisation or sequence of generators + // following provided fractions, if not generators are used in proper sequence + if (mRandomize) { + mIndex = gRandom->Integer(gens.size()); + } else { + while (mFractions[mCurrentFraction] == 0 || mseqCounter == mFractions[mCurrentFraction]) { + if (mFractions[mCurrentFraction] != 0) + mseqCounter = 0; + mCurrentFraction = (mCurrentFraction + 1) % mFractions.size(); + } + mIndex = mCurrentFraction; + } LOG(info) << "GeneratorHybrid: generating event with generator " << mGens[mIndex]; gens[mIndex]->clearParticles(); // clear container of this class gens[mIndex]->generateEvent(); // notify the sub event generator notifySubGenerator(mIndex); + mseqCounter++; return true; } From 3391bcc78c59c419239b4af9df75ded44a56d822 Mon Sep 17 00:00:00 2001 From: Marco Giacalone Date: Tue, 29 Oct 2024 14:25:42 +0100 Subject: [PATCH 08/14] Added features to use alien path, phi rotation and event randomisation --- .../include/Generators/GeneratorFromFile.h | 7 ++++ .../Generators/GeneratorFromO2KineParam.h | 3 ++ Generators/src/GeneratorFromFile.cxx | 39 +++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/Generators/include/Generators/GeneratorFromFile.h b/Generators/include/Generators/GeneratorFromFile.h index 42656baddd402..b180f981f8b88 100644 --- a/Generators/include/Generators/GeneratorFromFile.h +++ b/Generators/include/Generators/GeneratorFromFile.h @@ -16,6 +16,8 @@ #include "FairGenerator.h" #include "Generators/Generator.h" +#include +#include class TBranch; class TFile; @@ -57,6 +59,7 @@ class GeneratorFromFile : public FairGenerator int mEventsAvailable = 0; bool mSkipNonTrackable = true; //! whether to pass non-trackable (decayed particles) to the MC stack bool mFixOffShell = true; // fix particles with M_assigned != M_calculated + TGrid* mAlienInstance = nullptr; // a cached connection to TGrid (needed for Alien locations) ClassDefOverride(GeneratorFromFile, 1); }; @@ -94,6 +97,10 @@ class GeneratorFromO2Kine : public o2::eventgen::Generator bool mSkipNonTrackable = true; //! whether to pass non-trackable (decayed particles) to the MC stack bool mContinueMode = false; //! whether we want to continue simulation of previously inhibited tracks bool mRoundRobin = false; //! whether we want to take events from file in a round robin fashion + bool mRandomize = false; //! whether we want to randomize the order of events in the input file + unsigned int mRngSeed = 0; //! randomizer seed, 0 for random value + bool mRandomPhi = false; //! whether we want to randomize the phi angle of the particles + TGrid* mAlienInstance = nullptr; // a cached connection to TGrid (needed for Alien locations) std::unique_ptr mOrigMCEventHeader; //! the MC event header of the original file diff --git a/Generators/include/Generators/GeneratorFromO2KineParam.h b/Generators/include/Generators/GeneratorFromO2KineParam.h index c0e032f740aba..5f384ab6d4fee 100644 --- a/Generators/include/Generators/GeneratorFromO2KineParam.h +++ b/Generators/include/Generators/GeneratorFromO2KineParam.h @@ -32,6 +32,9 @@ struct GeneratorFromO2KineParam : public o2::conf::ConfigurableParamHelperSetSeed(mRngSeed); + } return true; } @@ -229,6 +249,18 @@ bool GeneratorFromO2Kine::importParticles() // It might need some adjustment to make it work with secondaries or to continue // from a kinematics snapshot + // Randomize the order of events in the input file + if (mRandomize) { + mEventCounter = gRandom->Integer(mEventsAvailable); + } + + double dPhi = 0.; + // Phi rotation + if (mRandomPhi) { + dPhi = gRandom->Uniform(2 * TMath::Pi()); + LOG(info) << "Rotating phi by " << dPhi; + } + if (mEventCounter < mEventsAvailable) { int particlecounter = 0; @@ -253,6 +285,13 @@ bool GeneratorFromO2Kine::importParticles() auto pdg = t.GetPdgCode(); auto px = t.Px(); auto py = t.Py(); + if (mRandomPhi) { + auto phi = TMath::ATan2(py, px); + auto pt = TMath::Sqrt(px * px + py * py); + phi += dPhi; + px = pt * TMath::Cos(phi); + py = pt * TMath::Sin(phi); + } auto pz = t.Pz(); auto vx = t.Vx(); auto vy = t.Vy(); From 3a8dc30f47a0ffc188f4dbf584f6fbcdff91d9dd Mon Sep 17 00:00:00 2001 From: Marco Giacalone Date: Tue, 29 Oct 2024 14:39:26 +0100 Subject: [PATCH 09/14] Removal of unused implementation attempt --- .../SimConfig/include/SimConfig/SimConfig.h | 2 - Common/SimConfig/src/SimConfig.cxx | 2 - run/o2sim_parallel.cxx | 40 ------------------- 3 files changed, 44 deletions(-) diff --git a/Common/SimConfig/include/SimConfig/SimConfig.h b/Common/SimConfig/include/SimConfig/SimConfig.h index be5e15fce26f2..da2f978ddf319 100644 --- a/Common/SimConfig/include/SimConfig/SimConfig.h +++ b/Common/SimConfig/include/SimConfig/SimConfig.h @@ -55,7 +55,6 @@ struct SimConfigData { std::string mTrigger; // chosen VMC generator trigger unsigned int mNEvents; // number of events to be simulated std::string mExtKinFileName; // file name of external kinematics file (needed for ext kinematics generator) - std::string mKineInput; // file name of external kinematics file used as input for the generation (events redirection) std::string mEmbedIntoFileName; // filename containing the reference events to be used for the embedding unsigned int mStartEvent; // index of first event to be taken float mBMax; // maximum for impact parameter sampling @@ -155,7 +154,6 @@ class SimConfig unsigned int getNEvents() const { return mConfigData.mNEvents; } std::string getExtKinematicsFileName() const { return mConfigData.mExtKinFileName; } - std::string getKineInput() const { return mConfigData.mKineInput; } std::string getEmbedIntoFileName() const { return mConfigData.mEmbedIntoFileName; } unsigned int getStartEvent() const { return mConfigData.mStartEvent; } float getBMax() const { return mConfigData.mBMax; } diff --git a/Common/SimConfig/src/SimConfig.cxx b/Common/SimConfig/src/SimConfig.cxx index 1dd2a208dfa0a..9a10b26547ce6 100644 --- a/Common/SimConfig/src/SimConfig.cxx +++ b/Common/SimConfig/src/SimConfig.cxx @@ -77,7 +77,6 @@ void SimConfig::initOptions(boost::program_options::options_description& options "forwardKine", bpo::bool_switch(), "forward kinematics on a FairMQ channel")( "noDiscOutput", bpo::bool_switch(), "switch off writing sim results to disc (useful in combination with forwardKine)"); options.add_options()("fromCollContext", bpo::value()->default_value(""), "Use a pregenerated collision context to infer number of events to simulate, how to embedd them, the vertex position etc. Takes precedence of other options such as \"--nEvents\"."); - options.add_options()("kine-input", bpo::value()->default_value(""), "Use a pregenerated kinematic .root file. The optional \':\' character with a number after it can be used to infer number of events to skip on the input file."); } void SimConfig::determineActiveModules(std::vector const& inputargs, std::vector const& skippedModules, std::vector& activeModules, bool isUpgrade) @@ -305,7 +304,6 @@ bool SimConfig::resetFromParsedMap(boost::program_options::variables_map const& mConfigData.mTrigger = vm["trigger"].as(); mConfigData.mNEvents = vm["nEvents"].as(); mConfigData.mExtKinFileName = vm["extKinFile"].as(); - mConfigData.mKineInput = vm["kine-input"].as(); mConfigData.mEmbedIntoFileName = vm["embedIntoFile"].as(); mConfigData.mStartEvent = vm["startEvent"].as(); mConfigData.mBMax = vm["bMax"].as(); diff --git a/run/o2sim_parallel.cxx b/run/o2sim_parallel.cxx index 0475340970a75..24be9743e6a03 100644 --- a/run/o2sim_parallel.cxx +++ b/run/o2sim_parallel.cxx @@ -512,46 +512,6 @@ int main(int argc, char* argv[]) } return r; } - // check if Kinematics input file is provided - LOG(info) << "Kinematics input file: " << conf.getKineInput(); - if (conf.getKineInput().size() > 0) { - std::string path = conf.getKineInput(); - std::size_t pos = path.find(':'); - std::string kinefilename; - int ntf = 1; - if (pos != std::string::npos) { - kinefilename = path.substr(0, pos); - ntf = std::stoi(path.substr(pos + 1)); - } else { - kinefilename = path; - } - LOG(info) << "Using Kinematics input file: " << kinefilename << ", TimeFrame number: " << ntf; - TFile kinefile(kinefilename.c_str(), "READ"); - if (kinefile.IsZombie()) { - LOG(fatal) << "Could not open Kinematics input file: " << kinefilename; - return 2; - } - TFile splitkinefile(Form("%s_Kine.root", conf.getOutPrefix().c_str()), "RECREATE"); - TTree* kine = (TTree*)kinefile.Get("o2sim"); - const int nentries = kine->GetEntries(); - const int nevsim = conf.getNEvents(); - TTree* kineout = kine->CloneTree(0); - ntf -= 1; - if ((ntf + 1) * nevsim > kine->GetEntries()) { - LOG(fatal) << "Not enough events in the input file to get the entries in the interval [" << ntf * nevsim << ',' << (ntf + 1) * nevsim << "]"; - return 2; - } - for (int i = ntf * nevsim; i < (ntf + 1) * nevsim; ++i) { - kine->GetEntry(i); - kineout->Fill(); - } - splitkinefile.Write(); - kinefile.Close(); - splitkinefile.Close(); - LOG(info) << "Kinematics input file processed successfully"; - LOG(info) << "Splitting time took " << timer.RealTime() << " s"; - return 0; - } gAskedEvents = conf.getNEvents(); if (conf.asService()) { From d8e70e111d7a6b3d1b3f5de0693e30e9447cd60e Mon Sep 17 00:00:00 2001 From: Marco Giacalone Date: Tue, 29 Oct 2024 14:50:14 +0100 Subject: [PATCH 10/14] Deleted feature for RUN2 based generator --- Generators/include/Generators/GeneratorFromFile.h | 1 - Generators/include/Generators/GeneratorFromO2KineParam.h | 2 +- Generators/src/GeneratorFromFile.cxx | 7 ------- 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/Generators/include/Generators/GeneratorFromFile.h b/Generators/include/Generators/GeneratorFromFile.h index b180f981f8b88..14a74db8dbc57 100644 --- a/Generators/include/Generators/GeneratorFromFile.h +++ b/Generators/include/Generators/GeneratorFromFile.h @@ -59,7 +59,6 @@ class GeneratorFromFile : public FairGenerator int mEventsAvailable = 0; bool mSkipNonTrackable = true; //! whether to pass non-trackable (decayed particles) to the MC stack bool mFixOffShell = true; // fix particles with M_assigned != M_calculated - TGrid* mAlienInstance = nullptr; // a cached connection to TGrid (needed for Alien locations) ClassDefOverride(GeneratorFromFile, 1); }; diff --git a/Generators/include/Generators/GeneratorFromO2KineParam.h b/Generators/include/Generators/GeneratorFromO2KineParam.h index 5f384ab6d4fee..298d52ba0a1f9 100644 --- a/Generators/include/Generators/GeneratorFromO2KineParam.h +++ b/Generators/include/Generators/GeneratorFromO2KineParam.h @@ -25,7 +25,7 @@ namespace eventgen /** ** a parameter class/struct to keep the settings of ** the FromO2Kine event generator and - ** allow the user to modify them + ** allow the user to modify them **/ struct GeneratorFromO2KineParam : public o2::conf::ConfigurableParamHelper { diff --git a/Generators/src/GeneratorFromFile.cxx b/Generators/src/GeneratorFromFile.cxx index 80f86ad2f3d2f..1299191d0aa23 100644 --- a/Generators/src/GeneratorFromFile.cxx +++ b/Generators/src/GeneratorFromFile.cxx @@ -29,13 +29,6 @@ namespace eventgen { GeneratorFromFile::GeneratorFromFile(const char* name) { - if (strncmp(name, "alien:/", 7) == 0) { - mAlienInstance = TGrid::Connect("alien"); - if (!mAlienInstance) { - LOG(fatal) << "Could not connect to alien, did you check the alien token?"; - return; - } - } mEventFile = TFile::Open(name); if (mEventFile == nullptr) { LOG(fatal) << "EventFile " << name << " not found \n"; From 335f4c9eb5f1aefdf2aec18804f80d746c939c5e Mon Sep 17 00:00:00 2001 From: Marco Giacalone Date: Wed, 30 Oct 2024 09:47:28 +0100 Subject: [PATCH 11/14] Revert "Add SMatrixGPU compatibility to trackParCov (#13602)" This reverts commit 6a2cc7e940863599154897007ac556cb51e72f59. --- .../MathUtils/include/MathUtils/SMatrixGPU.h | 37 ------------------- .../TrackParametrizationWithError.h | 13 +++---- .../src/TrackParametrizationWithError.cxx | 31 ++++++++-------- 3 files changed, 22 insertions(+), 59 deletions(-) diff --git a/Common/MathUtils/include/MathUtils/SMatrixGPU.h b/Common/MathUtils/include/MathUtils/SMatrixGPU.h index 60965a4fa2776..ef76c490ddfbd 100644 --- a/Common/MathUtils/include/MathUtils/SMatrixGPU.h +++ b/Common/MathUtils/include/MathUtils/SMatrixGPU.h @@ -446,8 +446,6 @@ class SMatrixGPU GPUdi() SMatrixGPU(SMatrixNoInit) {} GPUd() SMatrixGPU(SMatrixIdentity); GPUd() SMatrixGPU(const SMatrixGPU& rhs); - template - GPUd() SMatrixGPU(const SMatrixGPU& rhs); template GPUd() SMatrixGPU(const Expr& rhs); template @@ -499,11 +497,6 @@ class SMatrixGPU GPUd() SMatrixRowGPU operator[](unsigned int i) { return SMatrixRowGPU(*this, i); } template GPUd() SMatrixGPU& operator+=(const SMatrixGPU& rhs); - GPUd() SMatrixGPU& operator*=(const T& rhs); - template - GPUd() SMatrixGPU& operator*=(const SMatrixGPU& rhs); - template - GPUd() SMatrixGPU& operator*=(const Expr& rhs); GPUd() bool Invert(); GPUd() bool IsInUse(const T* p) const; @@ -535,13 +528,6 @@ GPUdi() SMatrixGPU::SMatrixGPU(const SMatrixGPU& rhs mRep = rhs.mRep; } -template -template -GPUd() SMatrixGPU::SMatrixGPU(const SMatrixGPU& rhs) -{ - operator=(rhs); -} - template GPUdi() T* SMatrixGPU::begin() { @@ -1401,29 +1387,6 @@ GPUdi() SMatrixGPU& SMatrixGPU::operator+=(const SMa return *this; } -template -GPUdi() SMatrixGPU& SMatrixGPU::operator*=(const T & rhs) -{ - for (unsigned int i = 0; i < R::kSize; ++i) { - mRep.Array()[i] *= rhs; - } - return *this; -} - -template -template -GPUdi() SMatrixGPU& SMatrixGPU::operator*=(const SMatrixGPU& rhs) -{ - return operator=(*this* rhs); -} - -template -template -GPUdi() SMatrixGPU& SMatrixGPU::operator*=(const Expr& rhs) -{ - return operator=(*this* rhs); -} - template struct TranspPolicyGPU { enum { diff --git a/DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackParametrizationWithError.h b/DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackParametrizationWithError.h index 015b5d37e258c..536bacf1a6a70 100644 --- a/DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackParametrizationWithError.h +++ b/DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackParametrizationWithError.h @@ -18,7 +18,6 @@ #define INCLUDE_RECONSTRUCTIONDATAFORMATS_TRACKPARAMETRIZATIONWITHERROR_H_ #include "ReconstructionDataFormats/TrackParametrization.h" -#include namespace o2 { @@ -39,8 +38,8 @@ class TrackParametrizationWithError : public TrackParametrization #endif using covMat_t = gpu::gpustd::array; - using MatrixDSym5 = o2::math_utils::SMatrix>; - using MatrixD5 = o2::math_utils::SMatrix>; + using MatrixDSym5 = ROOT::Math::SMatrix>; + using MatrixD5 = ROOT::Math::SMatrix>; GPUd() TrackParametrizationWithError(); GPUd() TrackParametrizationWithError(value_t x, value_t alpha, const params_t& par, const covMat_t& cov, int charge = 1, const PID pid = PID::Pion); @@ -101,12 +100,12 @@ class TrackParametrizationWithError : public TrackParametrization template GPUd() value_t getPredictedChi2(const BaseCluster& p) const; - GPUd() void buildCombinedCovMatrix(const TrackParametrizationWithError& rhs, MatrixDSym5& cov) const; - GPUd() value_t getPredictedChi2(const TrackParametrizationWithError& rhs, MatrixDSym5& covToSet) const; + void buildCombinedCovMatrix(const TrackParametrizationWithError& rhs, MatrixDSym5& cov) const; + value_t getPredictedChi2(const TrackParametrizationWithError& rhs, MatrixDSym5& covToSet) const; GPUd() value_t getPredictedChi2(const TrackParametrizationWithError& rhs) const; GPUd() value_t getPredictedChi2Quiet(const TrackParametrizationWithError& rhs) const; - GPUd() bool update(const TrackParametrizationWithError& rhs, const MatrixDSym5& covInv); - GPUd() bool update(const TrackParametrizationWithError& rhs); + bool update(const TrackParametrizationWithError& rhs, const MatrixDSym5& covInv); + bool update(const TrackParametrizationWithError& rhs); GPUd() bool update(const dim2_t& p, const dim3_t& cov); GPUd() bool update(const value_t* p, const value_t* cov); diff --git a/DataFormats/Reconstruction/src/TrackParametrizationWithError.cxx b/DataFormats/Reconstruction/src/TrackParametrizationWithError.cxx index 0dd4a4441c0b3..e56830deace14 100644 --- a/DataFormats/Reconstruction/src/TrackParametrizationWithError.cxx +++ b/DataFormats/Reconstruction/src/TrackParametrizationWithError.cxx @@ -14,14 +14,11 @@ #include "ReconstructionDataFormats/DCA.h" #include -#ifndef __OPENCL__ -#include -#else -#include -#endif - #ifndef GPUCA_GPUCODE_DEVICE #include +#ifndef GPUCA_STANDALONE +#include "Math/SMatrix.h" +#endif #endif #ifndef GPUCA_ALIGPUCODE @@ -757,17 +754,11 @@ GPUd() auto TrackParametrizationWithError::getPredictedChi2Quiet(const return (d * (szz * d - sdz * z) + z * (sdd * z - d * sdz)) / det; } -//______________________________________________ -template -GPUd() auto TrackParametrizationWithError::getPredictedChi2(const TrackParametrizationWithError& rhs) const -> value_t -{ - MatrixDSym5 cov; // perform matrix operations in double! - return getPredictedChi2(rhs, cov); -} +#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE) // Disable function relying on ROOT SMatrix on GPU //______________________________________________ template -GPUd() void TrackParametrizationWithError::buildCombinedCovMatrix(const TrackParametrizationWithError& rhs, MatrixDSym5& cov) const +void TrackParametrizationWithError::buildCombinedCovMatrix(const TrackParametrizationWithError& rhs, MatrixDSym5& cov) const { // fill combined cov.matrix (NOT inverted) cov(kY, kY) = static_cast(getSigmaY2()) + static_cast(rhs.getSigmaY2()); @@ -787,6 +778,14 @@ GPUd() void TrackParametrizationWithError::buildCombinedCovMatrix(const cov(kQ2Pt, kQ2Pt) = static_cast(getSigma1Pt2()) + static_cast(rhs.getSigma1Pt2()); } +//______________________________________________ +template +GPUd() auto TrackParametrizationWithError::getPredictedChi2(const TrackParametrizationWithError& rhs) const -> value_t +{ + MatrixDSym5 cov; // perform matrix operations in double! + return getPredictedChi2(rhs, cov); +} + //______________________________________________ template GPUd() auto TrackParametrizationWithError::getPredictedChi2(const TrackParametrizationWithError& rhs, MatrixDSym5& covToSet) const -> value_t @@ -868,7 +867,7 @@ GPUd() bool TrackParametrizationWithError::update(const TrackParametriz } // updated covariance: Cov0 = Cov0 - K*Cov0 - matK *= o2::math_utils::SMatrix>(matC0); + matK *= ROOT::Math::SMatrix>(matC0); mC[kSigY2] -= matK(kY, kY); mC[kSigZY] -= matK(kZ, kY); mC[kSigZ2] -= matK(kZ, kZ); @@ -902,6 +901,8 @@ GPUd() bool TrackParametrizationWithError::update(const TrackParametriz return update(rhs, covI); } +#endif + //______________________________________________ template GPUd() bool TrackParametrizationWithError::update(const value_t* p, const value_t* cov) From 983ce32505f2a542c119ecdc0b0d631beba277a4 Mon Sep 17 00:00:00 2001 From: Marco Giacalone Date: Wed, 30 Oct 2024 09:49:18 +0100 Subject: [PATCH 12/14] Revert "Merge branch 'eventpool1' into eventpool" This reverts commit 2d3b69218d6f235f2a63846d5025df171bf92503, reversing changes made to c9a5dad46522d515a7bdf50a3a992dc3f123c90f. --- Generators/CMakeLists.txt | 4 - .../include/Generators/GeneratorFromFile.h | 1 - .../include/Generators/GeneratorHybrid.h | 63 ------- .../include/Generators/GeneratorHybridParam.h | 42 ----- Generators/src/GeneratorFactory.cxx | 15 -- Generators/src/GeneratorFromFile.cxx | 7 - Generators/src/GeneratorHybrid.cxx | 178 ------------------ Generators/src/GeneratorHybridParam.cxx | 15 -- Generators/src/GeneratorsLinkDef.h | 2 - 9 files changed, 327 deletions(-) delete mode 100644 Generators/include/Generators/GeneratorHybrid.h delete mode 100644 Generators/include/Generators/GeneratorHybridParam.h delete mode 100644 Generators/src/GeneratorHybrid.cxx delete mode 100644 Generators/src/GeneratorHybridParam.cxx diff --git a/Generators/CMakeLists.txt b/Generators/CMakeLists.txt index 3b32d076aec1a..855ac1adfe888 100644 --- a/Generators/CMakeLists.txt +++ b/Generators/CMakeLists.txt @@ -24,8 +24,6 @@ o2_add_library(Generators src/GeneratorTGenerator.cxx src/GeneratorExternalParam.cxx src/GeneratorFromFile.cxx - src/GeneratorHybrid.cxx - src/GeneratorHybridParam.cxx src/GeneratorFromO2KineParam.cxx src/GeneratorFileOrCmd.cxx src/GeneratorFileOrCmdParam.cxx @@ -70,8 +68,6 @@ set(headers include/Generators/GeneratorTGenerator.h include/Generators/GeneratorExternalParam.h include/Generators/GeneratorFromFile.h - include/Generators/GeneratorHybrid.h - include/Generators/GeneratorHybridParam.h include/Generators/GeneratorFromO2KineParam.h include/Generators/GeneratorFileOrCmd.h include/Generators/GeneratorFileOrCmdParam.h diff --git a/Generators/include/Generators/GeneratorFromFile.h b/Generators/include/Generators/GeneratorFromFile.h index b180f981f8b88..14a74db8dbc57 100644 --- a/Generators/include/Generators/GeneratorFromFile.h +++ b/Generators/include/Generators/GeneratorFromFile.h @@ -59,7 +59,6 @@ class GeneratorFromFile : public FairGenerator int mEventsAvailable = 0; bool mSkipNonTrackable = true; //! whether to pass non-trackable (decayed particles) to the MC stack bool mFixOffShell = true; // fix particles with M_assigned != M_calculated - TGrid* mAlienInstance = nullptr; // a cached connection to TGrid (needed for Alien locations) ClassDefOverride(GeneratorFromFile, 1); }; diff --git a/Generators/include/Generators/GeneratorHybrid.h b/Generators/include/Generators/GeneratorHybrid.h deleted file mode 100644 index 3d3bff77463e9..0000000000000 --- a/Generators/include/Generators/GeneratorHybrid.h +++ /dev/null @@ -1,63 +0,0 @@ -// 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. - -/// \author M. Giacalone - October 2024 - -#ifndef ALICEO2_EVENTGEN_GENERATORHYBRID_H_ -#define ALICEO2_EVENTGEN_GENERATORHYBRID_H_ - -#include "Generators/Generator.h" -#include "Generators/BoxGenerator.h" -#include -#include -#include "SimulationDataFormat/MCEventHeader.h" -#include "SimulationDataFormat/MCGenProperties.h" -#include "SimulationDataFormat/ParticleStatus.h" -#include "Generators/GeneratorHybridParam.h" -#include "Generators/GeneratorFromO2KineParam.h" -#include -#include - -namespace o2 -{ -namespace eventgen -{ - -class GeneratorHybrid : public Generator -{ - - public: - GeneratorHybrid() = default; - GeneratorHybrid(std::vector gens); - ~GeneratorHybrid() = default; - - Bool_t Init() override; - Bool_t generateEvent() override; - Bool_t importParticles() override; - - private: - o2::eventgen::Generator* currentgen = nullptr; - std::vector> gens; - const std::vector generatorNames = {"extkinO2", "boxgen", "external", "pythia8", "pythia8pp", "pythia8hi", "pythia8hf", "pythia8powheg"}; - std::vector mGens; - std::vector mConfigs; - std::vector mConfsPythia8; - bool mRandomize = false; - std::vector mFractions; - int mseqCounter = 0; - int mCurrentFraction = 0; - int mIndex = 0; -}; - -} // namespace eventgen -} // namespace o2 - -#endif diff --git a/Generators/include/Generators/GeneratorHybridParam.h b/Generators/include/Generators/GeneratorHybridParam.h deleted file mode 100644 index 4e237d8e4005e..0000000000000 --- a/Generators/include/Generators/GeneratorHybridParam.h +++ /dev/null @@ -1,42 +0,0 @@ -// 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. - -/// \author M. Giacalone - October 2024 - -#ifndef ALICEO2_EVENTGEN_GENERATORHYBRIDPARAM_H_ -#define ALICEO2_EVENTGEN_GENERATORHYBRIDPARAM_H_ - -#include "CommonUtils/ConfigurableParam.h" -#include "CommonUtils/ConfigurableParamHelper.h" - -namespace o2 -{ -namespace eventgen -{ - -/** - ** a parameter class/struct to keep the settings of - ** the Hybrid event generator and - ** allow the user to modify them - **/ - -struct GeneratorHybridParam : public o2::conf::ConfigurableParamHelper { - std::string Generators = ""; // generators to be used in the cocktail, each divided by a comma - std::string Configs = ""; // configurations for the generators, each divided by a colon - bool Randomize = false; // randomize the order of the generators, if not generator using fractions - std::string Fractions = ""; // events fractions for each generator, works only for sequence - O2ParamDef(GeneratorHybridParam, "GeneratorHybrid"); -}; - -} // end namespace eventgen -} // end namespace o2 - -#endif // ALICEO2_EVENTGEN_GENERATORHYBRIDPARAM_H_ diff --git a/Generators/src/GeneratorFactory.cxx b/Generators/src/GeneratorFactory.cxx index 94d9733484b47..5b3a5b5330617 100644 --- a/Generators/src/GeneratorFactory.cxx +++ b/Generators/src/GeneratorFactory.cxx @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #ifdef GENERATORS_WITH_PYTHIA8 @@ -27,7 +26,6 @@ #endif #include #include -#include #include "Generators/GeneratorFromO2KineParam.h" #ifdef GENERATORS_WITH_HEPMC3 #include @@ -242,19 +240,6 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair primGen->AddGenerator(boxGen); } } - } else if (genconfig.compare("hybrid") == 0) { // hybrid using multiple generators - LOG(info) << "Init hybrid generator"; - auto& hybridparam = GeneratorHybridParam::Instance(); - std::string genslist = hybridparam.Generators; - LOG(info) << "Generators list: " << genslist; - std::vector generators; - std::stringstream ss(genslist); - std::string item; - while (std::getline(ss, item, ',')) { - generators.push_back(item); - } - auto hybrid = new o2::eventgen::GeneratorHybrid(generators); - primGen->AddGenerator(hybrid); } else { LOG(fatal) << "Invalid generator"; } diff --git a/Generators/src/GeneratorFromFile.cxx b/Generators/src/GeneratorFromFile.cxx index 80f86ad2f3d2f..1299191d0aa23 100644 --- a/Generators/src/GeneratorFromFile.cxx +++ b/Generators/src/GeneratorFromFile.cxx @@ -29,13 +29,6 @@ namespace eventgen { GeneratorFromFile::GeneratorFromFile(const char* name) { - if (strncmp(name, "alien:/", 7) == 0) { - mAlienInstance = TGrid::Connect("alien"); - if (!mAlienInstance) { - LOG(fatal) << "Could not connect to alien, did you check the alien token?"; - return; - } - } mEventFile = TFile::Open(name); if (mEventFile == nullptr) { LOG(fatal) << "EventFile " << name << " not found \n"; diff --git a/Generators/src/GeneratorHybrid.cxx b/Generators/src/GeneratorHybrid.cxx deleted file mode 100644 index ab0be5501e0db..0000000000000 --- a/Generators/src/GeneratorHybrid.cxx +++ /dev/null @@ -1,178 +0,0 @@ -// 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. - -#include "Generators/GeneratorHybrid.h" -#include -#include - -namespace o2 -{ - namespace eventgen - { - GeneratorHybrid::GeneratorHybrid(std::vector inputgens) - { - auto configs = GeneratorHybridParam::Instance().Configs; - mRandomize = GeneratorHybridParam::Instance().Randomize; - std::stringstream ss(configs); - std::string conf; - while (std::getline(ss, conf, ':')) { - mConfigs.push_back(conf); - } - if(mConfigs.size() != inputgens.size()){ - LOG(fatal) << "Number of configurations does not match the number of generators"; - } - if(mConfigs.size() == 0){ - for(auto gen : inputgens){ - mConfigs.push_back(""); - } - } - int index = 0; - if (!mRandomize) { - std::string fractions = GeneratorHybridParam::Instance().Fractions; - if(fractions.compare("") == 0){ - for (auto gen : inputgens) { - mFractions.push_back(1); - } - } - else{ - std::stringstream streamfrac(fractions); - std::string frac; - while (std::getline(streamfrac, frac, ',')) { - if(frac.compare("") == 0) - mFractions.push_back(1); - else - mFractions.push_back(std::stoi(frac)); - } - if(mFractions.size() != inputgens.size()){ - LOG(fatal) << "Number of fractions does not match the number of generators"; - return; - } - // Check if all elements of mFractions are 0 - if (std::all_of(mFractions.begin(), mFractions.end(), [](int i){ return i == 0; })) { - LOG(fatal) << "All fractions provided are 0, no simulation will be performed"; - return; - } - - } - } - for(auto gen : inputgens) - { - // Search if the generator name is inside generatorNames (which is a vector of strings) - LOG(info) << "Checking if generator " << gen << " is in the list of available generators \n"; - if (std::find(generatorNames.begin(), generatorNames.end(), gen) != generatorNames.end()) - { - LOG(info) << "Found generator " << gen << " in the list of available generators \n"; - if (gen.compare("boxgen") == 0) { - if (mConfigs[index].compare("") == 0) { - gens.push_back(std::make_unique()); - } else { - std::stringstream ss(mConfigs[index]); - std::string pars; - std::vector params; - while (std::getline(ss, pars, ',')) { - params.push_back(std::stod(pars)); - } - gens.push_back(std::make_unique(int(params[0]), int(params[1]), params[2], params[3], params[4], params[5], params[6], params[7])); - } - mGens.push_back(gen); - } else if (gen.compare(0, 7, "pythia8") == 0) { - gens.push_back(std::make_unique()); - mConfsPythia8.push_back(mConfigs[index]); - mGens.push_back(gen); - } else if(gen.compare("extkinO2") == 0){ - gens.push_back(std::make_unique(mConfigs[index].c_str())); - mGens.push_back(gen); - } else { - LOG(info) << "Generator " << gen << " not found in the list of available generators \n"; - } - } - index++; - } - } - - Bool_t GeneratorHybrid::Init() - { - // init all sub-gens - int count = 0; - for (auto& gen : gens) - { - if (mGens[count] == "pythia8"){ - auto config = std::string(std::getenv("O2_ROOT")) + mConfsPythia8[count]; - LOG(info) << "Setting \'Pythia8\' base configuration: " << config << std::endl; - dynamic_cast(gen.get())->setConfig(config); - } else if (mGens[count] == "pythia8pp"){ - auto config = std::string(std::getenv("O2_ROOT")) + "/share/Generators/egconfig/pythia8_inel.cfg"; - LOG(info) << "Setting \'Pythia8\' base configuration: " << config << std::endl; - dynamic_cast(gen.get())->setConfig(config); - } else if (mGens[count] == "pythia8hf") { - auto config = std::string(std::getenv("O2_ROOT")) + "/share/Generators/egconfig/pythia8_hf.cfg"; - LOG(info) << "Setting \'Pythia8\' base configuration: " << config << std::endl; - dynamic_cast(gen.get())->setConfig(config); - } else if (mGens[count] == "pythia8hi") { - auto config = std::string(std::getenv("O2_ROOT")) + "/share/Generators/egconfig/pythia8_hi.cfg"; - LOG(info) << "Setting \'Pythia8\' base configuration: " << config << std::endl; - dynamic_cast(gen.get())->setConfig(config); - } else if (mGens[count] == "pythia8powheg") { - auto config = std::string(std::getenv("O2_ROOT")) + "/share/Generators/egconfig/pythia8_powheg.cfg"; - LOG(info) << "Setting \'Pythia8\' base configuration: " << config << std::endl; - dynamic_cast(gen.get())->setConfig(config); - } - gen->Init(); - addSubGenerator(count, mGens[count]); - count++; - } - return Generator::Init(); - } - - Bool_t GeneratorHybrid::generateEvent() - { - // Order randomisation or sequence of generators - // following provided fractions, if not generators are used in proper sequence - if (mRandomize) { - mIndex = gRandom->Integer(gens.size()); - } else { - while (mFractions[mCurrentFraction] == 0 || mseqCounter == mFractions[mCurrentFraction]) { - if (mFractions[mCurrentFraction] != 0) - mseqCounter = 0; - mCurrentFraction = (mCurrentFraction + 1) % mFractions.size(); - } - mIndex = mCurrentFraction; - } - LOG(info) << "GeneratorHybrid: generating event with generator " << mGens[mIndex]; - gens[mIndex]->clearParticles(); // clear container of this class - gens[mIndex]->generateEvent(); - // notify the sub event generator - notifySubGenerator(mIndex); - mseqCounter++; - return true; - } - - Bool_t GeneratorHybrid::importParticles() - { - mParticles.clear(); // clear container of mother class - gens[mIndex]->importParticles(); - std::copy(gens[mIndex]->getParticles().begin(), gens[mIndex]->getParticles().end(), std::back_insert_iterator(mParticles)); - - // we need to fix particles statuses --> need to enforce this on the importParticles level of individual generators - for (auto& p : mParticles) - { - auto st = o2::mcgenstatus::MCGenStatusEncoding(p.GetStatusCode(), p.GetStatusCode()).fullEncoding; - p.SetStatusCode(st); - p.SetBit(ParticleStatus::kToBeDone, true); - } - - return true; - } - - } // namespace eventgen -} // namespace o2 - -ClassImp(o2::eventgen::GeneratorHybrid); \ No newline at end of file diff --git a/Generators/src/GeneratorHybridParam.cxx b/Generators/src/GeneratorHybridParam.cxx deleted file mode 100644 index e15fbb8ee4ba4..0000000000000 --- a/Generators/src/GeneratorHybridParam.cxx +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -/// \author M. Giacalone - October 2024 - -#include "Generators/GeneratorHybridParam.h" -O2ParamImpl(o2::eventgen::GeneratorHybridParam); \ No newline at end of file diff --git a/Generators/src/GeneratorsLinkDef.h b/Generators/src/GeneratorsLinkDef.h index 013dfe6080933..222004e0957cb 100644 --- a/Generators/src/GeneratorsLinkDef.h +++ b/Generators/src/GeneratorsLinkDef.h @@ -51,8 +51,6 @@ #endif #pragma link C++ class o2::eventgen::GeneratorFromFile + ; #pragma link C++ class o2::eventgen::GeneratorFromO2Kine + ; -#pragma link C++ class o2::eventgen::GeneratorHybrid + ; -#pragma link C++ class o2::eventgen::GeneratorHybridParam + ; #pragma link C++ class o2::eventgen::GeneratorFromO2KineParam + ; #pragma link C++ class o2::conf::ConfigurableParamHelper < o2::eventgen::GeneratorFromO2KineParam> + ; #pragma link C++ class o2::eventgen::PrimaryGenerator + ; From b465c39011bce04f0ffe2a0b0ccc208bd42e25d7 Mon Sep 17 00:00:00 2001 From: Marco Giacalone Date: Wed, 30 Oct 2024 10:08:47 +0100 Subject: [PATCH 13/14] Reapply "Add SMatrixGPU compatibility to trackParCov (#13602)" This reverts commit 335f4c9eb5f1aefdf2aec18804f80d746c939c5e. --- .../MathUtils/include/MathUtils/SMatrixGPU.h | 37 +++++++++++++++++++ .../TrackParametrizationWithError.h | 13 ++++--- .../src/TrackParametrizationWithError.cxx | 31 ++++++++-------- 3 files changed, 59 insertions(+), 22 deletions(-) diff --git a/Common/MathUtils/include/MathUtils/SMatrixGPU.h b/Common/MathUtils/include/MathUtils/SMatrixGPU.h index ef76c490ddfbd..60965a4fa2776 100644 --- a/Common/MathUtils/include/MathUtils/SMatrixGPU.h +++ b/Common/MathUtils/include/MathUtils/SMatrixGPU.h @@ -446,6 +446,8 @@ class SMatrixGPU GPUdi() SMatrixGPU(SMatrixNoInit) {} GPUd() SMatrixGPU(SMatrixIdentity); GPUd() SMatrixGPU(const SMatrixGPU& rhs); + template + GPUd() SMatrixGPU(const SMatrixGPU& rhs); template GPUd() SMatrixGPU(const Expr& rhs); template @@ -497,6 +499,11 @@ class SMatrixGPU GPUd() SMatrixRowGPU operator[](unsigned int i) { return SMatrixRowGPU(*this, i); } template GPUd() SMatrixGPU& operator+=(const SMatrixGPU& rhs); + GPUd() SMatrixGPU& operator*=(const T& rhs); + template + GPUd() SMatrixGPU& operator*=(const SMatrixGPU& rhs); + template + GPUd() SMatrixGPU& operator*=(const Expr& rhs); GPUd() bool Invert(); GPUd() bool IsInUse(const T* p) const; @@ -528,6 +535,13 @@ GPUdi() SMatrixGPU::SMatrixGPU(const SMatrixGPU& rhs mRep = rhs.mRep; } +template +template +GPUd() SMatrixGPU::SMatrixGPU(const SMatrixGPU& rhs) +{ + operator=(rhs); +} + template GPUdi() T* SMatrixGPU::begin() { @@ -1387,6 +1401,29 @@ GPUdi() SMatrixGPU& SMatrixGPU::operator+=(const SMa return *this; } +template +GPUdi() SMatrixGPU& SMatrixGPU::operator*=(const T & rhs) +{ + for (unsigned int i = 0; i < R::kSize; ++i) { + mRep.Array()[i] *= rhs; + } + return *this; +} + +template +template +GPUdi() SMatrixGPU& SMatrixGPU::operator*=(const SMatrixGPU& rhs) +{ + return operator=(*this* rhs); +} + +template +template +GPUdi() SMatrixGPU& SMatrixGPU::operator*=(const Expr& rhs) +{ + return operator=(*this* rhs); +} + template struct TranspPolicyGPU { enum { diff --git a/DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackParametrizationWithError.h b/DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackParametrizationWithError.h index 536bacf1a6a70..015b5d37e258c 100644 --- a/DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackParametrizationWithError.h +++ b/DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackParametrizationWithError.h @@ -18,6 +18,7 @@ #define INCLUDE_RECONSTRUCTIONDATAFORMATS_TRACKPARAMETRIZATIONWITHERROR_H_ #include "ReconstructionDataFormats/TrackParametrization.h" +#include namespace o2 { @@ -38,8 +39,8 @@ class TrackParametrizationWithError : public TrackParametrization #endif using covMat_t = gpu::gpustd::array; - using MatrixDSym5 = ROOT::Math::SMatrix>; - using MatrixD5 = ROOT::Math::SMatrix>; + using MatrixDSym5 = o2::math_utils::SMatrix>; + using MatrixD5 = o2::math_utils::SMatrix>; GPUd() TrackParametrizationWithError(); GPUd() TrackParametrizationWithError(value_t x, value_t alpha, const params_t& par, const covMat_t& cov, int charge = 1, const PID pid = PID::Pion); @@ -100,12 +101,12 @@ class TrackParametrizationWithError : public TrackParametrization template GPUd() value_t getPredictedChi2(const BaseCluster& p) const; - void buildCombinedCovMatrix(const TrackParametrizationWithError& rhs, MatrixDSym5& cov) const; - value_t getPredictedChi2(const TrackParametrizationWithError& rhs, MatrixDSym5& covToSet) const; + GPUd() void buildCombinedCovMatrix(const TrackParametrizationWithError& rhs, MatrixDSym5& cov) const; + GPUd() value_t getPredictedChi2(const TrackParametrizationWithError& rhs, MatrixDSym5& covToSet) const; GPUd() value_t getPredictedChi2(const TrackParametrizationWithError& rhs) const; GPUd() value_t getPredictedChi2Quiet(const TrackParametrizationWithError& rhs) const; - bool update(const TrackParametrizationWithError& rhs, const MatrixDSym5& covInv); - bool update(const TrackParametrizationWithError& rhs); + GPUd() bool update(const TrackParametrizationWithError& rhs, const MatrixDSym5& covInv); + GPUd() bool update(const TrackParametrizationWithError& rhs); GPUd() bool update(const dim2_t& p, const dim3_t& cov); GPUd() bool update(const value_t* p, const value_t* cov); diff --git a/DataFormats/Reconstruction/src/TrackParametrizationWithError.cxx b/DataFormats/Reconstruction/src/TrackParametrizationWithError.cxx index e56830deace14..0dd4a4441c0b3 100644 --- a/DataFormats/Reconstruction/src/TrackParametrizationWithError.cxx +++ b/DataFormats/Reconstruction/src/TrackParametrizationWithError.cxx @@ -14,11 +14,14 @@ #include "ReconstructionDataFormats/DCA.h" #include +#ifndef __OPENCL__ +#include +#else +#include +#endif + #ifndef GPUCA_GPUCODE_DEVICE #include -#ifndef GPUCA_STANDALONE -#include "Math/SMatrix.h" -#endif #endif #ifndef GPUCA_ALIGPUCODE @@ -754,11 +757,17 @@ GPUd() auto TrackParametrizationWithError::getPredictedChi2Quiet(const return (d * (szz * d - sdz * z) + z * (sdd * z - d * sdz)) / det; } -#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE) // Disable function relying on ROOT SMatrix on GPU +//______________________________________________ +template +GPUd() auto TrackParametrizationWithError::getPredictedChi2(const TrackParametrizationWithError& rhs) const -> value_t +{ + MatrixDSym5 cov; // perform matrix operations in double! + return getPredictedChi2(rhs, cov); +} //______________________________________________ template -void TrackParametrizationWithError::buildCombinedCovMatrix(const TrackParametrizationWithError& rhs, MatrixDSym5& cov) const +GPUd() void TrackParametrizationWithError::buildCombinedCovMatrix(const TrackParametrizationWithError& rhs, MatrixDSym5& cov) const { // fill combined cov.matrix (NOT inverted) cov(kY, kY) = static_cast(getSigmaY2()) + static_cast(rhs.getSigmaY2()); @@ -778,14 +787,6 @@ void TrackParametrizationWithError::buildCombinedCovMatrix(const TrackP cov(kQ2Pt, kQ2Pt) = static_cast(getSigma1Pt2()) + static_cast(rhs.getSigma1Pt2()); } -//______________________________________________ -template -GPUd() auto TrackParametrizationWithError::getPredictedChi2(const TrackParametrizationWithError& rhs) const -> value_t -{ - MatrixDSym5 cov; // perform matrix operations in double! - return getPredictedChi2(rhs, cov); -} - //______________________________________________ template GPUd() auto TrackParametrizationWithError::getPredictedChi2(const TrackParametrizationWithError& rhs, MatrixDSym5& covToSet) const -> value_t @@ -867,7 +868,7 @@ GPUd() bool TrackParametrizationWithError::update(const TrackParametriz } // updated covariance: Cov0 = Cov0 - K*Cov0 - matK *= ROOT::Math::SMatrix>(matC0); + matK *= o2::math_utils::SMatrix>(matC0); mC[kSigY2] -= matK(kY, kY); mC[kSigZY] -= matK(kZ, kY); mC[kSigZ2] -= matK(kZ, kZ); @@ -901,8 +902,6 @@ GPUd() bool TrackParametrizationWithError::update(const TrackParametriz return update(rhs, covI); } -#endif - //______________________________________________ template GPUd() bool TrackParametrizationWithError::update(const value_t* p, const value_t* cov) From 84619f15dc20006a4f5e6219e5e0d0f974999184 Mon Sep 17 00:00:00 2001 From: Marco Giacalone Date: Wed, 30 Oct 2024 13:42:13 +0100 Subject: [PATCH 14/14] Better rotation handling --- Generators/src/GeneratorFromFile.cxx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Generators/src/GeneratorFromFile.cxx b/Generators/src/GeneratorFromFile.cxx index 1299191d0aa23..d3cd7b967c4d5 100644 --- a/Generators/src/GeneratorFromFile.cxx +++ b/Generators/src/GeneratorFromFile.cxx @@ -279,11 +279,13 @@ bool GeneratorFromO2Kine::importParticles() auto px = t.Px(); auto py = t.Py(); if (mRandomPhi) { - auto phi = TMath::ATan2(py, px); - auto pt = TMath::Sqrt(px * px + py * py); - phi += dPhi; - px = pt * TMath::Cos(phi); - py = pt * TMath::Sin(phi); + // transformation applied through rotation matrix + auto cos = TMath::Cos(dPhi); + auto sin = TMath::Sin(dPhi); + auto newPx = px * cos - py * sin; + auto newPy = px * sin + py * cos; + px = newPx; + py = newPy; } auto pz = t.Pz(); auto vx = t.Vx();