Fixed warnings
[u/mrichter/AliRoot.git] / FMD / analysis / AliFMDAnaParameters.cxx
CommitLineData
d7346eed 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15//
16//The design of this class is based on the AliFMDParameters class. Its purpose
17//is to hold parameters for the analysis such as background correction and
18//fit functions.
19//
20//Author: Hans Hjersing Dalsgaard, NBI, hans.dalsgaard@cern.ch
21//
22
23#include "AliFMDDebug.h" // ALILOG_H
24#include "AliFMDAnaParameters.h" // ALIFMDPARAMETERS_H
25#include <AliCDBManager.h> // ALICDBMANAGER_H
26#include <AliCDBEntry.h> // ALICDBMANAGER_H
27#include <AliLog.h>
28#include <Riostream.h>
29#include <sstream>
30#include <TSystem.h>
31#include <TH2D.h>
32
33//====================================================================
34ClassImp(AliFMDAnaParameters)
35#if 0
36 ; // This is here to keep Emacs for indenting the next line
37#endif
38
39const char* AliFMDAnaParameters::fgkBackgroundCorrection = "FMD/AnalysisCalib/Background";
40const char* AliFMDAnaParameters::fgkEnergyDists = "FMD/AnalysisCalib/EnergyDistribution";
41//____________________________________________________________________
42AliFMDAnaParameters* AliFMDAnaParameters::fgInstance = 0;
43
44//____________________________________________________________________
45
46AliFMDAnaParameters*
47AliFMDAnaParameters::Instance()
48{
49 // Get static instance
50 if (!fgInstance) fgInstance = new AliFMDAnaParameters;
51 return fgInstance;
52}
53
54//____________________________________________________________________
55AliFMDAnaParameters::AliFMDAnaParameters() :
56 fIsInit(kFALSE),
57 fBackgroundArray(0),
58 fEdistArray(0)
59{
60
61 // Default constructor
62}
63//____________________________________________________________________
64void AliFMDAnaParameters::Init(Bool_t forceReInit, UInt_t what)
65{
66 // Initialize the parameters manager. We need to get stuff from the
67 // CDB here.
68 if (forceReInit) fIsInit = kFALSE;
69 if (fIsInit) return;
70 if (what & kBackgroundCorrection) InitBackground();
71 if (what & kEnergyDistributions) InitEnergyDists();
72
73 fIsInit = kTRUE;
74}
75//____________________________________________________________________
76
77void AliFMDAnaParameters::InitBackground() {
78
79 AliCDBEntry* background = GetEntry(fgkBackgroundCorrection);
80 if (!background) return;
81
82 fBackgroundArray = dynamic_cast<TObjArray*>(background->GetObject());
83 if (!fBackgroundArray) AliFatal("Invalid background object from CDB");
84
85}
86//____________________________________________________________________
87
88void AliFMDAnaParameters::InitEnergyDists() {
89
90 AliCDBEntry* edist = GetEntry(fgkEnergyDists);
91 if (!edist) return;
92
93 fEdistArray = dynamic_cast<TObjArray*>(edist->GetObject());
94
95 if (!fEdistArray) AliFatal("Invalid background object from CDB");
96
97}
98//____________________________________________________________________
99Float_t AliFMDAnaParameters::GetVtxCutZ() {
100
101 if(!fIsInit) {
102 AliWarning("Not initialized yet. Call Init() to remedy");
103 return -1;
104 }
105
106 TAxis* refAxis = GetRefAxis();
107
108 return refAxis->GetXmax();
109}
110
111//____________________________________________________________________
112Int_t AliFMDAnaParameters::GetNvtxBins() {
113
114 if(!fIsInit) {
115 AliWarning("Not initialized yet. Call Init() to remedy");
116 return -1;
117 }
118
119 TAxis* refAxis = GetRefAxis();
120
121 return refAxis->GetNbins();
122}
123//____________________________________________________________________
124TH1F* AliFMDAnaParameters::GetEnergyDistribution(Int_t det, Char_t ring) {
125
126 if(!fIsInit) {
127 AliWarning("Not initialized yet. Call Init() to remedy");
128 return 0;
129 }
130
131 TObjArray* detArray = (TObjArray*)fEdistArray->At(det);
132 Int_t ringNumber = (ring == 'I' ? 0 : 1);
133 TH1F* hEnergyDist = (TH1F*)detArray->At(ringNumber);
134 return hEnergyDist;
135}
136//____________________________________________________________________
137TH2F* AliFMDAnaParameters::GetBackgroundCorrection(Int_t det,
138 Char_t ring,
139 Int_t vtxbin) {
140
141 if(!fIsInit) {
142 AliWarning("Not initialized yet. Call Init() to remedy");
143 return 0;
144 }
145 if(vtxbin > GetNvtxBins()) {
146 AliWarning(Form("No background object for vertex bin %d", vtxbin));
147 return 0;
148 }
149
150 TObjArray* correction = GetBackgroundArray();
151
152 TObjArray* detArray = (TObjArray*)correction->At(det);
153 Int_t ringNumber = (ring == 'I' ? 0 : 1);
154 TObjArray* ringArray = (TObjArray*)detArray->At(ringNumber);
155 TH2F* bgHist = (TH2F*)ringArray->At(vtxbin);
156
157 return bgHist;
158}
159//____________________________________________________________________
160TAxis* AliFMDAnaParameters::GetRefAxis() {
161
162 TAxis* refAxis = (TAxis*)fBackgroundArray->At(0);
163
164 return refAxis;
165}
166//____________________________________________________________________
167TObjArray* AliFMDAnaParameters::GetBackgroundArray() {
168
169 TObjArray* correction = (TObjArray*)fBackgroundArray->At(1);
170
171 return correction;
172}
173
174//____________________________________________________________________
175AliCDBEntry* AliFMDAnaParameters::GetEntry(const char* path, Bool_t fatal) const
176{
177 // Get an entry from the CDB or via preprocessor
178 AliCDBEntry* entry = 0;
179 AliCDBManager* cdb = AliCDBManager::Instance();
180 entry = cdb->Get(path);
181
182 if (!entry) {
183 TString msg(Form("No %s found in CDB, perhaps you need to "
184 "use AliFMDCalibFaker?", path));
185 if (fatal) { AliFatal(msg.Data()); }
186 else AliLog::Message(AliLog::kWarning, msg.Data(), "FMD",
187 "AliFMDParameters", "GetEntry", __FILE__,
188 __LINE__);
189 return 0;
190 }
191 return entry;
192}
193
194
195//____________________________________________________________________
196//
197// EOF
198//