00001
00002
00003
00004 #include <stdio.h>
00005 #include <TFile.h>
00006 #include <TH1.h>
00007 #include <TH2.h>
00008
00009 #include "StJanBarrelDbMaker.h"
00010
00011 #include "StEmcRawMaker/defines.h"
00012 #include "StEmcUtil/database/StBemcTables.h"
00013 #include "StEmcUtil/geometry/StEmcGeom.h"
00014 #include "StEmcUtil/database/StEmcDecoder.h"
00015
00016 ClassImp(StJanBarrelDbMaker)
00017
00018
00019
00020 StJanBarrelDbMaker::StJanBarrelDbMaker(const char *name):StMaker(name){
00021 mMappB=0;
00022 setDbType(kStarDb); setHList(0);
00023 }
00024
00025
00026
00027
00028
00029 StJanBarrelDbMaker::~StJanBarrelDbMaker(){
00030
00031 }
00032
00033
00034
00035
00036
00037 Int_t StJanBarrelDbMaker::Init(){
00038 LOG_INFO<<Form("::Init() ")<<endm;
00039 assert(HList);
00040
00041 mBtowGeom = StEmcGeom::instance("bemc");
00042 mBprsGeom = StEmcGeom::instance("bprs");
00043 mSmdEGeom = StEmcGeom::instance("bsmde");
00044 mSmdPGeom = StEmcGeom::instance("bsmdp");
00045 mTables = new StBemcTables();
00046
00047 initBprsGeometry();
00048
00049
00050
00051
00052 return StMaker::Init();
00053 }
00054
00055
00056
00057
00058 Int_t StJanBarrelDbMaker::InitRun (int runNo){
00059 LOG_INFO<<Form("::InitRun(%d) algo params:dbType=%d",
00060 runNo, par_dbType
00061 )<<endm;
00062
00063
00064
00065
00066 mMappB = new StEmcDecoder(GetDateTime().GetDate(),GetDateTime().GetTime());
00067
00068 mTables->loadTables(this );
00069 janDb_bprsPed2D=0;
00070 janDb_bprsReMap=janDb_btowReMap=0;
00071
00072 if(par_dbType==kJanDb ) {
00073 assert(par_dbType==kJanDb);
00074 int pedRun=runNo;
00075
00076
00077 LOG_INFO<<"upload local peds from run"<<pedRun<<endm;
00078 char txt[100];
00079
00080 const char *pedPath="/star/institutions/mit/balewski/2008-janDb-BprsPeds-v3.1";
00081 sprintf(txt,"%s/pedBprsR%d-allCap.hist.root",pedPath,pedRun);
00082 TFile* fd=new TFile(txt); assert(fd->IsOpen());
00083 fd->ls();
00084 janDb_bprsPed2D=(TH2S *)fd->Get("pedBPRScap"); assert(janDb_bprsPed2D);
00085 janDb_bprsSigPed2D=(TH2S *)fd->Get("rmsPedBPRScap"); assert(janDb_bprsSigPed2D);
00086 janDb_bprsStat=(TH1S *)fd->Get("statBPRSallCap"); assert( janDb_bprsStat);
00087
00088 const char *path= "calib-jan3.1/";
00089
00090 sprintf(txt,"%s/mipGainBprs+Btow_v2.hist.root",path);
00091 TFile* fd5=new TFile(txt); assert(fd5->IsOpen());
00092 fd5->ls();
00093 const char *core[mxBTile]={"btow","bprs"};
00094 for(int ibp=0;ibp<mxBTile;ibp++) {
00095 TString tit=core[ibp]; tit+="MipGain";
00096 janDb_mipMean[ibp]=(TH1F *)fd5->Get(tit); assert( janDb_mipMean[ibp]);
00097 tit=core[ibp]; tit+="MipSig";
00098 janDb_mipSig[ibp]=(TH1F *)fd5->Get(tit); assert( janDb_mipSig[ibp]);
00099 tit=core[ibp]; tit+="MipStat";
00100 janDb_mipStat[ibp]=(TH1F *)fd5->Get(tit); assert( janDb_mipStat[ibp]);
00101 }
00102
00103
00104
00105 sprintf(txt,"%s/bprsReMap-ver3.hist.root",path);
00106 TFile* fd3=new TFile(txt); assert(fd3->IsOpen());
00107 janDb_bprsReMap=(TH1I *)fd3->Get("bprsReMap"); assert(janDb_bprsReMap);
00108 printf("use BPRS softID corection: %s\n",txt);
00109
00110
00111
00112 sprintf(txt,"%s/btowReMap-ver3.hist.root",path);
00113 TFile* fd4=new TFile(txt); assert(fd4->IsOpen());
00114 janDb_btowReMap=(TH1I *)fd4->Get("btowReMap"); assert(janDb_btowReMap);
00115 printf("use BTOW softID corection: %s\n",txt);
00116
00117
00118
00119
00120 for(int ibp=0;ibp<mxBTile;ibp++) {
00121 for(int id=1;id<=mxBtow;id++) {
00122 float adcL=5., adcH=40.;
00123 if(ibp==kBPrs) adcL=3.5;
00124 int statGain=(int)mipStat(ibp)->GetBinContent(id);
00125 if(!statGain){
00126 float mean=mipMean(ibp)->GetBinContent(id);
00127 float sig=mipSig(ibp)->GetBinContent(id);
00128 adcL=mean-sig;
00129 adcH=mean+sig;
00130 if(ibp==kBTow && adcL<5) adcL=5;
00131 if(ibp==kBPrs && adcL<3.5) adcL=3.5;
00132 if(adcH>2*mean) adcH=2*mean;
00133 if(id%77==0)
00134 printf("%s id=%4d MIP mean=%.1f sig=%.1f adcL=%.1f H=%.1f\n",core[ibp],id,mean,sig,adcL,adcH);
00135
00136 }
00137 cut_mipAdcL[ibp][id-1]=adcL;
00138 cut_mipAdcH[ibp][id-1]=adcH;
00139 }
00140 }
00141
00142 LOG_INFO<<Form("::InitRun() Load private DB, nBad BPRS=%.0f",janDb_bprsStat->GetEntries())<<endm;
00143
00144 printf("WARN: tmp disable 2 BPRS & 1 tiles\n");
00145
00146
00147 janDb_bprsStat->SetBinContent(2821,99);
00148 janDb_bprsStat->SetBinContent(3781,99);
00149
00150
00151 }
00152
00153
00154 #if 0
00155
00156 int RDO;
00157 int posInFiber;
00158 int softId;
00159 int PMTbox;
00160 int wire;
00161 int A_value;
00162
00163 for(softId=650; softId<750;softId++) {
00164 int newId;
00165 mMappB->GetPsdRDO(softId, RDO, posInFiber);
00166 mMappB->GetPsdId( RDO, posInFiber, newId,PMTbox,wire, A_value, true);
00167 assert(newId==softId);
00168
00169 }
00170
00171
00172 printf("JJJBprs softID rdo posInFib \n");
00173
00174 for(softId=1; softId<=4800;softId++) {
00175 mMappB->GetPsdRDO(softId, RDO, posInFiber);
00176 int newId=(int)bprsReMap()->GetBinContent(softId);
00177
00178 if(newId==4525) { RDO=2; posInFiber=487; }
00179 if(newId==4526) { RDO=2; posInFiber=507; }
00180 printf("JJJBprs %4d %2d %4d \n", newId,RDO,posInFiber);
00181 janDb_bprsSoft2Hard->SetBinContent(softId, RDO*5000 + posInFiber);
00182 }
00183
00184
00185 printf("JJJBtow softID rdo posInFib \n");
00186 for(int softId=1; softId<=4800;softId++) {
00187 int RDO;
00188 int posInFiber;
00189 mMappB->GetCrateFromTowerId(softId, RDO, posInFiber);
00190 int newId=softId;
00191 printf("JJJBtow %4d %2d %4d \n", newId,RDO,posInFiber);
00192 }
00193 #endif
00194
00195 LOG_INFO<<Form("::InitRun() done")<<endm;
00196 return StMaker::Init();
00197 }
00198
00199
00200
00201
00202
00203 Int_t StJanBarrelDbMaker::Make(){
00204 LOG_INFO<<Form("::Make() ")<<endm;
00205
00206
00207 return kStOK;
00208 }
00209
00210
00211
00212
00213 int StJanBarrelDbMaker::bprsCrate(int softID) {
00214 assert(softID>0);
00215 assert(softID<=mxBtow);
00216 if(softID<=340 ) return 0;
00217 else if(softID<=1540 ) return 1;
00218 else if(softID<=2400 ) return 0;
00219 else if(softID<=2900 ) return 2;
00220 else if(softID<=4100 ) return 3;
00221 return 2;
00222 }
00223
00224
00225
00226
00227
00228 float StJanBarrelDbMaker::pedTile(int ibp, int softID, int capID){
00229 assert(softID>0 && softID<=mxBtow);
00230 assert(capID>=0 && capID<mxBcap);
00231
00232 float ped=-991;
00233 int jBP=BTOW;
00234 if(ibp==kBPrs)jBP=BPRS;
00235
00236 float pedOfl,sigPedOfl;
00237 mTables->getPedestal(jBP,softID,capID,pedOfl,sigPedOfl);
00238
00239 ped=pedOfl;
00240
00241
00242 if(ibp==kBPrs && par_dbType==kJanDb)
00243 ped=0.1*janDb_bprsPed2D->GetBinContent(softID,capID+1);
00244
00245 return ped;
00246
00247 }
00248
00249
00250
00251
00252 float StJanBarrelDbMaker::sigPedTile(int ibp, int softID, int capID){
00253
00254 assert(softID>0 && softID<=mxBtow);
00255 assert(capID>=0 && capID<mxBcap);
00256
00257 float sigPed=-991;
00258 int jBP=BTOW;
00259 if(ibp==kBPrs)jBP=BPRS;
00260
00261 float pedOfl,sigPedOfl;
00262 mTables->getPedestal(jBP,softID,capID,pedOfl,sigPedOfl);
00263
00264 sigPed=sigPedOfl;
00265
00266
00267 if(ibp==kBPrs && par_dbType==kJanDb)
00268 sigPed=0.1*janDb_bprsSigPed2D->GetBinContent(softID,capID+1);
00269
00270
00271 return sigPed;
00272
00273 }
00274
00275
00276
00277
00278
00279 int StJanBarrelDbMaker::statTile(int ibp, int softID){
00280
00281 assert(softID>0 && softID<=mxBtow);
00282
00283 int jBP=BTOW;
00284 if(ibp==kBPrs)jBP=BPRS;
00285 int statOflPed;
00286 mTables->getStatus(jBP, softID, statOflPed,"pedestal");
00287 int stat=0;
00288 if(statOflPed!=1) stat=1;
00289
00290
00291 if(ibp==kBTow ){
00292 if( softID==1075) stat=1;
00293 if( softID==2969) stat=1;
00294 if( softID==3289) stat=1;
00295 }
00296
00297
00298 if(ibp==kBPrs && par_dbType==kJanDb)
00299 stat=(int)janDb_bprsStat->GetBinContent(softID);
00300
00301 return stat;
00302
00303 }
00304
00305
00306
00307
00308
00309 void StJanBarrelDbMaker::initBprsGeometry(){
00310 printf("\nggg BPRS geometry initialization\n");
00311
00312
00313 for( int id0=0; id0< mxBTetaBin; id0++) {
00314 int id=id0+1;
00315 float eta;
00316 assert(mBprsGeom->getEta(id,eta)==0);
00317 float eta2;
00318 assert(mBtowGeom->getEta(id,eta2)==0);
00319 printf("id=%d, BPRS eta=%f BTOW eta=%f\n",id,eta,eta2);
00320
00321 }
00322 }
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341 #if 0
00342
00343
00345 int GetPsdId(int RDO, int posInFiber, int &softId, int &PMTbox, int &wire, int &A_value, bool print=false) const;
00346
00348 int GetPsdRDO(int softId, int &RDO, int &posInFiber) const;
00349
00350
00351
00352
00353
00354 #endif
00355