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