LCOV - code coverage report
Current view: top level - MUON/MUONgeometry - AliMUONGeometryDetElement.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 59 124 47.6 %
Date: 2016-06-14 17:26:59 Functions: 16 23 69.6 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : 
      16             : // $Id$
      17             : 
      18             : //-----------------------------------------------------------------------------
      19             : // Class AliMUONGeometryDetElement
      20             : // --------------------------------------
      21             : // The class defines the detection element.
      22             : // Author: Ivana Hrivnacova, IPN Orsay
      23             : //-----------------------------------------------------------------------------
      24             : 
      25             : #include "AliMUONGeometryDetElement.h"
      26             : 
      27             : #include "AliLog.h"
      28             : 
      29             : #include <TGeoMatrix.h>
      30             : #include <Riostream.h>
      31             : 
      32             : #include <sstream>
      33             : 
      34             : using std::cout;
      35             : using std::endl;
      36             : using std::string;
      37             : /// \cond CLASSIMP
      38          18 : ClassImp(AliMUONGeometryDetElement)
      39             : /// \endcond
      40             : 
      41             : //
      42             : // static methods
      43             : //
      44             : 
      45             : //______________________________________________________________________________
      46             : const TString& AliMUONGeometryDetElement::GetDENamePrefix()
      47             : {
      48             :   ///< Geometry DE name prefix
      49        3201 :   static const TString kDENamePrefix = "DE";
      50        1596 :   return kDENamePrefix;
      51           0 : }  
      52             : 
      53             : //______________________________________________________________________________
      54             : TString AliMUONGeometryDetElement::GetDEName(Int_t detElemId)
      55             : {
      56             : /// Return the module name for given moduleId
      57             : 
      58        3192 :   TString deName(GetDENamePrefix());
      59        1596 :   deName += detElemId;
      60             :   return deName;
      61        3192 : }   
      62             : 
      63             : //______________________________________________________________________________
      64             : AliMUONGeometryDetElement::AliMUONGeometryDetElement(Int_t detElemId)
      65         456 :  : TObject(),
      66         456 :    fDEName(GetDEName(detElemId)),
      67         456 :    fVolumePath(),
      68         456 :    fLocalTransformation(0),
      69         456 :    fGlobalTransformation(0)
      70        2280 : { 
      71             : /// Standard constructor
      72             : 
      73         456 :   SetUniqueID(detElemId);
      74         912 : }
      75             : 
      76             : //______________________________________________________________________________
      77             : AliMUONGeometryDetElement::AliMUONGeometryDetElement(
      78             :                                         Int_t detElemId,
      79             :                                         const TString& volumePath)
      80         228 :  : TObject(),
      81         228 :    fDEName(GetDEName(detElemId)),
      82         228 :    fVolumePath(volumePath),
      83         228 :    fLocalTransformation(0),
      84         228 :    fGlobalTransformation(0)
      85        1140 : { 
      86             : /// Standard constructor
      87             : 
      88         228 :   SetUniqueID(detElemId);
      89         456 : }
      90             : 
      91             : //______________________________________________________________________________
      92             : AliMUONGeometryDetElement::AliMUONGeometryDetElement(TRootIOCtor* /*ioCtor*/)
      93        2736 :  : TObject(),
      94        2736 :    fDEName(),
      95        2736 :    fVolumePath(),
      96        2736 :    fLocalTransformation(0),
      97        2736 :    fGlobalTransformation(0)
      98       13680 : {
      99             : /// Root IO constructor
     100        5472 : }
     101             : 
     102             : //______________________________________________________________________________
     103             : AliMUONGeometryDetElement::~AliMUONGeometryDetElement() 
     104       20520 : {
     105             : /// Destructor
     106             : 
     107        6840 :   delete fLocalTransformation;
     108        6840 :   delete fGlobalTransformation;
     109       10260 : }
     110             : 
     111             : //
     112             : // private methods
     113             : //
     114             : 
     115             : //______________________________________________________________________________
     116             : void  AliMUONGeometryDetElement::PrintTransform(
     117             :                                             const TGeoHMatrix* transform) const
     118             : {
     119             : /// Print the detection element transformation
     120             : 
     121           0 :   cout << "DetElemId: " << GetUniqueID();
     122           0 :   cout << "  name: " << fVolumePath << endl;
     123             : 
     124           0 :   if ( !transform ) {
     125           0 :     cout << "    Transformation not defined." << endl;
     126           0 :     return;
     127             :   }  
     128             : 
     129           0 :   const double* translation = transform->GetTranslation();
     130           0 :   cout << "   translation: "
     131             : #if defined (__DECCXX)
     132             :        << translation[0] << ", " 
     133             :        << translation[1] << ", "
     134             :        << translation[2] << endl;
     135             : #else
     136           0 :        << std::fixed
     137           0 :        << std::setw(7) << std::setprecision(4) << translation[0] << ", " 
     138           0 :        << std::setw(7) << std::setprecision(4) << translation[1] << ", "
     139           0 :        << std::setw(7) << std::setprecision(4) << translation[2] << endl;
     140             : #endif
     141             :          
     142           0 :   const double* rotation = transform->GetRotationMatrix();
     143           0 :   cout << "   rotation matrix:  "
     144             : #if defined (__DECCXX)
     145             :        << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
     146             :        << "                     "           
     147             :        << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl         
     148             :        << "                     "           
     149             :        << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
     150             : #else
     151           0 :        << std::fixed
     152           0 :        << std::setw(7) << std::setprecision(4) 
     153           0 :        << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
     154           0 :        << "                     "           
     155           0 :        << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl         
     156           0 :        << "                     "           
     157           0 :        << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
     158             : #endif
     159           0 : }     
     160             : 
     161             : //
     162             : // public methods
     163             : //
     164             : 
     165             : //______________________________________________________________________________
     166             : void  AliMUONGeometryDetElement::Global2Local(
     167             :                                   Float_t xg, Float_t yg, Float_t zg, 
     168             :                                   Float_t& xl, Float_t& yl, Float_t& zl) const
     169             : {
     170             : /// Transform point from the global reference frame (ALIC)
     171             : /// to the local reference frame of this detection element.
     172             : 
     173           0 :   Double_t dxg = xg;
     174           0 :   Double_t dyg = yg;
     175           0 :   Double_t dzg = zg;
     176             : 
     177           0 :   Double_t dxl, dyl, dzl;
     178           0 :   Global2Local(dxg, dyg, dzg, dxl, dyl, dzl);  
     179             :   
     180           0 :   xl = dxl;
     181           0 :   yl = dyl;
     182           0 :   zl = dzl;
     183           0 : }
     184             :                                   
     185             : //______________________________________________________________________________
     186             : void  AliMUONGeometryDetElement::Global2Local(
     187             :                                   Double_t xg, Double_t yg, Double_t zg, 
     188             :                                   Double_t& xl, Double_t& yl, Double_t& zl) const
     189             : {
     190             : /// Transform point from the global reference frame (ALIC)
     191             : /// to the local reference frame of this detection element
     192             : 
     193             :    // Check transformation
     194        4940 :    if (!fGlobalTransformation) {
     195           0 :      AliError(Form("Global transformation for detection element %d not defined.",
     196             :                     GetUniqueID()));
     197           0 :      return;
     198             :    }  
     199             :    
     200             :    // Transform point 
     201        2470 :    Double_t pg[3] = { xg, yg, zg };
     202        2470 :    Double_t pl[3] = { 0., 0., 0. };
     203        2470 :    fGlobalTransformation->MasterToLocal(pg, pl);
     204             :    
     205             :    // Return transformed point
     206        2470 :    xl = pl[0];
     207        2470 :    yl = pl[1];     
     208        2470 :    zl = pl[2];  
     209        4940 : }
     210             :                                   
     211             : //______________________________________________________________________________
     212             : void  AliMUONGeometryDetElement::Local2Global(
     213             :                  Float_t xl, Float_t yl, Float_t zl, 
     214             :                  Float_t& xg, Float_t& yg, Float_t& zg) const
     215             : {
     216             : /// Transform point from the local reference frame of this detection element 
     217             : /// to the global reference frame (ALIC).
     218             : 
     219           0 :   Double_t dxl = xl;
     220           0 :   Double_t dyl = yl;
     221           0 :   Double_t dzl = zl;
     222             : 
     223           0 :   Double_t dxg, dyg, dzg;
     224           0 :   Local2Global(dxl, dyl, dzl, dxg, dyg, dzg);  
     225             :   
     226           0 :   xg = dxg;
     227           0 :   yg = dyg;
     228           0 :   zg = dzg;
     229           0 : }
     230             : 
     231             : //______________________________________________________________________________
     232             : void  AliMUONGeometryDetElement::Local2Global(
     233             :                  Double_t xl, Double_t yl, Double_t zl, 
     234             :                  Double_t& xg, Double_t& yg, Double_t& zg) const
     235             : {
     236             : /// Transform point from the local reference frame of this detection element 
     237             : /// to the global reference frame (ALIC).
     238             : 
     239             :    // Check transformation
     240       60554 :    if (!fGlobalTransformation) {
     241           0 :      AliError(Form("Global transformation for detection element %d not defined.",
     242             :                     GetUniqueID()));
     243           0 :      return;
     244             :    }  
     245             :    
     246             :    // Transform point 
     247       30277 :    Double_t pl[3] = { xl, yl, zl };
     248       30277 :    Double_t pg[3] = { 0., 0., 0. };
     249       30277 :    fGlobalTransformation->LocalToMaster(pl, pg);
     250             :    
     251             :    // Return transformed point
     252       30277 :    xg = pg[0];
     253       30277 :    yg = pg[1];     
     254       30277 :    zg = pg[2];  
     255       60554 : }
     256             : 
     257             : //______________________________________________________________________________
     258             : void AliMUONGeometryDetElement::SetLocalTransformation(
     259             :                                                 const TGeoHMatrix& transform, 
     260             :                                                 Bool_t warn)
     261             : { 
     262             : /// Set local transformation;
     263             : /// give warning if the global transformation is already defined.
     264             :  
     265         912 :   if ( fLocalTransformation ) {
     266         456 :     delete fLocalTransformation;
     267         228 :     if ( warn ) {
     268           0 :       AliWarning("Local transformation already defined was deleted.");
     269           0 :     }  
     270             :   }  
     271             : 
     272        1824 :   fLocalTransformation = new TGeoHMatrix(transform);
     273         912 : }  
     274             :                                               
     275             : //______________________________________________________________________________
     276             : void AliMUONGeometryDetElement::SetGlobalTransformation(
     277             :                                                 const TGeoHMatrix& transform,
     278             :                                                 Bool_t warn)
     279             : { 
     280             : /// Set global transformation;
     281             : /// give warning if the global transformation is already defined.
     282             :  
     283         912 :   if (fGlobalTransformation) {
     284         456 :     delete fGlobalTransformation;
     285         228 :     if ( warn ) {
     286           0 :       AliWarning("Global transformation already defined was deleted.");
     287           0 :     }  
     288             :   }  
     289             : 
     290        1824 :   fGlobalTransformation = new TGeoHMatrix(transform);
     291         912 : }  
     292             :                                               
     293             : //______________________________________________________________________________
     294             : void AliMUONGeometryDetElement::PrintLocalTransform() const
     295             : {
     296             : /// Print detection element relative transformation
     297             : /// (the transformation wrt module frame)
     298             : 
     299           0 :   PrintTransform(fLocalTransformation);
     300           0 : }  
     301             : 
     302             : //______________________________________________________________________________
     303             : void AliMUONGeometryDetElement::PrintGlobalTransform() const
     304             : {
     305             : /// Print detection element global transformation
     306             : /// (the transformation wrt global frame)
     307             : 
     308           0 :   PrintTransform(fGlobalTransformation);
     309           0 : }  
     310             : 
     311             : //______________________________________________________________________________
     312             : TString AliMUONGeometryDetElement::GetVolumeName() const
     313             : { 
     314             : /// Extract volume name from the path
     315             :   
     316           0 :   std::string volPath = fVolumePath.Data();
     317           0 :   std::string::size_type first = volPath.rfind('/')+1;
     318           0 :   std::string::size_type last = volPath.rfind('_');
     319             :   
     320           0 :   return volPath.substr(first, last-first );
     321           0 : }
     322             : 
     323             : //______________________________________________________________________________
     324             : Int_t AliMUONGeometryDetElement::GetVolumeCopyNo() const
     325             : { 
     326             : /// Extract volume copyNo from the path
     327             :   
     328           0 :   string volPath = fVolumePath.Data();
     329           0 :   std::string::size_type first = volPath.rfind('_');
     330           0 :   std::string copyNoStr = volPath.substr(first+1, volPath.length());
     331           0 :   std::istringstream in(copyNoStr);
     332           0 :   Int_t copyNo;
     333           0 :   in >> copyNo;
     334             :   
     335           0 :   return copyNo;
     336           0 : }
     337             : 

Generated by: LCOV version 1.11