Updates to Trains. create a job-script to help
[u/mrichter/AliRoot.git] / PWGLF / SPECTRA / IdentifiedHighPt / macros / my_tools.C
CommitLineData
4ebdd20e 1#include <TFile.h>
2#include <TH1.h>
3#include <TROOT.h>
4#include <TString.h>
5#include <TSystem.h>
6
7#include <iostream>
8
9#include "AliHighPtDeDxBase.h"
10
11using namespace std;
12
13
14class DeDxFitInfo : public TObject
15{
16 public:
17
18 DeDxFitInfo();
19 void Print(Option_t* option="") const;
20
21 Double_t MIP;
22 Double_t plateau;
23
24 Int_t optionDeDx;
25 Int_t nDeDxPar;
26 Double_t parDeDx[5];
27
28 Int_t optionSigma;
29 Int_t nSigmaPar;
30 Double_t parSigma[5];
31
32 TString calibFileName;
33
34 ClassDef(DeDxFitInfo, 1); // Help class
35};
36
37
38//_____________________________________________________________________________
39ClassImp(DeDxFitInfo)
40
41DeDxFitInfo::DeDxFitInfo():
42TObject(),
43 MIP(0),
44 plateau(0),
45 optionDeDx(-1),
46 nDeDxPar(-1),
47 optionSigma(-1),
48 nSigmaPar(-1),
49 calibFileName("")
50{
51 // default constructor
52 for(Int_t i = 0; i < 5; i++) {
53 parDeDx[i] = 0;
54 parSigma[i] = 0;
55 }
56}
57
58//_________________________________________________________
59void DeDxFitInfo::Print(Option_t* option) const
60{
61 if(option)
62 cout << "Option: " << option << endl;
63
64 cout << ClassName() << " : " << GetName() << endl
65 << "MIP: " << MIP << endl
66 << "Plateau: " << plateau << endl
67 << "OptionDeDx: " << optionDeDx << endl
68 << "nDeDxPar: " << nDeDxPar << endl;
69 for(Int_t i = 0; i < nDeDxPar; i++) {
70
71 cout << "parDeDx[" << i << "] = " << parDeDx[i] << endl;
72 }
73 cout << "OptionSigma: " << optionSigma << endl
74 << "nSigmaPar: " << nSigmaPar << endl;
75 for(Int_t i = 0; i < nSigmaPar; i++) {
76
77 cout << "parSigma[" << i << "] = " << parSigma[i] << endl;
78 }
79
80 if(calibFileName.IsNull()) {
81 cout << "No eta calibration file." << endl;
82 } else {
83 cout << "Eta calibration file: " << calibFileName.Data() << endl;
84 }
85}
86
87//_____________________________________________________________________________
88
89
90AliHighPtDeDxBase* GetObject(TFile* file, Int_t filter, Bool_t phiCut,
91 Int_t run, const Char_t* baseName="filter",
92 const Char_t* endName=0);
93
94TFile* FindFileFresh(const Char_t* fileName);
95TFile* FindFile(const Char_t* fileName);
96void CutHistogram(TH1* hist, Double_t xMin, Double_t xMax);
97void SetHistError(TH1* hist, Double_t error);
98void CreateDir(const Char_t* dirName);
99
100//___________________________________________________________________________
101AliHighPtDeDxBase* GetObject(TFile* file, Int_t filter, Bool_t phiCut, Int_t run,
102 const Char_t* baseName, const Char_t* endName)
103{
104 TString objectName(baseName);
105 if(filter>0)
106 objectName += filter;
107 if(phiCut)
108 objectName += "phicut";
109 if(run) {
110 objectName += "_";
111 objectName += run;
112 }
113 if(endName)
114 objectName += endName;
115
116 cout << "Getting object: " << objectName.Data() << endl;
117
118 return (AliHighPtDeDxBase*)(file->Get(objectName.Data()));
119}
120
121//______________________________________________________________________
122TFile* FindFileFresh(const Char_t* fileName)
123{
124 // Find file
125 TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(fileName);
126 if(file) {
127 file->Close();
128 delete file;
129 }
130
131 file = TFile::Open(fileName, "READ");
132
133 if(!file)
134 cout << "File : " << fileName << " was not found" << endl;
135
136 return file;
137}
138
139//______________________________________________________________________
140TFile* FindFile(const Char_t* fileName)
141{
142 // Find file
143 TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(fileName);
144 if(file) {
145 return file;
146 }
147
148 file = TFile::Open(fileName, "READ");
149
150 if(!file)
151 cout << "File : " << fileName << " was not found" << endl;
152
153 return file;
154}
155
156//______________________________________________________________________
157void CutHistogram(TH1* hist, Double_t xMin, Double_t xMax)
158{
159 const Int_t n = hist->GetNbinsX();
160
161 for(Int_t bin = 1; bin <= n; bin++) {
162
163 Float_t x = hist->GetXaxis()->GetBinCenter(bin);
164 if(x < xMin) {
165 hist->SetBinContent(bin, 0);
166 hist->SetBinError(bin, 0);
167 } else if(x > xMax) {
168 hist->SetBinContent(bin, 0);
169 hist->SetBinError(bin, 0);
170 }
171
172 }
173}
174
175//______________________________________________________________________
176void SetHistError(TH1* hist, Double_t error)
177{
178 const Int_t n = hist->GetNbinsX();
179
180 for(Int_t bin = 1; bin <= n; bin++) {
181
182 // Float_t x = hist->GetXaxis()->GetBinCenter(bin);
183 hist->SetBinError(bin, error);
184 }
185}
186
187//______________________________________________________________________
188void CreateDir(const Char_t* dirName)
189{
190 TString pwd(gSystem->pwd());
191 gSystem->cd(pwd.Data());
192
193 if(gSystem->cd(dirName)) {
194 gSystem->cd(pwd.Data());
195 } else {
196 gSystem->mkdir(dirName, kTRUE); // kTRUE means recursive
197 }
198}