StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFgtTracking.cxx
1 /***************************************************************************
2  *
3  * $Id: StFgtTracking.cxx,v 1.4 2012/04/11 22:13:30 sgliske Exp $
4  * Author: S. Gliske, March 2012
5  *
6  ***************************************************************************
7  *
8  * Description: See header.
9  *
10  ***************************************************************************
11  *
12  * $Log: StFgtTracking.cxx,v $
13  * Revision 1.4 2012/04/11 22:13:30 sgliske
14  * update
15  *
16  * Revision 1.3 2012/04/09 21:08:24 sgliske
17  * many bugs fixed--seems to be working
18  *
19  * Revision 1.2 2012/03/14 22:22:40 sgliske
20  * update
21  *
22  * Revision 1.1 2012/03/07 15:38:04 sgliske
23  * creation
24  *
25  *
26  **************************************************************************/
27 
28 #include "StFgtTracking.h"
29 
30 #include "StRoot/StFgtUtil/StFgtConsts.h"
31 #include "StRoot/StFgtUtil/geometry/StFgtGeom.h"
32 
33 #include "StRoot/StEvent/StEvent.h"
34 #include "StRoot/StEvent/StFgtCollection.h"
35 #include "StRoot/StEvent/StFgtHitCollection.h"
36 #include "StRoot/StEvent/StFgtHit.h"
37 
38 #include "StRoot/StMuDSTMaker/COMMON/StMuDst.h"
39 #include "StRoot/StMuDSTMaker/COMMON/StMuFgtStrip.h"
40 #include "StRoot/StMuDSTMaker/COMMON/StMuFgtCluster.h"
41 
42 //#define DEBUG
43 //#define DEBUG2
44 
45 // initialize structure value
46 Int_t StFgtTrPoint::lastIdx = -1;
47 
48 // constructor
49 StFgtTracking::StFgtTracking( const Char_t* name ) : StMaker( name ) { /* */ };
50 
51 // deconstructor
52 StFgtTracking::~StFgtTracking(){ /* */ };
53 
54 Int_t StFgtTracking::Init(){
55  StFgtTracking::Clear();
56  return kStOk;
57 };
58 
60  // for some reason simply calling Clear() does not work
61  // need to actually cally StFgtTracking::Clear();
62  StFgtTracking::Clear();
63 
64  Int_t ierr = computePointsFromStEvent();
65 
66  if( ierr )
67  ierr = computePointsFromMuDst();
68 
69  if( ierr ){
70  LOG_ERROR << "No valid input" << endm;
71  } else {
72  ierr = makePoints();
73 
74 #ifdef DEBUG
75  LOG_INFO << "mPointsTot = " << mPointsTot << endm;
76 #endif
77 
78  if( !ierr && mPointsTot )
79  ierr = findTracks();
80  };
81 
82  return ierr;
83 };
84 
85 
86 Int_t StFgtTracking::computePointsFromStEvent(){
87  Int_t ierr = kStFatal;
88 
89  StEvent* eventPtr = 0;
90  StFgtCollection *fgtCollectionPtr = 0;
91  StFgtHitCollection *fgtHitColPtr = 0;
92 
93  eventPtr = (StEvent*)GetInputDS("StEvent");
94 
95  if( eventPtr ) {
96  fgtCollectionPtr = eventPtr->fgtCollection();
97 
98  if( fgtCollectionPtr ){
99  // got this far, so flag that this is the right input.
100  ierr = kStOk;
101 
102  // loop over discs
103  for( Int_t disc = 0; disc < kFgtNumDiscs; ++disc ){
104  fgtHitColPtr = fgtCollectionPtr->getHitCollection( disc );
105 
106  if( fgtHitColPtr ){
107  const StSPtrVecFgtHit& hitVec = fgtHitColPtr->getHitVec();
108  StSPtrVecFgtHitConstIterator hitIter;
109 
110  Int_t idx = 0;
111  for( hitIter = hitVec.begin(); hitIter != hitVec.end(); ++hitIter, ++idx )
112  addClus( idx, (*hitIter)->getCentralStripGeoId(), (*hitIter)->getPositionR(), (*hitIter)->getPositionPhi() );
113  };
114  };
115  };
116  };
117 
118  return ierr;
119 };
120 
121 Int_t StFgtTracking::computePointsFromMuDst(){
122  Int_t ierr = kStFatal;
123 
124  // get pointer to input
125  const StMuDst* muDst = (const StMuDst*)GetInputDS("MuDst");
126 
127  if( muDst ){
128  TClonesArray *fgtClusters = muDst->fgtArray( muFgtClusters );
129 
130  if( fgtClusters ){
131  // flag this is the correct input
132  ierr = kStOk;
133 
134  Int_t nClusters = fgtClusters->GetEntriesFast();
135 #ifdef DEBUG
136  LOG_INFO << "Number of clusters " << nClusters << endm;
137 #endif
138 
139  for( Int_t i = 0; i < nClusters; ++i ){
140  StMuFgtCluster* clus = static_cast< StMuFgtCluster* >( (*fgtClusters)[i] );
141  if( clus )
142  addClus( i, clus->getCentralStripGeoId(), clus->getR(), clus->getPhi() );
143  };
144  };
145  };
146 
147  return ierr;
148 };
149 
150 void StFgtTracking::addClus( Int_t clusIdx, Int_t geoId, Float_t rPos, Float_t pPos ){
151  Short_t disc, quad, strip;
152  Char_t layer;
153  StFgtGeom::decodeGeoId( geoId, disc, quad, layer, strip );
154 
155 #ifdef DEBUG2
156  LOG_INFO << "Clus " << clusIdx << " at " << StFgtGeom::encodeGeoName( disc, quad, layer, strip ) << endm;
157 #endif
158 
159  Int_t octIdx = (quad*2 + ( StFgtGeom::getOctant( layer, strip ) == 'S' ))*kFgtNumDiscs + disc;
160 
161  if( layer == 'R' )
162  mRclusVecPerOctDisc[ octIdx ].push_back( StFgtTrClus( clusIdx, rPos ) );
163  else
164  mPclusVecPerOctDisc[ octIdx ].push_back( StFgtTrClus( clusIdx, pPos ) );
165 };
166 
167 Int_t StFgtTracking::makePoints(){
168  for( Int_t disc = 0; disc < kFgtNumDiscs; ++disc ){
169  Double_t discZ = StFgtGeom::getDiscZ( disc );
170 
171  StFgtTrPointVec &pointVec = mPointVecPerDisc[disc];
172 
173  for( Int_t oct = 0; oct < kFgtNumOctantsPerDisc; ++oct ){
174  Int_t octIdx = oct*kFgtNumDiscs + disc;
175 
176  StFgtTrClusVec &rClusVec = mRclusVecPerOctDisc[octIdx];
177  StFgtTrClusVec &pClusVec = mPclusVecPerOctDisc[octIdx];
178 
179  if( !rClusVec.empty() && !pClusVec.empty() ){
180  StFgtTrClusVec::iterator rClusIter = rClusVec.begin();
181  StFgtTrClusVec::iterator pClusIter = pClusVec.begin();
182 
183  for( rClusVec.begin(); rClusIter != rClusVec.end(); ++rClusIter )
184  for( pClusIter = pClusVec.begin(); pClusIter != pClusVec.end(); ++pClusIter )
185  pointVec.push_back( StFgtTrPoint( *rClusIter, *pClusIter, discZ ) );
186  };
187 
188 #ifdef DEBUG
189  if( rClusVec.size() || pClusVec.size() ){
190  LOG_INFO << "oct " << disc+1 << (Char_t)(oct/2+'A') << "." << ( oct%2 ? 'S' : 'L' )
191  << " r/phi clusters? " << rClusVec.size() << ' ' << pClusVec.size() << " points per disc " << pointVec.size() << endm;
192  };
193 #endif
194  };
195 
196  mPointsTot += pointVec.size();
197 
198 #ifdef DEBUG
199  if( pointVec.size() ){
200  LOG_INFO << "Disc " << disc+1 << " contributes " << pointVec.size() << " new points, for a total of " << mPointsTot << " clusters" << endm;
201  };
202 #endif
203  };
204 
205 #ifdef DEBUG2
206  for( Int_t disc = 0; disc < kFgtNumDiscs; ++disc ){
207  StFgtTrPointVec &pointVec = mPointVecPerDisc[disc];
208  for( UInt_t i=0; i<pointVec.size(); ++i ){
209  LOG_INFO << "Disc " << disc+1 << " point " << pointVec[i].trIdx << " ( " << pointVec[i].rIdx << ", " << pointVec[i].pIdx << " )"
210  << " ( " << pointVec[i].pos.X() << ", " << pointVec[i].pos.Y() << " )" << endm;
211  };
212  };
213 #endif
214 
215  return kStOk;
216 };
217 
218 
219 void StFgtTracking::Clear( const Option_t *opt ){
220  mPointsTot = 0;
221  StFgtTrPoint::lastIdx = -1;
222 
223  for( Int_t discOct = 0; discOct < kFgtNumDiscs*kFgtNumOctantsPerDisc; ++discOct ){
224  mRclusVecPerOctDisc[discOct].clear();
225  mPclusVecPerOctDisc[discOct].clear();
226  };
227  for( Int_t disc = 0; disc < kFgtNumDiscs; ++disc )
228  mPointVecPerDisc[disc].clear();
229 };
230 
231 ClassImp( StFgtTracking );
virtual Int_t Make()
static TClonesArray * fgtArray(int type)
returns pointer to the n-th TClonesArray from the fgt arrays
Definition: StMuDst.h:293
Definition: Stypes.h:41