From 59e49925f22149e20951f400ea92d3834453b431 Mon Sep 17 00:00:00 2001 From: rpreghen Date: Wed, 13 Nov 2013 15:43:34 +0000 Subject: [PATCH] adding code for TOF pPb502 spectra analysis --- .../TOF/pPb502/lib/AliAnalysisEvent.cxx | 1 + .../PiKaPr/TOF/pPb502/lib/AliAnalysisEvent.h | 1 + .../TOF/pPb502/lib/AliAnalysisParticle.cxx | 1 + .../TOF/pPb502/lib/AliAnalysisParticle.h | 1 + .../TOF/pPb502/lib/AliAnalysisTrack.cxx | 1 + .../PiKaPr/TOF/pPb502/lib/AliAnalysisTrack.h | 1 + .../PiKaPr/TOF/pPb502/lib/MakeRooShapes.C | 7 + .../PiKaPr/TOF/pPb502/lib/RooFermiCutoff.cxx | 47 + .../PiKaPr/TOF/pPb502/lib/RooFermiCutoff.h | 40 + .../PiKaPr/TOF/pPb502/lib/RooGaussianTail.cxx | 54 + .../PiKaPr/TOF/pPb502/lib/RooGaussianTail.h | 42 + .../TOF/pPb502/lib/RooInverseGaussianTail.cxx | 54 + .../TOF/pPb502/lib/RooInverseGaussianTail.h | 42 + .../PiKaPr/TOF/pPb502/macros/CommonDefs.C | 247 ++ PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCA.C | 1392 +++++++++ PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCA.sh | 9 + .../PiKaPr/TOF/pPb502/macros/DCAAnalysis.sh | 10 + .../PiKaPr/TOF/pPb502/macros/DCAdata_std.C | 11 + .../PiKaPr/TOF/pPb502/macros/DCAdata_std.sh | 9 + .../PiKaPr/TOF/pPb502/macros/DCAmc_std.C | 11 + .../PiKaPr/TOF/pPb502/macros/DCAmc_std.sh | 9 + .../TOF/pPb502/macros/EfficiencyAnalysis.sh | 12 + .../PiKaPr/TOF/pPb502/macros/FinalSpectra.C | 318 ++ .../PiKaPr/TOF/pPb502/macros/FitPeak.C | 67 + .../PiKaPr/TOF/pPb502/macros/FullAnalysis.sh | 8 + .../PiKaPr/TOF/pPb502/macros/HistoUtils.C | 358 +++ .../PiKaPr/TOF/pPb502/macros/MakeLibs.C | 14 + .../PiKaPr/TOF/pPb502/macros/MultCent.C | 124 + .../PiKaPr/TOF/pPb502/macros/PIDAnalysis.sh | 9 + .../PiKaPr/TOF/pPb502/macros/SpectraUtils.C | 809 +++++ .../macros/T0FillOnline.139465.extended.root | Bin 0 -> 15852 bytes .../PiKaPr/TOF/pPb502/macros/TOFmatchEff.C | 1417 +++++++++ .../PiKaPr/TOF/pPb502/macros/TOFmatchEff.sh | 9 + .../PiKaPr/TOF/pPb502/macros/TOFmatchMC.C | 1470 +++++++++ .../PiKaPr/TOF/pPb502/macros/TOFmatchMC.sh | 9 + .../SPECTRA/PiKaPr/TOF/pPb502/macros/TOFpid.C | 2733 +++++++++++++++++ .../PiKaPr/TOF/pPb502/macros/TOFpid.sh | 39 + .../PiKaPr/TOF/pPb502/macros/TOFsignal.C | 60 + .../PiKaPr/TOF/pPb502/macros/TPCcalib.C | 646 ++++ .../PiKaPr/TOF/pPb502/macros/TPCcalib.sh | 9 + .../PiKaPr/TOF/pPb502/macros/TZEROcalib.C | 420 +++ .../PiKaPr/TOF/pPb502/macros/TrackingEff.C | 1077 +++++++ .../PiKaPr/TOF/pPb502/macros/TrackingEff.sh | 9 + .../PiKaPr/TOF/pPb502/macros/defaultFit.C | 7 + .../PiKaPr/TOF/pPb502/macros/defaultFit.sh | 26 + .../PiKaPr/TOF/pPb502/macros/mcSpectra.C | 41 + .../SPECTRA/PiKaPr/TOF/pPb502/macros/merger.C | 30 + .../task/AddAnalysisTaskTOFSpectraPbPb.C | 86 + .../TOF/pPb502/task/AliAnalysisEvent.cxx | 508 +++ .../PiKaPr/TOF/pPb502/task/AliAnalysisEvent.h | 137 + .../TOF/pPb502/task/AliAnalysisParticle.cxx | 160 + .../TOF/pPb502/task/AliAnalysisParticle.h | 48 + .../task/AliAnalysisTaskTOFSpectraPbPb.cxx | 350 +++ .../task/AliAnalysisTaskTOFSpectraPbPb.h | 118 + .../TOF/pPb502/task/AliAnalysisTrack.cxx | 975 ++++++ .../PiKaPr/TOF/pPb502/task/AliAnalysisTrack.h | 220 ++ PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/Makefile | 13 + .../task/SteerAnalysisTaskTOFSpectraPbPb.C | 125 + 58 files changed, 14451 insertions(+) create mode 120000 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisEvent.cxx create mode 120000 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisEvent.h create mode 120000 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisParticle.cxx create mode 120000 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisParticle.h create mode 120000 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisTrack.cxx create mode 120000 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisTrack.h create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/MakeRooShapes.C create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooFermiCutoff.cxx create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooFermiCutoff.h create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooGaussianTail.cxx create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooGaussianTail.h create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooInverseGaussianTail.cxx create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooInverseGaussianTail.h create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/CommonDefs.C create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCA.C create mode 100755 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCA.sh create mode 100755 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCAAnalysis.sh create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCAdata_std.C create mode 100755 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCAdata_std.sh create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCAmc_std.C create mode 100755 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCAmc_std.sh create mode 100755 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/EfficiencyAnalysis.sh create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/FinalSpectra.C create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/FitPeak.C create mode 100755 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/FullAnalysis.sh create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/HistoUtils.C create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/MakeLibs.C create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/MultCent.C create mode 100755 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/PIDAnalysis.sh create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/SpectraUtils.C create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/T0FillOnline.139465.extended.root create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFmatchEff.C create mode 100755 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFmatchEff.sh create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFmatchMC.C create mode 100755 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFmatchMC.sh create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFpid.C create mode 100755 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFpid.sh create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFsignal.C create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TPCcalib.C create mode 100755 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TPCcalib.sh create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TZEROcalib.C create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TrackingEff.C create mode 100755 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TrackingEff.sh create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/defaultFit.C create mode 100755 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/defaultFit.sh create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/mcSpectra.C create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/merger.C create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AddAnalysisTaskTOFSpectraPbPb.C create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisEvent.cxx create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisEvent.h create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisParticle.cxx create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisParticle.h create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisTaskTOFSpectraPbPb.cxx create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisTaskTOFSpectraPbPb.h create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisTrack.cxx create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisTrack.h create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/Makefile create mode 100644 PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/SteerAnalysisTaskTOFSpectraPbPb.C diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisEvent.cxx b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisEvent.cxx new file mode 120000 index 00000000000..416d46ba5bc --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisEvent.cxx @@ -0,0 +1 @@ +../task/AliAnalysisEvent.cxx \ No newline at end of file diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisEvent.h b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisEvent.h new file mode 120000 index 00000000000..b07a68795ec --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisEvent.h @@ -0,0 +1 @@ +../task/AliAnalysisEvent.h \ No newline at end of file diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisParticle.cxx b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisParticle.cxx new file mode 120000 index 00000000000..0056cf0949b --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisParticle.cxx @@ -0,0 +1 @@ +../task/AliAnalysisParticle.cxx \ No newline at end of file diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisParticle.h b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisParticle.h new file mode 120000 index 00000000000..547264912f7 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisParticle.h @@ -0,0 +1 @@ +../task/AliAnalysisParticle.h \ No newline at end of file diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisTrack.cxx b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisTrack.cxx new file mode 120000 index 00000000000..1a32d19d388 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisTrack.cxx @@ -0,0 +1 @@ +../task/AliAnalysisTrack.cxx \ No newline at end of file diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisTrack.h b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisTrack.h new file mode 120000 index 00000000000..e9a45608567 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/AliAnalysisTrack.h @@ -0,0 +1 @@ +../task/AliAnalysisTrack.h \ No newline at end of file diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/MakeRooShapes.C b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/MakeRooShapes.C new file mode 100644 index 00000000000..a9ed683243a --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/MakeRooShapes.C @@ -0,0 +1,7 @@ +{ + gSystem->Load("libRooFit"); + using namespace RooFit; + gROOT->ProcessLine(".L RooFermiCutoff.cxx++"); + gROOT->ProcessLine(".L RooGaussianTail.cxx++"); + gROOT->ProcessLine(".L RooInverseGaussianTail.cxx++"); +} diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooFermiCutoff.cxx b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooFermiCutoff.cxx new file mode 100644 index 00000000000..c3d08d78293 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooFermiCutoff.cxx @@ -0,0 +1,47 @@ +/***************************************************************************** + * Project: RooFit * + * * + * This code was autogenerated by RooClassFactory * + *****************************************************************************/ + +// Your description goes here... + +#include "Riostream.h" + +#include "RooFermiCutoff.h" +#include "RooAbsReal.h" +#include "RooAbsCategory.h" +#include +#include "TMath.h" + +ClassImp(RooFermiCutoff) + + RooFermiCutoff::RooFermiCutoff(const char *name, const char *title, + RooAbsReal& _x, + RooAbsReal& _cutoff, + RooAbsReal& _power) : + RooAbsPdf(name,title), + x("x","x",this,_x), + cutoff("cutoff","cutoff",this,_cutoff), + power("power","power",this,_power) + { + } + + + RooFermiCutoff::RooFermiCutoff(const RooFermiCutoff& other, const char* name) : + RooAbsPdf(other,name), + x("x",this,other.x), + cutoff("cutoff",this,other.cutoff), + power("power",this,other.power) + { + } + + + + Double_t RooFermiCutoff::evaluate() const + { + return (1. / (TMath::Exp((cutoff - x) / power) + 1.)); + } + + + diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooFermiCutoff.h b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooFermiCutoff.h new file mode 100644 index 00000000000..0efa7477c42 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooFermiCutoff.h @@ -0,0 +1,40 @@ +/***************************************************************************** + * Project: RooFit * + * * + * This code was autogenerated by RooClassFactory * + *****************************************************************************/ + +#ifndef ROOFERMICUTOFF +#define ROOFERMICUTOFF + +#include "RooAbsPdf.h" +#include "RooRealProxy.h" +#include "RooCategoryProxy.h" +#include "RooAbsReal.h" +#include "RooAbsCategory.h" + +class RooFermiCutoff : public RooAbsPdf { +public: + RooFermiCutoff() {} ; + RooFermiCutoff(const char *name, const char *title, + RooAbsReal& _x, + RooAbsReal& _cutoff, + RooAbsReal& _power); + RooFermiCutoff(const RooFermiCutoff& other, const char* name=0) ; + virtual TObject* clone(const char* newname) const { return new RooFermiCutoff(*this,newname); } + inline virtual ~RooFermiCutoff() { } + +protected: + + RooRealProxy x ; + RooRealProxy cutoff ; + RooRealProxy power ; + + Double_t evaluate() const ; + +private: + + ClassDef(RooFermiCutoff,1) // Your description goes here... +}; + +#endif diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooGaussianTail.cxx b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooGaussianTail.cxx new file mode 100644 index 00000000000..cd6f7ae07ed --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooGaussianTail.cxx @@ -0,0 +1,54 @@ +/***************************************************************************** + * Project: RooFit * + * * + * This code was autogenerated by RooClassFactory * + *****************************************************************************/ + +// Your description goes here... + +#include "Riostream.h" + +#include "RooGaussianTail.h" +#include "RooAbsReal.h" +#include "RooAbsCategory.h" +#include +#include "TMath.h" + +ClassImp(RooGaussianTail) + + RooGaussianTail::RooGaussianTail(const char *name, const char *title, + RooAbsReal& _x, + RooAbsReal& _mean, + RooAbsReal& _sigma, + RooAbsReal& _tail) : + RooAbsPdf(name,title), + x("x","x",this,_x), + mean("mean","mean",this,_mean), + sigma("sigma","sigma",this,_sigma), + tail("tail","tail",this,_tail) + { + } + + + RooGaussianTail::RooGaussianTail(const RooGaussianTail& other, const char* name) : + RooAbsPdf(other,name), + x("x",this,other.x), + mean("mean",this,other.mean), + sigma("sigma",this,other.sigma), + tail("tail",this,other.tail) + { + } + + + + Double_t RooGaussianTail::evaluate() const + { + Double_t tail2 = tail * sigma; + if (x <= (tail2 + mean)) + return TMath::Gaus(x, mean, sigma); + else + return TMath::Gaus(tail2 + mean, mean, sigma) * TMath::Exp(-tail2 * (x - tail2 - mean) / (sigma * sigma)); + } + + + diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooGaussianTail.h b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooGaussianTail.h new file mode 100644 index 00000000000..eb340879ca3 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooGaussianTail.h @@ -0,0 +1,42 @@ +/***************************************************************************** + * Project: RooFit * + * * + * This code was autogenerated by RooClassFactory * + *****************************************************************************/ + +#ifndef ROOGAUSSIANTAIL +#define ROOGAUSSIANTAIL + +#include "RooAbsPdf.h" +#include "RooRealProxy.h" +#include "RooCategoryProxy.h" +#include "RooAbsReal.h" +#include "RooAbsCategory.h" + +class RooGaussianTail : public RooAbsPdf { +public: + RooGaussianTail() {} ; + RooGaussianTail(const char *name, const char *title, + RooAbsReal& _x, + RooAbsReal& _mean, + RooAbsReal& _sigma, + RooAbsReal& _tail); + RooGaussianTail(const RooGaussianTail& other, const char* name=0) ; + virtual TObject* clone(const char* newname) const { return new RooGaussianTail(*this,newname); } + inline virtual ~RooGaussianTail() { } + +protected: + + RooRealProxy x ; + RooRealProxy mean ; + RooRealProxy sigma ; + RooRealProxy tail ; + + Double_t evaluate() const; + +private: + + ClassDef(RooGaussianTail,1) // Your description goes here... +}; + +#endif diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooInverseGaussianTail.cxx b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooInverseGaussianTail.cxx new file mode 100644 index 00000000000..ff5dbb2623a --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooInverseGaussianTail.cxx @@ -0,0 +1,54 @@ +/***************************************************************************** + * Project: RooFit * + * * + * This code was autogenerated by RooClassFactory * + *****************************************************************************/ + +// Your description goes here... + +#include "Riostream.h" + +#include "RooInverseGaussianTail.h" +#include "RooAbsReal.h" +#include "RooAbsCategory.h" +#include +#include "TMath.h" + +ClassImp(RooInverseGaussianTail) + + RooInverseGaussianTail::RooInverseGaussianTail(const char *name, const char *title, + RooAbsReal& _x, + RooAbsReal& _mean, + RooAbsReal& _sigma, + RooAbsReal& _tail) : + RooAbsPdf(name,title), + x("x","x",this,_x), + mean("mean","mean",this,_mean), + sigma("sigma","sigma",this,_sigma), + tail("tail","tail",this,_tail) + { + } + + + RooInverseGaussianTail::RooInverseGaussianTail(const RooInverseGaussianTail& other, const char* name) : + RooAbsPdf(other,name), + x("x",this,other.x), + mean("mean",this,other.mean), + sigma("sigma",this,other.sigma), + tail("tail",this,other.tail) + { + } + + + + Double_t RooInverseGaussianTail::evaluate() const + { + Double_t tail2 = tail * sigma; + if (x >= (mean - tail2)) + return TMath::Gaus(x, mean, sigma); + else + return TMath::Gaus(mean - tail2, mean, sigma) * TMath::Exp(tail2 * (x + tail2 - mean) / (sigma * sigma)); + } + + + diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooInverseGaussianTail.h b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooInverseGaussianTail.h new file mode 100644 index 00000000000..886a5539229 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/lib/RooInverseGaussianTail.h @@ -0,0 +1,42 @@ +/***************************************************************************** + * Project: RooFit * + * * + * This code was autogenerated by RooClassFactory * + *****************************************************************************/ + +#ifndef ROOINVERSEGAUSSIANTAIL +#define ROOINVERSEGAUSSIANTAIL + +#include "RooAbsPdf.h" +#include "RooRealProxy.h" +#include "RooCategoryProxy.h" +#include "RooAbsReal.h" +#include "RooAbsCategory.h" + +class RooInverseGaussianTail : public RooAbsPdf { +public: + RooInverseGaussianTail() {} ; + RooInverseGaussianTail(const char *name, const char *title, + RooAbsReal& _x, + RooAbsReal& _mean, + RooAbsReal& _sigma, + RooAbsReal& _tail); + RooInverseGaussianTail(const RooInverseGaussianTail& other, const char* name=0) ; + virtual TObject* clone(const char* newname) const { return new RooInverseGaussianTail(*this,newname); } + inline virtual ~RooInverseGaussianTail() { } + +protected: + + RooRealProxy x ; + RooRealProxy mean ; + RooRealProxy sigma ; + RooRealProxy tail ; + + Double_t evaluate() const; + +private: + + ClassDef(RooInverseGaussianTail,1) // Your description goes here... +}; + +#endif diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/CommonDefs.C b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/CommonDefs.C new file mode 100644 index 00000000000..686bcd188d2 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/CommonDefs.C @@ -0,0 +1,247 @@ + +#ifndef COMMONDEFS +#define COMMONDEFS + +#define PROTONLEAD 1 +#define LEADLEAD 0 +#define PROTONPROTON 0 + +/* analysis dependent stuff */ + +/***** p-Pb *****/ +#if PROTONLEAD + +Double_t tofReso = 80.; +Double_t tofTail = 75.; + +Double_t scaletexpreso[5] = {1., 1., 1., 1., 1.}; +Double_t scaletimezerosigma = 1.; +Double_t forcetimezeroineff = 0.; +Double_t timezero_spread = 200.; + +Int_t acceptEventType = 0; +Int_t centralityEstimator = 1; +const Int_t NcentralityBins = 7; +Double_t centralityBin[NcentralityBins + 1] = {0., 5., 10., 20., 40., 60., 80., 100.}; + +Float_t rapidityShift = -0.465; +Float_t rapidityMinCut = 0.0; +Float_t rapidityMaxCut = 0.5; + +/* TZERO corrections */ +Double_t TZEROFILL_shift = 0.; +Double_t TZEROA_shift = 0.; +Double_t TZEROC_shift = 0.; +Double_t TZEROTOF_shift = 0.; + +Double_t TZEROvertexCorr = 0.5; + +Double_t TZEROA_sigma = 1000.;//247.187; +Double_t TZEROC_sigma = 1000.;//235.113; +Double_t TZEROTOF_sigma = 1000.;//234.423; + +Double_t TZEROTOF_resoScaleFactor = 1.25; + + +Int_t multcentColor[7] = { + kRed, + kPink+1, + kOrange+1, + kYellow+1, + kGreen+1, + kAzure+1, + kViolet+1, +}; + +/***** Pb-Pb *****/ +#elif LEADLEAD + +Float_t rapidityShift = 0.; +Float_t rapidityMinCut = -0.5; +Float_t rapidityMaxCut = 0.5; +Float_t rapidityCut = 0.5; + +Int_t acceptEventType = 0; +Int_t centralityEstimator = AliAnalysisEvent::kCentEst_V0M; +const Int_t NcentralityBins = 10; +Double_t centralityBin[NcentralityBins + 1] = {0., 5., 10., 20., 30., 40., 50., 60., 70., 80., 90.}; + +/* TZERO corrections */ +Double_t TZEROFILL_shift = 0.; +Double_t TZEROA_shift = 0.; +Double_t TZEROC_shift = 0.; +Double_t TZEROTOF_shift = 0.; + +Double_t TZEROvertexCorr = 0.5; + +Double_t TZEROA_sigma = 1000.;//247.187; +Double_t TZEROC_sigma = 1000.;//235.113; +Double_t TZEROTOF_sigma = 1000.;//234.423; + +Double_t TZEROTOF_resoScaleFactor = 1.25; + + +Int_t multcentColor[10] = { + kRed, + kOrange+1, + kOrange, + kYellow, + kYellow+1, + kGreen, + kGreen+1, + kCyan+1, + kBlue, + kMagenta, + // kMagenta+1 +}; + +/***** p-p *****/ +#elif PROTONPROTON /* LHC10d, run 126088 */ + +Float_t rapidityShift = 0.; +Float_t rapidityMinCut = -0.5; +Float_t rapidityMaxCut = 0.5; +Float_t rapidityCut = 0.5; + +Int_t acceptEventType = 1; +Int_t centralityEstimator = 999; +const Int_t NcentralityBins = 6; +Double_t centralityBin[NcentralityBins + 1] = {0., 5., 10., 15., 20., 25., 100}; + +/* TZERO corrections */ +Double_t TZEROFILL_shift = 0.;//-30.6174; +Double_t TZEROA_shift = -6.5e6;// + -13.8783; +Double_t TZEROC_shift = -6.5e6;// + -21.7581; +Double_t TZEROTOF_shift = 0.;//-45.1779; + +Double_t TZEROvertexCorr = 0.5; + +Double_t TZEROA_sigma = 1000.;//247.187; +Double_t TZEROC_sigma = 1000.;//235.113; +Double_t TZEROTOF_sigma = 1000.;//234.423; + +Double_t TZEROA_resolution[NcentralityBins] = {86.4697, + 81.6549, + 79.0132, + 76.5572, + 74.8259, + 73.3834}; + +Double_t TZEROC_resolution[NcentralityBins] = {58.0423, + 52.9241, + 50.8822, + 49.05, + 48.6712, + 46.5776}; + +Double_t TZEROAND_resolution[NcentralityBins] = {48.383, + 51.9983, + 51.2704, + 50.1974, + 51.0198, + 48.6588}; + +Double_t TOFTZEROADIFF[NcentralityBins] = {-20.2311, + -19.539, + -18.8685, + -19.5327, + -18.4323, + -18.0336}; + +Double_t TOFTZEROCDIFF[NcentralityBins] = {-16.0008, + -11.9249, + -9.29299, + -8.46063, + -8.1128, + -4.89226}; + +Double_t TOFTZEROTOFDIFF[NcentralityBins] = {-11.9418, + -12.4526, + -14.0921, + -18.1132, + -17.5909, + -18.9787}; + +Double_t TZEROTOF_resoScaleFactor = 1.25; + +Double_t TZEROFILL_sigma = 1000.; + +Int_t multcentColor[10] = { + kRed, + kOrange+1, + kOrange, + kYellow, + kYellow+1, + kGreen, + kGreen+1, + kCyan+1, + kBlue, + kMagenta, + // kMagenta+1 +}; +#endif + +/* commom binning and similar business */ + +const Char_t *t0FillOnlineFileName = "T0FillOnline.139465.extended.root"; +Double_t t0Fill_offset = -1.26416e+04; + +//const Char_t *enabledChannelsFileName = "enabledChannels.root"; +const Char_t *enabledChannelsFileName = NULL; + +const Int_t NptBins = 46; +Double_t ptBin[NptBins + 1] = {0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.2, 3.4, 3.6, 3.8, 4.0, 4.2, 4.4, 4.6, 4.8, 5.0}; + +const Int_t NpBins = 46; +Double_t pBin[NpBins + 1] = {0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.2, 3.4, 3.6, 3.8, 4.0, 4.2, 4.4, 4.6, 4.8, 5.0}; + +const Int_t NmtBins = 46; +Double_t mtBin[NmtBins + 1] = {0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.2, 3.4, 3.6, 3.8, 4.0, 4.2, 4.4, 4.6, 4.8, 5.0}; + +Int_t particleColor[5] = {1, 1, 4, 8, 2}; +Int_t chargeMarker[2] = {20, 25}; + +const Char_t *partChargeName[5][2] = {"e^{+}", "e^{-}", "#mu^{+}", "#mu^{-}", "#pi^{+}", "#pi^{-}", "K^{+}", "K^{-}", "p", "#bar{p}"}; + +const Double_t kEpsilon = 0.001; + +enum ECharge_t { + kPositive, + kNegative, + kNCharges +}; +const Char_t *chargeName[kNCharges] = { + "positive", + "negative" +}; + +const Int_t NetaBins = 10; +Double_t etaMin = -1.; +Double_t etaMax = 1.; +Double_t etaStep = (etaMax - etaMin) / NetaBins; +Double_t etaBin[NetaBins + 1]; /* computed at run-time */ + +const Int_t NyBins = 20; +Double_t yMin = -1.; +Double_t yMax = 1.; +Double_t yStep = (yMax - yMin) / NyBins; +Double_t yBin[NyBins + 1]; /* computed at run-time */ + +const Int_t NphiBins = 10; +Double_t phiMin = 0.; +Double_t phiMax = 2. * TMath::Pi(); +Double_t phiStep = (phiMax - phiMin) / NphiBins; +Double_t phiBin[NphiBins + 1]; /* computed at run-time */ + +const Int_t NptsubBins = 4; +Double_t ptsubBin[NptsubBins + 1] = {0.2, 0.5, 1.0, 1.5, 5.0}; +Int_t ptsubBinMin[NptsubBins] = {0, 6, 16, 21}; +Int_t ptsubBinMax[NptsubBins] = {5, 15, 20, 45}; + +const Int_t NdcaBins = 2000; +Double_t dcaBin[NdcaBins + 1]; +Double_t dcaMin = -5., dcaMax = 5., dcaStep = (dcaMax - dcaMin) / NdcaBins; + + + +#endif diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCA.C b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCA.C new file mode 100644 index 00000000000..a7274fa2c15 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCA.C @@ -0,0 +1,1392 @@ +#include "CommonDefs.C" + +enum EMCHisto_t { + kPrimary, + kWeakDecay, + kMaterial, + kNMCHistos +}; +const Char_t *mchistoName[kNMCHistos] = { + "primary", + "weakdecay", + "material" +}; + +DCAdata(const Char_t *filename, Int_t evMax = kMaxInt, Int_t startEv = 0) +{ + + /* include path for ACLic */ + gSystem->AddIncludePath("-I$ALICE_ROOT/include"); + gSystem->AddIncludePath("-I$ALICE_ROOT/TOF"); + /* load libraries */ + gSystem->Load("libANALYSIS"); + gSystem->Load("libANALYSISalice"); + /* build analysis task class */ + gROOT->LoadMacro("AliAnalysisParticle.cxx+g"); + gROOT->LoadMacro("AliAnalysisEvent.cxx+g"); + gROOT->LoadMacro("AliAnalysisTrack.cxx+g"); + + /* open file, get tree and connect */ + TFile *filein = TFile::Open(filename); + TTree *treein = (TTree *)filein->Get("aodTree"); + printf("got \"aodTree\": %d entries\n", treein->GetEntries()); + AliAnalysisEvent *analysisEvent = new AliAnalysisEvent(); + TClonesArray *analysisTrackArray = new TClonesArray("AliAnalysisTrack"); + AliAnalysisTrack *analysisTrack = NULL; + treein->SetBranchAddress("AnalysisEvent", &analysisEvent); + treein->SetBranchAddress("AnalysisTrack", &analysisTrackArray); + + /* open enabled flag map */ + TH1F *hEnabledFlag = NULL; + if (enabledChannelsFileName) { + TFile *enabledfile = TFile::Open(enabledChannelsFileName); + hEnabledFlag = (TH1F *)enabledfile->Get("hEnabledFlag"); + } + + /**************************************************************/ + /*** HISTOS ***************************************************/ + /**************************************************************/ + + /* run-time binning */ + for (Int_t ibin = 0; ibin < NdcaBins + 1; ibin++) + dcaBin[ibin] = dcaMin + ibin * dcaStep; + + /* histos */ + TH3I *hDCAopen[AliPID::kSPECIES][kNCharges]; + TH3I *hDCAcut[AliPID::kSPECIES][kNCharges]; + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) { + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + hDCAopen[ipart][icharge] = new TH3I(Form("hDCAopen_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge]), "", NcentralityBins, centralityBin, NptBins, ptBin, NdcaBins, dcaBin); + hDCAcut[ipart][icharge] = new TH3I(Form("hDCAcut_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge]), "", NcentralityBins, centralityBin, NptBins, ptBin, NdcaBins, dcaBin); + } + } + + /**************************************************************/ + /**************************************************************/ + /**************************************************************/ + + /* TOF PID response */ + AliTOFPIDResponse tofResponse; + tofResponse.SetTimeResolution(tofReso); + /* TPC PID response */ + AliTPCPIDResponse *tpcResponse = AliAnalysisTrack::GetTPCResponse(); + + /* start stopwatch */ + TStopwatch timer; + timer.Start(); + + /* loop over events */ + Int_t charge, index; + UShort_t dedxN; + Double_t cent, p, pt, mt, dca, tofsignal, tpcsignal, tpctofsignal; + Double_t dedx, bethe, deltadedx, dedx_sigma, ptpc; + Double_t time, time_sigma, timezero, timezero_sigma, tof, tof_sigma, texp, texp_sigma, deltat, deltat_sigma; + + /* open TZERO calibfile */ + TH1 *hCentrality_TZEROA_mean = NULL; + TH1 *hCentrality_TZEROA_sigma = NULL; + TH1 *hCentrality_TZEROC_mean = NULL; + TH1 *hCentrality_TZEROC_sigma = NULL; + TH1 *hCentrality_TOF_mean = NULL; + TH1 *hCentrality_TOF_TZEROA_mean = NULL; + TH1 *hCentrality_TOF_TZEROC_mean = NULL; + TH1 *hCentrality_TOF_TZEROTOF_mean = NULL; + TH1 *hCentrality_TZEROA_reso = NULL; + TH1 *hCentrality_TZEROC_reso = NULL; + TH1 *hCentrality_TZEROAND_reso = NULL; + if (1) { + TFile *calibfile = TFile::Open("TZEROcalibration.root"); + hCentrality_TZEROA_mean = (TH1 *)calibfile->Get("hCentrality_TZEROA_mean"); + hCentrality_TZEROA_sigma = (TH1 *)calibfile->Get("hCentrality_TZEROA_sigma"); + hCentrality_TZEROC_mean = (TH1 *)calibfile->Get("hCentrality_TZEROC_calib"); + hCentrality_TZEROC_sigma = (TH1 *)calibfile->Get("hCentrality_TZEROC_sigma"); + hCentrality_TOF_mean = (TH1 *)calibfile->Get("hCentrality_TOF_mean"); + hCentrality_TOF_TZEROA_mean = (TH1 *)calibfile->Get("hCentrality_TOF_TZEROA_mean"); + hCentrality_TOF_TZEROC_mean = (TH1 *)calibfile->Get("hCentrality_TOF_TZEROC_mean"); + hCentrality_TOF_TZEROTOF_mean = (TH1 *)calibfile->Get("hCentrality_TOF_TZEROTOF_mean"); + + TFile *resofile = TFile::Open("TZEROresolution.root"); + hCentrality_TZEROA_reso = (TH1 *)resofile->Get("hTZEROA_reso"); + hCentrality_TZEROC_reso = (TH1 *)resofile->Get("hTZEROC_reso"); + hCentrality_TZEROAND_reso = (TH1 *)resofile->Get("hTZEROAND_reso"); + } + Double_t TZEROA_mean; + Double_t TZEROA_sigma; + Double_t TZEROC_mean; + Double_t TZEROC_sigma; + Double_t TOF_mean; + Double_t TOF_TZEROA_mean; + Double_t TOF_TZEROC_mean; + Double_t TOF_TZEROTOF_mean; + Double_t TZEROA; + Double_t TZEROA_reso; + Bool_t hasTZEROA; + Double_t TZEROC; + Double_t TZEROC_reso; + Bool_t hasTZEROC; + Double_t TZEROAND; + Double_t TZEROAND_reso; + Bool_t hasTZEROAND; + Double_t TZEROTOF; + Double_t TZEROTOF_reso; + Bool_t hasTZEROTOF; + Double_t TZEROMEAN; + Double_t TZEROMEAN_weight; + Double_t TZEROBEST; + Double_t TZEROBEST_reso; + + + for (Int_t iev = startEv; iev < treein->GetEntries() && iev < evMax; iev++) { + /* get event */ + treein->GetEvent(iev); + if (iev % 100000 == 0) printf("iev = %d\n", iev); + /* check event */ + if (!analysisEvent->AcceptEvent(acceptEventType)) continue; + + /*** ACCEPTED EVENT ***/ + + /* apply time-zero TOF correction */ + analysisEvent->ApplyTimeZeroTOFCorrection(); + + /* get centrality */ + cent = analysisEvent->GetCentralityPercentile(centralityEstimator); + + /* TZERO corrections */ + Int_t icent; + for (icent = 0; icent < NcentralityBins; icent++) + if (cent < centralityBin[icent + 1]) + break; + TZEROA_mean = hCentrality_TZEROA_mean ? hCentrality_TZEROA_mean->GetBinContent(icent + 1) : 0.; + TZEROA_sigma = hCentrality_TZEROA_sigma ? hCentrality_TZEROA_sigma->GetBinContent(icent + 1) : 1000.; + TZEROC_mean = hCentrality_TZEROC_mean ? hCentrality_TZEROC_mean->GetBinContent(icent + 1) : 0.; + TZEROC_sigma = hCentrality_TZEROC_sigma ? hCentrality_TZEROC_sigma->GetBinContent(icent + 1) : 1000.; + + TOF_mean = hCentrality_TOF_mean ? hCentrality_TOF_mean->GetBinContent(icent + 1) : 0.; + TOF_TZEROA_mean = hCentrality_TOF_TZEROA_mean ? hCentrality_TOF_TZEROA_mean->GetBinContent(icent + 1) : 0.; + TOF_TZEROC_mean = hCentrality_TOF_TZEROC_mean ? hCentrality_TOF_TZEROC_mean->GetBinContent(icent + 1) : 0.; + TOF_TZEROTOF_mean = hCentrality_TOF_TZEROTOF_mean ? hCentrality_TOF_TZEROTOF_mean->GetBinContent(icent + 1) : 0.; + + TZEROA_reso = hCentrality_TZEROA_reso ? hCentrality_TZEROA_reso->GetBinContent(icent + 1) : 70.; + TZEROC_reso = hCentrality_TZEROC_reso ? hCentrality_TZEROC_reso->GetBinContent(icent + 1) : 70.; + TZEROAND_reso = hCentrality_TZEROAND_reso ? hCentrality_TZEROAND_reso->GetBinContent(icent + 1) : 50.; + + /* loop over tracks */ + for (Int_t itrk = 0; itrk < analysisTrackArray->GetEntries(); itrk++) { + /* get track */ + analysisTrack = (AliAnalysisTrack *)analysisTrackArray->At(itrk); + if (!analysisTrack) continue; + /* check accepted track (no DCA cut) */ + if (!analysisTrack->AcceptTrack(kFALSE)) continue; + /* get charge */ + charge = analysisTrack->GetSign() > 0. ? kPositive : kNegative; + /* check TPC pid */ + if (!analysisTrack->HasTPCPID()) continue; + /* check TOF pid */ + if (!analysisTrack->HasTOFPID(hEnabledFlag)) continue; + + /*** ACCEPTED TRACK WITH TPC+TOF PID ***/ + + /* get track info */ + p = analysisTrack->GetP(); + pt = analysisTrack->GetPt(); + dca = analysisTrack->GetImpactParameter(0); + + /* get TPC info */ + dedx = analysisTrack->GetTPCdEdx(); + dedxN = analysisTrack->GetTPCdEdxN(); + ptpc = analysisTrack->GetTPCmomentum(); + + /* apply expected time correction */ + // analysisTrack->ApplyTOFExpectedTimeCorrection(); + + /* get TOF info */ + time = analysisTrack->GetTOFTime() - TOF_mean; + time_sigma = tofReso; + /* TZEROTOF */ + TZEROTOF = analysisEvent->GetTimeZeroTOF(analysisTrack->GetP()); + TZEROTOF_reso = analysisEvent->GetTimeZeroTOFSigma(analysisTrack->GetP()); + hasTZEROTOF = TZEROTOF_reso < 150.; + if (hasTZEROTOF) { + TZEROTOF += TOF_TZEROTOF_mean - TOF_mean; + TZEROTOF_reso *= TZEROTOF_resoScaleFactor; + } + /* TZEROA */ + TZEROA = analysisEvent->GetTimeZeroT0(1) - TZEROA_shift; + // TZEROA_reso = TZEROA_resolution[icent]; + hasTZEROA = TMath::Abs(TZEROA - TZEROA_mean) < 3. * TZEROA_sigma; + TZEROA += TOF_TZEROA_mean - TOF_mean; + /* TZEROC */ + TZEROC = analysisEvent->GetTimeZeroT0(2) - TZEROC_shift; + // TZEROC_reso = TZEROC_resolution[icent]; + hasTZEROC = TMath::Abs(TZEROC - TZEROC_mean) < 3. * TZEROC_sigma; + TZEROC += TOF_TZEROC_mean - TOF_mean; + /* TZEROAND */ + TZEROAND = (TZEROA + TZEROC) * 0.5; + // TZEROAND_reso = TZEROAND_resolution[icent]; + hasTZEROAND = hasTZEROA && hasTZEROC; + /* TZEROMEAN */ + TZEROMEAN = TZEROTOF / TZEROTOF_reso / TZEROTOF_reso; + TZEROMEAN_weight = 1. / TZEROTOF_reso / TZEROTOF_reso; + if (hasTZEROAND) { + // printf("TZEROAND\n"); + TZEROMEAN += TZEROAND / TZEROAND_reso / TZEROAND_reso; + TZEROMEAN_weight = 1. / TZEROAND_reso / TZEROAND_reso; + } + else if (hasTZEROA) { + // printf("TZEROA\n"); + TZEROMEAN += TZEROA / TZEROA_reso / TZEROA_reso; + TZEROMEAN_weight = 1. / TZEROA_reso / TZEROA_reso; + } + else if (hasTZEROC) { + // printf("TZEROC\n"); + TZEROMEAN += TZEROC / TZEROC_reso / TZEROC_reso; + TZEROMEAN_weight = 1. / TZEROC_reso / TZEROC_reso; + } + timezero = TZEROMEAN / TZEROMEAN_weight; + timezero_sigma = TMath::Sqrt(1. / TZEROMEAN_weight); + /* TZEROBEST */ + TZEROBEST = TZEROTOF; + TZEROBEST_reso = TZEROTOF_reso; + if (hasTZEROAND && TZEROAND_reso < TZEROBEST_reso) { + TZEROBEST = TZEROAND; + TZEROBEST_reso = TZEROAND_reso; + } + else if (hasTZEROA && TZEROA_reso < TZEROBEST_reso) { + TZEROBEST = TZEROA; + TZEROBEST_reso = TZEROA_reso; + } + if (hasTZEROC && TZEROC_reso < TZEROBEST_reso) { + TZEROBEST = TZEROC; + TZEROBEST_reso = TZEROC_reso; + } + timezero = TZEROBEST; + timezero_sigma = TZEROBEST_reso; + + tof = time - timezero; + tof_sigma = TMath::Sqrt(time_sigma * time_sigma + timezero_sigma * timezero_sigma); + + /* loop over particle IDs */ + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) { + + /* check rapidity */ + if (analysisTrack->GetY(AliPID::ParticleMass(ipart)) - rapidityShift > rapidityMaxCut || + analysisTrack->GetY(AliPID::ParticleMass(ipart)) - rapidityShift < rapidityMinCut) continue; + + /*** ACCEPTED TRACK WITHIN CORRECT RAPIDTY ***/ + + /* TPC signal */ + bethe = tpcResponse->GetExpectedSignal(ptpc, ipart); + deltadedx = dedx - bethe; + dedx_sigma = tpcResponse->GetExpectedSigma(ptpc, dedxN, ipart); + tpcsignal = deltadedx / dedx_sigma; + + /* TOF expected time */ + texp = analysisTrack->GetTOFExpTime(ipart); + texp_sigma = analysisTrack->GetTOFExpTimeSigma(ipart); + + /* TOF signal */ + deltat = tof - texp; + deltat_sigma = TMath::Sqrt(tof_sigma * tof_sigma + texp_sigma * texp_sigma); + tofsignal = deltat / deltat_sigma; + + /* TPC+TOF signal */ + tpctofsignal = TMath::Sqrt(tpcsignal * tpcsignal + tofsignal * tofsignal); + + /* check PID cuts */ + if (tpctofsignal > 2.) continue; + + /* fill histo */ + hDCAopen[ipart][charge]->Fill(cent, pt, dca); + + /* check accepted track (with DCA cut) */ + if (!analysisTrack->AcceptTrack(kTRUE)) continue; + + /* fill histo */ + hDCAcut[ipart][charge]->Fill(cent, pt, dca); + + } /* end of loop over particle IDs */ + } /* end of loop over tracks */ + } /* end of loop over events */ + + /* stop stopwatch */ + timer.Stop(); + timer.Print(); + + /* output */ + TFile *fileout = TFile::Open(Form("DCAdata.%s", filename), "RECREATE"); + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) { + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + hDCAopen[ipart][icharge]->Write(); + hDCAcut[ipart][icharge]->Write(); + } + } + + fileout->Close(); + +} + +/**************************************************************/ + +DCAmc(const Char_t *filename, Int_t evMax = kMaxInt, Int_t startEv = 0) +{ + + /* include path for ACLic */ + gSystem->AddIncludePath("-I$ALICE_ROOT/include"); + gSystem->AddIncludePath("-I$ALICE_ROOT/TOF"); + /* load libraries */ + gSystem->Load("libANALYSIS"); + gSystem->Load("libANALYSISalice"); + /* build analysis task class */ + gROOT->LoadMacro("AliAnalysisParticle.cxx+g"); + gROOT->LoadMacro("AliAnalysisEvent.cxx+g"); + gROOT->LoadMacro("AliAnalysisTrack.cxx+g"); + + /* open file, get tree and connect */ + TFile *filein = TFile::Open(filename); + TTree *treein = (TTree *)filein->Get("aodTree"); + printf("got \"aodTree\": %d entries\n", treein->GetEntries()); + AliAnalysisEvent *analysisEvent = new AliAnalysisEvent(); + TClonesArray *analysisTrackArray = new TClonesArray("AliAnalysisTrack"); + AliAnalysisTrack *analysisTrack = NULL; + treein->SetBranchAddress("AnalysisEvent", &analysisEvent); + treein->SetBranchAddress("AnalysisTrack", &analysisTrackArray); + + /**************************************************************/ + /*** HISTOS ***************************************************/ + /**************************************************************/ + + /* run-time binning */ + for (Int_t ibin = 0; ibin < NdcaBins + 1; ibin++) + dcaBin[ibin] = dcaMin + ibin * dcaStep; + + /* histos */ + TH3I *hDCAopen[kNMCHistos][AliPID::kSPECIES][kNCharges]; + TH3I *hDCAcut[kNMCHistos][AliPID::kSPECIES][kNCharges]; + for (Int_t ihisto = 0; ihisto < kNMCHistos; ihisto++ ) { + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) { + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + hDCAopen[ihisto][ipart][icharge] = new TH3I(Form("hDCAopen_%s_%s_%s", mchistoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge]), "", NcentralityBins, centralityBin, NptBins, ptBin, NdcaBins, dcaBin); + hDCAcut[ihisto][ipart][icharge] = new TH3I(Form("hDCAcut_%s_%s_%s", mchistoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge]), "", NcentralityBins, centralityBin, NptBins, ptBin, NdcaBins, dcaBin); + } + } + } + + /**************************************************************/ + /**************************************************************/ + /**************************************************************/ + + /* start stopwatch */ + TStopwatch timer; + timer.Start(); + + /* loop over events */ + Int_t part, charge, type; + Double_t cent, pt, mt, dca; + + for (Int_t iev = startEv; iev < treein->GetEntries() && iev < evMax; iev++) { + /* get event */ + treein->GetEvent(iev); + if (iev % 100000 == 0) printf("iev = %d\n", iev); + /* check event */ + if (!analysisEvent->AcceptEvent(acceptEventType)) continue; + + /*** ACCEPTED EVENT ***/ + + /* get centrality */ + cent = analysisEvent->GetCentralityPercentile(centralityEstimator); + + /* loop over tracks */ + for (Int_t itrk = 0; itrk < analysisTrackArray->GetEntries(); itrk++) { + /* get track */ + analysisTrack = (AliAnalysisTrack *)analysisTrackArray->At(itrk); + if (!analysisTrack) continue; + /* check defined PID */ + part = analysisTrack->GetMCPID(); + if (part < 0 || analysisTrack->GetSign() == 0.) continue; + /* check accepted track (no DCA cut) */ + if (!analysisTrack->AcceptTrack(kFALSE)) continue; + /* check rapidity */ + if (analysisTrack->GetY(AliPID::ParticleMass(part)) - rapidityShift > rapidityMaxCut || + analysisTrack->GetY(AliPID::ParticleMass(part)) - rapidityShift < rapidityMinCut) continue; + + /*** ACCEPTED TRACK WITHIN CORRECT RAPIDTY ***/ + + /* get track info */ + pt = analysisTrack->GetPt(); + dca = analysisTrack->GetImpactParameter(0); + charge = analysisTrack->GetMCCharge() > 0. ? kPositive : kNegative; + if (analysisTrack->IsMCPrimary()) + type = kPrimary; + else if (analysisTrack->IsMCSecondaryWeakDecay()) + type = kWeakDecay; + else if (analysisTrack->IsMCSecondaryMaterial()) + type = kMaterial; + else + continue; + + /* fill histo */ + hDCAopen[type][part][charge]->Fill(cent, pt, dca); + + /* check accepted track (with DCA cut) */ + if (!analysisTrack->AcceptTrack(kTRUE)) continue; + + /* fill histo */ + hDCAcut[type][part][charge]->Fill(cent, pt, dca); + + } /* end of loop over tracks */ + } /* end of loop over events */ + + /* stop stopwatch */ + timer.Stop(); + timer.Print(); + + /* output */ + TFile *fileout = TFile::Open(Form("DCAmc.%s", filename), "RECREATE"); + for (Int_t ihisto = 0; ihisto < kNMCHistos; ihisto++) { + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) { + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + hDCAopen[ihisto][ipart][icharge]->Write(); + hDCAcut[ihisto][ipart][icharge]->Write(); + } + } + } + + fileout->Close(); + +} + +/**************************************************************/ + +enum EFitParams_t { + kIntegralCounts, + kPrimaryCounts, + kWeakDecayCounts, + kMaterialCounts, + kPrimaryIntegral, + kWeakDecayIntegral, + kMaterialIntegral, + kDataCutIntegral, + kPrimaryCutIntegral, + kWeakDecayCutIntegral, + kMaterialCutIntegral, + kNFitParams +}; + +/* fit output params name */ +const Char_t *fitParamName[kNFitParams] = { + "IntegralCounts", + "PrimaryCounts", + "WeakDecayCounts", + "MaterialCounts", + "PrimaryIntegral", + "WeakDecayIntegral", + "MaterialIntegral", + "DataCutIntegral", + "PrimaryCutIntegral", + "WeakDecayCutIntegral", + "MaterialCutIntegral" +}; + +/* fit output params title */ +const Char_t *fitParamTitle[kNFitParams] = { + "Integral counts;p_{T} (GeV/c);", + "Primary counts;p_{T} (GeV/c);", + "Weak-decay counts;p_{T} (GeV/c);", + "Material counts;p_{T} (GeV/c);", + "Primary integral;p_{T} (GeV/c);", + "Weak-decay integral;p_{T} (GeV/c);", + "Material integral;p_{T} (GeV/c);", + "Data cut integral;p_{T} (GeV/c);", + "Primary cut integral;p_{T} (GeV/c);", + "Weak-decay cut integral;p_{T} (GeV/c);", + "Material cut integral;p_{T} (GeV/c);" +}; + +/* fit ranges */ +Double_t fitPtMin[AliPID::kSPECIES] = {0.5, 0.5, 0.3, 0.4, 0.5}; +Double_t fitPtMax[AliPID::kSPECIES] = {2.0, 2.0, 2.0, 2.0, 3.0}; + +/* rebin DCA */ +Int_t rebindca = 10; + +DCAdeltafeed(const Char_t *datafilename, const Char_t *mcfilename) +{ + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + DCAdeltafeed(datafilename, mcfilename, 2, icharge, -1); + DCAdeltafeed(datafilename, mcfilename, 4, icharge, -1); + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + DCAdeltafeed(datafilename, mcfilename, 2, icharge, icent); + DCAdeltafeed(datafilename, mcfilename, 4, icharge, icent); + } + } +} + +DCAdeltafeed(const Char_t *datafilename, const Char_t *mcfilename, Int_t ipart, Int_t icharge, Int_t icent, Float_t ptMin = -1., Float_t ptMax = -1., Bool_t checkHistoFlag = kFALSE) +{ + + printf("****************************************\n"); + printf("RUNNING DCA FIT:\n"); + printf("RAPIDITY-CUT: %s\n", AliPID::ParticleName(ipart)); + printf("CHARGE: %s\n", chargeName[icharge]); + printf("PARTICLE: %s\n", AliPID::ParticleName(ipart)); + printf("CENTRALITY BIN: %d\n", icent); + printf("****************************************\n"); + + /* open data */ + TFile *datafilein = TFile::Open(datafilename); + TFile *mcfilein = TFile::Open(mcfilename); + + /* get histos */ + TH3I *hDCAopen = (TH3I *)datafilein->Get(Form("hDCAopen_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + TH3I *hDCAopen_primary = (TH3I *)mcfilein->Get(Form("hDCAopen_primary_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + TH3I *hDCAopen_weakdecay = (TH3I *)mcfilein->Get(Form("hDCAopen_weakdecay_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + TH3I *hDCAopen_material = (TH3I *)mcfilein->Get(Form("hDCAopen_material_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + TH3I *hDCAcut = (TH3I *)datafilein->Get(Form("hDCAcut_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + TH3I *hDCAcut_primary = (TH3I *)mcfilein->Get(Form("hDCAcut_primary_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + TH3I *hDCAcut_weakdecay = (TH3I *)mcfilein->Get(Form("hDCAcut_weakdecay_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + TH3I *hDCAcut_material = (TH3I *)mcfilein->Get(Form("hDCAcut_material_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + + /* setup centrality range */ + if (icent < 0 || icent >= NcentralityBins) { + printf("WARNING: undefined centrality -> using 00-90\% range\n"); + hDCAopen->GetXaxis()->SetRange(1, NcentralityBins); + hDCAopen_primary->GetXaxis()->SetRange(1, NcentralityBins); + hDCAopen_weakdecay->GetXaxis()->SetRange(1, NcentralityBins); + hDCAopen_material->GetXaxis()->SetRange(1, NcentralityBins); + hDCAcut->GetXaxis()->SetRange(1, NcentralityBins); + hDCAcut_primary->GetXaxis()->SetRange(1, NcentralityBins); + hDCAcut_weakdecay->GetXaxis()->SetRange(1, NcentralityBins); + hDCAcut_material->GetXaxis()->SetRange(1, NcentralityBins); + } + else { + printf("***** FITTING CENTRALITY-BIN [%02d, %02d] %% *****\n", centralityBin[icent], centralityBin[icent + 1]); + hDCAopen->GetXaxis()->SetRange(icent + 1, icent + 1); +#if 0 + hDCAopen_primary->GetXaxis()->SetRange(icent + 1, icent + 1); + hDCAopen_weakdecay->GetXaxis()->SetRange(icent + 1, icent + 1); + hDCAopen_material->GetXaxis()->SetRange(icent + 1, icent + 1); +#else + hDCAopen_primary->GetXaxis()->SetRange(1, NcentralityBins); + hDCAopen_weakdecay->GetXaxis()->SetRange(1, NcentralityBins); + hDCAopen_material->GetXaxis()->SetRange(1, NcentralityBins); +#endif + hDCAcut->GetXaxis()->SetRange(icent + 1, icent + 1); +#if 0 + hDCAcut_primary->GetXaxis()->SetRange(icent + 1, icent + 1); + hDCAcut_weakdecay->GetXaxis()->SetRange(icent + 1, icent + 1); + hDCAcut_material->GetXaxis()->SetRange(icent + 1, icent + 1); +#else + hDCAcut_primary->GetXaxis()->SetRange(1, NcentralityBins); + hDCAcut_weakdecay->GetXaxis()->SetRange(1, NcentralityBins); + hDCAcut_material->GetXaxis()->SetRange(1, NcentralityBins); +#endif + } + + /* setup pt range */ + Bool_t requestedRange = kFALSE; + if (ptMin > -0.001 && ptMax > -0.001 && ptMax > ptMin) { + printf("***** FITTING PT-BIN [%f, %f] GeV/c *****\n", ptMin, ptMax); + requestedRange = kTRUE; + hDCAopen->GetYaxis()->SetRangeUser(ptMin + 0.001, ptMax - 0.001); + hDCAopen_primary->GetYaxis()->SetRangeUser(ptMin + 0.001, ptMax - 0.001); + hDCAopen_weakdecay->GetYaxis()->SetRangeUser(ptMin + 0.001, ptMax - 0.001); + hDCAopen_material->GetYaxis()->SetRangeUser(ptMin + 0.001, ptMax - 0.001); + hDCAcut->GetYaxis()->SetRangeUser(ptMin + 0.001, ptMax - 0.001); + hDCAcut_primary->GetYaxis()->SetRangeUser(ptMin + 0.001, ptMax - 0.001); + hDCAcut_weakdecay->GetYaxis()->SetRangeUser(ptMin + 0.001, ptMax - 0.001); + hDCAcut_material->GetYaxis()->SetRangeUser(ptMin + 0.001, ptMax - 0.001); + } + + /* output */ + Char_t outfilename[1024]; + if (icent < 0 || icent >= NcentralityBins) + sprintf(outfilename, "DCAdeltafeed_cent0090_%s_%s.root", AliPID::ParticleName(ipart), chargeName[icharge]); + else { + sprintf(outfilename, "DCAdeltafeed_cent%02d%02d_%s_%s.root", centralityBin[icent], centralityBin[icent + 1], AliPID::ParticleName(ipart), chargeName[icharge]); + } + TFile *fileout = TFile::Open(outfilename, "RECREATE"); + TDirectory *fitDir = fileout->mkdir("FitParams"); + /* canvas */ + TCanvas *canvas = new TCanvas("canvas"); + canvas->SetLogy(); + /* histo */ + TH1D *hFitParamHisto[kNFitParams]; + for (Int_t iparam = 0; iparam < kNFitParams; iparam++) + hFitParamHisto[iparam] = new TH1D(Form("h%s", fitParamName[iparam]), fitParamTitle[iparam], NptBins, ptBin); + + + /* loop over ptBins */ + for (Int_t ipt = 0; ipt < NptBins; ipt++) { + + if (!requestedRange) { + if ((ptBin[ipt] + 0.001) < fitPtMin[ipart] || (ptBin[ipt + 1] - 0.001) > fitPtMax[ipart]) continue; + printf("***** FITTING PT-BIN [%f, %f] GeV/c *****\n", ptBin[ipt], ptBin[ipt + 1]); + hDCAopen->GetYaxis()->SetRange(ipt + 1, ipt + 1); + hDCAopen_primary->GetYaxis()->SetRange(ipt + 1, ipt + 1); + hDCAopen_weakdecay->GetYaxis()->SetRange(ipt + 1, ipt + 1); + hDCAopen_material->GetYaxis()->SetRange(ipt + 1, ipt + 1); + hDCAcut->GetYaxis()->SetRange(ipt + 1, ipt + 1); + hDCAcut_primary->GetYaxis()->SetRange(ipt + 1, ipt + 1); + hDCAcut_weakdecay->GetYaxis()->SetRange(ipt + 1, ipt + 1); + hDCAcut_material->GetYaxis()->SetRange(ipt + 1, ipt + 1); + } + + /* dca projections */ + TH1 *hDCAopen_py = hDCAopen->Project3D("z"); + TH1 *hDCAopen_primary_py = hDCAopen_primary->Project3D("z"); + TH1 *hDCAopen_weakdecay_py = hDCAopen_weakdecay->Project3D("z"); + TH1 *hDCAopen_material_py = hDCAopen_material->Project3D("z"); + TH1 *hDCAcut_py = hDCAcut->Project3D("z"); + TH1 *hDCAcut_primary_py = hDCAcut_primary->Project3D("z"); + TH1 *hDCAcut_weakdecay_py = hDCAcut_weakdecay->Project3D("z"); + TH1 *hDCAcut_material_py = hDCAcut_material->Project3D("z"); + + /* rebin */ + hDCAopen_py->Rebin(rebindca); + hDCAopen_primary_py->Rebin(rebindca); + hDCAopen_weakdecay_py->Rebin(rebindca); + hDCAopen_material_py->Rebin(rebindca); + hDCAcut_py->Rebin(rebindca); + hDCAcut_primary_py->Rebin(rebindca); + hDCAcut_weakdecay_py->Rebin(rebindca); + hDCAcut_material_py->Rebin(rebindca); + + /* check histos if requested */ + if (checkHistoFlag) { + TCanvas *cCheckHisto = new TCanvas("cCheckHisto"); + cCheckHisto->Divide(2, 4); + cCheckHisto->cd(1); + hDCAopen_py->Draw(); + cCheckHisto->cd(2); + hDCAcut_py->Draw(); + cCheckHisto->cd(3); + hDCAopen_primary_py->Draw(); + cCheckHisto->cd(4); + hDCAcut_primary_py->Draw(); + cCheckHisto->cd(5); + hDCAopen_weakdecay_py->Draw(); + cCheckHisto->cd(6); + hDCAcut_weakdecay_py->Draw(); + cCheckHisto->cd(7); + hDCAopen_material_py->Draw(); + cCheckHisto->cd(8); + hDCAcut_material_py->Draw(); + return; + } + + Double_t param[kNFitParams]; + Double_t param_err[kNFitParams]; + + param[kPrimaryIntegral] = hDCAopen_primary_py->Integral(); + param_err[kPrimaryIntegral] = TMath::Sqrt(hDCAopen_primary_py->Integral()); + param[kWeakDecayIntegral] = hDCAopen_weakdecay_py->Integral(); + param_err[kWeakDecayIntegral] = TMath::Sqrt(hDCAopen_weakdecay_py->Integral()); + param[kMaterialIntegral] = hDCAopen_material_py->Integral(); + param_err[kMaterialIntegral] = TMath::Sqrt(hDCAopen_material_py->Integral()); + + param[kDataCutIntegral] = hDCAcut_py->Integral(); + param_err[kDataCutIntegral] = TMath::Sqrt(hDCAcut_py->Integral()); + param[kPrimaryCutIntegral] = hDCAcut_primary_py->Integral(); + param_err[kPrimaryCutIntegral] = TMath::Sqrt(hDCAcut_primary_py->Integral()); + param[kWeakDecayCutIntegral] = hDCAcut_weakdecay_py->Integral(); + param_err[kWeakDecayCutIntegral] = TMath::Sqrt(hDCAcut_weakdecay_py->Integral()); + param[kMaterialCutIntegral] = hDCAcut_material_py->Integral(); + param_err[kMaterialCutIntegral] = TMath::Sqrt(hDCAcut_material_py->Integral()); + + /* fit */ + DCAfit(hDCAopen_py, hDCAopen_primary_py, hDCAopen_weakdecay_py, hDCAopen_material_py, param, param_err, canvas); + + + /* check requested pt-range */ + if (requestedRange) + return; + + /* write canvas */ + fitDir->cd(); + canvas->Write(Form("fitDisplay_ptBin_%3.2f_%3.2f", ptBin[ipt], ptBin[ipt + 1])); + + /* set histo */ + for (Int_t iparam = 0; iparam < kNFitParams; iparam++) { + hFitParamHisto[iparam]->SetBinContent(ipt + 1, param[iparam]); + hFitParamHisto[iparam]->SetBinError(ipt + 1, param_err[iparam]); + } + + /* delete */ + delete hDCAopen_py; + delete hDCAopen_primary_py; + delete hDCAopen_weakdecay_py; + delete hDCAopen_material_py; + delete hDCAcut_py; + delete hDCAcut_primary_py; + delete hDCAcut_weakdecay_py; + delete hDCAcut_material_py; + + } + + /* check requested pt-range */ + if (requestedRange) + return; + + /*** POST-ANALYSIS ***/ + + TDirectory *postDir = fileout->mkdir("PostAnalysis"); + + /* compute fractions */ + TH1D *hPrimaryFraction = new TH1D(*hFitParamHisto[kPrimaryCounts]); + hPrimaryFraction->Divide(hFitParamHisto[kPrimaryCounts], hFitParamHisto[kIntegralCounts], 1., 1., "B"); + TH1D *hWeakDecayFraction = new TH1D(*hFitParamHisto[kWeakDecayCounts]); + hWeakDecayFraction->Divide(hFitParamHisto[kWeakDecayCounts], hFitParamHisto[kIntegralCounts], 1., 1., "B"); + TH1D *hMaterialFraction = new TH1D(*hFitParamHisto[kMaterialCounts]); + hMaterialFraction->Divide(hFitParamHisto[kMaterialCounts], hFitParamHisto[kIntegralCounts], 1., 1., "B"); + + /* compute scale factors */ + TH1D *hPrimaryScale = new TH1D(*hFitParamHisto[kPrimaryCounts]); + hPrimaryScale->Divide(hFitParamHisto[kPrimaryCounts], hFitParamHisto[kPrimaryIntegral], 1., 1., "B"); + TH1D *hWeakDecayScale = new TH1D(*hFitParamHisto[kWeakDecayCounts]); + hWeakDecayScale->Divide(hFitParamHisto[kWeakDecayCounts], hFitParamHisto[kWeakDecayIntegral], 1., 1., "B"); + TH1D *hMaterialScale = new TH1D(*hFitParamHisto[kMaterialCounts]); + hMaterialScale->Divide(hFitParamHisto[kMaterialCounts], hFitParamHisto[kMaterialIntegral], 1., 1., "B"); + + /* compute cut integrals */ + TH1D *hPrimaryCutIntegral = new TH1D(*hFitParamHisto[kPrimaryCutIntegral]); + hPrimaryCutIntegral->Multiply(hPrimaryScale); + TH1D *hWeakDecayCutIntegral = new TH1D(*hFitParamHisto[kWeakDecayCutIntegral]); + hWeakDecayCutIntegral->Multiply(hWeakDecayScale); + TH1D *hMaterialCutIntegral = new TH1D(*hFitParamHisto[kMaterialCutIntegral]); + hMaterialCutIntegral->Multiply(hMaterialScale); + + /* compute cut fractions */ + TH1D *hPrimaryCutFraction = new TH1D(*hPrimaryCutIntegral); + hPrimaryCutFraction->Divide(hPrimaryCutIntegral, hFitParamHisto[kDataCutIntegral], 1., 1., "B"); + TH1D *hWeakDecayCutFraction = new TH1D(*hWeakDecayCutIntegral); + hWeakDecayCutFraction->Divide(hWeakDecayCutIntegral, hFitParamHisto[kDataCutIntegral], 1., 1., "B"); + TH1D *hMaterialCutFraction = new TH1D(*hMaterialCutIntegral); + hMaterialCutFraction->Divide(hMaterialCutIntegral, hFitParamHisto[kDataCutIntegral], 1., 1., "B"); + + + /*** OUTPUT ***/ + + /* write fir params histos */ + fitDir->cd(); + for (Int_t iparam = 0; iparam < kNFitParams; iparam++) + hFitParamHisto[iparam]->Write(); + /* write post-analysis histos */ + postDir->cd(); + hPrimaryFraction->Write("hPrimaryFraction"); + hWeakDecayFraction->Write("hWeakDecayFraction"); + hMaterialFraction->Write("hMaterialFraction"); + hPrimaryCutFraction->Write("hPrimaryCutFraction"); + hWeakDecayCutFraction->Write("hWeakDecayCutFraction"); + hMaterialCutFraction->Write("hMaterialCutFraction"); + + /* cleanup */ + delete hPrimaryFraction; + delete hWeakDecayFraction; + delete hMaterialFraction; + delete hPrimaryScale; + delete hWeakDecayScale; + delete hMaterialScale; + delete hPrimaryCutIntegral; + delete hWeakDecayCutIntegral; + delete hMaterialCutIntegral; + delete hPrimaryCutFraction; + delete hWeakDecayCutFraction; + delete hMaterialCutFraction; + delete canvas; + for (Int_t iparam = 0; iparam < kNFitParams; iparam++) + delete hFitParamHisto[iparam]; + + /* close file */ + fileout->Close(); + + +} + +/**************************************************************/ + +//___________________________________________________________________________________ + +Float_t +TOFpid_histomin(TH1 *h) +{ + + for (Int_t ibin = 0; ibin < h->GetNbinsX(); ibin++) + if (h->GetBinContent(ibin + 1) > 0.) + return h->GetXaxis()->GetBinCenter(ibin + 1); + return kMaxInt; +} + +//___________________________________________________________________________________ + +Float_t +TOFpid_histomax(TH1 *h) +{ + + for (Int_t ibin = h->GetNbinsX(); ibin > 0; ibin--) + if (h->GetBinContent(ibin) > 0.) + return h->GetXaxis()->GetBinCenter(ibin); + return -kMaxInt; +} + +//___________________________________________________________________________________ + +TOFpid_checkneg(TH1 *h) +{ + + for (Int_t ibin = 0; ibin < h->GetNbinsX(); ibin++) + if (h->GetBinContent(ibin + 1) <= 0.) { + h->SetBinContent(ibin + 1, 1.e-300); + // h->SetBinError(ibin + 1, 0.1); + } +} + + +Double_t +DCAfit(TH1 *hData, TH1 *hPrimary, TH1 *hWeakDecay, TH1 *hMaterial, Double_t *param = NULL, Double_t *param_err = NULL, TCanvas *canvas = NULL) +{ + + /** ROOFIT ***/ + gSystem->Load("libRooFit"); + using namespace RooFit; + + /*** DEFINE FIT RANGE ***/ + + printf("***** FIT RANGE DEFINITION *****\n"); + + /* check material histogram to define min/max fit range */ + Double_t rangeMin = TMath::Max(dcaMin, TOFpid_histomin(hMaterial)); + Double_t rangeMax = TMath::Min(dcaMax, TOFpid_histomax(hMaterial)); + /* fix zeroes */ + TOFpid_checkneg(hMaterial); + + /* define range */ + RooRealVar x("x", "DCA_{xy}", 0., -5., 5., ""); + printf("FIT RANGE DEFINED: %f -> %f\n", dcaMin, dcaMax); + printf("********************************\n"); + + /*** DEFINE HISTOGRAM DATA ***/ + + /* define data to fit and background from input histogram */ + RooDataHist hdata("hdata", "hdata", x, hData); + RooDataHist hprimary("hprimary", "hprimary", x, hPrimary); + RooDataHist hweakdecay("hweakdecay", "hweakdecay", x, hWeakDecay); + RooDataHist hmaterial("hmaterial", "hmaterial", x, hMaterial); + + /*** DEFINE SHAPES ***/ + + RooHistPdf primary("primary", "primary", x, hprimary); + RooHistPdf weakdecay("weakdecay", "weakdecay", x, hweakdecay); + RooHistPdf material("material", "material", x, hmaterial); + + /*** DEFINE MODEL ***/ + + Double_t integral = hdata.sumEntries(); + RooRealVar nprimary("nprimary", "nprimary", 0.80 * integral, 0., integral); + RooRealVar nweakdecay("nweakdecay", "nweakdecay", 0.1 * integral, 0., integral); + RooRealVar nmaterial("nmaterial", "nmaterial", 0.1 * integral, 0., integral); + + RooAddPdf model("model", "model p.d.f.", RooArgList(primary, weakdecay, material), RooArgList(nprimary, nweakdecay, nmaterial)); + + /*** FIT ***/ + + if (canvas) canvas->cd(); + model.fitTo(hdata, Extended(kTRUE), SumW2Error(kFALSE)); + + /*** DRAW ***/ + + RooPlot *xframe = x.frame(); + hdata.plotOn(xframe, XErrorSize(0), DrawOption("PZ")); + model.plotOn(xframe, LineWidth(2), Precision(1.e-4)); + model.plotOn(xframe, Components(primary), LineWidth(2), LineColor(kRed), Precision(1.e-4)); + model.plotOn(xframe, Components(weakdecay), LineWidth(2), LineStyle(kDashed), LineColor(kCyan+1)); + model.plotOn(xframe, Components(material), LineWidth(2), LineStyle(kDashed), LineColor(kGreen+1)); + xframe->SetMinimum(0.1); + xframe->Draw(); + if (canvas) canvas->Update(); + + printf("*****************************\n"); + printf("***** FRACTIONS *****\n"); + printf("primary = %f +- %f\n", nprimary.getVal(), nprimary.getError()); + printf("weak-decay = %f +- %f\n", nweakdecay.getVal(), nweakdecay.getError()); + printf("material = %f +- %f\n", nmaterial.getVal(), nmaterial.getError()); + printf("******************\n"); + + /*** OUTPUT FIT PARAMS ***/ + + param[kIntegralCounts] = integral; + param_err[kIntegralCounts] = sqrt(integral); + param[kPrimaryCounts] = nprimary.getVal(); + param_err[kPrimaryCounts] = nprimary.getError(); + param[kWeakDecayCounts] = nweakdecay.getVal(); + param_err[kWeakDecayCounts] = nweakdecay.getError(); + param[kMaterialCounts] = nmaterial.getVal(); + param_err[kMaterialCounts] = nmaterial.getError(); + + return; + +} + +enum EFitFunc_t { + kExpo, + kInverseExpo, + kPowerLaw, + kInversePowerLaw, + kExpoPowerLaw +}; + +DCAdeltafeed_param() +{ +#if 0 + DCAdeltafeed_param(2, 0, "WeakDecayCutFraction", kExpo); + DCAdeltafeed_param(2, 1, "WeakDecayCutFraction", kExpo); + DCAdeltafeed_param(4, 0, "WeakDecayCutFraction", kExpo); + DCAdeltafeed_param(4, 1, "WeakDecayCutFraction", kExpo); + DCAdeltafeed_param(2, 0, "MaterialCutFraction", kPowerLaw); + DCAdeltafeed_param(2, 1, "MaterialCutFraction", kPowerLaw); + DCAdeltafeed_param(4, 0, "MaterialCutFraction", kPowerLaw); + DCAdeltafeed_param(4, 1, "MaterialCutFraction", kPowerLaw); +#endif + DCAdeltafeed_param_bothcharges(2, 0, "PrimaryCutFraction", kInverseExpo); + DCAdeltafeed_param_bothcharges(2, 1, "PrimaryCutFraction", kInverseExpo); + DCAdeltafeed_param_bothcharges(4, 0, "PrimaryCutFraction", kInverseExpo); + DCAdeltafeed_param_bothcharges(4, 1, "PrimaryCutFraction", kInverseExpo); +} + +DCAdeltafeed_param_bothcharges(Int_t ipart, Int_t icharge, const Char_t *name, Int_t fitFunc) +{ + + TVirtualFitter::SetMaxIterations(1000000); + + /* load HistoUtils */ + gROOT->LoadMacro("HistoUtils.C"); + + Char_t outfilename[1024]; + TH1D *hDeltaFeed_mb[kNCharges]; + TH1D *hDeltaFeed_cent[kNCharges][NcentralityBins]; + for (Int_t iicharge = 0; iicharge < kNCharges; iicharge++) { + + /* get minimum-bias results */ + sprintf(outfilename, "DCAdeltafeed_cent0090_%s_%s.root", AliPID::ParticleName(ipart), chargeName[iicharge]); + TFile *filein = TFile::Open(outfilename); + hDeltaFeed_mb[iicharge] = (TH1D *)filein->Get(Form("PostAnalysis/h%s", name)); + if (!hDeltaFeed_mb[iicharge]) { + printf("cannot find PostAnalysis/h%s in %s\n", name, outfilename); + return; + } + + /* get centrality-binned results */ + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + sprintf(outfilename, "DCAdeltafeed_cent%02d%02d_%s_%s.root", centralityBin[icent], centralityBin[icent + 1], AliPID::ParticleName(ipart), chargeName[iicharge]); + filein = TFile::Open(outfilename); + if (!filein || !filein->IsOpen()) continue; + hDeltaFeed_cent[iicharge][icent] = (TH1D *)filein->Get(Form("PostAnalysis/h%s", name)); + if (!hDeltaFeed_cent[iicharge][icent]) { + printf("cannot find PostAnalysis/h%s in %s\n", name, outfilename); + return; + } + } + } + + /* define delta feed-down function */ + switch (fitFunc) { + case kExpo: + printf("expo function selected\n"); + TF1 *fDeltaFeed = new TF1("fDeltaFeed_expo", "[0] * ([1] + [2] * TMath::Exp([3] * x))", 0.5, 5.); + fDeltaFeed->SetParameter(1, 0.01); + fDeltaFeed->SetParLimits(1, 0., 0.1); + fDeltaFeed->SetParameter(2, 0.1); + fDeltaFeed->SetParameter(3, -1.); + break; + case kInverseExpo: + printf("inverse-expo function selected\n"); + TF1 *fDeltaFeed = new TF1("fDeltaFeed_expo", "[0] * ([1] + [2] * TMath::Exp([3] * x))", 0.5, 5.); + fDeltaFeed->SetParameter(1, 1.); + fDeltaFeed->SetParLimits(1, 0.9, 1.0); + fDeltaFeed->SetParameter(2, -0.1); + fDeltaFeed->SetParLimits(2, -1., 0.); + fDeltaFeed->SetParameter(3, -1.); + break; + case kPowerLaw: + printf("powerlaw function selected\n"); + TF1 *fDeltaFeed = new TF1("fDeltaFeed_powerlaw", "[0] * ([1] + [2] * TMath::Power(x, [3]))", 0.5, 5.); + fDeltaFeed->SetParameter(1, 0.01); + fDeltaFeed->SetParLimits(1, 0., 0.1); + fDeltaFeed->SetParameter(2, 0.1); + fDeltaFeed->SetParameter(3, -1.); + break; + case kInversePowerLaw: + printf("inverse-powerlaw function selected\n"); + TF1 *fDeltaFeed = new TF1("fDeltaFeed_powerlaw", "[0] * ([1] + [2] * TMath::Power(x, [3]) + [4] * x)", 0.5, 5.); + fDeltaFeed->SetParameter(1, 1.); + fDeltaFeed->SetParLimits(1, 0.9, 1.); + fDeltaFeed->SetParameter(2, -0.1); + fDeltaFeed->SetParameter(3, -1.); + fDeltaFeed->SetParameter(4, 0.); + fDeltaFeed->SetParLimits(4, 0., 1.) + break; + case kExpoPowerLaw: + printf("expo+powerlaw function selected\n"); + TF1 *fDeltaFeed = new TF1("fDeltaFeed_expopowerlaw", "[0] * ([1] + [2] * TMath::Exp([3] * x) + [4] * TMath::Exp([5] * x))", 0.5, 5.); + + fDeltaFeed->SetParameter(1, 0.95); + fDeltaFeed->SetParLimits(1, 0.9, 1.); + fDeltaFeed->SetParameter(2, -0.1); + fDeltaFeed->SetParLimits(2, -1000., 0.); + fDeltaFeed->SetParameter(3, -1.); + fDeltaFeed->SetParameter(4, -100.); + fDeltaFeed->SetParLimits(4, -100., 0.); + fDeltaFeed->SetParameter(5, -20.); + fDeltaFeed->SetParLimits(5, -100., 10.); + break; + default: + printf("fit function not defined\n"); + return; + break; + } + fDeltaFeed->FixParameter(0, 1.); + + /* output */ + TFile *fileout = TFile::Open(Form("DCAdeltafeed_param_%s_%s_%s.root", name, AliPID::ParticleName(ipart), chargeName[icharge]), "RECREATE"); + + /* extra-material function */ + TF1 *fExtraMaterial = new TF1("fExtraMaterial", "1. + [0] * TMath::Exp([1] * x)", 0., 5.); + fExtraMaterial->SetParameter(0, 0.1); + fExtraMaterial->SetParameter(1, -0.5); + + /* loop over centrality bins */ + for (Int_t icent = -1; icent < NcentralityBins; icent++) { + + printf(" icent = %d\n", icent); + + /* fit material from proton-antiproton ratio and remove it */ + if (ipart == AliPID::kProton) { + printf("fitting extra-material for positive protons\n"); + if (icent == -1) { + TH1D *hr = new TH1D(*hDeltaFeed_mb[kPositive]); + hr->Divide(hDeltaFeed_mb[kNegative]); + hr->Fit(fExtraMaterial, "R", "", fitPtMin[ipart], fitPtMax[ipart]); + hDeltaFeed_mb[kPositive]->Divide(fExtraMaterial); + } + else { + TH1D *hr = new TH1D(*hDeltaFeed_cent[kPositive][icent]); + hr->Divide(hDeltaFeed_cent[kNegative][icent]); + hr->Fit(fExtraMaterial, "R", "", fitPtMin[ipart], fitPtMax[ipart]); + hDeltaFeed_cent[kPositive][icent]->Divide(fExtraMaterial); + } + } + + /* build graph with both charges */ + TGraphErrors *gDeltaFeed = new TGraphErrors(); + Int_t npoints = 0; + Double_t pt, pte, val, vale; + for (Int_t iicharge = 0; iicharge < kNCharges; iicharge++) { + for (Int_t ipt = 0; ipt < NptBins; ipt++) { + if (icent == -1) { + if (hDeltaFeed_mb[iicharge]->GetBinError(ipt + 1) == 0.) + continue; + pt = hDeltaFeed_mb[iicharge]->GetBinCenter(ipt + 1); + pte = 0.5 * hDeltaFeed_mb[iicharge]->GetBinWidth(ipt + 1); + val = hDeltaFeed_mb[iicharge]->GetBinContent(ipt + 1); + vale = hDeltaFeed_mb[iicharge]->GetBinError(ipt + 1); + gDeltaFeed->SetPoint(npoints, pt, val); + gDeltaFeed->SetPointError(npoints, pte, vale); + npoints++; + } + else { + if (hDeltaFeed_cent[iicharge][icent]->GetBinError(ipt + 1) == 0.) + continue; + pt = hDeltaFeed_cent[iicharge][icent]->GetBinCenter(ipt + 1); + pte = 0.5 * hDeltaFeed_cent[iicharge][icent]->GetBinWidth(ipt + 1); + val = hDeltaFeed_cent[iicharge][icent]->GetBinContent(ipt + 1); + vale = hDeltaFeed_cent[iicharge][icent]->GetBinError(ipt + 1); + gDeltaFeed->SetPoint(npoints, pt, val); + gDeltaFeed->SetPointError(npoints, pte, vale); + npoints++; + } + } + } + + /* fit graph */ + Int_t fitres = -1; + fitres = gDeltaFeed->Fit(fDeltaFeed, "R", "", 0.5, 2.0); + if (fitres != 0) { + fDeltaFeed->SetParLimits(1, 0.9, 1.0); + fDeltaFeed->SetParameter(2, -0.1); + fDeltaFeed->SetParLimits(2, -1., 0.); + fDeltaFeed->SetParameter(3, -1.); + } + fitres = -1; + while(fitres != 0) + fitres = gDeltaFeed->Fit(fDeltaFeed, "R", "", fitPtMin[ipart], fitPtMax[ipart]); + + gDeltaFeed->Draw("ap*"); + fDeltaFeed->Draw("same"); + gPad->Update(); + + printf("done part = %d, charge = %d, cent = %d\n", ipart, icharge, icent); + + /* build fit profile */ + TProfile *pDeltaFeed = new TProfile("pDeltaFeed", "", NptBins, ptBin); + HistoUtils_Function2Profile(fDeltaFeed, pDeltaFeed); + + /* put material back */ + if (ipart == AliPID::kProton && icharge == kPositive) { + if (icent == -1) { + hDeltaFeed_mb[kPositive]->Multiply(fExtraMaterial); + pDeltaFeed->Multiply(fExtraMaterial); + } + else { + hDeltaFeed_cent[kPositive][icent]->Multiply(fExtraMaterial); + pDeltaFeed->Multiply(fExtraMaterial); + } + } + + /* write */ + fileout->cd(); + if (icent == -1) { + hDeltaFeed_mb[icharge]->Write(Form("hDeltaFeed_MB")); + fDeltaFeed->Write(Form("fDeltaFeed_MB")); + pDeltaFeed->Write(Form("pDeltaFeed_MB")); + fExtraMaterial->Write(Form("fExtraMaterial_MB")); + } + else { + hDeltaFeed_cent[icharge][icent]->Write(Form("hDeltaFeed_cent%d", icent)); + fDeltaFeed->Write(Form("fDeltaFeed_cent%d", icent)); + pDeltaFeed->Write(Form("pDeltaFeed_cent%d", icent)); + fExtraMaterial->Write(Form("fExtraMaterial_cent%d", icent)); + } + } + + fileout->Close(); +} + +DCAdeltafeed_param(Int_t ipart, Int_t icharge, const Char_t *name, Int_t fitFunc) +{ + + TVirtualFitter::SetMaxIterations(1000000); + + /* load HistoUtils */ + gROOT->LoadMacro("HistoUtils.C"); + + /* get minimum-bias results */ + Char_t outfilename[1024]; + sprintf(outfilename, "DCAdeltafeed_cent0090_%s_%s.root", AliPID::ParticleName(ipart), chargeName[icharge]); + TFile *filein = TFile::Open(outfilename); + TH1D *hDeltaFeed_mb = (TH1D *)filein->Get(Form("PostAnalysis/h%s", name)); + if (!hDeltaFeed_mb) { + printf("cannot find PostAnalysis/h%s in %s\n", name, outfilename); + return; + } + + /* get centrality-binned results */ + TH1D *hDeltaFeed_cent[NcentralityBins]; + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + sprintf(outfilename, "DCAdeltafeed_cent%02d%02d_%s_%s.root", centralityBin[icent], centralityBin[icent + 1], AliPID::ParticleName(ipart), chargeName[icharge]); + filein = TFile::Open(outfilename); + if (!filein || !filein->IsOpen()) continue; + hDeltaFeed_cent[icent] = (TH1D *)filein->Get(Form("PostAnalysis/h%s", name)); + if (!hDeltaFeed_cent[icent]) { + printf("cannot find PostAnalysis/h%s in %s\n", name, outfilename); + return; + } + } + + /* define delta feed-down function */ + switch (fitFunc) { + case kExpo: + printf("expo function selected\n"); + TF1 *fDeltaFeed = new TF1("fDeltaFeed_expo", "[0] * ([1] + [2] * TMath::Exp([3] * x))", 0.5, 5.); + fDeltaFeed->SetParameter(1, 0.01); + fDeltaFeed->SetParLimits(1, 0., 0.1); + fDeltaFeed->SetParameter(2, 0.1); + fDeltaFeed->SetParameter(3, -1.); + break; + case kInverseExpo: + printf("inverse-expo function selected\n"); + TF1 *fDeltaFeed = new TF1("fDeltaFeed_expo", "[0] * ([1] + [2] * TMath::Exp([3] * x))", 0.5, 5.); + fDeltaFeed->SetParameter(1, 1.); + fDeltaFeed->SetParLimits(1, 0.9, 1.0); + fDeltaFeed->SetParameter(2, -0.1); + fDeltaFeed->SetParameter(3, -1.); + break; + case kPowerLaw: + printf("powerlaw function selected\n"); + TF1 *fDeltaFeed = new TF1("fDeltaFeed_powerlaw", "[0] * ([1] + [2] * TMath::Power(x, [3]))", 0.5, 5.); + fDeltaFeed->SetParameter(1, 0.01); + fDeltaFeed->SetParLimits(1, 0., 0.1); + fDeltaFeed->SetParameter(2, 0.1); + fDeltaFeed->SetParameter(3, -1.); + break; + case kInversePowerLaw: + printf("inverse-powerlaw function selected\n"); + TF1 *fDeltaFeed = new TF1("fDeltaFeed_powerlaw", "[0] * ([1] + [2] * TMath::Power(x, [3]) + [4] * x)", 0.5, 5.); + fDeltaFeed->SetParameter(1, 1.); + fDeltaFeed->SetParLimits(1, 0.9, 1.); + fDeltaFeed->SetParameter(2, -0.1); + fDeltaFeed->SetParameter(3, -1.); + fDeltaFeed->SetParameter(4, 0.); + fDeltaFeed->SetParLimits(4, 0., 1.) + break; + case kExpoPowerLaw: + printf("expo+powerlaw function selected\n"); + // TF1 *fDeltaFeed = new TF1("fDeltaFeed_expopowerlaw", "[0] * ([1] + [2] * TMath::Exp([3] * x) + [4] * TMath::Exp([5] * x))", 0.5, 5.); + TF1 *fDeltaFeed = new TF1("fDeltaFeed_expopowerlaw", "[0] * ([1] + [2] * TMath::Exp([3] * x) * TMath::Exp([5] / x))", 0.5, 5.); + + fDeltaFeed->SetParameter(1, 0.95); + fDeltaFeed->SetParLimits(1, 0.9, 1.); + fDeltaFeed->SetParameter(2, -0.1); + fDeltaFeed->SetParLimits(2, -1000., 0.); + fDeltaFeed->SetParameter(3, -1.); + fDeltaFeed->SetParameter(4, -100.); + fDeltaFeed->SetParLimits(4, -100., 0.); + fDeltaFeed->SetParameter(5, -20.); + fDeltaFeed->SetParLimits(5, -100., 10.); + break; + default: + printf("fit function not defined\n"); + return; + break; + } + fDeltaFeed->FixParameter(0, 1.); + + /* output */ + TFile *fileout = TFile::Open(Form("DCAdeltafeed_param_%s_%s_%s.root", name, AliPID::ParticleName(ipart), chargeName[icharge]), "RECREATE"); + + /* fit minimum-bias */ + TCanvas *cMinimumBias = new TCanvas("cMinimumBias"); + if (fitFunc == kExpoPowerLaw) { + fDeltaFeed->FixParameter(4, 0.); + hDeltaFeed_mb->Fit(fDeltaFeed, "IMRE", "", 1.0, 3.0); + fDeltaFeed->FixParameter(1, fDeltaFeed->GetParameter(1)); + fDeltaFeed->FixParameter(2, fDeltaFeed->GetParameter(2)); + fDeltaFeed->FixParameter(3, fDeltaFeed->GetParameter(3)); + fDeltaFeed->ReleaseParameter(4); + hDeltaFeed_mb->Fit(fDeltaFeed, "IMRE", "", 0.5, 3.0); + } + else { + hDeltaFeed_mb->Fit(fDeltaFeed, "IMRE", "", 0.5, 3.0); + } + cMinimumBias->SetLogy(); + + /* build fit profile */ + TProfile *pDeltaFeed = new TProfile("pDeltaFeed", "", NptBins, ptBin); + HistoUtils_Function2Profile(fDeltaFeed, pDeltaFeed); + + /* save MB params */ + Double_t parMB[100]; + for (Int_t ipar = 0; ipar < fDeltaFeed->GetNpar(); ipar++) + parMB[ipar] = fDeltaFeed->GetParameter(ipar); + + /* write */ + fileout->cd(); + hDeltaFeed_mb->Write("hDeltaFeed_mb"); + fDeltaFeed->Write("fDeltaFeed_mb"); + pDeltaFeed->Write("pDeltaFeed_mb"); + + /* fix pt-depencence and release scale factor + to fit centrality bins */ + TCanvas *cCentralityDependence = new TCanvas("cCentralityDependence"); + TH1D *hCentDep = new TH1D("hCentDep", "", NcentralityBins, centralityBin); + //fDeltaFeed->ReleaseParameter(0); + // for (Int_t ipar = 1; ipar < fDeltaFeed->GetNpar(); ipar++) + // fDeltaFeed->FixParameter(ipar, fDeltaFeed->GetParameter(ipar)); + //fDeltaFeed->FixParameter(1, fDeltaFeed->GetParameter(1)); + TProfile *pDeltaFeed_cent[NcentralityBins]; = new TProfile("pDeltaFeed", "", NptBins, ptBin); + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + if (!hDeltaFeed_cent[icent]) continue; + + /* restore MB parameters */ + for (Int_t ipar = 0; ipar < fDeltaFeed->GetNpar(); ipar++) + fDeltaFeed->SetParameter(ipar, parMB[ipar]); + + if (fitFunc == kExpoPowerLaw) { + fDeltaFeed->FixParameter(4, 0.); + hDeltaFeed_mb->Fit(fDeltaFeed, "IMRE", "", 1.0, 3.0); + fDeltaFeed->FixParameter(1, fDeltaFeed->GetParameter(1)); + fDeltaFeed->FixParameter(2, fDeltaFeed->GetParameter(2)); + fDeltaFeed->FixParameter(3, fDeltaFeed->GetParameter(3)); + fDeltaFeed->ReleaseParameter(4); + hDeltaFeed_cent[icent]->Fit(fDeltaFeed, "IMRE", "", 0.5, 3.0); + } + else { + hDeltaFeed_cent[icent]->Fit(fDeltaFeed, "IMRE", "", 0.5, 3.0); + } + + pDeltaFeed_cent[icent] = new TProfile(Form("pDeltaFeed_cent%d", icent), "", NptBins, ptBin); + HistoUtils_Function2Profile(fDeltaFeed, pDeltaFeed_cent[icent]); + hCentDep->SetBinContent(icent + 1, fDeltaFeed->GetParameter(0.)); + hCentDep->SetBinError(icent + 1, fDeltaFeed->GetParError(0.)); + + /* write */ + fileout->cd(); + hDeltaFeed_cent[icent]->Write(Form("hDeltaFeed_cent%d", icent)); + fDeltaFeed->Write(Form("fDeltaFeed_cent%d", icent)); + pDeltaFeed_cent[icent]->Write(Form("pDeltaFeed_cent%d", icent)); + + } + + /* fit centrality dependence */ + TF1 *fCentDep = (TF1 *)gROOT->GetFunction("pol3"); + // hCentDep->Fit(fCentDep); + + /* build fit profile */ + TProfile *pCentDep = new TProfile("pCentDep", "", NcentralityBins, centralityBin); + HistoUtils_Function2Profile(fCentDep, pCentDep); + + /* write */ + fileout->cd(); + hCentDep->Write("hCentDep"); + fCentDep->Write("fCentDep"); + pCentDep->Write("pCentDep"); + fileout->Close(); + +} + +DCA_primaryFraction(const Char_t *destdir) +{ + + Int_t marker[2] = {20, 21}; + Int_t color[AliPID::kSPECIES] = {1, 1, 4, 8, 2}; + Char_t *partLatex[AliPID::kSPECIES][2] = { + "", "", "", "", "#pi^{+}", "#pi^{-}", "K^{+}", "K^{-}", "p", "#bar{p}" + }; + + TFile *fileout = TFile::Open("TOF_primaryFraction.root", "RECREATE"); + + TProfile *pFrac; + TH1D *hFrac = new TH1D("hFrac", "", NptBins, ptBin); + Char_t title[1024]; + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) { + if (ipart == 3) continue; + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + TFile *filein = TFile::Open(Form("%s/DCAdeltafeed_param_PrimaryCutFraction_%s_%s.root", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + for (Int_t icent = -1; icent < NcentralityBins; icent++) { + if (icent == -1) + pFrac = (TProfile *)filein->Get(Form("pDeltaFeed_MB")); + else + pFrac = (TProfile *)filein->Get(Form("pDeltaFeed_cent%d", icent)); + /* copy profile in TH1D */ + for (Int_t ipt = 0; ipt < NptBins; ipt++) { + hFrac->SetBinContent(ipt + 1, pFrac->GetBinContent(ipt + 1)); + hFrac->SetBinError(ipt + 1, pFrac->GetBinError(ipt + 1)); + } + if (icent == -1) + sprintf(title, "%s (MB);p_{T} (GeV/c);fraction of primary particle;", partLatex[ipart][icharge]); + else + sprintf(title, "%s (%d-%d%%);p_{T} (GeV/c);fraction of primary particle;", partLatex[ipart][icharge], (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1]); + hFrac->SetMarkerStyle(marker[icharge]); + hFrac->SetMarkerColor(color[ipart]); + hFrac->SetTitle(title); + if (icent == -1) + hFrac->SetName(Form("hPrimaryFrac_MB_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + else + hFrac->SetName(Form("hPrimaryFrac_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + fileout->cd(); + hFrac->Write(); + } + } + } + + fileout->Close(); + +} diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCA.sh b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCA.sh new file mode 100755 index 00000000000..e57c5f2e8ea --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCA.sh @@ -0,0 +1,9 @@ +#! /bin/bash + +if [ "$1" == "" ]; then + echo "argument needed" + exit 1 +fi +echo "launching DCAdata on $1 in background" +aliroot -b -q "DCA.C(\"$1\", 0)" &> DCA.$1.log & +echo "DCAdata started" \ No newline at end of file diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCAAnalysis.sh b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCAAnalysis.sh new file mode 100755 index 00000000000..a51f92f7c60 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCAAnalysis.sh @@ -0,0 +1,10 @@ +#! /bin/bash + +if [ "$2" == "" ]; then + echo "two arguments needed" + exit 1 +fi + +aliroot -b -q MakeLibs.C +./DCAdata_std.sh $1 +./DCAmc_std.sh $2 diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCAdata_std.C b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCAdata_std.C new file mode 100644 index 00000000000..9204f370288 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCAdata_std.C @@ -0,0 +1,11 @@ +DCAdata_std(const Char_t *filename) +{ + + gROOT->LoadMacro("MakeLibs.C"); + gROOT->LoadMacro("DCA.C"); + MakeLibs(); + + /* start DCAdata */ + DCAdata(filename); + +} diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCAdata_std.sh b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCAdata_std.sh new file mode 100755 index 00000000000..9a8ebefda4d --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCAdata_std.sh @@ -0,0 +1,9 @@ +#! /bin/bash + +if [ "$1" == "" ]; then + echo "argument needed" + exit 1 +fi +echo "launching DCAdata_std on $1 in background" +aliroot -b -q "DCAdata_std.C(\"$1\")" &> DCAdata.$1.log & +echo "DCAdata_std started" \ No newline at end of file diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCAmc_std.C b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCAmc_std.C new file mode 100644 index 00000000000..f37ccf724fc --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCAmc_std.C @@ -0,0 +1,11 @@ +DCAmc_std(const Char_t *filename) +{ + + gROOT->LoadMacro("MakeLibs.C"); + gROOT->LoadMacro("DCA.C"); + MakeLibs(); + + /* start DCAmc */ + DCAmc(filename); + +} diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCAmc_std.sh b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCAmc_std.sh new file mode 100755 index 00000000000..cfb2778c1be --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/DCAmc_std.sh @@ -0,0 +1,9 @@ +#! /bin/bash + +if [ "$1" == "" ]; then + echo "argument needed" + exit 1 +fi +echo "launching DCAmc_std on $1 in background" +aliroot -b -q "DCAmc_std.C(\"$1\")" &> DCAmc.$1.log & +echo "DCAmc_std started" \ No newline at end of file diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/EfficiencyAnalysis.sh b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/EfficiencyAnalysis.sh new file mode 100755 index 00000000000..fce6584437c --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/EfficiencyAnalysis.sh @@ -0,0 +1,12 @@ +#! /bin/bash + +if [ "$2" == "" ]; then + echo "two arguments needed" + exit 1 +fi + +aliroot -b -q MakeLibs.C +./TOFmatchEff.sh $1 +./TOFmatchEff.sh $2 +./TOFmatchMC.sh $2 +./TrackingEff.sh $2 diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/FinalSpectra.C b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/FinalSpectra.C new file mode 100644 index 00000000000..cbcf42c5742 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/FinalSpectra.C @@ -0,0 +1,318 @@ +#include "CommonDefs.C" + +/**************************************************************/ +Char_t *partChargeName[AliPID::kSPECIES][2] = { + "", "", "", "", "#pi^{+}", "#pi^{-}", "K^{+}", "K^{-}", "p", "#bar{p}" +}; + /**************************************************************/ + +FinalSpectra() +{ + + doFinalSpectra(1., "TOF_rawSpectra.root", "TOF_matchingEfficiency.root", "TOF_trackingEfficiency.root", "TOF_primaryFraction.root", "TOF_electronCorrection.root", "TOF_finalSpectra.root"); + doFinalSpectra(1., "TOF_rawSpectra.root", "TOF_matchingEfficiency.root", "TOF_trackingEfficiency.root", "TOF_primaryFraction.root", "TOF_electronCorrection.root", "TOF_finalSpectra_centCorr.root", kFALSE); + + doFinalRatios("TOF_finalSpectra.root", "TOF_finalRatios.root"); + + FinalSpectra_mismatchCorrected(); +} + +FinalSpectra_mismatchCorrected() +{ + doFinalSpectra(1., "TOF_rawSpectra_mismatchCorrected.root", "TOF_matchingEfficiency_mismatchCorrected.root", "TOF_trackingEfficiency.root", "TOF_primaryFraction.root", "TOF_electronCorrection.root", "TOF_finalSpectra_mismatchCorrected.root"); + doFinalSpectra(1., "TOF_rawSpectra_mismatchCorrected.root", "TOF_matchingEfficiency_mismatchCorrected.root", "TOF_trackingEfficiency.root", "TOF_primaryFraction.root", "TOF_electronCorrection.root", "TOF_finalSpectra_mismatchCorrected_centCorr.root", kFALSE); + + doFinalRatios("TOF_finalSpectra_mismatchCorrected.root", "TOF_finalRatios_mismatchCorrected.root"); +} + +doFinalSpectra(Double_t scaleFact = 1., const Char_t *rawfilename = "TOF_rawSpectra.root", const Char_t *matchfilename = "TOF_matchingEfficiency.root", const Char_t *trackfilename = "TOF_trackingEfficiency.root", const Char_t *primaryfilename = "TOF_primaryFraction.root", const Char_t *electronfilename = "TOF_electronCorrection.root", const Char_t *outputfilename = "TOF_finalSpectra.root", Bool_t useMB = kTRUE) + { + + Int_t marker[2] = {20, 25}; + Int_t color[AliPID::kSPECIES] = {1, 1, 4, 8, 2}; + + TFile *rawfile = TFile::Open(rawfilename); + TFile *matchfile = TFile::Open(matchfilename); + TFile *trackfile = TFile::Open(trackfilename); + TFile *primaryfile = TFile::Open(primaryfilename); + TFile *electronfile = TFile::Open(electronfilename); + + TFile *fileout = TFile::Open(outputfilename, "RECREATE"); + TH1D *hRaw, *hMatch, *hTrack, *hPrim, *hElectron; + TH1D *hSpectrum[NcentralityBins+1][5][2]; + Char_t title[1024]; + for (Int_t icent = -1; icent < NcentralityBins; icent++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) { + if (icent == -1) + hRaw = (TH1D *)rawfile->Get(Form("hRaw_MB_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + else + hRaw = (TH1D *)rawfile->Get(Form("hRaw_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + if (!hRaw) { + printf("cannot find %s in %s\n", Form("hRaw_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge]), rawfilename); + continue; + } + if (0) + hMatch = (TH1D *)matchfile->Get(Form("hMatchEff_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + else + hMatch = (TH1D *)matchfile->Get(Form("hMatchEff_MB_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + if (!hMatch) { + printf("cannot find %s in %s\n", Form("hMatchEff_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge]), matchfilename); + continue; + } + if (0) + hTrack = (TH1D *)trackfile->Get(Form("hTrackingEff_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + else + hTrack = (TH1D *)trackfile->Get(Form("hTrackingEff_MB_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + if (!hTrack) { + printf("cannot find %s in %s\n", Form("hTrackingEff_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge]), trackfilename); + continue; + } + if (useMB || icent == -1) { + hPrim = (TH1D *)primaryfile->Get(Form("hPrimaryFrac_MB_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + if (ipart != 3 && !hPrim) { + printf("cannot find %s in %s\n", Form("hPrimaryFrac_MB_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge]), primaryfilename); + continue; + } + } + else { + hPrim = (TH1D *)primaryfile->Get(Form("hPrimaryFrac_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + if (ipart != 3 && !hPrim) { + printf("cannot find %s in %s\n", Form("hPrimaryFrac_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge]), primaryfilename); + continue; + } + } + hElectron = (TH1D *)electronfile->Get("hElectronCorr_average"); + if (!hElectron) { + printf("cannot find hElectronCorr_average in %s\n", electronfilename); + continue; + } + hRaw->Divide(hMatch); + hRaw->Divide(hTrack); + if (hPrim) hRaw->Multiply(hPrim); + if (ipart == 2) hRaw->Multiply(hElectron); + if (icent == -1) + sprintf(title, "%s (MB);p_{T} (GeV/c);#frac{d^{2}N}{dy dp_{T}} (c/GeV);", partChargeName[ipart][icharge]); + else + sprintf(title, "%s (%d-%d%%);p_{T} (GeV/c);#frac{d^{2}N}{dy dp_{T}} (c/GeV);", partChargeName[ipart][icharge], centralityBin[icent], centralityBin[icent + 1]); + if (icent == -1) + hRaw->SetName(Form("hFinal_MB_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + else + hRaw->SetName(Form("hFinal_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + hRaw->SetTitle(title); + hRaw->SetMarkerStyle(marker[icharge]); + hRaw->SetMarkerColor(color[ipart]); + fileout->cd(); + hRaw->Scale(scaleFact); + hRaw->Write(); + if (icent == -1) + hSpectrum[NcentralityBins][ipart][icharge] = hRaw; + else + hSpectrum[icent][ipart][icharge] = hRaw; + } + + TH1 *hRatioMB; + for (Int_t icent = 0; icent < NcentralityBins; icent++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) { + hRatioMB = (TH1 *)hSpectrum[icent][ipart][icharge]->Clone(Form("hRatioMB_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + hRatioMB->Divide(hRatioMB, hSpectrum[NcentralityBins][ipart][icharge], 1., 1., ""); + fileout->cd(); + hRatioMB->Write(); + } + + fileout->Close(); + + } + + +/**************************************************************/ + +doFinalRatios(const Char_t *filename = "TOF_finalSpectra.root", const Char_t *outputfilename = "TOF_finalRatios.root") +{ + + // printf("WARNING: skipping ratios\n"); + // return; + + Int_t marker[2] = {20, 25}; + Int_t color[AliPID::kSPECIES] = {1, 1, 4, 8, 2}; + + /* open data */ + TFile *filein = TFile::Open(filename); + /* get spectra */ + TH1D *hSpectrum[NcentralityBins+1][AliPID::kSPECIES][kNCharges]; + for (Int_t icent = 0; icent < NcentralityBins+1; icent++) { + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) { + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + if (icent == NcentralityBins) + hSpectrum[icent][ipart][icharge] = (TH1D *)filein->Get(Form("hFinal_MB_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + else + hSpectrum[icent][ipart][icharge] = (TH1D *)filein->Get(Form("hFinal_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + } + } + } + + /* output */ + TFile *fileout = TFile::Open(outputfilename, "RECREATE"); + + /* particle/anti-particle ratios */ + TH1D *hRatio; + TH1D *hPosNegRatio[NcentralityBins+1][5]; + for (Int_t icent = 0; icent < NcentralityBins+1; icent++) { + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) { + if (!hSpectrum[icent][ipart][kNegative] || + !hSpectrum[icent][ipart][kPositive]) continue; + hRatio = new TH1D(*hSpectrum[icent][ipart][kNegative]); + hRatio->Divide(hSpectrum[icent][ipart][kPositive]); + if (icent == NcentralityBins) { + hRatio->SetName(Form("hRatio_MB_%s_negative_%s_positive", AliPID::ParticleName(ipart), AliPID::ParticleName(ipart))); + hRatio->SetTitle(Form("%s/%s (MB);p_{T} (GeV/c);%s/%s;", partChargeName[ipart][kNegative], partChargeName[ipart][kPositive], partChargeName[ipart][kNegative], partChargeName[ipart][kPositive])); + } + else { + hRatio->SetName(Form("hRatio_cent%d_%s_negative_%s_positive", icent, AliPID::ParticleName(ipart), AliPID::ParticleName(ipart))); + hRatio->SetTitle(Form("%s/%s (%d-%d%%);p_{T} (GeV/c);%s/%s;", partChargeName[ipart][kNegative], partChargeName[ipart][kPositive], (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1], partChargeName[ipart][kNegative], partChargeName[ipart][kPositive])); + } + hRatio->SetMarkerStyle(20); + hRatio->SetMarkerColor(color[ipart]); + fileout->cd(); + hRatio->Write(); + hPosNegRatio[icent][ipart] = hRatio; + } + } + + TH1 *hRatioMB; + for (Int_t icent = 0; icent < NcentralityBins; icent++) + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) { + hRatioMB = (TH1 *)hPosNegRatio[icent][ipart]->Clone(Form("hDoubleRatioMB_cent%d_%s_negative_%s_positive", icent, AliPID::ParticleName(ipart), AliPID::ParticleName(ipart))); + hRatioMB->Divide(hRatioMB, hPosNegRatio[NcentralityBins][ipart], 1., 1., ""); + fileout->cd(); + hRatioMB->Write(); + } + + /* kaon/pion ratios */ + TH1D *hSum1, *hSum2; + TH1D *hKaToPi[NcentralityBins+1][3]; + for (Int_t icent = 0; icent < NcentralityBins+1; icent++) { + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + if (!hSpectrum[icent][AliPID::kKaon][icharge] || + !hSpectrum[icent][AliPID::kPion][icharge]) continue; + hRatio = new TH1D(*hSpectrum[icent][AliPID::kKaon][icharge]); + hRatio->Divide(hSpectrum[icent][AliPID::kPion][icharge]); + if (icent == NcentralityBins) { + hRatio->SetName(Form("hRatio_MB_kaon_%s_pion_%s", chargeName[icharge], chargeName[icharge])); + hRatio->SetTitle(Form("%s/%s (MB);p_{T} (GeV/c);%s/%s;", partChargeName[AliPID::kKaon][icharge], partChargeName[AliPID::kPion][icharge], partChargeName[AliPID::kKaon][icharge], partChargeName[AliPID::kPion][icharge])); + } + else { + hRatio->SetName(Form("hRatio_cent%d_kaon_%s_pion_%s", icent, chargeName[icharge], chargeName[icharge])); + hRatio->SetTitle(Form("%s/%s (%d-%d%%);p_{T} (GeV/c);%s/%s;", partChargeName[AliPID::kKaon][icharge], partChargeName[AliPID::kPion][icharge], (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1], partChargeName[AliPID::kKaon][icharge], partChargeName[AliPID::kPion][icharge])); + } + hRatio->SetMarkerStyle(marker[icharge]); + hRatio->SetMarkerColor(color[AliPID::kKaon]); + fileout->cd(); + hRatio->Write(); + hKaToPi[icent][icharge] = hRatio; + } + if (!hSpectrum[icent][AliPID::kKaon][kPositive] || + !hSpectrum[icent][AliPID::kKaon][kNegative] || + !hSpectrum[icent][AliPID::kPion][kPositive] || + !hSpectrum[icent][AliPID::kPion][kNegative]) continue; + hSum1 = new TH1D(*hSpectrum[icent][AliPID::kKaon][kPositive]); + hSum1->Add(hSpectrum[icent][AliPID::kKaon][kNegative]); + hSum2 = new TH1D(*hSpectrum[icent][AliPID::kPion][kPositive]); + hSum2->Add(hSpectrum[icent][AliPID::kPion][kNegative]); + hRatio = new TH1D(*hSum1); + hRatio->Divide(hSum2); + if (icent == NcentralityBins) { + hRatio->SetName(Form("hRatio_MB_kaon_pion")); + hRatio->SetTitle(Form("(%s+%s)/(%s+%s) (MB);p_{T} (GeV/c);(%s+%s)/(%s+%s);", partChargeName[AliPID::kKaon][kPositive], partChargeName[AliPID::kKaon][kNegative], partChargeName[AliPID::kPion][kPositive], partChargeName[AliPID::kPion][kNegative], partChargeName[AliPID::kKaon][kPositive], partChargeName[AliPID::kKaon][kNegative], partChargeName[AliPID::kPion][kPositive], partChargeName[AliPID::kPion][kNegative])); + } + else { + hRatio->SetName(Form("hRatio_cent%d_kaon_pion", icent)); + hRatio->SetTitle(Form("(%s+%s)/(%s+%s) (%d-%d%%);p_{T} (GeV/c);(%s+%s)/(%s+%s);", partChargeName[AliPID::kKaon][kPositive], partChargeName[AliPID::kKaon][kNegative], partChargeName[AliPID::kPion][kPositive], partChargeName[AliPID::kPion][kNegative], (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1], partChargeName[AliPID::kKaon][kPositive], partChargeName[AliPID::kKaon][kNegative], partChargeName[AliPID::kPion][kPositive], partChargeName[AliPID::kPion][kNegative])); + } + hRatio->SetMarkerStyle(20); + hRatio->SetMarkerColor(color[AliPID::kKaon]); + fileout->cd(); + hRatio->Write(); + hKaToPi[icent][2] = hRatio; + } + + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + for (Int_t icharge = 0; icharge < 2; icharge++) { + hRatioMB = (TH1 *)hKaToPi[icent][icharge]->Clone(Form("hDoubleRatioMB_cent%d_kaon_%s_pion_%s", icent, chargeName[icharge], chargeName[icharge])); + hRatioMB->Divide(hRatioMB, hKaToPi[NcentralityBins][icharge], 1., 1., ""); + fileout->cd(); + hRatioMB->Write(); + } + hRatioMB = (TH1 *)hKaToPi[icent][2]->Clone(Form("hDoubleRatioMB_cent%d_kaon_pion", icent)); + hRatioMB->Divide(hRatioMB, hKaToPi[NcentralityBins][2], 1., 1., ""); + fileout->cd(); + hRatioMB->Write(); + } + + + /* proton/pion ratios */ + TH1D *hSum1, *hSum2; + TH1D *hPrToPi[NcentralityBins+1][3]; + for (Int_t icent = 0; icent < NcentralityBins+1; icent++) { + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + if (!hSpectrum[icent][AliPID::kProton][icharge] || + !hSpectrum[icent][AliPID::kPion][icharge]) continue; + hRatio = new TH1D(*hSpectrum[icent][AliPID::kProton][icharge]); + hRatio->Divide(hSpectrum[icent][AliPID::kPion][icharge]); + if (icent == NcentralityBins) { + hRatio->SetName(Form("hRatio_MB_proton_%s_pion_%s", chargeName[icharge], chargeName[icharge])); + hRatio->SetTitle(Form("%s/%s (MB);p_{T} (GeV/c);%s/%s;", partChargeName[AliPID::kProton][icharge], partChargeName[AliPID::kPion][icharge], partChargeName[AliPID::kProton][icharge], partChargeName[AliPID::kPion][icharge])); + } + else { + hRatio->SetName(Form("hRatio_cent%d_proton_%s_pion_%s", icent, chargeName[icharge], chargeName[icharge])); + hRatio->SetTitle(Form("%s/%s (%d-%d%%);p_{T} (GeV/c);%s/%s;", partChargeName[AliPID::kProton][icharge], partChargeName[AliPID::kPion][icharge], (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1], partChargeName[AliPID::kProton][icharge], partChargeName[AliPID::kPion][icharge])); + } + hRatio->SetMarkerStyle(marker[icharge]); + hRatio->SetMarkerColor(color[AliPID::kProton]); + fileout->cd(); + hRatio->Write(); + hPrToPi[icent][icharge] = hRatio; + } + if (!hSpectrum[icent][AliPID::kProton][kPositive] || + !hSpectrum[icent][AliPID::kProton][kNegative] || + !hSpectrum[icent][AliPID::kPion][kPositive] || + !hSpectrum[icent][AliPID::kPion][kNegative]) continue; + hSum1 = new TH1D(*hSpectrum[icent][AliPID::kProton][kPositive]); + hSum1->Add(hSpectrum[icent][AliPID::kProton][kNegative]); + hSum2 = new TH1D(*hSpectrum[icent][AliPID::kPion][kPositive]); + hSum2->Add(hSpectrum[icent][AliPID::kPion][kNegative]); + hRatio = new TH1D(*hSum1); + hRatio->Divide(hSum2); + if (icent == NcentralityBins) { + hRatio->SetName(Form("hRatio_MB_proton_pion")); + hRatio->SetTitle(Form("(%s+%s)/(%s+%s) (MB);p_{T} (GeV/c);(%s+%s)/(%s+%s);", partChargeName[AliPID::kProton][kPositive], partChargeName[AliPID::kProton][kNegative], partChargeName[AliPID::kPion][kPositive], partChargeName[AliPID::kPion][kNegative], partChargeName[AliPID::kProton][kPositive], partChargeName[AliPID::kProton][kNegative], partChargeName[AliPID::kPion][kPositive], partChargeName[AliPID::kPion][kNegative])); + } + else { + hRatio->SetName(Form("hRatio_cent%d_proton_pion", icent)); + hRatio->SetTitle(Form("(%s+%s)/(%s+%s) (%d-%d%%);p_{T} (GeV/c);(%s+%s)/(%s+%s);", partChargeName[AliPID::kProton][kPositive], partChargeName[AliPID::kProton][kNegative], partChargeName[AliPID::kPion][kPositive], partChargeName[AliPID::kPion][kNegative], (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1], partChargeName[AliPID::kProton][kPositive], partChargeName[AliPID::kProton][kNegative], partChargeName[AliPID::kPion][kPositive], partChargeName[AliPID::kPion][kNegative])); + } + hRatio->SetMarkerStyle(20); + hRatio->SetMarkerColor(color[AliPID::kProton]); + fileout->cd(); + hRatio->Write(); + hPrToPi[icent][2] = hRatio; + } + + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + for (Int_t icharge = 0; icharge < 2; icharge++) { + hRatioMB = (TH1 *)hPrToPi[icent][icharge]->Clone(Form("hDoubleRatioMB_cent%d_proton_%s_pion_%s", icent, chargeName[icharge], chargeName[icharge])); + hRatioMB->Divide(hRatioMB, hPrToPi[NcentralityBins][icharge], 1., 1., ""); + fileout->cd(); + hRatioMB->Write(); + } + hRatioMB = (TH1 *)hPrToPi[icent][2]->Clone(Form("hDoubleRatioMB_cent%d_proton_pion", icent)); + hRatioMB->Divide(hRatioMB, hPrToPi[NcentralityBins][2], 1., 1., ""); + fileout->cd(); + hRatioMB->Write(); + } + + + fileout->Close(); +} + diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/FitPeak.C b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/FitPeak.C new file mode 100644 index 00000000000..b57c336e351 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/FitPeak.C @@ -0,0 +1,67 @@ +TObjArray * +FitPeak(TH2 *h, Float_t startSigma, Float_t nSigmaMin, Float_t nSigmaMax, const Char_t *name = "hsigma", TF1 *fitFunc = NULL) +{ + /* + * fit peak + */ + + TH1 *hpy = NULL; + TH1 *hout[2]; + TH1 *hmean = h->ProjectionX(Form("%s_mean", name)); + hmean->Reset(); + TH1 *hsigma = h->ProjectionX(Form("%s_sigma", name)); + hsigma->Reset(); + for (Int_t i = 0; i < h->GetNbinsX(); i++) { + hpy = h->ProjectionY("hpy", i + 1, i + 1); + if (hpy->Integral() <= 0.) { + delete hpy; + continue; + } + fitFunc = FitPeak(hpy, startSigma, nSigmaMin, nSigmaMax, fitFunc); + hmean->SetBinContent(i + 1, fitFunc->GetParameter(1)); + hmean->SetBinError(i + 1, fitFunc->GetParError(1)); + hsigma->SetBinContent(i + 1, fitFunc->GetParameter(2)); + hsigma->SetBinError(i + 1, fitFunc->GetParError(2)); + delete hpy; + } + // new TCanvas("cmean"); + // hmean->DrawClone(); + // new TCanvas("csigma"); + // hsigma->DrawClone(); + TObjArray *oa = new TObjArray(); + oa->Add(hmean); + oa->Add(hsigma); + return oa; +} + +TF1 * +FitPeak(TH1 *h, Float_t startSigma, Float_t nSigmaMin, Float_t nSigmaMax, TF1 *fitFunc = NULL) +{ + /* + * fit peak + */ + + if (!fitFunc) + fitFunc = (TF1 *)gROOT->GetFunction("gaus"); + + Double_t fitCent = h->GetBinCenter(h->GetMaximumBin()); + Double_t fitMin = fitCent - nSigmaMin * startSigma; + Double_t fitMax = fitCent + nSigmaMax * startSigma; + if (fitMin < h->GetXaxis()->GetXmin()) fitMin = h->GetXaxis()->GetXmin(); + if (fitMax > h->GetXaxis()->GetXmax()) fitMax = h->GetXaxis()->GetXmax(); + fitFunc->SetParameter(1, fitCent); + fitFunc->SetParameter(2, startSigma); + Int_t fitres = h->Fit(fitFunc, "WWq0", "", fitMin, fitMax); + if (fitres != 0) return NULL; + /* refit with better range */ + for (Int_t i = 0; i < 3; i++) { + fitCent = fitFunc->GetParameter(1); + fitMin = fitCent - nSigmaMin * fitFunc->GetParameter(2); + fitMax = fitCent + nSigmaMax * fitFunc->GetParameter(2); + if (fitMin < h->GetXaxis()->GetXmin()) fitMin = h->GetXaxis()->GetXmin(); + if (fitMax > h->GetXaxis()->GetXmax()) fitMax = h->GetXaxis()->GetXmax(); + fitres = h->Fit(fitFunc, "q0", "", fitMin, fitMax); + if (fitres != 0) return NULL; + } + return fitFunc; +} diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/FullAnalysis.sh b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/FullAnalysis.sh new file mode 100755 index 00000000000..182858c491b --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/FullAnalysis.sh @@ -0,0 +1,8 @@ +#! /bin/bash + +if [ "$2" == "" ]; then + echo "two arguments needed" + exit 1 +fi + +aliroot -b -q MakeLibs.C diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/HistoUtils.C b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/HistoUtils.C new file mode 100644 index 00000000000..f8b00dbf630 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/HistoUtils.C @@ -0,0 +1,358 @@ +TH1 * +HistoUtils_weightedmean(TH1 *h1, TH1 *h2) +{ + + TH1 *ho = (TH1 *)h1->Clone("ho"); + ho->Reset(); + Double_t val1, val2, w1, w2, mean, meane; + for (Int_t i = 0; i < ho->GetNbinsX(); i++) { + val1 = h1->GetBinContent(i + 1); + w1 = 1. / (h1->GetBinError(i + 1) * h1->GetBinError(i + 1)); + val2 = h2->GetBinContent(i + 1); + w2 = 1. / (h2->GetBinError(i + 1) * h2->GetBinError(i + 1)); + + if (val1 == 0 && val2 == 0) continue; + + mean = (w1 * val1 + w2 * val2) / (w1 + w2); + meane = TMath::Sqrt(1. / (w1 + w2)); + + ho->SetBinContent(i + 1, mean); + ho->SetBinError(i + 1, meane); + } + + return ho; +} + +//__________________________________________________________________ + +TH1 * +HistoUtils_smartdifference(TH1 *hnum, TH1 *hden) +{ + + TH1 *hr = (TH1 *)hnum->Clone("hr"); + hr->Reset(); + Double_t ref; + for (Int_t i = 0; i < hr->GetNbinsX(); i++) { + if (hnum->GetBinError(i + 1) <= 0.) continue; + ref = hden->Interpolate(hr->GetBinCenter(i + 1)); + if (ref <= 0.) continue; + hr->SetBinContent(i + 1, (hnum->GetBinContent(i + 1) - ref) / ref); + hr->SetBinError(i + 1, hnum->GetBinError(i + 1) / ref); + } + return hr; +} + +//__________________________________________________________________ + +TH1 * +HistoUtils_smartratio(TH1 *hnum, TGraph *hden) +{ + + TH1 *hr = (TH1 *)hnum->Clone("hr"); + hr->Reset(); + Double_t ref; + for (Int_t i = 0; i < hr->GetNbinsX(); i++) { + if (hnum->GetBinError(i + 1) <= 0.) continue; + ref = hden->Eval(hr->GetBinCenter(i + 1)); + if (ref <= 0.) continue; + hr->SetBinContent(i + 1, hnum->GetBinContent(i + 1) / ref); + hr->SetBinError(i + 1, hnum->GetBinError(i + 1) / ref); + } + return hr; +} + +//__________________________________________________________________ + +HistoUtils_drawthemall(const Char_t *filename, Int_t sleepms) +{ + TFile *f1 = TFile::Open(filename); + TList *l1 = f1->GetListOfKeys(); + TObject *o; + Char_t *name; + for (Int_t i = 0; i < l1->GetEntries(); i++) { + name = l1->At(i)->GetName(); + o = f1->Get(name); + o->Draw(); + gPad->Update(); + gSystem->Sleep(sleepms); + } + f1->Close(); +} + +//__________________________________________________________________ + +HistoUtils_autoratio(const Char_t *f1name, const Char_t *f2name, const Char_t *outname) +{ + + TFile *f1 = TFile::Open(f1name); + TFile *f2 = TFile::Open(f2name); + TFile *fo = TFile::Open(outname, "RECREATE"); + TList *l1 = f1->GetListOfKeys(); + + + TH1D *h1, *h2, *hr; + Char_t *name; + for (Int_t i = 0; i < l1->GetEntries(); i++) { + name = l1->At(i)->GetName(); + h1 = (TH1D *)f1->Get(name); + h2 = (TH1D *)f2->Get(name); + if (!h1 || !h2) continue; + hr = new TH1D(*h1); + hr->Divide(h2); + fo->cd(); + hr->Write(); + } + + delete hr; + f1->Close(); + f2->Close(); + fo->Close(); + +} + +//__________________________________________________________________ + +HistoUtils_autosystematics(const Char_t *f1name, const Char_t *f2name, const Char_t *outname) +{ + + TFile *f1 = TFile::Open(f1name); + TFile *f2 = TFile::Open(f2name); + if (!f1 || !f1->IsOpen() || !f2 || !f2->IsOpen()) return; + TFile *fo = TFile::Open(outname, "RECREATE"); + TList *l1 = f1->GetListOfKeys(); + + + TH1D *h1, *h2, *hd; + Char_t *name; + for (Int_t i = 0; i < l1->GetEntries(); i++) { + name = l1->At(i)->GetName(); + h1 = (TH1D *)f1->Get(name); + h2 = (TH1D *)f2->Get(name); + if (!h1 || !h2) continue; + + hd = new TH1D(*h1); + Double_t val1, val2, vald, vale1, vale2, valde; + for (Int_t ii = 0; ii < hd->GetNbinsX(); ii++) { + val1 = h1->GetBinContent(ii + 1); + vale1 = h1->GetBinError(ii + 1); + val2 = h2->GetBinContent(ii + 1); + vale2 = h2->GetBinError(ii + 1); + if (val2 == 0.) continue; + vald = (val1 - val2) / val2; + valde = TMath::Sqrt(TMath::Abs((vale1 * vale1 - vale2 * vale2))) / val2; + hd->SetBinContent(ii + 1, vald); + hd->SetBinError(ii + 1, valde); + } + + fo->cd(); + hd->Write(); + delete hd; + } + + f1->Close(); + f2->Close(); + fo->Close(); + +} + +//__________________________________________________________________ + +TH1 * +HistoUtils_ratio(const Char_t *f1name, const Char_t *f2name, const Char_t *h1name, const Char_t *h2name) +{ + + if (!f2name) f2name = f1name; + TFile *f1 = TFile::Open(f1name); + TFile *f2 = TFile::Open(f2name); + + if (!h2name) h2name = h1name; + TH1 *h1 = (TH1 *)f1->Get(h1name); + TH1 *h2 = (TH1 *)f2->Get(h2name); + + TH1 *hr = h1->Clone("hr"); + hr->Sumw2(); + hr->Divide(h2); + + return hr; + +} + +//__________________________________________________________________ + +TH1 * +HistoUtils_systematics(const Char_t *f1name, const Char_t *f2name, const Char_t *h1name, const Char_t *h2name) +{ + + if (!f2name) f2name = f1name; + TFile *f1 = TFile::Open(f1name); + TFile *f2 = TFile::Open(f2name); + + if (!h2name) h2name = h1name; + TH1 *h1 = (TH1 *)f1->Get(h1name); + TH1 *h2 = (TH1 *)f2->Get(h2name); + + TH1 *hd = h1->Clone("hd"); + Double_t val1, val2, vald, vale1, vale2, valde; + for (Int_t i = 0; i < h1->GetNbinsX(); i++) { + val1 = h1->GetBinContent(i + 1); + vale1 = h1->GetBinError(i + 1); + val2 = h2->GetBinContent(i + 1); + vale2 = h2->GetBinError(i + 1); + if (val2 == 0.) continue; + vald = (val1 - val2) / val2; + valde = TMath::Sqrt(TMath::Abs((vale1 * vale1 - vale2 * vale2))) / val2; + hd->SetBinContent(i + 1, vald); + hd->SetBinError(i + 1, valde); + } + + return hd; + +} + +//__________________________________________________________________ + +HistoUtils_BinLogX(TH1 *h) +{ + TAxis *axis = h->GetXaxis(); + Int_t bins = axis->GetNbins(); + Axis_t from = axis->GetXmin(); + Axis_t to = axis->GetXmax(); + Axis_t width = (to - from) / bins; + Axis_t *new_bins = new Axis_t[bins + 1]; + for (int i = 0; i <= bins; i++) new_bins[i] = TMath::Power(10, from + i * width); + axis->Set(bins, new_bins); + delete new_bins; +} + +//__________________________________________________________________ + +HistoUtils_BinNormX(TH1 *h) +{ + TAxis *axis = h->GetXaxis(); + Int_t bins = axis->GetNbins(); + Double_t c, ec; + Double_t w; + for (Int_t i = 0; i < bins; i++) { + c = h->GetBinContent(i + 1); + ec = h->GetBinError(i + 1); + w = axis->GetBinWidth(i + 1); + c /= w; + ec /= w; + h->SetBinContent(i + 1, c); + h->SetBinError(i + 1, ec); + } +} + +//__________________________________________________________________ + +TObjArray * +HistoUtils_FitPeak(TF1 *fitFunc, TH2 *h, Float_t startSigma, Float_t nSigmaMin, Float_t nSigmaMax, Int_t minIntegral = 100., const Char_t *basename = "hParam", Bool_t monitor = kFALSE) +{ + + /* gaus function if not specified */ + if (!fitFunc) + fitFunc = (TF1*)gROOT->GetFunction("gaus"); + + /* prepare output histos */ + TObjArray *outArray = new TObjArray(); + Int_t npars = fitFunc->GetNpar(); + TH1D *hpx = h->ProjectionX("hpx"); + TH1D *hParam; + for (Int_t ipar = 0; ipar < npars; ipar++) { + hParam = new TH1D(*hpx); + hParam->SetName(Form("%s_%d", basename, ipar)); + hParam->Reset(); + outArray->Add(hParam); + } + + /* loop over x-bins */ + for (Int_t ibin = 0; ibin < hpx->GetNbinsX(); ibin++) { + + /* check integral */ + if (hpx->GetBinContent(ibin + 1) < minIntegral) continue; + /* projection y */ + TH1D *hpy = h->ProjectionY("hpy", ibin + 1, ibin + 1); + /* fit peak */ + if (HistoUtils_FitPeak(fitFunc, hpy, startSigma, nSigmaMin, nSigmaMax) != 0) { + delete hpy; + continue; + } + /* setup output histos */ + for (Int_t ipar = 0; ipar < npars; ipar++) { + hParam = (TH1D *)outArray->At(ipar); + hParam->SetBinContent(ibin + 1, fitFunc->GetParameter(ipar)); + hParam->SetBinError(ibin + 1, fitFunc->GetParError(ipar)); + } + /* monitor */ + if (monitor) { + hpy->SetMarkerStyle(20); + hpy->SetMarkerColor(4); + hpy->Draw("E1"); + fitFunc->Draw("same"); + gPad->Update(); + getchar(); + } + /* delete */ + delete hpy; + + } + /* delete */ + delete hpx; + /* return output array */ + return outArray; +} + +//__________________________________________________________________ + +Int_t +HistoUtils_FitPeak(TF1 *fitFunc, TH1 *h, Float_t startSigma, Float_t nSigmaMin, Float_t nSigmaMax) +{ + + Double_t fitCent = h->GetBinCenter(h->GetMaximumBin()); + Double_t fitMin = fitCent - nSigmaMin * startSigma; + Double_t fitMax = fitCent + nSigmaMax * startSigma; + if (fitMin < h->GetXaxis()->GetXmin()) fitMin = h->GetXaxis()->GetXmin(); + if (fitMax > h->GetXaxis()->GetXmax()) fitMax = h->GetXaxis()->GetXmax(); + fitFunc->SetParameter(1, fitCent); + fitFunc->SetParameter(2, startSigma); + Int_t fitres = h->Fit(fitFunc, "WWq0", "", fitMin, fitMax); + if (fitres != 0) return fitres; + /* refit with better range */ + for (Int_t i = 0; i < 3; i++) { + fitCent = fitFunc->GetParameter(1); + fitMin = fitCent - nSigmaMin * fitFunc->GetParameter(2); + fitMax = fitCent + nSigmaMax * fitFunc->GetParameter(2); + if (fitMin < h->GetXaxis()->GetXmin()) fitMin = h->GetXaxis()->GetXmin(); + if (fitMax > h->GetXaxis()->GetXmax()) fitMax = h->GetXaxis()->GetXmax(); + fitres = h->Fit(fitFunc, "q0", "", fitMin, fitMax); + if (fitres != 0) return fitres; + } + return fitres; + +} + +//__________________________________________________________________ + +void +HistoUtils_Function2Profile(TF1 *fin, TProfile *p, Int_t ntry = 10000) +{ + + TF1 *f = new TF1(*fin); + Int_t npars = f->GetNpar(); + Double_t par[1000]; + Double_t pare[1000]; + for (Int_t ipar = 0; ipar < npars; ipar++) { + par[ipar] = f->GetParameter(ipar); + pare[ipar] = f->GetParError(ipar); + } + + Double_t x; + for (Int_t ibin = 0; ibin < p->GetNbinsX(); ibin++) { + for (Int_t itry = 0; itry < ntry; itry++) { + for (Int_t ipar = 0; ipar < npars; ipar++) + f->SetParameter(ipar, gRandom->Gaus(par[ipar], pare[ipar])); + x = gRandom->Uniform(p->GetXaxis()->GetBinLowEdge(ibin + 1), p->GetXaxis()->GetBinUpEdge(ibin + 1)); + p->Fill(x, f->Eval(x)); + } + } +} diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/MakeLibs.C b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/MakeLibs.C new file mode 100644 index 00000000000..381f5ee6c99 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/MakeLibs.C @@ -0,0 +1,14 @@ +MakeLibs() +{ + /* include path for ACLic */ + gSystem->AddIncludePath("-I$ALICE_ROOT/include"); + gSystem->AddIncludePath("-I$ALICE_ROOT/TOF"); + /* load libraries */ + gSystem->Load("libANALYSIS"); + gSystem->Load("libANALYSISalice"); + /* build analysis task class */ + gROOT->LoadMacro("AliAnalysisParticle.cxx+g"); + gROOT->LoadMacro("AliAnalysisEvent.cxx+g"); + gROOT->LoadMacro("AliAnalysisTrack.cxx+g"); + +} diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/MultCent.C b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/MultCent.C new file mode 100644 index 00000000000..7818fc890d6 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/MultCent.C @@ -0,0 +1,124 @@ +#include "CommonDefs.C" + +MultCent(const Char_t *filename = "data.root", Int_t evMax = kMaxInt) +{ + + /* include path for ACLic */ + gSystem->AddIncludePath("-I$ALICE_ROOT/include"); + gSystem->AddIncludePath("-I$ALICE_ROOT/TOF"); + /* load libraries */ + gSystem->Load("libANALYSIS"); + gSystem->Load("libANALYSISalice"); + /* build analysis task class */ + gROOT->LoadMacro("AliAnalysisParticle.cxx+g"); + gROOT->LoadMacro("AliAnalysisEvent.cxx+g"); + gROOT->LoadMacro("AliAnalysisTrack.cxx+g"); + + /* open file, get tree and connect */ + TFile *filein = TFile::Open(filename); + TTree *treein = (TTree *)filein->Get("aodTree"); + printf("got \"aodTree\": %d entries\n", treein->GetEntries()); + AliAnalysisEvent *analysisEvent = new AliAnalysisEvent(); + TClonesArray *analysisTrackArray = new TClonesArray("AliAnalysisTrack"); + AliAnalysisTrack *analysisTrack = NULL; + treein->SetBranchAddress("AnalysisEvent", &analysisEvent); + treein->SetBranchAddress("AnalysisTrack", &analysisTrackArray); + + /* histo */ + TH2F *hMultCent = new TH2F("hMultCent", "", 120, -10., 110., 5000, 0., 5000.); + TH2F *hRefMultCent = new TH2F("hRefMultCent", "", 120, -10., 110., 5000, 0., 5000.); + TH2F *hMultTOFCent = new TH2F("hMultTOFCent", "", 100, 0., 100., 5000, 0., 5000.); + TH2F *hMultCent_T0TOF = new TH2F("hMultCent_T0TOF", "", 100, 0., 100., 5000, 0., 5000.); + + /* loop over events */ + Int_t mult; + Double_t cent, refmult; + for (Int_t iev = 0; iev < treein->GetEntries() && iev < evMax; iev++) { + /* get event */ + treein->GetEvent(iev); + if (iev % 100000 == 0) printf("iev = %d\n", iev); + + /* check accept event */ + if (!analysisEvent->AcceptEvent(acceptEventType)) continue; + + /* count tracks for multiplicity */ + mult = analysisTrackArray->GetEntries(); + cent = analysisEvent->GetCentralityPercentile(centralityEstimator); + refmult = analysisEvent->GetCentralityPercentile(999); + /* check centrality percentile (V0M) */ + // if (cent == 100.) continue; + + /*** ACCEPTED EVENT ***/ + + /* fill histo */ + hMultCent->Fill(cent, mult); + hRefMultCent->Fill(cent, refmult); + + /* check if event has T0-TOF */ + if (analysisEvent->GetTimeZeroTOFSigma(9) > 150.) continue; + + hMultCent_T0TOF->Fill(cent, mult); + + Int_t nTOFtrk = 0, ntrk = 0; + AliAnalysisTrack *analysisTrack = NULL; + for (Int_t itrk = 0; itrk < mult; itrk++) { + analysisTrack = (AliAnalysisTrack *)analysisTrackArray->At(itrk); + if (!analysisTrack->AcceptTrack()) continue; + ntrk++; + if (analysisTrack->HasTOFMatch()) nTOFtrk++; + + } + + hMultTOFCent->Fill(cent, nTOFtrk); + + } + + /* output */ + TFile *fileout = new TFile(Form("MultCent.%s", filename), "RECREATE"); + hMultCent->Write(); + hRefMultCent->Write(); + hMultCent_T0TOF->Write(); + hMultTOFCent->Write(); + fileout->Close(); + +} + +MultCent_T0TOFeff(const Char_t *filename) +{ + + TFile *filein = TFile::Open(filename); + TH2F *hMultCent = (TH2F *)filein->Get("hMultCent"); + TH2F *hMultCent_T0TOF = (TH2F *)filein->Get("hMultCent_T0TOF"); + + /* projections */ + TH1D *hMultCent_px = hMultCent->ProjectionX(); + TH1D *hMultCent_T0TOF_px = hMultCent_T0TOF->ProjectionX(); + TH1D *hMultCent_py = hMultCent->ProjectionY(); + TH1D *hMultCent_T0TOF_py = hMultCent_T0TOF->ProjectionY(); + + /* efficiency centrality */ + TH1D *hEfficiency_centrality = new TH1D(*hMultCent_T0TOF_px); + hEfficiency_centrality->SetNameTitle("hEfficiency_centrality", ";centrality percentile;T0-TOF efficiency"); + hEfficiency_centrality->Sumw2(); + hEfficiency_centrality->Divide(hEfficiency_centrality, hMultCent_px, 1., 1., "B"); + + /* efficiency tracks */ + TH1D *hEfficiency_tracks = new TH1D(*hMultCent_T0TOF_py); + hEfficiency_tracks->SetNameTitle("hEfficiency_tracks", ";N_{tracks};T0-TOF efficiency"); + hEfficiency_tracks->Sumw2(); + hEfficiency_tracks->Divide(hEfficiency_tracks, hMultCent_py, 1., 1., "B"); + + /* draw */ + TCanvas *cCentrality = new TCanvas("cCentrality"); + hEfficiency_centrality->DrawCopy(); + TCanvas *cTracks = new TCanvas("cTracks"); + hEfficiency_tracks->DrawCopy(); + + /* output */ + TFile *fileout = new TFile(Form("MultCent_T0TOFeff.%s", filename), "RECREATE"); + hEfficiency_centrality->Write(); + hEfficiency_tracks->Write(); + fileout->Close(); + + +} diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/PIDAnalysis.sh b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/PIDAnalysis.sh new file mode 100755 index 00000000000..21e9d42a583 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/PIDAnalysis.sh @@ -0,0 +1,9 @@ +#! /bin/bash + +if [ "$2" == "" ]; then + echo "two arguments needed" + exit 1 +fi + +aliroot -b -q MakeLibs.C +./TOFpid.sh $1 \ No newline at end of file diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/SpectraUtils.C b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/SpectraUtils.C new file mode 100644 index 00000000000..a3887253e7c --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/SpectraUtils.C @@ -0,0 +1,809 @@ +/* + several function used for PbPb combined spectra + Blast Wave is also implemented here + further documentation will come + + author: Roberto Preghenella + email : preghenella@bo.infn.it +*/ + + +/*****************************************************************/ +/* BOLTZMANN +/*****************************************************************/ + +Double_t +Boltzmann_Func(const Double_t *x, const Double_t *p) +{ + /* dN/dpt */ + + Double_t pt = x[0]; + Double_t mass = p[0]; + Double_t mt = TMath::Sqrt(pt * pt + mass * mass); + Double_t T = p[1]; + Double_t norm = p[2]; + + return pt * norm * mt * TMath::Exp(-mt / T); +} + +TF1 * +Boltzmann(const Char_t *name, Double_t mass, Double_t T = 0.1, Double_t norm = 1.) +{ + + TF1 *fBoltzmann = new TF1(name, Boltzmann_Func, 0., 10., 3); + fBoltzmann->SetParameters(mass, T, norm); + fBoltzmann->SetParNames("mass", "T", "norm"); + fBoltzmann->FixParameter(0, mass); + return fBoltzmann; +} + +/*****************************************************************/ +/* LEVY-TSALLIS */ +/*****************************************************************/ + +Double_t +LevyTsallis_Func(const Double_t *x, const Double_t *p) +{ + /* dN/dpt */ + + Double_t pt = x[0]; + Double_t mass = p[0]; + Double_t mt = TMath::Sqrt(pt * pt + mass * mass); + Double_t n = p[1]; + Double_t C = p[2]; + Double_t norm = p[3]; + + Double_t part1 = (n - 1.) * (n - 2); + Double_t part2 = n * C * (n * C + mass * (n - 2.)); + Double_t part3 = part1 / part2; + Double_t part4 = 1. + (mt - mass) / n / C; + Double_t part5 = TMath::Power(part4, -n); + return pt * norm * part3 * part5; +} + +TF1 * +LevyTsallis(const Char_t *name, Double_t mass, Double_t n = 5., Double_t C = 0.1, Double_t norm = 1.) +{ + + TF1 *fLevyTsallis = new TF1(name, LevyTsallis_Func, 0., 10., 4); + fLevyTsallis->SetParameters(mass, n, C, norm); + fLevyTsallis->SetParNames("mass", "n", "C", "norm"); + fLevyTsallis->FixParameter(0, mass); + return fLevyTsallis; +} + +/*****************************************************************/ +/* BOLTZMANN-GIBBS BLAST-WAVE */ +/*****************************************************************/ + +static TF1 *fBGBlastWave_Integrand = NULL; +Double_t +BGBlastWave_Integrand(const Double_t *x, const Double_t *p) +{ + + /* + x[0] -> r (radius) + p[0] -> mT (transverse mass) + p[1] -> pT (transverse momentum) + p[2] -> beta_max (surface velocity) + p[3] -> T (freezout temperature) + p[4] -> n (velocity profile) + */ + + Double_t r = x[0]; + Double_t mt = p[0]; + Double_t pt = p[1]; + Double_t beta_max = p[2]; + Double_t temp_1 = 1. / p[3]; + Double_t n = p[4]; + + Double_t beta = beta_max * TMath::Power(r, n); + if (beta > 0.9999999999999999) beta = 0.9999999999999999; + Double_t rho = TMath::ATanH(beta); + Double_t argI0 = pt * TMath::SinH(rho) * temp_1; + if (argI0 > 700.) argI0 = 700.; + Double_t argK1 = mt * TMath::CosH(rho) * temp_1; + // if (argI0 > 100 || argI0 < -100) + // printf("r=%f, pt=%f, beta_max=%f, temp=%f, n=%f, mt=%f, beta=%f, rho=%f, argI0=%f, argK1=%f\n", r, pt, beta_max, 1. / temp_1, n, mt, beta, rho, argI0, argK1); + return r * mt * TMath::BesselI0(argI0) * TMath::BesselK1(argK1); + +} + +Double_t +BGBlastWave_Func(const Double_t *x, const Double_t *p) +{ + /* dN/dpt */ + + Double_t pt = x[0]; + Double_t mass = p[0]; + Double_t mt = TMath::Sqrt(pt * pt + mass * mass); + Double_t beta_max = p[1]; + Double_t temp = p[2]; + Double_t n = p[3]; + Double_t norm = p[4]; + + if (!fBGBlastWave_Integrand) + fBGBlastWave_Integrand = new TF1("fBGBlastWave_Integrand", BGBlastWave_Integrand, 0., 1., 5); + fBGBlastWave_Integrand->SetParameters(mt, pt, beta_max, temp, n); + Double_t integral = fBGBlastWave_Integrand->Integral(0., 1.); + return norm * pt * integral; +} + +Double_t +BGBlastWave_Func_OneOverPt(const Double_t *x, const Double_t *p) +{ + /* 1/pt dN/dpt */ + + Double_t pt = x[0]; + Double_t mass = p[0]; + Double_t mt = TMath::Sqrt(pt * pt + mass * mass); + Double_t beta_max = p[1]; + Double_t temp = p[2]; + Double_t n = p[3]; + Double_t norm = p[4]; + + if (!fBGBlastWave_Integrand) + fBGBlastWave_Integrand = new TF1("fBGBlastWave_Integrand", BGBlastWave_Integrand, 0., 1., 5); + fBGBlastWave_Integrand->SetParameters(mt, pt, beta_max, temp, n); + Double_t integral = fBGBlastWave_Integrand->Integral(0., 1.); + + return norm * integral; +} + + +TF1 * +BGBlastWave(const Char_t *name, Double_t mass, Double_t beta_max = 0.9, Double_t temp = 0.1, Double_t n = 1., Double_t norm = 1.e6) +{ + + TF1 *fBGBlastWave = new TF1(name, BGBlastWave_Func, 0., 10., 5); + fBGBlastWave->SetParameters(mass, beta_max, temp, n, norm); + fBGBlastWave->SetParNames("mass", "beta_max", "T", "n", "norm"); + fBGBlastWave->FixParameter(0, mass); + fBGBlastWave->SetParLimits(1, 0.01, 0.99); + fBGBlastWave->SetParLimits(2, 0.01, 1.); + fBGBlastWave->SetParLimits(3, 0.01, 10.); + return fBGBlastWave; +} + +TF1 * BGBlastWave_OneOverPT(const Char_t *name, Double_t mass, Double_t beta_max = 0.9, Double_t temp = 0.1, Double_t n = 1., Double_t norm = 1.e6) +{ + + TF1 *fBGBlastWave = new TF1(name, BGBlastWave_Func_OneOverPt, 0., 10., 5); + fBGBlastWave->SetParameters(mass, beta_max, temp, n, norm); + fBGBlastWave->SetParNames("mass", "beta_max", "T", "n", "norm"); + fBGBlastWave->FixParameter(0, mass); + fBGBlastWave->SetParLimits(1, 0.01, 0.99); + fBGBlastWave->SetParLimits(2, 0.01, 1.); + fBGBlastWave->SetParLimits(3, 0.01, 10.); + return fBGBlastWave; +} + +/*****************************************************************/ +/* TSALLIS BLAST-WAVE */ +/*****************************************************************/ + +static TF1 *fTsallisBlastWave_Integrand_r = NULL; +Double_t +TsallisBlastWave_Integrand_r(const Double_t *x, const Double_t *p) +{ + /* + x[0] -> r (radius) + p[0] -> mT (transverse mass) + p[1] -> pT (transverse momentum) + p[2] -> beta_max (surface velocity) + p[3] -> T (freezout temperature) + p[4] -> n (velocity profile) + p[5] -> q + p[6] -> y (rapidity) + p[7] -> phi (azimuthal angle) + */ + + Double_t r = x[0]; + Double_t mt = p[0]; + Double_t pt = p[1]; + Double_t beta_max = p[2]; + Double_t temp_1 = 1. / p[3]; + Double_t n = p[4]; + Double_t q = p[5]; + Double_t y = p[6]; + Double_t phi = p[7]; + + if (q <= 1.) return r; + + Double_t beta = beta_max * TMath::Power(r, n); + Double_t rho = TMath::ATanH(beta); + + Double_t part1 = mt * TMath::CosH(y) * TMath::CosH(rho); + Double_t part2 = pt * TMath::SinH(rho) * TMath::Cos(phi); + Double_t part3 = part1 - part2; + Double_t part4 = 1 + (q - 1.) * temp_1 * part3; + Double_t expo = -1. / (q - 1.); + // printf("part1=%f, part2=%f, part3=%f, part4=%f, expo=%f\n", part1, part2, part3, part4, expo); + Double_t part5 = TMath::Power(part4, expo); + + return r * part5; +} + +static TF1 *fTsallisBlastWave_Integrand_phi = NULL; +Double_t +TsallisBlastWave_Integrand_phi(const Double_t *x, const Double_t *p) +{ + /* + x[0] -> phi (azimuthal angle) + */ + + Double_t phi = x[0]; + fTsallisBlastWave_Integrand_r->SetParameter(7, phi); + Double_t integral = fTsallisBlastWave_Integrand_r->Integral(0., 1.); + return integral; +} + +static TF1 *fTsallisBlastWave_Integrand_y = NULL; +Double_t +TsallisBlastWave_Integrand_y(const Double_t *x, const Double_t *p) +{ + /* + x[0] -> y (rapidity) + */ + + Double_t y = x[0]; + fTsallisBlastWave_Integrand_r->SetParameter(6, y); + Double_t integral = fTsallisBlastWave_Integrand_phi->Integral(-TMath::Pi(), TMath::Pi()); + return TMath::CosH(y) * integral; +} + +Double_t +TsallisBlastWave_Func(const Double_t *x, const Double_t *p) +{ + /* dN/dpt */ + + Double_t pt = x[0]; + Double_t mass = p[0]; + Double_t mt = TMath::Sqrt(pt * pt + mass * mass); + Double_t beta_max = p[1]; + Double_t temp = p[2]; + Double_t n = p[3]; + Double_t q = p[4]; + Double_t norm = p[5]; + + if (!fTsallisBlastWave_Integrand_r) + fTsallisBlastWave_Integrand_r = new TF1("fTsallisBlastWave_Integrand_r", TsallisBlastWave_Integrand_r, 0., 1., 8); + if (!fTsallisBlastWave_Integrand_phi) + fTsallisBlastWave_Integrand_phi = new TF1("fTsallisBlastWave_Integrand_phi", TsallisBlastWave_Integrand_phi, -TMath::Pi(), TMath::Pi(), 0); + if (!fTsallisBlastWave_Integrand_y) + fTsallisBlastWave_Integrand_y = new TF1("fTsallisBlastWave_Integrand_y", TsallisBlastWave_Integrand_y, -0.5, 0.5, 0); + + fTsallisBlastWave_Integrand_r->SetParameters(mt, pt, beta_max, temp, n, q, 0., 0.); + Double_t integral = fTsallisBlastWave_Integrand_y->Integral(-0.5, 0.5); + return norm * pt * integral; +} + +TF1 * +TsallisBlastWave(const Char_t *name, Double_t mass, Double_t beta_max = 0.9, Double_t temp = 0.1, Double_t n = 1., Double_t q = 2., Double_t norm = 1.e6) +{ + + TF1 *fTsallisBlastWave = new TF1(name, TsallisBlastWave_Func, 0., 10., 6); + fTsallisBlastWave->SetParameters(mass, beta_max, temp, n, q, norm); + fTsallisBlastWave->SetParNames("mass", "beta_max", "T", "n", "q", "norm"); + fTsallisBlastWave->FixParameter(0, mass); + fTsallisBlastWave->SetParLimits(1, 0.01, 0.99); + fTsallisBlastWave->SetParLimits(2, 0.01, 1.); + fTsallisBlastWave->SetParLimits(3, 0.1, 10.); + fTsallisBlastWave->SetParLimits(4, 1., 10.); + return fTsallisBlastWave; +} + +/*****************************************************************/ +/*****************************************************************/ +/*****************************************************************/ + + +TF1 * +BGBlastWave_SingleFit(TH1 *h, Double_t mass, Option_t *opt = "") +{ + + TF1 *f = BGBlastWave(Form("fBGBW_%s", h->GetName()), mass); + h->Fit(f); + h->Fit(f); + h->Fit(f, opt); + return f; + +} + +Int_t nBW; +TF1 *fBGBW[1000]; +TGraphErrors *gBW[1000]; + +TObjArray * +BGBlastWave_GlobalFit(TObjArray *data, Double_t *mass, Double_t profile = .7, Bool_t fixProfile = kFALSE) +{ + + /* get data */ + nBW = data->GetEntries(); + for (Int_t idata = 0; idata < nBW; idata++) { + gBW[idata] = (TGraphErrors *)data->At(idata); + gBW[idata]->SetName(Form("gBW%d", idata)); + } + + /* init BG blast-wave functions */ + for (Int_t idata = 0; idata < nBW; idata++) { + printf("init BG-BlastWave function #%d: mass = %f\n", idata, mass[idata]); + fBGBW[idata] = BGBlastWave(Form("fBGBW%d", idata), mass[idata]); + } + + /* display data */ + TCanvas *cBW = new TCanvas("cBW"); + cBW->Divide(nBW, 1); + for (Int_t idata = 0; idata < nBW; idata++) { + cBW->cd(idata + 1); + gBW[idata]->Draw("ap*"); + } + cBW->Update(); + + /* init minuit: nBW normalizations + 3 (beta, T, n) BG-BlastWave params */ + const Int_t nbwpars = 3; + const Int_t nfitpars = nBW + nbwpars; + TMinuit *minuit = new TMinuit(nfitpars); + minuit->SetFCN(BGBlastWave_FCN); + Double_t arglist[10]; + Int_t ierflg = 0; + arglist[0] = 1; + minuit->mnexcm("SET ERR", arglist, 1, ierflg); + for (Int_t idata = 0; idata < nBW; idata++) + minuit->mnparm(idata, Form("norm%d", idata), 1.e6, 1., 0., 0., ierflg); + minuit->mnparm(nBW + 0, "", 0.65, 0.01, 0., 1., ierflg); + minuit->mnparm(nBW + 1, "T", 0.1, 0.01, 0., 1., ierflg); + minuit->mnparm(nBW + 2, "n", profile, 0.1, 0., 10., ierflg); + if (fixProfile) minuit->FixParameter(nBW + 2); + + /* set strategy */ + arglist[0] = 1; + minuit->mnexcm("SET STRATEGY", arglist, 1, ierflg); + + /* start MIGRAD minimization */ + arglist[0] = 500000; + arglist[1] = 1.; + minuit->mnexcm("MIGRAD", arglist, 2, ierflg); + + /* set strategy */ + arglist[0] = 2; + minuit->mnexcm("SET STRATEGY", arglist, 1, ierflg); + + /* start MIGRAD minimization */ + arglist[0] = 500000; + arglist[1] = 1.; + minuit->mnexcm("MIGRAD", arglist, 2, ierflg); + + /* start IMPROVE minimization */ + arglist[0] = 500000; + minuit->mnexcm("IMPROVE", arglist, 1, ierflg); + + /* start MINOS */ + arglist[0] = 500000; + arglist[1] = nBW + 1; + arglist[2] = nBW + 2; + arglist[3] = nBW + 3; + minuit->mnexcm("MINOS", arglist, 4, ierflg); + + /* print results */ + Double_t amin,edm,errdef; + Int_t nvpar,nparx,icstat; + minuit->mnstat(amin, edm, errdef, nvpar, nparx, icstat); + minuit->mnprin(4, amin); + + /* get parameters */ + Double_t beta, betae, betaeplus, betaeminus, betagcc, temp, tempe, tempeplus, tempeminus, tempgcc, prof, profe, profeplus, profeminus, profgcc; + minuit->GetParameter(nBW + 0, beta, betae); + minuit->mnerrs(nBW + 0, betaeplus, betaeminus, betae, betagcc); + minuit->GetParameter(nBW + 1, temp, tempe); + minuit->mnerrs(nBW + 1, tempeplus, tempeminus, tempe, tempgcc); + minuit->GetParameter(nBW + 2, prof, profe); + minuit->mnerrs(nBW + 2, profeplus, profeminus, profe, profgcc); + Double_t beta_max = 0.5 * (2. + prof) * beta; + Double_t norm[1000], norme[1000]; + for (Int_t idata = 0; idata < nBW; idata++) + minuit->GetParameter(idata, norm[idata], norme[idata]); + + /* printout */ + printf("*********************************\n"); + printf("beta_max = %f\n", beta_max); + printf(" = %f +- %f (e+ = %f, e- = %f)\n", beta, betae, betaeplus, betaeminus); + printf("T = %f +- %f (e+ = %f, e- = %f)\n", temp, tempe, tempeplus, tempeminus); + printf("n = %f +- %f (e+ = %f, e- = %f)\n", prof, profe, profeplus, profeminus); + + /* 1-sigma contour */ + minuit->SetErrorDef(1); + TGraph *gCont1 = NULL; + gCont1 = (TGraph *) minuit->Contour(50, nBW + 0, nBW + 1); + if (gCont1) gCont1->SetName("gCont1"); + + /* 2-sigma contour */ + minuit->SetErrorDef(4); + TGraph *gCont2 = NULL; + // gCont2 = (TGraph *) minuit->Contour(50, nBW + 0, nBW + 1); + if (gCont2) gCont2->SetName("gCont2"); + + /* display fits */ + for (Int_t idata = 0; idata < nBW; idata++) { + cBW->cd(idata + 1); + fBGBW[idata]->SetParameter(4, norm[idata]); + fBGBW[idata]->SetParameter(1, beta_max); + fBGBW[idata]->SetParameter(2, temp); + fBGBW[idata]->SetParameter(3, prof); + fBGBW[idata]->Draw("same"); + } + cBW->Update(); + + /* histo params */ + TH1D *hBW = new TH1D("hBW", "", 3, 0., 3.); + hBW->SetBinContent(1, beta); + hBW->SetBinError(1, betae); + hBW->SetBinContent(2, temp); + hBW->SetBinError(2, tempe); + hBW->SetBinContent(3, prof); + hBW->SetBinError(3, profe); + + /* BW graph */ + TGraphAsymmErrors *gBetaT = new TGraphAsymmErrors(); + gBetaT->SetName("gBetaT"); + gBetaT->SetPoint(0, beta, temp); + gBetaT->SetPointEXlow(0, TMath::Abs(betaeminus)); + gBetaT->SetPointEXhigh(0, TMath::Abs(betaeplus)); + gBetaT->SetPointEYlow(0, TMath::Abs(tempeminus)); + gBetaT->SetPointEYhigh(0, TMath::Abs(tempeplus)); + + /* prepare output array */ + TObjArray *outoa = new TObjArray(); + for (Int_t idata = 0; idata < nBW; idata++) { + outoa->Add(gBW[idata]); + outoa->Add(fBGBW[idata]); + } + outoa->Add(cBW); + outoa->Add(hBW); + outoa->Add(gBetaT); + if (gCont1) outoa->Add(gCont1); + if (gCont2) outoa->Add(gCont2); + + return outoa; + +} + +void +BGBlastWave_FCN(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag) +{ + + /* beta -> beta_max */ + Double_t beta = par[nBW+0]; + Double_t T = par[nBW+1]; + Double_t n = par[nBW+2]; + Double_t beta_max = 0.5 * (2. + n) * beta; +#if 0 + /* check beta_max */ + if (beta_max >= 1. || beta_max <= 0.) { + f = kMaxInt; + return; + } + /* check T */ + if (T <= 0.) { + f = kMaxInt; + return; + } +#endif + + Double_t pt, pte, val, vale, func, pull, chi = 0; + /* loop over all the data */ + for (Int_t iBW = 0; iBW < nBW; iBW++) { + /* set BGBW parameters */ + fBGBW[iBW]->SetParameter(4, par[iBW]); + fBGBW[iBW]->SetParameter(1, beta_max); + fBGBW[iBW]->SetParameter(2, T); + fBGBW[iBW]->SetParameter(3, n); + /* loop over all the points */ + for (Int_t ipt = 0; ipt < gBW[iBW]->GetN(); ipt++) { + pt = gBW[iBW]->GetX()[ipt]; + pte = gBW[iBW]->GetEX()[ipt]; + val = gBW[iBW]->GetY()[ipt]; + vale = gBW[iBW]->GetEY()[ipt]; + func = fBGBW[iBW]->Eval(pt); + // func = fBGBW[iBW]->Integral(pt - pte, pt + pte); + pull = (val - func) / vale; + chi += pull * pull; + } + } + + f = chi; +} + +/*****************************************************************/ + +IntegratedProduction(TH1 *h, Double_t mass, Option_t *opt = "") +{ + + Double_t yield, yielderr, yielderrcorr, mean, meanerr, meanerrcorr, partyield[3], partyielderr[3], partyielderrcorr[3]; + TF1 *f = BGBlastWave_SingleFit(h, mass, opt); + GetYieldAndMean(h, f, yield, yielderr, yielderrcorr, mean, meanerr, meanerrcorr, 0., 10., partyield, partyielderr, partyielderrcorr); + + // Double_t fint = f->Integral(0.,10.); + // Double_t finte = f->IntegralError(0.,10.); + // Double_t fmean = f->Mean(0., 10.); + + printf("dN/dy = %f +- %f (%f)\n", yield, yielderr, yielderrcorr); + printf(" = %f +- %f (%f)\n", mean, meanerr, meanerrcorr); + printf("dN/dy (data) = %f +- %f (%f)\n", partyield[0], partyielderr[0], partyielderrcorr[0]); + printf("dN/dy (low) = %f +- %f (%f)\n", partyield[1], partyielderr[1], partyielderrcorr[1]); + printf("dN/dy (high) = %f +- %f (%f)\n", partyield[2], partyielderr[2], partyielderrcorr[2]); + // printf("----\n"); + // printf("dN/dy (func) = %f +- %f\n", fint, finte); + // printf(" (func) = %f +- %f\n", fmean, 0.); + + // TH1 *hr = (TH1 *)h->Clone("hr"); + // hr->Divide(f); + // new TCanvas; + // hr->Draw(); + + // TProfile *p = new TProfile("p", "", 100, 0., 10.); + // gROOT->LoadMacro("HistoUtils.C"); + // HistoUtils_Function2Profile(f, p); + // p->Draw(); +} + +GetYieldAndMean(TH1 *h, TF1 *f, Double_t &yield, Double_t &yielderr, Double_t &yielderrcorr, Double_t &mean, Double_t &meanerr, Double_t &meanerrcorr, Double_t min, Double_t max, Double_t *partyield, Double_t *partyielderr, Double_t *partyielderrcorr) +{ + + /* find lowest edge in histo */ + Int_t binlo; + Double_t lo; + for (Int_t ibin = 1; ibin < h->GetNbinsX() + 1; ibin++) { + if (h->GetBinContent(ibin) != 0.) { + binlo = ibin; + lo = h->GetBinLowEdge(ibin); + break; + } + } + + /* find highest edge in histo */ + Int_t binhi; + Double_t hi; + for (Int_t ibin = h->GetNbinsX(); ibin > 0; ibin--) { + if (h->GetBinContent(ibin) != 0.) { + binhi = ibin + 1; + hi = h->GetBinLowEdge(ibin + 1); + break; + } + } + + /* integrate the data */ + Double_t cont, err, width, cent, integral_data = 0., integralerr_data = 0., integralerrcorr_data = 0., meanintegral_data = 0., meanintegralerr_data = 0., meanintegralerrcorr_data = 0.; + for (Int_t ibin = binlo; ibin < binhi; ibin++) { + cent = h->GetBinCenter(ibin); + width = h->GetBinWidth(ibin); + cont = h->GetBinContent(ibin); + err = h->GetBinError(ibin); + /* check we didn't get an empty bin in between */ + if (cont != 0. && err != 0.) { + /* all right, use data */ + integral_data += cont * width; + integralerr_data += err * err * width * width; + integralerrcorr_data += err * width; + meanintegral_data += cont * width * cent; + meanintegralerr_data += err * err * width * width * cent * cent; + meanintegralerrcorr_data += err * width * cent; + } + else { + /* missing data-point, complain and use function */ + printf("WARNING: missing data-point at %f\n", cent); + printf(" using function as a patch\n"); + integral_data += f->Integral(h->GetBinLowEdge(ibin), h->GetBinLowEdge(ibin+1)); + integralerr_data += f->IntegralError(h->GetBinLowEdge(ibin), h->GetBinLowEdge(ibin+1), 0, 0, 1.e-6); + meanintegral_data += f->Mean(h->GetBinLowEdge(ibin), h->GetBinLowEdge(ibin+1)) * f->Integral(h->GetBinLowEdge(ibin), h->GetBinLowEdge(ibin+1)); + meanintegralerr_data += f->Mean(h->GetBinLowEdge(ibin), h->GetBinLowEdge(ibin+1)) * f->IntegralError(h->GetBinLowEdge(ibin), h->GetBinLowEdge(ibin+1), 0, 0, 1.e-6); + } + } + integralerr_data = TMath::Sqrt(integralerr_data); + meanintegralerr_data = TMath::Sqrt(meanintegralerr_data); + + /* integrate below the data */ + Double_t integral_lo = min < lo ? f->Integral(min, lo) : 0.; + Double_t integralerr_lo = min < lo ? f->IntegralError(min, lo, 0, 0, 1.e-6) : 0.; + Double_t meanintegral_lo = min < lo ? f->Mean(min, lo) * integral_lo : 0.; + Double_t meanintegralerr_lo = min < lo ? f->Mean(min, lo) * integralerr_lo : 0.; + + /* integrate above the data */ + Double_t integral_hi = max > hi ? f->Integral(hi, max) : 0.; + Double_t integralerr_hi = max > hi ? f->IntegralError(hi, max, 0, 0, 1.e-6) : 0.; + Double_t meanintegral_hi = max > hi ? f->Mean(hi, max) * integral_hi : 0.; + Double_t meanintegralerr_hi = max > hi ? f->Mean(hi, max) * integralerr_hi : 0.; + + /* compute integrated yield */ + yield = integral_data + integral_lo + integral_hi; + yielderr = TMath::Sqrt(integralerr_data * integralerr_data + + integralerr_lo * integralerr_lo + + integralerr_hi * integralerr_hi); + yielderrcorr = TMath::Sqrt(integralerrcorr_data * integralerrcorr_data + + integralerr_lo * integralerr_lo + + integralerr_hi * integralerr_hi); + + /* compute integrated mean */ + mean = (meanintegral_data + meanintegral_lo + meanintegral_hi) / yield; + meanerr = TMath::Sqrt(meanintegralerr_data * meanintegralerr_data + + meanintegralerr_lo * meanintegralerr_lo + + meanintegralerr_hi * meanintegralerr_hi) / yield; + meanerrcorr = TMath::Sqrt(meanintegralerrcorr_data * meanintegralerrcorr_data + + meanintegralerr_lo * meanintegralerr_lo + + meanintegralerr_hi * meanintegralerr_hi) / yield; + + /* set partial yields */ + partyield[0] = integral_data; + partyielderr[0] = integralerr_data; + partyielderrcorr[0] = integralerrcorr_data; + partyield[1] = integral_lo; + partyielderr[1] = integralerr_lo; + partyielderrcorr[1] = integralerr_lo; + partyield[2] = integral_hi; + partyielderr[2] = integralerr_hi; + partyielderrcorr[2] = integralerr_hi; + +} + +/*****************************************************************/ + +Double_t +y2eta(Double_t pt, Double_t mass, Double_t y){ + Double_t mt = TMath::Sqrt(mass * mass + pt * pt); + return TMath::ASinH(mt / pt * TMath::SinH(y)); +} +Double_t +eta2y(Double_t pt, Double_t mass, Double_t eta){ + Double_t mt = TMath::Sqrt(mass * mass + pt * pt); + return TMath::ASinH(pt / mt * TMath::SinH(eta)); +} + +TH1 * +Convert_dNdy_1over2pipt_dNdeta(TH1 *hin, Double_t mass, Double_t eta = 0.8) +{ + + TH1 *hout = hin->Clone("hout"); + hout->Reset(); + Double_t pt, mt, conv, val, vale; + for (Int_t ibin = 0; ibin < hin->GetNbinsX(); ibin++) { + pt = hin->GetBinCenter(ibin + 1); + conv = eta2y(pt, mass, eta) / eta; + val = hin->GetBinContent(ibin + 1); + vale = hin->GetBinError(ibin + 1); + val /= (2. * TMath::Pi() * pt); + vale /= (2. * TMath::Pi() * pt); + val *= conv; + vale *= conv; + hout->SetBinContent(ibin + 1, val); + hout->SetBinError(ibin + 1, vale); + } + return hout; +} + +TH1 * +Convert_dNdy_1over2pipt_dNdy(TH1 *hin) +{ + + TH1 *hout = hin->Clone("hout"); + hout->Reset(); + Double_t pt, mt, conv, val, vale; + for (Int_t ibin = 0; ibin < hin->GetNbinsX(); ibin++) { + pt = hin->GetBinCenter(ibin + 1); + val = hin->GetBinContent(ibin + 1); + vale = hin->GetBinError(ibin + 1); + val /= (2. * TMath::Pi() * pt); + vale /= (2. * TMath::Pi() * pt); + hout->SetBinContent(ibin + 1, val); + hout->SetBinError(ibin + 1, vale); + } + return hout; +} + +TH1 * +Convert_dNdy_dNdeta(TH1 *hin, Double_t mass, Double_t eta = 0.8) +{ + + TH1 *hout = hin->Clone("hout"); + hout->Reset(); + Double_t pt, mt, conv, val, vale; + for (Int_t ibin = 0; ibin < hin->GetNbinsX(); ibin++) { + pt = hin->GetBinCenter(ibin + 1); + conv = eta2y(pt, mass, eta) / eta; + val = hin->GetBinContent(ibin + 1); + vale = hin->GetBinError(ibin + 1); + val *= conv; + vale *= conv; + hout->SetBinContent(ibin + 1, val); + hout->SetBinError(ibin + 1, vale); + } + return hout; +} + +TGraph * +Convert_dNdy_dNdeta(TGraph *hin, Double_t mass, Double_t eta = 0.8) +{ + + TGraph *hout = hin->Clone("hout"); + // hout->Reset(); + Double_t pt, mt, conv, val, valelo, valehi; + for (Int_t ibin = 0; ibin < hin->GetN(); ibin++) { + pt = hin->GetX()[ibin]; + conv = eta2y(pt, mass, eta) / eta; + val = hin->GetY()[ibin]; + valelo = hin->GetEYlow()[ibin]; + valehi = hin->GetEYhigh()[ibin]; + val *= conv; + valelo *= conv; + valehi *= conv; + hout->GetX()[ibin] = pt; + hout->GetY()[ibin] = val; + hout->GetEYlow()[ibin] = valelo; + hout->GetEYhigh()[ibin] = valehi; + } + return hout; +} + +TH1 * +SummedId_1over2pipt_dNdeta(const Char_t *filename, Int_t icent) +{ + + const Char_t *chargeName[2] = { + "plus", "minus" + }; + + TFile *filein = TFile::Open(filename); + TH1 *hy[AliPID::kSPECIES][2]; + TH1 *heta[AliPID::kSPECIES][2]; + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) + for (Int_t icharge = 0; icharge < 2; icharge++) { + hy[ipart][icharge] = (TH1 *)filein->Get(Form("cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + if (!hy[ipart][icharge]) { + printf("cannot find cent%d_%s_%s\n", icent, AliPID::ParticleName(ipart), chargeName[icharge]); + return NULL; + } + heta[ipart][icharge] = Convert_dNdy_1over2pipt_dNdeta(hy[ipart][icharge], AliPID::ParticleMass(ipart)); + } + + /* sum */ + TH1D *hsum = heta[2][0]->Clone("hsum"); + hsum->Reset(); + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) + for (Int_t icharge = 0; icharge < 2; icharge++) + hsum->Add(heta[ipart][icharge]); + + return hsum; +} + +TH1 * +SummedId_dNdeta(const Char_t *filename, Int_t icent) +{ + + const Char_t *chargeName[2] = { + "plus", "minus" + }; + + TFile *filein = TFile::Open(filename); + TH1 *hy[AliPID::kSPECIES][2]; + TH1 *heta[AliPID::kSPECIES][2]; + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) + for (Int_t icharge = 0; icharge < 2; icharge++) { + hy[ipart][icharge] = (TH1 *)filein->Get(Form("cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + if (!hy[ipart][icharge]) { + printf("cannot find cent%d_%s_%s\n", icent, AliPID::ParticleName(ipart), chargeName[icharge]); + return NULL; + } + heta[ipart][icharge] = Convert_dNdy_dNdeta(hy[ipart][icharge], AliPID::ParticleMass(ipart)); + } + + /* sum */ + TH1D *hsum = heta[2][0]->Clone("hsum"); + hsum->Reset(); + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) + for (Int_t icharge = 0; icharge < 2; icharge++) + hsum->Add(heta[ipart][icharge]); + + return hsum; +} + +/*****************************************************************/ + diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/T0FillOnline.139465.extended.root b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/T0FillOnline.139465.extended.root new file mode 100644 index 0000000000000000000000000000000000000000..4a131cd23f37bdaa8fe3c2313994ad577533b606 GIT binary patch literal 15852 zcma)jWl&wQ7Vg2_-5pACcXw}r;#S<^ZvcNXVxS$ zN!GWLy(g2b{e8|34z2*e1Q-ASm;wMor=OPnSy%crh)*+z{=XGE9smI62>?NT6=tbr zh_Mw2@!1;Cb@AEyKRtPX|2Q%fy&r=INc`9HCmH|%qb_Y_Yeu2Y`dQej*xOp!n=!L- z@Nsf;F`Ie1n%SG0nKC>7C&K@s3jpRn-aifN)3L*+nSa`UQ9kFy`u_`^mhC?g@>+h5 zM+bcQPlOP#{}~UhF3TnjXZe341n4Nj184!3yZ}##Mo&0(bql<+Tn~I`+rXGW#E1yv zUP!&S$LF$+eQvY_QQx)~@R6J&+Mv-#6d!^*%n{ zUr#DE7cwe@UNZge`3~AW&J|^`BaW505nGYzWd4+JE^m=_oZ1dAHwKIeo2*D%LcyZZ z&S!qFO>zUp%$lV{5C1D0AVgqkruqgOhqU2Wpl0p9dwLo-%VE|7&qw|HG~8Ag566Vi zzGa(`#J9ikdvB?ib70i>@ZOyMeIiXW9(t7uy}xlgh?ypJT+(OVj8qn(wI88l6$gJM zOm4bj-su=V>~)jtXr8i*A6X*m*iSmlw#YP-9yQ+<=AZJn$Z-E;?#K5p zs`TqL{TROQ!|Pa~y(eC$vof8Ezuu`8lDzjcl>0L0TG#KBm^YQOd!TjOI$E4_NH)K# zwiR5wrBS@9wmH61!npZn+H?Fv=x_JaGfFmzP*UTbL}$5P8ga%CM{5FF&_1y}lY^tJ z{UR&+V@NqAR3EA!&OjU=pD#xT4N@q^wGm=`Rf&!|g$Kw}GOQyXi}}4OZlXT#L>8ab zn3}nF|2)9pYgJf?Hj|Ldy;j6(lQH>p?O$tKWiK4MWiMX*f|_v1;m!Vt+z zVwYxVpsJg#@8t+>Z#UtmbR7f4xlEI%gU+o1=^)qvW*c%omnszPkVBlTGBzqKZ2IJm z_5G!=?`A6HI$J;~h0)teVmrXZB2ri=^tiTG<4&jX__mbrJCWUoiU1s*p@l=;z?aHH zp{;;6PWrSH^fCu(ay^YgV;WK(mME-5yD5aeU-fGq7-sVg zVt4-iklH@+7)LG2yU?1kcyZ`%_}Ck&eVn%sz1r~t5Iu9*>$=ZY`RG&sGj)!8%zYbFCOE>_tB*X+ojw5dRa=&x3}rcOV|AGcm4kscZ1rVt5e9$^s^#~J=i zWgm9l*I#_3AHB3jaNkS*!(b9(hq^@erkG}A)m(aWD@$`%HuYE_Z*I17*lj?7+NEl4 zf%fJcaDr|2UUr4#U`DErySQ#E()i+P*1A-fm2t17{dSXBB*zw;0N2Xmd!(r~nz4DlD^4P5;?LrM$yiTnqWf z#ozOwKXc;m${H&}N`f=DN1QaZPb+(O%(j}~eHLOvzWeyRwXb6Vdg~?gFLT5nCjDA8 z#$#>W=Dx)F>h6{`dzlwBg|8(ib2@Y(YBfBIV}$aYp%LXDg*bXj}KOjUkAHh z{PkQ96u69C7Ga7STnz9s2(GNs)ui1|4Y5WW|sC}p4HSWwFC~Yt=-Wv%=~BRv$*t= zB0d9dfdG5e<$iZY|LCXf?Aq~OQLGh4`Q%EctwDClk~jSvOLoL?EJ`HD+xExm#8RC~ z_5C4P7WT=8lh}<_cXRa9-{&mD`TY4*JRt)V?m_*q){IUQ_eYikllM!Hbrx&RaK5Xu z1Eha%>f==o3ez6nsZ2DgU%CAT(>2-Z)n*yf$^*g)4*V)jj>eZ#A^L|5;NQQ|7xnLZ zSO|EzK2Kc~d-*TsT`Xz7KmTzNpv0e~10waXj4=s^(GC5M!Sz=UX3 zm`toUn;d9eWAdRXptZS1euEfi=<}>uqno0zP#6|IO5)=LL!z{I5smannl$8oi)9b<+Eu2D_VxTTFfId^BWyr~5)_vne<4`*>i?noQ8 zDjZ+GMgo?38dD3CVTao?pWKp9Q~aEh1yi7*>QsOO@V-L*no7@w%oa=#1p)lz7IMk$ zdv2rtUa;Xm0&nGq+ipir9x)zuR`n_-n9aR5^n2KhM2uif?M&EA&&rt(fROi)&hOqv zC^g7&!hEaHnGolY0)fE*;47t)!K#$#d7O*s2hJ9>BSIVp<3Q`}h~9a^OQFoYZ1=bW zgjWxV=mImK?f{4UL_08(-o^6|)g$c^Y$ientm#ENSj(FX;M}!4HBfuo2{4`FAcy0) zJa9@pF|z1EVB44Pj`~An+}d8#64TiSRl{PQHs-Hg{phfP80Mt0jiL^-%ShIP#D5>j z9w@Q}*8*7x;8U1HfgOe1gAn?L8RsG%VNwbQ$)7_U*y&vLd9D#Eoy??>O9HGRlo<2W*)X4T;0T=F8cfoeb*gHXYM39#OI zywEINwb=RNaiS1PB*jJR?H5t~&sAGwu#l6@?wCs0JFWhF+pnj)d}jI^4o`d|^`mKG zffXZDa&>DI7P9)nc&aJcjU55k-e!#1C|)XisC+W_BSP<=YbFJ__TCkKiW=6QWw^+X z+H)Hgnq4J~dl2gxu?RdMk{gdlu7HanAM#Mx zBCznGazYQ(UqecTJ(c#~kS&W&Q~wZD#epjA#FWc&Pn?goDtNc0xbx??a=(ye(9dXa zJ)tX#nsymdu3_{7TjtS5tQExu)rSx3y#V{2M-4kRJv zx1iHSAlWH7Z9C9c4LU_cz9xdL4U1d&A$k;ykQ)|_cn+E9tM*|dBJtrq^aE#nV!>ZO z6rFG~R5Sf~%-!=^dU(f&Iua1D59SiV9keki6XeE}XwF)J4aKmtbsBN^EmT&xyUoV3?X3|FHZ7A3RR#K8vMYt=1#clI0-Grf zbB999X${#HkezY@AwG`tDGhI$asr%j4MJiCXURRUB)GFp=5bAXIDtT=)W&U@*@X*o zJCgm3vcx9DPMcFX-K(?)Gm9YU0w%8brV?r^q?vYrg>t*{%36HEgfOf!U^Rhz2it0H zr?*iqgCD==d?Zr#<>yzcQcYP7!Jk(^C7 za?S>@GlCGkZTdAfl_b73srtO-fuXesPkjKoEXX!sH|g2#d@5?^GhNwznI+`=K|oR zp^iw$1YIAzl7MTAc3N}X>kUdRB$Lze%9My*-b0i_Izg%N#V+fD07FP|E}y<5JDZ6Wh&^lD+w^@}Bi=l=ewmRn`Z?H7?(NrRB+KOz zGVR^YPu0z$xaVHUW1?4JNAHE4m|$u3X8iNl;Q6)pg8e;+N4t?J$~*dogUf@SY!sFI zpQ;>*a(=e7cXH`CX(gMw(q%O9^Q&POvXfBx2hXmK*rfq>GG$>WVwc* zMhZxI#6mxQV|1q=mJVIZ3L$RRGOEVn%L+k%)W%Hrh$yjy{Fx8FB>8$UhG!`x|AP~{UUG-))ynCGC6du>*t3m_?_g$nFKIVz|Uw(UeMb(ohpkv%4y*E9{p zno+q-m(y=dnol~&EhLAnmaIl_*?awWS%C^O-F{DNJ*{aAg9?Q)JyTDZep?|A3(n0R zs(25>lGBgzY@E*ztSmW_)rYlfoexYZjPGv;!4EPY87A9j)oKl1iNfypHdCYA396>_ zwL|;hslZXwK_ZqSZ5!6%+`Sht{|dm^$LR%3NFM)UR6P)okPs#lx?#2H6;PcE{DYB- z5xe4gNKi0&rgF@Pq~&loF0~0M9XJK_6nY)G z1Ux=C$9qJD&pSyAthHy2 z=Vy&ohdTD_?F=NnyoG@UbVijB$PR46SfgPX|Dxp!p5L&V?#-H>+kjN2Ym|U4U3V>T zp8%Z5o&D_gL*qGkL?hHE_FjL zSjYzxl#FP*&B|3mREC7l>%gi~U8C#DR$5Uvw#Ce^n1e3WlZ3UQC==x>i|DunA-yTR zOYp5OzZQfLOxsAJIN>1qhS}h=D#U8Rq38`jXQ$1N9$nI!klr3c!+zb%O%8hJ1Ys<6 zu-|?I{ct@LBTk4}3*(Jf7itl-_MR`>?adBpgY3ae7qgCo5XQ1TD$tOXL_Lg$V<>>7 zm7r2(NYBkTAl0ccP0Oe445Hn|Bq)Hzhp^n6%hCN7TEwG^VO#S&_O+xq9|$+>&F)(F z{I-23MG9Eolq^Hz?Gd%s2AN@QLyQv2F_p?xLCwbH8_+_<>F`^JLFJ}Ih%%+kV;-ei z{Q`#Ze`7~!g;X9y1(}Txqg;*=lE28C21bkWTk{`!0XVZIRTWO;{uTBnA`fS7#kZo~ z0J0Ej;*R0gkxor&p3SP8N!hjvd$MK9=w3H)8Fm@*2(Sb(OT3Qd+$2sBszbxoH9b2h zW!+S0{}HrxLJ&Gn8OQqYzYb?@GnMJGa-fmc|8Qa7>UMA|;HNf*^;JGf4I=D4fY;w| zqOBqIhw4DQ76ea8d$I>g?v6~OfDEw#AM3A!$UrV?e>)0)Gf_jrD_tt*twd6;5%b$%5u>I|dJEqM^aG6J=e(@f*{HVoM;Kni z-n5(mR&)^_3=tZz9%!m(8FyFO#zDB@WjOl_C{_uC*2A}@ha~82*+aFf-6MhI9eoLj z%V7+4wHbKY4JY^?SPztv;0r*rA}H;*o>n3Y3!jRyyR%VT^PIbD3?#rwjgNDs*)L3+|2r zbwdQChjU=xlE06Mz9Jc?DNI#E$HK5uz%i#)u6V)lT}Hwvf)0>DctJ>EEWuOhVN+Ta z?=D6J*{u0RM%<4oP@IWBQmz&^5yI<3$U125E7wcK8DDqJ>jFtmi8YN^(DTN zfgJ=}I;!Qr|^hjjIG3jpr-1_wiv_(FHAMzvuG6&aJH3xUHT_0HC#Y1uk{t@Q3-0L^@9V>8l*uml1mAgj z;5N!aQBT==i?t4hpJS)FgPRj^bbB(e!Aw2Opw;oPULr;#s#>`q^O}2GX+}SyFwZPf z(T-)s4vgBG%vrjSJOFL?I*57*CX3b6NuwgP$OOD9+uwu6bzv+B(7DQ~d%u1KTEJ z3{Mzsi{Y$tloBe#DmW^`aKQ=54&*2H$UD*s_Pi><@Z4=G)VM^)yrLkMmNhxBTI&Rf z2J4ELW1nD)OS^Nd*ZG|irp5>rtQ~ehm7EF7NO2ovk=EmF^I=PMWs7vBcPY+sqIs97+jf`AEB zig*Q2T|er2vTe6bEsRHH9SG+xVJjm zM*rbZs+5EHmp$P2fFOYJ-~sSVaSk(_9tDTxWHG?6cAlVPXgMNnQ^|6DFRHTJi49g} zmtmY*gmR(-^+U8)mm9CMfo%80ruQa;OxK@KT=|MoreT~MVEA%jT{$SZb*pR9t|<_m zbaRlv=jQY7dfPy%Uo94IoVSnl+ox9C<7vGiO~K1sB4Iv)sgpuYSzyx5V#0v}3i+zbh;=iL)_bd|eJOft^8AHtb`xuOzL#}5kTBQyVM z0TUrDoHL4nYx|en_8g5w%~nK%cE8qI-GCg;!rN1o7B*{bH^}xR&v96rO*M4R&1473J8h0*`vz-ur%d+o zE>XI~%Tr9|Krn6=nM-6D4)6Akqw?b!E?vcO4??gDFNHS-ohPl+jZf~H;Cg6=3gpUf zr<*PJwbMIQ`};8@`=$mCo|Ayk3@-fMiM278xo)O4*9QuFek&**rIleNhIi1F0|(!` zIO|Zg{Ptt+17DXDTFisjh*NBe)0&DMpS?T$(4FIciw-yO!Pdaa1pGqNgW1`O>%xj> zjfN9t`2~qqXG`)AH6#rg?^?o?k+Kh({k6?hl}&Sl=RaPKLgq9{%MZelr_{JZ4s}|W zOp*Q&jD#EJxvK+8q)fZCGUiT+UJ5O87jJ6??vA(6Z5!$|HZXBh^dM)RL z#Qqyg644={vPLe0cgFC~E|>76a-5zl%ayYN-3*Z7Ml zH#=?aSS^#AFnR~9p1Ej?1kS%tKxjMsy^XE+78X^0Hw23t9w|0cjgDs!EUit)6ODI> zGXAeXs_KuycpnCr-Aou_zMd>9FE*Lu{?>&d2ECI(&Z@?0zQuIB;YL{heVrAgDxBLW z8-M>PE{7NA2?;hmmu<@`zEj>s#moKAQ(8;Wn@LQ|W(rkI_kI|T6){^8g$(tcizEmm z<}!7R%eiZh@Stm(kO)Q3WEQ<@#*c8(GIf$mUS$8+q0I44WXS36c2&>MUQmGb(p4ryq#V=R?bd+s1xO-R_s2Y&!mvQ)np@bNrX8qQ`Z~sY$Ol`olhU`>V{e zW73{bi#%dWzgCs12cPDZz}Qb1&`(V+)Yaz9e%y|on(a=$iaQe2^5w*S*J@r)mS_nM zLdV1N6k>h{kx9dCGQ_I%;S!ntJ6oq3#J=04a2Jm;!3W2D zo=aw^_Cle-RI5%khF{=1-F9;_T8UkEDc~x-d&D+H4sw7^#MHldONH@YA z@j6@ks^0Y|&LB1MzsE8(tWMzMSv&u!qtp5*6*{@-w0J9>sMws(x|?ID@!vvPXyzSz z4zsIx(C*vY9N)eUD0F%EFwcc6z$RX1;I>8QV+Qc3vEEZp|ij zZv98nnt8>a((h5Lrzf0Jo<6wOaqP5JZj0K{6%G}P4DR7V;bZ+53-!`*&{L$sTa*3= zs*}u7v=<4r#cT?KPMp`sPXRSGeG~#JU_VepnHYUJ9!mbqm zWHInRUMi|raGGm&uY zn0NIKyF-j~+A1!y%WUwNtvNHt2^@2xZ}?b4b&naL@)rAZsNP^LSBn2LLrT|Llmc1D zXrboa!EEWhUfX7@UYnE*GfC;rY$1zF=@dh&`u;a&w_Ji0`Rd-nWN7Eot1i7`B68tC zg&)^$vvpAlz_%=gbJv{&q*cd}+LIR3*atn;lX05Tq7X`)b?AG^PCwuHm7g&p#XVphMf1p9JvmQl9!>M|WD+iwlm zG2EAo*~x|`h4)92f~`P5&HlqarioC??``OmFtUCc%DfgyE28^%=Rcj8P+)yaB@fu>>>BkH#nrap&LrxnXVSW5WVmhCH7*}fq)N0OC-j_`S zJN3ru56T7aJKh+4fXjnGfw?7@5y|^Z-gKdtSktKmljZte^?PK4Uf?<0QvMdL&sx1n z>`mjc$rSp%R&AmXEndwKx_Rt9!xGg!lh1EAvslc7<<1(4b`k!b^MHA?hklXzmuHPr z;S;v@*z~@0p}r-dcf$6?^xkubU+W|!OH2%38(vN@%kcMMvHVLOLx~Er{1nq?e=YhRaT^@&-yOzXF}Qfy6+QJcT`JU zp0w@Wf@Ucmc1wFfY5M-v{mh~FHDk}R?rDBe`h(Op3R7^W39Rw@$1wE@e-uu^!tq&~ z3uXr|FsHs(bne2pPy*E#J(DihH7*f!0s%MaS-M(Fe8(#8s9nR8K)mInHyroTjxptc z4%6a%`_qQjuL2Ve6UsZ?7RCNPOQlMv0t4zli)$Q~M;>?u;$uj%QH_R9y6bjI2~S&G zXatxajE3mdmf4nrNZQ9uhguR&wQP_Ck|WJzQo5IO$&*OVL+kscK%scG{ezP3vNvX- zPQx!}Mxh0Ar|7HEBxQqj5~cE|Mh9c}t&_F^tI20m%QbJpbWMgQ{rB}>>)ui=n=bzS zInz}#eF@QB?z&cLdbl(7u^x4wGOt~qV6c5q@M>D+$UM{d7L}*;{tsL}=pj>u+)qTyj5kYC03hv`Z|jwL3*> zLJ{d{GNY}nG{Icm)ifiDodrMXPm&`3HL;>8ez7^c> zCGE_@!cdc&cw{`dVX=w614H&RV3Rk80hw-naQ_$&xWCZzYI`Ue+|Q|bmAlA$MbRYc z3y;sR(d~hIQJn^Q=@jqC&S2O;TVdQ7dceA1SirupBLTIyr-9dJBEjo*Sm5;%DzH9L zy{9IXM2E{1u7ispXw?M;v>Lq`(VTc6(Y%f{uqqu6woB6oPpl?@C;nN1Ck%A2%s14p z%)_!h=WIhgu~t+&oIF_&Nzbui=-?uMHOA)|{R;ka=&OP)nS~2O^ANUJ-5jx~*%ZEb z^a46*wHP?*MH@KTX9l}z`CYA8wG0O|8180M#CLaP4fC91Jqf)^`QI|elWmb3_@z=9 zyzS8$kgPBpFj>(WMElYh(Ac3@Tf1RZcQAydw6cK46p9DNvQ7rZmN^E-#CAYq=J}wp z8tkiCuZUrvI=$U2A?j=HbsR4d&xnoAlS~KBPh@$A*h=~1ym}b0lH;S1En@Gr$)KZ zRYV-nRW6>wi$$ieRFpQrrA|qnEA=6sD~~)^oR+Dc)(0%kq~>9n94?ZRMckAYWd^&q zepJrjs))?#e99rSjNwVP@YBtOh*J{X&y6vd(&vySe*O5*aFw>IX-XKD_7j%W!jJl4 z{zJyPWOqz$dLJnb3$plsjvd2@p3Fesa|Ym=4<#^D5m$wKDU41{BaF_ED1y!@4J@~0 zdxL_?GJv=9 z?ZMlvdRLc21mNw=GVpdyIrwJ=8K|Fs2K=*B1>76T0q)&I8i2Y1Tp3AZda`oq3F3c~ z7L>h2N3(7TgQHm+c>ARaexG3NI|%@+AJQ%Umkswx7*p8zFX2q|KZLRWaO41{FzSj{ zF0ROGuFhsZ?aZ9z?9Cl8B^}(1ZN11p>1{SnD+{1_!XA@JS>))3dQ9UUcgc z*uAEYTzL68L`dHx`F%dPA!{COc`OuvELm1tZ@IusJAFNiLS`jPdtyAIphAmi)pCwn zG@U#skyb1+M|7qL2C+curWm0oM=7X}={f(4PJ_q_rR6%V-A%q&Vv%LH%lZ2DxN|o0 z9;cK{YFgHI*3%^4!rRNn?0R_~)R00R)=)o1DtewkbaVQ$5s}V{_8WLyQODy6^_@4Sb9;eLnA-=INi-kc zxMyq59T)!jNAC6`ri2LbA7vfT0e5)OD&HJ}?HIQZ1qlD1^wh1{9+MiNDz3*62~y*o zLO>acjLMgBYO81<*_~iQ{E~w-0}GofE2xhPW}l38@;E~@j6E-t{igRC`3IvT<@rRI zGXU;@x(!B2{bH+PMoK;`cHsBGCszZzwVW|Gx0h>w#}uCW_hBP5-~B{_m%DSdaUp2Y zX=Xh%Icw>}UO#1$zxN+G4M<$uGLqL2hcMQD?_}>tb{%C?;m)z*U6xS3)&Q ztAR2+TVN;77tF2PI_xcf+^u_bnAsym5gvA$=TL)Zp^jM2qZdo0qws)Ix=umDiaar8 z*R4lHEPqDd!oZfR(Ko6gy0c$hmM=l=TLdsd!L>OSHz61KQgfAgEBf>l<8`3+KF|6n zJhi=ZPPFk-2;rluLS3&#_!UTbQN=e00D|{IK;%FJ(=LKBB@pDZ!_$Q{E2jRzm@Y2= z#-grZ#X=Ytvo00v)x z`~~y^*_(23>wyICY+F?fEy(>7Y$h`Kj((seum1L*-mAM-!Ip%n!5WvMoivAK!D{mm zP}WfVLsqZJ;rvThO!H4jex{}|$*S1|!B|tbopNy^kmIew0uL&s;>GIJ?DG>c^+rZ3 z{5_m3^~G3Sz9eN=jE<54=~2vB%90LlOuUAqn9d}s#rOT z(D@1c1#LWP`)FCJAIX=bpVNW4Wj-{0#i^{*ZHl=K$oW{!0O^}s_&W}FyYvf0r)1BV zJF}Lr7MNw`V&a#f`sE_NLHZfh_eau`C@3hS=hY$!p%6_`kKeBFg#0i zyeID?y-cL0Mn!s9*V%744YGT?V0_k^GQ(%=R*yd5$^{`RN3`|V<5{Ia$ZHi=7H=6e4+I)jOiTgJkA0;7^SQg_RU>4mW ze+wEt=PUML)(hj9bxx&!<)kcxciMda1S(4BW!AA(_ROW*!o1xhhC-kP?^!rm2) zl@eJ;bo|(Z$I*06C)Kz`o`b!EmcF z5NYVQU+)Rwy9Uy32qgpJm*4k~wCBZi7VQ$Ed_((FEtMf0nYoF;bK&jh@UvtJSj4%c_C+8^06d=>XRq_qHuIkO6BLgF(BhFqTqs8 z!19iBM&Wn$@Nbr`>ry;oU8}qr9z~Po<}!kh1mD1uP9dNNQ6l)hJx7ZC{1^PUj5ksC zXH)IbL#E`Jjc-Xgx$!j;ub1n=4oI%7z|FGc|Fpt0QS+mg1Ner8{~qNR3>@(|M)2sS}kswKYv&8n|haFe&pL4KN6+ zOdkm%S6^^6O=q4NSZ8x+q_FzacG0t+caG{#W79_{((uted^Y^x9jJq6IQgJ8MJtNX zg(6Xj%`8A`70hY&OFYR}P-re9dD;aqJgHkb-(A}oVe5E(#QU$f&fm4f3&)Iw@AaCB zst>n`ZI!C`_+lbyuaDF6{to{OM0OCbFT%k>&w0#ZNBZ_k%i#Kh{qKzA&;x2f7OCV( zwuBAgwMTgp!Sj^FhUz+L)~rdF$n-;%6uzpb`39pAd#+sPKr8ZJx`5L0zjT{FM?HR1 z!4?dYYjikWW|(-=)pf|BMT>bl>z^lg7R;-B9}MZcf#A1gEfw1@JZe}nQ&Ph;Inhy> zp)p+!>daNadL~rL?V`1!sU9AM`6K4L^y_kky_i) zuFgm)r4}S1>?~mkU$kt}McbfG14pRlY-%KHATVSX+WYy#pTj)2AQh>=Fr#>Xrcd(iE!*aE zkQKR@&5`Uw8ZfI+td>N8NHo*NUVo=5<6up;l~Dp{mRmTyKWC{ZReEG$UG!xTIYyB% z$Sd_Ko@6lk=enN1s>mH^Bz`7QMKCuuO8Du}L^ zPPNjn=<#lM_c|L3`}@7H<003A zr;yC=ua44R3~c;Lc5!g{io_?E>GITXwLt^|w(W(*u=KFQcP>#s(HB+!aAls@=gyha zcUZ;_AS-vDvcVF=L-gBI{auJt{4?KUX0e_sKKQezFQ{IK2vBBLYjRZ2lt7b~&}m3( zV$!xWuW+hipb~*6v7kMZx){kD=bD*0Q;DtNfM1#eZHb7|qNy!rf=Z2Yc^d6fRFBSh zK7JG41GzSjq}4z^VHw(}Gg6+)oZ#1ASB||q$t9M6JK9*tjgjH5pDjuK)4m$sMQz4- z8v_CRwf6i1-c2NAvF&~FTE}>!1sr`FAXD-|1cCJ}*5PmA&6}<*>BDba=tMaOOW6VU zGn;@v%z1D+SKR|&2^aM56r3lm1d5F{hKbjEys6CU0n@H0>RfPgd3$K136Bm7*WFgI z=nMgm`_rZ|M4a@DO3dvAzsmyZ} z7(GQ_rL(2%O(w6yiq6MFtS?!1eOUV2jE5<{{tdL-Rs@sdh3r#KI-_LPkgq@z8-m#% znSe{cas4!p=|E%pM+QHX=6fSLdHnn9cWvwS=GM?ML|t`^si>Qzk3J$S%Xc%*Vv5_= zLEKJ2nEiW6Jr`PueRd@lMa#_>dGSN%u~XWUeTnY zbV`b=aW0*iIlz($n|`(}QKejx&m9=9i7khNcgCpEFH|4qW@Xy%>4j0zZ22v4{cl2n z)F1m;G@$T6PstY-=McEBUn8~ppTq2R`PITu#VB*Hi|@fyh9kQn)1oOO?BSJWd6q@P zCuWTUkWiAUVn{PFfMo27v6@*+!SDZY64hiDSY7siS&V)KAc;8J2ia~)=VYuHn9lp| zBzw7{2$sQ7TeZH6jhNctGWB}l-48Z3t5WTLoy1FZ35Fp>f_$z(sK|Am=|3M$pdG>c z!F0@BvqET<8pG@G#uwt7MInNTxSibV0Uok2BM%rIGb99(V6)X^r8|c zY2qam&K~b|A@}+>0ldm6rOkuGp!>@L+Kl8kvRo&X5TnCySV^<#mGfnLE=T@ZHLAmZ zI>42W-aPCUQ6cZN^-^Hxsq&A#$-g&LU9OKk*Mx)9{?PTiXOW)NTeM5~6F*HM+g_BWs`FT|%?Ct&cYgFh2`Rc~F=~oGD zo^BeHk;$;M7@fieCTBJB!^X&gFcKSCSF4=9uyMl^(PVImy?q>_dOR`;rL3=ALn9cr zbA+LwOnbLQnV89UJpT=*9EjC?U zG3nE>JJkd$i%oZ3#K(OtxNo#`&cRYx3aHY@x9V=Dt{b9yNit=tf27yRyPrAl#Xhek z2G8t~kz}gkzG6Wizos4U5MTr7%h-ScxiI9| ziD=?pkWgdc&+!5>B}K2(wI-pm-K#k$<~dZ~&FREmAOsM8+{xl?#ZOSi-40YM`Jd=_ zba2pcj=J?JO?RoC(N6!BNZvcEbHzG`m+u^=84dr^-D&0Rw4#R^!XTo2Xu|)tkaBAD z{o#AaF-0CQ4ww)<#)hun`?|_h3NLXQQ2_!SQ#UwncevhV`I>!VotUFr$ zmr%=X&pa;^WPt%Ix8`ASmIwphP;Y%p`e$RLbr$J-NK>d;^0j z-O@>SWZZ!2_FW_8T>uhQaAU+F1-F=0{ga$Of<&6kS-Tk@;(NM`*gt-GDVc#-;mg_B zOC1!nS8mcAu}h*mScp{g@={ngBRN_RkxP`p=Lr?QcoR(#ZF8daqnNel zqbQm^vn511{jlW$U*eIwBmPkyYYLJ4h-7ZX=O0$cdrq)`3p$!sRBU2&j7&;xf!~Lk zhU8xTt}vX8XOfSoiqoIvG6DsEKV~+IXkf5m)($zopkHEx$fg5ZA;WiGWDJ5?J+hcF zCcy0uiUVy-D?~7|5y_t&{7J?X_b^g2K*Z|opLx#Yh3N>~BTEZPTqaigP2?#-r=dZhT&Hh)|dh4A1e zt>MAw|8vy%{)LNOi0`UrEliPL^%-SRE33z%swwyykNs26K)BLj3EKiQ?lqVhV90hL zoi;V|kfbu0xhXiVTPBj99r3EDZuo6JHYPEfo;VQaH@)dx>UO&xQXnbw%GfnW(t?cR z+^h90|H)D>`d-t>Q6D%+<$KAiEL;_tRniXZa|8kTuH*RqENrUWvZ<8C?2@LrZiP1Y zs}{(u^Ub$Hi>WR_#&`XoTOv`{f)Ig7S|3vfv6O`rSPOU*hGrn$pN^ECWPT$1i>Jk# z%V3aJFjd9Y{q3aVCt_PA1IqG`CuW#WUq_>rNg z14onC8u)p#=|)r7O8#YiiZNYqt#%LNQF+8$q)w8G+cX)!ACm)!$CH=Lh**Ujd>vkR z@`+~S`TB$}MR6juW1@at%ZB`=F*&42fAEPoHm*#aL%4{pTK4rEgl2my4tYi@?L$a| zrV)$joND>kbad8Ps{1{RPvT2{pTJNij4#%}r+`BERY_fdS+i0&rq!)8O1zM$6ImP! z9o`lWD!4{_kK84p885Rk0qa?gfQj77dZ_ds_es11SG8hTZ8Yj2`Go-Cju{?f^#gWT zUGSgMFNN0c(HYQSah|ks7$T*#1h;ZZng&0!Qms|3+OjTYKDY;a?bqw(4wh*JHOea$ zOO!_WSN%pEw>$^~y8US*oCBoOYUL~STHG^)TibN#IXO5zuJx~1DaqDc?<>eQk>iBr z*vdVf6M7&G+6$S2z($#;PByEH8ol^kXBcIq$HJ&r6_VFPe*`NHx9?As4HBH;x_#B0 z-`s~9u+wnUT%*huo+}Baq&X!`1tkf4@o_d`pCD8U8MQWbADCnXVp0m-1yvbRw}oGy z9CS@xI5}}G6-Teg?*8rs^j;^!5NfKSl(FzIg&3;7;WD{}(L{3DoL>?b5pV8K&C`$k z63a!~S7N}Q?Bh=(tpsNAip4mdti$f>1Oi0_yPu}P0RVAUYSzybufu<}%#8m{{Qg(V y{HZSfZ{qiV)G~i|{>&EtZ-V2`zDoavL;Qc>{v*)-%rpP5aGzj8ryg8?0sjX8wbs}G literal 0 HcmV?d00001 diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFmatchEff.C b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFmatchEff.C new file mode 100644 index 00000000000..8a709c3de37 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFmatchEff.C @@ -0,0 +1,1417 @@ +#include "CommonDefs.C" + +enum EHisto_t { + kAcceptedTracks, + kMatchedTracks, + kMismatchedTracks, + kUncorrelatedTracks, + kMatchedCorrelatedTracks, + kMatchedGoodTracks, + kNHistos +}; +const Char_t *histoName[kNHistos] = { + "hAcceptedTracks", + "hMatchedTracks", + "hMismatchedTracks", + "hUncorrelatedTracks", + "hMatchedCorrelatedTracks", + "hMatchedGoodTracks" +}; + +enum EParam_t { + kCentrality, + kPt, + kEta, + kPhi, + kNParams +}; + +#define USEHISTOPID 0 + +TOFmatchEff(const Char_t *filename, Int_t evMax = kMaxInt) +{ + + /* include path for ACLic */ + gSystem->AddIncludePath("-I$ALICE_ROOT/include"); + gSystem->AddIncludePath("-I$ALICE_ROOT/TOF"); + /* load libraries */ + gSystem->Load("libANALYSIS"); + gSystem->Load("libANALYSISalice"); + /* build analysis task class */ + gROOT->LoadMacro("AliAnalysisParticle.cxx+g"); + gROOT->LoadMacro("AliAnalysisEvent.cxx+g"); + gROOT->LoadMacro("AliAnalysisTrack.cxx+g"); + + /* open file, get tree and connect */ + TFile *filein = TFile::Open(filename); + TTree *treein = (TTree *)filein->Get("aodTree"); + printf("got \"aodTree\": %d entries\n", treein->GetEntries()); + AliAnalysisEvent *analysisEvent = new AliAnalysisEvent(); + TClonesArray *analysisTrackArray = new TClonesArray("AliAnalysisTrack"); + AliAnalysisTrack *analysisTrack = NULL; + treein->SetBranchAddress("AnalysisEvent", &analysisEvent); + treein->SetBranchAddress("AnalysisTrack", &analysisTrackArray); + + /* open enabled flag map */ + TH1F *hEnabledFlag = NULL; + if (enabledChannelsFileName) { + TFile *enabledfile = TFile::Open(enabledChannelsFileName); + hEnabledFlag = (TH1F *)enabledfile->Get("hEnabledFlag"); + } + + /* binning */ + for (Int_t ieta = 0; ieta < NetaBins + 1; ieta++) + etaBin[ieta] = etaMin + ieta * etaStep; + for (Int_t iphi = 0; iphi < NphiBins + 1; iphi++) + phiBin[iphi] = phiMin + iphi * phiStep; + /* THnSparse */ + Int_t NparamBins[kNParams] = {NcentralityBins, NptBins, NetaBins, NphiBins}; + Double_t *paramBin[kNParams] = {centralityBin, ptBin, etaBin, phiBin}; + THnSparseF *hHisto[kNHistos][kNCharges]; + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + hHisto[ihisto][icharge] = new THnSparseF(Form("hHisto_%s_%s", histoName[ihisto], chargeName[icharge]), "", kNParams, NparamBins); + for (Int_t iparam = 0; iparam < kNParams; iparam++) + hHisto[ihisto][icharge]->SetBinEdges(iparam, paramBin[iparam]); + } +#if USEHISTOPID + TH2F *hHistoPID[kNHistos][AliPID::kSPECIES][kNCharges]; + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + + + + hHistoPID[ihisto][ipart][icharge] = new TH2F(Form("hHistoPID_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge]), "", NcentralityBins, centralityBin, NptBins, ptBin); + } +#endif + /* histos */ + TH2F *hFEAMap = new TH2F("hFEAMap", "", 72, 0., 18., 91, 0., 91.); + + /* start stopwatch */ + TStopwatch timer; + timer.Start(); + + /* loop over events */ + Double_t param[kNParams]; + Int_t charge; + Int_t index, sector, sectorStrip, padx, fea; + Float_t hitmapx, hitmapy; + AliTOFcalibHisto calib; + calib.LoadCalibHisto(); + for (Int_t iev = 0; iev < treein->GetEntries() && iev < evMax; iev++) { + /* get event */ + treein->GetEvent(iev); + if (iev % 10000 == 0) printf("iev = %d\n", iev); + /* check vertex */ + if (!analysisEvent->AcceptEvent(acceptEventType)) continue; + + /*** ACCEPTED EVENT ***/ + + /* get centrality */ + param[kCentrality] = analysisEvent->GetCentralityPercentile(centralityEstimator); + + /* loop over tracks */ + for (Int_t itrk = 0; itrk < analysisTrackArray->GetEntries(); itrk++) { + /* get track */ + analysisTrack = (AliAnalysisTrack *)analysisTrackArray->At(itrk); + if (!analysisTrack) continue; + /* check accepted track */ + if (!analysisTrack->AcceptTrack()) continue; + + /*** ACCEPTED TRACK ***/ + + /* get track info */ + param[kPt] = analysisTrack->GetPt(); + param[kEta] = analysisTrack->GetEta(); + param[kPhi] = analysisTrack->GetPhi(); + charge = analysisTrack->GetSign() > 0. ? kPositive : kNegative; + index = analysisTrack->GetTOFIndex(); + + /* fill accepted tracks histos */ + hHisto[kAcceptedTracks][charge]->Fill(param); +#if USEHISTOPID + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) { + + if (analysisTrack->GetY(AliPID::ParticleMass(ipart)) - rapidityShift > rapidityMaxCut || + analysisTrack->GetY(AliPID::ParticleMass(ipart)) - rapidityShift < rapidityMinCut) continue; + + hHistoPID[kAcceptedTracks][ipart][charge]->Fill(param[kCentrality], param[kPt]); + } +#endif + + /* check TOF PID */ + if (!analysisTrack->HasTOFPID(hEnabledFlag)) continue; + + /*** ACCEPTED TRACK WITH TOF SIGNAL ***/ + + /* fill FEA map */ + sector = calib.GetCalibMap(AliTOFcalibHisto::kSector, index); + sectorStrip = calib.GetCalibMap(AliTOFcalibHisto::kSectorStrip, index); + padx = calib.GetCalibMap(AliTOFcalibHisto::kPadX, index); + fea = padx / 12; + hitmapx = sector + ((Double_t)(3 - fea) + 0.5) / 4.; + hitmapy = sectorStrip; + hFEAMap->Fill(hitmapx, hitmapy); + + /* fill matched tracks histos */ + hHisto[kMatchedTracks][charge]->Fill(param); + if (!analysisTrack->IsMismatchMC()) { + hHisto[kMatchedGoodTracks][charge]->Fill(param); + hHisto[kMatchedCorrelatedTracks][charge]->Fill(param); + } + else { + hHisto[kMismatchedTracks][charge]->Fill(param); + if (!analysisTrack->IsUncorrelatedMismatchMC()) + hHisto[kMatchedCorrelatedTracks][charge]->Fill(param); + else + hHisto[kUncorrelatedTracks][charge]->Fill(param); + } +#if USEHISTOPID + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) { + if (analysisTrack->GetY(AliPID::ParticleMass(ipart)) - rapidityShift > rapidityMaxCut || + analysisTrack->GetY(AliPID::ParticleMass(ipart)) - rapidityShift < rapidityMinCut) continue; + hHistoPID[kMatchedTracks][ipart][charge]->Fill(param[kCentrality], param[kPt]); + if (!analysisTrack->IsMismatchMC()) { + hHistoPID[kMatchedGoodTracks][ipart][charge]->Fill(param); + hHistoPID[kMatchedCorrelatedTracks][ipart][charge]->Fill(param); + } + else { + hHistoPID[kMismatchedTracks][ipart][charge]->Fill(param); + if (!analysisTrack->IsUncorrelatedMismatchMC()) + hHistoPID[kMatchedCorrelatedTracks][ipart][charge]->Fill(param); + else + hHistoPID[kUncorrelatedTracks][ipart][charge]->Fill(param); + } + } +#endif + } + } + + /* stop stopwatch */ + timer.Stop(); + timer.Print(); + + TFile *fileout = TFile::Open(Form("TOFmatchEff.%s", filename), "RECREATE"); + hFEAMap->Write(); + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + hHisto[ihisto][icharge]->Write(); + } +#if USEHISTOPID + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + hHistoPID[ihisto][ipart][icharge]->Write(); + } +#endif + fileout->Close(); + + TString str = Form("TOFmatchEff.%s", filename); + TOFmatchEff_efficiencyPt(str.Data()); + TOFmatchEff_efficiencyEta(str.Data()); + TOFmatchEff_efficiencyPhi(str.Data()); +} + +//_____________________________________________________________________________- + +TOFmatchEff_efficiencyPt(const Char_t *filename) +{ + + /* get data */ + TFile *filein = TFile::Open(filename); + THnSparseF *hHisto[kNHistos][kNCharges]; + TH2F *hHistoPID[kNHistos][AliPID::kSPECIES][kNCharges]; + TH1D *hHistoPt_MB[kNHistos][kNCharges], *hHistoPt_centrality[NcentralityBins][kNHistos][kNCharges]; + TH1D *hHistoPIDPt_MB[kNHistos][AliPID::kSPECIES][kNCharges], *hHistoPIDPt_centrality[NcentralityBins][kNHistos][AliPID::kSPECIES][kNCharges]; + TH1D *hHistoAllPt_MB[kNHistos], *hHistoAllPt_centrality[NcentralityBins][kNHistos]; + /* loop over histos */ + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) { + + /* INCLUSIVE */ + + hHistoAllPt_MB[ihisto] = new TH1D(Form("hHistoAllPt_MB_%s", histoName[ihisto]), "", NptBins, ptBin); + for (Int_t icent = 0; icent < NcentralityBins; icent++) + hHistoAllPt_centrality[icent][ihisto] = new TH1D(Form("hHistoAllPt_centrality%d_%s", icent, histoName[ihisto]), "", NptBins, ptBin); + + /* SINGLE PARTICLE */ + + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + + /* get histo */ + hHisto[ihisto][icharge] = (THnSparseF *)filein->Get(Form("hHisto_%s_%s", histoName[ihisto], chargeName[icharge])); + + /* MB projection */ + hHistoPt_MB[ihisto][icharge] = hHisto[ihisto][icharge]->Projection(kPt); + hHistoPt_MB[ihisto][icharge]->SetName(Form("hHistoPt_MB_%s_%s", histoName[ihisto], chargeName[icharge])); + hHistoPt_MB[ihisto][icharge]->Sumw2(); + hHistoAllPt_MB[ihisto]->Add(hHistoPt_MB[ihisto][icharge]); + + /* centrality projection */ + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + + hHisto[ihisto][icharge]->GetAxis(kCentrality)->SetRange(icent + 1, icent + 1); + hHistoPt_centrality[icent][ihisto][icharge] = hHisto[ihisto][icharge]->Projection(kPt); + hHistoPt_centrality[icent][ihisto][icharge]->SetName(Form("hHistoPt_centrality%d_%s_%s", icent, histoName[ihisto], chargeName[icharge])); + hHistoPt_centrality[icent][ihisto][icharge]->Sumw2(); + hHistoAllPt_centrality[icent][ihisto]->Add(hHistoPt_centrality[icent][ihisto][icharge]); + } + +#if USEHISTOPID + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) { + + /* get histo */ + hHistoPID[ihisto][ipart][icharge] = (TH2F *)filein->Get(Form("hHistoPID_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + + /* MB projection */ + hHistoPIDPt_MB[ihisto][ipart][icharge] = hHistoPID[ihisto][ipart][icharge]->ProjectionY("hpy"); + hHistoPIDPt_MB[ihisto][ipart][icharge]->SetName(Form("hHistoPIDPt_MB_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hHistoPIDPt_MB[ihisto][ipart][icharge]->Sumw2(); + + /* centrality projection */ + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + hHistoPIDPt_centrality[icent][ihisto][ipart][icharge] = hHistoPID[ihisto][ipart][icharge]->ProjectionY("hpy", icent + 1, icent + 1); + hHistoPIDPt_centrality[icent][ihisto][ipart][icharge]->SetName(Form("hHistoPIDPt_centrality%d_%s_%s_%s", icent, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hHistoPIDPt_centrality[icent][ihisto][ipart][icharge]->Sumw2(); + + } + + } +#endif + + } + } + + /* output */ + TString str = filename; + str.Insert(str.Length() - TString(".root").Length(), ".efficiencyPt"); + TFile *fileout = TFile::Open(str.Data(), "RECREATE"); + + /* efficiencies/fractions and write */ + TH1D *hEfficiencyPt_MB[kNHistos][kNCharges], *hEfficiencyPt_centrality[NcentralityBins][kNHistos][kNCharges], *hEfficiencyPt_ratioMB_centrality[NcentralityBins][kNHistos][kNCharges]; + TH1D *hEfficiencyPIDPt_MB[kNHistos][AliPID::kSPECIES][kNCharges], *hEfficiencyPIDPt_centrality[NcentralityBins][kNHistos][AliPID::kSPECIES][kNCharges], *hEfficiencyPIDPt_ratioMB_centrality[NcentralityBins][kNHistos][AliPID::kSPECIES][kNCharges]; + TH1D *hEfficiencyAllPt_MB[kNHistos], *hEfficiencyAllPt_centrality[NcentralityBins][kNHistos], *hEfficiencyAllPt_ratioMB_centrality[NcentralityBins][kNHistos]; + + TH1D *hFractionPt_MB[kNHistos][kNCharges], *hFractionPt_centrality[NcentralityBins][kNHistos][kNCharges], *hFractionPt_ratioMB_centrality[NcentralityBins][kNHistos][kNCharges]; + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) { + + if (ihisto == kAcceptedTracks) continue; + + /* INCLUSIVE */ + + /* MB efficiency */ + hEfficiencyAllPt_MB[ihisto] = new TH1D(*hHistoAllPt_MB[ihisto]); + hEfficiencyAllPt_MB[ihisto]->SetName(Form("hEfficiencyAllPt_MB_%s", histoName[ihisto])); + hEfficiencyAllPt_MB[ihisto]->SetLineWidth(2); + hEfficiencyAllPt_MB[ihisto]->SetLineColor(1); + hEfficiencyAllPt_MB[ihisto]->SetMarkerStyle(20); + hEfficiencyAllPt_MB[ihisto]->SetMarkerColor(1); + hEfficiencyAllPt_MB[ihisto]->Divide(hEfficiencyAllPt_MB[ihisto], hHistoAllPt_MB[kAcceptedTracks], 1, 1, "B"); + hEfficiencyAllPt_MB[ihisto]->Write(); + + /* multiplicity/centrality efficiency */ + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + hEfficiencyAllPt_centrality[icent][ihisto] = new TH1D(*hHistoAllPt_centrality[icent][ihisto]); + hEfficiencyAllPt_centrality[icent][ihisto]->SetName(Form("hEfficiencyAllPt_centrality%d_%s", icent, histoName[ihisto])); + hEfficiencyAllPt_centrality[icent][ihisto]->SetLineWidth(2); + hEfficiencyAllPt_centrality[icent][ihisto]->SetLineColor(multcentColor[icent]); + hEfficiencyAllPt_centrality[icent][ihisto]->SetMarkerStyle(20); + hEfficiencyAllPt_centrality[icent][ihisto]->SetMarkerColor(multcentColor[icent]); + hEfficiencyAllPt_centrality[icent][ihisto]->Divide(hEfficiencyAllPt_centrality[icent][ihisto], hHistoAllPt_centrality[icent][kAcceptedTracks], 1, 1, "B"); + hEfficiencyAllPt_centrality[icent][ihisto]->Write(); + + /* ratio wrt. MB */ + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto] = new TH1D(*hEfficiencyAllPt_centrality[icent][ihisto]); + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto]->SetName(Form("hEfficiencyAllPt_ratioMB_centrality%d_%s", icent, histoName[ihisto])); + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto]->SetLineWidth(2); + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto]->SetLineColor(multcentColor[icent]); + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto]->SetMarkerStyle(20); + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto]->SetMarkerColor(multcentColor[icent]); + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto]->Divide(hEfficiencyAllPt_MB[ihisto]); + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto]->Write(); + } + + /* SINGLE PARTICLE */ + + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + + /* MB efficiency */ + hEfficiencyPt_MB[ihisto][icharge] = new TH1D(*hHistoPt_MB[ihisto][icharge]); + hEfficiencyPt_MB[ihisto][icharge]->SetName(Form("hEfficiencyPt_MB_%s_%s", histoName[ihisto], chargeName[icharge])); + hEfficiencyPt_MB[ihisto][icharge]->SetLineWidth(2); + hEfficiencyPt_MB[ihisto][icharge]->SetLineColor(1); + hEfficiencyPt_MB[ihisto][icharge]->SetMarkerStyle(20); + hEfficiencyPt_MB[ihisto][icharge]->SetMarkerColor(1); + hEfficiencyPt_MB[ihisto][icharge]->Divide(hEfficiencyPt_MB[ihisto][icharge], hHistoPt_MB[kAcceptedTracks][icharge], 1, 1, "B"); + hEfficiencyPt_MB[ihisto][icharge]->Write(); + + /* multiplicity/centrality efficiency */ + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + hEfficiencyPt_centrality[icent][ihisto][icharge] = new TH1D(*hHistoPt_centrality[icent][ihisto][icharge]); + hEfficiencyPt_centrality[icent][ihisto][icharge]->SetName(Form("hEfficiencyPt_centrality%d_%s_%s", icent, histoName[ihisto], chargeName[icharge])); + hEfficiencyPt_centrality[icent][ihisto][icharge]->SetLineWidth(2); + hEfficiencyPt_centrality[icent][ihisto][icharge]->SetLineColor(multcentColor[icent]); + hEfficiencyPt_centrality[icent][ihisto][icharge]->SetMarkerStyle(20); + hEfficiencyPt_centrality[icent][ihisto][icharge]->SetMarkerColor(multcentColor[icent]); + hEfficiencyPt_centrality[icent][ihisto][icharge]->Divide(hEfficiencyPt_centrality[icent][ihisto][icharge], hHistoPt_centrality[icent][kAcceptedTracks][icharge], 1, 1, "B"); + hEfficiencyPt_centrality[icent][ihisto][icharge]->Write(); + + /* ratio wrt. MB */ + hEfficiencyPt_ratioMB_centrality[icent][ihisto][icharge] = new TH1D(*hEfficiencyPt_centrality[icent][ihisto][icharge]); + hEfficiencyPt_ratioMB_centrality[icent][ihisto][icharge]->SetName(Form("hEfficiencyPt_ratioMB_centrality%d_%s_%s", icent, histoName[ihisto], chargeName[icharge])); + hEfficiencyPt_ratioMB_centrality[icent][ihisto][icharge]->SetLineWidth(2); + hEfficiencyPt_ratioMB_centrality[icent][ihisto][icharge]->SetLineColor(multcentColor[icent]); + hEfficiencyPt_ratioMB_centrality[icent][ihisto][icharge]->SetMarkerStyle(20); + hEfficiencyPt_ratioMB_centrality[icent][ihisto][icharge]->SetMarkerColor(multcentColor[icent]); + hEfficiencyPt_ratioMB_centrality[icent][ihisto][icharge]->Divide(hEfficiencyPt_MB[ihisto][icharge]); + hEfficiencyPt_ratioMB_centrality[icent][ihisto][icharge]->Write(); + } + +#if USEHISTOPID + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) { + + /* MB efficiency */ + hEfficiencyPIDPt_MB[ihisto][ipart][icharge] = new TH1D(*hHistoPIDPt_MB[ihisto][ipart][icharge]); + hEfficiencyPIDPt_MB[ihisto][ipart][icharge]->SetName(Form("hEfficiencyPIDPt_MB_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyPIDPt_MB[ihisto][ipart][icharge]->SetLineWidth(2); + hEfficiencyPIDPt_MB[ihisto][ipart][icharge]->SetLineColor(1); + hEfficiencyPIDPt_MB[ihisto][ipart][icharge]->SetMarkerStyle(20); + hEfficiencyPIDPt_MB[ihisto][ipart][icharge]->SetMarkerColor(1); + hEfficiencyPIDPt_MB[ihisto][ipart][icharge]->Divide(hEfficiencyPIDPt_MB[ihisto][ipart][icharge], hHistoPIDPt_MB[kAcceptedTracks][ipart][icharge], 1, 1, "B"); + hEfficiencyPIDPt_MB[ihisto][ipart][icharge]->Write(); + + /* multiplicity/centrality efficiency */ + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + + hEfficiencyPIDPt_centrality[icent][ihisto][ipart][icharge] = new TH1D(*hHistoPIDPt_centrality[icent][ihisto][ipart][icharge]); + hEfficiencyPIDPt_centrality[icent][ihisto][ipart][icharge]->SetName(Form("hEfficiencyPIDPt_centrality%d_%s_%s_%s", icent, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyPIDPt_centrality[icent][ihisto][ipart][icharge]->SetLineWidth(2); + hEfficiencyPIDPt_centrality[icent][ihisto][ipart][icharge]->SetLineColor(multcentColor[icent]); + hEfficiencyPIDPt_centrality[icent][ihisto][ipart][icharge]->SetMarkerStyle(20); + hEfficiencyPIDPt_centrality[icent][ihisto][ipart][icharge]->SetMarkerColor(multcentColor[icent]); + + hEfficiencyPIDPt_centrality[icent][ihisto][ipart][icharge]->Divide(hEfficiencyPIDPt_centrality[icent][ihisto][ipart][icharge], hHistoPIDPt_centrality[icent][kAcceptedTracks][ipart][icharge], 1, 1, "B"); + hEfficiencyPIDPt_centrality[icent][ihisto][ipart][icharge]->Write(); + + /* ratio wrt. MB */ + hEfficiencyPIDPt_ratioMB_centrality[icent][ihisto][ipart][icharge] = new TH1D(*hEfficiencyPIDPt_centrality[icent][ihisto][ipart][icharge]); + hEfficiencyPIDPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetName(Form("hEfficiencyPIDPt_ratioMB_centrality%d_%s_%s_%s", icent, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyPIDPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetLineWidth(2); + hEfficiencyPIDPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetLineColor(multcentColor[icent]); + hEfficiencyPIDPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetMarkerStyle(20); + hEfficiencyPIDPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetMarkerColor(multcentColor[icent]); + hEfficiencyPIDPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->Divide(hEfficiencyPIDPt_MB[ihisto][ipart][icharge]); + hEfficiencyPIDPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->Write(); + } + + + } +#endif + + } + } + + fileout->Close(); + +} + +//_____________________________________________________________________________- + +TOFmatchEff_efficiencyPhi(const Char_t *filename) +{ + + /* get data */ + TFile *filein = TFile::Open(filename); + THnSparseF *hHisto[kNHistos][kNCharges]; + TH1D *hHistoPhi_MB[kNHistos][kNCharges], *hHistoPhi_centrality[NcentralityBins][kNHistos][kNCharges]; + TH1D *hHistoPhi_MB_pt[NptsubBins][kNHistos][kNCharges], *hHistoPhi_centrality_pt[NcentralityBins][NptsubBins][kNHistos][kNCharges]; + /* loop over histos */ + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + + /* get histo */ + hHisto[ihisto][icharge] = (THnSparseF *)filein->Get(Form("hHisto_%s_%s", histoName[ihisto], chargeName[icharge])); + + /* MB projection */ + hHisto[ihisto][icharge]->GetAxis(kPt)->SetRange(0, 0); + hHisto[ihisto][icharge]->GetAxis(kCentrality)->SetRange(0, 0); + hHistoPhi_MB[ihisto][icharge] = hHisto[ihisto][icharge]->Projection(kPhi); + hHistoPhi_MB[ihisto][icharge]->SetName(Form("hHistoPhi_MB_%s_%s", histoName[ihisto], chargeName[icharge])); + hHistoPhi_MB[ihisto][icharge]->Sumw2(); + /* pt bins */ + for (Int_t ipt = 0; ipt < NptsubBins; ipt++) { + hHisto[ihisto][icharge]->GetAxis(kPt)->SetRange(ptsubBinMin[ipt] + 1, ptsubBinMax[ipt] + 1); + hHisto[ihisto][icharge]->GetAxis(kCentrality)->SetRange(0, 0); + hHistoPhi_MB_pt[ipt][ihisto][icharge] = hHisto[ihisto][icharge]->Projection(kPhi); + hHistoPhi_MB_pt[ipt][ihisto][icharge]->SetName(Form("hHistoPhi_MB_pt%d_%s_%s", ipt, histoName[ihisto], chargeName[icharge])); + hHistoPhi_MB_pt[ipt][ihisto][icharge]->Sumw2(); + } + + /* centrality projection */ + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + hHisto[ihisto][icharge]->GetAxis(kPt)->SetRange(0, 0); + hHisto[ihisto][icharge]->GetAxis(kCentrality)->SetRange(icent + 1, icent + 1); + hHistoPhi_centrality[icent][ihisto][icharge] = hHisto[ihisto][icharge]->Projection(kPhi); + hHistoPhi_centrality[icent][ihisto][icharge]->SetName(Form("hHistoPhi_centrality%d_%s_%s", icent, histoName[ihisto], chargeName[icharge])); + hHistoPhi_centrality[icent][ihisto][icharge]->Sumw2(); + /* pt bins */ + for (Int_t ipt = 0; ipt < NptsubBins; ipt++) { + hHisto[ihisto][icharge]->GetAxis(kPt)->SetRange(ptsubBinMin[ipt] + 1, ptsubBinMax[ipt] + 1); + hHisto[ihisto][icharge]->GetAxis(kCentrality)->SetRange(icent + 1, icent + 1); + hHistoPhi_centrality_pt[icent][ipt][ihisto][icharge] = hHisto[ihisto][icharge]->Projection(kPhi); + hHistoPhi_centrality_pt[icent][ipt][ihisto][icharge]->SetName(Form("hHistoPhi_centrality%d_pt%d_%s_%s", icent, ipt, histoName[ihisto], chargeName[icharge])); + hHistoPhi_centrality_pt[icent][ipt][ihisto][icharge]->Sumw2(); + } + } + } + + /* output */ + TString str = filename; + str.Insert(str.Length() - TString(".root").Length(), ".efficiencyPhi"); + TFile *fileout = TFile::Open(str.Data(), "RECREATE"); + + /* efficiencies/fractions and write */ + TH1D *hEfficiencyPhi_MB[kNHistos][kNCharges], *hEfficiencyPhi_centrality[NcentralityBins][kNHistos][kNCharges], *hEfficiencyPhi_ratioMB_centrality[NcentralityBins][kNHistos][kNCharges]; + TH1D *hEfficiencyPhi_MB_pt[NptsubBins][kNHistos][kNCharges], *hEfficiencyPhi_centrality_pt[NcentralityBins][NptsubBins][kNHistos][kNCharges], *hEfficiencyPhi_ratioMB_centrality_pt[NcentralityBins][NptsubBins][kNHistos][kNCharges]; + + + TH1D *hFractionPhi_MB[kNHistos][kNCharges], *hFractionPhi_centrality[NcentralityBins][kNHistos][kNCharges], *hFractionPhi_ratioMB_centrality[NcentralityBins][kNHistos][kNCharges]; + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) { + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + + if (ihisto == kAcceptedTracks) continue; + + /* MB efficiency */ + hEfficiencyPhi_MB[ihisto][icharge] = new TH1D(*hHistoPhi_MB[ihisto][icharge]); + hEfficiencyPhi_MB[ihisto][icharge]->SetName(Form("hEfficiencyPhi_MB_%s_%s", histoName[ihisto], chargeName[icharge])); + hEfficiencyPhi_MB[ihisto][icharge]->SetLineWidth(2); + hEfficiencyPhi_MB[ihisto][icharge]->SetLineColor(1); + hEfficiencyPhi_MB[ihisto][icharge]->SetMarkerStyle(20); + hEfficiencyPhi_MB[ihisto][icharge]->SetMarkerColor(1); + hEfficiencyPhi_MB[ihisto][icharge]->Divide(hEfficiencyPhi_MB[ihisto][icharge], hHistoPhi_MB[kAcceptedTracks][icharge], 1, 1, "B"); + hEfficiencyPhi_MB[ihisto][icharge]->Write(); + /* pt bins */ + for (Int_t ipt = 0; ipt < NptsubBins; ipt++) { + hEfficiencyPhi_MB_pt[ipt][ihisto][icharge] = new TH1D(*hHistoPhi_MB_pt[ipt][ihisto][icharge]); + hEfficiencyPhi_MB_pt[ipt][ihisto][icharge]->SetName(Form("hEfficiencyPhi_MB_pt%d_%s_%s", ipt, histoName[ihisto], chargeName[icharge])); + hEfficiencyPhi_MB_pt[ipt][ihisto][icharge]->SetLineWidth(2); + hEfficiencyPhi_MB_pt[ipt][ihisto][icharge]->SetLineColor(1); + hEfficiencyPhi_MB_pt[ipt][ihisto][icharge]->SetMarkerStyle(20); + hEfficiencyPhi_MB_pt[ipt][ihisto][icharge]->SetMarkerColor(1); + hEfficiencyPhi_MB_pt[ipt][ihisto][icharge]->Divide(hEfficiencyPhi_MB_pt[ipt][ihisto][icharge], hHistoPhi_MB_pt[ipt][kAcceptedTracks][icharge], 1, 1, "B"); + hEfficiencyPhi_MB_pt[ipt][ihisto][icharge]->Write(); + } + + /* multiplicity/centrality efficiency */ + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + hEfficiencyPhi_centrality[icent][ihisto][icharge] = new TH1D(*hHistoPhi_centrality[icent][ihisto][icharge]); + hEfficiencyPhi_centrality[icent][ihisto][icharge]->SetName(Form("hEfficiencyPhi_centrality%d_%s_%s", icent, histoName[ihisto], chargeName[icharge])); + hEfficiencyPhi_centrality[icent][ihisto][icharge]->SetLineWidth(2); + hEfficiencyPhi_centrality[icent][ihisto][icharge]->SetLineColor(multcentColor[icent]); + hEfficiencyPhi_centrality[icent][ihisto][icharge]->SetMarkerStyle(20); + hEfficiencyPhi_centrality[icent][ihisto][icharge]->SetMarkerColor(multcentColor[icent]); + hEfficiencyPhi_centrality[icent][ihisto][icharge]->Divide(hEfficiencyPhi_centrality[icent][ihisto][icharge], hHistoPhi_centrality[icent][kAcceptedTracks][icharge], 1, 1, "B"); + hEfficiencyPhi_centrality[icent][ihisto][icharge]->Write(); + + /* ratio wrt. MB */ + hEfficiencyPhi_ratioMB_centrality[icent][ihisto][icharge] = new TH1D(*hEfficiencyPhi_centrality[icent][ihisto][icharge]); + hEfficiencyPhi_ratioMB_centrality[icent][ihisto][icharge]->SetName(Form("hEfficiencyPhi_ratioMB_centrality%d_%s_%s", icent, histoName[ihisto], chargeName[icharge])); + hEfficiencyPhi_ratioMB_centrality[icent][ihisto][icharge]->SetLineWidth(2); + hEfficiencyPhi_ratioMB_centrality[icent][ihisto][icharge]->SetLineColor(multcentColor[icent]); + hEfficiencyPhi_ratioMB_centrality[icent][ihisto][icharge]->SetMarkerStyle(20); + hEfficiencyPhi_ratioMB_centrality[icent][ihisto][icharge]->SetMarkerColor(multcentColor[icent]); + hEfficiencyPhi_ratioMB_centrality[icent][ihisto][icharge]->Divide(hEfficiencyPhi_MB[ihisto][icharge]); + hEfficiencyPhi_ratioMB_centrality[icent][ihisto][icharge]->Write(); + } + + } + } + + fileout->Close(); + +} + +//_____________________________________________________________________________- + +TOFmatchEff_efficiencyEta(const Char_t *filename) +{ + + /* get data */ + TFile *filein = TFile::Open(filename); + THnSparseF *hHisto[kNHistos][kNCharges]; + TH1D *hHistoEta_MB[kNHistos][kNCharges], *hHistoEta_centrality[NcentralityBins][kNHistos][kNCharges]; + TH1D *hHistoEta_MB_pt[NptsubBins][kNHistos][kNCharges], *hHistoEta_centrality_pt[NcentralityBins][NptsubBins][kNHistos][kNCharges]; + /* loop over histos */ + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + + /* get histo */ + hHisto[ihisto][icharge] = (THnSparseF *)filein->Get(Form("hHisto_%s_%s", histoName[ihisto], chargeName[icharge])); + + /* MB projection */ + hHisto[ihisto][icharge]->GetAxis(kPt)->SetRange(0, 0); + hHisto[ihisto][icharge]->GetAxis(kCentrality)->SetRange(0, 0); + hHistoEta_MB[ihisto][icharge] = hHisto[ihisto][icharge]->Projection(kEta); + hHistoEta_MB[ihisto][icharge]->SetName(Form("hHistoEta_MB_%s_%s", histoName[ihisto], chargeName[icharge])); + hHistoEta_MB[ihisto][icharge]->Sumw2(); + /* pt bins */ + for (Int_t ipt = 0; ipt < NptsubBins; ipt++) { + hHisto[ihisto][icharge]->GetAxis(kPt)->SetRange(ptsubBinMin[ipt] + 1, ptsubBinMax[ipt] + 1); + hHisto[ihisto][icharge]->GetAxis(kCentrality)->SetRange(0, 0); + hHistoEta_MB_pt[ipt][ihisto][icharge] = hHisto[ihisto][icharge]->Projection(kEta); + hHistoEta_MB_pt[ipt][ihisto][icharge]->SetName(Form("hHistoEta_MB_pt%d_%s_%s", ipt, histoName[ihisto], chargeName[icharge])); + hHistoEta_MB_pt[ipt][ihisto][icharge]->Sumw2(); + } + + /* centrality projection */ + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + hHisto[ihisto][icharge]->GetAxis(kPt)->SetRange(0, 0); + hHisto[ihisto][icharge]->GetAxis(kCentrality)->SetRange(icent + 1, icent + 1); + hHistoEta_centrality[icent][ihisto][icharge] = hHisto[ihisto][icharge]->Projection(kEta); + hHistoEta_centrality[icent][ihisto][icharge]->SetName(Form("hHistoEta_centrality%d_%s_%s", icent, histoName[ihisto], chargeName[icharge])); + hHistoEta_centrality[icent][ihisto][icharge]->Sumw2(); + /* pt bins */ + for (Int_t ipt = 0; ipt < NptsubBins; ipt++) { + hHisto[ihisto][icharge]->GetAxis(kPt)->SetRange(ptsubBinMin[ipt] + 1, ptsubBinMax[ipt] + 1); + hHisto[ihisto][icharge]->GetAxis(kCentrality)->SetRange(icent + 1, icent + 1); + hHistoEta_centrality_pt[icent][ipt][ihisto][icharge] = hHisto[ihisto][icharge]->Projection(kEta); + hHistoEta_centrality_pt[icent][ipt][ihisto][icharge]->SetName(Form("hHistoEta_centrality%d_pt%d_%s_%s", icent, ipt, histoName[ihisto], chargeName[icharge])); + hHistoEta_centrality_pt[icent][ipt][ihisto][icharge]->Sumw2(); + } + } + } + + /* output */ + TString str = filename; + str.Insert(str.Length() - TString(".root").Length(), ".efficiencyEta"); + TFile *fileout = TFile::Open(str.Data(), "RECREATE"); + + /* efficiencies/fractions and write */ + TH1D *hEfficiencyEta_MB[kNHistos][kNCharges], *hEfficiencyEta_centrality[NcentralityBins][kNHistos][kNCharges], *hEfficiencyEta_ratioMB_centrality[NcentralityBins][kNHistos][kNCharges]; + TH1D *hEfficiencyEta_MB_pt[NptsubBins][kNHistos][kNCharges], *hEfficiencyEta_centrality_pt[NcentralityBins][NptsubBins][kNHistos][kNCharges], *hEfficiencyEta_ratioMB_centrality_pt[NcentralityBins][NptsubBins][kNHistos][kNCharges]; + + + TH1D *hFractionEta_MB[kNHistos][kNCharges], *hFractionEta_centrality[NcentralityBins][kNHistos][kNCharges], *hFractionEta_ratioMB_centrality[NcentralityBins][kNHistos][kNCharges]; + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) { + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + + if (ihisto == kAcceptedTracks) continue; + + /* MB efficiency */ + hEfficiencyEta_MB[ihisto][icharge] = new TH1D(*hHistoEta_MB[ihisto][icharge]); + hEfficiencyEta_MB[ihisto][icharge]->SetName(Form("hEfficiencyEta_MB_%s_%s", histoName[ihisto], chargeName[icharge])); + hEfficiencyEta_MB[ihisto][icharge]->SetLineWidth(2); + hEfficiencyEta_MB[ihisto][icharge]->SetLineColor(1); + hEfficiencyEta_MB[ihisto][icharge]->SetMarkerStyle(20); + hEfficiencyEta_MB[ihisto][icharge]->SetMarkerColor(1); + hEfficiencyEta_MB[ihisto][icharge]->Divide(hEfficiencyEta_MB[ihisto][icharge], hHistoEta_MB[kAcceptedTracks][icharge], 1, 1, "B"); + hEfficiencyEta_MB[ihisto][icharge]->Write(); + /* pt bins */ + for (Int_t ipt = 0; ipt < NptsubBins; ipt++) { + hEfficiencyEta_MB_pt[ipt][ihisto][icharge] = new TH1D(*hHistoEta_MB_pt[ipt][ihisto][icharge]); + hEfficiencyEta_MB_pt[ipt][ihisto][icharge]->SetName(Form("hEfficiencyEta_MB_pt%d_%s_%s", ipt, histoName[ihisto], chargeName[icharge])); + hEfficiencyEta_MB_pt[ipt][ihisto][icharge]->SetLineWidth(2); + hEfficiencyEta_MB_pt[ipt][ihisto][icharge]->SetLineColor(1); + hEfficiencyEta_MB_pt[ipt][ihisto][icharge]->SetMarkerStyle(20); + hEfficiencyEta_MB_pt[ipt][ihisto][icharge]->SetMarkerColor(1); + hEfficiencyEta_MB_pt[ipt][ihisto][icharge]->Divide(hEfficiencyEta_MB_pt[ipt][ihisto][icharge], hHistoEta_MB_pt[ipt][kAcceptedTracks][icharge], 1, 1, "B"); + hEfficiencyEta_MB_pt[ipt][ihisto][icharge]->Write(); + } + + /* multiplicity/centrality efficiency */ + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + hEfficiencyEta_centrality[icent][ihisto][icharge] = new TH1D(*hHistoEta_centrality[icent][ihisto][icharge]); + hEfficiencyEta_centrality[icent][ihisto][icharge]->SetName(Form("hEfficiencyEta_centrality%d_%s_%s", icent, histoName[ihisto], chargeName[icharge])); + hEfficiencyEta_centrality[icent][ihisto][icharge]->SetLineWidth(2); + hEfficiencyEta_centrality[icent][ihisto][icharge]->SetLineColor(multcentColor[icent]); + hEfficiencyEta_centrality[icent][ihisto][icharge]->SetMarkerStyle(20); + hEfficiencyEta_centrality[icent][ihisto][icharge]->SetMarkerColor(multcentColor[icent]); + hEfficiencyEta_centrality[icent][ihisto][icharge]->Divide(hEfficiencyEta_centrality[icent][ihisto][icharge], hHistoEta_centrality[icent][kAcceptedTracks][icharge], 1, 1, "B"); + hEfficiencyEta_centrality[icent][ihisto][icharge]->Write(); + + /* ratio wrt. MB */ + hEfficiencyEta_ratioMB_centrality[icent][ihisto][icharge] = new TH1D(*hEfficiencyEta_centrality[icent][ihisto][icharge]); + hEfficiencyEta_ratioMB_centrality[icent][ihisto][icharge]->SetName(Form("hEfficiencyEta_ratioMB_centrality%d_%s_%s", icent, histoName[ihisto], chargeName[icharge])); + hEfficiencyEta_ratioMB_centrality[icent][ihisto][icharge]->SetLineWidth(2); + hEfficiencyEta_ratioMB_centrality[icent][ihisto][icharge]->SetLineColor(multcentColor[icent]); + hEfficiencyEta_ratioMB_centrality[icent][ihisto][icharge]->SetMarkerStyle(20); + hEfficiencyEta_ratioMB_centrality[icent][ihisto][icharge]->SetMarkerColor(multcentColor[icent]); + hEfficiencyEta_ratioMB_centrality[icent][ihisto][icharge]->Divide(hEfficiencyEta_MB[ihisto][icharge]); + hEfficiencyEta_ratioMB_centrality[icent][ihisto][icharge]->Write(); + } + + } + } + + fileout->Close(); + +} + +#if 0 +//_____________________________________________________________________________- + +TOFmatchMC_efficiencyCent(const Char_t *filename, const Char_t *particle = "", const Char_t *charge = "", const Char_t *trdmode = "") +{ + + const Int_t npt = 4; + Double_t pt[npt + 1] = {0., 0.5, 1.0, 1.5, 5.0}; + + /* get data */ + TFile *filein = TFile::Open(filename); + THnSparseF *hHisto[kNHistos]; + TH1D *hHisto_all[kNHistos], *hHisto_MB_all[kNHistos], *hHisto_pt[kNHistos][MAXMULTCENTBINS], *hHisto_MB_pt[kNHistos][MAXMULTCENTBINS]; + /* loop over histos */ + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) { + if (ihisto == kMatchedCorrelatedTracks) continue; + /* get histo */ + hHisto[ihisto] = (THnSparseF *)filein->Get(histoName[ihisto]); + /* set range limits */ + hHisto[ihisto]->GetAxis(kRapidity)->SetRangeUser(-0.5 + kEpsilon, 0.5 - kEpsilon); + hHisto[ihisto]->GetAxis(kEta)->SetRangeUser(-0.8 + kEpsilon, 0.8 - kEpsilon); + hHisto[ihisto]->GetAxis(kPt)->SetRangeUser(0. + kEpsilon, 5.0 - kEpsilon); + /* select particle if requested */ + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) + if (TString(particle) == AliPID::ParticleName(ipart)) + hHisto[ihisto]->GetAxis(kParticle)->SetRange(ipart + 1, ipart + 1); + /* select charge if requested */ + if (TString(charge) == "plus") + hHisto[ihisto]->GetAxis(kCharge)->SetRange(1, 1); + else if (TString(charge) == "minus") + hHisto[ihisto]->GetAxis(kCharge)->SetRange(2, 2); + /* select TRD mode if requested */ + if (TString(trdmode) == "trdout") + hHisto[ihisto]->GetAxis(kTRDmode)->SetRange(1, 1); + else if (TString(trdmode) == "notrdout") + hHisto[ihisto]->GetAxis(kTRDmode)->SetRange(2, 2); + /* all projection */ + hHisto_all[ihisto] = hHisto[ihisto]->Projection(kMultCent); + hHisto_all[ihisto]->SetName(Form("%s_all", histoName[ihisto])); + hHisto_all[ihisto]->Sumw2(); + /* MB all projection */ + hHisto_MB_all[ihisto] = new TH1D(*hHisto_all[ihisto]); + hHisto_MB_all[ihisto]->SetName(Form("%s_MB_all", histoName[ihisto])); + for (Int_t i = 0; i < hHisto_MB_all[ihisto]->GetNbinsX(); i++) { + hHisto_MB_all[ihisto]->SetBinContent(i + 1, hHisto_all[ihisto]->Integral()); + hHisto_MB_all[ihisto]->SetBinError(i + 1, TMath::Sqrt(hHisto_all[ihisto]->Integral())); + } + /* pt projection */ + for (Int_t ibin = 0; ibin < npt; ibin++) { + hHisto[ihisto]->GetAxis(kPt)->SetRangeUser(pt[ibin] + kEpsilon, pt[ibin + 1] - kEpsilon); + hHisto_pt[ihisto][ibin] = hHisto[ihisto]->Projection(kMultCent); + hHisto_pt[ihisto][ibin]->SetName(Form("%s_pt%3.1f-%3.1f", histoName[ihisto], pt[ibin], pt[ibin + 1])); + hHisto_pt[ihisto][ibin]->Sumw2(); + /* MB pt projection */ + hHisto_MB_pt[ihisto][ibin] = new TH1D(*hHisto_pt[ihisto][ibin]); + hHisto_MB_pt[ihisto][ibin]->SetName(Form("%s_MB_pt%3.1f-%3.1f", histoName[ihisto], pt[ibin], pt[ibin + 1])); + for (Int_t i = 0; i < hHisto_MB_pt[ihisto][ibin]->GetNbinsX(); i++) { + hHisto_MB_pt[ihisto][ibin]->SetBinContent(i + 1, hHisto_pt[ihisto][ibin]->Integral()); + hHisto_MB_pt[ihisto][ibin]->SetBinError(i + 1, TMath::Sqrt(hHisto_pt[ihisto][ibin]->Integral())); + } + } + } + /*** matched correlated histos ***/ + /* all projection */ + hHisto_all[kMatchedCorrelatedTracks] = new TH1D(*hHisto_all[kMatchedTracks]); + hHisto_all[kMatchedCorrelatedTracks]->Add(hHisto_all[kUncorrelatedTracks], -1.); + hHisto_all[kMatchedCorrelatedTracks]->SetName(Form("%s_all", histoName[kMatchedCorrelatedTracks])); + /* MB all projection */ + hHisto_MB_all[kMatchedCorrelatedTracks] = new TH1D(*hHisto_MB_all[kMatchedTracks]); + hHisto_MB_all[kMatchedCorrelatedTracks]->Add(hHisto_MB_all[kUncorrelatedTracks], -1.); + hHisto_MB_all[kMatchedCorrelatedTracks]->SetName(Form("%s_MB_all", histoName[kMatchedCorrelatedTracks])); + /* pt projection */ + for (Int_t ibin = 0; ibin < npt; ibin++) { + hHisto_pt[kMatchedCorrelatedTracks][ibin] = new TH1D(*hHisto_pt[kMatchedTracks][ibin]); + hHisto_pt[kMatchedCorrelatedTracks][ibin]->Add(hHisto_pt[kUncorrelatedTracks][ibin], -1.); + hHisto_pt[kMatchedCorrelatedTracks][ibin]->SetName(Form("%s_pt%3.1f-%3.1f", histoName[kMatchedCorrelatedTracks], pt[ibin], pt[ibin + 1])); + /* MB pt projection */ + hHisto_MB_pt[kMatchedCorrelatedTracks][ibin] = new TH1D(*hHisto_MB_pt[kMatchedTracks][ibin]); + hHisto_MB_pt[kMatchedCorrelatedTracks][ibin]->Add(hHisto_MB_pt[kUncorrelatedTracks][ibin], -1.); + hHisto_MB_pt[kMatchedCorrelatedTracks][ibin]->SetName(Form("%s_MB_pt%3.1f-%3.1f", histoName[kMatchedCorrelatedTracks], pt[ibin], pt[ibin + 1])); + } + + /* output */ + TString str = filename; + str.Insert(str.Length() - TString(".root").Length(), ".efficiencyCent"); + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) + if (TString(particle) == AliPID::ParticleName(ipart)) + str.Insert(str.Length() - TString(".root").Length(), Form(".%s", AliPID::ParticleName(ipart))); + if (TString(charge) == "plus") + str.Insert(str.Length() - TString(".root").Length(), ".plus"); + else if (TString(charge) == "minus") + str.Insert(str.Length() - TString(".root").Length(), ".minus"); + if (TString(trdmode) == "trdout") + str.Insert(str.Length() - TString(".root").Length(), ".trdout"); + else if (TString(trdmode) == "notrdout") + str.Insert(str.Length() - TString(".root").Length(), ".notrdout"); + TFile *fileout = TFile::Open(str.Data(), "RECREATE"); + + /* efficiencies/fractions and write */ + TH1D *hEfficiency_all[kNHistos], *hEfficiency_MB_all[kNHistos], *hEfficiency_ratioMB_all[kNHistos], *hEfficiency_pt[kNHistos][MAXMULTCENTBINS], *hEfficiency_MB_pt[kNHistos][MAXMULTCENTBINS], *hEfficiency_ratioMB_pt[kNHistos][MAXMULTCENTBINS]; + + + // TH1D *hEfficiency_MB[kNHistos], *hEfficiency_multcent[kNHistos][MAXMULTCENTBINS], *hEfficiency_ratioMB_multcent[kNHistos][MAXMULTCENTBINS]; + // TH1D *hFraction_MB[kNHistos], *hFraction_multcent[kNHistos][MAXMULTCENTBINS], *hFraction_ratioMB_multcent[kNHistos][MAXMULTCENTBINS]; + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) { + if (ihisto == kAcceptedTracks) continue; + /* all efficiency */ + hEfficiency_all[ihisto] = new TH1D(*hHisto_all[ihisto]); + hEfficiency_all[ihisto]->SetName(Form("%s_efficiency_all", histoName[ihisto])); + hEfficiency_all[ihisto]->SetLineWidth(2); + hEfficiency_all[ihisto]->SetLineColor(1); + hEfficiency_all[ihisto]->SetMarkerStyle(20); + hEfficiency_all[ihisto]->SetMarkerColor(1); + hEfficiency_all[ihisto]->Divide(hHisto_all[kAcceptedTracks]); + hEfficiency_all[ihisto]->Write(); + /* MB all efficiency */ + hEfficiency_MB_all[ihisto] = new TH1D(*hHisto_MB_all[ihisto]); + hEfficiency_MB_all[ihisto]->SetName(Form("%s_efficiency_MB_all", histoName[ihisto])); + hEfficiency_MB_all[ihisto]->Divide(hHisto_MB_all[kAcceptedTracks]); + hEfficiency_MB_all[ihisto]->Write(); + /* ratio wrt. MB */ + hEfficiency_ratioMB_all[ihisto] = new TH1D(*hEfficiency_all[ihisto]); + hEfficiency_ratioMB_all[ihisto]->SetName(Form("%s_efficiency_ratioMB_all", histoName[ihisto])); + hEfficiency_ratioMB_all[ihisto]->Divide(hEfficiency_MB_all[ihisto]); + hEfficiency_ratioMB_all[ihisto]->Write(); + /* pt efficiency */ + for (Int_t ibin = 0; ibin < npt; ibin++) { + hEfficiency_pt[ihisto][ibin] = new TH1D(*hHisto_pt[ihisto][ibin]); + hEfficiency_pt[ihisto][ibin]->SetName(Form("%s_efficiency_pt%3.1f-%3.1f", histoName[ihisto], pt[ibin], pt[ibin + 1])); + hEfficiency_pt[ihisto][ibin]->SetLineWidth(2); + hEfficiency_pt[ihisto][ibin]->SetLineColor(multcentColor[ibin]); + hEfficiency_pt[ihisto][ibin]->SetMarkerStyle(20); + hEfficiency_pt[ihisto][ibin]->SetMarkerColor(multcentColor[ibin]); + hEfficiency_pt[ihisto][ibin]->Divide(hHisto_pt[kAcceptedTracks][ibin]); + hEfficiency_pt[ihisto][ibin]->Write(); + /* MB pt efficiency */ + hEfficiency_MB_pt[ihisto][ibin] = new TH1D(*hHisto_MB_pt[ihisto][ibin]); + hEfficiency_MB_pt[ihisto][ibin]->SetName(Form("%s_efficiency_MB_pt%3.1f-%3.1f", histoName[ihisto], pt[ibin], pt[ibin + 1])); + hEfficiency_MB_pt[ihisto][ibin]->Divide(hHisto_MB_pt[kAcceptedTracks][ibin]); + hEfficiency_MB_pt[ihisto][ibin]->Write(); + /* ratio wrt. central */ + hEfficiency_ratioMB_pt[ihisto][ibin] = new TH1D(*hEfficiency_pt[ihisto][ibin]); + hEfficiency_ratioMB_pt[ihisto][ibin]->SetName(Form("%s_efficiency_ratioMB_pt%3.1f-%3.1f", histoName[ihisto], pt[ibin], pt[ibin + 1])); + hEfficiency_ratioMB_pt[ihisto][ibin]->Divide(hEfficiency_MB_pt[ihisto][ibin]); + hEfficiency_ratioMB_pt[ihisto][ibin]->Write(); + } + +#if 0 + + if (ihisto == kAcceptedTracks || ihisto == kMatchedTracks) continue; + /* MB fraction */ + hFraction_MB[ihisto] = new TH1D(*hHisto_MB[ihisto]); + hFraction_MB[ihisto]->SetName(Form("%s_fraction_MB", histoName[ihisto])); + hFraction_MB[ihisto]->SetLineWidth(2); + hFraction_MB[ihisto]->SetLineColor(1); + hFraction_MB[ihisto]->SetMarkerStyle(20); + hFraction_MB[ihisto]->SetMarkerColor(1); + hFraction_MB[ihisto]->Divide(hHisto_MB[kMatchedTracks]); + hFraction_MB[ihisto]->Write(); + /* multiplicity/centrality fraction */ + for (Int_t ibin = 0; ibin < hHisto[kMatchedTracks]->GetAxis(kMultCent)->GetNbins(); ibin++) { + hFraction_multcent[ihisto][ibin] = new TH1D(*hHisto_multcent[ihisto][ibin]); + hFraction_multcent[ihisto][ibin]->SetName(Form("%s_fraction_multcent%d", histoName[ihisto], ibin)); + hFraction_multcent[ihisto][ibin]->SetLineWidth(2); + hFraction_multcent[ihisto][ibin]->SetLineColor(multcentColor[ibin]); + hFraction_multcent[ihisto][ibin]->SetMarkerStyle(20); + hFraction_multcent[ihisto][ibin]->SetMarkerColor(multcentColor[ibin]); + hFraction_multcent[ihisto][ibin]->Divide(hHisto_multcent[kMatchedTracks][ibin]); + hFraction_multcent[ihisto][ibin]->Write(); + /* ratio wrt. MB */ + hFraction_ratioMB_multcent[ihisto][ibin] = new TH1D(*hFraction_multcent[ihisto][ibin]); + hFraction_ratioMB_multcent[ihisto][ibin]->SetName(Form("%s_fraction_ratioMB_multcent%d", histoName[ihisto], ibin)); + hFraction_ratioMB_multcent[ihisto][ibin]->SetLineWidth(2); + hFraction_ratioMB_multcent[ihisto][ibin]->SetLineColor(multcentColor[ibin]); + hFraction_ratioMB_multcent[ihisto][ibin]->SetMarkerStyle(20); + hFraction_ratioMB_multcent[ihisto][ibin]->SetMarkerColor(multcentColor[ibin]); + hFraction_ratioMB_multcent[ihisto][ibin]->Divide(hFraction_MB[ihisto]); + hFraction_ratioMB_multcent[ihisto][ibin]->Write(); + } + + #endif + + } + fileout->Close(); + +} +#endif + +//_____________________________________________________________________________- + +TH1D * +TOFmatchMC_get(const Char_t *filename, const Char_t *name, Option_t *opt = "", Int_t color = 1, Int_t marker = 20) +{ + + TFile *f = TFile::Open(filename); + if (!f || !f->IsOpen()) + return NULL; + TH1D *h = (TH1D *)f->Get(name); + if (!h) + return NULL; + h->SetLineColor(color); + h->SetLineWidth(2); + h->SetMarkerColor(color); + h->SetMarkerStyle(marker); + h->Draw(opt); + return h; +} + +//_____________________________________________________________________________- + +TH1D * +TOFmatchMC_divide(const Char_t *filename, const Char_t *name1, const Char_t *name2, Option_t *opt = "") +{ + + TFile *f = TFile::Open(filename); + if (!f || !f->IsOpen()) + return NULL; + TH1D *h1 = (TH1D *)f->Get(name1); + TH1D *h2 = (TH1D *)f->Get(name2); + if (!h1 || !h2) + return NULL; + TH1D *hr = new TH1D(*h1); + hr->Divide(h2); + hr->Draw(opt); + return hr; +} + +//_____________________________________________________________________________- + +TH1D * +TOFmatchMC_sub(const Char_t *filename, const Char_t *name1, const Char_t *name2, Option_t *opt = "", Int_t color = 1, Int_t marker = 20) +{ + + TFile *f = TFile::Open(filename); + if (!f || !f->IsOpen()) + return NULL; + TH1D *h1 = (TH1D *)f->Get(name1); + TH1D *h2 = (TH1D *)f->Get(name2); + if (!h1 || !h2) + return NULL; + TH1D *hr = new TH1D(*h1); + hr->Add(h2, -1.); + hr->SetLineColor(color); + hr->SetLineWidth(2); + hr->SetMarkerColor(color); + hr->SetMarkerStyle(marker); + hr->Draw(opt); + return hr; +} + +//_____________________________________________________________________________- + +TH1D * +TOFmatchMC_compare(const Char_t *filename1, const Char_t *filename2, const Char_t *name, Option_t *opt = "", Int_t color = 1, Int_t marker = 20) +{ + + TFile *f1 = TFile::Open(filename1); + TFile *f2 = TFile::Open(filename2); + if (!f1 || !f2 || !f1->IsOpen() || !f2->IsOpen()) + return NULL; + TH1D *h1 = (TH1D *)f1->Get(name); + TH1D *h2 = (TH1D *)f2->Get(name); + if (!h1 || !h2) + return NULL; + TH1D *hr = new TH1D(*h1); + hr->Divide(h2); + hr->SetLineColor(color); + hr->SetLineWidth(2); + hr->SetMarkerColor(color); + hr->SetMarkerStyle(marker); + hr->Draw(opt); + return hr; +} + +//_____________________________________________________________________________- + +TH1D * +TOFmatchMC_comparesub(const Char_t *filename1, const Char_t *filename2, const Char_t *name1, const Char_t *name2, Option_t *opt = "", Int_t color = 1, Int_t marker = 20) +{ + + TFile *f1 = TFile::Open(filename1); + TFile *f2 = TFile::Open(filename2); + if (!f1 || !f2 || !f1->IsOpen() || !f2->IsOpen()) + return NULL; + TH1D *h11 = (TH1D *)f1->Get(name1); + TH1D *h21 = (TH1D *)f2->Get(name1); + TH1D *h12 = (TH1D *)f1->Get(name2); + TH1D *h22 = (TH1D *)f2->Get(name2); + if (!h11 || !h21 || !h12 || !h22) + return NULL; + TH1D *hs1 = new TH1D(*h11); + hs1->Add(h12, -1.); + TH1D *hs2 = new TH1D(*h21); + hs2->Add(h22, -1.); + TH1D *hr = new TH1D(*hs1); + hr->Divide(hs2); + hr->SetLineColor(color); + hr->SetLineWidth(2); + hr->SetMarkerColor(color); + hr->SetMarkerStyle(marker); + hr->Draw(opt); + return hr; +} + + +TH1D * +TOFmatchEff_efficiencyPt_MB_plot(const Char_t *filename, Int_t ihisto = kMatchedTracks, Int_t icharge, Int_t marker = 20, Int_t color = 2, Option_t *opt = "") +{ + + TCanvas *cCanvas1 = new TCanvas("cCanvas1"); + TCanvas *cCanvas2 = new TCanvas("cCanvas2"); + const Char_t *destdir = "matchingEfficiency_DATA"; + + Double_t ptMin = 0.5; + Double_t ptMax = 5.0; + + TF1 *fEff = new TF1("fEff", "[0] + [1] * x - [2] * TMath::Exp(-[3] * TMath::Power(x, [4]))", 0., 5.0); + fEff->SetParameter(0, 0.5); + fEff->SetParameter(1, 0.); + fEff->SetParameter(2, 0.5); + fEff->SetParameter(3, 1.); + fEff->SetParameter(4, 2.); + + + TFile *filein = TFile::Open(filename); + TH1D *hEfficiencyPt = (TH1D *)filein->Get(Form("hEfficiencyPt_MB_%s_%s", histoName[ihisto], chargeName[icharge])); + hEfficiencyPt->Fit(fEff, "0", "", 0.5, 5.0); + hEfficiencyPt->SetTitle(Form("%s tracks;p_{T} (GeV/c);acceptance #times efficiency;", chargeName[icharge])); + hEfficiencyPt->SetMinimum(0.4); + hEfficiencyPt->SetMaximum(0.8); + hEfficiencyPt->SetMarkerStyle(marker); + hEfficiencyPt->SetMarkerColor(color); + hEfficiencyPt->SetMarkerSize(1.5); + hEfficiencyPt->SetLineWidth(2); + hEfficiencyPt->SetLineColor(color); + hEfficiencyPt->GetXaxis()->SetRangeUser(ptMin + 0.001, ptMax - 0.001); + hEfficiencyPt->SetStats(kFALSE); + cCanvas1->cd(); + hEfficiencyPt->Draw(opt); + fEff->Draw("same"); + + cCanvas1->SetGridx(); + cCanvas1->SetGridy(); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_%s.C", destdir, chargeName[icharge])); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_%s.root", destdir, chargeName[icharge])); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_%s.png", destdir, chargeName[icharge])); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_%s.eps", destdir, chargeName[icharge])); + + TH1D *hRatioPt = new TH1D(*hEfficiencyPt); + hRatioPt->Divide(fEff); + hRatioPt->SetTitle(Form("%s tracks;p_{T} (GeV/c);ratio wrt. fitted dependence;", chargeName[icharge])); + hRatioPt->SetMinimum(0.9); + hRatioPt->SetMaximum(1.1); + cCanvas2->cd(); + hRatioPt->Draw(); + + cCanvas2->SetGridx(); + cCanvas2->SetGridy(); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_%s.C", destdir, chargeName[icharge])); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_%s.root", destdir, chargeName[icharge])); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_%s.png", destdir, chargeName[icharge])); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_%s.eps", destdir, chargeName[icharge])); + + + // hEfficiencyPt->Add(fEff, -1.); + return hEfficiencyPt; +} + + +//_____________________________________________________________________________- + +TH1D * +TOFmatchEff_efficiencyPt_centrality_all_plot(const Char_t *filename, Int_t ihisto = kMatchedTracks, Int_t marker = 20, Int_t color = 1, Option_t *opt = "") +{ + + TCanvas *cCanvas1 = new TCanvas("cCanvas1"); + TCanvas *cCanvas2 = new TCanvas("cCanvas2"); + const Char_t *destdir = "matchingEfficiency_DATA"; + + Double_t ptMin = 0.5; + Double_t ptMax = 5.0; + + TF1 *fMismatchFrac = new TF1("fMismatchFrac", "([0]+[1]*TMath::Exp(-[2]*TMath::Power(x,[3])))*[4]", 0., 5.0); + fMismatchFrac->SetParameter(0, 0.0447133); + fMismatchFrac->SetParameter(1, 0.179172); + fMismatchFrac->SetParameter(2, 2.54333); + fMismatchFrac->SetParameter(3, 1.16819); + fMismatchFrac->SetParameter(4, 1.); + + TF1 *fEff = new TF1("fEff", "([0] + [1] * x - [2] * TMath::Exp(-[3] * TMath::Power(x, [4]))) * [5]", 0., 5.0); + fEff->SetParameter(0, 0.5); + fEff->SetParameter(1, 0.); + fEff->SetParameter(2, 0.5); + fEff->SetParameter(3, 1.); + fEff->SetParameter(4, 2.); + fEff->FixParameter(5, 1.); + + TFile *filein = TFile::Open(filename); + TH1D *hEfficiencyPt = (TH1D *)filein->Get(Form("hEfficiencyAllPt_MB_%s", histoName[ihisto])); + hEfficiencyPt->Fit(fEff, "0", "", 0.5, 5.0); + hEfficiencyPt->SetTitle("all particles;p_{T} (GeV/c);acceptance #times efficiency;"); + hEfficiencyPt->SetMinimum(0.4); + hEfficiencyPt->SetMaximum(0.8); + hEfficiencyPt->SetMarkerStyle(marker); + hEfficiencyPt->SetMarkerColor(color); + hEfficiencyPt->SetMarkerSize(1.5); + hEfficiencyPt->SetLineWidth(2); + hEfficiencyPt->SetLineColor(color); + hEfficiencyPt->GetXaxis()->SetRangeUser(0.5 + 0.001, 5.0 - 0.001); + hEfficiencyPt->SetStats(kFALSE); + cCanvas1->cd(); + hEfficiencyPt->Draw(opt); + fEff->Draw("same"); + + cCanvas1->SetGridx(); + cCanvas1->SetGridy(); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_all.C", destdir)); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_all.root", destdir)); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_all.png", destdir)); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_all.eps", destdir)); + + TH1D *hRatioPt = new TH1D(*hEfficiencyPt); + hRatioPt->Divide(fEff); + hRatioPt->SetTitle("all particles;p_{T} (GeV/c);ratio wrt. fitted dependence;"); + hRatioPt->SetMinimum(0.9); + hRatioPt->SetMaximum(1.1); + cCanvas2->cd(); + hRatioPt->Draw(); + + cCanvas2->SetGridx(); + cCanvas2->SetGridy(); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_all.C", destdir)); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_all.root", destdir)); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_all.png", destdir)); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_all.eps", destdir)); + + /* fix efficiency shape and release scale factor */ + fEff->FixParameter(0, fEff->GetParameter(0)); + fEff->FixParameter(1, fEff->GetParameter(1)); + fEff->FixParameter(2, fEff->GetParameter(2)); + fEff->FixParameter(3, fEff->GetParameter(3)); + fEff->FixParameter(4, fEff->GetParameter(4)); + fEff->ReleaseParameter(5); + + TH1D *hEfficiencyCent = new TH1D("hEfficiencyCent", "all particles;centrality percentile;acceptance x efficiency scale factor;", NcentralityBins, centralityBin); + hEfficiencyCent->SetMinimum(0.95); + hEfficiencyCent->SetMaximum(1.05); + hEfficiencyCent->SetMarkerStyle(marker); + hEfficiencyCent->SetMarkerColor(color); + hEfficiencyCent->SetMarkerSize(1.5); + hEfficiencyCent->SetLineWidth(2); + hEfficiencyCent->SetLineColor(color); + hEfficiencyCent->SetStats(kFALSE); + + + TH1D *hEfficiencyPt_cent[NcentralityBins]; + TH1D *hRatioPt_cent[NcentralityBins]; + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + + + hEfficiencyPt_cent[icent] = (TH1D *)filein->Get(Form("hEfficiencyAllPt_centrality%d_%s", icent, histoName[ihisto])); + hEfficiencyPt_cent[icent]->Fit(fEff, "", "", 0.5, 5.0); + + hEfficiencyPt_cent[icent]->SetTitle(Form("all particles (%d-%d\%);p_{T} (GeV/c);acceptance #times efficiency;", (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1])); + hEfficiencyPt_cent[icent]->SetMinimum(0.2); + hEfficiencyPt_cent[icent]->SetMaximum(0.8); + hEfficiencyPt_cent[icent]->SetMarkerStyle(marker); + hEfficiencyPt_cent[icent]->SetMarkerColor(color); + hEfficiencyPt_cent[icent]->SetMarkerSize(1.5); + hEfficiencyPt_cent[icent]->SetLineWidth(2); + hEfficiencyPt_cent[icent]->SetLineColor(color); + hEfficiencyPt_cent[icent]->GetXaxis()->SetRangeUser(0.5 + 0.001, 5.0 - 0.001); + hEfficiencyPt_cent[icent]->SetStats(kFALSE); + cCanvas1->cd(); + hEfficiencyPt_cent[icent]->Draw(opt); + fEff->Draw("same"); + + hEfficiencyCent->SetBinContent(icent + 1, fEff->GetParameter(5)); + hEfficiencyCent->SetBinError(icent + 1, fEff->GetParError(5)); + + cCanvas1->SetGridx(); + cCanvas1->SetGridy(); + cCanvas1->SaveAs(Form("%s/efficiencyPt_centrality%d_all.C", destdir, icent)); + cCanvas1->SaveAs(Form("%s/efficiencyPt_centrality%d_all.root", destdir, icent)); + cCanvas1->SaveAs(Form("%s/efficiencyPt_centrality%d_all.png", destdir, icent)); + cCanvas1->SaveAs(Form("%s/efficiencyPt_centrality%d_all.eps", destdir, icent)); + + hRatioPt_cent[icent] = new TH1D(*hEfficiencyPt_cent[icent]); + hRatioPt_cent[icent]->Divide(fEff); + hRatioPt_cent[icent]->SetTitle(Form("all particles (%d-%d\%);p_{T} (GeV/c);ratio wrt. fitted dependence;", (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1])); + hRatioPt_cent[icent]->SetMinimum(0.9); + hRatioPt_cent[icent]->SetMaximum(1.1); + cCanvas2->cd(); + hRatioPt_cent[icent]->Draw(); + + cCanvas2->SetGridx(); + cCanvas2->SetGridy(); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_centrality%d_all.C", destdir, icent)); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_centrality%d_all.root", destdir, icent)); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_centrality%d_all.png", destdir, icent)); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_centrality%d_all.eps", destdir, icent)); + + + } + + TF1 *fEffCent = new TF1("fEffCent", "[0] - [1] * TMath::Exp(-[2] * TMath::Power(x, [3]))", 0., 90.); + fEffCent->SetParameter(0, 1.02); + fEffCent->SetParameter(1, 0.04); + fEffCent->SetParameter(2, 0.001); + fEffCent->SetParameter(3, 2.); + // hEfficiencyCent->Fit(fEffCent, "q0", "", 0., 90.); + + TCanvas *cCanvas3 = new TCanvas("cCanvas3"); + hEfficiencyCent->Draw(); + // fEffCent->Draw("same"); + + cCanvas3->SetGridx(); + cCanvas3->SetGridy(); + cCanvas3->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_all.C", destdir)); + cCanvas3->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_all.root", destdir)); + cCanvas3->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_all.png", destdir)); + cCanvas3->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_all.eps", destdir)); + + TCanvas *cCanvas4 = new TCanvas("cCanvas4"); + + TH1D *hRatioCent = new TH1D(*hEfficiencyCent); + hRatioCent->Divide(fEffCent); + hRatioCent->SetTitle(Form("all particles;centrality percentile;ratio wrt. fitted dependence;")); + hRatioCent->SetMinimum(0.95); + hRatioCent->SetMaximum(1.05); + cCanvas4->cd(); + hRatioCent->Draw(); + + cCanvas4->SetGridx(); + cCanvas4->SetGridy(); + cCanvas4->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_ratioFit_all.C", destdir)); + cCanvas4->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_ratioFit_all.root", destdir)); + cCanvas4->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_ratioFit_all.png", destdir)); + cCanvas4->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_ratioFit_all.eps", destdir)); + + + + // hEfficiencyPt->Add(fEff, -1.); + return hEfficiencyCent; +} + + +//_____________________________________________________________________________- + +TH1D * +TOFmatchEff_efficiencyPt_centrality_all_plot_nomismatch(const Char_t *filename, Int_t ihisto = kMatchedTracks, Int_t marker = 20, Int_t color = 1, Option_t *opt = "") +{ + + TF1 *fpol0 = (TF1 *)gROOT->GetFunction("pol0"); + fpol0->SetRange(0., 5.0); + + TCanvas *cCanvas1 = new TCanvas("cCanvas1"); + TCanvas *cCanvas2 = new TCanvas("cCanvas2"); + const Char_t *destdir = "matchingEfficiency_DATA"; + + Double_t ptMin = 0.5; + Double_t ptMax = 5.0; + + TF1 *fMismatchCorr = new TF1("fMismatchCorr", "1. - ([0]+[1]*TMath::Exp(-[2]*TMath::Power(x,[3])))*[4]", 0., 5.0); + fMismatchCorr->SetParameter(0, 4.47133e-02); + fMismatchCorr->SetParameter(1, 1.79172e-01); + fMismatchCorr->SetParameter(2, 2.54333e+00); + fMismatchCorr->SetParameter(3, 1.16819e+00); + fMismatchCorr->SetParameter(4, 1.); + + TF1 *fMismatchScale = new TF1("fMismatchScale", "[0] + [1] * TMath::Exp(-[2] * x)", 0., 100.); + fMismatchScale->SetParameter(0, -6.36877e-02); + fMismatchScale->SetParameter(1, 1.74818e+00); + fMismatchScale->SetParameter(2, 3.00818e-02); + + TFile *filein = TFile::Open(filename); + TH1D *hEfficiencyPt = (TH1D *)filein->Get(Form("hEfficiencyAllPt_MB_%s", histoName[ihisto])); + if (ihisto != kMatchedCorrelatedTracks) + hEfficiencyPt->Multiply(fMismatchCorr); + hEfficiencyPt->SetTitle("all particles;p_{T} (GeV/c);acceptance #times efficiency;"); + hEfficiencyPt->SetMinimum(0.4); + hEfficiencyPt->SetMaximum(0.8); + hEfficiencyPt->SetMarkerStyle(marker); + hEfficiencyPt->SetMarkerColor(color); + hEfficiencyPt->SetMarkerSize(1.5); + hEfficiencyPt->SetLineWidth(2); + hEfficiencyPt->SetLineColor(color); + hEfficiencyPt->GetXaxis()->SetRangeUser(0.5 + 0.001, 5.0 - 0.001); + hEfficiencyPt->SetStats(kFALSE); + cCanvas1->cd(); + hEfficiencyPt->Draw(opt); + + cCanvas1->SetGridx(); + cCanvas1->SetGridy(); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_all.C", destdir)); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_all.root", destdir)); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_all.png", destdir)); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_all.eps", destdir)); + + TH1D *hEfficiencyCent = new TH1D("hEfficiencyCent", "all particles;centrality percentile;acceptance x efficiency scale factor;", NcentralityBins, centralityBin); + hEfficiencyCent->SetMinimum(0.95); + hEfficiencyCent->SetMaximum(1.05); + hEfficiencyCent->SetMarkerStyle(marker); + hEfficiencyCent->SetMarkerColor(color); + hEfficiencyCent->SetMarkerSize(1.5); + hEfficiencyCent->SetLineWidth(2); + hEfficiencyCent->SetLineColor(color); + hEfficiencyCent->SetStats(kFALSE); + + + TH1D *hEfficiencyPt_cent[NcentralityBins]; + TH1D *hRatioPt_cent[NcentralityBins]; + Double_t centmean; + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + + centmean = 0.5 * (centralityBin[icent] + centralityBin[icent + 1]); + hEfficiencyPt_cent[icent] = (TH1D *)filein->Get(Form("hEfficiencyAllPt_centrality%d_%s", icent, histoName[ihisto])); + fMismatchCorr->SetParameter(4, fMismatchScale->Eval(centmean)); + if (ihisto != kMatchedCorrelatedTracks) + hEfficiencyPt_cent[icent]->Multiply(fMismatchCorr); + hEfficiencyPt_cent[icent]->Divide(hEfficiencyPt); + hEfficiencyPt_cent[icent]->Fit(fpol0, "q0", "", 0.5, 5.0); + hEfficiencyPt_cent[icent]->SetTitle(Form("all particles (%d-%d\%);p_{T} (GeV/c);acceptance #times efficiency;", (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1])); + hEfficiencyPt_cent[icent]->SetMinimum(0.2); + hEfficiencyPt_cent[icent]->SetMaximum(0.8); + hEfficiencyPt_cent[icent]->SetMarkerStyle(marker); + hEfficiencyPt_cent[icent]->SetMarkerColor(color); + hEfficiencyPt_cent[icent]->SetMarkerSize(1.5); + hEfficiencyPt_cent[icent]->SetLineWidth(2); + hEfficiencyPt_cent[icent]->SetLineColor(color); + hEfficiencyPt_cent[icent]->GetXaxis()->SetRangeUser(0.5 + 0.001, 5.0 - 0.001); + hEfficiencyPt_cent[icent]->SetStats(kFALSE); + cCanvas1->cd(); + hEfficiencyPt_cent[icent]->Draw(opt); + fpol0->Draw("same"); + + hEfficiencyCent->SetBinContent(icent + 1, fpol0->GetParameter(0)); + hEfficiencyCent->SetBinError(icent + 1, fpol0->GetParError(0)); + + cCanvas1->SetGridx(); + cCanvas1->SetGridy(); + cCanvas1->SaveAs(Form("%s/efficiencyPt_centrality%d_all.C", destdir, icent)); + cCanvas1->SaveAs(Form("%s/efficiencyPt_centrality%d_all.root", destdir, icent)); + cCanvas1->SaveAs(Form("%s/efficiencyPt_centrality%d_all.png", destdir, icent)); + cCanvas1->SaveAs(Form("%s/efficiencyPt_centrality%d_all.eps", destdir, icent)); + + hRatioPt_cent[icent] = new TH1D(*hEfficiencyPt_cent[icent]); + hRatioPt_cent[icent]->Divide(fpol0); + hRatioPt_cent[icent]->SetTitle(Form("all particles (%d-%d\%);p_{T} (GeV/c);ratio wrt. fitted dependence;", (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1])); + hRatioPt_cent[icent]->SetMinimum(0.9); + hRatioPt_cent[icent]->SetMaximum(1.1); + cCanvas2->cd(); + hRatioPt_cent[icent]->Draw(); + + cCanvas2->SetGridx(); + cCanvas2->SetGridy(); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_centrality%d_all.C", destdir, icent)); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_centrality%d_all.root", destdir, icent)); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_centrality%d_all.png", destdir, icent)); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_centrality%d_all.eps", destdir, icent)); + + + } + + TF1 *fEffCent = new TF1("fEffCent", "[0] - [1] * TMath::Exp(-[2] * TMath::Power(x, [3]))", 0., 90.); + fEffCent->SetParameter(0, 1.02); + fEffCent->SetParameter(1, 0.04); + fEffCent->SetParameter(2, 0.001); + fEffCent->SetParameter(3, 2.); + // hEfficiencyCent->Fit(fEffCent, "q0", "", 0., 90.); + + TCanvas *cCanvas3 = new TCanvas("cCanvas3"); + hEfficiencyCent->Draw(); + // fEffCent->Draw("same"); + + cCanvas3->SetGridx(); + cCanvas3->SetGridy(); + cCanvas3->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_all.C", destdir)); + cCanvas3->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_all.root", destdir)); + cCanvas3->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_all.png", destdir)); + cCanvas3->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_all.eps", destdir)); + + TCanvas *cCanvas4 = new TCanvas("cCanvas4"); + + TH1D *hRatioCent = new TH1D(*hEfficiencyCent); + hRatioCent->Divide(fEffCent); + hRatioCent->SetTitle(Form("all particles;centrality percentile;ratio wrt. fitted dependence;")); + hRatioCent->SetMinimum(0.95); + hRatioCent->SetMaximum(1.05); + cCanvas4->cd(); + hRatioCent->Draw(); + + cCanvas4->SetGridx(); + cCanvas4->SetGridy(); + cCanvas4->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_ratioFit_all.C", destdir)); + cCanvas4->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_ratioFit_all.root", destdir)); + cCanvas4->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_ratioFit_all.png", destdir)); + cCanvas4->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_ratioFit_all.eps", destdir)); + + + + // hEfficiencyPt->Add(fEff, -1.); + return hEfficiencyCent; +} + + +TH1D * +TOFmatchEff_rapidityCut(const Char_t *filename, Int_t ipart, Int_t icharge, Int_t color = 2, Int_t marker = 20, Option_t *opt = "") +{ + + TFile *filein = TFile::Open(filename); + TH1D *hEfficiency_MB = (TH1D *)filein->Get(Form("hEfficiencyPt_MB_hMatchedTracks_%s", chargeName[icharge])); + TH1D *hEfficiencyPID_MB = (TH1D *)filein->Get(Form("hEfficiencyPIDPt_MB_hMatchedTracks_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + + TH1D *hRatio = new TH1D(*hEfficiencyPID_MB); + hRatio->Divide(hEfficiency_MB); + hRatio->SetLineColor(color); + hRatio->SetLineWidth(2); + hRatio->SetMarkerColor(color); + hRatio->SetMarkerStyle(marker); + hRatio->Draw(opt); + return hRatio; +} + +void +TOFmatchEff_checkFEAmap(const Char_t *filename) +{ + + TFile *filein = TFile::Open(filename); + TH2F *hFEAMap = (TH2F *)filein->Get("hFEAMap"); + TH2F *hEmptyFEA = new TH2F("hEmptyFEA", "", 72, 0., 18., 91, 0., 91.); + + Float_t nhits = hFEAMap->GetEntries(); + if (nhits <= 0) { + printf("found not hits.\n"); + return; + } + printf("found %d hits\n", nhits); + Float_t avhits = nhits / (hFEAMap->GetNbinsX() * hFEAMap->GetNbinsX()); + printf("on average %f hits/FEA\n", avhits); + + TH1F *hFEANormHit = new TH1F("hFEANormHit", "", 1000, 0., 3.); + for (Int_t ibinx = 0; ibinx < hFEAMap->GetNbinsX(); ibinx++) + for (Int_t ibiny = 0; ibiny < hFEAMap->GetNbinsY(); ibiny++) { + if (hFEAMap->GetBinContent(ibinx + 1, ibiny + 1) == 0.) { + hEmptyFEA->SetBinContent(ibinx + 1, ibiny + 1, 1.); + continue; + } + hFEANormHit->Fill(hFEAMap->GetBinContent(ibinx + 1, ibiny + 1) / avhits); + } + + TCanvas *cCanvas1 = new TCanvas("cCanvas1"); + cCanvas1->Divide(1, 2); + cCanvas1->cd(1); + hFEAMap->Draw("colz"); + cCanvas1->cd(2); + hEmptyFEA->Draw("colz"); + + TCanvas *cCanvas2 = new TCanvas("cCanvas2"); + hFEANormHit->Draw(); + + + TFile *fileout = TFile::Open(Form("TOFmatchEff_checkFEAmap.%s", filename), "RECREATE"); + hFEAMap->Write(); + hFEANormHit->Write(); + hEmptyFEA->Write(); + fileout->Close(); +} diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFmatchEff.sh b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFmatchEff.sh new file mode 100755 index 00000000000..686d5429cc9 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFmatchEff.sh @@ -0,0 +1,9 @@ +#! /bin/bash + +if [ "$1" == "" ]; then + echo "argument needed" + exit 1 +fi +echo "launching TOFmatchEff on $1 in background" +aliroot -b -q "TOFmatchEff.C(\"$1\")" &> TOFmatchEff.$1.log & +echo "TOFmatchEff started" \ No newline at end of file diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFmatchMC.C b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFmatchMC.C new file mode 100644 index 00000000000..7c42eea5966 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFmatchMC.C @@ -0,0 +1,1470 @@ +#include "CommonDefs.C" + +const Char_t *destdir = "plots"; + +enum EHisto_t { + kAcceptedTracks, + kMatchedTracks, + kMismatchedTracks, + kUncorrelatedTracks, + kMatchedCorrelatedTracks, + kMatchedGoodTracks, + kNHistos +}; +const Char_t *histoName[kNHistos] = { + "hAcceptedTracks", + "hMatchedTracks", + "hMismatchedTracks", + "hUncorrelatedTracks", + "hMatchedCorrelatedTracks", + "hMatchedGoodTracks" +}; + +enum EParam_t { + kCentrality, + kPt, + kEta, + kPhi, + kNParams +}; + +TOFmatchMC(const Char_t *filename, Int_t rapidityPart = -1, Int_t evMax = kMaxInt) +{ + + /* include path for ACLic */ + gSystem->AddIncludePath("-I$ALICE_ROOT/include"); + gSystem->AddIncludePath("-I$ALICE_ROOT/TOF"); + /* load libraries */ + gSystem->Load("libANALYSIS"); + gSystem->Load("libANALYSISalice"); + /* build analysis task class */ + gROOT->LoadMacro("AliAnalysisParticle.cxx+g"); + gROOT->LoadMacro("AliAnalysisEvent.cxx+g"); + gROOT->LoadMacro("AliAnalysisTrack.cxx+g"); + + /* open file, get tree and connect */ + TFile *filein = TFile::Open(filename); + TTree *treein = (TTree *)filein->Get("aodTree"); + printf("got \"aodTree\": %d entries\n", treein->GetEntries()); + AliAnalysisEvent *analysisEvent = new AliAnalysisEvent(); + TClonesArray *analysisTrackArray = new TClonesArray("AliAnalysisTrack"); + AliAnalysisTrack *analysisTrack = NULL; + treein->SetBranchAddress("AnalysisEvent", &analysisEvent); + treein->SetBranchAddress("AnalysisTrack", &analysisTrackArray); + + /* open enabled flag map */ + TH1F *hEnabledFlag = NULL; + if (enabledChannelsFileName) { + TFile *enabledfile = TFile::Open(enabledChannelsFileName); + hEnabledFlag = (TH1F *)enabledfile->Get("hEnabledFlag"); + } + + /* binning */ + for (Int_t ieta = 0; ieta < NetaBins + 1; ieta++) + etaBin[ieta] = etaMin + ieta * etaStep; + for (Int_t iphi = 0; iphi < NphiBins + 1; iphi++) + phiBin[iphi] = phiMin + iphi * phiStep; + /* THnSparse */ + Int_t NparamBins[kNParams] = {NcentralityBins, NptBins, NetaBins, NphiBins}; + Double_t *paramBin[kNParams] = {centralityBin, ptBin, etaBin, phiBin}; + THnSparseF *hHisto[kNHistos][AliPID::kSPECIES][kNCharges]; + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + hHisto[ihisto][ipart][icharge] = new THnSparseF(Form("hHisto_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge]), "", kNParams, NparamBins); + for (Int_t iparam = 0; iparam < kNParams; iparam++) + hHisto[ihisto][ipart][icharge]->SetBinEdges(iparam, paramBin[iparam]); + } + /* histos */ + TH2F *hFEAMap = new TH2F("hFEAMap", "", 72, 0., 18., 91, 0., 91.); + + /* start stopwatch */ + TStopwatch timer; + timer.Start(); + + /* loop over events */ + Double_t param[kNParams]; + Int_t part, charge; + Int_t index, sector, sectorStrip, padx, fea; + Float_t hitmapx, hitmapy; + AliTOFcalibHisto calib; + calib.LoadCalibHisto(); + for (Int_t iev = 0; iev < treein->GetEntries() && iev < evMax; iev++) { + /* get event */ + treein->GetEvent(iev); + if (iev % 1000 == 0) printf("iev = %d\n", iev); + /* check event */ + if (!analysisEvent->AcceptEvent(acceptEventType)) continue; + + /*** ACCEPTED EVENT ***/ + + /* get centrality */ + param[kCentrality] = analysisEvent->GetCentralityPercentile(centralityEstimator); + + /* loop over tracks */ + for (Int_t itrk = 0; itrk < analysisTrackArray->GetEntries(); itrk++) { + /* get track */ + analysisTrack = (AliAnalysisTrack *)analysisTrackArray->At(itrk); + if (!analysisTrack) continue; + /* check charged primary with defined PID */ + part = analysisTrack->GetMCPID(); + if (!analysisTrack->IsMCPrimary() || part < 0 || analysisTrack->GetSign() == 0.) continue; + /* check accepted track */ + if (!analysisTrack->AcceptTrack()) continue; + /* check rapidity */ + if (rapidityPart < 0) { + if ((analysisTrack->GetY(AliPID::ParticleMass(part)) - rapidityShift) > rapidityMaxCut || + (analysisTrack->GetY(AliPID::ParticleMass(part)) - rapidityShift) < rapidityMinCut) continue; + } + else { + if ((analysisTrack->GetY(AliPID::ParticleMass(rapidityPart)) - rapidityShift) > rapidityMaxCut || + (analysisTrack->GetY(AliPID::ParticleMass(rapidityPart)) - rapidityShift) < rapidityMinCut) continue; + } + + /*** ACCEPTED TRACK ***/ + + /* get track info */ + param[kPt] = analysisTrack->GetPt(); + param[kEta] = analysisTrack->GetEta(); + param[kPhi] = analysisTrack->GetPhi(); + charge = analysisTrack->GetSign() > 0. ? kPositive : kNegative; + + /* fill accepted tracks histos */ + hHisto[kAcceptedTracks][part][charge]->Fill(param); + + /* check TOF PID */ + if (!analysisTrack->HasTOFPID(hEnabledFlag)) continue; + + /*** ACCEPTED TRACK WITH TOF SIGNAL ***/ + + /* fill FEA map */ + sector = calib.GetCalibMap(AliTOFcalibHisto::kSector, index); + sectorStrip = calib.GetCalibMap(AliTOFcalibHisto::kSectorStrip, index); + padx = calib.GetCalibMap(AliTOFcalibHisto::kPadX, index); + fea = padx / 12; + hitmapx = sector + ((Double_t)(3 - fea) + 0.5) / 4.; + hitmapy = sectorStrip; + hFEAMap->Fill(hitmapx, hitmapy); + + /* fill matched tracks histos */ + hHisto[kMatchedTracks][part][charge]->Fill(param); + + /* check mismatch */ + if (!analysisTrack->IsMismatchMC()) { + hHisto[kMatchedGoodTracks][part][charge]->Fill(param); + hHisto[kMatchedCorrelatedTracks][part][charge]->Fill(param); + continue; + } + + /*** MIS-MATCHED TRACK ***/ + + /* fill mis-matched tracks histos */ + hHisto[kMismatchedTracks][part][charge]->Fill(param); + + /* check uncorrelated mismatch */ + if (!analysisTrack->IsUncorrelatedMismatchMC()) { + hHisto[kMatchedCorrelatedTracks][part][charge]->Fill(param); + continue; + } + + /*** UNCORRELATED MIS-MATCHED TRACK ***/ + + /* fill uncorrelated mis-matched tracks histos */ + hHisto[kUncorrelatedTracks][part][charge]->Fill(param); + + } + } + + /* stop stopwatch */ + timer.Stop(); + timer.Print(); + + /* output */ + if (rapidityPart < 0) + TFile *fileout = TFile::Open(Form("TOFmatchMC.%s", filename), "RECREATE"); + else + TFile *fileout = TFile::Open(Form("TOFmatchMC.%s.%s", AliPID::ParticleName(rapidityPart), filename), "RECREATE"); + hFEAMap->Write(); + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) + hHisto[ihisto][ipart][icharge]->Write(); + fileout->Close(); + + if (rapidityPart < 0) + TString str = Form("TOFmatchMC.%s", filename); + else + TString str = Form("TOFmatchMC.%s.%s", AliPID::ParticleName(rapidityPart), filename); + TOFmatchMC_efficiencyPt(str.Data()); +} + +//_____________________________________________________________________________- + +TOFmatchMC_efficiencyPt(const Char_t *filename) +{ + + /* get data */ + TFile *filein = TFile::Open(filename); + THnSparseF *hHisto[kNHistos][AliPID::kSPECIES][kNCharges]; + TH1D *hHistoPt_MB[kNHistos][AliPID::kSPECIES][kNCharges], *hHistoPt_centrality[NcentralityBins][kNHistos][AliPID::kSPECIES][kNCharges]; + TH1D *hHistoAllPt_MB[kNHistos], *hHistoAllPt_centrality[NcentralityBins][kNHistos]; + /* loop over histos */ + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) { + + /* INCLUSIVE */ + + hHistoAllPt_MB[ihisto] = new TH1D(Form("hHistoAllPt_MB_%s", histoName[ihisto]), "", NptBins, ptBin); + for (Int_t icent = 0; icent < NcentralityBins; icent++) + hHistoAllPt_centrality[icent][ihisto] = new TH1D(Form("hHistoAllPt_centrality%d_%s", icent, histoName[ihisto]), "", NptBins, ptBin); + + /* SINGLE PARTICLE */ + + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) { + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + + /* get histo */ + hHisto[ihisto][ipart][icharge] = (THnSparseF *)filein->Get(Form("hHisto_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + + /* MB projection */ + hHistoPt_MB[ihisto][ipart][icharge] = hHisto[ihisto][ipart][icharge]->Projection(kPt); + hHistoPt_MB[ihisto][ipart][icharge]->SetName(Form("hHistoPt_MB_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hHistoPt_MB[ihisto][ipart][icharge]->Sumw2(); + hHistoAllPt_MB[ihisto]->Add(hHistoPt_MB[ihisto][ipart][icharge]); + + /* centrality projection */ + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + hHisto[ihisto][ipart][icharge]->GetAxis(kCentrality)->SetRange(icent + 1, icent + 1); + hHistoPt_centrality[icent][ihisto][ipart][icharge] = hHisto[ihisto][ipart][icharge]->Projection(kPt); + hHistoPt_centrality[icent][ihisto][ipart][icharge]->SetName(Form("hHistoPt_centrality%d_%s_%s_%s", icent, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hHistoPt_centrality[icent][ihisto][ipart][icharge]->Sumw2(); + hHistoAllPt_centrality[icent][ihisto]->Add(hHistoPt_centrality[icent][ihisto][ipart][icharge]); + } + } + } + } + + /* output */ + TString str = filename; + str.Insert(str.Length() - TString(".root").Length(), ".efficiencyPt"); + TFile *fileout = TFile::Open(str.Data(), "RECREATE"); + + /* efficiencies/fractions and write */ + TH1D *hEfficiencyPt_MB[kNHistos][AliPID::kSPECIES][kNCharges], *hEfficiencyPt_centrality[NcentralityBins][kNHistos][AliPID::kSPECIES][kNCharges], *hEfficiencyPt_ratioMB_centrality[NcentralityBins][kNHistos][AliPID::kSPECIES][kNCharges]; + TH1D *hEfficiencyAllPt_MB[kNHistos], *hEfficiencyAllPt_centrality[NcentralityBins][kNHistos], *hEfficiencyAllPt_ratioMB_centrality[NcentralityBins][kNHistos]; + + + TH1D *hFractionPt_MB[kNHistos][AliPID::kSPECIES][kNCharges], *hFractionPt_centrality[NcentralityBins][kNHistos][AliPID::kSPECIES][kNCharges], *hFractionPt_ratioMB_centrality[NcentralityBins][kNHistos][AliPID::kSPECIES][kNCharges]; + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) { + + if (ihisto == kAcceptedTracks) continue; + + /* INCLUSIVE */ + + /* MB efficiency */ + hEfficiencyAllPt_MB[ihisto] = new TH1D(*hHistoAllPt_MB[ihisto]); + hEfficiencyAllPt_MB[ihisto]->SetName(Form("hEfficiencyAllPt_MB_%s", histoName[ihisto])); + hEfficiencyAllPt_MB[ihisto]->SetLineWidth(2); + hEfficiencyAllPt_MB[ihisto]->SetLineColor(1); + hEfficiencyAllPt_MB[ihisto]->SetMarkerStyle(20); + hEfficiencyAllPt_MB[ihisto]->SetMarkerColor(1); + hEfficiencyAllPt_MB[ihisto]->Divide(hEfficiencyAllPt_MB[ihisto], hHistoAllPt_MB[kAcceptedTracks], 1, 1, "B"); + hEfficiencyAllPt_MB[ihisto]->Write(); + + /* multiplicity/centrality efficiency */ + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + hEfficiencyAllPt_centrality[icent][ihisto] = new TH1D(*hHistoAllPt_centrality[icent][ihisto]); + hEfficiencyAllPt_centrality[icent][ihisto]->SetName(Form("hEfficiencyAllPt_centrality%d_%s", icent, histoName[ihisto])); + hEfficiencyAllPt_centrality[icent][ihisto]->SetLineWidth(2); + hEfficiencyAllPt_centrality[icent][ihisto]->SetLineColor(multcentColor[icent]); + hEfficiencyAllPt_centrality[icent][ihisto]->SetMarkerStyle(20); + hEfficiencyAllPt_centrality[icent][ihisto]->SetMarkerColor(multcentColor[icent]); + hEfficiencyAllPt_centrality[icent][ihisto]->Divide(hEfficiencyAllPt_centrality[icent][ihisto], hHistoAllPt_centrality[icent][kAcceptedTracks], 1, 1, "B"); + hEfficiencyAllPt_centrality[icent][ihisto]->Write(); + + /* ratio wrt. MB */ + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto] = new TH1D(*hEfficiencyAllPt_centrality[icent][ihisto]); + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto]->SetName(Form("hEfficiencyAllPt_ratioMB_centrality%d_%s", icent, histoName[ihisto])); + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto]->SetLineWidth(2); + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto]->SetLineColor(multcentColor[icent]); + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto]->SetMarkerStyle(20); + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto]->SetMarkerColor(multcentColor[icent]); + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto]->Divide(hEfficiencyAllPt_MB[ihisto]); + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto]->Write(); + } + + /* SINGLE PARTICLE */ + + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) { + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + + /* MB efficiency */ + hEfficiencyPt_MB[ihisto][ipart][icharge] = new TH1D(*hHistoPt_MB[ihisto][ipart][icharge]); + hEfficiencyPt_MB[ihisto][ipart][icharge]->SetName(Form("hEfficiencyPt_MB_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyPt_MB[ihisto][ipart][icharge]->SetLineWidth(2); + hEfficiencyPt_MB[ihisto][ipart][icharge]->SetLineColor(1); + hEfficiencyPt_MB[ihisto][ipart][icharge]->SetMarkerStyle(20); + hEfficiencyPt_MB[ihisto][ipart][icharge]->SetMarkerColor(1); + hEfficiencyPt_MB[ihisto][ipart][icharge]->Divide(hEfficiencyPt_MB[ihisto][ipart][icharge], hHistoPt_MB[kAcceptedTracks][ipart][icharge], 1, 1, "B"); + hEfficiencyPt_MB[ihisto][ipart][icharge]->Write(); + + /* multiplicity/centrality efficiency */ + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + hEfficiencyPt_centrality[icent][ihisto][ipart][icharge] = new TH1D(*hHistoPt_centrality[icent][ihisto][ipart][icharge]); + hEfficiencyPt_centrality[icent][ihisto][ipart][icharge]->SetName(Form("hEfficiencyPt_centrality%d_%s_%s_%s", icent, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyPt_centrality[icent][ihisto][ipart][icharge]->SetLineWidth(2); + hEfficiencyPt_centrality[icent][ihisto][ipart][icharge]->SetLineColor(multcentColor[icent]); + hEfficiencyPt_centrality[icent][ihisto][ipart][icharge]->SetMarkerStyle(20); + hEfficiencyPt_centrality[icent][ihisto][ipart][icharge]->SetMarkerColor(multcentColor[icent]); + hEfficiencyPt_centrality[icent][ihisto][ipart][icharge]->Divide(hEfficiencyPt_centrality[icent][ihisto][ipart][icharge], hHistoPt_centrality[icent][kAcceptedTracks][ipart][icharge], 1, 1, "B"); + hEfficiencyPt_centrality[icent][ihisto][ipart][icharge]->Write(); + + /* ratio wrt. MB */ + hEfficiencyPt_ratioMB_centrality[icent][ihisto][ipart][icharge] = new TH1D(*hEfficiencyPt_centrality[icent][ihisto][ipart][icharge]); + hEfficiencyPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetName(Form("hEfficiencyPt_ratioMB_centrality%d_%s_%s_%s", icent, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetLineWidth(2); + hEfficiencyPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetLineColor(multcentColor[icent]); + hEfficiencyPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetMarkerStyle(20); + hEfficiencyPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetMarkerColor(multcentColor[icent]); + hEfficiencyPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->Divide(hEfficiencyPt_MB[ihisto][ipart][icharge]); + hEfficiencyPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->Write(); + } + + /* fractions */ + + if (ihisto == kAcceptedTracks || ihisto == kMatchedTracks) continue; + + /* MB fraction */ + hFractionPt_MB[ihisto][ipart][icharge] = new TH1D(*hHistoPt_MB[ihisto][ipart][icharge]); + hFractionPt_MB[ihisto][ipart][icharge]->SetName(Form("hFractionPt_MB_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hFractionPt_MB[ihisto][ipart][icharge]->SetLineWidth(2); + hFractionPt_MB[ihisto][ipart][icharge]->SetLineColor(1); + hFractionPt_MB[ihisto][ipart][icharge]->SetMarkerStyle(20); + hFractionPt_MB[ihisto][ipart][icharge]->SetMarkerColor(1); + hFractionPt_MB[ihisto][ipart][icharge]->Divide(hFractionPt_MB[ihisto][ipart][icharge], hHistoPt_MB[kMatchedTracks][ipart][icharge], 1, 1, "B"); + hFractionPt_MB[ihisto][ipart][icharge]->Write(); + + /* multiplicity/centrality fraction */ + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + hFractionPt_centrality[icent][ihisto][ipart][icharge] = new TH1D(*hHistoPt_centrality[icent][ihisto][ipart][icharge]); + hFractionPt_centrality[icent][ihisto][ipart][icharge]->SetName(Form("hFractionPt_centrality%d_%s_%s_%s", icent, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hFractionPt_centrality[icent][ihisto][ipart][icharge]->SetLineWidth(2); + hFractionPt_centrality[icent][ihisto][ipart][icharge]->SetLineColor(multcentColor[icent]); + hFractionPt_centrality[icent][ihisto][ipart][icharge]->SetMarkerStyle(20); + hFractionPt_centrality[icent][ihisto][ipart][icharge]->SetMarkerColor(multcentColor[icent]); + hFractionPt_centrality[icent][ihisto][ipart][icharge]->Divide(hFractionPt_centrality[icent][ihisto][ipart][icharge], hHistoPt_centrality[icent][kMatchedTracks][ipart][icharge], 1, 1, "B"); + hFractionPt_centrality[icent][ihisto][ipart][icharge]->Write(); + + /* ratio wrt. MB */ + hFractionPt_ratioMB_centrality[icent][ihisto][ipart][icharge] = new TH1D(*hFractionPt_centrality[icent][ihisto][ipart][icharge]); + hFractionPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetName(Form("hFractionPt_ratioMB_centrality%d_%s_%s_%s", icent, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hFractionPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetLineWidth(2); + hFractionPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetLineColor(multcentColor[icent]); + hFractionPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetMarkerStyle(20); + hFractionPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetMarkerColor(multcentColor[icent]); + hFractionPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->Divide(hFractionPt_MB[ihisto][ipart][icharge]); + hFractionPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->Write(); + } + } + } + } + + fileout->Close(); + + TOFmatchMC_matchingEfficiency(str.Data()); + TOFmatchMC_matchingEfficiency_mismatchCorrected(str.Data()); + +} + +//_____________________________________________________________________________- + +TOFmatchMC_efficiencyEta(const Char_t *filename) +{ + + /* get data */ + TFile *filein = TFile::Open(filename); + THnSparseF *hHisto[kNHistos][AliPID::kSPECIES][kNCharges]; + TH1D *hHistoEta_MB[kNHistos][AliPID::kSPECIES][kNCharges], *hHistoEta_centrality[NcentralityBins][kNHistos][AliPID::kSPECIES][kNCharges]; + TH1D *hHistoEta_MB_pt[NptsubBins][kNHistos][AliPID::kSPECIES][kNCharges], *hHistoEta_centrality_pt[NcentralityBins][NptsubBins][kNHistos][AliPID::kSPECIES][kNCharges]; + /* loop over histos */ + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + + /* get histo */ + hHisto[ihisto][ipart][icharge] = (THnSparseF *)filein->Get(Form("hHisto_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + + /* MB projection */ + hHisto[ihisto][ipart][icharge]->GetAxis(kPt)->SetRange(0, 0); + hHisto[ihisto][ipart][icharge]->GetAxis(kCentrality)->SetRange(0, 0); + hHistoEta_MB[ihisto][ipart][icharge] = hHisto[ihisto][ipart][icharge]->Projection(kEta); + hHistoEta_MB[ihisto][ipart][icharge]->SetName(Form("hHistoEta_MB_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hHistoEta_MB[ihisto][ipart][icharge]->Sumw2(); + /* pt bins */ + for (Int_t ipt = 0; ipt < NptsubBins; ipt++) { + hHisto[ihisto][ipart][icharge]->GetAxis(kPt)->SetRange(ptsubBinMin[ipt] + 1, ptsubBinMax[ipt] + 1); + hHisto[ihisto][ipart][icharge]->GetAxis(kCentrality)->SetRange(0, 0); + hHistoEta_MB_pt[ipt][ihisto][ipart][icharge] = hHisto[ihisto][ipart][icharge]->Projection(kEta); + hHistoEta_MB_pt[ipt][ihisto][ipart][icharge]->SetName(Form("hHistoEta_MB_pt%d_%s_%s_%s", ipt, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hHistoEta_MB_pt[ipt][ihisto][ipart][icharge]->Sumw2(); + } + + /* centrality projection */ + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + hHisto[ihisto][ipart][icharge]->GetAxis(kPt)->SetRange(0, 0); + hHisto[ihisto][ipart][icharge]->GetAxis(kCentrality)->SetRange(icent + 1, icent + 1); + hHistoEta_centrality[icent][ihisto][ipart][icharge] = hHisto[ihisto][ipart][icharge]->Projection(kEta); + hHistoEta_centrality[icent][ihisto][ipart][icharge]->SetName(Form("hHistoEta_centrality%d_%s_%s_%s", icent, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hHistoEta_centrality[icent][ihisto][ipart][icharge]->Sumw2(); + /* pt bins */ + for (Int_t ipt = 0; ipt < NptsubBins; ipt++) { + hHisto[ihisto][ipart][icharge]->GetAxis(kPt)->SetRange(ptsubBinMin[ipt] + 1, ptsubBinMax[ipt] + 1); + hHisto[ihisto][ipart][icharge]->GetAxis(kCentrality)->SetRange(icent + 1, icent + 1); + hHistoEta_centrality_pt[icent][ipt][ihisto][ipart][icharge] = hHisto[ihisto][ipart][icharge]->Projection(kEta); + hHistoEta_centrality_pt[icent][ipt][ihisto][ipart][icharge]->SetName(Form("hHistoEta_centrality%d_pt%d_%s_%s_%s", icent, ipt, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hHistoEta_centrality_pt[icent][ipt][ihisto][ipart][icharge]->Sumw2(); + } + } + } + + /* output */ + TString str = filename; + str.Insert(str.Length() - TString(".root").Length(), ".efficiencyEta"); + TFile *fileout = TFile::Open(str.Data(), "RECREATE"); + + /* efficiencies/fractions and write */ + TH1D *hEfficiencyEta_MB[kNHistos][AliPID::kSPECIES][kNCharges], *hEfficiencyEta_centrality[NcentralityBins][kNHistos][AliPID::kSPECIES][kNCharges], *hEfficiencyEta_ratioMB_centrality[NcentralityBins][kNHistos][AliPID::kSPECIES][kNCharges]; + TH1D *hEfficiencyEta_MB_pt[NptsubBins][kNHistos][AliPID::kSPECIES][kNCharges], *hEfficiencyEta_centrality_pt[NcentralityBins][NptsubBins][kNHistos][AliPID::kSPECIES][kNCharges], *hEfficiencyEta_ratioMB_centrality_pt[NcentralityBins][NptsubBins][kNHistos][AliPID::kSPECIES][kNCharges]; + + + TH1D *hFractionEta_MB[kNHistos][AliPID::kSPECIES][kNCharges], *hFractionEta_centrality[NcentralityBins][kNHistos][AliPID::kSPECIES][kNCharges], *hFractionEta_ratioMB_centrality[NcentralityBins][kNHistos][AliPID::kSPECIES][kNCharges]; + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) { + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + + if (ihisto == kAcceptedTracks) continue; + + /* MB efficiency */ + hEfficiencyEta_MB[ihisto][ipart][icharge] = new TH1D(*hHistoEta_MB[ihisto][ipart][icharge]); + hEfficiencyEta_MB[ihisto][ipart][icharge]->SetName(Form("hEfficiencyEta_MB_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyEta_MB[ihisto][ipart][icharge]->SetLineWidth(2); + hEfficiencyEta_MB[ihisto][ipart][icharge]->SetLineColor(1); + hEfficiencyEta_MB[ihisto][ipart][icharge]->SetMarkerStyle(20); + hEfficiencyEta_MB[ihisto][ipart][icharge]->SetMarkerColor(1); + hEfficiencyEta_MB[ihisto][ipart][icharge]->Divide(hHistoEta_MB[kAcceptedTracks][ipart][icharge]); + hEfficiencyEta_MB[ihisto][ipart][icharge]->Write(); + /* pt bins */ + for (Int_t ipt = 0; ipt < NptsubBins; ipt++) { + hEfficiencyEta_MB_pt[ipt][ihisto][ipart][icharge] = new TH1D(*hHistoEta_MB_pt[ipt][ihisto][ipart][icharge]); + hEfficiencyEta_MB_pt[ipt][ihisto][ipart][icharge]->SetName(Form("hEfficiencyEta_MB_pt%d_%s_%s_%s", ipt, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyEta_MB_pt[ipt][ihisto][ipart][icharge]->SetLineWidth(2); + hEfficiencyEta_MB_pt[ipt][ihisto][ipart][icharge]->SetLineColor(1); + hEfficiencyEta_MB_pt[ipt][ihisto][ipart][icharge]->SetMarkerStyle(20); + hEfficiencyEta_MB_pt[ipt][ihisto][ipart][icharge]->SetMarkerColor(1); + hEfficiencyEta_MB_pt[ipt][ihisto][ipart][icharge]->Divide(hHistoEta_MB_pt[ipt][kAcceptedTracks][ipart][icharge]); + hEfficiencyEta_MB_pt[ipt][ihisto][ipart][icharge]->Write(); + } + + /* multiplicity/centrality efficiency */ + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + hEfficiencyEta_centrality[icent][ihisto][ipart][icharge] = new TH1D(*hHistoEta_centrality[icent][ihisto][ipart][icharge]); + hEfficiencyEta_centrality[icent][ihisto][ipart][icharge]->SetName(Form("hEfficiencyEta_centrality%d_%s_%s_%s", icent, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyEta_centrality[icent][ihisto][ipart][icharge]->SetLineWidth(2); + hEfficiencyEta_centrality[icent][ihisto][ipart][icharge]->SetLineColor(multcentColor[icent]); + hEfficiencyEta_centrality[icent][ihisto][ipart][icharge]->SetMarkerStyle(20); + hEfficiencyEta_centrality[icent][ihisto][ipart][icharge]->SetMarkerColor(multcentColor[icent]); + hEfficiencyEta_centrality[icent][ihisto][ipart][icharge]->Divide(hHistoEta_centrality[icent][kAcceptedTracks][ipart][icharge]); + hEfficiencyEta_centrality[icent][ihisto][ipart][icharge]->Write(); + + /* ratio wrt. MB */ + hEfficiencyEta_ratioMB_centrality[icent][ihisto][ipart][icharge] = new TH1D(*hEfficiencyEta_centrality[icent][ihisto][ipart][icharge]); + hEfficiencyEta_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetName(Form("hEfficiencyEta_ratioMB_centrality%d_%s_%s_%s", icent, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyEta_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetLineWidth(2); + hEfficiencyEta_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetLineColor(multcentColor[icent]); + hEfficiencyEta_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetMarkerStyle(20); + hEfficiencyEta_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetMarkerColor(multcentColor[icent]); + hEfficiencyEta_ratioMB_centrality[icent][ihisto][ipart][icharge]->Divide(hEfficiencyEta_MB[ihisto][ipart][icharge]); + hEfficiencyEta_ratioMB_centrality[icent][ihisto][ipart][icharge]->Write(); + } + + } + } + + fileout->Close(); + +} + +//_____________________________________________________________________________- + +TOFmatchMC_centralityDependence(const Char_t *filename) +{ + + Double_t fitMin[AliPID::kSPECIES] = {0.5, 0.5, 0.5, 0.5, 0.5}; + Double_t fitMax[AliPID::kSPECIES] = {3.0, 3.0, 3.0, 3.0, 5.0}; + + TF1 *pol0 = (TF1 *)gROOT->GetFunction("pol0"); + TF1 *pol1 = (TF1 *)gROOT->GetFunction("pol1"); + pol0->SetRange(0., 5.0); + TFile *filein = TFile::Open(filename); + + /* output */ + TString str = filename; + str.Insert(str.Length() - TString(".root").Length(), ".centralityDependence"); + TFile *fileout = TFile::Open(str.Data(), "RECREATE"); + + TH1D *hEfficiencyPt_ratioMB; + TH1D *hEfficiencyCentrality[kNHistos][AliPID::kSPECIES][kNCharges]; + TH1D *hChi2Centrality[kNHistos][AliPID::kSPECIES][kNCharges]; + TH1D *hEfficiencyAllCentrality[kNHistos]; + TH1F *hHistoEffRatio = new TH1F("hHistoEffRatio", "", 100, 0.5, 1.5); + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) { + if (ihisto == kAcceptedTracks) continue; + + /* INCLUSIVE */ + + hEfficiencyAllCentrality[ihisto] = new TH1D(Form("hEfficiencyAllCentrality_ratioMB_%s", histoName[ihisto]), "", NcentralityBins, centralityBin); + hEfficiencyAllCentrality[ihisto]->SetLineWidth(2); + hEfficiencyAllCentrality[ihisto]->SetLineColor(1); + hEfficiencyAllCentrality[ihisto]->SetMarkerStyle(20); + hEfficiencyAllCentrality[ihisto]->SetMarkerColor(1); + + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + + hEfficiencyPt_ratioMB = (TH1D *)filein->Get(Form("hEfficiencyAllPt_ratioMB_centrality%d_%s", icent, histoName[ihisto])); + hEfficiencyPt_ratioMB->Fit(pol0, "q0", "", 0., 5.0); + hEfficiencyAllCentrality[ihisto]->SetBinContent(icent + 1, pol0->GetParameter(0)); + hEfficiencyAllCentrality[ihisto]->SetBinError(icent + 1, pol0->GetParError(0)); + hEfficiencyPt_ratioMB->Add(pol0, -1.); + hEfficiencyPt_ratioMB->Write(); + + } + hEfficiencyAllCentrality[ihisto]->Write(); + + + /* SINGLE PARTICLE */ + + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + + hEfficiencyCentrality[ihisto][ipart][icharge] = new TH1D(Form("hEfficiencyCentrality_ratioMB_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge]), "", NcentralityBins, centralityBin); + hEfficiencyCentrality[ihisto][ipart][icharge]->SetLineWidth(2); + hEfficiencyCentrality[ihisto][ipart][icharge]->SetLineColor(particleColor[ipart]); + hEfficiencyCentrality[ihisto][ipart][icharge]->SetMarkerStyle(chargeMarker[icharge]); + hEfficiencyCentrality[ihisto][ipart][icharge]->SetMarkerColor(particleColor[ipart]); + + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + + hEfficiencyPt_ratioMB = (TH1D *)filein->Get(Form("hEfficiencyPt_ratioMB_centrality%d_%s_%s_%s", icent, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + + hEfficiencyPt_ratioMB->Fit(pol0, "q0", "", fitMin[ipart], fitMax[ipart]); + hEfficiencyCentrality[ihisto][ipart][icharge]->SetBinContent(icent + 1, pol0->GetParameter(0)); + hEfficiencyCentrality[ihisto][ipart][icharge]->SetBinError(icent + 1, pol0->GetParError(0)); + pol0->SetRange(fitMin[ipart], fitMax[ipart]); + hEfficiencyPt_ratioMB->Add(pol0, -1.); + hEfficiencyPt_ratioMB->Write(); + + } + + hEfficiencyCentrality[ihisto][ipart][icharge]->Write(); + } + } + + fileout->Close(); +} + +//_____________________________________________________________________________- + +TOFmatchMC_centralityDependenceFit(const Char_t *filename, Int_t ihisto = kMatchedGoodTracks) +{ + + const Char_t *particleLabel[5][2] = {"", "", "", "", "#pi^{+}", "#pi^{-}", "K^{+}", "K^{-}", "p", "#bar{p}"}; + + TF1 *fCentralityDependence = new TF1("fCentralityDependence", "[0] + [1] * (1. - TMath::Exp(-x / [2]))", 0., 90.); + fCentralityDependence->SetParameter(0, 0.98); + fCentralityDependence->SetParameter(1, 0.05); + fCentralityDependence->SetParameter(2, 50.); + + TFile *filein = TFile::Open(filename); + TH1D *hEfficiencyAllCentrality; + TH1D *hEfficiencyCentrality[AliPID::kSPECIES][kNCharges]; + hEfficiencyAllCentrality = (TH1D *)filein->Get(Form("hEfficiencyAllCentrality_ratioMB_%s", histoName[ihisto])); + TCanvas *cFit = new TCanvas("cFit"); + hEfficiencyAllCentrality->Fit(fCentralityDependence); + hEfficiencyAllCentrality->SetMaximum(1.05); + hEfficiencyAllCentrality->SetMinimum(0.95); + TCanvas *cRatios = new TCanvas("cRatios"); + cRatios->Divide(2, 3); + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) { + for (Int_t icharge = 0; icharge < 2; icharge++) { + cRatios->cd(icharge + 1 + 2 * (ipart - 2)); + cRatios->cd(icharge + 1 + 2 * (ipart - 2))->SetGridx(); + cRatios->cd(icharge + 1 + 2 * (ipart - 2))->SetGridy(); + hEfficiencyCentrality[ipart][icharge] = (TH1D *)filein->Get(Form("hEfficiencyCentrality_ratioMB_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyCentrality[ipart][icharge]->Divide(fCentralityDependence); + hEfficiencyCentrality[ipart][icharge]->SetMaximum(1.05); + hEfficiencyCentrality[ipart][icharge]->SetMinimum(0.95); + hEfficiencyCentrality[ipart][icharge]->SetTitle(Form("%s;centrality percentile;efficiency ratio wrt. fitted centrality dependence", particleLabel[ipart][icharge])); + hEfficiencyCentrality[ipart][icharge]->SetStats(kFALSE); + hEfficiencyCentrality[ipart][icharge]->Draw(); + } + } + + +} + +//_____________________________________________________________________________- + +TOFmatchMC_efficiencyPt_MB_plot(const Char_t *filename) +{ + TOFmatchMC_efficiencyPt_MB_plot(filename, kMatchedGoodTracks, 2, 0, 20, 4); + TOFmatchMC_efficiencyPt_MB_plot(filename, kMatchedGoodTracks, 2, 1, 25, 4); + TOFmatchMC_efficiencyPt_MB_plot(filename, kMatchedGoodTracks, 3, 0, 20, 8); + TOFmatchMC_efficiencyPt_MB_plot(filename, kMatchedGoodTracks, 3, 1, 25, 8); + TOFmatchMC_efficiencyPt_MB_plot(filename, kMatchedGoodTracks, 4, 0, 20, 2); + TOFmatchMC_efficiencyPt_MB_plot(filename, kMatchedGoodTracks, 4, 1, 25, 2); +} + +TH1D * +TOFmatchMC_efficiencyPt_MB_plot(const Char_t *filename, Int_t ihisto = kMatchedGoodTracks, Int_t ipart, Int_t icharge, Int_t marker = 20, Int_t color = 2, Option_t *opt = "") +{ + + TCanvas *cCanvas1 = new TCanvas("cCanvas1"); + TCanvas *cCanvas2 = new TCanvas("cCanvas2"); + + Double_t ptMin[AliPID::kSPECIES] = {0.5, 0.5, 0.5, 0.5, 0.5}; + Double_t ptMax[AliPID::kSPECIES] = {3.0, 3.0, 3.0, 3.0, 5.0}; + + TF1 *fEff = new TF1("fEff", "[0] * TMath::Exp(-TMath::Power(x / [1], [2])) / (1. + TMath::Exp(([3] - x) / [4]))", 0., 5.0); + fEff->SetParameter(0, 0.5); + fEff->SetParameter(1, 0.5); + fEff->SetParameter(2, 1.); + fEff->SetParameter(3, 0.5); + fEff->SetParameter(4, 0.5); + fEff->SetParLimits(4, 0.3, 2.0); + + TFile *fileout = TFile::Open(Form("%s/efficiencyPt_MB_%s_%s.root", destdir, AliPID::ParticleName(ipart), chargeName[icharge]), "RECREATE"); + + TFile *filein = TFile::Open(filename); + TH1D *hEfficiencyPt = (TH1D *)filein->Get(Form("hEfficiencyPt_MB_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + + hEfficiencyPt->Fit(fEff, "0q", "IME", 0.5, 5.0); + hEfficiencyPt->SetTitle(Form("%s;p_{T} (GeV/c);acceptance #times efficiency;", partChargeName[ipart][icharge])); + hEfficiencyPt->SetMinimum(0.2); + hEfficiencyPt->SetMaximum(0.7); + hEfficiencyPt->SetMarkerStyle(marker); + hEfficiencyPt->SetMarkerColor(color); + hEfficiencyPt->SetMarkerSize(1.5); + hEfficiencyPt->SetLineWidth(2); + hEfficiencyPt->SetLineColor(color); + hEfficiencyPt->GetXaxis()->SetRangeUser(ptMin[ipart] + 0.001, ptMax[ipart] - 0.001); + hEfficiencyPt->SetStats(kFALSE); + cCanvas1->cd(); + hEfficiencyPt->DrawCopy(); + fEff->DrawCopy("same"); + fileout->cd(); + hEfficiencyPt->Write("hEfficiencyPt"); + fEff->Write("fEff"); + + cCanvas1->SetGridx(); + cCanvas1->SetGridy(); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_%s_%s.C", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_%s_%s.png", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_%s_%s.eps", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + + TH1D *hRatioPt = new TH1D(*hEfficiencyPt); + hRatioPt->Divide(fEff); + hRatioPt->SetTitle(Form("%s;p_{T} (GeV/c);ratio wrt. fitted dependence;", partChargeName[ipart][icharge])); + hRatioPt->SetMinimum(0.9); + hRatioPt->SetMaximum(1.1); + cCanvas2->cd(); + hRatioPt->DrawCopy(); + fileout->cd(); + hRatioPt->Write("hRatioPt"); + + cCanvas2->SetGridx(); + cCanvas2->SetGridy(); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_%s_%s.C", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_%s_%s.png", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_%s_%s.eps", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + + + fileout->Close(); + + // hEfficiencyPt->Add(fEff, -1.); + return hEfficiencyPt; +} + + +//_____________________________________________________________________________- + +TOFmatchMC_efficiencyPt_centrality_plot(const Char_t *filename) +{ + TOFmatchMC_efficiencyPt_centrality_plot(filename, kMatchedGoodTracks, 2, 0, 20, 4); + TOFmatchMC_efficiencyPt_centrality_plot(filename, kMatchedGoodTracks, 2, 1, 25, 4); + TOFmatchMC_efficiencyPt_centrality_plot(filename, kMatchedGoodTracks, 3, 0, 20, 8); + TOFmatchMC_efficiencyPt_centrality_plot(filename, kMatchedGoodTracks, 3, 1, 25, 8); + TOFmatchMC_efficiencyPt_centrality_plot(filename, kMatchedGoodTracks, 4, 0, 20, 2); + TOFmatchMC_efficiencyPt_centrality_plot(filename, kMatchedGoodTracks, 4, 1, 25, 2); +} + +TOFmatchMC_efficiencyPt_fit(TH1 *h, TF1 *f, Int_t param) +{ + + if (param >= 0) { + for (Int_t ipar = 0; ipar < f->GetNpar(); ipar++) + if (ipar != param) + f->FixParameter(ipar, f->GetParameter(ipar)); + else + f->ReleaseParameter(ipar); + } + else { + for (Int_t ipar = 0; ipar < f->GetNpar(); ipar++) + f->ReleaseParameter(ipar); + } + h->Fit(f); + +} + +TH1D * +TOFmatchMC_efficiencyPt_centrality_plot(const Char_t *filename, Int_t ihisto = kMatchedGoodTracks, Int_t ipart, Int_t icharge, Int_t marker = 20, Int_t color = 2, Option_t *opt = "") +{ + + TVirtualFitter::SetMaxIterations(1000000); + + /* load HistoUtils */ + gROOT->LoadMacro("HistoUtils.C"); + + TCanvas *cCanvas1 = new TCanvas("cCanvas1"); + TCanvas *cCanvas2 = new TCanvas("cCanvas2"); + TCanvas *cCanvas3 = new TCanvas("cCanvas3"); + + Double_t ptMin[AliPID::kSPECIES] = {0.5, 0.5, 0.5, 0.5, 0.5}; + Double_t ptMax[AliPID::kSPECIES] = {3.0, 3.0, 3.0, 3.0, 5.0}; + + /* fit minimum-bias efficiency pt */ + + TF1 *fEff = new TF1("fEff", "[0] * TMath::Exp(-TMath::Power([1] / x, [2])) + [3] * x", ptMin[ipart], ptMax[ipart]); + fEff->SetParameter(0, 0.5); + fEff->SetParameter(1, 0.1); + fEff->SetParameter(2, 2.); + fEff->SetParameter(3, 0.); + fEff->SetParameter(4, 0.); + Int_t nPars = fEff->GetNpar(); + Int_t scalePar = 0.; + TF1 *fEffCopy = new TF1(*fEff); + + TFile *fileout = TFile::Open(Form("%s/efficiencyPt_centrality_%s_%s.root", destdir, AliPID::ParticleName(ipart), chargeName[icharge]), "RECREATE"); + + TFile *filein = TFile::Open(filename); + TH1D *hEfficiencyPt = (TH1D *)filein->Get(Form("hEfficiencyPt_MB_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyPt->Fit(fEff, "0", "", 0.5, 1.0); + hEfficiencyPt->Fit(fEff, "0", "", 0.5, 1.5); + hEfficiencyPt->Fit(fEff, "0", "", 0.5, 2.0); + hEfficiencyPt->Fit(fEff, "0", "IMRE", ptMin[ipart], ptMax[ipart]); + hEfficiencyPt->Fit(fEff, "0", "IMRE", ptMin[ipart], ptMax[ipart]); + hEfficiencyPt->Fit(fEff, "0", "IMRE", ptMin[ipart], ptMax[ipart]); + + /* build efficiency profile */ + for (Int_t ipar = 0; ipar < nPars; ipar++) { + fEffCopy->SetParameter(ipar, fEff->GetParameter(ipar)); + fEffCopy->SetParError(ipar, fEff->GetParError(ipar)); + } + TProfile *pEfficiencyPt = new TProfile(Form("pEfficiencyPt_MB_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge]), Form("%s;p_{T} (GeV/c);acceptance #times efficiency;", partChargeName[ipart][icharge]), NptBins, ptBin, "s"); + HistoUtils_Function2Profile(fEffCopy, pEfficiencyPt); + + /* draw */ + cCanvas1->cd(); + pEfficiencyPt->SetMarkerStyle(marker); + pEfficiencyPt->SetMarkerColor(color); + pEfficiencyPt->SetMarkerSize(0); + pEfficiencyPt->SetLineWidth(2); + pEfficiencyPt->SetLineColor(color); + pEfficiencyPt->SetFillStyle(3001); + pEfficiencyPt->SetFillColor(color); + pEfficiencyPt->GetXaxis()->SetRangeUser(ptMin[ipart] + 0.001, ptMax[ipart] - 0.001); + pEfficiencyPt->SetStats(kFALSE); + pEfficiencyPt->DrawCopy("E2"); + + hEfficiencyPt->SetTitle(Form("%s;p_{T} (GeV/c);acceptance #times efficiency;", partChargeName[ipart][icharge])); + hEfficiencyPt->SetMarkerStyle(marker); + hEfficiencyPt->SetMarkerColor(color); + hEfficiencyPt->SetMarkerSize(1.5); + hEfficiencyPt->SetLineWidth(2); + hEfficiencyPt->SetLineColor(color); + hEfficiencyPt->GetXaxis()->SetRangeUser(ptMin[ipart] + 0.001, ptMax[ipart] - 0.001); + hEfficiencyPt->SetStats(kFALSE); + hEfficiencyPt->DrawCopy("same"); + fEff->DrawCopy("same"); + cCanvas1->Update(); + + /* write */ + fileout->cd(); + pEfficiencyPt->Write("pEfficiencyPt"); + hEfficiencyPt->Write("hEfficiencyPt"); + fEff->Write("fEff"); + + TH1D *hEfficiencyCent = new TH1D("hEfficiencyCent", Form("%s;centrality percentile;acceptance x efficiency scale factor;", partChargeName[ipart][icharge]), NcentralityBins, centralityBin); + hEfficiencyCent->SetMinimum(0.9); + hEfficiencyCent->SetMaximum(1.1); + hEfficiencyCent->SetMarkerStyle(marker); + hEfficiencyCent->SetMarkerColor(color); + hEfficiencyCent->SetMarkerSize(1.5); + hEfficiencyCent->SetLineWidth(2); + hEfficiencyCent->SetLineColor(color); + hEfficiencyCent->SetStats(kFALSE); + + TProfile *pEfficiencyPt_cent[NcentralityBins]; + TH1D *hEfficiencyPt_cent[NcentralityBins]; + TH1D *hRatioPt_cent[NcentralityBins]; + + /* fix efficiency shape and release scale factor */ + for (Int_t ipar = 0; ipar < nPars; ipar++) + fEff->FixParameter(ipar, fEff->GetParameter(ipar)); + fEff->ReleaseParameter(scalePar); + + gStyle->SetOptStat(1100); + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + + hEfficiencyPt_cent[icent] = (TH1D *)filein->Get(Form("hEfficiencyPt_centrality%d_%s_%s_%s", icent, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyPt_cent[icent]->Fit(fEff, "", "IME", ptMin[ipart], ptMax[ipart]); + + /* build efficiency profile */ + fEffCopy->SetParameter(scalePar, fEff->GetParameter(scalePar)); + fEffCopy->SetParError(scalePar, fEff->GetParError(scalePar)); + pEfficiencyPt_cent[icent] = new TProfile(Form("pEfficiencyPt_centrality%d_%s_%s_%s", icent, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge]), Form("%s;p_{T} (GeV/c);acceptance #times efficiency;", partChargeName[ipart][icharge]), NptBins, ptBin, "s"); + HistoUtils_Function2Profile(fEffCopy, pEfficiencyPt_cent[icent]); + + /* draw */ + cCanvas1->cd(); + pEfficiencyPt_cent[icent]->SetMarkerStyle(marker); + pEfficiencyPt_cent[icent]->SetMarkerColor(color); + pEfficiencyPt_cent[icent]->SetMarkerSize(0); + pEfficiencyPt_cent[icent]->SetLineWidth(2); + pEfficiencyPt_cent[icent]->SetLineColor(color); + pEfficiencyPt_cent[icent]->SetFillStyle(3001); + pEfficiencyPt_cent[icent]->SetFillColor(color); + pEfficiencyPt_cent[icent]->GetXaxis()->SetRangeUser(ptMin[ipart] + 0.001, ptMax[ipart] - 0.001); + pEfficiencyPt_cent[icent]->SetStats(kFALSE); + pEfficiencyPt_cent[icent]->DrawCopy("E2"); + + hEfficiencyPt_cent[icent]->SetTitle(Form("%s (%d-%d\%);p_{T} (GeV/c);acceptance #times efficiency;", partChargeName[ipart][icharge], (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1])); + hEfficiencyPt_cent[icent]->SetMarkerStyle(marker); + hEfficiencyPt_cent[icent]->SetMarkerColor(color); + hEfficiencyPt_cent[icent]->SetMarkerSize(1.5); + hEfficiencyPt_cent[icent]->SetLineWidth(2); + hEfficiencyPt_cent[icent]->SetLineColor(color); + hEfficiencyPt_cent[icent]->GetXaxis()->SetRangeUser(ptMin[ipart] + 0.001, ptMax[ipart] - 0.001); + hEfficiencyPt_cent[icent]->SetStats(kFALSE); + hEfficiencyPt_cent[icent]->DrawCopy("same"); + fEff->DrawCopy("same"); + cCanvas1->Update(); + + fileout->cd(); + pEfficiencyPt_cent[icent]->Write(Form("pEfficiencyPt_cent%d", icent)); + hEfficiencyPt_cent[icent]->Write(Form("hEfficiencyPt_cent%d", icent)); + fEff->Write(Form("fEff_cent%d", icent)); + + hEfficiencyCent->SetBinContent(icent + 1, fEff->GetParameter(scalePar)); + hEfficiencyCent->SetBinError(icent + 1, fEff->GetParError(scalePar)); + + cCanvas1->SetGridx(); + cCanvas1->SetGridy(); + cCanvas1->SaveAs(Form("%s/efficiencyPt_centrality%d_%s_%s.C", destdir, icent, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas1->SaveAs(Form("%s/efficiencyPt_centrality%d_%s_%s.png", destdir, icent, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas1->SaveAs(Form("%s/efficiencyPt_centrality%d_%s_%s.eps", destdir, icent, AliPID::ParticleName(ipart), chargeName[icharge])); + + hRatioPt_cent[icent] = new TH1D(*hEfficiencyPt_cent[icent]); + hRatioPt_cent[icent]->Divide(fEff); + hRatioPt_cent[icent]->SetTitle(Form("%s (%d-%d\%);p_{T} (GeV/c);ratio wrt. fitted dependence;", partChargeName[ipart][icharge], (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1])); + hRatioPt_cent[icent]->SetMinimum(0.75); + hRatioPt_cent[icent]->SetMaximum(1.25); + cCanvas2->cd(); + hRatioPt_cent[icent]->DrawCopy(); + fileout->cd(); + hRatioPt_cent[icent]->Write(Form("hRatioPt_cent%d", icent)); + + + cCanvas2->SetGridx(); + cCanvas2->SetGridy(); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_centrality%d_%s_%s.C", destdir, icent, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_centrality%d_%s_%s.png", destdir, icent, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_centrality%d_%s_%s.eps", destdir, icent, AliPID::ParticleName(ipart), chargeName[icharge])); + + } + + cCanvas3->cd(); + hEfficiencyCent->DrawCopy(); + fileout->cd(); + hEfficiencyCent->Write("hEfficiencyCent"); + + cCanvas3->SetGridx(); + cCanvas3->SetGridy(); + cCanvas3->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_%s_%s.C", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas3->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_%s_%s.png", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas3->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_%s_%s.eps", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + + // hEfficiencyPt->Add(fEff, -1.); + return hEfficiencyCent; +} + + +//_____________________________________________________________________________- + +TH1D * +TOFmatchMC_efficiencyPt_centrality_all_plot(const Char_t *filename, Int_t ihisto = kMatchedGoodTracks, Int_t marker = 20, Int_t color = 1, Option_t *opt = "") +{ + + /* + this function measures the centrality-dependent scale factor + of the matching efficiency, assuming that the scale factor + is common to all particles species + + 1.) first the inclusive pt-dependence is fitted for MB events with scale factor = 1. + 2.) the shape of the pt-dependence is the fixed and the scale factor released + 3.) using a fixed-shape the inclusive pt-dependence is fitted in centrality bins with only the scale factor as a free parameter + + */ + + TCanvas *cCanvas1 = new TCanvas("cCanvas1"); + TCanvas *cCanvas2 = new TCanvas("cCanvas2"); + + /* pt-dependent matching efficiency function with scale factor */ + TF1 *fEff = new TF1("fEff", "[5] * [0] * TMath::Exp(-TMath::Power(x / [1], [2])) / (1. + TMath::Exp(([3] - x) / [4]))", 0., 5.0); + fEff->SetParameter(0, 0.5); + fEff->SetParameter(1, 0.5); + fEff->SetParameter(2, 1.); + fEff->SetParameter(3, 0.5); + fEff->SetParameter(4, 0.5); + fEff->SetParLimits(4, 0.3, 2.0); + fEff->FixParameter(5, 1.); + + TFile *fileout = TFile::Open(Form("%s/efficiencyPt_MB_all.root", destdir), "RECREATE"); + + /* fit inclusive pt-dependence in MB events */ + TFile *filein = TFile::Open(filename); + TH1D *hEfficiencyPt = (TH1D *)filein->Get(Form("hEfficiencyAllPt_MB_%s", histoName[ihisto])); + hEfficiencyPt->Fit(fEff, "0", "IME", 0.5, 5.0); + hEfficiencyPt->SetTitle("all particles;p_{T} (GeV/c);acceptance #times efficiency;"); + hEfficiencyPt->SetMinimum(0.2); + hEfficiencyPt->SetMaximum(0.7); + hEfficiencyPt->SetMarkerStyle(marker); + hEfficiencyPt->SetMarkerColor(color); + hEfficiencyPt->SetMarkerSize(1.5); + hEfficiencyPt->SetLineWidth(2); + hEfficiencyPt->SetLineColor(color); + hEfficiencyPt->GetXaxis()->SetRangeUser(0.5 + 0.001, 5.0 - 0.001); + hEfficiencyPt->SetStats(kFALSE); + cCanvas1->cd(); + hEfficiencyPt->DrawCopy(); + fEff->DrawCopy("same"); + fileout->cd(); + hEfficiencyPt->Write("hEfficiencyPt"); + fEff->Write("fEff"); + + cCanvas1->SetGridx(); + cCanvas1->SetGridy(); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_all.C", destdir)); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_all.png", destdir)); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_all.eps", destdir)); + + TH1D *hRatioPt = new TH1D(*hEfficiencyPt); + hRatioPt->Divide(fEff); + hRatioPt->SetTitle("all particles;p_{T} (GeV/c);ratio wrt. fitted dependence;"); + hRatioPt->SetMinimum(0.9); + hRatioPt->SetMaximum(1.1); + cCanvas2->cd(); + hRatioPt->DrawCopy(); + fileout->cd(); + hRatioPt->Write("hRatioPt"); + + cCanvas2->SetGridx(); + cCanvas2->SetGridy(); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_all.C", destdir)); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_all.png", destdir)); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_all.eps", destdir)); + + /* fix efficiency shape and release scale factor */ + fEff->FixParameter(0, fEff->GetParameter(0)); + fEff->FixParameter(1, fEff->GetParameter(1)); + fEff->FixParameter(2, fEff->GetParameter(2)); + fEff->FixParameter(3, fEff->GetParameter(3)); + fEff->FixParameter(4, fEff->GetParameter(4)); + fEff->ReleaseParameter(5); + + TH1D *hEfficiencyCent = new TH1D("hEfficiencyCent", "all particles;centrality percentile;acceptance x efficiency scale factor;", NcentralityBins, centralityBin); + hEfficiencyCent->SetMinimum(0.95); + hEfficiencyCent->SetMaximum(1.05); + hEfficiencyCent->SetMarkerStyle(marker); + hEfficiencyCent->SetMarkerColor(color); + hEfficiencyCent->SetMarkerSize(1.5); + hEfficiencyCent->SetLineWidth(2); + hEfficiencyCent->SetLineColor(color); + hEfficiencyCent->SetStats(kFALSE); + + + /* fit inclusive pt-dependence in centrality bins + with fixed pt-shape and free scale factor */ + TH1D *hEfficiencyPt_cent[NcentralityBins]; + TH1D *hRatioPt_cent[NcentralityBins]; + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + + hEfficiencyPt_cent[icent] = (TH1D *)filein->Get(Form("hEfficiencyAllPt_centrality%d_%s", icent, histoName[ihisto])); + hEfficiencyPt_cent[icent]->Fit(fEff, "", "IME", 0.5, 5.0); + + hEfficiencyPt_cent[icent]->SetTitle(Form("all particles (%d-%d\%);p_{T} (GeV/c);acceptance #times efficiency;", (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1])); + hEfficiencyPt_cent[icent]->SetMinimum(0.2); + hEfficiencyPt_cent[icent]->SetMaximum(0.8); + hEfficiencyPt_cent[icent]->SetMarkerStyle(marker); + hEfficiencyPt_cent[icent]->SetMarkerColor(color); + hEfficiencyPt_cent[icent]->SetMarkerSize(1.5); + hEfficiencyPt_cent[icent]->SetLineWidth(2); + hEfficiencyPt_cent[icent]->SetLineColor(color); + hEfficiencyPt_cent[icent]->GetXaxis()->SetRangeUser(0.5 + 0.001, 5.0 - 0.001); + hEfficiencyPt_cent[icent]->SetStats(kFALSE); + cCanvas1->cd(); + hEfficiencyPt_cent[icent]->DrawCopy(); + fEff->DrawCopy("same"); + hEfficiencyPt_cent[icent]->Write(Form("hEfficiencyPt_cent%d", icent)); + fEff->Write(Form("fEff_cent%d", icent)); + + hEfficiencyCent->SetBinContent(icent + 1, fEff->GetParameter(5)); + hEfficiencyCent->SetBinError(icent + 1, fEff->GetParError(5)); + + cCanvas1->SetGridx(); + cCanvas1->SetGridy(); + cCanvas1->SaveAs(Form("%s/efficiencyPt_centrality%d_all.C", destdir, icent)); + cCanvas1->SaveAs(Form("%s/efficiencyPt_centrality%d_all.png", destdir, icent)); + cCanvas1->SaveAs(Form("%s/efficiencyPt_centrality%d_all.eps", destdir, icent)); + + hRatioPt_cent[icent] = new TH1D(*hEfficiencyPt_cent[icent]); + hRatioPt_cent[icent]->Divide(fEff); + hRatioPt_cent[icent]->SetTitle(Form("all particles (%d-%d\%);p_{T} (GeV/c);ratio wrt. fitted dependence;", (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1])); + hRatioPt_cent[icent]->SetMinimum(0.9); + hRatioPt_cent[icent]->SetMaximum(1.1); + cCanvas2->cd(); + hRatioPt_cent[icent]->DrawCopy(); + fileout->cd(); + hRatioPt_cent[icent]->Write(Form("hRatioPt_cent%d", icent)); + + cCanvas2->SetGridx(); + cCanvas2->SetGridy(); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_centrality%d_all.C", destdir, icent)); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_centrality%d_all.png", destdir, icent)); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_centrality%d_all.eps", destdir, icent)); + + + } + + TF1 *fEffCent = new TF1("fEffCent", "[0] - [1] * TMath::Exp(-[2] * TMath::Power(x, [3]))", 0., 90.); + fEffCent->SetParameter(0, 1.02); + fEffCent->SetParameter(1, 0.04); + fEffCent->SetParameter(2, 0.001); + fEffCent->SetParameter(3, 2.); + hEfficiencyCent->Fit(fEffCent, "q0", "IME", 0., 90.); + + TCanvas *cCanvas3 = new TCanvas("cCanvas3"); + hEfficiencyCent->DrawCopy(); + fEffCent->DrawCopy("same"); + fileout->cd(); + hEfficiencyCent->Write("hEfficiencyCent"); + fEffCent->Write("fEffCent"); + + cCanvas3->SetGridx(); + cCanvas3->SetGridy(); + cCanvas3->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_all.C", destdir)); + cCanvas3->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_all.png", destdir)); + cCanvas3->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_all.eps", destdir)); + + TCanvas *cCanvas4 = new TCanvas("cCanvas4"); + + TH1D *hRatioCent = new TH1D(*hEfficiencyCent); + hRatioCent->Divide(fEffCent); + hRatioCent->SetTitle(Form("all particles;centrality percentile;ratio wrt. fitted dependence;")); + hRatioCent->SetMinimum(0.95); + hRatioCent->SetMaximum(1.05); + cCanvas4->cd(); + hRatioCent->DrawCopy(); + fileout->cd(); + hRatioCent->Write("hRatioCent"); + + cCanvas4->SetGridx(); + cCanvas4->SetGridy(); + cCanvas4->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_ratioFit_all.C", destdir)); + cCanvas4->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_ratioFit_all.png", destdir)); + cCanvas4->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_ratioFit_all.eps", destdir)); + + + + // hEfficiencyPt->Add(fEff, -1.); + return hEfficiencyCent; +} + + +//_____________________________________________________________________________- + +TOFmatchMC_efficiencyPt_MB_smooth_plot(const Char_t *filename) +{ + TOFmatchMC_efficiencyPt_MB_smooth_plot(filename, kMatchedGoodTracks, 2, 0, 20, 4); + TOFmatchMC_efficiencyPt_MB_smooth_plot(filename, kMatchedGoodTracks, 2, 1, 25, 4); + TOFmatchMC_efficiencyPt_MB_smooth_plot(filename, kMatchedGoodTracks, 3, 0, 20, 8); + TOFmatchMC_efficiencyPt_MB_smooth_plot(filename, kMatchedGoodTracks, 3, 1, 25, 8); + TOFmatchMC_efficiencyPt_MB_smooth_plot(filename, kMatchedGoodTracks, 4, 0, 20, 2); + TOFmatchMC_efficiencyPt_MB_smooth_plot(filename, kMatchedGoodTracks, 4, 1, 25, 2); +} + +TH1D * +TOFmatchMC_efficiencyPt_MB_smooth_plot(const Char_t *filename, Int_t ihisto = kMatchedGoodTracks, Int_t ipart, Int_t icharge, Int_t marker = 20, Int_t color = 2, Option_t *opt = "") +{ + + TCanvas *cCanvas1 = new TCanvas("cCanvas1"); + TCanvas *cCanvas2 = new TCanvas("cCanvas2"); + + Double_t ptMin[AliPID::kSPECIES] = {0.5, 0.5, 0.5, 0.5, 0.5}; + Double_t ptMax[AliPID::kSPECIES] = {3.0, 3.0, 3.0, 3.0, 5.0}; + + TF1 *fEff = new TF1("fEff", "[0] + [1] * x - [2] * TMath::Exp(-[3] * TMath::Power(x, [4]))", 1.0, 5.0); + fEff->SetParameter(0, 0.5); + fEff->SetParameter(1, 0.); + fEff->SetParameter(2, 0.5); + fEff->SetParameter(3, 1.); + fEff->SetParameter(4, 2.); + + + TFile *filein = TFile::Open(filename); + TH1D *hEfficiencyPt = (TH1D *)filein->Get(Form("hEfficiencyPt_MB_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyPt->Fit(fEff, "0", "IME", 1.0, 5.0); + hEfficiencyPt->SetTitle(Form("%s;p_{T} (GeV/c);acceptance #times efficiency;", partChargeName[ipart][icharge])); + hEfficiencyPt->SetMinimum(0.2); + hEfficiencyPt->SetMaximum(0.7); + hEfficiencyPt->SetMarkerStyle(marker); + hEfficiencyPt->SetMarkerColor(color); + hEfficiencyPt->SetMarkerSize(1.5); + hEfficiencyPt->SetLineWidth(2); + hEfficiencyPt->SetLineColor(color); + hEfficiencyPt->GetXaxis()->SetRangeUser(ptMin[ipart] + 0.001, ptMax[ipart] - 0.001); + hEfficiencyPt->SetStats(kFALSE); + cCanvas1->cd(); + hEfficiencyPt->Draw(opt); + fEff->Draw("same"); + + cCanvas1->SetGridx(); + cCanvas1->SetGridy(); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_smooth_%s_%s.C", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_smooth_%s_%s.root", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_smooth_%s_%s.png", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_smooth_%s_%s.eps", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + + TH1D *hRatioPt = new TH1D(*hEfficiencyPt); + hRatioPt->Divide(fEff); + hRatioPt->SetTitle(Form("%s;p_{T} (GeV/c);ratio wrt. fitted dependence;", partChargeName[ipart][icharge])); + hRatioPt->SetMinimum(0.9); + hRatioPt->SetMaximum(1.1); + cCanvas2->cd(); + hRatioPt->Draw(); + + cCanvas2->SetGridx(); + cCanvas2->SetGridy(); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_smooth_%s_%s.C", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_smooth_%s_%s.root", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_smooth_%s_%s.png", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_smooth_%s_%s.eps", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + + + /* smoothing step */ + TH1D *hEfficiencyPt_smooth = new TH1D(*hEfficiencyPt); + Double_t ratio, value, error; + for (Int_t ipt = 0; ipt < hRatioPt->GetNbinsX(); ipt++) { + if (hRatioPt->GetBinCenter(ipt + 1) < 1.5) continue; + ratio = hRatioPt->GetBinContent(ipt + 1); + value = hEfficiencyPt->GetBinContent(ipt + 1); + error = hEfficiencyPt->GetBinError(ipt + 1); + value /= ratio; + hEfficiencyPt_smooth->SetBinContent(ipt + 1, value); + } + new TCanvas(); + hEfficiencyPt_smooth->Draw(); + + // hEfficiencyPt->Add(fEff, -1.); + return hEfficiencyPt; +} + +TOFmatchMC_matchingEfficiency(const Char_t *filename, Bool_t useGFcorrection = kTRUE) +{ + + Int_t marker[2] = {20, 21}; + Int_t color[AliPID::kSPECIES] = {1, 1, 4, 8, 2}; + Char_t *partLatex[AliPID::kSPECIES][2] = { + "", "", "#pi^{+}", "K^{+}", "p", + "", "", "#pi^{-}", "K^{-}", "#bar{p}" + }; + + TFile *filein = TFile::Open(filename); + if (useGFcorrection) + TFile *fileout = TFile::Open("TOF_matchingEfficiency.root", "RECREATE"); + else + TFile *fileout = TFile::Open("TOF_matchingEfficiency_noGF.root", "RECREATE"); + TH1D *hEff; + TF1 *fGF; + Char_t title[1024]; + for (Int_t icent = -1; icent < NcentralityBins; icent++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) { + if (icent == -1) + hEff = (TH1D *)filein->Get(Form("hEfficiencyPt_MB_hMatchedCorrelatedTracks_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + else + hEff = (TH1D *)filein->Get(Form("hEfficiencyPt_centrality%d_hMatchedCorrelatedTracks_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + /* geant-fluka correction */ + fGF = TOFmatchMC_geantflukaCorrection(ipart, icharge); + if (useGFcorrection) + hEff->Divide(fGF); + if (icent == -1) + sprintf(title, "%s (MB);p_{T} (GeV/c);matching efficiency;", partLatex[ipart][icharge]); + else + sprintf(title, "%s (%d-%d%%);p_{T} (GeV/c);matching efficiency;", partLatex[ipart][icharge], (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1]); + hEff->SetMarkerStyle(marker[icharge]); + hEff->SetMarkerColor(color[ipart]); + hEff->SetLineColor(1); + hEff->SetLineWidth(1); + hEff->SetTitle(title); + if (icent == -1) + hEff->SetName(Form("hMatchEff_MB_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + else + hEff->SetName(Form("hMatchEff_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + fileout->cd(); + hEff->Write(); + } + + fileout->Close(); +} + +TOFmatchMC_matchingEfficiency_mismatchCorrected(const Char_t *filename, Bool_t useGFcorrection = kTRUE) +{ + + Int_t marker[2] = {20, 21}; + Int_t color[AliPID::kSPECIES] = {1, 1, 4, 8, 2}; + Char_t *partLatex[AliPID::kSPECIES][2] = { + "", "", "#pi^{+}", "K^{+}", "p", + "", "", "#pi^{-}", "K^{-}", "#bar{p}" + }; + + TFile *filein = TFile::Open(filename); + if (useGFcorrection) + TFile *fileout = TFile::Open("TOF_matchingEfficiency_mismatchCorrected.root", "RECREATE"); + else + TFile *fileout = TFile::Open("TOF_matchingEfficiency_mismatchCorrected_noGF.root", "RECREATE"); + TH1D *hEff; + TF1 *fGF; + Char_t title[1024]; + for (Int_t icent = -1; icent < NcentralityBins; icent++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) { + if (icent == -1) + hEff = (TH1D *)filein->Get(Form("hEfficiencyPt_MB_hMatchedTracks_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + else + hEff = (TH1D *)filein->Get(Form("hEfficiencyPt_centrality%d_hMatchedTracks_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + /* geant-fluka correction */ + fGF = TOFmatchMC_geantflukaCorrection(ipart, icharge); + if (useGFcorrection) + hEff->Divide(fGF); + if (icent == -1) +sprintf(title, "%s (MB);p_{T} (GeV/c);matching efficiency;", partLatex[ipart][icharge]); + else + sprintf(title, "%s (%d-%d%%);p_{T} (GeV/c);matching efficiency;", partLatex[ipart][icharge], (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1]); + hEff->SetMarkerStyle(marker[icharge]); + hEff->SetMarkerColor(color[ipart]); + hEff->SetLineColor(1); + hEff->SetLineWidth(1); + hEff->SetTitle(title); + if (icent == -1) + hEff->SetName(Form("hMatchEff_MB_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + else + hEff->SetName(Form("hMatchEff_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + fileout->cd(); + hEff->Write(); + } + + fileout->Close(); +} + +TOFmatchMC_matchingEfficiency_acceptTRDin(const Char_t *filename, Bool_t useGFcorrection = kTRUE) +{ + + Int_t marker[2] = {20, 21}; + Int_t color[AliPID::kSPECIES] = {1, 1, 4, 8, 2}; + Char_t *partLatex[AliPID::kSPECIES][2] = { + "", "", "#pi^{+}", "K^{+}", "p", + "", "", "#pi^{-}", "K^{-}", "#bar{p}" + }; + + TFile *filein = TFile::Open(filename); + if (useGFcorrection) + TFile *fileout = TFile::Open("TOF_matchingEfficiency_acceptTRDin.root", "RECREATE"); + else + TFile *fileout = TFile::Open("TOF_matchingEfficiency_acceptTRDin_noGF.root", "RECREATE"); + TH1D *hEff; + TF1 *fGF; + Char_t title[1024]; + for (Int_t icent = 0; icent < NcentralityBins; icent++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) { + hEff = (TH1D *)filein->Get(Form("hEfficiencyPt_centrality%d_hMatchedGoodTracks_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + /* geant-fluka correction */ + fGF = TOFmatchMC_geantflukaCorrection_acceptTRDin(ipart, icharge); + if (useGFcorrection) + hEff->Divide(fGF); + sprintf(title, "%s (%d-%d%%);p_{T} (GeV/c);matching efficiency;", partLatex[ipart][icharge], (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1]); + hEff->SetMarkerStyle(marker[icharge]); + hEff->SetMarkerColor(color[ipart]); + hEff->SetLineColor(1); + hEff->SetLineWidth(1); + hEff->SetTitle(title); + hEff->SetName(Form("hMatchEff_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + fileout->cd(); + hEff->Write(); + } + + fileout->Close(); +} + +TOFmatchMC_matchingEfficiency_rejectTRDin(const Char_t *filename, Bool_t useGFcorrection = kTRUE) +{ + + Int_t marker[2] = {20, 21}; + Int_t color[AliPID::kSPECIES] = {1, 1, 4, 8, 2}; + Char_t *partLatex[AliPID::kSPECIES][2] = { + "", "", "#pi^{+}", "K^{+}", "p", + "", "", "#pi^{-}", "K^{-}", "#bar{p}" + }; + + TFile *filein = TFile::Open(filename); + if (useGFcorrection) + TFile *fileout = TFile::Open("TOF_matchingEfficiency_rejectTRDin.root", "RECREATE"); + else + TFile *fileout = TFile::Open("TOF_matchingEfficiency_rejectTRDin_noGF.root", "RECREATE"); + TH1D *hEff; + TF1 *fGF; + Char_t title[1024]; + for (Int_t icent = 0; icent < NcentralityBins; icent++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) { + hEff = (TH1D *)filein->Get(Form("hEfficiencyPt_centrality%d_hMatchedGoodTracks_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + /* geant-fluka correction */ + fGF = TOFmatchMC_geantflukaCorrection_rejectTRDin(ipart, icharge); + if (useGFcorrection) + hEff->Divide(fGF); + sprintf(title, "%s (%d-%d%%);p_{T} (GeV/c);matching efficiency;", partLatex[ipart][icharge], (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1]); + hEff->SetMarkerStyle(marker[icharge]); + hEff->SetMarkerColor(color[ipart]); + hEff->SetLineColor(1); + hEff->SetLineWidth(1); + hEff->SetTitle(title); + hEff->SetName(Form("hMatchEff_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + fileout->cd(); + hEff->Write(); + } + + fileout->Close(); +} + +TF1 * +TOFmatchMC_geantflukaCorrection(Int_t ipart, Int_t icharge) +{ + + if (ipart == 3 && icharge == kNegative) { + TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge]), "MatchingPtGeantFlukaCorrectionKaMinus(x)", 0., 5.); + return f; + } + // else if (ipart == 4 && icharge == kNegative) { + // TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge]), "MatchingPtGeantFlukaCorrectionPrMinus(x)", 0., 5.); + // } + else + TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge]), "MatchingPtGeantFlukaCorrectionNull(x)", 0., 5.); + + return f; +} + + +TF1 * +TOFmatchMC_geantflukaCorrection_acceptTRDin(Int_t ipart, Int_t icharge) +{ + + if (ipart == 3 && icharge == kNegative) { + TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge]), "MatchingPtGeantFlukaCorrectionKaMinus_acceptTRDin(x)", 0., 5.); + return f; + } + else if (ipart == 4 && icharge == kNegative) { + TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge]), "MatchingPtGeantFlukaCorrectionPrMinus_acceptTRDin(x)", 0., 5.); + } + else + TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge]), "MatchingPtGeantFlukaCorrectionNull(x)", 0., 5.); + + return f; +} + + +TF1 * +TOFmatchMC_geantflukaCorrection_rejectTRDin(Int_t ipart, Int_t icharge) +{ + + if (ipart == 3 && icharge == kNegative) { + TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge]), "MatchingPtGeantFlukaCorrectionKaMinus_rejectTRDin(x)", 0., 5.); + return f; + } + else if (ipart == 4 && icharge == kNegative) { + TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge]), "MatchingPtGeantFlukaCorrectionPrMinus_rejectTRDin(x)", 0., 5.); + } + else + TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge]), "MatchingPtGeantFlukaCorrectionNull(x)", 0., 5.); + + return f; +} + + +Double_t +MatchingPtGeantFlukaCorrectionNull(Double_t pTmc) +{ + return 1.; +} + +Double_t +MatchingPtGeantFlukaCorrectionPrMinus(Double_t pTmc, Int_t ntrd = 12) +{ + Float_t ptTPCoutP =pTmc*(1-6.81059e-01*TMath::Exp(-pTmc*4.20094)); + Float_t scale = (ntrd * 0.14638485 + (18 - ntrd) * 0.02406) / 18.; + return (TMath::Power(1 - 0.129758*TMath::Exp(-ptTPCoutP*0.679612),scale/0.03471)); +} + +Double_t +MatchingPtGeantFlukaCorrectionPrMinus_acceptTRDin(Double_t pTmc) +{ + Float_t ptTPCoutP =pTmc*(1-6.81059e-01*TMath::Exp(-pTmc*4.20094)); + return (TMath::Power(1 - 0.129758*TMath::Exp(-ptTPCoutP*0.679612),0.14638485/0.03471)); +} + +Double_t +MatchingPtGeantFlukaCorrectionPrMinus_rejectTRDin(Double_t pTmc) +{ + Float_t ptTPCoutP =pTmc*(1-6.81059e-01*TMath::Exp(-pTmc*4.20094)); + return (TMath::Power(1 - 0.129758*TMath::Exp(-ptTPCoutP*0.679612),0.02406/0.03471)); +} + +Double_t +MatchingPtGeantFlukaCorrectionKaMinus(Double_t pTmc, Int_t ntrd = 12) +{ + Float_t ptTPCoutK=pTmc*(1- 3.37297e-03/pTmc/pTmc - 3.26544e-03/pTmc); + Float_t scale = (ntrd * 0.14638485 + (18 - ntrd) * 0.02406) / 18.; + return TMath::Min((TMath::Power(0.972865 + 0.0117093*ptTPCoutK,scale/0.03471)), 1.); +} + +Double_t +MatchingPtGeantFlukaCorrectionKaMinus_acceptTRDin(Double_t pTmc) +{ + Float_t ptTPCoutK=pTmc*(1- 3.37297e-03/pTmc/pTmc - 3.26544e-03/pTmc); + return TMath::Min((TMath::Power(0.972865 + 0.0117093*ptTPCoutK,0.14638485/0.03471)), 1.); +} + +Double_t +MatchingPtGeantFlukaCorrectionKaMinus_rejectTRDin(Double_t pTmc) +{ + Float_t ptTPCoutK=pTmc*(1- 3.37297e-03/pTmc/pTmc - 3.26544e-03/pTmc); + return TMath::Min((TMath::Power(0.972865 + 0.0117093*ptTPCoutK,0.02406/0.03471)), 1.); +} diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFmatchMC.sh b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFmatchMC.sh new file mode 100755 index 00000000000..2395c1a719d --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFmatchMC.sh @@ -0,0 +1,9 @@ +#! /bin/bash + +if [ "$1" == "" ]; then + echo "argument needed" + exit 1 +fi +echo "launching TOFmatchMC on $1 in background" +aliroot -b -q "TOFmatchMC.C(\"$1\")" &> TOFmatchMC.$1.log & +echo "TOFmatchMC started" \ No newline at end of file diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFpid.C b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFpid.C new file mode 100644 index 00000000000..eeda6ff882d --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFpid.C @@ -0,0 +1,2733 @@ +#include "CommonDefs.C" + +#define DISPLAY 0 + +/* SIGNAL SHAPE */ +Bool_t GAUSSIAN_SIGNAL = kFALSE; +Bool_t GAUSSIANTAIL_SIGNAL = kFALSE; +Bool_t GAUSSIANTAIL2_SIGNAL = kFALSE; +Bool_t GAUSSIANPLUSGAUSSIANTAIL_SIGNAL = kFALSE; +Bool_t GAUSSIANPLUSEXPONENTIAL_SIGNAL = kFALSE; +Bool_t EXPECTED_SIGNAL_TAIL = kTRUE; +Bool_t EXPECTED_SIGNAL_TEMPLATE = kTRUE; +Bool_t EXPECTED_SIGNAL_FIT = kFALSE; +/* SIGNAL PARAMETERS */ +Bool_t FIX_SIGNAL_MEAN = kFALSE; +Bool_t FIX_SIGNAL_SIGMA = kFALSE; +Bool_t FIX_SIGNAL_TAIL = kFALSE; +Float_t SCALE_SIGNAL_SIGMA = 1.; +Float_t SCALE_SIGNAL_TAIL = 1.; +/* OTHER STUFF */ +Char_t *SIGNAL_PARAM_FILE = NULL;//"signalParamFile.root"; +Float_t DEFAULT_SIGNAL_MEAN = 0.; +Float_t MIN_SIGNAL_MEAN = -0.2; +Float_t MAX_SIGNAL_MEAN = 0.2.; +Float_t DEFAULT_SIGNAL_SIGMA = 1.; +Float_t MIN_SIGNAL_SIGMA = 0.8; +Float_t MAX_SIGNAL_SIGMA = 1.2; +Float_t DEFAULT_SIGNAL_TAIL = 1.; +Float_t MIN_SIGNAL_TAIL = 0.5; +Float_t MAX_SIGNAL_TAIL = 1.5; +/* BACKGROUND */ +Bool_t EXPECTED_BACKGROUND_TAIL = kTRUE; +Bool_t EXPECTED_BACKGROUND_TEMPLATE = kTRUE; +Bool_t EXPECTED_BACKGROUND_FIT = kFALSE; +Bool_t GAUSSIAN_BACKGROUND = kFALSE; +Bool_t USE_ELECTRON_BACKGROUND = kTRUE; +/* BACKGROUND PARAMETERS */ +Bool_t FIX_BACKGROUND_MEAN = kTRUE; +Bool_t FIX_BACKGROUND_SIGMA = kTRUE; +Bool_t FIX_BACKGROUND_TAIL = kTRUE; +Float_t SCALE_BACKGROUND_SIGMA = 1.; +Float_t SCALE_BACKGROUND_TAIL = 1.; +/* MISMATCH */ +Bool_t NO_MISMATCH = kFALSE; +Bool_t EXPECTED_MISMATCH = kTRUE; +Bool_t EXPONENTIAL_MISMATCH = kFALSE; +Bool_t UNIFORM_MISMATCH = kFALSE; +Bool_t DOUBLEEXPONENTIAL_MISMATCH = kFALSE; +Bool_t UNIFORMPLUSEXPONENTIAL_MISMATCH = kFALSE; +/* AUTOMATIC CONSTRAINS */ +Float_t FIT_ELECTRONS_PT_MIN = 0.; +Float_t FIT_ELECTRONS_PT_MAX = 1.0; +Float_t FIT_MUONS_PT_MIN = 0.7; +Float_t FIT_MUONS_PT_MAX = 0.; +Float_t FIT_PIONS_PT_MIN = 0.; +Float_t FIT_PIONS_PT_MAX = 5.; + +Float_t CONSTRAINSIGNAL_LIMIT = 0.; +Float_t CONSTRAINTAIL_LIMIT = 0.; + +enum EFitParams_t { + kMean, + kSigma, + kTail, + kTotalCounts, + kIntegralCounts, + kSignalCounts, + kBkg1Counts, + kBkg2Counts, + kBkg3Counts, + kBkg4Counts, + kMismatchCounts, + kNFitParams +}; + +/* fit output params name */ +const Char_t *fitParamName[kNFitParams] = { + "Mean", + "Sigma", + "Tail", + "TotalCounts", + "IntegralCounts", + "SignalCounts", + "Bkg1Counts", + "Bkg2Counts", + "Bkg3Counts", + "Bkg4Counts", + "MismatchCounts" +}; + +/* fit output params title */ +const Char_t *fitParamTitle[kNFitParams] = { + "Signal mean;p_{T} (GeV/c);#mu (ps)", + "Signal sigma;p_{T} (GeV/c);#sigma (ps)", + "Signal tail;p_{T} (GeV/c);#sigma_{tail} (ps)", + "Total counts;p_{T} (GeV/c);counts", + "Total counts within fit range;p_{T} (GeV/c);counts", + "Signal counts;p_{T} (GeV/c);counts", + "Background-1 counts;p_{T} (GeV/c);counts", + "Background-2 counts;p_{T} (GeV/c);counts", + "Background-3 counts;p_{T} (GeV/c);counts", + "Background-4 counts;p_{T} (GeV/c);counts", + "Mismatch counts within fit range;p_{T} (GeV/c);counts" +}; + +/**************************************************************/ +/*** GENERATION OF TEMPLATE HISTOS ****************************/ +/**************************************************************/ + +const Int_t NmismatchTrials = 1; +const Int_t NexpectedTrials = 1; + +/**************************************************************/ +/*** HISTOS AND BINNING ***************************************/ +/**************************************************************/ + +/**************************************************************/ +/**************************************************************/ +enum EHistoParam_t { + kCentrality, + kTOFsigma, + kPt, + kTPCsigma, + kNHistoParams +}; +/**************************************************************/ +/**************************************************************/ +const Int_t NtofsigmaBins = 1750; +Double_t tofsigmaBin[NtofsigmaBins + 1]; +Double_t tofsigmaMin = -100., tofsigmaMax = 250., tofsigmaStep = (tofsigmaMax - tofsigmaMin) / NtofsigmaBins; +/**************************************************************/ +const Int_t NtofsignalBins = 2000; +Double_t tofsignalBin[NtofsignalBins + 1]; +Double_t tofsignalMin = -24400., tofsignalMax = 24400., tofsignalStep = (tofsignalMax - tofsignalMin) / NtofsignalBins; +/**************************************************************/ +const Int_t NtofresoBins = 500; +Double_t tofresoBin[NtofsignalBins + 1]; +Double_t tofresoMin = 0., tofresoMax = 500., tofresoStep = (tofresoMax - tofresoMin) / NtofresoBins; +/**************************************************************/ +/**************************************************************/ +const Int_t NtpcsigmaBins = 10; +Double_t tpcsigmaBin[NtpcsigmaBins + 1]; +Double_t tpcsigmaMin = -5., tpcsigmaMax = 5., tpcsigmaStep = (tpcsigmaMax - tpcsigmaMin) / NtpcsigmaBins; +/**************************************************************/ +Int_t NparamsBins[kNHistoParams] = {NcentralityBins, NtofsigmaBins, NptBins, NtpcsigmaBins}; +Double_t *paramBin[kNHistoParams] = {centralityBin, tofsigmaBin, ptBin, tpcsigmaBin}; +/**************************************************************/ + +/**************************************************************/ +/**************************************************************/ +/**************************************************************/ + +/**************************************************************/ + +AliTOFGeometry tofGeo; +Float_t c = TMath::C() * 1.e2 / 1.e12; /* cm/ps */ +Float_t c_1 = 1. / c; + +Double_t +GenerateRandomHit(TH1F *hT0Fill, Double_t t0fill, Int_t index) +{ + + Int_t det[5]; + Float_t length, timeexp, pos[3]; + + /* compute length and expected time */ + tofGeo.GetVolumeIndices(index, det); + tofGeo.GetPosPar(det, pos); + length = 0.; + for (Int_t i = 0; i < 3; i++) length += pos[i] * pos[i]; + length = TMath::Sqrt(length); + timeexp = length * c_1; + + Double_t hittime = hT0Fill->GetRandom() - t0fill + timeexp; + return hittime; + +} + +/**************************************************************/ + +TOFpid(const Char_t *filename, Int_t ipart, Int_t icharge, Int_t iipart, Bool_t dorapidityCut = kTRUE, Bool_t electronCut = kFALSE, Bool_t cutOnTPC = kFALSE, Float_t tpcsignalMin = -2., Float_t tpcsignalMax = 2., Int_t evMax = kMaxInt, Int_t startEv = 0, Bool_t mcFlag = kFALSE) +{ + + printf("****************************************\n"); + printf("RUNNING TOF PID:\n"); + if (dorapidityCut) + printf("RAPIDITY-CUT: %s\n", AliPID::ParticleName(ipart)); + else + printf("NO RAPIDITY-CUT\n"); + printf("CHARGE: %s\n", chargeName[icharge]); + printf("PARTICLE-ID: %s\n", AliPID::ParticleName(iipart)); + if (electronCut) + printf("-> ELECTRON CUT REQUESTED\n"); + if (cutOnTPC) + printf(" -> CUT-ON-TPC [%3.1f,%3.1f]\n", tpcsignalMin, tpcsignalMax); + printf("****************************************\n"); + + /* include path for ACLic */ + gSystem->AddIncludePath("-I$ALICE_ROOT/include"); + gSystem->AddIncludePath("-I$ALICE_ROOT/TOF"); + /* load libraries */ + gSystem->Load("libANALYSIS"); + gSystem->Load("libANALYSISalice"); + /* build analysis task class */ + gROOT->LoadMacro("AliAnalysisParticle.cxx+g"); + gROOT->LoadMacro("AliAnalysisEvent.cxx+g"); + gROOT->LoadMacro("AliAnalysisTrack.cxx+g"); + + /* create TOF response with tail */ + // gROOT->LoadMacro("~/ALICE.2011/ANALYSIS/TOFSpectraPbPb/macros/TOFsignal.C"); + gROOT->LoadMacro("TOFsignal.C"); + TF1 *fTOFsignal = new TF1("fTOFsignal", TOFsignal, -2440., 2440., 4); + fTOFsignal->SetParameter(0, 1.); + fTOFsignal->SetParameter(1, 0.); + fTOFsignal->SetParameter(2, tofReso); + fTOFsignal->SetParameter(3, tofTail); + + /* open file, get tree and connect */ + TFile *filein = TFile::Open(filename); + TTree *treein = (TTree *)filein->Get("aodTree"); + printf("got \"aodTree\": %d entries\n", treein->GetEntries()); + AliAnalysisEvent *analysisEvent = new AliAnalysisEvent(); + TClonesArray *analysisTrackArray = new TClonesArray("AliAnalysisTrack"); + AliAnalysisTrack *analysisTrack = NULL; + treein->SetBranchAddress("AnalysisEvent", &analysisEvent); + treein->SetBranchAddress("AnalysisTrack", &analysisTrackArray); + + /* open hT0fill for mismatch */ + TFile *filein_T0Fill = TFile::Open(t0FillOnlineFileName); + TH1F *hT0Fill = (TH1F *)filein_T0Fill->Get("hT0Fill"); + Double_t t0fill = t0Fill_offset; + + /* open enabled flag map */ + TH1F *hEnabledFlag = NULL; + if (enabledChannelsFileName) { + TFile *enabledfile = TFile::Open(enabledChannelsFileName); + hEnabledFlag = (TH1F *)enabledfile->Get("hEnabledFlag"); + } + + /**************************************************************/ + /*** HISTOS ***************************************************/ + /**************************************************************/ + + /* run-time binning */ + for (Int_t ibin = 0; ibin < NtofsigmaBins + 1; ibin++) + tofsigmaBin[ibin] = tofsigmaMin + ibin * tofsigmaStep; + for (Int_t ibin = 0; ibin < NtofsignalBins + 1; ibin++) + tofsignalBin[ibin] = tofsignalMin + ibin * tofsignalStep; + for (Int_t ibin = 0; ibin < NtpcsigmaBins + 1; ibin++) + tpcsigmaBin[ibin] = tpcsigmaMin + ibin * tpcsigmaStep; + for (Int_t ibin = 0; ibin < NtofresoBins + 1; ibin++) + tofresoBin[ibin] = tofresoMin + ibin * tofresoStep; + + /* histos */ + TH1F *hAcceptedEvents = new TH1F(Form("hAcceptedEvents_%s_%s_%sID", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart)), "", NcentralityBins, centralityBin); + TH2I *hAcceptedTracks = new TH2I(Form("hAcceptedTracks_%s_%s_%sID", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart)), "", NcentralityBins, centralityBin, NptBins, ptBin); + + TH3I *hTOFreso = new TH3I(Form("hTOFreso_%s_%s_%sID", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart)), "", NcentralityBins, centralityBin, NptBins, ptBin, NtofresoBins, tofresoBin); + + TH3I *hTOFpid = new TH3I(Form("hTOFpid_%s_%s_%sID", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart)), "", NcentralityBins, centralityBin, NptBins, ptBin, NtofsigmaBins, tofsigmaBin); + TH3I *hTOFpid_withTZERO = new TH3I(Form("hTOFpid_withTZERO_%s_%s_%sID", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart)), "", NcentralityBins, centralityBin, NptBins, ptBin, NtofsigmaBins, tofsigmaBin); + TH3I *hTOFmismatch = new TH3I(Form("hTOFmismatch_%s_%s_%sID", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart)), "", NcentralityBins, centralityBin, NptBins, ptBin, NtofsigmaBins, tofsigmaBin); + TH3I *hTOFexpected[AliPID::kSPECIES]; + for (Int_t iiipart = 0; iiipart < AliPID::kSPECIES; iiipart++) { + hTOFexpected[iiipart] = new TH3I(Form("hTOFexpected_%s_%s_%sID_%sBKG", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart), AliPID::ParticleName(iiipart)), "", NcentralityBins, centralityBin, NptBins, ptBin, NtofsigmaBins, tofsigmaBin); + } + + TH3I *hTOFpid_delta = new TH3I(Form("hTOFpid_delta_%s_%s_%sID", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart)), "", NcentralityBins, centralityBin, NptBins, ptBin, NtofsignalBins, tofsignalBin); + TH3I *hTOFmismatch_delta = new TH3I(Form("hTOFmismatch_delta_%s_%s_%sID", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart)), "", NcentralityBins, centralityBin, NptBins, ptBin, NtofsignalBins, tofsignalBin); + TH3I *hTOFexpected_delta[AliPID::kSPECIES]; + for (Int_t iiipart = 0; iiipart < AliPID::kSPECIES; iiipart++) { + hTOFexpected_delta[iiipart] = new TH3I(Form("hTOFexpected_delta_%s_%s_%sID_%sBKG", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart), AliPID::ParticleName(iiipart)), "", NcentralityBins, centralityBin, NptBins, ptBin, NtofsignalBins, tofsignalBin); + } + + /**************************************************************/ + /**************************************************************/ + /**************************************************************/ + + /* TOF PID response */ + AliTOFPIDResponse tofResponse; + tofResponse.SetTimeResolution(tofReso); + /* TPC PID response */ + AliTPCPIDResponse *tpcResponse = AliAnalysisTrack::GetTPCResponse(); + + /* start stopwatch */ + TStopwatch timer; + timer.Start(); + + /* verbose */ + printf("***** RUNNING for %s %s *****\n", chargeName[icharge], AliPID::ParticleName(ipart)); + if (!dorapidityCut) + printf("***** NO RAPIDITY CUT REQUESTED *****\n"); + if (cutOnTPC) { + printf("***** CUT-ON-TPC requested %3.1f-%3.1f *****\n", tpcsignalMin, tpcsignalMax); + } + + /* loop over events */ + Bool_t hastofpid; + Int_t charge, index; + UShort_t dedxN; + Double_t cent, p, pt, mt, tofsignal, tpcsignal; + Double_t dedx, bethe, deltadedx, dedx_sigma, ptpc; + Double_t time, time_sigma, timezero, timezeroTOF, timezeroA, timezeroC, timezero_sigmaTOF, timezero_sigma, tof, tof_sigma, texp, texp_sigma, deltat, deltat_sigma, tof_rnd, tof_th, signal_smear, timezero_smear, texp_smear; + + /* open TZERO calibfile */ + TH1 *hCentrality_TZEROA_mean = NULL; + TH1 *hCentrality_TZEROA_sigma = NULL; + TH1 *hCentrality_TZEROC_mean = NULL; + TH1 *hCentrality_TZEROC_sigma = NULL; + TH1 *hCentrality_TOF_mean = NULL; + TH1 *hCentrality_TOF_TZEROA_mean = NULL; + TH1 *hCentrality_TOF_TZEROC_mean = NULL; + TH1 *hCentrality_TOF_TZEROTOF_mean = NULL; + TH1 *hCentrality_TZEROA_reso = NULL; + TH1 *hCentrality_TZEROC_reso = NULL; + TH1 *hCentrality_TZEROAND_reso = NULL; + if (1) { + TFile *calibfile = TFile::Open("TZEROcalibration.root"); + hCentrality_TZEROA_mean = (TH1 *)calibfile->Get("hCentrality_TZEROA_mean"); + hCentrality_TZEROA_sigma = (TH1 *)calibfile->Get("hCentrality_TZEROA_sigma"); + hCentrality_TZEROC_mean = (TH1 *)calibfile->Get("hCentrality_TZEROC_calib"); + hCentrality_TZEROC_sigma = (TH1 *)calibfile->Get("hCentrality_TZEROC_sigma"); + hCentrality_TOF_mean = (TH1 *)calibfile->Get("hCentrality_TOF_mean"); + hCentrality_TOF_TZEROA_mean = (TH1 *)calibfile->Get("hCentrality_TOF_TZEROA_mean"); + hCentrality_TOF_TZEROC_mean = (TH1 *)calibfile->Get("hCentrality_TOF_TZEROC_mean"); + hCentrality_TOF_TZEROTOF_mean = (TH1 *)calibfile->Get("hCentrality_TOF_TZEROTOF_mean"); + + TFile *resofile = TFile::Open("TZEROresolution.root"); + hCentrality_TZEROA_reso = (TH1 *)resofile->Get("hTZEROA_reso"); + hCentrality_TZEROC_reso = (TH1 *)resofile->Get("hTZEROC_reso"); + hCentrality_TZEROAND_reso = (TH1 *)resofile->Get("hTZEROAND_reso"); + } + Double_t TZEROA_mean; + Double_t TZEROA_sigma; + Double_t TZEROC_mean; + Double_t TZEROC_sigma; + Double_t TOF_mean; + Double_t TOF_TZEROA_mean; + Double_t TOF_TZEROC_mean; + Double_t TOF_TZEROTOF_mean; + Double_t TZEROA; + Double_t TZEROA_reso; + Bool_t hasTZEROA; + Double_t TZEROC; + Double_t TZEROC_reso; + Bool_t hasTZEROC; + Double_t TZEROAND; + Double_t TZEROAND_reso; + Bool_t hasTZEROAND; + Double_t TZEROTOF; + Double_t TZEROTOF_reso; + Bool_t hasTZEROTOF; + Double_t TZEROMEAN; + Double_t TZEROMEAN_weight; + Double_t TZEROBEST; + Double_t TZEROBEST_reso; + + Double_t param[kNHistoParams]; + for (Int_t iev = startEv; iev < treein->GetEntries() && iev < evMax; iev++) { + /* get event */ + treein->GetEvent(iev); + if (iev % 10000 == 0) printf("iev = %d\n", iev); + /* check event */ + if (!analysisEvent->AcceptEvent(acceptEventType)) continue; + + /*** ACCEPTED EVENT ***/ + + /* apply time-zero TOF correction */ + // analysisEvent->ApplyTimeZeroTOFCorrection(); + + /* get centrality */ + cent = analysisEvent->GetCentralityPercentile(centralityEstimator); + + /* vertex */ + Double_t vertexz = analysisEvent->GetVertexZ(); + + /* fill histos */ + hAcceptedEvents->Fill(cent); + + /* TZERO corrections */ + Int_t icent; + for (icent = 0; icent < NcentralityBins; icent++) + if (cent < centralityBin[icent + 1]) + break; + TZEROA_mean = hCentrality_TZEROA_mean ? hCentrality_TZEROA_mean->GetBinContent(icent + 1) : 0.; + TZEROA_sigma = hCentrality_TZEROA_sigma ? hCentrality_TZEROA_sigma->GetBinContent(icent + 1) : 1000.; + TZEROC_mean = hCentrality_TZEROC_mean ? hCentrality_TZEROC_mean->GetBinContent(icent + 1) : 0.; + TZEROC_sigma = hCentrality_TZEROC_sigma ? hCentrality_TZEROC_sigma->GetBinContent(icent + 1) : 1000.; + + TOF_mean = hCentrality_TOF_mean ? hCentrality_TOF_mean->GetBinContent(icent + 1) : 0.; + TOF_TZEROA_mean = hCentrality_TOF_TZEROA_mean ? hCentrality_TOF_TZEROA_mean->GetBinContent(icent + 1) : 0.; + TOF_TZEROC_mean = hCentrality_TOF_TZEROC_mean ? hCentrality_TOF_TZEROC_mean->GetBinContent(icent + 1) : 0.; + TOF_TZEROTOF_mean = hCentrality_TOF_TZEROTOF_mean ? hCentrality_TOF_TZEROTOF_mean->GetBinContent(icent + 1) : 0.; + + TZEROA_reso = hCentrality_TZEROA_reso ? hCentrality_TZEROA_reso->GetBinContent(icent + 1) : 70.; + TZEROC_reso = hCentrality_TZEROC_reso ? hCentrality_TZEROC_reso->GetBinContent(icent + 1) : 70.; + TZEROAND_reso = hCentrality_TZEROAND_reso ? hCentrality_TZEROAND_reso->GetBinContent(icent + 1) : 50.; + + /* simulate inefficient TZERO */ + Bool_t resetTZERO = kFALSE; + if (forcetimezeroineff > 0.) + if (gRandom->Uniform() < forcetimezeroineff) + resetTZERO = kTRUE; + + /* loop over tracks */ + for (Int_t itrk = 0; itrk < analysisTrackArray->GetEntries(); itrk++) { + /* get track */ + analysisTrack = (AliAnalysisTrack *)analysisTrackArray->At(itrk); + if (!analysisTrack) continue; + /* check accepted track */ + if (!analysisTrack->AcceptTrack()) continue; + /* check rapidity */ + if (dorapidityCut) + if (analysisTrack->GetY(AliPID::ParticleMass(ipart)) - rapidityShift > rapidityMaxCut || + analysisTrack->GetY(AliPID::ParticleMass(ipart)) - rapidityShift < rapidityMinCut) continue; + + /* check charge */ + charge = analysisTrack->GetSign() > 0. ? kPositive : kNegative; + if (charge != icharge) continue; + + /*** ACCEPTED TRACK ***/ + + /* get track info */ + p = analysisTrack->GetP(); + pt = analysisTrack->GetPt(); + + /* compute track mt */ + mt = TMath::Sqrt(pt * pt + AliPID::ParticleMass(ipart) * AliPID::ParticleMass(ipart)); + + /* get TPC info */ + dedx = analysisTrack->GetTPCdEdx(); + dedxN = analysisTrack->GetTPCdEdxN(); + ptpc = analysisTrack->GetTPCmomentum(); + + /* TPC signal */ + bethe = tpcResponse->GetExpectedSignal(ptpc, iipart); + /* fix electron signal */ + if (iipart == AliPID::kElectron) + bethe += 23.; + deltadedx = dedx - bethe; + dedx_sigma = 0.07 * bethe; + tpcsignal = deltadedx / dedx_sigma; + + /* electronCut requested, remove electrons */ + if (electronCut) { + /* TPC signal */ + bethe = tpcResponse->GetExpectedSignal(ptpc, AliPID::kElectron); + /* fix electron signal */ + bethe += 23.; + deltadedx = dedx - bethe; + dedx_sigma = 0.07 * bethe; + tpcsignal = deltadedx / dedx_sigma; + if (TMath::Abs(tpcsignal) < 1.5) continue; + } + + /* cut on TPC signal if requested */ + if (cutOnTPC && (tpcsignal < tpcsignalMin || tpcsignal > tpcsignalMax)) + continue; + + /* fill histos */ + hAcceptedTracks->Fill(cent, pt); + + /* set TOF pid flag */ + hastofpid = analysisTrack->HasTOFPID(hEnabledFlag); + + /* check TOF pid */ + if (!hastofpid) + continue; + + /*** ACCEPTED TRACK WITH TOF PID ***/ + + /* apply expected time correction */ + // analysisTrack->ApplyTOFExpectedTimeCorrection(); + + /* get TOF info */ + index = analysisTrack->GetTOFIndex(); + time = analysisTrack->GetTOFTime() - TOF_mean; + time_sigma = tofReso; + /* TZEROTOF */ + TZEROTOF = analysisEvent->GetTimeZeroTOF(analysisTrack->GetP()); + TZEROTOF_reso = analysisEvent->GetTimeZeroTOFSigma(analysisTrack->GetP()); + hasTZEROTOF = TZEROTOF_reso < 150.; + if (hasTZEROTOF) { + TZEROTOF += TOF_TZEROTOF_mean - TOF_mean; + TZEROTOF_reso *= TZEROTOF_resoScaleFactor; + } + /* TZEROA */ + TZEROA = analysisEvent->GetTimeZeroT0(1) - TZEROA_shift; + // TZEROA_reso = TZEROA_resolution[icent]; + hasTZEROA = TMath::Abs(TZEROA - TZEROA_mean) < 3. * TZEROA_sigma; + TZEROA += TOF_TZEROA_mean - TOF_mean; + /* TZEROC */ + TZEROC = analysisEvent->GetTimeZeroT0(2) - TZEROC_shift; + // TZEROC_reso = TZEROC_resolution[icent]; + hasTZEROC = TMath::Abs(TZEROC - TZEROC_mean) < 3. * TZEROC_sigma; + TZEROC += TOF_TZEROC_mean - TOF_mean; + /* TZEROAND */ + TZEROAND = (TZEROA + TZEROC) * 0.5; + // TZEROAND_reso = TZEROAND_resolution[icent]; + hasTZEROAND = hasTZEROA && hasTZEROC; + /* TZEROMEAN */ + TZEROMEAN = TZEROTOF / TZEROTOF_reso / TZEROTOF_reso; + TZEROMEAN_weight = 1. / TZEROTOF_reso / TZEROTOF_reso; + if (hasTZEROAND) { + // printf("TZEROAND\n"); + TZEROMEAN += TZEROAND / TZEROAND_reso / TZEROAND_reso; + TZEROMEAN_weight = 1. / TZEROAND_reso / TZEROAND_reso; + } + else if (hasTZEROA) { + // printf("TZEROA\n"); + TZEROMEAN += TZEROA / TZEROA_reso / TZEROA_reso; + TZEROMEAN_weight = 1. / TZEROA_reso / TZEROA_reso; + } + else if (hasTZEROC) { + // printf("TZEROC\n"); + TZEROMEAN += TZEROC / TZEROC_reso / TZEROC_reso; + TZEROMEAN_weight = 1. / TZEROC_reso / TZEROC_reso; + } + timezero = TZEROMEAN / TZEROMEAN_weight; + timezero_sigma = TMath::Sqrt(1. / TZEROMEAN_weight); + /* TZEROBEST */ + TZEROBEST = TZEROTOF; + TZEROBEST_reso = TZEROTOF_reso; + if (hasTZEROAND && TZEROAND_reso < TZEROBEST_reso) { + TZEROBEST = TZEROAND; + TZEROBEST_reso = TZEROAND_reso; + } + else if (hasTZEROA && TZEROA_reso < TZEROBEST_reso) { + TZEROBEST = TZEROA; + TZEROBEST_reso = TZEROA_reso; + } + if (hasTZEROC && TZEROC_reso < TZEROBEST_reso) { + TZEROBEST = TZEROC; + TZEROBEST_reso = TZEROC_reso; + } + timezero = TZEROBEST; + timezero_sigma = TZEROBEST_reso; + + /* DEBUG */ + // timezero = 0.;//TZEROTOF; + // timezero_sigma = 203.854691;//TZEROTOF_reso; + + // if (timezero == 0.) + // printf("%f %f\n", timezero, timezero_sigma); + + timezero_sigma *= scaletimezerosigma; + + if (resetTZERO) { + timezero = 0.; + timezero_sigma = timezero_spread; + } + + + tof = time - timezero; + tof_sigma = TMath::Sqrt(time_sigma * time_sigma + timezero_sigma * timezero_sigma); + + /* TOF expected time */ + texp = analysisTrack->GetTOFExpTime(iipart); + texp_sigma = analysisTrack->GetTOFExpTimeSigma(iipart) * scaletexpreso[iipart]; + + /* TOF signal */ + deltat = tof - texp; + deltat_sigma = TMath::Sqrt(tof_sigma * tof_sigma + texp_sigma * texp_sigma); + tofsignal = deltat / deltat_sigma; + + /* fill histo */ + hTOFpid->Fill(cent, pt, tofsignal); + hTOFpid_delta->Fill(cent, p, deltat); + hTOFreso->Fill(cent, pt, deltat_sigma); + if (hasTZEROTOF || hasTZEROA || hasTZEROC || hasTZEROAND) + hTOFpid_withTZERO->Fill(cent, pt, tofsignal); + + + /*** EXPECTED MISMATCH ***/ + + /* loop to generated random hits */ + for (Int_t irnd = 0; irnd < NmismatchTrials; irnd++) { + + /* generate ramdom tof values */ + tof_rnd = GenerateRandomHit(hT0Fill, t0fill, index); + + /* TOF signal */ + deltat = tof_rnd - texp; + tofsignal = deltat / deltat_sigma; + + /* fill histo */ + hTOFmismatch->Fill(cent, pt, tofsignal); + hTOFmismatch_delta->Fill(cent, p, deltat); + + } /* end of loop over generated random hits */ + + /*** EXPECTED SIGNALS ***/ + + /* loop over other particles */ + for (Int_t iiipart = 0; iiipart < AliPID::kSPECIES; iiipart++) { + + /* generate expected tof value */ + tof_th = analysisTrack->GetTOFExpTime(iiipart); + texp_sigma = analysisTrack->GetTOFExpTimeSigma(iiipart) * scaletexpreso[iiipart]; + + /* loop over many trials */ + for (Int_t irnd = 0; irnd < NexpectedTrials; irnd++) { + + /* tof response smearing */ + signal_smear = fTOFsignal->GetRandom(); + /* timezero resolution smearing */ + timezero_smear = gRandom->Gaus(0., timezero_sigma); + /* texp resolution smearing */ + texp_smear = gRandom->Gaus(0., texp_sigma); + + /* deltat and sigma */ + deltat = tof_th - texp + signal_smear + timezero_smear + texp_smear; + tofsignal = deltat / deltat_sigma; + + /* fill histo */ + hTOFexpected[iiipart]->Fill(cent, pt, tofsignal); + hTOFexpected_delta[iiipart]->Fill(cent, p, deltat); + + } /* end of loop over many trials */ + } /* end of loop over other particle */ + } /* end of loop over tracks */ + } /* end of loop over events */ + + /* stop stopwatch */ + timer.Stop(); + timer.Print(); + + /* output */ + TString outputstring = "TOFpid"; + if (!dorapidityCut) + outputstring += "_noRapidityCut"; + if (electronCut) + outputstring += "_electronCut"; + if (cutOnTPC) + outputstring += Form("_cutOnTPC[%3.1f,%3.1f]", , tpcsignalMin, tpcsignalMax); + outputstring += Form("_%s_%s_%sID.%s", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart), filename); + TFile *fileout = TFile::Open(outputstring.Data(), "RECREATE"); + hAcceptedEvents->Write(); + hAcceptedTracks->Write(); + hTOFpid->Write(); + hTOFreso->Write(); + hTOFpid_withTZERO->Write(); + hTOFmismatch->Write(); + for (Int_t iiipart = 0; iiipart < AliPID::kSPECIES; iiipart++) + hTOFexpected[iiipart]->Write(); + hTOFpid_delta->Write(); + hTOFmismatch_delta->Write(); + for (Int_t iiipart = 0; iiipart < AliPID::kSPECIES; iiipart++) + hTOFexpected_delta[iiipart]->Write(); + + fileout->Close(); + +} + +//___________________________________________________________________________________ + +TOFspectra_defaultFit(const Char_t *filename) +{ + +Bool_t EXPECTED_SIGNAL_TEMPLATE = kTRUE; +Bool_t EXPECTED_SIGNAL_FIT = kFALSE; +Bool_t EXPECTED_BACKGROUND_TEMPLATE = kFALSE; +Bool_t EXPECTED_BACKGROUND_FIT = kTRUE; + +} + +//___________________________________________________________________________________ + +TOFspectra_defaultFit_fitElectrons(const Char_t *filename, Float_t electronLimit = 5.) +{ + + + TOFspectra(filename, electronLimit); +} + +//___________________________________________________________________________________ + +TOFspectra_signalFit(Bool_t fixParams = kTRUE, Float_t scaleSigma = 1., Float_t scaleTail = 1.) +{ + + EXPECTED_SIGNAL_TEMPLATE = kFALSE; + EXPECTED_SIGNAL_FIT = kTRUE; + FIX_SIGNAL_MEAN = fixParams; + FIX_SIGNAL_SIGMA = fixParams; + FIX_SIGNAL_TAIL = fixParams; + SCALE_SIGNAL_SIGMA = scaleSigma; + SCALE_SIGNAL_TAIL = scaleTail; + +} + +//___________________________________________________________________________________ + +TOFspectra_bkgFit(Bool_t fixParams = kTRUE, Float_t scaleSigma = 1., Float_t scaleTail = 1.) +{ + + EXPECTED_BACKGROUND_TEMPLATE = kFALSE; + EXPECTED_BACKGROUND_FIT = kTRUE; + FIX_BACKGROUND_MEAN = fixParams; + FIX_BACKGROUND_SIGMA = fixParams; + FIX_BACKGROUND_TAIL = fixParams; + SCALE_BACKGROUND_SIGMA = scaleSigma; + SCALE_BACKGROUND_TAIL = scaleTail; + + TOFspectra(filename); + +} + +//___________________________________________________________________________________ + +void +TOFspectra(const Char_t *filename, Float_t electronLimit = 0.) +{ + + for (Int_t icent = 0; icent < NcentralityBins; icent++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) + TOFspectrum(filename, ipart, icharge, ipart, icent, -1., -1., electronLimit); + +} + +//___________________________________________________________________________________ + +#define USENSIGMA 1 + +/* fit ranges */ +Double_t fitPtMin[AliPID::kSPECIES] = {0.5, 0.5, 0.3, 0.4, 0.5}; +Double_t fitPtMax[AliPID::kSPECIES] = {3.0, 3.0, 3.0, 3.0, 5.0}; +#if USENSIGMA +Double_t fitSigmaMin[AliPID::kSPECIES] = {tofsigmaMin, tofsigmaMin, -25., -75., -65.}; +Double_t fitSigmaMax[AliPID::kSPECIES] = {tofsigmaMax, tofsigmaMax, 225., 200., 100.}; +#else +Double_t fitSigmaMin[AliPID::kSPECIES] = {-24400., -24400., -24400., -24400., -24400.}; +Double_t fitSigmaMax[AliPID::kSPECIES] = {24400., 24400., 24400., 24400., 24400.}; +#endif + +void +TOFspectrum(const Char_t *filename, Int_t ipart, Int_t icharge, Int_t iipart, Int_t icent, Float_t ptMin = -1., Float_t ptMax = -1., Bool_t checkHistoFlag = kFALSE) +{ + + printf("****************************************\n"); + printf("RUNNING SPECTRA FIT:\n"); + printf("RAPIDITY-CUT: %s\n", AliPID::ParticleName(ipart)); + printf("RAPIDITY-CUT: %s\n", AliPID::ParticleName(ipart)); + printf("CHARGE: %s\n", chargeName[icharge]); + printf("PARTICLE: %s\n", AliPID::ParticleName(iipart)); + printf("CENTRALITY BIN: %d\n", icent); + printf("****************************************\n"); + + /* mismatch balance functions */ + TF1 *fMismatchBalanceFunction[5][2]; + Double_t mismatchBalanceParam0[5][2] = { + 0., 0., + 0., 0., + 0.669488, 0.599374, + -1.2582, -2.53613, + 5.48850e-01, 10.1622 + }; + Double_t mismatchBalanceParam1[5][2] = { + 0., 0., + 0., 0., + -1.64894, -0.825764, + -1.63683, -2.55156, + -1.64894, -7.09531 + }; + for (Int_t iiipart = 0; iiipart < AliPID::kSPECIES; iiipart++) { + for (Int_t iiicharge = 0; iiicharge < 2; iiicharge++) { + fMismatchBalanceFunction[iiipart][iiicharge] = new TF1(Form(""), "1. - [0]*TMath::Exp(x*[1])", 0., 5.); + fMismatchBalanceFunction[iiipart][iiicharge]->SetParameter(0, mismatchBalanceParam0[iiipart][iiicharge]); + fMismatchBalanceFunction[iiipart][iiicharge]->SetParameter(1, mismatchBalanceParam1[iiipart][iiicharge]); + } + } + + /* open data */ + TFile *filein = TFile::Open(filename); + + /* get number of events */ + TH1F *hAcceptedEvents = (TH1F *)filein->Get(Form("hAcceptedEvents_%s_%s_%sID", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart))); + if (!hAcceptedEvents) { + printf("cannot find %s\n", Form("hAcceptedEvents_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart))); + return; + } + Double_t nevents; + if (icent < 0 || icent >= NcentralityBins) + nevents = hAcceptedEvents->GetEntries(); + else + nevents = hAcceptedEvents->Integral(icent + 1, icent + 1); + printf("N_EVENTS : %d\n", nevents); + printf("****************************************\n"); + + /* get histos */ + TH2I *hAcceptedTracks = (TH2I *)filein->Get(Form("hAcceptedTracks_%s_%s_%sID", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart))); + if (!hAcceptedTracks) { + printf("cannot find %s\n", Form("hAcceptedTracks_%s_%s_%sID", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart))); + // return; + } +#if USENSIGMA + TH3I *hTOFpid = (TH3I *)filein->Get(Form("hTOFpid_%s_%s_%sID", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart))); +#else + TH3I *hTOFpid = (TH3I *)filein->Get(Form("hTOFpid_delta_%s_%s_%sID", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart))); +#endif + if (!hTOFpid) { + printf("cannot find %s\n", Form("hTOFpid_%s_%s_%sID", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart))); + return; + } +#if USENSIGMA + TH3I *hTOFmismatch = (TH3I *)filein->Get(Form("hTOFmismatch_%s_%s_%sID", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart))); +#else + TH3I *hTOFmismatch = (TH3I *)filein->Get(Form("hTOFmismatch_delta_%s_%s_%sID", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart))); +#endif + if (!hTOFmismatch) { + printf("cannot find %s\n", Form("hTOFpid_%s_%s_%sID", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart))); + return; + } + TH3I *hTOFexpected[AliPID::kSPECIES]; + for (Int_t iiipart = 0; iiipart < AliPID::kSPECIES; iiipart++) { +#if USENSIGMA + hTOFexpected[iiipart] = (TH3I *)filein->Get(Form("hTOFexpected_%s_%s_%sID_%sBKG", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart), AliPID::ParticleName(iiipart))); +#else + hTOFexpected[iiipart] = (TH3I *)filein->Get(Form("hTOFexpected_delta_%s_%s_%sID_%sBKG", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart), AliPID::ParticleName(iiipart))); +#endif + if (!hTOFexpected[iiipart]) { + printf("cannot find %s\n", Form("hTOFexpected_%s_%s_%sID_%sBKG", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart), AliPID::ParticleName(iiipart))); + return; + } + } + + /* setup centrality range */ + if (icent < 0 || icent >= NcentralityBins) { + printf("WARNING: undefined centrality -> using 00-90\% range\n"); + if (hAcceptedTracks) hAcceptedTracks->GetXaxis()->SetRange(1, NcentralityBins); + hTOFpid->GetXaxis()->SetRange(1, NcentralityBins); + hTOFmismatch->GetXaxis()->SetRange(1, NcentralityBins); + for (Int_t iiipart = 0; iiipart < AliPID::kSPECIES; iiipart++) + hTOFexpected[iiipart]->GetXaxis()->SetRange(1, NcentralityBins); + } + else { + printf("***** FITTING CENTRALITY-BIN [%02d, %02d] %% *****\n", centralityBin[icent], centralityBin[icent + 1]); + if (hAcceptedTracks) hAcceptedTracks->GetXaxis()->SetRange(icent + 1, icent + 1); + hTOFpid->GetXaxis()->SetRange(icent + 1, icent + 1); + hTOFmismatch->GetXaxis()->SetRange(icent + 1, icent + 1); + for (Int_t iiipart = 0; iiipart < AliPID::kSPECIES; iiipart++) + hTOFexpected[iiipart]->GetXaxis()->SetRange(icent + 1, icent + 1); + } + + /* init flags */ + Bool_t requestedRange = kFALSE; + Bool_t fitElectrons = kTRUE; + Bool_t fitMuons = kTRUE; + Bool_t fitPions = kTRUE; + + /* setup pt range if requested */ + if (ptMin > -0.001 && ptMax > -0.001 && ptMax > ptMin) { + printf("***** FITTING PT-BIN [%f, %f] GeV/c *****\n", ptMin, ptMax); + requestedRange = kTRUE; + + /* check electron-fit is allowed */ + fitElectrons = kTRUE; + if ((ptMin + 0.001) < FIT_ELECTRONS_PT_MIN || (ptMax - 0.001) > FIT_ELECTRONS_PT_MAX) + fitElectrons = kFALSE; + /* check muon-fit is allowed */ + fitMuons = kTRUE; + if ((ptMin + 0.001) < FIT_MUONS_PT_MIN || (ptMax - 0.001) > FIT_MUONS_PT_MAX) + fitMuons = kFALSE; + /* check pion-fit is allowed */ + fitPions = kTRUE; + if ((ptMin + 0.001) < FIT_PIONS_PT_MIN || (ptMax - 0.001) > FIT_PIONS_PT_MAX) + fitPions = kFALSE; + + + hTOFpid->GetYaxis()->SetRangeUser(ptMin + 0.001, ptMax - 0.001); + hTOFmismatch->GetYaxis()->SetRangeUser(ptMin + 0.001, ptMax - 0.001); + for (Int_t iiipart = 0; iiipart < AliPID::kSPECIES; iiipart++) + hTOFexpected[iiipart]->GetYaxis()->SetRangeUser(ptMin + 0.001, ptMax - 0.001); + } + + /* output */ + Char_t outfilename[1024]; + if (icent < 0 || icent >= NcentralityBins) + sprintf(outfilename, "TOFspectrum_cent0090_%s_%s_%sID.root", AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart)); + else { + sprintf(outfilename, "TOFspectrum_cent%02d%02d_%s_%s_%sID.root", centralityBin[icent], centralityBin[icent + 1], AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart)); + } + TFile *fileout = TFile::Open(outfilename, "RECREATE"); + TDirectory *fitDir = fileout->mkdir("FitParams"); + /* canvas */ + TCanvas *canvas = new TCanvas("canvas"); + canvas->SetLogy(); + /* histo */ + TH1D *hFitParamHisto[kNFitParams]; + for (Int_t iparam = 0; iparam < kNFitParams; iparam++) + hFitParamHisto[iparam] = new TH1D(Form("h%s", fitParamName[iparam]), fitParamTitle[iparam], NptBins, ptBin); + + /* loop over ptBins */ + for (Int_t ipt = 0; ipt < NptBins; ipt++) { + + if (!requestedRange) { + if ((ptBin[ipt] + 0.001) < fitPtMin[ipart] || (ptBin[ipt + 1] - 0.001) > fitPtMax[ipart]) continue; + printf("***** FITTING PT-BIN [%f, %f] GeV/c *****\n", ptBin[ipt], ptBin[ipt + 1]); + + /* check electron-fit is allowed */ + fitElectrons = kTRUE; + if ((ptBin[ipt] + 0.001) < FIT_ELECTRONS_PT_MIN || (ptBin[ipt + 1] - 0.001) > FIT_ELECTRONS_PT_MAX) + fitElectrons = kFALSE; + /* check muon-fit is allowed */ + fitMuons = kTRUE; + if ((ptBin[ipt] + 0.001) < FIT_MUONS_PT_MIN || (ptBin[ipt + 1] - 0.001) > FIT_MUONS_PT_MAX) + fitMuons = kFALSE; + /* check pion-fit is allowed */ + fitPions = kTRUE; + if ((ptBin[ipt] + 0.001) < FIT_PIONS_PT_MIN || (ptBin[ipt + 1] - 0.001) > FIT_PIONS_PT_MAX) + fitPions = kFALSE; + + hTOFpid->GetYaxis()->SetRange(ipt + 1, ipt + 1); + hTOFmismatch->GetYaxis()->SetRange(ipt + 1, ipt + 1); + for (Int_t iiipart = 0; iiipart < AliPID::kSPECIES; iiipart++) + hTOFexpected[iiipart]->GetYaxis()->SetRange(ipt + 1, ipt + 1); + } + + /* nsigma projections */ + TH1 *hSignal_py = hTOFpid->Project3D("z"); + TH1 *hMismatch_py = hTOFmismatch->Project3D("z"); + TH1 *hSignalExp_py[AliPID::kSPECIES]; + TH1 *hSignalExpTail_py[AliPID::kSPECIES]; + for (Int_t iiipart = 0; iiipart < AliPID::kSPECIES; iiipart++) { + hSignalExp_py[iiipart] = hTOFexpected[iiipart]->Project3D("z"); + hSignalExpTail_py[iiipart] = hTOFexpected[iiipart]->Project3D("z"); + } + + /* prepare histos for the fitter */ + Int_t partbkg1[AliPID::kSPECIES] = {AliPID::kKaon, AliPID::kKaon, AliPID::kKaon, AliPID::kPion, AliPID::kPion}; + Int_t partbkg2[AliPID::kSPECIES] = {AliPID::kProton, AliPID::kProton, AliPID::kProton, AliPID::kProton, AliPID::kKaon}; + Int_t partbkg3[AliPID::kSPECIES] = {AliPID::kPion, AliPID::kPion, AliPID::kElectron, AliPID::kElectron, AliPID::kElectron}; + Int_t partbkg4[AliPID::kSPECIES] = {AliPID::kMuon, AliPID::kElectron, AliPID::kMuon, AliPID::kMuon, AliPID::kMuon}; + TH1 *hSigExp_py, *hBkgExp1_py, *hBkgExp2_py, *hBkgExp3_py, *hBkgExp4_py; + hSigExp_py = EXPECTED_SIGNAL_TAIL ? hSignalExpTail_py[iipart] : hSignalExp_py[iipart]; + hBkgExp1_py = EXPECTED_BACKGROUND_TAIL ? hSignalExpTail_py[partbkg1[iipart]] : hSignalExp_py[partbkg1[iipart]]; + hBkgExp2_py = EXPECTED_BACKGROUND_TAIL ? hSignalExpTail_py[partbkg2[iipart]] : hSignalExp_py[partbkg2[iipart]]; + hBkgExp3_py = EXPECTED_BACKGROUND_TAIL ? hSignalExpTail_py[partbkg3[iipart]] : hSignalExp_py[partbkg3[iipart]]; + hBkgExp4_py = EXPECTED_BACKGROUND_TAIL ? hSignalExpTail_py[partbkg4[iipart]] : hSignalExp_py[partbkg4[iipart]]; + + /* check histos if requested */ + if (checkHistoFlag) { + TCanvas *cCheckHisto = new TCanvas("cCheckHisto"); + cCheckHisto->Divide(2, 3); + cCheckHisto->cd(1); + hSignal_py->Draw(); + cCheckHisto->cd(2); + hSigExp_py->Draw(); + cCheckHisto->cd(3); + hBkgExp1_py->Draw(); + cCheckHisto->cd(4); + hBkgExp2_py->Draw(); + cCheckHisto->cd(5); + hBkgExp3_py->Draw(); + cCheckHisto->cd(6); + hMismatch_py->Draw(); + return; + } + + Double_t rangeMin = fitSigmaMin[iipart], rangeMax = fitSigmaMax[iipart]; + Bool_t constrainSignal = kFALSE; + Bool_t constrainBkg1 = kFALSE; + Bool_t constrainBkg2 = kFALSE; + Bool_t forceGaussianSignal = kFALSE; + Bool_t fitBkg1 = kTRUE, fitBkg2 = kTRUE, fitBkg3 = kTRUE, fitBkg4 = kTRUE; + + /* check whether we can fit electrons */ + if (!fitElectrons) { + printf("INHIBIT FIT ELECTRONS\n"); + if (partbkg1[iipart] == AliPID::kElectron) fitBkg1 = kFALSE; + if (partbkg2[iipart] == AliPID::kElectron) fitBkg2 = kFALSE; + if (partbkg3[iipart] == AliPID::kElectron) fitBkg3 = kFALSE; + if (partbkg4[iipart] == AliPID::kElectron) fitBkg4 = kFALSE; + } + /* check whether we can fit muons */ + if (!fitMuons) { + printf("INHIBIT FIT MUONS\n"); + if (partbkg1[iipart] == AliPID::kMuon) fitBkg1 = kFALSE; + if (partbkg2[iipart] == AliPID::kMuon) fitBkg2 = kFALSE; + if (partbkg3[iipart] == AliPID::kMuon) fitBkg3 = kFALSE; + if (partbkg4[iipart] == AliPID::kMuon) fitBkg4 = kFALSE; + } + /* check whether we can fit pions */ + if (!fitPions) { + printf("INHIBIT FIT PIONS\n"); + if (partbkg1[iipart] == AliPID::kPion) fitBkg1 = kFALSE; + if (partbkg2[iipart] == AliPID::kPion) fitBkg2 = kFALSE; + if (partbkg3[iipart] == AliPID::kPion) fitBkg3 = kFALSE; + if (partbkg4[iipart] == AliPID::kPion) fitBkg4 = kFALSE; + } + + + /* fit */ + Double_t param[kNFitParams]; + Double_t param_err[kNFitParams]; + TOFpid_fit(hSignal_py, hSigExp_py, hBkgExp1_py, hBkgExp2_py, hBkgExp3_py, hBkgExp4_py, hMismatch_py, rangeMin, rangeMax, fitBkg1, fitBkg2, fitBkg3, fitBkg4, constrainSignal, constrainBkg1, constrainBkg2, forceGaussianSignal, param, param_err, canvas); + + + /* if fitting pions add electrons and to the signal */ + if (iipart == 2) { + param[kSignalCounts] += param[kBkg3Counts] + param[kBkg4Counts]; + param_err[kSignalCounts] = TMath::Sqrt(param_err[kSignalCounts] * param_err[kSignalCounts] + param_err[kBkg3Counts] * param_err[kBkg3Counts] + param_err[kBkg4Counts] * param_err[kBkg3Counts]); + } + /* else add to bkg1 (pions) */ + else { + param[kBkg1Counts] += param[kBkg3Counts] + param[kBkg4Counts]; + param_err[kBkg1Counts] = TMath::Sqrt(param_err[kBkg1Counts] * param_err[kBkg1Counts] + param_err[kBkg3Counts] * param_err[kBkg3Counts] + param_err[kBkg4Counts] * param_err[kBkg3Counts]); + } + + /* check requested pt-range */ + if (requestedRange) + return; + + /* write canvas */ + fitDir->cd(); + canvas->Write(Form("fitDisplay_ptBin_%3.2f_%3.2f", ptBin[ipt], ptBin[ipt + 1])); + + /* set histo */ + for (Int_t iparam = 0; iparam < kNFitParams; iparam++) { + hFitParamHisto[iparam]->SetBinContent(ipt + 1, param[iparam]); + hFitParamHisto[iparam]->SetBinError(ipt + 1, param_err[iparam]); + } + + /* delete */ + delete hSignal_py; + delete hMismatch_py; + for (Int_t iiipart = 0; iiipart < AliPID::kSPECIES; iiipart++) { + delete hSignalExp_py[iiipart]; + // delete hSignalExpTail_py[iiipart]; + } + } + + /* check requested pt-range */ + if (requestedRange) + return; + + /*** POST-ANALYSIS ***/ + + TDirectory *postDir = fileout->mkdir("PostAnalysis"); + + /* compute overflows */ + TH1D *hOverflowCounts = new TH1D(*hFitParamHisto[kTotalCounts]); + hOverflowCounts->SetNameTitle("hOverflowCounts", "Overflow counts: TotalCounts - IntegralCounts;p_{T} (GeV/c);counts"); + hOverflowCounts->Add(hFitParamHisto[kIntegralCounts], -1.); + /* compute total mismatch counts */ + TH1D *hTotalMismatchCounts = new TH1D(*hFitParamHisto[kMismatchCounts]); + hTotalMismatchCounts->SetNameTitle("hTotalMismatchCounts", "Total mismatch counts: MismatchCounts + OverflowCounts;p_{T} (GeV/c);counts"); + hTotalMismatchCounts->Add(hOverflowCounts); + /* computed mismatch fraction */ + TH1D *hTotalMismatchFraction = new TH1D(*hTotalMismatchCounts); + hTotalMismatchFraction->SetNameTitle("hTotalMismatchFraction", "Total mismatch fraction: TotalMismatchCounts / TotalCounts;p_{T} (GeV/c);"); + hTotalMismatchFraction->Divide(hFitParamHisto[kTotalCounts]); + /* compute identified counts */ + TH1D *hIdentifiedCounts = new TH1D(*hFitParamHisto[kSignalCounts]); + hIdentifiedCounts->SetNameTitle("hIdentifiedCounts", "Identified counts: SignalCounts + sum(BkgCounts);p_{T} (GeV/c);counts"); + hIdentifiedCounts->Add(hFitParamHisto[kBkg1Counts]); + hIdentifiedCounts->Add(hFitParamHisto[kBkg2Counts]); + // hIdentifiedCounts->Add(hFitParamHisto[kBkg3Counts]); + // hIdentifiedCounts->Add(hFitParamHisto[kBkg4Counts]); + /* compute signal fraction */ + TH1D *hSignalFraction = new TH1D(*hFitParamHisto[kSignalCounts]); + hSignalFraction->SetNameTitle("hSignalFraction", "Signal fraction: SignalCounts / IdentifiedCounts;p_{T} (GeV/c);"); + hSignalFraction->Divide(hSignalFraction, hIdentifiedCounts, 1., 1., "B"); + /* compute bkg1 fraction */ + TH1D *hBkg1Fraction = new TH1D(*hFitParamHisto[kBkg1Counts]); + hBkg1Fraction->SetNameTitle("hBkg1Fraction", "Bkg1 fraction: Bkg1Counts / IdentifiedCounts;p_{T} (GeV/c);"); + hBkg1Fraction->Divide(hBkg1Fraction, hIdentifiedCounts, 1., 1., "B"); + /* compute bkg2 fraction */ + TH1D *hBkg2Fraction = new TH1D(*hFitParamHisto[kBkg2Counts]); + hBkg2Fraction->SetNameTitle("hBkg2Fraction", "Bkg2 fraction: Bkg2Counts / IdentifiedCounts;p_{T} (GeV/c);"); + hBkg2Fraction->Divide(hBkg2Fraction, hIdentifiedCounts, 1., 1., "B"); + /* compute bkg3 fraction */ + TH1D *hBkg3Fraction = new TH1D(*hFitParamHisto[kBkg3Counts]); + hBkg3Fraction->SetNameTitle("hBkg3Fraction", "Bkg3 fraction: Bkg3Counts / IdentifiedCounts;p_{T} (GeV/c);"); + hBkg3Fraction->Divide(hBkg3Fraction, hIdentifiedCounts, 1., 1., "B"); + /* compute bkg4 fraction */ + TH1D *hBkg4Fraction = new TH1D(*hFitParamHisto[kBkg4Counts]); + hBkg4Fraction->SetNameTitle("hBkg4Fraction", "Bkg4 fraction: Bkg4Counts / IdentifiedCounts;p_{T} (GeV/c);"); + hBkg4Fraction->Divide(hBkg4Fraction, hIdentifiedCounts, 1., 1., "B"); + /* rework */ + TH1D *hSignalFractionReworked = new TH1D(*hFitParamHisto[kSignalCounts]); + hSignalFractionReworked->SetNameTitle("hSignalFractionReworked", "Signal fraction reworked: SignalCounts / IdentifiedCounts;p_{T} (GeV/c);"); + hSignalFractionReworked->Multiply(fMismatchBalanceFunction[iipart][icharge]); + TH1D *hBkg1FractionReworked = new TH1D(*hFitParamHisto[kBkg1Counts]); + hBkg1FractionReworked->SetNameTitle("hBkg1FractionReworked", "Bkg1 fraction reworked: SignalCounts / IdentifiedCounts;p_{T} (GeV/c);"); + hBkg1FractionReworked->Multiply(fMismatchBalanceFunction[partbkg1[iipart]][icharge]); + TH1D *hBkg2FractionReworked = new TH1D(*hFitParamHisto[kBkg2Counts]); + hBkg2FractionReworked->SetNameTitle("hBkg2FractionReworked", "Bkg1 fraction reworked: SignalCounts / IdentifiedCounts;p_{T} (GeV/c);"); + hBkg2FractionReworked->Multiply(fMismatchBalanceFunction[partbkg2[iipart]][icharge]); + TH1D *hIdentifiedCountsReworked = new TH1D(*hSignalFractionReworked); + hIdentifiedCountsReworked->SetNameTitle("hIdentifiedCountsReworked", "Identified counts reworked: SignalCounts / IdentifiedCounts;p_{T} (GeV/c);"); + hIdentifiedCountsReworked->Add(hBkg1FractionReworked); + hIdentifiedCountsReworked->Add(hBkg2FractionReworked); + + hSignalFractionReworked->Divide(hSignalFractionReworked, hIdentifiedCountsReworked, 1., 1., "B"); + + /* compute mismatch-correction counts */ + TH1D *hMismatchCorrectionCounts = new TH1D(*hTotalMismatchCounts); + hMismatchCorrectionCounts->SetNameTitle("hMismatchCorrectionCounts", "Mismatch-correction counts: TotalMismatchCounts * SignalFraction;p_{T} (GeV/c);counts"); + hMismatchCorrectionCounts->Multiply(hSignalFractionReworked); + /* compute mismatch-corrected signal counts */ + TH1D *hMismatchCorrectedSignalCounts = new TH1D(*hFitParamHisto[kSignalCounts]); + hMismatchCorrectedSignalCounts->SetNameTitle("hMismatchCorrectedSignalCounts", "Mismatch-corrected signal counts: SignalCounts + MismatchCorrectionCounts;p_{T} (GeV/c);counts"); + hMismatchCorrectedSignalCounts->Add(hMismatchCorrectionCounts); + + + /* accepted tracks histo */ + if (hAcceptedTracks) { + TH1D *hAcceptedTracks_py = hAcceptedTracks->ProjectionY(); + hAcceptedTracks_py->SetNameTitle("hAcceptedTracks", "Accepted tracks;p_{T} (GeV/c);"); + hAcceptedTracks_py->Sumw2(); + } + + /*** RAW SPECTRA ***/ + + TDirectory *rawDir = fileout->mkdir("RawSpectra"); + + /* compute normalized raw yield */ + TH1D *hNormalizedRawYield = new TH1D(*hFitParamHisto[kSignalCounts]); + hNormalizedRawYield->SetNameTitle("hNormalizedRawYield", "Raw yield;p_{T} (GeV/c);#frac{1}{N_{ev}} #frac{d^{2}N}{dy dp_{T}}"); + TOFpid_normalize(hNormalizedRawYield, nevents); + /* compute normalized mismatch-corrected raw yield */ + TH1D *hNormalizedMismatchCorrectedRawYield = new TH1D(*hMismatchCorrectedSignalCounts); + hNormalizedMismatchCorrectedRawYield->SetNameTitle("hNormalizedMismatchCorrectedRawYield", "Mismatch-corrected raw yield;p_{T} (GeV/c);#frac{1}{N_{ev}} #frac{d^{2}N}{dy dp_{T}}"); + TOFpid_normalize(hNormalizedMismatchCorrectedRawYield, nevents); + + /*** OUTPUT ***/ + + /* write fir params histos */ + fitDir->cd(); + for (Int_t iparam = 0; iparam < kNFitParams; iparam++) + hFitParamHisto[iparam]->Write(); + /* write post-analysis histos */ + postDir->cd(); + hOverflowCounts->Write(); + hTotalMismatchCounts->Write(); + hTotalMismatchFraction->Write(); + hIdentifiedCounts->Write(); + hSignalFraction->Write(); + hSignalFractionReworked->Write(); + hBkg1Fraction->Write(); + hBkg2Fraction->Write(); + hBkg3Fraction->Write(); + hBkg4Fraction->Write(); + hMismatchCorrectionCounts->Write(); + hMismatchCorrectedSignalCounts->Write(); + if (hAcceptedTracks) hAcceptedTracks_py->Write(); + /* write raw spectra histos */ + rawDir->cd(); + hNormalizedRawYield->Write(); + hNormalizedMismatchCorrectedRawYield->Write(); + + /* clean up */ + delete canvas; + for (Int_t iparam = 0; iparam < kNFitParams; iparam++) + delete hFitParamHisto[iparam]; + delete hOverflowCounts; + delete hTotalMismatchCounts; + delete hTotalMismatchFraction; + delete hIdentifiedCounts; + delete hSignalFraction; + delete hBkg1Fraction; + delete hBkg2Fraction; + delete hBkg3Fraction; + delete hBkg4Fraction; + delete hMismatchCorrectionCounts; + delete hMismatchCorrectedSignalCounts; + if (hAcceptedTracks) { + delete hAcceptedTracks_py; + } + delete hNormalizedRawYield; + delete hNormalizedMismatchCorrectedRawYield; + + /* close file */ + fileout->Close(); +} + +//___________________________________________________________________________________ + +Float_t +TOFpid_histomin(TH1 *h) +{ + + for (Int_t ibin = 0; ibin < h->GetNbinsX(); ibin++) + if (h->GetBinContent(ibin + 1) > 0.) + return h->GetXaxis()->GetBinCenter(ibin + 1); + return kMaxInt; +} + +//___________________________________________________________________________________ + +Float_t +TOFpid_histomax(TH1 *h) +{ + + for (Int_t ibin = h->GetNbinsX(); ibin > 0; ibin--) + if (h->GetBinContent(ibin) > 0.) + return h->GetXaxis()->GetBinCenter(ibin); + return -kMaxInt; +} + +//___________________________________________________________________________________ + +TOFpid_checkneg(TH1 *h) +{ + + for (Int_t ibin = 0; ibin < h->GetNbinsX(); ibin++) + if (h->GetBinContent(ibin + 1) <= 0.) { + h->SetBinContent(ibin + 1, 1.e-300); + // h->SetBinError(ibin + 1, 0.1); + } +} + +//___________________________________________________________________________________ + +Double_t +TOFpid_fit(TH1 *hSignal, TH1 *hSigExp, TH1 *hBkgExp1, TH1 *hBkgExp2, TH1 *hBkgExp3, TH1 *hBkgExp4, TH1 *hMismatch, Double_t rangeMin, Double_t rangeMax, Bool_t fitBkg1, Bool_t fitBkg2, Bool_t fitBkg3, Bool_t fitBkg4, Bool_t constrainSignal, Bool_t constrainBkg1, Bool_t constrainBkg2, Bool_t forceGaussianSignal, Double_t *param = NULL, Double_t *param_err = NULL, TCanvas *canvas = NULL) +{ + + /** ROOFIT ***/ + gSystem->Load("libRooFit"); + using namespace RooFit; + /*** LOAD GAUSSIANTAIL CLASS ***/ + gSystem->Load("RooFermiCutoff_cxx.so"); + gSystem->Load("RooGaussianTail_cxx.so"); + + /*** DEFINE FIT RANGE ***/ + + printf("***** FIT RANGE DEFINITION *****\n"); + + /* check mismatch histogram to define min/max fit range */ + // rangeMin = TMath::Max(rangeMin, TOFpid_histomin(hMismatch)); + // rangeMax = TMath::Min(rangeMax, TOFpid_histomax(hMismatch)); + /* fix zeroes */ + TOFpid_checkneg(hMismatch); + + /* define range */ + RooRealVar x("x", "n_{#sigma}", 0., rangeMin, rangeMax, ""); + printf("FIT RANGE DEFINED: %f -> %f\n", rangeMin, rangeMax); + printf("********************************\n"); + + /*** DEFINE HISTOGRAM DATA ***/ + + /* define data to fit and background from input histogram */ + RooDataHist hdata("hdata", "hdata", x, hSignal); + RooDataHist hsig("hsig", "hsig", x, hSigExp); + RooDataHist hbkg1("hbkg1", "hbkg1", x, hBkgExp1); + RooDataHist hbkg2("hbkg2", "hbkg2", x, hBkgExp2); + RooDataHist hbkg3("hbkg3", "hbkg3", x, hBkgExp3); + RooDataHist hbkg4("hbkg4", "hbkg4", x, hBkgExp4); + RooDataHist hmismatch("hmismatch", "hmismatch", x, hMismatch); + + /*** DEFINE SIGNAL SHAPE ***/ + + printf("***** SIGNAL SHAPE DEFINITION *****\n"); + + /* variables */ + if (FIX_SIGNAL_MEAN) { + RooRealVar mean("mean", "mean", DEFAULT_SIGNAL_MEAN, ""); + printf("FIXED SIGNAL_MEAN = %f\n", mean.getVal()); + } + else { + RooRealVar mean("mean", "mean", DEFAULT_SIGNAL_MEAN, MIN_SIGNAL_MEAN, MAX_SIGNAL_MEAN, ""); + printf("FREE SIGNAL_MEAN = %f [%f, %f]\n", mean.getVal(), MIN_SIGNAL_MEAN, MAX_SIGNAL_MEAN); + } + if (FIX_SIGNAL_SIGMA) { + RooRealVar sigma("sigma", "sigma", DEFAULT_SIGNAL_SIGMA, ""); + printf("FIXED SIGNAL_SIGMA = %f\n", sigma.getVal()); + } + else { + RooRealVar sigma("sigma", "sigma", DEFAULT_SIGNAL_SIGMA, MIN_SIGNAL_SIGMA, MAX_SIGNAL_SIGMA, ""); + printf("FREE SIGNAL_SIGMA = %f\n", sigma.getVal()); + } + if (FIX_SIGNAL_TAIL) { + RooRealVar tail("tail", "tail", DEFAULT_SIGNAL_TAIL, ""); + printf("FIXED SIGNAL_TAIL = %f\n", tail.getVal()); + } + else { + RooRealVar tail("tail", "tail", DEFAULT_SIGNAL_TAIL, MIN_SIGNAL_TAIL, MAX_SIGNAL_TAIL, ""); + printf("FREE SIGNAL_TAIL = %f\n", tail.getVal()); + } + RooRealVar gaussianfrac("gaussianfrac", "gaussianfrac", 1., 0., 1., ""); + RooRealVar sigalpha("sigalpha", "sigalpha", 0., -10., 0.); + + /* shapes */ + if (GAUSSIAN_SIGNAL || forceGaussianSignal) { + printf("USING GAUSSIAN_SIGNAL SHAPE\n"); + RooGaussian signal("signal", "signal", x, mean, sigma); + } + else if (GAUSSIANTAIL_SIGNAL) { + printf("USING GAUSSIANTAIL_SIGNAL SHAPE\n"); + RooGaussianTail signal("signal", "signal", x, mean, sigma, tail); + } + else if (GAUSSIANTAIL2_SIGNAL) { + printf("USING GAUSSIANTAIL2_SIGNAL SHAPE\n"); + RooGaussianTail signal("signal", "signal", x, mean, sigma, sigma); + } + else if (GAUSSIANPLUSGAUSSIANTAIL_SIGNAL) { + printf("USING GAUSSIANPLUSGAUSSIANTAIL_SIGNAL SHAPE\n"); + RooGaussian gaussian("gaussian", "gaussian", x, mean, sigma); + RooGaussianTail gaussiantail("gaussiantail", "gaussiantail", x, mean, sigma, tail); + RooAddPdf signal("signal", "signal", RooArgList(gaussian, gaussiantail), gaussianfrac, kTRUE); + + } + else if (GAUSSIANPLUSEXPONENTIAL_SIGNAL) { + printf("USING GAUSSIANPLUSEXPONENTIAL_SIGNAL SHAPE\n"); + RooGaussian gaussian("gaussian", "gaussian", x, mean, sigma); + RooExponential sigexpo("sigexpo", "sigexpo", x, sigalpha); + RooRealVar sigcutoff("sigcutoff", "sigcutoff", 0.); + RooRealVar sigpower("sigpower", "sigpower", 0.1); + RooFermiCutoff sigfermi("sigfermi", "sigfermi", x, sigcutoff, sigpower); + RooProdPdf exposignal("exposignal", "exposignal", sigfermi, sigexpo, -100.); + RooRealVar gaussianfrac("gaussianfrac", "gaussianfrac", 0.9, 0.7, 1., ""); + RooAddPdf signal("signal", "signal", RooArgList(gaussian, exposignal), gaussianfrac, kTRUE); + } + else if (EXPECTED_SIGNAL_TEMPLATE) { + printf("SHAPE OF SIGNAL FROM TEMPLATE HISTOGRAM\n"); + RooHistPdf signal("signal", "signal", x, hsig); + } + else if (EXPECTED_SIGNAL_FIT) { + /* fitting bkg1 */ + TF1 *fGaus = (TF1 *)gROOT->GetFunction("gaus"); + hSigExp->Fit(fGaus, "0q"); + Double_t sig_mean = fGaus->GetParameter(1); + Double_t sig_sigma = fGaus->GetParameter(2); + mean.setConstant(kFALSE); + mean.setVal(sig_mean); + mean.setRange(sig_mean - 10., sig_mean + 10.); + mean.setConstant(kFALSE); + sigma.setConstant(kFALSE); + sigma.setVal(sig_sigma); + sigma.setRange(sig_sigma * 0.5, sig_sigma * 1.5); + tail.setConstant(kFALSE); + tail.setVal(1.); + tail.setRange(0.5, 5.); + RooGaussianTail signal("signal", "signal", x, mean, sigma, tail); + signal.fitTo(hsig, Range(sig_mean - 5. * sig_sigma, sig_mean + 10. * sig_sigma), SumW2Error(kFALSE), Verbose(kFALSE), PrintEvalErrors(10)); +#if DISPLAY + TCanvas *cSig_fit = new TCanvas("cSig_fit"); + RooPlot *sig_frame = x.frame(); + hsig.plotOn(sig_frame); + signal.plotOn(sig_frame, LineColor(kRed)); + sig_frame->Draw(); + cSig_fit->Update(); +#endif + printf("SIGNAL PARAMETERS AFTER FIT OF EXPECTED SIGNAL\n"); + printf("mean = %f +- %f\n", mean.getVal(), mean.getError()); + printf("sigma = %f +- %f\n", sigma.getVal(), sigma.getError()); + printf("tail = %f +- %f\n", tail.getVal(), tail.getError()); + /* scale parameters if requested */ + if (SCALE_SIGNAL_SIGMA != 1.) { + printf("SCALE FITTED SIGNAL SIGMA BY %f\n", SCALE_SIGNAL_SIGMA); + sigma.setVal(sigma.getVal() * SCALE_SIGNAL_SIGMA); + } + if (SCALE_SIGNAL_TAIL != 1.) { + printf("SCALE FITTED SIGNAL TAIL BY %f\n", SCALE_SIGNAL_TAIL); + tail.setVal(tail.getVal() * SCALE_SIGNAL_TAIL); + } + /* fix/release parameters if requested */ + if (FIX_SIGNAL_MEAN) { + printf("SETTING FITTED SIGNAL MEAN AS CONSTANTS\n"); + mean.setConstant(kTRUE); + } + else { + printf("SETTING FITTED SIGNAL MEAN AS FREE\n"); + // mean.setRange(mean.getVal() - 0.25 * TMath::Abs(mean.getVal()), mean.getVal() + 0.25 * TMath::Abs(mean.getVal())); + // mean.setRange(mean.getVal() - 0.5 * TMath::Abs(mean.getVal()), mean.getVal() + 0.5 * TMath::Abs(mean.getVal())); + mean.setRange(mean.getVal() - 0.2, mean.getVal() + 0.2); + } + if (FIX_SIGNAL_SIGMA) { + printf("SETTING FITTED SIGNAL SIGMA AS CONSTANTS\n"); + sigma.setConstant(kTRUE); + } + else { + printf("SETTING FITTED SIGNAL SIGMA AS FREE\n"); + sigma.setRange(sigma.getVal() * 0.8, sigma.getVal() * 1.2); + // sigma.setRange(sigma.getVal() - 0.5, sigma.getVal() + 0.5); + } + if (FIX_SIGNAL_TAIL) { + printf("SETTING FITTED SIGNAL TAIL AS CONSTANTS\n"); + tail.setConstant(kTRUE); + } + else { + printf("SETTING FITTED SIGNAL TAIL AS FREE\n"); + // tail.setRange(0.5, 5.0); + tail.setRange(tail.getVal() * 0.8, tail.getVal() * 1.2); + // tail.setRange(tail.getVal() - 0.5, tail.getVal() + 0.5); + } + } + else { + printf("SHAPE OF SIGNAL NOT DEFINE: using GAUSSIAN_SIGNAL\n"); + RooGaussian signal("signal", "signal", x, mean, sigma); + } + + +#if 0 + if (constrainSignal) { +#if 0 + /* fix expected signal and constrain parameters if requested */ + signal.fitTo(hsig); +#if 0 + TCanvas *cConstrainSignal = new TCanvas("cConstrainSignal"); + RooPlot *xfr = x.frame(); + hsig.plotOn(xfr); + signal.plotOn(xfr, LineColor(kRed)); + xfr->Draw(); + cConstrainSignal->Update(); +#endif + printf("SIGNAL PARAMETERS AFTER FIT OF EXPECTED SIGNAL\n"); + printf("mean = %f +- %f\n", mean.getVal(), mean.getError()); + printf("sigma = %f +- %f\n", sigma.getVal(), sigma.getError()); + printf("tail = %f +- %f\n", tail.getVal(), tail.getError()); + if (constrainSignal) { + mean.setConstant(kTRUE); + sigma.setConstant(kTRUE); + tail.setConstant(kTRUE); + printf("SIGNAL PARAMETERS CONSTRAINED AFTER FIT OF EXPECTED SIGNAL\n"); + } +#endif + } +#endif + + if (constrainSignal) { + mean.setConstant(kTRUE); + sigma.setConstant(kTRUE); + tail.setConstant(kTRUE); + // mean.setRange(-0.1, 0.1); + // sigma.setRange(0.95, 1.05); + // tail.setRange(0.95, 1.25); + } + + printf("***********************************\n"); + + /*** DEFINE IDENTIFIED BACKGROUND SHAPES ***/ + + printf("***** IDENTIFIED BACKGROUND SHAPE DEFINITION *****\n"); + + /* shapes */ +if (EXPECTED_BACKGROUND_TEMPLATE) { + printf("USING EXPECTED BACKGROUND TEMPLATE SHAPES FROM HISTOGRAMS\n"); + RooHistPdf bkg1("bkg1", "bkg1", x, hbkg1, 0); + RooHistPdf bkg2("bkg2", "bkg2", x, hbkg2, 0); + RooHistPdf bkg3("bkg3", "bkg3", x, hbkg3, 0); + RooHistPdf bkg4("bkg4", "bkg4", x, hbkg4, 0); + } + else if (EXPECTED_BACKGROUND_FIT) { + printf("USING EXPECTED BACKGROUND FITTED SHAPES FROM HISTOGRAMS\n"); + /* fitting bkg1 */ + TF1 *fGaus = (TF1 *)gROOT->GetFunction("gaus"); + hBkgExp1->Fit(fGaus, "0q"); + Double_t bkgexp1_mean = fGaus->GetParameter(1); + Double_t bkgexp1_sigma = fGaus->GetParameter(2); + RooRealVar mean_bkg1("mean_bkg1", "mean_bkg1", bkgexp1_mean, bkgexp1_mean - 10., bkgexp1_mean + 10., ""); + RooRealVar sigma_bkg1("sigma_bkg1", "sigma_bkg1", bkgexp1_sigma, bkgexp1_sigma * 0.5, bkgexp1_sigma * 1.5, ""); + RooRealVar tail_bkg1("tail_bkg1", "tail_bkg1", 1.0, 0.5, 5., ""); + RooGaussianTail bkg1("bkg1", "bkg1", x, mean_bkg1, sigma_bkg1, tail_bkg1); + bkg1.fitTo(hbkg1, Range(bkgexp1_mean - 5. * bkgexp1_sigma, bkgexp1_mean + 10. * bkgexp1_sigma), SumW2Error(kFALSE), Verbose(kFALSE), PrintEvalErrors(10)); +#if DISPLAY + TCanvas *cBkg1_fit = new TCanvas("cBkg1_fit"); + RooPlot *bkg1_frame = x.frame(); + hbkg1.plotOn(bkg1_frame); + bkg1.plotOn(bkg1_frame, LineColor(kCyan+1)); + bkg1_frame->Draw(); + cBkg1_fit->Update(); +#endif + printf("BACKGROUND-1 PARAMETERS AFTER FIT OF EXPECTED BACKGROUND-1\n"); + printf("mean_bkg1 = %f +- %f\n", mean_bkg1.getVal(), mean_bkg1.getError()); + printf("sigma_bkg1 = %f +- %f\n", sigma_bkg1.getVal(), sigma_bkg1.getError()); + printf("tail_bkg1 = %f +- %f\n", tail_bkg1.getVal(), tail_bkg1.getError()); + /* scale parameters if requested */ + if (SCALE_BACKGROUND_SIGMA != 1.) { + printf("SCALE FITTED BACKGROUND-1 SIGMA BY %f\n", SCALE_BACKGROUND_SIGMA); + sigma_bkg1.setVal(sigma_bkg1.getVal() * SCALE_BACKGROUND_SIGMA); + } + if (SCALE_BACKGROUND_TAIL != 1.) { + printf("SCALE FITTED BACKGROUND-1 TAIL BY %f\n", SCALE_BACKGROUND_TAIL); + tail_bkg1.setVal(tail_bkg1.getVal() * SCALE_BACKGROUND_TAIL); + } + /* fix/release parameters if requested */ + if (FIX_BACKGROUND_MEAN) { + printf("SETTING BACKGROUND-1 FITTED MEAN AS CONSTANTS\n"); + mean_bkg1.setConstant(kTRUE); + } + else { + printf("SETTING BACKGROUND-1 FITTED MEAN AS FREE\n"); + mean_bkg1.setRange(mean_bkg1.getVal() - 0.25 * TMath::Abs(mean_bkg1.getVal()), mean_bkg1.getVal() + 0.25 * TMath::Abs(mean_bkg1.getVal())); + } + if (FIX_BACKGROUND_SIGMA) { + printf("SETTING BACKGROUND-1 FITTED SIGMA AS CONSTANTS\n"); + sigma_bkg1.setConstant(kTRUE); + } + else { + printf("SETTING BACKGROUND-1 FITTED SIGMA AS FREE\n"); + sigma_bkg1.setRange(sigma_bkg1.getVal() * 0.75, sigma_bkg1.getVal() * 1.25); + } + if (FIX_BACKGROUND_TAIL) { + printf("SETTING BACKGROUND-1 FITTED TAIL AS CONSTANTS\n"); + tail_bkg1.setConstant(kTRUE); + } + else { + printf("SETTING BACKGROUND-1 FITTED TAIL AS FREE\n"); + tail_bkg1.setRange(tail_bkg1.getVal() * 0.75, tail_bkg1.getVal() * 1.25); + } + /* fitting bkg2 */ + TF1 *fGaus = (TF1 *)gROOT->GetFunction("gaus"); + hBkgExp2->Fit(fGaus, "0q"); + Double_t bkgexp2_mean = fGaus->GetParameter(1); + Double_t bkgexp2_sigma = fGaus->GetParameter(2); + RooRealVar mean_bkg2("mean_bkg2", "mean_bkg2", bkgexp2_mean, bkgexp2_mean - 10., bkgexp2_mean + 10., ""); + RooRealVar sigma_bkg2("sigma_bkg2", "sigma_bkg2", bkgexp2_sigma, bkgexp2_sigma * 0.5, bkgexp2_sigma * 1.5, ""); + RooRealVar tail_bkg2("tail_bkg2", "tail_bkg2", 1.0, 0.5, 5., ""); + RooGaussianTail bkg2("bkg2", "bkg2", x, mean_bkg2, sigma_bkg2, tail_bkg2); + bkg2.fitTo(hbkg2, Range(bkgexp2_mean - 5. * bkgexp2_sigma, bkgexp2_mean + 10. * bkgexp2_sigma), SumW2Error(kFALSE), Verbose(kFALSE), PrintEvalErrors(10)); +#if DISPLAY + TCanvas *cBkg2_fit = new TCanvas("cBkg2_fit"); + RooPlot *bkg2_frame = x.frame(); + hbkg2.plotOn(bkg2_frame); + bkg2.plotOn(bkg2_frame, LineColor(kGreen+1)); + bkg2_frame->Draw(); + cBkg2_fit->Update(); +#endif + printf("BACKGROUND-2 PARAMETERS AFTER FIT OF EXPECTED BACKGROUND-2\n"); + printf("mean_bkg2 = %f +- %f\n", mean_bkg2.getVal(), mean_bkg2.getError()); + printf("sigma_bkg2 = %f +- %f\n", sigma_bkg2.getVal(), sigma_bkg2.getError()); + printf("tail_bkg2 = %f +- %f\n", tail_bkg2.getVal(), tail_bkg2.getError()); + /* scale parameters if requested */ + if (SCALE_BACKGROUND_SIGMA != 1.) { + printf("SCALE FITTED BACKGROUND-2 SIGMA BY %f\n", SCALE_BACKGROUND_SIGMA); + sigma_bkg2.setVal(sigma_bkg2.getVal() * SCALE_BACKGROUND_SIGMA); + } + if (SCALE_BACKGROUND_TAIL != 1.) { + printf("SCALE FITTED BACKGROUND-2 TAIL BY %f\n", SCALE_BACKGROUND_TAIL); + tail_bkg2.setVal(tail_bkg2.getVal() * SCALE_BACKGROUND_TAIL); + } + /* fix/release parameters if requested */ + if (FIX_BACKGROUND_MEAN) { + printf("SETTING BACKGROUND-2 FITTED MEAN AS CONSTANTS\n"); + mean_bkg2.setConstant(kTRUE); + } + else { + printf("SETTING BACKGROUND-2 FITTED MEAN AS FREE\n"); + mean_bkg2.setRange(mean_bkg2.getVal() - 0.25 * TMath::Abs(mean_bkg2.getVal()), mean_bkg2.getVal() + 0.25 * TMath::Abs(mean_bkg2.getVal())); + } + if (FIX_BACKGROUND_SIGMA) { + printf("SETTING BACKGROUND-2 FITTED SIGMA AS CONSTANTS\n"); + sigma_bkg2.setConstant(kTRUE); + } + else { + printf("SETTING BACKGROUND-2 FITTED SIGMA AS FREE\n"); + sigma_bkg2.setRange(sigma_bkg2.getVal() * 0.75, sigma_bkg2.getVal() * 1.25); + } + if (FIX_BACKGROUND_TAIL) { + printf("SETTING BACKGROUND-2 FITTED TAIL AS CONSTANTS\n"); + tail_bkg2.setConstant(kTRUE); + } + else { + printf("SETTING BACKGROUND-2 FITTED TAIL AS FREE\n"); + tail_bkg2.setRange(tail_bkg2.getVal() * 0.75, tail_bkg2.getVal() * 1.25); + } + /* fitting bkg3 */ + TF1 *fGaus = (TF1 *)gROOT->GetFunction("gaus"); + hBkgExp3->Fit(fGaus, "0q"); + Double_t bkgexp3_mean = fGaus->GetParameter(1); + Double_t bkgexp3_sigma = fGaus->GetParameter(2); + RooRealVar mean_bkg3("mean_bkg3", "mean_bkg3", bkgexp3_mean, bkgexp3_mean - 10., bkgexp3_mean + 10., ""); + RooRealVar sigma_bkg3("sigma_bkg3", "sigma_bkg3", bkgexp3_sigma, bkgexp3_sigma * 0.5, bkgexp3_sigma * 1.5, ""); + RooRealVar tail_bkg3("tail_bkg3", "tail_bkg3", 1., 0.5, 5., ""); + RooGaussianTail bkg3("bkg3", "bkg3", x, mean_bkg3, sigma_bkg3, tail_bkg3); + bkg3.fitTo(hbkg3, Range(bkgexp3_mean - 5. * bkgexp3_sigma, bkgexp3_mean + 10. * bkgexp3_sigma), SumW2Error(kFALSE), Verbose(kFALSE), PrintEvalErrors(10)); +#if DISPLAY + TCanvas *cBkg3_fit = new TCanvas("cBkg3_fit"); + RooPlot *bkg3_frame = x.frame(); + hbkg3.plotOn(bkg3_frame); + bkg3.plotOn(bkg3_frame, LineColor(kYellow+1)); + bkg3_frame->Draw(); + cBkg3_fit->Update(); +#endif + printf("BACKGROUND-3 PARAMETERS AFTER FIT OF EXPECTED BACKGROUND-3\n"); + printf("mean_bkg3 = %f +- %f\n", mean_bkg3.getVal(), mean_bkg3.getError()); + printf("sigma_bkg3 = %f +- %f\n", sigma_bkg3.getVal(), sigma_bkg3.getError()); + printf("tail_bkg3 = %f +- %f\n", tail_bkg3.getVal(), tail_bkg3.getError()); + /* scale parameters if requested */ + if (SCALE_BACKGROUND_SIGMA != 1.) { + printf("SCALE FITTED BACKGROUND-3 SIGMA BY %f\n", SCALE_BACKGROUND_SIGMA); + sigma_bkg3.setVal(sigma_bkg3.getVal() * SCALE_BACKGROUND_SIGMA); + } + if (SCALE_BACKGROUND_TAIL != 1.) { + printf("SCALE FITTED BACKGROUND-3 TAIL BY %f\n", SCALE_BACKGROUND_TAIL); + tail_bkg3.setVal(tail_bkg3.getVal() * SCALE_BACKGROUND_TAIL); + } + /* fix/release parameters if requested */ + if (FIX_BACKGROUND_MEAN) { + printf("SETTING BACKGROUND-3 FITTED MEAN AS CONSTANTS\n"); + mean_bkg3.setConstant(kTRUE); + } + else { + printf("SETTING BACKGROUND-3 FITTED MEAN AS FREE\n"); + mean_bkg3.setRange(mean_bkg3.getVal() - 0.25 * TMath::Abs(mean_bkg3.getVal()), mean_bkg3.getVal() + 0.25 * TMath::Abs(mean_bkg3.getVal())); + } + if (FIX_BACKGROUND_SIGMA) { + printf("SETTING BACKGROUND-3 FITTED SIGMA AS CONSTANTS\n"); + sigma_bkg3.setConstant(kTRUE); + } + else { + printf("SETTING BACKGROUND-3 FITTED SIGMA AS FREE\n"); + sigma_bkg3.setRange(sigma_bkg3.getVal() * 0.75, sigma_bkg3.getVal() * 1.25); + } + if (FIX_BACKGROUND_TAIL) { + printf("SETTING BACKGROUND-3 FITTED TAIL AS CONSTANTS\n"); + tail_bkg3.setConstant(kTRUE); + } + else { + printf("SETTING BACKGROUND-3 FITTED TAIL AS FREE\n"); + tail_bkg3.setRange(tail_bkg3.getVal() * 0.75, tail_bkg3.getVal() * 1.25); + } + /* fitting bkg4 */ + TF1 *fGaus = (TF1 *)gROOT->GetFunction("gaus"); + hBkgExp4->Fit(fGaus, "0q"); + Double_t bkgexp4_mean = fGaus->GetParameter(1); + Double_t bkgexp4_sigma = fGaus->GetParameter(2); + RooRealVar mean_bkg4("mean_bkg4", "mean_bkg4", bkgexp4_mean, bkgexp4_mean - 10., bkgexp4_mean + 10., ""); + RooRealVar sigma_bkg4("sigma_bkg4", "sigma_bkg4", bkgexp4_sigma, bkgexp4_sigma * 0.5, bkgexp4_sigma * 1.5, ""); + RooRealVar tail_bkg4("tail_bkg4", "tail_bkg4", 1., 0.5, 5., ""); + RooGaussianTail bkg4("bkg4", "bkg4", x, mean_bkg4, sigma_bkg4, tail_bkg4); + bkg4.fitTo(hbkg4, Range(bkgexp4_mean - 5. * bkgexp4_sigma, bkgexp4_mean + 10. * bkgexp4_sigma), SumW2Error(kFALSE), Verbose(kFALSE), PrintEvalErrors(10)); +#if DISPLAY + TCanvas *cBkg4_fit = new TCanvas("cBkg4_fit"); + RooPlot *bkg4_frame = x.frame(); + hbkg4.plotOn(bkg4_frame); + bkg4.plotOn(bkg4_frame, LineColor(kYellow+2)); + bkg4_frame->Draw(); + cBkg4_fit->Update(); +#endif + printf("BACKGROUND-4 PARAMETERS AFTER FIT OF EXPECTED BACKGROUND-4\n"); + printf("mean_bkg4 = %f +- %f\n", mean_bkg4.getVal(), mean_bkg4.getError()); + printf("sigma_bkg4 = %f +- %f\n", sigma_bkg4.getVal(), sigma_bkg4.getError()); + printf("tail_bkg4 = %f +- %f\n", tail_bkg4.getVal(), tail_bkg4.getError()); + /* scale parameters if requested */ + if (SCALE_BACKGROUND_SIGMA != 1.) { + printf("SCALE FITTED BACKGROUND-4 SIGMA BY %f\n", SCALE_BACKGROUND_SIGMA); + sigma_bkg4.setVal(sigma_bkg4.getVal() * SCALE_BACKGROUND_SIGMA); + } + if (SCALE_BACKGROUND_TAIL != 1.) { + printf("SCALE FITTED BACKGROUND-4 TAIL BY %f\n", SCALE_BACKGROUND_TAIL); + tail_bkg4.setVal(tail_bkg4.getVal() * SCALE_BACKGROUND_TAIL); + } + /* fix/release parameters if requested */ + if (FIX_BACKGROUND_MEAN) { + printf("SETTING BACKGROUND-4 FITTED MEAN AS CONSTANTS\n"); + mean_bkg4.setConstant(kTRUE); + } + else { + printf("SETTING BACKGROUND-4 FITTED MEAN AS FREE\n"); + mean_bkg4.setRange(mean_bkg4.getVal() - 0.25 * TMath::Abs(mean_bkg4.getVal()), mean_bkg4.getVal() + 0.25 * TMath::Abs(mean_bkg4.getVal())); + } + if (FIX_BACKGROUND_SIGMA) { + printf("SETTING BACKGROUND-4 FITTED SIGMA AS CONSTANTS\n"); + sigma_bkg4.setConstant(kTRUE); + } + else { + printf("SETTING BACKGROUND-4 FITTED SIGMA AS FREE\n"); + sigma_bkg4.setRange(sigma_bkg4.getVal() * 0.75, sigma_bkg4.getVal() * 1.25); + } + if (FIX_BACKGROUND_TAIL) { + printf("SETTING BACKGROUND-4 FITTED TAIL AS CONSTANTS\n"); + tail_bkg4.setConstant(kTRUE); + } + else { + printf("SETTING BACKGROUND-4 FITTED TAIL AS FREE\n"); + tail_bkg4.setRange(tail_bkg4.getVal() * 0.75, tail_bkg4.getVal() * 1.25); + } + } + else if (GAUSSIAN_BACKGROUND) { + printf("USING GAUSSIAN BACKGROUND SHAPES (not reccomended)\n"); + RooRealVar mean1("mean1", "mean1", hBkgExp1->GetMean(), hBkgExp1->GetMean() * 0.95, hBkgExp1->GetMean() * 1.05, ""); + RooRealVar sigma1("sigma1", "sigma1", hBkgExp1->GetRMS(), hBkgExp1->GetRMS() * 0.5, hBkgExp1->GetRMS() * 1.5, ""); + RooGaussian bkg1("bkg1", "bkg1", x, mean1, sigma1); + + RooRealVar mean2("mean2", "mean2", hBkgExp2->GetMean(), hBkgExp2->GetMean() * 0.95, hBkgExp2->GetMean() * 1.05, ""); + RooRealVar sigma2("sigma2", "sigma2", hBkgExp2->GetRMS(), hBkgExp2->GetRMS() * 0.5, hBkgExp2->GetRMS() * 1.5, ""); + RooGaussian bkg2("bkg2", "bkg2", x, mean2, sigma2); + + RooRealVar mean3("mean3", "mean3", hBkgExp3->GetMean(), hBkgExp3->GetMean() * 0.95, hBkgExp3->GetMean() * 1.05, ""); + RooRealVar sigma3("sigma3", "sigma3", hBkgExp3->GetRMS(), hBkgExp3->GetRMS() * 0.5, hBkgExp3->GetRMS() * 1.5, ""); + RooGaussian bkg3("bkg3", "bkg3", x, mean3, sigma3); + } + else { + printf("SHAPE OF BACKGROUND NOT DEFINE: using EXPECTED_BACKGROUND\n"); + RooHistPdf bkg1("bkg1", "bkg1", x, hbkg1, 0); + RooHistPdf bkg2("bkg2", "bkg2", x, hbkg2, 0); + RooHistPdf bkg3("bkg3", "bkg3", x, hbkg3, 0); + RooHistPdf bkg4("bkg4", "bkg4", x, hbkg4, 0); + } + printf("**************************************************\n"); + + /*** DEFINE MISMATCH BACKGROUND SHAPE ***/ + + printf("***** MISMATCH BACKGROUND SHAPE DEFINITION *****\n"); + + /* variables and generic shapes */ + Double_t expectedCutoff = hBkgExp3->GetMean(); + Double_t expectedCutoffRMS = hBkgExp3->GetRMS(); + // RooRealVar cutoff("cutoff", "cutoff", -30., -50., 0., ""); + RooRealVar cutoff("cutoff", "cutoff", expectedCutoff, expectedCutoff - 3. * expectedCutoffRMS, expectedCutoff, ""); + // RooRealVar cutoff("cutoff", "cutoff", expectedCutoff, ""); + // RooRealVar power("power", "power", 1., 0.5, 5.0, ""); + RooRealVar power("power", "power", 1., ""); + RooFermiCutoff fermi("fermi", "fermi", x, cutoff, power); + RooRealVar alpha("alpha", "alpha", 0., -10., 0., ""); + RooExponential expo("expo", "expo", x, alpha); + RooUniform uniform("uniform", "uniform", x); + + /* mismatch shape */ + if (EXPECTED_MISMATCH) { + printf("USING EXPECTED MISMATCH SHAPE FROM HISTOGRAMS\n"); + RooHistPdf mismatch("mismatch", "mismatch", x, hmismatch, 0); + } + else if (UNIFORM_MISMATCH) { + printf("USING UNIFORM BACKGROUND SHAPE WITH CUTOFF\n"); + RooProdPdf mismatch("mismatch", "mismatch", fermi, uniform, -100.); + } + else if (EXPONENTIAL_MISMATCH) { + printf("USING EXPONENTIAL BACKGROUND SHAPE WITH CUTOFF\n"); + RooProdPdf mismatch("mismatch", "mismatch", fermi, expo, -100.); + } + else if (DOUBLEEXPONENTIAL_MISMATCH) { + printf("USING DOUBLE-EXPONENTIAL BACKGROUND SHAPE WITH CUTOFF\n"); + RooRealVar alpha1("alpha1", "alpha1", 0., -10., 0., ""); + RooRealVar alpha2("alpha2", "alpha2", 0., -10., 0., ""); + RooRealVar frac("frac", "frac", 0.5, 0., 1., ""); + RooGenericPdf doubleexpo("doubleexpo", "TMath::Exp(alpha1 * x) + frac * TMath::Exp(alpha2 * x)", RooArgSet(x, alpha1, alpha2, frac)); + RooProdPdf mismatch("mismatch", "mismatch", fermi, doubleexpo, -100.); + } + else if (UNIFORMPLUSEXPONENTIAL_MISMATCH) { + printf("USING UNIFORM-PLUS-EXPONENTIAL BACKGROUND SHAPE WITH CUTOFF\n"); + RooRealVar funiform("funiform", "funiform", 100., 0., 100000., ""); + RooRealVar fexpo("fexpo", "fexpo", 100., 0., 100000., ""); + RooAddPdf uniformplusexpo("uniformplusexpo", "uniformplusexpo", RooArgList(uniform, expo), RooArgList(funiform, fexpo), kFALSE); + RooProdPdf mismatch("mismatch", "mismatch", fermi, uniformplusexpo, -100.); + } + else { + printf("SHAPE OF MISMATCH NOT DEFINE: using EXPECTED_MISMATCH\n"); + RooHistPdf mismatch("mismatch", "mismatch", x, hmismatch, 0); + } + printf("************************************************\n"); + + /*** DEFINE THE MODEL ***/ + + printf("***** MODEL DEFINITION *****\n"); + + /* variables */ + Double_t integral = hdata.sumEntries(); + RooRealVar nsignal("nsignal", "nsignal", 0.3 * integral, 0., integral); + RooRealVar nbkg1("nbkg1", "nbkg1", 0.3 * integral, 0., integral); + RooRealVar nbkg2("nbkg2", "nbkg2", 0.3 * integral, 0., integral); + RooRealVar nbkg3("nbkg3", "nbkg3", 0.3 * integral, 0., integral); + RooRealVar nbkg4("nbkg4", "nbkg4", 0.3 * integral, 0., integral); + RooRealVar nmismatch("nmismatch", "nmismatch", 0.1 * integral, 0., integral); + +if (!fitBkg1) { + nbkg1.setVal(0.); + nbkg1.setConstant(kTRUE); + } +if (!fitBkg2) { + nbkg2.setVal(0.); + nbkg2.setConstant(kTRUE); + } +if (!fitBkg3) { + nbkg3.setVal(0.); + nbkg3.setConstant(kTRUE); + } +if (!fitBkg4) { + nbkg4.setVal(0.); + nbkg4.setConstant(kTRUE); + } + + RooAddPdf model("model", "model p.d.f.", RooArgList(signal, bkg1, bkg2, bkg3, bkg4, mismatch), RooArgList(nsignal, nbkg1, nbkg2, nbkg3, nbkg4, nmismatch)); + +#if 0 + /* the model */ + if (USE_ELECTRON_BACKGROUND && fitElectrons && fitPions) { + printf("USING ELECTRON BACKGROUND\n"); + if (NO_MISMATCH) { + printf("NOT USING MISMATCH BACKGROUND\n"); + nmismatch.setVal(0.); + RooAddPdf model("model", "model p.d.f.", RooArgList(signal, bkg1, bkg2, bkg3/*, bkg4*/), RooArgList(nsignal, nbkg1, nbkg2, nbkg3/*, nbkg4*/)); + } + else { + printf("USING MISMATCH BACKGROUND\n"); + RooAddPdf model("model", "model p.d.f.", RooArgList(signal, bkg1, bkg2, bkg3/*, bkg4*/, mismatch), RooArgList(nsignal, nbkg1, nbkg2, nbkg3/*, nbkg4*/, nmismatch)); + } + } + else if (!USE_ELECTRON_BACKGROUND || !fitElectrons) { + printf("NOT USING ELECTRON BACKGROUND\n"); + nbkg3.setVal(0.); + nbkg4.setVal(0.); + if (NO_MISMATCH) { + printf("NOT USING MISMATCH BACKGROUND\n"); + nmismatch.setVal(0.); + RooAddPdf model("model", "model p.d.f.", RooArgList(signal, bkg1, bkg2), RooArgList(nsignal, nbkg1, nbkg2)); + } + else { + printf("USING MISMATCH BACKGROUND\n"); + RooAddPdf model("model", "model p.d.f.", RooArgList(signal, bkg1, bkg2, mismatch), RooArgList(nsignal, nbkg1, nbkg2, nmismatch)); + } + } + printf("****************************\n"); +#endif + + + + + /*** FIT ***/ + + printf("***** FIT *****\n"); + + printf("SIGNAL PARAMETERS BEFORE GLOBAL FIT\n"); + printf("mean = %f +- %f\n", mean.getVal(), mean.getError()); + printf("sigma = %f +- %f\n", sigma.getVal(), sigma.getError()); + printf("tail = %f +- %f\n", tail.getVal(), tail.getError()); + + /* fit and draw */ + if (canvas) canvas->cd(); + // model.chi2FitTo(hdata, Extended(kTRUE), Verbose(kFALSE), SumW2Error(kFALSE), Range(-40., 140.), Binned(kTRUE)); +// model.fitTo(hdata, Extended(kTRUE), SumW2Error(kFALSE), Verbose(kFALSE), PrintEvalErrors(10), Range(-10., 10.)); +model.fitTo(hdata, Range(rangeMin, rangeMax), Extended(kTRUE), SumW2Error(kFALSE), Verbose(kFALSE), PrintEvalErrors(10)); + + printf("***************\n"); + + /*** DRAW ***/ +#if DISPLAY + RooPlot *xframe = x.frame(); +hdata.plotOn(xframe, XErrorSize(0), DrawOption("PZ")); + printf("plotting model...\n"); +model.plotOn(xframe, LineWidth(2)/*, Precision(1.e-4)*/); + printf("plotting signal...\n"); +model.plotOn(xframe, Components(signal), LineWidth(2), LineColor(kRed)/*, Precision(1.e-4)*/); + printf("plotting bkg1...\n"); + model.plotOn(xframe, Components(bkg1), LineWidth(2), LineStyle(kDashed), LineColor(kCyan+1)); + printf("plotting bkg2...\n"); + model.plotOn(xframe, Components(bkg2), LineWidth(2), LineStyle(kDashed), LineColor(kGreen+1)); + if (USE_ELECTRON_BACKGROUND) { + model.plotOn(xframe, Components(bkg3), LineWidth(2), LineStyle(kDashed), LineColor(kYellow+1)); + model.plotOn(xframe, Components(bkg4), LineWidth(2), LineStyle(kDashed), LineColor(kYellow+2)); + } + if (!NO_MISMATCH) + model.plotOn(xframe, Components(mismatch), LineWidth(2), LineStyle(kDashed), LineColor(kGray+1)); + hSignal->SetFillColor(kYellow); + hSignal->SetLineWidth(0); + hSignal->SetFillStyle(0); + hSignal->SetMinimum(0.1); + hSignal->GetXaxis()->SetRangeUser(rangeMin, rangeMax); +// hSignal->Draw(); +xframe->SetMinimum(0.1); + xframe->Draw(); +#endif + if (canvas) canvas->Update(); + + /*** COMPUTE CHI2 ***/ + Double_t datax, datapoint, datapoint_err, modelpoint; + Double_t chi2 = 0.; + Int_t ndf = 0; + for (Int_t ibin = 0; ibin < hSignal->GetNbinsX(); ibin++) { + datax = hSignal->GetBinCenter(ibin + 1); + if (datax < rangeMin || datax > rangeMax) continue; + datapoint = hSignal->GetBinContent(ibin + 1); + datapoint_err = hSignal->GetBinError(ibin + 1); + if (datapoint_err == 0.) continue; + x.setVal(datax); + modelpoint = model.getVal(); + chi2 += (datapoint - modelpoint) * (datapoint - modelpoint) / (datapoint_err * datapoint_err); + ndf++; + } + + +/*** PRINT FIT OUTPUT ***/ +printf("***** CHI-SQUARE *****\n"); + printf("chi-square = %f\n", chi2); + printf("NDF = %d\n", ndf); + printf("chi2/NDF = %f\n", ndf > 0 ? chi2 / ndf : 0.); + printf("***** SIGNAL-SHAPE INFO *****\n"); + printf("mean = %f +- %f\n", mean.getVal(), mean.getError()); + printf("sigma = %f +- %f\n", sigma.getVal(), sigma.getError()); + printf("tail = %f +- %f\n", tail.getVal(), tail.getError()); + printf("pure gaus = %f +- %f\n", gaussianfrac.getVal(), gaussianfrac.getError()); +printf("*****************************\n"); +printf("***** COUNTS *****\n"); +printf("total = %f\n", hSignal->Integral(-1, -1)); + printf("integral = %f\n", hdata.sumEntries()); + printf("nsignal = %f +- %f\n", nsignal.getVal(), nsignal.getError()); + printf("nbkg1 = %f +- %f\n", nbkg1.getVal(), nbkg1.getError()); + printf("nbkg2 = %f +- %f\n", nbkg2.getVal(), nbkg2.getError()); + printf("nbkg3 = %f +- %f\n", nbkg3.getVal(), nbkg3.getError()); + printf("nbkg4 = %f +- %f\n", nbkg4.getVal(), nbkg4.getError()); + printf("nmismatch = %f +- %f\n", nmismatch.getVal(), nmismatch.getError()); + printf("******************\n"); + + /*** OUTPUT FIT PARAMS ***/ + + param[kMean] = mean.getVal(); + param_err[kMean] = mean.getError(); + param[kSigma] = sigma.getVal(); + param_err[kSigma] = sigma.getError(); + param[kTail] = tail.getVal(); + param_err[kTail] = tail.getError(); + param[kTotalCounts] = hSignal->GetEntries(); + param_err[kTotalCounts] = sqrt(hSignal->GetEntries()); + param[kIntegralCounts] = hdata.sumEntries(); + param_err[kIntegralCounts] = sqrt(hdata.sumEntries()); + param[kSignalCounts] = nsignal.getVal(); + param_err[kSignalCounts] = nsignal.getError(); + param[kBkg1Counts] = nbkg1.getVal(); + param_err[kBkg1Counts] = nbkg1.getError(); + param[kBkg2Counts] = nbkg2.getVal(); + param_err[kBkg2Counts] = nbkg2.getError(); + param[kBkg3Counts] = nbkg3.getVal(); + param_err[kBkg3Counts] = nbkg3.getError(); + param[kBkg4Counts] = nbkg4.getVal(); + param_err[kBkg4Counts] = nbkg4.getError(); + param[kMismatchCounts] = nmismatch.getVal(); + param_err[kMismatchCounts] = nmismatch.getError(); + + return; +} + +//___________________________________________________________________________________ + +TOFpid_efficiency(Int_t ipart, Int_t icharge, Int_t icent, Int_t useTPCcut = -1, Double_t minsignalFrac = 0., Int_t nTrials = 1000) +{ + + /* prepare centrality name */ + Char_t centName[1024]; + if (icent < 0 || icent >= NcentralityBins) + sprintf(centName, "cent0090"); + else + sprintf(centName, "cent%02d%02d", centralityBin[icent], centralityBin[icent + 1]); + + /* fraction names */ + const Char_t *fractionName[AliPID::kSPECIES][AliPID::kSPECIES] = { + "hSignalFraction", "hBkg4Fraction", "hBkg3Fraction", "hBkg1Fraction", "hBkg2Fraction", + "hBkg4Fraction", "hSignalFraction", "hBkg3Fraction", "hBkg1Fraction", "hBkg2Fraction", + "hBkg3Fraction", "hBkg4Fraction", "hSignalFraction", "hBkg1Fraction", "hBkg2Fraction", + "hBkg3Fraction", "hBkg4Fraction", "hBkg1Fraction", "hSignalFraction", "hBkg2Fraction", + "hBkg3Fraction", "hBkg4Fraction", "hBkg1Fraction", "hBkg2Fraction", "hSignalFraction" + }; + + enum ETPCcut_t { + kCurrentDir, + k11Cut, + k12Cut, + k21Cut, + k22Cut, + k23Cut, + k32Cut, + k33Cut, + kNTPCcuts + }; + const Char_t *tpccutdir[8] = { + ".", + "TOFpid_cutOnTPC[-1.0,1.0]", + "TOFpid_cutOnTPC[1.0,2.0]", + "TOFpid_cutOnTPC[-2.0,-1.0]", + "TOFpid_cutOnTPC[-2.0,2.0]", + "TOFpid_cutOnTPC[2.0,3.0]", + "TOFpid_cutOnTPC[-3.0,-2.0]", + "TOFpid_cutOnTPC[-3.0,3.0]" + }; + + /* get data */ + Char_t filename[1024]; + TH1D *hAccepted[AliPID::kSPECIES][kNTPCcuts]; + TH1D *hIdentified[AliPID::kSPECIES][kNTPCcuts]; + TH1D *hEfficiencyIn[AliPID::kSPECIES][kNTPCcuts]; + TH1D *hFraction[AliPID::kSPECIES][AliPID::kSPECIES][kNTPCcuts]; + for (Int_t itpccut = 0; itpccut < kNTPCcuts; itpccut++) { + + /* check whether we use this cut */ + if (useTPCcut >= 0 && itpccut != useTPCcut) + continue; + + for (Int_t iipart = 0; iipart < AliPID::kSPECIES; iipart++) { + /* skip electrons and muons */ + if (iipart == AliPID::kMuon) + continue; + + /* open file */ + sprintf(filename, "%s/TOFspectrum_%s_%s_%s_%sID.root", tpccutdir[itpccut], centName, AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart)); + TFile *filein = TFile::Open(filename); + if (!filein || !filein->IsOpen()) { + printf("cannot open %s\n", filename); + return; + } + + /* get accepted tracks */ + hAccepted[iipart][itpccut] = (TH1D *)filein->Get("PostAnalysis/hAcceptedTracks"); + if (!hAccepted[iipart][itpccut]) { + printf("cannot find PostAnalysis/hAcceptedTracks in %s\n", filename); + return; + } + + /* get identified tracks */ + hIdentified[iipart][itpccut] = (TH1D *)filein->Get("PostAnalysis/hIdentifiedCounts"); + if (!hIdentified[iipart][itpccut]) { + printf("cannot find PostAnalysis/hIdentifiedCounts in %s\n", filename); + return; + } + + /* compute efficiency */ + hEfficiencyIn[iipart][itpccut] = new TH1D(*hIdentified[iipart][itpccut]); + hEfficiencyIn[iipart][itpccut]->Divide(hEfficiencyIn[iipart][itpccut], hAccepted[iipart][itpccut], 1., 1., "B"); + + /* get fractions */ + for (Int_t iiipart = 0; iiipart < AliPID::kSPECIES; iiipart++) { + /* skip muons */ + if (iiipart == AliPID::kMuon) + continue; + + hFraction[iipart][iiipart][itpccut] = (TH1D *)filein->Get(Form("PostAnalysis/%s", fractionName[iipart][iiipart])); + if (!hFraction[iipart][iiipart][itpccut]) { + printf("cannot find PostAnalysis/%s in %s\n", fractionName[iipart][iiipart], filename); + return; + } + } + } + } + + /* prepare output efficiency histos */ + TH1D *hEfficiencyOut[AliPID::kSPECIES]; + for (Int_t iipart = 0; iipart < AliPID::kSPECIES; iipart++) { + hEfficiencyOut[iipart] = new TH1D(Form("hPIDEff_%d_%s_%s_%sID", icent, AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(iipart)), "", NptBins, ptBin); + } + + + /*** MATRIX ***/ + + const Int_t nPart = 4; + Int_t partIndex[4] = {AliPID::kElectron, AliPID::kPion, AliPID::kKaon, AliPID::kProton}; + + TMatrixD Meffin(nPart, 1); + TMatrixD Meffout(nPart, 1); + TMatrixD Mfrac(nPart, nPart); + + Double_t eff[4], effe[4], frac[4][4], frace[4][4], geneff, genfrac; + Bool_t gotbestcut[4]; + + TH1F *hEffTemp[4]; + for (Int_t iipart = 0; iipart < nPart; iipart++) + hEffTemp[iipart] = new TH1F(Form("hEffTemp_%d", iipart), "", 20000, -10., 10.); + + /* loop over pt-bins */ + for (Int_t ibin = 0; ibin < NptBins; ibin++) { + + /* reset temp histos */ + for (Int_t iipart = 0; iipart < nPart; iipart++) + hEffTemp[iipart]->Reset(); + + /* get measured data */ + for (Int_t iipart = 0; iipart < nPart; iipart++) { + + /* select the best set of cuts */ + Double_t signalFrac, maxsignalFrac = minsignalFrac; + Int_t bestcut = -1; + gotbestcut[iipart] = kFALSE; + for (Int_t itpccut = 0; itpccut < kNTPCcuts; itpccut++) { + + /* check whether we use this cut */ + if (useTPCcut >= 0 && itpccut != useTPCcut) + continue; + + /* maximize the signal fraction */ + signalFrac = hFraction[partIndex[iipart]][partIndex[iipart]][itpccut]->GetBinContent(ibin + 1); + if (signalFrac > maxsignalFrac) { + maxsignalFrac = signalFrac; + bestcut = itpccut; + gotbestcut[iipart] = kTRUE; + } + } + if (bestcut < 0) + continue; + + eff[iipart] = hEfficiencyIn[partIndex[iipart]][bestcut]->GetBinContent(ibin + 1); + effe[iipart] = hEfficiencyIn[partIndex[iipart]][bestcut]->GetBinError(ibin + 1); + for (Int_t iiipart = 0; iiipart < nPart; iiipart++) { + frac[iipart][iiipart] = hFraction[partIndex[iipart]][partIndex[iiipart]][bestcut]->GetBinContent(ibin + 1); + frace[iipart][iiipart] = hFraction[partIndex[iipart]][partIndex[iiipart]][bestcut]->GetBinError(ibin + 1); + } + } + + /* check best cuts */ + Bool_t skip = kFALSE; + for (Int_t iipart = 0; iipart < nPart; iipart++) + if (!gotbestcut[iipart]) + skip = kTRUE; + if (skip) continue; + + /* loop over trials */ + for (Int_t itry = 0; itry < nTrials; itry++) { + + /* setup matrix */ + for (Int_t iipart = 0; iipart < nPart; iipart++) { + geneff = gRandom->Gaus(eff[iipart], effe[iipart]); + if (geneff < 0.) geneff = 0.; + if (geneff > 1.) geneff = 1.; + Meffin[iipart] = geneff != 0. ? 1. / geneff : 0.; + for (Int_t iiipart = 0; iiipart < nPart; iiipart++) { + genfrac = gRandom->Gaus(frac[iipart][iiipart], frace[iipart][iiipart]); + if (genfrac < 0.) genfrac = 0.; + if (genfrac > 1.) genfrac = 1.; + Mfrac[iipart][iiipart] = genfrac; + } + } + + /* invert matrix */ + TDecompLU lu(Mfrac); + TMatrixD Minv(nPart, nPart); + if (!lu.Decompose()) continue; + lu.Invert(Minv); + Meffout = Minv * Meffin; + + /* fill histos */ + for (Int_t iipart = 0; iipart < nPart; iipart++) { + if (Meffout.GetMatrixArray()[iipart] > 0.) + hEffTemp[iipart]->Fill(1. / Meffout.GetMatrixArray()[iipart]); + } + + } /* end of loop over trials */ + + + /* get average and RMS */ + for (Int_t iipart = 0; iipart < nPart; iipart++) { + hEfficiencyOut[partIndex[iipart]]->SetBinContent(ibin + 1, hEffTemp[iipart]->GetMean()); + hEfficiencyOut[partIndex[iipart]]->SetBinError(ibin + 1, hEffTemp[iipart]->GetRMS()); + } + + } /* end of loop over pt-bins */ + + + hEfficiencyOut[AliPID::kPion]->SetMarkerStyle(20); + hEfficiencyOut[AliPID::kKaon]->SetMarkerStyle(20); + hEfficiencyOut[AliPID::kProton]->SetMarkerStyle(20); + hEfficiencyOut[AliPID::kElectron]->SetMarkerStyle(20); + + hEfficiencyOut[AliPID::kPion]->SetMarkerColor(4); + hEfficiencyOut[AliPID::kKaon]->SetMarkerColor(8); + hEfficiencyOut[AliPID::kProton]->SetMarkerColor(2); + hEfficiencyOut[AliPID::kElectron]->SetMarkerColor(1); + + hEfficiencyOut[AliPID::kPion]->Draw(); + hEfficiencyOut[AliPID::kKaon]->Draw("same"); + hEfficiencyOut[AliPID::kProton]->Draw("same"); + hEfficiencyOut[AliPID::kElectron]->Draw("same"); + + + /* output */ + TFile *fileout = TFile::Open(Form("TOFpid_efficiency_cent%d_%s_%s.root", icent, AliPID::ParticleName(ipart), chargeName[icharge]), "RECREATE"); + hEfficiencyOut[AliPID::kPion]->Write(); + hEfficiencyOut[AliPID::kKaon]->Write(); + hEfficiencyOut[AliPID::kProton]->Write(); + hEfficiencyOut[AliPID::kElectron]->Write(); + fileout->Close(); + +} + +TOFpid_normalize(TH1D *h, Double_t nevents = 8.42446600000000000e+06) +{ + + Double_t counts, counts_err; + for (Int_t ibin = 0; ibin < h->GetNbinsX(); ibin++) { + counts = h->GetBinContent(ibin + 1); + counts_err = h->GetBinError(ibin + 1); + counts /= h->GetBinWidth(ibin + 1); + counts_err /= h->GetBinWidth(ibin + 1); + h->SetBinContent(ibin + 1, counts); + h->SetBinError(ibin + 1, counts_err); + } + + h->Scale(1. / nevents); + +} + +TOFpid_normalizeAndwrite(const Char_t *fileoutname, const Char_t *corrstring = "") +{ + + TFile *fpiplus = TFile::Open("TOFpid_spectrum_pion_plus.root"); + TFile *fpiminus = TFile::Open("TOFpid_spectrum_pion_minus.root"); + TFile *fkaplus = TFile::Open("TOFpid_spectrum_kaon_plus.root"); + TFile *fkaminus = TFile::Open("TOFpid_spectrum_kaon_minus.root"); + TFile *fprplus = TFile::Open("TOFpid_spectrum_proton_plus.root"); + TFile *fprminus = TFile::Open("TOFpid_spectrum_proton_minus.root"); + + hpiplus = (TH1F *)fpiplus->Get(Form("hSignal%sCounts", corrstring)); + hpiminus = (TH1F *)fpiminus->Get(Form("hSignal%sCounts", corrstring)); + hkaplus = (TH1F *)fkaplus->Get(Form("hSignal%sCounts", corrstring)); + hkaminus = (TH1F *)fkaminus->Get(Form("hSignal%sCounts", corrstring)); + hprplus = (TH1F *)fprplus->Get(Form("hSignal%sCounts", corrstring)); + hprminus = (TH1F *)fprminus->Get(Form("hSignal%sCounts", corrstring)); + + hpiplus->SetName("hpiplus"); + hpiminus->SetName("hpiminus"); + hkaplus->SetName("hkaplus"); + hkaminus->SetName("hkaminus"); + hprplus->SetName("hprplus"); + hprminus->SetName("hprminus"); + + TOFpid_normalize(hpiplus); + TOFpid_normalize(hpiminus); + TOFpid_normalize(hkaplus); + TOFpid_normalize(hkaminus); + TOFpid_normalize(hprplus); + TOFpid_normalize(hprminus); + + TFile *fileout = TFile::Open(fileoutname, "RECREATE"); + hpiplus->Write("hpiplus"); + hpiminus->Write("hpiminus"); + hkaplus->Write("hkaplus"); + hkaminus->Write("hkaminus"); + hprplus->Write("hprplus"); + hprminus->Write("hprminus"); + fileout->Close(); + +} + +/**************************************************************/ + +TOFpid_rawSpectra(const Char_t *destdir = ".") +{ + + Int_t marker[2] = {20, 21}; + Int_t color[AliPID::kSPECIES] = {1, 1, 4, 8, 2}; + Char_t *partLatex[AliPID::kSPECIES][2] = { + "", "", "", "", "#pi^{+}", "#pi^{-}", "K^{+}", "K^{-}", "p", "#bar{p}" + }; + + Float_t deltaRapidity = rapidityMaxCut - rapidityMinCut; + + TFile *fileout = TFile::Open("TOF_rawSpectra.root", "RECREATE"); + TH1D *hRaw; + Char_t title[1024]; + for (Int_t icent = -1; icent < NcentralityBins; icent++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) { + hRaw = TOFpid_rawSpectra(destdir, ipart, icharge, icent); + if (!hRaw) continue; + hRaw->Scale(1. / deltaRapidity); + hRaw->SetMarkerStyle(marker[icharge]); + hRaw->SetMarkerColor(color[ipart]); + hRaw->SetLineColor(1); + hRaw->SetLineWidth(1); + if (icent == -1) + sprintf(title, "%s (MB);p_{T} (GeV/c);#frac{d^{2}N}{dy dp_{T}} (c/GeV);", partLatex[ipart][icharge]); + else + sprintf(title, "%s (%d-%d%%);p_{T} (GeV/c);#frac{d^{2}N}{dy dp_{T}} (c/GeV);", partLatex[ipart][icharge], (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1]); + hRaw->SetTitle(title); + if (icent == -1) + hRaw->SetName(Form("hRaw_MB_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + else + hRaw->SetName(Form("hRaw_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + fileout->cd(); + hRaw->Write(); + } + + fileout->Close(); +} + +TH1D * +TOFpid_rawSpectra(const Char_t *dirname, Int_t ipart, Int_t icharge, Int_t icent) +{ + + /* open data */ + Char_t outfilename[1024]; + if (icent < 0 || icent >= NcentralityBins) { + sprintf(outfilename, "%s/TOFspectrum_cent0090_%s_%s_%sID.root", dirname, AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(ipart)); + } + else { + sprintf(outfilename, "%s/TOFspectrum_cent%02d%02d_%s_%s_%sID.root", dirname, centralityBin[icent], centralityBin[icent + 1], AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(ipart)); + } + TFile *filein = TFile::Open(outfilename); + if (!filein || !filein->IsOpen()) { + printf("cannot open %s\n", outfilename); + return NULL; + } + /* get data */ + TH1D *h = (TH1D *)filein->Get("RawSpectra/hNormalizedRawYield"); + if (!h) { + printf("cannot get RawSpectra/hNormalizedRawYield from %s\n", outfilename); + return NULL; + } + + return h; + +} + +TOFpid_rawSpectra_mismatchCorrected(const Char_t *destdir = ".") +{ + + Int_t marker[2] = {20, 21}; + Int_t color[AliPID::kSPECIES] = {1, 1, 4, 8, 2}; + Char_t *partLatex[AliPID::kSPECIES][2] = { + "", "", "", "", "#pi^{+}", "#pi^{-}", "K^{+}", "K^{-}", "p", "#bar{p}" + }; + + Float_t deltaRapidity = rapidityMaxCut - rapidityMinCut; + + TFile *fileout = TFile::Open("TOF_rawSpectra_mismatchCorrected.root", "RECREATE"); + TH1D *hRaw; + Char_t title[1024]; + for (Int_t icent = -1; icent < NcentralityBins; icent++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) { + hRaw = TOFpid_rawSpectra_mismatchCorrected(destdir, ipart, icharge, icent); + if (!hRaw) continue; + hRaw->Scale(1. / deltaRapidity); + hRaw->SetMarkerStyle(marker[icharge]); + hRaw->SetMarkerColor(color[ipart]); + hRaw->SetLineColor(1); + hRaw->SetLineWidth(1); + if (icent == -1) + sprintf(title, "%s (MB);p_{T} (GeV/c);#frac{d^{2}N}{dy dp_{T}} (c/GeV);", partLatex[ipart][icharge]); + else + sprintf(title, "%s (%d-%d%%);p_{T} (GeV/c);#frac{d^{2}N}{dy dp_{T}} (c/GeV);", partLatex[ipart][icharge], (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1]); + hRaw->SetTitle(title); + if (icent == -1) + hRaw->SetName(Form("hRaw_MB_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + else + hRaw->SetName(Form("hRaw_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + fileout->cd(); + hRaw->Write(); + } + + fileout->Close(); +} + +TH1D * +TOFpid_rawSpectra_mismatchCorrected(const Char_t *dirname, Int_t ipart, Int_t icharge, Int_t icent) +{ + + /* open data */ + Char_t outfilename[1024]; + if (icent < 0 || icent >= NcentralityBins) { + sprintf(outfilename, "%s/TOFspectrum_cent0090_%s_%s_%sID.root", dirname, AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(ipart)); + } + else { + sprintf(outfilename, "%s/TOFspectrum_cent%02d%02d_%s_%s_%sID.root", dirname, centralityBin[icent], centralityBin[icent + 1], AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(ipart)); + } + TFile *filein = TFile::Open(outfilename); + if (!filein || !filein->IsOpen()) { + printf("cannot open %s\n", outfilename); + return NULL; + } + /* get data */ + TH1D *h = (TH1D *)filein->Get("RawSpectra/hNormalizedMismatchCorrectedRawYield"); + if (!h) { + printf("cannot get RawSpectra/hNormalizedRawYield from %s\n", outfilename); + return NULL; + } + + return h; + +} + +/**************************************************************/ + +TOFpid_electronCorrection() +{ + + Int_t marker[2] = {20, 21}; + Int_t color[AliPID::kSPECIES] = {1, 1, 4, 8, 2}; + Char_t *partLatex[AliPID::kSPECIES][2] = { + "", "", "", "", "#pi^{+}", "#pi^{-}", "K^{+}", "K^{-}", "p", "#bar{p}" + }; + + + TFile *fileout = TFile::Open("TOF_electronCorrection.root", "RECREATE"); + TH1D *hCorr; + TProfile *pCorrAv = new TProfile("pCorrAv", "", NptBins, ptBin, "s"); + Char_t title[1024]; + for (Int_t icent = 0; icent < NcentralityBins; icent++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) + for (Int_t ipart = 2; ipart < 3; ipart++) { + hCorr = TOFpid_electronCorrection(ipart, icharge, icent); + hCorr->SetMarkerStyle(marker[icharge]); + hCorr->SetMarkerColor(color[ipart]); + hCorr->SetLineColor(1); + hCorr->SetLineWidth(1); + sprintf(title, "%s (%d-%d%%);p_{T} (GeV/c);electron-subtracted pion fraction;", partLatex[ipart][icharge], (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1]); + hCorr->SetTitle(title); + hCorr->SetName(Form("hElectronCorr_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + fileout->cd(); + hCorr->Write(); + /* fill for average correction */ + for (Int_t ipt = 0; ipt < NptBins; ipt++) { + pCorrAv->Fill(hCorr->GetBinCenter(ipt + 1), hCorr->GetBinContent(ipt + 1)); + } + } + hCorr = new TH1D("hElectronCorr_average", ";p_{T} (GeV/c);electron-subtracted pion fraction;", NptBins, ptBin); + for (Int_t ipt = 0; ipt < NptBins; ipt++) { + hCorr->SetBinContent(ipt + 1, pCorrAv->GetBinContent(ipt + 1)); + hCorr->SetBinError(ipt + 1, pCorrAv->GetBinError(ipt + 1)); + } + hCorr->Write(); + fileout->Close(); +} + +TH1D * +TOFpid_electronCorrection(Int_t ipart, Int_t icharge, Int_t icent) +{ + + Int_t marker[2] = {20, 21}; + Int_t color[AliPID::kSPECIES] = {1, 1, 4, 8, 2}; + Char_t *partLatex[AliPID::kSPECIES][2] = { + "", "", "", "", "#pi^{+}", "#pi^{-}", "K^{+}", "K^{-}", "p", "#bar{p}" + }; + + TH1D *hr = TOFpid_systematics_ratio("defaultFit_electronCut", "defaultFit", ipart, icharge, icent, "electronCorrection", "", marker[icharge], color[ipart], kTRUE); + TF1 fOne("fOne", "1.", fitPtMin[ipart], fitPtMax[ipart]); + hr->Add(&fOne, -1.); + hr->Scale(1. / 0.866); + hr->Add(&fOne, 1.); + + return hr; +} + +/**************************************************************/ + +SystematicCheck(const Char_t *defaultname = "defaultFit") +{ + + const Int_t ndata = 6; + const Char_t *name[ndata] = { + "signalFit_fixed_scaleSigma_09", + "signalFit_fixed_scaleSigma_11", + "signalFit_fixed_scaleTail_09", + "signalFit_fixed_scaleTail_11", + "signalFit_fixed_scaleSigma_09_scaleTail_11", + "signalFit_fixed_scaleSigma_11_scaleTail_09" + }; + for (Int_t idata = 0; idata < ndata; idata++) + SystematicCheck(name[idata], defaultname); + +} + +SystematicCheck(const Char_t *checkname, const Char_t *defaultname = "defaultFit") +{ + + gROOT->LoadMacro("HistoUtils.C"); + + Char_t filename1[1024]; + Char_t filename2[1024]; + + Int_t marker[2] = {20, 25}; + Int_t color[AliPID::kSPECIES] = {1, 1, 4, 8, 2}; + Char_t *partLatex[AliPID::kSPECIES][2] = { + "", "", "", "", "#pi^{+}", "#pi^{-}", "K^{+}", "K^{-}", "p", "#bar{p}" + }; + + + TFile *fileout = TFile::Open(Form("SystematicCheck_%s.root", checkname), "RECREATE"); + Char_t title[1024]; + TH1 *hd; + for (Int_t icent = 0; icent < NcentralityBins; icent++) + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + + if (icent < 0 || icent >= NcentralityBins) { + sprintf(filename1, "%s/TOFspectrum_cent0090_%s_%s_%sID.root", checkname, AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(ipart)); + sprintf(filename2, "%s/TOFspectrum_cent0090_%s_%s_%sID.root", defaultname, AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(ipart)); + } + else { + sprintf(filename1, "%s/TOFspectrum_cent%02d%02d_%s_%s_%sID.root", checkname, centralityBin[icent], centralityBin[icent + 1], AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(ipart)); + sprintf(filename2, "%s/TOFspectrum_cent%02d%02d_%s_%s_%sID.root", defaultname, centralityBin[icent], centralityBin[icent + 1], AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(ipart)); + } + + hd = HistoUtils_systematics(filename1, filename2, "RawSpectra/hNormalizedRawYield", NULL); + hd->SetName(Form("hRaw_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + sprintf(title, "%s (%d-%d%%);p_{T} (GeV/c);#frac{d^{2}N}{dy dp_{T}} (c/GeV);", partLatex[ipart][icharge], centralityBin[icent], centralityBin[icent + 1]); + hd->SetTitle(title); + hd->SetLineColor(1); + hd->SetLineWidth(1); + hd->SetMarkerStyle(marker[icharge]); + hd->SetMarkerColor(color[ipart]); + fileout->cd(); + hd->Write(); + delete hd; + } + fileout->Close(); + +} + +/**************************************************************/ + +TOFpid_systematics() +{ + + TFile *fileout = TFile::Open("TOFpid_systematics.root", "RECREATE"); + TH1D *hSys; + for (Int_t icent = 0; icent < NcentralityBins; icent++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) { + hSys = TOFpid_systematics(ipart, icharge, icent); + fileout->cd(); + hSys->Write(Form("hRawSys_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + delete hSys; + } + + fileout->Close(); +} + +TH1D * +TOFpid_systematics(Int_t ipart, Int_t icharge, Int_t icent) +{ + + TH1D *hSignalFit = TOFpid_systematics_signalFit(ipart, icharge, icent); + TH1D *hBkgFit = TOFpid_systematics_bkgFit(ipart, icharge, icent); + TH1D *hFitRange = TOFpid_systematics_fitRange(ipart, icharge, icent); + + TH1D *hSys = new TH1D("hSys", "", NptBins, ptBin); + Double_t sigsys, bkgsys, rangesys, totsys = 0.; + for (Int_t ipt = 0; ipt < NptBins; ipt++) { + sigsys = hSignalFit->GetBinError(ipt + 1); + bkgsys = hBkgFit->GetBinError(ipt + 1); + rangesys = hFitRange->GetBinError(ipt + 1); + totsys = TMath::Sqrt(sigsys * sigsys + bkgsys * bkgsys + rangesys * rangesys); + hSys->SetBinContent(ipt + 1, totsys); + } + + hSys->Draw(); + + delete hSignalFit; + delete hBkgFit; + delete hFitRange; + + return hSys; +} + +TH1D * +TOFpid_systematics_fitRange(Int_t ipart, Int_t icharge, Int_t icent) +{ + + TH1D *hArea = new TH1D("hArea", "", NptBins, ptBin); + hArea->SetMinimum(0.8); + hArea->SetMaximum(1.2); + hArea->Draw(); + + TH1D *hr = TOFpid_systematics_ratio("default_wideRange", "default", ipart, icharge, icent, "wide", "wide-range fit;p_{T} (GeV/c);ratio wrt. default;", 20, 4); + hr->Draw("same"); + + TH1D *hSys = new TH1D("hSys", "", NptBins, ptBin); + hSys->SetFillStyle(0); + hSys->SetMarkerSize(0); + for (Int_t ipt = 0; ipt < NptBins; ipt++) { + Double_t val, max = 0.; + if (hr->GetBinContent(ipt + 1) == 0.) continue; + val = TMath::Abs(hr->GetBinContent(ipt + 1) - 1.); + hSys->SetBinContent(ipt + 1, 1.); + hSys->SetBinError(ipt + 1, val); + } + hSys->Draw("same, E2"); + + delete hr; + + return hSys; +} + +TH1D * +TOFpid_systematics_signalFit(Int_t ipart, Int_t icharge, Int_t icent) +{ + + const Int_t ndata = 6; + const Char_t *name[ndata] = { + "signalFit_fixed_scaleSigma_09", + "signalFit_fixed_scaleSigma_11", + "signalFit_fixed_scaleTail_09", + "signalFit_fixed_scaleTail_11", + "signalFit_fixed_scaleSigma_09_scaleTail_11", + "signalFit_fixed_scaleSigma_11_scaleTail_09" + }; + const Char_t *title[ndata] = { + "-10% #sigma;p_{T} (GeV/c); ratio", + "+10% #sigma;p_{T} (GeV/c); ratio", + "-10% #tau;p_{T} (GeV/c); ratio", + "+10% #tau;p_{T} (GeV/c); ratio", + "-10% #sigma, +10% #tau;p_{T} (GeV/c); ratio", + "+10% #sigma, -10% #tau;p_{T} (GeV/c); ratio" + }; + Int_t marker[ndata] = {22, 28, 22, 28, 22, 28}; + Int_t color[ndata] = {2, 2, 8, 8, 4, 4}; + + TH1D *hArea = new TH1D("hArea", "", NptBins, ptBin); + hArea->SetMinimum(0.8); + hArea->SetMaximum(1.2); + hArea->Draw(); + + TH1D *hr[ndata]; + for (Int_t idata = 0; idata < ndata; idata++) { + hr[idata] = TOFpid_systematics_ratio(name[idata], "defaultFit", ipart, icharge, icent, name[idata], title[idata], marker[idata], color[idata]); + hr[idata]->Draw("same"); + } + + TH1D *hSys = new TH1D("hSys", "", NptBins, ptBin); + hSys->SetFillStyle(0); + hSys->SetMarkerSize(0); + for (Int_t ipt = 0; ipt < NptBins; ipt++) { + Double_t val, max = 0.; + for (Int_t idata = 0; idata < ndata; idata++) { + if (hr[idata]->GetBinContent(ipt + 1) == 0.) continue; + val = TMath::Abs(hr[idata]->GetBinContent(ipt + 1) - 1.); + if (val > 0.9) continue; + if (val > max) + max = val; + } + hSys->SetBinContent(ipt + 1, 1.); + hSys->SetBinError(ipt + 1, max); + } + hSys->Draw("same, E2"); + + // delete hArea; + // for (Int_t idata = 0; idata < ndata; idata++) + // delete hr[idata]; + + return hSys; +} + +TH1D * +TOFpid_systematics_bkgFit(Int_t ipart, Int_t icharge, Int_t icent) +{ + + const Int_t ndata = 6; + const Char_t *name[ndata] = { + "bkgFit_fixed_scaleSigma_09", + "bkgFit_fixed_scaleSigma_11", + "bkgFit_fixed_scaleTail_09", + "bkgFit_fixed_scaleTail_11", + "bkgFit_fixed_scaleSigma_09_scaleTail_11", + "bkgFit_fixed_scaleSigma_11_scaleTail_09" + }; + const Char_t *title[ndata] = { + "-10% #sigma;p_{T} (GeV/c); ratio", + "+10% #sigma;p_{T} (GeV/c); ratio", + "-10% #tau;p_{T} (GeV/c); ratio", + "+10% #tau;p_{T} (GeV/c); ratio", + "-10% #sigma, +10% #tau;p_{T} (GeV/c); ratio", + "+10% #sigma, -10% #tau;p_{T} (GeV/c); ratio" + }; + Int_t marker[ndata] = {22, 28, 22, 28, 22, 28}; + Int_t color[ndata] = {2, 2, 8, 8, 4, 4}; + + TH1D *hArea = new TH1D("hArea", "", NptBins, ptBin); + hArea->SetMinimum(0.5); + hArea->SetMaximum(1.5); + hArea->Draw(); + + TH1D *hr[ndata]; + for (Int_t idata = 0; idata < ndata; idata++) { + hr[idata] = TOFpid_systematics_ratio(name[idata], "defaultFit", ipart, icharge, icent, name[idata], title[idata], marker[idata], color[idata]); + hr[idata]->Draw("same"); + } + + TH1D *hSys = new TH1D("hSys", "", NptBins, ptBin); + hSys->SetFillStyle(0); + hSys->SetMarkerSize(0); + for (Int_t ipt = 0; ipt < NptBins; ipt++) { + Double_t val, max = 0.; + for (Int_t idata = 0; idata < ndata; idata++) { + if (hr[idata]->GetBinContent(ipt + 1) == 0.) continue; + val = TMath::Abs(hr[idata]->GetBinContent(ipt + 1) - 1.); + if (val > 0.9) continue; + if (val > max) + max = val; + } + hSys->SetBinContent(ipt + 1, 1.); + hSys->SetBinError(ipt + 1, max); + } + hSys->Draw("same, E2"); + + // delete hArea; + // for (Int_t idata = 0; idata < ndata; idata++) + // delete hr[idata]; + + return hSys; +} + +TH1D * +TOFpid_systematics_ratio(const Char_t *dirname1, const Char_t *dirname2, Int_t ipart, Int_t icharge, Int_t icent, const Char_t *name = "rawRatio", const Char_t *title = ";p_{T} (GeV/c);raw yield ratio;", Int_t marker = 20, Int_t color = 2, Bool_t correlated = kFALSE) +{ + + TH1D *hr = new TH1D("hr", "", NptBins, ptBin); + + /* open data */ + Char_t outfilename1[1024]; + Char_t outfilename2[1024]; + if (icent < 0 || icent >= NcentralityBins) { + sprintf(outfilename1, "%s/TOFspectrum_cent0090_%s_%s_%sID.root", dirname1, AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(ipart)); + sprintf(outfilename2, "%s/TOFspectrum_cent0090_%s_%s_%sID.root", dirname2, AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(ipart)); + } + else { + sprintf(outfilename1, "%s/TOFspectrum_cent%02d%02d_%s_%s_%sID.root", dirname1, centralityBin[icent], centralityBin[icent + 1], AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(ipart)); + sprintf(outfilename2, "%s/TOFspectrum_cent%02d%02d_%s_%s_%sID.root", dirname2, centralityBin[icent], centralityBin[icent + 1], AliPID::ParticleName(ipart), chargeName[icharge], AliPID::ParticleName(ipart)); + } + TFile *filein1 = TFile::Open(outfilename1); + if (!filein1 || !filein1->IsOpen()) { + printf("cannot open %s\n", outfilename1); + return; + } + TFile *filein2 = TFile::Open(outfilename2); + if (!filein2 || !filein2->IsOpen()) { + printf("cannot open %s\n", outfilename2); + return; + } + /* get data */ + TH1D *h1 = (TH1D *)filein1->Get("RawSpectra/hNormalizedRawYield"); + if (!h1) { + printf("cannot get RawSpectra/hNormalizedRawYield from %s\n", outfilename1); + return; + } + TH1D *h2 = (TH1D *)filein2->Get("RawSpectra/hNormalizedRawYield"); + if (!h2) { + printf("cannot get RawSpectra/hNormalizedRawYield from %s\n", outfilename2); + return; + } + /* ratio */ + if (correlated) hr->Divide(h1, h2, 1., 1., "B"); + else hr->Divide(h1, h2); + hr->SetNameTitle(name, title); + hr->SetMarkerStyle(marker); + hr->SetMarkerColor(color); + + filein1->Close(); + filein2->Close(); + + return hr; + +} + diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFpid.sh b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFpid.sh new file mode 100755 index 00000000000..984207f253e --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFpid.sh @@ -0,0 +1,39 @@ +#! /bin/bash + +if [ "$1" = "" ]; then + echo "filename not specified" + exit 1 +fi + +if [ "$2" = "" ]; then + nevents=kMaxInt +else + nevents=$2 +fi + +echo "*********************************************" +echo " make libs" +echo "*********************************************" + +aliroot -b -q MakeLibs.C &> makelibs.log + +echo "*********************************************" +echo " starting TOFpid on $1" +echo " run over $nevents events" +echo "*********************************************" + +for (( icharge = 0; icharge < 2; icharge++ )); do + for (( ipart = 2; ipart < 5; ipart++ )); do + echo aliroot -b -q "TOFpid.C(\"$1\", $ipart, $icharge, $ipart, kTRUE, kFALSE, kFALSE, -2., 2., $nevents)" + aliroot -b -q "TOFpid.C(\"$1\", $ipart, $icharge, $ipart, kTRUE, kFALSE, kFALSE, -2., 2., $nevents)" &> "TOFpid.$ipart.$icharge.$ipart.$1.log" & + +# echo aliroot -b -q "TOFpid.C(\"$1\", $ipart, $icharge, $ipart, kFALSE, kFALSE, kFALSE, -2., 2., $nevents)" +# aliroot -b -q "TOFpid.C(\"$1\", $ipart, $icharge, $ipart, kFALSE, kFALSE, kFALSE, -2., 2., $nevents)" &> "TOFpid.norapiditycut.$ipart.$icharge.$ipart.$1.log" & + + done +done + +echo "*********************************************" +echo " TOFpid processes now running in background" +echo "*********************************************" + diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFsignal.C b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFsignal.C new file mode 100644 index 00000000000..cf21908e9ee --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TOFsignal.C @@ -0,0 +1,60 @@ +#if 0 +TF1 * +TOFsignal(Float_t norm, Float_t mean, Float_t sigma, Float_t tail) +{ + + TF1 *f = new TF1("fTOFsignal", "(x <= ([3] + [1])) * [0] * TMath::Gaus(x, [1], [2]) + (x > ([3] + [1])) * [0] * TMath::Gaus([3] + [1], [1], [2]) * TMath::Exp(-([3]) * (x - [3] - [1]) / ([2] * [2]))"); + + f->SetParameter(0, norm); + f->SetParameter(1, mean); + f->SetParameter(2, sigma); + f->SetParameter(3, tail); + f->SetRange(mean - 10. * sigma, mean + 10. * sigma); + return f; +} +#endif + +Double_t +TOFsignal(Double_t *x, Double_t *par) +{ + Double_t norm = par[0]; + Double_t mean = par[1]; + Double_t sigma = par[2]; + Double_t tail = par[3]; + + if (x[0] <= (tail + mean)) + return norm * TMath::Gaus(x[0], mean, sigma); + else + return norm * TMath::Gaus(tail + mean, mean, sigma) * TMath::Exp(-tail * (x[0] - tail - mean) / (sigma * sigma)); +} + +Double_t +TOFsignal_double(Double_t *x, Double_t *par) +{ + return TOFsignal(x, par) + TOFsignal(x, &par[4]); +} + +Double_t +TOFsignal_triple(Double_t *x, Double_t *par) +{ + return TOFsignal(x, par) + TOFsignal(x, &par[4]) + TOFsignal(x, &par[8]); +} + +static TF1 *fIntegrand = NULL; +Double_t +TOFsignal_Integrand(const Double_t *x, const Double_t *par) +{ + Double_t f = TOFsignal(x, par); + Double_t g = /*TMath::Abs(par[5] - x[0]) < 1.e-1 ? 1. : 0.;*/TMath::Gaus(x[0], par[5], par[4], kTRUE); + return f * g; +} + +Double_t +TOFsignal_convolution(const Double_t *x, const Double_t *par) +{ + if (!fIntegrand) + fIntegrand = new TF1("fIntegrand", TOFsignal_Integrand, -10., 10., 6); + fIntegrand->SetParameters(par[0], par[1], par[2], par[3], par[4], x[0]); + Double_t integral = fIntegrand->Integral(-5. * par[4], 5. * par[4]); + return integral; +} diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TPCcalib.C b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TPCcalib.C new file mode 100644 index 00000000000..fb77cede689 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TPCcalib.C @@ -0,0 +1,646 @@ +#include "CommonDefs.C" + +/**************************************************************/ +/*** HISTOS AND BINNING ***************************************/ +/**************************************************************/ + +/**************************************************************/ +enum ECharge_t { + kPositive, + kNegative, + kNCharges +}; +const Char_t *chargeName[kNCharges] = { + "positive", + "negative", +}; +/**************************************************************/ +enum EHistoParam_t { + kCentrality, + kPtpc, + kTPCNcls, + kTPCdelta, + kTPCgain, + kTOFsignal, + kNHistoParams +}; +/**************************************************************/ +const Int_t NclsBins = 200; +Double_t clsBin[NclsBins + 1]; +Double_t clsMin = 0., clsMax = 200., clsStep = (clsMax - clsMin) / NclsBins; +/**************************************************************/ +const Int_t NtpcdeltaBins = 200; +Double_t tpcdeltaBin[NtpcdeltaBins + 1]; +Double_t tpcdeltaMin = -100., tpcdeltaMax = 100., tpcdeltaStep = (tpcdeltaMax - tpcdeltaMin) / NtpcdeltaBins; +/**************************************************************/ +const Int_t NtpcgainBins = 200; +Double_t tpcgainBin[NtpcgainBins + 1]; +Double_t tpcgainMin = 0., tpcgainMax = 2., tpcgainStep = (tpcgainMax - tpcgainMin) / NtpcgainBins; +/**************************************************************/ +const Int_t NsigmaBins = 20; +Double_t sigmaBin[NsigmaBins + 1]; +Double_t sigmaMin = -5., sigmaMax = 5., sigmaStep = (sigmaMax - sigmaMin) / NsigmaBins; +/**************************************************************/ +Int_t NparamsBins[kNHistoParams] = {NcentralityBins, NpBins, NclsBins, NtpcdeltaBins, NtpcgainBins, NsigmaBins}; +Double_t *paramBin[kNHistoParams] = {centralityBin, pBin, clsBin, tpcdeltaBin, tpcgainBin, sigmaBin}; +/**************************************************************/ + +/**************************************************************/ + + +TPCcalib(const Char_t *filename, Int_t evMax = kMaxInt, Int_t startEv = 0) +{ + + /* include path for ACLic */ + gSystem->AddIncludePath("-I$ALICE_ROOT/include"); + gSystem->AddIncludePath("-I$ALICE_ROOT/TOF"); + /* load libraries */ + gSystem->Load("libANALYSIS"); + gSystem->Load("libANALYSISalice"); + /* build analysis task class */ + gROOT->LoadMacro("AliAnalysisParticle.cxx+g"); + gROOT->LoadMacro("AliAnalysisEvent.cxx+g"); + gROOT->LoadMacro("AliAnalysisTrack.cxx+g"); + + /* open file, get tree and connect */ + TFile *filein = TFile::Open(filename); + TTree *treein = (TTree *)filein->Get("aodTree"); + printf("got \"aodTree\": %d entries\n", treein->GetEntries()); + AliAnalysisEvent *analysisEvent = new AliAnalysisEvent(); + TClonesArray *analysisTrackArray = new TClonesArray("AliAnalysisTrack"); + AliAnalysisTrack *analysisTrack = NULL; + treein->SetBranchAddress("AnalysisEvent", &analysisEvent); + treein->SetBranchAddress("AnalysisTrack", &analysisTrackArray); + + /* open enabled flag map */ + TH1F *hEnabledFlag = NULL; + if (enabledChannelsFileName) { + TFile *enabledfile = TFile::Open(enabledChannelsFileName); + hEnabledFlag = (TH1F *)enabledfile->Get("hEnabledFlag"); + } + + /**************************************************************/ + /*** HISTOS ***************************************************/ + /**************************************************************/ + + /* run-time binning */ + for (Int_t ibin = 0; ibin < NclsBins + 1; ibin++) + clsBin[ibin] = clsMin + ibin * clsStep; + for (Int_t ibin = 0; ibin < NtpcdeltaBins + 1; ibin++) + tpcdeltaBin[ibin] = tpcdeltaMin + ibin * tpcdeltaStep; + for (Int_t ibin = 0; ibin < NtpcgainBins + 1; ibin++) + tpcgainBin[ibin] = tpcgainMin + ibin * tpcgainStep; + for (Int_t ibin = 0; ibin < NsigmaBins + 1; ibin++) + sigmaBin[ibin] = sigmaMin + ibin * sigmaStep; + + /* THnSparse */ + THnSparse *hTPCcalib[AliPID::kSPECIES][kNCharges]; + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) { + for (Int_t icharge = 0; icharge< kNCharges; icharge++) { + hTPCcalib[ipart][icharge] = new THnSparseF(Form("hTPCcalib_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge]), "", kNHistoParams, NparamsBins); + for (Int_t iparam = 0; iparam < kNHistoParams; iparam++) { + hTPCcalib[ipart][icharge]->SetBinEdges(iparam, paramBin[iparam]); + } + } + } + + /**************************************************************/ + /**************************************************************/ + /**************************************************************/ + + /* TOF PID response */ + AliTOFPIDResponse tofResponse; + tofResponse.SetTimeResolution(tofReso); + /* TPC PID response */ + AliTPCPIDResponse *tpcResponse = AliAnalysisTrack::GetTPCResponse(); + + /* Start stopwatch */ + TStopwatch timer; + timer.Start(); + + if (1) { + TFile *calibfile = TFile::Open("TZEROcalibration.root"); + hCentrality_TZEROA_mean = (TH1 *)calibfile->Get("hCentrality_TZEROA_mean"); + hCentrality_TZEROA_sigma = (TH1 *)calibfile->Get("hCentrality_TZEROA_sigma"); + hCentrality_TZEROC_mean = (TH1 *)calibfile->Get("hCentrality_TZEROC_calib"); + hCentrality_TZEROC_sigma = (TH1 *)calibfile->Get("hCentrality_TZEROC_sigma"); + hCentrality_TOF_mean = (TH1 *)calibfile->Get("hCentrality_TOF_mean"); + hCentrality_TOF_TZEROA_mean = (TH1 *)calibfile->Get("hCentrality_TOF_TZEROA_mean"); + hCentrality_TOF_TZEROC_mean = (TH1 *)calibfile->Get("hCentrality_TOF_TZEROC_mean"); + hCentrality_TOF_TZEROTOF_mean = (TH1 *)calibfile->Get("hCentrality_TOF_TZEROTOF_mean"); + + TFile *resofile = TFile::Open("TZEROresolution.root"); + hCentrality_TZEROA_reso = (TH1 *)resofile->Get("hTZEROA_reso"); + hCentrality_TZEROC_reso = (TH1 *)resofile->Get("hTZEROC_reso"); + hCentrality_TZEROAND_reso = (TH1 *)resofile->Get("hTZEROAND_reso"); + } + Double_t TZEROA_mean; + Double_t TZEROA_sigma; + Double_t TZEROC_mean; + Double_t TZEROC_sigma; + Double_t TOF_mean; + Double_t TOF_TZEROA_mean; + Double_t TOF_TZEROC_mean; + Double_t TOF_TZEROTOF_mean; + Double_t TZEROA; + Double_t TZEROA_reso; + Bool_t hasTZEROA; + Double_t TZEROC; + Double_t TZEROC_reso; + Bool_t hasTZEROC; + Double_t TZEROAND; + Double_t TZEROAND_reso; + Bool_t hasTZEROAND; + Double_t TZEROTOF; + Double_t TZEROTOF_reso; + Bool_t hasTZEROTOF; + Double_t TZEROMEAN; + Double_t TZEROMEAN_weight; + Double_t TZEROBEST; + Double_t TZEROBEST_reso; + + + /* loop over events */ + Bool_t hastofpid; + Int_t charge, index; + UShort_t dedxN; + Double_t ptpc, dedx, bethe, deltadedx, dedx_sigma, tpcsignal; + Double_t p, time, time_sigma, timezero, timezero_sigma, tof, tof_sigma, texp, texp_sigma, deltat, deltat_sigma, tofsignal; + Double_t tpctofsignal; + Double_t param[kNHistoParams]; + for (Int_t iev = startEv; iev < treein->GetEntries() && iev < evMax; iev++) { + /* get event */ + treein->GetEvent(iev); + if (iev % 10000 == 0) printf("iev = %d\n", iev); + /* check event */ + if (!analysisEvent->AcceptEvent(acceptEventType)) continue; + + /*** ACCEPTED EVENT ***/ + + /* get centrality */ + param[kCentrality] = analysisEvent->GetCentralityPercentile(centralityEstimator); + cent = analysisEvent->GetCentralityPercentile(centralityEstimator); + + + /* TZERO corrections */ + Int_t icent; + for (icent = 0; icent < NcentralityBins; icent++) + if (cent < centralityBin[icent + 1]) + break; + TZEROA_mean = hCentrality_TZEROA_mean ? hCentrality_TZEROA_mean->GetBinContent(icent + 1) : 0.; + TZEROA_sigma = hCentrality_TZEROA_sigma ? hCentrality_TZEROA_sigma->GetBinContent(icent + 1) : 1000.; + TZEROC_mean = hCentrality_TZEROC_mean ? hCentrality_TZEROC_mean->GetBinContent(icent + 1) : 0.; + TZEROC_sigma = hCentrality_TZEROC_sigma ? hCentrality_TZEROC_sigma->GetBinContent(icent + 1) : 1000.; + + TOF_mean = hCentrality_TOF_mean ? hCentrality_TOF_mean->GetBinContent(icent + 1) : 0.; + TOF_TZEROA_mean = hCentrality_TOF_TZEROA_mean ? hCentrality_TOF_TZEROA_mean->GetBinContent(icent + 1) : 0.; + TOF_TZEROC_mean = hCentrality_TOF_TZEROC_mean ? hCentrality_TOF_TZEROC_mean->GetBinContent(icent + 1) : 0.; + TOF_TZEROTOF_mean = hCentrality_TOF_TZEROTOF_mean ? hCentrality_TOF_TZEROTOF_mean->GetBinContent(icent + 1) : 0.; + + TZEROA_reso = hCentrality_TZEROA_reso ? hCentrality_TZEROA_reso->GetBinContent(icent + 1) : 70.; + TZEROC_reso = hCentrality_TZEROC_reso ? hCentrality_TZEROC_reso->GetBinContent(icent + 1) : 70.; + TZEROAND_reso = hCentrality_TZEROAND_reso ? hCentrality_TZEROAND_reso->GetBinContent(icent + 1) : 50.; + + /* loop over tracks */ + for (Int_t itrk = 0; itrk < analysisTrackArray->GetEntries(); itrk++) { + /* get track */ + analysisTrack = (AliAnalysisTrack *)analysisTrackArray->At(itrk); + if (!analysisTrack) continue; + /* check accepted track */ + if (!analysisTrack->AcceptTrack()) continue; + /* get charge */ + charge = analysisTrack->GetSign() > 0. ? kPositive : kNegative; + + /*** ACCEPTED TRACK ***/ + + /* check TOF pid */ + if (!analysisTrack->HasTOFPID(hEnabledFlag) || !analysisTrack->HasTPCPID()) continue; + + + /* get TOF info */ + index = analysisTrack->GetTOFIndex(); + time = analysisTrack->GetTOFTime() - TOF_mean; + time_sigma = tofReso; + /* TZEROTOF */ + TZEROTOF = analysisEvent->GetTimeZeroTOF(analysisTrack->GetP()); + TZEROTOF_reso = analysisEvent->GetTimeZeroTOFSigma(analysisTrack->GetP()); + hasTZEROTOF = TZEROTOF_reso < 150.; + if (hasTZEROTOF) { + TZEROTOF += TOF_TZEROTOF_mean - TOF_mean; + TZEROTOF_reso *= TZEROTOF_resoScaleFactor; + } + /* TZEROA */ + TZEROA = analysisEvent->GetTimeZeroT0(1) - TZEROA_shift; + // TZEROA_reso = TZEROA_resolution[icent]; + hasTZEROA = TMath::Abs(TZEROA - TZEROA_mean) < 3. * TZEROA_sigma; + TZEROA += TOF_TZEROA_mean - TOF_mean; + /* TZEROC */ + TZEROC = analysisEvent->GetTimeZeroT0(2) - TZEROC_shift; + // TZEROC_reso = TZEROC_resolution[icent]; + hasTZEROC = TMath::Abs(TZEROC - TZEROC_mean) < 3. * TZEROC_sigma; + TZEROC += TOF_TZEROC_mean - TOF_mean; + /* TZEROAND */ + TZEROAND = (TZEROA + TZEROC) * 0.5; + // TZEROAND_reso = TZEROAND_resolution[icent]; + hasTZEROAND = hasTZEROA && hasTZEROC; + /* TZEROMEAN */ + TZEROMEAN = TZEROTOF / TZEROTOF_reso / TZEROTOF_reso; + TZEROMEAN_weight = 1. / TZEROTOF_reso / TZEROTOF_reso; + if (hasTZEROAND) { + // printf("TZEROAND\n"); + TZEROMEAN += TZEROAND / TZEROAND_reso / TZEROAND_reso; + TZEROMEAN_weight = 1. / TZEROAND_reso / TZEROAND_reso; + } + else if (hasTZEROA) { + // printf("TZEROA\n"); + TZEROMEAN += TZEROA / TZEROA_reso / TZEROA_reso; + TZEROMEAN_weight = 1. / TZEROA_reso / TZEROA_reso; + } + else if (hasTZEROC) { + // printf("TZEROC\n"); + TZEROMEAN += TZEROC / TZEROC_reso / TZEROC_reso; + TZEROMEAN_weight = 1. / TZEROC_reso / TZEROC_reso; + } + timezero = TZEROMEAN / TZEROMEAN_weight; + timezero_sigma = TMath::Sqrt(1. / TZEROMEAN_weight); + /* TZEROBEST */ + TZEROBEST = TZEROTOF; + TZEROBEST_reso = TZEROTOF_reso; + if (hasTZEROAND && TZEROAND_reso < TZEROBEST_reso) { + TZEROBEST = TZEROAND; + TZEROBEST_reso = TZEROAND_reso; + } + else if (hasTZEROA && TZEROA_reso < TZEROBEST_reso) { + TZEROBEST = TZEROA; + TZEROBEST_reso = TZEROA_reso; + } + if (hasTZEROC && TZEROC_reso < TZEROBEST_reso) { + TZEROBEST = TZEROC; + TZEROBEST_reso = TZEROC_reso; + } + timezero = TZEROBEST; + timezero_sigma = TZEROBEST_reso; + + /* DEBUG */ + // timezero = 0.;//TZEROTOF; + // timezero_sigma = 203.854691;//TZEROTOF_reso; + + // if (timezero == 0.) + // printf("%f %f\n", timezero, timezero_sigma); + + timezero_sigma *= scaletimezerosigma; + + if (resetTZERO) { + timezero = 0.; + timezero_sigma = timezero_spread; + } + + + tof = time - timezero; + tof_sigma = TMath::Sqrt(time_sigma * time_sigma + timezero_sigma * timezero_sigma); + + /* TOF expected time */ + texp = analysisTrack->GetTOFExpTime(iipart); + texp_sigma = analysisTrack->GetTOFExpTimeSigma(iipart) * scaletexpreso[iipart]; + + /* TOF signal */ + deltat = tof - texp; + deltat_sigma = TMath::Sqrt(tof_sigma * tof_sigma + texp_sigma * texp_sigma); + tofsignal = deltat / deltat_sigma; + + + + /*** ACCEPTED TRACK WITH TPC+TOF PID ***/ + + /* get track info */ + p = analysisTrack->GetP(); + + /* get TPC info */ + dedx = analysisTrack->GetTPCdEdx(); + dedxN = analysisTrack->GetTPCdEdxN(); + ptpc = analysisTrack->GetTPCmomentum(); + param[kPtpc] = ptpc; + param[kTPCNcls] = dedxN; + + /* get TOF info */ + time = analysisTrack->GetTOFTime() - TOF_mean; + time_sigma = tofReso; + timezero = analysisEvent->GetTimeZeroTOF(p); + timezero_sigma = analysisEvent->GetTimeZeroTOFSigma(p); + tof = time - timezero; + tof_sigma = TMath::Sqrt(time_sigma * time_sigma + timezero_sigma * timezero_sigma); + + /* loop over particle IDs */ + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) { + + /* check rapidity */ + if (TMath::Abs(analysisTrack->GetY(AliPID::ParticleMass(ipart))) > 0.5) continue; + + /*** ACCEPTED TRACK WITHIN CORRECT RAPIDITY ***/ + + /* TOF expected time */ + texp = analysisTrack->GetTOFExpTime(ipart); + texp_sigma = analysisTrack->GetTOFExpTimeSigma(ipart); + + /* TOF signal */ + deltat = tof - texp; + deltat_sigma = TMath::Sqrt(tof_sigma * tof_sigma + texp_sigma * texp_sigma); + tofsignal = deltat / deltat_sigma; + param[kTOFsignal] = tofsignal; + + /* check TOF PID with 3-sigma cut */ + if (TMath::Abs(tofsignal) > 3.) continue; + + /*** ACCEPTED TRACK WITH COMPATIBLE TOF PID ***/ + + /* TPC signal */ + bethe = tpcResponse->GetExpectedSignal(ptpc, ipart); + deltadedx = dedx - bethe; + param[kTPCdelta] = deltadedx; + param[kTPCgain] = dedx / bethe; + + /* fill histo */ + hTPCcalib[ipart][charge]->Fill(param); + + } /* end of loop over particle IDs */ + } /* end of loop over tracks */ + } /* end of loop over events */ + + /* start stopwatch */ + timer.Stop(); + timer.Print(); + + /* output */ + TFile *fileout = TFile::Open(Form("TPCcalib.%s", filename), "RECREATE"); + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) { + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + hTPCcalib[ipart][icharge]->Write(); + } + } + fileout->Close(); + +} + +/**************************************************************/ + +TPCcalib_delta(const Char_t *filename, Int_t ipart, Int_t icharge, Float_t tofsigmaMin = -3., Float_t tofsigmaMax = 3.) +{ + + Double_t ptMin[AliPID::kSPECIES] = {0., 0., 0.5, 0.5, 0.5}; + Double_t ptMax[AliPID::kSPECIES] = {0.5, 0., 1.5, 1.5, 2.0}; + + /* load HistoUtils */ + gROOT->LoadMacro("HistoUtils.C"); + + /* open data */ + TFile *filein = TFile::Open(filename); + THnSparseF *hTPCcalib = (THnSparseF *)filein->Get(Form("hTPCcalib_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + + /* set momentum range */ + hTPCcalib->GetAxis(kPtpc)->SetRangeUser(ptMin[ipart] + 0.001, ptMax[ipart] - 0.001); + + /* set TOF pid range */ + // hTPCcalib->GetAxis(kTOFsignal)->SetRangeUser(tofsigmaMin + 0.001, tofsigmaMax - 0.001); + + /* minimum-bias projection */ + hTPCcalib->GetAxis(kCentrality)->SetRange(1, NcentralityBins); + TH2 *hDeltaPtpc = hTPCcalib->Projection(kTPCdelta, kPtpc); + TObjArray *oaTPCdelta_mb = HistoUtils_FitPeak(NULL, hDeltaPtpc, 5, 3., 3., 100, Form("hTPCdelta_mb_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + delete hDeltaPtpc; + + /* convert to bethe-blok */ + TH1D *hTPCdelta_mb = (TH1D *)oaTPCdelta_mb->At(1); + TH1D *hTPCbethe_mb = TPCcalib_delta2bethe(hTPCdelta_mb, ipart, Form("hTPCbethe_mb_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + + /* centrality projections */ + TObjArray *oaTPCdelta_cent[NcentralityBins]; + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + + hTPCcalib->GetAxis(kCentrality)->SetRange(icent + 1, icent + 1); + hDeltaPtpc = hTPCcalib->Projection(kTPCdelta, kPtpc); + oaTPCdelta_cent[icent] = HistoUtils_FitPeak(NULL, hDeltaPtpc, 5, 3., 3., 100, Form("hTPCdelta_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + delete hDeltaPtpc; + } + +} + +/**************************************************************/ + +TF1 * +TPCcalib_BetheBlochAleph(Double_t min, Double_t max) +{ + + TF1 *f = new TF1("fBetheBlochAleph", "[0] * AliExternalTrackParam::BetheBlochAleph(x, [1], [2], [3], [4], [5])", min, max); + f->SetParameter(0, 50.); + f->SetParameter(1, 0.0283086); + f->SetParameter(2, 2.63394e+01); + f->SetParameter(3, 5.04114e-11); + f->SetParameter(4, 2.12543); + f->SetParameter(5, 4.88663); + +#if 0 + 1 p0 4.94077e+01 nan nan -4.26724e+00 + 2 p1 2.83086e-02 nan nan -7.44772e+03 + 3 p2 2.62767e+01 nan nan 3.89671e-01 + 4 p3 -1.00486e-03 nan nan 7.91984e+04 + 5 p4 2.43863e+00 nan nan -1.64563e-04 + 6 p5 4.37961e+00 nan nan inf +#endif + + + return f; + +}; + +/**************************************************************/ + +void +TPCcalib_fitBetheBloch(TGraphErrors *g, TF1 *f, Int_t param = -1) +{ + + TVirtualFitter::SetMaxIterations(1000000); + if (param >= 0) { + for (Int_t ipar = 0; ipar < 6; ipar++) + if (ipar != param) + f->FixParameter(ipar, f->GetParameter(ipar)); + else + f->ReleaseParameter(ipar); + } + else { + for (Int_t ipar = 0; ipar < 6; ipar++) + f->ReleaseParameter(ipar); + } + g->Fit(f, "", "", 0.5, 5.); + +} + +/**************************************************************/ + +TPCcalib_bethe(const Char_t *filename, Int_t icent = -1, Float_t tofsigmaMin = -3., Float_t tofsigmaMax = 3.) +{ + + /* include path for ACLic */ + gSystem->AddIncludePath("-I$ALICE_ROOT/include"); + gSystem->AddIncludePath("-I$ALICE_ROOT/TOF"); + /* load libraries */ + gSystem->Load("libANALYSIS"); + gSystem->Load("libANALYSISalice"); + /* build analysis task class */ + gROOT->LoadMacro("AliAnalysisParticle.cxx+g"); + gROOT->LoadMacro("AliAnalysisEvent.cxx+g"); + gROOT->LoadMacro("AliAnalysisTrack.cxx+g"); + + + AliAnalysisTrack t; + + Double_t ptMin[AliPID::kSPECIES] = {0., 0., 0.5, 0.5, 0.5}; + Double_t ptMax[AliPID::kSPECIES] = {0., 0., 1.5, 1.5, 2.0}; + + /* set centrality name */ + Char_t centName[1024]; + if (icent < 0 || icent >= NcentralityBins) + sprintf(centName, "cent0090"); + else + sprintf(centName, "cent%02d%02d", , centralityBin[icent], centralityBin[icent + 1]); + + /* load HistoUtils */ + gROOT->LoadMacro("HistoUtils.C"); + + /* open data */ + TFile *filein = TFile::Open(filename); + + /* output */ + TFile *fileout = TFile::Open(Form("TPCcalib_bethe_%s.%s", centName, filename), "RECREATE"); + + /* loop over particles and charges */ + TH1D *hTPCbethe[AliPID::kSPECIES][kNCharges]; + TGraphErrors *gTPCbethe = new TGraphErrors(); + gTPCbethe->SetName("gTPCbethe"); + Int_t nPoints = 0; + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) { + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + + /* check momentum range */ + if (ptMax[ipart] == 0. || ptMax[ipart] < ptMin[ipart]) continue; + + /* get histo */ + THnSparseF *hTPCcalib = (THnSparseF *)filein->Get(Form("hTPCcalib_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + + /* set centrality range */ + if (icent < 0 || icent >= NcentralityBins) + hTPCcalib->GetAxis(kCentrality)->SetRange(1, NcentralityBins); + else + hTPCcalib->GetAxis(kCentrality)->SetRange(icent + 1, icent + 1); + + /* set TOF pid range */ + hTPCcalib->GetAxis(kTOFsignal)->SetRangeUser(tofsigmaMin + 0.001, tofsigmaMax - 0.001); + + /* set momentum range */ + hTPCcalib->GetAxis(kPtpc)->SetRangeUser(ptMin[ipart] + 0.001, ptMax[ipart] - 0.001); + + /* minimum-bias projection */ + TH2 *hDeltaPtpc = hTPCcalib->Projection(kTPCdelta, kPtpc); + TObjArray *oaTPCdelta = HistoUtils_FitPeak(NULL, hDeltaPtpc, 5, 3., 3., 100, Form("hTPCdelta_%s_%s_%s", centName, AliPID::ParticleName(ipart), chargeName[icharge])); + delete hDeltaPtpc; + + /* convert to bethe-blok */ + TH1D *hTPCdelta = (TH1D *)oaTPCdelta->At(1); + hTPCbethe[ipart][icharge] = TPCcalib_delta2bethe(hTPCdelta, ipart, Form("hTPCbethe_%s_%s_%s", centName, AliPID::ParticleName(ipart), chargeName[icharge])); + + /* delete array */ + delete oaTPCdelta; + + /* add points to graph */ + for (Int_t ibin = 0; ibin < hTPCbethe[ipart][icharge]->GetNbinsX(); ibin++) { + gTPCbethe->SetPoint(nPoints, hTPCbethe[ipart][icharge]->GetBinCenter(ibin + 1), hTPCbethe[ipart][icharge]->GetBinContent(ibin + 1)); + gTPCbethe->SetPointError(nPoints, 0.5 * hTPCbethe[ipart][icharge]->GetBinWidth(ibin + 1), hTPCbethe[ipart][icharge]->GetBinError(ibin + 1)); + nPoints++; + } + + /* write */ + fileout->cd(); + hTPCbethe[ipart][icharge]->Write(); + } + } + + + TF1 *fBethe = TPCcalib_BetheBlochAleph(0.1, 1.e3); + for (Int_t i = 0; i < 50; i++) + for (Int_t ii = 0; ii < 6; ii++) + TPCcalib_fitBetheBloch(gTPCbethe, fBethe, ii); + TPCcalib_fitBetheBloch(gTPCbethe, fBethe, -1); + + /* write */ + fileout->cd(); + gTPCbethe->Write("gTPCbethe"); + fBethe->Write("fBetheBlochAleph"); + + /* close file */ + fileout->Close(); + + return; + +} + +/**************************************************************/ + +TPCcalib_gain(const Char_t *filename, Int_t ipart, Int_t icharge, Float_t tofsigmaMin = -3., Float_t tofsigmaMax = 3.) +{ + + /* load HistoUtils */ + gROOT->LoadMacro("HistoUtils.C"); + + /* open data */ + TFile *filein = TFile::Open(filename); + THnSparseF *hTPCcalib = (THnSparseF *)filein->Get(Form("hTPCcalib_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + + /* set TOF pid range */ + // hTPCcalib->GetAxis(kTOFsignal)->SetRangeUser(tofsigmaMin + 0.001, tofsigmaMax - 0.001); + + /* minimum-bias projection */ + hTPCcalib->GetAxis(kCentrality)->SetRange(1, NcentralityBins); + TH2 *hGainPtpc = hTPCcalib->Projection(kTPCgain, kPtpc); + TObjArray *oaTPCgain_mb = HistoUtils_FitPeak(NULL, hGainPtpc, 5, 3., 3., 100, Form("hTPCgain_mb_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + delete hGainPtpc; + TH1D *hmb = (TH1D *)oaTPCgain_mb->At(1); + + /* centrality projections */ + TObjArray *oaTPCgain_cent[NcentralityBins]; + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + + hTPCcalib->GetAxis(kCentrality)->SetRange(icent + 1, icent + 1); + hGainPtpc = hTPCcalib->Projection(kTPCgain, kPtpc); + oaTPCgain_cent[icent] = HistoUtils_FitPeak(NULL, hGainPtpc, 5, 3., 3., 100, Form("hTPCgain_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + TH1D *hcent = (TH1D *)oaTPCgain_cent[icent]->At(1); + hcent->Divide(hmb); + delete hGainPtpc; + } + +} + +/**************************************************************/ + +TH1D * +TPCcalib_delta2bethe(TH1D *hDelta, Int_t ipart, const Char_t *name = "hTPCbethe") +{ + + Int_t nbins = hDelta->GetNbinsX(); + Float_t *xbins = new Float_t[nbins + 1]; + for(Int_t ibin = 0; ibin <= nbins; ibin++) + xbins[ibin] = hDelta->GetBinLowEdge(ibin + 1) / AliPID::ParticleMass(ipart); + + TH1D *hBethe = new TH1D(name, "", nbins, xbins); + /* TPC PID response */ + AliTPCPIDResponse *tpcResponse = AliAnalysisTrack::GetTPCResponse(); + Double_t ptpc, delta, bethe, deltae; + for (Int_t ibin = 0; ibin < nbins; ibin++) { + ptpc = hDelta->GetBinCenter(ibin + 1); + delta = hDelta->GetBinContent(ibin + 1); + deltae = hDelta->GetBinError(ibin + 1); + bethe = tpcResponse->GetExpectedSignal(ptpc, ipart); + hBethe->SetBinContent(ibin + 1, bethe + delta); + hBethe->SetBinError(ibin + 1, deltae); + } + + return hBethe; +} diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TPCcalib.sh b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TPCcalib.sh new file mode 100755 index 00000000000..2667df1adbe --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TPCcalib.sh @@ -0,0 +1,9 @@ +#! /bin/bash + +if [ "$1" == "" ]; then + echo "argument needed" + exit 1 +fi +echo "launching TPCcalib on $1 in background" +aliroot -b -q "TPCcalib.C(\"$1\")" &> TPCcalib.$1.log & +echo "TPCcalib started" \ No newline at end of file diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TZEROcalib.C b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TZEROcalib.C new file mode 100644 index 00000000000..cf19b2f1c1a --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TZEROcalib.C @@ -0,0 +1,420 @@ +#include "CommonDefs.C" + +Int_t ncentbins = 5; +Int_t nvertexbins = 20; + +TZEROcalib(const Char_t *filename = "data.root", const Char_t *calibfilename = NULL, Int_t evMax = kMaxInt) +{ + + /* include path for ACLic */ + gSystem->AddIncludePath("-I$ALICE_ROOT/include"); + gSystem->AddIncludePath("-I$ALICE_ROOT/TOF"); + /* load libraries */ + gSystem->Load("libANALYSIS"); + gSystem->Load("libANALYSISalice"); + /* build analysis task class */ + gROOT->LoadMacro("AliAnalysisParticle.cxx+g"); + gROOT->LoadMacro("AliAnalysisEvent.cxx+g"); + gROOT->LoadMacro("AliAnalysisTrack.cxx+g"); + + /* open file, get tree and connect */ + TFile *filein = TFile::Open(filename); + TTree *treein = (TTree *)filein->Get("aodTree"); + printf("got \"aodTree\": %d entries\n", treein->GetEntries()); + AliAnalysisEvent *analysisEvent = new AliAnalysisEvent(); + TClonesArray *analysisTrackArray = new TClonesArray("AliAnalysisTrack"); + AliAnalysisTrack *analysisTrack = NULL; + treein->SetBranchAddress("AnalysisEvent", &analysisEvent); + treein->SetBranchAddress("AnalysisTrack", &analysisTrackArray); + + /* open calibfile */ + TH1 *hCentrality_TZEROA_mean = NULL; + TH1 *hCentrality_TZEROA_sigma = NULL; + TH1 *hCentrality_TZEROC_mean = NULL; + TH1 *hCentrality_TZEROC_sigma = NULL; + TH1 *hCentrality_TOF_mean = NULL; + TH1 *hCentrality_TOF_TZEROA_mean = NULL; + TH1 *hCentrality_TOF_TZEROC_mean = NULL; + TH1 *hCentrality_TOF_TZEROTOF_mean = NULL; + if (calibfilename) { + TFile *calibfile = TFile::Open(calibfilename); + hCentrality_TZEROA_mean = (TH1 *)calibfile->Get("hCentrality_TZEROA_mean"); + hCentrality_TZEROA_sigma = (TH1 *)calibfile->Get("hCentrality_TZEROA_sigma"); + hCentrality_TZEROC_mean = (TH1 *)calibfile->Get("hCentrality_TZEROC_calib"); + hCentrality_TZEROC_sigma = (TH1 *)calibfile->Get("hCentrality_TZEROC_sigma"); + hCentrality_TOF_mean = (TH1 *)calibfile->Get("hCentrality_TOF_mean"); + hCentrality_TOF_TZEROA_mean = (TH1 *)calibfile->Get("hCentrality_TOF_TZEROA_mean"); + hCentrality_TOF_TZEROC_mean = (TH1 *)calibfile->Get("hCentrality_TOF_TZEROC_mean"); + hCentrality_TOF_TZEROTOF_mean = (TH1 *)calibfile->Get("hCentrality_TOF_TZEROTOF_mean"); + } + + /* histos */ + TH1F *hCentrality = new TH1F("hCentrality", "", NcentralityBins, centralityBin); + TH1F *hCentrality_AC = new TH1F("hCentrality_AC", "", NcentralityBins, centralityBin); + TH1F *hCentrality_A = new TH1F("hCentrality_A", "", NcentralityBins, centralityBin); + TH1F *hCentrality_C = new TH1F("hCentrality_C", "", NcentralityBins, centralityBin); + TH1F *hCentrality_NONE = new TH1F("hCentrality_NONE", "", NcentralityBins, centralityBin); + + TH2F *hCentrality_TZEROA = new TH2F("hCentrality_TZEROA", "", NcentralityBins, centralityBin, 200, -2440., 2440.); + TH2F *hCentrality_TZEROC = new TH2F("hCentrality_TZEROC", "", NcentralityBins, centralityBin, 200, -2440., 2440.); + TH2F *hCentrality_TZEROOR = new TH2F("hCentrality_TZEROOR", "", NcentralityBins, centralityBin, 200, -2440., 2440.); + TH2F *hCentrality_TZEROAND = new TH2F("hCentrality_TZEROAND", "", NcentralityBins, centralityBin, 200, -2440., 2440.); + TH2F *hCentrality_TZEROTOF = new TH2F("hCentrality_TZEROTOF", "", NcentralityBins, centralityBin, 200, -2440., 2440.); + TH2F *hCentrality_TZERODIFF = new TH2F("hCentrality_TZERODIFF", "", NcentralityBins, centralityBin, 200, -2440., 2440.); + + TH2F *hCentrality_TZEROTOF_TZEROA = new TH2F("hCentrality_TZEROTOF_TZEROA", "", NcentralityBins, centralityBin, 200, -2440., 2440.); + TH2F *hCentrality_TZEROTOF_TZEROC = new TH2F("hCentrality_TZEROTOF_TZEROC", "", NcentralityBins, centralityBin, 200, -2440., 2440.); + TH2F *hCentrality_TZEROTOF_TZEROAND = new TH2F("hCentrality_TZEROTOF_TZEROAND", "", NcentralityBins, centralityBin, 200, -2440., 2440.); + TH2F *hCentrality_TZEROA_TZEROC = new TH2F("hCentrality_TZEROA_TZEROC", "", NcentralityBins, centralityBin, 200, -2440., 2440.); + + TH2F *hVertex_TZEROA = new TH2F("hVertex_TZEROA", "", nvertexbins, -10., 10., 200, -2440., 2440.); + TH2F *hVertex_TZEROC = new TH2F("hVertex_TZEROC", "", nvertexbins, -10., 10., 200, -2440., 2440.); + TH2F *hVertex_TZEROOR = new TH2F("hVertex_TZEROOR", "", nvertexbins, -10., 10., 200, -2440., 2440.); + TH2F *hVertex_TZEROAND = new TH2F("hVertex_TZEROAND", "", nvertexbins, -10., 10., 200, -2440., 2440.); + TH2F *hVertex_TZEROTOF = new TH2F("hVertex_TZEROTOF", "", nvertexbins, -10., 10., 200, -2440., 2440.); + TH2F *hVertex_TZERODIFF = new TH2F("hVertex_TZERODIFF", "", nvertexbins, -10., 10., 200, -2440., 2440.); + + + TH2F *hCentrality_TOF = new TH2F("hCentrality_TOF", "", NcentralityBins, centralityBin, 200, -2440., 2440.); + TH2F *hCentrality_TOF_TZEROA = new TH2F("hCentrality_TOF_TZEROA", "", NcentralityBins, centralityBin, 200, -2440., 2440.); + TH2F *hCentrality_TOF_TZEROC = new TH2F("hCentrality_TOF_TZEROC", "", NcentralityBins, centralityBin, 200, -2440., 2440.); + TH2F *hCentrality_TOF_TZEROAND = new TH2F("hCentrality_TOF_TZEROAND", "", NcentralityBins, centralityBin, 200, -2440., 2440.); + TH2F *hCentrality_TOF_TZEROTOF = new TH2F("hCentrality_TOF_TZEROTOF", "", NcentralityBins, centralityBin, 200, -2440., 2440.); + TH2F *hCentrality_Resolution = new TH2F("hCentrality_Resolution", "", NcentralityBins, centralityBin, 20, 0., 100.); + + TH2F *hResolution_TZERODIFF = new TH2F("hResolution_TZERODIFF", "", 20, 0., 100., 200, -2440., 2440.); + TH2F *hResolution_TOF_TZEROA = new TH2F("hResolution_TOF_TZEROA", "", 20, 0., 100., 200, -2440., 2440.); + TH2F *hResolution_TOF_TZEROC = new TH2F("hResolution_TOF_TZEROC", "", 20, 0., 100., 200, -2440., 2440.); + TH2F *hResolution_TOF_TZEROAND = new TH2F("hResolution_TOF_TZEROAND", "", 20, 0., 100., 200, -2440., 2440.); + TH2F *hResolution_TOF_TZEROTOF = new TH2F("hResolution_TOF_TZEROTOF", "", 20, 0., 100., 200, -2440., 2440.); + + TH2F *hVertex_TOF = new TH2F("hVertex_TOF", "", nvertexbins, -10., 10., 200, -2440., 2440.); + TH2F *hVertex_TOF_TZEROA = new TH2F("hVertex_TOF_TZEROA", "", nvertexbins, -10., 10., 200, -2440., 2440.); + TH2F *hVertex_TOF_TZEROC = new TH2F("hVertex_TOF_TZEROC", "", nvertexbins, -10., 10., 200, -2440., 2440.); + TH2F *hVertex_TOF_TZEROOR = new TH2F("hVertex_TOF_TZEROOR", "", nvertexbins, -10., 10., 200, -2440., 2440.); + TH2F *hVertex_TOF_TZEROAND = new TH2F("hVertex_TOF_TZEROAND", "", nvertexbins, -10., 10., 200, -2440., 2440.); + TH2F *hVertex_TOF_TZEROTOF = new TH2F("hVertex_TOF_TZEROTOF", "", nvertexbins, -10., 10., 200, -2440., 2440.); + + TH2F *hDiffDiff = new TH2F("hDiffDiff", "", 200, -2440., 2440., 200, -2440., 2440.); + + /* loop over events */ + for (Int_t iev = 0; iev < treein->GetEntries() && iev < evMax; iev++) { + /* get event */ + treein->GetEvent(iev); + if (iev % 100000 == 0) printf("iev = %d\n", iev); + /* check event */ + if (!analysisEvent->AcceptEvent(acceptEventType)) continue; + + /*** ACCEPTED EVENT ***/ + + /* get vertex position */ + Double_t vertexz = analysisEvent->GetVertexZ(); + + /* get centrality */ + Double_t cent = analysisEvent->GetCentralityPercentile(centralityEstimator); + hCentrality->Fill(cent); + + Int_t icent; + for (icent = 0; icent < NcentralityBins; icent++) + if (cent < centralityBin[icent + 1]) + break; + + Double_t TZEROA_mean = hCentrality_TZEROA_mean ? hCentrality_TZEROA_mean->GetBinContent(icent + 1) : 0.; + Double_t TZEROA_sigma = hCentrality_TZEROA_sigma ? hCentrality_TZEROA_sigma->GetBinContent(icent + 1) : 1000.; + Double_t TZEROC_mean = hCentrality_TZEROC_mean ? hCentrality_TZEROC_mean->GetBinContent(icent + 1) : 0.; + Double_t TZEROC_sigma = hCentrality_TZEROC_sigma ? hCentrality_TZEROC_sigma->GetBinContent(icent + 1) : 1000.; + + Double_t TOF_mean = hCentrality_TOF_mean ? hCentrality_TOF_mean->GetBinContent(icent + 1) : 0.; + Double_t TOF_TZEROA_mean = hCentrality_TOF_TZEROA_mean ? hCentrality_TOF_TZEROA_mean->GetBinContent(icent + 1) : 0.; + Double_t TOF_TZEROC_mean = hCentrality_TOF_TZEROC_mean ? hCentrality_TOF_TZEROC_mean->GetBinContent(icent + 1) : 0.; + Double_t TOF_TZEROTOF_mean = hCentrality_TOF_TZEROTOF_mean ? hCentrality_TOF_TZEROTOF_mean->GetBinContent(icent + 1) : 0.; + + + /* TZERO */ + Double_t TZEROA = analysisEvent->GetTimeZeroT0(1) - TZEROA_shift; + Bool_t hasTZEROA = TMath::Abs(TZEROA - TZEROA_mean) < 3. * TZEROA_sigma; + Double_t TZEROC = analysisEvent->GetTimeZeroT0(2) - TZEROC_shift; + Bool_t hasTZEROC = TMath::Abs(TZEROC - TZEROC_mean) < 3. * TZEROC_sigma; + /* vertex correction */ + // TZEROA += -TZEROvertexCorr * vertexz; + // TZEROC += TZEROvertexCorr * vertexz; + /* alignment to TOF */ + TZEROA += TOF_TZEROA_mean - TOF_mean; + TZEROC += TOF_TZEROC_mean - TOF_mean; + /* TZEROAND */ + Double_t TZEROAND = (TZEROA + TZEROC) * 0.5; + Bool_t hasTZEROAND = hasTZEROA && hasTZEROC; + /* TZEROTOF */ + Double_t TZEROTOF = analysisEvent->GetTimeZeroTOF()[9]; + Bool_t hasTZEROTOF = analysisEvent->GetTimeZeroTOFSigma()[9] < 150.; + TZEROTOF += TOF_TZEROTOF_mean - TOF_mean; + + if (hasTZEROA) { + hCentrality_TZEROA->Fill(cent, TZEROA); + hVertex_TZEROA->Fill(vertexz, TZEROA); + } + if (hasTZEROC) { + hCentrality_TZEROC->Fill(cent, TZEROC); + hVertex_TZEROC->Fill(vertexz, TZEROC); + } + if (hasTZEROAND) { + hCentrality_TZEROAND->Fill(cent, TZEROAND); + hVertex_TZEROAND->Fill(vertexz, TZEROAND); + } + if (hasTZEROTOF) { + hCentrality_TZEROTOF->Fill(cent, TZEROTOF); + hVertex_TZEROTOF->Fill(vertexz, TZEROTOF); + } + + if (hasTZEROA && hasTZEROC && hasTZEROAND && hasTZEROTOF) { + hCentrality_TZEROTOF_TZEROA->Fill(cent, TZEROTOF - TZEROA); + hCentrality_TZEROTOF_TZEROC->Fill(cent, TZEROTOF - TZEROC); + hCentrality_TZEROTOF_TZEROAND->Fill(cent, TZEROTOF - TZEROAND); + hCentrality_TZEROA_TZEROC->Fill(cent, TZEROA - TZEROC); + } + + /* loop over tracks */ + for (Int_t itrk = 0; itrk < analysisTrackArray->GetEntries(); itrk++) { + /* get track */ + AliAnalysisTrack *analysisTrack = (AliAnalysisTrack *)analysisTrackArray->At(itrk); + if (!analysisTrack) continue; + /* check accepted track */ + if (!analysisTrack->AcceptTrack()) continue; + /* check momentum */ + if (analysisTrack->GetP() < 0.9 || analysisTrack->GetP() > 1.1) continue; + /* check TOF pid */ + if (!analysisTrack->HasTOFPID()) continue; + + TZEROTOF = analysisEvent->GetTimeZeroTOF(analysisTrack->GetP()); + TZEROTOF += TOF_TZEROTOF_mean - TOF_mean; + hasTZEROTOF = analysisEvent->GetTimeZeroTOFSigma(analysisTrack->GetP()) < 150.; + + Double_t time = analysisTrack->GetTOFTime() - TOF_mean; + Double_t texp = analysisTrack->GetTOFExpTime(2); + Double_t deltat = time - texp; + + + hCentrality_TOF->Fill(cent, deltat); + hVertex_TOF->Fill(vertexz, deltat); + if (hasTZEROA) { + hCentrality_TOF_TZEROA->Fill(cent, deltat - TZEROA); + hVertex_TOF_TZEROA->Fill(vertexz, deltat - TZEROA); + } + if (hasTZEROC) { + hCentrality_TOF_TZEROC->Fill(cent, deltat - TZEROC); + hVertex_TOF_TZEROC->Fill(vertexz, deltat - TZEROC); + } + if (hasTZEROAND) { + hCentrality_TOF_TZEROAND->Fill(cent, deltat - TZEROAND); + hVertex_TOF_TZEROAND->Fill(vertexz, deltat - TZEROAND); + } + if (hasTZEROTOF) { + hCentrality_TOF_TZEROTOF->Fill(cent, deltat - TZEROTOF); + hVertex_TOF_TZEROTOF->Fill(vertexz, deltat - TZEROTOF); + } + + } + + } /* end of loop over events */ + + /* output */ + if (!calibfilename) TFile *fileout = TFile::Open(Form("TZEROcalib.%s", filename), "RECREATE"); + else TFile *fileout = TFile::Open(Form("TZEROcheck.%s", filename), "RECREATE"); + + hCentrality->Write(); + hCentrality_TZEROA->Write(); + hCentrality_TZEROC->Write(); + hCentrality_TZEROAND->Write(); + hCentrality_TZEROTOF->Write(); + hCentrality_TZERODIFF->Write(); + + hVertex_TZEROA->Write(); + hVertex_TZEROC->Write(); + hVertex_TZEROAND->Write(); + hVertex_TZEROTOF->Write(); + hVertex_TZERODIFF->Write(); + + hCentrality_TOF->Write(); + hCentrality_TOF_TZEROA->Write(); + hCentrality_TOF_TZEROC->Write(); + hCentrality_TOF_TZEROAND->Write(); + hCentrality_TOF_TZEROTOF->Write(); + hCentrality_Resolution->Write(); + + hCentrality_TZEROTOF_TZEROA->Write(); + hCentrality_TZEROTOF_TZEROC->Write(); + hCentrality_TZEROTOF_TZEROAND->Write(); + hCentrality_TZEROA_TZEROC->Write(); + + hVertex_TOF->Write(); + hVertex_TOF_TZEROA->Write(); + hVertex_TOF_TZEROC->Write(); + hVertex_TOF_TZEROAND->Write(); + hVertex_TOF_TZEROTOF->Write(); + + hResolution_TZERODIFF->Write(); + hResolution_TOF_TZEROA->Write(); + hResolution_TOF_TZEROC->Write(); + hResolution_TOF_TZEROAND->Write(); + + hDiffDiff->Write(); + + fileout->Close(); + + if (!calibfilename) { + TZEROcalibration(Form("TZEROcalib.%s", filename)); + TZEROcalib(filename, "TZEROcalibration.root"); + TZEROresolution(Form("TZEROcheck.%s", filename)); + } + +} + +TZEROcalibration(const Char_t *filename = "TZEROcalib.data.root", Float_t min = 2., Float_t max = 1.) +{ + + gROOT->LoadMacro("FitPeak.C"); + + TFile *fin = TFile::Open(filename); + TH2 *hCentrality_TOF = (TH2 *)fin->Get("hCentrality_TOF"); + TH2 *hCentrality_TZEROA = (TH2 *)fin->Get("hCentrality_TZEROA"); + TH2 *hCentrality_TZEROC = (TH2 *)fin->Get("hCentrality_TZEROC"); + + TH2 *hCentrality_TOF_TZEROTOF = (TH2 *)fin->Get("hCentrality_TOF_TZEROTOF"); + TH2 *hCentrality_TOF_TZEROA = (TH2 *)fin->Get("hCentrality_TOF_TZEROA"); + TH2 *hCentrality_TOF_TZEROC = (TH2 *)fin->Get("hCentrality_TOF_TZEROC"); + TH2 *hCentrality_TOF_TZEROTOF = (TH2 *)fin->Get("hCentrality_TOF_TZEROTOF"); + + TFile *fout = TFile::Open("TZEROcalibration.root", "RECREATE"); + FitPeak(hCentrality_TOF, 200., 2., 1., "hCentrality_TOF")->Write(); + FitPeak(hCentrality_TZEROA, 200., 2., 1., "hCentrality_TZEROA")->Write(); + FitPeak(hCentrality_TZEROC, 200., 2., 1., "hCentrality_TZEROC")->Write(); + + FitPeak(hCentrality_TOF_TZEROA, 200., 2., 1., "hCentrality_TOF_TZEROA")->Write(); + FitPeak(hCentrality_TOF_TZEROC, 200., 2., 1., "hCentrality_TOF_TZEROC")->Write(); + FitPeak(hCentrality_TOF_TZEROTOF, 200., 2., 1., "hCentrality_TOF_TZEROTOF")->Write(); + + fout->Close(); +} + +TZEROresolution(const Char_t *filename, Float_t min = 2., Float_t max = 2., Char_t *what = "Centrality") +{ + + TFile *fin = TFile::Open(filename); + hdiff = (TH2 *)fin->Get(Form("h%s_TZEROA_TZEROC", what)); + hA = (TH2 *)fin->Get(Form("h%s_TZEROTOF_TZEROA", what)); + hC = (TH2 *)fin->Get(Form("h%s_TZEROTOF_TZEROC", what)); + hAND = (TH2 *)fin->Get(Form("h%s_TZEROTOF_TZEROAND", what)); + + gROOT->LoadMacro("FitPeak.C"); + + + TH1 *hdiff_sigma = (TH1 *)FitPeak(hdiff, 100., min, max, "sigma1")->At(1); + + TH1 *hA_sigma = (TH1 *)FitPeak(hA, 100., min, max, "sigma2")->At(1); + + TH1 *hC_sigma = (TH1 *)FitPeak(hC, 100., min, max, "sigma3")->At(1); + + TH1 *hAND_sigma = (TH1 *)FitPeak(hAND, 100., min, max, "sigma4")->At(1); + + TH1 *hTZEROTOF_reso = (TH1 *)hdiff_sigma->Clone("hTZEROTOF_reso"); + hTZEROTOF_reso->Reset(); + hTZEROTOF_reso->SetMarkerStyle(20); + hTZEROTOF_reso->SetMarkerColor(2); + hTZEROTOF_reso->SetLineColor(2); + hTZEROTOF_reso->SetTitle("T0-TOF"); + TH1 *hTZEROA_reso = (TH1 *)hdiff_sigma->Clone("hTZEROA_reso"); + hTZEROA_reso->Reset(); + hTZEROA_reso->SetMarkerStyle(21); + hTZEROA_reso->SetMarkerColor(8); + hTZEROA_reso->SetLineColor(8); + hTZEROA_reso->SetTitle("T0-TZEROA"); + TH1 *hTZEROC_reso = (TH1 *)hdiff_sigma->Clone("hTZEROC_reso"); + hTZEROC_reso->Reset(); + hTZEROC_reso->SetMarkerStyle(22); + hTZEROC_reso->SetMarkerColor(4); + hTZEROC_reso->SetLineColor(4); + hTZEROC_reso->SetTitle("T0-TZEROC"); + TH1 *hTZEROAND_reso = (TH1 *)hdiff_sigma->Clone("hTZEROAND_reso"); + hTZEROAND_reso->Reset(); + hTZEROAND_reso->SetMarkerStyle(23); + hTZEROAND_reso->SetMarkerColor(kYellow+1); + hTZEROAND_reso->SetLineColor(kYellow+1); + hTZEROAND_reso->SetTitle("T0-TZEROAND"); + + for (Int_t i = 0; i < hTZEROTOF_reso->GetNbinsX(); i++) { + + Double_t diff = hdiff_sigma->GetBinContent(i+1); + Double_t diff_e = hdiff_sigma->GetBinError(i+1); + Double_t diff2 = diff*diff; + Double_t diff2_e = 2.*diff*diff_e; + Double_t a = hA_sigma->GetBinContent(i+1); + Double_t a_e = hA_sigma->GetBinError(i+1); + Double_t a2 = a*a; + Double_t a2_e = 2.*a*a_e; + Double_t c = hC_sigma->GetBinContent(i+1); + Double_t c_e = hC_sigma->GetBinError(i+1); + Double_t c2 = c*c; + Double_t c2_e = 2.*c*c_e; + Double_t ac = hAND_sigma->GetBinContent(i+1); + Double_t ac_e = hAND_sigma->GetBinError(i+1); + Double_t ac2 = ac*ac; + Double_t ac2_e = 2.*ac*ac_e; + + if (diff == 0.) continue; + if (a2 + c2 - diff2 < 0.) continue; + + printf("a=%f, c=%f, diff=%f, ac=%f\n", a, c, diff, ac); + + Double_t tofreso2 = (a2 + c2 - diff2) * 0.5; + Double_t tofreso2_e = (a2_e + c2_e + diff2_e) * 0.5; + Double_t tofreso = TMath::Sqrt(tofreso2); + Double_t tofreso_e = tofreso2_e / (2. * tofreso); + hTZEROTOF_reso->SetBinContent(i+1, tofreso); + hTZEROTOF_reso->SetBinError(i+1, tofreso_e); + + if (a2 - tofreso*tofreso < 0.) continue; + if (c2 - tofreso*tofreso < 0.) continue; + if (ac2 - tofreso*tofreso < 0.) continue; + + Double_t tzeroareso2 = a2 - tofreso2; + Double_t tzeroareso2_e = a2_e + tofreso2_e; + Double_t tzeroareso = TMath::Sqrt(tzeroareso2); + Double_t tzeroareso_e = tzeroareso2_e / (2. * tzeroareso); + hTZEROA_reso->SetBinContent(i+1, tzeroareso); + hTZEROA_reso->SetBinError(i+1, tzeroareso_e); + + Double_t tzerocreso2 = c2 - tofreso2; + Double_t tzerocreso2_e = c2_e + tofreso2_e; + Double_t tzerocreso = TMath::Sqrt(tzerocreso2); + Double_t tzerocreso_e = tzerocreso2_e / (2. * tzerocreso); + hTZEROC_reso->SetBinContent(i+1, tzerocreso); + hTZEROC_reso->SetBinError(i+1, tzerocreso_e); + + Double_t tzeroacreso2 = ac2 - tofreso2; + Double_t tzeroacreso2_e = ac2_e + tofreso2_e; + Double_t tzeroacreso = TMath::Sqrt(tzeroacreso2); + Double_t tzeroacreso_e = tzeroacreso2_e / (2. * tzeroacreso); + hTZEROAND_reso->SetBinContent(i+1, tzeroacreso); + hTZEROAND_reso->SetBinError(i+1, tzeroacreso_e); + + // Double_t tzerocreso = TMath::Sqrt(c2 - tofreso*tofreso); + // hTZEROC_reso->SetBinContent(i+1, tzerocreso); + + // Double_t tzeroacreso = TMath::Sqrt(ac2 - tofreso*tofreso); + // hTZEROAND_reso->SetBinContent(i+1, tzeroacreso); + + printf("TOF=%f, TZEROA=%f, TZEROC=%f, TZEROAND=%f\n", tofreso, tzeroareso, tzerocreso, tzeroacreso); + } + + hTZEROTOF_reso->Draw(); + hTZEROA_reso->Draw("same"); + hTZEROC_reso->Draw("same"); + hTZEROAND_reso->Draw("same"); + + TFile *fout = TFile::Open("TZEROresolution.root", "RECREATE"); + hTZEROTOF_reso->Write(); + hTZEROA_reso->Write(); + hTZEROC_reso->Write(); + hTZEROAND_reso->Write(); + fout->Close(); +} diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TrackingEff.C b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TrackingEff.C new file mode 100644 index 00000000000..df211b74e5a --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TrackingEff.C @@ -0,0 +1,1077 @@ +#include "CommonDefs.C" + +const Char_t *destdir = "plots"; + +enum EHisto_t { + kPrimaryTracks, + kReconstructedTracks, + kNHistos +}; +const Char_t *histoName[kNHistos] = { + "hPrimaryTracks", + "hReconstructedTracks" +}; + +enum EParam_t { + kCentrality, + kPt, + kEta, + kPhi, + kY, + kNParams +}; + +TrackingEff(const Char_t *filename, Int_t evMax = kMaxInt) +{ + + /* include path for ACLic */ + gSystem->AddIncludePath("-I$ALICE_ROOT/include"); + gSystem->AddIncludePath("-I$ALICE_ROOT/TOF"); + /* load libraries */ + gSystem->Load("libANALYSIS"); + gSystem->Load("libANALYSISalice"); + /* build analysis task class */ + gROOT->LoadMacro("AliAnalysisParticle.cxx+g"); + gROOT->LoadMacro("AliAnalysisEvent.cxx+g"); + gROOT->LoadMacro("AliAnalysisTrack.cxx+g"); + + /* open file, get tree and connect */ + TFile *filein = TFile::Open(filename); + TTree *treein = (TTree *)filein->Get("aodTree"); + printf("got \"aodTree\": %d entries\n", treein->GetEntries()); + AliAnalysisEvent *analysisEvent = new AliAnalysisEvent(); + TClonesArray *analysisTrackArray = new TClonesArray("AliAnalysisTrack"); + AliAnalysisTrack *analysisTrack = NULL; + TClonesArray *analysisParticleArray = new TClonesArray("AliAnalysisParticle"); + AliAnalysisParticle *analysisParticle = NULL; + treein->SetBranchAddress("AnalysisEvent", &analysisEvent); + treein->SetBranchAddress("AnalysisTrack", &analysisTrackArray); + treein->SetBranchAddress("AnalysisParticle", &analysisParticleArray); + + /* binning */ + for (Int_t iy = 0; iy < NyBins + 1; iy++) + yBin[iy] = yMin + iy * yStep; + for (Int_t ieta = 0; ieta < NetaBins + 1; ieta++) + etaBin[ieta] = etaMin + ieta * etaStep; + for (Int_t iphi = 0; iphi < NphiBins + 1; iphi++) + phiBin[iphi] = phiMin + iphi * phiStep; + /* THnSparse */ + Int_t NparamBins[kNParams] = {NcentralityBins, NptBins, NetaBins, NphiBins, NyBins}; + Double_t *paramBin[kNParams] = {centralityBin, ptBin, etaBin, phiBin, yBin}; + THnSparseF *hHisto[kNHistos][AliPID::kSPECIES][kNCharges]; + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + hHisto[ihisto][ipart][icharge] = new THnSparseF(Form("hHisto_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge]), "", kNParams, NparamBins); + for (Int_t iparam = 0; iparam < kNParams; iparam++) + hHisto[ihisto][ipart][icharge]->SetBinEdges(iparam, paramBin[iparam]); + } + + /* selected particle array */ + AliAnalysisParticle *selParticle[1000000]; + for (Int_t idx = 0; idx < 1000000; idx++) + selParticle[idx] = NULL; + + /* filled slot array */ + Int_t filledSlot[1000000]; + Int_t nFilledSlots = 0; + + + /* loop over events */ + Double_t param[kNParams]; + Int_t part, charge; + for (Int_t iev = 0; iev < treein->GetEntries() && iev < evMax; iev++) { + /* get event */ + treein->GetEvent(iev); + if (iev % 1000 == 0) printf("iev = %d\n", iev); + /* check vertex */ + if (!analysisEvent->AcceptVertex()) continue; + /* check collision candidate */ + if (!analysisEvent->IsCollisionCandidate()) continue; + /* check centrality quality */ + if (analysisEvent->GetCentralityQuality() != 0.) continue; + param[kCentrality] = analysisEvent->GetCentralityPercentile(centralityEstimator); + + /*** ACCEPTED EVENT ***/ + + /* reset filled slots selected particle array */ + for (Int_t islot = 0; islot < nFilledSlots; islot++) + selParticle[filledSlot[islot]] = NULL; + /* reset filled slots */ + nFilledSlots = 0; + + /* loop over primaries */ + for (Int_t iprim = 0; iprim < analysisParticleArray->GetEntries(); iprim++) { + /* get and check particle */ + analysisParticle = (AliAnalysisParticle *)analysisParticleArray->At(iprim); + if (!analysisParticle || analysisParticle->GetPID() == -1 || analysisParticle->GetLabel() < 0 || analysisParticle->GetSign() == 0.) continue; + + /* check rapidity */ + if (analysisParticle->GetY() - rapidityShift > rapidityMaxCut || + analysisParticle->GetY() - rapidityShift < rapidityMinCut) + continue; + + /*** ACCEPTED PARTICLE ***/ + + /* get particle info */ + part = analysisParticle->GetPID(); + param[kPt] = analysisParticle->GetPt(); + param[kEta] = analysisParticle->GetEta(); + param[kPhi] = analysisParticle->GetPhi(); + charge = analysisParticle->GetSign() > 0. ? kPositive : kNegative; + + /* fill histo and slot */ + hHisto[kPrimaryTracks][part][charge]->Fill(param); + selParticle[analysisParticle->GetLabel()] = analysisParticle; + filledSlot[nFilledSlots] = analysisParticle->GetLabel(); + nFilledSlots++; + + } + + /* loop over tracks */ + for (Int_t itrk = 0; itrk < analysisTrackArray->GetEntries(); itrk++) { + /* get and check track */ + analysisTrack = (AliAnalysisTrack *)analysisTrackArray->At(itrk); + if (!analysisTrack) continue; + /* check accepted track */ + if (!analysisTrack->AcceptTrack()) continue; + /* get corresponding particle */ + analysisParticle = selParticle[TMath::Abs(analysisTrack->GetLabel())]; + if (!analysisParticle) continue; + + /*** ACCEPTED PARTICLE WITH RECONSTRUCTED TRACK ***/ + + /* get particle info */ + part = analysisParticle->GetPID(); + param[kPt] = analysisParticle->GetPt(); + param[kEta] = analysisParticle->GetEta(); + param[kPhi] = analysisParticle->GetPhi(); + charge = analysisParticle->GetSign() > 0. ? kPositive : kNegative; + + /* fill reconstructed histo */ + hHisto[kReconstructedTracks][part][charge]->Fill(param); + + } + + } + + TFile *fileout = TFile::Open(Form("TrackingEff.%s", filename), "RECREATE"); + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) + hHisto[ihisto][ipart][icharge]->Write(); + fileout->Close(); + + TString str = Form("TrackingEff.%s", filename); + TrackingEff_efficiencyPt(str.Data()); + +} + +//_____________________________________________________________________________- + +TrackingEff_efficiencyPt(const Char_t *filename) +{ + + /* get data */ + TFile *filein = TFile::Open(filename); + THnSparseF *hHisto[kNHistos][AliPID::kSPECIES][kNCharges]; + TH1D *hHistoPt_MB[kNHistos][AliPID::kSPECIES][kNCharges], *hHistoPt_centrality[NcentralityBins][kNHistos][AliPID::kSPECIES][kNCharges]; + TH1D *hHistoAllPt_MB[kNHistos], *hHistoAllPt_centrality[NcentralityBins][kNHistos]; + /* loop over histos */ + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) { + + /* INCLUSIVE */ + + hHistoAllPt_MB[ihisto] = new TH1D(Form("hHistoAllPt_MB_%s", histoName[ihisto]), "", NptBins, ptBin); + for (Int_t icent = 0; icent < NcentralityBins; icent++) + hHistoAllPt_centrality[icent][ihisto] = new TH1D(Form("hHistoAllPt_centrality%d_%s", icent, histoName[ihisto]), "", NptBins, ptBin); + + /* SINGLE PARTICLE */ + + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) { + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + + /* get histo */ + hHisto[ihisto][ipart][icharge] = (THnSparseF *)filein->Get(Form("hHisto_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + + /* MB projection */ + hHistoPt_MB[ihisto][ipart][icharge] = hHisto[ihisto][ipart][icharge]->Projection(kPt); + hHistoPt_MB[ihisto][ipart][icharge]->SetName(Form("hHistoPt_MB_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hHistoPt_MB[ihisto][ipart][icharge]->Sumw2(); + hHistoAllPt_MB[ihisto]->Add(hHistoPt_MB[ihisto][ipart][icharge]); + + /* centrality projection */ + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + hHisto[ihisto][ipart][icharge]->GetAxis(kCentrality)->SetRange(icent + 1, icent + 1); + hHistoPt_centrality[icent][ihisto][ipart][icharge] = hHisto[ihisto][ipart][icharge]->Projection(kPt); + hHistoPt_centrality[icent][ihisto][ipart][icharge]->SetName(Form("hHistoPt_centrality%d_%s_%s_%s", icent, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hHistoPt_centrality[icent][ihisto][ipart][icharge]->Sumw2(); + hHistoAllPt_centrality[icent][ihisto]->Add(hHistoPt_centrality[icent][ihisto][ipart][icharge]); + } + } + } + } + + /* output */ + TString str = filename; + str.Insert(str.Length() - TString(".root").Length(), ".efficiencyPt"); + TFile *fileout = TFile::Open(str.Data(), "RECREATE"); + + /* efficiencies/fractions and write */ + TH1D *hEfficiencyPt_MB[kNHistos][AliPID::kSPECIES][kNCharges], *hEfficiencyPt_centrality[NcentralityBins][kNHistos][AliPID::kSPECIES][kNCharges], *hEfficiencyPt_ratioMB_centrality[NcentralityBins][kNHistos][AliPID::kSPECIES][kNCharges]; + TH1D *hEfficiencyAllPt_MB[kNHistos], *hEfficiencyAllPt_centrality[NcentralityBins][kNHistos], *hEfficiencyAllPt_ratioMB_centrality[NcentralityBins][kNHistos]; + + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) { + + if (ihisto == kPrimaryTracks) continue; + + /* INCLUSIVE */ + + /* MB efficiency */ + hEfficiencyAllPt_MB[ihisto] = new TH1D(*hHistoAllPt_MB[ihisto]); + hEfficiencyAllPt_MB[ihisto]->SetName(Form("hEfficiencyAllPt_MB_%s", histoName[ihisto])); + hEfficiencyAllPt_MB[ihisto]->SetLineWidth(2); + hEfficiencyAllPt_MB[ihisto]->SetLineColor(1); + hEfficiencyAllPt_MB[ihisto]->SetMarkerStyle(20); + hEfficiencyAllPt_MB[ihisto]->SetMarkerColor(1); + hEfficiencyAllPt_MB[ihisto]->Divide(hEfficiencyAllPt_MB[ihisto], hHistoAllPt_MB[kPrimaryTracks], 1, 1, "B"); + hEfficiencyAllPt_MB[ihisto]->Write(); + + /* multiplicity/centrality efficiency */ + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + hEfficiencyAllPt_centrality[icent][ihisto] = new TH1D(*hHistoAllPt_centrality[icent][ihisto]); + hEfficiencyAllPt_centrality[icent][ihisto]->SetName(Form("hEfficiencyAllPt_centrality%d_%s", icent, histoName[ihisto])); + hEfficiencyAllPt_centrality[icent][ihisto]->SetLineWidth(2); + hEfficiencyAllPt_centrality[icent][ihisto]->SetLineColor(multcentColor[icent]); + hEfficiencyAllPt_centrality[icent][ihisto]->SetMarkerStyle(20); + hEfficiencyAllPt_centrality[icent][ihisto]->SetMarkerColor(multcentColor[icent]); + hEfficiencyAllPt_centrality[icent][ihisto]->Divide(hEfficiencyAllPt_centrality[icent][ihisto], hHistoAllPt_centrality[icent][kPrimaryTracks], 1, 1, "B"); + hEfficiencyAllPt_centrality[icent][ihisto]->Write(); + + /* ratio wrt. MB */ + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto] = new TH1D(*hEfficiencyAllPt_centrality[icent][ihisto]); + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto]->SetName(Form("hEfficiencyAllPt_ratioMB_centrality%d_%s", icent, histoName[ihisto])); + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto]->SetLineWidth(2); + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto]->SetLineColor(multcentColor[icent]); + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto]->SetMarkerStyle(20); + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto]->SetMarkerColor(multcentColor[icent]); + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto]->Divide(hEfficiencyAllPt_MB[ihisto]); + hEfficiencyAllPt_ratioMB_centrality[icent][ihisto]->Write(); + } + + /* SINGLE PARTICLE */ + + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) { + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + + /* MB efficiency */ + hEfficiencyPt_MB[ihisto][ipart][icharge] = new TH1D(*hHistoPt_MB[ihisto][ipart][icharge]); + hEfficiencyPt_MB[ihisto][ipart][icharge]->SetName(Form("hEfficiencyPt_MB_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyPt_MB[ihisto][ipart][icharge]->SetLineWidth(2); + hEfficiencyPt_MB[ihisto][ipart][icharge]->SetLineColor(1); + hEfficiencyPt_MB[ihisto][ipart][icharge]->SetMarkerStyle(20); + hEfficiencyPt_MB[ihisto][ipart][icharge]->SetMarkerColor(1); + hEfficiencyPt_MB[ihisto][ipart][icharge]->Divide(hEfficiencyPt_MB[ihisto][ipart][icharge], hHistoPt_MB[kPrimaryTracks][ipart][icharge], 1, 1, "B"); + hEfficiencyPt_MB[ihisto][ipart][icharge]->Write(); + + /* multiplicity/centrality efficiency */ + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + hEfficiencyPt_centrality[icent][ihisto][ipart][icharge] = new TH1D(*hHistoPt_centrality[icent][ihisto][ipart][icharge]); + hEfficiencyPt_centrality[icent][ihisto][ipart][icharge]->SetName(Form("hEfficiencyPt_centrality%d_%s_%s_%s", icent, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyPt_centrality[icent][ihisto][ipart][icharge]->SetLineWidth(2); + hEfficiencyPt_centrality[icent][ihisto][ipart][icharge]->SetLineColor(multcentColor[icent]); + hEfficiencyPt_centrality[icent][ihisto][ipart][icharge]->SetMarkerStyle(20); + hEfficiencyPt_centrality[icent][ihisto][ipart][icharge]->SetMarkerColor(multcentColor[icent]); + hEfficiencyPt_centrality[icent][ihisto][ipart][icharge]->Divide(hEfficiencyPt_centrality[icent][ihisto][ipart][icharge], hHistoPt_centrality[icent][kPrimaryTracks][ipart][icharge], 1, 1, "B"); + hEfficiencyPt_centrality[icent][ihisto][ipart][icharge]->Write(); + + /* ratio wrt. MB */ + hEfficiencyPt_ratioMB_centrality[icent][ihisto][ipart][icharge] = new TH1D(*hEfficiencyPt_centrality[icent][ihisto][ipart][icharge]); + hEfficiencyPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetName(Form("hEfficiencyPt_ratioMB_centrality%d_%s_%s_%s", icent, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetLineWidth(2); + hEfficiencyPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetLineColor(multcentColor[icent]); + hEfficiencyPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetMarkerStyle(20); + hEfficiencyPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetMarkerColor(multcentColor[icent]); + hEfficiencyPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->Divide(hEfficiencyPt_MB[ihisto][ipart][icharge]); + hEfficiencyPt_ratioMB_centrality[icent][ihisto][ipart][icharge]->Write(); + } + + } + } + } + + fileout->Close(); + + TrackingEff_trackingEfficiency(str.Data()); +} + +//_____________________________________________________________________________- + +TrackingEff_efficiencyEta(const Char_t *filename) +{ + + /* get data */ + TFile *filein = TFile::Open(filename); + THnSparseF *hHisto[kNHistos][AliPID::kSPECIES][kNCharges]; + TH1D *hHistoEta_MB[kNHistos][AliPID::kSPECIES][kNCharges], *hHistoEta_centrality[NcentralityBins][kNHistos][AliPID::kSPECIES][kNCharges]; + TH1D *hHistoEta_MB_pt[NptsubBins][kNHistos][AliPID::kSPECIES][kNCharges], *hHistoEta_centrality_pt[NcentralityBins][NptsubBins][kNHistos][AliPID::kSPECIES][kNCharges]; + /* loop over histos */ + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + + /* get histo */ + hHisto[ihisto][ipart][icharge] = (THnSparseF *)filein->Get(Form("hHisto_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + + /* MB projection */ + hHisto[ihisto][ipart][icharge]->GetAxis(kPt)->SetRange(0, 0); + hHisto[ihisto][ipart][icharge]->GetAxis(kCentrality)->SetRange(0, 0); + hHistoEta_MB[ihisto][ipart][icharge] = hHisto[ihisto][ipart][icharge]->Projection(kEta); + hHistoEta_MB[ihisto][ipart][icharge]->SetName(Form("hHistoEta_MB_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hHistoEta_MB[ihisto][ipart][icharge]->Sumw2(); + /* pt bins */ + for (Int_t ipt = 0; ipt < NptsubBins; ipt++) { + hHisto[ihisto][ipart][icharge]->GetAxis(kPt)->SetRange(ptsubBinMin[ipt] + 1, ptsubBinMax[ipt] + 1); + hHisto[ihisto][ipart][icharge]->GetAxis(kCentrality)->SetRange(0, 0); + hHistoEta_MB_pt[ipt][ihisto][ipart][icharge] = hHisto[ihisto][ipart][icharge]->Projection(kEta); + hHistoEta_MB_pt[ipt][ihisto][ipart][icharge]->SetName(Form("hHistoEta_MB_pt%d_%s_%s_%s", ipt, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hHistoEta_MB_pt[ipt][ihisto][ipart][icharge]->Sumw2(); + } + + /* centrality projection */ + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + hHisto[ihisto][ipart][icharge]->GetAxis(kPt)->SetRange(0, 0); + hHisto[ihisto][ipart][icharge]->GetAxis(kCentrality)->SetRange(icent + 1, icent + 1); + hHistoEta_centrality[icent][ihisto][ipart][icharge] = hHisto[ihisto][ipart][icharge]->Projection(kEta); + hHistoEta_centrality[icent][ihisto][ipart][icharge]->SetName(Form("hHistoEta_centrality%d_%s_%s_%s", icent, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hHistoEta_centrality[icent][ihisto][ipart][icharge]->Sumw2(); + /* pt bins */ + for (Int_t ipt = 0; ipt < NptsubBins; ipt++) { + hHisto[ihisto][ipart][icharge]->GetAxis(kPt)->SetRange(ptsubBinMin[ipt] + 1, ptsubBinMax[ipt] + 1); + hHisto[ihisto][ipart][icharge]->GetAxis(kCentrality)->SetRange(icent + 1, icent + 1); + hHistoEta_centrality_pt[icent][ipt][ihisto][ipart][icharge] = hHisto[ihisto][ipart][icharge]->Projection(kEta); + hHistoEta_centrality_pt[icent][ipt][ihisto][ipart][icharge]->SetName(Form("hHistoEta_centrality%d_pt%d_%s_%s_%s", icent, ipt, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hHistoEta_centrality_pt[icent][ipt][ihisto][ipart][icharge]->Sumw2(); + } + } + } + + /* output */ + TString str = filename; + str.Insert(str.Length() - TString(".root").Length(), ".efficiencyEta"); + TFile *fileout = TFile::Open(str.Data(), "RECREATE"); + + /* efficiencies/fractions and write */ + TH1D *hEfficiencyEta_MB[kNHistos][AliPID::kSPECIES][kNCharges], *hEfficiencyEta_centrality[NcentralityBins][kNHistos][AliPID::kSPECIES][kNCharges], *hEfficiencyEta_ratioMB_centrality[NcentralityBins][kNHistos][AliPID::kSPECIES][kNCharges]; + TH1D *hEfficiencyEta_MB_pt[NptsubBins][kNHistos][AliPID::kSPECIES][kNCharges], *hEfficiencyEta_centrality_pt[NcentralityBins][NptsubBins][kNHistos][AliPID::kSPECIES][kNCharges], *hEfficiencyEta_ratioMB_centrality_pt[NcentralityBins][NptsubBins][kNHistos][AliPID::kSPECIES][kNCharges]; + + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) { + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + + if (ihisto == kPrimaryTracks) continue; + + /* MB efficiency */ + hEfficiencyEta_MB[ihisto][ipart][icharge] = new TH1D(*hHistoEta_MB[ihisto][ipart][icharge]); + hEfficiencyEta_MB[ihisto][ipart][icharge]->SetName(Form("hEfficiencyEta_MB_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyEta_MB[ihisto][ipart][icharge]->SetLineWidth(2); + hEfficiencyEta_MB[ihisto][ipart][icharge]->SetLineColor(1); + hEfficiencyEta_MB[ihisto][ipart][icharge]->SetMarkerStyle(20); + hEfficiencyEta_MB[ihisto][ipart][icharge]->SetMarkerColor(1); + hEfficiencyEta_MB[ihisto][ipart][icharge]->Divide(hEfficiencyEta_MB[ihisto][ipart][icharge], hHistoEta_MB[kPrimaryTracks][ipart][icharge], 1, 1, "B"); + hEfficiencyEta_MB[ihisto][ipart][icharge]->Write(); + /* pt bins */ + for (Int_t ipt = 0; ipt < NptsubBins; ipt++) { + hEfficiencyEta_MB_pt[ipt][ihisto][ipart][icharge] = new TH1D(*hHistoEta_MB_pt[ipt][ihisto][ipart][icharge]); + hEfficiencyEta_MB_pt[ipt][ihisto][ipart][icharge]->SetName(Form("hEfficiencyEta_MB_pt%d_%s_%s_%s", ipt, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyEta_MB_pt[ipt][ihisto][ipart][icharge]->SetLineWidth(2); + hEfficiencyEta_MB_pt[ipt][ihisto][ipart][icharge]->SetLineColor(1); + hEfficiencyEta_MB_pt[ipt][ihisto][ipart][icharge]->SetMarkerStyle(20); + hEfficiencyEta_MB_pt[ipt][ihisto][ipart][icharge]->SetMarkerColor(1); + hEfficiencyEta_MB_pt[ipt][ihisto][ipart][icharge]->Divide(hEfficiencyEta_MB_pt[ipt][ihisto][ipart][icharge], hHistoEta_MB_pt[ipt][kPrimaryTracks][ipart][icharge], 1, 1, "B"); + hEfficiencyEta_MB_pt[ipt][ihisto][ipart][icharge]->Write(); + } + + /* multiplicity/centrality efficiency */ + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + hEfficiencyEta_centrality[icent][ihisto][ipart][icharge] = new TH1D(*hHistoEta_centrality[icent][ihisto][ipart][icharge]); + hEfficiencyEta_centrality[icent][ihisto][ipart][icharge]->SetName(Form("hEfficiencyEta_centrality%d_%s_%s_%s", icent, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyEta_centrality[icent][ihisto][ipart][icharge]->SetLineWidth(2); + hEfficiencyEta_centrality[icent][ihisto][ipart][icharge]->SetLineColor(multcentColor[icent]); + hEfficiencyEta_centrality[icent][ihisto][ipart][icharge]->SetMarkerStyle(20); + hEfficiencyEta_centrality[icent][ihisto][ipart][icharge]->SetMarkerColor(multcentColor[icent]); + hEfficiencyEta_centrality[icent][ihisto][ipart][icharge]->Divide(hEfficiencyEta_centrality[icent][ihisto][ipart][icharge], hHistoEta_centrality[icent][kPrimaryTracks][ipart][icharge], 1, 1, "B"); + hEfficiencyEta_centrality[icent][ihisto][ipart][icharge]->Write(); + + /* ratio wrt. MB */ + hEfficiencyEta_ratioMB_centrality[icent][ihisto][ipart][icharge] = new TH1D(*hEfficiencyEta_centrality[icent][ihisto][ipart][icharge]); + hEfficiencyEta_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetName(Form("hEfficiencyEta_ratioMB_centrality%d_%s_%s_%s", icent, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyEta_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetLineWidth(2); + hEfficiencyEta_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetLineColor(multcentColor[icent]); + hEfficiencyEta_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetMarkerStyle(20); + hEfficiencyEta_ratioMB_centrality[icent][ihisto][ipart][icharge]->SetMarkerColor(multcentColor[icent]); + hEfficiencyEta_ratioMB_centrality[icent][ihisto][ipart][icharge]->Divide(hEfficiencyEta_MB[ihisto][ipart][icharge]); + hEfficiencyEta_ratioMB_centrality[icent][ihisto][ipart][icharge]->Write(); + } + + } + } + + fileout->Close(); + +} + +//_____________________________________________________________________________- + +TrackingEff_centralityDependence(const Char_t *filename) +{ + + Double_t fitMin[AliPID::kSPECIES] = {0.5, 0.5, 0.5, 0.5, 0.5}; + Double_t fitMax[AliPID::kSPECIES] = {3.0, 3.0, 3.0, 3.0, 5.0}; + + TF1 *pol0 = (TF1 *)gROOT->GetFunction("pol0"); + TF1 *pol1 = (TF1 *)gROOT->GetFunction("pol1"); + pol0->SetRange(0., 5.0); + TFile *filein = TFile::Open(filename); + + /* output */ + TString str = filename; + str.Insert(str.Length() - TString(".root").Length(), ".centralityDependence"); + TFile *fileout = TFile::Open(str.Data(), "RECREATE"); + + TH1D *hEfficiencyPt_ratioMB; + TH1D *hEfficiencyCentrality[kNHistos][AliPID::kSPECIES][kNCharges]; + TH1D *hChi2Centrality[kNHistos][AliPID::kSPECIES][kNCharges]; + TH1D *hEfficiencyAllCentrality[kNHistos]; + TH1F *hHistoEffRatio = new TH1F("hHistoEffRatio", "", 100, 0.5, 1.5); + for (Int_t ihisto = 0; ihisto < kNHistos; ihisto++) { + if (ihisto == kPrimaryTracks) continue; + + /* INCLUSIVE */ + + hEfficiencyAllCentrality[ihisto] = new TH1D(Form("hEfficiencyAllCentrality_ratioMB_%s", histoName[ihisto]), "", NcentralityBins, centralityBin); + hEfficiencyAllCentrality[ihisto]->SetLineWidth(2); + hEfficiencyAllCentrality[ihisto]->SetLineColor(1); + hEfficiencyAllCentrality[ihisto]->SetMarkerStyle(20); + hEfficiencyAllCentrality[ihisto]->SetMarkerColor(1); + + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + + hEfficiencyPt_ratioMB = (TH1D *)filein->Get(Form("hEfficiencyAllPt_ratioMB_centrality%d_%s", icent, histoName[ihisto])); + hEfficiencyPt_ratioMB->Fit(pol0, "q0", "", 0., 5.0); + hEfficiencyAllCentrality[ihisto]->SetBinContent(icent + 1, pol0->GetParameter(0)); + hEfficiencyAllCentrality[ihisto]->SetBinError(icent + 1, pol0->GetParError(0)); + hEfficiencyPt_ratioMB->Add(pol0, -1.); + hEfficiencyPt_ratioMB->Write(); + + } + hEfficiencyAllCentrality[ihisto]->Write(); + + + /* SINGLE PARTICLE */ + + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) { + + hEfficiencyCentrality[ihisto][ipart][icharge] = new TH1D(Form("hEfficiencyCentrality_ratioMB_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge]), "", NcentralityBins, centralityBin); + hEfficiencyCentrality[ihisto][ipart][icharge]->SetLineWidth(2); + hEfficiencyCentrality[ihisto][ipart][icharge]->SetLineColor(particleColor[ipart]); + hEfficiencyCentrality[ihisto][ipart][icharge]->SetMarkerStyle(chargeMarker[icharge]); + hEfficiencyCentrality[ihisto][ipart][icharge]->SetMarkerColor(particleColor[ipart]); + + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + + hEfficiencyPt_ratioMB = (TH1D *)filein->Get(Form("hEfficiencyPt_ratioMB_centrality%d_%s_%s_%s", icent, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + + hEfficiencyPt_ratioMB->Fit(pol0, "q0", "", fitMin[ipart], fitMax[ipart]); + hEfficiencyCentrality[ihisto][ipart][icharge]->SetBinContent(icent + 1, pol0->GetParameter(0)); + hEfficiencyCentrality[ihisto][ipart][icharge]->SetBinError(icent + 1, pol0->GetParError(0)); + pol0->SetRange(fitMin[ipart], fitMax[ipart]); + hEfficiencyPt_ratioMB->Add(pol0, -1.); + hEfficiencyPt_ratioMB->Write(); + + } + + hEfficiencyCentrality[ihisto][ipart][icharge]->Write(); + } + } + + fileout->Close(); +} + +//_____________________________________________________________________________- + +TrackingEff_centralityDependenceFit(const Char_t *filename, Int_t ihisto = kReconstructedTracks) +{ + + const Char_t *particleLabel[5][2] = {"", "", "", "", "#pi^{+}", "#pi^{-}", "K^{+}", "K^{-}", "p", "#bar{p}"}; + + TF1 *fCentralityDependence = new TF1("fCentralityDependence", "[0] + [1] * (1. - TMath::Exp(-x / [2]))", 0., 90.); + fCentralityDependence->SetParameter(0, 0.98); + fCentralityDependence->SetParameter(1, 0.05); + fCentralityDependence->SetParameter(2, 50.); + + TFile *filein = TFile::Open(filename); + TH1D *hEfficiencyAllCentrality; + TH1D *hEfficiencyCentrality[AliPID::kSPECIES][kNCharges]; + hEfficiencyAllCentrality = (TH1D *)filein->Get(Form("hEfficiencyAllCentrality_ratioMB_%s", histoName[ihisto])); + TCanvas *cFit = new TCanvas("cFit"); + hEfficiencyAllCentrality->Fit(fCentralityDependence); + hEfficiencyAllCentrality->SetMaximum(1.05); + hEfficiencyAllCentrality->SetMinimum(0.95); + TCanvas *cRatios = new TCanvas("cRatios"); + cRatios->Divide(2, 3); + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) { + for (Int_t icharge = 0; icharge < 2; icharge++) { + cRatios->cd(icharge + 1 + 2 * (ipart - 2)); + cRatios->cd(icharge + 1 + 2 * (ipart - 2))->SetGridx(); + cRatios->cd(icharge + 1 + 2 * (ipart - 2))->SetGridy(); + hEfficiencyCentrality[ipart][icharge] = (TH1D *)filein->Get(Form("hEfficiencyCentrality_ratioMB_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyCentrality[ipart][icharge]->Divide(fCentralityDependence); + hEfficiencyCentrality[ipart][icharge]->SetMaximum(1.05); + hEfficiencyCentrality[ipart][icharge]->SetMinimum(0.95); + hEfficiencyCentrality[ipart][icharge]->SetTitle(Form("%s;centrality percentile;efficiency ratio wrt. fitted centrality dependence", particleLabel[ipart][icharge])); + hEfficiencyCentrality[ipart][icharge]->SetStats(kFALSE); + hEfficiencyCentrality[ipart][icharge]->Draw(); + } + } + + +} + + +//_____________________________________________________________________________- + +TrackingEff_efficiencyPt_MB_plot(const Char_t *filename) +{ + TrackingEff_efficiencyPt_MB_plot(filename, kReconstructedTracks, 2, 0, 20, 4); + TrackingEff_efficiencyPt_MB_plot(filename, kReconstructedTracks, 2, 1, 25, 4); + TrackingEff_efficiencyPt_MB_plot(filename, kReconstructedTracks, 3, 0, 20, 8); + TrackingEff_efficiencyPt_MB_plot(filename, kReconstructedTracks, 3, 1, 25, 8); + TrackingEff_efficiencyPt_MB_plot(filename, kReconstructedTracks, 4, 0, 20, 2); + TrackingEff_efficiencyPt_MB_plot(filename, kReconstructedTracks, 4, 1, 25, 2); +} + +TH1D * +TrackingEff_efficiencyPt_MB_plot(const Char_t *filename, Int_t ihisto = kReconstructedTracks, Int_t ipart, Int_t icharge, Int_t marker = 20, Int_t color = 2, Option_t *opt = "") +{ + + TCanvas *cCanvas1 = new TCanvas("cCanvas1"); + TCanvas *cCanvas2 = new TCanvas("cCanvas2"); + + Double_t ptMin[AliPID::kSPECIES] = {0.5, 0.5, 0.5, 0.5, 0.5}; + Double_t ptMax[AliPID::kSPECIES] = {3.0, 3.0, 3.0, 3.0, 5.0}; + + TF1 *fEff = new TF1("fEff", "[0] + [1] * x - [2] * TMath::Exp(-[3] * TMath::Power(x, [4]))", 0.5, 5.0); + fEff->SetParameter(0, 0.8); + fEff->SetParameter(1, -0.01); + fEff->SetParameter(2, 2.0); + fEff->SetParameter(3, 1.); + fEff->SetParameter(4, 2.); + + TFile *fileout = TFile::Open(Form("%s/efficiencyPt_MB_%s_%s.root", destdir, AliPID::ParticleName(ipart), chargeName[icharge]), "RECREATE"); + + TFile *filein = TFile::Open(filename); + TH1D *hEfficiencyPt = (TH1D *)filein->Get(Form("hEfficiencyPt_MB_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyPt->Fit(fEff, "0", "IME", 0.5, 5.0); + hEfficiencyPt->SetTitle(Form("%s;p_{T} (GeV/c);acceptance #times efficiency;", partChargeName[ipart][icharge])); + hEfficiencyPt->SetMinimum(0.4); + hEfficiencyPt->SetMaximum(0.8); + hEfficiencyPt->SetMarkerStyle(marker); + hEfficiencyPt->SetMarkerColor(color); + hEfficiencyPt->SetMarkerSize(1.5); + hEfficiencyPt->SetLineWidth(2); + hEfficiencyPt->SetLineColor(color); + hEfficiencyPt->GetXaxis()->SetRangeUser(ptMin[ipart] + 0.001, ptMax[ipart] - 0.001); + hEfficiencyPt->SetStats(kFALSE); + cCanvas1->cd(); + hEfficiencyPt->DrawCopy(); + fEff->DrawCopy("same"); + fileout->cd(); + hEfficiencyPt->Write("hEfficiencyPt"); + fEff->Write("fEff"); + + cCanvas1->SetGridx(); + cCanvas1->SetGridy(); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_%s_%s.C", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_%s_%s.png", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_%s_%s.eps", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + + TH1D *hRatioPt = new TH1D(*hEfficiencyPt); + hRatioPt->Divide(fEff); + hRatioPt->SetTitle(Form("%s;p_{T} (GeV/c);ratio wrt. fitted dependence;", partChargeName[ipart][icharge])); + hRatioPt->SetMinimum(0.9); + hRatioPt->SetMaximum(1.1); + cCanvas2->cd(); + hRatioPt->DrawCopy(); + fileout->cd(); + hRatioPt->Write("hRatioPt"); + + cCanvas2->SetGridx(); + cCanvas2->SetGridy(); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_%s_%s.C", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_%s_%s.png", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_%s_%s.eps", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + + + fileout->Close(); + + // hEfficiencyPt->Add(fEff, -1.); + return hEfficiencyPt; +} + +//_____________________________________________________________________________- + +TH1D * +TrackingEff_efficiencyPt_centrality_all_plot(const Char_t *filename, Int_t ihisto = kReconstructedTracks, Int_t marker = 20, Int_t color = 1, Option_t *opt = "") +{ + + TCanvas *cCanvas1 = new TCanvas("cCanvas1"); + TCanvas *cCanvas2 = new TCanvas("cCanvas2"); + + Double_t ptMin[AliPID::kSPECIES] = {0.5, 0.5, 0.5, 0.5, 0.5}; + Double_t ptMax[AliPID::kSPECIES] = {3.0, 3.0, 3.0, 3.0, 5.0}; + + TF1 *fEff = new TF1("fEff", "[5] * ([0] + [1] * x - [2] * TMath::Exp(-[3] * TMath::Power(x, [4])))", 0.5, 5.0); + fEff->SetParameter(0, 0.8); + fEff->SetParameter(1, -0.01); + fEff->SetParameter(2, 2.0); + fEff->SetParameter(3, 1.); + fEff->SetParameter(4, 2.); + fEff->FixParameter(5, 1.); + + TFile *fileout = TFile::Open(Form("%s/efficiencyPt_MB_all.root", destdir), "RECREATE"); + + TFile *filein = TFile::Open(filename); + TH1D *hEfficiencyPt = (TH1D *)filein->Get(Form("hEfficiencyAllPt_MB_%s", histoName[ihisto])); + hEfficiencyPt->Fit(fEff, "0", "IME", 0.5, 5.0); + hEfficiencyPt->SetTitle("all particles;p_{T} (GeV/c);acceptance #times efficiency;"); + hEfficiencyPt->SetMinimum(0.4); + hEfficiencyPt->SetMaximum(0.8); + hEfficiencyPt->SetMarkerStyle(marker); + hEfficiencyPt->SetMarkerColor(color); + hEfficiencyPt->SetMarkerSize(1.5); + hEfficiencyPt->SetLineWidth(2); + hEfficiencyPt->SetLineColor(color); + hEfficiencyPt->GetXaxis()->SetRangeUser(0.5 + 0.001, 5.0 - 0.001); + hEfficiencyPt->SetStats(kFALSE); + cCanvas1->cd(); + hEfficiencyPt->DrawCopy(); + fEff->DrawCopy("same"); + fileout->cd(); + hEfficiencyPt->Write("hEfficiencyPt"); + fEff->Write("fEff"); + + cCanvas1->SetGridx(); + cCanvas1->SetGridy(); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_all.C", destdir)); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_all.png", destdir)); + cCanvas1->SaveAs(Form("%s/efficiencyPt_MB_all.eps", destdir)); + + TH1D *hRatioPt = new TH1D(*hEfficiencyPt); + hRatioPt->Divide(fEff); + hRatioPt->SetTitle("all particles;p_{T} (GeV/c);ratio wrt. fitted dependence;"); + hRatioPt->SetMinimum(0.9); + hRatioPt->SetMaximum(1.1); + cCanvas2->cd(); + hRatioPt->DrawCopy(); + fileout->cd(); + hRatioPt->Write("hRatioPt"); + + cCanvas2->SetGridx(); + cCanvas2->SetGridy(); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_all.C", destdir)); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_all.png", destdir)); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_MB_all.eps", destdir)); + + /* fix efficiency shape and release scale factor */ + fEff->FixParameter(0, fEff->GetParameter(0)); + fEff->FixParameter(1, fEff->GetParameter(1)); + fEff->FixParameter(2, fEff->GetParameter(2)); + fEff->FixParameter(3, fEff->GetParameter(3)); + fEff->FixParameter(4, fEff->GetParameter(4)); + fEff->ReleaseParameter(5); + + TH1D *hEfficiencyCent = new TH1D("hEfficiencyCent", "all particles;centrality percentile;acceptance x efficiency scale factor;", NcentralityBins, centralityBin); + hEfficiencyCent->SetMinimum(0.95); + hEfficiencyCent->SetMaximum(1.05); + hEfficiencyCent->SetMarkerStyle(marker); + hEfficiencyCent->SetMarkerColor(color); + hEfficiencyCent->SetMarkerSize(1.5); + hEfficiencyCent->SetLineWidth(2); + hEfficiencyCent->SetLineColor(color); + hEfficiencyCent->SetStats(kFALSE); + + + TH1D *hEfficiencyPt_cent[NcentralityBins]; + TH1D *hRatioPt_cent[NcentralityBins]; + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + + + hEfficiencyPt_cent[icent] = (TH1D *)filein->Get(Form("hEfficiencyAllPt_centrality%d_%s", icent, histoName[ihisto])); + hEfficiencyPt_cent[icent]->Fit(fEff, "0", "IME", 1.0, 3.0); + hEfficiencyPt_cent[icent]->Fit(fEff, "", "IME", 0.5, 5.0); + + hEfficiencyPt_cent[icent]->SetTitle(Form("all particles (%d-%d\%);p_{T} (GeV/c);acceptance #times efficiency;", (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1])); + hEfficiencyPt_cent[icent]->SetMinimum(0.2); + hEfficiencyPt_cent[icent]->SetMaximum(0.8); + hEfficiencyPt_cent[icent]->SetMarkerStyle(marker); + hEfficiencyPt_cent[icent]->SetMarkerColor(color); + hEfficiencyPt_cent[icent]->SetMarkerSize(1.5); + hEfficiencyPt_cent[icent]->SetLineWidth(2); + hEfficiencyPt_cent[icent]->SetLineColor(color); + hEfficiencyPt_cent[icent]->GetXaxis()->SetRangeUser(0.5 + 0.001, 5.0 - 0.001); + hEfficiencyPt_cent[icent]->SetStats(kFALSE); + cCanvas1->cd(); + hEfficiencyPt_cent[icent]->DrawCopy(); + fEff->DrawCopy("same"); + fileout->cd(); + hEfficiencyPt_cent[icent]->Write(Form("hEfficiencyPt_cent%d", icent)); + fEff->Write(Form("fEff_cent%d", icent)); + + hEfficiencyCent->SetBinContent(icent + 1, fEff->GetParameter(5)); + hEfficiencyCent->SetBinError(icent + 1, fEff->GetParError(5)); + + cCanvas1->SetGridx(); + cCanvas1->SetGridy(); + cCanvas1->SaveAs(Form("%s/efficiencyPt_centrality%d_all.C", destdir, icent)); + cCanvas1->SaveAs(Form("%s/efficiencyPt_centrality%d_all.png", destdir, icent)); + cCanvas1->SaveAs(Form("%s/efficiencyPt_centrality%d_all.eps", destdir, icent)); + + hRatioPt_cent[icent] = new TH1D(*hEfficiencyPt_cent[icent]); + hRatioPt_cent[icent]->Divide(fEff); + hRatioPt_cent[icent]->SetTitle(Form("all particles (%d-%d\%);p_{T} (GeV/c);ratio wrt. fitted dependence;", (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1])); + hRatioPt_cent[icent]->SetMinimum(0.9); + hRatioPt_cent[icent]->SetMaximum(1.1); + cCanvas2->cd(); + hRatioPt_cent[icent]->DrawCopy(); + fileout->cd(); + hRatioPt_cent[icent]->Write(Form("hRatio_cent%d", icent)); + + cCanvas2->SetGridx(); + cCanvas2->SetGridy(); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_centrality%d_all.C", destdir, icent)); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_centrality%d_all.png", destdir, icent)); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_centrality%d_all.eps", destdir, icent)); + + + } + + TF1 *fEffCent = new TF1("fEffCent", "[0] - [1] * TMath::Exp(-[2] * TMath::Power(x, [3]))", 0., 90.); + fEffCent->SetParameter(0, 1.02); + fEffCent->SetParameter(1, 0.04); + fEffCent->SetParameter(2, 0.001); + fEffCent->SetParameter(3, 2.); + hEfficiencyCent->Fit(fEffCent, "q0", "IME", 0., 90.); + + TCanvas *cCanvas3 = new TCanvas("cCanvas3"); + hEfficiencyCent->DrawCopy(); + fEffCent->DrawCopy("same"); + fileout->cd(); + hEfficiencyCent->Write("hEfficiencyCent"); + fEffCent->Write("fEffCent"); + + cCanvas3->SetGridx(); + cCanvas3->SetGridy(); + cCanvas3->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_all.C", destdir)); + cCanvas3->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_all.png", destdir)); + cCanvas3->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_all.eps", destdir)); + + TCanvas *cCanvas4 = new TCanvas("cCanvas4"); + + TH1D *hRatioCent = new TH1D(*hEfficiencyCent); + hRatioCent->Divide(fEffCent); + hRatioCent->SetTitle(Form("all particles;centrality percentile;ratio wrt. fitted dependence;")); + hRatioCent->SetMinimum(0.95); + hRatioCent->SetMaximum(1.05); + cCanvas4->cd(); + hRatioCent->DrawCopy(); + fileout->cd(); + hRatioCent->Write("hRatioCent"); + + cCanvas4->SetGridx(); + cCanvas4->SetGridy(); + cCanvas4->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_ratioFit_all.C", destdir)); + cCanvas4->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_ratioFit_all.png", destdir)); + cCanvas4->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_ratioFit_all.eps", destdir)); + + fileout->Close(); + + // hEfficiencyPt->Add(fEff, -1.); + return hEfficiencyCent; +} + + +//_____________________________________________________________________________- + +TrackingEff_efficiencyPt_centrality_plot(const Char_t *filename) +{ + TrackingEff_efficiencyPt_centrality_plot(filename, kReconstructedTracks, 2, 0, 20, 4); + TrackingEff_efficiencyPt_centrality_plot(filename, kReconstructedTracks, 2, 1, 25, 4); + TrackingEff_efficiencyPt_centrality_plot(filename, kReconstructedTracks, 3, 0, 20, 8); + TrackingEff_efficiencyPt_centrality_plot(filename, kReconstructedTracks, 3, 1, 25, 8); + TrackingEff_efficiencyPt_centrality_plot(filename, kReconstructedTracks, 4, 0, 20, 2); + TrackingEff_efficiencyPt_centrality_plot(filename, kReconstructedTracks, 4, 1, 25, 2); +} + +TH1D * +TrackingEff_efficiencyPt_centrality_plot(const Char_t *filename, Int_t ihisto = kReconstructedTracks, Int_t ipart, Int_t icharge, Int_t marker = 20, Int_t color = 2, Option_t *opt = "") +{ + + TVirtualFitter::SetMaxIterations(1000000); + + /* load HistoUtils */ + gROOT->LoadMacro("HistoUtils.C"); + + TCanvas *cCanvas1 = new TCanvas("cCanvas1"); + TCanvas *cCanvas2 = new TCanvas("cCanvas2"); + TCanvas *cCanvas5 = new TCanvas("cCanvas5"); + + Double_t ptMin[AliPID::kSPECIES] = {0.5, 0.5, 0.5, 0.5, 0.5}; + Double_t ptMax[AliPID::kSPECIES] = {3.0, 3.0, 3.0, 3.0, 5.0}; + + /* fit minimum-bias efficiency pt */ + + TF1 *fEff = new TF1("fEff", "([0] * TMath::Exp(-TMath::Power([1] / x, [2])) + [3] * x) * TMath::Exp(TMath::Power([4] / x, [5]))", ptMin[ipart], ptMax[ipart]); + fEff->SetParameter(0, 0.5); + fEff->SetParameter(1, 0.1); + fEff->SetParameter(2, 2.); + fEff->SetParameter(3, 0.); + fEff->SetParameter(4, 0.001); + fEff->SetParameter(5, 1.); + Int_t nPars = fEff->GetNpar(); + Int_t scalePar = 0.; + TF1 *fEffCopy = new TF1(*fEff); + + TFile *fileout = TFile::Open(Form("%s/efficiencyPt_centrality_%s_%s.root", destdir, AliPID::ParticleName(ipart), chargeName[icharge]), "RECREATE"); + + TFile *filein = TFile::Open(filename); + TH1D *hEfficiencyPt = (TH1D *)filein->Get(Form("hEfficiencyPt_MB_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyPt->Fit(fEff, "0", "IMRE", ptMin[ipart], ptMax[ipart]); + + /* build efficiency profile */ + for (Int_t ipar = 0; ipar < nPars; ipar++) { + fEffCopy->SetParameter(ipar, fEff->GetParameter(ipar)); + fEffCopy->SetParError(ipar, fEff->GetParError(ipar)); + } + TProfile *pEfficiencyPt = new TProfile(Form("pEfficiencyPt_MB_%s_%s_%s", histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge]), Form("%s;p_{T} (GeV/c);acceptance #times efficiency;", partChargeName[ipart][icharge]), NptBins, ptBin, "s"); + HistoUtils_Function2Profile(fEffCopy, pEfficiencyPt); + + /* draw */ + cCanvas1->cd(); + pEfficiencyPt->SetMarkerStyle(marker); + pEfficiencyPt->SetMarkerColor(color); + pEfficiencyPt->SetMarkerSize(0); + pEfficiencyPt->SetLineWidth(2); + pEfficiencyPt->SetLineColor(color); + pEfficiencyPt->SetFillStyle(3001); + pEfficiencyPt->SetFillColor(color); + pEfficiencyPt->GetXaxis()->SetRangeUser(ptMin[ipart] + 0.001, ptMax[ipart] - 0.001); + pEfficiencyPt->SetStats(kFALSE); + pEfficiencyPt->DrawCopy("E2"); + + hEfficiencyPt->SetTitle(Form("%s;p_{T} (GeV/c);acceptance #times efficiency;", partChargeName[ipart][icharge])); + hEfficiencyPt->SetMarkerStyle(marker); + hEfficiencyPt->SetMarkerColor(color); + hEfficiencyPt->SetMarkerSize(1.5); + hEfficiencyPt->SetLineWidth(2); + hEfficiencyPt->SetLineColor(color); + hEfficiencyPt->GetXaxis()->SetRangeUser(ptMin[ipart] + 0.001, ptMax[ipart] - 0.001); + hEfficiencyPt->SetStats(kFALSE); + hEfficiencyPt->DrawCopy("same"); + fEff->DrawCopy("same"); + cCanvas1->Update(); + + /* write */ + fileout->cd(); + pEfficiencyPt->Write("pEfficiencyPt"); + hEfficiencyPt->Write("hEfficiencyPt"); + fEff->Write("fEff"); + + TH1D *hEfficiencyCent = new TH1D("hEfficiencyCent", Form("%s;centrality percentile;acceptance x efficiency scale factor;", partChargeName[ipart][icharge]), NcentralityBins, centralityBin); + hEfficiencyCent->SetMinimum(0.9); + hEfficiencyCent->SetMaximum(1.1); + hEfficiencyCent->SetMarkerStyle(marker); + hEfficiencyCent->SetMarkerColor(color); + hEfficiencyCent->SetMarkerSize(1.5); + hEfficiencyCent->SetLineWidth(2); + hEfficiencyCent->SetLineColor(color); + hEfficiencyCent->SetStats(kFALSE); + + TProfile *pEfficiencyPt_cent[NcentralityBins]; + TH1D *hEfficiencyPt_cent[NcentralityBins]; + TH1D *hRatioPt_cent[NcentralityBins]; + + /* fix efficiency shape and release scale factor */ + for (Int_t ipar = 0; ipar < nPars; ipar++) + fEff->FixParameter(ipar, fEff->GetParameter(ipar)); + fEff->ReleaseParameter(scalePar); + + gStyle->SetOptStat(1100); + for (Int_t icent = 0; icent < NcentralityBins; icent++) { + + hEfficiencyPt_cent[icent] = (TH1D *)filein->Get(Form("hEfficiencyPt_centrality%d_%s_%s_%s", icent, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge])); + hEfficiencyPt_cent[icent]->Fit(fEff, "", "IME", ptMin[ipart], ptMax[ipart]); + + /* build efficiency profile */ + fEffCopy->SetParameter(scalePar, fEff->GetParameter(scalePar)); + fEffCopy->SetParError(scalePar, fEff->GetParError(scalePar)); + pEfficiencyPt_cent[icent] = new TProfile(Form("pEfficiencyPt_centrality%d_%s_%s_%s", icent, histoName[ihisto], AliPID::ParticleName(ipart), chargeName[icharge]), Form("%s;p_{T} (GeV/c);acceptance #times efficiency;", partChargeName[ipart][icharge]), NptBins, ptBin, "s"); + HistoUtils_Function2Profile(fEffCopy, pEfficiencyPt_cent[icent]); + + /* draw */ + cCanvas1->cd(); + pEfficiencyPt_cent[icent]->SetMarkerStyle(marker); + pEfficiencyPt_cent[icent]->SetMarkerColor(color); + pEfficiencyPt_cent[icent]->SetMarkerSize(0); + pEfficiencyPt_cent[icent]->SetLineWidth(2); + pEfficiencyPt_cent[icent]->SetLineColor(color); + pEfficiencyPt_cent[icent]->SetFillStyle(3001); + pEfficiencyPt_cent[icent]->SetFillColor(color); + pEfficiencyPt_cent[icent]->GetXaxis()->SetRangeUser(ptMin[ipart] + 0.001, ptMax[ipart] - 0.001); + pEfficiencyPt_cent[icent]->SetStats(kFALSE); + pEfficiencyPt_cent[icent]->DrawCopy("E2"); + + hEfficiencyPt_cent[icent]->SetTitle(Form("%s (%d-%d\%);p_{T} (GeV/c);acceptance #times efficiency;", partChargeName[ipart][icharge], (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1])); + hEfficiencyPt_cent[icent]->SetMarkerStyle(marker); + hEfficiencyPt_cent[icent]->SetMarkerColor(color); + hEfficiencyPt_cent[icent]->SetMarkerSize(1.5); + hEfficiencyPt_cent[icent]->SetLineWidth(2); + hEfficiencyPt_cent[icent]->SetLineColor(color); + hEfficiencyPt_cent[icent]->GetXaxis()->SetRangeUser(ptMin[ipart] + 0.001, ptMax[ipart] - 0.001); + hEfficiencyPt_cent[icent]->SetStats(kFALSE); + hEfficiencyPt_cent[icent]->DrawCopy("same"); + fEff->DrawCopy("same"); + cCanvas1->Update(); + + fileout->cd(); + pEfficiencyPt_cent[icent]->Write(Form("pEfficiencyPt_cent%d", icent)); + hEfficiencyPt_cent[icent]->Write(Form("hEfficiencyPt_cent%d", icent)); + fEff->Write(Form("fEff_cent%d", icent)); + + hEfficiencyCent->SetBinContent(icent + 1, fEff->GetParameter(5)); + hEfficiencyCent->SetBinError(icent + 1, fEff->GetParError(5)); + + cCanvas1->SetGridx(); + cCanvas1->SetGridy(); + cCanvas1->SaveAs(Form("%s/efficiencyPt_centrality%d_%s_%s.C", destdir, icent, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas1->SaveAs(Form("%s/efficiencyPt_centrality%d_%s_%s.png", destdir, icent, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas1->SaveAs(Form("%s/efficiencyPt_centrality%d_%s_%s.eps", destdir, icent, AliPID::ParticleName(ipart), chargeName[icharge])); + + hRatioPt_cent[icent] = new TH1D(*hEfficiencyPt_cent[icent]); + hRatioPt_cent[icent]->Divide(fEff); + hRatioPt_cent[icent]->SetTitle(Form("%s (%d-%d\%);p_{T} (GeV/c);ratio wrt. fitted dependence;", partChargeName[ipart][icharge], (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1])); + hRatioPt_cent[icent]->SetMinimum(0.75); + hRatioPt_cent[icent]->SetMaximum(1.25); + cCanvas2->cd(); + hRatioPt_cent[icent]->DrawCopy(); + fileout->cd(); + hRatioPt_cent[icent]->Write(Form("hRatioPt_cent%d", icent)); + + + cCanvas2->SetGridx(); + cCanvas2->SetGridy(); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_centrality%d_%s_%s.C", destdir, icent, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_centrality%d_%s_%s.png", destdir, icent, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas2->SaveAs(Form("%s/efficiencyPt_ratioFit_centrality%d_%s_%s.eps", destdir, icent, AliPID::ParticleName(ipart), chargeName[icharge])); + + } + + TCanvas *cCanvas3 = new TCanvas("cCanvas3"); + hEfficiencyCent->DrawCopy(); + fileout->cd(); + hEfficiencyCent->Write("hEfficiencyCent"); + + cCanvas3->SetGridx(); + cCanvas3->SetGridy(); + cCanvas3->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_%s_%s.C", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas3->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_%s_%s.png", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + cCanvas3->SaveAs(Form("%s/efficiencyCentrality_scaleFactor_%s_%s.eps", destdir, AliPID::ParticleName(ipart), chargeName[icharge])); + + // hEfficiencyPt->Add(fEff, -1.); + return hEfficiencyCent; +} + +TrackingEff_trackingEfficiency(const Char_t *filename, Bool_t useGFcorrection =kTRUE) +{ + + Int_t marker[2] = {20, 21}; + Int_t color[AliPID::kSPECIES] = {1, 1, 4, 8, 2}; + Char_t *partLatex[AliPID::kSPECIES][2] = { + "", "", "#pi^{+}", "K^{+}", "p", + "", "", "#pi^{-}", "K^{-}", "#bar{p}" + }; + + TFile *filein = TFile::Open(filename); + if (useGFcorrection) + TFile *fileout = TFile::Open("TOF_trackingEfficiency.root", "RECREATE"); + else + TFile *fileout = TFile::Open("TOF_trackingEfficiency_noGF.root", "RECREATE"); + TH1D *hEff; + TF1 *fGF; + Char_t title[1024]; + for (Int_t icent = -1; icent < NcentralityBins; icent++) + for (Int_t icharge = 0; icharge < kNCharges; icharge++) + for (Int_t ipart = 2; ipart < AliPID::kSPECIES; ipart++) { + if (icent == -1) + hEff = (TH1D *)filein->Get(Form("hEfficiencyPt_MB_hReconstructedTracks_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + else + hEff = (TH1D *)filein->Get(Form("hEfficiencyPt_centrality%d_hReconstructedTracks_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + /* geant-fluka correction */ + fGF = TrackingEff_geantflukaCorrection(ipart, icharge); + if (useGFcorrection) + hEff->Divide(fGF); + if (icent == -1) + sprintf(title, "%s (MB);p_{T} (GeV/c);tracking efficiency;", partLatex[ipart][icharge]); + else + sprintf(title, "%s (%d-%d%%);p_{T} (GeV/c);tracking efficiency;", partLatex[ipart][icharge], (Int_t)centralityBin[icent], (Int_t)centralityBin[icent + 1]); + hEff->SetMarkerStyle(marker[icharge]); + hEff->SetMarkerColor(color[ipart]); + hEff->SetLineColor(1); + hEff->SetLineWidth(1); + hEff->SetTitle(title); + if (icent == -1) + hEff->SetName(Form("hTrackingEff_MB_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge])); + else + hEff->SetName(Form("hTrackingEff_cent%d_%s_%s", icent, AliPID::ParticleName(ipart), chargeName[icharge])); + fileout->cd(); + hEff->Write(); + } + + fileout->Close(); +} + +TF1 * +TrackingEff_geantflukaCorrection(Int_t ipart, Int_t icharge) +{ + + if (ipart == 3 && icharge == kNegative) { + TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge]), "TrackingPtGeantFlukaCorrectionKaMinus(x)", 0., 5.); + return f; + } + // else if (ipart == 4 && icharge == kNegative) { + // TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge]), "TrackingPtGeantFlukaCorrectionPrMinus(x)", 0., 5.); + // } + else + TF1 *f = new TF1(Form("fGeantFluka_%s_%s", AliPID::ParticleName(ipart), chargeName[icharge]), "TrackingPtGeantFlukaCorrectionNull(x)", 0., 5.); + + return f; +} + +Double_t +TrackingPtGeantFlukaCorrectionNull(Double_t pTmc) +{ + return 1.; +} + +Double_t +TrackingPtGeantFlukaCorrectionPrMinus(Double_t pTmc) +{ + return (1 - 0.129758 *TMath::Exp(-pTmc*0.679612)); +} + +Double_t +TrackingPtGeantFlukaCorrectionKaMinus(Double_t pTmc) +{ + return TMath::Min((0.972865 + 0.0117093*pTmc), 1.); +} diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TrackingEff.sh b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TrackingEff.sh new file mode 100755 index 00000000000..420fb729d90 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/TrackingEff.sh @@ -0,0 +1,9 @@ +#! /bin/bash + +if [ "$1" == "" ]; then + echo "argument needed" + exit 1 +fi +echo "launching TrackingEff on $1 in background" +aliroot -b -q "TrackingEff.C(\"$1\")" &> TrackingEff.$1.log & +echo "TrackingEff started" \ No newline at end of file diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/defaultFit.C b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/defaultFit.C new file mode 100644 index 00000000000..6528b06a072 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/defaultFit.C @@ -0,0 +1,7 @@ +defaultFit(const Char_t *filename, Int_t ipart, Int_t icharge, Int_t iipart, Int_t icent) +{ + gROOT->LoadMacro("TOFpid.C"); + TOFspectrum(filename, ipart, icharge, iipart, icent); + TOFpid_rawSpectra(); + TOFpid_rawSpectra_mismatchCorrected(); +} diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/defaultFit.sh b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/defaultFit.sh new file mode 100755 index 00000000000..b18e0b2c481 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/defaultFit.sh @@ -0,0 +1,26 @@ +#! /bin/bash + +if [ "$1" == "" ]; then + echo "argument required" + exit 1 +fi + +echo creating merged file: $1 +ls TOFpid_*.root | tee list +aliroot -b -q "merger.C(\"list\", \"$1\", kFALSE)" + + + +for ((icent = -1; icent < 7; icent++ )); do + for (( icharge = 0; icharge < 2; icharge++ )); do + for (( ipart = 2; ipart < 5; ipart++ )); do + echo "*** START FITTING ***" + echo "icent = $icent" + echo "ipart = $ipart" + echo "icharge = $icharge" + aliroot -b -q "defaultFit.C(\"$1\", $ipart, $icharge, $ipart, $icent)" &> defaultFit.$ipart.$icharge.$icent.$ipart.log & + done + done + wait +done + diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/mcSpectra.C b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/mcSpectra.C new file mode 100644 index 00000000000..737b67cf55e --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/mcSpectra.C @@ -0,0 +1,41 @@ +Char_t *partname[3] = {"pion", "kaon", "proton"}; +Char_t *chargename[2] = {"positive", "negative"}; +Char_t *chargename2[2] = {"plus", "minus"}; + +mcSpectra(Char_t *filename) +{ + + TFile *fin = TFile::Open(filename); + TH1D *hspectrumMB[3][2]; + TH1D *hspectrumCent[3][2][6]; + TH1 *h; + THnSparseF *hsparse; + TFile *fout = TFile::Open("mcSpectra.root", "RECREATE"); + + for (Int_t ipart = 0; ipart < 3; ipart++) + for (Int_t icharge = 0; icharge < 2; icharge++) { + hsparse = (THnSparseF *)fin->Get(Form("hHisto_hPrimaryTracks_%s_%s", partname[ipart], chargename[icharge])); + h = hsparse->Projection(1); + h->SetName(Form("mb_%s_%s", partname[ipart], chargename2[icharge])); + h->Sumw2(); + for (Int_t ipt = 0; ipt < h->GetNbinsX(); ipt++) { + h->SetBinContent(ipt + 1, h->GetBinContent(ipt + 1) / h->GetBinWidth(ipt + 1)); + h->SetBinError(ipt + 1, h->GetBinError(ipt + 1) / h->GetBinWidth(ipt + 1)); + } + fout->cd(); + h->Write(); + for (Int_t icent = 0; icent < 6; icent++) { + hsparse->GetAxis(0)->SetRange(icent + 1, icent + 1); + h = hsparse->Projection(1); + h->SetName(Form("cent%d_%s_%s", icent, partname[ipart], chargename2[icharge])); + h->Sumw2(); + for (Int_t ipt = 0; ipt < h->GetNbinsX(); ipt++) { + h->SetBinContent(ipt + 1, h->GetBinContent(ipt + 1) / h->GetBinWidth(ipt + 1)); + h->SetBinError(ipt + 1, h->GetBinError(ipt + 1) / h->GetBinWidth(ipt + 1)); + } + fout->cd(); + h->Write(); + } + } + +} diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/merger.C b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/merger.C new file mode 100644 index 00000000000..e81d223e37a --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/macros/merger.C @@ -0,0 +1,30 @@ +merger(const Char_t *filelist, const Char_t *output, Bool_t alien = kFALSE) +{ + + gSystem->Setenv("TMPDIR", gSystem->pwd()); + if (alien) TGrid::Connect("alien"); + + ifstream filein(filelist); + Int_t nfiles = 0; + Char_t filename[4096]; + TFileMerger m(kFALSE); + m.OutputFile(output); + + while(1) { + filein.getline(filename, 4096); + if (filein.eof()) break; + if (alien) sprintf(filename, "alien://%s", filename); + printf("adding file: %s\n", filename); + if (m.AddFile(filename)) { + printf("file %s successfully added\n", filename); + nfiles++; + } + } + + printf("start merging %d files\n", nfiles); + m.Merge(); + printf("%d files merged: %s\n", nfiles, output); + + /* create dummy file to tell we are done */ + gSystem->Exec("touch done"); +} diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AddAnalysisTaskTOFSpectraPbPb.C b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AddAnalysisTaskTOFSpectraPbPb.C new file mode 100644 index 00000000000..a253aaa51fe --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AddAnalysisTaskTOFSpectraPbPb.C @@ -0,0 +1,86 @@ +AliAnalysisTaskTOFSpectraPbPb * +AddAnalysisTaskTOFSpectraPbPb(Bool_t mcFlag = kFALSE, Bool_t mcTuneFlag = kFALSE, Bool_t pbpbFlag = kFALSE) +{ + + /* check analysis manager */ + AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); + if (!mgr) { + Error("AddAnalysisTaskTOFSpectraPbPb", "cannot get analysis manager"); + return NULL; + } + + /* check input event handler */ + if (!mgr->GetInputEventHandler()) { + Error("AddAnalysisTaskTOFSpectraPbPb", "cannot get input event handler"); + return NULL; + } + + /* check input data type */ + TString str = mgr->GetInputEventHandler()->GetDataType(); + if (str.CompareTo("ESD")) { + Error("AddAnalysisTaskTOFSpectraPbPb", "input data type is not \"ESD\""); + return NULL; + } + + /* check MC truth event handler */ + if (mcFlag) { + if (!mgr->GetMCtruthEventHandler()) { + Error("AddAnalysisTaskTOFSpectraPbPb", "cannot get MC truth event handler"); + return NULL; + } + } + + /* get common input data container */ + AliAnalysisDataContainer *inputc = mgr->GetCommonInputContainer(); + if (!inputc) { + Error("AddAnalysisTaskTOFSpectraPbPb", "cannot get common input container"); + return NULL; + } + + /* setup output event handler */ + AliAODHandler *outputh = (AliAODHandler *)mgr->GetOutputEventHandler(); + outputh->SetCreateNonStandardAOD(); + outputh->SetOutputFileName("TOFSpectraPbPb.root"); + + /* create task and connect input/output */ + AliAnalysisTaskTOFSpectraPbPb *task = new AliAnalysisTaskTOFSpectraPbPb(); + mgr->ConnectInput(task, 0, inputc); + + /* setup task */ + task->SetMCFlag(mcFlag); + task->SetMCTuneFlag(mcTuneFlag); + task->SetPbPbFlag(pbpbFlag); + task->SelectCollisionCandidates(AliVEvent::kAny); + task->SetVertexSelectionFlag(kTRUE); + task->SetVertexCut(15.0); + task->SetRapidityCut(1.0); + /* setup TOF calib */ + task->GetTOFcalib()->SetRemoveMeanT0(!mcFlag); + task->GetTOFcalib()->SetCalibrateTOFsignal(!mcFlag); + task->GetTOFcalib()->SetCorrectTExp(kFALSE); + /* setup resolution */ + Double_t timeReso = 85.; + if (mcFlag && !mcTuneFlag) timeReso = 80.; + task->SetTimeResolution(timeReso); + task->GetESDpid()->GetTOFResponse().SetTimeResolution(timeReso); + task->GetTOFT0maker()->SetTimeResolution(timeReso); + /* setup track cuts */ + AliESDtrackCuts *trackCuts = new AliESDtrackCuts; + trackCuts->SetMaxChi2PerClusterTPC(4.5); + trackCuts->SetAcceptKinkDaughters(kFALSE); + trackCuts->SetRequireTPCRefit(kTRUE); + trackCuts->SetRequireITSRefit(kTRUE); + trackCuts->SetClusterRequirementITS(AliESDtrackCuts::kSPD, + AliESDtrackCuts::kAny); + trackCuts->SetMaxDCAToVertexZ(2); + trackCuts->SetDCAToVertex2D(kFALSE); + trackCuts->SetRequireSigmaToVertex(kFALSE); + trackCuts->SetMaxChi2PerClusterITS(36); + trackCuts->SetPtRange(0.15, 10.); + trackCuts->SetEtaRange(-0.9, 0.9); + task->SetTrackCuts(trackCuts); + + /* return task */ + return task; + +} diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisEvent.cxx b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisEvent.cxx new file mode 100644 index 00000000000..126f4d1e7fb --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisEvent.cxx @@ -0,0 +1,508 @@ +#include "AliAnalysisEvent.h" +#include "AliVEvent.h" + +ClassImp(AliAnalysisEvent) + +//___________________________________________________________ + +Bool_t AliAnalysisEvent::fgInitCorrections = kFALSE; + +const Char_t *AliAnalysisEvent::fgTimeZeroTOFCentCorrFormula = "[0]+[1]*x+[2]*x*x"; + +Double_t AliAnalysisEvent::fgTimeZeroTOFCentCorrParams[3] = { + -14.9262, 0.0212941, 0.000960528 +}; + +TF1 *AliAnalysisEvent::fgTimeZeroTOFCentCorrFunc = NULL; + +//___________________________________________________________ + +AliTOFPIDResponse AliAnalysisEvent::fgTOFResponse; + +Float_t AliAnalysisEvent::fgVertexZ_cuts[2] = {-10., 10.}; /* min,max */ +Float_t AliAnalysisEvent::fgTimeZeroT0_AND_params[2] = {0., 1000.}; /* mean,sigma */ +Float_t AliAnalysisEvent::fgTimeZeroT0_A_params[2] = {0., 1000.}; /* mean,sigma */ +Float_t AliAnalysisEvent::fgTimeZeroT0_C_params[2] = {0., 1000.}; /* mean,sigma */ +Float_t AliAnalysisEvent::fgTimeZeroT0_ACdiff_params[2] = {0., 1000.}; /* mean,sigma */ +Float_t AliAnalysisEvent::fgTimeZero_TOFT0diff_params[2] = {0., 1000.}; /* mean,sigma */ + +const Char_t *AliAnalysisEvent::fgkCentralityEstimatorName[AliAnalysisEvent::kNCentralityEstimators] = { + "V0M", + "V0A", + "V0C", + "TRK", + "TKL", + "CL1", + "ZNA" +}; + +Float_t AliAnalysisEvent::fgTimeZeroSpread = 196.7; +Float_t AliAnalysisEvent::fgTimeZeroT0_AND_sigma = 3.87264325235363032e+01; +Float_t AliAnalysisEvent::fgTimeZeroT0_A_sigma = 8.27180042372880706e+01; +Float_t AliAnalysisEvent::fgTimeZeroT0_C_sigma = 9.73209262235003933e+01; + +//___________________________________________________________ + +AliAnalysisEvent::AliAnalysisEvent() : + TObject(), + fIsCollisionCandidate(kFALSE), + fIsEventSelected(0), + fIsPileupFromSPD(kFALSE), + fHasVertex(kFALSE), + fVertexZ(0.), + fCentralityQuality(0), + fCentralityPercentile(), + fReferenceMultiplicity(0), + fMCMultiplicity(0), + fTimeZeroTOF(), + fTimeZeroTOFSigma(), + fTimeZeroT0(), + fMCTimeZero(0.) +{ + /* + * default constructor + */ + + /* init corrections */ + if (!fgInitCorrections) { + + /*** TIME-ZERO TOF CENTRALITY CORRECTION ***/ + fgTimeZeroTOFCentCorrFunc = new TF1("fTimeZeroTOFCentCorrFunc", fgTimeZeroTOFCentCorrFormula, 0., 100.); + for (Int_t iparam = 0; iparam < 3; iparam++) + fgTimeZeroTOFCentCorrFunc->SetParameter(iparam, fgTimeZeroTOFCentCorrParams[iparam]); + + /* set init flag */ + fgInitCorrections = kTRUE; + } + + /* reset */ + Reset(); +} + +//___________________________________________________________ + +AliAnalysisEvent::AliAnalysisEvent(const AliAnalysisEvent &source) : + TObject(source), + fIsCollisionCandidate(source.fIsCollisionCandidate), + fIsEventSelected(source.fIsEventSelected), + fIsPileupFromSPD(source.fIsPileupFromSPD), + fHasVertex(source.fHasVertex), + fVertexZ(source.fVertexZ), + fCentralityQuality(source.fCentralityQuality), + fCentralityPercentile(), + fReferenceMultiplicity(source.fReferenceMultiplicity), + fMCMultiplicity(source.fMCMultiplicity), + fTimeZeroTOF(), + fTimeZeroTOFSigma(), + fTimeZeroT0(), + fMCTimeZero(source.fMCTimeZero) +{ + /* + * copy constructor + */ + + for (Int_t i = 0; i < kNCentralityEstimators; i++) + fCentralityPercentile[i] = source.fCentralityPercentile[i]; + for (Int_t i = 0; i < 10; i++) { + fTimeZeroTOF[i] = source.fTimeZeroTOF[i]; + fTimeZeroTOFSigma[i] = source.fTimeZeroTOFSigma[i]; + } + for (Int_t i = 0; i < 3; i++) + fTimeZeroT0[i] = source.fTimeZeroT0[i]; + +} + +//___________________________________________________________ + +AliAnalysisEvent & +AliAnalysisEvent::operator=(const AliAnalysisEvent &source) +{ + /* + * operator= + */ + + if (&source == this) return *this; + TObject::operator=(source); + + fIsCollisionCandidate = source.fIsCollisionCandidate; + fIsEventSelected = source.fIsEventSelected; + fIsPileupFromSPD = source.fIsPileupFromSPD; + fHasVertex = source.fHasVertex; + fVertexZ = source.fVertexZ; + fCentralityQuality = source.fCentralityQuality; + fReferenceMultiplicity = source.fReferenceMultiplicity; + fMCMultiplicity = source.fMCMultiplicity; + for (Int_t i = 0; i < kNCentralityEstimators; i++) + fCentralityPercentile[i] = source.fCentralityPercentile[i]; + for (Int_t i = 0; i < 10; i++) { + fTimeZeroTOF[i] = source.fTimeZeroTOF[i]; + fTimeZeroTOFSigma[i] = source.fTimeZeroTOFSigma[i]; + } + for (Int_t i = 0; i < 3; i++) + fTimeZeroT0[i] = source.fTimeZeroT0[i]; + fMCTimeZero = source.fMCTimeZero; + + return *this; +} + +//___________________________________________________________ + +AliAnalysisEvent::~AliAnalysisEvent() +{ + /* + * default destructor + */ + +} + +//___________________________________________________________ + +void +AliAnalysisEvent::Reset() +{ + /* + * reset + */ + + fIsCollisionCandidate = kFALSE; + fIsEventSelected = 0; + fIsPileupFromSPD = kFALSE; + fHasVertex = 0.; + fVertexZ = 0.; + fCentralityQuality = 0; + fReferenceMultiplicity = 0; + fMCMultiplicity = 0; + for (Int_t i = 0; i < kNCentralityEstimators; i++) + fCentralityPercentile[i] = 0.; + for (Int_t i = 0; i < 10; i++) { + fTimeZeroTOF[i] = 0.; + fTimeZeroTOFSigma[i] = 0.; + } + for (Int_t i = 0; i < 3; i++) + fTimeZeroT0[i] = 0.; + fMCTimeZero = 0.; +} + +//___________________________________________________________ + +Bool_t +AliAnalysisEvent::CheckLimits(Float_t value, Float_t *params, Float_t nSigma) const +{ + /* + * check limits + */ + + Float_t min = params[0] - nSigma * params[1]; + Float_t max = params[0] + nSigma * params[1]; + if (value < min || value > max) return kFALSE; + return kTRUE; +} + +//___________________________________________________________ + +Bool_t +AliAnalysisEvent::AcceptEvent(Int_t type) const +{ + /* + * accept event proton-proton + */ + + if (!fIsCollisionCandidate) return kFALSE; + if (!AcceptVertex()) return kFALSE; + if (fCentralityQuality != 0) return kFALSE; + if (!(fIsEventSelected & AliVEvent::kINT7)) return kFALSE; + + if (type > 0) { + if (fIsPileupFromSPD) return kFALSE; + if (!(fIsEventSelected & AliVEvent::kMB)) return kFALSE; + }; + + + return kTRUE; +} + +//___________________________________________________________ + +Bool_t +AliAnalysisEvent::AcceptVertex() const +{ + /* + * accept vertex + */ + + if (!HasVertex()) return kFALSE; + if (fVertexZ < fgVertexZ_cuts[0] || fVertexZ > fgVertexZ_cuts[1]) return kFALSE; + return kTRUE; +} + +//___________________________________________________________ + +Bool_t +AliAnalysisEvent::HasTimeZeroT0_AND() const +{ + /* + * has time-zero T0-AND + */ + + /* check T0-AND */ + if (!CheckLimits(fTimeZeroT0[0], fgTimeZeroT0_AND_params)) return kFALSE; + /* check T0-A */ + if (!CheckLimits(fTimeZeroT0[1], fgTimeZeroT0_A_params)) return kFALSE; + /* check T0-C */ + if (!CheckLimits(fTimeZeroT0[2], fgTimeZeroT0_C_params)) return kFALSE; + /* check A-C difference */ + if (!CheckLimits(fTimeZeroT0[1] - fTimeZeroT0[2], fgTimeZeroT0_ACdiff_params)) return kFALSE; + /* ok */ + return kTRUE; +} + +//___________________________________________________________ + +Bool_t +AliAnalysisEvent::HasTimeZeroT0_XOR() const +{ + /* + * has time-zero T0-XOR + */ + + /* check T0-A only */ + if (CheckLimits(fTimeZeroT0[1], fgTimeZeroT0_A_params) && + !CheckLimits(fTimeZeroT0[2], fgTimeZeroT0_C_params)) return kTRUE; + /* check T0-C only */ + if (!CheckLimits(fTimeZeroT0[1], fgTimeZeroT0_A_params) && + CheckLimits(fTimeZeroT0[2], fgTimeZeroT0_C_params)) return kTRUE; + return kFALSE; +} + +//___________________________________________________________ + +Bool_t +AliAnalysisEvent::HasTimeZeroT0_OR() const +{ + /* + * has time-zero T0-OR + */ + + if (HasTimeZeroT0_AND() || HasTimeZeroT0_XOR()) return kTRUE; + return kFALSE; +} + +//___________________________________________________________ + +Bool_t +AliAnalysisEvent::HasTimeZeroTOF(Float_t momentum) const +{ + /* + * has time-zero TOF + */ + + Int_t momBin = fgTOFResponse.GetMomBin(momentum); + if (fTimeZeroTOF[momBin] == 0.) return kFALSE; + return kTRUE; +} + +//___________________________________________________________ + +Bool_t +AliAnalysisEvent::HasTimeZeroBest(Float_t momentum) const +{ + /* + * has time-zero best + */ + + if (HasTimeZeroT0_OR() || HasTimeZeroTOF(momentum)) return kTRUE; + return kFALSE; +} + +//___________________________________________________________ + +Bool_t +AliAnalysisEvent::HasTimeZeroSafe(Float_t momentum) const +{ + /* + * has time-zero safe + */ + + if (!HasTimeZeroT0_AND() || !HasTimeZeroTOF(momentum)) return kFALSE; + Float_t tzeroTOF = GetTimeZeroTOF(momentum); + Float_t tzeroT0 = GetTimeZeroT0_AND(); + Float_t diff = tzeroTOF - tzeroT0; + if (!CheckLimits(diff, fgTimeZero_TOFT0diff_params)) return kFALSE; + return kTRUE; +} + +//___________________________________________________________ + +Float_t +AliAnalysisEvent::GetTimeZeroT0_AND() const +{ + /* + * get time-zero T0-AND + */ + + return fTimeZeroT0[0] - fgTimeZeroT0_AND_params[0]; +} + +//___________________________________________________________ + +Float_t +AliAnalysisEvent::GetTimeZeroT0Sigma_AND() const +{ + /* + * get time-zero T0-AND sigma + */ + + return fgTimeZeroT0_AND_sigma; +} + +//___________________________________________________________ + +Float_t +AliAnalysisEvent::GetTimeZeroT0_XOR() const +{ + /* + * get time-zero T0-XOR + */ + + if (CheckLimits(fTimeZeroT0[1], fgTimeZeroT0_A_params) && + !CheckLimits(fTimeZeroT0[2], fgTimeZeroT0_C_params)) return fTimeZeroT0[1] - fgTimeZeroT0_A_params[0]; + if (!CheckLimits(fTimeZeroT0[1], fgTimeZeroT0_A_params) && + CheckLimits(fTimeZeroT0[2], fgTimeZeroT0_C_params)) return fTimeZeroT0[2] - fgTimeZeroT0_C_params[0]; + return 0.; +} + +//___________________________________________________________ + +Float_t +AliAnalysisEvent::GetTimeZeroT0Sigma_XOR() const +{ + /* + * get time-zero T0-XOR sigma + */ + + if (CheckLimits(fTimeZeroT0[1], fgTimeZeroT0_A_params) && + !CheckLimits(fTimeZeroT0[2], fgTimeZeroT0_C_params)) return fgTimeZeroT0_A_sigma; + if (!CheckLimits(fTimeZeroT0[1], fgTimeZeroT0_A_params) && + CheckLimits(fTimeZeroT0[2], fgTimeZeroT0_C_params)) return fgTimeZeroT0_C_sigma; + return 0.; +} + +//___________________________________________________________ + +Float_t +AliAnalysisEvent::GetTimeZeroT0_OR() const +{ + /* + * get time-zero T0-OR + */ + + if (HasTimeZeroT0_AND()) return GetTimeZeroT0_AND(); + if (HasTimeZeroT0_XOR()) return GetTimeZeroT0_XOR(); + return 0.; +} + +//___________________________________________________________ + +Float_t +AliAnalysisEvent::GetTimeZeroT0Sigma_OR() const +{ + /* + * get time-zero T0-OR sigma + */ + + if (HasTimeZeroT0_AND()) return GetTimeZeroT0Sigma_AND(); + if (HasTimeZeroT0_XOR()) return GetTimeZeroT0Sigma_XOR(); + return 0.; +} + +//___________________________________________________________ + +Float_t +AliAnalysisEvent::GetTimeZeroTOF(Float_t momentum) const +{ + /* + * get time-zero TOF + */ + + Int_t momBin = fgTOFResponse.GetMomBin(momentum); + return fTimeZeroTOF[momBin]; +} + +//___________________________________________________________ + +Float_t +AliAnalysisEvent::GetTimeZeroTOFSigma(Float_t momentum) const +{ + /* + * get time-zero TOF sigma + */ + + Int_t momBin = fgTOFResponse.GetMomBin(momentum); + return fTimeZeroTOFSigma[momBin]; +} + +//___________________________________________________________ + +Float_t +AliAnalysisEvent::GetTimeZeroBest(Float_t momentum) const +{ + /* + * get time-zero best + */ + + if (HasTimeZeroTOF(momentum)) return GetTimeZeroTOF(momentum); + if (HasTimeZeroT0_OR()) return GetTimeZeroT0_OR(); + return 0.; +} + +//___________________________________________________________ + +Float_t +AliAnalysisEvent::GetTimeZeroBestSigma(Float_t momentum) const +{ + /* + * get time-zero best sigma + */ + + if (HasTimeZeroTOF(momentum)) return GetTimeZeroTOFSigma(momentum); + if (HasTimeZeroT0_OR()) return GetTimeZeroT0Sigma_OR(); + return fgTimeZeroSpread; +} + +//___________________________________________________________ + +Float_t +AliAnalysisEvent::GetTimeZeroSafe(Float_t momentum) const +{ + /* + * get time-zero safe + */ + + return GetTimeZeroTOF(momentum); +} + +//___________________________________________________________ + +Float_t +AliAnalysisEvent::GetTimeZeroSafeSigma(Float_t momentum) const +{ + /* + * get time-zero safe sigma + */ + + return GetTimeZeroTOFSigma(momentum); +} + +//___________________________________________________________ + +void +AliAnalysisEvent::ApplyTimeZeroTOFCorrection() +{ + /* + * apply timezero TOF correction + */ + + for (Int_t imom = 0; imom < 10; imom++) + fTimeZeroTOF[imom] += GetTimeZeroTOFCorrection(); + +} diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisEvent.h b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisEvent.h new file mode 100644 index 00000000000..5d735f52097 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisEvent.h @@ -0,0 +1,137 @@ +#ifndef ALIANALYSISEVENT_H +#define ALIANALYSISEVENT_H + +#include "TObject.h" +#include "AliTOFPIDResponse.h" +#include "TF1.h" + +class AliAnalysisEvent : +public TObject +{ + + public: + + AliAnalysisEvent(); // default constructor + AliAnalysisEvent(const AliAnalysisEvent &source); // copy constructor + AliAnalysisEvent &operator=(const AliAnalysisEvent &source); // operator= + virtual ~AliAnalysisEvent(); // default destructor + + Bool_t IsCollisionCandidate() const {return fIsCollisionCandidate;}; // getter + Bool_t HasVertex() const {return fHasVertex;}; // getter + Float_t GetVertexZ() const {return fVertexZ;}; // getter + UChar_t GetCentralityQuality() const {return fCentralityQuality;}; // getter + Float_t GetCentralityPercentile(Int_t i) const {return i < kNCentralityEstimators ? fCentralityPercentile[i] : (Float_t)GetReferenceMultiplicity();}; // getter + Int_t GetReferenceMultiplicity() const {return fReferenceMultiplicity;}; // getter + Float_t *GetTimeZeroTOF() {return fTimeZeroTOF;}; // getter + Float_t *GetTimeZeroTOFSigma() {return fTimeZeroTOFSigma;}; // getter + Float_t *GetTimeZeroT0() {return fTimeZeroT0;}; // getter + Float_t GetTimeZeroTOF(Int_t i) {return i < 10 ? fTimeZeroTOF[i] : 0.;}; // getter + Float_t GetTimeZeroTOFSigma(Int_t i) {return i < 10 ? fTimeZeroTOFSigma[i] : 0.;}; // getter + Float_t GetTimeZeroT0(Int_t i) {return i < 3 ? fTimeZeroT0[i] : 0.;}; // getter + Float_t GetMCTimeZero() const {return fMCTimeZero;}; // getter + + void SetIsCollisionCandidate(Bool_t value) {fIsCollisionCandidate = value;}; // setter + void SetIsEventSelected(UInt_t value) {fIsEventSelected = value;}; // setter + void SetIsPileupFromSPD(Bool_t value) {fIsPileupFromSPD = value;}; // setter + void SetHasVertex(Bool_t value) {fHasVertex = value;}; // setter + void SetVertexZ(Float_t value) {fVertexZ = value;}; // setter + void SetCentralityQuality(UChar_t value) {fCentralityQuality = value;}; // setter + void SetCentralityPercentile(Int_t icent, Float_t value) {if (icent < kNCentralityEstimators) fCentralityPercentile[icent] = value;}; // setter + void SetReferenceMultiplicity(Int_t value) {fReferenceMultiplicity = value;}; // setter + void SetMCMultiplicity(Int_t value) {fMCMultiplicity = value;}; // setter + void SetTimeZeroTOF(Int_t i, Float_t value) {fTimeZeroTOF[i] = value;}; // setter + void SetTimeZeroTOFSigma(Int_t i, Float_t value) {fTimeZeroTOFSigma[i] = value;}; // setter + void SetTimeZeroT0(Int_t i, Float_t value) {fTimeZeroT0[i] = value;}; // setter + void SetMCTimeZero(Float_t value) {fMCTimeZero = value;}; // setter + + void Reset(); // reset + Bool_t CheckLimits(Float_t value, Float_t *params, Float_t nSigma = 3.) const; // check limits + + Bool_t AcceptEvent(Int_t type = 0) const; // accept event proton-proton + Bool_t AcceptVertex() const; // accept vertex + Bool_t HasTimeZeroT0_AND() const; // has time-zero T0-AND + Bool_t HasTimeZeroT0_XOR() const; // has time-zero T0-XOR + Bool_t HasTimeZeroT0_OR() const; // has time-zero T0-OR + Bool_t HasTimeZeroTOF(Float_t momentum) const; // has time-zero TOF + Bool_t HasTimeZeroBest(Float_t momentum) const; // has time-zero TOF + Bool_t HasTimeZeroSafe(Float_t momentum) const; // has time-zero safe + + Float_t GetTimeZeroT0_AND() const; // get time-zero T0-AND + Float_t GetTimeZeroT0_XOR() const; // get time-zero T0-XOR + Float_t GetTimeZeroT0_OR() const; // get time-zero T0-OR + Float_t GetTimeZeroTOF(Float_t momentum) const; // get time-zero TOF + Float_t GetTimeZeroBest(Float_t momentum) const; // get time-zero best + Float_t GetTimeZeroSafe(Float_t momentum) const; // get time-zero safe + + Float_t GetTimeZeroT0Sigma_AND() const; // get time-zero T0-AND sigma + Float_t GetTimeZeroT0Sigma_XOR() const; // get time-zero T0-XOR sigma + Float_t GetTimeZeroT0Sigma_OR() const; // get time-zero T0-OR sigma + Float_t GetTimeZeroTOFSigma(Float_t momentum) const; // get time-zero TOF sigma + Float_t GetTimeZeroBestSigma(Float_t momentum) const; // get time-zero best sigma + Float_t GetTimeZeroSafeSigma(Float_t momentum) const; // get time-zero safe sigma + + enum ECentralityEstimator_t { + kCentEst_V0M, /* V0 multiplicity */ + kCentEst_V0A, /* V0A multiplicity */ + kCentEst_V0C, /* V0C multiplicity */ + kCentEst_TRK, /* N. of tracks */ + kCentEst_TKL, /* N. of tracklets */ + kCentEst_CL1, /* N. of clusters in layer 1 */ + kCentEst_ZNA, /* ZNA */ + kNCentralityEstimators + }; + static const Char_t *fgkCentralityEstimatorName[kNCentralityEstimators]; // centrality estimator name + + static void SetVertexZCuts(Float_t min, Float_t max) {fgVertexZ_cuts[0] = min; fgVertexZ_cuts[1] = max;}; // setter + + void ApplyTimeZeroTOFCorrection(); + Double_t GetTimeZeroTOFCorrection() {return fgTimeZeroTOFCentCorrFunc->Eval(fCentralityPercentile[kCentEst_V0M]);}; + + private: + + /*** global event info ***/ + Bool_t fIsCollisionCandidate; // is collision candidate + UInt_t fIsEventSelected; // is event selected + Bool_t fIsPileupFromSPD; // is pile-up from SPD + Bool_t fHasVertex; // has vertex + Float_t fVertexZ; // vertex z + UChar_t fCentralityQuality; // centrality quality + Float_t fCentralityPercentile[kNCentralityEstimators]; // centrality percentile + Int_t fReferenceMultiplicity; // reference multiplicity + Int_t fMCMultiplicity; // MC multiplicity + /*** TPC event info ***/ + /*** TOF event info ***/ + Float_t fTimeZeroTOF[10]; // time-zero TOF + Float_t fTimeZeroTOFSigma[10]; // time-zero TOF sigma + /*** T0 event info ***/ + Float_t fTimeZeroT0[3]; // time-zero T0 + /*** MC info ***/ + Float_t fMCTimeZero; // MC time-zero + + /*** tools ***/ + static AliTOFPIDResponse fgTOFResponse; // TOF PID response + + /*** cuts ***/ + static Float_t fgVertexZ_cuts[2]; // min,max + static Float_t fgTimeZeroT0_AND_params[2]; // mean,sigma + static Float_t fgTimeZeroT0_A_params[2]; + static Float_t fgTimeZeroT0_C_params[2]; + static Float_t fgTimeZeroT0_ACdiff_params[2]; + static Float_t fgTimeZero_TOFT0diff_params[2]; + + /*** other ***/ + static Float_t fgTimeZeroSpread; + static Float_t fgTimeZeroT0_AND_sigma; + static Float_t fgTimeZeroT0_A_sigma; + static Float_t fgTimeZeroT0_C_sigma; + + /*** corrections ***/ + static Bool_t fgInitCorrections; + static const Char_t *fgTimeZeroTOFCentCorrFormula; + static Double_t fgTimeZeroTOFCentCorrParams[3]; + static TF1 *fgTimeZeroTOFCentCorrFunc; + + ClassDef(AliAnalysisEvent, 6); +}; + +#endif /* ALIANALYSISEVENT_H */ diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisParticle.cxx b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisParticle.cxx new file mode 100644 index 00000000000..ce7e99b5d81 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisParticle.cxx @@ -0,0 +1,160 @@ +#include "AliAnalysisParticle.h" +#include "TParticle.h" +#include "AliPID.h" +#include "TDatabasePDG.h" +#include "TParticlePDG.h" +#include "TMath.h" + +ClassImp(AliAnalysisParticle) + +//___________________________________________________________ + +TLorentzVector AliAnalysisParticle::fgLorentzVector; + +//___________________________________________________________ + +Double_t +AliAnalysisParticle::GetY() const +{ + + fgLorentzVector.SetPtEtaPhiM(fPt, fEta, fPhi, GetMass()); + return fgLorentzVector.Rapidity(); +} + +//___________________________________________________________ + +Float_t +AliAnalysisParticle::GetSign() const +{ + + TDatabasePDG *dbpdg = TDatabasePDG::Instance(); + TParticlePDG *ppdg = dbpdg->GetParticle(fPdgCode); + if (!ppdg) + return 0.; + return TMath::Sign(1., ppdg->Charge()); +} + +//___________________________________________________________ + +Int_t +AliAnalysisParticle::GetPID() const +{ + /* + * get PID + */ + + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) + if (TMath::Abs(fPdgCode) == AliPID::ParticleCode(ipart)) + return ipart; + return -1; + +} + +//___________________________________________________________ + +Double_t +AliAnalysisParticle::GetMass() const +{ + /* + * get mass + */ + + if (GetPID() == -1) + return 0.; + return AliPID::ParticleMass(GetPID()); +} + +//___________________________________________________________ + +AliAnalysisParticle::AliAnalysisParticle() : + TObject(), + fLabel(0), + fPt(0.), + fEta(0.), + fPhi(0.), + fPdgCode(0) +{ + /* + * default constructor + */ +} + +//___________________________________________________________ + +AliAnalysisParticle::AliAnalysisParticle(const AliAnalysisParticle &source) : + TObject(source), + fLabel(source.fLabel), + fPt(source.fPt), + fEta(source.fEta), + fPhi(source.fPhi), + fPdgCode(source.fPdgCode) +{ + /* + * copy constructor + */ +} + +//___________________________________________________________ + +AliAnalysisParticle & +AliAnalysisParticle::operator=(const AliAnalysisParticle &source) +{ + /* + * operator= + */ + + if (&source == this) return *this; + TObject::operator=(source); + + fLabel = source.fLabel; + fPt = source.fPt; + fEta = source.fEta; + fPhi = source.fPhi; + fPdgCode = source.fPdgCode; + + return *this; +} + +//___________________________________________________________ + +AliAnalysisParticle::~AliAnalysisParticle() +{ + /* + * default destructor + */ +} + +//___________________________________________________________ + +void +AliAnalysisParticle::Reset() +{ + /* + * reset + */ + + fLabel = 0; + fPt = 0.; + fEta = 0.; + fPhi = 0.; + fPdgCode = 0; + +} + +//___________________________________________________________ + +void +AliAnalysisParticle::Update(TParticle *particle, Int_t label) +{ + /* + * update + */ + + fLabel = label; + fPt = particle->Pt(); + fEta = particle->Eta(); + fPhi = particle->Phi(); + fPdgCode = particle->GetPdgCode(); + +} + diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisParticle.h b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisParticle.h new file mode 100644 index 00000000000..5b025873cc2 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisParticle.h @@ -0,0 +1,48 @@ +#ifndef ALIANALYSISPARTICLE_H +#define ALIANALYSISPARTICLE_H + +#include "TObject.h" +#include "TLorentzVector.h" + +class TParticle; + +class AliAnalysisParticle : +public TObject +{ + + public: + + AliAnalysisParticle(); // default constructor + AliAnalysisParticle(const AliAnalysisParticle &source); // copy constructor + AliAnalysisParticle &operator=(const AliAnalysisParticle &source); // operator= + virtual ~AliAnalysisParticle(); // default destructor + + Int_t GetLabel() const {return fLabel;} // get label + Float_t GetPt() const {return fPt;}; // get pt + Float_t GetEta() const {return fEta;}; // get eta + Float_t GetPhi() const {return fPhi;}; // get phi + Int_t GetPdgCode() const {return fPdgCode;}; // get PDG code + + Double_t GetY() const; // get Y + Float_t GetSign() const; // get sign + Int_t GetPID() const; // get MC PID + Double_t GetMass() const; // get mass + + void Reset(); // reset + void Update(TParticle *particle, Int_t label); // update + + private: + + Int_t fLabel; // label + Float_t fPt; // pt + Float_t fEta; // eta + Float_t fPhi; // phi + Int_t fPdgCode; // PDG code + + /*** tools ***/ + static TLorentzVector fgLorentzVector; + + ClassDef(AliAnalysisParticle, 1); +}; + +#endif /* ALIANALYSISPARTICLE_H */ diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisTaskTOFSpectraPbPb.cxx b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisTaskTOFSpectraPbPb.cxx new file mode 100644 index 00000000000..41e13ac64cb --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisTaskTOFSpectraPbPb.cxx @@ -0,0 +1,350 @@ +#include "AliAnalysisTaskTOFSpectraPbPb.h" +#include "AliESDEvent.h" +#include "AliMCEvent.h" +#include "AliStack.h" +#include "AliPhysicsSelection.h" +#include "AliESDtrackCuts.h" +#include "AliESDpid.h" +#include "AliTOFcalib.h" +#include "AliTOFT0maker.h" +#include "TList.h" +#include "TH1F.h" +#include "TH2F.h" +#include "AliCDBManager.h" +#include "AliLog.h" +#include "AliESDtrack.h" +#include "TObjArray.h" +#include "TLorentzVector.h" +#include "TParticle.h" +#include "TDatabasePDG.h" +#include "TParticlePDG.h" +#include "AliTOFRunParams.h" +#include "AliAnalysisTrack.h" +#include "AliAnalysisParticle.h" +#include "AliAnalysisEvent.h" +#include "TClonesArray.h" +#include "AliAnalysisManager.h" +#include "AliAODHandler.h" +#include "TTree.h" +#include "AliCentrality.h" +#include "AliInputEventHandler.h" +#include "AliVEvent.h" + +ClassImp(AliAnalysisTaskTOFSpectraPbPb) + +//_______________________________________________________ + +AliAnalysisTaskTOFSpectraPbPb::AliAnalysisTaskTOFSpectraPbPb() : + AliAnalysisTaskSE("TOFSpectraPbPb"), + fInitFlag(kFALSE), + fMCFlag(kFALSE), + fMCTuneFlag(kFALSE), + fPbPbFlag(kFALSE), + fVertexSelectionFlag(kFALSE), + fRunNumber(0), + fESDEvent(NULL), + fMCEvent(NULL), + fMCStack(NULL), + fTrackCuts(NULL), + fESDpid(new AliESDpid()), + fIsCollisionCandidate(kFALSE), + fIsEventSelected(0), + fIsPileupFromSPD(kFALSE), + fHasVertex(kFALSE), + fVertexZ(0.), + fMCTimeZero(0.), + fCentrality(NULL), + fAnalysisEvent(new AliAnalysisEvent()), + fAnalysisTrackArray(new TClonesArray("AliAnalysisTrack")), + fAnalysisTrack(new AliAnalysisTrack()), + fAnalysisParticleArray(new TClonesArray("AliAnalysisParticle")), + fAnalysisParticle(new AliAnalysisParticle()), + fTOFcalib(new AliTOFcalib()), + fTOFT0maker(new AliTOFT0maker(fESDpid)), + fTimeResolution(80.), + fVertexCut(10.0), + fRapidityCut(1.0), + fHistoList(new TList()), + fMCHistoList(new TList()) +{ + /* + * default constructor + */ + +} + +//_______________________________________________________ + +AliAnalysisTaskTOFSpectraPbPb::~AliAnalysisTaskTOFSpectraPbPb() +{ + /* + * default destructor + */ + + if (fTrackCuts) delete fTrackCuts; + delete fESDpid; + delete fTOFcalib; + delete fTOFT0maker; + delete fHistoList; + delete fMCHistoList; +} + +//_______________________________________________________ + +void +AliAnalysisTaskTOFSpectraPbPb::UserCreateOutputObjects() +{ + /* + * user create output objects + */ + + /* output tree */ + OutputTree()->Branch("AnalysisEvent", "AliAnalysisEvent", &fAnalysisEvent); + OutputTree()->Branch("AnalysisTrack", "TClonesArray", &fAnalysisTrackArray); + if (fMCFlag) + OutputTree()->Branch("AnalysisParticle", "TClonesArray", &fAnalysisParticleArray); +} + +//_______________________________________________________ + +Bool_t +AliAnalysisTaskTOFSpectraPbPb::InitRun() +{ + /* + * init run + */ + + /* get ESD event */ + fESDEvent = dynamic_cast(InputEvent()); + if (!fESDEvent) { + AliError("cannot get ESD event"); + return kFALSE; + } + /* get run number */ + Int_t runNb = fESDEvent->GetRunNumber(); + /* check run already initialized */ + if (fInitFlag && fRunNumber == runNb) return kTRUE; + /* init cdb */ + AliCDBManager *cdb = AliCDBManager::Instance(); + cdb->SetDefaultStorage("raw://"); + cdb->SetRun(runNb); + /* init TOF calib */ + if (!fTOFcalib->Init()) { + AliError("cannot init TOF calib"); + return kFALSE; + } + AliInfo(Form("initialized for run %d", runNb)); + fInitFlag = kTRUE; + fRunNumber = runNb; + return kTRUE; +} + +//_______________________________________________________ + +Bool_t +AliAnalysisTaskTOFSpectraPbPb::InitEvent() +{ + /* + * init event + */ + + /* get ESD event */ + fESDEvent = dynamic_cast(InputEvent()); + if (!fESDEvent) return kFALSE; + /* get MC event */ + if (fMCFlag) { + fMCEvent = dynamic_cast(MCEvent()); + if (!fMCEvent) return kFALSE; + } + /* get stack */ + if (fMCFlag) { + fMCStack = fMCEvent->Stack(); + if (!fMCStack) return kFALSE; + } + /* event selection */ + fIsCollisionCandidate = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & AliVEvent::kAny); + fIsEventSelected = ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected(); + fIsPileupFromSPD = fESDEvent->IsPileupFromSPD(); + + /* vertex selection */ + const AliESDVertex *vertex = fESDEvent->GetPrimaryVertexTracks(); + if (vertex->GetNContributors() < 1) { + vertex = fESDEvent->GetPrimaryVertexSPD(); + if (vertex->GetNContributors() < 1) fHasVertex = kFALSE; + else fHasVertex = kTRUE; + TString vtxTyp = vertex->GetTitle(); + Double_t cov[6]={0}; + vertex->GetCovarianceMatrix(cov); + Double_t zRes = TMath::Sqrt(cov[5]); + if (vtxTyp.Contains("vertexer:Z") && (zRes>0.25)) fHasVertex = kFALSE; + } + else fHasVertex = kTRUE; + + // if (fVertexSelectionFlag && (!fHasVertex || TMath::Abs(vertex->GetZ()) > fVertexCut)) return kFALSE; + + fVertexZ = vertex->GetZ(); + /* centrality in PbPb */ + if (fPbPbFlag) { + fCentrality = fESDEvent->GetCentrality(); + } + printf("smack"); + /* calibrate ESD (also in MC to correct TExp) */ + fTOFcalib->CalibrateESD(fESDEvent); + + /* check MC flags */ + if (fMCFlag && fMCTuneFlag) + fMCTimeZero = fTOFcalib->TuneForMC(fESDEvent, fTimeResolution); + +#if 0 /* NEW METHOD */ + /* compute TOF-T0, fill ESD and make PID */ + fTOFT0maker->ComputeT0TOF(fESDEvent); + fTOFT0maker->WriteInESD(fESDEvent); + fESDpid->SetTOFResponse(fESDEvent, AliESDpid::kTOF_T0); + fESDpid->MakePID(fESDEvent, kFALSE, 0.); +#endif + +#if 1 /* OLD METHOD */ + /* compute and apply TOF-T0 */ + fTOFT0maker->ComputeT0TOF(fESDEvent); + fESDpid->MakePID(fESDEvent, kFALSE, 0.); +#endif + + return kTRUE; +} + +//_______________________________________________________ + +Bool_t +AliAnalysisTaskTOFSpectraPbPb::HasPrimaryDCA(AliESDtrack *track) +{ + /* + * has primary DCA + */ + + // cut on transverse impact parameter + Float_t d0z0[2],covd0z0[3]; + track->GetImpactParameters(d0z0, covd0z0); + Float_t sigma= 0.0050 + 0.0060 / TMath::Power(track->Pt(), 0.9); + Float_t d0max = 7. * sigma; + // + Float_t sigmaZ = 0.0146 + 0.0070 / TMath::Power(track->Pt(), 1.114758); + if (track->Pt() > 1.) sigmaZ = 0.0216; + Float_t d0maxZ = 5. * sigmaZ; + // + if(TMath::Abs(d0z0[0]) > d0max || TMath::Abs(d0z0[1]) > d0maxZ) + return kFALSE; + + /* primary DCA ok */ + return kTRUE; +} + +//_______________________________________________________ + +void +AliAnalysisTaskTOFSpectraPbPb::UserExec(Option_t *option) +{ + /* + * user exec + */ + + /*** INITIALIZATION ***/ + + /* unset fill AOD */ + ((AliAODHandler*)(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()))->SetFillAOD(kFALSE); + + /* init run */ + if (!InitRun()) return; + /* init event */ + if (!InitEvent()) return; + + /* set fill AOD */ + ((AliAODHandler*)(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()))->SetFillAOD(kTRUE); + + /*** MC PRIMARY PARTICLES ***/ + + Int_t mcmulti = 0; + + if (fMCFlag) { + + /* reset track array */ + fAnalysisParticleArray->Clear(); + + /* loop over primary particles */ + Int_t nPrimaries = fMCStack->GetNprimary(); + TParticle *particle; + TParticlePDG *particlePDG; + /* loop over primary particles */ + for (Int_t ipart = 0; ipart < nPrimaries; ipart++) { + /* check primary */ + if (!fMCStack->IsPhysicalPrimary(ipart)) continue; + /* get particle */ + particle = fMCStack->Particle(ipart); + if (!particle) continue; + /* get particlePDG */ + particlePDG = particle->GetPDG(); + if (!particlePDG) continue; + /* check charged */ + if (particlePDG->Charge() == 0.) continue; + mcmulti++; + /* check rapidity and pt cuts */ + if (TMath::Abs(particle->Y()) > fRapidityCut) continue; + if (particle->Pt() < 0.15) continue; + /* update and add analysis particle */ + fAnalysisParticle->Update(particle, ipart); + new ((*fAnalysisParticleArray)[fAnalysisParticleArray->GetEntries()]) AliAnalysisParticle(*fAnalysisParticle); + } /* end of loop over primary particles */ + + + } + + /*** GLOBAL EVENT INFORMATION ***/ + + fAnalysisEvent->Reset(); + /* update global event info */ + fAnalysisEvent->SetIsCollisionCandidate(fIsCollisionCandidate); + fAnalysisEvent->SetIsEventSelected(fIsEventSelected); + fAnalysisEvent->SetIsPileupFromSPD(fIsPileupFromSPD); + fAnalysisEvent->SetHasVertex(fHasVertex); + fAnalysisEvent->SetVertexZ(fVertexZ); + fAnalysisEvent->SetMCTimeZero(fMCTimeZero); + /* update TOF event info */ + for (Int_t i = 0; i < 10; i++) { + fAnalysisEvent->SetTimeZeroTOF(i, fESDpid->GetTOFResponse().GetT0bin(i)); + fAnalysisEvent->SetTimeZeroTOFSigma(i, fESDpid->GetTOFResponse().GetT0binRes(i)); + } + /* update T0 event info */ + for (Int_t i = 0; i < 3; i++) + fAnalysisEvent->SetTimeZeroT0(i, fESDEvent->GetT0TOF(i)); + + /* update centrality info in PbPb */ + if (fPbPbFlag) { + fAnalysisEvent->SetCentralityQuality(fCentrality->GetQuality()); + for (Int_t icent = 0; icent < AliAnalysisEvent::kNCentralityEstimators; icent++) + fAnalysisEvent->SetCentralityPercentile(icent, fCentrality->GetCentralityPercentileUnchecked(AliAnalysisEvent::fgkCentralityEstimatorName[icent])); + } + Int_t refmulti = AliESDtrackCuts::GetReferenceMultiplicity(fESDEvent, AliESDtrackCuts::kTrackletsITSTPC,0.5); + fAnalysisEvent->SetReferenceMultiplicity(refmulti); + fAnalysisEvent->SetMCMultiplicity(mcmulti); + + /*** RECONSTRUCTED TRACKS ***/ + + /* reset track array */ + fAnalysisTrackArray->Clear(); + + /* loop over ESD tracks */ + Int_t nTracks = fESDEvent->GetNumberOfTracks(); + AliESDtrack *track; + for (Int_t itrk = 0; itrk < nTracks; itrk++) { + /* get track */ + track = fESDEvent->GetTrack(itrk); + if (!track) continue; + /* check accept track */ + if (!fTrackCuts->AcceptTrack(track)) continue; + /* update and add analysis track */ + fAnalysisTrack->Update(track, fMCStack, fMCEvent); + new ((*fAnalysisTrackArray)[fAnalysisTrackArray->GetEntries()]) AliAnalysisTrack(*fAnalysisTrack); + + } /* end of loop over ESD tracks */ + +} + diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisTaskTOFSpectraPbPb.h b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisTaskTOFSpectraPbPb.h new file mode 100644 index 00000000000..4f99cecf20d --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisTaskTOFSpectraPbPb.h @@ -0,0 +1,118 @@ +#ifndef ALIANALYSISTASKTOFSPECTRAPBPB_H +#define ALIANALYSISTASKTOFSPECTRAPBPB_H + +#include "AliAnalysisTaskSE.h" +#include "AliPID.h" + +class AliESDEvent; +class AliMCEvent; +class AliStack; +class AliPhysicsSelection; +class AliESDtrackCuts; +class AliESDpid; +class AliESDtrack; +class AliTOFcalib; +class AliTOFT0maker; +class TList; +class TH1F; +class TH2F; +class TObjArray; +class AliAnalysisEvent; +class AliAnalysisTrack; +class AliAnalysisParticle; +class TClonesArray; +class AliCentrality; + +class AliAnalysisTaskTOFSpectraPbPb : +public AliAnalysisTaskSE +{ + + public: + + AliAnalysisTaskTOFSpectraPbPb(); // default constructor + virtual ~AliAnalysisTaskTOFSpectraPbPb(); // default destructor + + virtual void UserCreateOutputObjects(); // user create output objects + virtual void UserExec(Option_t *option); // user exec + + /* getters */ + AliESDtrackCuts *GetTrackCuts() const {return fTrackCuts;}; // getter + AliESDpid *GetESDpid() const {return fESDpid;}; // get ESD PID + AliTOFcalib *GetTOFcalib() const {return fTOFcalib;}; // getter + AliTOFT0maker *GetTOFT0maker() const {return fTOFT0maker;}; // getter + + /* setters */ + void SetMCFlag(Bool_t value = kTRUE) {fMCFlag = value;}; // setter + void SetMCTuneFlag(Bool_t value = kTRUE) {fMCTuneFlag = value;}; // setter + void SetPbPbFlag(Bool_t value = kTRUE) {fPbPbFlag = value;}; // setter + void SetVertexSelectionFlag(Bool_t value = kTRUE) {fVertexSelectionFlag = value;}; // setter + void SetVertexCut(Double_t value) {fVertexCut = value;}; // setter + void SetRapidityCut(Double_t value) {fRapidityCut = value;}; // setter + void SetTimeResolution(Double_t value) {fTimeResolution = value;}; // setter + void SetTrackCuts(AliESDtrackCuts *value) {fTrackCuts = value;}; // setter + + protected: + + AliAnalysisTaskTOFSpectraPbPb(const AliAnalysisTaskTOFSpectraPbPb &); // copy constructor + AliAnalysisTaskTOFSpectraPbPb &operator=(const AliAnalysisTaskTOFSpectraPbPb &); // operator= + + /* methods */ + Bool_t InitRun(); // init run + Bool_t InitEvent(); // init event + Bool_t HasPrimaryDCA(AliESDtrack *track); // has primary DCA + Bool_t MakeTPCPID(AliESDtrack *track, Double_t *nsigma, Double_t *signal); // make TPC PID + Bool_t MakeTOFPID(AliESDtrack *track, Double_t *nsigma, Double_t *signal); // make TOF PID + + /* flags */ + Bool_t fInitFlag; // init flag + Bool_t fMCFlag; // MC flag + Bool_t fMCTuneFlag; // MC tune flag + Bool_t fPbPbFlag; // PbPb flag + Bool_t fVertexSelectionFlag; // vertex selection flag + Bool_t fPrimaryDCASelectionFlag; // primary DCA selection flag + + /* ESD analysis */ + Int_t fRunNumber; // run number + UInt_t fStartTime; // start time + UInt_t fEndTime; // end time + AliESDEvent *fESDEvent; // ESD event + AliMCEvent *fMCEvent; // MC event + AliStack *fMCStack; // MC stack + AliESDtrackCuts *fTrackCuts; // track cuts + AliESDpid *fESDpid; // ESD PID + Bool_t fIsCollisionCandidate; // is collision candidate + UInt_t fIsEventSelected; // is event selected + Bool_t fIsPileupFromSPD; // is pile-up from SPD + Bool_t fHasVertex; // has vertex + Float_t fVertexZ; // vertex z + Float_t fMCTimeZero; // MC time-zero + AliCentrality *fCentrality; // centrality + + AliAnalysisEvent *fAnalysisEvent; // analysis event + TClonesArray *fAnalysisTrackArray; // analysis track array + AliAnalysisTrack *fAnalysisTrack; // analysis track + TClonesArray *fAnalysisParticleArray; // analysis particle array + AliAnalysisParticle *fAnalysisParticle; // analysis particle + + /* TOF related */ + AliTOFcalib *fTOFcalib; // TOF calib + AliTOFT0maker *fTOFT0maker; // TOF-T0 maker + Float_t fTimeResolution; // time resolution + + /*** CUTS ***/ + + /* vertex cut */ + Double_t fVertexCut; // vertex cut + Double_t fRapidityCut; // rapidity cut + + /*** HISTOGRAMS ***/ + + /* histo lists */ + TList *fHistoList; // histo list + TList *fMCHistoList; // MC histo list + + + ClassDef(AliAnalysisTaskTOFSpectraPbPb, 1); +}; + +#endif /* ALIANALYSISTASKTOFSPECTRAPBPB_H */ diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisTrack.cxx b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisTrack.cxx new file mode 100644 index 00000000000..69e533b76ab --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisTrack.cxx @@ -0,0 +1,975 @@ +#include "AliAnalysisTrack.h" +#include "AliAnalysisEvent.h" +#include "AliStack.h" +#include "AliTrackReference.h" +#include "AliMCEvent.h" +#include "TParticle.h" +#include "TDatabasePDG.h" +#include "TParticlePDG.h" +#include "TFile.h" +#include "TH2F.h" +#include "TF1.h" +#include "TMath.h" + +ClassImp(AliAnalysisTrack) + +//___________________________________________________________ + +Float_t AliAnalysisTrack::fgEtaCut = 0.8; +Float_t AliAnalysisTrack::fgEtaReject = 0.; +//TFormula *AliAnalysisTrack::fgMaxDCAToVertexXYPtDepFormula = new TFormula("f1MaxDCAToVertexXYPtDepFormula", "0.0182+0.0350/x^1.01"); +TFormula *AliAnalysisTrack::fgMaxDCAToVertexXYPtDepFormula = new TFormula("f1MaxDCAToVertexXYPtDepFormula", "0.0105+0.0350/x^1.1"); +UShort_t AliAnalysisTrack::fgMinNClustersTPC = 70; +UShort_t AliAnalysisTrack::fgMinNCrossedRowsTPC = 70; +Float_t AliAnalysisTrack::fgMinRatioCrossedRowsOverFindableClustersTPC = 0.8; +//Int_t AliAnalysisTrack::fgAcceptTrackClusterCut = 0; +Int_t AliAnalysisTrack::fgAcceptTrackClusterCut = 1; +ULong_t AliAnalysisTrack::fgAcceptTrackStatusCut = 0; +ULong_t AliAnalysisTrack::fgRejectTrackStatusCut = 0; +Float_t AliAnalysisTrack::fgMaxDCAToVertexZCut = 2.; +Float_t AliAnalysisTrack::fgMaxChi2PerClusterTPC = 4.; +Bool_t AliAnalysisTrack::fgRejectITSFakes = kFALSE; +Float_t AliAnalysisTrack::fgMatchTrackDeltaX = 10.; +Float_t AliAnalysisTrack::fgMatchTrackDeltaZ = 10.; + +//___________________________________________________________ + +TLorentzVector AliAnalysisTrack::fgLorentzVector; +AliTOFGeometry AliAnalysisTrack::fgTOFGeometry; +AliTOFcalibHisto AliAnalysisTrack::fgTOFcalibHisto; +Bool_t AliAnalysisTrack::fgTOFcalibHistoFlag = kFALSE; +AliTPCPIDResponse *AliAnalysisTrack::fgTPCResponse = NULL; +AliTOFPIDResponse *AliAnalysisTrack::fgTOFResponse = NULL; +TH2F *AliAnalysisTrack::hTOFtuned_th[AliPID::kSPECIES] = { + NULL, NULL, NULL, NULL, NULL +}; + +//___________________________________________________________ + +Float_t +AliAnalysisTrack::GetY(Float_t mass) const +{ + + fgLorentzVector.SetPtEtaPhiM(fPt, fEta, fPhi, mass); + return fgLorentzVector.Rapidity(); +} + +//___________________________________________________________ + +AliAnalysisTrack::AliAnalysisTrack() : + TObject(), + fP(), + fPt(), + fEta(), + fPhi(), + fSign(0.), + fStatus(0x0), + fLabel(0), + fImpactParameter(), + fImpactParameterCov(), + fTPCmomentum(0.), + fTPCdEdx(0.), + fTPCdEdxN(0), + fTPCNcls(0), + fTPCNclsF(0), + fTPCNcr(0.), + fTOFIndex(0), + fTOFTime(0.), + fTOFExpTime(), + fTOFLength(0.), + fTOFDeltaX(0.), + fTOFDeltaZ(0.), + fTOFLabel(), + fMCPrimary(kFALSE), + fMCPdgCode(0), + fMCMotherPrimary(kFALSE), + fMCMotherPdgCode(0), + fMCTOFMatchPrimary(kFALSE), + fMCTOFMatchPdgCode(0), + fMCTOFMatchLevel(-1), + fMCTOFTime(0.), + fMCTOFLength(0.), + fMCSecondaryWeak(kFALSE), + fMCSecondaryMaterial(kFALSE), + fHMPIDmomentum(0.), + fHMPIDsignal(0.), + fTPCchi2(0.), + fITSFakeFlag(kFALSE), + fTimeZeroSigma(0.) +{ + /* + * default constructor + */ + + /* load calib histo */ + if (!fgTOFcalibHistoFlag) { + fgTOFcalibHisto.LoadCalibHisto(); + fgTOFcalibHistoFlag = kTRUE; + } + + Double_t bbParam[6] = { /* R+ fit on minimum-bias PbPb (run 138275, pass2) */ + 5.22879e+01, + 2.80863e-02, + 2.58364e+01, + 5.15102e-07, + 2.42169e+00, + 5.38930e+00 + }; + + if (!fgTPCResponse) { + fgTPCResponse = new AliTPCPIDResponse(); + fgTPCResponse->SetMip(bbParam[0]); + fgTPCResponse->SetBetheBlochParameters(bbParam[1], bbParam[2], bbParam[3], bbParam[4], bbParam[5]); + } + + /* reset */ + Reset(); +} + +//___________________________________________________________ + +AliAnalysisTrack::AliAnalysisTrack(const AliAnalysisTrack &source) : + TObject(source), + fP(source.fP), + fPt(source.fPt), + fEta(source.fEta), + fPhi(source.fPhi), + fSign(source.fSign), + fStatus(source.fStatus), + fLabel(source.fLabel), + fImpactParameter(), + fImpactParameterCov(), + fTPCmomentum(source.fTPCmomentum), + fTPCdEdx(source.fTPCdEdx), + fTPCdEdxN(source.fTPCdEdxN), + fTPCNcls(source.fTPCNcls), + fTPCNclsF(source.fTPCNclsF), + fTPCNcr(source.fTPCNcr), + fTOFIndex(source.fTOFIndex), + fTOFTime(source.fTOFTime), + fTOFExpTime(), + fTOFLength(source.fTOFLength), + fTOFDeltaX(source.fTOFDeltaX), + fTOFDeltaZ(source.fTOFDeltaZ), + fTOFLabel(), + fMCPrimary(source.fMCPrimary), + fMCPdgCode(source.fMCPdgCode), + fMCMotherPrimary(source.fMCMotherPrimary), + fMCMotherPdgCode(source.fMCMotherPdgCode), + fMCTOFMatchPrimary(source.fMCTOFMatchPrimary), + fMCTOFMatchPdgCode(source.fMCTOFMatchPdgCode), + fMCTOFMatchLevel(source.fMCTOFMatchLevel), + fMCTOFTime(source.fMCTOFTime), + fMCTOFLength(source.fMCTOFLength), + fMCSecondaryWeak(source.fMCSecondaryWeak), + fMCSecondaryMaterial(source.fMCSecondaryMaterial), + fHMPIDmomentum(source.fHMPIDmomentum), + fHMPIDsignal(source.fHMPIDsignal), + fTPCchi2(source.fTPCchi2), + fITSFakeFlag(source.fITSFakeFlag), + fTimeZeroSigma(source.fTimeZeroSigma) +{ + /* + * copy constructor + */ + + for (Int_t i = 0; i < 2; i++) fImpactParameter[i] = source.fImpactParameter[i]; + for (Int_t i = 0; i < 3; i++) fImpactParameterCov[i] = source.fImpactParameterCov[i]; + for (Int_t i = 0; i < 5; i++) fTOFExpTime[i] = source.fTOFExpTime[i]; + for (Int_t i = 0; i < 3; i++) fTOFLabel[i] = source.fTOFLabel[i]; + +} + +//___________________________________________________________ + +AliAnalysisTrack & +AliAnalysisTrack::operator=(const AliAnalysisTrack &source) +{ + /* + * operator= + */ + + if (&source == this) return *this; + TObject::operator=(source); + + fP = source.fP; + fPt = source.fPt; + fEta = source.fEta; + fPhi = source.fPhi; + fSign = source.fSign; + fStatus = source.fStatus; + fLabel = source.fLabel; + for (Int_t i = 0; i < 2; i++) fImpactParameter[i] = source.fImpactParameter[i]; + for (Int_t i = 0; i < 3; i++) fImpactParameterCov[i] = source.fImpactParameterCov[i]; + fTPCmomentum = source.fTPCmomentum; + fTPCdEdx = source.fTPCdEdx; + fTPCdEdxN = source.fTPCdEdxN; + fTPCNcls = source.fTPCNcls; + fTPCNclsF = source.fTPCNclsF; + fTPCNcr = source.fTPCNcr; + fTOFIndex = source.fTOFIndex; + fTOFTime = source.fTOFTime; + for (Int_t i = 0; i < 5; i++) fTOFExpTime[i] = source.fTOFExpTime[i]; + fTOFLength = source.fTOFLength; + fTOFDeltaX = source.fTOFDeltaX; + fTOFDeltaZ = source.fTOFDeltaZ; + for (Int_t i = 0; i < 3; i++) fTOFLabel[i] = source.fTOFLabel[i]; + fMCPrimary = source.fMCPrimary; + fMCPdgCode = source.fMCPdgCode; + fMCMotherPrimary = source.fMCMotherPrimary; + fMCMotherPdgCode = source.fMCMotherPdgCode; + fMCTOFMatchPrimary = source.fMCTOFMatchPrimary; + fMCTOFMatchPdgCode = source.fMCTOFMatchPdgCode; + fMCTOFMatchLevel = source.fMCTOFMatchLevel; + fMCTOFTime = source.fMCTOFTime; + fMCTOFLength = source.fMCTOFLength; + fMCSecondaryWeak = source.fMCSecondaryWeak; + fMCSecondaryMaterial = source.fMCSecondaryMaterial; + fHMPIDmomentum = source.fHMPIDmomentum; + fHMPIDsignal = source.fHMPIDsignal; + fTPCchi2 = source.fTPCchi2; + fITSFakeFlag = source.fITSFakeFlag; + fTimeZeroSigma = source.fTimeZeroSigma; + + return *this; +} + +//___________________________________________________________ + +AliAnalysisTrack::~AliAnalysisTrack() +{ + /* + * default destructor + */ + +} + +//___________________________________________________________ + +void +AliAnalysisTrack::Reset() +{ + /* + * reset + */ + + fP = 0.; + fPt = 0.; + fEta = 0.; + fPhi = 0.; + fSign = 0.; + fStatus = 0; + fLabel = 0; + for (Int_t i = 0; i < 2; i++) fImpactParameter[i] = 0.; + for (Int_t i = 0; i < 3; i++) fImpactParameterCov[i] = 0.; + fTPCmomentum = 0.; + fTPCdEdx = 0.; + fTPCdEdxN = 0; + fTPCNcls = 0; + fTPCNclsF = 0; + fTPCNcr = 0.; + fTOFIndex = 0; + fTOFTime = 0.; + for (Int_t i = 0; i < 5; i++) fTOFExpTime[i] = 0.; + fTOFLength = 0.; + fTOFDeltaX = 0.; + fTOFDeltaZ = 0.; + for (Int_t i = 0; i < 3; i++) fTOFLabel[i] = 0; + fMCPrimary = kFALSE; + fMCPdgCode = 0; + fMCMotherPrimary = kFALSE; + fMCMotherPdgCode = 0; + fMCTOFMatchPrimary = kFALSE; + fMCTOFMatchPdgCode = 0; + fMCTOFMatchLevel = -1; + fMCTOFTime = 0.; + fMCTOFLength = 0.; + fMCSecondaryWeak = 0.; + fMCSecondaryMaterial = 0.; + fHMPIDmomentum = 0.; + fHMPIDsignal = 0.; + fTPCchi2 = 0.; + fITSFakeFlag = kFALSE; + fTimeZeroSigma = 0.; + +} + +//___________________________________________________________ + +void +AliAnalysisTrack::Update(AliESDtrack *track, AliStack *stack, AliMCEvent *mcevent) +{ + /* + * update + */ + + fP = track->P(); + fPt = track->Pt(); + fEta = track->Eta(); + fPhi = track->Phi(); + fSign = track->GetSign(); + fStatus = track->GetStatus(); + fLabel = track->GetLabel(); + track->GetImpactParameters(fImpactParameter, fImpactParameterCov); + fTPCmomentum = track->GetInnerParam() ? track->GetInnerParam()->P() : 0.; + fTPCdEdx = track->GetTPCsignal(); + fTPCdEdxN = track->GetTPCsignalN(); + fTPCNcls = track->GetTPCNcls(); + fTPCNclsF = track->GetTPCNclsF(); + fTPCNcr = track->GetTPCClusterInfo(2,1); + fTPCchi2 = track->GetTPCchi2(); + fITSFakeFlag = track->GetITSFakeFlag(); + fTOFIndex = track->GetTOFCalChannel(); + fTOFTime = track->GetTOFsignal(); + Double_t timei[5]; + track->GetIntegratedTimes(timei); + for (Int_t i = 0; i < 5; i++) fTOFExpTime[i] = timei[i]; + fTOFLength = track->GetIntegratedLength(); + fTOFDeltaX = track->GetTOFsignalDx(); + fTOFDeltaZ = track->GetTOFsignalDz(); + track->GetTOFLabel(fTOFLabel); + fHMPIDmomentum = track->GetOuterHmpParam() ? track->GetOuterHmpParam()->P() : 0.; + /* HMPID signal with cuts */ + Float_t xPc=0., yPc=0., xMip=0., yMip=0., thetaTrk=0., phiTrk=0.; + Int_t nPhot=0, qMip=0; + track->GetHMPIDtrk(xPc,yPc,thetaTrk,phiTrk); + track->GetHMPIDmip(xMip,yMip,qMip,nPhot); + Float_t dist = TMath::Sqrt((xPc-xMip)*(xPc-xMip) + (yPc-yMip)*(yPc-yMip)); + if (dist < 0.7 && nPhot < 30 && qMip > 100) + fHMPIDsignal = track->GetHMPIDsignal(); + else + fHMPIDsignal = 0.; + /* info from track references */ + fMCTOFTime = 0.; + fMCTOFLength = 0.; + if (mcevent && fTOFLabel[0] > 0) { + TParticle *particle; + TClonesArray *arrayTR; + AliTrackReference *trackRef; + mcevent->GetParticleAndTR(fTOFLabel[0], particle, arrayTR); + for (Int_t itr = 0; itr < arrayTR->GetEntries(); itr++) { + trackRef = (AliTrackReference *)arrayTR->At(itr); + if (!trackRef || trackRef->DetectorId() != AliTrackReference::kTOF) continue; + fMCTOFTime = trackRef->GetTime() * 1.e12; /* s -> ps */ + fMCTOFLength = trackRef->GetLength(); + /* break as soon as we get it */ + break; + } + } + /* info from stack */ + fMCPrimary = kFALSE; + fMCPdgCode = 0; + fMCMotherPrimary = kFALSE; + fMCMotherPdgCode = 0; + fMCSecondaryWeak = kFALSE; + fMCSecondaryMaterial = kFALSE; + if (stack) { + Int_t index = TMath::Abs(fLabel); + if (index < 0) { + printf("index = %d\n", index); + return; + } + TParticle *particle = stack->Particle(index); + fMCPrimary = stack->IsPhysicalPrimary(index); + fMCSecondaryWeak = stack->IsSecondaryFromWeakDecay(index); + fMCSecondaryMaterial = stack->IsSecondaryFromMaterial(index); + fMCPdgCode = particle->GetPdgCode(); + Int_t indexm = particle->GetFirstMother(); + if (indexm < 0) { + fMCMotherPrimary = kFALSE; + fMCMotherPdgCode = 0; + } + else { + TParticle *particlem = stack->Particle(indexm); + fMCMotherPrimary = stack->IsPhysicalPrimary(indexm); + fMCMotherPdgCode = particlem->GetPdgCode(); + } + + /* check TOF match */ + fMCTOFMatchPrimary = kFALSE; + fMCTOFMatchPdgCode = 0; + fMCTOFMatchLevel = -1; + if (fTOFLabel[0] > 0) { + index = fTOFLabel[0]; + particle = stack->Particle(index); + fMCTOFMatchPrimary = stack->IsPhysicalPrimary(index); + fMCTOFMatchPdgCode = particle->GetPdgCode(); + /* check match level */ + Int_t tracklabel = TMath::Abs(fLabel); + Int_t matchlevel = -1; + // printf("entering match level loop\n"); + // printf("track is a:\n"); + // stack->Particle(tracklabel)->Print(); + for (Int_t ilevel = 0; index > 0; ilevel++) { + // printf("ilevel = %d, index = %d, tracklabel = %d\n", ilevel, index, tracklabel); + // stack->Particle(index)->Print(); + if (index == tracklabel) { + matchlevel = ilevel; + // printf("break match loop at level %d\n", ilevel); + break; + } + index = stack->Particle(index)->GetFirstMother(); + } + // printf("out of match level loop: matchlevel = %d\n", matchlevel); + // if (matchlevel != 0 && matchlevel != 1) + // getchar(); + fMCTOFMatchLevel = matchlevel; + } + + } + fTimeZeroSigma = 0.; + +} + +//___________________________________________________________ + +Bool_t +AliAnalysisTrack::HasTPCPID() const +{ + /* + * has TPC PID + */ + + /* check PID signal */ + if (fTPCdEdx <= 0. || fTPCdEdxN == 0) return kFALSE; + return kTRUE; +} + +//___________________________________________________________ + +Bool_t +AliAnalysisTrack::HasTOFPID(TH1 *henabled) const +{ + /* + * has TOF PID + */ + + /* check channel enabled */ + if (henabled && henabled->GetBinContent(fTOFIndex + 1) == 0) return kFALSE; + + /* check TOF matched track */ + if (!(fStatus & AliESDtrack::kTOFout)|| + !(fStatus & AliESDtrack::kTIME)) return kFALSE; + /* check integrated length */ + if (fTOFLength < 350.) return kFALSE; + /* check deltax and deltaz */ + if (TMath::Abs(fTOFDeltaX) > fgMatchTrackDeltaX || + TMath::Abs(fTOFDeltaZ) > fgMatchTrackDeltaZ) return kFALSE; + return kTRUE; +} + +//___________________________________________________________ + +Bool_t +AliAnalysisTrack::IsTPCPID(Int_t ipart, Float_t cutTPC) const +{ + /* + * is TPC PID + */ + + Float_t nSigma[AliPID::kSPECIES]; + if (!MakeTPCPID(nSigma)) return kFALSE; + if (TMath::Abs(nSigma[ipart]) > cutTPC) return kFALSE; + return kTRUE; +} + +//___________________________________________________________ + +Bool_t +AliAnalysisTrack::MakeTPCPID(Float_t *nSigma) const +{ + /* + * make TPC PID + */ + + /* check TPC PID */ + if (!HasTPCPID()) return kFALSE; + /* loop over particles */ + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) { + Double_t bethe = fgTPCResponse->GetExpectedSignal(fTPCmomentum, (AliPID::EParticleType)ipart); + Double_t diff = fTPCdEdx - bethe; + Double_t sigma = fgTPCResponse->GetExpectedSigma(fTPCmomentum, fTPCdEdxN, (AliPID::EParticleType)ipart); + nSigma[ipart] = diff / sigma; + } + + return kTRUE; +} + +//___________________________________________________________ + +Bool_t +AliAnalysisTrack::MakeTOFPID(Float_t *nSigma) const +{ + /* + * make TOF PID + */ + + /* check TOF PID */ + if (!HasTOFPID()) return kFALSE; + + /* loop over particles */ + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) { + Double_t timez = fTOFTime - fTOFExpTime[ipart] - fgTOFResponse->GetStartTime(fP); + Double_t sigma = fgTOFResponse->GetExpectedSigma(fP, fTOFExpTime[ipart], AliPID::ParticleMass(ipart)); + nSigma[ipart] = timez / sigma; + } + + return kTRUE; +} + +//___________________________________________________________ + +Bool_t +AliAnalysisTrack::IsMismatch(const Float_t *nSigmaTPC, const Float_t *nSigmaTOF, Float_t cutTPC, Float_t cutTOF) const +{ + /* + * is mismatch + */ + + /* search for valid and compatible PID */ + Bool_t valid = kFALSE; + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) { + if (TMath::Abs(nSigmaTPC[ipart]) < cutTPC) { + valid = kTRUE; + if (TMath::Abs(nSigmaTOF[ipart]) < cutTOF) return kFALSE; + } + } + /* check valid TPC PID */ + if (!valid) return kFALSE; + /* check beta-gamma compatible */ + if (IsBetaGammaCompatible(cutTPC, cutTOF)) return kFALSE; + /* mismatch */ + return kTRUE; +} + +//___________________________________________________________ + +Bool_t +AliAnalysisTrack::IsMismatch(Float_t cutTPC, Float_t cutTOF) const +{ + /* + * is mismatch + */ + + Float_t nSigmaTPC[AliPID::kSPECIES]; + Float_t nSigmaTOF[AliPID::kSPECIES]; + Bool_t hasTPCPID = MakeTPCPID(nSigmaTPC); + Bool_t hasTOFPID = MakeTOFPID(nSigmaTOF); + /* check both TPC and TOF PID */ + if (!hasTPCPID || !hasTOFPID) return kFALSE; + return IsMismatch(nSigmaTPC, nSigmaTOF, cutTPC, cutTOF); +} + +//___________________________________________________________ + +void +AliAnalysisTrack::RemoveTimeZero(const AliAnalysisEvent *analysisEvent) +{ + /* + * remove time-zero + */ + + if (!analysisEvent) return; + fTOFTime -= analysisEvent->GetTimeZeroSafe(fP); + fTimeZeroSigma = analysisEvent->GetTimeZeroSafeSigma(fP); + // fTOFTime -= analysisEvent->GetTimeZeroBest(fP); + // fTimeZeroSigma = analysisEvent->GetTimeZeroBestSigma(fP); +} + +//___________________________________________________________ + +Bool_t +AliAnalysisTrack::IsTPCDeuton() const +{ + /* + * is TPC deuton + */ + + /* check TPC PID */ + if (!HasTPCPID()) return kFALSE; + Double_t mass = 1.8756; /* GeV */ + Double_t bethe = fgTPCResponse->Bethe(fTPCmomentum / mass); + Double_t diff = fTPCdEdx - bethe; + Double_t sigma = bethe * 0.07; + if (TMath::Abs(diff / sigma) < 5.) return kTRUE; + return kFALSE; +} + +//___________________________________________________________ + +Bool_t +AliAnalysisTrack::IsTPCTriton() const +{ + /* + * is TPC triton + */ + + /* check TPC PID */ + if (!HasTPCPID()) return kFALSE; + Double_t mass = 2. * 0.939565560 + AliPID::ParticleMass(4); /* GeV */ + Double_t bethe = fgTPCResponse->Bethe(fTPCmomentum / mass); + Double_t diff = fTPCdEdx - bethe; + Double_t sigma = bethe * 0.07; + if (TMath::Abs(diff / sigma) < 5.) return kTRUE; + return kFALSE; +} + +//___________________________________________________________ + +Bool_t +AliAnalysisTrack::IsTPCHeavy() const +{ + /* + * is TPC heavy + */ + + /* check TPC heavier than proton */ + if (!HasTPCPID()) return kFALSE; + Double_t mass = 1.8756; /* GeV */ + Double_t bethe = fgTPCResponse->Bethe(fTPCmomentum / mass); + Double_t diff = fTPCdEdx - bethe; + Double_t sigma = bethe * 0.07; + if (diff / sigma > -5.) return kTRUE; + return kFALSE; +} + +//___________________________________________________________ + +Float_t +AliAnalysisTrack::GetTOFBetaSigma() const +{ + /* + * get TOF beta sigma + */ + + Float_t tofReso = TMath::Sqrt(80. * 80. + fTimeZeroSigma * fTimeZeroSigma); + return GetTOFBeta() * tofReso / fTOFTime; +} + +//___________________________________________________________ + +Float_t +AliAnalysisTrack::GetTPCdEdxTh(Float_t betagamma) const +{ + /* + * get TPD dEdx th + */ + + return fgTPCResponse->Bethe(betagamma); +} + +//___________________________________________________________ + +Bool_t +AliAnalysisTrack::IsBetaGammaCompatible(Float_t cutTPC, Float_t cutTOF) const +{ + /* + * is beta-gamma compatible + */ + + Double_t epsilon = 1.e-10; + /* check TPC PID */ + if (!HasTPCPID()) return kTRUE; + /* get beta and sigma */ + Double_t beta = GetTOFBeta(); + Double_t betasigma = GetTOFBetaSigma(); + /* get and check beta min/max */ + Double_t betamin = beta - cutTOF * betasigma; + Double_t betamax = beta + cutTOF * betasigma; + if (betamin <= 0.) betamin = epsilon; + if (betamin >= 1.) betamin = 1. - epsilon; + if (betamax <= 0.) betamax = epsilon; + if (betamax >= 1.) betamax = 1. - epsilon; + /* check TOF beta-gamma min/max compatible with TPC dEdx */ + Double_t betagammamin = betamin / TMath::Sqrt(1. - betamin * betamin); + Double_t betagammamax = betamax / TMath::Sqrt(1. - betamax * betamax); + Double_t bethemin = fgTPCResponse->Bethe(betagammamin); + Double_t bethemax = fgTPCResponse->Bethe(betagammamax); + Double_t diffmin = fTPCdEdx - bethemin; + Double_t diffmax = fTPCdEdx - bethemax; + Double_t sigmamin = bethemin * 0.07; + Double_t sigmamax = bethemax * 0.07; + Double_t nsigmamin = diffmin / sigmamin; + Double_t nsigmamax = diffmax / sigmamax; + if (TMath::Abs(nsigmamin) < cutTPC) return kTRUE; + if (TMath::Abs(nsigmamax) < cutTPC) return kTRUE; + return kFALSE; +} + +//___________________________________________________________ + +Bool_t +AliAnalysisTrack::IsHeavyAndCompatible(const Float_t *nSigmaTOF, Float_t cutTPC, Float_t cutTOF) const +{ + /* + * is heavy and compatible + */ + + /* check TOF time larger than proton expected time */ + if (nSigmaTOF[AliPID::kProton] < cutTOF) return kFALSE; + return IsBetaGammaCompatible(cutTPC, cutTOF); +} + +//___________________________________________________________ + +Bool_t +AliAnalysisTrack::HasPrimaryDCA(Float_t nSigmaXY, Float_t nSigmaZ) const +{ + /* + * has primary DCA + */ + + // cut on transverse impact parameter + Float_t d0z0[2],covd0z0[3]; + d0z0[0] = GetImpactParameter(0); + d0z0[1] = GetImpactParameter(1); + covd0z0[0] = GetImpactParameterCov(0); + covd0z0[1] = GetImpactParameterCov(1); + covd0z0[2] = GetImpactParameterCov(2); + Float_t sigma= 0.0050 + 0.0060 / TMath::Power(fPt, 0.9); + Float_t d0max = nSigmaXY * sigma; + // + Float_t sigmaZ = 0.0146 + 0.0070 / TMath::Power(fPt, 1.114758); + if (fPt > 1.) sigmaZ = 0.0216; + Float_t d0maxZ = nSigmaZ * sigmaZ; + // + if(TMath::Abs(d0z0[0]) > d0max || TMath::Abs(d0z0[1]) > d0maxZ) + return kFALSE; + + /* primary DCA ok */ + return kTRUE; +} + +//___________________________________________________________ + +Bool_t +AliAnalysisTrack::LoadTuningExpTimeTh(const Char_t *filename) +{ + /* + * load tuning exp time th + */ + + TFile *file = TFile::Open(filename); + if (!file || !file->IsOpen()) return kFALSE; + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) + hTOFtuned_th[ipart] = (TH2F *)file->Get(Form("hTOFtuned_th_%s", AliPID::ParticleName(ipart))); + return kTRUE; + +} + +//___________________________________________________________ + +Float_t +AliAnalysisTrack::GetTuningExpTimeTh(Int_t ipart) const +{ + /* + * get tuning exp time th + */ + + if (!hTOFtuned_th[ipart]) return 0.; + if (fP > 1.5) return 0.; + Int_t bin = hTOFtuned_th[ipart]->FindBin(fP, fEta); + Float_t value = hTOFtuned_th[ipart]->GetBinContent(bin); + return value; +} + +//___________________________________________________________ + +Int_t +AliAnalysisTrack::GetTOFVolumeIndex(Int_t i) +{ + /* + * get TOF volume index + */ + + if (i < 0 || i > 4) return -1; + Int_t det[5]; + fgTOFGeometry.GetVolumeIndices(fTOFIndex, det); + return det[i]; + +} + +//___________________________________________________________ + +Int_t +AliAnalysisTrack::GetMCPID() const +{ + /* + * get MC PID + */ + + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) + if (TMath::Abs(fMCPdgCode) == AliPID::ParticleCode(ipart)) + return ipart; + return -1; + +} + +//___________________________________________________________ + +Int_t +AliAnalysisTrack::GetMCCharge() const +{ + /* + * get MC charge + */ + + TDatabasePDG *dbpdg = TDatabasePDG::Instance(); + TParticlePDG *pdg = dbpdg->GetParticle(fMCPdgCode); + if (!pdg) return 0; + return (Int_t)TMath::Sign(1., pdg->Charge()); +} + +//___________________________________________________________ + +Float_t +AliAnalysisTrack::GetTOFExpTimeSigma(Int_t i) const +{ + /* + * get TOF integrated times sigma + */ + + Double_t par[5][3] = { + {1.84217e-04, 2.50350e-04, -2.06718e+00}, + {1.84217e-04, 2.50350e-04, -2.06718e+00}, + {1.84217e-04, 2.50350e-04, -2.06718e+00}, + {1.30006e-04, 1.65197e-03, -1.21072e+00}, + {1.89219e-03, 2.06852e-03, -1.85165e+00} + }; + + return 1.5 * (par[i][0] + par[i][1] * TMath::Power(fP, par[i][2])) * fTOFExpTime[i]; + +} + +//___________________________________________________________ + +Float_t +AliAnalysisTrack::GetTOFExpTimeCorrection(Int_t i, Int_t chargeCorr) const +{ + /* + * get TOF integrated times correction + */ + + /* for both charges */ + Double_t par[AliPID::kSPECIES][5] = { + {-40., 0., 0., 0., 1.}, + {-4.26411e+00, -8.17232e+01, 2.84390e+02, -1.10976e-02, -3.76187e+00}, + {-4.26411e+00, -8.17232e+01, 2.84390e+02, -1.10976e-02, -3.76187e+00}, + {3.74297e+00, -4.90544e+03, 0.00000e+00, 0.00000e+00, -8.79427e+00}, + {3.36701e+00, 1.60189e+04, -3.43919e+04, 8.27698e-02, -6.49010e+00} + }; + /* split charges */ + Double_t parpos[AliPID::kSPECIES][2] = { + {0., 0.}, + {1.97815e+00, -1.76842e-01}, + {1.97815e+00, -1.76842e-01}, + {1.66051e+01, -8.98377e-01}, + {2.09552e+01, -3.18122e-01} + }; + Double_t parneg[AliPID::kSPECIES][2] = { + {0., 0.}, + {-5.91210e+00, -1.04768e+00}, + {-5.91210e+00, -1.04768e+00}, + {-1.58687e+01, -7.93304e-01}, + {-2.90316e+01, -4.05392e-01} + }; + + Double_t x = fP; + Double_t corr = par[i][0]+(par[i][1]*x+par[i][2]*x*x+par[i][3]*x*x*x)*TMath::Exp(par[i][4]*x); + Double_t chcorr; + if (fSign > 0.) + chcorr = parpos[i][0]*TMath::Exp(parpos[i][1]*x); + else if (fSign < 0.) + chcorr = parneg[i][0]*TMath::Exp(parneg[i][1]*x); + else + return 0.; + + return corr + chargeCorr * chcorr; +} + +//___________________________________________________________ + +void +AliAnalysisTrack::UpdateTOFResponse(AliAnalysisEvent *analysisEvent) +{ + /* + * update TOF response + */ + + fgTOFResponse->SetT0event(analysisEvent->GetTimeZeroTOF()); + fgTOFResponse->SetT0resolution(analysisEvent->GetTimeZeroTOFSigma()); +} + +//___________________________________________________________ + +Float_t +AliAnalysisTrack::GetTOFExpectedSigma(Int_t i) const +{ + /* + * get TOF expected sigma + */ + + return fgTOFResponse->GetExpectedSigma(fP, fTOFExpTime[i], AliPID::ParticleMass(i)); + +} + +//___________________________________________________________ + +void +AliAnalysisTrack::ApplyTOFExpectedTimeCorrection(Int_t chargeCorr) +{ + /* + * apply TOF expected time correction + */ + + for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++) + fTOFExpTime[ipart] += GetTOFExpTimeCorrection(ipart, chargeCorr); + +} + +//___________________________________________________________ + +Bool_t +AliAnalysisTrack::AcceptTrack(Bool_t selPrimaries) +{ + /* + * accept track + */ + + /* check charge */ + if (fSign == 0.) return kFALSE; + /* check eta */ + if (TMath::Abs(fEta) > fgEtaCut) return kFALSE; + if (TMath::Abs(fEta) < fgEtaReject) return kFALSE; + /* check max DCA to vertex Z */ + if (TMath::Abs(fImpactParameter[1]) > fgMaxDCAToVertexZCut) return kFALSE; + /* check max DCA to vertex XY */ + if (selPrimaries) { + Float_t maxdca = fgMaxDCAToVertexXYPtDepFormula->Eval(fPt); + if (TMath::Abs(fImpactParameter[0]) > maxdca) return kFALSE; + } + /* check max chi2 per cluster TPC */ + Float_t chi2 = fTPCchi2 / (Float_t)fTPCNcls; + if (chi2 > fgMaxChi2PerClusterTPC) return kFALSE; + /* check min N clusters TPC */ + if (fgAcceptTrackClusterCut != 1) { + if (fTPCNcls < fgMinNClustersTPC) return kFALSE; + } + if (fgAcceptTrackClusterCut == 1) { + /* check min N crossed rows TPC */ + if (fTPCNcr < fgMinNCrossedRowsTPC) return kFALSE; + /* check min crossed rows over findable clusters ratio */ + Float_t crratio = 1.; + if (fTPCNclsF > 0) crratio = fTPCNcr / fTPCNclsF; + if (crratio < fgMinRatioCrossedRowsOverFindableClustersTPC) return kFALSE; + } + /* check accept track status cut */ + if (fgAcceptTrackStatusCut && (fStatus & fgAcceptTrackStatusCut) == 0) return kFALSE; + /* check reject track status cut */ + if (fgRejectTrackStatusCut && (fStatus & fgRejectTrackStatusCut) != 0) return kFALSE; + /* reject ITS fakes if requested */ + if (fgRejectITSFakes && fITSFakeFlag) return kFALSE; + + /* accept track */ + return kTRUE; +} diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisTrack.h b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisTrack.h new file mode 100644 index 00000000000..e3fd83724a1 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/AliAnalysisTrack.h @@ -0,0 +1,220 @@ +#ifndef ALIANALYSISTRACK_H +#define ALIANALYSISTRACK_H + +#include "TObject.h" +#include "TMath.h" +#include "TLorentzVector.h" +#include "AliTOFGeometry.h" +#include "AliTOFcalibHisto.h" +#include "AliTPCPIDResponse.h" +#include "AliTOFPIDResponse.h" +#include "AliAnalysisEvent.h" +#include "AliESDtrack.h" +#include "AliPID.h" +#include "TF1.h" + +class AliStack; +class AliMCEvent; +class TH2F; +class TH1; + +class AliAnalysisTrack : +public TObject +{ + + public: + + AliAnalysisTrack(); // default constructor + AliAnalysisTrack(const AliAnalysisTrack &source); // copy constructor + AliAnalysisTrack &operator=(const AliAnalysisTrack &source); // operator= + virtual ~AliAnalysisTrack(); // default destructor + + Float_t GetP() const {return fP;}; // get p + Float_t GetPt() const {return fPt;}; // get pt + Float_t GetEta() const {return fEta;}; // get eta + Float_t GetPhi() const {return fPhi;}; // get phi + Float_t GetY(Float_t mass) const; // get Y + Double_t GetSign() const {return fSign;}; // get sign + ULong_t GetStatus() const {return fStatus;}; // get status + Int_t GetLabel() const {return fLabel;}; // get label + Float_t GetImpactParameter(Int_t i) const {return fImpactParameter[i];}; // get impact parameter + Float_t GetImpactParameterCov(Int_t i) const {return fImpactParameterCov[i];}; // get impact parameter covariance + Float_t GetTPCmomentum() const {return fTPCmomentum;}; // get TPC inner wall momentum + Float_t GetTPCdEdx() const {return fTPCdEdx;}; // get TPC dEdx + UShort_t GetTPCdEdxN() const {return fTPCdEdxN;}; // get TPC dEdx clusters + UShort_t GetTPCNcls() const {return fTPCNcls;}; // get number of clusters TPC + UShort_t GetTPCNclsF() const {return fTPCNclsF;}; // get number of findable clusters TPC + Float_t GetTPCnc() const {return fTPCNcr;}; // get number of crossed rows TPC + Int_t GetTOFIndex() const {return fTOFIndex;}; // get TOF index + Float_t GetTOFTime() const {return fTOFTime;}; // get TOF time + Float_t GetTOFExpTime(Int_t i) const {return fTOFExpTime[i];}; // get TOF integrated times + Float_t GetTOFExpTimeCorrection(Int_t i, Int_t chargeCorr = 0) const; // get TOF integrated times correction + Float_t GetTOFExpTimeSigma(Int_t i) const; // get TOF integrated times sigma + Float_t GetTOFExpectedSigma(Int_t i) const; // get TOF expected sigma + Float_t GetTOFLength() const {return fTOFLength;}; // get TOF length + Int_t GetTOFLabel(Int_t i) const {return fTOFLabel[i];}; // get TOF label + Float_t GetTOFDeltaX() const {return fTOFDeltaX;}; // get TOF deltaX + Float_t GetTOFDeltaZ() const {return fTOFDeltaZ;}; // get TOF deltaZ + Bool_t IsMCPrimary() const {return fMCPrimary;}; // is MC primary + Bool_t IsMCSecondaryWeakDecay() const {return fMCSecondaryWeak;}; // is MC weak decay + Bool_t IsMCSecondaryMaterial() const {return fMCSecondaryMaterial;}; // is MC material + Bool_t IsMCPrimary(Int_t ipart) const {return (fMCPrimary && TMath::Abs(fMCPdgCode) == AliPID::ParticleCode(ipart));}; // is MC primary + Int_t GetMCPdgCode() const {return fMCPdgCode;}; // get MC PDG code + Int_t GetMCMotherPdgCode() const {return fMCMotherPdgCode;}; // get MC mother PDG code + Int_t GetMCMotherPrimary() const {return fMCMotherPrimary;}; // get MC mother primary + + Bool_t IsMCTOFMatchPrimary() const {return fMCTOFMatchPrimary;}; + Int_t GetMCTOFMatchPdgCode() const {return fMCTOFMatchPdgCode;}; + Int_t GetMCTOFMatchLevel() const {return fMCTOFMatchLevel;}; + Float_t GetMCTOFTime() const {return fMCTOFTime;}; + Float_t GetMCTOFLength() const {return fMCTOFLength;}; + + Bool_t IsInTOFPad() const {return ((TMath::Abs(fTOFDeltaX) < 1.25) && (TMath::Abs(fTOFDeltaZ) < 1.75));}; // is in TOF pad + + Int_t GetTOFVolumeIndex(Int_t i); // get TOF volume index + Float_t GetTOFBeta() const {return HasTOFPID() ? fTOFLength / (2.99792457999999984e-02 * (fTOFTime - fgTOFResponse->GetStartTime(fP))) : 0.;}; // get TOF beta + Float_t GetTOFBetaSigma() const; // get TOF beta sigma + Float_t GetTOFExpBeta(Int_t ipart) const {return HasTOFPID() ? fTOFLength / (2.99792457999999984e-02 * fTOFExpTime[ipart]) : 0.;}; // get TOF beta + Float_t GetTOFBetaTh(Int_t ipart) const {return GetTOFBetaTh(AliPID::ParticleMass(ipart));}; // get TOF beta th + Float_t GetTOFBetaTPCin(Int_t ipart) const {return GetTOFBetaTPCin(AliPID::ParticleMass(ipart));}; // get TOF beta th + Float_t GetTOFBetaTh(Float_t mass) const {return TMath::Sqrt(1. / (1. + mass * mass / (fP * fP)));}; // get TOF beta th + Float_t GetTOFBetaTPCin(Float_t mass) const {return TMath::Sqrt(1. / (1. + mass * mass / (fTPCmomentum * fTPCmomentum)));}; // get TOF beta th + Float_t GetTOFMass2() const {return fP * fP * (1. / (GetTOFBeta() * GetTOFBeta()) - 1.);}; // get TOF mass^2 + Float_t GetTOFMass() const {return GetTOFMass2() > 0. ? TMath::Sqrt(TMath::Abs(GetTOFMass2())) : -TMath::Sqrt(TMath::Abs(GetTOFMass2()));}; // get TOF mass + Float_t GetTPCdEdxTh(Float_t betagamma) const; // get TPC dEdx th + Float_t GetTOFExpTimeTh(Int_t ipart) const {return fTOFLength / 2.99792457999999984e-02 / GetTOFBetaTh(ipart);}; // get TOF exp time th + Float_t GetTOFExpTimeTPCin(Int_t ipart) const {return fTOFLength / 2.99792457999999984e-02 / GetTOFBetaTPCin(ipart);}; // get TOF exp time th + Float_t GetTuningExpTimeTh(Int_t ipart) const; // get tuning exp time th + Float_t GetTPCBetaGamma(Int_t ipart) const {return fTPCmomentum / AliPID::ParticleMass(ipart);}; // get TPC beta-gamma + + void Reset(); // reset + void Update(AliESDtrack *track, AliStack *stack, AliMCEvent *mcevent); // update + Bool_t HasTOFMatch() const {return (fStatus & AliESDtrack::kTOFout);}; // has TOF match + Bool_t HasIntegratedTimes() const{ return (fStatus & AliESDtrack::kTIME);}; // has integrated times + Bool_t HasTPCPID() const; // has TPC PID + Bool_t HasTOFPID(TH1 *henabled = NULL) const; // has TOF PID + Bool_t MakeTPCPID(Float_t *nSigma) const; // make TPC PID + Bool_t MakeTOFPID(Float_t *nSigma) const; // make TOF PID + Bool_t IsMismatchMC() const {return (fMCTOFMatchLevel != 0);}; // is mismatch MC + Int_t GetMCPID() const; // get MC PID + Int_t GetMCCharge() const; // get MC charge + Bool_t IsUncorrelatedMismatchMC() const {return (fMCTOFMatchLevel < 0);}; // is uncorreltaed mismatch MC + Bool_t IsMismatch(Float_t cutTPC = 5., Float_t cutTOF = 5.) const; // is mismatch + Bool_t IsMismatch(const Float_t *nSigmaTPC, const Float_t *nSigmaTOF, Float_t cutTPC = 5., Float_t cutTOF = 5.) const; // is mismatch + Bool_t IsBetaGammaCompatible(Float_t cutTPC = 5., Float_t cutTOF = 5.) const; // is beta-gamma compatible + Bool_t IsHeavyAndCompatible(const Float_t *nSigmaTOF, Float_t cutTPC = 5., Float_t cutTOF = 5.) const; // is heavy and compatible + void RemoveTimeZero(const AliAnalysisEvent *analysisEvent); // remove time-zero + Bool_t IsTPCPID(Int_t ipart, Float_t cutTPC = 5.) const; // is TPC PID + Bool_t IsTPCDeuton() const; // is TPC deuton + Bool_t IsTPCTriton() const; // is TPC deuton + Bool_t IsTPCHeavy() const; // is TPC heavy + Bool_t HasPrimaryDCA(Float_t nSigmaXY = 7., Float_t nSigmaZ = 5.) const; // has primary DCA + Bool_t IsTRDin() const {return fStatus & AliESDtrack::kTRDin;}; // is TRD in + Bool_t IsTRDout() const {return fStatus & AliESDtrack::kTRDout;}; // is TRD out + Bool_t IsTRDrefit() const {return fStatus & AliESDtrack::kTRDrefit;}; // is TRD refit + Bool_t IsTOFout() const {return fStatus & AliESDtrack::kTOFout;}; // is TOF out + + static Bool_t LoadTuningExpTimeTh(const Char_t *filename); // load tuning exp time th + + Int_t GetTOFCalibIndex(Int_t imap) {return (Int_t)fgTOFcalibHisto.GetCalibMap(imap, fTOFIndex);}; // get TOF calib index + + static AliTOFPIDResponse *GetTOFResponse() {return fgTOFResponse;}; // getter + static AliTPCPIDResponse *GetTPCResponse() {return fgTPCResponse;}; // getter + static void SetTOFResponse(AliTOFPIDResponse *value) {fgTOFResponse = value;}; // setter + static void SetTPCResponse(AliTPCPIDResponse *value) {fgTPCResponse = value;}; // setter + + static void UpdateTOFResponse(AliAnalysisEvent *analysisEvent); // update TOF response + + void ApplyTOFExpectedTimeCorrection(Int_t chargeCorr = 0); // apply expected time correction + + Bool_t AcceptTrack(Bool_t selPrimaries = kTRUE); // accept track + static void SetAcceptTrackMinNClustersTPC(UShort_t value) {fgMinNClustersTPC = value;}; // setter + static void SetAcceptTrackClusterCut(Int_t value) {fgAcceptTrackClusterCut = value;}; // setter + static void SetAcceptTrackMaxDCAToVertexXYPtDepFormula(TFormula *formula) {fgMaxDCAToVertexXYPtDepFormula = formula;}; // setter + static void SetAcceptTrackEtaCut(Float_t value) {fgEtaCut = value;}; // setter + static void SetAcceptTrackEtaReject(Float_t value) {fgEtaReject = value;}; // setter + static void SetAcceptTrackStatusCut(ULong_t value) {fgAcceptTrackStatusCut = value;}; // setter + static void SetRejectTrackStatusCut(ULong_t value) {fgRejectTrackStatusCut = value;}; // setter + static void SetAcceptTrackMaxDCAToVertexZCut(Float_t value) {fgMaxDCAToVertexZCut = value;}; // setter + static void SetAcceptTrackMaxChi2PerClusterTPC(Float_t value) {fgMaxChi2PerClusterTPC = value;}; // setter + static void SetRejectITSFakes(Bool_t value) {fgRejectITSFakes = value;}; // setter + static void SetMatchTrackDeltaX(Float_t value) {fgMatchTrackDeltaX = value;}; // setter + static void SetMatchTrackDeltaZ(Float_t value) {fgMatchTrackDeltaZ = value;}; // setter + + private: + + /*** global track info ***/ + Float_t fP; // p + Float_t fPt; // pt + Float_t fEta; // eta + Float_t fPhi; // phi + Double_t fSign; // sign + ULong_t fStatus; // status + Int_t fLabel; // label + Float_t fImpactParameter[2]; // impact parameters + Float_t fImpactParameterCov[3]; // impact parameters covariance + /*** TPC PID info ***/ + Float_t fTPCmomentum; // TPC inner wall momentum + Float_t fTPCdEdx; // dEdx + UShort_t fTPCdEdxN; // dEdx clusters + UShort_t fTPCNcls; // number of clusters TPC + UShort_t fTPCNclsF; // number of findable clusters TPC + Float_t fTPCNcr; // number of crossed rows TPC + /*** TOF PID info ***/ + Int_t fTOFIndex; // index + Float_t fTOFTime; // time + Float_t fTOFExpTime[AliPID::kSPECIES]; // integrated time array + Float_t fTOFLength; // track length + Float_t fTOFDeltaX; // TOF deltaX + Float_t fTOFDeltaZ; // TOF deltaZ + Int_t fTOFLabel[3]; // TOF label + /*** MC info ***/ + Bool_t fMCPrimary; // MC primary flag + Int_t fMCPdgCode; // MC PDG code + Bool_t fMCMotherPrimary; // MC mother primary flag + Int_t fMCMotherPdgCode; // MC mother PDG code + Bool_t fMCTOFMatchPrimary; // MC TOF match primary flag + Int_t fMCTOFMatchPdgCode; // MC TOF match PDG code + Short_t fMCTOFMatchLevel; // MC TOF match level + Float_t fMCTOFTime; // MC TOF time + Float_t fMCTOFLength; // MC TOF length + Bool_t fMCSecondaryWeak; + Bool_t fMCSecondaryMaterial; + /*** HMPID PID info ***/ + Float_t fHMPIDmomentum; + Float_t fHMPIDsignal; + /*** extras ***/ + Float_t fTPCchi2; // TPC chi2 + Bool_t fITSFakeFlag; // ITS fake flag + + /*** cut paramters */ + static Float_t fgEtaCut; // eta cut + static Float_t fgEtaReject; // eta reject + static TFormula *fgMaxDCAToVertexXYPtDepFormula; // DCA-xy cut formula + static UShort_t fgMinNClustersTPC; // cut + static UShort_t fgMinNCrossedRowsTPC; // cut + static Float_t fgMinRatioCrossedRowsOverFindableClustersTPC; // cut + static Int_t fgAcceptTrackClusterCut; // cluster cut + static ULong_t fgAcceptTrackStatusCut; // accept track status cut + static ULong_t fgRejectTrackStatusCut; // reject track status cut + static Float_t fgMaxDCAToVertexZCut; // DCA-z cut + static Float_t fgMaxChi2PerClusterTPC; // max chi2 per cluster TPC cut + static Bool_t fgRejectITSFakes; // reject ITS fakes cut + static Float_t fgMatchTrackDeltaX; // match track deltaX + static Float_t fgMatchTrackDeltaZ; // match track deltaZ + + /*** tools ***/ + static TLorentzVector fgLorentzVector; + static AliTOFGeometry fgTOFGeometry; + static AliTOFcalibHisto fgTOFcalibHisto; + static Bool_t fgTOFcalibHistoFlag; + static AliTPCPIDResponse *fgTPCResponse; + static AliTOFPIDResponse *fgTOFResponse; + static TH2F *hTOFtuned_th[AliPID::kSPECIES]; + + Float_t fTimeZeroSigma; //! + + ClassDef(AliAnalysisTrack, 9); +}; + +#endif /* ALIANALYSISTRACK_H */ diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/Makefile b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/Makefile new file mode 100644 index 00000000000..4eabf10cf77 --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/Makefile @@ -0,0 +1,13 @@ +SRC = AddAnalysisTaskTOFSpectraPbPb.C \ + AliAnalysisEvent.cxx \ + AliAnalysisEvent.h \ + AliAnalysisParticle.cxx \ + AliAnalysisParticle.h \ + AliAnalysisTaskTOFSpectraPbPb.cxx \ + AliAnalysisTaskTOFSpectraPbPb.h \ + AliAnalysisTrack.cxx \ + AliAnalysisTrack.h \ + SteerAnalysisTaskTOFSpectraPbPb.C + +tar: + tar zcvf TOFSpectraPbPb.tgz $(SRC) \ No newline at end of file diff --git a/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/SteerAnalysisTaskTOFSpectraPbPb.C b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/SteerAnalysisTaskTOFSpectraPbPb.C new file mode 100644 index 00000000000..80cbb4cfddf --- /dev/null +++ b/PWGLF/SPECTRA/PiKaPr/TOF/pPb502/task/SteerAnalysisTaskTOFSpectraPbPb.C @@ -0,0 +1,125 @@ +SteerAnalysisTaskTOFSpectraPbPb(const Char_t *inputfilename, Bool_t mcFlag = kFALSE, Bool_t mcTuneFlag = kFALSE, Bool_t pbpbFlag = kTRUE, Int_t maxFiles = kMaxInt, Int_t maxEv = kMaxInt) +{ + + /* include path for ACLic */ + gSystem->AddIncludePath("-I$ALICE_ROOT/include"); + gSystem->AddIncludePath("-I$ALICE_ROOT/TOF"); + /* load libraries */ + gSystem->Load("libANALYSIS"); + gSystem->Load("libANALYSISalice"); + gSystem->Load("libTENDER"); + gSystem->Load("libTENDERSupplies"); + /* build analysis task class */ + gROOT->LoadMacro("AliAnalysisParticle.cxx+g"); + gROOT->LoadMacro("AliAnalysisEvent.cxx+g"); + gROOT->LoadMacro("AliAnalysisTrack.cxx+g"); + gROOT->LoadMacro("AliAnalysisTaskTOFSpectraPbPb.cxx+g"); + + /* Setup input chain */ + TString str = inputfilename; + const Char_t *filename; + TChain *chain = new TChain("esdTree"); + if (str.EndsWith(".xml")) { + TGrid::Connect("alien://"); + Info("SteerTaskTOFSpectraPbPb", "reading data list from collection:"); + TAlienCollection coll(inputfilename, maxFiles); + coll.Reset(); + while (coll.Next()) { + filename = coll.GetTURL(); + Info("SteerTaskTOFSpectraPbPb", Form("%s", filename)); + chain->Add(filename); + } + } + else if (str.EndsWith(".txt")) { + Info("SteerTaskTOFSpectraPbPb", "reading data list from text file:"); + ifstream is(inputfilename); + Char_t buf[4096]; + while(!is.eof()) { + is.getline(buf, 4096); + if (is.eof()) break; + chain->Add(buf); + Info("SteerTaskTOFSpectraPbPb", Form("%s", buf)); + } + is.close(); + } + else { + Info("SteerTaskTOFSpectraPbPb", "single file:"); + filename = inputfilename; + Info("SteerTaskTOFSpectraPbPb", Form("%s", filename)); + chain->Add(filename); + } + Info("SteerTaskTOFSpectraPbPb", Form("chain is ready: %d events", chain->GetEntries())); + + /* create analysis manager */ + AliAnalysisManager *mgr = new AliAnalysisManager("TOFSpectraPbPb"); + + /* define input event handler */ + AliESDInputHandler *esdh = new AliESDInputHandler(); + esdh->SetReadFriends(kFALSE); + mgr->SetInputEventHandler(esdh); + + /* define MC truth event handler */ + if (mcFlag) { + AliMCEventHandler *mch = new AliMCEventHandler(); + mgr->SetMCtruthEventHandler(mch); + } + + /* define output handler */ + AliAODHandler *outputh = new AliAODHandler(); + mgr->SetOutputEventHandler(outputh); + + /* add tasks */ + +#if 0 + gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C"); + AddTaskPIDResponse(); + + gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/TenderSupplies/AddTaskTender.C"); + AddTaskTender(kFALSE, + kFALSE, + kTRUE, + kFALSE, + kFALSE, + kFALSE, + kFALSE, + kFALSE, + kFALSE); +#endif + + /* create tender, setup and add to manager */ + AliTender *tender = new AliTender("TENDER"); + tender->SetCheckEventSelection(kFALSE); /* was kFALSE */ + tender->SetDefaultCDBStorage("raw://"); + mgr->AddTask(tender); + mgr->ConnectInput(tender, 0, inputc); + mgr->ConnectOutput(tender, 1, outputc); + AliTOFTenderSupply *TOFtender = new AliTOFTenderSupply("TOF-TENDER"); + tender->AddSupply(TOFtender); + + gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C"); + AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(mcFlag); + + /* pA trigger fix */ + // gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/PhysicsSelectionOADB_CINT5_pA.C"); + // AliOADBPhysicsSelection *oadb = OADBSelection_CINT5_V0AND(); + // physSelTask->GetPhysicsSelection()->SetCustomOADBObjects(oadb,0); + + if (pbpbFlag) { + gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C"); + AliCentralitySelectionTask *centralityTask = AddTaskCentrality(); + // centralityTask->SetPass(2); + if (mcFlag) centralityTask->SetMCInput(); + } + gROOT->LoadMacro("AddAnalysisTaskTOFSpectraPbPb.C"); + AliAnalysisTaskTOFSpectraPbPb *thisTask = AddAnalysisTaskTOFSpectraPbPb(mcFlag, mcTuneFlag, pbpbFlag); + + /* start analysis */ + mgr->SetDebugLevel(0); + if (!mgr->InitAnalysis()) return; + mgr->PrintStatus(); + mgr->StartAnalysis("local", chain, maxEv); + + /* create dummy file to tell we are done */ + gSystem->Exec("touch done"); + +} -- 2.39.3