3 // Implementation for TTree output in PHOS DA
4 // for calibrating energy by pi0 and MIP.
6 // -- Author: Hisayuki Torii (Hiroshima Univ.)
12 #include "AliPHOSDATreeDigit.h"
13 #include "AliPHOSDATreeCluster.h"
14 ClassImp(AliPHOSDATreeCluster)
15 //------------------------------------------------------------------------
16 AliPHOSDATreeCluster::AliPHOSDATreeCluster(const AliPHOSDATreeCluster& cluster):
17 //fEnergy(cluster.fEnergy),fX(cluster.fX),fY(cluster.fY),fZ(cluster.fZ),fNDigits(cluster.fNDigits){
18 fEnergy(cluster.fEnergy),fRow(cluster.fRow),fCol(cluster.fCol),fNDigits(cluster.fNDigits),fDigits(0){
22 fDigits = new AliPHOSDATreeDigit[fNDigits];
23 int ndigits = fNDigits;
25 fDigits[ndigits] = cluster.fDigits[ndigits];
31 //------------------------------------------------------------------------
32 AliPHOSDATreeCluster& AliPHOSDATreeCluster::operator=(const AliPHOSDATreeCluster& cluster){
35 if( fNDigits> 0 ) delete[] fDigits;
36 fEnergy = cluster.fEnergy;
37 fNDigits = cluster.fNDigits;
44 fDigits = new AliPHOSDATreeDigit[fNDigits];
45 int ndigits = fNDigits;
47 fDigits[ndigits] = cluster.fDigits[ndigits];
54 //------------------------------------------------------------------------
55 void AliPHOSDATreeCluster::Print(char* opt){
57 std::cout<<" AliPHOSDATreeCluster:: Energy="<<fEnergy<<" NDigits="<<fNDigits
58 <<" (row,col)=("<<fRow<<","<<fCol<<")"<<std::endl;
59 //<<" (x,y,z)=("<<fX<<","<<fY<<","<<fZ<<")"<<std::endl;
60 int ndigits = fNDigits;
62 std::cout<<" -->["<<ndigits<<"] : ";
63 fDigits[ndigits].Print(opt);
66 //------------------------------------------------------------------------
67 std::ostream& operator<<(std::ostream& out, const AliPHOSDATreeCluster& cluster){
69 out<<" AliPHOSDATreeCluster:: Energy="<<cluster.fEnergy<<" NDigits="<<cluster.fNDigits
70 <<" (row,col)=("<<cluster.fRow<<","<<cluster.fCol<<")"<<std::endl;
71 int ndigits = cluster.fNDigits;
73 out<<" -->["<<ndigits<<"] : "<<cluster.fDigits[ndigits];
74 if( ndigits!=0 ) out<<std::endl;
78 //------------------------------------------------------------------------
79 void AliPHOSDATreeCluster::Reset(){
88 if( fNDigits> 0 ) delete[] fDigits;
91 //------------------------------------------------------------------------
92 bool AliPHOSDATreeCluster::Append(AliPHOSDATreeDigit& digit){
93 // Add digit information and sum all energy
95 if(! digit.IsValid() ){
96 std::cout<<" AliPHOSDATreeCluster::Append():: Error!! Digit is not valid.."<<std::endl;
99 AliPHOSDATreeDigit* newfDigits = new AliPHOSDATreeDigit[fNDigits+1];
100 bool bsearching = true;
101 int ndigit = fNDigits;
103 if( fDigits[ndigit].GetAbsId() == digit.GetAbsId() ){
104 std::cout<<" AliPHOSDATreeCluster::Append():: Error!! The channel already exist."<<std::endl;
105 std::cout<<" Add "<<digit<<std::endl;
106 std::cout<<" into *this"<<*this<<std::endl;
110 if( fDigits[ndigit].GetEnergy() < digit.GetEnergy() ){
111 newfDigits[ndigit+1] = fDigits[ndigit];
115 newfDigits[ndigit+1] = digit;
117 newfDigits[ndigit] = fDigits[ndigit];
120 if( bsearching ) newfDigits[0] = digit;
121 if( fNDigits>0 ) delete[] fDigits;
123 fDigits = newfDigits;
124 fEnergy += digit.GetEnergy();
127 //------------------------------------------------------------------------
128 bool AliPHOSDATreeCluster::Append(AliPHOSDATreeCluster& cluster){
129 // Add another cluster information and sum all energy
131 AliPHOSDATreeDigit* newfDigits = new AliPHOSDATreeDigit[fNDigits+cluster.fNDigits];
132 int ndigits1 = fNDigits;
133 int ndigits2 = cluster.fNDigits;
134 int ndigitsall = ndigits1 + ndigits2;
135 while( ndigitsall-- ){
136 //std::cout<<" ------ ndigits1:"<<ndigits1<<" ndigits2:"<<ndigits2<<std::endl;
137 if( ndigits1 && ndigits2 ){
138 if( fDigits[ndigits1-1].GetEnergy() < cluster.fDigits[ndigits2-1].GetEnergy() ){
139 newfDigits[ndigitsall] = fDigits[--ndigits1];
141 newfDigits[ndigitsall]= cluster.fDigits[--ndigits2];
143 } else if ( ndigits1 && ndigits2==0 ){
144 newfDigits[ndigitsall] = fDigits[--ndigits1];
145 } else if ( ndigits2 && ndigits1==0 ){
146 newfDigits[ndigitsall]= cluster.fDigits[--ndigits2];
148 std::cout<<" AliPHOSDATreeCluster::Append() Something wrong.. "<<std::endl;
152 if(fNDigits>0) delete[] fDigits;
153 fDigits = newfDigits;
154 fNDigits += cluster.fNDigits;
155 fEnergy += cluster.GetEnergy();
159 //------------------------------------------------------------------------
160 bool AliPHOSDATreeCluster::IsNeighbor(const AliPHOSDATreeDigit& digit) const{
161 // Check wether the given digit is neighboring to this cluster.
162 // Return true if yes.
165 int ndigits = fNDigits;
166 while( ndigits-- && !status ){
167 status = digit.IsNeighbor(fDigits[ndigits]);
171 //------------------------------------------------------------------------
172 bool AliPHOSDATreeCluster::IsNeighbor(const AliPHOSDATreeCluster& cluster) const{
173 // Check wether the given cluster is neighboring to this cluster.
174 // Return true if yes.
177 int ndigits = fNDigits;
178 while( ndigits-- && !status ){
179 status = cluster.IsNeighbor(fDigits[ndigits]);
183 //------------------------------------------------------------------------
184 bool AliPHOSDATreeCluster::CalculateProperty(){
185 // Calculate the hit position
186 // (calculation of dispersion is not valid)
192 int ndigits = fNDigits;
194 weight = log(fDigits[ndigits].GetEnergy()/fEnergy) + 4.5; //4.5 is for PHOS
195 //std::cout<<" AliPHOSDATreeCluster::CalculateProperty() DEBUG: ndigits="<<ndigits<<" weight="<<weight<<std::endl;
198 fRow += fDigits[ndigits].GetRow() * weight;
199 fCol += fDigits[ndigits].GetCol() * weight;
202 //std::cout<<" AliPHOSDATreeCluster::CalculateProperty() DEBUG: totweight="<<totweight<<std::endl;
215 weight = log(fDigits[ndigits].GetEnergy()/fEnergy) + 4.5; //4.5 is for PHOS
216 disp += weight * ( (fDigits[ndigits].GetRow()-fRow)*(fDigits[ndigits].GetRow()-fRow) +
217 (fDigits[ndigits].GetCol()-fCol)*(fDigits[ndigits].GetCol()-fCol) );
224 //------------------------------------------------------------------------