50 #include "tables/St_tofTDIGOnTray_Table.h"
51 #include "tables/St_tofINLSCorr_Table.h"
52 #include "StMessMgr.h"
54 #include "StBTofINLCorr.h"
56 StBTofINLCorr::StBTofINLCorr()
61 StBTofINLCorr::~StBTofINLCorr()
66 void StBTofINLCorr::init() {
70 void StBTofINLCorr::init(
StMaker *maker) {
77 LOG_INFO <<
"[StBTofINLCorr] retrieving TDIGOnTray and INL correction tables ..." << endm;
82 TDataSet *mDbTOFDataSet = maker->GetDataBase(
"Calibrations/tof/tofTDIGOnTray");
83 St_tofTDIGOnTray* tofTDIGOnTray =
static_cast<St_tofTDIGOnTray*
>(mDbTOFDataSet->
Find(
"tofTDIGOnTray"));
85 LOG_ERROR <<
"unable to get tofTDIGOnTray table" << endm;
88 tofTDIGOnTray_st* tdigOnTray =
static_cast<tofTDIGOnTray_st*
>(tofTDIGOnTray->GetArray());
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;
94 if(trayId==mEastVpdTrayId) {
95 for(Int_t j=0;j<mNTDIGOnTray;j++)
96 mTdigOnEastVpd[j] = (Int_t)tdigOnTray[i].tdigId[j];
97 }
else if (trayId==mWestVpdTrayId) {
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) {
101 for(Int_t j=0;j<mNTDIGOnTray;j++)
102 mTdigOnTray[trayId-1][j] = (Int_t)tdigOnTray[i].tdigId[j];
106 mDbTOFDataSet = maker->GetDataBase(
"Calibrations/tof/tofINLSCorr");
107 St_tofINLSCorr* tofINLCorr =
static_cast<St_tofINLSCorr*
>(mDbTOFDataSet->
Find(
"tofINLSCorr"));
109 LOG_ERROR <<
"unable to get tofINLSCorr table" << endm;
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; }
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; }
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;
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;
140 if(maker->Debug()&&(j%200==0)) {
141 LOG_DEBUG <<
" " << corr;
144 if(maker->Debug()) { LOG_DEBUG << endm; }
147 LOG_INFO <<
"[StBTofINLCorr] Total number of boards: " << NTdig << endm;
148 mNValidBoards = NTdig;
151 for(Int_t i=0;i<NTdig;i++) {
152 int boardId = mBoardId[i];
153 if(boardId>0 && boardId<=mNBoardIdMAX) {
154 mBoardId2Index[boardId] = i;
156 { LOG_WARN<<
" Warning! boardId " << boardId <<
" out of range!" << endm; }
160 LOG_DEBUG <<
"[StBTofINLCorr] ... done" << endm;
163 void StBTofINLCorr::Reset() {
165 for(Int_t i=0;i<mNTray;i++) {
166 for(Int_t j=0;j<mNTDIGOnTray;j++) {
167 mTdigOnTray[i][j] = 0;
170 for(Int_t i=0;i<mNTDIGOnTray;i++) {
171 mTdigOnEastVpd[i] = 0;
172 mTdigOnWestVpd[i] = 0;
175 for(Int_t i=0;i<mNTDIGMAX;i++) {
177 for(
int j=0;j<mNChanOnTDIG;j++) {
178 for(
int k=0;k<mNChanMAX;k++) {
179 mINLCorr[i][j][k] = 0;
183 for(Int_t i=0;i<mNBoardIdMAX;i++) {
184 mBoardId2Index[i] = -1;
191 int index = mBoardId2Index[tdigId];
192 if (tdcChannel<0||tdcChannel>23) {
193 LOG_WARN <<
"TDC Channel (" << tdcChannel <<
") out of range. Forcing default values" << endm;
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;
200 return mINLCorr[0][0][bin]/100.;
202 return mINLCorr[index][tdcChannel][bin]/100.;
207 if(trayId<=0 || trayId>mNTray)
return 0.0;
208 if(globalTdcChan<0 || globalTdcChan>=mNGLOBALCHANMAX)
return 0.0;
209 if(bin<0 || bin>=mNChanMAX)
return 0.0;
211 int iTdig = globalTdcChan/mNChanOnTDIG;
212 int boardId = mTdigOnTray[trayId-1][iTdig];
213 if(boardId<=0 || boardId>mNBoardIdMAX)
return 0.0;
215 int index = mBoardId2Index[boardId];
216 int tdcChan = globalTdcChan % mNChanOnTDIG;
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;
221 return mINLCorr[0][0][bin]/100.;
223 return mINLCorr[index][tdcChan][bin]/100.;
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;
235 boardId = mTdigOnEastVpd[iTdig];
236 }
else if(eastwest==west) {
237 boardId = mTdigOnWestVpd[iTdig];
239 if(boardId<=0 || boardId>mNBoardIdMAX)
return 0.0;
241 int index = mBoardId2Index[boardId];
242 int tdcChan = globalTdcChan % mNChanOnTDIG;
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;
247 return mINLCorr[0][0][bin]/100.;
249 return mINLCorr[index][tdcChan][bin]/100.;
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