StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEEmcSmdCluster.cxx
1 
17 #include "StEEmcSmdCluster.h"
18 #include <TMath.h>
19 #include <TH1F.h>
20 
21 #include "StEvent/StEmcCluster.h"
22 
23 ClassImp(StEEmcSmdCluster);
24 
25 // ----------------------------------------------------------------------------
26 StEEmcSmdCluster::StEEmcSmdCluster() : StEEmcBaseCluster()
27 {
28  mEnergy=0.;
29  mSumXW=0.;
30  mSumX2W=0.;
31  mEmcCluster = 0;
32  mLeft=999;
33  mRight=-999;
34 }
35 
36 // ----------------------------------------------------------------------------
37 StEEmcSmdCluster::StEEmcSmdCluster( const StEEmcSmdCluster &c ) : StEEmcBaseCluster()
38 {
39  mStrips=c.mStrips;
40  mWeights=c.mWeights;
41  mEnergy=c.mEnergy;
42  mSumXW=c.mSumXW;
43  mSumX2W=c.mSumX2W;
44  mMean=c.mMean;
45  mSigma=c.mSigma;
46  mSize=c.mSize;
47  mKey=c.mKey;
48  mMatchedTowers=c.mMatchedTowers;
49  mEmcCluster=c.mEmcCluster;
50  mPlane=c.mPlane;
51  mSector=c.mSector;
52 }
53 
54 // ----------------------------------------------------------------------------
55 void StEEmcSmdCluster::print(Option_t *opts) const
56 {
57  const Char_t *names[]={"u","v"};
58  std::cout << "smd cluster plane=" << names[plane()] << std::endl;
59  std::cout << "key = " << key() << std::endl;
60  std::cout << "energy= " << energy() << std::endl;
61  std::cout << "mean = " << mean() << std::endl;
62  if ( TString(opts).Contains("all") ) {
63  for ( UInt_t ii=0;ii<mStrips.size();ii++ )
64  {
65  mStrips[ii].print();
66  std::cout <<" w=" << mWeights[ii] << std::endl;
67  }
68  }
69 }
70 
71 // ----------------------------------------------------------------------------
72 void StEEmcSmdCluster::printLine(Bool_t endline) const
73 {
74  std::cout << strip(0).name() << " "
75  << energy() << " "
76  << mStrips.size() << " "
77  << mean() << " "
78  << sigma();
79  if ( endline ) std::cout << std::endl;
80 }
81 
82 // ----------------------------------------------------------------------------
83 void StEEmcSmdCluster::copy( TH1F *h ) const
84 {
85  for ( UInt_t ii=0;ii<mStrips.size();ii++ )
86  h->AddBinContent( mStrips[ii].index()+1, mStrips[ii].energy()*1000.*mWeights[ii] );
87 }
88 
89 // ----------------------------------------------------------------------------
90 void StEEmcSmdCluster::add(const StEEmcStripVec_t &strips)
91 {
92  for ( UInt_t ii=0;ii<strips.size();ii++ ) add( strips[ii] );
93 }
94 
95 // ----------------------------------------------------------------------------
96 void StEEmcSmdCluster::add(const StEEmcStrip &strip, Float_t weight)
97 {
98 
99  if ( mStrips.size() == 0 )
100  {
101  mPlane=strip.plane();
102  mSector=strip.sector();
103  }
104 
105  mWeights.push_back(weight);
106  mStrips.push_back(strip);
107 
108  Float_t energy = strip.energy() * weight;
109 
110  mEnergy += energy;
111  mSumXW += ( strip.index() + 0.5 ) * energy;
112  mSumX2W += ( strip.index() + 0.5 ) * ( strip.index() + 0.5 ) * energy;
113 
114  mMean = mSumXW / mEnergy;
116  mSigma = TMath::Sqrt(mSigma);
117 
118  mSize=(Int_t)mStrips.size();
119  mNumberOfElements=mSize;
120 
121  if ( strip.index()<=mLeft ) mLeft=strip.index()-1;
122  if ( strip.index()>=mRight ) mRight=strip.index()+1;
123 
124 }
125 
126 // ----------------------------------------------------------------------------
128 {
129 
130  if ( mEmcCluster ) return mEmcCluster;
131 
133  Int_t iuv=( mStrips[0].plane()==1 ); // 0=U, 1=V
134 
135  if ( iuv==0 ) {
136  mEmcCluster->setEta( mean() );
137  mEmcCluster->setSigmaEta( sigma() );
138  mEmcCluster->setPhi( -1. );
139  mEmcCluster->setSigmaPhi( -1. );
140  }
141  else {
142  mEmcCluster->setEta( -1. );
143  mEmcCluster->setSigmaEta( -1. );
144  mEmcCluster->setPhi( mean() );
145  mEmcCluster->setSigmaPhi( sigma() );
146  }
147  mEmcCluster->setEnergy( energy() );
148 
149  for ( Int_t i=0; i<numberOfStrips(); i++ ) {
150  StEmcRawHit *hit=mStrips[i].stemc();
151  if (hit) mEmcCluster->addHit( hit );
152  }
153 
154  return mEmcCluster;
155 
156 }
157 
158 // ----------------------------------------------------------------------------
159 Float_t StEEmcSmdCluster::energy(Int_t nmax, Option_t *opts) const
160 {
161 
162  Float_t mymean;
163  if ( TString(opts).Contains("seed") )
164  {
165  mymean=mStrips[0].index()+0.5;
166  }
167  else
168  {
169  mymean=mean();
170  }
171  Int_t min=(Int_t)(mymean-(Float_t)nmax);
172  Int_t max=(Int_t)(mymean+(Float_t)nmax);
173 
174  Float_t esum=0.;
175 
176  for ( UInt_t i=0;i<mStrips.size();i++ )
177  {
178  const StEEmcStrip &s=mStrips[i];
179  if ( s.index() >= min && s.index() <= max ) esum+=s.energy();
180  }
181 
182  return esum;
183 
184 }
185 
186 // ----------------------------------------------------------------------------
187 Float_t StEEmcSmdCluster::sigma(Int_t nmax, Option_t *opts) const
188 {
189 
190  Float_t mymean;
191  if ( TString(opts).Contains("seed") )
192  {
193  mymean=mStrips[0].index()+0.5;
194  }
195  else
196  {
197  mymean=mean();
198  }
199  Int_t min=(Int_t)(mymean-(Float_t)nmax);
200  Int_t max=(Int_t)(mymean+(Float_t)nmax);
201 
202  std::cout << "mymean=" << mymean << std::endl;
203  std::cout << "min =" << min << std::endl;
204  std::cout << "max =" << max << std::endl;
205 
206  Float_t esum=0.;
207  Float_t xsum=0.;
208  Float_t x2sum=0.;
209 
210  for ( UInt_t i=0;i<mStrips.size();i++ )
211  {
212  const StEEmcStrip &s=mStrips[i];
213  std::cout << i << " " << s.index() << std::endl;
214  if ( s.index() >= min && s.index() <= max ) {
215  esum+=s.energy();
216  xsum+=(s.index()+0.5)*s.energy();
217  x2sum+=(s.index()+0.5)*(s.index()+0.5)*s.energy();
218  }
219  }
220  Float_t sig=0.;
221  if ( esum>0. )
222  {
223  sig=TMath::Sqrt( x2sum/esum - (xsum/esum)*(xsum/esum) );
224  }
225 
226 
227  return sig;
228 
229 }
230 
231 // ----------------------------------------------------------------------------
232 ostream& operator<<(ostream &out, const StEEmcSmdCluster &c)
233 {
234  out << "seed="
235  << c.strip(0).name() << " "
236  << "key="
237  << c.key() << " "
238  << c.energy() << " "
239  << c.size() << " "
240  << c.mean() << " "
241  << c.sigma();
242  return out;
243 }
Int_t mRight
index of next strip to the right
Float_t mEnergy
Energy of this SMD cluster.
void name(const Char_t *n)
Set the name for this element.
Definition: StEEmcElement.h:27
Int_t mSector
Sector.
Int_t mPlane
Plane.
Int_t mLeft
index of next strip to the left
void index(Int_t i)
Sets the index for this SMD strip, 0..287.
Definition: StEEmcStrip.cxx:32
Float_t mMean
Mean and sigma computed after each strip is added.
std::vector< Float_t > mWeights
Vector of strip weights.
Int_t key()
Return a unique key assigned by the cluster maker.
StEmcCluster * stemc()
Float_t mSumX2W
Running sums to calculate mean, sigma of cluster.
StEEmcStripVec_t mStrips
Vector of strips belonging to this SMD cluster.
A base class for representing clusters of EEMC smd strips.
Float_t mSigma
Sigma.
StEmcCluster * mEmcCluster
POinter to EMC cluster.
Int_t mSize
Kludge so that root will store number of smd strips.
StEEmcTowerVec_t mMatchedTowers
Vector of hit towers above this SMD cluster.
void plane(Int_t p)
Sets the plane for this SMD strip, 0=U, 1=V.
Definition: StEEmcStrip.h:19
void sector(Int_t s)
Sets the sector for this SMD strip.
Definition: StEEmcStrip.h:17
void energy(Float_t e)
Set the energy (adc-ped+0.5)/gain for this element.
Definition: StEEmcElement.h:21
StEEmcStrip & strip(Int_t s)
Returns the specified smd strip w/in the cluster.
Base class for describing an endcap SMD strip.
Definition: StEEmcStrip.h:8
Float_t mSumXW
Running sums to calculate mean, sigma of cluster.