StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFmsDbMaker.cxx
1  /***************************************************************************
2  * $Id: StFmsDbMaker.cxx,v 1.40 2019/10/31 13:51:11 akio Exp $
3  * \author: akio ogawa
4  ***************************************************************************
5  *
6  * Description: This maker is the interface between FMS and the STAR database
7  *
8  ***************************************************************************
9  *
10  * $Log: StFmsDbMaker.cxx,v $
11  * Revision 1.40 2019/10/31 13:51:11 akio
12  * adding Attr for FmsGainCorrB table flavors
13  *
14  * Revision 1.39 2019/10/30 18:49:33 akio
15  * Adding FmsGainCorrection flavor control
16  *
17  * Revision 1.38 2019/01/04 18:19:56 akio
18  * A bug fix which caused crash when fmsBitShiftGain/B was empty.
19  *
20  * Revision 1.37 2018/05/22 20:04:45 akio
21  * fix not dumping last detector Id to dump file
22  *
23  * Revision 1.36 2018/03/09 21:37:06 smirnovd
24  * Remove inline keyword from source file
25  *
26  * Revision 1.35 2018/03/01 15:58:34 akio
27  * fixed a typo
28  *
29  * Revision 1.34 2018/02/12 20:15:06 akio
30  * fixing typo
31  *
32  * Revision 1.33 2018/02/07 14:45:14 akio
33  * Update for faster DB tables
34  *
35  * Revision 1.32 2017/11/02 13:09:25 akio
36  * Adding getCorrectedAdc and fix a memory leak
37  *
38  * Revision 1.31 2017/10/10 15:34:00 akio
39  * Fix a crashing bug
40  *
41  * Revision 1.30 2017/10/06 15:06:20 akio
42  * fix a crash
43  *
44  * Revision 1.29 2017/09/28 17:00:48 akio
45  * adding BitShiftGain
46  *
47  * Revision 1.28 2017/09/15 15:43:54 akio
48  * Adding readGainCorrFromText()
49  *
50  * Revision 1.27 2017/08/14 16:08:55 smirnovd
51  * StFmsDbMaker: Declare member functions const
52  *
53  * These methods don't change the object by design
54  *
55  * Revision 1.26 2017/05/03 17:14:01 akio
56  * Adding Sigma and Valley for Fps/Fpost
57  *
58  * Revision 1.25 2017/03/24 16:39:09 akio
59  * adding run17 fms positions
60  *
61  * Revision 1.24 2017/03/18 16:23:15 akio
62  * fixes nslat functions
63  *
64  * Revision 1.23 2017/01/30 19:47:24 akio
65  * fix fps/fpost empty slatid
66  *
67  * Revision 1.22 2017/01/30 17:50:16 akio
68  * adding Fpost
69  *
70  * Revision 1.21 2016/11/22 18:23:32 akio
71  * added getLorentzVector to take into account beamline angles/offsets for pt calc
72  *
73  * Revision 1.20 2016/11/21 16:51:20 akio
74  * Avoiding crash when FPS DB is not there
75  *
76  * Revision 1.19 2016/06/08 19:58:03 akio
77  * Applying Coverity report
78  *
79  * Revision 1.18 2016/06/07 15:51:39 akio
80  * Making code better based on Coverity reports
81  *
82  * Revision 1.17 2015/11/12 16:46:40 akio
83  * *** empty log message ***
84  *
85  * Revision 1.16 2015/11/10 23:09:45 akio
86  * fixed logic flaw
87  *
88  * Revision 1.15 2015/11/10 22:48:43 akio
89  * change default to 1, not -1, for case we do not have LED time dep corr
90  *
91  * Revision 1.14 2015/11/10 22:35:44 akio
92  * fix logic for fmsTimeDepCorr table making
93  *
94  * Revision 1.13 2015/11/10 22:13:54 akio
95  * fix of a fix
96  *
97  * Revision 1.12 2015/11/10 21:59:03 akio
98  * fixing backward compatbility
99  *
100  * Revision 1.11 2015/11/10 19:06:02 akio
101  * Adding TimeDepCorr for LED gain correction based on event#
102  *
103  * Revision 1.10 2015/10/20 19:49:28 akio
104  * Fixing distanceFromEdge()
105  * Adding readRecParamFromFile()
106  *
107  * Revision 1.9 2015/09/23 17:34:01 akio
108  * Adding distanceFromEdge() for fiducial volume cut
109  *
110  * Revision 1.8 2015/09/18 18:34:35 akio
111  * Adding getStarXYZfromColumnRow() to convert from local grid space [cell width unit, not cm]
112  * Adding protection for fmsGain and fmsGainCorrection when table length get shorter and can
113  * overwritten by old values.
114  * Removing some error log
115  *
116  * Revision 1.7 2015/09/02 14:45:14 akio
117  * Adding new functions for un-uniform grid cell positions, switched based on DB fmsPositionModel
118  *
119  * Revision 1.3 2011/01/13 02:56:34 jgma
120  * Fixed bug in function nRow and nColumn
121  *
122  * Revision 1.2 2010/01/11 20:35:30 jgma
123  * Added reversed map and some other minor updates
124  *
125  * Revision 1.1 2009/10/28 16:11:15 jgma
126  * This is the first check in of the code.
127  *
128  **************************************************************************/
129 
130 
131 #include "StFmsDbMaker.h"
132 #include "St_db_Maker/St_db_Maker.h"
133 #include "StMessMgr.h"
134 #include "tables/St_fmsDetectorPosition_Table.h"
135 #include "tables/St_fmsChannelGeometry_Table.h"
136 #include "tables/St_fmsMap_Table.h"
137 #include "tables/St_fmsPatchPanelMap_Table.h"
138 #include "tables/St_fmsQTMap_Table.h"
139 #include "tables/St_fmsGain_Table.h"
140 #include "tables/St_fmsGainCorrection_Table.h"
141 #include "tables/St_fmsBitShiftGain_Table.h"
142 #include "tables/St_fmsGainB_Table.h"
143 #include "tables/St_fmsGainCorrectionB_Table.h"
144 #include "tables/St_fmsBitShiftGainB_Table.h"
145 #include "tables/St_fmsTimeDepCorr_Table.h"
146 #include "tables/St_fmsRec_Table.h"
147 #include "tables/St_fmsPositionModel_Table.h"
148 #include "tables/St_fpsConstant_Table.h"
149 #include "tables/St_fpsChannelGeometry_Table.h"
150 #include "tables/St_fpsSlatId_Table.h"
151 #include "tables/St_fpsPosition_Table.h"
152 #include "tables/St_fpsMap_Table.h"
153 #include "tables/St_fpsGain_Table.h"
154 #include "tables/St_fpsStatus_Table.h"
155 #include "tables/St_fpostConstant_Table.h"
156 #include "tables/St_fpostChannelGeometry_Table.h"
157 #include "tables/St_fpostSlatId_Table.h"
158 #include "tables/St_fpostPosition_Table.h"
159 #include "tables/St_fpostMap_Table.h"
160 #include "tables/St_fpostGain_Table.h"
161 #include "tables/St_fpostStatus_Table.h"
162 #include "tables/St_vertexSeed_Table.h"
163 
164 #include "getCellPosition2015pp.h"
165 #include "getCellPosition2015pA.h"
166 #include "getCellPosition2017.h"
167 
168 #include "StEvent/StFmsHit.h"
169 #include "StEvent/StFmsPoint.h"
170 #include "StEvent/StEnumerations.h"
171 
172 ClassImp(StFmsDbMaker)
173 
174 StFmsDbMaker::StFmsDbMaker(const Char_t *name) : StMaker(name), mRecConfig(StFmsDbConfig::Instance()) {};
175 StFmsDbMaker::~StFmsDbMaker() {deleteArrays();}
176 Int_t StFmsDbMaker::Init(){LOG_DEBUG<<"StFmsDbMaker Init Start"<<endm; return StMaker::Init();}
177 Int_t StFmsDbMaker::Make(){LOG_DEBUG<<"StFmsDbMaker Make"<<endm; return kStOK;}
178 void StFmsDbMaker::Clear(const Char_t*){LOG_DEBUG<<"StFmsDbMaker Clear"<<endm; StMaker::Clear();}
179 Int_t StFmsDbMaker::Finish(){LOG_DEBUG<<"StFmsDbMaker Finish"<<endm; return kStOK;}
180 
181 Int_t StFmsDbMaker::InitRun(Int_t runNumber) {
182  LOG_DEBUG << "StFmsDbMaker::InitRun - run = " << runNumber << endm;
183  deleteArrays();
184 
185  TString attr(SAttr("fmsGainCorr"));
186  if(attr!="") {
187  LOG_INFO << "FmsGainCorrection Flavor = " << attr << endm;
188  SetFlavor(attr.Data(),"fmsGainCorrectionB");
189  }
190 
192  if(mDebug>0) {
193  St_db_Maker* dbmaker = (St_db_Maker*)GetMaker("db");
194  LOG_INFO << "StFmsDbMaker::InitRun - Date&time from St_db_Maker="<<dbmaker->GetDate()<<","<< dbmaker->GetTime() << endm;
195  }
196 
197  TDataSet *DBgeom = 0;
198  TDataSet *DBmapping = 0;
199  TDataSet *DBcalibration = 0;
200  TDataSet *DBFpsGeom = 0;
201  TDataSet *DBFpsCalibration = 0;
202  DBgeom = GetInputDB("Geometry/fms");
203  DBmapping = GetInputDB("Calibrations/fms/mapping");
204  DBcalibration= GetInputDB("Calibrations/fms");
205  DBFpsGeom = GetInputDB("Geometry/fps");
206  DBFpsCalibration= GetInputDB("Calibrations/fps");
207  if(!DBgeom) {LOG_ERROR << "StFmsDbMaker::InitRun - No Geometry/fms"<<endm; return kStFatal;}
208  if(!DBmapping) {LOG_ERROR << "StFmsDbMaker::InitRun - No Calibration/fms/mapping"<<endm; return kStFatal;}
209  if(!DBcalibration) {LOG_ERROR << "StFmsDbMaker::InitRun - No Calibration/fms"<<endm; return kStFatal;}
210  if(!DBFpsGeom) {LOG_ERROR << "StFmsDbMaker::InitRun - No Geometry/fps"<<endm; return kStFatal;}
211  if(!DBFpsCalibration){LOG_ERROR << "StFmsDbMaker::InitRun - No Calibration/fps"<<endm; return kStFatal;}
212 
214  St_fmsChannelGeometry *dbChannelGeometry =0;
215  St_fmsDetectorPosition *dbDetectorPosition =0;
216  St_fmsPositionModel *dbPositionModel =0;
217  St_fmsMap *dbMap =0;
218  St_fmsPatchPanelMap *dbPatchPanelMap =0;
219  St_fmsQTMap *dbQTMap =0;
220  St_fmsGain *dbGain =0;
221  St_fmsGainCorrection *dbGainCorrection =0;
222  St_fmsBitShiftGain *dbBitShiftGain =0;
223  St_fmsGainB *dbGainB =0;
224  St_fmsGainCorrectionB *dbGainCorrectionB =0;
225  St_fmsBitShiftGainB *dbBitShiftGainB =0;
226  St_fmsTimeDepCorr *dbTimeDepCorr =0;
227  St_fmsRec *dbRec =0;
228  St_fpsConstant *dbFpsConstant =0;
229  St_fpsChannelGeometry *dbFpsChannelGeometry=0;
230  St_fpsSlatId *dbFpsSlatId =0;
231  St_fpsPosition *dbFpsPosition =0;
232  St_fpsMap *dbFpsMap =0;
233  St_fpsGain *dbFpsGain =0;
234  St_fpsStatus *dbFpsStatus =0;
235  St_fpostConstant *dbFpostConstant =0;
236  St_fpostChannelGeometry *dbFpostChannelGeometry=0;
237  St_fpostSlatId *dbFpostSlatId =0;
238  St_fpostPosition *dbFpostPosition =0;
239  St_fpostMap *dbFpostMap =0;
240  St_fpostGain *dbFpostGain =0;
241  St_fpostStatus *dbFpostStatus =0;
242 
243  dbChannelGeometry = (St_fmsChannelGeometry*) DBgeom->Find("fmsChannelGeometry");
244  dbDetectorPosition = (St_fmsDetectorPosition*)DBgeom->Find("fmsDetectorPosition");
245  dbPositionModel = (St_fmsPositionModel*) DBgeom->Find("fmsPositionModel");
246  dbMap = (St_fmsMap*) DBmapping->Find("fmsMap");
247  dbPatchPanelMap = (St_fmsPatchPanelMap*) DBmapping->Find("fmsPatchPanelMap");
248  dbQTMap = (St_fmsQTMap*) DBmapping->Find("fmsQTMap");
249  dbGain = (St_fmsGain*) DBcalibration->Find("fmsGain");
250  dbGainCorrection = (St_fmsGainCorrection*) DBcalibration->Find("fmsGainCorrection");
251  dbBitShiftGain = (St_fmsBitShiftGain*) DBcalibration->Find("fmsBitShiftGain");
252  dbGainB = (St_fmsGainB*) DBcalibration->Find("fmsGainB");
253  dbGainCorrectionB = (St_fmsGainCorrectionB*) DBcalibration->Find("fmsGainCorrectionB");
254  dbBitShiftGainB = (St_fmsBitShiftGainB*) DBcalibration->Find("fmsBitShiftGainB");
255  dbTimeDepCorr = (St_fmsTimeDepCorr*) DBcalibration->Find("fmsTimeDepCorr");
256  dbRec = (St_fmsRec*) DBcalibration->Find("fmsRec");
257  dbFpsConstant = (St_fpsConstant*) DBFpsGeom->Find("fpsConstant");
258  dbFpsChannelGeometry= (St_fpsChannelGeometry*) DBFpsGeom->Find("fpsChannelGeometry");
259  dbFpsSlatId = (St_fpsSlatId*) DBFpsGeom->Find("fpsSlatId");
260  dbFpsPosition = (St_fpsPosition*) DBFpsGeom->Find("fpsPosition");
261  dbFpsMap = (St_fpsMap*) DBFpsGeom->Find("fpsMap");
262  dbFpsGain = (St_fpsGain*) DBFpsCalibration->Find("fpsGain");
263  dbFpsStatus = (St_fpsStatus*) DBFpsCalibration->Find("fpsStatus");
264  dbFpostConstant = (St_fpostConstant*) DBFpsGeom->Find("fpostConstant");
265  dbFpostChannelGeometry= (St_fpostChannelGeometry*) DBFpsGeom->Find("fpostChannelGeometry");
266  dbFpostSlatId = (St_fpostSlatId*) DBFpsGeom->Find("fpostSlatId");
267  dbFpostPosition = (St_fpostPosition*) DBFpsGeom->Find("fpostPosition");
268  dbFpostMap = (St_fpostMap*) DBFpsGeom->Find("fpostMap");
269  dbFpostGain = (St_fpostGain*) DBFpsCalibration->Find("fpostGain");
270  dbFpostStatus = (St_fpostStatus*) DBFpsCalibration->Find("fpostStatus");
271 
272  if(!dbChannelGeometry) {LOG_ERROR << "StFmsDbMaker::InitRun - No Geometry/fms/fmsChannelGeometry" <<endm; return kStFatal;}
273  if(!dbDetectorPosition) {LOG_ERROR << "StFmsDbMaker::InitRun - No Geometry/fms/fmsDetectorPosition" <<endm; return kStFatal;}
274  if(!dbPositionModel) {LOG_INFO << "StFmsDbMaker::InitRun - No Geometry/fms/fmsPositionModel, using default" <<endm; }
275  if(!dbMap) {LOG_ERROR << "StFmsDbMaker::InitRun - No Calibration/fms/mapping/fmsMap" <<endm; return kStFatal;}
276  if(!dbPatchPanelMap) {LOG_ERROR << "StFmsDbMaker::InitRun - No Calibration/fms/mapping/fmsPatchPanelMap"<<endm; return kStFatal;}
277  if(!dbQTMap) {LOG_ERROR << "StFmsDbMaker::InitRun - No Calibration/fms/mapping/fmsQTMap" <<endm; return kStFatal;}
278  if(!dbGain && !dbGainB) {LOG_ERROR << "StFmsDbMaker::InitRun - No Calibration/fms/fmsGain nor B" <<endm; return kStFatal;}
279  if(!dbGainCorrection && !dbGainCorrectionB) {LOG_ERROR << "StFmsDbMaker::InitRun - No Calibration/fms/fmsGainCorrection nor B"<<endm; return kStFatal;}
280  if(!dbBitShiftGain && !dbBitShiftGainB) {LOG_ERROR << "StFmsDbMaker::InitRun - No Calibration/fms/fmsBitShiftGain nor B" <<endm;}
281  if(!dbTimeDepCorr) {LOG_ERROR << "StFmsDbMaker::InitRun - No Calibration/fms/fmsTimeDepCorr" <<endm;}
282  if(!dbRec) {LOG_ERROR << "StFmsDbMaker::InitRun - No Calibration/fms/fmsRec" <<endm; return kStFatal;}
283 
284  if(!dbFpsConstant) {LOG_ERROR << "StFmsDbMaker::InitRun - No Geometry/fps/fpsConstant" <<endm;}
285  if(!dbFpsChannelGeometry){LOG_ERROR << "StFmsDbMaker::InitRun - No Geometry/fps/fpsChannelGeometry" <<endm;}
286  if(!dbFpsSlatId) {LOG_ERROR << "StFmsDbMaker::InitRun - No Geometry/fps/fpsSlatId" <<endm;}
287  if(!dbFpsPosition) {LOG_ERROR << "StFmsDbMaker::InitRun - No Geometry/fps/fpsPosition" <<endm;}
288  if(!dbFpsMap) {LOG_ERROR << "StFmsDbMaker::InitRun - No Geometry/fps/fpsMap" <<endm;}
289  if(!dbFpsGain) {LOG_ERROR << "StFmsDbMaker::InitRun - No Calibration/fps/fpsGain" <<endm;}
290  if(!dbFpsStatus) {LOG_ERROR << "StFmsDbMaker::InitRun - No Calibration/fps/fpsStatus" <<endm;}
291 
292  if(!dbFpostConstant) {LOG_ERROR << "StFmsDbMaker::InitRun - No Geometry/fpost/fpostConstant" <<endm;}
293  if(!dbFpostChannelGeometry){LOG_ERROR << "StFmsDbMaker::InitRun - No Geometry/fpost/fpostChannelGeometry" <<endm;}
294  if(!dbFpostSlatId) {LOG_ERROR << "StFmsDbMaker::InitRun - No Geometry/fpost/fpostSlatId" <<endm;}
295  if(!dbFpostPosition) {LOG_ERROR << "StFmsDbMaker::InitRun - No Geometry/fpost/fpostPosition" <<endm;}
296  if(!dbFpostMap) {LOG_ERROR << "StFmsDbMaker::InitRun - No Geometry/fpost/fpostMap" <<endm;}
297  if(!dbFpostGain) {LOG_ERROR << "StFmsDbMaker::InitRun - No Calibration/fpost/fpostGain" <<endm;}
298  if(!dbFpostStatus) {LOG_ERROR << "StFmsDbMaker::InitRun - No Calibration/fpost/fpostStatus" <<endm;}
299 
301  fmsChannelGeometry_st *tChannelGeometry = 0;
302  tChannelGeometry = (fmsChannelGeometry_st*) dbChannelGeometry->GetTable();
303  UShort_t max = dbChannelGeometry->GetNRows();
304  mMaxDetectorId = 0;
305  for(Int_t i=0; i<max; i++){
306  if(mMaxDetectorId < tChannelGeometry[i].detectorId) mMaxDetectorId = tChannelGeometry[i].detectorId;
307  }
308  mChannelGeometry = new fmsChannelGeometry_st[mMaxDetectorId+1]();
309  //memset(mChannelGeometry,0,sizeof(fmsChannelGeometry_st)*(mMaxDetectorId+1));
310  for(Int_t i=0; i<max; i++){
311  memcpy(&mChannelGeometry[tChannelGeometry[i].detectorId], &tChannelGeometry[i], sizeof(fmsChannelGeometry_st));
312  }
313  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Geometry/fms/fmsChannelGeometry with maxDetectorId = "<<mMaxDetectorId<< endm;
314 
316  fmsDetectorPosition_st *tDetectorPosition = 0;
317  tDetectorPosition = (fmsDetectorPosition_st*) dbDetectorPosition->GetTable();
318  mDetectorPosition = new fmsDetectorPosition_st[mMaxDetectorId+1]();
319  // memset(mDetectorPosition,0,sizeof(fmsDetectorPosition_st)*(mMaxDetectorId+1));
320  max = dbDetectorPosition->GetNRows();
321  for(Int_t i=0; i<max; i++){
322  memcpy(&mDetectorPosition[tDetectorPosition[i].detectorId], &tDetectorPosition[i], sizeof(fmsDetectorPosition_st));
323  }
324  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Geometry/fms/fmsDetectorPosition with "<<max<<" detectors"<< endm;
325 
327  mPositionModel=0;
328  if(dbPositionModel){
329  fmsPositionModel_st *tPositionModel = 0;
330  tPositionModel = (fmsPositionModel_st*) dbPositionModel->GetTable();
331  mPositionModel= tPositionModel[0].model;
332  }
333  LOG_INFO << "StFmsDbMaker::InitRun - Got Geometry/fms/fmsPositionModel = "<<mPositionModel<< endm;
334 
336  mPatchPanelMap = (fmsPatchPanelMap_st*) dbPatchPanelMap->GetTable();
337  mMaxModule = dbPatchPanelMap->GetNRows();
339  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Calibration/fms/mapping/fmsPatchPanelMap with mMaxModule = "<<mMaxModule<< endm;
340 
342  mQTMap = (fmsQTMap_st*) dbQTMap->GetTable();
343  mMaxNS = dbQTMap->GetNRows();
344  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Calibration/fms/mapping/fmsQTMap with mMaxNS = "<<mMaxNS<< endm;
345 
347  mMap = (fmsMap_st*) dbMap->GetTable();
348  mMaxMap = dbMap->GetNRows();
349  mmMap = new fmsMap_st* [mMaxDetectorId+1]();
350  //memset(mmMap,0,sizeof(fmsMap_st*)*(mMaxDetectorId+1));
351  memset(mReverseMapDetectorId,0,sizeof(mReverseMapDetectorId));
352  memset(mReverseMapChannel,0,sizeof(mReverseMapChannel));
353  for(Int_t i=0; i<mMaxMap; i++){
354  Int_t d=mMap[i].detectorId;
355  Int_t c=mMap[i].ch;
356  if(d<0 || d>mMaxDetectorId){
357  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/mapping/fmsMap detectorId="<<d<<" exceed max="<<mMaxDetectorId<<endm;
358  return kStFatal;
359  }
360  if(c<1 || c>maxChannel(d)){
361  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/mapping/fmsMap ch="<<c<<" exceed max="<<maxChannel(d)<<endm;
362  return kStFatal;
363  }
364  if(mmMap[d]==0){
365  mmMap[d] = new fmsMap_st [maxChannel(d)]();
366  //memset(mmMap[d],0,sizeof(fmsMap_st)*maxChannel(d));
367  }
368  memcpy(&mmMap[d][c-1],&mMap[i],sizeof(fmsMap_st));
369  //creating reverse mapping
370  Int_t crt,slot,ch;
371  getMap(d,c,&crt,&slot,&ch);
372  mReverseMapDetectorId[crt][slot][ch]=d;
373  mReverseMapChannel[crt][slot][ch]=c;
374  }
375 
376  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Geometry/fms/mapping/fmsMap with mMaxMap = "<<mMaxMap<< endm;
377 
379  if(dbGainB){
380  mGainB = (fmsGainB_st*) dbGainB->GetTable();
381  mMaxGain = dbGainB->GetNRows();
382  if(mMaxGain==1){
383  mMaxGain=0;
384  mmGain = new fmsGain_st* [mMaxDetectorId+1]();
385  for(Int_t i=0; i<2500; i++){
386  Int_t d=mGainB[0].detectorId[i];
387  Int_t c=mGainB[0].ch[i];
388  if(d==0 && c==0) continue;
389  if(d<0 || d>mMaxDetectorId){
390  LOG_DEBUG << "StFmsDbMaker::InitRun - Calibration/fms/fmsGainB detectorId="<<d<<" exceed max = "<<mMaxDetectorId<<endm;
391  continue;
392  }
393  if(maxChannel(d)<1){
394  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsGainB invalid max number of channel = "<<maxChannel(d)
395  <<"for det="<<d<<endm;
396  continue;
397  }
398  if(c<1 || c>maxChannel(d)){
399  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsGainB detectorId="<<d<<" ch="<<c<<" exceed max = "<<maxChannel(d)<<endm;
400  continue;
401  }
402  if(mmGain[d]==0){
403  mmGain[d] = new fmsGain_st [maxChannel(d)]();
404  //memset(mmGain[d],0,sizeof(fmsGain_st)*maxChannel(d));
405  }
406  if(mmGain[d][c-1].ch==0){
407  mMaxGain++;
408  mmGain[d][c-1].detectorId=d;
409  mmGain[d][c-1].ch=c;
410  mmGain[d][c-1].gain=mGainB[0].gain[i];;
411  }else{
412  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsGainB detectorId="<<d<<" ch="<<c<<" double entry, skipping"<<endm;
413  }
414  if(mForceUniformGain>0.0){
415  static int first=0;
416  if(first<3){
417  LOG_INFO << "StFmsDbMaker::InitRun - Calibration/fms/fmsGainB overwritten to uniform value="<<mForceUniformGain<<endm;
418  first++;
419  }
420  mmGain[d][c-1].gain=mForceUniformGain;
421  }
422  }
423  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Calibration/fms/fmsGainB with mMaxGain = "<<mMaxGain<< endm;
424  }
425  }else if(!mmGain && dbGain){
426  mGain = (fmsGain_st*) dbGain->GetTable();
427  mMaxGain = dbGain->GetNRows();
428  mmGain = new fmsGain_st* [mMaxDetectorId+1]();
429  for(Int_t i=0; i<mMaxGain; i++){
430  Int_t d=mGain[i].detectorId;
431  Int_t c=mGain[i].ch;
432  if(d<0 || d>mMaxDetectorId){
433  LOG_DEBUG << "StFmsDbMaker::InitRun - Calibration/fms/fmsGain detectorId="<<d<<" exceed max = "<<mMaxDetectorId<<endm;
434  continue;
435  }
436  if(maxChannel(d)<1){
437  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsGain invalid max number of channel = "<<maxChannel(d)
438  <<"for det="<<d<<endm;
439  continue;
440  }
441  if(c<1 || c>maxChannel(d)){
442  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsGain detectorId="<<d<<" ch="<<c<<" exceed max = "<<maxChannel(d)<<endm;
443  continue;
444  }
445  if(mmGain[d]==0){
446  mmGain[d] = new fmsGain_st [maxChannel(d)]();
447  //memset(mmGain[d],0,sizeof(fmsGain_st)*maxChannel(d));
448  }
449  if(mmGain[d][c-1].ch==0){
450  memcpy(&mmGain[d][c-1],&mGain[i],sizeof(fmsGain_st));
451  }else{
452  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsGain detectorId="<<d<<" ch="<<c<<" double entry, skipping"<<endm;
453  }
454  if(mForceUniformGain>0.0){
455  static int first=0;
456  if(first<3){
457  LOG_INFO << "StFmsDbMaker::InitRun - Calibration/fms/fmsGain overwritten to uniform value="<<mForceUniformGain<<endm;
458  first++;
459  }
460  mmGain[d][c-1].gain=mForceUniformGain;
461  }
462  }
463  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Calibration/fms/fmsGain with mMaxGain = "<<mMaxGain<< endm;
464  }
465  if(mReadGainFile){
466  LOG_INFO << "StFmsDbMaker::InitRun - Calibration/fms/fmsGain or B will be overwritten by FmsGain.txt"<<endm;
467  FILE* f=fopen("FmsGain.txt","r");
468  if(!f){
469  LOG_INFO<<"Failed to open FmsGain.txt"<<endm;
470  }else{
471  int ew,nstb,ch;
472  float gain;
473  while(fscanf(f,"%d %d %d %f",&ew,&nstb,&ch,&gain)!=EOF){
474  if(ew==2){
475  int dd=nstb+7;
476  //printf("Reading FmsGain.txt %1d %1d %2d %3d %f\n",ew,nstb,dd,ch,gain);
477  mmGain[dd][ch-1].gain=gain;
478  }
479  }
480  fclose(f);
481  LOG_INFO << "StFmsDbMaker::InitRun - Calibration/fms/fmsGain was overwritten by FmsGain.txt"<<endm;
482  }
483  }
484 
486  if(dbGainCorrectionB){
487  mGainCorrectionB = (fmsGainCorrectionB_st*) dbGainCorrectionB->GetTable();
488  mMaxGainCorrection = dbGainCorrectionB->GetNRows();
489  if(mMaxGainCorrection==1){
490  mMaxGainCorrection=0;
491  mmGainCorrection = new fmsGainCorrection_st* [mMaxDetectorId+1]();
492  //memset(mmGainCorrection,0,sizeof(fmsGainCorrection_st*)*(mMaxDetectorId+1));
493  for(Int_t i=0; i<2500; i++){
494  Int_t d=mGainCorrectionB[0].detectorId[i];
495  Int_t c=mGainCorrectionB[0].ch[i];
496  if(d==0 && c==0) continue;
497  if(d<0 || d>mMaxDetectorId){
498  LOG_DEBUG << "StFmsDbMaker::InitRun - Calibration/fms/fmsGainCorrectionB detectorId="<<d<<" exceed max="<<mMaxDetectorId<<endm;
499  continue;
500  }
501  if(maxChannel(d)<1){
502  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsGainCorrectionB invalid max number of channel = "<<maxChannel(d)
503  <<"for det="<<d<<endm;
504  continue;
505  }
506  if(c<1 || c>maxChannel(d)){
507  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsGainCorrectionB ch="<<c<<" exceed max="<<maxChannel(d)<<endm;
508  continue;
509  }
510  if(mmGainCorrection[d]==0){
511  mmGainCorrection[d] = new fmsGainCorrection_st [maxChannel(d)]();
512  //memset(mmGainCorrection[d],0,sizeof(fmsGainCorrection_st)*maxChannel(d));
513  }
514  if(mmGainCorrection[d][c-1].ch==0){
515  mMaxGainCorrection++;
516  mmGainCorrection[d][c-1].detectorId=d;
517  mmGainCorrection[d][c-1].ch=c;
518  mmGainCorrection[d][c-1].corr=mGainCorrectionB[0].corr[i];;
519  }else{
520  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsGainCorrectionB detectorId="<<d<<" ch="<<c<<" double entry, skipping"<<endm;
521  }
522  if(mForceUniformGainCorrection>0.0){
523  static int first=0;
524  if(first==0){
525  LOG_INFO << "StFmsDbMaker::InitRun - Calibration/fms/fmsGainCorrectionB overwritten to uniform value="<<mForceUniformGainCorrection<<endm;
526  first++;
527  }
528  mmGainCorrection[d][c-1].corr=mForceUniformGainCorrection;
529  }
530  }
531  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Geometry/fms/fmsGainCorrectionB with mMaxGainCorrection = "<<mMaxGainCorrection<< endm;
532  }
533  }else if(dbGainCorrection && !mmGainCorrection){
534  mGainCorrection = (fmsGainCorrection_st*) dbGainCorrection->GetTable();
535  mMaxGainCorrection = dbGainCorrection->GetNRows();
536  mmGainCorrection = new fmsGainCorrection_st* [mMaxDetectorId+1]();
537  //memset(mmGainCorrection,0,sizeof(fmsGainCorrection_st*)*(mMaxDetectorId+1));
538  for(Int_t i=0; i<mMaxGainCorrection; i++){
539  Int_t d=mGainCorrection[i].detectorId;
540  Int_t c=mGainCorrection[i].ch;
541  if(d<0 || d>mMaxDetectorId){
542  LOG_DEBUG << "StFmsDbMaker::InitRun - Calibration/fms/fmsGainCorrection detectorId="<<d<<" exceed max="<<mMaxDetectorId<<endm;
543  continue;
544  }
545  if(maxChannel(d)<1){
546  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsGainCorrection invalid max number of channel = "<<maxChannel(d)
547  <<"for det="<<d<<endm;
548  continue;
549  }
550  if(c<1 || c>maxChannel(d)){
551  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsGainCorrection ch="<<c<<" exceed max="<<maxChannel(d)<<endm;
552  continue;
553  }
554  if(mmGainCorrection[d]==0){
555  mmGainCorrection[d] = new fmsGainCorrection_st [maxChannel(d)]();
556  //memset(mmGainCorrection[d],0,sizeof(fmsGainCorrection_st)*maxChannel(d));
557  }
558  if(mmGainCorrection[d][c-1].ch==0){
559  memcpy(&mmGainCorrection[d][c-1],&mGainCorrection[i],sizeof(fmsGainCorrection_st));
560  }else{
561  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsGainCorr detectorId="<<d<<" ch="<<c<<" double entry, skipping"<<endm;
562  }
563  if(mForceUniformGainCorrection>0.0){
564  static int first=0;
565  if(first==0){
566  LOG_INFO << "StFmsDbMaker::InitRun - Calibration/fms/fmsGainCorrection overwritten to uniform value="<<mForceUniformGainCorrection<<endm;
567  first++;
568  }
569  mmGainCorrection[d][c-1].corr=mForceUniformGainCorrection;
570  }
571  }
572  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Geometry/fms/fmsGainCorrection with mMaxGainCorrection = "<<mMaxGainCorrection<< endm;
573  }
574  if(mReadGainCorrFile){
575  LOG_INFO << "StFmsDbMaker::InitRun - Calibration/fms/fmsGainCorr will be overwritten by FmsGainCorr.txt"<<endm;
576  FILE* f=fopen("FmsGainCorr.txt","r");
577  if(!f){
578  LOG_INFO<<"Failed to open FmsGainCorr.txt"<<endm;
579  }else{
580  int ew,nstb,ch;
581  float corr;
582  while(fscanf(f,"%d %d %d %f",&ew,&nstb,&ch,&corr)!=EOF){
583  if(ew==2){
584  int dd=nstb+7;
585  //printf("Reading FmsGainCorr.txt %1d %1d %2d %3d %f\n",ew,nstb,dd,ch,corr);
586  mmGainCorrection[dd][ch-1].corr=corr;
587  }
588  }
589  fclose(f);
590  LOG_INFO << "StFmsDbMaker::InitRun - Calibration/fms/fmsGainCorr was overwritten by FmsGainCorr.txt"<<endm;
591  }
592  }
593 
595  mmBitShiftGain = new fmsBitShiftGain_st* [mMaxDetectorId+1]();
596  if(dbBitShiftGainB!=0){
597  mBitShiftGainB = (fmsBitShiftGainB_st*) dbBitShiftGainB->GetTable();
598  mMaxBitShiftGain = dbBitShiftGainB->GetNRows();
599  if(mMaxBitShiftGain==1){
600  mMaxBitShiftGain=0;
601  for(Int_t i=0; i<2500; i++){
602  Int_t d=mBitShiftGainB[0].detectorId[i];
603  Int_t c=mBitShiftGainB[0].ch[i];
604  if(d==0 && c==0) continue;
605  if(d<0 || d>mMaxDetectorId){
606  LOG_DEBUG << "StFmsDbMaker::InitRun - Calibration/fms/fmsBitShiftGainB detectorId="<<d<<" exceed max = "<<mMaxDetectorId<<endm;
607  continue;
608  }
609  if(maxChannel(d)<1){
610  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsBitShiftGainB invalid max number of channel = "<<maxChannel(d)
611  <<"for det="<<d<<endm;
612  continue;
613  }
614  if(c<1 || c>maxChannel(d)){
615  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsBitShiftGainB detectorId="<<d<<" ch="<<c<<" exceed max = "<<maxChannel(d)<<endm;
616  continue;
617  }
618  if(mmBitShiftGain[d]==0){
619  mmBitShiftGain[d] = new fmsBitShiftGain_st [maxChannel(d)]();
620  //memset(mmBitShiftGain[d],0,sizeof(fmsBitShiftGain_st)*maxChannel(d));
621  }
622  if(mmBitShiftGain[d][c-1].ch==0){
623  mMaxBitShiftGain++;
624  mmBitShiftGain[d][c-1].detectorId=d;
625  mmBitShiftGain[d][c-1].ch=c;
626  mmBitShiftGain[d][c-1].bitshift=mBitShiftGainB[0].bitshift[i];;
627  }else{
628  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsBitShiftGainB detectorId="<<d<<" ch="<<c<<" double entry, skipping"<<endm;
629  }
630  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Calibration/fms/fmsBitShiftGainB with mMaxBitShiftGain = "<<mMaxBitShiftGain<< endm;
631  }
632  }
633  }else if(!mmBitShiftGain && dbBitShiftGain){
634  mBitShiftGain = (fmsBitShiftGain_st*) dbBitShiftGain->GetTable();
635  mMaxBitShiftGain = dbBitShiftGain->GetNRows();
636  for(Int_t i=0; i<mMaxBitShiftGain; i++){
637  Int_t d=mBitShiftGain[i].detectorId;
638  Int_t c=mBitShiftGain[i].ch;
639  if(d<0 || d>mMaxDetectorId){
640  LOG_DEBUG << "StFmsDbMaker::InitRun - Calibration/fms/fmsBitShiftGain detectorId="<<d<<" exceed max = "<<mMaxDetectorId<<endm;
641  continue;
642  }
643  if(maxChannel(d)<1){
644  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsBitShiftGain invalid max number of channel = "<<maxChannel(d)
645  <<"for det="<<d<<endm;
646  continue;
647  }
648  if(c<1 || c>maxChannel(d)){
649  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsBitShiftGain detectorId="<<d<<" ch="<<c<<" exceed max = "<<maxChannel(d)<<endm;
650  continue;
651  }
652  if(mmBitShiftGain[d]==0){
653  mmBitShiftGain[d] = new fmsBitShiftGain_st [maxChannel(d)]();
654  //memset(mmBitShiftGain[d],0,sizeof(fmsBitShiftGain_st)*maxChannel(d));
655  }
656  if(mmBitShiftGain[d][c-1].ch==0){
657  memcpy(&mmBitShiftGain[d][c-1],&mBitShiftGain[i],sizeof(fmsBitShiftGain_st));
658  }else{
659  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsBitShiftGain detectorId="<<d<<" ch="<<c<<" double entry, skipping"<<endm;
660  }
661  }
662  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Calibration/fms/fmsBitShiftGain with mMaxBitShiftGain = "<<mMaxBitShiftGain<< endm;
663  }else{ //no DB found, default to zero
664  for(int d=0; d<=maxDetectorId(); d++){
665  mmBitShiftGain[d] = new fmsBitShiftGain_st [maxChannel(d)]();
666  for(int c=1; c<=maxChannel(d); c++){
667  mmBitShiftGain[d][c-1].detectorId=d;
668  mmBitShiftGain[d][c-1].ch=c;
669  mmBitShiftGain[d][c-1].bitshift=0;
670  }
671  }
672  LOG_INFO << "StFmsDbMaker::InitRun - Found no Calibration/fms/fmsBitShiftGain or B, defaulted to zero"<<endm;
673  }
674  if(mForceUniformGain>0.0){
675  for(int d=0; d<=maxDetectorId(); d++){
676  for(int c=1; c<=maxChannel(d); c++){
677  static int first=0;
678  if(first<3){
679  LOG_INFO << "StFmsDbMaker::InitRun - Calibration/fms/fmsBitShiftGain overwritten to uniform value="<<mForceUniformBitShiftGain<<endm;
680  first++;
681  }
682  mmBitShiftGain[d][c-1].bitshift=mForceUniformBitShiftGain;
683  }
684  }
685  }
686  if(mReadBitShiftGainFile){
687  LOG_INFO << "StFmsDbMaker::InitRun - Calibration/fms/fmsBitShiftGain oe B will be overwritten by FmsBitShiftGain.txt"<<endm;
688  FILE* f=fopen("FmsBitShiftGain.txt","r");
689  if(!f){
690  LOG_INFO<<"Failed to open FmsBitShiftGain.txt"<<endm;
691  }else{
692  int ew,nstb,ch,gain;
693  while(fscanf(f,"%d %d %d %d",&ew,&nstb,&ch,&gain)!=EOF){
694  if(ew==2){
695  int dd=nstb+7;
696  //printf("Reading FmsBitShiftGain.txt %1d %1d %2d %3d %d\n",ew,nstb,dd,ch,gain);
697  mmBitShiftGain[dd][ch-1].bitshift=gain;
698  }
699  }
700  fclose(f);
701  LOG_INFO << "StFmsDbMaker::InitRun - Calibration/fms/fmsBitShiftGain or B was overwritten by FmsBitShiftGain.txt"<<endm;
702  }
703  }
704 
706  mMaxTimeSlice=0;
707  fill_n(&mTimeDep[0][0][0],mFmsTimeDepMaxTimeSlice*mFmsTimeDepMaxDet*mFmsTimeDepMaxCh,1.0);
708  memset(mTimeDepEvt,0,sizeof(mTimeDepEvt));
709  if(dbTimeDepCorr){
710  mTimeDepCorr = (fmsTimeDepCorr_st*) dbTimeDepCorr->GetTable();
711  if(mTimeDepCorr){
712  int nrow = dbTimeDepCorr->GetNRows();
713  if(nrow!=1) {
714  LOG_DEBUG << "StFmsDbMaker::InitRun - Calibration/fms/fmsTimeDepCorr should have 1 row only, but found "
715  << nrow << " rows. No TimeDepCorr"<<endm;
716  }else{
717  int t=0, ndata=0, keepch=0, keept=0;
718  for(Int_t i=0; i<mFmsTimeDepMaxData; i++){
719  Int_t d=mTimeDepCorr[0].detectorId[i];
720  Int_t c=mTimeDepCorr[0].ch[i];
721  Int_t e=mTimeDepCorr[0].endEvent[i];
722  Float_t v=mTimeDepCorr[0].corr[i];
723  if(d==0 && c==1){
724  mTimeDepEvt[t]=e;
725  mTimeDep[t][d][c-1]=v;
726  t++;
727  mMaxTimeSlice=t;
728  }else if(d==0 && c==0 && e==0){
729  break;
730  }else{
731  if(c!=keepch) keept=0;
732  for(int tt=keept; tt<mMaxTimeSlice; tt++){
733  if(e>=mTimeDepEvt[tt]) {mTimeDep[tt][d][c-1]=v;}
734  else {keept=tt; break;}
735  }
736  keepch=c;
737  }
738  ndata++;
739  }
740  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Geometry/fms/fmsTimeDepCorr with "<<ndata<<" lines abd "<<mMaxTimeSlice<<" timeslices"<<endm;
741  }
742  }
743  }
744 
745 
747  mMaxRecPar = 80; //dummy
748  if(mReadRecParam==0){
749  mRecPar = (fmsRec_st*)dbRec->GetTable();
750  mRecConfig.readMap(*mRecPar); //read recPar into internal memory
751  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Calibration/fms/fmsRec "<< endm;
752  }else{
753  mRecConfig.fillMap("fmsrecpar.txt");
754  LOG_INFO << "StFmsDbMaker::InitRun - read fmsrecpar.txt for FmsRec table! "<< endm;
755  }
756 
758  if(dbFpsConstant){
759  fpsConstant_st *tFpsConstant = 0;
760  tFpsConstant = (fpsConstant_st*) dbFpsConstant->GetTable();
761  mFpsConstant = new fpsConstant_st;
762  memcpy(mFpsConstant,tFpsConstant,sizeof(fpsConstant_st));
763  mFpsMaxSlatId=fpsNQuad()*fpsNLayer()*fpsMaxSlat();
764  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Geometry/fms/fpsConstant maxSlatId="<<mFpsMaxSlatId<<endm;
765  }
766 
767  int mI=0, mQ = 0, mL=0, mS=0;
769  if(dbFpsChannelGeometry){
770  fpsChannelGeometry_st *tFpsChannelGeometry = 0;
771  tFpsChannelGeometry = (fpsChannelGeometry_st*) dbFpsChannelGeometry->GetTable();
772  max = dbFpsChannelGeometry->GetNRows();
773  for(Int_t i=0; i<max; i++){
774  if(mQ < tFpsChannelGeometry[i].quad) mQ=tFpsChannelGeometry[i].quad;
775  if(mL < tFpsChannelGeometry[i].layer) mL=tFpsChannelGeometry[i].layer;
776  }
777  if(mQ>fpsNQuad()) LOG_WARN << "StFmsDbMaker::InitRun - fpsChannelGeometry has more quad than fpsConstant"<<endm;
778  if(mL>fpsNLayer()) LOG_WARN << "StFmsDbMaker::InitRun - fpsChannelGeometry has more layer than fpsConstant"<<endm;
779  mFpsChannelGeometry = new fpsChannelGeometry_st*[fpsNQuad()]();
780  for(int i=0; i<fpsNQuad(); i++) mFpsChannelGeometry[i]= new fpsChannelGeometry_st[fpsNLayer()]();
781  for(Int_t i=0; i<max; i++){
782  memcpy(&mFpsChannelGeometry[tFpsChannelGeometry[i].quad-1][tFpsChannelGeometry[i].layer-1],
783  &tFpsChannelGeometry[i], sizeof(fpsChannelGeometry_st));
784  }
785  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Geometry/fms/fpsChannelGeometry with maxQuad="<<mQ<<" and maxLayer="<<mL<<endm;
786  }
787 
789  if(dbFpsSlatId){
790  fpsSlatId_st *tFpsSlatId = 0;
791  tFpsSlatId = (fpsSlatId_st*) dbFpsSlatId->GetTable();
792  max = dbFpsSlatId->GetNRows();
793  mI=0; mQ=0; mL=0; mS=0;
794  for(Int_t i=0; i<max; i++){
795  if(mI < tFpsSlatId[i].slatid) mI=tFpsSlatId[i].slatid;
796  if(mQ < tFpsSlatId[i].quad) mQ=tFpsSlatId[i].quad;
797  if(mL < tFpsSlatId[i].layer) mL=tFpsSlatId[i].layer;
798  if(mS < tFpsSlatId[i].slat) mS=tFpsSlatId[i].slat;
799  }
800  if(max>fpsMaxSlatId()) LOG_WARN << "StFmsDbMaker::InitRun - fpsSlatId has more row than fpsConstant"<<endm;
801  if(mI>fpsMaxSlatId()) LOG_WARN << "StFmsDbMaker::InitRun - fpsSlatId has more slatId than fpsConstant"<<endm;
802  if(mQ>fpsNQuad()) LOG_WARN << "StFmsDbMaker::InitRun - fpsSlatId has more quad than fpsConstant"<<endm;
803  if(mL>fpsNLayer()) LOG_WARN << "StFmsDbMaker::InitRun - fpsSlatId has more layer than fpsConstant"<<endm;
804  if(mS>fpsMaxSlat()) LOG_WARN << "StFmsDbMaker::InitRun - fpsSlatId has more slat than fpsConstant"<<endm;
805  mFpsSlatId = new fpsSlatId_st[max];
806  mFpsReverseSlatId = new int**[fpsNQuad()]();
807  for(int i=0; i<fpsNQuad(); i++) {
808  mFpsReverseSlatId[i] = new int*[fpsNLayer()]();
809  for(int j=0; j<fpsNLayer(); j++) {
810  mFpsReverseSlatId[i][j] = new int[fpsMaxSlat()]();
811  for(int k=0; k<fpsMaxSlat(); k++) mFpsReverseSlatId[i][j][k]=-1;
812  }
813  }
814  for(Int_t i=0; i<max; i++){
815  memcpy(&mFpsSlatId[tFpsSlatId[i].slatid],&tFpsSlatId[i],sizeof(fpsSlatId_st));
816  if(tFpsSlatId[i].quad>0 && tFpsSlatId[i].layer>0 && tFpsSlatId[i].slat>0){
817  mFpsReverseSlatId[tFpsSlatId[i].quad-1][tFpsSlatId[i].layer-1][tFpsSlatId[i].slat-1]=tFpsSlatId[i].slatid;
818  }
819  }
820  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Geometry/fms/fpsSlatId with max slat Id="<<max<<endm;
821  }
822 
824  if(dbFpsPosition){
825  fpsPosition_st *tFpsPosition = 0;
826  tFpsPosition = (fpsPosition_st*) dbFpsPosition->GetTable();
827  max = dbFpsPosition->GetNRows();
828  mI=0;
829  for(Int_t i=0; i<max; i++){
830  if(mI < tFpsPosition[i].slatid) mI=tFpsPosition[i].slatid;
831  }
832  if(max>fpsMaxSlatId()) LOG_WARN << "StFmsDbMaker::InitRun - fpsPosition has more row than fpsConstant"<<endm;
833  if( mI>fpsMaxSlatId()) LOG_WARN << "StFmsDbMaker::InitRun - fpsPosition has more slatId than fpsConstant"<<endm;
834  mFpsPosition = new fpsPosition_st[max]();
835  //memset(mFpsPosition,0,sizeof(*mFpsPosition));
836  for(Int_t i=0; i<max; i++){
837  if(tFpsPosition[i].slatid==0 && tFpsPosition[i].xoffset==0.0 && tFpsPosition[i].yoffset==0.0) continue;
838  memcpy(&mFpsPosition[tFpsPosition[i].slatid],&tFpsPosition[i],sizeof(fpsPosition_st));
839  }
840  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Geometry/fms/fpsPosition with max slat Id="<<max<<endm;
841  }
842 
844  if(dbFpsMap){
845  fpsMap_st *tFpsMap = 0;
846  tFpsMap = (fpsMap_st*) dbFpsMap->GetTable();
847  max = dbFpsMap->GetNRows();
848  if(max>fpsMaxSlatId()) LOG_WARN << "StFmsDbMaker::InitRun - fpsMap has more slatId than fpsConstant"<<endm;
849  int mA = 0, mC=0; mI=0;
850  for(Int_t i=0; i<max; i++){
851  if(mI < tFpsMap[i].slatid) mI=tFpsMap[i].slatid;
852  if(mA < tFpsMap[i].QTaddr) mA=tFpsMap[i].QTaddr;
853  if(mC < tFpsMap[i].QTch) mC=tFpsMap[i].QTch;
854  }
855  if(max>fpsMaxSlat()) LOG_WARN << "StFmsDbMaker::InitRun - fpsMap has more row than fpsConstant"<<endm;
856  if(mI >fpsMaxSlat()) LOG_WARN << "StFmsDbMaker::InitRun - fpsMap has more slatid than fpsConstant"<<endm;
857  if(mA>=fpsMaxQTaddr()) LOG_WARN << "StFmsDbMaker::InitRun - fpsMap has more QTaddr"<<endm;
858  if(mC>=fpsMaxQTch()) LOG_WARN << "StFmsDbMaker::InitRun - fpsMap has more QTch"<<endm;
859  mFpsMap = new fpsMap_st[max];
860  mFpsReverseMap = new int*[fpsMaxQTaddr()]();
861  for(int i=0; i<fpsMaxQTaddr(); i++) {
862  mFpsReverseMap[i] = new int[fpsMaxQTch()];
863  for(int j=0; j<fpsMaxQTch(); j++) mFpsReverseMap[i][j]=-1;
864  }
865  for(Int_t i=0; i<max; i++){
866  memcpy(&mFpsMap[tFpsMap[i].slatid],&tFpsMap[i],sizeof(fpsMap_st));
867  if(tFpsMap[i].QTaddr>=0 && tFpsMap[i].QTch>=0)
868  mFpsReverseMap[tFpsMap[i].QTaddr][tFpsMap[i].QTch]=tFpsMap[i].slatid;
869  }
870  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Geometry/fms/fpsMap with max slat Id="<<max<<endm;
871  }
872 
874  if(dbFpsGain){
875  fpsGain_st *tFpsGain = 0;
876  tFpsGain = (fpsGain_st*) dbFpsGain->GetTable();
877  max = dbFpsGain->GetNRows();
878  int mI=0;
879  for(Int_t i=0; i<max; i++){
880  if(mI < tFpsGain[i].slatid) mI=tFpsGain[i].slatid;
881  }
882  if(max>fpsMaxSlatId()) LOG_WARN << "StFmsDbMaker::InitRun - fpsGain has more row than fpsConstant"<<endm;
883  if(mI >fpsMaxSlatId()) LOG_WARN << "StFmsDbMaker::InitRun - fpsGain has more slatId than fpsConstant"<<endm;
884  mFpsGain = new fpsGain_st[max]();
885  //memset(mFpsGain,0,sizeof(*mFpsGain));
886  for(Int_t i=0; i<max; i++){
887  memcpy(&mFpsGain[tFpsGain[i].slatid],&tFpsGain[i],sizeof(fpsGain_st));
888  }
889  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Calibration/fms/fpsGain with max slat Id="<<max<<endm;
890  }
891 
893  if(dbFpsStatus){
894  fpsStatus_st *tFpsStatus = 0;
895  tFpsStatus = (fpsStatus_st*) dbFpsStatus->GetTable();
896  max = dbFpsStatus->GetNRows();
897  mI=0;
898  for(Int_t i=0; i<max; i++){
899  if(mI < tFpsStatus[i].slatid) mI=tFpsStatus[i].slatid;
900  }
901  if(max>fpsMaxSlatId()) LOG_WARN << "StFmsDbMaker::InitRun - fpsStatus has more row than fpsConstant"<<endm;
902  if(mI >fpsMaxSlatId()) LOG_WARN << "StFmsDbMaker::InitRun - fpsStatus has more slatId than fpsConstant"<<endm;
903  mFpsStatus = new fpsStatus_st[max]();
904  //memset(mFpsStatus,0,sizeof(*mFpsStatus));
905  for(Int_t i=0; i<max; i++){
906  memcpy(&mFpsStatus[tFpsStatus[i].slatid],&tFpsStatus[i],sizeof(fpsStatus_st));
907  }
908  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Calibration/fms/fpsStatus with max slat Id="<<max<<endm;
909  }
910 
912  if(dbFpostConstant){
913  fpostConstant_st *tFpostConstant = 0;
914  tFpostConstant = (fpostConstant_st*) dbFpostConstant->GetTable();
915  mFpostConstant = new fpostConstant_st;
916  memcpy(mFpostConstant,tFpostConstant,sizeof(fpostConstant_st));
917  mFpostMaxSlatId=fpostNQuad()*fpostNLayer()*fpostMaxSlat();
918  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Geometry/fms/fpostConstant maxSlatId="<<mFpostMaxSlatId<<endm;
919  }
920 
921  mI=0; mQ=0; mL=0; mS=0;
923  if(dbFpostChannelGeometry){
924  fpostChannelGeometry_st *tFpostChannelGeometry = 0;
925  tFpostChannelGeometry = (fpostChannelGeometry_st*) dbFpostChannelGeometry->GetTable();
926  max = dbFpostChannelGeometry->GetNRows();
927  for(Int_t i=0; i<max; i++){
928  if(mQ < tFpostChannelGeometry[i].quad) mQ=tFpostChannelGeometry[i].quad;
929  if(mL < tFpostChannelGeometry[i].layer) mL=tFpostChannelGeometry[i].layer;
930  }
931  if(mQ>fpostNQuad()) LOG_WARN << "StFmsDbMaker::InitRun - fpostChannelGeometry has more quad than fpostConstant"<<endm;
932  if(mL>fpostNLayer()) LOG_WARN << "StFmsDbMaker::InitRun - fpostChannelGeometry has more layer than fpostConstant"<<endm;
933  mFpostChannelGeometry = new fpostChannelGeometry_st*[fpostNQuad()]();
934  for(int i=0; i<fpostNQuad(); i++) mFpostChannelGeometry[i]= new fpostChannelGeometry_st[fpostNLayer()]();
935  for(Int_t i=0; i<max; i++){
936  memcpy(&mFpostChannelGeometry[tFpostChannelGeometry[i].quad-1][tFpostChannelGeometry[i].layer-1],
937  &tFpostChannelGeometry[i], sizeof(fpostChannelGeometry_st));
938  }
939  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Geometry/fms/fpostChannelGeometry with maxQuad="<<mQ<<" and maxLayer="<<mL<<endm;
940  }
941 
943  if(dbFpostSlatId){
944  fpostSlatId_st *tFpostSlatId = 0;
945  tFpostSlatId = (fpostSlatId_st*) dbFpostSlatId->GetTable();
946  max = dbFpostSlatId->GetNRows();
947  mI=0; mQ=0; mL=0; mS=0;
948  for(Int_t i=0; i<max; i++){
949  if(mI < tFpostSlatId[i].slatid) mI=tFpostSlatId[i].slatid;
950  if(mQ < tFpostSlatId[i].quad) mQ=tFpostSlatId[i].quad;
951  if(mL < tFpostSlatId[i].layer) mL=tFpostSlatId[i].layer;
952  if(mS < tFpostSlatId[i].slat) mS=tFpostSlatId[i].slat;
953  }
954  if(max>fpostMaxSlatId()) LOG_WARN << "StFmsDbMaker::InitRun - fpostSlatId has more row than fpostConstant"<<endm;
955  if(mI>fpostMaxSlatId()) LOG_WARN << "StFmsDbMaker::InitRun - fpostSlatId has more slatId than fpostConstant"<<endm;
956  if(mQ>fpostNQuad()) LOG_WARN << "StFmsDbMaker::InitRun - fpostSlatId has more quad than fpostConstant"<<endm;
957  if(mL>fpostNLayer()) LOG_WARN << "StFmsDbMaker::InitRun - fpostSlatId has more layer than fpostConstant"<<endm;
958  if(mS>fpostMaxSlat()) LOG_WARN << "StFmsDbMaker::InitRun - fpostSlatId has more slat than fpostConstant"<<endm;
959  mFpostSlatId = new fpostSlatId_st[max];
960  mFpostReverseSlatId = new int**[fpostNQuad()]();
961  for(int i=0; i<fpostNQuad(); i++) {
962  mFpostReverseSlatId[i] = new int*[fpostNLayer()]();
963  for(int j=0; j<fpostNLayer(); j++) {
964  mFpostReverseSlatId[i][j] = new int[fpostMaxSlat()]();
965  for(int k=0; k<fpostMaxSlat(); k++) mFpostReverseSlatId[i][j][k]=-1;
966  }
967  }
968  for(Int_t i=0; i<max; i++){
969  memcpy(&mFpostSlatId[tFpostSlatId[i].slatid],&tFpostSlatId[i],sizeof(fpostSlatId_st));
970  if(tFpostSlatId[i].quad>0 && tFpostSlatId[i].layer>0 && tFpostSlatId[i].slat>0){
971  mFpostReverseSlatId[tFpostSlatId[i].quad-1][tFpostSlatId[i].layer-1][tFpostSlatId[i].slat-1]=tFpostSlatId[i].slatid;
972  }
973  }
974  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Geometry/fms/fpostSlatId with max slat Id="<<max<<endm;
975  }
976 
978  if(dbFpostPosition){
979  fpostPosition_st *tFpostPosition = 0;
980  tFpostPosition = (fpostPosition_st*) dbFpostPosition->GetTable();
981  max = dbFpostPosition->GetNRows();
982  mI=0;
983  for(Int_t i=0; i<max; i++){
984  if(mI < tFpostPosition[i].slatid) mI=tFpostPosition[i].slatid;
985  }
986  if(max>fpostMaxSlatId()) LOG_WARN << "StFmsDbMaker::InitRun - fpostPosition has more row than fpostConstant"<<endm;
987  if( mI>fpostMaxSlatId()) LOG_WARN << "StFmsDbMaker::InitRun - fpostPosition has more slatId than fpostConstant"<<endm;
988  mFpostPosition = new fpostPosition_st[max]();
989  //memset(mFpostPosition,0,sizeof(*mFpostPosition));
990  for(Int_t i=0; i<max; i++){
991  if(tFpostPosition[i].slatid==0 && tFpostPosition[i].xoffset==0.0 && tFpostPosition[i].yoffset==0.0) continue;
992  memcpy(&mFpostPosition[tFpostPosition[i].slatid],&tFpostPosition[i],sizeof(fpostPosition_st));
993  }
994  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Geometry/fms/fpostPosition with max slat Id="<<max<<endm;
995  }
996 
998  if(dbFpostMap){
999  fpostMap_st *tFpostMap = 0;
1000  tFpostMap = (fpostMap_st*) dbFpostMap->GetTable();
1001  max = dbFpostMap->GetNRows();
1002  if(max>fpostMaxSlatId()) LOG_WARN << "StFmsDbMaker::InitRun - fpostMap has more slatId than fpostConstant"<<endm;
1003  int mA = 0, mC=0; mI=0;
1004  for(Int_t i=0; i<max; i++){
1005  if(mI < tFpostMap[i].slatid) mI=tFpostMap[i].slatid;
1006  if(mA < tFpostMap[i].QTaddr) mA=tFpostMap[i].QTaddr;
1007  if(mC < tFpostMap[i].QTch) mC=tFpostMap[i].QTch;
1008  }
1009  if(max>fpostMaxSlat()) LOG_WARN << "StFmsDbMaker::InitRun - fpostMap has more row than fpostConstant"<<endm;
1010  if(mI >fpostMaxSlat()) LOG_WARN << "StFmsDbMaker::InitRun - fpostMap has more slatid than fpostConstant"<<endm;
1011  if(mA>=fpostMaxQTaddr()) LOG_WARN << "StFmsDbMaker::InitRun - fpostMap has more QTaddr"<<endm;
1012  if(mC>=fpostMaxQTch()) LOG_WARN << "StFmsDbMaker::InitRun - fpostMap has more QTch"<<endm;
1013  mFpostMap = new fpostMap_st[max];
1014  mFpostReverseMap = new int*[fpostMaxQTaddr()]();
1015  for(int i=0; i<fpostMaxQTaddr(); i++) {
1016  mFpostReverseMap[i] = new int[fpostMaxQTch()];
1017  for(int j=0; j<fpostMaxQTch(); j++) mFpostReverseMap[i][j]=-1;
1018  }
1019  for(Int_t i=0; i<max; i++){
1020  memcpy(&mFpostMap[tFpostMap[i].slatid],&tFpostMap[i],sizeof(fpostMap_st));
1021  if(tFpostMap[i].QTaddr>=0 && tFpostMap[i].QTch>=0)
1022  mFpostReverseMap[tFpostMap[i].QTaddr][tFpostMap[i].QTch]=tFpostMap[i].slatid;
1023  }
1024  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Geometry/fms/fpostMap with max slat Id="<<max<<endm;
1025  }
1026 
1028  if(dbFpostGain){
1029  fpostGain_st *tFpostGain = 0;
1030  tFpostGain = (fpostGain_st*) dbFpostGain->GetTable();
1031  max = dbFpostGain->GetNRows();
1032  int mI=0;
1033  for(Int_t i=0; i<max; i++){
1034  if(mI < tFpostGain[i].slatid) mI=tFpostGain[i].slatid;
1035  }
1036  if(max>fpostMaxSlatId()) LOG_WARN << "StFmsDbMaker::InitRun - fpostGain has more row than fpostConstant"<<endm;
1037  if(mI >fpostMaxSlatId()) LOG_WARN << "StFmsDbMaker::InitRun - fpostGain has more slatId than fpostConstant"<<endm;
1038  mFpostGain = new fpostGain_st[max]();
1039  //memset(mFpostGain,0,sizeof(*mFpostGain));
1040  for(Int_t i=0; i<max; i++){
1041  memcpy(&mFpostGain[tFpostGain[i].slatid],&tFpostGain[i],sizeof(fpostGain_st));
1042  }
1043  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Calibration/fms/fpostGain with max slat Id="<<max<<endm;
1044  }
1045 
1047  if(dbFpostStatus){
1048  fpostStatus_st *tFpostStatus = 0;
1049  tFpostStatus = (fpostStatus_st*) dbFpostStatus->GetTable();
1050  max = dbFpostStatus->GetNRows();
1051  mI=0;
1052  for(Int_t i=0; i<max; i++){
1053  if(mI < tFpostStatus[i].slatid) mI=tFpostStatus[i].slatid;
1054  }
1055  if(max>fpostMaxSlatId()) LOG_WARN << "StFmsDbMaker::InitRun - fpostStatus has more row than fpostConstant"<<endm;
1056  if(mI >fpostMaxSlatId()) LOG_WARN << "StFmsDbMaker::InitRun - fpostStatus has more slatId than fpostConstant"<<endm;
1057  mFpostStatus = new fpostStatus_st[max]();
1058  //memset(mFpostStatus,0,sizeof(*mFpostStatus));
1059  for(Int_t i=0; i<max; i++){
1060  memcpy(&mFpostStatus[tFpostStatus[i].slatid],&tFpostStatus[i],sizeof(fpostStatus_st));
1061  }
1062  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Calibration/fms/fpostStatus with max slat Id="<<max<<endm;
1063  }
1064 
1066  if(mDebug>0){
1068  dumpFmsDetectorPosition();
1069  dumpFmsMap();
1070  dumpFmsPatchPanelMap();
1071  dumpFmsQTMap();
1072  dumpFmsGain();
1073  dumpFmsGainCorrection();
1074  dumpFmsBitShiftGain();
1075  if(dbTimeDepCorr) dumpFmsTimeDepCorr();
1076  dumpFmsRec();
1077  if(dbFpsConstant) dumpFpsConstant();
1078  if(dbFpsChannelGeometry) dumpFpsChannelGeometry();
1079  if(dbFpsSlatId) dumpFpsSlatId();
1080  if(dbFpsPosition) dumpFpsPosition();
1081  if(dbFpsMap) dumpFpsMap();
1082  if(dbFpsGain) dumpFpsGain();
1083  if(dbFpsStatus) dumpFpsStatus();
1084  if(dbFpostConstant) dumpFpostConstant();
1085  if(dbFpostChannelGeometry) dumpFpostChannelGeometry();
1086  if(dbFpostSlatId) dumpFpostSlatId();
1087  if(dbFpostPosition) dumpFpostPosition();
1088  if(dbFpostMap) dumpFpostMap();
1089  if(dbFpostGain) dumpFpostGain();
1090  if(dbFpostStatus) dumpFpostStatus();
1091  }
1092  return kStOK;
1093 }
1094 
1095 StFmsDbConfig& StFmsDbMaker::getRecConfig(){ return mRecConfig; }
1096 
1097 void StFmsDbMaker::deleteArrays(){
1098  if(mChannelGeometry) delete [] mChannelGeometry;
1099  if(mDetectorPosition) delete [] mDetectorPosition;
1100  if(mmMap){
1101  for(Int_t d=0; d<=mMaxDetectorId; d++){
1102  if(mmMap[d]) delete [] mmMap[d];
1103  }
1104  delete [] mmMap;
1105  }
1106  if(mmGain){
1107  for(Int_t d=0; d<=mMaxDetectorId; d++){
1108  if(mmGain[d]) delete [] mmGain[d];
1109  }
1110  delete [] mmGain;
1111  }
1112  if(mmGainCorrection){
1113  for(Int_t d=0; d<=mMaxDetectorId; d++){
1114  if(mmGainCorrection[d]) delete [] mmGainCorrection[d];
1115  }
1116  delete [] mmGainCorrection;
1117  }
1118  if(mmBitShiftGain){
1119  for(Int_t d=0; d<=mMaxDetectorId; d++){
1120  if(mmBitShiftGain[d]) delete [] mmBitShiftGain[d];
1121  }
1122  delete [] mmBitShiftGain;
1123  }
1124  //FPS
1125  if(mFpsGain) delete [] mFpsGain;
1126  if(mFpsStatus) delete [] mFpsStatus;
1127  if(mFpsReverseMap){
1128  for(Int_t i=0; i<fpsNQuad(); i++){
1129  if(mFpsReverseMap[i]) delete [] mFpsReverseMap[i];
1130  }
1131  delete [] mFpsReverseMap;
1132  }
1133  if(mFpsMap) delete [] mFpsMap;
1134  if(mFpsPosition) delete [] mFpsPosition;
1135  if(mFpsReverseSlatId){
1136  for(Int_t i=0; i<fpsNQuad(); i++){
1137  if(mFpsReverseSlatId[i]){
1138  for(Int_t j=0; j<fpsNLayer(); j++){
1139  if(mFpsReverseSlatId[i][j]) delete [] mFpsReverseSlatId[i][j];
1140  }
1141  delete [] mFpsReverseSlatId[i];
1142  }
1143  }
1144  delete [] mFpsReverseSlatId;
1145  }
1146  if(mFpsSlatId) delete [] mFpsSlatId;
1147  if(mFpsChannelGeometry) {
1148  for(Int_t d=0; d<fpsNQuad(); d++){
1149  if(mFpsChannelGeometry[d]) delete [] mFpsChannelGeometry[d];
1150  }
1151  delete [] mFpsChannelGeometry;
1152  }
1153  if(mFpsConstant) delete mFpsConstant; //this comes last since some delete above uses this
1154  //FPost
1155  if(mFpostGain) delete [] mFpostGain;
1156  if(mFpostStatus) delete [] mFpostStatus;
1157  if(mFpostReverseMap){
1158  for(Int_t i=0; i<fpostNQuad(); i++){
1159  if(mFpostReverseMap[i]) delete [] mFpostReverseMap[i];
1160  }
1161  delete [] mFpostReverseMap;
1162  }
1163  if(mFpostMap) delete [] mFpostMap;
1164  if(mFpostPosition) delete [] mFpostPosition;
1165  if(mFpostReverseSlatId){
1166  for(Int_t i=0; i<fpostNQuad(); i++){
1167  if(mFpostReverseSlatId[i]){
1168  for(Int_t j=0; j<fpostNLayer(); j++){
1169  if(mFpostReverseSlatId[i][j]) delete [] mFpostReverseSlatId[i][j];
1170  }
1171  delete [] mFpostReverseSlatId[i];
1172  }
1173  }
1174  delete [] mFpostReverseSlatId;
1175  }
1176  if(mFpostSlatId) delete [] mFpostSlatId;
1177  if(mFpostChannelGeometry) {
1178  for(Int_t d=0; d<fpostNQuad(); d++){
1179  if(mFpostChannelGeometry[d]) delete [] mFpostChannelGeometry[d];
1180  }
1181  delete [] mFpostChannelGeometry;
1182  }
1183  if(mFpostConstant) delete mFpostConstant; //this comes last since some delete above uses this
1184 }
1185 
1187 StThreeVectorF StFmsDbMaker::getStarXYZ(Int_t detectorId, Int_t ch){
1188  return getStarXYZ(detectorId,getColumnNumber(detectorId,ch),getRowNumber(detectorId,ch));
1189 }
1190 
1192 StThreeVectorF StFmsDbMaker::getStarXYZ(Int_t detectorId, Int_t column, Int_t row){
1193  return getStarXYZfromColumnRow(detectorId,float(column-0.5),float(row-0.5));
1194 }
1195 
1196 
1198 StThreeVectorF StFmsDbMaker::getStarXYZfromColumnRow(Int_t detectorId, Float_t column, Float_t row){
1199  return getStarXYZ(detectorId,column*getXWidth(detectorId),row*getYWidth(detectorId));
1200 }
1201 
1204  return getStarXYZ(hit->detectorId(),hit->channel());
1205 }
1206 
1208 StThreeVectorF StFmsDbMaker::getStarXYZ(Int_t detectorId,Double_t FmsX, Double_t FmsY){
1209  return getStarXYZ(detectorId,float(FmsX),float(FmsY));
1210 }
1211 
1213 StThreeVectorF StFmsDbMaker::getStarXYZ(Int_t detectorId,Float_t FmsX, Float_t FmsY){
1214  Float_t x = 0.0, y=0.0, z=0.0;
1215  //printf("getStarXYZ mPositionModel=%d\n",mPositionModel);
1216  if(mPositionModel==0){ //simple uniform model with xyz offsets and widthes from DB
1217  //printf("getStarXYZ XOFF=%f YOFF=%f\n",mDetectorPosition[detectorId].xoffset,mDetectorPosition[detectorId].yoffset);
1218  if(northSouth(detectorId) == 0)
1219  x = mDetectorPosition[detectorId].xoffset - FmsX;
1220  else
1221  x = mDetectorPosition[detectorId].xoffset + FmsX;
1222  //y = mDetectorPosition[detectorId].yoffset - FmsY;
1223  y = FmsY - mDetectorPosition[detectorId].yoffset; //row# start from bottom
1224  z = mDetectorPosition[detectorId].zoffset;
1225  }else{
1226  float x1=0.0,x2=0.0,y1=0.0,y2=0.0;
1227  float lx = FmsX/getXWidth(detectorId);
1228  float ly = nRow(detectorId) - FmsY/getYWidth(detectorId); //row# in getCellPosition2015xx start from top, so reverse it
1229  int c = int(lx);
1230  int r = int(ly);
1231  float dx = lx-c;
1232  if (northSouth(detectorId)==0) {dx=1.0-dx;} //north side
1233  float dy = 1.0-(ly-r);
1234  if(mPositionModel==1) {getCellPosition2015pp(detectorId-7,r,c,x1,y1,x2,y2,z);}
1235  else if(mPositionModel==2) {getCellPosition2015pA(detectorId-7,r,c,x1,y1,x2,y2,z);}
1236  else if(mPositionModel==3) {getCellPosition2017(detectorId-7,r,c,x1,y1,x2,y2,z);}
1237  else { LOG_ERROR << Form("mPositionModel=%d is not valid!",mPositionModel) <<endm;}
1238  x = x1*(1.0-dx) + x2*dx;
1239  y = y1*(1.0-dy) + y2*dy;
1240  z = z + 15.0; // Detector front face + ShowerMax depth
1241  if( ( detectorId<=9 && fabs(x)<40.0 && fabs(y)<40.0) ||
1242  ( detectorId>=10 && y>50.0) ){
1243  LOG_INFO << Form("Something wrong in getStarXYZ for det=%d",detectorId)<<endm;
1244  LOG_INFO << Form(" getStarXYZ input XY=%f %f",FmsX,FmsY)<<endm;
1245  LOG_INFO << Form(" getStarXYZ local XY=%f %f",lx,ly)<<endm;
1246  LOG_INFO << Form(" getStarXYZ column/row=%d %d",c,r)<<endm;
1247  LOG_INFO << Form(" getStarXYZ star XYZ=%f %f %f",x,y,z)<<endm;
1248  }
1249  }
1250  return StThreeVectorF(x,y,z);
1251 }
1252 Float_t StFmsDbMaker::getPhi(Int_t detectorId,Float_t FmsX, Float_t FmsY){ return (getStarXYZ(detectorId,FmsX,FmsY)).phi();}
1253 Float_t StFmsDbMaker::getEta(Int_t detectorId,Float_t FmsX, Float_t FmsY, Float_t Vertex) { return (getStarXYZ(detectorId,FmsX,FmsY)).pseudoRapidity();}
1254 
1255 void StFmsDbMaker::setDebug(Int_t debug) {mDebug = debug;}
1256 
1258 fmsDetectorPosition_st* StFmsDbMaker::DetectorPosition() {return mDetectorPosition;}
1259 fmsChannelGeometry_st* StFmsDbMaker::ChannelGeometry() {return mChannelGeometry;}
1260 fmsMap_st* StFmsDbMaker::Map() {return mMap;}
1261 fmsPatchPanelMap_st* StFmsDbMaker::PatchPanelMap() {return mPatchPanelMap;}
1262 fmsQTMap_st* StFmsDbMaker::QTMap() {return mQTMap;}
1263 fmsGain_st* StFmsDbMaker::Gain() {return mGain;}
1264 fmsGainCorrection_st* StFmsDbMaker::GainCorrection() {return mGainCorrection;}
1265 fmsRec_st* StFmsDbMaker::RecPar() {return mRecPar;}
1266 fpsConstant_st* StFmsDbMaker::FpsConstant() {return mFpsConstant;}
1267 fpsChannelGeometry_st** StFmsDbMaker::FpsChannelGeometry(){return mFpsChannelGeometry;}
1268 fpsSlatId_st* StFmsDbMaker::FpsSlatId() {return mFpsSlatId;}
1269 fpsPosition_st* StFmsDbMaker::FpsPosition() {return mFpsPosition;}
1270 fpsMap_st* StFmsDbMaker::FpsMap() {return mFpsMap;}
1271 fpsGain_st* StFmsDbMaker::FpsGain() {return mFpsGain;}
1272 fpostConstant_st* StFmsDbMaker::FpostConstant() {return mFpostConstant;}
1273 fpostChannelGeometry_st** StFmsDbMaker::FpostChannelGeometry(){return mFpostChannelGeometry;}
1274 fpostSlatId_st* StFmsDbMaker::FpostSlatId() {return mFpostSlatId;}
1275 fpostPosition_st* StFmsDbMaker::FpostPosition() {return mFpostPosition;}
1276 fpostMap_st* StFmsDbMaker::FpostMap() {return mFpostMap;}
1277 fpostGain_st* StFmsDbMaker::FpostGain() {return mFpostGain;}
1278 
1280 UShort_t StFmsDbMaker::maxDetectorId() {return mMaxDetectorId;}
1281 Int_t StFmsDbMaker::eastWest(Int_t detectorId){
1282  if(detectorId>=0 && detectorId<=mMaxDetectorId && maxChannel(detectorId)>0) return mChannelGeometry[detectorId].ew;
1283  else{
1284  //LOG_WARN<<"StFmsDbMaker::eastWest: Corresponding channel geometry not found."<<endm;
1285  return -1;
1286  }
1287 }
1288 
1289 Int_t StFmsDbMaker::northSouth(Int_t detectorId){
1290  if(detectorId>=0 && detectorId<=mMaxDetectorId && maxChannel(detectorId)>0) return mChannelGeometry[detectorId].ns;
1291  else{
1292  //LOG_WARN<<"StFmsDbMaker::northSouth: Corresponding channel geometry not found."<<endm;
1293  return -1;
1294  }
1295 }
1296 
1297 Int_t StFmsDbMaker::largeSmall(Int_t detectorId){
1298  if(detectorId>=kFmsNorthLargeDetId && detectorId<=kFmsSouthLargeDetId && maxChannel(detectorId)>0) return 0;
1299  if(detectorId>=kFmsNorthSmallDetId && detectorId<=kFmsSouthSmallDetId && maxChannel(detectorId)>0) return 1;
1300  //LOG_WARN<<"StFmsDbMaker::largeSmall: Corresponding channel geometry not found."<<endm;
1301  return -1;
1302 }
1303 
1304 Int_t StFmsDbMaker::type(Int_t detectorId){
1305  if(detectorId>=0 && detectorId<=mMaxDetectorId && maxChannel(detectorId)>0) return mChannelGeometry[detectorId].type;
1306  else{
1307  //LOG_WARN<<"StFmsDbMaker::type: Corresponding channel geometry not found."<<endm;
1308  return -1;
1309  }
1310 }
1311 
1312 Int_t StFmsDbMaker::nRow(Int_t detectorId){
1313  if(detectorId>=0 && detectorId<=mMaxDetectorId && maxChannel(detectorId)>0) return mChannelGeometry[detectorId].nY;
1314  else{
1315  //LOG_WARN<<"StFmsDbMaker::nRow: Corresponding channel geometry not found."<<endm;
1316  return -1;
1317  }
1318 }
1319 
1320 Int_t StFmsDbMaker::nColumn(Int_t detectorId){
1321  if(detectorId>=0 && detectorId<=mMaxDetectorId && maxChannel(detectorId)>0)
1322  return mChannelGeometry[detectorId].nX;
1323  else{
1324  //LOG_WARN<<"StFmsDbMaker::nColumn: Corresponding channel geometry not found."<<endm;
1325  return -1;
1326  }
1327 }
1328 
1329 UShort_t StFmsDbMaker::maxChannel(Int_t detectorId) const {
1330  if(detectorId>=0 && detectorId<=mMaxDetectorId &&
1331  mChannelGeometry[detectorId].nX>0 && mChannelGeometry[detectorId].nY>0)
1332  return mChannelGeometry[detectorId].nX*mChannelGeometry[detectorId].nY;
1333  else{
1334  //LOG_WARN<<"StFmsDbMaker::maxChannel: Corresponding channel geometry not found."<<endm;
1335  return 0;
1336  }
1337 }
1338 
1339 Int_t StFmsDbMaker::detectorId(Int_t ew, Int_t ns, Int_t type){
1340  for(Int_t i=0; i<=mMaxDetectorId; i++)
1341  if((mChannelGeometry+i)){
1342  if(mChannelGeometry[i].ew == ew && mChannelGeometry[i].ns == ns && mChannelGeometry[i].type == type)
1343  return mChannelGeometry[i].detectorId;
1344  }
1345  //LOG_WARN<<"StFmsDbMaker::detectorId: Corresponding channel geometry not found."<<endm;
1346  return -1;
1347 }
1348 
1349 Int_t StFmsDbMaker::getRowNumber(Int_t detectorId, Int_t ch){
1350  if(maxChannel(detectorId)>0) return mChannelGeometry[detectorId].nY - (ch-1)/mChannelGeometry[detectorId].nX;
1351  return -1; //channel# start from top, but row# start from bottom
1352 }
1353 
1354 Int_t StFmsDbMaker::getColumnNumber(Int_t detectorId, Int_t ch){
1355  if(maxChannel(detectorId)>0) return (ch-1)%mChannelGeometry[detectorId].nX + 1;
1356  return -1;
1357 }
1358 
1359 Int_t StFmsDbMaker::getChannelNumber(Int_t detectorId, Int_t row, Int_t column){
1360  if(maxChannel(detectorId)>0) return column + mChannelGeometry[detectorId].nX * (mChannelGeometry[detectorId].nY - row);
1361  return -1;
1362 }
1363 
1365  if(detectorId>=0 && detectorId<=mMaxDetectorId && maxChannel(detectorId)>0)
1366  return StThreeVectorF(mDetectorPosition[detectorId].xoffset, mDetectorPosition[detectorId].yoffset, mDetectorPosition[detectorId].zoffset);
1367  return StThreeVectorF(0, 0, 0);
1368 }
1369 
1370 Float_t StFmsDbMaker::getXWidth(Int_t detectorId){
1371  if(detectorId>=0 && detectorId<=mMaxDetectorId)
1372  return mDetectorPosition[detectorId].xwidth; return -1;
1373 }
1374 
1375 Float_t StFmsDbMaker::getYWidth(Int_t detectorId){
1376  if(detectorId>=0 && detectorId<=mMaxDetectorId)
1377  return mDetectorPosition[detectorId].ywidth; return -1;
1378 }
1379 
1381 Int_t StFmsDbMaker::maxMap() {return mMaxMap;}
1382 void StFmsDbMaker::getMap(Int_t detectorId, Int_t ch, Int_t* qtCrate, Int_t* qtSlot, Int_t* qtChannel){
1383  if(detectorId<0 || detectorId>mMaxDetectorId || ch<1 || ch>maxChannel(detectorId) || mmMap[detectorId]==0 ){
1384  *qtCrate=0; *qtSlot=0; *qtChannel=0;
1385  return;
1386  }
1387  *qtCrate = mmMap[detectorId][ch-1].qtCrate;
1388  *qtSlot = mmMap[detectorId][ch-1].qtSlot;
1389  *qtChannel = mmMap[detectorId][ch-1].qtChannel;
1390 }
1391 
1392 void StFmsDbMaker::getReverseMap(Int_t qtCrate, Int_t qtSlot, Int_t qtChannel, Int_t* detectorId, Int_t* ch) const
1393 {
1394  if(qtCrate==0 && qtSlot==0 && qtChannel==0) {
1395  *detectorId = 0;
1396  *ch = 0;
1397  }else{
1398  *detectorId = mReverseMapDetectorId[qtCrate][qtSlot][qtChannel];
1399  *ch = mReverseMapChannel[qtCrate][qtSlot][qtChannel];
1400  }
1401 }
1402 
1404 Int_t StFmsDbMaker::maxModule() {return mMaxModule;}
1405 
1407 Int_t StFmsDbMaker::maxNS() {return mMaxNS;}
1408 
1410 Int_t StFmsDbMaker::maxGain() {return mMaxGain;}
1411 Int_t StFmsDbMaker::maxGainCorrection() {return mMaxGainCorrection;}
1412 Int_t StFmsDbMaker::maxBitShiftGain() {return mMaxBitShiftGain;}
1413 
1414 Float_t StFmsDbMaker::getGain(Int_t detectorId, Int_t ch) const
1415 {
1416  if(detectorId<0 || detectorId>mMaxDetectorId || ch<1 || ch>maxChannel(detectorId) || mmGain[detectorId]==0) return 0;
1417  return mmGain[detectorId][ch-1].gain;
1418 }
1419 
1420 Float_t StFmsDbMaker::getGainCorrection(Int_t detectorId, Int_t ch) const
1421 {
1422  if(detectorId<0 || detectorId>mMaxDetectorId || ch<1 || ch>maxChannel(detectorId) || mmGainCorrection[detectorId]==0) return 0;
1423  return mmGainCorrection[detectorId][ch-1].corr;
1424 }
1425 
1426 Short_t StFmsDbMaker::getBitShiftGain(Int_t detectorId, Int_t ch) const
1427 {
1428  if(detectorId<0 || detectorId>mMaxDetectorId || ch<1 || ch>maxChannel(detectorId) || mmBitShiftGain[detectorId]==0) return 0;
1429  return mmBitShiftGain[detectorId][ch-1].bitshift;
1430 }
1431 
1432 unsigned short StFmsDbMaker::getCorrectedAdc(unsigned short detectorId, unsigned short ch, unsigned short adc) const
1433 {
1434  short bitshift = getBitShiftGain(detectorId,ch);
1435  if(bitshift>=0) {
1436  return adc + (0x1<<bitshift);
1437  }else{
1438  return adc;
1439  }
1440 }
1441 
1442 unsigned short StFmsDbMaker::getCorrectedAdc(StFmsHit* hit) const
1443 {
1444  return getCorrectedAdc(hit->detectorId(),hit->channel(),hit->adc());
1445 }
1446 
1447 
1449 float StFmsDbMaker::getTimeDepCorr(int event, int det, int ch){ //det=0-3, ch=1-574
1450  static int oldEvent=-1;
1451  static int timeslice=-1;
1452  if(mMaxTimeSlice<=0) {
1453  LOG_INFO << "getTimeDepCorr did not find time dependent correction, returning 1.0"<<endm;
1454  return 1.0;
1455  }
1456  if(event!=oldEvent){
1457  for(int i=0; i<mMaxTimeSlice; i++){
1458  if(event < mTimeDepEvt[i]) {timeslice=i; break;}
1459  }
1460  oldEvent=event;
1461  }
1462  if(timeslice<0){
1463  LOG_INFO << Form("getTimeDepCorr did not find time dependent correction for event=%d in %d time slices",event,mMaxTimeSlice)<<endm;
1464  return 1.0;
1465  }
1466  return mTimeDep[timeslice][det][ch-1];
1467 }
1468 
1469 
1471 void StFmsDbMaker::dumpFmsChannelGeometry(const Char_t* filename) {
1472  FILE* fp;
1473  LOG_INFO << "Writing "<<filename<<endm;
1474  if((fp=fopen(filename,"w"))){
1475  fprintf(fp,"maxDetectorId = %d\n",maxDetectorId());
1476  fprintf(fp," i detiid ew ns type nRow nCol maxCh\n");
1477  for(Int_t i=0; i<mMaxDetectorId+1; i++){
1478  fprintf(fp,"%5d%7d%4d%5d%5d%5d%5d%6d\n",
1479  i,detectorId(eastWest(i),northSouth(i),type(i)),eastWest(i),northSouth(i),type(i),
1480  nRow(i),nColumn(i),maxChannel(i));
1481  }
1482  for(Int_t i=0; i<mMaxDetectorId+1; i++){
1483  fprintf(fp,"DetectorId=%d\n",i);
1484  fprintf(fp,"detiid ch getCh getRow getCol\n");
1485  for(Int_t j=1; j<=maxChannel(i); j++){
1486  fprintf(fp,"%6d%4d%8d%8d%7d\n",
1488  }
1489  }
1490  fclose(fp);
1491  }
1492 }
1493 
1494 void StFmsDbMaker::dumpFmsDetectorPosition(const Char_t* filename) {
1495  FILE* fp;
1496  LOG_INFO << "Writing "<<filename<<endm;
1497  if((fp=fopen(filename,"w"))){
1498  fprintf(fp,"maxDetectorId = %d\n",maxDetectorId());
1499  fprintf(fp," detiid zoffset xoffset yoffset xwidth ywidth\n");
1500  for(Int_t i=0; i<mMaxDetectorId+1; i++)
1501  if((mDetectorPosition+i))
1502  fprintf(fp,"%8d%10.1f%10.2f%8.1f%10.3f%10.3f\n", i,getDetectorOffset(i).z(),getDetectorOffset(i).x(),getDetectorOffset(i).y(),getXWidth(i),getYWidth(i));
1503  fclose(fp);
1504  }
1505 }
1506 
1507 void StFmsDbMaker::dumpFmsMap(const Char_t* filename) {
1508  FILE* fp;
1509  LOG_INFO << "Writing "<<filename<<endm;
1510  if((fp=fopen(filename,"w"))){
1511  fprintf(fp,"maxMap = %d\n",maxMap());
1512  fprintf(fp," i DetId ch crt slt qtch getmap() getReverseMap\n");
1513  for(Int_t i=0; i<mMaxMap; i++){
1514  Int_t d=mMap[i].detectorId;
1515  Int_t c=mMap[i].ch;
1516  Int_t crt,slot,ch,dd,cc;
1517  getMap(d,c,&crt,&slot,&ch);
1518  getReverseMap(crt,slot,ch,&dd,&cc);
1519  fprintf(fp,"%5d%6d%6d%5d%5d%5d%5d%5d%5d%5d%5d\n",
1520  i,d,c,mMap[i].qtCrate,mMap[i].qtSlot,mMap[i].qtChannel,crt,slot,ch,dd,cc);
1521  if(mMap[i].qtCrate>0 && (d-dd!=0 || c-cc!=0)) fprintf(fp,"Problem in reverse map!\n");
1522  }
1523  fclose(fp);
1524  }
1525 }
1526 
1527 void StFmsDbMaker::dumpFmsPatchPanelMap(const Char_t* filename) {
1528  FILE* fp;
1529  LOG_INFO << "Writing "<<filename<<endm;
1530  if((fp=fopen(filename,"w"))){
1531  fprintf(fp," mod channel ppPanel ppRow ppColumn\n");
1532  for(Int_t i=0; i<mMaxModule; i++)
1533  for(Int_t j=0; j<maxChannel(i+8); j++)
1534  fprintf(fp,"%5d%8d%8d%6d%9d\n",i+1,j+1,mPatchPanelMap[i].ppPanel[j],mPatchPanelMap[i].ppRow[j],mPatchPanelMap[i].ppColumn[j]);
1535  fclose(fp);
1536  }
1537 }
1538 
1539 void StFmsDbMaker::dumpFmsQTMap(const Char_t* filename) {
1540  FILE* fp;
1541  LOG_INFO << "Writing "<<filename<<endm;
1542  if((fp=fopen(filename,"w"))){
1543  fprintf(fp,"ns ppPanel row column crate slot channel\n");
1544  for(Int_t ns=0; ns<2; ns++)
1545  for(Int_t pp=0; pp<2; pp++)
1546  for(Int_t row=0; row<20; row++)
1547  for(Int_t col=0; col<16; col++){
1548  if(mQTMap[ns].qtCrate[pp][row][col]==0 && mQTMap[ns].qtSlot[pp][row][col]==0 && mQTMap[ns].qtChannel[pp][row][col]==0)
1549  fprintf(fp,"-1 -1 -1 -1 -1 -1 -1\n");
1550  else
1551  fprintf(fp,"%2d%8d%6d%7d%6d%5d%8d\n",ns+1, pp+1, row+1, col+1,mQTMap[ns].qtCrate[pp][row][col],mQTMap[ns].qtSlot[pp][row][col],
1552  mQTMap[ns].qtChannel[pp][row][col]);
1553  }
1554  fclose(fp);
1555  }
1556 }
1557 
1558 void StFmsDbMaker::dumpFmsGain(const Char_t* filename) {
1559  FILE* fp;
1560  LOG_INFO << "Writing "<<filename<<endm;
1561  if((fp=fopen(filename,"w"))){
1562  fprintf(fp,"maxGain = %d\n",maxGain());
1563  fprintf(fp," i DetId ch gain\n");
1564  int i=0;
1565  for(int d=0; d<=mMaxDetectorId; d++){
1566  if(mmGain[d]){
1567  for(int c=0; c<maxChannel(d); c++){
1568  Int_t dd=mmGain[d][c].detectorId;
1569  Int_t cc=mmGain[d][c].ch;
1570  if(cc>0){
1571  fprintf(fp,"%5d%6d%6d%8.3f\n",
1572  i,dd,cc,getGain(d,cc));
1573  //printf("%5d%6d%6d%8.3f\n",
1574  // i,dd,cc,getGain(d,cc));
1575  i++;
1576  }
1577  }
1578  }
1579  }
1580  fclose(fp);
1581  }
1582 }
1583 
1584 void StFmsDbMaker::dumpFmsGainCorrection(const Char_t* filename) {
1585  FILE* fp;
1586  LOG_INFO << "Writing "<<filename<<endm;
1587  if((fp=fopen(filename,"w"))){
1588  fprintf(fp,"maxGainCorrection = %d\n",maxGainCorrection());
1589  fprintf(fp," i DetId ch gain\n");
1590  int i=0;
1591  for(int d=0; d<=mMaxDetectorId; d++){
1592  if(mmGainCorrection[d]){
1593  for(int c=0; c<maxChannel(d); c++){
1594  Int_t dd=mmGainCorrection[d][c].detectorId;
1595  Int_t cc=mmGainCorrection[d][c].ch;
1596  if(cc>0){
1597  fprintf(fp,"%5d%6d%6d%8.3f\n",
1598  i,dd,cc,getGainCorrection(d,cc));
1599  //printf("%5d%6d%6d%8.3f\n",
1600  // i,dd,cc,getGainCorrection(d,cc));
1601  i++;
1602  }
1603  }
1604  }
1605  }
1606  fclose(fp);
1607  }
1608 }
1609 
1610 void StFmsDbMaker::dumpFmsBitShiftGain(const Char_t* filename) {
1611  FILE* fp;
1612  LOG_INFO << "Writing "<<filename<<endm;
1613  if((fp=fopen(filename,"w"))){
1614  fprintf(fp,"maxGain = %d\n",maxBitShiftGain());
1615  fprintf(fp," i DetId ch bitshiftgain\n");
1616  int i=0;
1617  for(int d=0; d<=mMaxDetectorId; d++){
1618  if(mmBitShiftGain[d]){
1619  for(int c=0; c<maxChannel(d); c++){
1620  Int_t dd=mmBitShiftGain[d][c].detectorId;
1621  Int_t cc=mmBitShiftGain[d][c].ch;
1622  if(cc>0){
1623  fprintf(fp,"%5d%6d%6d%4d\n",
1624  i,dd,cc,getBitShiftGain(d,cc));
1625  i++;
1626  }
1627  }
1628  }
1629  }
1630  fclose(fp);
1631  }
1632 }
1633 
1634 void StFmsDbMaker::dumpFmsTimeDepCorr(const Char_t* filename) {
1635  FILE* fp;
1636  LOG_INFO << "Writing "<<filename<<endm;
1637  if((fp=fopen(filename,"w"))){
1638  fprintf(fp,"maxTimeSlice = %d\n",mMaxTimeSlice);
1639  for(Int_t t=0; t<mMaxTimeSlice; t++){
1640  fprintf(fp,"%3d %10d %6.3f\n",t,mTimeDepEvt[t],getTimeDepCorr(mTimeDepEvt[t]-1,0,1));
1641  }
1642  for(Int_t d=0; d<mFmsTimeDepMaxDet; d++){
1643  for(Int_t c=1; c<=mFmsTimeDepMaxCh; c++){
1644  fprintf(fp,"%1d %3d :",d,c);
1645  for(Int_t t=0; t<mMaxTimeSlice; t++){
1646  fprintf(fp,"%6.3f ",mTimeDep[t][d][c-1]);
1647  if(t%10==9) fprintf(fp,"\n :");
1648  }
1649  fprintf(fp,"\n");
1650  }
1651  }
1652  fclose(fp);
1653  }
1654 }
1655 
1656 void StFmsDbMaker::dumpFmsRec(const Char_t* filename) {
1657  LOG_INFO << "writing "<<filename<<endm;
1658  mRecConfig.writeMap(filename);
1659 
1660 }
1661 
1662 Int_t StFmsDbMaker::fpsNQuad() {if(mFpsConstant) {return mFpsConstant->nQuad;} else {return 0;}}
1663 Int_t StFmsDbMaker::fpsNLayer() {if(mFpsConstant) {return mFpsConstant->nLayer;} else {return 0;}}
1664 Int_t StFmsDbMaker::fpsMaxSlat() {if(mFpsConstant) {return mFpsConstant->maxSlat;} else {return 0;}}
1665 Int_t StFmsDbMaker::fpsMaxQTaddr() {if(mFpsConstant) {return mFpsConstant->maxQTaddr;} else {return 0;}}
1666 Int_t StFmsDbMaker::fpsMaxQTch() {if(mFpsConstant) {return mFpsConstant->maxQTch;} else {return 0;}}
1667 Int_t StFmsDbMaker::fpsMaxSlatId() {if(mFpsConstant) {return mFpsMaxSlatId;} else {return 0;}}
1668 
1669 Int_t StFmsDbMaker::fpsNSlat(int quad, int layer) {
1670  if(quad>0 && quad<=fpsNQuad() && layer>0 && layer<=fpsNLayer()) return mFpsChannelGeometry[quad-1][layer-1].nslat;
1671  return 0;
1672 }
1673 
1674 void StFmsDbMaker::fpsQLSfromSlatId(int slatid, int* quad, int* layer, int* slat){
1675  if(slatid>=0 && slatid<fpsMaxSlatId()){
1676  *quad =mFpsSlatId[slatid].quad;
1677  *layer=mFpsSlatId[slatid].layer;
1678  *slat =mFpsSlatId[slatid].slat;
1679  }else{
1680  *quad=0; *layer=0; *slat=0;
1681  }
1682 }
1683 
1684 Int_t StFmsDbMaker::fpsSlatId(int quad, int layer, int slat) {
1685  if(quad>0 && quad<=fpsNQuad() && layer>0 && layer<=fpsNLayer() && slat>0 && slat<=fpsMaxSlat()){
1686  return mFpsReverseSlatId[quad-1][layer-1][slat-1];
1687  }
1688  return -1;
1689 }
1690 
1691 Int_t StFmsDbMaker::fpsSlatIdFromG2t(int g2tvolid){
1692  int q = (g2tvolid/1000)%10;
1693  int l = (g2tvolid/100)%10;
1694  int s = g2tvolid%100;
1695  return fpsSlatId(q,l,s);
1696 }
1697 
1698 void StFmsDbMaker::fpsPosition(int slatid, float xyz[3], float dxyz[3]){
1699  if(slatid>=0 && slatid<fpsMaxSlatId()){
1700  xyz[0]=mFpsPosition[slatid].xoffset;
1701  xyz[1]=mFpsPosition[slatid].yoffset;
1702  xyz[2]=mFpsPosition[slatid].zoffset;
1703  dxyz[0]=mFpsPosition[slatid].xwidth;
1704  dxyz[1]=mFpsPosition[slatid].ywidth;
1705  dxyz[2]=mFpsPosition[slatid].zwidth;
1706  return;
1707  }
1708  memset(xyz,0,sizeof(*xyz));
1709  memset(dxyz,0,sizeof(*dxyz));
1710 }
1711 
1712 void StFmsDbMaker::fpsPosition(int quad, int layer, int slat, float xyz[3], float dxyz[3]){
1713  fpsPosition(fpsSlatId(quad,layer,slat),xyz,dxyz);
1714 }
1715 
1716 void StFmsDbMaker::fpsQTMap(int slatid, int* QTaddr, int* QTch){
1717  if(slatid>=0 && slatid<fpsMaxSlatId()){
1718  *QTaddr=mFpsMap[slatid].QTaddr;
1719  *QTch=mFpsMap[slatid].QTch;
1720  return;
1721  }
1722  *QTaddr=-1;
1723  *QTch=-1;
1724 }
1725 
1726 Int_t StFmsDbMaker::fpsSlatidFromQT(int QTaddr, int QTch){
1727  if(QTaddr>=0 && QTaddr<fpsMaxQTaddr() && QTch>=0 && QTch<fpsMaxQTch()){
1728  return mFpsReverseMap[QTaddr][QTch];
1729  }
1730  return -1;
1731 }
1732 
1733 void StFmsDbMaker::fpsQLSFromQT(int QTaddr, int QTch, int* quad, int* layer, int* slat){
1734  int slatid=fpsSlatidFromQT(QTaddr,QTch);
1735  fpsQLSfromSlatId(slatid,quad,layer,slat);
1736 }
1737 
1738 Float_t StFmsDbMaker::fpsGain(int slatid){
1739  if(slatid>=0 && slatid<fpsMaxSlatId()) return mFpsGain[slatid].MIP;
1740  return 0.0;
1741 }
1742 
1743 Float_t StFmsDbMaker::fpsGain(int quad, int layer, int slat){
1744  return fpsGain(fpsSlatId(quad,layer,slat));
1745 }
1746 
1747 Float_t StFmsDbMaker::fpsMipSigma(int slatid){
1748  if(slatid>=0 && slatid<fpsMaxSlatId()) return mFpsGain[slatid].Sigma;
1749  return 0.0;
1750 }
1751 
1752 Float_t StFmsDbMaker::fpsMipSigma(int quad, int layer, int slat){
1753  return fpsMipSigma(fpsSlatId(quad,layer,slat));
1754 }
1755 
1756 Float_t StFmsDbMaker::fpsValley(int slatid){
1757  if(slatid>=0 && slatid<fpsMaxSlatId()) return mFpsGain[slatid].Valley;
1758  return 0.0;
1759 }
1760 
1761 Float_t StFmsDbMaker::fpsValley(int quad, int layer, int slat){
1762  return fpsValley(fpsSlatId(quad,layer,slat));
1763 }
1764 
1765 UShort_t StFmsDbMaker::fpsStatus(int slatid){
1766  if(slatid>=0 && slatid<fpsMaxSlatId()) return mFpsStatus[slatid].status;
1767  return 999;
1768 }
1769 
1770 UShort_t StFmsDbMaker::fpsStatus(int quad, int layer, int slat){
1771  return fpsStatus(fpsSlatId(quad,layer,slat));
1772 }
1773 
1774 void StFmsDbMaker::dumpFpsConstant(const Char_t* filename){
1775  FILE* fp;
1776  LOG_INFO << "Writing "<<filename<<endm;
1777  if((fp=fopen(filename,"w"))){
1778  fprintf(fp,"nQuad = %d\n",fpsNQuad());
1779  fprintf(fp,"nLayer = %d\n",fpsNLayer());
1780  fprintf(fp,"maxSlat = %d\n",fpsMaxSlat());
1781  fprintf(fp,"maxQTAddr = %d\n",fpsMaxQTaddr());
1782  fprintf(fp,"maxQTch = %d\n",fpsMaxQTch());
1783  fprintf(fp,"maxSlatId = %d\n",fpsMaxSlatId());
1784  fclose(fp);
1785  }
1786 }
1787 
1788 void StFmsDbMaker::dumpFpsChannelGeometry (const Char_t* filename){
1789  FILE* fp;
1790  LOG_INFO << "Writing "<<filename<<endm;
1791  if((fp=fopen(filename,"w"))){
1792  for(int q=1; q<=fpsNQuad(); q++){
1793  for(int l=1; l<=fpsNLayer(); l++){
1794  fprintf(fp,"Q=%1d L=%1d Nslat=%2d\n",q,l,fpsNSlat(q,l));
1795  }
1796  }
1797  fclose(fp);
1798  }
1799 }
1800 
1801 void StFmsDbMaker::dumpFpsSlatId (const Char_t* filename){
1802  FILE* fp;
1803  LOG_INFO << "Writing "<<filename<<endm;
1804  if((fp=fopen(filename,"w"))){
1805  for(int i=0; i<fpsMaxSlatId(); i++){
1806  int q,l,s,id;
1807  fpsQLSfromSlatId(i,&q,&l,&s);
1808  id=fpsSlatId(q,l,s);
1809  fprintf(fp,"SlatId=%3d Q=%1d L=%1d S=%2d Reversemap=%3d\n",i,q,l,s,id);
1810  if(i!=id) fprintf(fp,"Reversemap did not work!!!\n");
1811  }
1812  fclose(fp);
1813  }
1814 }
1815 
1816 void StFmsDbMaker::dumpFpsPosition(const Char_t* filename){
1817  FILE* fp;
1818  LOG_INFO << "Writing "<<filename<<endm;
1819  if((fp=fopen(filename,"w"))){
1820  for(int i=0; i<fpsMaxSlatId(); i++){
1821  int q,l,s;
1822  float x[3],d[3];
1823  fpsQLSfromSlatId(i,&q,&l,&s);
1824  fpsPosition(q,l,s,x,d);
1825  fprintf(fp,"SlatId=%3d Q=%1d L=%1d S=%2d xyz=%8.3f %8.3f %8.3f dxyz=%8.3f %8.3f %8.3f\n",
1826  i,q,l,s,x[0],x[1],x[2],d[0],d[1],d[2]);
1827  }
1828  fclose(fp);
1829  }
1830 }
1831 
1832 void StFmsDbMaker::dumpFpsMap(const Char_t* filename){
1833  FILE* fp;
1834  LOG_INFO << "Writing "<<filename<<endm;
1835  if((fp=fopen(filename,"w"))){
1836  fprintf(fp,"SlatId ordered\n");
1837  for(int i=0; i<fpsMaxSlatId(); i++){
1838  int a,c,q,l,s;
1839  fpsQTMap(i,&a,&c);
1840  fpsQLSFromQT(a,c,&q,&l,&s);
1841  int id=fpsSlatId(q,l,s);
1842  fprintf(fp,"SlatId=%3d Q=%1d L=%1d S=%2d QTAddr=%2d QTch=%2d\n",
1843  i,q,l,s,a,c);
1844  if(id!=i) fprintf(fp,"Reversemap did not work!!!\n");
1845  }
1846  fprintf(fp,"QT ordered\n");
1847  for(int a=0; a<fpsMaxQTaddr(); a++){
1848  for(int c=0; c<fpsMaxQTch(); c++){
1849  int q,l,s;
1850  fpsQLSFromQT(a,c,&q,&l,&s);
1851  int id=fpsSlatId(q,l,s);
1852  fprintf(fp,"QTAddr=%2d QTch=%2d SlatId=%3d Q=%1d L=%1d S=%2d\n",
1853  a,c,id,q,l,s);
1854  }
1855  }
1856  fclose(fp);
1857  }
1858 }
1859 
1860 void StFmsDbMaker::dumpFpsGain(const Char_t* filename){
1861  FILE* fp;
1862  LOG_INFO << "Writing "<<filename<<endm;
1863  if((fp=fopen(filename,"w"))){
1864  for(int i=0; i<fpsMaxSlatId(); i++){
1865  int q,l,s;
1866  fpsQLSfromSlatId(i,&q,&l,&s);
1867  float g = fpsGain(q,l,s);
1868  fprintf(fp,"SlatId=%3d Q=%1d L=%1d S=%2d MIP=%8.3f\n",
1869  i,q,l,s,g);
1870  }
1871  fclose(fp);
1872  }
1873 }
1874 
1875 void StFmsDbMaker::dumpFpsStatus(const Char_t* filename){
1876  FILE* fp;
1877  LOG_INFO << "Writing "<<filename<<endm;
1878  if((fp=fopen(filename,"w"))){
1879  for(int i=0; i<fpsMaxSlatId(); i++){
1880  int q,l,s;
1881  fpsQLSfromSlatId(i,&q,&l,&s);
1882  int g = fpsStatus(q,l,s);
1883  fprintf(fp,"SlatId=%3d Q=%1d L=%1d S=%2d Status=%d\n",
1884  i,q,l,s,g);
1885  }
1886  fclose(fp);
1887  }
1888 }
1889 
1890 Int_t StFmsDbMaker::fpostNQuad() {if(mFpostConstant) {return mFpostConstant->nQuad;} else {return 0;}}
1891 Int_t StFmsDbMaker::fpostNLayer() {if(mFpostConstant) {return mFpostConstant->nLayer;} else {return 0;}}
1892 Int_t StFmsDbMaker::fpostMaxSlat() {if(mFpostConstant) {return mFpostConstant->maxSlat;} else {return 0;}}
1893 Int_t StFmsDbMaker::fpostMaxQTaddr() {if(mFpostConstant) {return mFpostConstant->maxQTaddr;} else {return 0;}}
1894 Int_t StFmsDbMaker::fpostMaxQTch() {if(mFpostConstant) {return mFpostConstant->maxQTch;} else {return 0;}}
1895 Int_t StFmsDbMaker::fpostMaxSlatId() {if(mFpostConstant) {return mFpostMaxSlatId;} else {return 0;}}
1896 
1897 Int_t StFmsDbMaker::fpostNSlat(int quad, int layer) {
1898  if(quad>0 && quad<=fpostNQuad() && layer>0 && layer<=fpostNLayer()) return mFpostChannelGeometry[quad-1][layer-1].nslat;
1899  return 0;
1900 }
1901 
1902 void StFmsDbMaker::fpostQLSfromSlatId(int slatid, int* quad, int* layer, int* slat){
1903  if(slatid>=0 && slatid<fpostMaxSlatId()){
1904  *quad =mFpostSlatId[slatid].quad;
1905  *layer=mFpostSlatId[slatid].layer;
1906  *slat =mFpostSlatId[slatid].slat;
1907  }else{
1908  *quad=0; *layer=0; *slat=0;
1909  }
1910 }
1911 
1912 Int_t StFmsDbMaker::fpostSlatId(int quad, int layer, int slat) {
1913  if(quad>0 && quad<=fpostNQuad() && layer>0 && layer<=fpostNLayer() && slat>0 && slat<=fpostMaxSlat()){
1914  return mFpostReverseSlatId[quad-1][layer-1][slat-1];
1915  }
1916  return -1;
1917 }
1918 
1919 Int_t StFmsDbMaker::fpostSlatIdFromG2t(int g2tvolid){
1920  int q = (g2tvolid/1000)%10;
1921  int l = (g2tvolid/100)%10;
1922  int s = g2tvolid%100;
1923  return fpostSlatId(q,l,s);
1924 }
1925 
1926 void StFmsDbMaker::fpostPosition(int slatid, float xyz[3], float dxyz[3], float *angle){
1927  if(slatid>=0 && slatid<fpostMaxSlatId()){
1928  xyz[0]=mFpostPosition[slatid].xoffset;
1929  xyz[1]=mFpostPosition[slatid].yoffset;
1930  xyz[2]=mFpostPosition[slatid].zoffset;
1931  dxyz[0]=mFpostPosition[slatid].length;
1932  dxyz[1]=mFpostPosition[slatid].width;
1933  dxyz[2]=mFpostPosition[slatid].thickness;
1934  *angle=mFpostPosition[slatid].angle_xy;
1935  return;
1936  }
1937  memset(xyz,0,sizeof(*xyz));
1938  memset(dxyz,0,sizeof(*dxyz));
1939  *angle=0.0;
1940 }
1941 
1942 void StFmsDbMaker::fpostPosition(int quad, int layer, int slat, float xyz[3], float dxyz[3], float* angle){
1943  fpostPosition(fpostSlatId(quad,layer,slat),xyz,dxyz,angle);
1944 }
1945 
1946 void StFmsDbMaker::fpostQTMap(int slatid, int* QTaddr, int* QTch){
1947  if(slatid>=0 && slatid<fpostMaxSlatId()){
1948  *QTaddr=mFpostMap[slatid].QTaddr;
1949  *QTch=mFpostMap[slatid].QTch;
1950  return;
1951  }
1952  *QTaddr=-1;
1953  *QTch=-1;
1954 }
1955 
1956 Int_t StFmsDbMaker::fpostSlatidFromQT(int QTaddr, int QTch){
1957  if(QTaddr>=0 && QTaddr<fpostMaxQTaddr() && QTch>=0 && QTch<fpostMaxQTch()){
1958  return mFpostReverseMap[QTaddr][QTch];
1959  }
1960  return -1;
1961 }
1962 
1963 void StFmsDbMaker::fpostQLSFromQT(int QTaddr, int QTch, int* quad, int* layer, int* slat){
1964  int slatid=fpostSlatidFromQT(QTaddr,QTch);
1965  fpostQLSfromSlatId(slatid,quad,layer,slat);
1966 }
1967 
1968 Float_t StFmsDbMaker::fpostGain(int slatid){
1969  if(slatid>=0 && slatid<fpostMaxSlatId()) return mFpostGain[slatid].MIP;
1970  return 0.0;
1971 }
1972 
1973 Float_t StFmsDbMaker::fpostGain(int quad, int layer, int slat){
1974  return fpostGain(fpostSlatId(quad,layer,slat));
1975 }
1976 
1977 Float_t StFmsDbMaker::fpostMipSigma(int slatid){
1978  if(slatid>=0 && slatid<fpostMaxSlatId()) return mFpostGain[slatid].Sigma;
1979  return 0.0;
1980 }
1981 
1982 Float_t StFmsDbMaker::fpostMipSigma(int quad, int layer, int slat){
1983  return fpostMipSigma(fpostSlatId(quad,layer,slat));
1984 }
1985 
1986 Float_t StFmsDbMaker::fpostValley(int slatid){
1987  if(slatid>=0 && slatid<fpostMaxSlatId()) return mFpostGain[slatid].Valley;
1988  return 0.0;
1989 }
1990 
1991 Float_t StFmsDbMaker::fpostValley(int quad, int layer, int slat){
1992  return fpostValley(fpostSlatId(quad,layer,slat));
1993 }
1994 
1995 UShort_t StFmsDbMaker::fpostStatus(int slatid){
1996  if(slatid>=0 && slatid<fpostMaxSlatId()) return mFpostStatus[slatid].status;
1997  return 999;
1998 }
1999 
2000 UShort_t StFmsDbMaker::fpostStatus(int quad, int layer, int slat){
2001  return fpostStatus(fpostSlatId(quad,layer,slat));
2002 }
2003 
2004 void StFmsDbMaker::dumpFpostConstant(const Char_t* filename){
2005  FILE* fp;
2006  LOG_INFO << "Writing "<<filename<<endm;
2007  if((fp=fopen(filename,"w"))){
2008  fprintf(fp,"nQuad = %d\n",fpostNQuad());
2009  fprintf(fp,"nLayer = %d\n",fpostNLayer());
2010  fprintf(fp,"maxSlat = %d\n",fpostMaxSlat());
2011  fprintf(fp,"maxQTAddr = %d\n",fpostMaxQTaddr());
2012  fprintf(fp,"maxQTch = %d\n",fpostMaxQTch());
2013  fprintf(fp,"maxSlatId = %d\n",fpostMaxSlatId());
2014  fclose(fp);
2015  }
2016 }
2017 
2018 void StFmsDbMaker::dumpFpostChannelGeometry (const Char_t* filename){
2019  FILE* fp;
2020  LOG_INFO << "Writing "<<filename<<endm;
2021  if((fp=fopen(filename,"w"))){
2022  for(int q=1; q<=fpostNQuad(); q++){
2023  for(int l=1; l<=fpostNLayer(); l++){
2024  fprintf(fp,"Q=%1d L=%1d NSlat=%2d\n",q,l,fpostNSlat(q,l));
2025  }
2026  }
2027  fclose(fp);
2028  }
2029 }
2030 
2031 void StFmsDbMaker::dumpFpostSlatId (const Char_t* filename){
2032  FILE* fp;
2033  LOG_INFO << "Writing "<<filename<<endm;
2034  if((fp=fopen(filename,"w"))){
2035  for(int i=0; i<fpostMaxSlatId(); i++){
2036  int q,l,s,id;
2037  fpostQLSfromSlatId(i,&q,&l,&s);
2038  id=fpostSlatId(q,l,s);
2039  fprintf(fp,"SlatId=%3d Q=%1d L=%1d S=%2d Reversemap=%3d\n",i,q,l,s,id);
2040  if(i!=id) fprintf(fp,"Reversemap did not work!!!\n");
2041  }
2042  fclose(fp);
2043  }
2044 }
2045 
2046 void StFmsDbMaker::dumpFpostPosition(const Char_t* filename){
2047  FILE* fp;
2048  LOG_INFO << "Writing "<<filename<<endm;
2049  if((fp=fopen(filename,"w"))){
2050  for(int i=0; i<fpostMaxSlatId(); i++){
2051  int q,l,s;
2052  float x[3],d[3],angle;
2053  fpostQLSfromSlatId(i,&q,&l,&s);
2054  fpostPosition(q,l,s,x,d,&angle);
2055  fprintf(fp,"SlatId=%3d Q=%1d L=%1d S=%2d xyz=%8.3f %8.3f %8.3f dxyz=%8.3f %8.3f %8.3f Angle=%8.3f\n",
2056  i,q,l,s,x[0],x[1],x[2],d[0],d[1],d[2],angle);
2057  }
2058  fclose(fp);
2059  }
2060 }
2061 
2062 void StFmsDbMaker::dumpFpostMap(const Char_t* filename){
2063  FILE* fp;
2064  LOG_INFO << "Writing "<<filename<<endm;
2065  if((fp=fopen(filename,"w"))){
2066  fprintf(fp,"SlatId ordered\n");
2067  for(int i=0; i<fpostMaxSlatId(); i++){
2068  int a,c,q,l,s;
2069  fpostQTMap(i,&a,&c);
2070  fpostQLSFromQT(a,c,&q,&l,&s);
2071  int id=fpostSlatId(q,l,s);
2072  fprintf(fp,"SlatId=%3d Q=%1d L=%1d S=%2d QTAddr=%2d QTch=%2d\n",
2073  i,q,l,s,a,c);
2074  if(id!=i) fprintf(fp,"Reversemap did not work!!!\n");
2075  }
2076  fprintf(fp,"QT ordered\n");
2077  for(int a=0; a<fpostMaxQTaddr(); a++){
2078  for(int c=0; c<fpostMaxQTch(); c++){
2079  int q,l,s;
2080  fpostQLSFromQT(a,c,&q,&l,&s);
2081  int id=fpostSlatId(q,l,s);
2082  fprintf(fp,"QTAddr=%2d QTch=%2d SlatId=%3d Q=%1d L=%1d S=%2d\n",
2083  a,c,id,q,l,s);
2084  }
2085  }
2086  fclose(fp);
2087  }
2088 }
2089 
2090 void StFmsDbMaker::dumpFpostGain(const Char_t* filename){
2091  FILE* fp;
2092  LOG_INFO << "Writing "<<filename<<endm;
2093  if((fp=fopen(filename,"w"))){
2094  for(int i=0; i<fpostMaxSlatId(); i++){
2095  int q,l,s;
2096  fpostQLSfromSlatId(i,&q,&l,&s);
2097  float g = fpostGain(q,l,s);
2098  fprintf(fp,"SlatId=%3d Q=%1d L=%1d S=%2d MIP=%8.3f\n",
2099  i,q,l,s,g);
2100  }
2101  fclose(fp);
2102  }
2103 }
2104 
2105 void StFmsDbMaker::dumpFpostStatus(const Char_t* filename){
2106  FILE* fp;
2107  LOG_INFO << "Writing "<<filename<<endm;
2108  if((fp=fopen(filename,"w"))){
2109  for(int i=0; i<fpostMaxSlatId(); i++){
2110  int q,l,s;
2111  fpostQLSfromSlatId(i,&q,&l,&s);
2112  int g = fpostStatus(q,l,s);
2113  fprintf(fp,"SlatId=%3d Q=%1d L=%1d S=%2d Status=%d\n",
2114  i,q,l,s,g);
2115  }
2116  fclose(fp);
2117  }
2118 }
2119 
2120 Int_t StFmsDbMaker::nCellHole(Int_t det){
2121  switch(det){
2122  case kFmsNorthLargeDetId:
2123  case kFmsSouthLargeDetId: return 8;
2124  case kFmsNorthSmallDetId:
2125  case kFmsSouthSmallDetId: return 5;
2126  default: return 0;
2127  }
2128 }
2129 
2130 Int_t StFmsDbMaker::nCellCorner(Int_t det){
2131  switch(det){
2132  case kFmsNorthLargeDetId:
2133  case kFmsSouthLargeDetId: return 7;
2134  default: return 0;
2135  }
2136 }
2137 
2138 Float_t StFmsDbMaker::distanceFromEdge(StFmsPoint* point, int& edge){
2139  return distanceFromEdge(point->detectorId(),point->x(),point->y(), edge);
2140 }
2141 
2142 Float_t StFmsDbMaker::distanceFromEdge(Int_t det,Float_t x, Float_t y, int& edge){
2143  //Input x/y should be local coordinate in cm, NOT STAR coordinate
2144  // x=0 is closest to beam edge, and x=nColumn(det) is far from beam edge
2145  // y=0 is bottom edge, and y=nRow(det) is top edge
2146  //Return value is distance from edge in cell width unit
2147  // negative is inside detector, positive is outside
2148  // typical fiducail volume cut would be distance<-0.5.
2149  // Return int edge is 0=inside detector, 1=inner edge, 2=outer, 3=north south gap, 4=large/small edge, 5=corner
2150  edge=-1;
2151  if(det<kFmsNorthLargeDetId || det>kFmsSouthSmallDetId) return -99.0;
2152  //convert input float(x/y) to int(column/row) space
2153  //for row#, subtract nRow/2 so 0 is at beam, and take abs to work on a quadrant
2154  float xx=x/getXWidth(det);
2155  float yy=abs(y/getYWidth(det) - nRow(det)/2.0);
2156  int column=int(xx);
2157  int row=int(yy);
2158  if(column<=0){
2159  if(row>nCellHole(det) && row<nRow(det)/2-1){ //north-south gap
2160  edge=3;
2161  return -xx;
2162  }
2163  if((row==nCellHole(det)) && ((yy-nCellHole(det))>xx) ){ //has to do diagonal cut for edge
2164  edge=3;
2165  return -xx;
2166  }
2167  if( (row==(nRow(det)/2-1)) && ((nRow(det)/2-yy)>xx) ){ //has to do diagonal cut for edge
2168  edge=3;
2169  return -xx;
2170  }
2171  }
2172  if(row>=nRow(det)/2-1.0){ //top or bottom edge
2173  if(largeSmall(det)==0) {edge=2;}
2174  else {edge=4;}
2175  return yy - nRow(det)/2;
2176  }
2177  if(column>=nColumn(det)-1.0){ //far from beam edge
2178  if(largeSmall(det)==0) {edge=2;}
2179  else {edge=4;}
2180  return xx - nColumn(det);
2181  }
2182  if(xx>yy && column<=nCellHole(det)){ //edge inner hole at side
2183  if(largeSmall(det)==0) {edge=4;}
2184  else {edge=1;}
2185  return nCellHole(det)-xx;
2186  }
2187  if(xx<yy && row<=nCellHole(det)) { //edge to inner hole below/above beam pipe
2188  if(largeSmall(det)==0) {edge=4;}
2189  else {edge=1;}
2190  return nCellHole(det)-yy;
2191  }
2192  if(largeSmall(det)==0 && xx+yy>=nRow(det)-nCellCorner(det)-2.0){ //corner for large cell
2193  edge=5;
2194  //approximation... just diagonal cut
2195  // not doing distance from zigzag for now... maybe later
2196  return xx + yy - (nRow(det)-nCellCorner(det)-1.0);
2197  }
2198  //more than 1 cell inside
2199  edge=0;
2200  return -1.0;
2201 }
2202 
2204  // Calculate a 4 momentum from a direction/momentum vector and energy assuming zero mass i.e. E =p
2205  // Taking into account beamline offsets and angles from DB
2206  TDataSet* dbDataSet = GetChain()->GetDataBase("Calibrations/rhic/vertexSeed");
2207  if(dbDataSet){
2208  vertexSeed_st* vSeed = ((St_vertexSeed*) (dbDataSet->FindObject("vertexSeed")))->GetTable();
2209  if(vSeed){
2210  double Vx = vSeed->x0;
2211  double Vy = vSeed->y0;
2212  double Vdxdz = vSeed->dxdz;
2213  double Vdydz = vSeed->dydz;
2214  //Vdxdz = -0.01; //hack for debug
2215  //Vdydz = -0.01;
2216  double thetaX = TMath::ATan( Vdxdz );
2217  double thetaY = TMath::ATan( Vdydz );
2218  StThreeVectorF xyznew(xyz.x()-Vx,xyz.y()-Vy,xyz.z());
2219  xyznew.rotateX(+thetaY);
2220  xyznew.rotateY(-thetaX);
2221 
2222  /*
2223  if(1){
2224  LOG_INFO << Form("vx=%6.3f vy=%6.3f dxdz=%8.5f dydz=%8.5f",Vx,Vy,Vdxdz,Vdydz) <<endm;
2225  LOG_INFO << Form("old px=%6.3f py=%6.3f pz=%6.3f",xyz.x(),xyz.y(),xyz.z()) <<endm;
2226  LOG_INFO << Form("new px=%6.3f py=%6.3f pz=%6.3f",xyznew.x(),xyznew.y(),xyznew.z()) <<endm;
2227  }
2228  */
2229 
2230  //With both dxdz=dydz=-0.01, positive x/y should get larger since beamline is pointing negative x/y at +z
2231  // StFmsPointMaker:INFO - vx= 0.096 vy=-0.272 dxdz=-0.01000 dydz=-0.01000
2232  // StFmsPointMaker:INFO - old px=26.820 py=61.350 pz=733.800
2233  // StFmsPointMaker:INFO - new px=34.054 py=68.957 pz=732.843
2234  //So... rotateX(+thetaY); and rotateY(-thetaX) is correct!
2235 
2236  StThreeVectorF mom3 = xyznew.unit() * energy;
2237  return StLorentzVectorF(mom3, energy);
2238  }
2239  }
2240  //no beamline from DB. Just assume no offsets/angles
2241  StThreeVectorF mom3 = xyz.unit() * energy; // Momentum vector with m = 0
2242  return StLorentzVectorF(mom3, energy);
2243 }
Int_t detectorId(Int_t ew, Int_t ns, Int_t type)
maximum value of detector Id
Float_t getGainCorrection(Int_t detectorId, Int_t ch) const
get the gain for the channel
Int_t maxMap()
fmsMap related
UShort_t maxDetectorId()
Utility functions related to FMS ChannelGeometry.
virtual Int_t Make()
Float_t getXWidth(Int_t detectorId)
get the offset of the detector
Int_t getChannelNumber(Int_t detectorId, Int_t row, Int_t column)
get the column number for the channel
Int_t maxNS()
fmsQTMap related
virtual Int_t Finish()
void setDebug(Int_t debug)
debug mode, 0 for minimal message, &gt;0 for more debug messages
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StMaker.cxx:634
StThreeVectorF getStarXYZfromColumnRow(Int_t detectorId, Float_t column, Float_t row)
get the STAR frame coordinates from column/row
float getTimeDepCorr(int event, int det, int ch)
force bit shift to be read from FmsBitShiftGain.txt
StThreeVectorF getDetectorOffset(Int_t detectorId)
get the channel number
fmsDetectorPosition_st * DetectorPosition()
getting the whole table
Int_t type(Int_t detectorId)
large or small cells for FMS
StLorentzVectorF getLorentzVector(const StThreeVectorF &xyz, Float_t energy)
get the STAR frame pseudo rapidity from the vertex from local X/Y [cm]
Int_t largeSmall(Int_t detectorId)
north or south side
Int_t getRowNumber(Int_t detectorId, Int_t ch)
maximum number of channels
Int_t nRow(Int_t detectorId)
type of the detector
StThreeVectorF getStarXYZ(Int_t detectorId, Float_t FmsX, Float_t FmsY)
get the Y width of the cell
Int_t getColumnNumber(Int_t detectorId, Int_t ch)
get the row number for the channel
void dumpFmsChannelGeometry(const Char_t *filename="dumpFmsChannelGeometry.txt")
text dump for debugging
Float_t distanceFromEdge(Int_t det, Float_t x, Float_t y, int &edge)
get 4 vector assuing m=0 and taking beamline from DB
Int_t northSouth(Int_t detectorId)
east or west to the STAR IP
Int_t fpsNQuad()
FPS related.
Short_t getBitShiftGain(Int_t detectorId, Int_t ch) const
get the gain correction for the channel
unsigned short getCorrectedAdc(unsigned short detectorId, unsigned short ch, unsigned short adc) const
get the bit shift gain for the channel
UShort_t maxChannel(Int_t detectorId) const
number of column
Float_t getYWidth(Int_t detectorId)
get the X width of the cell
Int_t fpostNQuad()
FPost related.
Float_t getEta(Int_t detectorId, Float_t FmsX, Float_t FmsY, Float_t Vertex)
get the STAR frame phi angle from from local X/Y [cm]
Definition: Stypes.h:40
Int_t eastWest(Int_t detectorId)
convert to detector Id
Int_t maxGain()
fmsGain/GainCorrection/Bitshift related
Float_t getPhi(Int_t detectorId, Float_t FmsX, Float_t FmsY)
get the STAR frame cooridnates for center of the cell
virtual Int_t InitRun(Int_t runNumber)
Int_t nColumn(Int_t detectorId)
number of rows
Int_t maxModule()
fmsPatchPanelMap related
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362
fmsChannelGeometry_st * ChannelGeometry()
getting the whole table