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