StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEEmcCluster.cxx
1 
27 #include "StEEmcCluster.h"
28 #include "StEvent/StEmcCluster.h"
29 
30 #include <iostream>
31 
32 #include "StEEmcUtil/EEmcGeom/EEmcGeomDefs.h"
33 #include "StEEmcUtil/EEmcGeom/EEmcGeomSimple.h"
34 
35 ClassImp(StEEmcCluster);
36 
37 // ----------------------------------------------------------------------------
38 StEEmcCluster::StEEmcCluster()
40 {
41  mEmcCluster=0;
42  mEnergy=0.;
43  mfPhibin=0.0;
44  mfEtabin=0.0;
45  mSumEta2W=0.;
46  mSumEtaW=0.;
47  mSumPhi2W=0.;
48  mSumPhiW=0.;
49  mMomentum=TVector3(0,0,0);
50 }
51 
52 // ----------------------------------------------------------------------------
53 StEEmcCluster::StEEmcCluster( const StEEmcCluster &other )
55 {
56  mEmcCluster=other.mEmcCluster;
57  mKey=other.mKey;
58 
59  mEnergy=other.mEnergy;
60  mfPhibin=other.mfPhibin;
61  mfEtabin=other.mfEtabin;
62  mSumEta2W=other.mSumEta2W;
63  mSumEtaW=other.mSumEtaW;
64  mSumPhi2W=other.mSumPhi2W;
65  mSumPhiW=other.mSumPhi2W;
66 
67  mWeights=other.mWeights;
68 
69  mEnergy=other.mEnergy;
70  mMomentum=other.mMomentum;
71  mPosition=other.mPosition;
72  mMatched=other.mMatched;
73 
74  for ( UInt_t ii=0;ii<other.mTowers.size();ii++ )
75  mTowers.push_back( other.mTowers[ii] );
76 }
77 
78 // ----------------------------------------------------------------------------
81  //$$$ if ( mEmcCluster != 0 ) delete mEmcCluster;
82  mTowers.clear();
83  mWeights.clear();
84 }
85 
86 // ----------------------------------------------------------------------------
87 void StEEmcCluster::add(const StEEmcTower &tower, Float_t weight)
88 {
89 
90  if ( weight * tower.energy() <= 0. ) return;
91 
92  mWeights.push_back( weight );
93  mTowers.push_back( tower );
94 
95  Float_t energy = weight * tower.energy();
96  mEnergy+=energy;
97 
98  mfEtabin+=energy*weight*tower.etabin();
99  int myphi = (tower.phibin() - mTowers[0].phibin());
100  mfPhibin+=energy*weight*myphi;
101 
102  mSumEta2W = (tower.etabin()*tower.etabin())*tower.energy()*weight;
103  mSumPhi2W = (myphi*myphi)*tower.energy()*weight;
104  mSumEtaW = (tower.etabin())*tower.energy()*weight;
105  mSumPhiW = (myphi)*tower.energy()*weight;
106 
107  //$$$ static EEmcGeomSimple geom=EEmcGeomSimple::Instance();
108 
109  EEmcGeomSimple *geom=new EEmcGeomSimple();
110  mMomentum += energy * ( geom->getTowerCenter( (UInt_t)tower.sector(), (UInt_t)tower.subsector(), (UInt_t)tower.etabin() ).Unit() );
111  delete geom;
112 
113  mPosition = mMomentum.Unit();
114  mPosition *= ( kEEmcZSMD / mMomentum.CosTheta() );
115 
116  if ( TMath::Abs(mPosition.Eta())>100.0 ) {
117  Warning("add","Cluster eta is crazy!");
118  print();
119  }
120 
121  mNumberOfElements=mTowers.size();
122 
123 }
124 
125 // ----------------------------------------------------------------------------
127 {
128  return mfEtabin/mEnergy;
129 }
130 
131 // ----------------------------------------------------------------------------
133 {
134  return mfPhibin/mEnergy+mTowers[0].phibin();
135 }
136 
137 // ----------------------------------------------------------------------------
139 {
140 
141  if ( mEmcCluster ) return mEmcCluster;
143 
144  mEmcCluster->setEta( momentum().Eta() );
145  mEmcCluster->setPhi( momentum().Phi() );
146  mEmcCluster->setSigmaEta(-1.);
147  mEmcCluster->setSigmaPhi(-1.);
148  mEmcCluster->setEnergy( energy() );
149  mEmcCluster->SetUniqueID( mKey );
150 #if 1
151  for ( Int_t i=0; i< numberOfTowers(); i++ )
152  {
153  StEmcRawHit *hit=mTowers[i].stemc();
154  if (hit) mEmcCluster->addHit( hit );
155  }
156 #endif
157 
158  return mEmcCluster;
159 }
160 
161 // ----------------------------------------------------------------------------
163 {
164  std::cout << "cluster key: " << mKey << std::endl;
165  std::cout << "seed tower: " << mTowers[0].name() << std::endl;
166  // std::cout << "ntowers: " << mTowers.size() << std::endl;
167  // std::cout << "feta: " << fracEtabin() << std::endl;
168  std::cout << "fphi: " << fracPhibin() << std::endl;
169  std::cout << "energy: " << mEnergy << std::endl;
170  std::cout << "pt: " << mMomentum.Perp() << std::endl;
171  std::cout << "eta: " << mMomentum.Eta() << std::endl;
172  std::cout << "phi: " << mMomentum.Phi() << std::endl;
173 
174  for ( UInt_t i=0;i<mTowers.size();i++ )
175  {
176  mTowers[i].printLine(); std::cout << " W=" << mWeights[i] << std::endl;
177  }
178 }
179 
180 // ----------------------------------------------------------------------------
181 void StEEmcCluster::printLine(Bool_t Endl) const
182 {
183  std::cout << "key="<<mKey<<" seed="<<mTowers[0].name()<<" ntow="<<mTowers.size()<<" pt=" <<mMomentum.Perp()<<" eta="<<mMomentum.Eta()<<" phi="<<mMomentum.Phi();
184  if ( Endl ) std::cout << std::endl;
185 }
186 
187 // ----------------------------------------------------------------------------
188 Bool_t StEEmcCluster::isNeighbor(const StEEmcTower &tower) const
189 {
190 
191  for ( UInt_t i=0;i<mTowers.size();i++ )
192  {
193  StEEmcTower myTower=mTowers[i];
194  if ( myTower.isNeighbor(tower) ) return true;
195  }
196 
197  return false;
198 
199 }
200 
201 // ----------------------------------------------------------------------------
202 Bool_t StEEmcCluster::hasTower(const StEEmcTower &tower) const
203 {
204 
205  for ( UInt_t i=0;i<mTowers.size();i++ )
206  {
207  if ( tower.index() == mTowers[i].index() ) return true;
208  }
209  return false;
210 }
211 
212 // ----------------------------------------------------------------------------
213 Float_t StEEmcCluster::sigmaE() const
214 {
215  Float_t sumE=0.;
216  Float_t sumE2=0.;
217  Float_t sumw=0.;
218  for ( UInt_t i=0;i<mTowers.size();i++ )
219  {
220  StEEmcTower t=mTowers[i];
221  Float_t w=mWeights[i];
222  sumE += t.energy()*w;
223  sumE2 += t.energy()*t.energy()*w;
224  sumw+=w;
225  }
226  Float_t mean=sumE/sumw;
227  Float_t var=sumE2/sumw-mean*mean;
228  return TMath::Sqrt(var);
229 }
230 
231 // ----------------------------------------------------------------------------
232 Int_t StEEmcCluster::numberOfEtabins() const
233 {
234  Int_t etabins[12];for ( Int_t ii=0;ii<12;ii++ ) etabins[ii]=0;
235  for ( UInt_t ii=0;ii<mTowers.size();ii++ ) etabins[ mTowers[ii].etabin() ]++;
236  Int_t count=0;
237  for ( Int_t ii=0;ii<12;ii++ ) if ( etabins[ii] ) count++;
238  return count;
239 }
240 
241 // ----------------------------------------------------------------------------
242 Int_t StEEmcCluster::numberOfPhibins() const
243 {
244  Int_t phibins[60];for ( Int_t ii=0;ii<12;ii++ ) phibins[ii]=0;
245  for ( UInt_t ii=0;ii<mTowers.size();ii++ ) phibins[ mTowers[ii].phibin() ]++;
246  Int_t count=0;
247  for ( Int_t ii=0;ii<12;ii++ ) if ( phibins[ii] ) count++;
248  return count;
249 }
TVector3 momentum() const
Definition: StEEmcCluster.h:69
TVector3 getTowerCenter(const UInt_t sec, const UInt_t sub, const UInt_t etabin) const
Bool_t isNeighbor(const StEEmcTower &t) const
Definition: StEEmcTower.cxx:98
Float_t fracEtabin() const
Returns the fractional mean etabin.
TVector3 mMomentum
Momentum.
void add(const StEEmcTower &t, Float_t weight=1.0)
Bool_t hasTower(const StEEmcTower &tower) const
Returns true if the specified tower is in the cluster.
StEEmcTowerVec_t mTowers
Vector of towers.
Float_t weight(Int_t t) const
Get the weight associated with tower.
Definition: StEEmcCluster.h:87
void print() const
Prints cluster data.
Int_t etabin() const
Returns the etabin of this tower, pre- or postshower element.
Definition: StEEmcTower.h:45
virtual ~StEEmcCluster()
Int_t subsector() const
Returns subsector of this tower, pre- or postshower element.
Definition: StEEmcTower.h:43
Float_t mfEtabin
void index(Int_t i)
Definition: StEEmcTower.cxx:76
Base class for representing tower, preshower and postshower elements.
Definition: StEEmcTower.h:11
StEmcCluster * stemc()
Bool_t isNeighbor(const StEEmcTower &tower) const
Returns true if tower is adjacent to any tower in the cluster.
Float_t mEnergy
Energy.
Definition: StEEmcCluster.h:66
Int_t sector() const
Returns sector of this tower, pre- or postshower element.
Definition: StEEmcTower.h:41
Int_t numberOfTowers() const
Get the number of towers in cluster.
Definition: StEEmcCluster.h:76
EEMC simple geometry.
Float_t mfPhibin
Float_t energy() const
Get energy of this cluster.
Definition: StEEmcCluster.h:62
Int_t phibin() const
Returns the phibin of this tower.
Definition: StEEmcTower.h:47
A base class for describing clusters of EEMC towers.
Definition: StEEmcCluster.h:50
StEmcCluster * mEmcCluster
Pointer to EMC cluster.
Float_t sigmaE() const
void energy(Float_t e)
Set the energy (adc-ped+0.5)/gain for this element.
Definition: StEEmcElement.h:21
std::vector< Float_t > mWeights
Vector of tower weights.
Float_t fracPhibin() const
Returns the fractional mean phibin.