Skip to content

Commit 61e9d67

Browse files
authored
[ALICE3] Add method to specify dead phi region in layer (#13119)
1 parent 71cc8fc commit 61e9d67

File tree

5 files changed

+155
-15
lines changed

5 files changed

+155
-15
lines changed

ALICE3/Core/DetLayer.cxx

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
/// \brief Basic struct to hold information regarding a detector layer to be used in fast simulation
1717
///
1818

19-
#include <vector>
20-
#include <string>
21-
2219
#include "DetLayer.h"
2320

21+
#include <CommonConstants/MathConstants.h>
22+
#include <Framework/Logger.h>
23+
24+
#include <string>
25+
#include <vector>
26+
2427
namespace o2::fastsim
2528
{
2629

@@ -51,6 +54,62 @@ DetLayer::DetLayer(const DetLayer& other)
5154
{
5255
}
5356

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+
54113
std::string DetLayer::toString() const
55114
{
56115
std::string out = "";

ALICE3/Core/DetLayer.h

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
#ifndef ALICE3_CORE_DETLAYER_H_
2020
#define ALICE3_CORE_DETLAYER_H_
2121

22-
#include <string>
22+
#include <TGraph.h>
23+
#include <TString.h>
2324

24-
#include "TString.h"
25+
#include <string>
2526

2627
namespace o2::fastsim
2728
{
@@ -47,6 +48,17 @@ struct DetLayer {
4748
void setEfficiency(float eff_) { eff = eff_; }
4849
void setType(int type_) { type = type_; }
4950

51+
// Dead areas
52+
53+
/// @brief Add a dead region in phi for this layer
54+
/// @param phiStart starting angle in radians of the dead region
55+
/// @param phiEnd ending angle in radians of the dead region
56+
void addDeadPhiRegion(float phiStart, float phiEnd);
57+
58+
/// @brief Set the dead regions in phi for this layer with a TGraph containing all regions. The graph should have y=2 for dead regions and y=0 for alive regions.
59+
/// @param graph graph of the dead regions. Can be nullptr to clear the dead regions.
60+
void setDeadPhiRegions(TGraph* graph);
61+
5062
// Getters
5163
float getRadius() const { return r; }
5264
float getZ() const { return z; }
@@ -57,6 +69,7 @@ struct DetLayer {
5769
float getEfficiency() const { return eff; }
5870
int getType() const { return type; }
5971
const TString& getName() const { return name; }
72+
const TGraph* getDeadPhiRegions() const { return mDeadPhiRegions; }
6073

6174
// Check layer type
6275
bool isInert() const { return type == layerInert; }
@@ -70,6 +83,15 @@ struct DetLayer {
7083
os << layer.toString();
7184
return os;
7285
}
86+
/// @brief Check if a given phi angle is in a dead region
87+
/// @param phi The phi angle to check
88+
/// @return True if the phi angle is in a dead region, false otherwise
89+
bool isInDeadPhiRegion(float phi) const
90+
{
91+
if (mDeadPhiRegions == nullptr)
92+
return false;
93+
return mDeadPhiRegions->Eval(phi) > 1.f;
94+
};
7395

7496
private:
7597
// TString for holding name
@@ -90,6 +112,9 @@ struct DetLayer {
90112
// efficiency
91113
float eff; // detection efficiency
92114

115+
// dead regions in phi (in radians)
116+
TGraph* mDeadPhiRegions = nullptr;
117+
93118
// layer type
94119
int type; // 0: undefined/inert, 1: silicon, 2: gas/tpc
95120
static constexpr int layerInert = 0; // inert/undefined layer

ALICE3/Core/FastTracker.cxx

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <TObject.h>
2323

2424
#include <fstream>
25-
#include <map>
2625
#include <string>
2726
#include <vector>
2827

@@ -33,7 +32,7 @@ namespace fastsim
3332

3433
// +-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+
3534

36-
void FastTracker::AddLayer(TString name, float r, float z, float x0, float xrho, float resRPhi, float resZ, float eff, int type)
35+
DetLayer* FastTracker::AddLayer(TString name, float r, float z, float x0, float xrho, float resRPhi, float resZ, float eff, int type)
3736
{
3837
LOG(debug) << "Adding layer " << name << " r=" << r << " z=" << z << " x0=" << x0 << " xrho=" << xrho << " resRPhi=" << resRPhi << " resZ=" << resZ << " eff=" << eff << " type=" << type;
3938
DetLayer newLayer(name, r, z, x0, xrho, resRPhi, resZ, eff, type);
@@ -53,6 +52,18 @@ void FastTracker::AddLayer(TString name, float r, float z, float x0, float xrho,
5352
}
5453
// Add the new layer to the layers vector
5554
layers.push_back(newLayer);
55+
// Return the last added layer
56+
return &layers.back();
57+
}
58+
59+
void FastTracker::addDeadPhiRegionInLayer(const std::string& layerName, float phiStart, float phiEnd)
60+
{
61+
const int layerIdx = GetLayerIndex(layerName);
62+
if (layerIdx < 0) {
63+
LOG(fatal) << "Cannot add dead phi region to non-existing layer " << layerName;
64+
return;
65+
}
66+
layers[layerIdx].addDeadPhiRegion(phiStart, phiEnd);
5667
}
5768

5869
DetLayer FastTracker::GetLayer(int layer, bool ignoreBarrelLayers) const
@@ -185,7 +196,7 @@ void FastTracker::AddSiliconALICE3(float scaleX0VD, std::vector<float> pixelReso
185196
AddLayer("B03", 7., 250, x0OT, xrhoOT, resRPhiOT, resZOT, eff, 1);
186197
AddLayer("B04", 9., 250, x0OT, xrhoOT, resRPhiOT, resZOT, eff, 1);
187198
AddLayer("B05", 12., 250, x0OT, xrhoOT, resRPhiOT, resZOT, eff, 1);
188-
AddLayer("iTOF", 19, 250, x0iTOF, xrhoiTOF, resRPhiOT, resZOT, 0.0f, 0);
199+
AddLayer("iTOF", 19, 250, x0iTOF, xrhoiTOF, resRPhiOT, resZOT, eff, 0);
189200
AddLayer("B06", 20., 250, x0OT, xrhoOT, resRPhiOT, resZOT, eff, 1);
190201
AddLayer("B07", 30., 250, x0OT, xrhoOT, resRPhiOT, resZOT, eff, 1);
191202
AddLayer("B08", 45., 250, x0OT, xrhoOT, resRPhiOT, resZOT, eff, 1);
@@ -285,12 +296,15 @@ void FastTracker::AddGenericDetector(std::string filename, o2::ccdb::BasicCCDBMa
285296
for (const auto& layer : layers) {
286297
LOG(info) << " Reading layer " << layer;
287298

288-
auto getKey = [&layer, &env](const std::string& name) {
299+
auto getKey = [&layer, &env](const std::string& name, const bool required = true) {
289300
std::string key = layer + "." + name;
290301
if (!env.Defined(key.c_str())) {
291-
LOG(warning) << "Key " << key << " not defined in configuration file, getting the default value";
302+
if (required) {
303+
LOG(fatal) << "Key " << key << " not defined in configuration file";
304+
}
305+
LOG(debug) << "Key " << key << " not defined in configuration file, getting the default value";
292306
}
293-
LOG(info) << " Getting key " << key;
307+
LOG(debug) << " Getting key " << key << " from configuration file";
294308
return key;
295309
};
296310
const float r = env.GetValue(getKey("r").c_str(), -1.0f);
@@ -302,9 +316,36 @@ void FastTracker::AddGenericDetector(std::string filename, o2::ccdb::BasicCCDBMa
302316
const float resZ = env.GetValue(getKey("resZ").c_str(), 0.0f);
303317
const float eff = env.GetValue(getKey("eff").c_str(), 0.0f);
304318
const int type = env.GetValue(getKey("type").c_str(), 0);
319+
const char* deadPhiRegions = env.GetValue(getKey("deadPhiRegions", false).c_str(), "");
305320

306321
// void AddLayer(TString name, float r, float z, float x0, float xrho, float resRPhi = 0.0f, float resZ = 0.0f, float eff = 0.0f, int type = 0);
307-
AddLayer(layer.c_str(), r, z, x0, xrho, resRPhi, resZ, eff, type);
322+
LOG(info) << " Adding layer " << layer << " r=" << r << " z=" << z << " x0=" << x0 << " xrho=" << xrho << " resRPhi=" << resRPhi << " resZ=" << resZ << " eff=" << eff << " type=" << type << " deadPhiRegions=" << deadPhiRegions;
323+
324+
DetLayer* addedLayer = AddLayer(layer.c_str(), r, z, x0, xrho, resRPhi, resZ, eff, type);
325+
if (strlen(deadPhiRegions) > 0) { // Taking it as ccdb path or local file
326+
// Check if it begins with ccdb:
327+
if (std::string(deadPhiRegions).rfind("ccdb:", 0) == 0) {
328+
std::string ccdbPath = std::string(deadPhiRegions).substr(5); // remove "ccdb:" prefix
329+
if (ccdbManager == nullptr) {
330+
LOG(fatal) << "CCDB manager is null, cannot retrieve file " << ccdbPath;
331+
return;
332+
}
333+
TGraph* g = ccdbManager->getForTimeStamp<TGraph>(ccdbPath, -1);
334+
addedLayer->setDeadPhiRegions(g);
335+
} else {
336+
// Taking it as local file
337+
TFile infile(deadPhiRegions, "READ");
338+
if (!infile.IsOpen()) {
339+
LOG(fatal) << "Cannot open dead phi regions file " << deadPhiRegions;
340+
return;
341+
}
342+
TGraph* g = (TGraph*)infile.Get(infile.GetListOfKeys()->At(0)->GetName());
343+
infile.Close();
344+
addedLayer->setDeadPhiRegions(g);
345+
}
346+
} else {
347+
LOG(debug) << " No dead phi regions for layer " << layer;
348+
}
308349
}
309350
}
310351

@@ -493,6 +534,11 @@ int FastTracker::FastTrack(o2::track::TrackParCov inputTrack, o2::track::TrackPa
493534
continue; // inert layer, skip
494535
}
495536

537+
if (layers[il].isInDeadPhiRegion(inputTrack.getPhi())) {
538+
LOGF(debug, "Track is in dead region of layer %d", il);
539+
continue; // dead region, skip
540+
}
541+
496542
// layer is reached
497543
if (firstLayerReached < 0) {
498544
LOGF(debug, "First layer reached: %d", il);

ALICE3/Core/FastTracker.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ class FastTracker
4141
virtual ~FastTracker() {}
4242

4343
// Layer and layer configuration
44-
void AddLayer(TString name, float r, float z, float x0, float xrho, float resRPhi = 0.0f, float resZ = 0.0f, float eff = 0.0f, int type = 0);
44+
DetLayer* AddLayer(TString name, float r, float z, float x0, float xrho, float resRPhi = 0.0f, float resZ = 0.0f, float eff = 0.0f, int type = 0);
45+
46+
/// Add a dead region in phi for a specific layer
47+
/// \param layerName Name of the layer to modify
48+
/// \param phiStart Start angle of the dead region (in radians)
49+
/// \param phiEnd End angle of the dead region (in radians)
50+
void addDeadPhiRegionInLayer(const std::string& layerName, float phiStart, float phiEnd);
4551
DetLayer GetLayer(const int layer, bool ignoreBarrelLayers = true) const;
4652
std::vector<DetLayer> GetLayers() const { return layers; }
4753
int GetLayerIndex(const std::string& name) const;
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@
1515

1616
#include "ALICE3/Core/FastTracker.h"
1717

18-
#include "CCDB/BasicCCDBManager.h"
19-
#include "DataFormatsParameters/GRPLHCIFData.h"
18+
#include <CCDB/BasicCCDBManager.h>
19+
#include <DataFormatsParameters/GRPLHCIFData.h>
20+
21+
#include <fairlogger/Logger.h>
2022

2123
void testFastTracker(std::string geometryFile = "a3geo.ini")
2224
{
2325

26+
fair::Logger::SetConsoleSeverity(fair::Severity::debug);
27+
2428
// auto& ccdb = o2::ccdb::BasicCCDBManager::instance();
2529
// ccdb.setURL("http://alice-ccdb.cern.ch");
2630
o2::fastsim::FastTracker fastTracker;

0 commit comments

Comments
 (0)