]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FORWARD/analysis2/AliForwardUtil.h
Mega commit.
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / AliForwardUtil.h
CommitLineData
7984e5f7 1//
2// Utilities used in the forward multiplcity analysis
3//
4//
5#ifndef ALIFORWARDUTIL_H
6#define ALIFORWARDUTIL_H
ffca499d 7/**
8 * @file AliForwardUtil.h
9 * @author Christian Holm Christensen <cholm@dalsgaard.hehi.nbi.dk>
10 * @date Wed Mar 23 14:06:54 2011
11 *
12 * @brief
13 *
14 *
15 * @ingroup pwg2_forward
16 */
7e4038b5 17#include <TObject.h>
9d99b0dd 18#include <TString.h>
7f759bb7 19#include <TObjArray.h>
7e4038b5 20class TH2D;
9d99b0dd 21class TH1I;
22class TH1;
7f759bb7 23class TF1;
7e4038b5 24class TAxis;
9d99b0dd 25class AliESDEvent;
7e4038b5 26
27/**
28 * Utilities used in the forward multiplcity analysis
29 *
7c1a1f1d 30 * @ingroup pwg2_forward
7e4038b5 31 */
32class AliForwardUtil : public TObject
33{
9d99b0dd 34public:
ffca499d 35 /**
36 * Get the standard color for a ring
37 *
38 * @param d Detector
39 * @param r Ring
40 *
41 * @return
42 */
cc83fca2 43 static Color_t RingColor(UShort_t d, Char_t r)
44 {
45 return ((d == 1 ? kRed : (d == 2 ? kGreen : kBlue))
5bb5d1f6 46 + ((r == 'I' || r == 'i') ? 2 : -3));
cc83fca2 47 }
0bd4b00f 48 //==================================================================
49 /**
50 * @{
7c1a1f1d 51 * @name Collision/run parameters
0bd4b00f 52 */
53 /**
54 * Defined collision types
55 */
56 enum ECollisionSystem {
57 kUnknown,
58 kPP,
59 kPbPb
60 };
61 //__________________________________________________________________
62 /**
63 * Parse a collision system spec given in a string. Known values are
64 *
65 * - "pp", "p-p" which returns kPP
66 * - "PbPb", "Pb-Pb", "A-A", which returns kPbPb
67 * - Everything else gives kUnknown
68 *
69 * @param sys Collision system spec
70 *
71 * @return Collision system id
72 */
73 static UShort_t ParseCollisionSystem(const char* sys);
74 /**
75 * Get a string representation of the collision system
76 *
77 * @param sys Collision system
78 * - kPP -> "pp"
79 * - kPbPb -> "PbPb"
80 * - anything else gives "unknown"
81 *
82 * @return String representation of the collision system
83 */
84 static const char* CollisionSystemString(UShort_t sys);
85 //__________________________________________________________________
86 /**
87 * Parse the center of mass energy given as a float and return known
88 * values as a unsigned integer
89 *
90 * @param sys Collision system (needed for AA)
91 * @param cms Center of mass energy * total charge
92 *
93 * @return Center of mass energy per nucleon
94 */
95 static UShort_t ParseCenterOfMassEnergy(UShort_t sys, Float_t cms);
96 /**
97 * Get a string representation of the center of mass energy per nuclean
98 *
7c1a1f1d 99 * @param cms Center of mass energy per nucleon
0bd4b00f 100 *
101 * @return String representation of the center of mass energy per nuclean
102 */
103 static const char* CenterOfMassEnergyString(UShort_t cms);
104 //__________________________________________________________________
105 /**
106 * Parse the magnetic field (in kG) as given by a floating point number
107 *
108 * @param field Magnetic field in kG
109 *
110 * @return Short integer value of magnetic field in kG
111 */
112 static Short_t ParseMagneticField(Float_t field);
113 /**
114 * Get a string representation of the magnetic field
115 *
116 * @param field Magnetic field in kG
117 *
118 * @return String representation of the magnetic field
119 */
120 static const char* MagneticFieldString(Short_t field);
121 /* @} */
122
123 /**
124 * @{
125 * @name Energy stragling functions
126 */
7f759bb7 127 //__________________________________________________________________
128 /**
129 * Number of steps to do in the Landau, Gaussiam convolution
130 */
fb3430ac 131 static Int_t fgConvolutionSteps; // Number of convolution steps
7f759bb7 132 //------------------------------------------------------------------
133 /**
134 * How many sigma's of the Gaussian in the Landau, Gaussian
135 * convolution to integrate over
136 */
fb3430ac 137 static Double_t fgConvolutionNSigma; // Number of convolution sigmas
7f759bb7 138 //------------------------------------------------------------------
139 /**
140 * Calculate the shifted Landau
141 * @f[
142 * f'_{L}(x;\Delta,\xi) = f_L(x;\Delta+0.22278298\xi)
143 * @f]
144 *
145 * where @f$ f_{L}@f$ is the ROOT implementation of the Landau
146 * distribution (known to have @f$ \Delta_{p}=-0.22278298@f$ for
147 * @f$\Delta=0,\xi=1@f$.
148 *
149 * @param x Where to evaluate @f$ f'_{L}@f$
150 * @param delta Most probable value
151 * @param xi The 'width' of the distribution
152 *
c389303e 153 * @return @f$ f'_{L}(x;\Delta,\xi) @f$
7f759bb7 154 */
155 static Double_t Landau(Double_t x, Double_t delta, Double_t xi);
156
157 //------------------------------------------------------------------
9d99b0dd 158 /**
7f759bb7 159 * Calculate the value of a Landau convolved with a Gaussian
9d99b0dd 160 *
7f759bb7 161 * @f[
c389303e 162 * f(x;\Delta,\xi,\sigma') = \frac{1}{\sigma' \sqrt{2 \pi}}
7f759bb7 163 * \int_{-\infty}^{+\infty} d\Delta' f'_{L}(x;\Delta',\xi)
c389303e 164 * \exp{-\frac{(\Delta-\Delta')^2}{2\sigma'^2}}
7f759bb7 165 * @f]
9d99b0dd 166 *
c389303e 167 * where @f$ f'_{L}@f$ is the Landau distribution, @f$ \Delta@f$ the
168 * energy loss, @f$ \xi@f$ the width of the Landau, and
169 * @f$ \sigma'^2=\sigma^2-\sigma_n^2 @f$. Here, @f$\sigma@f$ is the
7f759bb7 170 * variance of the Gaussian, and @f$\sigma_n@f$ is a parameter modelling
171 * noise in the detector.
172 *
173 * Note that this function uses the constants fgConvolutionSteps and
174 * fgConvolutionNSigma
175 *
176 * References:
177 * - <a href="http://dx.doi.org/10.1016/0168-583X(84)90472-5">Nucl.Instrum.Meth.B1:16</a>
178 * - <a href="http://dx.doi.org/10.1103/PhysRevA.28.615">Phys.Rev.A28:615</a>
179 * - <a href="http://root.cern.ch/root/htmldoc/tutorials/fit/langaus.C.html">ROOT implementation</a>
180 *
181 * @param x where to evaluate @f$ f@f$
182 * @param delta @f$ \Delta@f$ of @f$ f(x;\Delta,\xi,\sigma')@f$
183 * @param xi @f$ \xi@f$ of @f$ f(x;\Delta,\xi,\sigma')@f$
c389303e 184 * @param sigma @f$ \sigma@f$ of @f$\sigma'^2=\sigma^2-\sigma_n^2 @f$
185 * @param sigma_n @f$ \sigma_n@f$ of @f$\sigma'^2=\sigma^2-\sigma_n^2 @f$
7f759bb7 186 *
187 * @return @f$ f@f$ evaluated at @f$ x@f$.
9d99b0dd 188 */
7f759bb7 189 static Double_t LandauGaus(Double_t x, Double_t delta, Double_t xi,
190 Double_t sigma, Double_t sigma_n);
0bd4b00f 191
192 //------------------------------------------------------------------
193 /**
194 * Evaluate
195 * @f[
196 * f_i(x;\Delta,\xi,\sigma') = f(x;\Delta_i,\xi_i,\sigma_i')
197 * @f]
198 * corresponding to @f$ i@f$ particles i.e., with the substitutions
7c1a1f1d 199 * @f{eqnarray*}{
200 * \Delta \rightarrow \Delta_i &=& i(\Delta + \xi\log(i))\\
201 * \xi \rightarrow \xi_i &=& i \xi\\
202 * \sigma \rightarrow \sigma_i &=& \sqrt{i}\sigma\\
203 * \sigma'^2 \rightarrow \sigma_i'^2 &=& \sigma_n^2 + \sigma_i^2
204 * @f}
0bd4b00f 205 *
206 * @param x Where to evaluate
207 * @param delta @f$ \Delta@f$
208 * @param xi @f$ \xi@f$
209 * @param sigma @f$ \sigma@f$
210 * @param sigma_n @f$ \sigma_n@f$
7c1a1f1d 211 * @param i @f$ i @f$
0bd4b00f 212 *
7c1a1f1d 213 * @return @f$ f_i @f$ evaluated
0bd4b00f 214 */
215 static Double_t ILandauGaus(Double_t x, Double_t delta, Double_t xi,
216 Double_t sigma, Double_t sigma_n, Int_t i);
217
218 //------------------------------------------------------------------
219 /**
220 * Numerically evaluate
221 * @f[
222 * \left.\frac{\partial f_i}{\partial p_i}\right|_{x}
223 * @f]
224 * where @f$ p_i@f$ is the @f$ i^{\mbox{th}}@f$ parameter. The mapping
225 * of the parameters is given by
226 *
227 * - 0: @f$\Delta@f$
228 * - 1: @f$\xi@f$
229 * - 2: @f$\sigma@f$
230 * - 3: @f$\sigma_n@f$
231 *
232 * This is the partial derivative with respect to the parameter of
233 * the response function corresponding to @f$ i@f$ particles i.e.,
234 * with the substitutions
235 * @f[
236 * \Delta \rightarrow \Delta_i = i(\Delta + \xi\log(i))\\
237 * \xi \rightarrow \xi_i = i \xi\\
238 * \sigma \rightarrow \sigma_i = \sqrt{i}\sigma\\
239 * \sigma'^2 \rightarrow \sigma_i'^2 = \sigma_n^2 + \sigma_i^2
240 * @f]
241 *
242 * @param x Where to evaluate
243 * @param ipar Parameter number
7c1a1f1d 244 * @param dp @f$ \epsilon\delta p_i@f$ for some value of @f$\epsilon@f$
0bd4b00f 245 * @param delta @f$ \Delta@f$
246 * @param xi @f$ \xi@f$
247 * @param sigma @f$ \sigma@f$
248 * @param sigma_n @f$ \sigma_n@f$
249 * @param i @f$ i@f$
250 *
251 * @return @f$ f_i@f$ evaluated
252 */
253 static Double_t IdLandauGausdPar(Double_t x, UShort_t ipar, Double_t dp,
254 Double_t delta, Double_t xi,
255 Double_t sigma, Double_t sigma_n, Int_t i);
256
7f759bb7 257 //------------------------------------------------------------------
9d99b0dd 258 /**
7f759bb7 259 * Evaluate
c389303e 260 * @f[
0bd4b00f 261 * f_N(x;\Delta,\xi,\sigma') = \sum_{i=1}^N a_i f_i(x;\Delta,\xi,\sigma'a)
262 * @f]
9d99b0dd 263 *
7f759bb7 264 * where @f$ f(x;\Delta,\xi,\sigma')@f$ is the convolution of a
265 * Landau with a Gaussian (see LandauGaus). Note that
c389303e 266 * @f$ a_1 = 1@f$, @f$\Delta_i = i(\Delta_1 + \xi\log(i))@f$,
267 * @f$\xi_i=i\xi_1@f$, and @f$\sigma_i'^2 = \sigma_n^2 + i\sigma_1^2@f$.
7f759bb7 268 *
269 * References:
270 * - <a href="http://dx.doi.org/10.1016/0168-583X(84)90472-5">Nucl.Instrum.Meth.B1:16</a>
271 * - <a href="http://dx.doi.org/10.1103/PhysRevA.28.615">Phys.Rev.A28:615</a>
272 * - <a href="http://root.cern.ch/root/htmldoc/tutorials/fit/langaus.C.html">ROOT implementation</a>
9d99b0dd 273 *
7f759bb7 274 * @param x Where to evaluate @f$ f_N@f$
275 * @param delta @f$ \Delta_1@f$
276 * @param xi @f$ \xi_1@f$
277 * @param sigma @f$ \sigma_1@f$
278 * @param sigma_n @f$ \sigma_n@f$
279 * @param n @f$ N@f$ in the sum above.
280 * @param a Array of size @f$ N-1@f$ of the weights @f$ a_i@f$ for
281 * @f$ i > 1@f$
282 *
283 * @return @f$ f_N(x;\Delta,\xi,\sigma')@f$
9d99b0dd 284 */
7f759bb7 285 static Double_t NLandauGaus(Double_t x, Double_t delta, Double_t xi,
286 Double_t sigma, Double_t sigma_n, Int_t n,
fb3430ac 287 const Double_t* a);
0bd4b00f 288 /**
289 * Generate a TF1 object of @f$ f_I@f$
290 *
291 * @param c Constant
292 * @param delta @f$ \Delta@f$
293 * @param xi @f$ \xi_1@f$
294 * @param sigma @f$ \sigma_1@f$
295 * @param sigma_n @f$ \sigma_n@f$
296 * @param i @f$ i@f$ - the number of particles
297 * @param xmin Least value of range
298 * @param xmax Largest value of range
299 *
300 * @return Newly allocated TF1 object
301 */
302 static TF1* MakeILandauGaus(Double_t c,
303 Double_t delta, Double_t xi,
304 Double_t sigma, Double_t sigma_n,
305 Int_t i,
306 Double_t xmin, Double_t xmax);
307 /**
308 * Generate a TF1 object of @f$ f_N@f$
309 *
310 * @param c Constant
311 * @param delta @f$ \Delta@f$
312 * @param xi @f$ \xi_1@f$
313 * @param sigma @f$ \sigma_1@f$
314 * @param sigma_n @f$ \sigma_n@f$
315 * @param n @f$ N@f$ - how many particles to sum to
316 * @param a Array of size @f$ N-1@f$ of the weights @f$ a_i@f$ for
317 * @f$ i > 1@f$
318 * @param xmin Least value of range
319 * @param xmax Largest value of range
320 *
321 * @return Newly allocated TF1 object
322 */
323 static TF1* MakeNLandauGaus(Double_t c,
324 Double_t delta, Double_t xi,
325 Double_t sigma, Double_t sigma_n,
fb3430ac 326 Int_t n, const Double_t* a,
0bd4b00f 327 Double_t xmin, Double_t xmax);
328
7f759bb7 329 //__________________________________________________________________
330 /**
331 * Structure to do fits to the energy loss spectrum
332 *
ca610c5c 333 * @ingroup pwg2_forward
7f759bb7 334 */
335 struct ELossFitter
336 {
c389303e 337 enum {
338 kC = 0,
339 kDelta,
340 kXi,
341 kSigma,
342 kSigmaN,
343 kN,
344 kA
345 };
7f759bb7 346 /**
347 * Constructor
348 *
349 * @param lowCut Lower cut of spectrum - data below this cuts is ignored
350 * @param maxRange Maximum range to fit to
351 * @param minusBins The number of bins below maximum to use
352 */
353 ELossFitter(Double_t lowCut, Double_t maxRange, UShort_t minusBins);
7984e5f7 354 /**
355 * Destructor
356 *
357 */
7f759bb7 358 virtual ~ELossFitter();
359 /**
360 * Clear internal arrays
361 *
362 */
363 void Clear();
364 /**
365 * Fit a 1-particle signal to the passed energy loss distribution
366 *
367 * Note that this function clears the internal arrays first
368 *
369 * @param dist Data to fit the function to
370 * @param sigman If larger than zero, the initial guess of the
371 * detector induced noise. If zero or less, then this
372 * parameter is ignored in the fit (fixed at 0)
373 *
374 * @return The function fitted to the data
375 */
376 TF1* Fit1Particle(TH1* dist, Double_t sigman=-1);
377 /**
378 * Fit a N-particle signal to the passed energy loss distribution
379 *
380 * If there's no 1-particle fit present, it does that first
381 *
382 * @param dist Data to fit the function to
c389303e 383 * @param n Number of particle signals to fit
7f759bb7 384 * @param sigman If larger than zero, the initial guess of the
385 * detector induced noise. If zero or less, then this
386 * parameter is ignored in the fit (fixed at 0)
387 *
388 * @return The function fitted to the data
389 */
390 TF1* FitNParticle(TH1* dist, UShort_t n, Double_t sigman=-1);
fb3430ac 391 /**
392 * Get Lower cut on data
393 *
394 * @return Lower cut on data
395 */
396 Double_t GetLowCut() const { return fLowCut; }
397 /**
398 * Get Maximum range to fit
399 *
400 * @return Maximum range to fit
401 */
402 Double_t GetMaxRange() const { return fMaxRange; }
403 /**
404 * Get Number of bins from maximum to fit 1st peak
405 *
406 * @return Number of bins from maximum to fit 1st peak
407 */
408 UShort_t GetMinusBins() const { return fMinusBins; }
409 /**
410 * Get Array of fit results
411 *
412 * @return Array of fit results
413 */
414 const TObjArray& GetFitResults() const { return fFitResults; }
415 /**
416 * Get Array of fit results
417 *
418 * @return Array of fit results
419 */
420 TObjArray& GetFitResults() { return fFitResults; }
421 /**
422 * Get Array of functions
423 *
424 * @return Array of functions
425 */
426 const TObjArray& GetFunctions() const { return fFunctions; }
427 /**
428 * Get Array of functions
429 *
430 * @return Array of functions
431 */
432 TObjArray& GetFunctions() { return fFunctions; }
433 private:
7f759bb7 434 const Double_t fLowCut; // Lower cut on data
435 const Double_t fMaxRange; // Maximum range to fit
436 const UShort_t fMinusBins; // Number of bins from maximum to fit 1st peak
437 TObjArray fFitResults; // Array of fit results
438 TObjArray fFunctions; // Array of functions
439 };
0bd4b00f 440 /* @} */
7f759bb7 441
442
0bd4b00f 443 //==================================================================
444 /**
445 * @{
446 * @name Convenience containers
447 */
7e4038b5 448 /**
449 * Structure to hold histograms
450 *
7c1a1f1d 451 * @ingroup pwg2_forward
7e4038b5 452 */
453 struct Histos : public TObject
454 {
455 /**
456 * Constructor
457 *
458 *
459 */
460 Histos() : fFMD1i(0), fFMD2i(0), fFMD2o(0), fFMD3i(0), fFMD3o(0) {}
461 /**
462 * Copy constructor
463 *
464 * @param o Object to copy from
465 */
466 Histos(const Histos& o)
467 : TObject(o),
468 fFMD1i(o.fFMD1i),
469 fFMD2i(o.fFMD2i),
470 fFMD2o(o.fFMD2o),
471 fFMD3i(o.fFMD3i),
472 fFMD3o(o.fFMD3o)
473 {}
474 /**
475 * Assignement operator
476 *
477 * @return Reference to this
478 */
479 Histos& operator=(const Histos&) { return *this;}
480 /**
481 * Destructor
482 */
483 ~Histos();
484 /**
485 * Initialize the object
486 *
487 * @param etaAxis Eta axis to use
488 */
489 void Init(const TAxis& etaAxis);
490 /**
491 * Make a histogram
492 *
493 * @param d Detector
494 * @param r Ring
495 * @param etaAxis Eta axis to use
496 *
497 * @return Newly allocated histogram
498 */
499 TH2D* Make(UShort_t d, Char_t r, const TAxis& etaAxis) const;
500 /**
501 * Clear data
502 *
503 * @param option Not used
504 */
505 void Clear(Option_t* option="");
506 // const TH2D* Get(UShort_t d, Char_t r) const;
507 /**
508 * Get the histogram for a particular detector,ring
509 *
510 * @param d Detector
511 * @param r Ring
512 *
513 * @return Histogram for detector,ring or nul
514 */
515 TH2D* Get(UShort_t d, Char_t r) const;
516 TH2D* fFMD1i; // Histogram for FMD1i
517 TH2D* fFMD2i; // Histogram for FMD2i
518 TH2D* fFMD2o; // Histogram for FMD2o
519 TH2D* fFMD3i; // Histogram for FMD3i
520 TH2D* fFMD3o; // Histogram for FMD3o
9d99b0dd 521
522 ClassDef(Histos,1)
7e4038b5 523 };
524
9d99b0dd 525 //__________________________________________________________________
ca610c5c 526 /**
527 * Base class for structure holding ring specific histograms
528 *
529 * @ingroup pwg2_forward
530 */
9d99b0dd 531 struct RingHistos : public TObject
532 {
ca610c5c 533 /**
534 * Constructor
535 *
536 */
9d99b0dd 537 RingHistos() : fDet(0), fRing('\0'), fName("") {}
ca610c5c 538 /**
539 *
540 *
541 * @param d Detector
542 * @param r Ring
543 */
9d99b0dd 544 RingHistos(UShort_t d, Char_t r)
545 : fDet(d), fRing(r), fName(TString::Format("FMD%d%c", d, r))
546 {}
ca610c5c 547 /**
548 * Copy constructor
549 *
550 * @param o Object to copy from
551 */
9d99b0dd 552 RingHistos(const RingHistos& o)
553 : TObject(o), fDet(o.fDet), fRing(o.fRing), fName(o.fName)
554 {}
ca610c5c 555 /**
556 *
557 */
9d99b0dd 558 virtual ~RingHistos() {}
ca610c5c 559 /**
560 * Assignement operator
561 *
562 * @param o Object to assign from
563 *
564 * @return Reference to this
565 */
9d99b0dd 566 RingHistos& operator=(const RingHistos& o)
567 {
568 TObject::operator=(o);
569 fDet = o.fDet;
570 fRing = o.fRing;
571 fName = o.fName;
572 return *this;
573 }
ca610c5c 574 /**
7984e5f7 575 * Define the outout list in @a d
ca610c5c 576 *
7984e5f7 577 * @param d Where to put the output list
ca610c5c 578 *
7984e5f7 579 * @return Newly allocated TList object or null
ca610c5c 580 */
9d99b0dd 581 TList* DefineOutputList(TList* d) const;
ca610c5c 582 /**
7984e5f7 583 * Get our output list from the container @a d
ca610c5c 584 *
7984e5f7 585 * @param d where to get the output list from
ca610c5c 586 *
7984e5f7 587 * @return The found TList or null
ca610c5c 588 */
fb3430ac 589 TList* GetOutputList(const TList* d) const;
ca610c5c 590 /**
7984e5f7 591 * Find a specific histogram in the source list @a d
ca610c5c 592 *
7984e5f7 593 * @param d (top)-container
594 * @param name Name of histogram
ca610c5c 595 *
7984e5f7 596 * @return Found histogram or null
ca610c5c 597 */
fb3430ac 598 TH1* GetOutputHist(const TList* d, const char* name) const;
ca610c5c 599 /**
600 *
601 *
602 *
603 * @return
604 */
7f759bb7 605 Color_t Color() const
606 {
cc83fca2 607 return AliForwardUtil::RingColor(fDet, fRing);
7f759bb7 608 }
5bb5d1f6 609 const char* GetName() const { return fName.Data(); }
ca610c5c 610 UShort_t fDet; // Detector
611 Char_t fRing; // Ring
612 TString fName; // Name
9d99b0dd 613
614 ClassDef(RingHistos,1)
615 };
0bd4b00f 616 /* @} */
9d99b0dd 617
7e4038b5 618};
619
620#endif
621// Local Variables:
622// mode: C++
623// End:
624