er  dev
ERGeoComponent.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 "ERGeoComponent.h"
10 
11 #include "TGeoMedium.h"
12 #include "TGeoManager.h"
13 #include "TROOT.h"
14 #include "TSystem.h"
15 
16 #include "FairGeoLoader.h"
17 #include "FairGeoMedia.h"
18 #include "FairGeoBuilder.h"
19 #include "FairGeoMedium.h"
20 #include "FairGeoInterface.h"
21 #include "FairLogger.h"
22 //--------------------------------------------------------------------------------------------------
23 ERGeoComponent::ERGeoComponent(const TString& typeFromXML, const TString& id)
24 : TNamed(typeFromXML + id, typeFromXML + id),
25  fType(typeFromXML),
26  fComponentId(id),
27  fVolumeName(id)
28 {
29 }
30 //--------------------------------------------------------------------------------------------------
31 ERGeoComponent::ERGeoComponent(const TString& name, const TVector3& position,
32  const TVector3& rotation)
33 : TNamed(name, name), fVolumeName(name), fPosition(position)
34 {
35  fRotation.RotateX(rotation.X());
36  fRotation.RotateY(rotation.Y());
37  fRotation.RotateZ(rotation.Z());
38 }
39 //--------------------------------------------------------------------------------------------------
40 ERGeoComponent::ERGeoComponent(const TString& typeFromXML, const TString& id, const TVector3& position,
41  const TVector3& rotation)
42 : TNamed(typeFromXML + id, typeFromXML + id), fType(typeFromXML),
43  fComponentId(id), fVolumeName(id), fPosition(position)
44 {
45  fRotation.RotateX(rotation.X());
46  fRotation.RotateY(rotation.Y());
47  fRotation.RotateZ(rotation.Z());
48 }
49 //--------------------------------------------------------------------------------------------------
50 void ERGeoComponent::SetRotation(const TVector3& rotation) {
51  fRotation.Clear();
52  fRotation.RotateX(rotation.X());
53  fRotation.RotateY(rotation.Y());
54  fRotation.RotateZ(rotation.Z());
55 }
56 //--------------------------------------------------------------------------------------------------
57 TGeoMedium* ERGeoComponent::CreateMaterial(const TString& name) {
58  FairGeoLoader* geoLoader = FairGeoLoader::Instance();
59  FairGeoInterface* geoFace = geoLoader->getGeoInterface();
60  TString geoPath = gSystem->Getenv("VMCWORKDIR");
61  TString medFile = geoPath + "/geometry/media.geo";
62  geoFace->setMediaFile(medFile);
63  geoFace->readMedia();
64  FairGeoMedia* geoMedia = geoFace->getMedia();
65  FairGeoBuilder* geoBuilder = geoLoader->getGeoBuilder();
66  FairGeoMedium* fairMedia = geoMedia->getMedium(name);
67  if (!fairMedia)
68  LOG(FATAL) << "Media " << name << " not found in media.geo file\n";
69  geoBuilder->createMedium(fairMedia);
70  TGeoMedium* rootMedia = gGeoManager->GetMedium(name);
71  if (!rootMedia)
72  LOG(FATAL) << "Media " << name << " not found in gGeoManager\n";
73  LOG(DEBUG) << "Created " << name << " media\n";
74  return rootMedia;
75 }
76 //--------------------------------------------------------------------------------------------------
77 ClassImp(ERGeoComponent)
78