diff --git a/DataFormats/simulation/include/SimulationDataFormat/MCEventHeader.h b/DataFormats/simulation/include/SimulationDataFormat/MCEventHeader.h index afebbbada470d..f37ce3b345dd8 100644 --- a/DataFormats/simulation/include/SimulationDataFormat/MCEventHeader.h +++ b/DataFormats/simulation/include/SimulationDataFormat/MCEventHeader.h @@ -27,67 +27,66 @@ namespace dataformats class GeneratorHeader; - /** Common keys for information in MC event header */ - struct MCInfoKeys { - /** @{ - @name HepMC3 heavy-ion fields */ - static constexpr const char* impactParameter = "Bimpact"; - static constexpr const char* nPart = "Npart"; - static constexpr const char* nPartProjectile = "Npart_proj"; - static constexpr const char* nPartTarget = "Npart_targ"; - static constexpr const char* nColl = "Ncoll"; - static constexpr const char* nCollHard = "Ncoll_hard"; - static constexpr const char* nCollNNWounded = "NColl_NNw"; - static constexpr const char* nCollNWoundedN = "NColl_NwN"; - static constexpr const char* nCollNWoundedNwounded = "NColl_NwNW"; - static constexpr const char* planeAngle = "eventPsi"; - static constexpr const char* sigmaInelNN = "sigmaInelNN"; - static constexpr const char* centrality = "centrality"; - static constexpr const char* nSpecProjectileProton = "Nspec_proj_p"; - static constexpr const char* nSpecProjectileNeutron = "Nspec_proj_n"; - static constexpr const char* nSpecTargetProton = "Nspec_targ_p"; - static constexpr const char* nSpecTargetNeutron = "Nspec_targ_n"; - /** @} */ - /** @{ - @name HepMC3 PDF information - - In principle a header can have many of these. In that case, - each set should be prefixed with "_" where "" is a - serial number. - */ - static constexpr const char* pdfParton1Id = "pdf_parton_1_id"; - static constexpr const char* pdfParton2Id = "pdf_parton_2_id"; - static constexpr const char* pdfX1 = "pdf_x1"; - static constexpr const char* pdfX2 = "pdf_x2"; - static constexpr const char* pdfScale = "pdf_scale"; - static constexpr const char* pdfXF1 = "pdf_par_x1"; - static constexpr const char* pdfXF2 = "pdf_par_x2"; - static constexpr const char* pdfCode1 = "pdf_lhc_1_id"; - static constexpr const char* pdfCode2 = "pdf_lhc_2_id"; - /** @} */ - /** @{ - @name HepMC3 cross-section information - - In principle we can have one cross section per weight. In that - case, each should be post-fixed by "_" where "" is a - serial number. These should then matcht possible names of - weights. - */ - static constexpr const char* acceptedEvents = "accepted_events"; - static constexpr const char* attemptedEvents = "attempted_events"; - static constexpr const char* xSection = "cross_section"; - static constexpr const char* xSectionError = "cross_section_error"; - /** @} */ - /** @{ - @name Common fields */ - static constexpr const char* generator = "generator"; - static constexpr const char* generatorVersion = "version"; - static constexpr const char* processName = "processName"; - static constexpr const char* processCode = "processCode"; - static constexpr const char* weight = "weight"; - /** @} */ - - }; +/** Common keys for information in MC event header */ +struct MCInfoKeys { + /** @{ +@name HepMC3 heavy-ion fields */ + static constexpr const char* impactParameter = "Bimpact"; + static constexpr const char* nPart = "Npart"; + static constexpr const char* nPartProjectile = "Npart_proj"; + static constexpr const char* nPartTarget = "Npart_targ"; + static constexpr const char* nColl = "Ncoll"; + static constexpr const char* nCollHard = "Ncoll_hard"; + static constexpr const char* nCollNNWounded = "NColl_NNw"; + static constexpr const char* nCollNWoundedN = "NColl_NwN"; + static constexpr const char* nCollNWoundedNwounded = "NColl_NwNW"; + static constexpr const char* planeAngle = "eventPsi"; + static constexpr const char* sigmaInelNN = "sigmaInelNN"; + static constexpr const char* centrality = "centrality"; + static constexpr const char* nSpecProjectileProton = "Nspec_proj_p"; + static constexpr const char* nSpecProjectileNeutron = "Nspec_proj_n"; + static constexpr const char* nSpecTargetProton = "Nspec_targ_p"; + static constexpr const char* nSpecTargetNeutron = "Nspec_targ_n"; + /** @} */ + /** @{ +@name HepMC3 PDF information + +In principle a header can have many of these. In that case, +each set should be prefixed with "_" where "" is a +serial number. + */ + static constexpr const char* pdfParton1Id = "pdf_parton_1_id"; + static constexpr const char* pdfParton2Id = "pdf_parton_2_id"; + static constexpr const char* pdfX1 = "pdf_x1"; + static constexpr const char* pdfX2 = "pdf_x2"; + static constexpr const char* pdfScale = "pdf_scale"; + static constexpr const char* pdfXF1 = "pdf_par_x1"; + static constexpr const char* pdfXF2 = "pdf_par_x2"; + static constexpr const char* pdfCode1 = "pdf_lhc_1_id"; + static constexpr const char* pdfCode2 = "pdf_lhc_2_id"; + /** @} */ + /** @{ +@name HepMC3 cross-section information + +In principle we can have one cross section per weight. In that +case, each should be post-fixed by "_" where "" is a +serial number. These should then matcht possible names of +weights. + */ + static constexpr const char* acceptedEvents = "accepted_events"; + static constexpr const char* attemptedEvents = "attempted_events"; + static constexpr const char* xSection = "cross_section"; + static constexpr const char* xSectionError = "cross_section_error"; + /** @} */ + /** @{ +@name Common fields */ + static constexpr const char* generator = "generator"; + static constexpr const char* generatorVersion = "version"; + static constexpr const char* processName = "processName"; + static constexpr const char* processCode = "processCode"; + static constexpr const char* weight = "weight"; + /** @} */ +}; /*****************************************************************/ /*****************************************************************/ diff --git a/Generators/include/Generators/GeneratorHepMC.h b/Generators/include/Generators/GeneratorHepMC.h index 4244f25be6327..8bcc567dd768b 100644 --- a/Generators/include/Generators/GeneratorHepMC.h +++ b/Generators/include/Generators/GeneratorHepMC.h @@ -65,6 +65,7 @@ class GeneratorHepMC : public Generator void setProgCmd(std::string val) { mProgCmd = val; }; void setEventsToSkip(uint64_t val) { mEventsToSkip = val; }; void setNEvents(unsigned int val) { mNEvents = val; } + protected: /** copy constructor **/ GeneratorHepMC(const GeneratorHepMC&); @@ -80,7 +81,7 @@ class GeneratorHepMC : public Generator /** methods that can be overridded **/ void updateHeader(o2::dataformats::MCEventHeader* eventHeader) override; - + /** HepMC interface **/ std::ifstream mStream; //! std::string mFileName; diff --git a/Generators/include/Generators/GeneratorHepMCParam.h b/Generators/include/Generators/GeneratorHepMCParam.h index 8cfd0a31cdd74..b44841df3cb61 100644 --- a/Generators/include/Generators/GeneratorHepMCParam.h +++ b/Generators/include/Generators/GeneratorHepMCParam.h @@ -31,7 +31,7 @@ namespace eventgen struct GeneratorHepMCParam : public o2::conf::ConfigurableParamHelper { std::string fileName = ""; - std::string progCmd = "";//Program command line to spawn, must write HepMC on stdout + std::string progCmd = ""; // Program command line to spawn, must write HepMC on stdout int version = 2; uint64_t eventsToSkip = 0; O2ParamDef(GeneratorHepMCParam, "HepMC"); diff --git a/Generators/include/Generators/GeneratorTParticle.h b/Generators/include/Generators/GeneratorTParticle.h index 4c69bd8c27a09..1dc87dac4c939 100644 --- a/Generators/include/Generators/GeneratorTParticle.h +++ b/Generators/include/Generators/GeneratorTParticle.h @@ -27,91 +27,89 @@ class TClonesArray; namespace o2 { - namespace eventgen +namespace eventgen +{ +/// A class that reads in particles of class @c TParticle from a +/// branch in a @c TChain. +/// +/// Optionally, a program that generates such a @c TTree can be +/// spawn, and the @c TParticles written to a file from which this +/// object reads them in. This is done with +/// +/// --configKeyValues "TParticle.progCmd=" +/// +/// which will execute the specified EG program with the given +/// options. The EG program _must_ support the command line options +/// +/// -n NUMBER Number of events to generate +/// -o FILENAME Name of file to write to +/// +/// The tree name and particle branch names can be configured. +/// +/// --configKeyValues "TParticle.treeName=T,TParticle.branchName=P" +/// +/// File(s) to read are also configurable +/// +/// --configKeyValues "TParticle.fileNames=foo.root,bar.root" +/// +class GeneratorTParticle : public Generator +{ + public: + /** CTOR */ + GeneratorTParticle() = default; + /** CTOR */ + GeneratorTParticle(const std::string& name) + : Generator(name.c_str(), "ALICEo2 TParticle Generator") { - /// A class that reads in particles of class @c TParticle from a - /// branch in a @c TChain. - /// - /// Optionally, a program that generates such a @c TTree can be - /// spawn, and the @c TParticles written to a file from which this - /// object reads them in. This is done with - /// - /// --configKeyValues "TParticle.progCmd=" - /// - /// which will execute the specified EG program with the given - /// options. The EG program _must_ support the command line options - /// - /// -n NUMBER Number of events to generate - /// -o FILENAME Name of file to write to - /// - /// The tree name and particle branch names can be configured. - /// - /// --configKeyValues "TParticle.treeName=T,TParticle.branchName=P" - /// - /// File(s) to read are also configurable - /// - /// --configKeyValues "TParticle.fileNames=foo.root,bar.root" - /// - class GeneratorTParticle : public Generator - { - public: - /** CTOR */ - GeneratorTParticle() = default; - /** CTOR */ - GeneratorTParticle(const std::string& name) - : Generator(name.c_str(),"ALICEo2 TParticle Generator") - {} - /** DTOR */ - virtual ~GeneratorTParticle(); + } + /** DTOR */ + virtual ~GeneratorTParticle(); - /** Initialize this generator. This will set up the chain. - Optionally, if a command line was specified by @c - TParticle.progCmd then that command line is executed in the - background and events are read from the output file of that - program */ - Bool_t Init() override; + /** Initialize this generator. This will set up the chain. +Optionally, if a command line was specified by @c +TParticle.progCmd then that command line is executed in the +background and events are read from the output file of that +program */ + Bool_t Init() override; - /** Read in the next entry from the chain. Returns false in - case of errors or no more entries to read. */ - Bool_t generateEvent() override; + /** Read in the next entry from the chain. Returns false in +case of errors or no more entries to read. */ + Bool_t generateEvent() override; - /** Import the read-in particles into the steer particle - stack */ - Bool_t importParticles() override; + /** Import the read-in particles into the steer particle +stack */ + Bool_t importParticles() override; - /** Set the names of files to read, separated by commas */ - void setFileNames(const std::string& val); - /** Set the name of the tree in the files. The tree _must_ - reside in the top-level directory of the files. */ - void setTreeName(const std::string& val) { mTreeName = val; } - /** Set the branch name of the branch that holds a @c - TClonesArray of @c TParticle objects */ - void setBranchName(const std::string& val) { mBranchName = val; } - /** Set child program command line to (optionally) execute */ - void setProgCmd(const std::string& val) { mProgCmd = val; } - /** Set the number of events to generate. */ - void setNEvents(unsigned int nev) { mNEvents = nev; } - protected: - std::string mTreeName = "T"; - std::string mBranchName = "Particles"; - std::string mProgCmd = ""; - std::list mFileNames; - unsigned int mNEvents = 0; - unsigned int mEntry = 0; - TChain* mChain; - TClonesArray* mTParticles; + /** Set the names of files to read, separated by commas */ + void setFileNames(const std::string& val); + /** Set the name of the tree in the files. The tree _must_ +reside in the top-level directory of the files. */ + void setTreeName(const std::string& val) { mTreeName = val; } + /** Set the branch name of the branch that holds a @c +TClonesArray of @c TParticle objects */ + void setBranchName(const std::string& val) { mBranchName = val; } + /** Set child program command line to (optionally) execute */ + void setProgCmd(const std::string& val) { mProgCmd = val; } + /** Set the number of events to generate. */ + void setNEvents(unsigned int nev) { mNEvents = nev; } - void waitForData(); + protected: + std::string mTreeName = "T"; + std::string mBranchName = "Particles"; + std::string mProgCmd = ""; + std::list mFileNames; + unsigned int mNEvents = 0; + unsigned int mEntry = 0; + TChain* mChain; + TClonesArray* mTParticles; - ClassDefOverride(GeneratorTParticle,1); - }; - } -} + void waitForData(); + + ClassDefOverride(GeneratorTParticle, 1); +}; +} // namespace eventgen +} // namespace o2 #endif // // EOF // - - - - diff --git a/Generators/include/Generators/GeneratorTParticleParam.h b/Generators/include/Generators/GeneratorTParticleParam.h index d293f9c0e2957..46c003e112f51 100644 --- a/Generators/include/Generators/GeneratorTParticleParam.h +++ b/Generators/include/Generators/GeneratorTParticleParam.h @@ -11,7 +11,7 @@ // immunities granted to it by virtue of its status as an // Intergovernmental Organization or submit itself to any // jurisdiction. -// +// // @author: Christian Holm Christensen #ifndef ALICEO2_EVENTGEN_GENERATORTPARTICLEPARAM_H_ #define ALICEO2_EVENTGEN_GENERATORTPARTICLEPARAM_H_ @@ -22,22 +22,20 @@ namespace o2 { - namespace eventgen - { +namespace eventgen +{ - /** - a parameter class/struct to keep the settings of the TGenerator - event generator and allow the user to modify them */ - struct GeneratorTParticleParam : - public o2::conf::ConfigurableParamHelper - { - std::string treeName = "T"; - std::string branchName = "Particles"; - std::string fileNames = "tparticle.root"; - std::string progCmd = ""; - O2ParamDef(GeneratorTParticleParam, "TParticle"); - }; - } // end namespace eventgen +/** + a parameter class/struct to keep the settings of the TGenerator + event generator and allow the user to modify them */ +struct GeneratorTParticleParam : public o2::conf::ConfigurableParamHelper { + std::string treeName = "T"; + std::string branchName = "Particles"; + std::string fileNames = "tparticle.root"; + std::string progCmd = ""; + O2ParamDef(GeneratorTParticleParam, "TParticle"); +}; +} // end namespace eventgen } // end namespace o2 #endif // ALICEO2_EVENTGEN_GENERATORHEPMCPARAM_H_ diff --git a/Generators/src/GeneratorFactory.cxx b/Generators/src/GeneratorFactory.cxx index 628ca885bbf0e..e572b5594e71e 100644 --- a/Generators/src/GeneratorFactory.cxx +++ b/Generators/src/GeneratorFactory.cxx @@ -157,10 +157,11 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair if (o2PrimGen) { o2PrimGen->setApplyVertex(false); } - } LOG(info) << "using external O2 kinematics"; + } + LOG(info) << "using external O2 kinematics"; } else if (genconfig.compare("tparticle") == 0) { // External ROOT file(s) with tree of TParticle in clones array, - // or external program generating such a file + // or external program generating such a file auto& param = GeneratorTParticleParam::Instance(); LOG(info) << "Init 'GeneratorTParticle' with the following parameters"; LOG(info) << param; diff --git a/Generators/src/GeneratorHepMC.cxx b/Generators/src/GeneratorHepMC.cxx index 56d0e80248a00..2741f98f57cc9 100644 --- a/Generators/src/GeneratorHepMC.cxx +++ b/Generators/src/GeneratorHepMC.cxx @@ -151,72 +151,71 @@ Bool_t GeneratorHepMC::importParticles() return kTRUE; } - namespace - { - void putAttributeInfo(o2::dataformats::MCEventHeader* eventHeader, - const std::string& name, - const std::shared_ptr& a) - { - if (auto* p = dynamic_cast(a.get())) - eventHeader->putInfo(name,p->value()); - if (auto* p = dynamic_cast(a.get())) - eventHeader->putInfo(name,p->value()); - if (auto* p = dynamic_cast(a.get())) - eventHeader->putInfo(name,p->value()); - if (auto* p = dynamic_cast(a.get())) - eventHeader->putInfo(name,p->value()); - if (auto* p = dynamic_cast(a.get())) - eventHeader->putInfo(name,p->value()); - if (auto* p = dynamic_cast(a.get())) - eventHeader->putInfo(name,p->value()); - if (auto* p = dynamic_cast(a.get())) - eventHeader->putInfo(name,p->value()); - if (auto* p = dynamic_cast(a.get())) - eventHeader->putInfo(name,p->value()); - if (auto* p = dynamic_cast(a.get())) - eventHeader->putInfo(name,p->value()); - if (auto* p = dynamic_cast(a.get())) - eventHeader->putInfo(name,p->value()); - if (auto* p = dynamic_cast(a.get())) - eventHeader->putInfo(name,p->value()); - if (auto* p = dynamic_cast(a.get())) - eventHeader->putInfo(name,p->value()); - } - } - - +namespace +{ +void putAttributeInfo(o2::dataformats::MCEventHeader* eventHeader, + const std::string& name, + const std::shared_ptr& a) +{ + if (auto* p = dynamic_cast(a.get())) + eventHeader->putInfo(name, p->value()); + if (auto* p = dynamic_cast(a.get())) + eventHeader->putInfo(name, p->value()); + if (auto* p = dynamic_cast(a.get())) + eventHeader->putInfo(name, p->value()); + if (auto* p = dynamic_cast(a.get())) + eventHeader->putInfo(name, p->value()); + if (auto* p = dynamic_cast(a.get())) + eventHeader->putInfo(name, p->value()); + if (auto* p = dynamic_cast(a.get())) + eventHeader->putInfo(name, p->value()); + if (auto* p = dynamic_cast(a.get())) + eventHeader->putInfo(name, p->value()); + if (auto* p = dynamic_cast(a.get())) + eventHeader->putInfo(name, p->value()); + if (auto* p = dynamic_cast(a.get())) + eventHeader->putInfo(name, p->value()); + if (auto* p = dynamic_cast(a.get())) + eventHeader->putInfo(name, p->value()); + if (auto* p = dynamic_cast(a.get())) + eventHeader->putInfo(name, p->value()); + if (auto* p = dynamic_cast(a.get())) + eventHeader->putInfo(name, p->value()); +} +} // namespace + /*****************************************************************/ void GeneratorHepMC::updateHeader(o2::dataformats::MCEventHeader* eventHeader) { /** update header **/ - using Key=o2::dataformats::MCInfoKeys; + using Key = o2::dataformats::MCInfoKeys; eventHeader->putInfo(Key::generator, "hepmc"); eventHeader->putInfo(Key::generatorVersion, HEPMC3_VERSION_CODE); auto xSection = mEvent->cross_section(); - auto pdfInfo = mEvent->pdf_info(); - auto hiInfo = mEvent->heavy_ion(); + auto pdfInfo = mEvent->pdf_info(); + auto hiInfo = mEvent->heavy_ion(); - // Set default cross-section + // Set default cross-section if (xSection) { - eventHeader->putInfo(Key::xSection, xSection->xsec()); + eventHeader->putInfo(Key::xSection, xSection->xsec()); eventHeader->putInfo(Key::xSectionError, xSection->xsec_err()); eventHeader->putInfo(Key::acceptedEvents, - xSection->get_accepted_events()); + xSection->get_accepted_events()); eventHeader->putInfo(Key::attemptedEvents, - xSection->get_attempted_events()); + xSection->get_attempted_events()); } - // Set weights and cross sections + // Set weights and cross sections size_t iw = 0; for (auto w : mEvent->weights()) { - std::string post = (iw > 0 ? "_"+std::to_string(iw) : ""); - eventHeader->putInfo(Key::weight+post, w); + std::string post = (iw > 0 ? "_" + std::to_string(iw) : ""); + eventHeader->putInfo(Key::weight + post, w); if (xSection) { - eventHeader->putInfo(Key::xSection, xSection->xsec(iw)); - eventHeader->putInfo(Key::xSectionError,xSection->xsec_err(iw)); + eventHeader->putInfo(Key::xSection, xSection->xsec(iw)); + eventHeader->putInfo(Key::xSectionError, xSection->xsec_err(iw)); } iw++; } @@ -225,59 +224,59 @@ void GeneratorHepMC::updateHeader(o2::dataformats::MCEventHeader* eventHeader) if (pdfInfo) { eventHeader->putInfo(Key::pdfParton1Id, pdfInfo->parton_id[0]); eventHeader->putInfo(Key::pdfParton2Id, pdfInfo->parton_id[1]); - eventHeader->putInfo(Key::pdfX1, pdfInfo->x[0]); - eventHeader->putInfo(Key::pdfX2, pdfInfo->x[1]); - eventHeader->putInfo(Key::pdfScale, pdfInfo->scale); - eventHeader->putInfo(Key::pdfXF1, pdfInfo->xf[0]); - eventHeader->putInfo(Key::pdfXF2, pdfInfo->xf[1]); - eventHeader->putInfo(Key::pdfCode1, pdfInfo->pdf_id[0]); - eventHeader->putInfo(Key::pdfCode2, pdfInfo->pdf_id[1]); + eventHeader->putInfo(Key::pdfX1, pdfInfo->x[0]); + eventHeader->putInfo(Key::pdfX2, pdfInfo->x[1]); + eventHeader->putInfo(Key::pdfScale, pdfInfo->scale); + eventHeader->putInfo(Key::pdfXF1, pdfInfo->xf[0]); + eventHeader->putInfo(Key::pdfXF2, pdfInfo->xf[1]); + eventHeader->putInfo(Key::pdfCode1, pdfInfo->pdf_id[0]); + eventHeader->putInfo(Key::pdfCode2, pdfInfo->pdf_id[1]); } // Set heavy-ion information if (hiInfo) { - eventHeader->putInfo(Key::impactParameter , - hiInfo->impact_parameter); - eventHeader->putInfo(Key::nPart , - hiInfo->Npart_proj+hiInfo->Npart_targ); - eventHeader->putInfo(Key::nPartProjectile ,hiInfo->Npart_proj); - eventHeader->putInfo(Key::nPartTarget ,hiInfo->Npart_targ); - eventHeader->putInfo(Key::nColl ,hiInfo->Ncoll); - eventHeader->putInfo(Key::nCollHard ,hiInfo->Ncoll_hard); - eventHeader->putInfo(Key::nCollNNWounded , - hiInfo->N_Nwounded_collisions); - eventHeader->putInfo(Key::nCollNWoundedN , - hiInfo->Nwounded_N_collisions); - eventHeader->putInfo(Key::nCollNWoundedNwounded , - hiInfo->Nwounded_Nwounded_collisions); - eventHeader->putInfo(Key::planeAngle , - hiInfo->event_plane_angle); - eventHeader->putInfo(Key::sigmaInelNN , - hiInfo->sigma_inel_NN); - eventHeader->putInfo(Key::centrality ,hiInfo->centrality); - eventHeader->putInfo(Key::nSpecProjectileProton ,hiInfo->Nspec_proj_p); - eventHeader->putInfo(Key::nSpecProjectileNeutron,hiInfo->Nspec_proj_n); - eventHeader->putInfo(Key::nSpecTargetProton ,hiInfo->Nspec_targ_p); - eventHeader->putInfo(Key::nSpecTargetNeutron ,hiInfo->Nspec_targ_n); + eventHeader->putInfo(Key::impactParameter, + hiInfo->impact_parameter); + eventHeader->putInfo(Key::nPart, + hiInfo->Npart_proj + hiInfo->Npart_targ); + eventHeader->putInfo(Key::nPartProjectile, hiInfo->Npart_proj); + eventHeader->putInfo(Key::nPartTarget, hiInfo->Npart_targ); + eventHeader->putInfo(Key::nColl, hiInfo->Ncoll); + eventHeader->putInfo(Key::nCollHard, hiInfo->Ncoll_hard); + eventHeader->putInfo(Key::nCollNNWounded, + hiInfo->N_Nwounded_collisions); + eventHeader->putInfo(Key::nCollNWoundedN, + hiInfo->Nwounded_N_collisions); + eventHeader->putInfo(Key::nCollNWoundedNwounded, + hiInfo->Nwounded_Nwounded_collisions); + eventHeader->putInfo(Key::planeAngle, + hiInfo->event_plane_angle); + eventHeader->putInfo(Key::sigmaInelNN, + hiInfo->sigma_inel_NN); + eventHeader->putInfo(Key::centrality, hiInfo->centrality); + eventHeader->putInfo(Key::nSpecProjectileProton, hiInfo->Nspec_proj_p); + eventHeader->putInfo(Key::nSpecProjectileNeutron, hiInfo->Nspec_proj_n); + eventHeader->putInfo(Key::nSpecTargetProton, hiInfo->Nspec_targ_p); + eventHeader->putInfo(Key::nSpecTargetNeutron, hiInfo->Nspec_targ_n); } for (auto na : mEvent->attributes()) { std::string name = na.first; if (name == "GenPdfInfo" || - name == "GenCrossSection" || - name == "GenHeavyIon") continue; + name == "GenCrossSection" || + name == "GenHeavyIon") + continue; for (auto ia : na.second) { - int no = ia.first; + int no = ia.first; auto at = ia.second; std::string post = (no == 0 ? "" : std::to_string(no)); - - putAttributeInfo(eventHeader, name+post, at); + + putAttributeInfo(eventHeader, name + post, at); } } } - - + /*****************************************************************/ Bool_t GeneratorHepMC::Init() @@ -317,10 +316,10 @@ Bool_t GeneratorHepMC::Init() // TString base("xxxxxx"); // auto fp = gSystem->TempFileName(base); // fclose(fp); - // + // filename = std::tmpnam(nullptr); - // Make a fifo + // Make a fifo int ret = mkfifo(filename.c_str(), 0600); if (ret != 0) { LOG(fatal) << "Failed to make fifo \"" << filename << "\""; @@ -328,7 +327,7 @@ Bool_t GeneratorHepMC::Init() } // Build command line, rediret stdout to our fifo and put - // in the background. + // in the background. std::string cmd = mProgCmd + " -n " + std::to_string(mNEvents) + diff --git a/Generators/src/GeneratorPythia8.cxx b/Generators/src/GeneratorPythia8.cxx index c055bf2718f26..442e93976546f 100644 --- a/Generators/src/GeneratorPythia8.cxx +++ b/Generators/src/GeneratorPythia8.cxx @@ -202,8 +202,8 @@ Bool_t void GeneratorPythia8::updateHeader(o2::dataformats::MCEventHeader* eventHeader) { /** update header **/ - using Key=o2::dataformats::MCInfoKeys; - + using Key = o2::dataformats::MCInfoKeys; + eventHeader->putInfo(Key::generator, "pythia8"); eventHeader->putInfo(Key::generatorVersion, PYTHIA_VERSION_INTEGER); eventHeader->putInfo(Key::processName, mPythia.info.name()); @@ -211,31 +211,31 @@ void GeneratorPythia8::updateHeader(o2::dataformats::MCEventHeader* eventHeader) eventHeader->putInfo(Key::weight, mPythia.info.weight()); auto& info = mPythia.info; - + // Set PDF information - eventHeader->putInfo (Key::pdfParton1Id, info.id1pdf()); - eventHeader->putInfo (Key::pdfParton2Id, info.id2pdf()); - eventHeader->putInfo(Key::pdfX1, info.x1pdf()); - eventHeader->putInfo(Key::pdfX2, info.x2pdf()); - eventHeader->putInfo(Key::pdfScale, info.QFac()); - eventHeader->putInfo(Key::pdfXF1, info.pdf1()); - eventHeader->putInfo(Key::pdfXF2, info.pdf2()); + eventHeader->putInfo(Key::pdfParton1Id, info.id1pdf()); + eventHeader->putInfo(Key::pdfParton2Id, info.id2pdf()); + eventHeader->putInfo(Key::pdfX1, info.x1pdf()); + eventHeader->putInfo(Key::pdfX2, info.x2pdf()); + eventHeader->putInfo(Key::pdfScale, info.QFac()); + eventHeader->putInfo(Key::pdfXF1, info.pdf1()); + eventHeader->putInfo(Key::pdfXF2, info.pdf2()); // Set cross section - eventHeader->putInfo(Key::xSection, info.sigmaGen()*1e9); - eventHeader->putInfo(Key::xSectionError,info.sigmaErr()*1e9); + eventHeader->putInfo(Key::xSection, info.sigmaGen() * 1e9); + eventHeader->putInfo(Key::xSectionError, info.sigmaErr() * 1e9); // Set weights (overrides cross-section for each weight) size_t iw = 0; auto xsecErr = info.weightContainerPtr->getTotalXsecErr(); for (auto w : info.weightContainerPtr->getTotalXsec()) { - std::string post = (iw == 0 ? "" : "_"+std::to_string(iw)); - eventHeader->putInfo(Key::weight+post, info.weightValueByIndex(iw)); - eventHeader->putInfo(Key::xSection+post,w*1e9); - eventHeader->putInfo(Key::xSectionError+post,xsecErr[iw]*1e9); + std::string post = (iw == 0 ? "" : "_" + std::to_string(iw)); + eventHeader->putInfo(Key::weight + post, info.weightValueByIndex(iw)); + eventHeader->putInfo(Key::xSection + post, w * 1e9); + eventHeader->putInfo(Key::xSectionError + post, xsecErr[iw] * 1e9); iw++; } - + #if PYTHIA_VERSION_INTEGER < 8300 auto hiinfo = mPythia.info.hiinfo; #else @@ -274,17 +274,16 @@ void GeneratorPythia8::updateHeader(o2::dataformats::MCEventHeader* eventHeader) eventHeader->putInfo("Nfree_targ_p", nFreeProtonTarg); // --- HepMC3 conforming information --- - // This is how the Pythia authors define Ncoll + // This is how the Pythia authors define Ncoll // eventHeader->putInfo(Key::nColl, // hiinfo->nAbsProj() + hiinfo->nDiffProj() + // hiinfo->nAbsTarg() + hiinfo->nDiffTarg() - // hiiinfo->nCollND() - hiinfo->nCollDD()); eventHeader->putInfo(Key::nPartProjectile, - hiinfo->nAbsProj()+hiinfo->nDiffProj()); + hiinfo->nAbsProj() + hiinfo->nDiffProj()); eventHeader->putInfo(Key::nPartTarget, - hiinfo->nAbsTarg()+hiinfo->nDiffTarg()); + hiinfo->nAbsTarg() + hiinfo->nDiffTarg()); eventHeader->putInfo(Key::nCollHard, hiinfo->nCollNDTot()); - } } @@ -344,9 +343,9 @@ void GeneratorPythia8::getNcoll(const Pythia8::Info& info, int& nColl) #endif // This is how the Pythia authors define Ncoll - nColl = (hiinfo->nAbsProj()+hiinfo->nDiffProj()+ - hiinfo->nAbsTarg()+hiinfo->nDiffTarg()- - hiinfo->nCollND() -hiinfo->nCollDD()); + nColl = (hiinfo->nAbsProj() + hiinfo->nDiffProj() + + hiinfo->nAbsTarg() + hiinfo->nDiffTarg() - + hiinfo->nCollND() - hiinfo->nCollDD()); nColl = 0; if (!hiinfo) { @@ -381,10 +380,10 @@ void GeneratorPythia8::getNpart(const Pythia8::Info& info, int& nPart) #else auto hiinfo = info.hiInfo; #endif - if (hiinfo) + if (hiinfo) nPart = (hiinfo->nAbsProj() + hiinfo->nDiffProj() + - hiinfo->nAbsTarg() + hiinfo->nDiffTarg()); - + hiinfo->nAbsTarg() + hiinfo->nDiffTarg()); + int nProtonProj, nNeutronProj, nProtonTarg, nNeutronTarg; getNpart(info, nProtonProj, nNeutronProj, nProtonTarg, nNeutronTarg); nPart = nProtonProj + nNeutronProj + nProtonTarg + nNeutronTarg; diff --git a/Generators/src/GeneratorTParticle.cxx b/Generators/src/GeneratorTParticle.cxx index 2f4400448a368..eb84a2bcfbe11 100644 --- a/Generators/src/GeneratorTParticle.cxx +++ b/Generators/src/GeneratorTParticle.cxx @@ -29,161 +29,159 @@ namespace o2 { - namespace eventgen - { - GeneratorTParticle::~GeneratorTParticle() - { - if (mChain) { - TFile* file = mChain->GetCurrentFile(); - if (file) mChain->RecursiveRemove(file); - delete mChain; - } - if (mProgCmd.empty()) return; - - // Get the file we're reading from - std::filesystem::path p(mFileNames.front()); - - // Wait until child process creates the file - if (not std::filesystem::exists(p)) return; - - // Remove temporary file - std::error_code ec; - std::filesystem::remove(p,ec); - } - - void GeneratorTParticle::setFileNames(const std::string& val) - { - std::stringstream s; - std::string f; - while (std::getline(s,f,',')) - mFileNames.push_back(f); - } +namespace eventgen +{ +GeneratorTParticle::~GeneratorTParticle() +{ + if (mChain) { + TFile* file = mChain->GetCurrentFile(); + if (file) + mChain->RecursiveRemove(file); + delete mChain; + } + if (mProgCmd.empty()) + return; + // Get the file we're reading from + std::filesystem::path p(mFileNames.front()); - Bool_t GeneratorTParticle::Init() - { - mChain = new TChain(mTreeName.c_str()); - mTParticles = new TClonesArray("TParticle"); - mChain->SetBranchAddress(mBranchName.c_str(), &mTParticles); - - if (not mProgCmd.empty()) { - // Set filename to be a temporary name - // Should perhaps use - // - // TString base("xxxxxx"); - // auto fp = gSystem->TempFileName(base); - // fclose(fp); - // - std::string filename = std::tmpnam(nullptr); - - // Build command line, Assumes command line parameter - // - // -n NUMBER of events to produce - // -o FILENAME of output file - // - // A script can be wrapped around existing EGs to ensure these - // options are observed. - std::string cmd = - mProgCmd + - " -n " + std::to_string(mNEvents) + - " -o " + filename + " &"; - LOG(info) << "EG command line is \"" << cmd << "\""; - - int ret = std::system(cmd.c_str()); - if (ret != 0) { - LOG(fatal) << "Failed to spawn \"" << cmd << "\""; - return false; - } - - mFileNames.clear(); - mFileNames.push_back(filename); - } - for (auto filename : mFileNames) - mChain->AddFile(filename.c_str()); - - return true; - } + // Wait until child process creates the file + if (not std::filesystem::exists(p)) + return; - void GeneratorTParticle::waitForData() - { - if (mProgCmd.empty()) return; // Not from child process - - using namespace std::chrono_literals; - - // Get the file we're reading from - std::filesystem::path p(mFileNames.front()); - - LOG(info) << "Waiting for data on " << p; - - // Wait until child process creates the file - while (not std::filesystem::exists(p)) - std::this_thread::sleep_for(500ms); - - // Wait until we have more data in the file than just the file - // header - while (std::filesystem::file_size(p) <= 256) - std::this_thread::sleep_for(500ms); - - // Give the child process 1 second to post the data to the file - LOG(info) << "Got data in " << p << ", sleeping for a while"; - std::this_thread::sleep_for(1s); - } - - Bool_t GeneratorTParticle::generateEvent() - { - if (mEntry == 0) waitForData(); - - int read = mChain->GetEntry(mEntry); - mEntry++; - - if (read < 0) - LOG(error) << "Failed to read entry " << mEntry << " of chain"; - - if (read <= 0) return false; - - return true; - } + // Remove temporary file + std::error_code ec; + std::filesystem::remove(p, ec); +} - Bool_t GeneratorTParticle::importParticles() - { - for (auto* object : *mTParticles) { - TParticle* particle = static_cast(object); - auto statusCode = particle->GetStatusCode(); - if (!mcgenstatus::isEncoded(statusCode)) - statusCode = mcgenstatus::MCGenStatusEncoding(statusCode, 0) - .fullEncoding; - - mParticles.emplace_back(particle->GetPdgCode(), - statusCode, - particle->GetFirstMother(), - particle->GetSecondMother(), - particle->GetFirstDaughter(), - particle->GetLastDaughter(), - particle->Px(), - particle->Py(), - particle->Pz(), - particle->Energy(), - particle->Vx(), - particle->Vy(), - particle->Vz(), - particle->T()); - auto& tgt = mParticles[mParticles.size()-1]; - tgt.SetPolarTheta(particle->GetPolarTheta()); - tgt.SetPolarPhi(particle->GetPolarPhi()); - tgt.SetCalcMass(particle->GetCalcMass()); - tgt.SetWeight(particle->GetWeight()); - } - return true; +void GeneratorTParticle::setFileNames(const std::string& val) +{ + std::stringstream s; + std::string f; + while (std::getline(s, f, ',')) + mFileNames.push_back(f); +} + +Bool_t GeneratorTParticle::Init() +{ + mChain = new TChain(mTreeName.c_str()); + mTParticles = new TClonesArray("TParticle"); + mChain->SetBranchAddress(mBranchName.c_str(), &mTParticles); + + if (not mProgCmd.empty()) { + // Set filename to be a temporary name + // Should perhaps use + // + // TString base("xxxxxx"); + // auto fp = gSystem->TempFileName(base); + // fclose(fp); + // + std::string filename = std::tmpnam(nullptr); + + // Build command line, Assumes command line parameter + // + // -n NUMBER of events to produce + // -o FILENAME of output file + // + // A script can be wrapped around existing EGs to ensure these + // options are observed. + std::string cmd = + mProgCmd + + " -n " + std::to_string(mNEvents) + + " -o " + filename + " &"; + LOG(info) << "EG command line is \"" << cmd << "\""; + + int ret = std::system(cmd.c_str()); + if (ret != 0) { + LOG(fatal) << "Failed to spawn \"" << cmd << "\""; + return false; } + + mFileNames.clear(); + mFileNames.push_back(filename); } + for (auto filename : mFileNames) + mChain->AddFile(filename.c_str()); + + return true; } -// -// EOF -// - - +void GeneratorTParticle::waitForData() +{ + if (mProgCmd.empty()) + return; // Not from child process + + using namespace std::chrono_literals; + + // Get the file we're reading from + std::filesystem::path p(mFileNames.front()); + + LOG(info) << "Waiting for data on " << p; + + // Wait until child process creates the file + while (not std::filesystem::exists(p)) + std::this_thread::sleep_for(500ms); + + // Wait until we have more data in the file than just the file + // header + while (std::filesystem::file_size(p) <= 256) + std::this_thread::sleep_for(500ms); + + // Give the child process 1 second to post the data to the file + LOG(info) << "Got data in " << p << ", sleeping for a while"; + std::this_thread::sleep_for(1s); +} + +Bool_t GeneratorTParticle::generateEvent() +{ + if (mEntry == 0) + waitForData(); + + int read = mChain->GetEntry(mEntry); + mEntry++; - + if (read < 0) + LOG(error) << "Failed to read entry " << mEntry << " of chain"; - + if (read <= 0) + return false; + + return true; +} + +Bool_t GeneratorTParticle::importParticles() +{ + for (auto* object : *mTParticles) { + TParticle* particle = static_cast(object); + auto statusCode = particle->GetStatusCode(); + if (!mcgenstatus::isEncoded(statusCode)) + statusCode = mcgenstatus::MCGenStatusEncoding(statusCode, 0) + .fullEncoding; + + mParticles.emplace_back(particle->GetPdgCode(), + statusCode, + particle->GetFirstMother(), + particle->GetSecondMother(), + particle->GetFirstDaughter(), + particle->GetLastDaughter(), + particle->Px(), + particle->Py(), + particle->Pz(), + particle->Energy(), + particle->Vx(), + particle->Vy(), + particle->Vz(), + particle->T()); + auto& tgt = mParticles[mParticles.size() - 1]; + tgt.SetPolarTheta(particle->GetPolarTheta()); + tgt.SetPolarPhi(particle->GetPolarPhi()); + tgt.SetCalcMass(particle->GetCalcMass()); + tgt.SetWeight(particle->GetWeight()); + } + return true; +} +} // namespace eventgen +} // namespace o2 +// +// EOF +// diff --git a/Generators/src/GeneratorsLinkDef.h b/Generators/src/GeneratorsLinkDef.h index 26f270c9a0a39..669b1f37019c1 100644 --- a/Generators/src/GeneratorsLinkDef.h +++ b/Generators/src/GeneratorsLinkDef.h @@ -67,8 +67,8 @@ #pragma link C++ class o2::conf::ConfigurableParamHelper < o2::eventgen::QEDGenParam> + ; #pragma link C++ class o2::eventgen::GenCosmicsParam + ; #pragma link C++ class o2::conf::ConfigurableParamHelper < o2::eventgen::GenCosmicsParam> + ; -#pragma link C++ class o2::eventgen::GeneratorTParticle +; -#pragma link C++ class o2::eventgen::GeneratorTParticleParam +; -#pragma link C++ class o2::conf::ConfigurableParamHelper +; +#pragma link C++ class o2::eventgen::GeneratorTParticle + ; +#pragma link C++ class o2::eventgen::GeneratorTParticleParam + ; +#pragma link C++ class o2::conf::ConfigurableParamHelper < o2::eventgen::GeneratorTParticleParam> + ; #endif