FairShip
Loading...
Searching...
No Matches
MuGeoProcessor.cxx
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP
3// Collaboration
4
5#include "MuGeoProcessor.h"
6
7#include <algorithm>
8#include <cmath>
9#include <fstream>
10#include <functional>
11#include <limits>
12#include <stdexcept>
13#include <utility>
14
15#include "TGeoBBox.h"
16
17using namespace ShipMuDIS;
18
20 fZmax = 14000;
21 fZmin = 2500;
22}
23
26
28 TGeoManager* geometry) {
29 if (!field || !geometry || geometry != gGeoManager)
30 throw std::invalid_argument(
31 "Shield transport requires a map and the active geometry");
33 std::make_unique<MagneticTrackPropagator>(nullptr, geometry, field);
34 fPropagator->SetAccuracy(1.e-4, 1.e-7, 0.5);
35 fGeometry = nullptr;
36 fTopNode = nullptr;
38}
39
41 if (!gGeoManager || !gGeoManager->GetTopNode())
42 throw std::runtime_error("Muon path discovery requires a closed geometry");
43 if (fGeometry == gGeoManager && fTopNode == gGeoManager->GetTopNode()) return;
44 if (fGeometry && fGeometry != gGeoManager && fPropagator)
45 throw std::runtime_error(
46 "Configure the shield field again after changing geometry");
47 fGeometry = gGeoManager;
48 fTopNode = gGeoManager->GetTopNode();
49 fShieldVolumes.clear();
50 fShieldMinZ = std::numeric_limits<double>::infinity();
51 std::function<void(TGeoNode*, const TGeoHMatrix&, bool)> visit;
52 visit = [&](TGeoNode* node, const TGeoHMatrix& parent, bool inShield) {
53 TGeoHMatrix transform(parent);
54 transform.Multiply(node->GetMatrix());
55 auto* volume = node->GetVolume();
56 const std::string name = volume->GetName();
57 inShield = inShield || name == "MuonShieldArea";
58 if (inShield && name.find("Magn") != std::string::npos &&
59 !volume->IsAssembly()) {
60 fShieldVolumes.insert(volume);
61 // Geometry is used only for material navigation and the upstream
62 // stopping plane, never to decide whether a track needs bending.
63 auto* box = dynamic_cast<TGeoBBox*>(volume->GetShape());
64 if (!box)
65 throw std::runtime_error("Shield magnet has no bounding box: " + name);
66 box->ComputeBBox();
67 const auto* origin = box->GetOrigin();
68 for (double x : {-box->GetDX(), box->GetDX()})
69 for (double y : {-box->GetDY(), box->GetDY()})
70 for (double z : {-box->GetDZ(), box->GetDZ()}) {
71 const double local[3] = {origin[0] + x, origin[1] + y,
72 origin[2] + z};
73 double global[3];
74 transform.LocalToMaster(local, global);
75 fShieldMinZ = std::min(fShieldMinZ, global[2]);
76 }
77 }
78 for (int i = 0; i < node->GetNdaughters(); ++i)
79 visit(node->GetDaughter(i), transform, inShield);
80 };
81 visit(fTopNode, TGeoHMatrix(), false);
82}
83
84bool MuGeoProcessor::AddMagneticChord(const TVector3& a, const TVector3& b,
85 double momentum, double& time,
86 unsigned depth) {
87 double error = 0.;
88 TVector3 middle;
89 for (double fraction : {0.25, 0.5, 0.75}) {
90 TVector3 point;
91 if (!fPropagator->PositionAt(a.Z() + fraction * (b.Z() - a.Z()), point))
92 return false;
93 error = std::max(error, (point - (a + fraction * (b - a))).Mag());
94 if (fraction == 0.5) middle = point;
95 }
96 if (error > 1.e-4) {
97 if (depth == 30) return false;
98 return AddMagneticChord(a, middle, momentum, time, depth + 1) &&
99 AddMagneticChord(middle, b, momentum, time, depth + 1);
100 }
101 const TVector3 displacement = b - a;
102 fSegments.push_back(
103 {{a, momentum * displacement.Unit(), time}, a.Z(), b.Z(), false});
104 const double speed =
105 ShipUnit::c_light * momentum / std::hypot(momentum, MuonMass());
106 time += displacement.Mag() / speed;
107 return true;
108}
109
111 double charge, double endZ) {
112 if (!fPropagator->BuildTrajectory(charge, start.position, start.momentum,
113 endZ))
114 return false;
115 double time = start.time;
116 TVector3 previous = start.position, position, momentum;
117 for (std::size_t i = 1; i < fPropagator->GetTrajectorySize(); ++i) {
118 if (!fPropagator->GetTrajectoryState(i, position, momentum) ||
119 !AddMagneticChord(previous, position, start.momentum.Mag(), time))
120 return false;
121 previous = position;
122 }
123 return true;
124}
125
127 if (fSegments.empty()) return fStart.position.Z();
128 const TVector3 direction = hit.momentum.Unit();
129 double bestDistance = std::numeric_limits<double>::infinity();
130 double pocaZ = fStart.position.Z();
131 // Minimize the distance between each refined trajectory chord and the
132 // hit's line. Use the midpoint of the closest pair, as in GetVertex().
133 for (const auto& segment : fSegments) {
134 const auto& m = segment.measurement;
135 const TVector3 delta = m.position - hit.position;
136 const TVector3 slope = m.momentum * (1. / m.momentum.Z());
137 const TVector3 transverse = slope - slope.Dot(direction) * direction;
138 const double denominator = transverse.Mag2();
139 const double dz = denominator < 1.e-12
140 ? 0.
141 : std::clamp(-delta.Dot(transverse) / denominator, 0.,
142 segment.endZ - segment.startZ);
143 const TVector3 onTrack = m.position + dz * slope;
144 const TVector3 onLine =
145 hit.position + (onTrack - hit.position).Dot(direction) * direction;
146 const double distance = (onTrack - onLine).Mag2();
147 if (distance < bestDistance) {
148 bestDistance = distance;
149 pocaZ =
150 denominator < 1.e-12 ? onTrack.Z() : 0.5 * (onTrack.Z() + onLine.Z());
151 }
152 }
153 return std::clamp(pocaZ, fStart.position.Z(), fSegments.back().endZ);
154}
155
157 if (!std::isfinite(threshold) || threshold < 0.)
158 throw std::invalid_argument(
159 "POCA jump threshold must be finite and nonnegative");
160 fPocaJumpThreshold = threshold;
161}
162
171
173 LOG(info) << "Muon path diagnostics: " << fMuons << " muons considered, "
174 << fBackwardMuons << " rejected for non-forward momentum, "
175 << fInvalidMuons << " rejected for invalid measurements";
176 LOG(info) << "Muon path routes prepared (before material navigation): "
177 << fUBTBackwardPaths << " from UBT with backward extrapolation, "
178 << fStartMagneticPaths << " from MC start in field, "
180 << " from MC start in field-free region (bending on field entry); "
181 << fStartsBeyondZmax << " skipped with start z >= maximum z";
182 LOG(info) << "UBT backward paths missing MS: " << fUBTBackwardMisses;
183 LOG(info) << "Muons starting before z = " << fZmin
184 << " cm (paths still built): " << fStartsBeforeZmin;
185 LOG(info) << "POCA transverse jumps: " << fLargeJumps << " of "
186 << fTransitions << " transitions exceed " << fPocaJumpThreshold
187 << " cm, in " << fMuonsWithLargeJumps
188 << " muons; maximum jump = " << fMaxTransverseJump << " cm";
189 LOG(info) << "Muon path diagnostics (sum MCTrack[0].fW): "
190 << fMuonWeights.considered << " considered, "
191 << fMuonWeights.backward << " rejected for non-forward momentum, "
192 << fMuonWeights.invalid << " rejected for invalid measurements"
193 << " (entries without MCTrack have no weight)";
194 LOG(info) << "Muon path routes prepared (sum MCTrack[0].fW): "
195 << fMuonWeights.ubtBackward << " from UBT, "
196 << fMuonWeights.startMagnetic << " from MC start in field, "
197 << fMuonWeights.startStraight
198 << " from MC start in field-free region, "
199 << fMuonWeights.beyondZmax << " skipped with start z >= maximum z";
200 LOG(info) << "UBT backward paths missing MS (sum MCTrack[0].fW): "
201 << fMuonWeights.ubtMiss;
202 LOG(info) << "Muons starting before z = " << fZmin
203 << " cm (sum MCTrack[0].fW): " << fMuonWeights.beforeZmin;
204 LOG(info) << "Muons with large POCA transverse jumps (sum MCTrack[0].fW): "
205 << fMuonWeights.largeJump;
206}
207
209 fSegments.clear();
210 fTraceBackward = false;
211 fPathMap.clear();
212 fMuonWeight = aEvt.mcTrks.empty() ? 0. : aEvt.mcTrks[0].GetWeight();
213 ++fMuons;
214 fMuonWeights.considered += fMuonWeight;
215 if (aEvt.mcTrks.empty()) {
217 fMuonWeights.invalid += fMuonWeight;
218 return false;
219 }
220
221 std::array<Measurement, 8> measurements;
222 unsigned count = 1;
223 aEvt.mcTrks[0].GetStartVertex(measurements[0].position);
224 aEvt.mcTrks[0].GetMomentum(measurements[0].momentum);
225 measurements[0].time = aEvt.mcTrks[0].GetStartT();
226 const auto addHit = [&](const auto& hit) {
227 auto& measurement = measurements[count++];
228 hit.Position(measurement.position);
229 hit.Momentum(measurement.momentum);
230 measurement.time = hit.GetTime();
231 };
232 if (!aEvt.ubtPt.empty()) addHit(aEvt.ubtPt.front());
233 if (!aEvt.sbtPt.empty()) addHit(aEvt.sbtPt.front());
234 std::array<bool, 4> found = {};
235 unsigned stations = 0;
236 for (const auto& hit : aEvt.sstPt) {
237 const int station = hit.GetDetectorID() / 1000000;
238 if (station < 1 || station > 4 || found[station - 1]) continue;
239 found[station - 1] = true;
240 addHit(hit);
241 if (++stations == 4) break;
242 }
243 if (!aEvt.tdPt.empty()) addHit(aEvt.tdPt.front());
244
245 for (unsigned i = 0; i < count; ++i) {
246 const auto& m = measurements[i];
247 if (!std::isfinite(m.position.X()) || !std::isfinite(m.position.Y()) ||
248 !std::isfinite(m.position.Z()) || !std::isfinite(m.momentum.X()) ||
249 !std::isfinite(m.momentum.Y()) || !std::isfinite(m.momentum.Z()) ||
250 !std::isfinite(m.momentum.Mag()) || !std::isfinite(m.time) ||
251 m.momentum.Mag() == 0.) {
253 fMuonWeights.invalid += fMuonWeight;
254 return false;
255 }
256 if (m.momentum.Z() <= 0.) {
258 fMuonWeights.backward += fMuonWeight;
259 return false;
260 }
261 if (m.position.Z() < measurements[0].position.Z()) {
263 fMuonWeights.invalid += fMuonWeight;
264 return false;
265 }
266 }
267 // Stable insertion sort for at most seven hits, without allocating storage.
268 for (unsigned i = 2; i < count; ++i) {
269 const auto measurement = measurements[i];
270 unsigned j = i;
271 while (j > 1 &&
272 measurements[j - 1].position.Z() > measurement.position.Z()) {
273 measurements[j] = measurements[j - 1];
274 --j;
275 }
276 measurements[j] = measurement;
277 }
278
280 fStart = measurements[0];
281 if (fStart.position.Z() >= fZmax) {
283 fMuonWeights.beyondZmax += fMuonWeight;
284 return true;
285 }
286 const bool hasUBT = !aEvt.ubtPt.empty();
287 if (hasUBT) {
288 aEvt.ubtPt.front().Position(fUBT.position);
289 aEvt.ubtPt.front().Momentum(fUBT.momentum);
290 fUBT.time = aEvt.ubtPt.front().GetTime();
291 }
292 double startZ = fStart.position.Z();
293 unsigned first = 0;
294 if (hasUBT) {
295 fTraceBackward = true;
296 // UBT always anchors both legs, irrespective of the MC start or field.
297 unsigned kept = 1;
298 for (unsigned i = 1; i < count; ++i)
299 if (measurements[i].position.Z() > fUBT.position.Z())
300 measurements[kept++] = measurements[i];
301 measurements[0] = fUBT;
302 count = kept;
303 startZ = fUBT.position.Z();
305 fMuonWeights.ubtBackward += fMuonWeight;
306 } else if (fPropagator) {
307 const bool startsInField = fPropagator->HasFieldAt(fStart.position);
308 // The propagator skips field-free regions linearly and resumes bending
309 // whenever the line enters a nonzero map region, including fringes.
310 const double endZ =
311 count > 1 ? std::min(fZmax, measurements[1].position.Z()) : fZmax;
312 const double charge = aEvt.mcTrks[0].GetPdgCode() == 13 ? -1. : 1.;
313 if (!AddMagneticSegments(fStart, charge, endZ)) {
314 LOG(error) << "Muon shield magnetic propagation failed at start z = "
315 << startZ;
316 fSegments.clear();
318 fMuonWeights.invalid += fMuonWeight;
319 return false;
320 }
321 startZ = count > 1 ? GetTrajectoryPocaZ(measurements[1]) : endZ;
322 // Keep only the trajectory before the switching plane. The first
323 // detector line takes over there, including a POCA inside the field.
324 while (!fSegments.empty() && fSegments.back().startZ >= startZ)
325 fSegments.pop_back();
326 if (fSegments.empty())
327 fSegments.push_back({fStart, startZ, startZ, false});
328 else
329 fSegments.back().endZ = startZ;
330 first = 1;
331 if (startsInField) {
333 fMuonWeights.startMagnetic += fMuonWeight;
334 } else {
336 fMuonWeights.startStraight += fMuonWeight;
337 }
338 } else {
339 if (!fShieldVolumes.empty())
340 throw std::runtime_error(
341 "Muon without UBT requires a configured shield field map");
343 fMuonWeights.startStraight += fMuonWeight;
344 }
345 for (unsigned i = first; i < count && startZ < fZmax; ++i) {
346 const auto& m = measurements[i];
347 const double pocaZ =
348 i + 1 < count ? std::min(fZmax, GetVertex(m.position, m.momentum,
349 measurements[i + 1].position,
350 measurements[i + 1].momentum)
351 .Z())
352 : fZmax;
353 // Switching planes must remain ordered to avoid replaying material.
354 const double endZ = std::max(startZ, pocaZ);
355 fSegments.push_back({m, startZ, endZ, i > 0});
356 startZ = endZ;
357 }
358 return true;
359}
360
361TVector3 MuGeoProcessor::GetVertex(const TVector3& r1, const TVector3& p1,
362 const TVector3& r2, const TVector3& p2) {
363 TVector3 u1 = p1.Unit();
364 TVector3 u2 = p2.Unit();
365
366 TVector3 w0 = r1 - r2;
367
368 double a = u1 * u1;
369 double b = u1 * u2;
370 double c = u2 * u2;
371
372 double d = u1 * w0;
373 double e = u2 * w0;
374
375 double denom = a * c - b * b;
376
377 // Protect against nearly parallel tracks
378 if (std::abs(denom) < 1e-12) {
379 LOG(debug) << "GetVertex(): nearly parallel tracks (denominator = " << denom
380 << "). Returning first measurement.";
381 return r1;
382 }
383
384 double t = (b * e - c * d) / denom;
385 double s = (a * e - b * d) / denom;
386
387 TVector3 poca1 = r1 + t * u1;
388 TVector3 poca2 = r2 + s * u2;
389
390 TVector3 vertex = 0.5 * (poca1 + poca2);
391
392 double zmin = std::min(r1.Z(), r2.Z());
393 double zmax = std::max(r1.Z(), r2.Z());
394
395 // Clamp the POCA to the measured interval
396 if (vertex.Z() < zmin) {
397 return (r1.Z() < r2.Z()) ? r1 : r2;
398 }
399
400 if (vertex.Z() > zmax) {
401 return (r1.Z() > r2.Z()) ? r1 : r2;
402 }
403
404 return vertex;
405}
406
408 std::map<std::string, double> lMap;
409 std::map<std::pair<std::string, std::string>, double> volumeMaterials;
410 if (!gGeoManager) {
411 LOG(error) << "gGeoManager does not exist!";
412 return;
413 }
414
415 double z = 2000;
416 double step = 50;
417 double stepd = 0.1;
418 int nS = 8;
419 int nSD = 10;
420 for (int ix(-nS); ix < nS + 1; ++ix) {
421 for (int iy(-nS); iy < nS + 1; ++iy) {
422 for (int idx(-nSD); idx < nSD + 1; ++idx) {
423 for (int idy(-nSD); idy < nSD + 1; ++idy) {
424 if (pow(idx * stepd, 2) + pow(idy * stepd, 2) > 1) continue;
425 double dz = sqrt(1 - pow(idx * stepd, 2) - pow(idy * stepd, 2));
426 TGeoNode* startnode = gGeoManager->InitTrack(
427 ix * step, iy * step, z, idx * stepd, idy * stepd, dz);
428 if (!startnode) {
429 LOG(error) << "Muon start point out of geometry: " << ix * step
430 << " " << iy * step << " " << z << " " << idx * stepd
431 << " " << idy * stepd << " " << dz;
432 continue;
433 }
434 TGeoNode* currentnode = gGeoManager->GetCurrentNode();
435 double snext = z;
436 unsigned lcount = 0;
437
438 while (currentnode) {
439 const auto* geoMaterial =
440 currentnode->GetVolume()->GetMedium()->GetMaterial();
441 std::string material = geoMaterial->GetName();
442 std::string volName = currentnode->GetVolume()->GetName();
443 volumeMaterials.emplace(std::make_pair(volName, material),
444 geoMaterial->GetDensity());
445 // if (volName.find("Tr2") != volName.npos) break;
446 volName.append("_");
447 volName.append(material);
448 lMap.emplace(volName, snext);
449 currentnode = gGeoManager->FindNextBoundaryAndStep();
450 snext += gGeoManager->GetStep() * dz;
451
452 // for safety...
453 if (lcount > 1000) {
454 LOG(info) << "Reached 1000 iterations in checking all volumes, "
455 "stopping there: z="
456 << snext << " cm, x=" << ix * step << " y=" << iy * step
457 << " z=" << z << " dir_x=" << idx * stepd
458 << " dir_y=" << idy * stepd << " dir_z=" << dz;
459 break;
460 }
461 lcount++;
462 }
463 }
464 }
465 }
466 }
467
468 LOG(info) << " -- All volumes found in geometry: n=" << lMap.size();
469 for (auto lele = lMap.begin(); lele != lMap.end(); ++lele) {
470 LOG(info) << lele->first << " " << lele->second;
471 }
472
473 std::map<std::string, std::ostringstream> categoryOutput;
474 MuonPath path;
475 for (const auto& entry : volumeMaterials) {
476 const auto& volName = entry.first.first;
477 const auto& material = entry.first.second;
478 categoryOutput[path.GetLabel(volName, material)]
479 << " volume=" << volName << ", material=" << material
480 << ", density=" << entry.second << " g/cm^3\n";
481 }
482 std::ostringstream summary;
483 summary << " -- Unique volumes and materials by MatType:\n";
484 for (const auto& category : MatTypeStr) {
485 summary << "MatType " << category.Data() << ":\n"
486 << categoryOutput[category.Data()].str();
487 }
488 LOG(info) << summary.str();
489 std::ofstream output("CheckAllVolumes.txt");
490 output << summary.str();
491 output.close();
492 if (!output) {
493 LOG(warning) << "Could not write volume summary to CheckAllVolumes.txt";
494 }
495}
496
498 auto inserted = fPathMap.emplace(path.GetLabel(), path);
499 if (!inserted.second) inserted.first->second.Add(path);
500}
501
502bool MuGeoProcessor::Trace(const Measurement& measurement, double startZ,
503 double endZ, bool backward) {
504 if (startZ == endZ) return true;
505 const TVector3 forward = measurement.momentum.Unit();
506 const TVector3 direction = backward ? -forward : forward;
507 const TVector3 start =
508 measurement.position +
509 ((startZ - measurement.position.Z()) / forward.Z()) * forward;
510 auto* node =
511 gGeoManager->InitTrack(start.X(), start.Y(), start.Z(), direction.X(),
512 direction.Y(), direction.Z());
513 std::vector<MuonPath> reverse;
514 double shieldZ = 0.;
515 bool reachedEnd = false;
516 unsigned steps = 0;
517 while (node) {
518 const auto* point = gGeoManager->GetCurrentPoint();
519 const TVector3 current(point[0], point[1], point[2]);
520 const double remaining = (endZ - current.Z()) / direction.Z();
521 if (remaining <= 1.e-8) {
522 reachedEnd = true;
523 break;
524 }
525 if (++steps > 10000) {
526 LOG(error) << "Muon geometry stepping did not converge at z = "
527 << current.Z();
528 break;
529 }
530 const auto* volume = node->GetVolume();
531 const auto* material = volume->GetMaterial();
532 if (!material) break;
533 const std::string name = volume->GetName();
534 const bool shield = fShieldVolumes.count(volume) != 0;
535 double limit = remaining;
536 if (backward && shield)
537 limit = std::min(limit, (kMuonShieldTailZ - shieldZ) / forward.Z());
538 node = gGeoManager->FindNextBoundaryAndStep(limit, kFALSE);
539 const double step = std::min(gGeoManager->GetStep(), limit);
540 if (!std::isfinite(step) || step < 0.) break;
541 if (step > 0.) {
542 MuonPath path;
543 path.AddVolume(name, material->GetName(), material->GetDensity());
544 // Only magnets inside MuonShieldArea belong to the shield category.
545 if (path.GetLabel() == "MS" && !shield) path.SetLabel("REST");
546 path.SetVertexInfo(measurement.position, measurement.momentum,
547 measurement.time);
548 path.SetLength(step, backward ? current + step * direction : current,
549 step * forward.Z());
550 fVolMap[path.GetLabel()].insert(name + "_" + material->GetName());
551 if (backward)
552 reverse.push_back(path);
553 else
554 AddPath(path);
555 if (shield) shieldZ += step * forward.Z();
556 }
557 if (remaining - step <= 1.e-8 ||
558 (backward && shieldZ >= kMuonShieldTailZ - 1.e-8)) {
559 reachedEnd = true;
560 break;
561 }
562 }
563 // Leaving the world is a valid end of the material path.
564 if (!node && gGeoManager->IsOutside()) reachedEnd = true;
565 if (reachedEnd)
566 for (auto it = reverse.rbegin(); it != reverse.rend(); ++it) AddPath(*it);
567 return reachedEnd;
568}
569
570std::map<std::string, MuonPath>& MuGeoProcessor::FillMuonPath() {
571 fPathMap.clear();
572 if (!gGeoManager || (fSegments.empty() && !fTraceBackward)) return fPathMap;
573 // Informational only: upstream starts are routed via UBT or field transport.
574 if (fStart.position.Z() < fZmin) {
576 fMuonWeights.beforeZmin += fMuonWeight;
577 LOG(debug) << "Muon starts at z = " << fStart.position.Z()
578 << " cm, before z_min = " << fZmin << " cm";
579 }
580
581 if (fTraceBackward) {
582 const double high = std::min(fUBT.position.Z(), fZmax);
583 const double low = std::isfinite(fShieldMinZ) ? fShieldMinZ : fZmin;
584 if (high > low && !Trace(fUBT, high, low, true)) {
585 fPathMap.clear();
586 return fPathMap;
587 }
588 if (fPathMap.count("MS") == 0) {
590 fMuonWeights.ubtMiss += fMuonWeight;
591 LOG(debug)
592 << "UBT backward extrapolation does not cross MS: start position ("
593 << fStart.position.X() << ", " << fStart.position.Y() << ", "
594 << fStart.position.Z() << "), start momentum (" << fStart.momentum.X()
595 << ", " << fStart.momentum.Y() << ", " << fStart.momentum.Z()
596 << "), UBT position (" << fUBT.position.X() << ", "
597 << fUBT.position.Y() << ", " << fUBT.position.Z()
598 << "), UBT momentum (" << fUBT.momentum.X() << ", "
599 << fUBT.momentum.Y() << ", " << fUBT.momentum.Z() << "), start time "
600 << fStart.time << ", UBT time " << fUBT.time;
601 }
602 }
603
604 bool hasPrevious = false;
605 bool hasLargeJump = false;
606 TVector3 previousEnd;
607 for (const auto& segment : fSegments) {
608 const auto& m = segment.measurement;
609 const TVector3 direction = m.momentum.Unit();
610 const TVector3 start =
611 m.position +
612 ((segment.startZ - m.position.Z()) / direction.Z()) * direction;
613 if (hasPrevious && segment.measurementTransition) {
614 const double jump = (start - previousEnd).Perp();
615 ++fTransitions;
616 fMaxTransverseJump = std::max(fMaxTransverseJump, jump);
617 if (jump > fPocaJumpThreshold) {
618 ++fLargeJumps;
619 hasLargeJump = true;
620 }
621 }
622 if (!Trace(m, segment.startZ, segment.endZ)) {
623 fPathMap.clear();
624 return fPathMap;
625 }
626 previousEnd = m.position +
627 ((segment.endZ - m.position.Z()) / direction.Z()) * direction;
628 hasPrevious = true;
629 }
630 if (hasLargeJump) {
632 fMuonWeights.largeJump += fMuonWeight;
633 }
634 return fPathMap;
635}
636
638 LOG(info) << " -- Volume Map elements: size=" << fVolMap.size();
639 for (const auto& [label, volumes] : fVolMap) {
640 LOG(info) << label << ":";
641 for (const auto& volume : volumes) {
642 LOG(info) << " " << volume;
643 }
644 }
645}
const Int_t debug
double MuonMass()
Definition MuonPath.h:29
constexpr Double_t m
Measurement fUBT
TGeoManager * fGeometry
Shield material volumes.
double fPocaJumpThreshold
int64_t fStartMagneticPaths
int64_t fMuonsWithLargeJumps
std::map< std::string, MuonPath > fPathMap
void SetMuonShieldField(ShipBFieldMap *field, TGeoManager *geometry)
std::map< std::string, std::set< std::string > > fVolMap
bool Trace(const Measurement &measurement, double startZ, double endZ, bool backward=false)
int64_t fStartStraightPaths
Measurement fStart
std::unique_ptr< MagneticTrackPropagator > fPropagator
Geometry cache identity.
int64_t fUBTBackwardPaths
int64_t fUBTBackwardMisses
std::vector< Segment > fSegments
TVector3 GetVertex(const TVector3 &r1, const TVector3 &p1, const TVector3 &r2, const TVector3 &p2)
bool initialise(ShipMuDIS::MuonBranches &aEvt)
MuonWeights fMuonWeights
double fShieldMinZ
Shield transport.
void PrintDiagnostics() const
bool AddMagneticSegments(const Measurement &start, double charge, double endZ)
void SetPocaJumpThreshold(double threshold)
bool AddMagneticChord(const TVector3 &a, const TVector3 &b, double momentum, double &time, unsigned depth=0)
std::map< std::string, MuonPath > & FillMuonPath()
TGeoNode * fTopNode
Borrowed geometry.
std::set< const TGeoVolume * > fShieldVolumes
Runtime path segments.
double GetTrajectoryPocaZ(const Measurement &hit) const
int64_t fStartsBeforeZmin
double fMaxTransverseJump
void AddPath(const MuonPath &path)
int64_t fStartsBeyondZmax
Class that defines a (3d) magnetic field map (distances in cm, fields in tesla).
constexpr double kMuonShieldTailZ
Definition MuDISDefs.h:30
const std::array< TString, nMats > MatTypeStr
Definition MuDISDefs.h:45
constexpr double c_light
Definition ShipUnit.h:44
std::vector< strawtubesPoint > sstPt
Definition MuDISDefs.h:107
std::vector< TimeDetPoint > tdPt
Definition MuDISDefs.h:108
std::vector< vetoPoint > sbtPt
Definition MuDISDefs.h:105
std::vector< ShipMCTrack > mcTrks
Definition MuDISDefs.h:104
std::vector< UpstreamTaggerPoint > ubtPt
Definition MuDISDefs.h:106