]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSlat.cxx
ba2b1ebc97f4c551e47c31dcf322991f4a1ffb0a
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSlat.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: AliMpSlat.cxx,v 1.6 2006/05/24 13:58:50 ivana Exp $
18
19 #include "AliMpSlat.h"
20
21 #include "AliMpExMapIterator.h"
22 #include "AliLog.h"
23 #include "AliMpMotifPosition.h"
24 #include "AliMpPCB.h"
25
26 #include "Riostream.h"
27
28 #include "TArrayI.h"
29
30 #include <cassert>
31
32 //-----------------------------------------------------------------------------
33 /// Representation of a slat cathode (bending or non-bending).
34 ///
35 /// A slat can be viewed as a "collection" of PCBs of various densities
36 /// (the density is defined by the size of the pads composing the PCB).
37 ///
38 /// All the PCBs have a least the same height, if not the same width. In most
39 /// of the case, height=width=40 cm, at least for St345 (for trigger,
40 /// width varies)
41 // 
42 /// \author Laurent Aphecetche
43 //-----------------------------------------------------------------------------
44
45 /// \cond CLASSIMP
46 ClassImp(AliMpSlat)
47 /// \endcond
48
49 //_____________________________________________________________________________
50 AliMpSlat::AliMpSlat(TRootIOCtor* ioCtor) 
51 : TObject(), 
52   fId(""), 
53   fPlaneType(AliMp::kNonBendingPlane),
54   fDX(0), 
55   fDY(0),
56   fNofPadsX(0), 
57   fMaxNofPadsY(0),
58   fManuMap(ioCtor),
59   fPCBs(),
60   fPosition(),
61   fNofPads(0)
62 {
63     ///
64     /// Empty ctor.
65     ///
66   AliDebug(1,Form("this=%p Empty ctor",this));
67
68     fPCBs.SetOwner(kTRUE);
69     fManuMap.SetOwner(kFALSE);
70 }
71
72 //_____________________________________________________________________________
73 AliMpSlat::AliMpSlat(const char* id, AliMp::PlaneType bendingOrNonBending)
74 : TObject(), 
75   fId(id), 
76   fPlaneType(bendingOrNonBending),
77   fDX(0), 
78   fDY(0),
79   fNofPadsX(0), 
80   fMaxNofPadsY(0),
81   fManuMap(),
82   fPCBs(),
83   fPosition(),
84   fNofPads(0)
85 {
86     ///
87     /// Normal ctor
88     ///
89   AliDebug(1,Form("this=%p id=%s",this,id));                    
90
91     fPCBs.SetOwner(kTRUE);
92     fManuMap.SetOwner(kFALSE);
93 }
94
95 //_____________________________________________________________________________
96 AliMpSlat::~AliMpSlat()
97 {
98   ///
99   /// Dtor.
100   ///
101   AliDebug(1,Form("this=%p fId=%s",this,fId.Data()));                   
102
103   fPCBs.Delete();
104 }
105
106 //_____________________________________________________________________________
107 void
108 AliMpSlat::Add(const AliMpPCB& pcbType, const TArrayI& manuList) 
109 {
110   ///
111   /// Adds a PCB to this slat. The manuList specifies the ids of the manu
112   /// that compose the PCB. The manuList ordering is important, as the 
113   /// assumption is that it's ordered counter-clockwise, starting from
114   /// the lower-left of the PCB.
115   ///
116   Int_t ixOffset = 0;
117   if ( GetSize() )
118         {
119                 ixOffset = GetPCB(GetSize()-1)->Ixmax()+1;
120         }
121   else
122   {
123     ixOffset = pcbType.Ixmin();
124   }
125   Double_t xOffset = DX()*2;
126   AliMpPCB* pcb = pcbType.Clone(manuList,ixOffset,xOffset);
127   fPCBs.AddLast(pcb);
128   fDY = TMath::Max(pcb->DY(),fDY);
129   fDX += pcb->DX();
130   fNofPadsX += pcb->GetNofPadsX();
131   fMaxNofPadsY = TMath::Max(fMaxNofPadsY,pcb->GetNofPadsY());
132   Int_t n(0);
133   for ( Int_t i = 0; i < pcb->GetSize(); ++i )
134         {
135                 AliMpMotifPosition* mp = pcb->GetMotifPosition(i);
136                 Int_t manuID = mp->GetID();
137     // Before inserting a new key, check if it's already there
138     TObject* there = fManuMap.GetValue(manuID);
139     if ( there == 0 )
140     {
141       ++n;
142       AliDebug(1,Form("Adding %d-th manuId=%d (%d) to ManuMap (size=%d)",n,manuID,mp->GetID(),fManuMap.GetSize()));
143       fManuMap.Add(manuID,(TObject*)mp);
144     }
145     else
146     {
147       AliError(Form("ManuID %d is duplicated for PCB %s",manuID,pcbType.GetID()));      
148     }
149   }
150   fPosition.Set(DX(),DY());
151   fNofPads += pcb->NofPads();
152 }
153
154 //_____________________________________________________________________________
155 TVector2
156 AliMpSlat::Dimensions() const
157 {
158   ///
159   /// Returns the half-sizes of the slat.
160   ///
161   return TVector2(DX(),DY());
162 }
163
164 //_____________________________________________________________________________
165 Double_t
166 AliMpSlat::DX() const
167 {
168   ///
169   /// Returns the x-half-size of the slat.
170   ///
171   return fDX;
172 }
173
174 //_____________________________________________________________________________
175 Double_t
176 AliMpSlat::DY() const
177 {
178   ///
179   /// Returns the y-half-size of the slat.
180   ///
181   return fDY;
182 }
183
184 //_____________________________________________________________________________
185 AliMpMotifPosition*
186 AliMpSlat::FindMotifPosition(Int_t manuID) const
187 {
188   ///
189   /// Returns the motifPosition referenced by it manuID
190   ///
191   return static_cast<AliMpMotifPosition*>(fManuMap.GetValue(manuID));
192 }
193
194 //_____________________________________________________________________________
195 AliMpMotifPosition*
196 AliMpSlat::FindMotifPosition(Int_t ix, Int_t iy) const
197 {
198   ///
199   /// - 1. Find the PCB containing ix (iy not needed for this)
200   /// - 2. Forward the request to the PCB, using pcb local indices.
201         //
202   const AliMpPCB* pcb = FindPCB(ix);
203   if ( pcb )
204         {
205                 return pcb->FindMotifPosition(ix,iy);
206         }
207   else
208         {
209                 return 0;
210         }
211 }
212
213 //_____________________________________________________________________________
214 AliMpMotifPosition*
215 AliMpSlat::FindMotifPosition(Double_t x, Double_t y) const
216 {
217   ///
218   /// Returns the motifPosition containing position (x,y)
219   ///
220   const AliMpPCB* pcb = FindPCB(x,y);
221   if (pcb)
222         {
223                 return pcb->FindMotifPosition(x,y);
224         }
225   else
226         {
227                 return 0;
228         }
229 }
230
231 //_____________________________________________________________________________
232 AliMpPCB*
233 AliMpSlat::FindPCB(Int_t ix) const
234 {
235   ///
236   /// Returns the PCB containing x-integer-position ix
237   ///
238   for ( Int_t i = 0; i < GetSize(); ++i ) 
239         {
240                 AliMpPCB* pcb = GetPCB(i);
241                 if ( ix >= pcb->Ixmin() && ix <= pcb->Ixmax() )
242                 {
243                         return pcb;
244                 }
245         }
246   return 0;
247 }
248
249 //_____________________________________________________________________________
250 Int_t
251 AliMpSlat::FindPCBIndex(Int_t ix) const
252 {
253   ///
254   /// Returns the index of the PCB containing x-integer-position ix.
255   ///
256   for ( Int_t i = 0; i < GetSize(); ++i ) 
257         {
258                 AliMpPCB* pcb = GetPCB(i);
259                 if ( ix >= pcb->Ixmin() && ix <= pcb->Ixmax() )
260                 {
261                         return i;
262                 }
263         }
264   return -1;
265 }
266
267 //_____________________________________________________________________________
268 AliMpPCB*
269 AliMpSlat::FindPCB(Double_t x, Double_t y) const
270 {
271   ///
272   /// Returns the PCB containing position (x,y)
273   ///
274   for ( Int_t i = 0; i < GetSize(); ++i ) 
275         {
276                 AliMpPCB* pcb = GetPCB(i);
277 //              if ( x >= pcb->Xmin() && x < pcb->Xmax() &&
278 //                               y >= pcb->Ymin() && y < pcb->Ymax() )
279 //              {
280 //                      return pcb;
281 //              }
282     if ( x < pcb->Xmin() || x >= pcb->Xmax() ||
283          y < pcb->Ymin() || y >= pcb->Ymax() )
284     {
285       continue;
286     }
287     return pcb;
288         }
289   return 0;
290 }
291
292 //_____________________________________________________________________________
293 Int_t
294 AliMpSlat::FindPCBIndex(Double_t x, Double_t y) const
295 {
296   ///
297   /// Returns the index of the PCB containing position (x,y)
298   ///
299   for ( Int_t i = 0; i < GetSize(); ++i ) 
300         {
301                 AliMpPCB* pcb = GetPCB(i);
302                 if ( x >= pcb->Xmin() && x < pcb->Xmax() &&
303                                  y >= pcb->Ymin() && y < pcb->Ymax() )
304                 {
305                         return i;
306                 }
307         }
308   return -1;
309 }
310
311 //_____________________________________________________________________________
312 Int_t 
313 AliMpSlat::FindPCBIndexByMotifPositionID(Int_t manuId) const
314 {
315   /// Find the index of the PCB containing a given manu
316   for ( Int_t i = 0; i< GetSize(); ++i )
317   {
318     AliMpPCB* pcb = GetPCB(i);
319     if ( pcb->HasMotifPositionID(manuId) ) return i;
320   }
321   return -1;
322 }
323
324 //_____________________________________________________________________________
325 void
326 AliMpSlat::ForcePosition(const TVector2& pos)
327 {
328   ///
329   /// Force the position to be different from (DX(),DY()).
330   /// Normally only used by triggerSlats (for layers).
331   /// Beware that this method must be called once all PCB have been added,
332   /// as the Add() method resets the position.
333   ///
334   fPosition = pos;
335 }
336
337 //_____________________________________________________________________________
338 void
339 AliMpSlat::GetAllMotifPositionsIDs(TArrayI& ecn) const
340 {
341   ///
342   /// Return all the manuIds (=MotifPositionIDs) of this slat
343   ///
344   Int_t nofElectronicCards(GetNofElectronicCards());
345   assert(nofElectronicCards>0);
346   ecn.Set(nofElectronicCards);
347   TIter next(fManuMap.CreateIterator());
348   AliMpMotifPosition* mp;
349   Int_t n(0);
350   while ( ( mp = static_cast<AliMpMotifPosition*>(next()) ) )
351   {
352     ecn.AddAt(mp->GetID(),n);
353     ++n;
354   }
355   assert(n==nofElectronicCards);
356 }
357
358 //_____________________________________________________________________________
359 const char*
360 AliMpSlat::GetID() const
361 {
362   ///
363   /// Returns the name of this slat.
364   ///
365   return fId.Data();
366 }
367
368 //_____________________________________________________________________________
369 Int_t 
370 AliMpSlat::GetMaxNofPadsY() const
371 {
372   ///
373   /// Returns the maximum number of pads to be found in this slat y-direction.
374   /// 
375   return fMaxNofPadsY;
376 }
377
378 //_____________________________________________________________________________
379 Int_t 
380 AliMpSlat::GetMaxPadIndexX() const
381 {
382   ///
383   /// Returns the max ix that is valid for this slat.
384   ///
385   AliMpPCB* last = GetPCB(GetSize()-1);
386   if (last)
387   {
388     return last->Ixmax();
389   }
390   return 0;
391 }
392
393 //_____________________________________________________________________________
394 const char*
395 AliMpSlat::GetName() const
396 {
397   ///
398   /// Returns the name of this slat, which is composed of its ID with
399   /// the plane type as a suffix.
400   ///
401   TString name(GetID());
402   if ( fPlaneType == AliMp::kBendingPlane )
403   {
404     name += ".Bending";
405   }
406   else if ( fPlaneType == AliMp::kNonBendingPlane )
407   {
408     name += ".NonBending";
409   }
410   else
411   {
412     name += ".Invalid";
413   }
414   return name.Data();  
415 }
416
417 //_____________________________________________________________________________
418 Int_t
419 AliMpSlat::GetNofElectronicCards() const
420 {
421   ///
422   /// Returns the number of manus that compose the readout of this slat.
423   ///
424   return fManuMap.GetSize();
425 }
426
427 //_____________________________________________________________________________
428 Int_t
429 AliMpSlat::GetNofPadsX() const
430 {
431   ///
432   /// Returns the number of pad in x-direction.
433   ///
434   return fNofPadsX;
435 }
436
437 //_____________________________________________________________________________
438 AliMpPCB*
439 AliMpSlat::GetPCB(Int_t i) const
440 {
441   ///
442   /// Returns the i-th PCB of this slat.
443   ///
444   if ( i >= fPCBs.GetEntriesFast() ) return 0;
445   return (AliMpPCB*)fPCBs[i];
446 }
447
448 //_____________________________________________________________________________
449 Int_t
450 AliMpSlat::GetSize() const
451 {
452   ///
453   /// Returns the number of PCB in this slat.
454   ///
455   return fPCBs.GetEntriesFast();
456 }
457
458 //_____________________________________________________________________________
459 void
460 AliMpSlat::Print(Option_t* option) const
461 {
462   ///
463   /// Prints the slat characteristics.
464   ///
465   cout << "SLAT " << GetID() <<  " 1/2 DIM = (" << DX() << "," << DY() << ")"
466   << " POS = " << Position().X() << "," << Position().Y()
467         << " NPADSX = " << GetNofPadsX() 
468   << " MAXNPADSY = " << GetMaxNofPadsY()
469   << " NPCBs=" << GetSize() << endl;
470   
471   TString soption(option);
472   
473   if ( soption.Contains("P") )
474         {
475     for ( Int_t i = 0; i < GetSize() ; ++i )
476                 {
477       cout << "    ";
478                         if ( option )
479             {
480                                 fPCBs[i]->Print(option+1);
481             }
482                         else
483             {
484               fPCBs[i]->Print();
485             }
486                 }
487         }
488   
489   if ( soption.Contains("M") || soption.Contains("L") )
490   {
491     cout << fManuMap.GetSize() << " ";
492     cout << "Electronic card (manu or local board) Ids : ";
493     TIter next(fManuMap.CreateIterator());
494     AliMpMotifPosition* mp;
495     while ( ( mp = static_cast<AliMpMotifPosition*>(next())) )
496     {
497       cout << mp->GetID() << " ";
498     }
499     cout << endl;
500   }
501 }