1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
19 // Implementation for TTree output in PHOS DA
20 // for calibrating energy by pi0 and MIP.
22 // -- Author: Hisayuki Torii (Hiroshima Univ.)
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){
38 fDigits = new AliPHOSDATreeDigit[fNDigits];
39 int ndigits = fNDigits;
41 fDigits[ndigits] = cluster.fDigits[ndigits];
47 //------------------------------------------------------------------------
48 AliPHOSDATreeCluster& AliPHOSDATreeCluster::operator=(const AliPHOSDATreeCluster& cluster){
51 if( fNDigits> 0 ) delete[] fDigits;
52 fEnergy = cluster.fEnergy;
53 fNDigits = cluster.fNDigits;
60 fDigits = new AliPHOSDATreeDigit[fNDigits];
61 int ndigits = fNDigits;
63 fDigits[ndigits] = cluster.fDigits[ndigits];
70 //------------------------------------------------------------------------
71 void AliPHOSDATreeCluster::Print(Option_t *opt) const
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;
79 std::cout<<" -->["<<ndigits<<"] : ";
80 fDigits[ndigits].Print(opt);
83 //------------------------------------------------------------------------
84 std::ostream& operator<<(std::ostream& out, const AliPHOSDATreeCluster& cluster){
86 out<<" AliPHOSDATreeCluster:: Energy="<<cluster.fEnergy<<" NDigits="<<cluster.fNDigits
87 <<" (row,col)=("<<cluster.fRow<<","<<cluster.fCol<<")"<<std::endl;
88 int ndigits = cluster.fNDigits;
90 out<<" -->["<<ndigits<<"] : "<<cluster.fDigits[ndigits];
91 if( ndigits!=0 ) out<<std::endl;
95 //------------------------------------------------------------------------
96 void AliPHOSDATreeCluster::Reset(){
105 if( fNDigits> 0 ) delete[] fDigits;
108 //------------------------------------------------------------------------
109 bool AliPHOSDATreeCluster::Append(AliPHOSDATreeDigit& digit){
110 // Add digit information and sum all energy
112 if(! digit.IsValid() ){
113 std::cout<<" AliPHOSDATreeCluster::Append():: Error!! Digit is not valid.."<<std::endl;
116 AliPHOSDATreeDigit* newfDigits = new AliPHOSDATreeDigit[fNDigits+1];
117 bool bsearching = true;
118 int ndigit = fNDigits;
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;
127 if( fDigits[ndigit].GetEnergy() < digit.GetEnergy() ){
128 newfDigits[ndigit+1] = fDigits[ndigit];
132 newfDigits[ndigit+1] = digit;
134 newfDigits[ndigit] = fDigits[ndigit];
137 if( bsearching ) newfDigits[0] = digit;
138 if( fNDigits>0 ) delete[] fDigits;
140 fDigits = newfDigits;
141 fEnergy += digit.GetEnergy();
144 //------------------------------------------------------------------------
145 bool AliPHOSDATreeCluster::Append(AliPHOSDATreeCluster& cluster){
146 // Add another cluster information and sum all energy
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];
158 newfDigits[ndigitsall]= cluster.fDigits[--ndigits2];
160 } else if ( ndigits1 && ndigits2==0 ){
161 newfDigits[ndigitsall] = fDigits[--ndigits1];
162 } else if ( ndigits2 && ndigits1==0 ){
163 newfDigits[ndigitsall]= cluster.fDigits[--ndigits2];
165 std::cout<<" AliPHOSDATreeCluster::Append() Something wrong.. "<<std::endl;
169 if(fNDigits>0) delete[] fDigits;
170 fDigits = newfDigits;
171 fNDigits += cluster.fNDigits;
172 fEnergy += cluster.GetEnergy();
176 //------------------------------------------------------------------------
177 bool AliPHOSDATreeCluster::IsNeighbor(const AliPHOSDATreeDigit& digit) const{
178 // Check wether the given digit is neighboring to this cluster.
179 // Return true if yes.
182 int ndigits = fNDigits;
183 while( ndigits-- && !status ){
184 status = digit.IsNeighbor(fDigits[ndigits]);
188 //------------------------------------------------------------------------
189 bool AliPHOSDATreeCluster::IsNeighbor(const AliPHOSDATreeCluster& cluster) const{
190 // Check wether the given cluster is neighboring to this cluster.
191 // Return true if yes.
194 int ndigits = fNDigits;
195 while( ndigits-- && !status ){
196 status = cluster.IsNeighbor(fDigits[ndigits]);
200 //------------------------------------------------------------------------
201 bool AliPHOSDATreeCluster::CalculateProperty(){
202 // Calculate the hit position
203 // (calculation of dispersion is not valid)
209 int ndigits = fNDigits;
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;
215 fRow += fDigits[ndigits].GetRow() * weight;
216 fCol += fDigits[ndigits].GetCol() * weight;
219 //std::cout<<" AliPHOSDATreeCluster::CalculateProperty() DEBUG: totweight="<<totweight<<std::endl;
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) );
241 //------------------------------------------------------------------------