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