2 // Utilities used in the forward multiplcity analysis
5 #ifndef ALIFORWARDUTIL_H
6 #define ALIFORWARDUTIL_H
8 * @file AliForwardUtil.h
9 * @author Christian Holm Christensen <cholm@dalsgaard.hehi.nbi.dk>
10 * @date Wed Mar 23 14:06:54 2011
15 * @ingroup pwglf_forward
19 #include <TObjArray.h>
27 class AliAnalysisTaskSE;
30 * Utilities used in the forward multiplcity analysis
32 * @ingroup pwglf_forward
34 class AliForwardUtil : public TObject
38 * Get the standard color for a ring
45 static Color_t RingColor(UShort_t d, Char_t r)
47 return ((d == 1 ? kRed : (d == 2 ? kGreen : kBlue))
48 + ((r == 'I' || r == 'i') ? 2 : -3));
50 //==================================================================
53 * @name Collision/run parameters
56 * Defined collision types
58 enum ECollisionSystem {
64 //__________________________________________________________________
66 * Parse a collision system spec given in a string. Known values are
68 * - "pp", "p-p" which returns kPP
69 * - "PbPb", "Pb-Pb", "A-A", which returns kPbPb
70 * - "pPb", "p-Pb", "pA", p-A" which returns kPPb
71 * - Everything else gives kUnknown
73 * @param sys Collision system spec
75 * @return Collision system id
77 static UShort_t ParseCollisionSystem(const char* sys);
79 * Get a string representation of the collision system
81 * @param sys Collision system
85 * - anything else gives "unknown"
87 * @return String representation of the collision system
89 static const char* CollisionSystemString(UShort_t sys);
90 //__________________________________________________________________
92 * Parse the center of mass energy given as a float and return known
93 * values as a unsigned integer
95 * @param sys Collision system (needed for AA)
96 * @param cms Center of mass energy * total charge
98 * @return Center of mass energy per nucleon
100 static UShort_t ParseCenterOfMassEnergy(UShort_t sys, Float_t cms);
102 * Get a string representation of the center of mass energy per nuclean
104 * @param cms Center of mass energy per nucleon
106 * @return String representation of the center of mass energy per nuclean
108 static const char* CenterOfMassEnergyString(UShort_t cms);
109 //__________________________________________________________________
111 * Parse the magnetic field (in kG) as given by a floating point number
113 * @param field Magnetic field in kG
115 * @return Short integer value of magnetic field in kG
117 static Short_t ParseMagneticField(Float_t field);
121 * @param det, ring, sec, strip, zvtx
125 static Double_t GetEtaFromStrip(UShort_t det, Char_t ring, UShort_t sec, UShort_t strip, Double_t zvtx) ;
127 * Get a string representation of the magnetic field
129 * @param field Magnetic field in kG
131 * @return String representation of the magnetic field
133 static const char* MagneticFieldString(Short_t field);
136 //__________________________________________________________________
138 * Get the AOD event - either from the input (AOD analysis) or the
139 * output (ESD analysis)
141 * @param task Task to do the investigation for
143 * @return Found AOD event or null
145 static AliAODEvent* GetAODEvent(AliAnalysisTaskSE* task);
147 * Check if we have something that will provide and AOD event
149 * @return 0 if there's nothing that provide an AOD event, 1 if it
150 * is provided on the input (AOD analysis) or 2 if it is provided on
151 * the output (ESD analysis)
153 static UShort_t CheckForAOD();
155 * Check if we have a particular (kind) of task in our train
157 * @param clsOrName Class name or name of task
158 * @param cls If true, look for a task of a particular class -
159 * otherwise search for a speficially name task
161 * @return true if the needed task was found
163 static Bool_t CheckForTask(const char* clsOrName, Bool_t cls=true);
167 * @name Energy stragling functions
169 //__________________________________________________________________
171 * Number of steps to do in the Landau, Gaussiam convolution
173 static Int_t fgConvolutionSteps; // Number of convolution steps
174 //------------------------------------------------------------------
176 * How many sigma's of the Gaussian in the Landau, Gaussian
177 * convolution to integrate over
179 static Double_t fgConvolutionNSigma; // Number of convolution sigmas
180 //------------------------------------------------------------------
182 * Calculate the shifted Landau
184 * f'_{L}(x;\Delta,\xi) = f_L(x;\Delta+0.22278298\xi)
187 * where @f$ f_{L}@f$ is the ROOT implementation of the Landau
188 * distribution (known to have @f$ \Delta_{p}=-0.22278298@f$ for
189 * @f$\Delta=0,\xi=1@f$.
191 * @param x Where to evaluate @f$ f'_{L}@f$
192 * @param delta Most probable value
193 * @param xi The 'width' of the distribution
195 * @return @f$ f'_{L}(x;\Delta,\xi) @f$
197 static Double_t Landau(Double_t x, Double_t delta, Double_t xi);
199 //------------------------------------------------------------------
201 * Calculate the value of a Landau convolved with a Gaussian
204 * f(x;\Delta,\xi,\sigma') = \frac{1}{\sigma' \sqrt{2 \pi}}
205 * \int_{-\infty}^{+\infty} d\Delta' f'_{L}(x;\Delta',\xi)
206 * \exp{-\frac{(\Delta-\Delta')^2}{2\sigma'^2}}
209 * where @f$ f'_{L}@f$ is the Landau distribution, @f$ \Delta@f$ the
210 * energy loss, @f$ \xi@f$ the width of the Landau, and
211 * @f$ \sigma'^2=\sigma^2-\sigma_n^2 @f$. Here, @f$\sigma@f$ is the
212 * variance of the Gaussian, and @f$\sigma_n@f$ is a parameter modelling
213 * noise in the detector.
215 * Note that this function uses the constants fgConvolutionSteps and
216 * fgConvolutionNSigma
219 * - <a href="http://dx.doi.org/10.1016/0168-583X(84)90472-5">Nucl.Instrum.Meth.B1:16</a>
220 * - <a href="http://dx.doi.org/10.1103/PhysRevA.28.615">Phys.Rev.A28:615</a>
221 * - <a href="http://root.cern.ch/root/htmldoc/tutorials/fit/langaus.C.html">ROOT implementation</a>
223 * @param x where to evaluate @f$ f@f$
224 * @param delta @f$ \Delta@f$ of @f$ f(x;\Delta,\xi,\sigma')@f$
225 * @param xi @f$ \xi@f$ of @f$ f(x;\Delta,\xi,\sigma')@f$
226 * @param sigma @f$ \sigma@f$ of @f$\sigma'^2=\sigma^2-\sigma_n^2 @f$
227 * @param sigma_n @f$ \sigma_n@f$ of @f$\sigma'^2=\sigma^2-\sigma_n^2 @f$
229 * @return @f$ f@f$ evaluated at @f$ x@f$.
231 static Double_t LandauGaus(Double_t x, Double_t delta, Double_t xi,
232 Double_t sigma, Double_t sigma_n);
234 //------------------------------------------------------------------
238 * f_i(x;\Delta,\xi,\sigma') = f(x;\Delta_i,\xi_i,\sigma_i')
240 * corresponding to @f$ i@f$ particles i.e., with the substitutions
242 * \Delta \rightarrow \Delta_i &=& i(\Delta + \xi\log(i))\\
243 * \xi \rightarrow \xi_i &=& i \xi\\
244 * \sigma \rightarrow \sigma_i &=& \sqrt{i}\sigma\\
245 * \sigma'^2 \rightarrow \sigma_i'^2 &=& \sigma_n^2 + \sigma_i^2
248 * @param x Where to evaluate
249 * @param delta @f$ \Delta@f$
250 * @param xi @f$ \xi@f$
251 * @param sigma @f$ \sigma@f$
252 * @param sigma_n @f$ \sigma_n@f$
255 * @return @f$ f_i @f$ evaluated
257 static Double_t ILandauGaus(Double_t x, Double_t delta, Double_t xi,
258 Double_t sigma, Double_t sigma_n, Int_t i);
260 //------------------------------------------------------------------
262 * Numerically evaluate
264 * \left.\frac{\partial f_i}{\partial p_i}\right|_{x}
266 * where @f$ p_i@f$ is the @f$ i^{\mbox{th}}@f$ parameter. The mapping
267 * of the parameters is given by
272 * - 3: @f$\sigma_n@f$
274 * This is the partial derivative with respect to the parameter of
275 * the response function corresponding to @f$ i@f$ particles i.e.,
276 * with the substitutions
278 * \Delta \rightarrow \Delta_i = i(\Delta + \xi\log(i))\\
279 * \xi \rightarrow \xi_i = i \xi\\
280 * \sigma \rightarrow \sigma_i = \sqrt{i}\sigma\\
281 * \sigma'^2 \rightarrow \sigma_i'^2 = \sigma_n^2 + \sigma_i^2
284 * @param x Where to evaluate
285 * @param ipar Parameter number
286 * @param dp @f$ \epsilon\delta p_i@f$ for some value of @f$\epsilon@f$
287 * @param delta @f$ \Delta@f$
288 * @param xi @f$ \xi@f$
289 * @param sigma @f$ \sigma@f$
290 * @param sigma_n @f$ \sigma_n@f$
293 * @return @f$ f_i@f$ evaluated
295 static Double_t IdLandauGausdPar(Double_t x, UShort_t ipar, Double_t dp,
296 Double_t delta, Double_t xi,
297 Double_t sigma, Double_t sigma_n, Int_t i);
299 //------------------------------------------------------------------
303 * f_N(x;\Delta,\xi,\sigma') = \sum_{i=1}^N a_i f_i(x;\Delta,\xi,\sigma'a)
306 * where @f$ f(x;\Delta,\xi,\sigma')@f$ is the convolution of a
307 * Landau with a Gaussian (see LandauGaus). Note that
308 * @f$ a_1 = 1@f$, @f$\Delta_i = i(\Delta_1 + \xi\log(i))@f$,
309 * @f$\xi_i=i\xi_1@f$, and @f$\sigma_i'^2 = \sigma_n^2 + i\sigma_1^2@f$.
312 * - <a href="http://dx.doi.org/10.1016/0168-583X(84)90472-5">Nucl.Instrum.Meth.B1:16</a>
313 * - <a href="http://dx.doi.org/10.1103/PhysRevA.28.615">Phys.Rev.A28:615</a>
314 * - <a href="http://root.cern.ch/root/htmldoc/tutorials/fit/langaus.C.html">ROOT implementation</a>
316 * @param x Where to evaluate @f$ f_N@f$
317 * @param delta @f$ \Delta_1@f$
318 * @param xi @f$ \xi_1@f$
319 * @param sigma @f$ \sigma_1@f$
320 * @param sigma_n @f$ \sigma_n@f$
321 * @param n @f$ N@f$ in the sum above.
322 * @param a Array of size @f$ N-1@f$ of the weights @f$ a_i@f$ for
325 * @return @f$ f_N(x;\Delta,\xi,\sigma')@f$
327 static Double_t NLandauGaus(Double_t x, Double_t delta, Double_t xi,
328 Double_t sigma, Double_t sigma_n, Int_t n,
331 * Generate a TF1 object of @f$ f_I@f$
334 * @param delta @f$ \Delta@f$
335 * @param xi @f$ \xi_1@f$
336 * @param sigma @f$ \sigma_1@f$
337 * @param sigma_n @f$ \sigma_n@f$
338 * @param i @f$ i@f$ - the number of particles
339 * @param xmin Least value of range
340 * @param xmax Largest value of range
342 * @return Newly allocated TF1 object
344 static TF1* MakeILandauGaus(Double_t c,
345 Double_t delta, Double_t xi,
346 Double_t sigma, Double_t sigma_n,
348 Double_t xmin, Double_t xmax);
350 * Generate a TF1 object of @f$ f_N@f$
353 * @param delta @f$ \Delta@f$
354 * @param xi @f$ \xi_1@f$
355 * @param sigma @f$ \sigma_1@f$
356 * @param sigma_n @f$ \sigma_n@f$
357 * @param n @f$ N@f$ - how many particles to sum to
358 * @param a Array of size @f$ N-1@f$ of the weights @f$ a_i@f$ for
360 * @param xmin Least value of range
361 * @param xmax Largest value of range
363 * @return Newly allocated TF1 object
365 static TF1* MakeNLandauGaus(Double_t c,
366 Double_t delta, Double_t xi,
367 Double_t sigma, Double_t sigma_n,
368 Int_t n, const Double_t* a,
369 Double_t xmin, Double_t xmax);
371 //__________________________________________________________________
373 * Structure to do fits to the energy loss spectrum
375 * @ingroup pwglf_forward
391 * @param lowCut Lower cut of spectrum - data below this cuts is ignored
392 * @param maxRange Maximum range to fit to
393 * @param minusBins The number of bins below maximum to use
395 ELossFitter(Double_t lowCut, Double_t maxRange, UShort_t minusBins);
400 virtual ~ELossFitter();
402 * Clear internal arrays
407 * Fit a 1-particle signal to the passed energy loss distribution
409 * Note that this function clears the internal arrays first
411 * @param dist Data to fit the function to
412 * @param sigman If larger than zero, the initial guess of the
413 * detector induced noise. If zero or less, then this
414 * parameter is ignored in the fit (fixed at 0)
416 * @return The function fitted to the data
418 TF1* Fit1Particle(TH1* dist, Double_t sigman=-1);
420 * Fit a N-particle signal to the passed energy loss distribution
422 * If there's no 1-particle fit present, it does that first
424 * @param dist Data to fit the function to
425 * @param n Number of particle signals to fit
426 * @param sigman If larger than zero, the initial guess of the
427 * detector induced noise. If zero or less, then this
428 * parameter is ignored in the fit (fixed at 0)
430 * @return The function fitted to the data
432 TF1* FitNParticle(TH1* dist, UShort_t n, Double_t sigman=-1);
434 * Get Lower cut on data
436 * @return Lower cut on data
438 Double_t GetLowCut() const { return fLowCut; }
440 * Get Maximum range to fit
442 * @return Maximum range to fit
444 Double_t GetMaxRange() const { return fMaxRange; }
446 * Get Number of bins from maximum to fit 1st peak
448 * @return Number of bins from maximum to fit 1st peak
450 UShort_t GetMinusBins() const { return fMinusBins; }
452 * Get Array of fit results
454 * @return Array of fit results
456 const TObjArray& GetFitResults() const { return fFitResults; }
458 * Get Array of fit results
460 * @return Array of fit results
462 TObjArray& GetFitResults() { return fFitResults; }
464 * Get Array of functions
466 * @return Array of functions
468 const TObjArray& GetFunctions() const { return fFunctions; }
470 * Get Array of functions
472 * @return Array of functions
474 TObjArray& GetFunctions() { return fFunctions; }
476 const Double_t fLowCut; // Lower cut on data
477 const Double_t fMaxRange; // Maximum range to fit
478 const UShort_t fMinusBins; // Number of bins from maximum to fit 1st peak
479 TObjArray fFitResults; // Array of fit results
480 TObjArray fFunctions; // Array of functions
485 //==================================================================
488 * @name Convenience containers
491 * Structure to hold histograms
493 * @ingroup pwglf_forward
495 struct Histos : public TObject
502 Histos() : fFMD1i(0), fFMD2i(0), fFMD2o(0), fFMD3i(0), fFMD3o(0) {}
506 * @param o Object to copy from
508 Histos(const Histos& o)
517 * Assignement operator
519 * @return Reference to this
521 Histos& operator=(const Histos&) { return *this;}
527 * Initialize the object
529 * @param etaAxis Eta axis to use
531 void Init(const TAxis& etaAxis);
537 * @param etaAxis Eta axis to use
539 * @return Newly allocated histogram
541 TH2D* Make(UShort_t d, Char_t r, const TAxis& etaAxis) const;
545 * @param option Not used
547 void Clear(Option_t* option="");
548 // const TH2D* Get(UShort_t d, Char_t r) const;
550 * Get the histogram for a particular detector,ring
555 * @return Histogram for detector,ring or nul
557 TH2D* Get(UShort_t d, Char_t r) const;
558 TH2D* fFMD1i; // Histogram for FMD1i
559 TH2D* fFMD2i; // Histogram for FMD2i
560 TH2D* fFMD2o; // Histogram for FMD2o
561 TH2D* fFMD3i; // Histogram for FMD3i
562 TH2D* fFMD3o; // Histogram for FMD3o
567 //__________________________________________________________________
569 * Base class for structure holding ring specific histograms
571 * @ingroup pwglf_forward
573 struct RingHistos : public TObject
579 RingHistos() : fDet(0), fRing('\0'), fName("") {}
586 RingHistos(UShort_t d, Char_t r)
587 : fDet(d), fRing(r), fName(TString::Format("FMD%d%c", d, r))
592 * @param o Object to copy from
594 RingHistos(const RingHistos& o)
595 : TObject(o), fDet(o.fDet), fRing(o.fRing), fName(o.fName)
600 virtual ~RingHistos() {}
602 * Assignement operator
604 * @param o Object to assign from
606 * @return Reference to this
608 RingHistos& operator=(const RingHistos& o)
610 if (&o == this) return *this;
611 TObject::operator=(o);
618 * Define the outout list in @a d
620 * @param d Where to put the output list
622 * @return Newly allocated TList object or null
624 TList* DefineOutputList(TList* d) const;
626 * Get our output list from the container @a d
628 * @param d where to get the output list from
630 * @return The found TList or null
632 TList* GetOutputList(const TList* d) const;
634 * Find a specific histogram in the source list @a d
636 * @param d (top)-container
637 * @param name Name of histogram
639 * @return Found histogram or null
641 TH1* GetOutputHist(const TList* d, const char* name) const;
648 Color_t Color() const
650 return AliForwardUtil::RingColor(fDet, fRing);
653 * The name of this ring
655 * @return Name of this ring
657 const char* GetName() const { return fName.Data(); }
658 UShort_t fDet; // Detector
659 Char_t fRing; // Ring
660 TString fName; // Name
662 ClassDef(RingHistos,1)
666 //__________________________________________________________________
668 * A guard idom for producing debug output
676 * @param lvl Current level
677 * @param msgLvl Target level
678 * @param format @c printf -like format
682 DebugGuard(Int_t lvl, Int_t msgLvl, const char* format, ...);
690 * @param lvl Current level
691 * @param msgLvl Target level
692 * @param format @c printf -like format
694 static void Message(Int_t lvl, Int_t msgLvl, const char* format, ...);
699 * @param in Direction
702 static void Output(int in, TString& msg);
706 * @param out Output is stored here
707 * @param format @c printf -like format
708 * @param ap List of arguments
710 static void Format(TString& out, const char* format, va_list ap);
721 * @param o Object to copy from
723 AliForwardUtil(const AliForwardUtil& o) : TObject(o) {}
725 * Assingment operator
728 * @return Reference to this object
730 AliForwardUtil& operator=(const AliForwardUtil&) { return *this; }
737 ClassDef(AliForwardUtil,1) // Utilities - do not make object
740 // #ifdef LOG_NO_DEBUG
741 // # define DGUARD(L,N,F,...) do {} while(false)
744 * Macro to declare a DebugGuard
746 * @param L Current debug level
747 * @param N Target debug level
748 * @param F @c printf -like Format
750 # define DGUARD(L,N,F,...) \
751 AliForwardUtil::DebugGuard _GUARD(L,N,F, ## __VA_ARGS__)
753 * Macro to make a debug message, using DebugGuard::Message
755 * @param L Current debug level
756 * @param N Target debug level
757 * @param F @c printf -like Format
759 # define DMSG(L,N,F,...) \
760 AliForwardUtil::DebugGuard::Message(L,N,F, ## __VA_ARGS__)