Project
Loading...
Searching...
No Matches
GeneratorTParticle.cxx
Go to the documentation of this file.
1// Copyright 2023-2099 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16#include <SimConfig/SimConfig.h>
17#include <fairlogger/Logger.h>
18#include <TFile.h>
19#include <TChain.h>
20#include <TClonesArray.h>
21#include <TParticle.h>
22
23namespace o2
24{
25namespace eventgen
26{
27/*****************************************************************/
32
33/*****************************************************************/
35{
36 if (mChain) {
37 TFile* file = mChain->GetCurrentFile();
38 if (file) {
39 mChain->RecursiveRemove(file);
40 }
41 delete mChain;
42 }
43 if (mCmd.empty()) {
44 return;
45 }
46
47 removeTemp();
48}
49/*****************************************************************/
51{
52 mChain = new TChain(mTreeName.c_str());
53 mTParticles = new TClonesArray("TParticle");
54 mChain->SetBranchAddress(mBranchName.c_str(), &mTParticles);
55
56 if (not mCmd.empty()) {
57 if (mFileNames.empty()) {
58 // Set filename to be a temporary name
59 if (not makeTemp(false)) {
60 return false;
61 }
62 } else {
63 // Use the first filename as output for cmd line
64 if (not makeTemp(true)) {
65 return false;
66 }
67 }
68
69 // Build command line, Assumes command line parameter
70 std::string cmd = makeCmdLine();
71 LOG(info) << "EG command line is \"" << cmd << "\"";
72
73 // Execute the background command
74 if (not executeCmdLine(cmd)) {
75 LOG(fatal) << "Failed to spawn \"" << cmd << "\"";
76 return false;
77 }
78 }
79 for (auto filename : mFileNames) {
80 mChain->AddFile(filename.c_str());
81 }
82
83 // Clear the array of file names
84 mFileNames.clear();
85
86 return true;
87}
88
89/*****************************************************************/
92 const conf::SimConfig& config)
93{
94 GeneratorFileOrCmd::setup(param0, config);
95 setTreeName(param.treeName);
96 setBranchName(param.branchName);
97}
98
99/*****************************************************************/
101{
102 // If this is the first entry, and we're executing a command, then
103 // wait until the input file exists and actually contain some data.
104 if (mEntry == 0 and not mCmd.empty()) {
106 }
107
108 // Read in the next entry in the chain
109 int read = mChain->GetEntry(mEntry);
110 mEntry++;
111
112 // If we got an error while reading, then give error message
113 if (read < 0) {
114 LOG(error) << "Failed to read entry " << mEntry << " of chain";
115 }
116
117 // If we had an error or nothing was read back, then return false
118 if (read <= 0) {
119 return false;
120 }
121
122 return true;
123}
124
126{
127 for (auto* object : *mTParticles) {
128 TParticle* particle = static_cast<TParticle*>(object);
129 auto statusCode = particle->GetStatusCode();
130 if (!mcgenstatus::isEncoded(statusCode)) {
131 statusCode = mcgenstatus::MCGenStatusEncoding(statusCode, 0)
133 }
134
135 mParticles.emplace_back(particle->GetPdgCode(),
136 statusCode,
137 particle->GetFirstMother(),
138 particle->GetSecondMother(),
139 particle->GetFirstDaughter(),
140 particle->GetLastDaughter(),
141 particle->Px(),
142 particle->Py(),
143 particle->Pz(),
144 particle->Energy(),
145 particle->Vx(),
146 particle->Vy(),
147 particle->Vz(),
148 particle->T());
149 auto& tgt = mParticles[mParticles.size() - 1];
150 tgt.SetPolarTheta(particle->GetPolarTheta());
151 tgt.SetPolarPhi(particle->GetPolarPhi());
152 tgt.SetCalcMass(particle->GetCalcMass());
153 tgt.SetWeight(particle->GetWeight());
154 }
155 return true;
156}
157} // namespace eventgen
158} // namespace o2
159//
160// EOF
161//
void setup(const GeneratorFileOrCmdParam &param0, const GeneratorTParticleParam &param, const conf::SimConfig &config)
void setBranchName(const std::string &val)
void setTreeName(const std::string &val)
std::vector< TParticle > mParticles
Definition Generator.h:140
GLuint object
Definition glcorearb.h:4041
GLenum GLfloat param
Definition glcorearb.h:271
bool isEncoded(MCGenStatusEncoding statusCode)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string filename()
void setup(const GeneratorFileOrCmdParam &param, const conf::SimConfig &config)
std::list< std::string > mFileNames
void setOutputSwitch(const std::string &opt)
virtual std::string makeCmdLine() const
virtual void waitForData(const std::string &filename) const
virtual bool executeCmdLine(const std::string &cmd)
virtual bool makeTemp(const bool &)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"