StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTofINLCorr.cxx
1 /*******************************************************************
2  *
3  * $Id: StTofINLCorr.cxx,v 1.6 2012/12/17 22:57:20 geurts Exp $
4  *
5  * Author: Xin Dong
6  *****************************************************************
7  *
8  * Description: INL correction for all TDIG board channels
9  *
10  *****************************************************************
11  *
12  * $Log: StTofINLCorr.cxx,v $
13  * Revision 1.6 2012/12/17 22:57:20 geurts
14  * bugfix (tickets #2456/#2457)
15  *
16  * Revision 1.5 2012/12/14 06:35:59 geurts
17  * Changed global database calls to direct table access and/or removed deprecated database access code.
18  *
19  * Revision 1.4 2008/08/05 19:36:48 dongx
20  * fixed a bug of empty lines in log file under no-debug mode
21  * LOGGER print corrected with an if statement
22  *
23  * Revision 1.3 2008/03/27 00:15:38 dongx
24  * Update for Run8 finished.
25  *
26  * Revision 1.2 2007/11/22 00:04:13 dongx
27  * - update for tof8++
28  * - added ValidTrays() function
29  *
30  *
31  *
32  *******************************************************************/
33 #include <iostream>
34 #include "tables/St_tofTDIGOnTray_Table.h"
35 #include "tables/St_tofINLCorr_Table.h"
36 #include "StMessMgr.h"
37 #include "StMaker.h"
38 #include "StTofINLCorr.h"
39 
40 StTofINLCorr::StTofINLCorr()
41 {
42  Reset();
43 }
44 
45 StTofINLCorr::~StTofINLCorr()
46 {
47  Reset();
48 }
49 
50 void StTofINLCorr::init() {
51  Reset();
52 }
53 
54 void StTofINLCorr::init(StMaker *maker) {
55  initFromDbase(maker);
56 }
57 
58 void StTofINLCorr::initFromDbase(StMaker *maker) {
59 
60  gMessMgr->Info("StTofINLCorr -- rertieving the INL correction table","OS");
62  // Load configuration parameters from dbase
63  // need "[shell] setenv Calibrations_tof reconV0"
65 
66  TDataSet *mDbTOFDataSet = maker->GetDataBase("Calibrations/tof/tofTDIGOnTray");
67  if(!mDbTOFDataSet) {
68  gMessMgr->Error("unable to access TOF tofTDIGonTray table","OS");
69  // assert(mDbTOFDataSet);
70  return; // kStErr;
71  }
72 
73  St_tofTDIGOnTray* tofTDIGOnTray = static_cast<St_tofTDIGOnTray*>(mDbTOFDataSet->Find("tofTDIGOnTray"));
74  if(!tofTDIGOnTray) {
75  gMessMgr->Error("unable to get tof INL correction parameters","OS");
76  // assert(tofTDIGOnTray);
77  return; // kStErr;
78  }
79  tofTDIGOnTray_st* tdigOnTray = static_cast<tofTDIGOnTray_st*>(tofTDIGOnTray->GetArray());
80 
81  Int_t numRows = tofTDIGOnTray->GetNRows();
82  LOG_INFO << "number of rows = " << numRows << endm;
83  for (Int_t i=0;i<mNValidTrays+2;i++) {
84  Int_t trayId = (Int_t)tdigOnTray[i].trayId;
85 
86  if(trayId==mEastVpdTrayId) { // east vpd
87  for(Int_t j=0;j<mNTDIGOnTray;j++)
88  mTdigOnEastVpd[j] = (Int_t)tdigOnTray[i].tdigId[j];
89  } else if (trayId==mWestVpdTrayId) { // west vpd
90  for(Int_t j=0;j<mNTDIGOnTray;j++)
91  mTdigOnWestVpd[j] = (Int_t)tdigOnTray[i].tdigId[j];
92  } else if (trayId>0 && trayId<= mNTray) { // barrel Tray
93  for(Int_t j=0;j<mNTDIGOnTray;j++)
94  mTdigOnTray[trayId-1][j] = (Int_t)tdigOnTray[i].tdigId[j];
95  }
96 
97  if(maker->Debug()) {
98  cout << " tray id=" << trayId;
99  for(int j=0;j<mNTDIGOnTray;j++) {
100  cout << " " << tdigOnTray[i].tdigId[j];
101  }
102  cout << endl;
103  }
104 
105  }
106 
107  mDbTOFDataSet = maker->GetDataBase("Calibrations/tof/tofINLCorr");
108  if(!mDbTOFDataSet) {
109  gMessMgr->Error("unable to access TOF tofINLCorr table","OS");
110  // assert(mDbTOFDataSet);
111  return; // kStErr;
112  }
113  St_tofINLCorr* tofINLCorr = static_cast<St_tofINLCorr*>(mDbTOFDataSet->Find("tofINLCorr"));
114  if(!tofINLCorr) {
115  gMessMgr->Error("unable to get tof INL correction parameters","OS");
116  // assert(tofINLCorr);
117  return; // kStErr;
118  }
119  tofINLCorr_st* inlcorr = static_cast<tofINLCorr_st*>(tofINLCorr->GetArray());
120 
121  numRows = tofINLCorr->GetNRows();
122  if(numRows>mNTDIGMAX*mNChanOnTDIG) {
123  { LOG_INFO << " !!! # of Rows in tofINLCorr table exceed the array limit in this function !!! Trancated !!! " << endm; }
124  }
125  Int_t NTdig = 0;
126  Int_t tdigId_old = 0;
127  for (Int_t i=0;i<numRows;i++) {
128  if(NTdig>mNTDIGMAX) {
129  { LOG_INFO << " !!! # of boards read-in exceeds the array limit in this function !!! Trancated !!! " << endm; }
130  NTdig = mNTDIGMAX;
131  break;
132  }
133 
134  int tdigId = (Int_t)(inlcorr[i].tdigId);
135  int tdcChanId = (Int_t)(inlcorr[i].tdcChanId);
136  if(tdigId!=tdigId_old) {
137  mBoardId[NTdig] = tdigId;
138  NTdig++;
139  }
140 
141  tdigId_old = tdigId;
142 
143  if(maker->Debug()) { LOG_INFO << " tdigId=" << tdigId << " tdcChanId=" << tdcChanId << endm; }
144  for(Int_t j=0;j<mNChanMAX;j++) {
145  float corr = (Float_t)(inlcorr[i].INLCorr[j]);
146  mINLCorr[NTdig-1][tdcChanId][j] = corr;
147 
148  if(maker->Debug()&&(j%200==0)) {
149  cout << " " << corr;
150  }
151  }
152  if(maker->Debug()) cout << endl;
153  }
154 
155  LOG_INFO << " Total # of boards read in : " << NTdig << endm;
156 
157  // re-organize
158  for(Int_t i=0;i<NTdig;i++) {
159  int boardId = mBoardId[i];
160  if(boardId>0 && boardId<=mNBoardIdMAX) {
161  mBoardId2Index[boardId] = i;
162  } else {
163  { LOG_INFO << " Warning! boardId " << boardId << " out of range!" << endm; }
164  }
165  }
166 
167 
168 }
169 
170 void StTofINLCorr::Reset() {
171 
172  for(Int_t i=0;i<mNTray;i++) {
173  for(Int_t j=0;j<mNTDIGOnTray;j++) {
174  mTdigOnTray[i][j] = 0;
175  }
176  }
177  for(Int_t i=0;i<mNTDIGOnTray;i++) {
178  mTdigOnEastVpd[i] = 0;
179  mTdigOnWestVpd[i] = 0;
180  }
181 
182  for(Int_t i=0;i<mNTDIGMAX;i++) {
183  mBoardId[i] = 0;
184  for(int j=0;j<mNChanOnTDIG;j++) {
185  for(int k=0;k<mNChanMAX;k++) {
186  mINLCorr[i][j][k] = 0.0;
187  }
188  }
189  }
190  for(Int_t i=0;i<mNBoardIdMAX;i++) {
191  mBoardId2Index[i] = -1;
192  }
193 
194  mNValidTrays = 0;
195 }
196 
197 float StTofINLCorr::getTrayINLCorr(int trayId, int globalTdcChan, int bin) {
198  if(trayId<=0 || trayId>mNTray) return 0.0; // trayId 1-120
199  if(globalTdcChan<0 || globalTdcChan>=mNGLOBALCHANMAX) return 0.0;
200  if(bin<0 || bin>=mNChanMAX) return 0.0;
201 
202  int iTdig = globalTdcChan/mNChanOnTDIG; // 0-7
203  int boardId = mTdigOnTray[trayId-1][iTdig];
204  if(boardId<=0 || boardId>mNBoardIdMAX) return 0.0;
205 
206  int index = mBoardId2Index[boardId]; // index in the inl array
207  int tdcChan = globalTdcChan % mNChanOnTDIG; // 0-23
208  return mINLCorr[index][tdcChan][bin];
209 }
210 
211 float StTofINLCorr::getVpdINLCorr(int ewId, int globalTdcChan, int bin) {
212  if(ewId!=1 && ewId!=2) return 0.0;
213  if(globalTdcChan<0 || globalTdcChan>=mNGLOBALCHANMAX) return 0.0;
214  if(bin<0 || bin>=mNChanMAX) return 0.0;
215  int iTdig = globalTdcChan/mNChanOnTDIG; // 0-7
216 
217  int boardId;
218  if(ewId==2) { // east pvpd
219  boardId = mTdigOnEastVpd[iTdig];
220  } else { // west pvpd
221  boardId = mTdigOnWestVpd[iTdig];
222  }
223  if(boardId<=0 || boardId>mNBoardIdMAX) return 0.0;
224 
225  int index = mBoardId2Index[boardId]; // index in the inl array
226  int tdcChan = globalTdcChan % mNChanOnTDIG; // 0-23
227  return mINLCorr[index][tdcChan][bin];
228 }
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362