]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpSlatSegmentation.cxx
New class - the factory for building mapping segmentations
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSlatSegmentation.cxx
CommitLineData
dee1d5f1 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$
0b91d34d 17// $MpId: AliMpSlatSegmentation.cxx,v 1.5 2005/10/28 15:26:01 ivana Exp $
dee1d5f1 18
1964cd2e 19// Caution !!
20// Implementation note.
21// The position(s) used in the interface are supposed to be relative
22// to the slat center (AliMpSlat::Position()), whereas internally
23// the x,y are relative to bottom-left corner.
24
dee1d5f1 25#include "AliMpSlatSegmentation.h"
26
27#include "AliLog.h"
1964cd2e 28#include "AliMpArea.h"
dee1d5f1 29#include "AliMpConnection.h"
30#include "AliMpMotif.h"
31#include "AliMpMotifPosition.h"
32#include "AliMpMotifType.h"
33#include "AliMpPCB.h"
34#include "AliMpSlat.h"
35#include "AliMpSlatPadIterator.h"
36
37ClassImp(AliMpSlatSegmentation)
38
39//_____________________________________________________________________________
40AliMpSlatSegmentation::AliMpSlatSegmentation()
41: AliMpVSegmentation(),
42fkSlat(0)
43{
44 //
45 // Default ctor. Not to be used really.
46 //
47 AliDebug(1,Form("this=%p Empty ctor",this));
48}
49
50//_____________________________________________________________________________
51AliMpSlatSegmentation::AliMpSlatSegmentation(const AliMpSlat* slat)
52: AliMpVSegmentation(),
53fkSlat(slat)
54{
55 //
56 // Normal ctor.
57 //
58 AliDebug(1,Form("this=%p Normal ctor slat=%p",this,slat));
59}
60
61//_____________________________________________________________________________
62AliMpSlatSegmentation::~AliMpSlatSegmentation()
63{
64 //
65 // Dtor (empty).
66 //
0b91d34d 67 // Int_t i(0);//just to be able to put a breakpoint in gdb
dee1d5f1 68 AliDebug(1,Form("this=%p",this));
69}
70
71//_____________________________________________________________________________
72AliMpVPadIterator*
73AliMpSlatSegmentation::CreateIterator(const AliMpArea& area) const
74{
75 //
76 // Returns an iterator to loop over the pad contained within given area.
77 //
1964cd2e 78 AliMpArea a(area.Position()+fkSlat->Position(),area.Dimensions());
79 return new AliMpSlatPadIterator(fkSlat,a);
dee1d5f1 80}
81
1faed5a9 82//_____________________________________________________________________________
83const char*
84AliMpSlatSegmentation::GetName() const
85{
86 TString name("SlatSegmentation");
87 if ( fkSlat)
88 {
89 name += ".";
90 name += fkSlat->GetName();
91 }
92 return name.Data();
93}
94
dee1d5f1 95//_____________________________________________________________________________
96Bool_t
97AliMpSlatSegmentation::HasPad(const AliMpIntPair& indices) const
98{
99 //
100 // Test if this slat has a pad located at the position referenced
101 // by the integer indices.
102 //
103
104 return PadByIndices(indices,kFALSE) != AliMpPad::Invalid();
105}
106
107//_____________________________________________________________________________
108Int_t
109AliMpSlatSegmentation::MaxPadIndexX()
110{
111 //
112 // Returns the value of the largest pad index in x-direction.
113 //
114
16e8fffd 115 return fkSlat->GetMaxPadIndexX();
dee1d5f1 116}
117
118//_____________________________________________________________________________
119Int_t
120AliMpSlatSegmentation::MaxPadIndexY()
121{
122 //
123 // Returns the value of the largest pad index in y-direction.
124 //
125
126 return fkSlat->GetMaxNofPadsY()-1;
127}
128
129//_____________________________________________________________________________
130AliMpPad
131AliMpSlatSegmentation::PadByLocation(const AliMpIntPair& location,
132 Bool_t warning) const
133{
134 //
135 // Returns the pad specified by its location, where location is the
136 // pair (ManuID,ManuChannel).
137 // If warning=kTRUE and the pad does not exist, a warning message is
138 // printed.
139 //
140 // AliMpPad::Invalid() is returned if there's no pad at the given location.
141 //
142 Int_t manuID = location.GetFirst();
143
144 AliMpMotifPosition* motifPos = fkSlat->FindMotifPosition(manuID);
145
146 if (!motifPos)
147 {
148 if (warning)
149 {
150 AliWarning(Form("Manu ID %d not found in slat %s",
151 manuID, fkSlat->GetID()));
1faed5a9 152 }
153 return AliMpPad::Invalid();
dee1d5f1 154 }
155 AliMpVMotif* motif = motifPos->GetMotif();
156 AliMpIntPair localIndices =
157 motif->GetMotifType()->FindLocalIndicesByGassiNum(location.GetSecond());
158
159 if (!localIndices.IsValid())
160 {
161 if (warning)
162 {
163 AliWarning(Form("The pad number %d doesn't exists",
164 location.GetSecond()));
165 }
166 return AliMpPad::Invalid();
167 }
168
169 return AliMpPad(location,
170 motifPos->GlobalIndices(localIndices),
1faed5a9 171 motifPos->Position()
172 + motif->PadPositionLocal(localIndices)
173 - fkSlat->Position(),
174 motif->GetPadDimensions(localIndices));
dee1d5f1 175}
176
177//_____________________________________________________________________________
178AliMpPad
179AliMpSlatSegmentation::PadByIndices(const AliMpIntPair& indices,
180 Bool_t warning) const
181{
182 //
183 // Returns the pad specified by its integer indices.
184 // If warning=kTRUE and the pad does not exist, a warning message is
185 // printed.
186 //
187 // AliMpPad::Invalid() is returned if there's no pad at the given location.
188 //
189 //
190 // FIXME: except for the FindMotifPosition below, this method
191 // is exactly as the one in AliMpSectorSegmentation.
192 // See if we can merge them somehow.
193
194 AliMpMotifPosition* motifPos = fkSlat->FindMotifPosition(indices.GetFirst(),
195 indices.GetSecond());
196 if (!motifPos)
197 {
198 if ( warning )
199 {
200 AliWarning(Form("No motif found containing pad location (%d,%d)",
201 indices.GetFirst(),indices.GetSecond()));
202 }
203 return AliMpPad::Invalid();
204 }
205
206 AliMpVMotif* motif = motifPos->GetMotif();
207 AliMpMotifType* motifType = motif->GetMotifType();
208 AliMpIntPair localIndices(indices-motifPos->GetLowIndicesLimit());
1faed5a9 209 AliMpConnection* connection = motifType->FindConnectionByLocalIndices(localIndices);
dee1d5f1 210
211 if (!connection)
212 {
213 if ( warning )
214 {
215 AliWarning(Form("No connection for pad location (%d,%d)",
216 indices.GetFirst(),indices.GetSecond()));
1faed5a9 217 }
218 return AliMpPad::Invalid();
dee1d5f1 219 }
220
221 return AliMpPad(AliMpIntPair(motifPos->GetID(),connection->GetGassiNum()),
222 indices,
1faed5a9 223 motifPos->Position()
224 + motif->PadPositionLocal(localIndices)
225 - fkSlat->Position(),
226 motif->GetPadDimensions(localIndices));
dee1d5f1 227}
228
229//_____________________________________________________________________________
230AliMpPad
231AliMpSlatSegmentation::PadByPosition(const TVector2& position,
232 Bool_t warning) const
233{
234 //
235 // Returns the pad specified by its (floating point) position.
236 // If warning=kTRUE and the pad does not exist, a warning message is
237 // printed.
238 //
239 // AliMpPad::Invalid() is returned if there's no pad at the given location.
240 //
241
1964cd2e 242 TVector2 blPos(position+fkSlat->Position()); // position relative to
243 // bottom-left of the slat.
244
245 AliMpMotifPosition* motifPos = fkSlat->FindMotifPosition(blPos.X(),blPos.Y());
dee1d5f1 246
247 if (!motifPos)
248 {
249 if (warning)
250 {
1964cd2e 251 AliWarning(Form("Slat %s Position (%e,%e)/center (%e,%e)/bottom-left cm "
252 " outside limits",fkSlat->GetID(),
253 position.X(),position.Y(),
254 blPos.X(),blPos.Y()));
dee1d5f1 255 }
256 return AliMpPad::Invalid();
257 }
258
259 AliMpVMotif* motif = motifPos->GetMotif();
260 AliMpIntPair localIndices
1964cd2e 261 = motif->PadIndicesLocal(blPos-motifPos->Position());
dee1d5f1 262
263 AliMpConnection* connect =
264 motif->GetMotifType()->FindConnectionByLocalIndices(localIndices);
265
266 if (!connect)
267 {
268 if (warning)
269 {
1faed5a9 270 AliWarning(Form("Slat %s localIndices (%d,%d) outside motif %s limits",
271 fkSlat->GetID(),localIndices.GetFirst(),
272 localIndices.GetSecond(),motif->GetID().Data()));
dee1d5f1 273 }
274 return AliMpPad::Invalid();
275 }
276
277 return AliMpPad(AliMpIntPair(motifPos->GetID(),connect->GetGassiNum()),
278 motifPos->GlobalIndices(localIndices),
1faed5a9 279 motifPos->Position()
280 + motif->PadPositionLocal(localIndices)
281 - fkSlat->Position(),
282 motif->GetPadDimensions(localIndices));
dee1d5f1 283}
284
285//_____________________________________________________________________________
286const AliMpSlat*
287AliMpSlatSegmentation::Slat() const
288{
289 //
290 // Returns the pointer to the referenced slat.
291 //
292
293 return fkSlat;
294}