]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/SPECTRA/IdentifiedHighPt/macros/my_tools.C
Merge branch 'master', remote branch 'origin' into TPCdev
[u/mrichter/AliRoot.git] / PWGLF / SPECTRA / IdentifiedHighPt / macros / my_tools.C
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
11 using namespace std;
12
13
14
15 //_____________________________________________________________________________
16
17
18 AliHighPtDeDxBase* GetObject(TFile* file, Int_t filter, Bool_t phiCut, 
19                              Int_t run, Bool_t etaAbs, 
20                              Int_t etaLow, Int_t etaHigh, const Char_t* baseName="filter",
21                              const Char_t* endName=0);
22
23 TFile* FindFileFresh(const Char_t* fileName);
24 TFile* FindFile(const Char_t* fileName);
25 void CutHistogram(TH1* hist, Double_t xMin, Double_t xMax);
26 void SetHistError(TH1* hist, Double_t error);
27 void CreateDir(const Char_t* dirName);
28
29 //___________________________________________________________________________
30 AliHighPtDeDxBase* GetObject(TFile* file, Int_t filter, Bool_t phiCut, Int_t run, Bool_t etaAbs, 
31                              Int_t etaLow, Int_t etaHigh,
32                              const Char_t* baseName, const Char_t* endName)
33 {
34   TString objectName(baseName);
35   if(filter>0)
36   objectName += filter;
37   if(phiCut)
38     objectName += "phicut";
39   if(run) {
40     objectName += "_";
41     objectName += run;
42   }
43   if(etaAbs) {
44     objectName += "etaabs";
45     objectName += etaLow;
46     objectName += etaHigh;
47   }
48
49   if(endName)
50     objectName += endName;
51
52   cout << "Getting object: " << objectName.Data() << endl;
53
54   return (AliHighPtDeDxBase*)(file->Get(objectName.Data()));
55 }
56
57 //______________________________________________________________________
58 TFile* FindFileFresh(const Char_t* fileName)
59 {
60   // Find file
61   TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(fileName);
62   if(file) {
63     file->Close();
64     delete file;
65   }
66
67   file = TFile::Open(fileName, "READ");
68
69   if(!file)
70     cout << "File : " << fileName << " was not found" << endl;
71
72   return file;
73 }
74
75 //______________________________________________________________________
76 TFile* FindFile(const Char_t* fileName)
77 {
78   // Find file
79   TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(fileName);
80   if(file) {
81     return file;
82   }
83
84   file = TFile::Open(fileName, "READ");
85
86   if(!file)
87     cout << "File : " << fileName << " was not found" << endl;
88
89   return file;
90 }
91
92 //______________________________________________________________________
93 void CutHistogram(TH1* hist, Double_t xMin, Double_t xMax)
94 {
95   const Int_t n = hist->GetNbinsX();
96   
97   for(Int_t bin = 1; bin <= n; bin++) {
98     
99     Float_t x = hist->GetXaxis()->GetBinCenter(bin);
100     if(x < xMin) {
101       hist->SetBinContent(bin, 0);
102       hist->SetBinError(bin, 0);
103     } else if(x > xMax) {
104       hist->SetBinContent(bin, 0);
105       hist->SetBinError(bin, 0);
106     }
107
108   }
109 }
110
111 //______________________________________________________________________
112 void SetHistError(TH1* hist, Double_t error)
113 {
114   const Int_t n = hist->GetNbinsX();
115   
116   for(Int_t bin = 1; bin <= n; bin++) {
117     
118     //    Float_t x = hist->GetXaxis()->GetBinCenter(bin);
119     hist->SetBinError(bin, error);
120   }
121 }
122
123 //______________________________________________________________________
124 void CreateDir(const Char_t* dirName)
125 {
126   TString pwd(gSystem->pwd());
127   gSystem->cd(pwd.Data());
128   
129   if(gSystem->cd(dirName)) {
130     gSystem->cd(pwd.Data());
131   } else {
132     gSystem->mkdir(dirName, kTRUE); // kTRUE means recursive
133   }
134 }