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