]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FORWARD/analysis2/AliFMDEnergyFitter.h
small fix to the merging efficiency on or off
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / AliFMDEnergyFitter.h
CommitLineData
7984e5f7 1//
2// Class to fit the energy distribution.
3//
7c1a1f1d 4#ifndef ALIFMDENERGYFITTER_H
5#define ALIFMDENERGYFITTER_H
f8715167 6#include <TNamed.h>
7#include <TH1D.h>
8#include <TAxis.h>
9#include <TList.h>
10#include <TObjArray.h>
0bd4b00f 11#include <TClonesArray.h>
12#include "AliFMDCorrELossFit.h"
f8715167 13#include "AliForwardUtil.h"
14class AliESDFMD;
15class TFitResult;
16class TF1;
17class TArrayD;
18
19/**
20 * Class to fit the energy distribution.
21 *
22 * @par Input:
23 * - AliESDFMD object - from reconstruction
24 *
25 * @par Output:
26 * - Lists of histogram - one per ring. Each list has a number of
27 * histograms corresponding to the number of eta bins defined.
28 *
29 * @par Corrections used:
30 * - None
31 *
32 *
06c1999d 33 * @ingroup pwg2_forward_algo
f8715167 34 */
35class AliFMDEnergyFitter : public TNamed
36{
37public:
c389303e 38 enum {
39 kC = AliForwardUtil::ELossFitter::kC,
40 kDelta = AliForwardUtil::ELossFitter::kDelta,
41 kXi = AliForwardUtil::ELossFitter::kXi,
42 kSigma = AliForwardUtil::ELossFitter::kSigma,
43 kSigmaN = AliForwardUtil::ELossFitter::kSigmaN,
44 kN = AliForwardUtil::ELossFitter::kN,
45 kA = AliForwardUtil::ELossFitter::kA
46 };
47
f8715167 48 /**
49 * Destructor
50 */
51 virtual ~AliFMDEnergyFitter();
52 /**
53 * Default Constructor - do not use
54 */
55 AliFMDEnergyFitter();
56 /**
57 * Constructor
58 *
59 * @param title Title of object - not significant
60 */
61 AliFMDEnergyFitter(const char* title);
62 /**
63 * Copy constructor
64 *
65 * @param o Object to copy from
66 */
67 AliFMDEnergyFitter(const AliFMDEnergyFitter& o);
68 /**
69 * Assignment operator
70 *
71 * @param o Object to assign from
72 *
73 * @return Reference to this
74 */
75 AliFMDEnergyFitter& operator=(const AliFMDEnergyFitter& o);
76
4b9857f3 77 /**
78 * Initialise the task
79 *
80 * @param etaAxis The eta axis to use. Note, that if the eta axis
81 * has already been set (using SetEtaAxis), then this parameter will be
82 * ignored
83 */
f8715167 84 void Init(const TAxis& etaAxis);
4b9857f3 85 /**
86 * Set the eta axis to use. This will force the code to use this
87 * eta axis definition - irrespective of whatever axis is passed to
88 * the Init member function. Therefore, this member function can be
89 * used to force another eta axis than one found in the correction
90 * objects.
91 *
92 * @param nBins Number of bins
93 * @param etaMin Minimum of the eta axis
94 * @param etaMax Maximum of the eta axis
95 */
96 void SetEtaAxis(Int_t nBins, Double_t etaMin, Double_t etaMax);
97 /**
98 * Set the eta axis to use. This will force the code to use this
99 * eta axis definition - irrespective of whatever axis is passed to
100 * the Init member function. Therefore, this member function can be
101 * used to force another eta axis than one found in the correction
102 * objects.
103 *
104 * @param etaAxis Eta axis to use
105 */
106 void SetEtaAxis(const TAxis& etaAxis);
f8715167 107 /**
108 * Set the low cut used for energy
109 *
110 * @param lowCut Low cut
111 */
112 void SetLowCut(Double_t lowCut=0.3) { fLowCut = lowCut; }
4b9857f3 113 /**
114 * Set the number of bins to subtract
115 *
116 * @param n
117 */
c389303e 118 void SetFitRangeBinWidth(UShort_t n=4) { fFitRangeBinWidth = n; }
f8715167 119 /**
120 * Whether or not to enable fitting of the final merged result.
121 * Note, fitting takes quite a while and one should be careful not to do
122 * this needlessly
123 *
124 * @param doFit Whether to do the fits or not
125 */
c389303e 126 void SetDoFits(Bool_t doFit=kTRUE) { fDoFits = doFit; }
0bd4b00f 127 /**
128 * Set whether to make the corrections object on the output. Note,
129 * fits should be enable for this to have any effect.
130 *
131 * @param doMake If true (false is default), do make the corrections object.
132 */
133 void SetDoMakeObject(Bool_t doMake=kTRUE) { fDoMakeObject = doMake; }
f8715167 134 /**
c389303e 135 * Set how many particles we will try to fit at most to the data
f8715167 136 *
c389303e 137 * @param n Max number of particle to try to fit
f8715167 138 */
c389303e 139 void SetNParticles(UShort_t n) { fNParticles = (n < 1 ? 1 : (n > 5 ? 5 : n)); }
f8715167 140 /**
c389303e 141 * Set the minimum number of entries each histogram must have
142 * before we try to fit our response function to it
f8715167 143 *
c389303e 144 * @param n Minimum number of entries
f8715167 145 */
146 void SetMinEntries(UShort_t n) { fMinEntries = (n < 1 ? 1 : n); }
4b9857f3 147 /**
148 * Set maximum energy loss to consider
149 *
150 * @param x Maximum energy loss to consider
151 */
152 void SetMaxE(Double_t x) { fMaxE = x; }
153 /**
154 * Set number of energy loss bins
155 *
156 * @param x Number of energy loss bins
157 */
158 void SetNEbins(Int_t x) { fNEbins = x; }
7c1a1f1d 159 /**
160 * Set the maximum relative error
161 *
162 * @param e Maximum relative error
163 */
0bd4b00f 164 void SetMaxRelativeParameterError(Double_t e=0.2) { fMaxRelParError = e; }
7c1a1f1d 165 /**
166 * Set the maximum @f$ \chi^2/\nu@f$
167 *
168 * @param c Maximum @f$ \chi^2/\nu@f$
169 */
0bd4b00f 170 void SetMaxChi2PerNDF(Double_t c=10) { fMaxChi2PerNDF = c; }
7c1a1f1d 171 /**
172 * Set the least weight
173 *
174 * @param c Least weight
175 */
0bd4b00f 176 void SetMinWeight(Double_t c=1e-7) { fMinWeight = c; }
4b9857f3 177 /**
178 * Set wheter to use increasing bin sizes
179 *
180 * @param x Wheter to use increasing bin sizes
181 */
182 void SetUseIncreasingBins(Bool_t x) { fUseIncreasingBins = x; }
f8715167 183 /**
184 * Fitter the input AliESDFMD object
185 *
186 * @param input Input
187 * @param empty Whether the event is 'empty'
188 *
189 * @return True on success, false otherwise
190 */
191 Bool_t Accumulate(const AliESDFMD& input,
192 Bool_t empty);
193 /**
194 * Scale the histograms to the total number of events
195 *
c389303e 196 * @param dir Where the histograms are
f8715167 197 */
7c1a1f1d 198 void Fit(const TList* dir);
199 /**
200 * Generate the corrections object
201 *
202 * @param dir List to analyse
203 */
0bd4b00f 204 void MakeCorrectionsObject(TList* dir);
f8715167 205
206 /**
207 * Define the output histograms. These are put in a sub list of the
208 * passed list. The histograms are merged before the parent task calls
209 * AliAnalysisTaskSE::Terminate
210 *
211 * @param dir Directory to add to
212 */
213 void DefineOutput(TList* dir);
214 /**
215 * Set the debug level. The higher the value the more output
216 *
217 * @param dbg Debug level
218 */
219 void SetDebug(Int_t dbg=1);
0bd4b00f 220 /**
221 * Print information
222 *
223 * @param option Not used
224 */
225 void Print(Option_t* option="") const;
f8715167 226protected:
227 /**
228 * Internal data structure to keep track of the histograms
229 */
230 struct RingHistos : public AliForwardUtil::RingHistos
231 {
232 /**
233 * Default CTOR
234 */
235 RingHistos();
236 /**
237 * Constructor
238 *
239 * @param d detector
240 * @param r ring
241 */
242 RingHistos(UShort_t d, Char_t r);
243 /**
244 * Copy constructor
245 *
246 * @param o Object to copy from
247 */
248 RingHistos(const RingHistos& o);
249 /**
250 * Assignment operator
251 *
252 * @param o Object to assign from
253 *
254 * @return Reference to this
255 */
256 RingHistos& operator=(const RingHistos& o);
257 /**
258 * Destructor
259 */
260 ~RingHistos();
261 /**
262 * Define outputs
263 *
264 * @param dir
265 */
266 void Output(TList* dir);
267 /**
268 * Initialise object
269 *
c389303e 270 * @param eAxis Eta axis
271 * @param maxDE Max energy loss to consider
272 * @param nDEbins Number of bins
273 * @param useIncrBin Whether to use an increasing bin size
f8715167 274 */
66b34429 275 void Init(const TAxis& eAxis,
4b9857f3 276 Double_t maxDE=10,
277 Int_t nDEbins=300,
278 Bool_t useIncrBin=true);
f8715167 279 /**
280 * Fill histogram
281 *
282 * @param empty True if event is empty
283 * @param ieta Eta bin
284 * @param mult Signal
285 */
286 void Fill(Bool_t empty, Int_t ieta, Double_t mult);
287 /**
c389303e 288 * Fit each histogram to up to @a nParticles particle responses.
f8715167 289 *
c389303e 290 * @param dir Output list
291 * @param eta Eta axis
292 * @param lowCut Lower cut
293 * @param nParticles Max number of convolved landaus to fit
294 * @param minEntries Minimum number of entries
295 * @param minusBins Number of bins from peak to subtract to
296 * get the fit range
297 * @param relErrorCut Cut applied to relative error of parameter.
298 * Note, for multi-particle weights, the cut
299 * is loosend by a factor of 2
300 * @param chi2nuCut Cut on @f$ \chi^2/\nu@f$ -
301 * the reduced @f$\chi^2@f$
f8715167 302 */
4b9857f3 303 TObjArray* Fit(TList* dir,
304 const TAxis& eta,
305 Double_t lowCut,
c389303e 306 UShort_t nParticles,
4b9857f3 307 UShort_t minEntries,
c389303e 308 UShort_t minusBins,
309 Double_t relErrorCut,
310 Double_t chi2nuCut) const;
f8715167 311 /**
7c1a1f1d 312 * Fit a signal histogram. First, the bin @f$ b_{min}@f$ with
c389303e 313 * maximum bin content in the range @f$ [E_{min},\infty]@f$ is
314 * found. Then the fit range is set to the bin range
315 * @f$ [b_{min}-\Delta b,b_{min}+2\Delta b]@f$, and a 1
316 * particle signal is fitted to that. The parameters of that fit
317 * is then used as seeds for a fit of the @f$ N@f$ particle response
318 * to the data in the range
319 * @f$ [b_{min}-\Delta b,N(\Delta_1+\xi_1\log(N))+2N\xi@f$
f8715167 320 *
c389303e 321 * @param dist Histogram to fit
322 * @param lowCut Lower cut @f$ E_{min}@f$ on signal
323 * @param nParticles Max number @f$ N@f$ of convolved landaus to fit
324 * @param minusBins Number of bins @f$ \Delta b@f$ from peak to
325 * subtract to get the fit range
326 * @param relErrorCut Cut applied to relative error of parameter.
327 * Note, for multi-particle weights, the cut
328 * is loosend by a factor of 2
329 * @param chi2nuCut Cut on @f$ \chi^2/\nu@f$ -
330 * the reduced @f$\chi^2@f$
f8715167 331 *
332 * @return The best fit function
333 */
4b9857f3 334 TF1* FitHist(TH1* dist,
335 Double_t lowCut,
c389303e 336 UShort_t nParticles,
337 UShort_t minusBins,
338 Double_t relErrorCut,
339 Double_t chi2nuCut) const;
0bd4b00f 340 /**
341 * Find the best fits
342 *
343 * @param d Parent list
344 * @param obj Object to add fits to
345 * @param eta Eta axis
346 * @param relErrorCut Cut applied to relative error of parameter.
347 * Note, for multi-particle weights, the cut
348 * is loosend by a factor of 2
349 * @param chi2nuCut Cut on @f$ \chi^2/\nu@f$ -
350 * the reduced @f$\chi^2@f$
351 * @param minWeightCut Least valid @f$ a_i@f$
352 */
353 void FindBestFits(TList* d,
354 AliFMDCorrELossFit& obj,
355 const TAxis& eta,
356 Double_t relErrorCut,
357 Double_t chi2nuCut,
358 Double_t minWeightCut);
359 /**
360 * Find the best fit
361 *
362 * @param dist Histogram
363 * @param relErrorCut Cut applied to relative error of parameter.
364 * Note, for multi-particle weights, the cut
365 * is loosend by a factor of 2
366 * @param chi2nuCut Cut on @f$ \chi^2/\nu@f$ -
367 * the reduced @f$\chi^2@f$
368 * @param minWeightCut Least valid @f$ a_i@f$
369 *
370 * @return Best fit
371 */
372 AliFMDCorrELossFit::ELossFit* FindBestFit(TH1* dist,
373 Double_t relErrorCut,
374 Double_t chi2nuCut,
375 Double_t minWeightCut);
f8715167 376 /**
4b9857f3 377 * Check the result of the fit. Returns true if
c389303e 378 * - @f$ \chi^2/\nu < \max{\chi^2/\nu}@f$
379 * - @f$ \Delta p_i/p_i < \delta_e@f$ for all parameters. Note,
380 * for multi-particle fits, this requirement is relaxed by a
381 * factor of 2
382 * - @f$ a_{n} > 10^{-7}@f$ when fitting to an @f$ n@f$
383 * particle response
f8715167 384 *
c389303e 385 * @param r Result to check
386 * @param relErrorCut Cut @f$ \delta_e@f$ applied to relative error
387 * of parameter.
388 * @param chi2nuCut Cut @f$ \max{\chi^2/\nu}@f$
f8715167 389 *
4b9857f3 390 * @return true if fit is good.
f8715167 391 */
c389303e 392 Bool_t CheckResult(TFitResult* r,
393 Double_t relErrorCut,
394 Double_t chi2nuCut) const;
f8715167 395 /**
4b9857f3 396 * Make an axis with increasing bins
f8715167 397 *
4b9857f3 398 * @param n Number of bins
399 * @param min Minimum
400 * @param max Maximum
f8715167 401 *
4b9857f3 402 * @return An axis with quadratically increasing bin size
f8715167 403 */
66b34429 404 TArrayD MakeIncreasingAxis(Int_t n, Double_t min, Double_t max) const;
f8715167 405 /**
406 * Make E/E_mip histogram
407 *
7c1a1f1d 408 * @param ieta Eta bin
409 * @param eMin Least signal
410 * @param eMax Largest signal
411 * @param deMax Maximum energy loss
412 * @param nDeBins Number energy loss bins
413 * @param incr Whether to make bins of increasing size
f8715167 414 */
66b34429 415 void Make(Int_t ieta, Double_t eMin, Double_t eMax,
416 Double_t deMax=12, Int_t nDeBins=300, Bool_t incr=true);
f8715167 417 /**
418 * Make a parameter histogram
419 *
420 * @param name Name of histogram.
421 * @param title Title of histogram.
422 * @param eta Eta axis
423 *
424 * @return
425 */
426 TH1D* MakePar(const char* name, const char* title, const TAxis& eta) const;
4b9857f3 427 /**
428 * Make a histogram that contains the results of the fit over the full ring
429 *
430 * @param name Name
431 * @param title Title
432 * @param eta Eta axis
433 * @param low Least bin
434 * @param high Largest bin
435 * @param val Value of parameter
436 * @param err Error on parameter
437 *
438 * @return The newly allocated histogram
439 */
f8715167 440 TH1D* MakeTotal(const char* name,
441 const char* title,
442 const TAxis& eta,
443 Int_t low,
444 Int_t high,
445 Double_t val,
446 Double_t err) const;
0bd4b00f 447 TH1D* fEDist; // Ring energy distribution
448 TH1D* fEmpty; // Ring energy distribution for empty events
449 TList fEtaEDists; // Energy distributions per eta bin.
450 TList* fList;
451 TClonesArray fFits;
452 Int_t fDebug;
f8715167 453 ClassDef(RingHistos,1);
454 };
455 /**
456 * Get the ring histogram container
457 *
458 * @param d Detector
459 * @param r Ring
460 *
461 * @return Ring histogram container
462 */
463 RingHistos* GetRingHistos(UShort_t d, Char_t r) const;
464
465 TList fRingHistos; // List of histogram containers
466 Double_t fLowCut; // Low cut on energy
c389303e 467 UShort_t fNParticles; // Number of landaus to try to fit
f8715167 468 UShort_t fMinEntries; // Minimum number of entries
c389303e 469 UShort_t fFitRangeBinWidth;// Number of bins to subtract from found max
0bd4b00f 470 Bool_t fDoFits; // Whether to actually do the fits
471 Bool_t fDoMakeObject; // Whether to make corrections object
f8715167 472 TAxis fEtaAxis; // Eta axis
4b9857f3 473 Double_t fMaxE; // Maximum energy loss to consider
474 Int_t fNEbins; // Number of energy loss bins
475 Bool_t fUseIncreasingBins; // Wheter to use increasing bin sizes
c389303e 476 Double_t fMaxRelParError;// Relative error cut
477 Double_t fMaxChi2PerNDF; // chi^2/nu cit
0bd4b00f 478 Double_t fMinWeight; // Minimum weight value
f8715167 479 Int_t fDebug; // Debug level
0bd4b00f 480
f8715167 481
482 ClassDef(AliFMDEnergyFitter,1); //
483};
484
485#endif
486// Local Variables:
487// mode: C++
488// End: