Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
daq_words_compare.C
Go to the documentation of this file.
1 
2 // The following are special comments used by RootSpy to know
3 // which histograms to fetch for the macro.
4 //
5 // hnamepath: /DAQ/daq_words_by_type
6 
7 void daq_words_compare(string fname1="hd_rawdata_031000_001.root", string fname2="hdl3_031000_001.root")
8 {
9  TFile *f1 = new TFile(fname1.c_str());
10  TH1D *daq_words_by_type1 = (TH1D*)gROOT->FindObject("daq_words_by_type");
11  if(!daq_words_by_type1){
12  cout << "Can't find 'daq_words_by_type' histogram in" << fname1 << " !" << endl;
13  return;
14  }
15 
16  TFile *f2 = new TFile(fname2.c_str());
17  TH1D *daq_words_by_type2 = (TH1D*)gROOT->FindObject("daq_words_by_type");
18  if(!daq_words_by_type2){
19  cout << "Can't find 'daq_words_by_type' histogram in" << fname2 << " !" << endl;
20  return;
21  }
22 
23  TCanvas *c1 = new TCanvas("c1", "", 1800, 800);
24  c1->Draw();
25 
26  gPad->SetTopMargin(0.13);
27  gPad->SetBottomMargin(0.3);
28  gPad->SetLeftMargin(0.05);
29  gPad->SetRightMargin(0.02);
30  gPad->GetCanvas()->SetTicks();
31  gPad->GetCanvas()->SetLogy();
32 
33  // Set max so maximum bin (not including total words bin
34  // which should be highest) is at 55%
35 
36  double mid1 = daq_words_by_type1->GetMaximum(daq_words_by_type1->GetMaximum());
37  double mid2 = daq_words_by_type2->GetMaximum(daq_words_by_type2->GetMaximum());
38  double mid = mid1>mid2 ? mid1:mid2;
39  double min = 1.0;
40  double max = pow(10.0, (1.0/0.65)*(log10(mid)-log10(min) + log10(min)));
41 
42  daq_words_by_type1->SetStats(0);
43  daq_words_by_type1->SetYTitle("Total number of 32-bit words");
44  daq_words_by_type1->GetYaxis()->SetTitleOffset(0.6);
45  daq_words_by_type1->GetYaxis()->SetRangeUser(min, max);
46  daq_words_by_type1->SetFillColor(kBlue);
47  daq_words_by_type1->SetBarWidth(0.43);
48  daq_words_by_type1->SetBarOffset(0.07);
49  daq_words_by_type1->Draw("bar");
50 
51  daq_words_by_type2->SetFillColor(kRed);
52  daq_words_by_type2->SetBarWidth(0.43);
53  daq_words_by_type2->SetBarOffset(0.5);
54  daq_words_by_type2->Draw("same bar");
55 
56  double ylab = max;
57 
58  TLatex latex;
59  latex.SetTextSize(0.030);
60  latex.SetTextAngle(90.0);
61 
62  Int_t Nbins = daq_words_by_type1->GetNbinsX();
63  double Nword_tot1 = daq_words_by_type1->GetBinContent(Nbins-1);
64  double Nword_tot2 = daq_words_by_type2->GetBinContent(Nbins-1);
65  double Nevents1 = daq_words_by_type1->GetBinContent(Nbins);
66  double Nevents2 = daq_words_by_type2->GetBinContent(Nbins);
67  double Nunknown1 = daq_words_by_type1->GetBinContent(2);
68  double sum = 0;
69  for(int ibin=1; ibin<=Nbins-2; ibin++){
70 
71  double x = daq_words_by_type1->GetXaxis()->GetBinCenter(ibin);
72  double Nwords = daq_words_by_type1->GetBinContent(ibin);
73  double percent = 100.0 * Nwords / Nword_tot1;
74 
75  if(Nwords == 0) continue;
76 
77  sum += Nwords;
78 
79  char str[256];
80  sprintf(str, "%4.1f%%", percent);
81  if(ibin < Nbins-2) sprintf(str, "%s _{(%3.1f%% total)}", str, 100.0*sum/Nword_tot1);
82  latex.SetTextAlign(32);
83  latex.SetTextColor(kBlue);
84  latex.SetTextSize(0.030);
85  latex.DrawLatex( x, ylab, str);
86 
87  x = daq_words_by_type2->GetXaxis()->GetBinCenter(ibin);
88  Nwords = daq_words_by_type2->GetBinContent(ibin);
89  percent = 100.0 * Nwords / Nword_tot2;
90  sprintf(str, "%4.1f%%", percent);
91  latex.SetTextAlign(12);
92  latex.SetTextColor(kRed);
93  latex.SetTextSize(0.020);
94  latex.DrawLatex( x, ylab, str);
95  }
96 
97  // Print avg. event sizes
98  double event_size1 = Nword_tot1/Nevents1*4.0/1024.0;
99  double event_size2 = Nword_tot2/Nevents2*4.0/1024.0;
100  char es_str1[256];
101  char es_str2[256];
102  sprintf(es_str1, "%4.1f kB/evt", event_size1);
103  sprintf(es_str2, "%4.1f kB/evt", event_size2);
104  double x = daq_words_by_type1->GetXaxis()->GetBinCenter(Nbins-1);
105  double dx = daq_words_by_type1->GetXaxis()->GetBinWidth(1);
106  double y = pow(10.0, 0.55*(log10(mid)-log10(min)) + log10(mid));
107  latex.SetTextAlign(12);
108  latex.SetTextSize(0.020);
109  latex.SetTextColor(kBlue);
110  latex.DrawLatex( x-dx/1.5, y, es_str1);
111  latex.SetTextAlign(12);
112  latex.SetTextSize(0.020);
113  latex.SetTextColor(kRed);
114  latex.DrawLatex( x, y, es_str2);
115 
116 
117  double y_one_percent = 0.01*Nword_tot1;
118  TLine *lin = new TLine(0.0, y_one_percent, (double)Nbins, y_one_percent);
119  lin->SetLineColor(kMagenta);
120  lin->Draw();
121 
122  cout << " sum: " << sum << endl;
123  cout << " Nword_tot: " << Nword_tot1 << endl;
124  cout << " missing: " << (Nword_tot1-sum)/Nword_tot1*100.0 << "%" << endl;
125  cout << " Event Size: " << (double)Nword_tot1/(double)Nevents1*4.0/1024.0 << " kB/event" << endl;
126  cout << " Nunknown/event: " << (double)Nunknown1/(double)Nevents1 << " bytes" << endl;
127 
128  latex.SetTextAngle(0);
129  latex.SetTextAlign(11);
130  latex.SetTextSize(0.025);
131  latex.SetTextColor(kBlue);
132  ylab = pow(10.0, 1.17*log10(max/min) + log10(min));
133  latex.DrawLatex(60.0, ylab, fname1.c_str());
134 
135  latex.SetTextColor(kRed);
136  ylab = pow(10.0, 1.12*log10(max/min) + log10(min));
137  latex.DrawLatex(60.0, ylab, fname2.c_str());
138 
139  c1->SaveAs("daq_words_compare.png");
140  c1->SaveAs("daq_words_compare.pdf");
141 }
142 
char str[256]
Double_t x[NCHANNELS]
Definition: st_tw_resols.C:39
sprintf(text,"Post KinFit Cut")
#define y
Double_t c1[2][NMODULES]
Definition: tw_corr.C:68
void daq_words_compare(string fname1="hd_rawdata_031000_001.root", string fname2="hdl3_031000_001.root")
TFile f1(fnam)
TF1 * f2
Definition: FitGains.C:28