21 TGeometry *gGeometry = 0;
96 TGeometry::TGeometry()
98 fMaterials =
new THashList(100,3);
99 fMatrices =
new THashList(100,3);
100 fShapes =
new THashList(500,3);
103 fMaterialPointer = 0;
111 fIsReflection[fGeomLevel] = kFALSE;
117 TGeometry::TGeometry(
const char *name,
const char *title ) : TNamed (name, title)
119 fMaterials =
new THashList(1000,3);
120 fMatrices =
new THashList(1000,3);
121 fShapes =
new THashList(5000,3);
124 fMaterialPointer = 0;
131 gROOT->GetListOfGeometries()->Add(
this);
133 fIsReflection[fGeomLevel] = kFALSE;
139 TGeometry::TGeometry(
const TGeometry& geo) :
141 fMaterials(geo.fMaterials),
142 fMatrices(geo.fMatrices),
143 fShapes(geo.fShapes),
145 fMatrix(geo.fMatrix),
146 fCurrentNode(geo.fCurrentNode),
147 fMaterialPointer(geo.fMaterialPointer),
148 fMatrixPointer(geo.fMatrixPointer),
149 fShapePointer(geo.fShapePointer),
151 fGeomLevel(geo.fGeomLevel),
156 for(Int_t i=0; i<kMAXLEVELS; i++) {
157 for(Int_t j=0; j<kVectorSize; j++)
158 fTranslation[i][j]=geo.fTranslation[i][j];
159 for(Int_t j=0; j<kMatrixSize; j++)
160 fRotMatrix[i][j]=geo.fRotMatrix[i][j];
161 fIsReflection[i]=geo.fIsReflection[i];
168 TGeometry& TGeometry::operator=(
const TGeometry& geo)
171 TNamed::operator=(geo);
172 fMaterials=geo.fMaterials;
173 fMatrices=geo.fMatrices;
177 fCurrentNode=geo.fCurrentNode;
178 fMaterialPointer=geo.fMaterialPointer;
179 fMatrixPointer=geo.fMatrixPointer;
180 fShapePointer=geo.fShapePointer;
182 fGeomLevel=geo.fGeomLevel;
186 for(Int_t i=0; i<kMAXLEVELS; i++) {
187 for(Int_t j=0; j<kVectorSize; j++)
188 fTranslation[i][j]=geo.fTranslation[i][j];
189 for(Int_t j=0; j<kMatrixSize; j++)
190 fRotMatrix[i][j]=geo.fRotMatrix[i][j];
191 fIsReflection[i]=geo.fIsReflection[i];
200 TGeometry::~TGeometry()
202 if (!fMaterials)
return;
203 fMaterials->Delete();
211 delete [] fMaterialPointer;
212 delete [] fMatrixPointer;
213 delete [] fShapePointer;
218 fMaterialPointer = 0;
222 if (gGeometry ==
this) {
223 gGeometry = (TGeometry*) gROOT->GetListOfGeometries()->First();
224 if (gGeometry ==
this)
225 gGeometry = (TGeometry*) gROOT->GetListOfGeometries()->After(gGeometry);
227 gROOT->GetListOfGeometries()->Remove(
this);
233 void TGeometry::Browse(TBrowser *b)
236 b->Add( fMaterials,
"Materials" );
237 b->Add( fMatrices,
"Rotation Matrices" );
238 b->Add( fShapes,
"Shapes" );
239 b->Add( fNodes,
"Nodes" );
246 void TGeometry::cd(
const char *)
254 void TGeometry::Draw(Option_t *option)
256 TNode *node1 = (TNode*)fNodes->First();
257 if (node1) node1->Draw(option);
264 TObject *TGeometry::FindObject(
const TObject *)
const
266 Error(
"FindObject",
"Not yet implemented");
273 TObject *TGeometry::FindObject(
const char *name)
const
275 TObjArray *loc = TGeometry::Get(name);
276 if (loc)
return loc->At(0);
285 TObjArray *TGeometry::Get(
const char *name)
287 static TObjArray *locs = 0;
288 if (!locs) locs =
new TObjArray(2);
289 TObjArray &loc = *locs;
293 if (!gGeometry)
return &loc;
298 temp = gGeometry->GetListOfMaterials()->FindObject(name);
299 where = gGeometry->GetListOfMaterials();
302 temp = gGeometry->GetListOfShapes()->FindObject(name);
303 where = gGeometry->GetListOfShapes();
306 temp = gGeometry->GetListOfMatrices()->FindObject(name);
307 where = gGeometry->GetListOfMatrices();
310 temp = gGeometry->GetNode(name);
322 TMaterial *TGeometry::GetMaterial(
const char *name)
const
324 return (TMaterial*)fMaterials->FindObject(name);
330 TMaterial *TGeometry::GetMaterialByNumber(Int_t number)
const
333 if (number < 0 || number >= fMaterials->GetSize())
return 0;
334 if (fMaterialPointer)
return fMaterialPointer[number];
335 TIter next(fMaterials);
336 while ((mat = (TMaterial*) next())) {
337 if (mat->GetNumber() == number)
return mat;
345 TNode *TGeometry::GetNode(
const char *name)
const
347 TNode *node= (TNode*)GetListOfNodes()->First();
349 if (node->TestBit(kNotDeleted))
return node->GetNode(name);
356 TRotMatrix *TGeometry::GetRotMatrix(
const char *name)
const
358 return (TRotMatrix*)fMatrices->FindObject(name);
364 TRotMatrix *TGeometry::GetRotMatrixByNumber(Int_t number)
const
367 if (number < 0 || number >= fMatrices->GetSize())
return 0;
368 if (fMatrixPointer)
return fMatrixPointer[number];
369 TIter next(fMatrices);
370 while ((matrix = (TRotMatrix*) next())) {
371 if (matrix->GetNumber() == number)
return matrix;
379 TShape *TGeometry::GetShape(
const char *name)
const
381 return (TShape*)fShapes->FindObject(name);
387 TShape *TGeometry::GetShapeByNumber(Int_t number)
const
390 if (number < 0 || number >= fShapes->GetSize())
return 0;
391 if (fShapePointer)
return fShapePointer[number];
393 while ((shape = (TShape*) next())) {
394 if (shape->GetNumber() == number)
return shape;
407 void TGeometry::Local2Master(Double_t *local, Double_t *master)
411 Double_t bomb = GetBomb();
412 Double_t *matrix = &fRotMatrix[GeomLevel()][0];
416 + local[2]*matrix[6];
421 + local[2]*matrix[7];
426 + local[2]*matrix[8];
427 master[0] = x; master[1] = y; master[2] = z;
430 for (Int_t i=0;i<3;i++) master[i] = local[i];
441 void TGeometry::Local2Master(Float_t *local, Float_t *master)
445 Float_t bomb = GetBomb();
447 Double_t *matrix = &fRotMatrix[GeomLevel()][0];
452 + local[2]*matrix[6];
457 + local[2]*matrix[7];
462 + local[2]*matrix[8];
464 master[0] = x; master[1] = y; master[2] = z;
467 for (Int_t i=0;i<3;i++) master[i] = local[i];
473 void TGeometry::ls(Option_t *option)
const
475 TString opt = option;
477 if (opt.Contains(
"m")) {
478 Printf(
"=================List of Materials================");
479 fMaterials->ls(option);
481 if (opt.Contains(
"r")) {
482 Printf(
"=================List of RotationMatrices================");
483 fMatrices->ls(option);
485 if (opt.Contains(
"s")) {
486 Printf(
"=================List of Shapes==========================");
489 if (opt.Contains(
"n")) {
490 Printf(
"=================List of Nodes===========================");
503 void TGeometry::Master2Local(Double_t *master, Double_t *local)
507 Double_t bomb = GetBomb();
508 Double_t *matrix = &fRotMatrix[GeomLevel()][0];
510 Double_t xms = master[0] - bomb*fX;
511 Double_t yms = master[1] - bomb*fY;
512 Double_t zms = master[2] - bomb*fZ;
514 x = xms*matrix[0] + yms*matrix[1] + zms*matrix[2];
515 y = xms*matrix[3] + yms*matrix[4] + zms*matrix[5];
516 z = xms*matrix[6] + yms*matrix[7] + zms*matrix[8];
518 local[0] = x; local[1] = y; local[2] = z;
521 memcpy(local,master,
sizeof(Double_t)* kVectorSize);
532 void TGeometry::Master2Local(Float_t *master, Float_t *local)
536 Float_t bomb = GetBomb();
538 Double_t *matrix = &fRotMatrix[GeomLevel()][0];
540 Double_t xms = master[0] - bomb*fX;
541 Double_t yms = master[1] - bomb*fY;
542 Double_t zms = master[2] - bomb*fZ;
544 x = xms*matrix[0] + yms*matrix[1] + zms*matrix[2];
545 y = xms*matrix[3] + yms*matrix[4] + zms*matrix[5];
546 z = xms*matrix[6] + yms*matrix[7] + zms*matrix[8];
548 local[0] = x; local[1] = y; local[2] = z;
551 memcpy(local,master,
sizeof(Float_t)* kVectorSize);
557 void TGeometry::Node(
const char *name,
const char *title,
const char *shapename, Double_t x, Double_t y, Double_t z,
const char *matrixname, Option_t *option)
559 new TNode(name,title,shapename,x,y,z,matrixname,option);
565 void TGeometry::RecursiveRemove(TObject *obj)
567 if (fNodes) fNodes->RecursiveRemove(obj);
573 void TGeometry::Streamer(TBuffer &b)
577 Version_t R__v = b.ReadVersion(&R__s, &R__c);
579 b.ReadClassBuffer(TGeometry::Class(),
this, R__v, R__s, R__c);
583 fMaterials->Streamer(b);
584 fMatrices->Streamer(b);
585 fShapes->Streamer(b);
588 b.CheckByteCount(R__s, R__c, TGeometry::IsA());
594 TRotMatrix *onematrix;
596 Int_t nmat = fMaterials->GetSize();
597 if (nmat) fMaterialPointer =
new TMaterial* [nmat];
598 TIter nextmat(fMaterials);
600 while ((onemat = (TMaterial*) nextmat())) {
601 fMaterialPointer[i] = onemat;
605 Int_t nrot = fMatrices->GetSize();
606 if (nrot) fMatrixPointer =
new TRotMatrix* [nrot];
607 TIter nextmatrix(fMatrices);
609 while ((onematrix = (TRotMatrix*) nextmatrix())) {
610 fMatrixPointer[i] = onematrix;
614 Int_t nsha = fShapes->GetSize();
615 if (nsha) fShapePointer =
new TShape* [nsha];
616 TIter nextshape(fShapes);
618 while ((oneshape = (TShape*) nextshape())) {
619 fShapePointer[i] = oneshape;
623 gROOT->GetListOfGeometries()->Add(
this);
625 fCurrentNode = (TNode*)GetListOfNodes()->First();
627 b.WriteClassBuffer(TGeometry::Class(),
this);
635 void TGeometry::UpdateMatrix(TNode *node)
637 TNode *nodes[kMAXLEVELS];
638 for (Int_t i=0;i<kVectorSize;i++) fTranslation[0][i] = 0;
639 for (Int_t i=0;i<kMatrixSize;i++) fRotMatrix[0][i] = 0;
640 fRotMatrix[0][0] = 1; fRotMatrix[0][4] = 1; fRotMatrix[0][8] = 1;
645 nodes[fGeomLevel] = node;
646 node = node->GetParent();
650 Int_t saveGeomLevel = fGeomLevel;
652 for (fGeomLevel=1;fGeomLevel<=saveGeomLevel;fGeomLevel++) {
653 node = nodes[fGeomLevel-1];
654 UpdateTempMatrix(node->GetX(),node->GetY(),node->GetZ(),node->GetMatrix());
661 void TGeometry::UpdateTempMatrix(Double_t x, Double_t y, Double_t z, TRotMatrix *rotMatrix)
663 Double_t *matrix = 0;
664 Bool_t isReflection = kFALSE;
665 if (rotMatrix && rotMatrix->GetType()) {
666 matrix = rotMatrix->GetMatrix();
667 isReflection = rotMatrix->IsReflection();
669 UpdateTempMatrix( x,y,z, matrix,isReflection);
675 void TGeometry::UpdateTempMatrix(Double_t x, Double_t y, Double_t z, Double_t *matrix,Bool_t isReflection)
680 UpdateTempMatrix(&(fTranslation[i-1][0]),&fRotMatrix[i-1][0]
682 ,&fTranslation[i][0],&fRotMatrix[i][0]);
683 fX = fTranslation[i][0];
684 fY = fTranslation[i][1];
685 fZ = fTranslation[i][2];
686 fIsReflection[i] = fIsReflection[i-1] ^ isReflection;
688 fX = fTranslation[i][0] = fTranslation[i-1][0] + x;
689 fY = fTranslation[i][1] = fTranslation[i-1][1] + y;
690 fZ = fTranslation[i][2] = fTranslation[i-1][2] + z;
694 fIsReflection[0] = kFALSE;
695 for (i=0;i<kVectorSize;i++) fTranslation[0][i] = 0;
696 for (i=0;i<kMatrixSize;i++) fRotMatrix[0][i] = 0;
697 fRotMatrix[0][0] = 1; fRotMatrix[0][4] = 1; fRotMatrix[0][8] = 1;
710 void TGeometry::UpdateTempMatrix(Double_t *dx,Double_t *rmat
711 , Double_t x, Double_t y, Double_t z, Double_t *matrix
712 , Double_t *dxnew, Double_t *rmatnew)
714 dxnew[0] = dx[0] + x*rmat[0] + y*rmat[3] + z*rmat[6];
715 dxnew[1] = dx[1] + x*rmat[1] + y*rmat[4] + z*rmat[7];
716 dxnew[2] = dx[2] + x*rmat[2] + y*rmat[5] + z*rmat[8];
718 rmatnew[0] = rmat[0]*matrix[0] + rmat[3]*matrix[1] + rmat[6]*matrix[2];
719 rmatnew[1] = rmat[1]*matrix[0] + rmat[4]*matrix[1] + rmat[7]*matrix[2];
720 rmatnew[2] = rmat[2]*matrix[0] + rmat[5]*matrix[1] + rmat[8]*matrix[2];
721 rmatnew[3] = rmat[0]*matrix[3] + rmat[3]*matrix[4] + rmat[6]*matrix[5];
722 rmatnew[4] = rmat[1]*matrix[3] + rmat[4]*matrix[4] + rmat[7]*matrix[5];
723 rmatnew[5] = rmat[2]*matrix[3] + rmat[5]*matrix[4] + rmat[8]*matrix[5];
724 rmatnew[6] = rmat[0]*matrix[6] + rmat[3]*matrix[7] + rmat[6]*matrix[8];
725 rmatnew[7] = rmat[1]*matrix[6] + rmat[4]*matrix[7] + rmat[7]*matrix[8];
726 rmatnew[8] = rmat[2]*matrix[6] + rmat[5]*matrix[7] + rmat[8]*matrix[8];