Skip to content

Commit c2bc3f6

Browse files
committed
Revert "Revert "Implementation of simulation inhibit-pause-trigger-continue features (#5305)""
This reverts commit 27ac59a. It re-enables the inhibit-pause-trigger-continue feature and fixes a problem in initialization order of stack and parameters.
1 parent 37ff3d1 commit c2bc3f6

23 files changed

+470
-38
lines changed

DataFormats/simulation/include/SimulationDataFormat/MCTrack.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ inline MCTrackT<T>::MCTrackT(const TParticle& part)
329329
{
330330
// our convention is to communicate the process as (part) of the unique ID
331331
setProcess(part.GetUniqueID());
332+
// extract storage flag
333+
setStore(part.TestBit(ParticleStatus::kKeep));
332334
// extract toBeDone flag
333335
setToBeDone(part.TestBit(ParticleStatus::kToBeDone));
334336
// extract inhibited flag

DataFormats/simulation/include/SimulationDataFormat/Stack.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ class Stack : public FairGenericStack
9090

9191
void PushTrack(Int_t toBeDone, Int_t parentID, Int_t pdgCode, Double_t px, Double_t py, Double_t pz, Double_t e,
9292
Double_t vx, Double_t vy, Double_t vz, Double_t time, Double_t polx, Double_t poly, Double_t polz,
93-
TMCProcess proc, Int_t& ntr, Double_t weight, Int_t is, Int_t secondParentId, Int_t daughter1Id, Int_t daughter2Id);
93+
TMCProcess proc, Int_t& ntr, Double_t weight, Int_t is, Int_t secondParentId, Int_t daughter1Id, Int_t daughter2Id,
94+
TMCProcess proc2);
9495

9596
// similar function taking a particle
9697
void PushTrack(Int_t toBeDone, TParticle&);

DataFormats/simulation/src/Stack.cxx

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Stack::Stack(Int_t size)
103103
if (!mTransportPrimary) {
104104
LOG(FATAL) << "Failed to retrieve external \'transportPrimary\' function: problem with configuration ";
105105
}
106+
LOG(INFO) << "Successfully retrieve external \'transportPrimary\' frunction: " << param.transportPrimaryFileName;
106107
} else {
107108
LOG(FATAL) << "unsupported \'trasportPrimary\' mode: " << param.transportPrimary;
108109
}
@@ -183,12 +184,13 @@ void Stack::PushTrack(Int_t toBeDone, Int_t parentId, Int_t pdgCode, Double_t px
183184
Double_t vx, Double_t vy, Double_t vz, Double_t time, Double_t polx, Double_t poly, Double_t polz,
184185
TMCProcess proc, Int_t& ntr, Double_t weight, Int_t is, Int_t secondparentId)
185186
{
186-
PushTrack(toBeDone, parentId, pdgCode, px, py, pz, e, vx, vy, vz, time, polx, poly, polz, proc, ntr, weight, is, secondparentId, -1, -1);
187+
PushTrack(toBeDone, parentId, pdgCode, px, py, pz, e, vx, vy, vz, time, polx, poly, polz, proc, ntr, weight, is, secondparentId, -1, -1, proc);
187188
}
188189

189190
void Stack::PushTrack(Int_t toBeDone, Int_t parentId, Int_t pdgCode, Double_t px, Double_t py, Double_t pz, Double_t e,
190191
Double_t vx, Double_t vy, Double_t vz, Double_t time, Double_t polx, Double_t poly, Double_t polz,
191-
TMCProcess proc, Int_t& ntr, Double_t weight, Int_t is, Int_t secondparentId, Int_t daughter1Id, Int_t daughter2Id)
192+
TMCProcess proc, Int_t& ntr, Double_t weight, Int_t is, Int_t secondparentId, Int_t daughter1Id, Int_t daughter2Id,
193+
TMCProcess proc2)
192194
{
193195
// printf("Pushing %s toBeDone %5d parentId %5d pdgCode %5d is %5d entries %5d \n",
194196
// proc == kPPrimary ? "Primary: " : "Secondary: ",
@@ -214,36 +216,38 @@ void Stack::PushTrack(Int_t toBeDone, Int_t parentId, Int_t pdgCode, Double_t px
214216
p.SetPolarisation(polx, poly, polz);
215217
p.SetWeight(weight);
216218
p.SetUniqueID(proc); // using the unique ID to transfer process ID
219+
p.SetBit(ParticleStatus::kPrimary, proc == kPPrimary ? 1 : 0); // set primary bit
220+
p.SetBit(ParticleStatus::kToBeDone, toBeDone == 1 ? 1 : 0); // set to be done bit
217221
mNumberOfEntriesInParticles++;
218222

219223
insertInVector(mTrackIDtoParticlesEntry, trackId, (int)(mParticles.size()));
220224

225+
handleTransportPrimary(p); // handle selective transport of primary particles
226+
221227
// Push particle on the stack if toBeDone is set
222-
if (proc == kPPrimary) {
228+
if (p.TestBit(ParticleStatus::kPrimary)) {
223229
// This is a particle from the primary particle generator
224230
//
225231
// SetBit is used to pass information about the primary particle to the stack during transport.
226232
// Sime particles have already decayed or are partons from a shower. They are needed for the
227233
// event history in the stack, but not for transport.
228234
//
235+
236+
// primary particles might have been pushed with a second creation process
237+
// in case we pushed a secondary track of a previous simulation to be continued.
238+
// We save therefore in the UniqueID the correct process
239+
// while the particle will still be treated as a primary given its bit settings
240+
p.SetUniqueID(proc2);
241+
229242
mIndexMap[trackId] = trackId;
230-
p.SetBit(ParticleStatus::kKeep);
231-
p.SetBit(ParticleStatus::kPrimary);
232-
if (toBeDone == 1) {
233-
handleTransportPrimary(p);
234-
} else {
235-
p.SetBit(ParticleStatus::kToBeDone, 0);
243+
p.SetBit(ParticleStatus::kKeep, 1);
244+
if (p.TestBit(ParticleStatus::kToBeDone)) {
245+
mNumberOfPrimariesforTracking++;
236246
}
237247
mNumberOfPrimaryParticles++;
238248
mPrimaryParticles.push_back(p);
239249
mTracks->emplace_back(p);
240250
} else {
241-
p.SetBit(ParticleStatus::kPrimary, 0);
242-
if (toBeDone == 1) {
243-
p.SetBit(ParticleStatus::kToBeDone, 1);
244-
} else {
245-
p.SetBit(ParticleStatus::kToBeDone, 0);
246-
}
247251
mParticles.emplace_back(p);
248252
mCurrentParticle0 = p;
249253
}
@@ -255,10 +259,11 @@ void Stack::handleTransportPrimary(TParticle& p)
255259
// this function tests whether we really want to transport
256260
// this particle and sets the relevant bits accordingly
257261

258-
if (mTransportPrimary(p, mPrimaryParticles)) {
259-
p.SetBit(ParticleStatus::kToBeDone, 1);
260-
mNumberOfPrimariesforTracking++;
261-
} else {
262+
if (!p.TestBit(ParticleStatus::kToBeDone) || !p.TestBit(ParticleStatus::kPrimary)) {
263+
return;
264+
}
265+
266+
if (!mTransportPrimary(p, mPrimaryParticles)) {
262267
p.SetBit(ParticleStatus::kToBeDone, 0);
263268
p.SetBit(ParticleStatus::kInhibited, 1);
264269
}
@@ -271,15 +276,15 @@ void Stack::PushTrack(int toBeDone, TParticle& p)
271276
// This method is called
272277
//
273278
// - during parallel simulation to push primary particles (called by the stack itself)
274-
if (p.GetUniqueID() == 0) {
279+
if (p.TestBit(ParticleStatus::kPrimary)) {
275280
// one to one mapping for primaries
276281
mIndexMap[mNumberOfPrimaryParticles] = mNumberOfPrimaryParticles;
277-
// Push particle on the stack
278-
if (p.TestBit(ParticleStatus::kPrimary) && p.TestBit(ParticleStatus::kToBeDone)) {
279-
handleTransportPrimary(p);
280-
}
281282
mNumberOfPrimaryParticles++;
282283
mPrimaryParticles.push_back(p);
284+
// Push particle on the stack
285+
if (p.TestBit(ParticleStatus::kToBeDone)) {
286+
mNumberOfPrimariesforTracking++;
287+
}
283288
mStack.push(p);
284289
mTracks->emplace_back(p);
285290
}

Generators/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ o2_add_library(Generators
2727
src/GeneratorTGenerator.cxx
2828
src/GeneratorExternalParam.cxx
2929
src/GeneratorFromFile.cxx
30+
src/GeneratorFromO2KineParam.cxx
3031
src/PDG.cxx
3132
src/PrimaryGenerator.cxx
3233
src/InteractionDiamondParam.cxx
@@ -68,6 +69,7 @@ set(headers
6869
include/Generators/GeneratorTGenerator.h
6970
include/Generators/GeneratorExternalParam.h
7071
include/Generators/GeneratorFromFile.h
72+
include/Generators/GeneratorFromO2KineParam.h
7173
include/Generators/PDG.h
7274
include/Generators/PrimaryGenerator.h
7375
include/Generators/InteractionDiamondParam.h

Generators/include/Generators/GeneratorFromFile.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,15 @@ class GeneratorFromO2Kine : public o2::eventgen::Generator
7878
void SetStartEvent(int start);
7979

8080
private:
81+
/** methods that can be overridden **/
82+
void updateHeader(o2::dataformats::MCEventHeader* eventHeader) override;
83+
8184
TFile* mEventFile = nullptr; //! the file containing the persistent events
8285
TBranch* mEventBranch = nullptr; //! the branch containing the persistent events
8386
int mEventCounter = 0;
8487
int mEventsAvailable = 0;
8588
bool mSkipNonTrackable = true; //! whether to pass non-trackable (decayed particles) to the MC stack
89+
bool mContinueMode = false; //! whether we want to continue simulation of previously inhibited tracks
8690
ClassDefOverride(GeneratorFromO2Kine, 1);
8791
};
8892

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// \author R+Preghenella - January 2021
12+
13+
#ifndef ALICEO2_EVENTGEN_GENERATORFROMO2KINEPARAM_H_
14+
#define ALICEO2_EVENTGEN_GENERATORFROMO2KINEPARAM_H_
15+
16+
#include "CommonUtils/ConfigurableParam.h"
17+
#include "CommonUtils/ConfigurableParamHelper.h"
18+
19+
namespace o2
20+
{
21+
namespace eventgen
22+
{
23+
24+
/**
25+
** a parameter class/struct to keep the settings of
26+
** the FromO2Kine event generator and
27+
** allow the user to modify them
28+
**/
29+
30+
struct GeneratorFromO2KineParam : public o2::conf::ConfigurableParamHelper<GeneratorFromO2KineParam> {
31+
bool skipNonTrackable = true;
32+
bool continueMode = false;
33+
O2ParamDef(GeneratorFromO2KineParam, "GeneratorFromO2Kine");
34+
};
35+
36+
} // end namespace eventgen
37+
} // end namespace o2
38+
39+
#endif // ALICEO2_EVENTGEN_GENERATORFROMO2KINEPARAM_H_

Generators/src/Generator.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ Bool_t
131131
particle.GetStatusCode() == 1,
132132
particle.Energy() * mEnergyUnit,
133133
particle.T() * mTimeUnit,
134-
particle.GetWeight());
134+
particle.GetWeight(),
135+
(TMCProcess)particle.GetUniqueID());
135136
}
136137

137138
/** success **/

Generators/src/GeneratorFromFile.cxx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
// or submit itself to any jurisdiction.
1010

1111
#include "Generators/GeneratorFromFile.h"
12+
#include "Generators/GeneratorFromO2KineParam.h"
1213
#include "SimulationDataFormat/MCTrack.h"
14+
#include "SimulationDataFormat/MCEventHeader.h"
1315
#include <FairLogger.h>
1416
#include <FairPrimaryGenerator.h>
1517
#include <TBranch.h>
@@ -176,6 +178,13 @@ GeneratorFromO2Kine::GeneratorFromO2Kine(const char* name)
176178
}
177179
}
178180
LOG(ERROR) << "Problem reading events from file " << name;
181+
182+
// read and set params
183+
auto& param = GeneratorFromO2KineParam::Instance();
184+
LOG(INFO) << "Instance \'FromO2Kine\' generator with following parameters";
185+
LOG(INFO) << param;
186+
mSkipNonTrackable = param.skipNonTrackable;
187+
mContinueMode = param.continueMode;
179188
}
180189

181190
void GeneratorFromO2Kine::SetStartEvent(int start)
@@ -201,8 +210,9 @@ bool GeneratorFromO2Kine::importParticles()
201210
mEventBranch->GetEntry(mEventCounter);
202211

203212
for (auto& t : *tracks) {
204-
// I guess we only want primaries (unless later on we continue a simulation)
205-
if (!t.isPrimary()) {
213+
214+
// in case we do not want to continue, take only primaries
215+
if (!mContinueMode && !t.isPrimary()) {
206216
continue;
207217
}
208218

@@ -221,9 +231,16 @@ bool GeneratorFromO2Kine::importParticles()
221231
auto vt = t.T();
222232
auto weight = 1.; // p.GetWeight() ??
223233
auto wanttracking = t.getToBeDone();
234+
235+
if (mContinueMode) { // in case we want to continue, do only inhibited tracks
236+
wanttracking &= t.getInhibited();
237+
}
238+
224239
LOG(DEBUG) << "Putting primary " << pdg;
225240

226241
mParticles.push_back(TParticle(pdg, wanttracking, m1, m2, d1, d2, px, py, pz, e, vx, vy, vz, vt));
242+
mParticles.back().SetUniqueID((unsigned int)t.getProcess()); // we should propagate the process ID
243+
227244
particlecounter++;
228245
}
229246
mEventCounter++;
@@ -240,6 +257,17 @@ bool GeneratorFromO2Kine::importParticles()
240257
return false;
241258
}
242259

260+
void GeneratorFromO2Kine::updateHeader(o2::dataformats::MCEventHeader* eventHeader)
261+
{
262+
/** update header **/
263+
264+
// put information about input file and event number of the current event
265+
266+
eventHeader->putInfo<std::string>("generator", "generatorFromO2Kine");
267+
eventHeader->putInfo<std::string>("inputFile", mEventFile->GetName());
268+
eventHeader->putInfo<int>("inputEventNumber", mEventCounter - 1);
269+
}
270+
243271
} // namespace eventgen
244272
} // end namespace o2
245273

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// \author R+Preghenella - January 2021
12+
13+
#include "Generators/GeneratorFromO2KineParam.h"
14+
O2ParamImpl(o2::eventgen::GeneratorFromO2KineParam);

Generators/src/GeneratorsLinkDef.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
#endif
4949
#pragma link C++ class o2::eventgen::GeneratorFromFile + ;
5050
#pragma link C++ class o2::eventgen::GeneratorFromO2Kine + ;
51+
#pragma link C++ class o2::eventgen::GeneratorFromO2KineParam + ;
52+
#pragma link C++ class o2::conf::ConfigurableParamHelper < o2::eventgen::GeneratorFromO2KineParam> + ;
5153
#pragma link C++ class o2::PDG + ;
5254
#pragma link C++ class o2::eventgen::PrimaryGenerator + ;
5355

0 commit comments

Comments
 (0)