4 #include "StiDetectorVolume.h"
6 #include "TVolumePosition.h"
7 #include "TRotMatrix.h"
12 #include "TGeometry.h"
13 #include "Sti/StiPlanarShape.h"
14 #include "Sti/StiCylindricalShape.h"
15 #include "Sti/StiGenericDetectorGroup.h"
16 #include "Sti/StiDetector.h"
17 #include "Sti/StiDetectorGroups.h"
18 #include "Sti/StiDetectorBuilder.h"
19 #include "Sti/StiPlacement.h"
20 #include "Sti/StiMaterial.h"
25 static Bool_t CompareMatrix(TRotMatrix &a,TRotMatrix &b)
28 double *pa=a.GetMatrix();
double *pb=b.GetMatrix();
29 for (
int i=0; i<9; i++)
if (pa[i]!=pb[i])
return kFALSE;
35 inline static TRotMatrix *GetMatrix(
float angle)
39 TMath::Cos(angle), -TMath::Sin(angle), 0
40 ,TMath::Sin(angle), TMath::Cos(angle), 0
44 TRotMatrix *mat =
new TRotMatrix();
56 StiDetectorVolume::StiDetectorVolume(
StiToolkit &tool,
const TString &detectorName,
unsigned int select)
57 :
TVolume(
"RnD",
"Sti",(TShape*)0),fDetector(0)
59 MakeDetector(tool,detectorName, select);
63 StiDetectorVolume::StiDetectorVolume(
const StiDetectorBuilder &builder,
unsigned int select) :
64 TVolume(builder.getName().c_str(),
"StiDetectorBuilder",(TShape *)0),fDetector(0)
66 MakeVolume(builder,select);
70 StiDetectorVolume::StiDetectorVolume(
StiDetector *detector) :
71 TVolume(),fDetector(detector) { }
74 StiDetectorVolume::StiDetectorVolume(
StiDetector *detector,
const Text_t* name,
const Text_t* title,
const Text_t* shapename, Option_t* option):
75 TVolume( name, title, shapename, option),fDetector(detector) { }
78 StiDetectorVolume::StiDetectorVolume(
StiDetector *detector,
const Text_t* name,
const Text_t* title, TShape* shape, Option_t* option):
79 TVolume(name,title,shape,option ),fDetector(detector) { }
92 void StiDetectorVolume::MakeDetector(
StiToolkit &tool,
const TString &detectorName,
unsigned int select)
96 vector<StiGenericDetectorGroup *>::iterator it = groups->begin();
97 for (; it != groups->end(); ++it) {
100 TString builderName = (
const char*)builder.
getName().c_str();
101 if ( detectorName.IsNull() || (builderName.BeginsWith(detectorName,TString::kIgnoreCase)) )
104 LOG_INFO <<
"Skip " << (
const char*)builder.
getName().c_str() <<
" detector" << endm;
109 void StiDetectorVolume::MakeVolume(
const StiDetectorBuilder &builder,
unsigned int select)
112 unsigned int nRows = builder.getNRows();
113 LOG_INFO <<
"Builder: " << builder.
getName().c_str() <<
" has " << nRows <<
" rows" << endm;
114 for (
unsigned int i=0; i < nRows; i++) {
116 Int_t iColor = 3 + i%6;
117 for (
unsigned int j=0;j<nSectors;j++)
121 LOG_ERROR <<
"The is no detector for row " << i <<
" sector " << j << endm;
124 if (select && ( ( select == kActive && !next->isActive())
126 ( select == kPassivie && next->isActive() )
128 const StiShape *stiShape = next->getShape();
129 TShape *shape = MakeShape(stiShape
130 ,(
const char*)next->getMaterial()->
getName().c_str() );
132 TString canonicName = (
const char*)next->
getName().c_str();
133 canonicName.ReplaceAll(
"/",
"_");
135 nextVolume->SetFillColor(iColor); nextVolume->SetLineColor(iColor);
136 bool planar = (stiShape->getShapeCode() == kPlanar);
139 if (place->getNormalRefAngle() != 0) {
140 position =
new TVolumePosition(0, 0, 0, 0, GetMatrix(place->getNormalRefAngle()));
141 position->SetMatrixOwner();
143 ,place->getNormalYoffset()
144 ,place->getNormalRadius()
147 position->Mult(*translate );
151 ,place->getNormalYoffset()
152 ,place->getNormalRadius()
154 ,GetMatrix(place->getNormalRefAngle())
158 position =
new TVolumePosition(0, 0, 0, place->getZcenter(), GetMatrix(place->getNormalRefAngle()));
160 position->SetNode(nextVolume);
161 Add(nextVolume,position);
164 TShape *sh = nextVolume->GetShape();
167 if (sh->InheritsFrom(
"TBRIK")) {
168 TBRIK *brik = (TBRIK *) sh;
169 cout <<
" dx " << brik->GetDx()
170 <<
" dy " << brik->GetDy()
171 <<
" dz " << brik->GetDz() << endl;
173 if (sh->InheritsFrom(
"TTUBE")) {
174 TTUBE *tube = (TTUBE *) sh;
175 cout <<
" Rmin " << tube->GetRmin()
176 <<
" Rmax " << tube->GetRmax()
177 <<
" dz " << tube->GetDz();
179 if (sh->InheritsFrom(
"TTUBS")) {
180 TTUBS *tubs = (TTUBS *) sh;
181 cout <<
" Phi1 " << tubs->GetPhi1()
182 <<
" Phi2 " << tubs->GetPhi2();
193 TShape *StiDetectorVolume::MakeShape(
const StiShape *shape,
const char*material)
197 switch (shape->getShapeCode()) {
211 TShape *StiDetectorVolume::MakeShape(
const StiPlanarShape &shape,
const char*material)
214 new TBRIK((
const char*)shape.
getName().c_str()
217 , shape.getHalfWidth()
218 , shape.getThickness()/2
219 , shape.getHalfDepth() );
225 return (shape.getOpeningAngle() < (TMath::TwoPi()-0.001) ) ?
226 new TTUBS((
const char*)shape.
getName().c_str()
227 ,
"StiCylindricalShape"
229 , shape.getOuterRadius() - shape.getThickness()
230 , shape.getOuterRadius()
231 , shape.getHalfDepth()
232 , -shape.getOpeningAngle()*TMath::RadToDeg()/2
233 , +shape.getOpeningAngle()*TMath::RadToDeg()/2 )
235 new TTUBE((
const char*)shape.
getName().c_str()
236 ,
"StiCylindricalShape"
238 , shape.getOuterRadius() - shape.getThickness()
239 , shape.getOuterRadius()
240 , shape.getHalfDepth()
254 TFile fileTmp(fileName.c_str(),
"RECREATE");
virtual char * GetObjectInfo(Int_t px, Int_t py) const
to be documented
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
virtual void Browse(TBrowser *b)
to be documented
virtual char * GetObjectInfo(Int_t px, Int_t py) const
to be documented
virtual StiDetectorBuilder * getDetectorBuilder()
Get a detector builder appropriate for this detector group.
virtual void Browse(TBrowser *b)
to be documented
void SaveGeometry(const std::string fileName="sti2rootgeo.root") const
virtual void Print(Option_t *option="") const
to be documented
virtual UInt_t getNSectors(UInt_t row=0) const
const string & getName() const
Get the name of the object.