StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFttDb.h
1 /***************************************************************************
2  * StFttDb.h
3  * jdb Feb, 2022
4  ***************************************************************************
5  *
6  * Description: FTT DB Utility
7  ***************************************************************************/
8 
9 #ifndef STFTTDB_H
10 #define STFTTDB_H
11 
12 #ifndef StMaker_H
13 #include "StMaker.h"
14 #endif
15 #include "StEvent/StEnumerations.h"
16 #include <stdint.h>
17 #include <map>
18 
19 
20 class StFttRawHit;
21 class StFttCluster;
22 class StFttPoint;
23 
24 struct FttDataWindow {
25  UChar_t uuid;
26  UChar_t mode;
27  Short_t min;
28  Short_t max;
29  Short_t anchor;
30 };
31 
32 
33 class St_fttHardwareMap;
34 class St_fttDataWindows;
35 
36 class StFttDb : public TDataSet {
37 
38 public:
39  StFttDb(const char *name="fttDb");
40  virtual ~StFttDb();
41  int Init();
42  int InitRun(int runNumber);
43 
44  void SetDebug(int v=1) {mDebug=v;}
45  void setDebug(int v=1) {mDebug=v;}
46  void setDbAccess(int v=1);
47  void setRun(int run);
48 
49 
50  static size_t uuid( StFttRawHit * h, bool includeStrip = false ) ;
51  static size_t uuid( StFttCluster * c ) ;
52 
53  // HARDWARE Mapping StFttRawHits
54  uint16_t packKey( int feb, int vmm, int ch ) const;
55  void unpackKey( int key, int &feb, int &vmm, int &ch ) const;
56  uint16_t packVal( int row, int strip ) const;
57  void unpackVal( int val, int &row, int &strip ) const;
58  void loadHardwareMapFromFile( std::string fn );
59  void loadHardwareMapFromDb( St_fttHardwareMap * );
60  void loadDataWindowsFromFile( std::string fn );
61  void loadDataWindowsFromDb( St_fttDataWindows * );
62 
63 
64  UChar_t plane( StFttRawHit * hit );
65  UChar_t quadrant( StFttRawHit * hit );
66  UChar_t fob( StFttRawHit * hit );
67  UChar_t rob( StFttRawHit * hit );
68  UChar_t rob( StFttCluster * clu );
69 
70  static double stripPitch; // mm
71  static double rowLength; // mm
72  static double lowerQuadOffsetX; //mm
73  static double idealPlaneZLocations[4];
74 
75  static const size_t nPlane = 4;
76  static const size_t nQuadPerPlane = 4;
77  static const size_t nFobPerQuad = 6;
78  static const size_t nVMMPerFob = 4;
79  static const size_t nChPerVMM = 64;
80 
81  static const size_t nQuad = nQuadPerPlane * nPlane; // 4 * 4 = 16 Total number of Quadrants
82  static const size_t nRob = nQuad;
83 
84  static const size_t nFobPerPlane = nFobPerQuad * nQuadPerPlane; // 4 * 6 = 24 Total number of FOB
85  static const size_t nFob = nFobPerPlane * nPlane; // 24 * 4 = 96 total FOB;
86 
87  static const size_t nVMMPerQuad = nFobPerQuad * nVMMPerFob; // 6 * 4 = 24 VMM per Quad
88  static const size_t nVMMPerPlane = nVMMPerQuad * nQuadPerPlane; // 24 * 4 = 96 VMM per Plane
89  static const size_t nVMM = nVMMPerPlane * nPlane; // 96 * 4 = 384 VMM total
90 
91  static const size_t nChPerFob = nVMMPerFob * nChPerVMM; // 4 * 64 = 256 VMM per Plane
92  static const size_t nChPerQuad = nChPerFob * nFobPerQuad; // 256 * 6 = 1536 VMM per Plane
93  static const size_t nChPerPlane = nChPerQuad * nQuadPerPlane; // 1536 * 4 = 6144 Ch per Plane
94  static const size_t nCh = nChPerPlane * nPlane; // 6144 * 4 = 24576 Ch per Plane
95 
96  static const size_t maxADC = 1024 + 1; // 10 bits;
97  static const size_t maxBCID = 4096 + 1; // 12 bits;
98  static const int minTb = -32768 - 1000; // get the under and overflow
99  static const int maxTb = 32768 + 1000;
100 
101  static const size_t nRowsPerQuad = 5; // 0 - 2 (Horizontal or Vertical) + 3, 4 for Diagonal
102  static const size_t nStripOrientations = 5; // real orientations (4) + 1 for unkown = 5 total
103  static const size_t maxStripPerRow = 166; // max number of strips in a row (only row 0 has this many)
104 
105  static vector<string> orientationLabels;
106 
107 
108 
109  UChar_t orientation( StFttRawHit * hit );
110  UChar_t getOrientation( int rob, int feb, int vmm, int row ) const;
111  bool hardwareMap( int rob, int feb, int vmm, int ch, int &row, int &strip, UChar_t &orientation ) const;
112  bool hardwareMap( StFttRawHit * rawHit ) const;
113 
114  void getGloablOffset( UChar_t plane, UChar_t quad, float &dx, float &sx, float &dy, float &sy, float &dz, float &sz );
115 
116  enum TimeCutMode {
117  CalibratedBunchCrossingMode = 0,
118  TimebinMode = 1
119  };
120 
121  void setTimeCut(TimeCutMode mode, int low=-70, int high=30)
122  {
123  mUserDefinedTimeCut = true;
124  mTimeCutMode=mode;
125  mTimeCutLow=low;
126  mTimeCutHigh=high;
127  }
128 
129  void getTimeCut( StFttRawHit * hit, int &mode, int &l, int &h ){
130  mode = mTimeCutMode;
131  l = mTimeCutLow;
132  h = mTimeCutHigh;
133  if (mUserDefinedTimeCut)
134  return;
135 
136  // load calibrated data windows from DB
137  size_t hit_uuid = uuid( hit );
138  if ( dwMap.count( hit_uuid ) ){
139  mode = dwMap[ hit_uuid ].mode;
140  l = dwMap[ hit_uuid ].min;
141  h = dwMap[ hit_uuid ].max;
142  }
143 
144  }
145 
146  private:
147  int mDbAccess=1;
148  int mRun=0;
149  int mDebug=0;
150 
151  bool mUserDefinedTimeCut = false;
152  TimeCutMode mTimeCutMode;
153  int mTimeCutLow, mTimeCutHigh;
154 
155  std :: map< uint16_t , uint16_t > mMap;
156  std :: map< uint16_t , uint16_t > rMap; // reverse map
157 
158  std :: map< uint16_t , FttDataWindow > dwMap;
159 
160  ClassDef(StFttDb,1) //StAF chain virtual base class for Makers
161 };
162 
163 #endif
164 
165 
void setRun(int run)
enable(1) or disable(0) offline DB access
Definition: StFttDb.cxx:41
void setDbAccess(int v=1)
debug level
Definition: StFttDb.cxx:40
static size_t uuid(StFttRawHit *h, bool includeStrip=false)
set run#
Definition: StFttDb.cxx:49
void setDebug(int v=1)
debug level
Definition: StFttDb.h:45