Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HistMacro_Beam.C
Go to the documentation of this file.
1 // hnamepath: /highlevel/RFBeamBunchPeriod
2 // hnamepath: /highlevel/RFBeamBunchPeriod_DFT
3 // hnamepath: /highlevel/BeamEnergy
4 //
5 // e-mail: davidl@jlab.org
6 // e-mail: staylor@jlab.org
7 // e-mail: sdobbs@jlab.org
8 // e-mail: tbritton@jlab.org
9 //
10 
11 {
12  //--------------------------------------------------------------------
13  // This taken from the bin contents of: DBeamPhoton::E of a janaroot file
14  // for run 61486, an amorphous target run.
15  // The data in the table below was created with a macro in:
16  // $HALLD_RECON_HOME/src/plugins/monitoring/highlevel_online/AmorphousNormalization
17  //
18  // The working directory used was:
19  // ~hdops/2018.10.05.amorphous_normalization
20  //
21  string amorphous_label = "Normalized to Amorphous run 61486";
22 
23  Double_t amorphous_data[] = {
24  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
25  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
26  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
27  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
28  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
29  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1528717.0, 1407544.0,
30  1528588.0, 1504324.0, 983111.0, 0.0, 1441092.0, 1480053.0, 1460954.0, 1392584.0, 1394014.0, 1336290.0,
31  0.0, 1346085.0, 1316119.0, 1285210.0, 1295065.0, 1250674.0, 1158590.0, 1126330.0, 0.0, 1146744.0,
32  1081900.0, 1086177.0, 0.0, 1068194.0, 1011269.0, 1012426.0, 1025018.0, 0.0, 951980.0, 939222.0,
33  927711.0, 917307.0, 901588.0, 919701.0, 0.0, 849302.0, 834149.0, 869406.0, 797246.0, 830177.0,
34  809832.0, 0.0, 790587.0, 749255.0, 760424.0, 720303.0, 761106.0, 724676.0, 704258.0, 0.0,
35  647908.0, 693104.0, 675661.0, 652931.0, 643327.0, 631906.0, 604586.0, 0.0, 612618.0, 603558.0,
36  613414.0, 582071.0, 569040.0, 559067.0, 0.0, 733722.0, 695395.0, 887978.0, 663665.0, 862062.0,
37  645243.0, 665747.0, 0.0, 784282.0, 800891.0, 761655.0, 746507.0, 729282.0, 716918.0, 0.0,
38  594731.0, 593412.0, 526234.0, 571098.0, 428117.0, 0.0, 816084.0, 542575.0, 544460.0, 523923.0,
39  487473.0, 508549.0, 703798.0, 1116513.0, 967680.0, 1285424.0, 1127003.0, 779033.0, 562754.0, 415374.0,
40  525636.0, 496556.0, 407793.0, 497061.0, 451473.0, 444332.0, 475791.0, 445463.0, 454212.0, 431271.0,
41  434089.0, 426533.0, 509816.0, 414168.0, 394648.0, 476410.0, 377050.0, 489869.0, 1281880.0, 750548.0,
42  755848.0, 891975.0, 821319.0, 533191.0, 929009.0, 600947.0, 918157.0, 977240.0, 949614.0, 925346.0,
43  577657.0, 896363.0, 1145221.0, 843711.0, 691364.0, 838236.0, 810891.0, 1209237.0, 790023.0, 741811.0,
44  711976.0, 690316.0, 1177627.0, 738936.0, 792484.0, 777937.0, 746319.0, 703869.0, 697973.0, 1025455.0,
45  639500.0, 908115.0, 581026.0, 899918.0, 786252.0, 809173.0, 732216.0, 699967.0, 1006938.0, 604373.0,
46  828893.0, 582538.0, 910984.0, 756836.0, 670650.0, 545766.0, 606404.0, 495667.0, 0.0, 0.0,
47  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
48  0.0};
49  //--------------------------------------------------------------------
50 
51 
52 
53  TDirectory *locTopDirectory = gDirectory;
54 
55  //Goto Beam Path
56  TDirectory *locDirectory = (TDirectory*)gDirectory->FindObjectAny("highlevel");
57  if(!locDirectory)
58  return;
59  locDirectory->cd();
60 
61  TH1* locHist_RFBeamBunchPeriod = (TH1*)gDirectory->Get("RFBeamBunchPeriod");
62  TH1* locHist_RFBeamBunchPeriod_DFT = (TH1*)gDirectory->Get("RFBeamBunchPeriod_DFT");
63  TH1* locHist_BeamEnergy = (TH1*)gDirectory->Get("BeamEnergy");
64 
65  //Get/Make Canvas
66  TCanvas *locCanvas = NULL;
67  if(TVirtualPad::Pad() == NULL)
68  locCanvas = new TCanvas("Beam", "Beam", 1200, 600); //for testing
69  else
70  locCanvas = gPad->GetCanvas();
71  locCanvas->Divide(2, 1);
72 
73  TLatex latex;
74  latex.SetTextSize(0.04);
75  char str[256];
76 
77  //Draw
78  locCanvas->cd(1);
79  gPad->SetTicks();
80  gPad->SetGrid();
81  if( (locHist_RFBeamBunchPeriod_DFT != NULL) && (locHist_RFBeamBunchPeriod != NULL))
82  {
83  double max = locHist_RFBeamBunchPeriod_DFT->GetMaximum()*2.0;
84  locHist_RFBeamBunchPeriod_DFT->GetXaxis()->SetTitleSize(0.05);
85  locHist_RFBeamBunchPeriod_DFT->GetXaxis()->SetLabelSize(0.05);
86  locHist_RFBeamBunchPeriod_DFT->GetYaxis()->SetLabelSize(0.03);
87  locHist_RFBeamBunchPeriod_DFT->SetFillStyle(3001);
88  locHist_RFBeamBunchPeriod_DFT->SetFillColor(kGreen);
89  locHist_RFBeamBunchPeriod_DFT->SetLineColor(kGreen-2);
90  locHist_RFBeamBunchPeriod_DFT->SetLineWidth(2);
91  locHist_RFBeamBunchPeriod_DFT->SetStats(0);
92  locHist_RFBeamBunchPeriod_DFT->GetYaxis()->SetRangeUser(0.0, max);
93  locHist_RFBeamBunchPeriod_DFT->Draw();
94 
95  sprintf(str, "%g entries", (double)locHist_RFBeamBunchPeriod->GetEntries());
96  latex.DrawLatex(300.0, 1.02*max, str);
97 
98  // Plot RFBeamBunchPeriod as inset
99  TPad *p = (TPad*)gDirectory->FindObjectAny("RF_DFT");
100  if(!p) p = new TPad("RF_DFT", "insert", 0.16, 0.6, 0.89, 0.9);
101  p->Draw();
102  p->cd();
103 
104  locHist_RFBeamBunchPeriod->GetXaxis()->SetRangeUser(30.0, 90.0);
105  locHist_RFBeamBunchPeriod->GetXaxis()->SetTitleSize(0.05);
106  locHist_RFBeamBunchPeriod->GetXaxis()->SetLabelSize(0.05);
107  locHist_RFBeamBunchPeriod->GetYaxis()->SetLabelSize(0.03);
108  locHist_RFBeamBunchPeriod->SetFillStyle(3001);
109  locHist_RFBeamBunchPeriod->SetFillColor(kMagenta);
110  locHist_RFBeamBunchPeriod->SetStats(0);
111  locHist_RFBeamBunchPeriod->Draw();
112 
113  }
114 
115  locCanvas->cd(2);
116  gPad->SetTicks();
117  gPad->SetGrid();
118  if(locHist_BeamEnergy != NULL)
119  {
120  // Create normalized histogram
121  TH1D* locHist_BeamEnergy_norm = (TH1D*)gDirectory->Get("BeamEnergy_norm");
122  if(!locHist_BeamEnergy_norm){
123  locHist_BeamEnergy_norm = new TH1D("BeamEnergy_norm", "Reconstructed Photon Beam Energy;Beam #gamma energy (GeV)", 240, 0.0, 12.0);
124  }
125  if(locHist_BeamEnergy_norm){
126 
127  locHist_BeamEnergy_norm->Reset();
128 
129  // Normalize to amorphous baseline
130  double scale = 0.0;
131  for(int ibin=1; ibin<=locHist_BeamEnergy_norm->GetNbinsX(); ibin++){
132  Double_t norm = amorphous_data[ibin-1];
133  if( norm < 10000.0) continue;
134 
135  Double_t v = (Double_t)locHist_BeamEnergy->GetBinContent(ibin);
136  v /= norm;
137  locHist_BeamEnergy_norm->SetBinContent(ibin, v);
138  if(v > scale) scale = v;
139  }
140 
141  // Find maximum and scale histogram so peak is at 1
142  if(scale != 0.0) locHist_BeamEnergy_norm->Scale(1.0/scale);
143 
144  // Find leftmost non-zero bin
145  double left_scale = 0.0;
146  for(int ibin=1; ibin<=locHist_BeamEnergy_norm->GetNbinsX(); ibin++){
147  if( amorphous_data[ibin-1] < 10000.0) continue;
148  Double_t v = (Double_t)locHist_BeamEnergy_norm->GetBinContent(ibin);
149  if(v>0.1){
150  left_scale = v;
151  break;
152  }
153  }
154 
155  // Set min and max of plot to show range
156  double diff = 1.0 - left_scale;
157  double min = left_scale - diff*0.1;
158  double max = left_scale + diff*1.2;
159  if( (max-min) < 0.4 ){
160  min = 0.25;
161  if(max<1.50) max =1.50;
162  }
163 
164  // max = 1.50;
165  // min = 0.25;
166 
167  locHist_BeamEnergy_norm->GetXaxis()->SetTitleSize(0.05);
168  locHist_BeamEnergy_norm->GetXaxis()->SetLabelSize(0.05);
169  locHist_BeamEnergy_norm->GetYaxis()->SetLabelSize(0.03);
170  locHist_BeamEnergy_norm->SetFillStyle(3001);
171  locHist_BeamEnergy_norm->SetFillColor(kOrange);
172  locHist_BeamEnergy_norm->SetLineColor(kRed-2);
173  locHist_BeamEnergy_norm->SetLineWidth(2);
174  locHist_BeamEnergy_norm->SetStats(0);
175  locHist_BeamEnergy_norm->GetYaxis()->SetRangeUser(min, max);
176  locHist_BeamEnergy_norm->Draw("HIST");
177 
178  // If diff is > 0.3 then assume this is not an amorphous run
179  // and draw a label of the peak energy
180  if(diff > 0.3){
181  double Epeak = locHist_BeamEnergy_norm->GetBinCenter(locHist_BeamEnergy_norm->GetMaximumBin());
182  sprintf(str, "Epeak: %3.2f GeV", Epeak);
183  latex.SetTextAlign(12);
184  latex.DrawLatex(1.0, (min+max)/2.0, str);
185  }
186 
187  sprintf(str, "%g entries", (double)locHist_BeamEnergy->GetEntries());
188  latex.SetTextAlign(22);
189  latex.DrawLatex(6.0, 1.035*(max-min)+min, str);
190 
191  latex.SetTextAngle(270);
192  latex.DrawLatex(12.5, (min+max)/2.0, amorphous_label.c_str());
193  }
194 
195  TPad *beamenergypad = (TPad*)gDirectory->FindObjectAny("beamenergypad");
196  if(!beamenergypad) beamenergypad = new TPad("beamenergypad", "", 0.105, 0.65, 0.5, 0.895);
197  beamenergypad->SetTicks();
198  beamenergypad->Draw();
199  beamenergypad->cd();
200 
201  //locHist_BeamEnergy->Rebin(5);
202  locHist_BeamEnergy->GetXaxis()->SetTitleSize(0.05);
203  locHist_BeamEnergy->GetXaxis()->SetLabelSize(0.05);
204  locHist_BeamEnergy->GetYaxis()->SetLabelSize(0.03);
205  locHist_BeamEnergy->SetFillStyle(3001);
206  locHist_BeamEnergy->SetFillColor(kCyan);
207  locHist_BeamEnergy->SetLineColor(kBlue);
208  locHist_BeamEnergy->SetLineWidth(2);
209  locHist_BeamEnergy->SetStats(0);
210  locHist_BeamEnergy->Draw();
211  }
212 }
213 
string amorphous_label
char str[256]
sprintf(text,"Post KinFit Cut")
TH1 * locHist_RFBeamBunchPeriod_DFT
TDirectory * locTopDirectory
Definition: HistMacro_p4pi.C:2
TDirectory * locDirectory
Double_t amorphous_data[]
TH1 * locHist_BeamEnergy
TH1 * locHist_RFBeamBunchPeriod
TCanvas * locCanvas