Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TOF_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/tof_num_events
6 // hnamepath: /occupancy/tof_adc_S_occ
7 // hnamepath: /occupancy/tof_adc_N_occ
8 // hnamepath: /occupancy/tof_adc_U_occ
9 // hnamepath: /occupancy/tof_adc_D_occ
10 // hnamepath: /occupancy/tof_tdc_S_occ
11 // hnamepath: /occupancy/tof_tdc_N_occ
12 // hnamepath: /occupancy/tof_tdc_U_occ
13 // hnamepath: /occupancy/tof_tdc_D_occ
14 //
15 // e-mail: davidl@jlab.org
16 // e-mail: zihlmann@jlab.org
17 // e-mail: marki@jlab.org
18 // e-mail: tbritton@jlab.org
19 //
20 
21 {
22  // RootSpy saves the current directory and style before
23  // calling the macro and restores it after so it is OK to
24  // change them and not change them back.
25  TDirectory *savedir = gDirectory;
26  TDirectory *dir = (TDirectory*)gDirectory->FindObjectAny("occupancy");
27  if(dir) dir->cd();
28 
29  double Nevents = 1.0;
30  TH1I *tof_num_events = (TH1I*)gDirectory->FindObjectAny("tof_num_events");
31  if(tof_num_events) Nevents = (double)tof_num_events->GetBinContent(1);
32 
33  TH1I *ha_s = (TH1I*)gDirectory->FindObjectAny("tof_adc_S_occ");
34  TH1I *ha_n = (TH1I*)gDirectory->FindObjectAny("tof_adc_N_occ");
35  TH1I *ha_u = (TH1I*)gDirectory->FindObjectAny("tof_adc_U_occ");
36  TH1I *ha_d = (TH1I*)gDirectory->FindObjectAny("tof_adc_D_occ");
37 
38  TH1I *h_s = (TH1I*)gDirectory->FindObjectAny("tof_tdc_S_occ");
39  TH1I *h_n = (TH1I*)gDirectory->FindObjectAny("tof_tdc_N_occ");
40  TH1I *h_u = (TH1I*)gDirectory->FindObjectAny("tof_tdc_U_occ");
41  TH1I *h_d = (TH1I*)gDirectory->FindObjectAny("tof_tdc_D_occ");
42 
43  TLegend *legend_sa = new TLegend(0.1,0.85,0.3,0.9);
44  TLegend *legend_na = new TLegend(0.3,0.85,0.5,0.9);
45  TLegend *legend_ua = new TLegend(0.5,0.85,0.7,0.9);
46  TLegend *legend_da = new TLegend(0.7,0.85,0.9,0.9);
47 
48  TLegend *legend_s = new TLegend(0.1,0.85,0.3,0.9);
49  TLegend *legend_n = new TLegend(0.3,0.85,0.5,0.9);
50  TLegend *legend_u = new TLegend(0.5,0.85,0.7,0.9);
51  TLegend *legend_d = new TLegend(0.7,0.85,0.9,0.9);
52 
53  if(ha_s){
54  ha_s->SetBarWidth(0.5);
55  ha_s->SetBarOffset(0);
56  ha_s->SetFillColor(2);
57  ha_s->SetStats(0);
58  ha_s->SetXTitle("Module number");
59  ha_s->SetYTitle("fADC occupancy");
60  ha_s->SetTitleSize(0.05,"X");
61  ha_s->GetXaxis()->CenterTitle();
62  ha_s->SetTitleSize(0.05,"Y");
63  ha_s->GetYaxis()->CenterTitle();
64  }
65 
66  if(ha_n){
67  ha_n->SetBarWidth(0.5);
68  ha_n->SetBarOffset(0.5);
69  ha_n->SetFillColor(3);
70  ha_n->SetStats(0);
71  }
72 
73  if(ha_u){
74  ha_u->SetBarWidth(0.5);
75  ha_u->SetBarOffset(1.0);
76  ha_u->SetFillColor(4);
77  ha_u->SetStats(0);
78  }
79 
80  if(ha_d){
81  ha_d->SetBarWidth(0.5);
82  ha_d->SetBarOffset(1.5);
83  ha_d->SetFillColor(6);
84  ha_d->SetStats(0);
85  }
86 
87  if(h_s){
88  h_s->SetBarWidth(0.5);
89  h_s->SetBarOffset(0);
90  h_s->SetFillColor(2);
91  h_s->SetStats(0);
92  h_s->SetXTitle("Module number");
93  h_s->SetYTitle("TDC occupancy");
94  h_s->SetTitleSize(0.05,"X");
95  h_s->GetXaxis()->CenterTitle();
96  h_s->SetTitleSize(0.05,"Y");
97  h_s->GetYaxis()->CenterTitle();
98  }
99 
100  if(h_n){
101  h_n->SetBarWidth(0.5);
102  h_n->SetBarOffset(0.5);
103  h_n->SetFillColor(3);
104  h_n->SetStats(0);
105  }
106 
107  if(h_u){
108  h_u->SetBarWidth(0.5);
109  h_u->SetBarOffset(1.0);
110  h_u->SetFillColor(4);
111  h_u->SetStats(0);
112  }
113 
114  if(h_d){
115  h_d->SetBarWidth(0.5);
116  h_d->SetBarOffset(1.5);
117  h_d->SetFillColor(6);
118  h_d->SetStats(0);
119  }
120 
121  legend_sa->AddEntry(ha_s,"South","f");
122  legend_na->AddEntry(ha_n,"North","f");
123  legend_ua->AddEntry(ha_u,"Up","f");
124  legend_da->AddEntry(ha_d,"Down","f");
125 
126  legend_s->AddEntry(h_s,"South","f");
127  legend_n->AddEntry(h_n,"North","f");
128  legend_u->AddEntry(h_u,"Up","f");
129  legend_d->AddEntry(h_d,"Down","f");
130 
131 
132  // Just for testing
133  if(gPad == NULL){
134  TCanvas *c1 = new TCanvas("c1");
135  c1->cd(0);
136  c1->Draw();
137  c1->Update();
138  }
139  if(!gPad) {savedir->cd(); return;}
140 
141  TCanvas *c1 = gPad->GetCanvas();
142  c1->cd(0);
143  c1->Clear();
144 
145  c1->Divide(1,2);
146  TVirtualPad *pad1 = c1->cd(1);
147  pad1->SetTicks();
148  pad1->SetGridy();
149  if(ha_s) ha_s->Draw("BAR");
150  if(ha_n) ha_n->Draw("BAR sames");
151  if(ha_u) ha_u->Draw("BAR sames");
152  if(ha_d) ha_d->Draw("BAR sames");
153 
154  legend_sa->Draw();
155  legend_na->Draw();
156  legend_ua->Draw();
157  legend_da->Draw();
158 
159  TVirtualPad *pad2 = c1->cd(2);
160  pad2->SetTicks();
161  pad2->SetGridy();
162  if(h_s) h_s->Draw("BAR");
163  if(h_n) h_n->Draw("BAR sames");
164  if(h_u) h_u->Draw("BAR sames");
165  if(h_d) h_d->Draw("BAR sames");
166 
167  legend_s->Draw();
168  legend_n->Draw();
169  legend_u->Draw();
170  legend_d->Draw();
171 
172  if(ha_s){
173  c1->cd(1);
174  char str[256];
175  sprintf(str,"%0.0f events", Nevents);
176  TLatex lat(24, 1.075*ha_s->GetMaximum(), str);
177  lat.SetTextAlign(22);
178  lat.SetTextSize(0.035);
179  lat.Draw();
180  }
181 }
char str[256]
sprintf(text,"Post KinFit Cut")
TVirtualPad * pad1
static TH1I * tof_num_events
Double_t c1[2][NMODULES]
Definition: tw_corr.C:68
double Nevents
TDirectory * savedir
TDirectory * dir
Definition: bcal_hist_eff.C:31
TVirtualPad * pad2