]> git.uio.no Git - u/mrichter/AliRoot.git/blob - JETAN/jetan2004/AliJFCluster.cxx
Replaced by JETANLinkDef.h
[u/mrichter/AliRoot.git] / JETAN / jetan2004 / AliJFCluster.cxx
1 // $Id$
2
3 #include <Riostream.h>
4 #include <vector>
5
6 #include <TParticle.h>
7 #include <TMath.h>
8
9 #include "AliJFCluster.h"
10
11 ClassImp(AliJFCluster)
12
13 AliJFCluster::AliJFCluster(Int_t n) : fStatus(0),fNMerge(0),fPx(0),fPy(0),fPz(0),fE(0),
14                                 fY(0),fPhi(0),fPt2(0),fPt2dD(0),fList(n)
15 {
16 }
17
18 AliJFCluster::AliJFCluster(const AliJFCluster &copy)
19 {
20   fStatus=copy.GetStatus();
21   fNMerge=copy.GetNMerge();
22   fPx=copy.GetPx();
23   fPy=copy.GetPy();
24   fPz=copy.GetPz();
25   fE=copy.GetE();
26   fY=copy.GetY();
27   fPhi=copy.GetPhi();
28   fPt2=copy.GetPt2();
29   fPt2dD=copy.GetPt2D();
30   fList=*copy.GetClusterList();
31 }
32
33 AliJFCluster::AliJFCluster(AliJFPreCluster &copy)
34 {
35   fStatus=1; //valid
36   fNMerge=0;
37   fPx=copy.GetPx();
38   fPy=copy.GetPy();
39   fPz=copy.GetPz();
40   fE=copy.GetE();
41
42   SetValues();
43   fList.push_back(&copy);
44 }
45
46 AliJFCluster::AliJFCluster(AliJFPreCluster *precluster)
47 {
48   fStatus=1; //valid
49   fNMerge=0;
50   SetValues(precluster->GetPx(),fPy=precluster->GetPy(),fPz=precluster->GetPz(),fE=precluster->GetE());
51   fList.push_back(precluster);
52 }
53
54 AliJFCluster::~AliJFCluster()
55 {
56   fList.erase(fList.begin(),fList.end());
57 }
58
59 AliJFCluster& AliJFCluster::operator=(const AliJFCluster &rhs)
60 {
61   fStatus=rhs.GetStatus();
62   fNMerge=rhs.GetNMerge();
63   fPx=rhs.GetPx();
64   fPy=rhs.GetPy();
65   fPz=rhs.GetPz();
66   fE=rhs.GetE();
67   fY=rhs.GetY();
68   fPhi=rhs.GetPhi();
69   fPt2=rhs.GetPt2();
70   fPt2dD=rhs.GetPt2D();
71   fList=*rhs.GetClusterList();
72   return *this;
73 }
74
75 AliJFCluster& AliJFCluster::operator=(AliJFPreCluster &rhs)
76 {
77   fStatus=1; //valid
78   fNMerge=0;
79   fPx=rhs.GetPx();
80   fPy=rhs.GetPy();
81   fPz=rhs.GetPz();
82   fE=rhs.GetE();
83
84   SetValues();
85   fList.push_back(&rhs);
86   return *this;
87 }
88
89 AliJFCluster& AliJFCluster::operator+=(AliJFCluster &rhs) //mark rhs as being merged!
90
91   if(!rhs.IsValid()){
92     cerr << "Cluster cannot be combined with invalid cluster:" << endl;
93     cerr << *this << endl;
94     cerr << rhs << endl;    
95     return *this;
96   }
97
98   AddValues(rhs.GetPx(),fPy=rhs.GetPy(),fPz=rhs.GetPz(),fE=rhs.GetE());
99   vector<AliJFPreCluster*> tmp=*rhs.GetClusterList();
100   for(vector<AliJFPreCluster*>::iterator i=tmp.begin();i!=tmp.end();i++){
101     fList.push_back(*i);
102   }
103
104   rhs.MarkIsMerged(); //change even rhs!
105
106   return *this;
107 }
108
109 AliJFCluster& AliJFCluster::operator+=(AliJFPreCluster &rhs)
110 {
111   AddValues(rhs.GetPx(),rhs.GetPy(),rhs.GetPz(),rhs.GetE());
112   fList.push_back(&rhs);
113
114   return *this;
115 }
116
117 ostream& operator<<(ostream& o, const AliJFCluster &c)
118 {
119   o << c.GetStatus() << ": " << c.GetPx() << " " << c.GetPy() << " " << c.GetPz() << " " << c.GetE();
120
121   return o;
122 }
123
124 void AliJFCluster::CombineCluster(AliJFCluster &rhs) //mark rhs as being merged!
125
126   if(!rhs.IsValid()){
127     cerr << "Error AliJFCluster: Cluster cannot be combined with invalid cluster:" << endl;
128     cerr << *this << endl;
129     cerr << rhs << endl;    
130     return;
131   }
132   AddValues(rhs.GetPx(),fPy=rhs.GetPy(),rhs.GetPz(),rhs.GetE());
133   vector<AliJFPreCluster*> tmp=*rhs.GetClusterList();
134   for(vector<AliJFPreCluster*>::iterator i=tmp.begin();i!=tmp.end();i++){
135     fList.push_back(*i);
136   }
137
138   rhs.MarkIsMerged(); //change even rhs!
139 }
140
141 void AliJFCluster::Print()
142 {
143   cout << "Cluster " << " " << *this << endl;
144   Int_t n=0;
145   for(vector<AliJFPreCluster*>::iterator i=fList.begin();i!=fList.end();i++){
146     n++;
147     cout << "PreCluster " << n << ": " << *(*i) << endl;
148   }
149 }
150
151 void AliJFCluster::SetValues(Float_t px, Float_t py, Float_t pz, Float_t E)
152 {
153   fPx=px;
154   fPy=py;
155   fPz=pz;
156   fE=E;
157
158   SetValues();
159 }
160
161 void AliJFCluster::SetValues()
162 {
163   if(IsValid()){
164     fPt2=fPx*fPx+fPy*fPy;
165     if(fE<0) fE=TMath::Sqrt(fPt2+fPz*fPz);
166     fPt2dD=fPt2/D2;
167     fPhi=TMath::Pi()+TMath::ATan2(-fPy,-fPx);
168     fY=0.5*TMath::Log((fE+fPz)/(fE-fPz));
169     if(fY>10) fY=10;
170     else if(fY<-10) fY=-10;
171   } else {
172     fPt2=fPt2dD=fPhi=fY=0;
173   }
174 }
175
176 void AliJFCluster::AddValues(Float_t px, Float_t py, Float_t pz, Float_t E)
177 {
178   fNMerge++;
179   fPx+=px;
180   fPy+=py;
181   fPz+=pz;
182   fE+=E;
183
184   SetValues();
185 }
186
187 Float_t AliJFCluster::D2=1.0;