CbmRoot
CbmStsElement.cxx
Go to the documentation of this file.
1 
5 #include "CbmStsElement.h"
6 
7 #include <FairLogger.h> // for Logger, LOG
8 
9 #include "CbmStsModule.h" // for CbmStsModule
10 #include "CbmStsSetup.h" // for CbmStsSetup
11 
12 #include <TGeoManager.h> // for gGeoManager
13 #include <TGeoNode.h> // for TGeoNode
14 #include <TGeoPhysicalNode.h> // for TGeoPhysicalNode
15 #include <TNamed.h> // for TNamed
16 
17 #include <cassert> // for assert
18 #include <iomanip> // for setw, __iom_t6
19 #include <ios> // for left, right
20 
21 using std::left;
22 using std::right;
23 using std::setw;
24 
25 // ----- Default constructor -------------------------------------------
27  : TNamed()
28  , fAddress(0)
29  , fLevel(kStsNofLevels)
30  , fNode(nullptr)
31  , fDaughters()
32  , fMother(nullptr) {}
33 // -------------------------------------------------------------------------
34 
35 
36 // ----- Standard constructor ------------------------------------------
38  Int_t level,
39  TGeoPhysicalNode* node,
40  CbmStsElement* mother)
41  : TNamed()
42  , fAddress(address)
43  , fLevel(kStsSystem)
44  , fNode(node)
45  , fDaughters()
46  , fMother(mother) {
47  SetLevel(level);
48  SetName(ConstructName(address, fLevel).Data());
49 }
50 // -------------------------------------------------------------------------
51 
52 
53 // ----- Construct the name of an element --------------------------------
55 
56  // Set the name for the STS system
57  if (GetLevel() == kStsSystem) {
58  SetName("STS");
59  return;
60  }
61 
62  // Special case half-ladder ("U"p or "D"own)
63  if (GetLevel() == kStsHalfLadder) {
64  TString label;
66  case 0: label = "U"; break;
67  case 1: label = "D"; break;
68  default: break;
69  }
70  SetName(fMother->GetName() + label);
71  return;
72  }
73 
74  // For other levels: Expand the name of the mother
75  TString label;
76  switch (GetLevel()) {
77  case kStsUnit: label = "_U"; break;
78  case kStsLadder: label = "_L"; break;
79  case kStsModule: label = "_M"; break;
80  case kStsSensor: label = "_S"; break;
81  default: break;
82  }
83  label += Form("%02i", CbmStsAddress::GetElementId(fAddress, GetLevel()) + 1);
84  SetName(fMother->GetName() + label);
85 }
86 // -------------------------------------------------------------------------
87 
88 
89 // ----- Construct name from address -----------------------------------
90 TString CbmStsElement::ConstructName(Int_t address, EStsElementLevel level) {
91 
92  TString result = "STS";
93  if (level >= kStsUnit) {
94  Int_t unit = CbmStsAddress::GetElementId(address, kStsUnit);
95  result += Form("_U%02i", unit + 1);
96  if (level >= kStsLadder) {
97  Int_t ladder = CbmStsAddress::GetElementId(address, kStsLadder);
98  result += Form("_L%02i", ladder + 1);
99  if (level >= kStsHalfLadder) {
100  Int_t hladder = CbmStsAddress::GetElementId(address, kStsHalfLadder);
101  result += (hladder == 0 ? "U" : "D");
102  if (level >= kStsModule) {
103  Int_t module = CbmStsAddress::GetElementId(address, kStsModule);
104  result += Form("_M%02i", module + 1);
105  if (level >= kStsSensor) {
106  Int_t sensor = CbmStsAddress::GetElementId(address, kStsSensor);
107  result += Form("_S%02i", sensor + 1);
108  } //? sensor
109  } //? module
110  } //? halfladder
111  } //? ladder
112  } //? unit
113 
114  return result;
115 }
116 // -------------------------------------------------------------------------
117 
118 
119 // ----- Get a daughter element ----------------------------------------
121  if (index < 0 || index >= GetNofDaughters()) return nullptr;
122  return fDaughters[index];
123 }
124 // -------------------------------------------------------------------------
125 
126 
127 // ----- Get number of elements at lower hierarchy levels --------------
128 Int_t CbmStsElement::GetNofElements(Int_t level) const {
129 
130  Int_t nElements = 0;
131  if (level <= fLevel)
132  nElements = 0;
133  else if (level == fLevel + 1)
134  nElements = GetNofDaughters();
135  else
136  for (Int_t iDaughter = 0; iDaughter < GetNofDaughters(); iDaughter++)
137  nElements += GetDaughter(iDaughter)->GetNofElements(level);
138 
139  return nElements;
140 }
141 // -------------------------------------------------------------------------
142 
143 
144 // ----- Recursively read daughters from geometry ----------------------
146 
147  // --- Catch absence of TGeoManager
148  assert(gGeoManager);
149 
150  // --- No daughter elements below sensor level
151  if (fLevel > kStsSensor) return;
152 
153  // --- Catch physical node not being set
154  if (!fNode) {
155  LOG(error) << fName << ": physical node is not set!";
156  return;
157  }
158 
159  TGeoNode* mNode = fNode->GetNode(); // This node
160  TString mPath = fNode->GetName(); // Full path to this node
161 
162  for (Int_t iNode = 0; iNode < mNode->GetNdaughters(); iNode++) {
163 
164  // Check name of daughter node for level name
165  TString dName = mNode->GetDaughter(iNode)->GetName();
166  if (dName.Contains(CbmStsSetup::Instance()->GetLevelName(fLevel + 1),
167  TString::kIgnoreCase)) {
168 
169  // Create physical node
170  TString dPath = mPath + "/" + dName;
171  TGeoPhysicalNode* pNode = new TGeoPhysicalNode(dPath.Data());
172 
173  // Create element and add it as daughter
174  UInt_t address =
176  CbmStsElement* dElement = nullptr;
177  switch (fLevel) {
178  case kStsHalfLadder:
179  dElement = new CbmStsModule(address, pNode, this);
180  break;
181  default:
182  dElement = new CbmStsElement(address, fLevel + 1, pNode, this);
183  break;
184  }
185  fDaughters.push_back(dElement);
186 
187  // Call init method recursively for the daughter elements
188  dElement->InitDaughters();
189 
190  } // name of daughter node
191 
192  } // daughter node loop
193 }
194 // -------------------------------------------------------------------------
195 
196 
197 // ----- Print ---------------------------------------------------------
198 void CbmStsElement::Print(Option_t* opt) const {
199  LOG(info) << setw(10) << right << fAddress << " " << setw(12) << left
200  << fName << " type " << setw(22) << fTitle << " path "
201  << fNode->GetName() << " " << fNode->GetTitle();
202  if (opt[0] == 'R') {
203  for (Int_t iDaughter = 0; iDaughter < GetNofDaughters(); iDaughter++)
204  GetDaughter(iDaughter)->Print("R");
205  }
206 }
207 // -------------------------------------------------------------------------
208 
209 
210 // ----- Set element level ---------------------------------------------
211 void CbmStsElement::SetLevel(Int_t level) {
212  switch (level) {
213  case kStsSystem: fLevel = kStsSystem; break;
214  case kStsUnit: fLevel = kStsUnit; break;
215  case kStsLadder: fLevel = kStsLadder; break;
216  case kStsHalfLadder: fLevel = kStsHalfLadder; break;
217  case kStsModule: fLevel = kStsModule; break;
218  case kStsSensor: fLevel = kStsSensor; break;
219  default: LOG(fatal) << fName << ": Illegal element level " << level; break;
220  }
221 }
222 // -------------------------------------------------------------------------
223 
224 
CbmStsElement::fDaughters
std::vector< CbmStsElement * > fDaughters
Array of daughters.
Definition: CbmStsElement.h:127
kStsHalfLadder
@ kStsHalfLadder
Definition: CbmStsAddress.h:20
CbmStsSetup.h
CbmStsElement::fMother
CbmStsElement * fMother
Mother element.
Definition: CbmStsElement.h:128
CbmStsSetup::Instance
static CbmStsSetup * Instance()
Definition: CbmStsSetup.cxx:293
kStsSystem
@ kStsSystem
Definition: CbmStsAddress.h:17
CbmStsSetup::GetLevelName
const char * GetLevelName(Int_t level) const
Definition: CbmStsSetup.cxx:167
CbmStsElement::Print
virtual void Print(Option_t *opt="") const
Definition: CbmStsElement.cxx:198
CbmStsModule
Class representing an instance of a readout unit in the CBM-STS.
Definition: CbmStsModule.h:31
CbmStsElement::GetNofElements
Int_t GetNofElements(Int_t level) const
Definition: CbmStsElement.cxx:128
CbmStsElement::ConstructName
void ConstructName()
Definition: CbmStsElement.cxx:54
kStsModule
@ kStsModule
Definition: CbmStsAddress.h:21
CbmStsAddress::SetElementId
Int_t SetElementId(Int_t address, Int_t level, UInt_t newId)
Set the index of an element, leaving the other element levels untouched.
Definition: CbmStsAddress.cxx:205
CbmStsAddress::GetElementId
UInt_t GetElementId(Int_t address, Int_t level)
Get the index of an element.
Definition: CbmStsAddress.cxx:180
CbmStsElement.h
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
kStsNofLevels
@ kStsNofLevels
Definition: CbmStsAddress.h:24
kStsUnit
@ kStsUnit
Definition: CbmStsAddress.h:18
EStsElementLevel
EStsElementLevel
Definition: CbmStsAddress.h:16
CbmStsElement::GetDaughter
CbmStsElement * GetDaughter(Int_t index) const
Definition: CbmStsElement.cxx:120
CbmStsElement::GetNofDaughters
Int_t GetNofDaughters() const
Definition: CbmStsElement.h:95
kStsSensor
@ kStsSensor
Definition: CbmStsAddress.h:22
CbmStsElement::GetLevel
EStsElementLevel GetLevel() const
Definition: CbmStsElement.h:85
kStsLadder
@ kStsLadder
Definition: CbmStsAddress.h:19
CbmStsElement::CbmStsElement
CbmStsElement()
Definition: CbmStsElement.cxx:26
CbmStsElement::InitDaughters
virtual void InitDaughters()
Definition: CbmStsElement.cxx:145
CbmStsModule.h
CbmStsElement
Class representing an element of the STS setup.
Definition: CbmStsElement.h:32
CbmStsElement::fAddress
Int_t fAddress
Unique element address.
Definition: CbmStsElement.h:124
CbmStsElement::fLevel
EStsElementLevel fLevel
Level in hierarchy.
Definition: CbmStsElement.h:125
CbmStsElement::fNode
TGeoPhysicalNode * fNode
Pointer to geometry.
Definition: CbmStsElement.h:126
CbmStsElement::SetLevel
void SetLevel(Int_t level)
Definition: CbmStsElement.cxx:211