-
Notifications
You must be signed in to change notification settings - Fork 25
Simple sim addition #268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
anthoak13
wants to merge
18
commits into
ATTPC:develop
Choose a base branch
from
anthoak13:SimpleSimAddition
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Simple sim addition #268
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
090b33c
Add AtPropagator and curved-track support to AtSimpleSimulation
857b45e
Add curved-track B/E-field propagation and physics unit tests
9c33d91
Fix macros: remove framework includes, use FairBoxGenerator
3f3697f
Fix macro physics and Bragg-curve dEdx calculation
fffd5e9
Add plan for validation
7758cb0
Get grant macros working for sim comp
3e917f8
Document AtSimpleSim hook plan
294b480
Integrate SimpleSim through the detector step contract
ddc85d4
Align SimpleSim detector entry points with Geant
b95f2be
Stabilize SimpleSim validation migration
248eb78
Rewrite SimpleSim migration guide
6916984
Add replay mode for SimpleSim validation
215ddb5
Split SimpleSim generator and replay tasks
c99f655
Fix SimpleSim integration issues from code review
anthoak13 3cbdf6b
Add factory-based validation macros and update docs for model factories
anthoak13 d99f90d
Add energy loss model factory and unify SimpleSim transport API
anthoak13 4151234
Refactor SimpleSim into transport engine + detector adapter and fix r…
anthoak13 f30396a
Address PR 268 review comments and rework energy-loss + sim APIs
anthoak13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ data | |
| *#* | ||
| event.dat | ||
| pulser-files.txt | ||
| .codex | ||
| .cache/* | ||
|
|
||
| # Executables | ||
| *.exe | ||
|
|
||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -60,69 +60,62 @@ void AtTpc::Initialize() | |
| rtdb->getContainer("AtTpcGeoPar"); | ||
| } | ||
|
|
||
| void AtTpc::trackEnteringVolume() | ||
| void AtTpc::trackEnteringVolume(const StepState &step) | ||
| { | ||
| auto AZ = DecodePdG(gMC->TrackPid()); | ||
| fELoss = 0.; | ||
| // Reset the accumulator before capturing this step's energy loss, so the | ||
| // entering step contributes fELoss (not fELoss + whatever was left over). | ||
| fELossAcc = 0.; | ||
| fTime = gMC->TrackTime() * 1.0e09; | ||
| fLength = gMC->TrackLength(); | ||
| gMC->TrackPosition(fPosIn); | ||
| gMC->TrackMomentum(fMomIn); | ||
| fTrackID = gMC->GetStack()->GetCurrentTrackNumber(); | ||
|
|
||
| // Position of the first hit of the beam in the TPC volume ( For tracking purposes in the TPC) | ||
| if (fTrackID == 0 && (fVolName == "drift_volume" || fVolName == "cell")) | ||
| getTrackParametersFromStep(step); | ||
|
|
||
| if (fTrackID == 0 && IsActiveGasVolume(fVolName)) | ||
| InPos = fPosIn; | ||
|
|
||
| Int_t VolumeID = 0; | ||
| auto AZ = DecodePdG(step.pdg); | ||
|
|
||
| if (fTrackID == 0) | ||
| LOG(debug) << cGREEN << " AtTPC: Beam Event "; | ||
| else | ||
| LOG(debug) << cBLUE << " AtTPC: Reaction/Decay Event "; | ||
|
|
||
| LOG(debug) << " AtTPC: First hit in Volume " << fVolName; | ||
| LOG(debug) << " Particle : " << gMC->ParticleName(gMC->TrackPid()); | ||
| LOG(debug) << " PID PdG : " << gMC->TrackPid(); | ||
| LOG(debug) << " PID PdG : " << step.pdg; | ||
| LOG(debug) << " Atomic Mass : " << AZ.first; | ||
| LOG(debug) << " Atomic Number : " << AZ.second; | ||
| LOG(debug) << " Volume ID " << gMC->CurrentVolID(VolumeID); | ||
| LOG(debug) << " Volume ID " << step.volumeID; | ||
| LOG(debug) << " Track ID : " << fTrackID; | ||
| LOG(debug) << " Position : " << fPosIn.X() << " " << fPosIn.Y() << " " << fPosIn.Z(); | ||
| LOG(debug) << " Momentum : " << fMomIn.X() << " " << fMomIn.Y() << " " << fMomIn.Z(); | ||
| LOG(debug) << " Total relativistic energy " << gMC->Etot(); | ||
| LOG(debug) << " Total relativistic energy " << step.totalEnergy; | ||
| LOG(debug) << " Mass of the Beam particle (gAVTP) : " << AtVertexPropagator::Instance()->GetBeamMass(); | ||
| LOG(debug) << " Mass of the Tracked particle (gMC) : " << gMC->TrackMass(); // NB: with electrons | ||
| LOG(debug) << " Mass of the Tracked particle (transport) : " << step.trackMass; // NB: with electrons | ||
| LOG(debug) << " Initial energy of the beam particle in this volume : " | ||
| << ((gMC->Etot() - AtVertexPropagator::Instance()->GetBeamMass() * 0.93149401) * | ||
| << ((step.totalEnergy - AtVertexPropagator::Instance()->GetBeamMass() * 0.93149401) * | ||
| 1000.); // Relativistic Mass | ||
| LOG(debug) << " Total energy of the current track (gMC) : " | ||
| << ((gMC->Etot() - gMC->TrackMass()) * 1000.); // Relativistic Mass | ||
| << ((step.totalEnergy - step.trackMass) * 1000.); // Relativistic Mass | ||
| LOG(debug) << " ==================================================== " << cNORMAL; | ||
| } | ||
|
|
||
| void AtTpc::getTrackParametersFromMC() | ||
| void AtTpc::getTrackParametersFromStep(const StepState &step) | ||
| { | ||
| fELoss = gMC->Edep(); | ||
| fELoss = step.energyLoss; | ||
| fELossAcc += fELoss; | ||
| fTime = gMC->TrackTime() * 1.0e09; | ||
| fLength = gMC->TrackLength(); | ||
| gMC->TrackPosition(fPosIn); | ||
| gMC->TrackMomentum(fMomIn); | ||
| fTrackID = gMC->GetStack()->GetCurrentTrackNumber(); | ||
| fTime = step.timeNs; | ||
| fLength = step.trackLength; | ||
| fPosIn = step.pos; | ||
| fMomIn = step.mom; | ||
| fTrackID = step.trackID; | ||
| } | ||
|
|
||
| void AtTpc::getTrackParametersWhileExiting() | ||
| void AtTpc::getTrackParametersWhileExiting(const StepState &step) | ||
| { | ||
| fTrackID = gMC->GetStack()->GetCurrentTrackNumber(); | ||
| gMC->TrackPosition(fPosOut); | ||
| gMC->TrackMomentum(fMomOut); | ||
| fTrackID = step.trackID; | ||
| fPosOut = step.posOut; | ||
| fMomOut = step.momOut; | ||
|
|
||
| // Correct fPosOut | ||
| if (gMC->IsTrackExiting()) { | ||
| if (step.exiting) { | ||
| correctPosOut(); | ||
| if ((fVolName.Contains("drift_volume") || fVolName.Contains("cell")) && fTrackID == 0) | ||
| if (IsActiveGasVolume(fVolName) && fTrackID == 0) | ||
| resetVertex(); | ||
| } | ||
| } | ||
|
|
@@ -135,6 +128,9 @@ void AtTpc::resetVertex() | |
|
|
||
| void AtTpc::correctPosOut() | ||
| { | ||
| if (gGeoManager == nullptr) | ||
| return; // No geometry (e.g. unit tests); caller's fPosOut is already final. | ||
|
|
||
| const Double_t *oldpos = nullptr; | ||
| const Double_t *olddirection = nullptr; | ||
| Double_t newpos[3]; | ||
|
|
@@ -166,61 +162,94 @@ bool AtTpc::reactionOccursHere() | |
| { | ||
| bool atEnergyLoss = fELossAcc * 1000 > AtVertexPropagator::Instance()->GetRndELoss(); | ||
| bool isPrimaryBeam = fTrackID == 0; | ||
| bool isInRightVolume = fVolName.Contains("drift_volume") || fVolName.Contains("cell"); | ||
| bool isInRightVolume = IsActiveGasVolume(fVolName); | ||
| return atEnergyLoss && isPrimaryBeam && isInRightVolume; | ||
| } | ||
|
|
||
| Bool_t AtTpc::ProcessHits(FairVolume *vol) | ||
| { | ||
| /** This method is called from the MC stepping */ | ||
|
|
||
| auto *stack = dynamic_cast<AtStack *>(gMC->GetStack()); | ||
| fVolName = gMC->CurrentVolName(); | ||
| fVolumeID = vol->getMCid(); | ||
| fDetCopyID = vol->getCopyNo(); | ||
|
|
||
| if (gMC->IsTrackEntering()) | ||
| trackEnteringVolume(); | ||
|
|
||
| getTrackParametersFromMC(); | ||
|
|
||
| if (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()) | ||
| getTrackParametersWhileExiting(); | ||
|
|
||
| addHit(); | ||
| StepState step; | ||
| step.trackID = gMC->GetStack()->GetCurrentTrackNumber(); | ||
| step.pdg = gMC->TrackPid(); | ||
| step.volumeName = gMC->CurrentVolName(); | ||
| step.volumeID = vol->getMCid(); | ||
| step.detCopyID = vol->getCopyNo(); | ||
| step.entering = gMC->IsTrackEntering(); | ||
| step.exiting = gMC->IsTrackExiting(); | ||
| step.stopping = gMC->IsTrackStop(); | ||
| step.disappeared = gMC->IsTrackDisappeared(); | ||
| step.energyLoss = gMC->Edep(); | ||
| step.timeNs = gMC->TrackTime() * 1.0e09; | ||
| step.trackLength = gMC->TrackLength(); | ||
| step.totalEnergy = gMC->Etot(); | ||
| step.trackMass = gMC->TrackMass(); | ||
| gMC->TrackPosition(step.pos); | ||
| gMC->TrackMomentum(step.mom); | ||
|
|
||
| if (step.exiting || step.stopping || step.disappeared) { | ||
| gMC->TrackPosition(step.posOut); | ||
| gMC->TrackMomentum(step.momOut); | ||
| } | ||
|
|
||
| // Reaction Occurs here | ||
| if (reactionOccursHere()) | ||
| startReactionEvent(); | ||
| bool stopTrack = ProcessStep(step); | ||
| if (stopTrack) | ||
| gMC->StopTrack(); | ||
|
|
||
| // Increment number of AtTpc det points in TParticle | ||
| stack->AddPoint(kAtTpc); | ||
| return kTRUE; | ||
| } | ||
|
|
||
| void AtTpc::startReactionEvent() | ||
| bool AtTpc::ProcessStep(const StepState &step) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this repeat so much of process hits? What is the difference. |
||
| { | ||
| fVolName = step.volumeName; | ||
| fVolumeID = step.volumeID; | ||
| fDetCopyID = step.detCopyID; | ||
|
|
||
| if (step.entering) | ||
| trackEnteringVolume(step); | ||
| else | ||
| getTrackParametersFromStep(step); | ||
|
|
||
| if (step.exiting || step.stopping || step.disappeared) | ||
| getTrackParametersWhileExiting(step); | ||
|
|
||
| addHit(step); | ||
|
|
||
| if (reactionOccursHere()) { | ||
| startReactionEvent(step); | ||
| return true; | ||
| } | ||
|
|
||
| gMC->StopTrack(); | ||
| return false; | ||
| } | ||
|
|
||
| void AtTpc::startReactionEvent(const StepState &step) | ||
| { | ||
| AtVertexPropagator::Instance()->ResetVertex(); | ||
|
|
||
| TLorentzVector StopPos; | ||
| TLorentzVector StopMom; | ||
| gMC->TrackPosition(StopPos); | ||
| gMC->TrackMomentum(StopMom); | ||
| Double_t StopEnergy = ((gMC->Etot() - AtVertexPropagator::Instance()->GetBeamMass() * 0.93149401) * 1000.); | ||
| const TLorentzVector &StopPos = step.pos; | ||
| const TLorentzVector &StopMom = step.mom; | ||
| Double_t StopEnergy = ((step.totalEnergy - AtVertexPropagator::Instance()->GetBeamMass() * 0.93149401) * 1000.); | ||
|
|
||
| LOG(info) << "AtTpc: triggering reaction handoff at z=" << StopPos.Z() << " cm with accumulated loss " | ||
| << fELossAcc * 1000. << " MeV and residual energy " << StopEnergy << " MeV"; | ||
|
|
||
| LOG(debug) << cYELLOW << " Beam energy loss before reaction : " << fELossAcc * 1000; | ||
| LOG(debug) << " Mass of the Tracked particle : " << gMC->TrackMass(); | ||
| LOG(debug) << " Mass of the Tracked particle : " << step.trackMass; | ||
| LOG(debug) << " Mass of the Beam particle (gAVTP) : " << AtVertexPropagator::Instance()->GetBeamMass(); | ||
| LOG(debug) << " Total energy of the Beam particle before reaction : " << StopEnergy << cNORMAL; // Relativistic Mass | ||
|
|
||
| AtVertexPropagator::Instance()->SetVertex(StopPos.X(), StopPos.Y(), StopPos.Z(), InPos.X(), InPos.Y(), InPos.Z(), | ||
| StopMom.Px(), StopMom.Py(), StopMom.Pz(), StopEnergy); | ||
| } | ||
|
|
||
| void AtTpc::addHit() | ||
| void AtTpc::addHit(const StepState &step) | ||
| { | ||
| auto AZ = DecodePdG(gMC->TrackPid()); | ||
| auto AZ = DecodePdG(step.pdg); | ||
|
|
||
| Double_t EIni = 0; | ||
| Double_t AIni = 0; | ||
|
|
@@ -239,6 +268,11 @@ void AtTpc::addHit() | |
| TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()), fTime, fLength, fELoss, EIni, AIni, AZ.first, AZ.second); | ||
| } | ||
|
|
||
| bool AtTpc::IsActiveGasVolume(const TString &volumeName) const | ||
| { | ||
| return volumeName.Contains("drift_volume") || volumeName.Contains("cell"); | ||
| } | ||
|
|
||
| void AtTpc::EndOfEvent() | ||
| { | ||
|
|
||
|
|
@@ -286,21 +320,11 @@ void AtTpc::ConstructGeometry() | |
|
|
||
| Bool_t AtTpc::CheckIfSensitive(std::string name) | ||
| { | ||
|
|
||
| TString tsname = name; | ||
| if (tsname.Contains("drift_volume") || tsname.Contains("window") || tsname.Contains("cell")) { | ||
| LOG(info) << " AtTPC geometry: Sensitive volume found: " << tsname; | ||
| return kTRUE; | ||
| } | ||
| return kFALSE; | ||
| } | ||
|
|
||
| AtMCPoint * | ||
| AtTpc::AddHit(Int_t trackID, Int_t detID, TVector3 pos, TVector3 mom, Double_t time, Double_t length, Double_t eLoss) | ||
| { | ||
| TClonesArray &clref = *fAtTpcPointCollection; | ||
| Int_t size = clref.GetEntriesFast(); | ||
| return new (clref[size]) AtMCPoint(trackID, detID, pos, mom, time, length, eLoss); | ||
| const bool sensitive = name.find("drift_volume") != std::string::npos || name.find("window") != std::string::npos || | ||
| name.find("cell") != std::string::npos; | ||
| if (sensitive) | ||
| LOG(debug) << " AtTPC geometry: Sensitive volume found: " << name; | ||
| return sensitive ? kTRUE : kFALSE; | ||
| } | ||
|
|
||
| // ----- Private method AddHit -------------------------------------------- | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this function called anywhere anymore?