er  dev
ERSetup.cxx
1 /********************************************************************************
2  * Copyright (C) Joint Institute for Nuclear Research *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 
9 #include "ERSetup.h"
10 
11 #include "TGeoManager.h"
12 #include "TROOT.h"
13 
14 #include "FairRootManager.h"
15 #include "FairRunAna.h"
16 #include "FairRun.h"
17 #include "FairRuntimeDb.h"
18 #include "FairGeoLoader.h"
19 #include "FairGeoInterface.h"
20 #include "FairGeoMedia.h"
21 #include "FairGeoBuilder.h"
22 #include "FairLogger.h"
23 //--------------------------------------------------------------------------------------------------
24 Int_t ERSetup::SetParContainers(){
25  // Get run and runtime database
26  FairRun* run = FairRun::Instance();
27  if ( ! run ) Fatal("SetParContainers", "No analysis run");
28  FairRuntimeDb* rtdb = run->GetRuntimeDb();
29  if ( ! rtdb ) Fatal("SetParContainers", "No runtime database");
30 }
31 //--------------------------------------------------------------------------------------------------
32 void ERSetup::AddSubAssembly(ERGeoSubAssembly* subAssembly) {
33  fSubAssemblies[subAssembly->GetName()] = subAssembly;
34 }
35 //--------------------------------------------------------------------------------------------------
36 void ERSetup::AddSubAssembly(ERGeoSubAssembly* subAssembly, const TVector3& position,
37  const TVector3& rotation) {
38  subAssembly->SetPosition(position);
39  subAssembly->SetRotation(rotation);
40  AddSubAssembly(subAssembly);
41 }
42 //--------------------------------------------------------------------------------------------------
43 void ERSetup::ConstructGeometry(void) {
44  if (!gGeoManager)
45  LOG(FATAL) << "[ERSetup] gGeoManager has not inited.\n";
46  TGeoVolume* top = new TGeoVolumeAssembly("TOP");
47  TGeoVolume* geoVol = new TGeoVolumeAssembly(fGeoName);
48  int i = 0;
49  for (auto subAssemblyPair : fSubAssemblies) {
50  auto* subAssembly = subAssemblyPair.second;
51  subAssembly->ConstructGeometryVolume();
52  const TVector3* translation = subAssembly->GetPosition();
53  auto* rotation = const_cast<TGeoRotation*>(subAssembly->GetRotation());
54  auto* volume = const_cast<TGeoVolume*>(subAssembly->GetVolume());
55  geoVol->AddNode(volume, ++i,
56  new TGeoCombiTrans(translation->X() ,translation->Y(), translation->Z(),
57  rotation));
58  }
59  top->AddNode(geoVol, 1, new TGeoCombiTrans(0., 0., 0., new TGeoRotation()));
60  const TString geoPath = gSystem->Getenv("VMCWORKDIR");
61  const TString geoFileName = geoPath + "/geometry/" + fGeoName + ".temp.root";
62  TFile* geoFile = new TFile(geoFileName, "RECREATE");
63  top->Write();
64  geoFile->Close();
65 }
66 //--------------------------------------------------------------------------------------------------
67 std::list<ERGeoComponent*> ERSetup::GetAllComponents() {
68  std::list<ERGeoComponent*> components;
69  for (auto subAssemblyPair : fSubAssemblies) {
70  auto* subAssembly = subAssemblyPair.second;
71  auto& subComponents = subAssembly->GetComponents();
72  for (auto subComponentPair : subComponents) {
73  components.push_back(subComponentPair.second);
74  }
75  }
76  return components;
77 }
78 //--------------------------------------------------------------------------------------------------
79 ERGeoComponent* ERSetup::GetComponent(const TString& path){
80  const auto components = GetAllComponents();
81  const auto componentIt = std::find_if(
82  components.begin(), components.end(), [&path](ERGeoComponent* component) {
83  return path.Contains(component->GetVolumeName());
84  });
85  return componentIt != components.end() ? *componentIt : nullptr;
86 }
87 //--------------------------------------------------------------------------------------------------
88 ClassImp(ERSetup)