13 #include <StMessMgr.h>
15 #include "StEmcAsciiDbMaker.h"
16 #include "StEmcRawMaker/defines.h"
18 #include <StEEmcUtil/database/StEEmcDb.h>
19 #include <StEEmcUtil/database/EEmcDbItem.h>
20 #include <StEEmcUtil/database/EEmcDbCrate.h>
24 #include "StEmcUtil/geometry/StEmcGeom.h"
25 #include "StEmcUtil/database/StBemcTables.h"
26 #include "StEmcUtil/database/StEmcDecoder.h"
41 memset(hA,0,
sizeof(hA));
52 StEmcAsciiDbMaker::~StEmcAsciiDbMaker() {
57 Int_t StEmcAsciiDbMaker::Init() {
60 mEeDb = (
StEEmcDb*)this->GetDataSet(
"StEEmcDb");
62 mGeomB = StEmcGeom::instance(
"bemc");
64 LOG_INFO << Form(
" %s::Init() setGain60Et=%d",
GetName(),mgain60Et) <<endm;
72 Int_t StEmcAsciiDbMaker::InitRun(
int runNo){
73 int yyyymmdd = this->GetDBTime().GetDate();
74 int hhmmss = this->GetDBTime().GetTime();
77 TString outPath=
"L2setup-"; outPath+=yyyymmdd;
78 printf(
"outPath=%s=\n",outPath.Data());
79 LOG_INFO <<
GetName()<<
"::InitRun() run=" <<runNo<<
" outPath="<<outPath<<endm;
86 exportBtowDb(outPath+
"/btowDb.current",runNo,yyyymmdd,hhmmss);
87 exportEtowDb(outPath+
"/etowDb.current",runNo,yyyymmdd,hhmmss);
104 void StEmcAsciiDbMaker::Clear(
const Option_t* ){
116 void StEmcAsciiDbMaker::exportBtowDb(TString fname,
int runNo,
int yyyymmdd,
int hhmmss){
117 LOG_INFO <<
GetName()<<
"::exportBtowDb start -->"<<fname<<endm;
120 const int par_maxADC=4096;
121 const float par_maxEt=60;
126 FILE *fd=fopen(fname.Data(),
"w");
128 fprintf(fd,
"# ::exportBtowDb(), time stamp: day=%d hhmmss=%06d run=R%d\n",yyyymmdd,hhmmss, runNo);
129 if(mgain60Et) fprintf(fd,
"# ideal gains(ch/GeV) set at maxEt=60 GeV\n");
130 else fprintf(fd,
"# real gains(ch/GeV) from OFL DB\n");
132 fprintf(fd,
"# see online/EmcDbAnsiC/EmcCDbItem.h for definitions\n");
133 fprintf(fd,
"#name, crate,chan, sec,sub,eta, gain, ped, thr, stat,fail, id-m-s-e, RDO\n");
137 for(softID=1; softID<=BTOWSIZE; softID++) {
147 myTable->
getStatus(BTOW, softID, status);
149 mGeomB->
getBin(softID,m,e,s);
152 mGeomB->getEta(m,e,etaF);
153 mGeomB->getPhi(m,s,phiF);
154 if( phiF<0) phiF+=2*C_PI;
161 myTable->
getCalib(BTOW, softID, 1, gain);
166 assert(fabs(etaF)<0.99);
167 int kEta=1+(int)((etaF+1.)/0.05);
169 int kPhi=24-(int)( phiF/C_PI*60.);
170 if(kPhi<0) kPhi+=120;
173 char name[10]=
"nnn", pname[100];
175 char sub=
'a'+kPhi%10;
176 sprintf(name,
"%02dt%c%02d",sec,sub,kEta);
178 hA[2]->Fill(softID,1000*kPhi+(kEta-1));
179 hA[3]->SetBinContent(kEta,kPhi+1,softID);
188 if(mgain60Et) myGain=par_maxADC/par_maxEt/cosh(etaF);
195 float ph=phiF/C_PI*180.;
196 while(ph<0) ph+=360.;
197 ((TH2F*) hA[0])->Fill(etaF,ph,myGain);
200 float thr=ped+mEeDb->getKsigOverPed()*sig;
201 sprintf(pname,
"id%04d-%03d-%d-%02d",softID,m,s,e);
202 fprintf(fd,
"%6s 0x%02x 0x%02x %2d %c %2d %8.2f %5.2f %5.2f 0x%02x 0x%02x %8s %4d\n",
203 name,CR,CHAN,sec,sub,kEta,myGain,ped,thr,stat,fail,pname,RDO);
208 LOG_INFO << Form(
"exportBtowDb -->%s ,nTw=%d nNotFail=%d nGoodGain=%d",fname.Data(),nA,nB,nC) <<endm;
210 #if 0 // tmp, somehow HList does not write, fix it
211 TString outName=
"btowMap.hist.root";
212 TFile f( outName,
"recreate");
214 printf(
"BTOW map histos are written to '%s' ...\n",outName.Data());
226 void StEmcAsciiDbMaker::exportEtowDb(TString fname,
int runNo,
int yyyymmdd,
int hhmmss){
227 LOG_INFO <<
GetName()<<
"::exportEtowDb start -->"<<fname<<endm;
230 const int par_maxADC=4096;
231 const float par_maxEt=60;
232 const float etaF[12]={1.95,1.855,1.765,1.675,1.59,1.51,1.435,1.365,1.3,1.235,1.17,1.115};
235 const int cETOW_DATSIZE=160;
236 const int cETOW_MAXFEE=6;
238 FILE *fd=fopen(fname.Data(),
"w");
240 fprintf(fd,
"# ::exportEtowDb(), time stamp: day=%d hhmmss=%06d run=R%d\n",yyyymmdd, runNo,hhmmss);
242 if(mgain60Et) fprintf(fd,
"# ideal gains(ch/GeV) set at maxEt=60 GeV\n");
243 else fprintf(fd,
"# real gains(ch/GeV) from OFL DB\n");
245 fprintf(fd,
"# see online/EmcDbAnsiC/EmcDbItemStruct.h for definitions\n");
246 fprintf(fd,
"#name, crate,chan, sec,sub,eta, gain, ped, thr, stat,fail, PsoftId, RDO\n");
250 for(icr=0;icr<mEeDb->getNFiber();icr++) {
252 if(fiber->
crID>6)
continue;
253 assert(fiber->
useIt);
254 assert(fiber->
crID==icr+1);
256 for(i=0;i<cETOW_DATSIZE;i++) {
260 int rdo = icr + i*cETOW_MAXFEE;
262 assert(x->eta>0 && x->eta<=12);
264 float myGain=x->gain;
265 if(mgain60Et) myGain=par_maxADC/par_maxEt/cosh(etaF[x->eta-1]);
268 fprintf(fd,
"%6s 0x%02x 0x%02x %2d %c %2d %8.2f %5.2f %5.2f 0x%02x 0x%02x %8s %4d\n",
269 x->
name,fiber->
crID,x->
chan,x->sec,x->sub,x->eta,myGain,x->ped,x->thr,0,0,x->
tube,rdo);
272 float ph=5*(x->sec-1)+x->sub-
'A';
273 ((TH2F*) hA[1])->Fill(13-x->eta,ph,myGain);
282 LOG_INFO << Form(
"exportEtowDb -->%s ,nTw=%d nNotFail=%d nGain=%d",fname.Data(),nA,nB,nC) <<endm;
289 void StEmcAsciiDbMaker::initAuxHisto() {
291 hA[0]=
new TH2F(
"bGn",
"BTOW gains from DB in [ch/GeV] ; eta; STAR phi (deg)",40,-1.,1.,120,0,360);
293 hA[1]=
new TH2F(
"eGn",
"ETOW gains from DB in [ch/GeV] ; eta bins reversed, (eta[+1,+2]); phi bin (5*sec-1 +sub-1)",12,0.5,12.5,60,-0.5,59.5);
296 hA[2]=
new TH1I(
"L2mapBTOWrev",
"map BTOW(softID) --> 1000*#phi_{bin} + #eta_{bin} , L2 di-jet convention; BTOW softID; composite {#eta,#phi} index ",4800,0.5,4800.5);
298 hA[3]=
new TH2I(
"L2mapBTOW",
"map BTOW(#eta_{bin},#phi_{bin}) --> softID , L2 di-jet convention ;BTOW #eta_{bin} ;BTOW #phi_{bin} ",40,-0.5,39.5,120,-0.5,119.5);
301 for(
int i=0;i<4;i++) mHList->Add( hA[i]);
char name[StEEmcNameLen]
ASCII name of the channel, see Readme.
int useIt
flag to ignore data from misconfig/broken crate/box
void getPedestal(Int_t det, Int_t softId, Int_t cap, Float_t &ped, Float_t &rms) const
Return pedestal mean and rms.
int GetTowerCrateFromDaqId(int RDO, int &crate, int &sequence) const
Get crate number from Daq Id for towers.
void loadTables(StMaker *anyMaker)
load tables.
char tube[StEEmcNameLen]
name of PMT or MAPMT pixel
void getCalib(Int_t det, Int_t softId, Int_t power, Float_t &calib) const
Return calibration constant.
virtual const char * GetName() const
special overload
Int_t getBin(const Float_t phi, const Float_t eta, Int_t &m, Int_t &e, Int_t &s) const
void getStatus(Int_t det, Int_t softId, Int_t &status, const char *option="") const
Return status.
int GetDaqIdFromTowerId(int softId, int &RDO) const
Get Daq Id from Software Id for towers.