StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StBarrelEmcClusterMaker.cxx
1 #include "StEmcUtil/projection/StEmcPosition.h"
2 #include "StEmcUtil/geometry/StEmcGeom.h"
3 
4 #include "StGammaEventMaker.h"
5 #include "StGammaEvent.h"
6 #include "StGammaRawMaker.h"
7 #include "StBarrelEmcCluster.h"
8 
9 #include "StBarrelEmcClusterMaker.h"
10 
11 using namespace std;
12 
13 ClassImp(StBarrelEmcClusterMaker);
14 
16 // Constructor //
18 StBarrelEmcClusterMaker::StBarrelEmcClusterMaker(const char *name): StMaker(name)
19 {
20  mHighTowerThreshold = 3.6;
21  mClusterThreshold = 5.1;
22 }
23 
25 // Maker Init //
27 int StBarrelEmcClusterMaker::Init()
28 {
29 
30  // Retrieve StGammaEventMaker
31  mGammaEventMaker = dynamic_cast<StGammaEventMaker*>(GetMakerInheritsFrom("StGammaEventMaker"));
32  assert(mGammaEventMaker);
33 
34  // Retrieve StGammaRawMaker
35  mGammaRawMaker = dynamic_cast<StGammaRawMaker*>(GetMakerInheritsFrom("StGammaRawMaker"));
36  assert(mGammaRawMaker);
37 
38  return StMaker::Init();
39 
40 }
41 
43 // Maker Clear //
45 void StBarrelEmcClusterMaker::Clear(Option_t* option)
46 {
47 
48  mVertex.SetXYZ(0,0,0);
49 
50  for(unsigned i = 0; i < mClusters.size(); ++i)
51  {
52  delete mClusters[i];
53  mClusters[i] = 0;
54  }
55 
56  mClusters.clear();
57 
58  StMaker::Clear(option);
59 
60 }
61 
63 // Maker Make //
66 {
67 
68  // Retrieve event vertex
69  if (mGammaEventMaker->event()) mVertex = mGammaEventMaker->event()->vertex();
70 
71  // Search through BEMC for seed towers
72  for(int id = 1; id <= 4800; ++id)
73  {
74 
75  if(StGammaTower* tower = mGammaRawMaker->tower(id, kBEmcTower))
76  {
77 
78  // If a tower passes the seed energy threshold
79  // then construct a candidate cluster
80  if (tower->energy > mHighTowerThreshold)
81  {
82 
83  StBarrelEmcCluster* cluster = makeCluster(tower);
84 
85  // If the clustering was successful and the
86  // cluster passes the energy threshold
87  // then store the cluster
88  if(cluster && cluster->energy() > mClusterThreshold)
89  {
90  mClusters.push_back(cluster);
91  }
92 
93  } // if(seedThreshold)
94 
95  } // if(tower)
96 
97  } // Towers
98 
99 
100  LOG_DEBUG << "Make() - Number of BEMC clusters: " << mClusters.size() << endm;
101 
102  for(unsigned int i = 0; i < mClusters.size(); ++i)
103  {
104  LOG_DEBUG << "---------- BEMC CLUSTER #" << i << " ----------" << endm;
105  LOG_DEBUG << *mClusters[i] << endm;
106  }
107 
108  return kStOk;
109 }
110 
112 // Construct a cluster consisting of the //
113 // 3x3 patch of towers surrounding the //
114 // input seed tower //
115 // //
116 // The cluster energy is the sum of the //
117 // energies of all towers in the cluster, and //
118 // the clsuter position is the energy weighted //
119 // centroid of all the towers. //
121 StBarrelEmcCluster* StBarrelEmcClusterMaker::makeCluster(StGammaTower* tower) const
122 {
123 
124  // Instantiate a copy of StEmcPosition to find
125  // the towers neighboring the seed tower
126  StEmcPosition emcPosition;
127 
128  // Store useful tower info
129  int id = tower->id;
130  float energy = tower->energy;
131 
132  // Calculate the momentum of the tower energy depostion
133  TVector3 position;
134  getTowerPosition(id, position);
135  position *= energy;
136 
137  // Create a candidate cluster
138  StBarrelEmcCluster* cluster = new StBarrelEmcCluster;
139  cluster->setSeed(tower);
140 
141  // Loop over eta neighbors
142  for (int deta = -1; deta <= 1; ++deta)
143  {
144 
145  // Loop over phi neighbors
146  for (int dphi = -1; dphi <= 1; ++dphi)
147  {
148 
149  // Skip the seed tower
150  if(deta == 0 && dphi == 0) continue;
151 
152  // Determine the neighbor softId
153  int neighborId = emcPosition.getNextTowerId(id, deta, dphi);
154 
155  // Grab the StGammaTower corresponding to the neighboring tower
156  if(StGammaTower* neighbor = mGammaRawMaker->tower(neighborId, kBEmcTower))
157  {
158 
159  // If the neighbor energy is less than the seed energy
160  // then add the neighboring tower to the cluster, otherwise
161  // the seed is no longer valid so stop the clustering
162  // and delete the instantiated cluster
163  if (tower->energy > neighbor->energy)
164  {
165 
166  cluster->setTower(deta, dphi, neighbor);
167  TVector3 neighborPosition;
168  getTowerPosition(neighborId, neighborPosition);
169  position += neighborPosition * neighbor->energy;
170  energy += neighbor->energy;
171  }
172  else
173  {
174  delete cluster;
175  return 0;
176  }
177 
178  } // if(neighbor)
179 
180  } // dPhi
181 
182  } // dEta
183 
184  // Normalize the cluster centroid
185  position *= 1.0 / energy;
186 
187  // Set energy and position
188  cluster->setEnergy(energy);
189  cluster->setPosition(position);
190 
191  // Calculate momentum, correcting for the vertex
192  TVector3 momentum = position - mVertex;
193  momentum.SetMag(energy);
194  cluster->setMomentum(momentum);
195 
196  return cluster;
197 
198 }
199 
201 // Retrieve the position of the tower //
202 // with the given softId //
204 void StBarrelEmcClusterMaker::getTowerPosition(int id, TVector3& position) const
205 {
206  float x, y, z;
207  StEmcGeom::instance("bemc")->getXYZ(id, x, y, z);
208  position.SetXYZ(x, y, z);
209 }
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StMaker.cxx:634
TVector3 & vertex()
Returns muDst file from which event originated.
Definition: StGammaEvent.h:79
Int_t getNextTowerId(Float_t eta, Float_t phi, Int_t nTowersdEta, Int_t nTowersdPhi) const
Return neighbor tower id&#39;s.
void Clear(Option_t *option="")
User defined functions.
Definition: Stypes.h:41