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