8 static const int NPERIOD=9;
9 const int RUN0[NPERIOD+1]={22359013,23005043,23048036,23066056,23073059,23080057,23087057,23094050,23101043,23164000};
10 const int RUN1[NPERIOD] ={23007007,23007007,23048050,23067001,23074017,23081008,23087070,23095010,23101063};
11 const int RUN2[NPERIOD] ={23007011,23007011,23048051,23067002,23074018,23081009,23087072,23095011,23101064};
12 const int RUN3[NPERIOD] ={23048002,23048002,23066013,23073042,23080044,23087033,23094044,23101005,23108014};
13 const int RUN4[NPERIOD] ={23048003,23048003,23066017,23073043,23080045,23087034,23094045,23101013,23108015};
14 const char *gainfile[NPERIOD][2] ={{
"period1/fcsgaincorr_007_final.txt",
"period1/fcsgaincorr_048P1_final.txt"},
15 {
"period1/fcsgaincorr_007_final.txt",
"period1/fcsgaincorr_048P1_final.txt"},
16 {
"period2/fcsgaincorr_048_03.txt",
"period2/fcsgaincorr_066_03.txt"},
17 {
"period3/fcsgaincorr_067_05.txt",
"period3/fcsgaincorr_073_06.txt"},
18 {
"period4/fcsgaincorr_074_final.txt",
"period4/fcsgaincorr_080_final.txt"},
19 {
"period5/fcsgaincorr_081_03.txt",
"period5/fcsgaincorr_087_04.txt"},
20 {
"period6/fcsgaincorr_70_3.txt",
"period6/fcsgaincorr_94_3.txt"},
21 {
"period7/fcsgaincorr_095_2.txt",
"period7/fcsgaincorr_101_3.txt"},
22 {
"period8/fcsgaincorr_101_4.txt",
"period8/fcsgaincorr_108_4.txt"}};
24 float mGainCorrCalib[NIDX][2];
25 float mGainCorr[NIDX];
26 const int showidx=500;
28 const int MAXSCL=350000;
29 const int MAXRUN=10000;
30 const int LIMIT[4] = {5e6,1e7,2e6,2e6};
31 const int STARTRUN=22354029;
34 unsigned int TIME[MAXSCL];
41 unsigned int RUNT[MAXRUN];
42 unsigned int RUNN[MAXRUN];
47 void readGainCorr(
int period){
48 for(
int i=0; i<2; i++){
49 printf(
"Reading GainCorr from %s\n",gainfile[period][i]);
50 FILE* F=fopen(gainfile[period][i],
"r");
52 printf(
"Could not open %s\n",gainfile[period][i]);
57 while(fscanf(F,
"%d %d %d %d %f",&ehp,&ns,&dep,&ch,&gain) != EOF){
61 mGainCorrCalib[idx][i]=gain;
63 printf(
"GAINCORR ehp%1d ns%1d dep%02d ch%02d id=%3d idx=%4d start/stop=%1d %f\n",
64 ehp,ns,dep,ch,
id,idx,i,mGainCorrCalib[idx][i]);
72 void writeGainCorr(
int run){
74 sprintf(file,
"corr/%d.txt",run);
75 printf(
"Writing %s\n",file);
76 FILE* F=fopen(file,
"w");
78 printf(
"Could not open %s\n",file);
82 for(
int ns=0; ns<2; ns++){
83 for(
int dep=0; dep<24; dep++){
84 for(
int ch=0; ch<32; ch++){
93 fprintf(F,
"%1d %1d %2d %2d %f\n",ehp,ns,dep,ch,gain);
102 char filename[100],line[200];
103 sprintf(filename,
"scaler.txt");
104 FILE *F=fopen(filename,
"r");
106 cout <<
"Cannot open " << filename << endl;
109 cout <<
"Reading " << filename << endl;
110 while(fgets(line, 200, F) != NULL){
112 double rs2,rs3,rs7,rs8;
114 sscanf(line,
"%lf %lf %lf %lf %d %s %s",&rs2,&rs3,&rs7,&rs8,&ts,d,t);
115 if(rs2>0 || rs3>0 || rs7>0 || rs8>0){
118 if(rs7 > LIMIT[2])
continue;
130 printf(
"Read %d scaler data\n",NDATA);
135 char filename[100],line[200];
136 sprintf(filename,
"runs.txt");
137 FILE *F=fopen(filename,
"r");
139 cout <<
"Cannot open " << filename << endl;
142 cout <<
"Reading " << filename << endl;
143 while(fgets(line, 200, F) != NULL){
144 unsigned int run, ts;
145 sscanf(line,
"%d %d",&run,&ts);
154 printf(
"Read %d runs\n",NRUN);
161 FILE* F=fopen(
"integralLumi.txt",
"w");
162 fprintf(F,
"# run bbcW bbcE*W zdcW zdcE*W [10^9 counts]\n");
163 unsigned int itime=0;
164 double bbcw=0,bbca=0,zdcw=0,zdca=0;
165 for(
unsigned int irun=0; irun<NRUN; irun++){
166 while(TIME[itime] < RUNT[irun]){
173 if(itime >= NDATA)
break;
176 printf(
"%8d %14.6f %14.6f %14.6f %14.6f TS=%12d %12d %12d %12d\n",
177 RUNN[irun],bbcw*f,bbca*f,zdcw*f,zdca*f,RUNT[irun],TIME[itime],RUNT[irun]-TIME[itime],itime);
178 fprintf(F,
"%8d %14.6f %14.6f %14.6f %14.6f\n",
179 RUNN[irun],bbcw*f,bbca*f,zdcw*f,zdca*f);
184 c1 =
new TCanvas(
"c1",
"SCALER",50,0,1500,1200);
185 gStyle->SetLabelSize(0.03,
"xy");
186 gStyle->SetPalette(1);
187 gStyle->SetOptStat(0);
189 c1->SaveAs(
"scaler.png");
192 double getIntgLumi(
int run){
193 for(
unsigned int irun=0; irun<NRUN; irun++){
194 if(run==RUNN[irun])
return ITGL[irun];
200 void fcsTimedepGainCorr_db(
int period=1,
char* opt =
"writetxt",
int onlydorun=0) {
201 gROOT->Macro(
"LoadLogger.C");
202 gSystem->Load(
"St_base.so");
203 gSystem->Load(
"libStDb_Tables.so");
204 gSystem->Load(
"StDbLib.so");
205 gSystem->Load(
"StChain.so");
206 gSystem->Load(
"StBFChain");
207 gSystem->Load(
"StUtilities");
208 gSystem->Load(
"StIOMaker");
209 gSystem->Load(
"StarClassLibrary");
210 gSystem->Load(
"St_Tables");
211 gSystem->Load(
"StDbLib");
212 gSystem->Load(
"StDbBroker");
213 gSystem->Load(
"St_db_Maker");
214 gSystem->Load(
"StFcsDbMaker.so");
221 fcsEcalGainCorr_st ecorr;
222 int readTime, readDate;
225 std::cout <<
"Opt =" << opt <<
"\n";
226 std::cout <<
"writedb = " << option.Contains(
"writedb") <<
"\n";
233 for(
unsigned int irun=0; irun<NRUN; irun++){
234 unsigned int run=RUNN[irun];
238 if(period==-1 || period==p){
240 double l1=getIntgLumi(RUN1[p]);
241 double l2=getIntgLumi(RUN2[p]);
242 double l3=getIntgLumi(RUN3[p]);
243 double l4=getIntgLumi(RUN4[p]);
249 if(p>=0 && (period==-1 || period==p) ){
250 if(onlydorun>0 && run!=onlydorun)
continue;
252 int year=run/1000000-1;
253 int port=3400+year-1;
256 sprintf(cmd,
"mysql -h db04.star.bnl.gov --port=%d -N -s -e \"SELECT startRunTime FROM RunLog.runDescriptor WHERE runNumber=%d LIMIT 1\"",port,run);
258 TString st=gSystem->GetFromPipe(cmd);
259 int starttime=st.Atoi();
260 readDate=gSystem->GetFromPipe(Form(
"date -u -d \@%d +%%Y%%m%%d",starttime)).Atoi();
261 readTime=gSystem->GetFromPipe(Form(
"date -u -d \@%d +%%H%%M%%S",starttime)).Atoi();
264 double l=getIntgLumi(run);
265 double w1=(l34-l)/(l34-l12);
266 double w2=(l-l12)/(l34-l12);
267 for(
int idx=0; idx<NIDX; idx++){
268 double c1 = mGainCorrCalib[idx][0];
269 double c2 = mGainCorrCalib[idx][1];
270 double cc = c1*w1 + c2*w2;
272 ecorr.gaincorr[idx]=cc;
274 printf(
"Run=%8d Period=%1d Start=%d Date=%06d Time=%06d idx=%4d %6.3f %6.3f %8.4f %8.4f %8.4f\n",
275 run,p,starttime,readDate,readTime,idx,w1,w2,c1,c2,ecorr.gaincorr[idx]);
278 if(option.Contains(
"writetxt")) {
281 if(option.Contains(
"writedb")) {
282 gSystem->Setenv(
"DB_ACCESS_MODE",
"write");
283 cout <<
"DB_ACCESS_MODE="<<gSystem->Getenv(
"DB_ACCESS_MODE")<<endl;
286 mgr->setStoreTime(starttime);
287 StDbTable* table = node->addDbTable(
"fcsEcalGainCorr");
289 table->setFlavor(
"ofl");
290 mgr->storeDbTable(table);
296 printf(
"Reading back DB\n");
297 int date,time,from=0,n=0;
309 std::cout <<
"Readout Date="<<readDate<<
" Time="<<readTime<<endl;
313 dbMk->SetDateTime(readDate,readTime);
314 dbMk->SetFlavor(
"ofl");
319 DB = dbMk->GetInputDB(
"Calibrations/fcs");
320 if(!DB){std::cout <<
"ERROR: no db maker or Calibrations/fcs" << std::endl; }
321 St_fcsEcalGainCorr *dbTable_ec = (St_fcsEcalGainCorr*) DB->
Find(
"fcsEcalGainCorr");
323 std::cout <<
"Reading fcsEcalGainCorr table from DB\n";
324 fcsEcalGainCorr_st *dbSt_ec = dbTable_ec->GetTable();
325 Int_t rows = dbTable_ec->GetNRows();
326 for(
int i=0; i<rows; i++){
327 for(
int id=0;
id<1496;
id++){
328 printf(
"DbRead row=%2d id=%d gaincorr=%10.6f\n",
329 i,
id,dbSt_ec[i].gaincorr[
id]);
333 std::cout <<
"WARNING: No data in fcsEcalGainCorr table\n";
void getIdfromDep(int ehp, int ns, int dep, int ch, int &detectorId, int &id, int &crt, int &slt) const
Get DEP map.
virtual void SetTable(char *data, int nrows, int *idList=0)
calloc'd version of data for StRoot
static StDbManager * Instance()
strdup(..) is not ANSI
virtual TDataSet * Find(const char *path) const