Renamed AliFMDCorrDeadChannels to AliFMDCorrAcceptance
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / AliFMDCorrAcceptance.cxx
CommitLineData
1298ee54 1//
8973b4ed 2// This class contains the acceptance correction due to dead channels
1298ee54 3//
4//
8973b4ed 5#include "AliFMDCorrAcceptance.h"
1298ee54 6#include <TBrowser.h>
7#include <TH2D.h>
8#include <AliLog.h>
9#include <iostream>
10
11//____________________________________________________________________
8973b4ed 12AliFMDCorrAcceptance::AliFMDCorrAcceptance()
1298ee54 13 : fRingArray(),
14 fVertexAxis(0,0,0)
15{
16 //
17 // Default constructor
18 //
19 fRingArray.SetOwner(kTRUE);
20 fRingArray.SetName("rings");
21 fVertexAxis.SetName("vtxAxis");
22 fVertexAxis.SetTitle("v_{z} [cm]");
23
24}
25//____________________________________________________________________
8973b4ed 26AliFMDCorrAcceptance::AliFMDCorrAcceptance(const
27 AliFMDCorrAcceptance& o)
1298ee54 28 : TObject(o),
29 fRingArray(o.fRingArray),
30 fVertexAxis(o.fVertexAxis.GetNbins(), o.fVertexAxis.GetXmin(),
31 o.fVertexAxis.GetXmax())
32{
33 //
34 // Copy constructor
35 //
36 // Parameters:
37 // o Object to copy from
38 //
39 fVertexAxis.SetName("vtxAxis");
40 fVertexAxis.SetTitle("v_{z} [cm]");
41}
42//____________________________________________________________________
8973b4ed 43AliFMDCorrAcceptance::~AliFMDCorrAcceptance()
1298ee54 44{
45 //
46 // Destructor
47 //
48 //
49 fRingArray.Clear();
50}
51//____________________________________________________________________
8973b4ed 52AliFMDCorrAcceptance&
53AliFMDCorrAcceptance::operator=(const AliFMDCorrAcceptance& o)
1298ee54 54{
55 //
56 // Assignment operator
57 //
58 // Parameters:
59 // o Object to assign from
60 //
61 // Return:
62 // Reference to this object
63 //
64 fRingArray = o.fRingArray;
65 SetVertexAxis(o.fVertexAxis);
66
67 return *this;
68}
69//____________________________________________________________________
70TH2D*
8973b4ed 71AliFMDCorrAcceptance::GetCorrection(UShort_t d, Char_t r, Double_t v) const
1298ee54 72{
73 //
8973b4ed 74 // Get the acceptance correction @f$ a_{r,v}@f$
1298ee54 75 //
76 // Parameters:
77 // d Detector number (1-3)
78 // r Ring identifier (I or O)
79 // v Primary interaction point @f$z@f$ coordinate
80 //
81 // Return:
8973b4ed 82 // The correction @f$ a_{r,v}@f$
1298ee54 83 //
84 Int_t b = FindVertexBin(v);
85 if (b <= 0) return 0;
86 return GetCorrection(d, r, UShort_t(b));
87}
88//____________________________________________________________________
89TH2D*
8973b4ed 90AliFMDCorrAcceptance::GetCorrection(UShort_t d, Char_t r, UShort_t b) const
1298ee54 91{
92 //
8973b4ed 93 // Get the acceptance correction @f$ a_{r,v}@f$
1298ee54 94 //
95 // Parameters:
96 // d Detector number (1-3)
97 // r Ring identifier (I or O)
98 // b Bin corresponding to the primary interaction point
99 // @f$z@f$ coordinate (1 based)
100 //
101 // Return:
8973b4ed 102 // The correction @f$ a_{r,v}@f$
1298ee54 103 //
104 TObjArray* ringArray = GetRingArray(d, r);
105 if (!ringArray) return 0;
106
107 if (b <= 0 || b > ringArray->GetEntriesFast()) {
108 AliWarning(Form("vertex bin %d out of range [1,%d]",
109 b, ringArray->GetEntriesFast()));
110 return 0;
111 }
112
113 TObject* o = ringArray->At(b-1);
114 if (!o) {
115 AliWarning(Form("No dead channels map found for FMD%d%c in vertex bin %d",
116 d,r,b));
117 return 0;
118 }
119 return static_cast<TH2D*>(o);
120}
121
122//____________________________________________________________________
123Int_t
8973b4ed 124AliFMDCorrAcceptance::FindVertexBin(Double_t v) const
1298ee54 125{
126 //
127 // Find the vertex bin that corresponds to the passed vertex
128 //
129 // Parameters:
130 // vertex The interaction points @f$z@f$-coordinate
131 //
132 // Return:
133 // Vertex bin in @f$[1,N_{\mbox{vertex}}]@f$ or negative if
134 // out of range
135 //
136 if (fVertexAxis.GetNbins() <= 0) {
137 AliWarning("No vertex array defined");
138 return 0;
139 }
140 Int_t bin = const_cast<TAxis&>(fVertexAxis).FindBin(v);
141 if (bin <= 0 || bin > fVertexAxis.GetNbins()) {
142 AliWarning(Form("vertex %+8.4f out of range [%+8.4f,%+8.4f]",
143 v, fVertexAxis.GetXmin(), fVertexAxis.GetXmax()));
144 return 0;
145 }
146 return bin;
147}
148//____________________________________________________________________
149Int_t
8973b4ed 150AliFMDCorrAcceptance::GetRingIndex(UShort_t d, Char_t r) const
1298ee54 151{
152 //
153 // Get the index corresponding to the given ring
154 //
155 // Parameters:
156 // d Detector
157 // r Ring
158 //
159 // Return:
160 // Index (0 based) or negative in case of errors
161 //
162 switch (d) {
163 case 1: return 0;
164 case 2: return (r == 'I' || r == 'i' ? 1 : 2); break;
165 case 3: return (r == 'I' || r == 'i' ? 3 : 4); break;
166 }
167 AliWarning(Form("Index for FMD%d%c not found", d, r));
168 return -1;
169}
170//____________________________________________________________________
171TObjArray*
8973b4ed 172AliFMDCorrAcceptance::GetRingArray(UShort_t d, Char_t r) const
1298ee54 173{
174 //
175 // Get the ring array corresponding to the specified ring
176 //
177 // Parameters:
178 // d Detector
179 // r Ring
180 //
181 // Return:
182 // Pointer to ring array, or null in case of problems
183 //
184 Int_t idx = GetRingIndex(d,r);
185 if (idx < 0) return 0;
186
187 TObject* o = fRingArray.At(idx);
188 if (!o) {
189 AliWarning(Form("No array found for FMD%d%c", d, r));
190 return 0;
191 }
192
193 return static_cast<TObjArray*>(o);
194}
195//____________________________________________________________________
196TObjArray*
8973b4ed 197AliFMDCorrAcceptance::GetOrMakeRingArray(UShort_t d, Char_t r)
1298ee54 198{
199 //
200 // Get the ring array corresponding to the specified ring
201 //
202 // Parameters:
203 // d Detector
204 // r Ring
205 //
206 // Return:
207 // Pointer to ring array, or newly created container
208 //
209 Int_t idx = GetRingIndex(d,r);
210 if (idx < 0) return 0;
211
212 TObject* o = fRingArray.At(idx);
213 if (!o) {
214 TObjArray* a = new TObjArray(fVertexAxis.GetNbins());
215 a->SetName(Form("FMD%d%c", d, r));
216 a->SetOwner(kTRUE);
217 fRingArray.AddAtAndExpand(a, idx);
218 return a;
219 }
220
221 return static_cast<TObjArray*>(fRingArray.At(idx));
222}
223
224//____________________________________________________________________
225Bool_t
8973b4ed 226AliFMDCorrAcceptance::SetCorrection(UShort_t d, Char_t r,
227 UShort_t b, TH2D* h)
1298ee54 228{
229 //
8973b4ed 230 // Set the acceptance correction @f$ a_{r,v}(\eta)@f$
1298ee54 231 // Note, that the object takes ownership of the passed pointer.
232 //
233 // Parameters:
234 // d Detector number (1-3)
235 // r Ring identifier (I or O)
236 // b Bin corresponding to the primary interaction point
237 // @f$z@f$ coordinate (1 based)
8973b4ed 238 // h @f$ a_{r,v}(\eta)@f$
1298ee54 239 //
240 // Return:
241 // true if operation succeeded
242 //
243 TObjArray* ringArray = GetOrMakeRingArray(d, r);
244 if (!ringArray) return false;
245
246 if (b <= 0 || b > fVertexAxis.GetNbins()) {
247 AliWarning(Form("Vertex bin %3d out of range [1,%3d]",
248 b, fVertexAxis.GetNbins()));
249 return false;
250 }
251 h->SetName(Form("FMD%d%c_vtxbin%03d", d, r, b));
8973b4ed 252 h->SetTitle(Form("Acceptance correction for FMD%d%c "
1298ee54 253 "in vertex bin %d [%+8.4f,%+8.4f]",
254 d, r, b, fVertexAxis.GetBinLowEdge(b),
255 fVertexAxis.GetBinUpEdge(b)));
256 h->SetXTitle("#eta");
257 h->SetYTitle("dN_{ch}/d#eta / sum_i N_{ch,i}");
258 h->SetFillStyle(3001);
259 h->SetDirectory(0);
260 h->SetStats(0);
261 ringArray->AddAtAndExpand(h, b-1);
262 return kTRUE;
263}
264//____________________________________________________________________
265Bool_t
8973b4ed 266AliFMDCorrAcceptance::SetCorrection(UShort_t d, Char_t r,
267 Double_t v, TH2D* h)
1298ee54 268{
269 //
8973b4ed 270 // Set the acceptance correction @f$ a_{r,v}(\eta)@f$.
1298ee54 271 // Note, that the object takes ownership of the passed pointer.
272 //
273 // Parameters:
274 // d Detector number (1-3)
275 // r Ring identifier (I or O)
276 // v Primary interaction point @f$z@f$ coordinate
8973b4ed 277 // h @f$ a_{r,v}(\eta)@f$
1298ee54 278 //
279 // Return:
280 // true if operation succeeded
281 //
282 Int_t b = FindVertexBin(v);
283 if (b <= 0 || b > fVertexAxis.GetNbins()) {
284 AliWarning(Form("Vertex %+8.4f out of range [%+8.4f,%+8.4f]",
285 v, fVertexAxis.GetXmin(), fVertexAxis.GetXmax()));
286 return false;
287 }
288 return SetCorrection(d, r, UShort_t(b), h);
289}
290//____________________________________________________________________
291void
8973b4ed 292AliFMDCorrAcceptance::Browse(TBrowser* b)
1298ee54 293{
294 //
295 // Browse this object in the browser
296 //
297 // Parameters:
298 // b
299 //
300 b->Add(&fRingArray);
301 b->Add(&fVertexAxis);
302}
303//____________________________________________________________________
304void
8973b4ed 305AliFMDCorrAcceptance::Print(Option_t* option) const
1298ee54 306{
307 //
308 // Print this object
309 //
310 // Parameters:
311 // option
312 //
8973b4ed 313 std::cout << "Acceptance correction due to dead channels" << std::endl;
1298ee54 314 fRingArray.Print(option);
315 fVertexAxis.Print(option);
316}
317
318//____________________________________________________________________
319//
320// EOF
321//