1414#include < math.h>
1515
1616#include " tables/St_fttHardwareMap_Table.h"
17- #include " tables/St_fttDataWindows_Table .h"
17+ #include " tables/St_fttDataWindowsB_Table .h"
1818
1919
2020ClassImp (StFttDb)
@@ -66,12 +66,59 @@ size_t StFttDb::uuid( StFttRawHit * h, bool includeStrip ) {
6666
6767size_t StFttDb::uuid ( StFttCluster * c ) {
6868 // this UUID is not really universally unique
69- // it is unique up to the hardware location
69+ // it is unique up to the hardware location
7070
7171 size_t _uuid = (size_t )c->orientation () + (nStripOrientations) * ( c->row () + nRowsPerQuad * ( c->quadrant () + nQuadPerPlane * c->plane () ) );
7272 return _uuid;
7373}
7474
75+ size_t StFttDb::vmmId ( StFttRawHit * h ) {
76+ // Calculate VMM hardware ID based on electronic readout structure
77+ // VMM_ID = vmm + nVMMPerFob * (feb + nFobPerQuad * (quadrant + nQuadPerPlane * plane))
78+ // Where: plane [0-3], quadrant [0-3], feb [0-5], vmm [0-3]
79+ // Valid range: 0-383 (total of 384 VMMs)
80+
81+ u_char iPlane = h->sector () - 1 ; // sector is 1-based
82+ u_char iQuad = h->rdo () - 1 ; // rdo is 1-based
83+ u_char iFeb = h->feb (); // feb is 0-based
84+ u_char iVmm = h->vmm (); // vmm is 0-based
85+
86+ size_t vmm_id = iVmm + nVMMPerFob * ( iFeb + nFobPerQuad * ( iQuad + nQuadPerPlane * iPlane ) );
87+
88+ return vmm_id;
89+ }
90+
91+
92+ void StFttDb::getTimeCut ( StFttRawHit * hit, int &mode, int &l, int &h ){
93+ mode = mTimeCutMode ;
94+ l = mTimeCutLow ;
95+ h = mTimeCutHigh ;
96+ if (mUserDefinedTimeCut )
97+ return ;
98+
99+ // load calibrated data windows from DB
100+ // NOTE: dwMap is indexed by VMM hardware ID, not geometric UUID
101+ size_t hit_vmmid = vmmId ( hit );
102+
103+ // Validate VMM ID is in expected range
104+ if ( hit_vmmid >= nVMM ) {
105+ LOG_WARN << " StFttDb::getTimeCut - VMM ID out of range: " << hit_vmmid
106+ << " (max=" << (nVMM-1 ) << " )" << endm;
107+ LOG_WARN << " Hit: plane=" << (int )plane (hit)
108+ << " quad=" << (int )quadrant (hit)
109+ << " feb=" << (int )hit->feb ()
110+ << " vmm=" << (int )hit->vmm () << endm;
111+ return ;
112+ }
113+
114+ if ( dwMap.count ( hit_vmmid ) ){
115+ mode = dwMap[ hit_vmmid ].mode ;
116+ l = dwMap[ hit_vmmid ].min ;
117+ h = dwMap[ hit_vmmid ].max ;
118+ }
119+
120+ }
121+
75122
76123uint16_t StFttDb::packKey ( int feb, int vmm, int ch ) const {
77124 // feb = [1 - 6] = 3 bits
@@ -96,15 +143,15 @@ void StFttDb::unpackVal( int val, int &row, int &strip ) const{
96143 return ;
97144}
98145
99- void StFttDb::loadDataWindowsFromDb ( St_fttDataWindows * dataset ) {
146+ void StFttDb::loadDataWindowsFromDb ( St_fttDataWindowsB * dataset ) {
100147 if (dataset) {
101148 Int_t rows = dataset->GetNRows ();
102149
103150 if ( !rows ) return ;
104151
105152 dwMap.clear ();
106153
107- fttDataWindows_st *table = dataset->GetTable ();
154+ fttDataWindowsB_st *table = dataset->GetTable ();
108155 for (Int_t i = 0 ; i < rows; i++) {
109156 for ( int j = 0 ; j < StFttDb::nVMM; j++ ) {
110157 // printf( "[feb=%d, vmm=%d, ch=%d] ==> [row=%d, strip%d]\n", table[i].feb[j], table[i].vmm[j], table[i].vmm_ch[j], table[i].row[j], table[i].strip[j] );
@@ -122,19 +169,16 @@ void StFttDb::loadDataWindowsFromDb( St_fttDataWindows * dataset ) {
122169 fdw.anchor = table[i].anchor [j];
123170 dwMap[ fdw.uuid ] = fdw;
124171
125-
126172 // std::cout << (int)table[i].feb[j] << std::endl;
127173 }
128174 // sample output of first member variable
129175 }
130176 } else {
131- std::cout << " ERROR: dataset does not contain requested table" << std::endl ;
177+ LOG_ERROR << " dataset does not contain requested table" << endm ;
132178 }
133179}
134180
135181void StFttDb::loadDataWindowsFromFile ( std::string fn ) {
136-
137-
138182}
139183
140184
@@ -224,7 +268,7 @@ UChar_t StFttDb::getOrientation( int rob, int feb, int vmm, int row ) const {
224268 }
225269
226270 if ( rob % 2 == 0 ){ // even rob
227- if ( feb % 2 != 0 ) { // odd
271+ if ( feb % 2 == 0 ) { // even feb
228272 // row 3 and 4 are always diagonal
229273 if ( 3 == row || 4 == row )
230274 return kFttDiagonalH ;
@@ -237,7 +281,7 @@ UChar_t StFttDb::getOrientation( int rob, int feb, int vmm, int row ) const {
237281 return kFttVertical ;
238282 } else { // odd rob
239283
240- if ( feb % 2 != 0 ) { // odd
284+ if ( feb % 2 == 0 ) { // even feb
241285 // row 3 and 4 are always diagonal
242286 if ( 3 == row || 4 == row )
243287 return kFttDiagonalV ;
@@ -250,6 +294,9 @@ UChar_t StFttDb::getOrientation( int rob, int feb, int vmm, int row ) const {
250294 return kFttHorizontal ;
251295 }
252296 // should never get here!
297+ if ( mDebug ) {
298+ LOG_DEBUG << " kFttUnknownOrientation = " << kFttUnknownOrientation << endm;
299+ }
253300 return kFttUnknownOrientation ;
254301}
255302
@@ -344,7 +391,7 @@ void StFttDb::getGloablOffset( UChar_t plane, UChar_t quad,
344391
345392 // shifts
346393 dx = 0.0 ;
347- dy = 0 .0 ;
394+ dy = 6 .0 ;
348395 dz = 0.0 ;
349396
350397 if ( plane < 4 )
0 commit comments