StFms  0.0.0
FMS software in the STAR framework
StFmsDbMaker.cxx
Go to the documentation of this file.
1 /***************************************************************************
2  * $Id: StFmsDbMaker.cxx,v 1.3 2011/01/13 02:56:34 jgma 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.3 2011/01/13 02:56:34 jgma
12  * Fixed bug in function nRow and nColumn
13  *
14  * Revision 1.2 2010/01/11 20:35:30 jgma
15  * Added reversed map and some other minor updates
16  *
17  * Revision 1.1 2009/10/28 16:11:15 jgma
18  * This is the first check in of the code.
19  *
20  **************************************************************************/
21 
22 
23 #include "StFmsDbMaker.h"
24 #include "St_db_Maker/St_db_Maker.h"
25 #include "StMessMgr.h"
26 #include "tables/St_fmsDetectorPosition_Table.h"
27 #include "tables/St_fmsChannelGeometry_Table.h"
28 #include "tables/St_fmsMap_Table.h"
29 #include "tables/St_fmsPatchPanelMap_Table.h"
30 #include "tables/St_fmsQTMap_Table.h"
31 #include "tables/St_fmsGain_Table.h"
32 #include "tables/St_fmsGainCorrection_Table.h"
34 
36 
37 StFmsDbMaker::StFmsDbMaker(const Char_t *name) : StMaker(name), mDebug(0),mChannelGeometry(0),mDetectorPosition(0),mMap(0),mmMap(0),mPatchPanelMap(0),
38  mQTMap(0),mGain(0),mmGain(0),mGainCorrection(0),mmGainCorrection(0){gStFmsDbMaker = this;}
39 StFmsDbMaker::~StFmsDbMaker() {deleteArrays(); gStFmsDbMaker = 0;}
40 Int_t StFmsDbMaker::Init(){LOG_DEBUG<<"StFmsDbMaker Init Start"<<endm; return StMaker::Init();}
41 Int_t StFmsDbMaker::Make(){LOG_DEBUG<<"StFmsDbMaker Make"<<endm; return kStOK;}
42 void StFmsDbMaker::Clear(const Char_t*){LOG_DEBUG<<"StFmsDbMaker Clear"<<endm; StMaker::Clear();}
43 Int_t StFmsDbMaker::Finish(){LOG_DEBUG<<"StFmsDbMaker Finish"<<endm; return kStOK;}
44 
45 Int_t StFmsDbMaker::InitRun(Int_t runNumber) {
46  LOG_DEBUG << "StFmsDbMaker::InitRun - run = " << runNumber << endm;
47  deleteArrays();
48 
50  if(mDebug>0) {
51  St_db_Maker* dbmaker = (St_db_Maker*)GetMaker("db");
52  LOG_INFO << "StFmsDbMaker::InitRun - Date&time from St_db_Maker="<<dbmaker->GetDate()<<","<< dbmaker->GetTime() << endm;
53  }
54 
55  TDataSet *DBgeom = 0;
56  TDataSet *DBmapping = 0;
57  TDataSet *DBcalibration = 0;
58  DBgeom = GetInputDB("Geometry/fms");
59  DBmapping = GetInputDB("Calibrations/fms/mapping");
60  DBcalibration= GetInputDB("Calibrations/fms");
61  if(!DBgeom) {LOG_ERROR << "StFmsDbMaker::InitRun - No Geometry/fms"<<endm; return kStFatal;}
62  if(!DBmapping) {LOG_ERROR << "StFmsDbMaker::InitRun - No Calibration/fms/mapping"<<endm; return kStFatal;}
63  if(!DBcalibration) {LOG_ERROR << "StFmsDbMaker::InitRun - No Calibration/fms"<<endm; return kStFatal;}
64 
66  St_fmsChannelGeometry *dbChannelGeometry = 0;
67  St_fmsDetectorPosition *dbDetectorPosition = 0;
68  St_fmsMap *dbMap = 0;
69  St_fmsPatchPanelMap *dbPatchPanelMap = 0;
70  St_fmsQTMap *dbQTMap = 0;
71  St_fmsGain *dbGain = 0;
72  St_fmsGainCorrection *dbGainCorrection = 0;
73  dbChannelGeometry = (St_fmsChannelGeometry*) DBgeom->Find("fmsChannelGeometry");
74  dbDetectorPosition = (St_fmsDetectorPosition*) DBgeom->Find("fmsDetectorPosition");
75  dbMap = (St_fmsMap*) DBmapping->Find("fmsMap");
76  dbPatchPanelMap = (St_fmsPatchPanelMap*) DBmapping->Find("fmsPatchPanelMap");
77  dbQTMap = (St_fmsQTMap*) DBmapping->Find("fmsQTMap");
78  dbGain = (St_fmsGain*) DBcalibration->Find("fmsGain");
79  dbGainCorrection = (St_fmsGainCorrection*) DBcalibration->Find("fmsGainCorrection");
80  if(!dbChannelGeometry){LOG_ERROR << "StFmsDbMaker::InitRun - No Geometry/fms/fmsChannelGeometry" <<endm; return kStFatal;}
81  if(!dbDetectorPosition){LOG_ERROR << "StFmsDbMaker::InitRun - No Geometry/fms/fmsDetectorPosition" <<endm; return kStFatal;}
82  if(!dbMap) {LOG_ERROR << "StFmsDbMaker::InitRun - No Calibration/fms/mapping/fmsMap" <<endm; return kStFatal;}
83  if(!dbPatchPanelMap) {LOG_ERROR << "StFmsDbMaker::InitRun - No Calibration/fms/mapping/fmsPatchPanelMap"<<endm; return kStFatal;}
84  if(!dbQTMap) {LOG_ERROR << "StFmsDbMaker::InitRun - No Calibration/fms/mapping/fmsQTMap" <<endm; return kStFatal;}
85  if(!dbGain) {LOG_ERROR << "StFmsDbMaker::InitRun - No Calibration/fms/fmsGain" <<endm; return kStFatal;}
86  if(!dbGainCorrection) {LOG_ERROR << "StFmsDbMaker::InitRun - No Calibration/fms/fmsGainCorrection" <<endm; return kStFatal;}
87 
89  fmsChannelGeometry_st *tChannelGeometry = 0;
90  tChannelGeometry = (fmsChannelGeometry_st*) dbChannelGeometry->GetTable();
91  Int_t max = dbChannelGeometry->GetNRows();
92  mMaxDetectorId = 0;
93  for(Int_t i=0; i<max; i++){
94  if(mMaxDetectorId < tChannelGeometry[i].detectorId) mMaxDetectorId = tChannelGeometry[i].detectorId;
95  }
96  mChannelGeometry = new fmsChannelGeometry_st[mMaxDetectorId+1];
97  memset(mChannelGeometry,0,sizeof(fmsChannelGeometry_st)*(mMaxDetectorId+1));
98  for(Int_t i=0; i<max; i++){
99  memcpy(&mChannelGeometry[tChannelGeometry[i].detectorId], &tChannelGeometry[i], sizeof(fmsChannelGeometry_st));
100  }
101  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Geometry/fms/fmsChannelGeometry with maxDetectorId = "<<mMaxDetectorId<< endm;
102 
104  fmsDetectorPosition_st *tDetectorPosition = 0;
105  tDetectorPosition = (fmsDetectorPosition_st*) dbDetectorPosition->GetTable();
106  mDetectorPosition = new fmsDetectorPosition_st[mMaxDetectorId+1];
107  memset(mDetectorPosition,0,sizeof(fmsDetectorPosition_st)*(mMaxDetectorId+1));
108  max = dbDetectorPosition->GetNRows();
109  for(Int_t i=0; i<max; i++){
110  memcpy(&mDetectorPosition[tDetectorPosition[i].detectorId], &tDetectorPosition[i], sizeof(fmsDetectorPosition_st));
111  }
112  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Geometry/fms/fmsDetectorPosition with "<<max<<" detectors"<< endm;
113 
115  mPatchPanelMap = (fmsPatchPanelMap_st*) dbPatchPanelMap->GetTable();
116  mMaxModule = dbPatchPanelMap->GetNRows();
118  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Calibration/fms/mapping/fmsPatchPanelMap with mMaxModule = "<<mMaxModule<< endm;
119 
121  mQTMap = (fmsQTMap_st*) dbQTMap->GetTable();
122  mMaxNS = dbQTMap->GetNRows();
123  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Calibration/fms/mapping/fmsQTMap with mMaxNS = "<<mMaxNS<< endm;
124 
126  mMap = (fmsMap_st*) dbMap->GetTable();
127  mMaxMap = dbMap->GetNRows();
128  mmMap = new fmsMap_st* [mMaxDetectorId+1];
129  memset(mmMap,0,sizeof(fmsMap_st*)*(mMaxDetectorId+1));
131  memset(mReverseMapChannel,0,sizeof(mReverseMapChannel));
132  for(Int_t i=0; i<mMaxMap; i++){
133  Int_t d=mMap[i].detectorId;
134  Int_t c=mMap[i].ch;
135  if(d<0 || d>mMaxDetectorId){
136  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/mapping/fmsMap detectorId="<<d<<" exceed max="<<mMaxDetectorId<<endm;
137  return kStFatal;
138  }
139  if(c<1 || c>maxChannel(d)){
140  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/mapping/fmsMap ch="<<c<<" exceed max="<<maxChannel(d)<<endm;
141  return kStFatal;
142  }
143  if(mmMap[d]==0){
144  mmMap[d] = new fmsMap_st [maxChannel(d)];
145  memset(mmMap[d],0,sizeof(fmsMap_st)*maxChannel(d));
146  }
147  memcpy(&mmMap[d][c-1],&mMap[i],sizeof(fmsMap_st));
148  //creating reverse mapping
149  Int_t crt,slot,ch;
150  getMap(d,c,&crt,&slot,&ch);
151  mReverseMapDetectorId[crt][slot][ch]=d;
152  mReverseMapChannel[crt][slot][ch]=c;
153  }
154 
155  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Geometry/fms/mapping/fmsMap with mMaxMap = "<<mMaxMap<< endm;
156 
158  mGain = (fmsGain_st*) dbGain->GetTable();
159  mMaxGain = dbGain->GetNRows();
160  mmGain = new fmsGain_st* [mMaxDetectorId+1];
161  memset(mmGain,0,sizeof(fmsGain_st*)*(mMaxDetectorId+1));
162  for(Int_t i=0; i<mMaxGain; i++){
163  Int_t d=mGain[i].detectorId;
164  Int_t c=mGain[i].ch;
165  if(maxChannel(d)<1){
166  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsGain invalid max number of channel = "<<maxChannel(d)<<endm;
167  continue;
168  }
169  if(d<0 || d>mMaxDetectorId){
170  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsGain detectorId="<<d<<" exceed max = "<<mMaxDetectorId<<endm;
171  continue;
172  }
173  if(c<1 || c>maxChannel(d)){
174  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsGain detectorId="<<d<<" ch="<<c<<" exceed max = "<<maxChannel(d)<<endm;
175  continue;
176  }
177  if(mmGain[d]==0){
178  mmGain[d] = new fmsGain_st [maxChannel(d)];
179  memset(mmGain[d],0,sizeof(fmsGain_st)*maxChannel(d));
180  }
181  memcpy(&mmGain[d][c-1],&mGain[i],sizeof(fmsGain_st));
182  }
183  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Calibration/fms/fmsGain with mMaxGain = "<<mMaxGain<< endm;
184 
186  mGainCorrection = (fmsGainCorrection_st*) dbGainCorrection->GetTable();
187  mMaxGainCorrection = dbGainCorrection->GetNRows();
188  mmGainCorrection = new fmsGainCorrection_st* [mMaxDetectorId+1];
189  memset(mmGainCorrection,0,sizeof(fmsGainCorrection_st*)*(mMaxDetectorId+1));
190  for(Int_t i=0; i<mMaxGainCorrection; i++){
191  Int_t d=mGainCorrection[i].detectorId;
192  Int_t c=mGainCorrection[i].ch;
193  if(maxChannel(d)<1){
194  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsGainCorrection invalid max number of channel = "<<maxChannel(d)<<endm;
195  continue;
196  }
197  if(d<0 || d>mMaxDetectorId){
198  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsGainCorrection detectorId="<<d<<" exceed max="<<mMaxDetectorId<<endm;
199  continue;
200  }
201  if(c<1 || c>maxChannel(d)){
202  LOG_ERROR << "StFmsDbMaker::InitRun - Calibration/fms/fmsGainCorrection ch="<<c<<" exceed max="<<maxChannel(d)<<endm;
203  continue;
204  }
205  if(mmGainCorrection[d]==0){
206  mmGainCorrection[d] = new fmsGainCorrection_st [maxChannel(d)];
207  memset(mmGainCorrection[d],0,sizeof(fmsGainCorrection_st)*maxChannel(d));
208  }
209  memcpy(&mmGainCorrection[d][c-1],&mGainCorrection[i],sizeof(fmsGainCorrection_st));
210  }
211  LOG_DEBUG << "StFmsDbMaker::InitRun - Got Geometry/fms/fmsGainCorrection with mMaxGainCorrection = "<<mMaxGainCorrection<< endm;
212 
214  if(mDebug>0){
217  dumpFmsMap();
219  dumpFmsQTMap();
220  dumpFmsGain();
222  }
223  return kStOK;
224 }
225 
227  if(mChannelGeometry) delete [] mChannelGeometry;
228  if(mDetectorPosition) delete [] mDetectorPosition;
229  if(mmMap){
230  for(Int_t d=0; d<=mMaxDetectorId; d++){
231  if(mmMap[d]) delete [] mmMap[d];
232  }
233  delete [] mmMap;
234  }
235 
236  if(mmGain){
237  for(Int_t d=0; d<=mMaxDetectorId; d++){
238  if(mmGain[d]) delete [] mmGain[d];
239  }
240  delete [] mmGain;
241  }
242  if(mmGainCorrection){
243  for(Int_t d=0; d<=mMaxDetectorId; d++){
244  if(mmGainCorrection[d]) delete [] mmGainCorrection[d];
245  }
246  delete [] mmGainCorrection;
247  }
248 }
249 
251 StThreeVectorF StFmsDbMaker::getStarXYZ(Int_t detectorId,Float_t FmsX, Float_t FmsY)
252 {
253  Float_t x = 0;
254  Float_t y = 0;
255  Float_t z = 0;
256  y = mDetectorPosition[detectorId].yoffset - FmsY*mDetectorPosition[detectorId].ywidth;
257  z = mDetectorPosition[detectorId].zoffset;
258  if(northSouth(detectorId) == 0)
259  x = mDetectorPosition[detectorId].xoffset - FmsX*mDetectorPosition[detectorId].xwidth;
260  else
261  x = mDetectorPosition[detectorId].xoffset + FmsX*mDetectorPosition[detectorId].xwidth;
262  return StThreeVectorF(x,y,z);
263 }
264 Float_t StFmsDbMaker::getPhi(Int_t detectorId,Float_t FmsX, Float_t FmsY){ return (getStarXYZ(detectorId,FmsX,FmsY)).phi();}
265 Float_t StFmsDbMaker::getEta(Int_t detectorId,Float_t FmsX, Float_t FmsY, Float_t Vertex) { return (getStarXYZ(detectorId,FmsX,FmsY)).pseudoRapidity();}
266 
267 void StFmsDbMaker::setDebug(Int_t debug) {mDebug = debug;}
268 
270 fmsDetectorPosition_st* StFmsDbMaker::DetectorPosition() {if(mDetectorPosition) return mDetectorPosition; return 0;}
271 fmsChannelGeometry_st* StFmsDbMaker::ChannelGeometry() {if(mChannelGeometry) return mChannelGeometry; return 0;}
272 fmsMap_st* StFmsDbMaker::Map() {if(mMap) return mMap; return 0;}
273 fmsPatchPanelMap_st* StFmsDbMaker::PatchPanelMap() {if(mPatchPanelMap) return mPatchPanelMap; return 0;}
274 fmsQTMap_st* StFmsDbMaker::QTMap() {if(mQTMap) return mQTMap; return 0;}
275 fmsGain_st* StFmsDbMaker::Gain() {if(mGain) return mGain; return 0;}
276 fmsGainCorrection_st* StFmsDbMaker::GainCorrection() {if(mGainCorrection) return mGainCorrection; return 0;}
277 
280 Int_t StFmsDbMaker::eastWest(Int_t detectorId){
281  if(detectorId>=0 && detectorId<=mMaxDetectorId && maxChannel(detectorId)>0) return mChannelGeometry[detectorId].ew;
282  else{
283  LOG_WARN<<"StFmsDbMaker::eastWest: Corresponding channel geometry not found."<<endm;
284  return -1;
285  }
286 }
287 
288 Int_t StFmsDbMaker::northSouth(Int_t detectorId){
289  if(detectorId>=0 && detectorId<=mMaxDetectorId && maxChannel(detectorId)>0) return mChannelGeometry[detectorId].ns;
290  else{
291  LOG_WARN<<"StFmsDbMaker::northSouth: Corresponding channel geometry not found."<<endm;
292  return -1;
293  }
294 }
295 
296 Int_t StFmsDbMaker::type(Int_t detectorId){
297  if(detectorId>=0 && detectorId<=mMaxDetectorId && maxChannel(detectorId)>0) return mChannelGeometry[detectorId].type;
298  else{
299  LOG_WARN<<"StFmsDbMaker::type: Corresponding channel geometry not found."<<endm;
300  return -1;
301  }
302 }
303 
304 Int_t StFmsDbMaker::nRow(Int_t detectorId){
305  if(detectorId>=0 && detectorId<=mMaxDetectorId && maxChannel(detectorId)>0) return mChannelGeometry[detectorId].nY;
306  else{
307  LOG_WARN<<"StFmsDbMaker::nRow: Corresponding channel geometry not found for detectorId = "<<detectorId<<endm;
308  return -1;
309  }
310 }
311 
312 Int_t StFmsDbMaker::nColumn(Int_t detectorId){
313  if(detectorId>=0 && detectorId<=mMaxDetectorId && maxChannel(detectorId)>0)
314  return mChannelGeometry[detectorId].nX;
315  else{
316  LOG_WARN<<"StFmsDbMaker::nColumn: Corresponding channel geometry not found."<<endm;
317  return -1;
318  }
319 }
320 
321 Int_t StFmsDbMaker::maxChannel(Int_t detectorId){
322  if(detectorId>=0 && detectorId<=mMaxDetectorId && mChannelGeometry[detectorId].nX>0)
324  else{
325  LOG_WARN<<"StFmsDbMaker::maxChannel: Corresponding channel geometry not found."<<endm;
326  return -1;
327  }
328 }
329 
330 Int_t StFmsDbMaker::detectorId(Int_t ew, Int_t ns, Int_t type){
331  for(Int_t i=0; i<=mMaxDetectorId; i++)
332  if((mChannelGeometry+i)){
333  if(mChannelGeometry[i].ew == ew && mChannelGeometry[i].ns == ns && mChannelGeometry[i].type == type)
334  return mChannelGeometry[i].detectorId;
335  }
336  LOG_WARN<<"StFmsDbMaker::detectorId: Corresponding channel geometry not found."<<endm;
337  return -1;
338 }
339 
340 Int_t StFmsDbMaker::getRowNumber(Int_t detectorId, Int_t ch){
341  if(maxChannel(detectorId)>0) return mChannelGeometry[detectorId].nY - (ch-1)/mChannelGeometry[detectorId].nX;
342  return -1;
343 }
344 
345 Int_t StFmsDbMaker::getColumnNumber(Int_t detectorId, Int_t ch){
346  if(maxChannel(detectorId)>0) return (ch-1)%mChannelGeometry[detectorId].nX + 1;
347  return -1;
348 }
349 
350 Int_t StFmsDbMaker::getChannelNumber(Int_t detectorId, Int_t row, Int_t column){
351  if(maxChannel(detectorId)>0) return column + mChannelGeometry[detectorId].nX * (mChannelGeometry[detectorId].nY - row);
352  return -1;
353 }
354 
355 StThreeVectorF StFmsDbMaker::getDetectorOffset(Int_t detectorId){
356  if(detectorId>=0 && detectorId<=mMaxDetectorId && maxChannel(detectorId)>0)
357  return StThreeVectorF(mDetectorPosition[detectorId].xoffset, mDetectorPosition[detectorId].yoffset, mDetectorPosition[detectorId].zoffset);
358  return StThreeVectorF(0, 0, 0);
359 }
360 
361 Float_t StFmsDbMaker::getXWidth(Int_t detectorId){
362  if(detectorId>=0 && detectorId<=mMaxDetectorId)
363  return mDetectorPosition[detectorId].xwidth; return -1;
364 }
365 
366 Float_t StFmsDbMaker::getYWidth(Int_t detectorId){
367  if(detectorId>=0 && detectorId<=mMaxDetectorId)
368  return mDetectorPosition[detectorId].ywidth; return -1;
369 }
370 
372 Int_t StFmsDbMaker::maxMap() {return mMaxMap;}
373 void StFmsDbMaker::getMap(Int_t detectorId, Int_t ch, Int_t* qtCrate, Int_t* qtSlot, Int_t* qtChannel){
374  if(detectorId<0 || detectorId>mMaxDetectorId || ch<1 || ch>maxChannel(detectorId) || mmMap[detectorId]==0 ){
375  *qtCrate=0; *qtSlot=0; *qtChannel=0;
376  return;
377  }
378  *qtCrate = mmMap[detectorId][ch-1].qtCrate;
379  *qtSlot = mmMap[detectorId][ch-1].qtSlot;
380  *qtChannel = mmMap[detectorId][ch-1].qtChannel;
381 }
382 void StFmsDbMaker::getReverseMap(Int_t qtCrate, Int_t qtSlot, Int_t qtChannel, Int_t* detectorId, Int_t* ch){
383  if(qtCrate==0 && qtSlot==0 && qtChannel==0) {
384  *detectorId = 0;
385  *ch = 0;
386  }else{
387  *detectorId = mReverseMapDetectorId[qtCrate][qtSlot][qtChannel];
388  *ch = mReverseMapChannel[qtCrate][qtSlot][qtChannel];
389  }
390 }
391 
394 
396 Int_t StFmsDbMaker::maxNS() {return mMaxNS;}
397 
401 Float_t StFmsDbMaker::getGain(Int_t detectorId, Int_t ch){
402  if(detectorId<0 || detectorId>mMaxDetectorId || ch<1 || ch>maxChannel(detectorId) || mmGain[detectorId]==0) return 0;
403  return mmGain[detectorId][ch-1].gain;
404 }
405 Float_t StFmsDbMaker::getGainCorrection(Int_t detectorId, Int_t ch){
406  if(detectorId<0 || detectorId>mMaxDetectorId || ch<1 || ch>maxChannel(detectorId) || mmGainCorrection[detectorId]==0) return 0;
407  return mmGainCorrection[detectorId][ch-1].corr;
408 }
409 
411 void StFmsDbMaker::dumpFmsChannelGeometry(const Char_t* filename) {
412  FILE* fp;
413  LOG_INFO << "Writing "<<filename<<endm;
414  if((fp=fopen(filename,"w"))){
415  fprintf(fp,"maxDetectorId = %d\n",maxDetectorId());
416  fprintf(fp," i detiid ew ns type nRow nCol maxCh\n");
417  for(Int_t i=0; i<mMaxDetectorId+1; i++){
418  fprintf(fp,"%5d%7d%4d%5d%5d%5d%5d%6d\n",
420  nRow(i),nColumn(i),maxChannel(i));
421  }
422  for(Int_t i=0; i<mMaxDetectorId+1; i++){
423  fprintf(fp,"DetectorId=%d\n",i);
424  fprintf(fp,"detiid ch getCh getRow getCol\n");
425  for(Int_t j=1; j<=maxChannel(i); j++){
426  fprintf(fp,"%6d%4d%8d%8d%7d\n",
428  }
429  }
430  fclose(fp);
431  }
432 }
433 
434 void StFmsDbMaker::dumpFmsDetectorPosition(const Char_t* filename) {
435  FILE* fp;
436  LOG_INFO << "Writing "<<filename<<endm;
437  if((fp=fopen(filename,"w"))){
438  fprintf(fp,"maxDetectorId = %d\n",maxDetectorId());
439  fprintf(fp," detiid zoffset xoffset yoffset xwidth ywidth\n");
440  for(Int_t i=0; i<mMaxDetectorId+1; i++)
441  if((mDetectorPosition+i))
442  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));
443  fclose(fp);
444  }
445 }
446 
447 void StFmsDbMaker::dumpFmsMap(const Char_t* filename) {
448  FILE* fp;
449  LOG_INFO << "Writing "<<filename<<endm;
450  if((fp=fopen(filename,"w"))){
451  fprintf(fp,"maxMap = %d\n",maxMap());
452  fprintf(fp," i DetId ch crt slt qtch getmap() getReverseMap\n");
453  for(Int_t i=0; i<mMaxMap; i++){
454  Int_t d=mMap[i].detectorId;
455  Int_t c=mMap[i].ch;
456  Int_t crt,slot,ch,dd,cc;
457  getMap(d,c,&crt,&slot,&ch);
458  getReverseMap(crt,slot,ch,&dd,&cc);
459  fprintf(fp,"%5d%6d%6d%5d%5d%5d%5d%5d%5d%5d%5d\n",
460  i,d,c,mMap[i].qtCrate,mMap[i].qtSlot,mMap[i].qtChannel,crt,slot,ch,dd,cc);
461  if(mMap[i].qtCrate>0 && (d-dd!=0 || c-cc!=0)) fprintf(fp,"Problem in reverse map!\n");
462  }
463  fclose(fp);
464  }
465 }
466 
467 void StFmsDbMaker::dumpFmsPatchPanelMap(const Char_t* filename) {
468  FILE* fp;
469  LOG_INFO << "Writing "<<filename<<endm;
470  if((fp=fopen(filename,"w"))){
471  fprintf(fp," mod channel ppPanel ppRow ppColumn\n");
472  for(Int_t i=0; i<mMaxModule; i++)
473  for(Int_t j=0; j<maxChannel(i+8); j++)
474  fprintf(fp,"%5d%8d%8d%6d%9d\n",i+1,j+1,mPatchPanelMap[i].ppPanel[j],mPatchPanelMap[i].ppRow[j],mPatchPanelMap[i].ppColumn[j]);
475  fclose(fp);
476  }
477 }
478 
479 void StFmsDbMaker::dumpFmsQTMap(const Char_t* filename) {
480  FILE* fp;
481  LOG_INFO << "Writing "<<filename<<endm;
482  if((fp=fopen(filename,"w"))){
483  fprintf(fp,"ns ppPanel row column crate slot channel\n");
484  for(Int_t ns=0; ns<2; ns++)
485  for(Int_t pp=0; pp<2; pp++)
486  for(Int_t row=0; row<20; row++)
487  for(Int_t col=0; col<16; col++){
488  if(mQTMap[ns].qtCrate[pp][row][col]==0 && mQTMap[ns].qtSlot[pp][row][col]==0 && mQTMap[ns].qtChannel[pp][row][col]==0)
489  fprintf(fp,"-1 -1 -1 -1 -1 -1 -1\n");
490  else
491  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],
492  mQTMap[ns].qtChannel[pp][row][col]);
493  }
494  fclose(fp);
495  }
496 }
497 
498 void StFmsDbMaker::dumpFmsGain(const Char_t* filename) {
499  FILE* fp;
500  LOG_INFO << "Writing "<<filename<<endm;
501  if((fp=fopen(filename,"w"))){
502  fprintf(fp,"maxGain = %d\n",maxGain());
503  fprintf(fp," i DetId ch gain getGain()\n");
504  for(Int_t i=0; i<mMaxGain; i++){
505  Int_t d=mGain[i].detectorId;
506  Int_t c=mGain[i].ch;
507  fprintf(fp,"%5d%6d%6d%8.3f%11.3f\n",
508  i,d,c,mGain[i].gain,getGain(d,c));
509  }
510  fclose(fp);
511  }
512 }
513 
514 void StFmsDbMaker::dumpFmsGainCorrection(const Char_t* filename) {
515  FILE* fp;
516  LOG_INFO << "Writing "<<filename<<endm;
517  if((fp=fopen(filename,"w"))){
518  fprintf(fp,"maxGainCorrection = %d\n",maxGainCorrection());
519  fprintf(fp," i DetId ch gain getGainCorrection()\n");
520  for(Int_t i=0; i<mMaxGainCorrection; i++){
521  Int_t d=mGainCorrection[i].detectorId;
522  Int_t c=mGainCorrection[i].ch;
523  fprintf(fp,"%5d%6d%6d%8.3f%21.3f\n",
524  i,d,c,mGainCorrection[i].corr,getGainCorrection(d,c));
525  }
526  fclose(fp);
527  }
528 }
529 
void getReverseMap(Int_t qtCrate, Int_t qtSlot, Int_t qtChannel, Int_t *detectorId, Int_t *ch)
fmsQTMap_st * QTMap()
fmsMap_st * Map()
virtual void Clear(const Char_t *opt)
StFmsDbMaker * gStFmsDbMaker
Int_t mReverseMapDetectorId[mMaxCrate][mMaxSlot][mMaxCh]
Definition: StFmsDbMaker.h:119
Int_t mMaxModule
patch panel map
Definition: StFmsDbMaker.h:123
Int_t nColumn(Int_t detectorId)
number of rows
virtual Int_t InitRun(Int_t runNumber)
fmsDetectorPosition_st * DetectorPosition()
getting the whole table
void dumpFmsGain(const Char_t *filename="dumpFmsGain.txt")
fmsGainCorrection_st ** mmGainCorrection
gain correction table
Definition: StFmsDbMaker.h:133
void dumpFmsMap(const Char_t *filename="dumpFmsMap.txt")
Int_t maxChannel(Int_t detectorId)
number of column
Int_t maxGainCorrection()
fmsGainCorrection_st * mGainCorrection
Definition: StFmsDbMaker.h:132
StThreeVectorF getDetectorOffset(Int_t detectorId)
get the channel number
Int_t maxNS()
fmsQTMap related
Int_t getChannelNumber(Int_t detectorId, Int_t row, Int_t column)
get the column number for the channel
Int_t detectorId(Int_t ew, Int_t ns, Int_t type)
maximum value of detector Id
Int_t getColumnNumber(Int_t detectorId, Int_t ch)
get the row number for the channel
Float_t getGainCorrection(Int_t detectorId, Int_t ch)
get the gain for the channel
Int_t maxGain()
fmsGain/GainCorrection related
void setDebug(Int_t debug)
debug mode, 0 for minimal message, >0 for more debug messages
Int_t type(Int_t detectorId)
north or south side
void dumpFmsGainCorrection(const Char_t *filename="dumpFmsGainCorrection.txt")
fmsPatchPanelMap_st * mPatchPanelMap
Definition: StFmsDbMaker.h:122
fmsMap_st * mMap
position (in STAR frame) of each detector
Definition: StFmsDbMaker.h:115
Int_t maxModule()
fmsPatchPanelMap related
Int_t mMaxGainCorrection
Definition: StFmsDbMaker.h:134
virtual ~StFmsDbMaker()
void dumpFmsPatchPanelMap(const Char_t *filename="dumpFmsPatchPanelMap.txt")
fmsMap_st ** mmMap
detector map
Definition: StFmsDbMaker.h:116
fmsChannelGeometry_st * ChannelGeometry()
getting the whole table
void deleteArrays()
ClassImp(StFmsDbMaker) StFmsDbMaker
fmsDetectorPosition_st * mDetectorPosition
max detector Id
Definition: StFmsDbMaker.h:113
fmsChannelGeometry_st * mChannelGeometry
>0 dump tables to text files
Definition: StFmsDbMaker.h:110
fmsPatchPanelMap_st * PatchPanelMap()
fmsGainCorrection_st * GainCorrection()
Int_t getRowNumber(Int_t detectorId, Int_t ch)
maximum number of channels
Float_t getYWidth(Int_t detectorId)
get the X width of the cell
fmsGain_st ** mmGain
gain table
Definition: StFmsDbMaker.h:129
virtual Int_t Init()
Float_t getEta(Int_t detectorId, Float_t FmsX, Float_t FmsY, Float_t Vertex)
get the STAR frame phi angle
Int_t mReverseMapChannel[mMaxCrate][mMaxSlot][mMaxCh]
Definition: StFmsDbMaker.h:120
Int_t nRow(Int_t detectorId)
type of the detector
virtual Int_t Make()
Float_t getPhi(Int_t detectorId, Float_t FmsX, Float_t FmsY)
get the STAR frame coordinates
Float_t getGain(Int_t detectorId, Int_t ch)
void dumpFmsChannelGeometry(const Char_t *filename="dumpFmsChannelGeometry.txt")
get the gain correction for the channel
Int_t maxMap()
get the STAR frame pseudo rapidity assuming vertex is at (0,0,0)
void dumpFmsDetectorPosition(const Char_t *filename="dumpFmsDetectorPosition.txt")
void dumpFmsQTMap(const Char_t *filename="dumpFmsQTMap.txt")
Int_t mMaxNS
Qt map.
Definition: StFmsDbMaker.h:126
fmsGain_st * Gain()
Int_t northSouth(Int_t detectorId)
east or west to the STAR IP
Int_t eastWest(Int_t detectorId)
convert to detector Id
fmsGain_st * mGain
Definition: StFmsDbMaker.h:128
Int_t maxDetectorId()
Utility functions related to FMS ChannelGeometry.
void getMap(Int_t detectorId, Int_t ch, Int_t *qtCrate, Int_t *qtSlot, Int_t *qtChannel)
Int_t mMaxDetectorId
channel configuration for each detector
Definition: StFmsDbMaker.h:111
Float_t getXWidth(Int_t detectorId)
get the offset of the detector
fmsQTMap_st * mQTMap
Definition: StFmsDbMaker.h:125
StThreeVectorF getStarXYZ(Int_t detectorId, Float_t FmsX, Float_t FmsY)
get the Y width of the cell
virtual Int_t Finish()