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 |
43 | ClassImp(AliMpSlat) |
13985652 |
44 | /// \endcond |
dee1d5f1 |
45 | |
46 | //_____________________________________________________________________________ |
47 | AliMpSlat::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 |
71 | AliMpSlat::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 | //_____________________________________________________________________________ |
95 | AliMpSlat::~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 | //_____________________________________________________________________________ |
112 | void |
d21dc4b0 |
113 | AliMpSlat::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 | //_____________________________________________________________________________ |
165 | TVector2 |
166 | AliMpSlat::Dimensions() const |
167 | { |
71a2d3aa |
168 | /// |
169 | /// Returns the half-sizes of the slat. |
170 | /// |
dee1d5f1 |
171 | return TVector2(DX(),DY()); |
172 | } |
173 | |
174 | //_____________________________________________________________________________ |
175 | Double_t |
176 | AliMpSlat::DX() const |
177 | { |
71a2d3aa |
178 | /// |
179 | /// Returns the x-half-size of the slat. |
180 | /// |
dee1d5f1 |
181 | return fDX; |
182 | } |
183 | |
184 | //_____________________________________________________________________________ |
185 | Double_t |
186 | AliMpSlat::DY() const |
187 | { |
71a2d3aa |
188 | /// |
189 | /// Returns the y-half-size of the slat. |
190 | /// |
dee1d5f1 |
191 | return fDY; |
192 | } |
193 | |
194 | //_____________________________________________________________________________ |
195 | AliMpMotifPosition* |
196 | AliMpSlat::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 | //_____________________________________________________________________________ |
217 | AliMpMotifPosition* |
218 | AliMpSlat::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 | //_____________________________________________________________________________ |
236 | AliMpMotifPosition* |
237 | AliMpSlat::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 | //_____________________________________________________________________________ |
254 | AliMpPCB* |
255 | AliMpSlat::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 | //_____________________________________________________________________________ |
272 | Int_t |
273 | AliMpSlat::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 | //_____________________________________________________________________________ |
290 | AliMpPCB* |
291 | AliMpSlat::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 | //_____________________________________________________________________________ |
315 | Int_t |
316 | AliMpSlat::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 | |
19b51aad |
333 | //_____________________________________________________________________________ |
334 | void |
335 | AliMpSlat::ForcePosition(const TVector2& pos) |
336 | { |
71a2d3aa |
337 | /// |
338 | /// Force the position to be different from (DX(),DY()). |
339 | /// Normally only used by triggerSlats (for layers). |
340 | /// Beware that this method must be called once all PCB have been added, |
341 | /// as the Add() method resets the position. |
342 | /// |
19b51aad |
343 | fPosition = pos; |
344 | } |
345 | |
346 | //_____________________________________________________________________________ |
347 | void |
c9da0af9 |
348 | AliMpSlat::GetAllMotifPositionsIDs(TArrayI& ecn) const |
19b51aad |
349 | { |
71a2d3aa |
350 | /// |
351 | /// Return all the manuIds (=MotifPositionIDs) of this slat |
352 | /// |
19b51aad |
353 | ecn.Set(GetNofElectronicCards()); |
0f60374b |
354 | //#ifdef WITH_ROOT |
19b51aad |
355 | TExMapIter it(fManuMap.GetIterator()); |
356 | Long_t key; |
357 | Long_t value; |
358 | Int_t n(0); |
359 | while ( it.Next(key,value) == kTRUE ) |
360 | { |
361 | ecn.AddAt((Int_t)(key),n); |
362 | ++n; |
363 | } |
0f60374b |
364 | //#else |
365 | // missing here |
366 | //#endif |
19b51aad |
367 | } |
368 | |
dee1d5f1 |
369 | //_____________________________________________________________________________ |
370 | const char* |
371 | AliMpSlat::GetID() const |
372 | { |
71a2d3aa |
373 | /// |
374 | /// Returns the name of this slat. |
375 | /// |
dee1d5f1 |
376 | return fId.Data(); |
377 | } |
378 | |
379 | //_____________________________________________________________________________ |
380 | Int_t |
381 | AliMpSlat::GetMaxNofPadsY() const |
382 | { |
71a2d3aa |
383 | /// |
384 | /// Returns the maximum number of pads to be found in this slat y-direction. |
385 | /// |
dee1d5f1 |
386 | return fMaxNofPadsY; |
387 | } |
388 | |
16e8fffd |
389 | //_____________________________________________________________________________ |
390 | Int_t |
391 | AliMpSlat::GetMaxPadIndexX() const |
392 | { |
71a2d3aa |
393 | /// |
394 | /// Returns the max ix that is valid for this slat. |
395 | /// |
16e8fffd |
396 | AliMpPCB* last = GetPCB(GetSize()-1); |
397 | if (last) |
398 | { |
399 | return last->Ixmax(); |
400 | } |
401 | return 0; |
402 | } |
403 | |
19b51aad |
404 | //_____________________________________________________________________________ |
405 | const char* |
406 | AliMpSlat::GetName() const |
407 | { |
71a2d3aa |
408 | /// |
409 | /// Returns the name of this slat, which is composed of its ID with |
410 | /// the plane type as a suffix. |
411 | /// |
19b51aad |
412 | TString name(GetID()); |
cddd101e |
413 | if ( fPlaneType == AliMp::kBendingPlane ) |
19b51aad |
414 | { |
415 | name += ".Bending"; |
416 | } |
cddd101e |
417 | else if ( fPlaneType == AliMp::kNonBendingPlane ) |
19b51aad |
418 | { |
419 | name += ".NonBending"; |
420 | } |
421 | else |
422 | { |
423 | name += ".Invalid"; |
424 | } |
425 | return name.Data(); |
426 | } |
427 | |
428 | //_____________________________________________________________________________ |
429 | Int_t |
430 | AliMpSlat::GetNofElectronicCards() const |
431 | { |
71a2d3aa |
432 | /// |
433 | /// Returns the number of manus that compose the readout of this slat. |
434 | /// |
19b51aad |
435 | return fManuMap.GetSize(); |
436 | } |
437 | |
dee1d5f1 |
438 | //_____________________________________________________________________________ |
439 | Int_t |
440 | AliMpSlat::GetNofPadsX() const |
441 | { |
71a2d3aa |
442 | /// |
443 | /// Returns the number of pad in x-direction. |
444 | /// |
dee1d5f1 |
445 | return fNofPadsX; |
446 | } |
447 | |
448 | //_____________________________________________________________________________ |
449 | AliMpPCB* |
450 | AliMpSlat::GetPCB(AliMpSlat::Size_t i) const |
451 | { |
71a2d3aa |
452 | /// |
453 | /// Returns the i-th PCB of this slat. |
454 | /// |
dee1d5f1 |
455 | #ifdef WITH_ROOT |
456 | if ( i >= fPCBs.GetEntriesFast() ) return 0; |
457 | return (AliMpPCB*)fPCBs[i]; |
458 | #else |
459 | if ( i >= fPCBs.size() ) return 0; |
460 | return fPCBs[i]; |
461 | #endif |
462 | } |
463 | |
464 | //_____________________________________________________________________________ |
465 | AliMpSlat::Size_t |
466 | AliMpSlat::GetSize() const |
467 | { |
71a2d3aa |
468 | /// |
469 | /// Returns the number of PCB in this slat. |
470 | /// |
dee1d5f1 |
471 | #ifdef WITH_ROOT |
472 | return fPCBs.GetEntriesFast(); |
473 | #else |
474 | return fPCBs.size(); |
475 | #endif |
476 | } |
477 | |
478 | //_____________________________________________________________________________ |
479 | void |
480 | AliMpSlat::Print(Option_t* option) const |
481 | { |
71a2d3aa |
482 | /// |
483 | /// Prints the slat characteristics. |
484 | /// |
dee1d5f1 |
485 | cout << "SLAT " << GetID() << " 1/2 DIM = (" << DX() << "," << DY() << ")" |
19b51aad |
486 | << " POS = " << Position().X() << "," << Position().Y() |
487 | << " NPADSX = " << GetNofPadsX() |
488 | << " MAXNPADSY = " << GetMaxNofPadsY() |
489 | << " NPCBs=" << GetSize() << endl; |
490 | |
491 | TString soption(option); |
dee1d5f1 |
492 | |
19b51aad |
493 | if ( soption.Contains("P") ) |
dee1d5f1 |
494 | { |
495 | for ( Size_t i = 0; i < GetSize() ; ++i ) |
496 | { |
497 | cout << " "; |
498 | if ( option ) |
499 | { |
500 | fPCBs[i]->Print(option+1); |
501 | } |
502 | else |
503 | { |
504 | fPCBs[i]->Print(); |
505 | } |
506 | } |
507 | } |
19b51aad |
508 | |
509 | if ( soption.Contains("M") || soption.Contains("L") ) |
510 | { |
511 | cout << fManuMap.GetSize() << " "; |
512 | cout << "Electronic card (manu or local board) Ids : "; |
513 | |
514 | TExMapIter iter(fManuMap.GetIterator()); |
515 | Long_t key, value; |
516 | while ( iter.Next(key,value) ) |
517 | { |
518 | cout << key << " "; |
519 | } |
520 | cout << endl; |
521 | } |
dee1d5f1 |
522 | } |