15#include <TDirectory.h>
26template <
typename hist_t>
27void setHistStyle(hist_t* hist,
short color = 1) {
28 hist->GetXaxis()->SetTitleSize(0.04);
29 hist->GetYaxis()->SetTitleSize(0.04);
30 hist->GetXaxis()->SetLabelSize(0.04);
31 hist->GetYaxis()->SetLabelSize(0.04);
32 hist->GetXaxis()->SetTitleOffset(1.0);
33 hist->GetYaxis()->SetTitleOffset(1.0);
34 hist->GetXaxis()->SetNdivisions(505);
35 hist->SetMarkerStyle(20);
36 hist->SetMarkerSize(0.8);
37 hist->SetLineWidth(2);
39 hist->SetLineColor(color);
40 hist->SetMarkerColor(color);
50template <
typename eff_t>
51void setEffStyle(eff_t* eff,
short color = 1) {
52 eff->SetMarkerStyle(20);
53 eff->SetMarkerSize(0.8);
55 eff->SetLineColor(color);
56 eff->SetMarkerColor(color);
69template <
typename hist_t>
70void adaptColorPalette(hist_t* h,
float rmin,
float rmax,
float rgood,
71 float rwindow,
int n) {
73 float rel_good = (rgood - rmin) / (rmax - rmin);
74 float rel_window = rwindow / (rmax - rmin);
78 double red[number] = {0., 0., 0., 1., 1.};
79 double green[number] = {0., 1., 1., 1., 0.};
80 double blue[number] = {1., 1., 0., 0., 0.};
81 double stops[number] = {0., rel_good - rel_window, rel_good,
82 rel_good + rel_window, 1.};
85 TColor::CreateGradientColorTable(number, stops, red, green, blue, n);
97template <
typename eff_t>
98void adaptEffRange(eff_t* eff,
float minScale = 1,
float maxScale = 1.1) {
100 auto ymin = gPad->GetUymin();
101 auto ymax = gPad->GetUymax();
102 auto graph = eff->GetPaintedGraph();
103 graph->SetMinimum(ymin * minScale);
104 graph->SetMaximum(ymax * maxScale);
121 std::string residualUnit =
"";
128 std::string rangeMaxStr =
"";
129 std::string rangeCutStr =
"";
132 std::array<float, 2>
range = {0., 0.};
136 std::function<float(ULong64_t)>
value;
139 std::function<float(ULong64_t)>
error;
144 TH1F* rangeHist =
nullptr;
146 TH1F* residualHist =
nullptr;
148 TH1F* pullHist =
nullptr;
150 ULong64_t accepted = 0;
155 void fill(
unsigned int entry) {
158 float v =
value(entry);
159 residualHist->Fill(v);
160 pullHist->Fill(v /
error(entry));
176 std::string rangeDrawStr =
"";
182 std::array<float, 2>
range = {0., 0.};
186 std::function<float(ULong64_t)>
value;
191 TH1F* hist =
nullptr;
196 void fill(
unsigned int entry) {
199 float v =
value(entry);
209 std::function<bool(ULong64_t)> one;
211 std::function<bool(ULong64_t)> two;
215 bool operator()(ULong64_t entry) {
return (one(entry) && two(entry)); }
221 bool operator()(ULong64_t ) {
return true; }
227 std::vector<float>* value =
nullptr;
229 std::array<float, 2> range = {0., 0.};
234 if (value !=
nullptr) {
235 float v = value->at(entry);
236 return (range[0] <= v && range[1] > v);
246template <
typename primitive_t>
248 std::vector<primitive_t>* value =
nullptr;
255 primitive_t v = value->at(entry);
258 return std::numeric_limits<primitive_t>::max();
263template <
typename primitive_one_t,
typename primitive_two_t>
265 std::vector<primitive_one_t>* one =
nullptr;
267 std::vector<primitive_two_t>* two =
nullptr;
274 primitive_one_t vo = one->at(entry);
275 primitive_two_t vt = two->at(entry);
278 return std::numeric_limits<primitive_one_t>::max();
284 std::vector<float>* value =
nullptr;
286 std::vector<float>* reference =
nullptr;
292 if (value !=
nullptr && reference !=
nullptr) {
293 float v = value->at(entry);
294 float r = reference->at(entry);
297 return std::numeric_limits<float>::infinity();
303 std::vector<float>* qop_value =
nullptr;
305 std::vector<int>* reference_charge =
nullptr;
307 std::vector<float>* reference_p =
nullptr;
313 if (qop_value !=
nullptr && reference_charge !=
nullptr &&
314 reference_p !=
nullptr) {
315 float v = qop_value->at(entry);
316 float q_true = reference_charge->at(entry);
317 float p_true = reference_p->at(entry);
318 return (v - q_true / p_true);
320 return std::numeric_limits<float>::infinity();
326 std::vector<float>* qop_value =
nullptr;
328 std::vector<float>* theta_value =
nullptr;
330 std::vector<float>* reference_pt =
nullptr;
336 if (qop_value !=
nullptr && theta_value !=
nullptr &&
337 reference_pt !=
nullptr) {
338 float p = 1. / std::abs(qop_value->at(entry));
339 float theta = theta_value->at(entry);
340 float pt_true = reference_pt->at(entry);
341 return (p * sin(theta) - pt_true);
343 return std::numeric_limits<float>::infinity();
349 std::vector<float>* qop_value =
nullptr;
350 std::vector<float>* qop_error =
nullptr;
352 std::vector<float>* theta_value =
nullptr;
353 std::vector<float>* theta_error =
nullptr;
359 if (qop_value !=
nullptr && qop_error !=
nullptr &&
360 theta_value !=
nullptr && theta_error !=
nullptr) {
361 float qop_v = qop_value->at(entry);
362 float qop_e = qop_error->at(entry);
363 float theta_v = theta_value->at(entry);
364 float theta_e = theta_error->at(entry);
365 return std::cos(theta_v) / qop_v * theta_e -
366 std::sin(theta_v) / (qop_v * qop_v) * qop_e;
368 return std::numeric_limits<float>::infinity();
382template <
typename dir_t,
typename tree_t>
384 tree_t& tree,
unsigned long peakEntries,
385 unsigned int hBarcode) {
391 TString rangeHN =
"hrg_";
394 rangeHist += rangeHN;
395 rangeHist += handle.rangeMaxStr;
398 tree.Draw(rangeHist.Data(), handle.rangeCutStr.c_str(),
"", peakEntries);
399 handle.rangeHist =
dynamic_cast<TH1F*
>(gDirectory->Get(rangeHN.Data()));
400 if (handle.rangeHist !=
nullptr) {
401 float rms = handle.rangeHist->GetRMS();
402 handle.
range = {-rms, rms};
416template <
typename dir_t,
typename tree_t>
417void estimateIntegerRange(
SingleHandle& handle, dir_t& directory, tree_t& tree,
418 unsigned long peakEntries,
unsigned int startBins,
419 unsigned int addBins,
unsigned int hBarcode) {
422 TString rangeHist = handle.rangeDrawStr;
425 TString rangeHN =
"hrg_";
428 rangeHist += rangeHN;
430 rangeHist += startBins;
431 rangeHist +=
",-0.5,";
432 rangeHist +=
static_cast<float>(startBins - 0.5);
435 unsigned int nBins = startBins;
437 tree.Draw(rangeHist.Data(),
"",
"", peakEntries);
438 auto rhist =
dynamic_cast<TH1F*
>(gDirectory->Get(rangeHN.Data()));
439 if (rhist !=
nullptr) {
440 for (
unsigned int ib = 1; ib <= startBins; ++ib) {
441 if (rhist->GetBinContent(ib) > 0.) {
445 handle.
bins = (nBins + addBins);
446 handle.
range = {-0.5,
static_cast<float>(handle.
bins - 0.5)};
449 handle.
bins = (startBins);
450 handle.
range = {-0.5,
static_cast<float>(handle.
bins - 0.5)};
460 unsigned int hBins,
unsigned int hBarcode) {
462 TString rName = std::string(
"res_") + handle.
tag;
464 handle.residualHist =
465 new TH1F(rName.Data(), handle.
tag.c_str(), hBins,
466 pullRange * handle.
range[0], pullRange * handle.
range[1]);
467 std::string xAxisTitle =
468 handle.
residualStr + std::string(
" ") + handle.residualUnit;
469 handle.residualHist->GetXaxis()->SetTitle(xAxisTitle.c_str());
470 handle.residualHist->GetYaxis()->SetTitle(
"Entries");
473 TString pName = std::string(
"pull_") + handle.
tag;
476 new TH1F(pName.Data(), (std::string(
"pull ") + handle.
tag).c_str(), hBins,
477 -pullRange, pullRange);
478 xAxisTitle = std::string(
"(") + handle.
residualStr + std::string(
")/") +
480 handle.pullHist->GetXaxis()->SetTitle(xAxisTitle.c_str());
481 handle.pullHist->GetYaxis()->SetTitle(
"Entries");
492template <
typename tree_t>
493unsigned long estimateEntries(
const tree_t& tree,
494 unsigned long configuredEntries) {
495 unsigned long entries =
static_cast<unsigned long>(tree.GetEntries());
496 if (configuredEntries > 0 && configuredEntries < entries) {
497 entries = configuredEntries;
This Struct is to accept all values - a placeholder.
This is a combined accept struct.
bool operator()(ULong64_t entry)
returns true if value is within range
This Struct is to accept a certain range from a TTree accessible value.
bool operator()(ULong64_t entry)
returns true if value is within range
This is a direct type accessor.
primitive_t operator()(ULong64_t entry)
Gives direct access to the underlying parameter.
primitive_one_t operator()(ULong64_t entry)
Gives direct access to the underlying parameter.
float operator()(ULong64_t entry)
This the dedicted pT residual accessor.
float operator()(ULong64_t entry)
float operator()(ULong64_t entry)
float operator()(ULong64_t entry)
A Parameter handle struct to deal with residuals and pulls.
std::function< bool(ULong64_t)> accept
The acceptance.
std::string residualStr
Title and names: residual.
std::function< float(ULong64_t)> error
The associated error accessor.
std::string rangeDrawStr
The rangeDrawStr draw string.
std::array< float, 2 > range
The range array.
std::string errorStr
Title and names: error.
std::function< float(ULong64_t)> value
Value function that allows to create combined parameters.
std::string tag
A tag name.
void fill(unsigned int entry)
Fill the entry.
std::function< float(ULong64_t)> value
Value function that allows to create combined parameters.
std::string label
A label name.
std::array< float, 2 > range
The range array.
std::string tag
A tag name.
void fill(unsigned int entry)
Fill the entry.
std::function< bool(ULong64_t)> accept
The acceptance.
unsigned int bins
The number of bins for the booking.