]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FORWARD/analysis2/AliFMDCorrVertexBias.cxx
Renamed
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / AliFMDCorrVertexBias.cxx
1 #include "AliFMDCorrVertexBias.h"
2 #include <TBrowser.h>
3 #include <TH2D.h>
4 #include <AliLog.h>
5 #include <iostream>
6
7 //____________________________________________________________________
8 AliFMDCorrVertexBias::AliFMDCorrVertexBias()
9   : fVertexArray(), 
10     fVertexAxis(0,0,0)
11 {
12   fVertexArray.SetOwner(kTRUE);
13   fVertexArray.SetName("rings");
14   fVertexAxis.SetName("vtxAxis");
15   fVertexAxis.SetTitle("v_{z} [cm]");
16   
17 }
18 //____________________________________________________________________
19 AliFMDCorrVertexBias::AliFMDCorrVertexBias(const AliFMDCorrVertexBias& o)
20   : TObject(o), 
21     fVertexArray(o.fVertexArray), 
22     fVertexAxis(o.fVertexAxis.GetNbins(), o.fVertexAxis.GetXmin(), 
23                 o.fVertexAxis.GetXmax())
24 {
25   fVertexAxis.SetName("vtxAxis");
26   fVertexAxis.SetTitle("v_{z} [cm]");
27 }
28 //____________________________________________________________________
29 AliFMDCorrVertexBias::~AliFMDCorrVertexBias()
30 {
31   fVertexArray.Clear();
32 }
33 //____________________________________________________________________
34 AliFMDCorrVertexBias&
35 AliFMDCorrVertexBias::operator=(const AliFMDCorrVertexBias& o)
36 {
37   fVertexArray        = o.fVertexArray;
38   SetVertexAxis(o.fVertexAxis);
39
40   return *this;
41 }
42 //____________________________________________________________________
43 TH2D*
44 AliFMDCorrVertexBias::GetCorrection(Char_t r, Double_t v) const
45 {
46   Int_t b = FindVertexBin(v);
47   if (b <= 0) return 0;
48   return GetCorrection(r, UShort_t(b));
49 }
50 //____________________________________________________________________
51 TH2D*
52 AliFMDCorrVertexBias::GetCorrection(Char_t r, UShort_t b) const
53 {
54   TObjArray* vertexarray = GetVertexArray(b);
55   if (!vertexarray) return 0;
56
57   Int_t idx = -1;
58   switch (r) { 
59   case 'i': case 'I': idx = 0; break;
60   case 'o': case 'O': idx = 1; break;
61   }
62   if (idx < 0) {
63     AliWarning(Form("Unknown ting type %c, not one of [iIoO]", r));
64     return 0;
65   }
66
67   TObject* o = vertexarray->At(idx);
68   if (!o) { 
69     AliWarning(Form("No vertex bias found for ring type %c in vertex bin %d",
70                     r,b));
71     return 0;
72   }
73   return static_cast<TH2D*>(o);
74 }
75   
76 //____________________________________________________________________
77 Int_t
78 AliFMDCorrVertexBias::FindVertexBin(Double_t v) const
79 {
80   if (fVertexAxis.GetNbins() <= 0) { 
81     AliWarning("No vertex array defined");
82     return 0;
83   }
84   Int_t bin = const_cast<TAxis&>(fVertexAxis).FindBin(v);
85   if (bin <= 0 || bin > fVertexAxis.GetNbins()) { 
86     AliWarning(Form("vertex %+8.4f out of range [%+8.4f,%+8.4f]",
87                     v, fVertexAxis.GetXmin(), fVertexAxis.GetXmax()));
88     return 0;
89   }
90   return bin;
91 }
92 //____________________________________________________________________
93 TObjArray*
94 AliFMDCorrVertexBias::GetVertexArray(UShort_t v) const
95 {
96   if (v <= 0 || v > fVertexAxis.GetNbins()) {
97     AliWarning(Form("vertex bin %d out of range [1,%d]",
98                     v, fVertexAxis.GetNbins()));
99     return 0;
100   }
101   
102   TObject* o = fVertexArray.At(v-1);
103   if (!o) { 
104     AliWarning(Form("No array found for vertex bin %d", v));
105     return 0;
106   }
107
108   return static_cast<TObjArray*>(o);
109 }
110 //____________________________________________________________________
111 TObjArray*
112 AliFMDCorrVertexBias::GetOrMakeVertexArray(UShort_t v)
113 {
114   if (v <= 0 || v > fVertexAxis.GetNbins()) {
115     AliWarning(Form("vertex bin %d out of range [1,%d]",
116                     v, fVertexAxis.GetNbins()));
117     return 0;
118   }
119     
120   TObject* o = fVertexArray.At(v-1);
121   if (!o) { 
122     TObjArray* a = new TObjArray(fVertexAxis.GetNbins());
123     a->SetName(Form("vertexbin%02d", v));
124     a->SetOwner(kTRUE);
125     fVertexArray.AddAtAndExpand(a, v-1);
126     return a;
127   }
128
129   return static_cast<TObjArray*>(fVertexArray.At(v-1));
130 }
131
132 //____________________________________________________________________
133 Bool_t
134 AliFMDCorrVertexBias::SetCorrection(Char_t r, UShort_t b, TH2D*  h) 
135 {
136   TObjArray* vertexarray = GetOrMakeVertexArray(b);
137   if (!vertexarray) return false;
138   
139
140   Int_t idx = -1;
141   switch (r) { 
142   case 'i': case 'I': idx = 0; break;
143   case 'o': case 'O': idx = 1; break;
144   }
145   if (idx < 0) {
146     AliWarning(Form("Unknown ting type %c, not one of [iIoO]", r));
147     return false;
148   }
149   h->SetName(Form("FMDX%c", r));
150   h->SetTitle(Form("Vertex bias correction for %c rings "
151                    "in vertex bin %d [%+8.4f,%+8.4f]", 
152                    r, b, fVertexAxis.GetBinLowEdge(b), 
153                    fVertexAxis.GetBinUpEdge(b)));
154   h->SetXTitle("#eta");
155   h->SetYTitle("#phi [radians]");
156   h->SetZTitle("1/N_{t}#sum_{i}^{N_{tv}} N_{ch,i,primary} / "
157                "1/N_{v}#sum_{i}^{N_{v}} N_{ch,i,primary}");
158   h->SetDirectory(0);
159   h->SetStats(0);
160
161   vertexarray->AddAtAndExpand(h, idx);
162   return kTRUE;
163 }
164 //____________________________________________________________________
165 Bool_t
166 AliFMDCorrVertexBias::SetCorrection(Char_t r, Double_t v, TH2D*  h) 
167 {
168   Int_t b = FindVertexBin(v);
169   if (b <= 0 || b > fVertexAxis.GetNbins()) { 
170     AliWarning(Form("Vertex %+8.4f out of range [%+8.4f,%+8.4f]", 
171                     v, fVertexAxis.GetXmin(), fVertexAxis.GetXmax()));
172     return false;
173   }
174   return SetCorrection(r, UShort_t(b), h);
175 }
176 //____________________________________________________________________
177 void
178 AliFMDCorrVertexBias::Browse(TBrowser* b)
179 {
180   b->Add(&fVertexArray);
181   b->Add(&fVertexAxis);
182 }
183 //____________________________________________________________________
184 void
185 AliFMDCorrVertexBias::Print(Option_t* option) const
186 {
187   std::cout << "Vertex bias correction" << std::endl;
188   fVertexArray.Print(option);
189   fVertexAxis.Print(option);
190 }
191     
192 //____________________________________________________________________
193 //
194 // EOF
195 //