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 (this != &cluster) {
52 if( fNDigits> 0 ) delete[] fDigits;
53 fEnergy = cluster.fEnergy;
54 fNDigits = cluster.fNDigits;
61 fDigits = new AliPHOSDATreeDigit[fNDigits];
62 int ndigits = fNDigits;
64 fDigits[ndigits] = cluster.fDigits[ndigits];
72 //------------------------------------------------------------------------
73 void AliPHOSDATreeCluster::Print(Option_t *opt) const
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;
81 std::cout<<" -->["<<ndigits<<"] : ";
82 fDigits[ndigits].Print(opt);
85 //------------------------------------------------------------------------
86 std::ostream& operator<<(std::ostream& out, const AliPHOSDATreeCluster& cluster){
88 out<<" AliPHOSDATreeCluster:: Energy="<<cluster.fEnergy<<" NDigits="<<cluster.fNDigits
89 <<" (row,col)=("<<cluster.fRow<<","<<cluster.fCol<<")"<<std::endl;
90 int ndigits = cluster.fNDigits;
92 out<<" -->["<<ndigits<<"] : "<<cluster.fDigits[ndigits];
93 if( ndigits!=0 ) out<<std::endl;
97 //------------------------------------------------------------------------
98 void AliPHOSDATreeCluster::Reset(){
107 if( fNDigits> 0 ) delete[] fDigits;
110 //------------------------------------------------------------------------
111 bool AliPHOSDATreeCluster::Append(AliPHOSDATreeDigit& digit){
112 // Add digit information and sum all energy
114 if(! digit.IsValid() ){
115 std::cout<<" AliPHOSDATreeCluster::Append():: Error!! Digit is not valid.."<<std::endl;
118 AliPHOSDATreeDigit* newfDigits = new AliPHOSDATreeDigit[fNDigits+1];
119 bool bsearching = true;
120 int ndigit = fNDigits;
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;
129 if( fDigits[ndigit].GetEnergy() < digit.GetEnergy() ){
130 newfDigits[ndigit+1] = fDigits[ndigit];
134 newfDigits[ndigit+1] = digit;
136 newfDigits[ndigit] = fDigits[ndigit];
139 if( bsearching ) newfDigits[0] = digit;
140 if( fNDigits>0 ) delete[] fDigits;
142 fDigits = newfDigits;
143 fEnergy += digit.GetEnergy();
146 //------------------------------------------------------------------------
147 bool AliPHOSDATreeCluster::Append(AliPHOSDATreeCluster& cluster){
148 // Add another cluster information and sum all energy
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];
160 newfDigits[ndigitsall]= cluster.fDigits[--ndigits2];
162 } else if ( ndigits1 && ndigits2==0 ){
163 newfDigits[ndigitsall] = fDigits[--ndigits1];
164 } else if ( ndigits2 && ndigits1==0 ){
165 newfDigits[ndigitsall]= cluster.fDigits[--ndigits2];
167 std::cout<<" AliPHOSDATreeCluster::Append() Something wrong.. "<<std::endl;
168 delete [] newfDigits;
172 if(fNDigits>0) delete[] fDigits;
173 fDigits = newfDigits;
174 fNDigits += cluster.fNDigits;
175 fEnergy += cluster.GetEnergy();
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.
185 int ndigits = fNDigits;
186 while( ndigits-- && !status ){
187 status = digit.IsNeighbor(fDigits[ndigits]);
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.
197 int ndigits = fNDigits;
198 while( ndigits-- && !status ){
199 status = cluster.IsNeighbor(fDigits[ndigits]);
203 //------------------------------------------------------------------------
204 bool AliPHOSDATreeCluster::CalculateProperty(){
205 // Calculate the hit position
206 // (calculation of dispersion is not valid)
212 int ndigits = fNDigits;
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;
218 fRow += fDigits[ndigits].GetRow() * weight;
219 fCol += fDigits[ndigits].GetCol() * weight;
222 //std::cout<<" AliPHOSDATreeCluster::CalculateProperty() DEBUG: totweight="<<totweight<<std::endl;
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) );
244 //------------------------------------------------------------------------