StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFgtSimpleClusterAlgo.cxx
1 //
2 // $Id: StFgtSimpleClusterAlgo.cxx,v 1.25 2013/02/19 18:24:04 avossen Exp $
3 // $Log: StFgtSimpleClusterAlgo.cxx,v $
4 // Revision 1.25 2013/02/19 18:24:04 avossen
5 // *** empty log message ***
6 //
7 // Revision 1.24 2012/03/08 17:43:40 avossen
8 // added default cluster algo, made StFgtIClusterAlgo destructor =0
9 //
10 // Revision 1.23 2012/03/07 03:57:23 avossen
11 // various updates
12 //
13 // Revision 1.22 2012/02/28 19:32:25 avossen
14 // many changes to enable new clustering algo: New strip fields, identification of seed strips, passing neighboring strips, new order in strip collections
15 //
16 // Revision 1.21 2012/02/06 17:18:15 avossen
17 // fixed negative charge clusters
18 //
19 // Revision 1.20 2012/01/28 20:10:12 avossen
20 // addec cluster uncertainty
21 //
22 // Revision 1.19 2011/11/17 19:23:54 ckriley
23 // fixed small bug
24 //
25 // Revision 1.18 2011/11/10 23:59:22 avossen
26 // modified simple cluster algo so that it should find phi clusters with R<19
27 //
28 // Revision 1.17 2011/11/09 01:53:04 avossen
29 // changed weighting by adc to weighting by charge
30 //
31 // Revision 1.16 2011/11/03 20:04:17 avossen
32 // updated clustering makers and algos to reflect new containers
33 //
34 // Revision 1.15 2011/11/03 15:54:05 avossen
35 // fixed error for last cluster on disk
36 //
37 // Revision 1.14 2011/11/03 15:00:10 sgliske
38 // Error estimate set to st. dev. of the ordinate
39 //
40 // Revision 1.13 2011/11/02 18:44:45 sgliske
41 // updated for changed StFgtHit constructor:
42 // changed saving central strip ptr to geoId in StFgtHit
43 //
44 // Revision 1.12 2011/11/01 18:46:30 sgliske
45 // Updated to correspond with StEvent containers, take 2.
46 //
47 // Revision 1.11 2011/10/27 14:18:25 avossen
48 // minor update
49 //
50 // Revision 1.10 2011/10/26 20:56:50 avossen
51 // use geoIds to determine if two strips are adjacent
52 //
53 // Revision 1.9 2011/10/14 18:45:27 avossen
54 // fixed some bugs in sibmple cluster algo
55 //
56 // Revision 1.8 2011/10/13 20:35:22 balewski
57 // cleanup, added missing return value
58 //
59 // Revision 1.7 2011/10/10 20:35:08 avossen
60 // fixed strip-cluster association in MaxCluster algo, made other files cvs compliant
61 //
62 //
63 // \class StFgtSimpleClusterAlgo
64 // \author Anselm Vossen (avossen@indiana.edu)
65 //
66 
67 #include "StFgtSimpleClusterAlgo.h"
68 #include "StRoot/StFgtUtil/geometry/StFgtGeom.h"
69 
70 #include "StRoot/StEvent/StFgtStripCollection.h"
71 #include "StRoot/StEvent/StFgtStrip.h"
72 #include "StRoot/StEvent/StFgtHitCollection.h"
73 #include "StRoot/StEvent/StFgtHit.h"
74 //for floor
75 #include <math.h>
76 
77 StFgtSimpleClusterAlgo::StFgtSimpleClusterAlgo()
78 {
79  //nothing else to do....
80 };
81 
82 Int_t StFgtSimpleClusterAlgo::Init()
83 {
84  return kStOk;
85 };
86 
98 {
99  // cout.precision(10);
100  //we make use of the fact, that the hits are already sorted by geoId
101  strips.sortByGeoId();
102 
103  Float_t defaultError = 0.001;
104  Short_t disc, quadrant,prvDisc,prvQuad;
105  Char_t layer,prvLayer,noLayer='z';
106  Double_t ordinate, lowerSpan, upperSpan, prvOrdinate;
107  Int_t prvGeoId;
108  Double_t accuCharge=0;
109  Double_t accuChargeError=0;
110  Double_t meanOrdinate=0;
111  Double_t meanSqOrdinate=0;
112  Int_t numStrips=0;
113  //bool lookForNewCluster=true;
114  prvLayer=noLayer;
115  bool isPhi, isR;
116  StFgtHit* newCluster=0;
117  //to compute energy weighted strip id
118  Double_t meanGeoId=0;
119  //for R < R/2 cm the difference in geo id of the phi strips is 2 and only even numbers are used...
120  bool stepTwo=false;
121  //const
122  for( StSPtrVecFgtStripIterator it=strips.getStripVec().begin();it!=strips.getStripVec().end();++it)
123  {
124  StFgtGeom::getPhysicalCoordinate((*it)->getGeoId(),disc,quadrant,layer,ordinate,lowerSpan,upperSpan);
125 
126  if((layer=='R')&& ordinate < kFgtRmid)
127  {
128  stepTwo=true;
129  break;
130  }
131 
132  }
133 
134  for( StSPtrVecFgtStripIterator it=strips.getStripVec().begin();it!=strips.getStripVec().end();++it)
135  {
136  StFgtGeom::getPhysicalCoordinate((*it)->getGeoId(),disc,quadrant,layer,ordinate,lowerSpan,upperSpan);
137  isPhi=(layer=='P');
138  isR=(!isPhi);
139  if(prvLayer==noLayer)//first hit
140  {
141  newCluster=new StFgtHit(clusters.getHitVec().size(),meanGeoId,accuCharge, disc, quadrant, layer, ordinate, defaultError,ordinate, defaultError,0.0,0.0);
142  stripWeightMap_t &stripWeightMap = newCluster->getStripWeightMap();
143  stripWeightMap[ *it ] = 1;
144 
145  // cout <<"strip adc: " << (*it)->getAdc() <<" charge: " << (*it)->getCharge() <<endl;
146  accuCharge=(*it)->getCharge();
147  accuChargeError=(*it)->getChargeUncert();
148  meanGeoId=(*it)->getCharge()*(*it)->getGeoId();
149  // cout << meanGeoId<<endl;
150 
151  meanOrdinate=ordinate;
152  meanSqOrdinate=ordinate*ordinate;
153  prvLayer=layer;
154  prvGeoId=(*it)->getGeoId();
155  numStrips=1;
156  prvOrdinate=ordinate;
157  //go to next hit
158  continue;
159  }
160 
161  // bool adjacentStrips=(((abs(prvOrdinate-ordinate)<StFgtGeom::kFgtPhiAnglePitch) &&isPhi)|| ((abs(prvOrdinate-ordinate)<StFgtGeom::kFgtRadPitch) && isR));
162  //so either
163  bool adjacentStrips=((abs(prvGeoId-(*it)->getGeoId())<2)|| (( abs(prvGeoId-(*it)->getGeoId())==2) && stepTwo && isPhi && (prvGeoId%2==0)));
164 
165  //if the strip is adjacent to the last one? Then we add it to the cluster
166  if((layer==prvLayer && adjacentStrips)&& prvLayer!=noLayer)
167  {
168  //should really be charge...
169  //accuCharge+=(*it)->getCharge();
170  // cout <<"adjacent strip with charge: " << (*it)->getCharge() <<endl;
171  accuCharge+=(*it)->getCharge();
172  accuChargeError+=(*it)->getChargeUncert();
173  meanOrdinate+=ordinate;
174  meanGeoId+=(*it)->getCharge()*(*it)->getGeoId();
175  // cout<<"accuCharge is: " << accuCharge <<endl;
176  // cout <<"meango: " << (*it)->getCharge() <<" * " << (*it)->getGeoId() <<" meanGeoId now " << meanGeoId <<endl;
177 
178  meanSqOrdinate+=ordinate*ordinate;
179  numStrips++;
180 
181  stripWeightMap_t &stripWeightMap = newCluster->getStripWeightMap();
182  stripWeightMap[ *it ] = 1;
183  prvLayer=layer;
184  prvGeoId=(*it)->getGeoId();
185  prvOrdinate=ordinate;
186  continue;
187  }
188  else
189  {//we are looking at a new cluster because we are not at the beginning and the new strip is not adjacent to the old one
190  //set charge, push back cluster, start new one
191  //set layer etc of cluster
192 
193  // cout <<"setting charge of new cluster to (1)" << accuCharge <<endl;
194 
195  newCluster->setCharge(accuCharge);
196  numStrips > 1 ? newCluster->setChargeUncert(sqrt(accuChargeError/((float)numStrips-1))) : newCluster->setChargeUncert(sqrt(accuChargeError/((float)numStrips)));
197  // compute mean and st. dev.
198  meanOrdinate /= (float)numStrips;
199  // cout <<" geo id is : " << meanGeoId <<" / " << accuCharge;
200  meanGeoId /= accuCharge;
201 
202  // cout <<" = " << meanGeoId <<" ends up as : " << floor(meanGeoId+0.5)<<endl;
203 
204  meanSqOrdinate /= (float)numStrips;
205  meanSqOrdinate -= meanOrdinate*meanOrdinate;
206  if( meanSqOrdinate > 0 )
207  meanSqOrdinate = sqrt(meanSqOrdinate);
208  // meanSqOrdinate is now the st. dev. of the ordinate
209  // avoid unreasonable small uncertainty, due to small cluster sizes
210  Double_t pitch = ( layer == 'R' ? StFgtGeom::radStrip_pitch() : StFgtGeom::phiStrip_pitch() );
211  if( meanSqOrdinate < 2*pitch )
212  meanSqOrdinate = 2*pitch;
213 
214  if(layer=='R')
215  {
216  newCluster->setPositionR(meanOrdinate );
217  newCluster->setErrorR(meanSqOrdinate);
218  }
219  else
220  {
221  newCluster->setPositionPhi(meanOrdinate );
222  newCluster->setErrorPhi(meanSqOrdinate);
223  }
224  newCluster->setCentralStripGeoId(floor(meanGeoId+0.5));
225  if(numStrips<=kFgtMaxClusterSize && newCluster->getCentralStripGeoId() > 0)
226  clusters.getHitVec().push_back(newCluster);
227  else
228  delete newCluster;
229  // cout <<"cluster has size: " << numStrips <<endl;
230  //
231  accuCharge=(*it)->getCharge();
232  accuChargeError=(*it)->getChargeUncert();
233  meanOrdinate=ordinate;
234  meanGeoId=(*it)->getCharge()*(*it)->getGeoId();
235  // cout<<" geo ID: " << (*it)->getGeoId() <<" charge: " << (*it)->getCharge() <<endl;
236  meanSqOrdinate=ordinate*ordinate;
237  numStrips=1;
238 
239  // cout << " starting new cluster with " << meanGeoId <<" and charge: " << accuCharge <<endl;
240 
241  newCluster=new StFgtHit(clusters.getHitVec().size(),meanGeoId,accuCharge, disc, quadrant, layer, ordinate, defaultError,ordinate, defaultError,0.0,0.0);
242  //add the current stuff
243  stripWeightMap_t &stripWeightMap = newCluster->getStripWeightMap();
244  stripWeightMap[ *it ] = 1;
245  prvLayer=layer;
246  prvGeoId=(*it)->getGeoId();
247  prvDisc=disc;
248  prvQuad=quadrant;
249  prvOrdinate=ordinate;
250  }
251  }
252 
253  //if there has been any 1+ clusters, we have to add the last cluster to the list
254  if(newCluster)
255  {
256  //new cluster was started but not included yet..
257  // newCluster->setPosition1D(meanOrdinate/(float)numStrips, defaultError );
258  meanOrdinate /= (float)numStrips;
259  // cout <<" finishing stuff up, mean geo: " << meanGeoId << " accucharge: " << accuCharge;
260  meanGeoId/=accuCharge;
261  // cout <<" and corrected: " << meanGeoId<<endl;
262  // cout <<"set charge: " << accuCharge <<endl;
263  newCluster->setCharge(accuCharge);
264  numStrips > 1 ? newCluster->setChargeUncert(sqrt(accuChargeError/((float)numStrips-1))) : newCluster->setChargeUncert(sqrt(accuChargeError/((float)numStrips)));
265 
266  meanSqOrdinate /= (float)numStrips;
267  meanSqOrdinate -= meanOrdinate*meanOrdinate;
268  if( meanSqOrdinate > 0 )
269  meanSqOrdinate = sqrt(meanSqOrdinate);
270 
271  // meanSqOrdinate is now the st. dev. of the ordinate
272 
273  // avoid unreasonable small uncertainty, due to small cluster sizes
274  Double_t pitch = ( layer == 'R' ? StFgtGeom::radStrip_pitch() : StFgtGeom::phiStrip_pitch() );
275  if( meanSqOrdinate < 2*pitch )
276  meanSqOrdinate = 2*pitch;
277  if(layer=='R')
278  {
279  newCluster->setPositionR(meanOrdinate );
280  newCluster->setErrorR(meanSqOrdinate);
281  }
282  else
283  {
284  newCluster->setPositionPhi(meanOrdinate );
285  newCluster->setErrorPhi(meanSqOrdinate);
286  }
287 
288  // cout <<"setting central strip to " << floor(meanGeoId+0.5)<<endl;
289 
290  newCluster->setCentralStripGeoId(floor(meanGeoId+0.5));
291  if(numStrips<=kFgtMaxClusterSize && newCluster->getCentralStripGeoId() > 0)
292  clusters.getHitVec().push_back(newCluster);
293  else
294  delete newCluster;
295  }
296 
297  return kStOk;
298 }
299 
300 StFgtSimpleClusterAlgo::~StFgtSimpleClusterAlgo()
301 {
302 
303 }
304 
305 ClassImp(StFgtSimpleClusterAlgo);
virtual Int_t doClustering(const StFgtCollection &fgtCollection, StFgtStripCollection &strips, StFgtHitCollection &clusters)
the main function, using a collection of strips tht fired to build clusters of neighbouring strips ...
Definition: Stypes.h:41