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"
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;}
46 LOG_DEBUG <<
"StFmsDbMaker::InitRun - run = " << runNumber << endm;
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;
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;}
66 St_fmsChannelGeometry *dbChannelGeometry = 0;
67 St_fmsDetectorPosition *dbDetectorPosition = 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;}
89 fmsChannelGeometry_st *tChannelGeometry = 0;
90 tChannelGeometry = (fmsChannelGeometry_st*) dbChannelGeometry->GetTable();
91 Int_t max = dbChannelGeometry->GetNRows();
93 for(Int_t i=0; i<max; i++){
98 for(Int_t i=0; i<max; i++){
101 LOG_DEBUG <<
"StFmsDbMaker::InitRun - Got Geometry/fms/fmsChannelGeometry with maxDetectorId = "<<
mMaxDetectorId<< endm;
104 fmsDetectorPosition_st *tDetectorPosition = 0;
105 tDetectorPosition = (fmsDetectorPosition_st*) dbDetectorPosition->GetTable();
108 max = dbDetectorPosition->GetNRows();
109 for(Int_t i=0; i<max; i++){
112 LOG_DEBUG <<
"StFmsDbMaker::InitRun - Got Geometry/fms/fmsDetectorPosition with "<<max<<
" detectors"<< endm;
115 mPatchPanelMap = (fmsPatchPanelMap_st*) dbPatchPanelMap->GetTable();
118 LOG_DEBUG <<
"StFmsDbMaker::InitRun - Got Calibration/fms/mapping/fmsPatchPanelMap with mMaxModule = "<<
mMaxModule<< endm;
121 mQTMap = (fmsQTMap_st*) dbQTMap->GetTable();
122 mMaxNS = dbQTMap->GetNRows();
123 LOG_DEBUG <<
"StFmsDbMaker::InitRun - Got Calibration/fms/mapping/fmsQTMap with mMaxNS = "<<
mMaxNS<< endm;
126 mMap = (fmsMap_st*) dbMap->GetTable();
132 for(Int_t i=0; i<
mMaxMap; i++){
133 Int_t d=
mMap[i].detectorId;
136 LOG_ERROR <<
"StFmsDbMaker::InitRun - Calibration/fms/mapping/fmsMap detectorId="<<d<<
" exceed max="<<mMaxDetectorId<<endm;
140 LOG_ERROR <<
"StFmsDbMaker::InitRun - Calibration/fms/mapping/fmsMap ch="<<c<<
" exceed max="<<
maxChannel(d)<<endm;
147 memcpy(&
mmMap[d][c-1],&
mMap[i],
sizeof(fmsMap_st));
150 getMap(d,c,&crt,&slot,&ch);
155 LOG_DEBUG <<
"StFmsDbMaker::InitRun - Got Geometry/fms/mapping/fmsMap with mMaxMap = "<<mMaxMap<< endm;
158 mGain = (fmsGain_st*) dbGain->GetTable();
163 Int_t d=
mGain[i].detectorId;
166 LOG_ERROR <<
"StFmsDbMaker::InitRun - Calibration/fms/fmsGain invalid max number of channel = "<<
maxChannel(d)<<endm;
170 LOG_ERROR <<
"StFmsDbMaker::InitRun - Calibration/fms/fmsGain detectorId="<<d<<
" exceed max = "<<mMaxDetectorId<<endm;
174 LOG_ERROR <<
"StFmsDbMaker::InitRun - Calibration/fms/fmsGain detectorId="<<d<<
" ch="<<c<<
" exceed max = "<<
maxChannel(d)<<endm;
181 memcpy(&
mmGain[d][c-1],&
mGain[i],
sizeof(fmsGain_st));
183 LOG_DEBUG <<
"StFmsDbMaker::InitRun - Got Calibration/fms/fmsGain with mMaxGain = "<<mMaxGain<< endm;
186 mGainCorrection = (fmsGainCorrection_st*) dbGainCorrection->GetTable();
194 LOG_ERROR <<
"StFmsDbMaker::InitRun - Calibration/fms/fmsGainCorrection invalid max number of channel = "<<
maxChannel(d)<<endm;
198 LOG_ERROR <<
"StFmsDbMaker::InitRun - Calibration/fms/fmsGainCorrection detectorId="<<d<<
" exceed max="<<mMaxDetectorId<<endm;
202 LOG_ERROR <<
"StFmsDbMaker::InitRun - Calibration/fms/fmsGainCorrection ch="<<c<<
" exceed max="<<
maxChannel(d)<<endm;
211 LOG_DEBUG <<
"StFmsDbMaker::InitRun - Got Geometry/fms/fmsGainCorrection with mMaxGainCorrection = "<<mMaxGainCorrection<< endm;
262 return StThreeVectorF(x,y,z);
283 LOG_WARN<<
"StFmsDbMaker::eastWest: Corresponding channel geometry not found."<<endm;
291 LOG_WARN<<
"StFmsDbMaker::northSouth: Corresponding channel geometry not found."<<endm;
299 LOG_WARN<<
"StFmsDbMaker::type: Corresponding channel geometry not found."<<endm;
307 LOG_WARN<<
"StFmsDbMaker::nRow: Corresponding channel geometry not found for detectorId = "<<detectorId<<endm;
316 LOG_WARN<<
"StFmsDbMaker::nColumn: Corresponding channel geometry not found."<<endm;
325 LOG_WARN<<
"StFmsDbMaker::maxChannel: Corresponding channel geometry not found."<<endm;
336 LOG_WARN<<
"StFmsDbMaker::detectorId: Corresponding channel geometry not found."<<endm;
358 return StThreeVectorF(0, 0, 0);
375 *qtCrate=0; *qtSlot=0; *qtChannel=0;
383 if(qtCrate==0 && qtSlot==0 && qtChannel==0) {
413 LOG_INFO <<
"Writing "<<filename<<endm;
414 if((fp=fopen(filename,
"w"))){
416 fprintf(fp,
" i detiid ew ns type nRow nCol maxCh\n");
418 fprintf(fp,
"%5d%7d%4d%5d%5d%5d%5d%6d\n",
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");
426 fprintf(fp,
"%6d%4d%8d%8d%7d\n",
427 i,j,
getChannelNumber(i,
getRowNumber(i,j),
getColumnNumber(i,j)),
getRowNumber(i,j),
getColumnNumber(i,j));
436 LOG_INFO <<
"Writing "<<filename<<endm;
437 if((fp=fopen(filename,
"w"))){
439 fprintf(fp,
" detiid zoffset xoffset yoffset xwidth ywidth\n");
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;
456 Int_t crt,slot,ch,dd,cc;
457 getMap(d,c,&crt,&slot,&ch);
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");
469 LOG_INFO <<
"Writing "<<filename<<endm;
470 if((fp=fopen(filename,
"w"))){
471 fprintf(fp,
" mod channel ppPanel ppRow ppColumn\n");
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");
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]);
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");
505 Int_t d=
mGain[i].detectorId;
507 fprintf(fp,
"%5d%6d%6d%8.3f%11.3f\n",
516 LOG_INFO <<
"Writing "<<filename<<endm;
517 if((fp=fopen(filename,
"w"))){
519 fprintf(fp,
" i DetId ch gain getGainCorrection()\n");
523 fprintf(fp,
"%5d%6d%6d%8.3f%21.3f\n",
void getReverseMap(Int_t qtCrate, Int_t qtSlot, Int_t qtChannel, Int_t *detectorId, Int_t *ch)
virtual void Clear(const Char_t *opt)
StFmsDbMaker * gStFmsDbMaker
Int_t mReverseMapDetectorId[mMaxCrate][mMaxSlot][mMaxCh]
Int_t mMaxModule
patch panel map
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
void dumpFmsMap(const Char_t *filename="dumpFmsMap.txt")
Int_t maxChannel(Int_t detectorId)
number of column
Int_t maxGainCorrection()
fmsGainCorrection_st * mGainCorrection
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
fmsMap_st * mMap
position (in STAR frame) of each detector
Int_t maxModule()
fmsPatchPanelMap related
void dumpFmsPatchPanelMap(const Char_t *filename="dumpFmsPatchPanelMap.txt")
fmsMap_st ** mmMap
detector map
fmsChannelGeometry_st * ChannelGeometry()
getting the whole table
ClassImp(StFmsDbMaker) StFmsDbMaker
fmsDetectorPosition_st * mDetectorPosition
max detector Id
fmsChannelGeometry_st * mChannelGeometry
>0 dump tables to text files
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
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]
Int_t nRow(Int_t detectorId)
type of the detector
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 northSouth(Int_t detectorId)
east or west to the STAR IP
Int_t eastWest(Int_t detectorId)
convert to detector Id
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
Float_t getXWidth(Int_t detectorId)
get the offset of the detector
StThreeVectorF getStarXYZ(Int_t detectorId, Float_t FmsX, Float_t FmsY)
get the Y width of the cell