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 * Calculate the beam rapidity.
68 * @b Note: The beam energy is given in GeV/charge
70 * @param beam Beam energy in GeV/charge
71 * @param z Charge number of projectile
72 * @param a Mass number of projectile
74 * @return The rapidity of the beam
76 static Float_t BeamRapidity(Float_t beam, UShort_t z, UShort_t a);
78 * Calculate the center of mass energy from the beam energy per
79 * charge and the nucleus numbers.
81 * @param beam Beam energy in GeV/charge
82 * @param z1 Charge number of projectile
83 * @param a1 Mass number of projectile
84 * @param z2 Charge number of projectile
85 * @param a2 Mass number of projectile
87 * @return The center of mass energy in GeV/nucleon
89 static Float_t CenterOfMassEnergy(Float_t beam, UShort_t z1, UShort_t a1,
90 Short_t z2=-1, Short_t a2=-1);
92 * Calculate the center of mass rapidity (shift)
94 * @param z1 Charge number of projectile
95 * @param a1 Mass number of projectile
96 * @param z2 Charge number of projectile
97 * @param a2 Mass number of projectile
99 * @return Rapidity of the center of mass
101 static Float_t CenterOfMassRapidity(UShort_t z1, UShort_t a1,
102 Short_t z2=-1, Short_t a2=-1);
104 * Parse a collision system spec given in a string. Known values are
106 * - "pp", "p-p" which returns kPP
107 * - "PbPb", "Pb-Pb", "A-A", which returns kPbPb
108 * - "pPb", "p-Pb", "pA", p-A" which returns kPPb
109 * - Everything else gives kUnknown
111 * @param sys Collision system spec
113 * @return Collision system id
115 static UShort_t ParseCollisionSystem(const char* sys);
117 * Get a string representation of the collision system
119 * @param sys Collision system
123 * - anything else gives "unknown"
125 * @return String representation of the collision system
127 static const char* CollisionSystemString(UShort_t sys);
128 //__________________________________________________________________
130 * Parse the center of mass energy given as a float and return known
131 * values as a unsigned integer
133 * @param sys Collision system (needed for AA)
134 * @param cms Center of mass energy * total charge
136 * @return Center of mass energy per nucleon
138 static UShort_t ParseCenterOfMassEnergy(UShort_t sys, Float_t cms);
140 * Get a string representation of the center of mass energy per nuclean
142 * @param cms Center of mass energy per nucleon
144 * @return String representation of the center of mass energy per nuclean
146 static const char* CenterOfMassEnergyString(UShort_t cms);
147 //__________________________________________________________________
149 * Parse the magnetic field (in kG) as given by a floating point number
151 * @param field Magnetic field in kG
153 * @return Short integer value of magnetic field in kG
155 static Short_t ParseMagneticField(Float_t field);
157 * Get the radius of a strip.
159 * @param ring Ring identifier 'I' or 'O'
160 * @param strip Strip number
162 * @return Radial distance from beam of the strip
164 static Double_t GetStripR(Char_t ring, UShort_t strip);
168 * @param det, ring, sec, strip, zvtx
172 static Double_t GetEtaFromStrip(UShort_t det, Char_t ring,
173 UShort_t sec, UShort_t strip, Double_t zvtx);
175 * Get the azimuthal angle of a strip
177 * @param ring Ring identifier 'I' or 'O'
178 * @param strip Strip number
179 * @param phi Straight forward strip phi
180 * @param xvtx Ip X coordinate
181 * @param yvtx Ip Y coordinate
183 * @return The phi angle correctef for (X,Y) off set.
185 static Double_t GetPhiFromStrip(Char_t ring, UShort_t strip,
186 Double_t phi, Double_t xvtx, Double_t yvtx);
188 * Get a string representation of the magnetic field
190 * @param field Magnetic field in kG
192 * @return String representation of the magnetic field
194 static const char* MagneticFieldString(Short_t field);
197 //__________________________________________________________________
199 * Get the AOD event - either from the input (AOD analysis) or the
200 * output (ESD analysis)
202 * @param task Task to do the investigation for
204 * @return Found AOD event or null
206 static AliAODEvent* GetAODEvent(AliAnalysisTaskSE* task);
208 * Check if we have something that will provide and AOD event
210 * @return 0 if there's nothing that provide an AOD event, 1 if it
211 * is provided on the input (AOD analysis) or 2 if it is provided on
212 * the output (ESD analysis)
214 static UShort_t CheckForAOD();
216 * Check if we have a particular (kind) of task in our train
218 * @param clsOrName Class name or name of task
219 * @param cls If true, look for a task of a particular class -
220 * otherwise search for a speficially name task
222 * @return true if the needed task was found
224 static Bool_t CheckForTask(const char* clsOrName, Bool_t cls=true);
226 //__________________________________________________________________
229 * @name Member functions to store and retrieve analysis parameters
231 static TObject* MakeParameter(const char* name, UShort_t value);
232 static TObject* MakeParameter(const char* name, Int_t value);
233 static TObject* MakeParameter(const char* name, Double_t value);
234 static TObject* MakeParameter(const char* name, Bool_t value);
235 static void GetParameter(TObject* o, UShort_t& value);
236 static void GetParameter(TObject* o, Int_t& value);
237 static void GetParameter(TObject* o, Double_t& value);
238 static void GetParameter(TObject* o, Bool_t& value);
243 * @name Energy stragling functions
245 //__________________________________________________________________
247 * Number of steps to do in the Landau, Gaussiam convolution
249 static Int_t fgConvolutionSteps; // Number of convolution steps
250 //------------------------------------------------------------------
252 * How many sigma's of the Gaussian in the Landau, Gaussian
253 * convolution to integrate over
255 static Double_t fgConvolutionNSigma; // Number of convolution sigmas
256 //------------------------------------------------------------------
258 * Calculate the shifted Landau
260 * f'_{L}(x;\Delta,\xi) = f_L(x;\Delta+0.22278298\xi)
263 * where @f$ f_{L}@f$ is the ROOT implementation of the Landau
264 * distribution (known to have @f$ \Delta_{p}=-0.22278298@f$ for
265 * @f$\Delta=0,\xi=1@f$.
267 * @param x Where to evaluate @f$ f'_{L}@f$
268 * @param delta Most probable value
269 * @param xi The 'width' of the distribution
271 * @return @f$ f'_{L}(x;\Delta,\xi) @f$
273 static Double_t Landau(Double_t x, Double_t delta, Double_t xi);
275 //------------------------------------------------------------------
277 * Calculate the value of a Landau convolved with a Gaussian
280 * f(x;\Delta,\xi,\sigma') = \frac{1}{\sigma' \sqrt{2 \pi}}
281 * \int_{-\infty}^{+\infty} d\Delta' f'_{L}(x;\Delta',\xi)
282 * \exp{-\frac{(\Delta-\Delta')^2}{2\sigma'^2}}
285 * where @f$ f'_{L}@f$ is the Landau distribution, @f$ \Delta@f$ the
286 * energy loss, @f$ \xi@f$ the width of the Landau, and
287 * @f$ \sigma'^2=\sigma^2-\sigma_n^2 @f$. Here, @f$\sigma@f$ is the
288 * variance of the Gaussian, and @f$\sigma_n@f$ is a parameter modelling
289 * noise in the detector.
291 * Note that this function uses the constants fgConvolutionSteps and
292 * fgConvolutionNSigma
295 * - <a href="http://dx.doi.org/10.1016/0168-583X(84)90472-5">Nucl.Instrum.Meth.B1:16</a>
296 * - <a href="http://dx.doi.org/10.1103/PhysRevA.28.615">Phys.Rev.A28:615</a>
297 * - <a href="http://root.cern.ch/root/htmldoc/tutorials/fit/langaus.C.html">ROOT implementation</a>
299 * @param x where to evaluate @f$ f@f$
300 * @param delta @f$ \Delta@f$ of @f$ f(x;\Delta,\xi,\sigma')@f$
301 * @param xi @f$ \xi@f$ of @f$ f(x;\Delta,\xi,\sigma')@f$
302 * @param sigma @f$ \sigma@f$ of @f$\sigma'^2=\sigma^2-\sigma_n^2 @f$
303 * @param sigma_n @f$ \sigma_n@f$ of @f$\sigma'^2=\sigma^2-\sigma_n^2 @f$
305 * @return @f$ f@f$ evaluated at @f$ x@f$.
307 static Double_t LandauGaus(Double_t x, Double_t delta, Double_t xi,
308 Double_t sigma, Double_t sigma_n);
310 //------------------------------------------------------------------
314 * f_i(x;\Delta,\xi,\sigma') = f(x;\Delta_i,\xi_i,\sigma_i')
316 * corresponding to @f$ i@f$ particles i.e., with the substitutions
318 * \Delta \rightarrow \Delta_i &=& i(\Delta + \xi\log(i))\\
319 * \xi \rightarrow \xi_i &=& i \xi\\
320 * \sigma \rightarrow \sigma_i &=& \sqrt{i}\sigma\\
321 * \sigma'^2 \rightarrow \sigma_i'^2 &=& \sigma_n^2 + \sigma_i^2
324 * @param x Where to evaluate
325 * @param delta @f$ \Delta@f$
326 * @param xi @f$ \xi@f$
327 * @param sigma @f$ \sigma@f$
328 * @param sigma_n @f$ \sigma_n@f$
331 * @return @f$ f_i @f$ evaluated
333 static Double_t ILandauGaus(Double_t x, Double_t delta, Double_t xi,
334 Double_t sigma, Double_t sigma_n, Int_t i);
336 //------------------------------------------------------------------
338 * Numerically evaluate
340 * \left.\frac{\partial f_i}{\partial p_i}\right|_{x}
342 * where @f$ p_i@f$ is the @f$ i^{\mbox{th}}@f$ parameter. The mapping
343 * of the parameters is given by
348 * - 3: @f$\sigma_n@f$
350 * This is the partial derivative with respect to the parameter of
351 * the response function corresponding to @f$ i@f$ particles i.e.,
352 * with the substitutions
354 * \Delta \rightarrow \Delta_i = i(\Delta + \xi\log(i))\\
355 * \xi \rightarrow \xi_i = i \xi\\
356 * \sigma \rightarrow \sigma_i = \sqrt{i}\sigma\\
357 * \sigma'^2 \rightarrow \sigma_i'^2 = \sigma_n^2 + \sigma_i^2
360 * @param x Where to evaluate
361 * @param ipar Parameter number
362 * @param dp @f$ \epsilon\delta p_i@f$ for some value of @f$\epsilon@f$
363 * @param delta @f$ \Delta@f$
364 * @param xi @f$ \xi@f$
365 * @param sigma @f$ \sigma@f$
366 * @param sigma_n @f$ \sigma_n@f$
369 * @return @f$ f_i@f$ evaluated
371 static Double_t IdLandauGausdPar(Double_t x, UShort_t ipar, Double_t dp,
372 Double_t delta, Double_t xi,
373 Double_t sigma, Double_t sigma_n, Int_t i);
375 //------------------------------------------------------------------
379 * f_N(x;\Delta,\xi,\sigma') = \sum_{i=1}^N a_i f_i(x;\Delta,\xi,\sigma'a)
382 * where @f$ f(x;\Delta,\xi,\sigma')@f$ is the convolution of a
383 * Landau with a Gaussian (see LandauGaus). Note that
384 * @f$ a_1 = 1@f$, @f$\Delta_i = i(\Delta_1 + \xi\log(i))@f$,
385 * @f$\xi_i=i\xi_1@f$, and @f$\sigma_i'^2 = \sigma_n^2 + i\sigma_1^2@f$.
388 * - <a href="http://dx.doi.org/10.1016/0168-583X(84)90472-5">Nucl.Instrum.Meth.B1:16</a>
389 * - <a href="http://dx.doi.org/10.1103/PhysRevA.28.615">Phys.Rev.A28:615</a>
390 * - <a href="http://root.cern.ch/root/htmldoc/tutorials/fit/langaus.C.html">ROOT implementation</a>
392 * @param x Where to evaluate @f$ f_N@f$
393 * @param delta @f$ \Delta_1@f$
394 * @param xi @f$ \xi_1@f$
395 * @param sigma @f$ \sigma_1@f$
396 * @param sigma_n @f$ \sigma_n@f$
397 * @param n @f$ N@f$ in the sum above.
398 * @param a Array of size @f$ N-1@f$ of the weights @f$ a_i@f$ for
401 * @return @f$ f_N(x;\Delta,\xi,\sigma')@f$
403 static Double_t NLandauGaus(Double_t x, Double_t delta, Double_t xi,
404 Double_t sigma, Double_t sigma_n, Int_t n,
407 * Generate a TF1 object of @f$ f_I@f$
410 * @param delta @f$ \Delta@f$
411 * @param xi @f$ \xi_1@f$
412 * @param sigma @f$ \sigma_1@f$
413 * @param sigma_n @f$ \sigma_n@f$
414 * @param i @f$ i@f$ - the number of particles
415 * @param xmin Least value of range
416 * @param xmax Largest value of range
418 * @return Newly allocated TF1 object
420 static TF1* MakeILandauGaus(Double_t c,
421 Double_t delta, Double_t xi,
422 Double_t sigma, Double_t sigma_n,
424 Double_t xmin, Double_t xmax);
426 * Generate a TF1 object of @f$ f_N@f$
429 * @param delta @f$ \Delta@f$
430 * @param xi @f$ \xi_1@f$
431 * @param sigma @f$ \sigma_1@f$
432 * @param sigma_n @f$ \sigma_n@f$
433 * @param n @f$ N@f$ - how many particles to sum to
434 * @param a Array of size @f$ N-1@f$ of the weights @f$ a_i@f$ for
436 * @param xmin Least value of range
437 * @param xmax Largest value of range
439 * @return Newly allocated TF1 object
441 static TF1* MakeNLandauGaus(Double_t c,
442 Double_t delta, Double_t xi,
443 Double_t sigma, Double_t sigma_n,
444 Int_t n, const Double_t* a,
445 Double_t xmin, Double_t xmax);
447 //__________________________________________________________________
449 * Structure to do fits to the energy loss spectrum
451 * @ingroup pwglf_forward
467 * @param lowCut Lower cut of spectrum - data below this cuts is ignored
468 * @param maxRange Maximum range to fit to
469 * @param minusBins The number of bins below maximum to use
471 ELossFitter(Double_t lowCut, Double_t maxRange, UShort_t minusBins);
476 virtual ~ELossFitter();
478 * Clear internal arrays
483 * Fit a 1-particle signal to the passed energy loss distribution
485 * Note that this function clears the internal arrays first
487 * @param dist Data to fit the function to
488 * @param sigman If larger than zero, the initial guess of the
489 * detector induced noise. If zero or less, then this
490 * parameter is ignored in the fit (fixed at 0)
492 * @return The function fitted to the data
494 TF1* Fit1Particle(TH1* dist, Double_t sigman=-1);
496 * Fit a N-particle signal to the passed energy loss distribution
498 * If there's no 1-particle fit present, it does that first
500 * @param dist Data to fit the function to
501 * @param n Number of particle signals to fit
502 * @param sigman If larger than zero, the initial guess of the
503 * detector induced noise. If zero or less, then this
504 * parameter is ignored in the fit (fixed at 0)
506 * @return The function fitted to the data
508 TF1* FitNParticle(TH1* dist, UShort_t n, Double_t sigman=-1);
510 * Get Lower cut on data
512 * @return Lower cut on data
514 Double_t GetLowCut() const { return fLowCut; }
516 * Get Maximum range to fit
518 * @return Maximum range to fit
520 Double_t GetMaxRange() const { return fMaxRange; }
522 * Get Number of bins from maximum to fit 1st peak
524 * @return Number of bins from maximum to fit 1st peak
526 UShort_t GetMinusBins() const { return fMinusBins; }
528 * Get Array of fit results
530 * @return Array of fit results
532 const TObjArray& GetFitResults() const { return fFitResults; }
534 * Get Array of fit results
536 * @return Array of fit results
538 TObjArray& GetFitResults() { return fFitResults; }
540 * Get Array of functions
542 * @return Array of functions
544 const TObjArray& GetFunctions() const { return fFunctions; }
546 * Get Array of functions
548 * @return Array of functions
550 TObjArray& GetFunctions() { return fFunctions; }
552 const Double_t fLowCut; // Lower cut on data
553 const Double_t fMaxRange; // Maximum range to fit
554 const UShort_t fMinusBins; // Number of bins from maximum to fit 1st peak
555 TObjArray fFitResults; // Array of fit results
556 TObjArray fFunctions; // Array of functions
561 //==================================================================
564 * @name Convenience containers
567 * Structure to hold histograms
569 * @ingroup pwglf_forward
571 struct Histos : public TObject
578 Histos() : fFMD1i(0), fFMD2i(0), fFMD2o(0), fFMD3i(0), fFMD3o(0) {}
582 * @param o Object to copy from
584 Histos(const Histos& o)
593 * Assignement operator
595 * @return Reference to this
597 Histos& operator=(const Histos&) { return *this;}
599 * Destructor. This does not delete the interally allocated
600 * memory. Use the member function Delete for that.
604 * Clear internal memory. Note, if the internal histograms are
605 * added to an output container, then we must not free this
608 void Delete(Option_t* opt="");
610 * Initialize the object
612 * @param etaAxis Eta axis to use
614 void Init(const TAxis& etaAxis);
620 * @param etaAxis Eta axis to use
622 * @return Newly allocated histogram
624 TH2D* Make(UShort_t d, Char_t r, const TAxis& etaAxis) const;
628 * @param option Not used
630 void Clear(Option_t* option="");
631 // const TH2D* Get(UShort_t d, Char_t r) const;
633 * Get the histogram for a particular detector,ring
638 * @return Histogram for detector,ring or nul
640 TH2D* Get(UShort_t d, Char_t r) const;
641 TH2D* fFMD1i; // Histogram for FMD1i
642 TH2D* fFMD2i; // Histogram for FMD2i
643 TH2D* fFMD2o; // Histogram for FMD2o
644 TH2D* fFMD3i; // Histogram for FMD3i
645 TH2D* fFMD3o; // Histogram for FMD3o
650 //__________________________________________________________________
652 * Base class for structure holding ring specific histograms
654 * @ingroup pwglf_forward
656 struct RingHistos : public TObject
662 RingHistos() : fDet(0), fRing('\0'), fName("") {}
669 RingHistos(UShort_t d, Char_t r)
670 : fDet(d), fRing(r), fName(TString::Format("FMD%d%c", d, r))
675 * @param o Object to copy from
677 RingHistos(const RingHistos& o)
678 : TObject(o), fDet(o.fDet), fRing(o.fRing), fName(o.fName)
683 virtual ~RingHistos() {}
685 * Assignement operator
687 * @param o Object to assign from
689 * @return Reference to this
691 RingHistos& operator=(const RingHistos& o)
693 if (&o == this) return *this;
694 TObject::operator=(o);
701 * Define the outout list in @a d
703 * @param d Where to put the output list
705 * @return Newly allocated TList object or null
707 TList* DefineOutputList(TList* d) const;
709 * Get our output list from the container @a d
711 * @param d where to get the output list from
713 * @return The found TList or null
715 TList* GetOutputList(const TList* d) const;
717 * Find a specific histogram in the source list @a d
719 * @param d (top)-container
720 * @param name Name of histogram
722 * @return Found histogram or null
724 TH1* GetOutputHist(const TList* d, const char* name) const;
731 Color_t Color() const
733 return AliForwardUtil::RingColor(fDet, fRing);
736 * The name of this ring
738 * @return Name of this ring
740 const char* GetName() const { return fName.Data(); }
741 UShort_t fDet; // Detector
742 Char_t fRing; // Ring
743 TString fName; // Name
745 ClassDef(RingHistos,1)
749 //__________________________________________________________________
751 * A guard idom for producing debug output
759 * @param lvl Current level
760 * @param msgLvl Target level
761 * @param format @c printf -like format
765 DebugGuard(Int_t lvl, Int_t msgLvl, const char* format, ...);
773 * @param lvl Current level
774 * @param msgLvl Target level
775 * @param format @c printf -like format
777 static void Message(Int_t lvl, Int_t msgLvl, const char* format, ...);
782 * @param in Direction
785 static void Output(int in, TString& msg);
789 * @param out Output is stored here
790 * @param format @c printf -like format
791 * @param ap List of arguments
793 static void Format(TString& out, const char* format, va_list ap);
804 * @param o Object to copy from
806 AliForwardUtil(const AliForwardUtil& o) : TObject(o) {}
808 * Assingment operator
811 * @return Reference to this object
813 AliForwardUtil& operator=(const AliForwardUtil&) { return *this; }
820 ClassDef(AliForwardUtil,1) // Utilities - do not make object
823 // #ifdef LOG_NO_DEBUG
824 // # define DGUARD(L,N,F,...) do {} while(false)
827 * Macro to declare a DebugGuard
829 * @param L Current debug level
830 * @param N Target debug level
831 * @param F @c printf -like Format
833 # define DGUARD(L,N,F,...) \
834 AliForwardUtil::DebugGuard _GUARD(L,N,F, ## __VA_ARGS__)
836 * Macro to make a debug message, using DebugGuard::Message
838 * @param L Current debug level
839 * @param N Target debug level
840 * @param F @c printf -like Format
842 # define DMSG(L,N,F,...) \
843 AliForwardUtil::DebugGuard::Message(L,N,F, ## __VA_ARGS__)