]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSlatSegmentation.cxx
Corrected some manu Id's in mapping for slat and updated the serial manu numbers
[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.12 2006/05/24 13:58:50 ivana Exp $
18
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
25 #include "AliMpSlatSegmentation.h"
26
27 #include "AliLog.h"
28 #include "AliMpArea.h"
29 #include "AliMpConnection.h"
30 #include "AliMpConstants.h"
31 #include "AliLog.h"
32 #include "AliMpMotif.h"
33 #include "AliMpMotifPosition.h"
34 #include "AliMpMotifType.h"
35 #include "AliMpSlat.h"
36 #include "AliMpSlatPadIterator.h"
37
38 /// \cond CLASSIMP
39 ClassImp(AliMpSlatSegmentation)
40 /// \endcond
41
42 //_____________________________________________________________________________
43 AliMpSlatSegmentation::AliMpSlatSegmentation() 
44 : AliMpVSegmentation(),
45   fkSlat(0),
46   fIsOwner(false)
47 {
48   //
49   // Default ctor. Not to be used really.
50   //
51   AliDebug(1,Form("this=%p Empty ctor",this));
52 }
53
54 //_____________________________________________________________________________
55 AliMpSlatSegmentation::AliMpSlatSegmentation(const AliMpSlat* slat, Bool_t own) 
56 : AliMpVSegmentation(), 
57   fkSlat(slat),
58   fIsOwner(own)
59 {
60   //
61   // Normal ctor.
62   //
63   AliDebug(1,Form("this=%p Normal ctor slat=%p",this,slat));
64 }
65
66 //_____________________________________________________________________________
67 AliMpSlatSegmentation::~AliMpSlatSegmentation()
68 {
69   //
70   // Dtor (empty).
71   //
72  
73   if ( fIsOwner ) delete fkSlat;
74  
75   // Int_t i(0);//just to be able to put a breakpoint in gdb
76   AliDebug(1,Form("this=%p",this));                     
77 }
78
79 //_____________________________________________________________________________
80 AliMpVPadIterator*
81 AliMpSlatSegmentation::CreateIterator(const AliMpArea& area) const
82 {
83   //
84   // Returns an iterator to loop over the pad contained within given area.
85   //
86   AliMpArea a(area.Position()+fkSlat->Position(),area.Dimensions());
87   AliDebug(3,Form("Converted input area wrt to slat center : "
88                   "%7.2f,%7.2f->%7.2f,%7.2f to wrt slat lower-left : "
89                   "%7.2f,%7.2f->%7.2f,%7.2f ",
90                   area.LeftBorder(),area.DownBorder(),
91                   area.RightBorder(),area.UpBorder(),
92                   a.LeftBorder(),a.DownBorder(),
93                   a.RightBorder(),a.UpBorder()));
94                   
95   return new AliMpSlatPadIterator(fkSlat,a);
96 }
97
98 //_____________________________________________________________________________
99 AliMpVPadIterator*
100 AliMpSlatSegmentation::CreateIterator() const
101 {
102   /// Returns an iterator to loop over all pads of that segmentation
103   ///
104   /// FIXME: we currently just forward this to the other CreateIterator,
105   /// with the proper region. Might be more efficient to write a dedicated
106   /// iterator ? Test that idea.
107   
108   AliMpArea area(TVector2(0.0,0.0),fkSlat->Dimensions());
109   return CreateIterator(area);
110 }
111
112 //_____________________________________________________________________________
113 Int_t 
114 AliMpSlatSegmentation::GetNeighbours(const AliMpPad& pad, 
115                                      TObjArray& neighbours,
116                                      Bool_t includeSelf,
117                                      Bool_t includeVoid) const
118 {
119   /// Uses default implementation
120   return AliMpVSegmentation::GetNeighbours(pad,neighbours,includeSelf,includeVoid);
121 }
122
123 //_____________________________________________________________________________
124 TVector2
125 AliMpSlatSegmentation::Dimensions() const
126 {
127   return Slat()->Dimensions();
128 }
129
130 //_____________________________________________________________________________
131 void 
132 AliMpSlatSegmentation::GetAllElectronicCardIDs(TArrayI& ecn) const
133 {
134   Slat()->GetAllMotifPositionsIDs(ecn);
135 }
136
137 //_____________________________________________________________________________
138 const char*
139 AliMpSlatSegmentation::GetName() const
140 {
141   // The name of this segmentation is "SlatSegmentation"+slatName
142
143   TString name("SlatSegmentation");
144   if ( fkSlat) 
145   {
146     name += ".";
147     name += fkSlat->GetName();
148   }
149   return name.Data();
150 }
151
152 //_____________________________________________________________________________
153 Bool_t
154 AliMpSlatSegmentation::HasPad(const AliMpIntPair& indices) const
155 {
156   //
157   // Test if this slat has a pad located at the position referenced
158   // by the integer indices.
159   //
160   
161   return PadByIndices(indices,kFALSE) != AliMpPad::Invalid();
162 }
163
164 //_____________________________________________________________________________
165 Int_t 
166 AliMpSlatSegmentation::MaxPadIndexX() const
167 {
168   //
169   // Returns the value of the largest pad index in x-direction.
170   //
171   
172   return fkSlat->GetMaxPadIndexX();
173 }
174
175 //_____________________________________________________________________________
176 Int_t 
177 AliMpSlatSegmentation::MaxPadIndexY() const
178 {
179   //
180   // Returns the value of the largest pad index in y-direction.
181   //
182   
183   return fkSlat->GetMaxNofPadsY()-1;
184 }
185
186 //_____________________________________________________________________________
187 Int_t 
188 AliMpSlatSegmentation::NofPads() const
189 {
190 /// Return number of pads defined in the slat
191   
192   return fkSlat->NofPads();
193 }
194
195 //_____________________________________________________________________________
196 AliMpPad
197 AliMpSlatSegmentation::PadByLocation(const AliMpIntPair& location, 
198                                      Bool_t warning) const
199 {
200   //
201   // Returns the pad specified by its location, where location is the 
202   // pair (ManuID,ManuChannel).
203   // If warning=kTRUE and the pad does not exist, a warning message is 
204   // printed.
205   //
206   // AliMpPad::Invalid() is returned if there's no pad at the given location.
207   //
208   Int_t manuID = location.GetFirst();
209         
210   AliMpMotifPosition* motifPos = fkSlat->FindMotifPosition(manuID);
211         
212   if (!motifPos)
213         {
214                 if (warning)
215                 {
216                         AliWarning(Form("Manu ID %d not found in slat %s",
217                                          manuID, fkSlat->GetID()));
218     }
219     return AliMpPad::Invalid();
220         }
221   AliMpVMotif* motif = motifPos->GetMotif();
222   AliMpIntPair localIndices = 
223     motif->GetMotifType()->FindLocalIndicesByGassiNum(location.GetSecond());
224         
225   if (!localIndices.IsValid()) 
226         {
227                 if (warning) 
228                 {
229                         AliWarning(Form("The pad number %d doesn't exists",
230                                         location.GetSecond()));
231                 }
232                 return AliMpPad::Invalid();
233         }
234         
235   return AliMpPad(location,
236                   motifPos->GlobalIndices(localIndices),
237                   motifPos->Position() 
238                   + motif->PadPositionLocal(localIndices) 
239                   - fkSlat->Position(),
240                   motif->GetPadDimensions(localIndices));  
241 }
242
243 //_____________________________________________________________________________
244 AliMpPad
245 AliMpSlatSegmentation::PadByIndices(const AliMpIntPair& indices, 
246                                     Bool_t warning) const
247 {
248   //
249   // Returns the pad specified by its integer indices.
250   // If warning=kTRUE and the pad does not exist, a warning message is 
251   // printed.
252   //
253   // AliMpPad::Invalid() is returned if there's no pad at the given location.
254   //
255   //  
256   // FIXME: except for the FindMotifPosition below, this method
257   // is exactly as the one in AliMpSectorSegmentation.
258   // See if we can merge them somehow.
259         
260   AliMpMotifPosition* motifPos = fkSlat->FindMotifPosition(indices.GetFirst(),
261                                                                                                                                                                                                          indices.GetSecond());
262   if (!motifPos)
263         {
264                 if ( warning ) 
265                 {
266                         AliWarning(Form("No motif found containing pad location (%d,%d)",
267                                          indices.GetFirst(),indices.GetSecond()));        
268                 }
269                 return AliMpPad::Invalid();
270         }
271         
272   AliMpVMotif* motif = motifPos->GetMotif();
273   AliMpMotifType* motifType = motif->GetMotifType();
274   AliMpIntPair localIndices(indices-motifPos->GetLowIndicesLimit());
275   AliMpConnection* connection = motifType->FindConnectionByLocalIndices(localIndices);
276   
277   if (!connection)
278         {
279                 if ( warning )
280                 {
281                         AliWarning(Form("No connection for pad location (%d,%d)",
282                                         indices.GetFirst(),indices.GetSecond()));
283     }
284     return AliMpPad::Invalid();
285         }
286         
287   return AliMpPad(AliMpIntPair(motifPos->GetID(),connection->GetGassiNum()),
288                   indices,
289                   motifPos->Position()
290                   + motif->PadPositionLocal(localIndices)
291                   - fkSlat->Position(),
292                   motif->GetPadDimensions(localIndices));
293 }
294
295 //_____________________________________________________________________________
296 AliMpPad
297 AliMpSlatSegmentation::PadByPosition(const TVector2& position, 
298                                      Bool_t warning) const
299 {
300   //
301   // Returns the pad specified by its (floating point) position.
302   // If warning=kTRUE and the pad does not exist, a warning message is 
303   // printed.
304   //
305   // AliMpPad::Invalid() is returned if there's no pad at the given location.
306   //
307   
308   TVector2 blPos(position);
309   
310   blPos += fkSlat->Position(); // position relative to bottom-left of the slat.
311   
312   AliMpMotifPosition* motifPos = fkSlat->FindMotifPosition(blPos.X(),blPos.Y());
313         
314   if (!motifPos)
315         {
316                 if (warning) 
317                 {
318                         AliWarning(Form("Slat %s Position (%e,%e)/center (%e,%e)/bottom-left cm "
319                       " outside limits",fkSlat->GetID(),
320                       position.X(),position.Y(),
321                       blPos.X(),blPos.Y()));
322                 }
323                 return AliMpPad::Invalid();
324         }
325         
326   AliMpVMotif* motif =  motifPos->GetMotif();  
327   blPos -= motifPos->Position();
328   AliMpIntPair localIndices 
329     = motif->PadIndicesLocal(blPos);
330         
331   AliMpConnection* connect = 
332     motif->GetMotifType()->FindConnectionByLocalIndices(localIndices);
333         
334   if (!connect)
335         {
336                 if (warning) 
337                 {
338                         AliWarning(Form("Slat %s localIndices (%d,%d) outside motif %s limits",
339                       fkSlat->GetID(),localIndices.GetFirst(),
340                       localIndices.GetSecond(),motif->GetID().Data()));
341                 }
342                 return AliMpPad::Invalid();
343         }
344   
345   return AliMpPad(AliMpIntPair(motifPos->GetID(),connect->GetGassiNum()),
346                   motifPos->GlobalIndices(localIndices),
347                   motifPos->Position()
348                   + motif->PadPositionLocal(localIndices)
349                   - fkSlat->Position(),
350                   motif->GetPadDimensions(localIndices));  
351 }
352
353 //_____________________________________________________________________________
354 AliMp::PlaneType
355 AliMpSlatSegmentation::PlaneType() const
356 {
357   return Slat()->PlaneType();
358 }
359
360 //_____________________________________________________________________________
361 void
362 AliMpSlatSegmentation::Print(Option_t* opt) const
363 {
364   fkSlat->Print(opt);
365 }
366
367 //_____________________________________________________________________________
368 const AliMpSlat* 
369 AliMpSlatSegmentation::Slat() const
370 {
371   //
372   // Returns the pointer to the referenced slat.
373   //
374   
375   return fkSlat;
376 }