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