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