2 #include "AliForwardCorrectionManager.h"
3 #include "AliFMDCorrELossFit.h"
10 #include <TClonesArray.h>
13 class AliFMDCirrELossFit;
19 * Class to make correction object and save to file
24 * gROOT->Macro("$ALICE_ROOT/PWGLF/FORWARD/analysis2/scripts/LoadLibs.C");
25 * gROOT->LoadMacro("$ALICE_ROOT/PWGLF/FORWARD/analysis2/scripts/Compile.C");
26 * Compile("$ALICE_ROOT/PWGLF/FORWARD/analysis2/MakeELossFit.C");
27 * MakeELossFit mef(sys, cms, field, mc, "AnalysisResults.root");
30 * where @e sys, the collision system, is one of
34 * @e cms is the center of mass energy per nuclean in GeV (e.g., 2760
35 * for first PbPb data), @e field is (signed) L3 magnetic in kG, and
36 * @e mc is wether this correction applies to MC data or not.
38 * The class generates a file like
40 * elossfits<sys>_<cms>GeV_<field>kG_<realmc>.root
42 * in the working directory. This file can be moved to
44 * $(ALICE_ROOT)/PWGLF/FORWARD/corrections/ELossFits
46 * and stored in SVN for later use.
49 * The class AliFMDELossFitter automatically generates the
50 * AliFMDCorrELossFit object.
52 * @ingroup pwglf_forward_scripts_tests
67 //__________________________________________________________________
68 MakeELossFit(UShort_t sys,
72 const char* filename="forward_eloss.root")
75 fFits("AliFMDCorrELossFit::ELossFit"),
81 TFile* file = TFile::Open(filename, "READ");
83 Error("MakeELossFit", "Failed to open file %s", filename);
86 TList* forward = static_cast<TList*>(file->Get("Forward"));
87 // static_cast<TList*>(file->Get("PWGLFforwardDnDeta/Forward"));
89 Error("MakeELossFit", "Couldn't get forward list from %s", filename);
93 fFitter = static_cast<TList*>(forward->FindObject("fmdEnergyFitter"));
95 Error("MakeELossFit", "Couldn't get fitter folder");
99 fAxis = static_cast<TAxis*>(fFitter->FindObject("etaAxis"));
101 Error("MakeELossFit", "Couldn't get eta axis");
107 AliForwardCorrectionManager& mgr = AliForwardCorrectionManager::Instance();
108 mgr.Init(sys, cms, field, mc, 0, true);
111 //__________________________________________________________________
112 TList* GetRing(UShort_t d, Char_t r) const
114 TList* rL = static_cast<TList*>(fFitter->FindObject(Form("FMD%d%c",d,r)));
116 Warning("DrawFits", "List FMD%d%c not found", d, r);
121 //__________________________________________________________________
122 TList* GetEDists(UShort_t d, Char_t r) const
124 TList* rList = GetRing(d, r);
129 TList* edists = static_cast<TList*>(rList->FindObject("EDists"));
131 Error("PrintFits", "Couldn't get EDists list for FMD%d%c", d,r);
136 //__________________________________________________________________
137 TH1* GetEDist(UShort_t d, Char_t r, UShort_t etabin)
139 TList* eList = GetEDists(d, r);
141 Warning("GetEDist", "No list for FMD%d%c", d, r);
146 TString cmp(Form("FMD%d%c_etabin%03d", d, r, etabin));
150 while ((o = next())) {
151 if (!cmp.CompareTo(o->GetName())) {
152 return static_cast<TH1*>(o);
158 //__________________________________________________________________
159 AliFMDCorrELossFit::ELossFit* FindBestFit(TH1* dist)
161 TList* funcs = dist->GetListOfFunctions();
166 Info("FindBestFit", "%s", dist->GetName());
167 while ((func = static_cast<TF1*>(next()))) {
168 AliFMDCorrELossFit::ELossFit* fit =
169 new(fFits[i++]) AliFMDCorrELossFit::ELossFit(0,*func);
170 fit->CalculateQuality(10, .20, 1e-7);
174 return static_cast<AliFMDCorrELossFit::ELossFit*>(fFits.At(0));
177 //__________________________________________________________________
180 if (!fFitter || !fAxis) {
181 Error("Run", "Missing objects");
184 AliFMDCorrELossFit* obj = new AliFMDCorrELossFit;
185 obj->SetEtaAxis(*fAxis);
187 for (UShort_t d = 1; d <= 3; d++) {
188 Info("Run", "detector is FMD%d", d);
189 UShort_t nQ = (d == 1 ? 1 : 2);
190 for (UShort_t q = 0; q < nQ; q++) {
191 Char_t r = (q == 0 ? 'I' : 'O');
192 Int_t nBin = fAxis->GetNbins();
193 Info("Run", " ring is FMD%d%c - %d bins", d, r, nBin);
195 Bool_t oneSeen = kFALSE;
196 for (UShort_t b = 1; b <= nBin; b++) {
197 TH1* h = GetEDist(d, r, b);
198 if (oneSeen && !h) break;
200 if (!oneSeen) oneSeen = true;
202 AliFMDCorrELossFit::ELossFit* best = FindBestFit(h);
207 // Double_t eta = fAxis->GetBinCenter(b);
208 Info("Run", " bin=%3d->%6.4f", b, eta);
209 obj->SetFit(d, r, b, new AliFMDCorrELossFit::ELossFit(*best));
213 AliForwardCorrectionManager& mgr = AliForwardCorrectionManager::Instance();
214 TString fname(mgr.GetFileName(AliForwardCorrectionManager::kELossFits,
215 fSys, fCMS, fField, fMC));
216 TFile* output = TFile::Open(fname.Data(), "RECREATE");
218 Warning("Run", "Failed to open output file %s", fname.Data());
221 obj->Write(mgr.GetObjectName(AliForwardCorrectionManager::kELossFits));
224 Info("Run", "File %s created. It should be copied to %s and stored in SVN",
225 fname.Data(),mgr.GetFileDir(AliForwardCorrectionManager::kELossFits));