CbmRoot
Loading...
Searching...
No Matches
CbmTrdParSetGeo.cxx
Go to the documentation of this file.
1/* Copyright (C) 2018-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Alexandru Bercuci, Florian Uhlig [committer] */
4
5#include "CbmTrdParSetGeo.h"
6
7#include "CbmTrdGeoHandler.h" // for CbmTrdGeoHandler
8#include "CbmTrdParModGeo.h" // for CbmTrdParModGeo
9
10#include <Logger.h> // for LOG, Logger
11
12#include <TGenericClassInfo.h> // for TGenericClassInfo
13#include <TGeoManager.h> // for TGeoManager, gGeoManager
14#include <TGeoNode.h> // for TGeoNode
15#include <TObjArray.h> // for TObjArray
16#include <TString.h> // for operator+, TString, Form, TString::kI...
17
18#include <map> // for map, map<>::const_iterator, operator!=
19#include <utility> // for pair
20
21#include <stdio.h> // for printf
22
23//________________________________________________________________________________________
24CbmTrdParSetGeo::CbmTrdParSetGeo(const char* name, const char* title, const char* context)
25 : CbmTrdParSet(name, title, context)
26{
27 LOG(debug) << "Constructor of CbmTrdParSetGeo";
28 Init();
29 LOG(debug) << "Constructor of CbmTrdParSetGeo --- finished";
30}
31
32//________________________________________________________________________________________
34
35//________________________________________________________________________________________
37{
39 TGeoNode* topNode = gGeoManager->GetTopNode();
40 TObjArray* nodes = topNode->GetNodes();
41 if (!nodes) {
42 LOG(fatal) << "CbmTrdParSetGeo::Init: nodes is null!";
43 return false;
44 }
45
46 CbmTrdParModGeo* pGeo(nullptr);
47 for (Int_t iNode = 0; iNode < nodes->GetEntriesFast(); iNode++) {
48 TGeoNode* node = static_cast<TGeoNode*>(nodes->At(iNode));
49 if (!TString(node->GetName()).Contains("trd", TString::kIgnoreCase))
50 continue; // trd_vXXy top node, e.g. trd_v13a, trd_v14b
51 TGeoNode* station = node;
52
53 TObjArray* layers = station->GetNodes();
54 for (Int_t iLayer = 0; iLayer < layers->GetEntriesFast(); iLayer++) {
55 TGeoNode* layer = static_cast<TGeoNode*>(layers->At(iLayer));
56 if (!TString(layer->GetName()).Contains("layer", TString::kIgnoreCase)) continue; // only layers
57
58 TObjArray* modules = layer->GetNodes();
59 for (Int_t iModule = 0; iModule < modules->GetEntriesFast(); iModule++) {
60 TGeoNode* module = static_cast<TGeoNode*>(modules->At(iModule));
61 TString path = TString("/") + topNode->GetName() + "/" + station->GetName() + "/" + layer->GetName() + "/"
62 + module->GetName();
63 TObjArray* parts = module->GetNodes();
64 for (Int_t iPart = 0; iPart < parts->GetEntriesFast(); iPart++) {
65 TGeoNode* part = static_cast<TGeoNode*>(parts->At(iPart));
66 // Put together the full path to the interesting volume, which
67 // is needed to navigate with the geomanager to this volume.
68 // Extract the geometry information (size, global position)
69 // from this volume.
70 if (TString(part->GetName()).Contains("gas", TString::kIgnoreCase)) {
71 // legacy naming convention for the active volume
72 path += Form("/%s", part->GetName());
73 }
74 else if (TString(part->GetName()).Contains("Volume", TString::kIgnoreCase)) {
75 path += Form("/%s/gas_0", part->GetName());
76 }
77 else
78 continue; // only active gas volume
79 LOG(debug) << "Adding detector with path " << path.Data();
80 // Generate a physical node which has all needed information
81 gGeoManager->cd(path.Data());
82 Int_t address = geo.GetModuleAddress();
83 pGeo = new CbmTrdParModGeo(Form("TRD_%d", address), path.Data());
84 pGeo->SetModuleId(address);
85 addParam(pGeo);
86 }
87 }
88 }
89 }
90 return true;
91}
92
93//________________________________________________________________________________________
95{
96 if (!GetNrOfModules()) {
97 LOG(error) << "CbmTrdParSetGeo::LoadAlignVolumes: No modules initialized. Nothing to do.";
98 return false;
99 }
100
101 for (auto mod : fModuleMap)
102 if (!((CbmTrdParModGeo*) mod.second)->SetNode()) return false;
103
104 return true;
105}
106
107//________________________________________________________________________________________
108void CbmTrdParSetGeo::Print(Option_t*) const
109{
110 std::map<Int_t, CbmTrdParMod*>::const_iterator imod = fModuleMap.begin();
111 CbmTrdParModGeo* mod(nullptr);
112 while (imod != fModuleMap.end()) {
113 mod = (CbmTrdParModGeo*) imod->second;
114 printf("Module %4d [%p]:\n", imod->first, (void*) mod);
115 printf(" %s[%s]\n", mod->GetName(), mod->GetPath());
116 Double_t xyz[3];
117 mod->GetXYZ(xyz);
118 printf(" X[%.2f] Y[%.2f] Z[%.2f] DX[%.2f] DY[%.2f] DZ[%.2f]\n", xyz[0], xyz[1], xyz[2], mod->GetDX(), mod->GetDY(),
119 mod->GetDZ());
120 imod++;
121 }
122}
123
124// //________________________________________________________________________________________
125// void CbmTrdParSetGeo::putParams(FairParamList* l)
126// {
127// if (!l) return;
128// TObjArray *snodes(nullptr), *pnodes(nullptr);
129// //for()
130// l->addObject("FairGeoNodes Sensitive List", snodes);
131// l->addObject("FairGeoNodes Passive List", pnodes);
132// }
133//
134// //________________________________________________________________________________________
135// Bool_t CbmTrdParSetGeo::getParams(FairParamList* l)
136// {
137// if (!l) return kFALSE;
138// TObjArray *snodes(nullptr), *pnodes(nullptr);
139// if (!l->fillObject("FairGeoNodes Sensitive List", snodes)) return kFALSE;
140// if (!l->fillObject("FairGeoNodes Passive List", pnodes)) return kFALSE;
141//
142// //CbmTrdParModGeo *geo(nullptr);
143// for (Int_t i=0; i < snodes->GetEntriesFast(); i++){
144// // fModPar[moduleId[i]] = new CbmTrdParModGeo(GetName());
145// // fModPar
146//
147// ((FairGeoNode*)(*snodes)[i])->print();
148// }
149// return kTRUE;
150// }
151
ClassImp(CbmConverterManager)
Helper class to extract information from the GeoManager.
Int_t GetModuleAddress()
Return module address calculated based on the current node in the TGeoManager.
Definition of geometry for one TRD module.
virtual void SetModuleId(int m)
bool LoadAlignVolumes()
Trigger loading alignment information for all nodes registered.
virtual void Print(Option_t *opt="") const
CbmTrdParSetGeo(const char *name="CbmTrdParSetGeo", const char *title="Trd Geometry Parameters", const char *context="TestDefaultContext")
virtual ~CbmTrdParSetGeo(void)
std::map< Int_t, CbmTrdParMod * > fModuleMap
virtual Int_t GetNrOfModules() const
virtual void addParam(CbmTrdParMod *mod)