CbmRoot
CbmTrdGeoHandler.cxx
Go to the documentation of this file.
1 
5 #include "CbmTrdGeoHandler.h"
6 
7 #include "CbmTrdAddress.h" // for CbmTrdAddress
8 
9 #include <FairLogger.h> // for LOG, Logger
10 
11 #include <TGenericClassInfo.h> // for TGenericClassInfo
12 #include <TGeoBBox.h> // for TGeoBBox
13 #include <TGeoManager.h> // for TGeoManager, gGeoManager
14 #include <TGeoNode.h> // for TGeoNode
15 #include <TGeoPhysicalNode.h> // for TGeoPhysicalNode
16 #include <TGeoVolume.h> // for TGeoVolume
17 #include <TObjArray.h> // for TObjArray
18 #include <TObject.h> // for TObject
19 #include <TVirtualMC.h> // for TVirtualMC, gMC
20 
21 #include <cstdlib> // for atoi
22 #include <iostream> // for string
23 
24 using std::atoi;
25 using std::string;
26 
28  : TObject()
29  , fIsSimulation(kFALSE)
30  , fGeoPathHash(0)
31  , fCurrentVolume(nullptr)
32  , fVolumeShape(nullptr)
33  , fGlobal()
34  , fGlobalMatrix(nullptr)
35  , fLayerId(0)
36  , fModuleId(0)
37  , fModuleType(0)
38  , fRotation(0)
39  , fStation(0)
40  , fLayer(0)
41  , fModuleCopy(0) {}
42 
44 
45 void CbmTrdGeoHandler::Init(Bool_t isSimulation) {
46  fIsSimulation = isSimulation;
47 }
48 
50 
51  // In the simulation we can not rely on the TGeoManager information
52  // In the simulation we get the correct information only from gMC
53  Int_t copyNr;
54  if (fIsSimulation) {
55  LOG(debug4) << gMC->CurrentVolPath();
56  // get the copy number of the mother volume (1 volume up in hierarchy)
57  gMC->CurrentVolOffID(1, copyNr);
58  } else {
59  LOG(debug4) << gGeoManager->GetPath();
60  // We take the mother node (module) of the current node we are in (gas).
61  TGeoNode* node = gGeoManager->GetMother();
62  // Get the module copy number to get the information about layerId and moduleId.
63  copyNr = node->GetNumber();
64  }
65  LOG(debug4) << "CopyNr: " << copyNr;
66 
67  Int_t layerId = 0;
68  Int_t moduleId = 0;
69 
70  if ((copyNr / 100000000) > 0) // has 9 digits => 2014 format
71  {
72  // In TGeoManager numbering starts with 1, so we have to subtract 1.
73  layerId = ((copyNr / 1000) % 100) - 1;
74  moduleId = (copyNr % 1000) - 1;
75  LOG(debug4) << "2014 ";
76  } else // 2013 and earlier
77  {
78  // In TGeoManager numbering starts with 1, so we have to subtract 1.
79  layerId = ((copyNr / 100) % 100) - 1;
80  moduleId = (copyNr % 100) - 1;
81  LOG(debug4) << "2013 ";
82  }
83 
84  LOG(debug4) << copyNr / 100000000 << " copy " << copyNr << " layerID "
85  << layerId << " moduleId " << moduleId;
86  // Form the module address.
87  return CbmTrdAddress::GetAddress(layerId, moduleId, 0, 0, 0);
88 }
89 
90 Int_t CbmTrdGeoHandler::GetModuleAddress(const TString& path) {
91  if (fGeoPathHash != path.Hash()) { NavigateTo(path); }
92  return GetModuleAddress();
93 }
94 
95 //Int_t CbmTrdGeoHandler::GetModuleOrientation()
96 //{
97 // // We take the mother node (module) of the current node we are in (gas).
98 // TGeoNode* modulenode = gGeoManager->GetMother();
99 // // Get the module copy number to get the information about layerId and moduleId.
100 // Int_t modulecopyNr = modulenode->GetNumber();
101 // // In TGeoManager numbering starts with 1, so we have to subtract 1.
102 // fRotation = ((modulecopyNr / 10000) % 10); // from module copy number
103 // // LOG(info) << "fRotation: " << modulecopyNr << " " << fRotation;
104 // return fRotation;
105 //}
106 
107 Int_t CbmTrdGeoHandler::GetModuleOrientation(const TString& path) {
108  if (fGeoPathHash != path.Hash()) { NavigateTo(path); }
109  return fRotation;
110 }
111 
112 Double_t CbmTrdGeoHandler::GetSizeX(const TString& path) {
113  if (fGeoPathHash != path.Hash()) { NavigateTo(path); }
114  return fVolumeShape->GetDX();
115 }
116 
117 Double_t CbmTrdGeoHandler::GetSizeY(const TString& path) {
118  if (fGeoPathHash != path.Hash()) { NavigateTo(path); }
119  return fVolumeShape->GetDY();
120 }
121 
122 Double_t CbmTrdGeoHandler::GetSizeZ(const TString& path) {
123  if (fGeoPathHash != path.Hash()) { NavigateTo(path); }
124  return fVolumeShape->GetDZ();
125 }
126 
127 Double_t CbmTrdGeoHandler::GetZ(const TString& path) {
128  if (fGeoPathHash != path.Hash()) { NavigateTo(path); }
129  return fGlobal[2];
130 }
131 
132 Double_t CbmTrdGeoHandler::GetY(const TString& path) {
133  if (fGeoPathHash != path.Hash()) { NavigateTo(path); }
134  return fGlobal[1];
135 }
136 
137 Double_t CbmTrdGeoHandler::GetX(const TString& path) {
138  if (fGeoPathHash != path.Hash()) { NavigateTo(path); }
139  return fGlobal[0];
140 }
141 
142 Int_t CbmTrdGeoHandler::GetModuleType(const TString& path) {
143  if (fGeoPathHash != path.Hash()) { NavigateTo(path); }
144  return fModuleType;
145 }
146 
147 Int_t CbmTrdGeoHandler::GetStation(const TString& path) {
148  if (fGeoPathHash != path.Hash()) { NavigateTo(path); }
149  return fStation;
150 }
151 
152 Int_t CbmTrdGeoHandler::GetLayer(const TString& path) {
153  if (fGeoPathHash != path.Hash()) {
154  // LOG(info) << "path : " << path.Data();
155  NavigateTo(path);
156  }
157  return fLayer;
158 }
159 
160 Int_t CbmTrdGeoHandler::GetModuleCopyNr(const TString& path) {
161  if (fGeoPathHash != path.Hash()) { NavigateTo(path); }
162  return fModuleCopy;
163 }
164 
165 void CbmTrdGeoHandler::NavigateTo(const TString& path) {
166  // LOG(info)<< "path : " << path.Data();
167  if (fIsSimulation) {
168  LOG(fatal) << "This method is not supported in simulation mode";
169  } else {
170  gGeoManager->cd(path.Data());
171  fGeoPathHash = path.Hash();
172  fCurrentVolume = gGeoManager->GetCurrentVolume();
173  fVolumeShape = (TGeoBBox*) fCurrentVolume->GetShape();
174  Double_t local[3] = {0., 0., 0.}; // Local center of volume
175  gGeoManager->LocalToMaster(local, fGlobal);
176  fGlobalMatrix = gGeoManager->GetCurrentMatrix();
177  // Get module type information which is decoded in copy number.
178  const char* moduleName = gGeoManager->GetMother()->GetName();
179  fModuleType = std::atoi(
180  string(1, *(moduleName + 6)).c_str()); // 6th element module type
181 
182  // We take the mother of the mother node (layer) of the current node we are in (gas).
183  TGeoNode* layernode = gGeoManager->GetMother(2); // get layer
184  Int_t layercopyNr = layernode->GetNumber();
185  // fIsRotated is the 4th digit from the back
186  fStation = ((layercopyNr / 10000) % 10); // from layer copy number
187  // LOG(info) << "DE fStation: " << fStation << " ";
188  fLayer = ((layercopyNr / 100) % 10); // from layer copy number
189 
190  // We take the mother node (module) of the current node we are in (gas).
191  TGeoNode* modulenode = gGeoManager->GetMother();
192  // Get the module copy number to get the information about layerId and moduleId.
193  Int_t modulecopyNr = modulenode->GetNumber();
194 
195  if ((modulecopyNr / 100000000) > 0) // has 9 digits => 2014 format
196  {
197  // In TGeoManager numbering starts with 1, so we have to subtract 1.
198  fModuleCopy =
199  ((modulecopyNr / 1000000) % 100); // from module copy number
200  fRotation = ((modulecopyNr / 100000) % 10); // from module copy number
201  } else // 2013 and earlier
202  {
203  // In TGeoManager numbering starts with 1, so we have to subtract 1.
204  fModuleCopy = ((modulecopyNr / 100000) % 100); // from module copy number
205  fRotation = ((modulecopyNr / 10000) % 10); // from module copy number
206  }
207 
208  // LOG(info) << "fRotation: " << modulecopyNr << " " << fRotation;
209  // fLayerId = ((modulecopyNr / 100) % 100) - 1;
210  // fModuleId = ((modulecopyNr / 1) % 100) - 1;
211  }
212 }
213 
214 std::map<Int_t, TGeoPhysicalNode*> CbmTrdGeoHandler::FillModuleMap() {
215  // The geometry structure is treelike with cave as
216  // the top node. For the TRD there are keeping volumes with names
217  // like trd_vXXy_1 which are only a container for the different layers.
218  // The trd layer is again only a container for all volumes of this layer.
219  // Loop over all nodes below the top node (cave). If one of
220  // the nodes contains a string trd it must be TRD detector.
221  // Now loop over the layers and then over all modules of the layer
222  // to extract the node information for each detector module
223  // all active regions (gas) of the complete TRD.
224 
225  std::map<Int_t, TGeoPhysicalNode*> moduleMap;
226 
227  TGeoNode* topNode = gGeoManager->GetTopNode();
228  TObjArray* nodes = topNode->GetNodes();
229  for (Int_t iNode = 0; iNode < nodes->GetEntriesFast(); iNode++) {
230  TGeoNode* node = static_cast<TGeoNode*>(nodes->At(iNode));
231  if (!TString(node->GetName()).Contains("trd", TString::kIgnoreCase))
232  continue; // trd_vXXy top node, e.g. trd_v13a, trd_v14b
233  TGeoNode* station = node;
234 
235  TObjArray* layers = station->GetNodes();
236  for (Int_t iLayer = 0; iLayer < layers->GetEntriesFast(); iLayer++) {
237  TGeoNode* layer = static_cast<TGeoNode*>(layers->At(iLayer));
238  if (!TString(layer->GetName()).Contains("layer", TString::kIgnoreCase))
239  continue; // only layers
240 
241  TObjArray* modules = layer->GetNodes();
242  for (Int_t iModule = 0; iModule < modules->GetEntriesFast(); iModule++) {
243  TGeoNode* module = static_cast<TGeoNode*>(modules->At(iModule));
244  TObjArray* parts = module->GetNodes();
245  for (Int_t iPart = 0; iPart < parts->GetEntriesFast(); iPart++) {
246  TGeoNode* part = static_cast<TGeoNode*>(parts->At(iPart));
247  if (!TString(part->GetName()).Contains("gas", TString::kIgnoreCase))
248  continue; // only active gas volume
249 
250  // Put together the full path to the interesting volume, which
251  // is needed to navigate with the geomanager to this volume.
252  // Extract the geometry information (size, global position)
253  // from this volume.
254  TString path = TString("/") + topNode->GetName() + "/"
255  + station->GetName() + "/" + layer->GetName() + "/"
256  + module->GetName() + "/" + part->GetName();
257 
258  LOG(debug) << "Adding detector with path " << path;
259  // Generate a physical node which has all needed information
260  TGeoPhysicalNode* pNode = new TGeoPhysicalNode(path.Data());
261  Int_t address = GetModuleAddress();
262  moduleMap[address] = pNode;
263  }
264  }
265  }
266  }
267  return moduleMap;
268 }
269 
270 
CbmTrdGeoHandler::fGeoPathHash
UInt_t fGeoPathHash
Definition: CbmTrdGeoHandler.h:92
CbmTrdGeoHandler::GetModuleAddress
Int_t GetModuleAddress()
Return module address calculated based on the current node in the TGeoManager.
Definition: CbmTrdGeoHandler.cxx:49
CbmTrdGeoHandler::GetSizeX
Double_t GetSizeX(const TString &path)
Definition: CbmTrdGeoHandler.cxx:112
CbmTrdAddress::GetAddress
static UInt_t GetAddress(Int_t layerId, Int_t moduleId, Int_t sectorId, Int_t rowId, Int_t columnId)
Return address from system ID, layer, module, sector, column and row IDs.
Definition: CbmTrdAddress.h:38
CbmTrdAddress.h
Helper class to convert unique channel ID back and forth.
CbmTrdGeoHandler::fModuleCopy
Int_t fModuleCopy
LayerID within station, 1..4.
Definition: CbmTrdGeoHandler.h:105
CbmTrdGeoHandler::CbmTrdGeoHandler
CbmTrdGeoHandler()
Constructor.
Definition: CbmTrdGeoHandler.cxx:27
CbmTrdGeoHandler::fModuleType
Int_t fModuleType
Definition: CbmTrdGeoHandler.h:99
CbmTrdGeoHandler::GetStation
Int_t GetStation(const TString &path)
Definition: CbmTrdGeoHandler.cxx:147
CbmTrdGeoHandler::GetModuleType
Int_t GetModuleType(const TString &path)
Definition: CbmTrdGeoHandler.cxx:142
CbmTrdGeoHandler::fLayer
Int_t fLayer
StationTypeID, 1..3.
Definition: CbmTrdGeoHandler.h:104
CbmTrdGeoHandler::fRotation
Int_t fRotation
Definition: CbmTrdGeoHandler.h:100
CbmTrdGeoHandler::fGlobal
Double_t fGlobal[3]
Definition: CbmTrdGeoHandler.h:95
CbmTrdGeoHandler::GetY
Double_t GetY(const TString &path)
Definition: CbmTrdGeoHandler.cxx:132
CbmTrdGeoHandler
Definition: CbmTrdGeoHandler.h:29
CbmTrdGeoHandler::GetModuleOrientation
Int_t GetModuleOrientation(const TString &path)
Navigate to node and return pad orientation.
Definition: CbmTrdGeoHandler.cxx:107
CbmTrdGeoHandler::GetModuleCopyNr
Int_t GetModuleCopyNr(const TString &path)
Definition: CbmTrdGeoHandler.cxx:160
CbmTrdGeoHandler::GetSizeZ
Double_t GetSizeZ(const TString &path)
Definition: CbmTrdGeoHandler.cxx:122
CbmTrdGeoHandler.h
Helper class to extract information from the GeoManager.
CbmTrdGeoHandler::Init
void Init(Bool_t isSimulation=kFALSE)
Definition: CbmTrdGeoHandler.cxx:45
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmTrdGeoHandler::FillModuleMap
std::map< Int_t, TGeoPhysicalNode * > FillModuleMap()
Fill map with information of the gas volumes for each detector.
Definition: CbmTrdGeoHandler.cxx:214
CbmTrdGeoHandler::fCurrentVolume
TGeoVolume * fCurrentVolume
Definition: CbmTrdGeoHandler.h:93
CbmTrdGeoHandler::GetLayer
Int_t GetLayer(const TString &path)
Definition: CbmTrdGeoHandler.cxx:152
CbmTrdGeoHandler::fStation
Int_t fStation
rotation angle 0,1,2,3
Definition: CbmTrdGeoHandler.h:103
CbmTrdGeoHandler::fGlobalMatrix
TGeoHMatrix * fGlobalMatrix
Global center of volume.
Definition: CbmTrdGeoHandler.h:96
CbmTrdGeoHandler::fIsSimulation
Bool_t fIsSimulation
Definition: CbmTrdGeoHandler.h:90
CbmTrdGeoHandler::GetSizeY
Double_t GetSizeY(const TString &path)
Definition: CbmTrdGeoHandler.cxx:117
CbmTrdGeoHandler::fVolumeShape
TGeoBBox * fVolumeShape
Definition: CbmTrdGeoHandler.h:94
CbmTrdGeoHandler::GetX
Double_t GetX(const TString &path)
Definition: CbmTrdGeoHandler.cxx:137
CbmTrdGeoHandler::NavigateTo
void NavigateTo(const TString &path)
Definition: CbmTrdGeoHandler.cxx:165
CbmTrdGeoHandler::~CbmTrdGeoHandler
~CbmTrdGeoHandler()
Destructor.
Definition: CbmTrdGeoHandler.cxx:43
CbmTrdGeoHandler::GetZ
Double_t GetZ(const TString &path)
Definition: CbmTrdGeoHandler.cxx:127