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