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