ATLAS Offline Software
Loading...
Searching...
No Matches
TFCS1DFunctionSpline.cxx File Reference
#include "ISF_FastCaloSimEvent/TFCS1DFunctionSpline.h"
#include "ISF_FastCaloSimEvent/TFCS1DFunctionInt32Histogram.h"
#include <algorithm>
#include <iostream>
#include "TMath.h"
#include "TCanvas.h"
#include "TH2F.h"
#include "TRandom.h"
#include "TFile.h"
Include dependency graph for TFCS1DFunctionSpline.cxx:

Go to the source code of this file.

Functions

void TFCS1DFunctionSpline::unit_test ATLAS_NOT_THREAD_SAFE (TH1 *hist)

Function Documentation

◆ ATLAS_NOT_THREAD_SAFE()

void TFCS1DFunctionSpline::unit_test ATLAS_NOT_THREAD_SAFE ( TH1 * hist)

Definition at line 378 of file TFCS1DFunctionSpline.cxx.

378 {
380 int nbinsx;
381 TH1 *histfine = nullptr;
382 if (hist == nullptr) {
383 nbinsx = 50;
384 double xmin = 1;
385 double xpeak = 1.5;
386 double sigma = 0.6;
387 double xmax = 5;
388 hist = new TH1D("test1D", "test1D", nbinsx, xmin, xmax);
389 histfine = new TH1D("test1Dfine", "test1Dfine", 10 * nbinsx, xmin, xmax);
390 hist->Sumw2();
391 for (int i = 1; i <= 100000; ++i) {
392 double x = gRandom->Gaus(xpeak, sigma);
393 if (x >= xmin && x < xmax) {
394 // hist->Fill(TMath::Sqrt(x));
395 hist->Fill(x);
396 if (histfine)
397 histfine->Fill(x, 10);
398 }
399 }
400 }
401 if (!histfine)
402 histfine = hist;
403 TFCS1DFunctionSpline rtof(histfine, 0.01, 2, 15);
404 nbinsx = hist->GetNbinsX();
405
406 float value[2];
407 float rnd[2];
408 //cppcheck-suppress uninitvar
409 for (rnd[0] = 0; rnd[0] < 0.9999; rnd[0] += 0.25) {
410 rtof.rnd_to_fct(value, rnd);
411 ATH_MSG_NOCLASS(logger, "rnd0=" << rnd[0] << " -> x=" << value[0]);
412 }
413
414 TH1 *hist_val = (TH1 *)histfine->Clone("hist_val");
415 hist_val->SetTitle("toy simulation");
416 hist_val->Reset();
417 hist_val->SetLineColor(2);
418 TH1 *hist_diff = (TH1 *)hist->Clone("hist_diff");
419 hist_diff->SetTitle("difference");
420 hist_diff->Reset();
421 int nrnd = 5000000;
422 double weight = histfine->Integral() / nrnd;
423 double weightdiff = hist->Integral() / nrnd;
424 hist_val->Sumw2();
425 hist_diff->Sumw2();
426 for (int i = 0; i < nrnd; ++i) {
427 rnd[0] = gRandom->Rndm();
428 rtof.rnd_to_fct(value, rnd);
429 hist_val->Fill(value[0], weight);
430 hist_diff->Fill(value[0], weightdiff);
431 }
432 hist_diff->Add(hist, -1);
433
434 TH1F *hist_pull = new TH1F("pull", "pull", 200, -10, 10);
435 for (int ix = 1; ix <= nbinsx; ++ix) {
436 float val = hist_diff->GetBinContent(ix);
437 float err = hist_diff->GetBinError(ix);
438 if (err > 0)
439 hist_pull->Fill(val / err);
440 // ATH_MSG_NOCLASS(logger,"val="<<val<<" err="<<err);
441 }
442
443// Screen output in athena won't make sense and would require linking of
444// additional libraries
445#if defined(__FastCaloSimStandAlone__)
446 new TCanvas("input", "Input");
447 histfine->SetLineColor(kGray);
448 histfine->Draw("hist");
449 hist->Draw("same");
450 hist_val->Draw("sameshist");
451
452 new TCanvas("spline", "spline");
453 TFCS1DFunctionInt32Histogram hist_fct(hist);
454 int ngr = 101;
455 TGraph *gr = new TGraph();
456 for (int i = 0; i < ngr; ++i) {
457 double r = i * 1.0 / (ngr - 1);
458 gr->SetPoint(i, r, hist_fct.rnd_to_fct(r));
459 }
460 gr->SetMarkerStyle(7);
461 gr->Draw("AP");
462 TSpline3 *sp = new TSpline3(rtof.spline());
463 sp->SetLineColor(2);
464 sp->SetMarkerColor(2);
465 sp->SetMarkerStyle(2);
466 sp->Draw("LPsame");
467
468 new TCanvas("difference", "difference");
469 hist_diff->Draw();
470
471 new TCanvas("pull", "Pull");
472 hist_pull->Draw();
473#endif
474}
#define gr
static Double_t sp
static TRandom * rnd
#define ATH_MSG_NOCLASS(logger_name, x)
Definition MLogging.h:52
#define x
Cut down AthMessaging.
Definition MLogging.h:176
int r
Definition globals.cxx:22
static Root::TMsgLogger logger("iLumiCalc")
double xmax
Definition listroot.cxx:61
double xmin
Definition listroot.cxx:60
TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)