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