1 #include "StMyPointMaker.h"
6 #include "StEEmcPool/StEEmcClusterMaker/StEEmcCluster.h"
7 #include "StEEmcPool/StEEmcClusterMaker/StEEmcSmdCluster.h"
15 mAllowSplitting=
false;
17 setSmdMinFraction(0.0);
22 Int_t StMyPointMaker::Init()
25 return StEEmcGenericPointMaker::Init();
32 gMessMgr->Info() <<
GetName() <<
" -I- building points " << endm;
44 for ( Int_t sector=0;sector<12;sector++ )
49 std::sort( clusters.begin(), clusters.end() );
50 std::reverse( clusters.begin(), clusters.end() );
52 LOG_INFO <<
GetName() <<
" sector "<<sector+1
53 <<
" nclusters="<<clusters.size()
62 for ( UInt_t ic=0;ic<clusters.size();ic++ )
72 StEEmcSmdClusterVec_t clusters1 =
73 (matches.smdu.size()<matches.smdv.size()) ? matches.smdu : matches.smdv;
77 StEEmcSmdClusterVec_t clusters2 =
78 (matches.smdu.size()<matches.smdv.size()) ? matches.smdv : matches.smdu;
80 if ( clusters1.size() == 0 )
continue;
81 if ( clusters2.size() == 0 )
continue;
93 if ( mAllowSplitting && cluster.
momentum().Perp() > mSplitMinimumET )
95 if ( SplitClusters( clusters1, clusters2 ) )
104 StEEmcSmdClusterVec_t uclusters = ( clusters1[0].plane()==0 ) ? clusters1 : clusters2 ;
105 StEEmcSmdClusterVec_t vclusters = ( clusters1[0].plane()==0 ) ? clusters2 : clusters1 ;
108 UInt_t npoints = clusters1.size();
109 for ( UInt_t ipoint = 0; ipoint < npoints; ipoint++ )
120 Float_t energy = ( u.energy() + v.energy() ) / 0.014;
123 Float_t sigma = ( u.sigma() + v.sigma() ) / 2.0;
127 if ( position.Z() < 0. )
129 LOG_WARN<<
GetName()<<
" attempt to add point with invalid intersection: "<<Form(
" X=%5.1f Y=%5.1f sec=%i %i u=%5.1f v=%5.1f",
130 position.X(),position.Y(),u.sector(),v.sector(),u.mean(),v.mean())<<endm;
144 LOG_WARN<<
GetName()<<
" attempt to add point which misses the EEMC towers: "<<Form(
" X=%5.1f Y=%5.1f sec=%i %i u=%5.1f v=%5.1f",
145 position.X(),position.Y(),u.sector(),v.sector(),u.mean(),v.mean())<<endm;
184 Float_t sumw[720];
for ( Int_t ii=0;ii<720;ii++ ) sumw[ii]=0.;
206 Float_t w = sumw[tower.
index()];
211 w = sumw[ neighbor.
index() ];
212 if ( !neighbor.
fail() && w>0. ) epoint+=neighbor.
energy() * point.
energy()/w;
221 Int_t index = tower.
index();
244 if ( list1.size() == 1 && list2.size()==1 )
247 if ( list1.size() > list2.size() )
250 if ( list2.size() == 0 )
253 LOG_DEBUG<<
GetName()<<
" associating smd clusters"<<endm;
259 std::vector<UInt_t> index1;
260 std::vector<UInt_t> index2;
261 for ( UInt_t i=0;i<list1.size();i++ ){ index1.push_back(i); }
262 for ( UInt_t i=0;i<list2.size();i++ ){ index2.push_back(i); }
264 std::vector<UInt_t> best1;
265 std::vector<UInt_t> best2;
271 Float_t ediff_min = 9.0E9;
277 LOG_DEBUG<<
GetName()<<
" permutation = " << count++ <<
" ediff_min="<< ediff_min<< endm;
281 Float_t ediff_sum = 0.0;
282 for ( UInt_t i=0;i<list1.size();i++ )
286 UInt_t i1 = index1[i];
287 UInt_t i2 = index2[i];
292 if ( cluster1.sector() != cluster2.sector() )
goto INVALID_PERM;
293 if ( cluster1.plane () == cluster2.plane () )
goto INVALID_PERM;
295 Float_t mean1 = cluster1.mean();
296 Float_t mean2 = cluster2.mean();
299 if ( hit.Z() < -1.0 )
goto INVALID_PERM;
301 Float_t echi2 =
energyChi2( cluster1, cluster2 );
302 if ( echi2 < 0. )
goto INVALID_PERM;
309 if ( ediff_sum < ediff_min )
313 ediff_min = ediff_sum;
318 go = std::next_permutation( index2.begin(), index2.end() );
325 if ( best1.size() == index1.size() )
328 StEEmcSmdClusterVec_t temp2;
330 for ( UInt_t i=0;i<best2.size();i++ )
333 temp2.push_back( list2[ best2[i] ] );
337 LOG_DEBUG<<
GetName()<<Form(
" ukey\tvkey\t\tvkey")<<endm;
338 LOG_DEBUG<<
GetName()<<Form(
" \t(initial)\t(final)")<<endm;
339 for ( UInt_t i=0;i<best1.size();i++ )
341 LOG_DEBUG<<
GetName()<<Form(
" %i\t%i\t\t%i", list1[i].key(), list2[i].key(), temp2[i].key() )<<endm;
359 Bool_t StMyPointMaker::SplitClusters( StEEmcSmdClusterVec_t &list1,
360 const StEEmcSmdClusterVec_t &list2 )
367 if ( list2.size() != 2 )
return false;
372 if ( list1.size() != 1 )
return false;
378 Float_t ediff12 =
energyChi2( list1[0], list2[0] );
383 Float_t ediff22 =
energyChi2( list1[0], list2[0], list2[1] );
388 if ( ediff12 <= ediff22 )
return false;
391 Float_t chi2_a=9.0E9, chi2_b = 9.0E9;
396 Bool_t a =
split( list2[0], list2[1], mergeda, tempa, chi2_a );
397 Bool_t b =
split( list2[1], list2[0], mergedb, tempb, chi2_b );
402 if ( chi2_a <= chi2_b ) {
403 tempa.
key( mMaxClusterId++ );
404 mergeda.
key( mMaxClusterId++ );
406 list1.push_back( tempa );
410 tempb.
key( mMaxClusterId++ );
411 mergedb.
key( mMaxClusterId++ );
413 list1.push_back( tempb );
421 tempa.
key( mMaxClusterId++ );
422 mergeda.
key( mMaxClusterId++ );
424 list1.push_back( tempa );
430 tempb.
key( mMaxClusterId++ );
431 mergedb.
key( mMaxClusterId++ );
433 list1.push_back( tempb );
446 Float_t e1 = c1.energy() * 1000.0;
447 Float_t e2 = c2.energy() * 1000.0;
448 Float_t esum = e1+e2;
449 Float_t edif = e1-e2;
450 Float_t nmip = esum/1.3;
451 if ( esum <= 0. )
return -1.;
452 return edif*edif/nmip;
456 Float_t e1 = c1.energy() * 1000.0;
457 Float_t e2 = c2.energy() * 1000.0;
458 Float_t e3 = c3.energy() * 1000.0;
459 Float_t esum = e1+e2+e3;
460 Float_t edif = e1-e2-e3;
461 Float_t nmip = esum/1.3;
462 if ( esum <= 0. )
return -1.;
463 return edif*edif/nmip;
483 if ( in1.sector() != in2.sector() )
return false;
484 if ( in1.plane() != in2.plane() )
return false;
485 if ( in1.sector() != out1.sector() )
return false;
486 if ( in1.plane() == out1.plane() )
return false;
495 Int_t size = out1.size();
499 Int_t id_min = seed.
index() - size/2;
500 Int_t id_max = seed.
index() + size/2;
516 Int_t id_first = seed.
index();
519 Int_t id_second = -1;
520 Float_t min_chi2 = 9.0E9;
523 for ( Int_t id_scan=id_min; id_scan<=id_max; id_scan++ )
527 Float_t energy[288];
for ( Int_t ii=0;ii<288;ii++ ) energy[ii]=0.;
531 for ( Int_t ii=0;ii<in1.size();ii++ )
534 Int_t index = strip.
index() + shift;
535 if ( index < 0 || index > 287 )
continue;
536 energy[index] = strip.
energy();
541 for ( Int_t ii=0;ii<in2.size();ii++ )
544 Int_t index = strip.
index() + shift;
545 if ( index < 0 || index > 287 )
continue;
546 energy[index] += strip.
energy();
552 for ( Int_t ii=0;ii<size;ii++ )
556 Int_t jj=strip.
index();
557 Float_t ediff = 1000.0 * ( strip.
energy() - energy[jj] );
558 Float_t esum = 1000.0 * ( strip.
energy() + energy[jj] );
559 Float_t nmip = esum / 1.3;
561 if ( nmip > 0. ) chi2+=ediff*ediff/nmip;
565 if ( chi2 < min_chi2 )
578 if ( id_second < 0 )
return false;
588 my2.
key( mMaxClusterId++ );
598 Float_t energy1[288], energy2[288];
599 for ( Int_t ii=0;ii<288;ii++ ) { energy1[ii]=0.; energy2[ii]=0.; }
601 Int_t shift = id_first - in1.
seed().
index();
602 for ( Int_t ii=0;ii<in1.size();ii++ )
605 Int_t index = strip.
index() + shift;
607 energy1[index] = strip.
energy();
611 for ( Int_t ii=0;ii<in2.size();ii++ )
614 Int_t index = strip.
index()+shift;
616 energy2[index] = strip.
energy();
622 Float_t e1 = energy1[ seed1.
index() ];
623 Float_t e2 = energy2[ seed1.
index() ];
624 if ( e1==0. ) e1=0.5*( energy1[seed1.
index()-1] + energy1[seed1.
index()+1] );
625 if ( e2==0. ) e2=0.5*( energy2[seed1.
index()-1] + energy2[seed1.
index()+1] );
626 Float_t sumw = e1+e2;
627 my1.add( seed1, e1/sumw );
630 Float_t e1 = energy1[ seed2.
index() ];
631 Float_t e2 = energy2[ seed2.
index() ];
632 if ( e1==0. ) e1=0.5*( energy1[seed2.
index()-1] + energy1[seed2.
index()+1] );
633 if ( e2==0. ) e2=0.5*( energy2[seed2.
index()-1] + energy2[seed2.
index()+1] );
634 Float_t sumw = e1+e2;
635 my2.add( seed2, e2/sumw );
638 for ( Int_t ii=0;ii<out1.size();ii++ )
643 Float_t e1 = energy1[ strip.
index() ];
644 Float_t e2 = energy2[ strip.
index() ];
645 if ( e1==0. ) e1=0.5*( energy1[strip.
index()-1] + energy1[strip.
index()+1] );
646 if ( e2==0. ) e2=0.5*( energy2[strip.
index()-1] + energy2[strip.
index()+1] );
648 Float_t sumw = e1+e2;
649 if ( sumw==0. )
continue;
651 if ( strip.
index() != seed1.
index() ) my1.add( strip, e1/sumw );
652 if ( strip.
index() != seed2.
index() ) my2.add( strip, e2/sumw );
TVector3 momentum() const
const StEEmcA2EMaker * mEEanalysis
void cluster(const StEEmcSmdCluster &c, Int_t plane)
Add an smd cluster to this point.
StEEmcTower & tower(Int_t t)
Get the specified tower within the cluster.
Int_t numberOfNeighbors() const
get the number of neighboring towers
Int_t numberOfSmdPoints() const
Number of smd-only points.
EEmc ADC –> energy maker.
Bool_t split(const StEEmcSmdCluster &in1, const StEEmcSmdCluster &in2, StEEmcSmdCluster &out1, StEEmcSmdCluster &out2, Float_t &chi2)
Base class for representing EEMC points.
void energy(Float_t e, Int_t layer=0)
Set the energy of this point.
void neighbor(StEEmcTower *n)
add a tower to list of neighbors
StEEmcStrip & strip(Int_t sector, Int_t plane, Int_t strip)
void name(const Char_t *n)
Set the name for this element.
StEEmcClusterVec_t & clusters(Int_t sec, Int_t layer)
Return a vector of tower clusters.
void fail(unsigned f)
Set a fail bit for this element.
Int_t numberOfClusters(Int_t sector, Int_t layer) const
EEmatch & clusterMatch(const StEEmcCluster &c)
Float_t sigma() const
Returns the width.
void index(Int_t i)
Sets the index for this SMD strip, 0..287.
Bool_t AssociateClusters(const StEEmcSmdClusterVec_t &c1, StEEmcSmdClusterVec_t &c2)
Base class for representing tower, preshower and postshower elements.
const StEEmcGenericClusterMaker * mEEclusters
StEEmcPoint & smdPoint(Int_t ipoint)
StEEmcStrip & seed()
Returns the seed strip (by convention, the first strip added to the cluster).
virtual const char * GetName() const
special overload
Int_t key()
Return a unique key assigned by the cluster maker.
virtual void Clear(Option_t *opts="")
User defined functions.
A base class for representing clusters of EEMC smd strips.
void tower(const StEEmcTower &t, Float_t w=1.)
Add a tower with specified weight to the point.
TVector3 getIntersection(Int_t iSec, Int_t iUStrip, Int_t iVStrip, const TVector3 &vertex) const
virtual void Clear(Option_t *opts="")
User defined functions.
void position(const TVector3 &p)
Set the position of this point at the SMD plane.
A base class for describing clusters of EEMC towers.
StEEmcTower & tower(Int_t index, Int_t layer=0)
Float_t energyChi2(const StEEmcSmdCluster &c1, const StEEmcSmdCluster &c2) const
Given two clusters, return (e1-e2)^2/nmips.
void energy(Float_t e)
Set the energy (adc-ped+0.5)/gain for this element.
StEEmcPoint & point(Int_t ipoint)
StEEmcStrip & strip(Int_t s)
Returns the specified smd strip w/in the cluster.
const EEmcSmdGeom * mEEsmd
Base class for describing an endcap SMD strip.