]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALRawDigit.cxx
re-activate contrib code
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALRawDigit.cxx
CommitLineData
916f1e76 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 **************************************************************************/
de39a0ff 15/*
16
17
18
19
20 Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
21*/
916f1e76 22
23// --- ROOT system ---
24#include <Riostream.h>
25#include <TMath.h>
26
916f1e76 27// --- AliRoot header files ---
916f1e76 28#include "AliEMCALRawDigit.h"
de39a0ff 29#include "AliLog.h"
916f1e76 30
31ClassImp(AliEMCALRawDigit)
32
33//____________________________________________________________________________
34AliEMCALRawDigit::AliEMCALRawDigit() : TObject(),
35fId(-1),
36fNSamples(0),
de39a0ff 37fSamples(0x0),
38fAmplitude(0),
39fTime(0)
916f1e76 40{
41 // default ctor
42}
43
44//____________________________________________________________________________
45AliEMCALRawDigit::AliEMCALRawDigit(Int_t id, Int_t timeSamples[], Int_t nSamples) : TObject(),
46fId(id),
47fNSamples(nSamples),
de39a0ff 48fSamples(0x0),
49fAmplitude(0),
50fTime(0)
916f1e76 51{
52 //
de39a0ff 53 fSamples = new Int_t[fNSamples];
54 for (Int_t i = 0; i < fNSamples; i++) fSamples[i] = timeSamples[i];
916f1e76 55}
56
57//____________________________________________________________________________
58AliEMCALRawDigit::~AliEMCALRawDigit()
59{
de39a0ff 60 //dtor, delete array of time samples
b57cc9b9 61 if(fSamples) delete [] fSamples;
916f1e76 62}
63
e0dc3f7d 64//____________________________________________________________________________
65void AliEMCALRawDigit::Clear(Option_t *)
66{
de39a0ff 67 // clear, delete array of time samples
b57cc9b9 68 if(fSamples) delete [] fSamples;
e0dc3f7d 69}
70
71
916f1e76 72//____________________________________________________________________________
73Bool_t AliEMCALRawDigit::GetTimeSample(const Int_t iSample, Int_t& timeBin, Int_t& amp) const
74{
a520bcd0 75 // returns the time and amplitude of a given time sample and if the sample was ok
76
916f1e76 77 if (iSample > fNSamples || iSample < 0) return kFALSE;
78
28bcaaaa 79 amp = (Short_t)(fSamples[iSample] & 0xFFFF);
80 timeBin = (Short_t)(fSamples[iSample] >> 16 );
916f1e76 81
82 return kTRUE;
83}
84
85//____________________________________________________________________________
de39a0ff 86void AliEMCALRawDigit::SetTimeSamples(const Int_t timeSamples[], const Int_t nSamples)
916f1e76 87{
a520bcd0 88 // Sets the time samples
89
de39a0ff 90 if (fSamples)
916f1e76 91 {
aa878a7b 92 AliDebug(1,"Samples already filled: delete first!");
de39a0ff 93 fNSamples = 0;
94 delete [] fSamples;
916f1e76 95 }
96
de39a0ff 97 fNSamples = nSamples;
98 fSamples = new Int_t[fNSamples];
99 for (Int_t i = 0; i < fNSamples; i++) fSamples[i] = timeSamples[i];
916f1e76 100}
101
102//____________________________________________________________________________
de39a0ff 103Bool_t AliEMCALRawDigit::GetMaximum(Int_t& amplitude, Int_t& time) const
104{
a520bcd0 105 // Checks the maximum amplitude in the time sample
106
de39a0ff 107 if (!fNSamples)
108 {
aa878a7b 109 AliDebug(1,"Digit has no time sample");
de39a0ff 110 return kFALSE;
111 }
112
113 amplitude = 0;
114 for (Int_t i = 0; i < fNSamples; i++)
115 {
116 Int_t t, a;
117 if (GetTimeSample(i, t, a))
118 {
119 if (a > amplitude)
120 {
121 amplitude = a;
122 time = t;
123 }
124 }
125 }
126
127 return kTRUE;
128}
129
130//____________________________________________________________________________
131Int_t AliEMCALRawDigit::Compare(const TObject * obj) const
916f1e76 132{
133 // Compares two digits with respect to its Id
134 // to sort according increasing Id
de39a0ff 135
136 Int_t rv=0;
137
138 AliEMCALRawDigit* digit = (AliEMCALRawDigit*)obj;
139
140 Int_t iddiff = fId - digit->GetId();
141
142 if (iddiff > 0)
143 rv = 1;
144 else if (iddiff < 0)
916f1e76 145 rv = -1;
146 else
de39a0ff 147 rv = 0;
148
916f1e76 149 return rv;
150}
151
152//____________________________________________________________________________
de39a0ff 153void AliEMCALRawDigit::Print(const Option_t* /*opt*/) const
916f1e76 154{
a520bcd0 155 // print
156
de39a0ff 157 printf("===\n| Digit id: %4d / %d Time Samples: \n",fId,fNSamples);
158 for (Int_t i=0; i < fNSamples; i++)
159 {
160 Int_t timeBin=-1, amp=0;
161 GetTimeSample(i, timeBin, amp);
162 printf("| (%d,%d) ",timeBin,amp);
163 }
164
165 printf("\n");
916f1e76 166}