|
16 | 16 | /// \brief Basic struct to hold information regarding a detector layer to be used in fast simulation |
17 | 17 | /// |
18 | 18 |
|
19 | | -#include <vector> |
20 | | -#include <string> |
21 | | - |
22 | 19 | #include "DetLayer.h" |
23 | 20 |
|
| 21 | +#include <CommonConstants/MathConstants.h> |
| 22 | +#include <Framework/Logger.h> |
| 23 | + |
| 24 | +#include <string> |
| 25 | +#include <vector> |
| 26 | + |
24 | 27 | namespace o2::fastsim |
25 | 28 | { |
26 | 29 |
|
@@ -51,6 +54,62 @@ DetLayer::DetLayer(const DetLayer& other) |
51 | 54 | { |
52 | 55 | } |
53 | 56 |
|
| 57 | +void DetLayer::addDeadPhiRegion(float phiStart, float phiEnd) |
| 58 | +{ |
| 59 | + static constexpr float kDefaultValue = 2.f; |
| 60 | + static constexpr float kPhiTolerance = 1e-4f; |
| 61 | + if (mDeadPhiRegions == nullptr) { |
| 62 | + mDeadPhiRegions = new TGraph(); |
| 63 | + mDeadPhiRegions->SetNameTitle(Form("deadPhiRegions_%s", name.Data()), Form("Dead phi regions for layer %s", name.Data())); |
| 64 | + mDeadPhiRegions->AddPoint(0, kDefaultValue); |
| 65 | + mDeadPhiRegions->AddPoint(o2::constants::math::TwoPI, kDefaultValue); |
| 66 | + } |
| 67 | + if (phiStart < 0 || phiStart >= o2::constants::math::TwoPI || phiEnd < 0 || phiEnd >= o2::constants::math::TwoPI) { |
| 68 | + LOG(fatal) << "Cannot add dead phi region with invalid range [" << phiStart << ", " << phiEnd << "] to layer " << name; |
| 69 | + return; |
| 70 | + } |
| 71 | + mDeadPhiRegions->AddPoint(phiStart, kDefaultValue); |
| 72 | + mDeadPhiRegions->AddPoint(phiEnd, kDefaultValue); |
| 73 | + mDeadPhiRegions->AddPoint(phiStart + kPhiTolerance, 0.f); |
| 74 | + mDeadPhiRegions->AddPoint(phiEnd - kPhiTolerance, 0.f); |
| 75 | + mDeadPhiRegions->Sort(); |
| 76 | +} |
| 77 | + |
| 78 | +void DetLayer::setDeadPhiRegions(TGraph* graph) |
| 79 | +{ |
| 80 | + LOG(debug) << "Setting dead phi regions for layer " << name << " with graph " << (graph ? graph->GetName() : "nullptr"); |
| 81 | + if (mDeadPhiRegions != nullptr) { |
| 82 | + LOG(warning) << "Overriding existing dead phi regions for layer " << name; |
| 83 | + delete mDeadPhiRegions; |
| 84 | + } |
| 85 | + mDeadPhiRegions = graph; |
| 86 | + if (mDeadPhiRegions->GetN() == 0) { |
| 87 | + LOG(warning) << "Dead phi regions graph for layer " << name << " is empty, clearing dead regions"; |
| 88 | + mDeadPhiRegions = nullptr; |
| 89 | + return; // cleared the dead regions |
| 90 | + } |
| 91 | + // Check sanity of the graph |
| 92 | + if (mDeadPhiRegions != nullptr) { |
| 93 | + for (int i = 0; i < mDeadPhiRegions->GetN(); i++) { |
| 94 | + const float x = mDeadPhiRegions->GetX()[i]; |
| 95 | + const float y = mDeadPhiRegions->GetY()[i]; |
| 96 | + // First point has to be at 0, last point has to be at 2PI |
| 97 | + if ((i == 0 && x != 0.f) || (i == mDeadPhiRegions->GetN() - 1 && x != o2::constants::math::TwoPI)) { |
| 98 | + LOG(fatal) << "Dead phi regions graph for layer " << name << " has invalid x value " << x << " at point " << i << ", first point should be 0 and last point should be 2PI"; |
| 99 | + } |
| 100 | + LOG(debug) << "Point " << i << ": (" << x << ", " << y << ")"; |
| 101 | + if (x < 0 || x > o2::constants::math::TwoPI) { |
| 102 | + LOG(fatal) << "Dead phi regions graph for layer " << name << " has invalid x value " << x << " at point " << i; |
| 103 | + } |
| 104 | + if (y != 0.f && y != 2.f) { |
| 105 | + LOG(fatal) << "Dead phi regions graph for layer " << name << " has invalid y value " << y << " at point " << i << ", should be 0 or 2"; |
| 106 | + } |
| 107 | + } |
| 108 | + } else { |
| 109 | + LOG(info) << "Cleared dead phi regions for layer " << name; |
| 110 | + } |
| 111 | +} |
| 112 | + |
54 | 113 | std::string DetLayer::toString() const |
55 | 114 | { |
56 | 115 | std::string out = ""; |
|
0 commit comments