Class to produce PHOS digits from raw data stream.
[u/mrichter/AliRoot.git] / PHOS / AliPHOSRawDigiProducer.cxx
CommitLineData
88fb5e50 1#include "TClonesArray.h"
2
3#include "AliPHOSRawDigiProducer.h"
4#include "AliPHOSRawDecoder.h"
5#include "AliPHOSGeometry.h"
6#include "AliPHOSDigit.h"
7
8ClassImp(AliPHOSRawDigiProducer)
9
10void AliPHOSRawDigiProducer::MakeDigits(TClonesArray *digits, AliPHOSRawDecoder* decoder)
11{
12 digits->Clear();
13
14 AliPHOSGeometry* geo = AliPHOSGeometry::GetInstance();
15 if(!geo) geo = AliPHOSGeometry::GetInstance("IHEP");
16
17 Int_t iDigit = 0 ;
18 Double_t time = 0. ;
19 Int_t iOldDigit;
20 Bool_t seen,lowGainFlag;
21 Int_t relId[4], absId =0;
22
23 while (decoder->NextDigit()) {
24
25 lowGainFlag = decoder->IsLowGain();
26 time = decoder->GetTime();
27
28 relId[0] = decoder->GetModule();
29 relId[1] = 0;
30 relId[2] = decoder->GetRow();
31 relId[3] = decoder->GetColumn();
32 geo->RelToAbsNumbering(relId, absId);
33
34 // Add low gain digit only
35 //if the high gain digit does not exist in the digits array
36
37 seen = kFALSE;
38
39 if(lowGainFlag) {
40 for (iOldDigit=iDigit-1; iOldDigit>=0; iOldDigit--) {
41 if ((dynamic_cast<AliPHOSDigit*>(digits->At(iOldDigit)))->GetId() == absId) {
42 seen = kTRUE;
43 break;
44 }
45 }
46 if (!seen) {
47 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,(Float_t)decoder->GetEnergy(),time);
48 iDigit++;
49 }
50 }
51
52 // Add high gain digit only if it is not saturated;
53 // replace low gain digit by a high gain one
54 else {
55 if (decoder->GetEnergy() >= 1023) continue;
56 for (iOldDigit=iDigit-1; iOldDigit>=0; iOldDigit--) {
57 if ((dynamic_cast<AliPHOSDigit*>(digits->At(iOldDigit)))->GetId() == absId) {
58 digits->RemoveAt(iOldDigit);
59 new((*digits)[iOldDigit]) AliPHOSDigit(-1,absId,(Float_t)decoder->GetEnergy(),time);
60 seen = kTRUE;
61 break;
62 }
63 }
64 if (!seen) {
65 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,(Float_t)decoder->GetEnergy(),time);
66 iDigit++;
67 }
68 }
69
70 }
71
72 digits->Compress();
73 digits->Sort();
74}