]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONDigit.cxx
Comments for Doxygen (mostly added comments for inline functions)
[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.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.0),
56 fHit(0),
57 fStatusMap(0)
58 {
59   /// Default constructor
60 }
61
62 //_____________________________________________________________________________
63 AliMUONDigit::AliMUONDigit(const AliMUONDigit& digit)
64 : TObject(digit),
65 fDetElemId(-1),
66 fManuId(-1),
67 fManuChannel(-1),
68 fSignal(0.0),
69 fPadX(-1),
70 fPadY(-1),
71 fCathode(-1),
72 fADC(0),
73 fFlags(0),
74 fNtracks(0),
75 fTcharges(0x0),
76 fTracks(0x0),
77 fPhysics(0.0),
78 fHit(0),
79 fStatusMap(0)
80 {
81   /// Copy constructor
82
83    (static_cast<const AliMUONDigit&>(digit)).Copy(*this);
84 }
85
86 //_____________________________________________________________________________
87 AliMUONDigit::~AliMUONDigit()
88 {
89   /// Destructor 
90
91   delete[] fTcharges;
92   delete[] fTracks;
93 }
94
95 //_____________________________________________________________________________
96 void
97 AliMUONDigit::AddTrack(Int_t trackNumber, Float_t trackCharge)
98 {
99   /// Add 1 track information to the track list we keep.
100   /// The implementation below is dumb, you've been warned !
101   
102   // First check if track is already there, in which
103   // case we simply increment its charge.
104   for ( Int_t i = 0; i < Ntracks(); ++i )
105   {
106       if ( Track(i) == trackNumber ) 
107       {
108         fTcharges[i] += trackCharge;
109         return;
110       }
111   }
112   
113   // Nope. It's a brand new track. Make a new array to get space
114   // for it, copy the old array into new one, and add the track.
115   Int_t* newTracks = new Int_t[fNtracks+1];
116   Float_t* newTcharges = new Float_t[fNtracks+1];
117   
118   for ( Int_t i = 0; i < fNtracks; ++i )
119   {
120     newTracks[i] = fTracks[i];
121     newTcharges[i] = fTcharges[i];
122   }
123   
124   newTracks[fNtracks] = trackNumber;
125   newTcharges[fNtracks] = trackCharge;
126   
127   delete[] fTracks;
128   delete[] fTcharges;
129   
130   fTracks = newTracks;
131   fTcharges = newTcharges;
132   
133   ++fNtracks;
134 }
135
136 //_____________________________________________________________________________
137 void 
138 AliMUONDigit::Clear(Option_t*)
139 {
140   /// Reset this digit, in particular the internal arrays are deleted.
141
142   delete[] fTracks;
143   delete[] fTcharges;
144   fTracks=0x0;
145   fTcharges=0x0;
146   fNtracks=0;
147 }
148
149 //_____________________________________________________________________________
150 Int_t AliMUONDigit::Compare(const TObject *obj) const
151 {
152   /// The order defined below is first by DE, then Signal, then 
153   /// manuId, and then manuChannel, i.e. it should be a total ordering...
154
155   const AliMUONDigit* d = static_cast<const AliMUONDigit*>(obj);
156   
157   if ( DetElemId() > d->DetElemId() ) 
158   {
159     return 1;
160   }
161   else if ( DetElemId() < d->DetElemId() )
162   {
163     return -1;
164   }
165   else
166   {
167     if ( Signal() > d->Signal() )
168     {
169       return 1;
170     }
171     else if ( Signal() < d->Signal() )
172     {
173       return -1;
174     }
175     else
176     {
177       if ( ManuId() < d->ManuId() )
178       {
179         return 1;
180       }
181       else if ( ManuId() > d->ManuId() )
182       {
183         return -1;
184       }
185       else
186       {
187         return ( ManuChannel() < d->ManuChannel() ) ? 1 : -1;
188       }
189     }
190   }
191 }
192
193 //______________________________________________________________________________
194 void 
195 AliMUONDigit::Copy(TObject& obj) const
196 {
197   /// Copy this line to line.
198
199   TObject::Copy(obj);
200   AliMUONDigit& digit = static_cast<AliMUONDigit&>(obj);
201   
202   digit.fDetElemId = fDetElemId;
203   digit.fManuId = fManuId;
204   digit.fManuChannel = fManuChannel;
205   digit.fSignal = fSignal;
206   
207   digit.fPadX = fPadX;
208   digit.fPadY = fPadY;
209   digit.fCathode = fCathode;
210   digit.fADC = fADC;
211   digit.fFlags = fFlags;
212   
213   digit.fNtracks = fNtracks;
214   
215   delete[] digit.fTcharges;
216   delete[] digit.fTracks;
217   
218   if ( fNtracks )
219   {
220     digit.fTcharges = new Float_t[fNtracks];
221     digit.fTracks = new Int_t[fNtracks];
222   }
223   
224   for ( Int_t i=0; i<fNtracks; ++i ) 
225   {
226     digit.fTcharges[i] = fTcharges[i];
227     digit.fTracks[i] = fTracks[i];
228   }
229   
230   digit.fPhysics = fPhysics;
231   digit.fHit = fHit;
232   digit.fStatusMap = fStatusMap;
233 }
234
235 //_____________________________________________________________________________
236 Bool_t
237 AliMUONDigit::IsNoiseOnly() const
238 {
239   /// Whether this (simulated only) digit is only due to noise.
240
241   return (fFlags & fgkNoiseOnlyMask );
242 }
243
244 //_____________________________________________________________________________
245 Bool_t
246 AliMUONDigit::IsSaturated() const
247 {
248   /// Whether this digit is saturated or not.
249
250   return (fFlags & fgkSaturatedMask );
251 }
252
253 //_____________________________________________________________________________
254 Bool_t
255 AliMUONDigit::IsEfficiencyApplied() const
256 {
257   /// Whether this digit had efficiency applied or not
258   
259   return (fFlags & fgkEfficiencyMask );
260 }
261
262 //_____________________________________________________________________________
263 void
264 AliMUONDigit::EfficiencyApplied(Bool_t value)
265 {
266   /// Set the EfficiencyApplied status of this digit.
267   
268   if ( value )
269   {
270     fFlags |= fgkEfficiencyMask;
271   }
272   else
273   {
274     fFlags ^= fgkEfficiencyMask;
275   }
276 }
277
278 //_____________________________________________________________________________
279 void
280 AliMUONDigit::NoiseOnly(Bool_t value)
281 {
282   /// Set the NoiseOnly status of this digit.
283
284   if ( value )
285   {
286     fFlags |= fgkNoiseOnlyMask;
287   }
288   else
289   {
290     fFlags ^= fgkNoiseOnlyMask;
291   }
292 }
293
294 //_____________________________________________________________________________
295 AliMUONDigit& 
296 AliMUONDigit::operator=(const AliMUONDigit& digit)
297 {
298   /// Assignement operator.
299
300   AliMUONDigit a(digit);
301   a.Copy(*this);
302   return *this;
303 }
304
305 //_____________________________________________________________________________
306 void
307 AliMUONDigit::PatchTracks(Int_t mask)
308 {
309   /// Add mask to each track number.
310
311   for ( Int_t i = 0; i < Ntracks(); ++i )
312   {
313     fTracks[i] += mask;
314   }
315 }
316
317 //_____________________________________________________________________________
318 void
319 AliMUONDigit::Print(Option_t* opt) const
320 {
321   /// Dump to screen.
322   /// If opt=="tracks", info on tracks are printed too.
323
324   cout << Form("<AliMUONDigit>: DE %4d Cath %d (Ix,Iy)=(%3d,%3d) (Manu,Channel)=(%4d,%2d)"
325                ", Signal=%7.2f Physics=%7.2f",
326                DetElemId(),Cathode(),PadX(),PadY(),ManuId(),ManuChannel(),Signal(),
327                Physics());
328   
329   if ( IsSaturated() ) 
330   {
331     cout << "(S)";
332   }
333   else
334   {
335     cout << "   ";
336   }
337   cout << " ADC=" << setw(4) << ADC();
338   cout << " Flags=0x" << setw(4) << hex << setfill('0') << fFlags << dec
339     << setfill(' ');
340   cout << " StatusMap=0x" << setw(4) << hex << setfill('0') << StatusMap() << dec
341     << setfill(' ');
342
343   TString options(opt);
344   options.ToLower();
345   if ( options.Contains("tracks") )
346   {
347     cout << " Hit " << setw(3) << Hit();
348     Int_t ntracks = Ntracks();
349     if (ntracks) 
350     {
351       cout << " Tracks : " << setw(2) << ntracks;
352       for ( Int_t i = 0; i < ntracks; ++i )
353       {
354         cout << " Track(" << i << ")=" << setw(3) << Track(i)
355         << " Charge(" << i << ")=" << setw(5) << TrackCharge(i);
356       }
357     }
358     else
359     {
360       cout << " no track info.";
361     }
362   }
363   cout << endl;  
364 }
365
366 //_____________________________________________________________________________
367 void
368 AliMUONDigit::Saturated(Bool_t value)
369 {
370   /// Set the saturation status of this digit.
371
372   if ( value )
373   {
374     fFlags |= fgkSaturatedMask;
375   }
376   else
377   {
378     fFlags ^= fgkSaturatedMask;
379   }
380 }
381
382 //_____________________________________________________________________________
383 void
384 AliMUONDigit::SetElectronics(Int_t manuId, Int_t manuChannel)
385 {
386   /// Set manuIs and manuChannel
387
388   //
389   //FIXME: should we check that the values are ok here ??
390   //
391   fManuId=manuId;
392   fManuChannel=manuChannel;
393 }
394
395 //_____________________________________________________________________________
396 Int_t
397 AliMUONDigit::Track(Int_t i) const
398 {
399   /// Return the i-th track number (if i is >=0 and < Ntracks()) or -1.
400
401   if ( i >= 0 && i < fNtracks ) 
402   {
403     return fTracks[i];
404   }
405
406   return -1;
407 }
408
409 //_____________________________________________________________________________
410 Float_t
411 AliMUONDigit::TrackCharge(Int_t i) const
412 {
413   /// Return the i-th track charge (if i is >=0 and < Ntracjs()) or -1.
414
415   if ( i >= 0 && i < fNtracks ) 
416   {
417     return fTcharges[i];
418   }
419
420   return -1;
421 }