StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEmcPreCluster.cxx
1 #include "StEmcPreCluster.h"
2 #include "StEventTypes.h"
3 ClassImp(StEmcPreCluster)
4 
5 StEmcPreCluster::StEmcPreCluster(Int_t detector)
6 {
7  mEnergy = 0.0;
8  mEta = 0.0;
9  mPhi = 0.0;
10  mSigmaEta =0.0;
11  mSigmaPhi=0.0;
12  mDetector=detector;
13  mMatchingId = 0;
14  mGeom = StEmcGeom::instance(detector);
15 }
16 StEmcPreCluster::StEmcPreCluster(StEmcPreCluster& cluster)
17 {
18  Int_t nh = cluster.nHits();
19  for(Int_t i = 0;i<nh;i++)
20  addHit(cluster.getHit(i));
21  mDetector = cluster.detector();
22  mMatchingId = cluster.matchingId();
23  mGeom = StEmcGeom::instance(mDetector);
24  update();
25 }
26 StEmcPreCluster::StEmcPreCluster(StEmcCluster* cluster)
27 {
28  StPtrVecEmcRawHit& hits=cluster->hit();
29  for(Int_t i=0;i<(Int_t)hits.size();i++)
30  addHit(hits[i]);
31  mDetector = (Int_t)(hits[0]->detector()-kBarrelEmcTowerId+1);
32  mMatchingId = cluster->GetUniqueID();
33  mGeom = StEmcGeom::instance(mDetector);
34  update();
35 }
36 StEmcPreCluster::~StEmcPreCluster()
37 {
38  mHits.Clear("nodelete"); // StEvent hits are not owned by this cluster
39 }
41 {
42  if(!mHits.FindObject(hit))
43  mHits.Add(hit);
44 }
46 {
47  if(mHits.FindObject(hit))
48  mHits.Remove(hit);
49 }
50 void StEmcPreCluster::removeHit(Int_t hitId)
51 {
52  if(mHits.At(hitId))
53  mHits.Remove(mHits.At(hitId));
54 }
56 {
57  Int_t nH = nHits();
58  mEnergy = 0.0;
59  mEta = 0.0;
60  mPhi = 0.0;
61  mSigmaEta =0.0;
62  mSigmaPhi=0.0;
63  if(nH==0)
64  return;
65 
66  Int_t m,e,s;
67  Float_t E,P,energy,phi0;
68  phi0 = -999; //this is always initialized below if there are any hits at all
69  Bool_t firstHit = true;
70  for(Int_t i = 0;i<nH;i++)
71  {
72  StEmcRawHit* hit = getHit(i);
73  if(hit)
74  {
75  m=(Int_t)hit->module();
76  e=(Int_t)hit->eta();
77  s=abs(hit->sub());
78  energy=hit->energy();
79 
80  mGeom->getEta(m,e, E);
81  mGeom->getPhi(m,s, P);
82  // Rotate to the system of first hit
83  if(firstHit)
84  {
85  phi0 = P;
86  P = 0.0;
87  firstHit = false;
88  }
89  else
90  P-=phi0;
91  P = StEmcMath::getPhiPlusMinusPi(P);
92 
93  mEta+=E*energy;
94  mPhi+=P*energy;
95  mSigmaEta+=E*E*energy;
96  mSigmaPhi+=P*P*energy;
97  mEnergy+=energy;
98  }
99  }
100  mEta /= mEnergy;
101  mSigmaEta = mSigmaEta/mEnergy - mEta*mEta;
102  if(mSigmaEta <= 0.0)
103  mSigmaEta = 0.0;
104  else
105  mSigmaEta = sqrt(mSigmaEta);
106 
107  mPhi /= mEnergy;
108  mSigmaPhi = mSigmaPhi/mEnergy - mPhi*mPhi;
109  if(mSigmaPhi <= 0.0)
110  mSigmaPhi = 0.0;
111  else
112  mSigmaPhi = sqrt(mSigmaPhi);
113 
114  // Rotate back to STAR system
115  mPhi += phi0;
116  mPhi = StEmcMath::getPhiPlusMinusPi(mPhi);
117 
118  return;
119 }
121 {
122  if(!cluster)
123  return;
124  if(mDetector!=cluster->detector())
125  return;
126  Int_t nH = cluster->nHits();
127  for(Int_t i = 0;i<nH;i++)
128  addHit(cluster->getHit(i));
129  update();
130 }
132 {
133  if(!cluster)
134  return;
135  StPtrVecEmcRawHit& hits=cluster->hit();
136  if(mDetector!=(Int_t)(hits[0]->detector()-kBarrelEmcTowerId+1))
137  return;
138  for(Int_t i=0;i<(Int_t)hits.size();i++)
139  addHit(hits[i]);
140  update();
141 }
143 {
144  if(!cluster)
145  return;
146  if(mDetector!=cluster->detector())
147  return;
148  Int_t nH = cluster->nHits();
149  for(Int_t i = 0;i<nH;i++)
150  removeHit(cluster->getHit(i));
151  update();
152 }
154 {
155  if(!cluster)
156  return;
157  StPtrVecEmcRawHit& hits=cluster->hit();
158  if(mDetector!=(Int_t)(hits[0]->detector()-kBarrelEmcTowerId+1))
159  return;
160  for(Int_t i=0;i<(Int_t)hits.size();i++)
161  removeHit(hits[i]);
162  update();
163 }
165 {
166  Int_t nH = nHits();
167  if(nH<2)
168  return NULL; // no way to split only with 1 hit
169  StEmcPreCluster *cluster = NULL;
170  TList *above = new TList();
171  Float_t E;
172  Int_t m,e;
173  Bool_t hasBelow = kFALSE;
174  for(Int_t i=0;i<nH;i++)
175  {
176  StEmcRawHit* hit = getHit(i);
177  if(hit)
178  {
179  m=(Int_t)hit->module();
180  e=(Int_t)hit->eta();
181  mGeom->getEta(m,e, E);
182  if(E<=eta)
183  hasBelow=kTRUE;
184  else
185  above->Add(hit);
186  }
187  }
188  if(hasBelow && above->GetSize()>0)
189  {
190  cluster = new StEmcPreCluster(detector());
191  Int_t na = above->GetSize();
192  for(Int_t i = 0;i<na;i++)
193  {
194  StEmcRawHit* hit = (StEmcRawHit*)above->At(i);
195  removeHit(hit);
196  cluster->addHit(hit);
197  }
198  update();
199  cluster->update();
200  }
201  delete above;
202  return cluster;
203 }
205 {
206  Int_t nH = nHits();
207  if(nH<2)
208  return NULL; // no way to split only with 1 hit
209  StEmcPreCluster *cluster = NULL;
210  TList *above = new TList();
211  Float_t P;
212  Int_t m,s;
213  Bool_t hasBelow = kFALSE;
214  for(Int_t i=0;i<nH;i++)
215  {
216  StEmcRawHit* hit = getHit(i);
217  if(hit)
218  {
219  m=(Int_t)hit->module();
220  s=abs((Int_t)hit->sub());
221  mGeom->getPhi(m,s, P);
222  P-= phi;
223  P = StEmcMath::getPhiPlusMinusPi(P);
224  if(P<=0)
225  hasBelow=kTRUE;
226  else
227  above->Add(hit);
228  }
229  }
230  if(hasBelow && above->GetSize()>0)
231  {
232  cluster = new StEmcPreCluster(detector());
233  Int_t na = above->GetSize();
234  for(Int_t i = 0;i<na;i++)
235  {
236  StEmcRawHit* hit = (StEmcRawHit*)above->At(i);
237  removeHit(hit);
238  cluster->addHit(hit);
239  }
240  update();
241  cluster->update();
242  }
243  delete above;
244  return cluster;
245 }
247 {
248  Int_t nH = nHits();
249  if(nH==0)
250  return NULL;
251  StEmcCluster *cluster = new StEmcCluster();
252  for(Int_t i = 0;i<nH;i++)
253  cluster->addHit(getHit(i));
254  update();
255  cluster->setEta(mEta);
256  cluster->setPhi(mPhi);
257  cluster->setSigmaEta(mSigmaEta);
258  cluster->setSigmaPhi(mSigmaPhi);
259  cluster->setEnergy(mEnergy);
260  cluster->SetUniqueID(mMatchingId);
261  return cluster;
262 }
StEmcPreCluster * splitInEta(Float_t)
split the cluster in the eta coordinate. Returns a pointer of the splitted cluster. The spllited cluster is not added to any collection
Int_t detector() const
returns the detector number
Int_t matchingId() const
returns the matching id with other detectors. 0 means no matching
Float_t energy() const
returns the energy of the cluster
void subtractCluster(StEmcPreCluster *)
subtract another cluster to this one.
void addHit(StEmcRawHit *)
add a hit to the cluster
Int_t nHits() const
returns the number of hits in the cluster
StEmcPreCluster * splitInPhi(Float_t)
split the cluster in the phi coordinate. Returns a pointer of the splitted cluster. The spllited cluster is not added to any collection
void removeHit(StEmcRawHit *)
removes a hit from the cluster
StEmcCluster * makeStCluster()
creates an StEmcCluster from the information in this pre cluster
void update()
updates cluster information. Calculates eta,phi, ernergy, etc from the hits added to the cluster ...
void addCluster(StEmcPreCluster *)
add another cluster to this one. Does not delete the added cluster
StEmcRawHit * getHit(Int_t i)
gets a pointer to a hit in the cluster
Float_t phi() const
returns the phi position of the cluster