]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpTrigger.cxx
Modifying ownership of slats (Laurent)
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpTrigger.cxx
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 purpeateose. It is      *
13 * provided "as is" without express or implied warranty.                  *
14 **************************************************************************/
15
16 // $Id$
17 // $MpId: AliMpTrigger.cxx,v 1.4 2006/05/24 13:58:52 ivana Exp $
18
19 #include "AliMpTrigger.h"
20 #include "AliMpSlatSegmentation.h"
21 #include "AliMpConstants.h"
22 #include "AliLog.h"
23 #include "AliMpSlat.h"
24
25 #include "Riostream.h"
26 #include "TArrayI.h"
27 #include "TObjArray.h"
28
29 /// 
30 /// \class AliMpTrigger
31 /// 
32 /// A trigger 'slat' object. 
33 /// It is to be viewed as a superposition of  
34 /// virtual layers of AliMpSlat objects. The need for more than one layer  
35 /// arise from the fact that a given local board deals with strips  
36 /// located in different detelem. So a given strip (pad) can have several  
37 /// "locations".
38 ///
39 /// \author Laurent Aphecetche
40
41 /// \cond CLASSIMP
42 ClassImp(AliMpTrigger)
43 /// \endcond
44
45 namespace
46 {
47   Bool_t IsEqual(Double_t a, Double_t b, Double_t precision)
48 {
49     if (b)
50     {
51       Double_t diff = TMath::Abs(b-a)/TMath::Abs(b);
52       if ( diff < precision ) 
53       {
54         return kTRUE;
55       }
56     }
57     else
58     {
59       if ( !a ) return kTRUE;
60     }
61     return kFALSE;
62 }
63 }
64
65 //_____________________________________________________________________________
66 AliMpTrigger::AliMpTrigger()
67 : TObject(), 
68   fId(""), 
69   fPlaneType(kNonBendingPlane), 
70   fSlats(0),
71   fSlatSegmentations(0),
72   fMaxNofPadsY(0),
73   fDX(0), 
74   fDY(0)
75 {
76   // default ctor
77
78   AliDebugStream(1) << "this = " << this << endl;
79
80   fSlats.SetOwner(kFALSE);
81   fSlatSegmentations.SetOwner(kTRUE);
82 }
83
84 //_____________________________________________________________________________
85 AliMpTrigger::AliMpTrigger(const char* slatType, AliMpPlaneType bendingOrNot)
86     :  TObject(), 
87        fId(slatType), 
88        fPlaneType(bendingOrNot), 
89        fSlats(0),
90        fSlatSegmentations(0),
91        fMaxNofPadsY(0), 
92        fDX(0), 
93        fDY(0)
94 {
95   // normal ctor
96
97   AliDebugStream(1) << "this = " << this << endl;
98
99   fSlats.SetOwner(kFALSE);
100   fSlatSegmentations.SetOwner(kTRUE);
101 }
102
103 //_____________________________________________________________________________
104 AliMpTrigger::~AliMpTrigger()
105 {
106   // dtor
107   AliDebugStream(1) << "this = " << this << endl;
108
109   fSlatSegmentations.Delete();
110 }
111
112 //_____________________________________________________________________________
113 Bool_t
114 AliMpTrigger::AdoptLayer(AliMpSlat* slat)
115 {
116   // Adopt (i.e. we become owner of that pointer) a slat, as 
117   // a layer of this trigger slat.
118
119   AliDebug(2,Form("%s is adopting %s ",
120                   GetID(),slat->GetID()));
121
122   // Check that we keep our size constant.
123     
124   if ( GetSize() > 0 && 
125        ( !::IsEqual(slat->DX(),fDX,AliMpConstants::LengthTolerance()) || 
126          !::IsEqual(slat->DY(),fDY,AliMpConstants::LengthTolerance()) )
127      )
128   {
129     AliError(Form("In %s trying to add a layer (%e,%e) (layer #%d) "
130                   "of a different size than mine (%e,%e)",
131                   GetID(),slat->DX(),slat->DY(),fSlats.GetEntries(),
132                   fDX,fDY));
133     return kFALSE;
134   }
135   fSlats.Add(slat);
136   Bool_t owner(kTRUE);
137   // the slat segmentation will be the owner of the slat, and will delete
138   // it when it'll be deleted itself
139   fSlatSegmentations.Add(new AliMpSlatSegmentation(slat,owner));
140   fMaxNofPadsY = std::max(slat->GetMaxNofPadsY(),fMaxNofPadsY);
141   fDX = std::max(fDX,slat->DX());
142   fDY = std::max(fDY,slat->DY());
143   return kTRUE;
144 }
145
146 //_____________________________________________________________________________
147 TVector2
148 AliMpTrigger::Dimensions() const
149 {
150   // Returns the dimensions (half-sizes) of that slat (cm)
151   return TVector2(DX(),DY());
152 }
153
154 //_____________________________________________________________________________
155 Double_t
156 AliMpTrigger::DX() const
157 {
158   // Returns the half-size in X (cm)
159   return fDX;
160 }
161
162 //_____________________________________________________________________________
163 Double_t
164 AliMpTrigger::DY() const
165 {
166   // Returns the half-size in Y (cm)
167   return fDY;
168 }
169
170 //_____________________________________________________________________________
171 void 
172 AliMpTrigger::GetAllLocalBoardNumbers(TArrayI& lbn) const
173 {
174   // Fills lbn with the local board numbers we're dealing with
175   Int_t n(0);
176   for ( Int_t i = 0; i < GetSize(); ++i )
177   {
178     n += GetLayer(i)->GetNofElectronicCards();
179   }
180   
181   lbn.Set(n);
182
183   Int_t index(0);
184   
185   for ( Int_t i = 0; i < GetSize(); ++i )
186   {
187     TArrayI slbn;
188     GetLayer(i)->GetAllMotifPositionsIDs(slbn);
189     for ( Int_t j = 0; j < slbn.GetSize(); ++j )
190     {
191       lbn[index] = slbn[j];
192       ++index;
193     }
194   }
195 }
196
197 //_____________________________________________________________________________
198 const char*
199 AliMpTrigger::GetID() const
200 {
201   // returns the id of this slat
202   return fId.Data();
203 }
204
205 //_____________________________________________________________________________
206 const char*
207 AliMpTrigger::GetName() const
208 {
209   // returns the name (=id+bending/non-bending) of this slat
210   TString name(GetID());
211   if ( fPlaneType == kBendingPlane )
212   {
213     name += ".Bending";
214   }
215   else if ( fPlaneType == kNonBendingPlane )
216   {
217     name += ".NonBending";
218   }
219   else
220   {
221     name += ".Invalid";
222   }
223   return name.Data();
224 }
225
226 //_____________________________________________________________________________
227 AliMpSlat*
228 AliMpTrigger::GetLayer(int layer) const
229 {
230   // Returns a given layer
231   if ( IsLayerValid(layer) )
232   {
233     return (AliMpSlat*)fSlats.At(layer);
234   }
235   return 0;
236 }
237
238 //_____________________________________________________________________________
239 AliMpVSegmentation*
240 AliMpTrigger::GetLayerSegmentation(int layer) const
241 {
242   // Returns a given layer
243   if ( IsLayerValid(layer) )
244   {
245     return (AliMpSlatSegmentation*)fSlatSegmentations.At(layer);
246   }
247   return 0;
248 }
249
250 //_____________________________________________________________________________
251 Int_t
252 AliMpTrigger::GetNofPadsX() const
253 {
254   // Returns the number of pad in x direction
255   if ( !GetSize() ) return -1;
256   if ( GetLayer(0) )
257   {
258     return GetLayer(0)->GetNofPadsX();
259   }
260   return -1;
261 }
262
263 //_____________________________________________________________________________
264 Int_t
265 AliMpTrigger::GetMaxNofPadsY() const
266 {
267   // Maximum number of pads in y direction
268   return fMaxNofPadsY;
269 }
270
271 //_____________________________________________________________________________
272 Int_t
273 AliMpTrigger::GetSize() const
274 {
275   // Number of layers
276   return fSlats.GetEntriesFast();
277 }
278
279 //_____________________________________________________________________________
280 Bool_t
281 AliMpTrigger::IsLayerValid(int layer) const
282 {
283   // Whether a given layer index is valid or not
284   if ( layer >= 0 && layer < GetSize() )
285   {
286     return kTRUE;
287   }
288   return kFALSE;
289 }
290
291 //_____________________________________________________________________________
292 AliMpPlaneType
293 AliMpTrigger::PlaneType() const
294 {
295   // Bending or not
296   return fPlaneType;
297 }
298
299 //_____________________________________________________________________________
300 TVector2
301 AliMpTrigger::Position() const
302 {
303   // Slat position (cm)
304   return TVector2(DX(),DY());
305 }
306
307 //_____________________________________________________________________________
308 void
309 AliMpTrigger::Print(Option_t* opt) const
310 {
311   // Dump on screen
312   cout << "AliMpTrigger::" << GetID();
313   if ( GetSize() == 0 )
314   {
315     cout << " Empty";
316   }
317   else if ( GetSize() > 1 )
318   {
319     cout << " Number of layers : " << GetSize();
320   }
321   else 
322   {
323     cout << " One layer";
324   }
325   cout << endl;
326   for ( Int_t i = 0; i < GetSize(); ++i ) 
327   {
328     cout << "   ";
329     GetLayer(i)->Print(opt);
330   }
331 }
332
333 //_____________________________________________________________________________
334 //_____________________________________________________________________________
335 //_____________________________________________________________________________
336 //_____________________________________________________________________________