]>
Commit | Line | Data |
---|---|---|
81775aba | 1 | /** |
2 | * Get a collection from a file directory | |
3 | * | |
4 | * @param dir Parent directory | |
5 | * @param name Name of collection | |
6 | * | |
7 | * @return collection or null | |
8 | */ | |
9 | TCollection* GetCollection(TDirectory* dir, const TString& name) | |
10 | { | |
11 | if (!dir) { | |
12 | Error("GetCollection", "No parent directory for %s", name.Data()); | |
13 | return 0; | |
14 | } | |
15 | TCollection* ret = 0; | |
16 | dir->GetObject(name, ret); | |
17 | if (!ret) { | |
18 | Error("GetCollection", "Couldn't find %s in %s", | |
19 | name.Data(), dir->GetName()); | |
20 | return 0; | |
21 | } | |
22 | return ret; | |
23 | } | |
24 | /** | |
25 | * Get an object from a collection. Optionally, we check that the | |
26 | * type of the possibly found object matches the request. | |
27 | * | |
28 | * @param parent Parent collection | |
29 | * @param name Name of object | |
30 | * @param cls If specified, check that the found object (if any) is of | |
31 | * this class. | |
32 | * | |
33 | * @return Found object (possibly type-checked) or null | |
34 | */ | |
35 | TObject* GetObject(const TCollection* parent, const TString& name, | |
36 | const TClass* cls=0) | |
37 | { | |
38 | if (!parent) { | |
39 | Error("GetObject", "No parent collection for %s", name.Data()); | |
40 | return 0; | |
41 | } | |
42 | TObject* ret = parent->FindObject(name); | |
43 | if (!ret) { | |
44 | Error("GetObject", "Couldn't find %s in %s", | |
45 | name.Data(), parent->GetName()); | |
46 | return 0; | |
47 | } | |
48 | if (cls && !ret->IsA()->InheritsFrom(cls)) { | |
49 | Error("GetObject", "%s in %s is a %s, not a %s", name.Data(), | |
50 | parent->GetName(), ret->ClassName(), cls->GetName()); | |
51 | return 0; | |
52 | } | |
53 | return ret; | |
54 | } | |
55 | /** | |
56 | * Get a collection contained in another collection | |
57 | * | |
58 | * @param parent Parent collection | |
59 | * @param name Name of collection to find | |
60 | * | |
61 | * @return Found collection or null | |
62 | */ | |
63 | TCollection* GetCollection(const TCollection* parent, const TString& name) | |
64 | { | |
65 | TObject* o = GetObject(parent, name, TCollection::Class()); | |
66 | if (!o) return 0; | |
67 | return static_cast<TCollection*>(o); | |
68 | } | |
69 | /** | |
70 | * Re-run the energy loss fitter on a merged output file | |
71 | * | |
72 | * @param input File name of merged output file | |
73 | * @param output If specified, the file the new results are written | |
74 | * to. If this is not specified, it defaults to the name of the input | |
75 | * file with "_rerun" attached to the base name | |
c8b1a7db | 76 | * |
77 | * @param forceSet Forcibly set things | |
78 | * @param input Input file | |
79 | * @param output Output file | |
81775aba | 80 | */ |
e65b8b56 | 81 | void RerunELossFits(Bool_t forceSet=false, |
82 | const TString& input="forward_eloss.root", | |
a19faec0 | 83 | Bool_t shift=true, |
81775aba | 84 | const TString& output="") |
85 | { | |
86 | const char* fwd = "$ALICE_ROOT/PWGLF/FORWARD/analysis2"; | |
87 | gROOT->Macro(Form("%s/scripts/LoadLibs.C", fwd)); | |
88 | ||
e65b8b56 | 89 | TFile* inFile = 0; |
90 | TFile* outFile = 0; | |
91 | TString outName(output); | |
92 | if (outName.IsNull()) { | |
93 | outName = input; | |
94 | outName.ReplaceAll(".root", "_rerun.root"); | |
95 | } | |
a19faec0 | 96 | Bool_t allOk = false; |
81775aba | 97 | try { |
98 | // --- Open input file --------------------------------------------- | |
99 | inFile = TFile::Open(input, "READ"); | |
100 | if (!inFile) | |
101 | throw TString::Format("Failed to open %s", input.Data()); | |
102 | ||
103 | // --- InFiled input collections -------------------------------------- | |
a19faec0 | 104 | TCollection* inFwdSum = GetCollection(inFile, "ForwardELossSums"); |
a1907e85 | 105 | if (!inFwdSum) throw new TString("Cannot proceed without sums"); |
81775aba | 106 | |
a19faec0 | 107 | TCollection* inFwdRes = GetCollection(inFile, "ForwardELossResults"); |
a1907e85 | 108 | if (!inFwdRes) { |
109 | inFwdRes = | |
110 | static_cast<TCollection*>(inFwdSum->Clone("ForwardELossResults")); | |
111 | // throw new TString("Cannot proceed with merged list"); | |
112 | } | |
81775aba | 113 | |
114 | TCollection* inEFSum = GetCollection(inFwdRes, "fmdEnergyFitter"); | |
a1907e85 | 115 | if (!inEFSum) throw new TString("Cannot proceed without accumulated data"); |
81775aba | 116 | |
117 | TCollection* inEFRes = GetCollection(inFwdRes, "fmdEnergyFitter"); | |
a1907e85 | 118 | if (!inEFRes) throw new TString("Cannot proceed without previous results"); |
81775aba | 119 | |
81775aba | 120 | // --- Open output file -------------------------------------------- |
81775aba | 121 | outFile = TFile::Open(outName, "RECREATE"); |
122 | if (!outFile) | |
e65b8b56 | 123 | throw TString::Format("Failed to open %s", outName.Data()); |
81775aba | 124 | |
125 | // --- Write copy of sum collection to output -------------------- | |
126 | TCollection* outFwdSum = static_cast<TCollection*>(inFwdSum->Clone()); | |
127 | outFile->cd(); | |
a19faec0 | 128 | outFwdSum->Write(inFwdSum->GetName(), TObject::kSingleKey); |
81775aba | 129 | |
130 | // --- Make our fitter object ------------------------------------ | |
131 | AliFMDEnergyFitter* fitter = new AliFMDEnergyFitter("energy"); | |
a19faec0 | 132 | fitter->SetDoFits(true); |
133 | fitter->SetEnableDeltaShift(shift); | |
134 | fitter->Init(); | |
e65b8b56 | 135 | if (forceSet || !fitter->ReadParameters(inEFSum)) { |
a19faec0 | 136 | Printf("Forced settings"); |
81775aba | 137 | |
e65b8b56 | 138 | const TAxis* etaAxis = static_cast<TAxis*>(GetObject(inEFSum,"etaAxis")); |
a1907e85 | 139 | if (!etaAxis) throw new TString("Cannot proceed without eta axis"); |
e65b8b56 | 140 | fitter->SetEtaAxis(*etaAxis); |
141 | ||
142 | // Set maximum energy loss to consider | |
143 | fitter->SetMaxE(15); | |
144 | // Set number of energy loss bins | |
145 | fitter->SetNEbins(500); | |
146 | // Set whether to use increasing bin sizes | |
147 | // fitter->SetUseIncreasingBins(true); | |
148 | // Set whether to do fit the energy distributions | |
149 | fitter->SetDoFits(kTRUE); | |
150 | // Set whether to make the correction object | |
151 | fitter->SetDoMakeObject(kTRUE); | |
152 | // Set the low cut used for energy | |
153 | fitter->SetLowCut(0.4); | |
154 | // Set the number of bins to subtract from maximum of distributions | |
155 | // to get the lower bound of the fit range | |
156 | fitter->SetFitRangeBinWidth(4); | |
157 | // Set the maximum number of landaus to try to fit (max 5) | |
158 | fitter->SetNParticles(5); | |
159 | // Set the minimum number of entries in the distribution before | |
160 | // trying to fit to the data - 10k seems the least we can do | |
161 | fitter->SetMinEntries(10000); | |
162 | // fitter->SetMaxChi2PerNDF(10); | |
163 | // Enable debug | |
164 | } | |
a19faec0 | 165 | fitter->SetDebug(3); |
e65b8b56 | 166 | fitter->SetStoreResiduals(AliFMDEnergyFitter::kResidualSquareDifference); |
a1907e85 | 167 | fitter->SetRegularizationCut(1e8); // Lower by factor 3 |
81775aba | 168 | // Set the number of bins to subtract from maximum of distributions |
169 | // to get the lower bound of the fit range | |
e65b8b56 | 170 | // fitter->SetFitRangeBinWidth(2); |
171 | // Skip all of FMD2 and 3 | |
172 | // fitter->SetSkips(AliFMDEnergyFitter::kFMD2|AliFMDEnergyFitter::kFMD3); | |
81775aba | 173 | |
174 | // --- Now do the fits ------------------------------------------- | |
175 | fitter->Print(); | |
a19faec0 | 176 | outFwdSum->ls("R"); |
81775aba | 177 | fitter->Fit(static_cast<TList*>(outFwdSum)); |
178 | ||
179 | // --- Copy full result folder ----------------------------------- | |
180 | TCollection* outFwdRes = static_cast<TCollection*>(inFwdRes->Clone()); | |
181 | // Remove old fits | |
182 | TCollection* outEFRes = GetCollection(outFwdRes, "fmdEnergyFitter"); | |
183 | outFwdRes->Remove(outEFRes); | |
184 | // Make our new fit results folder, and add it to results folder | |
185 | TCollection* tmp = GetCollection(outFwdSum, "fmdEnergyFitter"); | |
186 | outEFRes = static_cast<TCollection*>(tmp->Clone()); | |
187 | outEFRes->Add(new TNamed("refitted", "Refit of the data")); | |
188 | outFwdRes->Add(outEFRes); | |
189 | ||
190 | // --- Write out new results folder ------------------------------ | |
191 | outFile->cd(); | |
a19faec0 | 192 | outFwdRes->Write(inFwdRes->GetName(), TObject::kSingleKey); |
e65b8b56 | 193 | Printf("Wrote results to \"%s\" (%s)", outName.Data(), outFile->GetName()); |
a19faec0 | 194 | allOk = true; |
81775aba | 195 | } |
a1907e85 | 196 | catch (const TString* e) { |
197 | Error("RerunELossFits", e->Data()); | |
198 | } | |
81775aba | 199 | catch (const TString& e) { |
a1907e85 | 200 | Error("RerunELossFits", e.Data()); |
81775aba | 201 | } |
202 | if (inFile) inFile->Close(); | |
e65b8b56 | 203 | if (outFile) { |
204 | Printf("Wrote new output to \"%s\"", outName.Data()); | |
205 | outFile->Close(); | |
206 | } | |
81775aba | 207 | |
a19faec0 | 208 | if (allOk) |
209 | gROOT->Macro(Form("%s/corrs/DrawCorrELoss.C(false,false,\"%s\")", | |
210 | fwd, outName.Data())); | |
81775aba | 211 | } |
212 | ||
213 |