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