AliPhysics  58f3d52 (58f3d52)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RerunTrackELoss.C
Go to the documentation of this file.
1 
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 }
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 }
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 }
82 void RerunTrackELoss(Bool_t forceSet=false,
83  const TString& input="forward_mctracks.root",
84  Bool_t shift=true,
85  const TString& output="")
86 {
87  const char* fwd = "$ALICE_PHYSICS/PWGLF/FORWARD/analysis2";
88  gROOT->Macro(Form("%s/scripts/LoadLibs.C", fwd));
89 
90  TFile* inFile = 0;
91  TFile* outFile = 0;
92  TString outName(output);
93  if (outName.IsNull()) {
94  outName = input;
95  outName.ReplaceAll(".root", "_rerun.root");
96  }
97  Bool_t allOk = false;
98  try {
99  // --- Open input file ---------------------------------------------
100  inFile = TFile::Open(input, "READ");
101  if (!inFile)
102  throw TString::Format("Failed to open %s", input.Data());
103 
104  // --- InFiled input collections --------------------------------------
105  TCollection* inFwdSum = GetCollection(inFile, "ForwardTracksSums");
106  if (!inFwdSum) throw new TString("Cannot proceed without sums");
107 
108  TCollection* inFwdRes = GetCollection(inFile, "ForwardTracksResults");
109  if (!inFwdRes) {
110  inFwdRes =
111  static_cast<TCollection*>(inFwdSum->Clone("ForwardTracksResults"));
112  // throw new TString("Cannot proceed with merged list");
113  }
114 
115  TCollection* inEFSum = GetCollection(inFwdRes, "fmdEnergyFitter");
116  if (!inEFSum) throw new TString("Cannot proceed without accumulated data");
117 
118  TCollection* inEFRes = GetCollection(inFwdRes, "fmdEnergyFitter");
119  if (!inEFRes) throw new TString("Cannot proceed without previous results");
120 
121  // --- Open output file --------------------------------------------
122  outFile = TFile::Open(outName, "RECREATE");
123  if (!outFile)
124  throw TString::Format("Failed to open %s", outName.Data());
125 
126  // --- Write copy of sum collection to output --------------------
127  TCollection* outFwdSum = static_cast<TCollection*>(inFwdSum->Clone());
128  outFile->cd();
129  outFwdSum->Write(inFwdSum->GetName(), TObject::kSingleKey);
130 
131  // --- Make our fitter object ------------------------------------
133  fitter->SetDoFits(true);
134  fitter->SetDoMakeObject(false);
135  fitter->SetEnableDeltaShift(shift);
136  fitter->Init();
137  if (forceSet || !fitter->ReadParameters(inEFSum)) {
138  Printf("Forced settings");
139 
140  const TAxis* etaAxis = static_cast<TAxis*>(GetObject(inEFSum,"etaAxis"));
141  if (!etaAxis) throw new TString("Cannot proceed without eta axis");
142  fitter->SetEtaAxis(*etaAxis);
143 
144  // Set maximum energy loss to consider
145  fitter->SetMaxE(15);
146  // Set number of energy loss bins
147  fitter->SetNEbins(500);
148  // Set whether to use increasing bin sizes
149  // fitter->SetUseIncreasingBins(true);
150  // Set whether to do fit the energy distributions
151  fitter->SetDoFits(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  }
165  fitter->SetDoMakeObject(false);
166  fitter->SetDebug(3);
168  fitter->SetRegularizationCut(1e8); // Lower by factor 3
169  // Set the number of bins to subtract from maximum of distributions
170  // to get the lower bound of the fit range
171  // fitter->SetFitRangeBinWidth(2);
172  // Skip all of FMD2 and 3
173  // fitter->SetSkips(AliFMDEnergyFitter::kFMD2|AliFMDEnergyFitter::kFMD3);
174 
175  // --- Now do the fits -------------------------------------------
176  fitter->Print();
177  outFwdSum->ls("R");
178  fitter->Fit(static_cast<TList*>(outFwdSum));
179 
180  // --- Copy full result folder -----------------------------------
181  TCollection* outFwdRes = static_cast<TCollection*>(inFwdRes->Clone());
182  // Remove old fits
183  TCollection* outEFRes = GetCollection(outFwdRes, "fmdEnergyFitter");
184  outFwdRes->Remove(outEFRes);
185  // Make our new fit results folder, and add it to results folder
186  TCollection* tmp = GetCollection(outFwdSum, "fmdEnergyFitter");
187  outEFRes = static_cast<TCollection*>(tmp->Clone());
188  outEFRes->Add(new TNamed("refitted", "Refit of the data"));
189  outFwdRes->Add(outEFRes);
190 
191  // --- Write out new results folder ------------------------------
192  outFile->cd();
193  outFwdRes->Write(inFwdRes->GetName(), TObject::kSingleKey);
194  Printf("Wrote results to \"%s\" (%s)", outName.Data(), outFile->GetName());
195  allOk = true;
196  }
197  catch (const TString* e) {
198  Error("RerunELossFits", e->Data());
199  }
200  catch (const TString& e) {
201  Error("RerunELossFits", e.Data());
202  }
203  if (inFile) inFile->Close();
204  if (outFile) {
205  Printf("Wrote new output to \"%s\"", outName.Data());
206  outFile->Close();
207  }
208 
209  if (allOk) {
210  gROOT->LoadMacro(Form("%s/scripts/SummaryMCTrackDrawer.C+g",fwd));
212  smd.Run(outName.Data(),0x10F);
213  }
214 }
215 
216 
void SetEnableDeltaShift(Bool_t use=true)
void RerunTrackELoss(Bool_t forceSet=false, const TString &input="forward_mctracks.root", Bool_t shift=true, const TString &output="")
void Run(const char *fname, UShort_t what=kNormal)
void SetDoFits(Bool_t doFit=kTRUE)
void SetLowCut(Double_t lowCut=0.3)
virtual void Fit(const TList *dir)
void SetFitRangeBinWidth(UShort_t n=4)
Bool_t ReadParameters(const TCollection *list)
void SetStoreResiduals(EResidualMethod x=kResidualDifference)
void SetMaxE(Double_t x)
TObject * GetObject(const TCollection *parent, const TString &name, const TClass *cls=0)
void SetNParticles(UShort_t n)
void SetDoMakeObject(Bool_t doMake=kTRUE)
void SetRegularizationCut(Double_t cut=3e6)
TList * fitter
Definition: DrawAnaELoss.C:26
void SetMinEntries(UShort_t n)
const char * fwd
void SetEtaAxis(Int_t nBins, Double_t etaMin, Double_t etaMax)
void SetDebug(Int_t dbg=1)
bool Bool_t
Definition: External.C:53
void Print(Option_t *option="") const
TDirectoryFile * dir
TCollection * GetCollection(TDirectory *dir, const TString &name)