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