2 // Utilities used in the forward multiplcity analysis
5 #include "AliForwardUtil.h"
6 #include <AliAnalysisManager.h>
7 #include "AliAODForwardMult.h"
9 #include <AliInputEventHandler.h>
10 #include <AliAODInputHandler.h>
11 #include <AliAODHandler.h>
12 #include <AliAODEvent.h>
13 #include <AliESDEvent.h>
14 #include <AliAnalysisTaskSE.h>
15 #include <AliPhysicsSelection.h>
16 #include <AliTriggerAnalysis.h>
17 #include <AliMultiplicity.h>
18 #include <TParameter.h>
22 #include <TFitResult.h>
27 //====================================================================
29 AliForwardUtil::ParseCollisionSystem(const char* sys)
32 // Parse a collision system spec given in a string. Known values are
34 // - "ppb", "p-pb", "pa", "p-a" which returns kPPb
35 // - "pp", "p-p" which returns kPP
36 // - "PbPb", "Pb-Pb", "A-A", which returns kPbPb
37 // - Everything else gives kUnknown
40 // sys Collision system spec
43 // Collision system id
47 // we do pA first to avoid pp catch on ppb string (AH)
48 if (s.Contains("p-pb") || s.Contains("ppb")) return AliForwardUtil::kPPb;
49 if (s.Contains("p-a") || s.Contains("pa")) return AliForwardUtil::kPPb;
50 if (s.Contains("a-p") || s.Contains("ap")) return AliForwardUtil::kPPb;
51 if (s.Contains("p-p") || s.Contains("pp")) return AliForwardUtil::kPP;
52 if (s.Contains("pb-pb") || s.Contains("pbpb")) return AliForwardUtil::kPbPb;
53 if (s.Contains("a-a") || s.Contains("aa")) return AliForwardUtil::kPbPb;
54 return AliForwardUtil::kUnknown;
56 //____________________________________________________________________
58 AliForwardUtil::CollisionSystemString(UShort_t sys)
61 // Get a string representation of the collision system
64 // sys Collision system
67 // - anything else gives "unknown"
70 // String representation of the collision system
73 case AliForwardUtil::kPP: return "pp";
74 case AliForwardUtil::kPbPb: return "PbPb";
75 case AliForwardUtil::kPPb: return "pPb";
79 //____________________________________________________________________
81 AliForwardUtil::ParseCenterOfMassEnergy(UShort_t /* sys */, Float_t v)
84 // Parse the center of mass energy given as a float and return known
85 // values as a unsigned integer
88 // sys Collision system (needed for AA)
89 // cms Center of mass energy * total charge
92 // Center of mass energy per nucleon
95 // Below no longer needed apparently
96 // if (sys == AliForwardUtil::kPbPb) energy = energy / 208 * 82;
97 if (TMath::Abs(energy - 900.) < 10) return 900;
98 if (TMath::Abs(energy - 2400.) < 10) return 2400;
99 if (TMath::Abs(energy - 2750.) < 20) return 2750;
100 if (TMath::Abs(energy - 4400.) < 10) return 4400;
101 if (TMath::Abs(energy - 5022.) < 10) return 5000;
102 if (TMath::Abs(energy - 5500.) < 40) return 5500;
103 if (TMath::Abs(energy - 7000.) < 10) return 7000;
104 if (TMath::Abs(energy - 8000.) < 10) return 8000;
105 if (TMath::Abs(energy - 10000.) < 10) return 10000;
106 if (TMath::Abs(energy - 14000.) < 10) return 14000;
109 //____________________________________________________________________
111 AliForwardUtil::CenterOfMassEnergyString(UShort_t cms)
114 // Get a string representation of the center of mass energy per nuclean
117 // cms Center of mass energy per nucleon
120 // String representation of the center of mass energy per nuclean
122 return Form("%04dGeV", cms);
124 //____________________________________________________________________
126 AliForwardUtil::ParseMagneticField(Float_t v)
129 // Parse the magnetic field (in kG) as given by a floating point number
132 // field Magnetic field in kG
135 // Short integer value of magnetic field in kG
137 if (TMath::Abs(v - 5.) < 1 ) return +5;
138 if (TMath::Abs(v + 5.) < 1 ) return -5;
139 if (TMath::Abs(v) < 1) return 0;
142 //____________________________________________________________________
144 AliForwardUtil::MagneticFieldString(Short_t f)
147 // Get a string representation of the magnetic field
150 // field Magnetic field in kG
153 // String representation of the magnetic field
155 return Form("%01dkG", f);
157 //_____________________________________________________________________
158 AliAODEvent* AliForwardUtil::GetAODEvent(AliAnalysisTaskSE* task)
160 // Check if AOD is the output event
161 if (!task) ::Fatal("GetAODEvent", "Null task given, cannot do that");
163 AliAODEvent* ret = task->AODEvent();
166 // Check if AOD is the input event
167 ret = dynamic_cast<AliAODEvent*>(task->InputEvent());
168 if (!ret) ::Warning("GetAODEvent", "No AOD event found");
172 //_____________________________________________________________________
173 UShort_t AliForwardUtil::CheckForAOD()
175 AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
176 if (dynamic_cast<AliAODInputHandler*>(am->GetInputEventHandler())) {
177 ::Info("CheckForAOD", "Found AOD Input handler");
180 if (dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler())) {
181 ::Info("CheckForAOD", "Found AOD Output handler");
185 ::Warning("CheckForAOD",
186 "Neither and input nor output AOD handler is specified");
189 //_____________________________________________________________________
190 Bool_t AliForwardUtil::CheckForTask(const char* clsOrName, Bool_t cls)
192 AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
194 AliAnalysisTask* t = am->GetTask(clsOrName);
196 ::Warning("CheckForTask", "Task %s not found in manager", clsOrName);
199 ::Info("CheckForTask", "Found task %s", clsOrName);
202 TClass* dep = gROOT->GetClass(clsOrName);
204 ::Warning("CheckForTask", "Unknown class %s for needed task", clsOrName);
207 TIter next(am->GetTasks());
209 while ((o = next())) {
210 if (o->IsA()->InheritsFrom(dep)) {
211 ::Info("CheckForTask", "Found task of class %s: %s",
212 clsOrName, o->GetName());
216 ::Warning("CheckForTask", "No task of class %s was found", clsOrName);
220 //_____________________________________________________________________
221 TObject* AliForwardUtil::MakeParameter(const Char_t* name, UShort_t value)
223 TParameter<int>* ret = new TParameter<int>(name, value);
224 ret->SetUniqueID(value);
227 //_____________________________________________________________________
228 TObject* AliForwardUtil::MakeParameter(const Char_t* name, Int_t value)
230 TParameter<int>* ret = new TParameter<int>(name, value);
231 ret->SetUniqueID(value);
234 //_____________________________________________________________________
235 TObject* AliForwardUtil::MakeParameter(const Char_t* name, Double_t value)
237 TParameter<double>* ret = new TParameter<double>(name, value);
239 UInt_t* tmp = reinterpret_cast<UInt_t*>(&v);
240 ret->SetUniqueID(*tmp);
243 //_____________________________________________________________________
244 TObject* AliForwardUtil::MakeParameter(const Char_t* name, Bool_t value)
246 TParameter<bool>* ret = new TParameter<bool>(name, value);
247 ret->SetUniqueID(value);
251 //_____________________________________________________________________
252 void AliForwardUtil::GetParameter(TObject* o, UShort_t& value)
255 value = o->GetUniqueID();
257 //_____________________________________________________________________
258 void AliForwardUtil::GetParameter(TObject* o, Int_t& value)
261 value = o->GetUniqueID();
263 //_____________________________________________________________________
264 void AliForwardUtil::GetParameter(TObject* o, Double_t& value)
267 UInt_t i = o->GetUniqueID();
268 Float_t v = *reinterpret_cast<Float_t*>(&i);
271 //_____________________________________________________________________
272 void AliForwardUtil::GetParameter(TObject* o, Bool_t& value)
275 value = o->GetUniqueID();
278 //_____________________________________________________________________
279 Double_t AliForwardUtil::GetEtaFromStrip(UShort_t det, Char_t ring, UShort_t sec, UShort_t strip, Double_t zvtx)
281 //Calculate eta from strip with vertex (redundant with AliESDFMD::Eta but support displaced vertices)
286 Bool_t inner = false;
288 case 'i': case 'I': maxR = 17.2; minR = 4.5213; inner = true; break;
289 case 'o': case 'O': maxR = 28.0; minR = 15.4; inner = false; break;
294 Double_t rad = maxR- minR;
295 Double_t nStrips = (ring == 'I' ? 512 : 256);
296 Double_t segment = rad / nStrips;
297 Double_t r = minR + segment*strip;
298 Int_t hybrid = sec / 2;
302 case 1: z = 320.266; break;
303 case 2: z = (inner ? 83.666 : 74.966); break;
304 case 3: z = (inner ? -63.066 : -74.966); break;
305 default: return -999999;
307 if ((hybrid % 2) == 0) z -= .5;
309 Double_t theta = TMath::ATan2(r,z-zvtx);
310 Double_t eta = -1*TMath::Log(TMath::Tan(0.5*theta));
316 //====================================================================
317 Int_t AliForwardUtil::fgConvolutionSteps = 100;
318 Double_t AliForwardUtil::fgConvolutionNSigma = 5;
321 // The shift of the most probable value for the ROOT function TMath::Landau
323 const Double_t mpshift = -0.22278298;
325 // Integration normalisation
327 const Double_t invSq2pi = 1. / TMath::Sqrt(2*TMath::Pi());
330 // Utility function to use in TF1 defintition
332 Double_t landauGaus1(Double_t* xp, Double_t* pp)
335 Double_t constant = pp[AliForwardUtil::ELossFitter::kC];
336 Double_t delta = pp[AliForwardUtil::ELossFitter::kDelta];
337 Double_t xi = pp[AliForwardUtil::ELossFitter::kXi];
338 Double_t sigma = pp[AliForwardUtil::ELossFitter::kSigma];
339 Double_t sigmaN = pp[AliForwardUtil::ELossFitter::kSigmaN];
341 return constant * AliForwardUtil::LandauGaus(x, delta, xi, sigma, sigmaN);
345 // Utility function to use in TF1 defintition
347 Double_t landauGausN(Double_t* xp, Double_t* pp)
350 Double_t constant = pp[AliForwardUtil::ELossFitter::kC];
351 Double_t delta = pp[AliForwardUtil::ELossFitter::kDelta];
352 Double_t xi = pp[AliForwardUtil::ELossFitter::kXi];
353 Double_t sigma = pp[AliForwardUtil::ELossFitter::kSigma];
354 Double_t sigmaN = pp[AliForwardUtil::ELossFitter::kSigmaN];
355 Int_t n = Int_t(pp[AliForwardUtil::ELossFitter::kN]);
356 Double_t* a = &(pp[AliForwardUtil::ELossFitter::kA]);
358 return constant * AliForwardUtil::NLandauGaus(x, delta, xi, sigma, sigmaN,
362 // Utility function to use in TF1 defintition
364 Double_t landauGausI(Double_t* xp, Double_t* pp)
367 Double_t constant = pp[AliForwardUtil::ELossFitter::kC];
368 Double_t delta = pp[AliForwardUtil::ELossFitter::kDelta];
369 Double_t xi = pp[AliForwardUtil::ELossFitter::kXi];
370 Double_t sigma = pp[AliForwardUtil::ELossFitter::kSigma];
371 Double_t sigmaN = pp[AliForwardUtil::ELossFitter::kSigmaN];
372 Int_t i = Int_t(pp[AliForwardUtil::ELossFitter::kN]);
374 return constant * AliForwardUtil::ILandauGaus(x,delta,xi,sigma,sigmaN,i);
379 //____________________________________________________________________
381 AliForwardUtil::Landau(Double_t x, Double_t delta, Double_t xi)
384 // Calculate the shifted Landau
386 // f'_{L}(x;\Delta,\xi) = f_L(x;\Delta+0.22278298\xi)
389 // where @f$ f_{L}@f$ is the ROOT implementation of the Landau
390 // distribution (known to have @f$ \Delta_{p}=-0.22278298@f$ for
391 // @f$\Delta=0,\xi=1@f$.
394 // x Where to evaluate @f$ f'_{L}@f$
395 // delta Most probable value
396 // xi The 'width' of the distribution
399 // @f$ f'_{L}(x;\Delta,\xi) @f$
401 return TMath::Landau(x, delta - xi * mpshift, xi);
403 //____________________________________________________________________
405 AliForwardUtil::LandauGaus(Double_t x, Double_t delta, Double_t xi,
406 Double_t sigma, Double_t sigmaN)
409 // Calculate the value of a Landau convolved with a Gaussian
412 // f(x;\Delta,\xi,\sigma') = \frac{1}{\sigma' \sqrt{2 \pi}}
413 // \int_{-\infty}^{+\infty} d\Delta' f'_{L}(x;\Delta',\xi)
414 // \exp{-\frac{(\Delta-\Delta')^2}{2\sigma'^2}}
417 // where @f$ f'_{L}@f$ is the Landau distribution, @f$ \Delta@f$ the
418 // energy loss, @f$ \xi@f$ the width of the Landau, and
419 // @f$ \sigma'^2=\sigma^2-\sigma_n^2 @f$. Here, @f$\sigma@f$ is the
420 // variance of the Gaussian, and @f$\sigma_n@f$ is a parameter modelling
421 // noise in the detector.
423 // Note that this function uses the constants fgConvolutionSteps and
424 // fgConvolutionNSigma
427 // - <a href="http://dx.doi.org/10.1016/0168-583X(84)90472-5">Nucl.Instrum.Meth.B1:16</a>
428 // - <a href="http://dx.doi.org/10.1103/PhysRevA.28.615">Phys.Rev.A28:615</a>
429 // - <a href="http://root.cern.ch/root/htmldoc/tutorials/fit/langaus.C.html">ROOT implementation</a>
432 // x where to evaluate @f$ f@f$
433 // delta @f$ \Delta@f$ of @f$ f(x;\Delta,\xi,\sigma')@f$
434 // xi @f$ \xi@f$ of @f$ f(x;\Delta,\xi,\sigma')@f$
435 // sigma @f$ \sigma@f$ of @f$\sigma'^2=\sigma^2-\sigma_n^2 @f$
436 // sigma_n @f$ \sigma_n@f$ of @f$\sigma'^2=\sigma^2-\sigma_n^2 @f$
439 // @f$ f@f$ evaluated at @f$ x@f$.
441 Double_t deltap = delta - xi * mpshift;
442 Double_t sigma2 = sigmaN*sigmaN + sigma*sigma;
443 Double_t sigma1 = sigmaN == 0 ? sigma : TMath::Sqrt(sigma2);
444 Double_t xlow = x - fgConvolutionNSigma * sigma1;
445 Double_t xhigh = x + fgConvolutionNSigma * sigma1;
446 Double_t step = (xhigh - xlow) / fgConvolutionSteps;
449 for (Int_t i = 0; i <= fgConvolutionSteps/2; i++) {
450 Double_t x1 = xlow + (i - .5) * step;
451 Double_t x2 = xhigh - (i - .5) * step;
453 sum += TMath::Landau(x1, deltap, xi, kTRUE) * TMath::Gaus(x, x1, sigma1);
454 sum += TMath::Landau(x2, deltap, xi, kTRUE) * TMath::Gaus(x, x2, sigma1);
456 return step * sum * invSq2pi / sigma1;
459 //____________________________________________________________________
461 AliForwardUtil::ILandauGaus(Double_t x, Double_t delta, Double_t xi,
462 Double_t sigma, Double_t sigmaN, Int_t i)
467 // f_i(x;\Delta,\xi,\sigma') = f(x;\Delta_i,\xi_i,\sigma_i')
469 // corresponding to @f$ i@f$ particles i.e., with the substitutions
471 // \Delta \rightarrow \Delta_i &=& i(\Delta + \xi\log(i))
472 // \xi \rightarrow \xi_i &=& i \xi
473 // \sigma \rightarrow \sigma_i &=& \sqrt{i}\sigma
474 // \sigma'^2 \rightarrow \sigma_i'^2 &=& \sigma_n^2 + \sigma_i^2
478 // x Where to evaluate
479 // delta @f$ \Delta@f$
481 // sigma @f$ \sigma@f$
482 // sigma_n @f$ \sigma_n@f$
486 // @f$ f_i @f$ evaluated
488 Double_t deltaI = (i == 1 ? delta : i * (delta + xi * TMath::Log(i)));
489 Double_t xiI = i * xi;
490 Double_t sigmaI = (i == 1 ? sigma : TMath::Sqrt(Double_t(i))*sigma);
491 if (sigmaI < 1e-10) {
492 // Fall back to landau
493 return AliForwardUtil::Landau(x, deltaI, xiI);
495 return AliForwardUtil::LandauGaus(x, deltaI, xiI, sigmaI, sigmaN);
498 //____________________________________________________________________
500 AliForwardUtil::IdLandauGausdPar(Double_t x,
501 UShort_t par, Double_t dPar,
502 Double_t delta, Double_t xi,
503 Double_t sigma, Double_t sigmaN,
507 // Numerically evaluate
509 // \left.\frac{\partial f_i}{\partial p_i}\right|_{x}
511 // where @f$ p_i@f$ is the @f$ i^{\mbox{th}}@f$ parameter. The mapping
512 // of the parameters is given by
517 // - 3: @f$\sigma_n@f$
519 // This is the partial derivative with respect to the parameter of
520 // the response function corresponding to @f$ i@f$ particles i.e.,
521 // with the substitutions
523 // \Delta \rightarrow \Delta_i = i(\Delta + \xi\log(i))
524 // \xi \rightarrow \xi_i = i \xi
525 // \sigma \rightarrow \sigma_i = \sqrt{i}\sigma
526 // \sigma'^2 \rightarrow \sigma_i'^2 = \sigma_n^2 + \sigma_i^2
530 // x Where to evaluate
531 // ipar Parameter number
532 // dp @f$ \epsilon\delta p_i@f$ for some value of @f$\epsilon@f$
533 // delta @f$ \Delta@f$
535 // sigma @f$ \sigma@f$
536 // sigma_n @f$ \sigma_n@f$
540 // @f$ f_i@f$ evaluated
542 if (dPar == 0) return 0;
544 Double_t d2 = dPar / 2;
545 Double_t deltaI = i * (delta + xi * TMath::Log(i));
546 Double_t xiI = i * xi;
547 Double_t si = TMath::Sqrt(Double_t(i));
548 Double_t sigmaI = si*sigma;
555 y1 = ILandauGaus(x, deltaI+i*dp, xiI, sigmaI, sigmaN, i);
556 y2 = ILandauGaus(x, deltaI+i*d2, xiI, sigmaI, sigmaN, i);
557 y3 = ILandauGaus(x, deltaI-i*d2, xiI, sigmaI, sigmaN, i);
558 y4 = ILandauGaus(x, deltaI-i*dp, xiI, sigmaI, sigmaN, i);
561 y1 = ILandauGaus(x, deltaI, xiI+i*dp, sigmaI, sigmaN, i);
562 y2 = ILandauGaus(x, deltaI, xiI+i*d2, sigmaI, sigmaN, i);
563 y3 = ILandauGaus(x, deltaI, xiI-i*d2, sigmaI, sigmaN, i);
564 y4 = ILandauGaus(x, deltaI, xiI-i*dp, sigmaI, sigmaN, i);
567 y1 = ILandauGaus(x, deltaI, xiI, sigmaI+si*dp, sigmaN, i);
568 y2 = ILandauGaus(x, deltaI, xiI, sigmaI+si*d2, sigmaN, i);
569 y3 = ILandauGaus(x, deltaI, xiI, sigmaI-si*d2, sigmaN, i);
570 y4 = ILandauGaus(x, deltaI, xiI, sigmaI-si*dp, sigmaN, i);
573 y1 = ILandauGaus(x, deltaI, xiI, sigmaI, sigmaN+dp, i);
574 y2 = ILandauGaus(x, deltaI, xiI, sigmaI, sigmaN+d2, i);
575 y3 = ILandauGaus(x, deltaI, xiI, sigmaI, sigmaN-d2, i);
576 y4 = ILandauGaus(x, deltaI, xiI, sigmaI, sigmaN-dp, i);
582 Double_t d0 = y1 - y4;
583 Double_t d1 = 2 * (y2 - y3);
585 Double_t g = 1/(2*dp) * (4*d1 - d0) / 3;
590 //____________________________________________________________________
592 AliForwardUtil::NLandauGaus(Double_t x, Double_t delta, Double_t xi,
593 Double_t sigma, Double_t sigmaN, Int_t n,
599 // f_N(x;\Delta,\xi,\sigma') = \sum_{i=1}^N a_i f_i(x;\Delta,\xi,\sigma'a)
602 // where @f$ f(x;\Delta,\xi,\sigma')@f$ is the convolution of a
603 // Landau with a Gaussian (see LandauGaus). Note that
604 // @f$ a_1 = 1@f$, @f$\Delta_i = i(\Delta_1 + \xi\log(i))@f$,
605 // @f$\xi_i=i\xi_1@f$, and @f$\sigma_i'^2 = \sigma_n^2 + i\sigma_1^2@f$.
608 // - <a href="http://dx.doi.org/10.1016/0168-583X(84)90472-5">Nucl.Instrum.Meth.B1:16</a>
609 // - <a href="http://dx.doi.org/10.1103/PhysRevA.28.615">Phys.Rev.A28:615</a>
610 // - <a href="http://root.cern.ch/root/htmldoc/tutorials/fit/langaus.C.html">ROOT implementation</a>
613 // x Where to evaluate @f$ f_N@f$
614 // delta @f$ \Delta_1@f$
616 // sigma @f$ \sigma_1@f$
617 // sigma_n @f$ \sigma_n@f$
618 // n @f$ N@f$ in the sum above.
619 // a Array of size @f$ N-1@f$ of the weights @f$ a_i@f$ for
623 // @f$ f_N(x;\Delta,\xi,\sigma')@f$
625 Double_t result = ILandauGaus(x, delta, xi, sigma, sigmaN, 1);
626 for (Int_t i = 2; i <= n; i++)
627 result += a[i-2] * AliForwardUtil::ILandauGaus(x,delta,xi,sigma,sigmaN,i);
631 const Int_t kColors[] = { kRed+1,
645 //____________________________________________________________________
647 AliForwardUtil::MakeNLandauGaus(Double_t c,
648 Double_t delta, Double_t xi,
649 Double_t sigma, Double_t sigmaN, Int_t n,
651 Double_t xmin, Double_t xmax)
654 // Generate a TF1 object of @f$ f_N@f$
658 // delta @f$ \Delta@f$
660 // sigma @f$ \sigma_1@f$
661 // sigma_n @f$ \sigma_n@f$
662 // n @f$ N@f$ - how many particles to sum to
663 // a Array of size @f$ N-1@f$ of the weights @f$ a_i@f$ for
665 // xmin Least value of range
666 // xmax Largest value of range
669 // Newly allocated TF1 object
671 Int_t npar = AliForwardUtil::ELossFitter::kN+n;
672 TF1* landaun = new TF1(Form("nlandau%d", n), &landauGausN,xmin,xmax,npar);
673 // landaun->SetLineStyle(((n-2) % 10)+2); // start at dashed
674 landaun->SetLineColor(kColors[((n-1) % 12)]); // start at red
675 landaun->SetLineWidth(2);
676 landaun->SetNpx(500);
677 landaun->SetParNames("C","#Delta_{p}","#xi", "#sigma", "#sigma_{n}", "N");
679 // Set the initial parameters from the seed fit
680 landaun->SetParameter(AliForwardUtil::ELossFitter::kC, c);
681 landaun->SetParameter(AliForwardUtil::ELossFitter::kDelta, delta);
682 landaun->SetParameter(AliForwardUtil::ELossFitter::kXi, xi);
683 landaun->SetParameter(AliForwardUtil::ELossFitter::kSigma, sigma);
684 landaun->SetParameter(AliForwardUtil::ELossFitter::kSigmaN, sigmaN);
685 landaun->FixParameter(AliForwardUtil::ELossFitter::kN, n);
687 // Set the range and name of the scale parameters
688 for (UShort_t i = 2; i <= n; i++) {// Take parameters from last fit
689 landaun->SetParameter(AliForwardUtil::ELossFitter::kA+i-2, a[i-2]);
690 landaun->SetParName(AliForwardUtil::ELossFitter::kA+i-2, Form("a_{%d}", i));
694 //____________________________________________________________________
696 AliForwardUtil::MakeILandauGaus(Double_t c,
697 Double_t delta, Double_t xi,
698 Double_t sigma, Double_t sigmaN, Int_t i,
699 Double_t xmin, Double_t xmax)
702 // Generate a TF1 object of @f$ f_I@f$
706 // delta @f$ \Delta@f$
708 // sigma @f$ \sigma_1@f$
709 // sigma_n @f$ \sigma_n@f$
710 // i @f$ i@f$ - the number of particles
711 // xmin Least value of range
712 // xmax Largest value of range
715 // Newly allocated TF1 object
717 Int_t npar = AliForwardUtil::ELossFitter::kN+1;
718 TF1* landaui = new TF1(Form("ilandau%d", i), &landauGausI,xmin,xmax,npar);
719 // landaui->SetLineStyle(((i-2) % 10)+2); // start at dashed
720 landaui->SetLineColor(kColors[((i-1) % 12)]); // start at red
721 landaui->SetLineWidth(1);
722 landaui->SetNpx(500);
723 landaui->SetParNames("C","#Delta_{p}","#xi", "#sigma", "#sigma_{n}", "i");
725 // Set the initial parameters from the seed fit
726 landaui->SetParameter(AliForwardUtil::ELossFitter::kC, c);
727 landaui->SetParameter(AliForwardUtil::ELossFitter::kDelta, delta);
728 landaui->SetParameter(AliForwardUtil::ELossFitter::kXi, xi);
729 landaui->SetParameter(AliForwardUtil::ELossFitter::kSigma, sigma);
730 landaui->SetParameter(AliForwardUtil::ELossFitter::kSigmaN, sigmaN);
731 landaui->FixParameter(AliForwardUtil::ELossFitter::kN, i);
736 //====================================================================
737 AliForwardUtil::ELossFitter::ELossFitter(Double_t lowCut,
740 : fLowCut(lowCut), fMaxRange(maxRange), fMinusBins(minusBins),
741 fFitResults(0), fFunctions(0)
747 // lowCut Lower cut of spectrum - data below this cuts is ignored
748 // maxRange Maximum range to fit to
749 // minusBins The number of bins below maximum to use
751 fFitResults.SetOwner();
752 fFunctions.SetOwner();
754 //____________________________________________________________________
755 AliForwardUtil::ELossFitter::~ELossFitter()
761 fFitResults.Delete();
764 //____________________________________________________________________
766 AliForwardUtil::ELossFitter::Clear()
769 // Clear internal arrays
775 //____________________________________________________________________
777 AliForwardUtil::ELossFitter::Fit1Particle(TH1* dist, Double_t sigman)
780 // Fit a 1-particle signal to the passed energy loss distribution
782 // Note that this function clears the internal arrays first
785 // dist Data to fit the function to
786 // sigman If larger than zero, the initial guess of the
787 // detector induced noise. If zero or less, then this
788 // parameter is ignored in the fit (fixed at 0)
791 // The function fitted to the data
797 // Find the fit range
798 dist->GetXaxis()->SetRangeUser(fLowCut, fMaxRange);
800 // Get the bin with maximum
801 Int_t maxBin = dist->GetMaximumBin();
802 Double_t maxE = dist->GetBinLowEdge(maxBin);
805 dist->GetXaxis()->SetRangeUser(fLowCut, maxE);
806 Int_t minBin = maxBin - fMinusBins; // dist->GetMinimumBin();
807 Double_t minE = TMath::Max(dist->GetBinCenter(minBin),fLowCut);
808 Double_t maxEE = dist->GetBinCenter(maxBin+2*fMinusBins);
811 dist->GetXaxis()->SetRangeUser(0, fMaxRange);
813 // Define the function to fit
814 TF1* landau1 = new TF1("landau1", landauGaus1, minE,maxEE,kSigmaN+1);
816 // Set initial guesses, parameter names, and limits
817 landau1->SetParameters(1,0.5,0.07,0.1,sigman);
818 landau1->SetParNames("C","#Delta_{p}","#xi", "#sigma", "#sigma_{n}");
819 landau1->SetNpx(500);
820 landau1->SetParLimits(kDelta, minE, fMaxRange);
821 landau1->SetParLimits(kXi, 0.00, fMaxRange);
822 landau1->SetParLimits(kSigma, 0.01, 0.1);
823 if (sigman <= 0) landau1->FixParameter(kSigmaN, 0);
824 else landau1->SetParLimits(kSigmaN, 0, fMaxRange);
826 // Do the fit, getting the result object
827 TFitResultPtr r = dist->Fit(landau1, "RNQS", "", minE, maxEE);
828 landau1->SetRange(minE, fMaxRange);
829 fFitResults.AddAtAndExpand(new TFitResult(*r), 0);
830 fFunctions.AddAtAndExpand(landau1, 0);
834 //____________________________________________________________________
836 AliForwardUtil::ELossFitter::FitNParticle(TH1* dist, UShort_t n,
840 // Fit a N-particle signal to the passed energy loss distribution
842 // If there's no 1-particle fit present, it does that first
845 // dist Data to fit the function to
846 // n Number of particle signals to fit
847 // sigman If larger than zero, the initial guess of the
848 // detector induced noise. If zero or less, then this
849 // parameter is ignored in the fit (fixed at 0)
852 // The function fitted to the data
855 // Get the seed fit result
856 TFitResult* r = static_cast<TFitResult*>(fFitResults.At(0));
857 TF1* f = static_cast<TF1*>(fFunctions.At(0));
859 f = Fit1Particle(dist, sigman);
860 r = static_cast<TFitResult*>(fFitResults.At(0));
862 ::Warning("FitNLandau", "No first shot at landau fit");
867 // Get some parameters from seed fit
868 Double_t delta1 = r->Parameter(kDelta);
869 Double_t xi1 = r->Parameter(kXi);
870 Double_t maxEi = n * (delta1 + xi1 * TMath::Log(n)) + 2 * n * xi1;
871 Double_t minE = f->GetXmin();
875 for (UShort_t i = 2; i <= n; i++)
876 a.fArray[i-2] = (n == 2 ? 0.05 : 0.000001);
877 // Make the fit function
878 TF1* landaun = MakeNLandauGaus(r->Parameter(kC),
879 r->Parameter(kDelta),
881 r->Parameter(kSigma),
882 r->Parameter(kSigmaN),
883 n,a.fArray,minE,maxEi);
884 landaun->SetParLimits(kDelta, minE, fMaxRange); // Delta
885 landaun->SetParLimits(kXi, 0.00, fMaxRange); // xi
886 landaun->SetParLimits(kSigma, 0.01, 1); // sigma
887 // Check if we're using the noise sigma
888 if (sigman <= 0) landaun->FixParameter(kSigmaN, 0);
889 else landaun->SetParLimits(kSigmaN, 0, fMaxRange);
891 // Set the range and name of the scale parameters
892 for (UShort_t i = 2; i <= n; i++) {// Take parameters from last fit
893 landaun->SetParLimits(kA+i-2, 0,1);
897 TFitResultPtr tr = dist->Fit(landaun, "RSQN", "", minE, maxEi);
899 landaun->SetRange(minE, fMaxRange);
900 fFitResults.AddAtAndExpand(new TFitResult(*tr), n-1);
901 fFunctions.AddAtAndExpand(landaun, n-1);
906 //====================================================================
907 AliForwardUtil::Histos::~Histos()
912 if (fFMD1i) delete fFMD1i;
913 if (fFMD2i) delete fFMD2i;
914 if (fFMD2o) delete fFMD2o;
915 if (fFMD3i) delete fFMD3i;
916 if (fFMD3o) delete fFMD3o;
919 //____________________________________________________________________
921 AliForwardUtil::Histos::Make(UShort_t d, Char_t r,
922 const TAxis& etaAxis) const
930 // etaAxis Eta axis to use
933 // Newly allocated histogram
935 Int_t ns = (r == 'I' || r == 'i') ? 20 : 40;
936 TH2D* hist = new TH2D(Form("FMD%d%c_cache", d, r),
937 Form("FMD%d%c cache", d, r),
938 etaAxis.GetNbins(), etaAxis.GetXmin(),
939 etaAxis.GetXmax(), ns, 0, 2*TMath::Pi());
940 hist->SetXTitle("#eta");
941 hist->SetYTitle("#phi [radians]");
942 hist->SetZTitle("d^{2}N_{ch}/d#etad#phi");
944 hist->SetDirectory(0);
948 //____________________________________________________________________
950 AliForwardUtil::Histos::Init(const TAxis& etaAxis)
953 // Initialize the object
956 // etaAxis Eta axis to use
958 fFMD1i = Make(1, 'I', etaAxis);
959 fFMD2i = Make(2, 'I', etaAxis);
960 fFMD2o = Make(2, 'O', etaAxis);
961 fFMD3i = Make(3, 'I', etaAxis);
962 fFMD3o = Make(3, 'O', etaAxis);
964 //____________________________________________________________________
966 AliForwardUtil::Histos::Clear(Option_t* option)
974 if (fFMD1i) fFMD1i->Reset(option);
975 if (fFMD2i) fFMD2i->Reset(option);
976 if (fFMD2o) fFMD2o->Reset(option);
977 if (fFMD3i) fFMD3i->Reset(option);
978 if (fFMD3o) fFMD3o->Reset(option);
981 //____________________________________________________________________
983 AliForwardUtil::Histos::Get(UShort_t d, Char_t r) const
986 // Get the histogram for a particular detector,ring
993 // Histogram for detector,ring or nul
996 case 1: return fFMD1i;
997 case 2: return (r == 'I' || r == 'i' ? fFMD2i : fFMD2o);
998 case 3: return (r == 'I' || r == 'i' ? fFMD3i : fFMD3o);
1002 //====================================================================
1004 AliForwardUtil::RingHistos::DefineOutputList(TList* d) const
1007 // Define the outout list in @a d
1010 // d Where to put the output list
1013 // Newly allocated TList object or null
1016 TList* list = new TList;
1018 list->SetName(fName.Data());
1022 //____________________________________________________________________
1024 AliForwardUtil::RingHistos::GetOutputList(const TList* d) const
1027 // Get our output list from the container @a d
1030 // d where to get the output list from
1033 // The found TList or null
1036 TList* list = static_cast<TList*>(d->FindObject(fName.Data()));
1040 //____________________________________________________________________
1042 AliForwardUtil::RingHistos::GetOutputHist(const TList* d, const char* name) const
1045 // Find a specific histogram in the source list @a d
1048 // d (top)-container
1049 // name Name of histogram
1052 // Found histogram or null
1054 return static_cast<TH1*>(d->FindObject(name));
1057 //====================================================================
1058 AliForwardUtil::DebugGuard::DebugGuard(Int_t lvl, Int_t msgLvl,
1059 const char* format, ...)
1062 if (lvl < msgLvl) return;
1064 va_start(ap, format);
1065 Format(fMsg, format, ap);
1069 //____________________________________________________________________
1070 AliForwardUtil::DebugGuard::~DebugGuard()
1072 if (fMsg.IsNull()) return;
1075 //____________________________________________________________________
1077 AliForwardUtil::DebugGuard::Message(Int_t lvl, Int_t msgLvl,
1078 const char* format, ...)
1080 if (lvl < msgLvl) return;
1083 va_start(ap, format);
1084 Format(msg, format, ap);
1089 //____________________________________________________________________
1091 AliForwardUtil::DebugGuard::Format(TString& out, const char* format, va_list ap)
1093 static char buf[512];
1094 Int_t n = gROOT->GetDirLevel() + 2;
1095 for (Int_t i = 0; i < n; i++) buf[i] = ' ';
1096 vsnprintf(&(buf[n]), 511-n, format, ap);
1100 //____________________________________________________________________
1102 AliForwardUtil::DebugGuard::Output(int in, TString& msg)
1104 msg[0] = (in > 0 ? '>' : in < 0 ? '<' : '=');
1105 AliLog::Message(AliLog::kInfo, msg, 0, 0, "PWGLF/forward", 0, 0);
1106 if (in > 0) gROOT->IncreaseDirLevel();
1107 else if (in < 0) gROOT->DecreaseDirLevel();