diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d07b985..9be8dfc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,152 +1,152 @@ stages: - build - test variables: LCG_VERSION: "101" BUILD_TYPE: "Release" BUILD_ROOFIT_TASK: "OFF" BUILD_DOCS: "OFF" .production_image: variables: LCG_OS: x86_64-centos7 image: gitlab-registry.cern.ch/ci-tools/ci-worker:cc7 tags: - cvmfs .lcg_setup: before_script: - set +e && source /cvmfs/sft.cern.ch/lcg/views/setupViews.sh LCG_$LCG_VERSION $LCG_OS-$LCG_COMPILER; set -e .build_template: stage: build extends: - .lcg_setup script: - mkdir install - mkdir build && cd build - - cmake -DCMAKE_BUILD_TYPE:STRING=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX:PATH=$CI_PROJECT_DIR/install -DLAURA_BUILD_EXAMPLES:BOOL=ON -DLAURA_BUILD_DOCS:BOOL=$BUILD_DOCS -DLAURA_BUILD_ROOFIT_TASK:BOOL=$BUILD_ROOFIT_TASK $CI_PROJECT_DIR + - cmake -DCMAKE_BUILD_TYPE:STRING=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX:PATH=$CI_PROJECT_DIR/install -DLAURA_BUILD_EXAMPLES:BOOL=ON -DLAURA_BUILD_TEST:BOOL=ON -DLAURA_BUILD_DOCS:BOOL=$BUILD_DOCS -DLAURA_BUILD_ROOFIT_TASK:BOOL=$BUILD_ROOFIT_TASK $CI_PROJECT_DIR - cmake --build . - cmake --build . --target install build_clang12_opt: variables: LCG_COMPILER: "clang12-opt" extends: - .production_image - .build_template build_gcc11_opt: variables: LCG_COMPILER: "gcc11-opt" extends: - .production_image - .build_template build_gcc11_dbg: variables: LCG_COMPILER: "gcc11-dbg" BUILD_TYPE: "Debug" BUILD_ROOFIT_TASK: "ON" BUILD_DOCS: "ON" extends: - .production_image - .build_template artifacts: paths: - install expire_in: 1 day .test_template: stage: test variables: LCG_COMPILER: "gcc11-dbg" extends: - .production_image - .lcg_setup dependencies: - build_gcc11_dbg artifacts: paths: - runtests expire_in: 1 day script: - export PATH=$CI_PROJECT_DIR/install/bin:$PATH - mkdir runtests && cd runtests - curl -o ft-eta-hist.root https://laura.hepforge.org/CI-files/ft-eta-hist-realistic.root - curl -O https://laura.hepforge.org/CI-files/dta-hist.root - curl -O https://laura.hepforge.org/CI-files/dte-hist.root - $CI_PROJECT_DIR/examples/runTimeDepTest.sh 0 $DTA_MODEL $DTR $DTR_PEREVENT test_flatDTA_noDTR: variables: DTA_MODEL: "flat" DTR: "0" DTR_PEREVENT: "0" extends: - .test_template test_flatDTA_avgDTR: variables: DTA_MODEL: "flat" DTR: "1" DTR_PEREVENT: "0" extends: - .test_template test_flatDTA_evtDTR: variables: DTA_MODEL: "flat" DTR: "1" DTR_PEREVENT: "1" extends: - .test_template test_histDTA_noDTR: variables: DTA_MODEL: "hist" DTR: "0" DTR_PEREVENT: "0" extends: - .test_template test_histDTA_avgDTR: variables: DTA_MODEL: "hist" DTR: "1" DTR_PEREVENT: "0" extends: - .test_template test_histDTA_evtDTR: variables: DTA_MODEL: "hist" DTR: "1" DTR_PEREVENT: "1" extends: - .test_template test_splineDTA_noDTR: variables: DTA_MODEL: "spline" DTR: "0" DTR_PEREVENT: "0" extends: - .test_template test_splineDTA_avgDTR: variables: DTA_MODEL: "spline" DTR: "1" DTR_PEREVENT: "0" extends: - .test_template test_splineDTA_evtDTR: variables: DTA_MODEL: "spline" DTR: "1" DTR_PEREVENT: "1" extends: - .test_template diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5b94d33..dcfa23b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,14 +1,15 @@ list(APPEND TEST_SOURCES TestCovariant TestCovariant2 TestNewKinematicsMethods TestFitSplineToTH1 + TestFitDoubleSplineToTH1 ) foreach( _test ${TEST_SOURCES}) add_executable(${_test} ${_test}.cc) target_link_libraries(${_test} PRIVATE Laura++) #install(TARGETS ${_test} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endforeach() diff --git a/test/TestFitDoubleSplineToTH1.cc b/test/TestFitDoubleSplineToTH1.cc new file mode 100644 index 0000000..15d1438 --- /dev/null +++ b/test/TestFitDoubleSplineToTH1.cc @@ -0,0 +1,53 @@ +#include + +#include "TFile.h" +#include "TH1.h" +#include "TF1.h" +#include "TCanvas.h" + +#include "Lau1DCubicSpline.hh" + +//int main(const int argc, const char ** argv) +int main() +{ + TFile* dtaFile = TFile::Open("dta-hist-hp.root"); + TH1* dtaHist = dynamic_cast(dtaFile->Get("dta_hist")); + + //std::vector dtvals = {0. ,0.25,0.5 ,0.75 ,1., 2., 3., 4., 7., 10., 15.}; + //std::vector effvals = {1e-11,0.01,0.015,0.2 ,0.022,0.035,0.042,0.05,0.051,0.052,0.055}; + std::vector dtvals = {0. ,0.5 ,1., 3., 4., 7., 10., 15.}; + std::vector effvals = {1e-11,0.015,0.022,0.042,0.05,0.051,0.052,0.055}; + Lau1DCubicSpline* dtEffSpline = nullptr; + dtEffSpline = new Lau1DCubicSpline(dtvals,effvals,Lau1DCubicSpline::SplineType::AkimaSpline); + + dtEffSpline->fitToTH1(dtaHist); + TF1* tf1 = dtEffSpline->makeTF1(); + tf1->SetName("AkimaSpline"); + + TCanvas canvas("canvas","canvas",800,450); + dtaHist->Draw(); + tf1->SetTitle("Akima Spline"); + + tf1->Draw("SAME"); + + Lau1DCubicSpline* dtEffSpline2 = nullptr; + dtEffSpline2 = new Lau1DCubicSpline(dtvals,effvals,Lau1DCubicSpline::SplineType::StandardSpline,Lau1DCubicSpline::BoundaryType::Natural,Lau1DCubicSpline::BoundaryType::Natural); + + dtEffSpline2->fitToTH1(dtaHist); + TF1* tf2 = dtEffSpline2->makeTF1(); + tf2->SetLineColor(1); + tf2->SetTitle("Standard Spline"); + + tf2->Draw("SAME"); + + canvas.BuildLegend(); + + canvas.SaveAs("TF1fitTest.pdf"); + + delete dtEffSpline; + delete dtaHist; + + dtaFile->Close(); + delete dtaFile; + return 0; +} diff --git a/test/TestFitSplineToTH1.cc b/test/TestFitSplineToTH1.cc index 77d11f7..a0b897e 100644 --- a/test/TestFitSplineToTH1.cc +++ b/test/TestFitSplineToTH1.cc @@ -1,106 +1,106 @@ #include #include #include "TFile.h" #include "TH1.h" #include "TH1D.h" #include "TF1.h" #include "TCanvas.h" #include "TPad.h" #include "TStyle.h" #include "TBox.h" #include "TLine.h" #include "Lau1DCubicSpline.hh" //int main(const int argc, const char ** argv) int main() { TFile* dtaFile = TFile::Open("DTA-hist-PV.root"); TH1* dtaHist = dynamic_cast(dtaFile->Get("dta_hist")); gStyle->SetOptStat(0); std::vector dtvals = {0. ,0.25,0.5 ,0.75 ,1., 2., 3., 4., 7., 10., 15.}; std::vector effvals = {1e-11,0.01,0.015,0.2 ,0.022,0.035,0.042,0.05,0.051,0.052,0.055}; Lau1DCubicSpline* dtEffSpline = nullptr; - dtEffSpline = new Lau1DCubicSpline(dtvals,effvals,Lau1DCubicSpline::AkimaSpline,Lau1DCubicSpline::Natural,Lau1DCubicSpline::Natural); + dtEffSpline = new Lau1DCubicSpline(dtvals,effvals,Lau1DCubicSpline::SplineType::AkimaSpline); dtEffSpline->fitToTH1(dtaHist); TF1* tf1 = dtEffSpline->makeTF1(); TCanvas canvas("canvas","canvas",800,450); TPad* fitPad = new TPad("fitPad","fit",0,0.3,1,1.0); fitPad->SetFillColor(0); TPad* ratioPad = new TPad("ratioPad","fit",0,0.05,1,0.3); ratioPad->SetFillColor(0); fitPad->Draw(); ratioPad->Draw(); fitPad->cd(); dtaHist->Draw(); tf1->Draw("SAME"); TH1D* ratios = new TH1D(*dynamic_cast(dtaHist)); ratios->SetName("ratios"); ratios->SetTitle("Ratios of spline/MC;t(ps)"); std::vector infIndicies; for(Int_t i = 1; i <= ratios->GetNbinsX(); ++i) { Double_t t = ratios->GetBinCenter(i); Double_t splineValue = dtEffSpline->evaluate(t); Double_t dtaHistVal = dtaHist->GetBinContent(i); Double_t ratio = splineValue/dtaHistVal; if (std::isinf(ratio)) { ratio = 0.; infIndicies.push_back(i); } ratios->SetBinContent( i, ratio ); std::cout << "ratio: " << splineValue/dtaHistVal << std::endl; ratios->SetBinError( i, 0. ); //TODO work out the error } ratioPad->cd(); ratios->Draw("P*"); const Double_t yMin = ratios->GetMinimum(0.001)*0.99; const Double_t yMax = ratios->GetMaximum(1000.)*1.01; std::cout << yMin << " " << yMax << std::endl; ratios->GetYaxis()->SetRangeUser(yMin,yMax); for(Int_t i : infIndicies) { TBox* b = new TBox( ratios->GetBinLowEdge(i), yMin, ratios->GetBinWidth(i)+ratios->GetBinLowEdge(i), yMax ); b->SetFillColorAlpha(2,0.3); b->Draw(); } TLine* zeroLine = new TLine(ratios->GetXaxis()->GetXmin(), 1, ratios->GetXaxis()->GetXmax(), 1); zeroLine->SetLineColor(kGray+1); zeroLine->Draw(); canvas.SaveAs("TF1fitTest.pdf"); delete dtEffSpline; delete dtaHist; delete ratios; delete zeroLine; dtaFile->Close(); delete dtaFile; return 0; }