25#include <TCollection.h>
26#include <TDirectory.h>
28#include <TGeoManager.h>
29#include <TGeoMatrix.h>
31#include <TGeoPhysicalNode.h>
32#include <TGeoShapeAssembly.h>
33#include <TGeoVolume.h>
34#include <TGeoVoxelFinder.h>
74 TString name = Form(
"STS_S%02i", stationId + 1);
75 TString title = Form(
"STS Station %i", stationId + 1);
96 Int_t nodeNumber = ladder->
GetPnode()->GetNode()->GetNumber();
97 Int_t stationId = nodeNumber / 100 - 1;
101 TString name = Form(
"STS_S%02i", stationId + 1);
102 TString title = Form(
"STS Station %i", stationId + 1);
125 Double_t zPrevious = -999999;
126 for (UInt_t iStation = 0; iStation <
fStations.size(); iStation++) {
128 LOG(error) << GetName() <<
": Number of stations is " <<
fStations.size() <<
", but station " << iStation
129 <<
"is not present!";
132 if (
fStations[iStation]->GetZ() <= zPrevious) {
133 LOG(error) << GetName() <<
": Disordered stations. Station " << iStation
134 <<
" is at z = " <<
fStations[iStation]->GetZ() <<
"cm , previous is at z = " << zPrevious <<
" cm.";
138 if (!isOk) LOG(fatal) << GetName() <<
": Error in creation of stations.";
150 if (!
fAddress) LOG(fatal) << fName <<
": not initialised!";
154 LOG(warn) << fName <<
": No STS address " << address;
160 LOG(warn) << fName <<
": Illegal level " << level;
165 for (
Int_t iLevel = 1; iLevel <= level; iLevel++) {
184 case kStsUnit:
return "unit";
break;
189 case kStsSide:
return "side";
break;
190 default:
return "";
break;
206 return ladder->
GetPnode()->GetNode()->GetNumber() / 100 - 1;
219 LOG(info) <<
"==========================================================";
220 LOG(info) <<
"Initialising STS Setup \n";
235 LOG(info) << fName <<
": Elements in setup: ";
239 LOG(info) <<
" " << setw(12) << name << setw(5) << right <<
GetNofElements(iLevel);
253 Int_t moduleAddress =
module->GetAddress();
254 assert(!
fModules.count(moduleAddress));
274 LOG(info) << GetName() <<
": Setup contains " << nStations <<
" stations objects.";
275 if (fair::Logger::Logging(fair::Severity::debug)) {
278 LOG(debug) <<
" " << it->second->ToString();
291 LOG(info) <<
"=========================================================="
314 LOG(info) << it->second->ToString();
325 LOG(info) << fName <<
": Reading geometry from TGeoManager " << geo->GetName();
329 TGeoNode* cave = geo->GetCurrentNode();
332 TGeoNode* sts =
nullptr;
333 for (
Int_t iNode = 0; iNode < cave->GetNdaughters(); iNode++) {
334 TString name = cave->GetDaughter(iNode)->GetName();
335 if (name.Contains(
"STS", TString::kIgnoreCase)) {
336 sts = cave->GetDaughter(iNode);
337 LOG(info) << fName <<
": STS top node is " << sts->GetName();
342 LOG(error) << fName <<
": No top STS node found in geometry!";
347 TString path = cave->GetName();
348 path = path +
"/" + sts->GetName();
349 fNode =
new TGeoPhysicalNode(path);
354 geo->RefreshPhysicalNodes();
357 Bool_t hasStation = kFALSE;
359 for (
Int_t iDaughter = 0; iDaughter <
fNode->GetNode()->GetNdaughters(); iDaughter++) {
360 TString dName =
fNode->GetNode()->GetDaughter(iDaughter)->GetName();
361 if (dName.Contains(
"station", TString::kIgnoreCase)) hasStation = kTRUE;
362 if (dName.Contains(
"unit", TString::kIgnoreCase)) hasUnit = kTRUE;
365 else if ((!hasUnit) && hasStation)
367 else if (hasUnit && hasStation)
368 LOG(fatal) << GetName() <<
": geometry contains both units and stations!";
370 LOG(fatal) << GetName() <<
": geometry contains neither units nor stations!";
372 if (
fHasStations) LOG(warn) << GetName() <<
": using old geometry (with stations)";
383 TIter nextv(geo->GetListOfVolumes());
385 while ((vol =
dynamic_cast<TGeoVolume*
>(nextv()))) {
386 if (vol->IsAssembly()) vol->GetShape()->ComputeBBox();
387 auto finder = vol->GetVoxels();
388 if (finder && finder->NeedRebuild()) {
399 LOG(info) << fName <<
": Reading geometry from file " << fileName;
402 assert(!gGeoManager);
404 TFile* oldFile = gFile;
405 TDirectory* oldDir = gDirectory;
408 TFile geoFile(fileName);
409 if (!geoFile.IsOpen()) {
410 LOG(fatal) << GetName() <<
": Could not open geometry file " << fileName;
417 TGeoManager* stsGeometry =
new TGeoManager(
"StsGeo",
"STS stand-alone geometry");
420 TGeoVolume* topVolume =
nullptr;
421 TList* keyList = geoFile.GetListOfKeys();
423 TIter keyIter(keyList);
424 while ((key = (TKey*) keyIter())) {
425 if (strcmp(key->GetClassName(),
"TGeoVolumeAssembly") == 0) {
426 TGeoVolume* volume = (TGeoVolume*) key->ReadObj();
427 if (strcmp(volume->GetName(),
"TOP") == 0) {
434 LOG(fatal) << GetName() <<
": No TOP volume in file!";
439 stsGeometry->SetTopVolume(topVolume);
442 stsGeometry->CdTop();
443 TGeoNode* cave = stsGeometry->GetCurrentNode();
446 TGeoNode* sts =
nullptr;
447 for (
Int_t iNode = 0; iNode < cave->GetNdaughters(); iNode++) {
448 TString name = cave->GetDaughter(iNode)->GetName();
449 if (name.Contains(
"STS", TString::kIgnoreCase)) {
450 sts = cave->GetDaughter(iNode);
451 stsGeometry->CdDown(iNode);
452 LOG(info) << fName <<
": STS top node is " << sts->GetName();
457 LOG(error) << fName <<
": No top STS node found in geometry!";
464 TString path = cave->GetName();
465 path = path +
"/" + sts->GetName();
466 fNode =
new TGeoPhysicalNode(path);
469 TString dName =
fNode->GetNode()->GetDaughter(0)->GetName();
470 if (dName.Contains(
"station", TString::kIgnoreCase))
fHasStations = kTRUE;
471 else if (dName.Contains(
"unit", TString::kIgnoreCase))
474 LOG(fatal) << GetName() <<
": unknown geometry type; first level name is " << dName;
475 if (
fHasStations) LOG(warn) << GetName() <<
": using old geometry (with stations)";
492 UInt_t address = moduleIt.first;
493 moduleIt.second->SetParameters(params->
GetParModule(address));
496 LOG(info) << GetName() <<
": Set parameters for " << nModules <<
" modules";
509 UInt_t address = sensorIt.first;
510 sensorIt.second->SetConditions(&(conds->
GetParSensor(address)));
513 LOG(info) << GetName() <<
": Set conditions for " << nSensors <<
" sensors";
525 UInt_t address = sensorIt.first;
526 sensorIt.second->SetParameters(&(parSet->
GetParSensor(address)));
529 LOG(info) << GetName() <<
": Set parameters for " << nSensors <<
" sensors";
ClassImp(CbmConverterManager)
XPU_D constexpr auto ToIntegralType(T enumerator) -> typename std::underlying_type< T >::type
Converts an element of enum class to its underlying integral type.
ECbmModuleId
Enumerator for module Identifiers.
@ kSts
Silicon Tracking System.
TGeoPhysicalNode * fNode
Pointer to geometry.
TGeoPhysicalNode * GetPnode() const
Int_t fAddress
Unique element address.
Int_t GetNofDaughters() const
Int_t GetNofElements(Int_t level) const
virtual void InitDaughters()
CbmStsElement * GetDaughter(Int_t index) const
Class representing an instance of a readout unit in the CBM-STS.
Parameters container for CbmStsParModule.
const CbmStsParModule & GetParModule(UInt_t address)
Get condition parameters of a sensor.
Parameters container for CbmStsParSensorCond.
const CbmStsParSensorCond & GetParSensor(UInt_t address)
Get condition parameters of a sensor.
Parameters container for CbmStsParSensor.
const CbmStsParSensor & GetParSensor(UInt_t address)
Get condition parameters of a sensor.
Class representing an instance of a sensor in the CBM-STS.
Class representing the top level of the STS setup.
const char * GetLevelName(Int_t level) const
static CbmStsSetup * fgInstance
Static instance of this class.
CbmStsSetup()
Default constructor.
Int_t GetNofSensors() const
Bool_t fIsSensorCondInit
Sensor conditions set.
Bool_t ReadGeometry(TGeoManager *geoManager)
Read the geometry from TGeoManager.
Bool_t fHasStations
Legacy with stations instead of units.
Bool_t Init(const char *geometryFile=nullptr)
Initialise the setup.
Bool_t fIsSensorParsInit
Sensor parameters set.
CbmStsElement * GetElement(Int_t address, Int_t level)
UInt_t SetSensorConditions(CbmStsParSetSensorCond *conds)
Set sensor conditions from parameter container.
Int_t CreateStations()
Create station objects.
std::map< Int_t, CbmStsSensor * > fSensors
void RecomputePhysicalAssmbBbox(TGeoManager *geo)
static CbmStsSetup * Instance()
std::vector< CbmStsModule * > fModuleVector
Bool_t fIsModuleParsInit
Module parameters set.
UInt_t SetModuleParameters(CbmStsParSetModule *modulePars)
Set module parameters from parameter container.
UInt_t SetSensorParameters(CbmStsParSetSensor *parSet)
Set sensor parameters from parameter container.
std::vector< CbmStsSensor * > fSensorVector
Int_t GetStationNumber(Int_t address)
std::map< Int_t, CbmStsModule * > fModules
Bool_t fIsInitialised
All parameter containers set.
std::map< Int_t, CbmStsStation * > fStations
Class representing a station of the StsSystem.
void Init()
Initialise the station parameters.
void AddLadder(CbmStsElement *ladder)
int32_t GetAddress(uint32_t unit=0, uint32_t ladder=0, uint32_t halfladder=0, uint32_t module=0, uint32_t sensor=0, uint32_t side=0, uint32_t version=kCurrentVersion)
Construct address.
ECbmModuleId GetSystemId(int32_t address)
Get system Id (should be ECbmModuleId::kSts)
uint32_t GetElementId(int32_t address, int32_t level)
Get the index of an element.