]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONDigit.cxx
Made a couple of methods const, and starting to add iteration capability
[u/mrichter/AliRoot.git] / MUON / AliMUONDigit.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 purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 #include "AliMUONDigit.h"
19
20 #include "Riostream.h"
21 #include "TString.h"
22
23 ClassImp(AliMUONDigit)
24
25 namespace
26 {
27   const UInt_t SATURATEDFLAG = 0x1;
28 }
29
30 //_____________________________________________________________________________
31 AliMUONDigit::AliMUONDigit()
32
33 TObject(),
34 fDetElemId(-1),
35 fManuId(-1),
36 fManuChannel(-1),
37 fSignal(0),
38 fPadX(-1),
39 fPadY(-1),
40 fCathode(-1),
41 fADC(0),
42 fFlags(0),
43 fNtracks(0),
44 fTcharges(0x0),
45 fTracks(0x0),
46 fPhysics(0),
47 fHit(0)
48 {
49   //
50   // Default constructor
51   //
52 }
53
54 //_____________________________________________________________________________
55 AliMUONDigit::AliMUONDigit(const AliMUONDigit& digit)
56 : TObject(digit),
57 fDetElemId(-1),
58 fManuId(-1),
59 fManuChannel(-1),
60 fSignal(0),
61 fPadX(-1),
62 fPadY(-1),
63 fCathode(-1),
64 fADC(0),
65 fFlags(0),
66 fNtracks(0),
67 fTcharges(0x0),
68 fTracks(0x0),
69 fPhysics(0),
70 fHit(0)
71 {
72   //
73   // copy constructor
74   //
75    (static_cast<const AliMUONDigit&>(digit)).Copy(*this);
76 }
77
78
79 //_____________________________________________________________________________
80 AliMUONDigit::AliMUONDigit(Int_t *digits)
81 : TObject(),
82 fDetElemId(-1),
83 fManuId(-1),
84 fManuChannel(-1),
85 fSignal(0),
86 fPadX(-1),
87 fPadY(-1),
88 fCathode(-1),
89 fADC(0),
90 fFlags(0),
91 fNtracks(0),
92 fTcharges(0x0),
93 fTracks(0x0),
94 fPhysics(0),
95 fHit(0)
96
97 {
98   //
99   // Creates a MUON digit object to be updated
100   // \deprecated
101   //
102     fPadX        = digits[0];
103     fPadY        = digits[1];
104     fCathode     = digits[2];
105     fSignal      = digits[3];
106     fPhysics     = digits[4];
107     fHit         = digits[5];
108     fDetElemId   = digits[6];
109     fManuId = -1;
110     fManuChannel = -1;
111     fADC=0;
112     fFlags = 0;
113 }
114
115 //_____________________________________________________________________________
116 AliMUONDigit::AliMUONDigit(Int_t *tracks, Int_t *charges, Int_t *digits)
117 : TObject(),
118 fDetElemId(-1),
119 fManuId(-1),
120 fManuChannel(-1),
121 fSignal(0),
122 fPadX(-1),
123 fPadY(-1),
124 fCathode(-1),
125 fADC(0),
126 fFlags(0),
127 fNtracks(0),
128 fTcharges(0x0),
129 fTracks(0x0),
130 fPhysics(0),
131 fHit(0)
132 {
133   //
134   // Creates a MUON digit object
135   //
136   // \deprecated
137     fPadX        = digits[0];
138     fPadY        = digits[1];
139     fCathode     = digits[2];
140     fSignal      = digits[3];
141     fPhysics     = digits[4];
142     fHit         = digits[5];
143     fDetElemId   = digits[6];
144     fManuId = -1;
145     fManuChannel = -1;
146     fADC=0;
147     
148     // For backward compatibility, which assumed 10 tracks.
149     fNtracks = 10;
150     fTcharges = new Int_t[fNtracks];
151     fTracks = new Int_t[fNtracks];
152     
153     for ( Int_t i=0; i<fNtracks; ++i ) 
154     {
155       fTcharges[i]  = charges[i];
156       fTracks[i]    = tracks[i];
157     }
158     fFlags=0;
159 }
160
161 //_____________________________________________________________________________
162 AliMUONDigit::~AliMUONDigit()
163 {
164   //
165   // Destructor 
166   //
167   delete[] fTcharges;
168   delete[] fTracks;
169 }
170
171 //_____________________________________________________________________________
172 void
173 AliMUONDigit::AddTrack(Int_t trackNumber, Int_t trackCharge)
174 {
175   //
176   // Add 1 track information to the track list we keep.
177   // The implementation below is dumb, you've been warned !
178   //
179   
180   // First check if track is already there, in which
181   // case we simply increment its charge.
182   for ( Int_t i = 0; i < Ntracks(); ++i )
183   {
184       if ( Track(i) == trackNumber ) 
185       {
186         fTcharges[i] += trackCharge;
187         return;
188       }
189   }
190   
191   // Nope. It's a brand new track. Make a new array to get space
192   // for it, copy the old array into new one, and add the track.
193   Int_t* newTracks = new Int_t[fNtracks+1];
194   Int_t* newTcharges = new Int_t[fNtracks+1];
195   
196   for ( Int_t i = 0; i < fNtracks; ++i )
197   {
198     newTracks[i] = fTracks[i];
199     newTcharges[i] = fTcharges[i];
200   }
201   
202   newTracks[fNtracks] = trackNumber;
203   newTcharges[fNtracks] = trackCharge;
204   
205   delete[] fTracks;
206   delete[] fTcharges;
207   
208   fTracks = newTracks;
209   fTcharges = newTcharges;
210   
211   ++fNtracks;
212 }
213
214 //_____________________________________________________________________________
215 void 
216 AliMUONDigit::Clear(Option_t*)
217 {
218   //
219   // Reset this digit, in particular the internal arrays are deleted.
220   //
221   delete[] fTracks;
222   delete[] fTcharges;
223   fTracks=0x0;
224   fTcharges=0x0;
225   fNtracks=0;
226 }
227
228 //_____________________________________________________________________________
229 Int_t AliMUONDigit::Compare(const TObject *obj) const
230 {
231   // 
232   // The order defined below is first by DE, then Signal, then 
233   // manuId, and then manuChannel, i.e. it should be a total ordering...
234   //
235
236   const AliMUONDigit* d = static_cast<const AliMUONDigit*>(obj);
237   
238   if ( DetElemId() > d->DetElemId() ) 
239   {
240     return 1;
241   }
242   else if ( DetElemId() < d->DetElemId() )
243   {
244     return -1;
245   }
246   else
247   {
248     if ( Signal() > d->Signal() )
249     {
250       return 1;
251     }
252     else if ( Signal() < d->Signal() )
253     {
254       return -1;
255     }
256     else
257     {
258       if ( ManuId() < d->ManuId() )
259       {
260         return 1;
261       }
262       else if ( ManuId() > d->ManuId() )
263       {
264         return -1;
265       }
266       else
267       {
268         return ( ManuChannel() < d->ManuChannel() ) ? 1 : -1;
269       }
270     }
271   }
272 }
273
274 //______________________________________________________________________________
275 void 
276 AliMUONDigit::Copy(TObject& obj) const
277 {
278   //
279   // Copy this line to line.
280   //
281   TObject::Copy(obj);
282   AliMUONDigit& digit = static_cast<AliMUONDigit&>(obj);
283   
284   digit.fDetElemId = fDetElemId;
285   digit.fManuId = fManuId;
286   digit.fManuChannel = fManuChannel;
287   digit.fSignal = fSignal;
288   
289   digit.fPadX = fPadX;
290   digit.fPadY = fPadY;
291   digit.fCathode = fCathode;
292   digit.fADC = fADC;
293   digit.fFlags = fFlags;
294   
295   digit.fNtracks = fNtracks;
296   
297   delete[] digit.fTcharges;
298   delete[] digit.fTracks;
299   
300   if ( fNtracks )
301   {
302     digit.fTcharges = new Int_t[fNtracks];
303     digit.fTracks = new Int_t[fNtracks];
304   }
305   
306   for ( Int_t i=0; i<fNtracks; ++i ) 
307   {
308     digit.fTcharges[i] = fTcharges[i];
309     digit.fTracks[i] = fTracks[i];
310   }
311   
312   digit.fPhysics = fPhysics;
313   digit.fHit = fHit;
314 }
315
316 //_____________________________________________________________________________
317 Bool_t
318 AliMUONDigit::IsSaturated() const
319 {
320   return (fFlags & SATURATEDFLAG );
321 }
322
323 //_____________________________________________________________________________
324 AliMUONDigit& 
325 AliMUONDigit::operator=(const AliMUONDigit& digit)
326 {
327   //
328   // Assignement operator.
329   //
330   AliMUONDigit a(digit);
331   a.Copy(*this);
332   return *this;
333 }
334
335 //_____________________________________________________________________________
336 void
337 AliMUONDigit::PatchTracks(Int_t mask)
338 {
339   //
340   // Add mask to each track number.
341   //
342   for ( Int_t i = 0; i < Ntracks(); ++i )
343   {
344     fTracks[i] += mask;
345   }
346 }
347
348 //_____________________________________________________________________________
349 void
350 AliMUONDigit::Print(Option_t* opt) const
351 {
352   //
353   // Dump to screen.
354   // If opt=="tracks", info on tracks are printed too.
355   //
356   cout << "DetEle " << setw(5) << DetElemId()
357   << " Cath " << setw(2) << Cathode()
358   << " (Ix,Iy)=(" << setw(3) << PadX() << "," << setw(3) << PadY()
359   << ") "
360   << " (Manu,Channel)=(" << setw(4) << ManuId() 
361   << "," << setw(3) << ManuChannel() << ")"
362   << " Signal=" << setw(6) << Signal()
363   << " Physics=" << setw(4) << Physics();
364   if ( IsSaturated() ) 
365   {
366     cout << "(S)";
367   }
368   else
369   {
370     cout << "   ";
371   }
372   cout << " ADC=" << setw(4) << ADC();
373   TString options(opt);
374   options.ToLower();
375   if ( options.Contains("tracks") )
376   {
377     cout << " Hit " << setw(3) << Hit();
378     Int_t ntracks = Ntracks();
379     if (ntracks) 
380     {
381       cout << " Tracks : " << setw(2) << ntracks;
382       for ( Int_t i = 0; i < ntracks; ++i )
383       {
384         cout << " Track(" << i << ")=" << setw(3) << Track(i)
385         << " Charge(" << i << ")=" << setw(5) << TrackCharge(i);
386       }
387     }
388     else
389     {
390       cout << " no track info.";
391     }
392   }
393   cout << endl;  
394 }
395
396 //_____________________________________________________________________________
397 void
398 AliMUONDigit::Saturated(Bool_t value)
399 {
400   if ( value )
401   {
402     fFlags |= SATURATEDFLAG;
403   }
404   else
405   {
406     fFlags ^= SATURATEDFLAG;
407   }
408 }
409
410 //_____________________________________________________________________________
411 void
412 AliMUONDigit::SetElectronics(Int_t manuId, Int_t manuChannel)
413 {
414   //
415   //FIXME: should we check that the values are ok here ??
416   //
417   fManuId=manuId;
418   fManuChannel=manuChannel;
419 }
420
421 //_____________________________________________________________________________
422 Int_t
423 AliMUONDigit::Track(Int_t i) const
424 {
425   //
426   // Return the i-th track number (if i is >=0 and < Ntracks()) or -1.
427   //
428   if ( i >= 0 && i < fNtracks ) 
429   {
430     return fTracks[i];
431   }
432
433   return -1;
434 }
435
436 //_____________________________________________________________________________
437 Int_t
438 AliMUONDigit::TrackCharge(Int_t i) const
439 {
440   //
441   // Return the i-th track charge (if i is >=0 and < Ntracjs()) or -1.
442   //
443   if ( i >= 0 && i < fNtracks ) 
444   {
445     return fTcharges[i];
446   }
447
448   return -1;
449 }