10 #include <geometry/Materials.h>
11 #include <framework/gearbox/GearDir.h>
12 #include <framework/logging/Logger.h>
13 #include <boost/format.hpp>
14 #include <boost/lexical_cast.hpp>
15 #include <boost/algorithm/string.hpp>
16 #include <beast/csi/geometry/CsiGeometryPar.h>
22 using namespace boost;
26 #define PI 3.14159265358979323846
33 if (!m_B4CsiGeometryParDB) m_B4CsiGeometryParDB =
new CsiGeometryPar();
34 return m_B4CsiGeometryParDB;
37 CsiGeometryPar::CsiGeometryPar()
45 CsiGeometryPar::~CsiGeometryPar()
47 if (m_B4CsiGeometryParDB) {
48 delete m_B4CsiGeometryParDB;
49 B2INFO(
"m_B4CsiGeometryParDB deleted ");
53 void CsiGeometryPar::clear()
58 m_Orientation.clear();
66 void CsiGeometryPar::read()
69 GearDir content =
GearDir(
"/Detector/DetectorComponent[@name=\"CSI\"]/Content/");
70 string gearPath =
"Enclosures/Enclosure";
71 int nEnc = content.getNumberNodes(gearPath);
75 for (
int iEnc = 1; iEnc <= nEnc; iEnc++) {
77 double length = content.getLength(
"Enclosures/Length") * CLHEP::cm;
78 double thk = content.getLength(
"Enclosures/Thickness") * CLHEP::cm;
79 double halflength = 15.0 * CLHEP::cm;
80 double zshift = 0.5 * length - thk - halflength;
82 string enclosurePath = (boost::format(
"/%1%[%2%]") % gearPath % iEnc).str();
85 GearDir enclosureContent(content);
86 enclosureContent.
append(enclosurePath);
89 double PosZ = enclosureContent.
getLength(
"PosZ") * CLHEP::cm;
90 double PosR = enclosureContent.
getLength(
"PosR") * CLHEP::cm;
91 double PosT = enclosureContent.
getAngle(
"PosT") ;
94 double Phi1 = enclosureContent.
getAngle(
"AngPhi1") ;
95 double Theta = enclosureContent.
getAngle(
"AngTheta") ;
96 double Phi2 = enclosureContent.
getAngle(
"AngPhi2") ;
98 Transform3D zsh = Translate3D(0, 0, zshift);
99 Transform3D m1 = RotateZ3D(Phi1);
100 Transform3D m2 = RotateY3D(Theta);
101 Transform3D m3 = RotateZ3D(Phi2);
102 Transform3D position = Translate3D(PosR * cos(PosT), PosR * sin(PosT), PosZ);
105 Transform3D Tr = position * m3 * m2 * m1;
108 for (
int iSlot = 1; iSlot <= nSlots; iSlot++) {
112 string slotPath = (boost::format(
"/Enclosures/Slot[%1%]") % iSlot).str();
115 slotContent.
append(slotPath);
117 double SlotX = slotContent.
getLength(
"PosX") * CLHEP::cm;
118 double SlotY = slotContent.
getLength(
"PosY") * CLHEP::cm;
119 double SlotZ = slotContent.
getLength(
"PosZ") * CLHEP::cm;
120 Transform3D Pos = Translate3D(SlotX, SlotY, SlotZ);
122 Transform3D CrystalPos = Tr * Pos;
123 RotationMatrix CrystalRot = CrystalPos.getRotation();
125 m_Position.push_back(CrystalPos.getTranslation() * 1.0 / CLHEP::cm);
126 m_Orientation.push_back(CrystalRot.colZ());
128 m_thetaID.push_back(CrystalPos.getTranslation().z() > 0 ? 0 : 1);
129 m_phiID.push_back(iCell - 9 * m_thetaID.back());
131 m_BoxID.push_back(iEnc - 1);
132 m_SlotID.push_back(iSlot - 1);
139 vector<ThreeVector>::iterator it;
140 for (it = m_Position.begin(); it != m_Position.end(); ++it) {
141 m_PositionTV3.push_back(ConvertToTVector3(*it));
143 for (it = m_Orientation.begin(); it != m_Orientation.end(); ++it) {
144 m_OrientationTV3.push_back(ConvertToTVector3(*it));
151 int CsiGeometryPar::CsiVolNameToCellID(
const G4String VolumeName)
155 vector< string > partName;
156 split(partName, VolumeName, is_any_of(
"_"));
160 for (std::vector<string>::iterator it = partName.begin() ; it != partName.end(); ++it) {
161 if (equals(*it,
"Enclosure")) iEnclosure = boost::lexical_cast<int>(*(it + 1)) - 1;
162 else if (equals(*it,
"Crystal")) iCrystal = boost::lexical_cast<int>(*(it + 1)) - 1;
165 cellID = 3 * iEnclosure + iCrystal;
167 if (cellID < 0) B2WARNING(
"CsiGeometryPar: volume " << VolumeName <<
" is not a crystal");
173 G4Material* CsiGeometryPar::GetMaterial(
int cid)
175 int iEnclosure = GetEnclosureID(cid) + 1;
176 int iSlot = GetSlotID(cid) + 1;
178 GearDir content =
GearDir(
"/Detector/DetectorComponent[@name=\"CSI\"]/Content/");
180 GearDir enclosureContent(content);
181 string gearPath =
"Enclosures/Enclosure";
182 string enclosurePath = (format(
"/%1%[%2%]") % gearPath % iEnclosure).str();
183 enclosureContent.
append(enclosurePath);
185 string slotName = (format(
"CrystalInSlot[%1%]") % iSlot).str();
186 int iCry = enclosureContent.
getInt(slotName);
189 GearDir crystalContent(content);
190 crystalContent.
append((format(
"/EndCapCrystals/EndCapCrystal[%1%]/") % (iCry)).str());
191 string strMatCrystal = crystalContent.
getString(
"Material",
"Air");
193 return geometry::Materials::get(strMatCrystal);
198 double CsiGeometryPar::GetMaterialProperty(
int cid,
const char* propertyname)
200 G4Material* mat = GetMaterial(cid);
201 G4MaterialPropertiesTable* properties = mat->GetMaterialPropertiesTable();
202 G4MaterialPropertyVector*
property = properties->GetProperty(propertyname);
204 return property->Value(0);
207 void CsiGeometryPar::Print(
int cid,
int debuglevel)
209 B2DEBUG(debuglevel,
"Cell ID : " << cid);
211 B2DEBUG(debuglevel,
" Position x : " << GetPosition(cid).x());
212 B2DEBUG(debuglevel,
" Position y : " << GetPosition(cid).y());
213 B2DEBUG(debuglevel,
" Position z : " << GetPosition(cid).z());
215 B2DEBUG(debuglevel,
" Orientation x : " << GetOrientation(cid).x());
216 B2DEBUG(debuglevel,
" Orientation y : " << GetOrientation(cid).y());
217 B2DEBUG(debuglevel,
" Orientation z : " << GetOrientation(cid).z());
219 B2DEBUG(debuglevel,
" Material : " << GetMaterial(cid)->GetName());
221 B2DEBUG(debuglevel,
" Slow time constatnt : " << GetMaterialProperty(cid,
"SLOWTIMECONSTANT"));
222 B2DEBUG(debuglevel,
" Fast time constatnt : " << GetMaterialProperty(cid,
"FASTTIMECONSTANT"));
223 B2DEBUG(debuglevel,
" Light yield : " << GetMaterialProperty(cid,
"SCINTILLATIONYIELD"));
228 void CsiGeometryPar::PrintAll(
int debuglevel)
230 for (uint i = 0; i < m_thetaID.size(); i++)
231 Print(i, debuglevel);