]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpVRowSegmentSpecial.cxx
- Reordering includes and/or
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpVRowSegmentSpecial.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
ea4cae7a 16// $Id$
63ed9c6b 17// $MpId: AliMpVRowSegmentSpecial.cxx,v 1.7 2006/03/02 16:37:30 ivana Exp $
ea4cae7a 18// Category: sector
19//
20// Class AliMpVRowSegmentSpecial
21// ----------------------------
22// Class describing a special row segment composed of the
23// pad rows.
dbe945cc 24// Included in AliRoot: 2003/05/02
ea4cae7a 25// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
26
ea4cae7a 27#include "AliMpVRowSegmentSpecial.h"
28#include "AliMpRow.h"
29#include "AliMpPadRow.h"
30#include "AliMpVPadRowSegment.h"
31#include "AliMpMotif.h"
32#include "AliMpMotifType.h"
33#include "AliMpMotifMap.h"
34#include "AliMpMotifPosition.h"
35#include "AliMpConstants.h"
36
63ed9c6b 37#include <TError.h>
38#include <Riostream.h>
ea4cae7a 39
f79c58a5 40#ifdef WITH_ROOT
41const Int_t AliMpVRowSegmentSpecial::fgkMaxNofMotifPositionIds = 20;
42#endif
43
63ed9c6b 44ClassImp(AliMpVRowSegmentSpecial)
45
ea4cae7a 46//______________________________________________________________________________
47AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial(AliMpRow* row, Double_t offsetX)
48 : AliMpVRowSegment(),
49 fRow(row),
50 fOffsetX(offsetX),
51 fPadRows(),
52 fMotifs(),
53 fMotifPositionIds()
f79c58a5 54#ifdef WITH_ROOT
55 ,fNofMotifPositionIds(0)
56#endif
ea4cae7a 57{
dee1d5f1 58/// Standard constructor
ea4cae7a 59}
60
61//______________________________________________________________________________
62AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial()
63 : AliMpVRowSegment(),
64 fRow(0),
65 fOffsetX(0.),
66 fPadRows(),
67 fMotifs(),
68 fMotifPositionIds()
f79c58a5 69#ifdef WITH_ROOT
70 ,fNofMotifPositionIds(0)
71#endif
ea4cae7a 72{
dee1d5f1 73/// Default constructor
74
f79c58a5 75#ifdef WITH_ROOT
76 fMotifPositionIds.Set(fgkMaxNofMotifPositionIds);
77#endif
ea4cae7a 78}
79
fb1bf5c0 80//_____________________________________________________________________________
81AliMpVRowSegmentSpecial::AliMpVRowSegmentSpecial(
82 const AliMpVRowSegmentSpecial& right)
dee1d5f1 83 : AliMpVRowSegment(right)
84{
85/// Protected copy constructor (not provided)
86
fb1bf5c0 87 Fatal("AliMpVRowSegmentSpecial", "Copy constructor not provided.");
88}
89
ea4cae7a 90//______________________________________________________________________________
91AliMpVRowSegmentSpecial::~AliMpVRowSegmentSpecial()
92{
dee1d5f1 93/// Destructor
94
ea4cae7a 95 for (Int_t i=0; i<GetNofPadRows(); i++)
96 delete fPadRows[i];
97}
98
fb1bf5c0 99//
100// operators
101//
102
103//_____________________________________________________________________________
104AliMpVRowSegmentSpecial&
105AliMpVRowSegmentSpecial::operator=(const AliMpVRowSegmentSpecial& right)
106{
dee1d5f1 107/// Protected assignment operator (not provided)
108
109 // check assignment to self
fb1bf5c0 110 if (this == &right) return *this;
111
dee1d5f1 112 Fatal("operator =", "Assignment operator not provided.");
fb1bf5c0 113
114 return *this;
115}
116
ea4cae7a 117//
118// protected methods
119//
120
121//______________________________________________________________________________
122AliMpPadRow* AliMpVRowSegmentSpecial::FindPadRow(Double_t y) const
123{
dee1d5f1 124/// Find the pad row in the given y coordinate.
ea4cae7a 125
126 Double_t lowBorder = fRow->LowBorderY();
127 Double_t highBorder = fRow->LowBorderY();
128
129 for (Int_t i=0; i<GetNofPadRows(); i++) {
130
131 AliMpPadRow* padRow = GetPadRow(i);
132 highBorder += 2.*padRow->HalfSizeY();
133
134 if ( y >= lowBorder && y <= highBorder)
135 return padRow;
136
137 lowBorder = highBorder;
138 }
139
140 return 0;
141}
142
143//______________________________________________________________________________
144AliMpVPadRowSegment*
145AliMpVRowSegmentSpecial::FindPadRowSegment(Int_t motifPositionId) const
146{
dee1d5f1 147/// Find the most down pad row segment with this motifPositionId.
ea4cae7a 148
149 for (Int_t i=0; i<GetNofPadRows(); i++) {
150 AliMpPadRow* padRow = GetPadRow(i);
151
152 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
153 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
154
155 if (padRowSegment->GetMotifPositionId() == motifPositionId)
156 return padRowSegment;
157 }
158 }
159 return 0;
160}
161
162//______________________________________________________________________________
163AliMpIntPair
164AliMpVRowSegmentSpecial::FindRelativeLowIndicesOf(Int_t motifPositionId) const
165{
dee1d5f1 166/// Return the lowest pad indices where the motif of the given position ID
167/// exist in this segment.
ea4cae7a 168
169 AliMpIntPair ans(0,1000);
170 AliMpIntPair ans0 = ans;
171 Int_t maxNofPadsX=0;
172
173 for (Int_t i=0; i<GetNofPadRows(); i++) {
174 AliMpPadRow* padRow = GetPadRow(i);
175
176 Int_t nofPadsX=0;
177 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
178 AliMpVPadRowSegment* padRowSegment = padRow->GetPadRowSegment(j);
179 nofPadsX += padRowSegment->GetNofPads();
180 if (padRowSegment->GetMotifPositionId() == motifPositionId) {
181 if (ans.GetFirst() < nofPadsX) ans.SetFirst(nofPadsX);
182 if (ans.GetSecond()>i) ans.SetSecond(i);
183 // ans.First = max (nof pads of this pos ID)
184 // ans.Second = min of pad row number
185 }
186 }
187 if (nofPadsX > maxNofPadsX) maxNofPadsX = nofPadsX;
188 }
189 if (ans == ans0) return AliMpIntPair::Invalid();
190
191 return AliMpIntPair(maxNofPadsX-ans.GetFirst(), ans.GetSecond());
192}
193
194//______________________________________________________________________________
195Int_t AliMpVRowSegmentSpecial::MaxNofPadsInRow() const
196{
dee1d5f1 197/// Return the maximum number of pads in this row segment along the X direction
ea4cae7a 198
199 Int_t maxNofPads = 0;
200
201 for (Int_t i=0; i<GetNofPadRows(); i++){
202 Int_t nofPads = GetPadRow(i)->GetNofPads();
203
204 // Find maximum
205 if (nofPads > maxNofPads) maxNofPads = nofPads;
206 }
207
208 return maxNofPads;
209}
210
211//______________________________________________________________________________
212Bool_t AliMpVRowSegmentSpecial::HasMotif(const AliMpVMotif* motif) const
213{
dee1d5f1 214/// Return true if the specified motif is already in fMotifs vector,
215/// returns false otherwise.
ea4cae7a 216
f79c58a5 217#ifdef WITH_STL
ea4cae7a 218 for (UInt_t i=0; i<fMotifs.size(); i++)
219 if (fMotifs[i] == motif) return true;
f79c58a5 220#endif
221
222#ifdef WITH_ROOT
223 for (Int_t i=0; i<fMotifs.GetEntriesFast(); i++)
b166d013 224 if (fMotifs[i] == (const TObject*)motif) return true;
f79c58a5 225#endif
ea4cae7a 226
227 return false;
228}
229
230//______________________________________________________________________________
231Int_t AliMpVRowSegmentSpecial::GetNofPadRows() const
232{
dee1d5f1 233/// Return number of pad rows.
ea4cae7a 234
f79c58a5 235#ifdef WITH_STL
ea4cae7a 236 return fPadRows.size();
f79c58a5 237#endif
238
239#ifdef WITH_ROOT
240 return fPadRows.GetEntriesFast();
241#endif
ea4cae7a 242}
243
244//______________________________________________________________________________
245AliMpPadRow* AliMpVRowSegmentSpecial::GetPadRow(Int_t i) const
246{
dee1d5f1 247/// Return number of pad rows.
ea4cae7a 248
f79c58a5 249#ifdef WITH_STL
ea4cae7a 250 return fPadRows[i];
f79c58a5 251#endif
252
253#ifdef WITH_ROOT
254 return (AliMpPadRow*)fPadRows[i];
255#endif
ea4cae7a 256}
257
258//
259// public methods
260//
261
262//______________________________________________________________________________
263void AliMpVRowSegmentSpecial::AddPadRow(AliMpPadRow* padRow)
264{
dee1d5f1 265/// Add a pad row.
ea4cae7a 266
267 padRow->SetOffsetX(fOffsetX);
268 padRow->SetID(GetNofPadRows());
f79c58a5 269
270#ifdef WITH_STL
ea4cae7a 271 fPadRows.push_back(padRow);
f79c58a5 272#endif
273
274#ifdef WITH_ROOT
275 fPadRows.Add(padRow);
276#endif
ea4cae7a 277}
278
279//______________________________________________________________________________
280void AliMpVRowSegmentSpecial::UpdateMotifVector()
281{
dee1d5f1 282/// Add motifs associated with the pad row segments in the specified
283/// pad row in the fMotifs vector.
ea4cae7a 284
285 for (Int_t i=0; i<GetNofPadRows(); i++) {
286 AliMpPadRow* padRow = GetPadRow(i);
287
288 for (Int_t j=0; j<padRow->GetNofPadRowSegments(); j++) {
289 AliMpVMotif* motif = padRow->GetPadRowSegment(j)->GetMotif();
290
291 if (!HasMotif(motif)) {
f79c58a5 292#ifdef WITH_STL
ea4cae7a 293 fMotifs.push_back(motif);
294 fMotifPositionIds.push_back(
295 padRow->GetPadRowSegment(j)->GetMotifPositionId());
f79c58a5 296#endif
297#ifdef WITH_ROOT
298 fMotifs.Add(motif);
299
300 // resize array if needed
301 if (fNofMotifPositionIds<fgkMaxNofMotifPositionIds)
302 fMotifPositionIds.Set(fMotifPositionIds.GetSize()+
303 fgkMaxNofMotifPositionIds);
304 fMotifPositionIds.AddAt(
305 padRow->GetPadRowSegment(j)->GetMotifPositionId(),
306 fNofMotifPositionIds++);
307#endif
ea4cae7a 308 }
309 }
310 }
311}
312
313//______________________________________________________________________________
314Double_t AliMpVRowSegmentSpecial::HalfSizeY() const
315{
dee1d5f1 316/// Return the size in y of this row segment.
ea4cae7a 317
318 Double_t halfSizeY = 0.;
319 for (Int_t i=0; i<GetNofPadRows(); i++) {
320 halfSizeY += GetPadRow(i)->HalfSizeY();
321 }
322
323 return halfSizeY;
324}
325
326//______________________________________________________________________________
327AliMpVMotif* AliMpVRowSegmentSpecial::FindMotif(const TVector2& position) const
328{
dee1d5f1 329/// Return the motif of this row;
ea4cae7a 330
331 AliMpPadRow* padRow
332 = FindPadRow(position.Y());
333
334 if (!padRow) return 0;
335
336 AliMpVPadRowSegment* padRowSegment
337 = padRow->FindPadRowSegment(position.X());
338
339 if (!padRowSegment) return 0;
340
341 return padRowSegment->GetMotif();
342}
343
344//______________________________________________________________________________
345Int_t AliMpVRowSegmentSpecial::FindMotifPositionId(const TVector2& position) const
346{
dee1d5f1 347/// Return the motif position identified for the given
348/// geometric position.
ea4cae7a 349
350 AliMpPadRow* padRow
351 = FindPadRow(position.Y());
352
353 if (!padRow) return 0;
354
355 AliMpVPadRowSegment* padRowSegment
356 = padRow->FindPadRowSegment(position.X());
357
358 if (!padRowSegment) return 0;
359
360 return padRowSegment->GetMotifPositionId();
361}
362
363//______________________________________________________________________________
364Bool_t AliMpVRowSegmentSpecial::HasMotifPosition(Int_t motifPositionId) const
365{
dee1d5f1 366/// Return true if the motif specified with the given position identifier
367/// is in this segment.
ea4cae7a 368
369 if (FindPadRowSegment(motifPositionId))
370 return true;
371 else
372 return false;
373}
374
375//______________________________________________________________________________
376TVector2 AliMpVRowSegmentSpecial::MotifCenter(Int_t motifPositionId) const
377{
dee1d5f1 378/// Return the coordinates of the motif specified with
379/// the given position identifier.
ea4cae7a 380
381 // Try to get the motif position from the motif map first
382 AliMpMotifPosition* motifPosition
383 = GetRow()->GetMotifMap()->FindMotifPosition(motifPositionId);
384 if (motifPosition) return motifPosition->Position();
385
386 // Use slow method otherwise
387 return MotifCenterSlow(motifPositionId);
388}
389
390//______________________________________________________________________________
391TVector2 AliMpVRowSegmentSpecial::Dimensions() const
392{
dee1d5f1 393/// Return the halflengths in x, y of the row segment rectangular envelope.
ea4cae7a 394
395 Double_t x = 0.;
396 Double_t y = 0.;
397 for (Int_t i=0; i<GetNofPadRows(); i++) {
398 AliMpPadRow* padRow = GetPadRow(i);
399
400 // Add all pad rows y halfsizes
401 y += padRow->HalfSizeY();
402
403 // Find the biggest pad rows x halfsize
404 Double_t xx
405 = (padRow->GetPadRowSegment(0)->RightBorderX() -
406 padRow->GetPadRowSegment(padRow->GetNofPadRowSegments()-1)->LeftBorderX())/2.;
407 if (xx > x) x = xx;
408 }
409
410 return TVector2(x, y);
411}
412
ea4cae7a 413//______________________________________________________________________________
414AliMpRow* AliMpVRowSegmentSpecial::GetRow() const
415{
dee1d5f1 416/// Return the row.which this row segment belongs to.
ea4cae7a 417
418 return fRow;
419}
420
421//______________________________________________________________________________
422Int_t AliMpVRowSegmentSpecial::GetNofMotifs() const
423{
dee1d5f1 424/// Return the number of different motifs present in this row segment.
ea4cae7a 425
f79c58a5 426#ifdef WITH_STL
ea4cae7a 427 return fMotifs.size();
f79c58a5 428#endif
429#ifdef WITH_ROOT
430 return fMotifs.GetEntriesFast();
431#endif
ea4cae7a 432}
433
434//______________________________________________________________________________
435AliMpVMotif* AliMpVRowSegmentSpecial::GetMotif(Int_t i) const
436{
dee1d5f1 437/// Return the i-th motif present in this row segment.
ea4cae7a 438
f79c58a5 439#ifdef WITH_STL
ea4cae7a 440 return fMotifs[i];
f79c58a5 441#endif
442#ifdef WITH_ROOT
443 return (AliMpVMotif*)fMotifs[i];
444#endif
ea4cae7a 445}
446
447//______________________________________________________________________________
448Int_t AliMpVRowSegmentSpecial::GetMotifPositionId(Int_t i) const
449{
dee1d5f1 450/// Return the i-th motif position Id present in this row segment.
ea4cae7a 451
452 return fMotifPositionIds[i];
453}
454