No more Isajet
[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
8dc823cc 40const char* AliFMDAnaParameters::fgkBackgroundCorrection = "FMD/Calib/Background";
41const char* AliFMDAnaParameters::fgkEnergyDists = "FMD/Calib/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),
58 fBackgroundArray(0),
59 fEdistArray(0)
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
83 fBackgroundArray = dynamic_cast<TObjArray*>(background->GetObject());
84 if (!fBackgroundArray) AliFatal("Invalid background object from CDB");
85
86}
87//____________________________________________________________________
88
89void AliFMDAnaParameters::InitEnergyDists() {
90
91 AliCDBEntry* edist = GetEntry(fgkEnergyDists);
92 if (!edist) return;
93
94 fEdistArray = dynamic_cast<TObjArray*>(edist->GetObject());
95
96 if (!fEdistArray) AliFatal("Invalid background object from CDB");
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
107 TAxis* refAxis = GetRefAxis();
108
109 return refAxis->GetXmax();
110}
111
112//____________________________________________________________________
113Int_t AliFMDAnaParameters::GetNvtxBins() {
114
115 if(!fIsInit) {
116 AliWarning("Not initialized yet. Call Init() to remedy");
117 return -1;
118 }
119
120 TAxis* refAxis = GetRefAxis();
121
122 return refAxis->GetNbins();
123}
124//____________________________________________________________________
125TH1F* AliFMDAnaParameters::GetEnergyDistribution(Int_t det, Char_t ring) {
126
8dc823cc 127 TObjArray* detArray = (TObjArray*)fEdistArray->At(det);
128 Int_t ringNumber = (ring == 'I' ? 0 : 1);
129 TH1F* hEnergyDist = (TH1F*)detArray->At(ringNumber);
130 return hEnergyDist;
131}
132//____________________________________________________________________
133Float_t AliFMDAnaParameters::GetSigma(Int_t det, Char_t ring) {
134
d7346eed 135 if(!fIsInit) {
136 AliWarning("Not initialized yet. Call Init() to remedy");
137 return 0;
138 }
139
8dc823cc 140 TH1F* hEnergyDist = GetEnergyDistribution(det,ring);
141 TF1* landau = hEnergyDist->GetFunction("landau");
142 Float_t sigma = landau->GetParameter(2);
143 return sigma;
144}
145
146
147//____________________________________________________________________
148Float_t AliFMDAnaParameters::GetMPV(Int_t det, Char_t ring) {
149
150 if(!fIsInit) {
151 AliWarning("Not initialized yet. Call Init() to remedy");
152 return 0;
153 }
154
155 TH1F* hEnergyDist = GetEnergyDistribution(det,ring);
156 TF1* landau = hEnergyDist->GetFunction("landau");
157 Float_t MPV = landau->GetParameter(1);
158 return MPV;
d7346eed 159}
160//____________________________________________________________________
8dc823cc 161
162
163
d7346eed 164TH2F* AliFMDAnaParameters::GetBackgroundCorrection(Int_t det,
165 Char_t ring,
166 Int_t vtxbin) {
167
168 if(!fIsInit) {
169 AliWarning("Not initialized yet. Call Init() to remedy");
170 return 0;
171 }
172 if(vtxbin > GetNvtxBins()) {
173 AliWarning(Form("No background object for vertex bin %d", vtxbin));
174 return 0;
175 }
176
177 TObjArray* correction = GetBackgroundArray();
178
179 TObjArray* detArray = (TObjArray*)correction->At(det);
180 Int_t ringNumber = (ring == 'I' ? 0 : 1);
181 TObjArray* ringArray = (TObjArray*)detArray->At(ringNumber);
182 TH2F* bgHist = (TH2F*)ringArray->At(vtxbin);
183
184 return bgHist;
185}
186//____________________________________________________________________
187TAxis* AliFMDAnaParameters::GetRefAxis() {
188
189 TAxis* refAxis = (TAxis*)fBackgroundArray->At(0);
190
191 return refAxis;
192}
193//____________________________________________________________________
194TObjArray* AliFMDAnaParameters::GetBackgroundArray() {
195
196 TObjArray* correction = (TObjArray*)fBackgroundArray->At(1);
197
198 return correction;
199}
200
201//____________________________________________________________________
202AliCDBEntry* AliFMDAnaParameters::GetEntry(const char* path, Bool_t fatal) const
203{
204 // Get an entry from the CDB or via preprocessor
205 AliCDBEntry* entry = 0;
206 AliCDBManager* cdb = AliCDBManager::Instance();
207 entry = cdb->Get(path);
208
209 if (!entry) {
210 TString msg(Form("No %s found in CDB, perhaps you need to "
211 "use AliFMDCalibFaker?", path));
212 if (fatal) { AliFatal(msg.Data()); }
213 else AliLog::Message(AliLog::kWarning, msg.Data(), "FMD",
214 "AliFMDParameters", "GetEntry", __FILE__,
215 __LINE__);
216 return 0;
217 }
218 return entry;
219}
220
221
222//____________________________________________________________________
223//
224// EOF
225//