StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFttPointMaker.cxx
1 /***************************************************************************
2  *
3  * StFttPointMaker.cxx
4  * Author: jdb 2021
5  ***************************************************************************
6  *
7  * Description: StFttPointMaker - class to fill the StFttPoint in StEvent
8  *
9  ***************************************************************************/
10 #include <vector>
11 #include <map>
12 #include <array>
13 #include <algorithm>
14 
15 
16 #include "StEvent.h"
17 #include "StEnumerations.h"
18 
19 #include "StFttPointMaker.h"
20 
21 
22 #include "StEvent/StFttRawHit.h"
23 #include "StEvent/StFttCluster.h"
24 #include "StEvent/StFttPoint.h"
25 #include "StEvent/StEvent.h"
26 #include "StEvent/StFttCollection.h"
27 
28 #include "StFttDbMaker/StFttDb.h"
29 
30 
31 //_____________________________________________________________
32 StFttPointMaker::StFttPointMaker( const char* name )
33 : StMaker( name ),
34  mEvent( 0 ),
35  mDebug( false ),
36  mUseTestData( false ),
37  mFttDb( nullptr )
38 {
39  LOG_DEBUG << "StFttPointMaker::ctor" << endm;
40 }
41 
42 //_____________________________________________________________
43 StFttPointMaker::~StFttPointMaker()
44 { /* no op */ }
45 
46 //_____________________________________________________________
47 Int_t
48 StFttPointMaker::Init()
49 {
50  return kStOk;
51 }
52 
53 //_____________________________________________________________
54 Int_t
55 StFttPointMaker::InitRun( Int_t runnumber )
56 {
57  return kStOk;
58 }
59 
60 //_____________________________________________________________
61 Int_t
62 StFttPointMaker::FinishRun( Int_t runnumber )
63 {
64  return kStOk;
65 }
66 
67 //_____________________________________________________________
68 Int_t
70 {
71  return kStOk;
72 }
73 
74 
75 //_____________________________________________________________
76 Int_t
78 {
79  mEvent = (StEvent*)GetInputDS("StEvent");
80  if(mEvent) {
81  LOG_DEBUG<<"Found StEvent"<<endm;
82  } else {
83  return kStOk;
84  }
85  mFttCollection=mEvent->fttCollection();
86  if(!mFttCollection) {
87  return kStOk;
88  }
89 
90  mFttDb = static_cast<StFttDb*>(GetDataSet("fttDb"));
91 
92  assert( mFttDb );
93 
94  if ( mUseTestData )
95  InjectTestData();
96 
97  MakeLocalPoints();
98  MakeGlobalPoints();
99 
100  LOG_INFO << "StFttPointMaker made " << mFttCollection->numberOfPoints() << " points this event" << endm;
101 
102  return kStOk;
103 }
104 
105 void StFttPointMaker::InjectTestData(){
106  mFttCollection->rawHits().clear();
107  // TODO: inject clean strip hits to test cluster finder
108  // should be empty for production code
109 }
110 
111 void StFttPointMaker::MakeLocalPoints(){
112  // next we will need them in even more detail
113  // per strip group, but start here
114  // key, dir, value is cluster
115  // std::map< UChar_t, std::vector<StFttCluster *> > clustersPerRob[4][StFttDb::nRowsPerQuad];
116  std::vector< StFttCluster *> clusters[StFttDb::nRob][StFttDb::nRowsPerQuad][StFttDb::nStripOrientations];
117 
118  for ( StFttCluster* clu : mFttCollection->clusters() ) {
119  UChar_t rob = mFttDb->rob( clu );
120  if ( clu->nStrips() < 2 ) continue;
121  clusters[ rob ][ clu->row() ][ clu->orientation() ].push_back( clu );
122  } // loop on hit
123 
124 
125  for ( size_t iRob = 1; iRob < StFttDb::nRob; iRob ++ ){
126  for ( size_t iRowH = 0; iRowH < 3; iRowH++ ){
127  size_t nH = clusters[ iRob ][ iRowH ][ kFttHorizontal ].size();
128  for ( size_t iRowV = 0; iRowV < 3; iRowV++ ){
129  size_t nV = clusters[ iRob ][ iRowV ][ kFttVertical ].size();
130  for ( size_t iH = 0; iH < nH; iH++ ){
131  auto cluH = clusters[ iRob ][ iRowH ][ kFttHorizontal ][ iH ];
132  for ( size_t iV = 0; iV < nV; iV++ ){
133  auto cluV = clusters[ iRob ][ iRowV ][ kFttVertical ][ iV ];
134 
135  StFttPoint * p = makePoint( cluH, cluV );
136  } // iV
137  } // iH
138  } // iRowV
139  } // iRowH
140  } // iRob
141 } // MakeLocalPoints
142 
143 void StFttPointMaker::MakeGlobalPoints() {
144  for ( StFttPoint * p : mFttCollection->points() ){
145 
146  float x = p->x();
147  float y = p->y();
148  float z = 0.0;
149  StThreeVectorD global;
150 
151  // dx is a local shift
152  float dx = 0, dy = 0, dz = 0;
153  // sx is only {1,-1} -> reflected or normal
154  float sx = 0, sy = 0, sz = 0;
155  mFttDb->getGloablOffset( p->plane(), p->quadrant(), dx, sx, dy, sy, dz, sz );
156  global.set( (x + dx) * sx, (y + dy) * sy, (z + dz) * sz );
157  p->setXYZ( global );
158  }
159 }
160 
161 
162 StFttPoint * StFttPointMaker::makePoint( StFttCluster * cluH, StFttCluster * cluV, int mode ){
163 
164  float x = cluV->x();
165  float y = cluH->x();
166 
167  // No pad sepearation
168  if ( mode == 0 ) {
169  StFttPoint * p = new StFttPoint();
170  p->setPlane( cluV->plane() );
171  p->setQuadrant( cluV->quadrant() );
172  p->setX( x );
173  p->setY( y );
174  p->addCluster( cluH, kFttHorizontal );
175  p->addCluster( cluV, kFttVertical );
176  mFttCollection->addPoint(p);
177  return p;
178  } else if ( mode == 1 ){ // simple pad separation
179  float hx1, hx2, hy1, hy2;
180  clusterBounds( cluH, hx1, hy1, hx2, hy2 );
181  float vx1, vx2, vy1, vy2;
182  clusterBounds( cluV, vx1, vy1, vx2, vy2 );
183 
184 
185  if ( y < vy1 || y > vy2 || x < hx1 || x > hx2 ){
186  return nullptr;
187  }
188 
189  StFttPoint * p = new StFttPoint();
190  p->setPlane( cluV->plane() );
191  p->setQuadrant( cluV->quadrant() );
192  p->setX( x );
193  p->setY( y );
194  p->addCluster( cluH, kFttHorizontal );
195  p->addCluster( cluV, kFttVertical );
196  mFttCollection->addPoint(p);
197  return p;
198  }
199 
200  return nullptr;
201 } // makePoint
202 
203 void StFttPointMaker::clusterBounds( StFttCluster* clu, float &x1, float &y1, float &x2, float &y2 ){
204  // printf( "clusterBounds:" );
205  const float rowWidth = 176;
206  if ( clu->orientation() == kFttHorizontal ){
207  y1 = y2 = clu->x();
208  x1 = clu->row() * rowWidth; // rowWidth is a rough estimate of strip width
209  x2 = (clu->row() + 1) * rowWidth; // rowWidth is a rough estimate of strip width
210  }
211 
212  if ( clu->orientation() == kFttVertical ){
213  x1 = x2 = clu->x();
214  y1 = clu->row() * rowWidth; // rowWidth is a rough estimate of strip width
215  y2 = (clu->row() + 1) * rowWidth; // rowWidth is a rough estimate of strip width
216  }
217 } // cluster bounds
218 
Definition: Stypes.h:41