First go of energy loss spectrum algorithm.
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / AliFMDEnergyFitter.h
CommitLineData
f8715167 1#ifndef ALIROOT_PWG2_FORWARD_ALIFMDENERGYFITTER_H
2#define ALIROOT_PWG2_FORWARD_ALIFMDENERGYFITTER_H
3#include <TNamed.h>
4#include <TH1D.h>
5#include <TAxis.h>
6#include <TList.h>
7#include <TObjArray.h>
8#include "AliForwardUtil.h"
9class AliESDFMD;
10class TFitResult;
11class TF1;
12class TArrayD;
13
14/**
15 * Class to fit the energy distribution.
16 *
17 * @par Input:
18 * - AliESDFMD object - from reconstruction
19 *
20 * @par Output:
21 * - Lists of histogram - one per ring. Each list has a number of
22 * histograms corresponding to the number of eta bins defined.
23 *
24 * @par Corrections used:
25 * - None
26 *
27 *
28 * @ingroup pwg2_forward_analysis
29 */
30class AliFMDEnergyFitter : public TNamed
31{
32public:
33 /**
34 * Destructor
35 */
36 virtual ~AliFMDEnergyFitter();
37 /**
38 * Default Constructor - do not use
39 */
40 AliFMDEnergyFitter();
41 /**
42 * Constructor
43 *
44 * @param title Title of object - not significant
45 */
46 AliFMDEnergyFitter(const char* title);
47 /**
48 * Copy constructor
49 *
50 * @param o Object to copy from
51 */
52 AliFMDEnergyFitter(const AliFMDEnergyFitter& o);
53 /**
54 * Assignment operator
55 *
56 * @param o Object to assign from
57 *
58 * @return Reference to this
59 */
60 AliFMDEnergyFitter& operator=(const AliFMDEnergyFitter& o);
61
62 void Init(const TAxis& etaAxis);
63 /**
64 * Set the low cut used for energy
65 *
66 * @param lowCut Low cut
67 */
68 void SetLowCut(Double_t lowCut=0.3) { fLowCut = lowCut; }
69 void SetBinsToSubtract(UShort_t n=4) { fBinsToSubtract = n; }
70 /**
71 * Whether or not to enable fitting of the final merged result.
72 * Note, fitting takes quite a while and one should be careful not to do
73 * this needlessly
74 *
75 * @param doFit Whether to do the fits or not
76 */
77 void DoFits(Bool_t doFit=kTRUE) { fDoFits = doFit; }
78 /**
79 * Whether or not to enable fitting of the final merged result.
80 * Note, fitting takes quite a while and one should be careful not to do
81 * this needlessly
82 *
83 * @param doFit Whether to do the fits or not
84 */
85 void SetNLandau(UShort_t n) { fNLandau = (n < 1 ? 1 : (n > 5 ? 5 : n)); }
86 /**
87 * Whether or not to enable fitting of the final merged result.
88 * Note, fitting takes quite a while and one should be careful not to do
89 * this needlessly
90 *
91 * @param doFit Whether to do the fits or not
92 */
93 void SetMinEntries(UShort_t n) { fMinEntries = (n < 1 ? 1 : n); }
94 /**
95 * Fitter the input AliESDFMD object
96 *
97 * @param input Input
98 * @param empty Whether the event is 'empty'
99 *
100 * @return True on success, false otherwise
101 */
102 Bool_t Accumulate(const AliESDFMD& input,
103 Bool_t empty);
104 /**
105 * Scale the histograms to the total number of events
106 *
107 * @param nEvents Number of events
108 */
109 void Fit(TList* dir);
110
111 /**
112 * Define the output histograms. These are put in a sub list of the
113 * passed list. The histograms are merged before the parent task calls
114 * AliAnalysisTaskSE::Terminate
115 *
116 * @param dir Directory to add to
117 */
118 void DefineOutput(TList* dir);
119 /**
120 * Set the debug level. The higher the value the more output
121 *
122 * @param dbg Debug level
123 */
124 void SetDebug(Int_t dbg=1);
125protected:
126 /**
127 * Internal data structure to keep track of the histograms
128 */
129 struct RingHistos : public AliForwardUtil::RingHistos
130 {
131 /**
132 * Default CTOR
133 */
134 RingHistos();
135 /**
136 * Constructor
137 *
138 * @param d detector
139 * @param r ring
140 */
141 RingHistos(UShort_t d, Char_t r);
142 /**
143 * Copy constructor
144 *
145 * @param o Object to copy from
146 */
147 RingHistos(const RingHistos& o);
148 /**
149 * Assignment operator
150 *
151 * @param o Object to assign from
152 *
153 * @return Reference to this
154 */
155 RingHistos& operator=(const RingHistos& o);
156 /**
157 * Destructor
158 */
159 ~RingHistos();
160 /**
161 * Define outputs
162 *
163 * @param dir
164 */
165 void Output(TList* dir);
166 /**
167 * Initialise object
168 *
169 * @param eAxis
170 */
171 void Init(const TAxis& eAxis);
172 /**
173 * Fill histogram
174 *
175 * @param empty True if event is empty
176 * @param ieta Eta bin
177 * @param mult Signal
178 */
179 void Fill(Bool_t empty, Int_t ieta, Double_t mult);
180 /**
181 * Scale the histograms to the total number of events
182 *
183 * @param dir Output list
184 * @param eta Eta axis
185 * @param lowCut Lower cut
186 * @param nLandau Max number of convolved landaus to fit
187 */
188 TObjArray* Fit(TList* dir, const TAxis& eta,
189 Double_t lowCut, UShort_t nLandau,
190 UShort_t minEntries,
191 UShort_t minusBins) const;
192 /**
193 * Fit a signal histogram
194 *
195 * @param dist Historgam to fit
196 * @param lowCut Lower cut on signal
197 * @param nLandau Max number of convolved landaus to fit
198 *
199 * @return The best fit function
200 */
201 TF1* FitHist(TH1* dist,Double_t lowCut, UShort_t nLandau,
202 UShort_t minEntries, UShort_t minusBins) const;
203 /**
204 * Fit more Landau
205 *
206 * @param dist Histogram to fit
207 * @param nLandau Number of landaus
208 * @param r Result from 1st Landau fit
209 * @param landau1 Function of 1st Landau fit
210 * @param minE Least signal for range
211 *
212 * @return The result
213 */
214 TF1* FitMore(TH1* dist,
215 UShort_t nLandau,
216 TFitResult& r,
217 TF1* landau1,
218 Double_t minE,
219 Double_t maxRange) const;
220 /**
221 * Fit more Landau
222 *
223 * @param dist Histogram to fit
224 * @param nLandau Number of landaus
225 * @param r Result from 1st Landau fit
226 * @param landau1 Function of 1st Landau fit
227 * @param minE Least signal for range
228 *
229 * @return The result
230 */
231 TF1* FitMore2(TH1* dist,
232 UShort_t nLandau,
233 TFitResult& r,
234 TF1* landau1,
235 Double_t minE,
236 Double_t maxRange) const;
237 /**
238 * Check the result of the fit. Returns true if the reduced
239 * @f$ \chi^2/\nu@f$ is less than 5, and that the relative error
240 * @f$ \Delta p_i/p_i@f$ on each parameter is less than 20 percent.
241 *
242 * @param r Result to check
243 *
244 * @return true if fit is good.
245 */
246 Bool_t CheckResult(TFitResult& r) const;
247
248 TArrayD MakeLogAxis(Int_t n, Double_t min, Double_t max) const
249 /**
250 * Make E/E_mip histogram
251 *
252 * @param ieta Eta bin
253 * @param eMin Least signal
254 * @param eMax Largest signal
255 */
256 void Make(Int_t ieta, Double_t eMin, Double_t eMax);
257 /**
258 * Make a parameter histogram
259 *
260 * @param name Name of histogram.
261 * @param title Title of histogram.
262 * @param eta Eta axis
263 *
264 * @return
265 */
266 TH1D* MakePar(const char* name, const char* title, const TAxis& eta) const;
267 TH1D* MakeTotal(const char* name,
268 const char* title,
269 const TAxis& eta,
270 Int_t low,
271 Int_t high,
272 Double_t val,
273 Double_t err) const;
274 TH1D* fEDist; // Ring energy distribution
275 TH1D* fEmpty; // Ring energy distribution for empty events
276 TList fEtaEDists; // Energy distributions per eta bin.
277 TList* fList;
278 Int_t fDebug;
279 ClassDef(RingHistos,1);
280 };
281 /**
282 * Get the ring histogram container
283 *
284 * @param d Detector
285 * @param r Ring
286 *
287 * @return Ring histogram container
288 */
289 RingHistos* GetRingHistos(UShort_t d, Char_t r) const;
290
291 TList fRingHistos; // List of histogram containers
292 Double_t fLowCut; // Low cut on energy
293 UShort_t fNLandau; // Number of landaus to try to fit
294 UShort_t fMinEntries; // Minimum number of entries
295 UShort_t fBinsToSubtract;// Number of bins to subtract from found max
296 Bool_t fDoFits; // Wheter to actually do the fits
297 TAxis fEtaAxis; // Eta axis
298 Int_t fDebug; // Debug level
299
300 ClassDef(AliFMDEnergyFitter,1); //
301};
302
303#endif
304// Local Variables:
305// mode: C++
306// End: