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 #include <iostream>
00028 #include "tables/St_tofTDIGOnTray_Table.h"
00029 #include "tables/St_tofINLCorr_Table.h"
00030 #include "StMessMgr.h"
00031 #include "StMaker.h"
00032 #include "StTofINLCorr.h"
00033
00034 StTofINLCorr::StTofINLCorr()
00035 {
00036 Reset();
00037 }
00038
00039 StTofINLCorr::~StTofINLCorr()
00040 {
00041 Reset();
00042 }
00043
00044 void StTofINLCorr::init() {
00045 Reset();
00046 }
00047
00048 void StTofINLCorr::init(StMaker *maker) {
00049 initFromDbase(maker);
00050 }
00051
00052 void StTofINLCorr::initFromDbase(StMaker *maker) {
00053
00054 gMessMgr->Info("StTofINLCorr -- rertieving the INL correction table","OS");
00056
00057
00059
00060 TDataSet *mDbTOFDataSet = maker->GetDataBase("Calibrations/tof");
00061 if(!mDbTOFDataSet) {
00062 gMessMgr->Error("unable to access Calibrations TOF parameters","OS");
00063
00064 return;
00065 }
00066
00067 St_tofTDIGOnTray* tofTDIGOnTray = static_cast<St_tofTDIGOnTray*>(mDbTOFDataSet->Find("tofTDIGOnTray"));
00068 if(!tofTDIGOnTray) {
00069 gMessMgr->Error("unable to get tof INL correction parameters","OS");
00070
00071 return;
00072 }
00073 tofTDIGOnTray_st* tdigOnTray = static_cast<tofTDIGOnTray_st*>(tofTDIGOnTray->GetArray());
00074
00075 Int_t numRows = tofTDIGOnTray->GetNRows();
00076 LOG_INFO << "number of rows = " << numRows << endm;
00077 for (Int_t i=0;i<mNValidTrays+2;i++) {
00078 Int_t trayId = (Int_t)tdigOnTray[i].trayId;
00079
00080 if(trayId==mEastVpdTrayId) {
00081 for(Int_t j=0;j<mNTDIGOnTray;j++)
00082 mTdigOnEastVpd[j] = (Int_t)tdigOnTray[i].tdigId[j];
00083 } else if (trayId==mWestVpdTrayId) {
00084 for(Int_t j=0;j<mNTDIGOnTray;j++)
00085 mTdigOnWestVpd[j] = (Int_t)tdigOnTray[i].tdigId[j];
00086 } else if (trayId>0 && trayId<= mNTray) {
00087 for(Int_t j=0;j<mNTDIGOnTray;j++)
00088 mTdigOnTray[trayId-1][j] = (Int_t)tdigOnTray[i].tdigId[j];
00089 }
00090
00091 if(maker->Debug()) {
00092 cout << " tray id=" << trayId;
00093 for(int j=0;j<mNTDIGOnTray;j++) {
00094 cout << " " << tdigOnTray[i].tdigId[j];
00095 }
00096 cout << endl;
00097 }
00098
00099 }
00100
00101 St_tofINLCorr* tofINLCorr = static_cast<St_tofINLCorr*>(mDbTOFDataSet->Find("tofINLCorr"));
00102 if(!tofINLCorr) {
00103 gMessMgr->Error("unable to get tof INL correction parameters","OS");
00104
00105 return;
00106 }
00107 tofINLCorr_st* inlcorr = static_cast<tofINLCorr_st*>(tofINLCorr->GetArray());
00108
00109 numRows = tofINLCorr->GetNRows();
00110 if(numRows>mNTDIGMAX*mNChanOnTDIG) {
00111 { LOG_INFO << " !!! # of Rows in tofINLCorr table exceed the array limit in this function !!! Trancated !!! " << endm; }
00112 }
00113 Int_t NTdig = 0;
00114 Int_t tdigId_old = 0;
00115 for (Int_t i=0;i<numRows;i++) {
00116 if(NTdig>mNTDIGMAX) {
00117 { LOG_INFO << " !!! # of boards read-in exceeds the array limit in this function !!! Trancated !!! " << endm; }
00118 NTdig = mNTDIGMAX;
00119 break;
00120 }
00121
00122 int tdigId = (Int_t)(inlcorr[i].tdigId);
00123 int tdcChanId = (Int_t)(inlcorr[i].tdcChanId);
00124 if(tdigId!=tdigId_old) {
00125 mBoardId[NTdig] = tdigId;
00126 NTdig++;
00127 }
00128
00129 tdigId_old = tdigId;
00130
00131 if(maker->Debug()) { LOG_INFO << " tdigId=" << tdigId << " tdcChanId=" << tdcChanId << endm; }
00132 for(Int_t j=0;j<mNChanMAX;j++) {
00133 float corr = (Float_t)(inlcorr[i].INLCorr[j]);
00134 mINLCorr[NTdig-1][tdcChanId][j] = corr;
00135
00136 if(maker->Debug()&&(j%200==0)) {
00137 cout << " " << corr;
00138 }
00139 }
00140 if(maker->Debug()) cout << endl;
00141 }
00142
00143 LOG_INFO << " Total # of boards read in : " << NTdig << endm;
00144
00145
00146 for(Int_t i=0;i<NTdig;i++) {
00147 int boardId = mBoardId[i];
00148 if(boardId>0 && boardId<=mNBoardIdMAX) {
00149 mBoardId2Index[boardId] = i;
00150 } else {
00151 { LOG_INFO << " Warning! boardId " << boardId << " out of range!" << endm; }
00152 }
00153 }
00154
00155
00156 }
00157
00158 void StTofINLCorr::Reset() {
00159
00160 for(Int_t i=0;i<mNTray;i++) {
00161 for(Int_t j=0;j<mNTDIGOnTray;j++) {
00162 mTdigOnTray[i][j] = 0;
00163 }
00164 }
00165 for(Int_t i=0;i<mNTDIGOnTray;i++) {
00166 mTdigOnEastVpd[i] = 0;
00167 mTdigOnWestVpd[i] = 0;
00168 }
00169
00170 for(Int_t i=0;i<mNTDIGMAX;i++) {
00171 mBoardId[i] = 0;
00172 for(int j=0;j<mNChanOnTDIG;j++) {
00173 for(int k=0;k<mNChanMAX;k++) {
00174 mINLCorr[i][j][k] = 0.0;
00175 }
00176 }
00177 }
00178 for(Int_t i=0;i<mNBoardIdMAX;i++) {
00179 mBoardId2Index[i] = -1;
00180 }
00181
00182 mNValidTrays = 0;
00183 }
00184
00185 float StTofINLCorr::getTrayINLCorr(int trayId, int globalTdcChan, int bin) {
00186 if(trayId<=0 || trayId>mNTray) return 0.0;
00187 if(globalTdcChan<0 || globalTdcChan>=mNGLOBALCHANMAX) return 0.0;
00188 if(bin<0 || bin>=mNChanMAX) return 0.0;
00189
00190 int iTdig = globalTdcChan/mNChanOnTDIG;
00191 int boardId = mTdigOnTray[trayId-1][iTdig];
00192 if(boardId<=0 || boardId>mNBoardIdMAX) return 0.0;
00193
00194 int index = mBoardId2Index[boardId];
00195 int tdcChan = globalTdcChan % mNChanOnTDIG;
00196 return mINLCorr[index][tdcChan][bin];
00197 }
00198
00199 float StTofINLCorr::getVpdINLCorr(int ewId, int globalTdcChan, int bin) {
00200 if(ewId!=1 && ewId!=2) return 0.0;
00201 if(globalTdcChan<0 || globalTdcChan>=mNGLOBALCHANMAX) return 0.0;
00202 if(bin<0 || bin>=mNChanMAX) return 0.0;
00203 int iTdig = globalTdcChan/mNChanOnTDIG;
00204
00205 int boardId;
00206 if(ewId==2) {
00207 boardId = mTdigOnEastVpd[iTdig];
00208 } else {
00209 boardId = mTdigOnWestVpd[iTdig];
00210 }
00211 if(boardId<=0 || boardId>mNBoardIdMAX) return 0.0;
00212
00213 int index = mBoardId2Index[boardId];
00214 int tdcChan = globalTdcChan % mNChanOnTDIG;
00215 return mINLCorr[index][tdcChan][bin];
00216 }