36 if (gMC->IsTrackEntering() || gMC->IsNewTrack()) {
40 fTime = gMC->TrackTime() * 1.0e09;
42 gMC->TrackPosition(
fPos);
43 gMC->TrackMomentum(
fMom);
50 if (gMC->IsTrackExiting() || gMC->IsTrackStop() ||
51 gMC->IsTrackDisappeared()) {
56 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
59 gMC->CurrentVolID(tileId);
61 TParticle* p = gMC->GetStack()->GetCurrentTrack();
62 Int_t pdgCode = p->GetPdgCode();
64 gMC->TrackPosition(Pos);
66 gMC->TrackMomentum(Mom);
67 Double_t xmean = (
fPos.X() + Pos.X()) / 2.;
68 Double_t ymean = (
fPos.Y() + Pos.Y()) / 2.;
69 Double_t zmean = (
fPos.Z() + Pos.Z()) / 2.;
73 pdgCode, TVector3(Pos.X(), Pos.Y(), Pos.Z()),
74 TVector3(Mom.Px(), Mom.Py(), Mom.Pz()));
93 TGeoVolume* top = gGeoManager->GetTopVolume();
96 TGeoMedium* scintillator = gGeoManager->GetMedium(
"Scintillator");
98 Fatal(
"ConstructGeometry",
"Medium 'Scintillator' not found.");
101 Fatal(
"ConstructGeometry",
"No regions loaded from the UBT detector map.");
104 Fatal(
"ConstructGeometry",
"UBT box dimensions not set.");
107 fDetector =
new TGeoVolumeAssembly(
"Upstream_Tagger");
109 std::map<Double_t, Int_t> regionsPerTileSize;
114 using ShapeKey = std::tuple<Long64_t, Long64_t, Long64_t, Long64_t>;
115 const auto um = [](Double_t length) {
return std::llround(length * 1.0e4); };
116 std::map<ShapeKey, TGeoVolume*> volumes;
118 if (region.sizeX <= 0. || region.sizeY <= 0.) {
119 Fatal(
"ConstructGeometry",
"UBT region %d has a non-positive size.",
122 if (region.thickness <= 0. || region.thickness >
fEnvelopeZ) {
123 Fatal(
"ConstructGeometry",
124 "UBT region %d: the thickness %g cm of its %g cm tiles is not in "
125 "(0, %g] cm, the space reserved for the UBT.",
126 region.id, region.thickness, region.constituentTileSize,
129 if (std::abs(region.x -
fCenterX) + region.sizeX / 2. >
fSizeX / 2. ||
130 std::abs(region.y -
fCenterY) + region.sizeY / 2. >
fSizeY / 2.) {
131 Fatal(
"ConstructGeometry",
"UBT region %d lies outside the UBT box.",
134 const ShapeKey shape{
um(region.sizeX),
um(region.sizeY),
135 um(region.thickness),
um(region.constituentTileSize)};
136 TGeoVolume*& regionVolume = volumes[shape];
140 const TString volumeName = TString::Format(
141 "UpstreamTaggerRegion_%dcm_%zu",
142 static_cast<Int_t
>(region.constituentTileSize), volumes.size() - 1);
144 gGeoManager->MakeBox(volumeName, scintillator, region.sizeX / 2.,
145 region.sizeY / 2., region.thickness / 2.);
147 regionVolume->SetLineColor(
148 kBlue -
static_cast<Int_t
>(region.constituentTileSize));
149 AddSensitiveVolume(regionVolume);
151 fDetector->AddNode(regionVolume, region.id,
152 new TGeoTranslation(region.x, region.y, 0.));
153 ++regionsPerTileSize[region.constituentTileSize];
157 cout <<
" Z Position (Upstream Tagger) " <<
det_zPos <<
", "
158 <<
fRegions.size() <<
" mapped regions (";
159 for (
auto it = regionsPerTileSize.begin(); it != regionsPerTileSize.end();
161 cout << (it == regionsPerTileSize.begin() ?
"" :
", ") << it->second
162 <<
" with " << it->first <<
" cm tiles";
164 cout <<
") in " << volumes.size() <<
" region shapes" << endl;