00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <iostream>
00044 #include "tables/St_tofTDIGOnTray_Table.h"
00045 #include "tables/St_tofINLSCorr_Table.h"
00046 #include "StMessMgr.h"
00047 #include "StMaker.h"
00048 #include "StBTofINLCorr.h"
00049
00050 StBTofINLCorr::StBTofINLCorr()
00051 {
00052 Reset();
00053 }
00054
00055 StBTofINLCorr::~StBTofINLCorr()
00056 {
00057 Reset();
00058 }
00059
00060 void StBTofINLCorr::init() {
00061 Reset();
00062 }
00063
00064 void StBTofINLCorr::init(StMaker *maker) {
00065 Reset();
00066 initFromDbase(maker);
00067 }
00068
00069 void StBTofINLCorr::initFromDbase(StMaker *maker) {
00070
00071 LOG_INFO << "[StBTofINLCorr] retrieving TDIGOnTray and INL correction tables ..." << endm;
00073
00075
00076
00077
00078
00079
00080
00081
00082 TDataSet *mDbTOFDataSet = maker->GetDataBase("Calibrations/tof/tofTDIGOnTray");
00083 St_tofTDIGOnTray* tofTDIGOnTray = static_cast<St_tofTDIGOnTray*>(mDbTOFDataSet->Find("tofTDIGOnTray"));
00084 if(!tofTDIGOnTray) {
00085 LOG_ERROR << "unable to get tofTDIGOnTray table" << endm;
00086 return;
00087 }
00088 tofTDIGOnTray_st* tdigOnTray = static_cast<tofTDIGOnTray_st*>(tofTDIGOnTray->GetArray());
00089
00090 Int_t numRows = tofTDIGOnTray->GetNRows();
00091 for (Int_t i=0;i<mNTray+2;i++) {
00092 Int_t trayId = (Int_t)tdigOnTray[i].trayId;
00093
00094 if(trayId==mEastVpdTrayId) {
00095 for(Int_t j=0;j<mNTDIGOnTray;j++)
00096 mTdigOnEastVpd[j] = (Int_t)tdigOnTray[i].tdigId[j];
00097 } else if (trayId==mWestVpdTrayId) {
00098 for(Int_t j=0;j<mNTDIGOnTray;j++)
00099 mTdigOnWestVpd[j] = (Int_t)tdigOnTray[i].tdigId[j];
00100 } else if (trayId>0 && trayId<= mNTray) {
00101 for(Int_t j=0;j<mNTDIGOnTray;j++)
00102 mTdigOnTray[trayId-1][j] = (Int_t)tdigOnTray[i].tdigId[j];
00103 }
00104 }
00105
00106 mDbTOFDataSet = maker->GetDataBase("Calibrations/tof/tofINLSCorr");
00107 St_tofINLSCorr* tofINLCorr = static_cast<St_tofINLSCorr*>(mDbTOFDataSet->Find("tofINLSCorr"));
00108 if(!tofINLCorr) {
00109 LOG_ERROR << "unable to get tofINLSCorr table" << endm;
00110 return;
00111 }
00112 tofINLSCorr_st* inlcorr = static_cast<tofINLSCorr_st*>(tofINLCorr->GetArray());
00113 numRows = tofINLCorr->GetNRows();
00114 if(numRows>mNTDIGMAX*mNChanOnTDIG) {
00115 { LOG_WARN << "number of rows in tofINLSCorr table exceed the array limit in this function! Entries truncated !!!" << endm; }
00116 }
00117 Int_t NTdig = 0;
00118 Int_t tdigId_old = 0;
00119 for (Int_t i=0;i<numRows;i++) {
00120 if(NTdig>=mNTDIGMAX) {
00121 { LOG_WARN << " number of boards read-in exceeds the array limit in this function! NTDIG Truncated !!! " << endm; }
00122 NTdig = mNTDIGMAX;
00123 break;
00124 }
00125
00126 int tdigId = (Int_t)(inlcorr[i].tdigId);
00127 int tdcChanId = (Int_t)(inlcorr[i].tdcChanId);
00128 if(tdigId!=tdigId_old) {
00129 mBoardId[NTdig] = tdigId;
00130 NTdig++;
00131 }
00132
00133 tdigId_old = tdigId;
00134
00135 LOG_DEBUG << " tdigId=" << tdigId << " tdcChanId=" << tdcChanId << endm;
00136 for(Int_t j=0;j<mNChanMAX;j++) {
00137 Short_t corr = (Short_t)(inlcorr[i].INLCorr[j]);
00138 mINLCorr[NTdig-1][tdcChanId][j] = corr;
00139
00140 if(maker->Debug()&&(j%200==0)) {
00141 LOG_DEBUG << " " << corr;
00142 }
00143 }
00144 if(maker->Debug()) { LOG_DEBUG << endm; }
00145 }
00146
00147 LOG_INFO << "[StBTofINLCorr] Total number of boards: " << NTdig << endm;
00148 mNValidBoards = NTdig;
00149
00150
00151 for(Int_t i=0;i<NTdig;i++) {
00152 int boardId = mBoardId[i];
00153 if(boardId>0 && boardId<=mNBoardIdMAX) {
00154 mBoardId2Index[boardId] = i;
00155 } else {
00156 { LOG_WARN<< " Warning! boardId " << boardId << " out of range!" << endm; }
00157 }
00158 }
00159
00160 LOG_DEBUG << "[StBTofINLCorr] ... done" << endm;
00161 }
00162
00163 void StBTofINLCorr::Reset() {
00164
00165 for(Int_t i=0;i<mNTray;i++) {
00166 for(Int_t j=0;j<mNTDIGOnTray;j++) {
00167 mTdigOnTray[i][j] = 0;
00168 }
00169 }
00170 for(Int_t i=0;i<mNTDIGOnTray;i++) {
00171 mTdigOnEastVpd[i] = 0;
00172 mTdigOnWestVpd[i] = 0;
00173 }
00174
00175 for(Int_t i=0;i<mNTDIGMAX;i++) {
00176 mBoardId[i] = 0;
00177 for(int j=0;j<mNChanOnTDIG;j++) {
00178 for(int k=0;k<mNChanMAX;k++) {
00179 mINLCorr[i][j][k] = 0;
00180 }
00181 }
00182 }
00183 for(Int_t i=0;i<mNBoardIdMAX;i++) {
00184 mBoardId2Index[i] = -1;
00185 }
00186
00187 mNValidBoards = 0;
00188 }
00189
00190 float StBTofINLCorr::getTdigINLCorr(int tdigId, int tdcChannel, int bin) {
00191 int index = mBoardId2Index[tdigId];
00192 if (tdcChannel<0||tdcChannel>23) {
00193 LOG_WARN << "TDC Channel (" << tdcChannel << ") out of range. Forcing default values" << endm;
00194 index = -999;
00195 }
00196 if(index<0||index>=mNValidBoards) {
00197 LOG_WARN << " Missing INL table for TDIG-Id = " << tdigId << endm;
00198 LOG_WARN << " Using the table from boardId # " << mBoardId[0] << " tdcchan # 0 " << endm;
00199
00200 return mINLCorr[0][0][bin]/100.;
00201 } else {
00202 return mINLCorr[index][tdcChannel][bin]/100.;
00203 }
00204 }
00205
00206 float StBTofINLCorr::getTrayINLCorr(int trayId, int globalTdcChan, int bin) {
00207 if(trayId<=0 || trayId>mNTray) return 0.0;
00208 if(globalTdcChan<0 || globalTdcChan>=mNGLOBALCHANMAX) return 0.0;
00209 if(bin<0 || bin>=mNChanMAX) return 0.0;
00210
00211 int iTdig = globalTdcChan/mNChanOnTDIG;
00212 int boardId = mTdigOnTray[trayId-1][iTdig];
00213 if(boardId<=0 || boardId>mNBoardIdMAX) return 0.0;
00214
00215 int index = mBoardId2Index[boardId];
00216 int tdcChan = globalTdcChan % mNChanOnTDIG;
00217 if(index<0||index>=mNValidBoards) {
00218 LOG_WARN << " Missing INL table for boardId = " << boardId << " on tray " << trayId << endm;
00219 LOG_WARN << " Using the table from boardId # " << mBoardId[0] << " tdcchan # 0 " << endm;
00220
00221 return mINLCorr[0][0][bin]/100.;
00222 } else {
00223 return mINLCorr[index][tdcChan][bin]/100.;
00224 }
00225 }
00226
00227 float StBTofINLCorr::getVpdINLCorr(StBeamDirection eastwest, int globalTdcChan, int bin) {
00228 if(eastwest!=east && eastwest!=west) return 0.0;
00229 if(globalTdcChan<0 || globalTdcChan>=mNGLOBALCHANMAX) return 0.0;
00230 if(bin<0 || bin>=mNChanMAX) return 0.0;
00231 int iTdig = globalTdcChan/mNChanOnTDIG;
00232
00233 int boardId = -1;
00234 if(eastwest==east) {
00235 boardId = mTdigOnEastVpd[iTdig];
00236 } else if(eastwest==west) {
00237 boardId = mTdigOnWestVpd[iTdig];
00238 }
00239 if(boardId<=0 || boardId>mNBoardIdMAX) return 0.0;
00240
00241 int index = mBoardId2Index[boardId];
00242 int tdcChan = globalTdcChan % mNChanOnTDIG;
00243 if(index<0||index>=mNValidBoards) {
00244 LOG_WARN << " Missing INL table for boardId = " << boardId << " on vpd " << eastwest << endm;
00245 LOG_WARN << " Using the table from boardId # " << mBoardId[0] << " tdcchan # 0 " << endm;
00246
00247 return mINLCorr[0][0][bin]/100.;
00248 } else {
00249 return mINLCorr[index][tdcChan][bin]/100.;
00250 }
00251 }