LCOV - code coverage report
Current view: top level - MUON/MUONgraphics - AliMUONManuContourMaker.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 95 1.1 %
Date: 2016-06-14 17:26:59 Functions: 1 11 9.1 %

          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             : /// \class AliMUONManuContourMaker
      19             : ///
      20             : /// Maker of manu contours. 
      21             : ///
      22             : /// Make use of the AliMUONContourMaker class, but this one contains
      23             : /// specific things for MUON (as the mapping, for instance), hence its
      24             : /// separation from AliMUONContourMaker.
      25             : ///
      26             : /// This class requires that the mapping is loaded before anything can be done.
      27             : ///
      28             : /// \author Laurent Aphecetche, Subatech
      29             : 
      30             : #include "AliMUONManuContourMaker.h"
      31             : 
      32             : #include "AliCodeTimer.h"
      33             : #include "AliLog.h"
      34             : #include "AliMUONContour.h"
      35             : #include "AliMUONContourMaker.h"
      36             : #include "AliMUONPolygon.h"
      37             : #include "AliMpCathodType.h"
      38             : #include "AliMpConnection.h"
      39             : #include "AliMpConstants.h"
      40             : #include "AliMpDDLStore.h"
      41             : #include "AliMpDEManager.h"
      42             : #include "AliMpIntPair.h"
      43             : #include "AliMpMotifPosition.h"
      44             : #include "AliMpMotifType.h"
      45             : #include "AliMpManuIterator.h"
      46             : #include "AliMpPlaneType.h"
      47             : #include "AliMpSegmentation.h"
      48             : #include "AliMpUID.h"
      49             : #include "AliMpVMotif.h"
      50             : #include "AliMpVSegmentation.h"
      51             : #include "TGeoMatrix.h"
      52             : #include "TObjArray.h"
      53             : #include "TObjString.h"
      54             : #include "TString.h"
      55             : #include "TVector2.h"
      56             : 
      57             : ///\cond CLASSIMP
      58          12 : ClassImp(AliMUONManuContourMaker)
      59             : ///\endcond
      60             : 
      61             : //_____________________________________________________________________________
      62             : AliMUONManuContourMaker::AliMUONManuContourMaker(AliMpExMap* deTransformations)
      63           0 : : TObject(), fDETransformations(deTransformations), fLocalManuContours(222,1)
      64           0 : {
      65             : /// Standard constructor
      66             : 
      67           0 :   fLocalManuContours.SetOwnerKeyValue(kTRUE,kTRUE);  
      68           0 : }
      69             : 
      70             : //_____________________________________________________________________________
      71             : AliMUONManuContourMaker::~AliMUONManuContourMaker()
      72           0 : {
      73             : /// Destructor
      74           0 : }
      75             : 
      76             : //_____________________________________________________________________________
      77             : AliMUONContour* 
      78             : AliMUONManuContourMaker::CreateManuContour(Int_t detElemId, Int_t manuId, const char* name) const
      79             : {
      80             :   /// Create the contour of a given manu (global coordinates)
      81             :  
      82           0 :   AliCodeTimerAuto("",0);
      83             :   
      84           0 :   TString sname(name);
      85             :   
      86           0 :   if ( sname.Length()==0 )
      87             :   {
      88           0 :     sname = ManuPathName(detElemId,manuId);
      89           0 :   }
      90             :   
      91           0 :   const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
      92           0 :   const AliMpMotifPosition* motifPos = seg->MotifPosition(manuId);
      93             : 
      94           0 :   AliMUONContour* contour = CreateMotifContour(*motifPos);
      95             :   
      96           0 :   if (!contour)
      97             :   {
      98           0 :     AliError(Form("Could not build contour %s",sname.Data()));
      99           0 :     return 0x0;
     100             :   }
     101             :   
     102           0 :   contour->SetName(sname.Data());
     103             :   
     104           0 :   contour->Offset(motifPos->GetPositionX()-seg->GetPositionX(),
     105           0 :                   motifPos->GetPositionY()-seg->GetPositionY());
     106             :   
     107             :   TGeoHMatrix* matrix = 0x0;
     108             :   
     109           0 :   if ( fDETransformations ) 
     110             :   {
     111           0 :     matrix = static_cast<TGeoHMatrix*>(fDETransformations->GetValue(detElemId));
     112           0 :     if ( matrix ) contour->Transform(*matrix);
     113             :   }
     114             :   
     115             :   return contour;
     116           0 : }
     117             : 
     118             : 
     119             : //_____________________________________________________________________________
     120             : AliMUONContour* 
     121             : AliMUONManuContourMaker::CreateMotifContour(const AliMpMotifPosition& motifPosition) const
     122             : {
     123             :   /// Create the contour of a given MOTIF (i.e. local coordinates only).
     124             :   
     125           0 :   AliCodeTimerAuto("",0);
     126             :   
     127           0 :   TString mpName(NameIt(motifPosition));
     128             :   
     129           0 :   AliMUONContour* contour = static_cast<AliMUONContour*>(fLocalManuContours.GetValue(mpName.Data()));
     130             :   
     131           0 :   if ( contour ) 
     132             :   {
     133             :     // if we have already done the job, just have to clone it and we are done
     134           0 :     return static_cast<AliMUONContour*>(contour->Clone());
     135             :   }
     136             :   
     137           0 :   TObjArray polygons(AliMpConstants::ManuNofChannels()); // array of AliMUONPolygon objects
     138           0 :   polygons.SetOwner(kTRUE);
     139             :   
     140           0 :   AliMpVMotif* motif = motifPosition.GetMotif();
     141             :   
     142           0 :   AliMpMotifType* motifType = motif->GetMotifType();
     143             :   
     144           0 :   if ( motifType->IsFull() ) 
     145             :   {
     146             :     // motif is a simple rectangle. No need to loop over pads, we can
     147             :     // compute the contour right here and now.
     148           0 :     polygons.Add(new AliMUONPolygon(0.0,0.0,motif->DimensionX(),motif->DimensionY()));
     149             :   }
     150             :   else
     151             :   {
     152           0 :     for ( Int_t i = 0; i <= AliMpConstants::ManuNofChannels(); ++i ) 
     153             :     {
     154           0 :       AliMpConnection* connection = motifType->FindConnectionByGassiNum(i);
     155             :       
     156           0 :       if ( connection ) 
     157             :       {
     158           0 :         Int_t ix = connection->GetLocalIx();
     159           0 :         Int_t iy = connection->GetLocalIy();
     160             :         
     161           0 :         Double_t x,y,dx,dy;
     162             :         
     163           0 :         motif->GetPadDimensionsByIndices(ix,iy,dx,dy);
     164           0 :         motif->PadPositionLocal(ix,iy,x,y);
     165             :         
     166           0 :         AliMUONPolygon* pol = new AliMUONPolygon(x,y,dx,dy);
     167           0 :         polygons.Add(pol);
     168           0 :       }
     169             :     }
     170             :   }
     171             :   
     172           0 :   AliMUONContourMaker maker;
     173             :   
     174           0 :   contour = maker.CreateContour(polygons);
     175             :   
     176           0 :   if (!contour || !contour->IsValid() ) 
     177             :   {
     178           0 :     AliError(Form("Failed to properly create contour %s contour = %p",mpName.Data(),contour));
     179           0 :     if ( contour ) 
     180             :     {
     181           0 :       AliError(Form("nofVertices=%d area.isvalid=%d",contour->NumberOfVertices(),contour->Area().IsValid()));
     182           0 :       StdoutToAliError(contour->Area().Print(););
     183           0 :     }
     184           0 :     delete contour;
     185           0 :     return 0x0;
     186             :   }
     187             :   
     188             :   {
     189           0 :     AliCodeTimerAuto("localmanucontour.add",1);
     190           0 :     fLocalManuContours.Add(new TObjString(mpName),contour);
     191           0 :   }
     192             :   
     193           0 :   return static_cast<AliMUONContour*>(contour->Clone());
     194           0 : }
     195             : 
     196             : //_____________________________________________________________________________
     197             : TObjArray* 
     198             : AliMUONManuContourMaker::GenerateManuContours(Bool_t stopAtError)
     199             : {
     200             :   /// Generate the contours for all the manus, taking into account the given transformation
     201             :   /// (to go from local to global). That transformation need not be the real one (i.e.
     202             :   /// it can be an "exploded" one to ease visualization).
     203             :   
     204           0 :   AliCodeTimerAuto("",0);
     205             :   
     206           0 :   TObjArray* manuContours = new TObjArray;
     207             :   
     208           0 :   manuContours->SetOwner(kTRUE);
     209             :   
     210           0 :   AliMpManuIterator it;
     211           0 :   Int_t detElemId, manuId;
     212             :   Int_t nmanus(0);
     213             :   Int_t nok(0);
     214             : 
     215           0 :   while ( it.Next(detElemId,manuId) ) 
     216             :   {
     217           0 :     ++nmanus;
     218           0 :     AliMUONContour* contour = CreateManuContour(detElemId,manuId);
     219           0 :     if (contour)
     220             :     {
     221           0 :       manuContours->Add(contour);
     222             :     }
     223             :     else
     224             :     {
     225           0 :       if ( stopAtError )
     226             :       {
     227           0 :         break;
     228             :       }
     229             :     }
     230           0 :     ++nok;
     231           0 :   }
     232             :   
     233             :   return manuContours;
     234           0 : }
     235             : 
     236             : //_____________________________________________________________________________
     237             : TString
     238             : AliMUONManuContourMaker::NameIt(const AliMpMotifPosition& motifPosition) const
     239             : {
     240             :   /// Get the name of an AliMpMotifPosition
     241             :   
     242           0 :   AliMpVMotif* motif = motifPosition.GetMotif();
     243           0 :   TString name(Form("%s",motif->GetID().Data()));
     244             :   
     245           0 :   for ( Int_t i = 0; i < motif->GetNofPadDimensions(); ++i )
     246             :   {
     247           0 :     name += Form("/%7.3f-%7.3f:",motif->GetPadDimensionX(i),motif->GetPadDimensionY(i));
     248             :   }
     249             :   
     250             :   return name;
     251           0 : }
     252             : 
     253             : //_____________________________________________________________________________
     254             : TString
     255             : AliMUONManuContourMaker::ManuPathName(Int_t detElemId, Int_t manuId, Bool_t withCathodeName)
     256             : {
     257             :   /// Get the name of a manu
     258             :   
     259             :   AliMp::PlaneType planeType;
     260           0 :   if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
     261             :   {
     262             :     planeType = AliMp::kNonBendingPlane;
     263           0 :   }
     264             :   else
     265             :   {
     266             :     planeType = AliMp::kBendingPlane;
     267             :   }
     268           0 :   AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,planeType);
     269             :   
     270           0 :   Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
     271           0 :   Int_t stationId = chamberId/2;
     272             :   
     273           0 :   Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId, manuId);
     274             :   
     275           0 :   AliMpUID id(cathodeType,stationId,chamberId,detElemId,busPatchId,manuId);
     276             :   
     277           0 :   if ( withCathodeName ) return id.PathName();
     278             :   
     279           0 :   TString name(id.PathName());
     280             :   
     281           0 :   name.ReplaceAll("Cathode0/","");
     282           0 :   name.ReplaceAll("Cathode1/","");
     283             :   
     284           0 :   return name;
     285           0 : }
     286             : 
     287             : 
     288             : 
     289             : 

Generated by: LCOV version 1.11