]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONDigit.cxx
Adding new classes (Laurent)
[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 void
255 AliMUONDigit::NoiseOnly(Bool_t value)
256 {
257   /// Set the NoiseOnly status of this digit.
258
259   if ( value )
260   {
261     fFlags |= fgkNoiseOnlyMask;
262   }
263   else
264   {
265     fFlags ^= fgkNoiseOnlyMask;
266   }
267 }
268
269 //_____________________________________________________________________________
270 AliMUONDigit& 
271 AliMUONDigit::operator=(const AliMUONDigit& digit)
272 {
273   /// Assignement operator.
274
275   AliMUONDigit a(digit);
276   a.Copy(*this);
277   return *this;
278 }
279
280 //_____________________________________________________________________________
281 void
282 AliMUONDigit::PatchTracks(Int_t mask)
283 {
284   /// Add mask to each track number.
285
286   for ( Int_t i = 0; i < Ntracks(); ++i )
287   {
288     fTracks[i] += mask;
289   }
290 }
291
292 //_____________________________________________________________________________
293 void
294 AliMUONDigit::Print(Option_t* opt) const
295 {
296   /// Dump to screen.
297   /// If opt=="tracks", info on tracks are printed too.
298
299   cout << Form("<AliMUONDigit>: DE %4d Cath %d (Ix,Iy)=(%3d,%3d) (Manu,Channel)=(%4d,%2d)"
300                ", Signal=%7.2f Physics=%7.2f",
301                DetElemId(),Cathode(),PadX(),PadY(),ManuId(),ManuChannel(),Signal(),
302                Physics());
303   
304   if ( IsSaturated() ) 
305   {
306     cout << "(S)";
307   }
308   else
309   {
310     cout << "   ";
311   }
312   cout << " ADC=" << setw(4) << ADC();
313   cout << " Flags=0x" << setw(4) << hex << setfill('0') << fFlags << dec
314     << setfill(' ');
315   cout << " StatusMap=0x" << setw(4) << hex << setfill('0') << StatusMap() << dec
316     << setfill(' ');
317
318   TString options(opt);
319   options.ToLower();
320   if ( options.Contains("tracks") )
321   {
322     cout << " Hit " << setw(3) << Hit();
323     Int_t ntracks = Ntracks();
324     if (ntracks) 
325     {
326       cout << " Tracks : " << setw(2) << ntracks;
327       for ( Int_t i = 0; i < ntracks; ++i )
328       {
329         cout << " Track(" << i << ")=" << setw(3) << Track(i)
330         << " Charge(" << i << ")=" << setw(5) << TrackCharge(i);
331       }
332     }
333     else
334     {
335       cout << " no track info.";
336     }
337   }
338   cout << endl;  
339 }
340
341 //_____________________________________________________________________________
342 void
343 AliMUONDigit::Saturated(Bool_t value)
344 {
345   /// Set the saturation status of this digit.
346
347   if ( value )
348   {
349     fFlags |= fgkSaturatedMask;
350   }
351   else
352   {
353     fFlags ^= fgkSaturatedMask;
354   }
355 }
356
357 //_____________________________________________________________________________
358 void
359 AliMUONDigit::SetElectronics(Int_t manuId, Int_t manuChannel)
360 {
361   //
362   //FIXME: should we check that the values are ok here ??
363   //
364   fManuId=manuId;
365   fManuChannel=manuChannel;
366 }
367
368 //_____________________________________________________________________________
369 Int_t
370 AliMUONDigit::Track(Int_t i) const
371 {
372   /// Return the i-th track number (if i is >=0 and < Ntracks()) or -1.
373
374   if ( i >= 0 && i < fNtracks ) 
375   {
376     return fTracks[i];
377   }
378
379   return -1;
380 }
381
382 //_____________________________________________________________________________
383 Float_t
384 AliMUONDigit::TrackCharge(Int_t i) const
385 {
386   /// Return the i-th track charge (if i is >=0 and < Ntracjs()) or -1.
387
388   if ( i >= 0 && i < fNtracks ) 
389   {
390     return fTcharges[i];
391   }
392
393   return -1;
394 }