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