8 #include <FairLogger.h>
9 #include <FairRootManager.h>
11 #include <TClonesArray.h>
12 #include <TGeoManager.h>
14 #include <TGeoVolume.h>
26 TGeoManager *geo = TGeoManager::Import(geoFile.c_str());
28 if (gGeoManager ==
nullptr)
29 LOG(fatal) <<
"Failed to load geometry file " << geoFile <<
" " << geo;
33 if (gGeoManager ==
nullptr)
34 LOG(fatal) <<
"No geometry file loaded!";
41 }
else if (
A > other.
A) {
51 auto pointCm = point / 10.;
53 std::lock_guard<std::mutex> lock(
fGeoMutex);
54 TGeoNode *
node = gGeoManager->FindNode(pointCm.X(), pointCm.Y(), pointCm.Z());
55 if (
node ==
nullptr) {
58 return node->GetVolume();
66 if (volume ==
nullptr || volName != std::string(volume->GetName())) {
76 if (volume ==
nullptr) {
79 return volume->GetName();
94 auto modelIt =
fModels.find({A, Z});
96 throw std::invalid_argument(
"Missing energy loss model for Z:" + std::to_string(Z) +
" A:" + std::to_string(A));
98 throw std::invalid_argument(
"Position of particle is not in active volume but is in " +
GetVolumeName(iniPos));
113 while (
IsInVolume(
"drift_volume", pos) && mom.E() - mom.M() > 1e-3) {
115 if (isnan(pos.X()) || isnan(mom.X())) {
116 LOG(error) <<
"Failed to simulate a point with nan!";
120 auto dir = mom.Vect().Unit();
123 double KE = mom.E() - mom.M();
124 double eLoss = model->GetEnergyLoss(KE,
fDistStep);
129 auto E = mom.E() - eLoss;
130 double p = sqrt(E * E - mom.M2());
131 mom.SetPxPyPzE(dir.X() * p, dir.Y() * p, dir.Z() * p, E);
133 LOG(debug) << mom <<
" " << mom.M() <<
" " << iniMom.M();
137 AddHit(eLoss, pos, mom, length);
152 LOG(debug) <<
"Adding a hit at element " <<
fMCPoints.GetEntriesFast() <<
" in TClonesArray.";
157 mcPoint->SetLength(length / 10.);
158 mcPoint->SetEnergyLoss(ELoss / 1000.);
164 auto posExpCoord = pos;
165 posExpCoord.SetZ(1000 - pos.Z());
166 auto corrExpCoord =
fSCModel->ApplySpaceCharge(posExpCoord);
167 corrExpCoord.SetZ(1000 + corrExpCoord.Z());
168 mcPoint->SetPosition(corrExpCoord / 10.);
170 mcPoint->SetPosition(pos / 10.);
171 mcPoint->SetMomentum(mom.Vect() / 1000.);
177 auto ioMan = FairRootManager::Instance();
178 if (ioMan ==
nullptr) {
179 LOG(fatal) <<
"The IO manager was not instatiated before attempting to simulate an event.";
183 ioMan->Register(branchName.c_str(),
"AtTPC", &
fMCPoints, perc);