TGeometry.cxx

Go to the documentation of this file.
00001 // @(#)root/g3d:$Id: TGeometry.cxx 35114 2010-09-02 09:46:45Z matevz $
00002 // Author: Rene Brun   22/09/95
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TROOT.h"
00013 #include "THashList.h"
00014 #include "TObjArray.h"
00015 #include "TGeometry.h"
00016 #include "TNode.h"
00017 #include "TMaterial.h"
00018 #include "TBrowser.h"
00019 #include "TClass.h"
00020 
00021 TGeometry *gGeometry = 0;
00022 
00023 ClassImp(TGeometry)
00024 
00025 
00026 //______________________________________________________________________________
00027 //                    T G E O M E T R Y  description
00028 //                    ==============================
00029 //
00030 //    The Geometry class describes the geometry of a detector.
00031 //    The current implementation supports the GEANT3 style description.
00032 //    A special program provided in the ROOT utilities (toroot) can be used
00033 //    to automatically translate a GEANT detector geometry into a ROOT geometry.
00034 //
00035 //   a Geometry object is entered into the list of geometries into the
00036 //     ROOT main object (see TROOT description) when the TGeometry
00037 //     constructor is invoked.
00038 //   Several geometries may coexist in memory.
00039 //
00040 //   A Geometry object consist of the following linked lists:
00041 //        - the TMaterial list (material definition only).
00042 //        - the TRotmatrix list (Rotation matrices definition only).
00043 //        - the TShape list (volume definition only).
00044 //        - the TNode list assembling all detector elements.
00045 //
00046 //   Only the Build and Draw functions for a geometry are currently supported.
00047 //
00048 //---------------------------------------------------------------------------
00049 //  The conversion program from Geant to Root has been added in the list
00050 //  of utilities in utils directory.(see g2root)
00051 //  The executable module of g2root can be found in $ROOTSYS/bin/g2root.
00052 //
00053 //  To use this conversion program, type the shell command:
00054 //        g2root  geant_rzfile macro_name
00055 //
00056 //  for example
00057 //        g2root na49.geom na49.C
00058 //  will convert the GEANT RZ file na49.geom into a ROOT macro na49.C
00059 //
00060 //  To generate the Geometry structure within Root, do:
00061 //    Root > .x na49.C
00062 //    Root > na49.Draw()
00063 //    Root > wh.x3d()    (this invokes the 3-d Root viewver)
00064 //    Root > TFile gna49("na49.root","NEW")  //open a new root file
00065 //    Root > na49.Write()                    //Write the na49 geometry structure
00066 //    Root > gna49.Write()                   //Write all keys (in this case only one)
00067 //  Note: all keys are also written on closing of the file, gna49.Close or
00068 //  when the program exits, Root closes all open files correctly.
00069 //  Once this file has been written, in a subsequent session, simply do:
00070 //    Root > TFile gna49("na49.root")
00071 //    Root > na49.Draw()
00072 //
00073 //  The figure below shows the geometry above using the x3d viewer.
00074 //  This x3d viewver is invoked by selecting "View x3d" in the View menu
00075 //  of a canvas (See example of this tool bar in TCanvas).
00076 //Begin_Html
00077 /*
00078 <img src="gif/na49.gif">
00079 */
00080 //End_Html
00081 
00082 
00083 //______________________________________________________________________________
00084 TGeometry::TGeometry()
00085 {
00086    // Geometry default constructor.
00087 
00088    fMaterials       = new THashList(100,3);
00089    fMatrices        = new THashList(100,3);
00090    fShapes          = new THashList(500,3);
00091    fNodes           = new TList;
00092    fCurrentNode     = 0;
00093    fMaterialPointer = 0;
00094    fMatrixPointer   = 0;
00095    fShapePointer    = 0;
00096    gGeometry = this;
00097    fBomb            = 1;
00098    fMatrix          = 0;
00099    fX=fY=fZ         =0.0;
00100    fGeomLevel       =0;
00101    fIsReflection[fGeomLevel] = kFALSE;
00102 }
00103 
00104 
00105 //______________________________________________________________________________
00106 TGeometry::TGeometry(const char *name,const char *title ) : TNamed (name, title)
00107 {
00108    // Geometry normal constructor.
00109 
00110    fMaterials       = new THashList(1000,3);
00111    fMatrices        = new THashList(1000,3);
00112    fShapes          = new THashList(5000,3);
00113    fNodes           = new TList;
00114    fCurrentNode     = 0;
00115    fMaterialPointer = 0;
00116    fMatrixPointer   = 0;
00117    fShapePointer    = 0;
00118    gGeometry = this;
00119    fBomb            = 1;
00120    fMatrix          = 0;
00121    fX=fY=fZ         =0.0;
00122    gROOT->GetListOfGeometries()->Add(this);
00123    fGeomLevel       =0;
00124    fIsReflection[fGeomLevel] = kFALSE;
00125 }
00126 
00127 //______________________________________________________________________________
00128 TGeometry::TGeometry(const TGeometry& geo) :
00129   TNamed(geo),
00130   fMaterials(geo.fMaterials),
00131   fMatrices(geo.fMatrices),
00132   fShapes(geo.fShapes),
00133   fNodes(geo.fNodes),
00134   fMatrix(geo.fMatrix),
00135   fCurrentNode(geo.fCurrentNode),
00136   fMaterialPointer(geo.fMaterialPointer),
00137   fMatrixPointer(geo.fMatrixPointer),
00138   fShapePointer(geo.fShapePointer),
00139   fBomb(geo.fBomb),
00140   fGeomLevel(geo.fGeomLevel),
00141   fX(geo.fX),
00142   fY(geo.fY),
00143   fZ(geo.fZ)
00144 {
00145    //copy constructor
00146    for(Int_t i=0; i<kMAXLEVELS; i++) {
00147       for(Int_t j=0; j<kVectorSize; j++) 
00148          fTranslation[i][j]=geo.fTranslation[i][j];
00149       for(Int_t j=0; j<kMatrixSize; j++) 
00150          fRotMatrix[i][j]=geo.fRotMatrix[i][j];
00151       fIsReflection[i]=geo.fIsReflection[i];
00152    }
00153 }
00154 
00155 //______________________________________________________________________________
00156 TGeometry& TGeometry::operator=(const TGeometry& geo)
00157 {
00158    //assignement operator
00159    if(this!=&geo) {
00160       TNamed::operator=(geo);
00161       fMaterials=geo.fMaterials;
00162       fMatrices=geo.fMatrices;
00163       fShapes=geo.fShapes;
00164       fNodes=geo.fNodes;
00165       fMatrix=geo.fMatrix;
00166       fCurrentNode=geo.fCurrentNode;
00167       fMaterialPointer=geo.fMaterialPointer;
00168       fMatrixPointer=geo.fMatrixPointer;
00169       fShapePointer=geo.fShapePointer;
00170       fBomb=geo.fBomb;
00171       fGeomLevel=geo.fGeomLevel;
00172       fX=geo.fX;
00173       fY=geo.fY;
00174       fZ=geo.fZ;
00175       for(Int_t i=0; i<kMAXLEVELS; i++) {
00176          for(Int_t j=0; j<kVectorSize; j++) 
00177             fTranslation[i][j]=geo.fTranslation[i][j];
00178          for(Int_t j=0; j<kMatrixSize; j++) 
00179             fRotMatrix[i][j]=geo.fRotMatrix[i][j];
00180          fIsReflection[i]=geo.fIsReflection[i];
00181       }
00182    } 
00183    return *this;
00184 }
00185 
00186 //______________________________________________________________________________
00187 TGeometry::~TGeometry()
00188 {
00189    // Geometry default destructor.
00190 
00191    if (!fMaterials) return;
00192    fMaterials->Delete();
00193    fMatrices->Delete();
00194    fShapes->Delete();
00195    fNodes->Delete();
00196    delete fMaterials;
00197    delete fMatrices;
00198    delete fShapes;
00199    delete fNodes;
00200    delete [] fMaterialPointer;
00201    delete [] fMatrixPointer;
00202    delete [] fShapePointer;
00203    fMaterials       = 0;
00204    fMatrices        = 0;
00205    fShapes          = 0;
00206    fNodes           = 0;
00207    fMaterialPointer = 0;
00208    fMatrixPointer   = 0;
00209    fShapePointer    = 0;
00210 
00211    if (gGeometry == this) {
00212       gGeometry = (TGeometry*) gROOT->GetListOfGeometries()->First();
00213       if (gGeometry == this)
00214          gGeometry = (TGeometry*) gROOT->GetListOfGeometries()->After(gGeometry);
00215    }
00216    gROOT->GetListOfGeometries()->Remove(this);
00217 }
00218 
00219 
00220 //______________________________________________________________________________
00221 void TGeometry::Browse(TBrowser *b)
00222 {
00223    // Browse.
00224 
00225    if( b ) {
00226       b->Add( fMaterials, "Materials" );
00227       b->Add( fMatrices, "Rotation Matrices" );
00228       b->Add( fShapes, "Shapes" );
00229       b->Add( fNodes, "Nodes" );
00230    }
00231 }
00232 
00233 
00234 //______________________________________________________________________________
00235 void TGeometry::cd(const char *)
00236 {
00237    // Change Current Geometry to this.
00238 
00239    gGeometry = this;
00240 }
00241 
00242 
00243 //______________________________________________________________________________
00244 void TGeometry::Draw(Option_t *option)
00245 {
00246    // Draw this Geometry.
00247 
00248    TNode *node1 = (TNode*)fNodes->First();
00249    if (node1) node1->Draw(option);
00250 
00251 }
00252 
00253 
00254 //______________________________________________________________________________
00255 TObject *TGeometry::FindObject(const TObject *) const
00256 {
00257    // Find object in a geometry node, material, etc
00258 
00259    Error("FindObject","Not yet implemented");
00260    return 0;
00261 }
00262 
00263 
00264 //______________________________________________________________________________
00265 TObject *TGeometry::FindObject(const char *name) const
00266 {
00267    // Search object identified by name in the geometry tree
00268 
00269    TObjArray *loc = TGeometry::Get(name);
00270    if (loc) return loc->At(0);
00271    return 0;
00272 }
00273 
00274 
00275 //______________________________________________________________________________
00276 TObjArray *TGeometry::Get(const char *name)
00277 {
00278    // Static function called by TROOT to search name in the geometry.
00279    // Returns a TObjArray containing a pointer to the found object
00280    // and a pointer to the container where the object was found.
00281 
00282    static TObjArray *locs = 0;
00283    if (!locs) locs = new TObjArray(2);
00284    TObjArray &loc = *locs;
00285    loc[0] = 0;
00286    loc[1] = 0;
00287 
00288    if (!gGeometry) return &loc;
00289 
00290    TObject *temp;
00291    TObject *where;
00292 
00293    temp  = gGeometry->GetListOfMaterials()->FindObject(name);
00294    where = gGeometry->GetListOfMaterials();
00295 
00296    if (!temp) {
00297       temp  = gGeometry->GetListOfShapes()->FindObject(name);
00298       where = gGeometry->GetListOfShapes();
00299    }
00300    if (!temp) {
00301       temp  = gGeometry->GetListOfMatrices()->FindObject(name);
00302       where = gGeometry->GetListOfMatrices();
00303    }
00304    if (!temp) {
00305       temp  = gGeometry->GetNode(name);
00306       where = gGeometry;
00307    }
00308    loc[0] = temp;
00309    loc[1] = where;
00310 
00311    return &loc;
00312 }
00313 
00314 
00315 //______________________________________________________________________________
00316 TMaterial *TGeometry::GetMaterial(const char *name) const
00317 {
00318    // Return pointer to Material with name.
00319 
00320    return (TMaterial*)fMaterials->FindObject(name);
00321 }
00322 
00323 
00324 //______________________________________________________________________________
00325 TMaterial *TGeometry::GetMaterialByNumber(Int_t number) const
00326 {
00327    // Return pointer to Material with number.
00328 
00329    TMaterial *mat;
00330    if (number < 0 || number >= fMaterials->GetSize()) return 0;
00331    if (fMaterialPointer)  return fMaterialPointer[number];
00332    TIter next(fMaterials);
00333    while ((mat = (TMaterial*) next())) {
00334       if (mat->GetNumber() == number) return mat;
00335    }
00336    return 0;
00337 }
00338 
00339 
00340 //______________________________________________________________________________
00341 TNode *TGeometry::GetNode(const char *name) const
00342 {
00343    // Return pointer to node with name in the geometry tree.
00344 
00345    TNode *node= (TNode*)GetListOfNodes()->First();
00346    if (!node) return 0;
00347    if (node->TestBit(kNotDeleted))  return node->GetNode(name);
00348    return 0;
00349 }
00350 
00351 
00352 //______________________________________________________________________________
00353 TRotMatrix *TGeometry::GetRotMatrix(const char *name) const
00354 {
00355    // Return pointer to RotMatrix with name.
00356 
00357    return (TRotMatrix*)fMatrices->FindObject(name);
00358 }
00359 
00360 
00361 //______________________________________________________________________________
00362 TRotMatrix *TGeometry::GetRotMatrixByNumber(Int_t number) const
00363 {
00364    // Return pointer to RotMatrix with number.
00365 
00366    TRotMatrix *matrix;
00367    if (number < 0 || number >= fMatrices->GetSize()) return 0;
00368    if (fMatrixPointer)  return fMatrixPointer[number];
00369    TIter next(fMatrices);
00370    while ((matrix = (TRotMatrix*) next())) {
00371       if (matrix->GetNumber() == number) return matrix;
00372    }
00373    return 0;
00374 }
00375 
00376 
00377 //______________________________________________________________________________
00378 TShape *TGeometry::GetShape(const char *name) const
00379 {
00380    // Return pointer to Shape with name.
00381 
00382    return (TShape*)fShapes->FindObject(name);
00383 }
00384 
00385 
00386 //______________________________________________________________________________
00387 TShape *TGeometry::GetShapeByNumber(Int_t number) const
00388 {
00389    // Return pointer to Shape with number.
00390 
00391    TShape *shape;
00392    if (number < 0 || number >= fShapes->GetSize()) return 0;
00393    if (fShapePointer)  return fShapePointer[number];
00394    TIter next(fShapes);
00395    while ((shape = (TShape*) next())) {
00396       if (shape->GetNumber() == number) return shape;
00397    }
00398    return 0;
00399 }
00400 
00401 
00402 //______________________________________________________________________________
00403 void TGeometry::Local2Master(Double_t *local, Double_t *master)
00404 {
00405    // Convert one point from local system to master reference system.
00406    //
00407    //  Note that before invoking this function, the global rotation matrix
00408    //  and translation vector for this node must have been computed.
00409    //  This is automatically done by the Paint functions.
00410    //  Otherwise TNode::UpdateMatrix should be called before.
00411 
00412    if (GeomLevel()) {
00413       Double_t x,y,z;
00414       Double_t bomb = GetBomb();
00415       Double_t *matrix = &fRotMatrix[GeomLevel()][0];
00416       x = bomb*fX
00417         + local[0]*matrix[0]
00418         + local[1]*matrix[3]
00419         + local[2]*matrix[6];
00420 
00421       y = bomb*fY
00422         + local[0]*matrix[1]
00423         + local[1]*matrix[4]
00424         + local[2]*matrix[7];
00425 
00426       z = bomb*fZ
00427         + local[0]*matrix[2]
00428         + local[1]*matrix[5]
00429         + local[2]*matrix[8];
00430       master[0] = x; master[1] = y; master[2] = z;
00431    }
00432    else 
00433       for (Int_t i=0;i<3;i++) master[i] = local[i];
00434 }
00435 
00436 
00437 //______________________________________________________________________________
00438 void TGeometry::Local2Master(Float_t *local, Float_t *master)
00439 {
00440    // Convert one point from local system to master reference system.
00441    //
00442    //  Note that before invoking this function, the global rotation matrix
00443    //  and translation vector for this node must have been computed.
00444    //  This is automatically done by the Paint functions.
00445    //  Otherwise TNode::UpdateMatrix should be called before.
00446 
00447    if (GeomLevel()) {
00448       Float_t x,y,z;
00449       Float_t bomb = GetBomb();
00450  
00451       Double_t *matrix = &fRotMatrix[GeomLevel()][0];
00452  
00453       x = bomb*fX
00454         + local[0]*matrix[0]
00455         + local[1]*matrix[3]
00456         + local[2]*matrix[6];
00457  
00458       y = bomb*fY
00459         + local[0]*matrix[1]
00460         + local[1]*matrix[4]
00461         + local[2]*matrix[7];
00462  
00463       z = bomb*fZ
00464         + local[0]*matrix[2]
00465         + local[1]*matrix[5]
00466         + local[2]*matrix[8];
00467  
00468       master[0] = x; master[1] = y; master[2] = z;
00469    }
00470    else
00471       for (Int_t i=0;i<3;i++) master[i] = local[i];
00472 }
00473 
00474 
00475 //______________________________________________________________________________
00476 void TGeometry::ls(Option_t *option) const
00477 {
00478    // List this geometry.
00479 
00480    TString opt = option;
00481    opt.ToLower();
00482    if (opt.Contains("m")) {
00483       Printf("=================List of Materials================");
00484       fMaterials->ls(option);
00485    }
00486    if (opt.Contains("r")) {
00487       Printf("=================List of RotationMatrices================");
00488       fMatrices->ls(option);
00489    }
00490    if (opt.Contains("s")) {
00491       Printf("=================List of Shapes==========================");
00492       fShapes->ls(option);
00493    }
00494    if (opt.Contains("n")) {
00495       Printf("=================List of Nodes===========================");
00496       fNodes->ls(option);
00497    }
00498 }
00499 
00500 
00501 //______________________________________________________________________________
00502 void TGeometry::Master2Local(Double_t *master, Double_t *local)
00503 {
00504    // Convert one point from master system to local reference system.
00505    //
00506    //  Note that before invoking this function, the global rotation matrix
00507    //  and translation vector for this node must have been computed.
00508    //  This is automatically done by the Paint functions.
00509    //  Otherwise TNode::UpdateMatrix should be called before.
00510 
00511    if (GeomLevel()) {
00512       Double_t x,y,z;
00513       Double_t bomb = GetBomb();
00514       Double_t *matrix = &fRotMatrix[GeomLevel()][0];
00515 
00516       Double_t xms = master[0] - bomb*fX;
00517       Double_t yms = master[1] - bomb*fY;
00518       Double_t zms = master[2] - bomb*fZ;
00519 
00520       x = xms*matrix[0] + yms*matrix[1] + zms*matrix[2];
00521       y = xms*matrix[3] + yms*matrix[4] + zms*matrix[5];
00522       z = xms*matrix[6] + yms*matrix[7] + zms*matrix[8];
00523 
00524       local[0] = x; local[1] = y; local[2] = z;
00525    }
00526    else
00527       memcpy(local,master,sizeof(Double_t)* kVectorSize);
00528 }
00529 
00530 
00531 //______________________________________________________________________________
00532 void TGeometry::Master2Local(Float_t *master, Float_t *local)
00533 {
00534    // Convert one point from master system to local reference system.
00535    //
00536    //  Note that before invoking this function, the global rotation matrix
00537    //  and translation vector for this node must have been computed.
00538    //  This is automatically done by the Paint functions.
00539    //  Otherwise TNode::UpdateMatrix should be called before.
00540 
00541    if (GeomLevel()) {
00542       Float_t x,y,z;
00543       Float_t bomb = GetBomb();
00544 
00545       Double_t *matrix = &fRotMatrix[GeomLevel()][0];
00546 
00547       Double_t xms = master[0] - bomb*fX;
00548       Double_t yms = master[1] - bomb*fY;
00549       Double_t zms = master[2] - bomb*fZ;
00550 
00551       x = xms*matrix[0] + yms*matrix[1] + zms*matrix[2];
00552       y = xms*matrix[3] + yms*matrix[4] + zms*matrix[5];
00553       z = xms*matrix[6] + yms*matrix[7] + zms*matrix[8];
00554 
00555       local[0] = x; local[1] = y; local[2] = z;
00556    }
00557    else
00558       memcpy(local,master,sizeof(Float_t)* kVectorSize);
00559 }
00560 
00561 
00562 //______________________________________________________________________________
00563 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)
00564 {
00565    // Add a node to the current node in this geometry.
00566 
00567    new TNode(name,title,shapename,x,y,z,matrixname,option);
00568 }
00569 
00570 
00571 //______________________________________________________________________________
00572 void TGeometry::RecursiveRemove(TObject *obj)
00573 {
00574    // Recursively remove object from a Geometry list.
00575 
00576    if (fNodes) fNodes->RecursiveRemove(obj);
00577 }
00578 
00579 
00580 //______________________________________________________________________________
00581 void TGeometry::Streamer(TBuffer &b)
00582 {
00583    // Stream a class object.
00584 
00585    if (b.IsReading()) {
00586       UInt_t R__s, R__c;
00587       Version_t R__v = b.ReadVersion(&R__s, &R__c);
00588       if (R__v > 1) {
00589          b.ReadClassBuffer(TGeometry::Class(), this, R__v, R__s, R__c);
00590       } else {
00591          //====process old versions before automatic schema evolution
00592          TNamed::Streamer(b);
00593          fMaterials->Streamer(b);
00594          fMatrices->Streamer(b);
00595          fShapes->Streamer(b);
00596          fNodes->Streamer(b);
00597          b >> fBomb;
00598          b.CheckByteCount(R__s, R__c, TGeometry::IsA());
00599          //====end of old versions
00600       }
00601       // Build direct access pointers to individual materials,matrices and shapes
00602       Int_t i;
00603       TMaterial *onemat;
00604       TRotMatrix *onematrix;
00605       TShape *oneshape;
00606       Int_t nmat = fMaterials->GetSize();
00607       if (nmat) fMaterialPointer = new TMaterial* [nmat];
00608       TIter nextmat(fMaterials);
00609       i = 0;
00610       while ((onemat = (TMaterial*) nextmat())) {
00611          fMaterialPointer[i] = onemat;
00612          i++;
00613       }
00614 
00615       Int_t nrot = fMatrices->GetSize();
00616       if (nrot) fMatrixPointer = new TRotMatrix* [nrot];
00617       TIter nextmatrix(fMatrices);
00618       i = 0;
00619       while ((onematrix = (TRotMatrix*) nextmatrix())) {
00620          fMatrixPointer[i] = onematrix;
00621          i++;
00622       }
00623 
00624       Int_t nsha = fShapes->GetSize();
00625       if (nsha) fShapePointer = new TShape* [nsha];
00626       TIter nextshape(fShapes);
00627       i = 0;
00628       while ((oneshape = (TShape*) nextshape())) {
00629          fShapePointer[i] = oneshape;
00630          i++;
00631       }
00632 
00633       gROOT->GetListOfGeometries()->Add(this);
00634 
00635       fCurrentNode = (TNode*)GetListOfNodes()->First();
00636    } else {
00637       b.WriteClassBuffer(TGeometry::Class(),this);
00638    }
00639 }
00640 
00641 
00642 //______________________________________________________________________________
00643 void TGeometry::UpdateMatrix(TNode *node)
00644 {
00645    // Update global rotation matrix/translation vector for this node
00646    // this function must be called before invoking Local2Master
00647 
00648    TNode *nodes[kMAXLEVELS];
00649    for (Int_t i=0;i<kVectorSize;i++) fTranslation[0][i] = 0;
00650    for (Int_t i=0;i<kMatrixSize;i++) fRotMatrix[0][i] = 0;
00651    fRotMatrix[0][0] = 1;   fRotMatrix[0][4] = 1;   fRotMatrix[0][8] = 1;
00652 
00653    fGeomLevel  = 0;
00654    //build array of parent nodes
00655    while (node) {
00656       nodes[fGeomLevel] = node;
00657       node = node->GetParent();
00658       fGeomLevel++;
00659    }
00660    fGeomLevel--;
00661    Int_t saveGeomLevel = fGeomLevel;
00662    //Update matrices in the hierarchy
00663    for (fGeomLevel=1;fGeomLevel<=saveGeomLevel;fGeomLevel++) {
00664       node = nodes[fGeomLevel-1];
00665       UpdateTempMatrix(node->GetX(),node->GetY(),node->GetZ(),node->GetMatrix());
00666    }
00667 }
00668 
00669 
00670 //______________________________________________________________________________
00671 void TGeometry::UpdateTempMatrix(Double_t x, Double_t y, Double_t z, TRotMatrix *rotMatrix)
00672 {
00673    // Update temp matrix.
00674 
00675    Double_t *matrix = 0;
00676    Bool_t isReflection = kFALSE;
00677    if (rotMatrix && rotMatrix->GetType()) {
00678       matrix = rotMatrix->GetMatrix();
00679       isReflection = rotMatrix->IsReflection();
00680    }
00681    UpdateTempMatrix( x,y,z, matrix,isReflection);
00682 }
00683 
00684 
00685 //______________________________________________________________________________
00686 void TGeometry::UpdateTempMatrix(Double_t x, Double_t y, Double_t z, Double_t *matrix,Bool_t isReflection)
00687 {
00688    // Update temp matrix.
00689 
00690    Int_t i=GeomLevel();
00691    if (i) {
00692       if(matrix) {
00693          UpdateTempMatrix(&(fTranslation[i-1][0]),&fRotMatrix[i-1][0]
00694                           ,x,y,z,matrix
00695                           ,&fTranslation[i][0],&fRotMatrix[i][0]);
00696          fX = fTranslation[i][0];
00697          fY = fTranslation[i][1];
00698          fZ = fTranslation[i][2];
00699          fIsReflection[i] = fIsReflection[i-1] ^ isReflection;
00700       } else {
00701          fX = fTranslation[i][0] = fTranslation[i-1][0] + x;
00702          fY = fTranslation[i][1] = fTranslation[i-1][1] + y;
00703          fZ = fTranslation[i][2] = fTranslation[i-1][2] + z;
00704       }
00705    } else {
00706       fX=fY=fZ=0;
00707       fIsReflection[0] = kFALSE;
00708       for (i=0;i<kVectorSize;i++) fTranslation[0][i] = 0;
00709       for (i=0;i<kMatrixSize;i++) fRotMatrix[0][i] = 0;
00710       fRotMatrix[0][0] = 1;   fRotMatrix[0][4] = 1;   fRotMatrix[0][8] = 1;
00711    }
00712 }
00713 
00714 
00715 //______________________________________________________________________________
00716 void TGeometry::UpdateTempMatrix(Double_t *dx,Double_t *rmat
00717                          , Double_t x, Double_t y, Double_t z, Double_t *matrix
00718                          , Double_t *dxnew, Double_t *rmatnew)
00719 {
00720    // Compute new translation vector and global matrix.
00721    //
00722    //  dx      old translation vector
00723    //  rmat    old global matrix
00724    //  x,y,z   offset of new local system with respect to mother
00725    //  dxnew   new translation vector
00726    //  rmatnew new global rotation matrix
00727 
00728    dxnew[0] = dx[0] + x*rmat[0] + y*rmat[3] + z*rmat[6];
00729    dxnew[1] = dx[1] + x*rmat[1] + y*rmat[4] + z*rmat[7];
00730    dxnew[2] = dx[2] + x*rmat[2] + y*rmat[5] + z*rmat[8];
00731 
00732    rmatnew[0] = rmat[0]*matrix[0] + rmat[3]*matrix[1] + rmat[6]*matrix[2];
00733    rmatnew[1] = rmat[1]*matrix[0] + rmat[4]*matrix[1] + rmat[7]*matrix[2];
00734    rmatnew[2] = rmat[2]*matrix[0] + rmat[5]*matrix[1] + rmat[8]*matrix[2];
00735    rmatnew[3] = rmat[0]*matrix[3] + rmat[3]*matrix[4] + rmat[6]*matrix[5];
00736    rmatnew[4] = rmat[1]*matrix[3] + rmat[4]*matrix[4] + rmat[7]*matrix[5];
00737    rmatnew[5] = rmat[2]*matrix[3] + rmat[5]*matrix[4] + rmat[8]*matrix[5];
00738    rmatnew[6] = rmat[0]*matrix[6] + rmat[3]*matrix[7] + rmat[6]*matrix[8];
00739    rmatnew[7] = rmat[1]*matrix[6] + rmat[4]*matrix[7] + rmat[7]*matrix[8];
00740    rmatnew[8] = rmat[2]*matrix[6] + rmat[5]*matrix[7] + rmat[8]*matrix[8];
00741 }

Generated on Tue Jul 5 14:16:40 2011 for ROOT_528-00b_version by  doxygen 1.5.1