1 static const int MAXP=100;
2 static const int MAXRUN=500;
5 static const int NS=21;
7 static const int NID=NQ*NL*NS*NC;
9 static int N[MAXRUN][NID];
10 static int T[MAXRUN][NID][MAXP];
11 static float V[MAXRUN][NID][MAXP];
12 static float C[MAXRUN][NID][MAXP];
13 static float A[MAXRUN][NID];
14 static TString FNAME[MAXRUN];
15 static TString DATE[MAXRUN];
19 static int COL[NC][NL]={{kRed, kOrange, kMagenta},{kBlue, kCyan, kBlack}};
23 int getID(
int quad,
int layer,
int slat,
int ch=0){
24 return (quad-1)*NL*NS*NC + (layer-1)*NS*NC + (slat-1)*NC + ch;
27 int readdir(
int forceread=0,
const char* dir=
"data/"){
28 TSystemDirectory Dir(dir,dir);
29 TList *files = Dir.GetListOfFiles();
36 while ((file=(TSystemFile*)next())) {
37 fname = file->GetName();
38 if (!file->IsDirectory() && fname.BeginsWith(
"fps_ivscan_")) {
40 f.ReplaceAll(
"fps_ivscan_",
"");
41 f.ReplaceAll(
"_",
" ");
43 sscanf(f.Data(),
"%d %d %d %d %d",&y,&mo,&d,&h,&m);
45 if(y==2014 && mo<12)
continue;
46 if(y==2014 && mo==12 && d<17)
continue;
47 time[n]=(y-2015)*372+mo*31+d+h/24.0+m/24.0/60.0;
50 if(n==MAXRUN) {printf(
"Reached MAXRUN\n");
break;}
53 FILE* ff=fopen(
"ivnrun.txt",
"r");
54 fscanf(ff,
"%d",&lastnrun);
56 printf(
"%d files found, and ivnrun.txt says %d runs found when checked last\n",n,lastnrun);
57 if(n<=lastnrun && forceread<0) {
58 printf(
"No new runs found. Skipping!\n");
61 ff=fopen(
"ivnrun.txt",
"w");
64 Int_t index[MAXRUN]; memset(index,0,
sizeof(index));
65 TMath::Sort(n,time,index,
false);
66 for(
int i=0; i<n; i++){
67 fname=FNAME[index[i]];
69 DATE[i]=FNAME[index[i]];
70 DATE[i].ReplaceAll(
"fps_ivscan_",
"");
78 void read(
const char* file){
80 FILE* f=fopen(file,
"r");
81 if(!f) { printf(
"Failed to open %s\n",file);
return; }
82 printf(
"%6d Reading %s\n",r+1,file);
84 while( fgets(line,1000,f) != NULL){
86 tline.ReplaceAll(
"67.000,67.000,0.000,",
"");
87 tline.ReplaceAll(
",",
" ");
88 tline.ReplaceAll(
".000",
"");
89 if(line[0]==
'\n')
continue;
91 float a,temp,v0,v1,i0,i1;
92 sscanf(tline.Data(),
"%d %d %d %d %f %f %f %f %f %f",
93 &t,&q,&l,&s,&a,&v0,&v1,&temp,&i0,&i1);
94 int id = getID(q,l,s);
116 for(
int q=1; q<=NQ; q++){
117 for(
int l=1; l<=NL; l++){
118 printf(
"Q%1d L%1d ",q,l);
119 for(
int s=1; s<=NS; s++){
120 printf(
" %4d ",N[r][getID(q,l,s)]);
129 void writetxt(
int run){
130 char file[100] =
"txt/iv.txt";
131 FILE* f=fopen(file,
"w");
132 if(!f) { printf(
"Failed to open %s\n",file);
return; }
133 printf(
"Writing %s\n",file);
134 for(
int q=1; q<=NQ; q++){
135 for(
int l=1; l<=NL; l++){
136 for(
int s=1; s<=NS; s++){
137 for(
int c=0; c<NC; c++){
138 for(
int r=0; r<NRUN; r++){
139 if(run>0 && r!=run)
continue;
140 int id=getID(q,l,s,c);
141 if(A[r][
id]==0.0)
continue;
142 fprintf(f,
"%1d %1d %2d %1d %4d %f\n",q,l,s,c,r,A[r][
id]);
151 void plot(
int q,
int l,
int s,
int ch,
int r,
int k,
int plt){
152 float low=65.0, high=72.0;
153 int id=getID(q,l,s,ch);
154 TGraph* g =
new TGraph(1);
155 TGraph* gg =
new TGraph(1);
157 for(
int i=0; i<N[r][id]; i++) {
160 g->SetPoint(j,
double(v),
double(log10(c)));
163 if(c<0.1 && v>low) low=v;
164 if(c>40.0 && v<high) high=v;
166 float low2=low+(high-low)*0.1;
167 float high2=low+(high-low)*0.8;
168 for(
int i=0; i<N[r][id]; i++) {
171 if(low2<v && v<high2){
172 gg->SetPoint(jj,
double(v),
double(log10(c)));
178 int style = 20 + k%8;
179 int color = 1 + k%8;
if(color>=5) {color++;}
180 if(plt==1) color=COL[ch][l-1];
181 g->SetMarkerStyle(style); gg->SetMarkerStyle(style);
182 g->SetMarkerSize(0.5); gg->SetMarkerSize(0.5);
183 g->SetMarkerColor(color); gg->SetMarkerColor(color);
184 g->SetLineColor(color); gg->SetLineColor(color);
185 g->Draw(
"PL"); gg->Draw(
"PL");
189 if(j>20 && jj<=2) bad=1;
192 TF1 *f=
new TF1(
"f",
"-1 + (x-[0])*[1] + (x-[0])*(x-[0])*[2]");
193 double p0[3]={66.0,66.0,67.5};
194 f->SetLineColor(color);
195 f->SetParameters(0,p0[l]);
196 f->SetParameters(1,0.2);
197 f->SetParameters(2,0.1);
200 pzero=f->GetParameter(0);
201 if(l!=3) {A[r][id]=f->GetX(-0.5,65.5,68.5);}
202 if(l==3) {A[r][id]=f->GetX(-0.5,68.0,70.0);}
204 if( (pzero<50.0 || pzero>80.0) ||
205 (l!=3 && (A[r][
id]<66.0 || A[r][
id]>68.0) ) ||
206 (l==3 && (A[r][
id]<68.0 || A[r][
id]>70.0) ) ) bad=1;
210 printf(
"BAD : Q%1dL%1dS%02dC%1d %s(Run=%4d) p0=%8.3f A=%8.3f\n",q,l,s,ch,DATE[r].Data(),r+1,pzero,A[r][
id]);
211 TText *t1=
new TText(0.15,0.88-NBAD*0.02,Form(
"Q%1dL%1dS%02dC%1d %s(%d)",q,l,s,ch,DATE[r].Data(),r+1));
212 t1->SetNDC(); t1->SetTextSize(0.018); t1->SetTextColor(color); t1->Draw();
217 void history(
int q,
int l,
int s,
int ch,
int k){
218 int id=getID(q,l,s,ch);
219 TGraph* g =
new TGraph(1);
221 for(
int r=0; r<NRUN; r++){
226 g->SetPoint(j,
double(r+1),
double(log10(c)));
231 int style = 20 + k%8;
232 int color = 1 + k%8;
if(color>=5) {color++;}
233 g->SetMarkerStyle(style);
234 g->SetMarkerSize(0.5);
235 g->SetMarkerColor(color);
236 g->SetLineColor(color);
241 void iv(
int plt=-3,
int quad=0,
int layer=0,
int slat=0,
int run=-1,
int log=1,
float max=100){
242 memset(N,0,
sizeof(N));
243 memset(V,0,
sizeof(V));
244 memset(C,0,
sizeof(C));
245 memset(T,0,
sizeof(T));
246 memset(A,0,
sizeof(A));
248 int lastnrun=readdir(plt);
249 if(lastnrun==-1)
return;
251 gStyle->SetOptStat(0);
252 gStyle->SetOptTitle(1);
253 gStyle->SetOptFit(0);
255 c1 =
new TCanvas(
"iv",
"iv",100,20,800,900);
256 c2 =
new TCanvas(
"IV hist",
"iv hist",910,20,800,900);
263 if(run==0){ sprintf(tit,
"Q%1d L%1d S%2d ALL RUNS",quad,layer,slat); }
266 if(run==-1) r=NRUN-1;
267 sprintf(tit,
"Q%1d L%1d S%2d %s",quad,layer,slat,DATE[r].Data());
270 TH2F *frame =
new TH2F(tit,tit,1,64.5,72,1,-2.0,2.0);
271 TH2F *frame2 =
new TH2F(tit,tit,1,0.0,
float(NRUN+1),1,-2.0,2.0);
273 if(plt==0) frame->Draw();
276 if(plt==-1 || plt==-3) {
278 for(
int r=0; r<NRUN; r++){
280 sprintf(filename,
"www/iv/iv.%s.png",DATE[r].Data());
282 for(
int q=1; q<=NQ; q++){
283 for(
int l=1; l<=NL; l++){
284 for(
int s=1; s<=NS; s++){
285 for(
int ch=0; ch<2; ch++){
286 plot(q,l,s,ch,r,k,plt);
293 c1->SaveAs(filename);
297 if(plt==-2 || plt==-3) {
302 sprintf(filename,
"www/iv/iv.history.png");
303 for(
int q=1; q<=NQ; q++){
304 for(
int l=1; l<=NL; l++){
305 for(
int s=1; s<=NS; s++){
306 for(
int ch=0; ch<2; ch++){
314 c2->SaveAs(filename);
316 for(
int q=1; q<=NQ; q++){
317 if(quad>0 && quad!=q)
continue;
322 for(
int l=1; l<=NL; l++){
323 if(plt==0 && layer>0 && layer!=12 && layer!=l)
continue;
324 if(layer==12 && layer==3)
continue;
325 for(
int s=1; s<=NS; s++){
326 if(q==2 && s>19)
continue;
327 if(q==4 && s>19)
continue;
328 if(plt==0 && slat>0 && slat!=s)
continue;
333 pad->SetRightMargin(mergin); pad->SetLeftMargin(mergin);
334 pad->SetTopMargin(mergin); pad->SetBottomMargin(mergin);
337 TText *t1=
new TText(0.75,0.05,Form(
"Q%1dS%02d",q,s)); t1->SetNDC(); t1->SetTextSize(0.12); t1->Draw();
339 TText *t2=
new TText(0.05,0.85,
"L1C0"); t2->SetNDC(); t2->SetTextSize(0.15); t2->SetTextColor(COL[0][0]); t2->Draw();
340 TText *t3=
new TText(0.20,0.85,
"L1C1"); t3->SetNDC(); t3->SetTextSize(0.15); t3->SetTextColor(COL[1][0]); t3->Draw();
341 TText *t4=
new TText(0.05,0.70,
"L2C0"); t4->SetNDC(); t4->SetTextSize(0.15); t4->SetTextColor(COL[0][1]); t4->Draw();
342 TText *t5=
new TText(0.20,0.70,
"L2C1"); t5->SetNDC(); t5->SetTextSize(0.15); t5->SetTextColor(COL[1][1]); t5->Draw();
343 TText *t6=
new TText(0.05,0.55,
"L3C0"); t6->SetNDC(); t6->SetTextSize(0.15); t6->SetTextColor(COL[0][2]); t6->Draw();
344 TText *t7=
new TText(0.20,0.55,
"L3C1"); t7->SetNDC(); t7->SetTextSize(0.15); t7->SetTextColor(COL[1][2]); t7->Draw();
348 for(
int ch=0; ch<2; ch++){
349 for(
int r=0; r<NRUN; r++){
350 if(run>0 && run!=r+1)
continue;
351 if(run==-1 && r!=NRUN-1)
continue;
352 plot(q,l,s,ch,r,k,plt);
361 sprintf(filename,
"plot/iv.Q%1d.Run%d.d.png",q,run);
362 c1->SaveAs(filename);
372 if(quad==0 && layer==0 && slat==0 && run==0){
373 sprintf(filename,
"plot/iv.png");
376 sprintf(filename,
"plot/iv-Q%1dL%1dS%1d.png",quad,layer,slat);
379 if(run==-1) r=NRUN-1;
380 sprintf(filename,
"plot/iv-Q%1dL%1dS%1d.%s.png",quad,layer,slat,DATE[r].Data()); }
382 c1->SaveAs(filename);