Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DigiHits_occupancy.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: /occupancy/digihits_trig1
6 // hnamepath: /occupancy/digihits_trig3
7 // hnamepath: /occupancy/digihits_trig4
8 // hnamepath: /occupancy/digihits_scale_factors
9 //
10 // e-mail: davidl@jlab.org
11 // e-mail: tbritton@jlab.org
12 //
13 
14 {
15 
16 // The following are empty versions of routines defined in RootSpy
17 // compiled executables. These are defined here for when this
18 // macro is run outside that context.
19 #ifndef ROOTSPY_MACROS
20 #define rs_SetFlag(A) cout<<"rs_SetFlag ignored outside of RootSpy context"<<endl
21 #define rs_GetFlag(A) 0
22 #define rs_ResetHisto(A) cout<<"rs_ResetHisto ignored outside of RootSpy context"<<endl
23 #define rs_RestoreHisto(A) cout<<"rs_RestoreHisto ignored outside of RootSpy context"<<endl
24 #define InsertSeriesData(A) cout<<"InsertSeriesData ignored outside of RootSpy context"<<endl
25 #define InsertSeriesMassFit(A,B,C,D,E,F) cout<<"InsertSeriesMassFit ignored outside of RootSpy context"<<endl
26 #endif
27 
28  // RootSpy saves the current directory and style before
29  // calling the macro and restores it after so it is OK to
30  // change them and not change them back.
31  TDirectory *savedir = gDirectory;
32 
33  // First get EventInfo which is used to get unix_time for time series DB
34  double unix_time = 0;
35  TDirectory *dir = (TDirectory*)gDirectory->FindObjectAny("highlevel");
36  if(dir) dir->cd();
37  TH1* EventInfo = (TH1*)gDirectory->Get("EventInfo");
38  if(EventInfo){
39  Double_t Nunix = EventInfo->GetBinContent(1);
40  if(Nunix>0.0){
41  Double_t sum_unix_time = EventInfo->GetBinContent(2);
42  unix_time = (sum_unix_time/Nunix);
43  time_t t = (time_t)unix_time;
44  cout << ctime(&t);
45  }
46  }
47 
48  // Get all other histos from occupancy
49  savedir->cd();
50  dir = (TDirectory*)gDirectory->FindObjectAny("occupancy");
51  if(dir) dir->cd();
52 
53  TH2I *digihits_trig1 = (TH2I*)gDirectory->FindObjectAny("digihits_trig1");
54  TH2I *digihits_trig3 = (TH2I*)gDirectory->FindObjectAny("digihits_trig3");
55  TH2I *digihits_trig4 = (TH2I*)gDirectory->FindObjectAny("digihits_trig4");
56  TH1F *digihits_scale_factors = (TH1F*)gDirectory->FindObjectAny("digihits_scale_factors");
57 
58  // Just for testing
59  if(gPad == NULL){
60  TCanvas *c1 = new TCanvas("c1", "", 1200, 900);
61  c1->cd(0);
62  c1->Draw();
63  c1->Update();
64  }
65  if(!gPad) {savedir->cd(); return;}
66 
67  // Some detectors are scaled in order to fit them on the same
68  // graph. The scale factors are communicated via the digihits_scale_factors
69  // histogram. Since RootSpy sums this histogram we must divide the bin contents
70  // by the last bin which keeps track of how many hists were added.
71  map<string,double> digihitbinmap; // bin number
72  map<string,double> digihitsclmap; // Scale number of hits by this (0 means don't scale)
73  if(digihits_scale_factors){
74  double Nhists_summed = digihits_scale_factors->GetBinContent(digihits_scale_factors->GetNbinsX());
75  TAxis *xaxis = digihits_scale_factors->GetXaxis();
76  for(int ibin=1; ibin<xaxis->GetNbins(); ibin++){
77  string lab = xaxis->GetBinLabel(ibin);
78  digihitbinmap[lab] = (double)ibin;
79  digihitsclmap[lab] = digihits_scale_factors->GetBinContent(ibin)/Nhists_summed;
80  }
81  }
82 
83  TCanvas *c1 = gPad->GetCanvas();
84 
85  c1->cd(0);
86  if(digihits_trig4){
87 
88  TPad *pad1 = (TPad*)gDirectory->FindObjectAny("digihitspad2");
89  if(!pad1) pad1 = new TPad("digihitspad2", "", 0.0, 0.0, 1.0, 0.5);
90  pad1->Draw();
91  pad1->cd();
92  pad1->SetTicks();
93  pad1->SetRightMargin(0.10);
94  pad1->SetLeftMargin(0.05);
95  pad1->SetBottomMargin(0.15);
96  pad1->SetTopMargin(0.05);
97  pad1->SetLogz();
98  digihits_trig4->SetStats(0);
99  digihits_trig4->SetTitle(" ");
100  digihits_trig4->GetXaxis()->SetLabelSize(0.06);
101  digihits_trig4->GetYaxis()->SetTitleSize(0.06);
102  digihits_trig4->GetYaxis()->SetTitleOffset(0.35);
103  digihits_trig4->Draw("colz");
104 
105  // Draw trigger label
106  TLatex latex;
107  latex.SetTextSize(0.07);
108  latex.SetTextAlign(12);
109  latex.DrawLatex(12.0, 115.0, "Trig 4: PS");
110 
111  // Draw any non-zero and non-one scale factors
112  latex.SetTextSize(0.04);
113  latex.SetTextAngle(90.0);
114  latex.SetTextAlign(22);
115  latex.SetTextColor(kWhite);
116  TBox box;
117  box.SetFillColor(kGray+1);
118  TAxis *xaxis = digihits_trig4->GetXaxis();
119  for(auto p : digihitsclmap){
120  if(p.second == 0.0) continue;
121  double x = xaxis->GetBinCenter((int)digihitbinmap[p.first]);
122  double y = 70.0;
123  char str[256];
124  if( p.second>1.0 ){
125  sprintf(str, "#divide%2.0f", p.second);
126  }else{
127  sprintf(str, "#times%2.0f", 1.0/p.second);
128  }
129  box.DrawBox(x-0.3, y-9.0, x+0.33, y+9.0);
130  latex.DrawLatex(x, y, str);
131  }
132 
133  // Draw mean number of hits
134  box.SetFillColor(kGray);
135  latex.SetTextColor(kBlack);
136  TAxis *yaxis = digihits_trig4->GetYaxis();
137  stringstream ss;
138  ss << "digihits,trig=4 ";
139  for(auto p : digihitbinmap){
140  int ibin = (int)digihitbinmap[p.first];
141  double x = xaxis->GetBinCenter(ibin);
142  double y = 139.0;
143 
144  double sum = 0.0;
145  double sumw = 0.0;
146  for(int jbin=1; jbin<=yaxis->GetNbins(); jbin++){
147  double w = digihits_trig4->GetBinContent(ibin, jbin);
148  double y = yaxis->GetBinLowEdge(jbin);
149  sumw += y*w;
150  sum += w;
151  }
152 
153  double mean = sum==0.0 ? 0.0:sumw/sum;
154  double scale = digihitsclmap[p.first];
155  if(scale != 0.0) mean *= scale;
156 
157  char str[256];
158  if( mean > 0.5 ){
159  sprintf(str, "%5.1f", mean);
160  }else{
161  sprintf(str, "%4.3f", mean);
162  }
163  box.DrawBox(x-0.3, y-10.0, x+0.33, y+10.0);
164  latex.DrawLatex(x, y, str);
165 
166  // Build time series string
167  if(digihits_scale_factors){
168  string lab = digihits_scale_factors->GetXaxis()->GetBinLabel(ibin);
169  if( ibin>1 ) ss << ",";
170  ss << lab << "=" << mean;
171  }
172  }
173 
174  // Only write out once every 100000 objects
175  if(digihits_trig4->Integral()>100000){
176  if(unix_time!=0.0) ss<<" "<<(uint64_t)(unix_time*1.0E9); // time is in units of ns
177  InsertSeriesData( ss.str() );
178 
179  // Optionally reset the histogram so next fit is independent of this one
180  if(rs_GetFlag("RESET_AFTER_FIT")) rs_ResetHisto("/occupancy/digihits_trig4");
181  }
182 
183  }
184 
185  c1->cd(0);
186  if(digihits_trig1){
187 
188  TPad *pad1 = (TPad*)gDirectory->FindObjectAny("digihitspad1");
189  if(!pad1) pad1 = new TPad("digihitspad1", "", 0.0, 0.5, 1.0, 1.0);
190  pad1->Draw();
191  pad1->cd();
192  pad1->SetTicks();
193  pad1->SetRightMargin(0.10);
194  pad1->SetLeftMargin(0.05);
195  pad1->SetBottomMargin(0.15);
196  pad1->SetTopMargin(0.05);
197  pad1->SetLogz();
198  digihits_trig1->SetStats(0);
199  digihits_trig1->SetTitle(" ");
200  digihits_trig1->GetXaxis()->SetLabelSize(0.06);
201  digihits_trig1->GetYaxis()->SetTitleSize(0.06);
202  digihits_trig1->GetYaxis()->SetTitleOffset(0.35);
203  digihits_trig1->Draw("colz");
204 
205  // Draw trigger label
206  TLatex latex;
207  latex.SetTextSize(0.07);
208  latex.SetTextAlign(12);
209  latex.DrawLatex(12.0, 115.0, "Trig 1: FCAL+BCAL");
210 
211  // Draw any non-zero and non-one scale factors
212  latex.SetTextSize(0.04);
213  latex.SetTextAngle(90.0);
214  latex.SetTextAlign(22);
215  latex.SetTextColor(kWhite);
216  TBox box;
217  box.SetFillColor(kGray+1);
218  TAxis *xaxis = digihits_trig1->GetXaxis();
219  for(auto p : digihitsclmap){
220  if(p.second == 0.0) continue;
221  double x = xaxis->GetBinCenter((int)digihitbinmap[p.first]);
222  double y = 70.0;
223  char str[256];
224  if( p.second>1.0 ){
225  sprintf(str, "#divide%2.0f", p.second);
226  }else{
227  sprintf(str, "#times%2.0f", 1.0/p.second);
228  }
229  box.DrawBox(x-0.3, y-9.0, x+0.33, y+9.0);
230  latex.DrawLatex(x, y, str);
231  }
232 
233  // Draw mean number of hits
234  box.SetFillColor(kGray);
235  latex.SetTextColor(kBlack);
236  TAxis *yaxis = digihits_trig1->GetYaxis();
237  stringstream ss;
238  ss << "digihits,trig=1 ";
239  for(auto p : digihitbinmap){
240  int ibin = (int)digihitbinmap[p.first];
241  double x = xaxis->GetBinCenter(ibin);
242  double y = 139.0;
243 
244  double sum = 0.0;
245  double sumw = 0.0;
246  for(int jbin=1; jbin<=yaxis->GetNbins(); jbin++){
247  double w = digihits_trig1->GetBinContent(ibin, jbin);
248  double y = yaxis->GetBinLowEdge(jbin);
249  sumw += y*w;
250  sum += w;
251  }
252 
253  double mean = sum==0.0 ? 0.0:sumw/sum;
254  double scale = digihitsclmap[p.first];
255  if(scale>0.0) mean *= scale;
256 
257  char str[256];
258  if( mean > 0.5 ){
259  sprintf(str, "%5.1f", mean);
260  }else{
261  sprintf(str, "%4.3f", mean);
262  }
263  box.DrawBox(x-0.3, y-10.0, x+0.33, y+10.0);
264  latex.DrawLatex(x, y, str);
265 
266  // Build time series string
267  if(digihits_scale_factors){
268  string lab = digihits_scale_factors->GetXaxis()->GetBinLabel(ibin);
269  if( ibin>1 ) ss << ",";
270  ss << lab << "=" << mean;
271  }
272  }
273 
274  // Only write out once every 100000 objects
275  if(digihits_trig1->Integral()>100000){
276  if(unix_time!=0.0) ss<<" "<<(uint64_t)(unix_time*1.0E9); // time is in units of ns
277  InsertSeriesData( ss.str() );
278 
279  // Optionally reset the histogram so next fit is independent of this one
280  if(rs_GetFlag("RESET_AFTER_FIT")) rs_ResetHisto("/occupancy/digihits_trig1");
281  }
282  }
283 }
284 
285 
#define rs_ResetHisto(A)
#define rs_GetFlag(A)
char str[256]
Double_t x[NCHANNELS]
Definition: st_tw_resols.C:39
sprintf(text,"Post KinFit Cut")
#define y
map< string, double > digihitsclmap
TVirtualPad * pad1
#define InsertSeriesData(A)
TH1 * EventInfo
Double_t c1[2][NMODULES]
Definition: tw_corr.C:68
double unix_time
TDirectory * savedir
TDirectory * dir
Definition: bcal_hist_eff.C:31
map< string, double > digihitbinmap