The web becomes richer
[u/mrichter/AliRoot.git] / PHOS / AliPHOSDigit.cxx
CommitLineData
d15a28e7 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
b2a60966 16/* $Id$ */
17
d15a28e7 18//_________________________________________________________________________
b2a60966 19// PHOS digit: Id
20// energy
21// 3 identifiers for the primary particle(s) at the origine of the digit
22// The digits are made in FinishEvent() by summing all the hits in a single PHOS crystal or PPSD gas cell
23// It would be nice to replace the 3 identifiers by an array, but, because digits are kept in a TClonesQArray,
24// it is not possible to stream such an array... (beyond my understqnding!)
25//
26//*-- Author: Laurent Aphecetche & Yves Schutz (SUBATECH)
27
d15a28e7 28
29// --- ROOT system ---
30
31// --- Standard library ---
32
33#include <iostream>
34
35// --- AliRoot header files ---
36
37#include "AliPHOSDigit.h"
38
39
40ClassImp(AliPHOSDigit)
41
42//____________________________________________________________________________
f741ce93 43 AliPHOSDigit::AliPHOSDigit()
cf239357 44{
b2a60966 45 // default ctor
46
26d4b141 47 fNprimary = 0 ;
f741ce93 48 fPrimary1 = -1 ;
49 fPrimary2 = -1 ;
50 fPrimary3 = -1 ;
cf239357 51}
52
53//____________________________________________________________________________
ff4c968a 54AliPHOSDigit::AliPHOSDigit(Int_t primary, Int_t id, Int_t DigEnergy)
d15a28e7 55{
b2a60966 56 // ctor with all data
57
cf239357 58 fId = id ;
59 fAmp = DigEnergy ;
f741ce93 60 fPrimary1 = primary ;
cf239357 61 fNprimary = 1 ;
62}
63
64//____________________________________________________________________________
65AliPHOSDigit::AliPHOSDigit(const AliPHOSDigit & digit)
b2a60966 66{
67 // copy ctor
68
cf239357 69 fId = digit.fId;
70 fAmp = digit.fAmp ;
f741ce93 71 fNprimary = digit.fNprimary ;
72 fPrimary1 = digit.fPrimary1 ;
73 fPrimary2 = digit.fPrimary2 ;
74 fPrimary3 = digit.fPrimary3 ;
ff4c968a 75}
76
77//____________________________________________________________________________
cf239357 78Int_t AliPHOSDigit::Compare(TObject * obj)
d15a28e7 79{
b2a60966 80 // Compares two digits with respect to its Id
81 // to sort according increasing Id
82
cf239357 83 Int_t rv ;
84
85 AliPHOSDigit * digit = (AliPHOSDigit *)obj ;
86
87 Int_t iddiff = fId - digit->GetId() ;
88
89 if ( iddiff > 0 )
90 rv = 1 ;
91 else if ( iddiff < 0 )
92 rv = -1 ;
93 else
94 rv = 0 ;
95
96 return rv ;
97
98}
26d4b141 99
100//____________________________________________________________________________
101Int_t AliPHOSDigit::GetPrimary(Int_t index) const
102{
b2a60966 103 // Returns the primary particle id index =1,2,3
104
26d4b141 105 Int_t rv = -1 ;
106 if ( index > 3 )
107 cout << "AliPHOSDigit ERROR > only 3 primaries allowed" << endl ;
108 else {
109 switch (index) {
110 case 1 :
111 rv = fPrimary1 ;
112 break ;
113 case 2 :
114 rv = fPrimary2 ;
115 break ;
116 case 3 :
117 rv = fPrimary3 ;
118 break ;
119 }
120 }
121
122 return rv ;
123
124}
125
cf239357 126//____________________________________________________________________________
127Bool_t AliPHOSDigit::operator==(AliPHOSDigit const & digit) const
128{
b2a60966 129 // Two digits are equal if they have the same Id
130
cf239357 131 if ( fId == digit.fId )
d15a28e7 132 return kTRUE ;
133 else
134 return kFALSE ;
135}
cf239357 136
d15a28e7 137//____________________________________________________________________________
cf239357 138AliPHOSDigit& AliPHOSDigit::operator+(AliPHOSDigit const & digit)
d15a28e7 139{
b2a60966 140 // Adds the amplitude of digits and completes the list of primary particles
31aa6d6c 141
cf239357 142 fAmp += digit.fAmp ;
31aa6d6c 143
26d4b141 144 // Here comes something crummy ... but I do not know how to stream pointers
145 // because AliPHOSDigit is in a TCLonesArray
f741ce93 146
147 Int_t tempo1[3] ;
148 tempo1[0] = fPrimary1 ;
149 tempo1[1] = fPrimary2 ;
150 tempo1[2] = fPrimary3 ;
151
152 Int_t tempo2[3] ;
153 tempo2[0] = digit.fPrimary1 ;
154 tempo2[1] = digit.fPrimary2 ;
155 tempo2[2] = digit.fPrimary3 ;
156
157 Int_t max1 = fNprimary ;
158 Int_t max2 = digit.fNprimary ;
159
160 if ( fNprimary >= 3 ) {
161 cout << "AliPHOSDigit + operator ERROR > too many primaries, modify AliPHOSDigit" << endl ;
162 }
163 else {
164 fNprimary += digit.fNprimary ;
165 if ( fNprimary > 3 ) {
26d4b141 166 cout << "AliPHOSDigit + operator ERROR > too many primaries, modify AliPHOSDigit" << endl ;
6a3f1304 167 fNprimary = 3 ;
26d4b141 168 }
f741ce93 169
170 Int_t tempo3[3] ;
171 Int_t index ;
31aa6d6c 172 for (index = 0 ; index < 3 ; index++)
173 tempo3[index] = 0 ;
174
f741ce93 175 for (index = 0 ; index < max1 ; index++)
176 tempo3[index] = tempo1[index] ;
31aa6d6c 177
f741ce93 178 for (index = 0 ; index < max2 ; index++)
179 tempo3[index+max1] = tempo2[index] ;
180
181 fPrimary1 = tempo3[0] ;
182 fPrimary2 = tempo3[1] ;
183 fPrimary3 = tempo3[2] ;
26d4b141 184
f741ce93 185 }
26d4b141 186 // end of crummy stuff
187
d15a28e7 188 return *this ;
189}
190
191//____________________________________________________________________________
cf239357 192ostream& operator << ( ostream& out , const AliPHOSDigit & digit)
d15a28e7 193{
b2a60966 194 // Prints the data of the digit
195
196 out << "ID " << digit.fId << " Energy = " << digit.fAmp << endl
197 << "Primary 1 = " << digit.fPrimary1 << endl
198 << "Primary 2 = " << digit.fPrimary2 << endl
199 << "Primary 3 = " << digit.fPrimary3 << endl ;
d15a28e7 200
201 return out ;
202}
203
cf239357 204