2 // Utilities used in the forward multiplcity analysis
5 #include "AliForwardUtil.h"
6 //#include <ARVersion.h>
7 #include <AliAnalysisManager.h>
8 #include "AliAODForwardMult.h"
10 #include <AliInputEventHandler.h>
11 #include <AliAODInputHandler.h>
12 #include <AliAODHandler.h>
13 #include <AliAODEvent.h>
14 #include <AliESDEvent.h>
15 #include <AliAnalysisTaskSE.h>
16 #include <AliPhysicsSelection.h>
17 #include <AliTriggerAnalysis.h>
18 #include <AliMultiplicity.h>
19 #include <TParameter.h>
23 #include <TFitResult.h>
27 #define FIT_OPTIONS "RNQS"
29 //====================================================================
30 ULong_t AliForwardUtil::AliROOTRevision()
32 #ifdef ALIROOT_SVN_REVISION
33 return ALIROOT_SVN_REVISION;
38 //____________________________________________________________________
39 ULong_t AliForwardUtil::AliROOTBranch()
41 #ifdef ALIROOT_SVN_BRANCH
42 static ULong_t ret = 0;
43 if (ret != 0) return ret;
45 TString str(ALIROOT_SVN_BRANCH);
46 if (str[0] == 'v') str.Remove(0,1);
47 if (str.EqualTo("trunk")) return ret = 0xFFFFFFFF;
49 TObjArray* tokens = str.Tokenize("-");
50 TObjString* pMajor = static_cast<TObjString*>(tokens->At(0));
51 TObjString* pMinor = static_cast<TObjString*>(tokens->At(1));
52 TObjString* pRelea = static_cast<TObjString*>(tokens->At(2));
53 TObjString* pAn = (tokens->GetEntries() > 3 ?
54 static_cast<TObjString*>(tokens->At(3)) : 0);
55 TString sMajor = pMajor->String().Strip(TString::kLeading, '0');
56 TString sMinor = pMinor->String().Strip(TString::kLeading, '0');
57 TString sRelea = pRelea->String().Strip(TString::kLeading, '0');
59 ret = (((sMajor.Atoi() & 0xFF) << 12) |
60 ((sMinor.Atoi() & 0xFF) << 8) |
61 ((sRelea.Atoi() & 0xFF) << 4) |
70 //====================================================================
72 AliForwardUtil::ParseCollisionSystem(const char* sys)
75 // Parse a collision system spec given in a string. Known values are
77 // - "ppb", "p-pb", "pa", "p-a" which returns kPPb
78 // - "pp", "p-p" which returns kPP
79 // - "PbPb", "Pb-Pb", "A-A", which returns kPbPb
80 // - Everything else gives kUnknown
83 // sys Collision system spec
86 // Collision system id
90 // we do pA first to avoid pp catch on ppb string (AH)
91 if (s.Contains("p-pb") || s.Contains("ppb")) return AliForwardUtil::kPPb;
92 if (s.Contains("p-a") || s.Contains("pa")) return AliForwardUtil::kPPb;
93 if (s.Contains("a-p") || s.Contains("ap")) return AliForwardUtil::kPPb;
94 if (s.Contains("p-p") || s.Contains("pp")) return AliForwardUtil::kPP;
95 if (s.Contains("pb-pb") || s.Contains("pbpb")) return AliForwardUtil::kPbPb;
96 if (s.Contains("a-a") || s.Contains("aa")) return AliForwardUtil::kPbPb;
97 return AliForwardUtil::kUnknown;
99 //____________________________________________________________________
101 AliForwardUtil::CollisionSystemString(UShort_t sys)
104 // Get a string representation of the collision system
107 // sys Collision system
110 // - anything else gives "unknown"
113 // String representation of the collision system
116 case AliForwardUtil::kPP: return "pp";
117 case AliForwardUtil::kPbPb: return "PbPb";
118 case AliForwardUtil::kPPb: return "pPb";
122 //____________________________________________________________________
124 AliForwardUtil::BeamRapidity(Float_t beam, UShort_t z, UShort_t a)
126 const Double_t pMass = 9.38271999999999995e-01;
127 const Double_t nMass = 9.39564999999999984e-01;
128 Double_t beamE = z * beam / 2;
129 Double_t beamM = z * pMass + (a - z) * nMass;
130 Double_t beamP = TMath::Sqrt(beamE * beamE - beamM * beamM);
131 Double_t beamY = .5* TMath::Log((beamE+beamP) / (beamE-beamP));
134 //____________________________________________________________________
136 AliForwardUtil::CenterOfMassEnergy(Float_t beam,
142 // Calculate the center of mass energy given target/projectile
143 // mass and charge numbers
146 return TMath::Sqrt(Float_t(z1*z2)/a1/a2) * beam;
148 //____________________________________________________________________
150 AliForwardUtil::CenterOfMassRapidity(UShort_t z1,
155 // Calculate the center of mass rapidity (shift) given target/projectile
156 // mass and charge numbers
159 if (z2 == z1 && a2 == a1) return 0;
160 return .5 * TMath::Log(Float_t(z1*a2)/z2/a1);
164 UShort_t CheckSNN(Float_t energy)
166 if (TMath::Abs(energy - 900.) < 10) return 900;
167 if (TMath::Abs(energy - 2400.) < 10) return 2400;
168 if (TMath::Abs(energy - 2760.) < 20) return 2760;
169 if (TMath::Abs(energy - 4400.) < 10) return 4400;
170 if (TMath::Abs(energy - 5022.) < 10) return 5023;
171 if (TMath::Abs(energy - 5500.) < 40) return 5500;
172 if (TMath::Abs(energy - 7000.) < 10) return 7000;
173 if (TMath::Abs(energy - 8000.) < 10) return 8000;
174 if (TMath::Abs(energy - 10000.) < 10) return 10000;
175 if (TMath::Abs(energy - 14000.) < 10) return 14000;
179 //____________________________________________________________________
181 AliForwardUtil::ParseCenterOfMassEnergy(UShort_t sys, Float_t beam)
184 // Parse the center of mass energy given as a float and return known
185 // values as a unsigned integer
188 // sys Collision system (needed for AA)
189 // beam Center of mass energy * total charge
192 // Center of mass energy per nucleon
194 Float_t energy = beam;
195 // Below no longer needed apparently
196 // if (sys == AliForwardUtil::kPbPb) energy = energy / 208 * 82;
197 if (sys == AliForwardUtil::kPPb)
198 energy = CenterOfMassEnergy(beam, 82, 208, 1, 1);
199 else if (sys == AliForwardUtil::kPbPb)
200 energy = CenterOfMassEnergy(beam, 82, 208, 82, 208);
201 UShort_t ret = CheckSNN(energy);
202 if (ret > 1) return ret;
203 if (sys == AliForwardUtil::kPbPb || sys == AliForwardUtil::kPPb) {
204 ret = CheckSNN(beam);
208 //____________________________________________________________________
210 AliForwardUtil::CenterOfMassEnergyString(UShort_t cms)
213 // Get a string representation of the center of mass energy per nuclean
216 // cms Center of mass energy per nucleon
219 // String representation of the center of mass energy per nuclean
221 return Form("%04dGeV", cms);
223 //____________________________________________________________________
225 AliForwardUtil::ParseMagneticField(Float_t v)
228 // Parse the magnetic field (in kG) as given by a floating point number
231 // field Magnetic field in kG
234 // Short integer value of magnetic field in kG
236 if (TMath::Abs(v - 5.) < 1 ) return +5;
237 if (TMath::Abs(v + 5.) < 1 ) return -5;
238 if (TMath::Abs(v) < 1) return 0;
241 //____________________________________________________________________
243 AliForwardUtil::MagneticFieldString(Short_t f)
246 // Get a string representation of the magnetic field
249 // field Magnetic field in kG
252 // String representation of the magnetic field
254 return Form("%01dkG", f);
256 //_____________________________________________________________________
257 AliAODEvent* AliForwardUtil::GetAODEvent(AliAnalysisTaskSE* task)
259 // Check if AOD is the output event
260 if (!task) ::Fatal("GetAODEvent", "Null task given, cannot do that");
262 AliAODEvent* ret = task->AODEvent();
265 // Check if AOD is the input event
266 ret = dynamic_cast<AliAODEvent*>(task->InputEvent());
267 if (!ret) ::Warning("GetAODEvent", "No AOD event found");
271 //_____________________________________________________________________
272 UShort_t AliForwardUtil::CheckForAOD()
274 AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
275 if (dynamic_cast<AliAODInputHandler*>(am->GetInputEventHandler())) {
276 ::Info("CheckForAOD", "Found AOD Input handler");
279 if (dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler())) {
280 ::Info("CheckForAOD", "Found AOD Output handler");
284 ::Warning("CheckForAOD",
285 "Neither and input nor output AOD handler is specified");
288 //_____________________________________________________________________
289 Bool_t AliForwardUtil::CheckForTask(const char* clsOrName, Bool_t cls)
291 AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
293 AliAnalysisTask* t = am->GetTask(clsOrName);
295 ::Warning("CheckForTask", "Task %s not found in manager", clsOrName);
298 ::Info("CheckForTask", "Found task %s", clsOrName);
301 TClass* dep = gROOT->GetClass(clsOrName);
303 ::Warning("CheckForTask", "Unknown class %s for needed task", clsOrName);
306 TIter next(am->GetTasks());
308 while ((o = next())) {
309 if (o->IsA()->InheritsFrom(dep)) {
310 ::Info("CheckForTask", "Found task of class %s: %s",
311 clsOrName, o->GetName());
315 ::Warning("CheckForTask", "No task of class %s was found", clsOrName);
319 //_____________________________________________________________________
320 TObject* AliForwardUtil::MakeParameter(const Char_t* name, UShort_t value)
322 TParameter<int>* ret = new TParameter<int>(name, value);
323 ret->SetMergeMode('f');
324 ret->SetUniqueID(value);
327 //_____________________________________________________________________
328 TObject* AliForwardUtil::MakeParameter(const Char_t* name, Int_t value)
330 TParameter<int>* ret = new TParameter<int>(name, value);
331 ret->SetMergeMode('f');
332 ret->SetUniqueID(value);
335 //_____________________________________________________________________
336 TObject* AliForwardUtil::MakeParameter(const Char_t* name, ULong_t value)
338 TParameter<Long_t>* ret = new TParameter<Long_t>(name, value);
339 ret->SetMergeMode('f');
340 ret->SetUniqueID(value);
343 //_____________________________________________________________________
344 TObject* AliForwardUtil::MakeParameter(const Char_t* name, Double_t value)
346 TParameter<double>* ret = new TParameter<double>(name, value);
347 // Float_t v = value;
348 // UInt_t* tmp = reinterpret_cast<UInt_t*>(&v);
349 ret->SetMergeMode('f');
350 // ret->SetUniqueID(*tmp);
353 //_____________________________________________________________________
354 TObject* AliForwardUtil::MakeParameter(const Char_t* name, Bool_t value)
356 TParameter<bool>* ret = new TParameter<bool>(name, value);
357 ret->SetMergeMode('f');
358 ret->SetUniqueID(value);
362 //_____________________________________________________________________
363 void AliForwardUtil::GetParameter(TObject* o, UShort_t& value)
366 TParameter<int>* p = static_cast<TParameter<int>*>(o);
367 if (p->TestBit(BIT(19)))
370 value = o->GetUniqueID();
372 //_____________________________________________________________________
373 void AliForwardUtil::GetParameter(TObject* o, Int_t& value)
376 TParameter<int>* p = static_cast<TParameter<int>*>(o);
377 if (p->TestBit(BIT(19)))
380 value = o->GetUniqueID();
382 //_____________________________________________________________________
383 void AliForwardUtil::GetParameter(TObject* o, ULong_t& value)
386 TParameter<Long_t>* p = static_cast<TParameter<Long_t>*>(o);
387 if (p->TestBit(BIT(19)))
390 value = o->GetUniqueID();
392 //_____________________________________________________________________
393 void AliForwardUtil::GetParameter(TObject* o, Double_t& value)
396 TParameter<double>* p = static_cast<TParameter<double>*>(o);
397 if (p->TestBit(BIT(19)))
398 value = p->GetVal(); // o->GetUniqueID();
400 UInt_t i = o->GetUniqueID();
401 Float_t v = *reinterpret_cast<Float_t*>(&i);
405 //_____________________________________________________________________
406 void AliForwardUtil::GetParameter(TObject* o, Bool_t& value)
409 TParameter<bool>* p = static_cast<TParameter<bool>*>(o);
410 if (p->TestBit(BIT(19)))
411 value = p->GetVal(); // o->GetUniqueID();
413 value = o->GetUniqueID();
417 //_____________________________________________________________________
418 Double_t AliForwardUtil::GetStripR(Char_t ring, UShort_t strip)
422 // Optimized version that has a cache
423 static TArrayD inner;
424 static TArrayD outer;
425 if (inner.GetSize() <= 0 || outer.GetSize() <= 0) {
426 const Double_t minR[] = { 4.5213, 15.4 };
427 const Double_t maxR[] = { 17.2, 28.0 };
428 const Int_t nStr[] = { 512, 256 };
429 for (Int_t q = 0; q < 2; q++) {
430 TArrayD& a = (q == 0 ? inner : outer);
433 for (Int_t it = 0; it < nStr[q]; it++) {
434 Double_t rad = maxR[q] - minR[q];
435 Double_t segment = rad / nStr[q];
436 Double_t r = minR[q] + segment*strip;
441 if (ring == 'I' || ring == 'i') return inner.At(strip);
442 return outer.At(strip);
445 //_____________________________________________________________________
446 Double_t AliForwardUtil::GetStripR(Char_t ring, UShort_t strip)
450 // New implementation has only one branch
451 const Double_t minR[] = { 4.5213, 15.4 };
452 const Double_t maxR[] = { 17.2, 28.0 };
453 const Int_t nStr[] = { 512, 256 };
455 Int_t q = (ring == 'I' || ring == 'i') ? 0 : 1;
456 Double_t rad = maxR[q] - minR[q];
457 Double_t segment = rad / nStr[q];
458 Double_t r = minR[q] + segment*strip;
465 //_____________________________________________________________________
466 Double_t AliForwardUtil::GetEtaFromStrip(UShort_t det, Char_t ring,
467 UShort_t sec, UShort_t strip,
470 // Calculate eta from strip with vertex (redundant with
471 // AliESDFMD::Eta but support displaced vertices)
473 // Slightly more optimized version that uses less branching
475 // Get R of the strip
476 Double_t r = GetStripR(ring, strip);
477 Int_t hybrid = sec / 2;
478 Int_t q = (ring == 'I' || ring == 'i') ? 0 : 1;
480 const Double_t zs[][2] = { { 320.266, -999999 },
482 { -63.066, -74.966 } };
483 if (det > 3 || zs[det-1][q] == -999999) return -999999;
485 Double_t z = zs[det-1][q];
486 if ((hybrid % 2) == 0) z -= .5;
488 Double_t theta = TMath::ATan2(r,z-zvtx);
489 Double_t eta = -1*TMath::Log(TMath::Tan(0.5*theta));
494 //_____________________________________________________________________
495 Double_t AliForwardUtil::GetEtaFromStrip(UShort_t det, Char_t ring,
496 UShort_t sec, UShort_t strip,
499 // Calculate eta from strip with vertex (redundant with
500 // AliESDFMD::Eta but support displaced vertices)
503 Double_t r = GetStripR(ring, strip);
504 Int_t hybrid = sec / 2;
505 Bool_t inner = (ring == 'I' || ring == 'i');
510 case 1: z = 320.266; break;
511 case 2: z = (inner ? 83.666 : 74.966); break;
512 case 3: z = (inner ? -63.066 : -74.966); break;
513 default: return -999999;
515 if ((hybrid % 2) == 0) z -= .5;
517 Double_t theta = TMath::ATan2(r,z-zvtx);
518 Double_t eta = -1*TMath::Log(TMath::Tan(0.5*theta));
524 //_____________________________________________________________________
525 Double_t AliForwardUtil::GetPhiFromStrip(Char_t ring, UShort_t strip,
527 Double_t xvtx, Double_t yvtx)
529 // Calculate eta from strip with vertex (redundant with
530 // AliESDFMD::Eta but support displaced vertices)
532 // Unknown x,y -> no change
533 if (yvtx > 999 || xvtx > 999) return phi;
536 Double_t r = GetStripR(ring, strip);
537 Double_t amp = TMath::Sqrt(xvtx*xvtx+yvtx*yvtx) / r;
538 Double_t pha = (TMath::Abs(yvtx) < 1e-12 ? 0 : TMath::ATan2(xvtx, yvtx));
539 Double_t cha = amp * TMath::Cos(phi+pha);
541 if (phi < 0) phi += TMath::TwoPi();
542 if (phi > TMath::TwoPi()) phi -= TMath::TwoPi();
546 //====================================================================
547 Int_t AliForwardUtil::fgConvolutionSteps = 100;
548 Double_t AliForwardUtil::fgConvolutionNSigma = 5;
551 // The shift of the most probable value for the ROOT function TMath::Landau
553 const Double_t mpshift = -0.22278298;
555 // Integration normalisation
557 const Double_t invSq2pi = 1. / TMath::Sqrt(2*TMath::Pi());
560 // Utility function to use in TF1 defintition
562 Double_t landauGaus1(Double_t* xp, Double_t* pp)
565 Double_t constant = pp[AliForwardUtil::ELossFitter::kC];
566 Double_t delta = pp[AliForwardUtil::ELossFitter::kDelta];
567 Double_t xi = pp[AliForwardUtil::ELossFitter::kXi];
568 Double_t sigma = pp[AliForwardUtil::ELossFitter::kSigma];
569 Double_t sigmaN = pp[AliForwardUtil::ELossFitter::kSigmaN];
571 return constant * AliForwardUtil::LandauGaus(x, delta, xi, sigma, sigmaN);
574 Double_t landauGausComposite(Double_t* xp, Double_t* pp)
577 Double_t cP = pp[AliForwardUtil::ELossFitter::kC];
578 Double_t deltaP = pp[AliForwardUtil::ELossFitter::kDelta];
579 Double_t xiP = pp[AliForwardUtil::ELossFitter::kXi];
580 Double_t sigmaP = pp[AliForwardUtil::ELossFitter::kSigma];
581 Double_t cS = pp[AliForwardUtil::ELossFitter::kSigma+1];
582 Double_t deltaS = pp[AliForwardUtil::ELossFitter::kSigma+2];
583 Double_t xiS = pp[AliForwardUtil::ELossFitter::kSigma+3];
584 Double_t sigmaS = pp[AliForwardUtil::ELossFitter::kSigma+4];
586 return (cP * AliForwardUtil::LandauGaus(x,deltaP,xiP,sigmaP,0) +
587 cS * AliForwardUtil::LandauGaus(x,deltaS,xiS,sigmaS,0));
591 // Utility function to use in TF1 defintition
593 Double_t landauGausN(Double_t* xp, Double_t* pp)
596 Double_t constant = pp[AliForwardUtil::ELossFitter::kC];
597 Double_t delta = pp[AliForwardUtil::ELossFitter::kDelta];
598 Double_t xi = pp[AliForwardUtil::ELossFitter::kXi];
599 Double_t sigma = pp[AliForwardUtil::ELossFitter::kSigma];
600 Double_t sigmaN = pp[AliForwardUtil::ELossFitter::kSigmaN];
601 Int_t n = Int_t(pp[AliForwardUtil::ELossFitter::kN]);
602 Double_t* a = &(pp[AliForwardUtil::ELossFitter::kA]);
604 return constant * AliForwardUtil::NLandauGaus(x, delta, xi, sigma, sigmaN,
608 // Utility function to use in TF1 defintition
610 Double_t landauGausI(Double_t* xp, Double_t* pp)
613 Double_t constant = pp[AliForwardUtil::ELossFitter::kC];
614 Double_t delta = pp[AliForwardUtil::ELossFitter::kDelta];
615 Double_t xi = pp[AliForwardUtil::ELossFitter::kXi];
616 Double_t sigma = pp[AliForwardUtil::ELossFitter::kSigma];
617 Double_t sigmaN = pp[AliForwardUtil::ELossFitter::kSigmaN];
618 Int_t i = Int_t(pp[AliForwardUtil::ELossFitter::kN]);
620 return constant * AliForwardUtil::ILandauGaus(x,delta,xi,sigma,sigmaN,i);
625 //____________________________________________________________________
627 AliForwardUtil::Landau(Double_t x, Double_t delta, Double_t xi)
630 // Calculate the shifted Landau
632 // f'_{L}(x;\Delta,\xi) = f_L(x;\Delta+0.22278298\xi)
635 // where @f$ f_{L}@f$ is the ROOT implementation of the Landau
636 // distribution (known to have @f$ \Delta_{p}=-0.22278298@f$ for
637 // @f$\Delta=0,\xi=1@f$.
640 // x Where to evaluate @f$ f'_{L}@f$
641 // delta Most probable value
642 // xi The 'width' of the distribution
645 // @f$ f'_{L}(x;\Delta,\xi) @f$
647 return TMath::Landau(x, delta - xi * mpshift, xi);
649 //____________________________________________________________________
651 AliForwardUtil::LandauGaus(Double_t x, Double_t delta, Double_t xi,
652 Double_t sigma, Double_t sigmaN)
655 // Calculate the value of a Landau convolved with a Gaussian
658 // f(x;\Delta,\xi,\sigma') = \frac{1}{\sigma' \sqrt{2 \pi}}
659 // \int_{-\infty}^{+\infty} d\Delta' f'_{L}(x;\Delta',\xi)
660 // \exp{-\frac{(\Delta-\Delta')^2}{2\sigma'^2}}
663 // where @f$ f'_{L}@f$ is the Landau distribution, @f$ \Delta@f$ the
664 // energy loss, @f$ \xi@f$ the width of the Landau, and
665 // @f$ \sigma'^2=\sigma^2-\sigma_n^2 @f$. Here, @f$\sigma@f$ is the
666 // variance of the Gaussian, and @f$\sigma_n@f$ is a parameter modelling
667 // noise in the detector.
669 // Note that this function uses the constants fgConvolutionSteps and
670 // fgConvolutionNSigma
673 // - <a href="http://dx.doi.org/10.1016/0168-583X(84)90472-5">Nucl.Instrum.Meth.B1:16</a>
674 // - <a href="http://dx.doi.org/10.1103/PhysRevA.28.615">Phys.Rev.A28:615</a>
675 // - <a href="http://root.cern.ch/root/htmldoc/tutorials/fit/langaus.C.html">ROOT implementation</a>
678 // x where to evaluate @f$ f@f$
679 // delta @f$ \Delta@f$ of @f$ f(x;\Delta,\xi,\sigma')@f$
680 // xi @f$ \xi@f$ of @f$ f(x;\Delta,\xi,\sigma')@f$
681 // sigma @f$ \sigma@f$ of @f$\sigma'^2=\sigma^2-\sigma_n^2 @f$
682 // sigma_n @f$ \sigma_n@f$ of @f$\sigma'^2=\sigma^2-\sigma_n^2 @f$
685 // @f$ f@f$ evaluated at @f$ x@f$.
687 Double_t deltap = delta - xi * mpshift;
688 Double_t sigma2 = sigmaN*sigmaN + sigma*sigma;
689 Double_t sigma1 = sigmaN == 0 ? sigma : TMath::Sqrt(sigma2);
690 Double_t xlow = x - fgConvolutionNSigma * sigma1;
691 Double_t xhigh = x + fgConvolutionNSigma * sigma1;
692 Double_t step = (xhigh - xlow) / fgConvolutionSteps;
695 for (Int_t i = 0; i <= fgConvolutionSteps/2; i++) {
696 Double_t x1 = xlow + (i - .5) * step;
697 Double_t x2 = xhigh - (i - .5) * step;
699 sum += TMath::Landau(x1, deltap, xi, kTRUE) * TMath::Gaus(x, x1, sigma1);
700 sum += TMath::Landau(x2, deltap, xi, kTRUE) * TMath::Gaus(x, x2, sigma1);
702 return step * sum * invSq2pi / sigma1;
705 //____________________________________________________________________
707 AliForwardUtil::ILandauGaus(Double_t x, Double_t delta, Double_t xi,
708 Double_t sigma, Double_t sigmaN, Int_t i)
713 // f_i(x;\Delta,\xi,\sigma') = f(x;\Delta_i,\xi_i,\sigma_i')
715 // corresponding to @f$ i@f$ particles i.e., with the substitutions
717 // \Delta \rightarrow \Delta_i &=& i(\Delta + \xi\log(i))
718 // \xi \rightarrow \xi_i &=& i \xi
719 // \sigma \rightarrow \sigma_i &=& \sqrt{i}\sigma
720 // \sigma'^2 \rightarrow \sigma_i'^2 &=& \sigma_n^2 + \sigma_i^2
724 // x Where to evaluate
725 // delta @f$ \Delta@f$
727 // sigma @f$ \sigma@f$
728 // sigma_n @f$ \sigma_n@f$
732 // @f$ f_i @f$ evaluated
734 Double_t deltaI = (i == 1 ? delta : i * (delta + xi * TMath::Log(i)));
735 Double_t xiI = i * xi;
736 Double_t sigmaI = (i == 1 ? sigma : TMath::Sqrt(Double_t(i))*sigma);
737 if (sigmaI < 1e-10) {
738 // Fall back to landau
739 return AliForwardUtil::Landau(x, deltaI, xiI);
741 return AliForwardUtil::LandauGaus(x, deltaI, xiI, sigmaI, sigmaN);
744 //____________________________________________________________________
746 AliForwardUtil::IdLandauGausdPar(Double_t x,
747 UShort_t par, Double_t dPar,
748 Double_t delta, Double_t xi,
749 Double_t sigma, Double_t sigmaN,
753 // Numerically evaluate
755 // \left.\frac{\partial f_i}{\partial p_i}\right|_{x}
757 // where @f$ p_i@f$ is the @f$ i^{\mbox{th}}@f$ parameter. The mapping
758 // of the parameters is given by
763 // - 3: @f$\sigma_n@f$
765 // This is the partial derivative with respect to the parameter of
766 // the response function corresponding to @f$ i@f$ particles i.e.,
767 // with the substitutions
769 // \Delta \rightarrow \Delta_i = i(\Delta + \xi\log(i))
770 // \xi \rightarrow \xi_i = i \xi
771 // \sigma \rightarrow \sigma_i = \sqrt{i}\sigma
772 // \sigma'^2 \rightarrow \sigma_i'^2 = \sigma_n^2 + \sigma_i^2
776 // x Where to evaluate
777 // ipar Parameter number
778 // dp @f$ \epsilon\delta p_i@f$ for some value of @f$\epsilon@f$
779 // delta @f$ \Delta@f$
781 // sigma @f$ \sigma@f$
782 // sigma_n @f$ \sigma_n@f$
786 // @f$ f_i@f$ evaluated
788 if (dPar == 0) return 0;
790 Double_t d2 = dPar / 2;
791 Double_t deltaI = i * (delta + xi * TMath::Log(i));
792 Double_t xiI = i * xi;
793 Double_t si = TMath::Sqrt(Double_t(i));
794 Double_t sigmaI = si*sigma;
801 y1 = ILandauGaus(x, deltaI+i*dp, xiI, sigmaI, sigmaN, i);
802 y2 = ILandauGaus(x, deltaI+i*d2, xiI, sigmaI, sigmaN, i);
803 y3 = ILandauGaus(x, deltaI-i*d2, xiI, sigmaI, sigmaN, i);
804 y4 = ILandauGaus(x, deltaI-i*dp, xiI, sigmaI, sigmaN, i);
807 y1 = ILandauGaus(x, deltaI, xiI+i*dp, sigmaI, sigmaN, i);
808 y2 = ILandauGaus(x, deltaI, xiI+i*d2, sigmaI, sigmaN, i);
809 y3 = ILandauGaus(x, deltaI, xiI-i*d2, sigmaI, sigmaN, i);
810 y4 = ILandauGaus(x, deltaI, xiI-i*dp, sigmaI, sigmaN, i);
813 y1 = ILandauGaus(x, deltaI, xiI, sigmaI+si*dp, sigmaN, i);
814 y2 = ILandauGaus(x, deltaI, xiI, sigmaI+si*d2, sigmaN, i);
815 y3 = ILandauGaus(x, deltaI, xiI, sigmaI-si*d2, sigmaN, i);
816 y4 = ILandauGaus(x, deltaI, xiI, sigmaI-si*dp, sigmaN, i);
819 y1 = ILandauGaus(x, deltaI, xiI, sigmaI, sigmaN+dp, i);
820 y2 = ILandauGaus(x, deltaI, xiI, sigmaI, sigmaN+d2, i);
821 y3 = ILandauGaus(x, deltaI, xiI, sigmaI, sigmaN-d2, i);
822 y4 = ILandauGaus(x, deltaI, xiI, sigmaI, sigmaN-dp, i);
828 Double_t d0 = y1 - y4;
829 Double_t d1 = 2 * (y2 - y3);
831 Double_t g = 1/(2*dp) * (4*d1 - d0) / 3;
836 //____________________________________________________________________
838 AliForwardUtil::NLandauGaus(Double_t x, Double_t delta, Double_t xi,
839 Double_t sigma, Double_t sigmaN, Int_t n,
845 // f_N(x;\Delta,\xi,\sigma') = \sum_{i=1}^N a_i f_i(x;\Delta,\xi,\sigma'a)
848 // where @f$ f(x;\Delta,\xi,\sigma')@f$ is the convolution of a
849 // Landau with a Gaussian (see LandauGaus). Note that
850 // @f$ a_1 = 1@f$, @f$\Delta_i = i(\Delta_1 + \xi\log(i))@f$,
851 // @f$\xi_i=i\xi_1@f$, and @f$\sigma_i'^2 = \sigma_n^2 + i\sigma_1^2@f$.
854 // - <a href="http://dx.doi.org/10.1016/0168-583X(84)90472-5">Nucl.Instrum.Meth.B1:16</a>
855 // - <a href="http://dx.doi.org/10.1103/PhysRevA.28.615">Phys.Rev.A28:615</a>
856 // - <a href="http://root.cern.ch/root/htmldoc/tutorials/fit/langaus.C.html">ROOT implementation</a>
859 // x Where to evaluate @f$ f_N@f$
860 // delta @f$ \Delta_1@f$
862 // sigma @f$ \sigma_1@f$
863 // sigma_n @f$ \sigma_n@f$
864 // n @f$ N@f$ in the sum above.
865 // a Array of size @f$ N-1@f$ of the weights @f$ a_i@f$ for
869 // @f$ f_N(x;\Delta,\xi,\sigma')@f$
871 Double_t result = ILandauGaus(x, delta, xi, sigma, sigmaN, 1);
872 for (Int_t i = 2; i <= n; i++)
873 result += a[i-2] * AliForwardUtil::ILandauGaus(x,delta,xi,sigma,sigmaN,i);
877 const Int_t kColors[] = { kRed+1,
891 //____________________________________________________________________
893 AliForwardUtil::MakeNLandauGaus(Double_t c,
894 Double_t delta, Double_t xi,
895 Double_t sigma, Double_t sigmaN, Int_t n,
897 Double_t xmin, Double_t xmax)
900 // Generate a TF1 object of @f$ f_N@f$
904 // delta @f$ \Delta@f$
906 // sigma @f$ \sigma_1@f$
907 // sigma_n @f$ \sigma_n@f$
908 // n @f$ N@f$ - how many particles to sum to
909 // a Array of size @f$ N-1@f$ of the weights @f$ a_i@f$ for
911 // xmin Least value of range
912 // xmax Largest value of range
915 // Newly allocated TF1 object
917 Int_t npar = AliForwardUtil::ELossFitter::kN+n;
918 TF1* landaun = new TF1(Form("nlandau%d", n), &landauGausN,xmin,xmax,npar);
919 // landaun->SetLineStyle(((n-2) % 10)+2); // start at dashed
920 landaun->SetLineColor(kColors[((n-1) % 12)]); // start at red
921 landaun->SetLineWidth(2);
922 landaun->SetNpx(500);
923 landaun->SetParNames("C","#Delta_{p}","#xi", "#sigma", "#sigma_{n}", "N");
925 // Set the initial parameters from the seed fit
926 landaun->SetParameter(AliForwardUtil::ELossFitter::kC, c);
927 landaun->SetParameter(AliForwardUtil::ELossFitter::kDelta, delta);
928 landaun->SetParameter(AliForwardUtil::ELossFitter::kXi, xi);
929 landaun->SetParameter(AliForwardUtil::ELossFitter::kSigma, sigma);
930 landaun->SetParameter(AliForwardUtil::ELossFitter::kSigmaN, sigmaN);
931 landaun->FixParameter(AliForwardUtil::ELossFitter::kN, n);
933 // Set the range and name of the scale parameters
934 for (UShort_t i = 2; i <= n; i++) {// Take parameters from last fit
935 landaun->SetParameter(AliForwardUtil::ELossFitter::kA+i-2, a[i-2]);
936 landaun->SetParName(AliForwardUtil::ELossFitter::kA+i-2, Form("a_{%d}", i));
940 //____________________________________________________________________
942 AliForwardUtil::MakeILandauGaus(Double_t c,
943 Double_t delta, Double_t xi,
944 Double_t sigma, Double_t sigmaN, Int_t i,
945 Double_t xmin, Double_t xmax)
948 // Generate a TF1 object of @f$ f_I@f$
952 // delta @f$ \Delta@f$
954 // sigma @f$ \sigma_1@f$
955 // sigma_n @f$ \sigma_n@f$
956 // i @f$ i@f$ - the number of particles
957 // xmin Least value of range
958 // xmax Largest value of range
961 // Newly allocated TF1 object
963 Int_t npar = AliForwardUtil::ELossFitter::kN+1;
964 TF1* landaui = new TF1(Form("ilandau%d", i), &landauGausI,xmin,xmax,npar);
965 // landaui->SetLineStyle(((i-2) % 10)+2); // start at dashed
966 landaui->SetLineColor(kColors[((i-1) % 12)]); // start at red
967 landaui->SetLineWidth(1);
968 landaui->SetNpx(500);
969 landaui->SetParNames("C","#Delta_{p}","#xi", "#sigma", "#sigma_{n}", "i");
971 // Set the initial parameters from the seed fit
972 landaui->SetParameter(AliForwardUtil::ELossFitter::kC, c);
973 landaui->SetParameter(AliForwardUtil::ELossFitter::kDelta, delta);
974 landaui->SetParameter(AliForwardUtil::ELossFitter::kXi, xi);
975 landaui->SetParameter(AliForwardUtil::ELossFitter::kSigma, sigma);
976 landaui->SetParameter(AliForwardUtil::ELossFitter::kSigmaN, sigmaN);
977 landaui->FixParameter(AliForwardUtil::ELossFitter::kN, i);
982 //====================================================================
983 AliForwardUtil::ELossFitter::ELossFitter(Double_t lowCut,
986 : fLowCut(lowCut), fMaxRange(maxRange), fMinusBins(minusBins),
987 fFitResults(0), fFunctions(0), fDebug(false)
993 // lowCut Lower cut of spectrum - data below this cuts is ignored
994 // maxRange Maximum range to fit to
995 // minusBins The number of bins below maximum to use
997 fFitResults.SetOwner();
998 fFunctions.SetOwner();
1000 //____________________________________________________________________
1001 AliForwardUtil::ELossFitter::~ELossFitter()
1007 fFitResults.Delete();
1008 fFunctions.Delete();
1010 //____________________________________________________________________
1012 AliForwardUtil::ELossFitter::Clear()
1015 // Clear internal arrays
1018 fFitResults.Clear();
1021 //____________________________________________________________________
1023 AliForwardUtil::ELossFitter::Fit1Particle(TH1* dist, Double_t sigman)
1026 // Fit a 1-particle signal to the passed energy loss distribution
1028 // Note that this function clears the internal arrays first
1031 // dist Data to fit the function to
1032 // sigman If larger than zero, the initial guess of the
1033 // detector induced noise. If zero or less, then this
1034 // parameter is ignored in the fit (fixed at 0)
1037 // The function fitted to the data
1043 // Find the fit range
1044 // Find the fit range
1045 Int_t cutBin = TMath::Max(dist->GetXaxis()->FindBin(fLowCut),3);
1046 Int_t maxBin = TMath::Min(dist->GetXaxis()->FindBin(fMaxRange),
1048 dist->GetXaxis()->SetRange(cutBin, maxBin);
1049 // dist->GetXaxis()->SetRangeUser(fLowCut, fMaxRange);
1051 // Get the bin with maximum
1052 Int_t peakBin = dist->GetMaximumBin();
1053 Double_t peakE = dist->GetBinLowEdge(peakBin);
1056 // dist->GetXaxis()->SetRangeUser(fLowCut, peakE);
1057 Int_t minBin = peakBin - fMinusBins; // dist->GetMinimumBin();
1058 Double_t minE = TMath::Max(dist->GetBinCenter(minBin),fLowCut);
1059 Double_t maxE = dist->GetBinCenter(peakBin+2*fMinusBins);
1061 Int_t minEb = dist->GetXaxis()->FindBin(minE);
1062 Int_t maxEb = dist->GetXaxis()->FindBin(maxE);
1063 Double_t intg = dist->Integral(minEb, maxEb);
1065 ::Warning("Fit1Particle",
1066 "Integral of %s between [%f,%f] [%03d,%03d] = %f < 0",
1067 dist->GetName(), minE, maxE, minEb, maxEb, intg);
1071 // Restore the range
1072 dist->GetXaxis()->SetRange(1, maxBin);
1074 // Define the function to fit
1075 TF1* landau1 = new TF1("landau1", landauGaus1, minE,maxE,kSigmaN+1);
1077 // Set initial guesses, parameter names, and limits
1078 landau1->SetParameters(1,peakE,peakE/10,peakE/5,sigman);
1079 landau1->SetParNames("C","#Delta_{p}","#xi", "#sigma", "#sigma_{n}");
1080 landau1->SetNpx(500);
1081 if (peakE >= minE && peakE <= fMaxRange) {
1082 // printf("Fit1: Set par limits on Delta: %f, %f\n", minE, fMaxRange);
1083 landau1->SetParLimits(kDelta, minE, fMaxRange);
1085 if (peakE/10 >= 0 && peakE <= 0.1) {
1086 // printf("Fit1: Set par limits on xi: %f, %f\n", 0., 0.1);
1087 landau1->SetParLimits(kXi, 0.00, 0.1); // Was fMaxRange - too wide
1089 if (peakE/5 >= 0 && peakE/5 <= 0.1) {
1090 // printf("Fit1: Set par limits on sigma: %f, %f\n", 0., 0.1);
1091 landau1->SetParLimits(kSigma, 1e-5, 0.1); // Was fMaxRange - too wide
1093 if (sigman <= 0) landau1->FixParameter(kSigmaN, 0);
1095 // printf("Fit1: Set par limits on sigmaN: %f, %f\n", 0., fMaxRange);
1096 landau1->SetParLimits(kSigmaN, 0, fMaxRange);
1099 // Do the fit, getting the result object
1101 ::Info("Fit1Particle", "Fitting in the range %f,%f", minE, maxE);
1102 TFitResultPtr r = dist->Fit(landau1, FIT_OPTIONS, "", minE, maxE);
1103 // landau1->SetRange(minE, fMaxRange);
1104 fFitResults.AddAtAndExpand(new TFitResult(*r), 0);
1105 fFunctions.AddAtAndExpand(landau1, 0);
1109 //____________________________________________________________________
1111 AliForwardUtil::ELossFitter::FitNParticle(TH1* dist, UShort_t n,
1115 // Fit a N-particle signal to the passed energy loss distribution
1117 // If there's no 1-particle fit present, it does that first
1120 // dist Data to fit the function to
1121 // n Number of particle signals to fit
1122 // sigman If larger than zero, the initial guess of the
1123 // detector induced noise. If zero or less, then this
1124 // parameter is ignored in the fit (fixed at 0)
1127 // The function fitted to the data
1130 // Get the seed fit result
1131 TFitResult* r = static_cast<TFitResult*>(fFitResults.At(0));
1132 TF1* f = static_cast<TF1*>(fFunctions.At(0));
1134 f = Fit1Particle(dist, sigman);
1135 r = static_cast<TFitResult*>(fFitResults.At(0));
1137 ::Warning("FitNLandau", "No first shot at landau fit");
1142 // Get some parameters from seed fit
1143 Double_t delta1 = r->Parameter(kDelta);
1144 Double_t xi1 = r->Parameter(kXi);
1145 Double_t maxEi = n * (delta1 + xi1 * TMath::Log(n)) + 2 * n * xi1;
1146 Double_t minE = f->GetXmin();
1148 Int_t minEb = dist->GetXaxis()->FindBin(minE);
1149 Int_t maxEb = dist->GetXaxis()->FindBin(maxEi);
1150 Double_t intg = dist->Integral(minEb, maxEb);
1152 ::Warning("FitNParticle",
1153 "Integral of %s between [%f,%f] [%03d,%03d] = %f < 0",
1154 dist->GetName(), minE, maxEi, minEb, maxEb, intg);
1160 for (UShort_t i = 2; i <= n; i++)
1161 a.fArray[i-2] = (n == 2 ? 0.05 : 0.000001);
1162 // Make the fit function
1163 TF1* landaun = MakeNLandauGaus(r->Parameter(kC),
1164 r->Parameter(kDelta),
1166 r->Parameter(kSigma),
1167 r->Parameter(kSigmaN),
1168 n, a.fArray, minE, maxEi);
1169 if (minE <= r->Parameter(kDelta) &&
1170 fMaxRange >= r->Parameter(kDelta)) {
1171 // Protect against warning from ParameterSettings
1172 // printf("FitN: Set par limits on Delta: %f, %f\n", minE, fMaxRange);
1173 landaun->SetParLimits(kDelta, minE, fMaxRange); // Delta
1175 if (r->Parameter(kXi) >= 0 && r->Parameter(kXi) <= 0.1) {
1176 // printf("FitN: Set par limits on xi: %f, %f\n", 0., 0.1);
1177 landaun->SetParLimits(kXi, 0.00, 0.1); // was fMaxRange - too wide
1179 if (r->Parameter(kSigma) >= 1e-5 && r->Parameter(kSigma) <= 0.1) {
1180 // printf("FitN: Set par limits on sigma: %f, %f\n", 1e-5, 0.1);
1181 landaun->SetParLimits(kSigma, 1e-5, 0.1); // was fMaxRange - too wide
1183 // Check if we're using the noise sigma
1184 if (sigman <= 0) landaun->FixParameter(kSigmaN, 0);
1186 // printf("FitN: Set par limits on sigmaN: %f, %f\n", 0., fMaxRange);
1187 landaun->SetParLimits(kSigmaN, 0, fMaxRange);
1190 // Set the range and name of the scale parameters
1191 for (UShort_t i = 2; i <= n; i++) {// Take parameters from last fit
1192 if (a[i-2] >= 0 && a[i-2] <= 1) {
1193 // printf("FitN: Set par limits on a_%d: %f, %f\n", i, 0., 1.);
1194 landaun->SetParLimits(kA+i-2, 0,1);
1200 ::Info("FitNParticle", "Fitting in the range %f,%f (%d)", minE, maxEi, n);
1201 TFitResultPtr tr = dist->Fit(landaun, FIT_OPTIONS, "", minE, maxEi);
1203 // landaun->SetRange(minE, fMaxRange);
1204 fFitResults.AddAtAndExpand(new TFitResult(*tr), n-1);
1205 fFunctions.AddAtAndExpand(landaun, n-1);
1209 //____________________________________________________________________
1211 AliForwardUtil::ELossFitter::FitComposite(TH1* dist, Double_t sigman)
1214 // Fit a composite particle signal to the passed energy loss
1218 // dist Data to fit the function to
1219 // sigman If larger than zero, the initial guess of the
1220 // detector induced noise. If zero or less, then this
1221 // parameter is ignored in the fit (fixed at 0)
1224 // The function fitted to the data
1227 // Find the fit range
1228 Int_t cutBin = TMath::Max(dist->GetXaxis()->FindBin(fLowCut),3);
1229 Int_t maxBin = TMath::Min(dist->GetXaxis()->FindBin(fMaxRange),
1231 dist->GetXaxis()->SetRange(cutBin, maxBin);
1233 // Get the bin with maximum
1234 Int_t peakBin = dist->GetMaximumBin();
1235 Double_t peakE = dist->GetBinLowEdge(peakBin);
1238 // dist->GetXaxis()->SetRangeUser(fLowCut, peakE);
1239 Int_t minBin = peakBin - fMinusBins; // dist->GetMinimumBin();
1240 Double_t minE = TMath::Max(dist->GetBinCenter(minBin),fLowCut);
1241 Double_t maxE = dist->GetBinCenter(peakBin+2*fMinusBins);
1243 // Get the range in bins and the integral of that range
1244 Int_t minEb = dist->GetXaxis()->FindBin(minE);
1245 Int_t maxEb = dist->GetXaxis()->FindBin(maxE);
1246 Double_t intg = dist->Integral(minEb, maxEb);
1248 ::Warning("Fit1Particle",
1249 "Integral of %s between [%f,%f] [%03d,%03d] = %f < 0",
1250 dist->GetName(), minE, maxE, minEb, maxEb, intg);
1254 // Restore the range
1255 dist->GetXaxis()->SetRange(1, maxBin);
1257 // Define the function to fit
1258 TF1* seed = new TF1("landauSeed", landauGaus1, minE,maxE,kSigmaN+1);
1260 // Set initial guesses, parameter names, and limits
1261 seed->SetParameters(1,peakE,peakE/10,peakE/5,sigman);
1262 seed->SetParNames("C","#Delta_{p}","#xi", "#sigma", "#sigma_{n}");
1264 seed->SetParLimits(kDelta, minE, fMaxRange);
1265 seed->SetParLimits(kXi, 0.00, 0.1); // Was fMaxRange - too wide
1266 seed->SetParLimits(kSigma, 1e-5, 0.1); // Was fMaxRange - too wide
1267 if (sigman <= 0) seed->FixParameter(kSigmaN, 0);
1268 else seed->SetParLimits(kSigmaN, 0, fMaxRange);
1270 // Do the fit, getting the result object
1272 ::Info("FitComposite", "Fitting seed in the range %f,%f", minE, maxE);
1273 /* TFitResultPtr r = */ dist->Fit(seed, FIT_OPTIONS, "", minE, maxE);
1275 maxE = dist->GetXaxis()->GetXmax();
1276 TF1* comp = new TF1("composite", landauGausComposite,
1277 minE, maxE, kSigma+1+4);
1278 comp->SetParNames("C", "#Delta_{p}", "#xi", "#sigma",
1279 "C#prime", "#Delta_{p}#prime", "#xi#prime", "#sigma#prim");
1280 comp->SetParameters(0.8 * seed->GetParameter(kC), // 0 Primary weight
1281 seed->GetParameter(kDelta), // 1 Primary Delta
1282 seed->GetParameter(kDelta)/10, // 2 primary Xi
1283 seed->GetParameter(kDelta)/5, // 3 primary sigma
1284 1.20 * seed->GetParameter(kC), // 5 Secondary weight
1285 seed->GetParameter(kDelta), // 6 secondary Delta
1286 seed->GetParameter(kXi), // 7 secondary Xi
1287 seed->GetParameter(kSigma)); // 8 secondary sigma
1289 // comp->SetParLimits(kC, minE, fMaxRange); // C
1290 comp->SetParLimits(kDelta, minE, fMaxRange); // Delta
1291 comp->SetParLimits(kXi, 0.00, fMaxRange); // Xi
1292 comp->SetParLimits(kSigma, 1e-5, fMaxRange); // Sigma
1293 // comp->SetParLimits(kSigma+1, minE, fMaxRange); // C
1294 comp->SetParLimits(kSigma+2, minE/10, fMaxRange); // Delta
1295 comp->SetParLimits(kSigma+3, 0.00, fMaxRange); // Xi
1296 comp->SetParLimits(kSigma+4, 1e-6, fMaxRange); // Sigma
1297 comp->SetLineColor(kRed+1);
1298 comp->SetLineWidth(3);
1300 // Do the fit, getting the result object
1302 ::Info("FitComposite", "Fitting composite in the range %f,%f", minE, maxE);
1303 /* TFitResultPtr r = */ dist->Fit(comp, FIT_OPTIONS, "", minE, maxE);
1306 TF1* part1 = static_cast<TF1*>(seed->Clone("part1"));
1307 part1->SetLineColor(kGreen+1);
1308 part1->SetLineWidth(4);
1309 part1->SetRange(minE, maxE);
1310 part1->SetParameters(comp->GetParameter(0), // C
1311 comp->GetParameter(1), // Delta
1312 comp->GetParameter(2), // Xi
1313 comp->GetParameter(3), // sigma
1315 part1->Save(minE,maxE,0,0,0,0);
1316 dist->GetListOfFunctions()->Add(part1);
1318 TF1* part2 = static_cast<TF1*>(seed->Clone("part2"));
1319 part2->SetLineColor(kBlue+1);
1320 part2->SetLineWidth(4);
1321 part2->SetRange(minE, maxE);
1322 part2->SetParameters(comp->GetParameter(4), // C
1323 comp->GetParameter(5), // Delta
1324 comp->GetParameter(6), // Xi
1325 comp->GetParameter(7), // sigma
1327 part2->Save(minE,maxE,0,0,0,0);
1328 dist->GetListOfFunctions()->Add(part2);
1333 //====================================================================
1334 AliForwardUtil::Histos::~Histos()
1341 //____________________________________________________________________
1343 AliForwardUtil::Histos::Delete(Option_t* opt)
1345 if (fFMD1i) delete fFMD1i;
1346 if (fFMD2i) delete fFMD2i;
1347 if (fFMD2o) delete fFMD2o;
1348 if (fFMD3i) delete fFMD3i;
1349 if (fFMD3o) delete fFMD3o;
1355 TObject::Delete(opt);
1358 //____________________________________________________________________
1360 AliForwardUtil::Histos::Make(UShort_t d, Char_t r, const TAxis& etaAxis)
1368 // etaAxis Eta axis to use
1371 // Newly allocated histogram
1373 Int_t ns = (r == 'I' || r == 'i') ? 20 : 40;
1375 if (etaAxis.GetXbins() && etaAxis.GetXbins()->GetArray())
1376 hist = new TH2D(Form("FMD%d%c_cache", d, r),
1377 Form("FMD%d%c cache", d, r),
1378 etaAxis.GetNbins(), etaAxis.GetXbins()->GetArray(),
1379 ns, 0, TMath::TwoPi());
1381 hist = new TH2D(Form("FMD%d%c_cache", d, r),
1382 Form("FMD%d%c cache", d, r),
1383 etaAxis.GetNbins(), etaAxis.GetXmin(),
1384 etaAxis.GetXmax(), ns, 0, TMath::TwoPi());
1385 hist->SetXTitle("#eta");
1386 hist->SetYTitle("#phi [radians]");
1387 hist->SetZTitle("d^{2}N_{ch}/d#etad#phi");
1389 hist->SetDirectory(0);
1393 //____________________________________________________________________
1395 AliForwardUtil::Histos::RebinEta(TH2D* hist, const TAxis& etaAxis)
1397 TAxis* xAxis = hist->GetXaxis();
1398 if (etaAxis.GetXbins() && etaAxis.GetXbins()->GetArray())
1399 xAxis->Set(etaAxis.GetNbins(), etaAxis.GetXbins()->GetArray());
1401 xAxis->Set(etaAxis.GetNbins(), etaAxis.GetXmin(), etaAxis.GetXmax());
1406 //____________________________________________________________________
1408 AliForwardUtil::Histos::Init(const TAxis& etaAxis)
1411 // Initialize the object
1414 // etaAxis Eta axis to use
1416 fFMD1i = Make(1, 'I', etaAxis);
1417 fFMD2i = Make(2, 'I', etaAxis);
1418 fFMD2o = Make(2, 'O', etaAxis);
1419 fFMD3i = Make(3, 'I', etaAxis);
1420 fFMD3o = Make(3, 'O', etaAxis);
1422 //____________________________________________________________________
1424 AliForwardUtil::Histos::ReInit(const TAxis& etaAxis)
1427 // Initialize the object
1430 // etaAxis Eta axis to use
1432 RebinEta(fFMD1i, etaAxis);
1433 RebinEta(fFMD2i, etaAxis);
1434 RebinEta(fFMD2o, etaAxis);
1435 RebinEta(fFMD3i, etaAxis);
1436 RebinEta(fFMD3o, etaAxis);
1439 //____________________________________________________________________
1441 AliForwardUtil::Histos::Clear(Option_t* option)
1449 if (fFMD1i) fFMD1i->Reset(option);
1450 if (fFMD2i) fFMD2i->Reset(option);
1451 if (fFMD2o) fFMD2o->Reset(option);
1452 if (fFMD3i) fFMD3i->Reset(option);
1453 if (fFMD3o) fFMD3o->Reset(option);
1456 //____________________________________________________________________
1458 AliForwardUtil::Histos::Get(UShort_t d, Char_t r) const
1461 // Get the histogram for a particular detector,ring
1468 // Histogram for detector,ring or nul
1471 case 1: return fFMD1i;
1472 case 2: return (r == 'I' || r == 'i' ? fFMD2i : fFMD2o);
1473 case 3: return (r == 'I' || r == 'i' ? fFMD3i : fFMD3o);
1477 //====================================================================
1479 AliForwardUtil::RingHistos::DefineOutputList(TList* d) const
1482 // Define the outout list in @a d
1485 // d Where to put the output list
1488 // Newly allocated TList object or null
1491 TList* list = new TList;
1493 list->SetName(fName.Data());
1497 //____________________________________________________________________
1499 AliForwardUtil::RingHistos::GetOutputList(const TList* d) const
1502 // Get our output list from the container @a d
1505 // d where to get the output list from
1508 // The found TList or null
1511 TList* list = static_cast<TList*>(d->FindObject(fName.Data()));
1515 //____________________________________________________________________
1517 AliForwardUtil::RingHistos::GetOutputHist(const TList* d, const char* name) const
1520 // Find a specific histogram in the source list @a d
1523 // d (top)-container
1524 // name Name of histogram
1527 // Found histogram or null
1529 return static_cast<TH1*>(d->FindObject(name));
1532 //====================================================================
1533 AliForwardUtil::DebugGuard::DebugGuard(Int_t lvl, Int_t msgLvl,
1534 const char* format, ...)
1537 if (lvl < msgLvl) return;
1539 va_start(ap, format);
1540 Format(fMsg, format, ap);
1544 //____________________________________________________________________
1545 AliForwardUtil::DebugGuard::~DebugGuard()
1547 if (fMsg.IsNull()) return;
1550 //____________________________________________________________________
1552 AliForwardUtil::DebugGuard::Message(Int_t lvl, Int_t msgLvl,
1553 const char* format, ...)
1555 if (lvl < msgLvl) return;
1558 va_start(ap, format);
1559 Format(msg, format, ap);
1564 //____________________________________________________________________
1566 AliForwardUtil::DebugGuard::Format(TString& out, const char* format, va_list ap)
1568 static char buf[512];
1569 Int_t n = gROOT->GetDirLevel() + 2;
1570 for (Int_t i = 0; i < n; i++) buf[i] = ' ';
1571 vsnprintf(&(buf[n]), 511-n, format, ap);
1575 //____________________________________________________________________
1577 AliForwardUtil::DebugGuard::Output(int in, TString& msg)
1579 msg[0] = (in > 0 ? '>' : in < 0 ? '<' : '=');
1580 AliLog::Message(AliLog::kInfo, msg, 0, 0, "PWGLF/forward", 0, 0);
1581 if (in > 0) gROOT->IncreaseDirLevel();
1582 else if (in < 0) gROOT->DecreaseDirLevel();