OnMonAnaTestStandHistos.C
Go to the documentation of this file.
1 #include <TFile.h>
2 #include <TTree.h>
3 #include <TLine.h>
4 #include <TText.h>
5 #include <TArrow.h>
6 #include <TChain.h>
7 #include <TMarker.h>
8 #include <TCanvas.h>
9 #include <TNtuple.h>
10 #include <TLegend.h>
11 #include <TH1.h>
12 #include <TH2.h>
13 #include <TH1F.h>
14 #include <TH2F.h>
15 #include <TGraph.h>
16 #include <TH1D.h>
17 #include <TProfile.h>
18 #include <TColor.h>
19 #include <TMultiGraph.h>
20 #include <TPaveText.h>
21 #include "TStyle.h"
22 #include <iostream>
23 #include <fstream>
24 #include <vector>
25 #include "/home/novasoft/onmon_testrel_CR13-07-29/OnlineMonitoring/ana/RateSummaryNt.h"
26 
27 // do gSystem->Load("libOnlineMonitoringAna.so");
28 // load .L OnMonAnaTestStandHistos.C+
29 // then MakeTestStandPlots()
30 
32 {
33  std::cout << "\n\nMaking plots for all runs...\n\n";
34 
35  /* Plot Color Options
36  */
37  int colors[33];
38  colors[0]=632;//red
39  colors[1]=920+2;//gray
40  colors[2]=632-7;//red
41  colors[3]=900+5;//pink
42  colors[4]=400-6;//yellow
43  colors[5]=616;//mgnt
44  colors[6]=616+2;//mgnt
45  colors[7]=616-6;//mgnt
46  colors[8]=800+10;//orange
47  colors[9]=880-7;//violet
48  colors[10]=600;//blue
49  colors[11]=600+2;//blue
50  colors[12]=600-3;//blue
51  colors[13]=600+3;//blue
52  colors[14]=600-6;//blue
53  colors[15]=860+7;//azure
54  colors[16]=432+1;//cyan
55  colors[17]=880-5;//violet
56  colors[18]=432-6;//cyan
57  colors[19]=416;//green
58  colors[20]=416+3;//green
59  colors[21]=416-6;//green
60  colors[22]=416+2;//green
61  colors[23]=820-5;//spring
62  colors[24]=820-7;//spring
63  colors[25]=820+4;//spring
64  colors[26]=400+2;//yellow
65  colors[27]=400+3;//yellow
66  colors[28]=800+7;//orange
67  colors[29]=632+2;//red
68  colors[30]=860+7;//azure
69  colors[31]=900+6;//pink
70  colors[32]=800+4;//orange
71 
72  const Int_t NRGBs = 3;
73  const Int_t NCont = 255;
74  Double_t stops[NRGBs] = { 0.00, 0.34, 1.00};
75  Double_t red[NRGBs] = { 1.00, 1.00, 0.60};
76  Double_t green[NRGBs] = { 0.97, 0.40, 0.00};
77  Double_t blue[NRGBs] = { 0.99, 0.70, 0.00};
78 
79  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
80  gStyle->SetNumberContours(NCont);
81  //...............
82  /* Get run info from file
83  */
84 
85  std::ifstream in;
86  in.open("/home/novasoft/onmon_testrel_CR13-07-29/OnMon_teststand_results/current_runs.txt");
87 
88  int run, sr, hw, hc, newData, Nbins;
89  std::vector<int> runList;
90  std::vector<int> srList;
91  std::vector<int> hwList;
92  std::vector<int> hcList;
93  std::vector<int> newDataList;
94  std::vector<int> startBin;
95 
96  // read information in from text file on disk
97  while(in.good()) {
98  in >> run;
99  in >> sr;
100  in >> hw;
101  in >> hc;
102  in >> newData;
103 
104  runList.push_back(run);
105  srList .push_back(sr);
106  hwList .push_back(hw);
107  hcList .push_back(hc);
108  newDataList.push_back(newData);
109  }
110 
111  // sort lists by run number ?
112  // make startBin list
113  int bin = 0;
114  for(unsigned int i = 0; i < runList.size(); i++) {
115  startBin.push_back(bin);
116  bin += srList[i];
117  }
118  Nbins = startBin[runList.size()-1] + srList[runList.size()-1];
119 
120  /*
121  for(unsigned int i = 0; i < runList.size(); i++){
122  std::cout << "\nrun = " << runList[i] << "\tsubrun = " << srList[i]
123  << "\tnew hardware? = " << hwList[i] << "\tstartBin = " << startBin[i];
124  }
125  std::cout << "\nBINS = " << Nbins;
126  */
127 
128 
129  /* Chain Files
130  */
131  TChain ch("OnMonSummary");
132 
133  for(unsigned int i = 0; i < runList.size(); i++) {
134  char anafilename[200];
135  // sprintf(anafilename, "/nova/app/users/psihas/MyTestRel/results/TestStandAna/Summary-onmon_ana-subrun-%.3u-*.root", runList[i]);
136  sprintf(anafilename, "/home/novasoft/onmon_testrel_CR13-07-29/OnMon_teststand_results/onmon_ana_files/Summary-onmon_ana-subrun-%.3u-*.root", runList[i]);
137  ch.Add(anafilename);
138  std::cout << " Chained ana file : " << anafilename << std::endl;
139  }
140  //...............
141 
142  /* Initializing
143  */
144 
146  ch.SetBranchAddress("fRateSummaryNt", &Nt);
147 
148  unsigned int DB_size = 16;
149  unsigned int DCM_size = 13;
150  unsigned int FEB_size = 31;
151  unsigned int PIX_size = 33;
152  TH1D* PIXRates[DB_size][DCM_size][FEB_size][PIX_size];
153  TH1D* PIXMin[DB_size][DCM_size][FEB_size][PIX_size];
154  TH2D* HighRatesFEBs[DB_size][DCM_size];
155  TH2D* AllTheFEBs[DB_size][DCM_size];
156 
157  TH2D* EmptyPIXs[DB_size][DCM_size];
158  TH2D* MissingData[DB_size][DCM_size];
159 
160  std::cout << "\n\nInitializing histos... " << std::endl;
161  for(unsigned int i = 0; i < DB_size; ++i) {
162  for(unsigned int j = 0; j < DCM_size; ++j) {
163  HighRatesFEBs[i][j] = 0;
164  AllTheFEBs[i][j] = 0;
165  EmptyPIXs[i][j] = 0;
166  MissingData[i][j] = 0;
167  for(unsigned int k = 0; k < FEB_size; ++k) {
168  for(unsigned int l = 0; l < PIX_size; ++l) {
169  PIXRates[i][j][k][l] = 0;
170  PIXMin[i][j][k][l] = 0;
171  }
172  }
173  }
174  }
175 
176  int n_entries = ch.GetEntries();
177  std::cout << "\nLooping over " << n_entries << " entries..." <<std::endl;
178 
179  /* Fill Pixel and FEB level graphs with rates
180  */
181  int pastrun=0;
182  for (int i = 0; i < n_entries; ++i)
183  {
184  ch.GetEntry(i);
185  if(Nt->run!= pastrun){
186  std::cout << "Processing run " << Nt->run << std::endl;
187  pastrun=Nt->run;
188  }
189  // Calculate temp run number for plotting
190  int RUN=-1;
191  for(unsigned int s = 0; s < runList.size(); s++) {
192  if(Nt->run == runList[s]){
193  RUN= Nt->subrun + startBin[s];
194  s=runList.size()+1;
195  }
196  }
197 
198  if(PIXRates[Nt->db][Nt->dcm][Nt->feb][Nt->pix] == 0){
199  char histoname[30];
200  sprintf(histoname, "RatePIX_%.2u_%.2u_%.2u_%.2u", Nt->db, Nt->dcm, Nt->feb, Nt->pix);
201  PIXRates[Nt->db][Nt->dcm][Nt->feb][Nt->pix] = new TH1D(histoname, "Hit Rate in Pixels;run;rate (Hz)",
202  Nbins, 0, Nbins);
203  }
204  PIXRates[Nt->db][Nt->dcm][Nt->feb][Nt->pix]->Fill(RUN, Nt->rate);
205  if(PIXMin[Nt->db][Nt->dcm][Nt->feb][Nt->pix] == 0){
206  char histoname[30];
207  sprintf(histoname, "MinADCPIX_%.2u_%.2u_%.2u_%.2u", Nt->db, Nt->dcm, Nt->feb, Nt->pix);
208  PIXMin[Nt->db][Nt->dcm][Nt->feb][Nt->pix] = new TH1D(histoname, "Min ADC in Pixels;run;ADC",
209  Nbins, 0, Nbins);
210  }
211  PIXMin[Nt->db][Nt->dcm][Nt->feb][Nt->pix]->Fill(RUN, Nt->minADC);
212 
213  if(AllTheFEBs[Nt->db][Nt->dcm] == 0){
214  char ratehistoname[50];
215  sprintf(ratehistoname, "AllTheFEBs_%.2u_%.2u", Nt->db, Nt->dcm);
216  char ratehistotitle[100];
217  sprintf(ratehistotitle, "All rates on FEBs for DB%.2u DCM%.2u;run;FEB", Nt->db, Nt->dcm);
218  AllTheFEBs[Nt->db][Nt->dcm] = new TH2D(ratehistoname, ratehistotitle, Nbins, 0, Nbins, 31, 0, 31);
219  }
220  AllTheFEBs[Nt->db][Nt->dcm]->Fill(RUN,Nt->feb);
221  if(Nt->rate > 500){
222  if(HighRatesFEBs[Nt->db][Nt->dcm] == 0){
223  char hratehistoname[50];
224  sprintf(hratehistoname, "HighRateFEB_%.2u_%.2u", Nt->db, Nt->dcm);
225  char ratehistotitle[100];
226  sprintf(ratehistotitle, "Fraction of noise incidents per FEB (DB%.2u DCM%.2u);run;FEB", Nt->db, Nt->dcm);
227  HighRatesFEBs[Nt->db][Nt->dcm] = new TH2D(hratehistoname, ratehistotitle, Nbins, 0, Nbins, 31, 0, 31);
228  }
229  HighRatesFEBs[Nt->db][Nt->dcm]->Fill(RUN,Nt->feb);
230  }
231 
232  if(EmptyPIXs[Nt->db][Nt->dcm] == 0){
233  char emptyhistoname[50];
234  sprintf(emptyhistoname, "EmptyPIXs_%.2u_%.2u", Nt->db, Nt->dcm);
235  char emptyhistotitle[100];
236  sprintf(emptyhistotitle, "Empty PIXs for DB%.2u DCM%.2u;run;FEB", Nt->db, Nt->dcm);
237  EmptyPIXs[Nt->db][Nt->dcm] = new TH2D(emptyhistoname, emptyhistotitle, Nbins, 0, Nbins, 31, 0, 31);
238 
239  char mdhistoname[50];
240  sprintf(mdhistoname, "MissingData_%.2u_%.2u", Nt->db, Nt->dcm);
241  char mdhistotitle[100];
242  sprintf(mdhistotitle, "Missing Data for DB%.2u DCM%.2u;run;FEB", Nt->db, Nt->dcm);
243  MissingData[Nt->db][Nt->dcm] = new TH2D(mdhistoname, mdhistotitle, Nbins, 0, Nbins, 31, 0, 31);
244  }
245  if(Nt->rate == 0.0)
246  EmptyPIXs[Nt->db][Nt->dcm]->Fill(RUN,Nt->feb);
247 
248  }
249 
250  /* Compute Ratios
251  */
252  for(unsigned int i = 1; i < DB_size+1; ++i) {
253  for(unsigned int j = 1; j < DCM_size; ++j) {
254  if( AllTheFEBs[i][j] !=0 && HighRatesFEBs[i][j]!=0) HighRatesFEBs[i][j]->Divide(AllTheFEBs[i][j]);
255  }
256  }
257 
258 
259 
260  //
261  // Make missing data plot
262  //
263  for(unsigned int i = 1; i < DB_size+1; ++i) {
264  for(unsigned int j = 1; j < DCM_size; ++j) {
265  if( EmptyPIXs[i][j] !=0 ) {
266 
267  int NXbins = EmptyPIXs[i][j]->GetNbinsX();
268  int NYbins = EmptyPIXs[i][j]->GetNbinsY();
269 
270  for(int a = 1; a <= NXbins; ++a) {
271  for(int b = 1; b <= NYbins; ++b) {
272 
273  double bin1 = AllTheFEBs[i][j]->GetBinContent(AllTheFEBs[i][j]->GetBin(a,b));
274  double bin2 = EmptyPIXs[i][j]->GetBinContent(EmptyPIXs[i][j]->GetBin(a,b));
275 
276  if( bin1 == 0.0 || bin2 == 32.0 )
277  MissingData[i][j]->SetBinContent(a,b,1.0);
278 
279  }
280  }
281 
282  }
283  }
284  }
285 
286 
287  /* Display Pots
288  */
289  TCanvas* cAllDCMsDB1 = new TCanvas("AllDCMsDB1","AllDCMsDB1",1000,500);
290  cAllDCMsDB1->Divide(2);
291  cAllDCMsDB1->cd(1);
292  AllTheFEBs[1][1]->Draw("colz");
293  AllTheFEBs[1][1]->SetStats(0);
294  cAllDCMsDB1->cd(2);
295  HighRatesFEBs[1][1]->Draw("colz");
296  HighRatesFEBs[1][1]->SetStats(0);
297 
298  std::cout << "\nWriting AllRuns_AllDCMsDB1.png to disk.\n";
299  cAllDCMsDB1->Print("AllRuns_AllDCMsDB1.png");
300 
301 
302 
303  TCanvas* cHighRatesTestStandFEBsRatio = new TCanvas("HighRatesTestStandFEBs","cHighRatesTestStandFEBs",880,800);
304  MissingData[1][1]->SetTitle("Fraction of noise incidents per FEB (Test Stand)");
305  MissingData[1][1]->GetYaxis()->SetNdivisions(31);
306  MissingData[1][1]->GetYaxis()->SetLabelSize(0.015);
307  MissingData[1][1]->GetXaxis()->SetTickLength(0);
308  MissingData[1][1]->GetXaxis()->SetLabelColor(0);
309  MissingData[1][1]->GetXaxis()->SetLabelSize(0.02);
310  MissingData[1][1]->GetXaxis()->SetTitleSize(0.025);
311  MissingData[1][1]->GetYaxis()->SetTitleSize(0.025);
312  MissingData[1][1]->GetXaxis()->SetNdivisions(1,122, kFALSE);
313  MissingData[1][1]->SetMaximum(0.501);
314  MissingData[1][1]->SetFillColor(kGray);
315  MissingData[1][1]->Draw("box");
316  MissingData[1][1]->SetStats(0);
317 
318  HighRatesFEBs[1][1]->SetTitle("Fraction of noise incidents per FEB (Test Stand)");
319  HighRatesFEBs[1][1]->GetYaxis()->SetNdivisions(31);
320  HighRatesFEBs[1][1]->GetYaxis()->SetLabelSize(0.015);
321  HighRatesFEBs[1][1]->GetXaxis()->SetTickLength(0);
322  HighRatesFEBs[1][1]->GetXaxis()->SetLabelColor(0);
323  HighRatesFEBs[1][1]->GetXaxis()->SetLabelSize(0.02);
324  HighRatesFEBs[1][1]->GetXaxis()->SetTitleSize(0.025);
325  HighRatesFEBs[1][1]->GetYaxis()->SetTitleSize(0.025);
326  HighRatesFEBs[1][1]->GetXaxis()->SetNdivisions(1,122, kFALSE);
327  HighRatesFEBs[1][1]->SetMaximum(0.501);
328  HighRatesFEBs[1][1]->Draw("samecolz");
329  HighRatesFEBs[1][1]->SetStats(0);
330  cHighRatesTestStandFEBsRatio->SetGridy();
331 
332  for(unsigned int i = 0; i < runList.size(); i++) {
333  double y2 = 31;
334  TLine *line = new TLine(startBin[i], 0, startBin[i], y2);
335  line->SetLineStyle(2);
336  if(hwList[i] == 1){
337  line->SetLineWidth(2);
338  line->SetLineStyle(9);
339  }
340  line->Draw();
341  char buff[16];
342  sprintf(buff,"%.3d",runList[i]);
343  TText *t = new TText(startBin[i],-0.7,buff);
344  t->SetTextAlign(22);
345  t->SetTextFont(42);
346  t->SetTextSize(0.016);
347  t->SetTextAngle(90);
348  t->Draw();
349  TArrow *a = new TArrow(startBin[i],31.5,startBin[i]+1,31.5, 0.03, "|>");
350  a->SetLineWidth(3);
351  a->SetLineColor(kAzure-3);
352  a->SetFillColor(kAzure-3);
353  if(hcList[i] == 1){
354  a->SetLineColor(kRed);
355  a->SetFillColor(kRed);
356  }
357  a->SetArrowSize(0.01);
358  a->Draw();
359  }
360 
361  std::cout << "\nWriting AllRuns_TestStandFEBRates.png to disk.\n";
362  cHighRatesTestStandFEBsRatio->Print("AllRuns_TestStandFEBRates.png");
363 
364 
365 
366  DCM_size = 2;
367  //.............. Show plots with both parts
368  for(unsigned int i = 1; i < DCM_size; ++i) {
369  for(unsigned int j = 1; j < DCM_size; ++j) {
370 
371  TCanvas* CanvasP[FEB_size];
372  bool goodCanvas[FEB_size];
373 
374  for(unsigned int k = 0; k < FEB_size; ++k) {
375  // bool hascanvas=0, haspad=0;
376  bool haspad=0;
377 
378 
379  char name[40];
380  sprintf(name, "AllRuns_2PIXratesTestStandFEB_%.2u",k);
381  CanvasP[k] = new TCanvas(name,name,1167,600);
382  CanvasP[k]->SetLogy();
383  CanvasP[k]->cd(1);
384  CanvasP[k]->SetBottomMargin(0.40);
385 
386  goodCanvas[k] = false;
387 
388  for(unsigned int l = 0; l < PIX_size; ++l) {
389 
390  if( PIXRates[i][j][k][l] !=0) {
391  goodCanvas[k] = true;
392 
393  PIXRates[i][j][k][l]->SetLineColor(colors[l]);
394  PIXRates[i][j][k][l]->SetMarkerColor(colors[l]);
395  PIXRates[i][j][k][l]->SetMarkerStyle(34);
396  PIXRates[i][j][k][l]->SetAxisRange(0.01,1000000,"Y");
397  PIXRates[i][j][k][l]->SetMarkerColor(colors[l]);
398  PIXRates[i][j][k][l]->Draw("same, L");
399  PIXRates[i][j][k][l]->GetXaxis()->SetNdivisions(1,Nbins-1, kFALSE);
400  PIXRates[i][j][k][l]->GetXaxis()->SetTickLength(0);
401  PIXRates[i][j][k][l]->GetXaxis()->SetLabelColor(0);
402  PIXRates[i][j][k][l]->SetStats(0);
403  PIXRates[i][j][k][l]->SetTitle("");
404  TPaveText *pt = new TPaveText(0.12, 0.82, 0.25, 0.89, "NDC");
405  pt->AddText("Hit Rate in Pixels");
406  char address[30];
407  sprintf(address, "Test Stand FEB %.2u", k);
408  //title must include dcm & db if more than 1 !
409  pt->AddText(address);
410  pt->SetLineColor(kWhite);
411  pt->SetShadowColor(kWhite);
412  pt->SetFillColor(kWhite);
413  pt->Draw();
414  pt->SetTextFont(42);
415 
416  TLine *rate500 = new TLine(0,500,startBin[runList.size()-1]+srList[runList.size()-1],500);
417  rate500->SetLineWidth(2);
418  rate500->SetLineStyle(2);
419  rate500->Draw();
420 
421  for(unsigned int s = 0; s < runList.size(); s++) {
422  double y2 = 1000000;
423  if((double)startBin[s] < (double)(Nbins/6) ) y2=50000;
424  TLine *line = new TLine(startBin[s], 0, startBin[s], y2);
425  line->SetLineStyle(2);
426  if(hwList[s] == 1){
427  line->SetLineWidth(2);
428  line->SetLineStyle(9);
429  }
430  line->Draw();
431  TArrow *a = new TArrow(startBin[s],2000000,startBin[s]+1,2000000, 0.03, "|>");
432  a->SetLineWidth(3);
433  a->SetLineColor(kAzure-3);
434  a->SetFillColor(kAzure-3);
435  if(hcList[s] == 1){
436  a->SetLineColor(kRed);
437  a->SetFillColor(kRed);
438  }
439  a->SetArrowSize(0.01);
440  a->Draw();
441  } // end for s
442 
443  } // end if(pixrate != 0)
444  }//for pix
445 
446  for(unsigned int l = 0; l < PIX_size; ++l) {
447  if( PIXMin[i][j][k][l] !=0) {
448  if(haspad==0 && goodCanvas[k]){
449  TPad* pad = new TPad("pad", "pad", 0., 0., 1., 1.);
450  pad->SetTopMargin(0.63);
451  pad->SetFillColor(0);
452  pad->SetFillStyle(0);
453  pad->Draw();
454  pad->cd(0);
455  haspad=1;
456  }
457  PIXMin[i][j][k][l]->SetLineColor(colors[l]);
458  PIXMin[i][j][k][l]->SetTitle("");
459  PIXMin[i][j][k][l]->SetLineStyle(2);
460  PIXMin[i][j][k][l]->SetMarkerStyle(34);
461  PIXMin[i][j][k][l]->SetMarkerColor(colors[l]);
462  PIXMin[i][j][k][l]->SetAxisRange(0,200,"Y");
463  PIXMin[i][j][k][l]->Draw("same, L");
464  PIXMin[i][j][k][l]->SetStats(0);
465  PIXMin[i][j][k][l]->GetXaxis()->SetNdivisions(1,122, kFALSE);
466  PIXMin[i][j][k][l]->GetXaxis()->SetTickLength(0);
467  PIXMin[i][j][k][l]->GetXaxis()->SetLabelColor(0);
468  PIXMin[i][j][k][l]->GetYaxis()->SetNdivisions(504, kTRUE);
469  TPaveText *pt1 = new TPaveText(0.12, 0.3, 0.25, 0.36, "NDC");
470  pt1->AddText("Min ADC in Pixels");
471  char address[30];
472  sprintf(address, "Test Stand FEB%.2u", k);
473  // title must include dcm & db if more than 1 !
474  pt1->AddText(address);
475  pt1->SetLineColor(kWhite);
476  pt1->SetShadowColor(kWhite);
477  pt1->SetFillColor(kWhite);
478  pt1->Draw();
479  pt1->SetTextFont(42);
480  for(unsigned int s = 0; s < runList.size(); s++) {
481  double y2 = 200;
482  if((double)startBin[s] < (double)(Nbins/6) ) y2=150;
483  TLine *line = new TLine(startBin[s], 0, startBin[s], y2);
484  line->SetLineStyle(2);
485  if(hwList[s] == 1){
486  line->SetLineWidth(2);
487  line->SetLineStyle(9);
488  }
489  line->Draw();
490  char buff[16];
491  sprintf(buff,"%.3d",runList[s]);
492  TText *t = new TText(startBin[s],-20,buff);
493  t->SetTextAlign(22);
494  t->SetTextFont(42);
495  t->SetTextSize(0.016);
496  t->SetTextAngle(90);
497  t->Draw();
498  }
499  }
500  }//for pix
501 
502  char name2[40];
503  sprintf(name2, "AllRuns_2PIXratesTestStandFEB_%.2u.png",k);
504  if(goodCanvas[k]) {
505  std::cout << "Printing canvas: " << name2 << std::endl;
506  CanvasP[k]->Print(name2);
507  }
508 
509  }//for feb (loop over k)
510  }//for dcm (loop over j)
511  }//for db (loop over i)
512 
513 
514  /*
515  // Open output file for this subrun
516  char outfilename[100];
517  sprintf(outfilename, "/nova/app/users/psihas/MyTestRel/results/TestStandAna/Onmon_ana-HistosPIXMin-run%.2u-%.2u.root", runList[0], runList[runList.size()-1]);
518  TFile* out_file = new TFile(outfilename, "RECREATE");
519  std::cout << "Writting " << outfilename << std::endl;
520 
521  for(unsigned int i = 1; i < DB_size; ++i) {
522  for(unsigned int j = 1; j < DCM_size; ++j) {
523  if( AllTheFEBs[i][j] !=0 && HighRatesFEBs[i][j] !=0) {
524  HighRatesFEBs[i][j]->Write();
525  }
526  for(unsigned int k = 0; k < FEB_size; ++k) {
527  for(int l = 0; l < PIX_size; ++l) {
528  if( PIXRates[i][j][k][l] !=0) {
529  PIXRates[i][j][k][l]->Write();
530  PIXMin[i][j][k][l]->Write();
531  }
532  }
533  }
534  }
535  }
536 
537  out_file->Close();
538  */
539 
540 
541 }
542 
543 
544 
545 
547 {
548  std::cout << "\n\nMaking plots for new runs only...\n\n";
549 
550  /* Plot Color Options
551  */
552  int colors[33];
553  colors[0]=632;//red
554  colors[1]=920+2;//gray
555  colors[2]=632-7;//red
556  colors[3]=900+5;//pink
557  colors[4]=400-6;//yellow
558  colors[5]=616;//mgnt
559  colors[6]=616+2;//mgnt
560  colors[7]=616-6;//mgnt
561  colors[8]=800+10;//orange
562  colors[9]=880-7;//violet
563  colors[10]=600;//blue
564  colors[11]=600+2;//blue
565  colors[12]=600-3;//blue
566  colors[13]=600+3;//blue
567  colors[14]=600-6;//blue
568  colors[15]=860+7;//azure
569  colors[16]=432+1;//cyan
570  colors[17]=880-5;//violet
571  colors[18]=432-6;//cyan
572  colors[19]=416;//green
573  colors[20]=416+3;//green
574  colors[21]=416-6;//green
575  colors[22]=416+2;//green
576  colors[23]=820-5;//spring
577  colors[24]=820-7;//spring
578  colors[25]=820+4;//spring
579  colors[26]=400+2;//yellow
580  colors[27]=400+3;//yellow
581  colors[28]=800+7;//orange
582  colors[29]=632+2;//red
583  colors[30]=860+7;//azure
584  colors[31]=900+6;//pink
585  colors[32]=800+4;//orange
586 
587  const Int_t NRGBs = 3;
588  const Int_t NCont = 255;
589  Double_t stops[NRGBs] = { 0.00, 0.34, 1.00};
590  Double_t red[NRGBs] = { 1.00, 1.00, 0.60};
591  Double_t green[NRGBs] = { 0.97, 0.40, 0.00};
592  Double_t blue[NRGBs] = { 0.99, 0.70, 0.00};
593 
594  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
595  gStyle->SetNumberContours(NCont);
596  //...............
597  /* Get run info from file
598  */
599 
600  std::ifstream in;
601  in.open("/home/novasoft/onmon_testrel_CR13-07-29/OnMon_teststand_results/current_runs.txt");
602 
603  int run, sr, hw, hc, newData, Nbins;
604  std::vector<int> runList;
605  std::vector<int> srList;
606  std::vector<int> hwList;
607  std::vector<int> hcList;
608  std::vector<int> newDataList;
609  std::vector<int> startBin;
610 
611  // read information in from text file on disk
612  while(in.good()) {
613  in >> run;
614  in >> sr;
615  in >> hw;
616  in >> hc;
617  in >> newData;
618 
619  if(newData == 1) {
620  runList.push_back(run);
621  srList .push_back(sr);
622  hwList .push_back(hw);
623  hcList .push_back(hc);
624  newDataList.push_back(newData);
625  }
626  }
627 
628  // sort lists by run number ?
629  // make startBin list
630  int bin = 0;
631  for(unsigned int i = 0; i < runList.size(); i++) {
632  startBin.push_back(bin);
633  bin += srList[i];
634  }
635  Nbins = startBin[runList.size()-1] + srList[runList.size()-1];
636 
637  /*
638  for(unsigned int i = 0; i < runList.size(); i++){
639  std::cout << "\nrun = " << runList[i] << "\tsubrun = " << srList[i]
640  << "\tnew hardware? = " << hwList[i] << "\tstartBin = " << startBin[i];
641  }
642  std::cout << "\nBINS = " << Nbins;
643  */
644 
645 
646  /* Chain Files
647  */
648  TChain ch("OnMonSummary");
649 
650  for(unsigned int i = 0; i < runList.size(); i++) {
651  char anafilename[200];
652  // sprintf(anafilename, "/nova/app/users/psihas/MyTestRel/results/TestStandAna/Summary-onmon_ana-subrun-%.3u-*.root", runList[i]);
653  sprintf(anafilename, "/home/novasoft/onmon_testrel_CR13-07-29/OnMon_teststand_results/onmon_ana_files/Summary-onmon_ana-subrun-%.3u-*.root", runList[i]);
654  ch.Add(anafilename);
655  std::cout << " Chained ana file : " << anafilename << std::endl;
656  }
657  //...............
658 
659 
660 
661  /* Initializing
662  */
663 
665  ch.SetBranchAddress("fRateSummaryNt", &Nt);
666 
667  unsigned int DB_size = 16;
668  unsigned int DCM_size = 13;
669  unsigned int FEB_size = 31;
670  unsigned int PIX_size = 33;
671  TH1D* PIXRates[DB_size][DCM_size][FEB_size][PIX_size];
672  TH1D* PIXMin[DB_size][DCM_size][FEB_size][PIX_size];
673  TH2D* HighRatesFEBs[DB_size][DCM_size];
674  TH2D* AllTheFEBs[DB_size][DCM_size];
675 
676  TH2D* EmptyPIXs[DB_size][DCM_size];
677  TH2D* MissingData[DB_size][DCM_size];
678 
679  std::cout << "\n\nInitializing histos... " << std::endl;
680  for(unsigned int i = 0; i < DB_size; ++i) {
681  for(unsigned int j = 0; j < DCM_size; ++j) {
682  HighRatesFEBs[i][j] = 0;
683  AllTheFEBs[i][j] = 0;
684  EmptyPIXs[i][j] = 0;
685  MissingData[i][j] = 0;
686  for(unsigned int k = 0; k < FEB_size; ++k) {
687  for(unsigned int l = 0; l < PIX_size; ++l) {
688  PIXRates[i][j][k][l] = 0;
689  PIXMin[i][j][k][l] = 0;
690  }
691  }
692  }
693  }
694 
695  int n_entries = ch.GetEntries();
696  std::cout << "\nLooping over " << n_entries << " entries..." <<std::endl;
697 
698  /* Fill Pixel and FEB level graphs with rates
699  */
700  int pastrun=0;
701  for (int i = 0; i < n_entries; ++i)
702  {
703  ch.GetEntry(i);
704  if(Nt->run!= pastrun){
705  std::cout << "Processing run " << Nt->run << std::endl;
706  pastrun=Nt->run;
707  }
708  // Calculate temp run number for plotting
709  int RUN=-1;
710  for(unsigned int s = 0; s < runList.size(); s++) {
711  if(Nt->run == runList[s]){
712  RUN= Nt->subrun + startBin[s];
713  s=runList.size()+1;
714  }
715  }
716 
717  if(PIXRates[Nt->db][Nt->dcm][Nt->feb][Nt->pix] == 0){
718  char histoname[30];
719  sprintf(histoname, "RatePIX_%.2u_%.2u_%.2u_%.2u", Nt->db, Nt->dcm, Nt->feb, Nt->pix);
720  PIXRates[Nt->db][Nt->dcm][Nt->feb][Nt->pix] = new TH1D(histoname, "Hit Rate in Pixels;run;rate (Hz)",
721  Nbins, 0, Nbins);
722  }
723  PIXRates[Nt->db][Nt->dcm][Nt->feb][Nt->pix]->Fill(RUN, Nt->rate);
724  if(PIXMin[Nt->db][Nt->dcm][Nt->feb][Nt->pix] == 0){
725  char histoname[30];
726  sprintf(histoname, "MinADCPIX_%.2u_%.2u_%.2u_%.2u", Nt->db, Nt->dcm, Nt->feb, Nt->pix);
727  PIXMin[Nt->db][Nt->dcm][Nt->feb][Nt->pix] = new TH1D(histoname, "Min ADC in Pixels;run;ADC",
728  Nbins, 0, Nbins);
729  }
730  PIXMin[Nt->db][Nt->dcm][Nt->feb][Nt->pix]->Fill(RUN, Nt->minADC);
731 
732  if(AllTheFEBs[Nt->db][Nt->dcm] == 0){
733  char ratehistoname[50];
734  sprintf(ratehistoname, "AllTheFEBs_%.2u_%.2u", Nt->db, Nt->dcm);
735  char ratehistotitle[100];
736  sprintf(ratehistotitle, "All rates on FEBs for DB%.2u DCM%.2u;run;FEB", Nt->db, Nt->dcm);
737  AllTheFEBs[Nt->db][Nt->dcm] = new TH2D(ratehistoname, ratehistotitle, Nbins, 0, Nbins, 31, 0, 31);
738  }
739  AllTheFEBs[Nt->db][Nt->dcm]->Fill(RUN,Nt->feb);
740  if(Nt->rate > 500){
741  if(HighRatesFEBs[Nt->db][Nt->dcm] == 0){
742  char hratehistoname[50];
743  sprintf(hratehistoname, "HighRateFEB_%.2u_%.2u", Nt->db, Nt->dcm);
744  char ratehistotitle[100];
745  sprintf(ratehistotitle, "Fraction of noise incidents per FEB (DB%.2u DCM%.2u);run;FEB", Nt->db, Nt->dcm);
746  HighRatesFEBs[Nt->db][Nt->dcm] = new TH2D(hratehistoname, ratehistotitle, Nbins, 0, Nbins, 31, 0, 31);
747  }
748  HighRatesFEBs[Nt->db][Nt->dcm]->Fill(RUN,Nt->feb);
749  }
750 
751  if(EmptyPIXs[Nt->db][Nt->dcm] == 0){
752  char emptyhistoname[50];
753  sprintf(emptyhistoname, "EmptyPIXs_%.2u_%.2u", Nt->db, Nt->dcm);
754  char emptyhistotitle[100];
755  sprintf(emptyhistotitle, "Empty PIXs for DB%.2u DCM%.2u;run;FEB", Nt->db, Nt->dcm);
756  EmptyPIXs[Nt->db][Nt->dcm] = new TH2D(emptyhistoname, emptyhistotitle, Nbins, 0, Nbins, 31, 0, 31);
757 
758  char mdhistoname[50];
759  sprintf(mdhistoname, "MissingData_%.2u_%.2u", Nt->db, Nt->dcm);
760  char mdhistotitle[100];
761  sprintf(mdhistotitle, "Missing Data for DB%.2u DCM%.2u;run;FEB", Nt->db, Nt->dcm);
762  MissingData[Nt->db][Nt->dcm] = new TH2D(mdhistoname, mdhistotitle, Nbins, 0, Nbins, 31, 0, 31);
763  }
764  if(Nt->rate == 0.0)
765  EmptyPIXs[Nt->db][Nt->dcm]->Fill(RUN,Nt->feb);
766 
767  }
768 
769  /* Compute Ratios
770  */
771  for(unsigned int i = 1; i < DB_size+1; ++i) {
772  for(unsigned int j = 1; j < DCM_size; ++j) {
773  if( AllTheFEBs[i][j] !=0 && HighRatesFEBs[i][j]!=0) HighRatesFEBs[i][j]->Divide(AllTheFEBs[i][j]);
774  }
775  }
776 
777 
778 
779  //
780  // Make missing data plot
781  //
782  for(unsigned int i = 1; i < DB_size+1; ++i) {
783  for(unsigned int j = 1; j < DCM_size; ++j) {
784  if( EmptyPIXs[i][j] !=0 ) {
785 
786  int NXbins = EmptyPIXs[i][j]->GetNbinsX();
787  int NYbins = EmptyPIXs[i][j]->GetNbinsY();
788 
789  for(int a = 1; a <= NXbins; ++a) {
790  for(int b = 1; b <= NYbins; ++b) {
791 
792  double bin1 = AllTheFEBs[i][j]->GetBinContent(AllTheFEBs[i][j]->GetBin(a,b));
793  double bin2 = EmptyPIXs[i][j]->GetBinContent(EmptyPIXs[i][j]->GetBin(a,b));
794 
795  if( bin1 == 0.0 || bin2 == 32.0 )
796  MissingData[i][j]->SetBinContent(a,b,1.0);
797 
798  }
799  }
800 
801  }
802  }
803  }
804 
805 
806  /* Display Pots
807  */
808  TCanvas* cAllDCMsDB1 = new TCanvas("AllDCMsDB1","AllDCMsDB1",1000,500);
809  cAllDCMsDB1->Divide(2);
810  cAllDCMsDB1->cd(1);
811  AllTheFEBs[1][1]->Draw("colz");
812  AllTheFEBs[1][1]->SetStats(0);
813  cAllDCMsDB1->cd(2);
814  HighRatesFEBs[1][1]->Draw("colz");
815  HighRatesFEBs[1][1]->SetStats(0);
816 
817  std::cout << "\nWriting NewRuns_AllDCMsDB1.png to disk.\n";
818  cAllDCMsDB1->Print("NewRuns_AllDCMsDB1.png");
819 
820 
821 
822  TCanvas* cHighRatesTestStandFEBsRatio = new TCanvas("HighRatesTestStandFEBs","cHighRatesTestStandFEBs",880,800);
823  MissingData[1][1]->SetTitle("Fraction of noise incidents per FEB (Test Stand)");
824  MissingData[1][1]->GetYaxis()->SetNdivisions(31);
825  MissingData[1][1]->GetYaxis()->SetLabelSize(0.015);
826  MissingData[1][1]->GetXaxis()->SetTickLength(0);
827  MissingData[1][1]->GetXaxis()->SetLabelColor(0);
828  MissingData[1][1]->GetXaxis()->SetLabelSize(0.02);
829  MissingData[1][1]->GetXaxis()->SetTitleSize(0.025);
830  MissingData[1][1]->GetYaxis()->SetTitleSize(0.025);
831  MissingData[1][1]->GetXaxis()->SetNdivisions(1,122, kFALSE);
832  MissingData[1][1]->SetMaximum(0.501);
833  MissingData[1][1]->SetFillColor(kGray);
834  MissingData[1][1]->Draw("box");
835  MissingData[1][1]->SetStats(0);
836 
837  HighRatesFEBs[1][1]->SetTitle("Fraction of noise incidents per FEB (Test Stand)");
838  HighRatesFEBs[1][1]->GetYaxis()->SetNdivisions(31);
839  HighRatesFEBs[1][1]->GetYaxis()->SetLabelSize(0.015);
840  HighRatesFEBs[1][1]->GetXaxis()->SetTickLength(0);
841  HighRatesFEBs[1][1]->GetXaxis()->SetLabelColor(0);
842  HighRatesFEBs[1][1]->GetXaxis()->SetLabelSize(0.02);
843  HighRatesFEBs[1][1]->GetXaxis()->SetTitleSize(0.025);
844  HighRatesFEBs[1][1]->GetYaxis()->SetTitleSize(0.025);
845  HighRatesFEBs[1][1]->GetXaxis()->SetNdivisions(1,122, kFALSE);
846  HighRatesFEBs[1][1]->SetMaximum(0.501);
847  HighRatesFEBs[1][1]->Draw("samecolz");
848  HighRatesFEBs[1][1]->SetStats(0);
849  cHighRatesTestStandFEBsRatio->SetGridy();
850 
851  for(unsigned int i = 0; i < runList.size(); i++) {
852  double y2 = 31;
853  TLine *line = new TLine(startBin[i], 0, startBin[i], y2);
854  line->SetLineStyle(2);
855  if(hwList[i] == 1){
856  line->SetLineWidth(2);
857  line->SetLineStyle(9);
858  }
859  line->Draw();
860  char buff[16];
861  sprintf(buff,"%.3d",runList[i]);
862  TText *t = new TText(startBin[i],-0.7,buff);
863  t->SetTextAlign(22);
864  t->SetTextFont(42);
865  t->SetTextSize(0.016);
866  t->SetTextAngle(90);
867  t->Draw();
868  TArrow *a = new TArrow(startBin[i],31.5,startBin[i]+1,31.5, 0.03, "|>");
869  a->SetLineWidth(3);
870  a->SetLineColor(kAzure-3);
871  a->SetFillColor(kAzure-3);
872  if(hcList[i] == 1){
873  a->SetLineColor(kRed);
874  a->SetFillColor(kRed);
875  }
876  a->SetArrowSize(0.01);
877  a->Draw();
878  }
879 
880  std::cout << "\nWriting NewRuns_TestStandFEBRates.png to disk.\n";
881  cHighRatesTestStandFEBsRatio->Print("NewRuns_TestStandFEBRates.png");
882 
883 
884 
885  DCM_size = 2;
886  //.............. Show plots with both parts
887  for(unsigned int i = 1; i < DCM_size; ++i) {
888  for(unsigned int j = 1; j < DCM_size; ++j) {
889 
890  TCanvas* CanvasP[FEB_size];
891  bool goodCanvas[FEB_size];
892 
893  for(unsigned int k = 0; k < FEB_size; ++k) {
894  // bool hascanvas=0, haspad=0;
895  bool haspad=0;
896 
897  char name[40];
898  sprintf(name, "NewRuns_2PIXratesTestStandFEB_%.2u",k);
899  CanvasP[k] = new TCanvas(name,name,1167,600);
900  CanvasP[k]->SetLogy();
901  CanvasP[k]->cd(1);
902  CanvasP[k]->SetBottomMargin(0.40);
903 
904  goodCanvas[k] = false;
905 
906  for(unsigned int l = 0; l < PIX_size; ++l) {
907 
908  if( PIXRates[i][j][k][l] !=0) {
909  goodCanvas[k] = true;
910 
911  PIXRates[i][j][k][l]->SetLineColor(colors[l]);
912  PIXRates[i][j][k][l]->SetMarkerColor(colors[l]);
913  PIXRates[i][j][k][l]->SetMarkerStyle(34);
914  PIXRates[i][j][k][l]->SetAxisRange(0.01,1000000,"Y");
915  PIXRates[i][j][k][l]->SetMarkerColor(colors[l]);
916  PIXRates[i][j][k][l]->Draw("same, L");
917  PIXRates[i][j][k][l]->GetXaxis()->SetNdivisions(1,Nbins-1, kFALSE);
918  PIXRates[i][j][k][l]->GetXaxis()->SetTickLength(0);
919  PIXRates[i][j][k][l]->GetXaxis()->SetLabelColor(0);
920  PIXRates[i][j][k][l]->SetStats(0);
921  PIXRates[i][j][k][l]->SetTitle("");
922  TPaveText *pt = new TPaveText(0.12, 0.82, 0.25, 0.89, "NDC");
923  pt->AddText("Hit Rate in Pixels");
924  char address[30];
925  sprintf(address, "Test Stand FEB %.2u", k);
926  //title must include dcm & db if more than 1 !
927  pt->AddText(address);
928  pt->SetLineColor(kWhite);
929  pt->SetShadowColor(kWhite);
930  pt->SetFillColor(kWhite);
931  pt->Draw();
932  pt->SetTextFont(42);
933 
934  TLine *rate500 = new TLine(0,500,startBin[runList.size()-1]+srList[runList.size()-1],500);
935  rate500->SetLineWidth(2);
936  rate500->SetLineStyle(2);
937  rate500->Draw();
938 
939  for(unsigned int s = 0; s < runList.size(); s++) {
940  double y2 = 1000000;
941  if((double)startBin[s] < (double)(Nbins/6) ) y2=50000;
942  TLine *line = new TLine(startBin[s], 0, startBin[s], y2);
943  line->SetLineStyle(2);
944  if(hwList[s] == 1){
945  line->SetLineWidth(2);
946  line->SetLineStyle(9);
947  }
948  line->Draw();
949  TArrow *a = new TArrow(startBin[s],2000000,startBin[s]+1,2000000, 0.03, "|>");
950  a->SetLineWidth(3);
951  a->SetLineColor(kAzure-3);
952  a->SetFillColor(kAzure-3);
953  if(hcList[s] == 1){
954  a->SetLineColor(kRed);
955  a->SetFillColor(kRed);
956  }
957  a->SetArrowSize(0.01);
958  a->Draw();
959  } // end for s
960 
961  } // end if(pixrate != 0)
962  }//for pix
963 
964  for(unsigned int l = 0; l < PIX_size; ++l) {
965  if( PIXMin[i][j][k][l] !=0) {
966  if(haspad==0 && goodCanvas[k]){
967  TPad* pad = new TPad("pad", "pad", 0., 0., 1., 1.);
968  pad->SetTopMargin(0.63);
969  pad->SetFillColor(0);
970  pad->SetFillStyle(0);
971  pad->Draw();
972  pad->cd(0);
973  haspad=1;
974  }
975  PIXMin[i][j][k][l]->SetLineColor(colors[l]);
976  PIXMin[i][j][k][l]->SetTitle("");
977  PIXMin[i][j][k][l]->SetLineStyle(2);
978  PIXMin[i][j][k][l]->SetMarkerStyle(34);
979  PIXMin[i][j][k][l]->SetMarkerColor(colors[l]);
980  PIXMin[i][j][k][l]->SetAxisRange(0,200,"Y");
981  PIXMin[i][j][k][l]->Draw("same, L");
982  PIXMin[i][j][k][l]->SetStats(0);
983  PIXMin[i][j][k][l]->GetXaxis()->SetNdivisions(1,122, kFALSE);
984  PIXMin[i][j][k][l]->GetXaxis()->SetTickLength(0);
985  PIXMin[i][j][k][l]->GetXaxis()->SetLabelColor(0);
986  PIXMin[i][j][k][l]->GetYaxis()->SetNdivisions(504, kTRUE);
987  TPaveText *pt1 = new TPaveText(0.12, 0.3, 0.25, 0.36, "NDC");
988  pt1->AddText("Min ADC in Pixels");
989  char address[30];
990  sprintf(address, "Test Stand FEB%.2u", k);
991  // title must include dcm & db if more than 1 !
992  pt1->AddText(address);
993  pt1->SetLineColor(kWhite);
994  pt1->SetShadowColor(kWhite);
995  pt1->SetFillColor(kWhite);
996  pt1->Draw();
997  pt1->SetTextFont(42);
998  for(unsigned int s = 0; s < runList.size(); s++) {
999  double y2 = 200;
1000  if((double)startBin[s] < (double)(Nbins/6) ) y2=150;
1001  TLine *line = new TLine(startBin[s], 0, startBin[s], y2);
1002  line->SetLineStyle(2);
1003  if(hwList[s] == 1){
1004  line->SetLineWidth(2);
1005  line->SetLineStyle(9);
1006  }
1007  line->Draw();
1008  char buff[16];
1009  sprintf(buff,"%.3d",runList[s]);
1010  TText *t = new TText(startBin[s],-20,buff);
1011  t->SetTextAlign(22);
1012  t->SetTextFont(42);
1013  t->SetTextSize(0.016);
1014  t->SetTextAngle(90);
1015  t->Draw();
1016  }
1017  }
1018  }//for pix
1019 
1020  char name2[40];
1021  sprintf(name2, "NewRuns_2PIXratesTestStandFEB_%.2u.png",k);
1022  if(goodCanvas[k]) {
1023  std::cout << "Printing canvas: " << name2 << std::endl;
1024  CanvasP[k]->Print(name2);
1025  }
1026 
1027  }//for feb (loop over k)
1028  }//for dcm (loop over j)
1029  }//for db (loop over i)
1030 
1031 
1032  /*
1033  // Open output file for this subrun
1034  char outfilename[100];
1035  sprintf(outfilename, "/nova/app/users/psihas/MyTestRel/results/TestStandAna/Onmon_ana-HistosPIXMin-run%.2u-%.2u.root", runList[0], runList[runList.size()-1]);
1036  TFile* out_file = new TFile(outfilename, "RECREATE");
1037  std::cout << "Writting " << outfilename << std::endl;
1038 
1039  for(unsigned int i = 1; i < DB_size; ++i) {
1040  for(unsigned int j = 1; j < DCM_size; ++j) {
1041  if( AllTheFEBs[i][j] !=0 && HighRatesFEBs[i][j] !=0) {
1042  HighRatesFEBs[i][j]->Write();
1043  }
1044  for(unsigned int k = 0; k < FEB_size; ++k) {
1045  for(int l = 0; l < PIX_size; ++l) {
1046  if( PIXRates[i][j][k][l] !=0) {
1047  PIXRates[i][j][k][l]->Write();
1048  PIXMin[i][j][k][l]->Write();
1049  }
1050  }
1051  }
1052  }
1053  }
1054 
1055  out_file->Close();
1056  */
1057 
1058 
1059 }
const XML_Char * name
Definition: expat.h:151
enum BeamMode kRed
const XML_Char * s
Definition: expat.h:262
int colors[6]
Definition: tools.h:1
tuple blue
Definition: rootlogon.py:65
int NRGBs
Definition: rootlogon.py:77
const double a
int NCont
Definition: rootlogon.py:78
caf::StandardRecord * sr
const double j
Definition: BetheBloch.cxx:29
float bin[41]
Definition: plottest35.C:14
OStream cout
Definition: OStream.cxx:6
ifstream in
Definition: comparison.C:7
void MakeTestStandPlots_AllRuns()
const hit & b
Definition: hits.cxx:21
void MakeTestStandPlots_NewRuns()