AliRoot Core  edcc906 (edcc906)
AliFMDCalibDrawer.cxx
Go to the documentation of this file.
1 #include <AliFMDCalibDrawer.h>
2 #include <TH1.h>
3 #include <TH2.h>
4 #include <TPad.h>
5 #include <TCanvas.h>
6 #include <AliFMDParameters.h>
7 #include <AliCDBManager.h>
8 #include <AliLog.h>
9 // #include <AliFMDCalibPedestal.h>
10 // #include <AliFMDCalibSampleRate.h>
11 // #include <AliFMDCalibStripRange.h>
12 
13 //____________________________________________________________________
14 void
15 AliFMDCalibDrawer::Init(Int_t runNo, const char* ocdb)
16 {
18  cdb->SetRun(runNo);
19  TString db(ocdb);
20  if (db.EqualTo("run", TString::kIgnoreCase) || db.IsNull())
21  cdb->SetDefaultStorageFromRun(runNo);
22  else
23  cdb->SetDefaultStorage(db);
24 
26  pars->Init(kTRUE);
27 }
28 
29 //____________________________________________________________________
30 Double_t
32 {
33  switch (what) {
34  case kPedestal: return 150;
35  case kNoise: return 5;
36  case kGain: return 4;
37  case kDead: return 1.5;
38  case kRate: return 5;
39  case kRange: return 128;
40  case kZeroSuppression: return 10;
41  }
42  return 1024;
43 }
44 //____________________________________________________________________
45 Double_t
47 {
48  switch (what) {
49  case kPedestal: return 0;
50  case kNoise: return 0;
51  case kGain: return 0;
52  case kDead: return -.5;
53  case kRate: return 0;
54  case kRange: return -1;
55  case kZeroSuppression: return -1;
56  }
57  return -1;
58 }
59 
60 //____________________________________________________________________
61 const char*
63 {
64  switch (what) {
65  case kPedestal: return "peds";
66  case kNoise: return "noise";
67  case kGain: return "gain";
68  case kDead: return "dead";
69  case kRate: return "rate";
70  case kRange: return "range";
71  case kZeroSuppression: return "thrs";
72  }
73  return "unknown";
74 }
75 //____________________________________________________________________
76 const char*
78 {
79  switch (what) {
80  case kPedestal: return "Pedestal & noise";
81  case kNoise: return "Noise";
82  case kGain: return "Gain";
83  case kDead: return "Dead map";
84  case kRate: return "Sample rate";
85  case kRange: return "Strip range";
86  case kZeroSuppression: return "ZS threshold";
87  }
88  return "Unknown";
89 }
90 
91 //____________________________________________________________________
92 Int_t
93 AliFMDCalibDrawer::GetRingColor(UShort_t d, Char_t r) const
94 {
95  return ((d == 1 ? kRed : (d == 2 ? kGreen : kBlue))
96  + ((r == 'I' || r == 'i') ? 2 : -3));
97 }
98 //____________________________________________________________________
99 void
101  UShort_t d, Char_t r) const
102 {
103  ret->SetFillColor(GetRingColor(d,r));
104  ret->SetMarkerColor(GetRingColor(d,r));
105  ret->SetLineColor(GetRingColor(d,r));
106  ret->SetFillStyle(3001);
107  ret->SetMarkerStyle(20);
108  ret->SetLineStyle(1);
109  ret->SetStats(0);
110  ret->SetDirectory(0);
111  ret->SetMinimum(GetHistMin(what));
112  ret->SetMaximum(GetHistMax(what));
113 }
114 //____________________________________________________________________
115 TH2D*
116 AliFMDCalibDrawer::Make2D(EWhat what, UShort_t d, Char_t r) const
117 {
118  UShort_t q = (r == 'I' || r == 'i') ? 0 : 1;
119  UShort_t nY = q == 0 ? 20 : 40;
120  UShort_t nX = q == 0 ? 512 : 256;
121  TString n(Form("%s_FMD%d%c", GetHistName(what), d, r));
122  TString t(Form("%s for FMD%d%c", GetHistTitle(what), d, r));
123  TH2D* ret = new TH2D(n, t, nX, 0, nX, nY, 0, nY);
124  ret->SetXTitle("Strip #");
125  ret->SetYTitle("Sector #");
126  ret->SetZTitle(GetHistTitle(what));
127  ret->GetXaxis()->SetNdivisions(1600 + (q == 0 ? 4 : 2),false);
128  ret->GetYaxis()->SetNdivisions(nY, false);
129  SetAttributes(ret, what, d, r);
130  return ret;
131 
132 }
133 
134 //____________________________________________________________________
135 TH1D*
136 AliFMDCalibDrawer::Make1D(EWhat what, UShort_t d, Char_t r, UShort_t s) const
137 {
138  UShort_t q = (r == 'I' || r == 'i') ? 0 : 1;
139  UShort_t nStr = (r == 'I' || r == 'i') ? 512 : 256;
140  TString n(Form("%s_FMD%d%c_%02d", GetHistName(what), d, r, s));
141  TString t(Form("%s for FMD%d%c[%2d]", GetHistTitle(what), d, r, s));
142  TH1D* ret = new TH1D(n, t, nStr, 0, nStr);
143  ret->SetXTitle("Strip #");
144  ret->SetYTitle(GetHistTitle(what));
145  ret->GetXaxis()->SetNdivisions(1600 + (q == 0 ? 4 : 2),false);
146  SetAttributes(ret, what, d, r);
147  return ret;
148 }
149 
150 //____________________________________________________________________
151 void
152 AliFMDCalibDrawer::GetNumber(EWhat what, UShort_t d, Char_t r, UShort_t s,
153  UShort_t t, Double_t& val, Double_t& err) const
154 {
156  err = 0;
157  switch (what) {
158  case kPedestal:
159  val = pars->GetPedestal(d, r, s, t);
160  err = pars->GetPedestalWidth(d, r, s, t);
161  break;
162  case kNoise: val = pars->GetPedestalWidth(d, r, s, t); break;
163  case kGain: val = pars->GetPulseGain(d, r, s, t); break;
164  case kDead: val = pars->IsDead(d, r, s, t) ? 0 : 1; break;
165  case kRate: val = pars->GetSampleRate(d, r, s, t); break;
166  case kRange:
167  val = pars->GetMaxStrip(d,r,s,t);
168  err = pars->GetMinStrip(d,r,s,t);
169  break;
170  case kZeroSuppression: val = pars->GetZeroSuppression(d,r,s,t); break;
171  default:
172  AliError(Form("Unknown quantity: %d - nothing returned", what));
173  break;
174  }
175 }
176 
177 //____________________________________________________________________
178 TH1*
179 AliFMDCalibDrawer::FillRing(EWhat what, UShort_t d, Char_t r) const
180 {
181  if (what == kRate || what == kRange) {
182  TH1D* ret = new TH1D(Form("%s_FMD%d%c", GetHistName(what), d, r),
183  Form("%s for FMD%d%c", GetHistTitle(what), d, r),
184  2, -.5, 1.5);
185  UShort_t nSec = (r == 'I' || r == 'i') ? 20 : 40;
186  ret->GetXaxis()->SetBinLabel(1, Form("Top [%02d-%02d]", 0, nSec/2-1));
187  ret->GetXaxis()->SetBinLabel(2, Form("Bottom [%02d-%02d]",nSec/2-1,nSec-1));
188  ret->SetYTitle(GetHistTitle(what));
189  SetAttributes(ret, what, d, r);
190  if (what == kRate) {
191  ret->SetBarWidth(0.8);
192  ret->SetBarOffset(0.1);
193  }
194  else
195  ret->SetMarkerSize(0);
196  for (UShort_t s = 0; s < ret->GetNbinsX(); s++) {
197  Double_t val;
198  Double_t err;
199  GetNumber(what, d, r, s*(nSec/2), 0, val, err);
200  if (what == kRange) {
201  Double_t min = err;
202  err = (val - err) / 2;
203  val = min + err;
204  }
205  ret->SetBinContent(s+1, val);
206  ret->SetBinError(s+1, err);
207  }
208  return ret;
209  }
210  if (what == kZeroSuppression) {
211  UShort_t nY = (r == 'I' || r == 'i') ? 20 : 40;
212  UShort_t nX = ((r == 'I' || r == 'i') ? 512 : 256) / 128;
213  TH2D* ret = new TH2D(Form("%s_FMD%d%c", GetHistName(what), d, r),
214  Form("%s for FMD%d%c", GetHistTitle(what), d, r),
215  nX, 0, nX, nY, 0, nY);
216  ret->SetXTitle("Channel #");
217  ret->SetYTitle("Sector #");
218  ret->SetZTitle(GetHistTitle(what));
219  ret->GetXaxis()->SetNdivisions(nX, false);
220  ret->GetYaxis()->SetNdivisions(nY, false);
221  SetAttributes(ret, what, d, r);
222  for (UShort_t s = 0; s < ret->GetNbinsY(); s++) {
223  for (UShort_t t = 0; t < ret->GetNbinsX(); t++) {
224  Double_t val;
225  Double_t err;
226  GetNumber(what, d, r, s, t*128, val, err);
227  ret->SetBinContent(t+1, s+1, val);
228  ret->SetBinError(t+1, s+1, err);
229  }
230  }
231  return ret;
232  }
233 
234  TH2D* ret = Make2D(what, d, r);
235  for (UShort_t s = 0; s < ret->GetNbinsY(); s++) {
236  for (UShort_t t = 0; t < ret->GetNbinsX(); t++) {
237  Double_t val;
238  Double_t err;
239  GetNumber(what, d, r, s, t, val, err);
240  ret->SetBinContent(t+1, s+1, val);
241  ret->SetBinError(t+1, s+1, err);
242  }
243  }
244  return ret;
245 }
246 //____________________________________________________________________
247 TH1*
248 AliFMDCalibDrawer::FillSector(EWhat what,UShort_t d, Char_t r, UShort_t s) const
249 {
250  if (what == kZeroSuppression) {
251  UShort_t nX = ((r == 'I' || r == 'i') ? 512 : 256) / 128;
252  TH1D* ret = new TH1D(Form("%s_FMD%d%c[%02d]",
253  GetHistName(what), d, r, s),
254  Form("%s for FMD%d%c[%02d]",
255  GetHistTitle(what), d, r, s),
256  nX, 0, nX);
257  ret->SetXTitle("Channel #");
258  ret->SetYTitle(GetHistTitle(what));
259  SetAttributes(ret, what, d, r);
260  ret->GetXaxis()->SetNdivisions(nX, false);
261  for (UShort_t t = 0; t < ret->GetNbinsX(); t++) {
262  Double_t val;
263  Double_t err;
264  GetNumber(what, d, r, s, t*128, val, err);
265  ret->SetBinContent(t+1, s+1, val);
266  if (err >= 0) ret->SetBinError(t+1, s+1, err);
267  }
268  return ret;
269  }
270 
271  TH1D* ret = Make1D(what, d, r, s);
272  for (UShort_t t = 0; t < ret->GetNbinsX(); t++) {
273  Double_t val;
274  Double_t err;
275  GetNumber(what, d, r, s, t, val, err);
276  ret->SetBinContent(t+1, s+1, val);
277  if (err >= 0) ret->SetBinError(t+1, s+1, err);
278  }
279  return ret;
280 }
281 
282 //____________________________________________________________________
283 void
284 AliFMDCalibDrawer::DrawOne(EWhat what, Short_t d, Char_t r,
285  Short_t s, Short_t /*t*/) const
286 {
287  Info("DrawOne", "Will draw %s for D=%d, R=%c, S=%d",
288  GetHistTitle(what), d, (r == '\0' ? '-' : r), s);
289  TVirtualPad* tp = gPad;
290  if (!tp) tp = TCanvas::MakeDefCanvas();
291  if (d <= 0 || d > 3) {
292  // All detectors - need to split current pad
293  tp->Divide(1,3,0,0);
294  for (UShort_t dd = 1; dd <= 3; dd++) {
295  tp->cd(dd);
296  // Call our selves
297  DrawOne(what, dd, '\0', -1, -1);
298  }
299  }
300  else if ((r != 'I' && r != 'i') && (r != 'O' && r != 'o')) {
301  // All rings in a detector. Split current pad in two
302  tp->SetName(Form("FMD%d", d));
303  tp->Divide(2,1,0,0);
304  for (UShort_t q = 0; q < 2; q++) {
305  tp->cd(q+1);
306  Char_t rr = q == 0 ? 'I' : 'O';
307  // Call ourselves
308  DrawOne(what, d, rr, -1, -1);
309  }
310  }
311  else if (what == kRate || what == kRange || s < 0 || s > 39) {
312  // A single ring - and special case for sample rate and strip range
313  tp->SetName(Form("FMD%d%c", d, r));
314  tp->SetFillColor(0);
315  tp->SetFillStyle(0);
316  tp->SetRightMargin(0.10);
317  if (d == 1 && (r == 'O' || r == 'o')) return;
318  TH1* h = FillRing(what, d, r);
319  switch (what) {
320  case kRate: h->Draw("bar"); break;
321  case kRange: h->Draw("e3"); break;
322  default: h->Draw("colz"); break;
323  }
324  }
325  else {
326  // Finally, we're down to a single sector. In this case, we just do
327  // a single 1D histogram
328  TH1* h = FillSector(what, d, r, s);
329  h->Draw("hist e");
330  }
331  tp->Update();
332  tp->Modified();
333  tp->cd();
334 }
335 
336 
337 
338 //____________________________________________________________________
339 //
340 // EOF
341 //
UShort_t GetZeroSuppression(UShort_t detector, Char_t ring, UShort_t sector, UShort_t strip) const
UShort_t GetMaxStrip(UShort_t detector, Char_t ring, UShort_t sector, UShort_t strip) const
Bool_t IsDead(UShort_t detector, Char_t ring, UShort_t sector, UShort_t strip) const
void SetDefaultStorageFromRun(Int_t run)
This class is a singleton that handles various parameters of the FMD detectors. This class reads from...
Manager of FMD parameters.
Float_t GetPulseGain(UShort_t detector, Char_t ring, UShort_t sector, UShort_t strip) const
TH1 * FillSector(EWhat what, UShort_t d, Char_t r, UShort_t s) const
Double_t GetHistMin(EWhat what) const
Int_t GetRingColor(UShort_t d, Char_t r) const
TH1D * Make1D(EWhat what, UShort_t d, Char_t r, UShort_t s) const
static AliFMDParameters * Instance()
void DrawOne(EWhat what, Short_t d=-1, Char_t r='\0', Short_t s=-1, Short_t t=-1) const
void SetRun(Int_t run)
void SetAttributes(TH1 *ret, EWhat what, UShort_t d, Char_t r) const
void SetDefaultStorage(const char *dbString)
void GetNumber(EWhat what, UShort_t d, Char_t r, UShort_t s, UShort_t t, Double_t &val, Double_t &err) const
const char * GetHistTitle(EWhat what) const
Double_t GetHistMax(EWhat what) const
TTree * db
Definition: kNNSpeed.C:21
#define AliError(message)
Definition: AliLog.h:591
static AliCDBManager * Instance(TMap *entryCache=NULL, Int_t run=-1)
Float_t GetPedestal(UShort_t detector, Char_t ring, UShort_t sector, UShort_t strip) const
Float_t GetPedestalWidth(UShort_t detector, Char_t ring, UShort_t sector, UShort_t strip) const
TH1 * FillRing(EWhat what, UShort_t d, Char_t r) const
TH2D * Make2D(EWhat what, UShort_t d, Char_t r) const
UShort_t GetSampleRate(UShort_t detector, Char_t ring, UShort_t sector, UShort_t strip) const
const char * GetHistName(EWhat what) const
void Init(Int_t runNo, const char *ocdb=0)
UShort_t Init(Bool_t forceReInit=kFALSE, UInt_t what=kAll)
UShort_t GetMinStrip(UShort_t detector, Char_t ring, UShort_t sector, UShort_t strip) const