]>
Commit | Line | Data |
---|---|---|
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 | |
76 | * | |
77 | * @param forceSet Forcibly set things | |
78 | * @param input Input file | |
79 | * @param output Output file | |
80 | */ | |
81 | void RerunELossFits(Bool_t forceSet=false, | |
82 | const TString& input="forward_eloss.root", | |
83 | const TString& output="") | |
84 | { | |
85 | const char* fwd = "$ALICE_ROOT/PWGLF/FORWARD/analysis2"; | |
86 | gROOT->Macro(Form("%s/scripts/LoadLibs.C", fwd)); | |
87 | ||
88 | TFile* inFile = 0; | |
89 | TFile* outFile = 0; | |
90 | TString outName(output); | |
91 | if (outName.IsNull()) { | |
92 | outName = input; | |
93 | outName.ReplaceAll(".root", "_rerun.root"); | |
94 | } | |
95 | ||
96 | try { | |
97 | // --- Open input file --------------------------------------------- | |
98 | inFile = TFile::Open(input, "READ"); | |
99 | if (!inFile) | |
100 | throw TString::Format("Failed to open %s", input.Data()); | |
101 | ||
102 | // --- InFiled input collections -------------------------------------- | |
103 | TCollection* inFwdSum = GetCollection(inFile, "Forward"); | |
104 | if (!inFwdSum) throw TString("Cannot proceed without sums"); | |
105 | ||
106 | TCollection* inFwdRes = GetCollection(inFile, "ForwardResults"); | |
107 | if (!inFwdRes) throw TString("Cannot proceed with merged list"); | |
108 | ||
109 | TCollection* inEFSum = GetCollection(inFwdRes, "fmdEnergyFitter"); | |
110 | if (!inEFSum) throw TString("Cannot proceed without accumulated data"); | |
111 | ||
112 | TCollection* inEFRes = GetCollection(inFwdRes, "fmdEnergyFitter"); | |
113 | if (!inEFRes) throw TString("Cannot proceed without previous results"); | |
114 | ||
115 | // --- Open output file -------------------------------------------- | |
116 | outFile = TFile::Open(outName, "RECREATE"); | |
117 | if (!outFile) | |
118 | throw TString::Format("Failed to open %s", outName.Data()); | |
119 | ||
120 | // --- Write copy of sum collection to output -------------------- | |
121 | TCollection* outFwdSum = static_cast<TCollection*>(inFwdSum->Clone()); | |
122 | outFile->cd(); | |
123 | outFwdSum->Write("Forward", TObject::kSingleKey); | |
124 | ||
125 | // --- Make our fitter object ------------------------------------ | |
126 | AliFMDEnergyFitter* fitter = new AliFMDEnergyFitter("energy"); | |
127 | if (forceSet || !fitter->ReadParameters(inEFSum)) { | |
128 | ||
129 | const TAxis* etaAxis = static_cast<TAxis*>(GetObject(inEFSum,"etaAxis")); | |
130 | if (!etaAxis) throw TString("Cannot proceed without eta axis"); | |
131 | fitter->SetEtaAxis(*etaAxis); | |
132 | ||
133 | // Set maximum energy loss to consider | |
134 | fitter->SetMaxE(15); | |
135 | // Set number of energy loss bins | |
136 | fitter->SetNEbins(500); | |
137 | // Set whether to use increasing bin sizes | |
138 | // fitter->SetUseIncreasingBins(true); | |
139 | // Set whether to do fit the energy distributions | |
140 | fitter->SetDoFits(kTRUE); | |
141 | // Set whether to make the correction object | |
142 | fitter->SetDoMakeObject(kTRUE); | |
143 | // Set the low cut used for energy | |
144 | fitter->SetLowCut(0.4); | |
145 | // Set the number of bins to subtract from maximum of distributions | |
146 | // to get the lower bound of the fit range | |
147 | fitter->SetFitRangeBinWidth(4); | |
148 | // Set the maximum number of landaus to try to fit (max 5) | |
149 | fitter->SetNParticles(5); | |
150 | // Set the minimum number of entries in the distribution before | |
151 | // trying to fit to the data - 10k seems the least we can do | |
152 | fitter->SetMinEntries(10000); | |
153 | // fitter->SetMaxChi2PerNDF(10); | |
154 | // Enable debug | |
155 | } | |
156 | fitter->SetDebug(1); | |
157 | fitter->SetStoreResiduals(AliFMDEnergyFitter::kResidualSquareDifference); | |
158 | // fitter->SetRegularizationCut(3e6); | |
159 | // Set the number of bins to subtract from maximum of distributions | |
160 | // to get the lower bound of the fit range | |
161 | // fitter->SetFitRangeBinWidth(2); | |
162 | // Skip all of FMD2 and 3 | |
163 | // fitter->SetSkips(AliFMDEnergyFitter::kFMD2|AliFMDEnergyFitter::kFMD3); | |
164 | ||
165 | // --- Now do the fits ------------------------------------------- | |
166 | fitter->Print(); | |
167 | fitter->Fit(static_cast<TList*>(outFwdSum)); | |
168 | ||
169 | // --- Copy full result folder ----------------------------------- | |
170 | TCollection* outFwdRes = static_cast<TCollection*>(inFwdRes->Clone()); | |
171 | // Remove old fits | |
172 | TCollection* outEFRes = GetCollection(outFwdRes, "fmdEnergyFitter"); | |
173 | outFwdRes->Remove(outEFRes); | |
174 | // Make our new fit results folder, and add it to results folder | |
175 | TCollection* tmp = GetCollection(outFwdSum, "fmdEnergyFitter"); | |
176 | outEFRes = static_cast<TCollection*>(tmp->Clone()); | |
177 | outEFRes->Add(new TNamed("refitted", "Refit of the data")); | |
178 | outFwdRes->Add(outEFRes); | |
179 | ||
180 | // --- Write out new results folder ------------------------------ | |
181 | outFile->cd(); | |
182 | outFwdRes->Write("ForwardResults", TObject::kSingleKey); | |
183 | Printf("Wrote results to \"%s\" (%s)", outName.Data(), outFile->GetName()); | |
184 | } | |
185 | catch (const TString& e) { | |
186 | Error("RerunELossFits", e); | |
187 | } | |
188 | if (inFile) inFile->Close(); | |
189 | if (outFile) { | |
190 | Printf("Wrote new output to \"%s\"", outName.Data()); | |
191 | outFile->Close(); | |
192 | } | |
193 | ||
194 | gROOT->Macro(Form("%s/corrs/DrawCorrELoss.C(false,false,\"%s\")", | |
195 | fwd, outName.Data())); | |
196 | } | |
197 | ||
198 |