StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StBTofINLCorr.cxx
1 /*******************************************************************
2  *
3  * $Id: StBTofINLCorr.cxx,v 1.11 2013/12/06 23:27:59 geurts Exp $
4  *
5  * Author: Xin Dong
6  *****************************************************************
7  *
8  * Description: INL correction for all TDIG board channels
9  *
10  *****************************************************************
11  *
12  * $Log: StBTofINLCorr.cxx,v $
13  * Revision 1.11 2013/12/06 23:27:59 geurts
14  * improve diagnostics in log output (when comparing max ranges to actual ranges)
15  *
16  * Revision 1.10 2012/12/14 06:35:41 geurts
17  * Changed global database calls to direct table access and/or removed deprecated database access code.
18  *
19  * Revision 1.9 2012/02/11 02:13:23 geurts
20  * allow direct access to INL corrections given TDIG-Id
21  *
22  * Revision 1.8 2010/05/25 22:09:44 geurts
23  * improved database handling and reduced log output
24  *
25  * Revision 1.7 2009/12/14 19:38:30 dongx
26  * - mNValidBoards set by the read-in database entrie instead of a hard-coded number
27  * - clean up mNValidTrays and related functions (not needed since previous versions)
28  *
29  * Revision 1.6 2009/08/25 01:02:44 dongx
30  * Correct the total # of rows read-in for the TDIGOnTray table
31  *
32  * Revision 1.5 2009/03/04 04:57:36 dongx
33  * INL arrays changed from float to short - memory occupied reduced by a factor of 2
34  *
35  * Revision 1.4 2009/02/23 23:52:07 dongx
36  * In case of missing INL tables in db, return the INL corr from the first element in db
37  *
38  * Revision 1.3 2009/02/13 23:32:52 dongx
39  * fixed the crash when no INL table for some board is available
40  *
41  * Revision 1.2 2009/02/13 22:59:02 dongx
42  * new tofINLSCorr table for full barrel system for Run 9++
43  *
44  * Revision 1.1 2009/02/02 21:57:51 dongx
45  * first release - Barrel TOF INL correction functions
46  *
47  *
48  *******************************************************************/
49 #include <iostream>
50 #include "tables/St_tofTDIGOnTray_Table.h"
51 #include "tables/St_tofINLSCorr_Table.h"
52 #include "StMessMgr.h"
53 #include "StMaker.h"
54 #include "StBTofINLCorr.h"
55 
56 StBTofINLCorr::StBTofINLCorr()
57 {
58  Reset();
59 }
60 
61 StBTofINLCorr::~StBTofINLCorr()
62 {
63  Reset();
64 }
65 
66 void StBTofINLCorr::init() {
67  Reset();
68 }
69 
70 void StBTofINLCorr::init(StMaker *maker) {
71  Reset();
72  initFromDbase(maker);
73 }
74 
76 
77  LOG_INFO << "[StBTofINLCorr] retrieving TDIGOnTray and INL correction tables ..." << endm;
79  // Load configuration parameters from dbase
81 
82  TDataSet *mDbTOFDataSet = maker->GetDataBase("Calibrations/tof/tofTDIGOnTray");
83  St_tofTDIGOnTray* tofTDIGOnTray = static_cast<St_tofTDIGOnTray*>(mDbTOFDataSet->Find("tofTDIGOnTray"));
84  if(!tofTDIGOnTray) {
85  LOG_ERROR << "unable to get tofTDIGOnTray table" << endm;
86  return;
87  }
88  tofTDIGOnTray_st* tdigOnTray = static_cast<tofTDIGOnTray_st*>(tofTDIGOnTray->GetArray());
89 
90  Int_t numRows = tofTDIGOnTray->GetNRows();
91  for (Int_t i=0;i<mNTray+2;i++) {
92  Int_t trayId = (Int_t)tdigOnTray[i].trayId;
93 
94  if(trayId==mEastVpdTrayId) { // east vpd
95  for(Int_t j=0;j<mNTDIGOnTray;j++)
96  mTdigOnEastVpd[j] = (Int_t)tdigOnTray[i].tdigId[j];
97  } else if (trayId==mWestVpdTrayId) { // west vpd
98  for(Int_t j=0;j<mNTDIGOnTray;j++)
99  mTdigOnWestVpd[j] = (Int_t)tdigOnTray[i].tdigId[j];
100  } else if (trayId>0 && trayId<= mNTray) { // barrel Tray
101  for(Int_t j=0;j<mNTDIGOnTray;j++)
102  mTdigOnTray[trayId-1][j] = (Int_t)tdigOnTray[i].tdigId[j];
103  }
104  }
105 
106  mDbTOFDataSet = maker->GetDataBase("Calibrations/tof/tofINLSCorr");
107  St_tofINLSCorr* tofINLCorr = static_cast<St_tofINLSCorr*>(mDbTOFDataSet->Find("tofINLSCorr"));
108  if(!tofINLCorr) {
109  LOG_ERROR << "unable to get tofINLSCorr table" << endm;
110  return;
111  }
112  tofINLSCorr_st* inlcorr = static_cast<tofINLSCorr_st*>(tofINLCorr->GetArray());
113  numRows = tofINLCorr->GetNRows();
114  if(numRows>mNTDIGMAX*mNChanOnTDIG) {
115  { LOG_WARN << "number of rows in tofINLSCorr table ("<< numRows<<") exceeds the array limit ("<<mNTDIGMAX*mNChanOnTDIG << ") in this function! Entries truncated !!!" << endm; }
116  }
117  Int_t NTdig = 0;
118  Int_t tdigId_old = 0;
119  for (Int_t i=0;i<numRows;i++) {
120  if(NTdig>mNTDIGMAX) {
121  { LOG_WARN << " number of boards read-in ("<< NTdig <<") exceeds the array limit ("<<mNTDIGMAX <<") in this function! NTDIG Truncated !!! " << endm; }
122  NTdig = mNTDIGMAX;
123  break;
124  }
125 
126  int tdigId = (Int_t)(inlcorr[i].tdigId);
127  int tdcChanId = (Int_t)(inlcorr[i].tdcChanId);
128  if(tdigId!=tdigId_old) {
129  mBoardId[NTdig] = tdigId;
130  NTdig++;
131  }
132 
133  tdigId_old = tdigId;
134 
135  LOG_DEBUG << " tdigId=" << tdigId << " tdcChanId=" << tdcChanId << endm;
136  for(Int_t j=0;j<mNChanMAX;j++) {
137  Short_t corr = (Short_t)(inlcorr[i].INLCorr[j]);
138  mINLCorr[NTdig-1][tdcChanId][j] = corr;
139 
140  if(maker->Debug()&&(j%200==0)) {
141  LOG_DEBUG << " " << corr;
142  }
143  }
144  if(maker->Debug()) { LOG_DEBUG << endm; }
145  }
146 
147  LOG_INFO << "[StBTofINLCorr] Total number of boards: " << NTdig << endm;
148  mNValidBoards = NTdig;
149 
150  // re-organize
151  for(Int_t i=0;i<NTdig;i++) {
152  int boardId = mBoardId[i];
153  if(boardId>0 && boardId<=mNBoardIdMAX) {
154  mBoardId2Index[boardId] = i;
155  } else {
156  { LOG_WARN<< " Warning! boardId " << boardId << " out of range!" << endm; }
157  }
158  }
159 
160  LOG_DEBUG << "[StBTofINLCorr] ... done" << endm;
161 }
162 
163 void StBTofINLCorr::Reset() {
164 
165  for(Int_t i=0;i<mNTray;i++) {
166  for(Int_t j=0;j<mNTDIGOnTray;j++) {
167  mTdigOnTray[i][j] = 0;
168  }
169  }
170  for(Int_t i=0;i<mNTDIGOnTray;i++) {
171  mTdigOnEastVpd[i] = 0;
172  mTdigOnWestVpd[i] = 0;
173  }
174 
175  for(Int_t i=0;i<mNTDIGMAX;i++) {
176  mBoardId[i] = 0;
177  for(int j=0;j<mNChanOnTDIG;j++) {
178  for(int k=0;k<mNChanMAX;k++) {
179  mINLCorr[i][j][k] = 0;
180  }
181  }
182  }
183  for(Int_t i=0;i<mNBoardIdMAX;i++) {
184  mBoardId2Index[i] = -1;
185  }
186 
187  mNValidBoards = 0;
188 }
189 
190 float StBTofINLCorr::getTdigINLCorr(int tdigId, int tdcChannel, int bin) {
191  int index = mBoardId2Index[tdigId]; // index in the inl array
192  if (tdcChannel<0||tdcChannel>23) {
193  LOG_WARN << "TDC Channel (" << tdcChannel << ") out of range. Forcing default values" << endm;
194  index = -999;
195  }
196  if(index<0||index>=mNValidBoards) {
197  LOG_WARN << " Missing INL table for TDIG-Id = " << tdigId << endm;
198  LOG_WARN << " Using the table from boardId # " << mBoardId[0] << " tdcchan # 0 " << endm;
199 // return 0.0;
200  return mINLCorr[0][0][bin]/100.;
201  } else {
202  return mINLCorr[index][tdcChannel][bin]/100.;
203  }
204 }
205 
206 float StBTofINLCorr::getTrayINLCorr(int trayId, int globalTdcChan, int bin) {
207  if(trayId<=0 || trayId>mNTray) return 0.0; // trayId 1-120
208  if(globalTdcChan<0 || globalTdcChan>=mNGLOBALCHANMAX) return 0.0;
209  if(bin<0 || bin>=mNChanMAX) return 0.0;
210 
211  int iTdig = globalTdcChan/mNChanOnTDIG; // 0-7
212  int boardId = mTdigOnTray[trayId-1][iTdig];
213  if(boardId<=0 || boardId>mNBoardIdMAX) return 0.0;
214 
215  int index = mBoardId2Index[boardId]; // index in the inl array
216  int tdcChan = globalTdcChan % mNChanOnTDIG; // 0-23
217  if(index<0||index>=mNValidBoards) {
218  LOG_WARN << " Missing INL table for boardId = " << boardId << " on tray " << trayId << endm;
219  LOG_WARN << " Using the table from boardId # " << mBoardId[0] << " tdcchan # 0 " << endm;
220 // return 0.0;
221  return mINLCorr[0][0][bin]/100.;
222  } else {
223  return mINLCorr[index][tdcChan][bin]/100.;
224  }
225 }
226 
227 float StBTofINLCorr::getVpdINLCorr(StBeamDirection eastwest, int globalTdcChan, int bin) {
228  if(eastwest!=east && eastwest!=west) return 0.0;
229  if(globalTdcChan<0 || globalTdcChan>=mNGLOBALCHANMAX) return 0.0;
230  if(bin<0 || bin>=mNChanMAX) return 0.0;
231  int iTdig = globalTdcChan/mNChanOnTDIG; // 0-7
232 
233  int boardId = -1;
234  if(eastwest==east) { // east pvpd
235  boardId = mTdigOnEastVpd[iTdig];
236  } else if(eastwest==west) { // west pvpd
237  boardId = mTdigOnWestVpd[iTdig];
238  }
239  if(boardId<=0 || boardId>mNBoardIdMAX) return 0.0;
240 
241  int index = mBoardId2Index[boardId]; // index in the inl array
242  int tdcChan = globalTdcChan % mNChanOnTDIG; // 0-23
243  if(index<0||index>=mNValidBoards) {
244  LOG_WARN << " Missing INL table for boardId = " << boardId << " on vpd " << eastwest << endm;
245  LOG_WARN << " Using the table from boardId # " << mBoardId[0] << " tdcchan # 0 " << endm;
246 // return 0.0;
247  return mINLCorr[0][0][bin]/100.;
248  } else {
249  return mINLCorr[index][tdcChan][bin]/100.;
250  }
251 }
float getTdigINLCorr(int tdigId, int tdcChannel, int bin)
direct access to INL correction table for any TDIG-Id
float getTrayINLCorr(int trayId, int globalTdcChan, int bin)
To get the INL correction tables for trays.
void initFromDbase(StMaker *maker)
Initial function to access the data base and retrieve INL tables.
float getVpdINLCorr(StBeamDirection eastwest, int globalTdcChan, int bin)
To get the INL correction tables for vpds.
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362