1 #ifndef FASTCENTHELPER_H 2 #define FASTCENTHELPER_H 13 # include <TProfile.h> 54 if (fCentMeth.IsNull()) {
58 fCentMeth = tokens->At(0)->GetName();
59 if (tokens->GetEntriesFast() > 1)
60 axis = tokens->At(1)->GetName();
62 if (fCentMeth.Contains(
"RefMult"))
SetCentAxis(
"mult");
78 fCentAxis =
new TAxis(n, low, high);
92 fCentAxis =
new TAxis(n, edges);
111 Info(
"SetCentAxis",
"Setting centrality axis from %s", spec);
114 if (s.IsNull())
return;
115 if (s.EqualTo(
"pbpb") || s.EqualTo(
"aa") || s.EqualTo(
"default")) {
116 Printf(
"Setting centrality axis Pb-Pb");
117 Double_t aa[] = { 0, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
119 fCentAxis->SetUniqueID(2);
122 if (s.EqualTo(
"ppb") || s.EqualTo(
"pbp") ||
123 s.EqualTo(
"pa") || s.EqualTo(
"ap")) {
124 Printf(
"Setting centrality axis p-Pb/Pb-p");
125 Double_t pa[] = { 0, 5, 10, 20, 40, 60, 80, 100 };
127 fCentAxis->SetUniqueID(3);
130 if (s.EqualTo(
"pp")) {
131 Printf(
"Setting centrality axis pp");
132 Double_t pp[] = { 0, 0.01, 0.1, 1, 5, 10, 15, 20, 30, 40, 50, 70, 100 };
134 fCentAxis->SetUniqueID(1);
139 Int_t nTokens = tokens->GetEntriesFast();
141 for (
Int_t i = 0; i < nTokens; i++) {
142 TObjString* token =
static_cast<TObjString*
>(tokens->At(i));
143 TString& edge = token->String();
144 edges[i] = edge.Atof();
159 Int_t nCol = gStyle->GetNumberOfColors();
160 Int_t icol = TMath::Min(nCol-1,
int(fc * nCol + .5));
161 Int_t col = gStyle->GetColorPalette(icol);
175 return Form(
"h%03dd%02d_%03dd%02d",
181 if (!fCentAxis)
return "?";
182 return HistName(fCentAxis->GetBinLowEdge(i), fCentAxis->GetBinUpEdge(i));
194 if (fCentMeth.BeginsWith(
"RefMult")) {
198 if (iLow == 0)
return " 0";
199 else return Form(
"%2d+", iLow);
201 return Form(
"%2d-%2d", iLow+1, iHigh);
203 return Form(
"%6.2f-%6.2f%%", low, high);
217 Printf(
"Base level, setting names on %p", o);
218 if (o->IsA()->InheritsFrom(TNamed::Class())) {
224 if (o->IsA()->InheritsFrom(TCollection::Class())) {
225 Printf(
"Got a collection, will loop on that");
231 while ((oo = next()))
ModHist(oo, low, high, lvl+1);
235 if (o->IsA()->InheritsFrom(TH1::Class())) {
236 Printf(
"Got a histogram, will modify that");
237 TH1* h =
static_cast<TH1*
>(o);
238 h->SetLineColor(col);
240 h->SetMarkerColor(col);
241 h->SetMarkerStyle(24);
242 h->SetFillColor(kWhite);
258 fCentList =
new TList;
259 fCentList->SetName(
"byCent");
261 for (
Int_t i = 1; i <= fCentAxis->GetNbins(); i++) {
262 Double_t low = fCentAxis->GetBinLowEdge(i);
263 Double_t high = fCentAxis->GetBinUpEdge(i);
264 Printf(
"Calling call-back for %5.1f-%5.1f%%", low, high);
266 Printf(
"Got call back return %p", obj);
268 Printf(
"Now adding %s (%s)to centrality list",
269 obj->GetName(), obj->ClassName());
273 if (fCentMeth.BeginsWith(
"RefMult")) {
275 TObject* first = (*callback)();
277 fCentList->AddFirst(first);
282 fCentList->AddLast(last);
284 output->Add(fCentList);
287 if (fCentAxis->GetXbins()->GetArray())
288 fCentAll =
new TH1D(
"cent",
"All Centralities",
289 fCentAxis->GetNbins(),
290 fCentAxis->GetXbins()->GetArray());
292 fCentAll =
new TH1D(
"cent",
"All Centralities",
293 fCentAxis->GetNbins(),
294 fCentAxis->GetXmin(),
295 fCentAxis->GetXmax());
296 fCentAll->SetXTitle(
"Centrality [%]");
297 fCentAll->SetYTitle(
"Events");
298 fCentAll->SetFillColor(kRed+2);
299 fCentAll->SetFillStyle(3002);
300 fCentAll->SetMarkerStyle(20);
301 fCentAll->SetMarkerColor(kRed+2);
302 fCentAll->SetLineColor(kRed+2);
303 fCentAll->SetDirectory(0);
304 fCentAll->SetMinimum(0);
305 output->Add(fCentAll);
307 fCentAcc =
static_cast<TH1*
>(fCentAll->Clone(
"centAcc"));
308 fCentAcc->SetTitle(
"Accepted centralities");
309 fCentAcc->SetFillColor(kGreen+2);
310 fCentAcc->SetMarkerColor(kGreen+2);
311 fCentAcc->SetLineColor(kGreen+2);
312 fCentAcc->SetDirectory(0);
313 output->Add(fCentAcc);
316 Printf(
"End of create outputs");
326 if (fCentMult || fCentNPart)
return;
331 Int_t maxNPart = 2*210;
332 Int_t maxNBin = 7*210;
333 if (fCentAxis->GetXbins()->GetArray()) {
334 fCentNPart =
new TH2D(
"centNPart",
"Centrality vs. N_{part}",
335 fCentAxis->GetNbins(),
336 fCentAxis->GetXbins()->GetArray(),
337 maxNPart, 0, maxNPart);
338 fCentNBin =
new TH2D(
"centNBin",
"Centrality vs. N_{bin}",
339 fCentAxis->GetNbins(),
340 fCentAxis->GetXbins()->GetArray(),
341 maxNBin, 0, maxNBin);
342 fCentB =
new TH2D(
"centB",
"Centrality vs. b",
343 fCentAxis->GetNbins(),
344 fCentAxis->GetXbins()->GetArray(),
347 fCentNPart =
new TH2D(
"centNPart",
"Centrality vs. N_{part}",
348 fCentAxis->GetNbins(), fCentAxis->GetXmin(),
349 fCentAxis->GetXmax(),
350 maxNPart, 0, maxNPart);
351 fCentNBin =
new TH2D(
"centNBin",
"Centrality vs. N_{bin}",
352 fCentAxis->GetNbins(), fCentAxis->GetXmin(),
353 fCentAxis->GetXmax(),
354 maxNBin, 0, maxNBin);
355 fCentB =
new TH2D(
"centB",
"Centrality vs. b",
356 fCentAxis->GetNbins(), fCentAxis->GetXmin(),
357 fCentAxis->GetXmax(),
361 fCentNPart->SetXTitle(Form(
"Centrality (%s) %%", fCentMeth.Data()));
362 fCentNPart->SetYTitle(
"N_{part}");
363 fCentNPart->SetDirectory(0);
365 fCentNBin->SetXTitle(Form(
"Centrality (%s) %%", fCentMeth.Data()));
366 fCentNBin->SetYTitle(
"N_{bin}");
367 fCentNBin->SetDirectory(0);
369 fCentB->SetXTitle(Form(
"Centrality (%s) %%", fCentMeth.Data()));
370 fCentB->SetYTitle(
"b [fm]");
371 fCentB->SetDirectory(0);
373 output->Add(fCentNPart);
374 output->Add(fCentNBin);
377 if (!centHist)
return;;
378 if (fCentAxis->GetXbins()->GetArray()) {
379 fCentMult =
new TH2D(
"centMult",
"Event multiplicity vs. centrality",
380 centHist->GetXaxis()->GetNbins(),
381 centHist->GetXaxis()->GetXmin(),
382 centHist->GetXaxis()->GetXmax(),
383 fCentAxis->GetNbins(),
384 fCentAxis->GetXbins()->GetArray());
386 fCentMult =
new TH2D(
"centMult",
"Event multiplicity vs. centrality",
387 centHist->GetXaxis()->GetNbins(),
388 centHist->GetXaxis()->GetXmin(),
389 centHist->GetXaxis()->GetXmax(),
390 fCentAxis->GetNbins(),
391 fCentAxis->GetXmin(), fCentAxis->GetXmax());
393 fCentMult->SetXTitle(Form(
"Event multiplicity (%s)", fCentMeth.Data()));
394 fCentMult->SetYTitle(Form(
"Centrality (%s) %%", fCentMeth.Data()));
395 fCentMult->SetDirectory(0);
396 output->Add(fCentMult);
418 fCentAll->Fill(cent);
419 if (fCentMult) fCentMult->Fill(mult, cent);
420 fCentB->Fill(cent, b);
421 if (cent < 0 || cent > 999) {
422 Warning(
"FillDiagnostics",
423 "Centrality is unreasonable: %f -> %f",mult, cent);
426 Int_t n = fCentAxis->GetNbins();
427 ret = fCentAxis->FindBin(cent);
428 if (ret-1 == n && cent == fCentAxis->GetXmax())
430 if (ret < 1 || ret > n) {
431 Warning(
"ProcessHeader",
"Centrality %f -> %f -> bin # %d",
436 fCentNPart->Fill(cent, nPart);
437 fCentNBin->Fill(cent, nBin);
438 if (ret == n) cent -= 0.001;
439 fCentAcc->Fill(cent);
455 Warning(
"CentObject",
"No centrality objects defined");
458 if (fMapping.GetArray()) {
459 if (bin >= fMapping.GetSize()) {
460 Warning(
"CentObject",
"Bin # %2d out of range [%2d,%2d]",
461 bin, 1, fMapping.GetSize());
468 if (bin <= 0 || bin > fCentList->GetEntries()) {
469 if (!fMapping.GetArray())
470 Warning(
"CentObject",
"Bin # %2d out of range [%2d,%2d]",
471 bin, 1, fCentList->GetEntries());
474 TObject* o = fCentList->At(bin-1);
476 Warning(
"CentObject",
"No centrality object defined for bin %d", bin);
479 if (cls && !o->IsA()->InheritsFrom(cls)) {
480 Warning(
"CentObject",
"Centrality object %s is not a %s, but a %s",
481 o->GetName(), cls->GetName(), o->ClassName());
524 TObject* o = output->FindObject(name);
526 Warning(
"GetOutputObject",
"Object %s not found in output", name);
530 if (cls && !o->IsA()->InheritsFrom(cls)) {
531 Warning(
"GetOutputObject",
"Object %s from output is not a %s, but a %s",
532 o->GetName(), cls->GetName(), o->ClassName());
543 TProfile* p = (projX ?
544 h->ProfileX(Form(
"%sMean", name)) :
545 h->ProfileY(Form(
"%sMean", name)));
559 fCentMult =
Get2DDiag(output,
"centMult",
false);
560 fCentNPart =
Get2DDiag(output,
"centNPart",
true);
561 fCentNBin =
Get2DDiag(output,
"centNBin",
true);
562 fCentB =
Get2DDiag(output,
"centB",
true);
565 if (!fCentList || !fCentAll || !fCentAcc) {
566 Warning(
"Finalize",
"Missing stack and histograms");
569 Info(
"Terminate",
"Accepted %d/%d=%6.2f%% events",
570 int(fCentAcc->GetEntries()),
int(fCentAll->GetEntries()),
571 100*fCentAcc->GetEntries()/fCentAll->GetEntries());
573 if (!callback)
return true;
575 fMapping.Set(fCentAll->GetNbinsX()+1);
577 THStack*
stack =
new THStack(
"all",
"All");
579 TObjLink* link = hists->FirstLink();
584 Long64_t all = fCentAll->GetEntries();
586 TObject* o = link->GetObject();
592 Int_t m = fCentAcc->GetBinContent(bin);
594 printf(
"%9d events in bin %s ...", m, o->GetTitle());
597 TObjLink* tmp = link->Next();
606 TH1* h = (*callback)(o,m);
608 Printf(
" processed [%2d->%2d]", bin, cnt);
610 fMapping[bin] = cnt+1;
614 TH1* h =
static_cast<TH1*
>(o);
615 Int_t n = h->GetBinContent(0);
616 h->SetBinContent(0,0);
617 printf(
"%9d (%9d) events in bin %s ...", n, m, o->GetTitle());
620 TObjLink* tmp = link->Next();
630 h->Scale(1. / n,
"width");
638 Printf(
"ana/acc/all: %9lld/%9lld/%9lld [%6.2f%%/%6.2f%%]",
639 sum, total, all,
float(100*sum)/total,
float(100*total)/all);
640 for (
Int_t i = 1; i < fMapping.GetSize(); i++)
641 Printf(
" %3d -> %3d", i, fMapping[i]);
645 Int_t nBins = (fCentAxis?fCentAxis->GetNbins():0);
646 Printf(
" Method: %s", fCentMeth.Data());
647 Printf(
" Axis: %d", nBins);
648 if (nBins < 2)
return;
650 for (
Int_t i = 1; i <= nBins; i++)
651 printf(
"%5.1f-",fCentAxis->GetBinLowEdge(i));
652 Printf(
"%5.1f%%", fCentAxis->GetBinUpEdge(nBins));
void SetCentAxis(const char *spec)
TObject * GetOutputObject(TCollection *output, const char *name, TClass *cls)
Bool_t Finalize(TCollection *output, Long_t minEvents, TH1 *(*callback)(TObject *, Int_t))
void SetCentAxis(Int_t n, Double_t *edges)
TH1 * CentHist(Int_t bin) const
TH2 * Get2DDiag(TCollection *output, const char *name, Bool_t projX)
virtual const char * HistName(Double_t low, Double_t high) const
virtual const char * HistTitle(Double_t low, Double_t high) const
virtual const char * HistName(Int_t i) const
void SetCentAxis(Int_t n, Double_t low, Double_t high)
TObject * CentObject(Int_t bin, TClass *cls=0) const
FastCentHelper(const char *method)
Int_t GetCentralityColor(Double_t, Double_t high) const
void CreateHistos(TCollection *output, TObject *(*callback)())
void ModHist(TObject *o, Double_t low, Double_t high, Int_t lvl=0)
TCollection * CentCollection(Int_t bin) const
void Print(Option_t *option="") const
void CreateDiagnostics(TCollection *output, TH1 *centHist)
Int_t CheckCentrality(Double_t cent, Double_t mult, Double_t b, Double_t nPart, Double_t nBin)