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