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