fixed typo for setting fraction of shared clusters
[u/mrichter/AliRoot.git] / FMD / AliFMDQADataMakerRec.cxx
CommitLineData
c9dd1c4d 1/**************************************************************************
2 * Copyright(c) 2004, 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// --- ROOT system ---
16#include <iostream>
17#include <TClonesArray.h>
18#include <TFile.h>
19#include <TH1F.h>
20#include <TH1I.h>
05e5e0c1 21#include <TH2I.h>
c9dd1c4d 22
23// --- AliRoot header files ---
24#include "AliESDEvent.h"
25#include "AliLog.h"
26#include "AliFMDQADataMakerRec.h"
27#include "AliFMDDigit.h"
28#include "AliFMDRecPoint.h"
29#include "AliQAChecker.h"
30#include "AliESDFMD.h"
31#include "AliFMDParameters.h"
86c6cec8 32#include "AliFMDRawReader.h"
3ceaa9ad 33#include "AliRawReader.h"
b995fc28 34#include "AliFMDAltroMapping.h"
f4b5062e 35#include "AliFMDDebug.h"
c9dd1c4d 36
05e5e0c1 37namespace {
38 Int_t colors[3] = {kRed,kGreen,kBlue};
39}
c9dd1c4d 40//_____________________________________________________________________
41// This is the class that collects the QA data for the FMD during
42// reconstruction.
43//
44// The following data types are picked up:
c9dd1c4d 45// - rec points
46// - esd data
c9dd1c4d 47// - raws
48// Author : Hans Hjersing Dalsgaard, hans.dalsgaard@cern.ch
49//_____________________________________________________________________
50
51ClassImp(AliFMDQADataMakerRec)
52#if 0
53; // For Emacs - do not delete!
54#endif
55
56//_____________________________________________________________________
57AliFMDQADataMakerRec::AliFMDQADataMakerRec() :
4e25ac79 58 AliQADataMakerRec(AliQAv1::GetDetName(AliQAv1::kFMD),
a7e41e8d 59 "FMD Quality Assurance Data Maker"),
198942c7 60 fRecPointsArray("AliFMDRecPoint", 1000)
c9dd1c4d 61{
62 // ctor
56236ce9 63
c9dd1c4d 64}
65
66//_____________________________________________________________________
a7e41e8d 67AliFMDQADataMakerRec::AliFMDQADataMakerRec(const AliFMDQADataMakerRec& qadm)
4e25ac79 68 : AliQADataMakerRec(AliQAv1::GetDetName(AliQAv1::kFMD),
a7e41e8d 69 "FMD Quality Assurance Data Maker"),
a7e41e8d 70 fRecPointsArray(qadm.fRecPointsArray)
c9dd1c4d 71{
ffa78f64 72 // copy ctor
c9dd1c4d 73 // Parameters:
74 // qadm Object to copy from
75
76}
9bd2ccc2 77//_____________________________________________________________________
63720979 78AliFMDQADataMakerRec&
79AliFMDQADataMakerRec::operator = (const AliFMDQADataMakerRec& qadm )
a7e41e8d 80{
09b6c804 81 //
82 // Assignment operator
83 //
84 // Parameters:
85 // qadm What to assign from
86 //
87 // Return:
88 // Reference to this
89 //
a7e41e8d 90 fRecPointsArray = qadm.fRecPointsArray;
91
92 return *this;
93}
94//_____________________________________________________________________
9bd2ccc2 95AliFMDQADataMakerRec::~AliFMDQADataMakerRec()
96{
09b6c804 97 //
98 // Destrcutor
99 //
9bd2ccc2 100}
c9dd1c4d 101
102
103//_____________________________________________________________________
104
105void
4e25ac79 106AliFMDQADataMakerRec::EndOfDetectorCycle(AliQAv1::TASKINDEX_t task,
57acd2d2 107 TObjArray ** list)
c9dd1c4d 108{
109 // Detector specific actions at end of cycle
110 // do the QA checking
ffa78f64 111 AliLog::Message(5,"FMD: end of detector cycle",
112 "AliFMDQADataMakerRec","AliFMDQADataMakerRec",
113 "AliFMDQADataMakerRec::EndOfDetectorCycle",
114 "AliFMDQADataMakerRec.cxx",95);
4e25ac79 115 AliQAChecker::Instance()->Run(AliQAv1::kFMD, task, list);
c9dd1c4d 116}
117
118//_____________________________________________________________________
05e5e0c1 119TH1* AliFMDQADataMakerRec::MakeADCHist(UShort_t d, Char_t r, Short_t b)
120{
121 TString name("adc");
122 TString title("ADC counts");
123 Int_t color = kRed+1;
124 if (d > 0) {
125 name.Append(Form("FMD%d%c", d, r));
126 title.Append(Form(" in FMD%d%c", d, r));
127 color = colors[d-1]+3+(r == 'I' || r == 'i' ? 0 : 1);
128 if (b >= 0) {
129 name.Append(Form("_0x%02x", b));
130 title.Append(Form("[0x%02x]", b));
131 }
132 }
133 TH1* hist = new TH1F(name, title,1024,0,1024);
134 hist->SetXTitle("Amplitude [ADC counts]");
135 hist->SetYTitle("Events [log]");
136 hist->SetFillStyle(3001);
137 hist->SetFillColor(color);
138 hist->SetLineColor(color);
139 hist->SetMarkerColor(color);
140 hist->GetXaxis()->SetNdivisions(408,false);
141 // hist->SetStats(0);
142
143 return hist;
144}
145//_____________________________________________________________________
146TH1* AliFMDQADataMakerRec::MakeELossHist(UShort_t d, Char_t r, Short_t b)
147{
148 TString name("eloss");
149 TString title("Energy loss");
150 Int_t color = kBlue+1;
151 if (d > 0) {
152 name.Append(Form("FMD%d%c", d, r));
153 title.Append(Form(" in FMD%d%c", d, r));
154 color = colors[d-1]+3+(r == 'I' || r == 'i' ? 0 : 1);
155 if (b >= 0) {
156 name.Append(Form("_0x%02x", b));
157 title.Append(Form("[0x%02x]", b));
158 }
159 }
160 TH1* hist = new TH1F(name, title,300,0, 15);
161 hist->SetXTitle("#Delta E/#Delta_{mip}");
162 hist->SetYTitle("Events [log]");
163 hist->SetFillStyle(3001);
164 hist->SetFillColor(color);
165 hist->SetLineColor(color);
166 hist->SetMarkerColor(color);
167 // hist->SetStats(0);
168
169 return hist;
170}
171
172
173//_____________________________________________________________________
c9dd1c4d 174void AliFMDQADataMakerRec::InitESDs()
175{
176 // create Digits histograms in Digits subdir
7d297381 177 const Bool_t expert = kTRUE ;
178 const Bool_t image = kTRUE ;
179
05e5e0c1 180 TH1* hist = MakeELossHist();
181 Add2ESDsList(hist, 0, !expert, image);
c9dd1c4d 182
183}
184
44ed7a66 185//_____________________________________________________________________
186void AliFMDQADataMakerRec::InitDigits()
187{
188 // create Digits histograms in Digits subdir
189 const Bool_t expert = kTRUE ;
190 const Bool_t image = kTRUE ;
191
05e5e0c1 192 TH1* hist = MakeADCHist();
193 Add2DigitsList(hist, 0, !expert, image);
44ed7a66 194}
195
196
c9dd1c4d 197//_____________________________________________________________________
c9dd1c4d 198void AliFMDQADataMakerRec::InitRecPoints()
199{
7d297381 200 // create Reconstructed Points histograms in RecPoints subdir
201 const Bool_t expert = kTRUE ;
202 const Bool_t image = kTRUE ;
203
05e5e0c1 204 TH1* hist = MakeELossHist();
205 Add2RecPointsList(hist,0, !expert, image);
c9dd1c4d 206}
207
208//_____________________________________________________________________
209void AliFMDQADataMakerRec::InitRaws()
210{
7d297381 211 // create Raws histograms in Raws subdir
212 const Bool_t expert = kTRUE ;
213 const Bool_t saveCorr = kTRUE ;
214 const Bool_t image = kTRUE ;
05e5e0c1 215 TH2I* hErrors = new TH2I("readoutErrors", "Read out errors", 3, .5, 3.5,
216 160, 0, 160);
217 hErrors->GetXaxis()->SetBinLabel(1, "FMD1");
218 hErrors->GetXaxis()->SetBinLabel(2, "FMD2");
219 hErrors->GetXaxis()->SetBinLabel(3, "FMD3");
220 hErrors->SetYTitle("# errors");
221 hErrors->SetZTitle("Events [log]");
222 Add2RawsList(hErrors, 1, !expert, image, !saveCorr);
223 //AliInfo(Form("Adding %30s to raw list @ %2d", hErrors->GetName(), 1));
224
225 TH1* hist;
226 Int_t idx = 0;
227 for(UShort_t d = 1; d<=3; d++) {
228 UShort_t nR = (d == 1 ? 1 : 2);
229 for(UShort_t q = 0; q < nR; q++) {
230 Char_t r = (q == 1 ? 'O' : 'I');
231 hist = MakeADCHist(d, r, -1);
232
233 Int_t index1 = GetHalfringIndex(d, r, 0, 1);
234 idx = TMath::Max(index1, idx);
235 Add2RawsList(hist, index1, !expert, image, !saveCorr);
236 //AliInfo(Form("Adding %30s to raw list @ %2d", hist->GetName(), index1));
c18fe410 237
05e5e0c1 238 for(UShort_t b = 0; b <= 1; b++) {
c18fe410 239 //Hexadecimal board numbers 0x0, 0x1, 0x10, 0x11;
05e5e0c1 240 UShort_t board = (q == 1 ? 0 : 1) + b*16;
c18fe410 241
05e5e0c1 242 hist = MakeADCHist(d, r, board);
243 Int_t index2 = GetHalfringIndex(d, r, board/16,0);
244 idx = TMath::Max(index2, idx);
245 Add2RawsList(hist, index2, expert, !image, !saveCorr);
246 //AliInfo(Form("Adding %30s to raw list @ %2d",hist->GetName(),index2));
b4da452d 247 }
248 }
249 }
c9dd1c4d 250}
251
408bf2b4 252#if 0
253struct FillESDHist : public AliESDFMD::ForOne
254{
255 FillESDHist(AliFMDQADataMakerRec* m) : fM(m) {}
256 FillESDHist(const FillESDHist& o) : fM(o.fM) {}
257 FillESDHist& operator=(const FillESDHist& o) { fM = o.fM; return *this; }
258 Bool_t operator()(UShort_t, Char_t, UShort_t, UShort_t, Float_t m, Float_t)
259 {
260 // Float_t mult = fmd->Multiplicity(det,ring,sec,strip);
261 if(m == AliESDFMD::kInvalidMult) return true;
262
263 fM->GetESDsData(0)->Fill(m);
264 return true;
265 }
266 AliFMDQADataMakerRec* fM;
267};
268#endif
269
c9dd1c4d 270//_____________________________________________________________________
271void AliFMDQADataMakerRec::MakeESDs(AliESDEvent * esd)
272{
09b6c804 273 //
274 // Analyse ESD event
275 //
276 // Parameters:
277 // esd ESD event
278 //
c9dd1c4d 279 if(!esd) {
280 AliError("FMD ESD object not found!!") ;
281 return;
282 }
f4b5062e 283 AliFMDDebug(2, ("Will loop over ESD data and fill histogram"));
284
c9dd1c4d 285 AliESDFMD* fmd = esd->GetFMDData();
286 if (!fmd) return;
f4b5062e 287
408bf2b4 288#if 0
289 FillESDHist f(this);
290 fmd->ForEach(f);
291#else
292
293
294
f4b5062e 295 // FIXME - we should use AliESDFMD::ForOne subclass to do this!
c9dd1c4d 296 for(UShort_t det=1;det<=3;det++) {
f4b5062e 297 UShort_t nrng = (det == 1 ? 1 : 2);
298 for (UShort_t ir = 0; ir < nrng; ir++) {
c9dd1c4d 299 Char_t ring = (ir == 0 ? 'I' : 'O');
300 UShort_t nsec = (ir == 0 ? 20 : 40);
301 UShort_t nstr = (ir == 0 ? 512 : 256);
302 for(UShort_t sec =0; sec < nsec; sec++) {
303 for(UShort_t strip = 0; strip < nstr; strip++) {
304 Float_t mult = fmd->Multiplicity(det,ring,sec,strip);
305 if(mult == AliESDFMD::kInvalidMult) continue;
306
307 GetESDsData(0)->Fill(mult);
308 }
309 }
310 }
311 }
408bf2b4 312#endif
c9dd1c4d 313}
314
44ed7a66 315
c9dd1c4d 316//_____________________________________________________________________
6252ceeb 317void AliFMDQADataMakerRec::MakeDigits()
c9dd1c4d 318{
319 // makes data from Digits
6252ceeb 320 if(!fDigitsArray) {
ffa78f64 321 AliError("FMD Digit object not found!!") ;
322 return;
c9dd1c4d 323 }
eca4fa66 324
6252ceeb 325 for(Int_t i=0;i<fDigitsArray->GetEntriesFast();i++) {
c9dd1c4d 326 //Raw ADC counts
6252ceeb 327 AliFMDDigit* digit = static_cast<AliFMDDigit*>(fDigitsArray->At(i));
c9dd1c4d 328 GetDigitsData(0)->Fill(digit->Counts());
329 }
330}
331
332//_____________________________________________________________________
333void AliFMDQADataMakerRec::MakeDigits(TTree * digitTree)
334{
09b6c804 335 //
336 // Analyse digits
337 //
338 // Parameters:
339 // digitTree Tree of digits
340 //
c9dd1c4d 341
6252ceeb 342 if (fDigitsArray)
343 fDigitsArray->Clear();
344 else
345 fDigitsArray = new TClonesArray("AliFMDDigit", 1000);
346
ffa78f64 347 TBranch* branch = digitTree->GetBranch("FMD");
348 if (!branch) {
c9dd1c4d 349 AliWarning("FMD branch in Digit Tree not found") ;
350 return;
351 }
6252ceeb 352 branch->SetAddress(&fDigitsArray);
ffa78f64 353 branch->GetEntry(0);
6252ceeb 354 MakeDigits();
c9dd1c4d 355}
44ed7a66 356
c9dd1c4d 357//_____________________________________________________________________
86c6cec8 358void AliFMDQADataMakerRec::MakeRaws(AliRawReader* rawReader)
c9dd1c4d 359{
09b6c804 360 //
361 // Analyse raw
362 //
363 // Parameters:
364 // rawReader Raw reader
365 //
198942c7 366
09b6c804 367 AliFMDRawReader fmdReader(rawReader,0);
6252ceeb 368
369 if (fDigitsArray)
370 fDigitsArray->Clear();
371 else
372 fDigitsArray = new TClonesArray("AliFMDDigit", 1000);
eca4fa66 373
6252ceeb 374 TClonesArray* digitsAddress = fDigitsArray;
3ceaa9ad 375
376 rawReader->Reset();
78328afd 377
c18fe410 378 digitsAddress->Clear();
379 fmdReader.ReadAdcs(digitsAddress);
380 for(Int_t i=0;i<digitsAddress->GetEntriesFast();i++) {
381 //Raw ADC counts
b995fc28 382 AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitsAddress->At(i));
383 UShort_t det = digit->Detector();
384 Char_t ring = digit->Ring();
385 UShort_t sec = digit->Sector();
386 // UShort_t strip = digit->Strip();
387 AliFMDParameters* pars = AliFMDParameters::Instance();
388 Short_t board = pars->GetAltroMap()->Sector2Board(ring, sec);
c18fe410 389
390 Int_t index1 = GetHalfringIndex(det, ring, 0, 1);
c18fe410 391 Int_t index2 = GetHalfringIndex(det, ring, board/16,0);
05e5e0c1 392 // AliInfo(Form("FMD%d%c[0x%02x]->%2d,%2d",
393 // det, ring, board, index1, index2));
394 GetRawsData(index1)->Fill(digit->Counts());
395 GetRawsData(index2)->Fill(digit->Counts());
c18fe410 396 }
05e5e0c1 397 GetRawsData(1)->Fill(1, fmdReader.GetNErrors(0));
398 GetRawsData(1)->Fill(2, fmdReader.GetNErrors(1));
399 GetRawsData(1)->Fill(3, fmdReader.GetNErrors(2));
c9dd1c4d 400}
401
402//_____________________________________________________________________
403void AliFMDQADataMakerRec::MakeRecPoints(TTree* clustersTree)
404{
405 // makes data from RecPoints
eca4fa66 406
6252ceeb 407 AliFMDParameters* pars = AliFMDParameters::Instance();
56236ce9 408 fRecPointsArray.Clear();
c9dd1c4d 409 TBranch *fmdbranch = clustersTree->GetBranch("FMD");
410 if (!fmdbranch) {
411 AliError("can't get the branch with the FMD recpoints !");
412 return;
413 }
414
56236ce9 415 TClonesArray* RecPointsAddress = &fRecPointsArray;
9bd2ccc2 416
56236ce9 417 fmdbranch->SetAddress(&RecPointsAddress);
c9dd1c4d 418 fmdbranch->GetEntry(0);
56236ce9 419 TIter next(RecPointsAddress) ;
c9dd1c4d 420 AliFMDRecPoint * rp ;
421 while ((rp = static_cast<AliFMDRecPoint*>(next()))) {
198942c7 422
423 GetRecPointsData(0)->Fill(rp->Edep()/pars->GetEdepMip()) ;
424
c9dd1c4d 425 }
c9dd1c4d 426
427}
428
429//_____________________________________________________________________
430void AliFMDQADataMakerRec::StartOfDetectorCycle()
431{
432 // What
433 // to
434 // do?
435}
436//_____________________________________________________________________
b4da452d 437Int_t AliFMDQADataMakerRec::GetHalfringIndex(UShort_t det,
438 Char_t ring,
c18fe410 439 UShort_t board,
09b6c804 440 UShort_t monitor) const
441{
442 //
443 // Get the half-ring index
444 //
445 // Parameters:
446 // det Detector
447 // ring Ring
448 // board Board number
449 // monitor Monitor
450 //
451 // Return:
452 // Half ring index
453 //
05e5e0c1 454 UShort_t iring = (ring == 'I' || ring == 'i' ? 1 : 0);
455 Int_t index = ((((det-1) & 0x3) << 3) |
456 ((iring & 0x1) << 2) |
457 ((board & 0x1) << 1) |
458 ((monitor & 0x1) << 0));
459#if 0
460 AliInfo(Form("d=%d, r=%c, b=%d, m=%d -> (%d<<3)|(%d<<2)|(%d<<1)|(%d<<0)=%2d",
461 det, ring, board, monitor, (det-1) & 0x3, iring & 0x1,
462 board & 0x1, monitor & 0x1, index));
463#endif
b4da452d 464 return index-2;
b4da452d 465}
466
467//_____________________________________________________________________
468
469
c9dd1c4d 470//
471// EOF
472//