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