1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 /// \class AliMUONManuContourMaker
20 /// Maker of manu contours.
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.
26 /// This class requires that the mapping is loaded before anything can be done.
28 /// \author Laurent Aphecetche, Subatech
30 #include "AliMUONManuContourMaker.h"
32 #include "AliCodeTimer.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"
49 #include "AliMpVMotif.h"
50 #include "AliMpVSegmentation.h"
51 #include "TGeoMatrix.h"
52 #include "TObjArray.h"
53 #include "TObjString.h"
58 ClassImp(AliMUONManuContourMaker)
61 //_____________________________________________________________________________
62 AliMUONManuContourMaker::AliMUONManuContourMaker(AliMpExMap* deTransformations)
63 : TObject(), fDETransformations(deTransformations), fLocalManuContours(222,1)
65 /// Standard constructor
67 fLocalManuContours.SetOwnerKeyValue(kTRUE,kTRUE);
70 //_____________________________________________________________________________
71 AliMUONManuContourMaker::~AliMUONManuContourMaker()
76 //_____________________________________________________________________________
78 AliMUONManuContourMaker::CreateManuContour(Int_t detElemId, Int_t manuId, const char* name) const
80 /// Create the contour of a given manu (global coordinates)
82 AliCodeTimerAuto("",0);
86 if ( sname.Length()==0 )
88 sname = ManuPathName(detElemId,manuId);
91 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
92 const AliMpMotifPosition* motifPos = seg->MotifPosition(manuId);
94 AliMUONContour* contour = CreateMotifContour(*motifPos);
98 AliError(Form("Could not build contour %s",sname.Data()));
102 contour->SetName(sname.Data());
104 contour->Offset(motifPos->GetPositionX()-seg->GetPositionX(),
105 motifPos->GetPositionY()-seg->GetPositionY());
107 TGeoHMatrix* matrix = 0x0;
109 if ( fDETransformations )
111 matrix = static_cast<TGeoHMatrix*>(fDETransformations->GetValue(detElemId));
112 if ( matrix ) contour->Transform(*matrix);
119 //_____________________________________________________________________________
121 AliMUONManuContourMaker::CreateMotifContour(const AliMpMotifPosition& motifPosition) const
123 /// Create the contour of a given MOTIF (i.e. local coordinates only).
125 AliCodeTimerAuto("",0);
127 TString mpName(NameIt(motifPosition));
129 AliMUONContour* contour = static_cast<AliMUONContour*>(fLocalManuContours.GetValue(mpName.Data()));
133 // if we have already done the job, just have to clone it and we are done
134 return static_cast<AliMUONContour*>(contour->Clone());
137 TObjArray polygons(AliMpConstants::ManuNofChannels()); // array of AliMUONPolygon objects
138 polygons.SetOwner(kTRUE);
140 AliMpVMotif* motif = motifPosition.GetMotif();
142 AliMpMotifType* motifType = motif->GetMotifType();
144 if ( motifType->IsFull() )
146 // motif is a simple rectangle. No need to loop over pads, we can
147 // compute the contour right here and now.
148 polygons.Add(new AliMUONPolygon(0.0,0.0,motif->DimensionX(),motif->DimensionY()));
152 for ( Int_t i = 0; i <= AliMpConstants::ManuNofChannels(); ++i )
154 AliMpConnection* connection = motifType->FindConnectionByGassiNum(i);
158 Int_t ix = connection->GetLocalIx();
159 Int_t iy = connection->GetLocalIy();
163 motif->GetPadDimensionsByIndices(ix,iy,dx,dy);
164 motif->PadPositionLocal(ix,iy,x,y);
166 AliMUONPolygon* pol = new AliMUONPolygon(x,y,dx,dy);
172 AliMUONContourMaker maker;
174 contour = maker.CreateContour(polygons);
176 if (!contour || !contour->IsValid() )
178 AliError(Form("Failed to properly create contour %s contour = %p",mpName.Data(),contour));
181 AliError(Form("nofVertices=%d area.isvalid=%d",contour->NumberOfVertices(),contour->Area().IsValid()));
182 StdoutToAliError(contour->Area().Print(););
189 AliCodeTimerAuto("localmanucontour.add",1);
190 fLocalManuContours.Add(new TObjString(mpName),contour);
193 return static_cast<AliMUONContour*>(contour->Clone());
196 //_____________________________________________________________________________
198 AliMUONManuContourMaker::GenerateManuContours(Bool_t stopAtError)
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).
204 AliCodeTimerAuto("",0);
206 TObjArray* manuContours = new TObjArray;
208 manuContours->SetOwner(kTRUE);
210 AliMpManuIterator it;
211 Int_t detElemId, manuId;
215 while ( it.Next(detElemId,manuId) )
218 AliMUONContour* contour = CreateManuContour(detElemId,manuId);
221 manuContours->Add(contour);
233 AliDebug(1,Form("%d manus. %d contours successfully created",nmanus,nok));
238 //_____________________________________________________________________________
240 AliMUONManuContourMaker::NameIt(const AliMpMotifPosition& motifPosition) const
242 /// Get the name of an AliMpMotifPosition
244 AliMpVMotif* motif = motifPosition.GetMotif();
245 TString name(Form("%s",motif->GetID().Data()));
247 for ( Int_t i = 0; i < motif->GetNofPadDimensions(); ++i )
249 name += Form("/%7.3f-%7.3f:",motif->GetPadDimensionX(i),motif->GetPadDimensionY(i));
255 //_____________________________________________________________________________
257 AliMUONManuContourMaker::ManuPathName(Int_t detElemId, Int_t manuId, Bool_t withCathodeName)
259 /// Get the name of a manu
261 AliMp::PlaneType planeType;
262 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
264 planeType = AliMp::kNonBendingPlane;
268 planeType = AliMp::kBendingPlane;
270 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,planeType);
272 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
273 Int_t stationId = chamberId/2;
275 Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId, manuId);
277 AliMpUID id(cathodeType,stationId,chamberId,detElemId,busPatchId,manuId);
279 if ( withCathodeName ) return id.PathName();
281 TString name(id.PathName());
283 name.ReplaceAll("Cathode0/","");
284 name.ReplaceAll("Cathode1/","");