StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEEmcEnergyApportionerIU.cxx
1 /*
2  * \class StEEmcEnergyApportionerIU_t
3  * \author Stephen Gliske <sgliske@anl.gov>
4  *
5  * See header file for description.
6 */
7 
8 #include <vector>
9 #include <Rtypes.h>
10 
11 #include "StRoot/StEEmcPool/./EEmcTreeContainers/EEmcEnergy.h"
12 #include "StRoot/StEEmcPool/StEEmcPointMaker/eeTowerFunction.h"
13 #include "StEEmcUtil/EEmcGeom/EEmcGeomSimple.h"
14 #include "StRoot/StEEmcPool/StEEmcGeoId/StEEmcGeoId.h"
15 
16 #include "StEEmcEnergyApportionerIU.h"
17 #include "StSimpleCluster.h"
18 #include "StEEmcHit.h"
19 #include "StESMDClustersPerSector.h"
20 
21 StEEmcEnergyApportionerIU_t::StEEmcEnergyApportionerIU_t() : StEEmcEnergyApportioner_t(),
22  mCheckTowerBits(1),
23  weightFunc( &StEEmcEnergyApportionerIU_t::smdSumWeightFunc ){
24  mIsReady = 1;
25 };
26 
28  const StSimpleClusterVec_t& towerClusterVec,
29  const StESMDClustersVec_t &smdClusterVec,
30  StEEmcHitVec_t& hitVec ){
31  if( !hitVec.empty() ){
32  Int_t nInvalid = 0;
33 
34  // Weight per tower per hit. Vector matches vector of hits.
35  // The sparseVec is indexed by tower index, and holds the relative
36  // contribution of each hit to the tower (i.e. non-normalized
37  // weight).
38  std::vector< sparseVec_t > wPerTowerPerHit( hitVec.size() );
39 
40  // temporary, to hold indexes of neighbors
41  std::vector< Int_t > neighborIndices;
42 
43  // to hold denominators (i.e. map used as a sparse vector)
44  sparseVec_t denominator;
45  sparseVec_t::iterator denomIter, weightIter;
46 
47  // iterate over hits
48  StEEmcHitVec_t::iterator hitIter = hitVec.begin();
49 
50  //LOG_INFO << "eee " << "---------------> Energy Apportioner <---------------" << endm;
51 
52  static Int_t kEEmcNumPhiBins = kEEmcNumSubSectors * kEEmcNumSectors;
53  Int_t hitIdx = 0;
54  for( hitIter = hitVec.begin(); hitIter != hitVec.end(); ++hitIter, ++hitIdx ){
55  //LOG_INFO << "eee " << '\t' << (*hitIter) << endm;
56 
57  // get new map
58  sparseVec_t& thisMap = wPerTowerPerHit[ hitIdx ];
59 
60  // clear the neighbors
61  neighborIndices.clear();
62 
63  // various indexing methods
64  Int_t towIdx = hitIter->getTowerIdx();
65  Short_t etaBin = 0;
66  Short_t phiBin = 0;
67  StEEmcGeoId_t::decodeTow( towIdx, phiBin, etaBin );
68 
69  // fill usedTowerIndices with all neighbors of the main hit tower
70  Int_t phiBinLeft = (phiBin ? phiBin-1 : kEEmcNumPhiBins-1);
71  Int_t phiBinRight = (phiBin+1 < kEEmcNumPhiBins ? phiBin+1 : 0);
72 
73  neighborIndices.push_back( StEEmcGeoId_t::encodeTow( phiBinLeft, etaBin ) );
74  neighborIndices.push_back( StEEmcGeoId_t::encodeTow( phiBin, etaBin ) );
75  neighborIndices.push_back( StEEmcGeoId_t::encodeTow( phiBinRight, etaBin ) );
76 
77  if( etaBin < kEEmcNumEtas -1 ){
78  // not at upper limit
79  neighborIndices.push_back( StEEmcGeoId_t::encodeTow( phiBinLeft, etaBin + 1 ) );
80  neighborIndices.push_back( StEEmcGeoId_t::encodeTow( phiBin, etaBin + 1 ) );
81  neighborIndices.push_back( StEEmcGeoId_t::encodeTow( phiBinRight, etaBin + 1 ) );
82  };
83 
84  if( etaBin > 0 ){
85  // not at lower limit
86  neighborIndices.push_back( StEEmcGeoId_t::encodeTow( phiBinLeft, etaBin - 1 ) );
87  neighborIndices.push_back( StEEmcGeoId_t::encodeTow( phiBin, etaBin - 1 ) );
88  neighborIndices.push_back( StEEmcGeoId_t::encodeTow( phiBinRight, etaBin - 1 ) );
89  };
90 
91 
92  // compute contribution of this hit to each tower
93  for( UInt_t i=0; i<neighborIndices.size(); ++i ){
94  Int_t& thisTowIdx = neighborIndices[i];
95  Float_t contribution = (this->*weightFunc)( *hitIter, thisTowIdx );
96 
97  thisMap[ thisTowIdx ] = contribution;
98 
99  denomIter = denominator.find( thisTowIdx );
100  if( denomIter == denominator.end() ){
101  denominator[ thisTowIdx ] = contribution;
102  } else {
103  denominator[ thisTowIdx ] += contribution;
104  };
105  };
106  };
107 
108  // to save indices and weights
109  std::vector< Short_t > usedTowerIndices;
110  std::vector< Float_t > usedTowerWeights;
111 
112  //LOG_INFO << "eee " << "numerators" << endm;
113 
114  // Now that have all the denominators, re-iterate and compute the
115  // energies.
116 
117 // cout << "----------------------------------------" << endl;
118  hitIdx = 0;
119  for( hitIter = hitVec.begin(); hitIter != hitVec.end(); ++hitIter, ++hitIdx ){
120 
121  // get new map
122  sparseVec_t& weightVec = wPerTowerPerHit[ hitIdx ];
123 
124  // clear
125  usedTowerIndices.clear();
126  usedTowerWeights.clear();
127 
128  Float_t hitEnergy = 0;
129  for( weightIter = weightVec.begin(); weightIter != weightVec.end(); ++weightIter ){
130 
131  EEmcElement_t element = eemcEnergyPtr->eTow.getByIdx( weightIter->first );
132 
133 // cout << " towIdx " << weightIter->first << " energy " << element.energy << " fail " << element.fail
134 // << " hit " << hitIdx << " weight " << weightIter->second << "/" << denominator[ weightIter->first ] << endl;
135 
136  if( !mCheckTowerBits || !element.fail ){
137  weightIter->second /= denominator[ weightIter->first ];
138  Float_t energy = element.energy;
139  energy *= weightIter->second;
140 
141  if( energy ){
142  hitEnergy += energy;
143  usedTowerIndices.push_back( weightIter->first );
144  usedTowerWeights.push_back( weightIter->second );
145  };
146  };
147  };
148 
149 // cout << "main Idx = " << hitIter->getTowerIdx() << " hitEnergy = " << hitEnergy << endl;
150  hitIter->setEnergy( hitEnergy );
151  hitIter->setUsedTowers( usedTowerIndices, usedTowerWeights );
152 
153  if( hitEnergy <= 0 ){
154  hitIter->setIsValid(0);
155  ++nInvalid;
156  };
157 // cout << "--------------------" << endl;
158  };
159 
160  // check for invalid
161  while( nInvalid ){
162  // find first invalid one
163  for( hitIter = hitVec.begin(); hitIter != hitVec.end() && hitIter->isValid(); ++hitIter ){ /* */};
164 
165  // remove it
166  hitVec.erase( hitIter );
167  --nInvalid;
168  };
169  };
170 
171  return kStOK;
172 };
173 
176 
177  // assume towerer neighbors hit tower, or wouldn't have gotten to this point
178 
179  // Get eta & phi bins for this tower
180  Short_t phiBin = 0, etaBin = 0;
181  StEEmcGeoId_t::decodeTow( thisTowIdx, phiBin, etaBin );
182  Double_t xTower[2] = { (Double_t) phiBin, (Double_t) etaBin };
183 
184  // Get eta & phi bins for the tower beneath the point, i.e. hit
185  Int_t towIdx = hit.getTowerIdx();
186  Short_t etaHitTower, phiHitTower;
187  StEEmcGeoId_t::decodeTow( towIdx, phiHitTower, etaHitTower );
188 
189  // Get the position of the point on the endcap.
190  // Return 0 if not on the endcap.
191  Int_t sec,sub,eta;
192  Float_t dphi,deta;
193 
194  if ( !mEEmcGeomSimple.getTower( hit.getPosition(), sec, sub, eta, dphi, deta ) )
195  return 0;
196 
197  dphi /= 2.0;
198  deta /= 2.0;
199 
200  // Position of the point in fractional eta, phi space
201  Double_t xHit[2] = {
202  phiHitTower + dphi,
203  etaHitTower + deta
204  };
205 
206  Double_t funcVal = eeTowerFunction( xTower, xHit );
207 
208  //LOG_INFO << "eee " << "tower IDs " << tower.index() << ' ' << hitTower.index() << ", eefunc = " << funcVal << endm;
209 
210  if( funcVal < 0 )
211  funcVal = 0;
212 
213  if( funcVal > 0 )
214  funcVal *= ( hit.getEnergyU()*hit.getWeightU() + hit.getEnergyV()*hit.getWeightV() );
215 
216  return funcVal;
217 };
218 
220  return ( hit.getEnergyU()*hit.getWeightU() + hit.getEnergyV()*hit.getWeightV() );
221 };
222 
223 void StEEmcEnergyApportionerIU_t::setWeightFunction( WeightFunction_t funcType ){
224  switch( funcType ){
225  case SMD_SUM:
227  break;
228  case SMD_SUM_AND_LEAKAGE:
230  break;
231  };
232 };
233 
234 ClassImp( StEEmcEnergyApportionerIU_t );
235 
236 /*
237  * $Id: StEEmcEnergyApportionerIU.cxx,v 1.2 2014/07/28 19:54:52 skoby Exp $
238  * $Log: StEEmcEnergyApportionerIU.cxx,v $
239  * Revision 1.2 2014/07/28 19:54:52 skoby
240  * explicit cast to satisfy C++11
241  *
242  * Revision 1.1 2012/11/26 19:05:54 sgliske
243  * moved from offline/users/sgliske/StRoot/StEEmcPool/StEEmcHitMaker to StRoot/StEEmcPool/StEEmcHitMaker
244  *
245  *
246  */
The class.
Definition: StEEmcHit.h:37
Definition: Stypes.h:40
Float_t(StEEmcEnergyApportionerIU_t::* weightFunc)(const StEEmcHit_t &hit, Int_t thisTowerIdx)
pointer to which function to use for weights
bool getTower(const TVector3 &r, int &sec, int &sub, int &etabin, Float_t &dphi, Float_t &deta) const
Float_t smdSumAndLeakageWeightFunc(const StEEmcHit_t &hit, Int_t thisTowerIdx)
Use sum of SMD energies times leakage function (spline), i.e. the eeTowerFunction.
Float_t smdSumWeightFunc(const StEEmcHit_t &hit, Int_t thisTowerIdx)
Use just sum of SMD energies.
virtual Int_t find(EEmcEnergy_t *eemcEnergyPtr, const StSimpleClusterVec_t &towerClusterVec, const StESMDClustersVec_t &smdClusterVec, StEEmcHitVec_t &hitVec)
apportion the energy