Added event inspector and energy distribution fitter.
[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 */
66b34429 171 void Init(const TAxis& eAxis,
172 Double_t maxDE=10,
173 Int_t nDEbins=300,
174 Bool_t useIncrBin=true);
f8715167 175 /**
176 * Fill histogram
177 *
178 * @param empty True if event is empty
179 * @param ieta Eta bin
180 * @param mult Signal
181 */
182 void Fill(Bool_t empty, Int_t ieta, Double_t mult);
183 /**
184 * Scale the histograms to the total number of events
185 *
186 * @param dir Output list
187 * @param eta Eta axis
188 * @param lowCut Lower cut
189 * @param nLandau Max number of convolved landaus to fit
190 */
191 TObjArray* Fit(TList* dir, const TAxis& eta,
192 Double_t lowCut, UShort_t nLandau,
193 UShort_t minEntries,
194 UShort_t minusBins) const;
195 /**
196 * Fit a signal histogram
197 *
198 * @param dist Historgam to fit
199 * @param lowCut Lower cut on signal
200 * @param nLandau Max number of convolved landaus to fit
201 *
202 * @return The best fit function
203 */
204 TF1* FitHist(TH1* dist,Double_t lowCut, UShort_t nLandau,
205 UShort_t minEntries, UShort_t minusBins) const;
206 /**
207 * Fit more Landau
208 *
209 * @param dist Histogram to fit
210 * @param nLandau Number of landaus
211 * @param r Result from 1st Landau fit
212 * @param landau1 Function of 1st Landau fit
213 * @param minE Least signal for range
214 *
215 * @return The result
216 */
217 TF1* FitMore(TH1* dist,
218 UShort_t nLandau,
219 TFitResult& r,
220 TF1* landau1,
221 Double_t minE,
222 Double_t maxRange) const;
223 /**
224 * Fit more Landau
225 *
226 * @param dist Histogram to fit
227 * @param nLandau Number of landaus
228 * @param r Result from 1st Landau fit
229 * @param landau1 Function of 1st Landau fit
230 * @param minE Least signal for range
231 *
232 * @return The result
233 */
234 TF1* FitMore2(TH1* dist,
235 UShort_t nLandau,
236 TFitResult& r,
237 TF1* landau1,
238 Double_t minE,
239 Double_t maxRange) const;
240 /**
241 * Check the result of the fit. Returns true if the reduced
242 * @f$ \chi^2/\nu@f$ is less than 5, and that the relative error
243 * @f$ \Delta p_i/p_i@f$ on each parameter is less than 20 percent.
244 *
245 * @param r Result to check
246 *
247 * @return true if fit is good.
248 */
249 Bool_t CheckResult(TFitResult& r) const;
66b34429 250 TArrayD MakeIncreasingAxis(Int_t n, Double_t min, Double_t max) const;
f8715167 251 /**
252 * Make E/E_mip histogram
253 *
254 * @param ieta Eta bin
255 * @param eMin Least signal
256 * @param eMax Largest signal
257 */
66b34429 258 void Make(Int_t ieta, Double_t eMin, Double_t eMax,
259 Double_t deMax=12, Int_t nDeBins=300, Bool_t incr=true);
f8715167 260 /**
261 * Make a parameter histogram
262 *
263 * @param name Name of histogram.
264 * @param title Title of histogram.
265 * @param eta Eta axis
266 *
267 * @return
268 */
269 TH1D* MakePar(const char* name, const char* title, const TAxis& eta) const;
270 TH1D* MakeTotal(const char* name,
271 const char* title,
272 const TAxis& eta,
273 Int_t low,
274 Int_t high,
275 Double_t val,
276 Double_t err) const;
277 TH1D* fEDist; // Ring energy distribution
278 TH1D* fEmpty; // Ring energy distribution for empty events
279 TList fEtaEDists; // Energy distributions per eta bin.
280 TList* fList;
281 Int_t fDebug;
282 ClassDef(RingHistos,1);
283 };
284 /**
285 * Get the ring histogram container
286 *
287 * @param d Detector
288 * @param r Ring
289 *
290 * @return Ring histogram container
291 */
292 RingHistos* GetRingHistos(UShort_t d, Char_t r) const;
293
294 TList fRingHistos; // List of histogram containers
295 Double_t fLowCut; // Low cut on energy
296 UShort_t fNLandau; // Number of landaus to try to fit
297 UShort_t fMinEntries; // Minimum number of entries
298 UShort_t fBinsToSubtract;// Number of bins to subtract from found max
299 Bool_t fDoFits; // Wheter to actually do the fits
300 TAxis fEtaAxis; // Eta axis
301 Int_t fDebug; // Debug level
302
303 ClassDef(AliFMDEnergyFitter,1); //
304};
305
306#endif
307// Local Variables:
308// mode: C++
309// End: