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 "RNS"
29 //====================================================================
30 ULong_t AliForwardUtil::AliROOTRevision()
32 #ifdef ALIROOT_SVN_REVISION
33 return ALIROOT_SVN_REVISION;
34 #elif defined(ALIROOT_REVISION)
35 static ULong_t ret = 0;
36 if (ret != 0) return ret;
38 // Select first 32bits of the 40byte long check-sum
39 TString rev(ALIROOT_REVISION, 8);
40 for (ULong_t i = 0; i < 8; i++) {
43 case '0': p = 0; break;
44 case '1': p = 1; break;
45 case '2': p = 2; break;
46 case '3': p = 3; break;
47 case '4': p = 4; break;
48 case '5': p = 5; break;
49 case '6': p = 6; break;
50 case '7': p = 7; break;
51 case '8': p = 8; break;
52 case '9': p = 9; break;
53 case 'a': case 'A': p = 10; break;
54 case 'b': case 'B': p = 11; break;
55 case 'c': case 'C': p = 12; break;
56 case 'd': case 'D': p = 13; break;
57 case 'e': case 'E': p = 14; break;
58 case 'f': case 'F': p = 15; break;
60 ret |= (p << (32-4*(i+1)));
67 //____________________________________________________________________
68 ULong_t AliForwardUtil::AliROOTBranch()
70 // Do something here when we switch to git - sigh!
71 #if !defined(ALIROOT_SVN_BRANCH) && !defined(ALIROOT_BRANCH)
74 static ULong_t ret = 0;
75 if (ret != 0) return ret;
78 #ifdef ALIROOT_SVN_BRANCH
79 str = ALIROOT_SVN_BRANCH;
81 #elif defined(ALIROOT_BRANCH)
85 if (str.IsNull()) return 0xFFFFFFFF;
86 if (str[0] == 'v') str.Remove(0,1);
87 if (str.EqualTo(top)) return ret = 0xFFFFFFFF;
89 TObjArray* tokens = str.Tokenize("-");
90 TObjString* pMajor = tokens->GetEntries()>0 ?
91 (static_cast<TObjString*>(tokens->At(0))) : 0;
92 TObjString* pMinor = tokens->GetEntries()>1 ?
93 (static_cast<TObjString*>(tokens->At(1))) : 0;
94 TObjString* pRelea = tokens->GetEntries() > 2 ?
95 static_cast<TObjString*>(tokens->At(2)) : 0;
96 TObjString* pAn = tokens->GetEntries() > 3 ?
97 static_cast<TObjString*>(tokens->At(3)) : 0;
98 TString sMajor,sMinor,sRelea;
99 if (pMajor) sMajor = pMajor->String().Strip(TString::kLeading, '0');
100 if (pMinor) sMinor = pMinor->String().Strip(TString::kLeading, '0');
101 if (pRelea) sRelea = pRelea->String().Strip(TString::kLeading, '0');
103 ret = (((sMajor.Atoi() & 0xFF) << 12) |
104 ((sMinor.Atoi() & 0xFF) << 8) |
105 ((sRelea.Atoi() & 0xFF) << 4) |
111 //====================================================================
113 AliForwardUtil::ParseCollisionSystem(const char* sys)
116 // Parse a collision system spec given in a string. Known values are
118 // - "ppb", "p-pb", "pa", "p-a" which returns kPPb
119 // - "pp", "p-p" which returns kPP
120 // - "PbPb", "Pb-Pb", "A-A", which returns kPbPb
121 // - Everything else gives kUnknown
124 // sys Collision system spec
127 // Collision system id
131 // we do pA first to avoid pp catch on ppb string (AH)
132 if (s.Contains("p-pb") || s.Contains("ppb")) return AliForwardUtil::kPPb;
133 if (s.Contains("p-a") || s.Contains("pa")) return AliForwardUtil::kPPb;
134 if (s.Contains("a-p") || s.Contains("ap")) return AliForwardUtil::kPPb;
135 if (s.Contains("p-p") || s.Contains("pp")) return AliForwardUtil::kPP;
136 if (s.Contains("pb-pb") || s.Contains("pbpb")) return AliForwardUtil::kPbPb;
137 if (s.Contains("a-a") || s.Contains("aa")) return AliForwardUtil::kPbPb;
138 return AliForwardUtil::kUnknown;
140 //____________________________________________________________________
142 AliForwardUtil::CollisionSystemString(UShort_t sys)
145 // Get a string representation of the collision system
148 // sys Collision system
151 // - anything else gives "unknown"
154 // String representation of the collision system
157 case AliForwardUtil::kPP: return "pp";
158 case AliForwardUtil::kPbPb: return "PbPb";
159 case AliForwardUtil::kPPb: return "pPb";
163 //____________________________________________________________________
165 AliForwardUtil::BeamRapidity(Float_t beam, UShort_t z, UShort_t a)
167 const Double_t pMass = 9.38271999999999995e-01;
168 const Double_t nMass = 9.39564999999999984e-01;
169 Double_t beamE = z * beam / 2;
170 Double_t beamM = z * pMass + (a - z) * nMass;
171 Double_t beamP = TMath::Sqrt(beamE * beamE - beamM * beamM);
172 Double_t beamY = .5* TMath::Log((beamE+beamP) / (beamE-beamP));
175 //____________________________________________________________________
177 AliForwardUtil::CenterOfMassEnergy(Float_t beam,
183 // Calculate the center of mass energy given target/projectile
184 // mass and charge numbers
187 return TMath::Sqrt(Float_t(z1*z2)/a1/a2) * beam;
189 //____________________________________________________________________
191 AliForwardUtil::CenterOfMassRapidity(UShort_t z1,
196 // Calculate the center of mass rapidity (shift) given target/projectile
197 // mass and charge numbers
200 if (z2 == z1 && a2 == a1) return 0;
201 return .5 * TMath::Log(Float_t(z1*a2)/z2/a1);
205 UShort_t CheckSNN(Float_t energy)
207 if (TMath::Abs(energy - 900.) < 10) return 900;
208 if (TMath::Abs(energy - 2400.) < 10) return 2400;
209 if (TMath::Abs(energy - 2760.) < 20) return 2760;
210 if (TMath::Abs(energy - 4400.) < 10) return 4400;
211 if (TMath::Abs(energy - 5022.) < 10) return 5023;
212 if (TMath::Abs(energy - 5500.) < 40) return 5500;
213 if (TMath::Abs(energy - 7000.) < 10) return 7000;
214 if (TMath::Abs(energy - 8000.) < 10) return 8000;
215 if (TMath::Abs(energy - 10000.) < 10) return 10000;
216 if (TMath::Abs(energy - 14000.) < 10) return 14000;
220 //____________________________________________________________________
222 AliForwardUtil::ParseCenterOfMassEnergy(UShort_t sys, Float_t beam)
225 // Parse the center of mass energy given as a float and return known
226 // values as a unsigned integer
229 // sys Collision system (needed for AA)
230 // beam Center of mass energy * total charge
233 // Center of mass energy per nucleon
235 Float_t energy = beam;
236 // Below no longer needed apparently
237 // if (sys == AliForwardUtil::kPbPb) energy = energy / 208 * 82;
238 if (sys == AliForwardUtil::kPPb)
239 energy = CenterOfMassEnergy(beam, 82, 208, 1, 1);
240 else if (sys == AliForwardUtil::kPbPb)
241 energy = CenterOfMassEnergy(beam, 82, 208, 82, 208);
242 UShort_t ret = CheckSNN(energy);
243 if (ret > 1) return ret;
244 if (sys == AliForwardUtil::kPbPb || sys == AliForwardUtil::kPPb) {
245 ret = CheckSNN(beam);
249 //____________________________________________________________________
251 AliForwardUtil::CenterOfMassEnergyString(UShort_t cms)
254 // Get a string representation of the center of mass energy per nuclean
257 // cms Center of mass energy per nucleon
260 // String representation of the center of mass energy per nuclean
262 return Form("%04dGeV", cms);
264 //____________________________________________________________________
266 AliForwardUtil::ParseMagneticField(Float_t v)
269 // Parse the magnetic field (in kG) as given by a floating point number
272 // field Magnetic field in kG
275 // Short integer value of magnetic field in kG
277 if (TMath::Abs(v - 5.) < 1 ) return +5;
278 if (TMath::Abs(v + 5.) < 1 ) return -5;
279 if (TMath::Abs(v) < 1) return 0;
282 //____________________________________________________________________
284 AliForwardUtil::MagneticFieldString(Short_t f)
287 // Get a string representation of the magnetic field
290 // field Magnetic field in kG
293 // String representation of the magnetic field
295 return Form("%01dkG", f);
297 //_____________________________________________________________________
298 AliAODEvent* AliForwardUtil::GetAODEvent(AliAnalysisTaskSE* task)
300 // Check if AOD is the output event
301 if (!task) ::Fatal("GetAODEvent", "Null task given, cannot do that");
303 AliAODEvent* ret = task->AODEvent();
306 // Check if AOD is the input event
307 ret = dynamic_cast<AliAODEvent*>(task->InputEvent());
308 if (!ret) ::Warning("GetAODEvent", "No AOD event found");
312 //_____________________________________________________________________
313 UShort_t AliForwardUtil::CheckForAOD()
315 AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
316 if (dynamic_cast<AliAODInputHandler*>(am->GetInputEventHandler())) {
317 // ::Info("CheckForAOD", "Found AOD Input handler");
320 if (dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler())) {
321 // ::Info("CheckForAOD", "Found AOD Output handler");
325 ::Warning("CheckForAOD",
326 "Neither and input nor output AOD handler is specified");
329 //_____________________________________________________________________
330 Bool_t AliForwardUtil::CheckForTask(const char* clsOrName, Bool_t cls)
332 AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
334 AliAnalysisTask* t = am->GetTask(clsOrName);
336 ::Warning("CheckForTask", "Task %s not found in manager", clsOrName);
339 ::Info("CheckForTask", "Found task %s", clsOrName);
342 TClass* dep = gROOT->GetClass(clsOrName);
344 ::Warning("CheckForTask", "Unknown class %s for needed task", clsOrName);
347 TIter next(am->GetTasks());
349 while ((o = next())) {
350 if (o->IsA()->InheritsFrom(dep)) {
351 ::Info("CheckForTask", "Found task of class %s: %s",
352 clsOrName, o->GetName());
356 ::Warning("CheckForTask", "No task of class %s was found", clsOrName);
360 //_____________________________________________________________________
361 TObject* AliForwardUtil::MakeParameter(const Char_t* name, UShort_t value)
363 TParameter<int>* ret = new TParameter<int>(name, value);
364 ret->SetMergeMode('f');
365 ret->SetUniqueID(value);
368 //_____________________________________________________________________
369 TObject* AliForwardUtil::MakeParameter(const Char_t* name, Int_t value)
371 TParameter<int>* ret = new TParameter<int>(name, value);
372 ret->SetMergeMode('f');
373 ret->SetUniqueID(value);
376 //_____________________________________________________________________
377 TObject* AliForwardUtil::MakeParameter(const Char_t* name, ULong_t value)
379 TParameter<Long_t>* ret = new TParameter<Long_t>(name, value);
380 ret->SetMergeMode('f');
381 ret->SetUniqueID(value);
384 //_____________________________________________________________________
385 TObject* AliForwardUtil::MakeParameter(const Char_t* name, Double_t value)
387 TParameter<double>* ret = new TParameter<double>(name, value);
388 // Float_t v = value;
389 // UInt_t* tmp = reinterpret_cast<UInt_t*>(&v);
390 ret->SetMergeMode('f');
391 // ret->SetUniqueID(*tmp);
394 //_____________________________________________________________________
395 TObject* AliForwardUtil::MakeParameter(const Char_t* name, Bool_t value)
397 TParameter<bool>* ret = new TParameter<bool>(name, value);
398 ret->SetMergeMode('f');
399 ret->SetUniqueID(value);
403 //_____________________________________________________________________
404 void AliForwardUtil::GetParameter(TObject* o, UShort_t& value)
407 TParameter<int>* p = static_cast<TParameter<int>*>(o);
408 if (p->TestBit(BIT(19)))
411 value = o->GetUniqueID();
413 //_____________________________________________________________________
414 void AliForwardUtil::GetParameter(TObject* o, Int_t& value)
417 TParameter<int>* p = static_cast<TParameter<int>*>(o);
418 if (p->TestBit(BIT(19)))
421 value = o->GetUniqueID();
423 //_____________________________________________________________________
424 void AliForwardUtil::GetParameter(TObject* o, ULong_t& value)
427 TParameter<Long_t>* p = static_cast<TParameter<Long_t>*>(o);
428 if (p->TestBit(BIT(19)))
431 value = o->GetUniqueID();
433 //_____________________________________________________________________
434 void AliForwardUtil::GetParameter(TObject* o, Double_t& value)
437 TParameter<double>* p = static_cast<TParameter<double>*>(o);
438 if (p->TestBit(BIT(19)))
439 value = p->GetVal(); // o->GetUniqueID();
441 UInt_t i = o->GetUniqueID();
442 Float_t v = *reinterpret_cast<Float_t*>(&i);
446 //_____________________________________________________________________
447 void AliForwardUtil::GetParameter(TObject* o, Bool_t& value)
450 TParameter<bool>* p = static_cast<TParameter<bool>*>(o);
451 if (p->TestBit(BIT(19)))
452 value = p->GetVal(); // o->GetUniqueID();
454 value = o->GetUniqueID();
458 //_____________________________________________________________________
459 Double_t AliForwardUtil::GetStripR(Char_t ring, UShort_t strip)
463 // Optimized version that has a cache
464 static TArrayD inner;
465 static TArrayD outer;
466 if (inner.GetSize() <= 0 || outer.GetSize() <= 0) {
467 const Double_t minR[] = { 4.5213, 15.4 };
468 const Double_t maxR[] = { 17.2, 28.0 };
469 const Int_t nStr[] = { 512, 256 };
470 for (Int_t q = 0; q < 2; q++) {
471 TArrayD& a = (q == 0 ? inner : outer);
474 for (Int_t it = 0; it < nStr[q]; it++) {
475 Double_t rad = maxR[q] - minR[q];
476 Double_t segment = rad / nStr[q];
477 Double_t r = minR[q] + segment*strip;
482 if (ring == 'I' || ring == 'i') return inner.At(strip);
483 return outer.At(strip);
486 //_____________________________________________________________________
487 Double_t AliForwardUtil::GetStripR(Char_t ring, UShort_t strip)
491 // New implementation has only one branch
492 const Double_t minR[] = { 4.5213, 15.4 };
493 const Double_t maxR[] = { 17.2, 28.0 };
494 const Int_t nStr[] = { 512, 256 };
496 Int_t q = (ring == 'I' || ring == 'i') ? 0 : 1;
497 Double_t rad = maxR[q] - minR[q];
498 Double_t segment = rad / nStr[q];
499 Double_t r = minR[q] + segment*strip;
506 //_____________________________________________________________________
507 Double_t AliForwardUtil::GetEtaFromStrip(UShort_t det, Char_t ring,
508 UShort_t sec, UShort_t strip,
511 // Calculate eta from strip with vertex (redundant with
512 // AliESDFMD::Eta but support displaced vertices)
514 // Slightly more optimized version that uses less branching
516 // Get R of the strip
517 Double_t r = GetStripR(ring, strip);
518 Int_t hybrid = sec / 2;
519 Int_t q = (ring == 'I' || ring == 'i') ? 0 : 1;
521 const Double_t zs[][2] = { { 320.266, -999999 },
523 { -63.066, -74.966 } };
524 if (det > 3 || zs[det-1][q] == -999999) return -999999;
526 Double_t z = zs[det-1][q];
527 if ((hybrid % 2) == 0) z -= .5;
529 Double_t theta = TMath::ATan2(r,z-zvtx);
530 Double_t eta = -1*TMath::Log(TMath::Tan(0.5*theta));
535 //_____________________________________________________________________
536 Double_t AliForwardUtil::GetEtaFromStrip(UShort_t det, Char_t ring,
537 UShort_t sec, UShort_t strip,
540 // Calculate eta from strip with vertex (redundant with
541 // AliESDFMD::Eta but support displaced vertices)
544 Double_t r = GetStripR(ring, strip);
545 Int_t hybrid = sec / 2;
546 Bool_t inner = (ring == 'I' || ring == 'i');
551 case 1: z = 320.266; break;
552 case 2: z = (inner ? 83.666 : 74.966); break;
553 case 3: z = (inner ? -63.066 : -74.966); break;
554 default: return -999999;
556 if ((hybrid % 2) == 0) z -= .5;
558 Double_t theta = TMath::ATan2(r,z-zvtx);
559 Double_t eta = -1*TMath::Log(TMath::Tan(0.5*theta));
565 //_____________________________________________________________________
566 Double_t AliForwardUtil::GetPhiFromStrip(Char_t ring, UShort_t strip,
568 Double_t xvtx, Double_t yvtx)
570 // Calculate eta from strip with vertex (redundant with
571 // AliESDFMD::Eta but support displaced vertices)
573 // Unknown x,y -> no change
574 if (yvtx > 999 || xvtx > 999) return phi;
577 Double_t r = GetStripR(ring, strip);
578 Double_t amp = TMath::Sqrt(xvtx*xvtx+yvtx*yvtx) / r;
579 Double_t pha = (TMath::Abs(yvtx) < 1e-12 ? 0 : TMath::ATan2(xvtx, yvtx));
580 Double_t cha = amp * TMath::Cos(phi+pha);
582 if (phi < 0) phi += TMath::TwoPi();
583 if (phi > TMath::TwoPi()) phi -= TMath::TwoPi();
586 //====================================================================
588 AliForwardUtil::MakeFullIpZAxis(Int_t nCenter)
591 MakeFullIpZAxis(nCenter, bins);
592 TAxis* a = new TAxis(bins.GetSize()-1,bins.GetArray());
596 AliForwardUtil::MakeFullIpZAxis(Int_t nCenter, TArrayD& bins)
598 // Custom vertex axis that will include satellite vertices
599 // Satellite vertices are at k*37.5 where k=-10,-9,...,9,10
600 // Nominal vertices are usually in -10 to 10 and we should have
601 // 10 bins in that range. That gives us a total of
605 // or 31 bin boundaries
606 if (nCenter % 2 == 1)
607 // Number of central bins is odd - make it even
609 const Double_t mCenter = 20;
610 const Int_t nSat = 10;
611 const Int_t nBins = 2*nSat + nCenter;
612 const Int_t mBin = nBins / 2;
613 Double_t dCenter = 2*mCenter / nCenter;
616 for (Int_t i = 1; i <= nCenter/2; i++) {
617 // Assign from the middle out
618 Double_t v = i * dCenter;
619 // Printf("Assigning +/-%7.2f to %3d/%3d", v,mBin-i,mBin+i);
623 for (Int_t i = 1; i <= nSat; i++) {
624 Double_t v = (i+.5) * 37.5;
625 Int_t o = nCenter/2+i;
626 // Printf("Assigning +/-%7.2f to %3d/%3d", v,mBin-o,mBin+o);
632 AliForwardUtil::MakeLogScale(Int_t nBins,
637 Double_t dO = Double_t(maxOrder-minOrder) / nBins;
639 for (Int_t i = 0; i <= nBins; i++) bins[i] = TMath::Power(10, i * dO);
643 AliForwardUtil::PrintTask(const TObject& o)
645 Int_t ind = gROOT->GetDirLevel();
648 std::cout << std::setfill(' ') << std::setw(ind) << " " << std::flush;
650 TString t = TString::Format("%s %s", o.GetName(), o.ClassName());
651 const Int_t maxN = 75;
652 std::cout << "--- " << t << " " << std::setfill('-')
653 << std::setw(maxN-ind-5-t.Length()) << "-" << std::endl;
656 AliForwardUtil::PrintName(const char* name)
658 Int_t ind = gROOT->GetDirLevel();
661 std::cout << std::setfill(' ') << std::setw(ind) << " " << std::flush;
663 // Now print field name
664 const Int_t maxN = 29;
665 Int_t width = maxN - ind;
667 if (n.Length() > width-1) {
668 // Truncate the string, and put in "..."
673 std::cout << std::setfill(' ') << std::left << std::setw(width)
674 << n << std::right << std::flush;
677 AliForwardUtil::PrintField(const char* name, const char* value, ...)
681 // Now format the field value
684 static char buf[512];
685 vsnprintf(buf, 511, value, ap);
689 std::cout << buf << std::endl;
692 //====================================================================
693 #if 0 // Moved to separate classes
694 Int_t AliForwardUtil::fgConvolutionSteps = 100;
695 Double_t AliForwardUtil::fgConvolutionNSigma = 5;
698 // The shift of the most probable value for the ROOT function TMath::Landau
700 const Double_t mpshift = -0.22278298;
702 // Integration normalisation
704 const Double_t invSq2pi = 1. / TMath::Sqrt(2*TMath::Pi());
707 // Utility function to use in TF1 defintition
709 Double_t landauGaus1(Double_t* xp, Double_t* pp)
712 Double_t constant = pp[AliForwardUtil::ELossFitter::kC];
713 Double_t delta = pp[AliForwardUtil::ELossFitter::kDelta];
714 Double_t xi = pp[AliForwardUtil::ELossFitter::kXi];
715 Double_t sigma = pp[AliForwardUtil::ELossFitter::kSigma];
716 Double_t sigmaN = pp[AliForwardUtil::ELossFitter::kSigmaN];
718 return constant * AliForwardUtil::LandauGaus(x, delta, xi, sigma, sigmaN);
721 Double_t landauGausComposite(Double_t* xp, Double_t* pp)
724 Double_t cP = pp[AliForwardUtil::ELossFitter::kC];
725 Double_t deltaP = pp[AliForwardUtil::ELossFitter::kDelta];
726 Double_t xiP = pp[AliForwardUtil::ELossFitter::kXi];
727 Double_t sigmaP = pp[AliForwardUtil::ELossFitter::kSigma];
728 Double_t cS = pp[AliForwardUtil::ELossFitter::kSigma+1];
729 Double_t deltaS = deltaP; // pp[AliForwardUtil::ELossFitter::kSigma+2];
730 Double_t xiS = pp[AliForwardUtil::ELossFitter::kSigma+2/*3*/];
731 Double_t sigmaS = sigmaP; // pp[AliForwardUtil::ELossFitter::kSigma+4];
733 return (cP * AliForwardUtil::LandauGaus(x,deltaP,xiP,sigmaP,0) +
734 cS * AliForwardUtil::LandauGaus(x,deltaS,xiS,sigmaS,0));
738 // Utility function to use in TF1 defintition
740 Double_t landauGausN(Double_t* xp, Double_t* pp)
743 Double_t constant = pp[AliForwardUtil::ELossFitter::kC];
744 Double_t delta = pp[AliForwardUtil::ELossFitter::kDelta];
745 Double_t xi = pp[AliForwardUtil::ELossFitter::kXi];
746 Double_t sigma = pp[AliForwardUtil::ELossFitter::kSigma];
747 Double_t sigmaN = pp[AliForwardUtil::ELossFitter::kSigmaN];
748 Int_t n = Int_t(pp[AliForwardUtil::ELossFitter::kN]);
749 Double_t* a = &(pp[AliForwardUtil::ELossFitter::kA]);
751 return constant * AliForwardUtil::NLandauGaus(x, delta, xi, sigma, sigmaN,
755 // Utility function to use in TF1 defintition
757 Double_t landauGausI(Double_t* xp, Double_t* pp)
760 Double_t constant = pp[AliForwardUtil::ELossFitter::kC];
761 Double_t delta = pp[AliForwardUtil::ELossFitter::kDelta];
762 Double_t xi = pp[AliForwardUtil::ELossFitter::kXi];
763 Double_t sigma = pp[AliForwardUtil::ELossFitter::kSigma];
764 Double_t sigmaN = pp[AliForwardUtil::ELossFitter::kSigmaN];
765 Int_t i = Int_t(pp[AliForwardUtil::ELossFitter::kN]);
767 return constant * AliForwardUtil::ILandauGaus(x,delta,xi,sigma,sigmaN,i);
772 //____________________________________________________________________
774 AliForwardUtil::Landau(Double_t x, Double_t delta, Double_t xi)
777 // Calculate the shifted Landau
779 // f'_{L}(x;\Delta,\xi) = f_L(x;\Delta+0.22278298\xi)
782 // where @f$ f_{L}@f$ is the ROOT implementation of the Landau
783 // distribution (known to have @f$ \Delta_{p}=-0.22278298@f$ for
784 // @f$\Delta=0,\xi=1@f$.
787 // x Where to evaluate @f$ f'_{L}@f$
788 // delta Most probable value
789 // xi The 'width' of the distribution
792 // @f$ f'_{L}(x;\Delta,\xi) @f$
794 Double_t deltaP = delta - xi * mpshift;
795 return TMath::Landau(x, deltaP, xi, true);
797 //____________________________________________________________________
799 AliForwardUtil::LandauGaus(Double_t x, Double_t delta, Double_t xi,
800 Double_t sigma, Double_t sigmaN)
803 // Calculate the value of a Landau convolved with a Gaussian
806 // f(x;\Delta,\xi,\sigma') = \frac{1}{\sigma' \sqrt{2 \pi}}
807 // \int_{-\infty}^{+\infty} d\Delta' f'_{L}(x;\Delta',\xi)
808 // \exp{-\frac{(\Delta-\Delta')^2}{2\sigma'^2}}
811 // where @f$ f'_{L}@f$ is the Landau distribution, @f$ \Delta@f$ the
812 // energy loss, @f$ \xi@f$ the width of the Landau, and
813 // @f$ \sigma'^2=\sigma^2-\sigma_n^2 @f$. Here, @f$\sigma@f$ is the
814 // variance of the Gaussian, and @f$\sigma_n@f$ is a parameter modelling
815 // noise in the detector.
817 // Note that this function uses the constants fgConvolutionSteps and
818 // fgConvolutionNSigma
821 // - <a href="http://dx.doi.org/10.1016/0168-583X(84)90472-5">Nucl.Instrum.Meth.B1:16</a>
822 // - <a href="http://dx.doi.org/10.1103/PhysRevA.28.615">Phys.Rev.A28:615</a>
823 // - <a href="http://root.cern.ch/root/htmldoc/tutorials/fit/langaus.C.html">ROOT implementation</a>
826 // x where to evaluate @f$ f@f$
827 // delta @f$ \Delta@f$ of @f$ f(x;\Delta,\xi,\sigma')@f$
828 // xi @f$ \xi@f$ of @f$ f(x;\Delta,\xi,\sigma')@f$
829 // sigma @f$ \sigma@f$ of @f$\sigma'^2=\sigma^2-\sigma_n^2 @f$
830 // sigma_n @f$ \sigma_n@f$ of @f$\sigma'^2=\sigma^2-\sigma_n^2 @f$
833 // @f$ f@f$ evaluated at @f$ x@f$.
835 if (xi <= 0) return 0;
837 Double_t deltaP = delta; // - sigma * sigmaShift; // + sigma * mpshift;
838 Double_t sigma2 = sigmaN*sigmaN + sigma*sigma;
839 Double_t sigma1 = sigmaN == 0 ? sigma : TMath::Sqrt(sigma2);
840 Double_t xlow = x - fgConvolutionNSigma * sigma1;
841 Double_t xhigh = x + fgConvolutionNSigma * sigma1;
842 Double_t step = (xhigh - xlow) / fgConvolutionSteps;
845 for (Int_t i = 0; i <= fgConvolutionSteps/2; i++) {
846 Double_t x1 = xlow + (i - .5) * step;
847 Double_t x2 = xhigh - (i - .5) * step;
849 //sum += TMath::Landau(x1, deltap, xi, kTRUE) * TMath::Gaus(x, x1, sigma1);
850 //sum += TMath::Landau(x2, deltap, xi, kTRUE) * TMath::Gaus(x, x2, sigma1);
851 sum += Landau(x1, deltaP, xi) * TMath::Gaus(x, x1, sigma1);
852 sum += Landau(x2, deltaP, xi) * TMath::Gaus(x, x2, sigma1);
854 return step * sum * invSq2pi / sigma1;
858 const Double_t sigmaShift = 0.36390; // TMath::Log(TMath::Sqrt(2.));
859 double deltaSigmaShift(Int_t i, Double_t sigma)
861 return 0; // - sigma * sigmaShift;
863 void getIPars(Int_t i, Double_t& delta, Double_t& xi, Double_t& sigma)
865 Double_t dsig = deltaSigmaShift(i, sigma);
868 return; // { delta = delta + xi*mpshift; return; } // Do nothing
871 delta = i * (delta + xi * TMath::Log(i)) + dsig;
873 sigma = TMath::Sqrt(Double_t(i)) * sigma;
878 //____________________________________________________________________
880 AliForwardUtil::ILandauGaus(Double_t x, Double_t delta, Double_t xi,
881 Double_t sigma, Double_t sigmaN, Int_t i)
886 // f_i(x;\Delta,\xi,\sigma') = f(x;\Delta_i,\xi_i,\sigma_i')
888 // corresponding to @f$ i@f$ particles i.e., with the substitutions
890 // \Delta \rightarrow \Delta_i &=& i(\Delta + \xi\log(i))
891 // \xi \rightarrow \xi_i &=& i \xi
892 // \sigma \rightarrow \sigma_i &=& \sqrt{i}\sigma
893 // \sigma'^2 \rightarrow \sigma_i'^2 &=& \sigma_n^2 + \sigma_i^2
897 // x Where to evaluate
898 // delta @f$ \Delta@f$
900 // sigma @f$ \sigma@f$
901 // sigma_n @f$ \sigma_n@f$
905 // @f$ f_i @f$ evaluated
907 Double_t deltaI = delta;
909 Double_t sigmaI = sigma;
910 getIPars(i, deltaI, xiI, sigmaI);
911 if (sigmaI < 1e-10) {
912 // Fall back to landau
913 return AliForwardUtil::Landau(x, deltaI, xiI);
915 return AliForwardUtil::LandauGaus(x, deltaI, xiI, sigmaI, sigmaN);
918 //____________________________________________________________________
920 AliForwardUtil::IdLandauGausdPar(Double_t x,
921 UShort_t par, Double_t dPar,
922 Double_t delta, Double_t xi,
923 Double_t sigma, Double_t sigmaN,
927 // Numerically evaluate
929 // \left.\frac{\partial f_i}{\partial p_i}\right|_{x}
931 // where @f$ p_i@f$ is the @f$ i^{\mbox{th}}@f$ parameter. The mapping
932 // of the parameters is given by
937 // - 3: @f$\sigma_n@f$
939 // This is the partial derivative with respect to the parameter of
940 // the response function corresponding to @f$ i@f$ particles i.e.,
941 // with the substitutions
943 // \Delta \rightarrow \Delta_i = i(\Delta + \xi\log(i))
944 // \xi \rightarrow \xi_i = i \xi
945 // \sigma \rightarrow \sigma_i = \sqrt{i}\sigma
946 // \sigma'^2 \rightarrow \sigma_i'^2 = \sigma_n^2 + \sigma_i^2
950 // x Where to evaluate
951 // ipar Parameter number
952 // dp @f$ \epsilon\delta p_i@f$ for some value of @f$\epsilon@f$
953 // delta @f$ \Delta@f$
955 // sigma @f$ \sigma@f$
956 // sigma_n @f$ \sigma_n@f$
960 // @f$ f_i@f$ evaluated
962 if (dPar == 0) return 0;
964 Double_t d2 = dPar / 2;
965 Double_t deltaI = i * (delta + xi * TMath::Log(i));
966 Double_t xiI = i * xi;
967 Double_t si = TMath::Sqrt(Double_t(i));
968 Double_t sigmaI = si*sigma;
975 y1 = ILandauGaus(x, deltaI+i*dp, xiI, sigmaI, sigmaN, i);
976 y2 = ILandauGaus(x, deltaI+i*d2, xiI, sigmaI, sigmaN, i);
977 y3 = ILandauGaus(x, deltaI-i*d2, xiI, sigmaI, sigmaN, i);
978 y4 = ILandauGaus(x, deltaI-i*dp, xiI, sigmaI, sigmaN, i);
981 y1 = ILandauGaus(x, deltaI, xiI+i*dp, sigmaI, sigmaN, i);
982 y2 = ILandauGaus(x, deltaI, xiI+i*d2, sigmaI, sigmaN, i);
983 y3 = ILandauGaus(x, deltaI, xiI-i*d2, sigmaI, sigmaN, i);
984 y4 = ILandauGaus(x, deltaI, xiI-i*dp, sigmaI, sigmaN, i);
987 y1 = ILandauGaus(x, deltaI, xiI, sigmaI+si*dp, sigmaN, i);
988 y2 = ILandauGaus(x, deltaI, xiI, sigmaI+si*d2, sigmaN, i);
989 y3 = ILandauGaus(x, deltaI, xiI, sigmaI-si*d2, sigmaN, i);
990 y4 = ILandauGaus(x, deltaI, xiI, sigmaI-si*dp, sigmaN, i);
993 y1 = ILandauGaus(x, deltaI, xiI, sigmaI, sigmaN+dp, i);
994 y2 = ILandauGaus(x, deltaI, xiI, sigmaI, sigmaN+d2, i);
995 y3 = ILandauGaus(x, deltaI, xiI, sigmaI, sigmaN-d2, i);
996 y4 = ILandauGaus(x, deltaI, xiI, sigmaI, sigmaN-dp, i);
1002 Double_t d0 = y1 - y4;
1003 Double_t d1 = 2 * (y2 - y3);
1005 Double_t g = 1/(2*dp) * (4*d1 - d0) / 3;
1010 //____________________________________________________________________
1012 AliForwardUtil::NLandauGaus(Double_t x, Double_t delta, Double_t xi,
1013 Double_t sigma, Double_t sigmaN, Int_t n,
1019 // f_N(x;\Delta,\xi,\sigma') = \sum_{i=1}^N a_i f_i(x;\Delta,\xi,\sigma'a)
1022 // where @f$ f(x;\Delta,\xi,\sigma')@f$ is the convolution of a
1023 // Landau with a Gaussian (see LandauGaus). Note that
1024 // @f$ a_1 = 1@f$, @f$\Delta_i = i(\Delta_1 + \xi\log(i))@f$,
1025 // @f$\xi_i=i\xi_1@f$, and @f$\sigma_i'^2 = \sigma_n^2 + i\sigma_1^2@f$.
1028 // - <a href="http://dx.doi.org/10.1016/0168-583X(84)90472-5">Nucl.Instrum.Meth.B1:16</a>
1029 // - <a href="http://dx.doi.org/10.1103/PhysRevA.28.615">Phys.Rev.A28:615</a>
1030 // - <a href="http://root.cern.ch/root/htmldoc/tutorials/fit/langaus.C.html">ROOT implementation</a>
1033 // x Where to evaluate @f$ f_N@f$
1034 // delta @f$ \Delta_1@f$
1036 // sigma @f$ \sigma_1@f$
1037 // sigma_n @f$ \sigma_n@f$
1038 // n @f$ N@f$ in the sum above.
1039 // a Array of size @f$ N-1@f$ of the weights @f$ a_i@f$ for
1043 // @f$ f_N(x;\Delta,\xi,\sigma')@f$
1045 Double_t result = ILandauGaus(x, delta, xi, sigma, sigmaN, 1);
1046 for (Int_t i = 2; i <= n; i++)
1047 result += a[i-2] * AliForwardUtil::ILandauGaus(x,delta,xi,sigma,sigmaN,i);
1051 const Int_t kColors[] = { kRed+1,
1065 //____________________________________________________________________
1067 AliForwardUtil::MakeNLandauGaus(Double_t c,
1068 Double_t delta, Double_t xi,
1069 Double_t sigma, Double_t sigmaN, Int_t n,
1071 Double_t xmin, Double_t xmax)
1074 // Generate a TF1 object of @f$ f_N@f$
1078 // delta @f$ \Delta@f$
1080 // sigma @f$ \sigma_1@f$
1081 // sigma_n @f$ \sigma_n@f$
1082 // n @f$ N@f$ - how many particles to sum to
1083 // a Array of size @f$ N-1@f$ of the weights @f$ a_i@f$ for
1085 // xmin Least value of range
1086 // xmax Largest value of range
1089 // Newly allocated TF1 object
1091 Int_t npar = AliForwardUtil::ELossFitter::kN+n;
1092 TF1* landaun = new TF1(Form("nlandau%d", n), &landauGausN,xmin,xmax,npar);
1093 // landaun->SetLineStyle(((n-2) % 10)+2); // start at dashed
1094 landaun->SetLineColor(kColors[((n-1) % 12)]); // start at red
1095 landaun->SetLineWidth(2);
1096 landaun->SetNpx(500);
1097 landaun->SetParNames("C","#Delta_{p}","#xi", "#sigma", "#sigma_{n}", "N");
1099 // Set the initial parameters from the seed fit
1100 landaun->SetParameter(AliForwardUtil::ELossFitter::kC, c);
1101 landaun->SetParameter(AliForwardUtil::ELossFitter::kDelta, delta);
1102 landaun->SetParameter(AliForwardUtil::ELossFitter::kXi, xi);
1103 landaun->SetParameter(AliForwardUtil::ELossFitter::kSigma, sigma);
1104 landaun->SetParameter(AliForwardUtil::ELossFitter::kSigmaN, sigmaN);
1105 landaun->FixParameter(AliForwardUtil::ELossFitter::kN, n);
1107 // Set the range and name of the scale parameters
1108 for (UShort_t i = 2; i <= n; i++) {// Take parameters from last fit
1109 landaun->SetParameter(AliForwardUtil::ELossFitter::kA+i-2, a[i-2]);
1110 landaun->SetParName(AliForwardUtil::ELossFitter::kA+i-2, Form("a_{%d}", i));
1114 //____________________________________________________________________
1116 AliForwardUtil::MakeILandauGaus(Double_t c,
1117 Double_t delta, Double_t xi,
1118 Double_t sigma, Double_t sigmaN, Int_t i,
1119 Double_t xmin, Double_t xmax)
1122 // Generate a TF1 object of @f$ f_I@f$
1126 // delta @f$ \Delta@f$
1128 // sigma @f$ \sigma_1@f$
1129 // sigma_n @f$ \sigma_n@f$
1130 // i @f$ i@f$ - the number of particles
1131 // xmin Least value of range
1132 // xmax Largest value of range
1135 // Newly allocated TF1 object
1137 Int_t npar = AliForwardUtil::ELossFitter::kN+1;
1138 TF1* landaui = new TF1(Form("ilandau%d", i), &landauGausI,xmin,xmax,npar);
1139 // landaui->SetLineStyle(((i-2) % 10)+2); // start at dashed
1140 landaui->SetLineColor(kColors[((i-1) % 12)]); // start at red
1141 landaui->SetLineWidth(1);
1142 landaui->SetNpx(500);
1143 landaui->SetParNames("C","#Delta_{p}","#xi", "#sigma", "#sigma_{n}", "i");
1145 // Set the initial parameters from the seed fit
1146 landaui->SetParameter(AliForwardUtil::ELossFitter::kC, c);
1147 landaui->SetParameter(AliForwardUtil::ELossFitter::kDelta, delta);
1148 landaui->SetParameter(AliForwardUtil::ELossFitter::kXi, xi);
1149 landaui->SetParameter(AliForwardUtil::ELossFitter::kSigma, sigma);
1150 landaui->SetParameter(AliForwardUtil::ELossFitter::kSigmaN, sigmaN);
1151 landaui->FixParameter(AliForwardUtil::ELossFitter::kN, i);
1156 //====================================================================
1157 AliForwardUtil::ELossFitter::ELossFitter(Double_t lowCut,
1160 : fLowCut(lowCut), fMaxRange(maxRange), fMinusBins(minusBins),
1161 fFitResults(0), fFunctions(0), fDebug(false)
1167 // lowCut Lower cut of spectrum - data below this cuts is ignored
1168 // maxRange Maximum range to fit to
1169 // minusBins The number of bins below maximum to use
1171 fFitResults.SetOwner();
1172 fFunctions.SetOwner();
1174 //____________________________________________________________________
1175 AliForwardUtil::ELossFitter::~ELossFitter()
1181 fFitResults.Delete();
1182 fFunctions.Delete();
1184 //____________________________________________________________________
1186 AliForwardUtil::ELossFitter::Clear()
1189 // Clear internal arrays
1192 fFitResults.Clear();
1196 void setParLimit(TF1* f, Int_t iPar, Bool_t debug,
1197 Double_t test, Double_t low, Double_t high)
1199 if (test >= low && test <= high) {
1201 printf("Fit: Set par limits on %s: %f, %f\n",
1202 f->GetParName(iPar), low, high);
1203 f->SetParLimits(iPar, low, high);
1208 //____________________________________________________________________
1210 AliForwardUtil::ELossFitter::Fit1Particle(TH1* dist, Double_t sigman)
1213 // Fit a 1-particle signal to the passed energy loss distribution
1215 // Note that this function clears the internal arrays first
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
1230 // Find the fit range
1231 // Find the fit range
1232 Int_t cutBin = TMath::Max(dist->GetXaxis()->FindBin(fLowCut),3);
1233 Int_t maxBin = TMath::Min(dist->GetXaxis()->FindBin(fMaxRange),
1235 dist->GetXaxis()->SetRange(cutBin, maxBin);
1236 // dist->GetXaxis()->SetRangeUser(fLowCut, fMaxRange);
1238 // Get the bin with maximum
1239 Int_t peakBin = dist->GetMaximumBin();
1240 Double_t peakE = dist->GetBinLowEdge(peakBin);
1241 Double_t rmsE = dist->GetRMS();
1244 // dist->GetXaxis()->SetRangeUser(fLowCut, peakE);
1245 Int_t minBin = peakBin - fMinusBins; // dist->GetMinimumBin();
1246 Double_t minE = TMath::Max(dist->GetBinCenter(minBin),fLowCut);
1247 Double_t maxE = dist->GetBinCenter(peakBin+2*fMinusBins);
1249 Int_t minEb = dist->GetXaxis()->FindBin(minE);
1250 Int_t maxEb = dist->GetXaxis()->FindBin(maxE);
1251 Double_t intg = dist->Integral(minEb, maxEb);
1253 ::Warning("Fit1Particle",
1254 "Integral of %s between [%f,%f] [%03d,%03d] = %f < 0",
1255 dist->GetName(), minE, maxE, minEb, maxEb, intg);
1259 // Restore the range
1260 dist->GetXaxis()->SetRange(1, maxBin);
1262 // Define the function to fit
1263 TF1* landau1 = new TF1("landau1", landauGaus1, minE,maxE,kSigmaN+1);
1265 // Set initial guesses, parameter names, and limits
1266 landau1->SetParameters(intg,peakE,peakE/10,peakE/5,sigman);
1267 landau1->SetParNames("C","#Delta_{p}","#xi", "#sigma", "#sigma_{n}");
1268 landau1->SetNpx(500);
1269 setParLimit(landau1, kDelta, fDebug, peakE, minE, fMaxRange);
1270 setParLimit(landau1, kXi, fDebug, peakE, 0, rmsE); // 0.1
1271 setParLimit(landau1, kSigma, fDebug, peakE/5, 1e-5, rmsE); // 0.1
1272 if (sigman <= 0) landau1->FixParameter(kSigmaN, 0);
1274 setParLimit(landau1, kSigmaN, fDebug, peakE, 0, rmsE);
1277 TString opts(Form("%s%s", FIT_OPTIONS, fDebug ? "" : "Q"));
1278 // Do the fit, getting the result object
1280 ::Info("Fit1Particle", "Fitting in the range %f,%f", minE, maxE);
1281 TFitResultPtr r = dist->Fit(landau1, opts, "", minE, maxE);
1283 ::Warning("Fit1Particle",
1284 "No fit returned when processing %s in the range [%f,%f] "
1285 "options %s", dist->GetName(), minE, maxE, FIT_OPTIONS);
1288 // landau1->SetRange(minE, fMaxRange);
1289 fFitResults.AddAtAndExpand(new TFitResult(*r), 0);
1290 fFunctions.AddAtAndExpand(landau1, 0);
1294 //____________________________________________________________________
1296 AliForwardUtil::ELossFitter::FitNParticle(TH1* dist, UShort_t n,
1300 // Fit a N-particle signal to the passed energy loss distribution
1302 // If there's no 1-particle fit present, it does that first
1305 // dist Data to fit the function to
1306 // n Number of particle signals to fit
1307 // sigman If larger than zero, the initial guess of the
1308 // detector induced noise. If zero or less, then this
1309 // parameter is ignored in the fit (fixed at 0)
1312 // The function fitted to the data
1315 // Get the seed fit result
1316 TFitResult* r = static_cast<TFitResult*>(fFitResults.At(0));
1317 TF1* f = static_cast<TF1*>(fFunctions.At(0));
1319 f = Fit1Particle(dist, sigman);
1320 r = static_cast<TFitResult*>(fFitResults.At(0));
1322 ::Warning("FitNLandau", "No first shot at landau fit");
1327 // Get some parameters from seed fit
1328 Double_t delta1 = r->Parameter(kDelta);
1329 Double_t xi1 = r->Parameter(kXi);
1330 Double_t maxEi = n * (delta1 + xi1 * TMath::Log(n)) + 2 * n * xi1;
1331 Double_t minE = f->GetXmin();
1333 Int_t minEb = dist->GetXaxis()->FindBin(minE);
1334 Int_t maxEb = dist->GetXaxis()->FindBin(maxEi);
1335 Double_t rmsE = dist->GetRMS();
1336 Double_t intg = dist->Integral(minEb, maxEb);
1338 ::Warning("FitNParticle",
1339 "Integral of %s between [%f,%f] [%03d,%03d] = %f < 0",
1340 dist->GetName(), minE, maxEi, minEb, maxEb, intg);
1346 for (UShort_t i = 2; i <= n; i++)
1347 a.fArray[i-2] = (n == 2 ? 0.05 : 0.000001);
1348 // Make the fit function
1349 TF1* landaun = MakeNLandauGaus(r->Parameter(kC),
1350 r->Parameter(kDelta),
1352 r->Parameter(kSigma),
1353 r->Parameter(kSigmaN),
1354 n, a.fArray, minE, maxEi);
1355 setParLimit(landaun, kDelta, fDebug, r->Parameter(kDelta), minE, fMaxRange);
1356 setParLimit(landaun, kXi, fDebug, r->Parameter(kXi), 0, rmsE); // 0.1
1357 setParLimit(landaun, kSigma, fDebug, r->Parameter(kSigma), 1e-5, rmsE); // 0.1
1358 if (sigman <= 0) landaun->FixParameter(kSigmaN, 0);
1360 setParLimit(landaun, kSigmaN, fDebug, r->Parameter(kSigmaN), 0, rmsE);
1362 // Set the range and name of the scale parameters
1363 for (UShort_t i = 2; i <= n; i++) {// Take parameters from last fit
1364 setParLimit(landaun, kA+i-2, fDebug, a[i-2], 0, 1);
1368 TString opts(Form("%s%s", FIT_OPTIONS, fDebug ? "" : "Q"));
1370 ::Info("FitNParticle", "Fitting in the range %f,%f (%d)", minE, maxEi, n);
1371 TFitResultPtr tr = dist->Fit(landaun, opts, "", minE, maxEi);
1373 // landaun->SetRange(minE, fMaxRange);
1374 fFitResults.AddAtAndExpand(new TFitResult(*tr), n-1);
1375 fFunctions.AddAtAndExpand(landaun, n-1);
1379 //____________________________________________________________________
1381 AliForwardUtil::ELossFitter::FitComposite(TH1* dist, Double_t sigman)
1384 // Fit a composite particle signal to the passed energy loss
1387 // dist Data to fit the function to
1388 // sigman If larger than zero, the initial guess of the
1389 // detector induced noise. If zero or less, then this
1390 // parameter is ignored in the fit (fixed at 0)
1393 // The function fitted to the data
1396 // Find the fit range
1397 Int_t cutBin = TMath::Max(dist->GetXaxis()->FindBin(fLowCut),3);
1398 Int_t maxBin = TMath::Min(dist->GetXaxis()->FindBin(fMaxRange),
1400 dist->GetXaxis()->SetRange(cutBin, maxBin);
1402 // Get the bin with maximum
1403 Int_t peakBin = dist->GetMaximumBin();
1404 Double_t peakE = dist->GetBinLowEdge(peakBin);
1407 // dist->GetXaxis()->SetRangeUser(fLowCut, peakE);
1408 Int_t minBin = peakBin - fMinusBins; // dist->GetMinimumBin();
1409 Double_t minE = TMath::Max(dist->GetBinCenter(minBin),fLowCut);
1410 Double_t maxE = dist->GetBinCenter(peakBin+2*fMinusBins);
1412 // Get the range in bins and the integral of that range
1413 Int_t minEb = dist->GetXaxis()->FindBin(minE);
1414 Int_t maxEb = dist->GetXaxis()->FindBin(maxE);
1415 Double_t intg = dist->Integral(minEb, maxEb);
1417 ::Warning("Fit1Particle",
1418 "Integral of %s between [%f,%f] [%03d,%03d] = %f < 0",
1419 dist->GetName(), minE, maxE, minEb, maxEb, intg);
1423 // Restore the range
1424 dist->GetXaxis()->SetRange(1, maxBin);
1426 // Define the function to fit
1427 TF1* seed = new TF1("landauSeed", landauGaus1, minE,maxE,kSigmaN+1);
1429 // Set initial guesses, parameter names, and limits
1430 seed->SetParameters(1,peakE,peakE/10,peakE/5,sigman);
1431 seed->SetParNames("C","#Delta_{p}","#xi", "#sigma", "#sigma_{n}");
1433 seed->SetParLimits(kDelta, minE, fMaxRange);
1434 seed->SetParLimits(kXi, 0.00, 0.1); // Was fMaxRange - too wide
1435 seed->SetParLimits(kSigma, 1e-5, 0.1); // Was fMaxRange - too wide
1436 if (sigman <= 0) seed->FixParameter(kSigmaN, 0);
1437 else seed->SetParLimits(kSigmaN, 0, fMaxRange);
1439 // Do the fit, getting the result object
1441 ::Info("FitComposite", "Fitting seed in the range %f,%f", minE, maxE);
1442 /* TFitResultPtr r = */ dist->Fit(seed, FIT_OPTIONS, "", minE, maxE);
1444 maxE = dist->GetXaxis()->GetXmax();
1446 TF1* comp = new TF1("composite", landauGausComposite,
1447 minE, maxE, kSigma+1+2);
1448 comp->SetParNames("C", "#Delta_{p}", "#xi", "#sigma",
1449 "C#prime", "#xi#prime");
1450 comp->SetParameters(0.8 * seed->GetParameter(kC), // 0 Primary weight
1451 seed->GetParameter(kDelta), // 1 Primary Delta
1452 seed->GetParameter(kDelta)/10, // 2 primary Xi
1453 seed->GetParameter(kDelta)/5, // 3 primary sigma
1454 1.20 * seed->GetParameter(kC), // 5 Secondary weight
1455 seed->GetParameter(kXi)); // 7 secondary Xi
1456 // comp->SetParLimits(kC, minE, fMaxRange); // C
1457 comp->SetParLimits(kDelta, minE, fMaxRange); // Delta
1458 comp->SetParLimits(kXi, 0.00, fMaxRange); // Xi
1459 comp->SetParLimits(kSigma, 1e-5, fMaxRange); // Sigma
1460 // comp->SetParLimits(kSigma+1, minE, fMaxRange); // C
1461 comp->SetParLimits(kSigma+2, 0.00, fMaxRange); // Xi'
1463 TF1* comp = new TF1("composite", landauGausComposite,
1464 minE, maxE, kSigma+1+4);
1465 comp->SetParNames("C", "#Delta_{p}", "#xi", "#sigma",
1466 "C#prime", "#Delta_{p}#prime", "#xi#prime", "#sigma#prim");
1467 comp->SetParameters(0.8 * seed->GetParameter(kC), // 0 Primary weight
1468 seed->GetParameter(kDelta), // 1 Primary Delta
1469 seed->GetParameter(kDelta)/10, // 2 primary Xi
1470 seed->GetParameter(kDelta)/5, // 3 primary sigma
1471 1.20 * seed->GetParameter(kC), // 5 Secondary weight
1472 seed->GetParameter(kDelta), // 6 secondary Delta
1473 seed->GetParameter(kXi), // 7 secondary Xi
1474 seed->GetParameter(kSigma)); // 8 secondary sigma
1475 // comp->SetParLimits(kC, minE, fMaxRange); // C
1476 comp->SetParLimits(kDelta, minE, fMaxRange); // Delta
1477 comp->SetParLimits(kXi, 0.00, fMaxRange); // Xi
1478 comp->SetParLimits(kSigma, 1e-5, fMaxRange); // Sigma
1479 // comp->SetParLimits(kSigma+1, minE, fMaxRange); // C
1480 comp->SetParLimits(kSigma+2, minE/10, fMaxRange); // Delta
1481 comp->SetParLimits(kSigma+3, 0.00, fMaxRange); // Xi
1482 comp->SetParLimits(kSigma+4, 1e-6, fMaxRange); // Sigma
1484 comp->SetLineColor(kRed+1);
1485 comp->SetLineWidth(3);
1487 // Do the fit, getting the result object
1488 TString opts(Form("%s%s", FIT_OPTIONS, fDebug ? "" : "Q"));
1490 ::Info("FitComposite", "Fitting composite in the range %f,%f", minE, maxE);
1491 /* TFitResultPtr r = */ dist->Fit(comp, opts, "", minE, maxE);
1494 TF1* part1 = static_cast<TF1*>(seed->Clone("part1"));
1495 part1->SetLineColor(kGreen+1);
1496 part1->SetLineWidth(4);
1497 part1->SetRange(minE, maxE);
1498 part1->SetParameters(comp->GetParameter(0), // C
1499 comp->GetParameter(1), // Delta
1500 comp->GetParameter(2), // Xi
1501 comp->GetParameter(3), // sigma
1503 part1->Save(minE,maxE,0,0,0,0);
1504 dist->GetListOfFunctions()->Add(part1);
1506 TF1* part2 = static_cast<TF1*>(seed->Clone("part2"));
1507 part2->SetLineColor(kBlue+1);
1508 part2->SetLineWidth(4);
1509 part2->SetRange(minE, maxE);
1510 part2->SetParameters(comp->GetParameter(4), // C
1511 comp->GetParameter(5), // Delta
1512 comp->GetParameter(6), // Xi
1513 comp->GetParameter(7), // sigma
1515 part2->Save(minE,maxE,0,0,0,0);
1516 dist->GetListOfFunctions()->Add(part2);
1522 //====================================================================
1523 AliForwardUtil::Histos::~Histos()
1530 //____________________________________________________________________
1532 AliForwardUtil::Histos::Delete(Option_t* opt)
1534 if (fFMD1i) delete fFMD1i;
1535 if (fFMD2i) delete fFMD2i;
1536 if (fFMD2o) delete fFMD2o;
1537 if (fFMD3i) delete fFMD3i;
1538 if (fFMD3o) delete fFMD3o;
1544 TObject::Delete(opt);
1547 //____________________________________________________________________
1549 AliForwardUtil::Histos::Make(UShort_t d, Char_t r, const TAxis& etaAxis)
1557 // etaAxis Eta axis to use
1560 // Newly allocated histogram
1562 Int_t ns = (r == 'I' || r == 'i') ? 20 : 40;
1564 if (etaAxis.GetXbins() && etaAxis.GetXbins()->GetArray())
1565 hist = new TH2D(Form("FMD%d%c_cache", d, r),
1566 Form("FMD%d%c cache", d, r),
1567 etaAxis.GetNbins(), etaAxis.GetXbins()->GetArray(),
1568 ns, 0, TMath::TwoPi());
1570 hist = new TH2D(Form("FMD%d%c_cache", d, r),
1571 Form("FMD%d%c cache", d, r),
1572 etaAxis.GetNbins(), etaAxis.GetXmin(),
1573 etaAxis.GetXmax(), ns, 0, TMath::TwoPi());
1574 hist->SetXTitle("#eta");
1575 hist->SetYTitle("#phi [radians]");
1576 hist->SetZTitle("d^{2}N_{ch}/d#etad#phi");
1578 hist->SetDirectory(0);
1582 //____________________________________________________________________
1584 AliForwardUtil::Histos::RebinEta(TH2D* hist, const TAxis& etaAxis)
1586 TAxis* xAxis = hist->GetXaxis();
1587 if (etaAxis.GetXbins() && etaAxis.GetXbins()->GetArray())
1588 xAxis->Set(etaAxis.GetNbins(), etaAxis.GetXbins()->GetArray());
1590 xAxis->Set(etaAxis.GetNbins(), etaAxis.GetXmin(), etaAxis.GetXmax());
1595 //____________________________________________________________________
1597 AliForwardUtil::Histos::Init(const TAxis& etaAxis)
1600 // Initialize the object
1603 // etaAxis Eta axis to use
1605 fFMD1i = Make(1, 'I', etaAxis);
1606 fFMD2i = Make(2, 'I', etaAxis);
1607 fFMD2o = Make(2, 'O', etaAxis);
1608 fFMD3i = Make(3, 'I', etaAxis);
1609 fFMD3o = Make(3, 'O', etaAxis);
1611 //____________________________________________________________________
1613 AliForwardUtil::Histos::ReInit(const TAxis& etaAxis)
1616 // Initialize the object
1619 // etaAxis Eta axis to use
1621 if (!fFMD1i) fFMD1i = Make(1, 'i', etaAxis); else RebinEta(fFMD1i, etaAxis);
1622 if (!fFMD2i) fFMD2i = Make(2, 'i', etaAxis); else RebinEta(fFMD2i, etaAxis);
1623 if (!fFMD2o) fFMD2o = Make(2, 'o', etaAxis); else RebinEta(fFMD2o, etaAxis);
1624 if (!fFMD3i) fFMD3i = Make(3, 'i', etaAxis); else RebinEta(fFMD3i, etaAxis);
1625 if (!fFMD3o) fFMD3o = Make(3, 'o', etaAxis); else RebinEta(fFMD3o, etaAxis);
1628 //____________________________________________________________________
1630 AliForwardUtil::Histos::Clear(Option_t* option)
1638 if (fFMD1i) { fFMD1i->Reset(option); fFMD1i->ResetBit(kSkipRing); }
1639 if (fFMD2i) { fFMD2i->Reset(option); fFMD2i->ResetBit(kSkipRing); }
1640 if (fFMD2o) { fFMD2o->Reset(option); fFMD2o->ResetBit(kSkipRing); }
1641 if (fFMD3i) { fFMD3i->Reset(option); fFMD3i->ResetBit(kSkipRing); }
1642 if (fFMD3o) { fFMD3o->Reset(option); fFMD3o->ResetBit(kSkipRing); }
1645 //____________________________________________________________________
1647 AliForwardUtil::Histos::Get(UShort_t d, Char_t r) const
1650 // Get the histogram for a particular detector,ring
1657 // Histogram for detector,ring or nul
1660 case 1: return fFMD1i;
1661 case 2: return (r == 'I' || r == 'i' ? fFMD2i : fFMD2o);
1662 case 3: return (r == 'I' || r == 'i' ? fFMD3i : fFMD3o);
1666 //====================================================================
1668 AliForwardUtil::RingHistos::DefineOutputList(TList* d) const
1671 // Define the outout list in @a d
1674 // d Where to put the output list
1677 // Newly allocated TList object or null
1680 TList* list = new TList;
1682 list->SetName(fName.Data());
1686 //____________________________________________________________________
1688 AliForwardUtil::RingHistos::GetOutputList(const TList* d) const
1691 // Get our output list from the container @a d
1694 // d where to get the output list from
1697 // The found TList or null
1700 TList* list = static_cast<TList*>(d->FindObject(fName.Data()));
1704 //____________________________________________________________________
1706 AliForwardUtil::RingHistos::GetOutputHist(const TList* d, const char* name) const
1709 // Find a specific histogram in the source list @a d
1712 // d (top)-container
1713 // name Name of histogram
1716 // Found histogram or null
1718 return static_cast<TH1*>(d->FindObject(name));
1721 //====================================================================
1722 AliForwardUtil::DebugGuard::DebugGuard(Int_t lvl, Int_t msgLvl,
1723 const char* format, ...)
1726 if (lvl < msgLvl) return;
1728 va_start(ap, format);
1729 Format(fMsg, format, ap);
1733 //____________________________________________________________________
1734 AliForwardUtil::DebugGuard::~DebugGuard()
1736 if (fMsg.IsNull()) return;
1739 //____________________________________________________________________
1741 AliForwardUtil::DebugGuard::Message(Int_t lvl, Int_t msgLvl,
1742 const char* format, ...)
1744 if (lvl < msgLvl) return;
1747 va_start(ap, format);
1748 Format(msg, format, ap);
1753 //____________________________________________________________________
1755 AliForwardUtil::DebugGuard::Format(TString& out, const char* format, va_list ap)
1757 static char buf[512];
1758 Int_t n = gROOT->GetDirLevel() + 2;
1759 for (Int_t i = 0; i < n; i++) buf[i] = ' ';
1760 vsnprintf(&(buf[n]), 511-n, format, ap);
1764 //____________________________________________________________________
1766 AliForwardUtil::DebugGuard::Output(int in, TString& msg)
1768 msg[0] = (in > 0 ? '>' : in < 0 ? '<' : '=');
1769 AliLog::Message(AliLog::kInfo, msg, 0, 0, "PWGLF/forward", 0, 0);
1770 if (in > 0) gROOT->IncreaseDirLevel();
1771 else if (in < 0) gROOT->DecreaseDirLevel();