]>
Commit | Line | Data |
---|---|---|
c335b3c5 | 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 | **************************************************************************/ | |
e7386040 | 15 | /* $Id$ */ |
c335b3c5 | 16 | |
12f6dd57 | 17 | // -- |
18 | // -- | |
19 | // Implementation for TTree output in PHOS DA | |
20 | // for calibrating energy by pi0 and MIP. | |
21 | // -- | |
22 | // -- Author: Hisayuki Torii (Hiroshima Univ.) | |
23 | // -- | |
24 | ||
25 | #include <math.h> | |
26 | #include <Rtypes.h> | |
27 | #include <iostream> | |
28 | #include "AliPHOSDATreeDigit.h" | |
29 | #include "AliPHOSDATreeCluster.h" | |
30 | ClassImp(AliPHOSDATreeCluster) | |
31 | //------------------------------------------------------------------------ | |
32 | AliPHOSDATreeCluster::AliPHOSDATreeCluster(const AliPHOSDATreeCluster& cluster): | |
33 | //fEnergy(cluster.fEnergy),fX(cluster.fX),fY(cluster.fY),fZ(cluster.fZ),fNDigits(cluster.fNDigits){ | |
34 | fEnergy(cluster.fEnergy),fRow(cluster.fRow),fCol(cluster.fCol),fNDigits(cluster.fNDigits),fDigits(0){ | |
35 | // Copy Constructor | |
36 | ||
37 | if( fNDigits > 0 ){ | |
38 | fDigits = new AliPHOSDATreeDigit[fNDigits]; | |
39 | int ndigits = fNDigits; | |
40 | while( ndigits-- ){ | |
41 | fDigits[ndigits] = cluster.fDigits[ndigits]; | |
42 | } | |
43 | } else { | |
44 | fDigits = 0; | |
45 | } | |
46 | } | |
47 | //------------------------------------------------------------------------ | |
48 | AliPHOSDATreeCluster& AliPHOSDATreeCluster::operator=(const AliPHOSDATreeCluster& cluster){ | |
49 | // Copy Operator | |
50 | ||
929af5d7 | 51 | if (this != &cluster) { |
52 | if( fNDigits> 0 ) delete[] fDigits; | |
53 | fEnergy = cluster.fEnergy; | |
54 | fNDigits = cluster.fNDigits; | |
55 | fRow = cluster.fRow; | |
56 | fCol = cluster.fCol; | |
57 | //fX = cluster.fX; | |
58 | //fY = cluster.fY; | |
59 | //fZ = cluster.fZ; | |
60 | if( fNDigits > 0 ){ | |
61 | fDigits = new AliPHOSDATreeDigit[fNDigits]; | |
62 | int ndigits = fNDigits; | |
63 | while( ndigits-- ){ | |
64 | fDigits[ndigits] = cluster.fDigits[ndigits]; | |
65 | } | |
66 | } else { | |
67 | fDigits = 0; | |
12f6dd57 | 68 | } |
12f6dd57 | 69 | } |
70 | return *this; | |
71 | } | |
72 | //------------------------------------------------------------------------ | |
c335b3c5 | 73 | void AliPHOSDATreeCluster::Print(Option_t *opt) const |
74 | { | |
12f6dd57 | 75 | // Print out |
76 | std::cout<<" AliPHOSDATreeCluster:: Energy="<<fEnergy<<" NDigits="<<fNDigits | |
77 | <<" (row,col)=("<<fRow<<","<<fCol<<")"<<std::endl; | |
78 | //<<" (x,y,z)=("<<fX<<","<<fY<<","<<fZ<<")"<<std::endl; | |
79 | int ndigits = fNDigits; | |
80 | while( ndigits-- ){ | |
81 | std::cout<<" -->["<<ndigits<<"] : "; | |
82 | fDigits[ndigits].Print(opt); | |
83 | } | |
84 | } | |
85 | //------------------------------------------------------------------------ | |
86 | std::ostream& operator<<(std::ostream& out, const AliPHOSDATreeCluster& cluster){ | |
87 | // Print out | |
88 | out<<" AliPHOSDATreeCluster:: Energy="<<cluster.fEnergy<<" NDigits="<<cluster.fNDigits | |
89 | <<" (row,col)=("<<cluster.fRow<<","<<cluster.fCol<<")"<<std::endl; | |
90 | int ndigits = cluster.fNDigits; | |
91 | while( ndigits-- ){ | |
92 | out<<" -->["<<ndigits<<"] : "<<cluster.fDigits[ndigits]; | |
93 | if( ndigits!=0 ) out<<std::endl; | |
94 | } | |
95 | return out; | |
96 | } | |
97 | //------------------------------------------------------------------------ | |
98 | void AliPHOSDATreeCluster::Reset(){ | |
99 | // Reset information | |
100 | ||
101 | fEnergy = 0; | |
102 | fRow = -100; | |
103 | fCol = -100; | |
104 | //fX = 0; | |
105 | //fY = 0; | |
106 | //fZ = 0; | |
107 | if( fNDigits> 0 ) delete[] fDigits; | |
108 | fNDigits = 0; | |
109 | } | |
110 | //------------------------------------------------------------------------ | |
111 | bool AliPHOSDATreeCluster::Append(AliPHOSDATreeDigit& digit){ | |
112 | // Add digit information and sum all energy | |
113 | // | |
114 | if(! digit.IsValid() ){ | |
115 | std::cout<<" AliPHOSDATreeCluster::Append():: Error!! Digit is not valid.."<<std::endl; | |
116 | return false; | |
117 | } | |
118 | AliPHOSDATreeDigit* newfDigits = new AliPHOSDATreeDigit[fNDigits+1]; | |
119 | bool bsearching = true; | |
120 | int ndigit = fNDigits; | |
121 | while( ndigit-- ){ | |
122 | if( fDigits[ndigit].GetAbsId() == digit.GetAbsId() ){ | |
123 | std::cout<<" AliPHOSDATreeCluster::Append():: Error!! The channel already exist."<<std::endl; | |
124 | std::cout<<" Add "<<digit<<std::endl; | |
125 | std::cout<<" into *this"<<*this<<std::endl; | |
126 | delete[] newfDigits; | |
127 | return false; | |
128 | } | |
129 | if( fDigits[ndigit].GetEnergy() < digit.GetEnergy() ){ | |
130 | newfDigits[ndigit+1] = fDigits[ndigit]; | |
131 | } else { | |
132 | if( bsearching ) { | |
133 | bsearching = false; | |
134 | newfDigits[ndigit+1] = digit; | |
135 | } | |
136 | newfDigits[ndigit] = fDigits[ndigit]; | |
137 | } | |
138 | } | |
139 | if( bsearching ) newfDigits[0] = digit; | |
140 | if( fNDigits>0 ) delete[] fDigits; | |
141 | fNDigits++; | |
142 | fDigits = newfDigits; | |
143 | fEnergy += digit.GetEnergy(); | |
144 | return true; | |
145 | } | |
146 | //------------------------------------------------------------------------ | |
147 | bool AliPHOSDATreeCluster::Append(AliPHOSDATreeCluster& cluster){ | |
148 | // Add another cluster information and sum all energy | |
149 | // | |
150 | AliPHOSDATreeDigit* newfDigits = new AliPHOSDATreeDigit[fNDigits+cluster.fNDigits]; | |
151 | int ndigits1 = fNDigits; | |
152 | int ndigits2 = cluster.fNDigits; | |
153 | int ndigitsall = ndigits1 + ndigits2; | |
154 | while( ndigitsall-- ){ | |
155 | //std::cout<<" ------ ndigits1:"<<ndigits1<<" ndigits2:"<<ndigits2<<std::endl; | |
156 | if( ndigits1 && ndigits2 ){ | |
157 | if( fDigits[ndigits1-1].GetEnergy() < cluster.fDigits[ndigits2-1].GetEnergy() ){ | |
158 | newfDigits[ndigitsall] = fDigits[--ndigits1]; | |
159 | } else { | |
160 | newfDigits[ndigitsall]= cluster.fDigits[--ndigits2]; | |
161 | } | |
162 | } else if ( ndigits1 && ndigits2==0 ){ | |
163 | newfDigits[ndigitsall] = fDigits[--ndigits1]; | |
164 | } else if ( ndigits2 && ndigits1==0 ){ | |
165 | newfDigits[ndigitsall]= cluster.fDigits[--ndigits2]; | |
166 | } else { | |
167 | std::cout<<" AliPHOSDATreeCluster::Append() Something wrong.. "<<std::endl; | |
bf7a2c74 | 168 | delete [] newfDigits; |
12f6dd57 | 169 | return false; |
170 | } | |
171 | } | |
172 | if(fNDigits>0) delete[] fDigits; | |
173 | fDigits = newfDigits; | |
174 | fNDigits += cluster.fNDigits; | |
175 | fEnergy += cluster.GetEnergy(); | |
176 | return true; | |
177 | ||
178 | } | |
179 | //------------------------------------------------------------------------ | |
180 | bool AliPHOSDATreeCluster::IsNeighbor(const AliPHOSDATreeDigit& digit) const{ | |
181 | // Check wether the given digit is neighboring to this cluster. | |
182 | // Return true if yes. | |
183 | ||
184 | bool status = false; | |
185 | int ndigits = fNDigits; | |
186 | while( ndigits-- && !status ){ | |
187 | status = digit.IsNeighbor(fDigits[ndigits]); | |
188 | } | |
189 | return status; | |
190 | } | |
191 | //------------------------------------------------------------------------ | |
192 | bool AliPHOSDATreeCluster::IsNeighbor(const AliPHOSDATreeCluster& cluster) const{ | |
193 | // Check wether the given cluster is neighboring to this cluster. | |
194 | // Return true if yes. | |
195 | ||
196 | bool status = false; | |
197 | int ndigits = fNDigits; | |
198 | while( ndigits-- && !status ){ | |
199 | status = cluster.IsNeighbor(fDigits[ndigits]); | |
200 | } | |
201 | return status; | |
202 | } | |
203 | //------------------------------------------------------------------------ | |
204 | bool AliPHOSDATreeCluster::CalculateProperty(){ | |
205 | // Calculate the hit position | |
206 | // (calculation of dispersion is not valid) | |
207 | ||
208 | fCol = 0; | |
209 | fRow = 0; | |
210 | float totweight = 0; | |
211 | float weight; | |
212 | int ndigits = fNDigits; | |
213 | while( ndigits-- ){ | |
214 | weight = log(fDigits[ndigits].GetEnergy()/fEnergy) + 4.5; //4.5 is for PHOS | |
215 | //std::cout<<" AliPHOSDATreeCluster::CalculateProperty() DEBUG: ndigits="<<ndigits<<" weight="<<weight<<std::endl; | |
216 | if( weight > 0 ){ | |
217 | totweight += weight; | |
218 | fRow += fDigits[ndigits].GetRow() * weight; | |
219 | fCol += fDigits[ndigits].GetCol() * weight; | |
220 | } | |
221 | } | |
222 | //std::cout<<" AliPHOSDATreeCluster::CalculateProperty() DEBUG: totweight="<<totweight<<std::endl; | |
223 | if( totweight > 0 ){ | |
224 | fRow /= totweight; | |
225 | fCol /= totweight; | |
226 | } else { | |
227 | fRow = 0; | |
228 | fCol = 0; | |
229 | } | |
230 | /* | |
231 | float disp = 0; | |
232 | if( totweight > ){ | |
233 | ndigits = fNDigits; | |
234 | while( ndigits-- ){ | |
235 | weight = log(fDigits[ndigits].GetEnergy()/fEnergy) + 4.5; //4.5 is for PHOS | |
236 | disp += weight * ( (fDigits[ndigits].GetRow()-fRow)*(fDigits[ndigits].GetRow()-fRow) + | |
237 | (fDigits[ndigits].GetCol()-fCol)*(fDigits[ndigits].GetCol()-fCol) ); | |
238 | } | |
239 | disp /= totweight; | |
240 | } | |
241 | */ | |
242 | return true; | |
243 | } | |
244 | //------------------------------------------------------------------------ |