]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGLF/FORWARD/analysis2/DrawdNdeta.C
Updates for pA
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / DrawdNdeta.C
CommitLineData
e1f47419 1/**
ffca499d 2 * @file DrawdNdeta.C
3 * @author Christian Holm Christensen <cholm@dalsgaard.hehi.nbi.dk>
4 * @date Wed Mar 23 14:07:10 2011
5 *
5bb5d1f6 6 * @brief Script to visualise the dN/deta for pp and PbPb
e1f47419 7 *
ffca499d 8 * This script is independent of any AliROOT code - and should stay
9 * that way.
10 *
970b1a8a 11 * The script is <i>very</i> long - sigh - the joy of drawing
5bb5d1f6 12 * things nicely in ROOT
ffca499d 13 *
bd6f5206 14 * @ingroup pwglf_forward_dndeta
e1f47419 15 */
b2e7f2d6 16#include <TH1.h>
f709afcf 17#include <TColor.h>
b2e7f2d6 18#include <THStack.h>
19#include <TGraphErrors.h>
20#include <TGraphAsymmErrors.h>
21#include <TMultiGraph.h>
22#include <TFile.h>
23#include <TList.h>
24#include <TString.h>
25#include <TError.h>
26#include <TSystem.h>
27#include <TROOT.h>
28#include <TMath.h>
29#include <TCanvas.h>
30#include <TPad.h>
31#include <TStyle.h>
32#include <TLegend.h>
33#include <TLegendEntry.h>
34#include <TLatex.h>
35#include <TImage.h>
33ab4a11 36#include <TRandom.h>
37#include <fstream>
298a7264 38#include <iostream>
290052e7 39/** Systematic error color */
37079f20 40#define SYSERR_COLOR kBlue-10
290052e7 41/** Systematic error style */
37079f20 42#define SYSERR_STYLE 1001
b2e7f2d6 43
797161e8 44Double_t myFunc(Double_t* xp, Double_t* pp);
45
2f92ff0e 46/**
47 * Class to draw dN/deta results
48 *
bd6f5206 49 * @ingroup pwglf_forward_tasks_dndeta
50 * @ingroup pwglf_forward_dndeta
2f92ff0e 51 */
b2e7f2d6 52struct dNdetaDrawer
53{
2f92ff0e 54 /**
55 * POD of data for range zooming
56 */
b2e7f2d6 57 struct RangeParam
58 {
59 TAxis* fMasterAxis; // Master axis
60 TAxis* fSlave1Axis; // First slave axis
61 TVirtualPad* fSlave1Pad; // First slave pad
62 TAxis* fSlave2Axis; // Second slave axis
63 TVirtualPad* fSlave2Pad; // Second slave pad
64 };
65 //__________________________________________________________________
2f92ff0e 66 /**
67 * Constructor
68 *
69 */
b2e7f2d6 70 dNdetaDrawer()
33ab4a11 71 : // Options
72 fShowRatios(false), // Show ratios
73 fShowLeftRight(false), // Show asymmetry
74 fShowRings(false), // Show rings too
75 fExport(false), // Export data to script
76 fCutEdges(false), // Whether to cut edges
77 fRemoveOuters(false), // Whether to remove outers
78 fShowOthers(0), // Show other data
298a7264 79 fMirror(false),
80 fForceMB(false),
33ab4a11 81 // Settings
82 fRebin(0), // Rebinning factor
83 fFwdSysErr(0.076), // Systematic error in forward range
84 fCenSysErr(0), // Systematic error in central range
85 fTitle(""), // Title on plot
86 fClusterScale(""), // Scaling of clusters to tracklets
87 // Read (or set) information
88 fTrigString(0), // Trigger string (read, or set)
89 fNormString(0), // Normalisation string (read, or set)
90 fSNNString(0), // Energy string (read, or set)
91 fSysString(0), // Collision system string (read or set)
92 fVtxAxis(0), // Vertex cuts (read or set)
93 fCentAxis(0), // Centrality axis
94 // Resulting plots
95 fResults(0), // Stack of results
96 fRatios(0), // Stack of ratios
97 fLeftRight(0), // Left-right asymmetry
98 fOthers(0), // Older data
99 fTriggers(0), // Number of triggers
100 fTruth(0), // Pointer to truth
101 fRangeParam(0) // Parameter object for range zoom
b2e7f2d6 102 {
103 fRangeParam = new RangeParam;
104 fRangeParam->fMasterAxis = 0;
105 fRangeParam->fSlave1Axis = 0;
106 fRangeParam->fSlave1Pad = 0;
107 fRangeParam->fSlave2Axis = 0;
108 fRangeParam->fSlave2Pad = 0;
109 }
290052e7 110 /**
111 * Cpoy constructor
112 */
33ab4a11 113 dNdetaDrawer(const dNdetaDrawer&) {}
290052e7 114 /**
115 * Assignment operator
116 *
117 *
118 * @return Reference to this object
119 */
33ab4a11 120 dNdetaDrawer& operator=(const dNdetaDrawer&) { return *this; }
121
ffca499d 122 //__________________________________________________________________
290052e7 123 /**
124 * Destructor
125 */
ffca499d 126 virtual ~dNdetaDrawer()
127 {
128 if (fRatios && fRatios->GetHists()) fRatios->GetHists()->Delete();
129 if (fResults && fResults->GetHists()) fResults->GetHists()->Delete();
130
131 if (fTrigString) { delete fTrigString; fTrigString = 0; }
132 if (fSNNString) { delete fSNNString; fSNNString = 0; }
133 if (fSysString) { delete fSysString; fSysString = 0; }
134 if (fVtxAxis) { delete fVtxAxis; fVtxAxis = 0; }
135 if (fCentAxis) { delete fCentAxis; fCentAxis = 0; }
136 if (fResults) { delete fResults; fResults = 0; }
137 if (fRatios) { delete fRatios; fRatios = 0; }
138 if (fOthers) { delete fOthers; fOthers = 0; }
139 if (fTriggers) { delete fTriggers; fTriggers = 0; }
140 fRangeParam = 0;
141 }
142
2f92ff0e 143 //==================================================================
144 /**
145 * @{
146 * @name Set parameters
147 */
148 /**
149 * Show other (UA5, CMS, ...) data
150 *
151 * @param x Whether to show or not
152 */
797161e8 153 void SetShowOthers(UShort_t x) { fShowOthers = x; }
2f92ff0e 154 //__________________________________________________________________
2f92ff0e 155 /**
156 * Whether to show ratios or not. If there's nothing to compare to,
157 * the ratio panel will be implicitly disabled
158 *
159 * @param x Whether to show or not
160 */
b2e7f2d6 161 void SetShowRatios(Bool_t x) { fShowRatios = x; }
2f92ff0e 162 //__________________________________________________________________
163 /**
164 *
165 * Whether to show the left/right asymmetry
166 *
167 * @param x To show or not
168 */
b2e7f2d6 169 void SetShowLeftRight(Bool_t x) { fShowLeftRight = x; }
797161e8 170 //__________________________________________________________________
171 /**
172 * Whether to show rings
173 *
174 * @param x To show or not
175 */
f709afcf 176 void SetShowRings(Bool_t x) { fShowRings = x; }
2f92ff0e 177 //__________________________________________________________________
33ab4a11 178 /**
179 * Whether to export results to a script
180 *
181 * @param x Wheter to export results to a script
182 */
183 void SetExport(Bool_t x) { fExport = x; }
184 //__________________________________________________________________
2f92ff0e 185 /**
186 * Set the rebinning factor
187 *
188 * @param x Rebinning factor (must be a divisor in the number of bins)
189 */
b2e7f2d6 190 void SetRebin(UShort_t x) { fRebin = x; }
2f92ff0e 191 //__________________________________________________________________
192 /**
193 * Wheter to cut away the edges
194 *
195 * @param x Whether or not to cut away edges
196 */
b2e7f2d6 197 void SetCutEdges(Bool_t x) { fCutEdges = x; }
2f92ff0e 198 //__________________________________________________________________
199 /**
200 * Set the title of the plot
201 *
202 * @param x Title
203 */
b2e7f2d6 204 void SetTitle(TString x) { fTitle = x; }
797161e8 205 //__________________________________________________________________
206 /**
207 * Set the systematic error in the forward region
208 *
209 * @param e Systematic error in the forward region
210 */
211 void SetForwardSysError(Double_t e=0) { fFwdSysErr = e; }
212 //__________________________________________________________________
213 /**
214 * Set the systematic error in the forward region
215 *
216 * @param e Systematic error in the forward region
217 */
218 void SetCentralSysError(Double_t e=0) { fCenSysErr = e; }
298a7264 219 void SetForceMB(Bool_t force=true) { fForceMB = force; }
220 void SetMirror(Bool_t mirror=true) { fMirror = mirror; }
2f92ff0e 221 /* @} */
222 //==================================================================
223 /**
224 * @{
225 * @name Override settings from input
226 */
227 /**
228 * Override setting from file
229 *
230 * @param sNN Center of mass energy per nucleon pair (GeV)
231 */
232 void SetSNN(UShort_t sNN)
233 {
cdb9e20f 234 fSNNString = new TNamed("sNN", Form("%04dGeV", sNN));
2f92ff0e 235 fSNNString->SetUniqueID(sNN);
236 }
237 //__________________________________________________________________
238 /**
239 * Set the collision system
240 * - 1: pp
241 * - 2: PbPb
242 *
243 * @param sys collision system
244 */
245 void SetSys(UShort_t sys)
246 {
fe52e455 247 fSysString = new TNamed("sys", (sys == 1 ? "pp" :
4d97b4bb 248 sys == 2 ? "PbPb" :
249 sys == 3 ? "pPb" :
250 "unknown"));
fe52e455 251 fSysString->SetUniqueID(sys);
2f92ff0e 252 }
253 //__________________________________________________________________
254 /**
255 * Set the vertex range in centimeters
256 *
257 * @param vzMin Min @f$ v_z@f$
258 * @param vzMax Max @f$ v_z@f$
259 */
260 void SetVertexRange(Double_t vzMin, Double_t vzMax)
261 {
262 fVtxAxis = new TAxis(10, vzMin, vzMax);
263 fVtxAxis->SetName("vtxAxis");
264 fVtxAxis->SetTitle(Form("v_{z}#in[%+5.1f,%+5.1f]cm", vzMin, vzMax));
265 }
b2e7f2d6 266 //__________________________________________________________________
2f92ff0e 267 void SetTrigger(UShort_t trig)
268 {
269 fTrigString = new TNamed("trigString", (trig & 0x1 ? "INEL" :
270 trig & 0x2 ? "INEL>0" :
271 trig & 0x4 ? "NSD" :
272 "unknown"));
273 fTrigString->SetUniqueID(trig);
274 }
275
276
277 //==================================================================
278 /**
279 * @{
280 * @name Main steering functions
281 */
282 /**
283 * Run the code to produce the final result.
284 *
285 * @param filename File containing the data
286 */
e308a636 287 void Run(const char* filename="forward_dndeta.root")
b2e7f2d6 288 {
e308a636 289 Double_t max = 0, rmax=0, amax=0;
b2e7f2d6 290
e308a636 291 gStyle->SetPalette(1);
e1f47419 292
e308a636 293 // --- Open input file -------------------------------------------
294 TFile* file = TFile::Open(filename, "READ");
295 if (!file) {
296 Error("Open", "Cannot open %s", filename);
297 return;
298 }
299 // --- Get forward list ------------------------------------------
300 TList* forward = static_cast<TList*>(file->Get("ForwardResults"));
301 if (!forward) {
302 Error("Open", "Couldn't find list ForwardResults");
303 return;
304 }
305 // --- Get information on the run --------------------------------
306 FetchInformation(forward);
307 // --- Set the macro pathand load other data script --------------
bd6f5206 308 gROOT->SetMacroPath(Form("%s:$(ALICE_ROOT)/PWGLF/FORWARD/analysis2",
e308a636 309 gROOT->GetMacroPath()));
310 gROOT->LoadMacro("OtherData.C");
311
312 // --- Get the central results -----------------------------------
313 TList* clusters = static_cast<TList*>(file->Get("CentralResults"));
314 if (!clusters) Warning("Open", "Couldn't find list CentralResults");
b2e7f2d6 315
9ecab72f 316 // --- Get the central results -----------------------------------
317 TList* mcTruth = static_cast<TList*>(file->Get("MCTruthResults"));
318 if (!mcTruth) Warning("Open", "Couldn't find list MCTruthResults");
319
e308a636 320 // --- Make our containtes ---------------------------------------
321 fResults = new THStack("results", "Results");
322 fRatios = new THStack("ratios", "Ratios");
323 fLeftRight = new THStack("asymmetry", "Left-right asymmetry");
324 fOthers = new TMultiGraph();
b2e7f2d6 325
e308a636 326 // --- Loop over input data --------------------------------------
797161e8 327 /*TObjArray* mcA =*/ FetchResults(mcTruth, "MCTruth", max, rmax, amax);
328 TObjArray* fwdA = FetchResults(forward, "Forward", max, rmax, amax);
329 TObjArray* cenA = FetchResults(clusters, "Central", max, rmax, amax);
b2e7f2d6 330
e308a636 331 // --- Get trigger information -----------------------------------
332 TList* sums = static_cast<TList*>(file->Get("ForwardSums"));
333 if (sums) {
334 TList* all = static_cast<TList*>(sums->FindObject("all"));
335 if (all) {
336 fTriggers = FetchResult(all, "triggers");
337 if (!fTriggers) all->ls();
338 }
339 else {
340 Warning("Run", "List all not found in ForwardSums");
341 sums->ls();
342 }
343 }
344 else {
345 Warning("Run", "No ForwardSums directory found in %s", file->GetName());
346 file->ls();
347 }
348
349 // --- Check our stacks ------------------------------------------
350 if (!fResults->GetHists() ||
351 fResults->GetHists()->GetEntries() <= 0) {
352 Error("Run", "No histograms in result stack!");
353 return;
354 }
355 if (!fOthers->GetListOfGraphs() ||
356 fOthers->GetListOfGraphs()->GetEntries() <= 0) {
357 Warning("Run", "No other data found - disabling that");
797161e8 358 fShowOthers = 0;
e308a636 359 }
360 if (!fRatios->GetHists() ||
361 fRatios->GetHists()->GetEntries() <= 0) {
362 Warning("Run", "No ratio data found - disabling that");
363 // fRatios->ls();
364 fShowRatios = false;
365 }
366 if (!fLeftRight->GetHists() ||
367 fLeftRight->GetHists()->GetEntries() <= 0) {
368 Warning("Run", "No left/right data found - disabling that");
369 // fLeftRight->ls();
370 fShowLeftRight = false;
371 }
797161e8 372 if (fFwdSysErr > 0) {
373 if (fCenSysErr <= 0) fCenSysErr = fFwdSysErr;
374 for (Int_t i = 0; i < fwdA->GetEntriesFast(); i++) {
375 TH1* fwd = static_cast<TH1*>(fwdA->At(i));
376 TH1* cen = static_cast<TH1*>(cenA->At(i));
377 CorrectForward(fwd);
378 CorrectCentral(cen);
379 Double_t low, high;
380 TH1* tmp = Merge(cen, fwd, low, high);
381 TF1* f = FitMerged(tmp, low, high);
382 MakeSysError(tmp, cen, fwd, f);
383 delete f;
384 Info("", "Adding systematic error histogram %s",
385 tmp->GetName());
386 fResults->GetHists()->AddFirst(tmp, "e5");
298a7264 387
388 if (!fMirror) continue;
389
797161e8 390 TH1* tmp2 = Symmetrice(tmp);
391 tmp2->SetFillColor(tmp->GetFillColor());
392 tmp2->SetFillStyle(tmp->GetFillStyle());
393 tmp2->SetMarkerStyle(tmp->GetMarkerStyle());
394 tmp2->SetLineWidth(tmp->GetLineWidth());
395 fResults->GetHists()->AddFirst(tmp2, "e5");
396 fResults->Modified();
397 }
398 }
399 delete fwdA;
400 delete cenA;
e308a636 401
402 // --- Close the input file --------------------------------------
403 file->Close();
404
405
b2e7f2d6 406
e308a636 407 // --- Plot results ----------------------------------------------
408 Plot(max, rmax, amax);
b2e7f2d6 409 }
e1f47419 410
b2e7f2d6 411 //__________________________________________________________________
2f92ff0e 412 /**
e1f47419 413 * Fetch the information on the run from the results list
2f92ff0e 414 *
e1f47419 415 * @param results Results list
2f92ff0e 416 */
e1f47419 417 void FetchInformation(const TList* results)
b2e7f2d6 418 {
2f92ff0e 419 if (!fTrigString)
0be6c8cd 420 fTrigString = static_cast<TNamed*>(results->FindObject("trigger"));
421 if (!fNormString)
422 fNormString = static_cast<TNamed*>(results->FindObject("scheme"));
2f92ff0e 423 if (!fSNNString)
424 fSNNString = static_cast<TNamed*>(results->FindObject("sNN"));
425 if (!fSysString)
426 fSysString = static_cast<TNamed*>(results->FindObject("sys"));
427 if (!fVtxAxis)
428 fVtxAxis = static_cast<TAxis*>(results->FindObject("vtxAxis"));
e308a636 429 if (!fCentAxis)
430 fCentAxis = static_cast<TAxis*>(results->FindObject("centAxis"));
c25b5e1b 431
432 TNamed* options = static_cast<TAxis*>(results->FindObject("options"));
0be6c8cd 433 if (!fTrigString) fTrigString = new TNamed("trigger", "unknown");
434 if (!fNormString) fNormString = new TNamed("scheme", "unknown");
bad9a3c1 435 if (!fSNNString) fSNNString = new TNamed("sNN", "unknown");
436 if (!fSysString) fSysString = new TNamed("sys", "unknown");
437 if (!fVtxAxis) {
438 fVtxAxis = new TAxis(1,0,0);
439 fVtxAxis->SetName("vtxAxis");
440 fVtxAxis->SetTitle("v_{z} range unspecified");
441 }
b2e7f2d6 442
0be6c8cd 443 TString centTxt("none");
e308a636 444 if (fCentAxis) {
445 Int_t nCent = fCentAxis->GetNbins();
0be6c8cd 446 centTxt = Form("%d bins", nCent);
e308a636 447 for (Int_t i = 0; i <= nCent; i++)
0be6c8cd 448 centTxt.Append(Form("%c%d", i == 0 ? ' ' : '-',
ffca499d 449 int(fCentAxis->GetXbins()->At(i))));
e308a636 450 }
e1f47419 451 Info("FetchInformation",
fe52e455 452 "Initialized for\n"
0be6c8cd 453 " Trigger: %-30s (%d)\n"
454 " sqrt(sNN): %-30s (%dGeV)\n"
455 " System: %-30s (%d)\n"
456 " Vz range: %-30s (%f,%f)\n"
457 " Normalization: %-30s (%d)\n"
c25b5e1b 458 " Centrality: %s\n"
459 " Options: %s",
fe52e455 460 fTrigString->GetTitle(), fTrigString->GetUniqueID(),
461 fSNNString->GetTitle(), fSNNString->GetUniqueID(),
462 fSysString->GetTitle(), fSysString->GetUniqueID(),
e308a636 463 fVtxAxis->GetTitle(), fVtxAxis->GetXmin(), fVtxAxis->GetXmax(),
0be6c8cd 464 fNormString->GetTitle(), fNormString->GetUniqueID(),
c25b5e1b 465 centTxt.Data(), (options ? options->GetTitle() : "none"));
e1f47419 466 }
e308a636 467 //__________________________________________________________________
468 TMultiGraph* FetchOthers(UShort_t centLow, UShort_t centHigh)
469 {
470 TMultiGraph* thisOther = 0;
797161e8 471 if (fShowOthers == 0) return 0;
e308a636 472
e308a636 473 UShort_t sys = (fSysString ? fSysString->GetUniqueID() : 0);
474 UShort_t trg = (fTrigString ? fTrigString->GetUniqueID() : 0);
475 UShort_t snn = (fSNNString ? fSNNString->GetUniqueID() : 0);
797161e8 476 Long_t ret = gROOT->ProcessLine(Form("GetData(%d,%d,%d,%d,%d,%d);",
e308a636 477 sys,snn,trg,
797161e8 478 centLow,centHigh,
479 fShowOthers));
480 if (!ret) return 0;
481
482 thisOther = reinterpret_cast<TMultiGraph*>(ret);
e308a636 483 return thisOther;
484 }
e1f47419 485 //__________________________________________________________________
486 /**
e308a636 487 * Get the results from the top-level list
e1f47419 488 *
e308a636 489 * @param list List
490 * @param name name
491 * @param max On return, maximum of data
492 * @param rmax On return, maximum of ratios
493 * @param amax On return, maximum of left-right comparisons
290052e7 494 *
495 * @return Array of results
e1f47419 496 */
797161e8 497 TObjArray*
498 FetchResults(const TList* list,
499 const char* name,
500 Double_t& max,
501 Double_t& rmax,
502 Double_t& amax)
e1f47419 503 {
298a7264 504 UShort_t n = HasCent() ? fCentAxis->GetNbins() : 0;
505 Info("Fetch results, got %d centrality bins", n);
e308a636 506 if (n == 0) {
507 TList* all = static_cast<TList*>(list->FindObject("all"));
797161e8 508 if (!all) {
e308a636 509 Error("FetchResults", "Couldn't find list 'all' in %s",
510 list->GetName());
797161e8 511 return 0;
512 }
513 TObjArray* a = new TObjArray;
514 TH1* h = FetchResults(all, name, FetchOthers(0,0),
515 -1000, 0, max, rmax, amax);
298a7264 516 Info("FetchResults", "Adding %s to result stack", h->GetName());
797161e8 517 a->AddAt(h, 0);
518 return a;
b2e7f2d6 519 }
e1f47419 520
797161e8 521 TObjArray* a = new TObjArray;
e308a636 522 for (UShort_t i = 0; i < n; i++) {
5bb5d1f6 523 UShort_t centLow = fCentAxis->GetBinLowEdge(i+1);
524 UShort_t centHigh = fCentAxis->GetBinUpEdge(i+1);
e308a636 525 TString lname = Form("cent%03d_%03d", centLow, centHigh);
526 TList* thisCent = static_cast<TList*>(list->FindObject(lname));
5bb5d1f6 527 Int_t col = GetCentralityColor(i+1);
e308a636 528
529 TString centTxt = Form("%3d%%-%3d%% central", centLow, centHigh);
797161e8 530 if (!thisCent) {
e308a636 531 Error("FetchResults", "Couldn't find list '%s' in %s",
532 lname.Data(), list->GetName());
797161e8 533 continue;
534 }
535 TH1* h = FetchResults(thisCent, name, FetchOthers(centLow, centHigh),
536 col, centTxt.Data(), max, rmax, amax);
298a7264 537 Info("FetchResults", "Adding %p to result stack", h);
797161e8 538 a->AddAt(h, i);
e1f47419 539 }
797161e8 540 return a;
e308a636 541 }
542 //__________________________________________________________________
290052e7 543 /**
544 * Get the color for a centrality bin
545 *
546 * @param bin Centrality bin
547 *
548 * @return Color
549 */
5bb5d1f6 550 Int_t GetCentralityColor(Int_t bin) const
551 {
552 UShort_t centLow = fCentAxis->GetBinLowEdge(bin);
553 UShort_t centHigh = fCentAxis->GetBinUpEdge(bin);
554 Float_t fc = (centLow+double(centHigh-centLow)/2) / 100;
555 Int_t nCol = gStyle->GetNumberOfColors();
556 Int_t icol = TMath::Min(nCol-1,int(fc * nCol + .5));
557 Int_t col = gStyle->GetColorPalette(icol);
558 //Info("GetCentralityColor","%3d: %3d-%3d -> %3d",bin,centLow,centHigh,col);
559 return col;
560 }
561 //__________________________________________________________________
290052e7 562 /**
563 * Set attributed on a histogram
564 *
565 * @param h Histogram
566 * @param color Color
567 */
e308a636 568 void SetAttributes(TH1* h, Int_t color)
569 {
570 if (!h) return;
571 if (color < 0) return;
ffca499d 572 // h->SetLineColor(color);
e308a636 573 h->SetMarkerColor(color);
ffca499d 574 // h->SetFillColor(color);
e308a636 575 }
576 //__________________________________________________________________
290052e7 577 /**
578 * Set attributed on a graph
579 *
580 * @param g Graph
581 * @param color Color
582 */
e308a636 583 void SetAttributes(TGraph* g, Int_t color)
584 {
585 if (!g) return;
586 if (color < 0) return;
ffca499d 587 // g->SetLineColor(color);
e308a636 588 g->SetMarkerColor(color);
ffca499d 589 // g->SetFillColor(color);
b2e7f2d6 590 }
591 //__________________________________________________________________
290052e7 592 /**
593 * Modify the title
594 *
595 */
9ecab72f 596 void ModifyTitle(TNamed* /*h*/, const char* /*centTxt*/)
e308a636 597 {
5bb5d1f6 598 return;
599 // if (!centTxt || !h) return;
600 // h->SetTitle(Form("%s, %s", h->GetTitle(), centTxt));
e308a636 601 }
602
603 //__________________________________________________________________
604 /**
605 * Fetch results for a particular centrality bin
606 *
607 * @param list List
608 * @param name Name
ffca499d 609 * @param thisOther Other graphs
610 * @param color Color
611 * @param centTxt Centrality text
e308a636 612 * @param max On return, data maximum
613 * @param rmax On return, ratio maximum
614 * @param amax On return, left-right maximum
290052e7 615 *
616 * @return Histogram of results
e308a636 617 */
797161e8 618 TH1* FetchResults(const TList* list,
e308a636 619 const char* name,
620 TMultiGraph* thisOther,
621 Int_t color,
622 const char* centTxt,
623 Double_t& max,
624 Double_t& rmax,
625 Double_t& amax)
b2e7f2d6 626 {
e1f47419 627 TH1* dndeta = FetchResult(list, Form("dndeta%s", name));
628 TH1* dndetaMC = FetchResult(list, Form("dndeta%sMC", name));
629 TH1* dndetaTruth = FetchResult(list, "dndetaTruth");
630 TH1* dndetaSym = 0;
631 TH1* dndetaMCSym = 0;
e308a636 632 SetAttributes(dndeta, color);
298a7264 633 SetAttributes(dndetaMC, HasCent() ? color : color+2);
e308a636 634 SetAttributes(dndetaTruth,color);
635 SetAttributes(dndetaSym, color);
298a7264 636 SetAttributes(dndetaMCSym,HasCent() ? color : color+2);
637 if (dndetaMC && HasCent())
5bb5d1f6 638 dndetaMC->SetMarkerStyle(dndetaMC->GetMarkerStyle()+2);
298a7264 639 if (dndetaMCSym && HasCent())
5bb5d1f6 640 dndetaMCSym->SetMarkerStyle(dndetaMCSym->GetMarkerStyle()+2);
298a7264 641 if (dndetaTruth && HasCent()) {
5bb5d1f6 642 dndetaTruth->SetMarkerStyle(34);
9ecab72f 643 dndetaTruth->SetMarkerColor(kYellow-1);
644 }
298a7264 645 if (dndetaTruth) {
646 dndetaTruth->SetLineColor(kBlack);
647 }
e308a636 648 ModifyTitle(dndeta, centTxt);
649 ModifyTitle(dndetaMC, centTxt);
650 ModifyTitle(dndetaTruth,centTxt);
651 ModifyTitle(dndetaSym, centTxt);
652 ModifyTitle(dndetaMCSym,centTxt);
e308a636 653
e1f47419 654
e308a636 655 max = TMath::Max(max, AddHistogram(fResults, dndetaTruth, "e5 p"));
656 max = TMath::Max(max, AddHistogram(fResults, dndetaMC, dndetaMCSym));
657 max = TMath::Max(max, AddHistogram(fResults, dndeta, dndetaSym));
5bb5d1f6 658
9ecab72f 659 if (dndetaTruth) {
660 fTruth = dndetaTruth;
5bb5d1f6 661 }
9ecab72f 662 else {
663 if (fShowRings) {
664 THStack* rings = static_cast<THStack*>(list->FindObject("dndetaRings"));
665 if (rings) {
666 TIter next(rings->GetHists());
667 TH1* hist = 0;
668 while ((hist = static_cast<TH1*>(next())))
669 max = TMath::Max(max, AddHistogram(fResults, hist));
ffca499d 670 }
b2e7f2d6 671 }
9ecab72f 672 // Info("FetchResults", "Got %p, %p, %p from %s with name %s, max=%f",
673 // dndeta, dndetaMC, dndetaTruth, list->GetName(), name, max);
674
675 if (fShowLeftRight) {
676 fLeftRight->Add(Asymmetry(dndeta, amax));
677 fLeftRight->Add(Asymmetry(dndetaMC, amax));
9ecab72f 678 }
679
680 if (thisOther) {
681 TIter next(thisOther->GetListOfGraphs());
682 TGraph* g = 0;
683 while ((g = static_cast<TGraph*>(next()))) {
684 fRatios->Add(Ratio(dndeta, g, rmax));
685 fRatios->Add(Ratio(dndetaSym, g, rmax));
686 SetAttributes(g, color);
687 ModifyTitle(g, centTxt);
688 if (!fOthers->GetListOfGraphs() ||
689 !fOthers->GetListOfGraphs()->FindObject(g->GetName())) {
690 max = TMath::Max(max,TMath::MaxElement(g->GetN(), g->GetY()));
691 fOthers->Add(g);
692 }
693 }
694 // fOthers->Add(thisOther);
695 }
b2e7f2d6 696 }
5bb5d1f6 697 if (dndetaMC) {
698 fRatios->Add(Ratio(dndeta, dndetaMC, rmax));
699 fRatios->Add(Ratio(dndetaSym, dndetaMCSym, rmax));
700 }
9ecab72f 701 if (fTruth) {
702 fRatios->Add(Ratio(dndeta, fTruth, rmax));
703 fRatios->Add(Ratio(dndetaSym, fTruth, rmax));
b2e7f2d6 704 }
797161e8 705 return dndeta;
b2e7f2d6 706 }
707 //__________________________________________________________________
2f92ff0e 708 /**
709 * Plot the results
2f92ff0e 710 * @param max Max value
2f92ff0e 711 * @param rmax Maximum diviation from 1 of ratios
2f92ff0e 712 * @param amax Maximum diviation from 1 of asymmetries
713 */
e308a636 714 void Plot(Double_t max,
b2e7f2d6 715 Double_t rmax,
b2e7f2d6 716 Double_t amax)
717 {
718 gStyle->SetOptTitle(0);
719 gStyle->SetTitleFont(132, "xyz");
720 gStyle->SetLabelFont(132, "xyz");
721
e308a636 722 Int_t h = 800;
723 Int_t w = 800; // h / TMath::Sqrt(2);
724 Double_t y1 = 0;
725 Double_t y2 = 0;
726 Double_t y3 = 0;
797161e8 727 if (!fShowRatios) w *= 1.3;
e308a636 728 else y1 = 0.3;
797161e8 729 if (!fShowLeftRight) w *= 1.3;
e308a636 730 else {
731 Double_t y11 = y1;
732 y1 = (y11 > 0.0001 ? 0.4 : 0.2);
ffca499d 733 y2 = (y11 > 0.0001 ? 0.2 : 0.3);
e308a636 734 }
b2e7f2d6 735 TCanvas* c = new TCanvas("Results", "Results", w, h);
736 c->SetFillColor(0);
737 c->SetBorderSize(0);
738 c->SetBorderMode(0);
739
e308a636 740 PlotResults(max, y1);
b2e7f2d6 741 c->cd();
742
e308a636 743 PlotRatios(rmax, y2, y1);
b2e7f2d6 744 c->cd( );
745
e308a636 746 PlotLeftRight(amax, y3, y2);
b2e7f2d6 747 c->cd();
bad9a3c1 748
749
750 Int_t vMin = fVtxAxis->GetXmin();
751 Int_t vMax = fVtxAxis->GetXmax();
752 TString trg(fTrigString->GetTitle());
e308a636 753 Int_t nev = 0;
ffca499d 754 if (fTriggers) nev = fTriggers->GetBinContent(1);
bad9a3c1 755 trg = trg.Strip(TString::kBoth);
f709afcf 756 trg.ReplaceAll(" ", "_");
757 trg.ReplaceAll(">", "Gt");
bad9a3c1 758 TString base(Form("dndeta_%s_%s_%s_%c%02d%c%02dcm_%09dev",
759 fSysString->GetTitle(),
760 fSNNString->GetTitle(),
761 trg.Data(),
762 vMin < 0 ? 'm' : 'p', TMath::Abs(vMin),
763 vMax < 0 ? 'm' : 'p', TMath::Abs(vMax),
764 nev));
765 c->SaveAs(Form("%s.png", base.Data()));
766 c->SaveAs(Form("%s.root", base.Data()));
767 c->SaveAs(Form("%s.C", base.Data()));
33ab4a11 768 base.ReplaceAll("dndeta", "export");
769 Export(base);
b2e7f2d6 770 }
771 //__________________________________________________________________
e308a636 772 /**
773 * Build main legend
774 *
ffca499d 775 * @param stack Stack to include
776 * @param mg (optional) Multi graph to include
777 * @param x1 Lower X coordinate in the range [0,1]
778 * @param y1 Lower Y coordinate in the range [0,1]
779 * @param x2 Upper X coordinate in the range [0,1]
780 * @param y2 Upper Y coordinate in the range [0,1]
e308a636 781 */
ffca499d 782 void BuildLegend(THStack* stack, TMultiGraph* mg,
783 Double_t x1, Double_t y1, Double_t x2, Double_t y2)
e308a636 784 {
785 TLegend* l = new TLegend(x1,y1,x2,y2);
298a7264 786 l->SetNColumns(HasCent() ? 1 : 2);
e308a636 787 l->SetFillColor(0);
788 l->SetFillStyle(0);
789 l->SetBorderSize(0);
790 l->SetTextFont(132);
791
797161e8 792 // Loop over items in stack and get unique items, while ignoring
793 // mirrored data and systematic error bands
ffca499d 794 TIter next(stack->GetHists());
5bb5d1f6 795 TH1* hist = 0;
796 TObjArray unique;
797 unique.SetOwner();
797161e8 798 Bool_t sysErrSeen = false;
5bb5d1f6 799 while ((hist = static_cast<TH1*>(next()))) {
797161e8 800 TString t(hist->GetTitle());
801 TString n(hist->GetName());
802 n.ToLower();
803 if (t.Contains("mirrored")) continue;
804 if (n.Contains("syserror")) { sysErrSeen = true; continue; }
805 if (unique.FindObject(t.Data())) continue;
298a7264 806 TObjString* s1 = new TObjString(hist->GetTitle());
807 s1->SetUniqueID(((hist->GetMarkerStyle() & 0xFFFF) << 16) |
808 ((hist->GetMarkerColor() & 0xFFFF) << 0));
809 unique.Add(s1);
5bb5d1f6 810 // l->AddEntry(hist, hist->GetTitle(), "pl");
e308a636 811 }
ffca499d 812 if (mg) {
797161e8 813 // If we have other stuff, scan for unique names
ffca499d 814 TIter nexto(mg->GetListOfGraphs());
5bb5d1f6 815 TGraph* g = 0;
816 while ((g = static_cast<TGraph*>(nexto()))) {
817 TString n(g->GetTitle());
ffca499d 818 if (n.Contains("mirrored")) continue;
5bb5d1f6 819 if (unique.FindObject(n.Data())) continue;
298a7264 820 TObjString* s2 = new TObjString(n);
821 s2->SetUniqueID(((g->GetMarkerStyle() & 0xFFFF) << 16) |
822 ((g->GetMarkerColor() & 0xFFFF) << 0));
823 unique.Add(s2);
5bb5d1f6 824 // l->AddEntry(hist, hist->GetTitle(), "pl");
ffca499d 825 }
e308a636 826 }
797161e8 827
828 // Add legend entries for unique items only
5bb5d1f6 829 TIter nextu(&unique);
830 TObject* s = 0;
831 Int_t i = 0;
832 while ((s = nextu())) {
833 TLegendEntry* dd = l->AddEntry(Form("data%2d", i++),
834 s->GetName(), "lp");
835 Int_t style = (s->GetUniqueID() >> 16) & 0xFFFF;
836 Int_t color = (s->GetUniqueID() >> 0) & 0xFFFF;
837 dd->SetLineColor(kBlack);
298a7264 838 if (HasCent()) dd->SetMarkerColor(kBlack);
5bb5d1f6 839 else dd->SetMarkerColor(color);
840 dd->SetMarkerStyle(style);
841 }
797161e8 842 if (sysErrSeen) {
843 // Add entry for systematic errors
844 TLegendEntry* d0 = l->AddEntry("d0", Form("%4.1f%% Systematic error",
845 100*fFwdSysErr), "f");
e42bc740 846 d0->SetLineColor(SYSERR_COLOR);
847 d0->SetMarkerColor(SYSERR_COLOR);
848 d0->SetFillColor(SYSERR_COLOR);
849 d0->SetFillStyle(SYSERR_STYLE);
797161e8 850 d0->SetMarkerStyle(0);
851 d0->SetLineWidth(0);
852 i++;
853 }
298a7264 854 if (!HasCent() && i % 2 == 1) {
797161e8 855 // To make sure the 'data' and 'mirrored' entries are on a line
856 // by themselves
857 TLegendEntry* dd = l->AddEntry("dd", " ", "");
858 dd->SetTextSize(0);
859 dd->SetFillStyle(0);
860 dd->SetFillColor(0);
861 dd->SetLineWidth(0);
862 dd->SetLineColor(0);
863 dd->SetMarkerSize(0);
864 }
865 // Add entry for 'data'
e308a636 866 TLegendEntry* d1 = l->AddEntry("d1", "Data", "lp");
867 d1->SetLineColor(kBlack);
868 d1->SetMarkerColor(kBlack);
869 d1->SetMarkerStyle(20);
797161e8 870 // Add entry for 'mirrored data'
298a7264 871 if (fMirror) {
872 TLegendEntry* d2 = l->AddEntry("d2", "Mirrored data", "lp");
873 d2->SetLineColor(kBlack);
874 d2->SetMarkerColor(kBlack);
875 d2->SetMarkerStyle(24);
876 }
e308a636 877
878 l->Draw();
879 }
880 //__________________________________________________________________
5bb5d1f6 881 /**
882 * Build centrality legend
883 *
5bb5d1f6 884 * @param x1 Lower X coordinate in the range [0,1]
885 * @param y1 Lower Y coordinate in the range [0,1]
886 * @param x2 Upper X coordinate in the range [0,1]
887 * @param y2 Upper Y coordinate in the range [0,1]
888 */
889 void BuildCentLegend(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
890 {
298a7264 891 if (!HasCent()) return;
5bb5d1f6 892
893 TLegend* l = new TLegend(x1,y1,x2,y2);
894 l->SetNColumns(1);
895 l->SetFillColor(0);
896 l->SetFillStyle(0);
897 l->SetBorderSize(0);
898 l->SetTextFont(132);
899
900 Int_t n = fCentAxis->GetNbins();
901 for (Int_t i = 1; i <= n; i++) {
902 Double_t low = fCentAxis->GetBinLowEdge(i);
903 Double_t upp = fCentAxis->GetBinUpEdge(i);
904 TLegendEntry* e = l->AddEntry(Form("dummy%02d", i),
905 Form("%3d%% - %3d%%",
906 int(low), int(upp)), "pl");
907 e->SetMarkerColor(GetCentralityColor(i));
908 }
909 l->Draw();
910 }
911 //__________________________________________________________________
2f92ff0e 912 /**
913 * Plot the results
914 *
2f92ff0e 915 * @param max Maximum
916 * @param yd Bottom position of pad
917 */
e308a636 918 void PlotResults(Double_t max, Double_t yd)
b2e7f2d6 919 {
920 // Make a sub-pad for the result itself
921 TPad* p1 = new TPad("p1", "p1", 0, yd, 1.0, 1.0, 0, 0, 0);
922 p1->SetTopMargin(0.05);
923 p1->SetBorderSize(0);
924 p1->SetBorderMode(0);
925 p1->SetBottomMargin(yd > 0.001 ? 0.001 : 0.1);
797161e8 926 p1->SetRightMargin(0.03);
927 if (fShowLeftRight || fShowRatios) p1->SetGridx();
b2e7f2d6 928 p1->SetTicks(1,1);
929 p1->SetNumber(1);
930 p1->Draw();
931 p1->cd();
33ab4a11 932
e308a636 933 // Info("PlotResults", "Plotting results with max=%f", max);
934 fResults->SetMaximum(1.15*max);
935 fResults->SetMinimum(yd > 0.00001 ? -0.1 : 0);
b2e7f2d6 936
797161e8 937 FixAxis(fResults, (1-yd)*(yd > .001 ? 1 : .9 / 1.2),
938 "#font[12]{#frac{1}{N} "
939 "#frac{dN_{#font[132]{ch}}}{d#font[152]{#eta}}}");
b2e7f2d6 940
941 p1->Clear();
e308a636 942 fResults->DrawClone("nostack e1");
b2e7f2d6 943
e308a636 944 fRangeParam->fSlave1Axis = fResults->GetXaxis();
b2e7f2d6 945 fRangeParam->fSlave1Pad = p1;
946
947 // Draw other data
797161e8 948 if (fShowOthers != 0) {
b2e7f2d6 949 TGraphAsymmErrors* o = 0;
e308a636 950 TIter nextG(fOthers->GetListOfGraphs());
b2e7f2d6 951 while ((o = static_cast<TGraphAsymmErrors*>(nextG())))
952 o->DrawClone("same p");
953 }
954
955 // Make a legend in the main result pad
5bb5d1f6 956 BuildCentLegend(.12, 1-p1->GetTopMargin()-.01-.5,
957 .35, 1-p1->GetTopMargin()-.01-.1);
298a7264 958 Double_t x1 = (HasCent() ? .7 : .15);
959 Double_t x2 = (HasCent() ? 1-p1->GetRightMargin()-.01: .90);
960 Double_t y1 = (HasCent() ? .5: p1->GetBottomMargin()+.01);
961 Double_t y2 = (HasCent() ? 1-p1->GetTopMargin()-.01-.15 : .35);
5bb5d1f6 962
963 BuildLegend(fResults, fOthers, x1, y1, x2, y2);
b2e7f2d6 964
965 // Put a title on top
ffca499d 966 fTitle.ReplaceAll("@", " ");
b2e7f2d6 967 TLatex* tit = new TLatex(0.10, 0.95, fTitle.Data());
968 tit->SetNDC();
969 tit->SetTextFont(132);
970 tit->SetTextSize(0.05);
971 tit->Draw();
972
f709afcf 973 Int_t aliceBlue = TColor::GetColor(41,73,156);
b2e7f2d6 974 // Put a nice label in the plot
975 TString eS;
bad9a3c1 976 UShort_t snn = fSNNString->GetUniqueID();
977 const char* sys = fSysString->GetTitle();
5bb5d1f6 978 if (snn == 2750) snn = 2760;
b2e7f2d6 979 if (snn > 1000) eS = Form("%4.2fTeV", float(snn)/1000);
980 else eS = Form("%3dGeV", snn);
5bb5d1f6 981 TLatex* tt = new TLatex(.93, .93, Form("%s #sqrt{s%s}=%s, %s",
b2e7f2d6 982 sys,
298a7264 983 (HasCent() ? "_{NN}" : ""),
b2e7f2d6 984 eS.Data(),
298a7264 985 HasCent() ? "by centrality" :
bad9a3c1 986 fTrigString->GetTitle()));
f709afcf 987 tt->SetTextColor(aliceBlue);
b2e7f2d6 988 tt->SetNDC();
989 tt->SetTextFont(132);
990 tt->SetTextAlign(33);
991 tt->Draw();
992
993 // Put number of accepted events on the plot
e308a636 994 Int_t nev = 0;
ffca499d 995 if (fTriggers) nev = fTriggers->GetBinContent(1);
b2e7f2d6 996 TLatex* et = new TLatex(.93, .83, Form("%d events", nev));
f709afcf 997 et->SetTextColor(aliceBlue);
b2e7f2d6 998 et->SetNDC();
999 et->SetTextFont(132);
1000 et->SetTextAlign(33);
1001 et->Draw();
1002
1003 // Put number of accepted events on the plot
1004 if (fVtxAxis) {
1005 TLatex* vt = new TLatex(.93, .88, fVtxAxis->GetTitle());
1006 vt->SetNDC();
1007 vt->SetTextFont(132);
1008 vt->SetTextAlign(33);
f709afcf 1009 vt->SetTextColor(aliceBlue);
b2e7f2d6 1010 vt->Draw();
1011 }
1012 // results->Draw("nostack e1 same");
1013
e308a636 1014 fRangeParam->fSlave1Axis = FindXAxis(p1, fResults->GetName());
b2e7f2d6 1015 fRangeParam->fSlave1Pad = p1;
1016
1017
1018 // Mark the plot as preliminary
f709afcf 1019 TLatex* pt = new TLatex(.12, .93, "Work in progress");
b2e7f2d6 1020 pt->SetNDC();
1021 pt->SetTextFont(22);
f709afcf 1022 // pt->SetTextSize();
1023 pt->SetTextColor(TColor::GetColor(234,26,46));
b2e7f2d6 1024 pt->SetTextAlign(13);
1025 pt->Draw();
1026
f709afcf 1027 const char* logos[] = { "ALICE.png", "FMD.png", 0 };
1028 const char** logo = logos;
1029 while (*logo) {
1030 if (gSystem->AccessPathName(*logo)) {
1031 logo++;
1032 continue;
1033 }
797161e8 1034 TPad* pad = new TPad("logo", "logo", .12, .7, .25, .9, 0, 0, 0);
f709afcf 1035 pad->SetFillStyle(0);
1036 pad->Draw();
1037 pad->cd();
b2e7f2d6 1038 TImage* i = TImage::Create();
f709afcf 1039 i->ReadImage(*logo);
b2e7f2d6 1040 i->Draw();
f709afcf 1041 break;
b2e7f2d6 1042 }
1043 p1->cd();
1044 }
1045 //__________________________________________________________________
2f92ff0e 1046 /**
1047 * Plot the ratios
1048 *
2f92ff0e 1049 * @param max Maximum diviation from 1
1050 * @param y1 Lower y coordinate of pad
1051 * @param y2 Upper y coordinate of pad
1052 */
e308a636 1053 void PlotRatios(Double_t max, Double_t y1, Double_t y2)
b2e7f2d6 1054 {
797161e8 1055 if (fShowRatios == 0) return;
e308a636 1056
b2e7f2d6 1057 bool isBottom = (y1 < 0.0001);
1058 Double_t yd = y2 - y1;
1059 // Make a sub-pad for the result itself
1060 TPad* p2 = new TPad("p2", "p2", 0, y1, 1.0, y2, 0, 0, 0);
1061 p2->SetTopMargin(0.001);
797161e8 1062 p2->SetRightMargin(0.03);
b2e7f2d6 1063 p2->SetBottomMargin(isBottom ? 1/yd * 0.07 : 0.0001);
1064 p2->SetGridx();
1065 p2->SetTicks(1,1);
1066 p2->SetNumber(2);
1067 p2->Draw();
1068 p2->cd();
1069
1070 // Fix up axis
797161e8 1071 FixAxis(fRatios, yd, "Ratios", 7);
b2e7f2d6 1072
e308a636 1073 fRatios->SetMaximum(1+TMath::Max(.22,1.05*max));
1074 fRatios->SetMinimum(1-TMath::Max(.32,1.05*max));
b2e7f2d6 1075 p2->Clear();
e308a636 1076 fRatios->DrawClone("nostack e1");
b2e7f2d6 1077
1078
1079 // Make a legend
ffca499d 1080 BuildLegend(fRatios, 0, .15,p2->GetBottomMargin()+.01,.9,
1081 isBottom ? .6 : .4);
1082#if 0
b2e7f2d6 1083 TLegend* l2 = p2->BuildLegend(.15,p2->GetBottomMargin()+.01,.9,
1084 isBottom ? .6 : .4);
1085 l2->SetNColumns(2);
1086 l2->SetFillColor(0);
1087 l2->SetFillStyle(0);
1088 l2->SetBorderSize(0);
1089 l2->SetTextFont(132);
ffca499d 1090#endif
b2e7f2d6 1091 // Make a nice band from 0.9 to 1.1
1092 TGraphErrors* band = new TGraphErrors(2);
e1f47419 1093 band->SetPoint(0, fResults->GetXaxis()->GetXmin(), 1);
1094 band->SetPoint(1, fResults->GetXaxis()->GetXmax(), 1);
b2e7f2d6 1095 band->SetPointError(0, 0, .1);
1096 band->SetPointError(1, 0, .1);
1097 band->SetFillColor(kYellow+2);
1098 band->SetFillStyle(3002);
1099 band->SetLineStyle(2);
1100 band->SetLineWidth(1);
1101 band->Draw("3 same");
1102 band->DrawClone("X L same");
1103
1104 // Replot the ratios on top
e308a636 1105 fRatios->DrawClone("nostack e1 same");
b2e7f2d6 1106
1107 if (isBottom) {
e308a636 1108 fRangeParam->fMasterAxis = FindXAxis(p2, fRatios->GetName());
b2e7f2d6 1109 p2->AddExec("range", Form("RangeExec((dNdetaDrawer::RangeParam*)%p)",
1110 fRangeParam));
1111 }
1112 else {
e308a636 1113 fRangeParam->fSlave2Axis = FindXAxis(p2, fRatios->GetName());
b2e7f2d6 1114 fRangeParam->fSlave2Pad = p2;
1115 }
1116 }
1117 //__________________________________________________________________
2f92ff0e 1118 /**
1119 * Plot the asymmetries
1120 *
2f92ff0e 1121 * @param max Maximum diviation from 1
1122 * @param y1 Lower y coordinate of pad
1123 * @param y2 Upper y coordinate of pad
1124 */
e308a636 1125 void PlotLeftRight(Double_t max, Double_t y1, Double_t y2)
b2e7f2d6 1126 {
e308a636 1127 if (!fShowLeftRight) return;
1128
b2e7f2d6 1129 bool isBottom = (y1 < 0.0001);
1130 Double_t yd = y2 - y1;
1131 // Make a sub-pad for the result itself
1132 TPad* p3 = new TPad("p3", "p3", 0, y1, 1.0, y2, 0, 0, 0);
1133 p3->SetTopMargin(0.001);
797161e8 1134 p3->SetRightMargin(0.03);
b2e7f2d6 1135 p3->SetBottomMargin(isBottom ? 1/yd * 0.07 : 0.0001);
1136 p3->SetGridx();
1137 p3->SetTicks(1,1);
1138 p3->SetNumber(2);
1139 p3->Draw();
1140 p3->cd();
1141
b2e7f2d6 1142 // Fix up axis
797161e8 1143 FixAxis(fLeftRight, yd, "Right/Left", 4);
b2e7f2d6 1144
e308a636 1145 fLeftRight->SetMaximum(1+TMath::Max(.12,1.05*max));
1146 fLeftRight->SetMinimum(1-TMath::Max(.15,1.05*max));
b2e7f2d6 1147 p3->Clear();
e308a636 1148 fLeftRight->DrawClone("nostack e1");
b2e7f2d6 1149
1150
1151 // Make a legend
298a7264 1152 Double_t xx1 = (HasCent() ? .7 : .15);
1153 Double_t xx2 = (HasCent() ? 1-p3->GetRightMargin()-.01 : .90);
5bb5d1f6 1154 Double_t yy1 = p3->GetBottomMargin()+.01;
298a7264 1155 Double_t yy2 = (HasCent() ? 1-p3->GetTopMargin()-.01-.15 : .5);
5bb5d1f6 1156 BuildLegend(fLeftRight, 0, xx1, yy1, xx2, yy2);
1157 // TLegend* l2 = p3->BuildLegend(.15,p3->GetBottomMargin()+.01,.9,.5);
1158 // l2->SetNColumns(2);
1159 // l2->SetFillColor(0);
1160 // l2->SetFillStyle(0);
1161 // l2->SetBorderSize(0);
1162 // l2->SetTextFont(132);
ffca499d 1163
b2e7f2d6 1164 // Make a nice band from 0.9 to 1.1
1165 TGraphErrors* band = new TGraphErrors(2);
e1f47419 1166 band->SetPoint(0, fResults->GetXaxis()->GetXmin(), 1);
1167 band->SetPoint(1, fResults->GetXaxis()->GetXmax(), 1);
b2e7f2d6 1168 band->SetPointError(0, 0, .05);
1169 band->SetPointError(1, 0, .05);
1170 band->SetFillColor(kYellow+2);
1171 band->SetFillStyle(3002);
1172 band->SetLineStyle(2);
1173 band->SetLineWidth(1);
1174 band->Draw("3 same");
1175 band->DrawClone("X L same");
1176
e308a636 1177 fLeftRight->DrawClone("nostack e1 same");
b2e7f2d6 1178 if (isBottom) {
e308a636 1179 fRangeParam->fMasterAxis = FindXAxis(p3, fLeftRight->GetName());
b2e7f2d6 1180 p3->AddExec("range", Form("RangeExec((dNdetaDrawer::RangeParam*)%p)",
1181 fRangeParam));
1182 }
1183 else {
e308a636 1184 fRangeParam->fSlave2Axis = FindXAxis(p3, fLeftRight->GetName());
b2e7f2d6 1185 fRangeParam->fSlave2Pad = p3;
1186 }
1187 }
2f92ff0e 1188 /** @} */
1189 //==================================================================
1190 /**
1191 * @{
1192 * @name Data utility functions
1193 */
1194 /**
1195 * Get a result from the passed list
1196 *
1197 * @param list List to search
1198 * @param name Object name to search for
1199 *
290052e7 1200 * @return Histogram
2f92ff0e 1201 */
e1f47419 1202 TH1* FetchResult(const TList* list, const char* name) const
2f92ff0e 1203 {
1204 if (!list) return 0;
1205
e308a636 1206 TH1* ret = static_cast<TH1*>(list->FindObject(name));
5bb5d1f6 1207#if 0
e1f47419 1208 if (!ret) {
1209 // all->ls();
1210 Warning("GetResult", "Histogram %s not found", name);
2f92ff0e 1211 }
5bb5d1f6 1212#endif
b2e7f2d6 1213
e1f47419 1214 return ret;
2f92ff0e 1215 }
b2e7f2d6 1216 //__________________________________________________________________
2f92ff0e 1217 /**
1218 * Add a histogram to the stack after possibly rebinning it
1219 *
1220 * @param stack Stack to add to
1221 * @param hist histogram
1222 * @param option Draw options
1223 *
1224 * @return Maximum of histogram
1225 */
e308a636 1226 Double_t AddHistogram(THStack* stack, TH1* hist, Option_t* option="") const
b2e7f2d6 1227 {
1228 // Check if we have input
1229 if (!hist) return 0;
1230
1231 // Rebin if needed
1232 Rebin(hist);
1233
1234 stack->Add(hist, option);
1235 return hist->GetMaximum();
1236 }
1237 //__________________________________________________________________
2f92ff0e 1238 /**
1239 * Add a histogram to the stack after possibly rebinning it
1240 *
1241 * @param stack Stack to add to
1242 * @param hist histogram
1243 * @param option Draw options
1244 * @param sym On return, the data symmetriced (added to stack)
1245 *
1246 * @return Maximum of histogram
1247 */
e308a636 1248 Double_t AddHistogram(THStack* stack, TH1* hist, TH1*& sym,
1249 Option_t* option="") const
b2e7f2d6 1250 {
1251 // Check if we have input
1252 if (!hist) return 0;
1253
1254 // Rebin if needed
1255 Rebin(hist);
1256 stack->Add(hist, option);
1257
1258 // Now symmetrice the histogram
298a7264 1259 if (fMirror) {
1260 sym = Symmetrice(hist);
1261 stack->Add(sym, option);
1262 }
b2e7f2d6 1263
1264 return hist->GetMaximum();
1265 }
1266
1267 //__________________________________________________________________
1268 /**
1269 * Rebin a histogram
1270 *
1271 * @param h Histogram to rebin
b2e7f2d6 1272 */
1273 virtual void Rebin(TH1* h) const
1274 {
1275 if (fRebin <= 1) return;
1276
1277 Int_t nBins = h->GetNbinsX();
1278 if(nBins % fRebin != 0) {
1279 Warning("Rebin", "Rebin factor %d is not a devisor of current number "
1280 "of bins %d in the histogram %s", fRebin, nBins, h->GetName());
1281 return;
1282 }
1283
1284 // Make a copy
1285 TH1* tmp = static_cast<TH1*>(h->Clone("tmp"));
1286 tmp->Rebin(fRebin);
1287 tmp->SetDirectory(0);
e28f5fc5 1288 tmp->Reset();
b2e7f2d6 1289 // The new number of bins
1290 Int_t nBinsNew = nBins / fRebin;
1291 for(Int_t i = 1;i<= nBinsNew; i++) {
1292 Double_t content = 0;
1293 Double_t sumw = 0;
1294 Double_t wsum = 0;
1295 Int_t nbins = 0;
1296 for(Int_t j = 1; j<=fRebin;j++) {
1297 Int_t bin = (i-1)*fRebin + j;
1298 Double_t c = h->GetBinContent(bin);
1299
1300 if (c <= 0) continue;
1301
1302 if (fCutEdges) {
1303 if (h->GetBinContent(bin+1)<=0 ||
1304 h->GetBinContent(bin-1)) {
1305 Warning("Rebin", "removing bin %d=%f of %s (%d=%f,%d=%f)",
1306 bin, c, h->GetName(),
1307 bin+1, h->GetBinContent(bin+1),
1308 bin-1, h->GetBinContent(bin-1));
1309 continue;
1310 }
1311 }
1312 Double_t e = h->GetBinError(bin);
1313 Double_t w = 1 / (e*e); // 1/c/c
1314 content += c;
1315 sumw += w;
1316 wsum += w * c;
1317 nbins++;
1318 }
1319
e28f5fc5 1320 if(content > 0 && nbins > 1 ) {
b2e7f2d6 1321 tmp->SetBinContent(i, wsum / sumw);
1322 tmp->SetBinError(i,1./TMath::Sqrt(sumw));
1323 }
1324 }
1325
1326 // Finally, rebin the histogram, and set new content
1327 h->Rebin(fRebin);
1328 h->Reset();
1329 for(Int_t i = 1; i<= nBinsNew; i++) {
1330 h->SetBinContent(i,tmp->GetBinContent(i));
1331 h->SetBinError(i, tmp->GetBinError(i));
1332 }
1333
1334 delete tmp;
1335 }
1336 //__________________________________________________________________
1337 /**
1338 * Make an extension of @a h to make it symmetric about 0
1339 *
1340 * @param h Histogram to symmertrice
1341 *
1342 * @return Symmetric extension of @a h
1343 */
1344 TH1* Symmetrice(const TH1* h) const
1345 {
1346 Int_t nBins = h->GetNbinsX();
1347 TH1* s = static_cast<TH1*>(h->Clone(Form("%s_mirror", h->GetName())));
1348 s->SetTitle(Form("%s (mirrored)", h->GetTitle()));
1349 s->Reset();
1350 s->SetBins(nBins, -h->GetXaxis()->GetXmax(), -h->GetXaxis()->GetXmin());
1351 s->SetMarkerColor(h->GetMarkerColor());
1352 s->SetMarkerSize(h->GetMarkerSize());
1353 s->SetMarkerStyle(h->GetMarkerStyle()+4);
1354 s->SetFillColor(h->GetFillColor());
1355 s->SetFillStyle(h->GetFillStyle());
1356 s->SetDirectory(0);
1357
1358 // Find the first and last bin with data
1359 Int_t first = nBins+1;
1360 Int_t last = 0;
1361 for (Int_t i = 1; i <= nBins; i++) {
1362 if (h->GetBinContent(i) <= 0) continue;
1363 first = TMath::Min(first, i);
1364 last = TMath::Max(last, i);
1365 }
1366
1367 Double_t xfirst = h->GetBinCenter(first-1);
1368 Int_t f1 = h->GetXaxis()->FindBin(-xfirst);
1369 Int_t l2 = s->GetXaxis()->FindBin(xfirst);
1370 for (Int_t i = f1, j=l2; i <= last; i++,j--) {
1371 s->SetBinContent(j, h->GetBinContent(i));
1372 s->SetBinError(j, h->GetBinError(i));
1373 }
1374 // Fill in overlap bin
1375 s->SetBinContent(l2+1, h->GetBinContent(first));
1376 s->SetBinError(l2+1, h->GetBinError(first));
1377 return s;
1378 }
1379 //__________________________________________________________________
2f92ff0e 1380 /**
1381 * Calculate the left-right asymmetry of input histogram
1382 *
1383 * @param h Input histogram
1384 * @param max On return, the maximum distance from 1 of the histogram
1385 *
1386 * @return Asymmetry
1387 */
1388 TH1* Asymmetry(TH1* h, Double_t& max)
1389 {
1390 if (!h) return 0;
1391
1392 TH1* ret = static_cast<TH1*>(h->Clone(Form("%s_leftright", h->GetName())));
1393 // Int_t oBins = h->GetNbinsX();
1394 // Double_t high = h->GetXaxis()->GetXmax();
1395 // Double_t low = h->GetXaxis()->GetXmin();
1396 // Double_t dBin = (high - low) / oBins;
1397 // Int_t tBins = Int_t(2*high/dBin+.5);
1398 // ret->SetBins(tBins, -high, high);
e308a636 1399 ret->SetDirectory(0);
2f92ff0e 1400 ret->Reset();
1401 ret->SetTitle(Form("%s (+/-)", h->GetTitle()));
1402 ret->SetYTitle("Right/Left");
1403 Int_t nBins = h->GetNbinsX();
1404 for (Int_t i = 1; i <= nBins; i++) {
1405 Double_t x = h->GetBinCenter(i);
1406 if (x > 0) break;
1407
1408 Double_t c1 = h->GetBinContent(i);
1409 Double_t e1 = h->GetBinError(i);
1410 if (c1 <= 0) continue;
1411
1412 Int_t j = h->FindBin(-x);
1413 if (j <= 0 || j > nBins) continue;
1414
1415 Double_t c2 = h->GetBinContent(j);
1416 Double_t e2 = h->GetBinError(j);
1417
1418 Double_t c12 = c1*c1;
1419 Double_t e = TMath::Sqrt((e2*e2*c1*c1+e1*e1*c2*c2)/(c12*c12));
1420
1421 Int_t k = ret->FindBin(x);
1422 ret->SetBinContent(k, c2/c1);
1423 ret->SetBinError(k, e);
1424 }
1425 max = TMath::Max(max, RatioMax(ret));
1426
1427 return ret;
1428 }
1429 //__________________________________________________________________
1430 /**
1431 * Transform a graph into a histogram
1432 *
290052e7 1433 * @param g Graph
2f92ff0e 1434 *
290052e7 1435 * @return Histogram
2f92ff0e 1436 */
1437 TH1* Graph2Hist(const TGraphAsymmErrors* g) const
1438 {
1439 Int_t nBins = g->GetN();
1440 TArrayF bins(nBins+1);
1441 Double_t dx = 0;
1442 for (Int_t i = 0; i < nBins; i++) {
1443 Double_t x = g->GetX()[i];
1444 Double_t exl = g->GetEXlow()[i];
1445 Double_t exh = g->GetEXhigh()[i];
1446 bins.fArray[i] = x-exl;
1447 bins.fArray[i+1] = x+exh;
1448 Double_t dxi = exh+exl;
1449 if (i == 0) dx = dxi;
1450 else if (dxi != dx) dx = 0;
1451 }
1452 TString name(g->GetName());
1453 TString title(g->GetTitle());
1454 TH1D* h = 0;
1455 if (dx != 0) {
1456 h = new TH1D(name.Data(), title.Data(), nBins, bins[0], bins[nBins]);
1457 }
1458 else {
1459 h = new TH1D(name.Data(), title.Data(), nBins, bins.fArray);
1460 }
1461 h->SetMarkerStyle(g->GetMarkerStyle());
1462 h->SetMarkerColor(g->GetMarkerColor());
1463 h->SetMarkerSize(g->GetMarkerSize());
1464
1465 return h;
1466 }
1467 /* @} */
1468 //==================================================================
1469 /**
1470 * @{
1471 * @name Ratio utility functions
1472 */
1473 /**
1474 * Get the maximum diviation from 1 in the passed ratio
1475 *
1476 * @param h Ratio histogram
1477 *
1478 * @return Max diviation from 1
1479 */
b2e7f2d6 1480 Double_t RatioMax(TH1* h) const
1481 {
1482 Int_t nBins = h->GetNbinsX();
1483 Double_t ret = 0;
1484 for (Int_t i = 1; i <= nBins; i++) {
1485 Double_t c = h->GetBinContent(i);
1486 if (c == 0) continue;
1487 Double_t e = h->GetBinError(i);
1488 Double_t d = TMath::Abs(1-c-e);
1489 ret = TMath::Max(d, ret);
1490 }
1491 return ret;
1492 }
1493 //__________________________________________________________________
e1f47419 1494 /**
1495 * Make the ratio of h1 to h2
1496 *
ffca499d 1497 * @param o1 First object (numerator)
1498 * @param o2 Second object (denominator)
1499 * @param max Maximum diviation from 1
e1f47419 1500 *
ffca499d 1501 * @return o1 / o2
e1f47419 1502 */
1503 TH1* Ratio(const TObject* o1, const TObject* o2, Double_t& max) const
1504 {
b30dee70 1505 if (!o1 || !o2) return 0;
1506
5bb5d1f6 1507 TH1* r = 0;
1508 const TAttMarker* m1 = 0;
1509 const TAttMarker* m2 = 0;
e1f47419 1510 const TH1* h1 = dynamic_cast<const TH1*>(o1);
1511 if (h1) {
5bb5d1f6 1512 m1 = h1;
e1f47419 1513 const TH1* h2 = dynamic_cast<const TH1*>(o2);
ffca499d 1514 if (h2) {
5bb5d1f6 1515 m2 = h2;
1516 r = RatioHH(h1,h2);
ffca499d 1517 }
1518 else {
1519 const TGraph* g2 = dynamic_cast<const TGraph*>(o2);
1520 if (g2) {
5bb5d1f6 1521 m2 = g2;
1522 r = RatioHG(h1,g2);
ffca499d 1523 }
1524 }
e1f47419 1525 }
ffca499d 1526 else {
1527 const TGraphAsymmErrors* g1 = dynamic_cast<const TGraphAsymmErrors*>(o1);
1528 if (g1) {
5bb5d1f6 1529 m1 = g1;
ffca499d 1530 const TGraphAsymmErrors* g2 =
1531 dynamic_cast<const TGraphAsymmErrors*>(o2);
1532 if (g2) {
5bb5d1f6 1533 m2 = g2;
1534 r = RatioGG(g1, g2);
ffca499d 1535 }
1536 }
e1f47419 1537 }
ffca499d 1538 if (!r) {
1539 Warning("Ratio", "Don't know how to divide a %s (%s) with a %s (%s)",
1540 o1->ClassName(), o1->GetName(), o2->ClassName(), o2->GetName());
1541 return 0;
1542 }
1543 // Check that the histogram isn't empty
1544 if (r->GetEntries() <= 0) {
1545 delete r;
1546 r = 0;
1547 }
5bb5d1f6 1548 if (r) {
9ecab72f 1549 r->SetMarkerStyle(m2->GetMarkerStyle());
1550 r->SetMarkerColor(m1->GetMarkerColor());
5bb5d1f6 1551 r->SetMarkerSize(0.9*m1->GetMarkerSize());
1552 r->SetName(Form("%s_over_%s", o1->GetName(), o2->GetName()));
1553 r->SetTitle(Form("%s / %s", o1->GetTitle(), o2->GetTitle()));
1554 r->SetDirectory(0);
1555 max = TMath::Max(RatioMax(r), max);
1556 }
1557
ffca499d 1558 return r;
e1f47419 1559 }
1560 //__________________________________________________________________
b2e7f2d6 1561 /**
1562 * Compute the ratio of @a h to @a g. @a g is evaluated at the bin
1563 * centers of @a h
1564 *
1565 * @param h Numerator
1566 * @param g Divisor
1567 *
1568 * @return h/g
1569 */
5bb5d1f6 1570 TH1* RatioHG(const TH1* h, const TGraph* g) const
b2e7f2d6 1571 {
1572 if (!h || !g) return 0;
1573
1574 TH1* ret = static_cast<TH1*>(h->Clone("tmp"));
b2e7f2d6 1575 ret->Reset();
b2e7f2d6 1576 Double_t xlow = g->GetX()[0];
1577 Double_t xhigh = g->GetX()[g->GetN()-1];
1578 if (xlow > xhigh) { Double_t t = xhigh; xhigh = xlow; xlow = t; }
1579
1580 for (Int_t i = 1; i <= h->GetNbinsX(); i++) {
1581 Double_t c = h->GetBinContent(i);
1582 if (c <= 0) continue;
1583
1584 Double_t x = h->GetBinCenter(i);
1585 if (x < xlow || x > xhigh) continue;
1586
1587 Double_t f = g->Eval(x);
1588 if (f <= 0) continue;
1589
1590 ret->SetBinContent(i, c / f);
1591 ret->SetBinError(i, h->GetBinError(i) / f);
1592 }
b2e7f2d6 1593 return ret;
1594 }
1595 //__________________________________________________________________
1596 /**
1597 * Make the ratio of h1 to h2
1598 *
1599 * @param h1 First histogram (numerator)
1600 * @param h2 Second histogram (denominator)
1601 *
1602 * @return h1 / h2
1603 */
5bb5d1f6 1604 TH1* RatioHH(const TH1* h1, const TH1* h2) const
b2e7f2d6 1605 {
1606 if (!h1 || !h2) return 0;
5bb5d1f6 1607 TH1* t1 = static_cast<TH1*>(h1->Clone("tmp"));
b2e7f2d6 1608 t1->Divide(h2);
b2e7f2d6 1609 return t1;
1610 }
1611 //__________________________________________________________________
1612 /**
1613 * Calculate the ratio of two graphs - g1 / g2
1614 *
1615 * @param g1 Numerator
1616 * @param g2 Denominator
1617 *
1618 * @return g1 / g2 in a histogram
1619 */
ffca499d 1620 TH1* RatioGG(const TGraphAsymmErrors* g1,
5bb5d1f6 1621 const TGraphAsymmErrors* g2) const
b2e7f2d6 1622 {
1623 Int_t nBins = g1->GetN();
1624 TArrayF bins(nBins+1);
1625 Double_t dx = 0;
1626 for (Int_t i = 0; i < nBins; i++) {
1627 Double_t x = g1->GetX()[i];
1628 Double_t exl = g1->GetEXlow()[i];
1629 Double_t exh = g1->GetEXhigh()[i];
1630 bins.fArray[i] = x-exl;
1631 bins.fArray[i+1] = x+exh;
1632 Double_t dxi = exh+exl;
1633 if (i == 0) dx = dxi;
1634 else if (dxi != dx) dx = 0;
1635 }
b2e7f2d6 1636 TH1* h = 0;
1637 if (dx != 0) {
5bb5d1f6 1638 h = new TH1F("tmp", "tmp", nBins, bins[0], bins[nBins]);
b2e7f2d6 1639 }
1640 else {
5bb5d1f6 1641 h = new TH1F("tmp", "tmp", nBins, bins.fArray);
b2e7f2d6 1642 }
b2e7f2d6 1643
1644 Double_t low = g2->GetX()[0];
1645 Double_t high = g2->GetX()[g2->GetN()-1];
1646 if (low > high) { Double_t t = low; low = high; high = t; }
1647 for (Int_t i = 0; i < nBins; i++) {
1648 Double_t x = g1->GetX()[i];
1649 if (x < low-dx || x > high+dx) continue;
1650 Double_t c1 = g1->GetY()[i];
1651 Double_t e1 = g1->GetErrorY(i);
1652 Double_t c2 = g2->Eval(x);
1653
1654 h->SetBinContent(i+1, c1 / c2);
1655 h->SetBinError(i+1, e1 / c2);
1656 }
b2e7f2d6 1657 return h;
2f92ff0e 1658 }
1659 /* @} */
1660 //==================================================================
1661 /**
1662 * @{
1663 * @name Graphics utility functions
1664 */
1665 /**
1666 * Find an X axis in a pad
1667 *
1668 * @param p Pad
1669 * @param name Histogram to find axis for
1670 *
1671 * @return Found axis or null
1672 */
1673 TAxis* FindXAxis(TVirtualPad* p, const char* name)
b2e7f2d6 1674 {
2f92ff0e 1675 TObject* o = p->GetListOfPrimitives()->FindObject(name);
1676 if (!o) {
1677 Warning("FindXAxis", "%s not found in pad", name);
1678 return 0;
b2e7f2d6 1679 }
2f92ff0e 1680 THStack* stack = dynamic_cast<THStack*>(o);
1681 if (!stack) {
1682 Warning("FindXAxis", "%s is not a THStack", name);
1683 return 0;
b2e7f2d6 1684 }
2f92ff0e 1685 if (!stack->GetHistogram()) {
1686 Warning("FindXAxis", "%s has no histogram", name);
1687 return 0;
b2e7f2d6 1688 }
2f92ff0e 1689 TAxis* ret = stack->GetHistogram()->GetXaxis();
1690 return ret;
b2e7f2d6 1691 }
2f92ff0e 1692
b2e7f2d6 1693 //__________________________________________________________________
2f92ff0e 1694 /**
1695 * Fix the apperance of the axis in a stack
1696 *
1697 * @param stack stack of histogram
c6115ede 1698 * @param yd How the canvas is cut
2f92ff0e 1699 * @param ytitle Y axis title
2f92ff0e 1700 * @param ynDiv Divisions on Y axis
c6115ede 1701 * @param force Whether to draw the stack first or not
2f92ff0e 1702 */
797161e8 1703 void FixAxis(THStack* stack, Double_t yd, const char* ytitle,
2f92ff0e 1704 Int_t ynDiv=210, Bool_t force=true)
b2e7f2d6 1705 {
e308a636 1706 if (!stack) {
1707 Warning("FixAxis", "No stack passed for %s!", ytitle);
1708 return;
1709 }
2f92ff0e 1710 if (force) stack->Draw("nostack e1");
b2e7f2d6 1711
2f92ff0e 1712 TH1* h = stack->GetHistogram();
e308a636 1713 if (!h) {
1714 Warning("FixAxis", "Stack %s has no histogram", stack->GetName());
1715 return;
1716 }
797161e8 1717 Double_t s = 1/yd/1.2;
1718 // Info("FixAxis", "for %s, s=1/%f=%f", stack->GetName(), yd, s);
1719
1720 h->SetXTitle("#font[152]{#eta}");
2f92ff0e 1721 h->SetYTitle(ytitle);
1722 TAxis* xa = h->GetXaxis();
1723 TAxis* ya = h->GetYaxis();
797161e8 1724
1725 // Int_t npixels = 20
1726 // Float_t dy = gPad->AbsPixeltoY(0) - gPad->AbsPixeltoY(npixels);
1727 // Float_t ts = dy/(gPad->GetY2() - gPad->GetY1());
1728
2f92ff0e 1729 if (xa) {
797161e8 1730 // xa->SetTitle(h->GetXTitle());
2f92ff0e 1731 // xa->SetTicks("+-");
1732 xa->SetTitleSize(s*xa->GetTitleSize());
1733 xa->SetLabelSize(s*xa->GetLabelSize());
1734 xa->SetTickLength(s*xa->GetTickLength());
797161e8 1735 // xa->SetTitleOffset(xa->GetTitleOffset()/s);
e308a636 1736
1737 if (stack != fResults) {
1738 TAxis* rxa = fResults->GetXaxis();
1739 xa->Set(rxa->GetNbins(), rxa->GetXmin(), rxa->GetXmax());
1740 }
2f92ff0e 1741 }
1742 if (ya) {
797161e8 1743 // ya->SetTitle(h->GetYTitle());
2f92ff0e 1744 ya->SetDecimals();
1745 // ya->SetTicks("+-");
1746 ya->SetNdivisions(ynDiv);
1747 ya->SetTitleSize(s*ya->GetTitleSize());
1748 ya->SetTitleOffset(ya->GetTitleOffset()/s);
1749 ya->SetLabelSize(s*ya->GetLabelSize());
b2e7f2d6 1750 }
b2e7f2d6 1751 }
797161e8 1752 //__________________________________________________________________
1753 /**
1754 * Merge two histograms into one
1755 *
1756 * @param cen Central part
1757 * @param fwd Forward part
1758 * @param xlow On return, lower eta bound
1759 * @param xhigh On return, upper eta bound
1760 *
1761 * @return Newly allocated histogram or null
1762 */
1763 TH1*
1764 Merge(const TH1* cen, const TH1* fwd, Double_t& xlow, Double_t& xhigh)
1765 {
1766 TH1* tmp = static_cast<TH1*>(fwd->Clone("tmp"));
1767 TString name(fwd->GetName());
1768 name.ReplaceAll("Forward", "Merged");
1769 tmp->SetName(name);
1770
1771 // tmp->SetMarkerStyle(28);
1772 // tmp->SetMarkerColor(kBlack);
1773 tmp->SetDirectory(0);
1774 xlow = 100;
1775 xhigh = -100;
1776 for (Int_t i = 1; i <= tmp->GetNbinsX(); i++) {
1777 Double_t cc = cen->GetBinContent(i);
1778 Double_t cf = fwd->GetBinContent(i);
1779 Double_t ec = cen->GetBinError(i);
1780 Double_t ef = fwd->GetBinError(i);
1781 Double_t nc = cf;
1782 Double_t ne = ef;
1783 if (cc < 0.001 && cf < 0.01) continue;
1784 xlow = TMath::Min(tmp->GetXaxis()->GetBinLowEdge(i),xlow);
1785 xhigh = TMath::Max(tmp->GetXaxis()->GetBinUpEdge(i),xhigh);
1786 if (cc > 0.001) {
1787 nc = cc;
1788 ne = ec;
1789 if (cf > 0.001) {
1790 nc = (cf + cc) / 2;
1791 ne = TMath::Sqrt(ec*ec + ef*ef);
1792 }
1793 }
1794 tmp->SetBinContent(i, nc);
1795 tmp->SetBinError(i, ne);
1796 }
1797 return tmp;
1798 }
1799 //____________________________________________________________________
1800 /**
1801 * Fit @f$g(x;A_1,A_2,\sigma_1,\sigma_2)@f$ to histogram data
1802 *
1803 * @param tmp Histogram
1804 * @param xlow Lower x bound
1805 * @param xhigh Upper x bound
1806 *
1807 * @return Fitted function
1808 */
1809 TF1*
1810 FitMerged(TH1* tmp, Double_t xlow, Double_t xhigh)
1811 {
1812 TF1* tmpf = new TF1("tmpf", "gaus", xlow, xhigh);
1813 tmp->Fit(tmpf, "NQ", "");
1814 tmp->SetDirectory(0);
1815
1816 TF1* fit = new TF1("f", myFunc, xlow, xhigh, 4);
1817 fit->SetParNames("a_{1}", "a_{2}", "#sigma_{1}", "#sigma_{2}");
1818 fit->SetParameters(tmpf->GetParameter(0),
1819 .2,
1820 tmpf->GetParameter(2),
1821 tmpf->GetParameter(2)/4);
1822 fit->SetParLimits(3, 0, 100);
1823 fit->SetParLimits(4, 0, 100);
1824 tmp->Fit(fit,"0W","");
1825
1826 delete tmpf;
1827 return fit;
1828 }
1829 //____________________________________________________________________
1830 /**
1831 * Make band of systematic errors
1832 *
1833 * @param tmp Histogram
c6115ede 1834 * @param cen Central
1835 * @param fwd Forward
797161e8 1836 * @param fit Fit
1837 */
1838 void
1839 MakeSysError(TH1* tmp, TH1* cen, TH1* fwd, TF1* fit)
1840 {
1841 for (Int_t i = 1; i <= tmp->GetNbinsX(); i++) {
1842 Double_t tc = tmp->GetBinContent(i);
1843 if (tc < 0.01) continue;
1844 Double_t fc = fwd->GetBinContent(i);
1845 Double_t cc = cen->GetBinContent(i);
1846 Double_t sysErr = fFwdSysErr;
1847 if (cc > .01 && fc > 0.01)
1848 sysErr = (fFwdSysErr+fCenSysErr) / 2;
1849 else if (cc > .01)
1850 sysErr = fCenSysErr;
1851 Double_t x = tmp->GetXaxis()->GetBinCenter(i);
1852 Double_t y = fit->Eval(x);
1853 tmp->SetBinContent(i, y);
1854 tmp->SetBinError(i,sysErr*y);
1855 }
1856 TString name(tmp->GetName());
1857 name.ReplaceAll("Merged", "SysError");
1858 tmp->SetName(name);
e42bc740 1859 tmp->SetMarkerColor(SYSERR_COLOR);
1860 tmp->SetLineColor(SYSERR_COLOR);
1861 tmp->SetFillColor(SYSERR_COLOR);
1862 tmp->SetFillStyle(SYSERR_STYLE);
797161e8 1863 tmp->SetMarkerStyle(0);
1864 tmp->SetLineWidth(0);
1865 }
1866 void CorrectForward(TH1* h) const
1867 {
1868 if (!fRemoveOuters) return;
1869
1870 for (Int_t i = 1; i <= h->GetNbinsX(); i++) {
1871 Double_t eta = h->GetBinCenter(i);
1872 if (TMath::Abs(eta) < 2.3) {
1873 h->SetBinContent(i, 0);
1874 h->SetBinError(i, 0);
1875 }
1876 }
1877 }
1878 void CorrectCentral(TH1* h) const
1879 {
1880 if (fClusterScale.IsNull()) return;
1881 TString t(h->GetTitle());
1882 Info("CorrectCentral", "Replacing Central with Tracklets in %s", t.Data());
1883 t.ReplaceAll("Central", "Tracklets");
1884 h->SetTitle(t);
1885
1886 TF1* cf = new TF1("clusterScale", fClusterScale);
1887 for (Int_t i = 1; i <= h->GetNbinsX(); i++) {
1888 Double_t eta = h->GetBinCenter(i);
1889 Double_t f = cf->Eval(eta);
1890 Double_t c = h->GetBinContent(i);
1891 if (f < .1) f = 1;
1892 h->SetBinContent(i, c / f);
1893 }
1894 delete cf;
1895 }
33ab4a11 1896 //____________________________________________________________________
1897 void Export(const char* basename)
1898 {
1899 TString bname(basename);
1900 bname.ReplaceAll(" ", "_");
1901 bname.ReplaceAll("-", "_");
1902 TString fname(Form("%s.C", bname.Data()));
1903
298a7264 1904 std::ofstream outf(fname.Data());
1905 if (!outf) {
33ab4a11 1906 Error("Export", "Failed to open output file %s", fname.Data());
1907 return;
1908 }
298a7264 1909 outf << "// Create by dNdetaDrawer\n"
1910 << "void " << bname << "(THStack* stack, TLegend* l, Int_t m)\n"
1911 << "{"
1912 << " Int_t ma[] = { 24, 25, 26, 32,\n"
1913 << " 20, 21, 22, 33,\n"
1914 << " 34, 30, 29, 0, \n"
1915 << " 23, 27 };\n"
1916 << " Int_t mm = ((m < 20 || m > 34) ? 0 : ma[m-20]);\n\n";
33ab4a11 1917 TList* hists = fResults->GetHists();
1918 TIter next(hists);
1919 TH1* hist = 0;
1920 while ((hist = static_cast<TH1*>(next()))) {
1921 TString hname = hist->GetName();
1922 hname.Append(Form("_%04x", (gRandom->Integer(0xffff) & 0xffff)));
1923 hist->SetName(hname);
1924 hist->GetListOfFunctions()->Clear();
298a7264 1925 hist->SavePrimitive(outf, "nodraw");
33ab4a11 1926 bool mirror = hname.Contains("mirror");
1927 bool syserr = hname.Contains("SysError");
1928 if (!syserr)
298a7264 1929 outf << " " << hname << "->SetMarkerStyle("
1930 << (mirror ? "mm" : "m") << ");\n";
33ab4a11 1931 else
298a7264 1932 outf << " " << hname << "->SetMarkerStyle(1);\n";
1933 outf << " stack->Add(" << hname
1934 << (syserr ? ",\"e5\"" : "") << ");\n\n";
33ab4a11 1935 }
1936 UShort_t snn = fSNNString->GetUniqueID();
1937 // const char* sys = fSysString->GetTitle();
1938 TString eS;
1939 if (snn == 2750) snn = 2760;
1940 if (snn < 1000) eS = Form("%3dGeV", snn);
1941 else if (snn % 1000 == 0) eS = Form("%dTeV", snn/1000);
1942 else eS = Form("%4.2fTeV", float(snn)/1000);
298a7264 1943 outf << " if (l) {\n"
1944 << " TLegendEntry* e = l->AddEntry(\"\",\"" << eS << "\",\"pl\");\n"
1945 << " e->SetMarkerStyle(m);\n"
1946 << " e->SetMarkerColor(kBlack);\n"
1947 << " }\n"
1948 << "}\n" << std::endl;
33ab4a11 1949 }
2f92ff0e 1950 /* @} */
298a7264 1951 Bool_t HasCent() const { return fCentAxis && !fForceMB; }
2f92ff0e 1952
b2e7f2d6 1953
1954
1955 //__________________________________________________________________
33ab4a11 1956 /**
1957 * @{
1958 * @name Options
1959 */
e308a636 1960 Bool_t fShowRatios; // Show ratios
1961 Bool_t fShowLeftRight;// Show asymmetry
f709afcf 1962 Bool_t fShowRings; // Show rings too
33ab4a11 1963 Bool_t fExport; // Export results to file
e308a636 1964 Bool_t fCutEdges; // Whether to cut edges
33ab4a11 1965 Bool_t fRemoveOuters; // Whether to remove outers
1966 UShort_t fShowOthers; // Show other data
298a7264 1967 Bool_t fMirror; // Whether to mirror
1968 Bool_t fForceMB; // Force min-bias
33ab4a11 1969 /* @} */
1970 /**
1971 * @{
1972 * @name Settings
1973 */
1974 UShort_t fRebin; // Rebinning factor
1975 Double_t fFwdSysErr; // Systematic error in forward range
1976 Double_t fCenSysErr; // Systematic error in central range
e308a636 1977 TString fTitle; // Title on plot
33ab4a11 1978 TString fClusterScale; // Scaling of clusters to tracklets
1979 /* @} */
1980 /**
1981 * @{
1982 * @name Read (or set) information
1983 */
e308a636 1984 TNamed* fTrigString; // Trigger string (read, or set)
0be6c8cd 1985 TNamed* fNormString; // Normalisation string (read, or set)
e308a636 1986 TNamed* fSNNString; // Energy string (read, or set)
1987 TNamed* fSysString; // Collision system string (read or set)
1988 TAxis* fVtxAxis; // Vertex cuts (read or set)
1989 TAxis* fCentAxis; // Centrality axis
33ab4a11 1990 /* @} */
1991 /**
1992 * @{
1993 * @name Resulting plots
1994 */
e308a636 1995 THStack* fResults; // Stack of results
1996 THStack* fRatios; // Stack of ratios
1997 THStack* fLeftRight; // Left-right asymmetry
1998 TMultiGraph* fOthers; // Older data
1999 TH1* fTriggers; // Number of triggers
9ecab72f 2000 TH1* fTruth; // Pointer to truth
33ab4a11 2001 /* @} */
e308a636 2002 RangeParam* fRangeParam; // Parameter object for range zoom
b2e7f2d6 2003};
2004
797161e8 2005//____________________________________________________________________
2006/**
2007 * Function to calculate
2008 * @f[
2009 * g(x;A_1,A_2,\sigma_1,\sigma_2) =
2010 * A_1\left(\frac{1}{2\pi\sigma_1}e^{(x/\sigma_1)^2} -
2011 * A_2\frac{1}{2\pi\sigma_2}e^{(x/\sigma_2)^2}\right)
2012 * @f]
2013 *
2014 * @param xp Pointer to x array
2015 * @param pp Pointer to parameter array
2016 *
2017 * @return @f$g(x;A_1,A_2,\sigma_1,\sigma_2)@f$
2018 */
2019Double_t myFunc(Double_t* xp, Double_t* pp)
2020{
2021 Double_t x = xp[0];
2022 Double_t a1 = pp[0];
2023 Double_t a2 = pp[1];
2024 Double_t s1 = pp[2];
2025 Double_t s2 = pp[3];
2026 return a1*(TMath::Gaus(x, 0, s1) - a2 * TMath::Gaus(x, 0, s2));
2027}
2028
b2e7f2d6 2029//=== Stuff for auto zooming =========================================
290052e7 2030/**
2031 * Update canvas range
2032 *
2033 * @param p Parameter
2034 */
b2e7f2d6 2035void UpdateRange(dNdetaDrawer::RangeParam* p)
2036{
2037 if (!p) {
2038 Warning("UpdateRange", "No parameters %p", p);
2039 return;
2040 }
2041 if (!p->fMasterAxis) {
2042 Warning("UpdateRange", "No master axis %p", p->fMasterAxis);
2043 return;
2044 }
2045 Int_t first = p->fMasterAxis->GetFirst();
2046 Int_t last = p->fMasterAxis->GetLast();
2047 Double_t x1 = p->fMasterAxis->GetBinCenter(first);
2048 Double_t x2 = p->fMasterAxis->GetBinCenter(last);
b2e7f2d6 2049
2050 if (p->fSlave1Axis) {
2051 Int_t i1 = p->fSlave1Axis->FindBin(x1);
2052 Int_t i2 = p->fSlave1Axis->FindBin(x2);
2053 p->fSlave1Axis->SetRange(i1, i2);
2054 p->fSlave1Pad->Modified();
2055 p->fSlave1Pad->Update();
2056 }
2057 if (p->fSlave2Axis) {
2058 Int_t i1 = p->fSlave2Axis->FindBin(x1);
2059 Int_t i2 = p->fSlave2Axis->FindBin(x2);
2060 p->fSlave2Axis->SetRange(i1, i2);
2061 p->fSlave2Pad->Modified();
2062 p->fSlave2Pad->Update();
2063 }
2064 TCanvas* c = gPad->GetCanvas();
2065 c->cd();
2066}
2067
2068//____________________________________________________________________
290052e7 2069/**
2070 * Called when user changes X range
2071 *
2072 * @param p Parameter
2073 */
b2e7f2d6 2074void RangeExec(dNdetaDrawer::RangeParam* p)
2075{
2076 // Event types:
2077 // 51: Mouse move
2078 // 53:
2079 // 1: Button down
2080 // 21: Mouse drag
2081 // 11: Mouse release
2082 // dNdetaDrawer::RangeParam* p =
2083 // reinterpret_cast<dNdetaDrawer::RangeParam*>(addr);
2084 Int_t event = gPad->GetEvent();
2085 TObject *select = gPad->GetSelected();
2086 if (event == 53) {
2087 UpdateRange(p);
2088 return;
2089 }
2090 if (event != 11 || !select || select != p->fMasterAxis) return;
2091 UpdateRange(p);
2092}
2093
33ab4a11 2094//=== Steering functions
2095//==============================================
290052e7 2096/**
2097 * Display usage information
2098 *
2099 */
33ab4a11 2100void
2101Usage()
2102{
2103 Info("DrawdNdeta", "Usage: DrawdNdeta(FILE,TITLE,REBIN,OTHERS,FLAGS)\n\n"
2104 " const char* FILE File name to open (\"forward_root\")\n"
2105 " const char* TITLE Title to put on plot (\"\")\n"
2106 " UShort_t REBIN Rebinning factor (1)\n"
2107 " UShort_t OTHERS Other data to draw - more below (0x7)\n"
2108 " UShort_t FLAGS Visualisation flags - more below (0x7)\n\n"
2109 " OTHERS is a bit mask of\n\n"
2110 " 0x1 Show UA5 data (INEL,NSD, ppbar, 900GeV)\n"
2111 " 0x2 Show CMS data (NSD, pp)\n"
2112 " 0x4 Show published ALICE data (INEL,INEL>0,NSD, pp)\n"
2113 " 0x8 Show event genertor data\n\n"
2114 " FLAGS is a bit mask of\n\n"
2115 " 0x1 Show ratios of data to other data and possibly MC\n"
2116 " 0x2 Show left-right asymmetry\n"
2117 " 0x4 Show systematic error band\n"
2118 " 0x8 Show individual ring results (INEL only)\n"
2119 " 0x10 Cut edges when rebinning\n"
2120 " 0x20 Remove FMDxO points\n"
2121 " 0x40 Do not make our own canvas\n"
298a7264 2122 " 0x80 Force use of MB\n"
2123 " 0x100 Mirror data\n"
33ab4a11 2124 );
2125}
2126
2127//____________________________________________________________________
ffca499d 2128/**
2129 * Draw @f$ dN/d\eta@f$
2130 *
2131 * @param filename File name
ffca499d 2132 * @param title Title
2133 * @param rebin Rebinning factor
c6115ede 2134 * @param others What other data to show
2135 * @param flags Flags
ffca499d 2136 * @param sNN (optional) Collision energy [GeV]
2137 * @param sys (optional) Collision system (1: pp, 2: PbPb)
2138 * @param trg (optional) Trigger (1: INEL, 2: INEL>0, 4: NSD)
2139 * @param vzMin Least @f$ v_z@f$
2140 * @param vzMax Largest @f$ v_z@f$
2141 *
bd6f5206 2142 * @ingroup pwglf_forward_dndeta
ffca499d 2143 */
b2e7f2d6 2144void
2145DrawdNdeta(const char* filename="forward_dndeta.root",
bad9a3c1 2146 const char* title="",
b2e7f2d6 2147 UShort_t rebin=5,
797161e8 2148 UShort_t others=0x7,
298a7264 2149 UShort_t flags=0x187,
fe52e455 2150 UShort_t sNN=0,
2151 UShort_t sys=0,
ffca499d 2152 UShort_t trg=0,
fe52e455 2153 Float_t vzMin=999,
2154 Float_t vzMax=-999)
b2e7f2d6 2155{
33ab4a11 2156 TString fname(filename);
2157 fname.ToLower();
2158 if (fname.CompareTo("help") == 0 ||
2159 fname.CompareTo("--help") == 0) {
2160 Usage();
2161 return;
2162 }
ffca499d 2163 dNdetaDrawer* pd = new dNdetaDrawer;
2164 dNdetaDrawer& d = *pd;
b2e7f2d6 2165 d.SetRebin(rebin);
b2e7f2d6 2166 d.SetTitle(title);
797161e8 2167 d.SetShowOthers(others);
2168 d.SetShowRatios(flags & 0x1);
2169 d.SetShowLeftRight(flags & 0x2);
2170 d.SetForwardSysError(flags & 0x4 ? 0.076 : 0);
2171 d.SetShowRings(flags & 0x8);
2172 d.SetCutEdges(flags & 0x10);
33ab4a11 2173 d.fRemoveOuters = (flags & 0x20);
2174 d.SetExport(flags & 0x40);
298a7264 2175 d.SetForceMB(flags & 0x80);
2176 d.SetMirror(flags & 0x100);
797161e8 2177 // d.fClusterScale = "1.06 -0.003*x +0.0119*x*x";
2f92ff0e 2178 // Do the below if your input data does not contain these settings
fe52e455 2179 if (sNN > 0) d.SetSNN(sNN); // Collision energy per nucleon pair (GeV)
2180 if (sys > 0) d.SetSys(sys); // Collision system (1:pp, 2:PbPB)
2181 if (trg > 0) d.SetTrigger(trg); // Collision trigger (1:INEL, 2:INEL>0, 4:NSD)
2182 if (vzMin < 999 && vzMax > -999)
2183 d.SetVertexRange(vzMin,vzMax); // Collision vertex range (cm)
b2e7f2d6 2184 d.Run(filename);
2185}
2f92ff0e 2186//____________________________________________________________________
2187//
2188// EOF
2189//
2190