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 fLocalManuContours.SetOwnerKeyValue(kTRUE,kTRUE);
68 //_____________________________________________________________________________
69 AliMUONManuContourMaker::~AliMUONManuContourMaker()
73 //_____________________________________________________________________________
75 AliMUONManuContourMaker::CreateManuContour(Int_t detElemId, Int_t manuId, const char* name) const
77 /// Create the contour of a given manu (global coordinates)
83 if ( sname.Length()==0 )
85 sname = ManuPathName(detElemId,manuId);
88 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
89 const AliMpMotifPosition* motifPos = seg->MotifPosition(manuId);
91 AliMUONContour* contour = CreateMotifContour(*motifPos);
95 AliError(Form("Could not build contour %s",sname.Data()));
99 contour->SetName(sname.Data());
101 contour->Offset(motifPos->GetPositionX()-seg->GetPositionX(),
102 motifPos->GetPositionY()-seg->GetPositionY());
104 TGeoHMatrix* matrix = 0x0;
106 if ( fDETransformations )
108 matrix = static_cast<TGeoHMatrix*>(fDETransformations->GetValue(detElemId));
109 if ( matrix ) contour->Transform(*matrix);
116 //_____________________________________________________________________________
118 AliMUONManuContourMaker::CreateMotifContour(const AliMpMotifPosition& motifPosition) const
120 /// Create the contour of a given MOTIF (i.e. local coordinates only).
122 AliCodeTimerAuto("");
124 TString mpName(NameIt(motifPosition));
126 AliMUONContour* contour = static_cast<AliMUONContour*>(fLocalManuContours.GetValue(mpName.Data()));
130 // if we have already done the job, just have to clone it and we are done
131 return static_cast<AliMUONContour*>(contour->Clone());
134 TObjArray polygons(AliMpConstants::ManuNofChannels()); // array of AliMUONPolygon objects
135 polygons.SetOwner(kTRUE);
137 AliMpVMotif* motif = motifPosition.GetMotif();
139 AliMpMotifType* motifType = motif->GetMotifType();
141 if ( motifType->IsFull() )
143 // motif is a simple rectangle. No need to loop over pads, we can
144 // compute the contour right here and now.
145 polygons.Add(new AliMUONPolygon(0.0,0.0,motif->DimensionX(),motif->DimensionY()));
149 for ( Int_t i = 0; i <= AliMpConstants::ManuNofChannels(); ++i )
151 AliMpConnection* connection = motifType->FindConnectionByGassiNum(i);
155 Int_t ix = connection->GetLocalIx();
156 Int_t iy = connection->GetLocalIy();
160 motif->GetPadDimensionsByIndices(ix,iy,dx,dy);
161 motif->PadPositionLocal(ix,iy,x,y);
163 AliMUONPolygon* pol = new AliMUONPolygon(x,y,dx,dy);
169 AliMUONContourMaker maker;
171 contour = maker.CreateContour(polygons);
173 if (!contour || !contour->IsValid() )
175 AliError(Form("Failed to properly create contour %s contour = %p",mpName.Data(),contour));
178 AliError(Form("nofVertices=%d area.isvalid=%d",contour->NumberOfVertices(),contour->Area().IsValid()));
179 StdoutToAliError(contour->Area().Print(););
186 AliCodeTimerAuto("localmanucontour.add");
187 fLocalManuContours.Add(new TObjString(mpName),contour);
190 return static_cast<AliMUONContour*>(contour->Clone());
193 //_____________________________________________________________________________
195 AliMUONManuContourMaker::GenerateManuContours(Bool_t stopAtError)
197 /// Generate the contours for all the manus, taking into account the given transformation
198 /// (to go from local to global). That transformation need not be the real one (i.e.
199 /// it can be an "exploded" one to ease visualization).
201 AliCodeTimerAuto("");
203 TObjArray* manuContours = new TObjArray;
205 manuContours->SetOwner(kTRUE);
207 AliMpManuIterator it;
208 Int_t detElemId, manuId;
212 while ( it.Next(detElemId,manuId) )
215 AliMUONContour* contour = CreateManuContour(detElemId,manuId);
218 manuContours->Add(contour);
230 AliInfo(Form("%d manus. %d contours successfully created",nmanus,nok));
235 //_____________________________________________________________________________
237 AliMUONManuContourMaker::NameIt(const AliMpMotifPosition& motifPosition) const
239 /// Get the name of an AliMpMotifPosition
241 AliMpVMotif* motif = motifPosition.GetMotif();
242 TString name(Form("%s",motif->GetID().Data()));
244 for ( Int_t i = 0; i < motif->GetNofPadDimensions(); ++i )
246 name += Form("/%7.3f-%7.3f:",motif->GetPadDimensionX(i),motif->GetPadDimensionY(i));
252 //_____________________________________________________________________________
254 AliMUONManuContourMaker::ManuPathName(Int_t detElemId, Int_t manuId, Bool_t withCathodeName)
256 /// Get the name of a manu
258 AliMp::PlaneType planeType;
259 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
261 planeType = AliMp::kNonBendingPlane;
265 planeType = AliMp::kBendingPlane;
267 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,planeType);
269 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
270 Int_t stationId = chamberId/2;
272 Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId, manuId);
274 AliMpUID id(cathodeType,stationId,chamberId,detElemId,busPatchId,manuId);
276 if ( withCathodeName ) return id.PathName();
278 TString name(id.PathName());
280 name.ReplaceAll("Cathode0/","");
281 name.ReplaceAll("Cathode1/","");