-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug in decaying generators (#235)
* Refactor AtVertexPropagator Instead of counting the event number with three different variables, we now use a single variable that is a boolean to distinguish between the beam-like half of the event and the reacion-like half of the event. * Refactor AtVertexPropagator Make the modification of the boolean more explicit so the behavior is more clear. * Add AtReactionGenerator as base for all reactions. This class covers if the generator should be run or not depending on which type of event we are runnning. It should also handle if there is a child generator that still needs to run and will only mark the reaction event complete if all generators have been run. * Remove redundant sequential decays * Allow reaction gen to handle event type * Fix reaction never generating Because we are setting the event type at the end of the generator phase (adding particles to the primary track), we loose the information about if it is reaction/beam in the stepping phase where `ProcessHits` is called. To account for this we use the trackID to determine what the event type is. Alternatively, we could check AtVertexPropogator we would just have to invert it To account for hehavior in `AtTPC2Body` generator added flag to `AtReactionGenerator` to allow for any reaction to always run (even if it is a beam- like event). * Add additional tests * Fix remaining generators By definition, if an AtReactionGenerator is running then it can create new particles. We should not check for if it is a reaction event. That is handled by the base class only and should be hidden from users implementing generators. * Fix formatting * Fix clang-tidy warnings * Refactor test system - Move all tests to the same directory as the source files so they are easier to locate in the project structure. --------- Co-authored-by: anthoak13 <[email protected]>
- Loading branch information
Showing
54 changed files
with
398 additions
and
1,030 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "AtReactionGenerator.h" | ||
|
||
#include "AtVertexPropagator.h" | ||
|
||
Bool_t AtReactionGenerator::ReadEvent(FairPrimaryGenerator *primGen) | ||
{ | ||
bool isBeamEvent = AtVertexPropagator::Instance()->IsBeamEvent(); | ||
if (kIsFinalGen) | ||
AtVertexPropagator::Instance()->EndEvent(); // End the event if this is the final generator | ||
|
||
if (!isBeamEvent || kAlwaysRun) | ||
return GenerateReaction(primGen); | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef ATREACTIONGENERATOR_H | ||
#define ATREACTIONGENERATOR_H | ||
|
||
#include <FairGenerator.h> | ||
|
||
/** | ||
* This class represents a generator for reaction-like events. | ||
* When the ReadEvent method is called, this generator can assume | ||
* that it's parent vertex is stored in the AtVertexPropagator singleton. | ||
* | ||
*/ | ||
class AtReactionGenerator : public FairGenerator { | ||
protected: | ||
bool kIsFinalGen{true}; ///< Flag to indicate if this generator is the final one in the chain | ||
bool kAlwaysRun{false}; ///< Flag to indicate if this generator should always run | ||
public: | ||
virtual Bool_t ReadEvent(FairPrimaryGenerator *primGen) final; | ||
void SetSequentialDecay(Bool_t var) { kIsFinalGen = !var; } | ||
void SetAlwaysRun(Bool_t var) { kAlwaysRun = var; } | ||
|
||
protected: | ||
virtual bool GenerateReaction(FairPrimaryGenerator *primGen) = 0; | ||
}; | ||
|
||
#endif // ATREACTIONGENERATOR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "AtReactionGenerator.h" | ||
|
||
#include "AtVertexPropagator.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
class FakeAtReactionGenerator : public AtReactionGenerator { | ||
protected: | ||
bool ranEvent{false}; | ||
|
||
public: | ||
bool GenerateReaction(FairPrimaryGenerator *primGen) override | ||
{ | ||
ranEvent = true; | ||
return true; | ||
} | ||
bool RanEvent() { return ranEvent; } | ||
}; | ||
|
||
class AtReactionGeneratorTest : public ::testing::Test { | ||
protected: | ||
FakeAtReactionGenerator generator; | ||
void SetUp() override { AtVertexPropagator::Instance()->ResetForTesting(); } | ||
void TearDown() override { AtVertexPropagator::Instance()->ResetForTesting(); } | ||
}; | ||
|
||
TEST_F(AtReactionGeneratorTest, AtReactionGenerator_ReadEvent_BeamEvent) | ||
{ | ||
|
||
AtVertexPropagator::Instance()->ResetForTesting(); | ||
AtVertexPropagator::Instance()->SetIsBeamEvent(true); | ||
generator.ReadEvent(nullptr); | ||
EXPECT_FALSE(generator.RanEvent()); | ||
} | ||
|
||
TEST_F(AtReactionGeneratorTest, AtReactionGenerator_ReadEvent_NonBeamEvent) | ||
{ | ||
|
||
AtVertexPropagator::Instance()->SetIsBeamEvent(false); | ||
generator.ReadEvent(nullptr); | ||
EXPECT_TRUE(generator.RanEvent()); | ||
} | ||
|
||
TEST_F(AtReactionGeneratorTest, AtReactionGenerator_ReadEvent_AlwaysNonBeamEvent) | ||
{ | ||
|
||
AtVertexPropagator::Instance()->SetIsBeamEvent(true); | ||
generator.SetAlwaysRun(true); | ||
generator.ReadEvent(nullptr); | ||
EXPECT_TRUE(generator.RanEvent()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.