Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hist_read.C
Go to the documentation of this file.
1 void hist_read(TString filename)
2 {
3 // Read histogram file and output offset constants to file
4 //
5 
6 #include <TRandom.h>
7 
8 gROOT->Reset();
9 //TTree *Bfield = (TTree *) gROOT->FindObject("Bfield");
10 gStyle->SetPalette(1,0);
11 gStyle->SetOptStat(kFALSE);
12 gStyle->SetOptStat(11111111);
13 gStyle->SetPadRightMargin(0.15);
14 gStyle->SetPadLeftMargin(0.15);
15 gStyle->SetPadBottomMargin(0.15);
16 //
17 
18  char string[256];
19  Int_t const nids=767;
20  Double_t const rms0=1;
21  Double_t const offset_down=23+10;
22  Double_t const offset_up=-23+10;
23  Int_t fail0=0;
24  Int_t fail1=0;
25 
26  // define histograms
27  TH1F *sigma = new TH1F ("sigma","Sigma",100,0,5);
28 
29  // read histograms from file
30 
31  // TString filename = "hd_rawdata_030494_fix";
32  // TString filename = "hd_rawdata_030964_005";
33  TString title = filename;
34 
35  // open file for output
36 
37  TString outfile = "dat/"+filename+".dat";
38  cout << "Opening text output file: " << outfile.Data() << endl;
39  TString outfile2 = "dat/"+filename+".dat2";
40  cout << "Opening constant output file: " << outfile.Data() << endl;
41 
42  ofstream filedat;
43  filedat.open (outfile.Data(), ios::out);
44  ofstream filedat2;
45  filedat2.open (outfile2.Data(), ios::out);
46 
47  TFile *in = new TFile(filename+".root","read");
48 
49  TDirectory *dir = (TDirectory*)gDirectory->FindObjectAny("BCAL_LED_time");
50  if(dir) {
51  dir->cd();
52  }
53  else {
54  cout << "*** Cannot find directory" << endl;
55  }
56 
57  TH1F *low_bias_down_time_vchannel = (TH1F*)gDirectory->FindObjectAny("low_bias_down_time_vchannel");
58  TH1F *low_bias_up_time_vchannel = (TH1F*)gDirectory->FindObjectAny("low_bias_up_time_vchannel");
59  TH1F *high_bias_down_time_vchannel = (TH1F*)gDirectory->FindObjectAny("high_bias_down_time_vchannel");
60  TH1F *high_bias_up_time_vchannel = (TH1F*)gDirectory->FindObjectAny("high_bias_up_time_vchannel");
61 
62  // retrieving information from the histogram
63 
64  Int_t ndim = low_bias_down_time_vchannel->GetNbinsX();
65  Double_t xlo = low_bias_down_time_vchannel->GetBinLowEdge(1);
66  Double_t width = low_bias_down_time_vchannel->GetBinWidth(1);
67  printf ("\nhist_read: ndim=%d, xlo=%f, width=%f\n\n",ndim,xlo,width);
68 
69  for(Int_t j=0;j<ndim;j++) {
70 
71  Int_t chid = low_bias_down_time_vchannel->GetBinCenter(j+1);
72 
73  // compute module, layer, sector
74 
75  Int_t module = chid/16 + 1;
76  Int_t layer = (chid - (module-1)*16)/4 + 1;
77  Int_t sector = (chid - (module-1)*16 - (layer-1)*4) +1;
78  // cout << " chid=" << chid << " module=" << module << " layer=" << layer << " sector=" << sector << endl;
79  Double_t tdiff_low_down = low_bias_down_time_vchannel->GetBinContent(j+1);
80  Double_t tdiff_low_up = low_bias_up_time_vchannel->GetBinContent(j+1);
81  Double_t tdiff_high_down = high_bias_down_time_vchannel->GetBinContent(j+1);
82  Double_t tdiff_high_up = high_bias_up_time_vchannel->GetBinContent(j+1);
83 
84  // subtract offset only if non-zero data are present
85 
86  tdiff_low_down = tdiff_low_down != 0? tdiff_low_down + offset_down : 0;
87  tdiff_low_up = tdiff_low_up != 0? tdiff_low_up + offset_up : 0;
88  tdiff_high_down = tdiff_high_down != 0? tdiff_high_down + offset_down : 0;
89  tdiff_high_up = tdiff_high_up != 0? tdiff_high_up + offset_up : 0;
90 
91  // compute rms
92  // Double_t sum = abs(tdiff_low_down) + abs(tdiff_low_up) + abs(tdiff_high_down) + abs(tdiff_high_up);
93  Double_t sum = tdiff_low_down + tdiff_low_up + tdiff_high_down + tdiff_high_up;
94  Double_t sum2 = tdiff_low_down*tdiff_low_down + tdiff_low_up*tdiff_low_up + tdiff_high_down*tdiff_high_down + tdiff_high_up*tdiff_high_up;
95  Double_t sum1 = 0;
96  sum1 = abs(tdiff_low_down)>0? sum1+1 : sum1;
97  sum1 = abs(tdiff_low_up)>0? sum1+1 : sum1;
98  sum1 = abs(tdiff_high_down)>0? sum1+1 : sum1;
99  sum1 = abs(tdiff_high_up)>0? sum1+1 : sum1;
100  Double_t rms = sum1 > 0? sqrt(sum2/sum1 - sum*sum/sum1/sum1): 0;
101  sigma->Fill(rms);
102 
103  sprintf (string,"chid low_down low_up high_down high_up rms %4d %4d %4d %4d %10.2f %10.2f %10.2f %10.2f %10.4f",chid,module,layer,sector,tdiff_low_down,tdiff_low_up,tdiff_high_down,tdiff_high_up,rms);
104  if (rms > rms0 | rms ==0) {
105  // cout << "***hist_read: chid=" << chid << " rms=" << rms << endl;
106  printf ("%s ***\n",string);
107  if (rms > rms0) fail1++;
108  if (rms == 0) fail0++;
109  filedat << string << " ***" << endl;
110  }
111  else {
112  filedat << string << endl;
113  }
114  // output average value to constant file. Add one line for each end:
115  Double_t average = sum1 > 0? sum/sum1 : 0;
116  filedat2 << chid*2 << "\t" << 0 << endl;
117  filedat2 << chid*2 + 1 << "\t" << average << endl;
118 
119  }
120 
121  cout << "*** Fails: N(rms==0):" << fail0 << ", N(rms > rms0):" << fail1 << endl;
122  filedat << "*** Fails: N(rms==0):" << fail0 << ", N(rms > rms0):" << fail1 << endl;
123 
124  //
125  TCanvas *c0 = new TCanvas("c0","c0 hist_read",200,10,1200,700);
126  c0->Divide(3,2);
127 
128  c0->cd(1);
129 
130  low_bias_down_time_vchannel->SetTitle(title);
131  // low_bias_down_time_vchannel->GetXaxis()->SetRangeUser(xmin,xmax);
132  // low_bias_down_time_vchannel->GetYaxis()->SetRangeUser(ymin,ymax);
133  low_bias_down_time_vchannel->GetXaxis()->SetTitleSize(0.05);
134  low_bias_down_time_vchannel->GetYaxis()->SetTitleSize(0.05);
135  low_bias_down_time_vchannel->GetXaxis()->SetTitle("Low Down - chid");
136  low_bias_down_time_vchannel->GetYaxis()->SetTitle("Time Difference (Down-Up) (ns)");
137  low_bias_down_time_vchannel->SetMarkerColor(2);
138  low_bias_down_time_vchannel->SetMarkerStyle(20);
139  low_bias_down_time_vchannel->SetMarkerSize(0.5);
140  low_bias_down_time_vchannel->Draw("");
141 
142  /*sprintf(string,"CMS Phys Lett B 716 (2012) 30");
143  printf("string=%s\n",string);
144  t1 = new TLatex(0.15,0.92,string);
145  t1->SetNDC();
146  t1->SetTextSize(0.03);
147  t1->Draw();*/
148 
149  c0->cd(2);
150 
151  low_bias_up_time_vchannel->SetTitle("");
152  // low_bias_up_time_vchannel->GetXaxis()->SetRangeUser(xmin,xmax);
153  // low_bias_up_time_vchannel->GetYaxis()->SetRangeUser(ymin,ymax);
154  low_bias_up_time_vchannel->GetXaxis()->SetTitleSize(0.05);
155  low_bias_up_time_vchannel->GetYaxis()->SetTitleSize(0.05);
156  low_bias_up_time_vchannel->GetXaxis()->SetTitle("Low Up - chid");
157  low_bias_up_time_vchannel->GetYaxis()->SetTitle("Time Difference (Down-Up) (ns)");
158  low_bias_up_time_vchannel->SetMarkerColor(2);
159  low_bias_up_time_vchannel->SetMarkerStyle(20);
160  low_bias_up_time_vchannel->SetMarkerSize(0.5);
161  low_bias_up_time_vchannel->Draw("");
162 
163  c0->cd(3);
164 
165  high_bias_down_time_vchannel->SetTitle("");
166  // high_bias_down_time_vchannel->GetXaxis()->SetRangeUser(xmin,xmax);
167  // high_bias_down_time_vchannel->GetYaxis()->SetRangeUser(ymin,ymax);
168  high_bias_down_time_vchannel->GetXaxis()->SetTitleSize(0.05);
169  high_bias_down_time_vchannel->GetYaxis()->SetTitleSize(0.05);
170  high_bias_down_time_vchannel->GetXaxis()->SetTitle("High Down - chid");
171  high_bias_down_time_vchannel->GetYaxis()->SetTitle("Time Difference (Down-Up) (ns)");
172  high_bias_down_time_vchannel->SetMarkerColor(2);
173  high_bias_down_time_vchannel->SetMarkerStyle(20);
174  high_bias_down_time_vchannel->SetMarkerSize(0.5);
175  high_bias_down_time_vchannel->Draw("");
176 
177  c0->cd(4);
178 
179  high_bias_up_time_vchannel->SetTitle("");
180  // high_bias_up_time_vchannel->GetXaxis()->SetRangeUser(xmin,xmax);
181  // high_bias_up_time_vchannel->GetYaxis()->SetRangeUser(ymin,ymax);
182  high_bias_up_time_vchannel->GetXaxis()->SetTitleSize(0.05);
183  high_bias_up_time_vchannel->GetYaxis()->SetTitleSize(0.05);
184  high_bias_up_time_vchannel->GetXaxis()->SetTitle("High Up - chid");
185  high_bias_up_time_vchannel->GetYaxis()->SetTitle("Time Difference (Down-Up) (ns)");
186  high_bias_up_time_vchannel->SetMarkerColor(2);
187  high_bias_up_time_vchannel->SetMarkerStyle(20);
188  high_bias_up_time_vchannel->SetMarkerSize(0.5);
189  high_bias_up_time_vchannel->Draw("");
190 
191  c0->cd(5);
192  gPad->SetLogy();
193 
194  sigma->SetTitle("");
195  // sigma->GetXaxis()->SetRangeUser(xmin,xmax);
196  // sigma->GetYaxis()->SetRangeUser(ymin,ymax);
197  sigma->GetXaxis()->SetTitleSize(0.05);
198  sigma->GetYaxis()->SetTitleSize(0.05);
199  sigma->GetYaxis()->SetTitle("Entries");
200  sigma->GetXaxis()->SetTitle("Sigma between configurations");
201  sigma->SetLineColor(2);
202  sigma->Draw("");
203 
204 
205  c0->SaveAs("plots/"+filename+"_plots.pdf");
206 
207  filedat.close(); // close text file
208  filedat2.close(); // close text file
209 
210 
211  // in->Close();
212 
213 }
214 
Double_t c0[2][NMODULES]
Definition: tw_corr.C:67
void hist_read(TString filename)
Definition: hist_read.C:1
Int_t layer
sprintf(text,"Post KinFit Cut")
TString filename
TFile * outfile
Definition: tw_corr.C:46
Double_t sigma[NCHANNELS]
Definition: st_tw_resols.C:37
double sqrt(double)
TDirectory * dir
Definition: bcal_hist_eff.C:31
printf("string=%s", string)