00001
00002
00003
00004
00005
00006 #include <stdio.h>
00007 #include <TH2.h>
00008 #include <TFile.h>
00009
00010 #include <StMessMgr.h>
00011
00012 #include "StEmcAsciiDbMaker.h"
00013 #include "StEmcRawMaker/defines.h"
00014
00015 #include <StEEmcUtil/database/StEEmcDb.h>
00016 #include <StEEmcUtil/database/EEmcDbItem.h>
00017 #include <StEEmcUtil/database/EEmcDbCrate.h>
00018
00019
00020
00021 #include "StEmcUtil/geometry/StEmcGeom.h"
00022 #include "StEmcUtil/database/StBemcTables.h"
00023 #include "StEmcUtil/database/StEmcDecoder.h"
00024
00025
00026 ClassImp(StEmcAsciiDbMaker)
00027
00028
00029
00030 StEmcAsciiDbMaker::StEmcAsciiDbMaker() : StMaker("StEmcAsciiDb") {
00031
00032 mGeomB =0;
00033 mEeDb=0;
00034 mMappB=0;
00035 mHList=0;
00036 mgain60Et=false;
00037
00038 memset(hA,0,sizeof(hA));
00039
00040
00041
00042
00043
00044
00045 }
00046
00047
00048
00049 StEmcAsciiDbMaker::~StEmcAsciiDbMaker() {
00050 }
00051
00052
00053
00054 Int_t StEmcAsciiDbMaker::Init() {
00055
00056
00057 mEeDb = (StEEmcDb*)this->GetDataSet("StEEmcDb");
00058 assert(mEeDb);
00059 mGeomB = StEmcGeom::instance("bemc");
00060 initAuxHisto();
00061 LOG_INFO << Form(" %s::Init() setGain60Et=%d",GetName(),mgain60Et) <<endm;
00062
00063 mMappB =0;
00064 return kStOk;
00065 }
00066
00067
00068
00069 Int_t StEmcAsciiDbMaker::InitRun(int runNo){
00070 int yyyymmdd = this->GetDBTime().GetDate();
00071 int hhmmss = this->GetDBTime().GetTime();
00072
00073
00074 TString outPath="L2setup-"; outPath+=yyyymmdd;
00075 printf("outPath=%s=\n",outPath.Data());
00076 LOG_INFO << GetName()<<"::InitRun() run=" <<runNo<<" outPath="<<outPath<<endm;
00077
00078
00079 assert( mMappB==0) ;
00080 mMappB = new StEmcDecoder(yyyymmdd,hhmmss);
00081
00082
00083 exportBtowDb(outPath+"/btowDb.current",runNo,yyyymmdd,hhmmss);
00084 exportEtowDb(outPath+"/etowDb.current",runNo,yyyymmdd,hhmmss);
00085
00086 return kStOk;
00087 }
00088
00089
00090
00091
00092
00093 Int_t StEmcAsciiDbMaker::Make() {
00094
00095 return kStOk;
00096
00097 }
00098
00099
00100
00101 void StEmcAsciiDbMaker::Clear(const Option_t* ){
00102 }
00103
00104
00105
00106 Int_t StEmcAsciiDbMaker::Finish() {
00107 return kStOk;
00108 }
00109
00110
00111
00112
00113 void StEmcAsciiDbMaker::exportBtowDb(TString fname, int runNo, int yyyymmdd,int hhmmss){
00114 LOG_INFO << GetName()<<"::exportBtowDb start -->"<<fname<<endm;
00115
00116
00117 const int par_maxADC=4096;
00118 const float par_maxEt=60;
00119
00120 StBemcTables *myTable=new StBemcTables;
00121 myTable->loadTables(this );
00122
00123 FILE *fd=fopen(fname.Data(),"w");
00124 assert(fd);
00125 fprintf(fd,"# ::exportBtowDb(), time stamp: day=%d hhmmss=%06d run=R%d\n",yyyymmdd,hhmmss, runNo);
00126 if(mgain60Et) fprintf(fd,"# ideal gains(ch/GeV) set at maxEt=60 GeV\n");
00127 else fprintf(fd,"# real gains(ch/GeV) from OFL DB\n");
00128
00129 fprintf(fd,"# see online/EmcDbAnsiC/EmcCDbItem.h for definitions\n");
00130 fprintf(fd,"#name, crate,chan, sec,sub,eta, gain, ped, thr, stat,fail, id-m-s-e, RDO\n");
00131
00132 int softID;
00133 int nB=0,nA=0,nC=0;
00134 for(softID=1; softID<=BTOWSIZE; softID++) {
00135 nA++;
00136
00137 int RDO, CR,CHAN;
00138 assert(mMappB->GetDaqIdFromTowerId(softID,RDO)==1);
00139 assert(mMappB->GetTowerCrateFromDaqId(RDO,CR,CHAN)==1);
00140
00141
00142
00143 int status;
00144 myTable->getStatus(BTOW, softID, status);
00145 int m,e,s;
00146 mGeomB->getBin(softID,m,e,s);
00147
00148 float etaF,phiF;
00149 mGeomB->getEta(m,e,etaF);
00150 mGeomB->getPhi(m,s,phiF);
00151 if( phiF<0) phiF+=2*C_PI;
00152
00153
00154 float ped,sig;
00155 myTable->getPedestal(BTOW, softID, 0, ped,sig);
00156
00157 float gain;
00158 myTable->getCalib(BTOW, softID, 1, gain);
00159
00160
00161
00162
00163 assert(fabs(etaF)<0.99);
00164 int kEta=1+(int)((etaF+1.)/0.05);
00165
00166 int kPhi=24-(int)( phiF/C_PI*60.);
00167 if(kPhi<0) kPhi+=120;
00168
00169
00170 char name[10]="nnn", pname[100];
00171 int sec=1+kPhi/10;
00172 char sub='a'+kPhi%10;
00173 sprintf(name,"%02dt%c%02d",sec,sub,kEta);
00174
00175 hA[2]->Fill(softID,1000*kPhi+(kEta-1));
00176 hA[3]->SetBinContent(kEta,kPhi+1,softID);
00177
00178
00179 float myGain=-2;
00180 if(gain>0) {
00181 myGain=1/gain;
00182 nC++;
00183 }
00184
00185 if(mgain60Et) myGain=par_maxADC/par_maxEt/cosh(etaF);
00186
00187
00188 ushort stat=0;
00189 ushort fail=0;
00190 if(status==1) {
00191 nB++;
00192 float ph=phiF/C_PI*180.;
00193 while(ph<0) ph+=360.;
00194 ((TH2F*) hA[0])->Fill(etaF,ph,myGain);
00195 }
00196
00197 float thr=ped+mEeDb->getKsigOverPed()*sig;
00198 sprintf(pname,"id%04d-%03d-%d-%02d",softID,m,s,e);
00199 fprintf(fd,"%6s 0x%02x 0x%02x %2d %c %2d %8.2f %5.2f %5.2f 0x%02x 0x%02x %8s %4d\n",
00200 name,CR,CHAN,sec,sub,kEta,myGain,ped,thr,stat,fail,pname,RDO);
00201
00202 }
00203 fclose(fd);
00204
00205 LOG_INFO << Form("exportBtowDb -->%s ,nTw=%d nNotFail=%d nGoodGain=%d",fname.Data(),nA,nB,nC) <<endm;
00206
00207 #if 0 // tmp, somehow HList does not write, fix it
00208 TString outName="btowMap.hist.root";
00209 TFile f( outName,"recreate");
00210 assert(f.IsOpen());
00211 printf("BTOW map histos are written to '%s' ...\n",outName.Data());
00212 hA[2]->Write();
00213 hA[3]->Write();
00214 f.Close();
00215
00216 #endif
00217
00218
00219 }
00220
00221
00222
00223 void StEmcAsciiDbMaker::exportEtowDb(TString fname, int runNo, int yyyymmdd,int hhmmss){
00224 LOG_INFO << GetName()<<"::exportEtowDb start -->"<<fname<<endm;
00225
00226
00227 const int par_maxADC=4096;
00228 const float par_maxEt=60;
00229 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};
00230
00231
00232 const int cETOW_DATSIZE=160;
00233 const int cETOW_MAXFEE=6;
00234
00235 FILE *fd=fopen(fname.Data(),"w");
00236 assert(fd);
00237 fprintf(fd,"# ::exportEtowDb(), time stamp: day=%d hhmmss=%06d run=R%d\n",yyyymmdd, runNo,hhmmss);
00238
00239 if(mgain60Et) fprintf(fd,"# ideal gains(ch/GeV) set at maxEt=60 GeV\n");
00240 else fprintf(fd,"# real gains(ch/GeV) from OFL DB\n");
00241
00242 fprintf(fd,"# see online/EmcDbAnsiC/EmcDbItemStruct.h for definitions\n");
00243 fprintf(fd,"#name, crate,chan, sec,sub,eta, gain, ped, thr, stat,fail, PsoftId, RDO\n");
00244 int nB=0,nA=0,nC=0;
00245 int icr;
00246
00247 for(icr=0;icr<mEeDb->getNFiber();icr++) {
00248 const EEmcDbCrate *fiber=mEeDb->getFiber(icr);
00249 if(fiber->crID>6) continue;
00250 assert(fiber->useIt);
00251 assert(fiber->crID==icr+1);
00252 int i;
00253 for(i=0;i<cETOW_DATSIZE;i++) {
00254 const EEmcDbItem *x=mEeDb->getByCrate(fiber->crID,i);
00255 if(x==0) continue;
00256 nA++;
00257 int rdo = icr + i*cETOW_MAXFEE;
00258
00259 assert(x->eta>0 && x->eta<=12);
00260
00261 float myGain=x->gain;
00262 if(mgain60Et) myGain=par_maxADC/par_maxEt/cosh(etaF[x->eta-1]);
00263
00264
00265 fprintf(fd,"%6s 0x%02x 0x%02x %2d %c %2d %8.2f %5.2f %5.2f 0x%02x 0x%02x %8s %4d\n",
00266 x->name,fiber->crID,x->chan,x->sec,x->sub,x->eta,myGain,x->ped,x->thr,0,0,x->tube,rdo);
00267 if( !x->fail) {
00268 nB++;
00269 float ph=5*(x->sec-1)+x->sub-'A';
00270 ((TH2F*) hA[1])->Fill(13-x->eta,ph,myGain);
00271 }
00272
00273
00274 if(x->gain>0) nC++;
00275 }
00276 }
00277 fclose(fd);
00278
00279 LOG_INFO << Form("exportEtowDb -->%s ,nTw=%d nNotFail=%d nGain=%d",fname.Data(),nA,nB,nC) <<endm;
00280 }
00281
00282
00283
00284
00285
00286 void StEmcAsciiDbMaker::initAuxHisto() {
00287 assert(mHList);
00288 hA[0]=new TH2F("bGn","BTOW gains from DB in [ch/GeV] ; eta; STAR phi (deg)",40,-1.,1.,120,0,360);
00289
00290 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);
00291
00292
00293 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);
00294
00295 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);
00296
00297
00298 for(int i=0;i<4;i++) mHList->Add( hA[i]);
00299 mHList->Print();
00300
00301 }
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321