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