]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGHF/vertexingHF/AliHFPtSpectrum.h
Set bin labels to avoid warning when merging
[u/mrichter/AliRoot.git] / PWGHF / vertexingHF / AliHFPtSpectrum.h
1 #ifndef ALIHFPTSPECTRUM_H
2 #define ALIHFPTSPECTRUM_H
3
4 /* Copyright(c) 1998-2010, ALICE Experiment at CERN, All rights reserved. *
5  * See cxx source for full Copyright notice                               */
6
7 /* $Id$ */ 
8
9 //***********************************************************************
10 // Class AliHFPtSpectrum
11 // Base class for feed-down corrections on heavy-flavour decays
12 // computes the cross-section via one of the three implemented methods:
13 //   0) Consider no feed-down prediction 
14 //   1) Subtract the feed-down with the "fc" method 
15 //       Yield = Reco * fc;  where fc = 1 / ( 1 + (eff_b/eff_c)*(N_b/N_c) ) ;
16 //   2) Subtract the feed-down with the "Nb" method
17 //       Yield = Reco - Feed-down (exact formula on the function implementation)
18 //
19 //  (the corrected yields per bin are divided by the bin-width)
20 //
21 //
22 //  In HIC you can also evaluate how the feed-down correction is influenced by an energy loss hypothesis: 
23 //      Raa(c-->D) / Raa(b-->D) defined here as Rcb for the "fc" method
24 //      Raa(b-->D) defined here as Rb for the "Nb" method
25 //
26 // Author: Z.Conesa, zconesa@in2p3.fr
27 //***********************************************************************
28
29 #include "TNamed.h"
30 #include "TMath.h"
31
32 #include "AliLog.h"
33
34 class TH1;
35 class TH2;
36 class TNtuple;
37 class TGraphAsymmErrors;
38
39
40 class AliHFPtSpectrum: public TNamed
41 {
42
43  public:
44   
45   // Constructor
46   AliHFPtSpectrum(const char* name="AliHFPtSpectrum", const char* title="HF feed down correction class", Int_t option=1);
47   // Copy constructor
48   AliHFPtSpectrum(const AliHFPtSpectrum &rhs);
49   // Assignment operator
50   AliHFPtSpectrum& operator=(const AliHFPtSpectrum &source);
51   // Destructor
52   virtual ~AliHFPtSpectrum();
53
54   //
55   // Setters
56   //
57   // Set the theoretical direct & feeddown pt spectrum
58   void SetMCptSpectra(TH1D *hDirect, TH1D *hFeedDown);
59   // Set the theoretical feeddown pt spectrum
60   void SetFeedDownMCptSpectra(TH1D *hFeedDown);
61   // Set the theoretical direct & feeddown pt spectrum upper and lower bounds
62   void SetMCptDistributionsBounds(TH1D *hDirectMax, TH1D *hDirectMin, TH1D *hFeedDownMax, TH1D *hFeedDownMin);
63   // Set the theoretical feeddown pt spectrum upper and lower bounds
64   void SetFeedDownMCptDistributionsBounds(TH1D *hFeedDownMax, TH1D *hFeedDownMin);
65   // Set the acceptance and efficiency corrections for direct  
66   void SetDirectAccEffCorrection(TH1D *hDirectEff);
67   // Set the acceptance and efficiency corrections for direct & feeddown 
68   void SetAccEffCorrection(TH1D *hDirectEff, TH1D *hFeedDownEff);
69   // Set the reconstructed spectrum
70   void SetReconstructedSpectrum(TH1D *hRec);
71   void SetReconstructedSpectrumSystematics(TGraphAsymmErrors *gRec); 
72   // Set the calculation option flag for feed-down correction: 0=none, 1=fc , 2=Nb 
73   void SetFeedDownCalculationOption(Int_t option){ fFeedDownOption = option; }
74   // Set if the calculation has to consider asymmetric uncertaInt_ties or not
75   void SetComputeAsymmetricUncertainties(Bool_t flag){ fAsymUncertainties = flag; }
76   // Set if the yield is for particle plus anti-particle or not
77   void SetIsParticlePlusAntiParticleYield(Bool_t flag){
78     if (flag) { fParticleAntiParticle = 2; AliInfo(" Setting for particle + anti-particle yields"); }
79     else { fParticleAntiParticle = 1; AliInfo(" Setting for only (anti)particle yields, not the sum of both"); }
80   }
81   //
82   void SetfIsStatUncEff(Bool_t flag){ fIsStatUncEff = flag; }
83   // Set if the calculation has to consider Ratio(c/b eloss) hypothesis 
84   void SetComputeElossHypothesis(Bool_t flag){ fPbPbElossHypothesis = flag; }
85   // Set the luminosity and its uncertainty
86   void SetLuminosity(Double_t luminosity, Double_t unc){
87     fLuminosity[0]=luminosity;  fLuminosity[1]=unc;
88   }
89   // Set the trigger efficiency and its uncertainty
90   void SetTriggerEfficiency(Double_t efficiency, Double_t unc){
91     fTrigEfficiency[0]=efficiency; fTrigEfficiency[1]=unc;
92   }
93   // Set global acceptance x efficiency correction uncertainty (in percentages)
94   void SetAccEffPercentageUncertainty(Double_t globalEffUnc, Double_t globalBCEffRatioUnc){
95     fGlobalEfficiencyUncertainties[0] = globalEffUnc;
96     fGlobalEfficiencyUncertainties[1] = globalBCEffRatioUnc;
97   }
98   // Set the normalization factors
99   void SetNormalization(Double_t normalization){
100     fLuminosity[0]=normalization;
101   }
102   void SetNormalization(Int_t nevents, Double_t sigma){
103     fLuminosity[0]=nevents/sigma;
104     fNevts = nevents;
105   }
106   void SetNormalization(Int_t nevents, Double_t sigma, Double_t sigmaunc){
107     fLuminosity[0] = nevents/sigma; 
108     fLuminosity[1] = fLuminosity[0] * TMath::Sqrt( (1/nevents) + (sigmaunc/sigma)*(sigmaunc/sigma) );
109     fNevts = nevents;
110   }
111   //
112   // Set the Tab parameter and its uncertainty
113   void SetTabParameter(Double_t tabvalue, Double_t uncertainty){
114     fTab[0] = tabvalue;
115     fTab[1] = uncertainty;
116   }
117
118
119   //
120   // Getters
121   //
122   // Return the theoretical predictions used for the calculation (rebinned if needed)
123   TH1D * GetDirectTheoreticalSpectrum() const { return (fhDirectMCpt ? (TH1D*)fhDirectMCpt : NULL); }
124   TH1D * GetDirectTheoreticalUpperLimitSpectrum() const { return (fhDirectMCptMax ? (TH1D*)fhDirectMCptMax : NULL); }
125   TH1D * GetDirectTheoreticalLowerLimitSpectrum() const { return (fhDirectMCptMin ? (TH1D*)fhDirectMCptMin : NULL); }
126   TH1D * GetFeedDownTheoreticalSpectrum() const { return (fhFeedDownMCpt ? (TH1D*)fhFeedDownMCpt : NULL); }
127   TH1D * GetFeedDownTheoreticalUpperLimitSpectrum() const { return (fhFeedDownMCptMax ? (TH1D*)fhFeedDownMCptMax : NULL); }
128   TH1D * GetFeedDownTheoreticalLowerLimitSpectrum() const { return (fhFeedDownMCptMin ? (TH1D*)fhFeedDownMCptMin : NULL); }
129   // Return the acceptance and efficiency corrections (rebinned if needed)
130   TH1D * GetDirectAccEffCorrection() const { return (fhDirectEffpt ? (TH1D*)fhDirectEffpt : NULL); }
131   TH1D * GetFeedDownAccEffCorrection() const { return (fhFeedDownEffpt ? (TH1D*)fhFeedDownEffpt : NULL); }
132   // Return whether the Ratio(c/b eloss) hypothesis has been considered
133   Bool_t IsElossHypothesisCalculated(){ return fPbPbElossHypothesis; }
134   // Return the TGraphAsymmErrors of the feed-down correction (extreme systematics)
135   TGraphAsymmErrors * GetFeedDownCorrectionFcExtreme() const { return (fgFcExtreme ?  fgFcExtreme : NULL); }
136   // Return the TGraphAsymmErrors of the feed-down correction (conservative systematics)
137   TGraphAsymmErrors * GetFeedDownCorrectionFcConservative() const { return (fgFcConservative ?  fgFcConservative : NULL); }
138   // Return the histogram of the feed-down correction
139   TH1D * GetHistoFeedDownCorrectionFc() const { return (fhFc ?  (TH1D*)fhFc : NULL); }
140   // Return the histograms of the feed-down correction bounds
141   TH1D * GetHistoUpperLimitFeedDownCorrectionFc() const { return (fhFcMax ? (TH1D*)fhFcMax : NULL); }
142   TH1D * GetHistoLowerLimitFeedDownCorrectionFc() const { return (fhFcMin ? (TH1D*)fhFcMin : NULL); }
143   // Return the histogram of the feed-down correction times the Ratio(c/b eloss)
144   TH2D * GetHistoFeedDownCorrectionFcVsEloss() const { return (fhFcRcb ?  (TH2D*)fhFcRcb : NULL); }
145   // Return the TGraphAsymmErrors of the yield after feed-down correction (systematics but feed-down) 
146   TGraphAsymmErrors * GetFeedDownCorrectedSpectrum() const { return (fgYieldCorr ? fgYieldCorr : NULL); }
147   // Return the TGraphAsymmErrors of the yield after feed-down correction (feed-down extreme systematics)
148   TGraphAsymmErrors * GetFeedDownCorrectedSpectrumExtreme() const { return (fgYieldCorrExtreme ? fgYieldCorrExtreme : NULL); }
149   // Return the TGraphAsymmErrors of the yield after feed-down correction (feed-down conservative systematics)
150   TGraphAsymmErrors * GetFeedDownCorrectedSpectrumConservative() const { return (fgYieldCorrConservative ? fgYieldCorrConservative : NULL); }
151   // Return the histogram of the yield after feed-down correction 
152   TH1D * GetHistoFeedDownCorrectedSpectrum() const { return (fhYieldCorr ? (TH1D*)fhYieldCorr : NULL); }
153   // Return the histogram of the yield after feed-down correction bounds
154   TH1D * GetHistoUpperLimitFeedDownCorrectedSpectrum() const { return (fhYieldCorrMax ? (TH1D*)fhYieldCorrMax : NULL); }
155   TH1D * GetHistoLowerLimitFeedDownCorrectedSpectrum() const { return (fhYieldCorrMin ? (TH1D*)fhYieldCorrMin : NULL); }
156   // Return the histogram of the yield after feed-down correction vs the Ratio(c/b eloss)
157   TH2D * GetHistoFeedDownCorrectedSpectrumVsEloss() const { return (fhYieldCorrRcb ? (TH2D*)fhYieldCorrRcb : NULL); }
158   // Return the equivalent invariant cross-section TGraphAsymmErrors (systematics but feed-down) 
159   TGraphAsymmErrors * GetCrossSectionFromYieldSpectrum() const { return (fgSigmaCorr ? fgSigmaCorr : NULL); }
160   // Return the equivalent invariant cross-section TGraphAsymmErrors (feed-down extreme systematics)
161   TGraphAsymmErrors * GetCrossSectionFromYieldSpectrumExtreme() const { return (fgSigmaCorrExtreme ? fgSigmaCorrExtreme : NULL); }
162   // Return the equivalent invariant cross-section TGraphAsymmErrors (feed-down conservative systematics)
163   TGraphAsymmErrors * GetCrossSectionFromYieldSpectrumConservative() const { return (fgSigmaCorrConservative ? fgSigmaCorrConservative : NULL); }
164   // Return the equivalent invariant cross-section histogram
165   TH1D * GetHistoCrossSectionFromYieldSpectrum() const { return (fhSigmaCorr ? (TH1D*)fhSigmaCorr : NULL); }
166   // Return the equivalent invariant cross-section histogram bounds
167   TH1D * GetHistoUpperLimitCrossSectionFromYieldSpectrum() const { return (fhSigmaCorrMax ? (TH1D*)fhSigmaCorrMax : NULL); }
168   TH1D * GetHistoLowerLimitCrossSectionFromYieldSpectrum() const { return (fhSigmaCorrMin ? (TH1D*)fhSigmaCorrMin : NULL); }
169   // Return the cross section systematics from data systematics
170   TH1D * GetHistoCrossSectionDataSystematics() const { return (fhSigmaCorrDataSyst ? (TH1D*)fhSigmaCorrDataSyst : NULL); }
171   //
172   // PbPb special calculations 
173   // Return the equivalent invariant cross-section histogram vs the Ratio(c/b eloss)
174   TH2D * GetHistoCrossSectionFromYieldSpectrumVsEloss() const { return (fhSigmaCorrRcb ? (TH2D*)fhSigmaCorrRcb : NULL); }
175   // Return the ntuple of the calculation vs the Ratio(c/b eloss)
176   TNtuple * GetNtupleCrossSectionVsEloss() { return (fnSigma ? (TNtuple*)fnSigma : NULL); }
177   //
178   //
179   // Histograms to keep track of the influence of the efficiencies statistical uncertainty on the cross-section
180   TH1D * GetDirectStatEffUncOnSigma() const { return (TH1D*)fhStatUncEffcSigma; }
181   TH1D * GetFeedDownStatEffUncOnSigma() const { return (TH1D*)fhStatUncEffbSigma; }
182   // Histograms to keep track of the influence of the efficiencies statistical uncertainty on the feed-down correction factor
183   TH1D * GetDirectStatEffUncOnFc() const { return (TH1D*)fhStatUncEffcFD; }
184   TH1D * GetFeedDownStatEffUncOnFc() const { return (TH1D*)fhStatUncEffbFD; }
185
186
187   //
188   // Main function:
189   //    Compute the invariant cross-section from the yield (correct it)
190   // variables : analysed delta_y, BR for the final correction, BR b --> decay (relative to the input theoretical prediction)
191   void ComputeHFPtSpectrum(Double_t deltaY=1.0, Double_t branchingRatioC=1.0, Double_t branchingRatioBintoFinalDecay=1.0);
192
193   // Compute the systematic uncertainties
194   //   taking as input the AliHFSystErr uncertainties
195   void ComputeSystUncertainties(AliHFSystErr *systematics, Bool_t combineFeedDown);
196   //
197   // Drawing the corrected spectrum comparing to theoretical prediction
198   void DrawSpectrum(TGraphAsymmErrors *gPrediction);
199
200   //
201   // Basic functions
202   // 
203   void EstimateAndSetDirectEfficiencyRecoBin(TH1D *hSimu, TH1D *hReco);
204   void EstimateAndSetFeedDownEfficiencyRecoBin(TH1D *hSimu, TH1D *hReco);
205   
206   //
207   // Functions to  reweight histograms for testing purposes: 
208   //   to reweight the simulation: hToReweight is reweighted as hReference/hToReweight
209   TH1D * ReweightHisto(TH1D *hToReweight, TH1D *hReference);
210   //   to reweight the reco-histos: hRecToReweight is reweighted as hReference/hMCToReweight
211   TH1D * ReweightRecHisto(TH1D *hRecToReweight, TH1D *hMCToReweight, TH1D *hMCReference);
212   // Functionality to find the y-axis bin of a TH2 for a given y-value
213   Int_t FindTH2YBin(TH2D *histo, Float_t yvalue);
214
215
216  protected:
217
218   // Initialization 
219   Bool_t Initialize();
220   
221   // Basic functions
222   //
223   // Compute the feed-down correction via fc-method
224   void CalculateFeedDownCorrectionFc(); 
225   // Correct the yield for feed-down correction via fc-method
226   void CalculateFeedDownCorrectedSpectrumFc(); 
227   // Correct the yield for feed-down correction via Nb-method
228   void CalculateFeedDownCorrectedSpectrumNb(Double_t deltaY, Double_t branchingRatioBintoFinalDecay); 
229
230   // Check histograms consistency function
231   Bool_t CheckHistosConsistency(TH1D *h1, TH1D *h2);
232   // Function to rebin the theoretical spectra in the data-reconstructed spectra binning
233   TH1D * RebinTheoreticalSpectra(TH1D *hTheory, const char *name);
234   // Function to estimate the efficiency in the data-reconstructed spectra binning
235   TH1D * EstimateEfficiencyRecoBin(TH1D *hSimu, TH1D *hReco, const char *name);
236   // Reset stat unc on the efficiencies
237   void ResetStatUncEff();
238
239
240   //
241   // Input spectra
242   //
243   TH1D *fhDirectMCpt;            // Input MC c-->D spectra
244   TH1D *fhFeedDownMCpt;          // Input MC b-->D spectra
245   TH1D *fhDirectMCptMax;         // Input MC maximum c-->D spectra
246   TH1D *fhDirectMCptMin;         // Input MC minimum c-->D spectra
247   TH1D *fhFeedDownMCptMax;       // Input MC maximum b-->D spectra
248   TH1D *fhFeedDownMCptMin;       // Input MC minimum b-->D spectra
249   TH1D *fhDirectEffpt;           // c-->D Acceptance and efficiency correction
250   TH1D *fhFeedDownEffpt;         // b-->D Acceptance and efficiency correction
251   TH1D *fhRECpt;                 // all reconstructed D
252   //
253   TGraphAsymmErrors *fgRECSystematics; // all reconstructed D Systematic uncertainties
254   //
255   // Normalization factors
256   Int_t fNevts;                      // nb of analyzed events
257   Double_t fLuminosity[2];           // analyzed luminosity & uncertainty
258   Double_t fTrigEfficiency[2];       // trigger efficiency & uncertainty
259   Double_t fGlobalEfficiencyUncertainties[2]; // uncertainties on the efficiency [0]=c, b, [1]=b/c
260   Double_t fTab[2];                   // Tab parameter and its uncertainty
261
262   //
263   // Output spectra
264   //
265   TH1D *fhFc;                            // Correction histo fc = 1 / ( 1 + (eff_b/eff_c)*(N_b/N_c) ) 
266   TH1D *fhFcMax;                         // Maximum fc histo
267   TH1D *fhFcMin;                         // Minimum fc histo
268   TH2D *fhFcRcb;                         // Correction histo fc vs the Ratio(c/b eloss)
269   TGraphAsymmErrors * fgFcExtreme;       // Extreme correction as TGraphAsymmErrors
270   TGraphAsymmErrors * fgFcConservative;  // Extreme correction as TGraphAsymmErrors
271   TH1D *fhYieldCorr;                     // Corrected yield (stat unc. only)
272   TH1D *fhYieldCorrMax;                  // Maximum corrected yield  
273   TH1D *fhYieldCorrMin;                  // Minimum corrected yield  
274   TH2D *fhYieldCorrRcb;                  // Corrected yield (stat unc. only) vs the Ratio(c/b eloss)
275   TGraphAsymmErrors * fgYieldCorr;              // Corrected yield as TGraphAsymmErrors  (syst but feed-down)
276   TGraphAsymmErrors * fgYieldCorrExtreme;       // Extreme corrected yield as TGraphAsymmErrors  (syst from feed-down)
277   TGraphAsymmErrors * fgYieldCorrConservative;  // Conservative corrected yield as TGraphAsymmErrors  (syst from feed-down) 
278   TH1D *fhSigmaCorr;                     // Corrected cross-section (stat unc. only)
279   TH1D *fhSigmaCorrMax;                  // Maximum corrected cross-section  
280   TH1D *fhSigmaCorrMin;                  // Minimum corrected cross-section
281   TH1D *fhSigmaCorrDataSyst;             // Corrected cross-section (syst. unc. from data only)
282   TH2D *fhSigmaCorrRcb;                  // Corrected cross-section (stat unc. only) vs the Ratio(c/b eloss)
283   TGraphAsymmErrors * fgSigmaCorr;              // Corrected cross-section as TGraphAsymmErrors (syst but feed-down)
284   TGraphAsymmErrors * fgSigmaCorrExtreme;       // Extreme corrected cross-section as TGraphAsymmErrors (syst from feed-down)
285   TGraphAsymmErrors * fgSigmaCorrConservative;  // Conservative corrected cross-section as TGraphAsymmErrors  (syst from feed-down)
286   //
287   TNtuple *fnSigma;          // Ntuple of the calculation vs the Ratio(c/b eloss)
288   TNtuple *fnHypothesis;     // Ntuple of the calculation vs the Ratio(c/b eloss)
289
290   //
291   Int_t fFeedDownOption;            // feed-down correction flag: 0=none, 1=fc, 2=Nb 
292   Bool_t fAsymUncertainties;        // flag: asymmetric uncertainties are (1) or not (0) considered
293   Bool_t fPbPbElossHypothesis;      // flag: whether to do estimates vs Ratio(c/b eloss) hypothesis
294   Bool_t fIsStatUncEff;             // flag : consider (1) or not (0) the stat unc on the efficiencies
295   Int_t fParticleAntiParticle;      // 1: only one sign, 2: yield is for particle+anti-particle
296
297   //
298   TH1D *fhStatUncEffcSigma;       // Uncertainty on the cross-section due to the prompt efficiency statistical uncertainty
299   TH1D *fhStatUncEffbSigma;       // Uncertainty on the cross-section due to the feed-down efficiency statistical uncertainty
300   TH1D *fhStatUncEffcFD;          // Uncertainty on the feed-down correction due to the prompt efficiency statistical uncertainty
301   TH1D *fhStatUncEffbFD;          // Uncertainty on the feed-down correction due to the feed-down efficiency statistical uncertainty
302
303   ClassDef(AliHFPtSpectrum,3) // Class for Heavy Flavor spectra corrections
304 };
305
306 #endif