]> git.uio.no Git - u/mrichter/AliRoot.git/blob - OADB/AliOADBPWG2Spectra.cxx
chaged template histo in AliOADBPWG2Spectra
[u/mrichter/AliRoot.git] / OADB / AliOADBPWG2Spectra.cxx
1 #include "AliOADBPWG2Spectra.h"
2 #include "TNamed.h"
3 #include "TString.h"
4 #include "TH1D.h"
5 #include "TObject.h"
6 #include "TList.h"
7 #include "AliAnalysisManager.h"
8 #include "TBrowser.h"
9 #include "AliLog.h"
10
11 ClassImp(AliOADBPWG2Spectra)
12
13 const char * AliOADBPWG2Spectra::fDetectorNames[] = {"ITS", "ITSTPC", "TPC", "TOF", "TOFTPC"};
14 const char * AliOADBPWG2Spectra::fPidTypeNames[]  = {"GaussFit", "NSigma", "Bayes", "Kinks"};
15 const char * AliOADBPWG2Spectra::fChargeTags[]    = {"Pos", "Neg"};
16 const char * AliOADBPWG2Spectra::fParticleNames[] = {"Pion", "Kaon", "Proton"};
17
18
19 AliOADBPWG2Spectra::AliOADBPWG2Spectra():
20 TNamed("Dummy", "OADB Object for PWG2 Spectra" ), fHistos(0)
21 {
22   // ctor
23   
24
25
26 }
27 AliOADBPWG2Spectra::AliOADBPWG2Spectra(char* name) :
28 TNamed(name, "OADB Object for PWG2 Spectra" ), fHistos(0) 
29
30 {
31   // ctor
32   // name is appended to all histos (e.g. "Corrected")
33
34   Init();
35
36 }
37
38 AliOADBPWG2Spectra::~AliOADBPWG2Spectra() {
39   // dtor
40   if(fHistos) delete fHistos;
41 }
42
43 void AliOADBPWG2Spectra::Init() {
44   fHistos = new TList();
45 }
46
47
48 const char * AliOADBPWG2Spectra::GetOADBPWG2SpectraFileName()  {
49   // get file name to the OADB
50   static TString filename;
51   filename.Form("%s/PWG2/SPECTRA/spectraResults.root", AliAnalysisManager::GetOADBPath()); 
52   return filename.Data();
53
54 }
55 const char * AliOADBPWG2Spectra::GetHistoName(EPWG2SpectraDetector det, EPWG2SpectraPIDType pidType, EPWG2SpectraParticle part, 
56                                                      EPWG2SpectraCharge charge, const char * centrTag, Int_t centrBin) {
57
58   // Returns histogram name
59   // h[Name]_[Detector(s)]_[PIDType]_[Particle]_[Pos|Neg]_[MultiplicityOrCentralityIndex]
60   // where "name" is the name of this container
61
62   static TString histoName;
63   if (centrTag)
64     histoName.Form("h%s_%s_%s_%s_%s_%s_%d", GetName(), fDetectorNames[det], fPidTypeNames[pidType], fParticleNames[part], fChargeTags[charge], centrTag, centrBin);
65   else 
66     histoName.Form("h%s_%s_%s_%s_%s",       GetName(), fDetectorNames[det], fPidTypeNames[pidType], fParticleNames[part], fChargeTags[charge]);
67
68   return histoName.Data();
69 }
70
71 TH1D * AliOADBPWG2Spectra::GetHisto(EPWG2SpectraDetector det, EPWG2SpectraPIDType pidType, EPWG2SpectraParticle part, 
72                                     EPWG2SpectraCharge charge, const char * centrTag, Int_t centrBin){
73
74   // Get an histogram from the list
75   const char * name = GetHistoName(det,pidType,part,charge,centrTag,centrBin);
76   TH1D * h = (TH1D*) fHistos->FindObject(name);
77   return h;
78
79 }
80
81 void  AliOADBPWG2Spectra::AddHisto(TH1D * h, EPWG2SpectraDetector det, EPWG2SpectraPIDType pidType, EPWG2SpectraParticle part, 
82                                     EPWG2SpectraCharge charge, const char * centrTag, Int_t centrBin) {
83   // Add a histogram to the list
84   // Rename it if necessary
85   const char * name = GetHistoName(det,pidType,part,charge,centrTag,centrBin);
86   TH1D * hold = (TH1D*) fHistos->FindObject(name);
87   if (hold) fHistos->Remove(hold);
88   delete hold;
89   if(strcmp(h->GetName(),name)){
90     AliError(Form("Histogram namws are not consinstent %s-%s, resetting", h->GetName(),name));
91     h->SetName(name); 
92   }
93   fHistos->Add(h);
94
95
96 }
97
98 TH1D * AliOADBPWG2Spectra::BookHisto(EPWG2SpectraDetector det, EPWG2SpectraPIDType pidType, EPWG2SpectraParticle part, 
99                                      EPWG2SpectraCharge charge, const char * centrTag, Int_t centrBin) {
100
101   // book a histogram according to the template. All the histograms
102   // should have the same binning (if possible/reasonable) to
103   // facilitate the compoarison and the combination
104
105   const Float_t templBins[] = {0.05,0.1,0.12,0.14,0.16,0.18,0.20,0.25,0.30,0.35,0.4,0.45,0.5,0.55,0.6,0.65,0.7,0.75,0.8,0.85,0.9,0.95,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,2,2.2,2.4,2.6, 2.7, 2.8, 2.9, 3.0, 3.2, 3.4, 3.6, 3.8, 4.0, 4.2, 4.4, 4.6, 4.8, 5.0};
106   Int_t nbinsTempl=48;
107   const char * name = GetHistoName(det,pidType,part,charge,centrTag,centrBin);
108   TH1D * h = new TH1D(name, name, nbinsTempl, templBins);
109   return h;
110
111 }
112
113 void AliOADBPWG2Spectra::Browse(TBrowser *b)
114 {
115   // Browse this object.
116    // If b=0, there is no Browse call TObject::Browse(0) instead.
117    //         This means TObject::Inspect() will be invoked indirectly
118
119
120   if (b) {
121     b->Add(fHistos);        
122   }     
123    else
124       TObject::Browse(b);
125 }