2 * Get a collection from a file directory
4 * @param dir Parent directory
5 * @param name Name of collection
7 * @return collection or null
9 TCollection* GetCollection(TDirectory* dir, const TString& name)
12 Error("GetCollection", "No parent directory for %s", name.Data());
16 dir->GetObject(name, ret);
18 Error("GetCollection", "Couldn't find %s in %s",
19 name.Data(), dir->GetName());
25 * Get an object from a collection. Optionally, we check that the
26 * type of the possibly found object matches the request.
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
33 * @return Found object (possibly type-checked) or null
35 TObject* GetObject(const TCollection* parent, const TString& name,
39 Error("GetObject", "No parent collection for %s", name.Data());
42 TObject* ret = parent->FindObject(name);
44 Error("GetObject", "Couldn't find %s in %s",
45 name.Data(), parent->GetName());
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());
56 * Get a collection contained in another collection
58 * @param parent Parent collection
59 * @param name Name of collection to find
61 * @return Found collection or null
63 TCollection* GetCollection(const TCollection* parent, const TString& name)
65 TObject* o = GetObject(parent, name, TCollection::Class());
67 return static_cast<TCollection*>(o);
70 * Re-run the energy loss fitter on a merged output file
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
77 * @param forceSet Forcibly set things
78 * @param input Input file
79 * @param output Output file
81 void RerunTrackELoss(Bool_t forceSet=false,
82 const TString& input="forward_mctracks.root",
84 const TString& output="")
86 const char* fwd = "$ALICE_ROOT/PWGLF/FORWARD/analysis2";
87 gROOT->Macro(Form("%s/scripts/LoadLibs.C", fwd));
91 TString outName(output);
92 if (outName.IsNull()) {
94 outName.ReplaceAll(".root", "_rerun.root");
98 // --- Open input file ---------------------------------------------
99 inFile = TFile::Open(input, "READ");
101 throw TString::Format("Failed to open %s", input.Data());
103 // --- InFiled input collections --------------------------------------
104 TCollection* inFwdSum = GetCollection(inFile, "ForwardTracksSums");
105 if (!inFwdSum) throw new TString("Cannot proceed without sums");
107 TCollection* inFwdRes = GetCollection(inFile, "ForwardTracksResults");
110 static_cast<TCollection*>(inFwdSum->Clone("ForwardTracksResults"));
111 // throw new TString("Cannot proceed with merged list");
114 TCollection* inEFSum = GetCollection(inFwdRes, "fmdEnergyFitter");
115 if (!inEFSum) throw new TString("Cannot proceed without accumulated data");
117 TCollection* inEFRes = GetCollection(inFwdRes, "fmdEnergyFitter");
118 if (!inEFRes) throw new TString("Cannot proceed without previous results");
120 // --- Open output file --------------------------------------------
121 outFile = TFile::Open(outName, "RECREATE");
123 throw TString::Format("Failed to open %s", outName.Data());
125 // --- Write copy of sum collection to output --------------------
126 TCollection* outFwdSum = static_cast<TCollection*>(inFwdSum->Clone());
128 outFwdSum->Write(inFwdSum->GetName(), TObject::kSingleKey);
130 // --- Make our fitter object ------------------------------------
131 AliFMDMCTrackInspector* fitter = new AliFMDMCTrackInspector("energy");
132 fitter->SetDoFits(true);
133 fitter->SetDoMakeObject(false);
134 fitter->SetEnableDeltaShift(shift);
136 if (forceSet || !fitter->ReadParameters(inEFSum)) {
137 Printf("Forced settings");
139 const TAxis* etaAxis = static_cast<TAxis*>(GetObject(inEFSum,"etaAxis"));
140 if (!etaAxis) throw new TString("Cannot proceed without eta axis");
141 fitter->SetEtaAxis(*etaAxis);
143 // Set maximum energy loss to consider
145 // Set number of energy loss bins
146 fitter->SetNEbins(500);
147 // Set whether to use increasing bin sizes
148 // fitter->SetUseIncreasingBins(true);
149 // Set whether to do fit the energy distributions
150 fitter->SetDoFits(kTRUE);
151 // Set the low cut used for energy
152 fitter->SetLowCut(0.4);
153 // Set the number of bins to subtract from maximum of distributions
154 // to get the lower bound of the fit range
155 fitter->SetFitRangeBinWidth(4);
156 // Set the maximum number of landaus to try to fit (max 5)
157 fitter->SetNParticles(5);
158 // Set the minimum number of entries in the distribution before
159 // trying to fit to the data - 10k seems the least we can do
160 fitter->SetMinEntries(10000);
161 // fitter->SetMaxChi2PerNDF(10);
164 fitter->SetDoMakeObject(false);
166 fitter->SetStoreResiduals(AliFMDEnergyFitter::kResidualSquareDifference);
167 fitter->SetRegularizationCut(1e8); // Lower by factor 3
168 // Set the number of bins to subtract from maximum of distributions
169 // to get the lower bound of the fit range
170 // fitter->SetFitRangeBinWidth(2);
171 // Skip all of FMD2 and 3
172 // fitter->SetSkips(AliFMDEnergyFitter::kFMD2|AliFMDEnergyFitter::kFMD3);
174 // --- Now do the fits -------------------------------------------
177 fitter->Fit(static_cast<TList*>(outFwdSum));
179 // --- Copy full result folder -----------------------------------
180 TCollection* outFwdRes = static_cast<TCollection*>(inFwdRes->Clone());
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);
190 // --- Write out new results folder ------------------------------
192 outFwdRes->Write(inFwdRes->GetName(), TObject::kSingleKey);
193 Printf("Wrote results to \"%s\" (%s)", outName.Data(), outFile->GetName());
196 catch (const TString* e) {
197 Error("RerunELossFits", e->Data());
199 catch (const TString& e) {
200 Error("RerunELossFits", e.Data());
202 if (inFile) inFile->Close();
204 Printf("Wrote new output to \"%s\"", outName.Data());
209 gROOT->LoadMacro(Form("%s/scripts/SummaryMCTrackDrawer.C+g",fwd));
210 SummaryMCTrackDrawer smd;
211 smd.Run(outName.Data(),0x10F);