8#include <geometry/Materials.h>
9#include <framework/gearbox/GearDir.h>
10#include <framework/logging/Logger.h>
11#include <boost/format.hpp>
12#include <boost/lexical_cast.hpp>
13#include <boost/algorithm/string.hpp>
14#include <beast/csi/geometry/CsiGeometryPar.h>
43 B2INFO(
"m_B4CsiGeometryParDB deleted ");
63 GearDir content =
GearDir(
"/Detector/DetectorComponent[@name=\"CSI\"]/Content/");
64 string gearPath =
"Enclosures/Enclosure";
65 int nEnc = content.getNumberNodes(gearPath);
69 for (
int iEnc = 1; iEnc <= nEnc; iEnc++) {
76 string enclosurePath = (boost::format(
"/%1%[%2%]") % gearPath % iEnc).str();
79 GearDir enclosureContent(content);
80 enclosureContent.
append(enclosurePath);
83 double PosZ = enclosureContent.
getLength(
"PosZ") * CLHEP::cm;
84 double PosR = enclosureContent.
getLength(
"PosR") * CLHEP::cm;
85 double PosT = enclosureContent.
getAngle(
"PosT") ;
88 double Phi1 = enclosureContent.
getAngle(
"AngPhi1") ;
89 double Theta = enclosureContent.
getAngle(
"AngTheta") ;
90 double Phi2 = enclosureContent.
getAngle(
"AngPhi2") ;
93 Transform3D m1 = RotateZ3D(Phi1);
94 Transform3D m2 = RotateY3D(Theta);
95 Transform3D m3 = RotateZ3D(Phi2);
96 Transform3D position = Translate3D(PosR * cos(PosT), PosR * sin(PosT), PosZ);
99 Transform3D Tr = position * m3 * m2 * m1;
102 for (
int iSlot = 1; iSlot <= nSlots; iSlot++) {
106 string slotPath = (boost::format(
"/Enclosures/Slot[%1%]") % iSlot).str();
109 slotContent.
append(slotPath);
111 double SlotX = slotContent.
getLength(
"PosX") * CLHEP::cm;
112 double SlotY = slotContent.
getLength(
"PosY") * CLHEP::cm;
113 double SlotZ = slotContent.
getLength(
"PosZ") * CLHEP::cm;
114 Transform3D Pos = Translate3D(SlotX, SlotY, SlotZ);
116 Transform3D CrystalPos = Tr * Pos;
117 RotationMatrix CrystalRot = CrystalPos.getRotation();
119 m_Position.push_back(ROOT::Math::XYZVector(CrystalPos.getTranslation()) * 1.0 / CLHEP::cm);
120 m_Orientation.push_back(ROOT::Math::XYZVector(CrystalRot.colZ()));
122 m_thetaID.push_back(CrystalPos.getTranslation().z() > 0 ? 0 : 1);
137 vector< string > partName;
138 boost::split(partName, VolumeName, boost::is_any_of(
"_"));
142 for (std::vector<string>::iterator it = partName.begin() ; it != partName.end(); ++it) {
143 if (boost::equals(*it,
"Enclosure")) iEnclosure = boost::lexical_cast<int>(*(it + 1)) - 1;
144 else if (boost::equals(*it,
"Crystal")) iCrystal = boost::lexical_cast<int>(*(it + 1)) - 1;
147 cellID = 3 * iEnclosure + iCrystal;
149 if (cellID < 0) B2WARNING(
"CsiGeometryPar: volume " << VolumeName <<
" is not a crystal");
160 GearDir content =
GearDir(
"/Detector/DetectorComponent[@name=\"CSI\"]/Content/");
162 GearDir enclosureContent(content);
163 string gearPath =
"Enclosures/Enclosure";
164 string enclosurePath = (boost::format(
"/%1%[%2%]") % gearPath % iEnclosure).str();
165 enclosureContent.
append(enclosurePath);
167 string slotName = (boost::format(
"CrystalInSlot[%1%]") % iSlot).str();
168 int iCry = enclosureContent.
getInt(slotName);
171 GearDir crystalContent(content);
172 crystalContent.
append((boost::format(
"/EndCapCrystals/EndCapCrystal[%1%]/") % (iCry)).str());
173 string strMatCrystal = crystalContent.
getString(
"Material",
"Air");
183 G4MaterialPropertiesTable* properties = mat->GetMaterialPropertiesTable();
184 G4MaterialPropertyVector*
property = properties->GetProperty(propertyname);
186 return property->Value(0);
191 B2DEBUG(debuglevel,
"Cell ID : " << cid);
193 B2DEBUG(debuglevel,
" Position x : " <<
GetPosition(cid).x());
194 B2DEBUG(debuglevel,
" Position y : " <<
GetPosition(cid).y());
195 B2DEBUG(debuglevel,
" Position z : " <<
GetPosition(cid).z());
197 B2DEBUG(debuglevel,
" Orientation x : " <<
GetOrientation(cid).x());
198 B2DEBUG(debuglevel,
" Orientation y : " <<
GetOrientation(cid).y());
199 B2DEBUG(debuglevel,
" Orientation z : " <<
GetOrientation(cid).z());
201 B2DEBUG(debuglevel,
" Material : " <<
GetMaterial(cid)->GetName());
203 B2DEBUG(debuglevel,
" Slow time constant : " <<
GetMaterialProperty(cid,
"SLOWTIMECONSTANT"));
204 B2DEBUG(debuglevel,
" Fast time constant : " <<
GetMaterialProperty(cid,
"FASTTIMECONSTANT"));
212 for (uint i = 0; i <
m_thetaID.size(); i++)
213 Print(i, debuglevel);
GearDir is the basic class used for accessing the parameter store.
void append(const std::string &path)
Append something to the current path, modifying the GearDir in place.
virtual int getNumberNodes(const std::string &path="") const override
Return the number of nodes a given path will expand to.
virtual std::string getString(const std::string &path="") const noexcept(false) override
Get the parameter path as a string.
The Class for CSI Geometry Parameters.
void PrintAll(int debuglevel=80)
Print all crystals information.
std::vector< ROOT::Math::XYZVector > m_Position
Position of the nominal centre of the crystal.
int GetEnclosureID(int cid)
Get Enclosure ID from cell ID.
ROOT::Math::XYZVector GetOrientation(int cid)
Get the orientation of the crystal.
std::vector< ROOT::Math::XYZVector > m_Orientation
Orientation of the crystal.
CsiGeometryPar()
Constructor.
std::vector< int > m_thetaID
The Theta ID information.
void Print(const int cid, int debuglevel=80)
Print crystal information.
int m_cellID
The Cell ID information.
ROOT::Math::XYZVector GetPosition(int cid)
Get the position of the crystal.
std::vector< int > m_phiID
The Phi ID information.
void read()
Gets geometry parameters from gearbox.
virtual ~CsiGeometryPar()
Destructor.
std::vector< int > m_BoxID
The index of the enclosure.
G4Material * GetMaterial(int cid)
Get pointer to the Geant4 Material.
static CsiGeometryPar * Instance()
Static method to get a reference to the CsiGeometryPar instance.
int CsiVolNameToCellID(const G4String VolumeName)
Get Cell Id.
std::vector< int > m_SlotID
The slot index of the crystal in the enclosure.
int GetSlotID(int cid)
Get Slot ID in the Enclosure from cell ID.
static CsiGeometryPar * m_B4CsiGeometryParDB
Pointer that saves the instance of this class.
double GetMaterialProperty(int cid, const char *propertyname)
Get material property.
double getAngle(const std::string &path="") const noexcept(false)
Get the parameter path as a double converted to the standard angle unit.
double getLength(const std::string &path="") const noexcept(false)
Get the parameter path as a double converted to the standard length unit.
int getInt(const std::string &path="") const noexcept(false)
Get the parameter path as a int.
static G4Material * get(const std::string &name)
Find given material.
Abstract base class for different kinds of events.