StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEEmcPointFitMaker.cxx
1 
54 #include "StEEmcPointFitMaker.h"
55 #include "EEmcSectorFit.h"
56 #include "StEEmcPool/StEEmcA2EMaker/StEEmcA2EMaker.h"
57 #include "StEEmcUtil/StEEmcSmd/EEmcSmdGeom.h"
58 #include <algorithm>
59 #include "TString.h"
60 #include "StEEmcPool/StEEmcClusterMaker/StEEmcSmdCluster.h"
61 
62 ClassImp(StEEmcPointFitMaker);
63 
64 // ----------------------------------------------------------------------------
65 StEEmcPointFitMaker::StEEmcPointFitMaker(const Char_t *n):StEEmcPointMaker(n)
66 {
67  for ( Int_t sec=0;sec<12;sec++ )
68  {
69  mSectorFit[sec]=0;
70  }
71 
72  mPermutations=true;
73 
74  mLimitFits=10;
75 
76 }
77 
78 // ----------------------------------------------------------------------------
80 {
81  return StEEmcPointMaker::Init();
82 }
83 
84 // ----------------------------------------------------------------------------
86 {
87  mClusterId=10000;
89  for ( Int_t sec=0;sec<12;sec++ )
90  {
91  mSectorFit[sec]=new EEmcSectorFit(10);
93  //mSectorFit[sec]->SetPrintLevel(-1);
94  }
95 
97  for ( Int_t i=0;i<12;i++ )
98  {
99  FitSector(i);
100  }
101 
103  if ( mEnergyMode == 0 )
104  shareEnergySmd();
105  else if ( mEnergyMode == 1 )
107 
108 
109  return kStOK;
110 }
111 // ----------------------------------------------------------------------------
113 {
114 
115  EEmcSectorFit *fitter = mSectorFit[sector];
116 
120  Float_t etowers = mEEanalysis->energy(sector,0);
121  Float_t eproject = etowers * 0.007 * 1000.0; // expected smd E [MeV]
122  Float_t nproject = eproject / 1.3; // expected smd E [nmips]
123 
124 
126  TString uname="h";uname+=(sector+1<10)?"0":"";uname+=sector+1;uname+="U";
127  TString vname="h";vname+=(sector+1<10)?"0":"";vname+=sector+1;vname+="V";
128  TH1F *hU=new TH1F(uname,"SMD-u energy distribution [nmips]",288,0.,288.);
129  TH1F *hV=new TH1F(vname,"SMD-v energy distribution [nmips]",288,0.,288.);
130 
131  for ( Int_t hit=0;hit<mEEanalysis->numberOfHitStrips(sector,0);hit++ ) {
132  StEEmcStrip strip=mEEanalysis->hitstrip(sector,0,hit);
133  if ( strip.fail() ) continue;
134  hU->SetBinContent( strip.index()+1, strip.energy() * 1000.0 / 1.3 );
135  }
136  for ( Int_t hit=0;hit<mEEanalysis->numberOfHitStrips(sector,1);hit++ ) {
137  StEEmcStrip strip=mEEanalysis->hitstrip(sector,1,hit);
138  if ( strip.fail() ) continue;
139  hV->SetBinContent( strip.index()+1, strip.energy() * 1000.0 / 1.3 );
140  }
141 
144  mSectorFit[sector]->SetHistograms(hU,hV);
145 
146 
148  if ( etowers < 1.0 ) return kStOK;
149 
150 
151  Float_t nfit = 0.;
152  Float_t nlast = 5.0;
153  Int_t count = 0;
154 
155  while ( nfit < 0.90 * nproject && nlast >= 4.0 && count < mLimitFits ) {
156 
158  Double_t res5umax=0.;
159  Double_t res5vmax=0.;
160  Double_t res5u=0.;
161  Double_t res5v=0.;
162  Int_t maxu=-1;
163  Int_t maxv=-1;
164  for ( Int_t i=0;i<288;i++ )
165  {
166  res5u=fitter->Residual(i,0,2);
167  res5v=fitter->Residual(i,1,2);
168  // resu=fitter->Residual(i,0);
169  // resv=fitter->Residual(i,1);
170  if ( res5u > res5umax ) {
171  res5umax=res5u;
172  maxu=i;
173  }
174  if ( res5v > res5vmax ) {
175  res5vmax=res5v;
176  maxv=i;
177  }
178  }
179 
181  if ( maxu<0 || maxv<0 ) {
182  // std::cout << "maxu || maxv < 0, abort" << std::endl;
183  break;
184  }
185  if ( res5umax < 4.0 && res5vmax < 4.0 ) {
186  // std::cout << "Not enough signal, abort" << std::endl;
187  break;
188  }
189 
191  // std::cout << "Adding candidate, now I expect some output!" << std::endl;
192  fitter -> AddCandidate( (res5umax+res5vmax)/2., 0.85, (Double_t)maxu+0.5, (Double_t)maxv+0.5 );
193 
195  fitter -> Migrad();
196 
198  Double_t e,s,u,v;
199  fitter->GetLastCandidate( e, s, u, v );
200  nlast = e;
201 
204  if ( count && count < 5 ) fitter -> TryPermutations();
205 
207  nfit = 0.;
208  for ( Int_t i=0;i<fitter->numberOfCandidates();i++ ){
209 
210  fitter->GetCandidate(i,e,s,u,v);
211  nfit += e;
212 
213  }
214 
215  count++;
216  if ( nlast < 4.0 ) break;
217 
218  }
219 
220 
221  //$$$ std::cout << "found ncand=" << fitter->numberOfCandidates() << std::endl;
222 
223 
226  std::vector<Bool_t> drop( fitter->numberOfCandidates(), false );
227  for ( Int_t ifit=0;ifit<fitter->numberOfCandidates()-1;ifit++ )
228  {
229  Double_t e1,s1,u1,v1;
230  fitter->GetCandidate(ifit,e1,s1,u1,v1);
231  for ( Int_t jfit=ifit+1;jfit<fitter->numberOfCandidates();jfit++ )
232  {
233  Double_t e2,s2,u2,v2;
234  fitter->GetCandidate(jfit,e2,s2,u2,v2);
235 
237  Float_t dist = TMath::Sqrt( (u1-u2)*(u1-u2) + (v1-v2)*(v1-v2) );
238 
240  if ( e1 < 0.15 * e2 ) {
241  Float_t min_dist = TMath::Abs(s1) * 3.5;
242  if ( dist < min_dist ) drop[ifit]=true;
243  }
244 
246  if ( e2 < 0.15 * e1 ) {
247  Float_t min_dist = TMath::Abs(s2) * 3.5;
248  if ( dist < min_dist ) drop[jfit]=true;
249  }
250 
251  }
252  }
253 
254 
255 
259 
260  for ( Int_t ifit=0;ifit<fitter->numberOfCandidates();ifit++ )
261  {
262 
264  if ( drop[ifit] ) continue;
265 
266  Double_t nmip,sigma,u,v;
267  fitter->GetCandidate( ifit, nmip, sigma, u, v );
269  point.sector( sector );
270  point.sigma( sigma );
271  point.u(u);
272  point.v(v);
273  point.energy( (Float_t)(nmip * 1.3 / 0.007 / 1000.0) );
274  TVector3 position = mEEsmd->getIntersection( sector, (Int_t)u, (Int_t)v );
275  point.position( position );
276  StEEmcTower *tower = mEEanalysis->tower(position,0);
277  if ( !tower ) continue;
278  point.tower( *tower );
280  point.residueU( (Float_t)fitter -> Residual( (Int_t)u, 0, 60 ) * 1.3 / 1000.0 );
281  point.residueV( (Float_t)fitter -> Residual( (Int_t)v, 1, 60 ) * 1.3 / 1000.0 );
282 
283 
285  StEEmcSmdCluster uc;
286  uc.energy( (float)(nmip * 1.3 / 1000.0) );
287  uc.mean( (float)u );
288  uc.sigma( (float)sigma );
289  uc.sector ( sector );
290  uc.plane( 0 );
291  uc.key( mClusterId++ );
292  StEEmcSmdCluster vc;
293  vc.energy( (float)(nmip * 1.3 / 1000.0) );
294  vc.mean ( (float)v );
295  vc.sigma( (float)sigma );
296  vc.plane( 1 );
297  vc.key( mClusterId++ );
298  point.cluster( uc, 0 );
299  point.cluster( vc, 1 );
300  point.energy( (float)(nmip * 1.3 / 1000.0) );
301  point.sector( sector );
302 
303  mPoints.push_back(point);
304 
305  }
306 
307  return kStOK;
308 
309 }
310 // ----------------------------------------------------------------------------
311 void StEEmcPointFitMaker::Clear(Option_t *opts)
312 {
314  for ( Int_t i=0;i<12;i++ )
315  if ( mSectorFit[i] ) delete mSectorFit[i];
316 
318 }
319 
320 // ----------------------------------------------------------------------------
322 {
323  for ( Int_t i=0;i<12;i++ )
324  {
325  mSectorFit[i]->print();
326  }
327  for ( UInt_t i=0;i<mPoints.size();i++ )
328  {
329  mPoints[i].print();
330  }
331 }
Float_t residueU() const
Get the residual in the U plane.
Definition: StEEmcPoint.h:105
StEEmcA2EMaker * mEEanalysis
ADC2E.
void cluster(const StEEmcSmdCluster &c, Int_t plane)
Add an smd cluster to this point.
Definition: StEEmcPoint.h:40
void shareEnergySmd()
Divide energy of eemc towers between identified smd points in proportion to the smd energy...
Base class for representing EEMC points.
Definition: StEEmcPoint.h:24
void print() const
print summary
void energy(Float_t e, Int_t layer=0)
Set the energy of this point.
Definition: StEEmcPoint.h:34
StEEmcPointVec_t mPoints
All fully reconstructed points.
void GetCandidate(Int_t i, Double_t &nmips, Double_t &width, Double_t &u, Double_t &v)
Returns the parameters of the fit to the ith gamma candidate.
Definition: EEmcSectorFit.h:69
Bool_t mPermutations
Do or don&#39;t do permutations.
EEmcSectorFit * mSectorFit[12]
Fits.
Int_t sector() const
Returns the sector.
Definition: StEEmcPoint.h:85
void shareEnergySimple()
Divide energy of eemc towers between identified smd points (doesn&#39;t work as well as smd algo) ...
void print() const
Print summary.
StEEmcPoint point(Int_t ipoint)
Return a specified point.
Int_t FitSector(Int_t s)
Fit the specified sector.
StEEmcStrip & hitstrip(Int_t sec, Int_t pl, Int_t hit)
virtual void Clear(Option_t *opts="")
Clear the maker.
Int_t numberOfHitStrips(Int_t sector, Int_t plane) const
Int_t Init()
Initialize.
virtual Int_t Make()
Process event.
Class for building points from smd clusters.
Float_t u() const
Returns mean U position.
Definition: StEEmcPoint.h:95
void fail(unsigned f)
Set a fail bit for this element.
Definition: StEEmcElement.h:25
Int_t mLimitFits
Maximum number of points to fit per sector.
Float_t energy(Int_t sector, Int_t layer) const
Float_t sigma() const
Returns the width.
Definition: StEEmcPoint.h:90
void index(Int_t i)
Sets the index for this SMD strip, 0..287.
Definition: StEEmcStrip.cxx:32
Base class for representing tower, preshower and postshower elements.
Definition: StEEmcTower.h:11
Float_t residueV() const
Get the residual in the V plane.
Definition: StEEmcPoint.h:109
Double_t Residual(Int_t x, Int_t plane) const
Int_t key()
Return a unique key assigned by the cluster maker.
Definition: Stypes.h:40
A base class for representing clusters of EEMC smd strips.
A class for finding EEMC points.
void tower(const StEEmcTower &t, Float_t w=1.)
Add a tower with specified weight to the point.
Definition: StEEmcPoint.h:38
TVector3 getIntersection(Int_t iSec, Int_t iUStrip, Int_t iVStrip, const TVector3 &vertex) const
void position(const TVector3 &p)
Set the position of this point at the SMD plane.
Definition: StEEmcPoint.h:32
StEEmcTower & tower(Int_t index, Int_t layer=0)
void GetLastCandidate(Double_t &nmips, Double_t &width, Double_t &u, Double_t &v)
Returns the parameters of the last candidate found.
Definition: EEmcSectorFit.h:71
void Clear(Option_t *opts="")
Clear old points.
void SetHistograms(TH1F *u, TH1F *v)
Set pointers to histograms which will be fit.
Definition: EEmcSectorFit.h:21
Float_t v() const
Returns mean V position.
Definition: StEEmcPoint.h:100
Int_t numberOfCandidates()
Returns the number of gamma candidates.
Definition: EEmcSectorFit.h:66
EEmcSmdGeom * mEEsmd
Smd geometry.
void energy(Float_t e)
Set the energy (adc-ped+0.5)/gain for this element.
Definition: StEEmcElement.h:21
Bool_t doPermutations
Flag to determine if we test all permutations or not.
Definition: EEmcSectorFit.h:84
Base class for describing an endcap SMD strip.
Definition: StEEmcStrip.h:8
Int_t mEnergyMode
Option for dividing energy.
virtual Int_t Init()
Initialize.
Simultaneous fit of two smd planes to N gammas.
Definition: EEmcSectorFit.h:7