-
Notifications
You must be signed in to change notification settings - Fork 652
Expand file tree
/
Copy pathDetLayer.cxx
More file actions
156 lines (145 loc) · 5.16 KB
/
DetLayer.cxx
File metadata and controls
156 lines (145 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
///
/// \file DetLayer.cxx
/// \author David Dobrigkeit Chinellato
/// \since 11/03/2021
/// \brief Basic struct to hold information regarding a detector layer to be used in fast simulation
///
#include "DetLayer.h"
#include <CommonConstants/MathConstants.h>
#include <Framework/Logger.h>
#include <string>
#include <vector>
namespace o2::fastsim
{
// Parametric constructor
DetLayer::DetLayer(const TString& name,
float r,
float z,
float x0,
float xrho,
float resRPhi,
float resZ,
float eff,
int type)
: mName(name),
mR(r),
mZ(z),
mX0(x0),
mXrho(xrho),
mResRPhi(resRPhi),
mResZ(resZ),
mEff(eff),
mType(type)
{
}
DetLayer::DetLayer(const DetLayer& other)
: mName(other.mName), mR(other.mR), mZ(other.mZ), mX0(other.mX0), mXrho(other.mXrho), mResRPhi(other.mResRPhi), mResZ(other.mResZ), mEff(other.mEff), mType(other.mType)
{
}
void DetLayer::addDeadPhiRegion(float phiStart, float phiEnd)
{
static constexpr float kDefaultValue = 2.f;
static constexpr float kPhiTolerance = 1e-4f;
if (mDeadPhiRegions == nullptr) {
mDeadPhiRegions = new TGraph();
mDeadPhiRegions->SetNameTitle(Form("deadPhiRegions_%s", mName.Data()), Form("Dead phi regions for layer %s", mName.Data()));
mDeadPhiRegions->AddPoint(0, kDefaultValue);
mDeadPhiRegions->AddPoint(o2::constants::math::TwoPI, kDefaultValue);
}
if (phiStart < 0 || phiStart >= o2::constants::math::TwoPI || phiEnd < 0 || phiEnd >= o2::constants::math::TwoPI) {
LOG(fatal) << "Cannot add dead phi region with invalid range [" << phiStart << ", " << phiEnd << "] to layer " << mName;
return;
}
mDeadPhiRegions->AddPoint(phiStart, kDefaultValue);
mDeadPhiRegions->AddPoint(phiEnd, kDefaultValue);
mDeadPhiRegions->AddPoint(phiStart + kPhiTolerance, 0.f);
mDeadPhiRegions->AddPoint(phiEnd - kPhiTolerance, 0.f);
mDeadPhiRegions->Sort();
}
void DetLayer::setDeadPhiRegions(TGraph* graph)
{
LOG(debug) << "Setting dead phi regions for layer " << mName << " with graph " << (graph ? graph->GetName() : "nullptr");
if (mDeadPhiRegions != nullptr) {
LOG(warning) << "Overriding existing dead phi regions for layer " << mName;
delete mDeadPhiRegions;
}
mDeadPhiRegions = graph;
if (mDeadPhiRegions->GetN() == 0) {
LOG(warning) << "Dead phi regions graph for layer " << mName << " is empty, clearing dead regions";
mDeadPhiRegions = nullptr;
return; // cleared the dead regions
}
// Check sanity of the graph
if (mDeadPhiRegions != nullptr) {
for (int i = 0; i < mDeadPhiRegions->GetN(); i++) {
const float x = mDeadPhiRegions->GetX()[i];
const float y = mDeadPhiRegions->GetY()[i];
// First point has to be at 0, last point has to be at 2PI
if ((i == 0 && x != 0.f) || (i == mDeadPhiRegions->GetN() - 1 && x != o2::constants::math::TwoPI)) {
LOG(fatal) << "Dead phi regions graph for layer " << mName << " has invalid x value " << x << " at point " << i << ", first point should be 0 and last point should be 2PI";
}
LOG(debug) << "Point " << i << ": (" << x << ", " << y << ")";
if (x < 0 || x > o2::constants::math::TwoPI) {
LOG(fatal) << "Dead phi regions graph for layer " << mName << " has invalid x value " << x << " at point " << i;
}
if (y != 0.f && y != 2.f) {
LOG(fatal) << "Dead phi regions graph for layer " << mName << " has invalid y value " << y << " at point " << i << ", should be 0 or 2";
}
}
} else {
LOG(info) << "Cleared dead phi regions for layer " << mName;
}
}
std::string DetLayer::toString() const
{
std::string out = "";
out.append("DetLayer: ");
out.append(mName.Data());
out.append(" | r: ");
out.append(std::to_string(mR));
out.append(" cm | z: ");
out.append(std::to_string(mZ));
out.append(" cm | x0: ");
out.append(std::to_string(mX0));
out.append(" cm | xrho: ");
out.append(std::to_string(mXrho));
out.append(" g/cm^3 | resRPhi: ");
out.append(std::to_string(mResRPhi));
out.append(" cm | resZ: ");
out.append(std::to_string(mResZ));
out.append(" cm | eff: ");
out.append(std::to_string(mEff));
out.append(" | type: ");
switch (mType) {
case kLayerInert:
out.append("Inert");
break;
case kLayerSilicon:
out.append("Silicon");
break;
case kLayerGas:
out.append("Gas/TPC");
break;
case kLayerTOF:
out.append("TOF");
break;
case kLayerVertex:
out.append("Vertex");
break;
default:
out.append("Unknown");
break;
}
return out;
}
} // namespace o2::fastsim