22 const float NA = -99.;
24 TGraphErrors* gr_x0 = 0;
25 TGraphErrors* gr_y0 = 0;
26 TGraphErrors* gr_dxdz = 0;
27 TGraphErrors* gr_dydz = 0;
28 TGraphErrors* gr_stats = 0;
47 TTree* PlotVtxSeed(
const char* dataName=0,
50 float ilow=NA,
float ihigh=NA,
51 float slow=NA,
float shigh=NA,
52 float dlow=NA,
float dhigh=NA);
55 void draw(
const char* dataName=0,
int do_stats=0);
56 void setInt(
float lo,
float hi) {int_lo = lo; int_hi = hi;}
57 void setSlo(
float lo,
float hi) {slo_lo = lo; slo_hi = hi;}
58 void setDay(
float lo,
float hi) {day_lo = lo; day_hi = hi;}
59 void unsetInt() {int_lo = NA; int_hi = NA;}
60 void unsetSlo() {slo_lo = NA; slo_hi = NA;}
61 void unsetDay() {day_lo = NA; day_hi = NA;}
64 void init(
const char* dir);
66 void roundIt(
float& min,
float& max,
float r);
72 TTree* PlotVtxSeed(
const char* dataName,
75 float ilow,
float ihigh,
76 float slow,
float shigh,
77 float dlow,
float dhigh) {
82 draw(dataName,do_stats);
86 void init(
const char* dir) {
87 TString dirStr = (dir ? dir :
".");
88 cout <<
"In directory: " << dirStr << endl;
89 cout <<
"Looking for BLpars.root first..." << endl;
90 TFile* ff = TFile::Open(Form(
"file:%s/BLpars.root",dirStr.Data()));
92 TKey* BLkey = ff->GetKey(
"BLpars");
93 if (BLkey) BLpars = (TTree*) (BLkey->ReadObj());
94 else cerr <<
"Found file, but no BLpars key!" << endl;
96 cout <<
"Looking for vertexseedhist.*.root second..." << endl;
97 TChain* BLchain =
new TChain(
"BLpars");
98 if (BLchain->Add(Form(
"%s/vertexseedhist.*.root",dirStr.Data())))
99 BLpars = (TTree*) BLchain;
102 cerr <<
"No luck finding BeamLine ntuples!" << endl;
105 BLpars->SetMarkerStyle(22);
106 c1 =
new TCanvas(
"BeamLine",
"BeamLine Constraint",600,600);
107 gStyle->SetGridColor(kGray);
114 ints =
new TPad(
"ints",
"Intercepts",0.01,0.468,0.99,0.9);
115 ints->SetBottomMargin(0.);
117 slos =
new TPad(
"slos",
"Slopes",0.01,0.04,0.99,0.472);
118 slos->SetTopMargin(0.);
120 legs =
new TPad(
"legs",
"Legends",0.84,0.87,0.99,0.99);
121 legs->SetBottomMargin(0.);
122 legs->SetTopMargin(0.);
123 legs->SetLeftMargin(0.);
124 legs->SetRightMargin(0.);
131 void draw(
const char* dataName,
int do_stats) {
151 BLpars->SetBranchAddress(
"days",&days);
152 BLpars->SetBranchAddress(
"x0",&x0);
153 BLpars->SetBranchAddress(
"err_x0",&err_x0);
154 BLpars->SetBranchAddress(
"y0",&y0);
155 BLpars->SetBranchAddress(
"err_y0",&err_y0);
156 BLpars->SetBranchAddress(
"dxdz",&dxdz);
157 BLpars->SetBranchAddress(
"err_dxdz",&err_dxdz);
158 BLpars->SetBranchAddress(
"dydz",&dydz);
159 BLpars->SetBranchAddress(
"err_dydz",&err_dydz);
160 BLpars->SetBranchAddress(
"stats",&stats);
161 BLpars->SetBranchAddress(
"date",&date);
162 BLpars->SetBranchAddress(
"fill",&fill);
163 BLpars->SetBranchAddress(
"zdc",&zdc);
165 Int_t nentries = (Int_t) (BLpars->GetEntries());
166 gr_x0 =
new TGraphErrors(nentries);
167 gr_y0 =
new TGraphErrors(nentries);
168 gr_dxdz =
new TGraphErrors(nentries);
169 gr_dydz =
new TGraphErrors(nentries);
170 gr_stats =
new TGraphErrors(nentries);
172 gr_x0->SetMarkerColor(2);
173 gr_y0->SetMarkerColor(4);
174 gr_dxdz->SetMarkerColor(6);
175 gr_dydz->SetMarkerColor(kGreen+2);
176 gr_x0->SetMarkerStyle(25);
177 gr_y0->SetMarkerStyle(27);
178 gr_dxdz->SetMarkerStyle(25);
179 gr_dydz->SetMarkerStyle(27);
180 gr_x0->SetMarkerSize(0.4);
181 gr_y0->SetMarkerSize(0.7);
182 gr_dxdz->SetMarkerSize(0.4);
183 gr_dydz->SetMarkerSize(0.7);
184 gr_stats->SetFillColor(41);
187 leg =
new TLegend(0.001,0.04,0.960,0.999);
188 leg->AddEntry(gr_x0,
"x0",
"p");
189 leg->AddEntry(gr_y0,
"y0",
"p");
190 leg->AddEntry(gr_dxdz,
"dxdz",
"p");
191 leg->AddEntry(gr_dydz,
"dydz",
"p");
192 leg->SetFillColor(42);
194 float min_day = 366.0;
202 for (Int_t i=0; i<nentries;i++) {
204 gr_x0->SetPoint(i,days,x0);
205 gr_x0->SetPointError(i,0,err_x0);
206 gr_y0->SetPoint(i,days,y0);
207 gr_y0->SetPointError(i,0,err_y0);
208 gr_dxdz->SetPoint(i,days,dxdz);
209 gr_dxdz->SetPointError(i,0,err_dxdz);
210 gr_dydz->SetPoint(i,days,dydz);
211 gr_dydz->SetPointError(i,0,err_dydz);
212 gr_stats->SetPoint(i,days,days);
214 gr_stats->SetPointError(i,0.1,TMath::Sqrt(10.0/stats));
216 min_day = TMath::Min(min_day,days);
217 max_day = TMath::Max(max_day,days);
218 min_int = TMath::Min(min_int,TMath::Min(x0-err_x0,y0-err_y0));
219 max_int = TMath::Max(max_int,TMath::Max(x0+err_x0,y0+err_y0));
220 min_slo = TMath::Min(min_slo,TMath::Min(dxdz-err_dxdz,dydz-err_dydz));
221 max_slo = TMath::Max(max_slo,TMath::Max(dxdz+err_dxdz,dydz+err_dydz));
224 float day_round = 5.0;
225 float int_round = 0.05;
226 float slo_round = 0.001;
228 if (day_lo == NA) roundIt(min_day,max_day,day_round);
229 else { min_day = day_lo; max_day = day_hi; }
230 if (int_lo == NA) roundIt(min_int,max_int,int_round);
231 else { min_int = int_lo; max_int = int_hi; }
232 if (slo_lo == NA) roundIt(min_slo,max_slo,slo_round);
233 else { min_slo = slo_lo; max_slo = slo_hi; }
235 for (Int_t i=0; i<nentries;i++) {
237 gr_stats->GetPoint(i,d1,d2);
238 gr_stats->SetPoint(i,d1,min_int);
242 TH1F* h_ints = ints->DrawFrame(min_day,min_int,max_day,max_int);
243 h_ints->SetTitleSize(0.05,
"Y");
244 h_ints->SetYTitle(
"Intercepts [cm] ");
245 if (do_stats) gr_stats->Draw(
"2");
251 TH1F* h_slos = slos->DrawFrame(min_day,min_slo,max_day,max_slo);
252 h_slos->SetTitleSize(0.05,
"Y");
253 h_slos->SetYTitle(
"Slopes ");
265 TText* t1 =
new TText;
266 t1->SetTextAlign(32);
267 t1->SetTextSize(0.035);
268 t1->DrawText(0.5,0.02,
"Day");
269 t1->SetTextAlign(12);
270 t1->SetTextSize(0.020);
271 t1->DrawText(0.55,0.02,
"[1.0,2.0] = Jan 1 EDT");
272 t1->SetTextAlign(22);
273 t1->SetTextSize(0.045);
274 t1->DrawText(0.4,0.97,
"BeamLine Constraint");
275 if (dataName) t1->DrawText(0.4,0.925,dataName);
277 c1->Update(); c1->Draw();
279 if (dataName) c1->SaveAs(Form(
"%s.gif",dataName));
282 void roundIt(
float& min,
float& max,
float r) {
285 max = r * ( ((int) (max/r - near + pad)) + ( (max>0) ? 1. : 0. ) + near );
286 min = r * ( ((int) (min/r + near - pad)) - ( (min<0) ? 1. : 0. ) - near );
290 c1->Update(); c1->Draw();
292 printf(
"Waiting...\n");