]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/AliFMDCorrAcceptance.cxx
Added 2012 geom
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / AliFMDCorrAcceptance.cxx
1 //
2 // This class contains the acceptance correction due to dead channels 
3 // 
4 //
5 #include "AliFMDCorrAcceptance.h"
6 #include <TBrowser.h>
7 #include <TH2D.h>
8 #include <AliLog.h>
9 #include <iostream>
10
11 //____________________________________________________________________
12 AliFMDCorrAcceptance::AliFMDCorrAcceptance()
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 //____________________________________________________________________
26 AliFMDCorrAcceptance::AliFMDCorrAcceptance(const 
27                                                AliFMDCorrAcceptance& o)
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 //____________________________________________________________________
43 AliFMDCorrAcceptance::~AliFMDCorrAcceptance()
44 {
45   //
46   // Destructor 
47   // 
48   //
49   fRingArray.Clear();
50 }
51 //____________________________________________________________________
52 AliFMDCorrAcceptance&
53 AliFMDCorrAcceptance::operator=(const AliFMDCorrAcceptance& o)
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 //____________________________________________________________________
70 TH2D*
71 AliFMDCorrAcceptance::GetCorrection(UShort_t d, Char_t r, Double_t v) const
72 {
73   // 
74   // Get the acceptance correction @f$ a_{r,v}@f$ 
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:
82   //    The correction @f$ a_{r,v}@f$ 
83   //
84   Int_t b = FindVertexBin(v);
85   if (b <= 0) return 0;
86   return GetCorrection(d, r, UShort_t(b));
87 }
88 //____________________________________________________________________
89 TH2D*
90 AliFMDCorrAcceptance::GetCorrection(UShort_t d, Char_t r, UShort_t b) const
91 {
92   // 
93   // Get the acceptance correction @f$ a_{r,v}@f$ 
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:
102   //    The correction @f$ a_{r,v}@f$ 
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 //____________________________________________________________________
123 Int_t
124 AliFMDCorrAcceptance::FindVertexBin(Double_t v) const
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 //____________________________________________________________________
149 Int_t
150 AliFMDCorrAcceptance::GetRingIndex(UShort_t d, Char_t r) const
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 //____________________________________________________________________
171 TObjArray*
172 AliFMDCorrAcceptance::GetRingArray(UShort_t d, Char_t r) const
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 //____________________________________________________________________
196 TObjArray*
197 AliFMDCorrAcceptance::GetOrMakeRingArray(UShort_t d, Char_t r)
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 //____________________________________________________________________
225 Bool_t
226 AliFMDCorrAcceptance::SetCorrection(UShort_t d, Char_t r, 
227                                     UShort_t b, TH2D*  h) 
228 {
229   // 
230   // Set the acceptance correction @f$ a_{r,v}(\eta)@f$ 
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)
238   //    h    @f$ a_{r,v}(\eta)@f$ 
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));
252   h->SetTitle(Form("Acceptance correction for FMD%d%c "
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 //____________________________________________________________________
265 Bool_t
266 AliFMDCorrAcceptance::SetCorrection(UShort_t d, Char_t r, 
267                                     Double_t v, TH2D*  h) 
268 {
269   // 
270   // Set the acceptance correction @f$ a_{r,v}(\eta)@f$.
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  
277   //    h    @f$ a_{r,v}(\eta)@f$ 
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 //____________________________________________________________________
291 void
292 AliFMDCorrAcceptance::Browse(TBrowser* b)
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 //____________________________________________________________________
304 void
305 AliFMDCorrAcceptance::Print(Option_t* option) const
306 {
307   // 
308   // Print this object 
309   // 
310   // Parameters:
311   //    option 
312   //  
313   std::cout << "Acceptance correction due to dead channels" << std::endl;
314   fRingArray.Print(option);
315   fVertexAxis.Print(option);
316 }
317     
318 //____________________________________________________________________
319 //
320 // EOF
321 //