Introducing the fixes needed in order to read the old RCU firmware format (v<3) with...
[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>
8dc823cc 32#include <TF1.h>
d7346eed 33
34//====================================================================
35ClassImp(AliFMDAnaParameters)
36#if 0
37 ; // This is here to keep Emacs for indenting the next line
38#endif
39
b82e76e0 40const char* AliFMDAnaParameters::fgkBackgroundCorrection = "FMD/Correction/Background";
41const char* AliFMDAnaParameters::fgkEnergyDists = "FMD/Correction/EnergyDistribution";
d7346eed 42//____________________________________________________________________
43AliFMDAnaParameters* AliFMDAnaParameters::fgInstance = 0;
44
45//____________________________________________________________________
46
47AliFMDAnaParameters*
48AliFMDAnaParameters::Instance()
49{
50 // Get static instance
51 if (!fgInstance) fgInstance = new AliFMDAnaParameters;
52 return fgInstance;
53}
54
55//____________________________________________________________________
56AliFMDAnaParameters::AliFMDAnaParameters() :
57 fIsInit(kFALSE),
b82e76e0 58 fBackground(0),
59 fEnergyDistribution(0)
d7346eed 60{
61
62 // Default constructor
63}
64//____________________________________________________________________
65void AliFMDAnaParameters::Init(Bool_t forceReInit, UInt_t what)
66{
67 // Initialize the parameters manager. We need to get stuff from the
68 // CDB here.
69 if (forceReInit) fIsInit = kFALSE;
70 if (fIsInit) return;
71 if (what & kBackgroundCorrection) InitBackground();
72 if (what & kEnergyDistributions) InitEnergyDists();
73
74 fIsInit = kTRUE;
75}
76//____________________________________________________________________
77
78void AliFMDAnaParameters::InitBackground() {
79
80 AliCDBEntry* background = GetEntry(fgkBackgroundCorrection);
81 if (!background) return;
82
b82e76e0 83 fBackground = dynamic_cast<AliFMDAnaCalibBackgroundCorrection*>(background->GetObject());
84 if (!fBackground) AliFatal("Invalid background object from CDB");
d7346eed 85
86}
87//____________________________________________________________________
88
89void AliFMDAnaParameters::InitEnergyDists() {
90
91 AliCDBEntry* edist = GetEntry(fgkEnergyDists);
92 if (!edist) return;
93
b82e76e0 94 fEnergyDistribution = dynamic_cast<AliFMDAnaCalibEnergyDistribution*>(edist->GetObject());
d7346eed 95
b82e76e0 96 if (!fEnergyDistribution) AliFatal("Invalid background object from CDB");
d7346eed 97
98}
99//____________________________________________________________________
100Float_t AliFMDAnaParameters::GetVtxCutZ() {
101
102 if(!fIsInit) {
103 AliWarning("Not initialized yet. Call Init() to remedy");
104 return -1;
105 }
106
b82e76e0 107 return fBackground->GetVtxCutZ();
d7346eed 108}
109
110//____________________________________________________________________
111Int_t AliFMDAnaParameters::GetNvtxBins() {
112
113 if(!fIsInit) {
114 AliWarning("Not initialized yet. Call Init() to remedy");
115 return -1;
116 }
117
b82e76e0 118 return fBackground->GetNvtxBins();
d7346eed 119}
120//____________________________________________________________________
5754671c 121TH1F* AliFMDAnaParameters::GetEnergyDistribution(Int_t det, Char_t ring, Float_t eta) {
d7346eed 122
5754671c 123 return fEnergyDistribution->GetEnergyDistribution(det, ring, eta);
8dc823cc 124}
125//____________________________________________________________________
5754671c 126Float_t AliFMDAnaParameters::GetSigma(Int_t det, Char_t ring, Float_t eta) {
8dc823cc 127
d7346eed 128 if(!fIsInit) {
129 AliWarning("Not initialized yet. Call Init() to remedy");
130 return 0;
131 }
132
5754671c 133 TH1F* hEnergyDist = GetEnergyDistribution(det,ring, eta);
134 TF1* fitFunc = hEnergyDist->GetFunction("FMDfitFunc");
135 if(!fitFunc) {
136 AliWarning(Form("No function for FMD%d%c, eta %f",det,ring,eta));
137 return 1024;
138 }
139 Float_t sigma = fitFunc->GetParameter(2);
8dc823cc 140 return sigma;
141}
142
143
144//____________________________________________________________________
5754671c 145Float_t AliFMDAnaParameters::GetMPV(Int_t det, Char_t ring, Float_t eta) {
8dc823cc 146
147 if(!fIsInit) {
148 AliWarning("Not initialized yet. Call Init() to remedy");
149 return 0;
150 }
151
5754671c 152 TH1F* hEnergyDist = GetEnergyDistribution(det,ring,eta);
153 TF1* fitFunc = hEnergyDist->GetFunction("FMDfitFunc");
154 if(!fitFunc) {
155 AliWarning(Form("No function for FMD%d%c, eta %f",det,ring,eta));
156 return 1024;
157 }
158
159 Float_t MPV = fitFunc->GetParameter(1);
8dc823cc 160 return MPV;
d7346eed 161}
162//____________________________________________________________________
5754671c 163Float_t AliFMDAnaParameters::Get2MIPWeight(Int_t det, Char_t ring, Float_t eta) {
164
165 if(!fIsInit) {
166 AliWarning("Not initialized yet. Call Init() to remedy");
167 return 0;
168 }
169
170 TH1F* hEnergyDist = GetEnergyDistribution(det,ring,eta);
171 TF1* fitFunc = hEnergyDist->GetFunction("FMDfitFunc");
172 if(!fitFunc) return 0;
173 Float_t TwoMIPweight = fitFunc->GetParameter(3);
174
175
176
177 if(TwoMIPweight < 1e-05)
178 TwoMIPweight = 0;
179
180 return TwoMIPweight;
181}
182//____________________________________________________________________
183Float_t AliFMDAnaParameters::Get3MIPWeight(Int_t det, Char_t ring, Float_t eta) {
184
185 if(!fIsInit) {
186 AliWarning("Not initialized yet. Call Init() to remedy");
187 return 0;
188 }
189
190 TH1F* hEnergyDist = GetEnergyDistribution(det,ring,eta);
191 TF1* fitFunc = hEnergyDist->GetFunction("FMDfitFunc");
192 if(!fitFunc) return 0;
193 Float_t ThreeMIPweight = fitFunc->GetParameter(4);
194
195 if(ThreeMIPweight < 1e-05)
196 ThreeMIPweight = 0;
197
198 Float_t TwoMIPweight = fitFunc->GetParameter(3);
199
200 if(TwoMIPweight < 1e-05)
201 ThreeMIPweight = 0;
202
203 return ThreeMIPweight;
204}
205//____________________________________________________________________
206Int_t AliFMDAnaParameters::GetNetaBins() {
207 return GetBackgroundCorrection(1,'I',0)->GetNbinsX();
208
209}
210//____________________________________________________________________
211Float_t AliFMDAnaParameters::GetEtaMin() {
8dc823cc 212
5754671c 213 return GetBackgroundCorrection(1,'I',0)->GetXaxis()->GetXmin();
214}
215//____________________________________________________________________
216Float_t AliFMDAnaParameters::GetEtaMax() {
217
218return GetBackgroundCorrection(1,'I',0)->GetXaxis()->GetXmax();
8dc823cc 219
5754671c 220}
221//____________________________________________________________________
8dc823cc 222
d7346eed 223TH2F* AliFMDAnaParameters::GetBackgroundCorrection(Int_t det,
224 Char_t ring,
225 Int_t vtxbin) {
b82e76e0 226
d7346eed 227 if(!fIsInit) {
228 AliWarning("Not initialized yet. Call Init() to remedy");
229 return 0;
230 }
b82e76e0 231
232
233
234 if(vtxbin > fBackground->GetNvtxBins()) {
d7346eed 235 AliWarning(Form("No background object for vertex bin %d", vtxbin));
236 return 0;
237 }
238
b82e76e0 239 return fBackground->GetBgCorrection(det,ring,vtxbin);
d7346eed 240}
d7346eed 241
242//____________________________________________________________________
243AliCDBEntry* AliFMDAnaParameters::GetEntry(const char* path, Bool_t fatal) const
244{
245 // Get an entry from the CDB or via preprocessor
246 AliCDBEntry* entry = 0;
247 AliCDBManager* cdb = AliCDBManager::Instance();
248 entry = cdb->Get(path);
249
250 if (!entry) {
251 TString msg(Form("No %s found in CDB, perhaps you need to "
252 "use AliFMDCalibFaker?", path));
253 if (fatal) { AliFatal(msg.Data()); }
254 else AliLog::Message(AliLog::kWarning, msg.Data(), "FMD",
255 "AliFMDParameters", "GetEntry", __FILE__,
256 __LINE__);
257 return 0;
258 }
259 return entry;
260}
261
262
263//____________________________________________________________________
264//
265// EOF
266//