166 TString volName = gMC->CurrentVolName();
171 if (gMC->IsTrackEntering()) {
172 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
174 TParticle* p = gMC->GetStack()->GetCurrentTrack();
176 Int_t pdgCode = p->GetPdgCode();
177 gMC->TrackMomentum(
fMom);
178 if (!
fOnlyMuons || TMath::Abs(pdgCode) == 13) {
179 fTime = gMC->TrackTime() * 1.0e09;
181 gMC->TrackPosition(
fPos);
187 pdgCode, TVector3(p->Vx(), p->Vy(), p->Vz()),
188 TVector3(p->Px(), p->Py(), p->Pz()));
189 auto* stack =
dynamic_cast<ShipStack*
>(gMC->GetStack());
190 stack->AddPoint(
kVETO);
210 const G4Track* track = step->GetTrack();
211 const G4ParticleDefinition* def = track->GetDefinition();
212 const Int_t track_pid = def->GetPDGEncoding();
213 if (std::abs(track_pid) != 211 && std::abs(track_pid) != 321) {
217 const Int_t currentTrackId = gMC->GetStack()->GetCurrentTrackNumber();
230 const G4StepPoint* pre = step->GetPreStepPoint();
231 const G4StepPoint* post = step->GetPostStepPoint();
232 const G4VPhysicalVolume* preVolume = pre->GetPhysicalVolume();
234 fSplitVolumes.count(preVolume->GetLogicalVolume()->GetName()) == 0) {
237 const Double_t mass = def->GetPDGMass() / CLHEP::GeV;
238 if (pre->GetKineticEnergy() / CLHEP::GeV <=
EMax) {
241 const Double_t delta_s = step->GetStepLength() / CLHEP::cm;
245 TParticle* part = gMC->GetStack()->GetCurrentTrack();
252 const Double_t c_tau = def->GetPDGLifeTime() / CLHEP::cm * CLHEP::c_light;
256 const G4ThreeVector pPre = pre->GetMomentum() / CLHEP::GeV;
257 const G4ThreeVector pPost = post->GetMomentum() / CLHEP::GeV;
258 const Double_t lambda_decay = pPre.mag() / mass * c_tau;
259 const Double_t P_decay = 1.0 - std::exp(-delta_s / lambda_decay);
260 if (!(P_decay > 0.0)) {
264 double polX = 0, polY = 0, polZ = 0;
266 part->GetPolarisation(polVector);
267 polX = polVector.X();
268 polY = polVector.Y();
269 polZ = polVector.Z();
270 Int_t trueParentId = part->GetFirstMother();
277 const std::size_t event_size = gMC->GetStack()->GetNtrack();
279 const std::size_t pending = secondaryBufferSize +
285 if (bufferFull || eventFull) {
294 LOG(warning) <<
"exitHadronAbsorber: intermediate split buffer "
296 << secondaryBufferSize
297 <<
" entries; skipping further per-step splitting "
298 "(reported once per event). Consider lowering "
299 "--intermediate-kaon-pion-splits or raising "
300 "--max-split-buffer.";
304 LOG(warning) <<
"exitHadronAbsorber: event size reached " << event_size
305 <<
" entries, projected size " << projected_size
306 <<
" with the pending split clones; skipping "
307 "further per-step splitting (reported once per "
308 "event). Consider lowering "
309 "--intermediate-kaon-pion-splits or raising "
332 const Double_t trackWeight = part->GetWeight();
334 PushedWeightScale(trueParentId);
335 const Int_t splitSet =
SplitSetOf(currentTrackId, trackWeight);
351 const G4ThreeVector pEnd = track->GetTrackStatus() == fAlive ? pPost : pPre;
352 const G4ThreeVector xPre = pre->GetPosition() / CLHEP::cm;
353 const G4ThreeVector xPost = post->GetPosition() / CLHEP::cm;
354 const Double_t tPre = pre->GetGlobalTime() / CLHEP::s;
355 const Double_t tPost = post->GetGlobalTime() / CLHEP::s;
358 -lambda_decay * std::log(1.0 - G4UniformRand() * P_decay);
359 const Double_t f = std::clamp(s / delta_s, 0.0, 1.0);
360 const G4ThreeVector x = xPre + f * (xPost - xPre);
361 const G4ThreeVector p = pPre + f * (pEnd - pPre);
363 clone.
pdg = track_pid;
367 clone.e = std::sqrt(p.mag2() + mass * mass);
371 clone.t = tPre + f * (tPost - tPre);
375 clone.weight = cloneWeight;
376 clone.parentID = trueParentId;
377 clone.splitSet = splitSet;
381 part->SetWeight(trackWeight * (1.0 - P_decay));
384 history->second.initial = trackWeight;
389 history->second.splits.emplace_back(tPost, trackWeight * (1.0 - P_decay));
404 LOG(fatal) <<
"exitHadronAbsorber: max split buffer (" <<
fMaxSplitBuffer
405 <<
") must be at least the endpoint split count (" <<
fNsplits
410 LOG(fatal) <<
"exitHadronAbsorber: only one instance can split per step";
414 TSeqCollection* fileList = gROOT->GetListOfFiles();
415 fout =
dynamic_cast<TFile*
>(fileList->At(0));
418 TDatabasePDG* PDG = TDatabasePDG::Instance();
419 for (
const auto& particle : kHistogrammed) {
420 for (Int_t sign : {1, -1}) {
421 if (sign < 0 && !particle.withAntiparticle) {
424 const Int_t idw = sign * particle.pdg;
425 const Int_t idhnu = HistogramId(idw);
426 TString name = PDG->GetParticle(idw)->GetName();
427 TString title = name;
428 title +=
" momentum (GeV)";
431 [[maybe_unused]] TH1D* Hidhnu =
new TH1D(key, title, 400, 0., 400.);
433 title +=
" log10-p vs log10-pt";
436 [[maybe_unused]] TH2D* Hidhnu100 =
437 new TH2D(key, title, 100, -0.3, 1.7, 100, -2., 0.5);
439 title +=
" log10-p vs log10-pt";
442 [[maybe_unused]] TH2D* Hidhnu200 =
443 new TH2D(key, title, 25, -0.3, 1.7, 100, -2., 0.5);
447 fNtuple =
new TNtuple(
"4DP",
"4DP",
"id:px:py:pz:x:y:z");
507 Int_t currentTrackId = gMC->GetStack()->GetCurrentTrackNumber();
517 Int_t track_pid = gMC->TrackPid();
519 (TMath::Abs(track_pid) == 211 || TMath::Abs(track_pid) == 321);
522 bool isNaturalDecay =
false;
524 gMC->StepProcesses(processes);
525 for (
int i = 0; i < processes.GetSize(); i++) {
526 if (processes[i] == kPDecay) {
527 isNaturalDecay =
true;
532 TParticle* part = gMC->GetStack()->GetCurrentTrack();
535 TLorentzVector finalPos, finalMom;
536 gMC->TrackPosition(finalPos);
537 gMC->TrackMomentum(finalMom);
539 double polX = 0, polY = 0, polZ = 0;
541 part->GetPolarisation(polVector);
542 polX = polVector.X();
543 polY = polVector.Y();
544 polZ = polVector.Z();
545 Int_t trueParentId = part->GetFirstMother();
566 if (isNaturalDecay) {
568 endpoint.
pdg = track_pid;
569 endpoint.
px = finalMom.Px();
570 endpoint.
py = finalMom.Py();
571 endpoint.
pz = finalMom.Pz();
572 endpoint.
e = finalMom.E();
573 endpoint.
x = finalPos.X();
574 endpoint.
y = finalPos.Y();
575 endpoint.
z = finalPos.Z();
576 endpoint.
t = finalPos.T();
577 endpoint.
polx = polX;
578 endpoint.
poly = polY;
579 endpoint.
polz = polZ;
587 endpoint.
weight = part->GetWeight() / PushedWeightScale(trueParentId);
593 part->GetWeight() /
fNsplits / PushedWeightScale(trueParentId);
594 for (
int i = 0; i <
fNsplits; ++i) {
623 gMC->TrackMomentum(
fMom);
624 TParticle* p = gMC->GetStack()->GetCurrentTrack();
625 Int_t currentID = gMC->GetStack()->GetCurrentTrackNumber();
637 Int_t pdgCode = p->GetPdgCode();
638 Int_t idabs = TMath::Abs(pdgCode);
640 Bool_t skippedNeutrino =
648 const Int_t motherId = p->GetFirstMother();
656 if (history !=
fgWeightHistory.end() && p->GetUniqueID() != kPNoProcess &&
658 auto* shipStack =
dynamic_cast<ShipStack*
>(gMC->GetStack());
659 const TParticle* mother =
660 shipStack ? shipStack->
GetParticle(motherId) :
nullptr;
661 const Double_t finalWeight = mother ? mother->GetWeight() : 0.;
662 if (finalWeight > 0.) {
663 p->SetWeight(p->GetWeight() * history->second.WeightAt(p->T()) /
673 if (!isClone && !isCarrier && (belowCut || isReplaced)) {
695 const Bool_t isCarrierOnly = isCarrier && !isClone;
696 if (isCarrierOnly && (belowCut || skippedNeutrino)) {
705 const Bool_t recordStatistics = !(isCarrierOnly && (belowCut || isReplaced));
709 if (recordStatistics && (idabs < 18 || idabs == 22 || idabs == 111 ||
710 idabs == 221 || idabs == 223 || idabs == 331 ||
711 idabs == 211 || idabs == 321 || idabs == 2212)) {
712 Double_t wspill = p->GetWeight();
713 Int_t idhnu = idabs + 10000;
718 TMath::Min(TMath::Max(TMath::Log10(
fMom.P()), -0.3), 1.69999);
720 TMath::Min(TMath::Max(TMath::Log10(
fMom.Pt()), -2.), 0.4999);
723 TH1D* h1 =
dynamic_cast<TH1D*
>(
fout->Get(key));
725 h1->Fill(
fMom.P(), wspill);
729 TH2D* h2 =
dynamic_cast<TH2D*
>(
fout->Get(key));
731 h2->Fill(l10ptot, l10pt, wspill);
735 h2 =
dynamic_cast<TH2D*
>(
fout->Get(key));
737 h2->Fill(l10ptot, l10pt, wspill);
743 if (skippedNeutrino && !isCarrier) {
756 if (!gMC->IsTrackAlive()) {
761 auto* stack =
dynamic_cast<ShipStack*
>(gMC->GetStack());
764 stack->PushTrack(1, trk.parentID, trk.pdg, trk.px, trk.py, trk.pz, trk.e,
765 trk.x, trk.y, trk.z, trk.t, trk.polx, trk.poly, trk.polz,
766 kPNoProcess, ntr, trk.weight, 999);
767 if (!trk.continuation) {
770 if (trk.splitSet >= 0) {
771 stack->SetSplitSet(ntr, trk.splitSet, trk.splitRole,
784 gMC->ForceDecayTime(0);
859 static FairGeoLoader* geoLoad = FairGeoLoader::Instance();
860 static FairGeoInterface* geoFace = geoLoad->getGeoInterface();
861 static FairGeoMedia* media = geoFace->getMedia();
862 static FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder();
864 FairGeoMedium* ShipMedium = media->getMedium(
"vacuums");
865 TGeoMedium* vac = gGeoManager->GetMedium(
"vacuums");
866 if (vac ==
nullptr) geoBuild->createMedium(ShipMedium);
867 vac = gGeoManager->GetMedium(
"vacuums");
868 gGeoManager->GetTopVolume();
869 TGeoNavigator* nav = gGeoManager->GetCurrentNavigator();
873 Double_t local[3] = {0, 0, 0};
874 if (!nav->cd(
"/MuonShieldArea_1/AbsorberVol_1")) {
875 LOG(fatal) <<
"exitHadronAbsorber: no hadron absorber in the geometry, "
876 "add the muon shield or set the plane position explicitly";
879 dynamic_cast<TGeoBBox*
>(nav->GetCurrentNode()->GetVolume()->GetShape());
880 local[2] = tmp->GetDZ();
881 Double_t global[3] = {0, 0, 0};
882 nav->LocalToMaster(local, global);
883 zLoc = global[2] + 1. *
cm;
888 TString myname(this->GetName());
889 TString shapename_prefix(myname);
891 Double_t xLocPlane = 0.0;
892 Double_t yLocPlane = 0.0;
893 Double_t zLocPlane = zLoc;
896 TGeoVolume* sensPlane =
897 gGeoManager->MakeBox(shapename_prefix +
fVetoName +
"_box", vac,
898 3.56 *
m - 1. *
mm, 1.7 *
m - 1. *
mm, 1. *
mm);
899 std::cout << this->GetName()
900 <<
", ConstructGeometry(): Created Box with dimensions: "
901 "3.56*m-1.*mm,1.7*m-1.*mm,1.*mm"
905 nav->cd(
"/MuonShieldArea_1/");
907 Double_t local[3] = {0, 0, zLoc};
909 nav->cd(
"/target_vacuum_box_1/TargetArea_1");
910 nav->LocalToMaster(local, global);
912 yLocPlane = global[1];
913 zLocPlane = global[2];
914 xLocPlane = global[0];
916 sensPlane->SetLineColor(kBlue - 10);
917 nav->GetCurrentNode()->GetVolume()->AddNode(
918 sensPlane, 1,
new TGeoTranslation(xLocPlane, yLocPlane, zLocPlane));
920 AddSensitiveVolume(sensPlane);
922 TGeoVolume* sensPlaneCyl =
923 gGeoManager->MakeTube(shapename_prefix +
fVetoName +
"_tube", vac,
924 12.51 *
cm, 12.52 *
cm, zLoc / 2.);
925 std::cout << this->GetName()
926 <<
", ConstructGeometry(): Created Tube with dimensions: "
927 "12.51*cm,12.52*cm,zLoc/2."
929 nav->cd(
"/target_vacuum_box_1/TargetArea_1/HeVolume_1");
930 nav->GetCurrentNode()->GetVolume()->AddNode(sensPlaneCyl, 1,
931 new TGeoTranslation(0, 0, 0));
933 AddSensitiveVolume(sensPlaneCyl);
939 nav->cd(
"/target_vacuum_box_1");
940 CollectVolumeNames(nav->GetCurrentNode()->GetVolume(),
fSplitVolumes);
941 LOG(info) <<
"exitHadronAbsorber: per-step splitting in "
942 <<
fSplitVolumes.size() <<
" volumes below target_vacuum_box";
std::vector< std::pair< Double_t, Double_t > > splits