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