]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpSlat.cxx
Applying ManuMask in motif position test
[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);
298 if ( x >= pcb->Xmin() && x < pcb->Xmax() &&
299 y >= pcb->Ymin() && y < pcb->Ymax() )
300 {
301 return pcb;
302 }
303 }
304 return 0;
305}
306
307//_____________________________________________________________________________
308Int_t
309AliMpSlat::FindPCBIndex(Double_t x, Double_t y) const
310{
311 //
312 // Returns the index of the PCB containing position (x,y)
313 //
314 for ( Size_t i = 0; i < GetSize(); ++i )
315 {
316 AliMpPCB* pcb = GetPCB(i);
317 if ( x >= pcb->Xmin() && x < pcb->Xmax() &&
318 y >= pcb->Ymin() && y < pcb->Ymax() )
319 {
320 return i;
321 }
322 }
323 return -1;
324}
325
19b51aad 326//_____________________________________________________________________________
327void
328AliMpSlat::ForcePosition(const TVector2& pos)
329{
330 //
331 // Force the position to be different from (DX(),DY()).
332 // Normally only used by triggerSlats (for layers).
333 // Beware that this method must be called once all PCB have been added,
334 // as the Add() method resets the position.
335 //
336 fPosition = pos;
337}
338
339//_____________________________________________________________________________
340void
c9da0af9 341AliMpSlat::GetAllMotifPositionsIDs(TArrayI& ecn) const
19b51aad 342{
efb408b3 343 //
344 // Return all the manuIds (=MotifPositionIDs) of this slat
345 //
19b51aad 346 ecn.Set(GetNofElectronicCards());
0f60374b 347//#ifdef WITH_ROOT
19b51aad 348 TExMapIter it(fManuMap.GetIterator());
349 Long_t key;
350 Long_t value;
351 Int_t n(0);
352 while ( it.Next(key,value) == kTRUE )
353 {
354 ecn.AddAt((Int_t)(key),n);
355 ++n;
356 }
0f60374b 357//#else
358 // missing here
359//#endif
19b51aad 360}
361
dee1d5f1 362//_____________________________________________________________________________
363const char*
364AliMpSlat::GetID() const
365{
366 //
367 // Returns the name of this slat.
368 //
369 return fId.Data();
370}
371
372//_____________________________________________________________________________
373Int_t
374AliMpSlat::GetMaxNofPadsY() const
375{
376 //
377 // Returns the maximum number of pads to be found in this slat y-direction.
378 //
379 return fMaxNofPadsY;
380}
381
16e8fffd 382//_____________________________________________________________________________
383Int_t
384AliMpSlat::GetMaxPadIndexX() const
385{
efb408b3 386 //
387 // Returns the max ix that is valid for this slat.
388 //
16e8fffd 389 AliMpPCB* last = GetPCB(GetSize()-1);
390 if (last)
391 {
392 return last->Ixmax();
393 }
394 return 0;
395}
396
19b51aad 397//_____________________________________________________________________________
398const char*
399AliMpSlat::GetName() const
400{
efb408b3 401 //
402 // Returns the name of this slat, which is composed of its ID with
403 // the plane type as a suffix.
404 //
19b51aad 405 TString name(GetID());
cddd101e 406 if ( fPlaneType == AliMp::kBendingPlane )
19b51aad 407 {
408 name += ".Bending";
409 }
cddd101e 410 else if ( fPlaneType == AliMp::kNonBendingPlane )
19b51aad 411 {
412 name += ".NonBending";
413 }
414 else
415 {
416 name += ".Invalid";
417 }
418 return name.Data();
419}
420
421//_____________________________________________________________________________
422Int_t
423AliMpSlat::GetNofElectronicCards() const
424{
efb408b3 425 //
426 // Returns the number of manus that compose the readout of this slat.
427 //
19b51aad 428 return fManuMap.GetSize();
429}
430
dee1d5f1 431//_____________________________________________________________________________
432Int_t
433AliMpSlat::GetNofPadsX() const
434{
435 //
436 // Returns the number of pad in x-direction.
437 //
438 return fNofPadsX;
439}
440
441//_____________________________________________________________________________
442AliMpPCB*
443AliMpSlat::GetPCB(AliMpSlat::Size_t i) const
444{
445 //
446 // Returns the i-th PCB of this slat.
447 //
448#ifdef WITH_ROOT
449 if ( i >= fPCBs.GetEntriesFast() ) return 0;
450 return (AliMpPCB*)fPCBs[i];
451#else
452 if ( i >= fPCBs.size() ) return 0;
453 return fPCBs[i];
454#endif
455}
456
457//_____________________________________________________________________________
458AliMpSlat::Size_t
459AliMpSlat::GetSize() const
460{
461 //
462 // Returns the number of PCB in this slat.
463 //
464#ifdef WITH_ROOT
465 return fPCBs.GetEntriesFast();
466#else
467 return fPCBs.size();
468#endif
469}
470
471//_____________________________________________________________________________
472void
473AliMpSlat::Print(Option_t* option) const
474{
475 //
476 // Prints the slat characteristics.
477 //
478 cout << "SLAT " << GetID() << " 1/2 DIM = (" << DX() << "," << DY() << ")"
19b51aad 479 << " POS = " << Position().X() << "," << Position().Y()
480 << " NPADSX = " << GetNofPadsX()
481 << " MAXNPADSY = " << GetMaxNofPadsY()
482 << " NPCBs=" << GetSize() << endl;
483
484 TString soption(option);
dee1d5f1 485
19b51aad 486 if ( soption.Contains("P") )
dee1d5f1 487 {
488 for ( Size_t i = 0; i < GetSize() ; ++i )
489 {
490 cout << " ";
491 if ( option )
492 {
493 fPCBs[i]->Print(option+1);
494 }
495 else
496 {
497 fPCBs[i]->Print();
498 }
499 }
500 }
19b51aad 501
502 if ( soption.Contains("M") || soption.Contains("L") )
503 {
504 cout << fManuMap.GetSize() << " ";
505 cout << "Electronic card (manu or local board) Ids : ";
506
507 TExMapIter iter(fManuMap.GetIterator());
508 Long_t key, value;
509 while ( iter.Next(key,value) )
510 {
511 cout << key << " ";
512 }
513 cout << endl;
514 }
dee1d5f1 515}